zupost 0.0.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +119 -0
- package/dist/index.d.mts +202 -29
- package/dist/index.d.ts +202 -29
- package/dist/index.js +531 -171
- package/dist/index.mjs +531 -171
- package/package.json +17 -8
package/dist/index.js
CHANGED
|
@@ -24,6 +24,18 @@ var __spreadValues = (a, b) => {
|
|
|
24
24
|
return a;
|
|
25
25
|
};
|
|
26
26
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
+
var __objRest = (source, exclude) => {
|
|
28
|
+
var target = {};
|
|
29
|
+
for (var prop in source)
|
|
30
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
if (source != null && __getOwnPropSymbols)
|
|
33
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
34
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
35
|
+
target[prop] = source[prop];
|
|
36
|
+
}
|
|
37
|
+
return target;
|
|
38
|
+
};
|
|
27
39
|
var __export = (target, all) => {
|
|
28
40
|
for (var name in all)
|
|
29
41
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -39,8 +51,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
39
51
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
52
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
41
53
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
54
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
42
55
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
56
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
43
57
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
58
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
59
|
+
set _(value) {
|
|
60
|
+
__privateSet(obj, member, value, setter);
|
|
61
|
+
},
|
|
62
|
+
get _() {
|
|
63
|
+
return __privateGet(obj, member, getter);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
44
66
|
var __async = (__this, __arguments, generator) => {
|
|
45
67
|
return new Promise((resolve, reject) => {
|
|
46
68
|
var fulfilled = (value) => {
|
|
@@ -70,9 +92,9 @@ __export(index_exports, {
|
|
|
70
92
|
module.exports = __toCommonJS(index_exports);
|
|
71
93
|
|
|
72
94
|
// package.json
|
|
73
|
-
var version = "0.
|
|
95
|
+
var version = "0.1.1";
|
|
74
96
|
|
|
75
|
-
// node_modules/.pnpm/ky@1.
|
|
97
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/HTTPError.js
|
|
76
98
|
var HTTPError = class extends Error {
|
|
77
99
|
constructor(response, request, options) {
|
|
78
100
|
var _a;
|
|
@@ -91,17 +113,41 @@ var HTTPError = class extends Error {
|
|
|
91
113
|
}
|
|
92
114
|
};
|
|
93
115
|
|
|
94
|
-
// node_modules/.pnpm/ky@1.
|
|
95
|
-
var
|
|
96
|
-
constructor(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/NonError.js
|
|
117
|
+
var NonError = class extends Error {
|
|
118
|
+
constructor(value) {
|
|
119
|
+
let message = "Non-error value was thrown";
|
|
120
|
+
try {
|
|
121
|
+
if (typeof value === "string") {
|
|
122
|
+
message = value;
|
|
123
|
+
} else if (value && typeof value === "object" && "message" in value && typeof value.message === "string") {
|
|
124
|
+
message = value.message;
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
}
|
|
128
|
+
super(message);
|
|
129
|
+
__publicField(this, "name", "NonError");
|
|
130
|
+
__publicField(this, "value");
|
|
131
|
+
this.value = value;
|
|
101
132
|
}
|
|
102
133
|
};
|
|
103
134
|
|
|
104
|
-
// node_modules/.pnpm/ky@1.
|
|
135
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/ForceRetryError.js
|
|
136
|
+
var ForceRetryError = class extends Error {
|
|
137
|
+
constructor(options) {
|
|
138
|
+
const cause = (options == null ? void 0 : options.cause) ? options.cause instanceof Error ? options.cause : new NonError(options.cause) : void 0;
|
|
139
|
+
super((options == null ? void 0 : options.code) ? `Forced retry: ${options.code}` : "Forced retry", cause ? { cause } : void 0);
|
|
140
|
+
__publicField(this, "name", "ForceRetryError");
|
|
141
|
+
__publicField(this, "customDelay");
|
|
142
|
+
__publicField(this, "code");
|
|
143
|
+
__publicField(this, "customRequest");
|
|
144
|
+
this.customDelay = options == null ? void 0 : options.delay;
|
|
145
|
+
this.code = options == null ? void 0 : options.code;
|
|
146
|
+
this.customRequest = options == null ? void 0 : options.request;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/core/constants.js
|
|
105
151
|
var supportsRequestStreams = (() => {
|
|
106
152
|
let duplexAccessed = false;
|
|
107
153
|
let hasContentType = false;
|
|
@@ -146,7 +192,14 @@ var responseTypes = {
|
|
|
146
192
|
};
|
|
147
193
|
var maxSafeTimeout = 2147483647;
|
|
148
194
|
var usualFormBoundarySize = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length;
|
|
149
|
-
var stop = Symbol("stop");
|
|
195
|
+
var stop = /* @__PURE__ */ Symbol("stop");
|
|
196
|
+
var RetryMarker = class {
|
|
197
|
+
constructor(options) {
|
|
198
|
+
__publicField(this, "options");
|
|
199
|
+
this.options = options;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var retry = (options) => new RetryMarker(options);
|
|
150
203
|
var kyOptionKeys = {
|
|
151
204
|
json: true,
|
|
152
205
|
parseJson: true,
|
|
@@ -159,7 +212,12 @@ var kyOptionKeys = {
|
|
|
159
212
|
throwHttpErrors: true,
|
|
160
213
|
onDownloadProgress: true,
|
|
161
214
|
onUploadProgress: true,
|
|
162
|
-
fetch: true
|
|
215
|
+
fetch: true,
|
|
216
|
+
context: true
|
|
217
|
+
};
|
|
218
|
+
var vendorSpecificOptions = {
|
|
219
|
+
next: true
|
|
220
|
+
// Next.js cache revalidation (revalidate, tags)
|
|
163
221
|
};
|
|
164
222
|
var requestOptionsRegistry = {
|
|
165
223
|
method: true,
|
|
@@ -175,12 +233,10 @@ var requestOptionsRegistry = {
|
|
|
175
233
|
keepalive: true,
|
|
176
234
|
signal: true,
|
|
177
235
|
window: true,
|
|
178
|
-
|
|
179
|
-
duplex: true,
|
|
180
|
-
priority: true
|
|
236
|
+
duplex: true
|
|
181
237
|
};
|
|
182
238
|
|
|
183
|
-
// node_modules/.pnpm/ky@1.
|
|
239
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/body.js
|
|
184
240
|
var getBodySize = (body) => {
|
|
185
241
|
if (!body) {
|
|
186
242
|
return 0;
|
|
@@ -254,7 +310,7 @@ var streamResponse = (response, onDownloadProgress) => {
|
|
|
254
310
|
headers: response.headers
|
|
255
311
|
});
|
|
256
312
|
}
|
|
257
|
-
const totalBytes = Number(response.headers.get("content-length")) || 0;
|
|
313
|
+
const totalBytes = Math.max(0, Number(response.headers.get("content-length")) || 0);
|
|
258
314
|
return new Response(withProgress(response.body, totalBytes, onDownloadProgress), {
|
|
259
315
|
status: response.status,
|
|
260
316
|
statusText: response.statusText,
|
|
@@ -273,10 +329,10 @@ var streamRequest = (request, onUploadProgress, originalBody) => {
|
|
|
273
329
|
});
|
|
274
330
|
};
|
|
275
331
|
|
|
276
|
-
// node_modules/.pnpm/ky@1.
|
|
332
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/is.js
|
|
277
333
|
var isObject = (value) => value !== null && typeof value === "object";
|
|
278
334
|
|
|
279
|
-
// node_modules/.pnpm/ky@1.
|
|
335
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/merge.js
|
|
280
336
|
var validateAndMerge = (...sources) => {
|
|
281
337
|
for (const source of sources) {
|
|
282
338
|
if ((!isObject(source) || Array.isArray(source)) && source !== void 0) {
|
|
@@ -308,10 +364,44 @@ var mergeHooks = (original = {}, incoming = {}) => ({
|
|
|
308
364
|
afterResponse: newHookValue(original, incoming, "afterResponse"),
|
|
309
365
|
beforeError: newHookValue(original, incoming, "beforeError")
|
|
310
366
|
});
|
|
367
|
+
var appendSearchParameters = (target, source) => {
|
|
368
|
+
const result = new URLSearchParams();
|
|
369
|
+
for (const input of [target, source]) {
|
|
370
|
+
if (input === void 0) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
if (input instanceof URLSearchParams) {
|
|
374
|
+
for (const [key, value] of input.entries()) {
|
|
375
|
+
result.append(key, value);
|
|
376
|
+
}
|
|
377
|
+
} else if (Array.isArray(input)) {
|
|
378
|
+
for (const pair of input) {
|
|
379
|
+
if (!Array.isArray(pair) || pair.length !== 2) {
|
|
380
|
+
throw new TypeError("Array search parameters must be provided in [[key, value], ...] format");
|
|
381
|
+
}
|
|
382
|
+
result.append(String(pair[0]), String(pair[1]));
|
|
383
|
+
}
|
|
384
|
+
} else if (isObject(input)) {
|
|
385
|
+
for (const [key, value] of Object.entries(input)) {
|
|
386
|
+
if (value !== void 0) {
|
|
387
|
+
result.append(key, String(value));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
} else {
|
|
391
|
+
const parameters = new URLSearchParams(input);
|
|
392
|
+
for (const [key, value] of parameters.entries()) {
|
|
393
|
+
result.append(key, value);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return result;
|
|
398
|
+
};
|
|
311
399
|
var deepMerge = (...sources) => {
|
|
312
400
|
let returnValue = {};
|
|
313
401
|
let headers = {};
|
|
314
402
|
let hooks = {};
|
|
403
|
+
let searchParameters;
|
|
404
|
+
const signals = [];
|
|
315
405
|
for (const source of sources) {
|
|
316
406
|
if (Array.isArray(source)) {
|
|
317
407
|
if (!Array.isArray(returnValue)) {
|
|
@@ -320,6 +410,27 @@ var deepMerge = (...sources) => {
|
|
|
320
410
|
returnValue = [...returnValue, ...source];
|
|
321
411
|
} else if (isObject(source)) {
|
|
322
412
|
for (let [key, value] of Object.entries(source)) {
|
|
413
|
+
if (key === "signal" && value instanceof globalThis.AbortSignal) {
|
|
414
|
+
signals.push(value);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (key === "context") {
|
|
418
|
+
if (value !== void 0 && value !== null && (!isObject(value) || Array.isArray(value))) {
|
|
419
|
+
throw new TypeError("The `context` option must be an object");
|
|
420
|
+
}
|
|
421
|
+
returnValue = __spreadProps(__spreadValues({}, returnValue), {
|
|
422
|
+
context: value === void 0 || value === null ? {} : __spreadValues(__spreadValues({}, returnValue.context), value)
|
|
423
|
+
});
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
if (key === "searchParams") {
|
|
427
|
+
if (value === void 0 || value === null) {
|
|
428
|
+
searchParameters = void 0;
|
|
429
|
+
} else {
|
|
430
|
+
searchParameters = searchParameters === void 0 ? value : appendSearchParameters(searchParameters, value);
|
|
431
|
+
}
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
323
434
|
if (isObject(value) && key in returnValue) {
|
|
324
435
|
value = deepMerge(returnValue[key], value);
|
|
325
436
|
}
|
|
@@ -335,10 +446,22 @@ var deepMerge = (...sources) => {
|
|
|
335
446
|
}
|
|
336
447
|
}
|
|
337
448
|
}
|
|
449
|
+
if (searchParameters !== void 0) {
|
|
450
|
+
returnValue.searchParams = searchParameters;
|
|
451
|
+
}
|
|
452
|
+
if (signals.length > 0) {
|
|
453
|
+
if (signals.length === 1) {
|
|
454
|
+
returnValue.signal = signals[0];
|
|
455
|
+
} else if (supportsAbortSignal) {
|
|
456
|
+
returnValue.signal = AbortSignal.any(signals);
|
|
457
|
+
} else {
|
|
458
|
+
returnValue.signal = signals.at(-1);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
338
461
|
return returnValue;
|
|
339
462
|
};
|
|
340
463
|
|
|
341
|
-
// node_modules/.pnpm/ky@1.
|
|
464
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/normalize.js
|
|
342
465
|
var normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
|
|
343
466
|
var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
|
|
344
467
|
var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
|
|
@@ -350,24 +473,38 @@ var defaultRetryOptions = {
|
|
|
350
473
|
afterStatusCodes: retryAfterStatusCodes,
|
|
351
474
|
maxRetryAfter: Number.POSITIVE_INFINITY,
|
|
352
475
|
backoffLimit: Number.POSITIVE_INFINITY,
|
|
353
|
-
delay: (attemptCount) => 0.3 * __pow(2, attemptCount - 1) * 1e3
|
|
476
|
+
delay: (attemptCount) => 0.3 * __pow(2, attemptCount - 1) * 1e3,
|
|
477
|
+
jitter: void 0,
|
|
478
|
+
retryOnTimeout: false
|
|
354
479
|
};
|
|
355
|
-
var normalizeRetryOptions = (
|
|
356
|
-
if (typeof
|
|
480
|
+
var normalizeRetryOptions = (retry2 = {}) => {
|
|
481
|
+
if (typeof retry2 === "number") {
|
|
357
482
|
return __spreadProps(__spreadValues({}, defaultRetryOptions), {
|
|
358
|
-
limit:
|
|
483
|
+
limit: retry2
|
|
359
484
|
});
|
|
360
485
|
}
|
|
361
|
-
if (
|
|
486
|
+
if (retry2.methods && !Array.isArray(retry2.methods)) {
|
|
362
487
|
throw new Error("retry.methods must be an array");
|
|
363
488
|
}
|
|
364
|
-
|
|
489
|
+
retry2.methods && (retry2.methods = retry2.methods.map((method) => method.toLowerCase()));
|
|
490
|
+
if (retry2.statusCodes && !Array.isArray(retry2.statusCodes)) {
|
|
365
491
|
throw new Error("retry.statusCodes must be an array");
|
|
366
492
|
}
|
|
367
|
-
|
|
493
|
+
const normalizedRetry = Object.fromEntries(Object.entries(retry2).filter(([, value]) => value !== void 0));
|
|
494
|
+
return __spreadValues(__spreadValues({}, defaultRetryOptions), normalizedRetry);
|
|
368
495
|
};
|
|
369
496
|
|
|
370
|
-
// node_modules/.pnpm/ky@1.
|
|
497
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/errors/TimeoutError.js
|
|
498
|
+
var TimeoutError = class extends Error {
|
|
499
|
+
constructor(request) {
|
|
500
|
+
super(`Request timed out: ${request.method} ${request.url}`);
|
|
501
|
+
__publicField(this, "request");
|
|
502
|
+
this.name = "TimeoutError";
|
|
503
|
+
this.request = request;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/timeout.js
|
|
371
508
|
function timeout(request, init, abortController, options) {
|
|
372
509
|
return __async(this, null, function* () {
|
|
373
510
|
return new Promise((resolve, reject) => {
|
|
@@ -384,7 +521,7 @@ function timeout(request, init, abortController, options) {
|
|
|
384
521
|
});
|
|
385
522
|
}
|
|
386
523
|
|
|
387
|
-
// node_modules/.pnpm/ky@1.
|
|
524
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/delay.js
|
|
388
525
|
function delay(_0, _1) {
|
|
389
526
|
return __async(this, arguments, function* (ms, { signal }) {
|
|
390
527
|
return new Promise((resolve, reject) => {
|
|
@@ -404,11 +541,14 @@ function delay(_0, _1) {
|
|
|
404
541
|
});
|
|
405
542
|
}
|
|
406
543
|
|
|
407
|
-
// node_modules/.pnpm/ky@1.
|
|
544
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/options.js
|
|
408
545
|
var findUnknownOptions = (request, options) => {
|
|
409
546
|
const unknownOptions = {};
|
|
410
547
|
for (const key in options) {
|
|
411
|
-
if (!(
|
|
548
|
+
if (!Object.hasOwn(options, key)) {
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && (!(key in request) || key in vendorSpecificOptions)) {
|
|
412
552
|
unknownOptions[key] = options[key];
|
|
413
553
|
}
|
|
414
554
|
}
|
|
@@ -433,131 +573,156 @@ var hasSearchParameters = (search) => {
|
|
|
433
573
|
return Boolean(search);
|
|
434
574
|
};
|
|
435
575
|
|
|
436
|
-
// node_modules/.pnpm/ky@1.
|
|
437
|
-
|
|
576
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/utils/type-guards.js
|
|
577
|
+
function isHTTPError(error) {
|
|
578
|
+
return error instanceof HTTPError || (error == null ? void 0 : error.name) === HTTPError.name;
|
|
579
|
+
}
|
|
580
|
+
function isTimeoutError(error) {
|
|
581
|
+
return error instanceof TimeoutError || (error == null ? void 0 : error.name) === TimeoutError.name;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/core/Ky.js
|
|
585
|
+
var _Ky_static, normalizeSearchParams_fn, _abortController, _retryCount, _input, _options, _originalRequest, _userProvidedAbortSignal, _cachedNormalizedOptions, _Ky_instances, calculateDelay_fn, calculateRetryDelay_fn, decorateResponse_fn, cancelBody_fn, cancelResponseBody_fn, retry_fn, fetch_fn, getNormalizedOptions_fn, assignRequest_fn, wrapRequestWithUploadProgress_fn;
|
|
438
586
|
var _Ky = class _Ky {
|
|
439
587
|
// eslint-disable-next-line complexity
|
|
440
588
|
constructor(input, options = {}) {
|
|
589
|
+
__privateAdd(this, _Ky_instances);
|
|
441
590
|
__publicField(this, "request");
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
this
|
|
449
|
-
this
|
|
450
|
-
|
|
591
|
+
__privateAdd(this, _abortController);
|
|
592
|
+
__privateAdd(this, _retryCount, 0);
|
|
593
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly -- False positive: #input is reassigned on line 202
|
|
594
|
+
__privateAdd(this, _input);
|
|
595
|
+
__privateAdd(this, _options);
|
|
596
|
+
__privateAdd(this, _originalRequest);
|
|
597
|
+
__privateAdd(this, _userProvidedAbortSignal);
|
|
598
|
+
__privateAdd(this, _cachedNormalizedOptions);
|
|
599
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
600
|
+
__privateSet(this, _input, input);
|
|
601
|
+
__privateSet(this, _options, __spreadProps(__spreadValues({}, options), {
|
|
602
|
+
headers: mergeHeaders(__privateGet(this, _input).headers, options.headers),
|
|
451
603
|
hooks: mergeHooks({
|
|
452
604
|
beforeRequest: [],
|
|
453
605
|
beforeRetry: [],
|
|
454
606
|
beforeError: [],
|
|
455
607
|
afterResponse: []
|
|
456
608
|
}, options.hooks),
|
|
457
|
-
method: normalizeRequestMethod((_b = (_a = options.method) != null ? _a : this
|
|
609
|
+
method: normalizeRequestMethod((_b = (_a = options.method) != null ? _a : __privateGet(this, _input).method) != null ? _b : "GET"),
|
|
458
610
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
459
611
|
prefixUrl: String(options.prefixUrl || ""),
|
|
460
612
|
retry: normalizeRetryOptions(options.retry),
|
|
461
|
-
throwHttpErrors: options.throwHttpErrors
|
|
462
|
-
timeout: (
|
|
463
|
-
fetch: (
|
|
464
|
-
|
|
465
|
-
|
|
613
|
+
throwHttpErrors: (_c = options.throwHttpErrors) != null ? _c : true,
|
|
614
|
+
timeout: (_d = options.timeout) != null ? _d : 1e4,
|
|
615
|
+
fetch: (_e = options.fetch) != null ? _e : globalThis.fetch.bind(globalThis),
|
|
616
|
+
context: (_f = options.context) != null ? _f : {}
|
|
617
|
+
}));
|
|
618
|
+
if (typeof __privateGet(this, _input) !== "string" && !(__privateGet(this, _input) instanceof URL || __privateGet(this, _input) instanceof globalThis.Request)) {
|
|
466
619
|
throw new TypeError("`input` must be a string, URL, or Request");
|
|
467
620
|
}
|
|
468
|
-
if (this
|
|
469
|
-
if (this
|
|
621
|
+
if (__privateGet(this, _options).prefixUrl && typeof __privateGet(this, _input) === "string") {
|
|
622
|
+
if (__privateGet(this, _input).startsWith("/")) {
|
|
470
623
|
throw new Error("`input` must not begin with a slash when using `prefixUrl`");
|
|
471
624
|
}
|
|
472
|
-
if (!this
|
|
473
|
-
this
|
|
625
|
+
if (!__privateGet(this, _options).prefixUrl.endsWith("/")) {
|
|
626
|
+
__privateGet(this, _options).prefixUrl += "/";
|
|
474
627
|
}
|
|
475
|
-
this
|
|
628
|
+
__privateSet(this, _input, __privateGet(this, _options).prefixUrl + __privateGet(this, _input));
|
|
476
629
|
}
|
|
477
630
|
if (supportsAbortController && supportsAbortSignal) {
|
|
478
|
-
|
|
479
|
-
this
|
|
480
|
-
this
|
|
631
|
+
__privateSet(this, _userProvidedAbortSignal, (_g = __privateGet(this, _options).signal) != null ? _g : __privateGet(this, _input).signal);
|
|
632
|
+
__privateSet(this, _abortController, new globalThis.AbortController());
|
|
633
|
+
__privateGet(this, _options).signal = __privateGet(this, _userProvidedAbortSignal) ? AbortSignal.any([__privateGet(this, _userProvidedAbortSignal), __privateGet(this, _abortController).signal]) : __privateGet(this, _abortController).signal;
|
|
481
634
|
}
|
|
482
635
|
if (supportsRequestStreams) {
|
|
483
|
-
this
|
|
636
|
+
__privateGet(this, _options).duplex = "half";
|
|
637
|
+
}
|
|
638
|
+
if (__privateGet(this, _options).json !== void 0) {
|
|
639
|
+
__privateGet(this, _options).body = (_j = (_i = (_h = __privateGet(this, _options)).stringifyJson) == null ? void 0 : _i.call(_h, __privateGet(this, _options).json)) != null ? _j : JSON.stringify(__privateGet(this, _options).json);
|
|
640
|
+
__privateGet(this, _options).headers.set("content-type", (_k = __privateGet(this, _options).headers.get("content-type")) != null ? _k : "application/json");
|
|
484
641
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
this
|
|
642
|
+
const userProvidedContentType = options.headers && new globalThis.Headers(options.headers).has("content-type");
|
|
643
|
+
if (__privateGet(this, _input) instanceof globalThis.Request && (supportsFormData && __privateGet(this, _options).body instanceof globalThis.FormData || __privateGet(this, _options).body instanceof URLSearchParams) && !userProvidedContentType) {
|
|
644
|
+
__privateGet(this, _options).headers.delete("content-type");
|
|
488
645
|
}
|
|
489
|
-
this.request = new globalThis.Request(this
|
|
490
|
-
if (hasSearchParameters(this
|
|
491
|
-
const textSearchParams = typeof this
|
|
646
|
+
this.request = new globalThis.Request(__privateGet(this, _input), __privateGet(this, _options));
|
|
647
|
+
if (hasSearchParameters(__privateGet(this, _options).searchParams)) {
|
|
648
|
+
const textSearchParams = typeof __privateGet(this, _options).searchParams === "string" ? __privateGet(this, _options).searchParams.replace(/^\?/, "") : new URLSearchParams(__privateMethod(_l = _Ky, _Ky_static, normalizeSearchParams_fn).call(_l, __privateGet(this, _options).searchParams)).toString();
|
|
492
649
|
const searchParams = "?" + textSearchParams;
|
|
493
650
|
const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
|
|
494
|
-
|
|
495
|
-
this.request.headers.delete("content-type");
|
|
496
|
-
}
|
|
497
|
-
this.request = new globalThis.Request(new globalThis.Request(url, __spreadValues({}, this.request)), this._options);
|
|
651
|
+
this.request = new globalThis.Request(url, __privateGet(this, _options));
|
|
498
652
|
}
|
|
499
|
-
if (this
|
|
500
|
-
if (typeof this
|
|
653
|
+
if (__privateGet(this, _options).onUploadProgress) {
|
|
654
|
+
if (typeof __privateGet(this, _options).onUploadProgress !== "function") {
|
|
501
655
|
throw new TypeError("The `onUploadProgress` option must be a function");
|
|
502
656
|
}
|
|
503
657
|
if (!supportsRequestStreams) {
|
|
504
658
|
throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
|
|
505
659
|
}
|
|
506
|
-
|
|
507
|
-
if (originalBody) {
|
|
508
|
-
this.request = streamRequest(this.request, this._options.onUploadProgress, this._options.body);
|
|
509
|
-
}
|
|
660
|
+
this.request = __privateMethod(this, _Ky_instances, wrapRequestWithUploadProgress_fn).call(this, this.request, (_m = __privateGet(this, _options).body) != null ? _m : void 0);
|
|
510
661
|
}
|
|
511
662
|
}
|
|
512
663
|
static create(input, options) {
|
|
513
|
-
var _a, _b;
|
|
664
|
+
var _a, _b, _c;
|
|
514
665
|
const ky2 = new _Ky(input, options);
|
|
515
666
|
const function_ = () => __async(null, null, function* () {
|
|
516
|
-
|
|
667
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
668
|
+
if (typeof __privateGet(ky2, _options).timeout === "number" && __privateGet(ky2, _options).timeout > maxSafeTimeout) {
|
|
517
669
|
throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
|
|
518
670
|
}
|
|
519
671
|
yield Promise.resolve();
|
|
520
|
-
let response = yield ky2.
|
|
521
|
-
for (const hook of ky2
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
672
|
+
let response = yield __privateMethod(_a2 = ky2, _Ky_instances, fetch_fn).call(_a2);
|
|
673
|
+
for (const hook of __privateGet(ky2, _options).hooks.afterResponse) {
|
|
674
|
+
const clonedResponse = __privateMethod(_b2 = ky2, _Ky_instances, decorateResponse_fn).call(_b2, response.clone());
|
|
675
|
+
let modifiedResponse;
|
|
676
|
+
try {
|
|
677
|
+
modifiedResponse = yield hook(ky2.request, __privateMethod(_c2 = ky2, _Ky_instances, getNormalizedOptions_fn).call(_c2), clonedResponse, { retryCount: __privateGet(ky2, _retryCount) });
|
|
678
|
+
} catch (error) {
|
|
679
|
+
__privateMethod(_d = ky2, _Ky_instances, cancelResponseBody_fn).call(_d, clonedResponse);
|
|
680
|
+
__privateMethod(_e = ky2, _Ky_instances, cancelResponseBody_fn).call(_e, response);
|
|
681
|
+
throw error;
|
|
682
|
+
}
|
|
683
|
+
if (modifiedResponse instanceof RetryMarker) {
|
|
684
|
+
__privateMethod(_f = ky2, _Ky_instances, cancelResponseBody_fn).call(_f, clonedResponse);
|
|
685
|
+
__privateMethod(_g = ky2, _Ky_instances, cancelResponseBody_fn).call(_g, response);
|
|
686
|
+
throw new ForceRetryError(modifiedResponse.options);
|
|
687
|
+
}
|
|
688
|
+
const nextResponse = modifiedResponse instanceof globalThis.Response ? modifiedResponse : response;
|
|
689
|
+
if (clonedResponse !== nextResponse) {
|
|
690
|
+
__privateMethod(_h = ky2, _Ky_instances, cancelResponseBody_fn).call(_h, clonedResponse);
|
|
691
|
+
}
|
|
692
|
+
if (response !== nextResponse) {
|
|
693
|
+
__privateMethod(_i = ky2, _Ky_instances, cancelResponseBody_fn).call(_i, response);
|
|
525
694
|
}
|
|
695
|
+
response = nextResponse;
|
|
526
696
|
}
|
|
527
|
-
ky2.
|
|
528
|
-
if (!response.ok && ky2._options.throwHttpErrors) {
|
|
529
|
-
let error = new HTTPError(response, ky2.request, ky2.
|
|
530
|
-
for (const hook of ky2
|
|
531
|
-
error = yield hook(error);
|
|
697
|
+
__privateMethod(_j = ky2, _Ky_instances, decorateResponse_fn).call(_j, response);
|
|
698
|
+
if (!response.ok && (typeof __privateGet(ky2, _options).throwHttpErrors === "function" ? __privateGet(ky2, _options).throwHttpErrors(response.status) : __privateGet(ky2, _options).throwHttpErrors)) {
|
|
699
|
+
let error = new HTTPError(response, ky2.request, __privateMethod(_k = ky2, _Ky_instances, getNormalizedOptions_fn).call(_k));
|
|
700
|
+
for (const hook of __privateGet(ky2, _options).hooks.beforeError) {
|
|
701
|
+
error = yield hook(error, { retryCount: __privateGet(ky2, _retryCount) });
|
|
532
702
|
}
|
|
533
703
|
throw error;
|
|
534
704
|
}
|
|
535
|
-
if (ky2
|
|
536
|
-
if (typeof ky2
|
|
705
|
+
if (__privateGet(ky2, _options).onDownloadProgress) {
|
|
706
|
+
if (typeof __privateGet(ky2, _options).onDownloadProgress !== "function") {
|
|
537
707
|
throw new TypeError("The `onDownloadProgress` option must be a function");
|
|
538
708
|
}
|
|
539
709
|
if (!supportsResponseStreams) {
|
|
540
710
|
throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
|
|
541
711
|
}
|
|
542
|
-
|
|
712
|
+
const progressResponse = response.clone();
|
|
713
|
+
__privateMethod(_l = ky2, _Ky_instances, cancelResponseBody_fn).call(_l, response);
|
|
714
|
+
return streamResponse(progressResponse, __privateGet(ky2, _options).onDownloadProgress);
|
|
543
715
|
}
|
|
544
716
|
return response;
|
|
545
717
|
});
|
|
546
|
-
const
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
cleanupPromises.push((_a2 = originalRequest.body) == null ? void 0 : _a2.cancel());
|
|
553
|
-
}
|
|
554
|
-
if (!ky2.request.bodyUsed) {
|
|
555
|
-
cleanupPromises.push((_b2 = ky2.request.body) == null ? void 0 : _b2.cancel());
|
|
556
|
-
}
|
|
557
|
-
yield Promise.all(cleanupPromises);
|
|
558
|
-
}));
|
|
718
|
+
const result = __privateMethod(_a = ky2, _Ky_instances, retry_fn).call(_a, function_).finally(() => {
|
|
719
|
+
var _a2, _b2, _c2, _d;
|
|
720
|
+
const originalRequest = __privateGet(ky2, _originalRequest);
|
|
721
|
+
__privateMethod(_b2 = ky2, _Ky_instances, cancelBody_fn).call(_b2, (_a2 = originalRequest == null ? void 0 : originalRequest.body) != null ? _a2 : void 0);
|
|
722
|
+
__privateMethod(_d = ky2, _Ky_instances, cancelBody_fn).call(_d, (_c2 = ky2.request.body) != null ? _c2 : void 0);
|
|
723
|
+
});
|
|
559
724
|
for (const [type, mimeType] of Object.entries(responseTypes)) {
|
|
560
|
-
if (type === "bytes" && typeof ((
|
|
725
|
+
if (type === "bytes" && typeof ((_c = (_b = globalThis.Response) == null ? void 0 : _b.prototype) == null ? void 0 : _c.bytes) !== "function") {
|
|
561
726
|
continue;
|
|
562
727
|
}
|
|
563
728
|
result[type] = () => __async(null, null, function* () {
|
|
@@ -581,100 +746,188 @@ var _Ky = class _Ky {
|
|
|
581
746
|
}
|
|
582
747
|
return result;
|
|
583
748
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
749
|
+
};
|
|
750
|
+
_Ky_static = new WeakSet();
|
|
751
|
+
normalizeSearchParams_fn = function(searchParams) {
|
|
752
|
+
if (searchParams && typeof searchParams === "object" && !Array.isArray(searchParams) && !(searchParams instanceof URLSearchParams)) {
|
|
753
|
+
return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => value !== void 0));
|
|
754
|
+
}
|
|
755
|
+
return searchParams;
|
|
756
|
+
};
|
|
757
|
+
_abortController = new WeakMap();
|
|
758
|
+
_retryCount = new WeakMap();
|
|
759
|
+
_input = new WeakMap();
|
|
760
|
+
_options = new WeakMap();
|
|
761
|
+
_originalRequest = new WeakMap();
|
|
762
|
+
_userProvidedAbortSignal = new WeakMap();
|
|
763
|
+
_cachedNormalizedOptions = new WeakMap();
|
|
764
|
+
_Ky_instances = new WeakSet();
|
|
765
|
+
calculateDelay_fn = function() {
|
|
766
|
+
var _a;
|
|
767
|
+
const retryDelay = __privateGet(this, _options).retry.delay(__privateGet(this, _retryCount));
|
|
768
|
+
let jitteredDelay = retryDelay;
|
|
769
|
+
if (__privateGet(this, _options).retry.jitter === true) {
|
|
770
|
+
jitteredDelay = Math.random() * retryDelay;
|
|
771
|
+
} else if (typeof __privateGet(this, _options).retry.jitter === "function") {
|
|
772
|
+
jitteredDelay = __privateGet(this, _options).retry.jitter(retryDelay);
|
|
773
|
+
if (!Number.isFinite(jitteredDelay) || jitteredDelay < 0) {
|
|
774
|
+
jitteredDelay = retryDelay;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const backoffLimit = (_a = __privateGet(this, _options).retry.backoffLimit) != null ? _a : Number.POSITIVE_INFINITY;
|
|
778
|
+
return Math.min(backoffLimit, jitteredDelay);
|
|
779
|
+
};
|
|
780
|
+
calculateRetryDelay_fn = function(error) {
|
|
781
|
+
return __async(this, null, function* () {
|
|
782
|
+
var _a, _b, _c, _d, _e, _f;
|
|
783
|
+
__privateWrapper(this, _retryCount)._++;
|
|
784
|
+
if (__privateGet(this, _retryCount) > __privateGet(this, _options).retry.limit) {
|
|
588
785
|
throw error;
|
|
589
786
|
}
|
|
590
|
-
|
|
591
|
-
|
|
787
|
+
const errorObject = error instanceof Error ? error : new NonError(error);
|
|
788
|
+
if (errorObject instanceof ForceRetryError) {
|
|
789
|
+
return (_a = errorObject.customDelay) != null ? _a : __privateMethod(this, _Ky_instances, calculateDelay_fn).call(this);
|
|
790
|
+
}
|
|
791
|
+
if (!__privateGet(this, _options).retry.methods.includes(this.request.method.toLowerCase())) {
|
|
792
|
+
throw error;
|
|
793
|
+
}
|
|
794
|
+
if (__privateGet(this, _options).retry.shouldRetry !== void 0) {
|
|
795
|
+
const result = yield __privateGet(this, _options).retry.shouldRetry({ error: errorObject, retryCount: __privateGet(this, _retryCount) });
|
|
796
|
+
if (result === false) {
|
|
592
797
|
throw error;
|
|
593
798
|
}
|
|
594
|
-
|
|
595
|
-
|
|
799
|
+
if (result === true) {
|
|
800
|
+
return __privateMethod(this, _Ky_instances, calculateDelay_fn).call(this);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
if (isTimeoutError(error) && !__privateGet(this, _options).retry.retryOnTimeout) {
|
|
804
|
+
throw error;
|
|
805
|
+
}
|
|
806
|
+
if (isHTTPError(error)) {
|
|
807
|
+
if (!__privateGet(this, _options).retry.statusCodes.includes(error.response.status)) {
|
|
808
|
+
throw error;
|
|
809
|
+
}
|
|
810
|
+
const retryAfter = (_e = (_d = (_c = (_b = error.response.headers.get("Retry-After")) != null ? _b : error.response.headers.get("RateLimit-Reset")) != null ? _c : error.response.headers.get("X-RateLimit-Retry-After")) != null ? _d : error.response.headers.get("X-RateLimit-Reset")) != null ? _e : error.response.headers.get("X-Rate-Limit-Reset");
|
|
811
|
+
if (retryAfter && __privateGet(this, _options).retry.afterStatusCodes.includes(error.response.status)) {
|
|
596
812
|
let after = Number(retryAfter) * 1e3;
|
|
597
813
|
if (Number.isNaN(after)) {
|
|
598
814
|
after = Date.parse(retryAfter) - Date.now();
|
|
599
815
|
} else if (after >= Date.parse("2024-01-01")) {
|
|
600
816
|
after -= Date.now();
|
|
601
817
|
}
|
|
602
|
-
const max = (
|
|
818
|
+
const max = (_f = __privateGet(this, _options).retry.maxRetryAfter) != null ? _f : after;
|
|
603
819
|
return after < max ? after : max;
|
|
604
820
|
}
|
|
605
821
|
if (error.response.status === 413) {
|
|
606
822
|
throw error;
|
|
607
823
|
}
|
|
608
824
|
}
|
|
609
|
-
|
|
610
|
-
|
|
825
|
+
return __privateMethod(this, _Ky_instances, calculateDelay_fn).call(this);
|
|
826
|
+
});
|
|
827
|
+
};
|
|
828
|
+
decorateResponse_fn = function(response) {
|
|
829
|
+
if (__privateGet(this, _options).parseJson) {
|
|
830
|
+
response.json = () => __async(this, null, function* () {
|
|
831
|
+
return __privateGet(this, _options).parseJson(yield response.text());
|
|
832
|
+
});
|
|
611
833
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
}
|
|
618
|
-
return response;
|
|
834
|
+
return response;
|
|
835
|
+
};
|
|
836
|
+
cancelBody_fn = function(body) {
|
|
837
|
+
if (!body) {
|
|
838
|
+
return;
|
|
619
839
|
}
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
error,
|
|
635
|
-
retryCount: this._retryCount
|
|
636
|
-
});
|
|
637
|
-
if (hookResult === stop) {
|
|
638
|
-
return;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
return this._retry(function_);
|
|
840
|
+
void body.cancel().catch(() => void 0);
|
|
841
|
+
};
|
|
842
|
+
cancelResponseBody_fn = function(response) {
|
|
843
|
+
var _a;
|
|
844
|
+
__privateMethod(this, _Ky_instances, cancelBody_fn).call(this, (_a = response.body) != null ? _a : void 0);
|
|
845
|
+
};
|
|
846
|
+
retry_fn = function(function_) {
|
|
847
|
+
return __async(this, null, function* () {
|
|
848
|
+
try {
|
|
849
|
+
return yield function_();
|
|
850
|
+
} catch (error) {
|
|
851
|
+
const ms = Math.min(yield __privateMethod(this, _Ky_instances, calculateRetryDelay_fn).call(this, error), maxSafeTimeout);
|
|
852
|
+
if (__privateGet(this, _retryCount) < 1) {
|
|
853
|
+
throw error;
|
|
642
854
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
this.request
|
|
855
|
+
yield delay(ms, __privateGet(this, _userProvidedAbortSignal) ? { signal: __privateGet(this, _userProvidedAbortSignal) } : {});
|
|
856
|
+
if (error instanceof ForceRetryError && error.customRequest) {
|
|
857
|
+
const managedRequest = __privateGet(this, _options).signal ? new globalThis.Request(error.customRequest, { signal: __privateGet(this, _options).signal }) : new globalThis.Request(error.customRequest);
|
|
858
|
+
__privateMethod(this, _Ky_instances, assignRequest_fn).call(this, managedRequest);
|
|
859
|
+
}
|
|
860
|
+
for (const hook of __privateGet(this, _options).hooks.beforeRetry) {
|
|
861
|
+
const hookResult = yield hook({
|
|
862
|
+
request: this.request,
|
|
863
|
+
options: __privateMethod(this, _Ky_instances, getNormalizedOptions_fn).call(this),
|
|
864
|
+
error,
|
|
865
|
+
retryCount: __privateGet(this, _retryCount)
|
|
866
|
+
});
|
|
867
|
+
if (hookResult instanceof globalThis.Request) {
|
|
868
|
+
__privateMethod(this, _Ky_instances, assignRequest_fn).call(this, hookResult);
|
|
651
869
|
break;
|
|
652
870
|
}
|
|
653
|
-
if (
|
|
654
|
-
return
|
|
871
|
+
if (hookResult instanceof globalThis.Response) {
|
|
872
|
+
return hookResult;
|
|
873
|
+
}
|
|
874
|
+
if (hookResult === stop) {
|
|
875
|
+
return;
|
|
655
876
|
}
|
|
656
877
|
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
878
|
+
return __privateMethod(this, _Ky_instances, retry_fn).call(this, function_);
|
|
879
|
+
}
|
|
880
|
+
});
|
|
881
|
+
};
|
|
882
|
+
fetch_fn = function() {
|
|
883
|
+
return __async(this, null, function* () {
|
|
884
|
+
var _a;
|
|
885
|
+
if ((_a = __privateGet(this, _abortController)) == null ? void 0 : _a.signal.aborted) {
|
|
886
|
+
__privateSet(this, _abortController, new globalThis.AbortController());
|
|
887
|
+
__privateGet(this, _options).signal = __privateGet(this, _userProvidedAbortSignal) ? AbortSignal.any([__privateGet(this, _userProvidedAbortSignal), __privateGet(this, _abortController).signal]) : __privateGet(this, _abortController).signal;
|
|
888
|
+
this.request = new globalThis.Request(this.request, { signal: __privateGet(this, _options).signal });
|
|
889
|
+
}
|
|
890
|
+
for (const hook of __privateGet(this, _options).hooks.beforeRequest) {
|
|
891
|
+
const result = yield hook(this.request, __privateMethod(this, _Ky_instances, getNormalizedOptions_fn).call(this), { retryCount: __privateGet(this, _retryCount) });
|
|
892
|
+
if (result instanceof Response) {
|
|
893
|
+
return result;
|
|
894
|
+
}
|
|
895
|
+
if (result instanceof globalThis.Request) {
|
|
896
|
+
__privateMethod(this, _Ky_instances, assignRequest_fn).call(this, result);
|
|
897
|
+
break;
|
|
662
898
|
}
|
|
663
|
-
|
|
664
|
-
|
|
899
|
+
}
|
|
900
|
+
const nonRequestOptions = findUnknownOptions(this.request, __privateGet(this, _options));
|
|
901
|
+
__privateSet(this, _originalRequest, this.request);
|
|
902
|
+
this.request = __privateGet(this, _originalRequest).clone();
|
|
903
|
+
if (__privateGet(this, _options).timeout === false) {
|
|
904
|
+
return __privateGet(this, _options).fetch(__privateGet(this, _originalRequest), nonRequestOptions);
|
|
905
|
+
}
|
|
906
|
+
return timeout(__privateGet(this, _originalRequest), nonRequestOptions, __privateGet(this, _abortController), __privateGet(this, _options));
|
|
907
|
+
});
|
|
908
|
+
};
|
|
909
|
+
getNormalizedOptions_fn = function() {
|
|
910
|
+
if (!__privateGet(this, _cachedNormalizedOptions)) {
|
|
911
|
+
const _a = __privateGet(this, _options), { hooks } = _a, normalizedOptions = __objRest(_a, ["hooks"]);
|
|
912
|
+
__privateSet(this, _cachedNormalizedOptions, Object.freeze(normalizedOptions));
|
|
665
913
|
}
|
|
914
|
+
return __privateGet(this, _cachedNormalizedOptions);
|
|
666
915
|
};
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
916
|
+
assignRequest_fn = function(request) {
|
|
917
|
+
__privateSet(this, _cachedNormalizedOptions, void 0);
|
|
918
|
+
this.request = __privateMethod(this, _Ky_instances, wrapRequestWithUploadProgress_fn).call(this, request);
|
|
919
|
+
};
|
|
920
|
+
wrapRequestWithUploadProgress_fn = function(request, originalBody) {
|
|
921
|
+
var _a;
|
|
922
|
+
if (!__privateGet(this, _options).onUploadProgress || !request.body) {
|
|
923
|
+
return request;
|
|
671
924
|
}
|
|
672
|
-
return
|
|
925
|
+
return streamRequest(request, __privateGet(this, _options).onUploadProgress, (_a = originalBody != null ? originalBody : __privateGet(this, _options).body) != null ? _a : void 0);
|
|
673
926
|
};
|
|
674
927
|
__privateAdd(_Ky, _Ky_static);
|
|
675
928
|
var Ky = _Ky;
|
|
676
929
|
|
|
677
|
-
// node_modules/.pnpm/ky@1.
|
|
930
|
+
// node_modules/.pnpm/ky@1.14.3/node_modules/ky/distribution/index.js
|
|
678
931
|
var createInstance = (defaults) => {
|
|
679
932
|
const ky2 = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
|
|
680
933
|
for (const method of requestMethods) {
|
|
@@ -688,29 +941,128 @@ var createInstance = (defaults) => {
|
|
|
688
941
|
return createInstance(validateAndMerge(defaults, newDefaults));
|
|
689
942
|
};
|
|
690
943
|
ky2.stop = stop;
|
|
944
|
+
ky2.retry = retry;
|
|
691
945
|
return ky2;
|
|
692
946
|
};
|
|
693
947
|
var ky = createInstance();
|
|
694
948
|
var distribution_default = ky;
|
|
695
949
|
|
|
950
|
+
// src/email/emails.ts
|
|
951
|
+
var import_render = require("@react-email/render");
|
|
952
|
+
var Emails = class {
|
|
953
|
+
constructor(zupost) {
|
|
954
|
+
this.zupost = zupost;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Send an email using template, markdown or HTML content.
|
|
958
|
+
*
|
|
959
|
+
* @param options - Email options including recipient, sender, and content.
|
|
960
|
+
* @returns A promise that resolves to the email response containing emailId.
|
|
961
|
+
*
|
|
962
|
+
* @example
|
|
963
|
+
* ```typescript
|
|
964
|
+
* const zupost = new Zupost('your-api-key');
|
|
965
|
+
*
|
|
966
|
+
* // Send with HTML content
|
|
967
|
+
* const { emailId } = await zupost.emails.send({
|
|
968
|
+
* from: 'sender@example.com',
|
|
969
|
+
* to: 'recipient@example.com',
|
|
970
|
+
* subject: 'Hello World',
|
|
971
|
+
* html: '<h1>Hello!</h1>',
|
|
972
|
+
* });
|
|
973
|
+
*
|
|
974
|
+
* // Send with a template
|
|
975
|
+
* await zupost.emails.send({
|
|
976
|
+
* from: 'sender@example.com',
|
|
977
|
+
* to: ['user1@example.com', 'user2@example.com'],
|
|
978
|
+
* subject: 'Welcome!',
|
|
979
|
+
* templateId: 'welcome-template',
|
|
980
|
+
* variables: { name: 'John' },
|
|
981
|
+
* });
|
|
982
|
+
*
|
|
983
|
+
* // Send with markdown
|
|
984
|
+
* await zupost.emails.send({
|
|
985
|
+
* from: 'sender@example.com',
|
|
986
|
+
* to: 'recipient@example.com',
|
|
987
|
+
* subject: 'Newsletter',
|
|
988
|
+
* markdown: '# Hello\n\nThis is **markdown** content.',
|
|
989
|
+
* });
|
|
990
|
+
* ```
|
|
991
|
+
*/
|
|
992
|
+
send(options) {
|
|
993
|
+
return __async(this, null, function* () {
|
|
994
|
+
if (options.react) {
|
|
995
|
+
options.html = yield (0, import_render.render)(options.react, options.reactOptions);
|
|
996
|
+
delete options.react;
|
|
997
|
+
delete options.reactOptions;
|
|
998
|
+
}
|
|
999
|
+
if (!options.html && !options.markdown && !options.react && !options.templateId) {
|
|
1000
|
+
throw new Error("Either html, markdown, react or templateId must be provided");
|
|
1001
|
+
}
|
|
1002
|
+
if (options.html && options.markdown) {
|
|
1003
|
+
throw new Error("Either html or markdown must be provided");
|
|
1004
|
+
}
|
|
1005
|
+
if (options.react && options.html) {
|
|
1006
|
+
throw new Error("Either react or html must be provided");
|
|
1007
|
+
}
|
|
1008
|
+
return this.zupost.post("email/send", options);
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
|
|
1013
|
+
// src/campaign/campaigns.ts
|
|
1014
|
+
var Campaigns = class {
|
|
1015
|
+
constructor(zupost) {
|
|
1016
|
+
this.zupost = zupost;
|
|
1017
|
+
}
|
|
1018
|
+
/**
|
|
1019
|
+
* Send a campaign to selected audiences.
|
|
1020
|
+
*
|
|
1021
|
+
* @param options - Campaign options including the campaign ID.
|
|
1022
|
+
* @returns A promise that resolves to the campaign response.
|
|
1023
|
+
*
|
|
1024
|
+
* @example
|
|
1025
|
+
* ```typescript
|
|
1026
|
+
* const zupost = new Zupost('your-api-key');
|
|
1027
|
+
*
|
|
1028
|
+
* const { success, message } = await zupost.campaigns.send({
|
|
1029
|
+
* campaignId: 'campaign_123',
|
|
1030
|
+
* });
|
|
1031
|
+
*
|
|
1032
|
+
* if (success) {
|
|
1033
|
+
* console.log('Campaign sent:', message);
|
|
1034
|
+
* }
|
|
1035
|
+
* ```
|
|
1036
|
+
*/
|
|
1037
|
+
send(options) {
|
|
1038
|
+
return __async(this, null, function* () {
|
|
1039
|
+
return this.zupost.post("campaign/send", options);
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
|
|
696
1044
|
// src/zupost.ts
|
|
697
1045
|
var Zupost = class {
|
|
698
|
-
constructor(apiKey,
|
|
699
|
-
this.apiKey = apiKey;
|
|
700
|
-
this.apiUrl = apiUrl;
|
|
1046
|
+
constructor(apiKey, options) {
|
|
701
1047
|
this.baseUrl = "https://api.zupost.com";
|
|
702
1048
|
if (!apiKey) {
|
|
703
1049
|
throw new Error("API key is required");
|
|
704
1050
|
}
|
|
705
|
-
if (
|
|
706
|
-
this.baseUrl =
|
|
1051
|
+
if (options == null ? void 0 : options.baseUrl) {
|
|
1052
|
+
this.baseUrl = options.baseUrl;
|
|
707
1053
|
}
|
|
708
1054
|
this.headers = new Headers({
|
|
709
1055
|
"Authorization": `Bearer ${apiKey}`,
|
|
710
1056
|
"Content-Type": "application/json",
|
|
711
1057
|
"User-Agent": `node-sdk@${version}`
|
|
712
1058
|
});
|
|
1059
|
+
this.emails = new Emails(this);
|
|
1060
|
+
this.campaigns = new Campaigns(this);
|
|
713
1061
|
}
|
|
1062
|
+
/**
|
|
1063
|
+
* @internal
|
|
1064
|
+
* Makes a request to the Zupost API.
|
|
1065
|
+
*/
|
|
714
1066
|
request(path, method, body) {
|
|
715
1067
|
return __async(this, null, function* () {
|
|
716
1068
|
return distribution_default(path, {
|
|
@@ -718,15 +1070,23 @@ var Zupost = class {
|
|
|
718
1070
|
method,
|
|
719
1071
|
retry: 3,
|
|
720
1072
|
prefixUrl: this.baseUrl,
|
|
721
|
-
body
|
|
1073
|
+
json: body
|
|
722
1074
|
}).json();
|
|
723
1075
|
});
|
|
724
1076
|
}
|
|
1077
|
+
/**
|
|
1078
|
+
* @internal
|
|
1079
|
+
* Makes a GET request to the Zupost API.
|
|
1080
|
+
*/
|
|
725
1081
|
get(path) {
|
|
726
1082
|
return __async(this, null, function* () {
|
|
727
1083
|
return this.request(path, "GET");
|
|
728
1084
|
});
|
|
729
1085
|
}
|
|
1086
|
+
/**
|
|
1087
|
+
* @internal
|
|
1088
|
+
* Makes a POST request to the Zupost API.
|
|
1089
|
+
*/
|
|
730
1090
|
post(path, body) {
|
|
731
1091
|
return __async(this, null, function* () {
|
|
732
1092
|
return this.request(path, "POST", body);
|