axios 1.7.6 → 1.7.8

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.6 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.8 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);
@@ -1150,7 +1150,7 @@ function encode(val) {
1150
1150
  *
1151
1151
  * @param {string} url The base of the url (e.g., http://www.google.com)
1152
1152
  * @param {object} [params] The params to be appended
1153
- * @param {?object} options
1153
+ * @param {?(object|Function)} options
1154
1154
  *
1155
1155
  * @returns {string} The formatted url
1156
1156
  */
@@ -1162,6 +1162,12 @@ function buildURL(url, params, options) {
1162
1162
 
1163
1163
  const _encode = options && options.encode || encode;
1164
1164
 
1165
+ if (utils$1.isFunction(options)) {
1166
+ options = {
1167
+ serialize: options
1168
+ };
1169
+ }
1170
+
1165
1171
  const serializeFn = options && options.serialize;
1166
1172
 
1167
1173
  let serializedParams;
@@ -2150,68 +2156,18 @@ const progressEventDecorator = (total, throttled) => {
2150
2156
 
2151
2157
  const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
2152
2158
 
2153
- const isURLSameOrigin = platform.hasStandardBrowserEnv ?
2154
-
2155
- // Standard browser envs have full support of the APIs needed to test
2156
- // whether the request URL is of the same origin as current location.
2157
- (function standardBrowserEnv() {
2158
- const msie = platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent);
2159
- const urlParsingNode = document.createElement('a');
2160
- let originURL;
2161
-
2162
- /**
2163
- * Parse a URL to discover its components
2164
- *
2165
- * @param {String} url The URL to be parsed
2166
- * @returns {Object}
2167
- */
2168
- function resolveURL(url) {
2169
- let href = url;
2170
-
2171
- if (msie) {
2172
- // IE needs attribute set twice to normalize properties
2173
- urlParsingNode.setAttribute('href', href);
2174
- href = urlParsingNode.href;
2175
- }
2176
-
2177
- urlParsingNode.setAttribute('href', href);
2178
-
2179
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2180
- return {
2181
- href: urlParsingNode.href,
2182
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2183
- host: urlParsingNode.host,
2184
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2185
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2186
- hostname: urlParsingNode.hostname,
2187
- port: urlParsingNode.port,
2188
- pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
2189
- urlParsingNode.pathname :
2190
- '/' + urlParsingNode.pathname
2191
- };
2192
- }
2193
-
2194
- originURL = resolveURL(window.location.href);
2159
+ const isURLSameOrigin = platform.hasStandardBrowserEnv ? ((origin, isMSIE) => (url) => {
2160
+ url = new URL(url, platform.origin);
2195
2161
 
2196
- /**
2197
- * Determine if a URL shares the same origin as the current location
2198
- *
2199
- * @param {String} requestURL The URL to test
2200
- * @returns {boolean} True if URL shares the same origin, otherwise false
2201
- */
2202
- return function isURLSameOrigin(requestURL) {
2203
- const parsed = (utils$1.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2204
- return (parsed.protocol === originURL.protocol &&
2205
- parsed.host === originURL.host);
2206
- };
2207
- })() :
2208
-
2209
- // Non standard browser envs (web workers, react-native) lack needed support.
2210
- (function nonStandardBrowserEnv() {
2211
- return function isURLSameOrigin() {
2212
- return true;
2213
- };
2214
- })();
2162
+ return (
2163
+ origin.protocol === url.protocol &&
2164
+ origin.host === url.host &&
2165
+ (isMSIE || origin.port === url.port)
2166
+ );
2167
+ })(
2168
+ new URL(platform.origin),
2169
+ platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
2170
+ ) : () => true;
2215
2171
 
2216
2172
  const cookies = platform.hasStandardBrowserEnv ?
2217
2173
 
@@ -2313,7 +2269,7 @@ function mergeConfig$1(config1, config2) {
2313
2269
  config2 = config2 || {};
2314
2270
  const config = {};
2315
2271
 
2316
- function getMergedValue(target, source, caseless) {
2272
+ function getMergedValue(target, source, prop, caseless) {
2317
2273
  if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2318
2274
  return utils$1.merge.call({caseless}, target, source);
2319
2275
  } else if (utils$1.isPlainObject(source)) {
@@ -2325,11 +2281,11 @@ function mergeConfig$1(config1, config2) {
2325
2281
  }
2326
2282
 
2327
2283
  // eslint-disable-next-line consistent-return
2328
- function mergeDeepProperties(a, b, caseless) {
2284
+ function mergeDeepProperties(a, b, prop , caseless) {
2329
2285
  if (!utils$1.isUndefined(b)) {
2330
- return getMergedValue(a, b, caseless);
2286
+ return getMergedValue(a, b, prop , caseless);
2331
2287
  } else if (!utils$1.isUndefined(a)) {
2332
- return getMergedValue(undefined, a, caseless);
2288
+ return getMergedValue(undefined, a, prop , caseless);
2333
2289
  }
2334
2290
  }
2335
2291
 
@@ -2387,7 +2343,7 @@ function mergeConfig$1(config1, config2) {
2387
2343
  socketPath: defaultToConfig2,
2388
2344
  responseEncoding: defaultToConfig2,
2389
2345
  validateStatus: mergeDirectKeys,
2390
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2346
+ headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2391
2347
  };
2392
2348
 
2393
2349
  utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
@@ -2697,14 +2653,34 @@ const streamChunk = function* (chunk, chunkSize) {
2697
2653
  }
2698
2654
  };
2699
2655
 
2700
- const readBytes = async function* (iterable, chunkSize, encode) {
2701
- for await (const chunk of iterable) {
2702
- yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
2656
+ const readBytes = async function* (iterable, chunkSize) {
2657
+ for await (const chunk of readStream(iterable)) {
2658
+ yield* streamChunk(chunk, chunkSize);
2703
2659
  }
2704
2660
  };
2705
2661
 
2706
- const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
2707
- const iterator = readBytes(stream, chunkSize, encode);
2662
+ const readStream = async function* (stream) {
2663
+ if (stream[Symbol.asyncIterator]) {
2664
+ yield* stream;
2665
+ return;
2666
+ }
2667
+
2668
+ const reader = stream.getReader();
2669
+ try {
2670
+ for (;;) {
2671
+ const {done, value} = await reader.read();
2672
+ if (done) {
2673
+ break;
2674
+ }
2675
+ yield value;
2676
+ }
2677
+ } finally {
2678
+ await reader.cancel();
2679
+ }
2680
+ };
2681
+
2682
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2683
+ const iterator = readBytes(stream, chunkSize);
2708
2684
 
2709
2685
  let bytes = 0;
2710
2686
  let done;
@@ -2884,7 +2860,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2884
2860
  progressEventReducer(asyncDecorator(onUploadProgress))
2885
2861
  );
2886
2862
 
2887
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
2863
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2888
2864
  }
2889
2865
  }
2890
2866
 
@@ -2927,7 +2903,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
2927
2903
  trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2928
2904
  flush && flush();
2929
2905
  unsubscribe && unsubscribe();
2930
- }, encodeText),
2906
+ }),
2931
2907
  options
2932
2908
  );
2933
2909
  }
