import * as v from "valibot" import type { CustomBlockErrorInfo } from "../errors.js" import { notionPageIdSchema } from "../ids.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 customBlockGetPageErrorCodeSchema = v.string() export type CustomBlockGetPageErrorCode = | "get_page_failed" | "page_access_failed" | (string & {}) export type CustomBlockGetPageErrorInfo = CustomBlockErrorInfo export const customBlockGetPageErrorInfoSchema = v.object({ code: customBlockGetPageErrorCodeSchema, message: v.string(), isRetryable: v.boolean(), }) /** * Sandbox -> host: fetch a page by ID. */ export const getPageMessageSchema = v.object({ type: v.literal("getPage"), requestId: v.string(), pageId: notionPageIdSchema, }) export type GetPageMessage = v.InferOutput export const getPageResultMessageSchema = v.variant("status", [ v.object({ type: v.literal("getPageResult"), requestId: v.string(), status: v.literal("success"), page: notionPageSchema, }), v.object({ type: v.literal("getPageResult"), requestId: v.string(), status: v.literal("error"), error: customBlockGetPageErrorInfoSchema, }), ]) export type GetPageResultMessage = v.InferOutput< typeof getPageResultMessageSchema >