@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.js CHANGED
@@ -752,26 +752,6 @@ const toFiniteNumber = (value, defaultValue) => {
752
752
  return value != null && Number.isFinite(value = +value) ? value : defaultValue;
753
753
  };
754
754
 
755
- const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
756
-
757
- const DIGIT = '0123456789';
758
-
759
- const ALPHABET = {
760
- DIGIT,
761
- ALPHA,
762
- ALPHA_DIGIT: ALPHA + ALPHA.toUpperCase() + DIGIT
763
- };
764
-
765
- const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
766
- let str = '';
767
- const {length} = alphabet;
768
- while (size--) {
769
- str += alphabet[Math.random() * length|0];
770
- }
771
-
772
- return str;
773
- };
774
-
775
755
  /**
776
756
  * If the thing is a FormData object, return true, otherwise return false.
777
757
  *
@@ -899,8 +879,6 @@ var utils$2 = {
899
879
  findKey,
900
880
  global: _global,
901
881
  isContextDefined,
902
- ALPHABET,
903
- generateString,
904
882
  isSpecCompliantForm,
905
883
  toJSONObject,
906
884
  isAsyncFn,
@@ -934,7 +912,10 @@ function AxiosError(message, code, config, request, response) {
934
912
  code && (this.code = code);
935
913
  config && (this.config = config);
936
914
  request && (this.request = request);
937
- response && (this.response = response);
915
+ if (response) {
916
+ this.response = response;
917
+ this.status = response.status ? response.status : null;
918
+ }
938
919
  }
939
920
 
940
921
  utils$2.inherits(AxiosError, Error, {
@@ -954,7 +935,7 @@ utils$2.inherits(AxiosError, Error, {
954
935
  // Axios
955
936
  config: utils$2.toJSONObject(this.config),
956
937
  code: this.code,
957
- status: this.response && this.response.status ? this.response.status : null
938
+ status: this.status
958
939
  };
959
940
  }
960
941
  });
@@ -1294,7 +1275,7 @@ function encode(val) {
1294
1275
  *
1295
1276
  * @param {string} url The base of the url (e.g., http://www.google.com)
1296
1277
  * @param {object} [params] The params to be appended
1297
- * @param {?object} options
1278
+ * @param {?(object|Function)} options
1298
1279
  *
1299
1280
  * @returns {string} The formatted url
1300
1281
  */
