@n1xyz/nord-ts 0.1.7 → 0.1.9

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 (84) hide show
  1. package/dist/actions.js +39 -82
  2. package/dist/bundle.js +79181 -0
  3. package/dist/client/Nord.d.ts +13 -2
  4. package/dist/client/Nord.js +68 -78
  5. package/dist/client/NordAdmin.d.ts +2 -2
  6. package/dist/client/NordAdmin.js +57 -89
  7. package/dist/client/NordUser.js +118 -147
  8. package/dist/const.js +5 -8
  9. package/dist/error.js +7 -5
  10. package/dist/gen/nord_pb.js +88 -92
  11. package/dist/gen/openapi.d.ts +83 -6
  12. package/dist/gen/openapi.js +1 -2
  13. package/dist/index.js +10 -49
  14. package/dist/types.d.ts +3 -0
  15. package/dist/types.js +21 -60
  16. package/dist/utils.js +38 -86
  17. package/dist/websocket/NordWebSocketClient.js +12 -17
  18. package/dist/websocket/Subscriber.js +6 -7
  19. package/dist/websocket/events.js +1 -2
  20. package/dist/websocket/index.js +10 -15
  21. package/package.json +3 -4
  22. package/dist/api/client.d.ts +0 -14
  23. package/dist/api/client.js +0 -45
  24. package/dist/bridge/client.d.ts +0 -151
  25. package/dist/bridge/client.js +0 -434
  26. package/dist/bridge/const.d.ts +0 -23
  27. package/dist/bridge/const.js +0 -47
  28. package/dist/bridge/index.d.ts +0 -4
  29. package/dist/bridge/index.js +0 -23
  30. package/dist/bridge/types.d.ts +0 -120
  31. package/dist/bridge/types.js +0 -18
  32. package/dist/bridge/utils.d.ts +0 -64
  33. package/dist/bridge/utils.js +0 -131
  34. package/dist/gen/common.d.ts +0 -68
  35. package/dist/gen/common.js +0 -215
  36. package/dist/gen/nord.d.ts +0 -882
  37. package/dist/gen/nord.js +0 -6520
  38. package/dist/idl/bridge.d.ts +0 -569
  39. package/dist/idl/bridge.js +0 -8
  40. package/dist/idl/bridge.json +0 -1506
  41. package/dist/idl/index.d.ts +0 -607
  42. package/dist/idl/index.js +0 -8
  43. package/dist/nord/api/actions.d.ts +0 -126
  44. package/dist/nord/api/actions.js +0 -397
  45. package/dist/nord/api/core.d.ts +0 -16
  46. package/dist/nord/api/core.js +0 -81
  47. package/dist/nord/api/market.d.ts +0 -36
  48. package/dist/nord/api/market.js +0 -96
  49. package/dist/nord/api/metrics.d.ts +0 -67
  50. package/dist/nord/api/metrics.js +0 -229
  51. package/dist/nord/api/queries.d.ts +0 -46
  52. package/dist/nord/api/queries.js +0 -109
  53. package/dist/nord/api/triggers.d.ts +0 -7
  54. package/dist/nord/api/triggers.js +0 -38
  55. package/dist/nord/client/Nord.d.ts +0 -396
  56. package/dist/nord/client/Nord.js +0 -747
  57. package/dist/nord/client/NordAdmin.d.ts +0 -259
  58. package/dist/nord/client/NordAdmin.js +0 -395
  59. package/dist/nord/client/NordClient.d.ts +0 -33
  60. package/dist/nord/client/NordClient.js +0 -45
  61. package/dist/nord/client/NordUser.d.ts +0 -362
  62. package/dist/nord/client/NordUser.js +0 -781
  63. package/dist/nord/index.d.ts +0 -11
  64. package/dist/nord/index.js +0 -36
  65. package/dist/nord/models/Subscriber.d.ts +0 -37
  66. package/dist/nord/models/Subscriber.js +0 -25
  67. package/dist/nord/utils/NordError.d.ts +0 -35
  68. package/dist/nord/utils/NordError.js +0 -49
  69. package/src/actions.ts +0 -333
  70. package/src/client/Nord.ts +0 -934
  71. package/src/client/NordAdmin.ts +0 -484
  72. package/src/client/NordUser.ts +0 -1122
  73. package/src/const.ts +0 -34
  74. package/src/error.ts +0 -76
  75. package/src/gen/.gitkeep +0 -0
  76. package/src/gen/nord_pb.ts +0 -5053
  77. package/src/gen/openapi.ts +0 -2904
  78. package/src/index.ts +0 -11
  79. package/src/types.ts +0 -327
  80. package/src/utils.ts +0 -266
  81. package/src/websocket/NordWebSocketClient.ts +0 -316
  82. package/src/websocket/Subscriber.ts +0 -56
  83. package/src/websocket/events.ts +0 -31
  84. package/src/websocket/index.ts +0 -105
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.marketsStats = marketsStats;
4
- exports.getTrades = getTrades;
5
- exports.getUserAccountIds = getUserAccountIds;
6
- exports.getOrderbook = getOrderbook;
7
- const utils_1 = require("../../utils");
8
- const NordError_1 = require("../utils/NordError");
9
- /**
10
- * Get market statistics
11
- *
12
- * @param webServerUrl - Base URL for the Nord web server
13
- * @returns Market statistics response
14
- * @throws {NordError} If the request fails
15
- */
16
- async function marketsStats(webServerUrl) {
17
- try {
18
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/stats`);
19
- return await response.json();
20
- }
21
- catch (error) {
22
- throw new NordError_1.NordError("Failed to fetch markets stats", { cause: error });
23
- }
24
- }
25
- /**
26
- * Get trades for a market
27
- *
28
- * @param webServerUrl - Base URL for the Nord web server
29
- * @param query - Trades query parameters
30
- * @returns Trades response
31
- * @throws {NordError} If the request fails
32
- */
33
- async function getTrades(webServerUrl, query) {
34
- try {
35
- const params = new URLSearchParams();
36
- params.append("accountId", query.accountId.toString());
37
- if (query.since) {
38
- params.append("since", query.since);
39
- }
40
- if (query.until) {
41
- params.append("until", query.until);
42
- }
43
- if (query.pageId) {
44
- params.append("pageId", query.pageId);
45
- }
46
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/trades?${params.toString()}`);
47
- return await response.json();
48
- }
49
- catch (error) {
50
- throw new NordError_1.NordError("Failed to get trades", { cause: error });
51
- }
52
- }
53
- /**
54
- * Get user account IDs
55
- *
56
- * @param webServerUrl - Base URL for the Nord web server
57
- * @param query - User account IDs query parameters
58
- * @returns User account IDs response
59
- * @throws {NordError} If the request fails
60
- */
61
- async function getUserAccountIds(webServerUrl, query) {
62
- try {
63
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/user/${query.pubkey.toString()}`);
64
- return await response.json();
65
- }
66
- catch (error) {
67
- throw new NordError_1.NordError("Failed to get user account IDs", { cause: error });
68
- }
69
- }
70
- /**
71
- * Get orderbook for a market
72
- *
73
- * @param webServerUrl - Base URL for the Nord web server
74
- * @param query - Orderbook query parameters
75
- * @returns Orderbook response
76
- * @throws {NordError} If the request fails
77
- */
78
- async function getOrderbook(webServerUrl, query) {
79
- try {
80
- const params = new URLSearchParams();
81
- if (query.symbol) {
82
- params.append("symbol", query.symbol);
83
- }
84
- else if (query.market_id !== undefined) {
85
- params.append("market_id", query.market_id.toString());
86
- }
87
- else {
88
- throw new NordError_1.NordError("Either symbol or market_id must be provided for orderbook query");
89
- }
90
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/orderbook?${params.toString()}`);
91
- return await response.json();
92
- }
93
- catch (error) {
94
- throw new NordError_1.NordError("Failed to get orderbook", { cause: error });
95
- }
96
- }
@@ -1,67 +0,0 @@
1
- import { AggregateMetrics, PeakTpsPeriodUnit } from "../../types";
2
- /**
3
- * Time periods for metrics queries
4
- */
5
- export declare enum MetricPeriod {
6
- ONE_MINUTE = "1m",
7
- FIVE_MINUTES = "5m",
8
- FIFTEEN_MINUTES = "15m",
9
- ONE_HOUR = "1h",
10
- FOUR_HOURS = "4h",
11
- ONE_DAY = "24h",
12
- ONE_WEEK = "7d"
13
- }
14
- /**
15
- * Fetch aggregate metrics from the Nord API
16
- *
17
- * @param webServerUrl - Base URL for the Nord web server
18
- * @param txPeakTpsPeriod - Period for peak TPS calculation
19
- * @param txPeakTpsPeriodUnit - Unit for peak TPS period
20
- * @returns Aggregate metrics
21
- * @throws {NordError} If the request fails
22
- */
23
- export declare function aggregateMetrics(webServerUrl: string, txPeakTpsPeriod?: number, txPeakTpsPeriodUnit?: PeakTpsPeriodUnit): Promise<AggregateMetrics>;
24
- /**
25
- * Get current transactions per second
26
- *
27
- * @param webServerUrl - Base URL for the Nord web server
28
- * @param period - Time period for the query
29
- * @returns Current TPS value
30
- * @throws {NordError} If the request fails
31
- */
32
- export declare function getCurrentTps(webServerUrl: string, period?: string): Promise<number>;
33
- /**
34
- * Get peak transactions per second
35
- *
36
- * @param webServerUrl - Base URL for the Nord web server
37
- * @param period - Time period for the query
38
- * @returns Peak TPS value
39
- * @throws {NordError} If the request fails
40
- */
41
- export declare function getPeakTps(webServerUrl: string, period?: string): Promise<number>;
42
- /**
43
- * Get median transaction latency
44
- *
45
- * @param webServerUrl - Base URL for the Nord web server
46
- * @param period - Time period for the query
47
- * @returns Median latency in milliseconds
48
- * @throws {NordError} If the request fails
49
- */
50
- export declare function getMedianLatency(webServerUrl: string, period?: string): Promise<number>;
51
- /**
52
- * Get total transaction count
53
- *
54
- * @param webServerUrl - Base URL for the Nord web server
55
- * @returns Total transaction count
56
- * @throws {NordError} If the request fails
57
- */
58
- export declare function getTotalTransactions(webServerUrl: string): Promise<number>;
59
- /**
60
- * Query Prometheus metrics
61
- *
62
- * @param webServerUrl - Base URL for the Nord web server
63
- * @param params - Prometheus query parameters
64
- * @returns Query result as a number
65
- * @throws {NordError} If the request fails
66
- */
67
- export declare function queryPrometheus(webServerUrl: string, params: string): Promise<number>;
@@ -1,229 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MetricPeriod = void 0;
4
- exports.aggregateMetrics = aggregateMetrics;
5
- exports.getCurrentTps = getCurrentTps;
6
- exports.getPeakTps = getPeakTps;
7
- exports.getMedianLatency = getMedianLatency;
8
- exports.getTotalTransactions = getTotalTransactions;
9
- exports.queryPrometheus = queryPrometheus;
10
- const types_1 = require("../../types");
11
- const utils_1 = require("../../utils");
12
- const NordError_1 = require("../utils/NordError");
13
- /**
14
- * Time periods for metrics queries
15
- */
16
- var MetricPeriod;
17
- (function (MetricPeriod) {
18
- MetricPeriod["ONE_MINUTE"] = "1m";
19
- MetricPeriod["FIVE_MINUTES"] = "5m";
20
- MetricPeriod["FIFTEEN_MINUTES"] = "15m";
21
- MetricPeriod["ONE_HOUR"] = "1h";
22
- MetricPeriod["FOUR_HOURS"] = "4h";
23
- MetricPeriod["ONE_DAY"] = "24h";
24
- MetricPeriod["ONE_WEEK"] = "7d";
25
- })(MetricPeriod || (exports.MetricPeriod = MetricPeriod = {}));
26
- /**
27
- * Fetch aggregate metrics from the Nord API
28
- *
29
- * @param webServerUrl - Base URL for the Nord web server
30
- * @param txPeakTpsPeriod - Period for peak TPS calculation
31
- * @param txPeakTpsPeriodUnit - Unit for peak TPS period
32
- * @returns Aggregate metrics
33
- * @throws {NordError} If the request fails
34
- */
35
- async function aggregateMetrics(webServerUrl, txPeakTpsPeriod = 1, txPeakTpsPeriodUnit = types_1.PeakTpsPeriodUnit.Day) {
36
- try {
37
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/metrics?tx_peak_tps_period=${txPeakTpsPeriod}&tx_peak_tps_period_unit=${txPeakTpsPeriodUnit}`);
38
- // Get the raw text response (Prometheus format)
39
- const text = await response.text();
40
- // Parse the Prometheus-formatted metrics text into an AggregateMetrics object
41
- const metrics = {
42
- blocks_total: 0,
43
- tx_total: extractMetricValue(text, "nord_requests_ok_count"),
44
- tx_tps: calculateTps(text),
45
- tx_tps_peak: calculatePeakTps(text),
46
- request_latency_average: extractLatency(text),
47
- };
48
- return metrics;
49
- }
50
- catch (error) {
51
- throw new NordError_1.NordError("Failed to fetch aggregate metrics", { cause: error });
52
- }
53
- }
54
- /**
55
- * Extract a metric value from Prometheus-formatted text
56
- *
57
- * @param text - Prometheus-formatted metrics text
58
- * @param metricName - Name of the metric to extract
59
- * @returns The metric value as a number, or 0 if not found
60
- */
61
- function extractMetricValue(text, metricName) {
62
- const regex = new RegExp(`^${metricName}\\s+([\\d.]+)`, "m");
63
- const match = text.match(regex);
64
- return match ? parseFloat(match[1]) : 0;
65
- }
66
- /**
67
- * Calculate TPS from Prometheus metrics
68
- *
69
- * @param text - Prometheus-formatted metrics text
70
- * @returns Calculated TPS value
71
- */
72
- function calculateTps(text) {
73
- // Use the request count and latency to estimate TPS
74
- const requestCount = extractMetricValue(text, "nord_requests_ok_count");
75
- const latencySum = extractSummaryValue(text, "nord_requests_ok_latency_sum");
76
- const latencyCount = extractSummaryValue(text, "nord_requests_ok_latency_count");
77
- if (latencySum > 0 && latencyCount > 0) {
78
- // Average latency in seconds
79
- const avgLatency = latencySum / latencyCount;
80
- // If we have valid latency data, estimate TPS as requests per second
81
- return avgLatency > 0 ? requestCount / (latencyCount * avgLatency) : 0;
82
- }
83
- // Fallback: just return a small fraction of the total request count
84
- return requestCount > 0 ? requestCount / 100 : 0;
85
- }
86
- /**
87
- * Calculate peak TPS from Prometheus metrics
88
- *
89
- * @param text - Prometheus-formatted metrics text
90
- * @returns Calculated peak TPS value
91
- */
92
- function calculatePeakTps(text) {
93
- // For peak TPS, we'll use a simple heuristic: 2x the current TPS estimate
94
- // TODO: fix this
95
- return calculateTps(text) * 2;
96
- }
97
- /**
98
- * Extract latency from Prometheus metrics
99
- *
100
- * @param text - Prometheus-formatted metrics text
101
- * @returns Average latency in seconds
102
- */
103
- function extractLatency(text) {
104
- // TODO: fix - using average for latency is kinda wack. ok to merge for now but should change.
105
- const latencySum = extractSummaryValue(text, "nord_requests_ok_latency_sum");
106
- const latencyCount = extractSummaryValue(text, "nord_requests_ok_latency_count");
107
- return latencyCount > 0 ? latencySum / latencyCount : 0;
108
- }
109
- /**
110
- * Extract a summary value from Prometheus-formatted text
111
- *
112
- * @param text - Prometheus-formatted metrics text
113
- * @param metricName - Name of the metric to extract
114
- * @returns The metric value as a number, or 0 if not found
115
- */
116
- function extractSummaryValue(text, metricName) {
117
- const regex = new RegExp(`^${metricName}\\s+([\\d.]+)`, "m");
118
- const match = text.match(regex);
119
- return match ? parseFloat(match[1]) : 0;
120
- }
121
- /**
122
- * Get current transactions per second
123
- *
124
- * @param webServerUrl - Base URL for the Nord web server
125
- * @param period - Time period for the query
126
- * @returns Current TPS value
127
- * @throws {NordError} If the request fails
128
- */
129
- async function getCurrentTps(webServerUrl, period = "1m") {
130
- try {
131
- // nord_tx_count doesn't exist in the metrics, use nord_requests_ok_count instead
132
- return await queryPrometheus(webServerUrl, `sum(rate(nord_requests_ok_count[${period}]))`);
133
- }
134
- catch (error) {
135
- throw new NordError_1.NordError(`Failed to get current TPS for period ${period}`, {
136
- cause: error,
137
- });
138
- }
139
- }
140
- /**
141
- * Get peak transactions per second
142
- *
143
- * @param webServerUrl - Base URL for the Nord web server
144
- * @param period - Time period for the query
145
- * @returns Peak TPS value
146
- * @throws {NordError} If the request fails
147
- */
148
- async function getPeakTps(webServerUrl, period = "24h") {
149
- try {
150
- // nord_tx_count doesn't exist in the metrics, use nord_requests_ok_count instead
151
- return await queryPrometheus(webServerUrl, `max_over_time(sum(rate(nord_requests_ok_count[1m]))[${period}:])`);
152
- }
153
- catch (error) {
154
- throw new NordError_1.NordError(`Failed to get peak TPS for period ${period}`, {
155
- cause: error,
156
- });
157
- }
158
- }
159
- /**
160
- * Get median transaction latency
161
- *
162
- * @param webServerUrl - Base URL for the Nord web server
163
- * @param period - Time period for the query
164
- * @returns Median latency in milliseconds
165
- * @throws {NordError} If the request fails
166
- */
167
- async function getMedianLatency(webServerUrl, period = "1m") {
168
- try {
169
- // nord_tx_latency_ms doesn't exist, use nord_requests_ok_latency instead
170
- // which contains the latency data in the summary metric
171
- return await queryPrometheus(webServerUrl, `quantile_over_time(0.5, nord_requests_ok_latency[${period}]) * 1000`);
172
- }
173
- catch (error) {
174
- throw new NordError_1.NordError(`Failed to get median latency for period ${period}`, {
175
- cause: error,
176
- });
177
- }
178
- }
179
- /**
180
- * Get total transaction count
181
- *
182
- * @param webServerUrl - Base URL for the Nord web server
183
- * @returns Total transaction count
184
- * @throws {NordError} If the request fails
185
- */
186
- async function getTotalTransactions(webServerUrl) {
187
- try {
188
- // nord_tx_count doesn't exist, use nord_requests_ok_count instead
189
- return await queryPrometheus(webServerUrl, "sum(nord_requests_ok_count)");
190
- }
191
- catch (error) {
192
- throw new NordError_1.NordError("Failed to get total transactions", { cause: error });
193
- }
194
- }
195
- /**
196
- * Query Prometheus metrics
197
- *
198
- * @param webServerUrl - Base URL for the Nord web server
199
- * @param params - Prometheus query parameters
200
- * @returns Query result as a number
201
- * @throws {NordError} If the request fails
202
- */
203
- async function queryPrometheus(webServerUrl, params) {
204
- try {
205
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/prometheus?query=${encodeURIComponent(params)}`);
206
- // Handle raw text response
207
- const text = await response.text();
208
- try {
209
- // Try to parse as JSON first
210
- const data = JSON.parse(text);
211
- return data.data.result[0]?.value[1] || 0;
212
- }
213
- catch (error) {
214
- console.log("Prometheus query failed:", error);
215
- // Try to find a number in the response
216
- const numberMatch = text.match(/[\d.]+/);
217
- if (numberMatch) {
218
- return parseFloat(numberMatch[0]);
219
- }
220
- // Return 0 if no number is found
221
- return 0;
222
- }
223
- }
224
- catch (error) {
225
- throw new NordError_1.NordError(`Failed to query Prometheus: ${params}`, {
226
- cause: error,
227
- });
228
- }
229
- }
@@ -1,46 +0,0 @@
1
- import { ActionQuery, ActionResponse, ActionsResponse, RollmanActionResponse, RollmanActionsResponse } from "../../types";
2
- /**
3
- * Query a specific action
4
- *
5
- * @param webServerUrl - Base URL for the Nord web server
6
- * @param query - Action query parameters
7
- * @returns Action response
8
- * @throws {NordError} If the request fails
9
- */
10
- export declare function queryAction(webServerUrl: string, query: ActionQuery): Promise<ActionResponse>;
11
- /**
12
- * Query recent actions
13
- *
14
- * @param webServerUrl - Base URL for the Nord web server
15
- * @param from - Starting action index
16
- * @param to - Ending action index
17
- * @returns Actions response
18
- * @throws {NordError} If the request fails
19
- */
20
- export declare function queryRecentActions(webServerUrl: string, from: number, to: number): Promise<ActionsResponse>;
21
- /**
22
- * Get the last action ID
23
- *
24
- * @param webServerUrl - Base URL for the Nord web server
25
- * @returns Last action ID
26
- * @throws {NordError} If the request fails
27
- */
28
- export declare function getLastActionId(webServerUrl: string): Promise<number>;
29
- /**
30
- * Query an action from Rollman
31
- *
32
- * @param webServerUrl - Base URL for the Nord web server
33
- * @param query - Action query parameters
34
- * @returns Rollman action response
35
- * @throws {NordError} If the request fails
36
- */
37
- export declare function actionQueryRollman(webServerUrl: string, query: ActionQuery): Promise<RollmanActionResponse>;
38
- /**
39
- * Query actions from Rollman
40
- *
41
- * @param webServerUrl - Base URL for the Nord web server
42
- * @param last_n - Number of recent actions to query
43
- * @returns Rollman actions response
44
- * @throws {NordError} If the request fails
45
- */
46
- export declare function actionsQueryRollman(webServerUrl: string, last_n: number): Promise<RollmanActionsResponse>;
@@ -1,109 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.queryAction = queryAction;
4
- exports.queryRecentActions = queryRecentActions;
5
- exports.getLastActionId = getLastActionId;
6
- exports.actionQueryRollman = actionQueryRollman;
7
- exports.actionsQueryRollman = actionsQueryRollman;
8
- const utils_1 = require("../../utils");
9
- const NordError_1 = require("../utils/NordError");
10
- /**
11
- * Query a specific action
12
- *
13
- * @param webServerUrl - Base URL for the Nord web server
14
- * @param query - Action query parameters
15
- * @returns Action response
16
- * @throws {NordError} If the request fails
17
- */
18
- async function queryAction(webServerUrl, query) {
19
- try {
20
- const params = new URLSearchParams();
21
- if (query.action_id !== undefined) {
22
- params.append("action_id", query.action_id.toString());
23
- }
24
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/action?${params.toString()}`);
25
- return await response.json();
26
- }
27
- catch (error) {
28
- throw new NordError_1.NordError("Failed to query action", { cause: error });
29
- }
30
- }
31
- /**
32
- * Query recent actions
33
- *
34
- * @param webServerUrl - Base URL for the Nord web server
35
- * @param from - Starting action index
36
- * @param to - Ending action index
37
- * @returns Actions response
38
- * @throws {NordError} If the request fails
39
- */
40
- async function queryRecentActions(webServerUrl, from, to) {
41
- try {
42
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/actions?from=${from}&to=${to}`);
43
- return await response.json();
44
- }
45
- catch (error) {
46
- throw new NordError_1.NordError(`Failed to query recent actions (from ${from} to ${to})`, {
47
- cause: error,
48
- });
49
- }
50
- }
51
- /**
52
- * Get the last action ID
53
- *
54
- * @param webServerUrl - Base URL for the Nord web server
55
- * @returns Last action ID
56
- * @throws {NordError} If the request fails
57
- */
58
- async function getLastActionId(webServerUrl) {
59
- try {
60
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/actions/last-id`);
61
- const data = await response.json();
62
- return data;
63
- }
64
- catch (error) {
65
- throw new NordError_1.NordError("Failed to get last action ID", {
66
- cause: error,
67
- });
68
- }
69
- }
70
- /**
71
- * Query an action from Rollman
72
- *
73
- * @param webServerUrl - Base URL for the Nord web server
74
- * @param query - Action query parameters
75
- * @returns Rollman action response
76
- * @throws {NordError} If the request fails
77
- */
78
- async function actionQueryRollman(webServerUrl, query) {
79
- try {
80
- const params = new URLSearchParams();
81
- if (query.action_id !== undefined) {
82
- params.append("action_id", query.action_id.toString());
83
- }
84
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/rollman/action?${params.toString()}`);
85
- return await response.json();
86
- }
87
- catch (error) {
88
- throw new NordError_1.NordError("Failed to query Rollman action", { cause: error });
89
- }
90
- }
91
- /**
92
- * Query actions from Rollman
93
- *
94
- * @param webServerUrl - Base URL for the Nord web server
95
- * @param last_n - Number of recent actions to query
96
- * @returns Rollman actions response
97
- * @throws {NordError} If the request fails
98
- */
99
- async function actionsQueryRollman(webServerUrl, last_n) {
100
- try {
101
- const response = await (0, utils_1.checkedFetch)(`${webServerUrl}/rollman/actions?last_n=${last_n}`);
102
- return await response.json();
103
- }
104
- catch (error) {
105
- throw new NordError_1.NordError(`Failed to query Rollman actions (last ${last_n})`, {
106
- cause: error,
107
- });
108
- }
109
- }
@@ -1,7 +0,0 @@
1
- import { components } from "../../gen/openapi";
2
- type AccountTriggerInfo = components["schemas"]["AccountTriggerInfo"];
3
- type TriggerHistoryPage = components["schemas"]["PageResult_for_uint64_and_HistoryTriggerInfo"];
4
- type HistoryTriggerQuery = components["schemas"]["AccountTriggersQuery"];
5
- export type { AccountTriggerInfo, TriggerHistoryPage, HistoryTriggerQuery };
6
- export declare function getAccountTriggers(serverUrl: string, accountId: number): Promise<AccountTriggerInfo[]>;
7
- export declare function getAccountTriggerHistory(serverUrl: string, accountId: number, options: HistoryTriggerQuery): Promise<TriggerHistoryPage>;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getAccountTriggers = getAccountTriggers;
7
- exports.getAccountTriggerHistory = getAccountTriggerHistory;
8
- const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
9
- async function getAccountTriggers(serverUrl, accountId) {
10
- const client = (0, openapi_fetch_1.default)({ baseUrl: serverUrl });
11
- const response = await client.GET("/account/{account_id}/triggers", {
12
- params: {
13
- path: { account_id: accountId },
14
- },
15
- });
16
- if (response.data === undefined) {
17
- throw new Error(`Failed to fetch triggers for account ${accountId}: HTTP ${response.response.status}`);
18
- }
19
- return response.data ?? [];
20
- }
21
- async function getAccountTriggerHistory(serverUrl, accountId, options) {
22
- const client = (0, openapi_fetch_1.default)({ baseUrl: serverUrl });
23
- const response = await client.GET("/account/{account_id}/triggers/history", {
24
- params: {
25
- path: { account_id: accountId },
26
- query: {
27
- since: options.since,
28
- until: options.until,
29
- pageSize: options.pageSize,
30
- startInclusive: options.startInclusive,
31
- },
32
- },
33
- });
34
- if (!response.data) {
35
- throw new Error(`Failed to fetch trigger history for account ${accountId}: HTTP ${response.response.status}`);
36
- }
37
- return response.data;
38
- }