@covalenthq/client-sdk 0.2.9 → 0.5.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 (116) hide show
  1. package/README.md +117 -46
  2. package/dist/cjs/index.d.ts +9 -0
  3. package/dist/cjs/index.js +5226 -0
  4. package/dist/cjs/index.js.map +1 -0
  5. package/dist/cjs/services/BalanceService.d.ts +543 -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 +620 -0
  9. package/dist/cjs/services/PricingService.d.ts +88 -0
  10. package/dist/cjs/services/SecurityService.d.ts +158 -0
  11. package/dist/cjs/services/TransactionService.d.ts +457 -0
  12. package/dist/cjs/services/XykService.d.ts +686 -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 +322 -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 +297 -0
  19. package/dist/cjs/util/types/PricingServiceTypes.d.ts +31 -0
  20. package/dist/cjs/util/types/SecurityServiceTypes.d.ts +121 -0
  21. package/dist/cjs/util/types/TransactionServiceTypes.d.ts +322 -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 +5223 -0
  25. package/dist/es/index.js.map +1 -0
  26. package/dist/es/services/BalanceService.d.ts +543 -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 +620 -0
  30. package/dist/es/services/PricingService.d.ts +88 -0
  31. package/dist/es/services/SecurityService.d.ts +158 -0
  32. package/dist/es/services/TransactionService.d.ts +457 -0
  33. package/dist/es/services/XykService.d.ts +686 -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 +322 -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 +297 -0
  40. package/dist/es/util/types/PricingServiceTypes.d.ts +31 -0
  41. package/dist/es/util/types/SecurityServiceTypes.d.ts +121 -0
  42. package/dist/es/util/types/TransactionServiceTypes.d.ts +322 -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 +5223 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/services/BalanceService.d.ts +543 -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 +620 -0
  51. package/dist/esm/services/PricingService.d.ts +88 -0
  52. package/dist/esm/services/SecurityService.d.ts +158 -0
  53. package/dist/esm/services/TransactionService.d.ts +457 -0
  54. package/dist/esm/services/XykService.d.ts +686 -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 +322 -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 +297 -0
  61. package/dist/esm/util/types/PricingServiceTypes.d.ts +31 -0
  62. package/dist/esm/util/types/SecurityServiceTypes.d.ts +121 -0
  63. package/dist/esm/util/types/TransactionServiceTypes.d.ts +322 -0
  64. package/dist/esm/util/types/XykServiceTypes.d.ts +479 -0
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.js +9 -27
  67. package/dist/index.js.map +1 -1
  68. package/dist/services/BalanceService.d.ts +149 -11
  69. package/dist/services/BalanceService.js +300 -84
  70. package/dist/services/BalanceService.js.map +1 -1
  71. package/dist/services/BaseService.d.ts +46 -10
  72. package/dist/services/BaseService.js +199 -151
  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 +182 -16
  78. package/dist/services/NftService.js +490 -211
  79. package/dist/services/NftService.js.map +1 -1
  80. package/dist/services/PricingService.d.ts +8 -3
  81. package/dist/services/PricingService.js +44 -38
  82. package/dist/services/PricingService.js.map +1 -1
  83. package/dist/services/SecurityService.d.ts +71 -3
  84. package/dist/services/SecurityService.js +140 -32
  85. package/dist/services/SecurityService.js.map +1 -1
  86. package/dist/services/TransactionService.d.ts +58 -9
  87. package/dist/services/TransactionService.js +152 -103
  88. package/dist/services/TransactionService.js.map +1 -1
  89. package/dist/services/XykService.d.ts +85 -19
  90. package/dist/services/XykService.js +470 -291
  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 +63 -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 +7 -0
  103. package/dist/util/types/GenericTypes.js +1 -2
  104. package/dist/util/types/NftServiceTypes.d.ts +86 -2
  105. package/dist/util/types/NftServiceTypes.js +1 -2
  106. package/dist/util/types/PricingServiceTypes.js +1 -2
  107. package/dist/util/types/SecurityServiceTypes.d.ts +51 -0
  108. package/dist/util/types/SecurityServiceTypes.js +1 -2
  109. package/dist/util/types/TransactionServiceTypes.d.ts +24 -2
  110. package/dist/util/types/TransactionServiceTypes.js +1 -2
  111. package/dist/util/types/XykServiceTypes.d.ts +20 -6
  112. package/dist/util/types/XykServiceTypes.js +1 -2
  113. package/package.json +19 -4
  114. package/dist/services/Client.d.ts +0 -29
  115. package/dist/services/Client.js +0 -30
  116. package/dist/services/Client.js.map +0 -1
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NftService = 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 ChainCollectionResponse {
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 ChainCollectionItem(itemData)) : null;
@@ -22,7 +20,7 @@ class ChainCollectionItem {
22
20
  this.token_total_supply = data.token_total_supply;
23
21
  this.cached_metadata_count = data.cached_metadata_count;
24
22
  this.cached_asset_count = data.cached_asset_count;
25
- this.last_scraped_at = data.last_scraped_at && data.last_scraped_at !== null ? (0, date_fns_1.parseISO)(data.last_scraped_at.toString()) : null;
23
+ this.last_scraped_at = data.last_scraped_at && data.last_scraped_at !== null ? parseISO(data.last_scraped_at.toString()) : null;
26
24
  }
27
25
  }
