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