axios 1.3.6 → 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
@@ -1,7 +1,5 @@
1
- type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
2
-
3
1
  interface RawAxiosHeaders {
4
- [key: string]: AxiosHeaderValue;
2
+ [key: string]: axios.AxiosHeaderValue;
5
3
  }
6
4
 
7
5
  type MethodsHeaders = Partial<{
@@ -12,7 +10,7 @@ type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, head
12
10
 
13
11
  type CommonRequestHeadersList = 'Accept' | 'Content-Length' | 'User-Agent'| 'Content-Encoding' | 'Authorization';
14
12
 
15
- type ContentType = AxiosHeaderValue | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream';
13
+ type ContentType = axios.AxiosHeaderValue | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream';
16
14
 
17
15
  type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' | 'Cache-Control'| 'Content-Encoding';
18
16
 
@@ -23,11 +21,11 @@ declare class AxiosHeaders {
23
21
 
24
22
  [key: string]: any;
25
23
 
26
- set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
24
+ set(headerName?: string, value?: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
27
25
  set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
28
26
 
29
27
  get(headerName: string, parser: RegExp): RegExpExecArray | null;
30
- get(headerName: string, matcher?: true | AxiosHeaderMatcher): AxiosHeaderValue;
28
+ get(headerName: string, matcher?: true | AxiosHeaderMatcher): axios.AxiosHeaderValue;
31
29
 
32
30
  has(header: string, matcher?: true | AxiosHeaderMatcher): boolean;
33
31
 
@@ -49,35 +47,35 @@ declare class AxiosHeaders {
49
47
 
50
48
  setContentType(value: ContentType, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
51
49
  getContentType(parser?: RegExp): RegExpExecArray | null;
52
- getContentType(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
50
+ getContentType(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
53
51
  hasContentType(matcher?: AxiosHeaderMatcher): boolean;
54
52
 
55
- setContentLength(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
53
+ setContentLength(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
56
54
  getContentLength(parser?: RegExp): RegExpExecArray | null;
57
- getContentLength(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
55
+ getContentLength(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
58
56
  hasContentLength(matcher?: AxiosHeaderMatcher): boolean;
59
57
 
60
- setAccept(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
58
+ setAccept(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
61
59
  getAccept(parser?: RegExp): RegExpExecArray | null;
62
- getAccept(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
60
+ getAccept(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
63
61
  hasAccept(matcher?: AxiosHeaderMatcher): boolean;
64
62
 
65
- setUserAgent(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
63
+ setUserAgent(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
66
64
  getUserAgent(parser?: RegExp): RegExpExecArray | null;
67
- getUserAgent(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
65
+ getUserAgent(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
68
66
  hasUserAgent(matcher?: AxiosHeaderMatcher): boolean;
69
67
 
70
- setContentEncoding(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
68
+ setContentEncoding(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
71
69
  getContentEncoding(parser?: RegExp): RegExpExecArray | null;
72
- getContentEncoding(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
70
+ getContentEncoding(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
73
71
  hasContentEncoding(matcher?: AxiosHeaderMatcher): boolean;
74
72
 
75
- setAuthorization(value: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
73
+ setAuthorization(value: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
76
74
  getAuthorization(parser?: RegExp): RegExpExecArray | null;
77
- getAuthorization(matcher?: AxiosHeaderMatcher): AxiosHeaderValue;
75
+ getAuthorization(matcher?: AxiosHeaderMatcher): axios.AxiosHeaderValue;
78
76
  hasAuthorization(matcher?: AxiosHeaderMatcher): boolean;
79
77
 
80
- [Symbol.iterator](): IterableIterator<[string, AxiosHeaderValue]>;
78
+ [Symbol.iterator](): IterableIterator<[string, axios.AxiosHeaderValue]>;
81
79
  }
82
80
 
83
81
  declare class AxiosError<T = unknown, D = any> extends Error {
@@ -214,6 +212,8 @@ declare namespace axios {
214
212
 
215
213
  type AxiosRequestHeaders = RawAxiosRequestHeaders & AxiosHeaders;
216
214
 
215
+ type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
216
+
217
217
  type RawCommonResponseHeaders = {
218
218
  [Key in CommonResponseHeadersList]: AxiosHeaderValue;
219
219
  } & {
@@ -403,6 +403,9 @@ declare namespace axios {
403
403
  FormData?: new (...args: any[]) => object;
404
404
  };
405
405
  formSerializer?: FormSerializerOptions;
406
+ family?: 4 | 6 | undefined;
407
+ lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: string, family: number) => void) => void) |
408
+ ((hostname: string, options: object) => Promise<[address: string, family: number] | string>);
406
409
  }
407
410
 
408
411
  // Alias
@@ -520,6 +523,7 @@ declare namespace axios {
520
523
  isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
521
524
  toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
522
525
  formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
526
+ getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
523
527
  AxiosHeaders: typeof AxiosHeaders;
524
528
  }
525
529
  }
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // TypeScript Version: 4.7
2
- type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
2
+ export type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
3
3
 
4
4
  interface RawAxiosHeaders {
5
5
  [key: string]: AxiosHeaderValue;
@@ -329,7 +329,7 @@ export interface AxiosRequestConfig<D = any> {
329
329
  maxBodyLength?: number;
330
330
  maxRedirects?: number;
331
331
  maxRate?: number | [MaxUploadRate, MaxDownloadRate];
332
- beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>}) => void;
332
+ beforeRedirect?: (options: Record<string, any>, responseDetails: { headers: Record<string, string> }) => void;
333
333
  socketPath?: string | null;
334
334
  transport?: any;
335
335
  httpAgent?: any;
@@ -344,6 +344,9 @@ export interface AxiosRequestConfig<D = any> {
344
344
  FormData?: new (...args: any[]) => object;
345
345
  };
346
346
  formSerializer?: FormSerializerOptions;
347
+ family?: 4 | 6 | undefined;
348
+ lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: string, family: number) => void) => void) |
349
+ ((hostname: string, options: object) => Promise<[address: string, family: number] | string>);
347
350
  }
348
351
 
349
352
  // Alias
@@ -509,6 +512,8 @@ export interface GenericHTMLFormElement {
509
512
  submit(): void;
510
513
  }
511
514
 
515
+ export function getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
516
+
512
517
  export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
513
518
 
514
519
  export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
@@ -535,6 +540,7 @@ export interface AxiosStatic extends AxiosInstance {
535
540
  isAxiosError: typeof isAxiosError;
536
541
  toFormData: typeof toFormData;
537
542
  formToJSON: typeof formToJSON;
543
+ getAdapter: typeof getAdapter;
538
544
  CanceledError: typeof CanceledError;
539
545
  AxiosHeaders: typeof AxiosHeaders;
540
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
  }
@@ -23,6 +23,7 @@ import EventEmitter from 'events';
23
23
  import formDataToStream from "../helpers/formDataToStream.js";
24
24
  import readBlob from "../helpers/readBlob.js";
25
25
  import ZlibHeaderTransformStream from '../helpers/ZlibHeaderTransformStream.js';
26
+ import callbackify from "../helpers/callbackify.js";
26
27
 
27
28
  const zlibOptions = {
28
29
  flush: zlib.constants.Z_SYNC_FLUSH,
@@ -146,13 +147,24 @@ const wrapAsync = (asyncExecutor) => {
146
147
  /*eslint consistent-return:0*/
147
148
  export default isHttpAdapterSupported && function httpAdapter(config) {
148
149
  return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
149
- let {data} = config;
150
+ let {data, lookup, family} = config;
150
151
  const {responseType, responseEncoding} = config;
151
152
  const method = config.method.toUpperCase();
152
153
  let isDone;
153
154
  let rejected = false;
154
155
  let req;
155
156
 
157
+ if (lookup && utils.isAsyncFn(lookup)) {
158
+ lookup = callbackify(lookup, (entry) => {
159
+ if(utils.isString(entry)) {
160
+ entry = [entry, entry.indexOf('.') < 0 ? 6 : 4]
161
+ } else if (!utils.isArray(entry)) {
162
+ throw new TypeError('lookup async function must return an array [ip: string, family: number]]')
163
+ }
164
+ return entry;
165
+ })
166
+ }
167
+
156
168
  // temporary internal emitter until the AxiosRequest class will be implemented
157
169
  const emitter = new EventEmitter();
158
170
 
@@ -378,10 +390,14 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
378
390
  agents: { http: config.httpAgent, https: config.httpsAgent },
379
391
  auth,
380
392
  protocol,
393
+ family,
381
394
  beforeRedirect: dispatchBeforeRedirect,
382
395
  beforeRedirects: {}
383
396
  };
384
397
 
398
+ // cacheable-lookup integration hotfix
399
+ !utils.isUndefined(lookup) && (options.lookup = lookup);
400
+
385
401
  if (config.socketPath) {
386
402
  options.socketPath = config.socketPath;
387
403
  } else {
@@ -61,8 +61,12 @@ export default isXHRAdapterSupported && function (config) {
61
61
  }
62
62
  }
63
63
 
64
- if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
65
- requestHeaders.setContentType(false); // Let the browser set it
64
+ if (utils.isFormData(requestData)) {
65
+ if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
66
+ requestHeaders.setContentType(false); // Let the browser set it
67
+ } else {
68
+ requestHeaders.setContentType('multipart/form-data;', false); // mobile/desktop app frameworks
69
+ }
66
70
  }
67
71
 
68
72
  let request = new XMLHttpRequest();
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;
@@ -95,7 +95,7 @@ export default function mergeConfig(config1, config2) {
95
95
  headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
96
96
  };
97
97
 
98
- utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
98
+ utils.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
99
99
  const merge = mergeMap[prop] || mergeDeepProperties;
100
100
  const configValue = merge(config1[prop], config2[prop], prop);
101
101
  (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
@@ -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.3.6";
1
+ export const VERSION = "1.5.0";
@@ -0,0 +1,16 @@
1
+ import utils from "../utils.js";
2
+
3
+ const callbackify = (fn, reducer) => {
4
+ return utils.isAsyncFn(fn) ? function (...args) {
5
+ const cb = args.pop();
6
+ fn.apply(this, args).then((value) => {
7
+ try {
8
+ reducer ? cb(null, ...reducer(value)) : cb(null, value);
9
+ } catch (err) {
10
+ cb(err);
11
+ }
12
+ }, cb);
13
+ } : fn;
14
+ }
15
+
16
+ export default callbackify;
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
 
@@ -662,6 +663,11 @@ const toJSONObject = (obj) => {
662
663
  return visit(obj, 0);
663
664
  }
664
665
 
666
+ const isAsyncFn = kindOfTest('AsyncFunction');
667
+
668
+ const isThenable = (thing) =>
669
+ thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
670
+
665
671
  export default {
666
672
  isArray,
667
673
  isArrayBuffer,
@@ -711,5 +717,7 @@ export default {
711
717
  ALPHABET,
712
718
  generateString,
713
719
  isSpecCompliantForm,
714
- toJSONObject
720
+ toJSONObject,
721
+ isAsyncFn,
722
+ isThenable
715
723
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.3.6",
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,17 @@
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",
23
+ "./unsafe/*": "./lib/*",
24
+ "./unsafe/core/settle.js": "./lib/core/settle.js",
25
+ "./unsafe/core/buildFullPath.js": "./lib/core/buildFullPath.js",
26
+ "./unsafe/helpers/isAbsoluteURL.js": "./lib/helpers/isAbsoluteURL.js",
27
+ "./unsafe/helpers/buildURL.js": "./lib/helpers/buildURL.js",
28
+ "./unsafe/helpers/combineURLs.js": "./lib/helpers/combineURLs.js",
29
+ "./unsafe/adapters/http.js": "./lib/adapters/http.js",
30
+ "./unsafe/adapters/xhr.js": "./lib/adapters/xhr.js",
31
+ "./unsafe/utils.js": "./lib/utils.js",
21
32
  "./package.json": "./package.json"
22
33
  },
23
34
  "type": "module",
@@ -29,6 +40,7 @@
29
40
  "test:mocha": "node bin/ssl_hotfix.js mocha test/unit/**/*.js --timeout 30000 --exit",
30
41
  "test:exports": "node bin/ssl_hotfix.js mocha test/module/test.js --timeout 30000 --exit",
31
42
  "test:karma": "node bin/ssl_hotfix.js cross-env LISTEN_ADDR=:: karma start karma.conf.cjs --single-run",
43
+ "test:karma:firefox": "node bin/ssl_hotfix.js cross-env LISTEN_ADDR=:: Browsers=Firefox karma start karma.conf.cjs --single-run",
32
44
  "test:karma:server": "node bin/ssl_hotfix.js cross-env karma start karma.conf.cjs",
33
45
  "test:build:version": "node ./bin/check-build-version.js",
34
46
  "start": "node ./sandbox/server.js",
@@ -122,8 +134,7 @@
122
134
  "stream-throttle": "^0.1.3",
123
135
  "string-replace-async": "^3.0.2",
124
136
  "terser-webpack-plugin": "^4.2.3",
125
- "typescript": "^4.8.4",
126
- "url-search-params": "^0.10.0"
137
+ "typescript": "^4.8.4"
127
138
  },
128
139
  "browser": {
129
140
  "./lib/adapters/http.js": "./lib/helpers/null.js",