@notionhq/client 0.4.5 → 0.4.9
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/build/package.json +4 -3
- package/build/src/Client.js +41 -41
- package/build/src/Client.js.map +1 -1
- package/build/src/api-endpoints.d.ts +7205 -14160
- package/build/src/api-endpoints.d.ts.map +1 -1
- package/build/src/api-endpoints.js +3 -0
- package/build/src/api-endpoints.js.map +1 -1
- package/build/src/errors.js +2 -2
- package/build/src/errors.js.map +1 -1
- package/build/src/logging.js +1 -1
- package/build/src/logging.js.map +1 -1
- package/package.json +4 -3
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notionhq/client",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.9",
|
|
4
4
|
"description": "A simple and easy to use client for the Notion API",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12"
|
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
"main": "./build/src",
|
|
23
23
|
"scripts": {
|
|
24
24
|
"prepare": "npm run build",
|
|
25
|
-
"prepublishOnly": "npm run lint && npm run test",
|
|
25
|
+
"prepublishOnly": "npm run checkLoggedIn && npm run lint && npm run test",
|
|
26
26
|
"build": "tsc",
|
|
27
27
|
"prettier": "prettier --write .",
|
|
28
28
|
"lint": "prettier --check . && eslint . --ext .ts && cspell '**/*' ",
|
|
29
29
|
"test": "ava",
|
|
30
30
|
"check-links": "git ls-files | grep md$ | xargs -n 1 markdown-link-check",
|
|
31
31
|
"prebuild": "npm run clean",
|
|
32
|
-
"clean": "rm -rf ./build"
|
|
32
|
+
"clean": "rm -rf ./build",
|
|
33
|
+
"checkLoggedIn": "./scripts/verifyLoggedIn.sh"
|
|
33
34
|
},
|
|
34
35
|
"author": "",
|
|
35
36
|
"license": "MIT",
|
package/build/src/Client.js
CHANGED
|
@@ -41,8 +41,8 @@ class Client {
|
|
|
41
41
|
return this.request({
|
|
42
42
|
path: api_endpoints_1.getBlock.path(args),
|
|
43
43
|
method: api_endpoints_1.getBlock.method,
|
|
44
|
-
query:
|
|
45
|
-
body:
|
|
44
|
+
query: helpers_1.pick(args, api_endpoints_1.getBlock.queryParams),
|
|
45
|
+
body: helpers_1.pick(args, api_endpoints_1.getBlock.bodyParams),
|
|
46
46
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
47
47
|
});
|
|
48
48
|
},
|
|
@@ -53,8 +53,8 @@ class Client {
|
|
|
53
53
|
return this.request({
|
|
54
54
|
path: api_endpoints_1.updateBlock.path(args),
|
|
55
55
|
method: api_endpoints_1.updateBlock.method,
|
|
56
|
-
query:
|
|
57
|
-
body:
|
|
56
|
+
query: helpers_1.pick(args, api_endpoints_1.updateBlock.queryParams),
|
|
57
|
+
body: helpers_1.pick(args, api_endpoints_1.updateBlock.bodyParams),
|
|
58
58
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
59
59
|
});
|
|
60
60
|
},
|
|
@@ -65,8 +65,8 @@ class Client {
|
|
|
65
65
|
return this.request({
|
|
66
66
|
path: api_endpoints_1.deleteBlock.path(args),
|
|
67
67
|
method: api_endpoints_1.deleteBlock.method,
|
|
68
|
-
query:
|
|
69
|
-
body:
|
|
68
|
+
query: helpers_1.pick(args, api_endpoints_1.deleteBlock.queryParams),
|
|
69
|
+
body: helpers_1.pick(args, api_endpoints_1.deleteBlock.bodyParams),
|
|
70
70
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
71
71
|
});
|
|
72
72
|
},
|
|
@@ -78,8 +78,8 @@ class Client {
|
|
|
78
78
|
return this.request({
|
|
79
79
|
path: api_endpoints_1.appendBlockChildren.path(args),
|
|
80
80
|
method: api_endpoints_1.appendBlockChildren.method,
|
|
81
|
-
query:
|
|
82
|
-
body:
|
|
81
|
+
query: helpers_1.pick(args, api_endpoints_1.appendBlockChildren.queryParams),
|
|
82
|
+
body: helpers_1.pick(args, api_endpoints_1.appendBlockChildren.bodyParams),
|
|
83
83
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
84
84
|
});
|
|
85
85
|
},
|
|
@@ -90,8 +90,8 @@ class Client {
|
|
|
90
90
|
return this.request({
|
|
91
91
|
path: api_endpoints_1.listBlockChildren.path(args),
|
|
92
92
|
method: api_endpoints_1.listBlockChildren.method,
|
|
93
|
-
query:
|
|
94
|
-
body:
|
|
93
|
+
query: helpers_1.pick(args, api_endpoints_1.listBlockChildren.queryParams),
|
|
94
|
+
body: helpers_1.pick(args, api_endpoints_1.listBlockChildren.bodyParams),
|
|
95
95
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
96
96
|
});
|
|
97
97
|
},
|
|
@@ -107,8 +107,8 @@ class Client {
|
|
|
107
107
|
return this.request({
|
|
108
108
|
path: api_endpoints_1.listDatabases.path(),
|
|
109
109
|
method: api_endpoints_1.listDatabases.method,
|
|
110
|
-
query:
|
|
111
|
-
body:
|
|
110
|
+
query: helpers_1.pick(args, api_endpoints_1.listDatabases.queryParams),
|
|
111
|
+
body: helpers_1.pick(args, api_endpoints_1.listDatabases.bodyParams),
|
|
112
112
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
113
113
|
});
|
|
114
114
|
},
|
|
@@ -119,8 +119,8 @@ class Client {
|
|
|
119
119
|
return this.request({
|
|
120
120
|
path: api_endpoints_1.getDatabase.path(args),
|
|
121
121
|
method: api_endpoints_1.getDatabase.method,
|
|
122
|
-
query:
|
|
123
|
-
body:
|
|
122
|
+
query: helpers_1.pick(args, api_endpoints_1.getDatabase.queryParams),
|
|
123
|
+
body: helpers_1.pick(args, api_endpoints_1.getDatabase.bodyParams),
|
|
124
124
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
125
125
|
});
|
|
126
126
|
},
|
|
@@ -131,8 +131,8 @@ class Client {
|
|
|
131
131
|
return this.request({
|
|
132
132
|
path: api_endpoints_1.queryDatabase.path(args),
|
|
133
133
|
method: api_endpoints_1.queryDatabase.method,
|
|
134
|
-
query:
|
|
135
|
-
body:
|
|
134
|
+
query: helpers_1.pick(args, api_endpoints_1.queryDatabase.queryParams),
|
|
135
|
+
body: helpers_1.pick(args, api_endpoints_1.queryDatabase.bodyParams),
|
|
136
136
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
137
137
|
});
|
|
138
138
|
},
|
|
@@ -143,8 +143,8 @@ class Client {
|
|
|
143
143
|
return this.request({
|
|
144
144
|
path: api_endpoints_1.createDatabase.path(),
|
|
145
145
|
method: api_endpoints_1.createDatabase.method,
|
|
146
|
-
query:
|
|
147
|
-
body:
|
|
146
|
+
query: helpers_1.pick(args, api_endpoints_1.createDatabase.queryParams),
|
|
147
|
+
body: helpers_1.pick(args, api_endpoints_1.createDatabase.bodyParams),
|
|
148
148
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
149
149
|
});
|
|
150
150
|
},
|
|
@@ -155,8 +155,8 @@ class Client {
|
|
|
155
155
|
return this.request({
|
|
156
156
|
path: api_endpoints_1.updateDatabase.path(args),
|
|
157
157
|
method: api_endpoints_1.updateDatabase.method,
|
|
158
|
-
query:
|
|
159
|
-
body:
|
|
158
|
+
query: helpers_1.pick(args, api_endpoints_1.updateDatabase.queryParams),
|
|
159
|
+
body: helpers_1.pick(args, api_endpoints_1.updateDatabase.bodyParams),
|
|
160
160
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
161
161
|
});
|
|
162
162
|
},
|
|
@@ -169,8 +169,8 @@ class Client {
|
|
|
169
169
|
return this.request({
|
|
170
170
|
path: api_endpoints_1.createPage.path(),
|
|
171
171
|
method: api_endpoints_1.createPage.method,
|
|
172
|
-
query:
|
|
173
|
-
body:
|
|
172
|
+
query: helpers_1.pick(args, api_endpoints_1.createPage.queryParams),
|
|
173
|
+
body: helpers_1.pick(args, api_endpoints_1.createPage.bodyParams),
|
|
174
174
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
175
175
|
});
|
|
176
176
|
},
|
|
@@ -181,8 +181,8 @@ class Client {
|
|
|
181
181
|
return this.request({
|
|
182
182
|
path: api_endpoints_1.getPage.path(args),
|
|
183
183
|
method: api_endpoints_1.getPage.method,
|
|
184
|
-
query:
|
|
185
|
-
body:
|
|
184
|
+
query: helpers_1.pick(args, api_endpoints_1.getPage.queryParams),
|
|
185
|
+
body: helpers_1.pick(args, api_endpoints_1.getPage.bodyParams),
|
|
186
186
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
187
187
|
});
|
|
188
188
|
},
|
|
@@ -193,8 +193,8 @@ class Client {
|
|
|
193
193
|
return this.request({
|
|
194
194
|
path: api_endpoints_1.updatePage.path(args),
|
|
195
195
|
method: api_endpoints_1.updatePage.method,
|
|
196
|
-
query:
|
|
197
|
-
body:
|
|
196
|
+
query: helpers_1.pick(args, api_endpoints_1.updatePage.queryParams),
|
|
197
|
+
body: helpers_1.pick(args, api_endpoints_1.updatePage.bodyParams),
|
|
198
198
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
199
199
|
});
|
|
200
200
|
},
|
|
@@ -206,8 +206,8 @@ class Client {
|
|
|
206
206
|
return this.request({
|
|
207
207
|
path: api_endpoints_1.getPageProperty.path(args),
|
|
208
208
|
method: api_endpoints_1.getPageProperty.method,
|
|
209
|
-
query:
|
|
210
|
-
body:
|
|
209
|
+
query: helpers_1.pick(args, api_endpoints_1.getPageProperty.queryParams),
|
|
210
|
+
body: helpers_1.pick(args, api_endpoints_1.getPageProperty.bodyParams),
|
|
211
211
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
212
212
|
});
|
|
213
213
|
},
|
|
@@ -221,8 +221,8 @@ class Client {
|
|
|
221
221
|
return this.request({
|
|
222
222
|
path: api_endpoints_1.getUser.path(args),
|
|
223
223
|
method: api_endpoints_1.getUser.method,
|
|
224
|
-
query:
|
|
225
|
-
body:
|
|
224
|
+
query: helpers_1.pick(args, api_endpoints_1.getUser.queryParams),
|
|
225
|
+
body: helpers_1.pick(args, api_endpoints_1.getUser.bodyParams),
|
|
226
226
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
227
227
|
});
|
|
228
228
|
},
|
|
@@ -233,8 +233,8 @@ class Client {
|
|
|
233
233
|
return this.request({
|
|
234
234
|
path: api_endpoints_1.listUsers.path(),
|
|
235
235
|
method: api_endpoints_1.listUsers.method,
|
|
236
|
-
query:
|
|
237
|
-
body:
|
|
236
|
+
query: helpers_1.pick(args, api_endpoints_1.listUsers.queryParams),
|
|
237
|
+
body: helpers_1.pick(args, api_endpoints_1.listUsers.bodyParams),
|
|
238
238
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
239
239
|
});
|
|
240
240
|
},
|
|
@@ -245,15 +245,15 @@ class Client {
|
|
|
245
245
|
return this.request({
|
|
246
246
|
path: api_endpoints_1.getSelf.path(),
|
|
247
247
|
method: api_endpoints_1.getSelf.method,
|
|
248
|
-
query:
|
|
249
|
-
body:
|
|
248
|
+
query: helpers_1.pick(args, api_endpoints_1.getSelf.queryParams),
|
|
249
|
+
body: helpers_1.pick(args, api_endpoints_1.getSelf.bodyParams),
|
|
250
250
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
251
251
|
});
|
|
252
252
|
},
|
|
253
253
|
};
|
|
254
254
|
__classPrivateFieldSet(this, _Client_auth, options === null || options === void 0 ? void 0 : options.auth, "f");
|
|
255
255
|
__classPrivateFieldSet(this, _Client_logLevel, (_a = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _a !== void 0 ? _a : logging_1.LogLevel.WARN, "f");
|
|
256
|
-
__classPrivateFieldSet(this, _Client_logger, (_b = options === null || options === void 0 ? void 0 : options.logger) !== null && _b !== void 0 ? _b :
|
|
256
|
+
__classPrivateFieldSet(this, _Client_logger, (_b = options === null || options === void 0 ? void 0 : options.logger) !== null && _b !== void 0 ? _b : logging_1.makeConsoleLogger(package_json_1.name), "f");
|
|
257
257
|
__classPrivateFieldSet(this, _Client_prefixUrl, ((_c = options === null || options === void 0 ? void 0 : options.baseUrl) !== null && _c !== void 0 ? _c : "https://api.notion.com") + "/v1/", "f");
|
|
258
258
|
__classPrivateFieldSet(this, _Client_timeoutMs, (_d = options === null || options === void 0 ? void 0 : options.timeoutMs) !== null && _d !== void 0 ? _d : 60000, "f");
|
|
259
259
|
__classPrivateFieldSet(this, _Client_notionVersion, (_e = options === null || options === void 0 ? void 0 : options.notionVersion) !== null && _e !== void 0 ? _e : Client.defaultNotionVersion, "f");
|
|
@@ -301,14 +301,14 @@ class Client {
|
|
|
301
301
|
}), __classPrivateFieldGet(this, _Client_timeoutMs, "f"));
|
|
302
302
|
const responseText = await response.text();
|
|
303
303
|
if (!response.ok) {
|
|
304
|
-
throw
|
|
304
|
+
throw errors_1.buildRequestError(response, responseText);
|
|
305
305
|
}
|
|
306
306
|
const responseJson = JSON.parse(responseText);
|
|
307
307
|
this.log(logging_1.LogLevel.INFO, `request success`, { method, path });
|
|
308
308
|
return responseJson;
|
|
309
309
|
}
|
|
310
310
|
catch (error) {
|
|
311
|
-
if (!
|
|
311
|
+
if (!errors_1.isNotionClientError(error)) {
|
|
312
312
|
throw error;
|
|
313
313
|
}
|
|
314
314
|
// Log the error if it's one of our known error types
|
|
@@ -316,7 +316,7 @@ class Client {
|
|
|
316
316
|
code: error.code,
|
|
317
317
|
message: error.message,
|
|
318
318
|
});
|
|
319
|
-
if (
|
|
319
|
+
if (errors_1.isHTTPResponseError(error)) {
|
|
320
320
|
// The response body may contain sensitive information so it is logged separately at the DEBUG level
|
|
321
321
|
this.log(logging_1.LogLevel.DEBUG, `failed response body`, {
|
|
322
322
|
body: error.body,
|
|
@@ -332,8 +332,8 @@ class Client {
|
|
|
332
332
|
return this.request({
|
|
333
333
|
path: api_endpoints_1.search.path(),
|
|
334
334
|
method: api_endpoints_1.search.method,
|
|
335
|
-
query:
|
|
336
|
-
body:
|
|
335
|
+
query: helpers_1.pick(args, api_endpoints_1.search.queryParams),
|
|
336
|
+
body: helpers_1.pick(args, api_endpoints_1.search.bodyParams),
|
|
337
337
|
auth: args === null || args === void 0 ? void 0 : args.auth,
|
|
338
338
|
});
|
|
339
339
|
}
|
|
@@ -344,7 +344,7 @@ class Client {
|
|
|
344
344
|
* @param args Arguments to send to the console
|
|
345
345
|
*/
|
|
346
346
|
log(level, message, extraInfo) {
|
|
347
|
-
if (
|
|
347
|
+
if (logging_1.logLevelSeverity(level) >= logging_1.logLevelSeverity(__classPrivateFieldGet(this, _Client_logLevel, "f"))) {
|
|
348
348
|
__classPrivateFieldGet(this, _Client_logger, "f").call(this, level, message, extraInfo);
|
|
349
349
|
}
|
|
350
350
|
}
|
package/build/src/Client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,uCAKkB;AAClB,qCAKiB;AACjB,uCAAgC;AAChC,mDAuDwB;AACxB,2CAAkC;AAClC,kDAGwB;AAuBxB,MAAqB,MAAM;IAazB,YAAmB,OAAuB;;QAZ1C,+BAAc;QACd,mCAAmB;QACnB,iCAAe;QACf,oCAAkB;QAClB,oCAAkB;QAClB,wCAAsB;QACtB,gCAAsB;QACtB,gCAAyB;QACzB,oCAAkB;QAmGlB;;WAEG;QAEa,WAAM,GAAG;YACvB;;eAEG;YACH,QAAQ,EAAE,CACR,IAAkC,EACP,EAAE;gBAC7B,OAAO,IAAI,CAAC,OAAO,CAAmB;oBACpC,IAAI,EAAE,wBAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;oBACzB,MAAM,EAAE,wBAAQ,CAAC,MAAM;oBACvB,KAAK,EAAE,IAAA,cAAI,EAAC,IAAI,EAAE,wBAAQ,CAAC,WAAW,CAAC;oBACvC,IAAI,EAAE,IAAA,cAAI,EAAC,IAAI,EAAE,wBAAQ,CAAC,UAAU,CAAC;oBACrC,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI;iBACjB,CAAC,CAAA;YACJ,CAAC;YAED;;eAEG;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1C,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,eAAe,EAAE,CAAA;SACvD;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;;AAhaH,yBAiaC;;AAtZiB,2BAAoB,GAAG,YAAY,CAAA","sourcesContent":["import type { Agent } from \"http\"\nimport {\n Logger,\n LogLevel,\n logLevelSeverity,\n makeConsoleLogger,\n} from \"./logging\"\nimport {\n buildRequestError,\n isHTTPResponseError,\n isNotionClientError,\n RequestTimeoutError,\n} from \"./errors\"\nimport { pick } from \"./helpers\"\nimport {\n GetBlockParameters,\n GetBlockResponse,\n getBlock,\n UpdateBlockParameters,\n UpdateBlockResponse,\n updateBlock,\n DeleteBlockParameters,\n DeleteBlockResponse,\n deleteBlock,\n AppendBlockChildrenParameters,\n AppendBlockChildrenResponse,\n appendBlockChildren,\n ListBlockChildrenParameters,\n ListBlockChildrenResponse,\n listBlockChildren,\n ListDatabasesParameters,\n ListDatabasesResponse,\n listDatabases,\n GetDatabaseParameters,\n GetDatabaseResponse,\n getDatabase,\n QueryDatabaseParameters,\n QueryDatabaseResponse,\n queryDatabase,\n CreateDatabaseParameters,\n CreateDatabaseResponse,\n createDatabase,\n UpdateDatabaseParameters,\n UpdateDatabaseResponse,\n updateDatabase,\n CreatePageParameters,\n CreatePageResponse,\n createPage,\n GetPageParameters,\n GetPageResponse,\n getPage,\n UpdatePageParameters,\n UpdatePageResponse,\n updatePage,\n GetUserParameters,\n GetUserResponse,\n getUser,\n ListUsersParameters,\n ListUsersResponse,\n listUsers,\n SearchParameters,\n SearchResponse,\n search,\n GetSelfParameters,\n GetSelfResponse,\n getSelf,\n GetPagePropertyParameters,\n GetPagePropertyResponse,\n getPageProperty,\n} from \"./api-endpoints\"\nimport nodeFetch from \"node-fetch\"\nimport {\n version as PACKAGE_VERSION,\n name as PACKAGE_NAME,\n} from \"../package.json\"\nimport { SupportedFetch } from \"./fetch-types\"\n\nexport interface ClientOptions {\n auth?: string\n timeoutMs?: number\n baseUrl?: string\n logLevel?: LogLevel\n logger?: Logger\n notionVersion?: string\n fetch?: SupportedFetch\n /** Silently ignored in the browser */\n agent?: Agent\n}\n\nexport interface RequestParameters {\n path: string\n method: Method\n query?: QueryParams\n body?: Record<string, unknown>\n auth?: string\n}\n\nexport default class Client {\n #auth?: string\n #logLevel: LogLevel\n #logger: Logger\n #prefixUrl: string\n #timeoutMs: number\n #notionVersion: string\n #fetch: SupportedFetch\n #agent: Agent | undefined\n #userAgent: string\n\n static readonly defaultNotionVersion = \"2021-08-16\"\n\n public constructor(options?: ClientOptions) {\n this.#auth = options?.auth\n this.#logLevel = options?.logLevel ?? LogLevel.WARN\n this.#logger = options?.logger ?? makeConsoleLogger(PACKAGE_NAME)\n this.#prefixUrl = (options?.baseUrl ?? \"https://api.notion.com\") + \"/v1/\"\n this.#timeoutMs = options?.timeoutMs ?? 60_000\n this.#notionVersion = options?.notionVersion ?? Client.defaultNotionVersion\n this.#fetch = options?.fetch ?? nodeFetch\n this.#agent = options?.agent\n this.#userAgent = `notionhq-client/${PACKAGE_VERSION}`\n }\n\n /**\n * Sends a request.\n *\n * @param path\n * @param method\n * @param query\n * @param body\n * @returns\n */\n public async request<ResponseBody>({\n path,\n method,\n query,\n body,\n auth,\n }: RequestParameters): Promise<ResponseBody> {\n this.log(LogLevel.INFO, \"request start\", { method, path })\n\n // If the body is empty, don't send the body in the HTTP request\n const bodyAsJsonString =\n !body || Object.entries(body).length === 0\n ? undefined\n : JSON.stringify(body)\n\n const url = new URL(`${this.#prefixUrl}${path}`)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) {\n url.searchParams.append(key, String(value))\n }\n }\n }\n\n const headers: Record<string, string> = {\n ...this.authAsHeaders(auth),\n \"Notion-Version\": this.#notionVersion,\n \"user-agent\": this.#userAgent,\n }\n\n if (bodyAsJsonString !== undefined) {\n headers[\"content-type\"] = \"application/json\"\n }\n try {\n const response = await RequestTimeoutError.rejectAfterTimeout(\n this.#fetch(url.toString(), {\n method,\n headers,\n body: bodyAsJsonString,\n agent: this.#agent,\n }),\n this.#timeoutMs\n )\n\n const responseText = await response.text()\n if (!response.ok) {\n throw buildRequestError(response, responseText)\n }\n\n const responseJson: ResponseBody = JSON.parse(responseText)\n this.log(LogLevel.INFO, `request success`, { method, path })\n return responseJson\n } catch (error: unknown) {\n if (!isNotionClientError(error)) {\n throw error\n }\n\n // Log the error if it's one of our known error types\n this.log(LogLevel.WARN, `request fail`, {\n code: error.code,\n message: error.message,\n })\n\n if (isHTTPResponseError(error)) {\n // The response body may contain sensitive information so it is logged separately at the DEBUG level\n this.log(LogLevel.DEBUG, `failed response body`, {\n body: error.body,\n })\n }\n\n throw error\n }\n }\n\n /*\n * Notion API endpoints\n */\n\n public readonly blocks = {\n /**\n * Retrieve block\n */\n retrieve: (\n args: WithAuth<GetBlockParameters>\n ): Promise<GetBlockResponse> => {\n return this.request<GetBlockResponse>({\n path: getBlock.path(args),\n method: getBlock.method,\n query: pick(args, getBlock.queryParams),\n body: pick(args, getBlock.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Update block\n */\n update: (\n args: WithAuth<UpdateBlockParameters>\n ): Promise<UpdateBlockResponse> => {\n return this.request<UpdateBlockResponse>({\n path: updateBlock.path(args),\n method: updateBlock.method,\n query: pick(args, updateBlock.queryParams),\n body: pick(args, updateBlock.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Delete block\n */\n delete: (\n args: WithAuth<DeleteBlockParameters>\n ): Promise<DeleteBlockResponse> => {\n return this.request<DeleteBlockResponse>({\n path: deleteBlock.path(args),\n method: deleteBlock.method,\n query: pick(args, deleteBlock.queryParams),\n body: pick(args, deleteBlock.bodyParams),\n auth: args?.auth,\n })\n },\n children: {\n /**\n * Append block children\n */\n append: (\n args: WithAuth<AppendBlockChildrenParameters>\n ): Promise<AppendBlockChildrenResponse> => {\n return this.request<AppendBlockChildrenResponse>({\n path: appendBlockChildren.path(args),\n method: appendBlockChildren.method,\n query: pick(args, appendBlockChildren.queryParams),\n body: pick(args, appendBlockChildren.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Retrieve block children\n */\n list: (\n args: WithAuth<ListBlockChildrenParameters>\n ): Promise<ListBlockChildrenResponse> => {\n return this.request<ListBlockChildrenResponse>({\n path: listBlockChildren.path(args),\n method: listBlockChildren.method,\n query: pick(args, listBlockChildren.queryParams),\n body: pick(args, listBlockChildren.bodyParams),\n auth: args?.auth,\n })\n },\n },\n }\n\n public readonly databases = {\n /**\n * List databases\n *\n * @deprecated Please use `search`\n */\n list: (\n args: WithAuth<ListDatabasesParameters>\n ): Promise<ListDatabasesResponse> => {\n return this.request<ListDatabasesResponse>({\n path: listDatabases.path(),\n method: listDatabases.method,\n query: pick(args, listDatabases.queryParams),\n body: pick(args, listDatabases.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Retrieve a database\n */\n retrieve: (\n args: WithAuth<GetDatabaseParameters>\n ): Promise<GetDatabaseResponse> => {\n return this.request<GetDatabaseResponse>({\n path: getDatabase.path(args),\n method: getDatabase.method,\n query: pick(args, getDatabase.queryParams),\n body: pick(args, getDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Query a database\n */\n query: (\n args: WithAuth<QueryDatabaseParameters>\n ): Promise<QueryDatabaseResponse> => {\n return this.request<QueryDatabaseResponse>({\n path: queryDatabase.path(args),\n method: queryDatabase.method,\n query: pick(args, queryDatabase.queryParams),\n body: pick(args, queryDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Create a database\n */\n create: (\n args: WithAuth<CreateDatabaseParameters>\n ): Promise<CreateDatabaseResponse> => {\n return this.request<CreateDatabaseResponse>({\n path: createDatabase.path(),\n method: createDatabase.method,\n query: pick(args, createDatabase.queryParams),\n body: pick(args, createDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Update a database\n */\n update: (\n args: WithAuth<UpdateDatabaseParameters>\n ): Promise<UpdateDatabaseResponse> => {\n return this.request<UpdateDatabaseResponse>({\n path: updateDatabase.path(args),\n method: updateDatabase.method,\n query: pick(args, updateDatabase.queryParams),\n body: pick(args, updateDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n }\n\n public readonly pages = {\n /**\n * Create a page\n */\n create: (\n args: WithAuth<CreatePageParameters>\n ): Promise<CreatePageResponse> => {\n return this.request<CreatePageResponse>({\n path: createPage.path(),\n method: createPage.method,\n query: pick(args, createPage.queryParams),\n body: pick(args, createPage.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Retrieve a page\n */\n retrieve: (args: WithAuth<GetPageParameters>): Promise<GetPageResponse> => {\n return this.request<GetPageResponse>({\n path: getPage.path(args),\n method: getPage.method,\n query: pick(args, getPage.queryParams),\n body: pick(args, getPage.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Update page properties\n */\n update: (\n args: WithAuth<UpdatePageParameters>\n ): Promise<UpdatePageResponse> => {\n return this.request<UpdatePageResponse>({\n path: updatePage.path(args),\n method: updatePage.method,\n query: pick(args, updatePage.queryParams),\n body: pick(args, updatePage.bodyParams),\n auth: args?.auth,\n })\n },\n properties: {\n /**\n * Retrieve page property\n */\n retrieve: (\n args: WithAuth<GetPagePropertyParameters>\n ): Promise<GetPagePropertyResponse> => {\n return this.request<GetPagePropertyResponse>({\n path: getPageProperty.path(args),\n method: getPageProperty.method,\n query: pick(args, getPageProperty.queryParams),\n body: pick(args, getPageProperty.bodyParams),\n auth: args?.auth,\n })\n },\n },\n }\n\n public readonly users = {\n /**\n * Retrieve a user\n */\n retrieve: (args: WithAuth<GetUserParameters>): Promise<GetUserResponse> => {\n return this.request<GetUserResponse>({\n path: getUser.path(args),\n method: getUser.method,\n query: pick(args, getUser.queryParams),\n body: pick(args, getUser.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * List all users\n */\n list: (args: WithAuth<ListUsersParameters>): Promise<ListUsersResponse> => {\n return this.request<ListUsersResponse>({\n path: listUsers.path(),\n method: listUsers.method,\n query: pick(args, listUsers.queryParams),\n body: pick(args, listUsers.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Get details about bot\n */\n me: (args: WithAuth<GetSelfParameters>): Promise<GetSelfResponse> => {\n return this.request<GetSelfResponse>({\n path: getSelf.path(),\n method: getSelf.method,\n query: pick(args, getSelf.queryParams),\n body: pick(args, getSelf.bodyParams),\n auth: args?.auth,\n })\n },\n }\n\n /**\n * Search\n */\n public search(args: WithAuth<SearchParameters>): Promise<SearchResponse> {\n return this.request<SearchResponse>({\n path: search.path(),\n method: search.method,\n query: pick(args, search.queryParams),\n body: pick(args, search.bodyParams),\n auth: args?.auth,\n })\n }\n\n /**\n * Emits a log message to the console.\n *\n * @param level The level for this message\n * @param args Arguments to send to the console\n */\n private log(\n level: LogLevel,\n message: string,\n extraInfo: Record<string, unknown>\n ) {\n if (logLevelSeverity(level) >= logLevelSeverity(this.#logLevel)) {\n this.#logger(level, message, extraInfo)\n }\n }\n\n /**\n * Transforms an API key or access token into a headers object suitable for an HTTP request.\n *\n * This method uses the instance's value as the default when the input is undefined. If neither are defined, it returns\n * an empty object\n *\n * @param auth API key or access token\n * @returns headers key-value object\n */\n private authAsHeaders(auth?: string): Record<string, string> {\n const headers: Record<string, string> = {}\n const authHeaderValue = auth ?? this.#auth\n if (authHeaderValue !== undefined) {\n headers[\"authorization\"] = `Bearer ${authHeaderValue}`\n }\n return headers\n }\n}\n\n/*\n * Type aliases to support the generic request interface.\n */\ntype Method = \"get\" | \"post\" | \"patch\" | \"delete\"\ntype QueryParams = Record<string, string | number> | URLSearchParams\n\ntype WithAuth<P> = P & { auth?: string }\n"]}
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,uCAKkB;AAClB,qCAKiB;AACjB,uCAAgC;AAChC,mDAuDwB;AACxB,2CAAkC;AAClC,kDAGwB;AAuBxB,MAAqB,MAAM;IAazB,YAAm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AElC,IAAI,0BAAgB,CAAC,KAAK,CAAC,IAAI,0BAAgB,CAAC,uBAAA,IAAI,wBAAU,CAAC,EAAE;YAC/D,uBAAA,IAAI,sBAAQ,MAAZ,IAAI,EAAS,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;SACxC;IACH,CAAC;IAED;;;;;;;;OAQG;IACK,aAAa,CAAC,IAAa;QACjC,MAAM,OAAO,GAA2B,EAAE,CAAA;QAC1C,MAAM,eAAe,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,uBAAA,IAAI,oBAAM,CAAA;QAC1C,IAAI,eAAe,KAAK,SAAS,EAAE;YACjC,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,eAAe,EAAE,CAAA;SACvD;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;;AAhaH,yBAiaC;;AAtZiB,2BAAoB,GAAG,YAAY,CAAA","sourcesContent":["import type { Agent } from \"http\"\nimport {\n Logger,\n LogLevel,\n logLevelSeverity,\n makeConsoleLogger,\n} from \"./logging\"\nimport {\n buildRequestError,\n isHTTPResponseError,\n isNotionClientError,\n RequestTimeoutError,\n} from \"./errors\"\nimport { pick } from \"./helpers\"\nimport {\n GetBlockParameters,\n GetBlockResponse,\n getBlock,\n UpdateBlockParameters,\n UpdateBlockResponse,\n updateBlock,\n DeleteBlockParameters,\n DeleteBlockResponse,\n deleteBlock,\n AppendBlockChildrenParameters,\n AppendBlockChildrenResponse,\n appendBlockChildren,\n ListBlockChildrenParameters,\n ListBlockChildrenResponse,\n listBlockChildren,\n ListDatabasesParameters,\n ListDatabasesResponse,\n listDatabases,\n GetDatabaseParameters,\n GetDatabaseResponse,\n getDatabase,\n QueryDatabaseParameters,\n QueryDatabaseResponse,\n queryDatabase,\n CreateDatabaseParameters,\n CreateDatabaseResponse,\n createDatabase,\n UpdateDatabaseParameters,\n UpdateDatabaseResponse,\n updateDatabase,\n CreatePageParameters,\n CreatePageResponse,\n createPage,\n GetPageParameters,\n GetPageResponse,\n getPage,\n UpdatePageParameters,\n UpdatePageResponse,\n updatePage,\n GetUserParameters,\n GetUserResponse,\n getUser,\n ListUsersParameters,\n ListUsersResponse,\n listUsers,\n SearchParameters,\n SearchResponse,\n search,\n GetSelfParameters,\n GetSelfResponse,\n getSelf,\n GetPagePropertyParameters,\n GetPagePropertyResponse,\n getPageProperty,\n} from \"./api-endpoints\"\nimport nodeFetch from \"node-fetch\"\nimport {\n version as PACKAGE_VERSION,\n name as PACKAGE_NAME,\n} from \"../package.json\"\nimport { SupportedFetch } from \"./fetch-types\"\n\nexport interface ClientOptions {\n auth?: string\n timeoutMs?: number\n baseUrl?: string\n logLevel?: LogLevel\n logger?: Logger\n notionVersion?: string\n fetch?: SupportedFetch\n /** Silently ignored in the browser */\n agent?: Agent\n}\n\nexport interface RequestParameters {\n path: string\n method: Method\n query?: QueryParams\n body?: Record<string, unknown>\n auth?: string\n}\n\nexport default class Client {\n #auth?: string\n #logLevel: LogLevel\n #logger: Logger\n #prefixUrl: string\n #timeoutMs: number\n #notionVersion: string\n #fetch: SupportedFetch\n #agent: Agent | undefined\n #userAgent: string\n\n static readonly defaultNotionVersion = \"2021-08-16\"\n\n public constructor(options?: ClientOptions) {\n this.#auth = options?.auth\n this.#logLevel = options?.logLevel ?? LogLevel.WARN\n this.#logger = options?.logger ?? makeConsoleLogger(PACKAGE_NAME)\n this.#prefixUrl = (options?.baseUrl ?? \"https://api.notion.com\") + \"/v1/\"\n this.#timeoutMs = options?.timeoutMs ?? 60_000\n this.#notionVersion = options?.notionVersion ?? Client.defaultNotionVersion\n this.#fetch = options?.fetch ?? nodeFetch\n this.#agent = options?.agent\n this.#userAgent = `notionhq-client/${PACKAGE_VERSION}`\n }\n\n /**\n * Sends a request.\n *\n * @param path\n * @param method\n * @param query\n * @param body\n * @returns\n */\n public async request<ResponseBody>({\n path,\n method,\n query,\n body,\n auth,\n }: RequestParameters): Promise<ResponseBody> {\n this.log(LogLevel.INFO, \"request start\", { method, path })\n\n // If the body is empty, don't send the body in the HTTP request\n const bodyAsJsonString =\n !body || Object.entries(body).length === 0\n ? undefined\n : JSON.stringify(body)\n\n const url = new URL(`${this.#prefixUrl}${path}`)\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) {\n url.searchParams.append(key, String(value))\n }\n }\n }\n\n const headers: Record<string, string> = {\n ...this.authAsHeaders(auth),\n \"Notion-Version\": this.#notionVersion,\n \"user-agent\": this.#userAgent,\n }\n\n if (bodyAsJsonString !== undefined) {\n headers[\"content-type\"] = \"application/json\"\n }\n try {\n const response = await RequestTimeoutError.rejectAfterTimeout(\n this.#fetch(url.toString(), {\n method,\n headers,\n body: bodyAsJsonString,\n agent: this.#agent,\n }),\n this.#timeoutMs\n )\n\n const responseText = await response.text()\n if (!response.ok) {\n throw buildRequestError(response, responseText)\n }\n\n const responseJson: ResponseBody = JSON.parse(responseText)\n this.log(LogLevel.INFO, `request success`, { method, path })\n return responseJson\n } catch (error: unknown) {\n if (!isNotionClientError(error)) {\n throw error\n }\n\n // Log the error if it's one of our known error types\n this.log(LogLevel.WARN, `request fail`, {\n code: error.code,\n message: error.message,\n })\n\n if (isHTTPResponseError(error)) {\n // The response body may contain sensitive information so it is logged separately at the DEBUG level\n this.log(LogLevel.DEBUG, `failed response body`, {\n body: error.body,\n })\n }\n\n throw error\n }\n }\n\n /*\n * Notion API endpoints\n */\n\n public readonly blocks = {\n /**\n * Retrieve block\n */\n retrieve: (\n args: WithAuth<GetBlockParameters>\n ): Promise<GetBlockResponse> => {\n return this.request<GetBlockResponse>({\n path: getBlock.path(args),\n method: getBlock.method,\n query: pick(args, getBlock.queryParams),\n body: pick(args, getBlock.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Update block\n */\n update: (\n args: WithAuth<UpdateBlockParameters>\n ): Promise<UpdateBlockResponse> => {\n return this.request<UpdateBlockResponse>({\n path: updateBlock.path(args),\n method: updateBlock.method,\n query: pick(args, updateBlock.queryParams),\n body: pick(args, updateBlock.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Delete block\n */\n delete: (\n args: WithAuth<DeleteBlockParameters>\n ): Promise<DeleteBlockResponse> => {\n return this.request<DeleteBlockResponse>({\n path: deleteBlock.path(args),\n method: deleteBlock.method,\n query: pick(args, deleteBlock.queryParams),\n body: pick(args, deleteBlock.bodyParams),\n auth: args?.auth,\n })\n },\n children: {\n /**\n * Append block children\n */\n append: (\n args: WithAuth<AppendBlockChildrenParameters>\n ): Promise<AppendBlockChildrenResponse> => {\n return this.request<AppendBlockChildrenResponse>({\n path: appendBlockChildren.path(args),\n method: appendBlockChildren.method,\n query: pick(args, appendBlockChildren.queryParams),\n body: pick(args, appendBlockChildren.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Retrieve block children\n */\n list: (\n args: WithAuth<ListBlockChildrenParameters>\n ): Promise<ListBlockChildrenResponse> => {\n return this.request<ListBlockChildrenResponse>({\n path: listBlockChildren.path(args),\n method: listBlockChildren.method,\n query: pick(args, listBlockChildren.queryParams),\n body: pick(args, listBlockChildren.bodyParams),\n auth: args?.auth,\n })\n },\n },\n }\n\n public readonly databases = {\n /**\n * List databases\n *\n * @deprecated Please use `search`\n */\n list: (\n args: WithAuth<ListDatabasesParameters>\n ): Promise<ListDatabasesResponse> => {\n return this.request<ListDatabasesResponse>({\n path: listDatabases.path(),\n method: listDatabases.method,\n query: pick(args, listDatabases.queryParams),\n body: pick(args, listDatabases.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Retrieve a database\n */\n retrieve: (\n args: WithAuth<GetDatabaseParameters>\n ): Promise<GetDatabaseResponse> => {\n return this.request<GetDatabaseResponse>({\n path: getDatabase.path(args),\n method: getDatabase.method,\n query: pick(args, getDatabase.queryParams),\n body: pick(args, getDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Query a database\n */\n query: (\n args: WithAuth<QueryDatabaseParameters>\n ): Promise<QueryDatabaseResponse> => {\n return this.request<QueryDatabaseResponse>({\n path: queryDatabase.path(args),\n method: queryDatabase.method,\n query: pick(args, queryDatabase.queryParams),\n body: pick(args, queryDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Create a database\n */\n create: (\n args: WithAuth<CreateDatabaseParameters>\n ): Promise<CreateDatabaseResponse> => {\n return this.request<CreateDatabaseResponse>({\n path: createDatabase.path(),\n method: createDatabase.method,\n query: pick(args, createDatabase.queryParams),\n body: pick(args, createDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Update a database\n */\n update: (\n args: WithAuth<UpdateDatabaseParameters>\n ): Promise<UpdateDatabaseResponse> => {\n return this.request<UpdateDatabaseResponse>({\n path: updateDatabase.path(args),\n method: updateDatabase.method,\n query: pick(args, updateDatabase.queryParams),\n body: pick(args, updateDatabase.bodyParams),\n auth: args?.auth,\n })\n },\n }\n\n public readonly pages = {\n /**\n * Create a page\n */\n create: (\n args: WithAuth<CreatePageParameters>\n ): Promise<CreatePageResponse> => {\n return this.request<CreatePageResponse>({\n path: createPage.path(),\n method: createPage.method,\n query: pick(args, createPage.queryParams),\n body: pick(args, createPage.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Retrieve a page\n */\n retrieve: (args: WithAuth<GetPageParameters>): Promise<GetPageResponse> => {\n return this.request<GetPageResponse>({\n path: getPage.path(args),\n method: getPage.method,\n query: pick(args, getPage.queryParams),\n body: pick(args, getPage.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Update page properties\n */\n update: (\n args: WithAuth<UpdatePageParameters>\n ): Promise<UpdatePageResponse> => {\n return this.request<UpdatePageResponse>({\n path: updatePage.path(args),\n method: updatePage.method,\n query: pick(args, updatePage.queryParams),\n body: pick(args, updatePage.bodyParams),\n auth: args?.auth,\n })\n },\n properties: {\n /**\n * Retrieve page property\n */\n retrieve: (\n args: WithAuth<GetPagePropertyParameters>\n ): Promise<GetPagePropertyResponse> => {\n return this.request<GetPagePropertyResponse>({\n path: getPageProperty.path(args),\n method: getPageProperty.method,\n query: pick(args, getPageProperty.queryParams),\n body: pick(args, getPageProperty.bodyParams),\n auth: args?.auth,\n })\n },\n },\n }\n\n public readonly users = {\n /**\n * Retrieve a user\n */\n retrieve: (args: WithAuth<GetUserParameters>): Promise<GetUserResponse> => {\n return this.request<GetUserResponse>({\n path: getUser.path(args),\n method: getUser.method,\n query: pick(args, getUser.queryParams),\n body: pick(args, getUser.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * List all users\n */\n list: (args: WithAuth<ListUsersParameters>): Promise<ListUsersResponse> => {\n return this.request<ListUsersResponse>({\n path: listUsers.path(),\n method: listUsers.method,\n query: pick(args, listUsers.queryParams),\n body: pick(args, listUsers.bodyParams),\n auth: args?.auth,\n })\n },\n\n /**\n * Get details about bot\n */\n me: (args: WithAuth<GetSelfParameters>): Promise<GetSelfResponse> => {\n return this.request<GetSelfResponse>({\n path: getSelf.path(),\n method: getSelf.method,\n query: pick(args, getSelf.queryParams),\n body: pick(args, getSelf.bodyParams),\n auth: args?.auth,\n })\n },\n }\n\n /**\n * Search\n */\n public search(args: WithAuth<SearchParameters>): Promise<SearchResponse> {\n return this.request<SearchResponse>({\n path: search.path(),\n method: search.method,\n query: pick(args, search.queryParams),\n body: pick(args, search.bodyParams),\n auth: args?.auth,\n })\n }\n\n /**\n * Emits a log message to the console.\n *\n * @param level The level for this message\n * @param args Arguments to send to the console\n */\n private log(\n level: LogLevel,\n message: string,\n extraInfo: Record<string, unknown>\n ) {\n if (logLevelSeverity(level) >= logLevelSeverity(this.#logLevel)) {\n this.#logger(level, message, extraInfo)\n }\n }\n\n /**\n * Transforms an API key or access token into a headers object suitable for an HTTP request.\n *\n * This method uses the instance's value as the default when the input is undefined. If neither are defined, it returns\n * an empty object\n *\n * @param auth API key or access token\n * @returns headers key-value object\n */\n private authAsHeaders(auth?: string): Record<string, string> {\n const headers: Record<string, string> = {}\n const authHeaderValue = auth ?? this.#auth\n if (authHeaderValue !== undefined) {\n headers[\"authorization\"] = `Bearer ${authHeaderValue}`\n }\n return headers\n }\n}\n\n/*\n * Type aliases to support the generic request interface.\n */\ntype Method = \"get\" | \"post\" | \"patch\" | \"delete\"\ntype QueryParams = Record<string, string | number> | URLSearchParams\n\ntype WithAuth<P> = P & { auth?: string }\n"]}
|