@human-protocol/sdk 5.2.0 → 6.0.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 (63) hide show
  1. package/dist/base.d.ts +4 -5
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +4 -5
  4. package/dist/constants.js +6 -6
  5. package/dist/encryption.d.ts +68 -203
  6. package/dist/encryption.d.ts.map +1 -1
  7. package/dist/encryption.js +66 -202
  8. package/dist/error.d.ts +0 -24
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +2 -26
  11. package/dist/escrow.d.ts +427 -780
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +314 -684
  14. package/dist/graphql/queries/operator.d.ts.map +1 -1
  15. package/dist/graphql/queries/operator.js +3 -1
  16. package/dist/graphql/types.d.ts.map +1 -1
  17. package/dist/index.d.ts +3 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -4
  20. package/dist/kvstore.d.ts +119 -181
  21. package/dist/kvstore.d.ts.map +1 -1
  22. package/dist/kvstore.js +119 -182
  23. package/dist/operator.d.ts +59 -30
  24. package/dist/operator.d.ts.map +1 -1
  25. package/dist/operator.js +59 -30
  26. package/dist/staking.d.ts +135 -134
  27. package/dist/staking.d.ts.map +1 -1
  28. package/dist/staking.js +135 -134
  29. package/dist/statistics.d.ts +104 -134
  30. package/dist/statistics.d.ts.map +1 -1
  31. package/dist/statistics.js +119 -144
  32. package/dist/transaction.d.ts +36 -15
  33. package/dist/transaction.d.ts.map +1 -1
  34. package/dist/transaction.js +36 -15
  35. package/dist/types.d.ts +0 -54
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/utils.d.ts +31 -17
  38. package/dist/utils.d.ts.map +1 -1
  39. package/dist/utils.js +31 -17
  40. package/dist/worker.d.ts +35 -14
  41. package/dist/worker.d.ts.map +1 -1
  42. package/dist/worker.js +35 -14
  43. package/package.json +7 -24
  44. package/src/base.ts +4 -5
  45. package/src/constants.ts +6 -6
  46. package/src/encryption.ts +69 -203
  47. package/src/error.ts +0 -36
  48. package/src/escrow.ts +425 -780
  49. package/src/graphql/queries/operator.ts +3 -1
  50. package/src/graphql/types.ts +4 -2
  51. package/src/index.ts +4 -5
  52. package/src/kvstore.ts +120 -183
  53. package/src/operator.ts +59 -30
  54. package/src/staking.ts +135 -134
  55. package/src/statistics.ts +125 -146
  56. package/src/transaction.ts +36 -15
  57. package/src/types.ts +0 -57
  58. package/src/utils.ts +31 -17
  59. package/src/worker.ts +35 -14
  60. package/dist/storage.d.ts +0 -186
  61. package/dist/storage.d.ts.map +0 -1
  62. package/dist/storage.js +0 -319
  63. package/src/storage.ts +0 -313
@@ -1,52 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StatisticsClient = void 0;
3
+ exports.StatisticsUtils = void 0;
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
5
  const enums_1 = require("./enums");
6
6
  const graphql_1 = require("./graphql");
7
7
  const utils_1 = require("./utils");
8
8
  /**
9
- * ## Introduction
9
+ * Utility class for statistics-related queries.
10
10
  *
11
- * This client enables obtaining statistical information from the subgraph.
12
- *
13
- * Unlike other SDK clients, `StatisticsClient` does not require `signer` or `provider` to be provided.
14
- * We just need to create a client object using relevant network data.
15
- *
16
- * ```ts
17
- * constructor(network: NetworkData)
18
- * ```
19
- *
20
- * ## Installation
21
- *
22
- * ### npm
23
- * ```bash
24
- * npm install @human-protocol/sdk
25
- * ```
26
- *
27
- * ### yarn
28
- * ```bash
29
- * yarn install @human-protocol/sdk
30
- * ```
31
- *
32
- * ## Code example
11
+ * Unlike other SDK clients, `StatisticsUtils` does not require `signer` or `provider` to be provided.
12
+ * We just need to pass the network data to each static method.
33
13
  *
14
+ * @example
34
15
  * ```ts
35
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
16
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
36
17
  *
37
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
18
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
19
+ * const escrowStats = await StatisticsUtils.getEscrowStatistics(networkData);
20
+ * console.log('Total escrows:', escrowStats.totalEscrows);
38
21
  * ```
39
22
  */
