import type { NotionAsCodeIcon } from "./intents.js"; /** Page icons cannot refer to workspace custom emoji or uploaded files. */ export type PageIcon = Exclude; const NOTION_ICON_COLORS = new Set([ "gray", "lightgray", "brown", "yellow", "orange", "green", "blue", "purple", "pink", "red", ]); /** Validate icon values before they enter a provisioning artifact. */ export function assertPageIcon(icon: unknown): asserts icon is PageIcon { if (typeof icon !== "object" || icon === null || !("type" in icon)) { throw new Error("Page icons must use a standard emoji or a Notion icon."); } if (icon.type === "emoji") { if ( !("emoji" in icon) || typeof icon.emoji !== "string" || !/^(?:\p{RGI_Emoji}|\p{Extended_Pictographic})$/v.test(icon.emoji) ) { throw new Error( "Page icons must use a single standard emoji, not workspace custom emoji.", ); } return; } if (icon.type === "notion_icon") { if ( !("description" in icon) || typeof icon.description !== "string" || icon.description.trim().length === 0 ) { throw new Error("Notion page icons need a nonempty description."); } if ( "color" in icon && icon.color !== undefined && (typeof icon.color !== "string" || !NOTION_ICON_COLORS.has(icon.color)) ) { throw new Error( `Notion page icon colors must be one of: ${[...NOTION_ICON_COLORS].join(", ")}.`, ); } return; } throw new Error( "Page icons must use a standard emoji or a Notion icon, not custom emoji or files.", ); }