@@ -3111,7 +3087,7 @@ function dispatchRequest(config) {
3111
3087
  });
3112
3088
  }
3113
3089
 
3114
- const VERSION$1 = "1.7.6";
3090
+ const VERSION$1 = "1.7.8";
3115
3091
 
3116
3092
  const validators$1 = {};
3117
3093
 
@@ -3162,6 +3138,14 @@ validators$1.transitional = function transitional(validator, version, message) {
3162
3138
  };
3163
3139
  };
3164
3140
 
3141
+ validators$1.spelling = function spelling(correctSpelling) {
3142
+ return (value, opt) => {
3143
+ // eslint-disable-next-line no-console
3144
+ console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
3145
+ return true;
3146
+ }
3147
+ };
3148
+
3165
3149
  /**
3166
3150
  * Assert object's properties type
3167
3151
  *
@@ -3231,9 +3215,9 @@ class Axios$1 {
3231
3215
  return await this._request(configOrUrl, config);
3232
3216
  } catch (err) {
3233
3217
  if (err instanceof Error) {
3234
- let dummy;
3218
+ let dummy = {};
3235
3219
 
3236
- Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
3220
+ Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
3237
3221
 
3238
3222
  // slice off the Error: ... line
3239
3223
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
@@ -3288,6 +3272,11 @@ class Axios$1 {
3288
3272
  }
3289
3273
  }
3290
3274
 
3275
+ validator.assertOptions(config, {
3276
+ baseUrl: validators.spelling('baseURL'),
3277
+ withXsrfToken: validators.spelling('withXSRFToken')
3278
+ }, true);
3279
+
3291
3280
  // Set config.method
3292
3281
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3293
3282