@covalenthq/client-sdk 0.6.7 → 0.7.1

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 (74) hide show
  1. package/README.md +1 -0
  2. package/dist/cjs/index.js +744 -193
  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 +744 -193
  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 +744 -193
  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 +75 -19
  43. package/dist/services/BalanceService.js.map +1 -1
  44. package/dist/services/BaseService.d.ts +55 -2
  45. package/dist/services/BaseService.js +212 -26
  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 +152 -40
  52. package/dist/services/NftService.js.map +1 -1
  53. package/dist/services/PricingService.d.ts +2 -1
  54. package/dist/services/PricingService.js +14 -4
  55. package/dist/services/PricingService.js.map +1 -1
  56. package/dist/services/SecurityService.d.ts +2 -1
  57. package/dist/services/SecurityService.js +25 -7
  58. package/dist/services/SecurityService.js.map +1 -1
  59. package/dist/services/TransactionService.d.ts +5 -4
  60. package/dist/services/TransactionService.js +78 -33
  61. package/dist/services/TransactionService.js.map +1 -1
  62. package/dist/services/XykService.d.ts +2 -1
  63. package/dist/services/XykService.js +157 -43
  64. package/dist/services/XykService.js.map +1 -1
  65. package/dist/util/ApiHelpers.js +3 -3
  66. package/dist/util/ApiHelpers.js.map +1 -1
  67. package/dist/util/ApiKeyValidator.d.ts +8 -0
  68. package/dist/util/ApiKeyValidator.js +13 -0
  69. package/dist/util/ApiKeyValidator.js.map +1 -0
  70. package/dist/util/backoff.js +3 -3
  71. package/dist/util/backoff.js.map +1 -1
  72. package/dist/util/types/BaseServiceTypes.d.ts +36 -0
  73. package/dist/util/types/TransactionServiceTypes.d.ts +3 -3
  74. package/package.json +1 -1
@@ -3,6 +3,7 @@ import { checkAndModifyResponse, debugOutput } from "../util/ApiHelpers";
3
3
  import { parseISO } from "date-fns";
4
4
  import { ExponentialBackoff } from "../util/backoff";
5
5
  import pLimit from "p-limit";
