@covalenthq/client-sdk 2.1.1 → 2.2.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 (28) hide show
  1. package/README.md +22 -6
  2. package/dist/cjs/index.d.ts +1 -0
  3. package/dist/cjs/index.js +172 -3
  4. package/dist/cjs/index.js.map +1 -1
  5. package/dist/cjs/src/GoldRushClient.d.ts +3 -1
  6. package/dist/cjs/src/services/AllChainsService.d.ts +26 -0
  7. package/dist/cjs/src/services/TransactionService.d.ts +1 -1
  8. package/dist/cjs/src/utils/functions/endpointGenerator.d.ts +1 -1
  9. package/dist/cjs/src/utils/functions/timestamp-parser.d.ts +1 -0
  10. package/dist/cjs/src/utils/types/AllChainService.types.d.ts +32 -0
  11. package/dist/cjs/src/utils/types/BaseService.types.d.ts +2 -0
  12. package/dist/cjs/src/utils/types/Generic.types.d.ts +8 -0
  13. package/dist/cjs/src/utils/types/PricingService.types.d.ts +3 -2
  14. package/dist/cjs/src/utils/types/TransactionService.types.d.ts +1 -0
  15. package/dist/esm/index.d.ts +1 -0
  16. package/dist/esm/index.js +172 -4
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/src/GoldRushClient.d.ts +3 -1
  19. package/dist/esm/src/services/AllChainsService.d.ts +26 -0
  20. package/dist/esm/src/services/TransactionService.d.ts +1 -1
  21. package/dist/esm/src/utils/functions/endpointGenerator.d.ts +1 -1
  22. package/dist/esm/src/utils/functions/timestamp-parser.d.ts +1 -0
  23. package/dist/esm/src/utils/types/AllChainService.types.d.ts +32 -0
  24. package/dist/esm/src/utils/types/BaseService.types.d.ts +2 -0
  25. package/dist/esm/src/utils/types/Generic.types.d.ts +8 -0
  26. package/dist/esm/src/utils/types/PricingService.types.d.ts +3 -2
  27. package/dist/esm/src/utils/types/TransactionService.types.d.ts +1 -0
  28. package/package.json +2 -2
