axios 1.12.1 → 1.13.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/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Axios v1.12.1 Copyright (c) 2025 Matt Zabriskie and contributors */
1
+ /*! Axios v1.13.0 Copyright (c) 2025 Matt Zabriskie and contributors */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -668,6 +668,13 @@
668
668
  };
669
669
  }
670
670
 
671
+ /**
672
+ * Create a bound version of a function with a specified `this` context
673
+ *
674
+ * @param {Function} fn - The function to bind
675
+ * @param {*} thisArg - The value to be passed as the `this` parameter
676
+ * @returns {Function} A new function that will call the original function with the specified `this` context
677
+ */
671
678
  function bind(fn, thisArg) {
672
679
  return function wrap() {
673
680
  return fn.apply(thisArg, arguments);
@@ -1031,10 +1038,8 @@
1031
1038
  result[targetKey] = merge({}, val);
1032
1039
  } else if (isArray(val)) {
1033
1040
  result[targetKey] = val.slice();
1034
- } else {
1035
- if (!skipUndefined || !isUndefined(val)) {
1036
- result[targetKey] = val;
1037
- }
1041
+ } else if (!skipUndefined || !isUndefined(val)) {
1042
+ result[targetKey] = val;
1038
1043
  }
1039
1044
  };
1040
1045
  for (var i = 0, l = arguments.length; i < l; i++) {
@@ -1833,7 +1838,7 @@
1833
1838
  *
1834
1839
  * @param {Number} id The ID that was returned by `use`
1835
1840
  *
1836
- * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
1841
+ * @returns {void}
1837
1842
  */
1838
1843
  }, {
1839
1844
  key: "eject",
@@ -2704,20 +2709,33 @@
2704
2709
  var cookies = platform.hasStandardBrowserEnv ?
2705
2710
  // Standard browser envs support document.cookie
2706
2711
  {
2707
- write: function write(name, value, expires, path, domain, secure) {
2708
- var cookie = [name + '=' + encodeURIComponent(value)];
2709
- utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
2710
- utils$1.isString(path) && cookie.push('path=' + path);
2711
- utils$1.isString(domain) && cookie.push('domain=' + domain);
2712
- secure === true && cookie.push('secure');
2712
+ write: function write(name, value, expires, path, domain, secure, sameSite) {
2713
+ if (typeof document === 'undefined') return;
2714
+ var cookie = ["".concat(name, "=").concat(encodeURIComponent(value))];
2715
+ if (utils$1.isNumber(expires)) {
2716
+ cookie.push("expires=".concat(new Date(expires).toUTCString()));
2717
+ }
2718
+ if (utils$1.isString(path)) {
2719
+ cookie.push("path=".concat(path));
2720
+ }
2721
+ if (utils$1.isString(domain)) {
2722
+ cookie.push("domain=".concat(domain));
2723
+ }
2724
+ if (secure === true) {
2725
+ cookie.push('secure');
2726
+ }
2727
+ if (utils$1.isString(sameSite)) {
2728
+ cookie.push("SameSite=".concat(sameSite));
2729
+ }
2713
2730
  document.cookie = cookie.join('; ');
2714
2731
  },
2715
2732
  read: function read(name) {
2716
- var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2717
- return match ? decodeURIComponent(match[3]) : null;
2733
+ if (typeof document === 'undefined') return null;
2734
+ var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
2735
+ return match ? decodeURIComponent(match[1]) : null;
2718
2736
  },
2719
2737
  remove: function remove(name) {
2720
- this.write(name, '', Date.now() - 86400000);
2738
+ this.write(name, '', Date.now() - 86400000, '/');
2721
2739
  }
2722
2740
  } :
2723
2741
  // Non-standard browser env (web workers, react-native) lack needed support.
@@ -3353,11 +3371,9 @@
3353
3371
  var DEFAULT_CHUNK_SIZE = 64 * 1024;
3354
3372
  var isFunction = utils$1.isFunction;
3355
3373
  var globalFetchAPI = function (_ref) {
3356
- var fetch = _ref.fetch,
3357
- Request = _ref.Request,
3374
+ var Request = _ref.Request,
3358
3375
  Response = _ref.Response;
3359
3376
  return {
3360
- fetch: fetch,
3361
3377
  Request: Request,
3362
3378
  Response: Response
3363
3379
  };
@@ -3376,11 +3392,14 @@
3376
3392
  }
3377
3393
  };
3378
3394
  var factory = function factory(env) {
3379
- var _Object$assign = Object.assign({}, globalFetchAPI, env),
3380
- fetch = _Object$assign.fetch,
3381
- Request = _Object$assign.Request,
3382
- Response = _Object$assign.Response;
3383
- var isFetchSupported = isFunction(fetch);
3395
+ env = utils$1.merge.call({
3396
+ skipUndefined: true
3397
+ }, globalFetchAPI, env);
3398
+ var _env = env,
3399
+ envFetch = _env.fetch,
3400
+ Request = _env.Request,
3401
+ Response = _env.Response;
3402
+ var isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
3384
3403
  var isRequestSupported = isFunction(Request);
3385
3404
  var isResponseSupported = isFunction(Response);
3386
3405
  if (!isFetchSupported) {
@@ -3521,31 +3540,32 @@
3521
3540
  }();
3522
3541
  return /*#__PURE__*/function () {
3523
3542
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config) {
3524
- var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, composedSignal, request, unsubscribe, requestContentLength, _request, contentTypeHeader, _progressEventDecorat, _progressEventDecorat2, onProgress, flush, isCredentialsSupported, resolvedOptions, response, isStreamResponse, options, responseContentLength, _ref6, _ref7, _onProgress, _flush, responseData;
3543
+ var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _fetch, composedSignal, request, unsubscribe, requestContentLength, _request, contentTypeHeader, _progressEventDecorat, _progressEventDecorat2, onProgress, flush, isCredentialsSupported, resolvedOptions, response, isStreamResponse, options, responseContentLength, _ref6, _ref7, _onProgress, _flush, responseData;
3525
3544
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
3526
3545
  while (1) switch (_context4.prev = _context4.next) {
3527
3546
  case 0:
3528
3547
  _resolveConfig = resolveConfig(config), url = _resolveConfig.url, method = _resolveConfig.method, data = _resolveConfig.data, signal = _resolveConfig.signal, cancelToken = _resolveConfig.cancelToken, timeout = _resolveConfig.timeout, onDownloadProgress = _resolveConfig.onDownloadProgress, onUploadProgress = _resolveConfig.onUploadProgress, responseType = _resolveConfig.responseType, headers = _resolveConfig.headers, _resolveConfig$withCr = _resolveConfig.withCredentials, withCredentials = _resolveConfig$withCr === void 0 ? 'same-origin' : _resolveConfig$withCr, fetchOptions = _resolveConfig.fetchOptions;
3548
+ _fetch = envFetch || fetch;
3529
3549
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
3530
3550
  composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
3531
3551
  request = null;
3532
3552
  unsubscribe = composedSignal && composedSignal.unsubscribe && function () {
3533
3553
  composedSignal.unsubscribe();
3534
3554
  };
3535
- _context4.prev = 5;
3555
+ _context4.prev = 6;
3536
3556
  _context4.t0 = onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head';
3537
3557
  if (!_context4.t0) {
3538
- _context4.next = 12;
3558
+ _context4.next = 13;
3539
3559
  break;
3540
3560
  }
3541
- _context4.next = 10;
3561
+ _context4.next = 11;
3542
3562
  return resolveBodyLength(headers, data);
3543
- case 10:
3563
+ case 11:
3544
3564
  _context4.t1 = requestContentLength = _context4.sent;
3545
3565
  _context4.t0 = _context4.t1 !== 0;
3546
- case 12:
3566
+ case 13:
3547
3567
  if (!_context4.t0) {
3548
- _context4.next = 16;
3568
+ _context4.next = 17;
3549
3569
  break;
3550
3570
  }
3551
3571
  _request = new Request(url, {
@@ -3560,7 +3580,7 @@
3560
3580
  _progressEventDecorat = progressEventDecorator(requestContentLength, progressEventReducer(asyncDecorator(onUploadProgress))), _progressEventDecorat2 = _slicedToArray(_progressEventDecorat, 2), onProgress = _progressEventDecorat2[0], flush = _progressEventDecorat2[1];
3561
3581
  data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
3562
3582
  }
3563
- case 16:
3583
+ case 17:
3564
3584
  if (!utils$1.isString(withCredentials)) {
3565
3585
  withCredentials = withCredentials ? 'include' : 'omit';
3566
3586
  }
@@ -3577,9 +3597,9 @@
3577
3597
  credentials: isCredentialsSupported ? withCredentials : undefined
3578
3598
  });
3579
3599
  request = isRequestSupported && new Request(url, resolvedOptions);
3580
- _context4.next = 22;
3581
- return isRequestSupported ? fetch(request, fetchOptions) : fetch(url, resolvedOptions);
3582
- case 22:
3600
+ _context4.next = 23;
3601
+ return isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions);
3602
+ case 23:
3583
3603
  response = _context4.sent;
3584
3604
  isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
3585
3605
  if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
@@ -3595,12 +3615,12 @@
3595
3615
  }), options);
