axios 0.21.4 → 0.30.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.
- package/CHANGELOG.md +318 -54
- package/README.md +378 -64
- package/SECURITY.md +3 -3
- package/UPGRADE_GUIDE.md +41 -13
- package/bin/check-build-version.js +19 -0
- package/bin/ssl_hotfix.js +22 -0
- package/dist/axios.js +2072 -1878
- package/dist/axios.js.map +1 -0
- package/dist/axios.min.js +2 -3
- package/dist/axios.min.js.map +1 -0
- package/dist/esm/axios.js +2379 -0
- package/dist/esm/axios.js.map +1 -0
- package/dist/esm/axios.min.js +2 -0
- package/dist/esm/axios.min.js.map +1 -0
- package/index.d.ts +219 -46
- package/lib/adapters/http.js +262 -130
- package/lib/adapters/xhr.js +59 -22
- package/lib/axios.js +19 -7
- package/lib/cancel/CancelToken.js +65 -4
- package/lib/cancel/CanceledError.js +24 -0
- package/lib/core/Axios.js +45 -17
- package/lib/core/AxiosError.js +97 -0
- package/lib/core/InterceptorManager.js +9 -0
- package/lib/core/buildFullPath.js +5 -2
- package/lib/core/dispatchRequest.js +13 -1
- package/lib/core/mergeConfig.js +54 -38
- package/lib/core/settle.js +3 -3
- package/lib/core/transformData.js +4 -3
- package/lib/{defaults.js → defaults/index.js} +64 -23
- package/lib/defaults/transitional.js +7 -0
- package/lib/env/README.md +3 -0
- package/lib/env/classes/FormData.js +2 -0
- package/lib/env/data.js +3 -0
- package/lib/helpers/AxiosURLSearchParams.js +42 -0
- package/lib/helpers/bind.js +1 -5
- package/lib/helpers/buildURL.js +18 -33
- package/lib/helpers/combineURLs.js +1 -1
- package/lib/helpers/formDataToJSON.js +74 -0
- package/lib/helpers/fromDataURI.js +51 -0
- package/lib/helpers/isAbsoluteURL.js +1 -1
- package/lib/helpers/isAxiosError.js +3 -1
- package/lib/helpers/isURLSameOrigin.js +12 -12
- package/lib/helpers/null.js +2 -0
- package/lib/helpers/parseHeaders.js +2 -2
- package/lib/helpers/parseProtocol.js +6 -0
- package/lib/helpers/toFormData.js +179 -0
- package/lib/helpers/toURLEncodedForm.js +18 -0
- package/lib/helpers/validator.js +14 -33
- package/lib/platform/browser/classes/FormData.js +3 -0
- package/lib/platform/browser/classes/URLSearchParams.js +5 -0
- package/lib/platform/browser/index.js +11 -0
- package/lib/platform/index.js +3 -0
- package/lib/platform/node/classes/FormData.js +3 -0
- package/lib/platform/node/classes/URLSearchParams.js +5 -0
- package/lib/platform/node/index.js +11 -0
- package/lib/utils.js +210 -37
- package/package.json +42 -26
- package/rollup.config.js +60 -0
- package/tsconfig.json +14 -0
- package/tslint.json +6 -0
- package/dist/axios.map +0 -1
- package/dist/axios.min.map +0 -1
- package/lib/cancel/Cancel.js +0 -19
- package/lib/core/createError.js +0 -18
- package/lib/core/enhanceError.js +0 -42
@@ -13,16 +13,16 @@ module.exports = (
|
|
13
13
|
var originURL;
|
14
14
|
|
15
15
|
/**
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
* Parse a URL to discover it's components
|
17
|
+
*
|
18
|
+
* @param {String} url The URL to be parsed
|
19
|
+
* @returns {Object}
|
20
|
+
*/
|
21
21
|
function resolveURL(url) {
|
22
22
|
var href = url;
|
23
23
|
|
24
24
|
if (msie) {
|
25
|
-
|
25
|
+
// IE needs attribute set twice to normalize properties
|
26
26
|
urlParsingNode.setAttribute('href', href);
|
27
27
|
href = urlParsingNode.href;
|
28
28
|
}
|
@@ -47,11 +47,11 @@ module.exports = (
|
|
47
47
|
originURL = resolveURL(window.location.href);
|
48
48
|
|
49
49
|
/**
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
* Determine if a URL shares the same origin as the current location
|
51
|
+
*
|
52
|
+
* @param {String} requestURL The URL to test
|
53
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
54
|
+
*/
|
55
55
|
return function isURLSameOrigin(requestURL) {
|
56
56
|
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
57
57
|
return (parsed.protocol === originURL.protocol &&
|
@@ -59,7 +59,7 @@ module.exports = (
|
|
59
59
|
};
|
60
60
|
})() :
|
61
61
|
|
62
|
-
|
62
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
63
63
|
(function nonStandardBrowserEnv() {
|
64
64
|
return function isURLSameOrigin() {
|
65
65
|
return true;
|
@@ -34,8 +34,8 @@ module.exports = function parseHeaders(headers) {
|
|
34
34
|
|
35
35
|
utils.forEach(headers.split('\n'), function parser(line) {
|
36
36
|
i = line.indexOf(':');
|
37
|
-
key = utils.trim(line.
|
38
|
-
val = utils.trim(line.
|
37
|
+
key = utils.trim(line.slice(0, i)).toLowerCase();
|
38
|
+
val = utils.trim(line.slice(i + 1));
|
39
39
|
|
40
40
|
if (key) {
|
41
41
|
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
@@ -0,0 +1,179 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var utils = require('../utils');
|
4
|
+
var AxiosError = require('../core/AxiosError');
|
5
|
+
var envFormData = require('../env/classes/FormData');
|
6
|
+
|
7
|
+
function isVisitable(thing) {
|
8
|
+
return utils.isPlainObject(thing) || utils.isArray(thing);
|
9
|
+
}
|
10
|
+
|
11
|
+
function removeBrackets(key) {
|
12
|
+
return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
13
|
+
}
|
14
|
+
|
15
|
+
function renderKey(path, key, dots) {
|
16
|
+
if (!path) return key;
|
17
|
+
return path.concat(key).map(function each(token, i) {
|
18
|
+
// eslint-disable-next-line no-param-reassign
|
19
|
+
token = removeBrackets(token);
|
20
|
+
return !dots && i ? '[' + token + ']' : token;
|
21
|
+
}).join(dots ? '.' : '');
|
22
|
+
}
|
23
|
+
|
24
|
+
function isFlatArray(arr) {
|
25
|
+
return utils.isArray(arr) && !arr.some(isVisitable);
|
26
|
+
}
|
27
|
+
|
28
|
+
var predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
29
|
+
return /^is[A-Z]/.test(prop);
|
30
|
+
});
|
31
|
+
|
32
|
+
function isSpecCompliant(thing) {
|
33
|
+
return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Convert a data object to FormData
|
38
|
+
* @param {Object} obj
|
39
|
+
* @param {?Object} [formData]
|
40
|
+
* @param {?Object} [options]
|
41
|
+
* @param {Function} [options.visitor]
|
42
|
+
* @param {Boolean} [options.metaTokens = true]
|
43
|
+
* @param {Boolean} [options.dots = false]
|
44
|
+
* @param {?Boolean} [options.indexes = false]
|
45
|
+
* @returns {Object}
|
46
|
+
**/
|
47
|
+
|
48
|
+
function toFormData(obj, formData, options) {
|
49
|
+
if (!utils.isObject(obj)) {
|
50
|
+
throw new TypeError('target must be an object');
|
51
|
+
}
|
52
|
+
|
53
|
+
// eslint-disable-next-line no-param-reassign
|
54
|
+
formData = formData || new (envFormData || FormData)();
|
55
|
+
|
56
|
+
// eslint-disable-next-line no-param-reassign
|
57
|
+
options = utils.toFlatObject(options, {
|
58
|
+
metaTokens: true,
|
59
|
+
dots: false,
|
60
|
+
indexes: false
|
61
|
+
}, false, function defined(option, source) {
|
62
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
63
|
+
return !utils.isUndefined(source[option]);
|
64
|
+
});
|
65
|
+
|
66
|
+
var metaTokens = options.metaTokens;
|
67
|
+
// eslint-disable-next-line no-use-before-define
|
68
|
+
var visitor = options.visitor || defaultVisitor;
|
69
|
+
var dots = options.dots;
|
70
|
+
var indexes = options.indexes;
|
71
|
+
var _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
|
72
|
+
var useBlob = _Blob && isSpecCompliant(formData);
|
73
|
+
|
74
|
+
if (!utils.isFunction(visitor)) {
|
75
|
+
throw new TypeError('visitor must be a function');
|
76
|
+
}
|
77
|
+
|
78
|
+
function convertValue(value) {
|
79
|
+
if (value === null) return '';
|
80
|
+
|
81
|
+
if (utils.isDate(value)) {
|
82
|
+
return value.toISOString();
|
83
|
+
}
|
84
|
+
|
85
|
+
if (!useBlob && utils.isBlob(value)) {
|
86
|
+
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
87
|
+
}
|
88
|
+
|
89
|
+
if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
|
90
|
+
return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
91
|
+
}
|
92
|
+
|
93
|
+
return value;
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
*
|
98
|
+
* @param {*} value
|
99
|
+
* @param {String|Number} key
|
100
|
+
* @param {Array<String|Number>} path
|
101
|
+
* @this {FormData}
|
102
|
+
* @returns {boolean} return true to visit the each prop of the value recursively
|
103
|
+
*/
|
104
|
+
function defaultVisitor(value, key, path) {
|
105
|
+
var arr = value;
|
106
|
+
|
107
|
+
if (value && !path && typeof value === 'object') {
|
108
|
+
if (utils.endsWith(key, '{}')) {
|
109
|
+
// eslint-disable-next-line no-param-reassign
|
110
|
+
key = metaTokens ? key : key.slice(0, -2);
|
111
|
+
// eslint-disable-next-line no-param-reassign
|
112
|
+
value = JSON.stringify(value);
|
113
|
+
} else if (
|
114
|
+
(utils.isArray(value) && isFlatArray(value)) ||
|
115
|
+
(utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
|
116
|
+
)) {
|
117
|
+
// eslint-disable-next-line no-param-reassign
|
118
|
+
key = removeBrackets(key);
|
119
|
+
|
120
|
+
arr.forEach(function each(el, index) {
|
121
|
+
!(utils.isUndefined(el) || el === null) && formData.append(
|
122
|
+
// eslint-disable-next-line no-nested-ternary
|
123
|
+
indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
|
124
|
+
convertValue(el)
|
125
|
+
);
|
126
|
+
});
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
if (isVisitable(value)) {
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
|
135
|
+
formData.append(renderKey(path, key, dots), convertValue(value));
|
136
|
+
|
137
|
+
return false;
|
138
|
+
}
|
139
|
+
|
140
|
+
var stack = [];
|
141
|
+
|
142
|
+
var exposedHelpers = Object.assign(predicates, {
|
143
|
+
defaultVisitor: defaultVisitor,
|
144
|
+
convertValue: convertValue,
|
145
|
+
isVisitable: isVisitable
|
146
|
+
});
|
147
|
+
|
148
|
+
function build(value, path) {
|
149
|
+
if (utils.isUndefined(value)) return;
|
150
|
+
|
151
|
+
if (stack.indexOf(value) !== -1) {
|
152
|
+
throw Error('Circular reference detected in ' + path.join('.'));
|
153
|
+
}
|
154
|
+
|
155
|
+
stack.push(value);
|
156
|
+
|
157
|
+
utils.forEach(value, function each(el, key) {
|
158
|
+
var result = !(utils.isUndefined(el) || el === null) && visitor.call(
|
159
|
+
formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
|
160
|
+
);
|
161
|
+
|
162
|
+
if (result === true) {
|
163
|
+
build(el, path ? path.concat(key) : [key]);
|
164
|
+
}
|
165
|
+
});
|
166
|
+
|
167
|
+
stack.pop();
|
168
|
+
}
|
169
|
+
|
170
|
+
if (!utils.isObject(obj)) {
|
171
|
+
throw new TypeError('data must be an object');
|
172
|
+
}
|
173
|
+
|
174
|
+
build(obj);
|
175
|
+
|
176
|
+
return formData;
|
177
|
+
}
|
178
|
+
|
179
|
+
module.exports = toFormData;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var utils = require('../utils');
|
4
|
+
var toFormData = require('./toFormData');
|
5
|
+
var platform = require('../platform/');
|
6
|
+
|
7
|
+
module.exports = function toURLEncodedForm(data, options) {
|
8
|
+
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
|
9
|
+
visitor: function(value, key, path, helpers) {
|
10
|
+
if (platform.isNode && utils.isBuffer(value)) {
|
11
|
+
this.append(key, value.toString('base64'));
|
12
|
+
return false;
|
13
|
+
}
|
14
|
+
|
15
|
+
return helpers.defaultVisitor.apply(this, arguments);
|
16
|
+
}
|
17
|
+
}, options));
|
18
|
+
};
|
package/lib/helpers/validator.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var VERSION = require('../env/data').version;
|
4
|
+
var AxiosError = require('../core/AxiosError');
|
4
5
|
|
5
6
|
var validators = {};
|
6
7
|
|
@@ -12,48 +13,29 @@ var validators = {};
|
|
12
13
|
});
|
13
14
|
|
14
15
|
var deprecatedWarnings = {};
|
15
|
-
var currentVerArr = pkg.version.split('.');
|
16
|
-
|
17
|
-
/**
|
18
|
-
* Compare package versions
|
19
|
-
* @param {string} version
|
20
|
-
* @param {string?} thanVersion
|
21
|
-
* @returns {boolean}
|
22
|
-
*/
|
23
|
-
function isOlderVersion(version, thanVersion) {
|
24
|
-
var pkgVersionArr = thanVersion ? thanVersion.split('.') : currentVerArr;
|
25
|
-
var destVer = version.split('.');
|
26
|
-
for (var i = 0; i < 3; i++) {
|
27
|
-
if (pkgVersionArr[i] > destVer[i]) {
|
28
|
-
return true;
|
29
|
-
} else if (pkgVersionArr[i] < destVer[i]) {
|
30
|
-
return false;
|
31
|
-
}
|
32
|
-
}
|
33
|
-
return false;
|
34
|
-
}
|
35
16
|
|
36
17
|
/**
|
37
18
|
* Transitional option validator
|
38
|
-
* @param {function|boolean?} validator
|
39
|
-
* @param {string?} version
|
40
|
-
* @param {string} message
|
19
|
+
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
20
|
+
* @param {string?} version - deprecated version / removed since version
|
21
|
+
* @param {string?} message - some message with additional info
|
41
22
|
* @returns {function}
|
42
23
|
*/
|
43
24
|
validators.transitional = function transitional(validator, version, message) {
|
44
|
-
var isDeprecated = version && isOlderVersion(version);
|
45
|
-
|
46
25
|
function formatMessage(opt, desc) {
|
47
|
-
return '[Axios v' +
|
26
|
+
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
48
27
|
}
|
49
28
|
|
50
29
|
// eslint-disable-next-line func-names
|
51
30
|
return function(value, opt, opts) {
|
52
31
|
if (validator === false) {
|
53
|
-
throw new
|
32
|
+
throw new AxiosError(
|
33
|
+
formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
|
34
|
+
AxiosError.ERR_DEPRECATED
|
35
|
+
);
|
54
36
|
}
|
55
37
|
|
56
|
-
if (
|
38
|
+
if (version && !deprecatedWarnings[opt]) {
|
57
39
|
deprecatedWarnings[opt] = true;
|
58
40
|
// eslint-disable-next-line no-console
|
59
41
|
console.warn(
|
@@ -77,7 +59,7 @@ validators.transitional = function transitional(validator, version, message) {
|
|
77
59
|
|
78
60
|
function assertOptions(options, schema, allowUnknown) {
|
79
61
|
if (typeof options !== 'object') {
|
80
|
-
throw new
|
62
|
+
throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
|
81
63
|
}
|
82
64
|
var keys = Object.keys(options);
|
83
65
|
var i = keys.length;
|
@@ -88,18 +70,17 @@ function assertOptions(options, schema, allowUnknown) {
|
|
88
70
|
var value = options[opt];
|
89
71
|
var result = value === undefined || validator(value, opt, options);
|
90
72
|
if (result !== true) {
|
91
|
-
throw new
|
73
|
+
throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE);
|
92
74
|
}
|
93
75
|
continue;
|
94
76
|
}
|
95
77
|
if (allowUnknown !== true) {
|
96
|
-
throw
|
78
|
+
throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
|
97
79
|
}
|
98
80
|
}
|
99
81
|
}
|
100
82
|
|
101
83
|
module.exports = {
|
102
|
-
isOlderVersion: isOlderVersion,
|
103
84
|
assertOptions: assertOptions,
|
104
85
|
validators: validators
|
105
86
|
};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
module.exports = {
|
4
|
+
isNode: true,
|
5
|
+
classes: {
|
6
|
+
URLSearchParams: require('./classes/URLSearchParams'),
|
7
|
+
FormData: require('./classes/FormData'),
|
8
|
+
Blob: typeof Blob !== 'undefined' && Blob || null
|
9
|
+
},
|
10
|
+
protocols: [ 'http', 'https', 'file', 'data' ]
|
11
|
+
};
|