28
26
  class Pagination {
@@ -36,7 +34,7 @@ class Pagination {
36
34
  class NftAddressBalanceNftResponse {
37
35
  constructor(data) {
38
36
  this.address = data.address;
39
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
37
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
40
38
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContractBalanceItem(itemData)) : null;
41
39
  }
42
40
  }
@@ -47,9 +45,9 @@ class NftTokenContractBalanceItem {
47
45
  this.contract_address = data.contract_address;
48
46
  this.supports_erc = data.supports_erc;
49
47
  this.is_spam = data.is_spam;
50
- this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? (0, date_fns_1.parseISO)(data.last_transfered_at.toString()) : null;
48
+ this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? parseISO(data.last_transfered_at.toString()) : null;
51
49
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
52
- this.balance24h = data.balance24h;
50
+ this.balance_24h = data.balance_24h;
53
51
  this.type = data.type;
54
52
  this.nft_data = data.nft_data && data.nft_data !== null ? data.nft_data.map((itemData) => new NftData(itemData)) : null;
55
53
  }
@@ -89,7 +87,7 @@ class NftCollectionAttribute {
89
87
  }
90
88
  class NftMetadataResponse {
91
89
  constructor(data) {
92
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
90
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
93
91
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTokenContract(itemData)) : null;
94
92
  this.pagination = data.pagination && data.pagination !== null ? new Pagination(data.pagination) : null;
95
93
  }
@@ -106,7 +104,7 @@ class NftTokenContract {
106
104
  }
107
105
  class NftTransactionsResponse {
108
106
  constructor(data) {
109
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
107
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
110
108
  this.chain_id = data.chain_id;
111
109
  this.chain_name = data.chain_name;
112
110
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTransaction(itemData)) : null;
@@ -126,7 +124,7 @@ class NftTransaction {
126
124
  }
127
125
  class NftTransactionItem {
128
126
  constructor(data) {
129
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
127
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
130
128
  this.block_height = data.block_height;
131
129
  this.tx_hash = data.tx_hash;
132
130
  this.tx_offset = data.tx_offset;
@@ -150,7 +148,7 @@ class NftTransactionItem {
150
148
  }
151
149
  class LogEvent {
152
150
  constructor(data) {
153
- this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? (0, date_fns_1.parseISO)(data.block_signed_at.toString()) : null;
151
+ this.block_signed_at = data.block_signed_at && data.block_signed_at !== null ? parseISO(data.block_signed_at.toString()) : null;
154
152
  this.block_height = data.block_height;
155
153
  this.tx_offset = data.tx_offset;
156
154
  this.log_offset = data.log_offset;
@@ -184,7 +182,7 @@ class Param {
184
182
  }
185
183
  class NftCollectionTraitsResponse {
186
184
  constructor(data) {
187
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
185
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
188
186
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTrait(itemData)) : null;
189
187
  }
190
188
  }
@@ -195,7 +193,7 @@ class NftTrait {
195
193
  }
196
194
  class NftCollectionAttributesForTraitResponse {
197
195
  constructor(data) {
198
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
196
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
199
197
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftSummaryAttribute(itemData)) : null;
200
198
  }
201
199
  }
@@ -214,7 +212,7 @@ class NftAttribute {
214
212
  }
215
213
  class NftCollectionTraitSummaryResponse {
216
214
  constructor(data) {
217
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
215
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
218
216
  this.items = data.items && data.items !== null ? data.items.map((itemData) => new NftTraitSummary(itemData)) : null;
219
217
  }
220
218
  }
@@ -242,7 +240,7 @@ class NftTraitString {
242
240
  }
243
241
  class NftOwnershipForCollectionResponse {
244
242
  constructor(data) {
245
- this.updated_at = data.updated_at && data.updated_at !== null ? (0, date_fns_1.parseISO)(data.updated_at.toString()) : null;
243
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
246
244
  this.address = data.address;
247
245
  this.collection = data.collection;
248
246
  this.is_spam = data.is_spam;
@@ -256,22 +254,83 @@ class NftOwnershipForCollectionItem {
256
254
  this.contract_address = data.contract_address;
257
255
  this.token_id = data.token_id && data.token_id !== null ? BigInt(data.token_id) : null;
258
256
  this.supports_erc = data.supports_erc;
259
- this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? (0, date_fns_1.parseISO)(data.last_transfered_at.toString()) : null;
257
+ this.last_transfered_at = data.last_transfered_at && data.last_transfered_at !== null ? parseISO(data.last_transfered_at.toString()) : null;
260
258
  this.balance = data.balance && data.balance !== null ? BigInt(data.balance) : null;
261
- this.balance24h = data.balance24h;
259
+ this.balance_24h = data.balance_24h;
262
260
  this.type = data.type;
263
261
  this.nft_data = data.nft_data && data.nft_data !== null ? new NftData(data.nft_data) : null;
264
262
  }
265
263
  }
264
+ class NftMarketSaleCountResponse {
265
+ constructor(data) {
266
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
267
+ this.address = data.address;
268
+ this.quote_currency = data.quote_currency;
269
+ this.chain_name = data.chain_name;
270
+ this.chain_id = data.chain_id;
271
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new MarketSaleCountItem(itemData)) : null;
272
+ }
273
+ }
274
+ class MarketSaleCountItem {
275
+ constructor(data) {
276
+ this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
277
+ this.sale_count = data.sale_count;
278
+ }
279
+ }
280
+ class NftMarketVolumeResponse {
281
+ constructor(data) {
282
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
283
+ this.address = data.address;
284
+ this.quote_currency = data.quote_currency;
285
+ this.chain_name = data.chain_name;
286
+ this.chain_id = data.chain_id;
287
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new MarketVolumeItem(itemData)) : null;
288
+ }
289
+ }
290
+ class MarketVolumeItem {
291
+ constructor(data) {
292
+ this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
293
+ this.native_ticker_symbol = data.native_ticker_symbol;
294
+ this.native_name = data.native_name;
295
+ this.volume_quote = data.volume_quote;
296
+ this.volume_native_quote = data.volume_native_quote;
297
+ this.pretty_volume_quote = data.pretty_volume_quote;
298
+ }
299
+ }
300
+ class NftMarketFloorPriceResponse {
301
+ constructor(data) {
302
+ this.updated_at = data.updated_at && data.updated_at !== null ? parseISO(data.updated_at.toString()) : null;
303
+ this.address = data.address;
304
+ this.quote_currency = data.quote_currency;
305
+ this.chain_name = data.chain_name;
306
+ this.chain_id = data.chain_id;
307
+ this.items = data.items && data.items !== null ? data.items.map((itemData) => new MarketFloorPriceItem(itemData)) : null;
308
+ }
309
+ }
310
+ class MarketFloorPriceItem {
311
+ constructor(data) {
312
+ this.date = data.date && data.date !== null ? parseISO(data.date.toString()) : null;
313
+ this.native_ticker_symbol = data.native_ticker_symbol;
314
+ this.native_name = data.native_name;
315
+ this.floor_price_native_quote = data.floor_price_native_quote;
316
+ this.floor_price_quote = data.floor_price_quote;
317
+ this.pretty_floor_price_quote = data.pretty_floor_price_quote;
318
+ }
319
+ }
266
320
  /**
267
321
  * NFT APIs
268
322
  *
269
323
  */
270
- class NftService {
271
- constructor(apiKey) {
324
+ export class NftService {
325
+ constructor(apiKey, debug = false, threadCount = 3) {
272
326
  this.apiKey = apiKey;
327
+ this.debug = debug;
328
+ this.threadCount = threadCount;
329
+ this.LIMIT = pLimit(this.threadCount);
273
330
  }
274
331
  /**
332
+ *
333
+ * Commonly used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files.
275
334
  *
276
335
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
277
336
  * @param {GetChainCollectionsQueryParamOpts} queryParamOpts
@@ -295,18 +354,20 @@ class NftService {
295
354
  if (queryParamOpts?.noSpam !== undefined) {
296
355
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
297
356
  }
298
- for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem)) {
357
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/collections/`, this.apiKey, urlParams, ChainCollectionItem, this.debug, this.threadCount)) {
299
358
  yield res;
300
359
  }
301
360
  success = true;
302
361
  }
303
362
  catch (error) {
304
363
  success = true;
305
- return res;
364
+ throw new Error(error.message);
306
365
  }
307
366
  }
308
367
  }
309
368
  /**
369
+ *
370
+ * Commonly used to render the NFTs (including ERC721 and ERC1155) held by an address.
310
371
  *
311
372
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
312
373
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -320,7 +381,7 @@ class NftService {
320
381
  let success = false;
321
382
  let data;
322
383
  let response;
323
- const backoff = new backoff_1.ExponentialBackoff();
384
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
324
385
  while (!success) {
325
386
  try {
326
387
  const urlParams = new URLSearchParams();
@@ -333,38 +394,43 @@ class NftService {
333
394
  if (queryParamOpts?.withUncached !== undefined) {
334
395
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
335
396
  }
336
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
397
+ let startTime;
398
+ if (this.debug) {
399
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
400
+ }
401
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/balances_nft/?${urlParams}`, {
337
402
  headers: {
338
403
  "Authorization": `Bearer ${this.apiKey}`,
339
- "X-Requested-With": Client_1.userAgent
404
+ "X-Requested-With": userAgent
340
405
  }
341
- });
342
- data = await response.json();
343
- if (data.error && data.error_code === 429) {
406
+ }));
407
+ debugOutput(response.url, response.status, startTime);
408
+ if (response.status === 429) {
344
409
  try {
345
- await backoff.backOff();
410
+ data = await this.LIMIT(() => backoff.backOff(response.url));
346
411
  }
347
412
  catch (error) {
348
413
  success = true;
349
414
  return {
350
415
  data: null,
351
- error: data.error,
352
- error_code: data ? data.error_code : response.status,
353
- error_message: data ? data.error_message : "401 Authorization Required"
416
+ error: true,
417
+ error_code: response.status,
418
+ error_message: error.message
354
419
  };
355
420
  }
356
421
  }
357
422
  else {
358
- const dataClass = new NftAddressBalanceNftResponse(data.data);
359
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
360
- success = true;
361
- return {
362
- data: dataClass,
363
- error: data.error,
364
- error_code: data ? data.error_code : response.status,
365
- error_message: data ? data.error_message : "401 Authorization Required"
366
- };
423
+ data = await response.json();
367
424
  }
425
+ const dataClass = new NftAddressBalanceNftResponse(data.data);
426
+ checkAndModifyResponse(dataClass);
427
+ success = true;
428
+ return {
429
+ data: dataClass,
430
+ error: data.error,
431
+ error_code: data ? data.error_code : response.status,
432
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
433
+ };
368
434
  }
369
435
  catch (error) {
370
436
  success = true;
@@ -372,12 +438,14 @@ class NftService {
372
438
  data: null,
373
439
  error: true,
374
440
  error_code: data ? data.error_code : response.status,
375
- error_message: data ? data.error_message : "401 Authorization Required"
441
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
376
442
  };
377
443
  }
378
444
  }
379
445
  }
380
446
  /**
447
+ *
448
+ * Commonly used to get NFT token IDs with metadata from a collection. Useful for building NFT card displays.
381
449
  *
382
450
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
383
451
  * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -414,18 +482,20 @@ class NftService {
414
482
  if (queryParamOpts?.withUncached !== undefined) {
415
483
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
416
484
  }
417
- for await (res of (0, ApiHelpers_1.paginateEndpoint)(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract)) {
485
+ for await (res of paginateEndpoint(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/`, this.apiKey, urlParams, NftTokenContract, this.debug, this.threadCount)) {
418
486
  yield res;
419
487
  }
420
488
  success = true;
421
489
  }
422
490
  catch (error) {
423
491
  success = true;
424
- return res;
492
+ throw new Error(error.message);
425
493
  }
426
494
  }
427
495
  }
428
496
  /**
497
+ *
498
+ * Commonly used to get a single NFT metadata by token ID from a collection. Useful for building NFT card displays.
429
499
  *
430
500
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
431
501
  * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -439,7 +509,7 @@ class NftService {
439
509
  let success = false;
440
510
  let data;
441
511
  let response;
442
- const backoff = new backoff_1.ExponentialBackoff();
512
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
443
513
  while (!success) {
444
514
  try {
445
515
  const urlParams = new URLSearchParams();
@@ -449,38 +519,43 @@ class NftService {
449
519
  if (queryParamOpts?.withUncached !== undefined) {
450
520
  urlParams.append("with-uncached", queryParamOpts?.withUncached.toString());
451
521
  }
452
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
522
+ let startTime;
523
+ if (this.debug) {
524
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
525
+ }
526
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${contractAddress}/metadata/${tokenId}/?${urlParams}`, {
453
527
  headers: {
454
528
  "Authorization": `Bearer ${this.apiKey}`,
455
- "X-Requested-With": Client_1.userAgent
529
+ "X-Requested-With": userAgent
456
530
  }
457
- });
458
- data = await response.json();
459
- if (data.error && data.error_code === 429) {
531
+ }));
532
+ debugOutput(response.url, response.status, startTime);
533
+ if (response.status === 429) {
460
534
  try {
461
- await backoff.backOff();
535
+ data = await this.LIMIT(() => backoff.backOff(response.url));
462
536
  }
463
537
  catch (error) {
464
538
  success = true;
465
539
  return {
466
540
  data: null,
467
- error: data.error,
468
- error_code: data ? data.error_code : response.status,
469
- error_message: data ? data.error_message : "401 Authorization Required"
541
+ error: true,
542
+ error_code: response.status,
543
+ error_message: error.message
470
544
  };
471
545
  }
472
546
  }
473
547
  else {
474
- const dataClass = new NftMetadataResponse(data.data);
475
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
476
- success = true;
477
- return {
478
- data: dataClass,
479
- error: data.error,
480
- error_code: data ? data.error_code : response.status,
481
- error_message: data ? data.error_message : "401 Authorization Required"
482
- };
548
+ data = await response.json();
483
549
  }
550
+ const dataClass = new NftMetadataResponse(data.data);
551
+ checkAndModifyResponse(dataClass);
552
+ success = true;
553
+ return {
554
+ data: dataClass,
555
+ error: data.error,
556
+ error_code: data ? data.error_code : response.status,
557
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
558
+ };
484
559
  }
485
560
  catch (error) {
486
561
  success = true;
@@ -488,12 +563,14 @@ class NftService {
488
563
  data: null,
489
564
  error: true,
490
565
  error_code: data ? data.error_code : response.status,
491
- error_message: data ? data.error_message : "401 Authorization Required"
566
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
492
567
  };
493
568
  }
494
569
  }
495
570
  }
496
571
  /**
572
+ *
573
+ * Commonly used to get all transactions of an NFT token. Useful for building a transaction history table or price chart.
497
574
  *
498
575
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
499
576
  * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -506,45 +583,50 @@ class NftService {
506
583
  let success = false;
507
584
  let data;
508
585
  let response;
509
- const backoff = new backoff_1.ExponentialBackoff();
586
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
510
587
  while (!success) {
511
588
  try {
512
589
  const urlParams = new URLSearchParams();
513
590
  if (queryParamOpts?.noSpam !== undefined) {
514
591
  urlParams.append("no-spam", queryParamOpts?.noSpam.toString());
515
592
  }
516
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
593
+ let startTime;
594
+ if (this.debug) {
595
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
596
+ }
597
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_transactions/${tokenId}/?${urlParams}`, {
517
598
  headers: {
518
599
  "Authorization": `Bearer ${this.apiKey}`,
519
- "X-Requested-With": Client_1.userAgent
600
+ "X-Requested-With": userAgent
520
601
  }
521
- });
522
- data = await response.json();
523
- if (data.error && data.error_code === 429) {
602
+ }));
603
+ debugOutput(response.url, response.status, startTime);
604
+ if (response.status === 429) {
524
605
  try {
525
- await backoff.backOff();
606
+ data = await this.LIMIT(() => backoff.backOff(response.url));
526
607
  }
527
608
  catch (error) {
528
609
  success = true;
529
610
  return {
530
611
  data: null,
531
- error: data.error,
532
- error_code: data ? data.error_code : response.status,
533
- error_message: data ? data.error_message : "401 Authorization Required"
612
+ error: true,
613
+ error_code: response.status,
614
+ error_message: error.message
534
615
  };
535
616
  }
536
617
  }
537
618
  else {
538
- const dataClass = new NftTransactionsResponse(data.data);
539
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
540
- success = true;
541
- return {
542
- data: dataClass,
543
- error: data.error,
544
- error_code: data ? data.error_code : response.status,
545
- error_message: data ? data.error_message : "401 Authorization Required"
546
- };
619
+ data = await response.json();
547
620
  }
621
+ const dataClass = new NftTransactionsResponse(data.data);
622
+ checkAndModifyResponse(dataClass);
623
+ success = true;
624
+ return {
625
+ data: dataClass,
626
+ error: data.error,
627
+ error_code: data ? data.error_code : response.status,
628
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
629
+ };
548
630
  }
549
631
  catch (error) {
550
632
  success = true;
@@ -552,12 +634,14 @@ class NftService {
552
634
  data: null,
553
635
  error: true,
554
636
  error_code: data ? data.error_code : response.status,
555
- error_message: data ? data.error_message : "401 Authorization Required"
637
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
556
638
  };
557
639
  }
558
640
  }
559
641
  }
560
642
  /**
643
+ *
644
+ * Commonly used to fetch and render the traits of a collection as seen in rarity calculators.
561
645
  *
562
646
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
563
647
  * @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -567,42 +651,47 @@ class NftService {
567
651
  let success = false;
568
652
  let data;
569
653
  let response;
570
- const backoff = new backoff_1.ExponentialBackoff();
654
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
571
655
  while (!success) {
572
656
  try {
573
657
  const urlParams = new URLSearchParams();
574
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
658
+ let startTime;
659
+ if (this.debug) {
660
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
661
+ }
662
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/?${urlParams}`, {
575
663
  headers: {
576
664
  "Authorization": `Bearer ${this.apiKey}`,
577
- "X-Requested-With": Client_1.userAgent
665
+ "X-Requested-With": userAgent
578
666
  }
579
- });
580
- data = await response.json();
581
- if (data.error && data.error_code === 429) {
667
+ }));
668
+ debugOutput(response.url, response.status, startTime);
669
+ if (response.status === 429) {
582
670
  try {
583
- await backoff.backOff();
671
+ data = await this.LIMIT(() => backoff.backOff(response.url));
584
672
  }
585
673
  catch (error) {
586
674
  success = true;
587
675
  return {
588
676
  data: null,
589
- error: data.error,
590
- error_code: data ? data.error_code : response.status,
591
- error_message: data ? data.error_message : "401 Authorization Required"
677
+ error: true,
678
+ error_code: response.status,
679
+ error_message: error.message
592
680
  };
593
681
  }
594
682
  }
595
683
  else {
596
- const dataClass = new NftCollectionTraitsResponse(data.data);
597
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
598
- success = true;
599
- return {
600
- data: dataClass,
601
- error: data.error,
602
- error_code: data ? data.error_code : response.status,
603
- error_message: data ? data.error_message : "401 Authorization Required"
604
- };
684
+ data = await response.json();
605
685
  }
686
+ const dataClass = new NftCollectionTraitsResponse(data.data);
687
+ checkAndModifyResponse(dataClass);
688
+ success = true;
689
+ return {
690
+ data: dataClass,
691
+ error: data.error,
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"
694
+ };
606
695
  }
607
696
  catch (error) {
608
697
  success = true;
@@ -610,12 +699,14 @@ class NftService {
610
699
  data: null,
611
700
  error: true,
612
701
  error_code: data ? data.error_code : response.status,
613
- error_message: data ? data.error_message : "401 Authorization Required"
702
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
614
703
  };
615
704
  }
616
705
  }
617
706
  }
618
707
  /**
708
+ *
709
+ * Commonly used to get the count of unique values for traits within an NFT collection.
619
710
  *
620
711
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
621
712
  * @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -626,42 +717,47 @@ class NftService {
626
717
  let success = false;
627
718
  let data;
628
719
  let response;
629
- const backoff = new backoff_1.ExponentialBackoff();
720
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
630
721
  while (!success) {
631
722
  try {
632
723
  const urlParams = new URLSearchParams();
633
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
724
+ let startTime;
725
+ if (this.debug) {
726
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
727
+ }
728
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits/${trait}/attributes/?${urlParams}`, {
634
729
  headers: {
635
730
  "Authorization": `Bearer ${this.apiKey}`,
636
- "X-Requested-With": Client_1.userAgent
731
+ "X-Requested-With": userAgent
637
732
  }
638
- });
639
- data = await response.json();
640
- if (data.error && data.error_code === 429) {
733
+ }));
734
+ debugOutput(response.url, response.status, startTime);
735
+ if (response.status === 429) {
641
736
  try {
642
- await backoff.backOff();
737
+ data = await this.LIMIT(() => backoff.backOff(response.url));
643
738
  }
644
739
  catch (error) {
645
740
  success = true;
646
741
  return {
647
742
  data: null,
648
- error: data.error,
649
- error_code: data ? data.error_code : response.status,
650
- error_message: data ? data.error_message : "401 Authorization Required"
743
+ error: true,
744
+ error_code: response.status,
745
+ error_message: error.message
651
746
  };
652
747
  }
653
748
  }
654
749
  else {
655
- const dataClass = new NftCollectionAttributesForTraitResponse(data.data);
656
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
657
- success = true;
658
- return {
659
- data: dataClass,
660
- error: data.error,
661
- error_code: data ? data.error_code : response.status,
662
- error_message: data ? data.error_message : "401 Authorization Required"
663
- };
750
+ data = await response.json();
664
751
  }
752
+ const dataClass = new NftCollectionAttributesForTraitResponse(data.data);
753
+ checkAndModifyResponse(dataClass);
754
+ success = true;
755
+ return {
756
+ data: dataClass,
757
+ error: data.error,
758
+ error_code: data ? data.error_code : response.status,
759
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
760
+ };
665
761
  }
666
762
  catch (error) {
667
763
  success = true;
@@ -669,12 +765,14 @@ class NftService {
669
765
  data: null,
670
766
  error: true,
671
767
  error_code: data ? data.error_code : response.status,
672
- error_message: data ? data.error_message : "401 Authorization Required"
768
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
673
769
  };
674
770
  }
675
771
  }
676
772
  }
677
773
  /**
774
+ *
775
+ * Commonly used to calculate rarity scores for a collection based on its traits.
678
776
  *
679
777
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
680
778
  * @param {string} collectionContract - The requested collection address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -684,42 +782,47 @@ class NftService {
684
782
  let success = false;
685
783
  let data;
686
784
  let response;
687
- const backoff = new backoff_1.ExponentialBackoff();
785
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
688
786
  while (!success) {
689
787
  try {
690
788
  const urlParams = new URLSearchParams();
691
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
789
+ let startTime;
790
+ if (this.debug) {
791
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
792
+ }
793
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft/${collectionContract}/traits_summary/?${urlParams}`, {
692
794
  headers: {
693
795
  "Authorization": `Bearer ${this.apiKey}`,
694
- "X-Requested-With": Client_1.userAgent
796
+ "X-Requested-With": userAgent
695
797
  }
696
- });
697
- data = await response.json();
698
- if (data.error && data.error_code === 429) {
798
+ }));
799
+ debugOutput(response.url, response.status, startTime);
800
+ if (response.status === 429) {
699
801
  try {
700
- await backoff.backOff();
802
+ data = await this.LIMIT(() => backoff.backOff(response.url));
701
803
  }
702
804
  catch (error) {
703
805
  success = true;
704
806
  return {
705
807
  data: null,
706
- error: data.error,
707
- error_code: data ? data.error_code : response.status,
708
- error_message: data ? data.error_message : "401 Authorization Required"
808
+ error: true,
809
+ error_code: response.status,
810
+ error_message: error.message
709
811
  };
710
812
  }
711
813
  }
712
814
  else {
713
- const dataClass = new NftCollectionTraitSummaryResponse(data.data);
714
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
715
- success = true;
716
- return {
717
- data: dataClass,
718
- error: data.error,
719
- error_code: data ? data.error_code : response.status,
720
- error_message: data ? data.error_message : "401 Authorization Required"
721
- };
815
+ data = await response.json();
722
816
  }
817
+ const dataClass = new NftCollectionTraitSummaryResponse(data.data);
818
+ checkAndModifyResponse(dataClass);
819
+ success = true;
820
+ return {
821
+ data: dataClass,
822
+ error: data.error,
823
+ error_code: data ? data.error_code : response.status,
824
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
825
+ };
723
826
  }
724
827
  catch (error) {
725
828
  success = true;
@@ -727,12 +830,14 @@ class NftService {
727
830
  data: null,
728
831
  error: true,
729
832
  error_code: data ? data.error_code : response.status,
730
- error_message: data ? data.error_message : "401 Authorization Required"
833
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
731
834
  };
732
835
  }
733
836
  }
734
837
  }
735
838
  /**
839
+ *
840
+ * Commonly used to verify ownership of NFTs (including ERC-721 and ERC-1155) within a collection.
736
841
  *
737
842
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
738
843
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -743,42 +848,47 @@ class NftService {
743
848
  let success = false;
744
849
  let data;
745
850
  let response;
746
- const backoff = new backoff_1.ExponentialBackoff();
851
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
747
852
  while (!success) {
748
853
  try {
749
854
  const urlParams = new URLSearchParams();
750
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
855
+ let startTime;
856
+ if (this.debug) {
857
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
858
+ }
859
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/?${urlParams}`, {
751
860
  headers: {
752
861
  "Authorization": `Bearer ${this.apiKey}`,
753
- "X-Requested-With": Client_1.userAgent
862
+ "X-Requested-With": userAgent
754
863
  }
755
- });
756
- data = await response.json();
757
- if (data.error && data.error_code === 429) {
864
+ }));
865
+ debugOutput(response.url, response.status, startTime);
866
+ if (response.status === 429) {
758
867
  try {
759
- await backoff.backOff();
868
+ data = await this.LIMIT(() => backoff.backOff(response.url));
760
869
  }
761
870
  catch (error) {
762
871
  success = true;
763
872
  return {
764
873
  data: null,
765
- error: data.error,
766
- error_code: data ? data.error_code : response.status,
767
- error_message: data ? data.error_message : "401 Authorization Required"
874
+ error: true,
875
+ error_code: response.status,
876
+ error_message: error.message
768
877
  };
769
878
  }
770
879
  }
771
880
  else {
772
- const dataClass = new NftOwnershipForCollectionResponse(data.data);
773
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
774
- success = true;
775
- return {
776
- data: dataClass,
777
- error: data.error,
778
- error_code: data ? data.error_code : response.status,
779
- error_message: data ? data.error_message : "401 Authorization Required"
780
- };
881
+ data = await response.json();
781
882
  }
883
+ const dataClass = new NftOwnershipForCollectionResponse(data.data);
884
+ checkAndModifyResponse(dataClass);
885
+ success = true;
886
+ return {
887
+ data: dataClass,
888
+ error: data.error,
889
+ error_code: data ? data.error_code : response.status,
890
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
891
+ };
782
892
  }
783
893
  catch (error) {
784
894
  success = true;
@@ -786,12 +896,14 @@ class NftService {
786
896
  data: null,
787
897
  error: true,
788
898
  error_code: data ? data.error_code : response.status,
789
- error_message: data ? data.error_message : "401 Authorization Required"
899
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
790
900
  };
791
901
  }
792
902
  }
793
903
  }
794
904
  /**
905
+ *
906
+ * Commonly used to verify ownership of a specific token (ERC-721 or ERC-1155) within a collection.
795
907
  *
796
908
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
797
909
  * @param {string} walletAddress - The requested address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
@@ -803,42 +915,47 @@ class NftService {
803
915
  let success = false;
804
916
  let data;
805
917
  let response;
806
- const backoff = new backoff_1.ExponentialBackoff();
918
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
807
919
  while (!success) {
808
920
  try {
809
921
  const urlParams = new URLSearchParams();
810
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
922
+ let startTime;
923
+ if (this.debug) {
924
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
925
+ }
926
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/address/${walletAddress}/collection/${collectionContract}/token/${tokenId}/?${urlParams}`, {
811
927
  headers: {
812
928
  "Authorization": `Bearer ${this.apiKey}`,
813
- "X-Requested-With": Client_1.userAgent
929
+ "X-Requested-With": userAgent
814
930
  }
815
- });
816
- data = await response.json();
817
- if (data.error && data.error_code === 429) {
931
+ }));
932
+ debugOutput(response.url, response.status, startTime);
933
+ if (response.status === 429) {
818
934
  try {
819
- await backoff.backOff();
935
+ data = await this.LIMIT(() => backoff.backOff(response.url));
820
936
  }
821
937
  catch (error) {
822
938
  success = true;
823
939
  return {
824
940
  data: null,
825
- error: data.error,
826
- error_code: data ? data.error_code : response.status,
827
- error_message: data ? data.error_message : "401 Authorization Required"
941
+ error: true,
942
+ error_code: response.status,
943
+ error_message: error.message
828
944
  };
829
945
  }
830
946
  }
831
947
  else {
832
- const dataClass = new NftOwnershipForCollectionResponse(data.data);
833
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
834
- success = true;
835
- return {
836
- data: dataClass,
837
- error: data.error,
838
- error_code: data ? data.error_code : response.status,
839
- error_message: data ? data.error_message : "401 Authorization Required"
840
- };
948
+ data = await response.json();
841
949
  }
950
+ const dataClass = new NftOwnershipForCollectionResponse(data.data);
951
+ checkAndModifyResponse(dataClass);
952
+ success = true;
953
+ return {
954
+ data: dataClass,
955
+ error: data.error,
956
+ error_code: data ? data.error_code : response.status,
957
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
958
+ };
842
959
  }
843
960
  catch (error) {
844
961
  success = true;
@@ -846,58 +963,221 @@ class NftService {
846
963
  data: null,
847
964
  error: true,
848
965
  error_code: data ? data.error_code : response.status,
849
- error_message: data ? data.error_message : "401 Authorization Required"
966
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
850
967
  };
851
968
  }
852
969
  }
853
970
  }
854
971
  /**
972
+ *
973
+ * Commonly used to build a time-series chart of the sales count of an NFT collection.
855
974
  *
856
975
  * @param {string} chainName - The chain name eg: `eth-mainnet`.
857
976
  * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
858
- * @param {string} tokenId - The requested token ID.
977
+ * @param {GetNftMarketSaleCountQueryParamOpts} queryParamOpts
978
+ * - `days`: The number of days to return data for. Request up 365 days. Defaults to 30 days.
979
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
980
+ *
981
+ */
982
+ async getNftMarketSaleCount(chainName, contractAddress, queryParamOpts) {
983
+ let success = false;
984
+ let data;
985
+ let response;
986
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
987
+ while (!success) {
988
+ try {
989
+ const urlParams = new URLSearchParams();
990
+ if (queryParamOpts?.days !== undefined) {
991
+ urlParams.append("days", queryParamOpts?.days.toString());
992
+ }
993
+ if (queryParamOpts?.quoteCurrency !== undefined) {
994
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
995
+ }
996
+ let startTime;
997
+ if (this.debug) {
998
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
999
+ }
1000
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/sale_count/?${urlParams}`, {
1001
+ headers: {
1002
+ "Authorization": `Bearer ${this.apiKey}`,
1003
+ "X-Requested-With": userAgent
1004
+ }
1005
+ }));
1006
+ debugOutput(response.url, response.status, startTime);
1007
+ if (response.status === 429) {
1008
+ try {
1009
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1010
+ }
1011
+ catch (error) {
1012
+ success = true;
1013
+ return {
1014
+ data: null,
1015
+ error: true,
1016
+ error_code: response.status,
1017
+ error_message: error.message
1018
+ };
1019
+ }
1020
+ }
1021
+ else {
1022
+ data = await response.json();
1023
+ }
1024
+ const dataClass = new NftMarketSaleCountResponse(data.data);
1025
+ checkAndModifyResponse(dataClass);
1026
+ success = true;
1027
+ return {
1028
+ data: dataClass,
1029
+ error: data.error,
1030
+ error_code: data ? data.error_code : response.status,
1031
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1032
+ };
1033
+ }
1034
+ catch (error) {
1035
+ success = true;
1036
+ return {
1037
+ data: null,
1038
+ error: true,
1039
+ error_code: data ? data.error_code : response.status,
1040
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1041
+ };
1042
+ }
1043
+ }
1044
+ }
1045
+ /**
1046
+ *
1047
+ * Commonly used to build a time-series chart of the transaction volume of an NFT collection.
1048
+ *
1049
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1050
+ * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1051
+ * @param {GetNftMarketVolumeQueryParamOpts} queryParamOpts
1052
+ * - `days`: The number of days to return data for. Request up 365 days. Defaults to 30 days.
1053
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
1054
+ *
1055
+ */
1056
+ async getNftMarketVolume(chainName, contractAddress, queryParamOpts) {
1057
+ let success = false;
1058
+ let data;
1059
+ let response;
1060
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
1061
+ while (!success) {
1062
+ try {
1063
+ const urlParams = new URLSearchParams();
1064
+ if (queryParamOpts?.days !== undefined) {
1065
+ urlParams.append("days", queryParamOpts?.days.toString());
1066
+ }
1067
+ if (queryParamOpts?.quoteCurrency !== undefined) {
1068
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1069
+ }
1070
+ let startTime;
1071
+ if (this.debug) {
1072
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1073
+ }
1074
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/volume/?${urlParams}`, {
1075
+ headers: {
1076
+ "Authorization": `Bearer ${this.apiKey}`,
1077
+ "X-Requested-With": userAgent
1078
+ }
1079
+ }));
1080
+ debugOutput(response.url, response.status, startTime);
1081
+ if (response.status === 429) {
1082
+ try {
1083
+ data = await this.LIMIT(() => backoff.backOff(response.url));
1084
+ }
1085
+ catch (error) {
1086
+ success = true;
1087
+ return {
1088
+ data: null,
1089
+ error: true,
1090
+ error_code: response.status,
1091
+ error_message: error.message
1092
+ };
1093
+ }
1094
+ }
1095
+ else {
1096
+ data = await response.json();
1097
+ }
1098
+ const dataClass = new NftMarketVolumeResponse(data.data);
1099
+ checkAndModifyResponse(dataClass);
1100
+ success = true;
1101
+ return {
1102
+ data: dataClass,
1103
+ error: data.error,
1104
+ error_code: data ? data.error_code : response.status,
1105
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1106
+ };
1107
+ }
1108
+ catch (error) {
1109
+ success = true;
1110
+ return {
1111
+ data: null,
1112
+ error: true,
1113
+ error_code: data ? data.error_code : response.status,
1114
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1115
+ };
1116
+ }
1117
+ }
1118
+ }
1119
+ /**
1120
+ *
1121
+ * Commonly used to render a price floor chart for an NFT collection.
1122
+ *
1123
+ * @param {string} chainName - The chain name eg: `eth-mainnet`.
1124
+ * @param {string} contractAddress - The requested contract address. Passing in an `ENS`, `RNS`, `Lens Handle`, or an `Unstoppable Domain` resolves automatically.
1125
+ * @param {GetNftMarketFloorPriceQueryParamOpts} queryParamOpts
1126
+ * - `days`: The number of days to return data for. Request up 365 days. Defaults to 30 days.
1127
+ * - `quoteCurrency`: The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, and `GBP`.
859
1128
  *
860
1129
  */
861
- async getNftExternalMetadataForContract(chainName, contractAddress, tokenId) {
1130
+ async getNftMarketFloorPrice(chainName, contractAddress, queryParamOpts) {
862
1131
  let success = false;
863
1132
  let data;
864
1133
  let response;
865
- const backoff = new backoff_1.ExponentialBackoff();
1134
+ const backoff = new ExponentialBackoff(this.apiKey, this.debug);
866
1135
  while (!success) {
867
1136
  try {
868
1137
  const urlParams = new URLSearchParams();
869
- response = await fetch(`https://api.covalenthq.com/v1/${chainName}/tokens/${contractAddress}/nft_metadata/${tokenId}/?${urlParams}`, {
1138
+ if (queryParamOpts?.days !== undefined) {
1139
+ urlParams.append("days", queryParamOpts?.days.toString());
1140
+ }
1141
+ if (queryParamOpts?.quoteCurrency !== undefined) {
1142
+ urlParams.append("quote-currency", queryParamOpts?.quoteCurrency.toString());
1143
+ }
1144
+ let startTime;
1145
+ if (this.debug) {
1146
+ startTime = typeof performance !== 'undefined' ? performance.now() : process.hrtime();
1147
+ }
1148
+ response = await this.LIMIT(() => fetch(`https://api.covalenthq.com/v1/${chainName}/nft_market/${contractAddress}/floor_price/?${urlParams}`, {
870
1149
  headers: {
871
1150
  "Authorization": `Bearer ${this.apiKey}`,
872
- "X-Requested-With": Client_1.userAgent
1151
+ "X-Requested-With": userAgent
873
1152
  }
874
- });
875
- data = await response.json();
876
- if (data.error && data.error_code === 429) {
1153
+ }));
1154
+ debugOutput(response.url, response.status, startTime);
1155
+ if (response.status === 429) {
877
1156
  try {
878
- await backoff.backOff();
1157
+ data = await this.LIMIT(() => backoff.backOff(response.url));
879
1158
  }
880
1159
  catch (error) {
881
1160
  success = true;
882
1161
  return {
883
1162
  data: null,
884
- error: data.error,
885
- error_code: data ? data.error_code : response.status,
886
- error_message: data ? data.error_message : "401 Authorization Required"
1163
+ error: true,
1164
+ error_code: response.status,
1165
+ error_message: error.message
887
1166
  };
888
1167
  }
889
1168
  }
890
1169
  else {
891
- const dataClass = new NftMetadataResponse(data.data);
892
- (0, ApiHelpers_1.checkAndModifyResponse)(dataClass);
893
- success = true;
894
- return {
895
- data: dataClass,
896
- error: data.error,
897
- error_code: data ? data.error_code : response.status,
898
- error_message: data ? data.error_message : "401 Authorization Required"
899
- };
1170
+ data = await response.json();
900
1171
  }
1172
+ const dataClass = new NftMarketFloorPriceResponse(data.data);
1173
+ checkAndModifyResponse(dataClass);
1174
+ success = true;
1175
+ return {
1176
+ data: dataClass,
1177
+ error: data.error,
1178
+ error_code: data ? data.error_code : response.status,
1179
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
1180
+ };
901
1181
  }
902
1182
  catch (error) {
903
1183
  success = true;
@@ -905,11 +1185,10 @@ class NftService {
905
1185
  data: null,
906
1186
  error: true,
907
1187
  error_code: data ? data.error_code : response.status,
908
- error_message: data ? data.error_message : "401 Authorization Required"
1188
+ error_message: data ? data.error_message : response.status === 500 ? "Internal server error" : "401 Authorization Required"
909
1189
  };
910
1190
  }
911
1191
  }
912
1192
  }
913
1193
  }
914
- exports.NftService = NftService;
915
1194
  //# sourceMappingURL=NftService.js.map