3596
3616
  }
3597
3617
  responseType = responseType || 'text';
3598
- _context4.next = 28;
3618
+ _context4.next = 29;
3599
3619
  return resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
3600
- case 28:
3620
+ case 29:
3601
3621
  responseData = _context4.sent;
3602
3622
  !isStreamResponse && unsubscribe && unsubscribe();
3603
- _context4.next = 32;
3623
+ _context4.next = 33;
3604
3624
  return new Promise(function (resolve, reject) {
3605
3625
  settle(resolve, reject, {
3606
3626
  data: responseData,
@@ -3611,26 +3631,26 @@
3611
3631
  request: request
3612
3632
  });
3613
3633
  });
3614
- case 32:
3634
+ case 33:
3615
3635
  return _context4.abrupt("return", _context4.sent);
3616
- case 35:
3617
- _context4.prev = 35;
3618
- _context4.t2 = _context4["catch"](5);
3636
+ case 36:
3637
+ _context4.prev = 36;
3638
+ _context4.t2 = _context4["catch"](6);
3619
3639
  unsubscribe && unsubscribe();
3620
3640
  if (!(_context4.t2 && _context4.t2.name === 'TypeError' && /Load failed|fetch/i.test(_context4.t2.message))) {
3621
- _context4.next = 40;
3641
+ _context4.next = 41;
3622
3642
  break;
3623
3643
  }
