@visus-io/notion-sdk-ts 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/blocks.api.d.ts +1083 -224
- package/dist/api/blocks.api.js +4 -0
- package/dist/api/comments.api.d.ts +19 -1
- package/dist/api/comments.api.js +1 -1
- package/dist/api/dataSources.api.d.ts +36 -0
- package/dist/api/databases.api.d.ts +36 -0
- package/dist/api/databases.api.js +1 -0
- package/dist/api/fileUploads.api.d.ts +17 -7
- package/dist/api/fileUploads.api.js +30 -16
- package/dist/api/pages.api.d.ts +46 -0
- package/dist/client.d.ts +33 -2
- package/dist/client.js +88 -21
- package/dist/helpers/filter.helpers.d.ts +11 -4
- package/dist/helpers/filter.helpers.js +73 -30
- package/dist/helpers/pagination.helpers.d.ts +7 -2
- package/dist/helpers/pagination.helpers.js +26 -5
- package/dist/models/page.model.d.ts +20 -1
- package/dist/models/page.model.js +33 -2
- package/dist/schemas/block.schema.d.ts +1082 -224
- package/dist/schemas/block.schema.js +40 -25
- package/dist/schemas/comment.schema.d.ts +18 -0
- package/dist/schemas/dataSource.schema.d.ts +36 -0
- package/dist/schemas/database.schema.d.ts +36 -0
- package/dist/schemas/meetingNotesQuery.schema.d.ts +1082 -224
- package/dist/schemas/page.schema.d.ts +46 -0
- package/dist/schemas/page.schema.js +2 -1
- package/dist/schemas/pageMarkdown.schema.js +1 -1
- package/dist/schemas/pageProperties.schema.d.ts +99 -1
- package/dist/schemas/pageProperties.schema.js +16 -1
- package/dist/schemas/pagination.schema.d.ts +1 -1
- package/dist/schemas/propertyObjects.schema.js +2 -1
- package/dist/schemas/richText.schema.d.ts +36 -0
- package/dist/schemas/richText.schema.js +21 -0
- package/dist/schemas/shared.schema.d.ts +3 -7
- package/dist/schemas/shared.schema.js +5 -9
- package/dist/schemas/view.schema.d.ts +46 -0
- package/dist/validation.d.ts +8 -0
- package/dist/validation.js +16 -0
- package/package.json +1 -1
package/dist/api/blocks.api.js
CHANGED
|
@@ -71,6 +71,7 @@ class BlocksAPI extends base_api_1.BaseAPI {
|
|
|
71
71
|
*
|
|
72
72
|
* @param options - Filter, sort, and limit options
|
|
73
73
|
* @returns Matching meeting-notes blocks
|
|
74
|
+
* @throws {NotionValidationError} If `limit` is outside the range 1 to 50.
|
|
74
75
|
*
|
|
75
76
|
* @see https://developers.notion.com/reference/query-meeting-notes
|
|
76
77
|
*/
|
|
@@ -78,6 +79,9 @@ class BlocksAPI extends base_api_1.BaseAPI {
|
|
|
78
79
|
if (options?.sort) {
|
|
79
80
|
(0, validation_1.validateArrayLength)(options.sort, validation_1.LIMITS.ARRAY_ELEMENTS, 'sort');
|
|
80
81
|
}
|
|
82
|
+
if (options?.limit !== undefined) {
|
|
83
|
+
(0, validation_1.validateNumberRange)(options.limit, 1, 50, 'limit');
|
|
84
|
+
}
|
|
81
85
|
const body = {};
|
|
82
86
|
if (options?.filter) {
|
|
83
87
|
body.filter = options.filter;
|
|
@@ -162,10 +162,23 @@ export declare class CommentsAPI extends BaseAPI<NotionComment, Comment> {
|
|
|
162
162
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
163
163
|
type: import("zod").ZodLiteral<"mention">;
|
|
164
164
|
mention: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
165
|
+
type: import("zod").ZodLiteral<"custom_emoji">;
|
|
166
|
+
custom_emoji: import("zod").ZodObject<{
|
|
167
|
+
id: import("zod").ZodUUID;
|
|
168
|
+
name: import("zod").ZodString;
|
|
169
|
+
url: import("zod").ZodURL;
|
|
170
|
+
}, import("zod/v4/core").$strip>;
|
|
171
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
165
172
|
type: import("zod").ZodLiteral<"database">;
|
|
166
173
|
database: import("zod").ZodObject<{
|
|
167
174
|
id: import("zod").ZodUUID;
|
|
168
175
|
}, import("zod/v4/core").$strip>;
|
|
176
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
177
|
+
type: import("zod").ZodLiteral<"data_source">;
|
|
178
|
+
data_source: import("zod").ZodObject<{
|
|
179
|
+
id: import("zod").ZodUUID;
|
|
180
|
+
database_id: import("zod").ZodOptional<import("zod").ZodUUID>;
|
|
181
|
+
}, import("zod/v4/core").$strip>;
|
|
169
182
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
170
183
|
type: import("zod").ZodLiteral<"date">;
|
|
171
184
|
date: import("zod").ZodObject<{
|
|
@@ -173,6 +186,11 @@ export declare class CommentsAPI extends BaseAPI<NotionComment, Comment> {
|
|
|
173
186
|
end: import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>>;
|
|
174
187
|
time_zone: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
175
188
|
}, import("zod/v4/core").$strip>;
|
|
189
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
190
|
+
type: import("zod").ZodLiteral<"link_mention">;
|
|
191
|
+
link_mention: import("zod").ZodObject<{
|
|
192
|
+
href: import("zod").ZodString;
|
|
193
|
+
}, import("zod/v4/core").$loose>;
|
|
176
194
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
177
195
|
type: import("zod").ZodLiteral<"link_preview">;
|
|
178
196
|
link_preview: import("zod").ZodObject<{
|
|
@@ -329,7 +347,7 @@ export declare class CommentsAPI extends BaseAPI<NotionComment, Comment> {
|
|
|
329
347
|
* @param params - Pagination parameters
|
|
330
348
|
* @returns Paginated list of comments
|
|
331
349
|
*
|
|
332
|
-
* @see https://developers.notion.com/reference/retrieve-a-comment
|
|
350
|
+
* @see https://developers.notion.com/reference/retrieve-a-comment-list
|
|
333
351
|
*/
|
|
334
352
|
list(parentId: string, params?: PaginationParameters): Promise<PaginatedList<Comment>>;
|
|
335
353
|
/**
|
package/dist/api/comments.api.js
CHANGED
|
@@ -39,7 +39,7 @@ class CommentsAPI extends base_api_1.BaseAPI {
|
|
|
39
39
|
* @param params - Pagination parameters
|
|
40
40
|
* @returns Paginated list of comments
|
|
41
41
|
*
|
|
42
|
-
* @see https://developers.notion.com/reference/retrieve-a-comment
|
|
42
|
+
* @see https://developers.notion.com/reference/retrieve-a-comment-list
|
|
43
43
|
*/
|
|
44
44
|
async list(parentId, params) {
|
|
45
45
|
const query = {
|
|
@@ -541,10 +541,23 @@ export declare class DataSourcesAPI extends BaseAPI<NotionDataSource, DataSource
|
|
|
541
541
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
542
542
|
type: import("zod").ZodLiteral<"mention">;
|
|
543
543
|
mention: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
544
|
+
type: import("zod").ZodLiteral<"custom_emoji">;
|
|
545
|
+
custom_emoji: import("zod").ZodObject<{
|
|
546
|
+
id: import("zod").ZodUUID;
|
|
547
|
+
name: import("zod").ZodString;
|
|
548
|
+
url: import("zod").ZodURL;
|
|
549
|
+
}, import("zod/v4/core").$strip>;
|
|
550
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
544
551
|
type: import("zod").ZodLiteral<"database">;
|
|
545
552
|
database: import("zod").ZodObject<{
|
|
546
553
|
id: import("zod").ZodUUID;
|
|
547
554
|
}, import("zod/v4/core").$strip>;
|
|
555
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
556
|
+
type: import("zod").ZodLiteral<"data_source">;
|
|
557
|
+
data_source: import("zod").ZodObject<{
|
|
558
|
+
id: import("zod").ZodUUID;
|
|
559
|
+
database_id: import("zod").ZodOptional<import("zod").ZodUUID>;
|
|
560
|
+
}, import("zod/v4/core").$strip>;
|
|
548
561
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
549
562
|
type: import("zod").ZodLiteral<"date">;
|
|
550
563
|
date: import("zod").ZodObject<{
|
|
@@ -552,6 +565,11 @@ export declare class DataSourcesAPI extends BaseAPI<NotionDataSource, DataSource
|
|
|
552
565
|
end: import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>>;
|
|
553
566
|
time_zone: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
554
567
|
}, import("zod/v4/core").$strip>;
|
|
568
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
569
|
+
type: import("zod").ZodLiteral<"link_mention">;
|
|
570
|
+
link_mention: import("zod").ZodObject<{
|
|
571
|
+
href: import("zod").ZodString;
|
|
572
|
+
}, import("zod/v4/core").$loose>;
|
|
555
573
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
556
574
|
type: import("zod").ZodLiteral<"link_preview">;
|
|
557
575
|
link_preview: import("zod").ZodObject<{
|
|
@@ -717,10 +735,23 @@ export declare class DataSourcesAPI extends BaseAPI<NotionDataSource, DataSource
|
|
|
717
735
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
718
736
|
type: import("zod").ZodLiteral<"mention">;
|
|
719
737
|
mention: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
738
|
+
type: import("zod").ZodLiteral<"custom_emoji">;
|
|
739
|
+
custom_emoji: import("zod").ZodObject<{
|
|
740
|
+
id: import("zod").ZodUUID;
|
|
741
|
+
name: import("zod").ZodString;
|
|
742
|
+
url: import("zod").ZodURL;
|
|
743
|
+
}, import("zod/v4/core").$strip>;
|
|
744
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
720
745
|
type: import("zod").ZodLiteral<"database">;
|
|
721
746
|
database: import("zod").ZodObject<{
|
|
722
747
|
id: import("zod").ZodUUID;
|
|
723
748
|
}, import("zod/v4/core").$strip>;
|
|
749
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
750
|
+
type: import("zod").ZodLiteral<"data_source">;
|
|
751
|
+
data_source: import("zod").ZodObject<{
|
|
752
|
+
id: import("zod").ZodUUID;
|
|
753
|
+
database_id: import("zod").ZodOptional<import("zod").ZodUUID>;
|
|
754
|
+
}, import("zod/v4/core").$strip>;
|
|
724
755
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
725
756
|
type: import("zod").ZodLiteral<"date">;
|
|
726
757
|
date: import("zod").ZodObject<{
|
|
@@ -728,6 +759,11 @@ export declare class DataSourcesAPI extends BaseAPI<NotionDataSource, DataSource
|
|
|
728
759
|
end: import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>>;
|
|
729
760
|
time_zone: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
730
761
|
}, import("zod/v4/core").$strip>;
|
|
762
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
763
|
+
type: import("zod").ZodLiteral<"link_mention">;
|
|
764
|
+
link_mention: import("zod").ZodObject<{
|
|
765
|
+
href: import("zod").ZodString;
|
|
766
|
+
}, import("zod/v4/core").$loose>;
|
|
731
767
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
732
768
|
type: import("zod").ZodLiteral<"link_preview">;
|
|
733
769
|
link_preview: import("zod").ZodObject<{
|
|
@@ -229,10 +229,23 @@ export declare class DatabasesAPI extends BaseAPI<NotionDatabase, Database> {
|
|
|
229
229
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
230
230
|
type: import("zod").ZodLiteral<"mention">;
|
|
231
231
|
mention: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
232
|
+
type: import("zod").ZodLiteral<"custom_emoji">;
|
|
233
|
+
custom_emoji: import("zod").ZodObject<{
|
|
234
|
+
id: import("zod").ZodUUID;
|
|
235
|
+
name: import("zod").ZodString;
|
|
236
|
+
url: import("zod").ZodURL;
|
|
237
|
+
}, import("zod/v4/core").$strip>;
|
|
238
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
232
239
|
type: import("zod").ZodLiteral<"database">;
|
|
233
240
|
database: import("zod").ZodObject<{
|
|
234
241
|
id: import("zod").ZodUUID;
|
|
235
242
|
}, import("zod/v4/core").$strip>;
|
|
243
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
244
|
+
type: import("zod").ZodLiteral<"data_source">;
|
|
245
|
+
data_source: import("zod").ZodObject<{
|
|
246
|
+
id: import("zod").ZodUUID;
|
|
247
|
+
database_id: import("zod").ZodOptional<import("zod").ZodUUID>;
|
|
248
|
+
}, import("zod/v4/core").$strip>;
|
|
236
249
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
237
250
|
type: import("zod").ZodLiteral<"date">;
|
|
238
251
|
date: import("zod").ZodObject<{
|
|
@@ -240,6 +253,11 @@ export declare class DatabasesAPI extends BaseAPI<NotionDatabase, Database> {
|
|
|
240
253
|
end: import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>>;
|
|
241
254
|
time_zone: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
242
255
|
}, import("zod/v4/core").$strip>;
|
|
256
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
257
|
+
type: import("zod").ZodLiteral<"link_mention">;
|
|
258
|
+
link_mention: import("zod").ZodObject<{
|
|
259
|
+
href: import("zod").ZodString;
|
|
260
|
+
}, import("zod/v4/core").$loose>;
|
|
243
261
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
244
262
|
type: import("zod").ZodLiteral<"link_preview">;
|
|
245
263
|
link_preview: import("zod").ZodObject<{
|
|
@@ -405,10 +423,23 @@ export declare class DatabasesAPI extends BaseAPI<NotionDatabase, Database> {
|
|
|
405
423
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
406
424
|
type: import("zod").ZodLiteral<"mention">;
|
|
407
425
|
mention: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
426
|
+
type: import("zod").ZodLiteral<"custom_emoji">;
|
|
427
|
+
custom_emoji: import("zod").ZodObject<{
|
|
428
|
+
id: import("zod").ZodUUID;
|
|
429
|
+
name: import("zod").ZodString;
|
|
430
|
+
url: import("zod").ZodURL;
|
|
431
|
+
}, import("zod/v4/core").$strip>;
|
|
432
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
408
433
|
type: import("zod").ZodLiteral<"database">;
|
|
409
434
|
database: import("zod").ZodObject<{
|
|
410
435
|
id: import("zod").ZodUUID;
|
|
411
436
|
}, import("zod/v4/core").$strip>;
|
|
437
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
438
|
+
type: import("zod").ZodLiteral<"data_source">;
|
|
439
|
+
data_source: import("zod").ZodObject<{
|
|
440
|
+
id: import("zod").ZodUUID;
|
|
441
|
+
database_id: import("zod").ZodOptional<import("zod").ZodUUID>;
|
|
442
|
+
}, import("zod/v4/core").$strip>;
|
|
412
443
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
413
444
|
type: import("zod").ZodLiteral<"date">;
|
|
414
445
|
date: import("zod").ZodObject<{
|
|
@@ -416,6 +447,11 @@ export declare class DatabasesAPI extends BaseAPI<NotionDatabase, Database> {
|
|
|
416
447
|
end: import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>>;
|
|
417
448
|
time_zone: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
418
449
|
}, import("zod/v4/core").$strip>;
|
|
450
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
451
|
+
type: import("zod").ZodLiteral<"link_mention">;
|
|
452
|
+
link_mention: import("zod").ZodObject<{
|
|
453
|
+
href: import("zod").ZodString;
|
|
454
|
+
}, import("zod/v4/core").$loose>;
|
|
419
455
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
420
456
|
type: import("zod").ZodLiteral<"link_preview">;
|
|
421
457
|
link_preview: import("zod").ZodObject<{
|
|
@@ -14,9 +14,12 @@ export interface InitiateFileUploadOptions {
|
|
|
14
14
|
content_length: number;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* File data for uploading
|
|
17
|
+
* File data for uploading. Accepts a `Buffer`, `Uint8Array`, `ArrayBuffer`, or
|
|
18
|
+
* `Blob`. The upload endpoint uses `multipart/form-data`, so the SDK cannot
|
|
19
|
+
* stream a `ReadableStream` without buffering it in full. Read a stream into a
|
|
20
|
+
* `Buffer` yourself before you call `upload()`.
|
|
18
21
|
*/
|
|
19
|
-
export type FileData = Buffer |
|
|
22
|
+
export type FileData = Buffer | Uint8Array | ArrayBuffer | Blob;
|
|
20
23
|
/**
|
|
21
24
|
* FileUploads API client for uploading files to Notion.
|
|
22
25
|
*
|
|
@@ -56,17 +59,24 @@ export declare class FileUploadsAPI extends BaseAPI<NotionFileUpload, FileUpload
|
|
|
56
59
|
*/
|
|
57
60
|
initiate(options: InitiateFileUploadOptions): Promise<FileUpload>;
|
|
58
61
|
/**
|
|
59
|
-
* Upload file data to the upload URL.
|
|
60
|
-
*
|
|
61
|
-
* through the Notion API.
|
|
62
|
+
* Upload file data to the upload URL from initiate(). Sends `multipart/form-data`
|
|
63
|
+
* through the configured `NotionClient`.
|
|
62
64
|
*
|
|
63
65
|
* @param uploadUrl - The upload URL from initiate()
|
|
64
66
|
* @param fileData - The file data to upload
|
|
65
67
|
* @param contentType - The MIME type of the file
|
|
68
|
+
* @param partNumber - The 1-based part number, for a multi-part upload of a file
|
|
69
|
+
* larger than 20 MB. Pass a positive integer.
|
|
70
|
+
* @throws {NotionValidationError} If `partNumber` is not a positive integer.
|
|
71
|
+
* @throws {NotionAPIError} If the upload endpoint returns an error response.
|
|
66
72
|
*
|
|
67
|
-
* @see https://developers.notion.com/reference/upload-
|
|
73
|
+
* @see https://developers.notion.com/reference/upload-file
|
|
68
74
|
*/
|
|
69
|
-
upload(uploadUrl: string, fileData: FileData, contentType: string): Promise<void>;
|
|
75
|
+
upload(uploadUrl: string, fileData: FileData, contentType: string, partNumber?: number): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Convert file data into a `Blob` for the multipart request body.
|
|
78
|
+
*/
|
|
79
|
+
private static toBlob;
|
|
70
80
|
/**
|
|
71
81
|
* Complete the file upload after uploading to the URL.
|
|
72
82
|
*
|
|
@@ -4,6 +4,7 @@ exports.FileUploadsAPI = void 0;
|
|
|
4
4
|
const schemas_1 = require("../schemas");
|
|
5
5
|
const models_1 = require("../models");
|
|
6
6
|
const base_model_1 = require("../models/base.model");
|
|
7
|
+
const validation_1 = require("../validation");
|
|
7
8
|
const base_api_1 = require("./base.api");
|
|
8
9
|
/**
|
|
9
10
|
* FileUploads API client for uploading files to Notion.
|
|
@@ -37,27 +38,38 @@ class FileUploadsAPI extends base_api_1.BaseAPI {
|
|
|
37
38
|
return new models_1.FileUpload(parsed, base_model_1.TRUSTED);
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
* Upload file data to the upload URL.
|
|
41
|
-
*
|
|
42
|
-
* through the Notion API.
|
|
41
|
+
* Upload file data to the upload URL from initiate(). Sends `multipart/form-data`
|
|
42
|
+
* through the configured `NotionClient`.
|
|
43
43
|
*
|
|
44
44
|
* @param uploadUrl - The upload URL from initiate()
|
|
45
45
|
* @param fileData - The file data to upload
|
|
46
46
|
* @param contentType - The MIME type of the file
|
|
47
|
+
* @param partNumber - The 1-based part number, for a multi-part upload of a file
|
|
48
|
+
* larger than 20 MB. Pass a positive integer.
|
|
49
|
+
* @throws {NotionValidationError} If `partNumber` is not a positive integer.
|
|
50
|
+
* @throws {NotionAPIError} If the upload endpoint returns an error response.
|
|
47
51
|
*
|
|
48
|
-
* @see https://developers.notion.com/reference/upload-
|
|
52
|
+
* @see https://developers.notion.com/reference/upload-file
|
|
49
53
|
*/
|
|
50
|
-
async upload(uploadUrl, fileData, contentType) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (!response.ok) {
|
|
59
|
-
throw new Error(`File upload failed: ${response.status} ${response.statusText}`);
|
|
54
|
+
async upload(uploadUrl, fileData, contentType, partNumber) {
|
|
55
|
+
const form = new FormData();
|
|
56
|
+
form.append('file', FileUploadsAPI.toBlob(fileData, contentType));
|
|
57
|
+
if (partNumber !== undefined) {
|
|
58
|
+
if (!Number.isInteger(partNumber) || partNumber < 1) {
|
|
59
|
+
throw new validation_1.NotionValidationError(`partNumber must be a positive integer (got ${partNumber})`);
|
|
60
|
+
}
|
|
61
|
+
form.append('part_number', String(partNumber));
|
|
60
62
|
}
|
|
63
|
+
await this.client.sendFileUpload(uploadUrl, form);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Convert file data into a `Blob` for the multipart request body.
|
|
67
|
+
*/
|
|
68
|
+
static toBlob(fileData, contentType) {
|
|
69
|
+
if (fileData instanceof Blob) {
|
|
70
|
+
return fileData;
|
|
71
|
+
}
|
|
72
|
+
return new Blob([new Uint8Array(fileData)], { type: contentType });
|
|
61
73
|
}
|
|
62
74
|
/**
|
|
63
75
|
* Complete the file upload after uploading to the URL.
|
|
@@ -101,11 +113,13 @@ class FileUploadsAPI extends base_api_1.BaseAPI {
|
|
|
101
113
|
* @returns The completed file upload object
|
|
102
114
|
*/
|
|
103
115
|
async uploadFile(filename, fileData, contentType) {
|
|
104
|
-
// Get content length
|
|
105
116
|
let contentLength;
|
|
106
117
|
if (fileData instanceof Buffer) {
|
|
107
118
|
contentLength = fileData.length;
|
|
108
119
|
}
|
|
120
|
+
else if (fileData instanceof Uint8Array) {
|
|
121
|
+
contentLength = fileData.byteLength;
|
|
122
|
+
}
|
|
109
123
|
else if (fileData instanceof ArrayBuffer) {
|
|
110
124
|
contentLength = fileData.byteLength;
|
|
111
125
|
}
|
|
@@ -113,7 +127,7 @@ class FileUploadsAPI extends base_api_1.BaseAPI {
|
|
|
113
127
|
contentLength = fileData.size;
|
|
114
128
|
}
|
|
115
129
|
else {
|
|
116
|
-
throw new TypeError('
|
|
130
|
+
throw new TypeError('Unsupported file data type. Pass a Buffer, Uint8Array, ArrayBuffer, or Blob.');
|
|
117
131
|
}
|
|
118
132
|
// Step 1: Initiate upload
|
|
119
133
|
const fileUpload = await this.initiate({
|
package/dist/api/pages.api.d.ts
CHANGED
|
@@ -496,6 +496,16 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
496
496
|
id: import("zod").ZodString;
|
|
497
497
|
type: import("zod").ZodLiteral<"phone_number">;
|
|
498
498
|
phone_number: import("zod").ZodNullable<import("zod").ZodString>;
|
|
499
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
500
|
+
id: import("zod").ZodString;
|
|
501
|
+
type: import("zod").ZodLiteral<"place">;
|
|
502
|
+
place: import("zod").ZodNullable<import("zod").ZodObject<{
|
|
503
|
+
name: import("zod").ZodOptional<import("zod").ZodString>;
|
|
504
|
+
address: import("zod").ZodOptional<import("zod").ZodString>;
|
|
505
|
+
latitude: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
506
|
+
longitude: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
507
|
+
google_place_id: import("zod").ZodOptional<import("zod").ZodString>;
|
|
508
|
+
}, import("zod/v4/core").$loose>>;
|
|
499
509
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
500
510
|
id: import("zod").ZodString;
|
|
501
511
|
type: import("zod").ZodLiteral<"relation">;
|
|
@@ -547,10 +557,23 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
547
557
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
548
558
|
type: import("zod").ZodLiteral<"mention">;
|
|
549
559
|
mention: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
560
|
+
type: import("zod").ZodLiteral<"custom_emoji">;
|
|
561
|
+
custom_emoji: import("zod").ZodObject<{
|
|
562
|
+
id: import("zod").ZodUUID;
|
|
563
|
+
name: import("zod").ZodString;
|
|
564
|
+
url: import("zod").ZodURL;
|
|
565
|
+
}, import("zod/v4/core").$strip>;
|
|
566
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
550
567
|
type: import("zod").ZodLiteral<"database">;
|
|
551
568
|
database: import("zod").ZodObject<{
|
|
552
569
|
id: import("zod").ZodUUID;
|
|
553
570
|
}, import("zod/v4/core").$strip>;
|
|
571
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
572
|
+
type: import("zod").ZodLiteral<"data_source">;
|
|
573
|
+
data_source: import("zod").ZodObject<{
|
|
574
|
+
id: import("zod").ZodUUID;
|
|
575
|
+
database_id: import("zod").ZodOptional<import("zod").ZodUUID>;
|
|
576
|
+
}, import("zod/v4/core").$strip>;
|
|
554
577
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
555
578
|
type: import("zod").ZodLiteral<"date">;
|
|
556
579
|
date: import("zod").ZodObject<{
|
|
@@ -558,6 +581,11 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
558
581
|
end: import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>>;
|
|
559
582
|
time_zone: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
560
583
|
}, import("zod/v4/core").$strip>;
|
|
584
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
585
|
+
type: import("zod").ZodLiteral<"link_mention">;
|
|
586
|
+
link_mention: import("zod").ZodObject<{
|
|
587
|
+
href: import("zod").ZodString;
|
|
588
|
+
}, import("zod/v4/core").$loose>;
|
|
561
589
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
562
590
|
type: import("zod").ZodLiteral<"link_preview">;
|
|
563
591
|
link_preview: import("zod").ZodObject<{
|
|
@@ -827,10 +855,23 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
827
855
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
828
856
|
type: import("zod").ZodLiteral<"mention">;
|
|
829
857
|
mention: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
|
|
858
|
+
type: import("zod").ZodLiteral<"custom_emoji">;
|
|
859
|
+
custom_emoji: import("zod").ZodObject<{
|
|
860
|
+
id: import("zod").ZodUUID;
|
|
861
|
+
name: import("zod").ZodString;
|
|
862
|
+
url: import("zod").ZodURL;
|
|
863
|
+
}, import("zod/v4/core").$strip>;
|
|
864
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
830
865
|
type: import("zod").ZodLiteral<"database">;
|
|
831
866
|
database: import("zod").ZodObject<{
|
|
832
867
|
id: import("zod").ZodUUID;
|
|
833
868
|
}, import("zod/v4/core").$strip>;
|
|
869
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
870
|
+
type: import("zod").ZodLiteral<"data_source">;
|
|
871
|
+
data_source: import("zod").ZodObject<{
|
|
872
|
+
id: import("zod").ZodUUID;
|
|
873
|
+
database_id: import("zod").ZodOptional<import("zod").ZodUUID>;
|
|
874
|
+
}, import("zod/v4/core").$strip>;
|
|
834
875
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
835
876
|
type: import("zod").ZodLiteral<"date">;
|
|
836
877
|
date: import("zod").ZodObject<{
|
|
@@ -838,6 +879,11 @@ export declare class PagesAPI extends BaseAPI<NotionPage, Page> {
|
|
|
838
879
|
end: import("zod").ZodNullable<import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>>;
|
|
839
880
|
time_zone: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
|
|
840
881
|
}, import("zod/v4/core").$strip>;
|
|
882
|
+
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
883
|
+
type: import("zod").ZodLiteral<"link_mention">;
|
|
884
|
+
link_mention: import("zod").ZodObject<{
|
|
885
|
+
href: import("zod").ZodString;
|
|
886
|
+
}, import("zod/v4/core").$loose>;
|
|
841
887
|
}, import("zod/v4/core").$strip>, import("zod").ZodObject<{
|
|
842
888
|
type: import("zod").ZodLiteral<"link_preview">;
|
|
843
889
|
link_preview: import("zod").ZodObject<{
|
package/dist/client.d.ts
CHANGED
|
@@ -49,10 +49,40 @@ export declare class NotionClient {
|
|
|
49
49
|
* Retry automatically on rate-limited and overloaded responses.
|
|
50
50
|
*/
|
|
51
51
|
request<T>(options: RequestOptions): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* Send a `multipart/form-data` `POST` to a Notion file-upload URL. Reuses the
|
|
54
|
+
* configured `fetch` and the request timeout. Does not retry. Does not set
|
|
55
|
+
* `Content-Type`, so `fetch` adds the multipart boundary.
|
|
56
|
+
*
|
|
57
|
+
* @param uploadUrl - The absolute `upload_url` from `fileUploads.initiate()`.
|
|
58
|
+
* @param form - A `FormData` body with the file bytes under the `file` key.
|
|
59
|
+
* @throws {NotionValidationError} If `uploadUrl` is not a valid `https` URL.
|
|
60
|
+
* @throws {NotionAPIError} If the endpoint returns an error response.
|
|
61
|
+
* @throws {NotionRequestTimeoutError} If the request exceeds the timeout.
|
|
62
|
+
* @throws {NotionNetworkError} If a network problem blocks the request.
|
|
63
|
+
*/
|
|
64
|
+
sendFileUpload(uploadUrl: string, form: FormData): Promise<void>;
|
|
52
65
|
/**
|
|
53
66
|
* Send one HTTP request to the Notion API.
|
|
54
67
|
*/
|
|
55
68
|
private makeRequest;
|
|
69
|
+
/**
|
|
70
|
+
* Call the configured `fetch` with an abort timeout of `timeoutMs`.
|
|
71
|
+
* Clear the timer as soon as the response headers arrive or the request fails.
|
|
72
|
+
*/
|
|
73
|
+
private fetchWithTimeout;
|
|
74
|
+
/**
|
|
75
|
+
* Map a transport-layer failure to the matching SDK error and throw it.
|
|
76
|
+
* Rethrow a `NotionAPIError` unchanged. Map an `AbortError` to
|
|
77
|
+
* `NotionRequestTimeoutError`. Map any other `Error` to `NotionNetworkError`.
|
|
78
|
+
*/
|
|
79
|
+
private mapTransportError;
|
|
80
|
+
/**
|
|
81
|
+
* Assert that `url` is a valid `https` URL. The SDK sends the API token in the
|
|
82
|
+
* `Authorization` header of a file upload. Reject a plaintext `http` URL so the
|
|
83
|
+
* token never travels unencrypted.
|
|
84
|
+
*/
|
|
85
|
+
private assertHttpsUrl;
|
|
56
86
|
/**
|
|
57
87
|
* Calculate a fallback retry delay with exponential backoff.
|
|
58
88
|
* Use this delay when the response has no `Retry-After` header.
|
|
@@ -68,8 +98,9 @@ export declare class NotionClient {
|
|
|
68
98
|
*/
|
|
69
99
|
private buildUrl;
|
|
70
100
|
/**
|
|
71
|
-
* Parse the `Retry-After` response header into milliseconds
|
|
72
|
-
* Return `undefined` if the header is missing or
|
|
101
|
+
* Parse the `Retry-After` response header into milliseconds, clamped to
|
|
102
|
+
* {@link MAX_RETRY_DELAY_MS}. Return `undefined` if the header is missing or
|
|
103
|
+
* not a valid non-negative number.
|
|
73
104
|
*/
|
|
74
105
|
private parseRetryAfterHeader;
|
|
75
106
|
/**
|