@visus-io/notion-sdk-ts 3.0.2 → 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.
Files changed (130) hide show
  1. package/README.md +20 -87
  2. package/dist/api/asyncTasks.api.d.ts +72 -0
  3. package/dist/api/asyncTasks.api.js +70 -0
  4. package/dist/api/base.api.d.ts +15 -4
  5. package/dist/api/base.api.js +20 -8
  6. package/dist/api/blocks.api.d.ts +435 -73
  7. package/dist/api/blocks.api.js +43 -1
  8. package/dist/api/comments.api.d.ts +42 -5
  9. package/dist/api/comments.api.js +45 -1
  10. package/dist/api/customEmojis.api.d.ts +38 -0
  11. package/dist/api/customEmojis.api.js +38 -0
  12. package/dist/api/dataSources.api.d.ts +67 -14
  13. package/dist/api/dataSources.api.js +26 -1
  14. package/dist/api/databases.api.d.ts +47 -11
  15. package/dist/api/databases.api.js +4 -1
  16. package/dist/api/fileUploads.api.d.ts +8 -5
  17. package/dist/api/fileUploads.api.js +11 -7
  18. package/dist/api/index.d.ts +3 -0
  19. package/dist/api/index.js +7 -1
  20. package/dist/api/pages.api.d.ts +144 -10
  21. package/dist/api/pages.api.js +66 -0
  22. package/dist/api/search.api.d.ts +12 -2
  23. package/dist/api/search.api.js +5 -2
  24. package/dist/api/users.api.d.ts +3 -0
  25. package/dist/api/users.api.js +2 -0
  26. package/dist/api/views.api.d.ts +286 -0
  27. package/dist/api/views.api.js +172 -0
  28. package/dist/client.d.ts +17 -17
  29. package/dist/client.js +25 -30
  30. package/dist/errors.d.ts +19 -5
  31. package/dist/errors.js +16 -4
  32. package/dist/helpers/block.helpers.d.ts +49 -5
  33. package/dist/helpers/block.helpers.js +50 -6
  34. package/dist/helpers/file.helpers.d.ts +46 -5
  35. package/dist/helpers/file.helpers.js +36 -8
  36. package/dist/helpers/filter.helpers.d.ts +8 -6
  37. package/dist/helpers/filter.helpers.js +2 -0
  38. package/dist/helpers/index.d.ts +3 -2
  39. package/dist/helpers/index.js +5 -1
  40. package/dist/helpers/pagination.helpers.d.ts +85 -13
  41. package/dist/helpers/pagination.helpers.js +114 -8
  42. package/dist/helpers/parent.helpers.d.ts +5 -3
  43. package/dist/helpers/parent.helpers.js +5 -3
  44. package/dist/helpers/property.helpers.d.ts +31 -0
  45. package/dist/helpers/property.helpers.js +30 -1
  46. package/dist/helpers/richText.helpers.d.ts +10 -5
  47. package/dist/helpers/richText.helpers.js +11 -6
  48. package/dist/helpers/sort.helpers.d.ts +2 -0
  49. package/dist/helpers/sort.helpers.js +2 -0
  50. package/dist/helpers/webhook.helpers.d.ts +54 -0
  51. package/dist/helpers/webhook.helpers.js +83 -0
  52. package/dist/models/asyncTask.model.d.ts +61 -0
  53. package/dist/models/asyncTask.model.js +91 -0
  54. package/dist/models/base.model.d.ts +16 -4
  55. package/dist/models/base.model.js +17 -5
  56. package/dist/models/block.model.d.ts +6 -2
  57. package/dist/models/block.model.js +48 -33
  58. package/dist/models/comment.model.d.ts +4 -2
  59. package/dist/models/comment.model.js +4 -2
  60. package/dist/models/customEmoji.model.d.ts +30 -0
  61. package/dist/models/customEmoji.model.js +44 -0
  62. package/dist/models/dataSource.model.d.ts +7 -5
  63. package/dist/models/dataSource.model.js +5 -3
  64. package/dist/models/database.model.d.ts +13 -5
  65. package/dist/models/database.model.js +15 -5
  66. package/dist/models/fileUpload.model.d.ts +6 -4
  67. package/dist/models/fileUpload.model.js +6 -4
  68. package/dist/models/index.d.ts +3 -0
  69. package/dist/models/index.js +7 -1
  70. package/dist/models/page.model.d.ts +8 -2
  71. package/dist/models/page.model.js +14 -4
  72. package/dist/models/richText.model.d.ts +3 -1
  73. package/dist/models/richText.model.js +3 -1
  74. package/dist/models/user.model.d.ts +4 -2
  75. package/dist/models/user.model.js +4 -2
  76. package/dist/models/view.model.d.ts +81 -0
  77. package/dist/models/view.model.js +121 -0
  78. package/dist/notion.d.ts +32 -8
  79. package/dist/notion.js +25 -4
  80. package/dist/schemas/asyncTask.schema.d.ts +53 -0
  81. package/dist/schemas/asyncTask.schema.js +88 -0
  82. package/dist/schemas/block.schema.d.ts +390 -73
  83. package/dist/schemas/block.schema.js +39 -8
  84. package/dist/schemas/codeLanguages.d.ts +7 -1
  85. package/dist/schemas/codeLanguages.js +4 -1
  86. package/dist/schemas/colors.d.ts +7 -1
  87. package/dist/schemas/colors.js +4 -1
  88. package/dist/schemas/comment.schema.d.ts +28 -5
  89. package/dist/schemas/comment.schema.js +11 -2
  90. package/dist/schemas/customEmoji.schema.d.ts +18 -0
  91. package/dist/schemas/customEmoji.schema.js +50 -0
  92. package/dist/schemas/dataSource.schema.d.ts +84 -10
  93. package/dist/schemas/dataSource.schema.js +31 -6
  94. package/dist/schemas/database.schema.d.ts +51 -7
  95. package/dist/schemas/database.schema.js +10 -3
  96. package/dist/schemas/emoji.schema.d.ts +7 -2
  97. package/dist/schemas/emoji.schema.js +4 -2
  98. package/dist/schemas/file.schema.d.ts +18 -2
  99. package/dist/schemas/file.schema.js +6 -2
  100. package/dist/schemas/fileUpload.schema.d.ts +9 -3
  101. package/dist/schemas/fileUpload.schema.js +5 -2
  102. package/dist/schemas/icon.schema.d.ts +116 -0
  103. package/dist/schemas/icon.schema.js +100 -0
  104. package/dist/schemas/index.d.ts +6 -0
  105. package/dist/schemas/index.js +6 -0
  106. package/dist/schemas/meetingNotesQuery.schema.d.ts +4198 -0
  107. package/dist/schemas/meetingNotesQuery.schema.js +67 -0
  108. package/dist/schemas/page.schema.d.ts +51 -9
  109. package/dist/schemas/page.schema.js +6 -2
  110. package/dist/schemas/pageMarkdown.schema.d.ts +70 -0
  111. package/dist/schemas/pageMarkdown.schema.js +70 -0
  112. package/dist/schemas/pageProperties.schema.d.ts +105 -21
  113. package/dist/schemas/pageProperties.schema.js +8 -6
  114. package/dist/schemas/pagination.schema.d.ts +57 -7
  115. package/dist/schemas/pagination.schema.js +25 -1
  116. package/dist/schemas/parent.schema.d.ts +39 -3
  117. package/dist/schemas/parent.schema.js +17 -5
  118. package/dist/schemas/propertyObjects.schema.d.ts +93 -15
  119. package/dist/schemas/propertyObjects.schema.js +11 -5
  120. package/dist/schemas/richText.schema.d.ts +23 -6
  121. package/dist/schemas/richText.schema.js +7 -4
  122. package/dist/schemas/shared.schema.d.ts +6 -3
  123. package/dist/schemas/shared.schema.js +6 -3
  124. package/dist/schemas/user.schema.d.ts +17 -0
  125. package/dist/schemas/user.schema.js +7 -3
  126. package/dist/schemas/view.schema.d.ts +1111 -0
  127. package/dist/schemas/view.schema.js +134 -0
  128. package/dist/validation.d.ts +11 -4
  129. package/dist/validation.js +11 -4
  130. package/package.json +6 -3