@@ -1306,6 +1287,12 @@ function buildURL(url, params, options) {
1306
1287
 
1307
1288
  const _encode = options && options.encode || encode;
1308
1289
 
1290
+ if (utils$2.isFunction(options)) {
1291
+ options = {
1292
+ serialize: options
1293
+ };
1294
+ }
1295
+
1309
1296
  const serializeFn = options && options.serialize;
1310
1297
 
1311
1298
  let serializedParams;
@@ -1420,6 +1407,8 @@ var platform$1 = {
1420
1407
 
1421
1408
  const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
1422
1409
 
1410
+ const _navigator = typeof navigator === 'object' && navigator || undefined;
1411
+
1423
1412
  /**
1424
1413
  * Determine if we're running in a standard browser environment
1425
1414
  *
@@ -1437,10 +1426,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
1437
1426
  *
1438
1427
  * @returns {boolean}
1439
1428
  */
1440
- const hasStandardBrowserEnv = (
1441
- (product) => {
1442
- return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
1443
- })(typeof navigator !== 'undefined' && navigator.product);
1429
+ const hasStandardBrowserEnv = hasBrowserEnv &&
1430
+ (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
1444
1431
 
1445
1432
  /**
1446
1433
  * Determine if we're running in a standard browser webWorker environment
@@ -1467,6 +1454,7 @@ var utils$1 = /*#__PURE__*/Object.freeze({
1467
1454
  hasBrowserEnv: hasBrowserEnv,
1468
1455
  hasStandardBrowserEnv: hasStandardBrowserEnv,
1469
1456
  hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
1457
+ navigator: _navigator,
1470
1458
  origin: origin
1471
1459
  });
1472
1460
 
@@ -2287,68 +2275,18 @@ const progressEventDecorator = (total, throttled) => {
2287
2275
 
2288
2276
  const asyncDecorator = (fn) => (...args) => utils$2.asap(() => fn(...args));
2289
2277
 
2290
- var isURLSameOrigin = platform.hasStandardBrowserEnv ?
2278
+ var isURLSameOrigin = platform.hasStandardBrowserEnv ? ((origin, isMSIE) => (url) => {
2279
+ url = new URL(url, platform.origin);
2291
2280
 
2292
- // Standard browser envs have full support of the APIs needed to test
2293
- // whether the request URL is of the same origin as current location.
2294
- (function standardBrowserEnv() {
2295
- const msie = /(msie|trident)/i.test(navigator.userAgent);
2296
- const urlParsingNode = document.createElement('a');
2297
- let originURL;
2298
-
2299
- /**
2300
- * Parse a URL to discover its components
2301
- *
2302
- * @param {String} url The URL to be parsed
2303
- * @returns {Object}
2304
- */
2305
- function resolveURL(url) {
2306
- let href = url;
2307
-
2308
- if (msie) {
2309
- // IE needs attribute set twice to normalize properties
2310
- urlParsingNode.setAttribute('href', href);
2311
- href = urlParsingNode.href;
2312
- }
2313
-
2314
- urlParsingNode.setAttribute('href', href);
2315
-
2316
- // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
2317
- return {
2318
- href: urlParsingNode.href,
2319
- protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
2320
- host: urlParsingNode.host,
2321
- search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
2322
- hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
2323
- hostname: urlParsingNode.hostname,
2324
- port: urlParsingNode.port,
2325
- pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
2326
- urlParsingNode.pathname :
2327
- '/' + urlParsingNode.pathname
2328
- };
2329
- }
2330
-
2331
- originURL = resolveURL(window.location.href);
2332
-
2333
- /**
2334
- * Determine if a URL shares the same origin as the current location
2335
- *
2336
- * @param {String} requestURL The URL to test
2337
- * @returns {boolean} True if URL shares the same origin, otherwise false
2338
- */
2339
- return function isURLSameOrigin(requestURL) {
2340
- const parsed = (utils$2.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
2341
- return (parsed.protocol === originURL.protocol &&
2342
- parsed.host === originURL.host);
2343
- };
2344
- })() :
2345
-
2346
- // Non standard browser envs (web workers, react-native) lack needed support.
2347
- (function nonStandardBrowserEnv() {
2348
- return function isURLSameOrigin() {
2349
- return true;
2350
- };
2351
- })();
2281
+ return (
2282
+ origin.protocol === url.protocol &&
2283
+ origin.host === url.host &&
2284
+ (isMSIE || origin.port === url.port)
2285
+ );
2286
+ })(
2287
+ new URL(platform.origin),
2288
+ platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent)
2289
+ ) : () => true;
2352
2290
 
2353
2291
  var cookies = platform.hasStandardBrowserEnv ?
2354
2292
 
@@ -2427,8 +2365,9 @@ function combineURLs(baseURL, relativeURL) {
2427
2365
  *
2428
2366
  * @returns {string} The combined full path
2429
2367
  */
2430
- function buildFullPath(baseURL, requestedURL) {
2431
- if (baseURL && !isAbsoluteURL(requestedURL)) {
2368
+ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
2369
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
2370
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls == false)) {
2432
2371
  return combineURLs(baseURL, requestedURL);
2433
2372
  }
2434
2373
  return requestedURL;
@@ -2450,7 +2389,7 @@ function mergeConfig(config1, config2) {
2450
2389
  config2 = config2 || {};
2451
2390
  const config = {};
2452
2391
 
2453
- function getMergedValue(target, source, caseless) {
2392
+ function getMergedValue(target, source, prop, caseless) {
2454
2393
  if (utils$2.isPlainObject(target) && utils$2.isPlainObject(source)) {
2455
2394
  return utils$2.merge.call({caseless}, target, source);
2456
2395
  } else if (utils$2.isPlainObject(source)) {
@@ -2462,11 +2401,11 @@ function mergeConfig(config1, config2) {
2462
2401
  }
2463
2402
 
2464
2403
  // eslint-disable-next-line consistent-return
2465
- function mergeDeepProperties(a, b, caseless) {
2404
+ function mergeDeepProperties(a, b, prop , caseless) {
2466
2405
  if (!utils$2.isUndefined(b)) {
2467
- return getMergedValue(a, b, caseless);
2406
+ return getMergedValue(a, b, prop , caseless);
2468
2407
  } else if (!utils$2.isUndefined(a)) {
2469
- return getMergedValue(undefined, a, caseless);
2408
+ return getMergedValue(undefined, a, prop , caseless);
2470
2409
  }
2471
2410
  }
2472
2411
 
@@ -2524,7 +2463,7 @@ function mergeConfig(config1, config2) {
2524
2463
  socketPath: defaultToConfig2,
2525
2464
  responseEncoding: defaultToConfig2,
2526
2465
  validateStatus: mergeDirectKeys,
2527
- headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
2466
+ headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
2528
2467
  };
2529
2468
 
2530
2469
  utils$2.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
@@ -2543,7 +2482,7 @@ var resolveConfig = (config) => {
2543
2482
 
2544
2483
  newConfig.headers = headers = AxiosHeaders.from(headers);
2545
2484
 
2546
- newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
2485
+ newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url, newConfig.allowAbsoluteUrls), config.params, config.paramsSerializer);
2547
2486
 
2548
2487
  // HTTP basic authentication
2549
2488
  if (auth) {
@@ -2772,45 +2711,46 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2772
2711
  };
2773
2712
 
2774
2713
  const composeSignals = (signals, timeout) => {
2775
- let controller = new AbortController();
2714
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
2776
2715
 
2777
- let aborted;
2716
+ if (timeout || length) {
2717
+ let controller = new AbortController();
2778
2718
 
2779
- const onabort = function (cancel) {
2780
- if (!aborted) {
2781
- aborted = true;
2782
- unsubscribe();
2783
- const err = cancel instanceof Error ? cancel : this.reason;
2784
- controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2785
- }
2786
- };
2719
+ let aborted;
2787
2720
 
2788
- let timer = timeout && setTimeout(() => {
2789
- onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2790
- }, timeout);
2721
+ const onabort = function (reason) {
2722
+ if (!aborted) {
2723
+ aborted = true;
2724
+ unsubscribe();
2725
+ const err = reason instanceof Error ? reason : this.reason;
2726
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2727
+ }
2728
+ };
2791
2729
 
2792
- const unsubscribe = () => {
2793
- if (signals) {
2794
- timer && clearTimeout(timer);
2730
+ let timer = timeout && setTimeout(() => {
2795
2731
  timer = null;
2796
- signals.forEach(signal => {
2797
- signal &&
2798
- (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
2799
- });
2800
- signals = null;
2801
- }
2802
- };
2732
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2733
+ }, timeout);
2734
+
2735
+ const unsubscribe = () => {
2736
+ if (signals) {
2737
+ timer && clearTimeout(timer);
2738
+ timer = null;
2739
+ signals.forEach(signal => {
2740
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
2741
+ });
2742
+ signals = null;
2743
+ }
2744
+ };
2803
2745
 
2804
- signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
2746
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
2805
2747
 
2806
- const {signal} = controller;
2748
+ const {signal} = controller;
2807
2749
 
2808
- signal.unsubscribe = unsubscribe;
2750
+ signal.unsubscribe = () => utils$2.asap(unsubscribe);
2809
2751
 
2810
- return [signal, () => {
2811
- timer && clearTimeout(timer);
2812
- timer = null;
2813
- }];
2752
+ return signal;
2753
+ }
2814
2754
  };
2815
2755
 
2816
2756
  const streamChunk = function* (chunk, chunkSize) {
@@ -2831,14 +2771,34 @@ const streamChunk = function* (chunk, chunkSize) {
2831
2771
  }
2832
2772
  };
2833
2773
 
2834
- const readBytes = async function* (iterable, chunkSize, encode) {
2835
- for await (const chunk of iterable) {
2836
- yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
2774
+ const readBytes = async function* (iterable, chunkSize) {
2775
+ for await (const chunk of readStream(iterable)) {
2776
+ yield* streamChunk(chunk, chunkSize);
2837
2777
  }
2838
2778
  };
2839
2779
 
2840
- const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
2841
- const iterator = readBytes(stream, chunkSize, encode);
2780
+ const readStream = async function* (stream) {
2781
+ if (stream[Symbol.asyncIterator]) {
2782
+ yield* stream;
2783
+ return;
2784
+ }
2785
+
2786
+ const reader = stream.getReader();
2787
+ try {
2788
+ for (;;) {
2789
+ const {done, value} = await reader.read();
2790
+ if (done) {
2791
+ break;
2792
+ }
2793
+ yield value;
2794
+ }
2795
+ } finally {
2796
+ await reader.cancel();
2797
+ }
2798
+ };
2799
+
2800
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2801
+ const iterator = readBytes(stream, chunkSize);
2842
2802
 
2843
2803
  let bytes = 0;
2844
2804
  let done;
@@ -2941,7 +2901,11 @@ const getBodyLength = async (body) => {
2941
2901
  }
2942
2902
 
2943
2903
  if(utils$2.isSpecCompliantForm(body)) {
2944
- return (await new Request(body).arrayBuffer()).byteLength;
2904
+ const _request = new Request(platform.origin, {
2905
+ method: 'POST',
2906
+ body,
2907
+ });
2908
+ return (await _request.arrayBuffer()).byteLength;
2945
2909
  }
2946
2910
 
2947
2911
  if(utils$2.isArrayBufferView(body) || utils$2.isArrayBuffer(body)) {
@@ -2981,18 +2945,13 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2981
2945
 
2982
2946
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2983
2947
 
2984
- let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
2985
- composeSignals([signal, cancelToken], timeout) : [];
2948
+ let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2986
2949
 
2987
- let finished, request;
2988
-
2989
- const onFinish = () => {
2990
- !finished && setTimeout(() => {
2991
- composedSignal && composedSignal.unsubscribe();
2992
- });
2950
+ let request;
2993
2951
 
2994
- finished = true;
2995
- };
2952
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2953
+ composedSignal.unsubscribe();
2954
+ });
2996
2955
 
2997
2956
  let requestContentLength;
2998
2957
 
@@ -3019,7 +2978,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3019
2978
  progressEventReducer(asyncDecorator(onUploadProgress))
3020
2979
  );
3021
2980
 
3022
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
2981
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
3023
2982
  }
3024
2983
  }
3025
2984
 
@@ -3027,6 +2986,9 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3027
2986
  withCredentials = withCredentials ? 'include' : 'omit';
3028
2987
  }
3029
2988
 
2989
+ // Cloudflare Workers throws when credentials are defined
2990
+ // see https://github.com/cloudflare/workerd/issues/902
2991
+ const isCredentialsSupported = "credentials" in Request.prototype;
3030
2992
  request = new Request(url, {
3031
2993
  ...fetchOptions,
3032
2994
  signal: composedSignal,
@@ -3034,14 +2996,14 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3034
2996
  headers: headers.normalize().toJSON(),
3035
2997
  body: data,
3036
2998
  duplex: "half",
3037
- credentials: withCredentials
2999
+ credentials: isCredentialsSupported ? withCredentials : undefined
3038
3000
  });
3039
3001
 
3040
3002
  let response = await fetch(request);
3041
3003
 
3042
3004
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
3043
3005
 
3044
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
3006
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
3045
3007
  const options = {};
3046
3008
 
3047
3009
  ['status', 'statusText', 'headers'].forEach(prop => {
@@ -3058,8 +3020,8 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3058
3020
  response = new Response(
3059
3021
  trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
3060
3022
  flush && flush();
3061
- isStreamResponse && onFinish();
3062
- }, encodeText),
3023
+ unsubscribe && unsubscribe();
3024
+ }),
3063
3025
  options
3064
3026
  );
3065
3027
  }
@@ -3068,9 +3030,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3068
3030
 
3069
3031
  let responseData = await resolvers[utils$2.findKey(resolvers, responseType) || 'text'](response, config);
3070
3032
 
3071
- !isStreamResponse && onFinish();
3072
-
3073
- stopTimeout && stopTimeout();
3033
+ !isStreamResponse && unsubscribe && unsubscribe();
3074
3034
 
3075
3035
  return await new Promise((resolve, reject) => {
3076
3036
  settle(resolve, reject, {
@@ -3083,7 +3043,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
3083
3043
  });
3084
3044
  })
3085
3045
  } catch (err) {
3086
- onFinish();
3046
+ unsubscribe && unsubscribe();
3087
3047
 
3088
3048
  if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
3089
3049
  throw Object.assign(
@@ -3245,7 +3205,7 @@ function dispatchRequest(config) {
3245
3205
  });
3246
3206
  }
3247
3207
 
3248
- const VERSION = "1.7.4";
3208
+ const VERSION = "1.8.4";
3249
3209
 
3250
3210
  const validators$1 = {};
3251
3211
 
@@ -3296,6 +3256,14 @@ validators$1.transitional = function transitional(validator, version, message) {
3296
3256
  };
3297
3257
  };
3298
3258
 
3259
+ validators$1.spelling = function spelling(correctSpelling) {
3260
+ return (value, opt) => {
3261
+ // eslint-disable-next-line no-console
3262
+ console.warn(`${opt} is likely a misspelling of ${correctSpelling}`);
3263
+ return true;
3264
+ }
3265
+ };
3266
+
3299
3267
  /**
3300
3268
  * Assert object's properties type
3301
3269
  *
@@ -3365,9 +3333,9 @@ class Axios {
3365
3333
  return await this._request(configOrUrl, config);
3366
3334
  } catch (err) {
3367
3335
  if (err instanceof Error) {
3368
- let dummy;
3336
+ let dummy = {};
3369
3337
 
3370
- Error.captureStackTrace ? Error.captureStackTrace(dummy = {}) : (dummy = new Error());
3338
+ Error.captureStackTrace ? Error.captureStackTrace(dummy) : (dummy = new Error());
3371
3339
 
3372
3340
  // slice off the Error: ... line
3373
3341
  const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
@@ -3422,6 +3390,18 @@ class Axios {
3422
3390
  }
3423
3391
  }
3424
3392
 
3393
+ // Set config.allowAbsoluteUrls
3394
+ if (config.allowAbsoluteUrls !== undefined) ; else if (this.defaults.allowAbsoluteUrls !== undefined) {
3395
+ config.allowAbsoluteUrls = this.defaults.allowAbsoluteUrls;
3396
+ } else {
3397
+ config.allowAbsoluteUrls = true;
3398
+ }
3399
+
3400
+ validator.assertOptions(config, {
3401
+ baseUrl: validators.spelling('baseURL'),
3402
+ withXsrfToken: validators.spelling('withXSRFToken')
3403
+ }, true);
3404
+
3425
3405
  // Set config.method
3426
3406
  config.method = (config.method || this.defaults.method || 'get').toLowerCase();
3427
3407
 
@@ -3512,7 +3492,7 @@ class Axios {
3512
3492
 
3513
3493
  getUri(config) {
3514
3494
  config = mergeConfig(this.defaults, config);
3515
- const fullPath = buildFullPath(config.baseURL, config.url);
3495
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
3516
3496
  return buildURL(fullPath, config.params, config.paramsSerializer);
3517
3497
  }
3518
3498
  }
@@ -3650,6 +3630,20 @@ class CancelToken {
3650
3630
  }
3651
3631
  }
3652
3632
 
3633
+ toAbortSignal() {
3634
+ const controller = new AbortController();
3635
+
3636
+ const abort = (err) => {
3637
+ controller.abort(err);
3638
+ };
3639
+
3640
+ this.subscribe(abort);
3641
+
3642
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
3643
+
3644
+ return controller.signal;
3645
+ }
3646
+
3653
3647
  /**
3654
3648
  * Returns an object that contains a new `CancelToken` and a function that, when called,
3655
3649
  * cancels the `CancelToken`.