axios 0.27.2 → 1.0.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.

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