@@ -0,0 +1,286 @@
1
+ import type { NotionClient } from '../client';
2
+ import { Page, View } from '../models';
3
+ import { type NotionView, type PaginatedList, type PaginationParameters, type RequestStatus, type ViewDeleteResult, type ViewType } from '../schemas';
4
+ import { BaseAPI } from './base.api';
5
+ import type { DataSourceSort } from './dataSources.api';
6
+ /**
7
+ * Options for listing views. Exactly one of `database_id`/`data_source_id` must be provided.
8
+ */
9
+ export interface ListViewsOptions extends PaginationParameters {
10
+ /** List views for this database (mutually exclusive with data_source_id) */
11
+ database_id?: string;
12
+ /** List views for this data source (mutually exclusive with database_id) */
13
+ data_source_id?: string;
14
+ }
15
+ /**
16
+ * Options for creating a view. Provide exactly one of
17
+ * `database_id`/`view_id`/`create_database` to select the parent context.
18
+ */
19
+ export interface CreateViewOptions {
20
+ /** The data source the view displays */
21
+ data_source_id: string;
22
+ /** The view name */
23
+ name: string;
24
+ /** The view layout type */
25
+ type: ViewType;
26
+ /** Attach the view to this existing database */
27
+ database_id?: string;
28
+ /** Clone the configuration of this existing view */
29
+ view_id?: string;
30
+ /** Create a new database to hold the view */
31
+ create_database?: true;
32
+ /** Filter configuration */
33
+ filter?: Record<string, unknown>;
34
+ /** Sort configuration */
35
+ sorts?: DataSourceSort[];
36
+ /** Quick filter configuration */
37
+ quick_filters?: Record<string, unknown>;
38
+ /** Per-layout configuration */
39
+ configuration?: Record<string, unknown>;
40
+ /** Where to place the new view relative to existing views */
41
+ position?: Record<string, unknown>;
42
+ }
43
+ /**
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
+ */
47
+ export interface UpdateViewOptions {
48
+ /** Rename the view */
49
+ name?: string;
50
+ /** Update or clear (`null`) the filter configuration */
51
+ filter?: Record<string, unknown> | null;
52
+ /** Update or clear (`null`) the sort configuration */
53
+ sorts?: DataSourceSort[] | null;
54
+ /** Update or clear (`null`) the quick filter configuration */
55
+ quick_filters?: Record<string, unknown> | null;
56
+ /** Shallow-merged per-layout configuration update */
57
+ configuration?: Record<string, unknown>;
58
+ }
59
+ /**
60
+ * Options for creating a view query.
61
+ */
62
+ export interface CreateViewQueryOptions extends PaginationParameters {
63
+ /** Filter configuration */
64
+ filter?: Record<string, unknown>;
65
+ /** Sort configuration */
66
+ sorts?: DataSourceSort[];
67
+ }
68
+ /**
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
+ */
73
+ export interface ViewQueryResult {
74
+ id: string;
75
+ viewId: string;
76
+ expiresAt: Date;
77
+ totalCount: number;
78
+ results: Page[];
79
+ nextCursor: string | null;
80
+ hasMore: boolean;
81
+ requestStatus?: RequestStatus;
82
+ }
83
+ /**
84
+ * Views API client for working with Notion views.
85
+ *
86
+ * Views control how a database/data source's rows are displayed (table, board,
87
+ * calendar, etc.). Requires API version 2025-09-03 or later.
88
+ *
89
+ * @category Views
90
+ */
91
+ export declare class ViewsAPI extends BaseAPI<NotionView, View> {
92
+ protected readonly client: NotionClient;
93
+ protected config: {
94
+ schema: import("zod").ZodObject<{
95
+ object: import("zod").ZodLiteral<"view">;
96
+ id: import("zod").ZodUUID;
97
+ parent: import("zod").ZodObject<{
98
+ type: import("zod").ZodLiteral<"database_id">;
99
+ database_id: import("zod").ZodUUID;
100
+ }, import("zod/v4/core").$strip>;
101
+ data_source_id: import("zod").ZodNullable<import("zod").ZodUUID>;
102
+ name: import("zod").ZodString;
103
+ type: import("zod").ZodEnum<{
104
+ map: "map";
105
+ table: "table";
106
+ list: "list";
107
+ board: "board";
108
+ calendar: "calendar";
109
+ timeline: "timeline";
110
+ gallery: "gallery";
111
+ form: "form";
112
+ chart: "chart";
113
+ dashboard: "dashboard";
114
+ }>;
115
+ filter: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>>;
116
+ sorts: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodArray<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>>>;
117
+ quick_filters: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodUnknown>>>;
118
+ configuration: import("zod").ZodOptional<import("zod").ZodObject<{
119
+ type: import("zod").ZodEnum<{
120
+ map: "map";
121
+ table: "table";
122
+ list: "list";
123
+ board: "board";
124
+ calendar: "calendar";
125
+ timeline: "timeline";
126
+ gallery: "gallery";
127
+ form: "form";
128
+ chart: "chart";
129
+ dashboard: "dashboard";
130
+ }>;
131
+ }, import("zod/v4/core").$catchall<import("zod").ZodUnknown>>>;
132
+ created_time: import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>;
133
+ last_edited_time: import("zod").ZodUnion<readonly [import("zod").ZodISODateTime, import("zod").ZodISODate]>;
134
+ created_by: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
135
+ object: import("zod").ZodLiteral<"user">;
136
+ id: import("zod").ZodUUID;
137
+ type: import("zod").ZodLiteral<"person">;
138
+ name: import("zod").ZodOptional<import("zod").ZodString>;
139
+ avatar_url: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodURL, import("zod").ZodNull]>>;
140
+ person: import("zod").ZodObject<{
141
+ email: import("zod").ZodEmail;
142
+ email_verified: import("zod").ZodOptional<import("zod").ZodBoolean>;
143
+ }, import("zod/v4/core").$strip>;
144
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
145
+ object: import("zod").ZodLiteral<"user">;
146
+ id: import("zod").ZodUUID;
147
+ type: import("zod").ZodLiteral<"bot">;
148
+ name: import("zod").ZodOptional<import("zod").ZodString>;
149
+ avatar_url: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodURL, import("zod").ZodNull]>>;
150
+ bot: import("zod").ZodObject<{
151
+ owner: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
152
+ type: import("zod").ZodLiteral<"workspace">;
153
+ workspace: import("zod").ZodLiteral<true>;
154
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
155
+ type: import("zod").ZodLiteral<"user">;
156
+ }, import("zod/v4/core").$strip>], "type">;
157
+ workspace_name: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
158
+ workspace_id: import("zod").ZodOptional<import("zod").ZodString>;
159
+ workspace_limits: import("zod").ZodOptional<import("zod").ZodObject<{
160
+ max_file_upload_size_in_bytes: import("zod").ZodInt;
161
+ }, import("zod/v4/core").$strip>>;
162
+ }, import("zod/v4/core").$strip>;
163
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
164
+ object: import("zod").ZodLiteral<"user">;
165
+ id: import("zod").ZodUUID;
166
+ }, import("zod/v4/core").$strip>]>;
167
+ last_edited_by: import("zod").ZodUnion<readonly [import("zod").ZodObject<{
168
+ object: import("zod").ZodLiteral<"user">;
169
+ id: import("zod").ZodUUID;
170
+ type: import("zod").ZodLiteral<"person">;
171
+ name: import("zod").ZodOptional<import("zod").ZodString>;
172
+ avatar_url: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodURL, import("zod").ZodNull]>>;
173
+ person: import("zod").ZodObject<{
174
+ email: import("zod").ZodEmail;
175
+ email_verified: import("zod").ZodOptional<import("zod").ZodBoolean>;
176
+ }, import("zod/v4/core").$strip>;
177
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
178
+ object: import("zod").ZodLiteral<"user">;
179
+ id: import("zod").ZodUUID;
180
+ type: import("zod").ZodLiteral<"bot">;
181
+ name: import("zod").ZodOptional<import("zod").ZodString>;
182
+ avatar_url: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodURL, import("zod").ZodNull]>>;
183
+ bot: import("zod").ZodObject<{
184
+ owner: import("zod").ZodDiscriminatedUnion<[import("zod").ZodObject<{
185
+ type: import("zod").ZodLiteral<"workspace">;
186
+ workspace: import("zod").ZodLiteral<true>;
187
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
188
+ type: import("zod").ZodLiteral<"user">;
189
+ }, import("zod/v4/core").$strip>], "type">;
190
+ workspace_name: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodString>>;
191
+ workspace_id: import("zod").ZodOptional<import("zod").ZodString>;
192
+ workspace_limits: import("zod").ZodOptional<import("zod").ZodObject<{
193
+ max_file_upload_size_in_bytes: import("zod").ZodInt;
194
+ }, import("zod/v4/core").$strip>>;
195
+ }, import("zod/v4/core").$strip>;
196
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
197
+ object: import("zod").ZodLiteral<"user">;
198
+ id: import("zod").ZodUUID;
199
+ }, import("zod/v4/core").$strip>]>;
200
+ url: import("zod").ZodURL;
201
+ dashboard_view_id: import("zod").ZodOptional<import("zod").ZodUUID>;
202
+ }, import("zod/v4/core").$strip>;
203
+ ModelClass: typeof View;
204
+ listType: "view";
205
+ };
206
+ constructor(client: NotionClient);
207
+ /**
208
+ * List the views for a database or data source.
209
+ *
210
+ * @param options - Exactly one of `database_id`/`data_source_id`, plus pagination
211
+ * @returns Paginated list of views
212
+ *
213
+ * @throws {NotionValidationError} If neither or both of `database_id`/`data_source_id` are provided
214
+ *
215
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
216
+ */
217
+ list(options: ListViewsOptions): Promise<PaginatedList<View>>;
218
+ /**
219
+ * Retrieve a view by ID.
220
+ *
221
+ * @param viewId - The ID of the view to retrieve
222
+ * @returns The view wrapped in a View model
223
+ *
224
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
225
+ */
226
+ retrieve(viewId: string): Promise<View>;
227
+ /**
228
+ * Create a new view.
229
+ *
230
+ * @param options - Options for creating the view
231
+ * @returns The created view wrapped in a View model
232
+ *
233
+ * @throws {NotionValidationError} If not exactly one of `database_id`/`view_id`/`create_database` is provided
234
+ *
235
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
236
+ */
237
+ create(options: CreateViewOptions): Promise<View>;
238
+ /**
239
+ * Update a view's name, filter, sorts, quick filters, or configuration.
240
+ *
241
+ * @param viewId - The ID of the view to update
242
+ * @param options - Options for updating the view
243
+ * @returns The updated view wrapped in a View model
244
+ *
245
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
246
+ */
247
+ update(viewId: string, options: UpdateViewOptions): Promise<View>;
248
+ /**
249
+ * Delete a view.
250
+ *
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.
254
+ *
255
+ * @param viewId - The ID of the view to delete
256
+ * @returns The partial view object returned by the API
257
+ *
258
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
259
+ */
260
+ delete(viewId: string): Promise<ViewDeleteResult>;
261
+ /**
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.
265
+ */
266
+ readonly queries: {
267
+ /**
268
+ * Create a new query against a view.
269
+ *
270
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
271
+ */
272
+ create: (viewId: string, options?: CreateViewQueryOptions) => Promise<ViewQueryResult>;
273
+ /**
274
+ * Retrieve the results of a previously created view query.
275
+ *
276
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
277
+ */
278
+ get: (viewId: string, queryId: string) => Promise<ViewQueryResult>;
279
+ /**
280
+ * Delete a view query.
281
+ *
282
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
283
+ */
284
+ delete: (viewId: string, queryId: string) => Promise<void>;
285
+ };
286
+ }
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewsAPI = void 0;
4
+ const models_1 = require("../models");
5
+ const base_model_1 = require("../models/base.model");
6
+ const schemas_1 = require("../schemas");
7
+ const validation_1 = require("../validation");
8
+ const base_api_1 = require("./base.api");
9
+ function toViewQueryResult(response) {
10
+ const parsed = schemas_1.viewQueryResponseSchema.parse(response);
11
+ return {
12
+ id: parsed.id,
13
+ viewId: parsed.view_id,
14
+ expiresAt: new Date(parsed.expires_at),
15
+ totalCount: parsed.total_count,
16
+ results: parsed.results.map((page) => new models_1.Page(page, base_model_1.TRUSTED)),
17
+ nextCursor: parsed.next_cursor,
18
+ hasMore: parsed.has_more,
19
+ requestStatus: parsed.request_status,
20
+ };
21
+ }
22
+ /**
23
+ * Views API client for working with Notion views.
24
+ *
25
+ * Views control how a database/data source's rows are displayed (table, board,
26
+ * calendar, etc.). Requires API version 2025-09-03 or later.
27
+ *
28
+ * @category Views
29
+ */
30
+ class ViewsAPI extends base_api_1.BaseAPI {
31
+ constructor(client) {
32
+ super(client);
33
+ this.client = client;
34
+ this.config = {
35
+ schema: schemas_1.viewSchema,
36
+ ModelClass: models_1.View,
37
+ listType: 'view',
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.
43
+ */
44
+ this.queries = {
45
+ /**
46
+ * Create a new query against a view.
47
+ *
48
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
49
+ */
50
+ create: async (viewId, options) => {
51
+ const body = {};
52
+ if (options?.filter) {
53
+ body.filter = options.filter;
54
+ }
55
+ if (options?.sorts) {
56
+ body.sorts = options.sorts;
57
+ }
58
+ Object.assign(body, this.buildPaginationBody(options));
59
+ const response = await this.client.request({
60
+ method: 'POST',
61
+ path: `/views/${viewId}/queries`,
62
+ body: Object.keys(body).length > 0 ? body : undefined,
63
+ });
64
+ return toViewQueryResult(response);
65
+ },
66
+ /**
67
+ * Retrieve the results of a previously created view query.
68
+ *
69
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
70
+ */
71
+ get: async (viewId, queryId) => {
72
+ const response = await this.client.request({
73
+ method: 'GET',
74
+ path: `/views/${viewId}/queries/${queryId}`,
75
+ });
76
+ return toViewQueryResult(response);
77
+ },
78
+ /**
79
+ * Delete a view query.
80
+ *
81
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
82
+ */
83
+ delete: async (viewId, queryId) => {
84
+ await this.client.request({
85
+ method: 'DELETE',
86
+ path: `/views/${viewId}/queries/${queryId}`,
87
+ });
88
+ },
89
+ };
90
+ }
91
+ /**
92
+ * List the views for a database or data source.
93
+ *
94
+ * @param options - Exactly one of `database_id`/`data_source_id`, plus pagination
95
+ * @returns Paginated list of views
96
+ *
97
+ * @throws {NotionValidationError} If neither or both of `database_id`/`data_source_id` are provided
98
+ *
99
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
100
+ */
101
+ async list(options) {
102
+ if (Boolean(options.database_id) === Boolean(options.data_source_id)) {
103
+ throw new validation_1.NotionValidationError('Exactly one of database_id or data_source_id must be provided');
104
+ }
105
+ const query = {
106
+ ...(options.database_id ? { database_id: options.database_id } : {}),
107
+ ...(options.data_source_id ? { data_source_id: options.data_source_id } : {}),
108
+ ...this.buildPaginationQuery(options),
109
+ };
110
+ return this.listResources('/views', query);
111
+ }
112
+ /**
113
+ * Retrieve a view by ID.
114
+ *
115
+ * @param viewId - The ID of the view to retrieve
116
+ * @returns The view wrapped in a View model
117
+ *
118
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
119
+ */
120
+ async retrieve(viewId) {
121
+ return this.retrieveResource(`/views/${viewId}`);
122
+ }
123
+ /**
124
+ * Create a new view.
125
+ *
126
+ * @param options - Options for creating the view
127
+ * @returns The created view wrapped in a View model
128
+ *
129
+ * @throws {NotionValidationError} If not exactly one of `database_id`/`view_id`/`create_database` is provided
130
+ *
131
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
132
+ */
133
+ async create(options) {
134
+ const selectorCount = [options.database_id, options.view_id, options.create_database].filter((value) => value !== undefined).length;
135
+ if (selectorCount !== 1) {
136
+ throw new validation_1.NotionValidationError('Exactly one of database_id, view_id, or create_database must be provided');
137
+ }
138
+ return this.createResource('/views', options);
139
+ }
140
+ /**
141
+ * Update a view's name, filter, sorts, quick filters, or configuration.
142
+ *
143
+ * @param viewId - The ID of the view to update
144
+ * @param options - Options for updating the view
145
+ * @returns The updated view wrapped in a View model
146
+ *
147
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
148
+ */
149
+ async update(viewId, options) {
150
+ return this.updateResource(`/views/${viewId}`, options);
151
+ }
152
+ /**
153
+ * Delete a view.
154
+ *
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.
158
+ *
159
+ * @param viewId - The ID of the view to delete
160
+ * @returns The partial view object returned by the API
161
+ *
162
+ * @see https://developers.notion.com/guides/data-apis/working-with-views
163
+ */
164
+ async delete(viewId) {
165
+ const response = await this.client.request({
166
+ method: 'DELETE',
167
+ path: `/views/${viewId}`,
168
+ });
169
+ return schemas_1.viewDeleteResponseSchema.parse(response);
170
+ }
171
+ }
172
+ exports.ViewsAPI = ViewsAPI;
package/dist/client.d.ts CHANGED
@@ -1,10 +1,14 @@
1
1
  /**
2
- * The Notion API version targeted by this SDK.
3
- * All schemas, request bodies, helpers, and models are coupled to this version.
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
- * Makes an HTTP request to the Notion API with retry logic for rate limits.
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
- * Makes a single HTTP request to the Notion API.
53
+ * Send one HTTP request to the Notion API.
49
54
  */
50
55
  private makeRequest;
51
56
  /**
52
- * Computes a fallback retry delay using exponential backoff.
53
- * Used when the `Retry-After` response header is absent.
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
- * Sleeps for the specified duration in milliseconds.
63
+ * Pause for the given duration, in milliseconds.
59
64
  */
60
65
  private sleep;
61
66
  /**
62
- * Builds the full URL with query parameters.
67
+ * Build the full URL with query parameters.
63
68
  */
64
69
  private buildUrl;
65
70
  /**
66
- * Builds request headers.
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
- * Handles error responses from the API.
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 targeted by this SDK.
7
- * All schemas, request bodies, helpers, and models are coupled to this version.
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.auth = options.auth;
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
- * Makes an HTTP request to the Notion API with retry logic for rate limits.
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;
@@ -29,10 +36,10 @@ class NotionClient {
29
36
  return await this.makeRequest(options);
30
37
  }
31
38
  catch (error) {
32
- // Only retry on rate limit errors if retry is enabled
39
+ // Retry rate-limited requests (if enabled) and service-overload (529)
40
+ // responses, which the API recommends always retrying.
33
41
  if (error instanceof errors_1.NotionAPIError &&
34
- error.isRateLimited() &&
35
- this.retryOnRateLimit &&
42
+ ((error.isRateLimited() && this.retryOnRateLimit) || error.isServiceOverloaded()) &&
36
43
  attempt < this.maxRetries) {
37
44
  // Prefer the server-supplied Retry-After value; fall back to
38
45
  // exponential backoff when the header is absent.
@@ -49,17 +56,16 @@ class NotionClient {
49
56
  throw lastError ?? new Error('Request failed after all retries');
50
57
  }
51
58
  /**
52
- * Makes a single HTTP request to the Notion API.
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
- * Computes a fallback retry delay using exponential backoff.
93
- * Used when the `Retry-After` response header is absent.
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
- * Sleeps for the specified duration in milliseconds.
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
- * Builds the full URL with query parameters.
113
+ * Build the full URL with query parameters.
108
114
  */
109
115
  buildUrl(path, query) {
110
- const url = new URL(`${this.baseUrl}/v1${path}`);
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
- * Builds request headers.
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
- * Handles error responses from the API.
148
+ * Handle an error response from the API.
154
149
  */
155
150
  async handleErrorResponse(response) {
156
151
  const retryAfterMs = this.parseRetryAfterHeader(response);