bc-api-client 0.1.0-beta.1 → 0.1.0-beta.3
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/dist/client.d.ts +73 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +93 -1804
- package/dist/index.js.map +4 -4
- package/dist/net.d.ts +2 -0
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1,597 +1,15 @@
|
|
|
1
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/errors/HTTPError.js
|
|
2
|
-
var HTTPError = class extends Error {
|
|
3
|
-
response;
|
|
4
|
-
request;
|
|
5
|
-
options;
|
|
6
|
-
constructor(response, request2, options) {
|
|
7
|
-
const code = response.status || response.status === 0 ? response.status : "";
|
|
8
|
-
const title = response.statusText || "";
|
|
9
|
-
const status = `${code} ${title}`.trim();
|
|
10
|
-
const reason = status ? `status code ${status}` : "an unknown error";
|
|
11
|
-
super(`Request failed with ${reason}: ${request2.method} ${request2.url}`);
|
|
12
|
-
this.name = "HTTPError";
|
|
13
|
-
this.response = response;
|
|
14
|
-
this.request = request2;
|
|
15
|
-
this.options = options;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/errors/TimeoutError.js
|
|
20
|
-
var TimeoutError = class extends Error {
|
|
21
|
-
request;
|
|
22
|
-
constructor(request2) {
|
|
23
|
-
super(`Request timed out: ${request2.method} ${request2.url}`);
|
|
24
|
-
this.name = "TimeoutError";
|
|
25
|
-
this.request = request2;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/core/constants.js
|
|
30
|
-
var supportsRequestStreams = (() => {
|
|
31
|
-
let duplexAccessed = false;
|
|
32
|
-
let hasContentType = false;
|
|
33
|
-
const supportsReadableStream = typeof globalThis.ReadableStream === "function";
|
|
34
|
-
const supportsRequest = typeof globalThis.Request === "function";
|
|
35
|
-
if (supportsReadableStream && supportsRequest) {
|
|
36
|
-
try {
|
|
37
|
-
hasContentType = new globalThis.Request("https://empty.invalid", {
|
|
38
|
-
body: new globalThis.ReadableStream(),
|
|
39
|
-
method: "POST",
|
|
40
|
-
// @ts-expect-error - Types are outdated.
|
|
41
|
-
get duplex() {
|
|
42
|
-
duplexAccessed = true;
|
|
43
|
-
return "half";
|
|
44
|
-
}
|
|
45
|
-
}).headers.has("Content-Type");
|
|
46
|
-
} catch (error) {
|
|
47
|
-
if (error instanceof Error && error.message === "unsupported BodyInit type") {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
throw error;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return duplexAccessed && !hasContentType;
|
|
54
|
-
})();
|
|
55
|
-
var supportsAbortController = typeof globalThis.AbortController === "function";
|
|
56
|
-
var supportsResponseStreams = typeof globalThis.ReadableStream === "function";
|
|
57
|
-
var supportsFormData = typeof globalThis.FormData === "function";
|
|
58
|
-
var requestMethods = ["get", "post", "put", "patch", "head", "delete"];
|
|
59
|
-
var validate = () => void 0;
|
|
60
|
-
validate();
|
|
61
|
-
var responseTypes = {
|
|
62
|
-
json: "application/json",
|
|
63
|
-
text: "text/*",
|
|
64
|
-
formData: "multipart/form-data",
|
|
65
|
-
arrayBuffer: "*/*",
|
|
66
|
-
blob: "*/*"
|
|
67
|
-
};
|
|
68
|
-
var maxSafeTimeout = 2147483647;
|
|
69
|
-
var usualFormBoundarySize = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length;
|
|
70
|
-
var stop = Symbol("stop");
|
|
71
|
-
var kyOptionKeys = {
|
|
72
|
-
json: true,
|
|
73
|
-
parseJson: true,
|
|
74
|
-
stringifyJson: true,
|
|
75
|
-
searchParams: true,
|
|
76
|
-
prefixUrl: true,
|
|
77
|
-
retry: true,
|
|
78
|
-
timeout: true,
|
|
79
|
-
hooks: true,
|
|
80
|
-
throwHttpErrors: true,
|
|
81
|
-
onDownloadProgress: true,
|
|
82
|
-
onUploadProgress: true,
|
|
83
|
-
fetch: true
|
|
84
|
-
};
|
|
85
|
-
var requestOptionsRegistry = {
|
|
86
|
-
method: true,
|
|
87
|
-
headers: true,
|
|
88
|
-
body: true,
|
|
89
|
-
mode: true,
|
|
90
|
-
credentials: true,
|
|
91
|
-
cache: true,
|
|
92
|
-
redirect: true,
|
|
93
|
-
referrer: true,
|
|
94
|
-
referrerPolicy: true,
|
|
95
|
-
integrity: true,
|
|
96
|
-
keepalive: true,
|
|
97
|
-
signal: true,
|
|
98
|
-
window: true,
|
|
99
|
-
dispatcher: true,
|
|
100
|
-
duplex: true,
|
|
101
|
-
priority: true
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/utils/body.js
|
|
105
|
-
var getBodySize = (body) => {
|
|
106
|
-
if (!body) {
|
|
107
|
-
return 0;
|
|
108
|
-
}
|
|
109
|
-
if (body instanceof FormData) {
|
|
110
|
-
let size = 0;
|
|
111
|
-
for (const [key, value] of body) {
|
|
112
|
-
size += usualFormBoundarySize;
|
|
113
|
-
size += new TextEncoder().encode(`Content-Disposition: form-data; name="${key}"`).length;
|
|
114
|
-
size += typeof value === "string" ? new TextEncoder().encode(value).length : value.size;
|
|
115
|
-
}
|
|
116
|
-
return size;
|
|
117
|
-
}
|
|
118
|
-
if (body instanceof Blob) {
|
|
119
|
-
return body.size;
|
|
120
|
-
}
|
|
121
|
-
if (body instanceof ArrayBuffer) {
|
|
122
|
-
return body.byteLength;
|
|
123
|
-
}
|
|
124
|
-
if (typeof body === "string") {
|
|
125
|
-
return new TextEncoder().encode(body).length;
|
|
126
|
-
}
|
|
127
|
-
if (body instanceof URLSearchParams) {
|
|
128
|
-
return new TextEncoder().encode(body.toString()).length;
|
|
129
|
-
}
|
|
130
|
-
if ("byteLength" in body) {
|
|
131
|
-
return body.byteLength;
|
|
132
|
-
}
|
|
133
|
-
if (typeof body === "object" && body !== null) {
|
|
134
|
-
try {
|
|
135
|
-
const jsonString = JSON.stringify(body);
|
|
136
|
-
return new TextEncoder().encode(jsonString).length;
|
|
137
|
-
} catch {
|
|
138
|
-
return 0;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return 0;
|
|
142
|
-
};
|
|
143
|
-
var streamResponse = (response, onDownloadProgress) => {
|
|
144
|
-
const totalBytes = Number(response.headers.get("content-length")) || 0;
|
|
145
|
-
let transferredBytes = 0;
|
|
146
|
-
if (response.status === 204) {
|
|
147
|
-
if (onDownloadProgress) {
|
|
148
|
-
onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
|
|
149
|
-
}
|
|
150
|
-
return new Response(null, {
|
|
151
|
-
status: response.status,
|
|
152
|
-
statusText: response.statusText,
|
|
153
|
-
headers: response.headers
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
return new Response(new ReadableStream({
|
|
157
|
-
async start(controller) {
|
|
158
|
-
const reader = response.body.getReader();
|
|
159
|
-
if (onDownloadProgress) {
|
|
160
|
-
onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
|
|
161
|
-
}
|
|
162
|
-
async function read() {
|
|
163
|
-
const { done, value } = await reader.read();
|
|
164
|
-
if (done) {
|
|
165
|
-
controller.close();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (onDownloadProgress) {
|
|
169
|
-
transferredBytes += value.byteLength;
|
|
170
|
-
const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
|
171
|
-
onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
|
|
172
|
-
}
|
|
173
|
-
controller.enqueue(value);
|
|
174
|
-
await read();
|
|
175
|
-
}
|
|
176
|
-
await read();
|
|
177
|
-
}
|
|
178
|
-
}), {
|
|
179
|
-
status: response.status,
|
|
180
|
-
statusText: response.statusText,
|
|
181
|
-
headers: response.headers
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
var streamRequest = (request2, onUploadProgress) => {
|
|
185
|
-
const totalBytes = getBodySize(request2.body);
|
|
186
|
-
let transferredBytes = 0;
|
|
187
|
-
return new Request(request2, {
|
|
188
|
-
// @ts-expect-error - Types are outdated.
|
|
189
|
-
duplex: "half",
|
|
190
|
-
body: new ReadableStream({
|
|
191
|
-
async start(controller) {
|
|
192
|
-
const reader = request2.body instanceof ReadableStream ? request2.body.getReader() : new Response("").body.getReader();
|
|
193
|
-
async function read() {
|
|
194
|
-
const { done, value } = await reader.read();
|
|
195
|
-
if (done) {
|
|
196
|
-
if (onUploadProgress) {
|
|
197
|
-
onUploadProgress({ percent: 1, transferredBytes, totalBytes: Math.max(totalBytes, transferredBytes) }, new Uint8Array());
|
|
198
|
-
}
|
|
199
|
-
controller.close();
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
transferredBytes += value.byteLength;
|
|
203
|
-
let percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
|
|
204
|
-
if (totalBytes < transferredBytes || percent === 1) {
|
|
205
|
-
percent = 0.99;
|
|
206
|
-
}
|
|
207
|
-
if (onUploadProgress) {
|
|
208
|
-
onUploadProgress({ percent: Number(percent.toFixed(2)), transferredBytes, totalBytes }, value);
|
|
209
|
-
}
|
|
210
|
-
controller.enqueue(value);
|
|
211
|
-
await read();
|
|
212
|
-
}
|
|
213
|
-
await read();
|
|
214
|
-
}
|
|
215
|
-
})
|
|
216
|
-
});
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/utils/is.js
|
|
220
|
-
var isObject = (value) => value !== null && typeof value === "object";
|
|
221
|
-
|
|
222
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/utils/merge.js
|
|
223
|
-
var validateAndMerge = (...sources) => {
|
|
224
|
-
for (const source of sources) {
|
|
225
|
-
if ((!isObject(source) || Array.isArray(source)) && source !== void 0) {
|
|
226
|
-
throw new TypeError("The `options` argument must be an object");
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return deepMerge({}, ...sources);
|
|
230
|
-
};
|
|
231
|
-
var mergeHeaders = (source1 = {}, source2 = {}) => {
|
|
232
|
-
const result = new globalThis.Headers(source1);
|
|
233
|
-
const isHeadersInstance = source2 instanceof globalThis.Headers;
|
|
234
|
-
const source = new globalThis.Headers(source2);
|
|
235
|
-
for (const [key, value] of source.entries()) {
|
|
236
|
-
if (isHeadersInstance && value === "undefined" || value === void 0) {
|
|
237
|
-
result.delete(key);
|
|
238
|
-
} else {
|
|
239
|
-
result.set(key, value);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return result;
|
|
243
|
-
};
|
|
244
|
-
function newHookValue(original, incoming, property) {
|
|
245
|
-
return Object.hasOwn(incoming, property) && incoming[property] === void 0 ? [] : deepMerge(original[property] ?? [], incoming[property] ?? []);
|
|
246
|
-
}
|
|
247
|
-
var mergeHooks = (original = {}, incoming = {}) => ({
|
|
248
|
-
beforeRequest: newHookValue(original, incoming, "beforeRequest"),
|
|
249
|
-
beforeRetry: newHookValue(original, incoming, "beforeRetry"),
|
|
250
|
-
afterResponse: newHookValue(original, incoming, "afterResponse"),
|
|
251
|
-
beforeError: newHookValue(original, incoming, "beforeError")
|
|
252
|
-
});
|
|
253
|
-
var deepMerge = (...sources) => {
|
|
254
|
-
let returnValue = {};
|
|
255
|
-
let headers = {};
|
|
256
|
-
let hooks = {};
|
|
257
|
-
for (const source of sources) {
|
|
258
|
-
if (Array.isArray(source)) {
|
|
259
|
-
if (!Array.isArray(returnValue)) {
|
|
260
|
-
returnValue = [];
|
|
261
|
-
}
|
|
262
|
-
returnValue = [...returnValue, ...source];
|
|
263
|
-
} else if (isObject(source)) {
|
|
264
|
-
for (let [key, value] of Object.entries(source)) {
|
|
265
|
-
if (isObject(value) && key in returnValue) {
|
|
266
|
-
value = deepMerge(returnValue[key], value);
|
|
267
|
-
}
|
|
268
|
-
returnValue = { ...returnValue, [key]: value };
|
|
269
|
-
}
|
|
270
|
-
if (isObject(source.hooks)) {
|
|
271
|
-
hooks = mergeHooks(hooks, source.hooks);
|
|
272
|
-
returnValue.hooks = hooks;
|
|
273
|
-
}
|
|
274
|
-
if (isObject(source.headers)) {
|
|
275
|
-
headers = mergeHeaders(headers, source.headers);
|
|
276
|
-
returnValue.headers = headers;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return returnValue;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/utils/normalize.js
|
|
284
|
-
var normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
|
|
285
|
-
var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
|
|
286
|
-
var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
|
287
|
-
var retryAfterStatusCodes = [413, 429, 503];
|
|
288
|
-
var defaultRetryOptions = {
|
|
289
|
-
limit: 2,
|
|
290
|
-
methods: retryMethods,
|
|
291
|
-
statusCodes: retryStatusCodes,
|
|
292
|
-
afterStatusCodes: retryAfterStatusCodes,
|
|
293
|
-
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
294
|
-
backoffLimit: Number.POSITIVE_INFINITY,
|
|
295
|
-
delay: (attemptCount) => 0.3 * 2 ** (attemptCount - 1) * 1e3
|
|
296
|
-
};
|
|
297
|
-
var normalizeRetryOptions = (retry = {}) => {
|
|
298
|
-
if (typeof retry === "number") {
|
|
299
|
-
return {
|
|
300
|
-
...defaultRetryOptions,
|
|
301
|
-
limit: retry
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
if (retry.methods && !Array.isArray(retry.methods)) {
|
|
305
|
-
throw new Error("retry.methods must be an array");
|
|
306
|
-
}
|
|
307
|
-
if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
|
|
308
|
-
throw new Error("retry.statusCodes must be an array");
|
|
309
|
-
}
|
|
310
|
-
return {
|
|
311
|
-
...defaultRetryOptions,
|
|
312
|
-
...retry
|
|
313
|
-
};
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/utils/timeout.js
|
|
317
|
-
async function timeout(request2, init, abortController, options) {
|
|
318
|
-
return new Promise((resolve, reject) => {
|
|
319
|
-
const timeoutId = setTimeout(() => {
|
|
320
|
-
if (abortController) {
|
|
321
|
-
abortController.abort();
|
|
322
|
-
}
|
|
323
|
-
reject(new TimeoutError(request2));
|
|
324
|
-
}, options.timeout);
|
|
325
|
-
void options.fetch(request2, init).then(resolve).catch(reject).then(() => {
|
|
326
|
-
clearTimeout(timeoutId);
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/utils/delay.js
|
|
332
|
-
async function delay(ms, { signal }) {
|
|
333
|
-
return new Promise((resolve, reject) => {
|
|
334
|
-
if (signal) {
|
|
335
|
-
signal.throwIfAborted();
|
|
336
|
-
signal.addEventListener("abort", abortHandler, { once: true });
|
|
337
|
-
}
|
|
338
|
-
function abortHandler() {
|
|
339
|
-
clearTimeout(timeoutId);
|
|
340
|
-
reject(signal.reason);
|
|
341
|
-
}
|
|
342
|
-
const timeoutId = setTimeout(() => {
|
|
343
|
-
signal?.removeEventListener("abort", abortHandler);
|
|
344
|
-
resolve();
|
|
345
|
-
}, ms);
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/utils/options.js
|
|
350
|
-
var findUnknownOptions = (request2, options) => {
|
|
351
|
-
const unknownOptions = {};
|
|
352
|
-
for (const key in options) {
|
|
353
|
-
if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && !(key in request2)) {
|
|
354
|
-
unknownOptions[key] = options[key];
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return unknownOptions;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/core/Ky.js
|
|
361
|
-
var Ky = class _Ky {
|
|
362
|
-
static create(input, options) {
|
|
363
|
-
const ky2 = new _Ky(input, options);
|
|
364
|
-
const function_ = async () => {
|
|
365
|
-
if (typeof ky2._options.timeout === "number" && ky2._options.timeout > maxSafeTimeout) {
|
|
366
|
-
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
|
367
|
-
}
|
|
368
|
-
await Promise.resolve();
|
|
369
|
-
let response = await ky2._fetch();
|
|
370
|
-
for (const hook of ky2._options.hooks.afterResponse) {
|
|
371
|
-
const modifiedResponse = await hook(ky2.request, ky2._options, ky2._decorateResponse(response.clone()));
|
|
372
|
-
if (modifiedResponse instanceof globalThis.Response) {
|
|
373
|
-
response = modifiedResponse;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
ky2._decorateResponse(response);
|
|
377
|
-
if (!response.ok && ky2._options.throwHttpErrors) {
|
|
378
|
-
let error = new HTTPError(response, ky2.request, ky2._options);
|
|
379
|
-
for (const hook of ky2._options.hooks.beforeError) {
|
|
380
|
-
error = await hook(error);
|
|
381
|
-
}
|
|
382
|
-
throw error;
|
|
383
|
-
}
|
|
384
|
-
if (ky2._options.onDownloadProgress) {
|
|
385
|
-
if (typeof ky2._options.onDownloadProgress !== "function") {
|
|
386
|
-
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
387
|
-
}
|
|
388
|
-
if (!supportsResponseStreams) {
|
|
389
|
-
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
390
|
-
}
|
|
391
|
-
return streamResponse(response.clone(), ky2._options.onDownloadProgress);
|
|
392
|
-
}
|
|
393
|
-
return response;
|
|
394
|
-
};
|
|
395
|
-
const isRetriableMethod = ky2._options.retry.methods.includes(ky2.request.method.toLowerCase());
|
|
396
|
-
const result = (isRetriableMethod ? ky2._retry(function_) : function_()).finally(async () => {
|
|
397
|
-
if (!ky2.request.bodyUsed) {
|
|
398
|
-
await ky2.request.body?.cancel();
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
|
402
|
-
result[type] = async () => {
|
|
403
|
-
ky2.request.headers.set("accept", ky2.request.headers.get("accept") || mimeType);
|
|
404
|
-
const response = await result;
|
|
405
|
-
if (type === "json") {
|
|
406
|
-
if (response.status === 204) {
|
|
407
|
-
return "";
|
|
408
|
-
}
|
|
409
|
-
const arrayBuffer = await response.clone().arrayBuffer();
|
|
410
|
-
const responseSize = arrayBuffer.byteLength;
|
|
411
|
-
if (responseSize === 0) {
|
|
412
|
-
return "";
|
|
413
|
-
}
|
|
414
|
-
if (options.parseJson) {
|
|
415
|
-
return options.parseJson(await response.text());
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
return response[type]();
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
return result;
|
|
422
|
-
}
|
|
423
|
-
request;
|
|
424
|
-
abortController;
|
|
425
|
-
_retryCount = 0;
|
|
426
|
-
_input;
|
|
427
|
-
_options;
|
|
428
|
-
// eslint-disable-next-line complexity
|
|
429
|
-
constructor(input, options = {}) {
|
|
430
|
-
this._input = input;
|
|
431
|
-
this._options = {
|
|
432
|
-
...options,
|
|
433
|
-
headers: mergeHeaders(this._input.headers, options.headers),
|
|
434
|
-
hooks: mergeHooks({
|
|
435
|
-
beforeRequest: [],
|
|
436
|
-
beforeRetry: [],
|
|
437
|
-
beforeError: [],
|
|
438
|
-
afterResponse: []
|
|
439
|
-
}, options.hooks),
|
|
440
|
-
method: normalizeRequestMethod(options.method ?? this._input.method ?? "GET"),
|
|
441
|
-
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
442
|
-
prefixUrl: String(options.prefixUrl || ""),
|
|
443
|
-
retry: normalizeRetryOptions(options.retry),
|
|
444
|
-
throwHttpErrors: options.throwHttpErrors !== false,
|
|
445
|
-
timeout: options.timeout ?? 1e4,
|
|
446
|
-
fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
|
|
447
|
-
};
|
|
448
|
-
if (typeof this._input !== "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
|
|
449
|
-
throw new TypeError("`input` must be a string, URL, or Request");
|
|
450
|
-
}
|
|
451
|
-
if (this._options.prefixUrl && typeof this._input === "string") {
|
|
452
|
-
if (this._input.startsWith("/")) {
|
|
453
|
-
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
454
|
-
}
|
|
455
|
-
if (!this._options.prefixUrl.endsWith("/")) {
|
|
456
|
-
this._options.prefixUrl += "/";
|
|
457
|
-
}
|
|
458
|
-
this._input = this._options.prefixUrl + this._input;
|
|
459
|
-
}
|
|
460
|
-
if (supportsAbortController) {
|
|
461
|
-
const originalSignal = this._options.signal ?? this._input.signal;
|
|
462
|
-
this.abortController = new globalThis.AbortController();
|
|
463
|
-
this._options.signal = originalSignal ? AbortSignal.any([originalSignal, this.abortController.signal]) : this.abortController.signal;
|
|
464
|
-
}
|
|
465
|
-
if (supportsRequestStreams) {
|
|
466
|
-
this._options.duplex = "half";
|
|
467
|
-
}
|
|
468
|
-
if (this._options.json !== void 0) {
|
|
469
|
-
this._options.body = this._options.stringifyJson?.(this._options.json) ?? JSON.stringify(this._options.json);
|
|
470
|
-
this._options.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json");
|
|
471
|
-
}
|
|
472
|
-
this.request = new globalThis.Request(this._input, this._options);
|
|
473
|
-
if (this._options.searchParams) {
|
|
474
|
-
const textSearchParams = typeof this._options.searchParams === "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString();
|
|
475
|
-
const searchParams = "?" + textSearchParams;
|
|
476
|
-
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
|
477
|
-
if ((supportsFormData && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"])) {
|
|
478
|
-
this.request.headers.delete("content-type");
|
|
479
|
-
}
|
|
480
|
-
this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);
|
|
481
|
-
}
|
|
482
|
-
if (this._options.onUploadProgress) {
|
|
483
|
-
if (typeof this._options.onUploadProgress !== "function") {
|
|
484
|
-
throw new TypeError("The `onUploadProgress` option must be a function");
|
|
485
|
-
}
|
|
486
|
-
if (!supportsRequestStreams) {
|
|
487
|
-
throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
|
|
488
|
-
}
|
|
489
|
-
const originalBody = this.request.body;
|
|
490
|
-
if (originalBody) {
|
|
491
|
-
this.request = streamRequest(this.request, this._options.onUploadProgress);
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
_calculateRetryDelay(error) {
|
|
496
|
-
this._retryCount++;
|
|
497
|
-
if (this._retryCount > this._options.retry.limit || error instanceof TimeoutError) {
|
|
498
|
-
throw error;
|
|
499
|
-
}
|
|
500
|
-
if (error instanceof HTTPError) {
|
|
501
|
-
if (!this._options.retry.statusCodes.includes(error.response.status)) {
|
|
502
|
-
throw error;
|
|
503
|
-
}
|
|
504
|
-
const retryAfter = error.response.headers.get("Retry-After") ?? error.response.headers.get("RateLimit-Reset") ?? error.response.headers.get("X-RateLimit-Reset") ?? error.response.headers.get("X-Rate-Limit-Reset");
|
|
505
|
-
if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
|
|
506
|
-
let after = Number(retryAfter) * 1e3;
|
|
507
|
-
if (Number.isNaN(after)) {
|
|
508
|
-
after = Date.parse(retryAfter) - Date.now();
|
|
509
|
-
} else if (after >= Date.parse("2024-01-01")) {
|
|
510
|
-
after -= Date.now();
|
|
511
|
-
}
|
|
512
|
-
const max = this._options.retry.maxRetryAfter ?? after;
|
|
513
|
-
return after < max ? after : max;
|
|
514
|
-
}
|
|
515
|
-
if (error.response.status === 413) {
|
|
516
|
-
throw error;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
const retryDelay = this._options.retry.delay(this._retryCount);
|
|
520
|
-
return Math.min(this._options.retry.backoffLimit, retryDelay);
|
|
521
|
-
}
|
|
522
|
-
_decorateResponse(response) {
|
|
523
|
-
if (this._options.parseJson) {
|
|
524
|
-
response.json = async () => this._options.parseJson(await response.text());
|
|
525
|
-
}
|
|
526
|
-
return response;
|
|
527
|
-
}
|
|
528
|
-
async _retry(function_) {
|
|
529
|
-
try {
|
|
530
|
-
return await function_();
|
|
531
|
-
} catch (error) {
|
|
532
|
-
const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
|
|
533
|
-
if (this._retryCount < 1) {
|
|
534
|
-
throw error;
|
|
535
|
-
}
|
|
536
|
-
await delay(ms, { signal: this._options.signal });
|
|
537
|
-
for (const hook of this._options.hooks.beforeRetry) {
|
|
538
|
-
const hookResult = await hook({
|
|
539
|
-
request: this.request,
|
|
540
|
-
options: this._options,
|
|
541
|
-
error,
|
|
542
|
-
retryCount: this._retryCount
|
|
543
|
-
});
|
|
544
|
-
if (hookResult === stop) {
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
return this._retry(function_);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
async _fetch() {
|
|
552
|
-
for (const hook of this._options.hooks.beforeRequest) {
|
|
553
|
-
const result = await hook(this.request, this._options);
|
|
554
|
-
if (result instanceof Request) {
|
|
555
|
-
this.request = result;
|
|
556
|
-
break;
|
|
557
|
-
}
|
|
558
|
-
if (result instanceof Response) {
|
|
559
|
-
return result;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
const nonRequestOptions = findUnknownOptions(this.request, this._options);
|
|
563
|
-
const mainRequest = this.request;
|
|
564
|
-
this.request = mainRequest.clone();
|
|
565
|
-
if (this._options.timeout === false) {
|
|
566
|
-
return this._options.fetch(mainRequest, nonRequestOptions);
|
|
567
|
-
}
|
|
568
|
-
return timeout(mainRequest, nonRequestOptions, this.abortController, this._options);
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
|
|
572
|
-
// node_modules/.pnpm/ky@1.8.1/node_modules/ky/distribution/index.js
|
|
573
|
-
var createInstance = (defaults) => {
|
|
574
|
-
const ky2 = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
|
|
575
|
-
for (const method of requestMethods) {
|
|
576
|
-
ky2[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
|
|
577
|
-
}
|
|
578
|
-
ky2.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
|
|
579
|
-
ky2.extend = (newDefaults) => {
|
|
580
|
-
if (typeof newDefaults === "function") {
|
|
581
|
-
newDefaults = newDefaults(defaults ?? {});
|
|
582
|
-
}
|
|
583
|
-
return createInstance(validateAndMerge(defaults, newDefaults));
|
|
584
|
-
};
|
|
585
|
-
ky2.stop = stop;
|
|
586
|
-
return ky2;
|
|
587
|
-
};
|
|
588
|
-
var ky = createInstance();
|
|
589
|
-
var distribution_default = ky;
|
|
590
|
-
|
|
591
1
|
// src/net.ts
|
|
2
|
+
import ky, { HTTPError } from "ky";
|
|
3
|
+
var Methods = {
|
|
4
|
+
GET: "GET",
|
|
5
|
+
POST: "POST",
|
|
6
|
+
PUT: "PUT",
|
|
7
|
+
DELETE: "DELETE"
|
|
8
|
+
};
|
|
9
|
+
var BASE_URL = "https://api.bigcommerce.com/stores/";
|
|
592
10
|
var CONFIG = {
|
|
593
11
|
/** Base URL for BigCommerce API */
|
|
594
|
-
BASE_URL
|
|
12
|
+
BASE_URL,
|
|
595
13
|
/** Default API version to use */
|
|
596
14
|
DEFAULT_VERSION: "v3",
|
|
597
15
|
/** Maximum delay in milliseconds for rate limit retries */
|
|
@@ -603,20 +21,20 @@ var CONFIG = {
|
|
|
603
21
|
/** Rate limit header names */
|
|
604
22
|
HEADERS: {
|
|
605
23
|
/** Time window for rate limiting in milliseconds */
|
|
606
|
-
WINDOW: "
|
|
24
|
+
WINDOW: "x-rate-limit-time-window-ms",
|
|
607
25
|
/** Time to wait before retrying after rate limit in milliseconds */
|
|
608
|
-
RETRY_AFTER: "
|
|
26
|
+
RETRY_AFTER: "x-rate-limit-time-reset-ms",
|
|
609
27
|
/** Total request quota for the time window */
|
|
610
|
-
REQUEST_QUOTA: "
|
|
28
|
+
REQUEST_QUOTA: "x-rate-limit-requests-quota",
|
|
611
29
|
/** Number of requests remaining in the current window */
|
|
612
|
-
REQUESTS_LEFT: "
|
|
30
|
+
REQUESTS_LEFT: "x-rate-limit-requests-left"
|
|
613
31
|
}
|
|
614
32
|
};
|
|
615
33
|
var RequestError = class extends Error {
|
|
616
|
-
constructor(status,
|
|
617
|
-
super(
|
|
34
|
+
constructor(status, message, data, cause) {
|
|
35
|
+
super(message, { cause });
|
|
618
36
|
this.status = status;
|
|
619
|
-
this.message =
|
|
37
|
+
this.message = message;
|
|
620
38
|
this.data = data;
|
|
621
39
|
this.cause = cause;
|
|
622
40
|
}
|
|
@@ -663,11 +81,13 @@ var safeRequest = async (options) => {
|
|
|
663
81
|
let res;
|
|
664
82
|
try {
|
|
665
83
|
res = await call(options);
|
|
666
|
-
} catch (
|
|
667
|
-
if (
|
|
668
|
-
throw
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof RequestError) {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
if (!(error instanceof HTTPError)) {
|
|
89
|
+
throw error;
|
|
669
90
|
}
|
|
670
|
-
const error = _error;
|
|
671
91
|
let data;
|
|
672
92
|
let errorMessage = error.message;
|
|
673
93
|
try {
|
|
@@ -683,11 +103,11 @@ var safeRequest = async (options) => {
|
|
|
683
103
|
data = "Failed to read error response";
|
|
684
104
|
}
|
|
685
105
|
throw new RequestError(
|
|
686
|
-
error
|
|
106
|
+
error?.response?.status ?? 500,
|
|
687
107
|
errorMessage,
|
|
688
108
|
{
|
|
689
109
|
data,
|
|
690
|
-
headers: Object.fromEntries(error
|
|
110
|
+
headers: Object.fromEntries(error?.response?.headers?.entries() ?? [])
|
|
691
111
|
},
|
|
692
112
|
error
|
|
693
113
|
);
|
|
@@ -728,128 +148,11 @@ var call = (options) => {
|
|
|
728
148
|
},
|
|
729
149
|
json: body
|
|
730
150
|
};
|
|
731
|
-
return
|
|
151
|
+
return ky(fullUrl, request2);
|
|
732
152
|
};
|
|
733
153
|
|
|
734
|
-
//
|
|
735
|
-
|
|
736
|
-
var s = { done: false, hasNext: false };
|
|
737
|
-
var a = () => e;
|
|
738
|
-
|
|
739
|
-
// node_modules/.pnpm/remeda@2.21.3/node_modules/remeda/dist/chunk-3GOCSNFN.js
|
|
740
|
-
function C(t, ...o2) {
|
|
741
|
-
let n = t, u3 = o2.map((e2) => "lazy" in e2 ? y(e2) : void 0), p = 0;
|
|
742
|
-
for (; p < o2.length; ) {
|
|
743
|
-
if (u3[p] === void 0 || !B(n)) {
|
|
744
|
-
let i2 = o2[p];
|
|
745
|
-
n = i2(n), p += 1;
|
|
746
|
-
continue;
|
|
747
|
-
}
|
|
748
|
-
let r = [];
|
|
749
|
-
for (let i2 = p; i2 < o2.length; i2++) {
|
|
750
|
-
let l = u3[i2];
|
|
751
|
-
if (l === void 0 || (r.push(l), l.isSingle)) break;
|
|
752
|
-
}
|
|
753
|
-
let a3 = [];
|
|
754
|
-
for (let i2 of n) if (f(i2, a3, r)) break;
|
|
755
|
-
let { isSingle: s4 } = r.at(-1);
|
|
756
|
-
n = s4 ? a3[0] : a3, p += r.length;
|
|
757
|
-
}
|
|
758
|
-
return n;
|
|
759
|
-
}
|
|
760
|
-
function f(t, o2, n) {
|
|
761
|
-
if (n.length === 0) return o2.push(t), false;
|
|
762
|
-
let u3 = t, p = s, e2 = false;
|
|
763
|
-
for (let [r, a3] of n.entries()) {
|
|
764
|
-
let { index: s4, items: i2 } = a3;
|
|
765
|
-
if (i2.push(u3), p = a3(u3, s4, i2), a3.index += 1, p.hasNext) {
|
|
766
|
-
if (p.hasMany ?? false) {
|
|
767
|
-
for (let l of p.next) if (f(l, o2, n.slice(r + 1))) return true;
|
|
768
|
-
return e2;
|
|
769
|
-
}
|
|
770
|
-
u3 = p.next;
|
|
771
|
-
}
|
|
772
|
-
if (!p.hasNext) break;
|
|
773
|
-
p.done && (e2 = true);
|
|
774
|
-
}
|
|
775
|
-
return p.hasNext && o2.push(u3), e2;
|
|
776
|
-
}
|
|
777
|
-
function y(t) {
|
|
778
|
-
let { lazy: o2, lazyArgs: n } = t, u3 = o2(...n);
|
|
779
|
-
return Object.assign(u3, { isSingle: o2.single ?? false, index: 0, items: [] });
|
|
780
|
-
}
|
|
781
|
-
function B(t) {
|
|
782
|
-
return typeof t == "string" || typeof t == "object" && t !== null && Symbol.iterator in t;
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
// node_modules/.pnpm/remeda@2.21.3/node_modules/remeda/dist/chunk-LFJW7BOT.js
|
|
786
|
-
function y2(t, i2) {
|
|
787
|
-
let a3 = i2.length - t.length;
|
|
788
|
-
if (a3 === 1) {
|
|
789
|
-
let [n, ...r] = i2;
|
|
790
|
-
return C(n, { lazy: t, lazyArgs: r });
|
|
791
|
-
}
|
|
792
|
-
if (a3 === 0) {
|
|
793
|
-
let n = { lazy: t, lazyArgs: i2 };
|
|
794
|
-
return Object.assign((e2) => C(e2, n), n);
|
|
795
|
-
}
|
|
796
|
-
throw new Error("Wrong number of arguments");
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// node_modules/.pnpm/remeda@2.21.3/node_modules/remeda/dist/chunk-D6FCK2GA.js
|
|
800
|
-
function u(o2, n, a3) {
|
|
801
|
-
let t = (r) => o2(r, ...n);
|
|
802
|
-
return a3 === void 0 ? t : Object.assign(t, { lazy: a3, lazyArgs: n });
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
// node_modules/.pnpm/remeda@2.21.3/node_modules/remeda/dist/chunk-WIMGWYZL.js
|
|
806
|
-
function u2(r, n, o2) {
|
|
807
|
-
let a3 = r.length - n.length;
|
|
808
|
-
if (a3 === 0) return r(...n);
|
|
809
|
-
if (a3 === 1) return u(r, n, o2);
|
|
810
|
-
throw new Error("Wrong number of arguments");
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
// node_modules/.pnpm/remeda@2.21.3/node_modules/remeda/dist/chunk-ENS7GPLZ.js
|
|
814
|
-
function a2(...r) {
|
|
815
|
-
return u2(o, r);
|
|
816
|
-
}
|
|
817
|
-
function o(r, t) {
|
|
818
|
-
let e2 = [];
|
|
819
|
-
for (let n = r; n < t; n++) e2.push(n);
|
|
820
|
-
return e2;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// node_modules/.pnpm/remeda@2.21.3/node_modules/remeda/dist/chunk-ICBBHOCR.js
|
|
824
|
-
function s2(...t) {
|
|
825
|
-
return y2(i, t);
|
|
826
|
-
}
|
|
827
|
-
function i(t) {
|
|
828
|
-
if (t.length === 0) return a;
|
|
829
|
-
let n = /* @__PURE__ */ new Map();
|
|
830
|
-
for (let r of t) n.set(r, (n.get(r) ?? 0) + 1);
|
|
831
|
-
return (r) => {
|
|
832
|
-
let e2 = n.get(r);
|
|
833
|
-
return e2 === void 0 || e2 === 0 ? s : (e2 === 1 ? n.delete(r) : n.set(r, e2 - 1), { hasNext: true, next: r, done: n.size === 0 });
|
|
834
|
-
};
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
// node_modules/.pnpm/remeda@2.21.3/node_modules/remeda/dist/chunk-WFMWIRTS.js
|
|
838
|
-
function f2(...e2) {
|
|
839
|
-
return u2(s3, e2);
|
|
840
|
-
}
|
|
841
|
-
function s3(e2, n) {
|
|
842
|
-
if (n < 1) throw new RangeError(`chunk: A chunk size of '${n.toString()}' would result in an infinite array`);
|
|
843
|
-
if (e2.length === 0) return [];
|
|
844
|
-
if (n >= e2.length) return [[...e2]];
|
|
845
|
-
let i2 = Math.ceil(e2.length / n), u3 = new Array(i2);
|
|
846
|
-
if (n === 1) for (let [r, t] of e2.entries()) u3[r] = [t];
|
|
847
|
-
else for (let r = 0; r < i2; r += 1) {
|
|
848
|
-
let t = r * n;
|
|
849
|
-
u3[r] = e2.slice(t, t + n);
|
|
850
|
-
}
|
|
851
|
-
return u3;
|
|
852
|
-
}
|
|
154
|
+
// src/client.ts
|
|
155
|
+
import { chunk, range } from "remeda";
|
|
853
156
|
|
|
854
157
|
// src/util.ts
|
|
855
158
|
var chunkStrLength = (items, options = {}) => {
|
|
@@ -884,9 +187,18 @@ var chunkStrLength = (items, options = {}) => {
|
|
|
884
187
|
// src/client.ts
|
|
885
188
|
var MAX_PAGE_SIZE = 250;
|
|
886
189
|
var BigCommerceClient = class {
|
|
190
|
+
/**
|
|
191
|
+
* Creates a new BigCommerce client instance
|
|
192
|
+
* @param config - Configuration options for the client
|
|
193
|
+
*/
|
|
887
194
|
constructor(config) {
|
|
888
195
|
this.config = config;
|
|
889
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Makes a GET request to the BigCommerce API
|
|
199
|
+
* @param options - Request options
|
|
200
|
+
* @returns Promise resolving to the response data
|
|
201
|
+
*/
|
|
890
202
|
async get(options) {
|
|
891
203
|
return request({
|
|
892
204
|
...options,
|
|
@@ -894,6 +206,11 @@ var BigCommerceClient = class {
|
|
|
894
206
|
...this.config
|
|
895
207
|
});
|
|
896
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* Makes a POST request to the BigCommerce API
|
|
211
|
+
* @param options - Request options including body data
|
|
212
|
+
* @returns Promise resolving to the response data
|
|
213
|
+
*/
|
|
897
214
|
async post(options) {
|
|
898
215
|
return request({
|
|
899
216
|
...options,
|
|
@@ -901,6 +218,11 @@ var BigCommerceClient = class {
|
|
|
901
218
|
...this.config
|
|
902
219
|
});
|
|
903
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Makes a PUT request to the BigCommerce API
|
|
223
|
+
* @param options - Request options including body data
|
|
224
|
+
* @returns Promise resolving to the response data
|
|
225
|
+
*/
|
|
904
226
|
async put(options) {
|
|
905
227
|
return request({
|
|
906
228
|
...options,
|
|
@@ -908,6 +230,10 @@ var BigCommerceClient = class {
|
|
|
908
230
|
...this.config
|
|
909
231
|
});
|
|
910
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Makes a DELETE request to the BigCommerce API
|
|
235
|
+
* @param endpoint - The API endpoint to delete
|
|
236
|
+
*/
|
|
911
237
|
async delete(endpoint) {
|
|
912
238
|
await request({
|
|
913
239
|
endpoint,
|
|
@@ -915,13 +241,19 @@ var BigCommerceClient = class {
|
|
|
915
241
|
...this.config
|
|
916
242
|
});
|
|
917
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Executes multiple requests concurrently with controlled concurrency
|
|
246
|
+
* @param requests - Array of request options to execute
|
|
247
|
+
* @param options - Concurrency control options
|
|
248
|
+
* @returns Promise resolving to array of response data
|
|
249
|
+
*/
|
|
918
250
|
async concurrent(requests, options) {
|
|
919
|
-
const chunks =
|
|
251
|
+
const chunks = chunk(requests, options.concurrency ?? 10);
|
|
920
252
|
const skipErrors = options.skipErrors ?? false;
|
|
921
253
|
const results = [];
|
|
922
|
-
for (const
|
|
254
|
+
for (const chunk2 of chunks) {
|
|
923
255
|
const responses = await Promise.allSettled(
|
|
924
|
-
|
|
256
|
+
chunk2.map(
|
|
925
257
|
(opt) => request({
|
|
926
258
|
...opt,
|
|
927
259
|
...this.config
|
|
@@ -942,6 +274,11 @@ var BigCommerceClient = class {
|
|
|
942
274
|
}
|
|
943
275
|
return results;
|
|
944
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Collects all pages of data from a paginated v3 API endpoint
|
|
279
|
+
* @param options - Request options with pagination parameters
|
|
280
|
+
* @returns Promise resolving to array of all items across all pages
|
|
281
|
+
*/
|
|
945
282
|
async collect(options) {
|
|
946
283
|
if (options.query) {
|
|
947
284
|
if (!options.query.limit) {
|
|
@@ -956,7 +293,7 @@ var BigCommerceClient = class {
|
|
|
956
293
|
}
|
|
957
294
|
const results = [...first.data];
|
|
958
295
|
const pages = first.meta.pagination.total_pages;
|
|
959
|
-
const remainingPages =
|
|
296
|
+
const remainingPages = range(2, pages + 1);
|
|
960
297
|
const requests = remainingPages.map((page) => ({
|
|
961
298
|
...options,
|
|
962
299
|
query: { ...options.query, page: page.toString() }
|
|
@@ -967,6 +304,11 @@ var BigCommerceClient = class {
|
|
|
967
304
|
});
|
|
968
305
|
return results;
|
|
969
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* Collects all pages of data from a paginated v2 API endpoint
|
|
309
|
+
* @param options - Request options with pagination parameters
|
|
310
|
+
* @returns Promise resolving to array of all items across all pages
|
|
311
|
+
*/
|
|
970
312
|
async collectV2(options) {
|
|
971
313
|
if (options.query) {
|
|
972
314
|
if (!options.query.limit) {
|
|
@@ -980,7 +322,7 @@ var BigCommerceClient = class {
|
|
|
980
322
|
let page = 1;
|
|
981
323
|
const concurrency = options.concurrency ?? 10;
|
|
982
324
|
while (!done) {
|
|
983
|
-
const pages =
|
|
325
|
+
const pages = range(page, page + concurrency);
|
|
984
326
|
page += concurrency;
|
|
985
327
|
const requests = pages.map((page2) => ({
|
|
986
328
|
...options,
|
|
@@ -1010,6 +352,11 @@ var BigCommerceClient = class {
|
|
|
1010
352
|
}
|
|
1011
353
|
return results;
|
|
1012
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Queries multiple values against a single field using the v3 API
|
|
357
|
+
* @param options - Query options including field name and values
|
|
358
|
+
* @returns Promise resolving to array of matching items
|
|
359
|
+
*/
|
|
1013
360
|
async query(options) {
|
|
1014
361
|
if (options.query) {
|
|
1015
362
|
if (!options.query.limit) {
|
|
@@ -1018,1081 +365,26 @@ var BigCommerceClient = class {
|
|
|
1018
365
|
} else {
|
|
1019
366
|
options.query = { limit: MAX_PAGE_SIZE.toString() };
|
|
1020
367
|
}
|
|
368
|
+
const { limit: _, ...restQuery } = options.query;
|
|
369
|
+
const fullUrl = `${BASE_URL}${this.config.storeHash}/v3/${options.endpoint}?${new URLSearchParams(restQuery).toString()}`;
|
|
1021
370
|
const queryStr = options.values.map((value) => `${value}`);
|
|
1022
371
|
const chunks = chunkStrLength(queryStr, {
|
|
1023
|
-
|
|
372
|
+
offset: fullUrl.length,
|
|
373
|
+
chunkLength: Number.parseInt(options.query?.limit) || MAX_PAGE_SIZE
|
|
1024
374
|
});
|
|
1025
|
-
const requests = chunks.map((
|
|
375
|
+
const requests = chunks.map((chunk2) => ({
|
|
1026
376
|
...options,
|
|
1027
|
-
query: { ...options.query, [options.key]:
|
|
377
|
+
query: { ...options.query, [options.key]: chunk2.join(",") }
|
|
1028
378
|
}));
|
|
1029
379
|
const responses = await this.concurrent(requests, options);
|
|
1030
380
|
return responses.flatMap((response) => response.data);
|
|
1031
381
|
}
|
|
1032
382
|
};
|
|
1033
383
|
|
|
1034
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
1035
|
-
var encoder = new TextEncoder();
|
|
1036
|
-
var decoder = new TextDecoder();
|
|
1037
|
-
var MAX_INT32 = 2 ** 32;
|
|
1038
|
-
function concat(...buffers) {
|
|
1039
|
-
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
1040
|
-
const buf = new Uint8Array(size);
|
|
1041
|
-
let i2 = 0;
|
|
1042
|
-
for (const buffer of buffers) {
|
|
1043
|
-
buf.set(buffer, i2);
|
|
1044
|
-
i2 += buffer.length;
|
|
1045
|
-
}
|
|
1046
|
-
return buf;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/base64.js
|
|
1050
|
-
function decodeBase64(encoded) {
|
|
1051
|
-
if (Uint8Array.fromBase64) {
|
|
1052
|
-
return Uint8Array.fromBase64(encoded);
|
|
1053
|
-
}
|
|
1054
|
-
const binary = atob(encoded);
|
|
1055
|
-
const bytes = new Uint8Array(binary.length);
|
|
1056
|
-
for (let i2 = 0; i2 < binary.length; i2++) {
|
|
1057
|
-
bytes[i2] = binary.charCodeAt(i2);
|
|
1058
|
-
}
|
|
1059
|
-
return bytes;
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/util/base64url.js
|
|
1063
|
-
function decode(input) {
|
|
1064
|
-
if (Uint8Array.fromBase64) {
|
|
1065
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
1066
|
-
alphabet: "base64url"
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
let encoded = input;
|
|
1070
|
-
if (encoded instanceof Uint8Array) {
|
|
1071
|
-
encoded = decoder.decode(encoded);
|
|
1072
|
-
}
|
|
1073
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
1074
|
-
try {
|
|
1075
|
-
return decodeBase64(encoded);
|
|
1076
|
-
} catch {
|
|
1077
|
-
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/util/errors.js
|
|
1082
|
-
var JOSEError = class extends Error {
|
|
1083
|
-
static code = "ERR_JOSE_GENERIC";
|
|
1084
|
-
code = "ERR_JOSE_GENERIC";
|
|
1085
|
-
constructor(message2, options) {
|
|
1086
|
-
super(message2, options);
|
|
1087
|
-
this.name = this.constructor.name;
|
|
1088
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
1089
|
-
}
|
|
1090
|
-
};
|
|
1091
|
-
var JWTClaimValidationFailed = class extends JOSEError {
|
|
1092
|
-
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
1093
|
-
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
1094
|
-
claim;
|
|
1095
|
-
reason;
|
|
1096
|
-
payload;
|
|
1097
|
-
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
1098
|
-
super(message2, { cause: { claim, reason, payload } });
|
|
1099
|
-
this.claim = claim;
|
|
1100
|
-
this.reason = reason;
|
|
1101
|
-
this.payload = payload;
|
|
1102
|
-
}
|
|
1103
|
-
};
|
|
1104
|
-
var JWTExpired = class extends JOSEError {
|
|
1105
|
-
static code = "ERR_JWT_EXPIRED";
|
|
1106
|
-
code = "ERR_JWT_EXPIRED";
|
|
1107
|
-
claim;
|
|
1108
|
-
reason;
|
|
1109
|
-
payload;
|
|
1110
|
-
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
1111
|
-
super(message2, { cause: { claim, reason, payload } });
|
|
1112
|
-
this.claim = claim;
|
|
1113
|
-
this.reason = reason;
|
|
1114
|
-
this.payload = payload;
|
|
1115
|
-
}
|
|
1116
|
-
};
|
|
1117
|
-
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
1118
|
-
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
1119
|
-
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
1120
|
-
};
|
|
1121
|
-
var JOSENotSupported = class extends JOSEError {
|
|
1122
|
-
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
1123
|
-
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
1124
|
-
};
|
|
1125
|
-
var JWSInvalid = class extends JOSEError {
|
|
1126
|
-
static code = "ERR_JWS_INVALID";
|
|
1127
|
-
code = "ERR_JWS_INVALID";
|
|
1128
|
-
};
|
|
1129
|
-
var JWTInvalid = class extends JOSEError {
|
|
1130
|
-
static code = "ERR_JWT_INVALID";
|
|
1131
|
-
code = "ERR_JWT_INVALID";
|
|
1132
|
-
};
|
|
1133
|
-
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
1134
|
-
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
1135
|
-
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
1136
|
-
constructor(message2 = "signature verification failed", options) {
|
|
1137
|
-
super(message2, options);
|
|
1138
|
-
}
|
|
1139
|
-
};
|
|
1140
|
-
|
|
1141
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
1142
|
-
function unusable(name, prop = "algorithm.name") {
|
|
1143
|
-
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
1144
|
-
}
|
|
1145
|
-
function isAlgorithm(algorithm, name) {
|
|
1146
|
-
return algorithm.name === name;
|
|
1147
|
-
}
|
|
1148
|
-
function getHashLength(hash) {
|
|
1149
|
-
return parseInt(hash.name.slice(4), 10);
|
|
1150
|
-
}
|
|
1151
|
-
function getNamedCurve(alg) {
|
|
1152
|
-
switch (alg) {
|
|
1153
|
-
case "ES256":
|
|
1154
|
-
return "P-256";
|
|
1155
|
-
case "ES384":
|
|
1156
|
-
return "P-384";
|
|
1157
|
-
case "ES512":
|
|
1158
|
-
return "P-521";
|
|
1159
|
-
default:
|
|
1160
|
-
throw new Error("unreachable");
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
function checkUsage(key, usage) {
|
|
1164
|
-
if (usage && !key.usages.includes(usage)) {
|
|
1165
|
-
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
function checkSigCryptoKey(key, alg, usage) {
|
|
1169
|
-
switch (alg) {
|
|
1170
|
-
case "HS256":
|
|
1171
|
-
case "HS384":
|
|
1172
|
-
case "HS512": {
|
|
1173
|
-
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
1174
|
-
throw unusable("HMAC");
|
|
1175
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
1176
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
1177
|
-
if (actual !== expected)
|
|
1178
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
1179
|
-
break;
|
|
1180
|
-
}
|
|
1181
|
-
case "RS256":
|
|
1182
|
-
case "RS384":
|
|
1183
|
-
case "RS512": {
|
|
1184
|
-
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
1185
|
-
throw unusable("RSASSA-PKCS1-v1_5");
|
|
1186
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
1187
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
1188
|
-
if (actual !== expected)
|
|
1189
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
1190
|
-
break;
|
|
1191
|
-
}
|
|
1192
|
-
case "PS256":
|
|
1193
|
-
case "PS384":
|
|
1194
|
-
case "PS512": {
|
|
1195
|
-
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
1196
|
-
throw unusable("RSA-PSS");
|
|
1197
|
-
const expected = parseInt(alg.slice(2), 10);
|
|
1198
|
-
const actual = getHashLength(key.algorithm.hash);
|
|
1199
|
-
if (actual !== expected)
|
|
1200
|
-
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
1201
|
-
break;
|
|
1202
|
-
}
|
|
1203
|
-
case "Ed25519":
|
|
1204
|
-
case "EdDSA": {
|
|
1205
|
-
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
1206
|
-
throw unusable("Ed25519");
|
|
1207
|
-
break;
|
|
1208
|
-
}
|
|
1209
|
-
case "ES256":
|
|
1210
|
-
case "ES384":
|
|
1211
|
-
case "ES512": {
|
|
1212
|
-
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
1213
|
-
throw unusable("ECDSA");
|
|
1214
|
-
const expected = getNamedCurve(alg);
|
|
1215
|
-
const actual = key.algorithm.namedCurve;
|
|
1216
|
-
if (actual !== expected)
|
|
1217
|
-
throw unusable(expected, "algorithm.namedCurve");
|
|
1218
|
-
break;
|
|
1219
|
-
}
|
|
1220
|
-
default:
|
|
1221
|
-
throw new TypeError("CryptoKey does not support this operation");
|
|
1222
|
-
}
|
|
1223
|
-
checkUsage(key, usage);
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
1227
|
-
function message(msg, actual, ...types) {
|
|
1228
|
-
types = types.filter(Boolean);
|
|
1229
|
-
if (types.length > 2) {
|
|
1230
|
-
const last = types.pop();
|
|
1231
|
-
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
1232
|
-
} else if (types.length === 2) {
|
|
1233
|
-
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
1234
|
-
} else {
|
|
1235
|
-
msg += `of type ${types[0]}.`;
|
|
1236
|
-
}
|
|
1237
|
-
if (actual == null) {
|
|
1238
|
-
msg += ` Received ${actual}`;
|
|
1239
|
-
} else if (typeof actual === "function" && actual.name) {
|
|
1240
|
-
msg += ` Received function ${actual.name}`;
|
|
1241
|
-
} else if (typeof actual === "object" && actual != null) {
|
|
1242
|
-
if (actual.constructor?.name) {
|
|
1243
|
-
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
return msg;
|
|
1247
|
-
}
|
|
1248
|
-
var invalid_key_input_default = (actual, ...types) => {
|
|
1249
|
-
return message("Key must be ", actual, ...types);
|
|
1250
|
-
};
|
|
1251
|
-
function withAlg(alg, actual, ...types) {
|
|
1252
|
-
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
1256
|
-
function isCryptoKey(key) {
|
|
1257
|
-
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
1258
|
-
}
|
|
1259
|
-
function isKeyObject(key) {
|
|
1260
|
-
return key?.[Symbol.toStringTag] === "KeyObject";
|
|
1261
|
-
}
|
|
1262
|
-
var is_key_like_default = (key) => {
|
|
1263
|
-
return isCryptoKey(key) || isKeyObject(key);
|
|
1264
|
-
};
|
|
1265
|
-
|
|
1266
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
1267
|
-
var is_disjoint_default = (...headers) => {
|
|
1268
|
-
const sources = headers.filter(Boolean);
|
|
1269
|
-
if (sources.length === 0 || sources.length === 1) {
|
|
1270
|
-
return true;
|
|
1271
|
-
}
|
|
1272
|
-
let acc;
|
|
1273
|
-
for (const header of sources) {
|
|
1274
|
-
const parameters = Object.keys(header);
|
|
1275
|
-
if (!acc || acc.size === 0) {
|
|
1276
|
-
acc = new Set(parameters);
|
|
1277
|
-
continue;
|
|
1278
|
-
}
|
|
1279
|
-
for (const parameter of parameters) {
|
|
1280
|
-
if (acc.has(parameter)) {
|
|
1281
|
-
return false;
|
|
1282
|
-
}
|
|
1283
|
-
acc.add(parameter);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
return true;
|
|
1287
|
-
};
|
|
1288
|
-
|
|
1289
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/is_object.js
|
|
1290
|
-
function isObjectLike(value) {
|
|
1291
|
-
return typeof value === "object" && value !== null;
|
|
1292
|
-
}
|
|
1293
|
-
var is_object_default = (input) => {
|
|
1294
|
-
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
1295
|
-
return false;
|
|
1296
|
-
}
|
|
1297
|
-
if (Object.getPrototypeOf(input) === null) {
|
|
1298
|
-
return true;
|
|
1299
|
-
}
|
|
1300
|
-
let proto = input;
|
|
1301
|
-
while (Object.getPrototypeOf(proto) !== null) {
|
|
1302
|
-
proto = Object.getPrototypeOf(proto);
|
|
1303
|
-
}
|
|
1304
|
-
return Object.getPrototypeOf(input) === proto;
|
|
1305
|
-
};
|
|
1306
|
-
|
|
1307
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
1308
|
-
var check_key_length_default = (alg, key) => {
|
|
1309
|
-
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
1310
|
-
const { modulusLength } = key.algorithm;
|
|
1311
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
1312
|
-
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
};
|
|
1316
|
-
|
|
1317
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
1318
|
-
function subtleMapping(jwk) {
|
|
1319
|
-
let algorithm;
|
|
1320
|
-
let keyUsages;
|
|
1321
|
-
switch (jwk.kty) {
|
|
1322
|
-
case "RSA": {
|
|
1323
|
-
switch (jwk.alg) {
|
|
1324
|
-
case "PS256":
|
|
1325
|
-
case "PS384":
|
|
1326
|
-
case "PS512":
|
|
1327
|
-
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1328
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1329
|
-
break;
|
|
1330
|
-
case "RS256":
|
|
1331
|
-
case "RS384":
|
|
1332
|
-
case "RS512":
|
|
1333
|
-
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
1334
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1335
|
-
break;
|
|
1336
|
-
case "RSA-OAEP":
|
|
1337
|
-
case "RSA-OAEP-256":
|
|
1338
|
-
case "RSA-OAEP-384":
|
|
1339
|
-
case "RSA-OAEP-512":
|
|
1340
|
-
algorithm = {
|
|
1341
|
-
name: "RSA-OAEP",
|
|
1342
|
-
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
1343
|
-
};
|
|
1344
|
-
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
1345
|
-
break;
|
|
1346
|
-
default:
|
|
1347
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1348
|
-
}
|
|
1349
|
-
break;
|
|
1350
|
-
}
|
|
1351
|
-
case "EC": {
|
|
1352
|
-
switch (jwk.alg) {
|
|
1353
|
-
case "ES256":
|
|
1354
|
-
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
1355
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1356
|
-
break;
|
|
1357
|
-
case "ES384":
|
|
1358
|
-
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
1359
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1360
|
-
break;
|
|
1361
|
-
case "ES512":
|
|
1362
|
-
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
1363
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1364
|
-
break;
|
|
1365
|
-
case "ECDH-ES":
|
|
1366
|
-
case "ECDH-ES+A128KW":
|
|
1367
|
-
case "ECDH-ES+A192KW":
|
|
1368
|
-
case "ECDH-ES+A256KW":
|
|
1369
|
-
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
1370
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1371
|
-
break;
|
|
1372
|
-
default:
|
|
1373
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1374
|
-
}
|
|
1375
|
-
break;
|
|
1376
|
-
}
|
|
1377
|
-
case "OKP": {
|
|
1378
|
-
switch (jwk.alg) {
|
|
1379
|
-
case "Ed25519":
|
|
1380
|
-
case "EdDSA":
|
|
1381
|
-
algorithm = { name: "Ed25519" };
|
|
1382
|
-
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
1383
|
-
break;
|
|
1384
|
-
case "ECDH-ES":
|
|
1385
|
-
case "ECDH-ES+A128KW":
|
|
1386
|
-
case "ECDH-ES+A192KW":
|
|
1387
|
-
case "ECDH-ES+A256KW":
|
|
1388
|
-
algorithm = { name: jwk.crv };
|
|
1389
|
-
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
1390
|
-
break;
|
|
1391
|
-
default:
|
|
1392
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
1393
|
-
}
|
|
1394
|
-
break;
|
|
1395
|
-
}
|
|
1396
|
-
default:
|
|
1397
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
1398
|
-
}
|
|
1399
|
-
return { algorithm, keyUsages };
|
|
1400
|
-
}
|
|
1401
|
-
var jwk_to_key_default = async (jwk) => {
|
|
1402
|
-
if (!jwk.alg) {
|
|
1403
|
-
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
1404
|
-
}
|
|
1405
|
-
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
1406
|
-
const keyData = { ...jwk };
|
|
1407
|
-
delete keyData.alg;
|
|
1408
|
-
delete keyData.use;
|
|
1409
|
-
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d ? false : true), jwk.key_ops ?? keyUsages);
|
|
1410
|
-
};
|
|
1411
|
-
|
|
1412
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
1413
|
-
var validate_crit_default = (Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) => {
|
|
1414
|
-
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
1415
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
1416
|
-
}
|
|
1417
|
-
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
1418
|
-
return /* @__PURE__ */ new Set();
|
|
1419
|
-
}
|
|
1420
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
1421
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
1422
|
-
}
|
|
1423
|
-
let recognized;
|
|
1424
|
-
if (recognizedOption !== void 0) {
|
|
1425
|
-
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
1426
|
-
} else {
|
|
1427
|
-
recognized = recognizedDefault;
|
|
1428
|
-
}
|
|
1429
|
-
for (const parameter of protectedHeader.crit) {
|
|
1430
|
-
if (!recognized.has(parameter)) {
|
|
1431
|
-
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1432
|
-
}
|
|
1433
|
-
if (joseHeader[parameter] === void 0) {
|
|
1434
|
-
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1435
|
-
}
|
|
1436
|
-
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
1437
|
-
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
return new Set(protectedHeader.crit);
|
|
1441
|
-
};
|
|
1442
|
-
|
|
1443
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
1444
|
-
var validate_algorithms_default = (option, algorithms) => {
|
|
1445
|
-
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s4) => typeof s4 !== "string"))) {
|
|
1446
|
-
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
1447
|
-
}
|
|
1448
|
-
if (!algorithms) {
|
|
1449
|
-
return void 0;
|
|
1450
|
-
}
|
|
1451
|
-
return new Set(algorithms);
|
|
1452
|
-
};
|
|
1453
|
-
|
|
1454
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
1455
|
-
function isJWK(key) {
|
|
1456
|
-
return is_object_default(key) && typeof key.kty === "string";
|
|
1457
|
-
}
|
|
1458
|
-
function isPrivateJWK(key) {
|
|
1459
|
-
return key.kty !== "oct" && typeof key.d === "string";
|
|
1460
|
-
}
|
|
1461
|
-
function isPublicJWK(key) {
|
|
1462
|
-
return key.kty !== "oct" && typeof key.d === "undefined";
|
|
1463
|
-
}
|
|
1464
|
-
function isSecretJWK(key) {
|
|
1465
|
-
return key.kty === "oct" && typeof key.k === "string";
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
1469
|
-
var cache;
|
|
1470
|
-
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
1471
|
-
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1472
|
-
let cached = cache.get(key);
|
|
1473
|
-
if (cached?.[alg]) {
|
|
1474
|
-
return cached[alg];
|
|
1475
|
-
}
|
|
1476
|
-
const cryptoKey = await jwk_to_key_default({ ...jwk, alg });
|
|
1477
|
-
if (freeze)
|
|
1478
|
-
Object.freeze(key);
|
|
1479
|
-
if (!cached) {
|
|
1480
|
-
cache.set(key, { [alg]: cryptoKey });
|
|
1481
|
-
} else {
|
|
1482
|
-
cached[alg] = cryptoKey;
|
|
1483
|
-
}
|
|
1484
|
-
return cryptoKey;
|
|
1485
|
-
};
|
|
1486
|
-
var handleKeyObject = (keyObject, alg) => {
|
|
1487
|
-
cache ||= /* @__PURE__ */ new WeakMap();
|
|
1488
|
-
let cached = cache.get(keyObject);
|
|
1489
|
-
if (cached?.[alg]) {
|
|
1490
|
-
return cached[alg];
|
|
1491
|
-
}
|
|
1492
|
-
const isPublic = keyObject.type === "public";
|
|
1493
|
-
const extractable = isPublic ? true : false;
|
|
1494
|
-
let cryptoKey;
|
|
1495
|
-
if (keyObject.asymmetricKeyType === "x25519") {
|
|
1496
|
-
switch (alg) {
|
|
1497
|
-
case "ECDH-ES":
|
|
1498
|
-
case "ECDH-ES+A128KW":
|
|
1499
|
-
case "ECDH-ES+A192KW":
|
|
1500
|
-
case "ECDH-ES+A256KW":
|
|
1501
|
-
break;
|
|
1502
|
-
default:
|
|
1503
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1504
|
-
}
|
|
1505
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1506
|
-
}
|
|
1507
|
-
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
1508
|
-
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
1509
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1510
|
-
}
|
|
1511
|
-
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
1512
|
-
isPublic ? "verify" : "sign"
|
|
1513
|
-
]);
|
|
1514
|
-
}
|
|
1515
|
-
if (keyObject.asymmetricKeyType === "rsa") {
|
|
1516
|
-
let hash;
|
|
1517
|
-
switch (alg) {
|
|
1518
|
-
case "RSA-OAEP":
|
|
1519
|
-
hash = "SHA-1";
|
|
1520
|
-
break;
|
|
1521
|
-
case "RS256":
|
|
1522
|
-
case "PS256":
|
|
1523
|
-
case "RSA-OAEP-256":
|
|
1524
|
-
hash = "SHA-256";
|
|
1525
|
-
break;
|
|
1526
|
-
case "RS384":
|
|
1527
|
-
case "PS384":
|
|
1528
|
-
case "RSA-OAEP-384":
|
|
1529
|
-
hash = "SHA-384";
|
|
1530
|
-
break;
|
|
1531
|
-
case "RS512":
|
|
1532
|
-
case "PS512":
|
|
1533
|
-
case "RSA-OAEP-512":
|
|
1534
|
-
hash = "SHA-512";
|
|
1535
|
-
break;
|
|
1536
|
-
default:
|
|
1537
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1538
|
-
}
|
|
1539
|
-
if (alg.startsWith("RSA-OAEP")) {
|
|
1540
|
-
return keyObject.toCryptoKey({
|
|
1541
|
-
name: "RSA-OAEP",
|
|
1542
|
-
hash
|
|
1543
|
-
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
1544
|
-
}
|
|
1545
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1546
|
-
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
1547
|
-
hash
|
|
1548
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1549
|
-
}
|
|
1550
|
-
if (keyObject.asymmetricKeyType === "ec") {
|
|
1551
|
-
const nist = /* @__PURE__ */ new Map([
|
|
1552
|
-
["prime256v1", "P-256"],
|
|
1553
|
-
["secp384r1", "P-384"],
|
|
1554
|
-
["secp521r1", "P-521"]
|
|
1555
|
-
]);
|
|
1556
|
-
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
1557
|
-
if (!namedCurve) {
|
|
1558
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1559
|
-
}
|
|
1560
|
-
if (alg === "ES256" && namedCurve === "P-256") {
|
|
1561
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1562
|
-
name: "ECDSA",
|
|
1563
|
-
namedCurve
|
|
1564
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1565
|
-
}
|
|
1566
|
-
if (alg === "ES384" && namedCurve === "P-384") {
|
|
1567
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1568
|
-
name: "ECDSA",
|
|
1569
|
-
namedCurve
|
|
1570
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1571
|
-
}
|
|
1572
|
-
if (alg === "ES512" && namedCurve === "P-521") {
|
|
1573
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1574
|
-
name: "ECDSA",
|
|
1575
|
-
namedCurve
|
|
1576
|
-
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
1577
|
-
}
|
|
1578
|
-
if (alg.startsWith("ECDH-ES")) {
|
|
1579
|
-
cryptoKey = keyObject.toCryptoKey({
|
|
1580
|
-
name: "ECDH",
|
|
1581
|
-
namedCurve
|
|
1582
|
-
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
if (!cryptoKey) {
|
|
1586
|
-
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
1587
|
-
}
|
|
1588
|
-
if (!cached) {
|
|
1589
|
-
cache.set(keyObject, { [alg]: cryptoKey });
|
|
1590
|
-
} else {
|
|
1591
|
-
cached[alg] = cryptoKey;
|
|
1592
|
-
}
|
|
1593
|
-
return cryptoKey;
|
|
1594
|
-
};
|
|
1595
|
-
var normalize_key_default = async (key, alg) => {
|
|
1596
|
-
if (key instanceof Uint8Array) {
|
|
1597
|
-
return key;
|
|
1598
|
-
}
|
|
1599
|
-
if (isCryptoKey(key)) {
|
|
1600
|
-
return key;
|
|
1601
|
-
}
|
|
1602
|
-
if (isKeyObject(key)) {
|
|
1603
|
-
if (key.type === "secret") {
|
|
1604
|
-
return key.export();
|
|
1605
|
-
}
|
|
1606
|
-
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
1607
|
-
try {
|
|
1608
|
-
return handleKeyObject(key, alg);
|
|
1609
|
-
} catch (err) {
|
|
1610
|
-
if (err instanceof TypeError) {
|
|
1611
|
-
throw err;
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
let jwk = key.export({ format: "jwk" });
|
|
1616
|
-
return handleJWK(key, jwk, alg);
|
|
1617
|
-
}
|
|
1618
|
-
if (isJWK(key)) {
|
|
1619
|
-
if (key.k) {
|
|
1620
|
-
return decode(key.k);
|
|
1621
|
-
}
|
|
1622
|
-
return handleJWK(key, key, alg, true);
|
|
1623
|
-
}
|
|
1624
|
-
throw new Error("unreachable");
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
1628
|
-
var tag = (key) => key?.[Symbol.toStringTag];
|
|
1629
|
-
var jwkMatchesOp = (alg, key, usage) => {
|
|
1630
|
-
if (key.use !== void 0) {
|
|
1631
|
-
let expected;
|
|
1632
|
-
switch (usage) {
|
|
1633
|
-
case "sign":
|
|
1634
|
-
case "verify":
|
|
1635
|
-
expected = "sig";
|
|
1636
|
-
break;
|
|
1637
|
-
case "encrypt":
|
|
1638
|
-
case "decrypt":
|
|
1639
|
-
expected = "enc";
|
|
1640
|
-
break;
|
|
1641
|
-
}
|
|
1642
|
-
if (key.use !== expected) {
|
|
1643
|
-
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
if (key.alg !== void 0 && key.alg !== alg) {
|
|
1647
|
-
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
1648
|
-
}
|
|
1649
|
-
if (Array.isArray(key.key_ops)) {
|
|
1650
|
-
let expectedKeyOp;
|
|
1651
|
-
switch (true) {
|
|
1652
|
-
case (usage === "sign" || usage === "verify"):
|
|
1653
|
-
case alg === "dir":
|
|
1654
|
-
case alg.includes("CBC-HS"):
|
|
1655
|
-
expectedKeyOp = usage;
|
|
1656
|
-
break;
|
|
1657
|
-
case alg.startsWith("PBES2"):
|
|
1658
|
-
expectedKeyOp = "deriveBits";
|
|
1659
|
-
break;
|
|
1660
|
-
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
1661
|
-
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
1662
|
-
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
1663
|
-
} else {
|
|
1664
|
-
expectedKeyOp = usage;
|
|
1665
|
-
}
|
|
1666
|
-
break;
|
|
1667
|
-
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
1668
|
-
expectedKeyOp = "wrapKey";
|
|
1669
|
-
break;
|
|
1670
|
-
case usage === "decrypt":
|
|
1671
|
-
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
1672
|
-
break;
|
|
1673
|
-
}
|
|
1674
|
-
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
1675
|
-
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
return true;
|
|
1679
|
-
};
|
|
1680
|
-
var symmetricTypeCheck = (alg, key, usage) => {
|
|
1681
|
-
if (key instanceof Uint8Array)
|
|
1682
|
-
return;
|
|
1683
|
-
if (isJWK(key)) {
|
|
1684
|
-
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1685
|
-
return;
|
|
1686
|
-
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
1687
|
-
}
|
|
1688
|
-
if (!is_key_like_default(key)) {
|
|
1689
|
-
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
1690
|
-
}
|
|
1691
|
-
if (key.type !== "secret") {
|
|
1692
|
-
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
1693
|
-
}
|
|
1694
|
-
};
|
|
1695
|
-
var asymmetricTypeCheck = (alg, key, usage) => {
|
|
1696
|
-
if (isJWK(key)) {
|
|
1697
|
-
switch (usage) {
|
|
1698
|
-
case "decrypt":
|
|
1699
|
-
case "sign":
|
|
1700
|
-
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1701
|
-
return;
|
|
1702
|
-
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
1703
|
-
case "encrypt":
|
|
1704
|
-
case "verify":
|
|
1705
|
-
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
1706
|
-
return;
|
|
1707
|
-
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
1708
|
-
}
|
|
1709
|
-
}
|
|
1710
|
-
if (!is_key_like_default(key)) {
|
|
1711
|
-
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1712
|
-
}
|
|
1713
|
-
if (key.type === "secret") {
|
|
1714
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
1715
|
-
}
|
|
1716
|
-
if (key.type === "public") {
|
|
1717
|
-
switch (usage) {
|
|
1718
|
-
case "sign":
|
|
1719
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
1720
|
-
case "decrypt":
|
|
1721
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
1722
|
-
default:
|
|
1723
|
-
break;
|
|
1724
|
-
}
|
|
1725
|
-
}
|
|
1726
|
-
if (key.type === "private") {
|
|
1727
|
-
switch (usage) {
|
|
1728
|
-
case "verify":
|
|
1729
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
1730
|
-
case "encrypt":
|
|
1731
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
1732
|
-
default:
|
|
1733
|
-
break;
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
};
|
|
1737
|
-
var check_key_type_default = (alg, key, usage) => {
|
|
1738
|
-
const symmetric = alg.startsWith("HS") || alg === "dir" || alg.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(alg) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(alg);
|
|
1739
|
-
if (symmetric) {
|
|
1740
|
-
symmetricTypeCheck(alg, key, usage);
|
|
1741
|
-
} else {
|
|
1742
|
-
asymmetricTypeCheck(alg, key, usage);
|
|
1743
|
-
}
|
|
1744
|
-
};
|
|
1745
|
-
|
|
1746
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
1747
|
-
var subtle_dsa_default = (alg, algorithm) => {
|
|
1748
|
-
const hash = `SHA-${alg.slice(-3)}`;
|
|
1749
|
-
switch (alg) {
|
|
1750
|
-
case "HS256":
|
|
1751
|
-
case "HS384":
|
|
1752
|
-
case "HS512":
|
|
1753
|
-
return { hash, name: "HMAC" };
|
|
1754
|
-
case "PS256":
|
|
1755
|
-
case "PS384":
|
|
1756
|
-
case "PS512":
|
|
1757
|
-
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
1758
|
-
case "RS256":
|
|
1759
|
-
case "RS384":
|
|
1760
|
-
case "RS512":
|
|
1761
|
-
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
1762
|
-
case "ES256":
|
|
1763
|
-
case "ES384":
|
|
1764
|
-
case "ES512":
|
|
1765
|
-
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
1766
|
-
case "Ed25519":
|
|
1767
|
-
case "EdDSA":
|
|
1768
|
-
return { name: "Ed25519" };
|
|
1769
|
-
default:
|
|
1770
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
1771
|
-
}
|
|
1772
|
-
};
|
|
1773
|
-
|
|
1774
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
1775
|
-
var get_sign_verify_key_default = async (alg, key, usage) => {
|
|
1776
|
-
if (key instanceof Uint8Array) {
|
|
1777
|
-
if (!alg.startsWith("HS")) {
|
|
1778
|
-
throw new TypeError(invalid_key_input_default(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
1779
|
-
}
|
|
1780
|
-
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
1781
|
-
}
|
|
1782
|
-
checkSigCryptoKey(key, alg, usage);
|
|
1783
|
-
return key;
|
|
1784
|
-
};
|
|
1785
|
-
|
|
1786
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/verify.js
|
|
1787
|
-
var verify_default = async (alg, key, signature, data) => {
|
|
1788
|
-
const cryptoKey = await get_sign_verify_key_default(alg, key, "verify");
|
|
1789
|
-
check_key_length_default(alg, cryptoKey);
|
|
1790
|
-
const algorithm = subtle_dsa_default(alg, cryptoKey.algorithm);
|
|
1791
|
-
try {
|
|
1792
|
-
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
1793
|
-
} catch {
|
|
1794
|
-
return false;
|
|
1795
|
-
}
|
|
1796
|
-
};
|
|
1797
|
-
|
|
1798
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
1799
|
-
async function flattenedVerify(jws, key, options) {
|
|
1800
|
-
if (!is_object_default(jws)) {
|
|
1801
|
-
throw new JWSInvalid("Flattened JWS must be an object");
|
|
1802
|
-
}
|
|
1803
|
-
if (jws.protected === void 0 && jws.header === void 0) {
|
|
1804
|
-
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
1805
|
-
}
|
|
1806
|
-
if (jws.protected !== void 0 && typeof jws.protected !== "string") {
|
|
1807
|
-
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
1808
|
-
}
|
|
1809
|
-
if (jws.payload === void 0) {
|
|
1810
|
-
throw new JWSInvalid("JWS Payload missing");
|
|
1811
|
-
}
|
|
1812
|
-
if (typeof jws.signature !== "string") {
|
|
1813
|
-
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
1814
|
-
}
|
|
1815
|
-
if (jws.header !== void 0 && !is_object_default(jws.header)) {
|
|
1816
|
-
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
1817
|
-
}
|
|
1818
|
-
let parsedProt = {};
|
|
1819
|
-
if (jws.protected) {
|
|
1820
|
-
try {
|
|
1821
|
-
const protectedHeader = decode(jws.protected);
|
|
1822
|
-
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
1823
|
-
} catch {
|
|
1824
|
-
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
if (!is_disjoint_default(parsedProt, jws.header)) {
|
|
1828
|
-
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
1829
|
-
}
|
|
1830
|
-
const joseHeader = {
|
|
1831
|
-
...parsedProt,
|
|
1832
|
-
...jws.header
|
|
1833
|
-
};
|
|
1834
|
-
const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
1835
|
-
let b64 = true;
|
|
1836
|
-
if (extensions.has("b64")) {
|
|
1837
|
-
b64 = parsedProt.b64;
|
|
1838
|
-
if (typeof b64 !== "boolean") {
|
|
1839
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
1840
|
-
}
|
|
1841
|
-
}
|
|
1842
|
-
const { alg } = joseHeader;
|
|
1843
|
-
if (typeof alg !== "string" || !alg) {
|
|
1844
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
1845
|
-
}
|
|
1846
|
-
const algorithms = options && validate_algorithms_default("algorithms", options.algorithms);
|
|
1847
|
-
if (algorithms && !algorithms.has(alg)) {
|
|
1848
|
-
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
1849
|
-
}
|
|
1850
|
-
if (b64) {
|
|
1851
|
-
if (typeof jws.payload !== "string") {
|
|
1852
|
-
throw new JWSInvalid("JWS Payload must be a string");
|
|
1853
|
-
}
|
|
1854
|
-
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
|
|
1855
|
-
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
1856
|
-
}
|
|
1857
|
-
let resolvedKey = false;
|
|
1858
|
-
if (typeof key === "function") {
|
|
1859
|
-
key = await key(parsedProt, jws);
|
|
1860
|
-
resolvedKey = true;
|
|
1861
|
-
}
|
|
1862
|
-
check_key_type_default(alg, key, "verify");
|
|
1863
|
-
const data = concat(encoder.encode(jws.protected ?? ""), encoder.encode("."), typeof jws.payload === "string" ? encoder.encode(jws.payload) : jws.payload);
|
|
1864
|
-
let signature;
|
|
1865
|
-
try {
|
|
1866
|
-
signature = decode(jws.signature);
|
|
1867
|
-
} catch {
|
|
1868
|
-
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
1869
|
-
}
|
|
1870
|
-
const k = await normalize_key_default(key, alg);
|
|
1871
|
-
const verified = await verify_default(alg, k, signature, data);
|
|
1872
|
-
if (!verified) {
|
|
1873
|
-
throw new JWSSignatureVerificationFailed();
|
|
1874
|
-
}
|
|
1875
|
-
let payload;
|
|
1876
|
-
if (b64) {
|
|
1877
|
-
try {
|
|
1878
|
-
payload = decode(jws.payload);
|
|
1879
|
-
} catch {
|
|
1880
|
-
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
1881
|
-
}
|
|
1882
|
-
} else if (typeof jws.payload === "string") {
|
|
1883
|
-
payload = encoder.encode(jws.payload);
|
|
1884
|
-
} else {
|
|
1885
|
-
payload = jws.payload;
|
|
1886
|
-
}
|
|
1887
|
-
const result = { payload };
|
|
1888
|
-
if (jws.protected !== void 0) {
|
|
1889
|
-
result.protectedHeader = parsedProt;
|
|
1890
|
-
}
|
|
1891
|
-
if (jws.header !== void 0) {
|
|
1892
|
-
result.unprotectedHeader = jws.header;
|
|
1893
|
-
}
|
|
1894
|
-
if (resolvedKey) {
|
|
1895
|
-
return { ...result, key: k };
|
|
1896
|
-
}
|
|
1897
|
-
return result;
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
1901
|
-
async function compactVerify(jws, key, options) {
|
|
1902
|
-
if (jws instanceof Uint8Array) {
|
|
1903
|
-
jws = decoder.decode(jws);
|
|
1904
|
-
}
|
|
1905
|
-
if (typeof jws !== "string") {
|
|
1906
|
-
throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
1907
|
-
}
|
|
1908
|
-
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
1909
|
-
if (length !== 3) {
|
|
1910
|
-
throw new JWSInvalid("Invalid Compact JWS");
|
|
1911
|
-
}
|
|
1912
|
-
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
|
1913
|
-
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
|
1914
|
-
if (typeof key === "function") {
|
|
1915
|
-
return { ...result, key: verified.key };
|
|
1916
|
-
}
|
|
1917
|
-
return result;
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/epoch.js
|
|
1921
|
-
var epoch_default = (date) => Math.floor(date.getTime() / 1e3);
|
|
1922
|
-
|
|
1923
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/secs.js
|
|
1924
|
-
var minute = 60;
|
|
1925
|
-
var hour = minute * 60;
|
|
1926
|
-
var day = hour * 24;
|
|
1927
|
-
var week = day * 7;
|
|
1928
|
-
var year = day * 365.25;
|
|
1929
|
-
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
1930
|
-
var secs_default = (str) => {
|
|
1931
|
-
const matched = REGEX.exec(str);
|
|
1932
|
-
if (!matched || matched[4] && matched[1]) {
|
|
1933
|
-
throw new TypeError("Invalid time period format");
|
|
1934
|
-
}
|
|
1935
|
-
const value = parseFloat(matched[2]);
|
|
1936
|
-
const unit = matched[3].toLowerCase();
|
|
1937
|
-
let numericDate;
|
|
1938
|
-
switch (unit) {
|
|
1939
|
-
case "sec":
|
|
1940
|
-
case "secs":
|
|
1941
|
-
case "second":
|
|
1942
|
-
case "seconds":
|
|
1943
|
-
case "s":
|
|
1944
|
-
numericDate = Math.round(value);
|
|
1945
|
-
break;
|
|
1946
|
-
case "minute":
|
|
1947
|
-
case "minutes":
|
|
1948
|
-
case "min":
|
|
1949
|
-
case "mins":
|
|
1950
|
-
case "m":
|
|
1951
|
-
numericDate = Math.round(value * minute);
|
|
1952
|
-
break;
|
|
1953
|
-
case "hour":
|
|
1954
|
-
case "hours":
|
|
1955
|
-
case "hr":
|
|
1956
|
-
case "hrs":
|
|
1957
|
-
case "h":
|
|
1958
|
-
numericDate = Math.round(value * hour);
|
|
1959
|
-
break;
|
|
1960
|
-
case "day":
|
|
1961
|
-
case "days":
|
|
1962
|
-
case "d":
|
|
1963
|
-
numericDate = Math.round(value * day);
|
|
1964
|
-
break;
|
|
1965
|
-
case "week":
|
|
1966
|
-
case "weeks":
|
|
1967
|
-
case "w":
|
|
1968
|
-
numericDate = Math.round(value * week);
|
|
1969
|
-
break;
|
|
1970
|
-
default:
|
|
1971
|
-
numericDate = Math.round(value * year);
|
|
1972
|
-
break;
|
|
1973
|
-
}
|
|
1974
|
-
if (matched[1] === "-" || matched[4] === "ago") {
|
|
1975
|
-
return -numericDate;
|
|
1976
|
-
}
|
|
1977
|
-
return numericDate;
|
|
1978
|
-
};
|
|
1979
|
-
|
|
1980
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
1981
|
-
var normalizeTyp = (value) => {
|
|
1982
|
-
if (value.includes("/")) {
|
|
1983
|
-
return value.toLowerCase();
|
|
1984
|
-
}
|
|
1985
|
-
return `application/${value.toLowerCase()}`;
|
|
1986
|
-
};
|
|
1987
|
-
var checkAudiencePresence = (audPayload, audOption) => {
|
|
1988
|
-
if (typeof audPayload === "string") {
|
|
1989
|
-
return audOption.includes(audPayload);
|
|
1990
|
-
}
|
|
1991
|
-
if (Array.isArray(audPayload)) {
|
|
1992
|
-
return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
1993
|
-
}
|
|
1994
|
-
return false;
|
|
1995
|
-
};
|
|
1996
|
-
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
1997
|
-
let payload;
|
|
1998
|
-
try {
|
|
1999
|
-
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
2000
|
-
} catch {
|
|
2001
|
-
}
|
|
2002
|
-
if (!is_object_default(payload)) {
|
|
2003
|
-
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
2004
|
-
}
|
|
2005
|
-
const { typ } = options;
|
|
2006
|
-
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
|
2007
|
-
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
|
|
2008
|
-
}
|
|
2009
|
-
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
2010
|
-
const presenceCheck = [...requiredClaims];
|
|
2011
|
-
if (maxTokenAge !== void 0)
|
|
2012
|
-
presenceCheck.push("iat");
|
|
2013
|
-
if (audience !== void 0)
|
|
2014
|
-
presenceCheck.push("aud");
|
|
2015
|
-
if (subject !== void 0)
|
|
2016
|
-
presenceCheck.push("sub");
|
|
2017
|
-
if (issuer !== void 0)
|
|
2018
|
-
presenceCheck.push("iss");
|
|
2019
|
-
for (const claim of new Set(presenceCheck.reverse())) {
|
|
2020
|
-
if (!(claim in payload)) {
|
|
2021
|
-
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
2022
|
-
}
|
|
2023
|
-
}
|
|
2024
|
-
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
2025
|
-
throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
|
|
2026
|
-
}
|
|
2027
|
-
if (subject && payload.sub !== subject) {
|
|
2028
|
-
throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
|
|
2029
|
-
}
|
|
2030
|
-
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
|
|
2031
|
-
throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
|
|
2032
|
-
}
|
|
2033
|
-
let tolerance;
|
|
2034
|
-
switch (typeof options.clockTolerance) {
|
|
2035
|
-
case "string":
|
|
2036
|
-
tolerance = secs_default(options.clockTolerance);
|
|
2037
|
-
break;
|
|
2038
|
-
case "number":
|
|
2039
|
-
tolerance = options.clockTolerance;
|
|
2040
|
-
break;
|
|
2041
|
-
case "undefined":
|
|
2042
|
-
tolerance = 0;
|
|
2043
|
-
break;
|
|
2044
|
-
default:
|
|
2045
|
-
throw new TypeError("Invalid clockTolerance option type");
|
|
2046
|
-
}
|
|
2047
|
-
const { currentDate } = options;
|
|
2048
|
-
const now = epoch_default(currentDate || /* @__PURE__ */ new Date());
|
|
2049
|
-
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
|
|
2050
|
-
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
|
|
2051
|
-
}
|
|
2052
|
-
if (payload.nbf !== void 0) {
|
|
2053
|
-
if (typeof payload.nbf !== "number") {
|
|
2054
|
-
throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
|
|
2055
|
-
}
|
|
2056
|
-
if (payload.nbf > now + tolerance) {
|
|
2057
|
-
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
if (payload.exp !== void 0) {
|
|
2061
|
-
if (typeof payload.exp !== "number") {
|
|
2062
|
-
throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
|
|
2063
|
-
}
|
|
2064
|
-
if (payload.exp <= now - tolerance) {
|
|
2065
|
-
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
if (maxTokenAge) {
|
|
2069
|
-
const age = now - payload.iat;
|
|
2070
|
-
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs_default(maxTokenAge);
|
|
2071
|
-
if (age - tolerance > max) {
|
|
2072
|
-
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
|
|
2073
|
-
}
|
|
2074
|
-
if (age < 0 - tolerance) {
|
|
2075
|
-
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
return payload;
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
// node_modules/.pnpm/jose@6.0.11/node_modules/jose/dist/webapi/jwt/verify.js
|
|
2082
|
-
async function jwtVerify(jwt, key, options) {
|
|
2083
|
-
const verified = await compactVerify(jwt, key, options);
|
|
2084
|
-
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
2085
|
-
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
2086
|
-
}
|
|
2087
|
-
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
|
2088
|
-
const result = { payload, protectedHeader: verified.protectedHeader };
|
|
2089
|
-
if (typeof key === "function") {
|
|
2090
|
-
return { ...result, key: verified.key };
|
|
2091
|
-
}
|
|
2092
|
-
return result;
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
384
|
// src/auth.ts
|
|
385
|
+
import ky2 from "ky";
|
|
386
|
+
import * as jose from "jose";
|
|
387
|
+
import { intersection } from "remeda";
|
|
2096
388
|
var GRANT_TYPE = "authorization_code";
|
|
2097
389
|
var TOKEN_ENDPOINT = "https://login.bigcommerce.com/oauth2/token";
|
|
2098
390
|
var ISSUER = "bc";
|
|
@@ -2105,7 +397,7 @@ var BigCommerceAuth = class {
|
|
|
2105
397
|
constructor(config) {
|
|
2106
398
|
this.config = config;
|
|
2107
399
|
try {
|
|
2108
|
-
URL
|
|
400
|
+
new URL(this.config.redirectUri);
|
|
2109
401
|
} catch (error) {
|
|
2110
402
|
throw new Error("Invalid redirect URI", { cause: error });
|
|
2111
403
|
}
|
|
@@ -2124,10 +416,11 @@ var BigCommerceAuth = class {
|
|
|
2124
416
|
grant_type: GRANT_TYPE,
|
|
2125
417
|
redirect_uri: this.config.redirectUri
|
|
2126
418
|
};
|
|
2127
|
-
|
|
419
|
+
const res = await ky2(TOKEN_ENDPOINT, {
|
|
2128
420
|
method: "POST",
|
|
2129
421
|
json: tokenRequest
|
|
2130
|
-
})
|
|
422
|
+
});
|
|
423
|
+
return res.json();
|
|
2131
424
|
}
|
|
2132
425
|
/**
|
|
2133
426
|
* Verifies a JWT payload from BigCommerce
|
|
@@ -2138,7 +431,7 @@ var BigCommerceAuth = class {
|
|
|
2138
431
|
async verify(jwtPayload) {
|
|
2139
432
|
try {
|
|
2140
433
|
const secret = new TextEncoder().encode(this.config.secret);
|
|
2141
|
-
const { payload } = await jwtVerify(jwtPayload, secret, {
|
|
434
|
+
const { payload } = await jose.jwtVerify(jwtPayload, secret, {
|
|
2142
435
|
audience: this.config.clientId,
|
|
2143
436
|
issuer: ISSUER,
|
|
2144
437
|
subject: `stores/${this.config.storeHash}`
|
|
@@ -2189,7 +482,7 @@ var BigCommerceAuth = class {
|
|
|
2189
482
|
validateScopes(scopes) {
|
|
2190
483
|
const scopesArray = scopes.split(" ");
|
|
2191
484
|
if (this.config.scopes?.length) {
|
|
2192
|
-
const int =
|
|
485
|
+
const int = intersection(scopesArray, this.config.scopes);
|
|
2193
486
|
if (int.length !== scopesArray.length) {
|
|
2194
487
|
throw new Error(`Scope mismatch: ${scopes}; expected: ${this.config.scopes.join(" ")}`);
|
|
2195
488
|
}
|
|
@@ -2198,11 +491,7 @@ var BigCommerceAuth = class {
|
|
|
2198
491
|
};
|
|
2199
492
|
export {
|
|
2200
493
|
BigCommerceAuth,
|
|
2201
|
-
BigCommerceClient
|
|
494
|
+
BigCommerceClient,
|
|
495
|
+
Methods
|
|
2202
496
|
};
|
|
2203
|
-
/*! Bundled license information:
|
|
2204
|
-
|
|
2205
|
-
ky/distribution/index.js:
|
|
2206
|
-
(*! MIT License © Sindre Sorhus *)
|
|
2207
|
-
*/
|
|
2208
497
|
//# sourceMappingURL=index.js.map
|