@visus-io/notion-sdk-ts 3.0.2 → 3.1.0
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.
- package/README.md +7 -6
- package/dist/api/asyncTasks.api.d.ts +70 -0
- package/dist/api/asyncTasks.api.js +68 -0
- package/dist/api/base.api.js +1 -0
- package/dist/api/blocks.api.d.ts +433 -73
- package/dist/api/blocks.api.js +39 -0
- package/dist/api/comments.api.d.ts +40 -5
- package/dist/api/comments.api.js +43 -1
- package/dist/api/customEmojis.api.d.ts +36 -0
- package/dist/api/customEmojis.api.js +36 -0
- package/dist/api/dataSources.api.d.ts +62 -11
- package/dist/api/dataSources.api.js +22 -0
- package/dist/api/databases.api.d.ts +40 -6
- package/dist/api/fileUploads.api.d.ts +1 -1
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +7 -1
- package/dist/api/pages.api.d.ts +142 -10
- package/dist/api/pages.api.js +64 -0
- package/dist/api/search.api.d.ts +10 -2
- package/dist/api/users.api.d.ts +1 -0
- package/dist/api/views.api.d.ts +284 -0
- package/dist/api/views.api.js +169 -0
- package/dist/client.js +3 -3
- package/dist/errors.d.ts +5 -1
- package/dist/errors.js +6 -0
- package/dist/helpers/block.helpers.d.ts +38 -1
- package/dist/helpers/block.helpers.js +45 -3
- package/dist/helpers/file.helpers.d.ts +36 -1
- package/dist/helpers/file.helpers.js +26 -4
- package/dist/helpers/filter.helpers.d.ts +6 -6
- package/dist/helpers/index.d.ts +3 -2
- package/dist/helpers/index.js +5 -1
- package/dist/helpers/pagination.helpers.d.ts +56 -0
- package/dist/helpers/pagination.helpers.js +86 -0
- package/dist/helpers/property.helpers.d.ts +29 -0
- package/dist/helpers/property.helpers.js +27 -0
- package/dist/helpers/webhook.helpers.d.ts +52 -0
- package/dist/helpers/webhook.helpers.js +81 -0
- package/dist/models/asyncTask.model.d.ts +59 -0
- package/dist/models/asyncTask.model.js +89 -0
- package/dist/models/block.model.js +4 -1
- package/dist/models/customEmoji.model.d.ts +28 -0
- package/dist/models/customEmoji.model.js +42 -0
- package/dist/models/dataSource.model.d.ts +3 -3
- package/dist/models/dataSource.model.js +1 -1
- package/dist/models/database.model.d.ts +7 -3
- package/dist/models/database.model.js +7 -1
- package/dist/models/index.d.ts +3 -0
- package/dist/models/index.js +7 -1
- package/dist/models/page.model.d.ts +2 -0
- package/dist/models/page.model.js +6 -0
- package/dist/models/view.model.d.ts +79 -0
- package/dist/models/view.model.js +119 -0
- package/dist/notion.d.ts +26 -7
- package/dist/notion.js +19 -3
- package/dist/schemas/asyncTask.schema.d.ts +42 -0
- package/dist/schemas/asyncTask.schema.js +83 -0
- package/dist/schemas/block.schema.d.ts +378 -72
- package/dist/schemas/block.schema.js +33 -7
- package/dist/schemas/comment.schema.d.ts +8 -3
- package/dist/schemas/customEmoji.schema.d.ts +13 -0
- package/dist/schemas/customEmoji.schema.js +48 -0
- package/dist/schemas/dataSource.schema.d.ts +68 -10
- package/dist/schemas/dataSource.schema.js +22 -4
- package/dist/schemas/database.schema.d.ts +38 -6
- package/dist/schemas/database.schema.js +3 -2
- package/dist/schemas/fileUpload.schema.d.ts +1 -1
- package/dist/schemas/icon.schema.d.ts +92 -0
- package/dist/schemas/icon.schema.js +88 -0
- package/dist/schemas/index.d.ts +6 -0
- package/dist/schemas/index.js +6 -0
- package/dist/schemas/meetingNotesQuery.schema.d.ts +4187 -0
- package/dist/schemas/meetingNotesQuery.schema.js +62 -0
- package/dist/schemas/page.schema.d.ts +46 -9
- package/dist/schemas/page.schema.js +4 -2
- package/dist/schemas/pageMarkdown.schema.d.ts +59 -0
- package/dist/schemas/pageMarkdown.schema.js +65 -0
- package/dist/schemas/pageProperties.schema.d.ts +30 -18
- package/dist/schemas/pageProperties.schema.js +2 -3
- package/dist/schemas/pagination.schema.d.ts +30 -3
- package/dist/schemas/pagination.schema.js +18 -1
- package/dist/schemas/parent.schema.d.ts +10 -1
- package/dist/schemas/parent.schema.js +9 -3
- package/dist/schemas/propertyObjects.schema.d.ts +12 -12
- package/dist/schemas/richText.schema.d.ts +8 -6
- package/dist/schemas/richText.schema.js +1 -1
- package/dist/schemas/user.schema.d.ts +2 -0
- package/dist/schemas/user.schema.js +2 -1
- package/dist/schemas/view.schema.d.ts +1077 -0
- package/dist/schemas/view.schema.js +115 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@ A type-safe TypeScript SDK for the Notion API with Zod validation, OOP models, a
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
15
|
- **Type-safe** Zod v4 runtime validation on every API response; full TypeScript declarations
|
|
16
|
-
- **Complete API coverage** Pages, Blocks, Databases, Data Sources, Comments, Search, Users, File Uploads
|
|
17
|
-
- **Ergonomic helpers** `block`, `richText`, `filter`, `sort`, `prop`, `parent`, `icon`, `cover`, `paginate` factories eliminate verbose JSON
|
|
18
|
-
- **OOP models** `Page`, `Block`, `Database`, `User`, `Comment`, `DataSource`, `FileUpload`, `RichText` with convenience methods
|
|
19
|
-
- **Automatic pagination** `paginate()` and `
|
|
16
|
+
- **Complete API coverage** Pages, Blocks, Databases, Data Sources, Comments, Search, Users, File Uploads, Async Tasks, Custom Emojis, Views
|
|
17
|
+
- **Ergonomic helpers** `block`, `richText`, `filter`, `sort`, `prop`, `parent`, `icon`, `cover`, `paginate` factories and a `webhook` signature-verification helper eliminate verbose JSON and boilerplate
|
|
18
|
+
- **OOP models** `Page`, `Block`, `Database`, `User`, `Comment`, `DataSource`, `FileUpload`, `RichText`, `AsyncTask`, `CustomEmoji`, `View` with convenience methods
|
|
19
|
+
- **Automatic pagination** `paginate()`, `paginateIterator()`, and `paginateWithMetadata()` helpers automatically fetch all pages, plus `iterateAllDataSourceRows()`/`collectAllDataSourceRows()` to work around the 10,000-result query cap
|
|
20
20
|
- **Automatic rate limiting** Respects `Retry-After` header with exponential backoff fallback (configurable)
|
|
21
21
|
- **Client-side size validation** Enforces Notion API size limits before sending requests
|
|
22
22
|
- **Zero bloat** Single runtime dependency (`zod`); uses built-in `fetch` (Node 18+)
|
|
@@ -110,7 +110,7 @@ Comprehensive documentation is available in the [**GitHub Wiki**](https://github
|
|
|
110
110
|
|
|
111
111
|
- **`archived` → `in_trash`**: Field renamed across all schemas, models, and API request bodies
|
|
112
112
|
- **`after` → `position` object**: `blocks.children.append()` now accepts a typed `position` union
|
|
113
|
-
- **`transcription` → `meeting_notes`**: Block type and helper renamed
|
|
113
|
+
- **`transcription` → `meeting_notes`**: Block type and helper renamed (`block.meetingNotes()` is itself now deprecated — meeting-notes blocks are server-managed, not client-constructed)
|
|
114
114
|
- **`notionVersion` removed**: Use the exported `NOTION_VERSION` constant to inspect the target version
|
|
115
115
|
|
|
116
116
|
### Quick Migration Example (v2.x → v3.x)
|
|
@@ -131,7 +131,8 @@ await notion.blocks.children.append('page-id', {
|
|
|
131
131
|
children: [block.paragraph('text')],
|
|
132
132
|
position: { type: 'after_block', after_block: { id: 'block-id' } },
|
|
133
133
|
});
|
|
134
|
-
|
|
134
|
+
// Meeting notes are server-managed — read them instead of constructing them:
|
|
135
|
+
await notion.blocks.meetingNotes.query();
|
|
135
136
|
```
|
|
136
137
|
|
|
137
138
|
### Key Changes (v2.x — 2025-09-03)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { NotionClient } from '../client';
|
|
2
|
+
import { AsyncTask } from '../models';
|
|
3
|
+
import { type NotionAsyncTask } from '../schemas';
|
|
4
|
+
import { BaseAPI } from './base.api';
|
|
5
|
+
/**
|
|
6
|
+
* Options for polling an async task until completion.
|
|
7
|
+
*/
|
|
8
|
+
export interface PollAsyncTaskOptions {
|
|
9
|
+
/** Maximum time to wait for the task to complete, in milliseconds (default: 300000 / 5 minutes) */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Async Tasks API client for polling long-running Notion operations.
|
|
14
|
+
*/
|
|
15
|
+
export declare class AsyncTasksAPI extends BaseAPI<NotionAsyncTask, AsyncTask> {
|
|
16
|
+
protected readonly client: NotionClient;
|
|
17
|
+
protected config: {
|
|
18
|
+
schema: import("zod").ZodObject<{
|
|
19
|
+
object: import("zod").ZodLiteral<"async_task">;
|
|
20
|
+
id: import("zod").ZodUUID;
|
|
21
|
+
status: import("zod").ZodEnum<{
|
|
22
|
+
queued: "queued";
|
|
23
|
+
running: "running";
|
|
24
|
+
retrying: "retrying";
|
|
25
|
+
succeeded: "succeeded";
|
|
26
|
+
failed: "failed";
|
|
27
|
+
}>;
|
|
28
|
+
status_url: import("zod").ZodURL;
|
|
29
|
+
created_time: import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>;
|
|
30
|
+
operation: import("zod").ZodObject<{
|
|
31
|
+
surface: import("zod").ZodEnum<{
|
|
32
|
+
rest: "rest";
|
|
33
|
+
mcp: "mcp";
|
|
34
|
+
}>;
|
|
35
|
+
name: import("zod").ZodString;
|
|
36
|
+
}, import("zod/v4/core").$strip>;
|
|
37
|
+
poll_after_seconds: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
38
|
+
result: import("zod").ZodOptional<import("zod").ZodUnknown>;
|
|
39
|
+
error: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
40
|
+
object: import("zod").ZodLiteral<"error">;
|
|
41
|
+
status: import("zod").ZodNumber;
|
|
42
|
+
code: import("zod").ZodString;
|
|
43
|
+
message: import("zod").ZodString;
|
|
44
|
+
}, import("zod/v4/core").$strip>>;
|
|
45
|
+
}, import("zod/v4/core").$strip>;
|
|
46
|
+
ModelClass: typeof AsyncTask;
|
|
47
|
+
};
|
|
48
|
+
constructor(client: NotionClient);
|
|
49
|
+
/**
|
|
50
|
+
* Retrieve the current status of an async task.
|
|
51
|
+
*
|
|
52
|
+
* @param taskId - The ID of the async task to retrieve
|
|
53
|
+
* @returns The task wrapped in an AsyncTask model
|
|
54
|
+
*
|
|
55
|
+
* @see https://developers.notion.com/reference/retrieve-async-task
|
|
56
|
+
*/
|
|
57
|
+
retrieve(taskId: string): Promise<AsyncTask>;
|
|
58
|
+
/**
|
|
59
|
+
* Poll an async task until it reaches a terminal status (succeeded or failed),
|
|
60
|
+
* waiting at least `poll_after_seconds` (from the response body, not a header)
|
|
61
|
+
* between polls, per the API's guidance.
|
|
62
|
+
*
|
|
63
|
+
* @param taskId - The ID of the async task to poll
|
|
64
|
+
* @param options - Polling options
|
|
65
|
+
* @returns The task wrapped in an AsyncTask model, once it reaches a terminal status
|
|
66
|
+
*
|
|
67
|
+
* @throws {NotionRequestTimeoutError} If the task doesn't complete within `timeoutMs`
|
|
68
|
+
*/
|
|
69
|
+
poll(taskId: string, options?: PollAsyncTaskOptions): Promise<AsyncTask>;
|
|
70
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncTasksAPI = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const models_1 = require("../models");
|
|
6
|
+
const schemas_1 = require("../schemas");
|
|
7
|
+
const base_api_1 = require("./base.api");
|
|
8
|
+
function sleep(ms) {
|
|
9
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Async Tasks API client for polling long-running Notion operations.
|
|
13
|
+
*/
|
|
14
|
+
class AsyncTasksAPI extends base_api_1.BaseAPI {
|
|
15
|
+
constructor(client) {
|
|
16
|
+
super(client);
|
|
17
|
+
this.client = client;
|
|
18
|
+
this.config = {
|
|
19
|
+
schema: schemas_1.asyncTaskSchema,
|
|
20
|
+
ModelClass: models_1.AsyncTask,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Retrieve the current status of an async task.
|
|
25
|
+
*
|
|
26
|
+
* @param taskId - The ID of the async task to retrieve
|
|
27
|
+
* @returns The task wrapped in an AsyncTask model
|
|
28
|
+
*
|
|
29
|
+
* @see https://developers.notion.com/reference/retrieve-async-task
|
|
30
|
+
*/
|
|
31
|
+
async retrieve(taskId) {
|
|
32
|
+
return this.retrieveResource(`/async_tasks/${taskId}`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Poll an async task until it reaches a terminal status (succeeded or failed),
|
|
36
|
+
* waiting at least `poll_after_seconds` (from the response body, not a header)
|
|
37
|
+
* between polls, per the API's guidance.
|
|
38
|
+
*
|
|
39
|
+
* @param taskId - The ID of the async task to poll
|
|
40
|
+
* @param options - Polling options
|
|
41
|
+
* @returns The task wrapped in an AsyncTask model, once it reaches a terminal status
|
|
42
|
+
*
|
|
43
|
+
* @throws {NotionRequestTimeoutError} If the task doesn't complete within `timeoutMs`
|
|
44
|
+
*/
|
|
45
|
+
async poll(taskId, options) {
|
|
46
|
+
const deadline = Date.now() + (options?.timeoutMs ?? 300_000);
|
|
47
|
+
for (;;) {
|
|
48
|
+
const task = await this.retrieve(taskId);
|
|
49
|
+
if (task.isTerminal()) {
|
|
50
|
+
return task;
|
|
51
|
+
}
|
|
52
|
+
const remainingMs = deadline - Date.now();
|
|
53
|
+
if (remainingMs <= 0) {
|
|
54
|
+
throw new errors_1.NotionRequestTimeoutError(`Task ${taskId} did not complete within timeout`);
|
|
55
|
+
}
|
|
56
|
+
const desiredSleepMs = Math.max((task.pollAfterSeconds ?? 1) * 1000, 250);
|
|
57
|
+
if (desiredSleepMs >= remainingMs) {
|
|
58
|
+
// Sleeping the full poll_after_seconds would overshoot the deadline -- cap the
|
|
59
|
+
// sleep to what's left and time out immediately after, instead of sleeping the
|
|
60
|
+
// full interval and only detecting the timeout on the next loop iteration.
|
|
61
|
+
await sleep(remainingMs);
|
|
62
|
+
throw new errors_1.NotionRequestTimeoutError(`Task ${taskId} did not complete within timeout`);
|
|
63
|
+
}
|
|
64
|
+
await sleep(desiredSleepMs);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.AsyncTasksAPI = AsyncTasksAPI;
|