axios 1.4.0 → 1.5.1

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 CHANGED
@@ -1,5 +1,47 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.5.1](https://github.com/axios/axios/compare/v1.5.0...v1.5.1) (2023-09-26)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **adapters:** improved adapters loading logic to have clear error messages; ([#5919](https://github.com/axios/axios/issues/5919)) ([e410779](https://github.com/axios/axios/commit/e4107797a7a1376f6209fbecfbbce73d3faa7859))
9
+ * **formdata:** fixed automatic addition of the `Content-Type` header for FormData in non-browser environments; ([#5917](https://github.com/axios/axios/issues/5917)) ([bc9af51](https://github.com/axios/axios/commit/bc9af51b1886d1b3529617702f2a21a6c0ed5d92))
10
+ * **headers:** allow `content-encoding` header to handle case-insensitive values ([#5890](https://github.com/axios/axios/issues/5890)) ([#5892](https://github.com/axios/axios/issues/5892)) ([4c89f25](https://github.com/axios/axios/commit/4c89f25196525e90a6e75eda9cb31ae0a2e18acd))
11
+ * **types:** removed duplicated code ([9e62056](https://github.com/axios/axios/commit/9e6205630e1c9cf863adf141c0edb9e6d8d4b149))
12
+
13
+ ### Contributors to this release
14
+
15
+ - <img src="https://avatars.githubusercontent.com/u/12586868?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS "+89/-18 (#5919 #5917 )")
16
+ - <img src="https://avatars.githubusercontent.com/u/110460234?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [David Dallas](https://github.com/DavidJDallas "+11/-5 ()")
17
+ - <img src="https://avatars.githubusercontent.com/u/71556073?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Sean Sattler](https://github.com/fb-sean "+2/-8 ()")
18
+ - <img src="https://avatars.githubusercontent.com/u/4294069?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Mustafa Ateş Uzun](https://github.com/0o001 "+4/-4 ()")
19
+ - <img src="https://avatars.githubusercontent.com/u/132928043?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Przemyslaw Motacki](https://github.com/sfc-gh-pmotacki "+2/-1 (#5892 )")
20
+ - <img src="https://avatars.githubusercontent.com/u/5492927?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Michael Di Prisco](https://github.com/Cadienvan "+1/-1 ()")
21
+
22
+ # [1.5.0](https://github.com/axios/axios/compare/v1.4.0...v1.5.0) (2023-08-26)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **adapter:** make adapter loading error more clear by using platform-specific adapters explicitly ([#5837](https://github.com/axios/axios/issues/5837)) ([9a414bb](https://github.com/axios/axios/commit/9a414bb6c81796a95c6c7fe668637825458e8b6d))
28
+ * **dns:** fixed `cacheable-lookup` integration; ([#5836](https://github.com/axios/axios/issues/5836)) ([b3e327d](https://github.com/axios/axios/commit/b3e327dcc9277bdce34c7ef57beedf644b00d628))
29
+ * **headers:** added support for setting header names that overlap with class methods; ([#5831](https://github.com/axios/axios/issues/5831)) ([d8b4ca0](https://github.com/axios/axios/commit/d8b4ca0ea5f2f05efa4edfe1e7684593f9f68273))
30
+ * **headers:** fixed common Content-Type header merging; ([#5832](https://github.com/axios/axios/issues/5832)) ([8fda276](https://github.com/axios/axios/commit/8fda2766b1e6bcb72c3fabc146223083ef13ce17))
31
+
32
+
33
+ ### Features
34
+
35
+ * export getAdapter function ([#5324](https://github.com/axios/axios/issues/5324)) ([ca73eb8](https://github.com/axios/axios/commit/ca73eb878df0ae2dace81fe3a7f1fb5986231bf1))
36
+ * **export:** export adapters without `unsafe` prefix ([#5839](https://github.com/axios/axios/issues/5839)) ([1601f4a](https://github.com/axios/axios/commit/1601f4a27a81ab47fea228f1e244b2c4e3ce28bf))
37
+
38
+ ### Contributors to this release
39
+
40
+ - <img src="https://avatars.githubusercontent.com/u/12586868?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS "+66/-29 (#5839 #5837 #5836 #5832 #5831 )")
41
+ - <img src="https://avatars.githubusercontent.com/u/102841186?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [夜葬](https://github.com/geekact "+42/-0 (#5324 )")
42
+ - <img src="https://avatars.githubusercontent.com/u/65978976?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Jonathan Budiman](https://github.com/JBudiman00 "+30/-0 (#5788 )")
43
+ - <img src="https://avatars.githubusercontent.com/u/5492927?v&#x3D;4&amp;s&#x3D;18" alt="avatar" width="18"/> [Michael Di Prisco](https://github.com/Cadienvan "+3/-5 (#5791 )")
44
+
3
45
  # [1.4.0](https://github.com/axios/axios/compare/v1.3.6...v1.4.0) (2023-04-27)
4
46
 
5
47
 
package/README.md CHANGED
@@ -167,7 +167,7 @@ Using unpkg CDN:
167
167
 
168
168
  ## Example
169
169
 
170
- > **Note** CommonJS usage
170
+ > **Note**: CommonJS usage
171
171
  > In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with `require()`, use the following approach:
172
172
 
173
173
  ```js
@@ -215,7 +215,7 @@ async function getUser() {
215
215
  }
216
216
  ```
217
217
 
218
- > **Note** `async/await` is part of ECMAScript 2017 and is not supported in Internet
218
+ > **Note**: `async/await` is part of ECMAScript 2017 and is not supported in Internet
219
219
  > Explorer and older browsers, so use with caution.
220
220
 
221
221
  Performing a `POST` request
@@ -384,12 +384,18 @@ These are the available config options for making requests. Only the `url` is re
384
384
  params: {
385
385
  ID: 12345
386
386
  },
387
-
388
- // `paramsSerializer` is an optional config in charge of serializing `params`
387
+
388
+ // `paramsSerializer` is an optional config that allows you to customize serializing `params`.
389
389
  paramsSerializer: {
390
- encode?: (param: string): string => { /* Do custom ops here and return transformed string */ }, // custom encoder function; sends Key/Values in an iterative fashion
391
- serialize?: (params: Record<string, any>, options?: ParamsSerializerOptions ), // mimic pre 1.x behavior and send entire params object to a custom serializer func. Allows consumer to control how params are serialized.
392
- indexes: false // array indexes format (null - no brackets, false (default) - empty brackets, true - brackets with indexes)
390
+
391
+ //Custom encoder function which sends key/value pairs in an iterative fashion.
392
+ encode?: (param: string): string => { /* Do custom operations here and return transformed string */ },
393
+
394
+ // Custom serializer function for the entire parameter. Allows user to mimic pre 1.x behaviour.
395
+ serialize?: (params: Record<string, any>, options?: ParamsSerializerOptions ),
396
+
397
+ //Configuration for formatting array indexes in the params.
398
+ indexes: false // Three available options: (1) indexes: null (leads to no brackets), (2) (default) indexes: false (leads to empty brackets), (3) indexes: true (leads to brackets with indexes).
393
399
  },
394
400
 
395
401
  // `data` is the data to be sent as the request body
@@ -764,6 +770,36 @@ and when the response was fulfilled
764
770
 
765
771
  Read [the interceptor tests](./test/specs/interceptors.spec.js) for seeing all this in code.
766
772
 
773
+ ## Error Types
774
+
775
+ There are many different axios error messages that can appear that can provide basic information about the specifics of the error and where opportunities may lie in debugging.
776
+
777
+ The general structure of axios errors is as follows:
778
+ | Property | Definition |
779
+ | -------- | ---------- |
780
+ | message | A quick summary of the error message and the status it failed with. |
781
+ | name | This defines where the error originated from. For axios, it will always be an 'AxiosError'. |
782
+ | stack | Provides the stack trace of the error. |
783
+ | config | An axios config object with specific instance configurations defined by the user from when the request was made |
784
+ | code | Represents an axios identified error. The table below lists out specific definitions for internal axios error. |
785
+ | status | HTTP response status code. See [here](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) for common HTTP response status code meanings.
786
+
787
+ Below is a list of potential axios identified error
788
+ | Code | Definition |
789
+ | -------- | ---------- |
790
+ | ERR_BAD_OPTION_VALUE | Invalid or unsupported value provided in axios configuration. |
791
+ | ERR_BAD_OPTION | Invalid option provided in axios configuration. |
792
+ | ECONNABORTED | Request timed out due to exceeding timeout specified in axios configuration. |
793
+ | ETIMEDOUT | Request timed out due to exceeding default axios timelimit. |
794
+ | ERR_NETWORK | Network-related issue.
795
+ | ERR_FR_TOO_MANY_REDIRECTS | Request is redirected too many times; exceeds max redirects specified in axios configuration.
796
+ | ERR_DEPRECATED | Deprecated feature or method used in axios.
797
+ | ERR_BAD_RESPONSE | Response cannot be parsed properly or is in an unexpected format.
798
+ | ERR_BAD_REQUEST | Requested has unexpected format or missing required parameters. |
799
+ | ERR_CANCELED | Feature or method is canceled explicitly by the user.
800
+ | ERR_NOT_SUPPORT | Feature or method not supported in the current axios environment.
801
+ | ERR_INVALID_URL | Invalid URL provided for axios request.
802
+
767
803
  ## Handling Errors
768
804
 
769
805
  the default behavior is to reject every response that returns with a status code that falls out of the range of 2xx and treat it as an error.
@@ -931,8 +967,7 @@ axios.post('https://something.com/', querystring.stringify({ foo: 'bar' }));
931
967
 
932
968
  You can also use the [`qs`](https://github.com/ljharb/qs) library.
933
969
 
934
- > **Note**
935
- > The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has [known issues](https://github.com/nodejs/node-v0.x-archive/issues/1665) with that use case.
970
+ > **Note**: The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has [known issues](https://github.com/nodejs/node-v0.x-archive/issues/1665) with that use case.
936
971
 
937
972
  ### 🆕 Automatic serialization to URLSearchParams
938
973
 
@@ -1048,8 +1083,7 @@ Axios FormData serializer supports some special endings to perform the following
1048
1083
  - `{}` - serialize the value with JSON.stringify
1049
1084
  - `[]` - unwrap the array-like object as separate fields with the same key
1050
1085
 
1051
- > **Note**
1052
- > unwrap/expand operation will be used by default on arrays and FileList objects
1086
+ > **Note**: unwrap/expand operation will be used by default on arrays and FileList objects
1053
1087
 
1054
1088
  FormData serializer supports additional options via `config.formSerializer: object` property to handle rare cases:
1055
1089
 
package/dist/axios.js CHANGED
@@ -1,4 +1,4 @@
1
- // Axios v1.4.0 Copyright (c) 2023 Matt Zabriskie and contributors
1
+ // Axios v1.5.1 Copyright (c) 2023 Matt Zabriskie and contributors
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -625,8 +625,9 @@
625
625
  var descriptors = Object.getOwnPropertyDescriptors(obj);
626
626
  var reducedDescriptors = {};
627
627
  forEach(descriptors, function (descriptor, name) {
628
- if (reducer(descriptor, name, obj) !== false) {
629
- reducedDescriptors[name] = descriptor;
628
+ var ret;
629
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
630
+ reducedDescriptors[name] = ret || descriptor;
630
631
  }
631
632
  });
632
633
  Object.defineProperties(obj, reducedDescriptors);
@@ -1361,10 +1362,6 @@
1361
1362
  return null;
1362
1363
  }
1363
1364
 
1364
- var DEFAULT_CONTENT_TYPE = {
1365
- 'Content-Type': undefined
1366
- };
1367
-
1368
1365
  /**
1369
1366
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1370
1367
  * of the input
@@ -1471,16 +1468,14 @@
1471
1468
  },
1472
1469
  headers: {
1473
1470
  common: {
1474
- 'Accept': 'application/json, text/plain, */*'
1471
+ 'Accept': 'application/json, text/plain, */*',
1472
+ 'Content-Type': undefined
1475
1473
  }
1476
1474
  }
1477
1475
  };
1478
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1476
+ utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], function (method) {
1479
1477
  defaults.headers[method] = {};
1480
1478
  });
1481
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1482
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
1483
- });
1484
1479
  var defaults$1 = defaults;
1485
1480
 
1486
1481
  // RawAxiosHeaders whose duplicates are ignored by node
@@ -1781,7 +1776,20 @@
1781
1776
  return AxiosHeaders;
1782
1777
  }(Symbol.iterator, Symbol.toStringTag);
1783
1778
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
1784
- utils.freezeMethods(AxiosHeaders.prototype);
1779
+
1780
+ // reserved names hotfix
1781
+ utils.reduceDescriptors(AxiosHeaders.prototype, function (_ref3, key) {
1782
+ var value = _ref3.value;
1783
+ var mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
1784
+ return {
1785
+ get: function get() {
1786
+ return value;
1787
+ },
1788
+ set: function set(headerValue) {
1789
+ this[mapped] = headerValue;
1790
+ }
1791
+ };
1792
+ });
1785
1793
  utils.freezeMethods(AxiosHeaders);
1786
1794
  var AxiosHeaders$1 = AxiosHeaders;
1787
1795
 
@@ -2067,14 +2075,17 @@
2067
2075
  config.signal.removeEventListener('abort', onCanceled);
2068
2076
  }
2069
2077
  }
2078
+ var contentType;
2070
2079
  if (utils.isFormData(requestData)) {
2071
2080
  if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
2072
2081
  requestHeaders.setContentType(false); // Let the browser set it
2073
- } else {
2074
- requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
2082
+ } else if (!requestHeaders.getContentType(/^\s*multipart\/form-data/)) {
2083
+ requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
2084
+ } else if (utils.isString(contentType = requestHeaders.getContentType())) {
2085
+ // fix semicolon duplication issue for ReactNative FormData implementation
2086
+ requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'));
2075
2087
  }
2076
2088
  }
2077
-
2078
2089
  var request = new XMLHttpRequest();
2079
2090
 
2080
2091
  // HTTP basic authentication
@@ -2256,6 +2267,12 @@
2256
2267
  });
2257
2268
  }
2258
2269
  });
2270
+ var renderReason = function renderReason(reason) {
2271
+ return "- ".concat(reason);
2272
+ };
2273
+ var isResolvedHandle = function isResolvedHandle(adapter) {
2274
+ return utils.isFunction(adapter) || adapter === null || adapter === false;
2275
+ };
2259
2276
  var adapters = {
2260
2277
  getAdapter: function getAdapter(adapters) {
2261
2278
  adapters = utils.isArray(adapters) ? adapters : [adapters];
@@ -2263,20 +2280,31 @@
2263
2280
  length = _adapters.length;
2264
2281
  var nameOrAdapter;
2265
2282
  var adapter;
2283
+ var rejectedReasons = {};
2266
2284
  for (var i = 0; i < length; i++) {
2267
2285
  nameOrAdapter = adapters[i];
2268
- if (adapter = utils.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter) {
2286
+ var id = void 0;
2287
+ adapter = nameOrAdapter;
2288
+ if (!isResolvedHandle(nameOrAdapter)) {
2289
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
2290
+ if (adapter === undefined) {
2291
+ throw new AxiosError("Unknown adapter '".concat(id, "'"));
2292
+ }
2293
+ }
2294
+ if (adapter) {
2269
2295
  break;
2270
2296
  }
2297
+ rejectedReasons[id || '#' + i] = adapter;
2271
2298
  }
2272
2299
  if (!adapter) {
2273
- if (adapter === false) {
2274
- throw new AxiosError("Adapter ".concat(nameOrAdapter, " is not supported by the environment"), 'ERR_NOT_SUPPORT');
2275
- }
2276
- throw new Error(utils.hasOwnProp(knownAdapters, nameOrAdapter) ? "Adapter '".concat(nameOrAdapter, "' is not available in the build") : "Unknown adapter '".concat(nameOrAdapter, "'"));
2277
- }
2278
- if (!utils.isFunction(adapter)) {
2279
- throw new TypeError('adapter is not a function');
2300
+ var reasons = Object.entries(rejectedReasons).map(function (_ref) {
2301
+ var _ref2 = _slicedToArray(_ref, 2),
2302
+ id = _ref2[0],
2303
+ state = _ref2[1];
2304
+ return "adapter ".concat(id, " ") + (state === false ? 'is not supported by the environment' : 'is not available in the build');
2305
+ });
2306
+ var s = length ? reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0]) : 'as no adapter specified';
2307
+ throw new AxiosError("There is no suitable adapter to dispatch the request " + s, 'ERR_NOT_SUPPORT');
2280
2308
  }
2281
2309
  return adapter;
2282
2310
  },
@@ -2440,7 +2468,7 @@
2440
2468
  return config;
2441
2469
  }
2442
2470
 
2443
- var VERSION = "1.4.0";
2471
+ var VERSION = "1.5.1";
2444
2472
 
2445
2473
  var validators$1 = {};
2446
2474
 
@@ -2582,11 +2610,10 @@
2582
2610
 
2583
2611
  // Set config.method
2584
2612
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
2585
- var contextHeaders;
2586
2613
 
2587
2614
  // Flatten headers
2588
- contextHeaders = headers && utils.merge(headers.common, headers[config.method]);
2589
- contextHeaders && utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], function (method) {
2615
+ var contextHeaders = headers && utils.merge(headers.common, headers[config.method]);
2616
+ headers && utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], function (method) {
2590
2617
  delete headers[method];
2591
2618
  });
2592
2619
  config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
@@ -2973,6 +3000,7 @@
2973
3000
  axios.formToJSON = function (thing) {
2974
3001
  return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
2975
3002
  };
3003
+ axios.getAdapter = adapters.getAdapter;
2976
3004
  axios.HttpStatusCode = HttpStatusCode$1;
2977
3005
  axios["default"] = axios;
2978
3006