@xchainjs/xchain-dash 1.0.9 → 1.0.11

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
@@ -725,26 +725,6 @@ const toFiniteNumber = (value, defaultValue) => {
725
725
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
726
726
  };
727
727
 
728
- const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
729
-
730
- const DIGIT = '0123456789';
731
-
732
- const ALPHABET = {
733
- DIGIT,
734
- ALPHA,
735
- ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
736
- };
737
-
738
- const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
739
- let str = '';
740
- const {length} = alphabet;
741
- while (size--) {
742
- str += alphabet[Math.random() * length|0];
743
- }
744
-
745
- return str;
746
- };
747
-
748
728
  /**
749
729
  * If the thing is a FormData object, return true, otherwise return false.
750
730
  *
@@ -872,8 +852,6 @@ var utils$2 = {
872
852
  findKey,
873
853
  global: _global,
874
854
  isContextDefined,
875
- ALPHABET,
876
- generateString,
877
855
  isSpecCompliantForm,
878
856
  toJSONObject,
879
857
  isAsyncFn,
@@ -907,7 +885,10 @@ function AxiosError(message, code, config, request, response) {
907
885
  code && (this.code = code);
908
886
  config && (this.config = config);
909
887
  request && (this.request = request);
910
- response && (this.response = response);
888
+ if (response) {
889
+ this.response = response;
890
+ this.status = response.status ? response.status : null;
891
+ }
911
892
  }
912
893
 
913
894
  utils$2.inherits(AxiosError, Error, {
@@ -927,7 +908,7 @@ utils$2.inherits(AxiosError, Error, {
927
908
  // Axios
928
909
  config: utils$2.toJSONObject(this.config),
929
910
  code: this.code,
930
- status: this.response && this.response.status ? this.response.status : null
911
+ status: this.status
931
912
  };
932
913
  }
933
914
  });
@@ -1267,7 +1248,7 @@ function encode(val) {
1267
1248
  *
1268
1249
  * @param {string} url The base of the url (e.g., http://www.google.com)
1269
1250
  * @param {object} [params] The params to be appended
1270
- * @param {?object} options
1251
+ * @param {?(object|Function)} options
1271
1252
  *
1272
1253
  * @returns {string} The formatted url
1273
1254
  */
