axios 1.4.0 → 1.6.0

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.4.0 Copyright (c) 2023 Matt Zabriskie and contributors
1
+ // Axios v1.6.0 Copyright (c) 2023 Matt Zabriskie and contributors
2
2
  function bind(fn, thisArg) {
3
3
  return function wrap() {
4
4
  return fn.apply(thisArg, arguments);
@@ -543,8 +543,9 @@ const reduceDescriptors = (obj, reducer) => {
543
543
  const reducedDescriptors = {};
544
544
 
545
545
  forEach(descriptors, (descriptor, name) => {
546
- if (reducer(descriptor, name, obj) !== false) {
547
- reducedDescriptors[name] = descriptor;
546
+ let ret;
547
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
548
+ reducedDescriptors[name] = ret || descriptor;
548
549
  }
549
550
  });
550
551
 
@@ -1386,10 +1387,6 @@ function formDataToJSON(formData) {
1386
1387
  return null;
1387
1388
  }
1388
1389
 
1389
- const DEFAULT_CONTENT_TYPE = {
1390
- 'Content-Type': undefined
1391
- };
1392
-
1393
1390
  /**
1394
1391
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1395
1392
  * of the input
@@ -1528,19 +1525,16 @@ const defaults = {
1528
1525
 
1529
1526
  headers: {
1530
1527
  common: {
1531
- 'Accept': 'application/json, text/plain, */*'
1528
+ 'Accept': 'application/json, text/plain, */*',
1529
+ 'Content-Type': undefined
1532
1530
  }
1533
1531
  }
1534
1532
  };
1535
1533
 
1536
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1534
+ utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
1537
1535
  defaults.headers[method] = {};
1538
1536
  });
1539
1537
 
1540
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1541
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1542
- });
1543
-
1544
1538
  const defaults$1 = defaults;
1545
1539
 
1546
1540
  // RawAxiosHeaders whose duplicates are ignored by node
@@ -1874,7 +1868,17 @@ class AxiosHeaders$1 {
1874
1868
 
1875
1869
  AxiosHeaders$1.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
1876
1870
 
1877
- utils.freezeMethods(AxiosHeaders$1.prototype);
1871
+ // reserved names hotfix
1872
+ utils.reduceDescriptors(AxiosHeaders$1.prototype, ({value}, key) => {
1873
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
1874
+ return {
1875
+ get: () => value,
1876
+ set(headerValue) {
1877
+ this[mapped] = headerValue;
1878
+ }
1879
+ }
1880
+ });
1881
+
1878
1882
  utils.freezeMethods(AxiosHeaders$1);
1879
1883
 
1880
1884
  const AxiosHeaders$2 = AxiosHeaders$1;
@@ -2209,11 +2213,16 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2209
2213
  }
2210
2214
  }
2211
2215
 
2216
+ let contentType;
2217
+
2212
2218
  if (utils.isFormData(requestData)) {
2213
2219
  if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
2214
2220
  requestHeaders.setContentType(false); // Let the browser set it
2215
- } else {
2216
- requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
2221
+ } else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
2222
+ requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
2223
+ } else if(utils.isString(contentType = requestHeaders.getContentType())){
2224
+ // fix semicolon duplication issue for ReactNative FormData implementation
2225
+ requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'));
2217
2226
  }
2218
2227
  }
2219
2228
 
@@ -2331,8 +2340,8 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2331
2340
  // Specifically not if we're in a web worker, or react-native.
