katanakit-js 3.1.3 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,397 @@
1
+ import type { FetchResult, NotionBlock, NotionBlockList, NotionConfig, NotionDatabase, NotionDatabaseQuery, NotionFilter, NotionPage, NotionPageList, NotionParent, NotionPropertySchema, NotionRichText, NotionSearchQuery, NotionSearchResult, NotionSort, NotionUser, NotionUserList } from "../../types/index.js";
2
+ /**
3
+ * Registers the Notion API configuration. Call this once before any other
4
+ * Notion function.
5
+ *
6
+ * @param cfg - Integration token (starts with "ntn_" or "secret_"), optional
7
+ * API version and base URL.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { useInitNotion } from "katanakit-js/adapters/notion";
12
+ *
13
+ * useInitNotion({ token: process.env.NOTION_TOKEN });
14
+ * ```
15
+ */
16
+ export declare function useInitNotion(cfg: NotionConfig): void;
17
+ /**
18
+ * Retrieves a single Notion page by its ID.
19
+ *
20
+ * Use when you need the full page object including all its properties
21
+ * (title, status, dates, relations, etc.).
22
+ *
23
+ * @param pageId - The page UUID.
24
+ * @returns The page object with all its properties.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const result = await useNotionGetPage("page-id");
29
+ * if (result.ok) console.log(result.data.properties);
30
+ * ```
31
+ */
32
+ export declare function useNotionGetPage(pageId: string): Promise<FetchResult<NotionPage>>;
33
+ /**
34
+ * Creates a new Notion page inside a database or as a child of another page.
35
+ *
36
+ * Use to add new entries to a database (tasks, notes, CRM records) or to
37
+ * create nested page structures.
38
+ *
39
+ * @param parent - Where to create the page: `{ type: "database_id", database_id }`
40
+ * for database entries, or `{ type: "page_id", page_id }` for child pages.
41
+ * @param properties - Page properties matching the parent database schema.
42
+ * @param children - Optional block children to populate the page content.
43
+ * @returns The created page.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * // Add a task to a database
48
+ * const result = await useNotionCreatePage(
49
+ * { type: "database_id", database_id: "db-id" },
50
+ * { Name: { title: [{ type: "text", text: { content: "My Task" } }] } },
51
+ * );
52
+ *
53
+ * // Create a child page with content
54
+ * const result = await useNotionCreatePage(
55
+ * { type: "page_id", page_id: "parent-id" },
56
+ * { title: { title: [{ type: "text", text: { content: "Child Page" } }] } },
57
+ * [{ type: "paragraph", paragraph: { rich_text: [{ type: "text", text: { content: "Hello!" } }] } }],
58
+ * );
59
+ * ```
60
+ */
61
+ export declare function useNotionCreatePage(parent: NotionParent, properties: Record<string, unknown>, children?: unknown[]): Promise<FetchResult<NotionPage>>;
62
+ /**
63
+ * Updates properties of an existing Notion page.
64
+ *
65
+ * Use to change a page's status, dates, relations, or any other property
66
+ * without touching the page content (blocks).
67
+ *
68
+ * @param pageId - The page UUID to update.
69
+ * @param properties - Properties to update (only changed properties).
70
+ * @returns The updated page.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * // Mark a task as done
75
+ * await useNotionUpdatePage("page-id", {
76
+ * Status: { select: { name: "Done" } },
77
+ * });
78
+ *
79
+ * // Update multiple properties
80
+ * await useNotionUpdatePage("page-id", {
81
+ * Priority: { select: { name: "High" } },
82
+ * DueDate: { date: { start: "2025-12-31" } },
83
+ * });
84
+ * ```
85
+ */
86
+ export declare function useNotionUpdatePage(pageId: string, properties: Record<string, unknown>): Promise<FetchResult<NotionPage>>;
87
+ /**
88
+ * Archives (soft-deletes) a Notion page. The page becomes hidden but
89
+ * can be restored from Notion's trash.
90
+ *
91
+ * @param pageId - The page UUID to archive.
92
+ * @returns The archived page.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * await useNotionArchivePage("page-id");
97
+ * ```
98
+ */
99
+ export declare function useNotionArchivePage(pageId: string): Promise<FetchResult<NotionPage>>;
100
+ /**
101
+ * Retrieves a single Notion block by its ID.
102
+ *
103
+ * A block is any content element: paragraph, heading, list item, image,
104
+ * table, callout, etc. Use to inspect a specific block's type and content.
105
+ *
106
+ * @param blockId - The block UUID.
107
+ * @returns The block object with its type-specific content.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const result = await useNotionGetBlock("block-id");
112
+ * if (result.ok) console.log(result.data.type); // "paragraph", "heading_1", etc.
113
+ * ```
114
+ */
115
+ export declare function useNotionGetBlock(blockId: string): Promise<FetchResult<NotionBlock>>;
116
+ /**
117
+ * Retrieves the direct children blocks of a block (single page).
118
+ *
119
+ * Use for manual pagination when you need fine-grained control over
120
+ * cursor-based pagination. For most cases, prefer
121
+ * {@link useNotionListAllBlockChildren} which handles pagination automatically.
122
+ *
123
+ * @param blockId - The parent block ID (usually a page ID).
124
+ * @param options - Pagination: `start_cursor` for next page, `page_size` (max 100).
125
+ * @returns Paginated list of child blocks with `has_more` and `next_cursor`.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const result = await useNotionGetBlockChildren("page-id");
130
+ * if (result.ok) {
131
+ * console.log(result.data.results); // First page of blocks
132
+ * if (result.data.has_more) {
133
+ * // Fetch next page with result.data.next_cursor
134
+ * }
135
+ * }
136
+ * ```
137
+ */
138
+ export declare function useNotionGetBlockChildren(blockId: string, options?: {
139
+ start_cursor?: string;
140
+ page_size?: number;
141
+ }): Promise<FetchResult<NotionBlockList>>;
142
+ /**
143
+ * Appends new child blocks to a parent block.
144
+ *
145
+ * Use to add content to a page: paragraphs, headings, lists, toggles,
146
+ * code blocks, etc. Blocks are appended at the end.
147
+ *
148
+ * @param blockId - The parent block ID (usually a page ID).
149
+ * @param children - Array of block objects to append.
150
+ * @returns The parent block.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * await useNotionAppendBlocks("page-id", [
155
+ * {
156
+ * type: "heading_2",
157
+ * heading_2: { rich_text: [{ type: "text", text: { content: "Section Title" } }] },
158
+ * },
159
+ * {
160
+ * type: "paragraph",
161
+ * paragraph: { rich_text: [{ type: "text", text: { content: "Body text here." } }] },
162
+ * },
163
+ * ]);
164
+ * ```
165
+ */
166
+ export declare function useNotionAppendBlocks(blockId: string, children: unknown[]): Promise<FetchResult<NotionBlock>>;
167
+ /**
168
+ * Updates the content of an existing block.
169
+ *
170
+ * Use to modify text, toggle content, code blocks, etc. without
171
+ * deleting and recreating the block.
172
+ *
173
+ * @param blockId - The block UUID to update.
174
+ * @param content - The new content for the block type (e.g. `{ paragraph: { rich_text: [...] } }`).
175
+ * @returns The updated block.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * await useNotionUpdateBlock("block-id", {
180
+ * paragraph: { rich_text: [{ type: "text", text: { content: "Updated text" } }] },
181
+ * });
182
+ * ```
183
+ */
184
+ export declare function useNotionUpdateBlock(blockId: string, content: Record<string, unknown>): Promise<FetchResult<NotionBlock>>;
185
+ /**
186
+ * Deletes (archives) a Notion block. The block is soft-deleted and
187
+ * can be restored.
188
+ *
189
+ * @param blockId - The block UUID to delete.
190
+ * @returns The deleted block.
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * await useNotionDeleteBlock("block-id");
195
+ * ```
196
+ */
197
+ export declare function useNotionDeleteBlock(blockId: string): Promise<FetchResult<NotionBlock>>;
198
+ /**
199
+ * Retrieves a Notion database schema by its ID.
200
+ *
201
+ * Use to inspect the database structure: property names, types, and
202
+ * configuration (select options, formula definitions, etc.).
203
+ *
204
+ * @param databaseId - The database UUID.
205
+ * @returns The database object with its full property schema.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * const result = await useNotionGetDatabase("db-id");
210
+ * if (result.ok) {
211
+ * // See all available properties
212
+ * Object.entries(result.data.properties).forEach(([name, prop]) => {
213
+ * console.log(`${name}: ${prop.type}`);
214
+ * });
215
+ * }
216
+ * ```
217
+ */
218
+ export declare function useNotionGetDatabase(databaseId: string): Promise<FetchResult<NotionDatabase>>;
219
+ /**
220
+ * Queries a Notion database with filters and sorts (single page).
221
+ *
222
+ * Use for manual pagination or when you only need the first page of
223
+ * results. For most cases, prefer {@link useNotionListAllDatabasePages}
224
+ * which handles pagination automatically.
225
+ *
226
+ * @param databaseId - The database UUID to query.
227
+ * @param query - Filter, sort, and pagination options.
228
+ * @returns Paginated list of pages matching the query.
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * // Get first page of all entries
233
+ * const all = await useNotionQueryDatabase("db-id");
234
+ *
235
+ * // With filter and sort
236
+ * const filtered = await useNotionQueryDatabase("db-id", {
237
+ * filter: { property: "Status", select: { equals: "Done" } },
238
+ * sorts: [{ property: "Date", direction: "descending" }],
239
+ * page_size: 10,
240
+ * });
241
+ * ```
242
+ */
243
+ export declare function useNotionQueryDatabase(databaseId: string, query?: NotionDatabaseQuery): Promise<FetchResult<NotionPageList>>;
244
+ /**
245
+ * Creates a new Notion database inside a page.
246
+ *
247
+ * Use to programmatically create structured databases with custom
248
+ * property schemas (select options, formulas, relations, etc.).
249
+ *
250
+ * @param parent - The parent page (`{ type: "page_id", page_id }`).
251
+ * @param title - Database title as rich text array.
252
+ * @param properties - Property schema definitions (Name, Status, Date, etc.).
253
+ * @returns The created database.
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * await useNotionCreateDatabase(
258
+ * { type: "page_id", page_id: "parent-id" },
259
+ * [{ type: "text", text: { content: "My Tasks" } }],
260
+ * {
261
+ * Name: { title: {} },
262
+ * Status: { select: { options: [{ name: "To Do" }, { name: "Done" }] } },
263
+ * Priority: { select: { options: [{ name: "Low" }, { name: "High" }] } },
264
+ * },
265
+ * );
266
+ * ```
267
+ */
268
+ export declare function useNotionCreateDatabase(parent: NotionParent, title: NotionRichText[], properties: Record<string, NotionPropertySchema>): Promise<FetchResult<NotionDatabase>>;
269
+ /**
270
+ * Updates a Notion database title and/or property schemas.
271
+ *
272
+ * Use to rename a database or add/modify property definitions.
273
+ *
274
+ * @param databaseId - The database UUID to update.
275
+ * @param title - New title as rich text array.
276
+ * @param properties - Optional property schema updates to merge.
277
+ * @returns The updated database.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * await useNotionUpdateDatabase("db-id", [
282
+ * { type: "text", text: { content: "Renamed Database" } },
283
+ * ]);
284
+ * ```
285
+ */
286
+ export declare function useNotionUpdateDatabase(databaseId: string, title: NotionRichText[], properties?: Record<string, NotionPropertySchema>): Promise<FetchResult<NotionDatabase>>;
287
+ /**
288
+ * Retrieves a Notion workspace member or bot by their user ID.
289
+ *
290
+ * Use to get display name, avatar, or email of the person who created
291
+ * or last edited a page.
292
+ *
293
+ * @param userId - The user UUID (from page.created_by.id or page.last_edited_by.id).
294
+ * @returns The user object.
295
+ *
296
+ * @example
297
+ * ```ts
298
+ * const result = await useNotionGetUser("user-id");
299
+ * if (result.ok) console.log(result.data.name);
300
+ * ```
301
+ */
302
+ export declare function useNotionGetUser(userId: string): Promise<FetchResult<NotionUser>>;
303
+ /**
304
+ * Lists all users (members + bots) in the workspace (paginated).
305
+ *
306
+ * Use to enumerate workspace members for assignment, mention, or
307
+ * permission checks.
308
+ *
309
+ * @param options - Pagination: `start_cursor`, `page_size` (max 100).
310
+ * @returns Paginated list of users.
311
+ *
312
+ * @example
313
+ * ```ts
314
+ * const result = await useNotionListUsers();
315
+ * if (result.ok) result.data.results.forEach(u => console.log(u.name));
316
+ * ```
317
+ */
318
+ export declare function useNotionListUsers(options?: {
319
+ start_cursor?: string;
320
+ page_size?: number;
321
+ }): Promise<FetchResult<NotionUserList>>;
322
+ /**
323
+ * Searches across all pages and databases the integration has access to.
324
+ *
325
+ * Use to find content by keyword when you don't have the page/database ID.
326
+ * Supports filtering by object type (page or database) and sorting by
327
+ * last edit time.
328
+ *
329
+ * @param query - Search options: text query, object type filter, sort direction.
330
+ * @returns Paginated search results (mixed pages and databases).
331
+ *
332
+ * @example
333
+ * ```ts
334
+ * // Search everything for a keyword
335
+ * const result = await useNotionSearchContent({ query: "meeting notes" });
336
+ *
337
+ * // Search only databases
338
+ * const dbs = await useNotionSearchContent({
339
+ * query: "tasks",
340
+ * filter: { value: "database", property: "object" },
341
+ * });
342
+ *
343
+ * // Search only pages, sorted by recent
344
+ * const pages = await useNotionSearchContent({
345
+ * filter: { value: "page", property: "object" },
346
+ * sort: { direction: "descending", timestamp: "last_edited_time" },
347
+ * });
348
+ * ```
349
+ */
350
+ export declare function useNotionSearchContent(query: NotionSearchQuery): Promise<FetchResult<NotionSearchResult>>;
351
+ /**
352
+ * Fetches ALL child blocks of a block, automatically handling cursor pagination.
353
+ *
354
+ * Use when you need the complete content of a page without worrying about
355
+ * pagination cursors. Loops through all pages until `has_more` is false.
356
+ *
357
+ * @param blockId - The parent block ID (usually a page ID).
358
+ * @returns All child blocks as a flat array.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * const result = await useNotionListAllBlockChildren("page-id");
363
+ * if (result.ok) {
364
+ * console.log(`Total blocks: ${result.data.length}`);
365
+ * result.data.forEach(block => console.log(block.type));
366
+ * }
367
+ * ```
368
+ */
369
+ export declare function useNotionListAllBlockChildren(blockId: string): Promise<FetchResult<NotionBlock[]>>;
370
+ /**
371
+ * Fetches ALL pages in a database, automatically handling cursor pagination.
372
+ *
373
+ * Use when you need every entry from a database without worrying about
374
+ * pagination. Supports optional filters and sorts. Loops through all
375
+ * pages until `has_more` is false.
376
+ *
377
+ * @param databaseId - The database UUID.
378
+ * @param filter - Optional filter to apply (same syntax as Notion API).
379
+ * @param sorts - Optional sort options.
380
+ * @returns All pages matching the filter as a flat array.
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * // Get ALL pages in a database
385
+ * const result = await useNotionListAllDatabasePages("db-id");
386
+ * if (result.ok) console.log(`Total entries: ${result.data.length}`);
387
+ *
388
+ * // Get only published pages, sorted by date
389
+ * const published = await useNotionListAllDatabasePages(
390
+ * "db-id",
391
+ * { property: "Status", select: { equals: "Published" } },
392
+ * [{ property: "Date", direction: "descending" }],
393
+ * );
394
+ * ```
395
+ */
396
+ export declare function useNotionListAllDatabasePages(databaseId: string, filter?: NotionFilter, sorts?: NotionSort[]): Promise<FetchResult<NotionPage[]>>;
397
+ //# sourceMappingURL=notion.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notion.service.d.ts","sourceRoot":"","sources":["../../../src/adapters/notion/notion.service.ts"],"names":[],"mappings":"AAAA,OAA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