axios 1.9.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Axios v1.9.0 Copyright (c) 2025 Matt Zabriskie and contributors */
1
+ /*! Axios v1.12.0 Copyright (c) 2025 Matt Zabriskie and contributors */
2
2
  function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -50,7 +50,7 @@ const isUndefined = typeOfTest('undefined');
50
50
  */
51
51
  function isBuffer(val) {
52
52
  return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
53
- && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
53
+ && isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
54
54
  }
55
55
 
56
56
  /**
@@ -95,7 +95,7 @@ const isString = typeOfTest('string');
95
95
  * @param {*} val The value to test
96
96
  * @returns {boolean} True if value is a Function, otherwise false
97
97
  */
98
- const isFunction = typeOfTest('function');
98
+ const isFunction$1 = typeOfTest('function');
99
99
 
100
100
  /**
101
101
  * Determine if a value is a Number
@@ -139,6 +139,27 @@ const isPlainObject = (val) => {
139
139
  return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
140
140
  };
141
141
 
142
+ /**
143
+ * Determine if a value is an empty object (safely handles Buffers)
144
+ *
145
+ * @param {*} val The value to test
146
+ *
147
+ * @returns {boolean} True if value is an empty object, otherwise false
148
+ */
149
+ const isEmptyObject = (val) => {
150
+ // Early return for non-objects or Buffers to prevent RangeError
151
+ if (!isObject(val) || isBuffer(val)) {
152
+ return false;
153
+ }
154
+
155
+ try {
156
+ return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
157
+ } catch (e) {
158
+ // Fallback for any other objects that might cause RangeError with Object.keys()
159
+ return false;
160
+ }
161
+ };
162
+
142
163
  /**
143
164
  * Determine if a value is a Date
144
165
  *
@@ -182,7 +203,7 @@ const isFileList = kindOfTest('FileList');
182
203
  *
183
204
  * @returns {boolean} True if value is a Stream, otherwise false
184
205
  */
185
- const isStream = (val) => isObject(val) && isFunction(val.pipe);
206
+ const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
186
207
 
187
208
  /**
188
209
  * Determine if a value is a FormData
@@ -195,10 +216,10 @@ const isFormData = (thing) => {
195
216
  let kind;
196
217
  return thing && (
197
218
  (typeof FormData === 'function' && thing instanceof FormData) || (
198
- isFunction(thing.append) && (
219
+ isFunction$1(thing.append) && (
199
220
  (kind = kindOf(thing)) === 'formdata' ||
200
221
  // detect form-data instance
201
- (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
222
+ (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
202
223
  )
203
224
  )
204
225
  )
@@ -261,6 +282,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
261
282
  fn.call(null, obj[i], i, obj);
262
283
  }
263
284
  } else {
285
+ // Buffer check
286
+ if (isBuffer(obj)) {
287
+ return;
288
+ }
289
+
264
290
  // Iterate over object keys
265
291
  const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
266
292
  const len = keys.length;
@@ -274,6 +300,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
274
300
  }
275
301
 
276
302
  function findKey(obj, key) {
303
+ if (isBuffer(obj)){
304
+ return null;
305
+ }
306
+
277
307
  key = key.toLowerCase();
278
308
  const keys = Object.keys(obj);
279
309
  let i = keys.length;
@@ -314,7 +344,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
314
344
  * @returns {Object} Result of all merge properties
315
345
  */
316
346
  function merge(/* obj1, obj2, obj3, ... */) {
317
- const {caseless} = isContextDefined(this) && this || {};
347
+ const {caseless, skipUndefined} = isContextDefined(this) && this || {};
318
348
  const result = {};
319
349
  const assignValue = (val, key) => {
320
350
  const targetKey = caseless && findKey(result, key) || key;
@@ -325,7 +355,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
325
355
  } else if (isArray(val)) {
326
356
  result[targetKey] = val.slice();
327
357
  } else {
328
- result[targetKey] = val;
358
+ if (!skipUndefined || !isUndefined(val)) {
359
+ result[targetKey] = val;
360
+ }
329
361
  }
330
362
  };
331
363
 
@@ -347,7 +379,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
347
379
  */
348
380
  const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
