axios 1.3.6 → 1.4.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
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
@@ -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,6 +390,8 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
378
390
  agents: { http: config.httpAgent, https: config.httpsAgent },
379
391
  auth,
380
392
  protocol,
393
+ family,
394
+ lookup,
381
395
  beforeRedirect: dispatchBeforeRedirect,
382
396
  beforeRedirects: {}
383
397
  };
@@ -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();
@@ -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);
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.3.6";
1
+ export const VERSION = "1.4.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
@@ -662,6 +662,11 @@ const toJSONObject = (obj) => {
662
662
  return visit(obj, 0);
663
663
  }
664
664
 
665
+ const isAsyncFn = kindOfTest('AsyncFunction');
666
+
667
+ const isThenable = (thing) =>
668
+ thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
669
+
665
670
  export default {
666
671
  isArray,
667
672
  isArrayBuffer,
@@ -711,5 +716,7 @@ export default {
711
716
  ALPHABET,
712
717
  generateString,
713
718
  isSpecCompliantForm,
714
- toJSONObject
719
+ toJSONObject,
720
+ isAsyncFn,
721
+ isThenable
715
722
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.3.6",
3
+ "version": "1.4.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,15 @@
18
18
  "default": "./index.js"
19
19
  }
20
20
  },
21
+ "./unsafe/*": "./lib/*",
22
+ "./unsafe/core/settle.js": "./lib/core/settle.js",
23
+ "./unsafe/core/buildFullPath.js": "./lib/core/buildFullPath.js",
24
+ "./unsafe/helpers/isAbsoluteURL.js": "./lib/helpers/isAbsoluteURL.js",
25
+ "./unsafe/helpers/buildURL.js": "./lib/helpers/buildURL.js",
26
+ "./unsafe/helpers/combineURLs.js": "./lib/helpers/combineURLs.js",
27
+ "./unsafe/adapters/http.js": "./lib/adapters/http.js",
28
+ "./unsafe/adapters/xhr.js": "./lib/adapters/xhr.js",
29
+ "./unsafe/utils.js": "./lib/utils.js",
21
30
  "./package.json": "./package.json"
22
31
  },
23
32
  "type": "module",
@@ -29,6 +38,7 @@
29
38
  "test:mocha": "node bin/ssl_hotfix.js mocha test/unit/**/*.js --timeout 30000 --exit",
30
39
  "test:exports": "node bin/ssl_hotfix.js mocha test/module/test.js --timeout 30000 --exit",
31
40
  "test:karma": "node bin/ssl_hotfix.js cross-env LISTEN_ADDR=:: karma start karma.conf.cjs --single-run",
41
+ "test:karma:firefox": "node bin/ssl_hotfix.js cross-env LISTEN_ADDR=:: Browsers=Firefox karma start karma.conf.cjs --single-run",
32
42
  "test:karma:server": "node bin/ssl_hotfix.js cross-env karma start karma.conf.cjs",
33
43
  "test:build:version": "node ./bin/check-build-version.js",
34
44
  "start": "node ./sandbox/server.js",
@@ -122,8 +132,7 @@
122
132
  "stream-throttle": "^0.1.3",
123
133
  "string-replace-async": "^3.0.2",
124
134
  "terser-webpack-plugin": "^4.2.3",
125
- "typescript": "^4.8.4",
126
- "url-search-params": "^0.10.0"
135
+ "typescript": "^4.8.4"
127
136
  },
128
137
  "browser": {
129
138
  "./lib/adapters/http.js": "./lib/helpers/null.js",