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