@v3finance/monitoring-sdk 0.0.0-stage → 0.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 (149) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +21 -0
  3. package/README.md +322 -2
  4. package/dist/cjs/client.d.ts +46 -0
  5. package/dist/cjs/client.d.ts.map +1 -0
  6. package/dist/cjs/client.js +80 -0
  7. package/dist/cjs/client.js.map +1 -0
  8. package/dist/cjs/core/errors.d.ts +64 -0
  9. package/dist/cjs/core/errors.d.ts.map +1 -0
  10. package/dist/cjs/core/errors.js +95 -0
  11. package/dist/cjs/core/errors.js.map +1 -0
  12. package/dist/cjs/core/http.d.ts +58 -0
  13. package/dist/cjs/core/http.d.ts.map +1 -0
  14. package/dist/cjs/core/http.js +143 -0
  15. package/dist/cjs/core/http.js.map +1 -0
  16. package/dist/cjs/core/pagination.d.ts +12 -0
  17. package/dist/cjs/core/pagination.d.ts.map +1 -0
  18. package/dist/cjs/core/pagination.js +15 -0
  19. package/dist/cjs/core/pagination.js.map +1 -0
  20. package/dist/cjs/core/scope.d.ts +8 -0
  21. package/dist/cjs/core/scope.d.ts.map +1 -0
  22. package/dist/cjs/core/scope.js +3 -0
  23. package/dist/cjs/core/scope.js.map +1 -0
  24. package/dist/cjs/generated/types.d.ts +336 -0
  25. package/dist/cjs/generated/types.d.ts.map +1 -0
  26. package/dist/cjs/generated/types.js +5 -0
  27. package/dist/cjs/generated/types.js.map +1 -0
  28. package/dist/cjs/index.d.ts +23 -0
  29. package/dist/cjs/index.d.ts.map +1 -0
  30. package/dist/cjs/index.js +47 -0
  31. package/dist/cjs/index.js.map +1 -0
  32. package/dist/cjs/package.json +1 -0
  33. package/dist/cjs/resources/account.d.ts +22 -0
  34. package/dist/cjs/resources/account.d.ts.map +1 -0
  35. package/dist/cjs/resources/account.js +31 -0
  36. package/dist/cjs/resources/account.js.map +1 -0
  37. package/dist/cjs/resources/addresses.d.ts +93 -0
  38. package/dist/cjs/resources/addresses.d.ts.map +1 -0
  39. package/dist/cjs/resources/addresses.js +128 -0
  40. package/dist/cjs/resources/addresses.js.map +1 -0
  41. package/dist/cjs/resources/catalog.d.ts +37 -0
  42. package/dist/cjs/resources/catalog.d.ts.map +1 -0
  43. package/dist/cjs/resources/catalog.js +52 -0
  44. package/dist/cjs/resources/catalog.js.map +1 -0
  45. package/dist/cjs/resources/deliveries.d.ts +61 -0
  46. package/dist/cjs/resources/deliveries.d.ts.map +1 -0
  47. package/dist/cjs/resources/deliveries.js +53 -0
  48. package/dist/cjs/resources/deliveries.js.map +1 -0
  49. package/dist/cjs/resources/transactions.d.ts +28 -0
  50. package/dist/cjs/resources/transactions.d.ts.map +1 -0
  51. package/dist/cjs/resources/transactions.js +34 -0
  52. package/dist/cjs/resources/transactions.js.map +1 -0
  53. package/dist/cjs/resources/webhooks.d.ts +22 -0
  54. package/dist/cjs/resources/webhooks.d.ts.map +1 -0
  55. package/dist/cjs/resources/webhooks.js +35 -0
  56. package/dist/cjs/resources/webhooks.js.map +1 -0
  57. package/dist/cjs/units.d.ts +29 -0
  58. package/dist/cjs/units.d.ts.map +1 -0
  59. package/dist/cjs/units.js +62 -0
  60. package/dist/cjs/units.js.map +1 -0
  61. package/dist/cjs/version.d.ts +5 -0
  62. package/dist/cjs/version.d.ts.map +1 -0
  63. package/dist/cjs/version.js +8 -0
  64. package/dist/cjs/version.js.map +1 -0
  65. package/dist/cjs/webhooks.d.ts +82 -0
  66. package/dist/cjs/webhooks.d.ts.map +1 -0
  67. package/dist/cjs/webhooks.js +133 -0
  68. package/dist/cjs/webhooks.js.map +1 -0
  69. package/dist/esm/client.d.ts +46 -0
  70. package/dist/esm/client.d.ts.map +1 -0
  71. package/dist/esm/client.js +76 -0
  72. package/dist/esm/client.js.map +1 -0
  73. package/dist/esm/core/errors.d.ts +64 -0
  74. package/dist/esm/core/errors.d.ts.map +1 -0
  75. package/dist/esm/core/errors.js +86 -0
  76. package/dist/esm/core/errors.js.map +1 -0
  77. package/dist/esm/core/http.d.ts +58 -0
  78. package/dist/esm/core/http.d.ts.map +1 -0
  79. package/dist/esm/core/http.js +138 -0
  80. package/dist/esm/core/http.js.map +1 -0
  81. package/dist/esm/core/pagination.d.ts +12 -0
  82. package/dist/esm/core/pagination.d.ts.map +1 -0
  83. package/dist/esm/core/pagination.js +12 -0
  84. package/dist/esm/core/pagination.js.map +1 -0
  85. package/dist/esm/core/scope.d.ts +8 -0
  86. package/dist/esm/core/scope.d.ts.map +1 -0
  87. package/dist/esm/core/scope.js +2 -0
  88. package/dist/esm/core/scope.js.map +1 -0
  89. package/dist/esm/generated/types.d.ts +336 -0
  90. package/dist/esm/generated/types.d.ts.map +1 -0
  91. package/dist/esm/generated/types.js +4 -0
  92. package/dist/esm/generated/types.js.map +1 -0
  93. package/dist/esm/index.d.ts +23 -0
  94. package/dist/esm/index.d.ts.map +1 -0
  95. package/dist/esm/index.js +20 -0
  96. package/dist/esm/index.js.map +1 -0
  97. package/dist/esm/resources/account.d.ts +22 -0
  98. package/dist/esm/resources/account.d.ts.map +1 -0
  99. package/dist/esm/resources/account.js +27 -0
  100. package/dist/esm/resources/account.js.map +1 -0
  101. package/dist/esm/resources/addresses.d.ts +93 -0
  102. package/dist/esm/resources/addresses.d.ts.map +1 -0
  103. package/dist/esm/resources/addresses.js +124 -0
  104. package/dist/esm/resources/addresses.js.map +1 -0
  105. package/dist/esm/resources/catalog.d.ts +37 -0
  106. package/dist/esm/resources/catalog.d.ts.map +1 -0
  107. package/dist/esm/resources/catalog.js +47 -0
  108. package/dist/esm/resources/catalog.js.map +1 -0
  109. package/dist/esm/resources/deliveries.d.ts +61 -0
  110. package/dist/esm/resources/deliveries.d.ts.map +1 -0
  111. package/dist/esm/resources/deliveries.js +49 -0
  112. package/dist/esm/resources/deliveries.js.map +1 -0
  113. package/dist/esm/resources/transactions.d.ts +28 -0
  114. package/dist/esm/resources/transactions.d.ts.map +1 -0
  115. package/dist/esm/resources/transactions.js +30 -0
  116. package/dist/esm/resources/transactions.js.map +1 -0
  117. package/dist/esm/resources/webhooks.d.ts +22 -0
  118. package/dist/esm/resources/webhooks.d.ts.map +1 -0
  119. package/dist/esm/resources/webhooks.js +31 -0
  120. package/dist/esm/resources/webhooks.js.map +1 -0
  121. package/dist/esm/units.d.ts +29 -0
  122. package/dist/esm/units.d.ts.map +1 -0
  123. package/dist/esm/units.js +58 -0
  124. package/dist/esm/units.js.map +1 -0
  125. package/dist/esm/version.d.ts +5 -0
  126. package/dist/esm/version.d.ts.map +1 -0
  127. package/dist/esm/version.js +5 -0
  128. package/dist/esm/version.js.map +1 -0
  129. package/dist/esm/webhooks.d.ts +82 -0
  130. package/dist/esm/webhooks.d.ts.map +1 -0
  131. package/dist/esm/webhooks.js +125 -0
  132. package/dist/esm/webhooks.js.map +1 -0
  133. package/package.json +69 -4
  134. package/src/client.ts +83 -0
  135. package/src/core/errors.ts +99 -0
  136. package/src/core/http.ts +183 -0
  137. package/src/core/pagination.ts +20 -0
  138. package/src/core/scope.ts +8 -0
  139. package/src/generated/types.ts +369 -0
  140. package/src/index.ts +43 -0
  141. package/src/resources/account.ts +33 -0
  142. package/src/resources/addresses.ts +165 -0
  143. package/src/resources/catalog.ts +56 -0
  144. package/src/resources/deliveries.ts +82 -0
  145. package/src/resources/transactions.ts +34 -0
  146. package/src/resources/webhooks.ts +36 -0
  147. package/src/units.ts +56 -0
  148. package/src/version.ts +5 -0
  149. package/src/webhooks.ts +138 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactions.d.ts","sourceRoot":"","sources":["../../../src/resources/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAExD,uDAAuD;AACvD,qBAAa,oBAAoB;;IAG/B,gBAAgB;IAChB,YAAY,KAAK,EAAE,KAAK,EAEvB;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAEjF;CACF"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionsResource = void 0;
