@covalenthq/client-sdk 0.6.7 → 0.7.0

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.
Files changed (70) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/index.js +576 -25
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +2 -1
  5. package/dist/cjs/services/BaseService.d.ts +55 -2
  6. package/dist/cjs/services/CovalentClient.d.ts +3 -1
  7. package/dist/cjs/services/NftService.d.ts +2 -1
  8. package/dist/cjs/services/PricingService.d.ts +2 -1
  9. package/dist/cjs/services/SecurityService.d.ts +2 -1
  10. package/dist/cjs/services/TransactionService.d.ts +5 -4
  11. package/dist/cjs/services/XykService.d.ts +2 -1
  12. package/dist/cjs/util/ApiKeyValidator.d.ts +8 -0
  13. package/dist/cjs/util/types/BaseServiceTypes.d.ts +36 -0
  14. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +3 -3
  15. package/dist/es/index.js +576 -25
  16. package/dist/es/index.js.map +1 -1
  17. package/dist/es/services/BalanceService.d.ts +2 -1
  18. package/dist/es/services/BaseService.d.ts +55 -2
  19. package/dist/es/services/CovalentClient.d.ts +3 -1
  20. package/dist/es/services/NftService.d.ts +2 -1
  21. package/dist/es/services/PricingService.d.ts +2 -1
  22. package/dist/es/services/SecurityService.d.ts +2 -1
  23. package/dist/es/services/TransactionService.d.ts +5 -4
  24. package/dist/es/services/XykService.d.ts +2 -1
  25. package/dist/es/util/ApiKeyValidator.d.ts +8 -0
  26. package/dist/es/util/types/BaseServiceTypes.d.ts +36 -0
  27. package/dist/es/util/types/TransactionServiceTypes.d.ts +3 -3
  28. package/dist/esm/index.js +576 -25
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/services/BalanceService.d.ts +2 -1
  31. package/dist/esm/services/BaseService.d.ts +55 -2
  32. package/dist/esm/services/CovalentClient.d.ts +3 -1
  33. package/dist/esm/services/NftService.d.ts +2 -1
  34. package/dist/esm/services/PricingService.d.ts +2 -1
  35. package/dist/esm/services/SecurityService.d.ts +2 -1
  36. package/dist/esm/services/TransactionService.d.ts +5 -4
  37. package/dist/esm/services/XykService.d.ts +2 -1
  38. package/dist/esm/util/ApiKeyValidator.d.ts +8 -0
  39. package/dist/esm/util/types/BaseServiceTypes.d.ts +36 -0
  40. package/dist/esm/util/types/TransactionServiceTypes.d.ts +3 -3
  41. package/dist/services/BalanceService.d.ts +2 -1
  42. package/dist/services/BalanceService.js +57 -1
  43. package/dist/services/BalanceService.js.map +1 -1
  44. package/dist/services/BaseService.d.ts +55 -2
  45. package/dist/services/BaseService.js +187 -1
  46. package/dist/services/BaseService.js.map +1 -1
  47. package/dist/services/CovalentClient.d.ts +3 -1
  48. package/dist/services/CovalentClient.js +20 -15
  49. package/dist/services/CovalentClient.js.map +1 -1
  50. package/dist/services/NftService.d.ts +2 -1
  51. package/dist/services/NftService.js +113 -1
  52. package/dist/services/NftService.js.map +1 -1
  53. package/dist/services/PricingService.d.ts +2 -1
  54. package/dist/services/PricingService.js +11 -1
  55. package/dist/services/PricingService.js.map +1 -1
  56. package/dist/services/SecurityService.d.ts +2 -1
  57. package/dist/services/SecurityService.js +19 -1
  58. package/dist/services/SecurityService.js.map +1 -1
  59. package/dist/services/TransactionService.d.ts +5 -4
  60. package/dist/services/TransactionService.js +49 -4
  61. package/dist/services/TransactionService.js.map +1 -1
  62. package/dist/services/XykService.d.ts +2 -1
  63. package/dist/services/XykService.js +115 -1
  64. package/dist/services/XykService.js.map +1 -1
  65. package/dist/util/ApiKeyValidator.d.ts +8 -0
  66. package/dist/util/ApiKeyValidator.js +13 -0
  67. package/dist/util/ApiKeyValidator.js.map +1 -0
  68. package/dist/util/types/BaseServiceTypes.d.ts +36 -0
  69. package/dist/util/types/TransactionServiceTypes.d.ts +3 -3
  70. package/package.json +1 -1
package/dist/cjs/index.js CHANGED
@@ -285,6 +285,19 @@ async function* paginateEndpoint$1(url, apiKey, urlsParams, dataClassConstructor
285
285
  }
286
286
  }
287
287
 
