import * as v from "valibot" import type { CustomBlockErrorInfo } from "../errors.js" import { notionPageSchema } from "../pages/page.js" // The schema accepts any string code. The type lists known codes for // autocomplete, with an open string fallback for newer senders. export const customBlockUpdatePageErrorCodeSchema = v.string() export type CustomBlockUpdatePageErrorCode = | "update_page_failed" | "invalid_page_update" | "page_access_failed" | "collection_access_failed" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value" | (string & {}) export type CustomBlockUpdatePageErrorInfo = CustomBlockErrorInfo export const customBlockUpdatePageErrorInfoSchema = v.object({ code: customBlockUpdatePageErrorCodeSchema, message: v.string(), isRetryable: v.boolean(), }) /** * Host -> sandbox: result for a page update request. */ export const updatePageResultMessageSchema = v.variant("status", [ v.object({ type: v.literal("updatePageResult"), requestId: v.string(), status: v.literal("success"), page: notionPageSchema, }), v.object({ type: v.literal("updatePageResult"), requestId: v.string(), status: v.literal("error"), error: customBlockUpdatePageErrorInfoSchema, }), ]) export type UpdatePageResultMessage = v.InferOutput< typeof updatePageResultMessageSchema >