@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.
- package/CHANGELOG.md +26 -0
- package/LICENSE +21 -0
- package/README.md +322 -2
- package/dist/cjs/client.d.ts +46 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +80 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/core/errors.d.ts +64 -0
- package/dist/cjs/core/errors.d.ts.map +1 -0
- package/dist/cjs/core/errors.js +95 -0
- package/dist/cjs/core/errors.js.map +1 -0
- package/dist/cjs/core/http.d.ts +58 -0
- package/dist/cjs/core/http.d.ts.map +1 -0
- package/dist/cjs/core/http.js +143 -0
- package/dist/cjs/core/http.js.map +1 -0
- package/dist/cjs/core/pagination.d.ts +12 -0
- package/dist/cjs/core/pagination.d.ts.map +1 -0
- package/dist/cjs/core/pagination.js +15 -0
- package/dist/cjs/core/pagination.js.map +1 -0
- package/dist/cjs/core/scope.d.ts +8 -0
- package/dist/cjs/core/scope.d.ts.map +1 -0
- package/dist/cjs/core/scope.js +3 -0
- package/dist/cjs/core/scope.js.map +1 -0
- package/dist/cjs/generated/types.d.ts +336 -0
- package/dist/cjs/generated/types.d.ts.map +1 -0
- package/dist/cjs/generated/types.js +5 -0
- package/dist/cjs/generated/types.js.map +1 -0
- package/dist/cjs/index.d.ts +23 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/resources/account.d.ts +22 -0
- package/dist/cjs/resources/account.d.ts.map +1 -0
- package/dist/cjs/resources/account.js +31 -0
- package/dist/cjs/resources/account.js.map +1 -0
- package/dist/cjs/resources/addresses.d.ts +93 -0
- package/dist/cjs/resources/addresses.d.ts.map +1 -0
- package/dist/cjs/resources/addresses.js +128 -0
- package/dist/cjs/resources/addresses.js.map +1 -0
- package/dist/cjs/resources/catalog.d.ts +37 -0
- package/dist/cjs/resources/catalog.d.ts.map +1 -0
- package/dist/cjs/resources/catalog.js +52 -0
- package/dist/cjs/resources/catalog.js.map +1 -0
- package/dist/cjs/resources/deliveries.d.ts +61 -0
- package/dist/cjs/resources/deliveries.d.ts.map +1 -0
- package/dist/cjs/resources/deliveries.js +53 -0
- package/dist/cjs/resources/deliveries.js.map +1 -0
- package/dist/cjs/resources/transactions.d.ts +28 -0
- package/dist/cjs/resources/transactions.d.ts.map +1 -0
- package/dist/cjs/resources/transactions.js +34 -0
- package/dist/cjs/resources/transactions.js.map +1 -0
- package/dist/cjs/resources/webhooks.d.ts +22 -0
- package/dist/cjs/resources/webhooks.d.ts.map +1 -0
- package/dist/cjs/resources/webhooks.js +35 -0
- package/dist/cjs/resources/webhooks.js.map +1 -0
- package/dist/cjs/units.d.ts +29 -0
- package/dist/cjs/units.d.ts.map +1 -0
- package/dist/cjs/units.js +62 -0
- package/dist/cjs/units.js.map +1 -0
- package/dist/cjs/version.d.ts +5 -0
- package/dist/cjs/version.d.ts.map +1 -0
- package/dist/cjs/version.js +8 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/cjs/webhooks.d.ts +82 -0
- package/dist/cjs/webhooks.d.ts.map +1 -0
- package/dist/cjs/webhooks.js +133 -0
- package/dist/cjs/webhooks.js.map +1 -0
- package/dist/esm/client.d.ts +46 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +76 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/core/errors.d.ts +64 -0
- package/dist/esm/core/errors.d.ts.map +1 -0
- package/dist/esm/core/errors.js +86 -0
- package/dist/esm/core/errors.js.map +1 -0
- package/dist/esm/core/http.d.ts +58 -0
- package/dist/esm/core/http.d.ts.map +1 -0
- package/dist/esm/core/http.js +138 -0
- package/dist/esm/core/http.js.map +1 -0
- package/dist/esm/core/pagination.d.ts +12 -0
- package/dist/esm/core/pagination.d.ts.map +1 -0
- package/dist/esm/core/pagination.js +12 -0
- package/dist/esm/core/pagination.js.map +1 -0
- package/dist/esm/core/scope.d.ts +8 -0
- package/dist/esm/core/scope.d.ts.map +1 -0
- package/dist/esm/core/scope.js +2 -0
- package/dist/esm/core/scope.js.map +1 -0
- package/dist/esm/generated/types.d.ts +336 -0
- package/dist/esm/generated/types.d.ts.map +1 -0
- package/dist/esm/generated/types.js +4 -0
- package/dist/esm/generated/types.js.map +1 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/resources/account.d.ts +22 -0
- package/dist/esm/resources/account.d.ts.map +1 -0
- package/dist/esm/resources/account.js +27 -0
- package/dist/esm/resources/account.js.map +1 -0
- package/dist/esm/resources/addresses.d.ts +93 -0
- package/dist/esm/resources/addresses.d.ts.map +1 -0
- package/dist/esm/resources/addresses.js +124 -0
- package/dist/esm/resources/addresses.js.map +1 -0
- package/dist/esm/resources/catalog.d.ts +37 -0
- package/dist/esm/resources/catalog.d.ts.map +1 -0
- package/dist/esm/resources/catalog.js +47 -0
- package/dist/esm/resources/catalog.js.map +1 -0
- package/dist/esm/resources/deliveries.d.ts +61 -0
- package/dist/esm/resources/deliveries.d.ts.map +1 -0
- package/dist/esm/resources/deliveries.js +49 -0
- package/dist/esm/resources/deliveries.js.map +1 -0
- package/dist/esm/resources/transactions.d.ts +28 -0
- package/dist/esm/resources/transactions.d.ts.map +1 -0
- package/dist/esm/resources/transactions.js +30 -0
- package/dist/esm/resources/transactions.js.map +1 -0
- package/dist/esm/resources/webhooks.d.ts +22 -0
- package/dist/esm/resources/webhooks.d.ts.map +1 -0
- package/dist/esm/resources/webhooks.js +31 -0
- package/dist/esm/resources/webhooks.js.map +1 -0
- package/dist/esm/units.d.ts +29 -0
- package/dist/esm/units.d.ts.map +1 -0
- package/dist/esm/units.js +58 -0
- package/dist/esm/units.js.map +1 -0
- package/dist/esm/version.d.ts +5 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +5 -0
- package/dist/esm/version.js.map +1 -0
- package/dist/esm/webhooks.d.ts +82 -0
- package/dist/esm/webhooks.d.ts.map +1 -0
- package/dist/esm/webhooks.js +125 -0
- package/dist/esm/webhooks.js.map +1 -0
- package/package.json +69 -4
- package/src/client.ts +83 -0
- package/src/core/errors.ts +99 -0
- package/src/core/http.ts +183 -0
- package/src/core/pagination.ts +20 -0
- package/src/core/scope.ts +8 -0
- package/src/generated/types.ts +369 -0
- package/src/index.ts +43 -0
- package/src/resources/account.ts +33 -0
- package/src/resources/addresses.ts +165 -0
- package/src/resources/catalog.ts +56 -0
- package/src/resources/deliveries.ts +82 -0
- package/src/resources/transactions.ts +34 -0
- package/src/resources/webhooks.ts +36 -0
- package/src/units.ts +56 -0
- package/src/version.ts +5 -0
- package/src/webhooks.ts +138 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { MonitoringApiError } from '../core/errors.js';
|
|
2
|
+
import { paginate } from '../core/pagination.js';
|
|
3
|
+
/** Maximum number of addresses the API accepts per request. Larger lists are split into batches automatically. */
|
|
4
|
+
export const ADDRESS_BATCH_SIZE = 1000;
|
|
5
|
+
/** Addresses you monitor and their subscriptions: which assets and which direction you are notified about. */
|
|
6
|
+
export class AddressesResource {
|
|
7
|
+
#scope;
|
|
8
|
+
/** @internal */
|
|
9
|
+
constructor(scope) {
|
|
10
|
+
this.#scope = scope;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Lists monitored addresses, one page at a time.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const { items, next } = await monitoring.addresses.list({ network: 'tron' })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
async list(params = {}, options) {
|
|
21
|
+
return this.#scope.http.request({ method: 'GET', path: `${await this.#scope.clientPath()}/addresses`, query: { ...params }, idempotent: true, options });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Iterates over all monitored addresses, fetching pages as needed.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* for await (const address of monitoring.addresses.iterate({ network: 'tron' })) {
|
|
29
|
+
* console.log(address.address, address.assets ?? 'all assets', address.direction)
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
iterate(params = {}, options) {
|
|
34
|
+
return paginate((after) => this.list({ ...params, after }, options));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Starts monitoring addresses. New addresses are picked up within seconds. Addresses that are already monitored are
|
|
38
|
+
* left unchanged — use {@link AddressesResource.update} to change their subscription.
|
|
39
|
+
*
|
|
40
|
+
* Each batch of up to {@link ADDRESS_BATCH_SIZE} addresses is validated as a whole: if any item is invalid, the
|
|
41
|
+
* batch is not applied. Larger lists are sent in batches, in order; if a batch fails, the previous batches have
|
|
42
|
+
* already been applied, and the indexes in `error.details` refer to your original list. Retrying is safe.
|
|
43
|
+
*
|
|
44
|
+
* @param addresses - Addresses to monitor. An EVM address is monitored per network: add it once per network.
|
|
45
|
+
* @param defaults - Subscription for addresses that do not set their own.
|
|
46
|
+
* @throws {@link MonitoringApiError} `400` with `details` when an address is invalid for its network or an asset
|
|
47
|
+
* is unknown.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* // deposit addresses: incoming USDT only
|
|
52
|
+
* await monitoring.addresses.add([{ network: 'tron', address: 'TA8Hg…', label: 'user-42' }], {
|
|
53
|
+
* assets: ['USDT'],
|
|
54
|
+
* direction: 'in',
|
|
55
|
+
* })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
async add(addresses, defaults = {}, options) {
|
|
59
|
+
const total = { added: 0, alreadyWatched: 0 };
|
|
60
|
+
await this.#batches(addresses, async (batch, path) => {
|
|
61
|
+
const r = await this.#scope.http.request({ method: 'POST', path: `${path}/addresses`, body: { ...defaults, addresses: batch }, idempotent: true, options });
|
|
62
|
+
total.added += r.added;
|
|
63
|
+
total.alreadyWatched += r.alreadyWatched;
|
|
64
|
+
});
|
|
65
|
+
return total;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Changes the subscription of monitored addresses. Only the fields you pass are changed: omit `assets` to keep the
|
|
69
|
+
* current assets, or pass `null` to subscribe to all assets of the network.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* await monitoring.addresses.update([{ network: 'tron', address: 'TA8Hg…' }], { direction: 'both' })
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
async update(addresses, defaults = {}, options) {
|
|
77
|
+
const total = { updated: 0, notWatched: 0 };
|
|
78
|
+
await this.#batches(addresses, async (batch, path) => {
|
|
79
|
+
const r = await this.#scope.http.request({ method: 'POST', path: `${path}/addresses/update`, body: { ...defaults, addresses: batch }, idempotent: true, options });
|
|
80
|
+
total.updated += r.updated;
|
|
81
|
+
total.notWatched += r.notWatched;
|
|
82
|
+
});
|
|
83
|
+
return total;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Stops monitoring addresses.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* await monitoring.addresses.remove([{ network: 'tron', address: 'TA8Hg…' }])
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
async remove(addresses, options) {
|
|
94
|
+
const total = { removed: 0, notWatched: 0 };
|
|
95
|
+
await this.#batches(addresses, async (batch, path) => {
|
|
96
|
+
const r = await this.#scope.http.request({ method: 'POST', path: `${path}/addresses/remove`, body: { addresses: batch }, idempotent: true, options });
|
|
97
|
+
total.removed += r.removed;
|
|
98
|
+
total.notWatched += r.notWatched;
|
|
99
|
+
});
|
|
100
|
+
return total;
|
|
101
|
+
}
|
|
102
|
+
/** Sends items in batches, in order; maps per-item error indexes back to the original list. */
|
|
103
|
+
async #batches(items, send) {
|
|
104
|
+
const path = await this.#scope.clientPath();
|
|
105
|
+
for (let offset = 0; offset < items.length; offset += ADDRESS_BATCH_SIZE) {
|
|
106
|
+
try {
|
|
107
|
+
await send(items.slice(offset, offset + ADDRESS_BATCH_SIZE), path);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (!(error instanceof MonitoringApiError) || offset === 0)
|
|
111
|
+
throw error;
|
|
112
|
+
throw new MonitoringApiError({
|
|
113
|
+
status: error.status,
|
|
114
|
+
code: error.code,
|
|
115
|
+
message: `${error.message.replace(/ \(HTTP \d+, [\w-]+\)$/, '')}; addresses before index ${offset} were already applied`,
|
|
116
|
+
details: error.details.map((d) => ({ ...d, index: d.index + offset })),
|
|
117
|
+
requestId: error.requestId,
|
|
118
|
+
body: error.body,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=addresses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addresses.js","sourceRoot":"","sources":["../../../src/resources/addresses.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAehD,kHAAkH;AAClH,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAuBtC,8GAA8G;AAC9G,MAAM,OAAO,iBAAiB;IACnB,MAAM,CAAO;IAEtB,gBAAgB;IAChB,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CAAC,MAAM,GAAwB,EAAE,EAAE,OAAwB;QACnE,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MA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AED,+FAA+F;IAC/F,KAAK,CAAC,QAAQ,CAAI,KAAU,EAAE,IAAuD;QACnF,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;QAC3C,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,kBAAkB,EAAE,CAAC;YACzE,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAAC,EAAE,IAAI,CAAC,CAAA;YACpE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,CAAC,KAAK,YAAY,kBAAkB,CAAC,IAAI,MAAM,KAAK,CAAC;oBAAE,MAAM,KAAK,CAAA;gBACvE,MAAM,IAAI,kBAAkB,CAAC;oBAC3B,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,CAAC,4BAA4B,MAAM,uBAAuB;oBACxH,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,GAAG,MAAM,EAAE,CAAC,CAAC;oBACtE,SAAS,EAAE,KAAK,CAAC,SAAS;oBAC1B,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type RequestOptions } from '../core/http.js';
|
|
2
|
+
import type { Scope } from '../core/scope.js';
|
|
3
|
+
import type { Asset, Network } from '../generated/types.js';
|
|
4
|
+
/** Supported networks. */
|
|
5
|
+
export declare class NetworksResource {
|
|
6
|
+
#private;
|
|
7
|
+
/** @internal */
|
|
8
|
+
constructor(scope: Scope);
|
|
9
|
+
/** Lists all networks. Transfers are monitored on networks with `enabled: true`. */
|
|
10
|
+
list(options?: RequestOptions): Promise<Network[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves a network.
|
|
13
|
+
*
|
|
14
|
+
* @param network - Network slug (`tron`, `ethereum`) or CAIP-2 ID (`eip155:1`).
|
|
15
|
+
*/
|
|
16
|
+
get(network: string, options?: RequestOptions): Promise<Network>;
|
|
17
|
+
}
|
|
18
|
+
/** Native coins and tokens. You are notified about transfers of enabled assets of at least `minAmount`. */
|
|
19
|
+
export declare class AssetsResource {
|
|
20
|
+
#private;
|
|
21
|
+
/** @internal */
|
|
22
|
+
constructor(scope: Scope);
|
|
23
|
+
/**
|
|
24
|
+
* Lists assets, optionally of one network.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const usdt = (await monitoring.assets.list({ network: 'tron' })).find((asset) => asset.symbol === 'USDT')
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
list(params?: {
|
|
32
|
+
network?: string;
|
|
33
|
+
}, options?: RequestOptions): Promise<Asset[]>;
|
|
34
|
+
/** Retrieves an asset by ID. */
|
|
35
|
+
get(assetId: number, options?: RequestOptions): Promise<Asset>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../../src/resources/catalog.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,KAAK,EAAa,OAAO,EAAe,MAAM,uBAAuB,CAAA;AAEnF,0BAA0B;AAC1B,qBAAa,gBAAgB;;IAG3B,gBAAgB;IAChB,YAAY,KAAK,EAAE,KAAK,EAEvB;IAED,oFAAoF;IAC9E,IAAI,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAGvD;IAED;;;;OAIG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAE/D;CACF;AAED,2GAA2G;AAC3G,qBAAa,cAAc;;IAGzB,gBAAgB;IAChB,YAAY,KAAK,EAAE,KAAK,EAEvB;IAED;;;;;;;OAOG;IACG,IAAI,CAAC,MAAM,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAGxF;IAED,gCAAgC;IAChC,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CAE7D;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { seg } from '../core/http.js';
|
|
2
|
+
/** Supported networks. */
|
|
3
|
+
export class NetworksResource {
|
|
4
|
+
#scope;
|
|
5
|
+
/** @internal */
|
|
6
|
+
constructor(scope) {
|
|
7
|
+
this.#scope = scope;
|
|
8
|
+
}
|
|
9
|
+
/** Lists all networks. Transfers are monitored on networks with `enabled: true`. */
|
|
10
|
+
async list(options) {
|
|
11
|
+
const r = await this.#scope.http.request({ method: 'GET', path: '/v1/networks', idempotent: true, options });
|
|
12
|
+
return r.items;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Retrieves a network.
|
|
16
|
+
*
|
|
17
|
+
* @param network - Network slug (`tron`, `ethereum`) or CAIP-2 ID (`eip155:1`).
|
|
18
|
+
*/
|
|
19
|
+
get(network, options) {
|
|
20
|
+
return this.#scope.http.request({ method: 'GET', path: `/v1/networks/${seg(network)}`, idempotent: true, options });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Native coins and tokens. You are notified about transfers of enabled assets of at least `minAmount`. */
|
|
24
|
+
export class AssetsResource {
|
|
25
|
+
#scope;
|
|
26
|
+
/** @internal */
|
|
27
|
+
constructor(scope) {
|
|
28
|
+
this.#scope = scope;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Lists assets, optionally of one network.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const usdt = (await monitoring.assets.list({ network: 'tron' })).find((asset) => asset.symbol === 'USDT')
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
async list(params = {}, options) {
|
|
39
|
+
const r = await this.#scope.http.request({ method: 'GET', path: '/v1/assets', query: params, idempotent: true, options });
|
|
40
|
+
return r.items;
|
|
41
|
+
}
|
|
42
|
+
/** Retrieves an asset by ID. */
|
|
43
|
+
get(assetId, options) {
|
|
44
|
+
return this.#scope.http.request({ method: 'GET', path: `/v1/assets/${seg(assetId)}`, idempotent: true, options });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../../src/resources/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAuB,MAAM,iBAAiB,CAAA;AAI1D,0BAA0B;AAC1B,MAAM,OAAO,gBAAgB;IAClB,MAAM,CAAO;IAEtB,gBAAgB;IAChB,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED,oFAAoF;IACpF,KAAK,CAAC,IAAI,CAAC,OAAwB;QACjC,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAc,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QACzH,OAAO,CAAC,CAAC,KAAK,CAAA;IAChB,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,OAAe,EAAE,OAAwB;QAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IACrH,CAAC;CACF;AAED,2GAA2G;AAC3G,MAAM,OAAO,cAAc;IAChB,MAAM,CAAO;IAEtB,gBAAgB;IAChB,YAAY,KAAY;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,IAAI,CAAC,MAAM,GAAyB,EAAE,EAAE,OAAwB;QACpE,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAY,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;QACpI,OAAO,CAAC,CAAC,KAAK,CAAA;IAChB,CAAC;IAED,gCAAgC;IAChC,GAAG,CAAC,OAAe,EAAE,OAAwB;QAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;IACnH,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type RequestOptions } from '../core/http.js';
|
|
2
|
+
import type { Scope } from '../core/scope.js';
|
|
3
|
+
import type { Delivery, DeliveryDetail, DeliveryPage, DeliveryStatus } from '../generated/types.js';
|
|
4
|
+
/** Filters for webhook deliveries. All are optional and can be combined. */
|
|
5
|
+
export interface DeliveryFilter {
|
|
6
|
+
/** `delivered`, `retrying` or `failed`. */
|
|
7
|
+
status?: DeliveryStatus;
|
|
8
|
+
/** Network slug or CAIP-2 ID. */
|
|
9
|
+
network?: string;
|
|
10
|
+
/** Asset symbol. */
|
|
11
|
+
asset?: string;
|
|
12
|
+
/** Transaction hash. */
|
|
13
|
+
tx?: string;
|
|
14
|
+
/** Sender or recipient address. */
|
|
15
|
+
address?: string;
|
|
16
|
+
/** First attempt at or after this time. */
|
|
17
|
+
since?: Date | string;
|
|
18
|
+
/** First attempt before this time. */
|
|
19
|
+
until?: Date | string;
|
|
20
|
+
}
|
|
21
|
+
/** Parameters of {@link DeliveriesResource.list}. */
|
|
22
|
+
export interface ListDeliveriesParams extends DeliveryFilter {
|
|
23
|
+
/** Page size, up to 500. Defaults to 100. */
|
|
24
|
+
limit?: number;
|
|
25
|
+
/** Cursor: `next` of the previous page. */
|
|
26
|
+
before?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Every webhook sent to you: status, attempts and your endpoint's response. Retries of the same webhook are one
|
|
30
|
+
* delivery with an attempt count. Deliveries are kept for 90 days.
|
|
31
|
+
*/
|
|
32
|
+
export declare class DeliveriesResource {
|
|
33
|
+
#private;
|
|
34
|
+
/** @internal */
|
|
35
|
+
constructor(scope: Scope);
|
|
36
|
+
/**
|
|
37
|
+
* Lists deliveries, newest first, one page at a time.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const { items } = await monitoring.deliveries.list({ status: 'failed', since: new Date(Date.now() - 86_400_000) })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
list(params?: ListDeliveriesParams, options?: RequestOptions): Promise<DeliveryPage>;
|
|
45
|
+
/**
|
|
46
|
+
* Iterates over all deliveries matching the filter, newest first.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* for await (const delivery of monitoring.deliveries.iterate({ status: 'failed' })) {
|
|
51
|
+
* console.log(delivery.txId, delivery.attempts, delivery.lastHttpStatus ?? delivery.lastError)
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
iterate(filter?: DeliveryFilter & {
|
|
56
|
+
limit?: number;
|
|
57
|
+
}, options?: RequestOptions): AsyncGenerator<Delivery, void, undefined>;
|
|
58
|
+
/** Retrieves a delivery with the URL of the last attempt and the exact request body. */
|
|
59
|
+
get(deliveryId: number, options?: RequestOptions): Promise<DeliveryDetail>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=deliveries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deliveries.d.ts","sourceRoot":"","sources":["../../../src/resources/deliveries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAE1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEnG,4EAA4E;AAC5E,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,wBAAwB;IACxB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IACrB,sCAAsC;IACtC,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;CACtB;AAED,qDAAqD;AACrD,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC1D,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAID;;;GAGG;AACH,qBAAa,kBAAkB;;IAG7B,gBAAgB;IAChB,YAAY,KAAK,EAAE,KAAK,EAEvB;IAED;;;;;;;OAOG;IACG,IAAI,CAAC,MAAM,GAAE,oBAAyB,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAQ7F;IAED;;;;;;;;;OASG;IACH,OAAO,CAAC,MAAM,GAAE,cAAc,GAAG;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,cAAc,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,CAAC,CAE7H;IAED,wFAAwF;IAClF,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAE/E;CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { seg } from '../core/http.js';
|
|
2
|
+
import { paginate } from '../core/pagination.js';
|
|
3
|
+
const iso = (value) => (value instanceof Date ? value.toISOString() : value);
|
|
4
|
+
/**
|
|
5
|
+
* Every webhook sent to you: status, attempts and your endpoint's response. Retries of the same webhook are one
|
|
6
|
+
* delivery with an attempt count. Deliveries are kept for 90 days.
|
|
7
|
+
*/
|
|
8
|
+
export class DeliveriesResource {
|
|
9
|
+
#scope;
|
|
10
|
+
/** @internal */
|
|
11
|
+
constructor(scope) {
|
|
12
|
+
this.#scope = scope;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Lists deliveries, newest first, one page at a time.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const { items } = await monitoring.deliveries.list({ status: 'failed', since: new Date(Date.now() - 86_400_000) })
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
async list(params = {}, options) {
|
|
23
|
+
return this.#scope.http.request({
|
|
24
|
+
method: 'GET',
|
|
25
|
+
path: `${await this.#scope.clientPath()}/deliveries`,
|
|
26
|
+
query: { ...params, since: iso(params.since), until: iso(params.until) },
|
|
27
|
+
idempotent: true,
|
|
28
|
+
options,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Iterates over all deliveries matching the filter, newest first.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* for await (const delivery of monitoring.deliveries.iterate({ status: 'failed' })) {
|
|
37
|
+
* console.log(delivery.txId, delivery.attempts, delivery.lastHttpStatus ?? delivery.lastError)
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
iterate(filter = {}, options) {
|
|
42
|
+
return paginate((before) => this.list({ ...filter, before }, options));
|
|
43
|
+
}
|
|
44
|
+
/** Retrieves a delivery with the URL of the last attempt and the exact request body. */
|
|
45
|
+
async get(deliveryId, options) {
|
|
46
|
+
return this.#scope.http.request({ method: 'GET', path: `${await this.#scope.clientPath()}/deliveries/${seg(deliveryId)}`, idempotent: true, options });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=deliveries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deliveries.js","sourceRoot":"","sources":["../../../src/resources/deliveries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAuB,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AA8BhD,MAAM,GAAG,GAAG,CAAC,KAAgC,EAAE,EAAE,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAEvG;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ope.js';
|
|
3
|
+
import type { Transaction } from '../generated/types.js';
|
|
4
|
+
/** Any transaction on a supported network, by hash. */
|
|
5
|
+
export declare class TransactionsResource {
|
|
6
|
+
#private;
|
|
7
|
+
/** @internal */
|
|
8
|
+
constructor(scope: Scope);
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves a transaction — not only the ones you were notified about: status, confirmations, finality, fee and
|
|
11
|
+
* every transfer inside it, plus your monitored addresses and the webhooks sent to you for it.
|
|
12
|
+
*
|
|
13
|
+
* `final: true` means the transaction can no longer be reverted: on TRON the block is solidified (about 1 minute),
|
|
14
|
+
* on EVM networks it is finalized (about 13 minutes on Ethereum). Credit large amounts once the transaction is final.
|
|
15
|
+
*
|
|
16
|
+
* @param network - Network slug (`tron`, `ethereum`) or CAIP-2 ID.
|
|
17
|
+
* @param hash - EVM: `0x` followed by 64 hex characters. TRON: 64 hex characters.
|
|
18
|
+
* @throws {@link MonitoringApiError} `404` when the transaction does not exist on the network.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const tx = await monitoring.transactions.get('tron', event.tx.id)
|
|
23
|
+
* if (tx.status === 'success' && tx.final) await credit(event.tx)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
get(network: string, hash: string, options?: RequestOptions): Promise<Transaction>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=transactions.d.ts.map
|
|
@@ -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,30 @@
|
|
|
1
|
+
import { seg } from '../core/http.js';
|
|
2
|
+
/** Any transaction on a supported network, by hash. */
|
|
3
|
+
export class TransactionsResource {
|
|
4
|
+
#scope;
|
|
5
|
+
/** @internal */
|
|
6
|
+
constructor(scope) {
|
|
7
|
+
this.#scope = scope;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves a transaction — not only the ones you were notified about: status, confirmations, finality, fee and
|
|
11
|
+
* every transfer inside it, plus your monitored addresses and the webhooks sent to you for it.
|
|
12
|
+
*
|
|
13
|
+
* `final: true` means the transaction can no longer be reverted: on TRON the block is solidified (about 1 minute),
|
|
14
|
+
* on EVM networks it is finalized (about 13 minutes on Ethereum). Credit large amounts once the transaction is final.
|
|
15
|
+
*
|
|
16
|
+
* @param network - Network slug (`tron`, `ethereum`) or CAIP-2 ID.
|
|
17
|
+
* @param hash - EVM: `0x` followed by 64 hex characters. TRON: 64 hex characters.
|
|
18
|
+
* @throws {@link MonitoringApiError} `404` when the transaction does not exist on the network.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const tx = await monitoring.transactions.get('tron', event.tx.id)
|
|
23
|
+
* if (tx.status === 'success' && tx.final) await credit(event.tx)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
get(network, hash, options) {
|
|
27
|
+
return this.#scope.http.request({ method: 'GET', path: `/v1/networks/${seg(network)}/transactions/${seg(hash)}`, idempotent: true, options });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=transactions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactions.js","sourceRoot":"","sources":["../../../src/resources/transactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAuB,MAAM,iBAAiB,CAAA;AAI1D,uDAAuD;AACvD,MAAM,OAAO,oBAAoB;IACtB,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,GAAG,CAAC,OAAO,CAAC,iBAAiB,GAAG,CAAC,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,31 @@
|
|
|
1
|
+
/** Test your webhook endpoint. To receive webhooks, see {@link parseWebhook}. */
|
|
2
|
+
export class WebhooksResource {
|
|
3
|
+
#scope;
|
|
4
|
+
/** @internal */
|
|
5
|
+
constructor(scope) {
|
|
6
|
+
this.#scope = scope;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Sends a signed test webhook to your webhook URL and returns the outcome, the signature and the exact body sent.
|
|
10
|
+
* Test webhooks have `"test": true` in the body and the `x-webhook-test: 1` header — do not credit them.
|
|
11
|
+
* Limited to 10 per minute.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const { delivery } = await monitoring.webhooks.sendTest({ asset: 'USDT' })
|
|
16
|
+
* if (!delivery.ok) console.error('Endpoint responded with', delivery.status ?? delivery.error)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
async sendTest(params = {}, options) {
|
|
20
|
+
return this.#scope.http.request({
|
|
21
|
+
method: 'POST',
|
|
22
|
+
path: `${await this.#scope.clientPath()}/webhooks/test`,
|
|
23
|
+
body: params,
|
|
24
|
+
idempotent: false,
|
|
25
|
+
// 502 means "your endpoint did not accept it": an outcome, not a failed request
|
|
26
|
+
acceptStatuses: [502],
|
|
27
|
+
options,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=webhooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../../../src/resources/webhooks.ts"],"names":[],"mappings":"AAIA,iFAAiF;AACjF,MAAM,OAAO,gBAAgB;IAClB,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,58 @@
|
|
|
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
|
+
const INTEGER = /^-?\d+$/;
|
|
7
|
+
const DECIMAL = /^(\d+)(?:\.(\d+))?$/;
|
|
8
|
+
/**
|
|
9
|
+
* Converts an amount in the smallest unit to a decimal string.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* formatUnits('100000000', 6) // '100' — 100 USDT
|
|
14
|
+
* formatUnits('1500000', 6) // '1.5'
|
|
15
|
+
* formatUnits('10090000000000000', 18) // '0.01009' — ETH
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function formatUnits(value, decimals) {
|
|
19
|
+
assertDecimals(decimals);
|
|
20
|
+
const raw = typeof value === 'bigint' ? value.toString() : value.trim();
|
|
21
|
+
if (!INTEGER.test(raw))
|
|
22
|
+
throw new RangeError(`formatUnits: expected an integer amount in the smallest unit, got ${JSON.stringify(value)}`);
|
|
23
|
+
const negative = raw.startsWith('-');
|
|
24
|
+
const digits = (negative ? raw.slice(1) : raw).replace(/^0+(?=\d)/, '');
|
|
25
|
+
if (decimals === 0)
|
|
26
|
+
return (negative && digits !== '0' ? '-' : '') + digits;
|
|
27
|
+
const padded = digits.padStart(decimals + 1, '0');
|
|
28
|
+
const whole = padded.slice(0, -decimals);
|
|
29
|
+
const fraction = padded.slice(-decimals).replace(/0+$/, '');
|
|
30
|
+
const sign = negative && (whole !== '0' || fraction) ? '-' : '';
|
|
31
|
+
return `${sign}${whole}${fraction ? `.${fraction}` : ''}`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Converts a decimal string to an amount in the smallest unit.
|
|
35
|
+
*
|
|
36
|
+
* @throws RangeError when the amount is not a non-negative decimal or has more decimal places than the asset.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* parseUnits('1.5', 6) // '1500000'
|
|
41
|
+
* parseUnits('100', 6) // '100000000'
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function parseUnits(amount, decimals) {
|
|
45
|
+
assertDecimals(decimals);
|
|
46
|
+
const m = DECIMAL.exec(amount.trim());
|
|
47
|
+
if (!m)
|
|
48
|
+
throw new RangeError(`parseUnits: expected a non-negative decimal, got ${JSON.stringify(amount)}`);
|
|
49
|
+
const fraction = m[2] ?? '';
|
|
50
|
+
if (fraction.length > decimals)
|
|
51
|
+
throw new RangeError(`parseUnits: ${amount} has more than ${decimals} decimal places`);
|
|
52
|
+
return BigInt(m[1] + fraction.padEnd(decimals, '0')).toString();
|
|
53
|
+
}
|
|
54
|
+
function assertDecimals(decimals) {
|
|
55
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 255)
|
|
56
|
+
throw new RangeError(`decimals: expected an integer from 0 to 255, got ${decimals}`);
|
|
57
|
+
}
|
|
58
|
+
//# 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,MAAM,UAAU,WAAW,CAAC,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,UAAU,CAAC,GAAG,CAAC,CAAA;IACpC,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,O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kB,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 @@
|
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAA;AAElC,4BAA4B;AAC5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,+BAA+B,CAAA"}
|