import * as v from "valibot" import { notionBlockIdSchema, notionDataSourceIdSchema, notionPageIdSchema, } from "../ids.js" import { notionPageCoverSchema, notionPageIconSchema, notionPagePropertyWriteMapSchema, } from "../pages/page.js" /** * Describes where the newly created page should be inserted. * - `start` / `end` (default): prepend / append to the request's `parent` * page's children. * - `before` / `after`: insert as a sibling of the anchor block identified by * `blockId`, using the anchor's own structural parent. The anchor can be * nested anywhere below the page (inside a toggle, column, callout, etc.). */ export const notionCreatePagePositionSchema = v.variant("type", [ v.object({ type: v.literal("start") }), v.object({ type: v.literal("end") }), v.object({ type: v.literal("before"), blockId: notionBlockIdSchema }), v.object({ type: v.literal("after"), blockId: notionBlockIdSchema }), ]) export type NotionCreatePagePosition = v.InferOutput< typeof notionCreatePagePositionSchema > /** * Parent accepted by the outbound `createPage` bridge message. * * Mirrors Notion's public API `POST /v1/pages` parent shape: `page_id` for a page-parented child, * `data_source_id` for a database row. `data_source_id` is the internal collection ID. * * The SDK additionally accepts a higher-level `data_source_key` variant that resolves to * `data_source_id` locally, using the `dataSources` mapping. */ export const createPageParentSchema = v.variant("type", [ v.object({ type: v.literal("page_id"), page_id: notionPageIdSchema }), v.object({ type: v.literal("data_source_id"), data_source_id: notionDataSourceIdSchema, }), ]) export type CreatePageMessageParent = v.InferOutput< typeof createPageParentSchema > /** * Message sent by the sandbox to ask the host to create a new page on its behalf. * The payload mirrors Notion's public `POST /v1/pages` API. */ export const createPageMessageSchema = v.object({ type: v.literal("createPage"), requestId: v.string(), parent: createPageParentSchema, properties: notionPagePropertyWriteMapSchema, icon: v.optional(notionPageIconSchema), cover: v.optional(notionPageCoverSchema), position: v.optional(notionCreatePagePositionSchema), }) export type CreatePageMessage = v.InferOutput