@covalenthq/client-sdk 0.2.8 → 0.4.2

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 (117) hide show
  1. package/README.md +64 -14
  2. package/dist/cjs/index.d.ts +9 -0
  3. package/dist/cjs/index.js +4619 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/services/BalanceService.d.ts +443 -0
  6. package/dist/cjs/services/BaseService.d.ts +357 -0
  7. package/dist/cjs/services/CovalentClient.d.ts +65 -0
  8. package/dist/cjs/services/NftService.d.ts +484 -0
  9. package/dist/cjs/services/PricingService.d.ts +88 -0
  10. package/dist/cjs/services/SecurityService.d.ts +96 -0
  11. package/dist/cjs/services/TransactionService.d.ts +440 -0
  12. package/dist/cjs/services/XykService.d.ts +682 -0
  13. package/dist/cjs/util/ApiHelpers.d.ts +5 -0
  14. package/dist/cjs/util/backoff.d.ts +11 -0
  15. package/dist/cjs/util/types/BalanceServiceTypes.d.ts +284 -0
  16. package/dist/cjs/util/types/BaseServiceTypes.d.ts +180 -0
  17. package/dist/cjs/util/types/GenericTypes.d.ts +96 -0
  18. package/dist/cjs/util/types/NftServiceTypes.d.ts +221 -0
  19. package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
  20. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +71 -0
  21. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +312 -0
  22. package/dist/cjs/util/types/XykServiceTypes.d.ts +479 -0
  23. package/dist/es/index.d.ts +9 -0
  24. package/dist/es/index.js +4616 -0
  25. package/dist/es/index.js.map +1 -0
  26. package/dist/es/services/BalanceService.d.ts +443 -0
  27. package/dist/es/services/BaseService.d.ts +357 -0
  28. package/dist/es/services/CovalentClient.d.ts +65 -0
  29. package/dist/es/services/NftService.d.ts +484 -0
  30. package/dist/es/services/PricingService.d.ts +88 -0
  31. package/dist/es/services/SecurityService.d.ts +96 -0
  32. package/dist/es/services/TransactionService.d.ts +440 -0
  33. package/dist/es/services/XykService.d.ts +682 -0
  34. package/dist/es/util/ApiHelpers.d.ts +5 -0
  35. package/dist/es/util/backoff.d.ts +11 -0
  36. package/dist/es/util/types/BalanceServiceTypes.d.ts +284 -0
  37. package/dist/es/util/types/BaseServiceTypes.d.ts +180 -0
  38. package/dist/es/util/types/GenericTypes.d.ts +96 -0
  39. package/dist/es/util/types/NftServiceTypes.d.ts +221 -0
  40. package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
  41. package/dist/es/util/types/SecurityServiceTypes.d.ts +71 -0
  42. package/dist/es/util/types/TransactionServiceTypes.d.ts +312 -0
  43. package/dist/es/util/types/XykServiceTypes.d.ts +479 -0
  44. package/dist/esm/index.d.ts +9 -0
  45. package/dist/esm/index.js +4616 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/services/BalanceService.d.ts +443 -0
  48. package/dist/esm/services/BaseService.d.ts +357 -0
  49. package/dist/esm/services/CovalentClient.d.ts +65 -0
  50. package/dist/esm/services/NftService.d.ts +484 -0
  51. package/dist/esm/services/PricingService.d.ts +88 -0
  52. package/dist/esm/services/SecurityService.d.ts +96 -0
  53. package/dist/esm/services/TransactionService.d.ts +440 -0
  54. package/dist/esm/services/XykService.d.ts +682 -0
  55. package/dist/esm/util/ApiHelpers.d.ts +5 -0
  56. package/dist/esm/util/backoff.d.ts +11 -0
  57. package/dist/esm/util/types/BalanceServiceTypes.d.ts +284 -0
  58. package/dist/esm/util/types/BaseServiceTypes.d.ts +180 -0
  59. package/dist/esm/util/types/GenericTypes.d.ts +96 -0
  60. package/dist/esm/util/types/NftServiceTypes.d.ts +221 -0
  61. package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
  62. package/dist/esm/util/types/SecurityServiceTypes.d.ts +71 -0
  63. package/dist/esm/util/types/TransactionServiceTypes.d.ts +312 -0
  64. package/dist/esm/util/types/XykServiceTypes.d.ts +479 -0
  65. package/dist/index.d.ts +3 -3
  66. package/dist/index.js +9 -27
  67. package/dist/index.js.map +1 -1
  68. package/dist/services/BalanceService.d.ts +49 -11
  69. package/dist/services/BalanceService.js +110 -81
  70. package/dist/services/BalanceService.js.map +1 -1
  71. package/dist/services/BaseService.d.ts +46 -10
  72. package/dist/services/BaseService.js +193 -145
  73. package/dist/services/BaseService.js.map +1 -1
  74. package/dist/services/CovalentClient.d.ts +65 -0
  75. package/dist/services/CovalentClient.js +44 -0
  76. package/dist/services/CovalentClient.js.map +1 -0
  77. package/dist/services/NftService.d.ts +52 -22
  78. package/dist/services/NftService.js +236 -235
  79. package/dist/services/NftService.js.map +1 -1
  80. package/dist/services/PricingService.d.ts +8 -3
  81. package/dist/services/PricingService.js +43 -37
  82. package/dist/services/PricingService.js.map +1 -1
  83. package/dist/services/SecurityService.d.ts +9 -3
  84. package/dist/services/SecurityService.js +38 -31
  85. package/dist/services/SecurityService.js.map +1 -1
  86. package/dist/services/TransactionService.d.ts +41 -9
  87. package/dist/services/TransactionService.js +133 -100
  88. package/dist/services/TransactionService.js.map +1 -1
  89. package/dist/services/XykService.d.ts +81 -19
  90. package/dist/services/XykService.js +451 -278
  91. package/dist/services/XykService.js.map +1 -1
  92. package/dist/util/ApiHelpers.d.ts +2 -1
  93. package/dist/util/ApiHelpers.js +57 -36
  94. package/dist/util/ApiHelpers.js.map +1 -1
  95. package/dist/util/backoff.d.ts +5 -3
  96. package/dist/util/backoff.js +35 -13
  97. package/dist/util/backoff.js.map +1 -1
  98. package/dist/util/types/BalanceServiceTypes.d.ts +25 -0
  99. package/dist/util/types/BalanceServiceTypes.js +1 -2
  100. package/dist/util/types/BaseServiceTypes.d.ts +8 -0
  101. package/dist/util/types/BaseServiceTypes.js +1 -2
  102. package/dist/util/types/GenericTypes.d.ts +21 -0
  103. package/dist/util/types/GenericTypes.js +1 -2
  104. package/dist/util/types/NftServiceTypes.d.ts +10 -2
  105. package/dist/util/types/NftServiceTypes.js +1 -2
  106. package/dist/util/types/PricingServiceTypes.d.ts +1 -14
  107. package/dist/util/types/PricingServiceTypes.js +1 -2
  108. package/dist/util/types/SecurityServiceTypes.d.ts +1 -0
  109. package/dist/util/types/SecurityServiceTypes.js +1 -2
  110. package/dist/util/types/TransactionServiceTypes.d.ts +15 -17
  111. package/dist/util/types/TransactionServiceTypes.js +1 -2
  112. package/dist/util/types/XykServiceTypes.d.ts +20 -6
  113. package/dist/util/types/XykServiceTypes.js +1 -2
  114. package/package.json +19 -4
  115. package/dist/services/Client.d.ts +0 -29
  116. package/dist/services/Client.js +0 -30
  117. package/dist/services/Client.js.map +0 -1
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseService = void 0;
4
- const Client_1 = require("./Client");
5
- const ApiHelpers_1 = require("../util/ApiHelpers");
6
- const date_fns_1 = require("date-fns");
7
- const backoff_1 = require("../util/backoff");
1
+ import { userAgent } from "./CovalentClient";
2
+ import { checkAndModifyResponse, debugOutput, paginateEndpoint } from "../util/ApiHelpers";
3
+ import { parseISO } from "date-fns";
4
+ import { ExponentialBackoff } from "../util/backoff";
5
+ import pLimit from "p-limit";
8
6
  class BlockResponse {
9
7
  constructor(data) {
10
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
8
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
11
9
  this.chain_id = data.chain_id;
12
10
  this.chain_name = data.chain_name;
13
11
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Block(itemData)) : null;
@@ -15,13 +13,13 @@ class BlockResponse {
15
13
  }
16
14
  class Block {
17
15
  constructor(data) {
18
- this.signed_at = data.signed_at && data.signed_at !== null ? (0, date_fns_1.parseISO)(data.signed_at.toString()) : null;
16
+ this.signed_at = data.signed_at && data.signed_at !== null ? parseISO(data.signed_at.toString()) : null;
19
17
  this.height = data.height;
20
18
  }
21
19
  }
22
20
  class ResolvedAddress {
23
21
  constructor(data) {
24
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
22
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
25
23
  this.chain_id = data.chain_id;
26
24
  this.chain_name = data.chain_name;
27
25
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new ResolvedAddressItem(itemData)) : null;
@@ -35,7 +33,7 @@ class ResolvedAddressItem {
35
33
  }
36
34
  class BlockHeightsResponse {
37
35
  constructor(data) {
38
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
36
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
39
37
  this.chain_id = data.chain_id;
40
38
  this.chain_name = data.chain_name;
41
39
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new Block(itemData)) : null;
@@ -52,7 +50,7 @@ class Pagination {
52
50
  }
53
51
  class GetLogsResponse {
54
52
  constructor(data) {
55
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
53
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
56
54
  this.chain_id = data.chain_id;
57
55
  this.chain_name = data.chain_name;
58
56
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new GetLogsEvent(itemData)) : null;
@@ -60,7 +58,7 @@ class GetLogsResponse {
60
58
  }
61
59
  class GetLogsEvent {
62
60
  constructor(data) {
63
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
61
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
64
62
  this.block_height = data.block_height;
65
63
  this.block_hash = data.block_hash;
66
64
  this.tx_offset = data.tx_offset;
@@ -95,7 +93,7 @@ class Param {
95
93
  }
96
94
  class LogEventsByAddressResponse {
97
95
  constructor(data) {
98
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
96
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
99
97
  this.chain_id = data.chain_id;
100
98
  this.chain_name = data.chain_name;
101
99
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent(itemData)) : null;
@@ -104,7 +102,7 @@ class LogEventsByAddressResponse {
104
102
  }
105
103
  class LogEvent {
106
104
  constructor(data) {
107
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
105
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
108
106
  this.block_height = data.block_height;
109
107
  this.tx_offset = data.tx_offset;
110
108
  this.log_offset = data.log_offset;
@@ -122,7 +120,7 @@ class LogEvent {
122
120
  }
123
121
  class LogEventsByTopicHashResponse {
124
122
  constructor(data) {
125
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
123
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
126
124
  this.chain_id = data.chain_id;
127
125
  this.chain_name = data.chain_name;
128
126
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new LogEvent(itemData)) : null;
@@ -131,7 +129,7 @@ class LogEventsByTopicHashResponse {
131
129
  }
132
130
  class AllChainsResponse {
133
131
  constructor(data) {
134
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
132
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
135
133
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainItem(itemData)) : null;
136
134
  }
137
135
  }
@@ -152,7 +150,7 @@ class ChainItem {
152
150
  }
153
151
  class AllChainsStatusResponse {
154
152
  constructor(data) {
155
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
153
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
156
154
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainStatusItem(itemData)) : null;
157
155
  }
158
156
  }
@@ -166,13 +164,13 @@ class ChainStatusItem {
166
164
  this.white_logo_url = data.white_logo_url;
167
165
  this.is_appchain = data.is_appchain;
168
166
  this.synced_block_height = data.synced_block_height;
169
- this.synced_blocked_signed_at = data.synced_blocked_signed_at && data.synced_blocked_signed_at !== null ? (0, date_fns_1.parseISO)(data.synced_blocked_signed_at.toString()) : null;
167
+ this.synced_blocked_signed_at = data.synced_blocked_signed_at && data.synced_blocked_signed_at !== null ? parseISO(data.synced_blocked_signed_at.toString()) : null;
170
168
  this.has_data = data.has_data;
171
169
  }
172
170
  }
173
171
  class ChainActivityResponse {
174
172
  constructor(data) {
175
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
173
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
176
174
  this.address = data.address;
177
175
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new ChainActivityEvent(itemData)) : null;
178
176
  }
@@ -180,18 +178,23 @@ class ChainActivityResponse {
180
178
  class ChainActivityEvent extends ChainItem {
181
179
  constructor(data) {
182
180
  super(data);
183
- this.last_seen_at = data.last_seen_at && data.last_seen_at !== null ? (0, date_fns_1.parseISO)(data.last_seen_at.toString()) : null;
181
+ this.last_seen_at = data.last_seen_at && data.last_seen_at !== null ? parseISO(data.last_seen_at.toString()) : null;
184
182
  }
185
183
  }
186
184
  /**
187
185
  * Class A - Base
188
186
  *
189
187
  */
190
- class BaseService {
191
- constructor(apiKey) {
188
+ export class BaseService {
189
+ constructor(apiKey, debug = false, threadCount = 3) {
192
190
  this.apiKey = apiKey;
191
+ this.debug = debug;
192
+ this.threadCount = threadCount;
193
+ this.LIMIT = pLimit(this.threadCount);
193
194
  }
194
195
  /**
196
+ *
197
+ * Commonly used to fetch and render a single block for a block explorer.
195
198
  *
196
199
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
197
200
  * @param {string} blockHeight - The block height or `latest` for the latest block available.
@@ -201,42 +204,47 @@ class BaseService {
201
204
  let success = false;
202
205
  let data;
203
206
  let response;
204
- const backoff = new backoff_1.ExponentialBackoff();
207
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
205
208
  while (!success) {
206
209
  try {
207
210
  const urlParams = new URLSearchParams();
208
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`, {
211
+ let startTime;
212
+ if (this.debug) {
213
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
214
+ }
215
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/block_v2/${blockHeight}/?${urlParams}`, {
209
216
  headers: {
210
217
  "Authorization": `Bearer ${this.apiKey}`,
211
- "X-Requested-With": Client_1.userAgent
218
+ "X-Requested-With": userAgent
212
219
  }
213
- });
214
- data = await response.json();
215
- if (data.error && data.error_code === 429) {
220
+ }));
221
+ debugOutput(response.url, response.status, startTime);
222
+ if (response.status === 429) {
216
223
  try {
217
- await backoff.backOff();
224
+ data = await this.LIMIT(() => backoff.backOff(response.url));
218
225
  }
219
226
  catch (error) {
220
227
  success = true;
221
228
  return {
222
229
  data: null,
223
- error: data.error,
224
- error_code: data ? data.error_code : response.status,
225
- error_message: data ? data.error_message : "401 Authorization Required"
230
+ error: true,
231
+ error_code: response.status,
232
+ error_message: error.message
226
233
  };
227
234
  }
228
235
  }
229
236
  else {
230
- const dataClass = new BlockResponse(data.data);
231
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
232
- success = true;
233
- return {
234
- data: dataClass,
235
- error: data.error,
236
- error_code: data ? data.error_code : response.status,
237
- error_message: data ? data.error_message : "401 Authorization Required"
238
- };
237
+ data = await response.json();
239
238
  }
239
+ const dataClass = new BlockResponse(data.data);
240
+ checkAndModifyResponse(dataClass);
241
+ success = true;
242
+ return {
243
+ data: dataClass,
244
+ error: data.error,
245
+ error_code: data ? data.error_code : response.status,
246
+ error_message: data ? data.error_message : "401 Authorization Required"
247
+ };
240
248
  }
241
249
  catch (error) {
242
250
  success = true;
@@ -250,6 +258,8 @@ class BaseService {
250
258
  }
251
259
  }
252
260
  /**
261
+ *
262
+ * Commonly used to resolve ENS, RNS and Unstoppable Domains addresses.
253
263
  *
254
264
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
255
265
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -259,42 +269,47 @@ class BaseService {
259
269
  let success = false;
260
270
  let data;
261
271
  let response;
262
- const backoff = new backoff_1.ExponentialBackoff();
272
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
263
273
  while (!success) {
264
274
  try {
265
275
  const urlParams = new URLSearchParams();
266
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`, {
276
+ let startTime;
277
+ if (this.debug) {
278
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
279
+ }
280
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/resolve_address/?${urlParams}`, {
267
281
  headers: {
268
282
  "Authorization": `Bearer ${this.apiKey}`,
269
- "X-Requested-With": Client_1.userAgent
283
+ "X-Requested-With": userAgent
270
284
  }
271
- });
272
- data = await response.json();
273
- if (data.error && data.error_code === 429) {
285
+ }));
286
+ debugOutput(response.url, response.status, startTime);
287
+ if (response.status === 429) {
274
288
  try {
275
- await backoff.backOff();
289
+ data = await this.LIMIT(() => backoff.backOff(response.url));
276
290
  }
277
291
  catch (error) {
278
292
  success = true;
279
293
  return {
280
294
  data: null,
281
- error: data.error,
282
- error_code: data ? data.error_code : response.status,
283
- error_message: data ? data.error_message : "401 Authorization Required"
295
+ error: true,
296
+ error_code: response.status,
297
+ error_message: error.message
284
298
  };
285
299
  }
286
300
  }
287
301
  else {
288
- const dataClass = new ResolvedAddress(data.data);
289
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
290
- success = true;
291
- return {
292
- data: dataClass,
293
- error: data.error,
294
- error_code: data ? data.error_code : response.status,
295
- error_message: data ? data.error_message : "401 Authorization Required"
296
- };
302
+ data = await response.json();
297
303
  }
304
+ const dataClass = new ResolvedAddress(data.data);
305
+ checkAndModifyResponse(dataClass);
306
+ success = true;
307
+ return {
308
+ data: dataClass,
309
+ error: data.error,
310
+ error_code: data ? data.error_code : response.status,
311
+ error_message: data ? data.error_message : "401 Authorization Required"
312
+ };
298
313
  }
299
314
  catch (error) {
300
315
  success = true;
@@ -308,6 +323,8 @@ class BaseService {
308
323
  }
309
324
  }
310
325
  /**
326
+ *
327
+ * Commonly used to get all the block heights within a particular date range. Useful for rendering a display where you sort blocks by day.
311
328
  *
312
329
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
313
330
  * @param {string} startDate - The start date in YYYY-MM-DD format.
@@ -329,18 +346,20 @@ class BaseService {
329
346
  if (queryParamOpts?.pageNumber !== undefined) {
330
347
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
331
348
  }
332
- for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block)) {
349
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/block_v2/${startDate}/${endDate}/`, this.apiKey, urlParams, Block, this.debug, this.threadCount)) {
333
350
  yield res;
334
351
  }
335
352
  success = true;
336
353
  }
337
354
  catch (error) {
338
355
  success = true;
339
- return res;
356
+ throw new Error(error.message);
340
357
  }
341
358
  }
342
359
  }
343
360
  /**
361
+ *
362
+ * Commonly used to get all the event logs of the latest block, or for a range of blocks. Includes sender contract metadata as well as decoded logs.
344
363
  *
345
364
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
346
365
  * @param {GetLogsQueryParamOpts} queryParamOpts
@@ -356,7 +375,7 @@ class BaseService {
356
375
  let success = false;
357
376
  let data;
358
377
  let response;
359
- const backoff = new backoff_1.ExponentialBackoff();
378
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
360
379
  while (!success) {
361
380
  try {
362
381
  const urlParams = new URLSearchParams();
@@ -378,38 +397,43 @@ class BaseService {
378
397
  if (queryParamOpts?.skipDecode !== undefined) {
379
398
  urlParams.append("skip-decode", queryParamOpts?.skipDecode.toString());
380
399
  }
381
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
400
+ let startTime;
401
+ if (this.debug) {
402
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
403
+ }
404
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/events/?${urlParams}`, {
382
405
  headers: {
383
406
  "Authorization": `Bearer ${this.apiKey}`,
384
- "X-Requested-With": Client_1.userAgent
407
+ "X-Requested-With": userAgent
385
408
  }
386
- });
387
- data = await response.json();
388
- if (data.error && data.error_code === 429) {
409
+ }));
410
+ debugOutput(response.url, response.status, startTime);
411
+ if (response.status === 429) {
389
412
  try {
390
- await backoff.backOff();
413
+ data = await this.LIMIT(() => backoff.backOff(response.url));
391
414
  }
392
415
  catch (error) {
393
416
  success = true;
394
417
  return {
395
418
  data: null,
396
- error: data.error,
397
- error_code: data ? data.error_code : response.status,
398
- error_message: data ? data.error_message : "401 Authorization Required"
419
+ error: true,
420
+ error_code: response.status,
421
+ error_message: error.message
399
422
  };
400
423
  }
401
424
  }
402
425
  else {
403
- const dataClass = new GetLogsResponse(data.data);
404
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
405
- success = true;
406
- return {
407
- data: dataClass,
408
- error: data.error,
409
- error_code: data ? data.error_code : response.status,
410
- error_message: data ? data.error_message : "401 Authorization Required"
411
- };
426
+ data = await response.json();
412
427
  }
428
+ const dataClass = new GetLogsResponse(data.data);
429
+ checkAndModifyResponse(dataClass);
430
+ success = true;
431
+ return {
432
+ data: dataClass,
433
+ error: data.error,
434
+ error_code: data ? data.error_code : response.status,
435
+ error_message: data ? data.error_message : "401 Authorization Required"
436
+ };
413
437
  }
414
438
  catch (error) {
415
439
  success = true;
@@ -423,6 +447,8 @@ class BaseService {
423
447
  }
424
448
  }
425
449
  /**
450
+ *
451
+ * Commonly used to get all the event logs emitted from a particular contract address. Useful for building dashboards that examine on-chain interactions.
426
452
  *
427
453
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
428
454
  * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -451,25 +477,27 @@ class BaseService {
451
477
  if (queryParamOpts?.pageNumber !== undefined) {
452
478
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
453
479
  }
454
- for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent)) {
480
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/events/address/${contractAddress}/`, this.apiKey, urlParams, LogEvent, this.debug, this.threadCount)) {
455
481
  yield res;
456
482
  }
457
483
  success = true;
458
484
  }
459
485
  catch (error) {
460
486
  success = true;
461
- return res;
487
+ throw new Error(error.message);
462
488
  }
463
489
  }
464
490
  }
465
491
  /**
492
+ *
493
+ * Commonly used to get all event logs of the same topic hash across all contracts within a particular chain. Useful for cross-sectional analysis of event logs that are emitted on-chain.
466
494
  *
467
495
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
468
496
  * @param {string} topicHash - The endpoint will return event logs that contain this topic hash.
469
497
  * @param {GetLogEventsByTopicHashQueryParamOpts} queryParamOpts
470
498
  * - `startingBlock`: The first block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
471
499
  * - `endingBlock`: The last block to retrieve log events with. Accepts decimals, hexadecimals, or the strings `earliest` and `latest`.
472
- * - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported.
500
+ * - `secondaryTopics`: Additional topic hash(es) to filter on - padded & unpadded address fields are supported. Separate multiple topics with a comma.
473
501
  * - `pageSize`: Number of items per page. Omitting this parameter defaults to 100.
474
502
  * - `pageNumber`: 0-indexed page number to begin pagination.
475
503
  *
@@ -495,18 +523,20 @@ class BaseService {
495
523
  if (queryParamOpts?.pageNumber !== undefined) {
496
524
  urlParams.append("page-number", queryParamOpts?.pageNumber.toString());
497
525
  }
498
- for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent)) {
526
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/events/topics/${topicHash}/`, this.apiKey, urlParams, LogEvent, this.debug, this.threadCount)) {
499
527
  yield res;
500
528
  }
501
529
  success = true;
502
530
  }
503
531
  catch (error) {
504
532
  success = true;
505
- return res;
533
+ throw new Error(error.message);
506
534
  }
507
535
  }
508
536
  }
509
537
  /**
538
+ *
539
+ * Commonly used to build internal dashboards for all supported chains on Covalent.
510
540
  *
511
541
  *
512
542
  */
@@ -514,42 +544,47 @@ class BaseService {
514
544
  let success = false;
515
545
  let data;
516
546
  let response;
517
- const backoff = new backoff_1.ExponentialBackoff();
547
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
518
548
  while (!success) {
519
549
  try {
520
550
  const urlParams = new URLSearchParams();
521
- response = await fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
551
+ let startTime;
552
+ if (this.debug) {
553
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
554
+ }
555
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/?${urlParams}`, {
522
556
  headers: {
523
557
  "Authorization": `Bearer ${this.apiKey}`,
524
- "X-Requested-With": Client_1.userAgent
558
+ "X-Requested-With": userAgent
525
559
  }
526
- });
527
- data = await response.json();
528
- if (data.error && data.error_code === 429) {
560
+ }));
561
+ debugOutput(response.url, response.status, startTime);
562
+ if (response.status === 429) {
529
563
  try {
530
- await backoff.backOff();
564
+ data = await this.LIMIT(() => backoff.backOff(response.url));
531
565
  }
532
566
  catch (error) {
533
567
  success = true;
534
568
  return {
535
569
  data: null,
536
- error: data.error,
537
- error_code: data ? data.error_code : response.status,
538
- error_message: data ? data.error_message : "401 Authorization Required"
570
+ error: true,
571
+ error_code: response.status,
572
+ error_message: error.message
539
573
  };
540
574
  }
541
575
  }
542
576
  else {
543
- const dataClass = new AllChainsResponse(data.data);
544
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
545
- success = true;
546
- return {
547
- data: dataClass,
548
- error: data.error,
549
- error_code: data ? data.error_code : response.status,
550
- error_message: data ? data.error_message : "401 Authorization Required"
551
- };
577
+ data = await response.json();
552
578
  }
579
+ const dataClass = new AllChainsResponse(data.data);
580
+ checkAndModifyResponse(dataClass);
581
+ success = true;
582
+ return {
583
+ data: dataClass,
584
+ error: data.error,
585
+ error_code: data ? data.error_code : response.status,
586
+ error_message: data ? data.error_message : "401 Authorization Required"
587
+ };
553
588
  }
554
589
  catch (error) {
555
590
  success = true;
@@ -563,6 +598,8 @@ class BaseService {
563
598
  }
564
599
  }
565
600
  /**
601
+ *
602
+ * Commonly used to build internal status dashboards of all supported chains.
566
603
  *
567
604
  *
568
605
  */
@@ -570,42 +607,47 @@ class BaseService {
570
607
  let success = false;
571
608
  let data;
572
609
  let response;
573
- const backoff = new backoff_1.ExponentialBackoff();
610
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
574
611
  while (!success) {
575
612
  try {
576
613
  const urlParams = new URLSearchParams();
577
- response = await fetch(`https://api.covalenthq.com/v1/chains/status/?${urlParams}`, {
614
+ let startTime;
615
+ if (this.debug) {
616
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
617
+ }
618
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/chains/status/?${urlParams}`, {
578
619
  headers: {
579
620
  "Authorization": `Bearer ${this.apiKey}`,
580
- "X-Requested-With": Client_1.userAgent
621
+ "X-Requested-With": userAgent
581
622
  }
582
- });
583
- data = await response.json();
584
- if (data.error && data.error_code === 429) {
623
+ }));
624
+ debugOutput(response.url, response.status, startTime);
625
+ if (response.status === 429) {
585
626
  try {
586
- await backoff.backOff();
627
+ data = await this.LIMIT(() => backoff.backOff(response.url));
587
628
  }
588
629
  catch (error) {
589
630
  success = true;
590
631
  return {
591
632
  data: null,
592
- error: data.error,
593
- error_code: data ? data.error_code : response.status,
594
- error_message: data ? data.error_message : "401 Authorization Required"
633
+ error: true,
634
+ error_code: response.status,
635
+ error_message: error.message
595
636
  };
596
637
  }
597
638
  }
598
639
  else {
599
- const dataClass = new AllChainsStatusResponse(data.data);
600
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
601
- success = true;
602
- return {
603
- data: dataClass,
604
- error: data.error,
605
- error_code: data ? data.error_code : response.status,
606
- error_message: data ? data.error_message : "401 Authorization Required"
607
- };
640
+ data = await response.json();
608
641
  }
642
+ const dataClass = new AllChainsStatusResponse(data.data);
643
+ checkAndModifyResponse(dataClass);
644
+ success = true;
645
+ return {
646
+ data: dataClass,
647
+ error: data.error,
648
+ error_code: data ? data.error_code : response.status,
649
+ error_message: data ? data.error_message : "401 Authorization Required"
650
+ };
609
651
  }
610
652
  catch (error) {
611
653
  success = true;
@@ -619,6 +661,8 @@ class BaseService {
619
661
  }
620
662
  }
621
663
  /**
664
+ *
665
+ * Commonly used to locate chains which an address is active on with a single API call.
622
666
  *
623
667
  * @param {string} walletAddress - The requested wallet address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
624
668
  * @param {GetAddressActivityQueryParamOpts} queryParamOpts
@@ -629,45 +673,50 @@ class BaseService {
629
673
  let success = false;
630
674
  let data;
631
675
  let response;
632
- const backoff = new backoff_1.ExponentialBackoff();
676
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
633
677
  while (!success) {
634
678
  try {
635
679
  const urlParams = new URLSearchParams();
636
680
  if (queryParamOpts?.testnets !== undefined) {
637
681
  urlParams.append("testnets", queryParamOpts?.testnets.toString());
638
682
  }
639
- response = await fetch(`https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`, {
683
+ let startTime;
684
+ if (this.debug) {
685
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
686
+ }
687
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/address/${walletAddress}/activity/?${urlParams}`, {
640
688
  headers: {
641
689
  "Authorization": `Bearer ${this.apiKey}`,
642
- "X-Requested-With": Client_1.userAgent
690
+ "X-Requested-With": userAgent
643
691
  }
644
- });
645
- data = await response.json();
646
- if (data.error && data.error_code === 429) {
692
+ }));
693
+ debugOutput(response.url, response.status, startTime);
694
+ if (response.status === 429) {
647
695
  try {
648
- await backoff.backOff();
696
+ data = await this.LIMIT(() => backoff.backOff(response.url));
649
697
  }
650
698
  catch (error) {
651
699
  success = true;
652
700
  return {
653
701
  data: null,
654
- error: data.error,
655
- error_code: data ? data.error_code : response.status,
656
- error_message: data ? data.error_message : "401 Authorization Required"
702
+ error: true,
703
+ error_code: response.status,
704
+ error_message: error.message
657
705
  };
658
706
  }
659
707
  }
660
708
  else {
661
- const dataClass = new ChainActivityResponse(data.data);
662
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
663
- success = true;
664
- return {
665
- data: dataClass,
666
- error: data.error,
667
- error_code: data ? data.error_code : response.status,
668
- error_message: data ? data.error_message : "401 Authorization Required"
669
- };
709
+ data = await response.json();
670
710
  }
711
+ const dataClass = new ChainActivityResponse(data.data);
712
+ checkAndModifyResponse(dataClass);
713
+ success = true;
714
+ return {
715
+ data: dataClass,
716
+ error: data.error,
717
+ error_code: data ? data.error_code : response.status,
718
+ error_message: data ? data.error_message : "401 Authorization Required"
719
+ };
671
720
  }
672
721
  catch (error) {
673
722
  success = true;
@@ -681,5 +730,4 @@ class BaseService {
681
730
  }
682
731
  }
683
732
  }
684
- exports.BaseService = BaseService;
685
733
  //# sourceMappingURL=BaseService.js.map