@visus-io/notion-sdk-ts 2.0.0 → 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 (206) hide show
  1. package/README.md +66 -921
  2. package/dist/api/base.api.d.ts +161 -0
  3. package/dist/api/base.api.js +228 -0
  4. package/dist/api/blocks.api.d.ts +3867 -4
  5. package/dist/api/blocks.api.js +16 -47
  6. package/dist/api/comments.api.d.ts +259 -4
  7. package/dist/api/comments.api.js +11 -29
  8. package/dist/api/dataSources.api.d.ts +788 -4
  9. package/dist/api/dataSources.api.js +14 -28
  10. package/dist/api/databases.api.d.ts +491 -4
  11. package/dist/api/databases.api.js +20 -45
  12. package/dist/api/fileUploads.api.d.ts +25 -3
  13. package/dist/api/fileUploads.api.js +7 -2
  14. package/dist/api/index.d.ts +0 -1
  15. package/dist/api/index.js +0 -1
  16. package/dist/api/pages.api.d.ts +864 -3
  17. package/dist/api/pages.api.js +14 -28
  18. package/dist/api/search.api.d.ts +0 -1
  19. package/dist/api/search.api.js +5 -11
  20. package/dist/api/users.api.d.ts +40 -4
  21. package/dist/api/users.api.js +12 -35
  22. package/dist/client.d.ts +0 -1
  23. package/dist/client.js +0 -1
  24. package/dist/errors.d.ts +0 -1
  25. package/dist/errors.js +0 -1
  26. package/dist/helpers/block.helpers.d.ts +4 -1
  27. package/dist/helpers/block.helpers.js +11 -1
  28. package/dist/helpers/file.helpers.d.ts +0 -1
  29. package/dist/helpers/file.helpers.js +0 -1
  30. package/dist/helpers/filter.helpers.d.ts +0 -1
  31. package/dist/helpers/filter.helpers.js +0 -1
  32. package/dist/helpers/index.d.ts +0 -1
  33. package/dist/helpers/index.js +0 -1
  34. package/dist/helpers/pagination.helpers.d.ts +0 -1
  35. package/dist/helpers/pagination.helpers.js +0 -1
  36. package/dist/helpers/parent.helpers.d.ts +0 -1
  37. package/dist/helpers/parent.helpers.js +0 -1
  38. package/dist/helpers/property.helpers.d.ts +0 -1
  39. package/dist/helpers/property.helpers.js +0 -1
  40. package/dist/helpers/richText.helpers.d.ts +0 -1
  41. package/dist/helpers/richText.helpers.js +0 -1
  42. package/dist/helpers/sort.helpers.d.ts +0 -1
  43. package/dist/helpers/sort.helpers.js +0 -1
  44. package/dist/index.d.ts +0 -1
  45. package/dist/index.js +0 -1
  46. package/dist/models/base.model.d.ts +2 -3
  47. package/dist/models/base.model.js +0 -1
  48. package/dist/models/block.model.d.ts +0 -1
  49. package/dist/models/block.model.js +0 -1
  50. package/dist/models/comment.model.d.ts +0 -1
  51. package/dist/models/comment.model.js +0 -1
  52. package/dist/models/dataSource.model.d.ts +0 -1
  53. package/dist/models/dataSource.model.js +0 -1
  54. package/dist/models/database.model.d.ts +0 -1
  55. package/dist/models/database.model.js +0 -1
  56. package/dist/models/fileUpload.model.d.ts +0 -1
  57. package/dist/models/fileUpload.model.js +0 -1
  58. package/dist/models/index.d.ts +0 -1
  59. package/dist/models/index.js +0 -1
  60. package/dist/models/page.model.d.ts +0 -1
  61. package/dist/models/page.model.js +0 -1
  62. package/dist/models/richText.model.d.ts +0 -1
  63. package/dist/models/richText.model.js +0 -1
  64. package/dist/models/user.model.d.ts +0 -1
  65. package/dist/models/user.model.js +0 -1
  66. package/dist/notion.d.ts +0 -1
  67. package/dist/notion.js +0 -1
  68. package/dist/schemas/block.schema.d.ts +261 -82
  69. package/dist/schemas/block.schema.js +157 -82
  70. package/dist/schemas/codeLanguages.d.ts +0 -1
  71. package/dist/schemas/codeLanguages.js +0 -1
  72. package/dist/schemas/colors.d.ts +0 -1
  73. package/dist/schemas/colors.js +0 -1
  74. package/dist/schemas/comment.schema.d.ts +9 -10
  75. package/dist/schemas/comment.schema.js +54 -21
  76. package/dist/schemas/dataSource.schema.d.ts +13 -14
  77. package/dist/schemas/dataSource.schema.js +46 -13
  78. package/dist/schemas/database.schema.d.ts +13 -14
  79. package/dist/schemas/database.schema.js +51 -18
  80. package/dist/schemas/emoji.schema.d.ts +1 -2
  81. package/dist/schemas/emoji.schema.js +37 -5
  82. package/dist/schemas/file.schema.d.ts +3 -4
  83. package/dist/schemas/file.schema.js +49 -16
  84. package/dist/schemas/fileUpload.schema.d.ts +3 -4
  85. package/dist/schemas/fileUpload.schema.js +47 -14
  86. package/dist/schemas/index.d.ts +1 -1
  87. package/dist/schemas/index.js +1 -1
  88. package/dist/schemas/page.schema.d.ts +30 -31
  89. package/dist/schemas/page.schema.js +47 -14
  90. package/dist/schemas/pageProperties.schema.d.ts +47 -48
  91. package/dist/schemas/pageProperties.schema.js +162 -129
  92. package/dist/schemas/pagination.schema.d.ts +1 -2
  93. package/dist/schemas/pagination.schema.js +40 -8
  94. package/dist/schemas/parent.schema.d.ts +1 -2
  95. package/dist/schemas/parent.schema.js +51 -19
  96. package/dist/schemas/propertyObjects.schema.d.ts +1 -2
  97. package/dist/schemas/propertyObjects.schema.js +194 -162
  98. package/dist/schemas/richText.schema.d.ts +7 -8
  99. package/dist/schemas/richText.schema.js +95 -57
  100. package/dist/schemas/shared.schema.d.ts +15 -0
  101. package/dist/schemas/shared.schema.js +54 -0
  102. package/dist/schemas/user.schema.d.ts +3 -4
  103. package/dist/schemas/user.schema.js +63 -31
  104. package/dist/validation.d.ts +0 -1
  105. package/dist/validation.js +0 -1
  106. package/package.json +3 -1
  107. package/dist/api/blocks.api.d.ts.map +0 -1
  108. package/dist/api/blocks.api.js.map +0 -1
  109. package/dist/api/comments.api.d.ts.map +0 -1
  110. package/dist/api/comments.api.js.map +0 -1
  111. package/dist/api/dataSources.api.d.ts.map +0 -1
  112. package/dist/api/dataSources.api.js.map +0 -1
  113. package/dist/api/databases.api.d.ts.map +0 -1
  114. package/dist/api/databases.api.js.map +0 -1
  115. package/dist/api/fileUploads.api.d.ts.map +0 -1
  116. package/dist/api/fileUploads.api.js.map +0 -1
  117. package/dist/api/index.d.ts.map +0 -1
  118. package/dist/api/index.js.map +0 -1
  119. package/dist/api/pages.api.d.ts.map +0 -1
  120. package/dist/api/pages.api.js.map +0 -1
  121. package/dist/api/search.api.d.ts.map +0 -1
  122. package/dist/api/search.api.js.map +0 -1
  123. package/dist/api/users.api.d.ts.map +0 -1
  124. package/dist/api/users.api.js.map +0 -1
  125. package/dist/client.d.ts.map +0 -1
  126. package/dist/client.js.map +0 -1
  127. package/dist/errors.d.ts.map +0 -1
  128. package/dist/errors.js.map +0 -1
  129. package/dist/helpers/block.helpers.d.ts.map +0 -1
  130. package/dist/helpers/block.helpers.js.map +0 -1
  131. package/dist/helpers/file.helpers.d.ts.map +0 -1
  132. package/dist/helpers/file.helpers.js.map +0 -1
  133. package/dist/helpers/filter.helpers.d.ts.map +0 -1
  134. package/dist/helpers/filter.helpers.js.map +0 -1
  135. package/dist/helpers/index.d.ts.map +0 -1
  136. package/dist/helpers/index.js.map +0 -1
  137. package/dist/helpers/pagination.helpers.d.ts.map +0 -1
  138. package/dist/helpers/pagination.helpers.js.map +0 -1
  139. package/dist/helpers/parent.helpers.d.ts.map +0 -1
  140. package/dist/helpers/parent.helpers.js.map +0 -1
  141. package/dist/helpers/property.helpers.d.ts.map +0 -1
  142. package/dist/helpers/property.helpers.js.map +0 -1
  143. package/dist/helpers/richText.helpers.d.ts.map +0 -1
  144. package/dist/helpers/richText.helpers.js.map +0 -1
  145. package/dist/helpers/sort.helpers.d.ts.map +0 -1
  146. package/dist/helpers/sort.helpers.js.map +0 -1
  147. package/dist/index.d.ts.map +0 -1
  148. package/dist/index.js.map +0 -1
  149. package/dist/models/base.model.d.ts.map +0 -1
  150. package/dist/models/base.model.js.map +0 -1
  151. package/dist/models/block.model.d.ts.map +0 -1
  152. package/dist/models/block.model.js.map +0 -1
  153. package/dist/models/comment.model.d.ts.map +0 -1
  154. package/dist/models/comment.model.js.map +0 -1
  155. package/dist/models/dataSource.model.d.ts.map +0 -1
  156. package/dist/models/dataSource.model.js.map +0 -1
  157. package/dist/models/database.model.d.ts.map +0 -1
  158. package/dist/models/database.model.js.map +0 -1
  159. package/dist/models/fileUpload.model.d.ts.map +0 -1
  160. package/dist/models/fileUpload.model.js.map +0 -1
  161. package/dist/models/index.d.ts.map +0 -1
  162. package/dist/models/index.js.map +0 -1
  163. package/dist/models/page.model.d.ts.map +0 -1
  164. package/dist/models/page.model.js.map +0 -1
  165. package/dist/models/richText.model.d.ts.map +0 -1
  166. package/dist/models/richText.model.js.map +0 -1
  167. package/dist/models/user.model.d.ts.map +0 -1
  168. package/dist/models/user.model.js.map +0 -1
  169. package/dist/notion.d.ts.map +0 -1
  170. package/dist/notion.js.map +0 -1
  171. package/dist/schemas/block.schema.d.ts.map +0 -1
  172. package/dist/schemas/block.schema.js.map +0 -1
  173. package/dist/schemas/codeLanguages.d.ts.map +0 -1
  174. package/dist/schemas/codeLanguages.js.map +0 -1
  175. package/dist/schemas/colors.d.ts.map +0 -1
  176. package/dist/schemas/colors.js.map +0 -1
  177. package/dist/schemas/comment.schema.d.ts.map +0 -1
  178. package/dist/schemas/comment.schema.js.map +0 -1
  179. package/dist/schemas/dataSource.schema.d.ts.map +0 -1
  180. package/dist/schemas/dataSource.schema.js.map +0 -1
  181. package/dist/schemas/database.schema.d.ts.map +0 -1
  182. package/dist/schemas/database.schema.js.map +0 -1
  183. package/dist/schemas/emoji.schema.d.ts.map +0 -1
  184. package/dist/schemas/emoji.schema.js.map +0 -1
  185. package/dist/schemas/file.schema.d.ts.map +0 -1
  186. package/dist/schemas/file.schema.js.map +0 -1
  187. package/dist/schemas/fileUpload.schema.d.ts.map +0 -1
  188. package/dist/schemas/fileUpload.schema.js.map +0 -1
  189. package/dist/schemas/index.d.ts.map +0 -1
  190. package/dist/schemas/index.js.map +0 -1
  191. package/dist/schemas/page.schema.d.ts.map +0 -1
  192. package/dist/schemas/page.schema.js.map +0 -1
  193. package/dist/schemas/pageProperties.schema.d.ts.map +0 -1
  194. package/dist/schemas/pageProperties.schema.js.map +0 -1
  195. package/dist/schemas/pagination.schema.d.ts.map +0 -1
  196. package/dist/schemas/pagination.schema.js.map +0 -1
  197. package/dist/schemas/parent.schema.d.ts.map +0 -1
  198. package/dist/schemas/parent.schema.js.map +0 -1
  199. package/dist/schemas/propertyObjects.schema.d.ts.map +0 -1
  200. package/dist/schemas/propertyObjects.schema.js.map +0 -1
  201. package/dist/schemas/richText.schema.d.ts.map +0 -1
  202. package/dist/schemas/richText.schema.js.map +0 -1
  203. package/dist/schemas/user.schema.d.ts.map +0 -1
  204. package/dist/schemas/user.schema.js.map +0 -1
  205. package/dist/validation.d.ts.map +0 -1
  206. package/dist/validation.js.map +0 -1
