axios 0.21.3 → 0.24.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 +73 -0
- package/README.md +28 -4
- package/dist/axios.js +203 -106
- package/dist/axios.map +1 -1
- package/dist/axios.min.js +1 -2
- package/dist/axios.min.map +1 -1
- package/index.d.ts +73 -35
- package/lib/adapters/http.js +46 -14
- package/lib/adapters/xhr.js +32 -9
- package/lib/axios.js +6 -5
- package/lib/cancel/CancelToken.js +62 -0
- package/lib/core/Axios.js +3 -3
- package/lib/core/dispatchRequest.js +5 -0
- package/lib/core/enhanceError.js +2 -1
- package/lib/core/mergeConfig.js +50 -38
- package/lib/defaults.js +22 -7
- package/lib/env/README.md +3 -0
- package/lib/env/data.js +3 -0
- package/lib/helpers/validator.js +7 -30
- package/package.json +8 -6
- package/tsconfig.json +14 -0
- package/tslint.json +6 -0
package/lib/adapters/http.js
CHANGED
@@ -10,9 +10,11 @@ var httpFollow = require('follow-redirects').http;
|
|
10
10
|
var httpsFollow = require('follow-redirects').https;
|
11
11
|
var url = require('url');
|
12
12
|
var zlib = require('zlib');
|
13
|
-
var
|
13
|
+
var VERSION = require('./../env/data').version;
|
14
14
|
var createError = require('../core/createError');
|
15
15
|
var enhanceError = require('../core/enhanceError');
|
16
|
+
var defaults = require('../defaults');
|
17
|
+
var Cancel = require('../cancel/Cancel');
|
16
18
|
|
17
19
|
var isHttps = /https:?/;
|
18
20
|
|
@@ -44,27 +46,43 @@ function setProxy(options, proxy, location) {
|
|
44
46
|
/*eslint consistent-return:0*/
|
45
47
|
module.exports = function httpAdapter(config) {
|
46
48
|
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
49
|
+
var onCanceled;
|
50
|
+
function done() {
|
51
|
+
if (config.cancelToken) {
|
52
|
+
config.cancelToken.unsubscribe(onCanceled);
|
53
|
+
}
|
54
|
+
|
55
|
+
if (config.signal) {
|
56
|
+
config.signal.removeEventListener('abort', onCanceled);
|
57
|
+
}
|
58
|
+
}
|
47
59
|
var resolve = function resolve(value) {
|
60
|
+
done();
|
48
61
|
resolvePromise(value);
|
49
62
|
};
|
50
63
|
var reject = function reject(value) {
|
64
|
+
done();
|
51
65
|
rejectPromise(value);
|
52
66
|
};
|
53
67
|
var data = config.data;
|
54
68
|
var headers = config.headers;
|
69
|
+
var headerNames = {};
|
70
|
+
|
71
|
+
Object.keys(headers).forEach(function storeLowerName(name) {
|
72
|
+
headerNames[name.toLowerCase()] = name;
|
73
|
+
});
|
55
74
|
|
56
75
|
// Set User-Agent (required by some servers)
|
57
76
|
// See https://github.com/axios/axios/issues/69
|
58
|
-
if ('
|
77
|
+
if ('user-agent' in headerNames) {
|
59
78
|
// User-Agent is specified; handle case where no UA header is desired
|
60
|
-
if (!headers[
|
61
|
-
delete headers['
|
62
|
-
delete headers['user-agent'];
|
79
|
+
if (!headers[headerNames['user-agent']]) {
|
80
|
+
delete headers[headerNames['user-agent']];
|
63
81
|
}
|
64
82
|
// Otherwise, use specified value
|
65
83
|
} else {
|
66
84
|
// Only set header if it hasn't been set in config
|
67
|
-
headers['User-Agent'] = 'axios/' +
|
85
|
+
headers['User-Agent'] = 'axios/' + VERSION;
|
68
86
|
}
|
69
87
|
|
70
88
|
if (data && !utils.isStream(data)) {
|
@@ -82,7 +100,9 @@ module.exports = function httpAdapter(config) {
|
|
82
100
|
}
|
83
101
|
|
84
102
|
// Add Content-Length header if data exists
|
85
|
-
|
103
|
+
if (!headerNames['content-length']) {
|
104
|
+
headers['Content-Length'] = data.length;
|
105
|
+
}
|
86
106
|
}
|
87
107
|
|
88
108
|
// HTTP basic authentication
|
@@ -105,8 +125,8 @@ module.exports = function httpAdapter(config) {
|
|
105
125
|
auth = urlUsername + ':' + urlPassword;
|
106
126
|
}
|
107
127
|
|
108
|
-
if (auth) {
|
109
|
-
delete headers.
|
128
|
+
if (auth && headerNames.authorization) {
|
129
|
+
delete headers[headerNames.authorization];
|
110
130
|
}
|
111
131
|
|
112
132
|
var isHttpsRequest = isHttps.test(protocol);
|
@@ -198,6 +218,10 @@ module.exports = function httpAdapter(config) {
|
|
198
218
|
options.maxBodyLength = config.maxBodyLength;
|
199
219
|
}
|
200
220
|
|
221
|
+
if (config.insecureHTTPParser) {
|
222
|
+
options.insecureHTTPParser = config.insecureHTTPParser;
|
223
|
+
}
|
224
|
+
|
201
225
|
// Create the request
|
202
226
|
var req = transport.request(options, function handleResponse(res) {
|
203
227
|
if (req.aborted) return;
|
@@ -300,25 +324,33 @@ module.exports = function httpAdapter(config) {
|
|
300
324
|
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
301
325
|
req.setTimeout(timeout, function handleRequestTimeout() {
|
302
326
|
req.abort();
|
327
|
+
var transitional = config.transitional || defaults.transitional;
|
303
328
|
reject(createError(
|
304
329
|
'timeout of ' + timeout + 'ms exceeded',
|
305
330
|
config,
|
306
|
-
|
331
|
+
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
307
332
|
req
|
308
333
|
));
|
309
334
|
});
|
310
335
|
}
|
311
336
|
|
312
|
-
if (config.cancelToken) {
|
337
|
+
if (config.cancelToken || config.signal) {
|
313
338
|
// Handle cancellation
|
314
|
-
|
339
|
+
// eslint-disable-next-line func-names
|
340
|
+
onCanceled = function(cancel) {
|
315
341
|
if (req.aborted) return;
|
316
342
|
|
317
343
|
req.abort();
|
318
|
-
reject(cancel);
|
319
|
-
}
|
344
|
+
reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
|
345
|
+
};
|
346
|
+
|
347
|
+
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
348
|
+
if (config.signal) {
|
349
|
+
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
350
|
+
}
|
320
351
|
}
|
321
352
|
|
353
|
+
|
322
354
|
// Send the request
|
323
355
|
if (utils.isStream(data)) {
|
324
356
|
data.on('error', function handleStreamError(err) {
|
package/lib/adapters/xhr.js
CHANGED
@@ -8,12 +8,24 @@ var buildFullPath = require('../core/buildFullPath');
|
|
8
8
|
var parseHeaders = require('./../helpers/parseHeaders');
|
9
9
|
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
10
10
|
var createError = require('../core/createError');
|
11
|
+
var defaults = require('../defaults');
|
12
|
+
var Cancel = require('../cancel/Cancel');
|
11
13
|
|
12
14
|
module.exports = function xhrAdapter(config) {
|
13
15
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
14
16
|
var requestData = config.data;
|
15
17
|
var requestHeaders = config.headers;
|
16
18
|
var responseType = config.responseType;
|
19
|
+
var onCanceled;
|
20
|
+
function done() {
|
21
|
+
if (config.cancelToken) {
|
22
|
+
config.cancelToken.unsubscribe(onCanceled);
|
23
|
+
}
|
24
|
+
|
25
|
+
if (config.signal) {
|
26
|
+
config.signal.removeEventListener('abort', onCanceled);
|
27
|
+
}
|
28
|
+
}
|
17
29
|
|
18
30
|
if (utils.isFormData(requestData)) {
|
19
31
|
delete requestHeaders['Content-Type']; // Let the browser set it
|
@@ -51,7 +63,13 @@ module.exports = function xhrAdapter(config) {
|
|
51
63
|
request: request
|
52
64
|
};
|
53
65
|
|
54
|
-
settle(
|
66
|
+
settle(function _resolve(value) {
|
67
|
+
resolve(value);
|
68
|
+
done();
|
69
|
+
}, function _reject(err) {
|
70
|
+
reject(err);
|
71
|
+
done();
|
72
|
+
}, response);
|
55
73
|
|
56
74
|
// Clean up request
|
57
75
|
request = null;
|
@@ -104,14 +122,15 @@ module.exports = function xhrAdapter(config) {
|
|
104
122
|
|
105
123
|
// Handle timeout
|
106
124
|
request.ontimeout = function handleTimeout() {
|
107
|
-
var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
|
125
|
+
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
126
|
+
var transitional = config.transitional || defaults.transitional;
|
108
127
|
if (config.timeoutErrorMessage) {
|
109
128
|
timeoutErrorMessage = config.timeoutErrorMessage;
|
110
129
|
}
|
111
130
|
reject(createError(
|
112
131
|
timeoutErrorMessage,
|
113
132
|
config,
|
114
|
-
|
133
|
+
transitional.clarifyTimeoutError ? 'ETIMEDOUT' : 'ECONNABORTED',
|
115
134
|
request));
|
116
135
|
|
117
136
|
// Clean up request
|
@@ -165,18 +184,22 @@ module.exports = function xhrAdapter(config) {
|
|
165
184
|
request.upload.addEventListener('progress', config.onUploadProgress);
|
166
185
|
}
|
167
186
|
|
168
|
-
if (config.cancelToken) {
|
187
|
+
if (config.cancelToken || config.signal) {
|
169
188
|
// Handle cancellation
|
170
|
-
|
189
|
+
// eslint-disable-next-line func-names
|
190
|
+
onCanceled = function(cancel) {
|
171
191
|
if (!request) {
|
172
192
|
return;
|
173
193
|
}
|
174
|
-
|
194
|
+
reject(!cancel || (cancel && cancel.type) ? new Cancel('canceled') : cancel);
|
175
195
|
request.abort();
|
176
|
-
reject(cancel);
|
177
|
-
// Clean up request
|
178
196
|
request = null;
|
179
|
-
}
|
197
|
+
};
|
198
|
+
|
199
|
+
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
200
|
+
if (config.signal) {
|
201
|
+
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
202
|
+
}
|
180
203
|
}
|
181
204
|
|
182
205
|
if (!requestData) {
|
package/lib/axios.js
CHANGED
@@ -22,6 +22,11 @@ function createInstance(defaultConfig) {
|
|
22
22
|
// Copy context to instance
|
23
23
|
utils.extend(instance, context);
|
24
24
|
|
25
|
+
// Factory for creating new instances
|
26
|
+
instance.create = function create(instanceConfig) {
|
27
|
+
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
28
|
+
};
|
29
|
+
|
25
30
|
return instance;
|
26
31
|
}
|
27
32
|
|
@@ -31,15 +36,11 @@ var axios = createInstance(defaults);
|
|
31
36
|
// Expose Axios class to allow class inheritance
|
32
37
|
axios.Axios = Axios;
|
33
38
|
|
34
|
-
// Factory for creating new instances
|
35
|
-
axios.create = function create(instanceConfig) {
|
36
|
-
return createInstance(mergeConfig(axios.defaults, instanceConfig));
|
37
|
-
};
|
38
|
-
|
39
39
|
// Expose Cancel & CancelToken
|
40
40
|
axios.Cancel = require('./cancel/Cancel');
|
41
41
|
axios.CancelToken = require('./cancel/CancelToken');
|
42
42
|
axios.isCancel = require('./cancel/isCancel');
|
43
|
+
axios.VERSION = require('./env/data').version;
|
43
44
|
|
44
45
|
// Expose all/spread
|
45
46
|
axios.all = function all(promises) {
|
@@ -14,11 +14,42 @@ function CancelToken(executor) {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
var resolvePromise;
|
17
|
+
|
17
18
|
this.promise = new Promise(function promiseExecutor(resolve) {
|
18
19
|
resolvePromise = resolve;
|
19
20
|
});
|
20
21
|
|
21
22
|
var token = this;
|
23
|
+
|
24
|
+
// eslint-disable-next-line func-names
|
25
|
+
this.promise.then(function(cancel) {
|
26
|
+
if (!token._listeners) return;
|
27
|
+
|
28
|
+
var i;
|
29
|
+
var l = token._listeners.length;
|
30
|
+
|
31
|
+
for (i = 0; i < l; i++) {
|
32
|
+
token._listeners[i](cancel);
|
33
|
+
}
|
34
|
+
token._listeners = null;
|
35
|
+
});
|
36
|
+
|
37
|
+
// eslint-disable-next-line func-names
|
38
|
+
this.promise.then = function(onfulfilled) {
|
39
|
+
var _resolve;
|
40
|
+
// eslint-disable-next-line func-names
|
41
|
+
var promise = new Promise(function(resolve) {
|
42
|
+
token.subscribe(resolve);
|
43
|
+
_resolve = resolve;
|
44
|
+
}).then(onfulfilled);
|
45
|
+
|
46
|
+
promise.cancel = function reject() {
|
47
|
+
token.unsubscribe(_resolve);
|
48
|
+
};
|
49
|
+
|
50
|
+
return promise;
|
51
|
+
};
|
52
|
+
|
22
53
|
executor(function cancel(message) {
|
23
54
|
if (token.reason) {
|
24
55
|
// Cancellation has already been requested
|
@@ -39,6 +70,37 @@ CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
|
39
70
|
}
|
40
71
|
};
|
41
72
|
|
73
|
+
/**
|
74
|
+
* Subscribe to the cancel signal
|
75
|
+
*/
|
76
|
+
|
77
|
+
CancelToken.prototype.subscribe = function subscribe(listener) {
|
78
|
+
if (this.reason) {
|
79
|
+
listener(this.reason);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
|
83
|
+
if (this._listeners) {
|
84
|
+
this._listeners.push(listener);
|
85
|
+
} else {
|
86
|
+
this._listeners = [listener];
|
87
|
+
}
|
88
|
+
};
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Unsubscribe from the cancel signal
|
92
|
+
*/
|
93
|
+
|
94
|
+
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
|
95
|
+
if (!this._listeners) {
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
var index = this._listeners.indexOf(listener);
|
99
|
+
if (index !== -1) {
|
100
|
+
this._listeners.splice(index, 1);
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
42
104
|
/**
|
43
105
|
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
44
106
|
* cancels the `CancelToken`.
|
package/lib/core/Axios.js
CHANGED
@@ -51,9 +51,9 @@ Axios.prototype.request = function request(config) {
|
|
51
51
|
|
52
52
|
if (transitional !== undefined) {
|
53
53
|
validator.assertOptions(transitional, {
|
54
|
-
silentJSONParsing: validators.transitional(validators.boolean
|
55
|
-
forcedJSONParsing: validators.transitional(validators.boolean
|
56
|
-
clarifyTimeoutError: validators.transitional(validators.boolean
|
54
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
55
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
56
|
+
clarifyTimeoutError: validators.transitional(validators.boolean)
|
57
57
|
}, false);
|
58
58
|
}
|
59
59
|
|
@@ -4,6 +4,7 @@ var utils = require('./../utils');
|
|
4
4
|
var transformData = require('./transformData');
|
5
5
|
var isCancel = require('../cancel/isCancel');
|
6
6
|
var defaults = require('../defaults');
|
7
|
+
var Cancel = require('../cancel/Cancel');
|
7
8
|
|
8
9
|
/**
|
9
10
|
* Throws a `Cancel` if cancellation has been requested.
|
@@ -12,6 +13,10 @@ function throwIfCancellationRequested(config) {
|
|
12
13
|
if (config.cancelToken) {
|
13
14
|
config.cancelToken.throwIfRequested();
|
14
15
|
}
|
16
|
+
|
17
|
+
if (config.signal && config.signal.aborted) {
|
18
|
+
throw new Cancel('canceled');
|
19
|
+
}
|
15
20
|
}
|
16
21
|
|
17
22
|
/**
|
package/lib/core/enhanceError.js
CHANGED
@@ -35,7 +35,8 @@ module.exports = function enhanceError(error, config, code, request, response) {
|
|
35
35
|
stack: this.stack,
|
36
36
|
// Axios
|
37
37
|
config: this.config,
|
38
|
-
code: this.code
|
38
|
+
code: this.code,
|
39
|
+
status: this.response && this.response.status ? this.response.status : null
|
39
40
|
};
|
40
41
|
};
|
41
42
|
return error;
|
package/lib/core/mergeConfig.js
CHANGED
@@ -15,17 +15,6 @@ module.exports = function mergeConfig(config1, config2) {
|
|
15
15
|
config2 = config2 || {};
|
16
16
|
var config = {};
|
17
17
|
|
18
|
-
var valueFromConfig2Keys = ['url', 'method', 'data'];
|
19
|
-
var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
|
20
|
-
var defaultToConfig2Keys = [
|
21
|
-
'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
|
22
|
-
'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
|
23
|
-
'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
|
24
|
-
'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
|
25
|
-
'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
|
26
|
-
];
|
27
|
-
var directMergeKeys = ['validateStatus'];
|
28
|
-
|
29
18
|
function getMergedValue(target, source) {
|
30
19
|
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
31
20
|
return utils.merge(target, source);
|
@@ -37,51 +26,74 @@ module.exports = function mergeConfig(config1, config2) {
|
|
37
26
|
return source;
|
38
27
|
}
|
39
28
|
|
29
|
+
// eslint-disable-next-line consistent-return
|
40
30
|
function mergeDeepProperties(prop) {
|
41
31
|
if (!utils.isUndefined(config2[prop])) {
|
42
|
-
|
32
|
+
return getMergedValue(config1[prop], config2[prop]);
|
43
33
|
} else if (!utils.isUndefined(config1[prop])) {
|
44
|
-
|
34
|
+
return getMergedValue(undefined, config1[prop]);
|
45
35
|
}
|
46
36
|
}
|
47
37
|
|
48
|
-
|
38
|
+
// eslint-disable-next-line consistent-return
|
39
|
+
function valueFromConfig2(prop) {
|
49
40
|
if (!utils.isUndefined(config2[prop])) {
|
50
|
-
|
41
|
+
return getMergedValue(undefined, config2[prop]);
|
51
42
|
}
|
52
|
-
}
|
53
|
-
|
54
|
-
utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
|
43
|
+
}
|
55
44
|
|
56
|
-
|
45
|
+
// eslint-disable-next-line consistent-return
|
46
|
+
function defaultToConfig2(prop) {
|
57
47
|
if (!utils.isUndefined(config2[prop])) {
|
58
|
-
|
48
|
+
return getMergedValue(undefined, config2[prop]);
|
59
49
|
} else if (!utils.isUndefined(config1[prop])) {
|
60
|
-
|
50
|
+
return getMergedValue(undefined, config1[prop]);
|
61
51
|
}
|
62
|
-
}
|
52
|
+
}
|
63
53
|
|
64
|
-
|
54
|
+
// eslint-disable-next-line consistent-return
|
55
|
+
function mergeDirectKeys(prop) {
|
65
56
|
if (prop in config2) {
|
66
|
-
|
57
|
+
return getMergedValue(config1[prop], config2[prop]);
|
67
58
|
} else if (prop in config1) {
|
68
|
-
|
59
|
+
return getMergedValue(undefined, config1[prop]);
|
69
60
|
}
|
70
|
-
}
|
71
|
-
|
72
|
-
var axiosKeys = valueFromConfig2Keys
|
73
|
-
.concat(mergeDeepPropertiesKeys)
|
74
|
-
.concat(defaultToConfig2Keys)
|
75
|
-
.concat(directMergeKeys);
|
61
|
+
}
|
76
62
|
|
77
|
-
var
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
63
|
+
var mergeMap = {
|
64
|
+
'url': valueFromConfig2,
|
65
|
+
'method': valueFromConfig2,
|
66
|
+
'data': valueFromConfig2,
|
67
|
+
'baseURL': defaultToConfig2,
|
68
|
+
'transformRequest': defaultToConfig2,
|
69
|
+
'transformResponse': defaultToConfig2,
|
70
|
+
'paramsSerializer': defaultToConfig2,
|
71
|
+
'timeout': defaultToConfig2,
|
72
|
+
'timeoutMessage': defaultToConfig2,
|
73
|
+
'withCredentials': defaultToConfig2,
|
74
|
+
'adapter': defaultToConfig2,
|
75
|
+
'responseType': defaultToConfig2,
|
76
|
+
'xsrfCookieName': defaultToConfig2,
|
77
|
+
'xsrfHeaderName': defaultToConfig2,
|
78
|
+
'onUploadProgress': defaultToConfig2,
|
79
|
+
'onDownloadProgress': defaultToConfig2,
|
80
|
+
'decompress': defaultToConfig2,
|
81
|
+
'maxContentLength': defaultToConfig2,
|
82
|
+
'maxBodyLength': defaultToConfig2,
|
83
|
+
'transport': defaultToConfig2,
|
84
|
+
'httpAgent': defaultToConfig2,
|
85
|
+
'httpsAgent': defaultToConfig2,
|
86
|
+
'cancelToken': defaultToConfig2,
|
87
|
+
'socketPath': defaultToConfig2,
|
88
|
+
'responseEncoding': defaultToConfig2,
|
89
|
+
'validateStatus': mergeDirectKeys
|
90
|
+
};
|
83
91
|
|
84
|
-
utils.forEach(
|
92
|
+
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
93
|
+
var merge = mergeMap[prop] || mergeDeepProperties;
|
94
|
+
var configValue = merge(prop);
|
95
|
+
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
96
|
+
});
|
85
97
|
|
86
98
|
return config;
|
87
99
|
};
|
package/lib/defaults.js
CHANGED
@@ -26,6 +26,21 @@ function getDefaultAdapter() {
|
|
26
26
|
return adapter;
|
27
27
|
}
|
28
28
|
|
29
|
+
function stringifySafely(rawValue, parser, encoder) {
|
30
|
+
if (utils.isString(rawValue)) {
|
31
|
+
try {
|
32
|
+
(parser || JSON.parse)(rawValue);
|
33
|
+
return utils.trim(rawValue);
|
34
|
+
} catch (e) {
|
35
|
+
if (e.name !== 'SyntaxError') {
|
36
|
+
throw e;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
return (encoder || JSON.stringify)(rawValue);
|
42
|
+
}
|
43
|
+
|
29
44
|
var defaults = {
|
30
45
|
|
31
46
|
transitional: {
|
@@ -58,13 +73,13 @@ var defaults = {
|
|
58
73
|
}
|
59
74
|
if (utils.isObject(data) || (headers && headers['Content-Type'] === 'application/json')) {
|
60
75
|
setContentTypeIfUnset(headers, 'application/json');
|
61
|
-
return
|
76
|
+
return stringifySafely(data);
|
62
77
|
}
|
63
78
|
return data;
|
64
79
|
}],
|
65
80
|
|
66
81
|
transformResponse: [function transformResponse(data) {
|
67
|
-
var transitional = this.transitional;
|
82
|
+
var transitional = this.transitional || defaults.transitional;
|
68
83
|
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
69
84
|
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
70
85
|
var strictJSONParsing = !silentJSONParsing && this.responseType === 'json';
|
@@ -99,12 +114,12 @@ var defaults = {
|
|
99
114
|
|
100
115
|
validateStatus: function validateStatus(status) {
|
101
116
|
return status >= 200 && status < 300;
|
102
|
-
}
|
103
|
-
};
|
117
|
+
},
|
104
118
|
|
105
|
-
|
106
|
-
|
107
|
-
|
119
|
+
headers: {
|
120
|
+
common: {
|
121
|
+
'Accept': 'application/json, text/plain, */*'
|
122
|
+
}
|
108
123
|
}
|
109
124
|
};
|
110
125
|
|
package/lib/env/data.js
ADDED
package/lib/helpers/validator.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var VERSION = require('../env/data').version;
|
4
4
|
|
5
5
|
var validators = {};
|
6
6
|
|
@@ -12,48 +12,26 @@ var validators = {};
|
|
12
12
|
});
|
13
13
|
|
14
14
|
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
15
|
|
36
16
|
/**
|
37
17
|
* Transitional option validator
|
38
|
-
* @param {function|boolean?} validator
|
39
|
-
* @param {string?} version
|
40
|
-
* @param {string} message
|
18
|
+
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
19
|
+
* @param {string?} version - deprecated version / removed since version
|
20
|
+
* @param {string?} message - some message with additional info
|
41
21
|
* @returns {function}
|
42
22
|
*/
|
43
23
|
validators.transitional = function transitional(validator, version, message) {
|
44
|
-
var isDeprecated = version && isOlderVersion(version);
|
45
|
-
|
46
24
|
function formatMessage(opt, desc) {
|
47
|
-
return '[Axios v' +
|
25
|
+
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
48
26
|
}
|
49
27
|
|
50
28
|
// eslint-disable-next-line func-names
|
51
29
|
return function(value, opt, opts) {
|
52
30
|
if (validator === false) {
|
53
|
-
throw new Error(formatMessage(opt, ' has been removed in ' + version));
|
31
|
+
throw new Error(formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')));
|
54
32
|
}
|
55
33
|
|
56
|
-
if (
|
34
|
+
if (version && !deprecatedWarnings[opt]) {
|
57
35
|
deprecatedWarnings[opt] = true;
|
58
36
|
// eslint-disable-next-line no-console
|
59
37
|
console.warn(
|
@@ -99,7 +77,6 @@ function assertOptions(options, schema, allowUnknown) {
|
|
99
77
|
}
|
100
78
|
|
101
79
|
module.exports = {
|
102
|
-
isOlderVersion: isOlderVersion,
|
103
80
|
assertOptions: assertOptions,
|
104
81
|
validators: validators
|
105
82
|
};
|
package/package.json
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.24.0",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
|
+
"types": "index.d.ts",
|
6
7
|
"scripts": {
|
7
|
-
"test": "grunt test",
|
8
|
+
"test": "grunt test && dtslint",
|
8
9
|
"start": "node ./sandbox/server.js",
|
9
10
|
"build": "NODE_ENV=production grunt build",
|
10
|
-
"preversion": "npm test",
|
11
|
-
"version": "npm run build &&
|
11
|
+
"preversion": "grunt version && npm test",
|
12
|
+
"version": "npm run build && git add -A dist && git add CHANGELOG.md bower.json package.json",
|
12
13
|
"postversion": "git push && git push --tags",
|
13
14
|
"examples": "node ./examples/server.js",
|
14
15
|
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
|
@@ -32,7 +33,9 @@
|
|
32
33
|
},
|
33
34
|
"homepage": "https://axios-http.com",
|
34
35
|
"devDependencies": {
|
36
|
+
"abortcontroller-polyfill": "^1.5.0",
|
35
37
|
"coveralls": "^3.0.0",
|
38
|
+
"dtslint": "^4.1.6",
|
36
39
|
"es6-promise": "^4.2.4",
|
37
40
|
"grunt": "^1.3.0",
|
38
41
|
"grunt-banner": "^0.6.0",
|
@@ -42,7 +45,6 @@
|
|
42
45
|
"grunt-eslint": "^23.0.0",
|
43
46
|
"grunt-karma": "^4.0.0",
|
44
47
|
"grunt-mocha-test": "^0.13.3",
|
45
|
-
"grunt-ts": "^6.0.0-beta.19",
|
46
48
|
"grunt-webpack": "^4.0.2",
|
47
49
|
"istanbul-instrumenter-loader": "^1.0.0",
|
48
50
|
"jasmine-core": "^2.4.1",
|
@@ -73,7 +75,7 @@
|
|
73
75
|
"unpkg": "dist/axios.min.js",
|
74
76
|
"typings": "./index.d.ts",
|
75
77
|
"dependencies": {
|
76
|
-
"follow-redirects": "^1.14.
|
78
|
+
"follow-redirects": "^1.14.4"
|
77
79
|
},
|
78
80
|
"bundlesize": [
|
79
81
|
{
|