import type { ConfigFacade, FetchResult, NotionBlock, NotionBlockList, NotionConfig, NotionDatabase, NotionDatabaseQuery, NotionFilter, NotionPage, NotionPageList, NotionParent, NotionPropertySchema, NotionRichText, NotionSearchQuery, NotionSearchResult, NotionSort, NotionUser, NotionUserList } from "../../types/index.js"; /** * NotionService - Singleton para el cliente de la Notion API. * * Aplica el patrón Singleton: una única instancia mantiene la configuración * (token, versión, base URL) y centraliza las operaciones sobre páginas, * bloques, bases de datos, usuarios y búsqueda, devolviendo siempre Safe Results. * * @example * ```ts * const notion = NotionService.getInstance(); * notion.useInit({ token: process.env.NOTION_TOKEN }); * const result = await notion.useGetPage("page-id"); * ``` */ export declare class NotionService { private static instance; /** Registered Notion configuration. */ private config; /** * Constructor privado - enforce singleton. */ private constructor(); /** * Obtiene la instancia única del NotionService (Singleton). * * @returns La instancia única de {@link NotionService}. */ static getInstance(): NotionService; /** * Registers the Notion API configuration. * * @param cfg - Integration token (starts with "ntn_" or "secret_"), optional * API version and base URL. * @throws {Error} If the config fails Zod validation. * * @example * ```ts * NotionService.getInstance().useInit({ token: process.env.NOTION_TOKEN }); * ``` */ useInit(cfg: NotionConfig): void; /** * Internal helper to make authenticated requests to the Notion API. * Handles Authorization header, Notion-Version, and JSON serialization. * @internal */ private useRequest; /** Retrieves a single Notion page by its ID. */ useGetPage(pageId: string): Promise>; /** Creates a new Notion page inside a database or as a child of another page. */ useCreatePage(parent: NotionParent, properties: Record, children?: unknown[]): Promise>; /** Updates properties of an existing Notion page. */ useUpdatePage(pageId: string, properties: Record): Promise>; /** Archives (soft-deletes) a Notion page. */ useArchivePage(pageId: string): Promise>; /** Retrieves a single Notion block by its ID. */ useGetBlock(blockId: string): Promise>; /** * Retrieves the direct children blocks of a block (single page). * * Use for manual pagination. For most cases, prefer * {@link useListAllBlockChildren} which handles pagination automatically. * * @param blockId - The parent block ID (usually a page ID). * @param options - Pagination: `start_cursor` for next page, `page_size` (max 100). */ useGetBlockChildren(blockId: string, options?: { start_cursor?: string; page_size?: number; }): Promise>; /** Appends new child blocks to a parent block. */ useAppendBlocks(blockId: string, children: unknown[]): Promise>; /** Updates the content of an existing block. */ useUpdateBlock(blockId: string, content: Record): Promise>; /** Deletes (archives) a Notion block. The block is soft-deleted. */ useDeleteBlock(blockId: string): Promise>; /** Retrieves a Notion database schema by its ID. */ useGetDatabase(databaseId: string): Promise>; /** * Queries a Notion database with filters and sorts (single page). * * For most cases, prefer {@link useListAllDatabasePages} which handles * pagination automatically. */ useQueryDatabase(databaseId: string, query?: NotionDatabaseQuery): Promise>; /** Creates a new Notion database inside a page. */ useCreateDatabase(parent: NotionParent, title: NotionRichText[], properties: Record): Promise>; /** Updates a Notion database title and/or property schemas. */ useUpdateDatabase(databaseId: string, title: NotionRichText[], properties?: Record): Promise>; /** Retrieves a Notion workspace member or bot by their user ID. */ useGetUser(userId: string): Promise>; /** Lists all users (members + bots) in the workspace (paginated). */ useListUsers(options?: { start_cursor?: string; page_size?: number; }): Promise>; /** Searches across all pages and databases the integration has access to. */ useSearchContent(query: NotionSearchQuery): Promise>; /** * Fetches ALL child blocks of a block, automatically handling cursor pagination. * * @param blockId - The parent block ID (usually a page ID). * @param maxItems - Cap on the total number of blocks to fetch (default `1000`). * @returns All child blocks as a flat array. */ useListAllBlockChildren(blockId: string, maxItems?: number): Promise>; /** * Fetches ALL pages in a database, automatically handling cursor pagination. * * @param databaseId - The database UUID. * @param filter - Optional filter to apply (same syntax as Notion API). * @param sorts - Optional sort options. * @param maxItems - Cap on the total number of pages to fetch (default `1000`). * @returns All pages matching the filter as a flat array. */ useListAllDatabasePages(databaseId: string, filter?: NotionFilter, sorts?: NotionSort[], maxItems?: number): Promise>; } /** * Registers the Notion configuration and returns your methods alongside it - * the config-file entry point. One call is the whole setup: no separate * `useInitNotion(...)` step. * * Declare methods with `function` (never arrows) so `this.config` resolves to * the registered config. * * @typeParam T - The literal passed in: Notion config plus any methods. * @param input - Notion config plus the methods you want on the facade. * @returns The registered config plus your methods (see {@link ConfigFacade}). * @throws {Error} If the config fails Zod validation. * * @example * ```ts * import { defineNotionConfig } from "katanakit-js/adapters/notion"; * * export default defineNotionConfig({ * token: process.env.NOTION_TOKEN, * getPage: async function (pageId: string) { * return useNotionGetPage(pageId); * }, * }); * ``` */ export declare function defineNotionConfig(input: T & ThisType>): ConfigFacade; /** * Registers the Notion API configuration. Call this once before any other * Notion function. * * @deprecated Use {@link defineNotionConfig}, which registers the config and * returns it with any methods declared on the same literal. * * @param cfg - Integration token (starts with "ntn_" or "secret_"), optional * API version and base URL. * * @example * ```ts * import { useInitNotion } from "katanakit-js/adapters/notion"; * * useInitNotion({ token: process.env.NOTION_TOKEN }); * ``` */ export declare function useInitNotion(cfg: NotionConfig): void; /** * Retrieves a single Notion page by its ID. * * @param pageId - The page UUID. * @returns The page object with all its properties. * * @example * ```ts * const result = await useNotionGetPage("page-id"); * if (result.ok) console.log(result.data.properties); * ``` */ export declare function useNotionGetPage(pageId: string): Promise>; /** * Creates a new Notion page inside a database or as a child of another page. * * @param parent - Where to create the page (`database_id` or `page_id`). * @param properties - Page properties matching the parent database schema. * @param children - Optional block children to populate the page content. * @returns The created page. * * @example * ```ts * const result = await useNotionCreatePage( * { type: "database_id", database_id: "db-id" }, * { Name: { title: [{ type: "text", text: { content: "My Task" } }] } }, * ); * ``` */ export declare function useNotionCreatePage(parent: NotionParent, properties: Record, children?: unknown[]): Promise>; /** * Updates properties of an existing Notion page. * * @param pageId - The page UUID to update. * @param properties - Properties to update (only changed properties). * @returns The updated page. * * @example * ```ts * await useNotionUpdatePage("page-id", { Status: { select: { name: "Done" } } }); * ``` */ export declare function useNotionUpdatePage(pageId: string, properties: Record): Promise>; /** * Archives (soft-deletes) a Notion page. * * @param pageId - The page UUID to archive. * @returns The archived page. * * @example * ```ts * await useNotionArchivePage("page-id"); * ``` */ export declare function useNotionArchivePage(pageId: string): Promise>; /** * Retrieves a single Notion block by its ID. * * @param blockId - The block UUID. * @returns The block object with its type-specific content. * * @example * ```ts * const result = await useNotionGetBlock("block-id"); * ``` */ export declare function useNotionGetBlock(blockId: string): Promise>; /** * Retrieves the direct children blocks of a block (single page). * * @param blockId - The parent block ID (usually a page ID). * @param options - Pagination: `start_cursor`, `page_size` (max 100). * @returns Paginated list of child blocks. * * @example * ```ts * const result = await useNotionGetBlockChildren("page-id"); * ``` */ export declare function useNotionGetBlockChildren(blockId: string, options?: { start_cursor?: string; page_size?: number; }): Promise>; /** * Appends new child blocks to a parent block. * * @param blockId - The parent block ID (usually a page ID). * @param children - Array of block objects to append. * @returns The parent block. * * @example * ```ts * await useNotionAppendBlocks("page-id", [ * { type: "paragraph", paragraph: { rich_text: [{ type: "text", text: { content: "Hi" } }] } }, * ]); * ``` */ export declare function useNotionAppendBlocks(blockId: string, children: unknown[]): Promise>; /** * Updates the content of an existing block. * * @param blockId - The block UUID to update. * @param content - The new content for the block type. * @returns The updated block. * * @example * ```ts * await useNotionUpdateBlock("block-id", { * paragraph: { rich_text: [{ type: "text", text: { content: "Updated text" } }] }, * }); * ``` */ export declare function useNotionUpdateBlock(blockId: string, content: Record): Promise>; /** * Deletes (archives) a Notion block. * * @param blockId - The block UUID to delete. * @returns The deleted block. * * @example * ```ts * await useNotionDeleteBlock("block-id"); * ``` */ export declare function useNotionDeleteBlock(blockId: string): Promise>; /** * Retrieves a Notion database schema by its ID. * * @param databaseId - The database UUID. * @returns The database object with its full property schema. * * @example * ```ts * const result = await useNotionGetDatabase("db-id"); * ``` */ export declare function useNotionGetDatabase(databaseId: string): Promise>; /** * Queries a Notion database with filters and sorts (single page). * * @param databaseId - The database UUID to query. * @param query - Filter, sort, and pagination options. * @returns Paginated list of pages matching the query. * * @example * ```ts * const filtered = await useNotionQueryDatabase("db-id", { * filter: { property: "Status", select: { equals: "Done" } }, * }); * ``` */ export declare function useNotionQueryDatabase(databaseId: string, query?: NotionDatabaseQuery): Promise>; /** * Creates a new Notion database inside a page. * * @param parent - The parent page (`{ type: "page_id", page_id }`). * @param title - Database title as rich text array. * @param properties - Property schema definitions. * @returns The created database. * * @example * ```ts * await useNotionCreateDatabase( * { type: "page_id", page_id: "parent-id" }, * [{ type: "text", text: { content: "My Tasks" } }], * { Name: { title: {} } }, * ); * ``` */ export declare function useNotionCreateDatabase(parent: NotionParent, title: NotionRichText[], properties: Record): Promise>; /** * Updates a Notion database title and/or property schemas. * * @param databaseId - The database UUID to update. * @param title - New title as rich text array. * @param properties - Optional property schema updates to merge. * @returns The updated database. * * @example * ```ts * await useNotionUpdateDatabase("db-id", [{ type: "text", text: { content: "Renamed" } }]); * ``` */ export declare function useNotionUpdateDatabase(databaseId: string, title: NotionRichText[], properties?: Record): Promise>; /** * Retrieves a Notion workspace member or bot by their user ID. * * @param userId - The user UUID. * @returns The user object. * * @example * ```ts * const result = await useNotionGetUser("user-id"); * ``` */ export declare function useNotionGetUser(userId: string): Promise>; /** * Lists all users (members + bots) in the workspace (paginated). * * @param options - Pagination: `start_cursor`, `page_size` (max 100). * @returns Paginated list of users. * * @example * ```ts * const result = await useNotionListUsers(); * ``` */ export declare function useNotionListUsers(options?: { start_cursor?: string; page_size?: number; }): Promise>; /** * Searches across all pages and databases the integration has access to. * * @param query - Search options: text query, object type filter, sort direction. * @returns Paginated search results (mixed pages and databases). * * @example * ```ts * const result = await useNotionSearchContent({ query: "meeting notes" }); * ``` */ export declare function useNotionSearchContent(query: NotionSearchQuery): Promise>; /** * Fetches ALL child blocks of a block, automatically handling cursor pagination. * * @param blockId - The parent block ID (usually a page ID). * @param maxItems - Cap on the total number of blocks to fetch (default `1000`). * @returns All child blocks as a flat array. * * @example * ```ts * const result = await useNotionListAllBlockChildren("page-id"); * ``` */ export declare function useNotionListAllBlockChildren(blockId: string, maxItems?: number): Promise>; /** * Fetches ALL pages in a database, automatically handling cursor pagination. * * @param databaseId - The database UUID. * @param filter - Optional filter to apply (same syntax as Notion API). * @param sorts - Optional sort options. * @param maxItems - Cap on the total number of pages to fetch (default `1000`). * @returns All pages matching the filter as a flat array. * * @example * ```ts * const result = await useNotionListAllDatabasePages("db-id"); * ``` */ export declare function useNotionListAllDatabasePages(databaseId: string, filter?: NotionFilter, sorts?: NotionSort[], maxItems?: number): Promise>; //# sourceMappingURL=notion.service.d.ts.map