@notionhq/client 5.25.2 → 5.27.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.
- package/README.md +130 -129
- package/build/package.json +4 -3
- package/build/src/Client.d.ts +1901 -96
- package/build/src/Client.d.ts.map +1 -1
- package/build/src/Client.js +271 -427
- package/build/src/Client.js.map +1 -1
- package/build/src/api-endpoint-methods.d.ts +920 -0
- package/build/src/api-endpoint-methods.d.ts.map +1 -0
- package/build/src/api-endpoint-methods.js +171 -0
- package/build/src/api-endpoint-methods.js.map +1 -0
- package/build/src/api-endpoints/agent-skills.d.ts +68 -0
- package/build/src/api-endpoints/agent-skills.d.ts.map +1 -0
- package/build/src/api-endpoints/agent-skills.js +36 -0
- package/build/src/api-endpoints/agent-skills.js.map +1 -0
- package/build/src/api-endpoints/agents.d.ts +3268 -0
- package/build/src/api-endpoints/agents.d.ts.map +1 -0
- package/build/src/api-endpoints/agents.js +336 -0
- package/build/src/api-endpoints/agents.js.map +1 -0
- package/build/src/api-endpoints/data-sources.d.ts +1 -0
- package/build/src/api-endpoints/data-sources.d.ts.map +1 -1
- package/build/src/api-endpoints/data-sources.js.map +1 -1
- package/build/src/api-endpoints/databases.d.ts +3 -1
- package/build/src/api-endpoints/databases.d.ts.map +1 -1
- package/build/src/api-endpoints/databases.js +1 -0
- package/build/src/api-endpoints/databases.js.map +1 -1
- package/build/src/api-endpoints/file-uploads.d.ts.map +1 -1
- package/build/src/api-endpoints/file-uploads.js.map +1 -1
- package/build/src/api-endpoints/pages.d.ts.map +1 -1
- package/build/src/api-endpoints/pages.js.map +1 -1
- package/build/src/api-endpoints/users.d.ts.map +1 -1
- package/build/src/api-endpoints/users.js.map +1 -1
- package/build/src/api-endpoints.d.ts +2 -0
- package/build/src/api-endpoints.d.ts.map +1 -1
- package/build/src/api-endpoints.js +2 -0
- package/build/src/api-endpoints.js.map +1 -1
- package/build/src/errors.d.ts +11 -0
- package/build/src/errors.d.ts.map +1 -1
- package/build/src/errors.js +20 -1
- package/build/src/errors.js.map +1 -1
- package/build/src/fetch-types.d.ts +11 -0
- package/build/src/fetch-types.d.ts.map +1 -1
- package/build/src/fetch-types.js.map +1 -1
- package/build/src/helpers.d.ts +4 -4
- package/build/src/helpers.d.ts.map +1 -1
- package/build/src/helpers.js.map +1 -1
- package/build/src/index.d.ts +2 -2
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +2 -1
- package/build/src/index.js.map +1 -1
- package/build/src/webhooks.d.ts +12 -19
- package/build/src/webhooks.d.ts.map +1 -1
- package/build/src/webhooks.js +27 -35
- package/build/src/webhooks.js.map +1 -1
- package/package.json +4 -3
package/build/src/Client.js
CHANGED
|
@@ -10,8 +10,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _Client_auth, _Client_logLevel, _Client_logger, _Client_prefixUrl, _Client_timeoutMs, _Client_notionVersion, _Client_fetch, _Client_agent, _Client_userAgent, _Client_maxRetries, _Client_initialRetryDelayMs, _Client_maxRetryDelayMs;
|
|
13
|
+
var _Client_endpointMethods, _Client_auth, _Client_logLevel, _Client_logger, _Client_prefixUrl, _Client_timeoutMs, _Client_notionVersion, _Client_fetch, _Client_agent, _Client_userAgent, _Client_maxRetries, _Client_initialRetryDelayMs, _Client_maxRetryDelayMs, _Client_dangerouslyAllowBrowser;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const api_endpoint_methods_1 = require("./api-endpoint-methods");
|
|
15
16
|
const logging_1 = require("./logging");
|
|
16
17
|
const errors_1 = require("./errors");
|
|
17
18
|
const utils_1 = require("./utils");
|
|
@@ -20,9 +21,27 @@ const api_endpoints_1 = require("./api-endpoints");
|
|
|
20
21
|
const meeting_notes_1 = require("./api-endpoints/meeting-notes");
|
|
21
22
|
const package_json_1 = require("../package.json");
|
|
22
23
|
const START_CURSOR_PARAM_NAME = "start_cursor";
|
|
24
|
+
/**
|
|
25
|
+
* True inside a browser page, web worker, or service worker: the places where
|
|
26
|
+
* every visitor downloads the script, so a token in it is public. Node, Bun,
|
|
27
|
+
* Deno, and edge runtimes have neither `window.document` nor
|
|
28
|
+
* `WorkerGlobalScope`. Test runners that emulate a browser, such as jsdom,
|
|
29
|
+
* also count as a browser here.
|
|
30
|
+
*/
|
|
31
|
+
function isBrowserEnvironment() {
|
|
32
|
+
const maybeWindow = globalThis.window;
|
|
33
|
+
if (maybeWindow !== undefined && maybeWindow.document !== undefined) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return "WorkerGlobalScope" in globalThis;
|
|
37
|
+
}
|
|
23
38
|
class Client {
|
|
24
39
|
constructor(options) {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
41
|
+
_Client_endpointMethods.set(this, (0, api_endpoint_methods_1.createEndpointMethods)({
|
|
42
|
+
request: args => this.request(args),
|
|
43
|
+
warnUnknownParams: (args, endpoint) => this.warnUnknownParams(args, endpoint),
|
|
44
|
+
}));
|
|
26
45
|
_Client_auth.set(this, void 0);
|
|
27
46
|
_Client_logLevel.set(this, void 0);
|
|
28
47
|
_Client_logger.set(this, void 0);
|
|
@@ -35,106 +54,76 @@ class Client {
|
|
|
35
54
|
_Client_maxRetries.set(this, void 0);
|
|
36
55
|
_Client_initialRetryDelayMs.set(this, void 0);
|
|
37
56
|
_Client_maxRetryDelayMs.set(this, void 0);
|
|
57
|
+
_Client_dangerouslyAllowBrowser.set(this, void 0);
|
|
38
58
|
/*
|
|
39
59
|
* Notion API endpoints
|
|
40
60
|
*/
|
|
41
|
-
this.
|
|
61
|
+
this.plugins = {
|
|
62
|
+
list: __classPrivateFieldGet(this, _Client_endpointMethods, "f").plugins.list,
|
|
63
|
+
retrieve: (args) => __classPrivateFieldGet(this, _Client_endpointMethods, "f").plugins.retrieve({
|
|
64
|
+
...args,
|
|
65
|
+
// Plugin IDs can be tag IDs containing URL delimiters, not just UUIDs.
|
|
66
|
+
id: encodeURIComponent(args.id),
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
this.skills = __classPrivateFieldGet(this, _Client_endpointMethods, "f").skills;
|
|
70
|
+
this.agents = __classPrivateFieldGet(this, _Client_endpointMethods, "f").agents;
|
|
71
|
+
this.sessions = {
|
|
42
72
|
/**
|
|
43
|
-
* Retrieve
|
|
73
|
+
* Retrieve a session
|
|
44
74
|
*/
|
|
45
|
-
retrieve: (
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
75
|
+
retrieve: __classPrivateFieldGet(this, _Client_endpointMethods, "f").sessions.retrieve,
|
|
76
|
+
/**
|
|
77
|
+
* Update a session
|
|
78
|
+
*/
|
|
79
|
+
update: __classPrivateFieldGet(this, _Client_endpointMethods, "f").sessions.update,
|
|
80
|
+
/**
|
|
81
|
+
* Open a session stream
|
|
82
|
+
*/
|
|
83
|
+
stream: (args) => {
|
|
84
|
+
this.warnUnknownParams(args, api_endpoints_1.updateSessionStream);
|
|
85
|
+
return this.streamRequest({
|
|
86
|
+
path: api_endpoints_1.updateSessionStream.path(),
|
|
87
|
+
method: api_endpoints_1.updateSessionStream.method,
|
|
88
|
+
query: (0, utils_1.pick)(args, api_endpoints_1.updateSessionStream.queryParams),
|
|
89
|
+
body: (0, utils_1.pick)(args, api_endpoints_1.updateSessionStream.bodyParams),
|
|
90
|
+
headers: api_endpoints_1.updateSessionStream.headers,
|
|
52
91
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
53
|
-
});
|
|
92
|
+
}, parseSessionStreamEvent);
|
|
54
93
|
},
|
|
94
|
+
/**
|
|
95
|
+
* Cancel a session
|
|
96
|
+
*/
|
|
97
|
+
cancel: __classPrivateFieldGet(this, _Client_endpointMethods, "f").sessions.cancel,
|
|
98
|
+
/**
|
|
99
|
+
* Query sessions
|
|
100
|
+
*/
|
|
101
|
+
query: __classPrivateFieldGet(this, _Client_endpointMethods, "f").sessions.query,
|
|
102
|
+
/**
|
|
103
|
+
* Query session events
|
|
104
|
+
*/
|
|
105
|
+
queryEvents: __classPrivateFieldGet(this, _Client_endpointMethods, "f").sessions.queryEvents,
|
|
55
106
|
};
|
|
107
|
+
this.asyncTasks = __classPrivateFieldGet(this, _Client_endpointMethods, "f").asyncTasks;
|
|
56
108
|
this.blocks = {
|
|
57
109
|
/**
|
|
58
110
|
* Retrieve block
|
|
59
111
|
*/
|
|
60
|
-
retrieve: (
|
|
61
|
-
this.warnUnknownParams(args, api_endpoints_1.getBlock);
|
|
62
|
-
return this.request({
|
|
63
|
-
path: api_endpoints_1.getBlock.path(args),
|
|
64
|
-
method: api_endpoints_1.getBlock.method,
|
|
65
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getBlock.queryParams),
|
|
66
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getBlock.bodyParams),
|
|
67
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
68
|
-
});
|
|
69
|
-
},
|
|
112
|
+
retrieve: __classPrivateFieldGet(this, _Client_endpointMethods, "f").blocks.retrieve,
|
|
70
113
|
/**
|
|
71
114
|
* Update block
|
|
72
115
|
*/
|
|
73
|
-
update: (
|
|
74
|
-
this.warnUnknownParams(args, api_endpoints_1.updateBlock);
|
|
75
|
-
return this.request({
|
|
76
|
-
path: api_endpoints_1.updateBlock.path(args),
|
|
77
|
-
method: api_endpoints_1.updateBlock.method,
|
|
78
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.updateBlock.queryParams),
|
|
79
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.updateBlock.bodyParams),
|
|
80
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
81
|
-
});
|
|
82
|
-
},
|
|
116
|
+
update: __classPrivateFieldGet(this, _Client_endpointMethods, "f").blocks.update,
|
|
83
117
|
/**
|
|
84
118
|
* Delete block
|
|
85
119
|
*/
|
|
86
|
-
delete: (
|
|
87
|
-
|
|
88
|
-
return this.request({
|
|
89
|
-
path: api_endpoints_1.deleteBlock.path(args),
|
|
90
|
-
method: api_endpoints_1.deleteBlock.method,
|
|
91
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.deleteBlock.queryParams),
|
|
92
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.deleteBlock.bodyParams),
|
|
93
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
94
|
-
});
|
|
95
|
-
},
|
|
96
|
-
children: {
|
|
97
|
-
/**
|
|
98
|
-
* Append block children
|
|
99
|
-
*/
|
|
100
|
-
append: (args) => {
|
|
101
|
-
this.warnUnknownParams(args, api_endpoints_1.appendBlockChildren);
|
|
102
|
-
return this.request({
|
|
103
|
-
path: api_endpoints_1.appendBlockChildren.path(args),
|
|
104
|
-
method: api_endpoints_1.appendBlockChildren.method,
|
|
105
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.appendBlockChildren.queryParams),
|
|
106
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.appendBlockChildren.bodyParams),
|
|
107
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
108
|
-
});
|
|
109
|
-
},
|
|
110
|
-
/**
|
|
111
|
-
* Retrieve block children
|
|
112
|
-
*/
|
|
113
|
-
list: (args) => {
|
|
114
|
-
this.warnUnknownParams(args, api_endpoints_1.listBlockChildren);
|
|
115
|
-
return this.request({
|
|
116
|
-
path: api_endpoints_1.listBlockChildren.path(args),
|
|
117
|
-
method: api_endpoints_1.listBlockChildren.method,
|
|
118
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.listBlockChildren.queryParams),
|
|
119
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.listBlockChildren.bodyParams),
|
|
120
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
},
|
|
120
|
+
delete: __classPrivateFieldGet(this, _Client_endpointMethods, "f").blocks.delete,
|
|
121
|
+
children: __classPrivateFieldGet(this, _Client_endpointMethods, "f").blocks.children,
|
|
124
122
|
meetingNotes: {
|
|
125
123
|
/**
|
|
126
124
|
* Create a meeting note
|
|
127
125
|
*/
|
|
128
|
-
create: (
|
|
129
|
-
this.warnUnknownParams(args, meeting_notes_1.createMeetingNote);
|
|
130
|
-
return this.request({
|
|
131
|
-
path: meeting_notes_1.createMeetingNote.path(),
|
|
132
|
-
method: meeting_notes_1.createMeetingNote.method,
|
|
133
|
-
query: (0, utils_1.pick)(args, meeting_notes_1.createMeetingNote.queryParams),
|
|
134
|
-
body: (0, utils_1.pick)(args, meeting_notes_1.createMeetingNote.bodyParams),
|
|
135
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
136
|
-
});
|
|
137
|
-
},
|
|
126
|
+
create: __classPrivateFieldGet(this, _Client_endpointMethods, "f").blocks.meetingNotes.create,
|
|
138
127
|
/**
|
|
139
128
|
* Query meeting notes
|
|
140
129
|
*/
|
|
@@ -149,167 +138,25 @@ class Client {
|
|
|
149
138
|
},
|
|
150
139
|
},
|
|
151
140
|
};
|
|
152
|
-
this.databases =
|
|
153
|
-
|
|
154
|
-
* Retrieve a database
|
|
155
|
-
*/
|
|
156
|
-
retrieve: (args) => {
|
|
157
|
-
this.warnUnknownParams(args, api_endpoints_1.getDatabase);
|
|
158
|
-
return this.request({
|
|
159
|
-
path: api_endpoints_1.getDatabase.path(args),
|
|
160
|
-
method: api_endpoints_1.getDatabase.method,
|
|
161
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getDatabase.queryParams),
|
|
162
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getDatabase.bodyParams),
|
|
163
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
164
|
-
});
|
|
165
|
-
},
|
|
166
|
-
/**
|
|
167
|
-
* Create a database
|
|
168
|
-
*/
|
|
169
|
-
create: (args) => {
|
|
170
|
-
this.warnUnknownParams(args, api_endpoints_1.createDatabase);
|
|
171
|
-
return this.request({
|
|
172
|
-
path: api_endpoints_1.createDatabase.path(),
|
|
173
|
-
method: api_endpoints_1.createDatabase.method,
|
|
174
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.createDatabase.queryParams),
|
|
175
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.createDatabase.bodyParams),
|
|
176
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
177
|
-
});
|
|
178
|
-
},
|
|
179
|
-
/**
|
|
180
|
-
* Update a database
|
|
181
|
-
*/
|
|
182
|
-
update: (args) => {
|
|
183
|
-
this.warnUnknownParams(args, api_endpoints_1.updateDatabase);
|
|
184
|
-
return this.request({
|
|
185
|
-
path: api_endpoints_1.updateDatabase.path(args),
|
|
186
|
-
method: api_endpoints_1.updateDatabase.method,
|
|
187
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.updateDatabase.queryParams),
|
|
188
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.updateDatabase.bodyParams),
|
|
189
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
190
|
-
});
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
|
-
this.dataSources = {
|
|
194
|
-
/**
|
|
195
|
-
* Retrieve a data source
|
|
196
|
-
*/
|
|
197
|
-
retrieve: (args) => {
|
|
198
|
-
this.warnUnknownParams(args, api_endpoints_1.getDataSource);
|
|
199
|
-
return this.request({
|
|
200
|
-
path: api_endpoints_1.getDataSource.path(args),
|
|
201
|
-
method: api_endpoints_1.getDataSource.method,
|
|
202
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getDataSource.queryParams),
|
|
203
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getDataSource.bodyParams),
|
|
204
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
/**
|
|
208
|
-
* Query a data source
|
|
209
|
-
*/
|
|
210
|
-
query: (args) => {
|
|
211
|
-
this.warnUnknownParams(args, api_endpoints_1.queryDataSource);
|
|
212
|
-
return this.request({
|
|
213
|
-
path: api_endpoints_1.queryDataSource.path(args),
|
|
214
|
-
method: api_endpoints_1.queryDataSource.method,
|
|
215
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.queryDataSource.queryParams),
|
|
216
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.queryDataSource.bodyParams),
|
|
217
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
218
|
-
});
|
|
219
|
-
},
|
|
220
|
-
/**
|
|
221
|
-
* Create a data source
|
|
222
|
-
*/
|
|
223
|
-
create: (args) => {
|
|
224
|
-
this.warnUnknownParams(args, api_endpoints_1.createDataSource);
|
|
225
|
-
return this.request({
|
|
226
|
-
path: api_endpoints_1.createDataSource.path(),
|
|
227
|
-
method: api_endpoints_1.createDataSource.method,
|
|
228
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.createDataSource.queryParams),
|
|
229
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.createDataSource.bodyParams),
|
|
230
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
231
|
-
});
|
|
232
|
-
},
|
|
233
|
-
/**
|
|
234
|
-
* Update a data source
|
|
235
|
-
*/
|
|
236
|
-
update: (args) => {
|
|
237
|
-
this.warnUnknownParams(args, api_endpoints_1.updateDataSource);
|
|
238
|
-
return this.request({
|
|
239
|
-
path: api_endpoints_1.updateDataSource.path(args),
|
|
240
|
-
method: api_endpoints_1.updateDataSource.method,
|
|
241
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.updateDataSource.queryParams),
|
|
242
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.updateDataSource.bodyParams),
|
|
243
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
244
|
-
});
|
|
245
|
-
},
|
|
246
|
-
/**
|
|
247
|
-
* List page templates that are available for a data source
|
|
248
|
-
*/
|
|
249
|
-
listTemplates: (args) => {
|
|
250
|
-
this.warnUnknownParams(args, api_endpoints_1.listDataSourceTemplates);
|
|
251
|
-
return this.request({
|
|
252
|
-
path: api_endpoints_1.listDataSourceTemplates.path(args),
|
|
253
|
-
method: api_endpoints_1.listDataSourceTemplates.method,
|
|
254
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.listDataSourceTemplates.queryParams),
|
|
255
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.listDataSourceTemplates.bodyParams),
|
|
256
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
257
|
-
});
|
|
258
|
-
},
|
|
259
|
-
};
|
|
141
|
+
this.databases = __classPrivateFieldGet(this, _Client_endpointMethods, "f").databases;
|
|
142
|
+
this.dataSources = __classPrivateFieldGet(this, _Client_endpointMethods, "f").dataSources;
|
|
260
143
|
this.pages = {
|
|
261
144
|
/**
|
|
262
145
|
* Create a page
|
|
263
146
|
*/
|
|
264
|
-
create: (
|
|
265
|
-
this.warnUnknownParams(args, api_endpoints_1.createPage);
|
|
266
|
-
return this.request({
|
|
267
|
-
path: api_endpoints_1.createPage.path(),
|
|
268
|
-
method: api_endpoints_1.createPage.method,
|
|
269
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.createPage.queryParams),
|
|
270
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.createPage.bodyParams),
|
|
271
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
272
|
-
});
|
|
273
|
-
},
|
|
147
|
+
create: __classPrivateFieldGet(this, _Client_endpointMethods, "f").pages.create,
|
|
274
148
|
/**
|
|
275
149
|
* Retrieve a page
|
|
276
150
|
*/
|
|
277
|
-
retrieve: (
|
|
278
|
-
this.warnUnknownParams(args, api_endpoints_1.getPage);
|
|
279
|
-
return this.request({
|
|
280
|
-
path: api_endpoints_1.getPage.path(args),
|
|
281
|
-
method: api_endpoints_1.getPage.method,
|
|
282
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getPage.queryParams),
|
|
283
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getPage.bodyParams),
|
|
284
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
285
|
-
});
|
|
286
|
-
},
|
|
151
|
+
retrieve: __classPrivateFieldGet(this, _Client_endpointMethods, "f").pages.retrieve,
|
|
287
152
|
/**
|
|
288
153
|
* Update page properties
|
|
289
154
|
*/
|
|
290
|
-
update: (
|
|
291
|
-
this.warnUnknownParams(args, api_endpoints_1.updatePage);
|
|
292
|
-
return this.request({
|
|
293
|
-
path: api_endpoints_1.updatePage.path(args),
|
|
294
|
-
method: api_endpoints_1.updatePage.method,
|
|
295
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.updatePage.queryParams),
|
|
296
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.updatePage.bodyParams),
|
|
297
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
298
|
-
});
|
|
299
|
-
},
|
|
155
|
+
update: __classPrivateFieldGet(this, _Client_endpointMethods, "f").pages.update,
|
|
300
156
|
/**
|
|
301
157
|
* Move a page
|
|
302
158
|
*/
|
|
303
|
-
move: (
|
|
304
|
-
this.warnUnknownParams(args, api_endpoints_1.movePage);
|
|
305
|
-
return this.request({
|
|
306
|
-
path: api_endpoints_1.movePage.path(args),
|
|
307
|
-
method: api_endpoints_1.movePage.method,
|
|
308
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.movePage.queryParams),
|
|
309
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.movePage.bodyParams),
|
|
310
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
311
|
-
});
|
|
312
|
-
},
|
|
159
|
+
move: __classPrivateFieldGet(this, _Client_endpointMethods, "f").pages.move,
|
|
313
160
|
/**
|
|
314
161
|
* Retrieve a page as markdown
|
|
315
162
|
*/
|
|
@@ -334,63 +181,9 @@ class Client {
|
|
|
334
181
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
335
182
|
});
|
|
336
183
|
},
|
|
337
|
-
properties:
|
|
338
|
-
/**
|
|
339
|
-
* Retrieve page property
|
|
340
|
-
*/
|
|
341
|
-
retrieve: (args) => {
|
|
342
|
-
this.warnUnknownParams(args, api_endpoints_1.getPageProperty);
|
|
343
|
-
return this.request({
|
|
344
|
-
path: api_endpoints_1.getPageProperty.path(args),
|
|
345
|
-
method: api_endpoints_1.getPageProperty.method,
|
|
346
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getPageProperty.queryParams),
|
|
347
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getPageProperty.bodyParams),
|
|
348
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
349
|
-
});
|
|
350
|
-
},
|
|
351
|
-
},
|
|
352
|
-
};
|
|
353
|
-
this.users = {
|
|
354
|
-
/**
|
|
355
|
-
* Retrieve a user
|
|
356
|
-
*/
|
|
357
|
-
retrieve: (args) => {
|
|
358
|
-
this.warnUnknownParams(args, api_endpoints_1.getUser);
|
|
359
|
-
return this.request({
|
|
360
|
-
path: api_endpoints_1.getUser.path(args),
|
|
361
|
-
method: api_endpoints_1.getUser.method,
|
|
362
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getUser.queryParams),
|
|
363
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getUser.bodyParams),
|
|
364
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
365
|
-
});
|
|
366
|
-
},
|
|
367
|
-
/**
|
|
368
|
-
* List all users
|
|
369
|
-
*/
|
|
370
|
-
list: (args) => {
|
|
371
|
-
this.warnUnknownParams(args, api_endpoints_1.listUsers);
|
|
372
|
-
return this.request({
|
|
373
|
-
path: api_endpoints_1.listUsers.path(),
|
|
374
|
-
method: api_endpoints_1.listUsers.method,
|
|
375
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.listUsers.queryParams),
|
|
376
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.listUsers.bodyParams),
|
|
377
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
378
|
-
});
|
|
379
|
-
},
|
|
380
|
-
/**
|
|
381
|
-
* Get details about bot
|
|
382
|
-
*/
|
|
383
|
-
me: (args) => {
|
|
384
|
-
this.warnUnknownParams(args, api_endpoints_1.getSelf);
|
|
385
|
-
return this.request({
|
|
386
|
-
path: api_endpoints_1.getSelf.path(),
|
|
387
|
-
method: api_endpoints_1.getSelf.method,
|
|
388
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getSelf.queryParams),
|
|
389
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getSelf.bodyParams),
|
|
390
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
391
|
-
});
|
|
392
|
-
},
|
|
184
|
+
properties: __classPrivateFieldGet(this, _Client_endpointMethods, "f").pages.properties,
|
|
393
185
|
};
|
|
186
|
+
this.users = __classPrivateFieldGet(this, _Client_endpointMethods, "f").users;
|
|
394
187
|
this.customEmojis = {
|
|
395
188
|
/**
|
|
396
189
|
* List custom emojis
|
|
@@ -406,87 +199,12 @@ class Client {
|
|
|
406
199
|
});
|
|
407
200
|
},
|
|
408
201
|
};
|
|
409
|
-
this.comments =
|
|
410
|
-
/**
|
|
411
|
-
* Create a comment
|
|
412
|
-
*/
|
|
413
|
-
create: (args) => {
|
|
414
|
-
this.warnUnknownParams(args, api_endpoints_1.createComment);
|
|
415
|
-
return this.request({
|
|
416
|
-
path: api_endpoints_1.createComment.path(),
|
|
417
|
-
method: api_endpoints_1.createComment.method,
|
|
418
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.createComment.queryParams),
|
|
419
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.createComment.bodyParams),
|
|
420
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
421
|
-
});
|
|
422
|
-
},
|
|
423
|
-
/**
|
|
424
|
-
* List comments
|
|
425
|
-
*/
|
|
426
|
-
list: (args) => {
|
|
427
|
-
this.warnUnknownParams(args, api_endpoints_1.listComments);
|
|
428
|
-
return this.request({
|
|
429
|
-
path: api_endpoints_1.listComments.path(),
|
|
430
|
-
method: api_endpoints_1.listComments.method,
|
|
431
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.listComments.queryParams),
|
|
432
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.listComments.bodyParams),
|
|
433
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
434
|
-
});
|
|
435
|
-
},
|
|
436
|
-
/**
|
|
437
|
-
* Retrieve a comment
|
|
438
|
-
*/
|
|
439
|
-
retrieve: (args) => {
|
|
440
|
-
this.warnUnknownParams(args, api_endpoints_1.getComment);
|
|
441
|
-
return this.request({
|
|
442
|
-
path: api_endpoints_1.getComment.path(args),
|
|
443
|
-
method: api_endpoints_1.getComment.method,
|
|
444
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getComment.queryParams),
|
|
445
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getComment.bodyParams),
|
|
446
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
447
|
-
});
|
|
448
|
-
},
|
|
449
|
-
/**
|
|
450
|
-
* Update a comment
|
|
451
|
-
*/
|
|
452
|
-
update: (args) => {
|
|
453
|
-
this.warnUnknownParams(args, api_endpoints_1.updateComment);
|
|
454
|
-
return this.request({
|
|
455
|
-
path: api_endpoints_1.updateComment.path(args),
|
|
456
|
-
method: api_endpoints_1.updateComment.method,
|
|
457
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.updateComment.queryParams),
|
|
458
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.updateComment.bodyParams),
|
|
459
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
460
|
-
});
|
|
461
|
-
},
|
|
462
|
-
/**
|
|
463
|
-
* Delete a comment
|
|
464
|
-
*/
|
|
465
|
-
delete: (args) => {
|
|
466
|
-
this.warnUnknownParams(args, api_endpoints_1.deleteComment);
|
|
467
|
-
return this.request({
|
|
468
|
-
path: api_endpoints_1.deleteComment.path(args),
|
|
469
|
-
method: api_endpoints_1.deleteComment.method,
|
|
470
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.deleteComment.queryParams),
|
|
471
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.deleteComment.bodyParams),
|
|
472
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
473
|
-
});
|
|
474
|
-
},
|
|
475
|
-
};
|
|
202
|
+
this.comments = __classPrivateFieldGet(this, _Client_endpointMethods, "f").comments;
|
|
476
203
|
this.fileUploads = {
|
|
477
204
|
/**
|
|
478
205
|
* Create a file upload
|
|
479
206
|
*/
|
|
480
|
-
create: (
|
|
481
|
-
this.warnUnknownParams(args, api_endpoints_1.createFileUpload);
|
|
482
|
-
return this.request({
|
|
483
|
-
path: api_endpoints_1.createFileUpload.path(),
|
|
484
|
-
method: api_endpoints_1.createFileUpload.method,
|
|
485
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.createFileUpload.queryParams),
|
|
486
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.createFileUpload.bodyParams),
|
|
487
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
488
|
-
});
|
|
489
|
-
},
|
|
207
|
+
create: __classPrivateFieldGet(this, _Client_endpointMethods, "f").fileUploads.create,
|
|
490
208
|
/**
|
|
491
209
|
* Retrieve a file upload
|
|
492
210
|
*/
|
|
@@ -577,16 +295,7 @@ class Client {
|
|
|
577
295
|
/**
|
|
578
296
|
* Retrieve a view
|
|
579
297
|
*/
|
|
580
|
-
retrieve: (
|
|
581
|
-
this.warnUnknownParams(args, api_endpoints_1.getView);
|
|
582
|
-
return this.request({
|
|
583
|
-
path: api_endpoints_1.getView.path(args),
|
|
584
|
-
method: api_endpoints_1.getView.method,
|
|
585
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getView.queryParams),
|
|
586
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getView.bodyParams),
|
|
587
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
588
|
-
});
|
|
589
|
-
},
|
|
298
|
+
retrieve: __classPrivateFieldGet(this, _Client_endpointMethods, "f").views.retrieve,
|
|
590
299
|
/**
|
|
591
300
|
* Update a view
|
|
592
301
|
*/
|
|
@@ -608,29 +317,11 @@ class Client {
|
|
|
608
317
|
/**
|
|
609
318
|
* Delete a view
|
|
610
319
|
*/
|
|
611
|
-
delete: (
|
|
612
|
-
this.warnUnknownParams(args, api_endpoints_1.deleteView);
|
|
613
|
-
return this.request({
|
|
614
|
-
path: api_endpoints_1.deleteView.path(args),
|
|
615
|
-
method: api_endpoints_1.deleteView.method,
|
|
616
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.deleteView.queryParams),
|
|
617
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.deleteView.bodyParams),
|
|
618
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
619
|
-
});
|
|
620
|
-
},
|
|
320
|
+
delete: __classPrivateFieldGet(this, _Client_endpointMethods, "f").views.delete,
|
|
621
321
|
/**
|
|
622
322
|
* List views for a database
|
|
623
323
|
*/
|
|
624
|
-
list: (
|
|
625
|
-
this.warnUnknownParams(args, api_endpoints_1.listDatabaseViews);
|
|
626
|
-
return this.request({
|
|
627
|
-
path: api_endpoints_1.listDatabaseViews.path(),
|
|
628
|
-
method: api_endpoints_1.listDatabaseViews.method,
|
|
629
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.listDatabaseViews.queryParams),
|
|
630
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.listDatabaseViews.bodyParams),
|
|
631
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
632
|
-
});
|
|
633
|
-
},
|
|
324
|
+
list: __classPrivateFieldGet(this, _Client_endpointMethods, "f").views.list,
|
|
634
325
|
queries: {
|
|
635
326
|
/**
|
|
636
327
|
* Create a view query
|
|
@@ -647,44 +338,17 @@ class Client {
|
|
|
647
338
|
/**
|
|
648
339
|
* Get view query results
|
|
649
340
|
*/
|
|
650
|
-
results: (
|
|
651
|
-
this.warnUnknownParams(args, api_endpoints_1.getViewQueryResults);
|
|
652
|
-
return this.request({
|
|
653
|
-
path: api_endpoints_1.getViewQueryResults.path(args),
|
|
654
|
-
method: api_endpoints_1.getViewQueryResults.method,
|
|
655
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.getViewQueryResults.queryParams),
|
|
656
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.getViewQueryResults.bodyParams),
|
|
657
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
658
|
-
});
|
|
659
|
-
},
|
|
341
|
+
results: __classPrivateFieldGet(this, _Client_endpointMethods, "f").views.queries.results,
|
|
660
342
|
/**
|
|
661
343
|
* Delete a view query
|
|
662
344
|
*/
|
|
663
|
-
delete: (
|
|
664
|
-
this.warnUnknownParams(args, api_endpoints_1.deleteViewQuery);
|
|
665
|
-
return this.request({
|
|
666
|
-
path: api_endpoints_1.deleteViewQuery.path(args),
|
|
667
|
-
method: api_endpoints_1.deleteViewQuery.method,
|
|
668
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.deleteViewQuery.queryParams),
|
|
669
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.deleteViewQuery.bodyParams),
|
|
670
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
671
|
-
});
|
|
672
|
-
},
|
|
345
|
+
delete: __classPrivateFieldGet(this, _Client_endpointMethods, "f").views.queries.delete,
|
|
673
346
|
},
|
|
674
347
|
};
|
|
675
348
|
/**
|
|
676
349
|
* Search
|
|
677
350
|
*/
|
|
678
|
-
this.search = (
|
|
679
|
-
this.warnUnknownParams(args, api_endpoints_1.search);
|
|
680
|
-
return this.request({
|
|
681
|
-
path: api_endpoints_1.search.path(),
|
|
682
|
-
method: api_endpoints_1.search.method,
|
|
683
|
-
query: (0, utils_1.pick)(args, api_endpoints_1.search.queryParams),
|
|
684
|
-
body: (0, utils_1.pick)(args, api_endpoints_1.search.bodyParams),
|
|
685
|
-
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
686
|
-
});
|
|
687
|
-
};
|
|
351
|
+
this.search = __classPrivateFieldGet(this, _Client_endpointMethods, "f").search;
|
|
688
352
|
this.oauth = {
|
|
689
353
|
/**
|
|
690
354
|
* Get token
|
|
@@ -751,6 +415,10 @@ class Client {
|
|
|
751
415
|
__classPrivateFieldSet(this, _Client_initialRetryDelayMs, (_k = (_j = options === null || options === void 0 ? void 0 : options.retry) === null || _j === void 0 ? void 0 : _j.initialRetryDelayMs) !== null && _k !== void 0 ? _k : constants_1.DEFAULT_INITIAL_RETRY_DELAY_MS, "f");
|
|
752
416
|
__classPrivateFieldSet(this, _Client_maxRetryDelayMs, (_m = (_l = options === null || options === void 0 ? void 0 : options.retry) === null || _l === void 0 ? void 0 : _l.maxRetryDelayMs) !== null && _m !== void 0 ? _m : constants_1.DEFAULT_MAX_RETRY_DELAY_MS, "f");
|
|
753
417
|
}
|
|
418
|
+
__classPrivateFieldSet(this, _Client_dangerouslyAllowBrowser, (_o = options === null || options === void 0 ? void 0 : options.dangerouslyAllowBrowser) !== null && _o !== void 0 ? _o : false, "f");
|
|
419
|
+
if ((options === null || options === void 0 ? void 0 : options.auth) !== undefined) {
|
|
420
|
+
this.assertTokenAllowedHere();
|
|
421
|
+
}
|
|
754
422
|
}
|
|
755
423
|
/**
|
|
756
424
|
* Sends a request.
|
|
@@ -769,7 +437,76 @@ class Client {
|
|
|
769
437
|
path,
|
|
770
438
|
headers,
|
|
771
439
|
body: bodyAsJsonString !== null && bodyAsJsonString !== void 0 ? bodyAsJsonString : formData,
|
|
772
|
-
});
|
|
440
|
+
}, request => this.executeSingleRequest(request));
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Opens an SSE response and yields each parsed event as it arrives.
|
|
444
|
+
*/
|
|
445
|
+
async *streamRequest(args, parseEvent) {
|
|
446
|
+
var _a;
|
|
447
|
+
const { path, method, query, body, auth } = args;
|
|
448
|
+
(0, errors_1.validateRequestPath)(path);
|
|
449
|
+
this.log(logging_1.LogLevel.INFO, "stream request start", { method, path });
|
|
450
|
+
const url = this.buildRequestUrl(path, query);
|
|
451
|
+
const bodyAsJsonString = this.serializeBody(body);
|
|
452
|
+
const headers = this.buildRequestHeaders(args.headers, auth, bodyAsJsonString);
|
|
453
|
+
const response = await this.executeWithRetry({
|
|
454
|
+
url,
|
|
455
|
+
method,
|
|
456
|
+
path,
|
|
457
|
+
headers,
|
|
458
|
+
body: bodyAsJsonString,
|
|
459
|
+
}, request => this.executeSingleStreamRequest(request));
|
|
460
|
+
this.log(logging_1.LogLevel.INFO, "stream request opened", { method, path });
|
|
461
|
+
if (response.body === undefined || response.body === null) {
|
|
462
|
+
for (const frame of takeSseFrames({
|
|
463
|
+
content: await response.text(),
|
|
464
|
+
complete: true,
|
|
465
|
+
}).frames) {
|
|
466
|
+
yield parseEvent(frame);
|
|
467
|
+
}
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const reader = response.body.getReader();
|
|
471
|
+
const decoder = new TextDecoder();
|
|
472
|
+
let remaining = "";
|
|
473
|
+
let complete = false;
|
|
474
|
+
try {
|
|
475
|
+
while (!complete) {
|
|
476
|
+
const { done, value } = await reader.read();
|
|
477
|
+
if (done) {
|
|
478
|
+
complete = true;
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
if (value === undefined) {
|
|
482
|
+
throw new Error("SSE response body ended without a data chunk.");
|
|
483
|
+
}
|
|
484
|
+
const frames = takeSseFrames({
|
|
485
|
+
content: `${remaining}${decoder.decode(value, { stream: true })}`,
|
|
486
|
+
complete: false,
|
|
487
|
+
});
|
|
488
|
+
remaining = frames.remaining;
|
|
489
|
+
for (const frame of frames.frames) {
|
|
490
|
+
yield parseEvent(frame);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
for (const frame of takeSseFrames({
|
|
494
|
+
content: `${remaining}${decoder.decode()}`,
|
|
495
|
+
complete: true,
|
|
496
|
+
}).frames) {
|
|
497
|
+
yield parseEvent(frame);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
finally {
|
|
501
|
+
try {
|
|
502
|
+
if (!complete) {
|
|
503
|
+
await ((_a = reader.cancel) === null || _a === void 0 ? void 0 : _a.call(reader));
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
finally {
|
|
507
|
+
reader.releaseLock();
|
|
508
|
+
}
|
|
509
|
+
}
|
|
773
510
|
}
|
|
774
511
|
/**
|
|
775
512
|
* Builds the full URL with query parameters.
|
|
@@ -821,8 +558,12 @@ class Client {
|
|
|
821
558
|
...customHeaders,
|
|
822
559
|
...authorizationHeader,
|
|
823
560
|
"Notion-Version": __classPrivateFieldGet(this, _Client_notionVersion, "f"),
|
|
824
|
-
"user-agent": __classPrivateFieldGet(this, _Client_userAgent, "f"),
|
|
825
561
|
};
|
|
562
|
+
// Firefox and Safari send a custom user-agent, which the API's CORS
|
|
563
|
+
// preflight does not allow, so every browser request would fail.
|
|
564
|
+
if (!isBrowserEnvironment()) {
|
|
565
|
+
headers["user-agent"] = __classPrivateFieldGet(this, _Client_userAgent, "f");
|
|
566
|
+
}
|
|
826
567
|
if (bodyAsJsonString !== undefined) {
|
|
827
568
|
headers["content-type"] = "application/json";
|
|
828
569
|
}
|
|
@@ -832,6 +573,9 @@ class Client {
|
|
|
832
573
|
* Builds the authorization header based on auth type.
|
|
833
574
|
*/
|
|
834
575
|
buildAuthHeader(auth) {
|
|
576
|
+
if (auth !== undefined) {
|
|
577
|
+
this.assertTokenAllowedHere();
|
|
578
|
+
}
|
|
835
579
|
if (typeof auth === "object") {
|
|
836
580
|
const unencodedCredential = `${auth.client_id}:${auth.client_secret}`;
|
|
837
581
|
const encodedCredential = Buffer.from(unencodedCredential).toString("base64");
|
|
@@ -862,13 +606,13 @@ class Client {
|
|
|
862
606
|
/**
|
|
863
607
|
* Executes the request with retry logic.
|
|
864
608
|
*/
|
|
865
|
-
async executeWithRetry(args) {
|
|
609
|
+
async executeWithRetry(args, execute) {
|
|
866
610
|
const { url, method, path, headers, body } = args;
|
|
867
611
|
let attempt = 0;
|
|
868
612
|
// eslint-disable-next-line no-constant-condition
|
|
869
613
|
while (true) {
|
|
870
614
|
try {
|
|
871
|
-
return await
|
|
615
|
+
return await execute({
|
|
872
616
|
url,
|
|
873
617
|
method,
|
|
874
618
|
path,
|
|
@@ -920,6 +664,24 @@ class Client {
|
|
|
920
664
|
});
|
|
921
665
|
return responseJson;
|
|
922
666
|
}
|
|
667
|
+
/**
|
|
668
|
+
* Opens an SSE response without consuming its body. Retry orchestration is
|
|
669
|
+
* shared with JSON requests so only the initial, retryable HTTP failures are
|
|
670
|
+
* retried; once a stream has opened, its events are never replayed.
|
|
671
|
+
*/
|
|
672
|
+
async executeSingleStreamRequest(args) {
|
|
673
|
+
const { url, method, body } = args;
|
|
674
|
+
const response = await errors_1.RequestTimeoutError.rejectAfterTimeout(__classPrivateFieldGet(this, _Client_fetch, "f").call(this, url.toString(), {
|
|
675
|
+
method: method.toUpperCase(),
|
|
676
|
+
headers: args.headers,
|
|
677
|
+
body,
|
|
678
|
+
agent: __classPrivateFieldGet(this, _Client_agent, "f"),
|
|
679
|
+
}), __classPrivateFieldGet(this, _Client_timeoutMs, "f"));
|
|
680
|
+
if (!response.ok) {
|
|
681
|
+
throw (0, errors_1.buildRequestError)(response, await response.text());
|
|
682
|
+
}
|
|
683
|
+
return response;
|
|
684
|
+
}
|
|
923
685
|
/**
|
|
924
686
|
* Logs a request error with appropriate detail level.
|
|
925
687
|
*/
|
|
@@ -1024,8 +786,9 @@ class Client {
|
|
|
1024
786
|
*/
|
|
1025
787
|
warnUnknownParams(args, endpoint) {
|
|
1026
788
|
var _a;
|
|
1027
|
-
if (!args || typeof args !== "object")
|
|
789
|
+
if (!args || typeof args !== "object") {
|
|
1028
790
|
return;
|
|
791
|
+
}
|
|
1029
792
|
const unknownKeys = (0, utils_1.getUnknownParams)(args, endpoint);
|
|
1030
793
|
if (unknownKeys.length > 0) {
|
|
1031
794
|
this.log(logging_1.LogLevel.WARN, "unknown parameters were ignored", {
|
|
@@ -1050,6 +813,19 @@ class Client {
|
|
|
1050
813
|
__classPrivateFieldGet(this, _Client_logger, "f").call(this, level, message, extraInfo);
|
|
1051
814
|
}
|
|
1052
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* Blocks a token or client secret inside a browser unless the caller opted
|
|
818
|
+
* in. Covers both the constructor `auth` and per-request `auth`, since a
|
|
819
|
+
* page that asks the visitor to type a token usually uses the latter. A
|
|
820
|
+
* client without a token stays usable, for example behind a proxy that
|
|
821
|
+
* adds the token on a server.
|
|
822
|
+
*/
|
|
823
|
+
assertTokenAllowedHere() {
|
|
824
|
+
if (__classPrivateFieldGet(this, _Client_dangerouslyAllowBrowser, "f") || !isBrowserEnvironment()) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
throw new errors_1.BrowserTokenNotAllowedError();
|
|
828
|
+
}
|
|
1053
829
|
/**
|
|
1054
830
|
* Transforms an API key or access token into a headers object suitable for an HTTP request.
|
|
1055
831
|
*
|
|
@@ -1068,7 +844,75 @@ class Client {
|
|
|
1068
844
|
return headers;
|
|
1069
845
|
}
|
|
1070
846
|
}
|
|
1071
|
-
_Client_auth = new WeakMap(), _Client_logLevel = new WeakMap(), _Client_logger = new WeakMap(), _Client_prefixUrl = new WeakMap(), _Client_timeoutMs = new WeakMap(), _Client_notionVersion = new WeakMap(), _Client_fetch = new WeakMap(), _Client_agent = new WeakMap(), _Client_userAgent = new WeakMap(), _Client_maxRetries = new WeakMap(), _Client_initialRetryDelayMs = new WeakMap(), _Client_maxRetryDelayMs = new WeakMap();
|
|
847
|
+
_Client_endpointMethods = new WeakMap(), _Client_auth = new WeakMap(), _Client_logLevel = new WeakMap(), _Client_logger = new WeakMap(), _Client_prefixUrl = new WeakMap(), _Client_timeoutMs = new WeakMap(), _Client_notionVersion = new WeakMap(), _Client_fetch = new WeakMap(), _Client_agent = new WeakMap(), _Client_userAgent = new WeakMap(), _Client_maxRetries = new WeakMap(), _Client_initialRetryDelayMs = new WeakMap(), _Client_maxRetryDelayMs = new WeakMap(), _Client_dangerouslyAllowBrowser = new WeakMap();
|
|
1072
848
|
Client.defaultNotionVersion = "2025-09-03";
|
|
1073
849
|
exports.default = Client;
|
|
850
|
+
const sessionStreamEventTypes = new Set([
|
|
851
|
+
"session.snapshot",
|
|
852
|
+
"event.provisional",
|
|
853
|
+
"event.committed",
|
|
854
|
+
"stream.timeout",
|
|
855
|
+
"stream.end",
|
|
856
|
+
"stream.error",
|
|
857
|
+
]);
|
|
858
|
+
function takeSseFrames(args) {
|
|
859
|
+
const frames = [];
|
|
860
|
+
let remaining = args.content.replace(/\r\n/g, "\n");
|
|
861
|
+
let boundary = remaining.indexOf("\n\n");
|
|
862
|
+
while (boundary !== -1) {
|
|
863
|
+
const frame = parseSseFrame(remaining.slice(0, boundary));
|
|
864
|
+
if (frame !== undefined) {
|
|
865
|
+
frames.push(frame);
|
|
866
|
+
}
|
|
867
|
+
remaining = remaining.slice(boundary + 2);
|
|
868
|
+
boundary = remaining.indexOf("\n\n");
|
|
869
|
+
}
|
|
870
|
+
if (args.complete && remaining !== "") {
|
|
871
|
+
const frame = parseSseFrame(remaining);
|
|
872
|
+
if (frame !== undefined) {
|
|
873
|
+
frames.push(frame);
|
|
874
|
+
}
|
|
875
|
+
remaining = "";
|
|
876
|
+
}
|
|
877
|
+
return { frames, remaining };
|
|
878
|
+
}
|
|
879
|
+
function parseSseFrame(content) {
|
|
880
|
+
let eventName;
|
|
881
|
+
const dataLines = [];
|
|
882
|
+
for (const line of content.split("\n")) {
|
|
883
|
+
if (line.startsWith(":")) {
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
const colonIndex = line.indexOf(":");
|
|
887
|
+
if (colonIndex === -1) {
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
const field = line.slice(0, colonIndex);
|
|
891
|
+
const valueStart = line.charAt(colonIndex + 1) === " " ? colonIndex + 2 : colonIndex + 1;
|
|
892
|
+
const value = line.slice(valueStart);
|
|
893
|
+
if (field === "event") {
|
|
894
|
+
eventName = value;
|
|
895
|
+
}
|
|
896
|
+
else if (field === "data") {
|
|
897
|
+
dataLines.push(value);
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
if (dataLines.length === 0) {
|
|
901
|
+
return undefined;
|
|
902
|
+
}
|
|
903
|
+
if (eventName === undefined) {
|
|
904
|
+
throw new Error("Session stream event is missing its SSE event name.");
|
|
905
|
+
}
|
|
906
|
+
return { eventName, data: dataLines.join("\n") };
|
|
907
|
+
}
|
|
908
|
+
function parseSessionStreamEvent(frame) {
|
|
909
|
+
const event = JSON.parse(frame.data);
|
|
910
|
+
if (typeof event !== "object" ||
|
|
911
|
+
event === null ||
|
|
912
|
+
!sessionStreamEventTypes.has(event.type) ||
|
|
913
|
+
event.type !== frame.eventName) {
|
|
914
|
+
throw new Error("Session stream event does not match its SSE event name.");
|
|
915
|
+
}
|
|
916
|
+
return event;
|
|
917
|
+
}
|
|
1074
918
|
//# sourceMappingURL=Client.js.map
|