axios 1.0.0-alpha.1 → 1.1.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 (70) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/README.md +59 -48
  3. package/SECURITY.md +3 -2
  4. package/bin/ssl_hotfix.js +1 -1
  5. package/dist/axios.js +1564 -981
  6. package/dist/axios.js.map +1 -1
  7. package/dist/axios.min.js +1 -1
  8. package/dist/axios.min.js.map +1 -1
  9. package/dist/esm/axios.js +1472 -866
  10. package/dist/esm/axios.js.map +1 -1
  11. package/dist/esm/axios.min.js +1 -1
  12. package/dist/esm/axios.min.js.map +1 -1
  13. package/dist/node/axios.cjs +3761 -0
  14. package/dist/node/axios.cjs.map +1 -0
  15. package/gulpfile.js +88 -0
  16. package/index.d.ts +213 -67
  17. package/index.js +2 -1
  18. package/karma.conf.cjs +250 -0
  19. package/lib/adapters/http.js +256 -131
  20. package/lib/adapters/index.js +33 -0
  21. package/lib/adapters/xhr.js +79 -56
  22. package/lib/axios.js +41 -25
  23. package/lib/cancel/CancelToken.js +91 -88
  24. package/lib/cancel/CanceledError.js +5 -4
  25. package/lib/cancel/isCancel.js +2 -2
  26. package/lib/core/Axios.js +127 -100
  27. package/lib/core/AxiosError.js +10 -7
  28. package/lib/core/AxiosHeaders.js +274 -0
  29. package/lib/core/InterceptorManager.js +61 -53
  30. package/lib/core/buildFullPath.js +5 -4
  31. package/lib/core/dispatchRequest.js +21 -39
  32. package/lib/core/mergeConfig.js +8 -7
  33. package/lib/core/settle.js +6 -4
  34. package/lib/core/transformData.js +15 -10
  35. package/lib/defaults/index.js +46 -39
  36. package/lib/defaults/transitional.js +1 -1
  37. package/lib/env/classes/FormData.js +2 -2
  38. package/lib/env/data.js +1 -3
  39. package/lib/helpers/AxiosTransformStream.js +191 -0
  40. package/lib/helpers/AxiosURLSearchParams.js +23 -7
  41. package/lib/helpers/bind.js +2 -2
  42. package/lib/helpers/buildURL.js +16 -7
  43. package/lib/helpers/combineURLs.js +3 -2
  44. package/lib/helpers/cookies.js +43 -44
  45. package/lib/helpers/deprecatedMethod.js +4 -2
  46. package/lib/helpers/formDataToJSON.js +36 -15
  47. package/lib/helpers/fromDataURI.js +15 -13
  48. package/lib/helpers/isAbsoluteURL.js +3 -2
  49. package/lib/helpers/isAxiosError.js +4 -3
  50. package/lib/helpers/isURLSameOrigin.js +55 -56
  51. package/lib/helpers/null.js +1 -1
  52. package/lib/helpers/parseHeaders.js +24 -22
  53. package/lib/helpers/parseProtocol.js +3 -3
  54. package/lib/helpers/speedometer.js +55 -0
  55. package/lib/helpers/spread.js +3 -2
  56. package/lib/helpers/throttle.js +33 -0
  57. package/lib/helpers/toFormData.js +68 -18
  58. package/lib/helpers/toURLEncodedForm.js +5 -5
  59. package/lib/helpers/validator.js +20 -15
  60. package/lib/platform/browser/classes/FormData.js +1 -1
  61. package/lib/platform/browser/classes/URLSearchParams.js +2 -3
  62. package/lib/platform/browser/index.js +38 -6
  63. package/lib/platform/index.js +2 -2
  64. package/lib/platform/node/classes/FormData.js +2 -2
  65. package/lib/platform/node/classes/URLSearchParams.js +2 -3
  66. package/lib/platform/node/index.js +5 -4
  67. package/lib/utils.js +294 -192
  68. package/package.json +55 -22
  69. package/rollup.config.js +37 -7
  70. package/lib/helpers/normalizeHeaderName.js +0 -12
