@visus-io/notion-sdk-ts 3.1.0 → 3.1.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.
- package/README.md +17 -85
- package/dist/api/asyncTasks.api.d.ts +5 -3
- package/dist/api/asyncTasks.api.js +5 -3
- package/dist/api/base.api.d.ts +15 -4
- package/dist/api/base.api.js +19 -8
- package/dist/api/blocks.api.d.ts +2 -0
- package/dist/api/blocks.api.js +5 -2
- package/dist/api/comments.api.d.ts +2 -0
- package/dist/api/comments.api.js +2 -0
- package/dist/api/customEmojis.api.d.ts +2 -0
- package/dist/api/customEmojis.api.js +2 -0
- package/dist/api/dataSources.api.d.ts +5 -3
- package/dist/api/dataSources.api.js +4 -1
- package/dist/api/databases.api.d.ts +7 -5
- package/dist/api/databases.api.js +4 -1
- package/dist/api/fileUploads.api.d.ts +7 -4
- package/dist/api/fileUploads.api.js +11 -7
- package/dist/api/pages.api.d.ts +5 -3
- package/dist/api/pages.api.js +5 -3
- package/dist/api/search.api.d.ts +4 -2
- package/dist/api/search.api.js +5 -2
- package/dist/api/users.api.d.ts +2 -0
- package/dist/api/users.api.js +2 -0
- package/dist/api/views.api.d.ts +15 -13
- package/dist/api/views.api.js +10 -7
- package/dist/client.d.ts +17 -17
- package/dist/client.js +22 -27
- package/dist/errors.d.ts +14 -4
- package/dist/errors.js +10 -4
- package/dist/helpers/block.helpers.d.ts +22 -15
- package/dist/helpers/block.helpers.js +14 -12
- package/dist/helpers/file.helpers.d.ts +12 -6
- package/dist/helpers/file.helpers.js +12 -6
- package/dist/helpers/filter.helpers.d.ts +2 -0
- package/dist/helpers/filter.helpers.js +2 -0
- package/dist/helpers/pagination.helpers.d.ts +52 -36
- package/dist/helpers/pagination.helpers.js +49 -29
- package/dist/helpers/parent.helpers.d.ts +5 -3
- package/dist/helpers/parent.helpers.js +5 -3
- package/dist/helpers/property.helpers.d.ts +2 -0
- package/dist/helpers/property.helpers.js +3 -1
- package/dist/helpers/richText.helpers.d.ts +10 -5
- package/dist/helpers/richText.helpers.js +11 -6
- package/dist/helpers/sort.helpers.d.ts +2 -0
- package/dist/helpers/sort.helpers.js +2 -0
- package/dist/helpers/webhook.helpers.d.ts +14 -12
- package/dist/helpers/webhook.helpers.js +17 -15
- package/dist/models/asyncTask.model.d.ts +8 -6
- package/dist/models/asyncTask.model.js +8 -6
- package/dist/models/base.model.d.ts +16 -4
- package/dist/models/base.model.js +17 -5
- package/dist/models/block.model.d.ts +6 -2
- package/dist/models/block.model.js +48 -36
- package/dist/models/comment.model.d.ts +4 -2
- package/dist/models/comment.model.js +4 -2
- package/dist/models/customEmoji.model.d.ts +7 -5
- package/dist/models/customEmoji.model.js +7 -5
- package/dist/models/dataSource.model.d.ts +4 -2
- package/dist/models/dataSource.model.js +4 -2
- package/dist/models/database.model.d.ts +6 -2
- package/dist/models/database.model.js +8 -4
- package/dist/models/fileUpload.model.d.ts +6 -4
- package/dist/models/fileUpload.model.js +6 -4
- package/dist/models/page.model.d.ts +6 -2
- package/dist/models/page.model.js +8 -4
- package/dist/models/richText.model.d.ts +3 -1
- package/dist/models/richText.model.js +3 -1
- package/dist/models/user.model.d.ts +4 -2
- package/dist/models/user.model.js +4 -2
- package/dist/models/view.model.d.ts +9 -7
- package/dist/models/view.model.js +9 -7
- package/dist/notion.d.ts +6 -1
- package/dist/notion.js +6 -1
- package/dist/schemas/asyncTask.schema.d.ts +11 -0
- package/dist/schemas/asyncTask.schema.js +5 -0
- package/dist/schemas/block.schema.d.ts +12 -1
- package/dist/schemas/block.schema.js +6 -1
- package/dist/schemas/codeLanguages.d.ts +7 -1
- package/dist/schemas/codeLanguages.js +4 -1
- package/dist/schemas/colors.d.ts +7 -1
- package/dist/schemas/colors.js +4 -1
- package/dist/schemas/comment.schema.d.ts +20 -2
- package/dist/schemas/comment.schema.js +11 -2
- package/dist/schemas/customEmoji.schema.d.ts +5 -0
- package/dist/schemas/customEmoji.schema.js +2 -0
- package/dist/schemas/dataSource.schema.d.ts +19 -3
- package/dist/schemas/dataSource.schema.js +12 -5
- package/dist/schemas/database.schema.d.ts +13 -1
- package/dist/schemas/database.schema.js +7 -1
- package/dist/schemas/emoji.schema.d.ts +7 -2
- package/dist/schemas/emoji.schema.js +4 -2
- package/dist/schemas/file.schema.d.ts +18 -2
- package/dist/schemas/file.schema.js +6 -2
- package/dist/schemas/fileUpload.schema.d.ts +8 -2
- package/dist/schemas/fileUpload.schema.js +5 -2
- package/dist/schemas/icon.schema.d.ts +28 -4
- package/dist/schemas/icon.schema.js +16 -4
- package/dist/schemas/meetingNotesQuery.schema.d.ts +13 -2
- package/dist/schemas/meetingNotesQuery.schema.js +7 -2
- package/dist/schemas/page.schema.d.ts +5 -0
- package/dist/schemas/page.schema.js +2 -0
- package/dist/schemas/pageMarkdown.schema.d.ts +15 -4
- package/dist/schemas/pageMarkdown.schema.js +9 -4
- package/dist/schemas/pageProperties.schema.d.ts +75 -3
- package/dist/schemas/pageProperties.schema.js +6 -3
- package/dist/schemas/pagination.schema.d.ts +33 -10
- package/dist/schemas/pagination.schema.js +12 -5
- package/dist/schemas/parent.schema.d.ts +29 -2
- package/dist/schemas/parent.schema.js +8 -2
- package/dist/schemas/propertyObjects.schema.d.ts +81 -3
- package/dist/schemas/propertyObjects.schema.js +11 -5
- package/dist/schemas/richText.schema.d.ts +15 -0
- package/dist/schemas/richText.schema.js +6 -3
- package/dist/schemas/shared.schema.d.ts +6 -3
- package/dist/schemas/shared.schema.js +6 -3
- package/dist/schemas/user.schema.d.ts +15 -0
- package/dist/schemas/user.schema.js +5 -2
- package/dist/schemas/view.schema.d.ts +43 -9
- package/dist/schemas/view.schema.js +28 -9
- package/dist/validation.d.ts +11 -4
- package/dist/validation.js +11 -4
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ A type-safe TypeScript SDK for the Notion API with Zod validation, OOP models, a
|
|
|
14
14
|
|
|
15
15
|
- **Type-safe** Zod v4 runtime validation on every API response; full TypeScript declarations
|
|
16
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`, `
|
|
17
|
+
- **Ergonomic helpers** `block`, `richText`, `filter`, `sort`, `prop`, `parent`, `icon`, `cover`, and `notionFile` factories, plus a `webhook` signature-verification helper, eliminate verbose JSON and boilerplate
|
|
18
18
|
- **OOP models** `Page`, `Block`, `Database`, `User`, `Comment`, `DataSource`, `FileUpload`, `RichText`, `AsyncTask`, `CustomEmoji`, `View` with convenience methods
|
|
19
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)
|
|
@@ -76,92 +76,16 @@ const results = await notion.databases.query('database-id', {
|
|
|
76
76
|
|
|
77
77
|
## Documentation
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
Full documentation is hosted at [nts.projects.visus.io](https://nts.projects.visus.io). It includes guides and a generated API reference. Source lives in [`docs/`](./docs). It has its own dependencies, separate from the root project. Install them once, then run the site locally:
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
- [**Migration Guide**](https://github.com/visus-io/notion-sdk-ts/wiki/Migration-Guide) - Migrating between API versions
|
|
85
|
-
- [**Common Use Cases**](https://github.com/visus-io/notion-sdk-ts/wiki/Common-Use-Cases) - Practical examples and workflows
|
|
86
|
-
|
|
87
|
-
### Core Concepts
|
|
88
|
-
|
|
89
|
-
- [**Helpers**](https://github.com/visus-io/notion-sdk-ts/wiki/Helpers) - Rich Text, Block Builder, Properties, Filters, Sorting
|
|
90
|
-
- [**Models**](https://github.com/visus-io/notion-sdk-ts/wiki/Models) - Page, Block, Database, DataSource, User, Comment, FileUpload
|
|
91
|
-
- [**API Reference**](https://github.com/visus-io/notion-sdk-ts/wiki/API-Reference) - Complete API endpoint documentation
|
|
92
|
-
|
|
93
|
-
### Configuration & Advanced Topics
|
|
94
|
-
|
|
95
|
-
- [**Configuration & Features**](https://github.com/visus-io/notion-sdk-ts/wiki/Configuration) - Client options, rate limiting, retries
|
|
96
|
-
- [**Error Handling**](https://github.com/visus-io/notion-sdk-ts/wiki/Error-Handling) - Error types, codes, and handling patterns
|
|
97
|
-
- [**Pagination**](https://github.com/visus-io/notion-sdk-ts/wiki/Pagination) - Automatic pagination helpers
|
|
98
|
-
- [**Request Size Limits**](https://github.com/visus-io/notion-sdk-ts/wiki/Request-Size-Limits) - Notion API size limits
|
|
99
|
-
|
|
100
|
-
### Development
|
|
101
|
-
|
|
102
|
-
- [**TypeScript Support**](https://github.com/visus-io/notion-sdk-ts/wiki/TypeScript-Support) - Types, schemas, and type safety
|
|
103
|
-
- [**Development & Contributing**](https://github.com/visus-io/notion-sdk-ts/wiki/Development) - Project structure and architecture
|
|
104
|
-
|
|
105
|
-
## Migration Notice
|
|
106
|
-
|
|
107
|
-
**This SDK now targets Notion API version `2026-03-11`** (upgraded from `2025-09-03` in v3.x; originally `2022-06-28` in v1.x). The API version is fixed — it cannot be overridden via client options.
|
|
108
|
-
|
|
109
|
-
### Key Changes (v3.x — 2026-03-11)
|
|
110
|
-
|
|
111
|
-
- **`archived` → `in_trash`**: Field renamed across all schemas, models, and API request bodies
|
|
112
|
-
- **`after` → `position` object**: `blocks.children.append()` now accepts a typed `position` union
|
|
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
|
-
- **`notionVersion` removed**: Use the exported `NOTION_VERSION` constant to inspect the target version
|
|
115
|
-
|
|
116
|
-
### Quick Migration Example (v2.x → v3.x)
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
// OLD (v2.x / 2025-09-03)
|
|
120
|
-
console.log(page.archived);
|
|
121
|
-
await notion.blocks.children.append('page-id', {
|
|
122
|
-
children: [block.paragraph('text')],
|
|
123
|
-
after: 'block-id',
|
|
124
|
-
});
|
|
125
|
-
block.transcription('Transcription text');
|
|
126
|
-
|
|
127
|
-
// NEW (v3.x / 2026-03-11)
|
|
128
|
-
import { NOTION_VERSION } from '@visus-io/notion-sdk-ts';
|
|
129
|
-
console.log(page.inTrash);
|
|
130
|
-
await notion.blocks.children.append('page-id', {
|
|
131
|
-
children: [block.paragraph('text')],
|
|
132
|
-
position: { type: 'after_block', after_block: { id: 'block-id' } },
|
|
133
|
-
});
|
|
134
|
-
// Meeting notes are server-managed — read them instead of constructing them:
|
|
135
|
-
await notion.blocks.meetingNotes.query();
|
|
81
|
+
```bash
|
|
82
|
+
bun run docs:install
|
|
83
|
+
bun run docs:dev
|
|
136
84
|
```
|
|
137
85
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
- **Database creation**: Properties moved to `initial_data_source.properties`
|
|
141
|
-
- **Database updates**: Use Data Sources API for property changes
|
|
142
|
-
- **Page creation**: Requires both data source ID and database ID
|
|
143
|
-
- **Search API**: Returns `DataSource` objects instead of `Database`
|
|
144
|
-
|
|
145
|
-
### Quick Migration Example (v1.x → v2.x)
|
|
146
|
-
|
|
147
|
-
```typescript
|
|
148
|
-
// OLD (v1.x / 2022-06-28)
|
|
149
|
-
await notion.pages.create({
|
|
150
|
-
parent: parent.database('database-id'),
|
|
151
|
-
properties: { Name: prop.title('Task') },
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
// NEW (v2.x / 2025-09-03)
|
|
155
|
-
const db = await notion.databases.retrieve('database-id');
|
|
156
|
-
const dataSourceId = db.dataSources[0].id;
|
|
157
|
-
|
|
158
|
-
await notion.pages.create({
|
|
159
|
-
parent: parent.dataSource(dataSourceId, db.id),
|
|
160
|
-
properties: { Name: prop.title('Task') },
|
|
161
|
-
});
|
|
162
|
-
```
|
|
86
|
+
## Migration Notice
|
|
163
87
|
|
|
164
|
-
See the [
|
|
88
|
+
**This SDK now targets Notion API version `2026-03-11`** (upgraded from `2025-09-03` in v3.x; originally `2022-06-28` in v1.x). The API version is fixed — it cannot be overridden via client options. See the [Migration Guide](./docs/src/content/docs/migration-guide.md) for complete upgrade details.
|
|
165
89
|
|
|
166
90
|
## Development
|
|
167
91
|
|
|
@@ -188,15 +112,23 @@ bun run test:coverage # Coverage report
|
|
|
188
112
|
bun run lint # ESLint
|
|
189
113
|
bun run lint:fix # Auto-fix
|
|
190
114
|
bun run format # Prettier
|
|
115
|
+
|
|
116
|
+
bun run docs:install # Install the docs site's dependencies (run once, or after they change)
|
|
117
|
+
bun run docs:dev # Run the docs site locally
|
|
118
|
+
bun run docs:build # Build the docs site
|
|
191
119
|
```
|
|
192
120
|
|
|
193
121
|
> **Note:** While this project uses Bun for development, the published package works with both Node.js 18+ and Bun 1.3.10+.
|
|
194
122
|
|
|
195
|
-
See [**
|
|
123
|
+
See [**ARCHITECTURE.md**](./ARCHITECTURE.md) for project structure and architecture.
|
|
124
|
+
|
|
125
|
+
## Contributing
|
|
126
|
+
|
|
127
|
+
Contributions are welcome! See [**CONTRIBUTING.md**](./CONTRIBUTING.md) for how to get started.
|
|
196
128
|
|
|
197
129
|
## Links
|
|
198
130
|
|
|
199
|
-
- [**Documentation
|
|
131
|
+
- [**Documentation**](https://nts.projects.visus.io)
|
|
200
132
|
- [**GitHub Repository**](https://github.com/visus-io/notion-sdk-ts)
|
|
201
133
|
- [**npm Package**](https://www.npmjs.com/package/@visus-io/notion-sdk-ts)
|
|
202
134
|
- [**Notion API Documentation**](https://developers.notion.com/reference/intro)
|
|
@@ -11,6 +11,8 @@ export interface PollAsyncTaskOptions {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Async Tasks API client for polling long-running Notion operations.
|
|
14
|
+
*
|
|
15
|
+
* @category Async Tasks
|
|
14
16
|
*/
|
|
15
17
|
export declare class AsyncTasksAPI extends BaseAPI<NotionAsyncTask, AsyncTask> {
|
|
16
18
|
protected readonly client: NotionClient;
|
|
@@ -56,9 +58,9 @@ export declare class AsyncTasksAPI extends BaseAPI<NotionAsyncTask, AsyncTask> {
|
|
|
56
58
|
*/
|
|
57
59
|
retrieve(taskId: string): Promise<AsyncTask>;
|
|
58
60
|
/**
|
|
59
|
-
* Poll an async task until it reaches a terminal status
|
|
60
|
-
*
|
|
61
|
-
*
|
|
61
|
+
* Poll an async task until it reaches a terminal status: succeeded or failed.
|
|
62
|
+
* Wait at least `poll_after_seconds` between each poll, per the API's guidance.
|
|
63
|
+
* This value comes from the response body, not a header.
|
|
62
64
|
*
|
|
63
65
|
* @param taskId - The ID of the async task to poll
|
|
64
66
|
* @param options - Polling options
|
|
@@ -10,6 +10,8 @@ function sleep(ms) {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* Async Tasks API client for polling long-running Notion operations.
|
|
13
|
+
*
|
|
14
|
+
* @category Async Tasks
|
|
13
15
|
*/
|
|
14
16
|
class AsyncTasksAPI extends base_api_1.BaseAPI {
|
|
15
17
|
constructor(client) {
|
|
@@ -32,9 +34,9 @@ class AsyncTasksAPI extends base_api_1.BaseAPI {
|
|
|
32
34
|
return this.retrieveResource(`/async_tasks/${taskId}`);
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
|
-
* Poll an async task until it reaches a terminal status
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* Poll an async task until it reaches a terminal status: succeeded or failed.
|
|
38
|
+
* Wait at least `poll_after_seconds` between each poll, per the API's guidance.
|
|
39
|
+
* This value comes from the response body, not a header.
|
|
38
40
|
*
|
|
39
41
|
* @param taskId - The ID of the async task to poll
|
|
40
42
|
* @param options - Polling options
|
package/dist/api/base.api.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { NotionClient } from '../client';
|
|
2
|
+
import { TRUSTED } from '../models/base.model';
|
|
2
3
|
import type { PaginatedList, PaginatedListType, PaginationParameters } from '../schemas';
|
|
3
4
|
import type * as z from 'zod';
|
|
4
5
|
/**
|
|
5
|
-
* Configuration for API resource operations
|
|
6
|
+
* Configuration for API resource operations. It defines the schema, model class,
|
|
7
|
+
* and list type that parse and wrap API responses.
|
|
6
8
|
*
|
|
7
9
|
* @template TResponse - The raw response type from the API
|
|
8
10
|
* @template TModel - The model class type that wraps the response
|
|
@@ -11,7 +13,7 @@ interface ResourceConfig<TResponse, TModel> {
|
|
|
11
13
|
/** Zod schema to validate the API response */
|
|
12
14
|
schema: z.ZodSchema<TResponse>;
|
|
13
15
|
/** Model class constructor to wrap the validated response */
|
|
14
|
-
ModelClass: new (data: TResponse) => TModel;
|
|
16
|
+
ModelClass: new (data: TResponse, trusted?: typeof TRUSTED) => TModel;
|
|
15
17
|
/** Type of items in the paginated list (used for typing the results) */
|
|
16
18
|
listType?: PaginatedListType;
|
|
17
19
|
}
|
|
@@ -24,7 +26,15 @@ interface ResourceConfig<TResponse, TModel> {
|
|
|
24
26
|
export declare abstract class BaseAPI<TResponse, TModel> {
|
|
25
27
|
protected readonly client: NotionClient;
|
|
26
28
|
protected abstract config: ResourceConfig<TResponse, TModel>;
|
|
29
|
+
private cachedPaginatedListSchema?;
|
|
27
30
|
protected constructor(client: NotionClient);
|
|
31
|
+
/**
|
|
32
|
+
* Return whether a query object has at least one entry.
|
|
33
|
+
*
|
|
34
|
+
* @param query - Query object to check
|
|
35
|
+
* @returns `true` if `query` has at least one own enumerable key
|
|
36
|
+
*/
|
|
37
|
+
private hasQueryParams;
|
|
28
38
|
/**
|
|
29
39
|
* Delete a resource via DELETE request.
|
|
30
40
|
*
|
|
@@ -49,8 +59,9 @@ export declare abstract class BaseAPI<TResponse, TModel> {
|
|
|
49
59
|
/**
|
|
50
60
|
* Build filter_properties query parameter from an array of property names.
|
|
51
61
|
*
|
|
52
|
-
* Notion sends this as a repeated query key
|
|
53
|
-
* not a single comma-joined value
|
|
62
|
+
* Notion sends this parameter as a repeated query key
|
|
63
|
+
* (`filter_properties=a&filter_properties=b`), not as a single comma-joined value.
|
|
64
|
+
* This method keeps the array intact so `NotionClient` can expand it.
|
|
54
65
|
*
|
|
55
66
|
* @param filterProperties - Optional array of property names to include in the response
|
|
56
67
|
* @returns Query object with filter_properties parameter for API requests
|
package/dist/api/base.api.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseAPI = void 0;
|
|
4
|
+
const base_model_1 = require("../models/base.model");
|
|
4
5
|
const schemas_1 = require("../schemas");
|
|
5
6
|
const validation_1 = require("../validation");
|
|
6
7
|
/**
|
|
@@ -13,6 +14,15 @@ class BaseAPI {
|
|
|
13
14
|
constructor(client) {
|
|
14
15
|
this.client = client;
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Return whether a query object has at least one entry.
|
|
19
|
+
*
|
|
20
|
+
* @param query - Query object to check
|
|
21
|
+
* @returns `true` if `query` has at least one own enumerable key
|
|
22
|
+
*/
|
|
23
|
+
hasQueryParams(query) {
|
|
24
|
+
return !!query && Object.keys(query).length > 0;
|
|
25
|
+
}
|
|
16
26
|
/**
|
|
17
27
|
* Delete a resource via DELETE request.
|
|
18
28
|
*
|
|
@@ -52,8 +62,9 @@ class BaseAPI {
|
|
|
52
62
|
/**
|
|
53
63
|
* Build filter_properties query parameter from an array of property names.
|
|
54
64
|
*
|
|
55
|
-
* Notion sends this as a repeated query key
|
|
56
|
-
* not a single comma-joined value
|
|
65
|
+
* Notion sends this parameter as a repeated query key
|
|
66
|
+
* (`filter_properties=a&filter_properties=b`), not as a single comma-joined value.
|
|
67
|
+
* This method keeps the array intact so `NotionClient` can expand it.
|
|
57
68
|
*
|
|
58
69
|
* @param filterProperties - Optional array of property names to include in the response
|
|
59
70
|
* @returns Query object with filter_properties parameter for API requests
|
|
@@ -127,7 +138,7 @@ class BaseAPI {
|
|
|
127
138
|
const response = await this.client.request({
|
|
128
139
|
method: 'GET',
|
|
129
140
|
path: resourcePath,
|
|
130
|
-
query:
|
|
141
|
+
query: this.hasQueryParams(query) ? query : undefined,
|
|
131
142
|
});
|
|
132
143
|
return this.parseAndWrap(response);
|
|
133
144
|
}
|
|
@@ -148,7 +159,7 @@ class BaseAPI {
|
|
|
148
159
|
const response = await this.client.request({
|
|
149
160
|
method: 'GET',
|
|
150
161
|
path: resourcePath,
|
|
151
|
-
query:
|
|
162
|
+
query: this.hasQueryParams(query) ? query : undefined,
|
|
152
163
|
});
|
|
153
164
|
return this.parsePaginatedList(response);
|
|
154
165
|
}
|
|
@@ -185,7 +196,7 @@ class BaseAPI {
|
|
|
185
196
|
*/
|
|
186
197
|
parseAndWrap(response) {
|
|
187
198
|
const parsed = this.config.schema.parse(response);
|
|
188
|
-
return new this.config.ModelClass(parsed);
|
|
199
|
+
return new this.config.ModelClass(parsed, base_model_1.TRUSTED);
|
|
189
200
|
}
|
|
190
201
|
/**
|
|
191
202
|
* Parse a paginated list response and wrap each item in the specified model class.
|
|
@@ -198,11 +209,11 @@ class BaseAPI {
|
|
|
198
209
|
* return this.parsePaginatedList(response);
|
|
199
210
|
*/
|
|
200
211
|
parsePaginatedList(response) {
|
|
201
|
-
|
|
202
|
-
const parsed =
|
|
212
|
+
this.cachedPaginatedListSchema ??= (0, schemas_1.paginatedListSchema)(this.config.schema);
|
|
213
|
+
const parsed = this.cachedPaginatedListSchema.parse(response);
|
|
203
214
|
return {
|
|
204
215
|
object: 'list',
|
|
205
|
-
results: parsed.results.map((item) => new this.config.ModelClass(item)),
|
|
216
|
+
results: parsed.results.map((item) => new this.config.ModelClass(item, base_model_1.TRUSTED)),
|
|
206
217
|
next_cursor: parsed.next_cursor,
|
|
207
218
|
has_more: parsed.has_more,
|
|
208
219
|
type: this.config.listType || 'unknown',
|
package/dist/api/blocks.api.d.ts
CHANGED
package/dist/api/blocks.api.js
CHANGED
|
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BlocksAPI = void 0;
|
|
4
4
|
const schemas_1 = require("../schemas");
|
|
5
5
|
const models_1 = require("../models");
|
|
6
|
+
const base_model_1 = require("../models/base.model");
|
|
6
7
|
const validation_1 = require("../validation");
|
|
7
8
|
const base_api_1 = require("./base.api");
|
|
8
9
|
/**
|
|
9
10
|
* Blocks API client for working with Notion blocks.
|
|
11
|
+
*
|
|
12
|
+
* @category Blocks
|
|
10
13
|
*/
|
|
11
14
|
class BlocksAPI extends base_api_1.BaseAPI {
|
|
12
15
|
constructor(client) {
|
|
@@ -53,7 +56,7 @@ class BlocksAPI extends base_api_1.BaseAPI {
|
|
|
53
56
|
const listSchema = (0, schemas_1.paginatedListSchema)(schemas_1.blockSchema);
|
|
54
57
|
const parsed = listSchema.parse(response);
|
|
55
58
|
return {
|
|
56
|
-
results: parsed.results.map((block) => new models_1.Block(block)),
|
|
59
|
+
results: parsed.results.map((block) => new models_1.Block(block, base_model_1.TRUSTED)),
|
|
57
60
|
next_cursor: parsed.next_cursor,
|
|
58
61
|
has_more: parsed.has_more,
|
|
59
62
|
};
|
|
@@ -92,7 +95,7 @@ class BlocksAPI extends base_api_1.BaseAPI {
|
|
|
92
95
|
});
|
|
93
96
|
const parsed = schemas_1.meetingNotesQueryResponseSchema.parse(response);
|
|
94
97
|
return {
|
|
95
|
-
results: parsed.results.map((b) => new models_1.Block(b)),
|
|
98
|
+
results: parsed.results.map((b) => new models_1.Block(b, base_model_1.TRUSTED)),
|
|
96
99
|
hasMore: parsed.has_more,
|
|
97
100
|
requestStatus: parsed.request_status,
|
|
98
101
|
};
|
|
@@ -56,6 +56,8 @@ export interface UpdateCommentOptions {
|
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Comments API client for working with Notion comments.
|
|
59
|
+
*
|
|
60
|
+
* @category Comments
|
|
59
61
|
*/
|
|
60
62
|
export declare class CommentsAPI extends BaseAPI<NotionComment, Comment> {
|
|
61
63
|
protected readonly client: NotionClient;
|
package/dist/api/comments.api.js
CHANGED
|
@@ -11,6 +11,8 @@ export interface ListCustomEmojisOptions extends PaginationParameters {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Custom Emojis API client for working with Notion workspace custom emojis.
|
|
14
|
+
*
|
|
15
|
+
* @category Custom Emoji & Icons
|
|
14
16
|
*/
|
|
15
17
|
export declare class CustomEmojisAPI extends BaseAPI<NotionCustomEmoji, CustomEmoji> {
|
|
16
18
|
protected readonly client: NotionClient;
|
|
@@ -6,6 +6,8 @@ const models_1 = require("../models");
|
|
|
6
6
|
const base_api_1 = require("./base.api");
|
|
7
7
|
/**
|
|
8
8
|
* Custom Emojis API client for working with Notion workspace custom emojis.
|
|
9
|
+
*
|
|
10
|
+
* @category Custom Emoji & Icons
|
|
9
11
|
*/
|
|
10
12
|
class CustomEmojisAPI extends base_api_1.BaseAPI {
|
|
11
13
|
constructor(client) {
|
|
@@ -52,7 +52,7 @@ export interface ListDataSourceTemplatesOptions extends PaginationParameters {
|
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Filter condition for data source queries.
|
|
55
|
-
* This is
|
|
55
|
+
* This type is simplified. The Notion API supports many more filter types.
|
|
56
56
|
* See: https://developers.notion.com/reference/filter-data-source-entries
|
|
57
57
|
*/
|
|
58
58
|
export type DataSourceFilter = Record<string, unknown>;
|
|
@@ -89,8 +89,8 @@ export interface QueryDataSourceOptions extends PaginationParameters {
|
|
|
89
89
|
/**
|
|
90
90
|
* Whether to return only trashed pages (true) or only non-trashed pages (false).
|
|
91
91
|
*
|
|
92
|
-
* @deprecated Use `is_archived` instead.
|
|
93
|
-
* `is_archived
|
|
92
|
+
* @deprecated Use `is_archived` instead. This field is an alias that forwards
|
|
93
|
+
* into `is_archived`. If you provide both fields, `is_archived` takes precedence.
|
|
94
94
|
*/
|
|
95
95
|
in_trash?: boolean;
|
|
96
96
|
}
|
|
@@ -99,6 +99,8 @@ export interface QueryDataSourceOptions extends PaginationParameters {
|
|
|
99
99
|
*
|
|
100
100
|
* Data sources are individual tables of data that live under a Notion database.
|
|
101
101
|
* As of API version 2025-09-03, data sources have their own API endpoints.
|
|
102
|
+
*
|
|
103
|
+
* @category Databases & Data Sources
|
|
102
104
|
*/
|
|
103
105
|
export declare class DataSourcesAPI extends BaseAPI<NotionDataSource, DataSource> {
|
|
104
106
|
protected readonly client: NotionClient;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DataSourcesAPI = void 0;
|
|
4
4
|
const schemas_1 = require("../schemas");
|
|
5
5
|
const models_1 = require("../models");
|
|
6
|
+
const base_model_1 = require("../models/base.model");
|
|
6
7
|
const validation_1 = require("../validation");
|
|
7
8
|
const base_api_1 = require("./base.api");
|
|
8
9
|
/**
|
|
@@ -10,6 +11,8 @@ const base_api_1 = require("./base.api");
|
|
|
10
11
|
*
|
|
11
12
|
* Data sources are individual tables of data that live under a Notion database.
|
|
12
13
|
* As of API version 2025-09-03, data sources have their own API endpoints.
|
|
14
|
+
*
|
|
15
|
+
* @category Databases & Data Sources
|
|
13
16
|
*/
|
|
14
17
|
class DataSourcesAPI extends base_api_1.BaseAPI {
|
|
15
18
|
constructor(client) {
|
|
@@ -103,7 +106,7 @@ class DataSourcesAPI extends base_api_1.BaseAPI {
|
|
|
103
106
|
const parsed = listSchema.parse(response);
|
|
104
107
|
return {
|
|
105
108
|
object: 'list',
|
|
106
|
-
results: parsed.results.map((page) => new models_1.Page(page)),
|
|
109
|
+
results: parsed.results.map((page) => new models_1.Page(page, base_model_1.TRUSTED)),
|
|
107
110
|
next_cursor: parsed.next_cursor,
|
|
108
111
|
has_more: parsed.has_more,
|
|
109
112
|
type: 'page',
|
|
@@ -11,7 +11,7 @@ export interface RetrieveDatabaseOptions {
|
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Filter condition for database queries.
|
|
14
|
-
* This is
|
|
14
|
+
* This type is simplified. The Notion API supports many more filter types.
|
|
15
15
|
* See: https://developers.notion.com/reference/post-database-query-filter
|
|
16
16
|
*/
|
|
17
17
|
export type DatabaseFilter = Record<string, unknown>;
|
|
@@ -62,8 +62,8 @@ export interface InitialDataSource {
|
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Options for creating a database.
|
|
65
|
-
* As of API version 2025-09-03, databases
|
|
66
|
-
*
|
|
65
|
+
* As of API version 2025-09-03, databases require an `initial_data_source` object.
|
|
66
|
+
* This object holds the properties schema. It replaces top-level properties.
|
|
67
67
|
*/
|
|
68
68
|
export interface CreateDatabaseOptions {
|
|
69
69
|
/** The parent object (page or workspace) */
|
|
@@ -81,8 +81,8 @@ export interface CreateDatabaseOptions {
|
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
83
|
* Options for updating a database.
|
|
84
|
-
* As of API version 2025-09-03, properties
|
|
85
|
-
* Use
|
|
84
|
+
* As of API version 2025-09-03, manage properties at the data source level.
|
|
85
|
+
* Use DataSourcesAPI to update properties.
|
|
86
86
|
*/
|
|
87
87
|
export interface UpdateDatabaseOptions {
|
|
88
88
|
/** Update the database title */
|
|
@@ -102,6 +102,8 @@ export interface UpdateDatabaseOptions {
|
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Databases API client for working with Notion databases.
|
|
105
|
+
*
|
|
106
|
+
* @category Databases & Data Sources
|
|
105
107
|
*/
|
|
106
108
|
export declare class DatabasesAPI extends BaseAPI<NotionDatabase, Database> {
|
|
107
109
|
protected readonly client: NotionClient;
|
|
@@ -3,10 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DatabasesAPI = void 0;
|
|
4
4
|
const schemas_1 = require("../schemas");
|
|
5
5
|
const models_1 = require("../models");
|
|
6
|
+
const base_model_1 = require("../models/base.model");
|
|
6
7
|
const validation_1 = require("../validation");
|
|
7
8
|
const base_api_1 = require("./base.api");
|
|
8
9
|
/**
|
|
9
10
|
* Databases API client for working with Notion databases.
|
|
11
|
+
*
|
|
12
|
+
* @category Databases & Data Sources
|
|
10
13
|
*/
|
|
11
14
|
class DatabasesAPI extends base_api_1.BaseAPI {
|
|
12
15
|
constructor(client) {
|
|
@@ -60,7 +63,7 @@ class DatabasesAPI extends base_api_1.BaseAPI {
|
|
|
60
63
|
const parsed = listSchema.parse(response);
|
|
61
64
|
return {
|
|
62
65
|
object: 'list',
|
|
63
|
-
results: parsed.results.map((page) => new models_1.Page(page)),
|
|
66
|
+
results: parsed.results.map((page) => new models_1.Page(page, base_model_1.TRUSTED)),
|
|
64
67
|
next_cursor: parsed.next_cursor,
|
|
65
68
|
has_more: parsed.has_more,
|
|
66
69
|
type: 'page',
|
|
@@ -19,6 +19,8 @@ export interface InitiateFileUploadOptions {
|
|
|
19
19
|
export type FileData = Buffer | ArrayBuffer | Blob | ReadableStream;
|
|
20
20
|
/**
|
|
21
21
|
* FileUploads API client for uploading files to Notion.
|
|
22
|
+
*
|
|
23
|
+
* @category File Uploads
|
|
22
24
|
*/
|
|
23
25
|
export declare class FileUploadsAPI extends BaseAPI<NotionFileUpload, FileUpload> {
|
|
24
26
|
protected readonly client: NotionClient;
|
|
@@ -55,7 +57,8 @@ export declare class FileUploadsAPI extends BaseAPI<NotionFileUpload, FileUpload
|
|
|
55
57
|
initiate(options: InitiateFileUploadOptions): Promise<FileUpload>;
|
|
56
58
|
/**
|
|
57
59
|
* Upload file data to the upload URL.
|
|
58
|
-
* This
|
|
60
|
+
* This method sends a PUT request directly to the upload URL. It does not go
|
|
61
|
+
* through the Notion API.
|
|
59
62
|
*
|
|
60
63
|
* @param uploadUrl - The upload URL from initiate()
|
|
61
64
|
* @param fileData - The file data to upload
|
|
@@ -74,9 +77,9 @@ export declare class FileUploadsAPI extends BaseAPI<NotionFileUpload, FileUpload
|
|
|
74
77
|
*/
|
|
75
78
|
complete(completeUrl: string): Promise<FileUpload>;
|
|
76
79
|
/**
|
|
77
|
-
*
|
|
78
|
-
* URLs
|
|
79
|
-
* relative paths
|
|
80
|
+
* Extract the request path from a complete URL.
|
|
81
|
+
* Accept absolute URLs, for example `https://api.notion.com/v1/file_uploads/.../complete`.
|
|
82
|
+
* Accept relative paths too, for example `/v1/file_uploads/.../complete` or the path alone.
|
|
80
83
|
*/
|
|
81
84
|
private static toRequestPath;
|
|
82
85
|
/**
|
|
@@ -3,9 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FileUploadsAPI = void 0;
|
|
4
4
|
const schemas_1 = require("../schemas");
|
|
5
5
|
const models_1 = require("../models");
|
|
6
|
+
const base_model_1 = require("../models/base.model");
|
|
6
7
|
const base_api_1 = require("./base.api");
|
|
7
8
|
/**
|
|
8
9
|
* FileUploads API client for uploading files to Notion.
|
|
10
|
+
*
|
|
11
|
+
* @category File Uploads
|
|
9
12
|
*/
|
|
10
13
|
class FileUploadsAPI extends base_api_1.BaseAPI {
|
|
11
14
|
constructor(client) {
|
|
@@ -31,11 +34,12 @@ class FileUploadsAPI extends base_api_1.BaseAPI {
|
|
|
31
34
|
body: options,
|
|
32
35
|
});
|
|
33
36
|
const parsed = schemas_1.fileUploadSchema.parse(response);
|
|
34
|
-
return new models_1.FileUpload(parsed);
|
|
37
|
+
return new models_1.FileUpload(parsed, base_model_1.TRUSTED);
|
|
35
38
|
}
|
|
36
39
|
/**
|
|
37
40
|
* Upload file data to the upload URL.
|
|
38
|
-
* This
|
|
41
|
+
* This method sends a PUT request directly to the upload URL. It does not go
|
|
42
|
+
* through the Notion API.
|
|
39
43
|
*
|
|
40
44
|
* @param uploadUrl - The upload URL from initiate()
|
|
41
45
|
* @param fileData - The file data to upload
|
|
@@ -70,12 +74,12 @@ class FileUploadsAPI extends base_api_1.BaseAPI {
|
|
|
70
74
|
body: {},
|
|
71
75
|
});
|
|
72
76
|
const parsed = schemas_1.fileUploadSchema.parse(response);
|
|
73
|
-
return new models_1.FileUpload(parsed);
|
|
77
|
+
return new models_1.FileUpload(parsed, base_model_1.TRUSTED);
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
|
-
*
|
|
77
|
-
* URLs
|
|
78
|
-
* relative paths
|
|
80
|
+
* Extract the request path from a complete URL.
|
|
81
|
+
* Accept absolute URLs, for example `https://api.notion.com/v1/file_uploads/.../complete`.
|
|
82
|
+
* Accept relative paths too, for example `/v1/file_uploads/.../complete` or the path alone.
|
|
79
83
|
*/
|
|
80
84
|
static toRequestPath(completeUrl) {
|
|
81
85
|
let path;
|
|
@@ -136,7 +140,7 @@ class FileUploadsAPI extends base_api_1.BaseAPI {
|
|
|
136
140
|
path: `/file_uploads/${fileUploadId}`,
|
|
137
141
|
});
|
|
138
142
|
const parsed = schemas_1.fileUploadSchema.parse(response);
|
|
139
|
-
return new models_1.FileUpload(parsed);
|
|
143
|
+
return new models_1.FileUpload(parsed, base_model_1.TRUSTED);
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
146
|
exports.FileUploadsAPI = FileUploadsAPI;
|
package/dist/api/pages.api.d.ts
CHANGED
|
@@ -143,6 +143,8 @@ export interface UpdatePageOptions {
|
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
145
|
* Pages API client for working with Notion pages.
|
|
146
|
+
*
|
|
147
|
+
* @category Pages
|
|
146
148
|
*/
|
|
147
149
|
export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
148
150
|
protected readonly client: NotionClient;
|
|
@@ -1075,9 +1077,9 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
1075
1077
|
/**
|
|
1076
1078
|
* Update a page's content as markdown.
|
|
1077
1079
|
*
|
|
1078
|
-
*
|
|
1079
|
-
* `async_task` handle instead of
|
|
1080
|
-
* `notion.asyncTasks.poll(task.id)`.
|
|
1080
|
+
* Set `allow_async: true` to allow asynchronous processing for large writes.
|
|
1081
|
+
* In that case, the API returns an `async_task` handle instead of the completed
|
|
1082
|
+
* content. Poll the task with `notion.asyncTasks.poll(task.id)`.
|
|
1081
1083
|
*
|
|
1082
1084
|
* @param pageId - The ID of the page to update
|
|
1083
1085
|
* @param options - The markdown update to apply
|
package/dist/api/pages.api.js
CHANGED
|
@@ -17,6 +17,8 @@ function validateMarkdownExclusivity(options) {
|
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Pages API client for working with Notion pages.
|
|
20
|
+
*
|
|
21
|
+
* @category Pages
|
|
20
22
|
*/
|
|
21
23
|
class PagesAPI extends base_api_1.BaseAPI {
|
|
22
24
|
constructor(client) {
|
|
@@ -81,9 +83,9 @@ class PagesAPI extends base_api_1.BaseAPI {
|
|
|
81
83
|
/**
|
|
82
84
|
* Update a page's content as markdown.
|
|
83
85
|
*
|
|
84
|
-
*
|
|
85
|
-
* `async_task` handle instead of
|
|
86
|
-
* `notion.asyncTasks.poll(task.id)`.
|
|
86
|
+
* Set `allow_async: true` to allow asynchronous processing for large writes.
|
|
87
|
+
* In that case, the API returns an `async_task` handle instead of the completed
|
|
88
|
+
* content. Poll the task with `notion.asyncTasks.poll(task.id)`.
|
|
87
89
|
*
|
|
88
90
|
* @param pageId - The ID of the page to update
|
|
89
91
|
* @param options - The markdown update to apply
|