@covalenthq/client-sdk 0.7.5 → 0.7.6

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 (66) hide show
  1. package/README.md +20 -0
  2. package/dist/cjs/index.js +455 -357
  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 +2 -1
  6. package/dist/cjs/services/CovalentClient.d.ts +4 -2
  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 +8 -4
  11. package/dist/cjs/services/XykService.d.ts +62 -8
  12. package/dist/cjs/util/ApiHelpers.d.ts +1 -1
  13. package/dist/cjs/util/types/XykServiceTypes.d.ts +46 -8
  14. package/dist/es/index.js +455 -357
  15. package/dist/es/index.js.map +1 -1
  16. package/dist/es/services/BalanceService.d.ts +2 -1
  17. package/dist/es/services/BaseService.d.ts +2 -1
  18. package/dist/es/services/CovalentClient.d.ts +4 -2
  19. package/dist/es/services/NftService.d.ts +2 -1
  20. package/dist/es/services/PricingService.d.ts +2 -1
  21. package/dist/es/services/SecurityService.d.ts +2 -1
  22. package/dist/es/services/TransactionService.d.ts +8 -4
  23. package/dist/es/services/XykService.d.ts +62 -8
  24. package/dist/es/util/ApiHelpers.d.ts +1 -1
  25. package/dist/es/util/types/XykServiceTypes.d.ts +46 -8
  26. package/dist/esm/index.js +455 -357
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/services/BalanceService.d.ts +2 -1
  29. package/dist/esm/services/BaseService.d.ts +2 -1
  30. package/dist/esm/services/CovalentClient.d.ts +4 -2
  31. package/dist/esm/services/NftService.d.ts +2 -1
  32. package/dist/esm/services/PricingService.d.ts +2 -1
  33. package/dist/esm/services/SecurityService.d.ts +2 -1
  34. package/dist/esm/services/TransactionService.d.ts +8 -4
  35. package/dist/esm/services/XykService.d.ts +62 -8
  36. package/dist/esm/util/ApiHelpers.d.ts +1 -1
  37. package/dist/esm/util/types/XykServiceTypes.d.ts +46 -8
  38. package/dist/services/BalanceService.d.ts +2 -1
  39. package/dist/services/BalanceService.js +40 -33
  40. package/dist/services/BalanceService.js.map +1 -1
  41. package/dist/services/BaseService.d.ts +2 -1
  42. package/dist/services/BaseService.js +66 -55
  43. package/dist/services/BaseService.js.map +1 -1
  44. package/dist/services/CovalentClient.d.ts +4 -2
  45. package/dist/services/CovalentClient.js +17 -17
  46. package/dist/services/CovalentClient.js.map +1 -1
  47. package/dist/services/NftService.d.ts +2 -1
  48. package/dist/services/NftService.js +82 -68
  49. package/dist/services/NftService.js.map +1 -1
  50. package/dist/services/PricingService.d.ts +2 -1
  51. package/dist/services/PricingService.js +8 -6
  52. package/dist/services/PricingService.js.map +1 -1
  53. package/dist/services/SecurityService.d.ts +2 -1
  54. package/dist/services/SecurityService.js +14 -11
  55. package/dist/services/SecurityService.js.map +1 -1
  56. package/dist/services/TransactionService.d.ts +8 -4
  57. package/dist/services/TransactionService.js +95 -79
  58. package/dist/services/TransactionService.js.map +1 -1
  59. package/dist/services/XykService.d.ts +62 -8
  60. package/dist/services/XykService.js +122 -78
  61. package/dist/services/XykService.js.map +1 -1
  62. package/dist/util/ApiHelpers.d.ts +1 -1
  63. package/dist/util/ApiHelpers.js +6 -5
  64. package/dist/util/ApiHelpers.js.map +1 -1
  65. package/dist/util/types/XykServiceTypes.d.ts +46 -8
  66. package/package.json +1 -1
@@ -218,11 +218,12 @@ class Param {
218
218
  }
