axios 1.1.1 → 1.1.3

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.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // TypeScript Version: 4.1
2
- type AxiosHeaderValue = string | string[] | number | boolean | null;
2
+ type AxiosHeaderValue = AxiosHeaders | string | string[] | number | boolean | null;
3
3
  type RawAxiosHeaders = Record<string, AxiosHeaderValue>;
4
4
 
5
5
  type MethodsHeaders = {
@@ -39,7 +39,7 @@ export class AxiosHeaders {
39
39
 
40
40
  normalize(format: boolean): AxiosHeaders;
41
41
 
42
- toJSON(): RawAxiosHeaders;
42
+ toJSON(asStrings?: boolean): RawAxiosHeaders;
43
43
 
44
44
  static from(thing?: AxiosHeaders | RawAxiosHeaders | string): AxiosHeaders;
45
45
 
@@ -247,8 +247,13 @@ export interface ParamEncoder {
247
247
  (value: any, defaultEncoder: (value: any) => any): any;
248
248
  }
249
249
 
250
+ export interface CustomParamsSerializer {
251
+ (params: Record<string, any>, options?: ParamsSerializerOptions): string;
252
+ }
253
+
250
254
  export interface ParamsSerializerOptions extends SerializerOptions {
251
255
  encode?: ParamEncoder;
256
+ serialize?: CustomParamsSerializer;
252
257
  }
253
258
 
254
259
  type MaxUploadRate = number;
package/index.js CHANGED
@@ -1,2 +1,32 @@
1
1
  import axios from './lib/axios.js';
2
+
3
+ // Keep top-level export same with static properties
4
+ // so that it can keep same with es module or cjs
5
+ const {
6
+ Axios,
7
+ AxiosError,
8
+ CanceledError,
9
+ isCancel,
10
+ CancelToken,
11
+ VERSION,
12
+ all,
13
+ Cancel,
14
+ isAxiosError,
15
+ spread,
16
+ toFormData
17
+ } = axios;
18
+
2
19
  export default axios;
20
+ export {
21
+ Axios,
22
+ AxiosError,
23
+ CanceledError,
24
+ isCancel,
25
+ CancelToken,
26
+ VERSION,
27
+ all,
28
+ Cancel,
29
+ isAxiosError,
30
+ spread,
31
+ toFormData
32
+ }
@@ -51,7 +51,7 @@ function dispatchBeforeRedirect(options) {
51
51
  * If the proxy or config afterRedirects functions are defined, call them with the options
52
52
  *
53
53
  * @param {http.ClientRequestArgs} options
54
- * @param {AxiosProxyConfig} configProxy
54
+ * @param {AxiosProxyConfig} configProxy configuration from Axios options object
55
55
  * @param {string} location
56
56
  *
57
57
  * @returns {http.ClientRequestArgs}
@@ -82,13 +82,14 @@ function setProxy(options, configProxy, location) {
82
82
  }
83
83
 
84
84
  options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
85
- options.hostname = proxy.hostname;
85
+ const proxyHost = proxy.hostname || proxy.host;
86
+ options.hostname = proxyHost;
86
87
  // Replace 'host' since options is not a URL object
87
- options.host = proxy.hostname;
88
+ options.host = proxyHost;
88
89
  options.port = proxy.port;
89
90
  options.path = location;
90
91
  if (proxy.protocol) {
91
- options.protocol = proxy.protocol;
92
+ options.protocol = proxy.protocol.includes(':') ? proxy.protocol : `${proxy.protocol}:`;
92
93
  }
93
94
  }
94
95
 
@@ -586,3 +587,5 @@ export default function httpAdapter(config) {
586
587
  }
587
588
  });
588
589
  }