2332
2341
  if (platform.isStandardBrowserEnv) {
2333
2342
  // Add xsrf header
2334
- const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
2335
- && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2343
+ // regarding CVE-2023-45857 config.withCredentials condition was removed temporarily
2344
+ const xsrfValue = isURLSameOrigin(fullPath) && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2336
2345
 
2337
2346
  if (xsrfValue) {
2338
2347
  requestHeaders.set(config.xsrfHeaderName, xsrfValue);
@@ -2406,7 +2415,7 @@ const knownAdapters = {
2406
2415
  };
2407
2416
 
2408
2417
  utils.forEach(knownAdapters, (fn, value) => {
2409
- if(fn) {
2418
+ if (fn) {
2410
2419
  try {
2411
2420
  Object.defineProperty(fn, 'name', {value});
2412
2421
  } catch (e) {
@@ -2416,6 +2425,10 @@ utils.forEach(knownAdapters, (fn, value) => {
2416
2425
  }
2417
2426
  });
2418
2427
 
2428
+ const renderReason = (reason) => `- ${reason}`;
2429
+
2430
+ const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
2431
+
2419
2432
  const adapters = {
2420
2433
  getAdapter: (adapters) => {
2421
2434
  adapters = utils.isArray(adapters) ? adapters : [adapters];
@@ -2424,30 +2437,44 @@ const adapters = {
2424
2437
  let nameOrAdapter;
2425
2438
  let adapter;
2426
2439
 
2440
+ const rejectedReasons = {};
2441
+
2427
2442
  for (let i = 0; i < length; i++) {
2428
2443
  nameOrAdapter = adapters[i];
2429
- if((adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
2444
+ let id;
2445
+
2446
+ adapter = nameOrAdapter;
2447
+
2448
+ if (!isResolvedHandle(nameOrAdapter)) {
2449
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
2450
+
2451
+ if (adapter === undefined) {
2452
+ throw new AxiosError$1(`Unknown adapter '${id}'`);
2453
+ }
2454
+ }
2455
+
2456
+ if (adapter) {
2430
2457
  break;
2431
2458
  }
2459
+
2460
+ rejectedReasons[id || '#' + i] = adapter;
2432
2461
  }
2433
2462
 
2434
2463
  if (!adapter) {
2435
- if (adapter === false) {
2436
- throw new AxiosError$1(
2437
- `Adapter ${nameOrAdapter} is not supported by the environment`,
2438
- 'ERR_NOT_SUPPORT'
2464
+
2465
+ const reasons = Object.entries(rejectedReasons)
2466
+ .map(([id, state]) => `adapter ${id} ` +
2467
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
2439
2468
  );
2440
- }
2441
2469
 
2442
- throw new Error(
2443
- utils.hasOwnProp(knownAdapters, nameOrAdapter) ?
2444
- `Adapter '${nameOrAdapter}' is not available in the build` :
2445
- `Unknown adapter '${nameOrAdapter}'`
2446
- );
2447
- }
2470
+ let s = length ?
2471
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
2472
+ 'as no adapter specified';
2448
2473
 
2449
- if (!utils.isFunction(adapter)) {
2450
- throw new TypeError('adapter is not a function');
2474
+ throw new AxiosError$1(
2475
+ `There is no suitable adapter to dispatch the request ` + s,
2476
+ 'ERR_NOT_SUPPORT'
2477
+ );
2451
2478
  }
2452
2479
 
2453
2480
  return adapter;
@@ -2629,7 +2656,7 @@ function mergeConfig$1(config1, config2) {
2629
2656
  return config;
2630
2657
  }
2631
2658
 
2632
- const VERSION$1 = "1.4.0";
2659
+ const VERSION$1 = "1.6.0";
2633
2660
 
2634
2661
  const validators$1 = {};
2635
2662
 
@@ -2782,15 +2809,13 @@ class Axios$1 {
2782
2809
  // Set config.method
2783
2810
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
2784
2811
 
2785
- let contextHeaders;
2786
-
2787
2812
  // Flatten headers
2788
- contextHeaders = headers && utils.merge(
2813
+ let contextHeaders = headers && utils.merge(
2789
2814
  headers.common,
2790
2815
  headers[config.method]
2791
2816
  );
2792
2817
 
2793
- contextHeaders && utils.forEach(
2818
+ headers && utils.forEach(
2794
2819
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
2795
2820
  (method) => {
2796
2821
  delete headers[method];
@@ -3200,6 +3225,8 @@ axios.AxiosHeaders = AxiosHeaders$2;
3200
3225
 
3201
3226
  axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3202
3227
 
3228
+ axios.getAdapter = adapters.getAdapter;
3229
+
3203
3230
  axios.HttpStatusCode = HttpStatusCode$2;
3204
3231
 
3205
3232
  axios.default = axios;
@@ -3225,8 +3252,9 @@ const {
3225
3252
  AxiosHeaders,
3226
3253
  HttpStatusCode,
3227
3254
  formToJSON,
3255
+ getAdapter,
3228
3256
  mergeConfig
3229
3257
  } = axios$1;
3230
3258
 
3231
- export { Axios, AxiosError, AxiosHeaders, Cancel, CancelToken, CanceledError, HttpStatusCode, VERSION, all, axios$1 as default, formToJSON, isAxiosError, isCancel, mergeConfig, spread, toFormData };
3259
+ export { Axios, AxiosError, AxiosHeaders, Cancel, CancelToken, CanceledError, HttpStatusCode, VERSION, all, axios$1 as default, formToJSON, getAdapter, isAxiosError, isCancel, mergeConfig, spread, toFormData };
3232
3260
  //# sourceMappingURL=axios.js.map