219
219
  }
220
220
  class RecentTransactionsResponse {
221
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
221
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
222
222
  this._debug = _debug;
223
223
  this._apiKey = _apiKey;
224
224
  this._threadCount = _threadCount;
225
225
  this._urlParams = _urlParams;
226
+ this._enableRetry = _enableRetry;
226
227
  this.address = data.address;
227
228
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
228
229
  this.quote_currency = data.quote_currency;
@@ -253,16 +254,17 @@ class RecentTransactionsResponse {
253
254
  error_message: "Invalid URL: URL link cannot be null"
254
255
  };
255
256
  }
257
+ const url = `${this.links.prev}?${this._urlParams}`;
256
258
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
257
259
  headers: {
258
260
  "Authorization": `Bearer ${this._apiKey}`,
259
261
  "X-Requested-With": userAgent
260
262
  }
261
263
  }));
262
- debugOutput(response.url, response.status ?? 429, startTime);
263
- if (response.status === null || response.status === 429) {
264
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
265
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
264
266
  try {
265
- data = await LIMIT(() => backoff.backOff(response.url));
267
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url));
266
268
  }
267
269
  catch (error) {
268
270
  success = true;
@@ -277,7 +279,7 @@ class RecentTransactionsResponse {
277
279
  else {
278
280
  data = await response.json();
279
281
  }
280
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
282
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
281
283
  checkAndModifyResponse(dataClass);
282
284
  success = true;
283
285
  return {
@@ -292,8 +294,8 @@ class RecentTransactionsResponse {
292
294
  return {
293
295
  data: null,
294
296
  error: true,
295
- error_code: data ? data.error_code : response.status,
296
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
297
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
298
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
297
299
  };
298
300
  }
299
301
  }
@@ -319,16 +321,17 @@ class RecentTransactionsResponse {
319
321
  error_message: "Invalid URL: URL link cannot be null"
320
322
  };
321
323
  }
324
+ const url = `${this.links.next}?${this._urlParams}`;
322
325
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
323
326
  headers: {
324
327
  "Authorization": `Bearer ${this._apiKey}`,
325
328
  "X-Requested-With": userAgent
326
329
  }
327
330
  }));
328
- debugOutput(response.url, response.status ?? 429, startTime);
329
- if (response.status === null || response.status === 429) {
331
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
332
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
330
333
  try {
331
- data = await LIMIT(() => backoff.backOff(response.url));
334
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url));
332
335
  }
333
336
  catch (error) {
334
337
  success = true;
@@ -343,7 +346,7 @@ class RecentTransactionsResponse {
343
346
  else {
344
347
  data = await response.json();
345
348
  }
346
- const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
349
+ const dataClass = new RecentTransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
347
350
  checkAndModifyResponse(dataClass);
348
351
  success = true;
349
352
  return {
@@ -358,8 +361,8 @@ class RecentTransactionsResponse {
358
361
  return {
359
362
  data: null,
360
363
  error: true,
361
- error_code: data ? data.error_code : response.status,
362
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
364
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
365
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
363
366
  };
364
367
  }
365
368
  }
@@ -403,11 +406,12 @@ class TransactionSummary {
403
406
  }
404
407
  }
405
408
  class TransactionsResponse {
406
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
409
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
407
410
  this._debug = _debug;
408
411
  this._apiKey = _apiKey;
409
412
  this._threadCount = _threadCount;
410
413
  this._urlParams = _urlParams;
414
+ this._enableRetry = _enableRetry;
411
415
  this.address = data.address;
412
416
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
413
417
  this.quote_currency = data.quote_currency;
@@ -438,16 +442,17 @@ class TransactionsResponse {
438
442
  error_message: "Invalid URL: URL link cannot be null"
439
443
  };
440
444
  }
445
+ const url = `${this.links.prev}?${this._urlParams}`;
441
446
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
442
447
  headers: {
443
448
  "Authorization": `Bearer ${this._apiKey}`,
444
449
  "X-Requested-With": userAgent
445
450
  }
446
451
  }));
