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.

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