349
381
  forEach(b, (val, key) => {
350
- if (thisArg && isFunction(val)) {
382
+ if (thisArg && isFunction$1(val)) {
351
383
  a[key] = bind(val, thisArg);
352
384
  } else {
353
385
  a[key] = val;
@@ -563,13 +595,13 @@ const reduceDescriptors = (obj, reducer) => {
563
595
  const freezeMethods = (obj) => {
564
596
  reduceDescriptors(obj, (descriptor, name) => {
565
597
  // skip restricted props in strict mode
566
- if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
598
+ if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
567
599
  return false;
568
600
  }
569
601
 
570
602
  const value = obj[name];
571
603
 
572
- if (!isFunction(value)) return;
604
+ if (!isFunction$1(value)) return;
573
605
 
574
606
  descriptor.enumerable = false;
575
607
 
@@ -606,6 +638,8 @@ const toFiniteNumber = (value, defaultValue) => {
606
638
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
607
639
  };
608
640
 
641
+
642
+
609
643
  /**
610
644
  * If the thing is a FormData object, return true, otherwise return false.
611
645
  *
@@ -614,7 +648,7 @@ const toFiniteNumber = (value, defaultValue) => {
614
648
  * @returns {boolean}
615
649
  */
616
650
  function isSpecCompliantForm(thing) {
617
- return !!(thing && isFunction(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
651
+ return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
618
652
  }
619
653
 
620
654
  const toJSONObject = (obj) => {
@@ -627,6 +661,11 @@ const toJSONObject = (obj) => {
627
661
  return;
628
662
  }
629
663
 
664
+ //Buffer check
665
+ if (isBuffer(source)) {
666
+ return source;
667
+ }
668
+
630
669
  if(!('toJSON' in source)) {
631
670
  stack[i] = source;
632
671
  const target = isArray(source) ? [] : {};
@@ -651,7 +690,7 @@ const toJSONObject = (obj) => {
651
690
  const isAsyncFn = kindOfTest('AsyncFunction');
652
691
 
653
692
  const isThenable = (thing) =>
654
- thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
693
+ thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
655
694
 
656
695
  // original code
657
696
  // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
@@ -675,7 +714,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
675
714
  })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
676
715
  })(
677
716
  typeof setImmediate === 'function',
678
- isFunction(_global.postMessage)
717
+ isFunction$1(_global.postMessage)
679
718
  );
680
719
 
681
720
  const asap = typeof queueMicrotask !== 'undefined' ?
@@ -684,7 +723,7 @@ const asap = typeof queueMicrotask !== 'undefined' ?
684
723
  // *********************
685
724
 
686
725
 
687
- const isIterable = (thing) => thing != null && isFunction(thing[iterator]);
726
+ const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
688
727
 
689
728
 
690
729
  const utils$1 = {
@@ -698,6 +737,7 @@ const utils$1 = {
698
737
  isBoolean,
699
738
  isObject,
700
739
  isPlainObject,
740
+ isEmptyObject,
701
741
  isReadableStream,
702
742
  isRequest,
703
743
  isResponse,
@@ -707,7 +747,7 @@ const utils$1 = {
707
747
  isFile,
708
748
  isBlob,
709
749
  isRegExp,
710
- isFunction,
750
+ isFunction: isFunction$1,
711
751
  isStream,
712
752
  isURLSearchParams,
713
753
  isTypedArray,
@@ -833,11 +873,18 @@ AxiosError$1.from = (error, code, config, request, response, customProps) => {
833
873
  return prop !== 'isAxiosError';
834
874
  });
835
875
 
836
- AxiosError$1.call(axiosError, error.message, code, config, request, response);
876
+ const msg = error && error.message ? error.message : 'Error';
837
877
 
838
- axiosError.cause = error;
878
+ // Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
879
+ const errCode = code == null && error ? error.code : code;
880
+ AxiosError$1.call(axiosError, msg, errCode, config, request, response);
839
881
 
840
- axiosError.name = error.name;
882
+ // Chain the original error on the standard field; non-enumerable to avoid JSON noise
883
+ if (error && axiosError.cause == null) {
884
+ Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
885
+ }
886
+
887
+ axiosError.name = (error && error.name) || 'Error';
841
888
 
842
889
  customProps && Object.assign(axiosError, customProps);
843
890
 
@@ -962,6 +1009,10 @@ function toFormData$1(obj, formData, options) {
962
1009
  return value.toISOString();
963
1010
  }
964
1011
 
1012
+ if (utils$1.isBoolean(value)) {
1013
+ return value.toString();
1014
+ }
1015
+
965
1016
  if (!useBlob && utils$1.isBlob(value)) {
966
1017
  throw new AxiosError$1('Blob is not supported. Use a Buffer instead.');
967
1018
  }
@@ -1124,9 +1175,7 @@ function encode(val) {
1124
1175
  replace(/%3A/gi, ':').
1125
1176
  replace(/%24/g, '$').
1126
1177
  replace(/%2C/gi, ',').
1127
- replace(/%20/g, '+').
1128
- replace(/%5B/gi, '[').
1129
- replace(/%5D/gi, ']');
1178
+ replace(/%20/g, '+');
1130
1179
  }
1131
1180
 
1132
1181
  /**
@@ -1325,7 +1374,7 @@ const platform = {
1325
1374
  };
1326
1375
 
1327
1376
  function toURLEncodedForm(data, options) {
1328
- return toFormData$1(data, new platform.classes.URLSearchParams(), Object.assign({
1377
+ return toFormData$1(data, new platform.classes.URLSearchParams(), {
1329
1378
  visitor: function(value, key, path, helpers) {
1330
1379
  if (platform.isNode && utils$1.isBuffer(value)) {
1331
1380
  this.append(key, value.toString('base64'));
@@ -1333,8 +1382,9 @@ function toURLEncodedForm(data, options) {
1333
1382
  }
1334
1383
 
1335
1384
  return helpers.defaultVisitor.apply(this, arguments);
1336
- }
1337
- }, options));
1385
+ },
1386
+ ...options
1387
+ });
1338
1388
  }
1339
1389
 
1340
1390
  /**
@@ -1530,7 +1580,7 @@ const defaults = {
1530
1580
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
1531
1581
 
1532
1582
  try {
1533
- return JSON.parse(data);
1583
+ return JSON.parse(data, this.parseReviver);
1534
1584
  } catch (e) {
1535
1585
  if (strictJSONParsing) {
1536
1586
  if (e.name === 'SyntaxError') {
@@ -2087,7 +2137,7 @@ function throttle(fn, freq) {
2087
2137
  clearTimeout(timer);
2088
2138
  timer = null;
2089
2139
  }
2090
- fn.apply(null, args);
2140
+ fn(...args);
2091
2141
  };
2092
2142
 
2093
2143
  const throttled = (...args) => {
@@ -2343,7 +2393,7 @@ function mergeConfig$1(config1, config2) {
2343
2393
  headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2344
2394
  };
2345
2395
 
2346
- utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2396
+ utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
2347
2397
  const merge = mergeMap[prop] || mergeDeepProperties;
2348
2398
  const configValue = merge(config1[prop], config2[prop], prop);
2349
2399
  (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
@@ -2355,7 +2405,7 @@ function mergeConfig$1(config1, config2) {
2355
2405
  const resolveConfig = (config) => {
2356
2406
  const newConfig = mergeConfig$1({}, config);
2357
2407
 
2358
- let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
2408
+ let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
2359
2409
 
2360
2410
  newConfig.headers = headers = AxiosHeaders$2.from(headers);
2361
2411
 
@@ -2368,17 +2418,21 @@ const resolveConfig = (config) => {
2368
2418
  );
2369
2419
  }
2370
2420
 
2371
- let contentType;
2372
-
2373
2421
  if (utils$1.isFormData(data)) {
2374
2422
  if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2375
- headers.setContentType(undefined); // Let the browser set it
2376
- } else if ((contentType = headers.getContentType()) !== false) {
2377
- // fix semicolon duplication issue for ReactNative FormData implementation
2378
- const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2379
- headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2423
+ headers.setContentType(undefined); // browser handles it
2424
+ } else if (utils$1.isFunction(data.getHeaders)) {
2425
+ // Node.js FormData (like form-data package)
2426
+ const formHeaders = data.getHeaders();
2427
+ // Only set safe headers to avoid overwriting security headers
2428
+ const allowedHeaders = ['content-type', 'content-length'];
2429
+ Object.entries(formHeaders).forEach(([key, val]) => {
2430
+ if (allowedHeaders.includes(key.toLowerCase())) {
2431
+ headers.set(key, val);
2432
+ }
2433
+ });
2380
2434
  }
2381
- }
2435
+ }
2382
2436
 
2383
2437
  // Add xsrf header
2384
2438
  // This is only done if running in a standard browser environment.
@@ -2495,15 +2549,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2495
2549
  };
2496
2550
 
2497
2551
  // Handle low level network errors
2498
- request.onerror = function handleError() {
2499
- // Real errors are hidden from us by the browser
2500
- // onerror should only fire if it's a network error
2501
- reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request));
2502
-
2503
- // Clean up request
2504
- request = null;
2552
+ request.onerror = function handleError(event) {
2553
+ // Browsers deliver a ProgressEvent in XHR onerror
2554
+ // (message may be empty; when present, surface it)
2555
+ // See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
2556
+ const msg = event && event.message ? event.message : 'Network Error';
2557
+ const err = new AxiosError$1(msg, AxiosError$1.ERR_NETWORK, config, request);
2558
+ // attach the underlying event for consumers who want details
2559
+ err.event = event || null;
2560
+ reject(err);
2561
+ request = null;
2505
2562
  };
2506
-
2563
+
2507
2564
  // Handle timeout
2508
2565
  request.ontimeout = function handleTimeout() {
2509
2566
  let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
@@ -2719,14 +2776,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2719
2776
  })
2720
2777
  };
2721
2778
 
2722
- const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
2723
- const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
2779
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
2780
+
2781
+ const {isFunction} = utils$1;
2782
+
2783
+ const globalFetchAPI = (({fetch, Request, Response}) => ({
2784
+ fetch, Request, Response
2785
+ }))(utils$1.global);
2786
+
2787
+ const {
2788
+ ReadableStream: ReadableStream$1, TextEncoder
2789
+ } = utils$1.global;
2724
2790
 
2725
- // used only inside the fetch adapter
2726
- const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2727
- ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2728
- async (str) => new Uint8Array(await new Response(str).arrayBuffer())
2729
- );
2730
2791
 
2731
2792
  const test = (fn, ...args) => {
2732
2793
  try {
@@ -2736,211 +2797,266 @@ const test = (fn, ...args) => {
2736
2797
  }
2737
2798
  };
2738
2799
 
2739
- const supportsRequestStream = isReadableStreamSupported && test(() => {
2740
- let duplexAccessed = false;
2800
+ const factory = (env) => {
2801
+ const {fetch, Request, Response} = Object.assign({}, globalFetchAPI, env);
2802
+ const isFetchSupported = isFunction(fetch);
2803
+ const isRequestSupported = isFunction(Request);
2804
+ const isResponseSupported = isFunction(Response);
2741
2805
 
2742
- const hasContentType = new Request(platform.origin, {
2743
- body: new ReadableStream(),
2744
- method: 'POST',
2745
- get duplex() {
2746
- duplexAccessed = true;
2747
- return 'half';
2748
- },
2749
- }).headers.has('Content-Type');
2806
+ if (!isFetchSupported) {
2807
+ return false;
2808
+ }
2750
2809
 
2751
- return duplexAccessed && !hasContentType;
2752
- });
2810
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
2753
2811
 
2754
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
2812
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2813
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2814
+ async (str) => new Uint8Array(await new Request(str).arrayBuffer())
2815
+ );
2755
2816
 
2756
- const supportsResponseStream = isReadableStreamSupported &&
2757
- test(() => utils$1.isReadableStream(new Response('').body));
2817
+ const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
2818
+ let duplexAccessed = false;
2758
2819
 
2820
+ const hasContentType = new Request(platform.origin, {
2821
+ body: new ReadableStream$1(),
2822
+ method: 'POST',
2823
+ get duplex() {
2824
+ duplexAccessed = true;
2825
+ return 'half';
2826
+ },
2827
+ }).headers.has('Content-Type');
2759
2828
 
2760
- const resolvers = {
2761
- stream: supportsResponseStream && ((res) => res.body)
2762
- };
2829
+ return duplexAccessed && !hasContentType;
2830
+ });
2831
+
2832
+ const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
2833
+ test(() => utils$1.isReadableStream(new Response('').body));
2834
+
2835
+ const resolvers = {
2836
+ stream: supportsResponseStream && ((res) => res.body)
2837
+ };
2838
+
2839
+ isFetchSupported && ((() => {
2840
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2841
+ !resolvers[type] && (resolvers[type] = (res, config) => {
2842
+ let method = res && res[type];
2843
+
2844
+ if (method) {
2845
+ return method.call(res);
2846
+ }
2763
2847
 
2764
- isFetchSupported && (((res) => {
2765
- ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2766
- !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2767
- (_, config) => {
2768
2848
  throw new AxiosError$1(`Response type '${type}' is not supported`, AxiosError$1.ERR_NOT_SUPPORT, config);
2769
2849
  });
2770
- });
2771
- })(new Response));
2850
+ });
2851
+ })());
2772
2852
 
2773
- const getBodyLength = async (body) => {
2774
- if (body == null) {
2775
- return 0;
2776
- }
2853
+ const getBodyLength = async (body) => {
2854
+ if (body == null) {
2855
+ return 0;
2856
+ }
2777
2857
 
2778
- if(utils$1.isBlob(body)) {
2779
- return body.size;
2780
- }
2858
+ if (utils$1.isBlob(body)) {
2859
+ return body.size;
2860
+ }
2781
2861
 
2782
- if(utils$1.isSpecCompliantForm(body)) {
2783
- const _request = new Request(platform.origin, {
2784
- method: 'POST',
2785
- body,
2786
- });
2787
- return (await _request.arrayBuffer()).byteLength;
2788
- }
2862
+ if (utils$1.isSpecCompliantForm(body)) {
2863
+ const _request = new Request(platform.origin, {
2864
+ method: 'POST',
2865
+ body,
2866
+ });
2867
+ return (await _request.arrayBuffer()).byteLength;
2868
+ }
2789
2869
 
2790
- if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2791
- return body.byteLength;
2792
- }
2870
+ if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
2871
+ return body.byteLength;
2872
+ }
2793
2873
 
2794
- if(utils$1.isURLSearchParams(body)) {
2795
- body = body + '';
2796
- }
2874
+ if (utils$1.isURLSearchParams(body)) {
2875
+ body = body + '';
2876
+ }
2797
2877
 
2798
- if(utils$1.isString(body)) {
2799
- return (await encodeText(body)).byteLength;
2800
- }
2801
- };
2878
+ if (utils$1.isString(body)) {
2879
+ return (await encodeText(body)).byteLength;
2880
+ }
2881
+ };
2802
2882
 
2803
- const resolveBodyLength = async (headers, body) => {
2804
- const length = utils$1.toFiniteNumber(headers.getContentLength());
2883
+ const resolveBodyLength = async (headers, body) => {
2884
+ const length = utils$1.toFiniteNumber(headers.getContentLength());
2805
2885
 
2806
- return length == null ? getBodyLength(body) : length;
2807
- };
2886
+ return length == null ? getBodyLength(body) : length;
2887
+ };
2888
+
2889
+ return async (config) => {
2890
+ let {
2891
+ url,
2892
+ method,
2893
+ data,
2894
+ signal,
2895
+ cancelToken,
2896
+ timeout,
2897
+ onDownloadProgress,
2898
+ onUploadProgress,
2899
+ responseType,
2900
+ headers,
2901
+ withCredentials = 'same-origin',
2902
+ fetchOptions
2903
+ } = resolveConfig(config);
2904
+
2905
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2808
2906
 
2809
- const fetchAdapter = isFetchSupported && (async (config) => {
2810
- let {
2811
- url,
2812
- method,
2813
- data,
2814
- signal,
2815
- cancelToken,
2816
- timeout,
2817
- onDownloadProgress,
2818
- onUploadProgress,
2819
- responseType,
2820
- headers,
2821
- withCredentials = 'same-origin',
2822
- fetchOptions
2823
- } = resolveConfig(config);
2824
-
2825
- responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2826
-
2827
- let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2828
-
2829
- let request;
2830
-
2831
- const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2907
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2908
+
2909
+ let request = null;
2910
+
2911
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2832
2912
  composedSignal.unsubscribe();
2833
- });
2913
+ });
2834
2914
 
2835
- let requestContentLength;
2915
+ let requestContentLength;
2836
2916
 
2837
- try {
2838
- if (
2839
- onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2840
- (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2841
- ) {
2842
- let _request = new Request(url, {
2843
- method: 'POST',
2844
- body: data,
2845
- duplex: "half"
2846
- });
2917
+ try {
2918
+ if (
2919
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2920
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2921
+ ) {
2922
+ let _request = new Request(url, {
2923
+ method: 'POST',
2924
+ body: data,
2925
+ duplex: "half"
2926
+ });
2847
2927
 
2848
- let contentTypeHeader;
2928
+ let contentTypeHeader;
2849
2929
 
2850
- if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2851
- headers.setContentType(contentTypeHeader);
2852
- }
2930
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
2931
+ headers.setContentType(contentTypeHeader);
2932
+ }
2853
2933
 
2854
- if (_request.body) {
2855
- const [onProgress, flush] = progressEventDecorator(
2856
- requestContentLength,
2857
- progressEventReducer(asyncDecorator(onUploadProgress))
2858
- );
2934
+ if (_request.body) {
2935
+ const [onProgress, flush] = progressEventDecorator(
2936
+ requestContentLength,
2937
+ progressEventReducer(asyncDecorator(onUploadProgress))
2938
+ );
2859
2939
 
2860
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2940
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2941
+ }
2861
2942
  }
2862
- }
2863
2943
 
2864
- if (!utils$1.isString(withCredentials)) {
2865
- withCredentials = withCredentials ? 'include' : 'omit';
2866
- }
2944
+ if (!utils$1.isString(withCredentials)) {
2945
+ withCredentials = withCredentials ? 'include' : 'omit';
2946
+ }
2867
2947
 
2868
- // Cloudflare Workers throws when credentials are defined
2869
- // see https://github.com/cloudflare/workerd/issues/902
2870
- const isCredentialsSupported = "credentials" in Request.prototype;
2871
- request = new Request(url, {
2872
- ...fetchOptions,
2873
- signal: composedSignal,
2874
- method: method.toUpperCase(),
2875
- headers: headers.normalize().toJSON(),
2876
- body: data,
2877
- duplex: "half",
2878
- credentials: isCredentialsSupported ? withCredentials : undefined
2879
- });
2948
+ // Cloudflare Workers throws when credentials are defined
2949
+ // see https://github.com/cloudflare/workerd/issues/902
2950
+ const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
2951
+
2952
+ const resolvedOptions = {
2953
+ ...fetchOptions,
2954
+ signal: composedSignal,
2955
+ method: method.toUpperCase(),
2956
+ headers: headers.normalize().toJSON(),
2957
+ body: data,
2958
+ duplex: "half",
2959
+ credentials: isCredentialsSupported ? withCredentials : undefined
2960
+ };
2880
2961
 
2881
- let response = await fetch(request);
2962
+ request = isRequestSupported && new Request(url, resolvedOptions);
2882
2963
 
2883
- const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2964
+ let response = await (isRequestSupported ? fetch(request, fetchOptions) : fetch(url, resolvedOptions));
2884
2965
 
2885
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2886
- const options = {};
2966
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2887
2967
 
2888
- ['status', 'statusText', 'headers'].forEach(prop => {
2889
- options[prop] = response[prop];
2890
- });
2968
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2969
+ const options = {};
2891
2970
 
2892
- const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2971
+ ['status', 'statusText', 'headers'].forEach(prop => {
2972
+ options[prop] = response[prop];
2973
+ });
2893
2974
 
2894
- const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2895
- responseContentLength,
2896
- progressEventReducer(asyncDecorator(onDownloadProgress), true)
2897
- ) || [];
2975
+ const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
2898
2976
 
2899
- response = new Response(
2900
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2901
- flush && flush();
2902
- unsubscribe && unsubscribe();
2903
- }),
2904
- options
2905
- );
2906
- }
2977
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
2978
+ responseContentLength,
2979
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
2980
+ ) || [];
2907
2981
 
2908
- responseType = responseType || 'text';
2982
+ response = new Response(
2983
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2984
+ flush && flush();
2985
+ unsubscribe && unsubscribe();
2986
+ }),
2987
+ options
2988
+ );
2989
+ }
2909
2990
 
2910
- let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2991
+ responseType = responseType || 'text';
2911
2992
 
2912
- !isStreamResponse && unsubscribe && unsubscribe();
2993
+ let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2913
2994
 
2914
- return await new Promise((resolve, reject) => {
2915
- settle(resolve, reject, {
2916
- data: responseData,
2917
- headers: AxiosHeaders$2.from(response.headers),
2918
- status: response.status,
2919
- statusText: response.statusText,
2920
- config,
2921
- request
2922
- });
2923
- })
2924
- } catch (err) {
2925
- unsubscribe && unsubscribe();
2926
-
2927
- if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
2928
- throw Object.assign(
2929
- new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request),
2930
- {
2931
- cause: err.cause || err
2932
- }
2933
- )
2995
+ !isStreamResponse && unsubscribe && unsubscribe();
2996
+
2997
+ return await new Promise((resolve, reject) => {
2998
+ settle(resolve, reject, {
2999
+ data: responseData,
3000
+ headers: AxiosHeaders$2.from(response.headers),
3001
+ status: response.status,
3002
+ statusText: response.statusText,
3003
+ config,
3004
+ request
3005
+ });
3006
+ })
3007
+ } catch (err) {
3008
+ unsubscribe && unsubscribe();
3009
+
3010
+ if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
3011
+ throw Object.assign(
3012
+ new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request),
3013
+ {
3014
+ cause: err.cause || err
3015
+ }
3016
+ )
3017
+ }
3018
+
3019
+ throw AxiosError$1.from(err, err && err.code, config, request);
2934
3020
  }
3021
+ }
3022
+ };
3023
+
3024
+ const seedCache = new Map();
3025
+
3026
+ const getFetch = (config) => {
3027
+ let env = utils$1.merge.call({
3028
+ skipUndefined: true
3029
+ }, globalFetchAPI, config ? config.env : null);
3030
+
3031
+ const {fetch, Request, Response} = env;
2935
3032
 
2936
- throw AxiosError$1.from(err, err && err.code, config, request);
3033
+ const seeds = [
3034
+ Request, Response, fetch
3035
+ ];
3036
+
3037
+ let len = seeds.length, i = len,
3038
+ seed, target, map = seedCache;
3039
+
3040
+ while (i--) {
3041
+ seed = seeds[i];
3042
+ target = map.get(seed);
3043
+
3044
+ target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
3045
+
3046
+ map = target;
2937
3047
  }
2938
- });
3048
+
3049
+ return target;
3050
+ };
3051
+
3052
+ getFetch();
2939
3053
 
2940
3054
  const knownAdapters = {
2941
3055
  http: httpAdapter,
2942
3056
  xhr: xhrAdapter,
2943
- fetch: fetchAdapter
3057
+ fetch: {
3058
+ get: getFetch,
3059
+ }
2944
3060
  };
2945
3061
 
2946
3062
  utils$1.forEach(knownAdapters, (fn, value) => {
@@ -2959,7 +3075,7 @@ const renderReason = (reason) => `- ${reason}`;
2959
3075
  const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
2960
3076
 
2961
3077
  const adapters = {
2962
- getAdapter: (adapters) => {
3078
+ getAdapter: (adapters, config) => {
2963
3079
  adapters = utils$1.isArray(adapters) ? adapters : [adapters];
2964
3080
 
2965
3081
  const {length} = adapters;
@@ -2982,7 +3098,7 @@ const adapters = {
2982
3098
  }
2983
3099
  }
2984
3100
 
2985
- if (adapter) {
3101
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
2986
3102
  break;
2987
3103
  }
2988
3104
 
@@ -3050,7 +3166,7 @@ function dispatchRequest(config) {
3050
3166
  config.headers.setContentType('application/x-www-form-urlencoded', false);
3051
3167
  }
3052
3168
 
3053
- const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
3169
+ const adapter = adapters.getAdapter(config.adapter || defaults$1.adapter, config);
3054
3170
 
3055
3171
  return adapter(config).then(function onAdapterResolution(response) {
3056
3172
  throwIfCancellationRequested(config);
@@ -3084,7 +3200,7 @@ function dispatchRequest(config) {
3084
3200
  });
3085
3201
  }
3086
3202
 
3087
- const VERSION$1 = "1.9.0";
3203
+ const VERSION$1 = "1.12.0";
3088
3204
 
3089
3205
  const validators$1 = {};
3090
3206
 
@@ -3323,8 +3439,8 @@ class Axios$1 {
3323
3439
 
3324
3440
  if (!synchronousRequestInterceptors) {
3325
3441
  const chain = [dispatchRequest.bind(this), undefined];
3326
- chain.unshift.apply(chain, requestInterceptorChain);
3327
- chain.push.apply(chain, responseInterceptorChain);
3442
+ chain.unshift(...requestInterceptorChain);
3443
+ chain.push(...responseInterceptorChain);
3328
3444
  len = chain.length;
3329
3445
 
3330
3446
  promise = Promise.resolve(config);