447
- debugOutput(response.url, response.status ?? 429, startTime);
448
- if (response.status === null || response.status === 429) {
452
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
453
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
449
454
  try {
450
- data = await LIMIT(() => backoff.backOff(response.url));
455
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url));
451
456
  }
452
457
  catch (error) {
453
458
  success = true;
@@ -462,7 +467,7 @@ class TransactionsResponse {
462
467
  else {
463
468
  data = await response.json();
464
469
  }
465
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
470
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
466
471
  checkAndModifyResponse(dataClass);
467
472
  success = true;
468
473
  return {
@@ -477,8 +482,8 @@ class TransactionsResponse {
477
482
  return {
478
483
  data: null,
479
484
  error: true,
480
- error_code: data ? data.error_code : response.status,
481
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
485
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
486
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
482
487
  };
483
488
  }
484
489
  }
@@ -504,16 +509,17 @@ class TransactionsResponse {
504
509
  error_message: "Invalid URL: URL link cannot be null"
505
510
  };
506
511
  }
512
+ const url = `${this.links.next}?${this._urlParams}`;
507
513
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
508
514
  headers: {
509
515
  "Authorization": `Bearer ${this._apiKey}`,
510
516
  "X-Requested-With": userAgent
511
517
  }
512
518
  }));
513
- debugOutput(response.url, response.status ?? 429, startTime);
514
- if (response.status === null || response.status === 429) {
519
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
520
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
515
521
  try {
516
- data = await LIMIT(() => backoff.backOff(response.url));
522
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url));
517
523
  }
518
524
  catch (error) {
519
525
  success = true;
@@ -528,7 +534,7 @@ class TransactionsResponse {
528
534
  else {
529
535
  data = await response.json();
530
536
  }
531
- const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
537
+ const dataClass = new TransactionsResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
532
538
  checkAndModifyResponse(dataClass);
533
539
  success = true;
534
540
  return {
@@ -543,19 +549,20 @@ class TransactionsResponse {
543
549
  return {
544
550
  data: null,
545
551
  error: true,
546
- error_code: data ? data.error_code : response.status,
547
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
552
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
553
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
548
554
  };
549
555
  }
550
556
  }
551
557
  }
552
558
  }
