axios 1.6.8 → 1.7.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

package/dist/axios.js CHANGED
@@ -1,10 +1,144 @@
1
- // Axios v1.6.8 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.0-beta.0 Copyright (c) 2024 Matt Zabriskie and contributors
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
5
5
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.axios = factory());
6
6
  })(this, (function () { 'use strict';
7
7
 
8
+ function _AsyncGenerator(e) {
9
+ var r, t;
10
+ function resume(r, t) {
11
+ try {
12
+ var n = e[r](t),
13
+ o = n.value,
14
+ u = o instanceof _OverloadYield;
15
+ Promise.resolve(u ? o.v : o).then(function (t) {
16
+ if (u) {
17
+ var i = "return" === r ? "return" : "next";
18
+ if (!o.k || t.done) return resume(i, t);
19
+ t = e[i](t).value;
20
+ }
21
+ settle(n.done ? "return" : "normal", t);
22
+ }, function (e) {
23
+ resume("throw", e);
24
+ });
25
+ } catch (e) {
26
+ settle("throw", e);
27
+ }
28
+ }
29
+ function settle(e, n) {
30
+ switch (e) {
31
+ case "return":
32
+ r.resolve({
33
+ value: n,
34
+ done: !0
35
+ });
36
+ break;
37
+ case "throw":
38
+ r.reject(n);
39
+ break;
40
+ default:
41
+ r.resolve({
42
+ value: n,
43
+ done: !1
44
+ });
45
+ }
46
+ (r = r.next) ? resume(r.key, r.arg) : t = null;
47
+ }
48
+ this._invoke = function (e, n) {
49
+ return new Promise(function (o, u) {
50
+ var i = {
51
+ key: e,
52
+ arg: n,
53
+ resolve: o,
54
+ reject: u,
55
+ next: null
56
+ };
57
+ t ? t = t.next = i : (r = t = i, resume(e, n));
58
+ });
59
+ }, "function" != typeof e.return && (this.return = void 0);
60
+ }
61
+ _AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function () {
62
+ return this;
63
+ }, _AsyncGenerator.prototype.next = function (e) {
64
+ return this._invoke("next", e);
65
+ }, _AsyncGenerator.prototype.throw = function (e) {
66
+ return this._invoke("throw", e);
67
+ }, _AsyncGenerator.prototype.return = function (e) {
68
+ return this._invoke("return", e);
69
+ };
70
+ function _OverloadYield(t, e) {
71
+ this.v = t, this.k = e;
72
+ }
73
+ function _asyncGeneratorDelegate(t) {
74
+ var e = {},
75
+ n = !1;
76
+ function pump(e, r) {
77
+ return n = !0, r = new Promise(function (n) {
78
+ n(t[e](r));
79
+ }), {
80
+ done: !1,
81
+ value: new _OverloadYield(r, 1)
82
+ };
83
+ }
84
+ return e["undefined" != typeof Symbol && Symbol.iterator || "@@iterator"] = function () {
85
+ return this;
86
+ }, e.next = function (t) {
87
+ return n ? (n = !1, t) : pump("next", t);
88
+ }, "function" == typeof t.throw && (e.throw = function (t) {
89
+ if (n) throw n = !1, t;
90
+ return pump("throw", t);
91
+ }), "function" == typeof t.return && (e.return = function (t) {
92
+ return n ? (n = !1, t) : pump("return", t);
93
+ }), e;
94
+ }
95
+ function _asyncIterator(r) {
96
+ var n,
97
+ t,
98
+ o,
99
+ e = 2;
100
+ for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
101
+ if (t && null != (n = r[t])) return n.call(r);
102
+ if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
103
+ t = "@@asyncIterator", o = "@@iterator";
104
+ }
105
+ throw new TypeError("Object is not async iterable");
106
+ }
107
+ function AsyncFromSyncIterator(r) {
108
+ function AsyncFromSyncIteratorContinuation(r) {
109
+ if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
110
+ var n = r.done;
111
+ return Promise.resolve(r.value).then(function (r) {
112
+ return {
113
+ value: r,
114
+ done: n
115
+ };
116
+ });
117
+ }
118
+ return AsyncFromSyncIterator = function (r) {
119
+ this.s = r, this.n = r.next;
120
+ }, AsyncFromSyncIterator.prototype = {
121
+ s: null,
122
+ n: null,
123
+ next: function () {
124
+ return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
125
+ },
126
+ return: function (r) {
127
+ var n = this.s.return;
128
+ return void 0 === n ? Promise.resolve({
129
+ value: r,
130
+ done: !0
131
+ }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
132
+ },
133
+ throw: function (r) {
134
+ var n = this.s.return;
135
+ return void 0 === n ? Promise.reject(r) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
136
+ }
137
+ }, new AsyncFromSyncIterator(r);
138
+ }
139
+ function _awaitAsyncGenerator(e) {
140
+ return new _OverloadYield(e, 0);
141
+ }
8
142
  function _iterableToArrayLimit(r, l) {
9
143
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
10
144
  if (null != t) {
@@ -377,6 +511,11 @@
377
511
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
378
512
  }, _typeof(o);
379
513
  }
514
+ function _wrapAsyncGenerator(fn) {
515
+ return function () {
516
+ return new _AsyncGenerator(fn.apply(this, arguments));
517
+ };
518
+ }
380
519
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
381
520
  try {
382
521
  var info = gen[key](arg);
@@ -480,6 +619,57 @@
480
619
  function _nonIterableRest() {
481
620
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
482
621
  }
622
+ function _createForOfIteratorHelper(o, allowArrayLike) {
623
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
624
+ if (!it) {
625
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
626
+ if (it) o = it;
627
+ var i = 0;
628
+ var F = function () {};
629
+ return {
630
+ s: F,
631
+ n: function () {
632
+ if (i >= o.length) return {
633
+ done: true
634
+ };
635
+ return {
636
+ done: false,
637
+ value: o[i++]
638
+ };
639
+ },
640
+ e: function (e) {
641
+ throw e;
642
+ },
643
+ f: F
644
+ };
645
+ }
646
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
647
+ }
648
+ var normalCompletion = true,
649
+ didErr = false,
650
+ err;
651
+ return {
652
+ s: function () {
653
+ it = it.call(o);
654
+ },
655
+ n: function () {
656
+ var step = it.next();
657
+ normalCompletion = step.done;
658
+ return step;
659
+ },
660
+ e: function (e) {
661
+ didErr = true;
662
+ err = e;
663
+ },
664
+ f: function () {
665
+ try {
666
+ if (!normalCompletion && it.return != null) it.return();
667
+ } finally {
668
+ if (didErr) throw err;
669
+ }
670
+ }
671
+ };
672
+ }
483
673
 
484
674
  function bind(fn, thisArg) {
485
675
  return function wrap() {
@@ -695,6 +885,12 @@
695
885
  * @returns {boolean} True if value is a URLSearchParams object, otherwise false
696
886
  */
697
887
  var isURLSearchParams = kindOfTest('URLSearchParams');
888
+ var _map = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest),
889
+ _map2 = _slicedToArray(_map, 4),
890
+ isReadableStream = _map2[0],
891
+ isRequest = _map2[1],
892
+ isResponse = _map2[2],
893
+ isHeaders = _map2[3];
698
894
 
699
895
  /**
700
896
  * Trim excess whitespace off the beginning and end of a string
@@ -1068,8 +1264,7 @@
1068
1264
  };
1069
1265
  var noop = function noop() {};
1070
1266
  var toFiniteNumber = function toFiniteNumber(value, defaultValue) {
1071
- value = +value;
1072
- return Number.isFinite(value) ? value : defaultValue;
1267
+ return value != null && Number.isFinite(value = +value) ? value : defaultValue;
1073
1268
  };
1074
1269
  var ALPHA = 'abcdefghijklmnopqrstuvwxyz';
1075
1270
  var DIGIT = '0123456789';
@@ -1136,6 +1331,10 @@
1136
1331
  isBoolean: isBoolean,
1137
1332
  isObject: isObject,
1138
1333
  isPlainObject: isPlainObject,
1334
+ isReadableStream: isReadableStream,
1335
+ isRequest: isRequest,
1336
+ isResponse: isResponse,
1337
+ isHeaders: isHeaders,
1139
1338
  isUndefined: isUndefined,
1140
1339
  isDate: isDate,
1141
1340
  isFile: isFile,
@@ -1667,12 +1866,14 @@
1667
1866
  // eslint-disable-next-line no-undef
1668
1867
  self instanceof WorkerGlobalScope && typeof self.importScripts === 'function';
1669
1868
  }();
1869
+ var origin = hasBrowserEnv && window.location.href || 'http://localhost';
1670
1870
 
1671
1871
  var utils = /*#__PURE__*/Object.freeze({
1672
1872
  __proto__: null,
1673
1873
  hasBrowserEnv: hasBrowserEnv,
1674
1874
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1675
- hasStandardBrowserEnv: hasStandardBrowserEnv
1875
+ hasStandardBrowserEnv: hasStandardBrowserEnv,
1876
+ origin: origin
1676
1877
  });
1677
1878
 
1678
1879
  var platform = _objectSpread2(_objectSpread2({}, utils), platform$1);
@@ -1792,7 +1993,7 @@
1792
1993
  }
1793
1994
  var defaults = {
1794
1995
  transitional: transitionalDefaults,
1795
- adapter: ['xhr', 'http'],
1996
+ adapter: ['xhr', 'http', 'fetch'],
1796
1997
  transformRequest: [function transformRequest(data, headers) {
1797
1998
  var contentType = headers.getContentType() || '';
1798
1999
  var hasJSONContentType = contentType.indexOf('application/json') > -1;
@@ -1804,7 +2005,7 @@
1804
2005
  if (isFormData) {
1805
2006
  return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1806
2007
  }
1807
- if (utils$1.isArrayBuffer(data) || utils$1.isBuffer(data) || utils$1.isStream(data) || utils$1.isFile(data) || utils$1.isBlob(data)) {
2008
+ if (utils$1.isArrayBuffer(data) || utils$1.isBuffer(data) || utils$1.isStream(data) || utils$1.isFile(data) || utils$1.isBlob(data) || utils$1.isReadableStream(data)) {
1808
2009
  return data;
1809
2010
  }
1810
2011
  if (utils$1.isArrayBufferView(data)) {
@@ -1836,6 +2037,9 @@
1836
2037
  var transitional = this.transitional || defaults.transitional;
1837
2038
  var forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1838
2039
  var JSONRequested = this.responseType === 'json';
2040
+ if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
2041
+ return data;
2042
+ }
1839
2043
  if (data && utils$1.isString(data) && (forcedJSONParsing && !this.responseType || JSONRequested)) {
1840
2044
  var silentJSONParsing = transitional && transitional.silentJSONParsing;
1841
2045
  var strictJSONParsing = !silentJSONParsing && JSONRequested;
@@ -2004,6 +2208,21 @@
2004
2208
  setHeaders(header, valueOrRewrite);
2005
2209
  } else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
2006
2210
  setHeaders(parseHeaders(header), valueOrRewrite);
2211
+ } else if (utils$1.isHeaders(header)) {
2212
+ var _iterator = _createForOfIteratorHelper(header.entries()),
2213
+ _step;
2214
+ try {
2215
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
2216
+ var _step$value = _slicedToArray(_step.value, 2),
2217
+ key = _step$value[0],
2218
+ value = _step$value[1];
2219
+ setHeader(value, key, rewrite);
2220
+ }
2221
+ } catch (err) {
2222
+ _iterator.e(err);
2223
+ } finally {
2224
+ _iterator.f();
2225
+ }
2007
2226
  } else {
2008
2227
  header != null && setHeader(valueOrRewrite, header, rewrite);
2009
2228
  }
@@ -2255,6 +2474,164 @@
2255
2474
  }
2256
2475
  }
2257
2476
 
2477
+ function parseProtocol(url) {
2478
+ var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2479
+ return match && match[1] || '';
2480
+ }
2481
+
2482
+ /**
2483
+ * Calculate data maxRate
2484
+ * @param {Number} [samplesCount= 10]
2485
+ * @param {Number} [min= 1000]
2486
+ * @returns {Function}
2487
+ */
2488
+ function speedometer(samplesCount, min) {
2489
+ samplesCount = samplesCount || 10;
2490
+ var bytes = new Array(samplesCount);
2491
+ var timestamps = new Array(samplesCount);
2492
+ var head = 0;
2493
+ var tail = 0;
2494
+ var firstSampleTS;
2495
+ min = min !== undefined ? min : 1000;
2496
+ return function push(chunkLength) {
2497
+ var now = Date.now();
2498
+ var startedAt = timestamps[tail];
2499
+ if (!firstSampleTS) {
2500
+ firstSampleTS = now;
2501
+ }
2502
+ bytes[head] = chunkLength;
2503
+ timestamps[head] = now;
2504
+ var i = tail;
2505
+ var bytesCount = 0;
2506
+ while (i !== head) {
2507
+ bytesCount += bytes[i++];
2508
+ i = i % samplesCount;
2509
+ }
2510
+ head = (head + 1) % samplesCount;
2511
+ if (head === tail) {
2512
+ tail = (tail + 1) % samplesCount;
2513
+ }
2514
+ if (now - firstSampleTS < min) {
2515
+ return;
2516
+ }
2517
+ var passed = startedAt && now - startedAt;
2518
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2519
+ };
2520
+ }
2521
+
2522
+ /**
2523
+ * Throttle decorator
2524
+ * @param {Function} fn
2525
+ * @param {Number} freq
2526
+ * @return {Function}
2527
+ */
2528
+ function throttle(fn, freq) {
2529
+ var timestamp = 0;
2530
+ var threshold = 1000 / freq;
2531
+ var timer = null;
2532
+ return function throttled() {
2533
+ var _arguments = arguments;
2534
+ var force = this === true;
2535
+ var now = Date.now();
2536
+ if (force || now - timestamp > threshold) {
2537
+ if (timer) {
2538
+ clearTimeout(timer);
2539
+ timer = null;
2540
+ }
2541
+ timestamp = now;
2542
+ return fn.apply(null, arguments);
2543
+ }
2544
+ if (!timer) {
2545
+ timer = setTimeout(function () {
2546
+ timer = null;
2547
+ timestamp = Date.now();
2548
+ return fn.apply(null, _arguments);
2549
+ }, threshold - (now - timestamp));
2550
+ }
2551
+ };
2552
+ }
2553
+
2554
+ var progressEventReducer = (function (listener, isDownloadStream) {
2555
+ var freq = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
2556
+ var bytesNotified = 0;
2557
+ var _speedometer = speedometer(50, 250);
2558
+ return throttle(function (e) {
2559
+ var loaded = e.loaded;
2560
+ var total = e.lengthComputable ? e.total : undefined;
2561
+ var progressBytes = loaded - bytesNotified;
2562
+ var rate = _speedometer(progressBytes);
2563
+ var inRange = loaded <= total;
2564
+ bytesNotified = loaded;
2565
+ var data = {
2566
+ loaded: loaded,
2567
+ total: total,
2568
+ progress: total ? loaded / total : undefined,
2569
+ bytes: progressBytes,
2570
+ rate: rate ? rate : undefined,
2571
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2572
+ event: e,
2573
+ lengthComputable: total != null
2574
+ };
2575
+ data[isDownloadStream ? 'download' : 'upload'] = true;
2576
+ listener(data);
2577
+ }, freq);
2578
+ });
2579
+
2580
+ var isURLSameOrigin = platform.hasStandardBrowserEnv ?
2581
+ // Standard browser envs have full support of the APIs needed to test
2582
+ // whether the request URL is of the same origin as current location.
2583
+ function standardBrowserEnv() {
2584
+ var msie = /(msie|trident)/i.test(navigator.userAgent);
2585
+ var urlParsingNode = document.createElement('a');
2586
+ var originURL;
2587
+
2588
+ /**
2589
+ * Parse a URL to discover its components
2590
+ *
2591
+ * @param {String} url The URL to be parsed
2592
+ * @returns {Object}
2593
+ */
2594
+ function resolveURL(url) {
2595
+ var href = url;
2596
+ if (msie) {
2597
+ // IE needs attribute set twice to normalize properties
2598
+ urlParsingNode.setAttribute('href', href);
2599
+ href = urlParsingNode.href;
2600
+ }
2601
+ urlParsingNode.setAttribute('href', href);
2602
+
2603
+ // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2604
+ return {
2605
+ href: urlParsingNode.href,
2606
+ protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2607
+ host: urlParsingNode.host,
2608
+ search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2609
+ hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2610
+ hostname: urlParsingNode.hostname,
2611
+ port: urlParsingNode.port,
2612
+ pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
2613
+ };
2614
+ }
2615
+ originURL = resolveURL(window.location.href);
2616
+
2617
+ /**
2618
+ * Determine if a URL shares the same origin as the current location
2619
+ *
2620
+ * @param {String} requestURL The URL to test
2621
+ * @returns {boolean} True if URL shares the same origin, otherwise false
2622
+ */
2623
+ return function isURLSameOrigin(requestURL) {
2624
+ var parsed = utils$1.isString(requestURL) ? resolveURL(requestURL) : requestURL;
2625
+ return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
2626
+ };
2627
+ }() :
2628
+ // Non standard browser envs (web workers, react-native) lack needed support.
2629
+ function nonStandardBrowserEnv() {
2630
+ return function isURLSameOrigin() {
2631
+ return true;
2632
+ };
2633
+ }();
2634
+
2258
2635
  var cookies = platform.hasStandardBrowserEnv ?
2259
2636
  // Standard browser envs support document.cookie
2260
2637
  {
@@ -2326,173 +2703,179 @@
2326
2703
  return requestedURL;
2327
2704
  }
2328
2705
 
2329
- var isURLSameOrigin = platform.hasStandardBrowserEnv ?
2330
- // Standard browser envs have full support of the APIs needed to test
2331
- // whether the request URL is of the same origin as current location.
2332
- function standardBrowserEnv() {
2333
- var msie = /(msie|trident)/i.test(navigator.userAgent);
2334
- var urlParsingNode = document.createElement('a');
2335
- var originURL;
2706
+ var headersToObject = function headersToObject(thing) {
2707
+ return thing instanceof AxiosHeaders$1 ? _objectSpread2({}, thing) : thing;
2708
+ };
2336
2709
 
2337
- /**
2338
- * Parse a URL to discover its components
2339
- *
2340
- * @param {String} url The URL to be parsed
2341
- * @returns {Object}
2342
- */
2343
- function resolveURL(url) {
2344
- var href = url;
2345
- if (msie) {
2346
- // IE needs attribute set twice to normalize properties
2347
- urlParsingNode.setAttribute('href', href);
2348
- href = urlParsingNode.href;
2710
+ /**
2711
+ * Config-specific merge-function which creates a new config-object
2712
+ * by merging two configuration objects together.
2713
+ *
2714
+ * @param {Object} config1
2715
+ * @param {Object} config2
2716
+ *
2717
+ * @returns {Object} New object resulting from merging config2 to config1
2718
+ */
2719
+ function mergeConfig(config1, config2) {
2720
+ // eslint-disable-next-line no-param-reassign
2721
+ config2 = config2 || {};
2722
+ var config = {};
2723
+ function getMergedValue(target, source, caseless) {
2724
+ if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2725
+ return utils$1.merge.call({
2726
+ caseless: caseless
2727
+ }, target, source);
2728
+ } else if (utils$1.isPlainObject(source)) {
2729
+ return utils$1.merge({}, source);
2730
+ } else if (utils$1.isArray(source)) {
2731
+ return source.slice();
2349
2732
  }
2350
- urlParsingNode.setAttribute('href', href);
2733
+ return source;
2734
+ }
2351
2735
 
2352
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2353
- return {
2354
- href: urlParsingNode.href,
2355
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2356
- host: urlParsingNode.host,
2357
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2358
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2359
- hostname: urlParsingNode.hostname,
2360
- port: urlParsingNode.port,
2361
- pathname: urlParsingNode.pathname.charAt(0) === '/' ? urlParsingNode.pathname : '/' + urlParsingNode.pathname
2362
- };
2736
+ // eslint-disable-next-line consistent-return
2737
+ function mergeDeepProperties(a, b, caseless) {
2738
+ if (!utils$1.isUndefined(b)) {
2739
+ return getMergedValue(a, b, caseless);
2740
+ } else if (!utils$1.isUndefined(a)) {
2741
+ return getMergedValue(undefined, a, caseless);
2742
+ }
2363
2743
  }
2364
- originURL = resolveURL(window.location.href);
2365
2744
 
2366
- /**
2367
- * Determine if a URL shares the same origin as the current location
2368
- *
2369
- * @param {String} requestURL The URL to test
2370
- * @returns {boolean} True if URL shares the same origin, otherwise false
2371
- */
2372
- return function isURLSameOrigin(requestURL) {
2373
- var parsed = utils$1.isString(requestURL) ? resolveURL(requestURL) : requestURL;
2374
- return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
2375
- };
2376
- }() :
2377
- // Non standard browser envs (web workers, react-native) lack needed support.
2378
- function nonStandardBrowserEnv() {
2379
- return function isURLSameOrigin() {
2380
- return true;
2381
- };
2382
- }();
2383
-
2384
- function parseProtocol(url) {
2385
- var match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2386
- return match && match[1] || '';
2387
- }
2388
-
2389
- /**
2390
- * Calculate data maxRate
2391
- * @param {Number} [samplesCount= 10]
2392
- * @param {Number} [min= 1000]
2393
- * @returns {Function}
2394
- */
2395
- function speedometer(samplesCount, min) {
2396
- samplesCount = samplesCount || 10;
2397
- var bytes = new Array(samplesCount);
2398
- var timestamps = new Array(samplesCount);
2399
- var head = 0;
2400
- var tail = 0;
2401
- var firstSampleTS;
2402
- min = min !== undefined ? min : 1000;
2403
- return function push(chunkLength) {
2404
- var now = Date.now();
2405
- var startedAt = timestamps[tail];
2406
- if (!firstSampleTS) {
2407
- firstSampleTS = now;
2745
+ // eslint-disable-next-line consistent-return
2746
+ function valueFromConfig2(a, b) {
2747
+ if (!utils$1.isUndefined(b)) {
2748
+ return getMergedValue(undefined, b);
2408
2749
  }
2409
- bytes[head] = chunkLength;
2410
- timestamps[head] = now;
2411
- var i = tail;
2412
- var bytesCount = 0;
2413
- while (i !== head) {
2414
- bytesCount += bytes[i++];
2415
- i = i % samplesCount;
2750
+ }
2751
+
2752
+ // eslint-disable-next-line consistent-return
2753
+ function defaultToConfig2(a, b) {
2754
+ if (!utils$1.isUndefined(b)) {
2755
+ return getMergedValue(undefined, b);
2756
+ } else if (!utils$1.isUndefined(a)) {
2757
+ return getMergedValue(undefined, a);
2416
2758
  }
2417
- head = (head + 1) % samplesCount;
2418
- if (head === tail) {
2419
- tail = (tail + 1) % samplesCount;
2759
+ }
2760
+
2761
+ // eslint-disable-next-line consistent-return
2762
+ function mergeDirectKeys(a, b, prop) {
2763
+ if (prop in config2) {
2764
+ return getMergedValue(a, b);
2765
+ } else if (prop in config1) {
2766
+ return getMergedValue(undefined, a);
2420
2767
  }
2421
- if (now - firstSampleTS < min) {
2422
- return;
2768
+ }
2769
+ var mergeMap = {
2770
+ url: valueFromConfig2,
2771
+ method: valueFromConfig2,
2772
+ data: valueFromConfig2,
2773
+ baseURL: defaultToConfig2,
2774
+ transformRequest: defaultToConfig2,
2775
+ transformResponse: defaultToConfig2,
2776
+ paramsSerializer: defaultToConfig2,
2777
+ timeout: defaultToConfig2,
2778
+ timeoutMessage: defaultToConfig2,
2779
+ withCredentials: defaultToConfig2,
2780
+ withXSRFToken: defaultToConfig2,
2781
+ adapter: defaultToConfig2,
2782
+ responseType: defaultToConfig2,
2783
+ xsrfCookieName: defaultToConfig2,
2784
+ xsrfHeaderName: defaultToConfig2,
2785
+ onUploadProgress: defaultToConfig2,
2786
+ onDownloadProgress: defaultToConfig2,
2787
+ decompress: defaultToConfig2,
2788
+ maxContentLength: defaultToConfig2,
2789
+ maxBodyLength: defaultToConfig2,
2790
+ beforeRedirect: defaultToConfig2,
2791
+ transport: defaultToConfig2,
2792
+ httpAgent: defaultToConfig2,
2793
+ httpsAgent: defaultToConfig2,
2794
+ cancelToken: defaultToConfig2,
2795
+ socketPath: defaultToConfig2,
2796
+ responseEncoding: defaultToConfig2,
2797
+ validateStatus: mergeDirectKeys,
2798
+ headers: function headers(a, b) {
2799
+ return mergeDeepProperties(headersToObject(a), headersToObject(b), true);
2423
2800
  }
2424
- var passed = startedAt && now - startedAt;
2425
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2426
2801
  };
2802
+ utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2803
+ var merge = mergeMap[prop] || mergeDeepProperties;
2804
+ var configValue = merge(config1[prop], config2[prop], prop);
2805
+ utils$1.isUndefined(configValue) && merge !== mergeDirectKeys || (config[prop] = configValue);
2806
+ });
2807
+ return config;
2427
2808
  }
2428
2809
 
2429
- function progressEventReducer(listener, isDownloadStream) {
2430
- var bytesNotified = 0;
2431
- var _speedometer = speedometer(50, 250);
2432
- return function (e) {
2433
- var loaded = e.loaded;
2434
- var total = e.lengthComputable ? e.total : undefined;
2435
- var progressBytes = loaded - bytesNotified;
2436
- var rate = _speedometer(progressBytes);
2437
- var inRange = loaded <= total;
2438
- bytesNotified = loaded;
2439
- var data = {
2440
- loaded: loaded,
2441
- total: total,
2442
- progress: total ? loaded / total : undefined,
2443
- bytes: progressBytes,
2444
- rate: rate ? rate : undefined,
2445
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2446
- event: e
2447
- };
2448
- data[isDownloadStream ? 'download' : 'upload'] = true;
2449
- listener(data);
2450
- };
2451
- }
2810
+ var resolveConfig = (function (config) {
2811
+ var newConfig = mergeConfig({}, config);
2812
+ var data = newConfig.data,
2813
+ withXSRFToken = newConfig.withXSRFToken,
2814
+ xsrfHeaderName = newConfig.xsrfHeaderName,
2815
+ xsrfCookieName = newConfig.xsrfCookieName,
2816
+ headers = newConfig.headers,
2817
+ auth = newConfig.auth;
2818
+ newConfig.headers = headers = AxiosHeaders$1.from(headers);
2819
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2820
+
2821
+ // HTTP basic authentication
2822
+ if (auth) {
2823
+ headers.set('Authorization', 'Basic ' + btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : '')));
2824
+ }
2825
+ var contentType;
2826
+ if (utils$1.isFormData(data)) {
2827
+ if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2828
+ headers.setContentType(undefined); // Let the browser set it
2829
+ } else if ((contentType = headers.getContentType()) !== false) {
2830
+ // fix semicolon duplication issue for ReactNative FormData implementation
2831
+ var _ref = contentType ? contentType.split(';').map(function (token) {
2832
+ return token.trim();
2833
+ }).filter(Boolean) : [],
2834
+ _ref2 = _toArray(_ref),
2835
+ type = _ref2[0],
2836
+ tokens = _ref2.slice(1);
2837
+ headers.setContentType([type || 'multipart/form-data'].concat(_toConsumableArray(tokens)).join('; '));
2838
+ }
2839
+ }
2840
+
2841
+ // Add xsrf header
2842
+ // This is only done if running in a standard browser environment.
2843
+ // Specifically not if we're in a web worker, or react-native.
2844
+
2845
+ if (platform.hasStandardBrowserEnv) {
2846
+ withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
2847
+ if (withXSRFToken || withXSRFToken !== false && isURLSameOrigin(newConfig.url)) {
2848
+ // Add xsrf header
2849
+ var xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
2850
+ if (xsrfValue) {
2851
+ headers.set(xsrfHeaderName, xsrfValue);
2852
+ }
2853
+ }
2854
+ }
2855
+ return newConfig;
2856
+ });
2857
+
2452
2858
  var isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2453
2859
  var xhrAdapter = isXHRAdapterSupported && function (config) {
2454
2860
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2455
- var requestData = config.data;
2456
- var requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
2457
- var responseType = config.responseType,
2458
- withXSRFToken = config.withXSRFToken;
2861
+ var _config = resolveConfig(config);
2862
+ var requestData = _config.data;
2863
+ var requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
2864
+ var responseType = _config.responseType;
2459
2865
  var onCanceled;
2460
2866
  function done() {
2461
- if (config.cancelToken) {
2462
- config.cancelToken.unsubscribe(onCanceled);
2867
+ if (_config.cancelToken) {
2868
+ _config.cancelToken.unsubscribe(onCanceled);
2463
2869
  }
2464
- if (config.signal) {
2465
- config.signal.removeEventListener('abort', onCanceled);
2466
- }
2467
- }
2468
- var contentType;
2469
- if (utils$1.isFormData(requestData)) {
2470
- if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2471
- requestHeaders.setContentType(false); // Let the browser set it
2472
- } else if ((contentType = requestHeaders.getContentType()) !== false) {
2473
- // fix semicolon duplication issue for ReactNative FormData implementation
2474
- var _ref = contentType ? contentType.split(';').map(function (token) {
2475
- return token.trim();
2476
- }).filter(Boolean) : [],
2477
- _ref2 = _toArray(_ref),
2478
- type = _ref2[0],
2479
- tokens = _ref2.slice(1);
2480
- requestHeaders.setContentType([type || 'multipart/form-data'].concat(_toConsumableArray(tokens)).join('; '));
2870
+ if (_config.signal) {
2871
+ _config.signal.removeEventListener('abort', onCanceled);
2481
2872
  }
2482
2873
  }
2483
2874
  var request = new XMLHttpRequest();
2484
-
2485
- // HTTP basic authentication
2486
- if (config.auth) {
2487
- var username = config.auth.username || '';
2488
- var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
2489
- requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
2490
- }
2491
- var fullPath = buildFullPath(config.baseURL, config.url);
2492
- request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
2875
+ request.open(_config.method.toUpperCase(), _config.url, true);
2493
2876
 
2494
2877
  // Set the request timeout in MS
2495
- request.timeout = config.timeout;
2878
+ request.timeout = _config.timeout;
2496
2879
  function onloadend() {
2497
2880
  if (!request) {
2498
2881
  return;
@@ -2547,7 +2930,7 @@
2547
2930
  if (!request) {
2548
2931
  return;
2549
2932
  }
2550
- reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
2933
+ reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, _config, request));
2551
2934
 
2552
2935
  // Clean up request
2553
2936
  request = null;
@@ -2557,7 +2940,7 @@
2557
2940
  request.onerror = function handleError() {
2558
2941
  // Real errors are hidden from us by the browser
2559
2942
  // onerror should only fire if it's a network error
2560
- reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
2943
+ reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, _config, request));
2561
2944
 
2562
2945
  // Clean up request
2563
2946
  request = null;
@@ -2565,31 +2948,17 @@
2565
2948
 
2566
2949
  // Handle timeout
2567
2950
  request.ontimeout = function handleTimeout() {
2568
- var timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
2569
- var transitional = config.transitional || transitionalDefaults;
2570
- if (config.timeoutErrorMessage) {
2571
- timeoutErrorMessage = config.timeoutErrorMessage;
2951
+ var timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
2952
+ var transitional = _config.transitional || transitionalDefaults;
2953
+ if (_config.timeoutErrorMessage) {
2954
+ timeoutErrorMessage = _config.timeoutErrorMessage;
2572
2955
  }
2573
- reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, request));
2956
+ reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, _config, request));
2574
2957
 
2575
2958
  // Clean up request
2576
2959
  request = null;
2577
2960
  };
2578
2961
 
2579
- // Add xsrf header
2580
- // This is only done if running in a standard browser environment.
2581
- // Specifically not if we're in a web worker, or react-native.
2582
- if (platform.hasStandardBrowserEnv) {
2583
- withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
2584
- if (withXSRFToken || withXSRFToken !== false && isURLSameOrigin(fullPath)) {
2585
- // Add xsrf header
2586
- var xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2587
- if (xsrfValue) {
2588
- requestHeaders.set(config.xsrfHeaderName, xsrfValue);
2589
- }
2590
- }
2591
- }
2592
-
2593
2962
  // Remove Content-Type if data is undefined
2594
2963
  requestData === undefined && requestHeaders.setContentType(null);
2595
2964
 
@@ -2601,25 +2970,25 @@
2601
2970
  }
2602
2971
 
2603
2972
  // Add withCredentials to request if needed
2604
- if (!utils$1.isUndefined(config.withCredentials)) {
2605
- request.withCredentials = !!config.withCredentials;
2973
+ if (!utils$1.isUndefined(_config.withCredentials)) {
2974
+ request.withCredentials = !!_config.withCredentials;
2606
2975
  }
2607
2976
 
2608
2977
  // Add responseType to request if needed
2609
2978
  if (responseType && responseType !== 'json') {
2610
- request.responseType = config.responseType;
2979
+ request.responseType = _config.responseType;
2611
2980
  }
2612
2981
 
2613
2982
  // Handle progress if needed
2614
- if (typeof config.onDownloadProgress === 'function') {
2615
- request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
2983
+ if (typeof _config.onDownloadProgress === 'function') {
2984
+ request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
2616
2985
  }
2617
2986
 
2618
2987
  // Not all browsers support upload events
2619
- if (typeof config.onUploadProgress === 'function' && request.upload) {
2620
- request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
2988
+ if (typeof _config.onUploadProgress === 'function' && request.upload) {
2989
+ request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
2621
2990
  }
2622
- if (config.cancelToken || config.signal) {
2991
+ if (_config.cancelToken || _config.signal) {
2623
2992
  // Handle cancellation
2624
2993
  // eslint-disable-next-line func-names
2625
2994
  onCanceled = function onCanceled(cancel) {
@@ -2630,12 +2999,12 @@
2630
2999
  request.abort();
2631
3000
  request = null;
2632
3001
  };
2633
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
2634
- if (config.signal) {
2635
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
3002
+ _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
3003
+ if (_config.signal) {
3004
+ _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
2636
3005
  }
2637
3006
  }
2638
- var protocol = parseProtocol(fullPath);
3007
+ var protocol = parseProtocol(_config.url);
2639
3008
  if (protocol && platform.protocols.indexOf(protocol) === -1) {
2640
3009
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
2641
3010
  return;
@@ -2646,9 +3015,409 @@
2646
3015
  });
2647
3016
  };
2648
3017
 
3018
+ var composeSignals = function composeSignals(signals, timeout) {
3019
+ var controller = new AbortController();
3020
+ var aborted;
3021
+ var onabort = function onabort(cancel) {
3022
+ if (!aborted) {
3023
+ aborted = true;
3024
+ unsubscribe();
3025
+ var err = cancel instanceof Error ? cancel : this.reason;
3026
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
3027
+ }
3028
+ };
3029
+ var timer = timeout && setTimeout(function () {
3030
+ onabort(new AxiosError("timeout ".concat(timeout, " of ms exceeded"), AxiosError.ETIMEDOUT));
3031
+ }, timeout);
3032
+ var unsubscribe = function unsubscribe() {
3033
+ if (signals) {
3034
+ timer && clearTimeout(timer);
3035
+ timer = null;
3036
+ signals.forEach(function (signal) {
3037
+ signal && (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
3038
+ });
3039
+ signals = null;
3040
+ }
3041
+ };
3042
+ signals.forEach(function (signal) {
3043
+ return signal && signal.addEventListener && signal.addEventListener('abort', onabort);
3044
+ });
3045
+ var signal = controller.signal;
3046
+ signal.unsubscribe = unsubscribe;
3047
+ return [signal, function () {
3048
+ timer && clearTimeout(timer);
3049
+ timer = null;
3050
+ }];
3051
+ };
3052
+ var composeSignals$1 = composeSignals;
3053
+
3054
+ var streamChunk = /*#__PURE__*/_regeneratorRuntime().mark(function streamChunk(chunk, chunkSize) {
3055
+ var len, pos, end;
3056
+ return _regeneratorRuntime().wrap(function streamChunk$(_context) {
3057
+ while (1) switch (_context.prev = _context.next) {
3058
+ case 0:
3059
+ len = chunk.byteLength;
3060
+ if (!(!chunkSize || len < chunkSize)) {
3061
+ _context.next = 5;
3062
+ break;
3063
+ }
3064
+ _context.next = 4;
3065
+ return chunk;
3066
+ case 4:
3067
+ return _context.abrupt("return");
3068
+ case 5:
3069
+ pos = 0;
3070
+ case 6:
3071
+ if (!(pos < len)) {
3072
+ _context.next = 13;
3073
+ break;
3074
+ }
3075
+ end = pos + chunkSize;
3076
+ _context.next = 10;
3077
+ return chunk.slice(pos, end);
3078
+ case 10:
3079
+ pos = end;
3080
+ _context.next = 6;
3081
+ break;
3082
+ case 13:
3083
+ case "end":
3084
+ return _context.stop();
3085
+ }
3086
+ }, streamChunk);
3087
+ });
3088
+ var encoder = new TextEncoder();
3089
+ var readBytes = /*#__PURE__*/function () {
3090
+ var _ref = _wrapAsyncGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(iterable, chunkSize) {
3091
+ var _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, chunk;
3092
+ return _regeneratorRuntime().wrap(function _callee$(_context2) {
3093
+ while (1) switch (_context2.prev = _context2.next) {
3094
+ case 0:
3095
+ _iteratorAbruptCompletion = false;
3096
+ _didIteratorError = false;
3097
+ _context2.prev = 2;
3098
+ _iterator = _asyncIterator(iterable);
3099
+ case 4:
3100
+ _context2.next = 6;
3101
+ return _awaitAsyncGenerator(_iterator.next());
3102
+ case 6:
3103
+ if (!(_iteratorAbruptCompletion = !(_step = _context2.sent).done)) {
3104
+ _context2.next = 27;
3105
+ break;
3106
+ }
3107
+ chunk = _step.value;
3108
+ _context2.t0 = _asyncGeneratorDelegate;
3109
+ _context2.t1 = _asyncIterator;
3110
+ _context2.t2 = streamChunk;
3111
+ if (!ArrayBuffer.isView(chunk)) {
3112
+ _context2.next = 15;
3113
+ break;
3114
+ }
3115
+ _context2.t3 = chunk;
3116
+ _context2.next = 18;
3117
+ break;
3118
+ case 15:
3119
+ _context2.next = 17;
3120
+ return _awaitAsyncGenerator(encoder.encode(String(chunk)));
3121
+ case 17:
3122
+ _context2.t3 = _context2.sent;
3123
+ case 18:
3124
+ _context2.t4 = _context2.t3;
3125
+ _context2.t5 = chunkSize;
3126
+ _context2.t6 = (0, _context2.t2)(_context2.t4, _context2.t5);
3127
+ _context2.t7 = (0, _context2.t1)(_context2.t6);
3128
+ _context2.t8 = _awaitAsyncGenerator;
3129
+ return _context2.delegateYield((0, _context2.t0)(_context2.t7, _context2.t8), "t9", 24);
3130
+ case 24:
3131
+ _iteratorAbruptCompletion = false;
3132
+ _context2.next = 4;
3133
+ break;
3134
+ case 27:
3135
+ _context2.next = 33;
3136
+ break;
3137
+ case 29:
3138
+ _context2.prev = 29;
3139
+ _context2.t10 = _context2["catch"](2);
3140
+ _didIteratorError = true;
3141
+ _iteratorError = _context2.t10;
3142
+ case 33:
3143
+ _context2.prev = 33;
3144
+ _context2.prev = 34;
3145
+ if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
3146
+ _context2.next = 38;
3147
+ break;
3148
+ }
3149
+ _context2.next = 38;
3150
+ return _awaitAsyncGenerator(_iterator["return"]());
3151
+ case 38:
3152
+ _context2.prev = 38;
3153
+ if (!_didIteratorError) {
3154
+ _context2.next = 41;
3155
+ break;
3156
+ }
3157
+ throw _iteratorError;
3158
+ case 41:
3159
+ return _context2.finish(38);
3160
+ case 42:
3161
+ return _context2.finish(33);
3162
+ case 43:
3163
+ case "end":
3164
+ return _context2.stop();
3165
+ }
3166
+ }, _callee, null, [[2, 29, 33, 43], [34,, 38, 42]]);
3167
+ }));
3168
+ return function readBytes(_x, _x2) {
3169
+ return _ref.apply(this, arguments);
3170
+ };
3171
+ }();
3172
+ var trackStream = function trackStream(stream, chunkSize, onProgress, onFinish) {
3173
+ var iterator = readBytes(stream, chunkSize);
3174
+ var bytes = 0;
3175
+ return new ReadableStream({
3176
+ type: 'bytes',
3177
+ pull: function pull(controller) {
3178
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
3179
+ var _yield$iterator$next, done, value, len;
3180
+ return _regeneratorRuntime().wrap(function _callee2$(_context3) {
3181
+ while (1) switch (_context3.prev = _context3.next) {
3182
+ case 0:
3183
+ _context3.next = 2;
3184
+ return iterator.next();
3185
+ case 2:
3186
+ _yield$iterator$next = _context3.sent;
3187
+ done = _yield$iterator$next.done;
3188
+ value = _yield$iterator$next.value;
3189
+ if (!done) {
3190
+ _context3.next = 9;
3191
+ break;
3192
+ }
3193
+ controller.close();
3194
+ onFinish();
3195
+ return _context3.abrupt("return");
3196
+ case 9:
3197
+ len = value.byteLength;
3198
+ onProgress && onProgress(bytes += len);
3199
+ controller.enqueue(new Uint8Array(value));
3200
+ case 12:
3201
+ case "end":
3202
+ return _context3.stop();
3203
+ }
3204
+ }, _callee2);
3205
+ }))();
3206
+ },
3207
+ cancel: function cancel(reason) {
3208
+ onFinish(reason);
3209
+ return iterator["return"]();
3210
+ }
3211
+ }, {
3212
+ highWaterMark: 2
3213
+ });
3214
+ };
3215
+
3216
+ var fetchProgressDecorator = function fetchProgressDecorator(total, fn) {
3217
+ var lengthComputable = total != null;
3218
+ return function (loaded) {
3219
+ return setTimeout(function () {
3220
+ return fn({
3221
+ lengthComputable: lengthComputable,
3222
+ total: total,
3223
+ loaded: loaded
3224
+ });
3225
+ });
3226
+ };
3227
+ };
3228
+ var isFetchSupported = typeof fetch !== 'undefined';
3229
+ var supportsRequestStreams = isFetchSupported && function () {
3230
+ var duplexAccessed = false;
3231
+ var hasContentType = new Request(platform.origin, {
3232
+ body: new ReadableStream(),
3233
+ method: 'POST',
3234
+ get duplex() {
3235
+ duplexAccessed = true;
3236
+ return 'half';
3237
+ }
3238
+ }).headers.has('Content-Type');
3239
+ return duplexAccessed && !hasContentType;
3240
+ }();
3241
+ var DEFAULT_CHUNK_SIZE = 64 * 1024;
3242
+ var resolvers = {
3243
+ stream: function stream(res) {
3244
+ return res.body;
3245
+ }
3246
+ };
3247
+ isFetchSupported && ['text', 'arrayBuffer', 'blob', 'formData'].forEach(function (type) {
3248
+ return [resolvers[type] = utils$1.isFunction(Response.prototype[type]) ? function (res) {
3249
+ return res[type]();
3250
+ } : function (_, config) {
3251
+ throw new AxiosError("Response type ".concat(type, " is not supported"), AxiosError.ERR_NOT_SUPPORT, config);
3252
+ }];
3253
+ });
3254
+ var getBodyLength = /*#__PURE__*/function () {
3255
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(body) {
3256
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
3257
+ while (1) switch (_context.prev = _context.next) {
3258
+ case 0:
3259
+ if (!utils$1.isBlob(body)) {
3260
+ _context.next = 2;
3261
+ break;
3262
+ }
3263
+ return _context.abrupt("return", body.size);
3264
+ case 2:
3265
+ if (!utils$1.isSpecCompliantForm(body)) {
3266
+ _context.next = 6;
3267
+ break;
3268
+ }
3269
+ _context.next = 5;
3270
+ return new Request(body).arrayBuffer();
3271
+ case 5:
3272
+ return _context.abrupt("return", _context.sent.byteLength);
3273
+ case 6:
3274
+ if (!utils$1.isArrayBufferView(body)) {
3275
+ _context.next = 8;
3276
+ break;
3277
+ }
3278
+ return _context.abrupt("return", body.byteLength);
3279
+ case 8:
3280
+ if (utils$1.isURLSearchParams(body)) {
3281
+ body = body + '';
3282
+ }
3283
+ if (!utils$1.isString(body)) {
3284
+ _context.next = 13;
3285
+ break;
3286
+ }
3287
+ _context.next = 12;
3288
+ return new TextEncoder().encode(body);
3289
+ case 12:
3290
+ return _context.abrupt("return", _context.sent.byteLength);
3291
+ case 13:
3292
+ case "end":
3293
+ return _context.stop();
3294
+ }
3295
+ }, _callee);
3296
+ }));
3297
+ return function getBodyLength(_x) {
3298
+ return _ref.apply(this, arguments);
3299
+ };
3300
+ }();
3301
+ var resolveBodyLength = /*#__PURE__*/function () {
3302
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(headers, body) {
3303
+ var length;
3304
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
3305
+ while (1) switch (_context2.prev = _context2.next) {
3306
+ case 0:
3307
+ length = utils$1.toFiniteNumber(headers.getContentLength());
3308
+ return _context2.abrupt("return", length == null ? getBodyLength(body) : length);
3309
+ case 2:
3310
+ case "end":
3311
+ return _context2.stop();
3312
+ }
3313
+ }, _callee2);
3314
+ }));
3315
+ return function resolveBodyLength(_x2, _x3) {
3316
+ return _ref2.apply(this, arguments);
3317
+ };
3318
+ }();
3319
+ var fetchAdapter = ( /*#__PURE__*/(function () {
3320
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(config) {
3321
+ var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _ref4, _ref5, composedSignal, stopTimeout, finished, request, onFinish, requestContentLength, _request, contentTypeHeader, response, isStreamResponse, options, responseContentLength, responseData, code;
3322
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
3323
+ while (1) switch (_context3.prev = _context3.next) {
3324
+ case 0:
3325
+ _resolveConfig = resolveConfig(config), url = _resolveConfig.url, method = _resolveConfig.method, data = _resolveConfig.data, signal = _resolveConfig.signal, cancelToken = _resolveConfig.cancelToken, timeout = _resolveConfig.timeout, onDownloadProgress = _resolveConfig.onDownloadProgress, onUploadProgress = _resolveConfig.onUploadProgress, responseType = _resolveConfig.responseType, headers = _resolveConfig.headers, _resolveConfig$withCr = _resolveConfig.withCredentials, withCredentials = _resolveConfig$withCr === void 0 ? 'same-origin' : _resolveConfig$withCr, fetchOptions = _resolveConfig.fetchOptions;
3326
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
3327
+ _ref4 = signal || cancelToken || timeout ? composeSignals$1([signal, cancelToken], timeout) : [], _ref5 = _slicedToArray(_ref4, 2), composedSignal = _ref5[0], stopTimeout = _ref5[1];
3328
+ onFinish = function onFinish() {
3329
+ !finished && setTimeout(function () {
3330
+ composedSignal && composedSignal.unsubscribe();
3331
+ });
3332
+ finished = true;
3333
+ };
3334
+ _context3.prev = 4;
3335
+ if (!(onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head')) {
3336
+ _context3.next = 12;
3337
+ break;
3338
+ }
3339
+ _context3.next = 8;
3340
+ return resolveBodyLength(headers, data);
3341
+ case 8:
3342
+ requestContentLength = _context3.sent;
3343
+ _request = new Request(url, {
3344
+ method: method,
3345
+ body: data,
3346
+ duplex: "half"
3347
+ });
3348
+ if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
3349
+ headers.setContentType(contentTypeHeader);
3350
+ }
3351
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(requestContentLength, progressEventReducer(onUploadProgress)));
3352
+ case 12:
3353
+ if (!utils$1.isString(withCredentials)) {
3354
+ withCredentials = withCredentials ? 'cors' : 'omit';
3355
+ }
3356
+ request = new Request(url, _objectSpread2(_objectSpread2({}, fetchOptions), {}, {
3357
+ signal: composedSignal,
3358
+ method: method,
3359
+ headers: headers.normalize().toJSON(),
3360
+ body: data,
3361
+ duplex: "half",
3362
+ withCredentials: withCredentials
3363
+ }));
3364
+ _context3.next = 16;
3365
+ return fetch(request);
3366
+ case 16:
3367
+ response = _context3.sent;
3368
+ isStreamResponse = responseType === 'stream' || responseType === 'response';
3369
+ if (onDownloadProgress || isStreamResponse) {
3370
+ options = {};
3371
+ Object.getOwnPropertyNames(response).forEach(function (prop) {
3372
+ options[prop] = response[prop];
3373
+ });
3374
+ responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
3375
+ response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(responseContentLength, progressEventReducer(onDownloadProgress, true)), isStreamResponse && onFinish), options);
3376
+ }
3377
+ responseType = responseType || 'text';
3378
+ _context3.next = 22;
3379
+ return resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
3380
+ case 22:
3381
+ responseData = _context3.sent;
3382
+ !isStreamResponse && onFinish();
3383
+ stopTimeout && stopTimeout();
3384
+ _context3.next = 27;
3385
+ return new Promise(function (resolve, reject) {
3386
+ settle(resolve, reject, {
3387
+ data: responseData,
3388
+ headers: AxiosHeaders$1.from(response.headers),
3389
+ status: response.status,
3390
+ statusText: response.statusText,
3391
+ config: config,
3392
+ request: request
3393
+ });
3394
+ });
3395
+ case 27:
3396
+ return _context3.abrupt("return", _context3.sent);
3397
+ case 30:
3398
+ _context3.prev = 30;
3399
+ _context3.t0 = _context3["catch"](4);
3400
+ onFinish();
3401
+ code = _context3.t0.code;
3402
+ if (_context3.t0.name === 'NetworkError') {
3403
+ code = AxiosError.ERR_NETWORK;
3404
+ }
3405
+ throw AxiosError.from(_context3.t0, code, config, request);
3406
+ case 36:
3407
+ case "end":
3408
+ return _context3.stop();
3409
+ }
3410
+ }, _callee3, null, [[4, 30]]);
3411
+ }));
3412
+ return function (_x4) {
3413
+ return _ref3.apply(this, arguments);
3414
+ };
3415
+ })());
3416
+
2649
3417
  var knownAdapters = {
2650
3418
  http: httpAdapter,
2651
- xhr: xhrAdapter
3419
+ xhr: xhrAdapter,
3420
+ fetch: fetchAdapter
2652
3421
  };
