axios 1.7.4 → 1.7.6

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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/dist/esm/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.7.4 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.6 Copyright (c) 2024 Matt Zabriskie and contributors
2
2
  function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -787,7 +787,10 @@ function AxiosError$1(message, code, config, request, response) {
787
787
  code && (this.code = code);
788
788
  config && (this.config = config);
789
789
  request && (this.request = request);
790
- response && (this.response = response);
790
+ if (response) {
791
+ this.response = response;
792
+ this.status = response.status ? response.status : null;
793
+ }
791
794
  }
792
795
 
793
796
  utils$1.inherits(AxiosError$1, Error, {
@@ -807,7 +810,7 @@ utils$1.inherits(AxiosError$1, Error, {
807
810
  // Axios
808
811
  config: utils$1.toJSONObject(this.config),
809
812
  code: this.code,
810
- status: this.response && this.response.status ? this.response.status : null
813
+ status: this.status
811
814
  };
812
815
  }
813
816
  });
@@ -1275,6 +1278,8 @@ const platform$1 = {
1275
1278
 
1276
1279
  const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
1277
1280
 
1281
+ const _navigator = typeof navigator === 'object' && navigator || undefined;
1282
+
1278
1283
  /**
1279
1284
  * Determine if we're running in a standard browser environment
1280
1285
  *
@@ -1292,10 +1297,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
1292
1297
  *
1293
1298
  * @returns {boolean}
1294
1299
  */
1295
- const hasStandardBrowserEnv = (
1296
- (product) => {
1297
- return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
1298
- })(typeof navigator !== 'undefined' && navigator.product);
1300
+ const hasStandardBrowserEnv = hasBrowserEnv &&
1301
+ (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
1299
1302
 
1300
1303
  /**
1301
1304
  * Determine if we're running in a standard browser webWorker environment
@@ -1322,6 +1325,7 @@ const utils = /*#__PURE__*/Object.freeze({
1322
1325
  hasBrowserEnv: hasBrowserEnv,
1323
1326
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1324
1327
  hasStandardBrowserEnv: hasStandardBrowserEnv,
1328
+ navigator: _navigator,
1325
1329
  origin: origin
1326
1330
  });
1327
1331
 
@@ -2151,7 +2155,7 @@ const isURLSameOrigin = platform.hasStandardBrowserEnv ?
2151
2155
  // Standard browser envs have full support of the APIs needed to test
2152
2156
  // whether the request URL is of the same origin as current location.
2153
2157
  (function standardBrowserEnv() {
2154
- const msie = /(msie|trident)/i.test(navigator.userAgent);
2158
+ const msie = platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent);
2155
2159
  const urlParsingNode = document.createElement('a');
2156
2160
  let originURL;
2157
2161
 
@@ -2631,45 +2635,46 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2631
2635
  };
2632
2636
 
2633
2637
  const composeSignals = (signals, timeout) => {
2634
- let controller = new AbortController();
2638
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
2635
2639
 
2636
- let aborted;
2640
+ if (timeout || length) {
2641
+ let controller = new AbortController();
2637
2642
 
2638
- const onabort = function (cancel) {
2639
- if (!aborted) {
2640
- aborted = true;
2641
- unsubscribe();
2642
- const err = cancel instanceof Error ? cancel : this.reason;
2643
- controller.abort(err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err));
2644
- }
2645
- };
2643
+ let aborted;
2646
2644
 
2647
- let timer = timeout && setTimeout(() => {
2648
- onabort(new AxiosError$1(`timeout ${timeout} of ms exceeded`, AxiosError$1.ETIMEDOUT));
2649
- }, timeout);
2645
+ const onabort = function (reason) {
2646
+ if (!aborted) {
2647
+ aborted = true;
2648
+ unsubscribe();
2649
+ const err = reason instanceof Error ? reason : this.reason;
2650
+ controller.abort(err instanceof AxiosError$1 ? err : new CanceledError$1(err instanceof Error ? err.message : err));
2651
+ }
2652
+ };
2650
2653
 
2651
- const unsubscribe = () => {
2652
- if (signals) {
2653
- timer && clearTimeout(timer);
2654
+ let timer = timeout && setTimeout(() => {
2654
2655
  timer = null;
2655
- signals.forEach(signal => {
2656
- signal &&
2657
- (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
2658
- });
2659
- signals = null;
2660
- }
2661
- };
2656
+ onabort(new AxiosError$1(`timeout ${timeout} of ms exceeded`, AxiosError$1.ETIMEDOUT));
2657
+ }, timeout);
2658
+
2659
+ const unsubscribe = () => {
2660
+ if (signals) {
2661
+ timer && clearTimeout(timer);
2662
+ timer = null;
2663
+ signals.forEach(signal => {
2664
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
2665
+ });
2666
+ signals = null;
2667
+ }
2668
+ };
2662
2669
 
2663
- signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
2670
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
2664
2671
 
2665
- const {signal} = controller;
2672
+ const {signal} = controller;
2666
2673
 
2667
- signal.unsubscribe = unsubscribe;
2674
+ signal.unsubscribe = () => utils$1.asap(unsubscribe);
2668
2675
 
2669
- return [signal, () => {
2670
- timer && clearTimeout(timer);
2671
- timer = null;
2672
- }];
2676
+ return signal;
2677
+ }
2673
2678
  };
2674
2679
 
2675
2680
  const composeSignals$1 = composeSignals;
@@ -2802,7 +2807,11 @@ const getBodyLength = async (body) => {
2802
2807
  }
2803
2808
 
2804
2809
  if(utils$1.isSpecCompliantForm(body)) {
2805
- return (await new Request(body).arrayBuffer()).byteLength;
2810
+ const _request = new Request(platform.origin, {
2811
+ method: 'POST',
2812
+ body,
2813
+ });
2814
+ return (await _request.arrayBuffer()).byteLength;
2806
2815
  }
2807
2816
 
2808
2817
  if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
@@ -2842,18 +2851,13 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2842
2851
 
2843
2852
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2844
2853
 
2845
- let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
2846
- composeSignals$1([signal, cancelToken], timeout) : [];
2847
-
2848
- let finished, request;
2854
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2849
2855
 
2850
- const onFinish = () => {
2851
- !finished && setTimeout(() => {
2852
- composedSignal && composedSignal.unsubscribe();
2853
- });
2856
+ let request;
2854
2857
 
2855
- finished = true;
2856
- };
2858
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2859
+ composedSignal.unsubscribe();
2860
+ });
2857
2861
 
