@visus-io/notion-sdk-ts 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +25 -9
  2. package/dist/api/base.api.d.ts +1 -1
  3. package/dist/api/blocks.api.d.ts +260 -80
  4. package/dist/api/comments.api.d.ts +7 -7
  5. package/dist/api/dataSources.api.d.ts +12 -12
  6. package/dist/api/databases.api.d.ts +12 -12
  7. package/dist/api/fileUploads.api.d.ts +2 -2
  8. package/dist/api/pages.api.d.ts +29 -29
  9. package/dist/api/users.api.d.ts +1 -1
  10. package/dist/helpers/block.helpers.d.ts +4 -0
  11. package/dist/helpers/block.helpers.js +11 -0
  12. package/dist/models/base.model.d.ts +2 -2
  13. package/dist/schemas/block.schema.d.ts +261 -81
  14. package/dist/schemas/block.schema.js +157 -81
  15. package/dist/schemas/comment.schema.d.ts +9 -9
  16. package/dist/schemas/comment.schema.js +54 -20
  17. package/dist/schemas/dataSource.schema.d.ts +13 -13
  18. package/dist/schemas/dataSource.schema.js +46 -12
  19. package/dist/schemas/database.schema.d.ts +13 -13
  20. package/dist/schemas/database.schema.js +51 -17
  21. package/dist/schemas/emoji.schema.d.ts +1 -1
  22. package/dist/schemas/emoji.schema.js +37 -4
  23. package/dist/schemas/file.schema.d.ts +3 -3
  24. package/dist/schemas/file.schema.js +49 -15
  25. package/dist/schemas/fileUpload.schema.d.ts +3 -3
  26. package/dist/schemas/fileUpload.schema.js +47 -13
  27. package/dist/schemas/index.d.ts +1 -0
  28. package/dist/schemas/index.js +1 -0
  29. package/dist/schemas/page.schema.d.ts +30 -30
  30. package/dist/schemas/page.schema.js +47 -13
  31. package/dist/schemas/pageProperties.schema.d.ts +47 -47
  32. package/dist/schemas/pageProperties.schema.js +162 -128
  33. package/dist/schemas/pagination.schema.d.ts +1 -1
  34. package/dist/schemas/pagination.schema.js +40 -7
  35. package/dist/schemas/parent.schema.d.ts +1 -1
  36. package/dist/schemas/parent.schema.js +51 -18
  37. package/dist/schemas/propertyObjects.schema.d.ts +1 -1
  38. package/dist/schemas/propertyObjects.schema.js +194 -161
  39. package/dist/schemas/richText.schema.d.ts +7 -7
  40. package/dist/schemas/richText.schema.js +95 -56
  41. package/dist/schemas/shared.schema.d.ts +15 -0
  42. package/dist/schemas/shared.schema.js +54 -0
  43. package/dist/schemas/user.schema.d.ts +3 -3
  44. package/dist/schemas/user.schema.js +63 -30
  45. package/package.json +3 -1
@@ -1,8 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.richTextSchema = void 0;
4
- const zod_1 = require("zod");
37
+ const z = __importStar(require("zod"));
5
38
  const colors_1 = require("./colors");
39
+ const shared_schema_1 = require("./shared.schema");
6
40
  const user_schema_1 = require("./user.schema");
7
41
  /**
8
42
  * Notion rich text object schema.
@@ -15,66 +49,67 @@ const user_schema_1 = require("./user.schema");
15
49
  * https://developers.notion.com/reference/rich-text
16
50
  */
17
51
  /** Annotations for rich text. */
