axios 1.1.3 → 1.2.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/CHANGELOG.md +139 -74
- package/{UPGRADE_GUIDE.md → MIGRATION_GUIDE.md} +1 -1
- package/README.md +59 -22
- package/dist/axios.js +754 -576
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +3054 -0
- package/dist/browser/axios.cjs.map +1 -0
- package/dist/esm/axios.js +719 -595
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +618 -517
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +490 -0
- package/index.d.ts +33 -11
- package/index.js +8 -3
- package/karma.conf.cjs +1 -1
- package/lib/adapters/adapters.js +59 -0
- package/lib/adapters/http.js +23 -21
- package/lib/adapters/xhr.js +5 -2
- package/lib/axios.js +7 -3
- package/lib/core/Axios.js +10 -8
- package/lib/core/AxiosError.js +1 -1
- package/lib/core/AxiosHeaders.js +82 -76
- package/lib/core/dispatchRequest.js +6 -1
- package/lib/core/mergeConfig.js +50 -46
- package/lib/defaults/index.js +2 -21
- package/lib/env/data.js +1 -1
- package/lib/utils.js +68 -8
- package/package.json +14 -7
- package/rollup.config.js +37 -10
- package/tsconfig.json +2 -7
- package/tslint.json +6 -1
- package/lib/adapters/index.js +0 -33
package/lib/utils.js
CHANGED
@@ -228,7 +228,7 @@ const trim = (str) => str.trim ?
|
|
228
228
|
* @param {Function} fn The callback to invoke for each item
|
229
229
|
*
|
230
230
|
* @param {Boolean} [allOwnKeys = false]
|
231
|
-
* @returns {
|
231
|
+
* @returns {any}
|
232
232
|
*/
|
233
233
|
function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
234
234
|
// Don't bother if no value provided
|
@@ -263,6 +263,24 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
263
263
|
}
|
264
264
|
}
|
265
265
|
|
266
|
+
function findKey(obj, key) {
|
267
|
+
key = key.toLowerCase();
|
268
|
+
const keys = Object.keys(obj);
|
269
|
+
let i = keys.length;
|
270
|
+
let _key;
|
271
|
+
while (i-- > 0) {
|
272
|
+
_key = keys[i];
|
273
|
+
if (key === _key.toLowerCase()) {
|
274
|
+
return _key;
|
275
|
+
}
|
276
|
+
}
|
277
|
+
return null;
|
278
|
+
}
|
279
|
+
|
280
|
+
const _global = typeof self === "undefined" ? typeof global === "undefined" ? this : global : self;
|
281
|
+
|
282
|
+
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
283
|
+
|
266
284
|
/**
|
267
285
|
* Accepts varargs expecting each argument to be an object, then
|
268
286
|
* immutably merges the properties of each object and returns result.
|
@@ -282,16 +300,18 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
282
300
|
* @returns {Object} Result of all merge properties
|
283
301
|
*/
|
284
302
|
function merge(/* obj1, obj2, obj3, ... */) {
|
303
|
+
const {caseless} = isContextDefined(this) && this || {};
|
285
304
|
const result = {};
|
286
305
|
const assignValue = (val, key) => {
|
287
|
-
|
288
|
-
|
306
|
+
const targetKey = caseless && findKey(result, key) || key;
|
307
|
+
if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
|
308
|
+
result[targetKey] = merge(result[targetKey], val);
|
289
309
|
} else if (isPlainObject(val)) {
|
290
|
-
result[
|
310
|
+
result[targetKey] = merge({}, val);
|
291
311
|
} else if (isArray(val)) {
|
292
|
-
result[
|
312
|
+
result[targetKey] = val.slice();
|
293
313
|
} else {
|
294
|
-
result[
|
314
|
+
result[targetKey] = val;
|
295
315
|
}
|
296
316
|
}
|
297
317
|
|
@@ -527,6 +547,11 @@ const reduceDescriptors = (obj, reducer) => {
|
|
527
547
|
|
528
548
|
const freezeMethods = (obj) => {
|
529
549
|
reduceDescriptors(obj, (descriptor, name) => {
|
550
|
+
// skip restricted props in strict mode
|
551
|
+
if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
552
|
+
return false;
|
553
|
+
}
|
554
|
+
|
530
555
|
const value = obj[name];
|
531
556
|
|
532
557
|
if (!isFunction(value)) return;
|
@@ -540,7 +565,7 @@ const freezeMethods = (obj) => {
|
|
540
565
|
|
541
566
|
if (!descriptor.set) {
|
542
567
|
descriptor.set = () => {
|
543
|
-
throw Error('Can not read-only method \'' + name + '\'');
|
568
|
+
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
544
569
|
};
|
545
570
|
}
|
546
571
|
});
|
@@ -567,6 +592,37 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
567
592
|
return Number.isFinite(value) ? value : defaultValue;
|
568
593
|
}
|
569
594
|
|
595
|
+
const toJSONObject = (obj) => {
|
596
|
+
const stack = new Array(10);
|
597
|
+
|
598
|
+
const visit = (source, i) => {
|
599
|
+
|
600
|
+
if (isObject(source)) {
|
601
|
+
if (stack.indexOf(source) >= 0) {
|
602
|
+
return;
|
603
|
+
}
|
604
|
+
|
605
|
+
if(!('toJSON' in source)) {
|
606
|
+
stack[i] = source;
|
607
|
+
const target = isArray(source) ? [] : {};
|
608
|
+
|
609
|
+
forEach(source, (value, key) => {
|
610
|
+
const reducedValue = visit(value, i + 1);
|
611
|
+
!isUndefined(reducedValue) && (target[key] = reducedValue);
|
612
|
+
});
|
613
|
+
|
614
|
+
stack[i] = undefined;
|
615
|
+
|
616
|
+
return target;
|
617
|
+
}
|
618
|
+
}
|
619
|
+
|
620
|
+
return source;
|
621
|
+
}
|
622
|
+
|
623
|
+
return visit(obj, 0);
|
624
|
+
}
|
625
|
+
|
570
626
|
export default {
|
571
627
|
isArray,
|
572
628
|
isArrayBuffer,
|
@@ -609,5 +665,9 @@ export default {
|
|
609
665
|
toObjectSet,
|
610
666
|
toCamelCase,
|
611
667
|
noop,
|
612
|
-
toFiniteNumber
|
668
|
+
toFiniteNumber,
|
669
|
+
findKey,
|
670
|
+
global: _global,
|
671
|
+
isContextDefined,
|
672
|
+
toJSONObject
|
613
673
|
};
|
package/package.json
CHANGED
@@ -1,27 +1,33 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.2.0",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"exports": {
|
7
7
|
".": {
|
8
|
+
"types": {
|
9
|
+
"require": "./index.d.cts",
|
10
|
+
"default": "./index.d.ts"
|
11
|
+
},
|
8
12
|
"browser": {
|
9
|
-
"require": "./dist/
|
13
|
+
"require": "./dist/browser/axios.cjs",
|
10
14
|
"default": "./index.js"
|
11
15
|
},
|
12
16
|
"default": {
|
13
17
|
"require": "./dist/node/axios.cjs",
|
14
18
|
"default": "./index.js"
|
15
19
|
}
|
16
|
-
}
|
20
|
+
},
|
21
|
+
"./package.json": "./package.json"
|
17
22
|
},
|
18
23
|
"type": "module",
|
19
24
|
"types": "index.d.ts",
|
20
25
|
"scripts": {
|
21
|
-
"test": "npm run test:eslint && npm run test:mocha && npm run test:karma && npm run test:dtslint",
|
26
|
+
"test": "npm run test:eslint && npm run test:mocha && npm run test:karma && npm run test:exports && npm run test:dtslint",
|
22
27
|
"test:eslint": "node bin/ssl_hotfix.js eslint lib/**/*.js",
|
23
28
|
"test:dtslint": "node bin/ssl_hotfix.js dtslint",
|
24
29
|
"test:mocha": "node bin/ssl_hotfix.js mocha test/unit/**/*.js --timeout 30000 --exit",
|
30
|
+
"test:exports": "node bin/ssl_hotfix.js mocha test/module/test.js --timeout 30000 --exit",
|
25
31
|
"test:karma": "node bin/ssl_hotfix.js cross-env LISTEN_ADDR=:: karma start karma.conf.cjs --single-run",
|
26
32
|
"test:karma:server": "node bin/ssl_hotfix.js cross-env karma start karma.conf.cjs",
|
27
33
|
"start": "node ./sandbox/server.js",
|
@@ -94,11 +100,11 @@
|
|
94
100
|
"sinon": "^4.5.0",
|
95
101
|
"stream-throttle": "^0.1.3",
|
96
102
|
"terser-webpack-plugin": "^4.2.3",
|
97
|
-
"typescript": "^4.
|
103
|
+
"typescript": "^4.8.4",
|
98
104
|
"url-search-params": "^0.10.0"
|
99
105
|
},
|
100
106
|
"browser": {
|
101
|
-
"./lib/adapters/http.js": "./lib/
|
107
|
+
"./lib/adapters/http.js": "./lib/helpers/null.js",
|
102
108
|
"./lib/platform/node/index.js": "./lib/platform/browser/index.js"
|
103
109
|
},
|
104
110
|
"jsdelivr": "dist/axios.min.js",
|
@@ -130,5 +136,6 @@
|
|
130
136
|
"Yasu Flores (https://github.com/yasuf)",
|
131
137
|
"Ben Carp (https://github.com/carpben)",
|
132
138
|
"Daniel Lopretto (https://github.com/timemachine3030)"
|
133
|
-
]
|
139
|
+
],
|
140
|
+
"sideEffects": false
|
134
141
|
}
|
package/rollup.config.js
CHANGED
@@ -5,20 +5,28 @@ import json from '@rollup/plugin-json';
|
|
5
5
|
import { babel } from '@rollup/plugin-babel';
|
6
6
|
import autoExternal from 'rollup-plugin-auto-external';
|
7
7
|
import bundleSize from 'rollup-plugin-bundle-size'
|
8
|
+
import path from 'path';
|
8
9
|
|
9
10
|
const lib = require("./package.json");
|
10
11
|
const outputFileName = 'axios';
|
11
12
|
const name = "axios";
|
12
|
-
const
|
13
|
+
const namedInput = './index.js';
|
14
|
+
const defaultInput = './lib/axios.js';
|
13
15
|
|
14
16
|
const buildConfig = ({es5, browser = true, minifiedVersion = true, ...config}) => {
|
17
|
+
const {file} = config.output;
|
18
|
+
const ext = path.extname(file);
|
19
|
+
const basename = path.basename(file, ext);
|
20
|
+
const extArr = ext.split('.');
|
21
|
+
extArr.shift();
|
22
|
+
|
15
23
|
|
16
24
|
const build = ({minified}) => ({
|
17
|
-
input,
|
25
|
+
input: namedInput,
|
18
26
|
...config,
|
19
27
|
output: {
|
20
28
|
...config.output,
|
21
|
-
file: `${
|
29
|
+
file: `${path.dirname(file)}/${basename}.${(minified ? ['min', ...extArr] : extArr).join('.')}`
|
22
30
|
},
|
23
31
|
plugins: [
|
24
32
|
json(),
|
@@ -50,10 +58,24 @@ export default async () => {
|
|
50
58
|
const banner = `// Axios v${lib.version} Copyright (c) ${year} ${lib.author} and contributors`;
|
51
59
|
|
52
60
|
return [
|
61
|
+
// browser ESM bundle for CDN
|
53
62
|
...buildConfig({
|
63
|
+
input: namedInput,
|
64
|
+
output: {
|
65
|
+
file: `dist/esm/${outputFileName}.js`,
|
66
|
+
format: "esm",
|
67
|
+
preferConst: true,
|
68
|
+
exports: "named",
|
69
|
+
banner
|
70
|
+
}
|
71
|
+
}),
|
72
|
+
|
73
|
+
// Browser UMD bundle for CDN
|
74
|
+
...buildConfig({
|
75
|
+
input: defaultInput,
|
54
76
|
es5: true,
|
55
77
|
output: {
|
56
|
-
file: `dist/${outputFileName}`,
|
78
|
+
file: `dist/${outputFileName}.js`,
|
57
79
|
name,
|
58
80
|
format: "umd",
|
59
81
|
exports: "default",
|
@@ -61,18 +83,23 @@ export default async () => {
|
|
61
83
|
}
|
62
84
|
}),
|
63
85
|
|
86
|
+
// Browser CJS bundle
|
64
87
|
...buildConfig({
|
88
|
+
input: defaultInput,
|
89
|
+
es5: false,
|
90
|
+
minifiedVersion: false,
|
65
91
|
output: {
|
66
|
-
file: `dist/
|
67
|
-
|
68
|
-
|
69
|
-
exports: "
|
92
|
+
file: `dist/browser/${name}.cjs`,
|
93
|
+
name,
|
94
|
+
format: "cjs",
|
95
|
+
exports: "default",
|
70
96
|
banner
|
71
97
|
}
|
72
98
|
}),
|
73
|
-
|
99
|
+
|
100
|
+
// Node.js commonjs bundle
|
74
101
|
{
|
75
|
-
input,
|
102
|
+
input: defaultInput,
|
76
103
|
output: {
|
77
104
|
file: `dist/node/${name}.cjs`,
|
78
105
|
format: "cjs",
|
package/tsconfig.json
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"compilerOptions": {
|
3
|
-
"module": "
|
3
|
+
"module": "node16",
|
4
4
|
"lib": ["dom", "es2015"],
|
5
5
|
"types": [],
|
6
|
-
"moduleResolution": "node",
|
7
6
|
"strict": true,
|
8
|
-
"noEmit": true
|
9
|
-
"baseUrl": ".",
|
10
|
-
"paths": {
|
11
|
-
"axios": ["."]
|
12
|
-
}
|
7
|
+
"noEmit": true
|
13
8
|
}
|
14
9
|
}
|
package/tslint.json
CHANGED
package/lib/adapters/index.js
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
import utils from '../utils.js';
|
2
|
-
import httpAdapter from './http.js';
|
3
|
-
import xhrAdapter from './xhr.js';
|
4
|
-
|
5
|
-
const adapters = {
|
6
|
-
http: httpAdapter,
|
7
|
-
xhr: xhrAdapter
|
8
|
-
}
|
9
|
-
|
10
|
-
export default {
|
11
|
-
getAdapter: (nameOrAdapter) => {
|
12
|
-
if(utils.isString(nameOrAdapter)){
|
13
|
-
const adapter = adapters[nameOrAdapter];
|
14
|
-
|
15
|
-
if (!nameOrAdapter) {
|
16
|
-
throw Error(
|
17
|
-
utils.hasOwnProp(nameOrAdapter) ?
|
18
|
-
`Adapter '${nameOrAdapter}' is not available in the build` :
|
19
|
-
`Can not resolve adapter '${nameOrAdapter}'`
|
20
|
-
);
|
21
|
-
}
|
22
|
-
|
23
|
-
return adapter
|
24
|
-
}
|
25
|
-
|
26
|
-
if (!utils.isFunction(nameOrAdapter)) {
|
27
|
-
throw new TypeError('adapter is not a function');
|
28
|
-
}
|
29
|
-
|
30
|
-
return nameOrAdapter;
|
31
|
-
},
|
32
|
-
adapters
|
33
|
-
}
|