288
+ class ApiKeyValidator {
289
+ constructor(apiKey) {
290
+ this._apiKey = apiKey;
291
+ }
292
+ isValidApiKey() {
293
+ return ApiKeyValidator._apiKeyV1Pattern.test(this._apiKey) || ApiKeyValidator._apiKeyV2Pattern.test(this._apiKey);
294
+ }
295
+ }
296
+ // Regular expression patterns
297
+ ApiKeyValidator._apiKeyV1Pattern = /^ckey_([a-f0-9]{27})$/;
298
+ ApiKeyValidator._apiKeyV2Pattern = /^cqt_(wF|rQ)([bcdfghjkmpqrtvwxyBCDFGHJKMPQRTVWXY346789]{26})$/;
299
+ ApiKeyValidator.INVALID_API_KEY_MESSAGE = "Invalid or missing API key (sign up at covalenthq.com/platform)";
300
+
288
301
  class ApprovalsResponse {
289
302
  constructor(data) {
290
303
  this.address = data.address;
@@ -372,10 +385,11 @@ class NftApprovalSpender {
372
385
  *
373
386
  */
374
387
  class SecurityService {
375
- constructor(apiKey, debug = false, threadCount = 3) {
388
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
376
389
  this.apiKey = apiKey;
377
390
  this.debug = debug;
378
391
  this.threadCount = threadCount;
392
+ this.is_key_valid = is_key_valid;
379
393
  this.LIMIT = pLimit$1(this.threadCount);
380
394
  }
381
395
  /**
@@ -394,6 +408,14 @@ class SecurityService {
394
408
  while (!success) {
395
409
  try {
396
410
  const urlParams = new URLSearchParams();
411
+ if (!this.is_key_valid) {
412
+ return {
413
+ data: null,
414
+ error: true,
415
+ error_code: 401,
416
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
417
+ };
418
+ }
397
419
  let startTime;
398
420
  if (this.debug) {
399
421
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -458,6 +480,14 @@ class SecurityService {
458
480
  while (!success) {
459
481
  try {
460
482
  const urlParams = new URLSearchParams();
483
+ if (!this.is_key_valid) {
484
+ return {
485
+ data: null,
486
+ error: true,
487
+ error_code: 401,
488
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
489
+ };
490
+ }
461
491
  let startTime;
462
492
  if (this.debug) {
463
493
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -790,10 +820,11 @@ class NativeBalanceItem {
790
820
  *
791
821
  */
792
822
  class BalanceService {
793
- constructor(apiKey, debug = false, threadCount = 3) {
823
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
794
824
  this.apiKey = apiKey;
795
825
  this.debug = debug;
796
826
  this.threadCount = threadCount;
827
+ this.is_key_valid = is_key_valid;
797
828
  this.LIMIT = pLimit$1(this.threadCount);
798
829
  }
799
830
  /**
@@ -818,6 +849,14 @@ class BalanceService {
818
849
  while (!success) {
819
850
  try {
820
851
  const urlParams = new URLSearchParams();
852
+ if (!this.is_key_valid) {
853
+ return {
854
+ data: null,
855
+ error: true,
856
+ error_code: 401,
857
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
858
+ };
859
+ }
821
860
  if (queryParamOpts?.quoteCurrency !== undefined) {
822
861
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
823
862
  }
@@ -901,6 +940,14 @@ class BalanceService {
901
940
  while (!success) {
902
941
  try {
903
942
  const urlParams = new URLSearchParams();
943
+ if (!this.is_key_valid) {
944
+ return {
945
+ data: null,
946
+ error: true,
947
+ error_code: 401,
948
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
949
+ };
950
+ }
904
951
  if (queryParamOpts?.quoteCurrency !== undefined) {
905
952
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
906
953
  }
@@ -977,6 +1024,9 @@ class BalanceService {
977
1024
  while (!success) {
978
1025
  try {
979
1026
  const urlParams = new URLSearchParams();
1027
+ if (!this.is_key_valid) {
1028
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
1029
+ }
980
1030
  if (queryParamOpts?.quoteCurrency !== undefined) {
981
1031
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
982
1032
  }
@@ -1029,6 +1079,14 @@ class BalanceService {
1029
1079
  while (!success) {
1030
1080
  try {
1031
1081
  const urlParams = new URLSearchParams();
1082
+ if (!this.is_key_valid) {
1083
+ return {
1084
+ data: null,
1085
+ error: true,
1086
+ error_code: 401,
1087
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1088
+ };
1089
+ }
1032
1090
  if (queryParamOpts?.quoteCurrency !== undefined) {
1033
1091
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1034
1092
  }
@@ -1115,6 +1173,9 @@ class BalanceService {
1115
1173
  while (!success) {
1116
1174
  try {
1117
1175
  const urlParams = new URLSearchParams();
1176
+ if (!this.is_key_valid) {
1177
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
1178
+ }
1118
1179
  if (queryParamOpts?.blockHeight !== undefined) {
1119
1180
  urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
1120
1181
  }
@@ -1159,6 +1220,14 @@ class BalanceService {
1159
1220
  while (!success) {
1160
1221
  try {
1161
1222
  const urlParams = new URLSearchParams();
1223
+ if (!this.is_key_valid) {
1224
+ return {
1225
+ data: null,
1226
+ error: true,
1227
+ error_code: 401,
1228
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1229
+ };
1230
+ }
1162
1231
  if (queryParamOpts?.blockHeight !== undefined) {
1163
1232
  urlParams.append("block-height", queryParamOpts?.blockHeight.toString());
1164
1233
  }
@@ -1244,6 +1313,14 @@ class BalanceService {
1244
1313
  while (!success) {
1245
1314
  try {
1246
1315
  const urlParams = new URLSearchParams();
1316
+ if (!this.is_key_valid) {
1317
+ return {
1318
+ data: null,
1319
+ error: true,
1320
+ error_code: 401,
1321
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1322
+ };
1323
+ }
1247
1324
  if (queryParamOpts?.quoteCurrency !== undefined) {
1248
1325
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1249
1326
  }
@@ -1331,6 +1408,14 @@ class BalanceService {
1331
1408
  while (!success) {
1332
1409
  try {
1333
1410
  const urlParams = new URLSearchParams();
1411
+ if (!this.is_key_valid) {
1412
+ return {
1413
+ data: null,
1414
+ error: true,
1415
+ error_code: 401,
1416
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1417
+ };
1418
+ }
1334
1419
  if (queryParamOpts?.quoteCurrency !== undefined) {
1335
1420
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1336
1421
  }
@@ -1577,15 +1662,43 @@ class ChainActivityEvent extends ChainItem {
1577
1662
  this.last_seen_at = data.last_seen_at && data.last_seen_at !== null ? dateFns.parseISO(data.last_seen_at.toString()) : null;
1578
1663
  }
1579
1664
  }
1665
+ class GasPricesResponse {
1666
+ constructor(data) {
1667
+ this.chain_id = data.chain_id;
1668
+ this.chain_name = data.chain_name;
1669
+ this.quote_currency = data.quote_currency;
1670
+ this.updated_at = data.updated_at && data.updated_at !== null ? dateFns.parseISO(data.updated_at.toString()) : null;
1671
+ this.event_type = data.event_type;
1672
+ this.gas_quote_rate = data.gas_quote_rate;
1673
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new PriceItem(itemData)) : null;
1674
+ }
1675
+ }
1676
+ class PriceItem {
1677
+ constructor(data) {
1678
+ this.gas_price = data.gas_price;
1679
+ this.gas_spent = data.gas_spent;
1680
+ this.gas_quote = data.gas_quote;
1681
+ this.total_gas_quote = data.total_gas_quote;
1682
+ this.pretty_total_gas_quote = data.pretty_total_gas_quote;
1683
+ this.interval = data.interval;
1684
+ this.other_fees = data.other_fees && data.other_fees !== null ? new OtherFees(data.other_fees) : null;
1685
+ }
1686
+ }
1687
+ class OtherFees {
1688
+ constructor(data) {
1689
+ this.l1_gas_quote = data.l1_gas_quote;
1690
+ }
1691
+ }
1580
1692
  /**
1581
1693
  * Class A - Base
1582
1694
  *
1583
1695
  */
1584
1696
  class BaseService {
1585
- constructor(apiKey, debug = false, threadCount = 3) {
1697
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
1586
1698
  this.apiKey = apiKey;
1587
1699
  this.debug = debug;
1588
1700
  this.threadCount = threadCount;
1701
+ this.is_key_valid = is_key_valid;
1589
1702
  this.LIMIT = pLimit$1(this.threadCount);
1590
1703
  }
1591
1704
  /**
@@ -1604,6 +1717,14 @@ class BaseService {
1604
1717
  while (!success) {
1605
1718
  try {
1606
1719
  const urlParams = new URLSearchParams();
1720
+ if (!this.is_key_valid) {
1721
+ return {
1722
+ data: null,
1723
+ error: true,
1724
+ error_code: 401,
1725
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1726
+ };
1727
+ }
1607
1728
  let startTime;
1608
1729
  if (this.debug) {
1609
1730
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1669,6 +1790,14 @@ class BaseService {
1669
1790
  while (!success) {
1670
1791
  try {
1671
1792
  const urlParams = new URLSearchParams();
1793
+ if (!this.is_key_valid) {
1794
+ return {
1795
+ data: null,
1796
+ error: true,
1797
+ error_code: 401,
1798
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1799
+ };
1800
+ }
1672
1801
  let startTime;
1673
1802
  if (this.debug) {
1674
1803
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1736,6 +1865,9 @@ class BaseService {
1736
1865
  while (!success) {
1737
1866
  try {
1738
1867
  const urlParams = new URLSearchParams();
1868
+ if (!this.is_key_valid) {
1869
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
1870
+ }
1739
1871
  if (queryParamOpts?.pageSize !== undefined) {
1740
1872
  urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1741
1873
  }
@@ -1773,6 +1905,14 @@ class BaseService {
1773
1905
  while (!success) {
1774
1906
  try {
1775
1907
  const urlParams = new URLSearchParams();
1908
+ if (!this.is_key_valid) {
1909
+ return {
1910
+ data: null,
1911
+ error: true,
1912
+ error_code: 401,
1913
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1914
+ };
1915
+ }
1776
1916
  if (queryParamOpts?.pageSize !== undefined) {
1777
1917
  urlParams.append("page-size", queryParamOpts?.pageSize.toString());
1778
1918
  }
@@ -1850,6 +1990,14 @@ class BaseService {
1850
1990
  while (!success) {
1851
1991
  try {
1852
1992
  const urlParams = new URLSearchParams();
1993
+ if (!this.is_key_valid) {
1994
+ return {
1995
+ data: null,
1996
+ error: true,
1997
+ error_code: 401,
1998
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1999
+ };
2000
+ }
1853
2001
  if (queryParamOpts?.startingBlock !== undefined) {
1854
2002
  urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
1855
2003
  }
@@ -1936,6 +2084,9 @@ class BaseService {
1936
2084
  while (!success) {
1937
2085
  try {
1938
2086
  const urlParams = new URLSearchParams();
2087
+ if (!this.is_key_valid) {
2088
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
2089
+ }
1939
2090
  if (queryParamOpts?.startingBlock !== undefined) {
1940
2091
  urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
1941
2092
  }
@@ -1980,6 +2131,14 @@ class BaseService {
1980
2131
  while (!success) {
1981
2132
  try {
1982
2133
  const urlParams = new URLSearchParams();
2134
+ if (!this.is_key_valid) {
2135
+ return {
2136
+ data: null,
2137
+ error: true,
2138
+ error_code: 401,
2139
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
2140
+ };
2141
+ }
1983
2142
  if (queryParamOpts?.startingBlock !== undefined) {
1984
2143
  urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
1985
2144
  }
@@ -2061,6 +2220,9 @@ class BaseService {
2061
2220
  while (!success) {
2062
2221
  try {
2063
2222
  const urlParams = new URLSearchParams();
2223
+ if (!this.is_key_valid) {
2224
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
2225
+ }
2064
2226
  if (queryParamOpts?.startingBlock !== undefined) {
2065
2227
  urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
2066
2228
  }
@@ -2109,6 +2271,14 @@ class BaseService {
2109
2271
  while (!success) {
2110
2272
  try {
2111
2273
  const urlParams = new URLSearchParams();
2274
+ if (!this.is_key_valid) {
2275
+ return {
2276
+ data: null,
2277
+ error: true,
2278
+ error_code: 401,
2279
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
2280
+ };
2281
+ }
2112
2282
  if (queryParamOpts?.startingBlock !== undefined) {
2113
2283
  urlParams.append("starting-block", queryParamOpts?.startingBlock.toString());
2114
2284
  }
@@ -2187,6 +2357,14 @@ class BaseService {
2187
2357
  while (!success) {
2188
2358
  try {
2189
2359
  const urlParams = new URLSearchParams();
2360
+ if (!this.is_key_valid) {
2361
+ return {
2362
+ data: null,
2363
+ error: true,
2364
+ error_code: 401,
2365
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
2366
+ };
2367
+ }
2190
2368
  let startTime;
2191
2369
  if (this.debug) {
2192
2370
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2250,6 +2428,14 @@ class BaseService {
2250
2428
  while (!success) {
2251
2429
  try {
2252
2430
  const urlParams = new URLSearchParams();
2431
+ if (!this.is_key_valid) {
2432
+ return {
2433
+ data: null,
2434
+ error: true,
2435
+ error_code: 401,
2436
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
2437
+ };
2438
+ }
2253
2439
  let startTime;
2254
2440
  if (this.debug) {
2255
2441
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -2316,6 +2502,14 @@ class BaseService {
2316
2502
  while (!success) {
2317
2503
  try {
2318
2504
  const urlParams = new URLSearchParams();
2505
+ if (!this.is_key_valid) {
2506
+ return {
2507
+ data: null,
2508
+ error: true,
2509
+ error_code: 401,
2510
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
2511
+ };
2512
+ }
2319
2513
  if (queryParamOpts?.testnets !== undefined) {
2320
2514
  urlParams.append("testnets", queryParamOpts?.testnets.toString());
2321
2515
  }
@@ -2368,6 +2562,82 @@ class BaseService {
2368
2562
  }
2369
2563
  }
2370
2564
  }
2565
+ /**
2566
+ *
2567
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
2568
+ * @param {string} eventType - The desired event type to retrieve gas prices for. Supports `erc20` transfer events, `uniswapv3` swap events and `nativetokens` transfers.
2569
+ * @param {GetGasPricesQueryParamOpts} queryParamOpts
2570
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
2571
+ *
2572
+ */
2573
+ async getGasPrices(chainName, eventType, queryParamOpts) {
2574
+ let success = false;
2575
+ let data;
2576
+ let response;
2577
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
2578
+ while (!success) {
2579
+ try {
2580
+ const urlParams = new URLSearchParams();
2581
+ if (!this.is_key_valid) {
2582
+ return {
2583
+ data: null,
2584
+ error: true,
2585
+ error_code: 401,
2586
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
2587
+ };
2588
+ }
2589
+ if (queryParamOpts?.quoteCurrency !== undefined) {
2590
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
2591
+ }
2592
+ let startTime;
2593
+ if (this.debug) {
2594
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
2595
+ }
2596
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/event/${eventType}/gas_prices/?${urlParams}`, {
2597
+ headers: {
2598
+ "Authorization": `Bearer ${this.apiKey}`,
2599
+ "X-Requested-With": userAgent
2600
+ }
2601
+ }));
2602
+ debugOutput(response.url, response.status, startTime);
2603
+ if (response.status === 429) {
2604
+ try {
2605
+ data = await this.LIMIT(() => backoff.backOff(response.url));
2606
+ }
2607
+ catch (error) {
2608
+ success = true;
2609
+ return {
2610
+ data: null,
2611
+ error: true,
2612
+ error_code: response.status,
2613
+ error_message: error.message
2614
+ };
2615
+ }
2616
+ }
2617
+ else {
2618
+ data = await response.json();
2619
+ }
2620
+ const dataClass = new GasPricesResponse(data.data);
2621
+ checkAndModifyResponse(dataClass);
2622
+ success = true;
2623
+ return {
2624
+ data: dataClass,
2625
+ error: data.error,
2626
+ error_code: data ? data.error_code : response.status,
2627
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2628
+ };
2629
+ }
2630
+ catch (error) {
2631
+ success = true;
2632
+ return {
2633
+ data: null,
2634
+ error: true,
2635
+ error_code: data ? data.error_code : response.status,
2636
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
2637
+ };
2638
+ }
2639
+ }
2640
+ }
2371
2641
  }
2372
2642
 
2373
2643
  class ChainCollectionResponse {
@@ -2692,10 +2962,11 @@ class MarketFloorPriceItem {
2692
2962
  *
2693
2963
  */
2694
2964
  class NftService {
2695
- constructor(apiKey, debug = false, threadCount = 3) {
2965
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
2696
2966
  this.apiKey = apiKey;
2697
2967
  this.debug = debug;
2698
2968
  this.threadCount = threadCount;
2969
+ this.is_key_valid = is_key_valid;
2699
2970
  this.LIMIT = pLimit$1(this.threadCount);
2700
2971
  }
2701
2972
  /**
@@ -2715,6 +2986,9 @@ class NftService {
2715
2986
  while (!success) {
2716
2987
  try {
2717
2988
  const urlParams = new URLSearchParams();
2989
+ if (!this.is_key_valid) {
2990
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
2991
+ }
2718
2992
  if (queryParamOpts?.pageSize !== undefined) {
2719
2993
  urlParams.append("page-size", queryParamOpts?.pageSize.toString());
2720
2994
  }
@@ -2754,6 +3028,14 @@ class NftService {
2754
3028
  while (!success) {
2755
3029
  try {
2756
3030
  const urlParams = new URLSearchParams();
3031
+ if (!this.is_key_valid) {
3032
+ return {
3033
+ data: null,
3034
+ error: true,
3035
+ error_code: 401,
3036
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3037
+ };
3038
+ }
2757
3039
  if (queryParamOpts?.pageSize !== undefined) {
2758
3040
  urlParams.append("page-size", queryParamOpts?.pageSize.toString());
2759
3041
  }
@@ -2832,6 +3114,14 @@ class NftService {
2832
3114
  while (!success) {
2833
3115
  try {
2834
3116
  const urlParams = new URLSearchParams();
3117
+ if (!this.is_key_valid) {
3118
+ return {
3119
+ data: null,
3120
+ error: true,
3121
+ error_code: 401,
3122
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3123
+ };
3124
+ }
2835
3125
  if (queryParamOpts?.noSpam !== undefined) {
2836
3126
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
2837
3127
  }
@@ -2911,6 +3201,9 @@ class NftService {
2911
3201
  while (!success) {
2912
3202
  try {
2913
3203
  const urlParams = new URLSearchParams();
3204
+ if (!this.is_key_valid) {
3205
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
3206
+ }
2914
3207
  if (queryParamOpts?.noMetadata !== undefined) {
2915
3208
  urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
2916
3209
  }
@@ -2963,6 +3256,14 @@ class NftService {
2963
3256
  while (!success) {
2964
3257
  try {
2965
3258
  const urlParams = new URLSearchParams();
3259
+ if (!this.is_key_valid) {
3260
+ return {
3261
+ data: null,
3262
+ error: true,
3263
+ error_code: 401,
3264
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3265
+ };
3266
+ }
2966
3267
  if (queryParamOpts?.noMetadata !== undefined) {
2967
3268
  urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
2968
3269
  }
@@ -3050,6 +3351,14 @@ class NftService {
3050
3351
  while (!success) {
3051
3352
  try {
3052
3353
  const urlParams = new URLSearchParams();
3354
+ if (!this.is_key_valid) {
3355
+ return {
3356
+ data: null,
3357
+ error: true,
3358
+ error_code: 401,
3359
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3360
+ };
3361
+ }
3053
3362
  if (queryParamOpts?.noMetadata !== undefined) {
3054
3363
  urlParams.append("no-metadata", queryParamOpts?.noMetadata.toString());
3055
3364
  }
@@ -3124,6 +3433,14 @@ class NftService {
3124
3433
  while (!success) {
3125
3434
  try {
3126
3435
  const urlParams = new URLSearchParams();
3436
+ if (!this.is_key_valid) {
3437
+ return {
3438
+ data: null,
3439
+ error: true,
3440
+ error_code: 401,
3441
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3442
+ };
3443
+ }
3127
3444
  if (queryParamOpts?.noSpam !== undefined) {
3128
3445
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
3129
3446
  }
@@ -3192,6 +3509,14 @@ class NftService {
3192
3509
  while (!success) {
3193
3510
  try {
3194
3511
  const urlParams = new URLSearchParams();
3512
+ if (!this.is_key_valid) {
3513
+ return {
3514
+ data: null,
3515
+ error: true,
3516
+ error_code: 401,
3517
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3518
+ };
3519
+ }
3195
3520
  let startTime;
3196
3521
  if (this.debug) {
3197
3522
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3258,6 +3583,14 @@ class NftService {
3258
3583
  while (!success) {
3259
3584
  try {
3260
3585
  const urlParams = new URLSearchParams();
3586
+ if (!this.is_key_valid) {
3587
+ return {
3588
+ data: null,
3589
+ error: true,
3590
+ error_code: 401,
3591
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3592
+ };
3593
+ }
3261
3594
  let startTime;
3262
3595
  if (this.debug) {
3263
3596
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3323,6 +3656,14 @@ class NftService {
3323
3656
  while (!success) {
3324
3657
  try {
3325
3658
  const urlParams = new URLSearchParams();
3659
+ if (!this.is_key_valid) {
3660
+ return {
3661
+ data: null,
3662
+ error: true,
3663
+ error_code: 401,
3664
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3665
+ };
3666
+ }
3326
3667
  let startTime;
3327
3668
  if (this.debug) {
3328
3669
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3389,6 +3730,14 @@ class NftService {
3389
3730
  while (!success) {
3390
3731
  try {
3391
3732
  const urlParams = new URLSearchParams();
3733
+ if (!this.is_key_valid) {
3734
+ return {
3735
+ data: null,
3736
+ error: true,
3737
+ error_code: 401,
3738
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3739
+ };
3740
+ }
3392
3741
  let startTime;
3393
3742
  if (this.debug) {
3394
3743
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3456,6 +3805,14 @@ class NftService {
3456
3805
  while (!success) {
3457
3806
  try {
3458
3807
  const urlParams = new URLSearchParams();
3808
+ if (!this.is_key_valid) {
3809
+ return {
3810
+ data: null,
3811
+ error: true,
3812
+ error_code: 401,
3813
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3814
+ };
3815
+ }
3459
3816
  let startTime;
3460
3817
  if (this.debug) {
3461
3818
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -3524,6 +3881,14 @@ class NftService {
3524
3881
  while (!success) {
3525
3882
  try {
3526
3883
  const urlParams = new URLSearchParams();
3884
+ if (!this.is_key_valid) {
3885
+ return {
3886
+ data: null,
3887
+ error: true,
3888
+ error_code: 401,
3889
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3890
+ };
3891
+ }
3527
3892
  if (queryParamOpts?.days !== undefined) {
3528
3893
  urlParams.append("days", queryParamOpts?.days.toString());
3529
3894
  }
@@ -3598,6 +3963,14 @@ class NftService {
3598
3963
  while (!success) {
3599
3964
  try {
3600
3965
  const urlParams = new URLSearchParams();
3966
+ if (!this.is_key_valid) {
3967
+ return {
3968
+ data: null,
3969
+ error: true,
3970
+ error_code: 401,
3971
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
3972
+ };
3973
+ }
3601
3974
  if (queryParamOpts?.days !== undefined) {
3602
3975
  urlParams.append("days", queryParamOpts?.days.toString());
3603
3976
  }
@@ -3672,6 +4045,14 @@ class NftService {
3672
4045
  while (!success) {
3673
4046
  try {
3674
4047
  const urlParams = new URLSearchParams();
4048
+ if (!this.is_key_valid) {
4049
+ return {
4050
+ data: null,
4051
+ error: true,
4052
+ error_code: 401,
4053
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
4054
+ };
4055
+ }
3675
4056
  if (queryParamOpts?.days !== undefined) {
3676
4057
  urlParams.append("days", queryParamOpts?.days.toString());
3677
4058
  }
@@ -3762,10 +4143,11 @@ let ContractMetadata$1 = class ContractMetadata {
3762
4143
  }
3763
4144
  };
3764
4145
  class PricingService {
3765
- constructor(apiKey, debug = false, threadCount = 3) {
4146
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
3766
4147
  this.apiKey = apiKey;
3767
4148
  this.debug = debug;
3768
4149
  this.threadCount = threadCount;
4150
+ this.is_key_valid = is_key_valid;
3769
4151
  this.LIMIT = pLimit$1(this.threadCount);
3770
4152
  }
3771
4153
  /**
@@ -3789,6 +4171,14 @@ class PricingService {
3789
4171
  while (!success) {
3790
4172
  try {
3791
4173
  const urlParams = new URLSearchParams();
4174
+ if (!this.is_key_valid) {
4175
+ return {
4176
+ data: null,
4177
+ error: true,
4178
+ error_code: 401,
4179
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
4180
+ };
4181
+ }
3792
4182
  if (queryParamOpts?.from !== undefined) {
3793
4183
  urlParams.append("from", queryParamOpts?.from.toString());
3794
4184
  }
@@ -3886,9 +4276,9 @@ class Transaction {
3886
4276
  this.gas_quote_rate = data.gas_quote_rate;
3887
4277
  this.gas_metadata = data.gas_metadata && data.gas_metadata !== null ? new ContractMetadata(data.gas_metadata) : null;
3888
4278
  this.explorers = data.explorers && data.explorers !== null ? data.explorers.map((itemData) => new Explorer(itemData)) : null;
3889
- this.dex_details = data.dex_details && data.dex_details !== null ? new DexReport(data.dex_details) : null;
3890
- this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? new NftSalesReport(data.nft_sale_details) : null;
3891
- this.lending_details = data.lending_details && data.lending_details !== null ? new LendingReport(data.lending_details) : null;
4279
+ this.dex_details = data.dex_details && data.dex_details !== null ? data.dex_details.map((itemData) => new DexReport(itemData)) : null;
4280
+ this.nft_sale_details = data.nft_sale_details && data.nft_sale_details !== null ? data.nft_sale_details.map((itemData) => new NftSalesReport(itemData)) : null;
4281
+ this.lending_details = data.lending_details && data.lending_details !== null ? data.lending_details.map((itemData) => new LendingReport(itemData)) : null;
3892
4282
  this.log_events = data.log_events && data.log_events !== null ? data.log_events.map((itemData) => new LogEvent(itemData)) : null;
3893
4283
  this.safe_details = data.safe_details && data.safe_details !== null ? data.safe_details.map((itemData) => new SafeDetails(itemData)) : null;
3894
4284
  }
@@ -4460,10 +4850,11 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
4460
4850
  }
4461
4851
  }
4462
4852
  class TransactionService {
4463
- constructor(apiKey, debug = false, threadCount = 3) {
4853
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
4464
4854
  this.apiKey = apiKey;
4465
4855
  this.debug = debug;
4466
4856
  this.threadCount = threadCount;
4857
+ this.is_key_valid = is_key_valid;
4467
4858
  this.LIMIT = pLimit$1(this.threadCount);
4468
4859
  }
4469
4860
  /**
@@ -4489,6 +4880,14 @@ class TransactionService {
4489
4880
  while (!success) {
4490
4881
  try {
4491
4882
  const urlParams = new URLSearchParams();
4883
+ if (!this.is_key_valid) {
4884
+ return {
4885
+ data: null,
4886
+ error: true,
4887
+ error_code: 401,
4888
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
4889
+ };
4890
+ }
4492
4891
  if (queryParamOpts?.quoteCurrency !== undefined) {
4493
4892
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4494
4893
  }
@@ -4575,6 +4974,9 @@ class TransactionService {
4575
4974
  while (!success) {
4576
4975
  try {
4577
4976
  const urlParams = new URLSearchParams();
4977
+ if (!this.is_key_valid) {
4978
+ throw new Error(`An error occurred 401: ${ApiKeyValidator.INVALID_API_KEY_MESSAGE}`);
4979
+ }
4578
4980
  if (queryParamOpts?.quoteCurrency !== undefined) {
4579
4981
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4580
4982
  }
@@ -4619,6 +5021,14 @@ class TransactionService {
4619
5021
  while (!success) {
4620
5022
  try {
4621
5023
  const urlParams = new URLSearchParams();
5024
+ if (!this.is_key_valid) {
5025
+ return {
5026
+ data: null,
5027
+ error: true,
5028
+ error_code: 401,
5029
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5030
+ };
5031
+ }
4622
5032
  if (queryParamOpts?.quoteCurrency !== undefined) {
4623
5033
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4624
5034
  }
@@ -4700,6 +5110,14 @@ class TransactionService {
4700
5110
  while (!success) {
4701
5111
  try {
4702
5112
  const urlParams = new URLSearchParams();
5113
+ if (!this.is_key_valid) {
5114
+ return {
5115
+ data: null,
5116
+ error: true,
5117
+ error_code: 401,
5118
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5119
+ };
5120
+ }
4703
5121
  if (queryParamOpts?.quoteCurrency !== undefined) {
4704
5122
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4705
5123
  }
@@ -4774,6 +5192,14 @@ class TransactionService {
4774
5192
  while (!success) {
4775
5193
  try {
4776
5194
  const urlParams = new URLSearchParams();
5195
+ if (!this.is_key_valid) {
5196
+ return {
5197
+ data: null,
5198
+ error: true,
5199
+ error_code: 401,
5200
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5201
+ };
5202
+ }
4777
5203
  let startTime;
4778
5204
  if (this.debug) {
4779
5205
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -4843,6 +5269,14 @@ class TransactionService {
4843
5269
  while (!success) {
4844
5270
  try {
4845
5271
  const urlParams = new URLSearchParams();
5272
+ if (!this.is_key_valid) {
5273
+ return {
5274
+ data: null,
5275
+ error: true,
5276
+ error_code: 401,
5277
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5278
+ };
5279
+ }
4846
5280
  if (queryParamOpts?.quoteCurrency !== undefined) {
4847
5281
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
4848
5282
  }
@@ -5304,10 +5738,11 @@ class HealthData {
5304
5738
  *
5305
5739
  */
5306
5740
  class XykService {
5307
- constructor(apiKey, debug = false, threadCount = 3) {
5741
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
5308
5742
  this.apiKey = apiKey;
5309
5743
  this.debug = debug;
5310
5744
  this.threadCount = threadCount;
5745
+ this.is_key_valid = is_key_valid;
5311
5746
  this.LIMIT = pLimit$1(this.threadCount);
5312
5747
  }
5313
5748
  /**
@@ -5326,6 +5761,14 @@ class XykService {
5326
5761
  while (!success) {
5327
5762
  try {
5328
5763
  const urlParams = new URLSearchParams();
5764
+ if (!this.is_key_valid) {
5765
+ return {
5766
+ data: null,
5767
+ error: true,
5768
+ error_code: 401,
5769
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5770
+ };
5771
+ }
5329
5772
  let startTime;
5330
5773
  if (this.debug) {
5331
5774
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5391,6 +5834,14 @@ class XykService {
5391
5834
  while (!success) {
5392
5835
  try {
5393
5836
  const urlParams = new URLSearchParams();
5837
+ if (!this.is_key_valid) {
5838
+ return {
5839
+ data: null,
5840
+ error: true,
5841
+ error_code: 401,
5842
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5843
+ };
5844
+ }
5394
5845
  let startTime;
5395
5846
  if (this.debug) {
5396
5847
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5457,6 +5908,14 @@ class XykService {
5457
5908
  while (!success) {
5458
5909
  try {
5459
5910
  const urlParams = new URLSearchParams();
5911
+ if (!this.is_key_valid) {
5912
+ return {
5913
+ data: null,
5914
+ error: true,
5915
+ error_code: 401,
5916
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5917
+ };
5918
+ }
5460
5919
  let startTime;
5461
5920
  if (this.debug) {
5462
5921
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5525,6 +5984,14 @@ class XykService {
5525
5984
  while (!success) {
5526
5985
  try {
5527
5986
  const urlParams = new URLSearchParams();
5987
+ if (!this.is_key_valid) {
5988
+ return {
5989
+ data: null,
5990
+ error: true,
5991
+ error_code: 401,
5992
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
5993
+ };
5994
+ }
5528
5995
  if (queryParamOpts?.quoteCurrency !== undefined) {
5529
5996
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
5530
5997
  }
@@ -5597,6 +6064,14 @@ class XykService {
5597
6064
  while (!success) {
5598
6065
  try {
5599
6066
  const urlParams = new URLSearchParams();
6067
+ if (!this.is_key_valid) {
6068
+ return {
6069
+ data: null,
6070
+ error: true,
6071
+ error_code: 401,
6072
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6073
+ };
6074
+ }
5600
6075
  let startTime;
5601
6076
  if (this.debug) {
5602
6077
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5666,6 +6141,14 @@ class XykService {
5666
6141
  while (!success) {
5667
6142
  try {
5668
6143
  const urlParams = new URLSearchParams();
6144
+ if (!this.is_key_valid) {
6145
+ return {
6146
+ data: null,
6147
+ error: true,
6148
+ error_code: 401,
6149
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6150
+ };
6151
+ }
5669
6152
  if (queryParamOpts?.tokenAddress !== undefined) {
5670
6153
  urlParams.append("token-address", queryParamOpts?.tokenAddress.toString());
5671
6154
  }
@@ -5740,6 +6223,14 @@ class XykService {
5740
6223
  while (!success) {
5741
6224
  try {
5742
6225
  const urlParams = new URLSearchParams();
6226
+ if (!this.is_key_valid) {
6227
+ return {
6228
+ data: null,
6229
+ error: true,
6230
+ error_code: 401,
6231
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6232
+ };
6233
+ }
5743
6234
  let startTime;
5744
6235
  if (this.debug) {
5745
6236
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5803,6 +6294,14 @@ class XykService {
5803
6294
  while (!success) {
5804
6295
  try {
5805
6296
  const urlParams = new URLSearchParams();
6297
+ if (!this.is_key_valid) {
6298
+ return {
6299
+ data: null,
6300
+ error: true,
6301
+ error_code: 401,
6302
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6303
+ };
6304
+ }
5806
6305
  let startTime;
5807
6306
  if (this.debug) {
5808
6307
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5869,6 +6368,14 @@ class XykService {
5869
6368
  while (!success) {
5870
6369
  try {
5871
6370
  const urlParams = new URLSearchParams();
6371
+ if (!this.is_key_valid) {
6372
+ return {
6373
+ data: null,
6374
+ error: true,
6375
+ error_code: 401,
6376
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6377
+ };
6378
+ }
5872
6379
  let startTime;
5873
6380
  if (this.debug) {
5874
6381
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -5935,6 +6442,14 @@ class XykService {
5935
6442
  while (!success) {
5936
6443
  try {
5937
6444
  const urlParams = new URLSearchParams();
6445
+ if (!this.is_key_valid) {
6446
+ return {
6447
+ data: null,
6448
+ error: true,
6449
+ error_code: 401,
6450
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6451
+ };
6452
+ }
5938
6453
  let startTime;
5939
6454
  if (this.debug) {
5940
6455
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6001,6 +6516,14 @@ class XykService {
6001
6516
  while (!success) {
6002
6517
  try {
6003
6518
  const urlParams = new URLSearchParams();
6519
+ if (!this.is_key_valid) {
6520
+ return {
6521
+ data: null,
6522
+ error: true,
6523
+ error_code: 401,
6524
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6525
+ };
6526
+ }
6004
6527
  let startTime;
6005
6528
  if (this.debug) {
6006
6529
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6067,6 +6590,14 @@ class XykService {
6067
6590
  while (!success) {
6068
6591
  try {
6069
6592
  const urlParams = new URLSearchParams();
6593
+ if (!this.is_key_valid) {
6594
+ return {
6595
+ data: null,
6596
+ error: true,
6597
+ error_code: 401,
6598
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6599
+ };
6600
+ }
6070
6601
  let startTime;
6071
6602
  if (this.debug) {
6072
6603
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6132,6 +6663,14 @@ class XykService {
6132
6663
  while (!success) {
6133
6664
  try {
6134
6665
  const urlParams = new URLSearchParams();
6666
+ if (!this.is_key_valid) {
6667
+ return {
6668
+ data: null,
6669
+ error: true,
6670
+ error_code: 401,
6671
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6672
+ };
6673
+ }
6135
6674
  let startTime;
6136
6675
  if (this.debug) {
6137
6676
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6197,6 +6736,14 @@ class XykService {
6197
6736
  while (!success) {
6198
6737
  try {
6199
6738
  const urlParams = new URLSearchParams();
6739
+ if (!this.is_key_valid) {
6740
+ return {
6741
+ data: null,
6742
+ error: true,
6743
+ error_code: 401,
6744
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
6745
+ };
6746
+ }
6200
6747
  let startTime;
6201
6748
  if (this.debug) {
6202
6749
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -6248,20 +6795,22 @@ class XykService {
6248
6795
  }
6249
6796
  }
6250
6797
 
6251
- const userAgent = "com.covalenthq.sdk.typescript/0.6.7";
6798
+ const userAgent = "com.covalenthq.sdk.typescript/0.7.0";
6252
6799
  /**
6253
6800
  * CovalentClient Class
6254
6801
  */
6255
6802
  class CovalentClient {
6256
6803
  constructor(apiKey, settings) {
6257
6804
  const { debug = false, threadCount = 3 } = settings || {};
6258
- this.SecurityService = new SecurityService(apiKey, debug, threadCount);
6259
- this.BalanceService = new BalanceService(apiKey, debug, threadCount);
6260
- this.BaseService = new BaseService(apiKey, debug, threadCount);
6261
- this.NftService = new NftService(apiKey, debug, threadCount);
6262
- this.PricingService = new PricingService(apiKey, debug, threadCount);
6263
- this.TransactionService = new TransactionService(apiKey, debug, threadCount);
6264
- this.XykService = new XykService(apiKey, debug, threadCount);
6805
+ const validator = new ApiKeyValidator(apiKey);
6806
+ this._is_key_valid = validator.isValidApiKey();
6807
+ this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
6808
+ this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
6809
+ this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
6810
+ this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
6811
+ this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
6812
+ this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
6813
+ this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
6265
6814
  }
6266
6815
  }
6267
6816
  /**
@@ -6273,13 +6822,15 @@ class CovalentClient {
6273
6822
  class Client {
6274
6823
  constructor(apiKey, settings) {
6275
6824
  const { debug = false, threadCount = 3 } = settings || {};
6276
- this.SecurityService = new SecurityService(apiKey, debug, threadCount);
6277
- this.BalanceService = new BalanceService(apiKey, debug, threadCount);
6278
- this.BaseService = new BaseService(apiKey, debug, threadCount);
6279
- this.NftService = new NftService(apiKey, debug, threadCount);
6280
- this.PricingService = new PricingService(apiKey, debug, threadCount);
6281
- this.TransactionService = new TransactionService(apiKey, debug, threadCount);
6282
- this.XykService = new XykService(apiKey, debug, threadCount);
6825
+ const validator = new ApiKeyValidator(apiKey);
6826
+ this._is_key_valid = validator.isValidApiKey();
6827
+ this.SecurityService = new SecurityService(apiKey, debug, threadCount, this._is_key_valid);
6828
+ this.BalanceService = new BalanceService(apiKey, debug, threadCount, this._is_key_valid);
6829
+ this.BaseService = new BaseService(apiKey, debug, threadCount, this._is_key_valid);
6830
+ this.NftService = new NftService(apiKey, debug, threadCount, this._is_key_valid);
6831
+ this.PricingService = new PricingService(apiKey, debug, threadCount, this._is_key_valid);
6832
+ this.TransactionService = new TransactionService(apiKey, debug, threadCount, this._is_key_valid);
6833
+ this.XykService = new XykService(apiKey, debug, threadCount, this._is_key_valid);
6283
6834
  }
6284
6835
  }
6285
6836