18
- const annotationsSchema = zod_1.z.object({
19
- bold: zod_1.z.boolean(),
20
- italic: zod_1.z.boolean(),
21
- strikethrough: zod_1.z.boolean(),
22
- underline: zod_1.z.boolean(),
23
- code: zod_1.z.boolean(),
24
- color: zod_1.z.enum(colors_1.NOTION_COLORS),
52
+ const annotationsSchema = z.object({
53
+ bold: z.boolean(),
54
+ italic: z.boolean(),
55
+ strikethrough: z.boolean(),
56
+ underline: z.boolean(),
57
+ code: z.boolean(),
58
+ color: z.enum(colors_1.NOTION_COLORS),
25
59
  });
26
60
  /** Text content with optional link. */
27
- const textContentSchema = zod_1.z.object({
28
- content: zod_1.z.string(),
29
- link: zod_1.z.object({ url: zod_1.z.url() }).nullable(),
61
+ const textContentSchema = z.object({
62
+ // eslint-disable-next-line zod/prefer-string-schema-with-trim -- content must preserve whitespace from Notion API
63
+ content: z.string(),
64
+ link: z.object({ url: z.url() }).nullable(),
30
65
  });
31
66
  /** Mention types. */
32
- const databaseMentionSchema = zod_1.z.object({
33
- type: zod_1.z.literal('database'),
34
- database: zod_1.z.object({
35
- id: zod_1.z.uuid(),
67
+ const databaseMentionSchema = z.object({
68
+ type: z.literal('database'),
69
+ database: z.object({
70
+ id: z.uuid(),
36
71
  }),
37
72
  });
38
- const dateMentionSchema = zod_1.z.object({
39
- type: zod_1.z.literal('date'),
40
- date: zod_1.z.object({
41
- start: zod_1.z.string(),
42
- end: zod_1.z.string().nullable(),
43
- time_zone: zod_1.z.string().nullable().optional(),
73
+ const dateMentionSchema = z.object({
74
+ type: z.literal('date'),
75
+ date: z.object({
76
+ start: shared_schema_1.notionDateStringSchema,
77
+ end: shared_schema_1.notionDateStringSchema.nullable(),
78
+ time_zone: z.string().trim().nullable().optional(),
44
79
  }),
45
80
  });
46
- const linkPreviewMentionSchema = zod_1.z.object({
47
- type: zod_1.z.literal('link_preview'),
48
- link_preview: zod_1.z.object({
49
- url: zod_1.z.url(),
81
+ const linkPreviewMentionSchema = z.object({
82
+ type: z.literal('link_preview'),
83
+ link_preview: z.object({
84
+ url: z.url(),
50
85
  }),
51
86
  });
52
- const pageMentionSchema = zod_1.z.object({
53
- type: zod_1.z.literal('page'),
54
- page: zod_1.z.object({
55
- id: zod_1.z.uuid(),
87
+ const pageMentionSchema = z.object({
88
+ type: z.literal('page'),
89
+ page: z.object({
90
+ id: z.uuid(),
56
91
  }),
57
92
  });
58
- const templateMentionDateSchema = zod_1.z.object({
59
- type: zod_1.z.literal('template_mention_date'),
60
- template_mention_date: zod_1.z.enum(['today', 'now']),
93
+ const templateMentionDateSchema = z.object({
94
+ type: z.literal('template_mention_date'),
95
+ template_mention_date: z.enum(['today', 'now']),
61
96
  });
62
- const templateMentionUserSchema = zod_1.z.object({
63
- type: zod_1.z.literal('template_mention_user'),
64
- template_mention_user: zod_1.z.literal('me'),
97
+ const templateMentionUserSchema = z.object({
98
+ type: z.literal('template_mention_user'),
99
+ template_mention_user: z.literal('me'),
65
100
  });
66
- const templateMentionSchema = zod_1.z.object({
67
- type: zod_1.z.literal('template_mention'),
68
- template_mention: zod_1.z.discriminatedUnion('type', [
101
+ const templateMentionSchema = z.object({
102
+ type: z.literal('template_mention'),
103
+ template_mention: z.discriminatedUnion('type', [
69
104
  templateMentionDateSchema,
70
105
  templateMentionUserSchema,
71
106
  ]),
72
107
  });
73
- const userMentionSchema = zod_1.z.object({
74
- type: zod_1.z.literal('user'),
108
+ const userMentionSchema = z.object({
109
+ type: z.literal('user'),
75
110
  user: user_schema_1.userSchema,
76
111
  });
77
- const mentionSchema = zod_1.z.discriminatedUnion('type', [
112
+ const mentionSchema = z.discriminatedUnion('type', [
78
113
  databaseMentionSchema,
79
114
  dateMentionSchema,
80
115
  linkPreviewMentionSchema,
@@ -83,29 +118,33 @@ const mentionSchema = zod_1.z.discriminatedUnion('type', [
83
118
  userMentionSchema,
84
119
  ]);
85
120
  /** Text rich text type. */
86
- const textRichTextSchema = zod_1.z.object({
87
- type: zod_1.z.literal('text'),
121
+ const textRichTextSchema = z.object({
122
+ type: z.literal('text'),
88
123
  text: textContentSchema,
89
124
  annotations: annotationsSchema,
90
- plain_text: zod_1.z.string(),
91
- href: zod_1.z.url().nullable(),
125
+ // eslint-disable-next-line zod/prefer-string-schema-with-trim -- plain_text must preserve whitespace from Notion API
126
+ plain_text: z.string(),
127
+ href: z.url().nullable(),
92
128
  });
93
129
  /** Mention rich text type. */
94
- const mentionRichTextSchema = zod_1.z.object({
95
- type: zod_1.z.literal('mention'),
130
+ const mentionRichTextSchema = z.object({
131
+ type: z.literal('mention'),
96
132
  mention: mentionSchema,
97
133
  annotations: annotationsSchema,
98
- plain_text: zod_1.z.string(),
99
- href: zod_1.z.url().nullable(),
134
+ // eslint-disable-next-line zod/prefer-string-schema-with-trim -- plain_text must preserve whitespace from Notion API
135
+ plain_text: z.string(),
136
+ href: z.url().nullable(),
100
137
  });
101
138
  /** Equation rich text type. */
102
- const equationRichTextSchema = zod_1.z.object({
103
- type: zod_1.z.literal('equation'),
104
- equation: zod_1.z.object({
105
- expression: zod_1.z.string(),
139
+ const equationRichTextSchema = z.object({
140
+ type: z.literal('equation'),
141
+ equation: z.object({
142
+ // eslint-disable-next-line zod/prefer-string-schema-with-trim -- LaTeX expression must preserve whitespace from Notion API
143
+ expression: z.string(),
106
144
  }),
107
145
  annotations: annotationsSchema,
108
- plain_text: zod_1.z.string(),
109
- href: zod_1.z.url().nullable(),
146
+ // eslint-disable-next-line zod/prefer-string-schema-with-trim -- plain_text must preserve whitespace from Notion API
147
+ plain_text: z.string(),
148
+ href: z.url().nullable(),
110
149
  });
111
- exports.richTextSchema = zod_1.z.array(zod_1.z.discriminatedUnion('type', [textRichTextSchema, mentionRichTextSchema, equationRichTextSchema]));
150
+ exports.richTextSchema = z.array(z.discriminatedUnion('type', [textRichTextSchema, mentionRichTextSchema, equationRichTextSchema]));
@@ -0,0 +1,15 @@
1
+ import * as z from 'zod';
2
+ /**
3
+ * Shared schema definitions used across multiple schema files.
4
+ *
5
+ * This file contains common schemas to avoid circular dependencies.
6
+ */
7
+ /**
8
+ * Notion date string schema.
9
+ *
10
+ * Validates ISO 8601 date strings as returned by the Notion API.
11
+ * Accepts both date-only format ("2023-02-23") and full datetime format ("2023-02-23T00:00:00.000Z").
12
+ *
13
+ * According to Notion API docs, date fields contain "A date, with an optional time".
14
+ */
15
+ export declare const notionDateStringSchema: z.ZodUnion<readonly [z.ZodISODateTime, z.ZodISODate]>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.notionDateStringSchema = void 0;
37
+ const z = __importStar(require("zod"));
38
+ /**
39
+ * Shared schema definitions used across multiple schema files.
40
+ *
41
+ * This file contains common schemas to avoid circular dependencies.
42
+ */
43
+ /**
44
+ * Notion date string schema.
45
+ *
46
+ * Validates ISO 8601 date strings as returned by the Notion API.
47
+ * Accepts both date-only format ("2023-02-23") and full datetime format ("2023-02-23T00:00:00.000Z").
48
+ *
49
+ * According to Notion API docs, date fields contain "A date, with an optional time".
50
+ */
51
+ exports.notionDateStringSchema = z.union([
52
+ z.iso.datetime(), // Full ISO 8601 datetime: "2023-02-23T00:00:00.000Z"
53
+ z.iso.date(), // Date only: "2023-02-23"
54
+ ]);
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import * as z from 'zod';
2
2
  /** Person user with email. */
3
3
  declare const personUserSchema: z.ZodObject<{
4
4
  object: z.ZodLiteral<"user">;
@@ -27,7 +27,7 @@ declare const botUserSchema: z.ZodObject<{
27
27
  workspace_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
28
28
  workspace_id: z.ZodOptional<z.ZodString>;
29
29
  workspace_limits: z.ZodOptional<z.ZodObject<{
30
- max_file_upload_size_in_bytes: z.ZodNumber;
30
+ max_file_upload_size_in_bytes: z.ZodInt;
31
31
  }, z.core.$strip>>;
32
32
  }, z.core.$strip>;
33
33
  }, z.core.$strip>;
@@ -61,7 +61,7 @@ export declare const userSchema: z.ZodUnion<readonly [z.ZodObject<{
61
61
  workspace_name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
62
  workspace_id: z.ZodOptional<z.ZodString>;
63
63
  workspace_limits: z.ZodOptional<z.ZodObject<{
64
- max_file_upload_size_in_bytes: z.ZodNumber;
64
+ max_file_upload_size_in_bytes: z.ZodInt;
65
65
  }, z.core.$strip>>;
66
66
  }, z.core.$strip>;
67
67
  }, z.core.$strip>, z.ZodObject<{
@@ -1,7 +1,40 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.userSchema = void 0;
4
- const zod_1 = require("zod");
37
+ const z = __importStar(require("zod"));
5
38
  /**
6
39
  * Notion user object schemas.
7
40
  *
@@ -12,47 +45,47 @@ const zod_1 = require("zod");
12
45
  * https://developers.notion.com/reference/user
13
46
  */
14
47
  /** Bot owner information. */
15
- const botOwnerSchema = zod_1.z.discriminatedUnion('type', [
16
- zod_1.z.object({
17
- type: zod_1.z.literal('workspace'),
18
- workspace: zod_1.z.literal(true),
48
+ const botOwnerSchema = z.discriminatedUnion('type', [
49
+ z.object({
50
+ type: z.literal('workspace'),
51
+ workspace: z.literal(true),
19
52
  }),
20
- zod_1.z.object({
21
- type: zod_1.z.literal('user'),
53
+ z.object({
54
+ type: z.literal('user'),
22
55
  }),
23
56
  ]);
24
57
  /** Person user with email. */
25
- const personUserSchema = zod_1.z.object({
26
- object: zod_1.z.literal('user'),
27
- id: zod_1.z.uuid(),
28
- type: zod_1.z.literal('person'),
29
- name: zod_1.z.string().optional(),
30
- avatar_url: zod_1.z.union([zod_1.z.url(), zod_1.z.null()]).optional(),
31
- person: zod_1.z.object({
32
- email: zod_1.z.email(),
58
+ const personUserSchema = z.object({
59
+ object: z.literal('user'),
60
+ id: z.uuid(),
61
+ type: z.literal('person'),
62
+ name: z.string().trim().optional(),
63
+ avatar_url: z.union([z.url(), z.null()]).optional(),
64
+ person: z.object({
65
+ email: z.email(),
33
66
  }),
34
67
  });
35
68
  /** Bot user with owner and workspace information. */
36
- const botUserSchema = zod_1.z.object({
37
- object: zod_1.z.literal('user'),
38
- id: zod_1.z.uuid(),
39
- type: zod_1.z.literal('bot'),
40
- name: zod_1.z.string().optional(),
41
- avatar_url: zod_1.z.union([zod_1.z.url(), zod_1.z.null()]).optional(),
42
- bot: zod_1.z.object({
69
+ const botUserSchema = z.object({
70
+ object: z.literal('user'),
71
+ id: z.uuid(),
72
+ type: z.literal('bot'),
73
+ name: z.string().trim().optional(),
74
+ avatar_url: z.union([z.url(), z.null()]).optional(),
75
+ bot: z.object({
43
76
  owner: botOwnerSchema,
44
- workspace_name: zod_1.z.string().nullable().optional(),
45
- workspace_id: zod_1.z.string().optional(),
46
- workspace_limits: zod_1.z
77
+ workspace_name: z.string().trim().nullable().optional(),
78
+ workspace_id: z.string().trim().optional(),
79
+ workspace_limits: z
47
80
  .object({
48
- max_file_upload_size_in_bytes: zod_1.z.number().int(),
81
+ max_file_upload_size_in_bytes: z.int(),
49
82
  })
50
83
  .optional(),
51
84
  }),
52
85
  });
53
86
  /** Partial user (only object and id, used in created_by/last_edited_by). */
54
- const partialUserSchema = zod_1.z.object({
55
- object: zod_1.z.literal('user'),
56
- id: zod_1.z.uuid(),
87
+ const partialUserSchema = z.object({
88
+ object: z.literal('user'),
89
+ id: z.uuid(),
57
90
  });
58
- exports.userSchema = zod_1.z.union([personUserSchema, botUserSchema, partialUserSchema]);
91
+ exports.userSchema = z.union([personUserSchema, botUserSchema, partialUserSchema]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visus-io/notion-sdk-ts",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "private": false,
5
5
  "description": "TypeScript SDK for the Notion API",
6
6
  "keywords": [
@@ -68,6 +68,7 @@
68
68
  "@types/node": "^25.2.1",
69
69
  "@vitest/coverage-v8": "^4.0.18",
70
70
  "eslint": "^9.39.2",
71
+ "eslint-plugin-zod": "3.4.0",
71
72
  "husky": "^9.1.7",
72
73
  "lint-staged": "^16.2.7",
73
74
  "prettier": "^3.8.1",
@@ -77,6 +78,7 @@
77
78
  "vitest": "^4.0.18"
78
79
  },
79
80
  "engines": {
81
+ "bun": ">=1.3.10",
80
82
  "node": ">=18.0.0"
81
83
  }
82
84
  }