@xchainjs/xchain-dash 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -354,6 +354,8 @@ const isFormData = (thing) => {
354
354
  */
355
355
  const isURLSearchParams = kindOfTest('URLSearchParams');
356
356
 
357
+ const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
358
+
357
359
  /**
358
360
  * Trim excess whitespace off the beginning and end of a string
359
361
  *
@@ -685,8 +687,9 @@ const reduceDescriptors = (obj, reducer) => {
685
687
  const reducedDescriptors = {};
686
688
 
687
689
  forEach(descriptors, (descriptor, name) => {
688
- if (reducer(descriptor, name, obj) !== false) {
689
- reducedDescriptors[name] = descriptor;
690
+ let ret;
691
+ if ((ret = reducer(descriptor, name, obj)) !== false) {
692
+ reducedDescriptors[name] = ret || descriptor;
690
693
  }
691
694
  });
692
695
 
@@ -741,8 +744,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
741
744
  const noop = () => {};
742
745
 
743
746
  const toFiniteNumber = (value, defaultValue) => {
744
- value = +value;
745
- return Number.isFinite(value) ? value : defaultValue;
747
+ return value != null && Number.isFinite(value = +value) ? value : defaultValue;
746
748
  };
747
749
 
748
750
  const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
@@ -807,7 +809,42 @@ const toJSONObject = (obj) => {
807
809
  return visit(obj, 0);
808
810
  };
809
811
 
810
- var utils$2 = {
812
+ const isAsyncFn = kindOfTest('AsyncFunction');
813
+
814
+ const isThenable = (thing) =>
815
+ thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
816
+
817
+ // original code
818
+ // https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
819
+
820
+ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
821
+ if (setImmediateSupported) {
822
+ return setImmediate;
823
+ }
824
+
825
+ return postMessageSupported ? ((token, callbacks) => {
826
+ _global.addEventListener("message", ({source, data}) => {
827
+ if (source === _global && data === token) {
828
+ callbacks.length && callbacks.shift()();
829
+ }
830
+ }, false);
831
+
832
+ return (cb) => {
833
+ callbacks.push(cb);
834
+ _global.postMessage(token, "*");
835
+ }
836
+ })(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
837
+ })(
838
+ typeof setImmediate === 'function',
839
+ isFunction(_global.postMessage)
840
+ );
841
+
842
+ const asap = typeof queueMicrotask !== 'undefined' ?
843
+ queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
844
+
845
+ // *********************
846
+
847
+ var utils$3 = {
811
848
  isArray,
812
849
  isArrayBuffer,
813
850
  isBuffer,
@@ -818,6 +855,10 @@ var utils$2 = {
818
855
  isBoolean,
819
856
  isObject,
820
857
  isPlainObject,
858
+ isReadableStream,
859
+ isRequest,
860
+ isResponse,
861
+ isHeaders,
821
862
  isUndefined,
822
863
  isDate,
823
864
  isFile,
@@ -856,7 +897,11 @@ var utils$2 = {
856
897
  ALPHABET,
857
898
  generateString,
858
899
  isSpecCompliantForm,
859
- toJSONObject
900
+ toJSONObject,
901
+ isAsyncFn,
902
+ isThenable,
903
+ setImmediate: _setImmediate,
904
+ asap
860
905
  };
861
906
 
862
907
  /**
@@ -887,7 +932,7 @@ function AxiosError(message, code, config, request, response) {
887
932
  response && (this.response = response);
888
933
  }
889
934
 
890
- utils$2.inherits(AxiosError, Error, {
935
+ utils$3.inherits(AxiosError, Error, {
891
936
  toJSON: function toJSON() {
892
937
  return {
893
938
  // Standard
@@ -902,7 +947,7 @@ utils$2.inherits(AxiosError, Error, {
902
947
  columnNumber: this.columnNumber,
903
948
  stack: this.stack,
904
949
  // Axios
905
- config: utils$2.toJSONObject(this.config),
950
+ config: utils$3.toJSONObject(this.config),
906
951
  code: this.code,
907
952
  status: this.response && this.response.status ? this.response.status : null
908
953
  };
@@ -937,7 +982,7 @@ Object.defineProperty(prototype$1, 'isAxiosError', {value: true});
937
982
  AxiosError.from = (error, code, config, request, response, customProps) => {
938
983
  const axiosError = Object.create(prototype$1);
939
984
 
940
- utils$2.toFlatObject(error, axiosError, function filter(obj) {
985
+ utils$3.toFlatObject(error, axiosError, function filter(obj) {
941
986
  return obj !== Error.prototype;
942
987
  }, prop => {
943
988
  return prop !== 'isAxiosError';
@@ -965,7 +1010,7 @@ var httpAdapter = null;
965
1010
  * @returns {boolean}
966
1011
  */
967
1012
  function isVisitable(thing) {
968
- return utils$2.isPlainObject(thing) || utils$2.isArray(thing);
1013
+ return utils$3.isPlainObject(thing) || utils$3.isArray(thing);
969
1014
  }
970
1015
 
971
1016
  /**
@@ -976,7 +1021,7 @@ function isVisitable(thing) {
976
1021
  * @returns {string} the key without the brackets.
977
1022
  */
978
1023
  function removeBrackets(key) {
979
- return utils$2.endsWith(key, '[]') ? key.slice(0, -2) : key;
1024
+ return utils$3.endsWith(key, '[]') ? key.slice(0, -2) : key;
980
1025
  }
981
1026
 
982
1027
  /**
@@ -1005,10 +1050,10 @@ function renderKey(path, key, dots) {
1005
1050
  * @returns {boolean}
1006
1051
  */
1007
1052
  function isFlatArray(arr) {
1008
- return utils$2.isArray(arr) && !arr.some(isVisitable);
1053
+ return utils$3.isArray(arr) && !arr.some(isVisitable);
1009
1054
  }
1010
1055
 
1011
- const predicates = utils$2.toFlatObject(utils$2, {}, null, function filter(prop) {
1056
+ const predicates = utils$3.toFlatObject(utils$3, {}, null, function filter(prop) {
1012
1057
  return /^is[A-Z]/.test(prop);
1013
1058
  });
1014
1059
 
@@ -1036,7 +1081,7 @@ const predicates = utils$2.toFlatObject(utils$2, {}, null, function filter(prop)
1036
1081
  * @returns
1037
1082
  */
1038
1083
  function toFormData(obj, formData, options) {
1039
- if (!utils$2.isObject(obj)) {
1084
+ if (!utils$3.isObject(obj)) {
1040
1085
  throw new TypeError('target must be an object');
1041
1086
  }
1042
1087
 
@@ -1044,13 +1089,13 @@ function toFormData(obj, formData, options) {
1044
1089
  formData = formData || new (FormData)();
1045
1090
 
1046
1091
  // eslint-disable-next-line no-param-reassign
1047
- options = utils$2.toFlatObject(options, {
1092
+ options = utils$3.toFlatObject(options, {
1048
1093
  metaTokens: true,
1049
1094
  dots: false,
1050
1095
  indexes: false
1051
1096
  }, false, function defined(option, source) {
1052
1097
  // eslint-disable-next-line no-eq-null,eqeqeq
1053
- return !utils$2.isUndefined(source[option]);
1098
+ return !utils$3.isUndefined(source[option]);
1054
1099
  });
1055
1100
 
1056
1101
  const metaTokens = options.metaTokens;
@@ -1059,24 +1104,24 @@ function toFormData(obj, formData, options) {
1059
1104
  const dots = options.dots;
1060
1105
  const indexes = options.indexes;
1061
1106
  const _Blob = options.Blob || typeof Blob !== 'undefined' && Blob;
1062
- const useBlob = _Blob && utils$2.isSpecCompliantForm(formData);
1107
+ const useBlob = _Blob && utils$3.isSpecCompliantForm(formData);
1063
1108
 
1064
- if (!utils$2.isFunction(visitor)) {
1109
+ if (!utils$3.isFunction(visitor)) {
1065
1110
  throw new TypeError('visitor must be a function');
1066
1111
  }
1067
1112
 
1068
1113
  function convertValue(value) {
1069
1114
  if (value === null) return '';
1070
1115
 
1071
- if (utils$2.isDate(value)) {
1116
+ if (utils$3.isDate(value)) {
1072
1117
  return value.toISOString();
1073
1118
  }
1074
1119
 
1075
- if (!useBlob && utils$2.isBlob(value)) {
1120
+ if (!useBlob && utils$3.isBlob(value)) {
1076
1121
  throw new AxiosError('Blob is not supported. Use a Buffer instead.');
1077
1122
  }
1078
1123
 
1079
- if (utils$2.isArrayBuffer(value) || utils$2.isTypedArray(value)) {
1124
+ if (utils$3.isArrayBuffer(value) || utils$3.isTypedArray(value)) {
1080
1125
  return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
1081
1126
  }
1082
1127
 
@@ -1097,20 +1142,20 @@ function toFormData(obj, formData, options) {
1097
1142
  let arr = value;
1098
1143
 
1099
1144
  if (value && !path && typeof value === 'object') {
1100
- if (utils$2.endsWith(key, '{}')) {
1145
+ if (utils$3.endsWith(key, '{}')) {
1101
1146
  // eslint-disable-next-line no-param-reassign
1102
1147
  key = metaTokens ? key : key.slice(0, -2);
1103
1148
  // eslint-disable-next-line no-param-reassign
1104
1149
  value = JSON.stringify(value);
1105
1150
  } else if (
1106
- (utils$2.isArray(value) && isFlatArray(value)) ||
1107
- ((utils$2.isFileList(value) || utils$2.endsWith(key, '[]')) && (arr = utils$2.toArray(value))
1151
+ (utils$3.isArray(value) && isFlatArray(value)) ||
1152
+ ((utils$3.isFileList(value) || utils$3.endsWith(key, '[]')) && (arr = utils$3.toArray(value))
1108
1153
  )) {
1109
1154
  // eslint-disable-next-line no-param-reassign
1110
1155
  key = removeBrackets(key);
1111
1156
 
1112
1157
  arr.forEach(function each(el, index) {
1113
- !(utils$2.isUndefined(el) || el === null) && formData.append(
1158
+ !(utils$3.isUndefined(el) || el === null) && formData.append(
1114
1159
  // eslint-disable-next-line no-nested-ternary
1115
1160
  indexes === true ? renderKey([key], index, dots) : (indexes === null ? key : key + '[]'),
1116
1161
  convertValue(el)
@@ -1138,7 +1183,7 @@ function toFormData(obj, formData, options) {
1138
1183
  });
1139
1184
 
1140
1185
  function build(value, path) {
1141
- if (utils$2.isUndefined(value)) return;
1186
+ if (utils$3.isUndefined(value)) return;
1142
1187
 
1143
1188
  if (stack.indexOf(value) !== -1) {
1144
1189
  throw Error('Circular reference detected in ' + path.join('.'));
@@ -1146,9 +1191,9 @@ function toFormData(obj, formData, options) {
1146
1191
 
1147
1192
  stack.push(value);
1148
1193
 
1149
- utils$2.forEach(value, function each(el, key) {
1150
- const result = !(utils$2.isUndefined(el) || el === null) && visitor.call(
1151
- formData, el, utils$2.isString(key) ? key.trim() : key, path, exposedHelpers
1194
+ utils$3.forEach(value, function each(el, key) {
1195
+ const result = !(utils$3.isUndefined(el) || el === null) && visitor.call(
1196
+ formData, el, utils$3.isString(key) ? key.trim() : key, path, exposedHelpers
1152
1197
  );
1153
1198
 
1154
1199
  if (result === true) {
@@ -1159,7 +1204,7 @@ function toFormData(obj, formData, options) {
1159
1204
  stack.pop();
1160
1205
  }
1161
1206
 
1162
- if (!utils$2.isObject(obj)) {
1207
+ if (!utils$3.isObject(obj)) {
1163
1208
  throw new TypeError('data must be an object');
1164
1209
  }
1165
1210
 
@@ -1263,7 +1308,7 @@ function buildURL(url, params, options) {
1263
1308
  if (serializeFn) {
1264
1309
  serializedParams = serializeFn(params, options);
1265
1310
  } else {
1266
- serializedParams = utils$2.isURLSearchParams(params) ?
1311
+ serializedParams = utils$3.isURLSearchParams(params) ?
1267
1312
  params.toString() :
1268
1313
  new AxiosURLSearchParams(params, options).toString(_encode);
1269
1314
  }
@@ -1338,7 +1383,7 @@ class InterceptorManager {
1338
1383
  * @returns {void}
1339
1384
  */
1340
1385
  forEach(fn) {
1341
- utils$2.forEach(this.handlers, function forEachHandler(h) {
1386
+ utils$3.forEach(this.handlers, function forEachHandler(h) {
1342
1387
  if (h !== null) {
1343
1388
  fn(h);
1344
1389
  }
@@ -1360,6 +1405,18 @@ var FormData$1 = typeof FormData !== 'undefined' ? FormData : null;
1360
1405
 
1361
1406
  var Blob$1 = typeof Blob !== 'undefined' ? Blob : null;
1362
1407
 
1408
+ var platform$1 = {
1409
+ isBrowser: true,
1410
+ classes: {
1411
+ URLSearchParams: URLSearchParams$1,
1412
+ FormData: FormData$1,
1413
+ Blob: Blob$1
1414
+ },
1415
+ protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
1416
+ };
1417
+
1418
+ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
1419
+
1363
1420
  /**
1364
1421
  * Determine if we're running in a standard browser environment
1365
1422
  *
@@ -1377,18 +1434,10 @@ var Blob$1 = typeof Blob !== 'undefined' ? Blob : null;
1377
1434
  *
1378
1435
  * @returns {boolean}
1379
1436
  */
1380
- const isStandardBrowserEnv = (() => {
1381
- let product;
1382
- if (typeof navigator !== 'undefined' && (
1383
- (product = navigator.product) === 'ReactNative' ||
1384
- product === 'NativeScript' ||
1385
- product === 'NS')
1386
- ) {
1387
- return false;
1388
- }
1389
-
1390
- return typeof window !== 'undefined' && typeof document !== 'undefined';
1391
- })();
1437
+ const hasStandardBrowserEnv = (
1438
+ (product) => {
1439
+ return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
1440
+ })(typeof navigator !== 'undefined' && navigator.product);
1392
1441
 
1393
1442
  /**
1394
1443
  * Determine if we're running in a standard browser webWorker environment
@@ -1399,7 +1448,7 @@ const isStandardBrowserEnv = (() => {
1399
1448
  * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
1400
1449
  * This leads to a problem when axios post `FormData` in webWorker
1401
1450
  */
1402
- const isStandardBrowserWebWorkerEnv = (() => {
1451
+ const hasStandardBrowserWebWorkerEnv = (() => {
1403
1452
  return (
1404
1453
  typeof WorkerGlobalScope !== 'undefined' &&
1405
1454
  // eslint-disable-next-line no-undef
@@ -1408,23 +1457,25 @@ const isStandardBrowserEnv = (() => {
1408
1457
  );
1409
1458
  })();
1410
1459
 
1460
+ const origin = hasBrowserEnv && window.location.href || 'http://localhost';
1461
+
1462
+ var utils$2 = /*#__PURE__*/Object.freeze({
1463
+ __proto__: null,
1464
+ hasBrowserEnv: hasBrowserEnv,
1465
+ hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1466
+ hasStandardBrowserEnv: hasStandardBrowserEnv,
1467
+ origin: origin
1468
+ });
1411
1469
 
1412
1470
  var platform = {
1413
- isBrowser: true,
1414
- classes: {
1415
- URLSearchParams: URLSearchParams$1,
1416
- FormData: FormData$1,
1417
- Blob: Blob$1
1418
- },
1419
- isStandardBrowserEnv,
1420
- isStandardBrowserWebWorkerEnv,
1421
- protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
1471
+ ...utils$2,
1472
+ ...platform$1
1422
1473
  };
1423
1474
 
1424
1475
  function toURLEncodedForm(data, options) {
1425
1476
  return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
1426
1477
  visitor: function(value, key, path, helpers) {
1427
- if (platform.isNode && utils$2.isBuffer(value)) {
1478
+ if (platform.isNode && utils$3.isBuffer(value)) {
1428
1479
  this.append(key, value.toString('base64'));
1429
1480
  return false;
1430
1481
  }
@@ -1446,7 +1497,7 @@ function parsePropPath(name) {
1446
1497
  // foo.x.y.z
1447
1498
  // foo-x-y-z
1448
1499
  // foo x y z
1449
- return utils$2.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
1500
+ return utils$3.matchAll(/\w+|\[(\w*)]/g, name).map(match => {
1450
1501
  return match[0] === '[]' ? '' : match[1] || match[0];
1451
1502
  });
1452
1503
  }
@@ -1481,12 +1532,15 @@ function arrayToObject(arr) {
1481
1532
  function formDataToJSON(formData) {
1482
1533
  function buildPath(path, value, target, index) {
1483
1534
  let name = path[index++];
1535
+
1536
+ if (name === '__proto__') return true;
1537
+
1484
1538
  const isNumericKey = Number.isFinite(+name);
1485
1539
  const isLast = index >= path.length;
1486
- name = !name && utils$2.isArray(target) ? target.length : name;
1540
+ name = !name && utils$3.isArray(target) ? target.length : name;
1487
1541
 
1488
1542
  if (isLast) {
1489
- if (utils$2.hasOwnProp(target, name)) {
1543
+ if (utils$3.hasOwnProp(target, name)) {
1490
1544
  target[name] = [target[name], value];
1491
1545
  } else {
1492
1546
  target[name] = value;
@@ -1495,23 +1549,23 @@ function formDataToJSON(formData) {
1495
1549
  return !isNumericKey;
1496
1550
  }
1497
1551
 
1498
- if (!target[name] || !utils$2.isObject(target[name])) {
1552
+ if (!target[name] || !utils$3.isObject(target[name])) {
1499
1553
  target[name] = [];
1500
1554
  }
1501
1555
 
1502
1556
  const result = buildPath(path, value, target[name], index);
1503
1557
 
1504
- if (result && utils$2.isArray(target[name])) {
1558
+ if (result && utils$3.isArray(target[name])) {
1505
1559
  target[name] = arrayToObject(target[name]);
1506
1560
  }
1507
1561
 
1508
1562
  return !isNumericKey;
1509
1563
  }
1510
1564
 
1511
- if (utils$2.isFormData(formData) && utils$2.isFunction(formData.entries)) {
1565
+ if (utils$3.isFormData(formData) && utils$3.isFunction(formData.entries)) {
1512
1566
  const obj = {};
1513
1567
 
1514
- utils$2.forEachEntry(formData, (name, value) => {
1568
+ utils$3.forEachEntry(formData, (name, value) => {
1515
1569
  buildPath(parsePropPath(name), value, obj, 0);
1516
1570
  });
1517
1571
 
@@ -1521,10 +1575,6 @@ function formDataToJSON(formData) {
1521
1575
  return null;
1522
1576
  }
1523
1577
 
1524
- const DEFAULT_CONTENT_TYPE = {
1525
- 'Content-Type': undefined
1526
- };
1527
-
1528
1578
  /**
1529
1579
  * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1530
1580
  * of the input
@@ -1536,10 +1586,10 @@ const DEFAULT_CONTENT_TYPE = {
1536
1586
  * @returns {string} A stringified version of the rawValue.
1537
1587
  */
1538
1588
  function stringifySafely(rawValue, parser, encoder) {
1539
- if (utils$2.isString(rawValue)) {
1589
+ if (utils$3.isString(rawValue)) {
1540
1590
  try {
1541
1591
  (parser || JSON.parse)(rawValue);
1542
- return utils$2.trim(rawValue);
1592
+ return utils$3.trim(rawValue);
1543
1593
  } catch (e) {
1544
1594
  if (e.name !== 'SyntaxError') {
1545
1595
  throw e;
@@ -1554,38 +1604,36 @@ const defaults = {
1554
1604
 
1555
1605
  transitional: transitionalDefaults,
1556
1606
 
1557
- adapter: ['xhr', 'http'],
1607
+ adapter: ['xhr', 'http', 'fetch'],
1558
1608
 
1559
1609
  transformRequest: [function transformRequest(data, headers) {
1560
1610
  const contentType = headers.getContentType() || '';
1561
1611
  const hasJSONContentType = contentType.indexOf('application/json') > -1;
1562
- const isObjectPayload = utils$2.isObject(data);
1612
+ const isObjectPayload = utils$3.isObject(data);
1563
1613
 
1564
- if (isObjectPayload && utils$2.isHTMLForm(data)) {
1614
+ if (isObjectPayload && utils$3.isHTMLForm(data)) {
1565
1615
  data = new FormData(data);
1566
1616
  }
1567
1617
 
1568
- const isFormData = utils$2.isFormData(data);
1618
+ const isFormData = utils$3.isFormData(data);
1569
1619
 
1570
1620
  if (isFormData) {
1571
- if (!hasJSONContentType) {
1572
- return data;
1573
- }
1574
1621
  return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1575
1622
  }
1576
1623
 
1577
- if (utils$2.isArrayBuffer(data) ||
1578
- utils$2.isBuffer(data) ||
1579
- utils$2.isStream(data) ||
1580
- utils$2.isFile(data) ||
1581
- utils$2.isBlob(data)
1624
+ if (utils$3.isArrayBuffer(data) ||
1625
+ utils$3.isBuffer(data) ||
1626
+ utils$3.isStream(data) ||
1627
+ utils$3.isFile(data) ||
1628
+ utils$3.isBlob(data) ||
1629
+ utils$3.isReadableStream(data)
1582
1630
  ) {
1583
1631
  return data;
1584
1632
  }
1585
- if (utils$2.isArrayBufferView(data)) {
1633
+ if (utils$3.isArrayBufferView(data)) {
1586
1634
  return data.buffer;
1587
1635
  }
1588
- if (utils$2.isURLSearchParams(data)) {
1636
+ if (utils$3.isURLSearchParams(data)) {
1589
1637
  headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1590
1638
  return data.toString();
1591
1639
  }
@@ -1597,7 +1645,7 @@ const defaults = {
1597
1645
  return toURLEncodedForm(data, this.formSerializer).toString();
1598
1646
  }
1599
1647
 
1600
- if ((isFileList = utils$2.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1648
+ if ((isFileList = utils$3.isFileList(data)) || contentType.indexOf('multipart/form-data') > -1) {
1601
1649
  const _FormData = this.env && this.env.FormData;
1602
1650
 
1603
1651
  return toFormData(
@@ -1621,7 +1669,11 @@ const defaults = {
1621
1669
  const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
1622
1670
  const JSONRequested = this.responseType === 'json';
1623
1671
 
1624
- if (data && utils$2.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1672
+ if (utils$3.isResponse(data) || utils$3.isReadableStream(data)) {
1673
+ return data;
1674
+ }
1675
+
1676
+ if (data && utils$3.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
1625
1677
  const silentJSONParsing = transitional && transitional.silentJSONParsing;
1626
1678
  const strictJSONParsing = !silentJSONParsing && JSONRequested;
1627
1679
 
@@ -1663,24 +1715,21 @@ const defaults = {
1663
1715
 
1664
1716
  headers: {
1665
1717
  common: {
1666
- 'Accept': 'application/json, text/plain, */*'
1718
+ 'Accept': 'application/json, text/plain, */*',
1719
+ 'Content-Type': undefined
1667
1720
  }
1668
1721
  }
1669
1722
  };
1670
1723
 
1671
- utils$2.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
1724
+ utils$3.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
1672
1725
  defaults.headers[method] = {};
1673
1726
  });
1674
1727
 
1675
- utils$2.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
1676
- defaults.headers[method] = utils$2.merge(DEFAULT_CONTENT_TYPE);
1677
- });
1678
-
1679
1728
  var defaults$1 = defaults;
1680
1729
 
1681
1730
  // RawAxiosHeaders whose duplicates are ignored by node
1682
1731
  // c.f. https://nodejs.org/api/http.html#http_message_headers
1683
- const ignoreDuplicateOf = utils$2.toObjectSet([
1732
+ const ignoreDuplicateOf = utils$3.toObjectSet([
1684
1733
  'age', 'authorization', 'content-length', 'content-type', 'etag',
1685
1734
  'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
1686
1735
  'last-modified', 'location', 'max-forwards', 'proxy-authorization',
@@ -1741,7 +1790,7 @@ function normalizeValue(value) {
1741
1790
  return value;
1742
1791
  }
1743
1792
 
1744
- return utils$2.isArray(value) ? value.map(normalizeValue) : String(value);
1793
+ return utils$3.isArray(value) ? value.map(normalizeValue) : String(value);
1745
1794
  }
1746
1795
 
1747
1796
  function parseTokens(str) {
@@ -1759,7 +1808,7 @@ function parseTokens(str) {
1759
1808
  const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
1760
1809
 
1761
1810
  function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
1762
- if (utils$2.isFunction(filter)) {
1811
+ if (utils$3.isFunction(filter)) {
1763
1812
  return filter.call(this, value, header);
1764
1813
  }
1765
1814
 
@@ -1767,13 +1816,13 @@ function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
1767
1816
  value = header;
1768
1817
  }
1769
1818
 
1770
- if (!utils$2.isString(value)) return;
1819
+ if (!utils$3.isString(value)) return;
1771
1820
 
1772
- if (utils$2.isString(filter)) {
1821
+ if (utils$3.isString(filter)) {
1773
1822
  return value.indexOf(filter) !== -1;
1774
1823
  }
1775
1824
 
1776
- if (utils$2.isRegExp(filter)) {
1825
+ if (utils$3.isRegExp(filter)) {
1777
1826
  return filter.test(value);
1778
1827
  }
1779
1828
  }
@@ -1786,7 +1835,7 @@ function formatHeader(header) {
1786
1835
  }
1787
1836
 
1788
1837
  function buildAccessors(obj, header) {
1789
- const accessorName = utils$2.toCamelCase(' ' + header);
1838
+ const accessorName = utils$3.toCamelCase(' ' + header);
1790
1839
 
1791
1840
  ['get', 'set', 'has'].forEach(methodName => {
1792
1841
  Object.defineProperty(obj, methodName + accessorName, {
@@ -1813,7 +1862,7 @@ class AxiosHeaders {
1813
1862
  throw new Error('header name must be a non-empty string');
1814
1863
  }
1815
1864
 
1816
- const key = utils$2.findKey(self, lHeader);
1865
+ const key = utils$3.findKey(self, lHeader);
1817
1866
 
1818
1867
  if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
1819
1868
  self[key || _header] = normalizeValue(_value);
@@ -1821,12 +1870,16 @@ class AxiosHeaders {
1821
1870
  }
1822
1871
 
1823
1872
  const setHeaders = (headers, _rewrite) =>
1824
- utils$2.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
1873
+ utils$3.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
1825
1874
 
1826
- if (utils$2.isPlainObject(header) || header instanceof this.constructor) {
1875
+ if (utils$3.isPlainObject(header) || header instanceof this.constructor) {
1827
1876
  setHeaders(header, valueOrRewrite);
1828
- } else if(utils$2.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1877
+ } else if(utils$3.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1829
1878
  setHeaders(parseHeaders(header), valueOrRewrite);
1879
+ } else if (utils$3.isHeaders(header)) {
1880
+ for (const [key, value] of header.entries()) {
1881
+ setHeader(value, key, rewrite);
1882
+ }
1830
1883
  } else {
1831
1884
  header != null && setHeader(valueOrRewrite, header, rewrite);
1832
1885
  }
@@ -1838,7 +1891,7 @@ class AxiosHeaders {
1838
1891
  header = normalizeHeader(header);
1839
1892
 
1840
1893
  if (header) {
1841
- const key = utils$2.findKey(this, header);
1894
+ const key = utils$3.findKey(this, header);
1842
1895
 
1843
1896
  if (key) {
1844
1897
  const value = this[key];
@@ -1851,11 +1904,11 @@ class AxiosHeaders {
1851
1904
  return parseTokens(value);
1852
1905
  }
1853
1906
 
1854
- if (utils$2.isFunction(parser)) {
1907
+ if (utils$3.isFunction(parser)) {
1855
1908
  return parser.call(this, value, key);
1856
1909
  }
1857
1910
 
1858
- if (utils$2.isRegExp(parser)) {
1911
+ if (utils$3.isRegExp(parser)) {
1859
1912
  return parser.exec(value);
1860
1913
  }
1861
1914
 
@@ -1868,7 +1921,7 @@ class AxiosHeaders {
1868
1921
  header = normalizeHeader(header);
1869
1922
 
1870
1923
  if (header) {
1871
- const key = utils$2.findKey(this, header);
1924
+ const key = utils$3.findKey(this, header);
1872
1925
 
1873
1926
  return !!(key && this[key] !== undefined && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
1874
1927
  }
@@ -1884,7 +1937,7 @@ class AxiosHeaders {
1884
1937
  _header = normalizeHeader(_header);
1885
1938
 
1886
1939
  if (_header) {
1887
- const key = utils$2.findKey(self, _header);
1940
+ const key = utils$3.findKey(self, _header);
1888
1941
 
1889
1942
  if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1890
1943
  delete self[key];
@@ -1894,7 +1947,7 @@ class AxiosHeaders {
1894
1947
  }
1895
1948
  }
1896
1949
 
1897
- if (utils$2.isArray(header)) {
1950
+ if (utils$3.isArray(header)) {
1898
1951
  header.forEach(deleteHeader);
1899
1952
  } else {
1900
1953
  deleteHeader(header);
@@ -1923,8 +1976,8 @@ class AxiosHeaders {
1923
1976
  const self = this;
1924
1977
  const headers = {};
1925
1978
 
1926
- utils$2.forEach(this, (value, header) => {
1927
- const key = utils$2.findKey(headers, header);
1979
+ utils$3.forEach(this, (value, header) => {
1980
+ const key = utils$3.findKey(headers, header);
1928
1981
 
1929
1982
  if (key) {
1930
1983
  self[key] = normalizeValue(value);
@@ -1953,8 +2006,8 @@ class AxiosHeaders {
1953
2006
  toJSON(asStrings) {
1954
2007
  const obj = Object.create(null);
1955
2008
 
1956
- utils$2.forEach(this, (value, header) => {
1957
- value != null && value !== false && (obj[header] = asStrings && utils$2.isArray(value) ? value.join(', ') : value);
2009
+ utils$3.forEach(this, (value, header) => {
2010
+ value != null && value !== false && (obj[header] = asStrings && utils$3.isArray(value) ? value.join(', ') : value);
1958
2011
  });
1959
2012
 
1960
2013
  return obj;
@@ -2001,7 +2054,7 @@ class AxiosHeaders {
2001
2054
  }
2002
2055
  }
2003
2056
 
2004
- utils$2.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
2057
+ utils$3.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
2005
2058
 
2006
2059
  return this;
2007
2060
  }
@@ -2009,8 +2062,18 @@ class AxiosHeaders {
2009
2062
 
2010
2063
  AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
2011
2064
 
2012
- utils$2.freezeMethods(AxiosHeaders.prototype);
2013
- utils$2.freezeMethods(AxiosHeaders);
2065
+ // reserved names hotfix
2066
+ utils$3.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
2067
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
2068
+ return {
2069
+ get: () => value,
2070
+ set(headerValue) {
2071
+ this[mapped] = headerValue;
2072
+ }
2073
+ }
2074
+ });
2075
+
2076
+ utils$3.freezeMethods(AxiosHeaders);
2014
2077
 
2015
2078
  var AxiosHeaders$1 = AxiosHeaders;
2016
2079
 
@@ -2028,7 +2091,7 @@ function transformData(fns, response) {
2028
2091
  const headers = AxiosHeaders$1.from(context.headers);
2029
2092
  let data = context.data;
2030
2093
 
2031
- utils$2.forEach(fns, function transform(fn) {
2094
+ utils$3.forEach(fns, function transform(fn) {
2032
2095
  data = fn.call(config, data, headers.normalize(), response ? response.status : undefined);
2033
2096
  });
2034
2097
 
@@ -2056,7 +2119,7 @@ function CanceledError(message, config, request) {
2056
2119
  this.name = 'CanceledError';
2057
2120
  }
2058
2121
 
2059
- utils$2.inherits(CanceledError, AxiosError, {
2122
+ utils$3.inherits(CanceledError, AxiosError, {
2060
2123
  __CANCEL__: true
2061
2124
  });
2062
2125
 
@@ -2084,100 +2147,148 @@ function settle(resolve, reject, response) {
2084
2147
  }
2085
2148
  }
2086
2149
 
2087
- var cookies = platform.isStandardBrowserEnv ?
2150
+ function parseProtocol(url) {
2151
+ const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2152
+ return match && match[1] || '';
2153
+ }
2088
2154
 
2089
- // Standard browser envs support document.cookie
2090
- (function standardBrowserEnv() {
2091
- return {
2092
- write: function write(name, value, expires, path, domain, secure) {
2093
- const cookie = [];
2094
- cookie.push(name + '=' + encodeURIComponent(value));
2155
+ /**
2156
+ * Calculate data maxRate
2157
+ * @param {Number} [samplesCount= 10]
2158
+ * @param {Number} [min= 1000]
2159
+ * @returns {Function}
2160
+ */
2161
+ function speedometer(samplesCount, min) {
2162
+ samplesCount = samplesCount || 10;
2163
+ const bytes = new Array(samplesCount);
2164
+ const timestamps = new Array(samplesCount);
2165
+ let head = 0;
2166
+ let tail = 0;
2167
+ let firstSampleTS;
2095
2168
 
2096
- if (utils$2.isNumber(expires)) {
2097
- cookie.push('expires=' + new Date(expires).toGMTString());
2098
- }
2169
+ min = min !== undefined ? min : 1000;
2099
2170
 
2100
- if (utils$2.isString(path)) {
2101
- cookie.push('path=' + path);
2102
- }
2171
+ return function push(chunkLength) {
2172
+ const now = Date.now();
2103
2173
 
2104
- if (utils$2.isString(domain)) {
2105
- cookie.push('domain=' + domain);
2106
- }
2174
+ const startedAt = timestamps[tail];
2107
2175
 
2108
- if (secure === true) {
2109
- cookie.push('secure');
2110
- }
2176
+ if (!firstSampleTS) {
2177
+ firstSampleTS = now;
2178
+ }
2111
2179
 
2112
- document.cookie = cookie.join('; ');
2113
- },
2180
+ bytes[head] = chunkLength;
2181
+ timestamps[head] = now;
2114
2182
 
2115
- read: function read(name) {
2116
- const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2117
- return (match ? decodeURIComponent(match[3]) : null);
2118
- },
2183
+ let i = tail;
2184
+ let bytesCount = 0;
2119
2185
 
2120
- remove: function remove(name) {
2121
- this.write(name, '', Date.now() - 86400000);
2122
- }
2123
- };
2124
- })() :
2186
+ while (i !== head) {
2187
+ bytesCount += bytes[i++];
2188
+ i = i % samplesCount;
2189
+ }
2125
2190
 
2126
- // Non standard browser env (web workers, react-native) lack needed support.
2127
- (function nonStandardBrowserEnv() {
2128
- return {
2129
- write: function write() {},
2130
- read: function read() { return null; },
2131
- remove: function remove() {}
2132
- };
2133
- })();
2191
+ head = (head + 1) % samplesCount;
2134
2192
 
2135
- /**
2136
- * Determines whether the specified URL is absolute
2137
- *
2138
- * @param {string} url The URL to test
2139
- *
2140
- * @returns {boolean} True if the specified URL is absolute, otherwise false
2141
- */
2142
- function isAbsoluteURL(url) {
2143
- // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
2144
- // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
2145
- // by any combination of letters, digits, plus, period, or hyphen.
2146
- return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
2147
- }
2193
+ if (head === tail) {
2194
+ tail = (tail + 1) % samplesCount;
2195
+ }
2148
2196
 
2149
- /**
2150
- * Creates a new URL by combining the specified URLs
2151
- *
2152
- * @param {string} baseURL The base URL
2153
- * @param {string} relativeURL The relative URL
2154
- *
2155
- * @returns {string} The combined URL
2156
- */
2157
- function combineURLs(baseURL, relativeURL) {
2158
- return relativeURL
2159
- ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
2160
- : baseURL;
2197
+ if (now - firstSampleTS < min) {
2198
+ return;
2199
+ }
2200
+
2201
+ const passed = startedAt && now - startedAt;
2202
+
2203
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2204
+ };
2161
2205
  }
2162
2206
 
2163
2207
  /**
2164
- * Creates a new URL by combining the baseURL with the requestedURL,
2165
- * only when the requestedURL is not already an absolute URL.
2166
- * If the requestURL is absolute, this function returns the requestedURL untouched.
2167
- *
2168
- * @param {string} baseURL The base URL
2169
- * @param {string} requestedURL Absolute or relative URL to combine
2170
- *
2171
- * @returns {string} The combined full path
2208
+ * Throttle decorator
2209
+ * @param {Function} fn
2210
+ * @param {Number} freq
2211
+ * @return {Function}
2172
2212
  */
2173
- function buildFullPath(baseURL, requestedURL) {
2174
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2175
- return combineURLs(baseURL, requestedURL);
2176
- }
2177
- return requestedURL;
2213
+ function throttle(fn, freq) {
2214
+ let timestamp = 0;
2215
+ let threshold = 1000 / freq;
2216
+ let lastArgs;
2217
+ let timer;
2218
+
2219
+ const invoke = (args, now = Date.now()) => {
2220
+ timestamp = now;
2221
+ lastArgs = null;
2222
+ if (timer) {
2223
+ clearTimeout(timer);
2224
+ timer = null;
2225
+ }
2226
+ fn.apply(null, args);
2227
+ };
2228
+
2229
+ const throttled = (...args) => {
2230
+ const now = Date.now();
2231
+ const passed = now - timestamp;
2232
+ if ( passed >= threshold) {
2233
+ invoke(args, now);
2234
+ } else {
2235
+ lastArgs = args;
2236
+ if (!timer) {
2237
+ timer = setTimeout(() => {
2238
+ timer = null;
2239
+ invoke(lastArgs);
2240
+ }, threshold - passed);
2241
+ }
2242
+ }
2243
+ };
2244
+
2245
+ const flush = () => lastArgs && invoke(lastArgs);
2246
+
2247
+ return [throttled, flush];
2178
2248
  }
2179
2249
 
2180
- var isURLSameOrigin = platform.isStandardBrowserEnv ?
2250
+ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
2251
+ let bytesNotified = 0;
2252
+ const _speedometer = speedometer(50, 250);
2253
+
2254
+ return throttle(e => {
2255
+ const loaded = e.loaded;
2256
+ const total = e.lengthComputable ? e.total : undefined;
2257
+ const progressBytes = loaded - bytesNotified;
2258
+ const rate = _speedometer(progressBytes);
2259
+ const inRange = loaded <= total;
2260
+
2261
+ bytesNotified = loaded;
2262
+
2263
+ const data = {
2264
+ loaded,
2265
+ total,
2266
+ progress: total ? (loaded / total) : undefined,
2267
+ bytes: progressBytes,
2268
+ rate: rate ? rate : undefined,
2269
+ estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2270
+ event: e,
2271
+ lengthComputable: total != null,
2272
+ [isDownloadStream ? 'download' : 'upload']: true
2273
+ };
2274
+
2275
+ listener(data);
2276
+ }, freq);
2277
+ };
2278
+
2279
+ const progressEventDecorator = (total, throttled) => {
2280
+ const lengthComputable = total != null;
2281
+
2282
+ return [(loaded) => throttled[0]({
2283
+ lengthComputable,
2284
+ total,
2285
+ loaded
2286
+ }), throttled[1]];
2287
+ };
2288
+
2289
+ const asyncDecorator = (fn) => (...args) => utils$3.asap(() => fn(...args));
2290
+
2291
+ var isURLSameOrigin = platform.hasStandardBrowserEnv ?
2181
2292
 
2182
2293
  // Standard browser envs have full support of the APIs needed to test
2183
2294
  // whether the request URL is of the same origin as current location.
@@ -2187,7 +2298,7 @@ var isURLSameOrigin = platform.isStandardBrowserEnv ?
2187
2298
  let originURL;
2188
2299
 
2189
2300
  /**
2190
- * Parse a URL to discover it's components
2301
+ * Parse a URL to discover its components
2191
2302
  *
2192
2303
  * @param {String} url The URL to be parsed
2193
2304
  * @returns {Object}
@@ -2227,7 +2338,7 @@ var isURLSameOrigin = platform.isStandardBrowserEnv ?
2227
2338
  * @returns {boolean} True if URL shares the same origin, otherwise false
2228
2339
  */
2229
2340
  return function isURLSameOrigin(requestURL) {
2230
- const parsed = (utils$2.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2341
+ const parsed = (utils$3.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2231
2342
  return (parsed.protocol === originURL.protocol &&
2232
2343
  parsed.host === originURL.host);
2233
2344
  };
@@ -2240,129 +2351,267 @@ var isURLSameOrigin = platform.isStandardBrowserEnv ?
2240
2351
  };
2241
2352
  })();
2242
2353
 
2243
- function parseProtocol(url) {
2244
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2245
- return match && match[1] || '';
2246
- }
2354
+ var cookies = platform.hasStandardBrowserEnv ?
2247
2355
 
2248
- /**
2249
- * Calculate data maxRate
2250
- * @param {Number} [samplesCount= 10]
2251
- * @param {Number} [min= 1000]
2252
- * @returns {Function}
2253
- */
2254
- function speedometer(samplesCount, min) {
2255
- samplesCount = samplesCount || 10;
2256
- const bytes = new Array(samplesCount);
2257
- const timestamps = new Array(samplesCount);
2258
- let head = 0;
2259
- let tail = 0;
2260
- let firstSampleTS;
2356
+ // Standard browser envs support document.cookie
2357
+ {
2358
+ write(name, value, expires, path, domain, secure) {
2359
+ const cookie = [name + '=' + encodeURIComponent(value)];
2261
2360
 
2262
- min = min !== undefined ? min : 1000;
2361
+ utils$3.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
2263
2362
 
2264
- return function push(chunkLength) {
2265
- const now = Date.now();
2363
+ utils$3.isString(path) && cookie.push('path=' + path);
2266
2364
 
2267
- const startedAt = timestamps[tail];
2365
+ utils$3.isString(domain) && cookie.push('domain=' + domain);
2268
2366
 
2269
- if (!firstSampleTS) {
2270
- firstSampleTS = now;
2271
- }
2367
+ secure === true && cookie.push('secure');
2272
2368
 
2273
- bytes[head] = chunkLength;
2274
- timestamps[head] = now;
2369
+ document.cookie = cookie.join('; ');
2370
+ },
2275
2371
 
2276
- let i = tail;
2277
- let bytesCount = 0;
2372
+ read(name) {
2373
+ const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
2374
+ return (match ? decodeURIComponent(match[3]) : null);
2375
+ },
2278
2376
 
2279
- while (i !== head) {
2280
- bytesCount += bytes[i++];
2281
- i = i % samplesCount;
2377
+ remove(name) {
2378
+ this.write(name, '', Date.now() - 86400000);
2282
2379
  }
2380
+ }
2283
2381
 
2284
- head = (head + 1) % samplesCount;
2285
-
2286
- if (head === tail) {
2287
- tail = (tail + 1) % samplesCount;
2288
- }
2382
+ :
2289
2383
 
2290
- if (now - firstSampleTS < min) {
2291
- return;
2292
- }
2384
+ // Non-standard browser env (web workers, react-native) lack needed support.
2385
+ {
2386
+ write() {},
2387
+ read() {
2388
+ return null;
2389
+ },
2390
+ remove() {}
2391
+ };
2293
2392
 
2294
- const passed = startedAt && now - startedAt;
2393
+ /**
2394
+ * Determines whether the specified URL is absolute
2395
+ *
2396
+ * @param {string} url The URL to test
2397
+ *
2398
+ * @returns {boolean} True if the specified URL is absolute, otherwise false
2399
+ */
2400
+ function isAbsoluteURL(url) {
2401
+ // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
2402
+ // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
2403
+ // by any combination of letters, digits, plus, period, or hyphen.
2404
+ return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
2405
+ }
2295
2406
 
2296
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2297
- };
2407
+ /**
2408
+ * Creates a new URL by combining the specified URLs
2409
+ *
2410
+ * @param {string} baseURL The base URL
2411
+ * @param {string} relativeURL The relative URL
2412
+ *
2413
+ * @returns {string} The combined URL
2414
+ */
2415
+ function combineURLs(baseURL, relativeURL) {
2416
+ return relativeURL
2417
+ ? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
2418
+ : baseURL;
2298
2419
  }
2299
2420
 
2300
- function progressEventReducer(listener, isDownloadStream) {
2301
- let bytesNotified = 0;
2302
- const _speedometer = speedometer(50, 250);
2421
+ /**
2422
+ * Creates a new URL by combining the baseURL with the requestedURL,
2423
+ * only when the requestedURL is not already an absolute URL.
2424
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
2425
+ *
2426
+ * @param {string} baseURL The base URL
2427
+ * @param {string} requestedURL Absolute or relative URL to combine
2428
+ *
2429
+ * @returns {string} The combined full path
2430
+ */
2431
+ function buildFullPath(baseURL, requestedURL) {
2432
+ if (baseURL && !isAbsoluteURL(requestedURL)) {
2433
+ return combineURLs(baseURL, requestedURL);
2434
+ }
2435
+ return requestedURL;
2436
+ }
2303
2437
 
2304
- return e => {
2305
- const loaded = e.loaded;
2306
- const total = e.lengthComputable ? e.total : undefined;
2307
- const progressBytes = loaded - bytesNotified;
2308
- const rate = _speedometer(progressBytes);
2309
- const inRange = loaded <= total;
2438
+ const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
2310
2439
 
2311
- bytesNotified = loaded;
2440
+ /**
2441
+ * Config-specific merge-function which creates a new config-object
2442
+ * by merging two configuration objects together.
2443
+ *
2444
+ * @param {Object} config1
2445
+ * @param {Object} config2
2446
+ *
2447
+ * @returns {Object} New object resulting from merging config2 to config1
2448
+ */
2449
+ function mergeConfig(config1, config2) {
2450
+ // eslint-disable-next-line no-param-reassign
2451
+ config2 = config2 || {};
2452
+ const config = {};
2312
2453
 
2313
- const data = {
2314
- loaded,
2315
- total,
2316
- progress: total ? (loaded / total) : undefined,
2317
- bytes: progressBytes,
2318
- rate: rate ? rate : undefined,
2319
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2320
- event: e
2321
- };
2454
+ function getMergedValue(target, source, caseless) {
2455
+ if (utils$3.isPlainObject(target) && utils$3.isPlainObject(source)) {
2456
+ return utils$3.merge.call({caseless}, target, source);
2457
+ } else if (utils$3.isPlainObject(source)) {
2458
+ return utils$3.merge({}, source);
2459
+ } else if (utils$3.isArray(source)) {
2460
+ return source.slice();
2461
+ }
2462
+ return source;
2463
+ }
2322
2464
 
2323
- data[isDownloadStream ? 'download' : 'upload'] = true;
2465
+ // eslint-disable-next-line consistent-return
2466
+ function mergeDeepProperties(a, b, caseless) {
2467
+ if (!utils$3.isUndefined(b)) {
2468
+ return getMergedValue(a, b, caseless);
2469
+ } else if (!utils$3.isUndefined(a)) {
2470
+ return getMergedValue(undefined, a, caseless);
2471
+ }
2472
+ }
2324
2473
 
2325
- listener(data);
2474
+ // eslint-disable-next-line consistent-return
2475
+ function valueFromConfig2(a, b) {
2476
+ if (!utils$3.isUndefined(b)) {
2477
+ return getMergedValue(undefined, b);
2478
+ }
2479
+ }
2480
+
2481
+ // eslint-disable-next-line consistent-return
2482
+ function defaultToConfig2(a, b) {
2483
+ if (!utils$3.isUndefined(b)) {
2484
+ return getMergedValue(undefined, b);
2485
+ } else if (!utils$3.isUndefined(a)) {
2486
+ return getMergedValue(undefined, a);
2487
+ }
2488
+ }
2489
+
2490
+ // eslint-disable-next-line consistent-return
2491
+ function mergeDirectKeys(a, b, prop) {
2492
+ if (prop in config2) {
2493
+ return getMergedValue(a, b);
2494
+ } else if (prop in config1) {
2495
+ return getMergedValue(undefined, a);
2496
+ }
2497
+ }
2498
+
2499
+ const mergeMap = {
2500
+ url: valueFromConfig2,
2501
+ method: valueFromConfig2,
2502
+ data: valueFromConfig2,
2503
+ baseURL: defaultToConfig2,
2504
+ transformRequest: defaultToConfig2,
2505
+ transformResponse: defaultToConfig2,
2506
+ paramsSerializer: defaultToConfig2,
2507
+ timeout: defaultToConfig2,
2508
+ timeoutMessage: defaultToConfig2,
2509
+ withCredentials: defaultToConfig2,
2510
+ withXSRFToken: defaultToConfig2,
2511
+ adapter: defaultToConfig2,
2512
+ responseType: defaultToConfig2,
2513
+ xsrfCookieName: defaultToConfig2,
2514
+ xsrfHeaderName: defaultToConfig2,
2515
+ onUploadProgress: defaultToConfig2,
2516
+ onDownloadProgress: defaultToConfig2,
2517
+ decompress: defaultToConfig2,
2518
+ maxContentLength: defaultToConfig2,
2519
+ maxBodyLength: defaultToConfig2,
2520
+ beforeRedirect: defaultToConfig2,
2521
+ transport: defaultToConfig2,
2522
+ httpAgent: defaultToConfig2,
2523
+ httpsAgent: defaultToConfig2,
2524
+ cancelToken: defaultToConfig2,
2525
+ socketPath: defaultToConfig2,
2526
+ responseEncoding: defaultToConfig2,
2527
+ validateStatus: mergeDirectKeys,
2528
+ headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2326
2529
  };
2530
+
2531
+ utils$3.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
2532
+ const merge = mergeMap[prop] || mergeDeepProperties;
2533
+ const configValue = merge(config1[prop], config2[prop], prop);
2534
+ (utils$3.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2535
+ });
2536
+
2537
+ return config;
2327
2538
  }
2328
2539
 
2540
+ var resolveConfig = (config) => {
2541
+ const newConfig = mergeConfig({}, config);
2542
+
2543
+ let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
2544
+
2545
+ newConfig.headers = headers = AxiosHeaders$1.from(headers);
2546
+
2547
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2548
+
2549
+ // HTTP basic authentication
2550
+ if (auth) {
2551
+ headers.set('Authorization', 'Basic ' +
2552
+ btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
2553
+ );
2554
+ }
2555
+
2556
+ let contentType;
2557
+
2558
+ if (utils$3.isFormData(data)) {
2559
+ if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
2560
+ headers.setContentType(undefined); // Let the browser set it
2561
+ } else if ((contentType = headers.getContentType()) !== false) {
2562
+ // fix semicolon duplication issue for ReactNative FormData implementation
2563
+ const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
2564
+ headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
2565
+ }
2566
+ }
2567
+
2568
+ // Add xsrf header
2569
+ // This is only done if running in a standard browser environment.
2570
+ // Specifically not if we're in a web worker, or react-native.
2571
+
2572
+ if (platform.hasStandardBrowserEnv) {
2573
+ withXSRFToken && utils$3.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
2574
+
2575
+ if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
2576
+ // Add xsrf header
2577
+ const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
2578
+
2579
+ if (xsrfValue) {
2580
+ headers.set(xsrfHeaderName, xsrfValue);
2581
+ }
2582
+ }
2583
+ }
2584
+
2585
+ return newConfig;
2586
+ };
2587
+
2329
2588
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
2330
2589
 
2331
2590
  var xhrAdapter = isXHRAdapterSupported && function (config) {
2332
2591
  return new Promise(function dispatchXhrRequest(resolve, reject) {
2333
- let requestData = config.data;
2334
- const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
2335
- const responseType = config.responseType;
2592
+ const _config = resolveConfig(config);
2593
+ let requestData = _config.data;
2594
+ const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
2595
+ let {responseType, onUploadProgress, onDownloadProgress} = _config;
2336
2596
  let onCanceled;
2597
+ let uploadThrottled, downloadThrottled;
2598
+ let flushUpload, flushDownload;
2599
+
2337
2600
  function done() {
2338
- if (config.cancelToken) {
2339
- config.cancelToken.unsubscribe(onCanceled);
2340
- }
2601
+ flushUpload && flushUpload(); // flush events
2602
+ flushDownload && flushDownload(); // flush events
2341
2603
 
2342
- if (config.signal) {
2343
- config.signal.removeEventListener('abort', onCanceled);
2344
- }
2345
- }
2604
+ _config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
2346
2605
 
2347
- if (utils$2.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
2348
- requestHeaders.setContentType(false); // Let the browser set it
2606
+ _config.signal && _config.signal.removeEventListener('abort', onCanceled);
2349
2607
  }
2350
2608
 
2351
2609
  let request = new XMLHttpRequest();
2352
2610
 
2353
- // HTTP basic authentication
2354
- if (config.auth) {
2355
- const username = config.auth.username || '';
2356
- const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
2357
- requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
2358
- }
2359
-
2360
- const fullPath = buildFullPath(config.baseURL, config.url);
2361
-
2362
- request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
2611
+ request.open(_config.method.toUpperCase(), _config.url, true);
2363
2612
 
2364
2613
  // Set the request timeout in MS
2365
- request.timeout = config.timeout;
2614
+ request.timeout = _config.timeout;
2366
2615
 
2367
2616
  function onloadend() {
2368
2617
  if (!request) {
@@ -2442,10 +2691,10 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2442
2691
 
2443
2692
  // Handle timeout
2444
2693
  request.ontimeout = function handleTimeout() {
2445
- let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
2446
- const transitional = config.transitional || transitionalDefaults;
2447
- if (config.timeoutErrorMessage) {
2448
- timeoutErrorMessage = config.timeoutErrorMessage;
2694
+ let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
2695
+ const transitional = _config.transitional || transitionalDefaults;
2696
+ if (_config.timeoutErrorMessage) {
2697
+ timeoutErrorMessage = _config.timeoutErrorMessage;
2449
2698
  }
2450
2699
  reject(new AxiosError(
2451
2700
  timeoutErrorMessage,
@@ -2457,50 +2706,42 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2457
2706
  request = null;
2458
2707
  };
2459
2708
 
2460
- // Add xsrf header
2461
- // This is only done if running in a standard browser environment.
2462
- // Specifically not if we're in a web worker, or react-native.
2463
- if (platform.isStandardBrowserEnv) {
2464
- // Add xsrf header
2465
- const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
2466
- && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
2467
-
2468
- if (xsrfValue) {
2469
- requestHeaders.set(config.xsrfHeaderName, xsrfValue);
2470
- }
2471
- }
2472
-
2473
2709
  // Remove Content-Type if data is undefined
2474
2710
  requestData === undefined && requestHeaders.setContentType(null);
2475
2711
 
2476
2712
  // Add headers to the request
2477
2713
  if ('setRequestHeader' in request) {
2478
- utils$2.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
2714
+ utils$3.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
2479
2715
  request.setRequestHeader(key, val);
2480
2716
  });
2481
2717
  }
2482
2718
 
2483
2719
  // Add withCredentials to request if needed
2484
- if (!utils$2.isUndefined(config.withCredentials)) {
2485
- request.withCredentials = !!config.withCredentials;
2720
+ if (!utils$3.isUndefined(_config.withCredentials)) {
2721
+ request.withCredentials = !!_config.withCredentials;
2486
2722
  }
2487
2723
 
2488
2724
  // Add responseType to request if needed
2489
2725
  if (responseType && responseType !== 'json') {
2490
- request.responseType = config.responseType;
2726
+ request.responseType = _config.responseType;
2491
2727
  }
2492
2728
 
2493
2729
  // Handle progress if needed
2494
- if (typeof config.onDownloadProgress === 'function') {
2495
- request.addEventListener('progress', progressEventReducer(config.onDownloadProgress, true));
2730
+ if (onDownloadProgress) {
2731
+ ([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
2732
+ request.addEventListener('progress', downloadThrottled);
2496
2733
  }
2497
2734
 
2498
2735
  // Not all browsers support upload events
2499
- if (typeof config.onUploadProgress === 'function' && request.upload) {
2500
- request.upload.addEventListener('progress', progressEventReducer(config.onUploadProgress));
2736
+ if (onUploadProgress && request.upload) {
2737
+ ([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
2738
+
2739
+ request.upload.addEventListener('progress', uploadThrottled);
2740
+
2741
+ request.upload.addEventListener('loadend', flushUpload);
2501
2742
  }
2502
2743
 
2503
- if (config.cancelToken || config.signal) {
2744
+ if (_config.cancelToken || _config.signal) {
2504
2745
  // Handle cancellation
2505
2746
  // eslint-disable-next-line func-names
2506
2747
  onCanceled = cancel => {
@@ -2512,13 +2753,13 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2512
2753
  request = null;
2513
2754
  };
2514
2755
 
2515
- config.cancelToken && config.cancelToken.subscribe(onCanceled);
2516
- if (config.signal) {
2517
- config.signal.aborted ? onCanceled() : config.signal.addEventListener('abort', onCanceled);
2756
+ _config.cancelToken && _config.cancelToken.subscribe(onCanceled);
2757
+ if (_config.signal) {
2758
+ _config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
2518
2759
  }
2519
2760
  }
2520
2761
 
2521
- const protocol = parseProtocol(fullPath);
2762
+ const protocol = parseProtocol(_config.url);
2522
2763
 
2523
2764
  if (protocol && platform.protocols.indexOf(protocol) === -1) {
2524
2765
  reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
@@ -2531,13 +2772,343 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2531
2772
  });
2532
2773
  };
2533
2774
 
2775
+ const composeSignals = (signals, timeout) => {
2776
+ let controller = new AbortController();
2777
+
2778
+ let aborted;
2779
+
2780
+ const onabort = function (cancel) {
2781
+ if (!aborted) {
2782
+ aborted = true;
2783
+ unsubscribe();
2784
+ const err = cancel instanceof Error ? cancel : this.reason;
2785
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2786
+ }
2787
+ };
2788
+
2789
+ let timer = timeout && setTimeout(() => {
2790
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2791
+ }, timeout);
2792
+
2793
+ const unsubscribe = () => {
2794
+ if (signals) {
2795
+ timer && clearTimeout(timer);
2796
+ timer = null;
2797
+ signals.forEach(signal => {
2798
+ signal &&
2799
+ (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
2800
+ });
2801
+ signals = null;
2802
+ }
2803
+ };
2804
+
2805
+ signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
2806
+
2807
+ const {signal} = controller;
2808
+
2809
+ signal.unsubscribe = unsubscribe;
2810
+
2811
+ return [signal, () => {
2812
+ timer && clearTimeout(timer);
2813
+ timer = null;
2814
+ }];
2815
+ };
2816
+
2817
+ var composeSignals$1 = composeSignals;
2818
+
2819
+ const streamChunk = function* (chunk, chunkSize) {
2820
+ let len = chunk.byteLength;
2821
+
2822
+ if (!chunkSize || len < chunkSize) {
2823
+ yield chunk;
2824
+ return;
2825
+ }
2826
+
2827
+ let pos = 0;
2828
+ let end;
2829
+
2830
+ while (pos < len) {
2831
+ end = pos + chunkSize;
2832
+ yield chunk.slice(pos, end);
2833
+ pos = end;
2834
+ }
2835
+ };
2836
+
2837
+ const readBytes = async function* (iterable, chunkSize, encode) {
2838
+ for await (const chunk of iterable) {
2839
+ yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
2840
+ }
2841
+ };
2842
+
2843
+ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
2844
+ const iterator = readBytes(stream, chunkSize, encode);
2845
+
2846
+ let bytes = 0;
2847
+ let done;
2848
+ let _onFinish = (e) => {
2849
+ if (!done) {
2850
+ done = true;
2851
+ onFinish && onFinish(e);
2852
+ }
2853
+ };
2854
+
2855
+ return new ReadableStream({
2856
+ async pull(controller) {
2857
+ try {
2858
+ const {done, value} = await iterator.next();
2859
+
2860
+ if (done) {
2861
+ _onFinish();
2862
+ controller.close();
2863
+ return;
2864
+ }
2865
+
2866
+ let len = value.byteLength;
2867
+ if (onProgress) {
2868
+ let loadedBytes = bytes += len;
2869
+ onProgress(loadedBytes);
2870
+ }
2871
+ controller.enqueue(new Uint8Array(value));
2872
+ } catch (err) {
2873
+ _onFinish(err);
2874
+ throw err;
2875
+ }
2876
+ },
2877
+ cancel(reason) {
2878
+ _onFinish(reason);
2879
+ return iterator.return();
2880
+ }
2881
+ }, {
2882
+ highWaterMark: 2
2883
+ })
2884
+ };
2885
+
2886
+ const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
2887
+ const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
2888
+
2889
+ // used only inside the fetch adapter
2890
+ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
2891
+ ((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
2892
+ async (str) => new Uint8Array(await new Response(str).arrayBuffer())
2893
+ );
2894
+
2895
+ const test = (fn, ...args) => {
2896
+ try {
2897
+ return !!fn(...args);
2898
+ } catch (e) {
2899
+ return false
2900
+ }
2901
+ };
2902
+
2903
+ const supportsRequestStream = isReadableStreamSupported && test(() => {
2904
+ let duplexAccessed = false;
2905
+
2906
+ const hasContentType = new Request(platform.origin, {
2907
+ body: new ReadableStream(),
2908
+ method: 'POST',
2909
+ get duplex() {
2910
+ duplexAccessed = true;
2911
+ return 'half';
2912
+ },
2913
+ }).headers.has('Content-Type');
2914
+
2915
+ return duplexAccessed && !hasContentType;
2916
+ });
2917
+
2918
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
2919
+
2920
+ const supportsResponseStream = isReadableStreamSupported &&
2921
+ test(() => utils$3.isReadableStream(new Response('').body));
2922
+
2923
+
2924
+ const resolvers = {
2925
+ stream: supportsResponseStream && ((res) => res.body)
2926
+ };
2927
+
2928
+ isFetchSupported && (((res) => {
2929
+ ['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
2930
+ !resolvers[type] && (resolvers[type] = utils$3.isFunction(res[type]) ? (res) => res[type]() :
2931
+ (_, config) => {
2932
+ throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
2933
+ });
2934
+ });
2935
+ })(new Response));
2936
+
2937
+ const getBodyLength = async (body) => {
2938
+ if (body == null) {
2939
+ return 0;
2940
+ }
2941
+
2942
+ if(utils$3.isBlob(body)) {
2943
+ return body.size;
2944
+ }
2945
+
2946
+ if(utils$3.isSpecCompliantForm(body)) {
2947
+ return (await new Request(body).arrayBuffer()).byteLength;
2948
+ }
2949
+
2950
+ if(utils$3.isArrayBufferView(body) || utils$3.isArrayBuffer(body)) {
2951
+ return body.byteLength;
2952
+ }
2953
+
2954
+ if(utils$3.isURLSearchParams(body)) {
2955
+ body = body + '';
2956
+ }
2957
+
2958
+ if(utils$3.isString(body)) {
2959
+ return (await encodeText(body)).byteLength;
2960
+ }
2961
+ };
2962
+
2963
+ const resolveBodyLength = async (headers, body) => {
2964
+ const length = utils$3.toFiniteNumber(headers.getContentLength());
2965
+
2966
+ return length == null ? getBodyLength(body) : length;
2967
+ };
2968
+
2969
+ var fetchAdapter = isFetchSupported && (async (config) => {
2970
+ let {
2971
+ url,
2972
+ method,
2973
+ data,
2974
+ signal,
2975
+ cancelToken,
2976
+ timeout,
2977
+ onDownloadProgress,
2978
+ onUploadProgress,
2979
+ responseType,
2980
+ headers,
2981
+ withCredentials = 'same-origin',
2982
+ fetchOptions
2983
+ } = resolveConfig(config);
2984
+
2985
+ responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2986
+
2987
+ let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
2988
+ composeSignals$1([signal, cancelToken], timeout) : [];
2989
+
2990
+ let finished, request;
2991
+
2992
+ const onFinish = () => {
2993
+ !finished && setTimeout(() => {
2994
+ composedSignal && composedSignal.unsubscribe();
2995
+ });
2996
+
2997
+ finished = true;
2998
+ };
2999
+
3000
+ let requestContentLength;
3001
+
3002
+ try {
3003
+ if (
3004
+ onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
3005
+ (requestContentLength = await resolveBodyLength(headers, data)) !== 0
3006
+ ) {
3007
+ let _request = new Request(url, {
3008
+ method: 'POST',
3009
+ body: data,
3010
+ duplex: "half"
3011
+ });
3012
+
3013
+ let contentTypeHeader;
3014
+
3015
+ if (utils$3.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
3016
+ headers.setContentType(contentTypeHeader);
3017
+ }
3018
+
3019
+ if (_request.body) {
3020
+ const [onProgress, flush] = progressEventDecorator(
3021
+ requestContentLength,
3022
+ progressEventReducer(asyncDecorator(onUploadProgress))
3023
+ );
3024
+
3025
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
3026
+ }
3027
+ }
3028
+
3029
+ if (!utils$3.isString(withCredentials)) {
3030
+ withCredentials = withCredentials ? 'include' : 'omit';
3031
+ }
3032
+
3033
+ request = new Request(url, {
3034
+ ...fetchOptions,
3035
+ signal: composedSignal,
3036
+ method: method.toUpperCase(),
3037
+ headers: headers.normalize().toJSON(),
3038
+ body: data,
3039
+ duplex: "half",
3040
+ credentials: withCredentials
3041
+ });
3042
+
3043
+ let response = await fetch(request);
3044
+
3045
+ const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
3046
+
3047
+ if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
3048
+ const options = {};
3049
+
3050
+ ['status', 'statusText', 'headers'].forEach(prop => {
3051
+ options[prop] = response[prop];
3052
+ });
3053
+
3054
+ const responseContentLength = utils$3.toFiniteNumber(response.headers.get('content-length'));
3055
+
3056
+ const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
3057
+ responseContentLength,
3058
+ progressEventReducer(asyncDecorator(onDownloadProgress), true)
3059
+ ) || [];
3060
+
3061
+ response = new Response(
3062
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
3063
+ flush && flush();
3064
+ isStreamResponse && onFinish();
3065
+ }, encodeText),
3066
+ options
3067
+ );
3068
+ }
3069
+
3070
+ responseType = responseType || 'text';
3071
+
3072
+ let responseData = await resolvers[utils$3.findKey(resolvers, responseType) || 'text'](response, config);
3073
+
3074
+ !isStreamResponse && onFinish();
3075
+
3076
+ stopTimeout && stopTimeout();
3077
+
3078
+ return await new Promise((resolve, reject) => {
3079
+ settle(resolve, reject, {
3080
+ data: responseData,
3081
+ headers: AxiosHeaders$1.from(response.headers),
3082
+ status: response.status,
3083
+ statusText: response.statusText,
3084
+ config,
3085
+ request
3086
+ });
3087
+ })
3088
+ } catch (err) {
3089
+ onFinish();
3090
+
3091
+ if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
3092
+ throw Object.assign(
3093
+ new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
3094
+ {
3095
+ cause: err.cause || err
3096
+ }
3097
+ )
3098
+ }
3099
+
3100
+ throw AxiosError.from(err, err && err.code, config, request);
3101
+ }
3102
+ });
3103
+
2534
3104
  const knownAdapters = {
2535
3105
  http: httpAdapter,
2536
- xhr: xhrAdapter
3106
+ xhr: xhrAdapter,
3107
+ fetch: fetchAdapter
2537
3108
  };
2538
3109
 
2539
- utils$2.forEach(knownAdapters, (fn, value) => {
2540
- if(fn) {
3110
+ utils$3.forEach(knownAdapters, (fn, value) => {
3111
+ if (fn) {
2541
3112
  try {
2542
3113
  Object.defineProperty(fn, 'name', {value});
2543
3114
  } catch (e) {
@@ -2547,38 +3118,56 @@ utils$2.forEach(knownAdapters, (fn, value) => {
2547
3118
  }
2548
3119
  });
2549
3120
 
3121
+ const renderReason = (reason) => `- ${reason}`;
3122
+
3123
+ const isResolvedHandle = (adapter) => utils$3.isFunction(adapter) || adapter === null || adapter === false;
3124
+
2550
3125
  var adapters = {
2551
3126
  getAdapter: (adapters) => {
2552
- adapters = utils$2.isArray(adapters) ? adapters : [adapters];
3127
+ adapters = utils$3.isArray(adapters) ? adapters : [adapters];
2553
3128
 
2554
3129
  const {length} = adapters;
2555
3130
  let nameOrAdapter;
2556
3131
  let adapter;
2557
3132
 
3133
+ const rejectedReasons = {};
3134
+
2558
3135
  for (let i = 0; i < length; i++) {
2559
3136
  nameOrAdapter = adapters[i];
2560
- if((adapter = utils$2.isString(nameOrAdapter) ? knownAdapters[nameOrAdapter.toLowerCase()] : nameOrAdapter)) {
3137
+ let id;
3138
+
3139
+ adapter = nameOrAdapter;
3140
+
3141
+ if (!isResolvedHandle(nameOrAdapter)) {
3142
+ adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
3143
+
3144
+ if (adapter === undefined) {
3145
+ throw new AxiosError(`Unknown adapter '${id}'`);
3146
+ }
3147
+ }
3148
+
3149
+ if (adapter) {
2561
3150
  break;
2562
3151
  }
3152
+
3153
+ rejectedReasons[id || '#' + i] = adapter;
2563
3154
  }
2564
3155
 
2565
3156
  if (!adapter) {
2566
- if (adapter === false) {
2567
- throw new AxiosError(
2568
- `Adapter ${nameOrAdapter} is not supported by the environment`,
2569
- 'ERR_NOT_SUPPORT'
3157
+
3158
+ const reasons = Object.entries(rejectedReasons)
3159
+ .map(([id, state]) => `adapter ${id} ` +
3160
+ (state === false ? 'is not supported by the environment' : 'is not available in the build')
2570
3161
  );
2571
- }
2572
3162
 
2573
- throw new Error(
2574
- utils$2.hasOwnProp(knownAdapters, nameOrAdapter) ?
2575
- `Adapter '${nameOrAdapter}' is not available in the build` :
2576
- `Unknown adapter '${nameOrAdapter}'`
2577
- );
2578
- }
3163
+ let s = length ?
3164
+ (reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
3165
+ 'as no adapter specified';
2579
3166
 
2580
- if (!utils$2.isFunction(adapter)) {
2581
- throw new TypeError('adapter is not a function');
3167
+ throw new AxiosError(
3168
+ `There is no suitable adapter to dispatch the request ` + s,
3169
+ 'ERR_NOT_SUPPORT'
3170
+ );
2582
3171
  }
2583
3172
 
2584
3173
  return adapter;
@@ -2659,108 +3248,7 @@ function dispatchRequest(config) {
2659
3248
  });
2660
3249
  }
2661
3250
 
2662
- const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? thing.toJSON() : thing;
2663
-
2664
- /**
2665
- * Config-specific merge-function which creates a new config-object
2666
- * by merging two configuration objects together.
2667
- *
2668
- * @param {Object} config1
2669
- * @param {Object} config2
2670
- *
2671
- * @returns {Object} New object resulting from merging config2 to config1
2672
- */
2673
- function mergeConfig(config1, config2) {
2674
- // eslint-disable-next-line no-param-reassign
2675
- config2 = config2 || {};
2676
- const config = {};
2677
-
2678
- function getMergedValue(target, source, caseless) {
2679
- if (utils$2.isPlainObject(target) && utils$2.isPlainObject(source)) {
2680
- return utils$2.merge.call({caseless}, target, source);
2681
- } else if (utils$2.isPlainObject(source)) {
2682
- return utils$2.merge({}, source);
2683
- } else if (utils$2.isArray(source)) {
2684
- return source.slice();
2685
- }
2686
- return source;
2687
- }
2688
-
2689
- // eslint-disable-next-line consistent-return
2690
- function mergeDeepProperties(a, b, caseless) {
2691
- if (!utils$2.isUndefined(b)) {
2692
- return getMergedValue(a, b, caseless);
2693
- } else if (!utils$2.isUndefined(a)) {
2694
- return getMergedValue(undefined, a, caseless);
2695
- }
2696
- }
2697
-
2698
- // eslint-disable-next-line consistent-return
2699
- function valueFromConfig2(a, b) {
2700
- if (!utils$2.isUndefined(b)) {
2701
- return getMergedValue(undefined, b);
2702
- }
2703
- }
2704
-
2705
- // eslint-disable-next-line consistent-return
2706
- function defaultToConfig2(a, b) {
2707
- if (!utils$2.isUndefined(b)) {
2708
- return getMergedValue(undefined, b);
2709
- } else if (!utils$2.isUndefined(a)) {
2710
- return getMergedValue(undefined, a);
2711
- }
2712
- }
2713
-
2714
- // eslint-disable-next-line consistent-return
2715
- function mergeDirectKeys(a, b, prop) {
2716
- if (prop in config2) {
2717
- return getMergedValue(a, b);
2718
- } else if (prop in config1) {
2719
- return getMergedValue(undefined, a);
2720
- }
2721
- }
2722
-
2723
- const mergeMap = {
2724
- url: valueFromConfig2,
2725
- method: valueFromConfig2,
2726
- data: valueFromConfig2,
2727
- baseURL: defaultToConfig2,
2728
- transformRequest: defaultToConfig2,
2729
- transformResponse: defaultToConfig2,
2730
- paramsSerializer: defaultToConfig2,
2731
- timeout: defaultToConfig2,
2732
- timeoutMessage: defaultToConfig2,
2733
- withCredentials: defaultToConfig2,
2734
- adapter: defaultToConfig2,
2735
- responseType: defaultToConfig2,
2736
- xsrfCookieName: defaultToConfig2,
2737
- xsrfHeaderName: defaultToConfig2,
2738
- onUploadProgress: defaultToConfig2,
2739
- onDownloadProgress: defaultToConfig2,
2740
- decompress: defaultToConfig2,
2741
- maxContentLength: defaultToConfig2,
2742
- maxBodyLength: defaultToConfig2,
2743
- beforeRedirect: defaultToConfig2,
2744
- transport: defaultToConfig2,
2745
- httpAgent: defaultToConfig2,
2746
- httpsAgent: defaultToConfig2,
2747
- cancelToken: defaultToConfig2,
2748
- socketPath: defaultToConfig2,
2749
- responseEncoding: defaultToConfig2,
2750
- validateStatus: mergeDirectKeys,
2751
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2752
- };
2753
-
2754
- utils$2.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
2755
- const merge = mergeMap[prop] || mergeDeepProperties;
2756
- const configValue = merge(config1[prop], config2[prop], prop);
2757
- (utils$2.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2758
- });
2759
-
2760
- return config;
2761
- }
2762
-
2763
- const VERSION = "1.3.6";
3251
+ const VERSION = "1.7.4";
2764
3252
 
2765
3253
  const validators$1 = {};
2766
3254
 
@@ -2875,7 +3363,34 @@ class Axios {
2875
3363
  *
2876
3364
  * @returns {Promise} The Promise to be fulfilled
2877
3365
  */
2878
- request(configOrUrl, config) {
3366
+ async request(configOrUrl, config) {
3367
+ try {
3368
+ return await this._request(configOrUrl, config);
3369
+ } catch (err) {
3370
+ if (err instanceof Error) {
3371
+ let dummy;
3372
+
3373
+ Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
3374
+
3375
+ // slice off the Error: ... line
3376
+ const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
3377
+ try {
3378
+ if (!err.stack) {
3379
+ err.stack = stack;
3380
+ // match without the 2 top stack lines
3381
+ } else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
3382
+ err.stack += '\n' + stack;
3383
+ }
3384
+ } catch (e) {
3385
+ // ignore the case where "stack" is an un-writable property
3386
+ }
3387
+ }
3388
+
3389
+ throw err;
3390
+ }
3391
+ }
3392
+
3393
+ _request(configOrUrl, config) {
2879
3394
  /*eslint no-param-reassign:0*/
2880
3395
  // Allow for axios('example/url'[, config]) a la fetch API
2881
3396
  if (typeof configOrUrl === 'string') {
@@ -2898,7 +3413,7 @@ class Axios {
2898
3413
  }
2899
3414
 
2900
3415
  if (paramsSerializer != null) {
2901
- if (utils$2.isFunction(paramsSerializer)) {
3416
+ if (utils$3.isFunction(paramsSerializer)) {
2902
3417
  config.paramsSerializer = {
2903
3418
  serialize: paramsSerializer
2904
3419
  };
@@ -2913,15 +3428,13 @@ class Axios {
2913
3428
  // Set config.method
2914
3429
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
2915
3430
 
2916
- let contextHeaders;
2917
-
2918
3431
  // Flatten headers
2919
- contextHeaders = headers && utils$2.merge(
3432
+ let contextHeaders = headers && utils$3.merge(
2920
3433
  headers.common,
2921
3434
  headers[config.method]
2922
3435
  );
2923
3436
 
2924
- contextHeaders && utils$2.forEach(
3437
+ headers && utils$3.forEach(
2925
3438
  ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
2926
3439
  (method) => {
2927
3440
  delete headers[method];
@@ -3008,7 +3521,7 @@ class Axios {
3008
3521
  }
3009
3522
 
3010
3523
  // Provide aliases for supported request methods
3011
- utils$2.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
3524
+ utils$3.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
3012
3525
  /*eslint func-names:0*/
3013
3526
  Axios.prototype[method] = function(url, config) {
3014
3527
  return this.request(mergeConfig(config || {}, {
@@ -3019,7 +3532,7 @@ utils$2.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoDa
3019
3532
  };
3020
3533
  });
3021
3534
 
3022
- utils$2.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3535
+ utils$3.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
3023
3536
  /*eslint func-names:0*/
3024
3537
 
3025
3538
  function generateHTTPMethod(isForm) {
@@ -3195,7 +3708,7 @@ function spread(callback) {
3195
3708
  * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
3196
3709
  */
3197
3710
  function isAxiosError(payload) {
3198
- return utils$2.isObject(payload) && (payload.isAxiosError === true);
3711
+ return utils$3.isObject(payload) && (payload.isAxiosError === true);
3199
3712
  }
3200
3713
 
3201
3714
  const HttpStatusCode = {
@@ -3282,10 +3795,10 @@ function createInstance(defaultConfig) {
3282
3795
  const instance = bind(Axios$1.prototype.request, context);
3283
3796
 
3284
3797
  // Copy axios.prototype to instance
3285
- utils$2.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
3798
+ utils$3.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
3286
3799
 
3287
3800
  // Copy context to instance
3288
- utils$2.extend(instance, context, null, {allOwnKeys: true});
3801
+ utils$3.extend(instance, context, null, {allOwnKeys: true});
3289
3802
 
3290
3803
  // Factory for creating new instances
3291
3804
  instance.create = function create(instanceConfig) {
@@ -3329,7 +3842,9 @@ axios.mergeConfig = mergeConfig;
3329
3842
 
3330
3843
  axios.AxiosHeaders = AxiosHeaders$1;
3331
3844
 
3332
- axios.formToJSON = thing => formDataToJSON(utils$2.isHTMLForm(thing) ? new FormData(thing) : thing);
3845
+ axios.formToJSON = thing => formDataToJSON(utils$3.isHTMLForm(thing) ? new FormData(thing) : thing);
3846
+
3847
+ axios.getAdapter = adapters.getAdapter;
3333
3848
 
3334
3849
  axios.HttpStatusCode = HttpStatusCode$1;
3335
3850