axios 1.7.2 → 1.7.3
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/CHANGELOG.md +15 -0
- package/dist/axios.js +169 -79
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +154 -78
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +153 -77
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +275 -237
- package/dist/node/axios.cjs.map +1 -1
- package/lib/adapters/fetch.js +31 -29
- package/lib/adapters/http.js +25 -15
- package/lib/adapters/xhr.js +22 -15
- package/lib/env/data.js +1 -1
- package/lib/helpers/AxiosTransformStream.js +3 -52
- package/lib/helpers/progressEventReducer.js +16 -4
- package/lib/helpers/throttle.js +29 -20
- package/lib/helpers/trackStream.js +25 -13
- package/lib/utils.js +33 -1
- package/package.json +1 -1
package/dist/esm/axios.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// Axios v1.7.
|
1
|
+
// Axios v1.7.3 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);
|
@@ -672,6 +672,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
|
|
672
672
|
const isThenable = (thing) =>
|
673
673
|
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
674
674
|
|
675
|
+
// original code
|
676
|
+
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
677
|
+
|
678
|
+
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
679
|
+
if (setImmediateSupported) {
|
680
|
+
return setImmediate;
|
681
|
+
}
|
682
|
+
|
683
|
+
return postMessageSupported ? ((token, callbacks) => {
|
684
|
+
_global.addEventListener("message", ({source, data}) => {
|
685
|
+
if (source === _global && data === token) {
|
686
|
+
callbacks.length && callbacks.shift()();
|
687
|
+
}
|
688
|
+
}, false);
|
689
|
+
|
690
|
+
return (cb) => {
|
691
|
+
callbacks.push(cb);
|
692
|
+
_global.postMessage(token, "*");
|
693
|
+
}
|
694
|
+
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
695
|
+
})(
|
696
|
+
typeof setImmediate === 'function',
|
697
|
+
isFunction(_global.postMessage)
|
698
|
+
);
|
699
|
+
|
700
|
+
const asap = typeof queueMicrotask !== 'undefined' ?
|
701
|
+
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
702
|
+
|
703
|
+
// *********************
|
704
|
+
|
675
705
|
const utils$1 = {
|
676
706
|
isArray,
|
677
707
|
isArrayBuffer,
|
@@ -727,7 +757,9 @@ const utils$1 = {
|
|
727
757
|
isSpecCompliantForm,
|
728
758
|
toJSONObject,
|
729
759
|
isAsyncFn,
|
730
|
-
isThenable
|
760
|
+
isThenable,
|
761
|
+
setImmediate: _setImmediate,
|
762
|
+
asap
|
731
763
|
};
|
732
764
|
|
733
765
|
/**
|
@@ -2038,28 +2070,39 @@ function speedometer(samplesCount, min) {
|
|
2038
2070
|
*/
|
2039
2071
|
function throttle(fn, freq) {
|
2040
2072
|
let timestamp = 0;
|
2041
|
-
|
2042
|
-
let
|
2043
|
-
|
2044
|
-
|
2073
|
+
let threshold = 1000 / freq;
|
2074
|
+
let lastArgs;
|
2075
|
+
let timer;
|
2076
|
+
|
2077
|
+
const invoke = (args, now = Date.now()) => {
|
2078
|
+
timestamp = now;
|
2079
|
+
lastArgs = null;
|
2080
|
+
if (timer) {
|
2081
|
+
clearTimeout(timer);
|
2082
|
+
timer = null;
|
2083
|
+
}
|
2084
|
+
fn.apply(null, args);
|
2085
|
+
};
|
2045
2086
|
|
2087
|
+
const throttled = (...args) => {
|
2046
2088
|
const now = Date.now();
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2089
|
+
const passed = now - timestamp;
|
2090
|
+
if ( passed >= threshold) {
|
2091
|
+
invoke(args, now);
|
2092
|
+
} else {
|
2093
|
+
lastArgs = args;
|
2094
|
+
if (!timer) {
|
2095
|
+
timer = setTimeout(() => {
|
2096
|
+
timer = null;
|
2097
|
+
invoke(lastArgs);
|
2098
|
+
}, threshold - passed);
|
2051
2099
|
}
|
2052
|
-
timestamp = now;
|
2053
|
-
return fn.apply(null, arguments);
|
2054
|
-
}
|
2055
|
-
if (!timer) {
|
2056
|
-
timer = setTimeout(() => {
|
2057
|
-
timer = null;
|
2058
|
-
timestamp = Date.now();
|
2059
|
-
return fn.apply(null, arguments);
|
2060
|
-
}, threshold - (now - timestamp));
|
2061
2100
|
}
|
2062
2101
|
};
|
2102
|
+
|
2103
|
+
const flush = () => lastArgs && invoke(lastArgs);
|
2104
|
+
|
2105
|
+
return [throttled, flush];
|
2063
2106
|
}
|
2064
2107
|
|
2065
2108
|
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
@@ -2083,15 +2126,26 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
|
2083
2126
|
rate: rate ? rate : undefined,
|
2084
2127
|
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
2085
2128
|
event: e,
|
2086
|
-
lengthComputable: total != null
|
2129
|
+
lengthComputable: total != null,
|
2130
|
+
[isDownloadStream ? 'download' : 'upload']: true
|
2087
2131
|
};
|
2088
2132
|
|
2089
|
-
data[isDownloadStream ? 'download' : 'upload'] = true;
|
2090
|
-
|
2091
2133
|
listener(data);
|
2092
2134
|
}, freq);
|
2093
2135
|
};
|
2094
2136
|
|
2137
|
+
const progressEventDecorator = (total, throttled) => {
|
2138
|
+
const lengthComputable = total != null;
|
2139
|
+
|
2140
|
+
return [(loaded) => throttled[0]({
|
2141
|
+
lengthComputable,
|
2142
|
+
total,
|
2143
|
+
loaded
|
2144
|
+
}), throttled[1]];
|
2145
|
+
};
|
2146
|
+
|
2147
|
+
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
2148
|
+
|
2095
2149
|
const isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
2096
2150
|
|
2097
2151
|
// Standard browser envs have full support of the APIs needed to test
|
@@ -2396,16 +2450,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2396
2450
|
const _config = resolveConfig(config);
|
2397
2451
|
let requestData = _config.data;
|
2398
2452
|
const requestHeaders = AxiosHeaders$2.from(_config.headers).normalize();
|
2399
|
-
let {responseType} = _config;
|
2453
|
+
let {responseType, onUploadProgress, onDownloadProgress} = _config;
|
2400
2454
|
let onCanceled;
|
2455
|
+
let uploadThrottled, downloadThrottled;
|
2456
|
+
let flushUpload, flushDownload;
|
2457
|
+
|
2401
2458
|
function done() {
|
2402
|
-
|
2403
|
-
|
2404
|
-
}
|
2459
|
+
flushUpload && flushUpload(); // flush events
|
2460
|
+
flushDownload && flushDownload(); // flush events
|
2405
2461
|
|
2406
|
-
|
2407
|
-
|
2408
|
-
|
2462
|
+
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
2463
|
+
|
2464
|
+
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
2409
2465
|
}
|
2410
2466
|
|
2411
2467
|
let request = new XMLHttpRequest();
|
@@ -2475,7 +2531,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2475
2531
|
return;
|
2476
2532
|
}
|
2477
2533
|
|
2478
|
-
reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED,
|
2534
|
+
reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED, config, request));
|
2479
2535
|
|
2480
2536
|
// Clean up request
|
2481
2537
|
request = null;
|
@@ -2485,7 +2541,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2485
2541
|
request.onerror = function handleError() {
|
2486
2542
|
// Real errors are hidden from us by the browser
|
2487
2543
|
// onerror should only fire if it's a network error
|
2488
|
-
reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK,
|
2544
|
+
reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request));
|
2489
2545
|
|
2490
2546
|
// Clean up request
|
2491
2547
|
request = null;
|
@@ -2501,7 +2557,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2501
2557
|
reject(new AxiosError$1(
|
2502
2558
|
timeoutErrorMessage,
|
2503
2559
|
transitional.clarifyTimeoutError ? AxiosError$1.ETIMEDOUT : AxiosError$1.ECONNABORTED,
|
2504
|
-
|
2560
|
+
config,
|
2505
2561
|
request));
|
2506
2562
|
|
2507
2563
|
// Clean up request
|
@@ -2529,13 +2585,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2529
2585
|
}
|
2530
2586
|
|
2531
2587
|
// Handle progress if needed
|
2532
|
-
if (
|
2533
|
-
|
2588
|
+
if (onDownloadProgress) {
|
2589
|
+
([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
|
2590
|
+
request.addEventListener('progress', downloadThrottled);
|
2534
2591
|
}
|
2535
2592
|
|
2536
2593
|
// Not all browsers support upload events
|
2537
|
-
if (
|
2538
|
-
|
2594
|
+
if (onUploadProgress && request.upload) {
|
2595
|
+
([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
|
2596
|
+
|
2597
|
+
request.upload.addEventListener('progress', uploadThrottled);
|
2598
|
+
|
2599
|
+
request.upload.addEventListener('loadend', flushUpload);
|
2539
2600
|
}
|
2540
2601
|
|
2541
2602
|
if (_config.cancelToken || _config.signal) {
|
@@ -2641,25 +2702,38 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
|
2641
2702
|
const iterator = readBytes(stream, chunkSize, encode);
|
2642
2703
|
|
2643
2704
|
let bytes = 0;
|
2705
|
+
let done;
|
2706
|
+
let _onFinish = (e) => {
|
2707
|
+
if (!done) {
|
2708
|
+
done = true;
|
2709
|
+
onFinish && onFinish(e);
|
2710
|
+
}
|
2711
|
+
};
|
2644
2712
|
|
2645
2713
|
return new ReadableStream({
|
2646
|
-
type: 'bytes',
|
2647
|
-
|
2648
2714
|
async pull(controller) {
|
2649
|
-
|
2715
|
+
try {
|
2716
|
+
const {done, value} = await iterator.next();
|
2650
2717
|
|
2651
|
-
|
2652
|
-
|
2653
|
-
|
2654
|
-
|
2655
|
-
|
2718
|
+
if (done) {
|
2719
|
+
_onFinish();
|
2720
|
+
controller.close();
|
2721
|
+
return;
|
2722
|
+
}
|
2656
2723
|
|
2657
|
-
|
2658
|
-
|
2659
|
-
|
2724
|
+
let len = value.byteLength;
|
2725
|
+
if (onProgress) {
|
2726
|
+
let loadedBytes = bytes += len;
|
2727
|
+
onProgress(loadedBytes);
|
2728
|
+
}
|
2729
|
+
controller.enqueue(new Uint8Array(value));
|
2730
|
+
} catch (err) {
|
2731
|
+
_onFinish(err);
|
2732
|
+
throw err;
|
2733
|
+
}
|
2660
2734
|
},
|
2661
2735
|
cancel(reason) {
|
2662
|
-
|
2736
|
+
_onFinish(reason);
|
2663
2737
|
return iterator.return();
|
2664
2738
|
}
|
2665
2739
|
}, {
|
@@ -2667,15 +2741,6 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
|
2667
2741
|
})
|
2668
2742
|
};
|
2669
2743
|
|
2670
|
-
const fetchProgressDecorator = (total, fn) => {
|
2671
|
-
const lengthComputable = total != null;
|
2672
|
-
return (loaded) => setTimeout(() => fn({
|
2673
|
-
lengthComputable,
|
2674
|
-
total,
|
2675
|
-
loaded
|
2676
|
-
}));
|
2677
|
-
};
|
2678
|
-
|
2679
2744
|
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
2680
2745
|
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
2681
2746
|
|
@@ -2685,7 +2750,15 @@ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
2685
2750
|
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
2686
2751
|
);
|
2687
2752
|
|
2688
|
-
const
|
2753
|
+
const test = (fn, ...args) => {
|
2754
|
+
try {
|
2755
|
+
return !!fn(...args);
|
2756
|
+
} catch (e) {
|
2757
|
+
return false
|
2758
|
+
}
|
2759
|
+
};
|
2760
|
+
|
2761
|
+
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
2689
2762
|
let duplexAccessed = false;
|
2690
2763
|
|
2691
2764
|
const hasContentType = new Request(platform.origin, {
|
@@ -2698,17 +2771,13 @@ const supportsRequestStream = isReadableStreamSupported && (() => {
|
|
2698
2771
|
}).headers.has('Content-Type');
|
2699
2772
|
|
2700
2773
|
return duplexAccessed && !hasContentType;
|
2701
|
-
})
|
2774
|
+
});
|
2702
2775
|
|
2703
2776
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
2704
2777
|
|
2705
|
-
const supportsResponseStream = isReadableStreamSupported &&
|
2706
|
-
|
2707
|
-
|
2708
|
-
} catch(err) {
|
2709
|
-
// return undefined
|
2710
|
-
}
|
2711
|
-
})();
|
2778
|
+
const supportsResponseStream = isReadableStreamSupported &&
|
2779
|
+
test(() => utils$1.isReadableStream(new Response('').body));
|
2780
|
+
|
2712
2781
|
|
2713
2782
|
const resolvers = {
|
2714
2783
|
stream: supportsResponseStream && ((res) => res.body)
|
@@ -2736,7 +2805,7 @@ const getBodyLength = async (body) => {
|
|
2736
2805
|
return (await new Request(body).arrayBuffer()).byteLength;
|
2737
2806
|
}
|
2738
2807
|
|
2739
|
-
if(utils$1.isArrayBufferView(body)) {
|
2808
|
+
if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
2740
2809
|
return body.byteLength;
|
2741
2810
|
}
|
2742
2811
|
|
@@ -2806,15 +2875,17 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
2806
2875
|
}
|
2807
2876
|
|
2808
2877
|
if (_request.body) {
|
2809
|
-
|
2878
|
+
const [onProgress, flush] = progressEventDecorator(
|
2810
2879
|
requestContentLength,
|
2811
|
-
progressEventReducer(onUploadProgress)
|
2812
|
-
)
|
2880
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
2881
|
+
);
|
2882
|
+
|
2883
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
2813
2884
|
}
|
2814
2885
|
}
|
2815
2886
|
|
2816
2887
|
if (!utils$1.isString(withCredentials)) {
|
2817
|
-
withCredentials = withCredentials ? '
|
2888
|
+
withCredentials = withCredentials ? 'include' : 'omit';
|
2818
2889
|
}
|
2819
2890
|
|
2820
2891
|
request = new Request(url, {
|
@@ -2824,7 +2895,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
2824
2895
|
headers: headers.normalize().toJSON(),
|
2825
2896
|
body: data,
|
2826
2897
|
duplex: "half",
|
2827
|
-
withCredentials
|
2898
|
+
credentials: withCredentials
|
2828
2899
|
});
|
2829
2900
|
|
2830
2901
|
let response = await fetch(request);
|
@@ -2840,11 +2911,16 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
|
2840
2911
|
|
2841
2912
|
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
2842
2913
|
|
2914
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
2915
|
+
responseContentLength,
|
2916
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
2917
|
+
) || [];
|
2918
|
+
|
2843
2919
|
response = new Response(
|
2844
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE,
|
2845
|
-
|
2846
|
-
|
2847
|
-
|
2920
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
2921
|
+
flush && flush();
|
2922
|
+
isStreamResponse && onFinish();
|
2923
|
+
}, encodeText),
|
2848
2924
|
options
|
2849
2925
|
);
|
2850
2926
|
}
|
@@ -3030,7 +3106,7 @@ function dispatchRequest(config) {
|
|
3030
3106
|
});
|
3031
3107
|
}
|
3032
3108
|
|
3033
|
-
const VERSION$1 = "1.7.
|
3109
|
+
const VERSION$1 = "1.7.3";
|
3034
3110
|
|
3035
3111
|
const validators$1 = {};
|
3036
3112
|
|