import {z} from 'zod' export type IdRequest = string; export type GetApiV1PagesPageIdPropertiesPropertyIdArgs = {page_id: IdRequest, property_id: string, start_cursor?: string | undefined, page_size?: number | undefined, 'Notion-Version': '2026-03-11'}; export type GetApiV1PagesPageIdPropertiesPropertyIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const numberPropertyItemObjectResponse = z.object({type: z.literal("number"), number: z.number().nullable(), object: z.literal("property_item"), id: z.string()}); export const urlPropertyItemObjectResponse = z.object({type: z.literal("url"), url: z.string().nullable(), object: z.literal("property_item"), id: z.string()}); export const selectColor = z.enum(["default", "gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", "red"]); export const partialSelectResponse = z.object({id: z.string(), name: z.string(), color: selectColor}); export const selectPropertyItemObjectResponse = z.object({type: z.literal("select"), select: partialSelectResponse.nullable(), object: z.literal("property_item"), id: z.string()}); export const multiSelectPropertyItemObjectResponse = z.object({type: z.literal("multi_select"), multi_select: z.array(partialSelectResponse), object: z.literal("property_item"), id: z.string()}); export const statusPropertyItemObjectResponse = z.object({type: z.literal("status"), status: partialSelectResponse.nullable(), object: z.literal("property_item"), id: z.string()}); export const timeZoneRequest = z.string(); export const dateResponse = z.object({start: z.string(), end: z.string().nullable(), time_zone: timeZoneRequest.nullable()}); export const datePropertyItemObjectResponse = z.object({type: z.literal("date"), date: dateResponse.nullable(), object: z.literal("property_item"), id: z.string()}); export const emailPropertyItemObjectResponse = z.object({type: z.literal("email"), email: z.string().nullable(), object: z.literal("property_item"), id: z.string()}); export const phoneNumberPropertyItemObjectResponse = z.object({type: z.literal("phone_number"), phone_number: z.string().nullable(), object: z.literal("property_item"), id: z.string()}); export const checkboxPropertyItemObjectResponse = z.object({type: z.literal("checkbox"), checkbox: z.boolean(), object: z.literal("property_item"), id: z.string()}); export const internalFileResponse = z.object({url: z.string(), expiry_time: z.string()}); export const internalOrExternalFileWithNameResponse = z.union([z.object({name: z.string(), type: z.literal("file"), file: internalFileResponse}), z.object({name: z.string(), type: z.literal("external"), external: z.object({url: z.string()})})]); export const filesPropertyItemObjectResponse = z.object({type: z.literal("files"), files: z.array(internalOrExternalFileWithNameResponse), object: z.literal("property_item"), id: z.string()}); export const idResponse = z.string(); export const partialUserObjectResponse = z.object({id: idResponse, object: z.literal("user")}); export const emptyObject = z.object({}); export const botInfoResponse = z.object({owner: z.union([z.object({type: z.literal("user"), user: z.union([z.object({id: idResponse, object: z.literal("user"), name: z.string().nullable(), avatar_url: z.string().nullable(), type: z.literal("person"), person: z.object({email: z.string().optional(), email_verified: z.boolean().optional()})}), partialUserObjectResponse])}), z.object({type: z.literal("workspace"), workspace: z.literal(true)})]), workspace_id: z.string(), workspace_limits: z.object({max_file_upload_size_in_bytes: z.number().int().gte(0)}), workspace_name: z.string().nullable()}); export const userObjectResponse = z.union([z.object({id: idResponse, object: z.literal("user"), name: z.string().nullable(), avatar_url: z.string().nullable(), type: z.literal("person"), person: z.object({email: z.string().optional(), email_verified: z.boolean().optional()})}), z.object({id: idResponse, object: z.literal("user"), name: z.string().nullable(), avatar_url: z.string().nullable(), type: z.literal("bot"), bot: z.union([emptyObject, botInfoResponse])})]); export const createdByPropertyItemObjectResponse = z.object({type: z.literal("created_by"), created_by: z.union([partialUserObjectResponse, userObjectResponse]), object: z.literal("property_item"), id: z.string()}); export const createdTimePropertyItemObjectResponse = z.object({type: z.literal("created_time"), created_time: z.string(), object: z.literal("property_item"), id: z.string()}); export const lastEditedByPropertyItemObjectResponse = z.object({type: z.literal("last_edited_by"), last_edited_by: z.union([partialUserObjectResponse, userObjectResponse]), object: z.literal("property_item"), id: z.string()}); export const lastEditedTimePropertyItemObjectResponse = z.object({type: z.literal("last_edited_time"), last_edited_time: z.string(), object: z.literal("property_item"), id: z.string()}); export const stringFormulaPropertyResponse = z.object({type: z.literal("string"), string: z.string().nullable()}); export const dateFormulaPropertyResponse = z.object({type: z.literal("date"), date: dateResponse.nullable()}); export const numberFormulaPropertyResponse = z.object({type: z.literal("number"), number: z.number().nullable()}); export const booleanFormulaPropertyResponse = z.object({type: z.literal("boolean"), boolean: z.boolean().nullable()}); export const formulaPropertyResponse = z.union([stringFormulaPropertyResponse, dateFormulaPropertyResponse, numberFormulaPropertyResponse, booleanFormulaPropertyResponse]); export const formulaPropertyItemObjectResponse = z.object({type: z.literal("formula"), formula: formulaPropertyResponse, object: z.literal("property_item"), id: z.string()}); export const buttonPropertyItemObjectResponse = z.object({type: z.literal("button"), button: emptyObject, object: z.literal("property_item"), id: z.string()}); export const uniqueIdPropertyItemObjectResponse = z.object({type: z.literal("unique_id"), unique_id: z.object({prefix: z.string().nullable(), number: z.number().nullable()}), object: z.literal("property_item"), id: z.string()}); export const verificationPropertyUnverifiedResponse = z.object({state: z.literal("unverified"), date: z.unknown(), verified_by: z.unknown()}); export const userValueResponse = z.union([partialUserObjectResponse, userObjectResponse]); export const verificationPropertyResponse = z.object({state: z.enum(["verified", "expired"]), date: dateResponse.nullable(), verified_by: userValueResponse.nullable()}); export const verificationPropertyValueResponse = z.union([verificationPropertyUnverifiedResponse, verificationPropertyResponse]); export const verificationPropertyItemObjectResponse = z.object({type: z.literal("verification"), verification: verificationPropertyValueResponse.nullable(), object: z.literal("property_item"), id: z.string()}); export const placePropertyItemObjectResponse = z.object({type: z.literal("place"), place: z.object({lat: z.number(), lon: z.number(), name: z.string().nullable().optional(), address: z.string().nullable().optional(), aws_place_id: z.string().nullable().optional(), google_place_id: z.string().nullable().optional()}).nullable(), object: z.literal("property_item"), id: z.string()}); export const apiColor = z.enum(["default", "gray", "brown", "orange", "yellow", "green", "blue", "purple", "pink", "red", "default_background", "gray_background", "brown_background", "orange_background", "yellow_background", "green_background", "blue_background", "purple_background", "pink_background", "red_background"]); export const annotationResponse = z.object({bold: z.boolean(), italic: z.boolean(), strikethrough: z.boolean(), underline: z.boolean(), code: z.boolean(), color: apiColor}); export const linkPreviewMentionResponse = z.object({url: z.string()}); export const linkMentionResponse = z.object({href: z.string(), title: z.string().optional(), description: z.string().optional(), link_author: z.string().optional(), link_provider: z.string().optional(), thumbnail_url: z.string().optional(), icon_url: z.string().optional(), iframe_url: z.string().optional(), height: z.number().int().optional(), padding: z.number().int().optional(), padding_top: z.number().int().optional()}); export const templateMentionDateTemplateMentionResponse = z.object({type: z.literal("template_mention_date"), template_mention_date: z.enum(["today", "now"])}); export const templateMentionUserTemplateMentionResponse = z.object({type: z.literal("template_mention_user"), template_mention_user: z.literal("me")}); export const templateMentionResponse = z.union([templateMentionDateTemplateMentionResponse, templateMentionUserTemplateMentionResponse]); export const customEmojiResponse = z.object({id: idResponse, name: z.string(), url: z.string()}); export const richTextItemResponse = z.union([z.object({plain_text: z.string(), href: z.string().nullable(), annotations: annotationResponse, type: z.literal("text"), text: z.object({content: z.string().max(2000), link: z.object({url: z.string()}).nullable()})}), z.object({plain_text: z.string(), href: z.string().nullable(), annotations: annotationResponse, type: z.literal("mention"), mention: z.union([z.object({type: z.literal("user"), user: userValueResponse}), z.object({type: z.literal("date"), date: dateResponse}), z.object({type: z.literal("link_preview"), link_preview: linkPreviewMentionResponse}), z.object({type: z.literal("link_mention"), link_mention: linkMentionResponse}), z.object({type: z.literal("page"), page: z.object({id: idResponse})}), z.object({type: z.literal("database"), database: z.object({id: idResponse})}), z.object({type: z.literal("template_mention"), template_mention: templateMentionResponse}), z.object({type: z.literal("custom_emoji"), custom_emoji: customEmojiResponse})])}), z.object({plain_text: z.string(), href: z.string().nullable(), annotations: annotationResponse, type: z.literal("equation"), equation: z.object({expression: z.string()})})]); export const titlePropertyItemObjectResponse = z.object({type: z.literal("title"), title: richTextItemResponse, object: z.literal("property_item"), id: z.string()}); export const richTextPropertyItemObjectResponse = z.object({type: z.literal("rich_text"), rich_text: richTextItemResponse, object: z.literal("property_item"), id: z.string()}); export const peoplePropertyItemObjectResponse = z.object({type: z.literal("people"), people: z.union([partialUserObjectResponse, userObjectResponse]), object: z.literal("property_item"), id: z.string()}); export const relationPropertyItemObjectResponse = z.object({type: z.literal("relation"), relation: z.object({id: z.string()}), object: z.literal("property_item"), id: z.string()}); export const rollupFunction = z.enum(["count", "count_values", "empty", "not_empty", "unique", "show_unique", "percent_empty", "percent_not_empty", "sum", "average", "median", "min", "max", "range", "earliest_date", "latest_date", "date_range", "checked", "unchecked", "percent_checked", "percent_unchecked", "count_per_group", "percent_per_group", "show_original"]); export const rollupPropertyItemObjectResponse = z.object({type: z.literal("rollup"), rollup: z.union([z.object({type: z.literal("number"), number: z.number().nullable(), function: rollupFunction}), z.object({type: z.literal("date"), date: dateResponse.nullable(), function: rollupFunction}), z.object({type: z.literal("array"), array: z.array(emptyObject), function: rollupFunction}), z.object({type: z.literal("unsupported"), unsupported: emptyObject, function: rollupFunction}), z.object({type: z.literal("incomplete"), incomplete: emptyObject, function: rollupFunction})]), object: z.literal("property_item"), id: z.string()}); export const propertyItemObjectResponse = z.union([numberPropertyItemObjectResponse, urlPropertyItemObjectResponse, selectPropertyItemObjectResponse, multiSelectPropertyItemObjectResponse, statusPropertyItemObjectResponse, datePropertyItemObjectResponse, emailPropertyItemObjectResponse, phoneNumberPropertyItemObjectResponse, checkboxPropertyItemObjectResponse, filesPropertyItemObjectResponse, createdByPropertyItemObjectResponse, createdTimePropertyItemObjectResponse, lastEditedByPropertyItemObjectResponse, lastEditedTimePropertyItemObjectResponse, formulaPropertyItemObjectResponse, buttonPropertyItemObjectResponse, uniqueIdPropertyItemObjectResponse, verificationPropertyItemObjectResponse, placePropertyItemObjectResponse, titlePropertyItemObjectResponse, richTextPropertyItemObjectResponse, peoplePropertyItemObjectResponse, relationPropertyItemObjectResponse, rollupPropertyItemObjectResponse]); export const propertyItemListResponse = z.object({type: z.literal("property_item"), property_item: z.union([z.object({type: z.literal("title"), title: emptyObject, next_url: z.string().nullable(), id: z.string()}), z.object({type: z.literal("rich_text"), rich_text: emptyObject, next_url: z.string().nullable(), id: z.string()}), z.object({type: z.literal("people"), people: emptyObject, next_url: z.string().nullable(), id: z.string()}), z.object({type: z.literal("relation"), relation: emptyObject, next_url: z.string().nullable(), id: z.string()}), z.object({type: z.literal("rollup"), rollup: z.union([z.object({type: z.literal("number"), number: z.number().nullable(), function: rollupFunction}), z.object({type: z.literal("date"), date: dateResponse.nullable(), function: rollupFunction}), z.object({type: z.literal("array"), array: z.array(emptyObject), function: rollupFunction}), z.object({type: z.literal("unsupported"), unsupported: emptyObject, function: rollupFunction}), z.object({type: z.literal("incomplete"), incomplete: emptyObject, function: rollupFunction})]), next_url: z.string().nullable(), id: z.string()})]), object: z.literal("list"), next_cursor: z.string().nullable(), has_more: z.boolean(), results: z.array(propertyItemObjectResponse)}); export const getApiV1PagesPageIdPropertiesPropertyIdResponse = z.union([propertyItemObjectResponse, propertyItemListResponse]); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieve a page property item * * GET /v1/pages/{page_id}/properties/{property_id} */ export const getApiV1PagesPageIdPropertiesPropertyId = async (args: GetApiV1PagesPageIdPropertiesPropertyIdArgs, options?: GetApiV1PagesPageIdPropertiesPropertyIdOptions) => { const {baseUrl = "https://api.notion.com/admin", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_cursor != null) query.append("start_cursor", String(args.start_cursor)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args['Notion-Version'] != null) headers.set("Notion-Version", String(args['Notion-Version'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/pages/${encodeURIComponent(String(args.page_id))}/properties/${encodeURIComponent(String(args.property_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1PagesPageIdPropertiesPropertyIdResponse, await res.json()) };