590
+
591
+ export const __setProxy = setProxy;
package/lib/core/Axios.js CHANGED
@@ -47,7 +47,7 @@ class Axios {
47
47
 
48
48
  config = mergeConfig(this.defaults, config);
49
49
 
50
- const transitional = config.transitional;
50
+ const {transitional, paramsSerializer} = config;
51
51
 
52
52
  if (transitional !== undefined) {
53
53
  validator.assertOptions(transitional, {
@@ -57,6 +57,13 @@ 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);
65
+ }
66
+
60
67
  // Set config.method
61
68
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
62
69
 
@@ -15,7 +15,7 @@ function normalizeValue(value) {
15
15
  return value;
16
16
  }
17
17
 
18
- return String(value);
18
+ return utils.isArray(value) ? value.map(normalizeValue) : String(value);
19
19
  }
20
20
 
21
21
  function parseTokens(str) {
@@ -102,13 +102,7 @@ Object.assign(AxiosHeaders.prototype, {
102
102
  return;
103
103
  }
104
104
 
105
- if (utils.isArray(_value)) {
106
- _value = _value.map(normalizeValue);
107
- } else {
108
- _value = normalizeValue(_value);
109
- }
110
-
111
- self[key || _header] = _value;
105
+ self[key || _header] = normalizeValue(_value);
112
106
  }
113
107
 
114
108
  if (utils.isPlainObject(header)) {
@@ -222,13 +216,13 @@ Object.assign(AxiosHeaders.prototype, {
222
216
  return this;
223
217
  },
224
218
 
225
- toJSON: function() {
219
+ toJSON: function(asStrings) {
226
220
  const obj = Object.create(null);
227
221
 
228
222
  utils.forEach(Object.assign({}, this[$defaults] || null, this),
229
223
  (value, header) => {
230
224
  if (value == null || value === false) return;
231
- obj[header] = utils.isArray(value) ? value.join(', ') : value;
225
+ obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value;
232
226
  });
233
227
 
234
228
  return obj;
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.1.1";
1
+ export const VERSION = "1.1.3";
@@ -35,21 +35,28 @@ export default function buildURL(url, params, options) {
35
35
  if (!params) {
36
36
  return url;
37
37
  }
38
+
39
+ const _encode = options && options.encode || encode;
38
40
 
39
- const hashmarkIndex = url.indexOf('#');
41
+ const serializeFn = options && options.serialize;
40
42
 
41
- if (hashmarkIndex !== -1) {
42
- url = url.slice(0, hashmarkIndex);
43
- }
43
+ let serializedParams;
44
44
 
45
- const _encode = options && options.encode || encode;
45
+ if (serializeFn) {
46
+ serializedParams = serializeFn(params, options);
47
+ } else {
48
+ serializedParams = utils.isURLSearchParams(params) ?
49
+ params.toString() :
50
+ new AxiosURLSearchParams(params, options).toString(_encode);
51
+ }
46
52
 
47
- const serializerParams = utils.isURLSearchParams(params) ?
48
- params.toString() :
49
- new AxiosURLSearchParams(params, options).toString(_encode);
53
+ if (serializedParams) {
54
+ const hashmarkIndex = url.indexOf("#");
50
55
 
51
- if (serializerParams) {
52
- url += (url.indexOf('?') === -1 ? '?' : '&') + serializerParams;
56
+ if (hashmarkIndex !== -1) {
57
+ url = url.slice(0, hashmarkIndex);
58
+ }
59
+ url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
53
60
  }
54
61
 
55
62
  return url;
@@ -168,7 +168,7 @@ function toFormData(obj, formData, options) {
168
168
  key = removeBrackets(key);
169
169
 
170
170
  arr.forEach(function each(el, index) {
171
- !utils.isUndefined(el) && formData.append(
171
+ !(utils.isUndefined(el) || el === null) && formData.append(
172
172
  // eslint-disable-next-line no-nested-ternary
173
173
  indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
174
174
  convertValue(el)
@@ -205,7 +205,7 @@ function toFormData(obj, formData, options) {
205
205
  stack.push(value);
206
206
 
207
207
  utils.forEach(value, function each(el, key) {
208
- const result = !utils.isUndefined(el) && visitor.call(
208
+ const result = !(utils.isUndefined(el) || el === null) && visitor.call(
209
209
  formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
210
210
  );
211
211
 
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {
7
7
  ".": {
8
8
  "browser": {
9
- "require": "./index.js",
9
+ "require": "./dist/node/axios.cjs",
10
10
  "default": "./index.js"
11
11
  },
12
12
  "default": {
@@ -52,6 +52,7 @@
52
52
  },
53
53
  "homepage": "https://axios-http.com",
54
54
  "devDependencies": {
55
+ "@babel/core": "^7.18.2",
55
56
  "@babel/preset-env": "^7.18.2",
56
57
  "@rollup/plugin-babel": "^5.3.1",
57
58
  "@rollup/plugin-commonjs": "^15.1.0",
package/rollup.config.js CHANGED
@@ -56,7 +56,7 @@ export default async () => {
56
56
  file: `dist/${outputFileName}`,
57
57
  name,
58
58
  format: "umd",
59
- exports: "named",
59
+ exports: "default",
60
60
  banner
61
61
  }
62
62
  }),