40
- class StatisticsClient {
41
- /**
42
- * **StatisticsClient constructor**
43
- *
44
- * @param {NetworkData} networkData - The network information required to connect to the Statistics contract
45
- */
46
- constructor(networkData) {
47
- this.networkData = networkData;
48
- this.subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
49
- }
23
+ class StatisticsUtils {
50
24
  /**
51
25
  * This function returns the statistical data of escrows.
52
26
  *
@@ -78,31 +52,37 @@ class StatisticsClient {
78
52
  * };
79
53
  * ```
80
54
  *
81
- * @param {IStatisticsFilter} filter Statistics params with duration data
82
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
83
- * @returns {Promise<IEscrowStatistics>} Escrow statistics data.
84
- *
85
- * **Code example**
55
+ * @param networkData - The network information required to connect to the subgraph
56
+ * @param filter - Statistics params with duration data
57
+ * @param options - Optional configuration for subgraph requests.
58
+ * @returns Escrow statistics data.
86
59
  *
60
+ * @example
87
61
  * ```ts
88
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
89
- *
90
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
91
- *
92
- * const escrowStatistics = await statisticsClient.getEscrowStatistics();
93
- * const escrowStatisticsApril = await statisticsClient.getEscrowStatistics({
94
- * from: new Date('2021-04-01'),
95
- * to: new Date('2021-04-30'),
96
- * });
62
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
63
+ *
64
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
65
+ * const escrowStats = await StatisticsUtils.getEscrowStatistics(networkData);
66
+ * console.log('Total escrows:', escrowStats.totalEscrows);
67
+ *
68
+ * const escrowStatsApril = await StatisticsUtils.getEscrowStatistics(
69
+ * networkData,
70
+ * {
71
+ * from: new Date('2021-04-01'),
72
+ * to: new Date('2021-04-30'),
73
+ * }
74
+ * );
75
+ * console.log('April escrows:', escrowStatsApril.totalEscrows);
97
76
  * ```
98
77
  */
99
- async getEscrowStatistics(filter = {}, options) {
78
+ static async getEscrowStatistics(networkData, filter = {}, options) {
100
79
  try {
80
+ const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
101
81
  const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
102
82
  const skip = filter.skip || 0;
103
83
  const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
104
- const { escrowStatistics } = await (0, utils_1.customGqlFetch)(this.subgraphUrl, graphql_1.GET_ESCROW_STATISTICS_QUERY, options);
105
- const { eventDayDatas } = await (0, utils_1.customGqlFetch)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
84
+ const { escrowStatistics } = await (0, utils_1.customGqlFetch)(subgraphUrl, graphql_1.GET_ESCROW_STATISTICS_QUERY, options);
85
+ const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
106
86
  from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
107
87
  to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
108
88
  orderDirection: orderDirection,
@@ -153,30 +133,36 @@ class StatisticsClient {
153
133
  * };
154
134
  * ```
155
135
  *
156
- * @param {IStatisticsFilter} filter Statistics params with duration data
157
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
158
- * @returns {Promise<IWorkerStatistics>} Worker statistics data.
159
- *
160
- * **Code example**
136
+ * @param networkData - The network information required to connect to the subgraph
137
+ * @param filter - Statistics params with duration data
138
+ * @param options - Optional configuration for subgraph requests.
139
+ * @returns Worker statistics data.
161
140
  *
141
+ * @example
162
142
  * ```ts
163
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
164
- *
165
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
166
- *
167
- * const workerStatistics = await statisticsClient.getWorkerStatistics();
168
- * const workerStatisticsApril = await statisticsClient.getWorkerStatistics({
169
- * from: new Date('2021-04-01'),
170
- * to: new Date('2021-04-30'),
171
- * });
143
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
144
+ *
145
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
146
+ * const workerStats = await StatisticsUtils.getWorkerStatistics(networkData);
147
+ * console.log('Daily workers data:', workerStats.dailyWorkersData);
148
+ *
149
+ * const workerStatsApril = await StatisticsUtils.getWorkerStatistics(
150
+ * networkData,
151
+ * {
152
+ * from: new Date('2021-04-01'),
153
+ * to: new Date('2021-04-30'),
154
+ * }
155
+ * );
156
+ * console.log('April workers:', workerStatsApril.dailyWorkersData.length);
172
157
  * ```
173
158
  */
174
- async getWorkerStatistics(filter = {}, options) {
159
+ static async getWorkerStatistics(networkData, filter = {}, options) {
175
160
  try {
161
+ const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
176
162
  const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
177
163
  const skip = filter.skip || 0;
178
164
  const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
179
- const { eventDayDatas } = await (0, utils_1.customGqlFetch)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
165
+ const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
180
166
  from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
181
167
  to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
182
168
  orderDirection: orderDirection,
@@ -222,51 +208,43 @@ class StatisticsClient {
222
208
  * };
223
209
  * ```
224
210
  *
225
- * @param {IStatisticsFilter} filter Statistics params with duration data
226
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
227
- * @returns {Promise<IPaymentStatistics>} Payment statistics data.
228
- *
229
- * **Code example**
211
+ * @param networkData - The network information required to connect to the subgraph
212
+ * @param filter - Statistics params with duration data
213
+ * @param options - Optional configuration for subgraph requests.
214
+ * @returns Payment statistics data.
230
215
  *
216
+ * @example
231
217
  * ```ts
232
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
233
- *
234
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
218
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
235
219
  *
220
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
221
+ * const paymentStats = await StatisticsUtils.getPaymentStatistics(networkData);
236
222
  * console.log(
237
223
  * 'Payment statistics:',
238
- * (await statisticsClient.getPaymentStatistics()).dailyPaymentsData.map(
239
- * (p) => ({
240
- * ...p,
241
- * totalAmountPaid: p.totalAmountPaid.toString(),
242
- * averageAmountPerJob: p.averageAmountPerJob.toString(),
243
- * averageAmountPerWorker: p.averageAmountPerWorker.toString(),
244
- * })
245
- * )
246
- * );
247
- *
248
- * console.log(
249
- * 'Payment statistics from 5/8 - 6/8:',
250
- * (
251
- * await statisticsClient.getPaymentStatistics({
252
- * from: new Date(2023, 4, 8),
253
- * to: new Date(2023, 5, 8),
254
- * })
255
- * ).dailyPaymentsData.map((p) => ({
224
+ * paymentStats.dailyPaymentsData.map((p) => ({
256
225
  * ...p,
257
226
  * totalAmountPaid: p.totalAmountPaid.toString(),
258
- * averageAmountPerJob: p.averageAmountPerJob.toString(),
259
227
  * averageAmountPerWorker: p.averageAmountPerWorker.toString(),
260
228
  * }))
261
229
  * );
230
+ *
231
+ * const paymentStatsRange = await StatisticsUtils.getPaymentStatistics(
232
+ * networkData,
233
+ * {
234
+ * from: new Date(2023, 4, 8),
235
+ * to: new Date(2023, 5, 8),
236
+ * }
237
+ * );
238
+ * console.log('Payment statistics from 5/8 - 6/8:', paymentStatsRange.dailyPaymentsData.length);
262
239
  * ```
263
240
  */
264
- async getPaymentStatistics(filter = {}, options) {
241
+ static async getPaymentStatistics(networkData, filter = {}, options) {
265
242
  try {
243
+ const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
266
244
  const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
267
245
  const skip = filter.skip || 0;
268
246
  const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
269
- const { eventDayDatas } = await (0, utils_1.customGqlFetch)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
247
+ const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
270
248
  from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
271
249
  to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
272
250
  orderDirection: orderDirection,
@@ -300,27 +278,26 @@ class StatisticsClient {
300
278
  * };
301
279
  * ```
302
280
  *
303
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
304
- * @returns {Promise<IHMTStatistics>} HMToken statistics data.
305
- *
306
- * **Code example**
281
+ * @param networkData - The network information required to connect to the subgraph
282
+ * @param options - Optional configuration for subgraph requests.
283
+ * @returns HMToken statistics data.
307
284
  *
285
+ * @example
308
286
  * ```ts
309
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
310
- *
311
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
312
- *
313
- * const hmtStatistics = await statisticsClient.getHMTStatistics();
287
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
314
288
  *
289
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
290
+ * const hmtStats = await StatisticsUtils.getHMTStatistics(networkData);
315
291
  * console.log('HMT statistics:', {
316
- * ...hmtStatistics,
317
- * totalTransferAmount: hmtStatistics.totalTransferAmount.toString(),
292
+ * ...hmtStats,
293
+ * totalTransferAmount: hmtStats.totalTransferAmount.toString(),
318
294
  * });
319
295
  * ```
320
296
  */
321
- async getHMTStatistics(options) {
297
+ static async getHMTStatistics(networkData, options) {
322
298
  try {
323
- const { hmtokenStatistics } = await (0, utils_1.customGqlFetch)(this.subgraphUrl, graphql_1.GET_HMTOKEN_STATISTICS_QUERY, options);
299
+ const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
300
+ const { hmtokenStatistics } = await (0, utils_1.customGqlFetch)(subgraphUrl, graphql_1.GET_HMTOKEN_STATISTICS_QUERY, options);
324
301
  return {
325
302
  totalTransferAmount: BigInt(hmtokenStatistics.totalValueTransfered),
326
303
  totalTransferCount: +hmtokenStatistics.totalTransferEventCount,
@@ -334,34 +311,31 @@ class StatisticsClient {
334
311
  /**
335
312
  * This function returns the holders of the HMToken with optional filters and ordering.
336
313
  *
337
- * **Input parameters**
338
- *
339
- * @param {IHMTHoldersParams} params HMT Holders params with filters and ordering
340
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
341
- * @returns {Promise<IHMTHolder[]>} List of HMToken holders.
342
- *
343
- * **Code example**
314
+ * @param networkData - The network information required to connect to the subgraph
315
+ * @param params - HMT Holders params with filters and ordering
316
+ * @param options - Optional configuration for subgraph requests.
317
+ * @returns List of HMToken holders.
344
318
  *
319
+ * @example
345
320
  * ```ts
346
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
321
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
347
322
  *
348
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
349
- *
350
- * const hmtHolders = await statisticsClient.getHMTHolders({
323
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
324
+ * const hmtHolders = await StatisticsUtils.getHMTHolders(networkData, {
351
325
  * orderDirection: 'asc',
352
326
  * });
353
- *
354
327
  * console.log('HMT holders:', hmtHolders.map((h) => ({
355
328
  * ...h,
356
329
  * balance: h.balance.toString(),
357
330
  * })));
358
331
  * ```
359
332
  */
360
- async getHMTHolders(params = {}, options) {
333
+ static async getHMTHolders(networkData, params = {}, options) {
361
334
  try {
335
+ const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
362
336
  const { address, orderDirection } = params;
363
337
  const query = (0, graphql_1.GET_HOLDERS_QUERY)(address);
364
- const { holders } = await (0, utils_1.customGqlFetch)(this.subgraphUrl, query, {
338
+ const { holders } = await (0, utils_1.customGqlFetch)(subgraphUrl, query, {
365
339
  address,
366
340
  orderBy: 'balance',
367
341
  orderDirection,
@@ -400,35 +374,36 @@ class StatisticsClient {
400
374
  * }
401
375
  * ```
402
376
  *
403
- * @param {IStatisticsFilter} filter Statistics params with duration data
404
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
405
- * @returns {Promise<IDailyHMT[]>} Daily HMToken statistics data.
406
- *
407
- * **Code example**
377
+ * @param networkData - The network information required to connect to the subgraph
378
+ * @param filter - Statistics params with duration data
379
+ * @param options - Optional configuration for subgraph requests.
380
+ * @returns Daily HMToken statistics data.
408
381
  *
382
+ * @example
409
383
  * ```ts
410
- * import { StatisticsClient, ChainId, NETWORKS } from '@human-protocol/sdk';
411
- *
412
- * const statisticsClient = new StatisticsClient(NETWORKS[ChainId.POLYGON_AMOY]);
413
- *
414
- * const dailyHMTStats = await statisticsClient.getHMTStatistics();
384
+ * import { StatisticsUtils, ChainId, NETWORKS } from '@human-protocol/sdk';
415
385
  *
386
+ * const networkData = NETWORKS[ChainId.POLYGON_AMOY];
387
+ * const dailyHMTStats = await StatisticsUtils.getHMTDailyData(networkData);
416
388
  * console.log('Daily HMT statistics:', dailyHMTStats);
417
389
  *
418
- * const hmtStatisticsRange = await statisticsClient.getHMTStatistics({
419
- * from: new Date(2023, 4, 8),
420
- * to: new Date(2023, 5, 8),
421
- * });
422
- *
423
- * console.log('HMT statistics from 5/8 - 6/8:', hmtStatisticsRange);
390
+ * const hmtStatsRange = await StatisticsUtils.getHMTDailyData(
391
+ * networkData,
392
+ * {
393
+ * from: new Date(2023, 4, 8),
394
+ * to: new Date(2023, 5, 8),
395
+ * }
396
+ * );
397
+ * console.log('HMT statistics from 5/8 - 6/8:', hmtStatsRange.length);
424
398
  * ```
425
399
  */
426
- async getHMTDailyData(filter = {}, options) {
400
+ static async getHMTDailyData(networkData, filter = {}, options) {
427
401
  try {
402
+ const subgraphUrl = (0, utils_1.getSubgraphUrl)(networkData);
428
403
  const first = filter.first !== undefined ? Math.min(filter.first, 1000) : 10;
429
404
  const skip = filter.skip || 0;
430
405
  const orderDirection = filter.orderDirection || enums_1.OrderDirection.ASC;
431
- const { eventDayDatas } = await (0, utils_1.customGqlFetch)(this.subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
406
+ const { eventDayDatas } = await (0, utils_1.customGqlFetch)(subgraphUrl, (0, graphql_1.GET_EVENT_DAY_DATA_QUERY)(filter), {
432
407
  from: filter.from ? (0, utils_1.getUnixTimestamp)(filter.from) : undefined,
433
408
  to: filter.to ? (0, utils_1.getUnixTimestamp)(filter.to) : undefined,
434
409
  orderDirection: orderDirection,
@@ -448,4 +423,4 @@ class StatisticsClient {
448
423
  }
449
424
  }
450
425
  }
451
- exports.StatisticsClient = StatisticsClient;
426
+ exports.StatisticsUtils = StatisticsUtils;
@@ -1,5 +1,19 @@
1
1
  import { ChainId } from './enums';
2
2
  import { ITransaction, ITransactionsFilter, SubgraphOptions } from './interfaces';
3
+ /**
4
+ * Utility class for transaction-related queries.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
9
+ *
10
+ * const transaction = await TransactionUtils.getTransaction(
11
+ * ChainId.POLYGON_AMOY,
12
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
13
+ * );
14
+ * console.log('Transaction:', transaction);
15
+ * ```
16
+ */
3
17
  export declare class TransactionUtils {
4
18
  /**
5
19
  * This function returns the transaction data for the given hash.
@@ -32,17 +46,22 @@ export declare class TransactionUtils {
32
46
  * };
33
47
  * ```
34
48
  *
35
- * @param {ChainId} chainId The chain ID.
36
- * @param {string} hash The transaction hash.
37
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
38
- * @returns {Promise<ITransaction | null>} - Returns the transaction details or null if not found.
39
- *
40
- * **Code example**
49
+ * @param chainId - The chain ID.
50
+ * @param hash - The transaction hash.
51
+ * @param options - Optional configuration for subgraph requests.
52
+ * @returns Returns the transaction details or null if not found.
53
+ * @throws ErrorInvalidHashProvided If the hash is invalid
54
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
41
55
  *
56
+ * @example
42
57
  * ```ts
43
58
  * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
44
59
  *
45
- * const transaction = await TransactionUtils.getTransaction(ChainId.POLYGON, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
60
+ * const transaction = await TransactionUtils.getTransaction(
61
+ * ChainId.POLYGON_AMOY,
62
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
63
+ * );
64
+ * console.log('Transaction:', transaction);
46
65
  * ```
47
66
  */
48
67
  static getTransaction(chainId: ChainId, hash: string, options?: SubgraphOptions): Promise<ITransaction | null>;
@@ -69,7 +88,7 @@ export declare class TransactionUtils {
69
88
  * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
70
89
  * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
71
90
  * }
72
- *
91
+ * ```
73
92
  *
74
93
  * ```ts
75
94
  * type InternalTransaction = {
@@ -99,17 +118,18 @@ export declare class TransactionUtils {
99
118
  * };
100
119
  * ```
101
120
  *
102
- * @param {ITransactionsFilter} filter Filter for the transactions.
103
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
104
- * @returns {Promise<ITransaction[]>} Returns an array with all the transaction details.
105
- *
106
- * **Code example**
121
+ * @param filter - Filter for the transactions.
122
+ * @param options - Optional configuration for subgraph requests.
123
+ * @returns Returns an array with all the transaction details.
124
+ * @throws ErrorCannotUseDateAndBlockSimultaneously If both date and block filters are used
125
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
107
126
  *
127
+ * @example
108
128
  * ```ts
109
129
  * import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
110
130
  *
111
- * const filter: ITransactionsFilter = {
112
- * chainId: ChainId.POLYGON,
131
+ * const filter = {
132
+ * chainId: ChainId.POLYGON_AMOY,
113
133
  * startDate: new Date('2022-01-01'),
114
134
  * endDate: new Date('2022-12-31'),
115
135
  * first: 10,
@@ -117,6 +137,7 @@ export declare class TransactionUtils {
117
137
  * orderDirection: OrderDirection.DESC,
118
138
  * };
119
139
  * const transactions = await TransactionUtils.getTransactions(filter);
140
+ * console.log('Transactions:', transactions.length);
120
141
  * ```
121
142
  */
122
143
  static getTransactions(filter: ITransactionsFilter, options?: SubgraphOptions): Promise<ITransaction[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAWlD,OAAO,EAEL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EAChB,MAAM,cAAc,CAAC;AAGtB,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAyB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwEG;WACiB,eAAe,CACjC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,EAAE,CAAC;CAgD3B"}
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../src/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAWlD,OAAO,EAEL,YAAY,EACZ,mBAAmB,EACnB,eAAe,EAChB,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;WACiB,cAAc,CAChC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAyB/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA0EG;WACiB,eAAe,CACjC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,YAAY,EAAE,CAAC;CAgD3B"}
@@ -7,6 +7,20 @@ const enums_1 = require("./enums");
7
7
  const error_1 = require("./error");
8
8
  const transaction_1 = require("./graphql/queries/transaction");
9
9
  const utils_1 = require("./utils");
10
+ /**
11
+ * Utility class for transaction-related queries.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
16
+ *
17
+ * const transaction = await TransactionUtils.getTransaction(
18
+ * ChainId.POLYGON_AMOY,
19
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
20
+ * );
21
+ * console.log('Transaction:', transaction);
22
+ * ```
23
+ */
10
24
  class TransactionUtils {
11
25
  /**
12
26
  * This function returns the transaction data for the given hash.
@@ -39,17 +53,22 @@ class TransactionUtils {
39
53
  * };
40
54
  * ```
41
55
  *
42
- * @param {ChainId} chainId The chain ID.
43
- * @param {string} hash The transaction hash.
44
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
45
- * @returns {Promise<ITransaction | null>} - Returns the transaction details or null if not found.
46
- *
47
- * **Code example**
56
+ * @param chainId - The chain ID.
57
+ * @param hash - The transaction hash.
58
+ * @param options - Optional configuration for subgraph requests.
59
+ * @returns Returns the transaction details or null if not found.
60
+ * @throws ErrorInvalidHashProvided If the hash is invalid
61
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
48
62
  *
63
+ * @example
49
64
  * ```ts
50
65
  * import { TransactionUtils, ChainId } from '@human-protocol/sdk';
51
66
  *
52
- * const transaction = await TransactionUtils.getTransaction(ChainId.POLYGON, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
67
+ * const transaction = await TransactionUtils.getTransaction(
68
+ * ChainId.POLYGON_AMOY,
69
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
70
+ * );
71
+ * console.log('Transaction:', transaction);
53
72
  * ```
54
73
  */
55
74
  static async getTransaction(chainId, hash, options) {
@@ -90,7 +109,7 @@ class TransactionUtils {
90
109
  * skip?: number; // (Optional) Number of transactions to skip. Default is 0.
91
110
  * orderDirection?: OrderDirection; // (Optional) Order of the results. Default is DESC.
92
111
  * }
93
- *
112
+ * ```
94
113
  *
95
114
  * ```ts
96
115
  * type InternalTransaction = {
@@ -120,17 +139,18 @@ class TransactionUtils {
120
139
  * };
121
140
  * ```
122
141
  *
123
- * @param {ITransactionsFilter} filter Filter for the transactions.
124
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
125
- * @returns {Promise<ITransaction[]>} Returns an array with all the transaction details.
126
- *
127
- * **Code example**
142
+ * @param filter - Filter for the transactions.
143
+ * @param options - Optional configuration for subgraph requests.
144
+ * @returns Returns an array with all the transaction details.
145
+ * @throws ErrorCannotUseDateAndBlockSimultaneously If both date and block filters are used
146
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
128
147
  *
148
+ * @example
129
149
  * ```ts
130
150
  * import { TransactionUtils, ChainId, OrderDirection } from '@human-protocol/sdk';
131
151
  *
132
- * const filter: ITransactionsFilter = {
133
- * chainId: ChainId.POLYGON,
152
+ * const filter = {
153
+ * chainId: ChainId.POLYGON_AMOY,
134
154
  * startDate: new Date('2022-01-01'),
135
155
  * endDate: new Date('2022-12-31'),
136
156
  * first: 10,
@@ -138,6 +158,7 @@ class TransactionUtils {
138
158
  * orderDirection: OrderDirection.DESC,
139
159
  * };
140
160
  * const transactions = await TransactionUtils.getTransactions(filter);
161
+ * console.log('Transactions:', transactions.length);
141
162
  * ```
142
163
  */
143
164
  static async getTransactions(filter, options) {
package/dist/types.d.ts CHANGED
@@ -34,60 +34,6 @@ export declare enum EscrowStatus {
34
34
  */
35
35
  ToCancel = 6
36
36
  }
37
- /**
38
- * AWS/GCP cloud storage access data
39
- * @readonly
40
- * @deprecated StorageClient is deprecated. Use Minio.Client directly.
41
- */
42
- export type StorageCredentials = {
43
- /**
44
- * Access Key
45
- */
46
- accessKey: string;
47
- /**
48
- * Secret Key
49
- */
50
- secretKey: string;
51
- };
52
- /**
53
- * @deprecated StorageClient is deprecated. Use Minio.Client directly.
54
- */
55
- export type StorageParams = {
56
- /**
57
- * Request endPoint
58
- */
59
- endPoint: string;
60
- /**
61
- * Enable secure (HTTPS) access. Default value set to false
62
- */
63
- useSSL: boolean;
64
- /**
65
- * Region
66
- */
67
- region?: string;
68
- /**
69
- * TCP/IP port number. Default value set to 80 for HTTP and 443 for HTTPs
70
- */
71
- port?: number;
72
- };
73
- /**
74
- * Upload file data
75
- * @readonly
76
- */
77
- export type UploadFile = {
78
- /**
79
- * Uploaded object key
80
- */
81
- key: string;
82
- /**
83
- * Uploaded object URL
84
- */
85
- url: string;
86
- /**
87
- * Hash of uploaded object key
88
- */
89
- hash: string;
90
- };
91
37
  /**
92
38
  * Network data
93
39
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,oBAAY,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