@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/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,9 +1,13 @@
|
|
|
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';
|
|
@@ -12,7 +16,9 @@ export interface NotionErrorResponse {
|
|
|
12
16
|
message: string;
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
|
-
*
|
|
19
|
+
* Thrown when the Notion API returns an error response.
|
|
20
|
+
*
|
|
21
|
+
* @category Errors
|
|
16
22
|
*/
|
|
17
23
|
export declare class NotionAPIError extends Error {
|
|
18
24
|
readonly status: number;
|
|
@@ -33,7 +39,7 @@ export declare class NotionAPIError extends Error {
|
|
|
33
39
|
*/
|
|
34
40
|
isUnauthorized(): boolean;
|
|
35
41
|
/**
|
|
36
|
-
* Check if the
|
|
42
|
+
* Check if the API could not find the requested object.
|
|
37
43
|
*/
|
|
38
44
|
isNotFound(): boolean;
|
|
39
45
|
/**
|
|
@@ -50,13 +56,17 @@ export declare class NotionAPIError extends Error {
|
|
|
50
56
|
isRetryable(): boolean;
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
53
|
-
*
|
|
59
|
+
* Thrown when a request exceeds its timeout.
|
|
60
|
+
*
|
|
61
|
+
* @category Errors
|
|
54
62
|
*/
|
|
55
63
|
export declare class NotionRequestTimeoutError extends Error {
|
|
56
64
|
constructor(message?: string);
|
|
57
65
|
}
|
|
58
66
|
/**
|
|
59
|
-
*
|
|
67
|
+
* Thrown when a network problem, such as a DNS failure, blocks a request.
|
|
68
|
+
*
|
|
69
|
+
* @category Errors
|
|
60
70
|
*/
|
|
61
71
|
export declare class NotionNetworkError extends Error {
|
|
62
72
|
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,7 +38,7 @@ 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';
|
|
@@ -62,7 +64,9 @@ class NotionAPIError extends Error {
|
|
|
62
64
|
}
|
|
63
65
|
exports.NotionAPIError = NotionAPIError;
|
|
64
66
|
/**
|
|
65
|
-
*
|
|
67
|
+
* Thrown when a request exceeds its timeout.
|
|
68
|
+
*
|
|
69
|
+
* @category Errors
|
|
66
70
|
*/
|
|
67
71
|
class NotionRequestTimeoutError extends Error {
|
|
68
72
|
constructor(message = 'Request timed out') {
|
|
@@ -75,7 +79,9 @@ class NotionRequestTimeoutError extends Error {
|
|
|
75
79
|
}
|
|
76
80
|
exports.NotionRequestTimeoutError = NotionRequestTimeoutError;
|
|
77
81
|
/**
|
|
78
|
-
*
|
|
82
|
+
* Thrown when a network problem, such as a DNS failure, blocks a request.
|
|
83
|
+
*
|
|
84
|
+
* @category Errors
|
|
79
85
|
*/
|
|
80
86
|
class NotionNetworkError extends Error {
|
|
81
87
|
constructor(message, cause) {
|
|
@@ -2,7 +2,9 @@ import type { CodeBlockLanguage, NotionColor, NotionRichText } from '../schemas'
|
|
|
2
2
|
import { RichTextBuilder } from './richText.helpers';
|
|
3
3
|
/**
|
|
4
4
|
* Accepted rich text input: a plain string, a {@link RichTextBuilder}, or
|
|
5
|
-
* a pre-built `NotionRichText
|
|
5
|
+
* a pre-built `NotionRichText`.
|
|
6
|
+
*
|
|
7
|
+
* @category Rich Text
|
|
6
8
|
*/
|
|
7
9
|
export type RichTextInput = string | RichTextBuilder | NotionRichText;
|
|
8
10
|
/** Common options shared by text-bearing blocks. */
|
|
@@ -10,7 +12,7 @@ interface TextBlockOptions {
|
|
|
10
12
|
color?: NotionColor;
|
|
11
13
|
children?: unknown[];
|
|
12
14
|
}
|
|
13
|
-
/** The
|
|
15
|
+
/** The Notion API accepts this minimal block object for creation. */
|
|
14
16
|
interface BlockObject {
|
|
15
17
|
object: 'block';
|
|
16
18
|
type: string;
|
|
@@ -18,7 +20,7 @@ interface BlockObject {
|
|
|
18
20
|
}
|
|
19
21
|
/** Options for paragraph blocks. */
|
|
20
22
|
interface ParagraphOptions extends TextBlockOptions {
|
|
21
|
-
/** Icon
|
|
23
|
+
/** Icon for the paragraph. Applies only to paragraphs used as tab items. */
|
|
22
24
|
icon?: unknown;
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
@@ -72,12 +74,12 @@ declare function template(text: RichTextInput, options?: {
|
|
|
72
74
|
children?: unknown[];
|
|
73
75
|
}): BlockObject;
|
|
74
76
|
/**
|
|
75
|
-
* @deprecated
|
|
76
|
-
* `status`, and child block IDs for the summary
|
|
77
|
-
*
|
|
78
|
-
* longer matches
|
|
79
|
-
*
|
|
80
|
-
* surface
|
|
77
|
+
* @deprecated Notion manages meeting-notes blocks on the server. Notion populates the
|
|
78
|
+
* real shape (`title`, `status`, and child block IDs for the summary, notes, and
|
|
79
|
+
* transcript). Clients do not construct this shape by hand. This helper's
|
|
80
|
+
* `rich_text`-based output no longer matches the `meeting_notes` shape in
|
|
81
|
+
* `blockSchema`. Do not use this helper to create a meeting-notes block. It remains
|
|
82
|
+
* only to avoid an abrupt removal from the helper surface. Do not use it in new code.
|
|
81
83
|
*/
|
|
82
84
|
declare function meetingNotes(text: RichTextInput, options?: {
|
|
83
85
|
children?: unknown[];
|
|
@@ -129,7 +131,10 @@ declare function table(width: number, options?: TableOptions): BlockObject;
|
|
|
129
131
|
declare function tableRow(cells: RichTextInput[]): BlockObject;
|
|
130
132
|
declare function columnList(columns: unknown[][]): BlockObject;
|
|
131
133
|
declare function column(children: unknown[]): BlockObject;
|
|
132
|
-
/**
|
|
134
|
+
/**
|
|
135
|
+
* A single tab. Its label becomes the tab's paragraph rich text.
|
|
136
|
+
* Its `children` become the tab's content.
|
|
137
|
+
*/
|
|
133
138
|
interface TabItem {
|
|
134
139
|
label: RichTextInput;
|
|
135
140
|
icon?: unknown;
|
|
@@ -137,9 +142,9 @@ interface TabItem {
|
|
|
137
142
|
children?: unknown[];
|
|
138
143
|
}
|
|
139
144
|
/**
|
|
140
|
-
* Create a tab block.
|
|
141
|
-
*
|
|
142
|
-
* `children` hold the tab's content.
|
|
145
|
+
* Create a tab block. A tab block accepts only `paragraph` blocks as direct children.
|
|
146
|
+
* Each tab is one paragraph. The paragraph's rich text holds the tab label. The
|
|
147
|
+
* paragraph's `children` hold the tab's content.
|
|
143
148
|
*
|
|
144
149
|
* @example
|
|
145
150
|
* ```ts
|
|
@@ -161,9 +166,9 @@ declare function syncedBlock(options?: {
|
|
|
161
166
|
children?: unknown[];
|
|
162
167
|
}): BlockObject;
|
|
163
168
|
/**
|
|
164
|
-
* Factory functions
|
|
169
|
+
* Factory functions that create Notion block objects.
|
|
165
170
|
*
|
|
166
|
-
* Every function returns a plain object
|
|
171
|
+
* Every function returns a plain object. Pass this object to
|
|
167
172
|
* `blocks.children.append()` or `pages.create()`.
|
|
168
173
|
*
|
|
169
174
|
* @example
|
|
@@ -189,6 +194,8 @@ declare function syncedBlock(options?: {
|
|
|
189
194
|
* }),
|
|
190
195
|
* ];
|
|
191
196
|
* ```
|
|
197
|
+
*
|
|
198
|
+
* @category Helpers
|
|
192
199
|
*/
|
|
193
200
|
export declare const block: {
|
|
194
201
|
paragraph: typeof paragraph;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.block = void 0;
|
|
4
4
|
const validation_1 = require("../validation");
|
|
5
5
|
const richText_helpers_1 = require("./richText.helpers");
|
|
6
|
-
/** Resolve a {@link RichTextInput} into a `NotionRichText
|
|
6
|
+
/** Resolve a {@link RichTextInput} into a `NotionRichText`. */
|
|
7
7
|
function resolveRichText(input) {
|
|
8
8
|
if (typeof input === 'string') {
|
|
9
9
|
(0, validation_1.validateStringLength)(input, validation_1.LIMITS.RICH_TEXT_CONTENT, 'Rich text content');
|
|
@@ -181,12 +181,12 @@ function template(text, options) {
|
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
183
|
/**
|
|
184
|
-
* @deprecated
|
|
185
|
-
* `status`, and child block IDs for the summary
|
|
186
|
-
*
|
|
187
|
-
* longer matches
|
|
188
|
-
*
|
|
189
|
-
* surface
|
|
184
|
+
* @deprecated Notion manages meeting-notes blocks on the server. Notion populates the
|
|
185
|
+
* real shape (`title`, `status`, and child block IDs for the summary, notes, and
|
|
186
|
+
* transcript). Clients do not construct this shape by hand. This helper's
|
|
187
|
+
* `rich_text`-based output no longer matches the `meeting_notes` shape in
|
|
188
|
+
* `blockSchema`. Do not use this helper to create a meeting-notes block. It remains
|
|
189
|
+
* only to avoid an abrupt removal from the helper surface. Do not use it in new code.
|
|
190
190
|
*/
|
|
191
191
|
function meetingNotes(text, options) {
|
|
192
192
|
return {
|
|
@@ -367,9 +367,9 @@ function column(children) {
|
|
|
367
367
|
};
|
|
368
368
|
}
|
|
369
369
|
/**
|
|
370
|
-
* Create a tab block.
|
|
371
|
-
*
|
|
372
|
-
* `children` hold the tab's content.
|
|
370
|
+
* Create a tab block. A tab block accepts only `paragraph` blocks as direct children.
|
|
371
|
+
* Each tab is one paragraph. The paragraph's rich text holds the tab label. The
|
|
372
|
+
* paragraph's `children` hold the tab's content.
|
|
373
373
|
*
|
|
374
374
|
* @example
|
|
375
375
|
* ```ts
|
|
@@ -411,9 +411,9 @@ function syncedBlock(options) {
|
|
|
411
411
|
// Public export
|
|
412
412
|
// ---------------------------------------------------------------------------
|
|
413
413
|
/**
|
|
414
|
-
* Factory functions
|
|
414
|
+
* Factory functions that create Notion block objects.
|
|
415
415
|
*
|
|
416
|
-
* Every function returns a plain object
|
|
416
|
+
* Every function returns a plain object. Pass this object to
|
|
417
417
|
* `blocks.children.append()` or `pages.create()`.
|
|
418
418
|
*
|
|
419
419
|
* @example
|
|
@@ -439,6 +439,8 @@ function syncedBlock(options) {
|
|
|
439
439
|
* }),
|
|
440
440
|
* ];
|
|
441
441
|
* ```
|
|
442
|
+
*
|
|
443
|
+
* @category Helpers
|
|
442
444
|
*/
|
|
443
445
|
exports.block = {
|
|
444
446
|
// Text blocks
|