2858
2862
  let requestContentLength;
2859
2863
 
@@ -2888,6 +2892,9 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2888
2892
  withCredentials = withCredentials ? 'include' : 'omit';
2889
2893
  }
2890
2894
 
2895
+ // Cloudflare Workers throws when credentials are defined
2896
+ // see https://github.com/cloudflare/workerd/issues/902
2897
+ const isCredentialsSupported = "credentials" in Request.prototype;
2891
2898
  request = new Request(url, {
2892
2899
  ...fetchOptions,
2893
2900
  signal: composedSignal,
@@ -2895,14 +2902,14 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2895
2902
  headers: headers.normalize().toJSON(),
2896
2903
  body: data,
2897
2904
  duplex: "half",
2898
- credentials: withCredentials
2905
+ credentials: isCredentialsSupported ? withCredentials : undefined
2899
2906
  });
2900
2907
 
2901
2908
  let response = await fetch(request);
2902
2909
 
2903
2910
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2904
2911
 
2905
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
2912
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2906
2913
  const options = {};
2907
2914
 
2908
2915
  ['status', 'statusText', 'headers'].forEach(prop => {
@@ -2919,7 +2926,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2919
2926
  response = new Response(
2920
2927
  trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2921
2928
  flush && flush();
2922
- isStreamResponse && onFinish();
2929
+ unsubscribe && unsubscribe();
2923
2930
  }, encodeText),
2924
2931
  options
2925
2932
  );
@@ -2929,9 +2936,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2929
2936
 
2930
2937
  let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2931
2938
 
2932
- !isStreamResponse && onFinish();
2933
-
2934
- stopTimeout && stopTimeout();
2939
+ !isStreamResponse && unsubscribe && unsubscribe();
2935
2940
 
2936
2941
  return await new Promise((resolve, reject) => {
2937
2942
  settle(resolve, reject, {
@@ -2944,7 +2949,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2944
2949
  });
2945
2950
  })
2946
2951
  } catch (err) {
2947
- onFinish();
2952
+ unsubscribe && unsubscribe();
2948
2953
 
2949
2954
  if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
2950
2955
  throw Object.assign(
@@ -3106,7 +3111,7 @@ function dispatchRequest(config) {
3106
3111
  });
3107
3112
  }
3108
3113
 
3109
- const VERSION$1 = "1.7.4";
3114
+ const VERSION$1 = "1.7.6";
3110
3115
 
3111
3116
  const validators$1 = {};
3112
3117
 
@@ -3513,6 +3518,20 @@ class CancelToken$1 {
3513
3518
  }
3514
3519
  }
3515
3520
 
3521
+ toAbortSignal() {
3522
+ const controller = new AbortController();
3523
+
3524
+ const abort = (err) => {
3525
+ controller.abort(err);
3526
+ };
3527
+
3528
+ this.subscribe(abort);
3529
+
3530
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
3531
+
3532
+ return controller.signal;
3533
+ }
3534
+
3516
3535
  /**
3517
3536
  * Returns an object that contains a new `CancelToken` and a function that, when called,
3518
3537
  * cancels the `CancelToken`.