@@ -0,0 +1,161 @@
1
+ import type { NotionClient } from '../client';
2
+ import type { PaginatedList, PaginatedListType, PaginationParameters } from '../schemas';
3
+ import type * as z from 'zod';
4
+ /**
5
+ * Configuration for API resource operations, including paths, schemas, and model classes.
6
+ *
7
+ * @template TResponse - The raw response type from the API
8
+ * @template TModel - The model class type that wraps the response
9
+ */
10
+ interface ResourceConfig<TResponse, TModel> {
11
+ /** Zod schema to validate the API response */
12
+ schema: z.ZodSchema<TResponse>;
13
+ /** Model class constructor to wrap the validated response */
14
+ ModelClass: new (data: TResponse) => TModel;
15
+ /** Type of items in the paginated list (used for typing the results) */
16
+ listType?: PaginatedListType;
17
+ }
18
+ /**
19
+ * Base API class providing common functionality for all Notion API clients.
20
+ *
21
+ * @template TResponse - The raw response type from the API
22
+ * @template TModel - The model class type that wraps the response
23
+ */
24
+ export declare abstract class BaseAPI<TResponse, TModel> {
25
+ protected readonly client: NotionClient;
26
+ protected abstract config: ResourceConfig<TResponse, TModel>;
27
+ protected constructor(client: NotionClient);
28
+ /**
29
+ * Delete a resource via DELETE request.
30
+ *
31
+ * @param resourcePath - Path to the specific resource (e.g., '/pages/{page_id}', '/databases/{database_id}')
32
+ * @returns Instance of the model class representing the deleted resource
33
+ *
34
+ * @example
35
+ * return this.deleteResource(`/pages/${pageId}`);
36
+ */
37
+ protected deleteResource(resourcePath: string): Promise<TModel>;
38
+ /**
39
+ * Build filter_properties body parameter from an array of property names.
40
+ *
41
+ * @param filterProperties - Optional array of property names to include in the response
42
+ * @returns Body object with filter_properties parameter for API requests
43
+ *
44
+ * @throws {NotionValidationError} If array exceeds LIMITS.ARRAY_ELEMENTS
45
+ * @example
46
+ * const body = this.buildFilterPropertiesBody(['Name', 'Status']);
47
+ * // body will be: { filter_properties: ['Name', 'Status'] }
48
+ */
49
+ protected buildFilterPropertiesBody(filterProperties?: string[]): Record<string, unknown>;
50
+ /**
51
+ * Build pagination body parameters from PaginationParameters.
52
+ *
53
+ * @param params - Optional pagination parameters
54
+ * @returns Body object with pagination parameters for API requests
55
+ *
56
+ * @example
57
+ * const body = this.buildPaginationBody({ page_size: 50, start_cursor: 'abc123' });
58
+ * // body will be: { page_size: 50, start_cursor: 'abc123' }
59
+ */
60
+ protected buildPaginationBody(params?: PaginationParameters): Record<string, unknown>;
61
+ /**
62
+ * Build filter_properties query parameter from an array of property names.
63
+ *
64
+ * @param filterProperties - Optional array of property names to include in the response
65
+ * @returns Query object with filter_properties parameter for API requests
66
+ *
67
+ * @throws {NotionValidationError} If array exceeds LIMITS.ARRAY_ELEMENTS
68
+ *
69
+ * @example
70
+ * const query = this.buildFilterPropertiesQuery(['Name', 'Status']);
71
+ * // query will be: { filter_properties: 'Name,Status' }
72
+ */
73
+ protected buildFilterPropertiesQuery(filterProperties?: string[]): Record<string, string>;
74
+ /**
75
+ * Build pagination query parameters from PaginationParameters.
76
+ *
77
+ * @param params - Optional pagination parameters
78
+ * @returns Query object with pagination parameters for API requests
79
+ *
80
+ * @example
81
+ * const query = this.buildPaginationQuery({ page_size: 50, start_cursor: 'abc123' });
82
+ * // query will be: { page_size: '50', start_cursor: 'abc123' }
83
+ */
84
+ protected buildPaginationQuery(params?: PaginationParameters): Record<string, string>;
85
+ /**
86
+ * Create a new resource via POST request.
87
+ *
88
+ * @param resourcePath - Path to the resource collection (e.g., '/pages', '/databases')
89
+ * @param body - Request body to send
90
+ * @returns Instance of the model class representing the created resource
91
+ *
92
+ * @example
93
+ * return this.createResource(
94
+ * '/pages',
95
+ * { parent: { ... }, properties: { ... } },
96
+ * );
97
+ */
98
+ protected createResource(resourcePath: string, body: unknown): Promise<TModel>;
99
+ /**
100
+ * Retrieve a resource via GET request.
101
+ *
102
+ * @param resourcePath - Path to the specific resource (e.g., '/pages/{page_id}', '/databases/{database_id}')
103
+ * @param query - Optional query parameters for the GET request
104
+ * @returns Instance of the model class representing the retrieved resource
105
+ *
106
+ * @example
107
+ * return this.retrieveResource(`/pages/${pageId}`, query);
108
+ */
109
+ protected retrieveResource(resourcePath: string, query?: Record<string, string>): Promise<TModel>;
110
+ /**
111
+ * Retrieve a paginated list of resources via GET request.
112
+ *
113
+ * @param resourcePath - Path to the resource collection (e.g., '/pages', '/databases')
114
+ * @param query - Optional query parameters for pagination and filtering
115
+ * @returns PaginatedList containing instances of the model class for each item in the results array
116
+ *
117
+ * @example
118
+ * return this.listResources(
119
+ * '/pages',
120
+ * { page_size: '50' },
121
+ * );
122
+ */
123
+ protected listResources(resourcePath: string, query?: Record<string, string>): Promise<PaginatedList<TModel>>;
124
+ /**
125
+ * Update an existing resource via PATCH request.
126
+ *
127
+ * @param resourcePath - Path to the specific resource (e.g., '/pages/{page_id}', '/databases/{database_id}')
128
+ * @param body - Request body with updated fields
129
+ * @returns Instance of the model class representing the updated resource
130
+ *
131
+ * @example
132
+ * return this.updateResource(
133
+ * `/pages/${pageId}`,
134
+ * { properties: { ... } },
135
+ * );
136
+ */
137
+ protected updateResource(resourcePath: string, body: unknown): Promise<TModel>;
138
+ /**
139
+ * Parse response data using the provided schema and wrap it in the specified model class.
140
+ *
141
+ * @param response - The raw response data to parse
142
+ * @returns Instance of the model class representing the parsed resource
143
+ *
144
+ * @example
145
+ * const response = await this.client.request<NotionPage>({ ... });
146
+ * return this.parseAndWrap(response);
147
+ */
148
+ private parseAndWrap;
149
+ /**
150
+ * Parse a paginated list response and wrap each item in the specified model class.
151
+ *
152
+ * @param response - The raw paginated list response to parse
153
+ * @returns PaginatedList containing instances of the model class for each item in the results array
154
+ *
155
+ * @example
156
+ * const response = await this.client.request<PaginatedList<NotionPage>>({ ... });
157
+ * return this.parsePaginatedList(response);
158
+ */
159
+ private parsePaginatedList;
160
+ }
161
+ export {};
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseAPI = void 0;
4
+ const schemas_1 = require("../schemas");
5
+ const validation_1 = require("../validation");
6
+ /**
7
+ * Base API class providing common functionality for all Notion API clients.
8
+ *
9
+ * @template TResponse - The raw response type from the API
10
+ * @template TModel - The model class type that wraps the response
11
+ */
12
+ class BaseAPI {
13
+ constructor(client) {
14
+ this.client = client;
15
+ }
16
+ /**
17
+ * Delete a resource via DELETE request.
18
+ *
19
+ * @param resourcePath - Path to the specific resource (e.g., '/pages/{page_id}', '/databases/{database_id}')
20
+ * @returns Instance of the model class representing the deleted resource
21
+ *
22
+ * @example
23
+ * return this.deleteResource(`/pages/${pageId}`);
24
+ */
25
+ async deleteResource(resourcePath) {
26
+ const response = await this.client.request({
27
+ method: 'DELETE',
28
+ path: resourcePath,
29
+ });
30
+ return this.parseAndWrap(response);
31
+ }
32
+ /**
33
+ * Build filter_properties body parameter from an array of property names.
34
+ *
35
+ * @param filterProperties - Optional array of property names to include in the response
36
+ * @returns Body object with filter_properties parameter for API requests
37
+ *
38
+ * @throws {NotionValidationError} If array exceeds LIMITS.ARRAY_ELEMENTS
39
+ * @example
40
+ * const body = this.buildFilterPropertiesBody(['Name', 'Status']);
41
+ * // body will be: { filter_properties: ['Name', 'Status'] }
42
+ */
43
+ buildFilterPropertiesBody(filterProperties) {
44
+ const body = {};
45
+ if (filterProperties) {
46
+ (0, validation_1.validateArrayLength)(filterProperties, validation_1.LIMITS.ARRAY_ELEMENTS, 'filter_properties');
47
+ body.filter_properties = filterProperties;
48
+ }
49
+ return body;
50
+ }
51
+ /**
52
+ * Build pagination body parameters from PaginationParameters.
53
+ *
54
+ * @param params - Optional pagination parameters
55
+ * @returns Body object with pagination parameters for API requests
56
+ *
57
+ * @example
58
+ * const body = this.buildPaginationBody({ page_size: 50, start_cursor: 'abc123' });
59
+ * // body will be: { page_size: 50, start_cursor: 'abc123' }
60
+ */
61
+ buildPaginationBody(params) {
62
+ const body = {};
63
+ if (params?.page_size) {
64
+ body.page_size = params.page_size;
65
+ }
66
+ if (params?.start_cursor) {
67
+ body.start_cursor = params.start_cursor;
68
+ }
69
+ return body;
70
+ }
71
+ /**
72
+ * Build filter_properties query parameter from an array of property names.
73
+ *
74
+ * @param filterProperties - Optional array of property names to include in the response
75
+ * @returns Query object with filter_properties parameter for API requests
76
+ *
77
+ * @throws {NotionValidationError} If array exceeds LIMITS.ARRAY_ELEMENTS
78
+ *
79
+ * @example
80
+ * const query = this.buildFilterPropertiesQuery(['Name', 'Status']);
81
+ * // query will be: { filter_properties: 'Name,Status' }
82
+ */
83
+ buildFilterPropertiesQuery(filterProperties) {
84
+ const query = {};
85
+ if (filterProperties) {
86
+ (0, validation_1.validateArrayLength)(filterProperties, validation_1.LIMITS.ARRAY_ELEMENTS, 'filter_properties');
87
+ query.filter_properties = filterProperties.join(',');
88
+ }
89
+ return query;
90
+ }
91
+ /**
92
+ * Build pagination query parameters from PaginationParameters.
93
+ *
94
+ * @param params - Optional pagination parameters
95
+ * @returns Query object with pagination parameters for API requests
96
+ *
97
+ * @example
98
+ * const query = this.buildPaginationQuery({ page_size: 50, start_cursor: 'abc123' });
99
+ * // query will be: { page_size: '50', start_cursor: 'abc123' }
100
+ */
101
+ buildPaginationQuery(params) {
102
+ const query = {};
103
+ if (params?.page_size) {
104
+ query.page_size = String(params.page_size);
105
+ }
106
+ if (params?.start_cursor) {
107
+ query.start_cursor = params.start_cursor;
108
+ }
109
+ return query;
110
+ }
111
+ /**
112
+ * Create a new resource via POST request.
113
+ *
114
+ * @param resourcePath - Path to the resource collection (e.g., '/pages', '/databases')
115
+ * @param body - Request body to send
116
+ * @returns Instance of the model class representing the created resource
117
+ *
118
+ * @example
119
+ * return this.createResource(
120
+ * '/pages',
121
+ * { parent: { ... }, properties: { ... } },
122
+ * );
123
+ */
124
+ async createResource(resourcePath, body) {
125
+ const response = await this.client.request({
126
+ method: 'POST',
127
+ path: resourcePath,
128
+ body,
129
+ });
130
+ return this.parseAndWrap(response);
131
+ }
132
+ /**
133
+ * Retrieve a resource via GET request.
134
+ *
135
+ * @param resourcePath - Path to the specific resource (e.g., '/pages/{page_id}', '/databases/{database_id}')
136
+ * @param query - Optional query parameters for the GET request
137
+ * @returns Instance of the model class representing the retrieved resource
138
+ *
139
+ * @example
140
+ * return this.retrieveResource(`/pages/${pageId}`, query);
141
+ */
142
+ async retrieveResource(resourcePath, query) {
143
+ const response = await this.client.request({
144
+ method: 'GET',
145
+ path: resourcePath,
146
+ query: Object.keys(query || {}).length > 0 ? query : undefined,
147
+ });
148
+ return this.parseAndWrap(response);
149
+ }
150
+ /**
151
+ * Retrieve a paginated list of resources via GET request.
152
+ *
153
+ * @param resourcePath - Path to the resource collection (e.g., '/pages', '/databases')
154
+ * @param query - Optional query parameters for pagination and filtering
155
+ * @returns PaginatedList containing instances of the model class for each item in the results array
156
+ *
157
+ * @example
158
+ * return this.listResources(
159
+ * '/pages',
160
+ * { page_size: '50' },
161
+ * );
162
+ */
163
+ async listResources(resourcePath, query) {
164
+ const response = await this.client.request({
165
+ method: 'GET',
166
+ path: resourcePath,
167
+ query: Object.keys(query || {}).length > 0 ? query : undefined,
168
+ });
169
+ return this.parsePaginatedList(response);
170
+ }
171
+ /**
172
+ * Update an existing resource via PATCH request.
173
+ *
174
+ * @param resourcePath - Path to the specific resource (e.g., '/pages/{page_id}', '/databases/{database_id}')
175
+ * @param body - Request body with updated fields
176
+ * @returns Instance of the model class representing the updated resource
177
+ *
178
+ * @example
179
+ * return this.updateResource(
180
+ * `/pages/${pageId}`,
181
+ * { properties: { ... } },
182
+ * );
183
+ */
184
+ async updateResource(resourcePath, body) {
185
+ const response = await this.client.request({
186
+ method: 'PATCH',
187
+ path: resourcePath,
188
+ body,
189
+ });
190
+ return this.parseAndWrap(response);
191
+ }
192
+ /**
193
+ * Parse response data using the provided schema and wrap it in the specified model class.
194
+ *
195
+ * @param response - The raw response data to parse
196
+ * @returns Instance of the model class representing the parsed resource
197
+ *
198
+ * @example
199
+ * const response = await this.client.request<NotionPage>({ ... });
200
+ * return this.parseAndWrap(response);
201
+ */
202
+ parseAndWrap(response) {
203
+ const parsed = this.config.schema.parse(response);
204
+ return new this.config.ModelClass(parsed);
205
+ }
206
+ /**
207
+ * Parse a paginated list response and wrap each item in the specified model class.
208
+ *
209
+ * @param response - The raw paginated list response to parse
210
+ * @returns PaginatedList containing instances of the model class for each item in the results array
211
+ *
212
+ * @example
213
+ * const response = await this.client.request<PaginatedList<NotionPage>>({ ... });
214
+ * return this.parsePaginatedList(response);
215
+ */
216
+ parsePaginatedList(response) {
217
+ const schema = (0, schemas_1.paginatedListSchema)(this.config.schema);
218
+ const parsed = schema.parse(response);
219
+ return {
220
+ object: 'list',
221
+ results: parsed.results.map((item) => new this.config.ModelClass(item)),
222
+ next_cursor: parsed.next_cursor,
223
+ has_more: parsed.has_more,
224
+ type: this.config.listType || 'unknown',
225
+ };
226
+ }
227
+ }
228
+ exports.BaseAPI = BaseAPI;