4
+ const http_js_1 = require("../core/http.js");
5
+ /** Any transaction on a supported network, by hash. */
6
+ class TransactionsResource {
7
+ #scope;
8
+ /** @internal */
9
+ constructor(scope) {
10
+ this.#scope = scope;
11
+ }
12
+ /**
13
+ * Retrieves a transaction — not only the ones you were notified about: status, confirmations, finality, fee and
14
+ * every transfer inside it, plus your monitored addresses and the webhooks sent to you for it.
15
+ *
16
+ * `final: true` means the transaction can no longer be reverted: on TRON the block is solidified (about 1 minute),
17
+ * on EVM networks it is finalized (about 13 minutes on Ethereum). Credit large amounts once the transaction is final.
18
+ *
19
+ * @param network - Network slug (`tron`, `ethereum`) or CAIP-2 ID.
20
+ * @param hash - EVM: `0x` followed by 64 hex characters. TRON: 64 hex characters.
21
+ * @throws {@link MonitoringApiError} `404` when the transaction does not exist on the network.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const tx = await monitoring.transactions.get('tron', event.tx.id)
26
+ * if (tx.status === 'success' && tx.final) await credit(event.tx)
27
+ * ```
28
+ */
29
+ get(network, hash, options) {
30
+ return this.#scope.http.request({ method: 'GET', path: `/v1/networks/${(0, http_js_1.seg)(network)}/transactions/${(0, http_js_1.seg)(hash)}`, idempotent: true, options });
31
+ }
32
+ }
33
+ exports.TransactionsResource = TransactionsResource;
34
+ //# sourceMappingURL=transactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactions.js","sourceRoot":"","sources":["../../../src/resources/transactions.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAI1D,uDAAuD;AACvD;IACW,MAAM,CAAO;IAEtB,gBAAgB;IAChB,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,OAAe,EAAE,IAAY,EAAE,OAAwB;QACzD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,IAAA,aAAG,EAAC,OAAO,CAAC,iBAAiB,IAAA,aAAG,EAAC,IAAI,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IAC/I,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import type { RequestOptions } from '../core/http.js';
2
+ import type { Scope } from '../core/scope.js';
3
+ import type { TestWebhookRequest, TestWebhookResult } from '../generated/types.js';
4
+ /** Test your webhook endpoint. To receive webhooks, see {@link parseWebhook}. */
5
+ export declare class WebhooksResource {
6
+ #private;
7
+ /** @internal */
8
+ constructor(scope: Scope);
9
+ /**
10
+ * Sends a signed test webhook to your webhook URL and returns the outcome, the signature and the exact body sent.
11
+ * Test webhooks have `"test": true` in the body and the `x-webhook-test: 1` header — do not credit them.
12
+ * Limited to 10 per minute.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const { delivery } = await monitoring.webhooks.sendTest({ asset: 'USDT' })
17
+ * if (!delivery.ok) console.error('Endpoint responded with', delivery.status ?? delivery.error)
18
+ * ```
19
+ */
20
+ sendTest(params?: TestWebhookRequest, options?: RequestOptions): Promise<TestWebhookResult>;
21
+ }
22
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../../src/resources/webhooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAElF,iFAAiF;AACjF,qBAAa,gBAAgB;;IAG3B,gBAAgB;IAChB,YAAY,KAAK,EAAE,KAAK,EAEvB;IAED;;;;;;;;;;OAUG;IACG,QAAQ,CAAC,MAAM,GAAE,kBAAuB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAUpG;CACF"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebhooksResource = void 0;
4
+ /** Test your webhook endpoint. To receive webhooks, see {@link parseWebhook}. */
5
+ class WebhooksResource {
6
+ #scope;
7
+ /** @internal */
8
+ constructor(scope) {
9
+ this.#scope = scope;
10
+ }
11
+ /**
12
+ * Sends a signed test webhook to your webhook URL and returns the outcome, the signature and the exact body sent.
13
+ * Test webhooks have `"test": true` in the body and the `x-webhook-test: 1` header — do not credit them.
14
+ * Limited to 10 per minute.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const { delivery } = await monitoring.webhooks.sendTest({ asset: 'USDT' })
19
+ * if (!delivery.ok) console.error('Endpoint responded with', delivery.status ?? delivery.error)
20
+ * ```
21
+ */
22
+ async sendTest(params = {}, options) {
23
+ return this.#scope.http.request({
24
+ method: 'POST',
25
+ path: `${await this.#scope.clientPath()}/webhooks/test`,
26
+ body: params,
27
+ idempotent: false,
28
+ // 502 means "your endpoint did not accept it": an outcome, not a failed request
29
+ acceptStatuses: [502],
30
+ options,
31
+ });
32
+ }
33
+ }
34
+ exports.WebhooksResource = WebhooksResource;
35
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../../src/resources/webhooks.ts"],"names":[],"mappings":";;;AAIA,iFAAiF;AACjF;IACW,MAAM,CAAO;IAEtB,gBAAgB;IAChB,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED;;;;;;;;;;OAUG;IACH,KAAK,CAAC,QAAQ,CAAC,MAAM,GAAuB,EAAE,EAAE,OAAwB;QACtE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;YAC9B,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,gBAAgB;YACvD,IAAI,EAAE,MAAM;YACZ,UAAU,EAAE,KAAK;YACjB,gFAAgF;YAChF,cAAc,EAAE,CAAC,GAAG,CAAC;YACrB,OAAO;SACR,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Amounts in the API and in webhooks are decimal strings in the asset's smallest unit (sun, wei; USDT has 6 decimals),
3
+ * because uint256 values do not fit in a `number`. These helpers convert them without losing precision. The decimals
4
+ * of every asset are returned by `monitoring.assets.list()`.
5
+ */
6
+ /**
7
+ * Converts an amount in the smallest unit to a decimal string.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * formatUnits('100000000', 6) // '100' — 100 USDT
12
+ * formatUnits('1500000', 6) // '1.5'
13
+ * formatUnits('10090000000000000', 18) // '0.01009' — ETH
14
+ * ```
15
+ */
16
+ export declare function formatUnits(value: string | bigint, decimals: number): string;
17
+ /**
18
+ * Converts a decimal string to an amount in the smallest unit.
19
+ *
20
+ * @throws RangeError when the amount is not a non-negative decimal or has more decimal places than the asset.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * parseUnits('1.5', 6) // '1500000'
25
+ * parseUnits('100', 6) // '100000000'
26
+ * ```
27
+ */
28
+ export declare function parseUnits(amount: string, decimals: number): string;
29
+ //# sourceMappingURL=units.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAY5E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOnE"}
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ /**
3
+ * Amounts in the API and in webhooks are decimal strings in the asset's smallest unit (sun, wei; USDT has 6 decimals),
4
+ * because uint256 values do not fit in a `number`. These helpers convert them without losing precision. The decimals
5
+ * of every asset are returned by `monitoring.assets.list()`.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.formatUnits = formatUnits;
9
+ exports.parseUnits = parseUnits;
10
+ const INTEGER = /^-?\d+$/;
11
+ const DECIMAL = /^(\d+)(?:\.(\d+))?$/;
12
+ /**
13
+ * Converts an amount in the smallest unit to a decimal string.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * formatUnits('100000000', 6) // '100' — 100 USDT
18
+ * formatUnits('1500000', 6) // '1.5'
19
+ * formatUnits('10090000000000000', 18) // '0.01009' — ETH
20
+ * ```
21
+ */
22
+ function formatUnits(value, decimals) {
23
+ assertDecimals(decimals);
24
+ const raw = typeof value === 'bigint' ? value.toString() : value.trim();
25
+ if (!INTEGER.test(raw))
26
+ throw new RangeError(`formatUnits: expected an integer amount in the smallest unit, got ${JSON.stringify(value)}`);
27
+ const negative = raw.startsWith('-');
28
+ const digits = (negative ? raw.slice(1) : raw).replace(/^0+(?=\d)/, '');
29
+ if (decimals === 0)
30
+ return (negative && digits !== '0' ? '-' : '') + digits;
31
+ const padded = digits.padStart(decimals + 1, '0');
32
+ const whole = padded.slice(0, -decimals);
33
+ const fraction = padded.slice(-decimals).replace(/0+$/, '');
34
+ const sign = negative && (whole !== '0' || fraction) ? '-' : '';
35
+ return `${sign}${whole}${fraction ? `.${fraction}` : ''}`;
36
+ }
37
+ /**
38
+ * Converts a decimal string to an amount in the smallest unit.
39
+ *
40
+ * @throws RangeError when the amount is not a non-negative decimal or has more decimal places than the asset.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * parseUnits('1.5', 6) // '1500000'
45
+ * parseUnits('100', 6) // '100000000'
46
+ * ```
47
+ */
48
+ function parseUnits(amount, decimals) {
49
+ assertDecimals(decimals);
50
+ const m = DECIMAL.exec(amount.trim());
51
+ if (!m)
52
+ throw new RangeError(`parseUnits: expected a non-negative decimal, got ${JSON.stringify(amount)}`);
53
+ const fraction = m[2] ?? '';
54
+ if (fraction.length > decimals)
55
+ throw new RangeError(`parseUnits: ${amount} has more than ${decimals} decimal places`);
56
+ return BigInt(m[1] + fraction.padEnd(decimals, '0')).toString();
57
+ }
58
+ function assertDecimals(decimals) {
59
+ if (!Number.isInteger(decimals) || decimals < 0 || decimals > 255)
60
+ throw new RangeError(`decimals: expected an integer from 0 to 255, got ${decimals}`);
61
+ }
62
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;AAEH,MAAM,OAAO,GAAG,SAAS,CAAA;AACzB,MAAM,OAAO,GAAG,qBAAqB,CAAA;AAErC;;;;;;;;;GASG;AACH,qBAA4B,KAAsB,EAAE,QAAgB;IAClE,cAAc,CAAC,QAAQ,CAAC,CAAA;IACxB,MAAM,GAAG,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;IACvE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,qEAAqE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IAC1I,MAAM,QAAQ,GAAG,GAAG,CAAC,U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,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAC3B,IAAI,QAAQ,CAAC,MAAM,GAAG,QAAQ;QAAE,MAAM,IAAI,UAAU,CAAC,eAAe,MAAM,kBAAkB,QAAQ,iBAAiB,CAAC,CAAA;IACtH,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;AAClE,CAAC;AAED,SAAS,cAAc,CAAC,QAAgB;IACtC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,QAAQ,GAAG,GAAG;QAAE,MAAM,IAAI,UAAU,CAAC,oDAAoD,QAAQ,EAAE,CAAC,CAAA;AACzJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** SDK version, sent in the `user-agent` header. */
2
+ export declare const SDK_VERSION = "0.2.0";
3
+ /** Default API base URL. */
4
+ export declare const DEFAULT_BASE_URL = "https://monitoring.v3.finance";
5
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,eAAO,MAAM,WAAW,UAAU,CAAA;AAElC,4BAA4B;AAC5B,eAAO,MAAM,gBAAgB,kCAAkC,CAAA"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_BASE_URL = exports.SDK_VERSION = void 0;
4
+ /** SDK version, sent in the `user-agent` header. */
5
+ exports.SDK_VERSION = '0.2.0';
6
+ /** Default API base URL. */
7
+ exports.DEFAULT_BASE_URL = 'https://monitoring.v3.finance';
8
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACvC,QAAA,WAAW,GAAG,OAAO,CAAA;AAElC,4BAA4B;AACf,QAAA,gBAAgB,GAAG,+BAA+B,CAAA"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Receiving webhooks: signature verification and parsing. No API key or network access is needed — only your
3
+ * webhook secret. Uses Web Crypto, so it runs on Node.js 20+, Bun, Deno and Cloudflare Workers.
4
+ */
5
+ import type { WebhookPayload } from './generated/types.js';
6
+ /** Headers sent with every webhook. */
7
+ export declare const WEBHOOK_HEADERS: {
8
+ /** HMAC-SHA256 of the raw body keyed with your webhook secret, hex-encoded. */
9
+ readonly signature: 'x-signature';
10
+ /** Your client ID. */
11
+ readonly clientId: 'x-client-id';
12
+ /** `1` for test webhooks. */
13
+ readonly test: 'x-webhook-test';
14
+ };
15
+ /**
16
+ * The raw request body, exactly as received. Do not parse and re-serialize the JSON: the signature is computed over
17
+ * the original bytes.
18
+ */
19
+ export type WebhookBody = string | Uint8Array | ArrayBuffer;
20
+ /**
21
+ * Where to read the signature from: the value of the `x-signature` header, or all request headers — a Fetch
22
+ * `Headers` object (Next.js, Hono, Cloudflare Workers) or a Node.js headers object (`req.headers` in Express, Fastify).
23
+ */
24
+ export type SignatureSource = string | null | undefined | Headers | Record<string, string | string[] | undefined>;
25
+ /**
26
+ * Computes the signature of a body the way the API does. Useful for testing your webhook handler.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const body = JSON.stringify({ tx: { network: 'TRON', asset: 'USDT', … } })
31
+ * await fetch('http://localhost:3000/webhooks/monitoring', {
32
+ * method: 'POST',
33
+ * body,
34
+ * headers: { 'content-type': 'application/json', 'x-signature': await signWebhookBody(body, secret) },
35
+ * })
36
+ * ```
37
+ */
38
+ export declare function signWebhookBody(body: WebhookBody, secret: string): Promise<string>;
39
+ /**
40
+ * Verifies a webhook signature. Returns `true` when the body was sent by the API and was not modified.
41
+ *
42
+ * @param body - Raw request body.
43
+ * @param signature - The `x-signature` header, or all request headers.
44
+ * @param secret - Your webhook secret.
45
+ */
46
+ export declare function verifyWebhookSignature(body: WebhookBody, signature: SignatureSource, secret: string): Promise<boolean>;
47
+ /**
48
+ * Verifies the signature and returns the parsed webhook.
49
+ *
50
+ * Respond with a 2xx status within 15 seconds. Process webhooks idempotently by {@link webhookIdempotencyKey} — the
51
+ * same webhook may arrive more than once — and do not credit test webhooks ({@link isTestWebhook}). Webhooks are sent
52
+ * as soon as a transfer is included in a block; before crediting large amounts, check that the transaction is final
53
+ * with `monitoring.transactions.get()`.
54
+ *
55
+ * @throws {@link WebhookSignatureError} when the signature does not match. Respond with `401` and do not process it.
56
+ *
57
+ * @example Express (use the raw body)
58
+ * ```ts
59
+ * app.post('/webhooks/monitoring', express.raw({ type: 'application/json' }), async (req, res) => {
60
+ * const event = await parseWebhook(req.body, req.headers, process.env.MONITORING_WEBHOOK_SECRET!)
61
+ * if (!isTestWebhook(event)) await creditOnce(webhookIdempotencyKey(event), event.tx)
62
+ * res.sendStatus(200)
63
+ * })
64
+ * ```
65
+ *
66
+ * @example Next.js route handlers, Hono, Cloudflare Workers
67
+ * ```ts
68
+ * const event = await parseWebhook(await request.text(), request.headers, env.MONITORING_WEBHOOK_SECRET)
69
+ * ```
70
+ */
71
+ export declare function parseWebhook(body: WebhookBody, signature: SignatureSource, secret: string): Promise<WebhookPayload>;
72
+ /** `true` for test webhooks. Do not credit them. */
73
+ export declare function isTestWebhook(event: WebhookPayload): boolean;
74
+ /**
75
+ * Idempotency key of a webhook: network, transaction hash and log index. A transfer always has the same key, however
76
+ * many times its webhook is delivered. An EVM transaction can contain several token transfers; they differ by
77
+ * `logIndex`.
78
+ *
79
+ * @example `"TRON:1249cb…a5fc45:"`, `"ETHEREUM:0x3fbc…1d57:7"`
80
+ */
81
+ export declare function webhookIdempotencyKey(event: WebhookPayload): string;
82
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../../src/webhooks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1D,uCAAuC;AACvC,eAAO,MAAM,eAAe;IAC1B,+EAA+E;aAC/E,SAAS,EAAE,aAAa;IACxB,sBAAsB;aACtB,QAAQ,EAAE,aAAa;IACvB,6BAA6B;aAC7B,IAAI,EAAE,gBAAgB;CACd,CAAA;AAEV;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,CAAA;AAE3D;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAA;AA0BjH;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIxF;AAED;;;;;;GAMG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAI5H;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAWzH;AAED,oDAAoD;AACpD,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAE5D;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAEnE"}
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /**
3
+ * Receiving webhooks: signature verification and parsing. No API key or network access is needed — only your
4
+ * webhook secret. Uses Web Crypto, so it runs on Node.js 20+, Bun, Deno and Cloudflare Workers.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.WEBHOOK_HEADERS = void 0;
8
+ exports.signWebhookBody = signWebhookBody;
9
+ exports.verifyWebhookSignature = verifyWebhookSignature;
10
+ exports.parseWebhook = parseWebhook;
11
+ exports.isTestWebhook = isTestWebhook;
12
+ exports.webhookIdempotencyKey = webhookIdempotencyKey;
13
+ const errors_js_1 = require("./core/errors.js");
14
+ /** Headers sent with every webhook. */
15
+ exports.WEBHOOK_HEADERS = {
16
+ /** HMAC-SHA256 of the raw body keyed with your webhook secret, hex-encoded. */
17
+ signature: 'x-signature',
18
+ /** Your client ID. */
19
+ clientId: 'x-client-id',
20
+ /** `1` for test webhooks. */
21
+ test: 'x-webhook-test',
22
+ };
23
+ const encoder = new TextEncoder();
24
+ function bytesOf(body) {
25
+ if (typeof body === 'string')
26
+ return encoder.encode(body);
27
+ // copy: Web Crypto does not accept views over a SharedArrayBuffer (a Node.js Buffer is a Uint8Array too)
28
+ return body instanceof Uint8Array ? new Uint8Array(body) : new Uint8Array(body);
29
+ }
30
+ function signatureOf(source) {
31
+ if (source === null || source === undefined)
32
+ return undefined;
33
+ if (typeof source === 'string')
34
+ return source;
35
+ if (typeof source.get === 'function')
36
+ return source.get(exports.WEBHOOK_HEADERS.signature) ?? undefined;
37
+ const value = source[exports.WEBHOOK_HEADERS.signature];
38
+ return Array.isArray(value) ? value[0] : value;
39
+ }
40
+ /** Constant-time comparison. */
41
+ function safeEqual(a, b) {
42
+ if (a.length !== b.length)
43
+ return false;
44
+ let diff = 0;
45
+ for (let i = 0; i < a.length; i++)
46
+ diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
47
+ return diff === 0;
48
+ }
49
+ /**
50
+ * Computes the signature of a body the way the API does. Useful for testing your webhook handler.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * const body = JSON.stringify({ tx: { network: 'TRON', asset: 'USDT', … } })
55
+ * await fetch('http://localhost:3000/webhooks/monitoring', {
56
+ * method: 'POST',
57
+ * body,
58
+ * headers: { 'content-type': 'application/json', 'x-signature': await signWebhookBody(body, secret) },
59
+ * })
60
+ * ```
61
+ */
62
+ async function signWebhookBody(body, secret) {
63
+ const key = await crypto.subtle.importKey('raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign']);
64
+ const mac = new Uint8Array(await crypto.subtle.sign('HMAC', key, bytesOf(body)));
65
+ return Array.from(mac, (b) => b.toString(16).padStart(2, '0')).join('');
66
+ }
67
+ /**
68
+ * Verifies a webhook signature. Returns `true` when the body was sent by the API and was not modified.
69
+ *
70
+ * @param body - Raw request body.
71
+ * @param signature - The `x-signature` header, or all request headers.
72
+ * @param secret - Your webhook secret.
73
+ */
74
+ async function verifyWebhookSignature(body, signature, secret) {
75
+ const given = signatureOf(signature)?.trim().toLowerCase();
76
+ if (!given)
77
+ return false;
78
+ return safeEqual(await signWebhookBody(body, secret), given);
79
+ }
80
+ /**
81
+ * Verifies the signature and returns the parsed webhook.
82
+ *
83
+ * Respond with a 2xx status within 15 seconds. Process webhooks idempotently by {@link webhookIdempotencyKey} — the
84
+ * same webhook may arrive more than once — and do not credit test webhooks ({@link isTestWebhook}). Webhooks are sent
85
+ * as soon as a transfer is included in a block; before crediting large amounts, check that the transaction is final
86
+ * with `monitoring.transactions.get()`.
87
+ *
88
+ * @throws {@link WebhookSignatureError} when the signature does not match. Respond with `401` and do not process it.
89
+ *
90
+ * @example Express (use the raw body)
91
+ * ```ts
92
+ * app.post('/webhooks/monitoring', express.raw({ type: 'application/json' }), async (req, res) => {
93
+ * const event = await parseWebhook(req.body, req.headers, process.env.MONITORING_WEBHOOK_SECRET!)
94
+ * if (!isTestWebhook(event)) await creditOnce(webhookIdempotencyKey(event), event.tx)
95
+ * res.sendStatus(200)
96
+ * })
97
+ * ```
98
+ *
99
+ * @example Next.js route handlers, Hono, Cloudflare Workers
100
+ * ```ts
101
+ * const event = await parseWebhook(await request.text(), request.headers, env.MONITORING_WEBHOOK_SECRET)
102
+ * ```
103
+ */
104
+ async function parseWebhook(body, signature, secret) {
105
+ if (!(await verifyWebhookSignature(body, signature, secret)))
106
+ throw new errors_js_1.WebhookSignatureError();
107
+ let payload;
108
+ try {
109
+ payload = JSON.parse(typeof body === 'string' ? body : new TextDecoder().decode(bytesOf(body)));
110
+ }
111
+ catch (error) {
112
+ throw new errors_js_1.MonitoringError('webhook body is not valid JSON', { cause: error });
113
+ }
114
+ const tx = payload?.tx;
115
+ if (typeof tx !== 'object' || tx === null || typeof tx.id !== 'string')
116
+ throw new errors_js_1.MonitoringError('webhook body has no tx');
117
+ return payload;
118
+ }
119
+ /** `true` for test webhooks. Do not credit them. */
120
+ function isTestWebhook(event) {
121
+ return event.test === true;
122
+ }
123
+ /**
124
+ * Idempotency key of a webhook: network, transaction hash and log index. A transfer always has the same key, however
125
+ * many times its webhook is delivered. An EVM transaction can contain several token transfers; they differ by
126
+ * `logIndex`.
127
+ *
128
+ * @example `"TRON:1249cb…a5fc45:"`, `"ETHEREUM:0x3fbc…1d57:7"`
129
+ */
130
+ function webhookIdempotencyKey(event) {
131
+ return `${event.tx.network}:${event.tx.id}:${event.tx.logIndex ?? ''}`;
132
+ }
133
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../src/webhooks.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;AAEH,gDAAyE;AAGzE,uCAAuC;AAC1B,QAAA,eAAe,GAAG;IAC7B,+EAA+E;IAC/E,SAAS,EAAE,aAAa;IACxB,sBAAsB;IACtB,QAAQ,EAAE,aAAa;IACvB,6BAA6B;IAC7B,IAAI,EAAE,gBAAgB;CACd,CAAA;AAcV,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AAEjC,SAAS,OAAO,CAAC,IAAiB;IAChC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC,MAAM,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,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjG,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,2BAAe,CAAC,gCAAgC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAC/E,CAAC;IACD,MAAM,EAAE,GAAI,OAA4C,EAAE,EAAE,CAAA;IAC5D,IAAI,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,IAAI,IAAI,OAAO,EAAE,CAAC,EAAE,KAAK,QAAQ;QAAE,MAAM,IAAI,2BAAe,CAAC,wBAAwB,CAAC,CAAA;IAC3H,OAAO,OAAyB,CAAA;AAClC,CAAC;AAED,oDAAoD;AACpD,uBAA8B,KAAqB;IACjD,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAA;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,+BAAsC,KAAqB;IACzD,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC,OAAO,IAAI,KAAK,CAAC,EAAE,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC,QAAQ,IAAI,EAAE,EAAE,CAAA;AACxE,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { type ClientOptions } from './core/http.js';
2
+ import { AccountResource } from './resources/account.js';
3
+ import { AddressesResource } from './resources/addresses.js';
4
+ import { AssetsResource, NetworksResource } from './resources/catalog.js';
5
+ import { DeliveriesResource } from './resources/deliveries.js';
6
+ import { TransactionsResource } from './resources/transactions.js';
7
+ import { WebhooksResource } from './resources/webhooks.js';
8
+ /**
9
+ * Client for the V3 Finance Monitoring API.
10
+ *
11
+ * Use it on the server only: an API key in a browser is visible to anyone.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { MonitoringClient } from '@v3finance/monitoring-sdk'
16
+ *
17
+ * const monitoring = new MonitoringClient({ apiKey: process.env.MONITORING_API_KEY! })
18
+ *
19
+ * await monitoring.addresses.add([{ network: 'tron', address: 'TA8Hg…' }], { assets: ['USDT'], direction: 'in' })
20
+ * ```
21
+ */
22
+ export declare class MonitoringClient {
23
+ #private;
24
+ /** Your client: the account your API key belongs to. */
25
+ readonly account: AccountResource;
26
+ /** Addresses you monitor and their subscriptions. */
27
+ readonly addresses: AddressesResource;
28
+ /** Test your webhook endpoint. */
29
+ readonly webhooks: WebhooksResource;
30
+ /** History of webhooks sent to you. */
31
+ readonly deliveries: DeliveriesResource;
32
+ /** Any transaction by hash, with confirmations and finality. */
33
+ readonly transactions: TransactionsResource;
34
+ /** Supported networks. */
35
+ readonly networks: NetworksResource;
36
+ /** Supported native coins and tokens. */
37
+ readonly assets: AssetsResource;
38
+ /**
39
+ * @param options - API key and optional settings.
40
+ * @throws {@link MonitoringError} when `apiKey` is missing or `fetch` is not available.
41
+ */
42
+ constructor(options: ClientOptions);
43
+ /** API base URL this client sends requests to. */
44
+ get baseUrl(): string;
45
+ }
46
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAGpE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAG1D;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAgB;;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;IACjC,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAA;IACrC,kCAAkC;IAClC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACnC,uCAAuC;IACvC,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAA;IACvC,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAA;IAC3C,0BAA0B;IAC1B,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAA;IACnC,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;IAK/B;;;OAGG;IACH,YAAY,OAAO,EAAE,aAAa,EAWjC;IAED,kDAAkD;IAClD,IAAI,OAAO,IAAI,MAAM,CAEpB;CAiBF"}
@@ -0,0 +1,76 @@
1
+ import { MonitoringError } from './core/errors.js';
2
+ import { HttpClient, seg } from './core/http.js';
3
+ import { AccountResource } from './resources/account.js';
4
+ import { AddressesResource } from './resources/addresses.js';
5
+ import { AssetsResource, NetworksResource } from './resources/catalog.js';
6
+ import { DeliveriesResource } from './resources/deliveries.js';
7
+ import { TransactionsResource } from './resources/transactions.js';
8
+ import { WebhooksResource } from './resources/webhooks.js';
9
+ import { DEFAULT_BASE_URL } from './version.js';
10
+ /**
11
+ * Client for the V3 Finance Monitoring API.
12
+ *
13
+ * Use it on the server only: an API key in a browser is visible to anyone.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { MonitoringClient } from '@v3finance/monitoring-sdk'
18
+ *
19
+ * const monitoring = new MonitoringClient({ apiKey: process.env.MONITORING_API_KEY! })
20
+ *
21
+ * await monitoring.addresses.add([{ network: 'tron', address: 'TA8Hg…' }], { assets: ['USDT'], direction: 'in' })
22
+ * ```
23
+ */
24
+ export class MonitoringClient {
25
+ /** Your client: the account your API key belongs to. */
26
+ account;
27
+ /** Addresses you monitor and their subscriptions. */
28
+ addresses;
29
+ /** Test your webhook endpoint. */
30
+ webhooks;
31
+ /** History of webhooks sent to you. */
32
+ deliveries;
33
+ /** Any transaction by hash, with confirmations and finality. */
34
+ transactions;
35
+ /** Supported networks. */
36
+ networks;
37
+ /** Supported native coins and tokens. */
38
+ assets;
39
+ #http;
40
+ #clientId;
41
+ /**
42
+ * @param options - API key and optional settings.
43
+ * @throws {@link MonitoringError} when `apiKey` is missing or `fetch` is not available.
44
+ */
45
+ constructor(options) {
46
+ this.#http = new HttpClient(options, DEFAULT_BASE_URL);
47
+ if (options.clientId)
48
+ this.#clientId = Promise.resolve(options.clientId);
49
+ const scope = { http: this.#http, clientPath: async () => `/v1/clients/${seg(await this.#resolveClientId())}` };
50
+ this.account = new AccountResource(scope, () => this.#resolveClientId());
51
+ this.addresses = new AddressesResource(scope);
52
+ this.webhooks = new WebhooksResource(scope);
53
+ this.deliveries = new DeliveriesResource(scope);
54
+ this.transactions = new TransactionsResource(scope);
55
+ this.networks = new NetworksResource(scope);
56
+ this.assets = new AssetsResource(scope);
57
+ }
58
+ /** API base URL this client sends requests to. */
59
+ get baseUrl() {
60
+ return this.#http.baseUrl;
61
+ }
62
+ /** Client ID of the API key: from the options, or resolved once from the API and cached. */
63
+ #resolveClientId() {
64
+ this.#clientId ??= this.#http.request({ method: 'GET', path: '/v1/me', idempotent: true }).then((identity) => {
65
+ if (!identity.actor.clientId)
66
+ throw new MonitoringError('this API key is not bound to a client: pass clientId in the options');
67
+ return identity.actor.clientId;
68
+ }, (error) => {
69
+ // a failed lookup is not cached: the next call tries again
70
+ this.#clientId = undefined;
71
+ throw error;
72
+ });
73
+ return this.#clientId;
74
+ }
75
+ }
76
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAsB,MAAM,gBAAgB,CAAA;AAGpE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;A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