axios 1.7.0-beta.0 → 1.7.0-beta.2

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.

@@ -1,4 +1,4 @@
1
- // Axios v1.7.0-beta.0 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.0-beta.2 Copyright (c) 2024 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  function bind(fn, thisArg) {
@@ -2681,8 +2681,9 @@ const fetchProgressDecorator = (total, fn) => {
2681
2681
  };
2682
2682
 
2683
2683
  const isFetchSupported = typeof fetch !== 'undefined';
2684
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined';
2684
2685
 
2685
- const supportsRequestStreams = isFetchSupported && (() => {
2686
+ const supportsRequestStream = isReadableStreamSupported && (() => {
2686
2687
  let duplexAccessed = false;
2687
2688
 
2688
2689
  const hasContentType = new Request(platform.origin, {
@@ -2699,17 +2700,32 @@ const supportsRequestStreams = isFetchSupported && (() => {
2699
2700
 
2700
2701
  const DEFAULT_CHUNK_SIZE = 64 * 1024;
2701
2702
 
2703
+ const supportsResponseStream = isReadableStreamSupported && !!(()=> {
2704
+ try {
2705
+ return utils$1.isReadableStream(new Response('').body);
2706
+ } catch(err) {
2707
+ // return undefined
2708
+ }
2709
+ })();
2710
+
2702
2711
  const resolvers = {
2703
- stream: (res) => res.body
2712
+ stream: supportsResponseStream && ((res) => res.body)
2704
2713
  };
2705
2714
 
2706
- isFetchSupported && ['text', 'arrayBuffer', 'blob', 'formData'].forEach(type => [
2707
- resolvers[type] = utils$1.isFunction(Response.prototype[type]) ? (res) => res[type]() : (_, config) => {
2708
- throw new AxiosError(`Response type ${type} is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2709
- }
2710
- ]);
2715
+ isFetchSupported && (((res) => {
2716
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2717
+ !resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
2718
+ (_, config) => {
2719
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2720
+ });
2721
+ });
2722
+ })(new Response));
2711
2723
 
2712
2724
  const getBodyLength = async (body) => {
2725
+ if (body == null) {
2726
+ return 0;
2727
+ }
2728
+
2713
2729
  if(utils$1.isBlob(body)) {
2714
2730
  return body.size;
2715
2731
  }
@@ -2737,7 +2753,7 @@ const resolveBodyLength = async (headers, body) => {
2737
2753
  return length == null ? getBodyLength(body) : length;
2738
2754
  };
2739
2755
 
2740
- var fetchAdapter = async (config) => {
2756
+ var fetchAdapter = isFetchSupported && (async (config) => {
2741
2757
  let {
2742
2758
  url,
2743
2759
  method,
@@ -2768,12 +2784,15 @@ var fetchAdapter = async (config) => {
2768
2784
  finished = true;
2769
2785
  };
2770
2786
 
2771
- try {
2772
- if (onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head') {
2773
- let requestContentLength = await resolveBodyLength(headers, data);
2787
+ let requestContentLength;
2774
2788
 
2789
+ try {
2790
+ if (
2791
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
2792
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
2793
+ ) {
2775
2794
  let _request = new Request(url, {
2776
- method,
2795
+ method: 'POST',
2777
2796
  body: data,
2778
2797
  duplex: "half"
2779
2798
  });
@@ -2784,10 +2803,12 @@ var fetchAdapter = async (config) => {
2784
2803
  headers.setContentType(contentTypeHeader);
2785
2804
  }
2786
2805
 
2787
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
2788
- requestContentLength,
2789
- progressEventReducer(onUploadProgress)
2790
- ));
2806
+ if (_request.body) {
2807
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
2808
+ requestContentLength,
2809
+ progressEventReducer(onUploadProgress)
2810
+ ));
2811
+ }
2791
2812
  }
2792
2813
 
2793
2814
  if (!utils$1.isString(withCredentials)) {
@@ -2797,7 +2818,7 @@ var fetchAdapter = async (config) => {
2797
2818
  request = new Request(url, {
2798
2819
  ...fetchOptions,
2799
2820
  signal: composedSignal,
2800
- method,
2821
+ method: method.toUpperCase(),
2801
2822
  headers: headers.normalize().toJSON(),
2802
2823
  body: data,
2803
2824
  duplex: "half",
@@ -2808,10 +2829,10 @@ var fetchAdapter = async (config) => {
2808
2829
 
2809
2830
  const isStreamResponse = responseType === 'stream' || responseType === 'response';
2810
2831
 
2811
- if (onDownloadProgress || isStreamResponse) {
2832
+ if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
2812
2833
  const options = {};
2813
2834
 
2814
- Object.getOwnPropertyNames(response).forEach(prop => {
2835
+ ['status', 'statusText', 'headers'].forEach(prop => {
2815
2836
  options[prop] = response[prop];
2816
2837
  });
2817
2838
 
@@ -2847,15 +2868,18 @@ var fetchAdapter = async (config) => {
2847
2868
  } catch (err) {
2848
2869
  onFinish();
2849
2870
 
2850
- let {code} = err;
2851
-
2852
- if (err.name === 'NetworkError') {
2853
- code = AxiosError.ERR_NETWORK;
2871
+ if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
2872
+ throw Object.assign(
2873
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
2874
+ {
2875
+ cause: err.cause || err
2876
+ }
2877
+ )
2854
2878
  }
2855
2879
 
2856
- throw AxiosError.from(err, code, config, request);
2880
+ throw AxiosError.from(err, err && err.code, config, request);
2857
2881
  }
2858
- };
2882
+ });
2859
2883
 
2860
2884
  const knownAdapters = {
2861
2885
  http: httpAdapter,
@@ -3004,7 +3028,7 @@ function dispatchRequest(config) {
3004
3028
  });
3005
3029
  }
3006
3030
 
3007
- const VERSION = "1.7.0-beta.0";
3031
+ const VERSION = "1.7.0-beta.2";
3008
3032
 
3009
3033
  const validators$1 = {};
3010
3034
 
@@ -3130,12 +3154,15 @@ class Axios {
3130
3154
 
3131
3155
  // slice off the Error: ... line
3132
3156
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
3133
-
3134
- if (!err.stack) {
3135
- err.stack = stack;
3136
- // match without the 2 top stack lines
3137
- } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3138
- err.stack += '\n' + stack;
3157
+ try {
3158
+ if (!err.stack) {
3159
+ err.stack = stack;
3160
+ // match without the 2 top stack lines
3161
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3162
+ err.stack += '\n' + stack;
3163
+ }
3164
+ } catch (e) {
3165
+ // ignore the case where "stack" is an un-writable property
3139
3166
  }
3140
3167
  }
3141
3168