@xchainjs/xchain-aggregator 2.3.2 → 2.3.4

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.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Network } from '@xchainjs/xchain-client';
2
- import { CachedValue, isSynthAsset, isTradeAsset, CryptoAmount, baseAmount, isSecuredAsset, assetToString, eqAsset, assetFromStringEx, assetFromString, isTokenAsset } from '@xchainjs/xchain-util';
2
+ import { CachedValue, isSynthAsset, isTradeAsset, CryptoAmount, baseAmount, isSecuredAsset, assetToString, eqAsset, assetFromStringEx, isTokenAsset, assetFromString } from '@xchainjs/xchain-util';
3
3
  import { SwapSDK } from '@chainflip/sdk/swap';
4
4
  import { assetUSDC, ThorchainCache, Thornode, ThorchainQuery } from '@xchainjs/xchain-thorchain-query';
5
5
  import { AssetCacao, MAYAChain } from '@xchainjs/xchain-mayachain';
@@ -40,7 +40,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
40
40
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
41
41
  };
42
42
 
43
- const SupportedProtocols = ['Thorchain', 'Mayachain', 'Chainflip'];
43
+ const SupportedProtocols = ['Thorchain', 'Mayachain', 'Chainflip', 'OneClick'];
44
44
  const DEFAULT_CONFIG = {
45
45
  protocols: SupportedProtocols,
46
46
  network: Network.Mainnet,
@@ -506,9 +506,9 @@ const isFile = kindOfTest('File');
506
506
  * also have a `name` and `type` attribute to specify filename and content type
507
507
  *
508
508
  * @see https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/Libraries/Network/FormData.js#L68-L71
509
- *
509
+ *
510
510
  * @param {*} value The value to test
511
- *
511
+ *
512
512
  * @returns {boolean} True if value is a React Native Blob, otherwise false
513
513
  */
514
514
  const isReactNativeBlob = (value) => {
@@ -518,9 +518,9 @@ const isReactNativeBlob = (value) => {
518
518
  /**
519
519
  * Determine if environment is React Native
520
520
  * ReactNative `FormData` has a non-standard `getParts()` method
521
- *
521
+ *
522
522
  * @param {*} formData The formData to test
523
- *
523
+ *
524
524
  * @returns {boolean} True if environment is React Native, otherwise false
525
525
  */
526
526
  const isReactNative = (formData) => formData && typeof formData.getParts !== 'undefined';
@@ -539,7 +539,7 @@ const isBlob = kindOfTest('Blob');
539
539
  *
540
540
  * @param {*} val The value to test
541
541
  *
542
- * @returns {boolean} True if value is a File, otherwise false
542
+ * @returns {boolean} True if value is a FileList, otherwise false
543
543
  */
544
544
  const isFileList = kindOfTest('FileList');
545
545
 
@@ -571,15 +571,17 @@ const G = getGlobal();
571
571
  const FormDataCtor = typeof G.FormData !== 'undefined' ? G.FormData : undefined;
572
572
 
573
573
  const isFormData = (thing) => {
574
- let kind;
575
- return thing && (
576
- (FormDataCtor && thing instanceof FormDataCtor) || (
577
- isFunction$1(thing.append) && (
578
- (kind = kindOf(thing)) === 'formdata' ||
579
- // detect form-data instance
580
- (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
581
- )
582
- )
574
+ if (!thing) return false;
575
+ if (FormDataCtor && thing instanceof FormDataCtor) return true;
576
+ // Reject plain objects inheriting directly from Object.prototype so prototype-pollution gadgets can't spoof FormData.
577
+ const proto = getPrototypeOf(thing);
578
+ if (!proto || proto === Object.prototype) return false;
579
+ if (!isFunction$1(thing.append)) return false;
580
+ const kind = kindOf(thing);
581
+ return (
582
+ kind === 'formdata' ||
583
+ // detect form-data instance
584
+ (kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
583
585
  );
584
586
  };
585
587
 
@@ -715,7 +717,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
715
717
  *
716
718
  * @returns {Object} Result of all merge properties
717
719
  */
718
- function merge(/* obj1, obj2, obj3, ... */) {
720
+ function merge(...objs) {
719
721
  const { caseless, skipUndefined } = (isContextDefined(this) && this) || {};
720
722
  const result = {};
721
723
  const assignValue = (val, key) => {
@@ -725,8 +727,12 @@ function merge(/* obj1, obj2, obj3, ... */) {
725
727
  }
726
728
 
727
729
  const targetKey = (caseless && findKey(result, key)) || key;
728
- if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
729
- result[targetKey] = merge(result[targetKey], val);
730
+ // Read via own-prop only — a bare `result[targetKey]` walks the prototype
731
+ // chain, so a polluted Object.prototype value could surface here and get
732
+ // copied into the merged result.
733
+ const existing = hasOwnProperty(result, targetKey) ? result[targetKey] : undefined;
734
+ if (isPlainObject(existing) && isPlainObject(val)) {
735
+ result[targetKey] = merge(existing, val);
730
736
  } else if (isPlainObject(val)) {
731
737
  result[targetKey] = merge({}, val);
732
738
  } else if (isArray(val)) {
@@ -736,8 +742,8 @@ function merge(/* obj1, obj2, obj3, ... */) {
736
742
  }
737
743
  };
738
744
 
739
- for (let i = 0, l = arguments.length; i < l; i++) {
740
- arguments[i] && forEach(arguments[i], assignValue);
745
+ for (let i = 0, l = objs.length; i < l; i++) {
746
+ objs[i] && forEach(objs[i], assignValue);
741
747
  }
742
748
  return result;
743
749
  }
@@ -759,6 +765,9 @@ const extend = (a, b, thisArg, { allOwnKeys } = {}) => {
759
765
  (val, key) => {
760
766
  if (thisArg && isFunction$1(val)) {
761
767
  Object.defineProperty(a, key, {
768
+ // Null-proto descriptor so a polluted Object.prototype.get cannot
769
+ // hijack defineProperty's accessor-vs-data resolution.
770
+ __proto__: null,
762
771
  value: bind(val, thisArg),
763
772
  writable: true,
764
773
  enumerable: true,
@@ -766,6 +775,7 @@ const extend = (a, b, thisArg, { allOwnKeys } = {}) => {
766
775
  });
767
776
  } else {
768
777
  Object.defineProperty(a, key, {
778
+ __proto__: null,
769
779
  value: val,
770
780
  writable: true,
771
781
  enumerable: true,
@@ -804,12 +814,14 @@ const stripBOM = (content) => {
804
814
  const inherits = (constructor, superConstructor, props, descriptors) => {
805
815
  constructor.prototype = Object.create(superConstructor.prototype, descriptors);
806
816
  Object.defineProperty(constructor.prototype, 'constructor', {
817
+ __proto__: null,
807
818
  value: constructor,
808
819
  writable: true,
809
820
  enumerable: false,
810
821
  configurable: true,
811
822
  });
812
823
  Object.defineProperty(constructor, 'super', {
824
+ __proto__: null,
813
825
  value: superConstructor.prototype,
814
826
  });
815
827
  props && Object.assign(constructor.prototype, props);
@@ -991,7 +1003,7 @@ const reduceDescriptors = (obj, reducer) => {
991
1003
  const freezeMethods = (obj) => {
992
1004
  reduceDescriptors(obj, (descriptor, name) => {
993
1005
  // skip restricted props in strict mode
994
- if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
1006
+ if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].includes(name)) {
995
1007
  return false;
996
1008
  }
997
1009
 
@@ -1065,11 +1077,11 @@ function isSpecCompliantForm(thing) {
1065
1077
  * @returns {Object} The JSON-compatible object.
1066
1078
  */
1067
1079
  const toJSONObject = (obj) => {
1068
- const stack = new Array(10);
1080
+ const visited = new WeakSet();
1069
1081
 
1070
- const visit = (source, i) => {
1082
+ const visit = (source) => {
1071
1083
  if (isObject(source)) {
1072
- if (stack.indexOf(source) >= 0) {
1084
+ if (visited.has(source)) {
1073
1085
  return;
1074
1086
  }
1075
1087
 
@@ -1079,15 +1091,16 @@ const toJSONObject = (obj) => {
1079
1091
  }
1080
1092
 
1081
1093
  if (!('toJSON' in source)) {
1082
- stack[i] = source;
1094
+ // add-on descent / delete-on-ascent: preserves path semantics, so DAG nodes serialise at every occurrence (see #7230).
1095
+ visited.add(source);
1083
1096
  const target = isArray(source) ? [] : {};
1084
1097
 
1085
1098
  forEach(source, (value, key) => {
1086
- const reducedValue = visit(value, i + 1);
1099
+ const reducedValue = visit(value);
1087
1100
  !isUndefined(reducedValue) && (target[key] = reducedValue);
1088
1101
  });
1089
1102
 
1090
- stack[i] = undefined;
1103
+ visited.delete(source);
1091
1104
 
1092
1105
  return target;
1093
1106
  }
@@ -1096,7 +1109,7 @@ const toJSONObject = (obj) => {
1096
1109
  return source;
1097
1110
  };
1098
1111
 
1099
- return visit(obj, 0);
1112
+ return visit(obj);
1100
1113
  };
1101
1114
 
1102
1115
  /**
@@ -1232,1297 +1245,1422 @@ var utils$1 = {
1232
1245
  isIterable,
1233
1246
  };
1234
1247
 
1235
- let AxiosError$1 = class AxiosError extends Error {
1236
- static from(error, code, config, request, response, customProps) {
1237
- const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
1238
- axiosError.cause = error;
1239
- axiosError.name = error.name;
1248
+ // RawAxiosHeaders whose duplicates are ignored by node
1249
+ // c.f. https://nodejs.org/api/http.html#http_message_headers
1250
+ const ignoreDuplicateOf = utils$1.toObjectSet([
1251
+ 'age',
1252
+ 'authorization',
1253
+ 'content-length',
1254
+ 'content-type',
1255
+ 'etag',
1256
+ 'expires',
1257
+ 'from',
1258
+ 'host',
1259
+ 'if-modified-since',
1260
+ 'if-unmodified-since',
1261
+ 'last-modified',
1262
+ 'location',
1263
+ 'max-forwards',
1264
+ 'proxy-authorization',
1265
+ 'referer',
1266
+ 'retry-after',
1267
+ 'user-agent',
1268
+ ]);
1240
1269
 
1241
- // Preserve status from the original error if not already set from response
1242
- if (error.status != null && axiosError.status == null) {
1243
- axiosError.status = error.status;
1244
- }
1270
+ /**
1271
+ * Parse headers into an object
1272
+ *
1273
+ * ```
1274
+ * Date: Wed, 27 Aug 2014 08:58:49 GMT
1275
+ * Content-Type: application/json
1276
+ * Connection: keep-alive
1277
+ * Transfer-Encoding: chunked
1278
+ * ```
1279
+ *
1280
+ * @param {String} rawHeaders Headers needing to be parsed
1281
+ *
1282
+ * @returns {Object} Headers parsed into an object
1283
+ */
1284
+ var parseHeaders = (rawHeaders) => {
1285
+ const parsed = {};
1286
+ let key;
1287
+ let val;
1288
+ let i;
1245
1289
 
1246
- customProps && Object.assign(axiosError, customProps);
1247
- return axiosError;
1248
- }
1290
+ rawHeaders &&
1291
+ rawHeaders.split('\n').forEach(function parser(line) {
1292
+ i = line.indexOf(':');
1293
+ key = line.substring(0, i).trim().toLowerCase();
1294
+ val = line.substring(i + 1).trim();
1249
1295
 
1250
- /**
1251
- * Create an Error with the specified message, config, error code, request and response.
1252
- *
1253
- * @param {string} message The error message.
1254
- * @param {string} [code] The error code (for example, 'ECONNABORTED').
1255
- * @param {Object} [config] The config.
1256
- * @param {Object} [request] The request.
1257
- * @param {Object} [response] The response.
1258
- *
1259
- * @returns {Error} The created error.
1260
- */
1261
- constructor(message, code, config, request, response) {
1262
- super(message);
1263
-
1264
- // Make message enumerable to maintain backward compatibility
1265
- // The native Error constructor sets message as non-enumerable,
1266
- // but axios < v1.13.3 had it as enumerable
1267
- Object.defineProperty(this, 'message', {
1268
- value: message,
1269
- enumerable: true,
1270
- writable: true,
1271
- configurable: true
1272
- });
1273
-
1274
- this.name = 'AxiosError';
1275
- this.isAxiosError = true;
1276
- code && (this.code = code);
1277
- config && (this.config = config);
1278
- request && (this.request = request);
1279
- if (response) {
1280
- this.response = response;
1281
- this.status = response.status;
1296
+ if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
1297
+ return;
1298
+ }
1299
+
1300
+ if (key === 'set-cookie') {
1301
+ if (parsed[key]) {
1302
+ parsed[key].push(val);
1303
+ } else {
1304
+ parsed[key] = [val];
1305
+ }
1306
+ } else {
1307
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1282
1308
  }
1309
+ });
1310
+
1311
+ return parsed;
1312
+ };
1313
+
1314
+ function trimSPorHTAB(str) {
1315
+ let start = 0;
1316
+ let end = str.length;
1317
+
1318
+ while (start < end) {
1319
+ const code = str.charCodeAt(start);
1320
+
1321
+ if (code !== 0x09 && code !== 0x20) {
1322
+ break;
1283
1323
  }
1284
1324
 
1285
- toJSON() {
1286
- return {
1287
- // Standard
1288
- message: this.message,
1289
- name: this.name,
1290
- // Microsoft
1291
- description: this.description,
1292
- number: this.number,
1293
- // Mozilla
1294
- fileName: this.fileName,
1295
- lineNumber: this.lineNumber,
1296
- columnNumber: this.columnNumber,
1297
- stack: this.stack,
1298
- // Axios
1299
- config: utils$1.toJSONObject(this.config),
1300
- code: this.code,
1301
- status: this.status,
1302
- };
1325
+ start += 1;
1303
1326
  }
1304
- };
1305
1327
 
1306
- // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated.
1307
- AxiosError$1.ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
1308
- AxiosError$1.ERR_BAD_OPTION = 'ERR_BAD_OPTION';
1309
- AxiosError$1.ECONNABORTED = 'ECONNABORTED';
1310
- AxiosError$1.ETIMEDOUT = 'ETIMEDOUT';
1311
- AxiosError$1.ERR_NETWORK = 'ERR_NETWORK';
1312
- AxiosError$1.ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
1313
- AxiosError$1.ERR_DEPRECATED = 'ERR_DEPRECATED';
1314
- AxiosError$1.ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
1315
- AxiosError$1.ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
1316
- AxiosError$1.ERR_CANCELED = 'ERR_CANCELED';
1317
- AxiosError$1.ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
1318
- AxiosError$1.ERR_INVALID_URL = 'ERR_INVALID_URL';
1328
+ while (end > start) {
1329
+ const code = str.charCodeAt(end - 1);
1319
1330
 
1320
- // eslint-disable-next-line strict
1321
- var httpAdapter = null;
1331
+ if (code !== 0x09 && code !== 0x20) {
1332
+ break;
1333
+ }
1322
1334
 
1323
- /**
1324
- * Determines if the given thing is a array or js object.
1325
- *
1326
- * @param {string} thing - The object or array to be visited.
1327
- *
1328
- * @returns {boolean}
1329
- */
1330
- function isVisitable(thing) {
1331
- return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
1332
- }
1335
+ end -= 1;
1336
+ }
1333
1337
 
1334
- /**
1335
- * It removes the brackets from the end of a string
1336
- *
1337
- * @param {string} key - The key of the parameter.
1338
- *
1339
- * @returns {string} the key without the brackets.
1340
- */
1341
- function removeBrackets(key) {
1342
- return utils$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
1338
+ return start === 0 && end === str.length ? str : str.slice(start, end);
1343
1339
  }
1344
1340
 
1345
- /**
1346
- * It takes a path, a key, and a boolean, and returns a string
1347
- *
1348
- * @param {string} path - The path to the current key.
1349
- * @param {string} key - The key of the current object being iterated over.
1350
- * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
1351
- *
1352
- * @returns {string} The path to the current key.
1353
- */
1354
- function renderKey(path, key, dots) {
1355
- if (!path) return key;
1356
- return path
1357
- .concat(key)
1358
- .map(function each(token, i) {
1359
- // eslint-disable-next-line no-param-reassign
1360
- token = removeBrackets(token);
1361
- return !dots && i ? '[' + token + ']' : token;
1362
- })
1363
- .join(dots ? '.' : '');
1364
- }
1341
+ // The control-code ranges are intentional: header sanitization strips C0/DEL bytes.
1342
+ // eslint-disable-next-line no-control-regex
1343
+ const INVALID_UNICODE_HEADER_VALUE_CHARS = new RegExp('[\\u0000-\\u0008\\u000a-\\u001f\\u007f]+', 'g');
1344
+ // eslint-disable-next-line no-control-regex
1345
+ const INVALID_BYTE_STRING_HEADER_VALUE_CHARS = new RegExp('[^\\u0009\\u0020-\\u007e\\u0080-\\u00ff]+', 'g');
1365
1346
 
1366
- /**
1367
- * If the array is an array and none of its elements are visitable, then it's a flat array.
1368
- *
1369
- * @param {Array<any>} arr - The array to check
1370
- *
1371
- * @returns {boolean}
1372
- */
1373
- function isFlatArray(arr) {
1374
- return utils$1.isArray(arr) && !arr.some(isVisitable);
1347
+ function sanitizeValue(value, invalidChars) {
1348
+ if (utils$1.isArray(value)) {
1349
+ return value.map((item) => sanitizeValue(item, invalidChars));
1350
+ }
1351
+
1352
+ return trimSPorHTAB(String(value).replace(invalidChars, ''));
1375
1353
  }
1376
1354
 
1377
- const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {
1378
- return /^is[A-Z]/.test(prop);
1379
- });
1355
+ const sanitizeHeaderValue = (value) =>
1356
+ sanitizeValue(value, INVALID_UNICODE_HEADER_VALUE_CHARS);
1380
1357
 
1381
- /**
1382
- * Convert a data object to FormData
1383
- *
1384
- * @param {Object} obj
1385
- * @param {?Object} [formData]
1386
- * @param {?Object} [options]
1387
- * @param {Function} [options.visitor]
1388
- * @param {Boolean} [options.metaTokens = true]
1389
- * @param {Boolean} [options.dots = false]
1390
- * @param {?Boolean} [options.indexes = false]
1391
- *
1392
- * @returns {Object}
1393
- **/
1358
+ const sanitizeByteStringHeaderValue = (value) =>
1359
+ sanitizeValue(value, INVALID_BYTE_STRING_HEADER_VALUE_CHARS);
1394
1360
 
1395
- /**
1396
- * It converts an object into a FormData object
1397
- *
1398
- * @param {Object<any, any>} obj - The object to convert to form data.
1399
- * @param {string} formData - The FormData object to append to.
1400
- * @param {Object<string, any>} options
1401
- *
1402
- * @returns
1403
- */
1404
- function toFormData$1(obj, formData, options) {
1405
- if (!utils$1.isObject(obj)) {
1406
- throw new TypeError('target must be an object');
1407
- }
1361
+ function toByteStringHeaderObject(headers) {
1362
+ const byteStringHeaders = Object.create(null);
1408
1363
 
1409
- // eslint-disable-next-line no-param-reassign
1410
- formData = formData || new (FormData)();
1364
+ utils$1.forEach(headers.toJSON(), (value, header) => {
1365
+ byteStringHeaders[header] = sanitizeByteStringHeaderValue(value);
1366
+ });
1411
1367
 
1412
- // eslint-disable-next-line no-param-reassign
1413
- options = utils$1.toFlatObject(
1414
- options,
1415
- {
1416
- metaTokens: true,
1417
- dots: false,
1418
- indexes: false,
1419
- },
1420
- false,
1421
- function defined(option, source) {
1422
- // eslint-disable-next-line no-eq-null,eqeqeq
1423
- return !utils$1.isUndefined(source[option]);
1424
- }
1425
- );
1368
+ return byteStringHeaders;
1369
+ }
1426
1370
 
1427
- const metaTokens = options.metaTokens;
1428
- // eslint-disable-next-line no-use-before-define
1429
- const visitor = options.visitor || defaultVisitor;
1430
- const dots = options.dots;
1431
- const indexes = options.indexes;
1432
- const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
1433
- const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
1371
+ const $internals = Symbol('internals');
1434
1372
 
1435
- if (!utils$1.isFunction(visitor)) {
1436
- throw new TypeError('visitor must be a function');
1373
+ function normalizeHeader(header) {
1374
+ return header && String(header).trim().toLowerCase();
1375
+ }
1376
+
1377
+ function normalizeValue(value) {
1378
+ if (value === false || value == null) {
1379
+ return value;
1437
1380
  }
1438
1381
 
1439
- function convertValue(value) {
1440
- if (value === null) return '';
1382
+ return utils$1.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
1383
+ }
1441
1384
 
1442
- if (utils$1.isDate(value)) {
1443
- return value.toISOString();
1444
- }
1385
+ function parseTokens(str) {
1386
+ const tokens = Object.create(null);
1387
+ const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
1388
+ let match;
1445
1389
 
1446
- if (utils$1.isBoolean(value)) {
1447
- return value.toString();
1448
- }
1390
+ while ((match = tokensRE.exec(str))) {
1391
+ tokens[match[1]] = match[2];
1392
+ }
1449
1393
 
1450
- if (!useBlob && utils$1.isBlob(value)) {
1451
- throw new AxiosError$1('Blob is not supported. Use a Buffer instead.');
1452
- }
1394
+ return tokens;
1395
+ }
1453
1396
 
1454
- if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
1455
- return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
1456
- }
1397
+ const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
1457
1398
 
1458
- return value;
1399
+ function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
1400
+ if (utils$1.isFunction(filter)) {
1401
+ return filter.call(this, value, header);
1459
1402
  }
1460
1403
 
1461
- /**
1462
- * Default visitor.
1463
- *
1464
- * @param {*} value
1465
- * @param {String|Number} key
1466
- * @param {Array<String|Number>} path
1467
- * @this {FormData}
1468
- *
1469
- * @returns {boolean} return true to visit the each prop of the value recursively
1470
- */
1471
- function defaultVisitor(value, key, path) {
1472
- let arr = value;
1404
+ if (isHeaderNameFilter) {
1405
+ value = header;
1406
+ }
1473
1407
 
1474
- if (utils$1.isReactNative(formData) && utils$1.isReactNativeBlob(value)) {
1475
- formData.append(renderKey(path, key, dots), convertValue(value));
1476
- return false;
1477
- }
1408
+ if (!utils$1.isString(value)) return;
1478
1409
 
1479
- if (value && !path && typeof value === 'object') {
1480
- if (utils$1.endsWith(key, '{}')) {
1481
- // eslint-disable-next-line no-param-reassign
1482
- key = metaTokens ? key : key.slice(0, -2);
1483
- // eslint-disable-next-line no-param-reassign
1484
- value = JSON.stringify(value);
1485
- } else if (
1486
- (utils$1.isArray(value) && isFlatArray(value)) ||
1487
- ((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value)))
1488
- ) {
1489
- // eslint-disable-next-line no-param-reassign
1490
- key = removeBrackets(key);
1410
+ if (utils$1.isString(filter)) {
1411
+ return value.indexOf(filter) !== -1;
1412
+ }
1491
1413
 
1492
- arr.forEach(function each(el, index) {
1493
- !(utils$1.isUndefined(el) || el === null) &&
1494
- formData.append(
1495
- // eslint-disable-next-line no-nested-ternary
1496
- indexes === true
1497
- ? renderKey([key], index, dots)
1498
- : indexes === null
1499
- ? key
1500
- : key + '[]',
1501
- convertValue(el)
1502
- );
1503
- });
1504
- return false;
1505
- }
1506
- }
1414
+ if (utils$1.isRegExp(filter)) {
1415
+ return filter.test(value);
1416
+ }
1417
+ }
1507
1418
 
1508
- if (isVisitable(value)) {
1509
- return true;
1510
- }
1419
+ function formatHeader(header) {
1420
+ return header
1421
+ .trim()
1422
+ .toLowerCase()
1423
+ .replace(/([a-z\d])(\w*)/g, (w, char, str) => {
1424
+ return char.toUpperCase() + str;
1425
+ });
1426
+ }
1511
1427
 
1512
- formData.append(renderKey(path, key, dots), convertValue(value));
1428
+ function buildAccessors(obj, header) {
1429
+ const accessorName = utils$1.toCamelCase(' ' + header);
1513
1430
 
1514
- return false;
1431
+ ['get', 'set', 'has'].forEach((methodName) => {
1432
+ Object.defineProperty(obj, methodName + accessorName, {
1433
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
1434
+ // this data descriptor into an accessor descriptor on the way in.
1435
+ __proto__: null,
1436
+ value: function (arg1, arg2, arg3) {
1437
+ return this[methodName].call(this, header, arg1, arg2, arg3);
1438
+ },
1439
+ configurable: true,
1440
+ });
1441
+ });
1442
+ }
1443
+
1444
+ let AxiosHeaders$1 = class AxiosHeaders {
1445
+ constructor(headers) {
1446
+ headers && this.set(headers);
1515
1447
  }
1516
1448
 
1517
- const stack = [];
1449
+ set(header, valueOrRewrite, rewrite) {
1450
+ const self = this;
1518
1451
 
1519
- const exposedHelpers = Object.assign(predicates, {
1520
- defaultVisitor,
1521
- convertValue,
1522
- isVisitable,
1523
- });
1452
+ function setHeader(_value, _header, _rewrite) {
1453
+ const lHeader = normalizeHeader(_header);
1524
1454
 
1525
- function build(value, path) {
1526
- if (utils$1.isUndefined(value)) return;
1455
+ if (!lHeader) {
1456
+ throw new Error('header name must be a non-empty string');
1457
+ }
1527
1458
 
1528
- if (stack.indexOf(value) !== -1) {
1529
- throw Error('Circular reference detected in ' + path.join('.'));
1459
+ const key = utils$1.findKey(self, lHeader);
1460
+
1461
+ if (
1462
+ !key ||
1463
+ self[key] === undefined ||
1464
+ _rewrite === true ||
1465
+ (_rewrite === undefined && self[key] !== false)
1466
+ ) {
1467
+ self[key || _header] = normalizeValue(_value);
1468
+ }
1530
1469
  }
1531
1470
 
1532
- stack.push(value);
1471
+ const setHeaders = (headers, _rewrite) =>
1472
+ utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
1533
1473
 
1534
- utils$1.forEach(value, function each(el, key) {
1535
- const result =
1536
- !(utils$1.isUndefined(el) || el === null) &&
1537
- visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
1474
+ if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
1475
+ setHeaders(header, valueOrRewrite);
1476
+ } else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
1477
+ setHeaders(parseHeaders(header), valueOrRewrite);
1478
+ } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
1479
+ let obj = {},
1480
+ dest,
1481
+ key;
1482
+ for (const entry of header) {
1483
+ if (!utils$1.isArray(entry)) {
1484
+ throw TypeError('Object iterator must return a key-value pair');
1485
+ }
1538
1486
 
1539
- if (result === true) {
1540
- build(el, path ? path.concat(key) : [key]);
1487
+ obj[(key = entry[0])] = (dest = obj[key])
1488
+ ? utils$1.isArray(dest)
1489
+ ? [...dest, entry[1]]
1490
+ : [dest, entry[1]]
1491
+ : entry[1];
1541
1492
  }
1542
- });
1543
1493
 
1544
- stack.pop();
1545
- }
1494
+ setHeaders(obj, valueOrRewrite);
1495
+ } else {
1496
+ header != null && setHeader(valueOrRewrite, header, rewrite);
1497
+ }
1546
1498
 
1547
- if (!utils$1.isObject(obj)) {
1548
- throw new TypeError('data must be an object');
1499
+ return this;
1549
1500
  }
1550
1501
 
1551
- build(obj);
1502
+ get(header, parser) {
1503
+ header = normalizeHeader(header);
1552
1504
 
1553
- return formData;
1554
- }
1505
+ if (header) {
1506
+ const key = utils$1.findKey(this, header);
1555
1507
 
1556
- /**
1557
- * It encodes a string by replacing all characters that are not in the unreserved set with
1558
- * their percent-encoded equivalents
1559
- *
1560
- * @param {string} str - The string to encode.
1561
- *
1562
- * @returns {string} The encoded string.
1563
- */
1564
- function encode$1(str) {
1565
- const charMap = {
1566
- '!': '%21',
1567
- "'": '%27',
1568
- '(': '%28',
1569
- ')': '%29',
1570
- '~': '%7E',
1571
- '%20': '+',
1572
- '%00': '\x00',
1573
- };
1574
- return encodeURIComponent(str).replace(/[!'()~]|%20|%00/g, function replacer(match) {
1575
- return charMap[match];
1576
- });
1577
- }
1508
+ if (key) {
1509
+ const value = this[key];
1578
1510
 
1579
- /**
1580
- * It takes a params object and converts it to a FormData object
1581
- *
1582
- * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
1583
- * @param {Object<string, any>} options - The options object passed to the Axios constructor.
1584
- *
1585
- * @returns {void}
1586
- */
1587
- function AxiosURLSearchParams(params, options) {
1588
- this._pairs = [];
1511
+ if (!parser) {
1512
+ return value;
1513
+ }
1589
1514
 
1590
- params && toFormData$1(params, this, options);
1591
- }
1515
+ if (parser === true) {
1516
+ return parseTokens(value);
1517
+ }
1592
1518
 
1593
- const prototype = AxiosURLSearchParams.prototype;
1519
+ if (utils$1.isFunction(parser)) {
1520
+ return parser.call(this, value, key);
1521
+ }
1594
1522
 
1595
- prototype.append = function append(name, value) {
1596
- this._pairs.push([name, value]);
1597
- };
1523
+ if (utils$1.isRegExp(parser)) {
1524
+ return parser.exec(value);
1525
+ }
1598
1526
 
1599
- prototype.toString = function toString(encoder) {
1600
- const _encode = encoder
1601
- ? function (value) {
1602
- return encoder.call(this, value, encode$1);
1527
+ throw new TypeError('parser must be boolean|regexp|function');
1603
1528
  }
1604
- : encode$1;
1529
+ }
1530
+ }
1605
1531
 
1606
- return this._pairs
1607
- .map(function each(pair) {
1608
- return _encode(pair[0]) + '=' + _encode(pair[1]);
1609
- }, '')
1610
- .join('&');
1611
- };
1532
+ has(header, matcher) {
1533
+ header = normalizeHeader(header);
1612
1534
 
1613
- /**
1614
- * It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
1615
- * their plain counterparts (`:`, `$`, `,`, `+`).
1616
- *
1617
- * @param {string} val The value to be encoded.
1618
- *
1619
- * @returns {string} The encoded value.
1620
- */
1621
- function encode(val) {
1622
- return encodeURIComponent(val)
1623
- .replace(/%3A/gi, ':')
1624
- .replace(/%24/g, '$')
1625
- .replace(/%2C/gi, ',')
1626
- .replace(/%20/g, '+');
1627
- }
1535
+ if (header) {
1536
+ const key = utils$1.findKey(this, header);
1628
1537
 
1629
- /**
1630
- * Build a URL by appending params to the end
1631
- *
1632
- * @param {string} url The base of the url (e.g., http://www.google.com)
1633
- * @param {object} [params] The params to be appended
1634
- * @param {?(object|Function)} options
1635
- *
1636
- * @returns {string} The formatted url
1637
- */
1638
- function buildURL(url, params, options) {
1639
- if (!params) {
1640
- return url;
1538
+ return !!(
1539
+ key &&
1540
+ this[key] !== undefined &&
1541
+ (!matcher || matchHeaderValue(this, this[key], key, matcher))
1542
+ );
1543
+ }
1544
+
1545
+ return false;
1641
1546
  }
1642
1547
 
1643
- const _encode = (options && options.encode) || encode;
1548
+ delete(header, matcher) {
1549
+ const self = this;
1550
+ let deleted = false;
1644
1551
 
1645
- const _options = utils$1.isFunction(options)
1646
- ? {
1647
- serialize: options,
1648
- }
1649
- : options;
1552
+ function deleteHeader(_header) {
1553
+ _header = normalizeHeader(_header);
1650
1554
 
1651
- const serializeFn = _options && _options.serialize;
1555
+ if (_header) {
1556
+ const key = utils$1.findKey(self, _header);
1652
1557
 
1653
- let serializedParams;
1558
+ if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
1559
+ delete self[key];
1654
1560
 
1655
- if (serializeFn) {
1656
- serializedParams = serializeFn(params, _options);
1657
- } else {
1658
- serializedParams = utils$1.isURLSearchParams(params)
1659
- ? params.toString()
1660
- : new AxiosURLSearchParams(params, _options).toString(_encode);
1561
+ deleted = true;
1562
+ }
1563
+ }
1564
+ }
1565
+
1566
+ if (utils$1.isArray(header)) {
1567
+ header.forEach(deleteHeader);
1568
+ } else {
1569
+ deleteHeader(header);
1570
+ }
1571
+
1572
+ return deleted;
1661
1573
  }
1662
1574
 
1663
- if (serializedParams) {
1664
- const hashmarkIndex = url.indexOf('#');
1575
+ clear(matcher) {
1576
+ const keys = Object.keys(this);
1577
+ let i = keys.length;
1578
+ let deleted = false;
1665
1579
 
1666
- if (hashmarkIndex !== -1) {
1667
- url = url.slice(0, hashmarkIndex);
1580
+ while (i--) {
1581
+ const key = keys[i];
1582
+ if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
1583
+ delete this[key];
1584
+ deleted = true;
1585
+ }
1668
1586
  }
1669
- url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
1587
+
1588
+ return deleted;
1670
1589
  }
1671
1590
 
1672
- return url;
1673
- }
1591
+ normalize(format) {
1592
+ const self = this;
1593
+ const headers = {};
1674
1594
 
1675
- class InterceptorManager {
1676
- constructor() {
1677
- this.handlers = [];
1595
+ utils$1.forEach(this, (value, header) => {
1596
+ const key = utils$1.findKey(headers, header);
1597
+
1598
+ if (key) {
1599
+ self[key] = normalizeValue(value);
1600
+ delete self[header];
1601
+ return;
1602
+ }
1603
+
1604
+ const normalized = format ? formatHeader(header) : String(header).trim();
1605
+
1606
+ if (normalized !== header) {
1607
+ delete self[header];
1608
+ }
1609
+
1610
+ self[normalized] = normalizeValue(value);
1611
+
1612
+ headers[normalized] = true;
1613
+ });
1614
+
1615
+ return this;
1678
1616
  }
1679
1617
 
1680
- /**
1681
- * Add a new interceptor to the stack
1682
- *
1683
- * @param {Function} fulfilled The function to handle `then` for a `Promise`
1684
- * @param {Function} rejected The function to handle `reject` for a `Promise`
1685
- * @param {Object} options The options for the interceptor, synchronous and runWhen
1686
- *
1687
- * @return {Number} An ID used to remove interceptor later
1688
- */
1689
- use(fulfilled, rejected, options) {
1690
- this.handlers.push({
1691
- fulfilled,
1692
- rejected,
1693
- synchronous: options ? options.synchronous : false,
1694
- runWhen: options ? options.runWhen : null,
1618
+ concat(...targets) {
1619
+ return this.constructor.concat(this, ...targets);
1620
+ }
1621
+
1622
+ toJSON(asStrings) {
1623
+ const obj = Object.create(null);
1624
+
1625
+ utils$1.forEach(this, (value, header) => {
1626
+ value != null &&
1627
+ value !== false &&
1628
+ (obj[header] = asStrings && utils$1.isArray(value) ? value.join(', ') : value);
1695
1629
  });
1696
- return this.handlers.length - 1;
1630
+
1631
+ return obj;
1697
1632
  }
1698
1633
 
1699
- /**
1700
- * Remove an interceptor from the stack
1701
- *
1702
- * @param {Number} id The ID that was returned by `use`
1703
- *
1704
- * @returns {void}
1705
- */
1706
- eject(id) {
1707
- if (this.handlers[id]) {
1708
- this.handlers[id] = null;
1709
- }
1634
+ [Symbol.iterator]() {
1635
+ return Object.entries(this.toJSON())[Symbol.iterator]();
1710
1636
  }
1711
1637
 
1712
- /**
1713
- * Clear all interceptors from the stack
1714
- *
1715
- * @returns {void}
1716
- */
1717
- clear() {
1718
- if (this.handlers) {
1719
- this.handlers = [];
1720
- }
1638
+ toString() {
1639
+ return Object.entries(this.toJSON())
1640
+ .map(([header, value]) => header + ': ' + value)
1641
+ .join('\n');
1721
1642
  }
1722
1643
 
1723
- /**
1724
- * Iterate over all the registered interceptors
1725
- *
1726
- * This method is particularly useful for skipping over any
1727
- * interceptors that may have become `null` calling `eject`.
1728
- *
1729
- * @param {Function} fn The function to call for each interceptor
1730
- *
1731
- * @returns {void}
1732
- */
1733
- forEach(fn) {
1734
- utils$1.forEach(this.handlers, function forEachHandler(h) {
1735
- if (h !== null) {
1736
- fn(h);
1737
- }
1738
- });
1644
+ getSetCookie() {
1645
+ return this.get('set-cookie') || [];
1739
1646
  }
1740
- }
1741
1647
 
1742
- var transitionalDefaults = {
1743
- silentJSONParsing: true,
1744
- forcedJSONParsing: true,
1745
- clarifyTimeoutError: false,
1746
- legacyInterceptorReqResOrdering: true,
1747
- };
1648
+ get [Symbol.toStringTag]() {
1649
+ return 'AxiosHeaders';
1650
+ }
1748
1651
 
1749
- var URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
1652
+ static from(thing) {
1653
+ return thing instanceof this ? thing : new this(thing);
1654
+ }
1750
1655
 
1751
- var FormData$1 = typeof FormData !== 'undefined' ? FormData : null;
1656
+ static concat(first, ...targets) {
1657
+ const computed = new this(first);
1752
1658
 
1753
- var Blob$1 = typeof Blob !== 'undefined' ? Blob : null;
1659
+ targets.forEach((target) => computed.set(target));
1754
1660
 
1755
- var platform$1 = {
1756
- isBrowser: true,
1757
- classes: {
1758
- URLSearchParams: URLSearchParams$1,
1759
- FormData: FormData$1,
1760
- Blob: Blob$1,
1761
- },
1762
- protocols: ['http', 'https', 'file', 'blob', 'url', 'data'],
1763
- };
1661
+ return computed;
1662
+ }
1764
1663
 
1765
- const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
1664
+ static accessor(header) {
1665
+ const internals =
1666
+ (this[$internals] =
1667
+ this[$internals] =
1668
+ {
1669
+ accessors: {},
1670
+ });
1766
1671
 
1767
- const _navigator = (typeof navigator === 'object' && navigator) || undefined;
1672
+ const accessors = internals.accessors;
1673
+ const prototype = this.prototype;
1768
1674
 
1769
- /**
1770
- * Determine if we're running in a standard browser environment
1771
- *
1772
- * This allows axios to run in a web worker, and react-native.
1773
- * Both environments support XMLHttpRequest, but not fully standard globals.
1774
- *
1775
- * web workers:
1776
- * typeof window -> undefined
1777
- * typeof document -> undefined
1778
- *
1779
- * react-native:
1780
- * navigator.product -> 'ReactNative'
1781
- * nativescript
1782
- * navigator.product -> 'NativeScript' or 'NS'
1783
- *
1784
- * @returns {boolean}
1785
- */
1786
- const hasStandardBrowserEnv =
1787
- hasBrowserEnv &&
1788
- (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
1675
+ function defineAccessor(_header) {
1676
+ const lHeader = normalizeHeader(_header);
1789
1677
 
1790
- /**
1791
- * Determine if we're running in a standard browser webWorker environment
1792
- *
1793
- * Although the `isStandardBrowserEnv` method indicates that
1794
- * `allows axios to run in a web worker`, the WebWorker will still be
1795
- * filtered out due to its judgment standard
1796
- * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
1797
- * This leads to a problem when axios post `FormData` in webWorker
1798
- */
1799
- const hasStandardBrowserWebWorkerEnv = (() => {
1800
- return (
1801
- typeof WorkerGlobalScope !== 'undefined' &&
1802
- // eslint-disable-next-line no-undef
1803
- self instanceof WorkerGlobalScope &&
1804
- typeof self.importScripts === 'function'
1805
- );
1806
- })();
1678
+ if (!accessors[lHeader]) {
1679
+ buildAccessors(prototype, _header);
1680
+ accessors[lHeader] = true;
1681
+ }
1682
+ }
1807
1683
 
1808
- const origin = (hasBrowserEnv && window.location.href) || 'http://localhost';
1684
+ utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
1809
1685
 
1810
- var utils = /*#__PURE__*/Object.freeze({
1811
- __proto__: null,
1812
- hasBrowserEnv: hasBrowserEnv,
1813
- hasStandardBrowserEnv: hasStandardBrowserEnv,
1814
- hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1815
- navigator: _navigator,
1816
- origin: origin
1817
- });
1818
-
1819
- var platform = {
1820
- ...utils,
1821
- ...platform$1,
1686
+ return this;
1687
+ }
1822
1688
  };
1823
1689
 
1824
- function toURLEncodedForm(data, options) {
1825
- return toFormData$1(data, new platform.classes.URLSearchParams(), {
1826
- visitor: function (value, key, path, helpers) {
1827
- if (platform.isNode && utils$1.isBuffer(value)) {
1828
- this.append(key, value.toString('base64'));
1829
- return false;
1830
- }
1690
+ AxiosHeaders$1.accessor([
1691
+ 'Content-Type',
1692
+ 'Content-Length',
1693
+ 'Accept',
1694
+ 'Accept-Encoding',
1695
+ 'User-Agent',
1696
+ 'Authorization',
1697
+ ]);
1831
1698
 
1832
- return helpers.defaultVisitor.apply(this, arguments);
1699
+ // reserved names hotfix
1700
+ utils$1.reduceDescriptors(AxiosHeaders$1.prototype, ({ value }, key) => {
1701
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
1702
+ return {
1703
+ get: () => value,
1704
+ set(headerValue) {
1705
+ this[mapped] = headerValue;
1833
1706
  },
1834
- ...options,
1835
- });
1836
- }
1707
+ };
1708
+ });
1837
1709
 
1838
- /**
1839
- * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
1840
- *
1841
- * @param {string} name - The name of the property to get.
1842
- *
1843
- * @returns An array of strings.
1844
- */
1845
- function parsePropPath(name) {
1846
- // foo[x][y][z]
1847
- // foo.x.y.z
1848
- // foo-x-y-z
1849
- // foo x y z
1850
- return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
1851
- return match[0] === '[]' ? '' : match[1] || match[0];
1852
- });
1853
- }
1710
+ utils$1.freezeMethods(AxiosHeaders$1);
1854
1711
 
1855
- /**
1856
- * Convert an array to an object.
1857
- *
1858
- * @param {Array<any>} arr - The array to convert to an object.
1859
- *
1860
- * @returns An object with the same keys and values as the array.
1861
- */
1862
- function arrayToObject(arr) {
1863
- const obj = {};
1864
- const keys = Object.keys(arr);
1865
- let i;
1866
- const len = keys.length;
1867
- let key;
1868
- for (i = 0; i < len; i++) {
1869
- key = keys[i];
1870
- obj[key] = arr[key];
1712
+ const REDACTED = '[REDACTED ****]';
1713
+
1714
+ function hasOwnOrPrototypeToJSON(source) {
1715
+ if (utils$1.hasOwnProp(source, 'toJSON')) {
1716
+ return true;
1871
1717
  }
1872
- return obj;
1718
+
1719
+ let prototype = Object.getPrototypeOf(source);
1720
+
1721
+ while (prototype && prototype !== Object.prototype) {
1722
+ if (utils$1.hasOwnProp(prototype, 'toJSON')) {
1723
+ return true;
1724
+ }
1725
+
1726
+ prototype = Object.getPrototypeOf(prototype);
1727
+ }
1728
+
1729
+ return false;
1873
1730
  }
1874
1731
 
1875
- /**
1876
- * It takes a FormData object and returns a JavaScript object
1877
- *
1878
- * @param {string} formData The FormData object to convert to JSON.
1879
- *
1880
- * @returns {Object<string, any> | null} The converted object.
1881
- */
1882
- function formDataToJSON(formData) {
1883
- function buildPath(path, value, target, index) {
1884
- let name = path[index++];
1732
+ // Build a plain-object snapshot of `config` and replace the value of any key
1733
+ // (case-insensitive) listed in `redactKeys` with REDACTED. Walks through arrays
1734
+ // and AxiosHeaders, and short-circuits on circular references.
1735
+ function redactConfig(config, redactKeys) {
1736
+ const lowerKeys = new Set(redactKeys.map((k) => String(k).toLowerCase()));
1737
+ const seen = [];
1885
1738
 
1886
- if (name === '__proto__') return true;
1739
+ const visit = (source) => {
1740
+ if (source === null || typeof source !== 'object') return source;
1741
+ if (utils$1.isBuffer(source)) return source;
1742
+ if (seen.indexOf(source) !== -1) return undefined;
1887
1743
 
1888
- const isNumericKey = Number.isFinite(+name);
1889
- const isLast = index >= path.length;
1890
- name = !name && utils$1.isArray(target) ? target.length : name;
1744
+ if (source instanceof AxiosHeaders$1) {
1745
+ source = source.toJSON();
1746
+ }
1891
1747
 
1892
- if (isLast) {
1893
- if (utils$1.hasOwnProp(target, name)) {
1894
- target[name] = [target[name], value];
1895
- } else {
1896
- target[name] = value;
1748
+ seen.push(source);
1749
+
1750
+ let result;
1751
+ if (utils$1.isArray(source)) {
1752
+ result = [];
1753
+ source.forEach((v, i) => {
1754
+ const reducedValue = visit(v);
1755
+ if (!utils$1.isUndefined(reducedValue)) {
1756
+ result[i] = reducedValue;
1757
+ }
1758
+ });
1759
+ } else {
1760
+ if (!utils$1.isPlainObject(source) && hasOwnOrPrototypeToJSON(source)) {
1761
+ seen.pop();
1762
+ return source;
1897
1763
  }
1898
1764
 
1899
- return !isNumericKey;
1765
+ result = Object.create(null);
1766
+ for (const [key, value] of Object.entries(source)) {
1767
+ const reducedValue = lowerKeys.has(key.toLowerCase()) ? REDACTED : visit(value);
1768
+ if (!utils$1.isUndefined(reducedValue)) {
1769
+ result[key] = reducedValue;
1770
+ }
1771
+ }
1900
1772
  }
1901
1773
 
1902
- if (!target[name] || !utils$1.isObject(target[name])) {
1903
- target[name] = [];
1904
- }
1774
+ seen.pop();
1775
+ return result;
1776
+ };
1905
1777
 
1906
- const result = buildPath(path, value, target[name], index);
1778
+ return visit(config);
1779
+ }
1907
1780
 
1908
- if (result && utils$1.isArray(target[name])) {
1909
- target[name] = arrayToObject(target[name]);
1781
+ let AxiosError$1 = class AxiosError extends Error {
1782
+ static from(error, code, config, request, response, customProps) {
1783
+ const axiosError = new AxiosError(error.message, code || error.code, config, request, response);
1784
+ axiosError.cause = error;
1785
+ axiosError.name = error.name;
1786
+
1787
+ // Preserve status from the original error if not already set from response
1788
+ if (error.status != null && axiosError.status == null) {
1789
+ axiosError.status = error.status;
1910
1790
  }
1911
1791
 
1912
- return !isNumericKey;
1792
+ customProps && Object.assign(axiosError, customProps);
1793
+ return axiosError;
1913
1794
  }
1914
1795
 
1915
- if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
1916
- const obj = {};
1917
-
1918
- utils$1.forEachEntry(formData, (name, value) => {
1919
- buildPath(parsePropPath(name), value, obj, 0);
1796
+ /**
1797
+ * Create an Error with the specified message, config, error code, request and response.
1798
+ *
1799
+ * @param {string} message The error message.
1800
+ * @param {string} [code] The error code (for example, 'ECONNABORTED').
1801
+ * @param {Object} [config] The config.
1802
+ * @param {Object} [request] The request.
1803
+ * @param {Object} [response] The response.
1804
+ *
1805
+ * @returns {Error} The created error.
1806
+ */
1807
+ constructor(message, code, config, request, response) {
1808
+ super(message);
1809
+
1810
+ // Make message enumerable to maintain backward compatibility
1811
+ // The native Error constructor sets message as non-enumerable,
1812
+ // but axios < v1.13.3 had it as enumerable
1813
+ Object.defineProperty(this, 'message', {
1814
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
1815
+ // this data descriptor into an accessor descriptor on the way in.
1816
+ __proto__: null,
1817
+ value: message,
1818
+ enumerable: true,
1819
+ writable: true,
1820
+ configurable: true,
1920
1821
  });
1921
1822
 
1922
- return obj;
1823
+ this.name = 'AxiosError';
1824
+ this.isAxiosError = true;
1825
+ code && (this.code = code);
1826
+ config && (this.config = config);
1827
+ request && (this.request = request);
1828
+ if (response) {
1829
+ this.response = response;
1830
+ this.status = response.status;
1831
+ }
1923
1832
  }
1924
1833
 
1925
- return null;
1926
- }
1834
+ toJSON() {
1835
+ // Opt-in redaction: when the request config carries a `redact` array, the
1836
+ // value of any matching key (case-insensitive, at any depth) is replaced
1837
+ // with REDACTED in the serialized snapshot. Undefined or empty leaves the
1838
+ // existing serialization behavior unchanged.
1839
+ const config = this.config;
1840
+ const redactKeys = config && utils$1.hasOwnProp(config, 'redact') ? config.redact : undefined;
1841
+ const serializedConfig =
1842
+ utils$1.isArray(redactKeys) && redactKeys.length > 0
1843
+ ? redactConfig(config, redactKeys)
1844
+ : utils$1.toJSONObject(config);
1845
+
1846
+ return {
1847
+ // Standard
1848
+ message: this.message,
1849
+ name: this.name,
1850
+ // Microsoft
1851
+ description: this.description,
1852
+ number: this.number,
1853
+ // Mozilla
1854
+ fileName: this.fileName,
1855
+ lineNumber: this.lineNumber,
1856
+ columnNumber: this.columnNumber,
1857
+ stack: this.stack,
1858
+ // Axios
1859
+ config: serializedConfig,
1860
+ code: this.code,
1861
+ status: this.status,
1862
+ };
1863
+ }
1864
+ };
1865
+
1866
+ // This can be changed to static properties as soon as the parser options in .eslint.cjs are updated.
1867
+ AxiosError$1.ERR_BAD_OPTION_VALUE = 'ERR_BAD_OPTION_VALUE';
1868
+ AxiosError$1.ERR_BAD_OPTION = 'ERR_BAD_OPTION';
1869
+ AxiosError$1.ECONNABORTED = 'ECONNABORTED';
1870
+ AxiosError$1.ETIMEDOUT = 'ETIMEDOUT';
1871
+ AxiosError$1.ECONNREFUSED = 'ECONNREFUSED';
1872
+ AxiosError$1.ERR_NETWORK = 'ERR_NETWORK';
1873
+ AxiosError$1.ERR_FR_TOO_MANY_REDIRECTS = 'ERR_FR_TOO_MANY_REDIRECTS';
1874
+ AxiosError$1.ERR_DEPRECATED = 'ERR_DEPRECATED';
1875
+ AxiosError$1.ERR_BAD_RESPONSE = 'ERR_BAD_RESPONSE';
1876
+ AxiosError$1.ERR_BAD_REQUEST = 'ERR_BAD_REQUEST';
1877
+ AxiosError$1.ERR_CANCELED = 'ERR_CANCELED';
1878
+ AxiosError$1.ERR_NOT_SUPPORT = 'ERR_NOT_SUPPORT';
1879
+ AxiosError$1.ERR_INVALID_URL = 'ERR_INVALID_URL';
1880
+ AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED = 'ERR_FORM_DATA_DEPTH_EXCEEDED';
1881
+
1882
+ // eslint-disable-next-line strict
1883
+ var httpAdapter = null;
1927
1884
 
1928
1885
  /**
1929
- * It takes a string, tries to parse it, and if it fails, it returns the stringified version
1930
- * of the input
1886
+ * Determines if the given thing is a array or js object.
1931
1887
  *
1932
- * @param {any} rawValue - The value to be stringified.
1933
- * @param {Function} parser - A function that parses a string into a JavaScript object.
1934
- * @param {Function} encoder - A function that takes a value and returns a string.
1888
+ * @param {string} thing - The object or array to be visited.
1935
1889
  *
1936
- * @returns {string} A stringified version of the rawValue.
1890
+ * @returns {boolean}
1937
1891
  */
1938
- function stringifySafely(rawValue, parser, encoder) {
1939
- if (utils$1.isString(rawValue)) {
1940
- try {
1941
- (parser || JSON.parse)(rawValue);
1942
- return utils$1.trim(rawValue);
1943
- } catch (e) {
1944
- if (e.name !== 'SyntaxError') {
1945
- throw e;
1946
- }
1947
- }
1948
- }
1892
+ function isVisitable(thing) {
1893
+ return utils$1.isPlainObject(thing) || utils$1.isArray(thing);
1894
+ }
1949
1895
 
1950
- return (encoder || JSON.stringify)(rawValue);
1896
+ /**
1897
+ * It removes the brackets from the end of a string
1898
+ *
1899
+ * @param {string} key - The key of the parameter.
1900
+ *
1901
+ * @returns {string} the key without the brackets.
1902
+ */
1903
+ function removeBrackets(key) {
1904
+ return utils$1.endsWith(key, '[]') ? key.slice(0, -2) : key;
1951
1905
  }
1952
1906
 
1953
- const defaults = {
1954
- transitional: transitionalDefaults,
1907
+ /**
1908
+ * It takes a path, a key, and a boolean, and returns a string
1909
+ *
1910
+ * @param {string} path - The path to the current key.
1911
+ * @param {string} key - The key of the current object being iterated over.
1912
+ * @param {string} dots - If true, the key will be rendered with dots instead of brackets.
1913
+ *
1914
+ * @returns {string} The path to the current key.
1915
+ */
1916
+ function renderKey(path, key, dots) {
1917
+ if (!path) return key;
1918
+ return path
1919
+ .concat(key)
1920
+ .map(function each(token, i) {
1921
+ // eslint-disable-next-line no-param-reassign
1922
+ token = removeBrackets(token);
1923
+ return !dots && i ? '[' + token + ']' : token;
1924
+ })
1925
+ .join(dots ? '.' : '');
1926
+ }
1955
1927
 
1956
- adapter: ['xhr', 'http', 'fetch'],
1928
+ /**
1929
+ * If the array is an array and none of its elements are visitable, then it's a flat array.
1930
+ *
1931
+ * @param {Array<any>} arr - The array to check
1932
+ *
1933
+ * @returns {boolean}
1934
+ */
1935
+ function isFlatArray(arr) {
1936
+ return utils$1.isArray(arr) && !arr.some(isVisitable);
1937
+ }
1957
1938
 
1958
- transformRequest: [
1959
- function transformRequest(data, headers) {
1960
- const contentType = headers.getContentType() || '';
1961
- const hasJSONContentType = contentType.indexOf('application/json') > -1;
1962
- const isObjectPayload = utils$1.isObject(data);
1939
+ const predicates = utils$1.toFlatObject(utils$1, {}, null, function filter(prop) {
1940
+ return /^is[A-Z]/.test(prop);
1941
+ });
1963
1942
 
1964
- if (isObjectPayload && utils$1.isHTMLForm(data)) {
1965
- data = new FormData(data);
1966
- }
1943
+ /**
1944
+ * Convert a data object to FormData
1945
+ *
1946
+ * @param {Object} obj
1947
+ * @param {?Object} [formData]
1948
+ * @param {?Object} [options]
1949
+ * @param {Function} [options.visitor]
1950
+ * @param {Boolean} [options.metaTokens = true]
1951
+ * @param {Boolean} [options.dots = false]
1952
+ * @param {?Boolean} [options.indexes = false]
1953
+ *
1954
+ * @returns {Object}
1955
+ **/
1967
1956
 
1968
- const isFormData = utils$1.isFormData(data);
1957
+ /**
1958
+ * It converts an object into a FormData object
1959
+ *
1960
+ * @param {Object<any, any>} obj - The object to convert to form data.
1961
+ * @param {string} formData - The FormData object to append to.
1962
+ * @param {Object<string, any>} options
1963
+ *
1964
+ * @returns
1965
+ */
1966
+ function toFormData$1(obj, formData, options) {
1967
+ if (!utils$1.isObject(obj)) {
1968
+ throw new TypeError('target must be an object');
1969
+ }
1969
1970
 
1970
- if (isFormData) {
1971
- return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
1972
- }
1971
+ // eslint-disable-next-line no-param-reassign
1972
+ formData = formData || new (FormData)();
1973
1973
 
1974
- if (
1975
- utils$1.isArrayBuffer(data) ||
1976
- utils$1.isBuffer(data) ||
1977
- utils$1.isStream(data) ||
1978
- utils$1.isFile(data) ||
1979
- utils$1.isBlob(data) ||
1980
- utils$1.isReadableStream(data)
1981
- ) {
1982
- return data;
1983
- }
1984
- if (utils$1.isArrayBufferView(data)) {
1985
- return data.buffer;
1986
- }
1987
- if (utils$1.isURLSearchParams(data)) {
1988
- headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
1989
- return data.toString();
1990
- }
1974
+ // eslint-disable-next-line no-param-reassign
1975
+ options = utils$1.toFlatObject(
1976
+ options,
1977
+ {
1978
+ metaTokens: true,
1979
+ dots: false,
1980
+ indexes: false,
1981
+ },
1982
+ false,
1983
+ function defined(option, source) {
1984
+ // eslint-disable-next-line no-eq-null,eqeqeq
1985
+ return !utils$1.isUndefined(source[option]);
1986
+ }
1987
+ );
1991
1988
 
1992
- let isFileList;
1989
+ const metaTokens = options.metaTokens;
1990
+ // eslint-disable-next-line no-use-before-define
1991
+ const visitor = options.visitor || defaultVisitor;
1992
+ const dots = options.dots;
1993
+ const indexes = options.indexes;
1994
+ const _Blob = options.Blob || (typeof Blob !== 'undefined' && Blob);
1995
+ const maxDepth = options.maxDepth === undefined ? 100 : options.maxDepth;
1996
+ const useBlob = _Blob && utils$1.isSpecCompliantForm(formData);
1993
1997
 
1994
- if (isObjectPayload) {
1995
- if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
1996
- return toURLEncodedForm(data, this.formSerializer).toString();
1997
- }
1998
+ if (!utils$1.isFunction(visitor)) {
1999
+ throw new TypeError('visitor must be a function');
2000
+ }
1998
2001
 
1999
- if (
2000
- (isFileList = utils$1.isFileList(data)) ||
2001
- contentType.indexOf('multipart/form-data') > -1
2002
- ) {
2003
- const _FormData = this.env && this.env.FormData;
2002
+ function convertValue(value) {
2003
+ if (value === null) return '';
2004
2004
 
2005
- return toFormData$1(
2006
- isFileList ? { 'files[]': data } : data,
2007
- _FormData && new _FormData(),
2008
- this.formSerializer
2009
- );
2010
- }
2011
- }
2005
+ if (utils$1.isDate(value)) {
2006
+ return value.toISOString();
2007
+ }
2012
2008
 
2013
- if (isObjectPayload || hasJSONContentType) {
2014
- headers.setContentType('application/json', false);
2015
- return stringifySafely(data);
2016
- }
2009
+ if (utils$1.isBoolean(value)) {
2010
+ return value.toString();
2011
+ }
2017
2012
 
2018
- return data;
2019
- },
2020
- ],
2013
+ if (!useBlob && utils$1.isBlob(value)) {
2014
+ throw new AxiosError$1('Blob is not supported. Use a Buffer instead.');
2015
+ }
2021
2016
 
2022
- transformResponse: [
2023
- function transformResponse(data) {
2024
- const transitional = this.transitional || defaults.transitional;
2025
- const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
2026
- const JSONRequested = this.responseType === 'json';
2017
+ if (utils$1.isArrayBuffer(value) || utils$1.isTypedArray(value)) {
2018
+ return useBlob && typeof Blob === 'function' ? new Blob([value]) : Buffer.from(value);
2019
+ }
2027
2020
 
2028
- if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
2029
- return data;
2030
- }
2021
+ return value;
2022
+ }
2031
2023
 
2032
- if (
2033
- data &&
2034
- utils$1.isString(data) &&
2035
- ((forcedJSONParsing && !this.responseType) || JSONRequested)
2024
+ /**
2025
+ * Default visitor.
2026
+ *
2027
+ * @param {*} value
2028
+ * @param {String|Number} key
2029
+ * @param {Array<String|Number>} path
2030
+ * @this {FormData}
2031
+ *
2032
+ * @returns {boolean} return true to visit the each prop of the value recursively
2033
+ */
2034
+ function defaultVisitor(value, key, path) {
2035
+ let arr = value;
2036
+
2037
+ if (utils$1.isReactNative(formData) && utils$1.isReactNativeBlob(value)) {
2038
+ formData.append(renderKey(path, key, dots), convertValue(value));
2039
+ return false;
2040
+ }
2041
+
2042
+ if (value && !path && typeof value === 'object') {
2043
+ if (utils$1.endsWith(key, '{}')) {
2044
+ // eslint-disable-next-line no-param-reassign
2045
+ key = metaTokens ? key : key.slice(0, -2);
2046
+ // eslint-disable-next-line no-param-reassign
2047
+ value = JSON.stringify(value);
2048
+ } else if (
2049
+ (utils$1.isArray(value) && isFlatArray(value)) ||
2050
+ ((utils$1.isFileList(value) || utils$1.endsWith(key, '[]')) && (arr = utils$1.toArray(value)))
2036
2051
  ) {
2037
- const silentJSONParsing = transitional && transitional.silentJSONParsing;
2038
- const strictJSONParsing = !silentJSONParsing && JSONRequested;
2052
+ // eslint-disable-next-line no-param-reassign
2053
+ key = removeBrackets(key);
2039
2054
 
2040
- try {
2041
- return JSON.parse(data, this.parseReviver);
2042
- } catch (e) {
2043
- if (strictJSONParsing) {
2044
- if (e.name === 'SyntaxError') {
2045
- throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, this.response);
2046
- }
2047
- throw e;
2048
- }
2049
- }
2055
+ arr.forEach(function each(el, index) {
2056
+ !(utils$1.isUndefined(el) || el === null) &&
2057
+ formData.append(
2058
+ // eslint-disable-next-line no-nested-ternary
2059
+ indexes === true
2060
+ ? renderKey([key], index, dots)
2061
+ : indexes === null
2062
+ ? key
2063
+ : key + '[]',
2064
+ convertValue(el)
2065
+ );
2066
+ });
2067
+ return false;
2050
2068
  }
2069
+ }
2051
2070
 
2052
- return data;
2053
- },
2054
- ],
2071
+ if (isVisitable(value)) {
2072
+ return true;
2073
+ }
2055
2074
 
2056
- /**
2057
- * A timeout in milliseconds to abort a request. If set to 0 (default) a
2058
- * timeout is not created.
2059
- */
2060
- timeout: 0,
2075
+ formData.append(renderKey(path, key, dots), convertValue(value));
2061
2076
 
2062
- xsrfCookieName: 'XSRF-TOKEN',
2063
- xsrfHeaderName: 'X-XSRF-TOKEN',
2077
+ return false;
2078
+ }
2064
2079
 
2065
- maxContentLength: -1,
2066
- maxBodyLength: -1,
2080
+ const stack = [];
2067
2081
 
2068
- env: {
2069
- FormData: platform.classes.FormData,
2070
- Blob: platform.classes.Blob,
2071
- },
2082
+ const exposedHelpers = Object.assign(predicates, {
2083
+ defaultVisitor,
2084
+ convertValue,
2085
+ isVisitable,
2086
+ });
2072
2087
 
2073
- validateStatus: function validateStatus(status) {
2074
- return status >= 200 && status < 300;
2075
- },
2088
+ function build(value, path, depth = 0) {
2089
+ if (utils$1.isUndefined(value)) return;
2076
2090
 
2077
- headers: {
2078
- common: {
2079
- Accept: 'application/json, text/plain, */*',
2080
- 'Content-Type': undefined,
2081
- },
2082
- },
2083
- };
2091
+ if (depth > maxDepth) {
2092
+ throw new AxiosError$1(
2093
+ 'Object is too deeply nested (' + depth + ' levels). Max depth: ' + maxDepth,
2094
+ AxiosError$1.ERR_FORM_DATA_DEPTH_EXCEEDED
2095
+ );
2096
+ }
2084
2097
 
2085
- utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
2086
- defaults.headers[method] = {};
2087
- });
2098
+ if (stack.indexOf(value) !== -1) {
2099
+ throw Error('Circular reference detected in ' + path.join('.'));
2100
+ }
2088
2101
 
2089
- // RawAxiosHeaders whose duplicates are ignored by node
2090
- // c.f. https://nodejs.org/api/http.html#http_message_headers
2091
- const ignoreDuplicateOf = utils$1.toObjectSet([
2092
- 'age',
2093
- 'authorization',
2094
- 'content-length',
2095
- 'content-type',
2096
- 'etag',
2097
- 'expires',
2098
- 'from',
2099
- 'host',
2100
- 'if-modified-since',
2101
- 'if-unmodified-since',
2102
- 'last-modified',
2103
- 'location',
2104
- 'max-forwards',
2105
- 'proxy-authorization',
2106
- 'referer',
2107
- 'retry-after',
2108
- 'user-agent',
2109
- ]);
2102
+ stack.push(value);
2110
2103
 
2111
- /**
2112
- * Parse headers into an object
2113
- *
2114
- * ```
2115
- * Date: Wed, 27 Aug 2014 08:58:49 GMT
2116
- * Content-Type: application/json
2117
- * Connection: keep-alive
2118
- * Transfer-Encoding: chunked
2119
- * ```
2120
- *
2121
- * @param {String} rawHeaders Headers needing to be parsed
2122
- *
2123
- * @returns {Object} Headers parsed into an object
2124
- */
2125
- var parseHeaders = (rawHeaders) => {
2126
- const parsed = {};
2127
- let key;
2128
- let val;
2129
- let i;
2130
-
2131
- rawHeaders &&
2132
- rawHeaders.split('\n').forEach(function parser(line) {
2133
- i = line.indexOf(':');
2134
- key = line.substring(0, i).trim().toLowerCase();
2135
- val = line.substring(i + 1).trim();
2136
-
2137
- if (!key || (parsed[key] && ignoreDuplicateOf[key])) {
2138
- return;
2139
- }
2104
+ utils$1.forEach(value, function each(el, key) {
2105
+ const result =
2106
+ !(utils$1.isUndefined(el) || el === null) &&
2107
+ visitor.call(formData, el, utils$1.isString(key) ? key.trim() : key, path, exposedHelpers);
2140
2108
 
2141
- if (key === 'set-cookie') {
2142
- if (parsed[key]) {
2143
- parsed[key].push(val);
2144
- } else {
2145
- parsed[key] = [val];
2146
- }
2147
- } else {
2148
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
2109
+ if (result === true) {
2110
+ build(el, path ? path.concat(key) : [key], depth + 1);
2149
2111
  }
2150
2112
  });
2151
2113
 
2152
- return parsed;
2153
- };
2154
-
2155
- const $internals = Symbol('internals');
2156
-
2157
- const isValidHeaderValue = (value) => !/[\r\n]/.test(value);
2158
-
2159
- function assertValidHeaderValue(value, header) {
2160
- if (value === false || value == null) {
2161
- return;
2114
+ stack.pop();
2162
2115
  }
2163
2116
 
2164
- if (utils$1.isArray(value)) {
2165
- value.forEach((v) => assertValidHeaderValue(v, header));
2166
- return;
2117
+ if (!utils$1.isObject(obj)) {
2118
+ throw new TypeError('data must be an object');
2167
2119
  }
2168
2120
 
2169
- if (!isValidHeaderValue(String(value))) {
2170
- throw new Error(`Invalid character in header content ["${header}"]`);
2171
- }
2121
+ build(obj);
2122
+
2123
+ return formData;
2172
2124
  }
2173
2125
 
2174
- function normalizeHeader(header) {
2175
- return header && String(header).trim().toLowerCase();
2126
+ /**
2127
+ * It encodes a string by replacing all characters that are not in the unreserved set with
2128
+ * their percent-encoded equivalents
2129
+ *
2130
+ * @param {string} str - The string to encode.
2131
+ *
2132
+ * @returns {string} The encoded string.
2133
+ */
2134
+ function encode$1(str) {
2135
+ const charMap = {
2136
+ '!': '%21',
2137
+ "'": '%27',
2138
+ '(': '%28',
2139
+ ')': '%29',
2140
+ '~': '%7E',
2141
+ '%20': '+',
2142
+ };
2143
+ return encodeURIComponent(str).replace(/[!'()~]|%20/g, function replacer(match) {
2144
+ return charMap[match];
2145
+ });
2176
2146
  }
2177
2147
 
2178
- function stripTrailingCRLF(str) {
2179
- let end = str.length;
2148
+ /**
2149
+ * It takes a params object and converts it to a FormData object
2150
+ *
2151
+ * @param {Object<string, any>} params - The parameters to be converted to a FormData object.
2152
+ * @param {Object<string, any>} options - The options object passed to the Axios constructor.
2153
+ *
2154
+ * @returns {void}
2155
+ */
2156
+ function AxiosURLSearchParams(params, options) {
2157
+ this._pairs = [];
2180
2158
 
2181
- while (end > 0) {
2182
- const charCode = str.charCodeAt(end - 1);
2159
+ params && toFormData$1(params, this, options);
2160
+ }
2183
2161
 
2184
- if (charCode !== 10 && charCode !== 13) {
2185
- break;
2186
- }
2162
+ const prototype = AxiosURLSearchParams.prototype;
2187
2163
 
2188
- end -= 1;
2189
- }
2164
+ prototype.append = function append(name, value) {
2165
+ this._pairs.push([name, value]);
2166
+ };
2190
2167
 
2191
- return end === str.length ? str : str.slice(0, end);
2192
- }
2168
+ prototype.toString = function toString(encoder) {
2169
+ const _encode = encoder
2170
+ ? function (value) {
2171
+ return encoder.call(this, value, encode$1);
2172
+ }
2173
+ : encode$1;
2193
2174
 
2194
- function normalizeValue(value) {
2195
- if (value === false || value == null) {
2196
- return value;
2197
- }
2175
+ return this._pairs
2176
+ .map(function each(pair) {
2177
+ return _encode(pair[0]) + '=' + _encode(pair[1]);
2178
+ }, '')
2179
+ .join('&');
2180
+ };
2198
2181
 
2199
- return utils$1.isArray(value) ? value.map(normalizeValue) : stripTrailingCRLF(String(value));
2182
+ /**
2183
+ * It replaces URL-encoded forms of `:`, `$`, `,`, and spaces with
2184
+ * their plain counterparts (`:`, `$`, `,`, `+`).
2185
+ *
2186
+ * @param {string} val The value to be encoded.
2187
+ *
2188
+ * @returns {string} The encoded value.
2189
+ */
2190
+ function encode(val) {
2191
+ return encodeURIComponent(val)
2192
+ .replace(/%3A/gi, ':')
2193
+ .replace(/%24/g, '$')
2194
+ .replace(/%2C/gi, ',')
2195
+ .replace(/%20/g, '+');
2200
2196
  }
2201
2197
 
2202
- function parseTokens(str) {
2203
- const tokens = Object.create(null);
2204
- const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
2205
- let match;
2206
-
2207
- while ((match = tokensRE.exec(str))) {
2208
- tokens[match[1]] = match[2];
2198
+ /**
2199
+ * Build a URL by appending params to the end
2200
+ *
2201
+ * @param {string} url The base of the url (e.g., http://www.google.com)
2202
+ * @param {object} [params] The params to be appended
2203
+ * @param {?(object|Function)} options
2204
+ *
2205
+ * @returns {string} The formatted url
2206
+ */
2207
+ function buildURL(url, params, options) {
2208
+ if (!params) {
2209
+ return url;
2209
2210
  }
2210
2211
 
2211
- return tokens;
2212
- }
2213
-
2214
- const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
2212
+ const _encode = (options && options.encode) || encode;
2215
2213
 
2216
- function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
2217
- if (utils$1.isFunction(filter)) {
2218
- return filter.call(this, value, header);
2219
- }
2214
+ const _options = utils$1.isFunction(options)
2215
+ ? {
2216
+ serialize: options,
2217
+ }
2218
+ : options;
2220
2219
 
2221
- if (isHeaderNameFilter) {
2222
- value = header;
2223
- }
2220
+ const serializeFn = _options && _options.serialize;
2224
2221
 
2225
- if (!utils$1.isString(value)) return;
2222
+ let serializedParams;
2226
2223
 
2227
- if (utils$1.isString(filter)) {
2228
- return value.indexOf(filter) !== -1;
2224
+ if (serializeFn) {
2225
+ serializedParams = serializeFn(params, _options);
2226
+ } else {
2227
+ serializedParams = utils$1.isURLSearchParams(params)
2228
+ ? params.toString()
2229
+ : new AxiosURLSearchParams(params, _options).toString(_encode);
2229
2230
  }
2230
2231
 
2231
- if (utils$1.isRegExp(filter)) {
2232
- return filter.test(value);
2232
+ if (serializedParams) {
2233
+ const hashmarkIndex = url.indexOf('#');
2234
+
2235
+ if (hashmarkIndex !== -1) {
2236
+ url = url.slice(0, hashmarkIndex);
2237
+ }
2238
+ url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
2233
2239
  }
2234
- }
2235
2240
 
2236
- function formatHeader(header) {
2237
- return header
2238
- .trim()
2239
- .toLowerCase()
2240
- .replace(/([a-z\d])(\w*)/g, (w, char, str) => {
2241
- return char.toUpperCase() + str;
2242
- });
2241
+ return url;
2243
2242
  }
2244
2243
 
2245
- function buildAccessors(obj, header) {
2246
- const accessorName = utils$1.toCamelCase(' ' + header);
2244
+ class InterceptorManager {
2245
+ constructor() {
2246
+ this.handlers = [];
2247
+ }
2247
2248
 
2248
- ['get', 'set', 'has'].forEach((methodName) => {
2249
- Object.defineProperty(obj, methodName + accessorName, {
2250
- value: function (arg1, arg2, arg3) {
2251
- return this[methodName].call(this, header, arg1, arg2, arg3);
2252
- },
2253
- configurable: true,
2249
+ /**
2250
+ * Add a new interceptor to the stack
2251
+ *
2252
+ * @param {Function} fulfilled The function to handle `then` for a `Promise`
2253
+ * @param {Function} rejected The function to handle `reject` for a `Promise`
2254
+ * @param {Object} options The options for the interceptor, synchronous and runWhen
2255
+ *
2256
+ * @return {Number} An ID used to remove interceptor later
2257
+ */
2258
+ use(fulfilled, rejected, options) {
2259
+ this.handlers.push({
2260
+ fulfilled,
2261
+ rejected,
2262
+ synchronous: options ? options.synchronous : false,
2263
+ runWhen: options ? options.runWhen : null,
2254
2264
  });
2255
- });
2256
- }
2257
-
2258
- let AxiosHeaders$1 = class AxiosHeaders {
2259
- constructor(headers) {
2260
- headers && this.set(headers);
2265
+ return this.handlers.length - 1;
2261
2266
  }
2262
2267
 
2263
- set(header, valueOrRewrite, rewrite) {
2264
- const self = this;
2265
-
2266
- function setHeader(_value, _header, _rewrite) {
2267
- const lHeader = normalizeHeader(_header);
2268
-
2269
- if (!lHeader) {
2270
- throw new Error('header name must be a non-empty string');
2271
- }
2268
+ /**
2269
+ * Remove an interceptor from the stack
2270
+ *
2271
+ * @param {Number} id The ID that was returned by `use`
2272
+ *
2273
+ * @returns {void}
2274
+ */
2275
+ eject(id) {
2276
+ if (this.handlers[id]) {
2277
+ this.handlers[id] = null;
2278
+ }
2279
+ }
2272
2280
 
2273
- const key = utils$1.findKey(self, lHeader);
2281
+ /**
2282
+ * Clear all interceptors from the stack
2283
+ *
2284
+ * @returns {void}
2285
+ */
2286
+ clear() {
2287
+ if (this.handlers) {
2288
+ this.handlers = [];
2289
+ }
2290
+ }
2274
2291
 
2275
- if (
2276
- !key ||
2277
- self[key] === undefined ||
2278
- _rewrite === true ||
2279
- (_rewrite === undefined && self[key] !== false)
2280
- ) {
2281
- assertValidHeaderValue(_value, _header);
2282
- self[key || _header] = normalizeValue(_value);
2292
+ /**
2293
+ * Iterate over all the registered interceptors
2294
+ *
2295
+ * This method is particularly useful for skipping over any
2296
+ * interceptors that may have become `null` calling `eject`.
2297
+ *
2298
+ * @param {Function} fn The function to call for each interceptor
2299
+ *
2300
+ * @returns {void}
2301
+ */
2302
+ forEach(fn) {
2303
+ utils$1.forEach(this.handlers, function forEachHandler(h) {
2304
+ if (h !== null) {
2305
+ fn(h);
2283
2306
  }
2284
- }
2307
+ });
2308
+ }
2309
+ }
2285
2310
 
2286
- const setHeaders = (headers, _rewrite) =>
2287
- utils$1.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
2311
+ var transitionalDefaults = {
2312
+ silentJSONParsing: true,
2313
+ forcedJSONParsing: true,
2314
+ clarifyTimeoutError: false,
2315
+ legacyInterceptorReqResOrdering: true,
2316
+ };
2288
2317
 
2289
- if (utils$1.isPlainObject(header) || header instanceof this.constructor) {
2290
- setHeaders(header, valueOrRewrite);
2291
- } else if (utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
2292
- setHeaders(parseHeaders(header), valueOrRewrite);
2293
- } else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
2294
- let obj = {},
2295
- dest,
2296
- key;
2297
- for (const entry of header) {
2298
- if (!utils$1.isArray(entry)) {
2299
- throw TypeError('Object iterator must return a key-value pair');
2300
- }
2318
+ var URLSearchParams$1 = typeof URLSearchParams !== 'undefined' ? URLSearchParams : AxiosURLSearchParams;
2301
2319
 
2302
- obj[(key = entry[0])] = (dest = obj[key])
2303
- ? utils$1.isArray(dest)
2304
- ? [...dest, entry[1]]
2305
- : [dest, entry[1]]
2306
- : entry[1];
2307
- }
2320
+ var FormData$1 = typeof FormData !== 'undefined' ? FormData : null;
2308
2321
 
2309
- setHeaders(obj, valueOrRewrite);
2310
- } else {
2311
- header != null && setHeader(valueOrRewrite, header, rewrite);
2312
- }
2322
+ var Blob$1 = typeof Blob !== 'undefined' ? Blob : null;
2313
2323
 
2314
- return this;
2315
- }
2324
+ var platform$1 = {
2325
+ isBrowser: true,
2326
+ classes: {
2327
+ URLSearchParams: URLSearchParams$1,
2328
+ FormData: FormData$1,
2329
+ Blob: Blob$1,
2330
+ },
2331
+ protocols: ['http', 'https', 'file', 'blob', 'url', 'data'],
2332
+ };
2316
2333
 
2317
- get(header, parser) {
2318
- header = normalizeHeader(header);
2334
+ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
2319
2335
 
2320
- if (header) {
2321
- const key = utils$1.findKey(this, header);
2336
+ const _navigator = (typeof navigator === 'object' && navigator) || undefined;
2322
2337
 
2323
- if (key) {
2324
- const value = this[key];
2338
+ /**
2339
+ * Determine if we're running in a standard browser environment
2340
+ *
2341
+ * This allows axios to run in a web worker, and react-native.
2342
+ * Both environments support XMLHttpRequest, but not fully standard globals.
2343
+ *
2344
+ * web workers:
2345
+ * typeof window -> undefined
2346
+ * typeof document -> undefined
2347
+ *
2348
+ * react-native:
2349
+ * navigator.product -> 'ReactNative'
2350
+ * nativescript
2351
+ * navigator.product -> 'NativeScript' or 'NS'
2352
+ *
2353
+ * @returns {boolean}
2354
+ */
2355
+ const hasStandardBrowserEnv =
2356
+ hasBrowserEnv &&
2357
+ (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
2325
2358
 
2326
- if (!parser) {
2327
- return value;
2328
- }
2359
+ /**
2360
+ * Determine if we're running in a standard browser webWorker environment
2361
+ *
2362
+ * Although the `isStandardBrowserEnv` method indicates that
2363
+ * `allows axios to run in a web worker`, the WebWorker will still be
2364
+ * filtered out due to its judgment standard
2365
+ * `typeof window !== 'undefined' && typeof document !== 'undefined'`.
2366
+ * This leads to a problem when axios post `FormData` in webWorker
2367
+ */
2368
+ const hasStandardBrowserWebWorkerEnv = (() => {
2369
+ return (
2370
+ typeof WorkerGlobalScope !== 'undefined' &&
2371
+ // eslint-disable-next-line no-undef
2372
+ self instanceof WorkerGlobalScope &&
2373
+ typeof self.importScripts === 'function'
2374
+ );
2375
+ })();
2329
2376
 
2330
- if (parser === true) {
2331
- return parseTokens(value);
2332
- }
2377
+ const origin = (hasBrowserEnv && window.location.href) || 'http://localhost';
2333
2378
 
2334
- if (utils$1.isFunction(parser)) {
2335
- return parser.call(this, value, key);
2336
- }
2379
+ var utils = /*#__PURE__*/Object.freeze({
2380
+ __proto__: null,
2381
+ hasBrowserEnv: hasBrowserEnv,
2382
+ hasStandardBrowserEnv: hasStandardBrowserEnv,
2383
+ hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
2384
+ navigator: _navigator,
2385
+ origin: origin
2386
+ });
2337
2387
 
2338
- if (utils$1.isRegExp(parser)) {
2339
- return parser.exec(value);
2340
- }
2388
+ var platform = {
2389
+ ...utils,
2390
+ ...platform$1,
2391
+ };
2341
2392
 
2342
- throw new TypeError('parser must be boolean|regexp|function');
2393
+ function toURLEncodedForm(data, options) {
2394
+ return toFormData$1(data, new platform.classes.URLSearchParams(), {
2395
+ visitor: function (value, key, path, helpers) {
2396
+ if (platform.isNode && utils$1.isBuffer(value)) {
2397
+ this.append(key, value.toString('base64'));
2398
+ return false;
2343
2399
  }
2344
- }
2345
- }
2346
2400
 
2347
- has(header, matcher) {
2348
- header = normalizeHeader(header);
2349
-
2350
- if (header) {
2351
- const key = utils$1.findKey(this, header);
2401
+ return helpers.defaultVisitor.apply(this, arguments);
2402
+ },
2403
+ ...options,
2404
+ });
2405
+ }
2352
2406
 
2353
- return !!(
2354
- key &&
2355
- this[key] !== undefined &&
2356
- (!matcher || matchHeaderValue(this, this[key], key, matcher))
2357
- );
2358
- }
2407
+ /**
2408
+ * It takes a string like `foo[x][y][z]` and returns an array like `['foo', 'x', 'y', 'z']
2409
+ *
2410
+ * @param {string} name - The name of the property to get.
2411
+ *
2412
+ * @returns An array of strings.
2413
+ */
2414
+ function parsePropPath(name) {
2415
+ // foo[x][y][z]
2416
+ // foo.x.y.z
2417
+ // foo-x-y-z
2418
+ // foo x y z
2419
+ return utils$1.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
2420
+ return match[0] === '[]' ? '' : match[1] || match[0];
2421
+ });
2422
+ }
2359
2423
 
2360
- return false;
2424
+ /**
2425
+ * Convert an array to an object.
2426
+ *
2427
+ * @param {Array<any>} arr - The array to convert to an object.
2428
+ *
2429
+ * @returns An object with the same keys and values as the array.
2430
+ */
2431
+ function arrayToObject(arr) {
2432
+ const obj = {};
2433
+ const keys = Object.keys(arr);
2434
+ let i;
2435
+ const len = keys.length;
2436
+ let key;
2437
+ for (i = 0; i < len; i++) {
2438
+ key = keys[i];
2439
+ obj[key] = arr[key];
2361
2440
  }
2441
+ return obj;
2442
+ }
2443
+
2444
+ /**
2445
+ * It takes a FormData object and returns a JavaScript object
2446
+ *
2447
+ * @param {string} formData The FormData object to convert to JSON.
2448
+ *
2449
+ * @returns {Object<string, any> | null} The converted object.
2450
+ */
2451
+ function formDataToJSON(formData) {
2452
+ function buildPath(path, value, target, index) {
2453
+ let name = path[index++];
2362
2454
 
2363
- delete(header, matcher) {
2364
- const self = this;
2365
- let deleted = false;
2455
+ if (name === '__proto__') return true;
2366
2456
 
2367
- function deleteHeader(_header) {
2368
- _header = normalizeHeader(_header);
2457
+ const isNumericKey = Number.isFinite(+name);
2458
+ const isLast = index >= path.length;
2459
+ name = !name && utils$1.isArray(target) ? target.length : name;
2369
2460
 
2370
- if (_header) {
2371
- const key = utils$1.findKey(self, _header);
2461
+ if (isLast) {
2462
+ if (utils$1.hasOwnProp(target, name)) {
2463
+ target[name] = utils$1.isArray(target[name])
2464
+ ? target[name].concat(value)
2465
+ : [target[name], value];
2466
+ } else {
2467
+ target[name] = value;
2468
+ }
2372
2469
 
2373
- if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
2374
- delete self[key];
2470
+ return !isNumericKey;
2471
+ }
2375
2472
 
2376
- deleted = true;
2377
- }
2378
- }
2473
+ if (!utils$1.hasOwnProp(target, name) || !utils$1.isObject(target[name])) {
2474
+ target[name] = [];
2379
2475
  }
2380
2476
 
2381
- if (utils$1.isArray(header)) {
2382
- header.forEach(deleteHeader);
2383
- } else {
2384
- deleteHeader(header);
2477
+ const result = buildPath(path, value, target[name], index);
2478
+
2479
+ if (result && utils$1.isArray(target[name])) {
2480
+ target[name] = arrayToObject(target[name]);
2385
2481
  }
2386
2482
 
2387
- return deleted;
2483
+ return !isNumericKey;
2388
2484
  }
2389
2485
 
2390
- clear(matcher) {
2391
- const keys = Object.keys(this);
2392
- let i = keys.length;
2393
- let deleted = false;
2486
+ if (utils$1.isFormData(formData) && utils$1.isFunction(formData.entries)) {
2487
+ const obj = {};
2394
2488
 
2395
- while (i--) {
2396
- const key = keys[i];
2397
- if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
2398
- delete this[key];
2399
- deleted = true;
2400
- }
2401
- }
2489
+ utils$1.forEachEntry(formData, (name, value) => {
2490
+ buildPath(parsePropPath(name), value, obj, 0);
2491
+ });
2402
2492
 
2403
- return deleted;
2493
+ return obj;
2404
2494
  }
2405
2495
 
2406
- normalize(format) {
2407
- const self = this;
2408
- const headers = {};
2496
+ return null;
2497
+ }
2409
2498
 
2410
- utils$1.forEach(this, (value, header) => {
2411
- const key = utils$1.findKey(headers, header);
2499
+ const own = (obj, key) => (obj != null && utils$1.hasOwnProp(obj, key) ? obj[key] : undefined);
2412
2500
 
2413
- if (key) {
2414
- self[key] = normalizeValue(value);
2415
- delete self[header];
2416
- return;
2501
+ /**
2502
+ * It takes a string, tries to parse it, and if it fails, it returns the stringified version
2503
+ * of the input
2504
+ *
2505
+ * @param {any} rawValue - The value to be stringified.
2506
+ * @param {Function} parser - A function that parses a string into a JavaScript object.
2507
+ * @param {Function} encoder - A function that takes a value and returns a string.
2508
+ *
2509
+ * @returns {string} A stringified version of the rawValue.
2510
+ */
2511
+ function stringifySafely(rawValue, parser, encoder) {
2512
+ if (utils$1.isString(rawValue)) {
2513
+ try {
2514
+ (parser || JSON.parse)(rawValue);
2515
+ return utils$1.trim(rawValue);
2516
+ } catch (e) {
2517
+ if (e.name !== 'SyntaxError') {
2518
+ throw e;
2417
2519
  }
2520
+ }
2521
+ }
2418
2522
 
2419
- const normalized = format ? formatHeader(header) : String(header).trim();
2420
-
2421
- if (normalized !== header) {
2422
- delete self[header];
2423
- }
2523
+ return (encoder || JSON.stringify)(rawValue);
2524
+ }
2424
2525
 
2425
- self[normalized] = normalizeValue(value);
2526
+ const defaults = {
2527
+ transitional: transitionalDefaults,
2426
2528
 
2427
- headers[normalized] = true;
2428
- });
2529
+ adapter: ['xhr', 'http', 'fetch'],
2429
2530
 
2430
- return this;
2431
- }
2531
+ transformRequest: [
2532
+ function transformRequest(data, headers) {
2533
+ const contentType = headers.getContentType() || '';
2534
+ const hasJSONContentType = contentType.indexOf('application/json') > -1;
2535
+ const isObjectPayload = utils$1.isObject(data);
2432
2536
 
2433
- concat(...targets) {
2434
- return this.constructor.concat(this, ...targets);
2435
- }
2537
+ if (isObjectPayload && utils$1.isHTMLForm(data)) {
2538
+ data = new FormData(data);
2539
+ }
2436
2540
 
2437
- toJSON(asStrings) {
2438
- const obj = Object.create(null);
2541
+ const isFormData = utils$1.isFormData(data);
2439
2542
 
2440
- utils$1.forEach(this, (value, header) => {
2441
- value != null &&
2442
- value !== false &&
2443
- (obj[header] = asStrings && utils$1.isArray(value) ? value.join(', ') : value);
2444
- });
2543
+ if (isFormData) {
2544
+ return hasJSONContentType ? JSON.stringify(formDataToJSON(data)) : data;
2545
+ }
2445
2546
 
2446
- return obj;
2447
- }
2547
+ if (
2548
+ utils$1.isArrayBuffer(data) ||
2549
+ utils$1.isBuffer(data) ||
2550
+ utils$1.isStream(data) ||
2551
+ utils$1.isFile(data) ||
2552
+ utils$1.isBlob(data) ||
2553
+ utils$1.isReadableStream(data)
2554
+ ) {
2555
+ return data;
2556
+ }
2557
+ if (utils$1.isArrayBufferView(data)) {
2558
+ return data.buffer;
2559
+ }
2560
+ if (utils$1.isURLSearchParams(data)) {
2561
+ headers.setContentType('application/x-www-form-urlencoded;charset=utf-8', false);
2562
+ return data.toString();
2563
+ }
2448
2564
 
2449
- [Symbol.iterator]() {
2450
- return Object.entries(this.toJSON())[Symbol.iterator]();
2451
- }
2565
+ let isFileList;
2452
2566
 
2453
- toString() {
2454
- return Object.entries(this.toJSON())
2455
- .map(([header, value]) => header + ': ' + value)
2456
- .join('\n');
2457
- }
2567
+ if (isObjectPayload) {
2568
+ const formSerializer = own(this, 'formSerializer');
2569
+ if (contentType.indexOf('application/x-www-form-urlencoded') > -1) {
2570
+ return toURLEncodedForm(data, formSerializer).toString();
2571
+ }
2458
2572
 
2459
- getSetCookie() {
2460
- return this.get('set-cookie') || [];
2461
- }
2573
+ if (
2574
+ (isFileList = utils$1.isFileList(data)) ||
2575
+ contentType.indexOf('multipart/form-data') > -1
2576
+ ) {
2577
+ const env = own(this, 'env');
2578
+ const _FormData = env && env.FormData;
2462
2579
 
2463
- get [Symbol.toStringTag]() {
2464
- return 'AxiosHeaders';
2465
- }
2580
+ return toFormData$1(
2581
+ isFileList ? { 'files[]': data } : data,
2582
+ _FormData && new _FormData(),
2583
+ formSerializer
2584
+ );
2585
+ }
2586
+ }
2466
2587
 
2467
- static from(thing) {
2468
- return thing instanceof this ? thing : new this(thing);
2469
- }
2588
+ if (isObjectPayload || hasJSONContentType) {
2589
+ headers.setContentType('application/json', false);
2590
+ return stringifySafely(data);
2591
+ }
2470
2592
 
2471
- static concat(first, ...targets) {
2472
- const computed = new this(first);
2593
+ return data;
2594
+ },
2595
+ ],
2473
2596
 
2474
- targets.forEach((target) => computed.set(target));
2597
+ transformResponse: [
2598
+ function transformResponse(data) {
2599
+ const transitional = own(this, 'transitional') || defaults.transitional;
2600
+ const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
2601
+ const responseType = own(this, 'responseType');
2602
+ const JSONRequested = responseType === 'json';
2475
2603
 
2476
- return computed;
2477
- }
2604
+ if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
2605
+ return data;
2606
+ }
2478
2607
 
2479
- static accessor(header) {
2480
- const internals =
2481
- (this[$internals] =
2482
- this[$internals] =
2483
- {
2484
- accessors: {},
2485
- });
2608
+ if (
2609
+ data &&
2610
+ utils$1.isString(data) &&
2611
+ ((forcedJSONParsing && !responseType) || JSONRequested)
2612
+ ) {
2613
+ const silentJSONParsing = transitional && transitional.silentJSONParsing;
2614
+ const strictJSONParsing = !silentJSONParsing && JSONRequested;
2486
2615
 
2487
- const accessors = internals.accessors;
2488
- const prototype = this.prototype;
2616
+ try {
2617
+ return JSON.parse(data, own(this, 'parseReviver'));
2618
+ } catch (e) {
2619
+ if (strictJSONParsing) {
2620
+ if (e.name === 'SyntaxError') {
2621
+ throw AxiosError$1.from(e, AxiosError$1.ERR_BAD_RESPONSE, this, null, own(this, 'response'));
2622
+ }
2623
+ throw e;
2624
+ }
2625
+ }
2626
+ }
2489
2627
 
2490
- function defineAccessor(_header) {
2491
- const lHeader = normalizeHeader(_header);
2628
+ return data;
2629
+ },
2630
+ ],
2492
2631
 
2493
- if (!accessors[lHeader]) {
2494
- buildAccessors(prototype, _header);
2495
- accessors[lHeader] = true;
2496
- }
2497
- }
2632
+ /**
2633
+ * A timeout in milliseconds to abort a request. If set to 0 (default) a
2634
+ * timeout is not created.
2635
+ */
2636
+ timeout: 0,
2498
2637
 
2499
- utils$1.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
2638
+ xsrfCookieName: 'XSRF-TOKEN',
2639
+ xsrfHeaderName: 'X-XSRF-TOKEN',
2500
2640
 
2501
- return this;
2502
- }
2503
- };
2641
+ maxContentLength: -1,
2642
+ maxBodyLength: -1,
2504
2643
 
2505
- AxiosHeaders$1.accessor([
2506
- 'Content-Type',
2507
- 'Content-Length',
2508
- 'Accept',
2509
- 'Accept-Encoding',
2510
- 'User-Agent',
2511
- 'Authorization',
2512
- ]);
2644
+ env: {
2645
+ FormData: platform.classes.FormData,
2646
+ Blob: platform.classes.Blob,
2647
+ },
2513
2648
 
2514
- // reserved names hotfix
2515
- utils$1.reduceDescriptors(AxiosHeaders$1.prototype, ({ value }, key) => {
2516
- let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
2517
- return {
2518
- get: () => value,
2519
- set(headerValue) {
2520
- this[mapped] = headerValue;
2649
+ validateStatus: function validateStatus(status) {
2650
+ return status >= 200 && status < 300;
2651
+ },
2652
+
2653
+ headers: {
2654
+ common: {
2655
+ Accept: 'application/json, text/plain, */*',
2656
+ 'Content-Type': undefined,
2521
2657
  },
2522
- };
2523
- });
2658
+ },
2659
+ };
2524
2660
 
2525
- utils$1.freezeMethods(AxiosHeaders$1);
2661
+ utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'query'], (method) => {
2662
+ defaults.headers[method] = {};
2663
+ });
2526
2664
 
2527
2665
  /**
2528
2666
  * Transform the data for a request or a response
@@ -2582,22 +2720,18 @@ function settle(resolve, reject, response) {
2582
2720
  if (!response.status || !validateStatus || validateStatus(response.status)) {
2583
2721
  resolve(response);
2584
2722
  } else {
2585
- reject(
2586
- new AxiosError$1(
2587
- 'Request failed with status code ' + response.status,
2588
- [AxiosError$1.ERR_BAD_REQUEST, AxiosError$1.ERR_BAD_RESPONSE][
2589
- Math.floor(response.status / 100) - 4
2590
- ],
2591
- response.config,
2592
- response.request,
2593
- response
2594
- )
2595
- );
2723
+ reject(new AxiosError$1(
2724
+ 'Request failed with status code ' + response.status,
2725
+ response.status >= 400 && response.status < 500 ? AxiosError$1.ERR_BAD_REQUEST : AxiosError$1.ERR_BAD_RESPONSE,
2726
+ response.config,
2727
+ response.request,
2728
+ response
2729
+ ));
2596
2730
  }
2597
2731
  }
2598
2732
 
2599
2733
  function parseProtocol(url) {
2600
- const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
2734
+ const match = /^([-+\w]{1,25}):(?:\/\/)?/.exec(url);
2601
2735
  return (match && match[1]) || '';
2602
2736
  }
2603
2737
 
@@ -2701,13 +2835,16 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
2701
2835
  const _speedometer = speedometer(50, 250);
2702
2836
 
2703
2837
  return throttle((e) => {
2704
- const loaded = e.loaded;
2838
+ if (!e || typeof e.loaded !== 'number') {
2839
+ return;
2840
+ }
2841
+ const rawLoaded = e.loaded;
2705
2842
  const total = e.lengthComputable ? e.total : undefined;
2706
- const progressBytes = loaded - bytesNotified;
2843
+ const loaded = total != null ? Math.min(rawLoaded, total) : rawLoaded;
2844
+ const progressBytes = Math.max(0, loaded - bytesNotified);
2707
2845
  const rate = _speedometer(progressBytes);
2708
- const inRange = loaded <= total;
2709
2846
 
2710
- bytesNotified = loaded;
2847
+ bytesNotified = Math.max(bytesNotified, loaded);
2711
2848
 
2712
2849
  const data = {
2713
2850
  loaded,
@@ -2715,7 +2852,7 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
2715
2852
  progress: total ? loaded / total : undefined,
2716
2853
  bytes: progressBytes,
2717
2854
  rate: rate ? rate : undefined,
2718
- estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
2855
+ estimated: rate && total ? (total - loaded) / rate : undefined,
2719
2856
  event: e,
2720
2857
  lengthComputable: total != null,
2721
2858
  [isDownloadStream ? 'download' : 'upload']: true,
@@ -2788,8 +2925,20 @@ var cookies = platform.hasStandardBrowserEnv
2788
2925
 
2789
2926
  read(name) {
2790
2927
  if (typeof document === 'undefined') return null;
2791
- const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
2792
- return match ? decodeURIComponent(match[1]) : null;
2928
+ // Match name=value by splitting on the semicolon separator instead of building a
2929
+ // RegExp from `name` interpolating an unescaped string into a RegExp would let
2930
+ // metacharacters (e.g. `.+?` in an attacker-influenced cookie name) cause ReDoS or
2931
+ // match the wrong cookie. Browsers may serialize cookie pairs as either ";" or
2932
+ // "; ", so ignore optional whitespace before each cookie name.
2933
+ const cookies = document.cookie.split(';');
2934
+ for (let i = 0; i < cookies.length; i++) {
2935
+ const cookie = cookies[i].replace(/^\s+/, '');
2936
+ const eq = cookie.indexOf('=');
2937
+ if (eq !== -1 && cookie.slice(0, eq) === name) {
2938
+ return decodeURIComponent(cookie.slice(eq + 1));
2939
+ }
2940
+ }
2941
+ return null;
2793
2942
  },
2794
2943
 
2795
2944
  remove(name) {
@@ -2849,7 +2998,7 @@ function combineURLs(baseURL, relativeURL) {
2849
2998
  */
2850
2999
  function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2851
3000
  let isRelativeUrl = !isAbsoluteURL(requestedURL);
2852
- if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
3001
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
2853
3002
  return combineURLs(baseURL, requestedURL);
2854
3003
  }
2855
3004
  return requestedURL;
@@ -2869,7 +3018,21 @@ const headersToObject = (thing) => (thing instanceof AxiosHeaders$1 ? { ...thing
2869
3018
  function mergeConfig$1(config1, config2) {
2870
3019
  // eslint-disable-next-line no-param-reassign
2871
3020
  config2 = config2 || {};
2872
- const config = {};
3021
+
3022
+ // Use a null-prototype object so that downstream reads such as `config.auth`
3023
+ // or `config.baseURL` cannot inherit polluted values from Object.prototype.
3024
+ // `hasOwnProperty` is restored as a non-enumerable own slot to preserve
3025
+ // ergonomics for user code that relies on it.
3026
+ const config = Object.create(null);
3027
+ Object.defineProperty(config, 'hasOwnProperty', {
3028
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
3029
+ // this data descriptor into an accessor descriptor on the way in.
3030
+ __proto__: null,
3031
+ value: Object.prototype.hasOwnProperty,
3032
+ enumerable: false,
3033
+ writable: true,
3034
+ configurable: true,
3035
+ });
2873
3036
 
2874
3037
  function getMergedValue(target, source, prop, caseless) {
2875
3038
  if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
@@ -2908,9 +3071,9 @@ function mergeConfig$1(config1, config2) {
2908
3071
 
2909
3072
  // eslint-disable-next-line consistent-return
2910
3073
  function mergeDirectKeys(a, b, prop) {
2911
- if (prop in config2) {
3074
+ if (utils$1.hasOwnProp(config2, prop)) {
2912
3075
  return getMergedValue(a, b);
2913
- } else if (prop in config1) {
3076
+ } else if (utils$1.hasOwnProp(config1, prop)) {
2914
3077
  return getMergedValue(undefined, a);
2915
3078
  }
2916
3079
  }
@@ -2942,6 +3105,7 @@ function mergeConfig$1(config1, config2) {
2942
3105
  httpsAgent: defaultToConfig2,
2943
3106
  cancelToken: defaultToConfig2,
2944
3107
  socketPath: defaultToConfig2,
3108
+ allowedSocketPaths: defaultToConfig2,
2945
3109
  responseEncoding: defaultToConfig2,
2946
3110
  validateStatus: mergeDirectKeys,
2947
3111
  headers: (a, b, prop) =>
@@ -2951,22 +3115,64 @@ function mergeConfig$1(config1, config2) {
2951
3115
  utils$1.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
2952
3116
  if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return;
2953
3117
  const merge = utils$1.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
2954
- const configValue = merge(config1[prop], config2[prop], prop);
3118
+ const a = utils$1.hasOwnProp(config1, prop) ? config1[prop] : undefined;
3119
+ const b = utils$1.hasOwnProp(config2, prop) ? config2[prop] : undefined;
3120
+ const configValue = merge(a, b, prop);
2955
3121
  (utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
2956
3122
  });
2957
3123
 
2958
3124
  return config;
2959
3125
  }
2960
3126
 
3127
+ const FORM_DATA_CONTENT_HEADERS = ['content-type', 'content-length'];
3128
+
3129
+ function setFormDataHeaders(headers, formHeaders, policy) {
3130
+ if (policy !== 'content-only') {
3131
+ headers.set(formHeaders);
3132
+ return;
3133
+ }
3134
+
3135
+ Object.entries(formHeaders).forEach(([key, val]) => {
3136
+ if (FORM_DATA_CONTENT_HEADERS.includes(key.toLowerCase())) {
3137
+ headers.set(key, val);
3138
+ }
3139
+ });
3140
+ }
3141
+
3142
+ /**
3143
+ * Encode a UTF-8 string to a Latin-1 byte string for use with btoa().
3144
+ * This is a modern replacement for the deprecated unescape(encodeURIComponent(str)) pattern.
3145
+ *
3146
+ * @param {string} str The string to encode
3147
+ *
3148
+ * @returns {string} UTF-8 bytes as a Latin-1 string
3149
+ */
3150
+ const encodeUTF8 = (str) =>
3151
+ encodeURIComponent(str).replace(/%([0-9A-F]{2})/gi, (_, hex) =>
3152
+ String.fromCharCode(parseInt(hex, 16))
3153
+ );
3154
+
2961
3155
  var resolveConfig = (config) => {
2962
3156
  const newConfig = mergeConfig$1({}, config);
2963
3157
 
2964
- let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
3158
+ // Read only own properties to prevent prototype pollution gadgets
3159
+ // (e.g. Object.prototype.baseURL = 'https://evil.com').
3160
+ const own = (key) => (utils$1.hasOwnProp(newConfig, key) ? newConfig[key] : undefined);
3161
+
3162
+ const data = own('data');
3163
+ let withXSRFToken = own('withXSRFToken');
3164
+ const xsrfHeaderName = own('xsrfHeaderName');
3165
+ const xsrfCookieName = own('xsrfCookieName');
3166
+ let headers = own('headers');
3167
+ const auth = own('auth');
3168
+ const baseURL = own('baseURL');
3169
+ const allowAbsoluteUrls = own('allowAbsoluteUrls');
3170
+ const url = own('url');
2965
3171
 
2966
3172
  newConfig.headers = headers = AxiosHeaders$1.from(headers);
2967
3173
 
2968
3174
  newConfig.url = buildURL(
2969
- buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls),
3175
+ buildFullPath(baseURL, url, allowAbsoluteUrls),
2970
3176
  config.params,
2971
3177
  config.paramsSerializer
2972
3178
  );
@@ -2976,11 +3182,7 @@ var resolveConfig = (config) => {
2976
3182
  headers.set(
2977
3183
  'Authorization',
2978
3184
  'Basic ' +
2979
- btoa(
2980
- (auth.username || '') +
2981
- ':' +
2982
- (auth.password ? unescape(encodeURIComponent(auth.password)) : '')
2983
- )
3185
+ btoa((auth.username || '') + ':' + (auth.password ? encodeUTF8(auth.password) : ''))
2984
3186
  );
2985
3187
  }
2986
3188
 
@@ -2989,14 +3191,7 @@ var resolveConfig = (config) => {
2989
3191
  headers.setContentType(undefined); // browser handles it
2990
3192
  } else if (utils$1.isFunction(data.getHeaders)) {
2991
3193
  // Node.js FormData (like form-data package)
2992
- const formHeaders = data.getHeaders();
2993
- // Only set safe headers to avoid overwriting security headers
2994
- const allowedHeaders = ['content-type', 'content-length'];
2995
- Object.entries(formHeaders).forEach(([key, val]) => {
2996
- if (allowedHeaders.includes(key.toLowerCase())) {
2997
- headers.set(key, val);
2998
- }
2999
- });
3194
+ setFormDataHeaders(headers, data.getHeaders(), own('formDataHeaderPolicy'));
3000
3195
  }
3001
3196
  }
3002
3197
 
@@ -3005,10 +3200,17 @@ var resolveConfig = (config) => {
3005
3200
  // Specifically not if we're in a web worker, or react-native.
3006
3201
 
3007
3202
  if (platform.hasStandardBrowserEnv) {
3008
- withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
3203
+ if (utils$1.isFunction(withXSRFToken)) {
3204
+ withXSRFToken = withXSRFToken(newConfig);
3205
+ }
3206
+
3207
+ // Strict boolean check — prevents proto-pollution gadgets (e.g. Object.prototype.withXSRFToken = 1)
3208
+ // and misconfigurations (e.g. "false") from short-circuiting the same-origin check and leaking
3209
+ // the XSRF token cross-origin.
3210
+ const shouldSendXSRF =
3211
+ withXSRFToken === true || (withXSRFToken == null && isURLSameOrigin(newConfig.url));
3009
3212
 
3010
- if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
3011
- // Add xsrf header
3213
+ if (shouldSendXSRF) {
3012
3214
  const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
3013
3215
 
3014
3216
  if (xsrfValue) {
@@ -3102,7 +3304,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3102
3304
  // will return status as 0 even though it's a successful request
3103
3305
  if (
3104
3306
  request.status === 0 &&
3105
- !(request.responseURL && request.responseURL.indexOf('file:') === 0)
3307
+ !(request.responseURL && request.responseURL.startsWith('file:'))
3106
3308
  ) {
3107
3309
  return;
3108
3310
  }
@@ -3119,6 +3321,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3119
3321
  }
3120
3322
 
3121
3323
  reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED, config, request));
3324
+ done();
3122
3325
 
3123
3326
  // Clean up request
3124
3327
  request = null;
@@ -3134,6 +3337,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3134
3337
  // attach the underlying event for consumers who want details
3135
3338
  err.event = event || null;
3136
3339
  reject(err);
3340
+ done();
3137
3341
  request = null;
3138
3342
  };
3139
3343
 
@@ -3154,6 +3358,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3154
3358
  request
3155
3359
  )
3156
3360
  );
3361
+ done();
3157
3362
 
3158
3363
  // Clean up request
3159
3364
  request = null;
@@ -3164,7 +3369,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3164
3369
 
3165
3370
  // Add headers to the request
3166
3371
  if ('setRequestHeader' in request) {
3167
- utils$1.forEach(requestHeaders.toJSON(), function setRequestHeader(val, key) {
3372
+ utils$1.forEach(toByteStringHeaderObject(requestHeaders), function setRequestHeader(val, key) {
3168
3373
  request.setRequestHeader(key, val);
3169
3374
  });
3170
3375
  }
@@ -3203,6 +3408,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3203
3408
  }
3204
3409
  reject(!cancel || cancel.type ? new CanceledError$1(null, config, request) : cancel);
3205
3410
  request.abort();
3411
+ done();
3206
3412
  request = null;
3207
3413
  };
3208
3414
 
@@ -3216,7 +3422,7 @@ var xhrAdapter = isXHRAdapterSupported &&
3216
3422
 
3217
3423
  const protocol = parseProtocol(_config.url);
3218
3424
 
3219
- if (protocol && platform.protocols.indexOf(protocol) === -1) {
3425
+ if (protocol && !platform.protocols.includes(protocol)) {
3220
3426
  reject(
3221
3427
  new AxiosError$1(
3222
3428
  'Unsupported protocol ' + protocol + ':',
@@ -3233,54 +3439,55 @@ var xhrAdapter = isXHRAdapterSupported &&
3233
3439
  };
3234
3440
 
3235
3441
  const composeSignals = (signals, timeout) => {
3236
- const { length } = (signals = signals ? signals.filter(Boolean) : []);
3237
-
3238
- if (timeout || length) {
3239
- let controller = new AbortController();
3240
-
3241
- let aborted;
3242
-
3243
- const onabort = function (reason) {
3244
- if (!aborted) {
3245
- aborted = true;
3246
- unsubscribe();
3247
- const err = reason instanceof Error ? reason : this.reason;
3248
- controller.abort(
3249
- err instanceof AxiosError$1
3250
- ? err
3251
- : new CanceledError$1(err instanceof Error ? err.message : err)
3252
- );
3253
- }
3254
- };
3442
+ signals = signals ? signals.filter(Boolean) : [];
3255
3443
 
3256
- let timer =
3257
- timeout &&
3258
- setTimeout(() => {
3259
- timer = null;
3260
- onabort(new AxiosError$1(`timeout of ${timeout}ms exceeded`, AxiosError$1.ETIMEDOUT));
3261
- }, timeout);
3262
-
3263
- const unsubscribe = () => {
3264
- if (signals) {
3265
- timer && clearTimeout(timer);
3266
- timer = null;
3267
- signals.forEach((signal) => {
3268
- signal.unsubscribe
3269
- ? signal.unsubscribe(onabort)
3270
- : signal.removeEventListener('abort', onabort);
3271
- });
3272
- signals = null;
3273
- }
3274
- };
3444
+ if (!timeout && !signals.length) {
3445
+ return;
3446
+ }
3447
+
3448
+ const controller = new AbortController();
3449
+
3450
+ let aborted = false;
3275
3451
 
3276
- signals.forEach((signal) => signal.addEventListener('abort', onabort));
3452
+ const onabort = function (reason) {
3453
+ if (!aborted) {
3454
+ aborted = true;
3455
+ unsubscribe();
3456
+ const err = reason instanceof Error ? reason : this.reason;
3457
+ controller.abort(
3458
+ err instanceof AxiosError$1
3459
+ ? err
3460
+ : new CanceledError$1(err instanceof Error ? err.message : err)
3461
+ );
3462
+ }
3463
+ };
3464
+
3465
+ let timer =
3466
+ timeout &&
3467
+ setTimeout(() => {
3468
+ timer = null;
3469
+ onabort(new AxiosError$1(`timeout of ${timeout}ms exceeded`, AxiosError$1.ETIMEDOUT));
3470
+ }, timeout);
3471
+
3472
+ const unsubscribe = () => {
3473
+ if (!signals) { return; }
3474
+ timer && clearTimeout(timer);
3475
+ timer = null;
3476
+ signals.forEach((signal) => {
3477
+ signal.unsubscribe
3478
+ ? signal.unsubscribe(onabort)
3479
+ : signal.removeEventListener('abort', onabort);
3480
+ });
3481
+ signals = null;
3482
+ };
3277
3483
 
3278
- const { signal } = controller;
3484
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
3279
3485
 
3280
- signal.unsubscribe = () => utils$1.asap(unsubscribe);
3486
+ const { signal } = controller;
3281
3487
 
3282
- return signal;
3283
- }
3488
+ signal.unsubscribe = () => utils$1.asap(unsubscribe);
3489
+
3490
+ return signal;
3284
3491
  };
3285
3492
 
3286
3493
  const streamChunk = function* (chunk, chunkSize) {
@@ -3373,16 +3580,112 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
3373
3580
  );
3374
3581
  };
3375
3582
 
3376
- const DEFAULT_CHUNK_SIZE = 64 * 1024;
3583
+ /**
3584
+ * Estimate decoded byte length of a data:// URL *without* allocating large buffers.
3585
+ * - For base64: compute exact decoded size using length and padding;
3586
+ * handle %XX at the character-count level (no string allocation).
3587
+ * - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
3588
+ *
3589
+ * @param {string} url
3590
+ * @returns {number}
3591
+ */
3592
+ function estimateDataURLDecodedBytes(url) {
3593
+ if (!url || typeof url !== 'string') return 0;
3594
+ if (!url.startsWith('data:')) return 0;
3377
3595
 
3378
- const { isFunction } = utils$1;
3596
+ const comma = url.indexOf(',');
3597
+ if (comma < 0) return 0;
3598
+
3599
+ const meta = url.slice(5, comma);
3600
+ const body = url.slice(comma + 1);
3601
+ const isBase64 = /;base64/i.test(meta);
3602
+
3603
+ if (isBase64) {
3604
+ let effectiveLen = body.length;
3605
+ const len = body.length; // cache length
3606
+
3607
+ for (let i = 0; i < len; i++) {
3608
+ if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
3609
+ const a = body.charCodeAt(i + 1);
3610
+ const b = body.charCodeAt(i + 2);
3611
+ const isHex =
3612
+ ((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
3613
+ ((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
3614
+
3615
+ if (isHex) {
3616
+ effectiveLen -= 2;
3617
+ i += 2;
3618
+ }
3619
+ }
3620
+ }
3621
+
3622
+ let pad = 0;
3623
+ let idx = len - 1;
3624
+
3625
+ const tailIsPct3D = (j) =>
3626
+ j >= 2 &&
3627
+ body.charCodeAt(j - 2) === 37 && // '%'
3628
+ body.charCodeAt(j - 1) === 51 && // '3'
3629
+ (body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
3630
+
3631
+ if (idx >= 0) {
3632
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
3633
+ pad++;
3634
+ idx--;
3635
+ } else if (tailIsPct3D(idx)) {
3636
+ pad++;
3637
+ idx -= 3;
3638
+ }
3639
+ }
3640
+
3641
+ if (pad === 1 && idx >= 0) {
3642
+ if (body.charCodeAt(idx) === 61 /* '=' */) {
3643
+ pad++;
3644
+ } else if (tailIsPct3D(idx)) {
3645
+ pad++;
3646
+ }
3647
+ }
3648
+
3649
+ const groups = Math.floor(effectiveLen / 4);
3650
+ const bytes = groups * 3 - (pad || 0);
3651
+ return bytes > 0 ? bytes : 0;
3652
+ }
3653
+
3654
+ if (typeof Buffer !== 'undefined' && typeof Buffer.byteLength === 'function') {
3655
+ return Buffer.byteLength(body, 'utf8');
3656
+ }
3657
+
3658
+ // Compute UTF-8 byte length directly from UTF-16 code units without allocating
3659
+ // a byte buffer (TextEncoder.encode would defeat the DoS guard on large bodies).
3660
+ // Using body.length here would undercount non-ASCII (e.g. '€' is 1 code unit
3661
+ // but 3 UTF-8 bytes).
3662
+ let bytes = 0;
3663
+ for (let i = 0, len = body.length; i < len; i++) {
3664
+ const c = body.charCodeAt(i);
3665
+ if (c < 0x80) {
3666
+ bytes += 1;
3667
+ } else if (c < 0x800) {
3668
+ bytes += 2;
3669
+ } else if (c >= 0xd800 && c <= 0xdbff && i + 1 < len) {
3670
+ const next = body.charCodeAt(i + 1);
3671
+ if (next >= 0xdc00 && next <= 0xdfff) {
3672
+ bytes += 4;
3673
+ i++;
3674
+ } else {
3675
+ bytes += 3;
3676
+ }
3677
+ } else {
3678
+ bytes += 3;
3679
+ }
3680
+ }
3681
+ return bytes;
3682
+ }
3683
+
3684
+ const VERSION$1 = "1.16.1";
3379
3685
 
3380
- const globalFetchAPI = (({ Request, Response }) => ({
3381
- Request,
3382
- Response,
3383
- }))(utils$1.global);
3686
+ const DEFAULT_CHUNK_SIZE = 64 * 1024;
3384
3687
 
3385
- const { ReadableStream: ReadableStream$1, TextEncoder } = utils$1.global;
3688
+ const { isFunction } = utils$1;
3386
3689
 
3387
3690
  const test = (fn, ...args) => {
3388
3691
  try {
@@ -3393,11 +3696,20 @@ const test = (fn, ...args) => {
3393
3696
  };
3394
3697
 
3395
3698
  const factory = (env) => {
3699
+ const globalObject =
3700
+ utils$1.global !== undefined && utils$1.global !== null
3701
+ ? utils$1.global
3702
+ : globalThis;
3703
+ const { ReadableStream, TextEncoder } = globalObject;
3704
+
3396
3705
  env = utils$1.merge.call(
3397
3706
  {
3398
3707
  skipUndefined: true,
3399
3708
  },
3400
- globalFetchAPI,
3709
+ {
3710
+ Request: globalObject.Request,
3711
+ Response: globalObject.Response,
3712
+ },
3401
3713
  env
3402
3714
  );
3403
3715
 
@@ -3410,7 +3722,7 @@ const factory = (env) => {
3410
3722
  return false;
3411
3723
  }
3412
3724
 
3413
- const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
3725
+ const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream);
3414
3726
 
3415
3727
  const encodeText =
3416
3728
  isFetchSupported &&
@@ -3427,18 +3739,20 @@ const factory = (env) => {
3427
3739
  test(() => {
3428
3740
  let duplexAccessed = false;
3429
3741
 
3430
- const body = new ReadableStream$1();
3431
-
3432
- const hasContentType = new Request(platform.origin, {
3433
- body,
3742
+ const request = new Request(platform.origin, {
3743
+ body: new ReadableStream(),
3434
3744
  method: 'POST',
3435
3745
  get duplex() {
3436
3746
  duplexAccessed = true;
3437
3747
  return 'half';
3438
3748
  },
3439
- }).headers.has('Content-Type');
3749
+ });
3440
3750
 
3441
- body.cancel();
3751
+ const hasContentType = request.headers.has('Content-Type');
3752
+
3753
+ if (request.body != null) {
3754
+ request.body.cancel();
3755
+ }
3442
3756
 
3443
3757
  return duplexAccessed && !hasContentType;
3444
3758
  });
@@ -3522,8 +3836,13 @@ const factory = (env) => {
3522
3836
  headers,
3523
3837
  withCredentials = 'same-origin',
3524
3838
  fetchOptions,
3839
+ maxContentLength,
3840
+ maxBodyLength,
3525
3841
  } = resolveConfig(config);
3526
3842
 
3843
+ const hasMaxContentLength = utils$1.isNumber(maxContentLength) && maxContentLength > -1;
3844
+ const hasMaxBodyLength = utils$1.isNumber(maxBodyLength) && maxBodyLength > -1;
3845
+
3527
3846
  let _fetch = envFetch || fetch;
3528
3847
 
3529
3848
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
@@ -3545,6 +3864,41 @@ const factory = (env) => {
3545
3864
  let requestContentLength;
3546
3865
 
3547
3866
  try {
3867
+ // Enforce maxContentLength for data: URLs up-front so we never materialize
3868
+ // an oversized payload. The HTTP adapter applies the same check (see http.js
3869
+ // "if (protocol === 'data:')" branch).
3870
+ if (hasMaxContentLength && typeof url === 'string' && url.startsWith('data:')) {
3871
+ const estimated = estimateDataURLDecodedBytes(url);
3872
+ if (estimated > maxContentLength) {
3873
+ throw new AxiosError$1(
3874
+ 'maxContentLength size of ' + maxContentLength + ' exceeded',
3875
+ AxiosError$1.ERR_BAD_RESPONSE,
3876
+ config,
3877
+ request
3878
+ );
3879
+ }
3880
+ }
3881
+
3882
+ // Enforce maxBodyLength against the outbound request body before dispatch.
3883
+ // Mirrors http.js behavior (ERR_BAD_REQUEST / 'Request body larger than
3884
+ // maxBodyLength limit'). Skip when the body length cannot be determined
3885
+ // (e.g. a live ReadableStream supplied by the caller).
3886
+ if (hasMaxBodyLength && method !== 'get' && method !== 'head') {
3887
+ const outboundLength = await resolveBodyLength(headers, data);
3888
+ if (
3889
+ typeof outboundLength === 'number' &&
3890
+ isFinite(outboundLength) &&
3891
+ outboundLength > maxBodyLength
3892
+ ) {
3893
+ throw new AxiosError$1(
3894
+ 'Request body larger than maxBodyLength limit',
3895
+ AxiosError$1.ERR_BAD_REQUEST,
3896
+ config,
3897
+ request
3898
+ );
3899
+ }
3900
+ }
3901
+
3548
3902
  if (
3549
3903
  onUploadProgress &&
3550
3904
  supportsRequestStream &&
@@ -3582,11 +3936,27 @@ const factory = (env) => {
3582
3936
  // see https://github.com/cloudflare/workerd/issues/902
3583
3937
  const isCredentialsSupported = isRequestSupported && 'credentials' in Request.prototype;
3584
3938
 
3939
+ // If data is FormData and Content-Type is multipart/form-data without boundary,
3940
+ // delete it so fetch can set it correctly with the boundary
3941
+ if (utils$1.isFormData(data)) {
3942
+ const contentType = headers.getContentType();
3943
+ if (
3944
+ contentType &&
3945
+ /^multipart\/form-data/i.test(contentType) &&
3946
+ !/boundary=/i.test(contentType)
3947
+ ) {
3948
+ headers.delete('content-type');
3949
+ }
3950
+ }
3951
+
3952
+ // Set User-Agent header if not already set (fetch defaults to 'node' in Node.js)
3953
+ headers.set('User-Agent', 'axios/' + VERSION$1, false);
3954
+
3585
3955
  const resolvedOptions = {
3586
3956
  ...fetchOptions,
3587
3957
  signal: composedSignal,
3588
3958
  method: method.toUpperCase(),
3589
- headers: headers.normalize().toJSON(),
3959
+ headers: toByteStringHeaderObject(headers.normalize()),
3590
3960
  body: data,
3591
3961
  duplex: 'half',
3592
3962
  credentials: isCredentialsSupported ? withCredentials : undefined,
@@ -3598,10 +3968,28 @@ const factory = (env) => {
3598
3968
  ? _fetch(request, fetchOptions)
3599
3969
  : _fetch(url, resolvedOptions));
3600
3970
 
3971
+ // Cheap pre-check: if the server honestly declares a content-length that
3972
+ // already exceeds the cap, reject before we start streaming.
3973
+ if (hasMaxContentLength) {
3974
+ const declaredLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
3975
+ if (declaredLength != null && declaredLength > maxContentLength) {
3976
+ throw new AxiosError$1(
3977
+ 'maxContentLength size of ' + maxContentLength + ' exceeded',
3978
+ AxiosError$1.ERR_BAD_RESPONSE,
3979
+ config,
3980
+ request
3981
+ );
3982
+ }
3983
+ }
3984
+
3601
3985
  const isStreamResponse =
3602
3986
  supportsResponseStream && (responseType === 'stream' || responseType === 'response');
3603
3987
 
3604
- if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
3988
+ if (
3989
+ supportsResponseStream &&
3990
+ response.body &&
3991
+ (onDownloadProgress || hasMaxContentLength || (isStreamResponse && unsubscribe))
3992
+ ) {
3605
3993
  const options = {};
3606
3994
 
3607
3995
  ['status', 'statusText', 'headers'].forEach((prop) => {
@@ -3618,8 +4006,24 @@ const factory = (env) => {
3618
4006
  )) ||
3619
4007
  [];
3620
4008
 
4009
+ let bytesRead = 0;
4010
+ const onChunkProgress = (loadedBytes) => {
4011
+ if (hasMaxContentLength) {
4012
+ bytesRead = loadedBytes;
4013
+ if (bytesRead > maxContentLength) {
4014
+ throw new AxiosError$1(
4015
+ 'maxContentLength size of ' + maxContentLength + ' exceeded',
4016
+ AxiosError$1.ERR_BAD_RESPONSE,
4017
+ config,
4018
+ request
4019
+ );
4020
+ }
4021
+ }
4022
+ onProgress && onProgress(loadedBytes);
4023
+ };
4024
+
3621
4025
  response = new Response(
3622
- trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
4026
+ trackStream(response.body, DEFAULT_CHUNK_SIZE, onChunkProgress, () => {
3623
4027
  flush && flush();
3624
4028
  unsubscribe && unsubscribe();
3625
4029
  }),
@@ -3634,6 +4038,33 @@ const factory = (env) => {
3634
4038
  config
3635
4039
  );
3636
4040
 
4041
+ // Fallback enforcement for environments without ReadableStream support
4042
+ // (legacy runtimes). Detect materialized size from typed output; skip
4043
+ // streams/Response passthrough since the user will read those themselves.
4044
+ if (hasMaxContentLength && !supportsResponseStream && !isStreamResponse) {
4045
+ let materializedSize;
4046
+ if (responseData != null) {
4047
+ if (typeof responseData.byteLength === 'number') {
4048
+ materializedSize = responseData.byteLength;
4049
+ } else if (typeof responseData.size === 'number') {
4050
+ materializedSize = responseData.size;
4051
+ } else if (typeof responseData === 'string') {
4052
+ materializedSize =
4053
+ typeof TextEncoder === 'function'
4054
+ ? new TextEncoder().encode(responseData).byteLength
4055
+ : responseData.length;
4056
+ }
4057
+ }
4058
+ if (typeof materializedSize === 'number' && materializedSize > maxContentLength) {
4059
+ throw new AxiosError$1(
4060
+ 'maxContentLength size of ' + maxContentLength + ' exceeded',
4061
+ AxiosError$1.ERR_BAD_RESPONSE,
4062
+ config,
4063
+ request
4064
+ );
4065
+ }
4066
+ }
4067
+
3637
4068
  !isStreamResponse && unsubscribe && unsubscribe();
3638
4069
 
3639
4070
  return await new Promise((resolve, reject) => {
@@ -3649,6 +4080,17 @@ const factory = (env) => {
3649
4080
  } catch (err) {
3650
4081
  unsubscribe && unsubscribe();
3651
4082
 
4083
+ // Safari can surface fetch aborts as a DOMException-like object whose
4084
+ // branded getters throw. Prefer our composed signal reason before reading
4085
+ // the caught error, preserving timeout vs cancellation semantics.
4086
+ if (composedSignal && composedSignal.aborted && composedSignal.reason instanceof AxiosError$1) {
4087
+ const canceledError = composedSignal.reason;
4088
+ canceledError.config = config;
4089
+ request && (canceledError.request = request);
4090
+ err !== canceledError && (canceledError.cause = err);
4091
+ throw canceledError;
4092
+ }
4093
+
3652
4094
  if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
3653
4095
  throw Object.assign(
3654
4096
  new AxiosError$1(
@@ -3717,11 +4159,13 @@ const knownAdapters = {
3717
4159
  utils$1.forEach(knownAdapters, (fn, value) => {
3718
4160
  if (fn) {
3719
4161
  try {
3720
- Object.defineProperty(fn, 'name', { value });
4162
+ // Null-proto descriptors so a polluted Object.prototype.get cannot turn
4163
+ // these data descriptors into accessor descriptors on the way in.
4164
+ Object.defineProperty(fn, 'name', { __proto__: null, value });
3721
4165
  } catch (e) {
3722
4166
  // eslint-disable-next-line no-empty
3723
4167
  }
3724
- Object.defineProperty(fn, 'adapterName', { value });
4168
+ Object.defineProperty(fn, 'adapterName', { __proto__: null, value });
3725
4169
  }
3726
4170
  });
3727
4171
 
@@ -3863,8 +4307,15 @@ function dispatchRequest(config) {
3863
4307
  function onAdapterResolution(response) {
3864
4308
  throwIfCancellationRequested(config);
3865
4309
 
3866
- // Transform response data
3867
- response.data = transformData.call(config, config.transformResponse, response);
4310
+ // Expose the current response on config so that transformResponse can
4311
+ // attach it to any AxiosError it throws (e.g. on JSON parse failure).
4312
+ // We clean it up afterwards to avoid polluting the config object.
4313
+ config.response = response;
4314
+ try {
4315
+ response.data = transformData.call(config, config.transformResponse, response);
4316
+ } finally {
4317
+ delete config.response;
4318
+ }
3868
4319
 
3869
4320
  response.headers = AxiosHeaders$1.from(response.headers);
3870
4321
 
@@ -3876,11 +4327,16 @@ function dispatchRequest(config) {
3876
4327
 
3877
4328
  // Transform response data
3878
4329
  if (reason && reason.response) {
3879
- reason.response.data = transformData.call(
3880
- config,
3881
- config.transformResponse,
3882
- reason.response
3883
- );
4330
+ config.response = reason.response;
4331
+ try {
4332
+ reason.response.data = transformData.call(
4333
+ config,
4334
+ config.transformResponse,
4335
+ reason.response
4336
+ );
4337
+ } finally {
4338
+ delete config.response;
4339
+ }
3884
4340
  reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
3885
4341
  }
3886
4342
  }
@@ -3890,8 +4346,6 @@ function dispatchRequest(config) {
3890
4346
  );
3891
4347
  }
3892
4348
 
3893
- const VERSION$1 = "1.15.0";
3894
-
3895
4349
  const validators$1 = {};
3896
4350
 
3897
4351
  // eslint-disable-next-line func-names
@@ -3975,7 +4429,9 @@ function assertOptions(options, schema, allowUnknown) {
3975
4429
  let i = keys.length;
3976
4430
  while (i-- > 0) {
3977
4431
  const opt = keys[i];
3978
- const validator = schema[opt];
4432
+ // Use hasOwnProperty so a polluted Object.prototype.<opt> cannot supply
4433
+ // a non-function validator and cause a TypeError.
4434
+ const validator = Object.prototype.hasOwnProperty.call(schema, opt) ? schema[opt] : undefined;
3979
4435
  if (validator) {
3980
4436
  const value = options[opt];
3981
4437
  const result = value === undefined || validator(value, opt, options);
@@ -4134,7 +4590,7 @@ let Axios$1 = class Axios {
4134
4590
  let contextHeaders = headers && utils$1.merge(headers.common, headers[config.method]);
4135
4591
 
4136
4592
  headers &&
4137
- utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'common'], (method) => {
4593
+ utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch', 'query', 'common'], (method) => {
4138
4594
  delete headers[method];
4139
4595
  });
4140
4596
 
@@ -4237,7 +4693,7 @@ utils$1.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoDa
4237
4693
  };
4238
4694
  });
4239
4695
 
4240
- utils$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
4696
+ utils$1.forEach(['post', 'put', 'patch', 'query'], function forEachMethodWithData(method) {
4241
4697
  function generateHTTPMethod(isForm) {
4242
4698
  return function httpMethod(url, data, config) {
4243
4699
  return this.request(
@@ -4257,7 +4713,11 @@ utils$1.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method)
4257
4713
 
4258
4714
  Axios$1.prototype[method] = generateHTTPMethod();
4259
4715
 
4260
- Axios$1.prototype[method + 'Form'] = generateHTTPMethod(true);
4716
+ // QUERY is a safe/idempotent read method; multipart form bodies don't fit
4717
+ // its semantics, so no queryForm shorthand is generated.
4718
+ if (method !== 'query') {
4719
+ Axios$1.prototype[method + 'Form'] = generateHTTPMethod(true);
4720
+ }
4261
4721
  });
4262
4722
 
4263
4723
  /**
@@ -4591,6 +5051,7 @@ const {
4591
5051
  formToJSON,
4592
5052
  getAdapter,
4593
5053
  mergeConfig,
5054
+ create,
4594
5055
  } = axios;
4595
5056
 
4596
5057
  /******************************************************************************
@@ -7678,10 +8139,255 @@ class MayachainProtocol {
7678
8139
  }
7679
8140
  }
7680
8141
 
8142
+ const BASE_URL = 'https://1click.chaindefuser.com';
8143
+ class OneClickApi {
8144
+ constructor(apiKey) {
8145
+ this.headers = { 'Content-Type': 'application/json' };
8146
+ if (apiKey) {
8147
+ this.headers['Authorization'] = `Bearer ${apiKey}`;
8148
+ }
8149
+ }
8150
+ getTokens() {
8151
+ return __awaiter$4(this, void 0, void 0, function* () {
8152
+ const resp = yield fetch(`${BASE_URL}/v0/tokens`, { headers: this.headers });
8153
+ if (!resp.ok)
8154
+ throw new Error(`1Click getTokens failed: ${resp.status}`);
8155
+ return resp.json();
8156
+ });
8157
+ }
8158
+ getQuote(params) {
8159
+ return __awaiter$4(this, void 0, void 0, function* () {
8160
+ const resp = yield fetch(`${BASE_URL}/v0/quote`, {
8161
+ method: 'POST',
8162
+ headers: this.headers,
8163
+ body: JSON.stringify(params),
8164
+ });
8165
+ if (!resp.ok)
8166
+ throw new Error(`1Click getQuote failed: ${resp.status}`);
8167
+ return resp.json();
8168
+ });
8169
+ }
8170
+ submitDeposit(txHash, depositAddress) {
8171
+ return __awaiter$4(this, void 0, void 0, function* () {
8172
+ yield fetch(`${BASE_URL}/v0/deposit/submit`, {
8173
+ method: 'POST',
8174
+ headers: this.headers,
8175
+ body: JSON.stringify({ txHash, depositAddress }),
8176
+ }).catch(() => {
8177
+ // Fire-and-forget
8178
+ });
8179
+ });
8180
+ }
8181
+ }
8182
+
8183
+ const X_TO_ONECLICK = {
8184
+ BTC: 'btc',
8185
+ ETH: 'eth',
8186
+ ARB: 'arb',
8187
+ AVAX: 'avax',
8188
+ BSC: 'bsc',
8189
+ SOL: 'sol',
8190
+ DOGE: 'doge',
8191
+ DASH: 'dash',
8192
+ LTC: 'ltc',
8193
+ BCH: 'bch',
8194
+ XRP: 'xrp',
8195
+ ADA: 'cardano',
8196
+ SUI: 'sui',
8197
+ };
8198
+ const ONECLICK_TO_X = Object.fromEntries(Object.entries(X_TO_ONECLICK).map(([k, v]) => [v, k]));
8199
+ const xChainToOneClickBlockchain = (chain) => {
8200
+ var _a;
8201
+ return (_a = X_TO_ONECLICK[chain]) !== null && _a !== void 0 ? _a : null;
8202
+ };
8203
+ const oneClickBlockchainToXChain = (blockchain) => {
8204
+ var _a;
8205
+ return (_a = ONECLICK_TO_X[blockchain]) !== null && _a !== void 0 ? _a : null;
8206
+ };
8207
+ const findOneClickToken = (asset, tokens) => {
8208
+ if (isSynthAsset(asset) || isTradeAsset(asset) || isSecuredAsset(asset))
8209
+ return undefined;
8210
+ const blockchain = xChainToOneClickBlockchain(asset.chain);
8211
+ if (!blockchain)
8212
+ return undefined;
8213
+ return tokens.find((token) => {
8214
+ if (token.blockchain !== blockchain)
8215
+ return false;
8216
+ if (isTokenAsset(asset)) {
8217
+ // Match by contract address (case-insensitive)
8218
+ const assetContract = asset.symbol.includes('-') ? asset.symbol.split('-')[1] : undefined;
8219
+ return assetContract && token.contractAddress
8220
+ ? token.contractAddress.toLowerCase() === assetContract.toLowerCase()
8221
+ : false;
8222
+ }
8223
+ // Native asset: match by symbol, ensure no contract address on token
8224
+ return token.symbol.toUpperCase() === asset.symbol.toUpperCase() && !token.contractAddress;
8225
+ });
8226
+ };
8227
+
8228
+ class OneClickProtocol {
8229
+ constructor(configuration) {
8230
+ this.name = 'OneClick';
8231
+ this.api = new OneClickApi(configuration === null || configuration === void 0 ? void 0 : configuration.oneClickApiKey);
8232
+ this.wallet = configuration === null || configuration === void 0 ? void 0 : configuration.wallet;
8233
+ this.affiliateAddress = configuration === null || configuration === void 0 ? void 0 : configuration.affiliateAddress;
8234
+ this.affiliateBps = configuration === null || configuration === void 0 ? void 0 : configuration.affiliateBps;
8235
+ this.tokensCache = new CachedValue(() => this.api.getTokens(), 24 * 60 * 60 * 1000);
8236
+ }
8237
+ approveRouterToSpend(_params) {
8238
+ return __awaiter$4(this, void 0, void 0, function* () {
8239
+ throw new Error('Not implemented');
8240
+ });
8241
+ }
8242
+ shouldBeApproved(_params) {
8243
+ return __awaiter$4(this, void 0, void 0, function* () {
8244
+ return false;
8245
+ });
8246
+ }
8247
+ isAssetSupported(asset) {
8248
+ return __awaiter$4(this, void 0, void 0, function* () {
8249
+ if (isSynthAsset(asset) || isTradeAsset(asset) || isSecuredAsset(asset))
8250
+ return false;
8251
+ const tokens = yield this.tokensCache.getValue();
8252
+ return findOneClickToken(asset, tokens) !== undefined;
8253
+ });
8254
+ }
8255
+ getSupportedChains() {
8256
+ return __awaiter$4(this, void 0, void 0, function* () {
8257
+ const tokens = yield this.tokensCache.getValue();
8258
+ const chains = new Set();
8259
+ for (const token of tokens) {
8260
+ const chain = oneClickBlockchainToXChain(token.blockchain);
8261
+ if (chain)
8262
+ chains.add(chain);
8263
+ }
8264
+ return Array.from(chains);
8265
+ });
8266
+ }
8267
+ estimateSwap(params) {
8268
+ return __awaiter$4(this, void 0, void 0, function* () {
8269
+ var _a, _b, _c;
8270
+ const tokens = yield this.tokensCache.getValue();
8271
+ const srcToken = findOneClickToken(params.fromAsset, tokens);
8272
+ const destToken = findOneClickToken(params.destinationAsset, tokens);
8273
+ if (!srcToken || !destToken) {
8274
+ return this.errorQuote(params, srcToken ? 'Destination asset not supported' : 'Source asset not supported');
8275
+ }
8276
+ try {
8277
+ const isDry = !(params.fromAddress && params.destinationAddress);
8278
+ const deadline = new Date(Date.now() + 10 * 60 * 1000).toISOString();
8279
+ const appFees = this.affiliateAddress && this.affiliateBps
8280
+ ? [{ recipient: this.affiliateAddress, fee: this.affiliateBps }]
8281
+ : undefined;
8282
+ const resp = yield this.api.getQuote({
8283
+ dry: isDry,
8284
+ swapType: 'EXACT_INPUT',
8285
+ depositType: 'ORIGIN_CHAIN',
8286
+ recipientType: 'DESTINATION_CHAIN',
8287
+ refundType: 'ORIGIN_CHAIN',
8288
+ originAsset: srcToken.assetId,
8289
+ destinationAsset: destToken.assetId,
8290
+ amount: params.amount.baseAmount.amount().toString(),
8291
+ refundTo: params.fromAddress || '',
8292
+ recipient: params.destinationAddress || '',
8293
+ slippageTolerance: (_a = params.toleranceBps) !== null && _a !== void 0 ? _a : 100,
8294
+ deadline,
8295
+ appFees,
8296
+ });
8297
+ if (resp.error || resp.message) {
8298
+ return this.errorQuote(params, resp.error || resp.message || 'Unknown error');
8299
+ }
8300
+ const quote = resp.quote;
8301
+ const toAddress = (_b = quote.depositAddress) !== null && _b !== void 0 ? _b : '';
8302
+ return {
8303
+ protocol: this.name,
8304
+ toAddress,
8305
+ memo: '',
8306
+ expectedAmount: new CryptoAmount(baseAmount(quote.amountOut, destToken.decimals), params.destinationAsset),
8307
+ dustThreshold: new CryptoAmount(baseAmount(0), params.fromAsset),
8308
+ totalSwapSeconds: (_c = quote.timeEstimate) !== null && _c !== void 0 ? _c : 0,
8309
+ maxStreamingQuantity: undefined,
8310
+ canSwap: toAddress !== '',
8311
+ warning: '',
8312
+ errors: [],
8313
+ slipBasisPoints: 0,
8314
+ fees: {
8315
+ asset: params.fromAsset,
8316
+ affiliateFee: new CryptoAmount(baseAmount(0), params.fromAsset),
8317
+ outboundFee: new CryptoAmount(baseAmount(0), params.destinationAsset),
8318
+ },
8319
+ };
8320
+ }
8321
+ catch (e) {
8322
+ return this.errorQuote(params, e instanceof Error ? e.message : 'Unknown error');
8323
+ }
8324
+ });
8325
+ }
8326
+ doSwap(params) {
8327
+ return __awaiter$4(this, void 0, void 0, function* () {
8328
+ const quoteSwap = yield this.estimateSwap(params);
8329
+ if (!quoteSwap.canSwap) {
8330
+ throw new Error(`Can not make swap. ${quoteSwap.errors.join('\n')}`);
8331
+ }
8332
+ if (!this.wallet)
8333
+ throw new Error('Wallet not configured. Can not do swap');
8334
+ const hash = yield this.wallet.transfer({
8335
+ recipient: quoteSwap.toAddress,
8336
+ amount: params.amount.baseAmount,
8337
+ asset: params.fromAsset,
8338
+ memo: quoteSwap.memo,
8339
+ });
8340
+ // Funds are already on the wire. Awaiting submitDeposit lets callers distinguish
8341
+ // "deposit registered, swap will settle" from "registration silently failed, swap will
8342
+ // never settle" — surface the failure with the broadcast hash so it can be retried.
8343
+ try {
8344
+ yield this.api.submitDeposit(hash, quoteSwap.toAddress);
8345
+ }
8346
+ catch (e) {
8347
+ throw new Error(`1Click deposit tx ${hash} was broadcast, but submitDeposit failed: ${e instanceof Error ? e.message : 'unknown error'}`);
8348
+ }
8349
+ // Explorer URL is best-effort; the hash is what callers actually need for tracking.
8350
+ let url = '';
8351
+ try {
8352
+ url = yield this.wallet.getExplorerTxUrl(params.fromAsset.chain, hash);
8353
+ }
8354
+ catch (_a) {
8355
+ // swallow: explorer URL lookup must not reject a successful swap
8356
+ }
8357
+ return { hash, url };
8358
+ });
8359
+ }
8360
+ getSwapHistory(_params) {
8361
+ return __awaiter$4(this, void 0, void 0, function* () {
8362
+ return { count: 0, swaps: [] };
8363
+ });
8364
+ }
8365
+ errorQuote(params, error) {
8366
+ return {
8367
+ protocol: this.name,
8368
+ toAddress: '',
8369
+ memo: '',
8370
+ expectedAmount: new CryptoAmount(baseAmount(0), params.destinationAsset),
8371
+ dustThreshold: new CryptoAmount(baseAmount(0), params.fromAsset),
8372
+ totalSwapSeconds: 0,
8373
+ maxStreamingQuantity: undefined,
8374
+ canSwap: false,
8375
+ warning: '',
8376
+ errors: [error],
8377
+ slipBasisPoints: 0,
8378
+ fees: {
8379
+ asset: params.fromAsset,
8380
+ affiliateFee: new CryptoAmount(baseAmount(0), params.fromAsset),
8381
+ outboundFee: new CryptoAmount(baseAmount(0), params.destinationAsset),
8382
+ },
8383
+ };
8384
+ }
8385
+ }
8386
+
7681
8387
  /**
7682
8388
  * The base URL for the Midgard API endpoint.
7683
8389
  */
7684
- const MIDGARD_API_URL = 'https://gateway.liquify.com/chain/thorchain_midgard/';
8390
+ const MIDGARD_API_URL = 'https://midgard.thorchain.network/';
7685
8391
 
7686
8392
  /******************************************************************************
7687
8393
  Copyright (c) Microsoft Corporation.
@@ -10510,7 +11216,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
10510
11216
  const defaultMidgardConfig = {
10511
11217
  mainnet: {
10512
11218
  apiRetries: 3,
10513
- midgardBaseUrls: ['https://gateway.liquify.com/chain/thorchain_midgard'],
11219
+ midgardBaseUrls: ['https://midgard.thorchain.network', 'https://gateway.liquify.com/chain/thorchain_midgard'],
10514
11220
  },
10515
11221
  stagenet: {
10516
11222
  apiRetries: 3,
@@ -11063,6 +11769,7 @@ const getProtocolConfig = (name, configuration) => {
11063
11769
  network: configuration.network,
11064
11770
  affiliateBrokers: configuration.affiliateBrokers,
11065
11771
  brokerUrl: configuration.brokerUrl,
11772
+ oneClickApiKey: configuration.oneClickApiKey,
11066
11773
  };
11067
11774
  };
11068
11775
  class ProtocolFactory {
@@ -11075,6 +11782,8 @@ class ProtocolFactory {
11075
11782
  return new MayachainProtocol(protocolConfig);
11076
11783
  case 'Chainflip':
11077
11784
  return new ChainflipProtocol(protocolConfig);
11785
+ case 'OneClick':
11786
+ return new OneClickProtocol(protocolConfig);
11078
11787
  }
11079
11788
  }
11080
11789
  }