axios 1.3.4 → 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
  } & {
@@ -370,7 +370,7 @@ declare namespace axios {
370
370
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
371
371
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
372
372
  params?: any;
373
- paramsSerializer?: ParamsSerializerOptions;
373
+ paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
374
374
  data?: D;
375
375
  timeout?: Milliseconds;
376
376
  timeoutErrorMessage?: string;
@@ -390,6 +390,7 @@ declare namespace axios {
390
390
  maxRate?: number | [MaxUploadRate, MaxDownloadRate];
391
391
  beforeRedirect?: (options: Record<string, any>, responseDetails: {headers: Record<string, string>}) => void;
392
392
  socketPath?: string | null;
393
+ transport?: any;
393
394
  httpAgent?: any;
394
395
  httpsAgent?: any;
395
396
  proxy?: AxiosProxyConfig | false;
@@ -402,6 +403,9 @@ declare namespace axios {
402
403
  FormData?: new (...args: any[]) => object;
403
404
  };
404
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>);
405
409
  }
406
410
 
407
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;
@@ -311,7 +311,7 @@ export interface AxiosRequestConfig<D = any> {
311
311
  transformResponse?: AxiosResponseTransformer | AxiosResponseTransformer[];
312
312
  headers?: (RawAxiosRequestHeaders & MethodsHeaders) | AxiosHeaders;
313
313
  params?: any;
314
- paramsSerializer?: ParamsSerializerOptions;
314
+ paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
315
315
  data?: D;
316
316
  timeout?: Milliseconds;
317
317
  timeoutErrorMessage?: string;
@@ -329,8 +329,9 @@ 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
+ transport?: any;
334
335
  httpAgent?: any;
335
336
  httpsAgent?: any;
336
337
  proxy?: AxiosProxyConfig | false;
@@ -343,6 +344,9 @@ export interface AxiosRequestConfig<D = any> {
343
344
  FormData?: new (...args: any[]) => object;
344
345
  };
345
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>);
346
350
  }
347
351
 
348
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();
package/lib/core/Axios.js CHANGED
@@ -57,11 +57,17 @@ class Axios {
57
57
  }, false);
58
58
  }
59
59
 
60
- if (paramsSerializer !== undefined) {
61
- validator.assertOptions(paramsSerializer, {
62
- encode: validators.function,
63
- serialize: validators.function
64
- }, true);
60
+ if (paramsSerializer != null) {
61
+ if (utils.isFunction(paramsSerializer)) {
62
+ config.paramsSerializer = {
63
+ serialize: paramsSerializer
64
+ }
65
+ } else {
66
+ validator.assertOptions(paramsSerializer, {
67
+ encode: validators.function,
68
+ serialize: validators.function
69
+ }, true);
70
+ }
65
71
  }
66
72
 
67
73
  // Set config.method
@@ -29,9 +29,7 @@ function parseTokens(str) {
29
29
  return tokens;
30
30
  }
31
31
 
32
- function isValidHeaderName(str) {
33
- return /^[-_a-zA-Z]+$/.test(str.trim());
34
- }
32
+ const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
35
33
 
36
34
  function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
37
35
  if (utils.isFunction(filter)) {
@@ -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.4";
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
@@ -188,12 +188,16 @@ const isStream = (val) => isObject(val) && isFunction(val.pipe);
188
188
  * @returns {boolean} True if value is an FormData, otherwise false
189
189
  */
190
190
  const isFormData = (thing) => {
191
- const pattern = '[object FormData]';
191
+ let kind;
192
192
  return thing && (
193
- (typeof FormData === 'function' && thing instanceof FormData) ||
194
- toString.call(thing) === pattern ||
195
- (isFunction(thing.toString) && thing.toString() === pattern)
196
- );
193
+ (typeof FormData === 'function' && thing instanceof FormData) || (
194
+ isFunction(thing.append) && (
195
+ (kind = kindOf(thing)) === 'formdata' ||
196
+ // detect form-data instance
197
+ (kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
198
+ )
199
+ )
200
+ )
197
201
  }
198
202
 
199
203
  /**
@@ -658,6 +662,11 @@ const toJSONObject = (obj) => {
658
662
  return visit(obj, 0);
659
663
  }
660
664
 
665
+ const isAsyncFn = kindOfTest('AsyncFunction');
666
+
667
+ const isThenable = (thing) =>
668
+ thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
669
+
661
670
  export default {
662
671
  isArray,
663
672
  isArrayBuffer,
@@ -707,5 +716,7 @@ export default {
707
716
  ALPHABET,
708
717
  generateString,
709
718
  isSpecCompliantForm,
710
- toJSONObject
719
+ toJSONObject,
720
+ isAsyncFn,
721
+ isThenable
711
722
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.3.4",
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",
@@ -25,10 +34,11 @@
25
34
  "scripts": {
26
35
  "test": "npm run test:eslint && npm run test:mocha && npm run test:karma && npm run test:dtslint && npm run test:exports",
27
36
  "test:eslint": "node bin/ssl_hotfix.js eslint lib/**/*.js",
28
- "test:dtslint": "node bin/ssl_hotfix.js dtslint",
37
+ "test:dtslint": "dtslint --localTs node_modules/typescript/lib",
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",