axios 0.27.0 → 1.0.0-alpha.1
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 +124 -927
- package/LICENSE +4 -16
- package/README.md +257 -69
- package/SECURITY.md +3 -3
- package/UPGRADE_GUIDE.md +1 -166
- package/bin/ssl_hotfix.js +22 -0
- package/dist/axios.js +1956 -3592
- package/dist/axios.js.map +1 -0
- package/dist/axios.min.js +2 -4
- package/dist/axios.min.js.map +1 -0
- package/dist/esm/axios.js +2336 -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 +96 -18
- package/lib/adapters/http.js +154 -113
- package/lib/adapters/xhr.js +12 -11
- package/lib/axios.js +5 -1
- package/lib/cancel/CancelToken.js +4 -5
- package/lib/cancel/CanceledError.js +4 -2
- package/lib/core/Axios.js +2 -1
- package/lib/core/AxiosError.js +12 -1
- package/lib/core/InterceptorManager.js +9 -0
- package/lib/core/dispatchRequest.js +7 -0
- package/lib/core/transformData.js +3 -2
- package/lib/defaults/index.js +45 -13
- package/lib/{defaults/env → env/classes}/FormData.js +0 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/AxiosURLSearchParams.js +42 -0
- package/lib/helpers/bind.js +1 -5
- package/lib/helpers/buildURL.js +14 -37
- package/lib/helpers/formDataToJSON.js +71 -0
- package/lib/helpers/fromDataURI.js +51 -0
- package/lib/helpers/isURLSameOrigin.js +12 -12
- package/lib/helpers/parseHeaders.js +2 -2
- package/lib/helpers/parseProtocol.js +6 -0
- package/lib/helpers/toFormData.js +141 -34
- package/lib/helpers/toURLEncodedForm.js +18 -0
- 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 +57 -34
- package/package.json +18 -8
- package/rollup.config.js +60 -0
- package/dist/axios.map +0 -1
- package/dist/axios.min.map +0 -1
@@ -0,0 +1,2336 @@
|
|
1
|
+
// axios v1.0.0-alpha.1 Copyright (c) 2022 Matt Zabriskie
|
2
|
+
var bind = function bind(fn, thisArg) {
|
3
|
+
return function wrap() {
|
4
|
+
return fn.apply(thisArg, arguments);
|
5
|
+
};
|
6
|
+
};
|
7
|
+
|
8
|
+
// utils is a library of generic helper functions non-specific to axios
|
9
|
+
|
10
|
+
var toString = Object.prototype.toString;
|
11
|
+
|
12
|
+
// eslint-disable-next-line func-names
|
13
|
+
var kindOf = (function(cache) {
|
14
|
+
// eslint-disable-next-line func-names
|
15
|
+
return function(thing) {
|
16
|
+
var str = toString.call(thing);
|
17
|
+
return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
|
18
|
+
};
|
19
|
+
})(Object.create(null));
|
20
|
+
|
21
|
+
function kindOfTest(type) {
|
22
|
+
type = type.toLowerCase();
|
23
|
+
return function isKindOf(thing) {
|
24
|
+
return kindOf(thing) === type;
|
25
|
+
};
|
26
|
+
}
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Determine if a value is an Array
|
30
|
+
*
|
31
|
+
* @param {Object} val The value to test
|
32
|
+
* @returns {boolean} True if value is an Array, otherwise false
|
33
|
+
*/
|
34
|
+
function isArray(val) {
|
35
|
+
return Array.isArray(val);
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Determine if a value is undefined
|
40
|
+
*
|
41
|
+
* @param {Object} val The value to test
|
42
|
+
* @returns {boolean} True if the value is undefined, otherwise false
|
43
|
+
*/
|
44
|
+
function isUndefined(val) {
|
45
|
+
return typeof val === 'undefined';
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Determine if a value is a Buffer
|
50
|
+
*
|
51
|
+
* @param {Object} val The value to test
|
52
|
+
* @returns {boolean} True if value is a Buffer, otherwise false
|
53
|
+
*/
|
54
|
+
function isBuffer(val) {
|
55
|
+
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
56
|
+
&& typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Determine if a value is an ArrayBuffer
|
61
|
+
*
|
62
|
+
* @function
|
63
|
+
* @param {Object} val The value to test
|
64
|
+
* @returns {boolean} True if value is an ArrayBuffer, otherwise false
|
65
|
+
*/
|
66
|
+
var isArrayBuffer = kindOfTest('ArrayBuffer');
|
67
|
+
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Determine if a value is a view on an ArrayBuffer
|
71
|
+
*
|
72
|
+
* @param {Object} val The value to test
|
73
|
+
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
|
74
|
+
*/
|
75
|
+
function isArrayBufferView(val) {
|
76
|
+
var result;
|
77
|
+
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
|
78
|
+
result = ArrayBuffer.isView(val);
|
79
|
+
} else {
|
80
|
+
result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
|
81
|
+
}
|
82
|
+
return result;
|
83
|
+
}
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Determine if a value is a String
|
87
|
+
*
|
88
|
+
* @param {Object} val The value to test
|
89
|
+
* @returns {boolean} True if value is a String, otherwise false
|
90
|
+
*/
|
91
|
+
function isString(val) {
|
92
|
+
return typeof val === 'string';
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Determine if a value is a Number
|
97
|
+
*
|
98
|
+
* @param {Object} val The value to test
|
99
|
+
* @returns {boolean} True if value is a Number, otherwise false
|
100
|
+
*/
|
101
|
+
function isNumber(val) {
|
102
|
+
return typeof val === 'number';
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Determine if a value is an Object
|
107
|
+
*
|
108
|
+
* @param {Object} val The value to test
|
109
|
+
* @returns {boolean} True if value is an Object, otherwise false
|
110
|
+
*/
|
111
|
+
function isObject(val) {
|
112
|
+
return val !== null && typeof val === 'object';
|
113
|
+
}
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Determine if a value is a plain Object
|
117
|
+
*
|
118
|
+
* @param {Object} val The value to test
|
119
|
+
* @return {boolean} True if value is a plain Object, otherwise false
|
120
|
+
*/
|
121
|
+
function isPlainObject(val) {
|
122
|
+
if (kindOf(val) !== 'object') {
|
123
|
+
return false;
|
124
|
+
}
|
125
|
+
|
126
|
+
var prototype = Object.getPrototypeOf(val);
|
127
|
+
return prototype === null || prototype === Object.prototype;
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Determine if a value is a Date
|
132
|
+
*
|
133
|
+
* @function
|
134
|
+
* @param {Object} val The value to test
|
135
|
+
* @returns {boolean} True if value is a Date, otherwise false
|
136
|
+
*/
|
137
|
+
var isDate = kindOfTest('Date');
|
138
|
+
|
139
|
+
/**
|
140
|
+
* Determine if a value is a File
|
141
|
+
*
|
142
|
+
* @function
|
143
|
+
* @param {Object} val The value to test
|
144
|
+
* @returns {boolean} True if value is a File, otherwise false
|
145
|
+
*/
|
146
|
+
var isFile = kindOfTest('File');
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Determine if a value is a Blob
|
150
|
+
*
|
151
|
+
* @function
|
152
|
+
* @param {Object} val The value to test
|
153
|
+
* @returns {boolean} True if value is a Blob, otherwise false
|
154
|
+
*/
|
155
|
+
var isBlob = kindOfTest('Blob');
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Determine if a value is a FileList
|
159
|
+
*
|
160
|
+
* @function
|
161
|
+
* @param {Object} val The value to test
|
162
|
+
* @returns {boolean} True if value is a File, otherwise false
|
163
|
+
*/
|
164
|
+
var isFileList = kindOfTest('FileList');
|
165
|
+
|
166
|
+
/**
|
167
|
+
* Determine if a value is a Function
|
168
|
+
*
|
169
|
+
* @param {Object} val The value to test
|
170
|
+
* @returns {boolean} True if value is a Function, otherwise false
|
171
|
+
*/
|
172
|
+
function isFunction(val) {
|
173
|
+
return toString.call(val) === '[object Function]';
|
174
|
+
}
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Determine if a value is a Stream
|
178
|
+
*
|
179
|
+
* @param {Object} val The value to test
|
180
|
+
* @returns {boolean} True if value is a Stream, otherwise false
|
181
|
+
*/
|
182
|
+
function isStream(val) {
|
183
|
+
return isObject(val) && isFunction(val.pipe);
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Determine if a value is a FormData
|
188
|
+
*
|
189
|
+
* @param {Object} thing The value to test
|
190
|
+
* @returns {boolean} True if value is an FormData, otherwise false
|
191
|
+
*/
|
192
|
+
function isFormData(thing) {
|
193
|
+
var pattern = '[object FormData]';
|
194
|
+
return thing && (
|
195
|
+
(typeof FormData === 'function' && thing instanceof FormData) ||
|
196
|
+
toString.call(thing) === pattern ||
|
197
|
+
(isFunction(thing.toString) && thing.toString() === pattern)
|
198
|
+
);
|
199
|
+
}
|
200
|
+
|
201
|
+
/**
|
202
|
+
* Determine if a value is a URLSearchParams object
|
203
|
+
* @function
|
204
|
+
* @param {Object} val The value to test
|
205
|
+
* @returns {boolean} True if value is a URLSearchParams object, otherwise false
|
206
|
+
*/
|
207
|
+
var isURLSearchParams = kindOfTest('URLSearchParams');
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Trim excess whitespace off the beginning and end of a string
|
211
|
+
*
|
212
|
+
* @param {String} str The String to trim
|
213
|
+
* @returns {String} The String freed of excess whitespace
|
214
|
+
*/
|
215
|
+
function trim(str) {
|
216
|
+
return str.trim ? str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
217
|
+
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Determine if we're running in a standard browser environment
|
221
|
+
*
|
222
|
+
* This allows axios to run in a web worker, and react-native.
|
223
|
+
* Both environments support XMLHttpRequest, but not fully standard globals.
|
224
|
+
*
|
225
|
+
* web workers:
|
226
|
+
* typeof window -> undefined
|
227
|
+
* typeof document -> undefined
|
228
|
+
*
|
229
|
+
* react-native:
|
230
|
+
* navigator.product -> 'ReactNative'
|
231
|
+
* nativescript
|
232
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
233
|
+
*/
|
234
|
+
function isStandardBrowserEnv() {
|
235
|
+
var product;
|
236
|
+
if (typeof navigator !== 'undefined' && (
|
237
|
+
(product = navigator.product) === 'ReactNative' ||
|
238
|
+
product === 'NativeScript' ||
|
239
|
+
product === 'NS')
|
240
|
+
) {
|
241
|
+
return false;
|
242
|
+
}
|
243
|
+
|
244
|
+
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Iterate over an Array or an Object invoking a function for each item.
|
249
|
+
*
|
250
|
+
* If `obj` is an Array callback will be called passing
|
251
|
+
* the value, index, and complete array for each item.
|
252
|
+
*
|
253
|
+
* If 'obj' is an Object callback will be called passing
|
254
|
+
* the value, key, and complete object for each property.
|
255
|
+
*
|
256
|
+
* @param {Object|Array} obj The object to iterate
|
257
|
+
* @param {Function} fn The callback to invoke for each item
|
258
|
+
*/
|
259
|
+
function forEach(obj, fn) {
|
260
|
+
// Don't bother if no value provided
|
261
|
+
if (obj === null || typeof obj === 'undefined') {
|
262
|
+
return;
|
263
|
+
}
|
264
|
+
|
265
|
+
// Force an array if not already something iterable
|
266
|
+
if (typeof obj !== 'object') {
|
267
|
+
/*eslint no-param-reassign:0*/
|
268
|
+
obj = [obj];
|
269
|
+
}
|
270
|
+
|
271
|
+
if (isArray(obj)) {
|
272
|
+
// Iterate over array values
|
273
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
274
|
+
fn.call(null, obj[i], i, obj);
|
275
|
+
}
|
276
|
+
} else {
|
277
|
+
// Iterate over object keys
|
278
|
+
for (var key in obj) {
|
279
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
280
|
+
fn.call(null, obj[key], key, obj);
|
281
|
+
}
|
282
|
+
}
|
283
|
+
}
|
284
|
+
}
|
285
|
+
|
286
|
+
/**
|
287
|
+
* Accepts varargs expecting each argument to be an object, then
|
288
|
+
* immutably merges the properties of each object and returns result.
|
289
|
+
*
|
290
|
+
* When multiple objects contain the same key the later object in
|
291
|
+
* the arguments list will take precedence.
|
292
|
+
*
|
293
|
+
* Example:
|
294
|
+
*
|
295
|
+
* ```js
|
296
|
+
* var result = merge({foo: 123}, {foo: 456});
|
297
|
+
* console.log(result.foo); // outputs 456
|
298
|
+
* ```
|
299
|
+
*
|
300
|
+
* @param {Object} obj1 Object to merge
|
301
|
+
* @returns {Object} Result of all merge properties
|
302
|
+
*/
|
303
|
+
function merge(/* obj1, obj2, obj3, ... */) {
|
304
|
+
var result = {};
|
305
|
+
function assignValue(val, key) {
|
306
|
+
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
307
|
+
result[key] = merge(result[key], val);
|
308
|
+
} else if (isPlainObject(val)) {
|
309
|
+
result[key] = merge({}, val);
|
310
|
+
} else if (isArray(val)) {
|
311
|
+
result[key] = val.slice();
|
312
|
+
} else {
|
313
|
+
result[key] = val;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
318
|
+
forEach(arguments[i], assignValue);
|
319
|
+
}
|
320
|
+
return result;
|
321
|
+
}
|
322
|
+
|
323
|
+
/**
|
324
|
+
* Extends object a by mutably adding to it the properties of object b.
|
325
|
+
*
|
326
|
+
* @param {Object} a The object to be extended
|
327
|
+
* @param {Object} b The object to copy properties from
|
328
|
+
* @param {Object} thisArg The object to bind function to
|
329
|
+
* @return {Object} The resulting value of object a
|
330
|
+
*/
|
331
|
+
function extend(a, b, thisArg) {
|
332
|
+
forEach(b, function assignValue(val, key) {
|
333
|
+
if (thisArg && typeof val === 'function') {
|
334
|
+
a[key] = bind(val, thisArg);
|
335
|
+
} else {
|
336
|
+
a[key] = val;
|
337
|
+
}
|
338
|
+
});
|
339
|
+
return a;
|
340
|
+
}
|
341
|
+
|
342
|
+
/**
|
343
|
+
* Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
344
|
+
*
|
345
|
+
* @param {string} content with BOM
|
346
|
+
* @return {string} content value without BOM
|
347
|
+
*/
|
348
|
+
function stripBOM(content) {
|
349
|
+
if (content.charCodeAt(0) === 0xFEFF) {
|
350
|
+
content = content.slice(1);
|
351
|
+
}
|
352
|
+
return content;
|
353
|
+
}
|
354
|
+
|
355
|
+
/**
|
356
|
+
* Inherit the prototype methods from one constructor into another
|
357
|
+
* @param {function} constructor
|
358
|
+
* @param {function} superConstructor
|
359
|
+
* @param {object} [props]
|
360
|
+
* @param {object} [descriptors]
|
361
|
+
*/
|
362
|
+
|
363
|
+
function inherits(constructor, superConstructor, props, descriptors) {
|
364
|
+
constructor.prototype = Object.create(superConstructor.prototype, descriptors);
|
365
|
+
constructor.prototype.constructor = constructor;
|
366
|
+
props && Object.assign(constructor.prototype, props);
|
367
|
+
}
|
368
|
+
|
369
|
+
/**
|
370
|
+
* Resolve object with deep prototype chain to a flat object
|
371
|
+
* @param {Object} sourceObj source object
|
372
|
+
* @param {Object} [destObj]
|
373
|
+
* @param {Function|Boolean} [filter]
|
374
|
+
* @param {Function} [propFilter]
|
375
|
+
* @returns {Object}
|
376
|
+
*/
|
377
|
+
|
378
|
+
function toFlatObject(sourceObj, destObj, filter, propFilter) {
|
379
|
+
var props;
|
380
|
+
var i;
|
381
|
+
var prop;
|
382
|
+
var merged = {};
|
383
|
+
|
384
|
+
destObj = destObj || {};
|
385
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
386
|
+
if (sourceObj == null) return destObj;
|
387
|
+
|
388
|
+
do {
|
389
|
+
props = Object.getOwnPropertyNames(sourceObj);
|
390
|
+
i = props.length;
|
391
|
+
while (i-- > 0) {
|
392
|
+
prop = props[i];
|
393
|
+
if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
|
394
|
+
destObj[prop] = sourceObj[prop];
|
395
|
+
merged[prop] = true;
|
396
|
+
}
|
397
|
+
}
|
398
|
+
sourceObj = filter !== false && Object.getPrototypeOf(sourceObj);
|
399
|
+
} while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
|
400
|
+
|
401
|
+
return destObj;
|
402
|
+
}
|
403
|
+
|
404
|
+
/*
|
405
|
+
* determines whether a string ends with the characters of a specified string
|
406
|
+
* @param {String} str
|
407
|
+
* @param {String} searchString
|
408
|
+
* @param {Number} [position= 0]
|
409
|
+
* @returns {boolean}
|
410
|
+
*/
|
411
|
+
function endsWith(str, searchString, position) {
|
412
|
+
str = String(str);
|
413
|
+
if (position === undefined || position > str.length) {
|
414
|
+
position = str.length;
|
415
|
+
}
|
416
|
+
position -= searchString.length;
|
417
|
+
var lastIndex = str.indexOf(searchString, position);
|
418
|
+
return lastIndex !== -1 && lastIndex === position;
|
419
|
+
}
|
420
|
+
|
421
|
+
|
422
|
+
/**
|
423
|
+
* Returns new array from array like object or null if failed
|
424
|
+
* @param {*} [thing]
|
425
|
+
* @returns {?Array}
|
426
|
+
*/
|
427
|
+
function toArray(thing) {
|
428
|
+
if (!thing) return null;
|
429
|
+
if (isArray(thing)) return thing;
|
430
|
+
var i = thing.length;
|
431
|
+
if (!isNumber(i)) return null;
|
432
|
+
var arr = new Array(i);
|
433
|
+
while (i-- > 0) {
|
434
|
+
arr[i] = thing[i];
|
435
|
+
}
|
436
|
+
return arr;
|
437
|
+
}
|
438
|
+
|
439
|
+
// eslint-disable-next-line func-names
|
440
|
+
var isTypedArray = (function(TypedArray) {
|
441
|
+
// eslint-disable-next-line func-names
|
442
|
+
return function(thing) {
|
443
|
+
return TypedArray && thing instanceof TypedArray;
|
444
|
+
};
|
445
|
+
})(typeof Uint8Array !== 'undefined' && Object.getPrototypeOf(Uint8Array));
|
446
|
+
|
447
|
+
function forEachEntry(obj, fn) {
|
448
|
+
var generator = obj && obj[Symbol.iterator];
|
449
|
+
|
450
|
+
var iterator = generator.call(obj);
|
451
|
+
|
452
|
+
var result;
|
453
|
+
|
454
|
+
while ((result = iterator.next()) && !result.done) {
|
455
|
+
var pair = result.value;
|
456
|
+
fn.call(obj, pair[0], pair[1]);
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
function matchAll(regExp, str) {
|
461
|
+
var matches;
|
462
|
+
var arr = [];
|
463
|
+
|
464
|
+
while ((matches = regExp.exec(str)) !== null) {
|
465
|
+
arr.push(matches);
|
466
|
+
}
|
467
|
+
|
468
|
+
return arr;
|
469
|
+
}
|
470
|
+
|
471
|
+
var isHTMLForm = kindOfTest('HTMLFormElement');
|
472
|
+
|
473
|
+
var hasOwnProperty = (function resolver(_hasOwnProperty) {
|
474
|
+
return function(obj, prop) {
|
475
|
+
return _hasOwnProperty.call(obj, prop);
|
476
|
+
};
|
477
|
+
})(Object.prototype.hasOwnProperty);
|
478
|
+
|
479
|
+
var utils = {
|
480
|
+
isArray: isArray,
|
481
|
+
isArrayBuffer: isArrayBuffer,
|
482
|
+
isBuffer: isBuffer,
|
483
|
+
isFormData: isFormData,
|
484
|
+
isArrayBufferView: isArrayBufferView,
|
485
|
+
isString: isString,
|
486
|
+
isNumber: isNumber,
|
487
|
+
isObject: isObject,
|
488
|
+
isPlainObject: isPlainObject,
|
489
|
+
isUndefined: isUndefined,
|
490
|
+
isDate: isDate,
|
491
|
+
isFile: isFile,
|
492
|
+
isBlob: isBlob,
|
493
|
+
isFunction: isFunction,
|
494
|
+
isStream: isStream,
|
495
|
+
isURLSearchParams: isURLSearchParams,
|
496
|
+
isStandardBrowserEnv: isStandardBrowserEnv,
|
497
|
+
forEach: forEach,
|
498
|
+
merge: merge,
|
499
|
+
extend: extend,
|
500
|
+
trim: trim,
|
501
|
+
stripBOM: stripBOM,
|
502
|
+
inherits: inherits,
|
503
|
+
toFlatObject: toFlatObject,
|
504
|
+
kindOf: kindOf,
|
505
|
+
kindOfTest: kindOfTest,
|
506
|
+
endsWith: endsWith,
|
507
|
+
toArray: toArray,
|
508
|
+
isTypedArray: isTypedArray,
|
509
|
+
isFileList: isFileList,
|
510
|
+
forEachEntry: forEachEntry,
|
511
|
+
matchAll: matchAll,
|
512
|
+
isHTMLForm: isHTMLForm,
|
513
|
+
hasOwnProperty: hasOwnProperty
|
514
|
+
};
|
515
|
+
|
516
|
+
/**
|
517
|
+
* Create an Error with the specified message, config, error code, request and response.
|
518
|
+
*
|
519
|
+
* @param {string} message The error message.
|
520
|
+
* @param {string} [code] The error code (for example, 'ECONNABORTED').
|
521
|
+
* @param {Object} [config] The config.
|
522
|
+
* @param {Object} [request] The request.
|
523
|
+
* @param {Object} [response] The response.
|
524
|
+
* @returns {Error} The created error.
|
525
|
+
*/
|
526
|
+
function AxiosError(message, code, config, request, response) {
|
527
|
+
Error.call(this);
|
528
|
+
|
529
|
+
if (Error.captureStackTrace) {
|
530
|
+
Error.captureStackTrace(this, this.constructor);
|
531
|
+
} else {
|
532
|
+
this.stack = (new Error()).stack;
|
533
|
+
}
|
534
|
+
|
535
|
+
this.message = message;
|
536
|
+
this.name = 'AxiosError';
|
537
|
+
code && (this.code = code);
|
538
|
+
config && (this.config = config);
|
539
|
+
request && (this.request = request);
|
540
|
+
response && (this.response = response);
|
541
|
+
}
|
542
|
+
|
543
|
+
utils.inherits(AxiosError, Error, {
|
544
|
+
toJSON: function toJSON() {
|
545
|
+
return {
|
546
|
+
// Standard
|
547
|
+
message: this.message,
|
548
|
+
name: this.name,
|
549
|
+
// Microsoft
|
550
|
+
description: this.description,
|
551
|
+
number: this.number,
|
552
|
+
// Mozilla
|
553
|
+
fileName: this.fileName,
|
554
|
+
lineNumber: this.lineNumber,
|
555
|
+
columnNumber: this.columnNumber,
|
556
|
+
stack: this.stack,
|
557
|
+
// Axios
|
558
|
+
config: this.config,
|
559
|
+
code: this.code,
|
560
|
+
status: this.response && this.response.status ? this.response.status : null
|
561
|
+
};
|
562
|
+
}
|
563
|
+
});
|
564
|
+
|
565
|
+
var prototype$1 = AxiosError.prototype;
|
566
|
+
var descriptors = {};
|
567
|
+
|
568
|
+
[
|
569
|
+
'ERR_BAD_OPTION_VALUE',
|
570
|
+
'ERR_BAD_OPTION',
|
571
|
+
'ECONNABORTED',
|
572
|
+
'ETIMEDOUT',
|
573
|
+
'ERR_NETWORK',
|
574
|
+
'ERR_FR_TOO_MANY_REDIRECTS',
|
575
|
+
'ERR_DEPRECATED',
|
576
|
+
'ERR_BAD_RESPONSE',
|
577
|
+
'ERR_BAD_REQUEST',
|
578
|
+
'ERR_CANCELED',
|
579
|
+
'ERR_NOT_SUPPORT',
|
580
|
+
'ERR_INVALID_URL'
|
581
|
+
// eslint-disable-next-line func-names
|
582
|
+
].forEach(function(code) {
|
583
|
+
descriptors[code] = {value: code};
|
584
|
+
});
|
585
|
+
|
586
|
+
Object.defineProperties(AxiosError, descriptors);
|
587
|
+
Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
|
588
|
+
|
589
|
+
// eslint-disable-next-line func-names
|
590
|
+
AxiosError.from = function(error, code, config, request, response, customProps) {
|
591
|
+
var axiosError = Object.create(prototype$1);
|
592
|
+
|
593
|
+
utils.toFlatObject(error, axiosError, function filter(obj) {
|
594
|
+
return obj !== Error.prototype;
|
595
|
+
});
|
596
|
+
|
597
|
+
AxiosError.call(axiosError, error.message, code, config, request, response);
|
598
|
+
|
599
|
+
axiosError.cause = error;
|
600
|
+
|
601
|
+
axiosError.name = error.name;
|
602
|
+
|
603
|
+
customProps && Object.assign(axiosError, customProps);
|
604
|
+
|
605
|
+
return axiosError;
|
606
|
+
};
|
607
|
+
|
608
|
+
var AxiosError_1 = AxiosError;
|
609
|
+
|
610
|
+
/* eslint-env browser */
|
611
|
+
var browser$1 = typeof self == 'object' ? self.FormData : window.FormData;
|
612
|
+
|
613
|
+
// eslint-disable-next-line strict
|
614
|
+
var FormData$1 = browser$1;
|
615
|
+
|
616
|
+
function isVisitable(thing) {
|
617
|
+
return utils.isPlainObject(thing) || utils.isArray(thing);
|
618
|
+
}
|
619
|
+
|
620
|
+
function removeBrackets(key) {
|
621
|
+
return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
|
622
|
+
}
|
623
|
+
|
624
|
+
function renderKey(path, key, dots) {
|
625
|
+
if (!path) return key;
|
626
|
+
return path.concat(key).map(function each(token, i) {
|
627
|
+
// eslint-disable-next-line no-param-reassign
|
628
|
+
token = removeBrackets(token);
|
629
|
+
return !dots && i ? '[' + token + ']' : token;
|
630
|
+
}).join(dots ? '.' : '');
|
631
|
+
}
|
632
|
+
|
633
|
+
function isFlatArray(arr) {
|
634
|
+
return utils.isArray(arr) && !arr.some(isVisitable);
|
635
|
+
}
|
636
|
+
|
637
|
+
var predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
|
638
|
+
return /^is[A-Z]/.test(prop);
|
639
|
+
});
|
640
|
+
|
641
|
+
function isSpecCompliant(thing) {
|
642
|
+
return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
|
643
|
+
}
|
644
|
+
|
645
|
+
/**
|
646
|
+
* Convert a data object to FormData
|
647
|
+
* @param {Object} obj
|
648
|
+
* @param {?Object} [formData]
|
649
|
+
* @param {?Object} [options]
|
650
|
+
* @param {Function} [options.visitor]
|
651
|
+
* @param {Boolean} [options.metaTokens = true]
|
652
|
+
* @param {Boolean} [options.dots = false]
|
653
|
+
* @param {?Boolean} [options.indexes = false]
|
654
|
+
* @returns {Object}
|
655
|
+
**/
|
656
|
+
|
657
|
+
function toFormData(obj, formData, options) {
|
658
|
+
if (!utils.isObject(obj)) {
|
659
|
+
throw new TypeError('target must be an object');
|
660
|
+
}
|
661
|
+
|
662
|
+
// eslint-disable-next-line no-param-reassign
|
663
|
+
formData = formData || new (FormData$1 || FormData)();
|
664
|
+
|
665
|
+
// eslint-disable-next-line no-param-reassign
|
666
|
+
options = utils.toFlatObject(options, {
|
667
|
+
metaTokens: true,
|
668
|
+
dots: false,
|
669
|
+
indexes: false
|
670
|
+
}, false, function defined(option, source) {
|
671
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
672
|
+
return !utils.isUndefined(source[option]);
|
673
|
+
});
|
674
|
+
|
675
|
+
var metaTokens = options.metaTokens;
|
676
|
+
// eslint-disable-next-line no-use-before-define
|
677
|
+
var visitor = options.visitor || defaultVisitor;
|
678
|
+
var dots = options.dots;
|
679
|
+
var indexes = options.indexes;
|
680
|
+
var _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
|
681
|
+
var useBlob = _Blob && isSpecCompliant(formData);
|
682
|
+
|
683
|
+
if (!utils.isFunction(visitor)) {
|
684
|
+
throw new TypeError('visitor must be a function');
|
685
|
+
}
|
686
|
+
|
687
|
+
function convertValue(value) {
|
688
|
+
if (value === null) return '';
|
689
|
+
|
690
|
+
if (utils.isDate(value)) {
|
691
|
+
return value.toISOString();
|
692
|
+
}
|
693
|
+
|
694
|
+
if (!useBlob && utils.isBlob(value)) {
|
695
|
+
throw new AxiosError_1('Blob is not supported. Use a Buffer instead.');
|
696
|
+
}
|
697
|
+
|
698
|
+
if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
|
699
|
+
return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
|
700
|
+
}
|
701
|
+
|
702
|
+
return value;
|
703
|
+
}
|
704
|
+
|
705
|
+
/**
|
706
|
+
*
|
707
|
+
* @param {*} value
|
708
|
+
* @param {String|Number} key
|
709
|
+
* @param {Array<String|Number>} path
|
710
|
+
* @this {FormData}
|
711
|
+
* @returns {boolean} return true to visit the each prop of the value recursively
|
712
|
+
*/
|
713
|
+
function defaultVisitor(value, key, path) {
|
714
|
+
var arr = value;
|
715
|
+
|
716
|
+
if (value && !path && typeof value === 'object') {
|
717
|
+
if (utils.endsWith(key, '{}')) {
|
718
|
+
// eslint-disable-next-line no-param-reassign
|
719
|
+
key = metaTokens ? key : key.slice(0, -2);
|
720
|
+
// eslint-disable-next-line no-param-reassign
|
721
|
+
value = JSON.stringify(value);
|
722
|
+
} else if (
|
723
|
+
(utils.isArray(value) && isFlatArray(value)) ||
|
724
|
+
(utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
|
725
|
+
)) {
|
726
|
+
// eslint-disable-next-line no-param-reassign
|
727
|
+
key = removeBrackets(key);
|
728
|
+
|
729
|
+
arr.forEach(function each(el, index) {
|
730
|
+
!utils.isUndefined(el) && formData.append(
|
731
|
+
// eslint-disable-next-line no-nested-ternary
|
732
|
+
indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
|
733
|
+
convertValue(el)
|
734
|
+
);
|
735
|
+
});
|
736
|
+
return false;
|
737
|
+
}
|
738
|
+
}
|
739
|
+
|
740
|
+
if (isVisitable(value)) {
|
741
|
+
return true;
|
742
|
+
}
|
743
|
+
|
744
|
+
formData.append(renderKey(path, key, dots), convertValue(value));
|
745
|
+
|
746
|
+
return false;
|
747
|
+
}
|
748
|
+
|
749
|
+
var stack = [];
|
750
|
+
|
751
|
+
var exposedHelpers = Object.assign(predicates, {
|
752
|
+
defaultVisitor: defaultVisitor,
|
753
|
+
convertValue: convertValue,
|
754
|
+
isVisitable: isVisitable
|
755
|
+
});
|
756
|
+
|
757
|
+
function build(value, path) {
|
758
|
+
if (utils.isUndefined(value)) return;
|
759
|
+
|
760
|
+
if (stack.indexOf(value) !== -1) {
|
761
|
+
throw Error('Circular reference detected in ' + path.join('.'));
|
762
|
+
}
|
763
|
+
|
764
|
+
stack.push(value);
|
765
|
+
|
766
|
+
utils.forEach(value, function each(el, key) {
|
767
|
+
var result = !utils.isUndefined(el) && visitor.call(
|
768
|
+
formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
|
769
|
+
);
|
770
|
+
|
771
|
+
if (result === true) {
|
772
|
+
build(el, path ? path.concat(key) : [key]);
|
773
|
+
}
|
774
|
+
});
|
775
|
+
|
776
|
+
stack.pop();
|
777
|
+
}
|
778
|
+
|
779
|
+
if (!utils.isObject(obj)) {
|
780
|
+
throw new TypeError('data must be an object');
|
781
|
+
}
|
782
|
+
|
783
|
+
build(obj);
|
784
|
+
|
785
|
+
return formData;
|
786
|
+
}
|
787
|
+
|
788
|
+
var toFormData_1 = toFormData;
|
789
|
+
|
790
|
+
function encode$1(str) {
|
791
|
+
var charMap = {
|
792
|
+
'!': '%21',
|
793
|
+
"'": '%27',
|
794
|
+
'(': '%28',
|
795
|
+
')': '%29',
|
796
|
+
'~': '%7E',
|
797
|
+
'%20': '+',
|
798
|
+
'%00': '\x00'
|
799
|
+
};
|
800
|
+
return encodeURIComponent(str).replace(/[!'\(\)~]|%20|%00/g, function replacer(match) {
|
801
|
+
return charMap[match];
|
802
|
+
});
|
803
|
+
}
|
804
|
+
|
805
|
+
function AxiosURLSearchParams(params, options) {
|
806
|
+
this._pairs = [];
|
807
|
+
|
808
|
+
params && toFormData_1(params, this, options);
|
809
|
+
}
|
810
|
+
|
811
|
+
var prototype = AxiosURLSearchParams.prototype;
|
812
|
+
|
813
|
+
prototype.append = function append(name, value) {
|
814
|
+
this._pairs.push([name, value]);
|
815
|
+
};
|
816
|
+
|
817
|
+
prototype.toString = function toString(encoder) {
|
818
|
+
var _encode = encoder ? function(value) {
|
819
|
+
return encoder.call(this, value, encode$1);
|
820
|
+
} : encode$1;
|
821
|
+
|
822
|
+
return this._pairs.map(function each(pair) {
|
823
|
+
return _encode(pair[0]) + '=' + _encode(pair[1]);
|
824
|
+
}, '').join('&');
|
825
|
+
};
|
826
|
+
|
827
|
+
var AxiosURLSearchParams_1 = AxiosURLSearchParams;
|
828
|
+
|
829
|
+
function encode(val) {
|
830
|
+
return encodeURIComponent(val).
|
831
|
+
replace(/%3A/gi, ':').
|
832
|
+
replace(/%24/g, '$').
|
833
|
+
replace(/%2C/gi, ',').
|
834
|
+
replace(/%20/g, '+').
|
835
|
+
replace(/%5B/gi, '[').
|
836
|
+
replace(/%5D/gi, ']');
|
837
|
+
}
|
838
|
+
|
839
|
+
/**
|
840
|
+
* Build a URL by appending params to the end
|
841
|
+
*
|
842
|
+
* @param {string} url The base of the url (e.g., http://www.google.com)
|
843
|
+
* @param {object} [params] The params to be appended
|
844
|
+
* @param {?object} options
|
845
|
+
* @returns {string} The formatted url
|
846
|
+
*/
|
847
|
+
var buildURL = function buildURL(url, params, options) {
|
848
|
+
/*eslint no-param-reassign:0*/
|
849
|
+
if (!params) {
|
850
|
+
return url;
|
851
|
+
}
|
852
|
+
|
853
|
+
var hashmarkIndex = url.indexOf('#');
|
854
|
+
|
855
|
+
if (hashmarkIndex !== -1) {
|
856
|
+
url = url.slice(0, hashmarkIndex);
|
857
|
+
}
|
858
|
+
|
859
|
+
var _encode = options && options.encode || encode;
|
860
|
+
|
861
|
+
var serializerParams = utils.isURLSearchParams(params) ?
|
862
|
+
params.toString() :
|
863
|
+
new AxiosURLSearchParams_1(params, options).toString(_encode);
|
864
|
+
|
865
|
+
if (serializerParams) {
|
866
|
+
url += (url.indexOf('?') === -1 ? '?' : '&') + serializerParams;
|
867
|
+
}
|
868
|
+
|
869
|
+
return url;
|
870
|
+
};
|
871
|
+
|
872
|
+
function InterceptorManager() {
|
873
|
+
this.handlers = [];
|
874
|
+
}
|
875
|
+
|
876
|
+
/**
|
877
|
+
* Add a new interceptor to the stack
|
878
|
+
*
|
879
|
+
* @param {Function} fulfilled The function to handle `then` for a `Promise`
|
880
|
+
* @param {Function} rejected The function to handle `reject` for a `Promise`
|
881
|
+
*
|
882
|
+
* @return {Number} An ID used to remove interceptor later
|
883
|
+
*/
|
884
|
+
InterceptorManager.prototype.use = function use(fulfilled, rejected, options) {
|
885
|
+
this.handlers.push({
|
886
|
+
fulfilled: fulfilled,
|
887
|
+
rejected: rejected,
|
888
|
+
synchronous: options ? options.synchronous : false,
|
889
|
+
runWhen: options ? options.runWhen : null
|
890
|
+
});
|
891
|
+
return this.handlers.length - 1;
|
892
|
+
};
|
893
|
+
|
894
|
+
/**
|
895
|
+
* Remove an interceptor from the stack
|
896
|
+
*
|
897
|
+
* @param {Number} id The ID that was returned by `use`
|
898
|
+
*/
|
899
|
+
InterceptorManager.prototype.eject = function eject(id) {
|
900
|
+
if (this.handlers[id]) {
|
901
|
+
this.handlers[id] = null;
|
902
|
+
}
|
903
|
+
};
|
904
|
+
|
905
|
+
/**
|
906
|
+
* Clear all interceptors from the stack
|
907
|
+
*/
|
908
|
+
InterceptorManager.prototype.clear = function clear() {
|
909
|
+
if (this.handlers) {
|
910
|
+
this.handlers = [];
|
911
|
+
}
|
912
|
+
};
|
913
|
+
|
914
|
+
/**
|
915
|
+
* Iterate over all the registered interceptors
|
916
|
+
*
|
917
|
+
* This method is particularly useful for skipping over any
|
918
|
+
* interceptors that may have become `null` calling `eject`.
|
919
|
+
*
|
920
|
+
* @param {Function} fn The function to call for each interceptor
|
921
|
+
*/
|
922
|
+
InterceptorManager.prototype.forEach = function forEach(fn) {
|
923
|
+
utils.forEach(this.handlers, function forEachHandler(h) {
|
924
|
+
if (h !== null) {
|
925
|
+
fn(h);
|
926
|
+
}
|
927
|
+
});
|
928
|
+
};
|
929
|
+
|
930
|
+
var InterceptorManager_1 = InterceptorManager;
|
931
|
+
|
932
|
+
var normalizeHeaderName = function normalizeHeaderName(headers, normalizedName) {
|
933
|
+
utils.forEach(headers, function processHeader(value, name) {
|
934
|
+
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
935
|
+
headers[normalizedName] = value;
|
936
|
+
delete headers[name];
|
937
|
+
}
|
938
|
+
});
|
939
|
+
};
|
940
|
+
|
941
|
+
var transitional = {
|
942
|
+
silentJSONParsing: true,
|
943
|
+
forcedJSONParsing: true,
|
944
|
+
clarifyTimeoutError: false
|
945
|
+
};
|
946
|
+
|
947
|
+
var URLSearchParams_1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams_1;
|
948
|
+
|
949
|
+
var FormData_1 = FormData;
|
950
|
+
|
951
|
+
var browser = {
|
952
|
+
isBrowser: true,
|
953
|
+
classes: {
|
954
|
+
URLSearchParams: URLSearchParams_1,
|
955
|
+
FormData: FormData_1,
|
956
|
+
Blob: Blob
|
957
|
+
},
|
958
|
+
protocols: ['http', 'https', 'file', 'blob', 'url']
|
959
|
+
};
|
960
|
+
|
961
|
+
var platform = browser;
|
962
|
+
|
963
|
+
var toURLEncodedForm = function toURLEncodedForm(data, options) {
|
964
|
+
return toFormData_1(data, new platform.classes.URLSearchParams(), Object.assign({
|
965
|
+
visitor: function(value, key, path, helpers) {
|
966
|
+
if (platform.isNode && utils.isBuffer(value)) {
|
967
|
+
this.append(key, value.toString('base64'));
|
968
|
+
return false;
|
969
|
+
}
|
970
|
+
|
971
|
+
return helpers.defaultVisitor.apply(this, arguments);
|
972
|
+
}
|
973
|
+
}, options));
|
974
|
+
};
|
975
|
+
|
976
|
+
function parsePropPath(name) {
|
977
|
+
// foo[x][y][z]
|
978
|
+
// foo.x.y.z
|
979
|
+
// foo-x-y-z
|
980
|
+
// foo x y z
|
981
|
+
return utils.matchAll(/\w+|\[(\w*)]/g, name).map(function(match) {
|
982
|
+
return match[0] === '[]' ? '' : match[1] || match[0];
|
983
|
+
});
|
984
|
+
}
|
985
|
+
|
986
|
+
function arrayToObject(arr) {
|
987
|
+
var obj = {};
|
988
|
+
var keys = Object.keys(arr);
|
989
|
+
var i;
|
990
|
+
var len = keys.length;
|
991
|
+
var key;
|
992
|
+
for (i = 0; i < len; i++) {
|
993
|
+
key = keys[i];
|
994
|
+
obj[key] = arr[key];
|
995
|
+
}
|
996
|
+
return obj;
|
997
|
+
}
|
998
|
+
|
999
|
+
function formDataToJSON(formData) {
|
1000
|
+
function buildPath(path, value, target, index) {
|
1001
|
+
var name = path[index++];
|
1002
|
+
var isNumericKey = Number.isFinite(+name);
|
1003
|
+
var isLast = index >= path.length;
|
1004
|
+
name = !name && utils.isArray(target) ? target.length : name;
|
1005
|
+
|
1006
|
+
if (isLast) {
|
1007
|
+
if (utils.hasOwnProperty(target, name)) {
|
1008
|
+
target[name] = [target[name], value];
|
1009
|
+
} else {
|
1010
|
+
target[name] = value;
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
return !isNumericKey;
|
1014
|
+
}
|
1015
|
+
|
1016
|
+
if (!target[name] || !utils.isObject(target[name])) {
|
1017
|
+
target[name] = [];
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
var result = buildPath(path, value, target[name], index);
|
1021
|
+
|
1022
|
+
if (result && utils.isArray(target[name])) {
|
1023
|
+
target[name] = arrayToObject(target[name]);
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
return !isNumericKey;
|
1027
|
+
}
|
1028
|
+
|
1029
|
+
if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
|
1030
|
+
var obj = {};
|
1031
|
+
|
1032
|
+
utils.forEachEntry(formData, function(name, value) {
|
1033
|
+
buildPath(parsePropPath(name), value, obj, 0);
|
1034
|
+
});
|
1035
|
+
|
1036
|
+
return obj;
|
1037
|
+
}
|
1038
|
+
|
1039
|
+
return null;
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
var formDataToJSON_1 = formDataToJSON;
|
1043
|
+
|
1044
|
+
/**
|
1045
|
+
* Resolve or reject a Promise based on response status.
|
1046
|
+
*
|
1047
|
+
* @param {Function} resolve A function that resolves the promise.
|
1048
|
+
* @param {Function} reject A function that rejects the promise.
|
1049
|
+
* @param {object} response The response.
|
1050
|
+
*/
|
1051
|
+
var settle = function settle(resolve, reject, response) {
|
1052
|
+
var validateStatus = response.config.validateStatus;
|
1053
|
+
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
1054
|
+
resolve(response);
|
1055
|
+
} else {
|
1056
|
+
reject(new AxiosError_1(
|
1057
|
+
'Request failed with status code ' + response.status,
|
1058
|
+
[AxiosError_1.ERR_BAD_REQUEST, AxiosError_1.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
1059
|
+
response.config,
|
1060
|
+
response.request,
|
1061
|
+
response
|
1062
|
+
));
|
1063
|
+
}
|
1064
|
+
};
|
1065
|
+
|
1066
|
+
var cookies = (
|
1067
|
+
utils.isStandardBrowserEnv() ?
|
1068
|
+
|
1069
|
+
// Standard browser envs support document.cookie
|
1070
|
+
(function standardBrowserEnv() {
|
1071
|
+
return {
|
1072
|
+
write: function write(name, value, expires, path, domain, secure) {
|
1073
|
+
var cookie = [];
|
1074
|
+
cookie.push(name + '=' + encodeURIComponent(value));
|
1075
|
+
|
1076
|
+
if (utils.isNumber(expires)) {
|
1077
|
+
cookie.push('expires=' + new Date(expires).toGMTString());
|
1078
|
+
}
|
1079
|
+
|
1080
|
+
if (utils.isString(path)) {
|
1081
|
+
cookie.push('path=' + path);
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
if (utils.isString(domain)) {
|
1085
|
+
cookie.push('domain=' + domain);
|
1086
|
+
}
|
1087
|
+
|
1088
|
+
if (secure === true) {
|
1089
|
+
cookie.push('secure');
|
1090
|
+
}
|
1091
|
+
|
1092
|
+
document.cookie = cookie.join('; ');
|
1093
|
+
},
|
1094
|
+
|
1095
|
+
read: function read(name) {
|
1096
|
+
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
1097
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
1098
|
+
},
|
1099
|
+
|
1100
|
+
remove: function remove(name) {
|
1101
|
+
this.write(name, '', Date.now() - 86400000);
|
1102
|
+
}
|
1103
|
+
};
|
1104
|
+
})() :
|
1105
|
+
|
1106
|
+
// Non standard browser env (web workers, react-native) lack needed support.
|
1107
|
+
(function nonStandardBrowserEnv() {
|
1108
|
+
return {
|
1109
|
+
write: function write() {},
|
1110
|
+
read: function read() { return null; },
|
1111
|
+
remove: function remove() {}
|
1112
|
+
};
|
1113
|
+
})()
|
1114
|
+
);
|
1115
|
+
|
1116
|
+
/**
|
1117
|
+
* Determines whether the specified URL is absolute
|
1118
|
+
*
|
1119
|
+
* @param {string} url The URL to test
|
1120
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
1121
|
+
*/
|
1122
|
+
var isAbsoluteURL = function isAbsoluteURL(url) {
|
1123
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
1124
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
1125
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
1126
|
+
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
1127
|
+
};
|
1128
|
+
|
1129
|
+
/**
|
1130
|
+
* Creates a new URL by combining the specified URLs
|
1131
|
+
*
|
1132
|
+
* @param {string} baseURL The base URL
|
1133
|
+
* @param {string} relativeURL The relative URL
|
1134
|
+
* @returns {string} The combined URL
|
1135
|
+
*/
|
1136
|
+
var combineURLs = function combineURLs(baseURL, relativeURL) {
|
1137
|
+
return relativeURL
|
1138
|
+
? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
1139
|
+
: baseURL;
|
1140
|
+
};
|
1141
|
+
|
1142
|
+
/**
|
1143
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
1144
|
+
* only when the requestedURL is not already an absolute URL.
|
1145
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
1146
|
+
*
|
1147
|
+
* @param {string} baseURL The base URL
|
1148
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
1149
|
+
* @returns {string} The combined full path
|
1150
|
+
*/
|
1151
|
+
var buildFullPath = function buildFullPath(baseURL, requestedURL) {
|
1152
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
1153
|
+
return combineURLs(baseURL, requestedURL);
|
1154
|
+
}
|
1155
|
+
return requestedURL;
|
1156
|
+
};
|
1157
|
+
|
1158
|
+
// Headers whose duplicates are ignored by node
|
1159
|
+
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
1160
|
+
var ignoreDuplicateOf = [
|
1161
|
+
'age', 'authorization', 'content-length', 'content-type', 'etag',
|
1162
|
+
'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
|
1163
|
+
'last-modified', 'location', 'max-forwards', 'proxy-authorization',
|
1164
|
+
'referer', 'retry-after', 'user-agent'
|
1165
|
+
];
|
1166
|
+
|
1167
|
+
/**
|
1168
|
+
* Parse headers into an object
|
1169
|
+
*
|
1170
|
+
* ```
|
1171
|
+
* Date: Wed, 27 Aug 2014 08:58:49 GMT
|
1172
|
+
* Content-Type: application/json
|
1173
|
+
* Connection: keep-alive
|
1174
|
+
* Transfer-Encoding: chunked
|
1175
|
+
* ```
|
1176
|
+
*
|
1177
|
+
* @param {String} headers Headers needing to be parsed
|
1178
|
+
* @returns {Object} Headers parsed into an object
|
1179
|
+
*/
|
1180
|
+
var parseHeaders = function parseHeaders(headers) {
|
1181
|
+
var parsed = {};
|
1182
|
+
var key;
|
1183
|
+
var val;
|
1184
|
+
var i;
|
1185
|
+
|
1186
|
+
if (!headers) { return parsed; }
|
1187
|
+
|
1188
|
+
utils.forEach(headers.split('\n'), function parser(line) {
|
1189
|
+
i = line.indexOf(':');
|
1190
|
+
key = utils.trim(line.slice(0, i)).toLowerCase();
|
1191
|
+
val = utils.trim(line.slice(i + 1));
|
1192
|
+
|
1193
|
+
if (key) {
|
1194
|
+
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
1195
|
+
return;
|
1196
|
+
}
|
1197
|
+
if (key === 'set-cookie') {
|
1198
|
+
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
1199
|
+
} else {
|
1200
|
+
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
1201
|
+
}
|
1202
|
+
}
|
1203
|
+
});
|
1204
|
+
|
1205
|
+
return parsed;
|
1206
|
+
};
|
1207
|
+
|
1208
|
+
var isURLSameOrigin = (
|
1209
|
+
utils.isStandardBrowserEnv() ?
|
1210
|
+
|
1211
|
+
// Standard browser envs have full support of the APIs needed to test
|
1212
|
+
// whether the request URL is of the same origin as current location.
|
1213
|
+
(function standardBrowserEnv() {
|
1214
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
1215
|
+
var urlParsingNode = document.createElement('a');
|
1216
|
+
var originURL;
|
1217
|
+
|
1218
|
+
/**
|
1219
|
+
* Parse a URL to discover it's components
|
1220
|
+
*
|
1221
|
+
* @param {String} url The URL to be parsed
|
1222
|
+
* @returns {Object}
|
1223
|
+
*/
|
1224
|
+
function resolveURL(url) {
|
1225
|
+
var href = url;
|
1226
|
+
|
1227
|
+
if (msie) {
|
1228
|
+
// IE needs attribute set twice to normalize properties
|
1229
|
+
urlParsingNode.setAttribute('href', href);
|
1230
|
+
href = urlParsingNode.href;
|
1231
|
+
}
|
1232
|
+
|
1233
|
+
urlParsingNode.setAttribute('href', href);
|
1234
|
+
|
1235
|
+
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
1236
|
+
return {
|
1237
|
+
href: urlParsingNode.href,
|
1238
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
1239
|
+
host: urlParsingNode.host,
|
1240
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
1241
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
1242
|
+
hostname: urlParsingNode.hostname,
|
1243
|
+
port: urlParsingNode.port,
|
1244
|
+
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
1245
|
+
urlParsingNode.pathname :
|
1246
|
+
'/' + urlParsingNode.pathname
|
1247
|
+
};
|
1248
|
+
}
|
1249
|
+
|
1250
|
+
originURL = resolveURL(window.location.href);
|
1251
|
+
|
1252
|
+
/**
|
1253
|
+
* Determine if a URL shares the same origin as the current location
|
1254
|
+
*
|
1255
|
+
* @param {String} requestURL The URL to test
|
1256
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
1257
|
+
*/
|
1258
|
+
return function isURLSameOrigin(requestURL) {
|
1259
|
+
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
1260
|
+
return (parsed.protocol === originURL.protocol &&
|
1261
|
+
parsed.host === originURL.host);
|
1262
|
+
};
|
1263
|
+
})() :
|
1264
|
+
|
1265
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
1266
|
+
(function nonStandardBrowserEnv() {
|
1267
|
+
return function isURLSameOrigin() {
|
1268
|
+
return true;
|
1269
|
+
};
|
1270
|
+
})()
|
1271
|
+
);
|
1272
|
+
|
1273
|
+
/**
|
1274
|
+
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
1275
|
+
*
|
1276
|
+
* @class
|
1277
|
+
* @param {string=} message The message.
|
1278
|
+
* @param {Object=} config The config.
|
1279
|
+
* @param {Object=} request The request.
|
1280
|
+
*/
|
1281
|
+
function CanceledError(message, config, request) {
|
1282
|
+
// eslint-disable-next-line no-eq-null,eqeqeq
|
1283
|
+
AxiosError_1.call(this, message == null ? 'canceled' : message, AxiosError_1.ERR_CANCELED, config, request);
|
1284
|
+
this.name = 'CanceledError';
|
1285
|
+
}
|
1286
|
+
|
1287
|
+
utils.inherits(CanceledError, AxiosError_1, {
|
1288
|
+
__CANCEL__: true
|
1289
|
+
});
|
1290
|
+
|
1291
|
+
var CanceledError_1 = CanceledError;
|
1292
|
+
|
1293
|
+
var parseProtocol = function parseProtocol(url) {
|
1294
|
+
var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
1295
|
+
return match && match[1] || '';
|
1296
|
+
};
|
1297
|
+
|
1298
|
+
var xhr = function xhrAdapter(config) {
|
1299
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
1300
|
+
var requestData = config.data;
|
1301
|
+
var requestHeaders = config.headers;
|
1302
|
+
var responseType = config.responseType;
|
1303
|
+
var onCanceled;
|
1304
|
+
function done() {
|
1305
|
+
if (config.cancelToken) {
|
1306
|
+
config.cancelToken.unsubscribe(onCanceled);
|
1307
|
+
}
|
1308
|
+
|
1309
|
+
if (config.signal) {
|
1310
|
+
config.signal.removeEventListener('abort', onCanceled);
|
1311
|
+
}
|
1312
|
+
}
|
1313
|
+
|
1314
|
+
if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
|
1315
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
var request = new XMLHttpRequest();
|
1319
|
+
|
1320
|
+
// HTTP basic authentication
|
1321
|
+
if (config.auth) {
|
1322
|
+
var username = config.auth.username || '';
|
1323
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
1324
|
+
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
1325
|
+
}
|
1326
|
+
|
1327
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
1328
|
+
|
1329
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
1330
|
+
|
1331
|
+
// Set the request timeout in MS
|
1332
|
+
request.timeout = config.timeout;
|
1333
|
+
|
1334
|
+
function onloadend() {
|
1335
|
+
if (!request) {
|
1336
|
+
return;
|
1337
|
+
}
|
1338
|
+
// Prepare the response
|
1339
|
+
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
1340
|
+
var responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
1341
|
+
request.responseText : request.response;
|
1342
|
+
var response = {
|
1343
|
+
data: responseData,
|
1344
|
+
status: request.status,
|
1345
|
+
statusText: request.statusText,
|
1346
|
+
headers: responseHeaders,
|
1347
|
+
config: config,
|
1348
|
+
request: request
|
1349
|
+
};
|
1350
|
+
|
1351
|
+
settle(function _resolve(value) {
|
1352
|
+
resolve(value);
|
1353
|
+
done();
|
1354
|
+
}, function _reject(err) {
|
1355
|
+
reject(err);
|
1356
|
+
done();
|
1357
|
+
}, response);
|
1358
|
+
|
1359
|
+
// Clean up request
|
1360
|
+
request = null;
|
1361
|
+
}
|
1362
|
+
|
1363
|
+
if ('onloadend' in request) {
|
1364
|
+
// Use onloadend if available
|
1365
|
+
request.onloadend = onloadend;
|
1366
|
+
} else {
|
1367
|
+
// Listen for ready state to emulate onloadend
|
1368
|
+
request.onreadystatechange = function handleLoad() {
|
1369
|
+
if (!request || request.readyState !== 4) {
|
1370
|
+
return;
|
1371
|
+
}
|
1372
|
+
|
1373
|
+
// The request errored out and we didn't get a response, this will be
|
1374
|
+
// handled by onerror instead
|
1375
|
+
// With one exception: request that using file: protocol, most browsers
|
1376
|
+
// will return status as 0 even though it's a successful request
|
1377
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
1378
|
+
return;
|
1379
|
+
}
|
1380
|
+
// readystate handler is calling before onerror or ontimeout handlers,
|
1381
|
+
// so we should call onloadend on the next 'tick'
|
1382
|
+
setTimeout(onloadend);
|
1383
|
+
};
|
1384
|
+
}
|
1385
|
+
|
1386
|
+
// Handle browser request cancellation (as opposed to a manual cancellation)
|
1387
|
+
request.onabort = function handleAbort() {
|
1388
|
+
if (!request) {
|
1389
|
+
return;
|
1390
|
+
}
|
1391
|
+
|
1392
|
+
reject(new AxiosError_1('Request aborted', AxiosError_1.ECONNABORTED, config, request));
|
1393
|
+
|
1394
|
+
// Clean up request
|
1395
|
+
request = null;
|
1396
|
+
};
|
1397
|
+
|
1398
|
+
// Handle low level network errors
|
1399
|
+
request.onerror = function handleError() {
|
1400
|
+
// Real errors are hidden from us by the browser
|
1401
|
+
// onerror should only fire if it's a network error
|
1402
|
+
reject(new AxiosError_1('Network Error', AxiosError_1.ERR_NETWORK, config, request));
|
1403
|
+
|
1404
|
+
// Clean up request
|
1405
|
+
request = null;
|
1406
|
+
};
|
1407
|
+
|
1408
|
+
// Handle timeout
|
1409
|
+
request.ontimeout = function handleTimeout() {
|
1410
|
+
var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
|
1411
|
+
var transitional$1 = config.transitional || transitional;
|
1412
|
+
if (config.timeoutErrorMessage) {
|
1413
|
+
timeoutErrorMessage = config.timeoutErrorMessage;
|
1414
|
+
}
|
1415
|
+
reject(new AxiosError_1(
|
1416
|
+
timeoutErrorMessage,
|
1417
|
+
transitional$1.clarifyTimeoutError ? AxiosError_1.ETIMEDOUT : AxiosError_1.ECONNABORTED,
|
1418
|
+
config,
|
1419
|
+
request));
|
1420
|
+
|
1421
|
+
// Clean up request
|
1422
|
+
request = null;
|
1423
|
+
};
|
1424
|
+
|
1425
|
+
// Add xsrf header
|
1426
|
+
// This is only done if running in a standard browser environment.
|
1427
|
+
// Specifically not if we're in a web worker, or react-native.
|
1428
|
+
if (utils.isStandardBrowserEnv()) {
|
1429
|
+
// Add xsrf header
|
1430
|
+
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
1431
|
+
cookies.read(config.xsrfCookieName) :
|
1432
|
+
undefined;
|
1433
|
+
|
1434
|
+
if (xsrfValue) {
|
1435
|
+
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
1436
|
+
}
|
1437
|
+
}
|
1438
|
+
|
1439
|
+
// Add headers to the request
|
1440
|
+
if ('setRequestHeader' in request) {
|
1441
|
+
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
1442
|
+
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
1443
|
+
// Remove Content-Type if data is undefined
|
1444
|
+
delete requestHeaders[key];
|
1445
|
+
} else {
|
1446
|
+
// Otherwise add header to the request
|
1447
|
+
request.setRequestHeader(key, val);
|
1448
|
+
}
|
1449
|
+
});
|
1450
|
+
}
|
1451
|
+
|
1452
|
+
// Add withCredentials to request if needed
|
1453
|
+
if (!utils.isUndefined(config.withCredentials)) {
|
1454
|
+
request.withCredentials = !!config.withCredentials;
|
1455
|
+
}
|
1456
|
+
|
1457
|
+
// Add responseType to request if needed
|
1458
|
+
if (responseType && responseType !== 'json') {
|
1459
|
+
request.responseType = config.responseType;
|
1460
|
+
}
|
1461
|
+
|
1462
|
+
// Handle progress if needed
|
1463
|
+
if (typeof config.onDownloadProgress === 'function') {
|
1464
|
+
request.addEventListener('progress', config.onDownloadProgress);
|
1465
|
+
}
|
1466
|
+
|
1467
|
+
// Not all browsers support upload events
|
1468
|
+
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
1469
|
+
request.upload.addEventListener('progress', config.onUploadProgress);
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
if (config.cancelToken || config.signal) {
|
1473
|
+
// Handle cancellation
|
1474
|
+
// eslint-disable-next-line func-names
|
1475
|
+
onCanceled = function(cancel) {
|
1476
|
+
if (!request) {
|
1477
|
+
return;
|
1478
|
+
}
|
1479
|
+
reject(!cancel || cancel.type ? new CanceledError_1(null, config, req) : cancel);
|
1480
|
+
request.abort();
|
1481
|
+
request = null;
|
1482
|
+
};
|
1483
|
+
|
1484
|
+
config.cancelToken && config.cancelToken.subscribe(onCanceled);
|
1485
|
+
if (config.signal) {
|
1486
|
+
config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
|
1487
|
+
}
|
1488
|
+
}
|
1489
|
+
|
1490
|
+
if (!requestData) {
|
1491
|
+
requestData = null;
|
1492
|
+
}
|
1493
|
+
|
1494
|
+
var protocol = parseProtocol(fullPath);
|
1495
|
+
|
1496
|
+
if (protocol && platform.protocols.indexOf(protocol) === -1) {
|
1497
|
+
reject(new AxiosError_1('Unsupported protocol ' + protocol + ':', AxiosError_1.ERR_BAD_REQUEST, config));
|
1498
|
+
return;
|
1499
|
+
}
|
1500
|
+
|
1501
|
+
|
1502
|
+
// Send the request
|
1503
|
+
request.send(requestData);
|
1504
|
+
});
|
1505
|
+
};
|
1506
|
+
|
1507
|
+
var DEFAULT_CONTENT_TYPE = {
|
1508
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
1509
|
+
};
|
1510
|
+
|
1511
|
+
function setContentTypeIfUnset(headers, value) {
|
1512
|
+
if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
|
1513
|
+
headers['Content-Type'] = value;
|
1514
|
+
}
|
1515
|
+
}
|
1516
|
+
|
1517
|
+
function getDefaultAdapter() {
|
1518
|
+
var adapter;
|
1519
|
+
if (typeof XMLHttpRequest !== 'undefined') {
|
1520
|
+
// For browsers use XHR adapter
|
1521
|
+
adapter = xhr;
|
1522
|
+
} else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
|
1523
|
+
// For node use HTTP adapter
|
1524
|
+
adapter = xhr;
|
1525
|
+
}
|
1526
|
+
return adapter;
|
1527
|
+
}
|
1528
|
+
|
1529
|
+
function stringifySafely(rawValue, parser, encoder) {
|
1530
|
+
if (utils.isString(rawValue)) {
|
1531
|
+
try {
|
1532
|
+
(parser || JSON.parse)(rawValue);
|
1533
|
+
return utils.trim(rawValue);
|
1534
|
+
} catch (e) {
|
1535
|
+
if (e.name !== 'SyntaxError') {
|
1536
|
+
throw e;
|
1537
|
+
}
|
1538
|
+
}
|
1539
|
+
}
|
1540
|
+
|
1541
|
+
return (encoder || JSON.stringify)(rawValue);
|
1542
|
+
}
|
1543
|
+
|
1544
|
+
var defaults = {
|
1545
|
+
|
1546
|
+
transitional: transitional,
|
1547
|
+
|
1548
|
+
adapter: getDefaultAdapter(),
|
1549
|
+
|
1550
|
+
transformRequest: [function transformRequest(data, headers) {
|
1551
|
+
normalizeHeaderName(headers, 'Accept');
|
1552
|
+
normalizeHeaderName(headers, 'Content-Type');
|
1553
|
+
|
1554
|
+
var contentType = headers && headers['Content-Type'] || '';
|
1555
|
+
var hasJSONContentType = contentType.indexOf('application/json') > -1;
|
1556
|
+
var isObjectPayload = utils.isObject(data);
|
1557
|
+
|
1558
|
+
if (isObjectPayload && utils.isHTMLForm(data)) {
|
1559
|
+
data = new FormData(data);
|
1560
|
+
}
|
1561
|
+
|
1562
|
+
var isFormData = utils.isFormData(data);
|
1563
|
+
|
1564
|
+
if (isFormData) {
|
1565
|
+
if (!hasJSONContentType) {
|
1566
|
+
return data;
|
1567
|
+
}
|
1568
|
+
return hasJSONContentType ? JSON.stringify(formDataToJSON_1(data)) : data;
|
1569
|
+
}
|
1570
|
+
|
1571
|
+
if (utils.isArrayBuffer(data) ||
|
1572
|
+
utils.isBuffer(data) ||
|
1573
|
+
utils.isStream(data) ||
|
1574
|
+
utils.isFile(data) ||
|
1575
|
+
utils.isBlob(data)
|
1576
|
+
) {
|
1577
|
+
return data;
|
1578
|
+
}
|
1579
|
+
if (utils.isArrayBufferView(data)) {
|
1580
|
+
return data.buffer;
|
1581
|
+
}
|
1582
|
+
if (utils.isURLSearchParams(data)) {
|
1583
|
+
setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
|
1584
|
+
return data.toString();
|
1585
|
+
}
|
1586
|
+
|
1587
|
+
var isFileList;
|
1588
|
+
|
1589
|
+
if (isObjectPayload) {
|
1590
|
+
if (contentType.indexOf('application/x-www-form-urlencoded') !== -1) {
|
1591
|
+
return toURLEncodedForm(data, this.formSerializer).toString();
|
1592
|
+
}
|
1593
|
+
|
1594
|
+
if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
|
1595
|
+
var _FormData = this.env && this.env.FormData;
|
1596
|
+
|
1597
|
+
return toFormData_1(
|
1598
|
+
isFileList ? {'files[]': data} : data,
|
1599
|
+
_FormData && new _FormData(),
|
1600
|
+
this.formSerializer
|
1601
|
+
);
|
1602
|
+
}
|
1603
|
+
}
|
1604
|
+
|
1605
|
+
if (isObjectPayload || hasJSONContentType ) {
|
1606
|
+
setContentTypeIfUnset(headers, 'application/json');
|
1607
|
+
return stringifySafely(data);
|
1608
|
+
}
|
1609
|
+
|
1610
|
+
return data;
|
1611
|
+
}],
|
1612
|
+
|
1613
|
+
transformResponse: [function transformResponse(data) {
|
1614
|
+
var transitional = this.transitional || defaults.transitional;
|
1615
|
+
var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
1616
|
+
var JSONRequested = this.responseType === 'json';
|
1617
|
+
|
1618
|
+
if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
|
1619
|
+
var silentJSONParsing = transitional && transitional.silentJSONParsing;
|
1620
|
+
var strictJSONParsing = !silentJSONParsing && JSONRequested;
|
1621
|
+
|
1622
|
+
try {
|
1623
|
+
return JSON.parse(data);
|
1624
|
+
} catch (e) {
|
1625
|
+
if (strictJSONParsing) {
|
1626
|
+
if (e.name === 'SyntaxError') {
|
1627
|
+
throw AxiosError_1.from(e, AxiosError_1.ERR_BAD_RESPONSE, this, null, this.response);
|
1628
|
+
}
|
1629
|
+
throw e;
|
1630
|
+
}
|
1631
|
+
}
|
1632
|
+
}
|
1633
|
+
|
1634
|
+
return data;
|
1635
|
+
}],
|
1636
|
+
|
1637
|
+
/**
|
1638
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
1639
|
+
* timeout is not created.
|
1640
|
+
*/
|
1641
|
+
timeout: 0,
|
1642
|
+
|
1643
|
+
xsrfCookieName: 'XSRF-TOKEN',
|
1644
|
+
xsrfHeaderName: 'X-XSRF-TOKEN',
|
1645
|
+
|
1646
|
+
maxContentLength: -1,
|
1647
|
+
maxBodyLength: -1,
|
1648
|
+
|
1649
|
+
env: {
|
1650
|
+
FormData: platform.classes.FormData,
|
1651
|
+
Blob: platform.classes.Blob
|
1652
|
+
},
|
1653
|
+
|
1654
|
+
validateStatus: function validateStatus(status) {
|
1655
|
+
return status >= 200 && status < 300;
|
1656
|
+
},
|
1657
|
+
|
1658
|
+
headers: {
|
1659
|
+
common: {
|
1660
|
+
'Accept': 'application/json, text/plain, */*'
|
1661
|
+
}
|
1662
|
+
}
|
1663
|
+
};
|
1664
|
+
|
1665
|
+
utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
|
1666
|
+
defaults.headers[method] = {};
|
1667
|
+
});
|
1668
|
+
|
1669
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
1670
|
+
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
1671
|
+
});
|
1672
|
+
|
1673
|
+
var defaults_1 = defaults;
|
1674
|
+
|
1675
|
+
/**
|
1676
|
+
* Transform the data for a request or a response
|
1677
|
+
*
|
1678
|
+
* @param {Object|String} data The data to be transformed
|
1679
|
+
* @param {Array} headers The headers for the request or response
|
1680
|
+
* @param {Number} status HTTP status code
|
1681
|
+
* @param {Array|Function} fns A single function or Array of functions
|
1682
|
+
* @returns {*} The resulting transformed data
|
1683
|
+
*/
|
1684
|
+
var transformData = function transformData(data, headers, status, fns) {
|
1685
|
+
var context = this || defaults_1;
|
1686
|
+
/*eslint no-param-reassign:0*/
|
1687
|
+
utils.forEach(fns, function transform(fn) {
|
1688
|
+
data = fn.call(context, data, headers, status);
|
1689
|
+
});
|
1690
|
+
|
1691
|
+
return data;
|
1692
|
+
};
|
1693
|
+
|
1694
|
+
var isCancel = function isCancel(value) {
|
1695
|
+
return !!(value && value.__CANCEL__);
|
1696
|
+
};
|
1697
|
+
|
1698
|
+
/**
|
1699
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
1700
|
+
*/
|
1701
|
+
function throwIfCancellationRequested(config) {
|
1702
|
+
if (config.cancelToken) {
|
1703
|
+
config.cancelToken.throwIfRequested();
|
1704
|
+
}
|
1705
|
+
|
1706
|
+
if (config.signal && config.signal.aborted) {
|
1707
|
+
throw new CanceledError_1();
|
1708
|
+
}
|
1709
|
+
}
|
1710
|
+
|
1711
|
+
/**
|
1712
|
+
* Dispatch a request to the server using the configured adapter.
|
1713
|
+
*
|
1714
|
+
* @param {object} config The config that is to be used for the request
|
1715
|
+
* @returns {Promise} The Promise to be fulfilled
|
1716
|
+
*/
|
1717
|
+
var dispatchRequest = function dispatchRequest(config) {
|
1718
|
+
throwIfCancellationRequested(config);
|
1719
|
+
|
1720
|
+
// Ensure headers exist
|
1721
|
+
config.headers = config.headers || {};
|
1722
|
+
|
1723
|
+
// Transform request data
|
1724
|
+
config.data = transformData.call(
|
1725
|
+
config,
|
1726
|
+
config.data,
|
1727
|
+
config.headers,
|
1728
|
+
null,
|
1729
|
+
config.transformRequest
|
1730
|
+
);
|
1731
|
+
|
1732
|
+
normalizeHeaderName(config.headers, 'Accept');
|
1733
|
+
normalizeHeaderName(config.headers, 'Content-Type');
|
1734
|
+
|
1735
|
+
// Flatten headers
|
1736
|
+
config.headers = utils.merge(
|
1737
|
+
config.headers.common || {},
|
1738
|
+
config.headers[config.method] || {},
|
1739
|
+
config.headers
|
1740
|
+
);
|
1741
|
+
|
1742
|
+
utils.forEach(
|
1743
|
+
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
1744
|
+
function cleanHeaderConfig(method) {
|
1745
|
+
delete config.headers[method];
|
1746
|
+
}
|
1747
|
+
);
|
1748
|
+
|
1749
|
+
var adapter = config.adapter || defaults_1.adapter;
|
1750
|
+
|
1751
|
+
return adapter(config).then(function onAdapterResolution(response) {
|
1752
|
+
throwIfCancellationRequested(config);
|
1753
|
+
|
1754
|
+
// Transform response data
|
1755
|
+
response.data = transformData.call(
|
1756
|
+
config,
|
1757
|
+
response.data,
|
1758
|
+
response.headers,
|
1759
|
+
response.status,
|
1760
|
+
config.transformResponse
|
1761
|
+
);
|
1762
|
+
|
1763
|
+
return response;
|
1764
|
+
}, function onAdapterRejection(reason) {
|
1765
|
+
if (!isCancel(reason)) {
|
1766
|
+
throwIfCancellationRequested(config);
|
1767
|
+
|
1768
|
+
// Transform response data
|
1769
|
+
if (reason && reason.response) {
|
1770
|
+
reason.response.data = transformData.call(
|
1771
|
+
config,
|
1772
|
+
reason.response.data,
|
1773
|
+
reason.response.headers,
|
1774
|
+
reason.response.status,
|
1775
|
+
config.transformResponse
|
1776
|
+
);
|
1777
|
+
}
|
1778
|
+
}
|
1779
|
+
|
1780
|
+
return Promise.reject(reason);
|
1781
|
+
});
|
1782
|
+
};
|
1783
|
+
|
1784
|
+
/**
|
1785
|
+
* Config-specific merge-function which creates a new config-object
|
1786
|
+
* by merging two configuration objects together.
|
1787
|
+
*
|
1788
|
+
* @param {Object} config1
|
1789
|
+
* @param {Object} config2
|
1790
|
+
* @returns {Object} New object resulting from merging config2 to config1
|
1791
|
+
*/
|
1792
|
+
var mergeConfig = function mergeConfig(config1, config2) {
|
1793
|
+
// eslint-disable-next-line no-param-reassign
|
1794
|
+
config2 = config2 || {};
|
1795
|
+
var config = {};
|
1796
|
+
|
1797
|
+
function getMergedValue(target, source) {
|
1798
|
+
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
1799
|
+
return utils.merge(target, source);
|
1800
|
+
} else if (utils.isPlainObject(source)) {
|
1801
|
+
return utils.merge({}, source);
|
1802
|
+
} else if (utils.isArray(source)) {
|
1803
|
+
return source.slice();
|
1804
|
+
}
|
1805
|
+
return source;
|
1806
|
+
}
|
1807
|
+
|
1808
|
+
// eslint-disable-next-line consistent-return
|
1809
|
+
function mergeDeepProperties(prop) {
|
1810
|
+
if (!utils.isUndefined(config2[prop])) {
|
1811
|
+
return getMergedValue(config1[prop], config2[prop]);
|
1812
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
1813
|
+
return getMergedValue(undefined, config1[prop]);
|
1814
|
+
}
|
1815
|
+
}
|
1816
|
+
|
1817
|
+
// eslint-disable-next-line consistent-return
|
1818
|
+
function valueFromConfig2(prop) {
|
1819
|
+
if (!utils.isUndefined(config2[prop])) {
|
1820
|
+
return getMergedValue(undefined, config2[prop]);
|
1821
|
+
}
|
1822
|
+
}
|
1823
|
+
|
1824
|
+
// eslint-disable-next-line consistent-return
|
1825
|
+
function defaultToConfig2(prop) {
|
1826
|
+
if (!utils.isUndefined(config2[prop])) {
|
1827
|
+
return getMergedValue(undefined, config2[prop]);
|
1828
|
+
} else if (!utils.isUndefined(config1[prop])) {
|
1829
|
+
return getMergedValue(undefined, config1[prop]);
|
1830
|
+
}
|
1831
|
+
}
|
1832
|
+
|
1833
|
+
// eslint-disable-next-line consistent-return
|
1834
|
+
function mergeDirectKeys(prop) {
|
1835
|
+
if (prop in config2) {
|
1836
|
+
return getMergedValue(config1[prop], config2[prop]);
|
1837
|
+
} else if (prop in config1) {
|
1838
|
+
return getMergedValue(undefined, config1[prop]);
|
1839
|
+
}
|
1840
|
+
}
|
1841
|
+
|
1842
|
+
var mergeMap = {
|
1843
|
+
'url': valueFromConfig2,
|
1844
|
+
'method': valueFromConfig2,
|
1845
|
+
'data': valueFromConfig2,
|
1846
|
+
'baseURL': defaultToConfig2,
|
1847
|
+
'transformRequest': defaultToConfig2,
|
1848
|
+
'transformResponse': defaultToConfig2,
|
1849
|
+
'paramsSerializer': defaultToConfig2,
|
1850
|
+
'timeout': defaultToConfig2,
|
1851
|
+
'timeoutMessage': defaultToConfig2,
|
1852
|
+
'withCredentials': defaultToConfig2,
|
1853
|
+
'adapter': defaultToConfig2,
|
1854
|
+
'responseType': defaultToConfig2,
|
1855
|
+
'xsrfCookieName': defaultToConfig2,
|
1856
|
+
'xsrfHeaderName': defaultToConfig2,
|
1857
|
+
'onUploadProgress': defaultToConfig2,
|
1858
|
+
'onDownloadProgress': defaultToConfig2,
|
1859
|
+
'decompress': defaultToConfig2,
|
1860
|
+
'maxContentLength': defaultToConfig2,
|
1861
|
+
'maxBodyLength': defaultToConfig2,
|
1862
|
+
'beforeRedirect': defaultToConfig2,
|
1863
|
+
'transport': defaultToConfig2,
|
1864
|
+
'httpAgent': defaultToConfig2,
|
1865
|
+
'httpsAgent': defaultToConfig2,
|
1866
|
+
'cancelToken': defaultToConfig2,
|
1867
|
+
'socketPath': defaultToConfig2,
|
1868
|
+
'responseEncoding': defaultToConfig2,
|
1869
|
+
'validateStatus': mergeDirectKeys
|
1870
|
+
};
|
1871
|
+
|
1872
|
+
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
1873
|
+
var merge = mergeMap[prop] || mergeDeepProperties;
|
1874
|
+
var configValue = merge(prop);
|
1875
|
+
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
1876
|
+
});
|
1877
|
+
|
1878
|
+
return config;
|
1879
|
+
};
|
1880
|
+
|
1881
|
+
var data = {
|
1882
|
+
"version": "1.0.0-alpha.1"
|
1883
|
+
};
|
1884
|
+
|
1885
|
+
var VERSION = data.version;
|
1886
|
+
|
1887
|
+
|
1888
|
+
var validators$1 = {};
|
1889
|
+
|
1890
|
+
// eslint-disable-next-line func-names
|
1891
|
+
['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach(function(type, i) {
|
1892
|
+
validators$1[type] = function validator(thing) {
|
1893
|
+
return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
|
1894
|
+
};
|
1895
|
+
});
|
1896
|
+
|
1897
|
+
var deprecatedWarnings = {};
|
1898
|
+
|
1899
|
+
/**
|
1900
|
+
* Transitional option validator
|
1901
|
+
* @param {function|boolean?} validator - set to false if the transitional option has been removed
|
1902
|
+
* @param {string?} version - deprecated version / removed since version
|
1903
|
+
* @param {string?} message - some message with additional info
|
1904
|
+
* @returns {function}
|
1905
|
+
*/
|
1906
|
+
validators$1.transitional = function transitional(validator, version, message) {
|
1907
|
+
function formatMessage(opt, desc) {
|
1908
|
+
return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
|
1909
|
+
}
|
1910
|
+
|
1911
|
+
// eslint-disable-next-line func-names
|
1912
|
+
return function(value, opt, opts) {
|
1913
|
+
if (validator === false) {
|
1914
|
+
throw new AxiosError_1(
|
1915
|
+
formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
|
1916
|
+
AxiosError_1.ERR_DEPRECATED
|
1917
|
+
);
|
1918
|
+
}
|
1919
|
+
|
1920
|
+
if (version && !deprecatedWarnings[opt]) {
|
1921
|
+
deprecatedWarnings[opt] = true;
|
1922
|
+
// eslint-disable-next-line no-console
|
1923
|
+
console.warn(
|
1924
|
+
formatMessage(
|
1925
|
+
opt,
|
1926
|
+
' has been deprecated since v' + version + ' and will be removed in the near future'
|
1927
|
+
)
|
1928
|
+
);
|
1929
|
+
}
|
1930
|
+
|
1931
|
+
return validator ? validator(value, opt, opts) : true;
|
1932
|
+
};
|
1933
|
+
};
|
1934
|
+
|
1935
|
+
/**
|
1936
|
+
* Assert object's properties type
|
1937
|
+
* @param {object} options
|
1938
|
+
* @param {object} schema
|
1939
|
+
* @param {boolean?} allowUnknown
|
1940
|
+
*/
|
1941
|
+
|
1942
|
+
function assertOptions(options, schema, allowUnknown) {
|
1943
|
+
if (typeof options !== 'object') {
|
1944
|
+
throw new AxiosError_1('options must be an object', AxiosError_1.ERR_BAD_OPTION_VALUE);
|
1945
|
+
}
|
1946
|
+
var keys = Object.keys(options);
|
1947
|
+
var i = keys.length;
|
1948
|
+
while (i-- > 0) {
|
1949
|
+
var opt = keys[i];
|
1950
|
+
var validator = schema[opt];
|
1951
|
+
if (validator) {
|
1952
|
+
var value = options[opt];
|
1953
|
+
var result = value === undefined || validator(value, opt, options);
|
1954
|
+
if (result !== true) {
|
1955
|
+
throw new AxiosError_1('option ' + opt + ' must be ' + result, AxiosError_1.ERR_BAD_OPTION_VALUE);
|
1956
|
+
}
|
1957
|
+
continue;
|
1958
|
+
}
|
1959
|
+
if (allowUnknown !== true) {
|
1960
|
+
throw new AxiosError_1('Unknown option ' + opt, AxiosError_1.ERR_BAD_OPTION);
|
1961
|
+
}
|
1962
|
+
}
|
1963
|
+
}
|
1964
|
+
|
1965
|
+
var validator = {
|
1966
|
+
assertOptions: assertOptions,
|
1967
|
+
validators: validators$1
|
1968
|
+
};
|
1969
|
+
|
1970
|
+
var validators = validator.validators;
|
1971
|
+
/**
|
1972
|
+
* Create a new instance of Axios
|
1973
|
+
*
|
1974
|
+
* @param {Object} instanceConfig The default config for the instance
|
1975
|
+
*/
|
1976
|
+
function Axios(instanceConfig) {
|
1977
|
+
this.defaults = instanceConfig;
|
1978
|
+
this.interceptors = {
|
1979
|
+
request: new InterceptorManager_1(),
|
1980
|
+
response: new InterceptorManager_1()
|
1981
|
+
};
|
1982
|
+
}
|
1983
|
+
|
1984
|
+
/**
|
1985
|
+
* Dispatch a request
|
1986
|
+
*
|
1987
|
+
* @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
|
1988
|
+
* @param {?Object} config
|
1989
|
+
*/
|
1990
|
+
Axios.prototype.request = function request(configOrUrl, config) {
|
1991
|
+
/*eslint no-param-reassign:0*/
|
1992
|
+
// Allow for axios('example/url'[, config]) a la fetch API
|
1993
|
+
if (typeof configOrUrl === 'string') {
|
1994
|
+
config = config || {};
|
1995
|
+
config.url = configOrUrl;
|
1996
|
+
} else {
|
1997
|
+
config = configOrUrl || {};
|
1998
|
+
}
|
1999
|
+
|
2000
|
+
config = mergeConfig(this.defaults, config);
|
2001
|
+
|
2002
|
+
// Set config.method
|
2003
|
+
if (config.method) {
|
2004
|
+
config.method = config.method.toLowerCase();
|
2005
|
+
} else if (this.defaults.method) {
|
2006
|
+
config.method = this.defaults.method.toLowerCase();
|
2007
|
+
} else {
|
2008
|
+
config.method = 'get';
|
2009
|
+
}
|
2010
|
+
|
2011
|
+
var transitional = config.transitional;
|
2012
|
+
|
2013
|
+
if (transitional !== undefined) {
|
2014
|
+
validator.assertOptions(transitional, {
|
2015
|
+
silentJSONParsing: validators.transitional(validators.boolean),
|
2016
|
+
forcedJSONParsing: validators.transitional(validators.boolean),
|
2017
|
+
clarifyTimeoutError: validators.transitional(validators.boolean)
|
2018
|
+
}, false);
|
2019
|
+
}
|
2020
|
+
|
2021
|
+
// filter out skipped interceptors
|
2022
|
+
var requestInterceptorChain = [];
|
2023
|
+
var synchronousRequestInterceptors = true;
|
2024
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
2025
|
+
if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
|
2026
|
+
return;
|
2027
|
+
}
|
2028
|
+
|
2029
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
2030
|
+
|
2031
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
2032
|
+
});
|
2033
|
+
|
2034
|
+
var responseInterceptorChain = [];
|
2035
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
2036
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
2037
|
+
});
|
2038
|
+
|
2039
|
+
var promise;
|
2040
|
+
|
2041
|
+
if (!synchronousRequestInterceptors) {
|
2042
|
+
var chain = [dispatchRequest, undefined];
|
2043
|
+
|
2044
|
+
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
2045
|
+
chain = chain.concat(responseInterceptorChain);
|
2046
|
+
|
2047
|
+
promise = Promise.resolve(config);
|
2048
|
+
while (chain.length) {
|
2049
|
+
promise = promise.then(chain.shift(), chain.shift());
|
2050
|
+
}
|
2051
|
+
|
2052
|
+
return promise;
|
2053
|
+
}
|
2054
|
+
|
2055
|
+
|
2056
|
+
var newConfig = config;
|
2057
|
+
while (requestInterceptorChain.length) {
|
2058
|
+
var onFulfilled = requestInterceptorChain.shift();
|
2059
|
+
var onRejected = requestInterceptorChain.shift();
|
2060
|
+
try {
|
2061
|
+
newConfig = onFulfilled(newConfig);
|
2062
|
+
} catch (error) {
|
2063
|
+
onRejected(error);
|
2064
|
+
break;
|
2065
|
+
}
|
2066
|
+
}
|
2067
|
+
|
2068
|
+
try {
|
2069
|
+
promise = dispatchRequest(newConfig);
|
2070
|
+
} catch (error) {
|
2071
|
+
return Promise.reject(error);
|
2072
|
+
}
|
2073
|
+
|
2074
|
+
while (responseInterceptorChain.length) {
|
2075
|
+
promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
|
2076
|
+
}
|
2077
|
+
|
2078
|
+
return promise;
|
2079
|
+
};
|
2080
|
+
|
2081
|
+
Axios.prototype.getUri = function getUri(config) {
|
2082
|
+
config = mergeConfig(this.defaults, config);
|
2083
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
2084
|
+
return buildURL(fullPath, config.params, config.paramsSerializer);
|
2085
|
+
};
|
2086
|
+
|
2087
|
+
// Provide aliases for supported request methods
|
2088
|
+
utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
|
2089
|
+
/*eslint func-names:0*/
|
2090
|
+
Axios.prototype[method] = function(url, config) {
|
2091
|
+
return this.request(mergeConfig(config || {}, {
|
2092
|
+
method: method,
|
2093
|
+
url: url,
|
2094
|
+
data: (config || {}).data
|
2095
|
+
}));
|
2096
|
+
};
|
2097
|
+
});
|
2098
|
+
|
2099
|
+
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
2100
|
+
/*eslint func-names:0*/
|
2101
|
+
|
2102
|
+
function generateHTTPMethod(isForm) {
|
2103
|
+
return function httpMethod(url, data, config) {
|
2104
|
+
return this.request(mergeConfig(config || {}, {
|
2105
|
+
method: method,
|
2106
|
+
headers: isForm ? {
|
2107
|
+
'Content-Type': 'multipart/form-data'
|
2108
|
+
} : {},
|
2109
|
+
url: url,
|
2110
|
+
data: data
|
2111
|
+
}));
|
2112
|
+
};
|
2113
|
+
}
|
2114
|
+
|
2115
|
+
Axios.prototype[method] = generateHTTPMethod();
|
2116
|
+
|
2117
|
+
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
2118
|
+
});
|
2119
|
+
|
2120
|
+
var Axios_1 = Axios;
|
2121
|
+
|
2122
|
+
/**
|
2123
|
+
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
2124
|
+
*
|
2125
|
+
* @class
|
2126
|
+
* @param {Function} executor The executor function.
|
2127
|
+
*/
|
2128
|
+
function CancelToken(executor) {
|
2129
|
+
if (typeof executor !== 'function') {
|
2130
|
+
throw new TypeError('executor must be a function.');
|
2131
|
+
}
|
2132
|
+
|
2133
|
+
var resolvePromise;
|
2134
|
+
|
2135
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
2136
|
+
resolvePromise = resolve;
|
2137
|
+
});
|
2138
|
+
|
2139
|
+
var token = this;
|
2140
|
+
|
2141
|
+
// eslint-disable-next-line func-names
|
2142
|
+
this.promise.then(function(cancel) {
|
2143
|
+
if (!token._listeners) return;
|
2144
|
+
|
2145
|
+
var i = token._listeners.length;
|
2146
|
+
|
2147
|
+
while (i-- > 0) {
|
2148
|
+
token._listeners[i](cancel);
|
2149
|
+
}
|
2150
|
+
token._listeners = null;
|
2151
|
+
});
|
2152
|
+
|
2153
|
+
// eslint-disable-next-line func-names
|
2154
|
+
this.promise.then = function(onfulfilled) {
|
2155
|
+
var _resolve;
|
2156
|
+
// eslint-disable-next-line func-names
|
2157
|
+
var promise = new Promise(function(resolve) {
|
2158
|
+
token.subscribe(resolve);
|
2159
|
+
_resolve = resolve;
|
2160
|
+
}).then(onfulfilled);
|
2161
|
+
|
2162
|
+
promise.cancel = function reject() {
|
2163
|
+
token.unsubscribe(_resolve);
|
2164
|
+
};
|
2165
|
+
|
2166
|
+
return promise;
|
2167
|
+
};
|
2168
|
+
|
2169
|
+
executor(function cancel(message, config, request) {
|
2170
|
+
if (token.reason) {
|
2171
|
+
// Cancellation has already been requested
|
2172
|
+
return;
|
2173
|
+
}
|
2174
|
+
|
2175
|
+
token.reason = new CanceledError_1(message, config, request);
|
2176
|
+
resolvePromise(token.reason);
|
2177
|
+
});
|
2178
|
+
}
|
2179
|
+
|
2180
|
+
/**
|
2181
|
+
* Throws a `CanceledError` if cancellation has been requested.
|
2182
|
+
*/
|
2183
|
+
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
2184
|
+
if (this.reason) {
|
2185
|
+
throw this.reason;
|
2186
|
+
}
|
2187
|
+
};
|
2188
|
+
|
2189
|
+
/**
|
2190
|
+
* Subscribe to the cancel signal
|
2191
|
+
*/
|
2192
|
+
|
2193
|
+
CancelToken.prototype.subscribe = function subscribe(listener) {
|
2194
|
+
if (this.reason) {
|
2195
|
+
listener(this.reason);
|
2196
|
+
return;
|
2197
|
+
}
|
2198
|
+
|
2199
|
+
if (this._listeners) {
|
2200
|
+
this._listeners.push(listener);
|
2201
|
+
} else {
|
2202
|
+
this._listeners = [listener];
|
2203
|
+
}
|
2204
|
+
};
|
2205
|
+
|
2206
|
+
/**
|
2207
|
+
* Unsubscribe from the cancel signal
|
2208
|
+
*/
|
2209
|
+
|
2210
|
+
CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
|
2211
|
+
if (!this._listeners) {
|
2212
|
+
return;
|
2213
|
+
}
|
2214
|
+
var index = this._listeners.indexOf(listener);
|
2215
|
+
if (index !== -1) {
|
2216
|
+
this._listeners.splice(index, 1);
|
2217
|
+
}
|
2218
|
+
};
|
2219
|
+
|
2220
|
+
/**
|
2221
|
+
* Returns an object that contains a new `CancelToken` and a function that, when called,
|
2222
|
+
* cancels the `CancelToken`.
|
2223
|
+
*/
|
2224
|
+
CancelToken.source = function source() {
|
2225
|
+
var cancel;
|
2226
|
+
var token = new CancelToken(function executor(c) {
|
2227
|
+
cancel = c;
|
2228
|
+
});
|
2229
|
+
return {
|
2230
|
+
token: token,
|
2231
|
+
cancel: cancel
|
2232
|
+
};
|
2233
|
+
};
|
2234
|
+
|
2235
|
+
var CancelToken_1 = CancelToken;
|
2236
|
+
|
2237
|
+
/**
|
2238
|
+
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
2239
|
+
*
|
2240
|
+
* Common use case would be to use `Function.prototype.apply`.
|
2241
|
+
*
|
2242
|
+
* ```js
|
2243
|
+
* function f(x, y, z) {}
|
2244
|
+
* var args = [1, 2, 3];
|
2245
|
+
* f.apply(null, args);
|
2246
|
+
* ```
|
2247
|
+
*
|
2248
|
+
* With `spread` this example can be re-written.
|
2249
|
+
*
|
2250
|
+
* ```js
|
2251
|
+
* spread(function(x, y, z) {})([1, 2, 3]);
|
2252
|
+
* ```
|
2253
|
+
*
|
2254
|
+
* @param {Function} callback
|
2255
|
+
* @returns {Function}
|
2256
|
+
*/
|
2257
|
+
var spread = function spread(callback) {
|
2258
|
+
return function wrap(arr) {
|
2259
|
+
return callback.apply(null, arr);
|
2260
|
+
};
|
2261
|
+
};
|
2262
|
+
|
2263
|
+
/**
|
2264
|
+
* Determines whether the payload is an error thrown by Axios
|
2265
|
+
*
|
2266
|
+
* @param {*} payload The value to test
|
2267
|
+
* @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
|
2268
|
+
*/
|
2269
|
+
var isAxiosError = function isAxiosError(payload) {
|
2270
|
+
return utils.isObject(payload) && (payload.isAxiosError === true);
|
2271
|
+
};
|
2272
|
+
|
2273
|
+
/**
|
2274
|
+
* Create an instance of Axios
|
2275
|
+
*
|
2276
|
+
* @param {Object} defaultConfig The default config for the instance
|
2277
|
+
* @return {Axios} A new instance of Axios
|
2278
|
+
*/
|
2279
|
+
function createInstance(defaultConfig) {
|
2280
|
+
var context = new Axios_1(defaultConfig);
|
2281
|
+
var instance = bind(Axios_1.prototype.request, context);
|
2282
|
+
|
2283
|
+
// Copy axios.prototype to instance
|
2284
|
+
utils.extend(instance, Axios_1.prototype, context);
|
2285
|
+
|
2286
|
+
// Copy context to instance
|
2287
|
+
utils.extend(instance, context);
|
2288
|
+
|
2289
|
+
// Factory for creating new instances
|
2290
|
+
instance.create = function create(instanceConfig) {
|
2291
|
+
return createInstance(mergeConfig(defaultConfig, instanceConfig));
|
2292
|
+
};
|
2293
|
+
|
2294
|
+
return instance;
|
2295
|
+
}
|
2296
|
+
|
2297
|
+
// Create the default instance to be exported
|
2298
|
+
var axios = createInstance(defaults_1);
|
2299
|
+
|
2300
|
+
// Expose Axios class to allow class inheritance
|
2301
|
+
axios.Axios = Axios_1;
|
2302
|
+
|
2303
|
+
// Expose Cancel & CancelToken
|
2304
|
+
axios.CanceledError = CanceledError_1;
|
2305
|
+
axios.CancelToken = CancelToken_1;
|
2306
|
+
axios.isCancel = isCancel;
|
2307
|
+
axios.VERSION = data.version;
|
2308
|
+
axios.toFormData = toFormData_1;
|
2309
|
+
|
2310
|
+
// Expose AxiosError class
|
2311
|
+
axios.AxiosError = AxiosError_1;
|
2312
|
+
|
2313
|
+
// alias for CanceledError for backward compatibility
|
2314
|
+
axios.Cancel = axios.CanceledError;
|
2315
|
+
|
2316
|
+
// Expose all/spread
|
2317
|
+
axios.all = function all(promises) {
|
2318
|
+
return Promise.all(promises);
|
2319
|
+
};
|
2320
|
+
axios.spread = spread;
|
2321
|
+
|
2322
|
+
// Expose isAxiosError
|
2323
|
+
axios.isAxiosError = isAxiosError;
|
2324
|
+
|
2325
|
+
axios.formToJSON = function(thing) {
|
2326
|
+
return formDataToJSON_1(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
2327
|
+
};
|
2328
|
+
|
2329
|
+
var axios_1 = axios;
|
2330
|
+
|
2331
|
+
// Allow use of default import syntax in TypeScript
|
2332
|
+
var _default = axios;
|
2333
|
+
axios_1.default = _default;
|
2334
|
+
|
2335
|
+
export { axios_1 as default };
|
2336
|
+
//# sourceMappingURL=axios.js.map
|