@visus-io/notion-sdk-ts 3.1.0 → 3.2.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 +20 -88
- 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 +10 -3
- package/dist/api/dataSources.api.js +4 -1
- package/dist/api/databases.api.d.ts +21 -8
- package/dist/api/databases.api.js +8 -4
- package/dist/api/fileUploads.api.d.ts +7 -4
- package/dist/api/fileUploads.api.js +11 -7
- package/dist/api/pages.api.d.ts +8 -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 +21 -4
- package/dist/errors.js +17 -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 +10 -3
- package/dist/models/dataSource.model.js +11 -2
- package/dist/models/database.model.d.ts +11 -3
- package/dist/models/database.model.js +14 -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 +9 -2
- package/dist/models/user.model.js +14 -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 +24 -3
- package/dist/schemas/dataSource.schema.js +15 -5
- package/dist/schemas/database.schema.d.ts +31 -1
- package/dist/schemas/database.schema.js +18 -2
- 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 +8 -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 +81 -3
- package/dist/schemas/pageProperties.schema.js +7 -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 +46 -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 +20 -16
|
@@ -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;
|
|
@@ -378,6 +380,9 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
378
380
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
379
381
|
type: import("zod").ZodLiteral<"string">;
|
|
380
382
|
string: import("zod").ZodNullable<import("zod").ZodString>;
|
|
383
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
384
|
+
type: import("zod").ZodLiteral<"unsupported">;
|
|
385
|
+
unsupported: import("zod").ZodObject<{}, import("zod/v4/core").$strip>;
|
|
381
386
|
}, import("zod/v4/core").$strip>], "type">;
|
|
382
387
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
383
388
|
id: import("zod").ZodString;
|
|
@@ -1075,9 +1080,9 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
1075
1080
|
/**
|
|
1076
1081
|
* Update a page's content as markdown.
|
|
1077
1082
|
*
|
|
1078
|
-
*
|
|
1079
|
-
* `async_task` handle instead of
|
|
1080
|
-
* `notion.asyncTasks.poll(task.id)`.
|
|
1083
|
+
* Set `allow_async: true` to allow asynchronous processing for large writes.
|
|
1084
|
+
* In that case, the API returns an `async_task` handle instead of the completed
|
|
1085
|
+
* content. Poll the task with `notion.asyncTasks.poll(task.id)`.
|
|
1081
1086
|
*
|
|
1082
1087
|
* @param pageId - The ID of the page to update
|
|
1083
1088
|
* @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
|
package/dist/api/search.api.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export type SearchFilterObject = 'page' | 'data_source';
|
|
|
9
9
|
/**
|
|
10
10
|
* Search filter configuration.
|
|
11
11
|
*
|
|
12
|
-
* `in_trash`
|
|
13
|
-
*
|
|
12
|
+
* Combine `in_trash` with the object filter (`property`/`value`), or use it alone
|
|
13
|
+
* to list only trashed content.
|
|
14
14
|
*/
|
|
15
15
|
export type SearchFilter = {
|
|
16
16
|
/** Filter by object type */
|
|
@@ -50,6 +50,8 @@ export interface SearchOptions extends PaginationParameters {
|
|
|
50
50
|
export type SearchResult = Page | DataSource;
|
|
51
51
|
/**
|
|
52
52
|
* Search API client for searching across the workspace.
|
|
53
|
+
*
|
|
54
|
+
* @category Search
|
|
53
55
|
*/
|
|
54
56
|
export declare class SearchAPI {
|
|
55
57
|
private readonly client;
|
package/dist/api/search.api.js
CHANGED
|
@@ -3,8 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SearchAPI = 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
|
/**
|
|
7
8
|
* Search API client for searching across the workspace.
|
|
9
|
+
*
|
|
10
|
+
* @category Search
|
|
8
11
|
*/
|
|
9
12
|
class SearchAPI {
|
|
10
13
|
constructor(client) {
|
|
@@ -41,11 +44,11 @@ class SearchAPI {
|
|
|
41
44
|
const results = response.results.map((item) => {
|
|
42
45
|
if (item.object === 'page') {
|
|
43
46
|
const parsed = schemas_1.pageSchema.parse(item);
|
|
44
|
-
return new models_1.Page(parsed);
|
|
47
|
+
return new models_1.Page(parsed, base_model_1.TRUSTED);
|
|
45
48
|
}
|
|
46
49
|
else {
|
|
47
50
|
const parsed = schemas_1.dataSourceSchema.parse(item);
|
|
48
|
-
return new models_1.DataSource(parsed);
|
|
51
|
+
return new models_1.DataSource(parsed, base_model_1.TRUSTED);
|
|
49
52
|
}
|
|
50
53
|
});
|
|
51
54
|
return {
|
package/dist/api/users.api.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { User } from '../models';
|
|
|
4
4
|
import { BaseAPI } from './base.api';
|
|
5
5
|
/**
|
|
6
6
|
* Users API client for working with Notion users.
|
|
7
|
+
*
|
|
8
|
+
* @category Users
|
|
7
9
|
*/
|
|
8
10
|
export declare class UsersAPI extends BaseAPI<NotionUser, User> {
|
|
9
11
|
protected readonly client: NotionClient;
|
package/dist/api/users.api.js
CHANGED
package/dist/api/views.api.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export interface ListViewsOptions extends PaginationParameters {
|
|
|
13
13
|
data_source_id?: string;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Options for creating a view.
|
|
17
|
-
*
|
|
16
|
+
* Options for creating a view. Provide exactly one of
|
|
17
|
+
* `database_id`/`view_id`/`create_database` to select the parent context.
|
|
18
18
|
*/
|
|
19
19
|
export interface CreateViewOptions {
|
|
20
20
|
/** The data source the view displays */
|
|
@@ -41,8 +41,8 @@ export interface CreateViewOptions {
|
|
|
41
41
|
position?: Record<string, unknown>;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Options for updating a view. All fields optional
|
|
45
|
-
* filter
|
|
44
|
+
* Options for updating a view. All fields are optional.
|
|
45
|
+
* Pass `null` for `filter`, `sorts`, or `quick_filters` to clear the existing value.
|
|
46
46
|
*/
|
|
47
47
|
export interface UpdateViewOptions {
|
|
48
48
|
/** Rename the view */
|
|
@@ -66,9 +66,9 @@ export interface CreateViewQueryOptions extends PaginationParameters {
|
|
|
66
66
|
sorts?: DataSourceSort[];
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
* Result of a view query.
|
|
70
|
-
*
|
|
71
|
-
*
|
|
69
|
+
* Result of a view query. This shape differs from {@link PaginatedList}.
|
|
70
|
+
* It includes `totalCount` and `expiresAt`. After `expiresAt` passes,
|
|
71
|
+
* {@link ViewsAPI.queries.get} can no longer retrieve the query.
|
|
72
72
|
*/
|
|
73
73
|
export interface ViewQueryResult {
|
|
74
74
|
id: string;
|
|
@@ -85,6 +85,8 @@ export interface ViewQueryResult {
|
|
|
85
85
|
*
|
|
86
86
|
* Views control how a database/data source's rows are displayed (table, board,
|
|
87
87
|
* calendar, etc.). Requires API version 2025-09-03 or later.
|
|
88
|
+
*
|
|
89
|
+
* @category Views
|
|
88
90
|
*/
|
|
89
91
|
export declare class ViewsAPI extends BaseAPI<NotionView, View> {
|
|
90
92
|
protected readonly client: NotionClient;
|
|
@@ -246,9 +248,9 @@ export declare class ViewsAPI extends BaseAPI<NotionView, View> {
|
|
|
246
248
|
/**
|
|
247
249
|
* Delete a view.
|
|
248
250
|
*
|
|
249
|
-
*
|
|
250
|
-
* `object`/`id`/`parent`/`type
|
|
251
|
-
* parsed result
|
|
251
|
+
* Notion's delete-view response differs from other delete methods. It includes
|
|
252
|
+
* only `object`/`id`/`parent`/`type`, not the full view shape. This method
|
|
253
|
+
* returns the raw parsed result instead of a full {@link View} model.
|
|
252
254
|
*
|
|
253
255
|
* @param viewId - The ID of the view to delete
|
|
254
256
|
* @returns The partial view object returned by the API
|
|
@@ -257,9 +259,9 @@ export declare class ViewsAPI extends BaseAPI<NotionView, View> {
|
|
|
257
259
|
*/
|
|
258
260
|
delete(viewId: string): Promise<ViewDeleteResult>;
|
|
259
261
|
/**
|
|
260
|
-
* Sub-resource
|
|
261
|
-
*
|
|
262
|
-
*
|
|
262
|
+
* Sub-resource to query a view's rows. View queries are non-standard.
|
|
263
|
+
* Each query returns a `total_count` and an `expires_at` value. The query
|
|
264
|
+
* result expires about 15 minutes after creation.
|
|
263
265
|
*/
|
|
264
266
|
readonly queries: {
|
|
265
267
|
/**
|
package/dist/api/views.api.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ViewsAPI = void 0;
|
|
4
4
|
const models_1 = require("../models");
|
|
5
|
+
const base_model_1 = require("../models/base.model");
|
|
5
6
|
const schemas_1 = require("../schemas");
|
|
6
7
|
const validation_1 = require("../validation");
|
|
7
8
|
const base_api_1 = require("./base.api");
|
|
@@ -12,7 +13,7 @@ function toViewQueryResult(response) {
|
|
|
12
13
|
viewId: parsed.view_id,
|
|
13
14
|
expiresAt: new Date(parsed.expires_at),
|
|
14
15
|
totalCount: parsed.total_count,
|
|
15
|
-
results: parsed.results.map((page) => new models_1.Page(page)),
|
|
16
|
+
results: parsed.results.map((page) => new models_1.Page(page, base_model_1.TRUSTED)),
|
|
16
17
|
nextCursor: parsed.next_cursor,
|
|
17
18
|
hasMore: parsed.has_more,
|
|
18
19
|
requestStatus: parsed.request_status,
|
|
@@ -23,6 +24,8 @@ function toViewQueryResult(response) {
|
|
|
23
24
|
*
|
|
24
25
|
* Views control how a database/data source's rows are displayed (table, board,
|
|
25
26
|
* calendar, etc.). Requires API version 2025-09-03 or later.
|
|
27
|
+
*
|
|
28
|
+
* @category Views
|
|
26
29
|
*/
|
|
27
30
|
class ViewsAPI extends base_api_1.BaseAPI {
|
|
28
31
|
constructor(client) {
|
|
@@ -34,9 +37,9 @@ class ViewsAPI extends base_api_1.BaseAPI {
|
|
|
34
37
|
listType: 'view',
|
|
35
38
|
};
|
|
36
39
|
/**
|
|
37
|
-
* Sub-resource
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
+
* Sub-resource to query a view's rows. View queries are non-standard.
|
|
41
|
+
* Each query returns a `total_count` and an `expires_at` value. The query
|
|
42
|
+
* result expires about 15 minutes after creation.
|
|
40
43
|
*/
|
|
41
44
|
this.queries = {
|
|
42
45
|
/**
|
|
@@ -149,9 +152,9 @@ class ViewsAPI extends base_api_1.BaseAPI {
|
|
|
149
152
|
/**
|
|
150
153
|
* Delete a view.
|
|
151
154
|
*
|
|
152
|
-
*
|
|
153
|
-
* `object`/`id`/`parent`/`type
|
|
154
|
-
* parsed result
|
|
155
|
+
* Notion's delete-view response differs from other delete methods. It includes
|
|
156
|
+
* only `object`/`id`/`parent`/`type`, not the full view shape. This method
|
|
157
|
+
* returns the raw parsed result instead of a full {@link View} model.
|
|
155
158
|
*
|
|
156
159
|
* @param viewId - The ID of the view to delete
|
|
157
160
|
* @returns The partial view object returned by the API
|
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The Notion API version
|
|
3
|
-
* All schemas, request bodies, helpers, and models
|
|
2
|
+
* The Notion API version this SDK uses.
|
|
3
|
+
* All schemas, request bodies, helpers, and models depend on this version.
|
|
4
|
+
*
|
|
5
|
+
* @category Client & Core
|
|
4
6
|
*/
|
|
5
7
|
export declare const NOTION_VERSION: "2026-03-11";
|
|
6
8
|
/**
|
|
7
9
|
* Configuration options for the Notion client.
|
|
10
|
+
*
|
|
11
|
+
* @category Client & Core
|
|
8
12
|
*/
|
|
9
13
|
export interface NotionClientOptions {
|
|
10
14
|
/** Notion integration token (Bearer token) */
|
|
@@ -33,47 +37,43 @@ export interface RequestOptions {
|
|
|
33
37
|
* Base HTTP client for Notion API requests.
|
|
34
38
|
*/
|
|
35
39
|
export declare class NotionClient {
|
|
36
|
-
private readonly auth;
|
|
37
40
|
private readonly baseUrl;
|
|
38
41
|
private readonly timeoutMs;
|
|
39
42
|
private readonly fetchImpl;
|
|
40
43
|
private readonly maxRetries;
|
|
41
44
|
private readonly retryOnRateLimit;
|
|
45
|
+
private readonly requestHeaders;
|
|
42
46
|
constructor(options: NotionClientOptions);
|
|
43
47
|
/**
|
|
44
|
-
*
|
|
48
|
+
* Send a request to the Notion API.
|
|
49
|
+
* Retry automatically on rate-limited and overloaded responses.
|
|
45
50
|
*/
|
|
46
51
|
request<T>(options: RequestOptions): Promise<T>;
|
|
47
52
|
/**
|
|
48
|
-
*
|
|
53
|
+
* Send one HTTP request to the Notion API.
|
|
49
54
|
*/
|
|
50
55
|
private makeRequest;
|
|
51
56
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
57
|
+
* Calculate a fallback retry delay with exponential backoff.
|
|
58
|
+
* Use this delay when the response has no `Retry-After` header.
|
|
54
59
|
* Formula: 2^attempt * 1000 ms, capped at 60 seconds.
|
|
55
60
|
*/
|
|
56
61
|
private getRetryAfter;
|
|
57
62
|
/**
|
|
58
|
-
*
|
|
63
|
+
* Pause for the given duration, in milliseconds.
|
|
59
64
|
*/
|
|
60
65
|
private sleep;
|
|
61
66
|
/**
|
|
62
|
-
*
|
|
67
|
+
* Build the full URL with query parameters.
|
|
63
68
|
*/
|
|
64
69
|
private buildUrl;
|
|
65
70
|
/**
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
private buildHeaders;
|
|
69
|
-
/**
|
|
70
|
-
* Parses the `Retry-After` response header into milliseconds.
|
|
71
|
-
* Returns `undefined` when the header is absent or not a valid
|
|
72
|
-
* non-negative integer.
|
|
71
|
+
* Parse the `Retry-After` response header into milliseconds.
|
|
72
|
+
* Return `undefined` if the header is missing or not a valid non-negative number.
|
|
73
73
|
*/
|
|
74
74
|
private parseRetryAfterHeader;
|
|
75
75
|
/**
|
|
76
|
-
*
|
|
76
|
+
* Handle an error response from the API.
|
|
77
77
|
*/
|
|
78
78
|
private handleErrorResponse;
|
|
79
79
|
}
|
package/dist/client.js
CHANGED
|
@@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NotionClient = exports.NOTION_VERSION = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
5
|
/**
|
|
6
|
-
* The Notion API version
|
|
7
|
-
* All schemas, request bodies, helpers, and models
|
|
6
|
+
* The Notion API version this SDK uses.
|
|
7
|
+
* All schemas, request bodies, helpers, and models depend on this version.
|
|
8
|
+
*
|
|
9
|
+
* @category Client & Core
|
|
8
10
|
*/
|
|
9
11
|
exports.NOTION_VERSION = '2026-03-11';
|
|
10
12
|
/**
|
|
@@ -12,15 +14,20 @@ exports.NOTION_VERSION = '2026-03-11';
|
|
|
12
14
|
*/
|
|
13
15
|
class NotionClient {
|
|
14
16
|
constructor(options) {
|
|
15
|
-
this.
|
|
16
|
-
this.baseUrl = options.baseUrl ?? 'https://api.notion.com';
|
|
17
|
+
this.baseUrl = `${options.baseUrl ?? 'https://api.notion.com'}/v1`;
|
|
17
18
|
this.timeoutMs = options.timeoutMs ?? 60000;
|
|
18
19
|
this.fetchImpl = options.fetch ?? fetch;
|
|
19
20
|
this.maxRetries = options.maxRetries ?? 3;
|
|
20
21
|
this.retryOnRateLimit = options.retryOnRateLimit ?? true;
|
|
22
|
+
this.requestHeaders = {
|
|
23
|
+
Authorization: `Bearer ${options.auth}`,
|
|
24
|
+
'Content-Type': 'application/json',
|
|
25
|
+
'Notion-Version': exports.NOTION_VERSION,
|
|
26
|
+
};
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
29
|
+
* Send a request to the Notion API.
|
|
30
|
+
* Retry automatically on rate-limited and overloaded responses.
|
|
24
31
|
*/
|
|
25
32
|
async request(options) {
|
|
26
33
|
let lastError;
|
|
@@ -49,17 +56,16 @@ class NotionClient {
|
|
|
49
56
|
throw lastError ?? new Error('Request failed after all retries');
|
|
50
57
|
}
|
|
51
58
|
/**
|
|
52
|
-
*
|
|
59
|
+
* Send one HTTP request to the Notion API.
|
|
53
60
|
*/
|
|
54
61
|
async makeRequest(options) {
|
|
55
62
|
const url = this.buildUrl(options.path, options.query);
|
|
56
|
-
const headers = this.buildHeaders();
|
|
57
63
|
const controller = new AbortController();
|
|
58
64
|
const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
59
65
|
try {
|
|
60
66
|
const response = await this.fetchImpl(url, {
|
|
61
67
|
method: options.method,
|
|
62
|
-
headers,
|
|
68
|
+
headers: this.requestHeaders,
|
|
63
69
|
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
64
70
|
signal: controller.signal,
|
|
65
71
|
});
|
|
@@ -89,8 +95,8 @@ class NotionClient {
|
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
98
|
+
* Calculate a fallback retry delay with exponential backoff.
|
|
99
|
+
* Use this delay when the response has no `Retry-After` header.
|
|
94
100
|
* Formula: 2^attempt * 1000 ms, capped at 60 seconds.
|
|
95
101
|
*/
|
|
96
102
|
getRetryAfter(attempt) {
|
|
@@ -98,16 +104,16 @@ class NotionClient {
|
|
|
98
104
|
return Math.min(backoffMs, 60000); // Cap at 60 seconds
|
|
99
105
|
}
|
|
100
106
|
/**
|
|
101
|
-
*
|
|
107
|
+
* Pause for the given duration, in milliseconds.
|
|
102
108
|
*/
|
|
103
109
|
sleep(ms) {
|
|
104
110
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
105
111
|
}
|
|
106
112
|
/**
|
|
107
|
-
*
|
|
113
|
+
* Build the full URL with query parameters.
|
|
108
114
|
*/
|
|
109
115
|
buildUrl(path, query) {
|
|
110
|
-
const url = new URL(`${this.baseUrl}
|
|
116
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
111
117
|
if (query) {
|
|
112
118
|
Object.entries(query).forEach(([key, value]) => {
|
|
113
119
|
if (value === undefined) {
|
|
@@ -124,19 +130,8 @@ class NotionClient {
|
|
|
124
130
|
return url.toString();
|
|
125
131
|
}
|
|
126
132
|
/**
|
|
127
|
-
*
|
|
128
|
-
|
|
129
|
-
buildHeaders() {
|
|
130
|
-
return {
|
|
131
|
-
Authorization: `Bearer ${this.auth}`,
|
|
132
|
-
'Content-Type': 'application/json',
|
|
133
|
-
'Notion-Version': exports.NOTION_VERSION,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Parses the `Retry-After` response header into milliseconds.
|
|
138
|
-
* Returns `undefined` when the header is absent or not a valid
|
|
139
|
-
* non-negative integer.
|
|
133
|
+
* Parse the `Retry-After` response header into milliseconds.
|
|
134
|
+
* Return `undefined` if the header is missing or not a valid non-negative number.
|
|
140
135
|
*/
|
|
141
136
|
parseRetryAfterHeader(response) {
|
|
142
137
|
const header = response.headers.get('Retry-After');
|
|
@@ -150,7 +145,7 @@ class NotionClient {
|
|
|
150
145
|
return Math.ceil(seconds) * 1000;
|
|
151
146
|
}
|
|
152
147
|
/**
|
|
153
|
-
*
|
|
148
|
+
* Handle an error response from the API.
|
|
154
149
|
*/
|
|
155
150
|
async handleErrorResponse(response) {
|
|
156
151
|
const retryAfterMs = this.parseRetryAfterHeader(response);
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Notion API error codes based on official documentation.
|
|
3
|
+
*
|
|
4
|
+
* @category Errors
|
|
3
5
|
*/
|
|
4
6
|
export type NotionErrorCode = 'invalid_json' | 'invalid_request_url' | 'invalid_request' | 'validation_error' | 'missing_version' | 'unauthorized' | 'restricted_resource' | 'object_not_found' | 'conflict_error' | 'rate_limited' | 'internal_server_error' | 'service_unavailable' | 'service_overload' | 'database_connection_unavailable' | 'gateway_timeout';
|
|
5
7
|
/**
|
|
6
8
|
* Notion API error response structure.
|
|
9
|
+
*
|
|
10
|
+
* @category Errors
|
|
7
11
|
*/
|
|
8
12
|
export interface NotionErrorResponse {
|
|
9
13
|
object: 'error';
|
|
10
14
|
status: number;
|
|
11
15
|
code: NotionErrorCode;
|
|
12
16
|
message: string;
|
|
17
|
+
/** Extra machine-readable context for some error codes, for example `restricted_resource`. */
|
|
18
|
+
additional_data?: Record<string, unknown>;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
|
-
*
|
|
21
|
+
* Thrown when the Notion API returns an error response.
|
|
22
|
+
*
|
|
23
|
+
* @category Errors
|
|
16
24
|
*/
|
|
17
25
|
export declare class NotionAPIError extends Error {
|
|
18
26
|
readonly status: number;
|
|
@@ -33,9 +41,14 @@ export declare class NotionAPIError extends Error {
|
|
|
33
41
|
*/
|
|
34
42
|
isUnauthorized(): boolean;
|
|
35
43
|
/**
|
|
36
|
-
* Check if the
|
|
44
|
+
* Check if the API could not find the requested object.
|
|
37
45
|
*/
|
|
38
46
|
isNotFound(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Check if a workspace restriction blocked the request.
|
|
49
|
+
* The Free workspace block limit is one example.
|
|
50
|
+
*/
|
|
51
|
+
isRestrictedResource(): boolean;
|
|
39
52
|
/**
|
|
40
53
|
* Check if the error is a validation error.
|
|
41
54
|
*/
|
|
@@ -50,13 +63,17 @@ export declare class NotionAPIError extends Error {
|
|
|
50
63
|
isRetryable(): boolean;
|
|
51
64
|
}
|
|
52
65
|
/**
|
|
53
|
-
*
|
|
66
|
+
* Thrown when a request exceeds its timeout.
|
|
67
|
+
*
|
|
68
|
+
* @category Errors
|
|
54
69
|
*/
|
|
55
70
|
export declare class NotionRequestTimeoutError extends Error {
|
|
56
71
|
constructor(message?: string);
|
|
57
72
|
}
|
|
58
73
|
/**
|
|
59
|
-
*
|
|
74
|
+
* Thrown when a network problem, such as a DNS failure, blocks a request.
|
|
75
|
+
*
|
|
76
|
+
* @category Errors
|
|
60
77
|
*/
|
|
61
78
|
export declare class NotionNetworkError extends Error {
|
|
62
79
|
readonly cause?: Error;
|
package/dist/errors.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotionNetworkError = exports.NotionRequestTimeoutError = exports.NotionAPIError = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Thrown when the Notion API returns an error response.
|
|
6
|
+
*
|
|
7
|
+
* @category Errors
|
|
6
8
|
*/
|
|
7
9
|
class NotionAPIError extends Error {
|
|
8
10
|
constructor(response, retryAfterMs) {
|
|
@@ -36,11 +38,18 @@ class NotionAPIError extends Error {
|
|
|
36
38
|
return this.code === 'unauthorized';
|
|
37
39
|
}
|
|
38
40
|
/**
|
|
39
|
-
* Check if the
|
|
41
|
+
* Check if the API could not find the requested object.
|
|
40
42
|
*/
|
|
41
43
|
isNotFound() {
|
|
42
44
|
return this.code === 'object_not_found';
|
|
43
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if a workspace restriction blocked the request.
|
|
48
|
+
* The Free workspace block limit is one example.
|
|
49
|
+
*/
|
|
50
|
+
isRestrictedResource() {
|
|
51
|
+
return this.code === 'restricted_resource';
|
|
52
|
+
}
|
|
44
53
|
/**
|
|
45
54
|
* Check if the error is a validation error.
|
|
46
55
|
*/
|
|
@@ -62,7 +71,9 @@ class NotionAPIError extends Error {
|
|
|
62
71
|
}
|
|
63
72
|
exports.NotionAPIError = NotionAPIError;
|
|
64
73
|
/**
|
|
65
|
-
*
|
|
74
|
+
* Thrown when a request exceeds its timeout.
|
|
75
|
+
*
|
|
76
|
+
* @category Errors
|
|
66
77
|
*/
|
|
67
78
|
class NotionRequestTimeoutError extends Error {
|
|
68
79
|
constructor(message = 'Request timed out') {
|
|
@@ -75,7 +86,9 @@ class NotionRequestTimeoutError extends Error {
|
|
|
75
86
|
}
|
|
76
87
|
exports.NotionRequestTimeoutError = NotionRequestTimeoutError;
|
|
77
88
|
/**
|
|
78
|
-
*
|
|
89
|
+
* Thrown when a network problem, such as a DNS failure, blocks a request.
|
|
90
|
+
*
|
|
91
|
+
* @category Errors
|
|
79
92
|
*/
|
|
80
93
|
class NotionNetworkError extends Error {
|
|
81
94
|
constructor(message, cause) {
|