@@ -1279,6 +1260,12 @@ function buildURL(url, params, options) {
1279
1260
 
1280
1261
  const _encode = options && options.encode || encode;
1281
1262
 
1263
+ if (utils$2.isFunction(options)) {
1264
+ options = {
1265
+ serialize: options
1266
+ };
1267
+ }
1268
+
1282
1269
  const serializeFn = options && options.serialize;
1283
1270
 
1284
1271
  let serializedParams;
@@ -1393,6 +1380,8 @@ var platform$1 = {
1393
1380
 
1394
1381
  const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
1395
1382
 
1383
+ const _navigator = typeof navigator === 'object' && navigator || undefined;
1384
+
1396
1385
  /**
1397
1386
  * Determine if we're running in a standard browser environment
1398
1387
  *
@@ -1410,10 +1399,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
1410
1399
  *
1411
1400
  * @returns {boolean}
1412
1401
  */
1413
- const hasStandardBrowserEnv = (
1414
- (product) => {
1415
- return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
1416
- })(typeof navigator !== 'undefined' && navigator.product);
1402
+ const hasStandardBrowserEnv = hasBrowserEnv &&
1403
+ (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
1417
1404
 
1418
1405
  /**
1419
1406
  * Determine if we're running in a standard browser webWorker environment
@@ -1440,6 +1427,7 @@ var utils$1 = /*#__PURE__*/Object.freeze({
1440
1427
  hasBrowserEnv: hasBrowserEnv,
1441
1428
  hasStandardBrowserEnv: hasStandardBrowserEnv,
1442
1429
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1430
+ navigator: _navigator,
1443
1431
  origin: origin
1444
1432
  });
1445
1433
 
@@ -2260,68 +2248,18 @@ const progressEventDecorator = (total, throttled) => {
2260
2248
 
2261
2249
  const asyncDecorator = (fn) => (...args) => utils$2.asap(() => fn(...args));
2262
2250
 
2263
- var isURLSameOrigin = platform.hasStandardBrowserEnv ?
2251
+ var isURLSameOrigin = platform.hasStandardBrowserEnv ? ((origin, isMSIE) => (url) => {
2252
+ url = new URL(url, platform.origin);
2264
2253
 
2265
- // Standard browser envs have full support of the APIs needed to test
2266
- // whether the request URL is of the same origin as current location.
2267
- (function standardBrowserEnv() {
2268
- const msie = /(msie|trident)/i.test(navigator.userAgent);
2269
- const urlParsingNode = document.createElement('a');
2270
- let originURL;
2271
-
2272
- /**
2273
- * Parse a URL to discover its components
2274
- *
2275
- * @param {String} url The URL to be parsed
2276
- * @returns {Object}
2277
- */
2278
- function resolveURL(url) {
2279
- let href = url;
2280
-
2281
- if (msie) {
2282
- // IE needs attribute set twice to normalize properties
2283
- urlParsingNode.setAttribute('href', href);
2284
- href = urlParsingNode.href;
2285
- }
2286
-
2287
- urlParsingNode.setAttribute('href', href);
2288
-
2289
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2290
- return {
2291
- href: urlParsingNode.href,
2292
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2293
- host: urlParsingNode.host,
2294
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2295
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2296
- hostname: urlParsingNode.hostname,
2297
- port: urlParsingNode.port,
2298
- pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
2299
- urlParsingNode.pathname :
2300
- '/' + urlParsingNode.pathname
2301
- };
2302
- }
2303
-
2304
- originURL = resolveURL(window.location.href);
2305
-
2306
- /**
2307
- * Determine if a URL shares the same origin as the current location
2308
- *
2309
- * @param {String} requestURL The URL to test
2310
- * @returns {boolean} True if URL shares the same origin, otherwise false
2311
- */
2312
- return function isURLSameOrigin(requestURL) {
2313
- const parsed = (utils$2.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2314
- return (parsed.protocol === originURL.protocol &&
2315
- parsed.host === originURL.host);
2316
- };
2317
- })() :
2318
-
2319
- // Non standard browser envs (web workers, react-native) lack needed support.
2320
- (function nonStandardBrowserEnv() {
2321
- return function isURLSameOrigin() {
2322
- return true;
2323
- };
2324
- })();
2254
+ return (
2255
+ origin.protocol === url.protocol &&
2256
+ origin.host === url.host &&
2257
+ (isMSIE || origin.port === url.port)
2258
+ );
2259
+ })(
2260
+ new URL(platform.origin),
2261
+ platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
2262
+ ) : () => true;
2325
2263
 
2326
2264
  var cookies = platform.hasStandardBrowserEnv ?
2327
2265
 
@@ -2400,8 +2338,9 @@ function combineURLs(baseURL, relativeURL) {
2400
2338
  *
2401
2339
  * @returns {string} The combined full path
2402
2340
  */
2403
- function buildFullPath(baseURL, requestedURL) {
2404
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2341
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2342
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
2343
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
2405
2344
  return combineURLs(baseURL, requestedURL);
2406
2345
  }
2407
2346
  return requestedURL;
@@ -2423,7 +2362,7 @@ function mergeConfig(config1, config2) {
2423
2362
  config2 = config2 || {};
2424
2363
  const config = {};
2425
2364
 
2426
- function getMergedValue(target, source, caseless) {
2365
+ function getMergedValue(target, source, prop, caseless) {
2427
2366
  if (utils$2.isPlainObject(target) && utils$2.isPlainObject(source)) {
2428
2367
  return utils$2.merge.call({caseless}, target, source);
2429
2368
  } else if (utils$2.isPlainObject(source)) {
@@ -2435,11 +2374,11 @@ function mergeConfig(config1, config2) {
2435
2374
  }
2436
2375
 
2437
2376
  // eslint-disable-next-line consistent-return
2438
- function mergeDeepProperties(a, b, caseless) {
2377
+ function mergeDeepProperties(a, b, prop , caseless) {
2439
2378
  if (!utils$2.isUndefined(b)) {
2440
- return getMergedValue(a, b, caseless);
2379
+ return getMergedValue(a, b, prop , caseless);
2441
2380
  } else if (!utils$2.isUndefined(a)) {
2442
- return getMergedValue(undefined, a, caseless);
2381
+ return getMergedValue(undefined, a, prop , caseless);
2443
2382
  }
2444
2383
  }
2445
2384
 
@@ -2497,7 +2436,7 @@ function mergeConfig(config1, config2) {
2497
2436
  socketPath: defaultToConfig2,
2498
2437
  responseEncoding: defaultToConfig2,
2499
2438
  validateStatus: mergeDirectKeys,
2500
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2439
+ headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2501
2440
  };
2502
2441
 
2503
2442
  utils$2.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
@@ -2516,7 +2455,7 @@ var resolveConfig = (config) => {
2516
2455
 
2517
2456
  newConfig.headers = headers = AxiosHeaders.from(headers);
2518
2457
 
2519
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2458
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
2520
2459
 
2521
2460
  // HTTP basic authentication
2522
2461
  if (auth) {
@@ -2745,45 +2684,46 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2745
2684
  };
2746
2685
 
2747
2686
  const composeSignals = (signals, timeout) => {
2748
- let controller = new AbortController();
2687
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
2749
2688
 
2750
- let aborted;
2689
+ if (timeout || length) {
2690
+ let controller = new AbortController();
2751
2691
 
2752
- const onabort = function (cancel) {
2753
- if (!aborted) {
2754
- aborted = true;
2755
- unsubscribe();
2756
- const err = cancel instanceof Error ? cancel : this.reason;
2757
- controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2758
- }
2759
- };
2692
+ let aborted;
2760
2693
 
2761
- let timer = timeout && setTimeout(() => {
2762
- onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2763
- }, timeout);
2694
+ const onabort = function (reason) {
2695
+ if (!aborted) {
2696
+ aborted = true;
2697
+ unsubscribe();
2698
+ const err = reason instanceof Error ? reason : this.reason;
2699
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2700
+ }
2701
+ };
2764
2702
 
2765
- const unsubscribe = () => {
2766
- if (signals) {
2767
- timer && clearTimeout(timer);
2703
+ let timer = timeout && setTimeout(() => {
2768
2704
  timer = null;
2769
- signals.forEach(signal => {
2770
- signal &&
2771
- (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
2772
- });
2773
- signals = null;
2774
- }
2775
- };
2705
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2706
+ }, timeout);
2707
+
2708
+ const unsubscribe = () => {
2709
+ if (signals) {
2710
+ timer && clearTimeout(timer);
2711
+ timer = null;
2712
+ signals.forEach(signal => {
2713
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
2714
+ });
2715
+ signals = null;
2716
+ }
2717
+ };
2776
2718
 
2777
- signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
2719
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
2778
2720
 
2779
- const {signal} = controller;
2721
+ const {signal} = controller;
2780
2722
 
2781
- signal.unsubscribe = unsubscribe;
2723
+ signal.unsubscribe = () => utils$2.asap(unsubscribe);
2782
2724
 
2783
- return [signal, () => {
2784
- timer && clearTimeout(timer);
2785
- timer = null;
2786
- }];
2725
+ return signal;
2726
+ }
2787
2727
  };
2788
2728
 
2789
2729
  const streamChunk = function* (chunk, chunkSize) {
@@ -2804,14 +2744,34 @@ const streamChunk = function* (chunk, chunkSize) {
2804
2744
  }
2805
2745
  };
2806
2746
 
2807
- const readBytes = async function* (iterable, chunkSize, encode) {
2808
- for await (const chunk of iterable) {
2809
- yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
2747
+ const readBytes = async function* (iterable, chunkSize) {
2748
+ for await (const chunk of readStream(iterable)) {
2749
+ yield* streamChunk(chunk, chunkSize);
2810
2750
  }
2811
2751
  };
2812
2752
 
2813
- const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
2814
- const iterator = readBytes(stream, chunkSize, encode);
2753
+ const readStream = async function* (stream) {
2754
+ if (stream[Symbol.asyncIterator]) {
2755
+ yield* stream;
2756
+ return;
2757
+ }
2758
+
2759
+ const reader = stream.getReader();
2760
+ try {
2761
+ for (;;) {
2762
+ const {done, value} = await reader.read();
2763
+ if (done) {
2764
+ break;
2765
+ }
2766
+ yield value;
2767
+ }
2768
+ } finally {
2769
+ await reader.cancel();
2770
+ }
2771
+ };
2772
+
2773
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2774
+ const iterator = readBytes(stream, chunkSize);
2815
2775
 
2816
2776
  let bytes = 0;
2817
2777
  let done;
@@ -2914,7 +2874,11 @@ const getBodyLength = async (body) => {
2914
2874
  }
2915
2875
 
2916
2876
  if(utils$2.isSpecCompliantForm(body)) {
2917
- return (await new Request(body).arrayBuffer()).byteLength;
2877
+ const _request = new Request(platform.origin, {
2878
+ method: 'POST',
2879
+ body,
2880
+ });
2881
+ return (await _request.arrayBuffer()).byteLength;
2918
2882
  }
2919
2883
 
2920
2884
  if(utils$2.isArrayBufferView(body) || utils$2.isArrayBuffer(body)) {
@@ -2954,18 +2918,13 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2954
2918
 
2955
2919
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2956
2920
 
2957
- let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
2958
- composeSignals([signal, cancelToken], timeout) : [];
2921
+ let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2959
2922
 
2960
- let finished, request;
2961
-
2962
- const onFinish = () => {
2963
- !finished && setTimeout(() => {
2964
- composedSignal && composedSignal.unsubscribe();
2965
- });
2923
+ let request;
2966
2924
 
2967
- finished = true;
2968
- };
2925
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2926
+ composedSignal.unsubscribe();
2927
+ });
2969
2928
 
2970
2929
  let requestContentLength;
2971
2930
 
@@ -2992,7 +2951,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2992
2951
  progressEventReducer(asyncDecorator(onUploadProgress))
2993
2952
  );
2994
2953
 
2995
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
2954
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2996
2955
  }
2997
2956
  }
2998
2957
 
@@ -3000,6 +2959,9 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3000
2959
  withCredentials = withCredentials ? 'include' : 'omit';
3001
2960
  }
3002
2961
 
2962
+ // Cloudflare Workers throws when credentials are defined
2963
+ // see https://github.com/cloudflare/workerd/issues/902
2964
+ const isCredentialsSupported = "credentials" in Request.prototype;
3003
2965
  request = new Request(url, {
3004
2966
  ...fetchOptions,
3005
2967
  signal: composedSignal,
@@ -3007,14 +2969,14 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3007
2969
  headers: headers.normalize().toJSON(),
3008
2970
  body: data,
3009
2971
  duplex: "half",
3010
- credentials: withCredentials
2972
+ credentials: isCredentialsSupported ? withCredentials : undefined
3011
2973
  });
3012
2974
 
3013
2975
  let response = await fetch(request);
3014
2976
 
3015
2977
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
3016
2978
 
3017
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
2979
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
3018
2980
  const options = {};
3019
2981
 
3020
2982
  ['status', 'statusText', 'headers'].forEach(prop => {
@@ -3031,8 +2993,8 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3031
2993
  response = new Response(
3032
2994
  trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
3033
2995
  flush && flush();
3034
- isStreamResponse && onFinish();
3035
- }, encodeText),
2996
+ unsubscribe && unsubscribe();
2997
+ }),
3036
2998
  options
3037
2999
  );
3038
3000
  }
@@ -3041,9 +3003,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3041
3003
 
3042
3004
  let responseData = await resolvers[utils$2.findKey(resolvers, responseType) || 'text'](response, config);
3043
3005
 
3044
- !isStreamResponse && onFinish();
3045
-
3046
- stopTimeout && stopTimeout();
3006
+ !isStreamResponse && unsubscribe && unsubscribe();
3047
3007
 
3048
3008
  return await new Promise((resolve, reject) => {
3049
3009
  settle(resolve, reject, {
@@ -3056,7 +3016,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3056
3016
  });
3057
3017
  })
3058
3018
  } catch (err) {
3059
- onFinish();
3019
+ unsubscribe && unsubscribe();
3060
3020
 
3061
3021
  if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
3062
3022
  throw Object.assign(
@@ -3218,7 +3178,7 @@ function dispatchRequest(config) {
3218
3178
  });
3219
3179
  }
3220
3180
 
3221
- const VERSION = "1.7.4";
3181
+ const VERSION = "1.8.4";
3222
3182
 
3223
3183
  const validators$1 = {};
3224
3184
 
@@ -3269,6 +3229,14 @@ validators$1.transitional = function transitional(validator, version, message) {
3269
3229
  };
3270
3230
  };
3271
3231
 
3232
+ validators$1.spelling = function spelling(correctSpelling) {
3233
+ return (value, opt) => {
3234
+ // eslint-disable-next-line no-console
3235
+ console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
3236
+ return true;
3237
+ }
3238
+ };
3239
+
3272
3240
  /**
3273
3241
  * Assert object's properties type
3274
3242
  *
@@ -3338,9 +3306,9 @@ class Axios {
3338
3306
  return await this._request(configOrUrl, config);
3339
3307
  } catch (err) {
3340
3308
  if (err instanceof Error) {
3341
- let dummy;
3309
+ let dummy = {};
3342
3310
 
3343
- Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
3311
+ Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
3344
3312
 
3345
3313
  // slice off the Error: ... line
3346
3314
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
@@ -3395,6 +3363,18 @@ class Axios {
3395
3363
  }
3396
3364
  }
3397
3365
 
3366
+ // Set config.allowAbsoluteUrls
3367
+ if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
3368
+ config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
3369
+ } else {
3370
+ config.allowAbsoluteUrls = true;
3371
+ }
3372
+
3373
+ validator.assertOptions(config, {
3374
+ baseUrl: validators.spelling('baseURL'),
3375
+ withXsrfToken: validators.spelling('withXSRFToken')
3376
+ }, true);
3377
+
3398
3378
  // Set config.method
3399
3379
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3400
3380
 
@@ -3485,7 +3465,7 @@ class Axios {
3485
3465
 
3486
3466
  getUri(config) {
3487
3467
  config = mergeConfig(this.defaults, config);
3488
- const fullPath = buildFullPath(config.baseURL, config.url);
3468
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
3489
3469
  return buildURL(fullPath, config.params, config.paramsSerializer);
3490
3470
  }
3491
3471
  }
@@ -3623,6 +3603,20 @@ class CancelToken {
3623
3603
  }
3624
3604
  }
3625
3605
 
3606
+ toAbortSignal() {
3607
+ const controller = new AbortController();
3608
+
3609
+ const abort = (err) => {
3610
+ controller.abort(err);
3611
+ };
3612
+
3613
+ this.subscribe(abort);
3614
+
3615
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
3616
+
3617
+ return controller.signal;
3618
+ }
3619
+
3626
3620
  /**
3627
3621
  * Returns an object that contains a new `CancelToken` and a function that, when called,
3628
3622
  * cancels the `CancelToken`.