6
+ import { ApiKeyValidator } from "../util/ApiKeyValidator";
6
7
  class PoolResponse {
7
8
  constructor(data) {
8
9
  this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
@@ -401,10 +402,11 @@ class HealthData {
401
402
  *
402
403
  */
403
404
  export class XykService {
404
- constructor(apiKey, debug = false, threadCount = 3) {
405
+ constructor(apiKey, debug = false, threadCount = 3, is_key_valid) {
405
406
  this.apiKey = apiKey;
406
407
  this.debug = debug;
407
408
  this.threadCount = threadCount;
409
+ this.is_key_valid = is_key_valid;
408
410
  this.LIMIT = pLimit(this.threadCount);
409
411
  }
410
412
  /**
@@ -423,6 +425,14 @@ export class XykService {
423
425
  while (!success) {
424
426
  try {
425
427
  const urlParams = new URLSearchParams();
428
+ if (!this.is_key_valid) {
429
+ return {
430
+ data: null,
431
+ error: true,
432
+ error_code: 401,
433
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
434
+ };
435
+ }
426
436
  let startTime;
427
437
  if (this.debug) {
428
438
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -433,8 +443,8 @@ export class XykService {
433
443
  "X-Requested-With": userAgent
434
444
  }
435
445
  }));
436
- debugOutput(response.url, response.status, startTime);
437
- if (response.status === 429) {
446
+ debugOutput(response.url, response.status ?? 429, startTime);
447
+ if (response.status === null || response.status === 429) {
438
448
  try {
439
449
  data = await this.LIMIT(() => backoff.backOff(response.url));
440
450
  }
@@ -443,7 +453,7 @@ export class XykService {
443
453
  return {
444
454
  data: null,
445
455
  error: true,
446
- error_code: response.status,
456
+ error_code: response.status ?? 429,
447
457
  error_message: error.message
448
458
  };
449
459
  }
@@ -488,6 +498,14 @@ export class XykService {
488
498
  while (!success) {
489
499
  try {
490
500
  const urlParams = new URLSearchParams();
501
+ if (!this.is_key_valid) {
502
+ return {
503
+ data: null,
504
+ error: true,
505
+ error_code: 401,
506
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
507
+ };
508
+ }
491
509
  let startTime;
492
510
  if (this.debug) {
493
511
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -498,8 +516,8 @@ export class XykService {
498
516
  "X-Requested-With": userAgent
499
517
  }
500
518
  }));
501
- debugOutput(response.url, response.status, startTime);
502
- if (response.status === 429) {
519
+ debugOutput(response.url, response.status ?? 429, startTime);
520
+ if (response.status === null || response.status === 429) {
503
521
  try {
504
522
  data = await this.LIMIT(() => backoff.backOff(response.url));
505
523
  }
@@ -508,7 +526,7 @@ export class XykService {
508
526
  return {
509
527
  data: null,
510
528
  error: true,
511
- error_code: response.status,
529
+ error_code: response.status ?? 429,
512
530
  error_message: error.message
513
531
  };
514
532
  }
@@ -554,6 +572,14 @@ export class XykService {
554
572
  while (!success) {
555
573
  try {
556
574
  const urlParams = new URLSearchParams();
575
+ if (!this.is_key_valid) {
576
+ return {
577
+ data: null,
578
+ error: true,
579
+ error_code: 401,
580
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
581
+ };
582
+ }
557
583
  let startTime;
558
584
  if (this.debug) {
559
585
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -564,8 +590,8 @@ export class XykService {
564
590
  "X-Requested-With": userAgent
565
591
  }
566
592
  }));
567
- debugOutput(response.url, response.status, startTime);
568
- if (response.status === 429) {
593
+ debugOutput(response.url, response.status ?? 429, startTime);
594
+ if (response.status === null || response.status === 429) {
569
595
  try {
570
596
  data = await this.LIMIT(() => backoff.backOff(response.url));
571
597
  }
@@ -574,7 +600,7 @@ export class XykService {
574
600
  return {
575
601
  data: null,
576
602
  error: true,
577
- error_code: response.status,
603
+ error_code: response.status ?? 429,
578
604
  error_message: error.message
579
605
  };
580
606
  }
@@ -622,6 +648,14 @@ export class XykService {
622
648
  while (!success) {
623
649
  try {
624
650
  const urlParams = new URLSearchParams();
651
+ if (!this.is_key_valid) {
652
+ return {
653
+ data: null,
654
+ error: true,
655
+ error_code: 401,
656
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
657
+ };
658
+ }
625
659
  if (queryParamOpts?.quoteCurrency !== undefined) {
626
660
  urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
627
661
  }
@@ -638,8 +672,8 @@ export class XykService {
638
672
  "X-Requested-With": userAgent
639
673
  }
640
674
  }));
641
- debugOutput(response.url, response.status, startTime);
642
- if (response.status === 429) {
675
+ debugOutput(response.url, response.status ?? 429, startTime);
676
+ if (response.status === null || response.status === 429) {
643
677
  try {
644
678
  data = await this.LIMIT(() => backoff.backOff(response.url));
645
679
  }
@@ -648,7 +682,7 @@ export class XykService {
648
682
  return {
649
683
  data: null,
650
684
  error: true,
651
- error_code: response.status,
685
+ error_code: response.status ?? 429,
652
686
  error_message: error.message
653
687
  };
654
688
  }
@@ -694,6 +728,14 @@ export class XykService {
694
728
  while (!success) {
695
729
  try {
696
730
  const urlParams = new URLSearchParams();
731
+ if (!this.is_key_valid) {
732
+ return {
733
+ data: null,
734
+ error: true,
735
+ error_code: 401,
736
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
737
+ };
738
+ }
697
739
  let startTime;
698
740
  if (this.debug) {
699
741
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -704,8 +746,8 @@ export class XykService {
704
746
  "X-Requested-With": userAgent
705
747
  }
706
748
  }));
707
- debugOutput(response.url, response.status, startTime);
708
- if (response.status === 429) {
749
+ debugOutput(response.url, response.status ?? 429, startTime);
750
+ if (response.status === null || response.status === 429) {
709
751
  try {
710
752
  data = await this.LIMIT(() => backoff.backOff(response.url));
711
753
  }
@@ -714,7 +756,7 @@ export class XykService {
714
756
  return {
715
757
  data: null,
716
758
  error: true,
717
- error_code: response.status,
759
+ error_code: response.status ?? 429,
718
760
  error_message: error.message
719
761
  };
720
762
  }
@@ -763,6 +805,14 @@ export class XykService {
763
805
  while (!success) {
764
806
  try {
765
807
  const urlParams = new URLSearchParams();
808
+ if (!this.is_key_valid) {
809
+ return {
810
+ data: null,
811
+ error: true,
812
+ error_code: 401,
813
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
814
+ };
815
+ }
766
816
  if (queryParamOpts?.tokenAddress !== undefined) {
767
817
  urlParams.append("token-address", queryParamOpts?.tokenAddress.toString());
768
818
  }
@@ -782,8 +832,8 @@ export class XykService {
782
832
  "X-Requested-With": userAgent
783
833
  }
784
834
  }));
785
- debugOutput(response.url, response.status, startTime);
786
- if (response.status === 429) {
835
+ debugOutput(response.url, response.status ?? 429, startTime);
836
+ if (response.status === null || response.status === 429) {
787
837
  try {
788
838
  data = await this.LIMIT(() => backoff.backOff(response.url));
789
839
  }
@@ -792,7 +842,7 @@ export class XykService {
792
842
  return {
793
843
  data: null,
794
844
  error: true,
795
- error_code: response.status,
845
+ error_code: response.status ?? 429,
796
846
  error_message: error.message
797
847
  };
798
848
  }
@@ -837,6 +887,14 @@ export class XykService {
837
887
  while (!success) {
838
888
  try {
839
889
  const urlParams = new URLSearchParams();
890
+ if (!this.is_key_valid) {
891
+ return {
892
+ data: null,
893
+ error: true,
894
+ error_code: 401,
895
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
896
+ };
897
+ }
840
898
  let startTime;
841
899
  if (this.debug) {
842
900
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -847,8 +905,8 @@ export class XykService {
847
905
  "X-Requested-With": userAgent
848
906
  }
849
907
  }));
850
- debugOutput(response.url, response.status, startTime);
851
- if (response.status === 429) {
908
+ debugOutput(response.url, response.status ?? 429, startTime);
909
+ if (response.status === null || response.status === 429) {
852
910
  try {
853
911
  data = await this.LIMIT(() => backoff.backOff(response.url));
854
912
  }
@@ -857,7 +915,7 @@ export class XykService {
857
915
  return {
858
916
  data: null,
859
917
  error: true,
860
- error_code: response.status,
918
+ error_code: response.status ?? 429,
861
919
  error_message: error.message
862
920
  };
863
921
  }
@@ -900,6 +958,14 @@ export class XykService {
900
958
  while (!success) {
901
959
  try {
902
960
  const urlParams = new URLSearchParams();
961
+ if (!this.is_key_valid) {
962
+ return {
963
+ data: null,
964
+ error: true,
965
+ error_code: 401,
966
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
967
+ };
968
+ }
903
969
  let startTime;
904
970
  if (this.debug) {
905
971
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -910,8 +976,8 @@ export class XykService {
910
976
  "X-Requested-With": userAgent
911
977
  }
912
978
  }));
913
- debugOutput(response.url, response.status, startTime);
914
- if (response.status === 429) {
979
+ debugOutput(response.url, response.status ?? 429, startTime);
980
+ if (response.status === null || response.status === 429) {
915
981
  try {
916
982
  data = await this.LIMIT(() => backoff.backOff(response.url));
917
983
  }
@@ -920,7 +986,7 @@ export class XykService {
920
986
  return {
921
987
  data: null,
922
988
  error: true,
923
- error_code: response.status,
989
+ error_code: response.status ?? 429,
924
990
  error_message: error.message
925
991
  };
926
992
  }
@@ -966,6 +1032,14 @@ export class XykService {
966
1032
  while (!success) {
967
1033
  try {
968
1034
  const urlParams = new URLSearchParams();
1035
+ if (!this.is_key_valid) {
1036
+ return {
1037
+ data: null,
1038
+ error: true,
1039
+ error_code: 401,
1040
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1041
+ };
1042
+ }
969
1043
  let startTime;
970
1044
  if (this.debug) {
971
1045
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -976,8 +1050,8 @@ export class XykService {
976
1050
  "X-Requested-With": userAgent
977
1051
  }
978
1052
  }));
979
- debugOutput(response.url, response.status, startTime);
980
- if (response.status === 429) {
1053
+ debugOutput(response.url, response.status ?? 429, startTime);
1054
+ if (response.status === null || response.status === 429) {
981
1055
  try {
982
1056
  data = await this.LIMIT(() => backoff.backOff(response.url));
983
1057
  }
@@ -986,7 +1060,7 @@ export class XykService {
986
1060
  return {
987
1061
  data: null,
988
1062
  error: true,
989
- error_code: response.status,
1063
+ error_code: response.status ?? 429,
990
1064
  error_message: error.message
991
1065
  };
992
1066
  }
@@ -1032,6 +1106,14 @@ export class XykService {
1032
1106
  while (!success) {
1033
1107
  try {
1034
1108
  const urlParams = new URLSearchParams();
1109
+ if (!this.is_key_valid) {
1110
+ return {
1111
+ data: null,
1112
+ error: true,
1113
+ error_code: 401,
1114
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1115
+ };
1116
+ }
1035
1117
  let startTime;
1036
1118
  if (this.debug) {
1037
1119
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1042,8 +1124,8 @@ export class XykService {
1042
1124
  "X-Requested-With": userAgent
1043
1125
  }
1044
1126
  }));
1045
- debugOutput(response.url, response.status, startTime);
1046
- if (response.status === 429) {
1127
+ debugOutput(response.url, response.status ?? 429, startTime);
1128
+ if (response.status === null || response.status === 429) {
1047
1129
  try {
1048
1130
  data = await this.LIMIT(() => backoff.backOff(response.url));
1049
1131
  }
@@ -1052,7 +1134,7 @@ export class XykService {
1052
1134
  return {
1053
1135
  data: null,
1054
1136
  error: true,
1055
- error_code: response.status,
1137
+ error_code: response.status ?? 429,
1056
1138
  error_message: error.message
1057
1139
  };
1058
1140
  }
@@ -1098,6 +1180,14 @@ export class XykService {
1098
1180
  while (!success) {
1099
1181
  try {
1100
1182
  const urlParams = new URLSearchParams();
1183
+ if (!this.is_key_valid) {
1184
+ return {
1185
+ data: null,
1186
+ error: true,
1187
+ error_code: 401,
1188
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1189
+ };
1190
+ }
1101
1191
  let startTime;
1102
1192
  if (this.debug) {
1103
1193
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1108,8 +1198,8 @@ export class XykService {
1108
1198
  "X-Requested-With": userAgent
1109
1199
  }
1110
1200
  }));
1111
- debugOutput(response.url, response.status, startTime);
1112
- if (response.status === 429) {
1201
+ debugOutput(response.url, response.status ?? 429, startTime);
1202
+ if (response.status === null || response.status === 429) {
1113
1203
  try {
1114
1204
  data = await this.LIMIT(() => backoff.backOff(response.url));
1115
1205
  }
@@ -1118,7 +1208,7 @@ export class XykService {
1118
1208
  return {
1119
1209
  data: null,
1120
1210
  error: true,
1121
- error_code: response.status,
1211
+ error_code: response.status ?? 429,
1122
1212
  error_message: error.message
1123
1213
  };
1124
1214
  }
@@ -1164,6 +1254,14 @@ export class XykService {
1164
1254
  while (!success) {
1165
1255
  try {
1166
1256
  const urlParams = new URLSearchParams();
1257
+ if (!this.is_key_valid) {
1258
+ return {
1259
+ data: null,
1260
+ error: true,
1261
+ error_code: 401,
1262
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1263
+ };
1264
+ }
1167
1265
  let startTime;
1168
1266
  if (this.debug) {
1169
1267
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1174,8 +1272,8 @@ export class XykService {
1174
1272
  "X-Requested-With": userAgent
1175
1273
  }
1176
1274
  }));
1177
- debugOutput(response.url, response.status, startTime);
1178
- if (response.status === 429) {
1275
+ debugOutput(response.url, response.status ?? 429, startTime);
1276
+ if (response.status === null || response.status === 429) {
1179
1277
  try {
1180
1278
  data = await this.LIMIT(() => backoff.backOff(response.url));
1181
1279
  }
@@ -1184,7 +1282,7 @@ export class XykService {
1184
1282
  return {
1185
1283
  data: null,
1186
1284
  error: true,
1187
- error_code: response.status,
1285
+ error_code: response.status ?? 429,
1188
1286
  error_message: error.message
1189
1287
  };
1190
1288
  }
@@ -1229,6 +1327,14 @@ export class XykService {
1229
1327
  while (!success) {
1230
1328
  try {
1231
1329
  const urlParams = new URLSearchParams();
1330
+ if (!this.is_key_valid) {
1331
+ return {
1332
+ data: null,
1333
+ error: true,
1334
+ error_code: 401,
1335
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1336
+ };
1337
+ }
1232
1338
  let startTime;
1233
1339
  if (this.debug) {
1234
1340
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1239,8 +1345,8 @@ export class XykService {
1239
1345
  "X-Requested-With": userAgent
1240
1346
  }
1241
1347
  }));
1242
- debugOutput(response.url, response.status, startTime);
1243
- if (response.status === 429) {
1348
+ debugOutput(response.url, response.status ?? 429, startTime);
1349
+ if (response.status === null || response.status === 429) {
1244
1350
  try {
1245
1351
  data = await this.LIMIT(() => backoff.backOff(response.url));
1246
1352
  }
@@ -1249,7 +1355,7 @@ export class XykService {
1249
1355
  return {
1250
1356
  data: null,
1251
1357
  error: true,
1252
- error_code: response.status,
1358
+ error_code: response.status ?? 429,
1253
1359
  error_message: error.message
1254
1360
  };
1255
1361
  }
@@ -1294,6 +1400,14 @@ export class XykService {
1294
1400
  while (!success) {
1295
1401
  try {
1296
1402
  const urlParams = new URLSearchParams();
1403
+ if (!this.is_key_valid) {
1404
+ return {
1405
+ data: null,
1406
+ error: true,
1407
+ error_code: 401,
1408
+ error_message: ApiKeyValidator.INVALID_API_KEY_MESSAGE
1409
+ };
1410
+ }
1297
1411
  let startTime;
1298
1412
  if (this.debug) {
1299
1413
  startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
@@ -1304,8 +1418,8 @@ export class XykService {
1304
1418
  "X-Requested-With": userAgent
1305
1419
  }
1306
1420
  }));
1307
- debugOutput(response.url, response.status, startTime);
1308
- if (response.status === 429) {
1421
+ debugOutput(response.url, response.status ?? 429, startTime);
1422
+ if (response.status === null || response.status === 429) {
1309
1423
  try {
1310
1424
  data = await this.LIMIT(() => backoff.backOff(response.url));
1311
1425
  }
@@ -1314,7 +1428,7 @@ export class XykService {
1314
1428
  return {
1315
1429
  data: null,
1316
1430
  error: true,
1317
- error_code: response.status,
1431
+ error_code: response.status ?? 429,
1318
1432
  error_message: error.message
1319
1433
  };
1320
1434
  }