@covalenthq/client-sdk 0.7.5 → 0.8.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 (76) hide show
  1. package/README.md +25 -0
  2. package/dist/cjs/index.js +1183 -451
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/services/BalanceService.d.ts +15 -13
  5. package/dist/cjs/services/BaseService.d.ts +13 -11
  6. package/dist/cjs/services/CovalentClient.d.ts +8 -4
  7. package/dist/cjs/services/NftService.d.ts +19 -17
  8. package/dist/cjs/services/PricingService.d.ts +5 -3
  9. package/dist/cjs/services/SecurityService.d.ts +6 -4
  10. package/dist/cjs/services/TransactionService.d.ts +83 -12
  11. package/dist/cjs/services/XykService.d.ts +287 -22
  12. package/dist/cjs/util/ApiHelpers.d.ts +2 -1
  13. package/dist/cjs/util/backoff.d.ts +2 -1
  14. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +11 -0
  15. package/dist/cjs/util/types/XykServiceTypes.d.ts +160 -8
  16. package/dist/es/index.js +1183 -451
  17. package/dist/es/index.js.map +1 -1
  18. package/dist/es/services/BalanceService.d.ts +15 -13
  19. package/dist/es/services/BaseService.d.ts +13 -11
  20. package/dist/es/services/CovalentClient.d.ts +8 -4
  21. package/dist/es/services/NftService.d.ts +19 -17
  22. package/dist/es/services/PricingService.d.ts +5 -3
  23. package/dist/es/services/SecurityService.d.ts +6 -4
  24. package/dist/es/services/TransactionService.d.ts +83 -12
  25. package/dist/es/services/XykService.d.ts +287 -22
  26. package/dist/es/util/ApiHelpers.d.ts +2 -1
  27. package/dist/es/util/backoff.d.ts +2 -1
  28. package/dist/es/util/types/TransactionServiceTypes.d.ts +11 -0
  29. package/dist/es/util/types/XykServiceTypes.d.ts +160 -8
  30. package/dist/esm/index.js +1183 -451
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/services/BalanceService.d.ts +15 -13
  33. package/dist/esm/services/BaseService.d.ts +13 -11
  34. package/dist/esm/services/CovalentClient.d.ts +8 -4
  35. package/dist/esm/services/NftService.d.ts +19 -17
  36. package/dist/esm/services/PricingService.d.ts +5 -3
  37. package/dist/esm/services/SecurityService.d.ts +6 -4
  38. package/dist/esm/services/TransactionService.d.ts +83 -12
  39. package/dist/esm/services/XykService.d.ts +287 -22
  40. package/dist/esm/util/ApiHelpers.d.ts +2 -1
  41. package/dist/esm/util/backoff.d.ts +2 -1
  42. package/dist/esm/util/types/TransactionServiceTypes.d.ts +11 -0
  43. package/dist/esm/util/types/XykServiceTypes.d.ts +160 -8
  44. package/dist/services/BalanceService.d.ts +15 -13
  45. package/dist/services/BalanceService.js +47 -39
  46. package/dist/services/BalanceService.js.map +1 -1
  47. package/dist/services/BaseService.d.ts +13 -11
  48. package/dist/services/BaseService.js +77 -65
  49. package/dist/services/BaseService.js.map +1 -1
  50. package/dist/services/CovalentClient.d.ts +8 -4
  51. package/dist/services/CovalentClient.js +19 -19
  52. package/dist/services/CovalentClient.js.map +1 -1
  53. package/dist/services/NftService.d.ts +19 -17
  54. package/dist/services/NftService.js +96 -81
  55. package/dist/services/NftService.js.map +1 -1
  56. package/dist/services/PricingService.d.ts +5 -3
  57. package/dist/services/PricingService.js +10 -7
  58. package/dist/services/PricingService.js.map +1 -1
  59. package/dist/services/SecurityService.d.ts +6 -4
  60. package/dist/services/SecurityService.js +17 -13
  61. package/dist/services/SecurityService.js.map +1 -1
  62. package/dist/services/TransactionService.d.ts +83 -12
  63. package/dist/services/TransactionService.js +434 -90
  64. package/dist/services/TransactionService.js.map +1 -1
  65. package/dist/services/XykService.d.ts +287 -22
  66. package/dist/services/XykService.js +438 -93
  67. package/dist/services/XykService.js.map +1 -1
  68. package/dist/util/ApiHelpers.d.ts +2 -1
  69. package/dist/util/ApiHelpers.js +7 -6
  70. package/dist/util/ApiHelpers.js.map +1 -1
  71. package/dist/util/backoff.d.ts +2 -1
  72. package/dist/util/backoff.js +3 -3
  73. package/dist/util/backoff.js.map +1 -1
  74. package/dist/util/types/TransactionServiceTypes.d.ts +11 -0
  75. package/dist/util/types/XykServiceTypes.d.ts +160 -8
  76. package/package.json +1 -1
