axios 1.4.0 → 1.5.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/index.d.cts CHANGED
@@ -523,6 +523,7 @@ declare namespace axios {
523
523
  isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
524
524
  toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
525
525
  formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
526
+ getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
526
527
  AxiosHeaders: typeof AxiosHeaders;
527
528
  }
528
529
  }
package/index.d.ts CHANGED
@@ -512,6 +512,8 @@ export interface GenericHTMLFormElement {
512
512
  submit(): void;
513
513
  }
514
514
 
515
+ export function getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
516
+
515
517
  export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
516
518
 
517
519
  export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
@@ -538,6 +540,7 @@ export interface AxiosStatic extends AxiosInstance {
538
540
  isAxiosError: typeof isAxiosError;
539
541
  toFormData: typeof toFormData;
540
542
  formToJSON: typeof formToJSON;
543
+ getAdapter: typeof getAdapter;
541
544
  CanceledError: typeof CanceledError;
542
545
  AxiosHeaders: typeof AxiosHeaders;
543
546
  }
package/index.js CHANGED
@@ -18,6 +18,7 @@ const {
18
18
  AxiosHeaders,
19
19
  HttpStatusCode,
20
20
  formToJSON,
21
+ getAdapter,
21
22
  mergeConfig
22
23
  } = axios;
23
24
 
@@ -37,5 +38,6 @@ export {
37
38
  AxiosHeaders,
38
39
  HttpStatusCode,
39
40
  formToJSON,
41
+ getAdapter,
40
42
  mergeConfig
41
43
  }
@@ -391,11 +391,13 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
391
391
  auth,
392
392
  protocol,
393
393
  family,
394
- lookup,
395
394
  beforeRedirect: dispatchBeforeRedirect,
396
395
  beforeRedirects: {}
397
396
  };
398
397
 
398
+ // cacheable-lookup integration hotfix
399
+ !utils.isUndefined(lookup) && (options.lookup = lookup);
400
+
399
401
  if (config.socketPath) {
400
402
  options.socketPath = config.socketPath;
401
403
  } else {
package/lib/axios.js CHANGED
@@ -15,6 +15,7 @@ import AxiosError from './core/AxiosError.js';
15
15
  import spread from './helpers/spread.js';
16
16
  import isAxiosError from './helpers/isAxiosError.js';
17
17
  import AxiosHeaders from "./core/AxiosHeaders.js";
18
+ import adapters from './adapters/adapters.js';
18
19
  import HttpStatusCode from './helpers/HttpStatusCode.js';
19
20
 
20
21
  /**
@@ -78,6 +79,8 @@ axios.AxiosHeaders = AxiosHeaders;
78
79
 
79
80
  axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
80
81
 
82
+ axios.getAdapter = adapters.getAdapter;
83
+
81
84
  axios.HttpStatusCode = HttpStatusCode;
82
85
 
83
86
  axios.default = axios;
package/lib/core/Axios.js CHANGED
@@ -73,15 +73,13 @@ class Axios {
73
73
  // Set config.method
74
74
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
75
75
 
76
- let contextHeaders;
77
-
78
76
  // Flatten headers
79
- contextHeaders = headers && utils.merge(
77
+ let contextHeaders = headers && utils.merge(
80
78
  headers.common,
81
79
  headers[config.method]
82
80
  );
83
81
 
84
- contextHeaders && utils.forEach(
82
+ headers && utils.forEach(
85
83
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
86
84
  (method) => {
87
85
  delete headers[method];
@@ -282,7 +282,17 @@ class AxiosHeaders {
282
282
 
283
283
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
284
284
 
285
- utils.freezeMethods(AxiosHeaders.prototype);
285
+ // reserved names hotfix
286
+ utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
287
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
288
+ return {
289
+ get: () => value,
290
+ set(headerValue) {
291
+ this[mapped] = headerValue;
292
+ }
293
+ }
294
+ });
295
+
286
296
  utils.freezeMethods(AxiosHeaders);
287
297
 
288
298
  export default AxiosHeaders;
@@ -8,10 +8,6 @@ import toURLEncodedForm from '../helpers/toURLEncodedForm.js';
8
8
  import platform from '../platform/index.js';
9
9
  import formDataToJSON from '../helpers/formDataToJSON.js';
10
10
 
11
- const DEFAULT_CONTENT_TYPE = {
12
- 'Content-Type': undefined
13
- };
14
-
15
11
  /**
16
12
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
17
13
  * of the input
@@ -41,7 +37,7 @@ const defaults = {
41
37
 
42
38
  transitional: transitionalDefaults,
43
39
 
44
- adapter: ['xhr', 'http'],
40
+ adapter: platform.isNode ? 'http' : 'xhr',
45
41
 
46
42
  transformRequest: [function transformRequest(data, headers) {
47
43
  const contentType = headers.getContentType() || '';
@@ -150,17 +146,14 @@ const defaults = {
150
146
 
151
147
  headers: {
152
148
  common: {
153
- 'Accept': 'application/json, text/plain, */*'
149
+ 'Accept': 'application/json, text/plain, */*',
150
+ 'Content-Type': undefined
154
151
  }
155
152
  }
156
153
  };
157
154
 
158
- utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
155
+ utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
159
156
  defaults.headers[method] = {};
160
157
  });
161
158
 
162
- utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
163
- defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
164
- });
165
-
166
159
  export default defaults;
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.4.0";
1
+ export const VERSION = "1.5.0";
package/lib/utils.js CHANGED
@@ -540,8 +540,9 @@ const reduceDescriptors = (obj, reducer) => {
540
540
  const reducedDescriptors = {};
541
541
 
542
542
  forEach(descriptors, (descriptor, name) => {
543
- if (reducer(descriptor, name, obj) !== false) {
544
- reducedDescriptors[name] = descriptor;
543
+ let ret;
544
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
545
+ reducedDescriptors[name] = ret || descriptor;
545
546
  }
546
547
  });
547
548
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -18,6 +18,8 @@
18
18
  "default": "./index.js"
19
19
  }
20
20
  },
21
+ "./lib/adapters/http.js": "./lib/adapters/http.js",
22
+ "./lib/adapters/xhr.js": "./lib/adapters/xhr.js",
21
23
  "./unsafe/*": "./lib/*",
22
24
  "./unsafe/core/settle.js": "./lib/core/settle.js",
23
25
  "./unsafe/core/buildFullPath.js": "./lib/core/buildFullPath.js",