@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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Sign a payload
|
|
2
|
+
* Sign a payload to generate test webhook signatures.
|
|
3
3
|
*
|
|
4
|
-
* @param body - The payload to sign.
|
|
5
|
-
* `JSON.stringify`
|
|
6
|
-
* serialization of
|
|
4
|
+
* @param body - The payload to sign. This function signs a string as-is. It
|
|
5
|
+
* converts anything else with `JSON.stringify` first. This is safe because the
|
|
6
|
+
* caller controls the serialization of their own payload.
|
|
7
7
|
* @param verificationToken - The webhook subscription's verification token
|
|
8
8
|
* @returns The `sha256=<hex digest>` signature
|
|
9
9
|
*
|
|
@@ -16,18 +16,18 @@ declare function sign(body: unknown, verificationToken: string): string;
|
|
|
16
16
|
/**
|
|
17
17
|
* Verify an incoming webhook's `X-Notion-Signature` header via constant-time comparison.
|
|
18
18
|
*
|
|
19
|
-
* IMPORTANT: `rawBody` must be the exact raw request body Notion sent
|
|
20
|
-
* `JSON.stringify(parsedBody)
|
|
21
|
-
*
|
|
22
|
-
* silently
|
|
23
|
-
* Express's `express.raw()`
|
|
24
|
-
*
|
|
19
|
+
* IMPORTANT: `rawBody` must be the exact raw request body that Notion sent. Do not use
|
|
20
|
+
* `JSON.stringify(parsedBody)`. Re-serializing a parsed object can produce a different
|
|
21
|
+
* byte sequence (key order, whitespace) than the original signed body, and this
|
|
22
|
+
* silently breaks verification. Use your framework's raw-body access, for example
|
|
23
|
+
* Express's `express.raw()` or `req.rawBody`. Do not use `req.body` after JSON
|
|
24
|
+
* middleware parses it.
|
|
25
25
|
*
|
|
26
26
|
* @param rawBody - The exact raw request body string Notion sent
|
|
27
27
|
* @param signatureHeader - The value of the `X-Notion-Signature` request header
|
|
28
28
|
* @param verificationToken - The webhook subscription's verification token
|
|
29
|
-
* @returns `true` if the signature is valid
|
|
30
|
-
* input
|
|
29
|
+
* @returns `true` if the signature is valid. Returns `false` for a mismatch or
|
|
30
|
+
* malformed input. This function never throws.
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* ```ts
|
|
@@ -44,6 +44,8 @@ declare function verifySignature(rawBody: string, signatureHeader: string | null
|
|
|
44
44
|
*
|
|
45
45
|
* const isValid = webhook.verifySignature(rawBody, req.headers['x-notion-signature'], verificationToken);
|
|
46
46
|
* ```
|
|
47
|
+
*
|
|
48
|
+
* @category Helpers
|
|
47
49
|
*/
|
|
48
50
|
export declare const webhook: {
|
|
49
51
|
sign: typeof sign;
|
|
@@ -5,9 +5,9 @@ const node_crypto_1 = require("node:crypto");
|
|
|
5
5
|
/**
|
|
6
6
|
* Webhook signature helpers.
|
|
7
7
|
*
|
|
8
|
-
* Notion signs webhook payloads with HMAC-SHA256
|
|
9
|
-
*
|
|
10
|
-
* `X-Notion-Signature` header as `sha256=<hex digest>`.
|
|
8
|
+
* Notion signs webhook payloads with HMAC-SHA256. It signs the raw JSON request body
|
|
9
|
+
* and keys the signature with the subscription's verification token. Notion sends the
|
|
10
|
+
* signature in the `X-Notion-Signature` header as `sha256=<hex digest>`.
|
|
11
11
|
*
|
|
12
12
|
* Notion API reference:
|
|
13
13
|
* https://developers.notion.com/reference/webhooks
|
|
@@ -16,11 +16,11 @@ function computeSignature(rawBody, verificationToken) {
|
|
|
16
16
|
return `sha256=${(0, node_crypto_1.createHmac)('sha256', verificationToken).update(rawBody).digest('hex')}`;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Sign a payload
|
|
19
|
+
* Sign a payload to generate test webhook signatures.
|
|
20
20
|
*
|
|
21
|
-
* @param body - The payload to sign.
|
|
22
|
-
* `JSON.stringify`
|
|
23
|
-
* serialization of
|
|
21
|
+
* @param body - The payload to sign. This function signs a string as-is. It
|
|
22
|
+
* converts anything else with `JSON.stringify` first. This is safe because the
|
|
23
|
+
* caller controls the serialization of their own payload.
|
|
24
24
|
* @param verificationToken - The webhook subscription's verification token
|
|
25
25
|
* @returns The `sha256=<hex digest>` signature
|
|
26
26
|
*
|
|
@@ -35,18 +35,18 @@ function sign(body, verificationToken) {
|
|
|
35
35
|
/**
|
|
36
36
|
* Verify an incoming webhook's `X-Notion-Signature` header via constant-time comparison.
|
|
37
37
|
*
|
|
38
|
-
* IMPORTANT: `rawBody` must be the exact raw request body Notion sent
|
|
39
|
-
* `JSON.stringify(parsedBody)
|
|
40
|
-
*
|
|
41
|
-
* silently
|
|
42
|
-
* Express's `express.raw()`
|
|
43
|
-
*
|
|
38
|
+
* IMPORTANT: `rawBody` must be the exact raw request body that Notion sent. Do not use
|
|
39
|
+
* `JSON.stringify(parsedBody)`. Re-serializing a parsed object can produce a different
|
|
40
|
+
* byte sequence (key order, whitespace) than the original signed body, and this
|
|
41
|
+
* silently breaks verification. Use your framework's raw-body access, for example
|
|
42
|
+
* Express's `express.raw()` or `req.rawBody`. Do not use `req.body` after JSON
|
|
43
|
+
* middleware parses it.
|
|
44
44
|
*
|
|
45
45
|
* @param rawBody - The exact raw request body string Notion sent
|
|
46
46
|
* @param signatureHeader - The value of the `X-Notion-Signature` request header
|
|
47
47
|
* @param verificationToken - The webhook subscription's verification token
|
|
48
|
-
* @returns `true` if the signature is valid
|
|
49
|
-
* input
|
|
48
|
+
* @returns `true` if the signature is valid. Returns `false` for a mismatch or
|
|
49
|
+
* malformed input. This function never throws.
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
52
52
|
* ```ts
|
|
@@ -74,6 +74,8 @@ function verifySignature(rawBody, signatureHeader, verificationToken) {
|
|
|
74
74
|
*
|
|
75
75
|
* const isValid = webhook.verifySignature(rawBody, req.headers['x-notion-signature'], verificationToken);
|
|
76
76
|
* ```
|
|
77
|
+
*
|
|
78
|
+
* @category Helpers
|
|
77
79
|
*/
|
|
78
80
|
exports.webhook = {
|
|
79
81
|
sign,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type NotionAsyncTask } from '../schemas';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* AsyncTask model class with helper methods.
|
|
5
5
|
*
|
|
6
|
-
* Represents a long-running operation
|
|
7
|
-
*
|
|
6
|
+
* Represents a long-running operation, for example an async markdown write. Poll the
|
|
7
|
+
* task until it reaches a terminal status.
|
|
8
|
+
*
|
|
9
|
+
* @category Async Tasks
|
|
8
10
|
*/
|
|
9
11
|
export declare class AsyncTask extends BaseModel<NotionAsyncTask> {
|
|
10
|
-
constructor(data: NotionAsyncTask);
|
|
12
|
+
constructor(data: NotionAsyncTask, trusted?: typeof TRUSTED);
|
|
11
13
|
/**
|
|
12
14
|
* Returns "async_task" - the object type.
|
|
13
15
|
*/
|
|
@@ -21,7 +23,7 @@ export declare class AsyncTask extends BaseModel<NotionAsyncTask> {
|
|
|
21
23
|
*/
|
|
22
24
|
get status(): NotionAsyncTask['status'];
|
|
23
25
|
/**
|
|
24
|
-
* Returns the URL
|
|
26
|
+
* Returns the URL to poll for the task status.
|
|
25
27
|
*/
|
|
26
28
|
get statusUrl(): string;
|
|
27
29
|
/**
|
|
@@ -4,14 +4,16 @@ exports.AsyncTask = void 0;
|
|
|
4
4
|
const base_model_1 = require("./base.model");
|
|
5
5
|
const schemas_1 = require("../schemas");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* AsyncTask model class with helper methods.
|
|
8
8
|
*
|
|
9
|
-
* Represents a long-running operation
|
|
10
|
-
*
|
|
9
|
+
* Represents a long-running operation, for example an async markdown write. Poll the
|
|
10
|
+
* task until it reaches a terminal status.
|
|
11
|
+
*
|
|
12
|
+
* @category Async Tasks
|
|
11
13
|
*/
|
|
12
14
|
class AsyncTask extends base_model_1.BaseModel {
|
|
13
|
-
constructor(data) {
|
|
14
|
-
super(data, schemas_1.asyncTaskSchema);
|
|
15
|
+
constructor(data, trusted) {
|
|
16
|
+
super(data, schemas_1.asyncTaskSchema, trusted);
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
19
|
* Returns "async_task" - the object type.
|
|
@@ -32,7 +34,7 @@ class AsyncTask extends base_model_1.BaseModel {
|
|
|
32
34
|
return this.data.status;
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
|
-
* Returns the URL
|
|
37
|
+
* Returns the URL to poll for the task status.
|
|
36
38
|
*/
|
|
37
39
|
get statusUrl() {
|
|
38
40
|
return this.data.status_url;
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import type * as z from 'zod';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Internal marker for trusted, already-validated data.
|
|
4
|
+
*
|
|
5
|
+
* Pass this to a model constructor to skip re-parsing data an API module already
|
|
6
|
+
* validated. This symbol is not exported from the package's public barrel, so
|
|
7
|
+
* external consumers can never construct or forge it. Direct construction from
|
|
8
|
+
* outside the SDK always validates.
|
|
9
|
+
*/
|
|
10
|
+
export declare const TRUSTED: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* Base class for all Notion models.
|
|
13
|
+
*
|
|
14
|
+
* This class wraps validated data from a schema. It adds methods and logic for each model.
|
|
15
|
+
*
|
|
16
|
+
* @category Client & Core
|
|
5
17
|
*/
|
|
6
18
|
export declare abstract class BaseModel<T> {
|
|
7
19
|
protected readonly data: T;
|
|
8
|
-
protected constructor(data: T, schema: z.ZodType<T
|
|
20
|
+
protected constructor(data: T, schema: z.ZodType<T>, trusted?: typeof TRUSTED);
|
|
9
21
|
/**
|
|
10
22
|
* Returns the raw validated data as a plain object.
|
|
11
23
|
*/
|
|
12
24
|
toJSON(): T;
|
|
13
25
|
/**
|
|
14
|
-
* Returns the object type
|
|
26
|
+
* Returns the object type, for example "page", "block", or "user".
|
|
15
27
|
*/
|
|
16
28
|
abstract get object(): string;
|
|
17
29
|
/**
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseModel = void 0;
|
|
3
|
+
exports.BaseModel = exports.TRUSTED = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Internal marker for trusted, already-validated data.
|
|
6
|
+
*
|
|
7
|
+
* Pass this to a model constructor to skip re-parsing data an API module already
|
|
8
|
+
* validated. This symbol is not exported from the package's public barrel, so
|
|
9
|
+
* external consumers can never construct or forge it. Direct construction from
|
|
10
|
+
* outside the SDK always validates.
|
|
11
|
+
*/
|
|
12
|
+
exports.TRUSTED = Symbol('trusted');
|
|
13
|
+
/**
|
|
14
|
+
* Base class for all Notion models.
|
|
15
|
+
*
|
|
16
|
+
* This class wraps validated data from a schema. It adds methods and logic for each model.
|
|
17
|
+
*
|
|
18
|
+
* @category Client & Core
|
|
7
19
|
*/
|
|
8
20
|
class BaseModel {
|
|
9
|
-
constructor(data, schema) {
|
|
10
|
-
this.data = schema.parse(data);
|
|
21
|
+
constructor(data, schema, trusted) {
|
|
22
|
+
this.data = trusted === exports.TRUSTED ? data : schema.parse(data);
|
|
11
23
|
}
|
|
12
24
|
/**
|
|
13
25
|
* Returns the raw validated data as a plain object.
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type NotionBlock } from '../schemas';
|
|
3
3
|
/**
|
|
4
4
|
* Block model wrapping a validated Notion block object with helper methods.
|
|
5
|
+
*
|
|
6
|
+
* @category Blocks
|
|
5
7
|
*/
|
|
6
8
|
export declare class Block extends BaseModel<NotionBlock> {
|
|
7
|
-
|
|
9
|
+
private cachedCreatedTimeMs?;
|
|
10
|
+
private cachedLastEditedTimeMs?;
|
|
11
|
+
constructor(data: unknown, trusted?: typeof TRUSTED);
|
|
8
12
|
get object(): string;
|
|
9
13
|
get id(): string;
|
|
10
14
|
get type(): NotionBlock['type'];
|
|
@@ -3,12 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Block = void 0;
|
|
4
4
|
const base_model_1 = require("./base.model");
|
|
5
5
|
const schemas_1 = require("../schemas");
|
|
6
|
+
const TEXT_BLOCK_TYPES = new Set([
|
|
7
|
+
'paragraph',
|
|
8
|
+
'heading_1',
|
|
9
|
+
'heading_2',
|
|
10
|
+
'heading_3',
|
|
11
|
+
'heading_4',
|
|
12
|
+
'quote',
|
|
13
|
+
'callout',
|
|
14
|
+
'bulleted_list_item',
|
|
15
|
+
'numbered_list_item',
|
|
16
|
+
'to_do',
|
|
17
|
+
'toggle',
|
|
18
|
+
]);
|
|
19
|
+
const HEADING_BLOCK_TYPES = new Set([
|
|
20
|
+
'heading_1',
|
|
21
|
+
'heading_2',
|
|
22
|
+
'heading_3',
|
|
23
|
+
'heading_4',
|
|
24
|
+
]);
|
|
25
|
+
const CHILD_CONTAINER_BLOCK_TYPES = new Set([
|
|
26
|
+
'paragraph',
|
|
27
|
+
'heading_1',
|
|
28
|
+
'heading_2',
|
|
29
|
+
'heading_3',
|
|
30
|
+
'heading_4',
|
|
31
|
+
'bulleted_list_item',
|
|
32
|
+
'numbered_list_item',
|
|
33
|
+
'to_do',
|
|
34
|
+
'toggle',
|
|
35
|
+
'quote',
|
|
36
|
+
'callout',
|
|
37
|
+
'synced_block',
|
|
38
|
+
'column',
|
|
39
|
+
'column_list',
|
|
40
|
+
'tab',
|
|
41
|
+
'table',
|
|
42
|
+
]);
|
|
6
43
|
/**
|
|
7
44
|
* Block model wrapping a validated Notion block object with helper methods.
|
|
45
|
+
*
|
|
46
|
+
* @category Blocks
|
|
8
47
|
*/
|
|
9
48
|
class Block extends base_model_1.BaseModel {
|
|
10
|
-
constructor(data) {
|
|
11
|
-
super(data, schemas_1.blockSchema);
|
|
49
|
+
constructor(data, trusted) {
|
|
50
|
+
super(data, schemas_1.blockSchema, trusted);
|
|
12
51
|
}
|
|
13
52
|
get object() {
|
|
14
53
|
return this.data.object;
|
|
@@ -20,10 +59,12 @@ class Block extends base_model_1.BaseModel {
|
|
|
20
59
|
return this.data.type;
|
|
21
60
|
}
|
|
22
61
|
get createdTime() {
|
|
23
|
-
|
|
62
|
+
this.cachedCreatedTimeMs ??= new Date(this.data.created_time).getTime();
|
|
63
|
+
return new Date(this.cachedCreatedTimeMs);
|
|
24
64
|
}
|
|
25
65
|
get lastEditedTime() {
|
|
26
|
-
|
|
66
|
+
this.cachedLastEditedTimeMs ??= new Date(this.data.last_edited_time).getTime();
|
|
67
|
+
return new Date(this.cachedLastEditedTimeMs);
|
|
27
68
|
}
|
|
28
69
|
get inTrash() {
|
|
29
70
|
return this.data.in_trash;
|
|
@@ -35,48 +76,19 @@ class Block extends base_model_1.BaseModel {
|
|
|
35
76
|
* Check if this is a text-based block type.
|
|
36
77
|
*/
|
|
37
78
|
isTextBlock() {
|
|
38
|
-
return
|
|
39
|
-
'paragraph',
|
|
40
|
-
'heading_1',
|
|
41
|
-
'heading_2',
|
|
42
|
-
'heading_3',
|
|
43
|
-
'heading_4',
|
|
44
|
-
'quote',
|
|
45
|
-
'callout',
|
|
46
|
-
'bulleted_list_item',
|
|
47
|
-
'numbered_list_item',
|
|
48
|
-
'to_do',
|
|
49
|
-
'toggle',
|
|
50
|
-
].includes(this.data.type);
|
|
79
|
+
return TEXT_BLOCK_TYPES.has(this.data.type);
|
|
51
80
|
}
|
|
52
81
|
/**
|
|
53
82
|
* Check if this is a heading block.
|
|
54
83
|
*/
|
|
55
84
|
isHeading() {
|
|
56
|
-
return
|
|
85
|
+
return HEADING_BLOCK_TYPES.has(this.data.type);
|
|
57
86
|
}
|
|
58
87
|
/**
|
|
59
88
|
* Check if this block can contain children.
|
|
60
89
|
*/
|
|
61
90
|
canHaveChildren() {
|
|
62
|
-
return
|
|
63
|
-
'paragraph',
|
|
64
|
-
'heading_1',
|
|
65
|
-
'heading_2',
|
|
66
|
-
'heading_3',
|
|
67
|
-
'heading_4',
|
|
68
|
-
'bulleted_list_item',
|
|
69
|
-
'numbered_list_item',
|
|
70
|
-
'to_do',
|
|
71
|
-
'toggle',
|
|
72
|
-
'quote',
|
|
73
|
-
'callout',
|
|
74
|
-
'synced_block',
|
|
75
|
-
'column',
|
|
76
|
-
'column_list',
|
|
77
|
-
'tab',
|
|
78
|
-
'table',
|
|
79
|
-
].includes(this.data.type);
|
|
91
|
+
return CHILD_CONTAINER_BLOCK_TYPES.has(this.data.type);
|
|
80
92
|
}
|
|
81
93
|
/**
|
|
82
94
|
* Get the plain text content from text-based blocks.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type CommentAttachment, type CommentDisplayName, type NotionComment, type NotionParent, type NotionRichText, type NotionUser } from '../schemas';
|
|
3
3
|
/**
|
|
4
4
|
* Comment model class with helper methods.
|
|
5
|
+
*
|
|
6
|
+
* @category Comments
|
|
5
7
|
*/
|
|
6
8
|
export declare class Comment extends BaseModel<NotionComment> {
|
|
7
|
-
constructor(data: NotionComment);
|
|
9
|
+
constructor(data: NotionComment, trusted?: typeof TRUSTED);
|
|
8
10
|
/**
|
|
9
11
|
* Returns "comment" - the object type.
|
|
10
12
|
*/
|
|
@@ -5,10 +5,12 @@ const base_model_1 = require("./base.model");
|
|
|
5
5
|
const schemas_1 = require("../schemas");
|
|
6
6
|
/**
|
|
7
7
|
* Comment model class with helper methods.
|
|
8
|
+
*
|
|
9
|
+
* @category Comments
|
|
8
10
|
*/
|
|
9
11
|
class Comment extends base_model_1.BaseModel {
|
|
10
|
-
constructor(data) {
|
|
11
|
-
super(data, schemas_1.commentSchema);
|
|
12
|
+
constructor(data, trusted) {
|
|
13
|
+
super(data, schemas_1.commentSchema, trusted);
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* Returns "comment" - the object type.
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type NotionCustomEmoji } from '../schemas';
|
|
3
3
|
/**
|
|
4
4
|
* Custom Emoji model class with helper methods.
|
|
5
|
+
*
|
|
6
|
+
* @category Custom Emoji & Icons
|
|
5
7
|
*/
|
|
6
8
|
export declare class CustomEmoji extends BaseModel<NotionCustomEmoji> {
|
|
7
|
-
constructor(data: NotionCustomEmoji);
|
|
9
|
+
constructor(data: NotionCustomEmoji, trusted?: typeof TRUSTED);
|
|
8
10
|
/**
|
|
9
11
|
* Returns "custom_emoji" - the object type.
|
|
10
12
|
*
|
|
11
|
-
* Note:
|
|
12
|
-
* the
|
|
13
|
-
*
|
|
13
|
+
* Note: A custom emoji list item has no `object` field in the API response. Only
|
|
14
|
+
* the paginated list wrapper has that field. This getter returns a synthetic
|
|
15
|
+
* value, not data from the payload, to meet the {@link BaseModel} contract.
|
|
14
16
|
*/
|
|
15
17
|
get object(): 'custom_emoji';
|
|
16
18
|
/**
|
|
@@ -5,17 +5,19 @@ const base_model_1 = require("./base.model");
|
|
|
5
5
|
const schemas_1 = require("../schemas");
|
|
6
6
|
/**
|
|
7
7
|
* Custom Emoji model class with helper methods.
|
|
8
|
+
*
|
|
9
|
+
* @category Custom Emoji & Icons
|
|
8
10
|
*/
|
|
9
11
|
class CustomEmoji extends base_model_1.BaseModel {
|
|
10
|
-
constructor(data) {
|
|
11
|
-
super(data, schemas_1.customEmojiSchema);
|
|
12
|
+
constructor(data, trusted) {
|
|
13
|
+
super(data, schemas_1.customEmojiSchema, trusted);
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* Returns "custom_emoji" - the object type.
|
|
15
17
|
*
|
|
16
|
-
* Note:
|
|
17
|
-
* the
|
|
18
|
-
*
|
|
18
|
+
* Note: A custom emoji list item has no `object` field in the API response. Only
|
|
19
|
+
* the paginated list wrapper has that field. This getter returns a synthetic
|
|
20
|
+
* value, not data from the payload, to meet the {@link BaseModel} contract.
|
|
19
21
|
*/
|
|
20
22
|
get object() {
|
|
21
23
|
return 'custom_emoji';
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type NotionDataSource, type NotionFile, type NotionIcon, type NotionParent, type NotionPropertiesObject, type NotionPropertyObject, type NotionRichText, type NotionUser } from '../schemas';
|
|
3
3
|
/**
|
|
4
4
|
* Data Source model class with helper methods.
|
|
5
5
|
*
|
|
6
6
|
* Data sources are individual tables of data that live under a Notion database.
|
|
7
|
+
*
|
|
8
|
+
* @category Databases & Data Sources
|
|
7
9
|
*/
|
|
8
10
|
export declare class DataSource extends BaseModel<NotionDataSource> {
|
|
9
|
-
constructor(data: NotionDataSource);
|
|
11
|
+
constructor(data: NotionDataSource, trusted?: typeof TRUSTED);
|
|
10
12
|
/**
|
|
11
13
|
* Returns "data_source" - the object type.
|
|
12
14
|
*/
|
|
@@ -7,10 +7,12 @@ const schemas_1 = require("../schemas");
|
|
|
7
7
|
* Data Source model class with helper methods.
|
|
8
8
|
*
|
|
9
9
|
* Data sources are individual tables of data that live under a Notion database.
|
|
10
|
+
*
|
|
11
|
+
* @category Databases & Data Sources
|
|
10
12
|
*/
|
|
11
13
|
class DataSource extends base_model_1.BaseModel {
|
|
12
|
-
constructor(data) {
|
|
13
|
-
super(data, schemas_1.dataSourceSchema);
|
|
14
|
+
constructor(data, trusted) {
|
|
15
|
+
super(data, schemas_1.dataSourceSchema, trusted);
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Returns "data_source" - the object type.
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type DataSourceRef, type NotionDatabase, type NotionFile, type NotionIcon, type NotionParent, type NotionRichText, type NotionUser } from '../schemas';
|
|
3
3
|
/**
|
|
4
4
|
* Database model class with helper methods.
|
|
5
|
+
*
|
|
6
|
+
* @category Databases & Data Sources
|
|
5
7
|
*/
|
|
6
8
|
export declare class Database extends BaseModel<NotionDatabase> {
|
|
7
|
-
|
|
9
|
+
private cachedCreatedTimeMs?;
|
|
10
|
+
private cachedLastEditedTimeMs?;
|
|
11
|
+
constructor(data: NotionDatabase, trusted?: typeof TRUSTED);
|
|
8
12
|
/**
|
|
9
13
|
* Returns "database" - the object type.
|
|
10
14
|
*/
|
|
@@ -5,10 +5,12 @@ const base_model_1 = require("./base.model");
|
|
|
5
5
|
const schemas_1 = require("../schemas");
|
|
6
6
|
/**
|
|
7
7
|
* Database model class with helper methods.
|
|
8
|
+
*
|
|
9
|
+
* @category Databases & Data Sources
|
|
8
10
|
*/
|
|
9
11
|
class Database extends base_model_1.BaseModel {
|
|
10
|
-
constructor(data) {
|
|
11
|
-
super(data, schemas_1.databaseSchema);
|
|
12
|
+
constructor(data, trusted) {
|
|
13
|
+
super(data, schemas_1.databaseSchema, trusted);
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* Returns "database" - the object type.
|
|
@@ -32,7 +34,8 @@ class Database extends base_model_1.BaseModel {
|
|
|
32
34
|
* Returns the created time as a Date object.
|
|
33
35
|
*/
|
|
34
36
|
get createdTime() {
|
|
35
|
-
|
|
37
|
+
this.cachedCreatedTimeMs ??= new Date(this.data.created_time).getTime();
|
|
38
|
+
return new Date(this.cachedCreatedTimeMs);
|
|
36
39
|
}
|
|
37
40
|
/**
|
|
38
41
|
* Returns the user who created the database.
|
|
@@ -44,7 +47,8 @@ class Database extends base_model_1.BaseModel {
|
|
|
44
47
|
* Returns the last edited time as a Date object.
|
|
45
48
|
*/
|
|
46
49
|
get lastEditedTime() {
|
|
47
|
-
|
|
50
|
+
this.cachedLastEditedTimeMs ??= new Date(this.data.last_edited_time).getTime();
|
|
51
|
+
return new Date(this.cachedLastEditedTimeMs);
|
|
48
52
|
}
|
|
49
53
|
/**
|
|
50
54
|
* Returns the user who last edited the database.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type NotionFileUpload } from '../schemas';
|
|
3
3
|
/**
|
|
4
4
|
* FileUpload model class with helper methods.
|
|
5
|
+
*
|
|
6
|
+
* @category File Uploads
|
|
5
7
|
*/
|
|
6
8
|
export declare class FileUpload extends BaseModel<NotionFileUpload> {
|
|
7
|
-
constructor(data: NotionFileUpload);
|
|
9
|
+
constructor(data: NotionFileUpload, trusted?: typeof TRUSTED);
|
|
8
10
|
/**
|
|
9
11
|
* Returns "file_upload" - the object type.
|
|
10
12
|
*/
|
|
@@ -38,11 +40,11 @@ export declare class FileUpload extends BaseModel<NotionFileUpload> {
|
|
|
38
40
|
*/
|
|
39
41
|
get contentLength(): number | null;
|
|
40
42
|
/**
|
|
41
|
-
* Returns the
|
|
43
|
+
* Returns the URL to upload the file.
|
|
42
44
|
*/
|
|
43
45
|
get uploadUrl(): string;
|
|
44
46
|
/**
|
|
45
|
-
* Returns the
|
|
47
|
+
* Returns the URL to complete the upload.
|
|
46
48
|
*/
|
|
47
49
|
get completeUrl(): string;
|
|
48
50
|
/**
|
|
@@ -5,10 +5,12 @@ const base_model_1 = require("./base.model");
|
|
|
5
5
|
const schemas_1 = require("../schemas");
|
|
6
6
|
/**
|
|
7
7
|
* FileUpload model class with helper methods.
|
|
8
|
+
*
|
|
9
|
+
* @category File Uploads
|
|
8
10
|
*/
|
|
9
11
|
class FileUpload extends base_model_1.BaseModel {
|
|
10
|
-
constructor(data) {
|
|
11
|
-
super(data, schemas_1.fileUploadSchema);
|
|
12
|
+
constructor(data, trusted) {
|
|
13
|
+
super(data, schemas_1.fileUploadSchema, trusted);
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* Returns "file_upload" - the object type.
|
|
@@ -59,13 +61,13 @@ class FileUpload extends base_model_1.BaseModel {
|
|
|
59
61
|
return this.data.content_length;
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
|
-
* Returns the
|
|
64
|
+
* Returns the URL to upload the file.
|
|
63
65
|
*/
|
|
64
66
|
get uploadUrl() {
|
|
65
67
|
return this.data.upload_url;
|
|
66
68
|
}
|
|
67
69
|
/**
|
|
68
|
-
* Returns the
|
|
70
|
+
* Returns the URL to complete the upload.
|
|
69
71
|
*/
|
|
70
72
|
get completeUrl() {
|
|
71
73
|
return this.data.complete_url;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { BaseModel } from './base.model';
|
|
1
|
+
import { BaseModel, type TRUSTED } from './base.model';
|
|
2
2
|
import { type NotionPage, type NotionPageProperties } from '../schemas';
|
|
3
3
|
/**
|
|
4
4
|
* Page model wrapping a validated Notion page object with helper methods.
|
|
5
|
+
*
|
|
6
|
+
* @category Pages
|
|
5
7
|
*/
|
|
6
8
|
export declare class Page extends BaseModel<NotionPage> {
|
|
7
|
-
|
|
9
|
+
private cachedCreatedTimeMs?;
|
|
10
|
+
private cachedLastEditedTimeMs?;
|
|
11
|
+
constructor(data: unknown, trusted?: typeof TRUSTED);
|
|
8
12
|
get object(): string;
|
|
9
13
|
get id(): string;
|
|
10
14
|
get createdTime(): Date;
|