package/README.md CHANGED
@@ -208,6 +208,14 @@ if (resp.data !== null) {
208
208
 
209
209
  You can explore more examples [here](./test/unit/is-valid-api-key.test.ts)
210
210
 
211
+ 5. **timestampParser**: Convert ISO timestamps to various human-readable formats
212
+
213
+ ```ts
214
+ timestampParser("2024-10-16T12:39:23.000Z", "descriptive"); // "October 16 2024 at 18:09:23"
215
+ ```
216
+
217
+ You can explore more examples [here](./test/unit/timestamp-parser.test.ts)
218
+
211
219
  ### 8. Standardized (Error) Responses
212
220
 
213
221
  All the responses are of the same standardized format
@@ -227,7 +235,15 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
227
235
 
228
236
  <details>
229
237
  <summary>
230
- 1. <strong>Security Service</strong>: Access to the token approvals API endpoints
238
+ 1. <strong>All Chains Service</strong>: Access to the data across multiple chains and addresses.
239
+ </summary>
240
+
241
+ - `getMultiChainAndMultiAddressTransactions()`: Fetch and render the transactions across multiple chains and addresses
242
+ </details>
243
+
244
+ <details>
245
+ <summary>
246
+ 2. <strong>Security Service</strong>: Access to the token approvals API endpoints
231
247
  </summary>
232
248
 
233
249
  - `getApprovals()`: Get a list of approvals across all ERC20 token contracts categorized by spenders for a wallet’s assets.
@@ -236,7 +252,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
236
252
 
237
253
  <details>
238
254
  <summary>
239
- 2. <strong>Balance Service</strong>: Access to the balances endpoints
255
+ 3. <strong>Balance Service</strong>: Access to the balances endpoints
240
256
  </summary>
241
257
 
242
258
  - `getTokenBalancesForWalletAddress()`: Fetch the native, fungible (ERC20), and non-fungible (ERC721 & ERC1155) tokens held by an address. Response includes spot prices and other metadata.
@@ -251,7 +267,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
251
267
 
252
268
  <details>
253
269
  <summary>
254
- 3. <strong>Balance Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
270
+ 4. <strong>Base Service</strong>: Access to the address activity, log events, chain status, and block retrieval endpoints
255
271
  </summary>
256
272
 
257
273
  - `getBlock()`: Fetch and render a single block for a block explorer.
@@ -271,7 +287,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
271
287
 
272
288
  <details>
273
289
  <summary>
274
- 4. <strong>NFT Service</strong>: Access to the NFT endpoints
290
+ 5. <strong>NFT Service</strong>: Access to the NFT endpoints
275
291
  </summary>
276
292
 
277
293
  - `getChainCollections()`: Used to fetch the list of NFT collections with downloaded and cached off chain data like token metadata and asset files. (Paginated)
@@ -290,7 +306,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
290
306
 
291
307
  <details>
292
308
  <summary>
293
- 5. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
309
+ 6. <strong>Pricing Service</strong>: Access to the historical token prices endpoint
294
310
  </summary>
295
311
 
296
312
  - `getTokenPrices()`: Get historic prices of a token between date ranges. Supports native tokens.
@@ -298,7 +314,7 @@ The Covalent SDK provides comprehensive support for all Class A, Class B, and Pr
298
314
 
299
315
  <details>
300
316
  <summary>
301
- 6. <strong>Transaction Service</strong>: Access to the transactions endpoints
317
+ 7. <strong>Transaction Service</strong>: Access to the transactions endpoints
302
318
  </summary>
303
319
 
304
320
  - `getAllTransactionsForAddress()`: Fetch and render the most recent transactions involving an address. Frequently seen in wallet applications. (Paginated)
@@ -3,6 +3,7 @@ export { bigIntParser } from "./src/utils/functions/bigIntParser";
3
3
  export { calculatePrettyBalance } from "./src/utils/functions/calculatePrettyBalance";
4
4
  export { isValidApiKey } from "./src/utils/functions/isValidApiKey";
5
5
  export { prettifyCurrency } from "./src/utils/functions/prettifyCurrency";
6
+ export { timestampParser } from "./src/utils/functions/timestamp-parser";
6
7
  export * from "./src/utils/types/BalanceService.types";
7
8
  export * from "./src/utils/types/BaseService.types";
8
9
  export * from "./src/utils/types/Generic.types";
package/dist/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var version = "2.1.1";
3
+ var version = "2.2.0";
4
4
 
5
5
  const bigIntParser = (val) => {
6
6
  if (val === null || val === undefined) {
@@ -27,6 +27,93 @@ const endpointGenerator = (extension = "", params = []) => {
27
27
  return new URL(`${baseUrl}/${extension}?${urlParams}`);
28
28
  };
29
29
 
30
+ /**
31
+ * Cross Chain API
32
+ *
33
+ */
34
+ class AllChainsService {
35
+ constructor(execution) {
36
+ this.execution = execution;
37
+ }
38
+ /**
39
+ *
40
+ * Commonly used to get transactions cross chains and addresses.
41
+ *
42
+ * @param {Chain[]} chains - An array of the chain names or IDs to retrieve transactions from. Defaults to all foundational chains.
43
+ * @param {string[]} addresses - An array of addresses for which transactions are fetched. Does not support name resolution.
44
+ * @param {number} limit - Number of transactions to return per page, up to the default max of 100 items.
45
+ * @param {string} before - Pagination cursor pointing to fetch transactions before a certain point.
46
+ * @param {string} after - Pagination cursor pointing to fetch transactions after a certain point.
47
+ * @param {boolean} withLogs - Whether to include raw logs in the response.
48
+ * @param {boolean} withDecodedLogs - Whether to include decoded logs in the response.
49
+ * @param {Quote | "BTC" | "ETH"} quoteCurrency - The currency to convert. Supports `USD`, `CAD`, `EUR`, `SGD`, `INR`, `JPY`, `VND`, `CNY`, `KRW`, `RUB`, `TRY`, `NGN`, `ARS`, `AUD`, `CHF`, `GBP`, "BTC" and "ETH".
50
+ *
51
+ */
52
+ async getMultiChainAndMultiAddressTransactions(queryParamOpts) {
53
+ const endpoint = endpointGenerator(`allchains/transactions`, [
54
+ {
55
+ key: "chains",
56
+ value: queryParamOpts?.chains,
57
+ },
58
+ {
59
+ key: "addresses",
60
+ value: queryParamOpts?.addresses,
61
+ },
62
+ {
63
+ key: "limit",
64
+ value: queryParamOpts?.limit,
65
+ },
66
+ {
67
+ key: "before",
68
+ value: queryParamOpts?.before,
69
+ },
70
+ {
71
+ key: "after",
72
+ value: queryParamOpts?.after,
73
+ },
74
+ {
75
+ key: "with-logs",
76
+ value: queryParamOpts?.withLogs,
77
+ },
78
+ {
79
+ key: "with-decoded-logs",
80
+ value: queryParamOpts?.withDecodedLogs,
81
+ },
82
+ {
83
+ key: "quote-currency",
84
+ value: queryParamOpts?.quoteCurrency,
85
+ },
86
+ ]);
87
+ const parseData = (data) => {
88
+ if (data.data) {
89
+ data.data.updated_at = data.data.updated_at
90
+ ? new Date(data.data.updated_at)
91
+ : null;
92
+ data.data.items = data.data.items
93
+ ? data.data.items.map((txItem) => ({
94
+ ...txItem,
95
+ value: bigIntParser(txItem.value),
96
+ fees_paid: bigIntParser(txItem.fees_paid),
97
+ block_signed_at: txItem.block_signed_at
98
+ ? new Date(txItem.block_signed_at)
99
+ : null,
100
+ log_events: txItem.log_events
101
+ ? txItem.log_events.map((logItem) => ({
102
+ ...logItem,
103
+ block_signed_at: logItem.block_signed_at
104
+ ? new Date(logItem.block_signed_at)
105
+ : null,
106
+ }))
107
+ : null,
108
+ }))
109
+ : null;
110
+ }
111
+ return data;
112
+ };
113
+ return await this.execution.execute(endpoint, parseData);
114
+ }
115
+ }
116
+
30
117
  async function* paginateEndpoint(endpoint, execution, parseData, implementation) {
31
118
  let _endpoint = new URL(endpoint);
32
119
  let hasMore = true;
@@ -178,8 +265,8 @@ class BalanceService {
178
265
  ...portfolioItem,
179
266
  holdings: portfolioItem.holdings?.map((holdingItem) => ({
180
267
  ...holdingItem,
181
- timestamp: holdingItem.timestamp && data.data?.updated_at
182
- ? new Date(data.data.updated_at)
268
+ timestamp: holdingItem.timestamp
269
+ ? new Date(holdingItem.timestamp)
183
270
  : null,
184
271
  close: {
185
272
  ...holdingItem.close,
@@ -2518,6 +2605,7 @@ class GoldRushClient {
2518
2605
  ? `${settings.source} (${this.userAgent})`
2519
2606
  : this.userAgent,
2520
2607
  });
2608
+ this.AllChainsService = new AllChainsService(execution);
2521
2609
  this.BalanceService = new BalanceService(execution);
2522
2610
  this.BaseService = new BaseService(execution);
2523
2611
  this.NftService = new NftService(execution);
@@ -3622,6 +3710,86 @@ const prettifyCurrency = (value, decimals = 2, currency = "USD", ignoreSmallValu
3622
3710
  return minus + formattedValue + currencySuffix;
3623
3711
  };
3624
3712
 
3713
+ const months = [
3714
+ "January",
3715
+ "February",
3716
+ "March",
3717
+ "April",
3718
+ "May",
3719
+ "June",
3720
+ "July",
3721
+ "August",
3722
+ "September",
3723
+ "October",
3724
+ "November",
3725
+ "December",
3726
+ ];
3727
+ const timestampParser = (timestamp, type) => {
3728
+ const _unix = new Date(timestamp);
3729
+ switch (type) {
3730
+ case "descriptive": {
3731
+ const _minutes = _unix.getMinutes();
3732
+ const _hours = _unix.getHours();
3733
+ const _seconds = _unix.getSeconds();
3734
+ const _parsedSeconds = `${_seconds <= 9 ? "0" : ""}${_seconds}`;
3735
+ const _parsedMinutes = `${_minutes <= 9 ? "0" : ""}${_minutes}`;
3736
+ const _parsedHours = `${_hours <= 9 ? "0" : ""}${_hours}`;
3737
+ return `${months[_unix.getMonth()]} ${_unix.getDate()} ${_unix.getFullYear()} at ${_parsedHours}:${_parsedMinutes}:${_parsedSeconds}`;
3738
+ }
3739
+ case "DD MMM YY": {
3740
+ const day = _unix.getDate().toString().padStart(2, "0");
3741
+ const month = months[_unix.getMonth()].substring(0, 3);
3742
+ const year = _unix.getFullYear();
3743
+ return `${day} ${month} ${year}`;
3744
+ }
3745
+ case "relative": {
3746
+ const currentTime = new Date();
3747
+ const unixTime = new Date(_unix);
3748
+ const timeDifference = currentTime.getTime() - unixTime.getTime();
3749
+ const secondsDifference = Math.floor(timeDifference / 1000);
3750
+ const minutesDifference = Math.floor(secondsDifference / 60);
3751
+ const hoursDifference = Math.floor(minutesDifference / 60);
3752
+ const daysDifference = Math.floor(hoursDifference / 24);
3753
+ const monthsDifference = Math.floor(daysDifference / 30);
3754
+ const yearsDifference = Math.floor(daysDifference / 365);
3755
+ if (yearsDifference > 0) {
3756
+ return `${yearsDifference} year${yearsDifference > 1 ? "s" : ""} ago`;
3757
+ }
3758
+ else if (monthsDifference > 0) {
3759
+ return `${monthsDifference} month${monthsDifference > 1 ? "s" : ""} ago`;
3760
+ }
3761
+ else if (daysDifference > 0) {
3762
+ return `${daysDifference} day${daysDifference > 1 ? "s" : ""} ago`;
3763
+ }
3764
+ else if (hoursDifference > 0) {
3765
+ return `${hoursDifference} hour${hoursDifference > 1 ? "s" : ""} ago`;
3766
+ }
3767
+ else if (minutesDifference > 0) {
3768
+ return `${minutesDifference} minute${minutesDifference > 1 ? "s" : ""} ago`;
3769
+ }
3770
+ else if (secondsDifference > 0) {
3771
+ return `${secondsDifference} second${secondsDifference > 1 ? "s" : ""} ago`;
3772
+ }
3773
+ else {
3774
+ return `just now`;
3775
+ }
3776
+ }
3777
+ case "YYYY-MM-DD": {
3778
+ const offsetMinutes = _unix.getTimezoneOffset();
3779
+ const offsetMilliseconds = offsetMinutes * 60 * 1000;
3780
+ const utcTime = _unix.getTime() + offsetMilliseconds;
3781
+ const _utc_unix = new Date(utcTime);
3782
+ const year = _utc_unix.getFullYear();
3783
+ const month = String(_utc_unix.getMonth() + 1).padStart(2, "0");
3784
+ const day = String(_utc_unix.getDate()).padStart(2, "0");
3785
+ return `${year}-${month}-${day}`;
3786
+ }
3787
+ default: {
3788
+ return _unix.toISOString();
3789
+ }
3790
+ }
3791
+ };
3792
+
3625
3793
  exports.ChainName = void 0;
3626
3794
  (function (ChainName) {
3627
3795
  ChainName["ETH_MAINNET"] = "eth-mainnet";
@@ -3962,4 +4130,5 @@ exports.bigIntParser = bigIntParser;
3962
4130
  exports.calculatePrettyBalance = calculatePrettyBalance;
3963
4131
  exports.isValidApiKey = isValidApiKey;
3964
4132
  exports.prettifyCurrency = prettifyCurrency;
4133
+ exports.timestampParser = timestampParser;
3965
4134
  //# sourceMappingURL=index.js.map