@xchainjs/xchain-dash 2.0.8 → 2.0.9
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 +370 -234
- package/lib/index.js +377 -240
- package/package.json +7 -7
- package/lib/modules.d copy.d.ts +0 -1
package/lib/index.esm.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { ExplorerProvider, Network, TxType, FeeOption, checkFeeBounds } from '@xchainjs/xchain-client';
|
|
2
2
|
import { AssetType, baseAmount, assetToBase, assetAmount } from '@xchainjs/xchain-util';
|
|
3
3
|
import { BlockcypherProvider, BlockcypherNetwork, BitgoProvider } from '@xchainjs/xchain-utxo-providers';
|
|
4
|
-
import
|
|
5
|
-
import dashcore__default from '@dashevo/dashcore-lib';
|
|
4
|
+
import dashcore from '@dashevo/dashcore-lib';
|
|
6
5
|
import { toBitcoinJS, Client as Client$1 } from '@xchainjs/xchain-utxo';
|
|
7
6
|
import * as Dash from 'bitcoinjs-lib';
|
|
8
|
-
import accumulative from 'coinselect/accumulative';
|
|
7
|
+
import accumulative from 'coinselect/accumulative.js';
|
|
9
8
|
import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';
|
|
10
9
|
import { getSeed } from '@xchainjs/xchain-crypto';
|
|
11
10
|
import { HDKey } from '@scure/bip32';
|
|
@@ -133,6 +132,7 @@ function bind(fn, thisArg) {
|
|
|
133
132
|
|
|
134
133
|
const {toString} = Object.prototype;
|
|
135
134
|
const {getPrototypeOf} = Object;
|
|
135
|
+
const {iterator, toStringTag} = Symbol;
|
|
136
136
|
|
|
137
137
|
const kindOf = (cache => thing => {
|
|
138
138
|
const str = toString.call(thing);
|
|
@@ -173,7 +173,7 @@ const isUndefined = typeOfTest('undefined');
|
|
|
173
173
|
*/
|
|
174
174
|
function isBuffer(val) {
|
|
175
175
|
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
|
|
176
|
-
&& isFunction(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
176
|
+
&& isFunction$1(val.constructor.isBuffer) && val.constructor.isBuffer(val);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
|
@@ -218,7 +218,7 @@ const isString = typeOfTest('string');
|
|
|
218
218
|
* @param {*} val The value to test
|
|
219
219
|
* @returns {boolean} True if value is a Function, otherwise false
|
|
220
220
|
*/
|
|
221
|
-
const isFunction = typeOfTest('function');
|
|
221
|
+
const isFunction$1 = typeOfTest('function');
|
|
222
222
|
|
|
223
223
|
/**
|
|
224
224
|
* Determine if a value is a Number
|
|
@@ -259,7 +259,28 @@ const isPlainObject = (val) => {
|
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
const prototype = getPrototypeOf(val);
|
|
262
|
-
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(
|
|
262
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Determine if a value is an empty object (safely handles Buffers)
|
|
267
|
+
*
|
|
268
|
+
* @param {*} val The value to test
|
|
269
|
+
*
|
|
270
|
+
* @returns {boolean} True if value is an empty object, otherwise false
|
|
271
|
+
*/
|
|
272
|
+
const isEmptyObject = (val) => {
|
|
273
|
+
// Early return for non-objects or Buffers to prevent RangeError
|
|
274
|
+
if (!isObject(val) || isBuffer(val)) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
280
|
+
} catch (e) {
|
|
281
|
+
// Fallback for any other objects that might cause RangeError with Object.keys()
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
263
284
|
};
|
|
264
285
|
|
|
265
286
|
/**
|
|
@@ -305,7 +326,7 @@ const isFileList = kindOfTest('FileList');
|
|
|
305
326
|
*
|
|
306
327
|
* @returns {boolean} True if value is a Stream, otherwise false
|
|
307
328
|
*/
|
|
308
|
-
const isStream = (val) => isObject(val) && isFunction(val.pipe);
|
|
329
|
+
const isStream = (val) => isObject(val) && isFunction$1(val.pipe);
|
|
309
330
|
|
|
310
331
|
/**
|
|
311
332
|
* Determine if a value is a FormData
|
|
@@ -318,10 +339,10 @@ const isFormData = (thing) => {
|
|
|
318
339
|
let kind;
|
|
319
340
|
return thing && (
|
|
320
341
|
(typeof FormData === 'function' && thing instanceof FormData) || (
|
|
321
|
-
isFunction(thing.append) && (
|
|
342
|
+
isFunction$1(thing.append) && (
|
|
322
343
|
(kind = kindOf(thing)) === 'formdata' ||
|
|
323
344
|
// detect form-data instance
|
|
324
|
-
(kind === 'object' && isFunction(thing.toString) && thing.toString() === '[object FormData]')
|
|
345
|
+
(kind === 'object' && isFunction$1(thing.toString) && thing.toString() === '[object FormData]')
|
|
325
346
|
)
|
|
326
347
|
)
|
|
327
348
|
)
|
|
@@ -384,6 +405,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
|
384
405
|
fn.call(null, obj[i], i, obj);
|
|
385
406
|
}
|
|
386
407
|
} else {
|
|
408
|
+
// Buffer check
|
|
409
|
+
if (isBuffer(obj)) {
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
387
413
|
// Iterate over object keys
|
|
388
414
|
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
|
389
415
|
const len = keys.length;
|
|
@@ -397,6 +423,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
|
|
397
423
|
}
|
|
398
424
|
|
|
399
425
|
function findKey(obj, key) {
|
|
426
|
+
if (isBuffer(obj)){
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
|
|
400
430
|
key = key.toLowerCase();
|
|
401
431
|
const keys = Object.keys(obj);
|
|
402
432
|
let i = keys.length;
|
|
@@ -437,7 +467,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
|
|
|
437
467
|
* @returns {Object} Result of all merge properties
|
|
438
468
|
*/
|
|
439
469
|
function merge(/* obj1, obj2, obj3, ... */) {
|
|
440
|
-
const {caseless} = isContextDefined(this) && this || {};
|
|
470
|
+
const {caseless, skipUndefined} = isContextDefined(this) && this || {};
|
|
441
471
|
const result = {};
|
|
442
472
|
const assignValue = (val, key) => {
|
|
443
473
|
const targetKey = caseless && findKey(result, key) || key;
|
|
@@ -448,7 +478,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
448
478
|
} else if (isArray(val)) {
|
|
449
479
|
result[targetKey] = val.slice();
|
|
450
480
|
} else {
|
|
451
|
-
|
|
481
|
+
if (!skipUndefined || !isUndefined(val)) {
|
|
482
|
+
result[targetKey] = val;
|
|
483
|
+
}
|
|
452
484
|
}
|
|
453
485
|
};
|
|
454
486
|
|
|
@@ -470,7 +502,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
|
|
470
502
|
*/
|
|
471
503
|
const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
|
|
472
504
|
forEach(b, (val, key) => {
|
|
473
|
-
if (thisArg && isFunction(val)) {
|
|
505
|
+
if (thisArg && isFunction$1(val)) {
|
|
474
506
|
a[key] = bind(val, thisArg);
|
|
475
507
|
} else {
|
|
476
508
|
a[key] = val;
|
|
@@ -610,13 +642,13 @@ const isTypedArray = (TypedArray => {
|
|
|
610
642
|
* @returns {void}
|
|
611
643
|
*/
|
|
612
644
|
const forEachEntry = (obj, fn) => {
|
|
613
|
-
const generator = obj && obj[
|
|
645
|
+
const generator = obj && obj[iterator];
|
|
614
646
|
|
|
615
|
-
const
|
|
647
|
+
const _iterator = generator.call(obj);
|
|
616
648
|
|
|
617
649
|
let result;
|
|
618
650
|
|
|
619
|
-
while ((result =
|
|
651
|
+
while ((result = _iterator.next()) && !result.done) {
|
|
620
652
|
const pair = result.value;
|
|
621
653
|
fn.call(obj, pair[0], pair[1]);
|
|
622
654
|
}
|
|
@@ -686,13 +718,13 @@ const reduceDescriptors = (obj, reducer) => {
|
|
|
686
718
|
const freezeMethods = (obj) => {
|
|
687
719
|
reduceDescriptors(obj, (descriptor, name) => {
|
|
688
720
|
// skip restricted props in strict mode
|
|
689
|
-
if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
721
|
+
if (isFunction$1(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
|
690
722
|
return false;
|
|
691
723
|
}
|
|
692
724
|
|
|
693
725
|
const value = obj[name];
|
|
694
726
|
|
|
695
|
-
if (!isFunction(value)) return;
|
|
727
|
+
if (!isFunction$1(value)) return;
|
|
696
728
|
|
|
697
729
|
descriptor.enumerable = false;
|
|
698
730
|
|
|
@@ -729,6 +761,8 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
|
729
761
|
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
|
730
762
|
};
|
|
731
763
|
|
|
764
|
+
|
|
765
|
+
|
|
732
766
|
/**
|
|
733
767
|
* If the thing is a FormData object, return true, otherwise return false.
|
|
734
768
|
*
|
|
@@ -737,7 +771,7 @@ const toFiniteNumber = (value, defaultValue) => {
|
|
|
737
771
|
* @returns {boolean}
|
|
738
772
|
*/
|
|
739
773
|
function isSpecCompliantForm(thing) {
|
|
740
|
-
return !!(thing && isFunction(thing.append) && thing[
|
|
774
|
+
return !!(thing && isFunction$1(thing.append) && thing[toStringTag] === 'FormData' && thing[iterator]);
|
|
741
775
|
}
|
|
742
776
|
|
|
743
777
|
const toJSONObject = (obj) => {
|
|
@@ -750,6 +784,11 @@ const toJSONObject = (obj) => {
|
|
|
750
784
|
return;
|
|
751
785
|
}
|
|
752
786
|
|
|
787
|
+
//Buffer check
|
|
788
|
+
if (isBuffer(source)) {
|
|
789
|
+
return source;
|
|
790
|
+
}
|
|
791
|
+
|
|
753
792
|
if(!('toJSON' in source)) {
|
|
754
793
|
stack[i] = source;
|
|
755
794
|
const target = isArray(source) ? [] : {};
|
|
@@ -774,7 +813,7 @@ const toJSONObject = (obj) => {
|
|
|
774
813
|
const isAsyncFn = kindOfTest('AsyncFunction');
|
|
775
814
|
|
|
776
815
|
const isThenable = (thing) =>
|
|
777
|
-
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
|
816
|
+
thing && (isObject(thing) || isFunction$1(thing)) && isFunction$1(thing.then) && isFunction$1(thing.catch);
|
|
778
817
|
|
|
779
818
|
// original code
|
|
780
819
|
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
|
@@ -798,7 +837,7 @@ const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
|
|
798
837
|
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
|
799
838
|
})(
|
|
800
839
|
typeof setImmediate === 'function',
|
|
801
|
-
isFunction(_global.postMessage)
|
|
840
|
+
isFunction$1(_global.postMessage)
|
|
802
841
|
);
|
|
803
842
|
|
|
804
843
|
const asap = typeof queueMicrotask !== 'undefined' ?
|
|
@@ -806,6 +845,10 @@ const asap = typeof queueMicrotask !== 'undefined' ?
|
|
|
806
845
|
|
|
807
846
|
// *********************
|
|
808
847
|
|
|
848
|
+
|
|
849
|
+
const isIterable = (thing) => thing != null && isFunction$1(thing[iterator]);
|
|
850
|
+
|
|
851
|
+
|
|
809
852
|
var utils$1 = {
|
|
810
853
|
isArray,
|
|
811
854
|
isArrayBuffer,
|
|
@@ -817,6 +860,7 @@ var utils$1 = {
|
|
|
817
860
|
isBoolean,
|
|
818
861
|
isObject,
|
|
819
862
|
isPlainObject,
|
|
863
|
+
isEmptyObject,
|
|
820
864
|
isReadableStream,
|
|
821
865
|
isRequest,
|
|
822
866
|
isResponse,
|
|
@@ -826,7 +870,7 @@ var utils$1 = {
|
|
|
826
870
|
isFile,
|
|
827
871
|
isBlob,
|
|
828
872
|
isRegExp,
|
|
829
|
-
isFunction,
|
|
873
|
+
isFunction: isFunction$1,
|
|
830
874
|
isStream,
|
|
831
875
|
isURLSearchParams,
|
|
832
876
|
isTypedArray,
|
|
@@ -861,7 +905,8 @@ var utils$1 = {
|
|
|
861
905
|
isAsyncFn,
|
|
862
906
|
isThenable,
|
|
863
907
|
setImmediate: _setImmediate,
|
|
864
|
-
asap
|
|
908
|
+
asap,
|
|
909
|
+
isIterable
|
|
865
910
|
};
|
|
866
911
|
|
|
867
912
|
/**
|
|
@@ -951,11 +996,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
|
|
|
951
996
|
return prop !== 'isAxiosError';
|
|
952
997
|
});
|
|
953
998
|
|
|
954
|
-
|
|
999
|
+
const msg = error && error.message ? error.message : 'Error';
|
|
955
1000
|
|
|
956
|
-
|
|
1001
|
+
// Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
|
|
1002
|
+
const errCode = code == null && error ? error.code : code;
|
|
1003
|
+
AxiosError.call(axiosError, msg, errCode, config, request, response);
|
|
1004
|
+
|
|
1005
|
+
// Chain the original error on the standard field; non-enumerable to avoid JSON noise
|
|
1006
|
+
if (error && axiosError.cause == null) {
|
|
1007
|
+
Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
|
|
1008
|
+
}
|
|
957
1009
|
|
|
958
|
-
axiosError.name = error.name;
|
|
1010
|
+
axiosError.name = (error && error.name) || 'Error';
|
|
959
1011
|
|
|
960
1012
|
customProps && Object.assign(axiosError, customProps);
|
|
961
1013
|
|
|
@@ -1080,6 +1132,10 @@ function toFormData(obj, formData, options) {
|
|
|
1080
1132
|
return value.toISOString();
|
|
1081
1133
|
}
|
|
1082
1134
|
|
|
1135
|
+
if (utils$1.isBoolean(value)) {
|
|
1136
|
+
return value.toString();
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1083
1139
|
if (!useBlob && utils$1.isBlob(value)) {
|
|
1084
1140
|
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
|
1085
1141
|
}
|
|
@@ -1242,9 +1298,7 @@ function encode(val) {
|
|
|
1242
1298
|
replace(/%3A/gi, ':').
|
|
1243
1299
|
replace(/%24/g, '$').
|
|
1244
1300
|
replace(/%2C/gi, ',').
|
|
1245
|
-
replace(/%20/g, '+')
|
|
1246
|
-
replace(/%5B/gi, '[').
|
|
1247
|
-
replace(/%5D/gi, ']');
|
|
1301
|
+
replace(/%20/g, '+');
|
|
1248
1302
|
}
|
|
1249
1303
|
|
|
1250
1304
|
/**
|
|
@@ -1441,7 +1495,7 @@ var platform = {
|
|
|
1441
1495
|
};
|
|
1442
1496
|
|
|
1443
1497
|
function toURLEncodedForm(data, options) {
|
|
1444
|
-
return toFormData(data, new platform.classes.URLSearchParams(),
|
|
1498
|
+
return toFormData(data, new platform.classes.URLSearchParams(), {
|
|
1445
1499
|
visitor: function(value, key, path, helpers) {
|
|
1446
1500
|
if (platform.isNode && utils$1.isBuffer(value)) {
|
|
1447
1501
|
this.append(key, value.toString('base64'));
|
|
@@ -1449,8 +1503,9 @@ function toURLEncodedForm(data, options) {
|
|
|
1449
1503
|
}
|
|
1450
1504
|
|
|
1451
1505
|
return helpers.defaultVisitor.apply(this, arguments);
|
|
1452
|
-
}
|
|
1453
|
-
|
|
1506
|
+
},
|
|
1507
|
+
...options
|
|
1508
|
+
});
|
|
1454
1509
|
}
|
|
1455
1510
|
|
|
1456
1511
|
/**
|
|
@@ -1646,7 +1701,7 @@ const defaults = {
|
|
|
1646
1701
|
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
|
1647
1702
|
|
|
1648
1703
|
try {
|
|
1649
|
-
return JSON.parse(data);
|
|
1704
|
+
return JSON.parse(data, this.parseReviver);
|
|
1650
1705
|
} catch (e) {
|
|
1651
1706
|
if (strictJSONParsing) {
|
|
1652
1707
|
if (e.name === 'SyntaxError') {
|
|
@@ -1842,10 +1897,18 @@ class AxiosHeaders {
|
|
|
1842
1897
|
setHeaders(header, valueOrRewrite);
|
|
1843
1898
|
} else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
|
1844
1899
|
setHeaders(parseHeaders(header), valueOrRewrite);
|
|
1845
|
-
} else if (utils$1.
|
|
1846
|
-
|
|
1847
|
-
|
|
1900
|
+
} else if (utils$1.isObject(header) && utils$1.isIterable(header)) {
|
|
1901
|
+
let obj = {}, dest, key;
|
|
1902
|
+
for (const entry of header) {
|
|
1903
|
+
if (!utils$1.isArray(entry)) {
|
|
1904
|
+
throw TypeError('Object iterator must return a key-value pair');
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
obj[key = entry[0]] = (dest = obj[key]) ?
|
|
1908
|
+
(utils$1.isArray(dest) ? [...dest, entry[1]] : [dest, entry[1]]) : entry[1];
|
|
1848
1909
|
}
|
|
1910
|
+
|
|
1911
|
+
setHeaders(obj, valueOrRewrite);
|
|
1849
1912
|
} else {
|
|
1850
1913
|
header != null && setHeader(valueOrRewrite, header, rewrite);
|
|
1851
1914
|
}
|
|
@@ -1987,6 +2050,10 @@ class AxiosHeaders {
|
|
|
1987
2050
|
return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
|
1988
2051
|
}
|
|
1989
2052
|
|
|
2053
|
+
getSetCookie() {
|
|
2054
|
+
return this.get("set-cookie") || [];
|
|
2055
|
+
}
|
|
2056
|
+
|
|
1990
2057
|
get [Symbol.toStringTag]() {
|
|
1991
2058
|
return 'AxiosHeaders';
|
|
1992
2059
|
}
|
|
@@ -2187,7 +2254,7 @@ function throttle(fn, freq) {
|
|
|
2187
2254
|
clearTimeout(timer);
|
|
2188
2255
|
timer = null;
|
|
2189
2256
|
}
|
|
2190
|
-
fn
|
|
2257
|
+
fn(...args);
|
|
2191
2258
|
};
|
|
2192
2259
|
|
|
2193
2260
|
const throttled = (...args) => {
|
|
@@ -2443,7 +2510,7 @@ function mergeConfig(config1, config2) {
|
|
|
2443
2510
|
headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
|
|
2444
2511
|
};
|
|
2445
2512
|
|
|
2446
|
-
utils$1.forEach(Object.keys(
|
|
2513
|
+
utils$1.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
|
|
2447
2514
|
const merge = mergeMap[prop] || mergeDeepProperties;
|
|
2448
2515
|
const configValue = merge(config1[prop], config2[prop], prop);
|
|
2449
2516
|
(utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
|
@@ -2455,7 +2522,7 @@ function mergeConfig(config1, config2) {
|
|
|
2455
2522
|
var resolveConfig = (config) => {
|
|
2456
2523
|
const newConfig = mergeConfig({}, config);
|
|
2457
2524
|
|
|
2458
|
-
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
|
2525
|
+
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
|
2459
2526
|
|
|
2460
2527
|
newConfig.headers = headers = AxiosHeaders.from(headers);
|
|
2461
2528
|
|
|
@@ -2468,17 +2535,21 @@ var resolveConfig = (config) => {
|
|
|
2468
2535
|
);
|
|
2469
2536
|
}
|
|
2470
2537
|
|
|
2471
|
-
let contentType;
|
|
2472
|
-
|
|
2473
2538
|
if (utils$1.isFormData(data)) {
|
|
2474
2539
|
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
|
2475
|
-
headers.setContentType(undefined); //
|
|
2476
|
-
} else if ((
|
|
2477
|
-
//
|
|
2478
|
-
const
|
|
2479
|
-
headers
|
|
2540
|
+
headers.setContentType(undefined); // browser handles it
|
|
2541
|
+
} else if (utils$1.isFunction(data.getHeaders)) {
|
|
2542
|
+
// Node.js FormData (like form-data package)
|
|
2543
|
+
const formHeaders = data.getHeaders();
|
|
2544
|
+
// Only set safe headers to avoid overwriting security headers
|
|
2545
|
+
const allowedHeaders = ['content-type', 'content-length'];
|
|
2546
|
+
Object.entries(formHeaders).forEach(([key, val]) => {
|
|
2547
|
+
if (allowedHeaders.includes(key.toLowerCase())) {
|
|
2548
|
+
headers.set(key, val);
|
|
2549
|
+
}
|
|
2550
|
+
});
|
|
2480
2551
|
}
|
|
2481
|
-
}
|
|
2552
|
+
}
|
|
2482
2553
|
|
|
2483
2554
|
// Add xsrf header
|
|
2484
2555
|
// This is only done if running in a standard browser environment.
|
|
@@ -2595,15 +2666,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
|
2595
2666
|
};
|
|
2596
2667
|
|
|
2597
2668
|
// Handle low level network errors
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2669
|
+
request.onerror = function handleError(event) {
|
|
2670
|
+
// Browsers deliver a ProgressEvent in XHR onerror
|
|
2671
|
+
// (message may be empty; when present, surface it)
|
|
2672
|
+
// See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
|
|
2673
|
+
const msg = event && event.message ? event.message : 'Network Error';
|
|
2674
|
+
const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
|
|
2675
|
+
// attach the underlying event for consumers who want details
|
|
2676
|
+
err.event = event || null;
|
|
2677
|
+
reject(err);
|
|
2678
|
+
request = null;
|
|
2605
2679
|
};
|
|
2606
|
-
|
|
2680
|
+
|
|
2607
2681
|
// Handle timeout
|
|
2608
2682
|
request.ontimeout = function handleTimeout() {
|
|
2609
2683
|
let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
|
@@ -2817,14 +2891,18 @@ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
|
|
2817
2891
|
})
|
|
2818
2892
|
};
|
|
2819
2893
|
|
|
2820
|
-
const
|
|
2821
|
-
|
|
2894
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
2895
|
+
|
|
2896
|
+
const {isFunction} = utils$1;
|
|
2897
|
+
|
|
2898
|
+
const globalFetchAPI = (({fetch, Request, Response}) => ({
|
|
2899
|
+
fetch, Request, Response
|
|
2900
|
+
}))(utils$1.global);
|
|
2901
|
+
|
|
2902
|
+
const {
|
|
2903
|
+
ReadableStream: ReadableStream$1, TextEncoder
|
|
2904
|
+
} = utils$1.global;
|
|
2822
2905
|
|
|
2823
|
-
// used only inside the fetch adapter
|
|
2824
|
-
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
2825
|
-
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
2826
|
-
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
|
2827
|
-
);
|
|
2828
2906
|
|
|
2829
2907
|
const test = (fn, ...args) => {
|
|
2830
2908
|
try {
|
|
@@ -2834,211 +2912,266 @@ const test = (fn, ...args) => {
|
|
|
2834
2912
|
}
|
|
2835
2913
|
};
|
|
2836
2914
|
|
|
2837
|
-
const
|
|
2838
|
-
|
|
2915
|
+
const factory = (env) => {
|
|
2916
|
+
const {fetch, Request, Response} = Object.assign({}, globalFetchAPI, env);
|
|
2917
|
+
const isFetchSupported = isFunction(fetch);
|
|
2918
|
+
const isRequestSupported = isFunction(Request);
|
|
2919
|
+
const isResponseSupported = isFunction(Response);
|
|
2839
2920
|
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
get duplex() {
|
|
2844
|
-
duplexAccessed = true;
|
|
2845
|
-
return 'half';
|
|
2846
|
-
},
|
|
2847
|
-
}).headers.has('Content-Type');
|
|
2921
|
+
if (!isFetchSupported) {
|
|
2922
|
+
return false;
|
|
2923
|
+
}
|
|
2848
2924
|
|
|
2849
|
-
|
|
2850
|
-
});
|
|
2925
|
+
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
|
|
2851
2926
|
|
|
2852
|
-
const
|
|
2927
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
|
2928
|
+
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
|
2929
|
+
async (str) => new Uint8Array(await new Request(str).arrayBuffer())
|
|
2930
|
+
);
|
|
2853
2931
|
|
|
2854
|
-
const
|
|
2855
|
-
|
|
2932
|
+
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
2933
|
+
let duplexAccessed = false;
|
|
2856
2934
|
|
|
2935
|
+
const hasContentType = new Request(platform.origin, {
|
|
2936
|
+
body: new ReadableStream$1(),
|
|
2937
|
+
method: 'POST',
|
|
2938
|
+
get duplex() {
|
|
2939
|
+
duplexAccessed = true;
|
|
2940
|
+
return 'half';
|
|
2941
|
+
},
|
|
2942
|
+
}).headers.has('Content-Type');
|
|
2857
2943
|
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2944
|
+
return duplexAccessed && !hasContentType;
|
|
2945
|
+
});
|
|
2946
|
+
|
|
2947
|
+
const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
|
|
2948
|
+
test(() => utils$1.isReadableStream(new Response('').body));
|
|
2949
|
+
|
|
2950
|
+
const resolvers = {
|
|
2951
|
+
stream: supportsResponseStream && ((res) => res.body)
|
|
2952
|
+
};
|
|
2953
|
+
|
|
2954
|
+
isFetchSupported && ((() => {
|
|
2955
|
+
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
2956
|
+
!resolvers[type] && (resolvers[type] = (res, config) => {
|
|
2957
|
+
let method = res && res[type];
|
|
2958
|
+
|
|
2959
|
+
if (method) {
|
|
2960
|
+
return method.call(res);
|
|
2961
|
+
}
|
|
2861
2962
|
|
|
2862
|
-
isFetchSupported && (((res) => {
|
|
2863
|
-
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
|
2864
|
-
!resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
|
|
2865
|
-
(_, config) => {
|
|
2866
2963
|
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
|
2867
2964
|
});
|
|
2868
|
-
|
|
2869
|
-
})(
|
|
2965
|
+
});
|
|
2966
|
+
})());
|
|
2870
2967
|
|
|
2871
|
-
const getBodyLength = async (body) => {
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2968
|
+
const getBodyLength = async (body) => {
|
|
2969
|
+
if (body == null) {
|
|
2970
|
+
return 0;
|
|
2971
|
+
}
|
|
2875
2972
|
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2973
|
+
if (utils$1.isBlob(body)) {
|
|
2974
|
+
return body.size;
|
|
2975
|
+
}
|
|
2879
2976
|
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2977
|
+
if (utils$1.isSpecCompliantForm(body)) {
|
|
2978
|
+
const _request = new Request(platform.origin, {
|
|
2979
|
+
method: 'POST',
|
|
2980
|
+
body,
|
|
2981
|
+
});
|
|
2982
|
+
return (await _request.arrayBuffer()).byteLength;
|
|
2983
|
+
}
|
|
2887
2984
|
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2985
|
+
if (utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
|
2986
|
+
return body.byteLength;
|
|
2987
|
+
}
|
|
2891
2988
|
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2989
|
+
if (utils$1.isURLSearchParams(body)) {
|
|
2990
|
+
body = body + '';
|
|
2991
|
+
}
|
|
2895
2992
|
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
};
|
|
2993
|
+
if (utils$1.isString(body)) {
|
|
2994
|
+
return (await encodeText(body)).byteLength;
|
|
2995
|
+
}
|
|
2996
|
+
};
|
|
2900
2997
|
|
|
2901
|
-
const resolveBodyLength = async (headers, body) => {
|
|
2902
|
-
|
|
2998
|
+
const resolveBodyLength = async (headers, body) => {
|
|
2999
|
+
const length = utils$1.toFiniteNumber(headers.getContentLength());
|
|
2903
3000
|
|
|
2904
|
-
|
|
2905
|
-
};
|
|
3001
|
+
return length == null ? getBodyLength(body) : length;
|
|
3002
|
+
};
|
|
3003
|
+
|
|
3004
|
+
return async (config) => {
|
|
3005
|
+
let {
|
|
3006
|
+
url,
|
|
3007
|
+
method,
|
|
3008
|
+
data,
|
|
3009
|
+
signal,
|
|
3010
|
+
cancelToken,
|
|
3011
|
+
timeout,
|
|
3012
|
+
onDownloadProgress,
|
|
3013
|
+
onUploadProgress,
|
|
3014
|
+
responseType,
|
|
3015
|
+
headers,
|
|
3016
|
+
withCredentials = 'same-origin',
|
|
3017
|
+
fetchOptions
|
|
3018
|
+
} = resolveConfig(config);
|
|
3019
|
+
|
|
3020
|
+
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|
3021
|
+
|
|
3022
|
+
let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
2906
3023
|
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
method,
|
|
2911
|
-
data,
|
|
2912
|
-
signal,
|
|
2913
|
-
cancelToken,
|
|
2914
|
-
timeout,
|
|
2915
|
-
onDownloadProgress,
|
|
2916
|
-
onUploadProgress,
|
|
2917
|
-
responseType,
|
|
2918
|
-
headers,
|
|
2919
|
-
withCredentials = 'same-origin',
|
|
2920
|
-
fetchOptions
|
|
2921
|
-
} = resolveConfig(config);
|
|
2922
|
-
|
|
2923
|
-
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
|
2924
|
-
|
|
2925
|
-
let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
|
2926
|
-
|
|
2927
|
-
let request;
|
|
2928
|
-
|
|
2929
|
-
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
3024
|
+
let request = null;
|
|
3025
|
+
|
|
3026
|
+
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
|
2930
3027
|
composedSignal.unsubscribe();
|
|
2931
|
-
|
|
3028
|
+
});
|
|
2932
3029
|
|
|
2933
|
-
|
|
3030
|
+
let requestContentLength;
|
|
2934
3031
|
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
3032
|
+
try {
|
|
3033
|
+
if (
|
|
3034
|
+
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
|
3035
|
+
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
|
3036
|
+
) {
|
|
3037
|
+
let _request = new Request(url, {
|
|
3038
|
+
method: 'POST',
|
|
3039
|
+
body: data,
|
|
3040
|
+
duplex: "half"
|
|
3041
|
+
});
|
|
2945
3042
|
|
|
2946
|
-
|
|
3043
|
+
let contentTypeHeader;
|
|
2947
3044
|
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
3045
|
+
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
|
3046
|
+
headers.setContentType(contentTypeHeader);
|
|
3047
|
+
}
|
|
2951
3048
|
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
3049
|
+
if (_request.body) {
|
|
3050
|
+
const [onProgress, flush] = progressEventDecorator(
|
|
3051
|
+
requestContentLength,
|
|
3052
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
|
3053
|
+
);
|
|
2957
3054
|
|
|
2958
|
-
|
|
3055
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
|
3056
|
+
}
|
|
2959
3057
|
}
|
|
2960
|
-
}
|
|
2961
3058
|
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
3059
|
+
if (!utils$1.isString(withCredentials)) {
|
|
3060
|
+
withCredentials = withCredentials ? 'include' : 'omit';
|
|
3061
|
+
}
|
|
2965
3062
|
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
request = new Request(url, {
|
|
2970
|
-
...fetchOptions,
|
|
2971
|
-
signal: composedSignal,
|
|
2972
|
-
method: method.toUpperCase(),
|
|
2973
|
-
headers: headers.normalize().toJSON(),
|
|
2974
|
-
body: data,
|
|
2975
|
-
duplex: "half",
|
|
2976
|
-
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
2977
|
-
});
|
|
3063
|
+
// Cloudflare Workers throws when credentials are defined
|
|
3064
|
+
// see https://github.com/cloudflare/workerd/issues/902
|
|
3065
|
+
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
2978
3066
|
|
|
2979
|
-
|
|
3067
|
+
const resolvedOptions = {
|
|
3068
|
+
...fetchOptions,
|
|
3069
|
+
signal: composedSignal,
|
|
3070
|
+
method: method.toUpperCase(),
|
|
3071
|
+
headers: headers.normalize().toJSON(),
|
|
3072
|
+
body: data,
|
|
3073
|
+
duplex: "half",
|
|
3074
|
+
credentials: isCredentialsSupported ? withCredentials : undefined
|
|
3075
|
+
};
|
|
2980
3076
|
|
|
2981
|
-
|
|
3077
|
+
request = isRequestSupported && new Request(url, resolvedOptions);
|
|
2982
3078
|
|
|
2983
|
-
|
|
2984
|
-
const options = {};
|
|
3079
|
+
let response = await (isRequestSupported ? fetch(request, fetchOptions) : fetch(url, resolvedOptions));
|
|
2985
3080
|
|
|
2986
|
-
|
|
2987
|
-
options[prop] = response[prop];
|
|
2988
|
-
});
|
|
3081
|
+
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
|
2989
3082
|
|
|
2990
|
-
|
|
3083
|
+
if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
|
|
3084
|
+
const options = {};
|
|
2991
3085
|
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
) || [];
|
|
3086
|
+
['status', 'statusText', 'headers'].forEach(prop => {
|
|
3087
|
+
options[prop] = response[prop];
|
|
3088
|
+
});
|
|
2996
3089
|
|
|
2997
|
-
|
|
2998
|
-
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
2999
|
-
flush && flush();
|
|
3000
|
-
unsubscribe && unsubscribe();
|
|
3001
|
-
}),
|
|
3002
|
-
options
|
|
3003
|
-
);
|
|
3004
|
-
}
|
|
3090
|
+
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
|
3005
3091
|
|
|
3006
|
-
|
|
3092
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
|
3093
|
+
responseContentLength,
|
|
3094
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
|
3095
|
+
) || [];
|
|
3007
3096
|
|
|
3008
|
-
|
|
3097
|
+
response = new Response(
|
|
3098
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
|
3099
|
+
flush && flush();
|
|
3100
|
+
unsubscribe && unsubscribe();
|
|
3101
|
+
}),
|
|
3102
|
+
options
|
|
3103
|
+
);
|
|
3104
|
+
}
|
|
3009
3105
|
|
|
3010
|
-
|
|
3106
|
+
responseType = responseType || 'text';
|
|
3011
3107
|
|
|
3012
|
-
|
|
3013
|
-
settle(resolve, reject, {
|
|
3014
|
-
data: responseData,
|
|
3015
|
-
headers: AxiosHeaders.from(response.headers),
|
|
3016
|
-
status: response.status,
|
|
3017
|
-
statusText: response.statusText,
|
|
3018
|
-
config,
|
|
3019
|
-
request
|
|
3020
|
-
});
|
|
3021
|
-
})
|
|
3022
|
-
} catch (err) {
|
|
3023
|
-
unsubscribe && unsubscribe();
|
|
3108
|
+
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
|
3024
3109
|
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
{
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3110
|
+
!isStreamResponse && unsubscribe && unsubscribe();
|
|
3111
|
+
|
|
3112
|
+
return await new Promise((resolve, reject) => {
|
|
3113
|
+
settle(resolve, reject, {
|
|
3114
|
+
data: responseData,
|
|
3115
|
+
headers: AxiosHeaders.from(response.headers),
|
|
3116
|
+
status: response.status,
|
|
3117
|
+
statusText: response.statusText,
|
|
3118
|
+
config,
|
|
3119
|
+
request
|
|
3120
|
+
});
|
|
3121
|
+
})
|
|
3122
|
+
} catch (err) {
|
|
3123
|
+
unsubscribe && unsubscribe();
|
|
3124
|
+
|
|
3125
|
+
if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
|
|
3126
|
+
throw Object.assign(
|
|
3127
|
+
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
|
3128
|
+
{
|
|
3129
|
+
cause: err.cause || err
|
|
3130
|
+
}
|
|
3131
|
+
)
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
throw AxiosError.from(err, err && err.code, config, request);
|
|
3032
3135
|
}
|
|
3136
|
+
}
|
|
3137
|
+
};
|
|
3138
|
+
|
|
3139
|
+
const seedCache = new Map();
|
|
3140
|
+
|
|
3141
|
+
const getFetch = (config) => {
|
|
3142
|
+
let env = utils$1.merge.call({
|
|
3143
|
+
skipUndefined: true
|
|
3144
|
+
}, globalFetchAPI, config ? config.env : null);
|
|
3145
|
+
|
|
3146
|
+
const {fetch, Request, Response} = env;
|
|
3033
3147
|
|
|
3034
|
-
|
|
3148
|
+
const seeds = [
|
|
3149
|
+
Request, Response, fetch
|
|
3150
|
+
];
|
|
3151
|
+
|
|
3152
|
+
let len = seeds.length, i = len,
|
|
3153
|
+
seed, target, map = seedCache;
|
|
3154
|
+
|
|
3155
|
+
while (i--) {
|
|
3156
|
+
seed = seeds[i];
|
|
3157
|
+
target = map.get(seed);
|
|
3158
|
+
|
|
3159
|
+
target === undefined && map.set(seed, target = (i ? new Map() : factory(env)));
|
|
3160
|
+
|
|
3161
|
+
map = target;
|
|
3035
3162
|
}
|
|
3036
|
-
|
|
3163
|
+
|
|
3164
|
+
return target;
|
|
3165
|
+
};
|
|
3166
|
+
|
|
3167
|
+
getFetch();
|
|
3037
3168
|
|
|
3038
3169
|
const knownAdapters = {
|
|
3039
3170
|
http: httpAdapter,
|
|
3040
3171
|
xhr: xhrAdapter,
|
|
3041
|
-
fetch:
|
|
3172
|
+
fetch: {
|
|
3173
|
+
get: getFetch,
|
|
3174
|
+
}
|
|
3042
3175
|
};
|
|
3043
3176
|
|
|
3044
3177
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
|
@@ -3057,7 +3190,7 @@ const renderReason = (reason) => `- ${reason}`;
|
|
|
3057
3190
|
const isResolvedHandle = (adapter) => utils$1.isFunction(adapter) || adapter === null || adapter === false;
|
|
3058
3191
|
|
|
3059
3192
|
var adapters = {
|
|
3060
|
-
getAdapter: (adapters) => {
|
|
3193
|
+
getAdapter: (adapters, config) => {
|
|
3061
3194
|
adapters = utils$1.isArray(adapters) ? adapters : [adapters];
|
|
3062
3195
|
|
|
3063
3196
|
const {length} = adapters;
|
|
@@ -3080,7 +3213,7 @@ var adapters = {
|
|
|
3080
3213
|
}
|
|
3081
3214
|
}
|
|
3082
3215
|
|
|
3083
|
-
if (adapter) {
|
|
3216
|
+
if (adapter && (utils$1.isFunction(adapter) || (adapter = adapter.get(config)))) {
|
|
3084
3217
|
break;
|
|
3085
3218
|
}
|
|
3086
3219
|
|
|
@@ -3148,7 +3281,7 @@ function dispatchRequest(config) {
|
|
|
3148
3281
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|
3149
3282
|
}
|
|
3150
3283
|
|
|
3151
|
-
const adapter = adapters.getAdapter(config.adapter || defaults.adapter);
|
|
3284
|
+
const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
|
|
3152
3285
|
|
|
3153
3286
|
return adapter(config).then(function onAdapterResolution(response) {
|
|
3154
3287
|
throwIfCancellationRequested(config);
|
|
@@ -3182,7 +3315,7 @@ function dispatchRequest(config) {
|
|
|
3182
3315
|
});
|
|
3183
3316
|
}
|
|
3184
3317
|
|
|
3185
|
-
const VERSION = "1.
|
|
3318
|
+
const VERSION = "1.12.1";
|
|
3186
3319
|
|
|
3187
3320
|
const validators$1 = {};
|
|
3188
3321
|
|
|
@@ -3290,7 +3423,7 @@ const validators = validator.validators;
|
|
|
3290
3423
|
*/
|
|
3291
3424
|
class Axios {
|
|
3292
3425
|
constructor(instanceConfig) {
|
|
3293
|
-
this.defaults = instanceConfig;
|
|
3426
|
+
this.defaults = instanceConfig || {};
|
|
3294
3427
|
this.interceptors = {
|
|
3295
3428
|
request: new InterceptorManager(),
|
|
3296
3429
|
response: new InterceptorManager()
|
|
@@ -3421,8 +3554,8 @@ class Axios {
|
|
|
3421
3554
|
|
|
3422
3555
|
if (!synchronousRequestInterceptors) {
|
|
3423
3556
|
const chain = [dispatchRequest.bind(this), undefined];
|
|
3424
|
-
chain.unshift
|
|
3425
|
-
chain.push
|
|
3557
|
+
chain.unshift(...requestInterceptorChain);
|
|
3558
|
+
chain.push(...responseInterceptorChain);
|
|
3426
3559
|
len = chain.length;
|
|
3427
3560
|
|
|
3428
3561
|
promise = Promise.resolve(config);
|
|
@@ -3901,7 +4034,7 @@ const TX_MIN_FEE = 1000;
|
|
|
3901
4034
|
/**
|
|
3902
4035
|
* Threshold value for dust amount in Dash transactions.
|
|
3903
4036
|
*/
|
|
3904
|
-
|
|
4037
|
+
dashcore.Transaction.DUST_AMOUNT;
|
|
3905
4038
|
/**
|
|
3906
4039
|
* Function to determine the Dash network based on the provided network type.
|
|
3907
4040
|
* @param {Network} network The network type (Mainnet, Testnet, or Stagenet).
|
|
@@ -3927,7 +4060,7 @@ const validateAddress = (address, network) => {
|
|
|
3927
4060
|
Dash.address.toOutputScript(address, dashNetwork(network)); // Convert address to output script
|
|
3928
4061
|
return true; // Address is valid
|
|
3929
4062
|
}
|
|
3930
|
-
catch (
|
|
4063
|
+
catch (_error) {
|
|
3931
4064
|
return false; // Address is invalid
|
|
3932
4065
|
}
|
|
3933
4066
|
};
|
|
@@ -3965,7 +4098,7 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ amount, rec
|
|
|
3965
4098
|
if (!inputs || !outputs)
|
|
3966
4099
|
throw new Error('Insufficient balance for transaction');
|
|
3967
4100
|
// Initialize new Dash transaction
|
|
3968
|
-
const tx = new
|
|
4101
|
+
const tx = new dashcore.Transaction().to(recipient, amount.amount().toNumber());
|
|
3969
4102
|
// Add inputs to the transaction
|
|
3970
4103
|
inputs.forEach((utxo) => {
|
|
3971
4104
|
const insightUtxo = insightUtxos.find((x) => x.txid === utxo.hash && x.vout == utxo.index);
|
|
@@ -3973,12 +4106,12 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ amount, rec
|
|
|
3973
4106
|
throw new Error('Unable to match accumulative inputs with insight UTXOs');
|
|
3974
4107
|
}
|
|
3975
4108
|
const scriptBuffer = Buffer.from(insightUtxo.scriptPubKey, 'hex');
|
|
3976
|
-
const script = new
|
|
3977
|
-
const input = new
|
|
4109
|
+
const script = new dashcore.Script(scriptBuffer);
|
|
4110
|
+
const input = new dashcore.Transaction.Input.PublicKeyHash({
|
|
3978
4111
|
prevTxId: Buffer.from(insightUtxo.txid, 'hex'),
|
|
3979
4112
|
outputIndex: insightUtxo.vout,
|
|
3980
4113
|
script: '',
|
|
3981
|
-
output: new
|
|
4114
|
+
output: new dashcore.Transaction.Output({
|
|
3982
4115
|
satoshis: utxo.value,
|
|
3983
4116
|
script,
|
|
3984
4117
|
}),
|
|
@@ -3986,7 +4119,7 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ amount, rec
|
|
|
3986
4119
|
tx.uncheckedAddInput(input);
|
|
3987
4120
|
});
|
|
3988
4121
|
// Define sender address
|
|
3989
|
-
const senderAddress =
|
|
4122
|
+
const senderAddress = dashcore.Address.fromString(sender, network);
|
|
3990
4123
|
tx.change(senderAddress);
|
|
3991
4124
|
// Add memo to the transaction if provided
|
|
3992
4125
|
if (memo) {
|
|
@@ -4198,6 +4331,9 @@ class Client extends Client$1 {
|
|
|
4198
4331
|
network: this.network,
|
|
4199
4332
|
});
|
|
4200
4333
|
// Return the raw unsigned transaction and UTXOs
|
|
4334
|
+
// ESLint disabled: Dash transaction has proper toString() method that returns hex string
|
|
4335
|
+
// Left as-is during ESLint 8 upgrade as this core crypto functionality is tested and working
|
|
4336
|
+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
4201
4337
|
return { rawUnsignedTx: tx.toString(), utxos, inputs };
|
|
4202
4338
|
});
|
|
4203
4339
|
}
|
|
@@ -4275,7 +4411,7 @@ const broadcastTx = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
4275
4411
|
}
|
|
4276
4412
|
catch (ex) {
|
|
4277
4413
|
// If an exception occurs during the request, reject the promise with the caught error message.
|
|
4278
|
-
return Promise.reject(Error(`failed to broadcast a transaction caught: ${ex}`));
|
|
4414
|
+
return Promise.reject(Error(`failed to broadcast a transaction caught: ${String(ex)}`));
|
|
4279
4415
|
}
|
|
4280
4416
|
});
|
|
4281
4417
|
|