553
559
  class TransactionsTimeBucketResponse {
554
- constructor(data, _debug, _apiKey, _threadCount, _urlParams) {
560
+ constructor(data, _debug, _apiKey, _threadCount, _urlParams, _enableRetry) {
555
561
  this._debug = _debug;
556
562
  this._apiKey = _apiKey;
557
563
  this._threadCount = _threadCount;
558
564
  this._urlParams = _urlParams;
565
+ this._enableRetry = _enableRetry;
559
566
  this.address = data.address;
560
567
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
561
568
  this.quote_currency = data.quote_currency;
@@ -587,16 +594,17 @@ class TransactionsTimeBucketResponse {
587
594
  error_message: "Invalid URL: URL link cannot be null"
588
595
  };
589
596
  }
597
+ const url = `${this.links.prev}?${this._urlParams}`;
590
598
  response = await LIMIT(() => fetch(`${this.links.prev}?${this._urlParams}`, {
591
599
  headers: {
592
600
  "Authorization": `Bearer ${this._apiKey}`,
593
601
  "X-Requested-With": userAgent
594
602
  }
595
603
  }));
596
- debugOutput(response.url, response.status ?? 429, startTime);
597
- if (response.status === null || response.status === 429) {
604
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
605
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
598
606
  try {
599
- data = await LIMIT(() => backoff.backOff(response.url));
607
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url));
600
608
  }
601
609
  catch (error) {
602
610
  success = true;
@@ -611,7 +619,7 @@ class TransactionsTimeBucketResponse {
611
619
  else {
612
620
  data = await response.json();
613
621
  }
614
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
622
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
615
623
  checkAndModifyResponse(dataClass);
616
624
  success = true;
617
625
  return {
@@ -626,8 +634,8 @@ class TransactionsTimeBucketResponse {
626
634
  return {
627
635
  data: null,
628
636
  error: true,
629
- error_code: data ? data.error_code : response.status,
630
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
637
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
638
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
631
639
  };
632
640
  }
633
641
  }
@@ -653,16 +661,17 @@ class TransactionsTimeBucketResponse {
653
661
  error_message: "Invalid URL: URL link cannot be null"
654
662
  };
655
663
  }
664
+ const url = `${this.links.next}?${this._urlParams}`;
656
665
  response = await LIMIT(() => fetch(`${this.links.next}?${this._urlParams}`, {
657
666
  headers: {
658
667
  "Authorization": `Bearer ${this._apiKey}`,
659
668
  "X-Requested-With": userAgent
660
669
  }
661
670
  }));
662
- debugOutput(response.url, response.status ?? 429, startTime);
663
- if (response.status === null || response.status === 429) {
671
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
672
+ if ((this._enableRetry === true) && (!response || response.status === null || response.status === 429)) {
664
673
  try {
665
- data = await LIMIT(() => backoff.backOff(response.url));
674
+ data = await LIMIT(() => backoff.backOff(response ? response.url : url));
666
675
  }
667
676
  catch (error) {
668
677
  success = true;
@@ -677,7 +686,7 @@ class TransactionsTimeBucketResponse {
677
686
  else {
678
687
  data = await response.json();
679
688
  }
680
- const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams);
689
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this._debug, this._apiKey, this._threadCount, this._urlParams, this._enableRetry);
681
690
  checkAndModifyResponse(dataClass);
682
691
  success = true;
683
692
  return {
@@ -692,8 +701,8 @@ class TransactionsTimeBucketResponse {
692
701
  return {
693
702
  data: null,
694
703
  error: true,
695
- error_code: data ? data.error_code : response.status,
696
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
704
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
705
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
697
706
  };
698
707
  }
699
708
  }
@@ -703,7 +712,7 @@ class TransactionsTimeBucketResponse {
703
712
  * Transactions APIs
704
713
  *
705
714
  */
706
- async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
715
+ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount, enableRetry) {
707
716
  let hasNext = true;
708
717
  let response;
709
718
  let data;
@@ -721,14 +730,14 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
721
730
  "X-Requested-With": userAgent
722
731
  }
723
732
  }));
724
- debugOutput(response.url, response.status ?? 429, startTime);
725
- if (response.status === null || response.status === 429) {
733
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
734
+ if ((enableRetry === true) && (!response || response.status === null || response.status === 429)) {
726
735
  try {
727
- data = await LIMIT(() => backoff.backOff(response.url));
736
+ data = await LIMIT(() => backoff.backOff(response ? response.url : `${url}?${urlsParams}`));
728
737
  }
729
738
  catch (error) {
730
739
  hasNext = false;
731
- throw new Error(`An error occurred ${response.status}: ${error.message}`);
740
+ throw new Error(`An error occurred ${response ? response.status : 429}: ${error.message}`);
732
741
  }
733
742
  }
734
743
  else {
@@ -760,11 +769,12 @@ async function* paginateEndpoint(url, apiKey, urlsParams, debug, threadCount) {
760
769
  }
761
770
  }
762
771
  export class TransactionService {
763
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
772
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true) {
764
773
  this.apiKey = apiKey;
765
774
  this.debug = debug;
766
775
  this.threadCount = threadCount;
767
776
  this.is_key_valid = is_key_valid;
777
+ this.enableRetry = enableRetry;
768
778
  this.LIMIT = pLimit(this.threadCount);
769
779
  }
770
780
  /**
@@ -820,16 +830,17 @@ export class TransactionService {
820
830
  if (this.debug) {
821
831
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
822
832
  }
833
+ const url = `https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`;
823
834
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/transaction_v2/${txHash}/?${urlParams}`, {
824
835
  headers: {
825
836
  "Authorization": `Bearer ${this.apiKey}`,
826
837
  "X-Requested-With": userAgent
827
838
  }
828
839
  }));
829
- debugOutput(response.url, response.status ?? 429, startTime);
830
- if (response.status === null || response.status === 429) {
840
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
841
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
831
842
  try {
832
- data = await this.LIMIT(() => backoff.backOff(response.url));
843
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
833
844
  }
834
845
  catch (error) {
835
846
  success = true;
@@ -859,8 +870,8 @@ export class TransactionService {
859
870
  return {
860
871
  data: null,
861
872
  error: true,
862
- error_code: data ? data.error_code : response.status,
863
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
873
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
874
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
864
875
  };
865
876
  }
866
877
  }
@@ -899,7 +910,7 @@ export class TransactionService {
899
910
  if (queryParamOpts?.withSafe !== undefined) {
900
911
  urlParams.append("with-safe", queryParamOpts?.withSafe.toString());
901
912
  }
902
- for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount)) {
913
+ for await (tx of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/`, this.apiKey, urlParams, this.debug, this.threadCount, this.enableRetry)) {
903
914
  yield tx;
904
915
  }
905
916
  success = true;
@@ -955,16 +966,17 @@ export class TransactionService {
955
966
  if (this.debug) {
956
967
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
957
968
  }
969
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`;
958
970
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/?${urlParams}`, {
959
971
  headers: {
960
972
  "Authorization": `Bearer ${this.apiKey}`,
961
973
  "X-Requested-With": userAgent
962
974
  }
963
975
  }));
964
- debugOutput(response.url, response.status ?? 429, startTime);
965
- if (response.status === null || response.status === 429) {
976
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
977
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
966
978
  try {
967
- data = await this.LIMIT(() => backoff.backOff(response.url));
979
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
968
980
  }
969
981
  catch (error) {
970
982
  success = true;
@@ -979,7 +991,7 @@ export class TransactionService {
979
991
  else {
980
992
  data = await response.json();
981
993
  }
982
- const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
994
+ const dataClass = new RecentTransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
983
995
  checkAndModifyResponse(dataClass);
984
996
  success = true;
985
997
  return {
@@ -994,8 +1006,8 @@ export class TransactionService {
994
1006
  return {
995
1007
  data: null,
996
1008
  error: true,
997
- error_code: data ? data.error_code : response.status,
998
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1009
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1010
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
999
1011
  };
1000
1012
  }
1001
1013
  }
@@ -1041,16 +1053,17 @@ export class TransactionService {
1041
1053
  if (this.debug) {
1042
1054
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1043
1055
  }
1056
+ const url = `https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`;
1044
1057
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block/${blockHeight}/transactions_v3/?${urlParams}`, {
1045
1058
  headers: {
1046
1059
  "Authorization": `Bearer ${this.apiKey}`,
1047
1060
  "X-Requested-With": userAgent
1048
1061
  }
1049
1062
  }));
1050
- debugOutput(response.url, response.status ?? 429, startTime);
1051
- if (response.status === null || response.status === 429) {
1063
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1064
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1052
1065
  try {
1053
- data = await this.LIMIT(() => backoff.backOff(response.url));
1066
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1054
1067
  }
1055
1068
  catch (error) {
1056
1069
  success = true;
@@ -1080,8 +1093,8 @@ export class TransactionService {
1080
1093
  return {
1081
1094
  data: null,
1082
1095
  error: true,
1083
- error_code: data ? data.error_code : response.status,
1084
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1096
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1097
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1085
1098
  };
1086
1099
  }
1087
1100
  }
@@ -1114,16 +1127,17 @@ export class TransactionService {
1114
1127
  if (this.debug) {
1115
1128
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1116
1129
  }
1130
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`;
1117
1131
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_summary/?${urlParams}`, {
1118
1132
  headers: {
1119
1133
  "Authorization": `Bearer ${this.apiKey}`,
1120
1134
  "X-Requested-With": userAgent
1121
1135
  }
1122
1136
  }));
1123
- debugOutput(response.url, response.status ?? 429, startTime);
1124
- if (response.status === null || response.status === 429) {
1137
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1138
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1125
1139
  try {
1126
- data = await this.LIMIT(() => backoff.backOff(response.url));
1140
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1127
1141
  }
1128
1142
  catch (error) {
1129
1143
  success = true;
@@ -1153,8 +1167,8 @@ export class TransactionService {
1153
1167
  return {
1154
1168
  data: null,
1155
1169
  error: true,
1156
- error_code: data ? data.error_code : response.status,
1157
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1170
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1171
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1158
1172
  };
1159
1173
  }
1160
1174
  }
@@ -1203,16 +1217,17 @@ export class TransactionService {
1203
1217
  if (this.debug) {
1204
1218
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1205
1219
  }
1220
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`;
1206
1221
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/transactions_v3/page/${page}/?${urlParams}`, {
1207
1222
  headers: {
1208
1223
  "Authorization": `Bearer ${this.apiKey}`,
1209
1224
  "X-Requested-With": userAgent
1210
1225
  }
1211
1226
  }));
1212
- debugOutput(response.url, response.status ?? 429, startTime);
1213
- if (response.status === null || response.status === 429) {
1227
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1228
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1214
1229
  try {
1215
- data = await this.LIMIT(() => backoff.backOff(response.url));
1230
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1216
1231
  }
1217
1232
  catch (error) {
1218
1233
  success = true;
@@ -1227,7 +1242,7 @@ export class TransactionService {
1227
1242
  else {
1228
1243
  data = await response.json();
1229
1244
  }
1230
- const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
1245
+ const dataClass = new TransactionsResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
1231
1246
  checkAndModifyResponse(dataClass);
1232
1247
  success = true;
1233
1248
  return {
@@ -1242,8 +1257,8 @@ export class TransactionService {
1242
1257
  return {
1243
1258
  data: null,
1244
1259
  error: true,
1245
- error_code: data ? data.error_code : response.status,
1246
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1260
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1261
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1247
1262
  };
1248
1263
  }
1249
1264
  }
@@ -1288,16 +1303,17 @@ export class TransactionService {
1288
1303
  if (this.debug) {
1289
1304
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1290
1305
  }
1306
+ const url = `https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`;
1291
1307
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/bulk/transactions/${walletAddress}/${timeBucket}/?${urlParams}`, {
1292
1308
  headers: {
1293
1309
  "Authorization": `Bearer ${this.apiKey}`,
1294
1310
  "X-Requested-With": userAgent
1295
1311
  }
1296
1312
  }));
1297
- debugOutput(response.url, response.status ?? 429, startTime);
1298
- if (response.status === null || response.status === 429) {
1313
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1314
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1299
1315
  try {
1300
- data = await this.LIMIT(() => backoff.backOff(response.url));
1316
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url));
1301
1317
  }
1302
1318
  catch (error) {
1303
1319
  success = true;
@@ -1312,7 +1328,7 @@ export class TransactionService {
1312
1328
  else {
1313
1329
  data = await response.json();
1314
1330
  }
1315
- const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams);
1331
+ const dataClass = new TransactionsTimeBucketResponse(data.data, this.debug, this.apiKey, this.threadCount, urlParams, this.enableRetry);
1316
1332
  checkAndModifyResponse(dataClass);
1317
1333
  success = true;
1318
1334
  return {
@@ -1327,8 +1343,8 @@ export class TransactionService {
1327
1343
  return {
1328
1344
  data: null,
1329
1345
  error: true,
1330
- error_code: data ? data.error_code : response.status,
1331
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1346
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1347
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1332
1348
  };
1333
1349
  }
1334
1350
  }