@microlink/mql 0.10.19 → 0.10.20

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/mql.js CHANGED
@@ -7,8 +7,14 @@
7
7
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
8
 
9
9
  function getAugmentedNamespace(n) {
10
- if (n.__esModule) return n;
11
- var a = Object.defineProperty({}, '__esModule', {value: true});
10
+ var f = n.default;
11
+ if (typeof f == "function") {
12
+ var a = function () {
13
+ return f.apply(this, arguments);
14
+ };
15
+ a.prototype = f.prototype;
16
+ } else a = {};
17
+ Object.defineProperty(a, '__esModule', {value: true});
12
18
  Object.keys(n).forEach(function (k) {
13
19
  var d = Object.getOwnPropertyDescriptor(n, k);
14
20
  Object.defineProperty(a, k, d.get ? d : {
@@ -323,13 +329,13 @@
323
329
  const factory$1 = ({
324
330
  VERSION,
325
331
  MicrolinkError,
326
- isUrlHttp,
332
+ urlHttp,
327
333
  stringify,
328
334
  got,
329
335
  flatten
330
336
  }) => {
331
337
  const assertUrl = (url = '') => {
332
- if (!isUrlHttp(url)) {
338
+ if (!urlHttp(url)) {
333
339
  const message = `The \`url\` as \`${url}\` is not valid. Ensure it has protocol (http or https) and hostname.`;
334
340
  throw new MicrolinkError({
335
341
  status: 'fail',
@@ -427,414 +433,414 @@
427
433
  var ky$1 = {exports: {}};
428
434
 
429
435
  (function (module, exports) {
430
- (function (global, factory) {
431
- factory(exports) ;
432
- })(commonjsGlobal, (function (exports) {
433
- // eslint-lint-disable-next-line @typescript-eslint/naming-convention
434
- class HTTPError extends Error {
435
- constructor(response, request, options) {
436
- const code = (response.status || response.status === 0) ? response.status : '';
437
- const title = response.statusText || '';
438
- const status = `${code} ${title}`.trim();
439
- const reason = status ? `status code ${status}` : 'an unknown error';
440
- super(`Request failed with ${reason}`);
441
- this.name = 'HTTPError';
442
- this.response = response;
443
- this.request = request;
444
- this.options = options;
445
- }
446
- }
447
-
448
- class TimeoutError extends Error {
449
- constructor(request) {
450
- super('Request timed out');
451
- this.name = 'TimeoutError';
452
- this.request = request;
453
- }
454
- }
455
-
456
- // eslint-disable-next-line @typescript-eslint/ban-types
457
- const isObject = (value) => value !== null && typeof value === 'object';
458
-
459
- const validateAndMerge = (...sources) => {
460
- for (const source of sources) {
461
- if ((!isObject(source) || Array.isArray(source)) && typeof source !== 'undefined') {
462
- throw new TypeError('The `options` argument must be an object');
463
- }
464
- }
465
- return deepMerge({}, ...sources);
466
- };
467
- const mergeHeaders = (source1 = {}, source2 = {}) => {
468
- const result = new globalThis.Headers(source1);
469
- const isHeadersInstance = source2 instanceof globalThis.Headers;
470
- const source = new globalThis.Headers(source2);
471
- for (const [key, value] of source.entries()) {
472
- if ((isHeadersInstance && value === 'undefined') || value === undefined) {
473
- result.delete(key);
474
- }
475
- else {
476
- result.set(key, value);
477
- }
478
- }
479
- return result;
480
- };
481
- // TODO: Make this strongly-typed (no `any`).
482
- const deepMerge = (...sources) => {
483
- let returnValue = {};
484
- let headers = {};
485
- for (const source of sources) {
486
- if (Array.isArray(source)) {
487
- if (!Array.isArray(returnValue)) {
488
- returnValue = [];
489
- }
490
- returnValue = [...returnValue, ...source];
491
- }
492
- else if (isObject(source)) {
493
- for (let [key, value] of Object.entries(source)) {
494
- if (isObject(value) && key in returnValue) {
495
- value = deepMerge(returnValue[key], value);
496
- }
497
- returnValue = { ...returnValue, [key]: value };
498
- }
499
- if (isObject(source.headers)) {
500
- headers = mergeHeaders(headers, source.headers);
501
- returnValue.headers = headers;
502
- }
503
- }
504
- }
505
- return returnValue;
506
- };
507
-
508
- const supportsAbortController = typeof globalThis.AbortController === 'function';
509
- const supportsStreams = typeof globalThis.ReadableStream === 'function';
510
- const supportsFormData = typeof globalThis.FormData === 'function';
511
- const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];
512
- const responseTypes = {
513
- json: 'application/json',
514
- text: 'text/*',
515
- formData: 'multipart/form-data',
516
- arrayBuffer: '*/*',
517
- blob: '*/*',
518
- };
519
- // The maximum value of a 32bit int (see issue #117)
520
- const maxSafeTimeout = 2147483647;
521
- const stop = Symbol('stop');
522
-
523
- const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
524
- const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
525
- const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
526
- const retryAfterStatusCodes = [413, 429, 503];
527
- const defaultRetryOptions = {
528
- limit: 2,
529
- methods: retryMethods,
530
- statusCodes: retryStatusCodes,
531
- afterStatusCodes: retryAfterStatusCodes,
532
- maxRetryAfter: Number.POSITIVE_INFINITY,
533
- };
534
- const normalizeRetryOptions = (retry = {}) => {
535
- if (typeof retry === 'number') {
536
- return {
537
- ...defaultRetryOptions,
538
- limit: retry,
539
- };
540
- }
541
- if (retry.methods && !Array.isArray(retry.methods)) {
542
- throw new Error('retry.methods must be an array');
543
- }
544
- if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
545
- throw new Error('retry.statusCodes must be an array');
546
- }
547
- return {
548
- ...defaultRetryOptions,
549
- ...retry,
550
- afterStatusCodes: retryAfterStatusCodes,
551
- };
552
- };
553
-
554
- // `Promise.race()` workaround (#91)
555
- const timeout = async (request, abortController, options) => new Promise((resolve, reject) => {
556
- const timeoutId = setTimeout(() => {
557
- if (abortController) {
558
- abortController.abort();
559
- }
560
- reject(new TimeoutError(request));
561
- }, options.timeout);
562
- /* eslint-disable promise/prefer-await-to-then */
563
- void options
564
- .fetch(request)
565
- .then(resolve)
566
- .catch(reject)
567
- .then(() => {
568
- clearTimeout(timeoutId);
569
- });
570
- /* eslint-enable promise/prefer-await-to-then */
571
- });
572
- const delay = async (ms) => new Promise(resolve => {
573
- setTimeout(resolve, ms);
574
- });
575
-
576
- class Ky {
577
- // eslint-disable-next-line complexity
578
- constructor(input, options = {}) {
579
- var _a, _b;
580
- this._retryCount = 0;
581
- this._input = input;
582
- this._options = {
583
- // TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
584
- credentials: this._input.credentials || 'same-origin',
585
- ...options,
586
- headers: mergeHeaders(this._input.headers, options.headers),
587
- hooks: deepMerge({
588
- beforeRequest: [],
589
- beforeRetry: [],
590
- beforeError: [],
591
- afterResponse: [],
592
- }, options.hooks),
593
- method: normalizeRequestMethod((_a = options.method) !== null && _a !== void 0 ? _a : this._input.method),
594
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
595
- prefixUrl: String(options.prefixUrl || ''),
596
- retry: normalizeRetryOptions(options.retry),
597
- throwHttpErrors: options.throwHttpErrors !== false,
598
- timeout: typeof options.timeout === 'undefined' ? 10000 : options.timeout,
599
- fetch: (_b = options.fetch) !== null && _b !== void 0 ? _b : globalThis.fetch.bind(globalThis),
600
- };
601
- if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
602
- throw new TypeError('`input` must be a string, URL, or Request');
603
- }
604
- if (this._options.prefixUrl && typeof this._input === 'string') {
605
- if (this._input.startsWith('/')) {
606
- throw new Error('`input` must not begin with a slash when using `prefixUrl`');
607
- }
608
- if (!this._options.prefixUrl.endsWith('/')) {
609
- this._options.prefixUrl += '/';
610
- }
611
- this._input = this._options.prefixUrl + this._input;
612
- }
613
- if (supportsAbortController) {
614
- this.abortController = new globalThis.AbortController();
615
- if (this._options.signal) {
616
- this._options.signal.addEventListener('abort', () => {
617
- this.abortController.abort();
618
- });
619
- }
620
- this._options.signal = this.abortController.signal;
621
- }
622
- this.request = new globalThis.Request(this._input, this._options);
623
- if (this._options.searchParams) {
624
- // eslint-disable-next-line unicorn/prevent-abbreviations
625
- const textSearchParams = typeof this._options.searchParams === 'string'
626
- ? this._options.searchParams.replace(/^\?/, '')
627
- : new URLSearchParams(this._options.searchParams).toString();
628
- // eslint-disable-next-line unicorn/prevent-abbreviations
629
- const searchParams = '?' + textSearchParams;
630
- const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
631
- // To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one
632
- if (((supportsFormData && this._options.body instanceof globalThis.FormData)
633
- || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {
634
- this.request.headers.delete('content-type');
635
- }
636
- this.request = new globalThis.Request(new globalThis.Request(url, this.request), this._options);
637
- }
638
- if (this._options.json !== undefined) {
639
- this._options.body = JSON.stringify(this._options.json);
640
- this.request.headers.set('content-type', 'application/json');
641
- this.request = new globalThis.Request(this.request, { body: this._options.body });
642
- }
643
- }
644
- // eslint-disable-next-line @typescript-eslint/promise-function-async
645
- static create(input, options) {
646
- const ky = new Ky(input, options);
647
- const fn = async () => {
648
- if (ky._options.timeout > maxSafeTimeout) {
649
- throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
650
- }
651
- // Delay the fetch so that body method shortcuts can set the Accept header
652
- await Promise.resolve();
653
- let response = await ky._fetch();
654
- for (const hook of ky._options.hooks.afterResponse) {
655
- // eslint-disable-next-line no-await-in-loop
656
- const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));
657
- if (modifiedResponse instanceof globalThis.Response) {
658
- response = modifiedResponse;
659
- }
660
- }
661
- ky._decorateResponse(response);
662
- if (!response.ok && ky._options.throwHttpErrors) {
663
- let error = new HTTPError(response, ky.request, ky._options);
664
- for (const hook of ky._options.hooks.beforeError) {
665
- // eslint-disable-next-line no-await-in-loop
666
- error = await hook(error);
667
- }
668
- throw error;
669
- }
670
- // If `onDownloadProgress` is passed, it uses the stream API internally
671
- /* istanbul ignore next */
672
- if (ky._options.onDownloadProgress) {
673
- if (typeof ky._options.onDownloadProgress !== 'function') {
674
- throw new TypeError('The `onDownloadProgress` option must be a function');
675
- }
676
- if (!supportsStreams) {
677
- throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
678
- }
679
- return ky._stream(response.clone(), ky._options.onDownloadProgress);
680
- }
681
- return response;
682
- };
683
- const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());
684
- const result = (isRetriableMethod ? ky._retry(fn) : fn());
685
- for (const [type, mimeType] of Object.entries(responseTypes)) {
686
- result[type] = async () => {
687
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
688
- ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);
689
- const response = (await result).clone();
690
- if (type === 'json') {
691
- if (response.status === 204) {
692
- return '';
693
- }
694
- if (options.parseJson) {
695
- return options.parseJson(await response.text());
696
- }
697
- }
698
- return response[type]();
699
- };
700
- }
701
- return result;
702
- }
703
- _calculateRetryDelay(error) {
704
- this._retryCount++;
705
- if (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {
706
- if (error instanceof HTTPError) {
707
- if (!this._options.retry.statusCodes.includes(error.response.status)) {
708
- return 0;
709
- }
710
- const retryAfter = error.response.headers.get('Retry-After');
711
- if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
712
- let after = Number(retryAfter);
713
- if (Number.isNaN(after)) {
714
- after = Date.parse(retryAfter) - Date.now();
715
- }
716
- else {
717
- after *= 1000;
718
- }
719
- if (typeof this._options.retry.maxRetryAfter !== 'undefined' && after > this._options.retry.maxRetryAfter) {
720
- return 0;
721
- }
722
- return after;
723
- }
724
- if (error.response.status === 413) {
725
- return 0;
726
- }
727
- }
728
- const BACKOFF_FACTOR = 0.3;
729
- return BACKOFF_FACTOR * (2 ** (this._retryCount - 1)) * 1000;
730
- }
731
- return 0;
732
- }
733
- _decorateResponse(response) {
734
- if (this._options.parseJson) {
735
- response.json = async () => this._options.parseJson(await response.text());
736
- }
737
- return response;
738
- }
739
- async _retry(fn) {
740
- try {
741
- return await fn();
742
- // eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
743
- }
744
- catch (error) {
745
- const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
746
- if (ms !== 0 && this._retryCount > 0) {
747
- await delay(ms);
748
- for (const hook of this._options.hooks.beforeRetry) {
749
- // eslint-disable-next-line no-await-in-loop
750
- const hookResult = await hook({
751
- request: this.request,
752
- options: this._options,
753
- error: error,
754
- retryCount: this._retryCount,
755
- });
756
- // If `stop` is returned from the hook, the retry process is stopped
757
- if (hookResult === stop) {
758
- return;
759
- }
760
- }
761
- return this._retry(fn);
762
- }
763
- throw error;
764
- }
765
- }
766
- async _fetch() {
767
- for (const hook of this._options.hooks.beforeRequest) {
768
- // eslint-disable-next-line no-await-in-loop
769
- const result = await hook(this.request, this._options);
770
- if (result instanceof Request) {
771
- this.request = result;
772
- break;
773
- }
774
- if (result instanceof Response) {
775
- return result;
776
- }
777
- }
778
- if (this._options.timeout === false) {
779
- return this._options.fetch(this.request.clone());
780
- }
781
- return timeout(this.request.clone(), this.abortController, this._options);
782
- }
783
- /* istanbul ignore next */
784
- _stream(response, onDownloadProgress) {
785
- const totalBytes = Number(response.headers.get('content-length')) || 0;
786
- let transferredBytes = 0;
787
- return new globalThis.Response(new globalThis.ReadableStream({
788
- async start(controller) {
789
- const reader = response.body.getReader();
790
- if (onDownloadProgress) {
791
- onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
792
- }
793
- async function read() {
794
- const { done, value } = await reader.read();
795
- if (done) {
796
- controller.close();
797
- return;
798
- }
799
- if (onDownloadProgress) {
800
- transferredBytes += value.byteLength;
801
- const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
802
- onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
803
- }
804
- controller.enqueue(value);
805
- await read();
806
- }
807
- await read();
808
- },
809
- }));
810
- }
811
- }
812
-
813
- /*! MIT License © Sindre Sorhus */
814
- const createInstance = (defaults) => {
815
- // eslint-disable-next-line @typescript-eslint/promise-function-async
816
- const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
817
- for (const method of requestMethods) {
818
- // eslint-disable-next-line @typescript-eslint/promise-function-async
819
- ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
820
- }
821
- ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
822
- ky.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
823
- ky.stop = stop;
824
- return ky;
825
- };
826
- const ky = createInstance();
827
-
828
- exports.HTTPError = HTTPError;
829
- exports.TimeoutError = TimeoutError;
830
- exports["default"] = ky;
831
-
832
- Object.defineProperty(exports, '__esModule', { value: true });
833
-
834
- }));
835
- }(ky$1, ky$1.exports));
836
-
837
- const isUrlHttp = lightweight;
436
+ (function (global, factory) {
437
+ factory(exports) ;
438
+ })(commonjsGlobal, (function (exports) {
439
+ // eslint-lint-disable-next-line @typescript-eslint/naming-convention
440
+ class HTTPError extends Error {
441
+ constructor(response, request, options) {
442
+ const code = (response.status || response.status === 0) ? response.status : '';
443
+ const title = response.statusText || '';
444
+ const status = `${code} ${title}`.trim();
445
+ const reason = status ? `status code ${status}` : 'an unknown error';
446
+ super(`Request failed with ${reason}`);
447
+ this.name = 'HTTPError';
448
+ this.response = response;
449
+ this.request = request;
450
+ this.options = options;
451
+ }
452
+ }
453
+
454
+ class TimeoutError extends Error {
455
+ constructor(request) {
456
+ super('Request timed out');
457
+ this.name = 'TimeoutError';
458
+ this.request = request;
459
+ }
460
+ }
461
+
462
+ // eslint-disable-next-line @typescript-eslint/ban-types
463
+ const isObject = (value) => value !== null && typeof value === 'object';
464
+
465
+ const validateAndMerge = (...sources) => {
466
+ for (const source of sources) {
467
+ if ((!isObject(source) || Array.isArray(source)) && typeof source !== 'undefined') {
468
+ throw new TypeError('The `options` argument must be an object');
469
+ }
470
+ }
471
+ return deepMerge({}, ...sources);
472
+ };
473
+ const mergeHeaders = (source1 = {}, source2 = {}) => {
474
+ const result = new globalThis.Headers(source1);
475
+ const isHeadersInstance = source2 instanceof globalThis.Headers;
476
+ const source = new globalThis.Headers(source2);
477
+ for (const [key, value] of source.entries()) {
478
+ if ((isHeadersInstance && value === 'undefined') || value === undefined) {
479
+ result.delete(key);
480
+ }
481
+ else {
482
+ result.set(key, value);
483
+ }
484
+ }
485
+ return result;
486
+ };
487
+ // TODO: Make this strongly-typed (no `any`).
488
+ const deepMerge = (...sources) => {
489
+ let returnValue = {};
490
+ let headers = {};
491
+ for (const source of sources) {
492
+ if (Array.isArray(source)) {
493
+ if (!Array.isArray(returnValue)) {
494
+ returnValue = [];
495
+ }
496
+ returnValue = [...returnValue, ...source];
497
+ }
498
+ else if (isObject(source)) {
499
+ for (let [key, value] of Object.entries(source)) {
500
+ if (isObject(value) && key in returnValue) {
501
+ value = deepMerge(returnValue[key], value);
502
+ }
503
+ returnValue = { ...returnValue, [key]: value };
504
+ }
505
+ if (isObject(source.headers)) {
506
+ headers = mergeHeaders(headers, source.headers);
507
+ returnValue.headers = headers;
508
+ }
509
+ }
510
+ }
511
+ return returnValue;
512
+ };
513
+
514
+ const supportsAbortController = typeof globalThis.AbortController === 'function';
515
+ const supportsStreams = typeof globalThis.ReadableStream === 'function';
516
+ const supportsFormData = typeof globalThis.FormData === 'function';
517
+ const requestMethods = ['get', 'post', 'put', 'patch', 'head', 'delete'];
518
+ const responseTypes = {
519
+ json: 'application/json',
520
+ text: 'text/*',
521
+ formData: 'multipart/form-data',
522
+ arrayBuffer: '*/*',
523
+ blob: '*/*',
524
+ };
525
+ // The maximum value of a 32bit int (see issue #117)
526
+ const maxSafeTimeout = 2147483647;
527
+ const stop = Symbol('stop');
528
+
529
+ const normalizeRequestMethod = (input) => requestMethods.includes(input) ? input.toUpperCase() : input;
530
+ const retryMethods = ['get', 'put', 'head', 'delete', 'options', 'trace'];
531
+ const retryStatusCodes = [408, 413, 429, 500, 502, 503, 504];
532
+ const retryAfterStatusCodes = [413, 429, 503];
533
+ const defaultRetryOptions = {
534
+ limit: 2,
535
+ methods: retryMethods,
536
+ statusCodes: retryStatusCodes,
537
+ afterStatusCodes: retryAfterStatusCodes,
538
+ maxRetryAfter: Number.POSITIVE_INFINITY,
539
+ };
540
+ const normalizeRetryOptions = (retry = {}) => {
541
+ if (typeof retry === 'number') {
542
+ return {
543
+ ...defaultRetryOptions,
544
+ limit: retry,
545
+ };
546
+ }
547
+ if (retry.methods && !Array.isArray(retry.methods)) {
548
+ throw new Error('retry.methods must be an array');
549
+ }
550
+ if (retry.statusCodes && !Array.isArray(retry.statusCodes)) {
551
+ throw new Error('retry.statusCodes must be an array');
552
+ }
553
+ return {
554
+ ...defaultRetryOptions,
555
+ ...retry,
556
+ afterStatusCodes: retryAfterStatusCodes,
557
+ };
558
+ };
559
+
560
+ // `Promise.race()` workaround (#91)
561
+ const timeout = async (request, abortController, options) => new Promise((resolve, reject) => {
562
+ const timeoutId = setTimeout(() => {
563
+ if (abortController) {
564
+ abortController.abort();
565
+ }
566
+ reject(new TimeoutError(request));
567
+ }, options.timeout);
568
+ /* eslint-disable promise/prefer-await-to-then */
569
+ void options
570
+ .fetch(request)
571
+ .then(resolve)
572
+ .catch(reject)
573
+ .then(() => {
574
+ clearTimeout(timeoutId);
575
+ });
576
+ /* eslint-enable promise/prefer-await-to-then */
577
+ });
578
+ const delay = async (ms) => new Promise(resolve => {
579
+ setTimeout(resolve, ms);
580
+ });
581
+
582
+ class Ky {
583
+ // eslint-disable-next-line complexity
584
+ constructor(input, options = {}) {
585
+ var _a, _b;
586
+ this._retryCount = 0;
587
+ this._input = input;
588
+ this._options = {
589
+ // TODO: credentials can be removed when the spec change is implemented in all browsers. Context: https://www.chromestatus.com/feature/4539473312350208
590
+ credentials: this._input.credentials || 'same-origin',
591
+ ...options,
592
+ headers: mergeHeaders(this._input.headers, options.headers),
593
+ hooks: deepMerge({
594
+ beforeRequest: [],
595
+ beforeRetry: [],
596
+ beforeError: [],
597
+ afterResponse: [],
598
+ }, options.hooks),
599
+ method: normalizeRequestMethod((_a = options.method) !== null && _a !== void 0 ? _a : this._input.method),
600
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
601
+ prefixUrl: String(options.prefixUrl || ''),
602
+ retry: normalizeRetryOptions(options.retry),
603
+ throwHttpErrors: options.throwHttpErrors !== false,
604
+ timeout: typeof options.timeout === 'undefined' ? 10000 : options.timeout,
605
+ fetch: (_b = options.fetch) !== null && _b !== void 0 ? _b : globalThis.fetch.bind(globalThis),
606
+ };
607
+ if (typeof this._input !== 'string' && !(this._input instanceof URL || this._input instanceof globalThis.Request)) {
608
+ throw new TypeError('`input` must be a string, URL, or Request');
609
+ }
610
+ if (this._options.prefixUrl && typeof this._input === 'string') {
611
+ if (this._input.startsWith('/')) {
612
+ throw new Error('`input` must not begin with a slash when using `prefixUrl`');
613
+ }
614
+ if (!this._options.prefixUrl.endsWith('/')) {
615
+ this._options.prefixUrl += '/';
616
+ }
617
+ this._input = this._options.prefixUrl + this._input;
618
+ }
619
+ if (supportsAbortController) {
620
+ this.abortController = new globalThis.AbortController();
621
+ if (this._options.signal) {
622
+ this._options.signal.addEventListener('abort', () => {
623
+ this.abortController.abort();
624
+ });
625
+ }
626
+ this._options.signal = this.abortController.signal;
627
+ }
628
+ this.request = new globalThis.Request(this._input, this._options);
629
+ if (this._options.searchParams) {
630
+ // eslint-disable-next-line unicorn/prevent-abbreviations
631
+ const textSearchParams = typeof this._options.searchParams === 'string'
632
+ ? this._options.searchParams.replace(/^\?/, '')
633
+ : new URLSearchParams(this._options.searchParams).toString();
634
+ // eslint-disable-next-line unicorn/prevent-abbreviations
635
+ const searchParams = '?' + textSearchParams;
636
+ const url = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, searchParams);
637
+ // To provide correct form boundary, Content-Type header should be deleted each time when new Request instantiated from another one
638
+ if (((supportsFormData && this._options.body instanceof globalThis.FormData)
639
+ || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers['content-type'])) {
640
+ this.request.headers.delete('content-type');
641
+ }
642
+ this.request = new globalThis.Request(new globalThis.Request(url, this.request), this._options);
643
+ }
644
+ if (this._options.json !== undefined) {
645
+ this._options.body = JSON.stringify(this._options.json);
646
+ this.request.headers.set('content-type', 'application/json');
647
+ this.request = new globalThis.Request(this.request, { body: this._options.body });
648
+ }
649
+ }
650
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
651
+ static create(input, options) {
652
+ const ky = new Ky(input, options);
653
+ const fn = async () => {
654
+ if (ky._options.timeout > maxSafeTimeout) {
655
+ throw new RangeError(`The \`timeout\` option cannot be greater than ${maxSafeTimeout}`);
656
+ }
657
+ // Delay the fetch so that body method shortcuts can set the Accept header
658
+ await Promise.resolve();
659
+ let response = await ky._fetch();
660
+ for (const hook of ky._options.hooks.afterResponse) {
661
+ // eslint-disable-next-line no-await-in-loop
662
+ const modifiedResponse = await hook(ky.request, ky._options, ky._decorateResponse(response.clone()));
663
+ if (modifiedResponse instanceof globalThis.Response) {
664
+ response = modifiedResponse;
665
+ }
666
+ }
667
+ ky._decorateResponse(response);
668
+ if (!response.ok && ky._options.throwHttpErrors) {
669
+ let error = new HTTPError(response, ky.request, ky._options);
670
+ for (const hook of ky._options.hooks.beforeError) {
671
+ // eslint-disable-next-line no-await-in-loop
672
+ error = await hook(error);
673
+ }
674
+ throw error;
675
+ }
676
+ // If `onDownloadProgress` is passed, it uses the stream API internally
677
+ /* istanbul ignore next */
678
+ if (ky._options.onDownloadProgress) {
679
+ if (typeof ky._options.onDownloadProgress !== 'function') {
680
+ throw new TypeError('The `onDownloadProgress` option must be a function');
681
+ }
682
+ if (!supportsStreams) {
683
+ throw new Error('Streams are not supported in your environment. `ReadableStream` is missing.');
684
+ }
685
+ return ky._stream(response.clone(), ky._options.onDownloadProgress);
686
+ }
687
+ return response;
688
+ };
689
+ const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());
690
+ const result = (isRetriableMethod ? ky._retry(fn) : fn());
691
+ for (const [type, mimeType] of Object.entries(responseTypes)) {
692
+ result[type] = async () => {
693
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
694
+ ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);
695
+ const response = (await result).clone();
696
+ if (type === 'json') {
697
+ if (response.status === 204) {
698
+ return '';
699
+ }
700
+ if (options.parseJson) {
701
+ return options.parseJson(await response.text());
702
+ }
703
+ }
704
+ return response[type]();
705
+ };
706
+ }
707
+ return result;
708
+ }
709
+ _calculateRetryDelay(error) {
710
+ this._retryCount++;
711
+ if (this._retryCount < this._options.retry.limit && !(error instanceof TimeoutError)) {
712
+ if (error instanceof HTTPError) {
713
+ if (!this._options.retry.statusCodes.includes(error.response.status)) {
714
+ return 0;
715
+ }
716
+ const retryAfter = error.response.headers.get('Retry-After');
717
+ if (retryAfter && this._options.retry.afterStatusCodes.includes(error.response.status)) {
718
+ let after = Number(retryAfter);
719
+ if (Number.isNaN(after)) {
720
+ after = Date.parse(retryAfter) - Date.now();
721
+ }
722
+ else {
723
+ after *= 1000;
724
+ }
725
+ if (typeof this._options.retry.maxRetryAfter !== 'undefined' && after > this._options.retry.maxRetryAfter) {
726
+ return 0;
727
+ }
728
+ return after;
729
+ }
730
+ if (error.response.status === 413) {
731
+ return 0;
732
+ }
733
+ }
734
+ const BACKOFF_FACTOR = 0.3;
735
+ return BACKOFF_FACTOR * (2 ** (this._retryCount - 1)) * 1000;
736
+ }
737
+ return 0;
738
+ }
739
+ _decorateResponse(response) {
740
+ if (this._options.parseJson) {
741
+ response.json = async () => this._options.parseJson(await response.text());
742
+ }
743
+ return response;
744
+ }
745
+ async _retry(fn) {
746
+ try {
747
+ return await fn();
748
+ // eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
749
+ }
750
+ catch (error) {
751
+ const ms = Math.min(this._calculateRetryDelay(error), maxSafeTimeout);
752
+ if (ms !== 0 && this._retryCount > 0) {
753
+ await delay(ms);
754
+ for (const hook of this._options.hooks.beforeRetry) {
755
+ // eslint-disable-next-line no-await-in-loop
756
+ const hookResult = await hook({
757
+ request: this.request,
758
+ options: this._options,
759
+ error: error,
760
+ retryCount: this._retryCount,
761
+ });
762
+ // If `stop` is returned from the hook, the retry process is stopped
763
+ if (hookResult === stop) {
764
+ return;
765
+ }
766
+ }
767
+ return this._retry(fn);
768
+ }
769
+ throw error;
770
+ }
771
+ }
772
+ async _fetch() {
773
+ for (const hook of this._options.hooks.beforeRequest) {
774
+ // eslint-disable-next-line no-await-in-loop
775
+ const result = await hook(this.request, this._options);
776
+ if (result instanceof Request) {
777
+ this.request = result;
778
+ break;
779
+ }
780
+ if (result instanceof Response) {
781
+ return result;
782
+ }
783
+ }
784
+ if (this._options.timeout === false) {
785
+ return this._options.fetch(this.request.clone());
786
+ }
787
+ return timeout(this.request.clone(), this.abortController, this._options);
788
+ }
789
+ /* istanbul ignore next */
790
+ _stream(response, onDownloadProgress) {
791
+ const totalBytes = Number(response.headers.get('content-length')) || 0;
792
+ let transferredBytes = 0;
793
+ return new globalThis.Response(new globalThis.ReadableStream({
794
+ async start(controller) {
795
+ const reader = response.body.getReader();
796
+ if (onDownloadProgress) {
797
+ onDownloadProgress({ percent: 0, transferredBytes: 0, totalBytes }, new Uint8Array());
798
+ }
799
+ async function read() {
800
+ const { done, value } = await reader.read();
801
+ if (done) {
802
+ controller.close();
803
+ return;
804
+ }
805
+ if (onDownloadProgress) {
806
+ transferredBytes += value.byteLength;
807
+ const percent = totalBytes === 0 ? 0 : transferredBytes / totalBytes;
808
+ onDownloadProgress({ percent, transferredBytes, totalBytes }, value);
809
+ }
810
+ controller.enqueue(value);
811
+ await read();
812
+ }
813
+ await read();
814
+ },
815
+ }));
816
+ }
817
+ }
818
+
819
+ /*! MIT License © Sindre Sorhus */
820
+ const createInstance = (defaults) => {
821
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
822
+ const ky = (input, options) => Ky.create(input, validateAndMerge(defaults, options));
823
+ for (const method of requestMethods) {
824
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
825
+ ky[method] = (input, options) => Ky.create(input, validateAndMerge(defaults, options, { method }));
826
+ }
827
+ ky.create = (newDefaults) => createInstance(validateAndMerge(newDefaults));
828
+ ky.extend = (newDefaults) => createInstance(validateAndMerge(defaults, newDefaults));
829
+ ky.stop = stop;
830
+ return ky;
831
+ };
832
+ const ky = createInstance();
833
+
834
+ exports.HTTPError = HTTPError;
835
+ exports.TimeoutError = TimeoutError;
836
+ exports["default"] = ky;
837
+
838
+ Object.defineProperty(exports, '__esModule', { value: true });
839
+
840
+ }));
841
+ } (ky$1, ky$1.exports));
842
+
843
+ const urlHttp = lightweight;
838
844
  const { flattie: flatten } = dist;
839
845
  const { encode: stringify } = require$$2;
840
846
  const whoops = lib.exports;
@@ -873,11 +879,11 @@
873
879
 
874
880
  var browser = factory({
875
881
  MicrolinkError,
876
- isUrlHttp,
882
+ urlHttp,
877
883
  stringify,
878
884
  got,
879
885
  flatten,
880
- VERSION: '0.10.19'
886
+ VERSION: '0.10.20'
881
887
  });
882
888
 
883
889
  return browser;