@builderbot/provider-evolution-api 1.3.10 → 1.3.12-alpha.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/dist/index.cjs CHANGED
@@ -9,6 +9,7 @@ var require$$4 = require('https');
9
9
  var require$$0$1 = require('url');
10
10
  var fs$1 = require('fs');
11
11
  var require$$8 = require('crypto');
12
+ var http2 = require('http2');
12
13
  var require$$4$1 = require('assert');
13
14
  var require$$1$2 = require('tty');
14
15
  var require$$0$2 = require('os');
@@ -66,6 +67,13 @@ var json = function (opts={}) {
66
67
  };
67
68
  };
68
69
 
70
+ /**
71
+ * Create a bound version of a function with a specified `this` context
72
+ *
73
+ * @param {Function} fn - The function to bind
74
+ * @param {*} thisArg - The value to be passed as the `this` parameter
75
+ * @returns {Function} A new function that will call the original function with the specified `this` context
76
+ */
69
77
  function bind$2(fn, thisArg) {
70
78
  return function wrap() {
71
79
  return fn.apply(thisArg, arguments);
@@ -117,7 +125,7 @@ const isUndefined = typeOfTest('undefined');
117
125
  */
118
126
  function isBuffer$1(val) {
119
127
  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
120
- && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
128
+ && isFunction$2(val.constructor.isBuffer) && val.constructor.isBuffer(val);
121
129
  }
122
130
 
123
131
  /**
@@ -162,7 +170,7 @@ const isString$1 = typeOfTest('string');
162
170
  * @param {*} val The value to test
163
171
  * @returns {boolean} True if value is a Function, otherwise false
164
172
  */
165
- const isFunction$1 = typeOfTest('function');
173
+ const isFunction$2 = typeOfTest('function');
166
174
 
167
175
  /**
168
176
  * Determine if a value is a Number
@@ -218,7 +226,7 @@ const isEmptyObject = (val) => {
218
226
  if (!isObject(val) || isBuffer$1(val)) {
219
227
  return false;
220
228
  }
221
-
229
+
222
230
  try {
223
231
  return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
224
232
  } catch (e) {
@@ -270,7 +278,7 @@ const isFileList = kindOfTest('FileList');
270
278
  *
271
279
  * @returns {boolean} True if value is a Stream, otherwise false
272
280
  */
273
- const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
281
+ const isStream = (val) => isObject(val) && isFunction$2(val.pipe);
274
282
 
275
283
  /**
276
284
  * Determine if a value is a FormData
@@ -283,10 +291,10 @@ const isFormData = (thing) => {
283
291
  let kind;
284
292
  return thing && (
285
293
  (typeof FormData === 'function' && thing instanceof FormData) || (
286
- isFunction$1(thing.append) && (
294
+ isFunction$2(thing.append) && (
287
295
  (kind = kindOf(thing)) === 'formdata' ||
288
296
  // detect form-data instance
289
- (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
297
+ (kind === 'object' && isFunction$2(thing.toString) && thing.toString() === '[object FormData]')
290
298
  )
291
299
  )
292
300
  )
@@ -411,7 +419,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
411
419
  * @returns {Object} Result of all merge properties
412
420
  */
413
421
  function merge(/* obj1, obj2, obj3, ... */) {
414
- const {caseless} = isContextDefined(this) && this || {};
422
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
415
423
  const result = {};
416
424
  const assignValue = (val, key) => {
417
425
  const targetKey = caseless && findKey(result, key) || key;
@@ -421,7 +429,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
421
429
  result[targetKey] = merge({}, val);
422
430
  } else if (isArray(val)) {
423
431
  result[targetKey] = val.slice();
424
- } else {
432
+ } else if (!skipUndefined || !isUndefined(val)) {
425
433
  result[targetKey] = val;
426
434
  }
427
435
  };
@@ -444,7 +452,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
444
452
  */
445
453
  const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
446
454
  forEach(b, (val, key) => {
447
- if (thisArg && isFunction$1(val)) {
455
+ if (thisArg && isFunction$2(val)) {
448
456
  a[key] = bind$2(val, thisArg);
449
457
  } else {
450
458
  a[key] = val;
@@ -660,13 +668,13 @@ const reduceDescriptors = (obj, reducer) => {
660
668
  const freezeMethods = (obj) => {
661
669
  reduceDescriptors(obj, (descriptor, name) => {
662
670
  // skip restricted props in strict mode
663
- if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
671
+ if (isFunction$2(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
664
672
  return false;
665
673
  }
666
674
 
667
675
  const value = obj[name];
668
676
 
669
- if (!isFunction$1(value)) return;
677
+ if (!isFunction$2(value)) return;
670
678
 
671
679
  descriptor.enumerable = false;
672
680
 
@@ -703,6 +711,8 @@ const toFiniteNumber = (value, defaultValue) => {
703
711
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
704
712
  };
705
713
 
714
+
715
+
706
716
  /**
707
717
  * If the thing is a FormData object, return true, otherwise return false.
708
718
  *
@@ -711,7 +721,7 @@ const toFiniteNumber = (value, defaultValue) => {
711
721
  * @returns {boolean}
712
722
  */
713
723
  function isSpecCompliantForm(thing) {
714
- return !!(thing && isFunction$1(thing.append) && thing[toStringTag$1] === 'FormData' && thing[iterator]);
724
+ return !!(thing && isFunction$2(thing.append) && thing[toStringTag$1] === 'FormData' && thing[iterator]);
715
725
  }
716
726
 
717
727
  const toJSONObject = (obj) => {
@@ -753,7 +763,7 @@ const toJSONObject = (obj) => {
753
763
  const isAsyncFn = kindOfTest('AsyncFunction');
754
764
 
755
765
  const isThenable = (thing) =>
756
- thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
766
+ thing && (isObject(thing) || isFunction$2(thing)) && isFunction$2(thing.then) && isFunction$2(thing.catch);
757
767
 
758
768
  // original code
759
769
  // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
@@ -777,7 +787,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
777
787
  })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
778
788
  })(
779
789
  typeof setImmediate === 'function',
780
- isFunction$1(_global.postMessage)
790
+ isFunction$2(_global.postMessage)
781
791
  );
782
792
 
783
793
  const asap = typeof queueMicrotask !== 'undefined' ?
@@ -786,7 +796,7 @@ const asap = typeof queueMicrotask !== 'undefined' ?
786
796
  // *********************
787
797
 
788
798
 
789
- const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
799
+ const isIterable = (thing) => thing != null && isFunction$2(thing[iterator]);
790
800
 
791
801
 
792
802
  var utils$1 = {
@@ -810,7 +820,7 @@ var utils$1 = {
810
820
  isFile,
811
821
  isBlob,
812
822
  isRegExp,
813
- isFunction: isFunction$1,
823
+ isFunction: isFunction$2,
814
824
  isStream,
815
825
  isURLSearchParams,
816
826
  isTypedArray,
@@ -936,11 +946,18 @@ AxiosError$1.from = (error, code, config, request, response, customProps) => {
936
946
  return prop !== 'isAxiosError';
937
947
  });
938
948
 
939
- AxiosError$1.call(axiosError, error.message, code, config, request, response);
949
+ const msg = error && error.message ? error.message : 'Error';
940
950
 
941
- axiosError.cause = error;
951
+ // Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
952
+ const errCode = code == null && error ? error.code : code;
953
+ AxiosError$1.call(axiosError, msg, errCode, config, request, response);
954
+
955
+ // Chain the original error on the standard field; non-enumerable to avoid JSON noise
956
+ if (error && axiosError.cause == null) {
957
+ Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
958
+ }
942
959
 
943
- axiosError.name = error.name;
960
+ axiosError.name = (error && error.name) || 'Error';
944
961
 
945
962
  customProps && Object.assign(axiosError, customProps);
946
963
 
@@ -13900,7 +13917,7 @@ FormData$1.prototype.submit = function (params, cb) {
13900
13917
  request.removeListener('error', callback);
13901
13918
  request.removeListener('response', onResponse);
13902
13919
 
13903
- return cb.call(this, error, responce); // eslint-disable-line no-invalid-this
13920
+ return cb.call(this, error, responce);
13904
13921
  };
13905
13922
 
13906
13923
  onResponse = callback.bind(this, null);
@@ -13924,7 +13941,7 @@ FormData$1.prototype._error = function (err) {
13924
13941
  FormData$1.prototype.toString = function () {
13925
13942
  return '[object FormData]';
13926
13943
  };
13927
- setToStringTag(FormData$1, 'FormData');
13944
+ setToStringTag(FormData$1.prototype, 'FormData');
13928
13945
 
13929
13946
  // Public API
13930
13947
  var form_data = FormData$1;
@@ -14212,9 +14229,7 @@ function encode(val) {
14212
14229
  replace(/%3A/gi, ':').
14213
14230
  replace(/%24/g, '$').
14214
14231
  replace(/%2C/gi, ',').
14215
- replace(/%20/g, '+').
14216
- replace(/%5B/gi, '[').
14217
- replace(/%5D/gi, ']');
14232
+ replace(/%20/g, '+');
14218
14233
  }
14219
14234
 
14220
14235
  /**
@@ -14292,7 +14307,7 @@ class InterceptorManager {
14292
14307
  *
14293
14308
  * @param {Number} id The ID that was returned by `use`
14294
14309
  *
14295
- * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
14310
+ * @returns {void}
14296
14311
  */
14297
14312
  eject(id) {
14298
14313
  if (this.handlers[id]) {
@@ -14638,7 +14653,7 @@ const defaults = {
14638
14653
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
14639
14654
 
14640
14655
  try {
14641
- return JSON.parse(data);
14656
+ return JSON.parse(data, this.parseReviver);
14642
14657
  } catch (e) {
14643
14658
  if (strictJSONParsing) {
14644
14659
  if (e.name === 'SyntaxError') {
@@ -16510,7 +16525,7 @@ var debug = debug_1;
16510
16525
  (function detectUnsupportedEnvironment() {
16511
16526
  var looksLikeNode = typeof process !== "undefined";
16512
16527
  var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
16513
- var looksLikeV8 = isFunction(Error.captureStackTrace);
16528
+ var looksLikeV8 = isFunction$1(Error.captureStackTrace);
16514
16529
  if (!looksLikeNode && (looksLikeBrowser || !looksLikeV8)) {
16515
16530
  console.warn("The follow-redirects package should be excluded from browser builds.");
16516
16531
  }
@@ -16634,7 +16649,7 @@ RedirectableRequest.prototype.write = function (data, encoding, callback) {
16634
16649
  if (!isString(data) && !isBuffer(data)) {
16635
16650
  throw new TypeError("data should be a string, Buffer or Uint8Array");
16636
16651
  }
16637
- if (isFunction(encoding)) {
16652
+ if (isFunction$1(encoding)) {
16638
16653
  callback = encoding;
16639
16654
  encoding = null;
16640
16655
  }
@@ -16663,11 +16678,11 @@ RedirectableRequest.prototype.write = function (data, encoding, callback) {
16663
16678
  // Ends the current native request
16664
16679
  RedirectableRequest.prototype.end = function (data, encoding, callback) {
16665
16680
  // Shift parameters if necessary
16666
- if (isFunction(data)) {
16681
+ if (isFunction$1(data)) {
16667
16682
  callback = data;
16668
16683
  data = encoding = null;
16669
16684
  }
16670
- else if (isFunction(encoding)) {
16685
+ else if (isFunction$1(encoding)) {
16671
16686
  callback = encoding;
16672
16687
  encoding = null;
16673
16688
  }
@@ -16975,7 +16990,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
16975
16990
  }
16976
16991
 
16977
16992
  // Evaluate the beforeRedirect callback
16978
- if (isFunction(beforeRedirect)) {
16993
+ if (isFunction$1(beforeRedirect)) {
16979
16994
  var responseDetails = {
16980
16995
  headers: response.headers,
16981
16996
  statusCode: statusCode,
@@ -17022,7 +17037,7 @@ function wrap(protocols) {
17022
17037
  options = validateUrl(input);
17023
17038
  input = { protocol: protocol };
17024
17039
  }
17025
- if (isFunction(options)) {
17040
+ if (isFunction$1(options)) {
17026
17041
  callback = options;
17027
17042
  options = null;
17028
17043
  }
@@ -17127,7 +17142,7 @@ function createErrorType(code, message, baseClass) {
17127
17142
  // Create constructor
17128
17143
  function CustomError(properties) {
17129
17144
  // istanbul ignore else
17130
- if (isFunction(Error.captureStackTrace)) {
17145
+ if (isFunction$1(Error.captureStackTrace)) {
17131
17146
  Error.captureStackTrace(this, this.constructor);
17132
17147
  }
17133
17148
  Object.assign(this, properties || {});
@@ -17168,7 +17183,7 @@ function isString(value) {
17168
17183
  return typeof value === "string" || value instanceof String;
17169
17184
  }
17170
17185
 
17171
- function isFunction(value) {
17186
+ function isFunction$1(value) {
17172
17187
  return typeof value === "function";
17173
17188
  }
17174
17189
 
@@ -17187,7 +17202,7 @@ followRedirects$1.exports.wrap = wrap;
17187
17202
  var followRedirectsExports = followRedirects$1.exports;
17188
17203
  var followRedirects = /*@__PURE__*/getDefaultExportFromCjs(followRedirectsExports);
17189
17204
 
17190
- const VERSION$1 = "1.11.0";
17205
+ const VERSION$1 = "1.13.2";
17191
17206
 
17192
17207
  function parseProtocol(url) {
17193
17208
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
@@ -17670,6 +17685,80 @@ const progressEventDecorator = (total, throttled) => {
17670
17685
 
17671
17686
  const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
17672
17687
 
17688
+ /**
17689
+ * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
17690
+ * - For base64: compute exact decoded size using length and padding;
17691
+ * handle %XX at the character-count level (no string allocation).
17692
+ * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
17693
+ *
17694
+ * @param {string} url
17695
+ * @returns {number}
17696
+ */
17697
+ function estimateDataURLDecodedBytes(url) {
17698
+ if (!url || typeof url !== 'string') return 0;
17699
+ if (!url.startsWith('data:')) return 0;
17700
+
17701
+ const comma = url.indexOf(',');
17702
+ if (comma < 0) return 0;
17703
+
17704
+ const meta = url.slice(5, comma);
17705
+ const body = url.slice(comma + 1);
17706
+ const isBase64 = /;base64/i.test(meta);
17707
+
17708
+ if (isBase64) {
17709
+ let effectiveLen = body.length;
17710
+ const len = body.length; // cache length
17711
+
17712
+ for (let i = 0; i < len; i++) {
17713
+ if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
17714
+ const a = body.charCodeAt(i + 1);
17715
+ const b = body.charCodeAt(i + 2);
17716
+ const isHex =
17717
+ ((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
17718
+ ((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
17719
+
17720
+ if (isHex) {
17721
+ effectiveLen -= 2;
17722
+ i += 2;
17723
+ }
17724
+ }
17725
+ }
17726
+
17727
+ let pad = 0;
17728
+ let idx = len - 1;
17729
+
17730
+ const tailIsPct3D = (j) =>
17731
+ j >= 2 &&
17732
+ body.charCodeAt(j - 2) === 37 && // '%'
17733
+ body.charCodeAt(j - 1) === 51 && // '3'
17734
+ (body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
17735
+
17736
+ if (idx >= 0) {
17737
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
17738
+ pad++;
17739
+ idx--;
17740
+ } else if (tailIsPct3D(idx)) {
17741
+ pad++;
17742
+ idx -= 3;
17743
+ }
17744
+ }
17745
+
17746
+ if (pad === 1 && idx >= 0) {
17747
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
17748
+ pad++;
17749
+ } else if (tailIsPct3D(idx)) {
17750
+ pad++;
17751
+ }
17752
+ }
17753
+
17754
+ const groups = Math.floor(effectiveLen / 4);
17755
+ const bytes = groups * 3 - (pad || 0);
17756
+ return bytes > 0 ? bytes : 0;
17757
+ }
17758
+
17759
+ return Buffer.byteLength(body, 'utf8');
17760
+ }
17761
+
17673
17762
  const zlibOptions = {
17674
17763
  flush: zlib.constants.Z_SYNC_FLUSH,
17675
17764
  finishFlush: zlib.constants.Z_SYNC_FLUSH
@@ -17690,6 +17779,7 @@ const supportedProtocols = platform.protocols.map(protocol => {
17690
17779
  return protocol + ':';
17691
17780
  });
17692
17781
 
17782
+
17693
17783
  const flushOnFinish = (stream, [throttled, flush]) => {
17694
17784
  stream
17695
17785
  .on('end', flush)
@@ -17698,6 +17788,102 @@ const flushOnFinish = (stream, [throttled, flush]) => {
17698
17788
  return throttled;
17699
17789
  };
17700
17790
 
17791
+ class Http2Sessions {
17792
+ constructor() {
17793
+ this.sessions = Object.create(null);
17794
+ }
17795
+
17796
+ getSession(authority, options) {
17797
+ options = Object.assign({
17798
+ sessionTimeout: 1000
17799
+ }, options);
17800
+
17801
+ let authoritySessions = this.sessions[authority];
17802
+
17803
+ if (authoritySessions) {
17804
+ let len = authoritySessions.length;
17805
+
17806
+ for (let i = 0; i < len; i++) {
17807
+ const [sessionHandle, sessionOptions] = authoritySessions[i];
17808
+ if (!sessionHandle.destroyed && !sessionHandle.closed && require$$1.isDeepStrictEqual(sessionOptions, options)) {
17809
+ return sessionHandle;
17810
+ }
17811
+ }
17812
+ }
17813
+
17814
+ const session = http2.connect(authority, options);
17815
+
17816
+ let removed;
17817
+
17818
+ const removeSession = () => {
17819
+ if (removed) {
17820
+ return;
17821
+ }
17822
+
17823
+ removed = true;
17824
+
17825
+ let entries = authoritySessions, len = entries.length, i = len;
17826
+
17827
+ while (i--) {
17828
+ if (entries[i][0] === session) {
17829
+ if (len === 1) {
17830
+ delete this.sessions[authority];
17831
+ } else {
17832
+ entries.splice(i, 1);
17833
+ }
17834
+ return;
17835
+ }
17836
+ }
17837
+ };
17838
+
17839
+ const originalRequestFn = session.request;
17840
+
17841
+ const {sessionTimeout} = options;
17842
+
17843
+ if(sessionTimeout != null) {
17844
+
17845
+ let timer;
17846
+ let streamsCount = 0;
17847
+
17848
+ session.request = function () {
17849
+ const stream = originalRequestFn.apply(this, arguments);
17850
+
17851
+ streamsCount++;
17852
+
17853
+ if (timer) {
17854
+ clearTimeout(timer);
17855
+ timer = null;
17856
+ }
17857
+
17858
+ stream.once('close', () => {
17859
+ if (!--streamsCount) {
17860
+ timer = setTimeout(() => {
17861
+ timer = null;
17862
+ removeSession();
17863
+ }, sessionTimeout);
17864
+ }
17865
+ });
17866
+
17867
+ return stream;
17868
+ };
17869
+ }
17870
+
17871
+ session.once('close', removeSession);
17872
+
17873
+ let entry = [
17874
+ session,
17875
+ options
17876
+ ];
17877
+
17878
+ authoritySessions ? authoritySessions.push(entry) : authoritySessions = this.sessions[authority] = [entry];
17879
+
17880
+ return session;
17881
+ }
17882
+ }
17883
+
17884
+ const http2Sessions = new Http2Sessions();
17885
+
17886
+
17701
17887
  /**
17702
17888
  * If the proxy or config beforeRedirects functions are defined, call them with the options
17703
17889
  * object.
@@ -17809,16 +17995,75 @@ const resolveFamily = ({address, family}) => {
17809
17995
 
17810
17996
  const buildAddressEntry = (address, family) => resolveFamily(utils$1.isObject(address) ? address : {address, family});
17811
17997
 
17998
+ const http2Transport = {
17999
+ request(options, cb) {
18000
+ const authority = options.protocol + '//' + options.hostname + ':' + (options.port || 80);
18001
+
18002
+ const {http2Options, headers} = options;
18003
+
18004
+ const session = http2Sessions.getSession(authority, http2Options);
18005
+
18006
+ const {
18007
+ HTTP2_HEADER_SCHEME,
18008
+ HTTP2_HEADER_METHOD,
18009
+ HTTP2_HEADER_PATH,
18010
+ HTTP2_HEADER_STATUS
18011
+ } = http2.constants;
18012
+
18013
+ const http2Headers = {
18014
+ [HTTP2_HEADER_SCHEME]: options.protocol.replace(':', ''),
18015
+ [HTTP2_HEADER_METHOD]: options.method,
18016
+ [HTTP2_HEADER_PATH]: options.path,
18017
+ };
18018
+
18019
+ utils$1.forEach(headers, (header, name) => {
18020
+ name.charAt(0) !== ':' && (http2Headers[name] = header);
18021
+ });
18022
+
18023
+ const req = session.request(http2Headers);
18024
+
18025
+ req.once('response', (responseHeaders) => {
18026
+ const response = req; //duplex
18027
+
18028
+ responseHeaders = Object.assign({}, responseHeaders);
18029
+
18030
+ const status = responseHeaders[HTTP2_HEADER_STATUS];
18031
+
18032
+ delete responseHeaders[HTTP2_HEADER_STATUS];
18033
+
18034
+ response.headers = responseHeaders;
18035
+
18036
+ response.statusCode = +status;
18037
+
18038
+ cb(response);
18039
+ });
18040
+
18041
+ return req;
18042
+ }
18043
+ };
18044
+
17812
18045
  /*eslint consistent-return:0*/
17813
18046
  var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17814
18047
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
17815
- let {data, lookup, family} = config;
18048
+ let {data, lookup, family, httpVersion = 1, http2Options} = config;
17816
18049
  const {responseType, responseEncoding} = config;
17817
18050
  const method = config.method.toUpperCase();
17818
18051
  let isDone;
17819
18052
  let rejected = false;
17820
18053
  let req;
17821
18054
 
18055
+ httpVersion = +httpVersion;
18056
+
18057
+ if (Number.isNaN(httpVersion)) {
18058
+ throw TypeError(`Invalid protocol version: '${config.httpVersion}' is not a number`);
18059
+ }
18060
+
18061
+ if (httpVersion !== 1 && httpVersion !== 2) {
18062
+ throw TypeError(`Unsupported protocol version '${httpVersion}'`);
18063
+ }
18064
+
18065
+ const isHttp2 = httpVersion === 2;
18066
+
17822
18067
  if (lookup) {
17823
18068
  const _lookup = callbackify(lookup, (value) => utils$1.isArray(value) ? value : [value]);
17824
18069
  // hotfix to support opt.all option which is required for node 20.x
@@ -17835,8 +18080,17 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17835
18080
  };
17836
18081
  }
17837
18082
 
17838
- // temporary internal emitter until the AxiosRequest class will be implemented
17839
- const emitter = new require$$0$3.EventEmitter();
18083
+ const abortEmitter = new require$$0$3.EventEmitter();
18084
+
18085
+ function abort(reason) {
18086
+ try {
18087
+ abortEmitter.emit('abort', !reason || reason.type ? new CanceledError$1(null, config, req) : reason);
18088
+ } catch(err) {
18089
+ console.warn('emit error', err);
18090
+ }
18091
+ }
18092
+
18093
+ abortEmitter.once('abort', reject);
17840
18094
 
17841
18095
  const onFinished = () => {
17842
18096
  if (config.cancelToken) {
@@ -17847,29 +18101,40 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17847
18101
  config.signal.removeEventListener('abort', abort);
17848
18102
  }
17849
18103
 
17850
- emitter.removeAllListeners();
18104
+ abortEmitter.removeAllListeners();
17851
18105
  };
17852
18106
 
17853
- onDone((value, isRejected) => {
18107
+ if (config.cancelToken || config.signal) {
18108
+ config.cancelToken && config.cancelToken.subscribe(abort);
18109
+ if (config.signal) {
18110
+ config.signal.aborted ? abort() : config.signal.addEventListener('abort', abort);
18111
+ }
18112
+ }
18113
+
18114
+ onDone((response, isRejected) => {
17854
18115
  isDone = true;
18116
+
17855
18117
  if (isRejected) {
17856
18118
  rejected = true;
17857
18119
  onFinished();
18120
+ return;
18121
+ }
18122
+
18123
+ const {data} = response;
18124
+
18125
+ if (data instanceof stream.Readable || data instanceof stream.Duplex) {
18126
+ const offListeners = stream.finished(data, () => {
18127
+ offListeners();
18128
+ onFinished();
18129
+ });
18130
+ } else {
18131
+ onFinished();
17858
18132
  }
17859
18133
  });
17860
18134
 
17861
- function abort(reason) {
17862
- emitter.emit('abort', !reason || reason.type ? new CanceledError$1(null, config, req) : reason);
17863
- }
17864
18135
 
17865
- emitter.once('abort', reject);
17866
18136
 
17867
- if (config.cancelToken || config.signal) {
17868
- config.cancelToken && config.cancelToken.subscribe(abort);
17869
- if (config.signal) {
17870
- config.signal.aborted ? abort() : config.signal.addEventListener('abort', abort);
17871
- }
17872
- }
18137
+
17873
18138
 
17874
18139
  // Parse url
17875
18140
  const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
@@ -17877,6 +18142,21 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
17877
18142
  const protocol = parsed.protocol || supportedProtocols[0];
17878
18143
 
17879
18144
  if (protocol === 'data:') {
18145
+ // Apply the same semantics as HTTP: only enforce if a finite, non-negative cap is set.
18146
+ if (config.maxContentLength > -1) {
18147
+ // Use the exact string passed to fromDataURI (config.url); fall back to fullPath if needed.
18148
+ const dataUrl = String(config.url || fullPath || '');
18149
+ const estimated = estimateDataURLDecodedBytes(dataUrl);
18150
+
18151
+ if (estimated > config.maxContentLength) {
18152
+ return reject(new AxiosError$1(
18153
+ 'maxContentLength size of ' + config.maxContentLength + ' exceeded',
18154
+ AxiosError$1.ERR_BAD_RESPONSE,
18155
+ config
18156
+ ));
18157
+ }
18158
+ }
18159
+
17880
18160
  let convertedData;
17881
18161
 
17882
18162
  if (method !== 'GET') {
@@ -18060,7 +18340,8 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18060
18340
  protocol,
18061
18341
  family,
18062
18342
  beforeRedirect: dispatchBeforeRedirect,
18063
- beforeRedirects: {}
18343
+ beforeRedirects: {},
18344
+ http2Options
18064
18345
  };
18065
18346
 
18066
18347
  // cacheable-lookup integration hotfix
@@ -18077,18 +18358,23 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18077
18358
  let transport;
18078
18359
  const isHttpsRequest = isHttps.test(options.protocol);
18079
18360
  options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
18080
- if (config.transport) {
18081
- transport = config.transport;
18082
- } else if (config.maxRedirects === 0) {
18083
- transport = isHttpsRequest ? require$$4 : require$$3;
18361
+
18362
+ if (isHttp2) {
18363
+ transport = http2Transport;
18084
18364
  } else {
18085
- if (config.maxRedirects) {
18086
- options.maxRedirects = config.maxRedirects;
18087
- }
18088
- if (config.beforeRedirect) {
18089
- options.beforeRedirects.config = config.beforeRedirect;
18365
+ if (config.transport) {
18366
+ transport = config.transport;
18367
+ } else if (config.maxRedirects === 0) {
18368
+ transport = isHttpsRequest ? require$$4 : require$$3;
18369
+ } else {
18370
+ if (config.maxRedirects) {
18371
+ options.maxRedirects = config.maxRedirects;
18372
+ }
18373
+ if (config.beforeRedirect) {
18374
+ options.beforeRedirects.config = config.beforeRedirect;
18375
+ }
18376
+ transport = isHttpsRequest ? httpsFollow : httpFollow;
18090
18377
  }
18091
- transport = isHttpsRequest ? httpsFollow : httpFollow;
18092
18378
  }
18093
18379
 
18094
18380
  if (config.maxBodyLength > -1) {
@@ -18108,7 +18394,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18108
18394
 
18109
18395
  const streams = [res];
18110
18396
 
18111
- const responseLength = +res.headers['content-length'];
18397
+ const responseLength = utils$1.toFiniteNumber(res.headers['content-length']);
18112
18398
 
18113
18399
  if (onDownloadProgress || maxDownloadRate) {
18114
18400
  const transformStream = new AxiosTransformStream({
@@ -18171,10 +18457,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18171
18457
 
18172
18458
  responseStream = streams.length > 1 ? stream.pipeline(streams, utils$1.noop) : streams[0];
18173
18459
 
18174
- const offListeners = stream.finished(responseStream, () => {
18175
- offListeners();
18176
- onFinished();
18177
- });
18460
+
18178
18461
 
18179
18462
  const response = {
18180
18463
  status: res.statusCode,
@@ -18200,7 +18483,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18200
18483
  // stream.destroy() emit aborted event before calling reject() on Node.js v16
18201
18484
  rejected = true;
18202
18485
  responseStream.destroy();
18203
- reject(new AxiosError$1('maxContentLength size of ' + config.maxContentLength + ' exceeded',
18486
+ abort(new AxiosError$1('maxContentLength size of ' + config.maxContentLength + ' exceeded',
18204
18487
  AxiosError$1.ERR_BAD_RESPONSE, config, lastRequest));
18205
18488
  }
18206
18489
  });
@@ -18242,7 +18525,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18242
18525
  });
18243
18526
  }
18244
18527
 
18245
- emitter.once('abort', err => {
18528
+ abortEmitter.once('abort', err => {
18246
18529
  if (!responseStream.destroyed) {
18247
18530
  responseStream.emit('error', err);
18248
18531
  responseStream.destroy();
@@ -18250,9 +18533,12 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18250
18533
  });
18251
18534
  });
18252
18535
 
18253
- emitter.once('abort', err => {
18254
- reject(err);
18255
- req.destroy(err);
18536
+ abortEmitter.once('abort', err => {
18537
+ if (req.close) {
18538
+ req.close();
18539
+ } else {
18540
+ req.destroy(err);
18541
+ }
18256
18542
  });
18257
18543
 
18258
18544
  // Handle errors
@@ -18274,7 +18560,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18274
18560
  const timeout = parseInt(config.timeout, 10);
18275
18561
 
18276
18562
  if (Number.isNaN(timeout)) {
18277
- reject(new AxiosError$1(
18563
+ abort(new AxiosError$1(
18278
18564
  'error trying to parse `config.timeout` to int',
18279
18565
  AxiosError$1.ERR_BAD_OPTION_VALUE,
18280
18566
  config,
@@ -18296,14 +18582,16 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18296
18582
  if (config.timeoutErrorMessage) {
18297
18583
  timeoutErrorMessage = config.timeoutErrorMessage;
18298
18584
  }
18299
- reject(new AxiosError$1(
18585
+ abort(new AxiosError$1(
18300
18586
  timeoutErrorMessage,
18301
18587
  transitional.clarifyTimeoutError ? AxiosError$1.ETIMEDOUT : AxiosError$1.ECONNABORTED,
18302
18588
  config,
18303
18589
  req
18304
18590
  ));
18305
- abort();
18306
18591
  });
18592
+ } else {
18593
+ // explicitly reset the socket timeout value for a possible `keep-alive` request
18594
+ req.setTimeout(0);
18307
18595
  }
18308
18596
 
18309
18597
 
@@ -18329,7 +18617,8 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
18329
18617
 
18330
18618
  data.pipe(req);
18331
18619
  } else {
18332
- req.end(data);
18620
+ data && req.write(data);
18621
+ req.end();
18333
18622
  }
18334
18623
  });
18335
18624
  };
@@ -18351,27 +18640,38 @@ var cookies = platform.hasStandardBrowserEnv ?
18351
18640
 
18352
18641
  // Standard browser envs support document.cookie
18353
18642
  {
18354
- write(name, value, expires, path, domain, secure) {
18355
- const cookie = [name + '=' + encodeURIComponent(value)];
18356
-
18357
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
18358
-
18359
- utils$1.isString(path) && cookie.push('path=' + path);
18643
+ write(name, value, expires, path, domain, secure, sameSite) {
18644
+ if (typeof document === 'undefined') return;
18360
18645
 
18361
- utils$1.isString(domain) && cookie.push('domain=' + domain);
18646
+ const cookie = [`${name}=${encodeURIComponent(value)}`];
18362
18647
 
18363
- secure === true && cookie.push('secure');
18648
+ if (utils$1.isNumber(expires)) {
18649
+ cookie.push(`expires=${new Date(expires).toUTCString()}`);
18650
+ }
18651
+ if (utils$1.isString(path)) {
18652
+ cookie.push(`path=${path}`);
18653
+ }
18654
+ if (utils$1.isString(domain)) {
18655
+ cookie.push(`domain=${domain}`);
18656
+ }
18657
+ if (secure === true) {
18658
+ cookie.push('secure');
18659
+ }
18660
+ if (utils$1.isString(sameSite)) {
18661
+ cookie.push(`SameSite=${sameSite}`);
18662
+ }
18364
18663
 
18365
18664
  document.cookie = cookie.join('; ');
18366
18665
  },
18367
18666
 
18368
18667
  read(name) {
18369
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
18370
- return (match ? decodeURIComponent(match[3]) : null);
18668
+ if (typeof document === 'undefined') return null;
18669
+ const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
18670
+ return match ? decodeURIComponent(match[1]) : null;
18371
18671
  },
18372
18672
 
18373
18673
  remove(name) {
18374
- this.write(name, '', Date.now() - 86400000);
18674
+ this.write(name, '', Date.now() - 86400000, '/');
18375
18675
  }
18376
18676
  }
18377
18677
 
@@ -18414,11 +18714,11 @@ function mergeConfig$1(config1, config2) {
18414
18714
  }
18415
18715
 
18416
18716
  // eslint-disable-next-line consistent-return
18417
- function mergeDeepProperties(a, b, prop , caseless) {
18717
+ function mergeDeepProperties(a, b, prop, caseless) {
18418
18718
  if (!utils$1.isUndefined(b)) {
18419
- return getMergedValue(a, b, prop , caseless);
18719
+ return getMergedValue(a, b, prop, caseless);
18420
18720
  } else if (!utils$1.isUndefined(a)) {
18421
- return getMergedValue(undefined, a, prop , caseless);
18721
+ return getMergedValue(undefined, a, prop, caseless);
18422
18722
  }
18423
18723
  }
18424
18724
 
@@ -18476,7 +18776,7 @@ function mergeConfig$1(config1, config2) {
18476
18776
  socketPath: defaultToConfig2,
18477
18777
  responseEncoding: defaultToConfig2,
18478
18778
  validateStatus: mergeDirectKeys,
18479
- headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
18779
+ headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
18480
18780
  };
18481
18781
 
18482
18782
  utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
@@ -18491,7 +18791,7 @@ function mergeConfig$1(config1, config2) {
18491
18791
  var resolveConfig = (config) => {
18492
18792
  const newConfig = mergeConfig$1({}, config);
18493
18793
 
18494
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
18794
+ let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
18495
18795
 
18496
18796
  newConfig.headers = headers = AxiosHeaders$1.from(headers);
18497
18797
 
@@ -18504,17 +18804,21 @@ var resolveConfig = (config) => {
18504
18804
  );
18505
18805
  }
18506
18806
 
18507
- let contentType;
18508
-
18509
18807
  if (utils$1.isFormData(data)) {
18510
18808
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
18511
- headers.setContentType(undefined); // Let the browser set it
18512
- } else if ((contentType = headers.getContentType()) !== false) {
18513
- // fix semicolon duplication issue for ReactNative FormData implementation
18514
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
18515
- headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
18809
+ headers.setContentType(undefined); // browser handles it
18810
+ } else if (utils$1.isFunction(data.getHeaders)) {
18811
+ // Node.js FormData (like form-data package)
18812
+ const formHeaders = data.getHeaders();
18813
+ // Only set safe headers to avoid overwriting security headers
18814
+ const allowedHeaders = ['content-type', 'content-length'];
18815
+ Object.entries(formHeaders).forEach(([key, val]) => {
18816
+ if (allowedHeaders.includes(key.toLowerCase())) {
18817
+ headers.set(key, val);
18818
+ }
18819
+ });
18516
18820
  }
18517
- }
18821
+ }
18518
18822
 
18519
18823
  // Add xsrf header
18520
18824
  // This is only done if running in a standard browser environment.
@@ -18631,15 +18935,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
18631
18935
  };
18632
18936
 
18633
18937
  // Handle low level network errors
18634
- request.onerror = function handleError() {
18635
- // Real errors are hidden from us by the browser
18636
- // onerror should only fire if it's a network error
18637
- reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request));
18638
-
18639
- // Clean up request
18640
- request = null;
18938
+ request.onerror = function handleError(event) {
18939
+ // Browsers deliver a ProgressEvent in XHR onerror
18940
+ // (message may be empty; when present, surface it)
18941
+ // See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
18942
+ const msg = event && event.message ? event.message : 'Network Error';
18943
+ const err = new AxiosError$1(msg, AxiosError$1.ERR_NETWORK, config, request);
18944
+ // attach the underlying event for consumers who want details
18945
+ err.event = event || null;
18946
+ reject(err);
18947
+ request = null;
18641
18948
  };
18642
-
18949
+
18643
18950
  // Handle timeout
18644
18951
  request.ontimeout = function handleTimeout() {
18645
18952
  let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
@@ -18853,14 +19160,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
18853
19160
  })
18854
19161
  };
18855
19162
 
18856
- const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
18857
- const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
19163
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
19164
+
19165
+ const {isFunction} = utils$1;
19166
+
19167
+ const globalFetchAPI = (({Request, Response}) => ({
19168
+ Request, Response
19169
+ }))(utils$1.global);
19170
+
19171
+ const {
19172
+ ReadableStream: ReadableStream$1, TextEncoder: TextEncoder$1
19173
+ } = utils$1.global;
18858
19174
 
18859
- // used only inside the fetch adapter
18860
- const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
18861
- ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
18862
- async (str) => new Uint8Array(await new Response(str).arrayBuffer())
18863
- );
18864
19175
 
18865
19176
  const test = (fn, ...args) => {
18866
19177
  try {
@@ -18870,278 +19181,380 @@ const test = (fn, ...args) => {
18870
19181
  }
18871
19182
  };
18872
19183
 
18873
- const supportsRequestStream = isReadableStreamSupported && test(() => {
18874
- let duplexAccessed = false;
19184
+ const factory = (env) => {
19185
+ env = utils$1.merge.call({
19186
+ skipUndefined: true
19187
+ }, globalFetchAPI, env);
18875
19188
 
18876
- const hasContentType = new Request(platform.origin, {
18877
- body: new ReadableStream(),
18878
- method: 'POST',
18879
- get duplex() {
18880
- duplexAccessed = true;
18881
- return 'half';
18882
- },
18883
- }).headers.has('Content-Type');
19189
+ const {fetch: envFetch, Request, Response} = env;
19190
+ const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
19191
+ const isRequestSupported = isFunction(Request);
19192
+ const isResponseSupported = isFunction(Response);
18884
19193
 
18885
- return duplexAccessed && !hasContentType;
18886
- });
19194
+ if (!isFetchSupported) {
19195
+ return false;
19196
+ }
18887
19197
 
18888
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
19198
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
18889
19199
 
18890
- const supportsResponseStream = isReadableStreamSupported &&
18891
- test(() => utils$1.isReadableStream(new Response('').body));
19200
+ const encodeText = isFetchSupported && (typeof TextEncoder$1 === 'function' ?
19201
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder$1()) :
19202
+ async (str) => new Uint8Array(await new Request(str).arrayBuffer())
19203
+ );
18892
19204
 
19205
+ const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
19206
+ let duplexAccessed = false;
18893
19207
 
18894
- const resolvers = {
18895
- stream: supportsResponseStream && ((res) => res.body)
18896
- };
19208
+ const hasContentType = new Request(platform.origin, {
19209
+ body: new ReadableStream$1(),
19210
+ method: 'POST',
19211
+ get duplex() {
19212
+ duplexAccessed = true;
19213
+ return 'half';
19214
+ },
19215
+ }).headers.has('Content-Type');
18897
19216
 
18898
- isFetchSupported && (((res) => {
18899
- ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
18900
- !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
18901
- (_, config) => {
18902
- throw new AxiosError$1(`Response type '${type}' is not supported`, AxiosError$1.ERR_NOT_SUPPORT, config);
18903
- });
19217
+ return duplexAccessed && !hasContentType;
18904
19218
  });
18905
- })(new Response));
18906
19219
 
18907
- const getBodyLength = async (body) => {
18908
- if (body == null) {
18909
- return 0;
18910
- }
19220
+ const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
19221
+ test(() => utils$1.isReadableStream(new Response('').body));
18911
19222
 
18912
- if(utils$1.isBlob(body)) {
18913
- return body.size;
18914
- }
19223
+ const resolvers = {
19224
+ stream: supportsResponseStream && ((res) => res.body)
19225
+ };
18915
19226
 
18916
- if(utils$1.isSpecCompliantForm(body)) {
18917
- const _request = new Request(platform.origin, {
18918
- method: 'POST',
18919
- body,
19227
+ isFetchSupported && ((() => {
19228
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
19229
+ !resolvers[type] && (resolvers[type] = (res, config) => {
19230
+ let method = res && res[type];
19231
+
19232
+ if (method) {
19233
+ return method.call(res);
19234
+ }
19235
+
19236
+ throw new AxiosError$1(`Response type '${type}' is not supported`, AxiosError$1.ERR_NOT_SUPPORT, config);
19237
+ });
18920
19238
  });
18921
- return (await _request.arrayBuffer()).byteLength;
18922
- }
19239
+ })());
18923
19240
 
18924
- if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
18925
- return body.byteLength;
18926
- }
19241
+ const getBodyLength = async (body) => {
19242
+ if (body == null) {
19243
+ return 0;
19244
+ }
18927
19245
 
18928
- if(utils$1.isURLSearchParams(body)) {
18929
- body = body + '';
18930
- }
19246
+ if (utils$1.isBlob(body)) {
19247
+ return body.size;
19248
+ }
18931
19249
 
18932
- if(utils$1.isString(body)) {
18933
- return (await encodeText(body)).byteLength;
18934
- }
18935
- };
19250
+ if (utils$1.isSpecCompliantForm(body)) {
19251
+ const _request = new Request(platform.origin, {
19252
+ method: 'POST',
19253
+ body,
19254
+ });
19255
+ return (await _request.arrayBuffer()).byteLength;
19256
+ }
18936
19257
 
18937
- const resolveBodyLength = async (headers, body) => {
18938
- const length = utils$1.toFiniteNumber(headers.getContentLength());
19258
+ if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
19259
+ return body.byteLength;
19260
+ }
18939
19261
 
18940
- return length == null ? getBodyLength(body) : length;
18941
- };
19262
+ if (utils$1.isURLSearchParams(body)) {
19263
+ body = body + '';
19264
+ }
19265
+
19266
+ if (utils$1.isString(body)) {
19267
+ return (await encodeText(body)).byteLength;
19268
+ }
19269
+ };
19270
+
19271
+ const resolveBodyLength = async (headers, body) => {
19272
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
19273
+
19274
+ return length == null ? getBodyLength(body) : length;
19275
+ };
19276
+
19277
+ return async (config) => {
19278
+ let {
19279
+ url,
19280
+ method,
19281
+ data,
19282
+ signal,
19283
+ cancelToken,
19284
+ timeout,
19285
+ onDownloadProgress,
19286
+ onUploadProgress,
19287
+ responseType,
19288
+ headers,
19289
+ withCredentials = 'same-origin',
19290
+ fetchOptions
19291
+ } = resolveConfig(config);
18942
19292
 
18943
- var fetchAdapter = isFetchSupported && (async (config) => {
18944
- let {
18945
- url,
18946
- method,
18947
- data,
18948
- signal,
18949
- cancelToken,
18950
- timeout,
18951
- onDownloadProgress,
18952
- onUploadProgress,
18953
- responseType,
18954
- headers,
18955
- withCredentials = 'same-origin',
18956
- fetchOptions
18957
- } = resolveConfig(config);
18958
-
18959
- responseType = responseType ? (responseType + '').toLowerCase() : 'text';
18960
-
18961
- let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
18962
-
18963
- let request;
18964
-
18965
- const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
19293
+ let _fetch = envFetch || fetch;
19294
+
19295
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
19296
+
19297
+ let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
19298
+
19299
+ let request = null;
19300
+
19301
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
18966
19302
  composedSignal.unsubscribe();
18967
- });
19303
+ });
18968
19304
 
18969
- let requestContentLength;
19305
+ let requestContentLength;
18970
19306
 
18971
- try {
18972
- if (
18973
- onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
18974
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
18975
- ) {
18976
- let _request = new Request(url, {
18977
- method: 'POST',
18978
- body: data,
18979
- duplex: "half"
18980
- });
19307
+ try {
19308
+ if (
19309
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
19310
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
19311
+ ) {
19312
+ let _request = new Request(url, {
19313
+ method: 'POST',
19314
+ body: data,
19315
+ duplex: "half"
19316
+ });
18981
19317
 
18982
- let contentTypeHeader;
19318
+ let contentTypeHeader;
18983
19319
 
18984
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
18985
- headers.setContentType(contentTypeHeader);
18986
- }
19320
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
19321
+ headers.setContentType(contentTypeHeader);
19322
+ }
18987
19323
 
18988
- if (_request.body) {
18989
- const [onProgress, flush] = progressEventDecorator(
18990
- requestContentLength,
18991
- progressEventReducer(asyncDecorator(onUploadProgress))
18992
- );
19324
+ if (_request.body) {
19325
+ const [onProgress, flush] = progressEventDecorator(
19326
+ requestContentLength,
19327
+ progressEventReducer(asyncDecorator(onUploadProgress))
19328
+ );
18993
19329
 
18994
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
19330
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
19331
+ }
18995
19332
  }
18996
- }
18997
19333
 
18998
- if (!utils$1.isString(withCredentials)) {
18999
- withCredentials = withCredentials ? 'include' : 'omit';
19000
- }
19334
+ if (!utils$1.isString(withCredentials)) {
19335
+ withCredentials = withCredentials ? 'include' : 'omit';
19336
+ }
19001
19337
 
19002
- // Cloudflare Workers throws when credentials are defined
19003
- // see https://github.com/cloudflare/workerd/issues/902
19004
- const isCredentialsSupported = "credentials" in Request.prototype;
19005
- request = new Request(url, {
19006
- ...fetchOptions,
19007
- signal: composedSignal,
19008
- method: method.toUpperCase(),
19009
- headers: headers.normalize().toJSON(),
19010
- body: data,
19011
- duplex: "half",
19012
- credentials: isCredentialsSupported ? withCredentials : undefined
19013
- });
19338
+ // Cloudflare Workers throws when credentials are defined
19339
+ // see https://github.com/cloudflare/workerd/issues/902
19340
+ const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
19014
19341
 
19015
- let response = await fetch(request, fetchOptions);
19342
+ const resolvedOptions = {
19343
+ ...fetchOptions,
19344
+ signal: composedSignal,
19345
+ method: method.toUpperCase(),
19346
+ headers: headers.normalize().toJSON(),
19347
+ body: data,
19348
+ duplex: "half",
19349
+ credentials: isCredentialsSupported ? withCredentials : undefined
19350
+ };
19016
19351
 
19017
- const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
19352
+ request = isRequestSupported && new Request(url, resolvedOptions);
19018
19353
 
19019
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
19020
- const options = {};
19354
+ let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
19021
19355
 
19022
- ['status', 'statusText', 'headers'].forEach(prop => {
19023
- options[prop] = response[prop];
19024
- });
19356
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
19025
19357
 
19026
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
19358
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
19359
+ const options = {};
19027
19360
 
19028
- const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
19029
- responseContentLength,
19030
- progressEventReducer(asyncDecorator(onDownloadProgress), true)
19031
- ) || [];
19361
+ ['status', 'statusText', 'headers'].forEach(prop => {
19362
+ options[prop] = response[prop];
19363
+ });
19032
19364
 
19033
- response = new Response(
19034
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
19035
- flush && flush();
19036
- unsubscribe && unsubscribe();
19037
- }),
19038
- options
19039
- );
19040
- }
19365
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
19041
19366
 
19042
- responseType = responseType || 'text';
19367
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
19368
+ responseContentLength,
19369
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
19370
+ ) || [];
19043
19371
 
19044
- let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
19372
+ response = new Response(
19373
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
19374
+ flush && flush();
19375
+ unsubscribe && unsubscribe();
19376
+ }),
19377
+ options
19378
+ );
19379
+ }
19045
19380
 
19046
- !isStreamResponse && unsubscribe && unsubscribe();
19381
+ responseType = responseType || 'text';
19047
19382
 
19048
- return await new Promise((resolve, reject) => {
19049
- settle(resolve, reject, {
19050
- data: responseData,
19051
- headers: AxiosHeaders$1.from(response.headers),
19052
- status: response.status,
19053
- statusText: response.statusText,
19054
- config,
19055
- request
19056
- });
19057
- })
19058
- } catch (err) {
19059
- unsubscribe && unsubscribe();
19060
-
19061
- if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
19062
- throw Object.assign(
19063
- new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request),
19064
- {
19065
- cause: err.cause || err
19066
- }
19067
- )
19383
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
19384
+
19385
+ !isStreamResponse && unsubscribe && unsubscribe();
19386
+
19387
+ return await new Promise((resolve, reject) => {
19388
+ settle(resolve, reject, {
19389
+ data: responseData,
19390
+ headers: AxiosHeaders$1.from(response.headers),
19391
+ status: response.status,
19392
+ statusText: response.statusText,
19393
+ config,
19394
+ request
19395
+ });
19396
+ })
19397
+ } catch (err) {
19398
+ unsubscribe && unsubscribe();
19399
+
19400
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
19401
+ throw Object.assign(
19402
+ new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request),
19403
+ {
19404
+ cause: err.cause || err
19405
+ }
19406
+ )
19407
+ }
19408
+
19409
+ throw AxiosError$1.from(err, err && err.code, config, request);
19068
19410
  }
19411
+ }
19412
+ };
19413
+
19414
+ const seedCache = new Map();
19415
+
19416
+ const getFetch = (config) => {
19417
+ let env = (config && config.env) || {};
19418
+ const {fetch, Request, Response} = env;
19419
+ const seeds = [
19420
+ Request, Response, fetch
19421
+ ];
19422
+
19423
+ let len = seeds.length, i = len,
19424
+ seed, target, map = seedCache;
19425
+
19426
+ while (i--) {
19427
+ seed = seeds[i];
19428
+ target = map.get(seed);
19069
19429
 
19070
- throw AxiosError$1.from(err, err && err.code, config, request);
19430
+ target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
19431
+
19432
+ map = target;
19071
19433
  }
19072
- });
19073
19434
 
19435
+ return target;
19436
+ };
19437
+
19438
+ getFetch();
19439
+
19440
+ /**
19441
+ * Known adapters mapping.
19442
+ * Provides environment-specific adapters for Axios:
19443
+ * - `http` for Node.js
19444
+ * - `xhr` for browsers
19445
+ * - `fetch` for fetch API-based requests
19446
+ *
19447
+ * @type {Object<string, Function|Object>}
19448
+ */
19074
19449
  const knownAdapters = {
19075
19450
  http: httpAdapter,
19076
19451
  xhr: xhrAdapter,
19077
- fetch: fetchAdapter
19452
+ fetch: {
19453
+ get: getFetch,
19454
+ }
19078
19455
  };
19079
19456
 
19457
+ // Assign adapter names for easier debugging and identification
19080
19458
  utils$1.forEach(knownAdapters, (fn, value) => {
19081
19459
  if (fn) {
19082
19460
  try {
19083
- Object.defineProperty(fn, 'name', {value});
19461
+ Object.defineProperty(fn, 'name', { value });
19084
19462
  } catch (e) {
19085
19463
  // eslint-disable-next-line no-empty
19086
19464
  }
19087
- Object.defineProperty(fn, 'adapterName', {value});
19465
+ Object.defineProperty(fn, 'adapterName', { value });
19088
19466
  }
19089
19467
  });
19090
19468
 
19469
+ /**
19470
+ * Render a rejection reason string for unknown or unsupported adapters
19471
+ *
19472
+ * @param {string} reason
19473
+ * @returns {string}
19474
+ */
19091
19475
  const renderReason = (reason) => `- ${reason}`;
19092
19476
 
19477
+ /**
19478
+ * Check if the adapter is resolved (function, null, or false)
19479
+ *
19480
+ * @param {Function|null|false} adapter
19481
+ * @returns {boolean}
19482
+ */
19093
19483
  const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
19094
19484
 
19095
- var adapters = {
19096
- getAdapter: (adapters) => {
19097
- adapters = utils$1.isArray(adapters) ? adapters : [adapters];
19485
+ /**
19486
+ * Get the first suitable adapter from the provided list.
19487
+ * Tries each adapter in order until a supported one is found.
19488
+ * Throws an AxiosError if no adapter is suitable.
19489
+ *
19490
+ * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
19491
+ * @param {Object} config - Axios request configuration
19492
+ * @throws {AxiosError} If no suitable adapter is available
19493
+ * @returns {Function} The resolved adapter function
19494
+ */
19495
+ function getAdapter$1(adapters, config) {
19496
+ adapters = utils$1.isArray(adapters) ? adapters : [adapters];
19098
19497
 
19099
- const {length} = adapters;
19100
- let nameOrAdapter;
19101
- let adapter;
19498
+ const { length } = adapters;
19499
+ let nameOrAdapter;
19500
+ let adapter;
19102
19501
 
19103
- const rejectedReasons = {};
19502
+ const rejectedReasons = {};
19104
19503
 
19105
- for (let i = 0; i < length; i++) {
19106
- nameOrAdapter = adapters[i];
19107
- let id;
19504
+ for (let i = 0; i < length; i++) {
19505
+ nameOrAdapter = adapters[i];
19506
+ let id;
19108
19507
 
19109
- adapter = nameOrAdapter;
19508
+ adapter = nameOrAdapter;
19110
19509
 
19111
- if (!isResolvedHandle(nameOrAdapter)) {
19112
- adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
19510
+ if (!isResolvedHandle(nameOrAdapter)) {
19511
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
19113
19512
 
19114
- if (adapter === undefined) {
19115
- throw new AxiosError$1(`Unknown adapter '${id}'`);
19116
- }
19117
- }
19118
-
19119
- if (adapter) {
19120
- break;
19513
+ if (adapter === undefined) {
19514
+ throw new AxiosError$1(`Unknown adapter '${id}'`);
19121
19515
  }
19516
+ }
19122
19517
 
19123
- rejectedReasons[id || '#' + i] = adapter;
19518
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
19519
+ break;
19124
19520
  }
19125
19521
 
19126
- if (!adapter) {
19522
+ rejectedReasons[id || '#' + i] = adapter;
19523
+ }
19127
19524
 
19128
- const reasons = Object.entries(rejectedReasons)
19129
- .map(([id, state]) => `adapter ${id} ` +
19130
- (state === false ? 'is not supported by the environment' : 'is not available in the build')
19131
- );
19525
+ if (!adapter) {
19526
+ const reasons = Object.entries(rejectedReasons)
19527
+ .map(([id, state]) => `adapter ${id} ` +
19528
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
19529
+ );
19132
19530
 
19133
- let s = length ?
19134
- (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
19135
- 'as no adapter specified';
19531
+ let s = length ?
19532
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
19533
+ 'as no adapter specified';
19136
19534
 
19137
- throw new AxiosError$1(
19138
- `There is no suitable adapter to dispatch the request ` + s,
19139
- 'ERR_NOT_SUPPORT'
19140
- );
19141
- }
19535
+ throw new AxiosError$1(
19536
+ `There is no suitable adapter to dispatch the request ` + s,
19537
+ 'ERR_NOT_SUPPORT'
19538
+ );
19539
+ }
19142
19540
 
19143
- return adapter;
19144
- },
19541
+ return adapter;
19542
+ }
19543
+
19544
+ /**
19545
+ * Exports Axios adapters and utility to resolve an adapter
19546
+ */
19547
+ var adapters = {
19548
+ /**
19549
+ * Resolve an adapter from a list of adapter names or functions.
19550
+ * @type {Function}
19551
+ */
19552
+ getAdapter: getAdapter$1,
19553
+
19554
+ /**
19555
+ * Exposes all known adapters
19556
+ * @type {Object<string, Function|Object>}
19557
+ */
19145
19558
  adapters: knownAdapters
19146
19559
  };
19147
19560
 
@@ -19184,7 +19597,7 @@ function dispatchRequest(config) {
19184
19597
  config.headers.setContentType('application/x-www-form-urlencoded', false);
19185
19598
  }
19186
19599
 
19187
- const adapter = adapters.getAdapter(config.adapter || defaults.adapter);
19600
+ const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
19188
19601
 
19189
19602
  return adapter(config).then(function onAdapterResolution(response) {
19190
19603
  throwIfCancellationRequested(config);
@@ -19472,8 +19885,6 @@ let Axios$1 = class Axios {
19472
19885
 
19473
19886
  let newConfig = config;
19474
19887
 
19475
- i = 0;
19476
-
19477
19888
  while (i < len) {
19478
19889
  const onFulfilled = requestInterceptorChain[i++];
19479
19890
  const onRejected = requestInterceptorChain[i++];
@@ -19773,6 +20184,12 @@ const HttpStatusCode$1 = {
19773
20184
  LoopDetected: 508,
19774
20185
  NotExtended: 510,
19775
20186
  NetworkAuthenticationRequired: 511,
20187
+ WebServerIsDown: 521,
20188
+ ConnectionTimedOut: 522,
20189
+ OriginIsUnreachable: 523,
20190
+ TimeoutOccurred: 524,
20191
+ SslHandshakeFailed: 525,
20192
+ InvalidSslCertificate: 526,
19776
20193
  };
19777
20194
 
19778
20195
  Object.entries(HttpStatusCode$1).forEach(([key, value]) => {