3624
3644
  throw Object.assign(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request), {
3625
3645
  cause: _context4.t2.cause || _context4.t2
3626
3646
  });
3627
- case 40:
3628
- throw AxiosError.from(_context4.t2, _context4.t2 && _context4.t2.code, config, request);
3629
3647
  case 41:
3648
+ throw AxiosError.from(_context4.t2, _context4.t2 && _context4.t2.code, config, request);
3649
+ case 42:
3630
3650
  case "end":
3631
3651
  return _context4.stop();
3632
3652
  }
3633
- }, _callee4, null, [[5, 35]]);
3653
+ }, _callee4, null, [[6, 36]]);
3634
3654
  }));
3635
3655
  return function (_x5) {
3636
3656
  return _ref5.apply(this, arguments);
@@ -3639,9 +3659,7 @@
3639
3659
  };
3640
3660
  var seedCache = new Map();
3641
3661
  var getFetch = function getFetch(config) {
3642
- var env = utils$1.merge.call({
3643
- skipUndefined: true
3644
- }, globalFetchAPI, config ? config.env : null);
3662
+ var env = config && config.env || {};
3645
3663
  var fetch = env.fetch,
3646
3664
  Request = env.Request,
3647
3665
  Response = env.Response;
@@ -3661,6 +3679,15 @@
3661
3679
  };
3662
3680
  getFetch();
3663
3681
 
3682
+ /**
3683
+ * Known adapters mapping.
3684
+ * Provides environment-specific adapters for Axios:
3685
+ * - `http` for Node.js
3686
+ * - `xhr` for browsers
3687
+ * - `fetch` for fetch API-based requests
3688
+ *
3689
+ * @type {Object<string, Function|Object>}
3690
+ */
3664
3691
  var knownAdapters = {
3665
3692
  http: httpAdapter,
3666
3693
  xhr: xhrAdapter,
@@ -3668,6 +3695,8 @@
3668
3695
  get: getFetch
3669
3696
  }
3670
3697
  };
3698
+
3699
+ // Assign adapter names for easier debugging and identification
3671
3700
  utils$1.forEach(knownAdapters, function (fn, value) {
3672
3701
  if (fn) {
3673
3702
  try {
@@ -3682,47 +3711,85 @@
3682
3711
  });
3683
3712
  }
3684
3713
  });
3714
+
3715
+ /**
3716
+ * Render a rejection reason string for unknown or unsupported adapters
3717
+ *
3718
+ * @param {string} reason
3719
+ * @returns {string}
3720
+ */
3685
3721
  var renderReason = function renderReason(reason) {
3686
3722
  return "- ".concat(reason);
3687
3723
  };
3724
+
3725
+ /**
3726
+ * Check if the adapter is resolved (function, null, or false)
3727
+ *
3728
+ * @param {Function|null|false} adapter
3729
+ * @returns {boolean}
3730
+ */
3688
3731
  var isResolvedHandle = function isResolvedHandle(adapter) {
3689
3732
  return utils$1.isFunction(adapter) || adapter === null || adapter === false;
3690
3733
  };
