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