zupost 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,744 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __typeError = (msg) => {
11
+ throw TypeError(msg);
12
+ };
13
+ var __pow = Math.pow;
14
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ if (__getOwnPropSymbols)
20
+ for (var prop of __getOwnPropSymbols(b)) {
21
+ if (__propIsEnum.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ var __export = (target, all) => {
28
+ for (var name in all)
29
+ __defProp(target, name, { get: all[name], enumerable: true });
30
+ };
31
+ var __copyProps = (to, from, except, desc) => {
32
+ if (from && typeof from === "object" || typeof from === "function") {
33
+ for (let key of __getOwnPropNames(from))
34
+ if (!__hasOwnProp.call(to, key) && key !== except)
35
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
36
+ }
37
+ return to;
38
+ };
39
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
41
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
42
+ 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);
43
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
44
+ var __async = (__this, __arguments, generator) => {
45
+ return new Promise((resolve, reject) => {
46
+ var fulfilled = (value) => {
47
+ try {
48
+ step(generator.next(value));
49
+ } catch (e) {
50
+ reject(e);
51
+ }
52
+ };
53
+ var rejected = (value) => {
54
+ try {
55
+ step(generator.throw(value));
56
+ } catch (e) {
57
+ reject(e);
58
+ }
59
+ };
60
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
61
+ step((generator = generator.apply(__this, __arguments)).next());
62
+ });
63
+ };
64
+
65
+ // src/index.ts
66
+ var index_exports = {};
67
+ __export(index_exports, {
68
+ Zupost: () => Zupost
69
+ });
70
+ module.exports = __toCommonJS(index_exports);
71
+
72
+ // package.json
73
+ var version = "0.0.0";
74
+
75
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/errors/HTTPError.js
76
+ var HTTPError = class extends Error {
77
+ constructor(response, request, options) {
78
+ var _a;
79
+ const code = response.status || response.status === 0 ? response.status : "";
80
+ const title = (_a = response.statusText) != null ? _a : "";
81
+ const status = `${code} ${title}`.trim();
82
+ const reason = status ? `status code ${status}` : "an unknown error";
83
+ super(`Request failed with ${reason}: ${request.method} ${request.url}`);
84
+ __publicField(this, "response");
85
+ __publicField(this, "request");
86
+ __publicField(this, "options");
87
+ this.name = "HTTPError";
88
+ this.response = response;
89
+ this.request = request;
90
+ this.options = options;
91
+ }
92
+ };
93
+
94
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/errors/TimeoutError.js
95
+ var TimeoutError = class extends Error {
96
+ constructor(request) {
97
+ super(`Request timed out: ${request.method} ${request.url}`);
98
+ __publicField(this, "request");
99
+ this.name = "TimeoutError";
100
+ this.request = request;
101
+ }
102
+ };
103
+
104
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/core/constants.js
105
+ var supportsRequestStreams = (() => {
106
+ let duplexAccessed = false;
107
+ let hasContentType = false;
108
+ const supportsReadableStream = typeof globalThis.ReadableStream === "function";
109
+ const supportsRequest = typeof globalThis.Request === "function";
110
+ if (supportsReadableStream && supportsRequest) {
111
+ try {
112
+ hasContentType = new globalThis.Request("https://empty.invalid", {
113
+ body: new globalThis.ReadableStream(),
114
+ method: "POST",
115
+ // @ts-expect-error - Types are outdated.
116
+ get duplex() {
117
+ duplexAccessed = true;
118
+ return "half";
119
+ }
120
+ }).headers.has("Content-Type");
121
+ } catch (error) {
122
+ if (error instanceof Error && error.message === "unsupported BodyInit type") {
123
+ return false;
124
+ }
125
+ throw error;
126
+ }
127
+ }
128
+ return duplexAccessed && !hasContentType;
129
+ })();
130
+ var supportsAbortController = typeof globalThis.AbortController === "function";
131
+ var supportsAbortSignal = typeof globalThis.AbortSignal === "function" && typeof globalThis.AbortSignal.any === "function";
132
+ var supportsResponseStreams = typeof globalThis.ReadableStream === "function";
133
+ var supportsFormData = typeof globalThis.FormData === "function";
134
+ var requestMethods = ["get", "post", "put", "patch", "head", "delete"];
135
+ var validate = () => void 0;
136
+ validate();
137
+ var responseTypes = {
138
+ json: "application/json",
139
+ text: "text/*",
140
+ formData: "multipart/form-data",
141
+ arrayBuffer: "*/*",
142
+ blob: "*/*",
143
+ // Supported in modern Fetch implementations (for example, browsers and recent Node.js/undici).
144
+ // We still feature-check at runtime before exposing the shortcut.
145
+ bytes: "*/*"
146
+ };
147
+ var maxSafeTimeout = 2147483647;
148
+ var usualFormBoundarySize = new TextEncoder().encode("------WebKitFormBoundaryaxpyiPgbbPti10Rw").length;
149
+ var stop = Symbol("stop");
150
+ var kyOptionKeys = {
151
+ json: true,
152
+ parseJson: true,
153
+ stringifyJson: true,
154
+ searchParams: true,
155
+ prefixUrl: true,
156
+ retry: true,
157
+ timeout: true,
158
+ hooks: true,
159
+ throwHttpErrors: true,
160
+ onDownloadProgress: true,
161
+ onUploadProgress: true,
162
+ fetch: true
163
+ };
164
+ var requestOptionsRegistry = {
165
+ method: true,
166
+ headers: true,
167
+ body: true,
168
+ mode: true,
169
+ credentials: true,
170
+ cache: true,
171
+ redirect: true,
172
+ referrer: true,
173
+ referrerPolicy: true,
174
+ integrity: true,
175
+ keepalive: true,
176
+ signal: true,
177
+ window: true,
178
+ dispatcher: true,
179
+ duplex: true,
180
+ priority: true
181
+ };
182
+
183
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/utils/body.js
184
+ var getBodySize = (body) => {
185
+ if (!body) {
186
+ return 0;
187
+ }
188
+ if (body instanceof FormData) {
189
+ let size = 0;
190
+ for (const [key, value] of body) {
191
+ size += usualFormBoundarySize;
192
+ size += new TextEncoder().encode(`Content-Disposition: form-data; name="${key}"`).length;
193
+ size += typeof value === "string" ? new TextEncoder().encode(value).length : value.size;
194
+ }
195
+ return size;
196
+ }
197
+ if (body instanceof Blob) {
198
+ return body.size;
199
+ }
200
+ if (body instanceof ArrayBuffer) {
201
+ return body.byteLength;
202
+ }
203
+ if (typeof body === "string") {
204
+ return new TextEncoder().encode(body).length;
205
+ }
206
+ if (body instanceof URLSearchParams) {
207
+ return new TextEncoder().encode(body.toString()).length;
208
+ }
209
+ if ("byteLength" in body) {
210
+ return body.byteLength;
211
+ }
212
+ if (typeof body === "object" && body !== null) {
213
+ try {
214
+ const jsonString = JSON.stringify(body);
215
+ return new TextEncoder().encode(jsonString).length;
216
+ } catch (e) {
217
+ return 0;
218
+ }
219
+ }
220
+ return 0;
221
+ };
222
+ var withProgress = (stream, totalBytes, onProgress) => {
223
+ let previousChunk;
224
+ let transferredBytes = 0;
225
+ return stream.pipeThrough(new TransformStream({
226
+ transform(currentChunk, controller) {
227
+ controller.enqueue(currentChunk);
228
+ if (previousChunk) {
229
+ transferredBytes += previousChunk.byteLength;
230
+ let percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
231
+ if (percent >= 1) {
232
+ percent = 1 - Number.EPSILON;
233
+ }
234
+ onProgress == null ? void 0 : onProgress({ percent, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes }, previousChunk);
235
+ }
236
+ previousChunk = currentChunk;
237
+ },
238
+ flush() {
239
+ if (previousChunk) {
240
+ transferredBytes += previousChunk.byteLength;
241
+ onProgress == null ? void 0 : onProgress({ percent: 1, totalBytes: Math.max(totalBytes, transferredBytes), transferredBytes }, previousChunk);
242
+ }
243
+ }
244
+ }));
245
+ };
246
+ var streamResponse = (response, onDownloadProgress) => {
247
+ if (!response.body) {
248
+ return response;
249
+ }
250
+ if (response.status === 204) {
251
+ return new Response(null, {
252
+ status: response.status,
253
+ statusText: response.statusText,
254
+ headers: response.headers
255
+ });
256
+ }
257
+ const totalBytes = Number(response.headers.get("content-length")) || 0;
258
+ return new Response(withProgress(response.body, totalBytes, onDownloadProgress), {
259
+ status: response.status,
260
+ statusText: response.statusText,
261
+ headers: response.headers
262
+ });
263
+ };
264
+ var streamRequest = (request, onUploadProgress, originalBody) => {
265
+ if (!request.body) {
266
+ return request;
267
+ }
268
+ const totalBytes = getBodySize(originalBody != null ? originalBody : request.body);
269
+ return new Request(request, {
270
+ // @ts-expect-error - Types are outdated.
271
+ duplex: "half",
272
+ body: withProgress(request.body, totalBytes, onUploadProgress)
273
+ });
274
+ };
275
+
276
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/utils/is.js
277
+ var isObject = (value) => value !== null && typeof value === "object";
278
+
279
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/utils/merge.js
280
+ var validateAndMerge = (...sources) => {
281
+ for (const source of sources) {
282
+ if ((!isObject(source) || Array.isArray(source)) && source !== void 0) {
283
+ throw new TypeError("The `options` argument must be an object");
284
+ }
285
+ }
286
+ return deepMerge({}, ...sources);
287
+ };
288
+ var mergeHeaders = (source1 = {}, source2 = {}) => {
289
+ const result = new globalThis.Headers(source1);
290
+ const isHeadersInstance = source2 instanceof globalThis.Headers;
291
+ const source = new globalThis.Headers(source2);
292
+ for (const [key, value] of source.entries()) {
293
+ if (isHeadersInstance && value === "undefined" || value === void 0) {
294
+ result.delete(key);
295
+ } else {
296
+ result.set(key, value);
297
+ }
298
+ }
299
+ return result;
300
+ };
301
+ function newHookValue(original, incoming, property) {
302
+ var _a, _b;
303
+ return Object.hasOwn(incoming, property) && incoming[property] === void 0 ? [] : deepMerge((_a = original[property]) != null ? _a : [], (_b = incoming[property]) != null ? _b : []);
304
+ }
305
+ var mergeHooks = (original = {}, incoming = {}) => ({
306
+ beforeRequest: newHookValue(original, incoming, "beforeRequest"),
307
+ beforeRetry: newHookValue(original, incoming, "beforeRetry"),
308
+ afterResponse: newHookValue(original, incoming, "afterResponse"),
309
+ beforeError: newHookValue(original, incoming, "beforeError")
310
+ });
311
+ var deepMerge = (...sources) => {
312
+ let returnValue = {};
313
+ let headers = {};
314
+ let hooks = {};
315
+ for (const source of sources) {
316
+ if (Array.isArray(source)) {
317
+ if (!Array.isArray(returnValue)) {
318
+ returnValue = [];
319
+ }
320
+ returnValue = [...returnValue, ...source];
321
+ } else if (isObject(source)) {
322
+ for (let [key, value] of Object.entries(source)) {
323
+ if (isObject(value) && key in returnValue) {
324
+ value = deepMerge(returnValue[key], value);
325
+ }
326
+ returnValue = __spreadProps(__spreadValues({}, returnValue), { [key]: value });
327
+ }
328
+ if (isObject(source.hooks)) {
329
+ hooks = mergeHooks(hooks, source.hooks);
330
+ returnValue.hooks = hooks;
331
+ }
332
+ if (isObject(source.headers)) {
333
+ headers = mergeHeaders(headers, source.headers);
334
+ returnValue.headers = headers;
335
+ }
336
+ }
337
+ }
338
+ return returnValue;
339
+ };
340
+
341
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/utils/normalize.js
342
+ var normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
343
+ var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
344
+ var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
345
+ var retryAfterStatusCodes = [413, 429, 503];
346
+ var defaultRetryOptions = {
347
+ limit: 2,
348
+ methods: retryMethods,
349
+ statusCodes: retryStatusCodes,
350
+ afterStatusCodes: retryAfterStatusCodes,
351
+ maxRetryAfter: Number.POSITIVE_INFINITY,
352
+ backoffLimit: Number.POSITIVE_INFINITY,
353
+ delay: (attemptCount) => 0.3 * __pow(2, attemptCount - 1) * 1e3
354
+ };
355
+ var normalizeRetryOptions = (retry = {}) => {
356
+ if (typeof retry === "number") {
357
+ return __spreadProps(__spreadValues({}, defaultRetryOptions), {
358
+ limit: retry
359
+ });
360
+ }
361
+ if (retry.methods && !Array.isArray(retry.methods)) {
362
+ throw new Error("retry.methods must be an array");
363
+ }
364
+ if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
365
+ throw new Error("retry.statusCodes must be an array");
366
+ }
367
+ return __spreadValues(__spreadValues({}, defaultRetryOptions), retry);
368
+ };
369
+
370
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/utils/timeout.js
371
+ function timeout(request, init, abortController, options) {
372
+ return __async(this, null, function* () {
373
+ return new Promise((resolve, reject) => {
374
+ const timeoutId = setTimeout(() => {
375
+ if (abortController) {
376
+ abortController.abort();
377
+ }
378
+ reject(new TimeoutError(request));
379
+ }, options.timeout);
380
+ void options.fetch(request, init).then(resolve).catch(reject).then(() => {
381
+ clearTimeout(timeoutId);
382
+ });
383
+ });
384
+ });
385
+ }
386
+
387
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/utils/delay.js
388
+ function delay(_0, _1) {
389
+ return __async(this, arguments, function* (ms, { signal }) {
390
+ return new Promise((resolve, reject) => {
391
+ if (signal) {
392
+ signal.throwIfAborted();
393
+ signal.addEventListener("abort", abortHandler, { once: true });
394
+ }
395
+ function abortHandler() {
396
+ clearTimeout(timeoutId);
397
+ reject(signal.reason);
398
+ }
399
+ const timeoutId = setTimeout(() => {
400
+ signal == null ? void 0 : signal.removeEventListener("abort", abortHandler);
401
+ resolve();
402
+ }, ms);
403
+ });
404
+ });
405
+ }
406
+
407
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/utils/options.js
408
+ var findUnknownOptions = (request, options) => {
409
+ const unknownOptions = {};
410
+ for (const key in options) {
411
+ if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && !(key in request)) {
412
+ unknownOptions[key] = options[key];
413
+ }
414
+ }
415
+ return unknownOptions;
416
+ };
417
+ var hasSearchParameters = (search) => {
418
+ if (search === void 0) {
419
+ return false;
420
+ }
421
+ if (Array.isArray(search)) {
422
+ return search.length > 0;
423
+ }
424
+ if (search instanceof URLSearchParams) {
425
+ return search.size > 0;
426
+ }
427
+ if (typeof search === "object") {
428
+ return Object.keys(search).length > 0;
429
+ }
430
+ if (typeof search === "string") {
431
+ return search.trim().length > 0;
432
+ }
433
+ return Boolean(search);
434
+ };
435
+
436
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/core/Ky.js
437
+ var _Ky_static, normalizeSearchParams_fn;
438
+ var _Ky = class _Ky {
439
+ // eslint-disable-next-line complexity
440
+ constructor(input, options = {}) {
441
+ __publicField(this, "request");
442
+ __publicField(this, "abortController");
443
+ __publicField(this, "_retryCount", 0);
444
+ __publicField(this, "_input");
445
+ __publicField(this, "_options");
446
+ __publicField(this, "_originalRequest");
447
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
448
+ this._input = input;
449
+ this._options = __spreadProps(__spreadValues({}, options), {
450
+ headers: mergeHeaders(this._input.headers, options.headers),
451
+ hooks: mergeHooks({
452
+ beforeRequest: [],
453
+ beforeRetry: [],
454
+ beforeError: [],
455
+ afterResponse: []
456
+ }, options.hooks),
457
+ method: normalizeRequestMethod((_b = (_a = options.method) != null ? _a : this._input.method) != null ? _b : "GET"),
458
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
459
+ prefixUrl: String(options.prefixUrl || ""),
460
+ retry: normalizeRetryOptions(options.retry),
461
+ throwHttpErrors: options.throwHttpErrors !== false,
462
+ timeout: (_c = options.timeout) != null ? _c : 1e4,
463
+ fetch: (_d = options.fetch) != null ? _d : globalThis.fetch.bind(globalThis)
464
+ });
465
+ if (typeof this._input !== "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
466
+ throw new TypeError("`input` must be a string, URL, or Request");
467
+ }
468
+ if (this._options.prefixUrl && typeof this._input === "string") {
469
+ if (this._input.startsWith("/")) {
470
+ throw new Error("`input` must not begin with a slash when using `prefixUrl`");
471
+ }
472
+ if (!this._options.prefixUrl.endsWith("/")) {
473
+ this._options.prefixUrl += "/";
474
+ }
475
+ this._input = this._options.prefixUrl + this._input;
476
+ }
477
+ if (supportsAbortController && supportsAbortSignal) {
478
+ const originalSignal = (_e = this._options.signal) != null ? _e : this._input.signal;
479
+ this.abortController = new globalThis.AbortController();
480
+ this._options.signal = originalSignal ? AbortSignal.any([originalSignal, this.abortController.signal]) : this.abortController.signal;
481
+ }
482
+ if (supportsRequestStreams) {
483
+ this._options.duplex = "half";
484
+ }
485
+ if (this._options.json !== void 0) {
486
+ this._options.body = (_h = (_g = (_f = this._options).stringifyJson) == null ? void 0 : _g.call(_f, this._options.json)) != null ? _h : JSON.stringify(this._options.json);
487
+ this._options.headers.set("content-type", (_i = this._options.headers.get("content-type")) != null ? _i : "application/json");
488
+ }
489
+ this.request = new globalThis.Request(this._input, this._options);
490
+ if (hasSearchParameters(this._options.searchParams)) {
491
+ const textSearchParams = typeof this._options.searchParams === "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(__privateMethod(_j = _Ky, _Ky_static, normalizeSearchParams_fn).call(_j, this._options.searchParams)).toString();
492
+ const searchParams = "?" + textSearchParams;
493
+ const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
494
+ if ((supportsFormData && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"])) {
495
+ this.request.headers.delete("content-type");
496
+ }
497
+ this.request = new globalThis.Request(new globalThis.Request(url, __spreadValues({}, this.request)), this._options);
498
+ }
499
+ if (this._options.onUploadProgress) {
500
+ if (typeof this._options.onUploadProgress !== "function") {
501
+ throw new TypeError("The `onUploadProgress` option must be a function");
502
+ }
503
+ if (!supportsRequestStreams) {
504
+ throw new Error("Request streams are not supported in your environment. The `duplex` option for `Request` is not available.");
505
+ }
506
+ const originalBody = this.request.body;
507
+ if (originalBody) {
508
+ this.request = streamRequest(this.request, this._options.onUploadProgress, this._options.body);
509
+ }
510
+ }
511
+ }
512
+ static create(input, options) {
513
+ var _a, _b;
514
+ const ky2 = new _Ky(input, options);
515
+ const function_ = () => __async(null, null, function* () {
516
+ if (typeof ky2._options.timeout === "number" && ky2._options.timeout > maxSafeTimeout) {
517
+ throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
518
+ }
519
+ yield Promise.resolve();
520
+ let response = yield ky2._fetch();
521
+ for (const hook of ky2._options.hooks.afterResponse) {
522
+ const modifiedResponse = yield hook(ky2.request, ky2._options, ky2._decorateResponse(response.clone()));
523
+ if (modifiedResponse instanceof globalThis.Response) {
524
+ response = modifiedResponse;
525
+ }
526
+ }
527
+ ky2._decorateResponse(response);
528
+ if (!response.ok && ky2._options.throwHttpErrors) {
529
+ let error = new HTTPError(response, ky2.request, ky2._options);
530
+ for (const hook of ky2._options.hooks.beforeError) {
531
+ error = yield hook(error);
532
+ }
533
+ throw error;
534
+ }
535
+ if (ky2._options.onDownloadProgress) {
536
+ if (typeof ky2._options.onDownloadProgress !== "function") {
537
+ throw new TypeError("The `onDownloadProgress` option must be a function");
538
+ }
539
+ if (!supportsResponseStreams) {
540
+ throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
541
+ }
542
+ return streamResponse(response.clone(), ky2._options.onDownloadProgress);
543
+ }
544
+ return response;
545
+ });
546
+ const isRetriableMethod = ky2._options.retry.methods.includes(ky2.request.method.toLowerCase());
547
+ const result = (isRetriableMethod ? ky2._retry(function_) : function_()).finally(() => __async(null, null, function* () {
548
+ var _a2, _b2;
549
+ const originalRequest = ky2._originalRequest;
550
+ const cleanupPromises = [];
551
+ if (originalRequest && !originalRequest.bodyUsed) {
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
+ }));
559
+ for (const [type, mimeType] of Object.entries(responseTypes)) {
560
+ if (type === "bytes" && typeof ((_b = (_a = globalThis.Response) == null ? void 0 : _a.prototype) == null ? void 0 : _b.bytes) !== "function") {
561
+ continue;
562
+ }
563
+ result[type] = () => __async(null, null, function* () {
564
+ ky2.request.headers.set("accept", ky2.request.headers.get("accept") || mimeType);
565
+ const response = yield result;
566
+ if (type === "json") {
567
+ if (response.status === 204) {
568
+ return "";
569
+ }
570
+ const text = yield response.text();
571
+ if (text === "") {
572
+ return "";
573
+ }
574
+ if (options.parseJson) {
575
+ return options.parseJson(text);
576
+ }
577
+ return JSON.parse(text);
578
+ }
579
+ return response[type]();
580
+ });
581
+ }
582
+ return result;
583
+ }
584
+ _calculateRetryDelay(error) {
585
+ var _a, _b, _c, _d;
586
+ this._retryCount++;
587
+ if (this._retryCount > this._options.retry.limit || error instanceof TimeoutError) {
588
+ throw error;
589
+ }
590
+ if (error instanceof HTTPError) {
591
+ if (!this._options.retry.statusCodes.includes(error.response.status)) {
592
+ throw error;
593
+ }
594
+ const retryAfter = (_c = (_b = (_a = error.response.headers.get("Retry-After")) != null ? _a : error.response.headers.get("RateLimit-Reset")) != null ? _b : error.response.headers.get("X-RateLimit-Reset")) != null ? _c : error.response.headers.get("X-Rate-Limit-Reset");
595
+ if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
596
+ let after = Number(retryAfter) * 1e3;
597
+ if (Number.isNaN(after)) {
598
+ after = Date.parse(retryAfter) - Date.now();
599
+ } else if (after >= Date.parse("2024-01-01")) {
600
+ after -= Date.now();
601
+ }
602
+ const max = (_d = this._options.retry.maxRetryAfter) != null ? _d : after;
603
+ return after < max ? after : max;
604
+ }
605
+ if (error.response.status === 413) {
606
+ throw error;
607
+ }
608
+ }
609
+ const retryDelay = this._options.retry.delay(this._retryCount);
610
+ return Math.min(this._options.retry.backoffLimit, retryDelay);
611
+ }
612
+ _decorateResponse(response) {
613
+ if (this._options.parseJson) {
614
+ response.json = () => __async(this, null, function* () {
615
+ return this._options.parseJson(yield response.text());
616
+ });
617
+ }
618
+ return response;
619
+ }
620
+ _retry(function_) {
621
+ return __async(this, null, function* () {
622
+ try {
623
+ return yield function_();
624
+ } catch (error) {
625
+ const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
626
+ if (this._retryCount < 1) {
627
+ throw error;
628
+ }
629
+ yield delay(ms, { signal: this._options.signal });
630
+ for (const hook of this._options.hooks.beforeRetry) {
631
+ const hookResult = yield hook({
632
+ request: this.request,
633
+ options: this._options,
634
+ error,
635
+ retryCount: this._retryCount
636
+ });
637
+ if (hookResult === stop) {
638
+ return;
639
+ }
640
+ }
641
+ return this._retry(function_);
642
+ }
643
+ });
644
+ }
645
+ _fetch() {
646
+ return __async(this, null, function* () {
647
+ for (const hook of this._options.hooks.beforeRequest) {
648
+ const result = yield hook(this.request, this._options);
649
+ if (result instanceof Request) {
650
+ this.request = result;
651
+ break;
652
+ }
653
+ if (result instanceof Response) {
654
+ return result;
655
+ }
656
+ }
657
+ const nonRequestOptions = findUnknownOptions(this.request, this._options);
658
+ this._originalRequest = this.request;
659
+ this.request = this._originalRequest.clone();
660
+ if (this._options.timeout === false) {
661
+ return this._options.fetch(this._originalRequest, nonRequestOptions);
662
+ }
663
+ return timeout(this._originalRequest, nonRequestOptions, this.abortController, this._options);
664
+ });
665
+ }
666
+ };
667
+ _Ky_static = new WeakSet();
668
+ normalizeSearchParams_fn = function(searchParams) {
669
+ if (searchParams && typeof searchParams === "object" && !Array.isArray(searchParams) && !(searchParams instanceof URLSearchParams)) {
670
+ return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => value !== void 0));
671
+ }
672
+ return searchParams;
673
+ };
674
+ __privateAdd(_Ky, _Ky_static);
675
+ var Ky = _Ky;
676
+
677
+ // node_modules/.pnpm/ky@1.11.0/node_modules/ky/distribution/index.js
678
+ var createInstance = (defaults) => {
679
+ const ky2 = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
680
+ for (const method of requestMethods) {
681
+ ky2[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
682
+ }
683
+ ky2.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
684
+ ky2.extend = (newDefaults) => {
685
+ if (typeof newDefaults === "function") {
686
+ newDefaults = newDefaults(defaults != null ? defaults : {});
687
+ }
688
+ return createInstance(validateAndMerge(defaults, newDefaults));
689
+ };
690
+ ky2.stop = stop;
691
+ return ky2;
692
+ };
693
+ var ky = createInstance();
694
+ var distribution_default = ky;
695
+
696
+ // src/zupost.ts
697
+ var Zupost = class {
698
+ constructor(apiKey, apiUrl) {
699
+ this.apiKey = apiKey;
700
+ this.apiUrl = apiUrl;
701
+ this.baseUrl = "https://api.zupost.com";
702
+ if (!apiKey) {
703
+ throw new Error("API key is required");
704
+ }
705
+ if (apiUrl) {
706
+ this.baseUrl = apiUrl;
707
+ }
708
+ this.headers = new Headers({
709
+ "Authorization": `Bearer ${apiKey}`,
710
+ "Content-Type": "application/json",
711
+ "User-Agent": `node-sdk@${version}`
712
+ });
713
+ }
714
+ request(path, method, body) {
715
+ return __async(this, null, function* () {
716
+ return distribution_default(path, {
717
+ headers: this.headers,
718
+ method,
719
+ retry: 3,
720
+ prefixUrl: this.baseUrl,
721
+ body
722
+ }).json();
723
+ });
724
+ }
725
+ get(path) {
726
+ return __async(this, null, function* () {
727
+ return this.request(path, "GET");
728
+ });
729
+ }
730
+ post(path, body) {
731
+ return __async(this, null, function* () {
732
+ return this.request(path, "POST", body);
733
+ });
734
+ }
735
+ };
736
+ // Annotate the CommonJS export names for ESM import in node:
737
+ 0 && (module.exports = {
738
+ Zupost
739
+ });
740
+ /*! Bundled license information:
741
+
742
+ ky/distribution/index.js:
743
+ (*! MIT License © Sindre Sorhus *)
744
+ */