3691
- var adapters = {
3692
- getAdapter: function getAdapter(adapters, config) {
3693
- adapters = utils$1.isArray(adapters) ? adapters : [adapters];
3694
- var _adapters = adapters,
3695
- length = _adapters.length;
3696
- var nameOrAdapter;
3697
- var adapter;
3698
- var rejectedReasons = {};
3699
- for (var i = 0; i < length; i++) {
3700
- nameOrAdapter = adapters[i];
3701
- var id = void 0;
3702
- adapter = nameOrAdapter;
3703
- if (!isResolvedHandle(nameOrAdapter)) {
3704
- adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3705
- if (adapter === undefined) {
3706
- throw new AxiosError("Unknown adapter '".concat(id, "'"));
3707
- }
3708
- }
3709
- if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
3710
- break;
3734
+
3735
+ /**
3736
+ * Get the first suitable adapter from the provided list.
3737
+ * Tries each adapter in order until a supported one is found.
3738
+ * Throws an AxiosError if no adapter is suitable.
3739
+ *
3740
+ * @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
3741
+ * @param {Object} config - Axios request configuration
3742
+ * @throws {AxiosError} If no suitable adapter is available
3743
+ * @returns {Function} The resolved adapter function
3744
+ */
3745
+ function getAdapter(adapters, config) {
3746
+ adapters = utils$1.isArray(adapters) ? adapters : [adapters];
3747
+ var _adapters = adapters,
3748
+ length = _adapters.length;
3749
+ var nameOrAdapter;
3750
+ var adapter;
3751
+ var rejectedReasons = {};
3752
+ for (var i = 0; i < length; i++) {
3753
+ nameOrAdapter = adapters[i];
3754
+ var id = void 0;
3755
+ adapter = nameOrAdapter;
3756
+ if (!isResolvedHandle(nameOrAdapter)) {
3757
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3758
+ if (adapter === undefined) {
3759
+ throw new AxiosError("Unknown adapter '".concat(id, "'"));
3711
3760
  }
3712
- rejectedReasons[id || '#' + i] = adapter;
3713
3761
  }
3714
- if (!adapter) {
3715
- var reasons = Object.entries(rejectedReasons).map(function (_ref) {
3716
- var _ref2 = _slicedToArray(_ref, 2),
3717
- id = _ref2[0],
3718
- state = _ref2[1];
3719
- return "adapter ".concat(id, " ") + (state === false ? 'is not supported by the environment' : 'is not available in the build');
3720
- });
3721
- var s = length ? reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0]) : 'as no adapter specified';
3722
- throw new AxiosError("There is no suitable adapter to dispatch the request " + s, 'ERR_NOT_SUPPORT');
3762
+ if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
3763
+ break;
3723
3764
  }
3724
- return adapter;
3725
- },
3765
+ rejectedReasons[id || '#' + i] = adapter;
3766
+ }
3767
+ if (!adapter) {
3768
+ var reasons = Object.entries(rejectedReasons).map(function (_ref) {
3769
+ var _ref2 = _slicedToArray(_ref, 2),
3770
+ id = _ref2[0],
3771
+ state = _ref2[1];
3772
+ return "adapter ".concat(id, " ") + (state === false ? 'is not supported by the environment' : 'is not available in the build');
3773
+ });
3774
+ var s = length ? reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0]) : 'as no adapter specified';
3775
+ throw new AxiosError("There is no suitable adapter to dispatch the request " + s, 'ERR_NOT_SUPPORT');
3776
+ }
3777
+ return adapter;
3778
+ }
3779
+
3780
+ /**
3781
+ * Exports Axios adapters and utility to resolve an adapter
3782
+ */
3783
+ var adapters = {
3784
+ /**
3785
+ * Resolve an adapter from a list of adapter names or functions.
3786
+ * @type {Function}
3787
+ */
3788
+ getAdapter: getAdapter,
3789
+ /**
3790
+ * Exposes all known adapters
3791
+ * @type {Object<string, Function|Object>}
3792
+ */
3726
3793
  adapters: knownAdapters
3727
3794
  };
3728
3795
 
@@ -3780,7 +3847,7 @@
3780
3847
  });
3781
3848
  }
3782
3849
 
3783
- var VERSION = "1.12.1";
3850
+ var VERSION = "1.13.0";
3784
3851
 
3785
3852
  var validators$1 = {};
3786
3853
 
@@ -4023,7 +4090,6 @@
4023
4090
  }
4024
4091
  len = requestInterceptorChain.length;
4025
4092
  var newConfig = config;
4026
- i = 0;
4027
4093
  while (i < len) {
4028
4094
  var onFulfilled = requestInterceptorChain[i++];
4029
4095
  var onRejected = requestInterceptorChain[i++];
@@ -4317,7 +4383,13 @@
4317
4383
  InsufficientStorage: 507,
4318
4384
  LoopDetected: 508,
4319
4385
  NotExtended: 510,
4320
- NetworkAuthenticationRequired: 511
4386
+ NetworkAuthenticationRequired: 511,
4387
+ WebServerIsDown: 521,
4388
+ ConnectionTimedOut: 522,
4389
+ OriginIsUnreachable: 523,
4390
+ TimeoutOccurred: 524,
4391
+ SslHandshakeFailed: 525,
4392
+ InvalidSslCertificate: 526
4321
4393
  };
4322
4394
  Object.entries(HttpStatusCode).forEach(function (_ref) {
4323
4395
  var _ref2 = _slicedToArray(_ref, 2),