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 customBlockCreatePageErrorCodeSchema = v.string() export type CustomBlockCreatePageErrorCode = | "create_page_failed" | "invalid_page_parent" | "page_access_failed" | "collection_access_failed" | "unknown_data_source_key" | "unmapped_data_source" | "unmapped_property" | "property_id_mismatch" | "duplicate_property" | "invalid_property_value" | (string & {}) export type CustomBlockCreatePageErrorInfo = CustomBlockErrorInfo export const customBlockCreatePageErrorInfoSchema = v.object({ code: customBlockCreatePageErrorCodeSchema, message: v.string(), isRetryable: v.boolean(), }) /** * Message sent by the host in response to a sandbox `createPage` request. */ export const createPageResultMessageSchema = v.variant("status", [ v.object({ type: v.literal("createPageResult"), requestId: v.string(), status: v.literal("success"), /** The newly created page. */ page: notionPageSchema, }), v.object({ type: v.literal("createPageResult"), requestId: v.string(), status: v.literal("error"), error: customBlockCreatePageErrorInfoSchema, }), ]) export type CreatePageResultMessage = v.InferOutput< typeof createPageResultMessageSchema >