2653
3422
  utils$1.forEach(knownAdapters, function (fn, value) {
2654
3423
  if (fn) {
@@ -2762,111 +3531,7 @@
2762
3531
  });
2763
3532
  }
2764
3533
 
2765
- var headersToObject = function headersToObject(thing) {
2766
- return thing instanceof AxiosHeaders$1 ? _objectSpread2({}, thing) : thing;
2767
- };
2768
-
2769
- /**
2770
- * Config-specific merge-function which creates a new config-object
2771
- * by merging two configuration objects together.
2772
- *
2773
- * @param {Object} config1
2774
- * @param {Object} config2
2775
- *
2776
- * @returns {Object} New object resulting from merging config2 to config1
2777
- */
2778
- function mergeConfig(config1, config2) {
2779
- // eslint-disable-next-line no-param-reassign
2780
- config2 = config2 || {};
2781
- var config = {};
2782
- function getMergedValue(target, source, caseless) {
2783
- if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
2784
- return utils$1.merge.call({
2785
- caseless: caseless
2786
- }, target, source);
2787
- } else if (utils$1.isPlainObject(source)) {
2788
- return utils$1.merge({}, source);
2789
- } else if (utils$1.isArray(source)) {
2790
- return source.slice();
2791
- }
2792
- return source;
2793
- }
2794
-
2795
- // eslint-disable-next-line consistent-return
2796
- function mergeDeepProperties(a, b, caseless) {
2797
- if (!utils$1.isUndefined(b)) {
2798
- return getMergedValue(a, b, caseless);
2799
- } else if (!utils$1.isUndefined(a)) {
2800
- return getMergedValue(undefined, a, caseless);
2801
- }
2802
- }
2803
-
2804
- // eslint-disable-next-line consistent-return
2805
- function valueFromConfig2(a, b) {
2806
- if (!utils$1.isUndefined(b)) {
2807
- return getMergedValue(undefined, b);
2808
- }
2809
- }
2810
-
2811
- // eslint-disable-next-line consistent-return
2812
- function defaultToConfig2(a, b) {
2813
- if (!utils$1.isUndefined(b)) {
2814
- return getMergedValue(undefined, b);
2815
- } else if (!utils$1.isUndefined(a)) {
2816
- return getMergedValue(undefined, a);
2817
- }
2818
- }
2819
-
2820
- // eslint-disable-next-line consistent-return
2821
- function mergeDirectKeys(a, b, prop) {
2822
- if (prop in config2) {
2823
- return getMergedValue(a, b);
2824
- } else if (prop in config1) {
2825
- return getMergedValue(undefined, a);
2826
- }
2827
- }
2828
- var mergeMap = {
2829
- url: valueFromConfig2,
2830
- method: valueFromConfig2,
2831
- data: valueFromConfig2,
2832
- baseURL: defaultToConfig2,
2833
- transformRequest: defaultToConfig2,
2834
- transformResponse: defaultToConfig2,
2835
- paramsSerializer: defaultToConfig2,
2836
- timeout: defaultToConfig2,
2837
- timeoutMessage: defaultToConfig2,
2838
- withCredentials: defaultToConfig2,
2839
- withXSRFToken: defaultToConfig2,
2840
- adapter: defaultToConfig2,
2841
- responseType: defaultToConfig2,
2842
- xsrfCookieName: defaultToConfig2,
2843
- xsrfHeaderName: defaultToConfig2,
2844
- onUploadProgress: defaultToConfig2,
2845
- onDownloadProgress: defaultToConfig2,
2846
- decompress: defaultToConfig2,
2847
- maxContentLength: defaultToConfig2,
2848
- maxBodyLength: defaultToConfig2,
2849
- beforeRedirect: defaultToConfig2,
2850
- transport: defaultToConfig2,
2851
- httpAgent: defaultToConfig2,
2852
- httpsAgent: defaultToConfig2,
2853
- cancelToken: defaultToConfig2,
2854
- socketPath: defaultToConfig2,
2855
- responseEncoding: defaultToConfig2,
2856
- validateStatus: mergeDirectKeys,
2857
- headers: function headers(a, b) {
2858
- return mergeDeepProperties(headersToObject(a), headersToObject(b), true);
2859
- }
2860
- };
2861
- utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2862
- var merge = mergeMap[prop] || mergeDeepProperties;
2863
- var configValue = merge(config1[prop], config2[prop], prop);
2864
- utils$1.isUndefined(configValue) && merge !== mergeDirectKeys || (config[prop] = configValue);
2865
- });
2866
- return config;
2867
- }
2868
-
2869
- var VERSION = "1.6.8";
3534
+ var VERSION = "1.7.0-beta.0";
2870
3535
 
2871
3536
  var validators$1 = {};
2872
3537