@agentuity/server 0.1.15 → 0.1.17
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/dist/api/api.d.ts +11 -6
- package/dist/api/api.d.ts.map +1 -1
- package/dist/api/api.js +19 -12
- package/dist/api/api.js.map +1 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/org/env-delete.d.ts +16 -0
- package/dist/api/org/env-delete.d.ts.map +1 -0
- package/dist/api/org/env-delete.js +25 -0
- package/dist/api/org/env-delete.js.map +1 -0
- package/dist/api/org/env-get.d.ts +20 -0
- package/dist/api/org/env-get.d.ts.map +1 -0
- package/dist/api/org/env-get.js +26 -0
- package/dist/api/org/env-get.js.map +1 -0
- package/dist/api/org/env-update.d.ts +17 -0
- package/dist/api/org/env-update.d.ts.map +1 -0
- package/dist/api/org/env-update.js +26 -0
- package/dist/api/org/env-update.js.map +1 -0
- package/dist/api/org/index.d.ts +3 -0
- package/dist/api/org/index.d.ts.map +1 -1
- package/dist/api/org/index.js +3 -0
- package/dist/api/org/index.js.map +1 -1
- package/dist/api/queue/analytics.d.ts +108 -0
- package/dist/api/queue/analytics.d.ts.map +1 -0
- package/dist/api/queue/analytics.js +245 -0
- package/dist/api/queue/analytics.js.map +1 -0
- package/dist/api/queue/destinations.d.ts +108 -0
- package/dist/api/queue/destinations.d.ts.map +1 -0
- package/dist/api/queue/destinations.js +238 -0
- package/dist/api/queue/destinations.js.map +1 -0
- package/dist/api/queue/dlq.d.ts +100 -0
- package/dist/api/queue/dlq.d.ts.map +1 -0
- package/dist/api/queue/dlq.js +204 -0
- package/dist/api/queue/dlq.js.map +1 -0
- package/dist/api/queue/index.d.ts +55 -0
- package/dist/api/queue/index.d.ts.map +1 -0
- package/dist/api/queue/index.js +86 -0
- package/dist/api/queue/index.js.map +1 -0
- package/dist/api/queue/messages.d.ts +332 -0
- package/dist/api/queue/messages.d.ts.map +1 -0
- package/dist/api/queue/messages.js +637 -0
- package/dist/api/queue/messages.js.map +1 -0
- package/dist/api/queue/queues.d.ts +153 -0
- package/dist/api/queue/queues.d.ts.map +1 -0
- package/dist/api/queue/queues.js +319 -0
- package/dist/api/queue/queues.js.map +1 -0
- package/dist/api/queue/sources.d.ts +132 -0
- package/dist/api/queue/sources.d.ts.map +1 -0
- package/dist/api/queue/sources.js +285 -0
- package/dist/api/queue/sources.js.map +1 -0
- package/dist/api/queue/types.d.ts +1129 -0
- package/dist/api/queue/types.d.ts.map +1 -0
- package/dist/api/queue/types.js +949 -0
- package/dist/api/queue/types.js.map +1 -0
- package/dist/api/queue/util.d.ts +262 -0
- package/dist/api/queue/util.d.ts.map +1 -0
- package/dist/api/queue/util.js +171 -0
- package/dist/api/queue/util.js.map +1 -0
- package/dist/api/queue/validation.d.ts +247 -0
- package/dist/api/queue/validation.d.ts.map +1 -0
- package/dist/api/queue/validation.js +513 -0
- package/dist/api/queue/validation.js.map +1 -0
- package/dist/api/sandbox/client.d.ts +56 -2
- package/dist/api/sandbox/client.d.ts.map +1 -1
- package/dist/api/sandbox/client.js +51 -0
- package/dist/api/sandbox/client.js.map +1 -1
- package/dist/api/sandbox/get.d.ts.map +1 -1
- package/dist/api/sandbox/get.js +5 -0
- package/dist/api/sandbox/get.js.map +1 -1
- package/dist/api/sandbox/index.d.ts +3 -3
- package/dist/api/sandbox/index.d.ts.map +1 -1
- package/dist/api/sandbox/index.js +1 -1
- package/dist/api/sandbox/index.js.map +1 -1
- package/dist/api/sandbox/run.d.ts.map +1 -1
- package/dist/api/sandbox/run.js +5 -2
- package/dist/api/sandbox/run.js.map +1 -1
- package/dist/api/sandbox/runtime.d.ts.map +1 -1
- package/dist/api/sandbox/runtime.js +14 -0
- package/dist/api/sandbox/runtime.js.map +1 -1
- package/dist/api/sandbox/snapshot-build.d.ts +2 -0
- package/dist/api/sandbox/snapshot-build.d.ts.map +1 -1
- package/dist/api/sandbox/snapshot-build.js +4 -0
- package/dist/api/sandbox/snapshot-build.js.map +1 -1
- package/dist/api/sandbox/snapshot.d.ts +44 -1
- package/dist/api/sandbox/snapshot.d.ts.map +1 -1
- package/dist/api/sandbox/snapshot.js +77 -4
- package/dist/api/sandbox/snapshot.js.map +1 -1
- package/package.json +4 -4
- package/src/api/api.ts +62 -13
- package/src/api/index.ts +1 -0
- package/src/api/org/env-delete.ts +37 -0
- package/src/api/org/env-get.ts +43 -0
- package/src/api/org/env-update.ts +38 -0
- package/src/api/org/index.ts +3 -0
- package/src/api/queue/analytics.ts +313 -0
- package/src/api/queue/destinations.ts +321 -0
- package/src/api/queue/dlq.ts +283 -0
- package/src/api/queue/index.ts +261 -0
- package/src/api/queue/messages.ts +875 -0
- package/src/api/queue/queues.ts +448 -0
- package/src/api/queue/sources.ts +384 -0
- package/src/api/queue/types.ts +1253 -0
- package/src/api/queue/util.ts +204 -0
- package/src/api/queue/validation.ts +560 -0
- package/src/api/sandbox/client.ts +86 -1
- package/src/api/sandbox/get.ts +5 -0
- package/src/api/sandbox/index.ts +9 -1
- package/src/api/sandbox/run.ts +5 -2
- package/src/api/sandbox/runtime.ts +15 -0
- package/src/api/sandbox/snapshot-build.ts +4 -0
- package/src/api/sandbox/snapshot.ts +96 -5
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema } from '../api';
|
|
3
|
+
import { OrgAnalyticsSchema, QueueAnalyticsSchema, TimeSeriesDataSchema, SSEStatsEventSchema, } from './types';
|
|
4
|
+
import { QueueError, QueueNotFoundError, queueApiPathWithQuery, buildQueueHeaders } from './util';
|
|
5
|
+
import { validateQueueName } from './validation';
|
|
6
|
+
const OrgAnalyticsResponseSchema = APIResponseSchema(z.object({ analytics: OrgAnalyticsSchema }));
|
|
7
|
+
const QueueAnalyticsResponseSchema = APIResponseSchema(z.object({ analytics: QueueAnalyticsSchema }));
|
|
8
|
+
const TimeSeriesResponseSchema = APIResponseSchema(z.object({ timeseries: TimeSeriesDataSchema }));
|
|
9
|
+
/**
|
|
10
|
+
* Build query string from analytics options.
|
|
11
|
+
*/
|
|
12
|
+
function buildAnalyticsQuery(options) {
|
|
13
|
+
if (!options)
|
|
14
|
+
return undefined;
|
|
15
|
+
const params = new URLSearchParams();
|
|
16
|
+
if (options.start)
|
|
17
|
+
params.set('start', options.start);
|
|
18
|
+
if (options.end)
|
|
19
|
+
params.set('end', options.end);
|
|
20
|
+
if (options.granularity)
|
|
21
|
+
params.set('granularity', options.granularity);
|
|
22
|
+
if (options.projectId)
|
|
23
|
+
params.set('project_id', options.projectId);
|
|
24
|
+
if (options.agentId)
|
|
25
|
+
params.set('agent_id', options.agentId);
|
|
26
|
+
const query = params.toString();
|
|
27
|
+
return query || undefined;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get org-level analytics for all queues.
|
|
31
|
+
*
|
|
32
|
+
* Returns aggregated statistics across all queues in the organization.
|
|
33
|
+
*
|
|
34
|
+
* @param client - The API client instance
|
|
35
|
+
* @param options - Analytics options (time range, filters)
|
|
36
|
+
* @returns Org-level analytics summary
|
|
37
|
+
* @throws {QueueError} If the API request fails
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const analytics = await getOrgAnalytics(client, {
|
|
42
|
+
* start: '2026-01-14T00:00:00Z',
|
|
43
|
+
* end: '2026-01-15T00:00:00Z',
|
|
44
|
+
* });
|
|
45
|
+
* console.log(`Total queues: ${analytics.summary.total_queues}`);
|
|
46
|
+
* console.log(`Messages published: ${analytics.summary.total_messages_published}`);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export async function getOrgAnalytics(client, options) {
|
|
50
|
+
const queryString = buildAnalyticsQuery(options);
|
|
51
|
+
const url = queueApiPathWithQuery('analytics/org', queryString);
|
|
52
|
+
const resp = await client.get(url, OrgAnalyticsResponseSchema, undefined, buildQueueHeaders(options?.orgId));
|
|
53
|
+
if (resp.success) {
|
|
54
|
+
return resp.data.analytics;
|
|
55
|
+
}
|
|
56
|
+
throw new QueueError({
|
|
57
|
+
message: resp.message || 'Failed to get org analytics',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get detailed analytics for a specific queue.
|
|
62
|
+
*
|
|
63
|
+
* Returns current state, period statistics, latency metrics, and destination stats.
|
|
64
|
+
*
|
|
65
|
+
* @param client - The API client instance
|
|
66
|
+
* @param name - The queue name
|
|
67
|
+
* @param options - Analytics options (time range, filters)
|
|
68
|
+
* @returns Queue analytics
|
|
69
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
70
|
+
* @throws {QueueError} If the API request fails
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const analytics = await getQueueAnalytics(client, 'order-processing', {
|
|
75
|
+
* start: '2026-01-14T00:00:00Z',
|
|
76
|
+
* });
|
|
77
|
+
* console.log(`Backlog: ${analytics.current.backlog}`);
|
|
78
|
+
* console.log(`P95 latency: ${analytics.latency.p95_ms}ms`);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export async function getQueueAnalytics(client, name, options) {
|
|
82
|
+
validateQueueName(name);
|
|
83
|
+
const queryString = buildAnalyticsQuery(options);
|
|
84
|
+
const url = queueApiPathWithQuery('analytics/queue', queryString, name);
|
|
85
|
+
const resp = await client.get(url, QueueAnalyticsResponseSchema, undefined, buildQueueHeaders(options?.orgId));
|
|
86
|
+
if (resp.success) {
|
|
87
|
+
return resp.data.analytics;
|
|
88
|
+
}
|
|
89
|
+
if (resp.message?.includes('not found')) {
|
|
90
|
+
throw new QueueNotFoundError({
|
|
91
|
+
queueName: name,
|
|
92
|
+
message: resp.message,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
throw new QueueError({
|
|
96
|
+
queueName: name,
|
|
97
|
+
message: resp.message || 'Failed to get queue analytics',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get time series analytics data for a queue.
|
|
102
|
+
*
|
|
103
|
+
* Returns time-bucketed metrics for visualization in charts and graphs.
|
|
104
|
+
*
|
|
105
|
+
* @param client - The API client instance
|
|
106
|
+
* @param name - The queue name
|
|
107
|
+
* @param options - Analytics options (time range, granularity)
|
|
108
|
+
* @returns Time series data
|
|
109
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
110
|
+
* @throws {QueueError} If the API request fails
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const timeseries = await getQueueTimeSeries(client, 'order-processing', {
|
|
115
|
+
* granularity: 'hour',
|
|
116
|
+
* start: '2026-01-14T00:00:00Z',
|
|
117
|
+
* });
|
|
118
|
+
* for (const point of timeseries.series) {
|
|
119
|
+
* console.log(`${point.timestamp}: ${point.throughput} msg/h`);
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export async function getQueueTimeSeries(client, name, options) {
|
|
124
|
+
validateQueueName(name);
|
|
125
|
+
const queryString = buildAnalyticsQuery(options);
|
|
126
|
+
const url = queueApiPathWithQuery('analytics/timeseries', queryString, name);
|
|
127
|
+
const resp = await client.get(url, TimeSeriesResponseSchema, undefined, buildQueueHeaders(options?.orgId));
|
|
128
|
+
if (resp.success) {
|
|
129
|
+
return resp.data.timeseries;
|
|
130
|
+
}
|
|
131
|
+
if (resp.message?.includes('not found')) {
|
|
132
|
+
throw new QueueNotFoundError({
|
|
133
|
+
queueName: name,
|
|
134
|
+
message: resp.message,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
throw new QueueError({
|
|
138
|
+
queueName: name,
|
|
139
|
+
message: resp.message || 'Failed to get queue time series',
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Stream real-time analytics for all queues via SSE.
|
|
144
|
+
*
|
|
145
|
+
* Returns an async iterator that yields stats events at the specified interval.
|
|
146
|
+
* The connection stays open until the iterator is closed or an error occurs.
|
|
147
|
+
*
|
|
148
|
+
* @param client - The API client instance
|
|
149
|
+
* @param options - Stream options (interval, orgId)
|
|
150
|
+
* @returns Async iterator of SSE stats events
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const stream = streamOrgAnalytics(client, { interval: 5 });
|
|
155
|
+
* for await (const event of stream) {
|
|
156
|
+
* console.log(`Backlog: ${event.backlog}, Throughput: ${event.throughput_1m}/min`);
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export async function* streamOrgAnalytics(client, options) {
|
|
161
|
+
const params = new URLSearchParams();
|
|
162
|
+
if (options?.interval)
|
|
163
|
+
params.set('interval', String(options.interval));
|
|
164
|
+
const queryString = params.toString() || undefined;
|
|
165
|
+
const url = queueApiPathWithQuery('analytics/stream', queryString);
|
|
166
|
+
yield* streamSSE(client, url, options?.orgId);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Stream real-time analytics for a specific queue via SSE.
|
|
170
|
+
*
|
|
171
|
+
* Returns an async iterator that yields stats events at the specified interval.
|
|
172
|
+
*
|
|
173
|
+
* @param client - The API client instance
|
|
174
|
+
* @param name - The queue name
|
|
175
|
+
* @param options - Stream options (interval, orgId)
|
|
176
|
+
* @returns Async iterator of SSE stats events
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* const stream = streamQueueAnalytics(client, 'order-processing', { interval: 5 });
|
|
181
|
+
* for await (const event of stream) {
|
|
182
|
+
* console.log(`Backlog: ${event.backlog}, In-flight: ${event.messages_in_flight}`);
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export async function* streamQueueAnalytics(client, name, options) {
|
|
187
|
+
validateQueueName(name);
|
|
188
|
+
const params = new URLSearchParams();
|
|
189
|
+
if (options?.interval)
|
|
190
|
+
params.set('interval', String(options.interval));
|
|
191
|
+
const queryString = params.toString() || undefined;
|
|
192
|
+
const url = queueApiPathWithQuery('analytics/stream', queryString, name);
|
|
193
|
+
yield* streamSSE(client, url, options?.orgId, name);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Internal helper to stream SSE events from a URL.
|
|
197
|
+
* Uses rawGet for streaming response access.
|
|
198
|
+
*/
|
|
199
|
+
async function* streamSSE(client, url, orgId, queueName) {
|
|
200
|
+
const response = await client.rawGet(url, undefined, buildQueueHeaders(orgId));
|
|
201
|
+
if (!response.ok) {
|
|
202
|
+
if (response.status === 404 && queueName) {
|
|
203
|
+
throw new QueueNotFoundError({ queueName });
|
|
204
|
+
}
|
|
205
|
+
throw new QueueError({
|
|
206
|
+
message: `SSE connection failed: ${response.status} ${response.statusText}`,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
const reader = response.body?.getReader();
|
|
210
|
+
if (!reader) {
|
|
211
|
+
throw new QueueError({ message: 'No response body for SSE stream' });
|
|
212
|
+
}
|
|
213
|
+
const decoder = new TextDecoder();
|
|
214
|
+
let buffer = '';
|
|
215
|
+
try {
|
|
216
|
+
while (true) {
|
|
217
|
+
const { done, value } = await reader.read();
|
|
218
|
+
if (done)
|
|
219
|
+
break;
|
|
220
|
+
buffer += decoder.decode(value, { stream: true });
|
|
221
|
+
const lines = buffer.split('\n');
|
|
222
|
+
buffer = lines.pop() || '';
|
|
223
|
+
for (const line of lines) {
|
|
224
|
+
if (line.startsWith('data: ')) {
|
|
225
|
+
const jsonStr = line.slice(6).trim();
|
|
226
|
+
if (jsonStr && jsonStr !== '{}') {
|
|
227
|
+
try {
|
|
228
|
+
const parsed = JSON.parse(jsonStr);
|
|
229
|
+
const event = SSEStatsEventSchema.parse(parsed);
|
|
230
|
+
yield event;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
// Skip malformed events
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
await reader.cancel();
|
|
242
|
+
reader.releaseLock();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../../src/api/queue/analytics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EACN,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,mBAAmB,GAOnB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAClG,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,0BAA0B,GAAG,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC;AAClG,MAAM,4BAA4B,GAAG,iBAAiB,CACrD,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,oBAAoB,EAAE,CAAC,CAC7C,CAAC;AACF,MAAM,wBAAwB,GAAG,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC,CAAC,CAAC;AAEnG;;GAEG;AACH,SAAS,mBAAmB,CAAC,OAA0B;IACtD,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAE/B,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,IAAI,OAAO,CAAC,KAAK;QAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,OAAO,CAAC,GAAG;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,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAClD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YACjC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;YAE3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBAC1B,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;oBACrC,IAAI,OAAO,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;wBACjC,IAAI,CAAC;4BACJ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;4BACnC,MAAM,KAAK,GAAG,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;4BAChD,MAAM,KAAK,CAAC;wBACb,CAAC;wBAAC,MAAM,CAAC;4BACR,wBAAwB;wBACzB,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;YAAS,CAAC;QACV,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;QACtB,MAAM,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { APIClient } from '../api';
|
|
2
|
+
import { type Destination, type CreateDestinationRequest, type UpdateDestinationRequest, type QueueApiOptions } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Create a destination for a queue.
|
|
5
|
+
*
|
|
6
|
+
* Destinations are webhook endpoints that automatically receive messages when
|
|
7
|
+
* they are published to a queue. When a message is published, it will be
|
|
8
|
+
* delivered via HTTP POST to all active destinations configured for that queue.
|
|
9
|
+
*
|
|
10
|
+
* @param client - The API client instance
|
|
11
|
+
* @param queueName - The name of the queue to add the destination to
|
|
12
|
+
* @param params - Destination configuration including URL and optional settings
|
|
13
|
+
* @returns The created destination with assigned ID
|
|
14
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name or config)
|
|
15
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
16
|
+
* @throws {QueueError} If the API request fails
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const destination = await createDestination(client, 'order-events', {
|
|
21
|
+
* url: 'https://api.example.com/webhooks/orders',
|
|
22
|
+
* config: {
|
|
23
|
+
* retry_attempts: 3,
|
|
24
|
+
* timeout_seconds: 30,
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* console.log(`Created destination ${destination.id}`);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function createDestination(client: APIClient, queueName: string, params: CreateDestinationRequest, options?: QueueApiOptions): Promise<Destination>;
|
|
31
|
+
/**
|
|
32
|
+
* List all destinations for a queue.
|
|
33
|
+
*
|
|
34
|
+
* Retrieves all webhook destinations configured for a queue. Each destination
|
|
35
|
+
* represents an endpoint that receives messages when they are published.
|
|
36
|
+
*
|
|
37
|
+
* @param client - The API client instance
|
|
38
|
+
* @param queueName - The name of the queue
|
|
39
|
+
* @returns Array of destinations configured for the queue
|
|
40
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name)
|
|
41
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
42
|
+
* @throws {QueueError} If the API request fails
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const destinations = await listDestinations(client, 'order-events');
|
|
47
|
+
* for (const dest of destinations) {
|
|
48
|
+
* console.log(`Destination ${dest.id}: ${dest.url} (${dest.enabled ? 'enabled' : 'disabled'})`);
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function listDestinations(client: APIClient, queueName: string, options?: QueueApiOptions): Promise<Destination[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Update a destination's configuration.
|
|
55
|
+
*
|
|
56
|
+
* Modifies an existing destination's settings such as URL, enabled status,
|
|
57
|
+
* or retry configuration. Only the fields provided in params will be updated.
|
|
58
|
+
*
|
|
59
|
+
* @param client - The API client instance
|
|
60
|
+
* @param queueName - The name of the queue
|
|
61
|
+
* @param destinationId - The destination ID to update (prefixed with dest_)
|
|
62
|
+
* @param params - Fields to update (partial update supported)
|
|
63
|
+
* @returns The updated destination
|
|
64
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name, destination ID, or config)
|
|
65
|
+
* @throws {DestinationNotFoundError} If the destination does not exist
|
|
66
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
67
|
+
* @throws {QueueError} If the API request fails
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Disable a destination temporarily
|
|
72
|
+
* const updated = await updateDestination(client, 'order-events', 'dest_abc123', {
|
|
73
|
+
* enabled: false,
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Update URL and retry settings
|
|
77
|
+
* const updated = await updateDestination(client, 'order-events', 'dest_abc123', {
|
|
78
|
+
* url: 'https://api.example.com/v2/webhooks/orders',
|
|
79
|
+
* config: {
|
|
80
|
+
* retry_attempts: 5,
|
|
81
|
+
* },
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function updateDestination(client: APIClient, queueName: string, destinationId: string, params: UpdateDestinationRequest, options?: QueueApiOptions): Promise<Destination>;
|
|
86
|
+
/**
|
|
87
|
+
* Delete a destination from a queue.
|
|
88
|
+
*
|
|
89
|
+
* Permanently removes a webhook destination. Messages will no longer be
|
|
90
|
+
* delivered to this endpoint. This action cannot be undone.
|
|
91
|
+
*
|
|
92
|
+
* @param client - The API client instance
|
|
93
|
+
* @param queueName - The name of the queue
|
|
94
|
+
* @param destinationId - The destination ID to delete (prefixed with dest_)
|
|
95
|
+
* @returns void
|
|
96
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name or destination ID)
|
|
97
|
+
* @throws {DestinationNotFoundError} If the destination does not exist
|
|
98
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
99
|
+
* @throws {QueueError} If the API request fails
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* await deleteDestination(client, 'order-events', 'dest_abc123');
|
|
104
|
+
* console.log('Destination deleted');
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function deleteDestination(client: APIClient, queueName: string, destinationId: string, options?: QueueApiOptions): Promise<void>;
|
|
108
|
+
//# sourceMappingURL=destinations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destinations.d.ts","sourceRoot":"","sources":["../../../src/api/queue/destinations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAwD,MAAM,QAAQ,CAAC;AACzF,OAAO,EAEN,KAAK,WAAW,EAChB,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,eAAe,EAGpB,MAAM,SAAS,CAAC;AAmBjB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,iBAAiB,CACtC,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,WAAW,CAAC,CAgEtB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,WAAW,EAAE,CAAC,CAyBxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,iBAAiB,CACtC,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,wBAAwB,EAChC,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,WAAW,CAAC,CAwCtB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,iBAAiB,CACtC,MAAM,EAAE,SAAS,EACjB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,eAAe,GACvB,OAAO,CAAC,IAAI,CAAC,CAmCf"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { APIResponseSchema, APIResponseSchemaNoData, APIError } from '../api';
|
|
3
|
+
import { DestinationSchema, CreateDestinationRequestSchema, UpdateDestinationRequestSchema, } from './types';
|
|
4
|
+
import { QueueError, QueueNotFoundError, DestinationNotFoundError, DestinationAlreadyExistsError, queueApiPath, buildQueueHeaders, } from './util';
|
|
5
|
+
import { validateQueueName, validateDestinationId, validateDestinationConfig } from './validation';
|
|
6
|
+
const DestinationResponseSchema = APIResponseSchema(z.object({ destination: DestinationSchema }));
|
|
7
|
+
const DestinationsListResponseSchema = APIResponseSchema(z.object({
|
|
8
|
+
destinations: z.array(DestinationSchema),
|
|
9
|
+
}));
|
|
10
|
+
const DeleteDestinationResponseSchema = APIResponseSchemaNoData();
|
|
11
|
+
/**
|
|
12
|
+
* Create a destination for a queue.
|
|
13
|
+
*
|
|
14
|
+
* Destinations are webhook endpoints that automatically receive messages when
|
|
15
|
+
* they are published to a queue. When a message is published, it will be
|
|
16
|
+
* delivered via HTTP POST to all active destinations configured for that queue.
|
|
17
|
+
*
|
|
18
|
+
* @param client - The API client instance
|
|
19
|
+
* @param queueName - The name of the queue to add the destination to
|
|
20
|
+
* @param params - Destination configuration including URL and optional settings
|
|
21
|
+
* @returns The created destination with assigned ID
|
|
22
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name or config)
|
|
23
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
24
|
+
* @throws {QueueError} If the API request fails
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const destination = await createDestination(client, 'order-events', {
|
|
29
|
+
* url: 'https://api.example.com/webhooks/orders',
|
|
30
|
+
* config: {
|
|
31
|
+
* retry_attempts: 3,
|
|
32
|
+
* timeout_seconds: 30,
|
|
33
|
+
* },
|
|
34
|
+
* });
|
|
35
|
+
* console.log(`Created destination ${destination.id}`);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export async function createDestination(client, queueName, params, options) {
|
|
39
|
+
validateQueueName(queueName);
|
|
40
|
+
if (params.config) {
|
|
41
|
+
validateDestinationConfig(params.config);
|
|
42
|
+
}
|
|
43
|
+
const url = queueApiPath('destinations/create', queueName);
|
|
44
|
+
try {
|
|
45
|
+
const resp = await client.post(url, params, DestinationResponseSchema, CreateDestinationRequestSchema, undefined, buildQueueHeaders(options?.orgId));
|
|
46
|
+
if (resp.success) {
|
|
47
|
+
return resp.data.destination;
|
|
48
|
+
}
|
|
49
|
+
if (resp.message?.includes('queue') && resp.message?.includes('not found')) {
|
|
50
|
+
throw new QueueNotFoundError({
|
|
51
|
+
queueName,
|
|
52
|
+
message: resp.message,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (resp.message?.includes('already exists')) {
|
|
56
|
+
throw new DestinationAlreadyExistsError({
|
|
57
|
+
queueName,
|
|
58
|
+
url: params.config?.url,
|
|
59
|
+
message: `A destination with URL "${params.config?.url}" already exists for queue "${queueName}"`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
throw new QueueError({
|
|
63
|
+
queueName,
|
|
64
|
+
message: resp.message || 'Failed to create destination',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof APIError) {
|
|
69
|
+
const message = error.message || '';
|
|
70
|
+
if (message.includes('already exists')) {
|
|
71
|
+
throw new DestinationAlreadyExistsError({
|
|
72
|
+
queueName,
|
|
73
|
+
url: params.config?.url,
|
|
74
|
+
message: `A destination with URL "${params.config?.url}" already exists for queue "${queueName}"`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
if (message.includes('queue') && message.includes('not found')) {
|
|
78
|
+
throw new QueueNotFoundError({
|
|
79
|
+
queueName,
|
|
80
|
+
message,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
throw new QueueError({
|
|
84
|
+
queueName,
|
|
85
|
+
message: message || 'Failed to create destination',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* List all destinations for a queue.
|
|
93
|
+
*
|
|
94
|
+
* Retrieves all webhook destinations configured for a queue. Each destination
|
|
95
|
+
* represents an endpoint that receives messages when they are published.
|
|
96
|
+
*
|
|
97
|
+
* @param client - The API client instance
|
|
98
|
+
* @param queueName - The name of the queue
|
|
99
|
+
* @returns Array of destinations configured for the queue
|
|
100
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name)
|
|
101
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
102
|
+
* @throws {QueueError} If the API request fails
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const destinations = await listDestinations(client, 'order-events');
|
|
107
|
+
* for (const dest of destinations) {
|
|
108
|
+
* console.log(`Destination ${dest.id}: ${dest.url} (${dest.enabled ? 'enabled' : 'disabled'})`);
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export async function listDestinations(client, queueName, options) {
|
|
113
|
+
validateQueueName(queueName);
|
|
114
|
+
const url = queueApiPath('destinations/list', queueName);
|
|
115
|
+
const resp = await client.get(url, DestinationsListResponseSchema, undefined, buildQueueHeaders(options?.orgId));
|
|
116
|
+
if (resp.success) {
|
|
117
|
+
return resp.data.destinations;
|
|
118
|
+
}
|
|
119
|
+
if (resp.message?.includes('not found')) {
|
|
120
|
+
throw new QueueNotFoundError({
|
|
121
|
+
queueName,
|
|
122
|
+
message: resp.message,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
throw new QueueError({
|
|
126
|
+
queueName,
|
|
127
|
+
message: resp.message || 'Failed to list destinations',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Update a destination's configuration.
|
|
132
|
+
*
|
|
133
|
+
* Modifies an existing destination's settings such as URL, enabled status,
|
|
134
|
+
* or retry configuration. Only the fields provided in params will be updated.
|
|
135
|
+
*
|
|
136
|
+
* @param client - The API client instance
|
|
137
|
+
* @param queueName - The name of the queue
|
|
138
|
+
* @param destinationId - The destination ID to update (prefixed with dest_)
|
|
139
|
+
* @param params - Fields to update (partial update supported)
|
|
140
|
+
* @returns The updated destination
|
|
141
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name, destination ID, or config)
|
|
142
|
+
* @throws {DestinationNotFoundError} If the destination does not exist
|
|
143
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
144
|
+
* @throws {QueueError} If the API request fails
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* // Disable a destination temporarily
|
|
149
|
+
* const updated = await updateDestination(client, 'order-events', 'dest_abc123', {
|
|
150
|
+
* enabled: false,
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Update URL and retry settings
|
|
154
|
+
* const updated = await updateDestination(client, 'order-events', 'dest_abc123', {
|
|
155
|
+
* url: 'https://api.example.com/v2/webhooks/orders',
|
|
156
|
+
* config: {
|
|
157
|
+
* retry_attempts: 5,
|
|
158
|
+
* },
|
|
159
|
+
* });
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
export async function updateDestination(client, queueName, destinationId, params, options) {
|
|
163
|
+
validateQueueName(queueName);
|
|
164
|
+
validateDestinationId(destinationId);
|
|
165
|
+
if (params.config) {
|
|
166
|
+
validateDestinationConfig(params.config);
|
|
167
|
+
}
|
|
168
|
+
const url = queueApiPath('destinations/update', queueName, destinationId);
|
|
169
|
+
const resp = await client.patch(url, params, DestinationResponseSchema, UpdateDestinationRequestSchema, undefined, buildQueueHeaders(options?.orgId));
|
|
170
|
+
if (resp.success) {
|
|
171
|
+
return resp.data.destination;
|
|
172
|
+
}
|
|
173
|
+
if (resp.message?.includes('destination') && resp.message?.includes('not found')) {
|
|
174
|
+
throw new DestinationNotFoundError({
|
|
175
|
+
queueName,
|
|
176
|
+
destinationId,
|
|
177
|
+
message: resp.message,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
if (resp.message?.includes('queue') && resp.message?.includes('not found')) {
|
|
181
|
+
throw new QueueNotFoundError({
|
|
182
|
+
queueName,
|
|
183
|
+
message: resp.message,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
throw new QueueError({
|
|
187
|
+
queueName,
|
|
188
|
+
message: resp.message || 'Failed to update destination',
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Delete a destination from a queue.
|
|
193
|
+
*
|
|
194
|
+
* Permanently removes a webhook destination. Messages will no longer be
|
|
195
|
+
* delivered to this endpoint. This action cannot be undone.
|
|
196
|
+
*
|
|
197
|
+
* @param client - The API client instance
|
|
198
|
+
* @param queueName - The name of the queue
|
|
199
|
+
* @param destinationId - The destination ID to delete (prefixed with dest_)
|
|
200
|
+
* @returns void
|
|
201
|
+
* @throws {QueueValidationError} If validation fails (invalid queue name or destination ID)
|
|
202
|
+
* @throws {DestinationNotFoundError} If the destination does not exist
|
|
203
|
+
* @throws {QueueNotFoundError} If the queue does not exist
|
|
204
|
+
* @throws {QueueError} If the API request fails
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* await deleteDestination(client, 'order-events', 'dest_abc123');
|
|
209
|
+
* console.log('Destination deleted');
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export async function deleteDestination(client, queueName, destinationId, options) {
|
|
213
|
+
validateQueueName(queueName);
|
|
214
|
+
validateDestinationId(destinationId);
|
|
215
|
+
const url = queueApiPath('destinations/delete', queueName, destinationId);
|
|
216
|
+
const resp = await client.delete(url, DeleteDestinationResponseSchema, undefined, buildQueueHeaders(options?.orgId));
|
|
217
|
+
if (resp.success) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (resp.message?.includes('destination') && resp.message?.includes('not found')) {
|
|
221
|
+
throw new DestinationNotFoundError({
|
|
222
|
+
queueName,
|
|
223
|
+
destinationId,
|
|
224
|
+
message: resp.message,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
if (resp.message?.includes('queue') && resp.message?.includes('not found')) {
|
|
228
|
+
throw new QueueNotFoundError({
|
|
229
|
+
queueName,
|
|
230
|
+
message: resp.message,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
throw new QueueError({
|
|
234
|
+
queueName,
|
|
235
|
+
message: resp.message || 'Failed to delete destination',
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=destinations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destinations.js","sourceRoot":"","sources":["../../../src/api/queue/destinations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,iBAAiB,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACzF,OAAO,EACN,iBAAiB,EAKjB,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,SAAS,CAAC;AACjB,OAAO,EACN,UAAU,EACV,kBAAkB,EAClB,wBAAwB,EACxB,6BAA6B,EAC7B,YAAY,EACZ,iBAAiB,GACjB,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAC;A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