@@ -0,0 +1,3761 @@
1
+ // Axios v1.1.0 Copyright (c) 2022 Matt Zabriskie and contributors
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const FormData$1 = require('form-data');
7
+ const url = require('url');
8
+ const proxyFromEnv = require('proxy-from-env');
9
+ const http = require('http');
10
+ const https = require('https');
11
+ const followRedirects = require('follow-redirects');
12
+ const zlib = require('zlib');
13
+ const stream = require('stream');
14
+ const EventEmitter = require('events');
15
+
16
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
+
18
+ const FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData$1);
19
+ const url__default = /*#__PURE__*/_interopDefaultLegacy(url);
20
+ const http__default = /*#__PURE__*/_interopDefaultLegacy(http);
21
+ const https__default = /*#__PURE__*/_interopDefaultLegacy(https);
22
+ const followRedirects__default = /*#__PURE__*/_interopDefaultLegacy(followRedirects);
23
+ const zlib__default = /*#__PURE__*/_interopDefaultLegacy(zlib);
24
+ const stream__default = /*#__PURE__*/_interopDefaultLegacy(stream);
25
+ const EventEmitter__default = /*#__PURE__*/_interopDefaultLegacy(EventEmitter);
26
+
27
+ function bind(fn, thisArg) {
28
+ return function wrap() {
29
+ return fn.apply(thisArg, arguments);
30
+ };
31
+ }
32
+
33
+ // utils is a library of generic helper functions non-specific to axios
34
+
35
+ const {toString} = Object.prototype;
36
+ const {getPrototypeOf} = Object;
37
+
38
+ const kindOf = (cache => thing => {
39
+ const str = toString.call(thing);
40
+ return cache[str] || (cache[str] = str.slice(8, -1).toLowerCase());
41
+ })(Object.create(null));
42
+
43
+ const kindOfTest = (type) => {
44
+ type = type.toLowerCase();
45
+ return (thing) => kindOf(thing) === type
46
+ };
47
+
48
+ const typeOfTest = type => thing => typeof thing === type;
49
+
50
+ /**
51
+ * Determine if a value is an Array
52
+ *
53
+ * @param {Object} val The value to test
54
+ *
55
+ * @returns {boolean} True if value is an Array, otherwise false
56
+ */
57
+ const {isArray} = Array;
58
+
59
+ /**
60
+ * Determine if a value is undefined
61
+ *
62
+ * @param {*} val The value to test
63
+ *
64
+ * @returns {boolean} True if the value is undefined, otherwise false
65
+ */
66
+ const isUndefined = typeOfTest('undefined');
67
+
68
+ /**
69
+ * Determine if a value is a Buffer
70
+ *
71
+ * @param {*} val The value to test
72
+ *
73
+ * @returns {boolean} True if value is a Buffer, otherwise false
74
+ */
75
+ function isBuffer(val) {
76
+ return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
77
+ && isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
78
+ }
79
+
80
+ /**
81
+ * Determine if a value is an ArrayBuffer
82
+ *
83
+ * @param {*} val The value to test
84
+ *
85
+ * @returns {boolean} True if value is an ArrayBuffer, otherwise false
86
+ */
87
+ const isArrayBuffer = kindOfTest('ArrayBuffer');
88
+
89
+
90
+ /**
91
+ * Determine if a value is a view on an ArrayBuffer
92
+ *
93
+ * @param {*} val The value to test
94
+ *
95
+ * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
96
+ */
97
+ function isArrayBufferView(val) {
98
+ let result;
99
+ if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
100
+ result = ArrayBuffer.isView(val);
101
+ } else {
102
+ result = (val) && (val.buffer) && (isArrayBuffer(val.buffer));
103
+ }
104
+ return result;
105
+ }
106
+
107
+ /**
108
+ * Determine if a value is a String
109
+ *
110
+ * @param {*} val The value to test
111
+ *
112
+ * @returns {boolean} True if value is a String, otherwise false
113
+ */
114
+ const isString = typeOfTest('string');
115
+
116
+ /**
117
+ * Determine if a value is a Function
118
+ *
119
+ * @param {*} val The value to test
120
+ * @returns {boolean} True if value is a Function, otherwise false
121
+ */
122
+ const isFunction = typeOfTest('function');
123
+
124
+ /**
125
+ * Determine if a value is a Number
126
+ *
127
+ * @param {*} val The value to test
128
+ *
129
+ * @returns {boolean} True if value is a Number, otherwise false
130
+ */
131
+ const isNumber = typeOfTest('number');
132
+
133
+ /**
134
+ * Determine if a value is an Object
135
+ *
136
+ * @param {*} thing The value to test
137
+ *
138
+ * @returns {boolean} True if value is an Object, otherwise false
139
+ */
140
+ const isObject = (thing) => thing !== null && typeof thing === 'object';
141
+
142
+ /**
143
+ * Determine if a value is a Boolean
144
+ *
145
+ * @param {*} thing The value to test
146
+ * @returns {boolean} True if value is a Boolean, otherwise false
147
+ */
148
+ const isBoolean = thing => thing === true || thing === false;
149
+
150
+ /**
151
+ * Determine if a value is a plain Object
152
+ *
153
+ * @param {*} val The value to test
154
+ *
155
+ * @returns {boolean} True if value is a plain Object, otherwise false
156
+ */
157
+ const isPlainObject = (val) => {
158
+ if (kindOf(val) !== 'object') {
159
+ return false;
160
+ }
161
+
162
+ const prototype = getPrototypeOf(val);
163
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
164
+ };
165
+
166
+ /**
167
+ * Determine if a value is a Date
168
+ *
169
+ * @param {*} val The value to test
170
+ *
171
+ * @returns {boolean} True if value is a Date, otherwise false
172
+ */
173
+ const isDate = kindOfTest('Date');
174
+
175
+ /**
176
+ * Determine if a value is a File
177
+ *
178
+ * @param {*} val The value to test
179
+ *
180
+ * @returns {boolean} True if value is a File, otherwise false
181
+ */
182
+ const isFile = kindOfTest('File');
183
+
184
+ /**
185
+ * Determine if a value is a Blob
186
+ *
187
+ * @param {*} val The value to test
188
+ *
189
+ * @returns {boolean} True if value is a Blob, otherwise false
190
+ */
191
+ const isBlob = kindOfTest('Blob');
192
+
193
+ /**
194
+ * Determine if a value is a FileList
195
+ *
196
+ * @param {*} val The value to test
197
+ *
198
+ * @returns {boolean} True if value is a File, otherwise false
199
+ */
200
+ const isFileList = kindOfTest('FileList');
201
+
202
+ /**
203
+ * Determine if a value is a Stream
204
+ *
205
+ * @param {*} val The value to test
206
+ *
207
+ * @returns {boolean} True if value is a Stream, otherwise false
208
+ */
209
+ const isStream = (val) => isObject(val) && isFunction(val.pipe);
210
+
211
+ /**
212
+ * Determine if a value is a FormData
213
+ *
214
+ * @param {*} thing The value to test
215
+ *
216
+ * @returns {boolean} True if value is an FormData, otherwise false
217
+ */
218
+ const isFormData = (thing) => {
219
+ const pattern = '[object FormData]';
220
+ return thing && (
221
+ (typeof FormData === 'function' && thing instanceof FormData) ||
222
+ toString.call(thing) === pattern ||
223
+ (isFunction(thing.toString) && thing.toString() === pattern)
224
+ );
225
+ };
226
+
227
+ /**
228
+ * Determine if a value is a URLSearchParams object
229
+ *
230
+ * @param {*} val The value to test
231
+ *
232
+ * @returns {boolean} True if value is a URLSearchParams object, otherwise false
233
+ */
234
+ const isURLSearchParams = kindOfTest('URLSearchParams');
235
+
236
+ /**
237
+ * Trim excess whitespace off the beginning and end of a string
238
+ *
239
+ * @param {String} str The String to trim
240
+ *
241
+ * @returns {String} The String freed of excess whitespace
242
+ */
243
+ const trim = (str) => str.trim ?
244
+ str.trim() : str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
245
+
246
+ /**
247
+ * Iterate over an Array or an Object invoking a function for each item.
248
+ *
249
+ * If `obj` is an Array callback will be called passing
250
+ * the value, index, and complete array for each item.
251
+ *
252
+ * If 'obj' is an Object callback will be called passing
253
+ * the value, key, and complete object for each property.
254
+ *
255
+ * @param {Object|Array} obj The object to iterate
256
+ * @param {Function} fn The callback to invoke for each item
257
+ *
258
+ * @param {Boolean} [allOwnKeys = false]
259
+ * @returns {void}
260
+ */
261
+ function forEach(obj, fn, {allOwnKeys = false} = {}) {
262
+ // Don't bother if no value provided
263
+ if (obj === null || typeof obj === 'undefined') {
264
+ return;
265
+ }
266
+
267
+ let i;
268
+ let l;
269
+
270
+ // Force an array if not already something iterable
271
+ if (typeof obj !== 'object') {
272
+ /*eslint no-param-reassign:0*/
273
+ obj = [obj];
274
+ }
275
+
276
+ if (isArray(obj)) {
277
+ // Iterate over array values
278
+ for (i = 0, l = obj.length; i < l; i++) {
279
+ fn.call(null, obj[i], i, obj);
280
+ }
281
+ } else {
282
+ // Iterate over object keys
283
+ const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
284
+ const len = keys.length;
285
+ let key;
286
+
287
+ for (i = 0; i < len; i++) {
288
+ key = keys[i];
289
+ fn.call(null, obj[key], key, obj);
290
+ }
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Accepts varargs expecting each argument to be an object, then
296
+ * immutably merges the properties of each object and returns result.
297
+ *
298
+ * When multiple objects contain the same key the later object in
299
+ * the arguments list will take precedence.
300
+ *
301
+ * Example:
302
+ *
303
+ * ```js
304
+ * var result = merge({foo: 123}, {foo: 456});
305
+ * console.log(result.foo); // outputs 456
306
+ * ```
307
+ *
308
+ * @param {Object} obj1 Object to merge
309
+ *
310
+ * @returns {Object} Result of all merge properties
311
+ */
312
+ function merge(/* obj1, obj2, obj3, ... */) {
313
+ const result = {};
314
+ const assignValue = (val, key) => {
315
+ if (isPlainObject(result[key]) && isPlainObject(val)) {
316
+ result[key] = merge(result[key], val);
317
+ } else if (isPlainObject(val)) {
318
+ result[key] = merge({}, val);
319
+ } else if (isArray(val)) {
320
+ result[key] = val.slice();
321
+ } else {
322
+ result[key] = val;
323
+ }
324
+ };
325
+
326
+ for (let i = 0, l = arguments.length; i < l; i++) {
327
+ arguments[i] && forEach(arguments[i], assignValue);
328
+ }
329
+ return result;
330
+ }
331
+
332
+ /**
333
+ * Extends object a by mutably adding to it the properties of object b.
334
+ *
335
+ * @param {Object} a The object to be extended
336
+ * @param {Object} b The object to copy properties from
337
+ * @param {Object} thisArg The object to bind function to
338
+ *
339
+ * @param {Boolean} [allOwnKeys]
340
+ * @returns {Object} The resulting value of object a
341
+ */
342
+ const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
343
+ forEach(b, (val, key) => {
344
+ if (thisArg && isFunction(val)) {
345
+ a[key] = bind(val, thisArg);
346
+ } else {
347
+ a[key] = val;
348
+ }
349
+ }, {allOwnKeys});
350
+ return a;
351
+ };
352
+
353
+ /**
354
+ * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
355
+ *
356
+ * @param {string} content with BOM
357
+ *
358
+ * @returns {string} content value without BOM
359
+ */
360
+ const stripBOM = (content) => {
361
+ if (content.charCodeAt(0) === 0xFEFF) {
362
+ content = content.slice(1);
363
+ }
364
+ return content;
365
+ };
366
+
367
+ /**
368
+ * Inherit the prototype methods from one constructor into another
369
+ * @param {function} constructor
370
+ * @param {function} superConstructor
371
+ * @param {object} [props]
372
+ * @param {object} [descriptors]
373
+ *
374
+ * @returns {void}
375
+ */
376
+ const inherits = (constructor, superConstructor, props, descriptors) => {
377
+ constructor.prototype = Object.create(superConstructor.prototype, descriptors);
378
+ constructor.prototype.constructor = constructor;
379
+ Object.defineProperty(constructor, 'super', {
380
+ value: superConstructor.prototype
381
+ });
382
+ props && Object.assign(constructor.prototype, props);
383
+ };
384
+
385
+ /**
386
+ * Resolve object with deep prototype chain to a flat object
387
+ * @param {Object} sourceObj source object
388
+ * @param {Object} [destObj]
389
+ * @param {Function|Boolean} [filter]
390
+ * @param {Function} [propFilter]
391
+ *
392
+ * @returns {Object}
393
+ */
394
+ const toFlatObject = (sourceObj, destObj, filter, propFilter) => {
395
+ let props;
396
+ let i;
397
+ let prop;
398
+ const merged = {};
399
+
400
+ destObj = destObj || {};
401
+ // eslint-disable-next-line no-eq-null,eqeqeq
402
+ if (sourceObj == null) return destObj;
403
+
404
+ do {
405
+ props = Object.getOwnPropertyNames(sourceObj);
406
+ i = props.length;
407
+ while (i-- > 0) {
408
+ prop = props[i];
409
+ if ((!propFilter || propFilter(prop, sourceObj, destObj)) && !merged[prop]) {
410
+ destObj[prop] = sourceObj[prop];
411
+ merged[prop] = true;
412
+ }
413
+ }
414
+ sourceObj = filter !== false && getPrototypeOf(sourceObj);
415
+ } while (sourceObj && (!filter || filter(sourceObj, destObj)) && sourceObj !== Object.prototype);
416
+
417
+ return destObj;
418
+ };
419
+
420
+ /**
421
+ * Determines whether a string ends with the characters of a specified string
422
+ *
423
+ * @param {String} str
424
+ * @param {String} searchString
425
+ * @param {Number} [position= 0]
426
+ *
427
+ * @returns {boolean}
428
+ */
429
+ const endsWith = (str, searchString, position) => {
430
+ str = String(str);
431
+ if (position === undefined || position > str.length) {
432
+ position = str.length;
433
+ }
434
+ position -= searchString.length;
435
+ const lastIndex = str.indexOf(searchString, position);
436
+ return lastIndex !== -1 && lastIndex === position;
437
+ };
438
+
439
+
440
+ /**
441
+ * Returns new array from array like object or null if failed
442
+ *
443
+ * @param {*} [thing]
444
+ *
445
+ * @returns {?Array}
446
+ */
447
+ const toArray = (thing) => {
448
+ if (!thing) return null;
449
+ if (isArray(thing)) return thing;
450
+ let i = thing.length;
451
+ if (!isNumber(i)) return null;
452
+ const arr = new Array(i);
453
+ while (i-- > 0) {
454
+ arr[i] = thing[i];
455
+ }
456
+ return arr;
457
+ };
458
+
459
+ /**
460
+ * Checking if the Uint8Array exists and if it does, it returns a function that checks if the
461
+ * thing passed in is an instance of Uint8Array
462
+ *
463
+ * @param {TypedArray}
464
+ *
465
+ * @returns {Array}
466
+ */
467
+ // eslint-disable-next-line func-names
468
+ const isTypedArray = (TypedArray => {
469
+ // eslint-disable-next-line func-names
470
+ return thing => {
471
+ return TypedArray && thing instanceof TypedArray;
472
+ };
473
+ })(typeof Uint8Array !== 'undefined' && getPrototypeOf(Uint8Array));
474
+
475
+ /**
476
+ * For each entry in the object, call the function with the key and value.
477
+ *
478
+ * @param {Object<any, any>} obj - The object to iterate over.
479
+ * @param {Function} fn - The function to call for each entry.
480
+ *
481
+ * @returns {void}
482
+ */
483
+ const forEachEntry = (obj, fn) => {
484
+ const generator = obj && obj[Symbol.iterator];
485
+
486
+ const iterator = generator.call(obj);
487
+
488
+ let result;
489
+
490
+ while ((result = iterator.next()) && !result.done) {
491
+ const pair = result.value;
492
+ fn.call(obj, pair[0], pair[1]);
493
+ }
494
+ };
495
+
496
+ /**
497
+ * It takes a regular expression and a string, and returns an array of all the matches
498
+ *
499
+ * @param {string} regExp - The regular expression to match against.
500
+ * @param {string} str - The string to search.
501
+ *
502
+ * @returns {Array<boolean>}
503
+ */
504
+ const matchAll = (regExp, str) => {
505
+ let matches;
506
+ const arr = [];
507
+
508
+ while ((matches = regExp.exec(str)) !== null) {
509
+ arr.push(matches);
510
+ }
511
+
512
+ return arr;
513
+ };
514
+
515
+ /* Checking if the kindOfTest function returns true when passed an HTMLFormElement. */
516
+ const isHTMLForm = kindOfTest('HTMLFormElement');
517
+
518
+ const toCamelCase = str => {
519
+ return str.toLowerCase().replace(/[_-\s]([a-z\d])(\w*)/g,
520
+ function replacer(m, p1, p2) {
521
+ return p1.toUpperCase() + p2;
522
+ }
523
+ );
524
+ };
525
+
526
+ /* Creating a function that will check if an object has a property. */
527
+ const hasOwnProperty = (({hasOwnProperty}) => (obj, prop) => hasOwnProperty.call(obj, prop))(Object.prototype);
528
+
529
+ /**
530
+ * Determine if a value is a RegExp object
531
+ *
532
+ * @param {*} val The value to test
533
+ *
534
+ * @returns {boolean} True if value is a RegExp object, otherwise false
535
+ */
536
+ const isRegExp = kindOfTest('RegExp');
537
+
538
+ const reduceDescriptors = (obj, reducer) => {
539
+ const descriptors = Object.getOwnPropertyDescriptors(obj);
540
+ const reducedDescriptors = {};
541
+
542
+ forEach(descriptors, (descriptor, name) => {
543
+ if (reducer(descriptor, name, obj) !== false) {
544
+ reducedDescriptors[name] = descriptor;
545
+ }
546
+ });
547
+
548
+ Object.defineProperties(obj, reducedDescriptors);
549
+ };
550
+
551
+ /**
552
+ * Makes all methods read-only
553
+ * @param {Object} obj
554
+ */
555
+
556
+ const freezeMethods = (obj) => {
557
+ reduceDescriptors(obj, (descriptor, name) => {
558
+ const value = obj[name];
559
+
560
+ if (!isFunction(value)) return;
561
+
562
+ descriptor.enumerable = false;
563
+
564
+ if ('writable' in descriptor) {
565
+ descriptor.writable = false;
566
+ return;
567
+ }
568
+
569
+ if (!descriptor.set) {
570
+ descriptor.set = () => {
571
+ throw Error('Can not read-only method \'' + name + '\'');
572
+ };
573
+ }
574
+ });
575
+ };
576
+
577
+ const toObjectSet = (arrayOrString, delimiter) => {
578
+ const obj = {};
579
+
580
+ const define = (arr) => {
581
+ arr.forEach(value => {
582
+ obj[value] = true;
583
+ });
584
+ };
585
+
586
+ isArray(arrayOrString) ? define(arrayOrString) : define(String(arrayOrString).split(delimiter));
587
+
588
+ return obj;
589
+ };
590
+
591
+ const noop = () => {};
592
+
593
+ const toFiniteNumber = (value, defaultValue) => {
594
+ value = +value;
595
+ return Number.isFinite(value) ? value : defaultValue;
596
+ };
597
+
598
+ const utils = {
599
+ isArray,
600
+ isArrayBuffer,
601
+ isBuffer,
602
+ isFormData,
603
+ isArrayBufferView,
604
+ isString,
605
+ isNumber,
606
+ isBoolean,
607
+ isObject,
608
+ isPlainObject,
609
+ isUndefined,
610
+ isDate,
611
+ isFile,
612
+ isBlob,
613
+ isRegExp,
614
+ isFunction,
615
+ isStream,
616
+ isURLSearchParams,
617
+ isTypedArray,
618
+ isFileList,
619
+ forEach,
620
+ merge,
621
+ extend,
622
+ trim,
623
+ stripBOM,
624
+ inherits,
625
+ toFlatObject,
626
+ kindOf,
627
+ kindOfTest,
628
+ endsWith,
629
+ toArray,
630
+ forEachEntry,
631
+ matchAll,
632
+ isHTMLForm,
633
+ hasOwnProperty,
634
+ hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
635
+ reduceDescriptors,
636
+ freezeMethods,
637
+ toObjectSet,
638
+ toCamelCase,
639
+ noop,
640
+ toFiniteNumber
641
+ };
642
+
643
+ /**
644
+ * Create an Error with the specified message, config, error code, request and response.
645
+ *
646
+ * @param {string} message The error message.
647
+ * @param {string} [code] The error code (for example, 'ECONNABORTED').
648
+ * @param {Object} [config] The config.
649
+ * @param {Object} [request] The request.
650
+ * @param {Object} [response] The response.
651
+ *
652
+ * @returns {Error} The created error.
653
+ */
654
+ function AxiosError(message, code, config, request, response) {
655
+ Error.call(this);
656
+
657
+ if (Error.captureStackTrace) {
658
+ Error.captureStackTrace(this, this.constructor);
659
+ } else {
660
+ this.stack = (new Error()).stack;
661
+ }
662
+
663
+ this.message = message;
664
+ this.name = 'AxiosError';
665
+ code && (this.code = code);
666
+ config && (this.config = config);
667
+ request && (this.request = request);
668
+ response && (this.response = response);
669
+ }
670
+
671
+ utils.inherits(AxiosError, Error, {
672
+ toJSON: function toJSON() {
673
+ return {
674
+ // Standard
675
+ message: this.message,
676
+ name: this.name,
677
+ // Microsoft
678
+ description: this.description,
679
+ number: this.number,
680
+ // Mozilla
681
+ fileName: this.fileName,
682
+ lineNumber: this.lineNumber,
683
+ columnNumber: this.columnNumber,
684
+ stack: this.stack,
685
+ // Axios
686
+ config: this.config,
687
+ code: this.code,
688
+ status: this.response && this.response.status ? this.response.status : null
689
+ };
690
+ }
691
+ });
692
+
693
+ const prototype$1 = AxiosError.prototype;
694
+ const descriptors = {};
695
+
696
+ [
697
+ 'ERR_BAD_OPTION_VALUE',
698
+ 'ERR_BAD_OPTION',
699
+ 'ECONNABORTED',
700
+ 'ETIMEDOUT',
701
+ 'ERR_NETWORK',
702
+ 'ERR_FR_TOO_MANY_REDIRECTS',
703
+ 'ERR_DEPRECATED',
704
+ 'ERR_BAD_RESPONSE',
705
+ 'ERR_BAD_REQUEST',
706
+ 'ERR_CANCELED',
707
+ 'ERR_NOT_SUPPORT',
708
+ 'ERR_INVALID_URL'
709
+ // eslint-disable-next-line func-names
710
+ ].forEach(code => {
711
+ descriptors[code] = {value: code};
712
+ });
713
+
714
+ Object.defineProperties(AxiosError, descriptors);
715
+ Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
716
+
717
+ // eslint-disable-next-line func-names
718
+ AxiosError.from = (error, code, config, request, response, customProps) => {
719
+ const axiosError = Object.create(prototype$1);
720
+
721
+ utils.toFlatObject(error, axiosError, function filter(obj) {
722
+ return obj !== Error.prototype;
723
+ }, prop => {
724
+ return prop !== 'isAxiosError';
725
+ });
726
+
727
+ AxiosError.call(axiosError, error.message, code, config, request, response);
728
+
729
+ axiosError.cause = error;
730
+
731
+ axiosError.name = error.name;
732
+
733
+ customProps && Object.assign(axiosError, customProps);
734
+
735
+ return axiosError;
736
+ };
737
+
738
+ /**
739
+ * Determines if the given thing is a array or js object.
740
+ *
741
+ * @param {string} thing - The object or array to be visited.
742
+ *
743
+ * @returns {boolean}
744
+ */
745
+ function isVisitable(thing) {
746
+ return utils.isPlainObject(thing) || utils.isArray(thing);
747
+ }
748
+
749
+ /**
750
+ * It removes the brackets from the end of a string
751
+ *
752
+ * @param {string} key - The key of the parameter.
753
+ *
754
+ * @returns {string} the key without the brackets.
755
+ */
756
+ function removeBrackets(key) {
757
+ return utils.endsWith(key, '[]') ? key.slice(0, -2) : key;
758
+ }
759
+
760
+ /**
761
+ * It takes a path, a key, and a boolean, and returns a string
762
+ *
763
+ * @param {string} path - The path to the current key.
764
+ * @param {string} key - The key of the current object being iterated over.
765
+ * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
766
+ *
767
+ * @returns {string} The path to the current key.
768
+ */
769
+ function renderKey(path, key, dots) {
770
+ if (!path) return key;
771
+ return path.concat(key).map(function each(token, i) {
772
+ // eslint-disable-next-line no-param-reassign
773
+ token = removeBrackets(token);
774
+ return !dots && i ? '[' + token + ']' : token;
775
+ }).join(dots ? '.' : '');
776
+ }
777
+
778
+ /**
779
+ * If the array is an array and none of its elements are visitable, then it's a flat array.
780
+ *
781
+ * @param {Array<any>} arr - The array to check
782
+ *
783
+ * @returns {boolean}
784
+ */
785
+ function isFlatArray(arr) {
786
+ return utils.isArray(arr) && !arr.some(isVisitable);
787
+ }
788
+
789
+ const predicates = utils.toFlatObject(utils, {}, null, function filter(prop) {
790
+ return /^is[A-Z]/.test(prop);
791
+ });
792
+
793
+ /**
794
+ * If the thing is a FormData object, return true, otherwise return false.
795
+ *
796
+ * @param {unknown} thing - The thing to check.
797
+ *
798
+ * @returns {boolean}
799
+ */
800
+ function isSpecCompliant(thing) {
801
+ return thing && utils.isFunction(thing.append) && thing[Symbol.toStringTag] === 'FormData' && thing[Symbol.iterator];
802
+ }
803
+
804
+ /**
805
+ * Convert a data object to FormData
806
+ *
807
+ * @param {Object} obj
808
+ * @param {?Object} [formData]
809
+ * @param {?Object} [options]
810
+ * @param {Function} [options.visitor]
811
+ * @param {Boolean} [options.metaTokens = true]
812
+ * @param {Boolean} [options.dots = false]
813
+ * @param {?Boolean} [options.indexes = false]
814
+ *
815
+ * @returns {Object}
816
+ **/
817
+
818
+ /**
819
+ * It converts an object into a FormData object
820
+ *
821
+ * @param {Object<any, any>} obj - The object to convert to form data.
822
+ * @param {string} formData - The FormData object to append to.
823
+ * @param {Object<string, any>} options
824
+ *
825
+ * @returns
826
+ */
827
+ function toFormData(obj, formData, options) {
828
+ if (!utils.isObject(obj)) {
829
+ throw new TypeError('target must be an object');
830
+ }
831
+
832
+ // eslint-disable-next-line no-param-reassign
833
+ formData = formData || new (FormData__default["default"] || FormData)();
834
+
835
+ // eslint-disable-next-line no-param-reassign
836
+ options = utils.toFlatObject(options, {
837
+ metaTokens: true,
838
+ dots: false,
839
+ indexes: false
840
+ }, false, function defined(option, source) {
841
+ // eslint-disable-next-line no-eq-null,eqeqeq
842
+ return !utils.isUndefined(source[option]);
843
+ });
844
+
845
+ const metaTokens = options.metaTokens;
846
+ // eslint-disable-next-line no-use-before-define
847
+ const visitor = options.visitor || defaultVisitor;
848
+ const dots = options.dots;
849
+ const indexes = options.indexes;
850
+ const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
851
+ const useBlob = _Blob && isSpecCompliant(formData);
852
+
853
+ if (!utils.isFunction(visitor)) {
854
+ throw new TypeError('visitor must be a function');
855
+ }
856
+
857
+ function convertValue(value) {
858
+ if (value === null) return '';
859
+
860
+ if (utils.isDate(value)) {
861
+ return value.toISOString();
862
+ }
863
+
864
+ if (!useBlob && utils.isBlob(value)) {
865
+ throw new AxiosError('Blob is not supported. Use a Buffer instead.');
866
+ }
867
+
868
+ if (utils.isArrayBuffer(value) || utils.isTypedArray(value)) {
869
+ return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
870
+ }
871
+
872
+ return value;
873
+ }
874
+
875
+ /**
876
+ * Default visitor.
877
+ *
878
+ * @param {*} value
879
+ * @param {String|Number} key
880
+ * @param {Array<String|Number>} path
881
+ * @this {FormData}
882
+ *
883
+ * @returns {boolean} return true to visit the each prop of the value recursively
884
+ */
885
+ function defaultVisitor(value, key, path) {
886
+ let arr = value;
887
+
888
+ if (value && !path && typeof value === 'object') {
889
+ if (utils.endsWith(key, '{}')) {
890
+ // eslint-disable-next-line no-param-reassign
891
+ key = metaTokens ? key : key.slice(0, -2);
892
+ // eslint-disable-next-line no-param-reassign
893
+ value = JSON.stringify(value);
894
+ } else if (
895
+ (utils.isArray(value) && isFlatArray(value)) ||
896
+ (utils.isFileList(value) || utils.endsWith(key, '[]') && (arr = utils.toArray(value))
897
+ )) {
898
+ // eslint-disable-next-line no-param-reassign
899
+ key = removeBrackets(key);
900
+
901
+ arr.forEach(function each(el, index) {
902
+ !utils.isUndefined(el) && formData.append(
903
+ // eslint-disable-next-line no-nested-ternary
904
+ indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
905
+ convertValue(el)
906
+ );
907
+ });
908
+ return false;
909
+ }
910
+ }
911
+
912
+ if (isVisitable(value)) {
913
+ return true;
914
+ }
915
+
916
+ formData.append(renderKey(path, key, dots), convertValue(value));
917
+
918
+ return false;
919
+ }
920
+
921
+ const stack = [];
922
+
923
+ const exposedHelpers = Object.assign(predicates, {
924
+ defaultVisitor,
925
+ convertValue,
926
+ isVisitable
927
+ });
928
+
929
+ function build(value, path) {
930
+ if (utils.isUndefined(value)) return;
931
+
932
+ if (stack.indexOf(value) !== -1) {
933
+ throw Error('Circular reference detected in ' + path.join('.'));
934
+ }
935
+
936
+ stack.push(value);
937
+
938
+ utils.forEach(value, function each(el, key) {
939
+ const result = !utils.isUndefined(el) && visitor.call(
940
+ formData, el, utils.isString(key) ? key.trim() : key, path, exposedHelpers
941
+ );
942
+
943
+ if (result === true) {
944
+ build(el, path ? path.concat(key) : [key]);
945
+ }
946
+ });
947
+
948
+ stack.pop();
949
+ }
950
+
951
+ if (!utils.isObject(obj)) {
952
+ throw new TypeError('data must be an object');
953
+ }
954
+
955
+ build(obj);
956
+
957
+ return formData;
958
+ }
959
+
960
+ /**
961
+ * It encodes a string by replacing all characters that are not in the unreserved set with
962
+ * their percent-encoded equivalents
963
+ *
964
+ * @param {string} str - The string to encode.
965
+ *
966
+ * @returns {string} The encoded string.
967
+ */
968
+ function encode$1(str) {
969
+ const charMap = {
970
+ '!': '%21',
971
+ "'": '%27',
972
+ '(': '%28',
973
+ ')': '%29',
974
+ '~': '%7E',
975
+ '%20': '+',
976
+ '%00': '\x00'
977
+ };
978
+ return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
979
+ return charMap[match];
980
+ });
981
+ }
982
+
983
+ /**
984
+ * It takes a params object and converts it to a FormData object
985
+ *
986
+ * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
987
+ * @param {Object<string, any>} options - The options object passed to the Axios constructor.
988
+ *
989
+ * @returns {void}
990
+ */
991
+ function AxiosURLSearchParams(params, options) {
992
+ this._pairs = [];
993
+
994
+ params && toFormData(params, this, options);
995
+ }
996
+
997
+ const prototype = AxiosURLSearchParams.prototype;
998
+
999
+ prototype.append = function append(name, value) {
1000
+ this._pairs.push([name, value]);
1001
+ };
1002
+
1003
+ prototype.toString = function toString(encoder) {
1004
+ const _encode = encoder ? function(value) {
1005
+ return encoder.call(this, value, encode$1);
1006
+ } : encode$1;
1007
+
1008
+ return this._pairs.map(function each(pair) {
1009
+ return _encode(pair[0]) + '=' + _encode(pair[1]);
1010
+ }, '').join('&');
1011
+ };
1012
+
1013
+ /**
1014
+ * It replaces all instances of the characters `:`, `$`, `,`, `+`, `[`, and `]` with their
1015
+ * URI encoded counterparts
1016
+ *
1017
+ * @param {string} val The value to be encoded.
1018
+ *
1019
+ * @returns {string} The encoded value.
1020
+ */
1021
+ function encode(val) {
1022
+ return encodeURIComponent(val).
1023
+ replace(/%3A/gi, ':').
1024
+ replace(/%24/g, '$').
1025
+ replace(/%2C/gi, ',').
1026
+ replace(/%20/g, '+').
1027
+ replace(/%5B/gi, '[').
1028
+ replace(/%5D/gi, ']');
1029
+ }
1030
+
1031
+ /**
1032
+ * Build a URL by appending params to the end
1033
+ *
1034
+ * @param {string} url The base of the url (e.g., http://www.google.com)
1035
+ * @param {object} [params] The params to be appended
1036
+ * @param {?object} options
1037
+ *
1038
+ * @returns {string} The formatted url
1039
+ */
1040
+ function buildURL(url, params, options) {
1041
+ /*eslint no-param-reassign:0*/
1042
+ if (!params) {
1043
+ return url;
1044
+ }
1045
+
1046
+ const hashmarkIndex = url.indexOf('#');
1047
+
1048
+ if (hashmarkIndex !== -1) {
1049
+ url = url.slice(0, hashmarkIndex);
1050
+ }
1051
+
1052
+ const _encode = options && options.encode || encode;
1053
+
1054
+ const serializerParams = utils.isURLSearchParams(params) ?
1055
+ params.toString() :
1056
+ new AxiosURLSearchParams(params, options).toString(_encode);
1057
+
1058
+ if (serializerParams) {
1059
+ url += (url.indexOf('?') === -1 ? '?' : '&') + serializerParams;
1060
+ }
1061
+
1062
+ return url;
1063
+ }
1064
+
1065
+ class InterceptorManager {
1066
+ constructor() {
1067
+ this.handlers = [];
1068
+ }
1069
+
1070
+ /**
1071
+ * Add a new interceptor to the stack
1072
+ *
1073
+ * @param {Function} fulfilled The function to handle `then` for a `Promise`
1074
+ * @param {Function} rejected The function to handle `reject` for a `Promise`
1075
+ *
1076
+ * @return {Number} An ID used to remove interceptor later
1077
+ */
1078
+ use(fulfilled, rejected, options) {
1079
+ this.handlers.push({
1080
+ fulfilled,
1081
+ rejected,
1082
+ synchronous: options ? options.synchronous : false,
1083
+ runWhen: options ? options.runWhen : null
1084
+ });
1085
+ return this.handlers.length - 1;
1086
+ }
1087
+
1088
+ /**
1089
+ * Remove an interceptor from the stack
1090
+ *
1091
+ * @param {Number} id The ID that was returned by `use`
1092
+ *
1093
+ * @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
1094
+ */
1095
+ eject(id) {
1096
+ if (this.handlers[id]) {
1097
+ this.handlers[id] = null;
1098
+ }
1099
+ }
1100
+
1101
+ /**
1102
+ * Clear all interceptors from the stack
1103
+ *
1104
+ * @returns {void}
1105
+ */
1106
+ clear() {
1107
+ if (this.handlers) {
1108
+ this.handlers = [];
1109
+ }
1110
+ }
1111
+
1112
+ /**
1113
+ * Iterate over all the registered interceptors
1114
+ *
1115
+ * This method is particularly useful for skipping over any
1116
+ * interceptors that may have become `null` calling `eject`.
1117
+ *
1118
+ * @param {Function} fn The function to call for each interceptor
1119
+ *
1120
+ * @returns {void}
1121
+ */
1122
+ forEach(fn) {
1123
+ utils.forEach(this.handlers, function forEachHandler(h) {
1124
+ if (h !== null) {
1125
+ fn(h);
1126
+ }
1127
+ });
1128
+ }
1129
+ }
1130
+
1131
+ const transitionalDefaults = {
1132
+ silentJSONParsing: true,
1133
+ forcedJSONParsing: true,
1134
+ clarifyTimeoutError: false
1135
+ };
1136
+
1137
+ const URLSearchParams = url__default["default"].URLSearchParams;
1138
+
1139
+ const platform = {
1140
+ isNode: true,
1141
+ classes: {
1142
+ URLSearchParams,
1143
+ FormData: FormData__default["default"],
1144
+ Blob: typeof Blob !== 'undefined' && Blob || null
1145
+ },
1146
+ protocols: [ 'http', 'https', 'file', 'data' ]
1147
+ };
1148
+
1149
+ function toURLEncodedForm(data, options) {
1150
+ return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
1151
+ visitor: function(value, key, path, helpers) {
1152
+ if (utils.isBuffer(value)) {
1153
+ this.append(key, value.toString('base64'));
1154
+ return false;
1155
+ }
1156
+
1157
+ return helpers.defaultVisitor.apply(this, arguments);
1158
+ }
1159
+ }, options));
1160
+ }
1161
+
1162
+ /**
1163
+ * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
1164
+ *
1165
+ * @param {string} name - The name of the property to get.
1166
+ *
1167
+ * @returns An array of strings.
1168
+ */
1169
+ function parsePropPath(name) {
1170
+ // foo[x][y][z]
1171
+ // foo.x.y.z
1172
+ // foo-x-y-z
1173
+ // foo x y z
1174
+ return utils.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
1175
+ return match[0] === '[]' ? '' : match[1] || match[0];
1176
+ });
1177
+ }
1178
+
1179
+ /**
1180
+ * Convert an array to an object.
1181
+ *
1182
+ * @param {Array<any>} arr - The array to convert to an object.
1183
+ *
1184
+ * @returns An object with the same keys and values as the array.
1185
+ */
1186
+ function arrayToObject(arr) {
1187
+ const obj = {};
1188
+ const keys = Object.keys(arr);
1189
+ let i;
1190
+ const len = keys.length;
1191
+ let key;
1192
+ for (i = 0; i < len; i++) {
1193
+ key = keys[i];
1194
+ obj[key] = arr[key];
1195
+ }
1196
+ return obj;
1197
+ }
1198
+
1199
+ /**
1200
+ * It takes a FormData object and returns a JavaScript object
1201
+ *
1202
+ * @param {string} formData The FormData object to convert to JSON.
1203
+ *
1204
+ * @returns {Object<string, any> | null} The converted object.
1205
+ */
1206
+ function formDataToJSON(formData) {
1207
+ function buildPath(path, value, target, index) {
1208
+ let name = path[index++];
1209
+ const isNumericKey = Number.isFinite(+name);
1210
+ const isLast = index >= path.length;
1211
+ name = !name && utils.isArray(target) ? target.length : name;
1212
+
1213
+ if (isLast) {
1214
+ if (utils.hasOwnProp(target, name)) {
1215
+ target[name] = [target[name], value];
1216
+ } else {
1217
+ target[name] = value;
1218
+ }
1219
+
1220
+ return !isNumericKey;
1221
+ }
1222
+
1223
+ if (!target[name] || !utils.isObject(target[name])) {
1224
+ target[name] = [];
1225
+ }
1226
+
1227
+ const result = buildPath(path, value, target[name], index);
1228
+
1229
+ if (result && utils.isArray(target[name])) {
1230
+ target[name] = arrayToObject(target[name]);
1231
+ }
1232
+
1233
+ return !isNumericKey;
1234
+ }
1235
+
1236
+ if (utils.isFormData(formData) && utils.isFunction(formData.entries)) {
1237
+ const obj = {};
1238
+
1239
+ utils.forEachEntry(formData, (name, value) => {
1240
+ buildPath(parsePropPath(name), value, obj, 0);
1241
+ });
1242
+
1243
+ return obj;
1244
+ }
1245
+
1246
+ return null;
1247
+ }
1248
+
1249
+ /**
1250
+ * Resolve or reject a Promise based on response status.
1251
+ *
1252
+ * @param {Function} resolve A function that resolves the promise.
1253
+ * @param {Function} reject A function that rejects the promise.
1254
+ * @param {object} response The response.
1255
+ *
1256
+ * @returns {object} The response.
1257
+ */
1258
+ function settle(resolve, reject, response) {
1259
+ const validateStatus = response.config.validateStatus;
1260
+ if (!response.status || !validateStatus || validateStatus(response.status)) {
1261
+ resolve(response);
1262
+ } else {
1263
+ reject(new AxiosError(
1264
+ 'Request failed with status code ' + response.status,
1265
+ [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
1266
+ response.config,
1267
+ response.request,
1268
+ response
1269
+ ));
1270
+ }
1271
+ }
1272
+
1273
+ /**
1274
+ * Determines whether the specified URL is absolute
1275
+ *
1276
+ * @param {string} url The URL to test
1277
+ *
1278
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
1279
+ */
1280
+ function isAbsoluteURL(url) {
1281
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
1282
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
1283
+ // by any combination of letters, digits, plus, period, or hyphen.
1284
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
1285
+ }
1286
+
1287
+ /**
1288
+ * Creates a new URL by combining the specified URLs
1289
+ *
1290
+ * @param {string} baseURL The base URL
1291
+ * @param {string} relativeURL The relative URL
1292
+ *
1293
+ * @returns {string} The combined URL
1294
+ */
1295
+ function combineURLs(baseURL, relativeURL) {
1296
+ return relativeURL
1297
+ ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
1298
+ : baseURL;
1299
+ }
1300
+
1301
+ /**
1302
+ * Creates a new URL by combining the baseURL with the requestedURL,
1303
+ * only when the requestedURL is not already an absolute URL.
1304
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
1305
+ *
1306
+ * @param {string} baseURL The base URL
1307
+ * @param {string} requestedURL Absolute or relative URL to combine
1308
+ *
1309
+ * @returns {string} The combined full path
1310
+ */
1311
+ function buildFullPath(baseURL, requestedURL) {
1312
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
1313
+ return combineURLs(baseURL, requestedURL);
1314
+ }
1315
+ return requestedURL;
1316
+ }
1317
+
1318
+ const VERSION = "1.1.0";
1319
+
1320
+ /**
1321
+ * A `CanceledError` is an object that is thrown when an operation is canceled.
1322
+ *
1323
+ * @param {string=} message The message.
1324
+ * @param {Object=} config The config.
1325
+ * @param {Object=} request The request.
1326
+ *
1327
+ * @returns {CanceledError} The created error.
1328
+ */
1329
+ function CanceledError(message, config, request) {
1330
+ // eslint-disable-next-line no-eq-null,eqeqeq
1331
+ AxiosError.call(this, message == null ? 'canceled' : message, AxiosError.ERR_CANCELED, config, request);
1332
+ this.name = 'CanceledError';
1333
+ }
1334
+
1335
+ utils.inherits(CanceledError, AxiosError, {
1336
+ __CANCEL__: true
1337
+ });
1338
+
1339
+ function parseProtocol(url) {
1340
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
1341
+ return match && match[1] || '';
1342
+ }
1343
+
1344
+ const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
1345
+
1346
+ /**
1347
+ * Parse data uri to a Buffer or Blob
1348
+ *
1349
+ * @param {String} uri
1350
+ * @param {?Boolean} asBlob
1351
+ * @param {?Object} options
1352
+ * @param {?Function} options.Blob
1353
+ *
1354
+ * @returns {Buffer|Blob}
1355
+ */
1356
+ function fromDataURI(uri, asBlob, options) {
1357
+ const _Blob = options && options.Blob || platform.classes.Blob;
1358
+ const protocol = parseProtocol(uri);
1359
+
1360
+ if (asBlob === undefined && _Blob) {
1361
+ asBlob = true;
1362
+ }
1363
+
1364
+ if (protocol === 'data') {
1365
+ uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
1366
+
1367
+ const match = DATA_URL_PATTERN.exec(uri);
1368
+
1369
+ if (!match) {
1370
+ throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
1371
+ }
1372
+
1373
+ const mime = match[1];
1374
+ const isBase64 = match[2];
1375
+ const body = match[3];
1376
+ const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
1377
+
1378
+ if (asBlob) {
1379
+ if (!_Blob) {
1380
+ throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
1381
+ }
1382
+
1383
+ return new _Blob([buffer], {type: mime});
1384
+ }
1385
+
1386
+ return buffer;
1387
+ }
1388
+
1389
+ throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
1390
+ }
1391
+
1392
+ // RawAxiosHeaders whose duplicates are ignored by node
1393
+ // c.f. https://nodejs.org/api/http.html#http_message_headers
1394
+ const ignoreDuplicateOf = utils.toObjectSet([
1395
+ 'age', 'authorization', 'content-length', 'content-type', 'etag',
1396
+ 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
1397
+ 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
1398
+ 'referer', 'retry-after', 'user-agent'
1399
+ ]);
1400
+
1401
+ /**
1402
+ * Parse headers into an object
1403
+ *
1404
+ * ```
1405
+ * Date: Wed, 27 Aug 2014 08:58:49 GMT
1406
+ * Content-Type: application/json
1407
+ * Connection: keep-alive
1408
+ * Transfer-Encoding: chunked
1409
+ * ```
1410
+ *
1411
+ * @param {String} rawHeaders Headers needing to be parsed
1412
+ *
1413
+ * @returns {Object} Headers parsed into an object
1414
+ */
1415
+ const parseHeaders = rawHeaders => {
1416
+ const parsed = {};
1417
+ let key;
1418
+ let val;
1419
+ let i;
1420
+
1421
+ rawHeaders && rawHeaders.split('\n').forEach(function parser(line) {
1422
+ i = line.indexOf(':');
1423
+ key = line.substring(0, i).trim().toLowerCase();
1424
+ val = line.substring(i + 1).trim();
1425
+
1426
+ if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
1427
+ return;
1428
+ }
1429
+
1430
+ if (key === 'set-cookie') {
1431
+ if (parsed[key]) {
1432
+ parsed[key].push(val);
1433
+ } else {
1434
+ parsed[key] = [val];
1435
+ }
1436
+ } else {
1437
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1438
+ }
1439
+ });
1440
+
1441
+ return parsed;
1442
+ };
1443
+
1444
+ const $internals = Symbol('internals');
1445
+ const $defaults = Symbol('defaults');
1446
+
1447
+ function normalizeHeader(header) {
1448
+ return header && String(header).trim().toLowerCase();
1449
+ }
1450
+
1451
+ function normalizeValue(value) {
1452
+ if (value === false || value == null) {
1453
+ return value;
1454
+ }
1455
+
1456
+ return String(value);
1457
+ }
1458
+
1459
+ function parseTokens(str) {
1460
+ const tokens = Object.create(null);
1461
+ const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
1462
+ let match;
1463
+
1464
+ while ((match = tokensRE.exec(str))) {
1465
+ tokens[match[1]] = match[2];
1466
+ }
1467
+
1468
+ return tokens;
1469
+ }
1470
+
1471
+ function matchHeaderValue(context, value, header, filter) {
1472
+ if (utils.isFunction(filter)) {
1473
+ return filter.call(this, value, header);
1474
+ }
1475
+
1476
+ if (!utils.isString(value)) return;
1477
+
1478
+ if (utils.isString(filter)) {
1479
+ return value.indexOf(filter) !== -1;
1480
+ }
1481
+
1482
+ if (utils.isRegExp(filter)) {
1483
+ return filter.test(value);
1484
+ }
1485
+ }
1486
+
1487
+ function formatHeader(header) {
1488
+ return header.trim()
1489
+ .toLowerCase().replace(/([a-z\d])(\w*)/g, (w, char, str) => {
1490
+ return char.toUpperCase() + str;
1491
+ });
1492
+ }
1493
+
1494
+ function buildAccessors(obj, header) {
1495
+ const accessorName = utils.toCamelCase(' ' + header);
1496
+
1497
+ ['get', 'set', 'has'].forEach(methodName => {
1498
+ Object.defineProperty(obj, methodName + accessorName, {
1499
+ value: function(arg1, arg2, arg3) {
1500
+ return this[methodName].call(this, header, arg1, arg2, arg3);
1501
+ },
1502
+ configurable: true
1503
+ });
1504
+ });
1505
+ }
1506
+
1507
+ function findKey(obj, key) {
1508
+ key = key.toLowerCase();
1509
+ const keys = Object.keys(obj);
1510
+ let i = keys.length;
1511
+ let _key;
1512
+ while (i-- > 0) {
1513
+ _key = keys[i];
1514
+ if (key === _key.toLowerCase()) {
1515
+ return _key;
1516
+ }
1517
+ }
1518
+ return null;
1519
+ }
1520
+
1521
+ function AxiosHeaders(headers, defaults) {
1522
+ headers && this.set(headers);
1523
+ this[$defaults] = defaults || null;
1524
+ }
1525
+
1526
+ Object.assign(AxiosHeaders.prototype, {
1527
+ set: function(header, valueOrRewrite, rewrite) {
1528
+ const self = this;
1529
+
1530
+ function setHeader(_value, _header, _rewrite) {
1531
+ const lHeader = normalizeHeader(_header);
1532
+
1533
+ if (!lHeader) {
1534
+ throw new Error('header name must be a non-empty string');
1535
+ }
1536
+
1537
+ const key = findKey(self, lHeader);
1538
+
1539
+ if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
1540
+ return;
1541
+ }
1542
+
1543
+ if (utils.isArray(_value)) {
1544
+ _value = _value.map(normalizeValue);
1545
+ } else {
1546
+ _value = normalizeValue(_value);
1547
+ }
1548
+
1549
+ self[key || _header] = _value;
1550
+ }
1551
+
1552
+ if (utils.isPlainObject(header)) {
1553
+ utils.forEach(header, (_value, _header) => {
1554
+ setHeader(_value, _header, valueOrRewrite);
1555
+ });
1556
+ } else {
1557
+ setHeader(valueOrRewrite, header, rewrite);
1558
+ }
1559
+
1560
+ return this;
1561
+ },
1562
+
1563
+ get: function(header, parser) {
1564
+ header = normalizeHeader(header);
1565
+
1566
+ if (!header) return undefined;
1567
+
1568
+ const key = findKey(this, header);
1569
+
1570
+ if (key) {
1571
+ const value = this[key];
1572
+
1573
+ if (!parser) {
1574
+ return value;
1575
+ }
1576
+
1577
+ if (parser === true) {
1578
+ return parseTokens(value);
1579
+ }
1580
+
1581
+ if (utils.isFunction(parser)) {
1582
+ return parser.call(this, value, key);
1583
+ }
1584
+
1585
+ if (utils.isRegExp(parser)) {
1586
+ return parser.exec(value);
1587
+ }
1588
+
1589
+ throw new TypeError('parser must be boolean|regexp|function');
1590
+ }
1591
+ },
1592
+
1593
+ has: function(header, matcher) {
1594
+ header = normalizeHeader(header);
1595
+
1596
+ if (header) {
1597
+ const key = findKey(this, header);
1598
+
1599
+ return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1600
+ }
1601
+
1602
+ return false;
1603
+ },
1604
+
1605
+ delete: function(header, matcher) {
1606
+ const self = this;
1607
+ let deleted = false;
1608
+
1609
+ function deleteHeader(_header) {
1610
+ _header = normalizeHeader(_header);
1611
+
1612
+ if (_header) {
1613
+ const key = findKey(self, _header);
1614
+
1615
+ if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1616
+ delete self[key];
1617
+
1618
+ deleted = true;
1619
+ }
1620
+ }
1621
+ }
1622
+
1623
+ if (utils.isArray(header)) {
1624
+ header.forEach(deleteHeader);
1625
+ } else {
1626
+ deleteHeader(header);
1627
+ }
1628
+
1629
+ return deleted;
1630
+ },
1631
+
1632
+ clear: function() {
1633
+ return Object.keys(this).forEach(this.delete.bind(this));
1634
+ },
1635
+
1636
+ normalize: function(format) {
1637
+ const self = this;
1638
+ const headers = {};
1639
+
1640
+ utils.forEach(this, (value, header) => {
1641
+ const key = findKey(headers, header);
1642
+
1643
+ if (key) {
1644
+ self[key] = normalizeValue(value);
1645
+ delete self[header];
1646
+ return;
1647
+ }
1648
+
1649
+ const normalized = format ? formatHeader(header) : String(header).trim();
1650
+
1651
+ if (normalized !== header) {
1652
+ delete self[header];
1653
+ }
1654
+
1655
+ self[normalized] = normalizeValue(value);
1656
+
1657
+ headers[normalized] = true;
1658
+ });
1659
+
1660
+ return this;
1661
+ },
1662
+
1663
+ toJSON: function() {
1664
+ const obj = Object.create(null);
1665
+
1666
+ utils.forEach(Object.assign({}, this[$defaults] || null, this),
1667
+ (value, header) => {
1668
+ if (value == null || value === false) return;
1669
+ obj[header] = utils.isArray(value) ? value.join(', ') : value;
1670
+ });
1671
+
1672
+ return obj;
1673
+ }
1674
+ });
1675
+
1676
+ Object.assign(AxiosHeaders, {
1677
+ from: function(thing) {
1678
+ if (utils.isString(thing)) {
1679
+ return new this(parseHeaders(thing));
1680
+ }
1681
+ return thing instanceof this ? thing : new this(thing);
1682
+ },
1683
+
1684
+ accessor: function(header) {
1685
+ const internals = this[$internals] = (this[$internals] = {
1686
+ accessors: {}
1687
+ });
1688
+
1689
+ const accessors = internals.accessors;
1690
+ const prototype = this.prototype;
1691
+
1692
+ function defineAccessor(_header) {
1693
+ const lHeader = normalizeHeader(_header);
1694
+
1695
+ if (!accessors[lHeader]) {
1696
+ buildAccessors(prototype, _header);
1697
+ accessors[lHeader] = true;
1698
+ }
1699
+ }
1700
+
1701
+ utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
1702
+
1703
+ return this;
1704
+ }
1705
+ });
1706
+
1707
+ AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
1708
+
1709
+ utils.freezeMethods(AxiosHeaders.prototype);
1710
+ utils.freezeMethods(AxiosHeaders);
1711
+
1712
+ /**
1713
+ * Throttle decorator
1714
+ * @param {Function} fn
1715
+ * @param {Number} freq
1716
+ * @return {Function}
1717
+ */
1718
+ function throttle(fn, freq) {
1719
+ let timestamp = 0;
1720
+ const threshold = 1000 / freq;
1721
+ let timer = null;
1722
+ return function throttled(force, args) {
1723
+ const now = Date.now();
1724
+ if (force || now - timestamp > threshold) {
1725
+ if (timer) {
1726
+ clearTimeout(timer);
1727
+ timer = null;
1728
+ }
1729
+ timestamp = now;
1730
+ return fn.apply(null, args);
1731
+ }
1732
+ if (!timer) {
1733
+ timer = setTimeout(() => {
1734
+ timer = null;
1735
+ timestamp = Date.now();
1736
+ return fn.apply(null, args);
1737
+ }, threshold - (now - timestamp));
1738
+ }
1739
+ };
1740
+ }
1741
+
1742
+ /**
1743
+ * Calculate data maxRate
1744
+ * @param {Number} [samplesCount= 10]
1745
+ * @param {Number} [min= 1000]
1746
+ * @returns {Function}
1747
+ */
1748
+ function speedometer(samplesCount, min) {
1749
+ samplesCount = samplesCount || 10;
1750
+ const bytes = new Array(samplesCount);
1751
+ const timestamps = new Array(samplesCount);
1752
+ let head = 0;
1753
+ let tail = 0;
1754
+ let firstSampleTS;
1755
+
1756
+ min = min !== undefined ? min : 1000;
1757
+
1758
+ return function push(chunkLength) {
1759
+ const now = Date.now();
1760
+
1761
+ const startedAt = timestamps[tail];
1762
+
1763
+ if (!firstSampleTS) {
1764
+ firstSampleTS = now;
1765
+ }
1766
+
1767
+ bytes[head] = chunkLength;
1768
+ timestamps[head] = now;
1769
+
1770
+ let i = tail;
1771
+ let bytesCount = 0;
1772
+
1773
+ while (i !== head) {
1774
+ bytesCount += bytes[i++];
1775
+ i = i % samplesCount;
1776
+ }
1777
+
1778
+ head = (head + 1) % samplesCount;
1779
+
1780
+ if (head === tail) {
1781
+ tail = (tail + 1) % samplesCount;
1782
+ }
1783
+
1784
+ if (now - firstSampleTS < min) {
1785
+ return;
1786
+ }
1787
+
1788
+ const passed = startedAt && now - startedAt;
1789
+
1790
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
1791
+ };
1792
+ }
1793
+
1794
+ const kInternals = Symbol('internals');
1795
+
1796
+ class AxiosTransformStream extends stream__default["default"].Transform{
1797
+ constructor(options) {
1798
+ options = utils.toFlatObject(options, {
1799
+ maxRate: 0,
1800
+ chunkSize: 64 * 1024,
1801
+ minChunkSize: 100,
1802
+ timeWindow: 500,
1803
+ ticksRate: 2,
1804
+ samplesCount: 15
1805
+ }, null, (prop, source) => {
1806
+ return !utils.isUndefined(source[prop]);
1807
+ });
1808
+
1809
+ super({
1810
+ readableHighWaterMark: options.chunkSize
1811
+ });
1812
+
1813
+ const self = this;
1814
+
1815
+ const internals = this[kInternals] = {
1816
+ length: options.length,
1817
+ timeWindow: options.timeWindow,
1818
+ ticksRate: options.ticksRate,
1819
+ chunkSize: options.chunkSize,
1820
+ maxRate: options.maxRate,
1821
+ minChunkSize: options.minChunkSize,
1822
+ bytesSeen: 0,
1823
+ isCaptured: false,
1824
+ notifiedBytesLoaded: 0,
1825
+ ts: Date.now(),
1826
+ bytes: 0,
1827
+ onReadCallback: null
1828
+ };
1829
+
1830
+ const _speedometer = speedometer(internals.ticksRate * options.samplesCount, internals.timeWindow);
1831
+
1832
+ this.on('newListener', event => {
1833
+ if (event === 'progress') {
1834
+ if (!internals.isCaptured) {
1835
+ internals.isCaptured = true;
1836
+ }
1837
+ }
1838
+ });
1839
+
1840
+ let bytesNotified = 0;
1841
+
1842
+ internals.updateProgress = throttle(function throttledHandler() {
1843
+ const totalBytes = internals.length;
1844
+ const bytesTransferred = internals.bytesSeen;
1845
+ const progressBytes = bytesTransferred - bytesNotified;
1846
+ if (!progressBytes || self.destroyed) return;
1847
+
1848
+ const rate = _speedometer(progressBytes);
1849
+
1850
+ bytesNotified = bytesTransferred;
1851
+
1852
+ process.nextTick(() => {
1853
+ self.emit('progress', {
1854
+ 'loaded': bytesTransferred,
1855
+ 'total': totalBytes,
1856
+ 'progress': totalBytes ? (bytesTransferred / totalBytes) : undefined,
1857
+ 'bytes': progressBytes,
1858
+ 'rate': rate ? rate : undefined,
1859
+ 'estimated': rate && totalBytes && bytesTransferred <= totalBytes ?
1860
+ (totalBytes - bytesTransferred) / rate : undefined
1861
+ });
1862
+ });
1863
+ }, internals.ticksRate);
1864
+
1865
+ const onFinish = () => {
1866
+ internals.updateProgress(true);
1867
+ };
1868
+
1869
+ this.once('end', onFinish);
1870
+ this.once('error', onFinish);
1871
+ }
1872
+
1873
+ _read(size) {
1874
+ const internals = this[kInternals];
1875
+
1876
+ if (internals.onReadCallback) {
1877
+ internals.onReadCallback();
1878
+ }
1879
+
1880
+ return super._read(size);
1881
+ }
1882
+
1883
+ _transform(chunk, encoding, callback) {
1884
+ const self = this;
1885
+ const internals = this[kInternals];
1886
+ const maxRate = internals.maxRate;
1887
+
1888
+ const readableHighWaterMark = this.readableHighWaterMark;
1889
+
1890
+ const timeWindow = internals.timeWindow;
1891
+
1892
+ const divider = 1000 / timeWindow;
1893
+ const bytesThreshold = (maxRate / divider);
1894
+ const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
1895
+
1896
+ function pushChunk(_chunk, _callback) {
1897
+ const bytes = Buffer.byteLength(_chunk);
1898
+ internals.bytesSeen += bytes;
1899
+ internals.bytes += bytes;
1900
+
1901
+ if (internals.isCaptured) {
1902
+ internals.updateProgress();
1903
+ }
1904
+
1905
+ if (self.push(_chunk)) {
1906
+ process.nextTick(_callback);
1907
+ } else {
1908
+ internals.onReadCallback = () => {
1909
+ internals.onReadCallback = null;
1910
+ process.nextTick(_callback);
1911
+ };
1912
+ }
1913
+ }
1914
+
1915
+ const transformChunk = (_chunk, _callback) => {
1916
+ const chunkSize = Buffer.byteLength(_chunk);
1917
+ let chunkRemainder = null;
1918
+ let maxChunkSize = readableHighWaterMark;
1919
+ let bytesLeft;
1920
+ let passed = 0;
1921
+
1922
+ if (maxRate) {
1923
+ const now = Date.now();
1924
+
1925
+ if (!internals.ts || (passed = (now - internals.ts)) >= timeWindow) {
1926
+ internals.ts = now;
1927
+ bytesLeft = bytesThreshold - internals.bytes;
1928
+ internals.bytes = bytesLeft < 0 ? -bytesLeft : 0;
1929
+ passed = 0;
1930
+ }
1931
+
1932
+ bytesLeft = bytesThreshold - internals.bytes;
1933
+ }
1934
+
1935
+ if (maxRate) {
1936
+ if (bytesLeft <= 0) {
1937
+ // next time window
1938
+ return setTimeout(() => {
1939
+ _callback(null, _chunk);
1940
+ }, timeWindow - passed);
1941
+ }
1942
+
1943
+ if (bytesLeft < maxChunkSize) {
1944
+ maxChunkSize = bytesLeft;
1945
+ }
1946
+ }
1947
+
1948
+ if (maxChunkSize && chunkSize > maxChunkSize && (chunkSize - maxChunkSize) > minChunkSize) {
1949
+ chunkRemainder = _chunk.subarray(maxChunkSize);
1950
+ _chunk = _chunk.subarray(0, maxChunkSize);
1951
+ }
1952
+
1953
+ pushChunk(_chunk, chunkRemainder ? () => {
1954
+ process.nextTick(_callback, null, chunkRemainder);
1955
+ } : _callback);
1956
+ };
1957
+
1958
+ transformChunk(chunk, function transformNextChunk(err, _chunk) {
1959
+ if (err) {
1960
+ return callback(err);
1961
+ }
1962
+
1963
+ if (_chunk) {
1964
+ transformChunk(_chunk, transformNextChunk);
1965
+ } else {
1966
+ callback(null);
1967
+ }
1968
+ });
1969
+ }
1970
+
1971
+ setLength(length) {
1972
+ this[kInternals].length = +length;
1973
+ return this;
1974
+ }
1975
+ }
1976
+
1977
+ const isBrotliSupported = utils.isFunction(zlib__default["default"].createBrotliDecompress);
1978
+
1979
+ const {http: httpFollow, https: httpsFollow} = followRedirects__default["default"];
1980
+
1981
+ const isHttps = /https:?/;
1982
+
1983
+ const supportedProtocols = platform.protocols.map(protocol => {
1984
+ return protocol + ':';
1985
+ });
1986
+
1987
+ /**
1988
+ * If the proxy or config beforeRedirects functions are defined, call them with the options
1989
+ * object.
1990
+ *
1991
+ * @param {Object<string, any>} options - The options object that was passed to the request.
1992
+ *
1993
+ * @returns {Object<string, any>}
1994
+ */
1995
+ function dispatchBeforeRedirect(options) {
1996
+ if (options.beforeRedirects.proxy) {
1997
+ options.beforeRedirects.proxy(options);
1998
+ }
1999
+ if (options.beforeRedirects.config) {
2000
+ options.beforeRedirects.config(options);
2001
+ }
2002
+ }
2003
+
2004
+ /**
2005
+ * If the proxy or config afterRedirects functions are defined, call them with the options
2006
+ *
2007
+ * @param {http.ClientRequestArgs} options
2008
+ * @param {AxiosProxyConfig} configProxy
2009
+ * @param {string} location
2010
+ *
2011
+ * @returns {http.ClientRequestArgs}
2012
+ */
2013
+ function setProxy(options, configProxy, location) {
2014
+ let proxy = configProxy;
2015
+ if (!proxy && proxy !== false) {
2016
+ const proxyUrl = proxyFromEnv.getProxyForUrl(location);
2017
+ if (proxyUrl) {
2018
+ proxy = new URL(proxyUrl);
2019
+ }
2020
+ }
2021
+ if (proxy) {
2022
+ // Basic proxy authorization
2023
+ if (proxy.username) {
2024
+ proxy.auth = (proxy.username || '') + ':' + (proxy.password || '');
2025
+ }
2026
+
2027
+ if (proxy.auth) {
2028
+ // Support proxy auth object form
2029
+ if (proxy.auth.username || proxy.auth.password) {
2030
+ proxy.auth = (proxy.auth.username || '') + ':' + (proxy.auth.password || '');
2031
+ }
2032
+ const base64 = Buffer
2033
+ .from(proxy.auth, 'utf8')
2034
+ .toString('base64');
2035
+ options.headers['Proxy-Authorization'] = 'Basic ' + base64;
2036
+ }
2037
+
2038
+ options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
2039
+ options.hostname = proxy.hostname;
2040
+ // Replace 'host' since options is not a URL object
2041
+ options.host = proxy.hostname;
2042
+ options.port = proxy.port;
2043
+ options.path = location;
2044
+ if (proxy.protocol) {
2045
+ options.protocol = proxy.protocol;
2046
+ }
2047
+ }
2048
+
2049
+ options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
2050
+ // Configure proxy for redirected request, passing the original config proxy to apply
2051
+ // the exact same logic as if the redirected request was performed by axios directly.
2052
+ setProxy(redirectOptions, configProxy, redirectOptions.href);
2053
+ };
2054
+ }
2055
+
2056
+ /*eslint consistent-return:0*/
2057
+ function httpAdapter(config) {
2058
+ return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
2059
+ let data = config.data;
2060
+ const responseType = config.responseType;
2061
+ const responseEncoding = config.responseEncoding;
2062
+ const method = config.method.toUpperCase();
2063
+ let isFinished;
2064
+ let isDone;
2065
+ let rejected = false;
2066
+ let req;
2067
+
2068
+ // temporary internal emitter until the AxiosRequest class will be implemented
2069
+ const emitter = new EventEmitter__default["default"]();
2070
+
2071
+ function onFinished() {
2072
+ if (isFinished) return;
2073
+ isFinished = true;
2074
+
2075
+ if (config.cancelToken) {
2076
+ config.cancelToken.unsubscribe(abort);
2077
+ }
2078
+
2079
+ if (config.signal) {
2080
+ config.signal.removeEventListener('abort', abort);
2081
+ }
2082
+
2083
+ emitter.removeAllListeners();
2084
+ }
2085
+
2086
+ function done(value, isRejected) {
2087
+ if (isDone) return;
2088
+
2089
+ isDone = true;
2090
+
2091
+ if (isRejected) {
2092
+ rejected = true;
2093
+ onFinished();
2094
+ }
2095
+
2096
+ isRejected ? rejectPromise(value) : resolvePromise(value);
2097
+ }
2098
+
2099
+ const resolve = function resolve(value) {
2100
+ done(value);
2101
+ };
2102
+
2103
+ const reject = function reject(value) {
2104
+ done(value, true);
2105
+ };
2106
+
2107
+ function abort(reason) {
2108
+ emitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
2109
+ }
2110
+
2111
+ emitter.once('abort', reject);
2112
+
2113
+ if (config.cancelToken || config.signal) {
2114
+ config.cancelToken && config.cancelToken.subscribe(abort);
2115
+ if (config.signal) {
2116
+ config.signal.aborted ? abort() : config.signal.addEventListener('abort', abort);
2117
+ }
2118
+ }
2119
+
2120
+ // Parse url
2121
+ const fullPath = buildFullPath(config.baseURL, config.url);
2122
+ const parsed = new URL(fullPath);
2123
+ const protocol = parsed.protocol || supportedProtocols[0];
2124
+
2125
+ if (protocol === 'data:') {
2126
+ let convertedData;
2127
+
2128
+ if (method !== 'GET') {
2129
+ return settle(resolve, reject, {
2130
+ status: 405,
2131
+ statusText: 'method not allowed',
2132
+ headers: {},
2133
+ config
2134
+ });
2135
+ }
2136
+
2137
+ try {
2138
+ convertedData = fromDataURI(config.url, responseType === 'blob', {
2139
+ Blob: config.env && config.env.Blob
2140
+ });
2141
+ } catch (err) {
2142
+ throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
2143
+ }
2144
+
2145
+ if (responseType === 'text') {
2146
+ convertedData = convertedData.toString(responseEncoding);
2147
+
2148
+ if (!responseEncoding || responseEncoding === 'utf8') {
2149
+ data = utils.stripBOM(convertedData);
2150
+ }
2151
+ } else if (responseType === 'stream') {
2152
+ convertedData = stream__default["default"].Readable.from(convertedData);
2153
+ }
2154
+
2155
+ return settle(resolve, reject, {
2156
+ data: convertedData,
2157
+ status: 200,
2158
+ statusText: 'OK',
2159
+ headers: {},
2160
+ config
2161
+ });
2162
+ }
2163
+
2164
+ if (supportedProtocols.indexOf(protocol) === -1) {
2165
+ return reject(new AxiosError(
2166
+ 'Unsupported protocol ' + protocol,
2167
+ AxiosError.ERR_BAD_REQUEST,
2168
+ config
2169
+ ));
2170
+ }
2171
+
2172
+ const headers = AxiosHeaders.from(config.headers).normalize();
2173
+
2174
+ // Set User-Agent (required by some servers)
2175
+ // See https://github.com/axios/axios/issues/69
2176
+ // User-Agent is specified; handle case where no UA header is desired
2177
+ // Only set header if it hasn't been set in config
2178
+ headers.set('User-Agent', 'axios/' + VERSION, false);
2179
+
2180
+ const onDownloadProgress = config.onDownloadProgress;
2181
+ const onUploadProgress = config.onUploadProgress;
2182
+ const maxRate = config.maxRate;
2183
+ let maxUploadRate = undefined;
2184
+ let maxDownloadRate = undefined;
2185
+
2186
+ // support for https://www.npmjs.com/package/form-data api
2187
+ if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
2188
+ headers.set(data.getHeaders());
2189
+ } else if (data && !utils.isStream(data)) {
2190
+ if (Buffer.isBuffer(data)) ; else if (utils.isArrayBuffer(data)) {
2191
+ data = Buffer.from(new Uint8Array(data));
2192
+ } else if (utils.isString(data)) {
2193
+ data = Buffer.from(data, 'utf-8');
2194
+ } else {
2195
+ return reject(new AxiosError(
2196
+ 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
2197
+ AxiosError.ERR_BAD_REQUEST,
2198
+ config
2199
+ ));
2200
+ }
2201
+
2202
+ // Add Content-Length header if data exists
2203
+ headers.set('Content-Length', data.length, false);
2204
+
2205
+ if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
2206
+ return reject(new AxiosError(
2207
+ 'Request body larger than maxBodyLength limit',
2208
+ AxiosError.ERR_BAD_REQUEST,
2209
+ config
2210
+ ));
2211
+ }
2212
+ }
2213
+
2214
+ const contentLength = +headers.getContentLength();
2215
+
2216
+ if (utils.isArray(maxRate)) {
2217
+ maxUploadRate = maxRate[0];
2218
+ maxDownloadRate = maxRate[1];
2219
+ } else {
2220
+ maxUploadRate = maxDownloadRate = maxRate;
2221
+ }
2222
+
2223
+ if (data && (onUploadProgress || maxUploadRate)) {
2224
+ if (!utils.isStream(data)) {
2225
+ data = stream__default["default"].Readable.from(data, {objectMode: false});
2226
+ }
2227
+
2228
+ data = stream__default["default"].pipeline([data, new AxiosTransformStream({
2229
+ length: utils.toFiniteNumber(contentLength),
2230
+ maxRate: utils.toFiniteNumber(maxUploadRate)
2231
+ })], utils.noop);
2232
+
2233
+ onUploadProgress && data.on('progress', progress => {
2234
+ onUploadProgress(Object.assign(progress, {
2235
+ upload: true
2236
+ }));
2237
+ });
2238
+ }
2239
+
2240
+ // HTTP basic authentication
2241
+ let auth = undefined;
2242
+ if (config.auth) {
2243
+ const username = config.auth.username || '';
2244
+ const password = config.auth.password || '';
2245
+ auth = username + ':' + password;
2246
+ }
2247
+
2248
+ if (!auth && parsed.username) {
2249
+ const urlUsername = parsed.username;
2250
+ const urlPassword = parsed.password;
2251
+ auth = urlUsername + ':' + urlPassword;
2252
+ }
2253
+
2254
+ auth && headers.delete('authorization');
2255
+
2256
+ let path;
2257
+
2258
+ try {
2259
+ path = buildURL(
2260
+ parsed.pathname + parsed.search,
2261
+ config.params,
2262
+ config.paramsSerializer
2263
+ ).replace(/^\?/, '');
2264
+ } catch (err) {
2265
+ const customErr = new Error(err.message);
2266
+ customErr.config = config;
2267
+ customErr.url = config.url;
2268
+ customErr.exists = true;
2269
+ return reject(customErr);
2270
+ }
2271
+
2272
+ headers.set('Accept-Encoding', 'gzip, deflate, br', false);
2273
+
2274
+ const options = {
2275
+ path,
2276
+ method: method,
2277
+ headers: headers.toJSON(),
2278
+ agents: { http: config.httpAgent, https: config.httpsAgent },
2279
+ auth,
2280
+ protocol,
2281
+ beforeRedirect: dispatchBeforeRedirect,
2282
+ beforeRedirects: {}
2283
+ };
2284
+
2285
+ if (config.socketPath) {
2286
+ options.socketPath = config.socketPath;
2287
+ } else {
2288
+ options.hostname = parsed.hostname;
2289
+ options.port = parsed.port;
2290
+ setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
2291
+ }
2292
+
2293
+ let transport;
2294
+ const isHttpsRequest = isHttps.test(options.protocol);
2295
+ options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
2296
+ if (config.transport) {
2297
+ transport = config.transport;
2298
+ } else if (config.maxRedirects === 0) {
2299
+ transport = isHttpsRequest ? https__default["default"] : http__default["default"];
2300
+ } else {
2301
+ if (config.maxRedirects) {
2302
+ options.maxRedirects = config.maxRedirects;
2303
+ }
2304
+ if (config.beforeRedirect) {
2305
+ options.beforeRedirects.config = config.beforeRedirect;
2306
+ }
2307
+ transport = isHttpsRequest ? httpsFollow : httpFollow;
2308
+ }
2309
+
2310
+ if (config.maxBodyLength > -1) {
2311
+ options.maxBodyLength = config.maxBodyLength;
2312
+ } else {
2313
+ // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
2314
+ options.maxBodyLength = Infinity;
2315
+ }
2316
+
2317
+ if (config.insecureHTTPParser) {
2318
+ options.insecureHTTPParser = config.insecureHTTPParser;
2319
+ }
2320
+
2321
+ // Create the request
2322
+ req = transport.request(options, function handleResponse(res) {
2323
+ if (req.destroyed) return;
2324
+
2325
+ const streams = [res];
2326
+
2327
+ // uncompress the response body transparently if required
2328
+ let responseStream = res;
2329
+
2330
+ // return the last request in case of redirects
2331
+ const lastRequest = res.req || req;
2332
+
2333
+ // if decompress disabled we should not decompress
2334
+ if (config.decompress !== false) {
2335
+ // if no content, but headers still say that it is encoded,
2336
+ // remove the header not confuse downstream operations
2337
+ if (data && data.length === 0 && res.headers['content-encoding']) {
2338
+ delete res.headers['content-encoding'];
2339
+ }
2340
+
2341
+ switch (res.headers['content-encoding']) {
2342
+ /*eslint default-case:0*/
2343
+ case 'gzip':
2344
+ case 'compress':
2345
+ case 'deflate':
2346
+ // add the unzipper to the body stream processing pipeline
2347
+ streams.push(zlib__default["default"].createUnzip());
2348
+
2349
+ // remove the content-encoding in order to not confuse downstream operations
2350
+ delete res.headers['content-encoding'];
2351
+ break;
2352
+ case 'br':
2353
+ if (isBrotliSupported) {
2354
+ streams.push(zlib__default["default"].createBrotliDecompress());
2355
+ delete res.headers['content-encoding'];
2356
+ }
2357
+ }
2358
+ }
2359
+
2360
+ if (onDownloadProgress) {
2361
+ const responseLength = +res.headers['content-length'];
2362
+
2363
+ const transformStream = new AxiosTransformStream({
2364
+ length: utils.toFiniteNumber(responseLength),
2365
+ maxRate: utils.toFiniteNumber(maxDownloadRate)
2366
+ });
2367
+
2368
+ onDownloadProgress && transformStream.on('progress', progress => {
2369
+ onDownloadProgress(Object.assign(progress, {
2370
+ download: true
2371
+ }));
2372
+ });
2373
+
2374
+ streams.push(transformStream);
2375
+ }
2376
+
2377
+ responseStream = streams.length > 1 ? stream__default["default"].pipeline(streams, utils.noop) : streams[0];
2378
+
2379
+ const offListeners = stream__default["default"].finished(responseStream, () => {
2380
+ offListeners();
2381
+ onFinished();
2382
+ });
2383
+
2384
+ const response = {
2385
+ status: res.statusCode,
2386
+ statusText: res.statusMessage,
2387
+ headers: new AxiosHeaders(res.headers),
2388
+ config,
2389
+ request: lastRequest
2390
+ };
2391
+
2392
+ if (responseType === 'stream') {
2393
+ response.data = responseStream;
2394
+ settle(resolve, reject, response);
2395
+ } else {
2396
+ const responseBuffer = [];
2397
+ let totalResponseBytes = 0;
2398
+
2399
+ responseStream.on('data', function handleStreamData(chunk) {
2400
+ responseBuffer.push(chunk);
2401
+ totalResponseBytes += chunk.length;
2402
+
2403
+ // make sure the content length is not over the maxContentLength if specified
2404
+ if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
2405
+ // stream.destroy() emit aborted event before calling reject() on Node.js v16
2406
+ rejected = true;
2407
+ responseStream.destroy();
2408
+ reject(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
2409
+ AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
2410
+ }
2411
+ });
2412
+
2413
+ responseStream.on('aborted', function handlerStreamAborted() {
2414
+ if (rejected) {
2415
+ return;
2416
+ }
2417
+
2418
+ const err = new AxiosError(
2419
+ 'maxContentLength size of ' + config.maxContentLength + ' exceeded',
2420
+ AxiosError.ERR_BAD_RESPONSE,
2421
+ config,
2422
+ lastRequest
2423
+ );
2424
+ responseStream.destroy(err);
2425
+ reject(err);
2426
+ });
2427
+
2428
+ responseStream.on('error', function handleStreamError(err) {
2429
+ if (req.destroyed) return;
2430
+ reject(AxiosError.from(err, null, config, lastRequest));
2431
+ });
2432
+
2433
+ responseStream.on('end', function handleStreamEnd() {
2434
+ try {
2435
+ let responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
2436
+ if (responseType !== 'arraybuffer') {
2437
+ responseData = responseData.toString(responseEncoding);
2438
+ if (!responseEncoding || responseEncoding === 'utf8') {
2439
+ responseData = utils.stripBOM(responseData);
2440
+ }
2441
+ }
2442
+ response.data = responseData;
2443
+ } catch (err) {
2444
+ reject(AxiosError.from(err, null, config, response.request, response));
2445
+ }
2446
+ settle(resolve, reject, response);
2447
+ });
2448
+ }
2449
+
2450
+ emitter.once('abort', err => {
2451
+ if (!responseStream.destroyed) {
2452
+ responseStream.emit('error', err);
2453
+ responseStream.destroy();
2454
+ }
2455
+ });
2456
+ });
2457
+
2458
+ emitter.once('abort', err => {
2459
+ reject(err);
2460
+ req.destroy(err);
2461
+ });
2462
+
2463
+ // Handle errors
2464
+ req.on('error', function handleRequestError(err) {
2465
+ // @todo remove
2466
+ // if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
2467
+ reject(AxiosError.from(err, null, config, req));
2468
+ });
2469
+
2470
+ // set tcp keep alive to prevent drop connection by peer
2471
+ req.on('socket', function handleRequestSocket(socket) {
2472
+ // default interval of sending ack packet is 1 minute
2473
+ socket.setKeepAlive(true, 1000 * 60);
2474
+ });
2475
+
2476
+ // Handle request timeout
2477
+ if (config.timeout) {
2478
+ // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
2479
+ const timeout = parseInt(config.timeout, 10);
2480
+
2481
+ if (isNaN(timeout)) {
2482
+ reject(new AxiosError(
2483
+ 'error trying to parse `config.timeout` to int',
2484
+ AxiosError.ERR_BAD_OPTION_VALUE,
2485
+ config,
2486
+ req
2487
+ ));
2488
+
2489
+ return;
2490
+ }
2491
+
2492
+ // Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
2493
+ // And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
2494
+ // At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
2495
+ // And then these socket which be hang up will devouring CPU little by little.
2496
+ // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
2497
+ req.setTimeout(timeout, function handleRequestTimeout() {
2498
+ if (isDone) return;
2499
+ let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
2500
+ const transitional = config.transitional || transitionalDefaults;
2501
+ if (config.timeoutErrorMessage) {
2502
+ timeoutErrorMessage = config.timeoutErrorMessage;
2503
+ }
2504
+ reject(new AxiosError(
2505
+ timeoutErrorMessage,
2506
+ transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
2507
+ config,
2508
+ req
2509
+ ));
2510
+ abort();
2511
+ });
2512
+ }
2513
+
2514
+
2515
+ // Send the request
2516
+ if (utils.isStream(data)) {
2517
+ let ended = false;
2518
+ let errored = false;
2519
+
2520
+ data.on('end', () => {
2521
+ ended = true;
2522
+ });
2523
+
2524
+ data.once('error', err => {
2525
+ errored = true;
2526
+ req.destroy(err);
2527
+ });
2528
+
2529
+ data.on('close', () => {
2530
+ if (!ended && !errored) {
2531
+ abort(new CanceledError('Request stream has been aborted', config, req));
2532
+ }
2533
+ });
2534
+
2535
+ data.pipe(req);
2536
+ } else {
2537
+ req.end(data);
2538
+ }
2539
+ });
2540
+ }
2541
+
2542
+ const cookies = platform.isStandardBrowserEnv ?
2543
+
2544
+ // Standard browser envs support document.cookie
2545
+ (function standardBrowserEnv() {
2546
+ return {
2547
+ write: function write(name, value, expires, path, domain, secure) {
2548
+ const cookie = [];
2549
+ cookie.push(name + '=' + encodeURIComponent(value));
2550
+
2551
+ if (utils.isNumber(expires)) {
2552
+ cookie.push('expires=' + new Date(expires).toGMTString());
2553
+ }
2554
+
2555
+ if (utils.isString(path)) {
2556
+ cookie.push('path=' + path);
2557
+ }
2558
+
2559
+ if (utils.isString(domain)) {
2560
+ cookie.push('domain=' + domain);
2561
+ }
2562
+
2563
+ if (secure === true) {
2564
+ cookie.push('secure');
2565
+ }
2566
+
2567
+ document.cookie = cookie.join('; ');
2568
+ },
2569
+
2570
+ read: function read(name) {
2571
+ const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2572
+ return (match ? decodeURIComponent(match[3]) : null);
2573
+ },
2574
+
2575
+ remove: function remove(name) {
2576
+ this.write(name, '', Date.now() - 86400000);
2577
+ }
2578
+ };
2579
+ })() :
2580
+
2581
+ // Non standard browser env (web workers, react-native) lack needed support.
2582
+ (function nonStandardBrowserEnv() {
2583
+ return {
2584
+ write: function write() {},
2585
+ read: function read() { return null; },
2586
+ remove: function remove() {}
2587
+ };
2588
+ })();
2589
+
2590
+ const isURLSameOrigin = platform.isStandardBrowserEnv ?
2591
+
2592
+ // Standard browser envs have full support of the APIs needed to test
2593
+ // whether the request URL is of the same origin as current location.
2594
+ (function standardBrowserEnv() {
2595
+ const msie = /(msie|trident)/i.test(navigator.userAgent);
2596
+ const urlParsingNode = document.createElement('a');
2597
+ let originURL;
2598
+
2599
+ /**
2600
+ * Parse a URL to discover it's components
2601
+ *
2602
+ * @param {String} url The URL to be parsed
2603
+ * @returns {Object}
2604
+ */
2605
+ function resolveURL(url) {
2606
+ let href = url;
2607
+
2608
+ if (msie) {
2609
+ // IE needs attribute set twice to normalize properties
2610
+ urlParsingNode.setAttribute('href', href);
2611
+ href = urlParsingNode.href;
2612
+ }
2613
+
2614
+ urlParsingNode.setAttribute('href', href);
2615
+
2616
+ // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2617
+ return {
2618
+ href: urlParsingNode.href,
2619
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2620
+ host: urlParsingNode.host,
2621
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2622
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2623
+ hostname: urlParsingNode.hostname,
2624
+ port: urlParsingNode.port,
2625
+ pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
2626
+ urlParsingNode.pathname :
2627
+ '/' + urlParsingNode.pathname
2628
+ };
2629
+ }
2630
+
2631
+ originURL = resolveURL(window.location.href);
2632
+
2633
+ /**
2634
+ * Determine if a URL shares the same origin as the current location
2635
+ *
2636
+ * @param {String} requestURL The URL to test
2637
+ * @returns {boolean} True if URL shares the same origin, otherwise false
2638
+ */
2639
+ return function isURLSameOrigin(requestURL) {
2640
+ const parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2641
+ return (parsed.protocol === originURL.protocol &&
2642
+ parsed.host === originURL.host);
2643
+ };
2644
+ })() :
2645
+
2646
+ // Non standard browser envs (web workers, react-native) lack needed support.
2647
+ (function nonStandardBrowserEnv() {
2648
+ return function isURLSameOrigin() {
2649
+ return true;
2650
+ };
2651
+ })();
2652
+
2653
+ function progressEventReducer(listener, isDownloadStream) {
2654
+ let bytesNotified = 0;
2655
+ const _speedometer = speedometer(50, 250);
2656
+
2657
+ return e => {
2658
+ const loaded = e.loaded;
2659
+ const total = e.lengthComputable ? e.total : undefined;
2660
+ const progressBytes = loaded - bytesNotified;
2661
+ const rate = _speedometer(progressBytes);
2662
+ const inRange = loaded <= total;
2663
+
2664
+ bytesNotified = loaded;
2665
+
2666
+ const data = {
2667
+ loaded,
2668
+ total,
2669
+ progress: total ? (loaded / total) : undefined,
2670
+ bytes: progressBytes,
2671
+ rate: rate ? rate : undefined,
2672
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined
2673
+ };
2674
+
2675
+ data[isDownloadStream ? 'download' : 'upload'] = true;
2676
+
2677
+ listener(data);
2678
+ };
2679
+ }
2680
+
2681
+ function xhrAdapter(config) {
2682
+ return new Promise(function dispatchXhrRequest(resolve, reject) {
2683
+ let requestData = config.data;
2684
+ const requestHeaders = AxiosHeaders.from(config.headers).normalize();
2685
+ const responseType = config.responseType;
2686
+ let onCanceled;
2687
+ function done() {
2688
+ if (config.cancelToken) {
2689
+ config.cancelToken.unsubscribe(onCanceled);
2690
+ }
2691
+
2692
+ if (config.signal) {
2693
+ config.signal.removeEventListener('abort', onCanceled);
2694
+ }
2695
+ }
2696
+
2697
+ if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
2698
+ requestHeaders.setContentType(false); // Let the browser set it
2699
+ }
2700
+
2701
+ let request = new XMLHttpRequest();
2702
+
2703
+ // HTTP basic authentication
2704
+ if (config.auth) {
2705
+ const username = config.auth.username || '';
2706
+ const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
2707
+ requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
2708
+ }
2709
+
2710
+ const fullPath = buildFullPath(config.baseURL, config.url);
2711
+
2712
+ request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
2713
+
2714
+ // Set the request timeout in MS
2715
+ request.timeout = config.timeout;
2716
+
2717
+ function onloadend() {
2718
+ if (!request) {
2719
+ return;
2720
+ }
2721
+ // Prepare the response
2722
+ const responseHeaders = AxiosHeaders.from(
2723
+ 'getAllResponseHeaders' in request && request.getAllResponseHeaders()
2724
+ );
2725
+ const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
2726
+ request.responseText : request.response;
2727
+ const response = {
2728
+ data: responseData,
2729
+ status: request.status,
2730
+ statusText: request.statusText,
2731
+ headers: responseHeaders,
2732
+ config,
2733
+ request
2734
+ };
2735
+
2736
+ settle(function _resolve(value) {
2737
+ resolve(value);
2738
+ done();
2739
+ }, function _reject(err) {
2740
+ reject(err);
2741
+ done();
2742
+ }, response);
2743
+
2744
+ // Clean up request
2745
+ request = null;
2746
+ }
2747
+
2748
+ if ('onloadend' in request) {
2749
+ // Use onloadend if available
2750
+ request.onloadend = onloadend;
2751
+ } else {
2752
+ // Listen for ready state to emulate onloadend
2753
+ request.onreadystatechange = function handleLoad() {
2754
+ if (!request || request.readyState !== 4) {
2755
+ return;
2756
+ }
2757
+
2758
+ // The request errored out and we didn't get a response, this will be
2759
+ // handled by onerror instead
2760
+ // With one exception: request that using file: protocol, most browsers
2761
+ // will return status as 0 even though it's a successful request
2762
+ if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
2763
+ return;
2764
+ }
2765
+ // readystate handler is calling before onerror or ontimeout handlers,
2766
+ // so we should call onloadend on the next 'tick'
2767
+ setTimeout(onloadend);
2768
+ };
2769
+ }
2770
+
2771
+ // Handle browser request cancellation (as opposed to a manual cancellation)
2772
+ request.onabort = function handleAbort() {
2773
+ if (!request) {
2774
+ return;
2775
+ }
2776
+
2777
+ reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
2778
+
2779
+ // Clean up request
2780
+ request = null;
2781
+ };
2782
+
2783
+ // Handle low level network errors
2784
+ request.onerror = function handleError() {
2785
+ // Real errors are hidden from us by the browser
2786
+ // onerror should only fire if it's a network error
2787
+ reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
2788
+
2789
+ // Clean up request
2790
+ request = null;
2791
+ };
2792
+
2793
+ // Handle timeout
2794
+ request.ontimeout = function handleTimeout() {
2795
+ let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
2796
+ const transitional = config.transitional || transitionalDefaults;
2797
+ if (config.timeoutErrorMessage) {
2798
+ timeoutErrorMessage = config.timeoutErrorMessage;
2799
+ }
2800
+ reject(new AxiosError(
2801
+ timeoutErrorMessage,
2802
+ transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
2803
+ config,
2804
+ request));
2805
+
2806
+ // Clean up request
2807
+ request = null;
2808
+ };
2809
+
2810
+ // Add xsrf header
2811
+ // This is only done if running in a standard browser environment.
2812
+ // Specifically not if we're in a web worker, or react-native.
2813
+ if (platform.isStandardBrowserEnv) {
2814
+ // Add xsrf header
2815
+ const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
2816
+ && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2817
+
2818
+ if (xsrfValue) {
2819
+ requestHeaders.set(config.xsrfHeaderName, xsrfValue);
2820
+ }
2821
+ }
2822
+
2823
+ // Remove Content-Type if data is undefined
2824
+ requestData === undefined && requestHeaders.setContentType(null);
2825
+
2826
+ // Add headers to the request
2827
+ if ('setRequestHeader' in request) {
2828
+ utils.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
2829
+ request.setRequestHeader(key, val);
2830
+ });
2831
+ }
2832
+
2833
+ // Add withCredentials to request if needed
2834
+ if (!utils.isUndefined(config.withCredentials)) {
2835
+ request.withCredentials = !!config.withCredentials;
2836
+ }
2837
+
2838
+ // Add responseType to request if needed
2839
+ if (responseType && responseType !== 'json') {
2840
+ request.responseType = config.responseType;
2841
+ }
2842
+
2843
+ // Handle progress if needed
2844
+ if (typeof config.onDownloadProgress === 'function') {
2845
+ request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
2846
+ }
2847
+
2848
+ // Not all browsers support upload events
2849
+ if (typeof config.onUploadProgress === 'function' && request.upload) {
2850
+ request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
2851
+ }
2852
+
2853
+ if (config.cancelToken || config.signal) {
2854
+ // Handle cancellation
2855
+ // eslint-disable-next-line func-names
2856
+ onCanceled = cancel => {
2857
+ if (!request) {
2858
+ return;
2859
+ }
2860
+ reject(!cancel || cancel.type ? new CanceledError(null, config, request) : cancel);
2861
+ request.abort();
2862
+ request = null;
2863
+ };
2864
+
2865
+ config.cancelToken && config.cancelToken.subscribe(onCanceled);
2866
+ if (config.signal) {
2867
+ config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
2868
+ }
2869
+ }
2870
+
2871
+ const protocol = parseProtocol(fullPath);
2872
+
2873
+ if (protocol && platform.protocols.indexOf(protocol) === -1) {
2874
+ reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
2875
+ return;
2876
+ }
2877
+
2878
+
2879
+ // Send the request
2880
+ request.send(requestData || null);
2881
+ });
2882
+ }
2883
+
2884
+ const adapters = {
2885
+ http: httpAdapter,
2886
+ xhr: xhrAdapter
2887
+ };
2888
+
2889
+ const adapters$1 = {
2890
+ getAdapter: (nameOrAdapter) => {
2891
+ if(utils.isString(nameOrAdapter)){
2892
+ const adapter = adapters[nameOrAdapter];
2893
+
2894
+ if (!nameOrAdapter) {
2895
+ throw Error(
2896
+ utils.hasOwnProp(nameOrAdapter) ?
2897
+ `Adapter '${nameOrAdapter}' is not available in the build` :
2898
+ `Can not resolve adapter '${nameOrAdapter}'`
2899
+ );
2900
+ }
2901
+
2902
+ return adapter
2903
+ }
2904
+
2905
+ if (!utils.isFunction(nameOrAdapter)) {
2906
+ throw new TypeError('adapter is not a function');
2907
+ }
2908
+
2909
+ return nameOrAdapter;
2910
+ },
2911
+ adapters
2912
+ };
2913
+
2914
+ const DEFAULT_CONTENT_TYPE = {
2915
+ 'Content-Type': 'application/x-www-form-urlencoded'
2916
+ };
2917
+
2918
+ /**
2919
+ * If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
2920
+ * adapter
2921
+ *
2922
+ * @returns {Function}
2923
+ */
2924
+ function getDefaultAdapter() {
2925
+ let adapter;
2926
+ if (typeof XMLHttpRequest !== 'undefined') {
2927
+ // For browsers use XHR adapter
2928
+ adapter = adapters$1.getAdapter('xhr');
2929
+ } else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
2930
+ // For node use HTTP adapter
2931
+ adapter = adapters$1.getAdapter('http');
2932
+ }
2933
+ return adapter;
2934
+ }
2935
+
2936
+ /**
2937
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
2938
+ * of the input
2939
+ *
2940
+ * @param {any} rawValue - The value to be stringified.
2941
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
2942
+ * @param {Function} encoder - A function that takes a value and returns a string.
2943
+ *
2944
+ * @returns {string} A stringified version of the rawValue.
2945
+ */
2946
+ function stringifySafely(rawValue, parser, encoder) {
2947
+ if (utils.isString(rawValue)) {
2948
+ try {
2949
+ (parser || JSON.parse)(rawValue);
2950
+ return utils.trim(rawValue);
2951
+ } catch (e) {
2952
+ if (e.name !== 'SyntaxError') {
2953
+ throw e;
2954
+ }
2955
+ }
2956
+ }
2957
+
2958
+ return (encoder || JSON.stringify)(rawValue);
2959
+ }
2960
+
2961
+ const defaults = {
2962
+
2963
+ transitional: transitionalDefaults,
2964
+
2965
+ adapter: getDefaultAdapter(),
2966
+
2967
+ transformRequest: [function transformRequest(data, headers) {
2968
+ const contentType = headers.getContentType() || '';
2969
+ const hasJSONContentType = contentType.indexOf('application/json') > -1;
2970
+ const isObjectPayload = utils.isObject(data);
2971
+
2972
+ if (isObjectPayload && utils.isHTMLForm(data)) {
2973
+ data = new FormData(data);
2974
+ }
2975
+
2976
+ const isFormData = utils.isFormData(data);
2977
+
2978
+ if (isFormData) {
2979
+ if (!hasJSONContentType) {
2980
+ return data;
2981
+ }
2982
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
2983
+ }
2984
+
2985
+ if (utils.isArrayBuffer(data) ||
2986
+ utils.isBuffer(data) ||
2987
+ utils.isStream(data) ||
2988
+ utils.isFile(data) ||
2989
+ utils.isBlob(data)
2990
+ ) {
2991
+ return data;
2992
+ }
2993
+ if (utils.isArrayBufferView(data)) {
2994
+ return data.buffer;
2995
+ }
2996
+ if (utils.isURLSearchParams(data)) {
2997
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
2998
+ return data.toString();
2999
+ }
3000
+
3001
+ let isFileList;
3002
+
3003
+ if (isObjectPayload) {
3004
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
3005
+ return toURLEncodedForm(data, this.formSerializer).toString();
3006
+ }
3007
+
3008
+ if ((isFileList = utils.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
3009
+ const _FormData = this.env && this.env.FormData;
3010
+
3011
+ return toFormData(
3012
+ isFileList ? {'files[]': data} : data,
3013
+ _FormData && new _FormData(),
3014
+ this.formSerializer
3015
+ );
3016
+ }
3017
+ }
3018
+
3019
+ if (isObjectPayload || hasJSONContentType ) {
3020
+ headers.setContentType('application/json', false);
3021
+ return stringifySafely(data);
3022
+ }
3023
+
3024
+ return data;
3025
+ }],
3026
+
3027
+ transformResponse: [function transformResponse(data) {
3028
+ const transitional = this.transitional || defaults.transitional;
3029
+ const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
3030
+ const JSONRequested = this.responseType === 'json';
3031
+
3032
+ if (data && utils.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
3033
+ const silentJSONParsing = transitional && transitional.silentJSONParsing;
3034
+ const strictJSONParsing = !silentJSONParsing && JSONRequested;
3035
+
3036
+ try {
3037
+ return JSON.parse(data);
3038
+ } catch (e) {
3039
+ if (strictJSONParsing) {
3040
+ if (e.name === 'SyntaxError') {
3041
+ throw AxiosError.from(e, AxiosError.ERR_BAD_RESPONSE, this, null, this.response);
3042
+ }
3043
+ throw e;
3044
+ }
3045
+ }
3046
+ }
3047
+
3048
+ return data;
3049
+ }],
3050
+
3051
+ /**
3052
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
3053
+ * timeout is not created.
3054
+ */
3055
+ timeout: 0,
3056
+
3057
+ xsrfCookieName: 'XSRF-TOKEN',
3058
+ xsrfHeaderName: 'X-XSRF-TOKEN',
3059
+
3060
+ maxContentLength: -1,
3061
+ maxBodyLength: -1,
3062
+
3063
+ env: {
3064
+ FormData: platform.classes.FormData,
3065
+ Blob: platform.classes.Blob
3066
+ },
3067
+
3068
+ validateStatus: function validateStatus(status) {
3069
+ return status >= 200 && status < 300;
3070
+ },
3071
+
3072
+ headers: {
3073
+ common: {
3074
+ 'Accept': 'application/json, text/plain, */*'
3075
+ }
3076
+ }
3077
+ };
3078
+
3079
+ utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
3080
+ defaults.headers[method] = {};
3081
+ });
3082
+
3083
+ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3084
+ defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
3085
+ });
3086
+
3087
+ /**
3088
+ * Transform the data for a request or a response
3089
+ *
3090
+ * @param {Array|Function} fns A single function or Array of functions
3091
+ * @param {?Object} response The response object
3092
+ *
3093
+ * @returns {*} The resulting transformed data
3094
+ */
3095
+ function transformData(fns, response) {
3096
+ const config = this || defaults;
3097
+ const context = response || config;
3098
+ const headers = AxiosHeaders.from(context.headers);
3099
+ let data = context.data;
3100
+
3101
+ utils.forEach(fns, function transform(fn) {
3102
+ data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
3103
+ });
3104
+
3105
+ headers.normalize();
3106
+
3107
+ return data;
3108
+ }
3109
+
3110
+ function isCancel(value) {
3111
+ return !!(value && value.__CANCEL__);
3112
+ }
3113
+
3114
+ /**
3115
+ * Throws a `CanceledError` if cancellation has been requested.
3116
+ *
3117
+ * @param {Object} config The config that is to be used for the request
3118
+ *
3119
+ * @returns {void}
3120
+ */
3121
+ function throwIfCancellationRequested(config) {
3122
+ if (config.cancelToken) {
3123
+ config.cancelToken.throwIfRequested();
3124
+ }
3125
+
3126
+ if (config.signal && config.signal.aborted) {
3127
+ throw new CanceledError();
3128
+ }
3129
+ }
3130
+
3131
+ /**
3132
+ * Dispatch a request to the server using the configured adapter.
3133
+ *
3134
+ * @param {object} config The config that is to be used for the request
3135
+ *
3136
+ * @returns {Promise} The Promise to be fulfilled
3137
+ */
3138
+ function dispatchRequest(config) {
3139
+ throwIfCancellationRequested(config);
3140
+
3141
+ config.headers = AxiosHeaders.from(config.headers);
3142
+
3143
+ // Transform request data
3144
+ config.data = transformData.call(
3145
+ config,
3146
+ config.transformRequest
3147
+ );
3148
+
3149
+ const adapter = config.adapter || defaults.adapter;
3150
+
3151
+ return adapter(config).then(function onAdapterResolution(response) {
3152
+ throwIfCancellationRequested(config);
3153
+
3154
+ // Transform response data
3155
+ response.data = transformData.call(
3156
+ config,
3157
+ config.transformResponse,
3158
+ response
3159
+ );
3160
+
3161
+ response.headers = AxiosHeaders.from(response.headers);
3162
+
3163
+ return response;
3164
+ }, function onAdapterRejection(reason) {
3165
+ if (!isCancel(reason)) {
3166
+ throwIfCancellationRequested(config);
3167
+
3168
+ // Transform response data
3169
+ if (reason && reason.response) {
3170
+ reason.response.data = transformData.call(
3171
+ config,
3172
+ config.transformResponse,
3173
+ reason.response
3174
+ );
3175
+ reason.response.headers = AxiosHeaders.from(reason.response.headers);
3176
+ }
3177
+ }
3178
+
3179
+ return Promise.reject(reason);
3180
+ });
3181
+ }
3182
+
3183
+ /**
3184
+ * Config-specific merge-function which creates a new config-object
3185
+ * by merging two configuration objects together.
3186
+ *
3187
+ * @param {Object} config1
3188
+ * @param {Object} config2
3189
+ *
3190
+ * @returns {Object} New object resulting from merging config2 to config1
3191
+ */
3192
+ function mergeConfig(config1, config2) {
3193
+ // eslint-disable-next-line no-param-reassign
3194
+ config2 = config2 || {};
3195
+ const config = {};
3196
+
3197
+ function getMergedValue(target, source) {
3198
+ if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
3199
+ return utils.merge(target, source);
3200
+ } else if (utils.isPlainObject(source)) {
3201
+ return utils.merge({}, source);
3202
+ } else if (utils.isArray(source)) {
3203
+ return source.slice();
3204
+ }
3205
+ return source;
3206
+ }
3207
+
3208
+ // eslint-disable-next-line consistent-return
3209
+ function mergeDeepProperties(prop) {
3210
+ if (!utils.isUndefined(config2[prop])) {
3211
+ return getMergedValue(config1[prop], config2[prop]);
3212
+ } else if (!utils.isUndefined(config1[prop])) {
3213
+ return getMergedValue(undefined, config1[prop]);
3214
+ }
3215
+ }
3216
+
3217
+ // eslint-disable-next-line consistent-return
3218
+ function valueFromConfig2(prop) {
3219
+ if (!utils.isUndefined(config2[prop])) {
3220
+ return getMergedValue(undefined, config2[prop]);
3221
+ }
3222
+ }
3223
+
3224
+ // eslint-disable-next-line consistent-return
3225
+ function defaultToConfig2(prop) {
3226
+ if (!utils.isUndefined(config2[prop])) {
3227
+ return getMergedValue(undefined, config2[prop]);
3228
+ } else if (!utils.isUndefined(config1[prop])) {
3229
+ return getMergedValue(undefined, config1[prop]);
3230
+ }
3231
+ }
3232
+
3233
+ // eslint-disable-next-line consistent-return
3234
+ function mergeDirectKeys(prop) {
3235
+ if (prop in config2) {
3236
+ return getMergedValue(config1[prop], config2[prop]);
3237
+ } else if (prop in config1) {
3238
+ return getMergedValue(undefined, config1[prop]);
3239
+ }
3240
+ }
3241
+
3242
+ const mergeMap = {
3243
+ 'url': valueFromConfig2,
3244
+ 'method': valueFromConfig2,
3245
+ 'data': valueFromConfig2,
3246
+ 'baseURL': defaultToConfig2,
3247
+ 'transformRequest': defaultToConfig2,
3248
+ 'transformResponse': defaultToConfig2,
3249
+ 'paramsSerializer': defaultToConfig2,
3250
+ 'timeout': defaultToConfig2,
3251
+ 'timeoutMessage': defaultToConfig2,
3252
+ 'withCredentials': defaultToConfig2,
3253
+ 'adapter': defaultToConfig2,
3254
+ 'responseType': defaultToConfig2,
3255
+ 'xsrfCookieName': defaultToConfig2,
3256
+ 'xsrfHeaderName': defaultToConfig2,
3257
+ 'onUploadProgress': defaultToConfig2,
3258
+ 'onDownloadProgress': defaultToConfig2,
3259
+ 'decompress': defaultToConfig2,
3260
+ 'maxContentLength': defaultToConfig2,
3261
+ 'maxBodyLength': defaultToConfig2,
3262
+ 'beforeRedirect': defaultToConfig2,
3263
+ 'transport': defaultToConfig2,
3264
+ 'httpAgent': defaultToConfig2,
3265
+ 'httpsAgent': defaultToConfig2,
3266
+ 'cancelToken': defaultToConfig2,
3267
+ 'socketPath': defaultToConfig2,
3268
+ 'responseEncoding': defaultToConfig2,
3269
+ 'validateStatus': mergeDirectKeys
3270
+ };
3271
+
3272
+ utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
3273
+ const merge = mergeMap[prop] || mergeDeepProperties;
3274
+ const configValue = merge(prop);
3275
+ (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
3276
+ });
3277
+
3278
+ return config;
3279
+ }
3280
+
3281
+ const validators$1 = {};
3282
+
3283
+ // eslint-disable-next-line func-names
3284
+ ['object', 'boolean', 'number', 'function', 'string', 'symbol'].forEach((type, i) => {
3285
+ validators$1[type] = function validator(thing) {
3286
+ return typeof thing === type || 'a' + (i < 1 ? 'n ' : ' ') + type;
3287
+ };
3288
+ });
3289
+
3290
+ const deprecatedWarnings = {};
3291
+
3292
+ /**
3293
+ * Transitional option validator
3294
+ *
3295
+ * @param {function|boolean?} validator - set to false if the transitional option has been removed
3296
+ * @param {string?} version - deprecated version / removed since version
3297
+ * @param {string?} message - some message with additional info
3298
+ *
3299
+ * @returns {function}
3300
+ */
3301
+ validators$1.transitional = function transitional(validator, version, message) {
3302
+ function formatMessage(opt, desc) {
3303
+ return '[Axios v' + VERSION + '] Transitional option \'' + opt + '\'' + desc + (message ? '. ' + message : '');
3304
+ }
3305
+
3306
+ // eslint-disable-next-line func-names
3307
+ return (value, opt, opts) => {
3308
+ if (validator === false) {
3309
+ throw new AxiosError(
3310
+ formatMessage(opt, ' has been removed' + (version ? ' in ' + version : '')),
3311
+ AxiosError.ERR_DEPRECATED
3312
+ );
3313
+ }
3314
+
3315
+ if (version && !deprecatedWarnings[opt]) {
3316
+ deprecatedWarnings[opt] = true;
3317
+ // eslint-disable-next-line no-console
3318
+ console.warn(
3319
+ formatMessage(
3320
+ opt,
3321
+ ' has been deprecated since v' + version + ' and will be removed in the near future'
3322
+ )
3323
+ );
3324
+ }
3325
+
3326
+ return validator ? validator(value, opt, opts) : true;
3327
+ };
3328
+ };
3329
+
3330
+ /**
3331
+ * Assert object's properties type
3332
+ *
3333
+ * @param {object} options
3334
+ * @param {object} schema
3335
+ * @param {boolean?} allowUnknown
3336
+ *
3337
+ * @returns {object}
3338
+ */
3339
+
3340
+ function assertOptions(options, schema, allowUnknown) {
3341
+ if (typeof options !== 'object') {
3342
+ throw new AxiosError('options must be an object', AxiosError.ERR_BAD_OPTION_VALUE);
3343
+ }
3344
+ const keys = Object.keys(options);
3345
+ let i = keys.length;
3346
+ while (i-- > 0) {
3347
+ const opt = keys[i];
3348
+ const validator = schema[opt];
3349
+ if (validator) {
3350
+ const value = options[opt];
3351
+ const result = value === undefined || validator(value, opt, options);
3352
+ if (result !== true) {
3353
+ throw new AxiosError('option ' + opt + ' must be ' + result, AxiosError.ERR_BAD_OPTION_VALUE);
3354
+ }
3355
+ continue;
3356
+ }
3357
+ if (allowUnknown !== true) {
3358
+ throw new AxiosError('Unknown option ' + opt, AxiosError.ERR_BAD_OPTION);
3359
+ }
3360
+ }
3361
+ }
3362
+
3363
+ const validator = {
3364
+ assertOptions,
3365
+ validators: validators$1
3366
+ };
3367
+
3368
+ const validators = validator.validators;
3369
+
3370
+ /**
3371
+ * Create a new instance of Axios
3372
+ *
3373
+ * @param {Object} instanceConfig The default config for the instance
3374
+ *
3375
+ * @return {Axios} A new instance of Axios
3376
+ */
3377
+ class Axios {
3378
+ constructor(instanceConfig) {
3379
+ this.defaults = instanceConfig;
3380
+ this.interceptors = {
3381
+ request: new InterceptorManager(),
3382
+ response: new InterceptorManager()
3383
+ };
3384
+ }
3385
+
3386
+ /**
3387
+ * Dispatch a request
3388
+ *
3389
+ * @param {String|Object} configOrUrl The config specific for this request (merged with this.defaults)
3390
+ * @param {?Object} config
3391
+ *
3392
+ * @returns {Promise} The Promise to be fulfilled
3393
+ */
3394
+ request(configOrUrl, config) {
3395
+ /*eslint no-param-reassign:0*/
3396
+ // Allow for axios('example/url'[, config]) a la fetch API
3397
+ if (typeof configOrUrl === 'string') {
3398
+ config = config || {};
3399
+ config.url = configOrUrl;
3400
+ } else {
3401
+ config = configOrUrl || {};
3402
+ }
3403
+
3404
+ config = mergeConfig(this.defaults, config);
3405
+
3406
+ const transitional = config.transitional;
3407
+
3408
+ if (transitional !== undefined) {
3409
+ validator.assertOptions(transitional, {
3410
+ silentJSONParsing: validators.transitional(validators.boolean),
3411
+ forcedJSONParsing: validators.transitional(validators.boolean),
3412
+ clarifyTimeoutError: validators.transitional(validators.boolean)
3413
+ }, false);
3414
+ }
3415
+
3416
+ // Set config.method
3417
+ config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3418
+
3419
+ // Flatten headers
3420
+ const defaultHeaders = config.headers && utils.merge(
3421
+ config.headers.common,
3422
+ config.headers[config.method]
3423
+ );
3424
+
3425
+ defaultHeaders && utils.forEach(
3426
+ ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
3427
+ function cleanHeaderConfig(method) {
3428
+ delete config.headers[method];
3429
+ }
3430
+ );
3431
+
3432
+ config.headers = new AxiosHeaders(config.headers, defaultHeaders);
3433
+
3434
+ // filter out skipped interceptors
3435
+ const requestInterceptorChain = [];
3436
+ let synchronousRequestInterceptors = true;
3437
+ this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
3438
+ if (typeof interceptor.runWhen === 'function' && interceptor.runWhen(config) === false) {
3439
+ return;
3440
+ }
3441
+
3442
+ synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
3443
+
3444
+ requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
3445
+ });
3446
+
3447
+ const responseInterceptorChain = [];
3448
+ this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
3449
+ responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
3450
+ });
3451
+
3452
+ let promise;
3453
+ let i = 0;
3454
+ let len;
3455
+
3456
+ if (!synchronousRequestInterceptors) {
3457
+ const chain = [dispatchRequest.bind(this), undefined];
3458
+ chain.unshift.apply(chain, requestInterceptorChain);
3459
+ chain.push.apply(chain, responseInterceptorChain);
3460
+ len = chain.length;
3461
+
3462
+ promise = Promise.resolve(config);
3463
+
3464
+ while (i < len) {
3465
+ promise = promise.then(chain[i++], chain[i++]);
3466
+ }
3467
+
3468
+ return promise;
3469
+ }
3470
+
3471
+ len = requestInterceptorChain.length;
3472
+
3473
+ let newConfig = config;
3474
+
3475
+ i = 0;
3476
+
3477
+ while (i < len) {
3478
+ const onFulfilled = requestInterceptorChain[i++];
3479
+ const onRejected = requestInterceptorChain[i++];
3480
+ try {
3481
+ newConfig = onFulfilled(newConfig);
3482
+ } catch (error) {
3483
+ onRejected.call(this, error);
3484
+ break;
3485
+ }
3486
+ }
3487
+
3488
+ try {
3489
+ promise = dispatchRequest.call(this, newConfig);
3490
+ } catch (error) {
3491
+ return Promise.reject(error);
3492
+ }
3493
+
3494
+ i = 0;
3495
+ len = responseInterceptorChain.length;
3496
+
3497
+ while (i < len) {
3498
+ promise = promise.then(responseInterceptorChain[i++], responseInterceptorChain[i++]);
3499
+ }
3500
+
3501
+ return promise;
3502
+ }
3503
+
3504
+ getUri(config) {
3505
+ config = mergeConfig(this.defaults, config);
3506
+ const fullPath = buildFullPath(config.baseURL, config.url);
3507
+ return buildURL(fullPath, config.params, config.paramsSerializer);
3508
+ }
3509
+ }
3510
+
3511
+ // Provide aliases for supported request methods
3512
+ utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
3513
+ /*eslint func-names:0*/
3514
+ Axios.prototype[method] = function(url, config) {
3515
+ return this.request(mergeConfig(config || {}, {
3516
+ method,
3517
+ url,
3518
+ data: (config || {}).data
3519
+ }));
3520
+ };
3521
+ });
3522
+
3523
+ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3524
+ /*eslint func-names:0*/
3525
+
3526
+ function generateHTTPMethod(isForm) {
3527
+ return function httpMethod(url, data, config) {
3528
+ return this.request(mergeConfig(config || {}, {
3529
+ method,
3530
+ headers: isForm ? {
3531
+ 'Content-Type': 'multipart/form-data'
3532
+ } : {},
3533
+ url,
3534
+ data
3535
+ }));
3536
+ };
3537
+ }
3538
+
3539
+ Axios.prototype[method] = generateHTTPMethod();
3540
+
3541
+ Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
3542
+ });
3543
+
3544
+ /**
3545
+ * A `CancelToken` is an object that can be used to request cancellation of an operation.
3546
+ *
3547
+ * @param {Function} executor The executor function.
3548
+ *
3549
+ * @returns {CancelToken}
3550
+ */
3551
+ class CancelToken {
3552
+ constructor(executor) {
3553
+ if (typeof executor !== 'function') {
3554
+ throw new TypeError('executor must be a function.');
3555
+ }
3556
+
3557
+ let resolvePromise;
3558
+
3559
+ this.promise = new Promise(function promiseExecutor(resolve) {
3560
+ resolvePromise = resolve;
3561
+ });
3562
+
3563
+ const token = this;
3564
+
3565
+ // eslint-disable-next-line func-names
3566
+ this.promise.then(cancel => {
3567
+ if (!token._listeners) return;
3568
+
3569
+ let i = token._listeners.length;
3570
+
3571
+ while (i-- > 0) {
3572
+ token._listeners[i](cancel);
3573
+ }
3574
+ token._listeners = null;
3575
+ });
3576
+
3577
+ // eslint-disable-next-line func-names
3578
+ this.promise.then = onfulfilled => {
3579
+ let _resolve;
3580
+ // eslint-disable-next-line func-names
3581
+ const promise = new Promise(resolve => {
3582
+ token.subscribe(resolve);
3583
+ _resolve = resolve;
3584
+ }).then(onfulfilled);
3585
+
3586
+ promise.cancel = function reject() {
3587
+ token.unsubscribe(_resolve);
3588
+ };
3589
+
3590
+ return promise;
3591
+ };
3592
+
3593
+ executor(function cancel(message, config, request) {
3594
+ if (token.reason) {
3595
+ // Cancellation has already been requested
3596
+ return;
3597
+ }
3598
+
3599
+ token.reason = new CanceledError(message, config, request);
3600
+ resolvePromise(token.reason);
3601
+ });
3602
+ }
3603
+
3604
+ /**
3605
+ * Throws a `CanceledError` if cancellation has been requested.
3606
+ */
3607
+ throwIfRequested() {
3608
+ if (this.reason) {
3609
+ throw this.reason;
3610
+ }
3611
+ }
3612
+
3613
+ /**
3614
+ * Subscribe to the cancel signal
3615
+ */
3616
+
3617
+ subscribe(listener) {
3618
+ if (this.reason) {
3619
+ listener(this.reason);
3620
+ return;
3621
+ }
3622
+
3623
+ if (this._listeners) {
3624
+ this._listeners.push(listener);
3625
+ } else {
3626
+ this._listeners = [listener];
3627
+ }
3628
+ }
3629
+
3630
+ /**
3631
+ * Unsubscribe from the cancel signal
3632
+ */
3633
+
3634
+ unsubscribe(listener) {
3635
+ if (!this._listeners) {
3636
+ return;
3637
+ }
3638
+ const index = this._listeners.indexOf(listener);
3639
+ if (index !== -1) {
3640
+ this._listeners.splice(index, 1);
3641
+ }
3642
+ }
3643
+
3644
+ /**
3645
+ * Returns an object that contains a new `CancelToken` and a function that, when called,
3646
+ * cancels the `CancelToken`.
3647
+ */
3648
+ static source() {
3649
+ let cancel;
3650
+ const token = new CancelToken(function executor(c) {
3651
+ cancel = c;
3652
+ });
3653
+ return {
3654
+ token,
3655
+ cancel
3656
+ };
3657
+ }
3658
+ }
3659
+
3660
+ /**
3661
+ * Syntactic sugar for invoking a function and expanding an array for arguments.
3662
+ *
3663
+ * Common use case would be to use `Function.prototype.apply`.
3664
+ *
3665
+ * ```js
3666
+ * function f(x, y, z) {}
3667
+ * var args = [1, 2, 3];
3668
+ * f.apply(null, args);
3669
+ * ```
3670
+ *
3671
+ * With `spread` this example can be re-written.
3672
+ *
3673
+ * ```js
3674
+ * spread(function(x, y, z) {})([1, 2, 3]);
3675
+ * ```
3676
+ *
3677
+ * @param {Function} callback
3678
+ *
3679
+ * @returns {Function}
3680
+ */
3681
+ function spread(callback) {
3682
+ return function wrap(arr) {
3683
+ return callback.apply(null, arr);
3684
+ };
3685
+ }
3686
+
3687
+ /**
3688
+ * Determines whether the payload is an error thrown by Axios
3689
+ *
3690
+ * @param {*} payload The value to test
3691
+ *
3692
+ * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
3693
+ */
3694
+ function isAxiosError(payload) {
3695
+ return utils.isObject(payload) && (payload.isAxiosError === true);
3696
+ }
3697
+
3698
+ /**
3699
+ * Create an instance of Axios
3700
+ *
3701
+ * @param {Object} defaultConfig The default config for the instance
3702
+ *
3703
+ * @returns {Axios} A new instance of Axios
3704
+ */
3705
+ function createInstance(defaultConfig) {
3706
+ const context = new Axios(defaultConfig);
3707
+ const instance = bind(Axios.prototype.request, context);
3708
+
3709
+ // Copy axios.prototype to instance
3710
+ utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
3711
+
3712
+ // Copy context to instance
3713
+ utils.extend(instance, context, null, {allOwnKeys: true});
3714
+
3715
+ // Factory for creating new instances
3716
+ instance.create = function create(instanceConfig) {
3717
+ return createInstance(mergeConfig(defaultConfig, instanceConfig));
3718
+ };
3719
+
3720
+ return instance;
3721
+ }
3722
+
3723
+ // Create the default instance to be exported
3724
+ const axios = createInstance(defaults);
3725
+
3726
+ // Expose Axios class to allow class inheritance
3727
+ axios.Axios = Axios;
3728
+
3729
+ // Expose Cancel & CancelToken
3730
+ axios.CanceledError = CanceledError;
3731
+ axios.CancelToken = CancelToken;
3732
+ axios.isCancel = isCancel;
3733
+ axios.VERSION = VERSION;
3734
+ axios.toFormData = toFormData;
3735
+
3736
+ // Expose AxiosError class
3737
+ axios.AxiosError = AxiosError;
3738
+
3739
+ // alias for CanceledError for backward compatibility
3740
+ axios.Cancel = axios.CanceledError;
3741
+
3742
+ // Expose all/spread
3743
+ axios.all = function all(promises) {
3744
+ return Promise.all(promises);
3745
+ };
3746
+
3747
+ axios.spread = spread;
3748
+
3749
+ // Expose isAxiosError
3750
+ axios.isAxiosError = isAxiosError;
3751
+
3752
+ axios.formToJSON = thing => {
3753
+ return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3754
+ };
3755
+
3756
+ exports.Axios = Axios;
3757
+ exports.AxiosError = AxiosError;
3758
+ exports.AxiosHeaders = AxiosHeaders;
3759
+ exports.CanceledError = CanceledError;
3760
+ exports["default"] = axios;
3761
+ //# sourceMappingURL=axios.cjs.map