@mx-space/api-client 1.8.0-beta.0 → 1.8.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.
@@ -1,590 +0,0 @@
1
- "use strict";
2
- (() => {
3
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/errors/HTTPError.js
4
- var HTTPError = class extends Error {
5
- constructor(response, request, options) {
6
- const code = response.status || response.status === 0 ? response.status : "";
7
- const title = response.statusText || "";
8
- const status = `${code} ${title}`.trim();
9
- const reason = status ? `status code ${status}` : "an unknown error";
10
- super(`Request failed with ${reason}`);
11
- Object.defineProperty(this, "response", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: void 0
16
- });
17
- Object.defineProperty(this, "request", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: void 0
22
- });
23
- Object.defineProperty(this, "options", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: void 0
28
- });
29
- this.name = "HTTPError";
30
- this.response = response;
31
- this.request = request;
32
- this.options = options;
33
- }
34
- };
35
-
36
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/errors/TimeoutError.js
37
- var TimeoutError = class extends Error {
38
- constructor(request) {
39
- super("Request timed out");
40
- Object.defineProperty(this, "request", {
41
- enumerable: true,
42
- configurable: true,
43
- writable: true,
44
- value: void 0
45
- });
46
- this.name = "TimeoutError";
47
- this.request = request;
48
- }
49
- };
50
-
51
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/utils/is.js
52
- var isObject = (value) => value !== null && typeof value === "object";
53
-
54
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/utils/merge.js
55
- var validateAndMerge = (...sources) => {
56
- for (const source of sources) {
57
- if ((!isObject(source) || Array.isArray(source)) && source !== void 0) {
58
- throw new TypeError("The `options` argument must be an object");
59
- }
60
- }
61
- return deepMerge({}, ...sources);
62
- };
63
- var mergeHeaders = (source1 = {}, source2 = {}) => {
64
- const result = new globalThis.Headers(source1);
65
- const isHeadersInstance = source2 instanceof globalThis.Headers;
66
- const source = new globalThis.Headers(source2);
67
- for (const [key, value] of source.entries()) {
68
- if (isHeadersInstance && value === "undefined" || value === void 0) {
69
- result.delete(key);
70
- } else {
71
- result.set(key, value);
72
- }
73
- }
74
- return result;
75
- };
76
- var deepMerge = (...sources) => {
77
- let returnValue = {};
78
- let headers = {};
79
- for (const source of sources) {
80
- if (Array.isArray(source)) {
81
- if (!Array.isArray(returnValue)) {
82
- returnValue = [];
83
- }
84
- returnValue = [...returnValue, ...source];
85
- } else if (isObject(source)) {
86
- for (let [key, value] of Object.entries(source)) {
87
- if (isObject(value) && key in returnValue) {
88
- value = deepMerge(returnValue[key], value);
89
- }
90
- returnValue = { ...returnValue, [key]: value };
91
- }
92
- if (isObject(source.headers)) {
93
- headers = mergeHeaders(headers, source.headers);
94
- returnValue.headers = headers;
95
- }
96
- }
97
- }
98
- return returnValue;
99
- };
100
-
101
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/core/constants.js
102
- var supportsRequestStreams = (() => {
103
- let duplexAccessed = false;
104
- let hasContentType = false;
105
- const supportsReadableStream = typeof globalThis.ReadableStream === "function";
106
- const supportsRequest = typeof globalThis.Request === "function";
107
- if (supportsReadableStream && supportsRequest) {
108
- hasContentType = new globalThis.Request("https://empty.invalid", {
109
- body: new globalThis.ReadableStream(),
110
- method: "POST",
111
- // @ts-expect-error - Types are outdated.
112
- get duplex() {
113
- duplexAccessed = true;
114
- return "half";
115
- }
116
- }).headers.has("Content-Type");
117
- }
118
- return duplexAccessed && !hasContentType;
119
- })();
120
- var supportsAbortController = typeof globalThis.AbortController === "function";
121
- var supportsResponseStreams = typeof globalThis.ReadableStream === "function";
122
- var supportsFormData = typeof globalThis.FormData === "function";
123
- var requestMethods = ["get", "post", "put", "patch", "head", "delete"];
124
- var validate = () => void 0;
125
- validate();
126
- var responseTypes = {
127
- json: "application/json",
128
- text: "text/*",
129
- formData: "multipart/form-data",
130
- arrayBuffer: "*/*",
131
- blob: "*/*"
132
- };
133
- var maxSafeTimeout = 2147483647;
134
- var stop = Symbol("stop");
135
- var kyOptionKeys = {
136
- json: true,
137
- parseJson: true,
138
- searchParams: true,
139
- prefixUrl: true,
140
- retry: true,
141
- timeout: true,
142
- hooks: true,
143
- throwHttpErrors: true,
144
- onDownloadProgress: true,
145
- fetch: true
146
- };
147
- var requestOptionsRegistry = {
148
- method: true,
149
- headers: true,
150
- body: true,
151
- mode: true,
152
- credentials: true,
153
- cache: true,
154
- redirect: true,
155
- referrer: true,
156
- referrerPolicy: true,
157
- integrity: true,
158
- keepalive: true,
159
- signal: true,
160
- window: true,
161
- dispatcher: true,
162
- duplex: true
163
- };
164
-
165
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/utils/normalize.js
166
- var normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
167
- var retryMethods = ["get", "put", "head", "delete", "options", "trace"];
168
- var retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
169
- var retryAfterStatusCodes = [413, 429, 503];
170
- var defaultRetryOptions = {
171
- limit: 2,
172
- methods: retryMethods,
173
- statusCodes: retryStatusCodes,
174
- afterStatusCodes: retryAfterStatusCodes,
175
- maxRetryAfter: Number.POSITIVE_INFINITY,
176
- backoffLimit: Number.POSITIVE_INFINITY,
177
- delay: (attemptCount) => 0.3 * 2 ** (attemptCount - 1) * 1e3
178
- };
179
- var normalizeRetryOptions = (retry = {}) => {
180
- if (typeof retry === "number") {
181
- return {
182
- ...defaultRetryOptions,
183
- limit: retry
184
- };
185
- }
186
- if (retry.methods && !Array.isArray(retry.methods)) {
187
- throw new Error("retry.methods must be an array");
188
- }
189
- if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
190
- throw new Error("retry.statusCodes must be an array");
191
- }
192
- return {
193
- ...defaultRetryOptions,
194
- ...retry,
195
- afterStatusCodes: retryAfterStatusCodes
196
- };
197
- };
198
-
199
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/utils/timeout.js
200
- async function timeout(request, init, abortController, options) {
201
- return new Promise((resolve, reject) => {
202
- const timeoutId = setTimeout(() => {
203
- if (abortController) {
204
- abortController.abort();
205
- }
206
- reject(new TimeoutError(request));
207
- }, options.timeout);
208
- void options.fetch(request, init).then(resolve).catch(reject).then(() => {
209
- clearTimeout(timeoutId);
210
- });
211
- });
212
- }
213
-
214
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/utils/delay.js
215
- async function delay(ms, { signal }) {
216
- return new Promise((resolve, reject) => {
217
- if (signal) {
218
- signal.throwIfAborted();
219
- signal.addEventListener("abort", abortHandler, { once: true });
220
- }
221
- function abortHandler() {
222
- clearTimeout(timeoutId);
223
- reject(signal.reason);
224
- }
225
- const timeoutId = setTimeout(() => {
226
- signal?.removeEventListener("abort", abortHandler);
227
- resolve();
228
- }, ms);
229
- });
230
- }
231
-
232
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/utils/options.js
233
- var findUnknownOptions = (request, options) => {
234
- const unknownOptions = {};
235
- for (const key in options) {
236
- if (!(key in requestOptionsRegistry) && !(key in kyOptionKeys) && !(key in request)) {
237
- unknownOptions[key] = options[key];
238
- }
239
- }
240
- return unknownOptions;
241
- };
242
-
243
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/core/Ky.js
244
- var Ky = class _Ky {
245
- static create(input, options) {
246
- const ky2 = new _Ky(input, options);
247
- const function_ = async () => {
248
- if (typeof ky2._options.timeout === "number" && ky2._options.timeout > maxSafeTimeout) {
249
- throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
250
- }
251
- await Promise.resolve();
252
- let response = await ky2._fetch();
253
- for (const hook of ky2._options.hooks.afterResponse) {
254
- const modifiedResponse = await hook(ky2.request, ky2._options, ky2._decorateResponse(response.clone()));
255
- if (modifiedResponse instanceof globalThis.Response) {
256
- response = modifiedResponse;
257
- }
258
- }
259
- ky2._decorateResponse(response);
260
- if (!response.ok && ky2._options.throwHttpErrors) {
261
- let error = new HTTPError(response, ky2.request, ky2._options);
262
- for (const hook of ky2._options.hooks.beforeError) {
263
- error = await hook(error);
264
- }
265
- throw error;
266
- }
267
- if (ky2._options.onDownloadProgress) {
268
- if (typeof ky2._options.onDownloadProgress !== "function") {
269
- throw new TypeError("The `onDownloadProgress` option must be a function");
270
- }
271
- if (!supportsResponseStreams) {
272
- throw new Error("Streams are not supported in your environment. `ReadableStream` is missing.");
273
- }
274
- return ky2._stream(response.clone(), ky2._options.onDownloadProgress);
275
- }
276
- return response;
277
- };
278
- const isRetriableMethod = ky2._options.retry.methods.includes(ky2.request.method.toLowerCase());
279
- const result = isRetriableMethod ? ky2._retry(function_) : function_();
280
- for (const [type, mimeType] of Object.entries(responseTypes)) {
281
- result[type] = async () => {
282
- ky2.request.headers.set("accept", ky2.request.headers.get("accept") || mimeType);
283
- const awaitedResult = await result;
284
- const response = awaitedResult.clone();
285
- if (type === "json") {
286
- if (response.status === 204) {
287
- return "";
288
- }
289
- const arrayBuffer = await response.clone().arrayBuffer();
290
- const responseSize = arrayBuffer.byteLength;
291
- if (responseSize === 0) {
292
- return "";
293
- }
294
- if (options.parseJson) {
295
- return options.parseJson(await response.text());
296
- }
297
- }
298
- return response[type]();
299
- };
300
- }
301
- return result;
302
- }
303
- // eslint-disable-next-line complexity
304
- constructor(input, options = {}) {
305
- Object.defineProperty(this, "request", {
306
- enumerable: true,
307
- configurable: true,
308
- writable: true,
309
- value: void 0
310
- });
311
- Object.defineProperty(this, "abortController", {
312
- enumerable: true,
313
- configurable: true,
314
- writable: true,
315
- value: void 0
316
- });
317
- Object.defineProperty(this, "_retryCount", {
318
- enumerable: true,
319
- configurable: true,
320
- writable: true,
321
- value: 0
322
- });
323
- Object.defineProperty(this, "_input", {
324
- enumerable: true,
325
- configurable: true,
326
- writable: true,
327
- value: void 0
328
- });
329
- Object.defineProperty(this, "_options", {
330
- enumerable: true,
331
- configurable: true,
332
- writable: true,
333
- value: void 0
334
- });
335
- this._input = input;
336
- this._options = {
337
- // TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
338
- credentials: this._input.credentials || "same-origin",
339
- ...options,
340
- headers: mergeHeaders(this._input.headers, options.headers),
341
- hooks: deepMerge({
342
- beforeRequest: [],
343
- beforeRetry: [],
344
- beforeError: [],
345
- afterResponse: []
346
- }, options.hooks),
347
- method: normalizeRequestMethod(options.method ?? this._input.method),
348
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
349
- prefixUrl: String(options.prefixUrl || ""),
350
- retry: normalizeRetryOptions(options.retry),
351
- throwHttpErrors: options.throwHttpErrors !== false,
352
- timeout: options.timeout ?? 1e4,
353
- fetch: options.fetch ?? globalThis.fetch.bind(globalThis)
354
- };
355
- if (typeof this._input !== "string" && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
356
- throw new TypeError("`input` must be a string, URL, or Request");
357
- }
358
- if (this._options.prefixUrl && typeof this._input === "string") {
359
- if (this._input.startsWith("/")) {
360
- throw new Error("`input` must not begin with a slash when using `prefixUrl`");
361
- }
362
- if (!this._options.prefixUrl.endsWith("/")) {
363
- this._options.prefixUrl += "/";
364
- }
365
- this._input = this._options.prefixUrl + this._input;
366
- }
367
- if (supportsAbortController) {
368
- this.abortController = new globalThis.AbortController();
369
- if (this._options.signal) {
370
- const originalSignal = this._options.signal;
371
- this._options.signal.addEventListener("abort", () => {
372
- this.abortController.abort(originalSignal.reason);
373
- });
374
- }
375
- this._options.signal = this.abortController.signal;
376
- }
377
- if (supportsRequestStreams) {
378
- this._options.duplex = "half";
379
- }
380
- this.request = new globalThis.Request(this._input, this._options);
381
- if (this._options.searchParams) {
382
- const textSearchParams = typeof this._options.searchParams === "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString();
383
- const searchParams = "?" + textSearchParams;
384
- const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
385
- if ((supportsFormData && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"])) {
386
- this.request.headers.delete("content-type");
387
- }
388
- this.request = new globalThis.Request(new globalThis.Request(url, { ...this.request }), this._options);
389
- }
390
- if (this._options.json !== void 0) {
391
- this._options.body = JSON.stringify(this._options.json);
392
- this.request.headers.set("content-type", this._options.headers.get("content-type") ?? "application/json");
393
- this.request = new globalThis.Request(this.request, { body: this._options.body });
394
- }
395
- }
396
- _calculateRetryDelay(error) {
397
- this._retryCount++;
398
- if (this._retryCount <= this._options.retry.limit && !(error instanceof TimeoutError)) {
399
- if (error instanceof HTTPError) {
400
- if (!this._options.retry.statusCodes.includes(error.response.status)) {
401
- return 0;
402
- }
403
- const retryAfter = error.response.headers.get("Retry-After");
404
- if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
405
- let after = Number(retryAfter);
406
- if (Number.isNaN(after)) {
407
- after = Date.parse(retryAfter) - Date.now();
408
- } else {
409
- after *= 1e3;
410
- }
411
- if (this._options.retry.maxRetryAfter !== void 0 && after > this._options.retry.maxRetryAfter) {
412
- return 0;
413
- }
414
- return after;
415
- }
416
- if (error.response.status === 413) {
417
- return 0;
418
- }
419
- }
420
- const retryDelay = this._options.retry.delay(this._retryCount);
421
- return Math.min(this._options.retry.backoffLimit, retryDelay);
422
- }
423
- return 0;
424
- }
425
- _decorateResponse(response) {
426
- if (this._options.parseJson) {
427
- response.json = async () => this._options.parseJson(await response.text());
428
- }
429
- return response;
430
- }
431
- async _retry(function_) {
432
- try {
433
- return await function_();
434
- } catch (error) {
435
- const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
436
- if (ms !== 0 && this._retryCount > 0) {
437
- await delay(ms, { signal: this._options.signal });
438
- for (const hook of this._options.hooks.beforeRetry) {
439
- const hookResult = await hook({
440
- request: this.request,
441
- options: this._options,
442
- error,
443
- retryCount: this._retryCount
444
- });
445
- if (hookResult === stop) {
446
- return;
447
- }
448
- }
449
- return this._retry(function_);
450
- }
451
- throw error;
452
- }
453
- }
454
- async _fetch() {
455
- for (const hook of this._options.hooks.beforeRequest) {
456
- const result = await hook(this.request, this._options);
457
- if (result instanceof Request) {
458
- this.request = result;
459
- break;
460
- }
461
- if (result instanceof Response) {
462
- return result;
463
- }
464
- }
465
- const nonRequestOptions = findUnknownOptions(this.request, this._options);
466
- if (this._options.timeout === false) {
467
- return this._options.fetch(this.request.clone(), nonRequestOptions);
468
- }
469
- return timeout(this.request.clone(), nonRequestOptions, this.abortController, this._options);
470
- }
471
- /* istanbul ignore next */
472
- _stream(response, onDownloadProgress) {
473
- const totalBytes = Number(response.headers.get("content-length")) || 0;
474
- let transferredBytes = 0;
475
- if (response.status === 204) {
476
- if (onDownloadProgress) {
477
- onDownloadProgress({ percent: 1, totalBytes, transferredBytes }, new Uint8Array());
478
- }
479
- return new globalThis.Response(null, {
480
- status: response.status,
481
- statusText: response.statusText,
482
- headers: response.headers
483
- });
484
- }
485
- return new globalThis.Response(new globalThis.ReadableStream({
486
- async start(controller) {
487
- const reader = response.body.getReader();
488
- if (onDownloadProgress) {
489
- onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
490
- }
491
- async function read() {
492
- const { done, value } = await reader.read();
493
- if (done) {
494
- controller.close();
495
- return;
496
- }
497
- if (onDownloadProgress) {
498
- transferredBytes += value.byteLength;
499
- const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
500
- onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
501
- }
502
- controller.enqueue(value);
503
- await read();
504
- }
505
- await read();
506
- }
507
- }), {
508
- status: response.status,
509
- statusText: response.statusText,
510
- headers: response.headers
511
- });
512
- }
513
- };
514
-
515
- // ../../node_modules/.pnpm/ky@1.2.0/node_modules/ky/distribution/index.js
516
- var createInstance = (defaults) => {
517
- const ky2 = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
518
- for (const method of requestMethods) {
519
- ky2[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
520
- }
521
- ky2.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
522
- ky2.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
523
- ky2.stop = stop;
524
- return ky2;
525
- };
526
- var ky = createInstance();
527
- var distribution_default = ky;
528
-
529
- // adaptors/ky.ts
530
- var $http = /* @__PURE__ */ distribution_default.create({});
531
- var getDataFromKyResponse = async (response) => {
532
- const res = await response;
533
- const isJsonType = res.headers.get("content-type")?.includes("application/json");
534
- const json = isJsonType ? await res.clone().json() : null;
535
- const result = {
536
- ...res,
537
- data: json ?? await res.clone().text()
538
- };
539
- return result;
540
- };
541
- var createKyAdaptor = (ky2) => {
542
- const adaptor = Object.preventExtensions({
543
- get default() {
544
- return ky2;
545
- },
546
- responseWrapper: {},
547
- get(url, options) {
548
- return getDataFromKyResponse(ky2.get(url, options));
549
- },
550
- async post(url, options) {
551
- const data = options.data;
552
- delete options.data;
553
- const kyOptions = {
554
- ...options,
555
- json: data
556
- };
557
- return getDataFromKyResponse(ky2.post(url, kyOptions));
558
- },
559
- put(url, options) {
560
- const data = options.data;
561
- delete options.data;
562
- const kyOptions = {
563
- ...options,
564
- json: data
565
- };
566
- return getDataFromKyResponse(ky2.put(url, kyOptions));
567
- },
568
- patch(url, options) {
569
- const data = options.data;
570
- delete options.data;
571
- const kyOptions = {
572
- ...options,
573
- json: data
574
- };
575
- return getDataFromKyResponse(ky2.patch(url, kyOptions));
576
- },
577
- delete(url, options) {
578
- return getDataFromKyResponse(ky2.delete(url, options));
579
- }
580
- });
581
- return adaptor;
582
- };
583
- var defaultKyAdaptor = createKyAdaptor($http);
584
- var ky_default = defaultKyAdaptor;
585
- })();
586
- /*! Bundled license information:
587
-
588
- ky/distribution/index.js:
589
- (*! MIT License © Sindre Sorhus *)
590
- */
@@ -1,62 +0,0 @@
1
- // adaptors/ky.ts
2
- import ky from "ky";
3
- var $http = /* @__PURE__ */ ky.create({});
4
- var getDataFromKyResponse = async (response) => {
5
- const res = await response;
6
- const isJsonType = res.headers.get("content-type")?.includes("application/json");
7
- const json = isJsonType ? await res.clone().json() : null;
8
- const result = {
9
- ...res,
10
- data: json ?? await res.clone().text()
11
- };
12
- return result;
13
- };
14
- var createKyAdaptor = (ky2) => {
15
- const adaptor = Object.preventExtensions({
16
- get default() {
17
- return ky2;
18
- },
19
- responseWrapper: {},
20
- get(url, options) {
21
- return getDataFromKyResponse(ky2.get(url, options));
22
- },
23
- async post(url, options) {
24
- const data = options.data;
25
- delete options.data;
26
- const kyOptions = {
27
- ...options,
28
- json: data
29
- };
30
- return getDataFromKyResponse(ky2.post(url, kyOptions));
31
- },
32
- put(url, options) {
33
- const data = options.data;
34
- delete options.data;
35
- const kyOptions = {
36
- ...options,
37
- json: data
38
- };
39
- return getDataFromKyResponse(ky2.put(url, kyOptions));
40
- },
41
- patch(url, options) {
42
- const data = options.data;
43
- delete options.data;
44
- const kyOptions = {
45
- ...options,
46
- json: data
47
- };
48
- return getDataFromKyResponse(ky2.patch(url, kyOptions));
49
- },
50
- delete(url, options) {
51
- return getDataFromKyResponse(ky2.delete(url, options));
52
- }
53
- });
54
- return adaptor;
55
- };
56
- var defaultKyAdaptor = createKyAdaptor($http);
57
- var ky_default = defaultKyAdaptor;
58
- export {
59
- createKyAdaptor,
60
- ky_default as default,
61
- defaultKyAdaptor
62
- };