@@ -326,11 +326,13 @@ class MarketFloorPriceItem {
326
326
  *
327
327
  */
328
328
  export class NftService {
329
- constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
329
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid, enableRetry = true, source) {
330
330
  this.apiKey = apiKey;
331
331
  this.debug = debug;
332
332
  this.threadCount = threadCount;
333
333
  this.is_key_valid = is_key_valid;
334
+ this.enableRetry = enableRetry;
335
+ this.source = source;
334
336
  this.LIMIT = pLimit(this.threadCount);
335
337
  }
336
338
  /**
@@ -362,7 +364,7 @@ export class NftService {
362
364
  if (queryParamOpts?.noSpam !== undefined) {
363
365
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
364
366
  }
365
- for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount)) {
367
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount, this.enableRetry, this.source)) {
366
368
  yield res;
367
369
  }
368
370
  success = true;
@@ -409,6 +411,7 @@ export class NftService {
409
411
  if (queryParamOpts?.noSpam !== undefined) {
410
412
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
411
413
  }
414
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`;
412
415
  let startTime;
413
416
  if (this.debug) {
414
417
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -416,13 +419,13 @@ export class NftService {
416
419
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/collections/?${urlParams}`, {
417
420
  headers: {
418
421
  "Authorization": `Bearer ${this.apiKey}`,
419
- "X-Requested-With": userAgent
422
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
420
423
  }
421
424
  }));
422
- debugOutput(response.url, response.status ?? 429, startTime);
423
- if (response.status === null || response.status === 429) {
425
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
426
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
424
427
  try {
425
- data = await this.LIMIT(() => backoff.backOff(response.url));
428
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
426
429
  }
427
430
  catch (error) {
428
431
  success = true;
@@ -452,8 +455,8 @@ export class NftService {
452
455
  return {
453
456
  data: null,
454
457
  error: true,
455
- error_code: data ? data.error_code : response.status,
456
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
458
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
459
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
457
460
  };
458
461
  }
459
462
  }
@@ -495,6 +498,7 @@ export class NftService {
495
498
  if (queryParamOpts?.withUncached !== undefined) {
496
499
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
497
500
  }
501
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`;
498
502
  let startTime;
499
503
  if (this.debug) {
500
504
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -502,13 +506,13 @@ export class NftService {
502
506
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
503
507
  headers: {
504
508
  "Authorization": `Bearer ${this.apiKey}`,
505
- "X-Requested-With": userAgent
509
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
506
510
  }
507
511
  }));
508
- debugOutput(response.url, response.status ?? 429, startTime);
509
- if (response.status === null || response.status === 429) {
512
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
513
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
510
514
  try {
511
- data = await this.LIMIT(() => backoff.backOff(response.url));
515
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
512
516
  }
513
517
  catch (error) {
514
518
  success = true;
@@ -538,8 +542,8 @@ export class NftService {
538
542
  return {
539
543
  data: null,
540
544
  error: true,
541
- error_code: data ? data.error_code : response.status,
542
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
545
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
546
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
543
547
  };
544
548
  }
545
549
  }
@@ -586,7 +590,7 @@ export class NftService {
586
590
  if (queryParamOpts?.withUncached !== undefined) {
587
591
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
588
592
  }
589
- for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount)) {
593
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount, this.enableRetry, this.source)) {
590
594
  yield res;
591
595
  }
592
596
  success = true;
@@ -646,6 +650,7 @@ export class NftService {
646
650
  if (queryParamOpts?.withUncached !== undefined) {
647
651
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
648
652
  }
653
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`;
649
654
  let startTime;
650
655
  if (this.debug) {
651
656
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -653,13 +658,13 @@ export class NftService {
653
658
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/?${urlParams}`, {
654
659
  headers: {
655
660
  "Authorization": `Bearer ${this.apiKey}`,
656
- "X-Requested-With": userAgent
661
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
657
662
  }
658
663
  }));
659
- debugOutput(response.url, response.status ?? 429, startTime);
660
- if (response.status === null || response.status === 429) {
664
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
665
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
661
666
  try {
662
- data = await this.LIMIT(() => backoff.backOff(response.url));
667
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
663
668
  }
664
669
  catch (error) {
665
670
  success = true;
@@ -689,8 +694,8 @@ export class NftService {
689
694
  return {
690
695
  data: null,
691
696
  error: true,
692
- error_code: data ? data.error_code : response.status,
693
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
697
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
698
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
694
699
  };
695
700
  }
696
701
  }
@@ -729,6 +734,7 @@ export class NftService {
729
734
  if (queryParamOpts?.withUncached !== undefined) {
730
735
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
731
736
  }
737
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`;
732
738
  let startTime;
733
739
  if (this.debug) {
734
740
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -736,13 +742,13 @@ export class NftService {
736
742
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
737
743
  headers: {
738
744
  "Authorization": `Bearer ${this.apiKey}`,
739
- "X-Requested-With": userAgent
745
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
740
746
  }
741
747
  }));
742
- debugOutput(response.url, response.status ?? 429, startTime);
743
- if (response.status === null || response.status === 429) {
748
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
749
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
744
750
  try {
745
- data = await this.LIMIT(() => backoff.backOff(response.url));
751
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
746
752
  }
747
753
  catch (error) {
748
754
  success = true;
@@ -772,8 +778,8 @@ export class NftService {
772
778
  return {
773
779
  data: null,
774
780
  error: true,
775
- error_code: data ? data.error_code : response.status,
776
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
781
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
782
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
777
783
  };
778
784
  }
779
785
  }
@@ -808,6 +814,7 @@ export class NftService {
808
814
  if (queryParamOpts?.noSpam !== undefined) {
809
815
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
810
816
  }
817
+ const url = `https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`;
811
818
  let startTime;
812
819
  if (this.debug) {
813
820
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -815,13 +822,13 @@ export class NftService {
815
822
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
816
823
  headers: {
817
824
  "Authorization": `Bearer ${this.apiKey}`,
818
- "X-Requested-With": userAgent
825
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
819
826
  }
820
827
  }));
821
- debugOutput(response.url, response.status ?? 429, startTime);
822
- if (response.status === null || response.status === 429) {
828
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
829
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
823
830
  try {
824
- data = await this.LIMIT(() => backoff.backOff(response.url));
831
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
825
832
  }
826
833
  catch (error) {
827
834
  success = true;
@@ -851,8 +858,8 @@ export class NftService {
851
858
  return {
852
859
  data: null,
853
860
  error: true,
854
- error_code: data ? data.error_code : response.status,
855
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
861
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
862
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
856
863
  };
857
864
  }
858
865
  }
@@ -881,6 +888,7 @@ export class NftService {
881
888
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
882
889
  };
883
890
  }
891
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`;
884
892
  let startTime;
885
893
  if (this.debug) {
886
894
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -888,13 +896,13 @@ export class NftService {
888
896
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
889
897
  headers: {
890
898
  "Authorization": `Bearer ${this.apiKey}`,
891
- "X-Requested-With": userAgent
899
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
892
900
  }
893
901
  }));
894
- debugOutput(response.url, response.status ?? 429, startTime);
895
- if (response.status === null || response.status === 429) {
902
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
903
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
896
904
  try {
897
- data = await this.LIMIT(() => backoff.backOff(response.url));
905
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
898
906
  }
899
907
  catch (error) {
900
908
  success = true;
@@ -924,8 +932,8 @@ export class NftService {
924
932
  return {
925
933
  data: null,
926
934
  error: true,
927
- error_code: data ? data.error_code : response.status,
928
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
935
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
936
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
929
937
  };
930
938
  }
931
939
  }
@@ -955,6 +963,7 @@ export class NftService {
955
963
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
956
964
  };
957
965
  }
966
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`;
958
967
  let startTime;
959
968
  if (this.debug) {
960
969
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -962,13 +971,13 @@ export class NftService {
962
971
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
963
972
  headers: {
964
973
  "Authorization": `Bearer ${this.apiKey}`,
965
- "X-Requested-With": userAgent
974
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
966
975
  }
967
976
  }));
968
- debugOutput(response.url, response.status ?? 429, startTime);
969
- if (response.status === null || response.status === 429) {
977
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
978
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
970
979
  try {
971
- data = await this.LIMIT(() => backoff.backOff(response.url));
980
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
972
981
  }
973
982
  catch (error) {
974
983
  success = true;
@@ -998,8 +1007,8 @@ export class NftService {
998
1007
  return {
999
1008
  data: null,
1000
1009
  error: true,
1001
- error_code: data ? data.error_code : response.status,
1002
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1010
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1011
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1003
1012
  };
1004
1013
  }
1005
1014
  }
@@ -1028,6 +1037,7 @@ export class NftService {
1028
1037
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1029
1038
  };
1030
1039
  }
1040
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`;
1031
1041
  let startTime;
1032
1042
  if (this.debug) {
1033
1043
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1035,13 +1045,13 @@ export class NftService {
1035
1045
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
1036
1046
  headers: {
1037
1047
  "Authorization": `Bearer ${this.apiKey}`,
1038
- "X-Requested-With": userAgent
1048
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1039
1049
  }
1040
1050
  }));
1041
- debugOutput(response.url, response.status ?? 429, startTime);
1042
- if (response.status === null || response.status === 429) {
1051
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1052
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1043
1053
  try {
1044
- data = await this.LIMIT(() => backoff.backOff(response.url));
1054
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1045
1055
  }
1046
1056
  catch (error) {
1047
1057
  success = true;
@@ -1071,8 +1081,8 @@ export class NftService {
1071
1081
  return {
1072
1082
  data: null,
1073
1083
  error: true,
1074
- error_code: data ? data.error_code : response.status,
1075
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1084
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1085
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1076
1086
  };
1077
1087
  }
1078
1088
  }
@@ -1102,6 +1112,7 @@ export class NftService {
1102
1112
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1103
1113
  };
1104
1114
  }
1115
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`;
1105
1116
  let startTime;
1106
1117
  if (this.debug) {
1107
1118
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1109,13 +1120,13 @@ export class NftService {
1109
1120
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
1110
1121
  headers: {
1111
1122
  "Authorization": `Bearer ${this.apiKey}`,
1112
- "X-Requested-With": userAgent
1123
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1113
1124
  }
1114
1125
  }));
1115
- debugOutput(response.url, response.status ?? 429, startTime);
1116
- if (response.status === null || response.status === 429) {
1126
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1127
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1117
1128
  try {
1118
- data = await this.LIMIT(() => backoff.backOff(response.url));
1129
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1119
1130
  }
1120
1131
  catch (error) {
1121
1132
  success = true;
@@ -1145,8 +1156,8 @@ export class NftService {
1145
1156
  return {
1146
1157
  data: null,
1147
1158
  error: true,
1148
- error_code: data ? data.error_code : response.status,
1149
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1159
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1160
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1150
1161
  };
1151
1162
  }
1152
1163
  }
@@ -1177,6 +1188,7 @@ export class NftService {
1177
1188
  error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1178
1189
  };
1179
1190
  }
1191
+ const url = `https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`;
1180
1192
  let startTime;
1181
1193
  if (this.debug) {
1182
1194
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1184,13 +1196,13 @@ export class NftService {
1184
1196
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
1185
1197
  headers: {
1186
1198
  "Authorization": `Bearer ${this.apiKey}`,
1187
- "X-Requested-With": userAgent
1199
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1188
1200
  }
1189
1201
  }));
1190
- debugOutput(response.url, response.status ?? 429, startTime);
1191
- if (response.status === null || response.status === 429) {
1202
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1203
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1192
1204
  try {
1193
- data = await this.LIMIT(() => backoff.backOff(response.url));
1205
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1194
1206
  }
1195
1207
  catch (error) {
1196
1208
  success = true;
@@ -1220,8 +1232,8 @@ export class NftService {
1220
1232
  return {
1221
1233
  data: null,
1222
1234
  error: true,
1223
- error_code: data ? data.error_code : response.status,
1224
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1235
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1236
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1225
1237
  };
1226
1238
  }
1227
1239
  }
@@ -1259,6 +1271,7 @@ export class NftService {
1259
1271
  if (queryParamOpts?.quoteCurrency !== undefined) {
1260
1272
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1261
1273
  }
1274
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`;
1262
1275
  let startTime;
1263
1276
  if (this.debug) {
1264
1277
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1266,13 +1279,13 @@ export class NftService {
1266
1279
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`, {
1267
1280
  headers: {
1268
1281
  "Authorization": `Bearer ${this.apiKey}`,
1269
- "X-Requested-With": userAgent
1282
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1270
1283
  }
1271
1284
  }));
1272
- debugOutput(response.url, response.status ?? 429, startTime);
1273
- if (response.status === null || response.status === 429) {
1285
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1286
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1274
1287
  try {
1275
- data = await this.LIMIT(() => backoff.backOff(response.url));
1288
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1276
1289
  }
1277
1290
  catch (error) {
1278
1291
  success = true;
@@ -1302,8 +1315,8 @@ export class NftService {
1302
1315
  return {
1303
1316
  data: null,
1304
1317
  error: true,
1305
- error_code: data ? data.error_code : response.status,
1306
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1318
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1319
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1307
1320
  };
1308
1321
  }
1309
1322
  }
@@ -1341,6 +1354,7 @@ export class NftService {
1341
1354
  if (queryParamOpts?.quoteCurrency !== undefined) {
1342
1355
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1343
1356
  }
1357
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`;
1344
1358
  let startTime;
1345
1359
  if (this.debug) {
1346
1360
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1348,13 +1362,13 @@ export class NftService {
1348
1362
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`, {
1349
1363
  headers: {
1350
1364
  "Authorization": `Bearer ${this.apiKey}`,
1351
- "X-Requested-With": userAgent
1365
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1352
1366
  }
1353
1367
  }));
1354
- debugOutput(response.url, response.status ?? 429, startTime);
1355
- if (response.status === null || response.status === 429) {
1368
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1369
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1356
1370
  try {
1357
- data = await this.LIMIT(() => backoff.backOff(response.url));
1371
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1358
1372
  }
1359
1373
  catch (error) {
1360
1374
  success = true;
@@ -1384,8 +1398,8 @@ export class NftService {
1384
1398
  return {
1385
1399
  data: null,
1386
1400
  error: true,
1387
- error_code: data ? data.error_code : response.status,
1388
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1401
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1402
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1389
1403
  };
1390
1404
  }
1391
1405
  }
@@ -1423,6 +1437,7 @@ export class NftService {
1423
1437
  if (queryParamOpts?.quoteCurrency !== undefined) {
1424
1438
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1425
1439
  }
1440
+ const url = `https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`;
1426
1441
  let startTime;
1427
1442
  if (this.debug) {
1428
1443
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1430,13 +1445,13 @@ export class NftService {
1430
1445
  response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`, {
1431
1446
  headers: {
1432
1447
  "Authorization": `Bearer ${this.apiKey}`,
1433
- "X-Requested-With": userAgent
1448
+ "X-Requested-With": this.source ? this.source + " " + "(" + userAgent + ")" : userAgent
1434
1449
  }
1435
1450
  }));
1436
- debugOutput(response.url, response.status ?? 429, startTime);
1437
- if (response.status === null || response.status === 429) {
1451
+ debugOutput(response ? response.url : url, response ? response.status : 429, startTime);
1452
+ if ((this.enableRetry === true) && (!response || response.status === null || response.status === 429)) {
1438
1453
  try {
1439
- data = await this.LIMIT(() => backoff.backOff(response.url));
1454
+ data = await this.LIMIT(() => backoff.backOff(response ? response.url : url, this.source));
1440
1455
  }
1441
1456
  catch (error) {
1442
1457
  success = true;
@@ -1466,8 +1481,8 @@ export class NftService {
1466
1481
  return {
1467
1482
  data: null,
1468
1483
  error: true,
1469
- error_code: data ? data.error_code : response.status,
1470
- error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1484
+ error_code: error.cause ? error.cause.code : data ? data.error_code : response ? response.status : "Unknown Error Code",
1485
+ error_message: error.cause ? error.cause.message : data ? data.error_message : response && response.status === 500 ? "Internal server error" : !response ? "Unknown Error" : "401 Authorization Required"
1471
1486
  };
1472
1487
  }
1473
1488
  }