queuebear 0.1.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/LICENSE +21 -0
- package/README.md +484 -0
- package/dist/index.d.ts +1209 -0
- package/dist/index.js +1313 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base HTTP client for QueueBear API requests
|
|
3
|
+
*/
|
|
4
|
+
interface BaseClientOptions {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
apiKey: string;
|
|
7
|
+
projectId: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* HTTP methods supported by the API
|
|
11
|
+
*/
|
|
12
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
13
|
+
/**
|
|
14
|
+
* Base client providing shared HTTP functionality
|
|
15
|
+
*/
|
|
16
|
+
declare class BaseClient {
|
|
17
|
+
protected baseUrl: string;
|
|
18
|
+
protected apiKey: string;
|
|
19
|
+
protected projectId: string;
|
|
20
|
+
constructor(options: BaseClientOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Build the full URL for a project-scoped endpoint
|
|
23
|
+
*/
|
|
24
|
+
protected buildUrl(path: string, queryParams?: Record<string, string | number | undefined>): string;
|
|
25
|
+
/**
|
|
26
|
+
* Make an authenticated request
|
|
27
|
+
*/
|
|
28
|
+
protected request<T>(method: HttpMethod, path: string, options?: {
|
|
29
|
+
body?: unknown;
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
queryParams?: Record<string, string | number | undefined>;
|
|
32
|
+
}): Promise<T>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Custom error class for QueueBear API errors
|
|
36
|
+
*/
|
|
37
|
+
declare class QueueBearError extends Error {
|
|
38
|
+
statusCode: number;
|
|
39
|
+
constructor(message: string, statusCode: number);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Workflow run status types
|
|
44
|
+
*/
|
|
45
|
+
type WorkflowRunStatus = "pending" | "running" | "sleeping" | "waiting_event" | "completed" | "failed" | "cancelled" | "timed_out";
|
|
46
|
+
/**
|
|
47
|
+
* Step types
|
|
48
|
+
*/
|
|
49
|
+
type StepType = "run" | "sleep" | "call" | "continuation" | "wait_event";
|
|
50
|
+
/**
|
|
51
|
+
* Workflow run information returned by client.getStatus()
|
|
52
|
+
*/
|
|
53
|
+
interface WorkflowRun {
|
|
54
|
+
runId: string;
|
|
55
|
+
workflowId: string;
|
|
56
|
+
workflowUrl: string;
|
|
57
|
+
status: WorkflowRunStatus;
|
|
58
|
+
input: unknown;
|
|
59
|
+
result?: unknown;
|
|
60
|
+
currentStepIndex: number;
|
|
61
|
+
completedSteps: number;
|
|
62
|
+
lastError?: string;
|
|
63
|
+
errorCount: number;
|
|
64
|
+
createdAt: string;
|
|
65
|
+
startedAt?: string;
|
|
66
|
+
completedAt?: string;
|
|
67
|
+
metadata?: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Step information within a workflow run
|
|
71
|
+
*/
|
|
72
|
+
interface WorkflowStep {
|
|
73
|
+
stepName: string;
|
|
74
|
+
stepIndex: number;
|
|
75
|
+
stepType: StepType;
|
|
76
|
+
status: "pending" | "completed" | "failed";
|
|
77
|
+
result?: unknown;
|
|
78
|
+
error?: string;
|
|
79
|
+
createdAt: string;
|
|
80
|
+
completedAt?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Response from client.trigger()
|
|
84
|
+
*/
|
|
85
|
+
interface TriggerResponse {
|
|
86
|
+
runId: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Response from client.getStatus() - includes run details and steps
|
|
90
|
+
*/
|
|
91
|
+
interface StatusResponse extends WorkflowRun {
|
|
92
|
+
steps: WorkflowStep[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Options for triggering a workflow
|
|
96
|
+
*/
|
|
97
|
+
interface TriggerOptions {
|
|
98
|
+
idempotencyKey?: string;
|
|
99
|
+
maxDuration?: number;
|
|
100
|
+
metadata?: Record<string, unknown>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Options for step-level retry configuration
|
|
104
|
+
*/
|
|
105
|
+
interface StepRetryOptions {
|
|
106
|
+
retries?: number;
|
|
107
|
+
backoff?: {
|
|
108
|
+
type: "exponential" | "fixed";
|
|
109
|
+
delay: number;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Options for serve() function
|
|
114
|
+
*/
|
|
115
|
+
interface ServeOptions {
|
|
116
|
+
baseUrl?: string;
|
|
117
|
+
retries?: number;
|
|
118
|
+
signingSecret?: string;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Completed step info returned by context.getCompletedSteps()
|
|
122
|
+
*/
|
|
123
|
+
interface CompletedStep {
|
|
124
|
+
stepName: string;
|
|
125
|
+
stepIndex: number;
|
|
126
|
+
stepType: StepType;
|
|
127
|
+
result: unknown;
|
|
128
|
+
completedAt: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* HTTP call configuration for context.call()
|
|
132
|
+
*/
|
|
133
|
+
interface CallConfig {
|
|
134
|
+
url: string;
|
|
135
|
+
method?: string;
|
|
136
|
+
headers?: Record<string, string>;
|
|
137
|
+
body?: unknown;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Options for listing workflow runs
|
|
141
|
+
*/
|
|
142
|
+
interface ListRunsOptions {
|
|
143
|
+
status?: WorkflowRunStatus;
|
|
144
|
+
limit?: number;
|
|
145
|
+
offset?: number;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Pagination info in list responses
|
|
149
|
+
*/
|
|
150
|
+
interface Pagination {
|
|
151
|
+
limit: number;
|
|
152
|
+
offset: number;
|
|
153
|
+
hasMore: boolean;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Response from client.listRuns()
|
|
157
|
+
*/
|
|
158
|
+
interface ListRunsResponse {
|
|
159
|
+
runs: WorkflowRun[];
|
|
160
|
+
pagination: Pagination;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Options for context.waitForEvent()
|
|
164
|
+
*/
|
|
165
|
+
interface WaitForEventOptions {
|
|
166
|
+
eventKey?: string;
|
|
167
|
+
timeoutSeconds?: number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Definition for a parallel step
|
|
171
|
+
*/
|
|
172
|
+
interface ParallelStepDefinition<T> {
|
|
173
|
+
name: string;
|
|
174
|
+
fn: () => Promise<T>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Options for client.sendEvent()
|
|
178
|
+
*/
|
|
179
|
+
interface SendEventOptions {
|
|
180
|
+
eventKey?: string;
|
|
181
|
+
payload?: unknown;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Response from client.sendEvent()
|
|
185
|
+
*/
|
|
186
|
+
interface SendEventResponse {
|
|
187
|
+
eventName: string;
|
|
188
|
+
eventKey?: string;
|
|
189
|
+
matchedRuns: number;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* HTTP methods for message delivery
|
|
193
|
+
*/
|
|
194
|
+
type MessageMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
195
|
+
/**
|
|
196
|
+
* Message status values
|
|
197
|
+
*/
|
|
198
|
+
type MessageStatus = "pending" | "active" | "completed" | "failed" | "cancelled" | "dlq";
|
|
199
|
+
/**
|
|
200
|
+
* Options for publishing a message
|
|
201
|
+
*/
|
|
202
|
+
interface PublishOptions {
|
|
203
|
+
/** Delay before delivery. Format: "{value}{unit}" where unit is s/m/h/d (e.g., "30s", "5m", "2h", "1d") */
|
|
204
|
+
delay?: string;
|
|
205
|
+
/** Number of retry attempts (1-5, default: 3) */
|
|
206
|
+
retries?: number;
|
|
207
|
+
/** HTTP method for delivery (default: POST) */
|
|
208
|
+
method?: MessageMethod;
|
|
209
|
+
/** Headers to forward to the destination */
|
|
210
|
+
headers?: Record<string, string>;
|
|
211
|
+
/** URL to call after successful delivery */
|
|
212
|
+
callbackUrl?: string;
|
|
213
|
+
/** URL to call after all retries exhausted */
|
|
214
|
+
failureCallbackUrl?: string;
|
|
215
|
+
/** Unique ID for message deduplication (max 128 chars) */
|
|
216
|
+
deduplicationId?: string;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Response from publishing a message
|
|
220
|
+
*/
|
|
221
|
+
interface PublishResponse {
|
|
222
|
+
messageId: string;
|
|
223
|
+
/** True if this message was deduplicated */
|
|
224
|
+
deduplicated?: boolean;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Delivery log entry for a message
|
|
228
|
+
*/
|
|
229
|
+
interface DeliveryLog {
|
|
230
|
+
id: string;
|
|
231
|
+
responseStatus: number | null;
|
|
232
|
+
success: boolean;
|
|
233
|
+
errorMessage: string | null;
|
|
234
|
+
durationMs: number | null;
|
|
235
|
+
attemptNumber: number;
|
|
236
|
+
createdAt: string;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Last response from message delivery
|
|
240
|
+
*/
|
|
241
|
+
interface LastResponse {
|
|
242
|
+
statusCode: number;
|
|
243
|
+
body: string;
|
|
244
|
+
headers?: Record<string, string>;
|
|
245
|
+
duration: number;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Message details returned by messages.get()
|
|
249
|
+
*/
|
|
250
|
+
interface Message {
|
|
251
|
+
messageId: string;
|
|
252
|
+
destination: string;
|
|
253
|
+
method: MessageMethod;
|
|
254
|
+
body: string | null;
|
|
255
|
+
headers: Record<string, string>;
|
|
256
|
+
status: MessageStatus;
|
|
257
|
+
retries: number;
|
|
258
|
+
retryCount: number;
|
|
259
|
+
delay: number | null;
|
|
260
|
+
scheduledFor: string | null;
|
|
261
|
+
createdAt: string;
|
|
262
|
+
processedAt: string | null;
|
|
263
|
+
completedAt: string | null;
|
|
264
|
+
lastResponse: LastResponse | null;
|
|
265
|
+
lastError: string | null;
|
|
266
|
+
deliveryLogs: DeliveryLog[];
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Message summary in list responses
|
|
270
|
+
*/
|
|
271
|
+
interface MessageSummary {
|
|
272
|
+
messageId: string;
|
|
273
|
+
destination: string;
|
|
274
|
+
status: MessageStatus;
|
|
275
|
+
retries: number;
|
|
276
|
+
retryCount: number;
|
|
277
|
+
createdAt: string;
|
|
278
|
+
completedAt: string | null;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Options for listing messages
|
|
282
|
+
*/
|
|
283
|
+
interface ListMessagesOptions {
|
|
284
|
+
status?: MessageStatus;
|
|
285
|
+
limit?: number;
|
|
286
|
+
offset?: number;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Response from messages.list()
|
|
290
|
+
*/
|
|
291
|
+
interface ListMessagesResponse {
|
|
292
|
+
messages: MessageSummary[];
|
|
293
|
+
pagination: Pagination;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Response from messages.cancel()
|
|
297
|
+
*/
|
|
298
|
+
interface CancelMessageResponse {
|
|
299
|
+
messageId: string;
|
|
300
|
+
cancelled: boolean;
|
|
301
|
+
previousStatus: MessageStatus;
|
|
302
|
+
bullmqCancelled: boolean;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Options for creating a schedule
|
|
306
|
+
*/
|
|
307
|
+
interface CreateScheduleOptions {
|
|
308
|
+
/** URL to call on each execution */
|
|
309
|
+
destination: string;
|
|
310
|
+
/** Cron expression (e.g., "0 9 * * *" for 9 AM daily) */
|
|
311
|
+
cron: string;
|
|
312
|
+
/** IANA timezone (default: "UTC") */
|
|
313
|
+
timezone?: string;
|
|
314
|
+
/** HTTP method (default: POST) */
|
|
315
|
+
method?: MessageMethod;
|
|
316
|
+
/** Request body to send */
|
|
317
|
+
body?: string;
|
|
318
|
+
/** Headers to include in request */
|
|
319
|
+
headers?: Record<string, string>;
|
|
320
|
+
/** Retry attempts per execution (0-5, default: 3) */
|
|
321
|
+
retries?: number;
|
|
322
|
+
/** Custom metadata */
|
|
323
|
+
metadata?: Record<string, unknown>;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Schedule details
|
|
327
|
+
*/
|
|
328
|
+
interface Schedule {
|
|
329
|
+
scheduleId: string;
|
|
330
|
+
destination: string;
|
|
331
|
+
cron: string;
|
|
332
|
+
timezone: string;
|
|
333
|
+
method: MessageMethod;
|
|
334
|
+
body: string | null;
|
|
335
|
+
headers: Record<string, string>;
|
|
336
|
+
retries: number;
|
|
337
|
+
isActive: boolean;
|
|
338
|
+
isPaused: boolean;
|
|
339
|
+
lastExecutedAt: string | null;
|
|
340
|
+
nextExecutionAt: string | null;
|
|
341
|
+
executionCount: number;
|
|
342
|
+
failureCount: number;
|
|
343
|
+
metadata: Record<string, unknown> | null;
|
|
344
|
+
createdAt: string;
|
|
345
|
+
updatedAt: string | null;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Schedule summary in list responses
|
|
349
|
+
*/
|
|
350
|
+
interface ScheduleSummary {
|
|
351
|
+
scheduleId: string;
|
|
352
|
+
destination: string;
|
|
353
|
+
cron: string;
|
|
354
|
+
timezone: string;
|
|
355
|
+
method: MessageMethod;
|
|
356
|
+
retries: number;
|
|
357
|
+
isActive: boolean;
|
|
358
|
+
isPaused: boolean;
|
|
359
|
+
lastExecutedAt: string | null;
|
|
360
|
+
nextExecutionAt: string | null;
|
|
361
|
+
executionCount: number;
|
|
362
|
+
failureCount: number;
|
|
363
|
+
createdAt: string;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Options for listing schedules
|
|
367
|
+
*/
|
|
368
|
+
interface ListSchedulesOptions {
|
|
369
|
+
limit?: number;
|
|
370
|
+
offset?: number;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Response from schedules.list()
|
|
374
|
+
*/
|
|
375
|
+
interface ListSchedulesResponse {
|
|
376
|
+
schedules: ScheduleSummary[];
|
|
377
|
+
pagination: Pagination;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Response from schedules.create()
|
|
381
|
+
*/
|
|
382
|
+
interface CreateScheduleResponse extends Schedule {
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Response from schedules.delete()
|
|
386
|
+
*/
|
|
387
|
+
interface DeleteScheduleResponse {
|
|
388
|
+
scheduleId: string;
|
|
389
|
+
deleted: boolean;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Response from schedules.pause()
|
|
393
|
+
*/
|
|
394
|
+
interface PauseScheduleResponse {
|
|
395
|
+
scheduleId: string;
|
|
396
|
+
isPaused: true;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Response from schedules.resume()
|
|
400
|
+
*/
|
|
401
|
+
interface ResumeScheduleResponse {
|
|
402
|
+
scheduleId: string;
|
|
403
|
+
isPaused: false;
|
|
404
|
+
nextExecutionAt: string;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* DLQ entry details
|
|
408
|
+
*/
|
|
409
|
+
interface DLQEntry {
|
|
410
|
+
id: string;
|
|
411
|
+
originalMessageId: string;
|
|
412
|
+
destination: string;
|
|
413
|
+
method: MessageMethod;
|
|
414
|
+
body: string | null;
|
|
415
|
+
headers: Record<string, string>;
|
|
416
|
+
failureReason: string;
|
|
417
|
+
lastStatusCode: number | null;
|
|
418
|
+
totalAttempts: number;
|
|
419
|
+
lastAttemptAt: string;
|
|
420
|
+
recoveredAt: string | null;
|
|
421
|
+
recoveryMessageId: string | null;
|
|
422
|
+
createdAt: string;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* DLQ entry summary in list responses
|
|
426
|
+
*/
|
|
427
|
+
interface DLQEntrySummary {
|
|
428
|
+
id: string;
|
|
429
|
+
originalMessageId: string;
|
|
430
|
+
destination: string;
|
|
431
|
+
method: MessageMethod;
|
|
432
|
+
failureReason: string;
|
|
433
|
+
lastStatusCode: number | null;
|
|
434
|
+
totalAttempts: number;
|
|
435
|
+
lastAttemptAt: string;
|
|
436
|
+
createdAt: string;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Options for listing DLQ entries
|
|
440
|
+
*/
|
|
441
|
+
interface ListDLQOptions {
|
|
442
|
+
limit?: number;
|
|
443
|
+
offset?: number;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Response from dlq.list()
|
|
447
|
+
*/
|
|
448
|
+
interface ListDLQResponse {
|
|
449
|
+
entries: DLQEntrySummary[];
|
|
450
|
+
pagination: Pagination;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Response from dlq.retry()
|
|
454
|
+
*/
|
|
455
|
+
interface RetryDLQResponse {
|
|
456
|
+
dlqId: string;
|
|
457
|
+
newMessageId: string;
|
|
458
|
+
recovered: true;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Response from dlq.delete()
|
|
462
|
+
*/
|
|
463
|
+
interface DeleteDLQResponse {
|
|
464
|
+
dlqId: string;
|
|
465
|
+
deleted: boolean;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Response from dlq.purge()
|
|
469
|
+
*/
|
|
470
|
+
interface PurgeDLQResponse {
|
|
471
|
+
purged: true;
|
|
472
|
+
count: number;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Messages API client for publishing and managing webhook messages
|
|
477
|
+
*/
|
|
478
|
+
declare class MessagesAPI extends BaseClient {
|
|
479
|
+
constructor(options: BaseClientOptions);
|
|
480
|
+
/**
|
|
481
|
+
* Publish a message to be delivered to a destination URL
|
|
482
|
+
*
|
|
483
|
+
* @param destination - The URL to deliver the message to
|
|
484
|
+
* @param body - The message body (will be JSON-stringified)
|
|
485
|
+
* @param options - Optional configuration for delay, retries, callbacks, etc.
|
|
486
|
+
* @returns The message ID and deduplication status
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* const { messageId } = await qb.messages.publish(
|
|
491
|
+
* "https://api.example.com/webhook",
|
|
492
|
+
* { event: "user.created", userId: "123" },
|
|
493
|
+
* { delay: "30s", retries: 5 }
|
|
494
|
+
* );
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
publish(destination: string, body: unknown, options?: PublishOptions): Promise<PublishResponse>;
|
|
498
|
+
/**
|
|
499
|
+
* Get message details and delivery history
|
|
500
|
+
*
|
|
501
|
+
* @param messageId - The message ID (e.g., "msg_abc123...")
|
|
502
|
+
* @returns Full message details including delivery logs
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```typescript
|
|
506
|
+
* const message = await qb.messages.get("msg_abc123");
|
|
507
|
+
* console.log(message.status); // "completed" | "pending" | "failed"
|
|
508
|
+
* console.log(message.deliveryLogs); // Delivery attempt history
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
get(messageId: string): Promise<Message>;
|
|
512
|
+
/**
|
|
513
|
+
* List messages with optional filtering
|
|
514
|
+
*
|
|
515
|
+
* @param options - Filter by status and pagination
|
|
516
|
+
* @returns Paginated list of messages
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```typescript
|
|
520
|
+
* const { messages, pagination } = await qb.messages.list({
|
|
521
|
+
* status: "pending",
|
|
522
|
+
* limit: 20
|
|
523
|
+
* });
|
|
524
|
+
* ```
|
|
525
|
+
*/
|
|
526
|
+
list(options?: ListMessagesOptions): Promise<ListMessagesResponse>;
|
|
527
|
+
/**
|
|
528
|
+
* Cancel a pending or active message
|
|
529
|
+
*
|
|
530
|
+
* @param messageId - The message ID to cancel
|
|
531
|
+
* @returns Cancellation result
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* const result = await qb.messages.cancel("msg_abc123");
|
|
536
|
+
* console.log(result.cancelled); // true
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
cancel(messageId: string): Promise<CancelMessageResponse>;
|
|
540
|
+
/**
|
|
541
|
+
* Publish a message and wait for delivery completion
|
|
542
|
+
* Polls the message status until it reaches a terminal state
|
|
543
|
+
*
|
|
544
|
+
* @param destination - The URL to deliver the message to
|
|
545
|
+
* @param body - The message body
|
|
546
|
+
* @param options - Publish options plus polling configuration
|
|
547
|
+
* @returns The final message status after delivery
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```typescript
|
|
551
|
+
* const message = await qb.messages.publishAndWait(
|
|
552
|
+
* "https://api.example.com/webhook",
|
|
553
|
+
* { event: "user.created" },
|
|
554
|
+
* { timeoutMs: 30000 }
|
|
555
|
+
* );
|
|
556
|
+
* console.log(message.status); // "completed"
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
publishAndWait(destination: string, body: unknown, options?: PublishOptions & {
|
|
560
|
+
/** Polling interval in milliseconds (default: 1000) */
|
|
561
|
+
pollIntervalMs?: number;
|
|
562
|
+
/** Maximum time to wait in milliseconds (default: 60000) */
|
|
563
|
+
timeoutMs?: number;
|
|
564
|
+
}): Promise<Message>;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Schedules API client for managing cron-based recurring jobs
|
|
569
|
+
*/
|
|
570
|
+
declare class SchedulesAPI extends BaseClient {
|
|
571
|
+
constructor(options: BaseClientOptions);
|
|
572
|
+
/**
|
|
573
|
+
* Create a cron-based recurring schedule
|
|
574
|
+
*
|
|
575
|
+
* @param options - Schedule configuration including destination, cron, and optional settings
|
|
576
|
+
* @returns The created schedule details
|
|
577
|
+
*
|
|
578
|
+
* @example
|
|
579
|
+
* ```typescript
|
|
580
|
+
* const schedule = await qb.schedules.create({
|
|
581
|
+
* destination: "https://api.example.com/cron-job",
|
|
582
|
+
* cron: "0 9 * * *", // Daily at 9 AM
|
|
583
|
+
* timezone: "America/New_York",
|
|
584
|
+
* method: "POST",
|
|
585
|
+
* body: JSON.stringify({ type: "daily-report" }),
|
|
586
|
+
* retries: 3
|
|
587
|
+
* });
|
|
588
|
+
* console.log(schedule.scheduleId);
|
|
589
|
+
* ```
|
|
590
|
+
*
|
|
591
|
+
* @example Common cron expressions
|
|
592
|
+
* - `"* * * * *"` - Every minute
|
|
593
|
+
* - `"0 * * * *"` - Every hour
|
|
594
|
+
* - `"0 9 * * *"` - Daily at 9:00 AM
|
|
595
|
+
* - `"0 9 * * 1-5"` - Weekdays at 9:00 AM
|
|
596
|
+
* - `"0 0 1 * *"` - First day of each month
|
|
597
|
+
* - `"0 */6 * * *"` - Every 6 hours
|
|
598
|
+
*/
|
|
599
|
+
create(options: CreateScheduleOptions): Promise<CreateScheduleResponse>;
|
|
600
|
+
/**
|
|
601
|
+
* Get details of a specific schedule
|
|
602
|
+
*
|
|
603
|
+
* @param scheduleId - The schedule ID (e.g., "sched_abc123...")
|
|
604
|
+
* @returns Full schedule details
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```typescript
|
|
608
|
+
* const schedule = await qb.schedules.get("sched_abc123");
|
|
609
|
+
* console.log(schedule.nextExecutionAt);
|
|
610
|
+
* console.log(schedule.executionCount);
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
get(scheduleId: string): Promise<Schedule>;
|
|
614
|
+
/**
|
|
615
|
+
* List all schedules for the current project
|
|
616
|
+
*
|
|
617
|
+
* @param options - Pagination options
|
|
618
|
+
* @returns Paginated list of schedules
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```typescript
|
|
622
|
+
* const { schedules, pagination } = await qb.schedules.list({ limit: 20 });
|
|
623
|
+
* for (const schedule of schedules) {
|
|
624
|
+
* console.log(`${schedule.scheduleId}: ${schedule.cron}`);
|
|
625
|
+
* }
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
list(options?: ListSchedulesOptions): Promise<ListSchedulesResponse>;
|
|
629
|
+
/**
|
|
630
|
+
* Delete (soft-delete) a schedule
|
|
631
|
+
*
|
|
632
|
+
* @param scheduleId - The schedule ID to delete
|
|
633
|
+
* @returns Deletion confirmation
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```typescript
|
|
637
|
+
* const result = await qb.schedules.delete("sched_abc123");
|
|
638
|
+
* console.log(result.deleted); // true
|
|
639
|
+
* ```
|
|
640
|
+
*/
|
|
641
|
+
delete(scheduleId: string): Promise<DeleteScheduleResponse>;
|
|
642
|
+
/**
|
|
643
|
+
* Pause a schedule to temporarily stop executions
|
|
644
|
+
*
|
|
645
|
+
* @param scheduleId - The schedule ID to pause
|
|
646
|
+
* @returns Pause confirmation
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```typescript
|
|
650
|
+
* await qb.schedules.pause("sched_abc123");
|
|
651
|
+
* // Schedule will not execute until resumed
|
|
652
|
+
* ```
|
|
653
|
+
*/
|
|
654
|
+
pause(scheduleId: string): Promise<PauseScheduleResponse>;
|
|
655
|
+
/**
|
|
656
|
+
* Resume a paused schedule
|
|
657
|
+
*
|
|
658
|
+
* @param scheduleId - The schedule ID to resume
|
|
659
|
+
* @returns Resume confirmation with next execution time
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
* ```typescript
|
|
663
|
+
* const result = await qb.schedules.resume("sched_abc123");
|
|
664
|
+
* console.log(result.nextExecutionAt); // Next scheduled run
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
resume(scheduleId: string): Promise<ResumeScheduleResponse>;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* DLQ (Dead Letter Queue) API client for managing failed messages
|
|
672
|
+
*
|
|
673
|
+
* Messages that fail all retry attempts are moved to the DLQ for manual review and recovery.
|
|
674
|
+
*/
|
|
675
|
+
declare class DLQAPI extends BaseClient {
|
|
676
|
+
constructor(options: BaseClientOptions);
|
|
677
|
+
/**
|
|
678
|
+
* List all DLQ entries for the current project
|
|
679
|
+
*
|
|
680
|
+
* @param options - Pagination options
|
|
681
|
+
* @returns Paginated list of DLQ entries
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```typescript
|
|
685
|
+
* const { entries, pagination } = await qb.dlq.list({ limit: 20 });
|
|
686
|
+
* for (const entry of entries) {
|
|
687
|
+
* console.log(`${entry.id}: ${entry.failureReason}`);
|
|
688
|
+
* }
|
|
689
|
+
* ```
|
|
690
|
+
*/
|
|
691
|
+
list(options?: ListDLQOptions): Promise<ListDLQResponse>;
|
|
692
|
+
/**
|
|
693
|
+
* Get details of a specific DLQ entry
|
|
694
|
+
*
|
|
695
|
+
* @param dlqId - The DLQ entry UUID
|
|
696
|
+
* @returns Full DLQ entry details including original message data
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* ```typescript
|
|
700
|
+
* const entry = await qb.dlq.get("uuid-123...");
|
|
701
|
+
* console.log(entry.failureReason);
|
|
702
|
+
* console.log(entry.totalAttempts);
|
|
703
|
+
* console.log(entry.body); // Original message body
|
|
704
|
+
* ```
|
|
705
|
+
*/
|
|
706
|
+
get(dlqId: string): Promise<DLQEntry>;
|
|
707
|
+
/**
|
|
708
|
+
* Retry a DLQ entry by creating a new message
|
|
709
|
+
*
|
|
710
|
+
* Creates a new message from the failed DLQ entry for redelivery.
|
|
711
|
+
* The DLQ entry is marked as recovered and linked to the new message.
|
|
712
|
+
*
|
|
713
|
+
* @param dlqId - The DLQ entry UUID to retry
|
|
714
|
+
* @returns The new message ID and recovery confirmation
|
|
715
|
+
* @throws Error if the entry was already recovered
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* ```typescript
|
|
719
|
+
* const result = await qb.dlq.retry("uuid-123...");
|
|
720
|
+
* console.log(result.newMessageId); // New message created
|
|
721
|
+
* console.log(result.recovered); // true
|
|
722
|
+
* ```
|
|
723
|
+
*/
|
|
724
|
+
retry(dlqId: string): Promise<RetryDLQResponse>;
|
|
725
|
+
/**
|
|
726
|
+
* Delete a DLQ entry permanently without retry
|
|
727
|
+
*
|
|
728
|
+
* @param dlqId - The DLQ entry UUID to delete
|
|
729
|
+
* @returns Deletion confirmation
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```typescript
|
|
733
|
+
* await qb.dlq.delete("uuid-123...");
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
delete(dlqId: string): Promise<DeleteDLQResponse>;
|
|
737
|
+
/**
|
|
738
|
+
* Purge all DLQ entries for the current project
|
|
739
|
+
*
|
|
740
|
+
* Permanently deletes all DLQ entries without retry.
|
|
741
|
+
* Use with caution as this action cannot be undone.
|
|
742
|
+
*
|
|
743
|
+
* @returns The number of entries purged
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* ```typescript
|
|
747
|
+
* const result = await qb.dlq.purge();
|
|
748
|
+
* console.log(`Purged ${result.count} entries`);
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
purge(): Promise<PurgeDLQResponse>;
|
|
752
|
+
/**
|
|
753
|
+
* Retry all DLQ entries for the current project
|
|
754
|
+
*
|
|
755
|
+
* Creates new messages from all failed DLQ entries.
|
|
756
|
+
*
|
|
757
|
+
* @returns Array of retry results
|
|
758
|
+
*
|
|
759
|
+
* @example
|
|
760
|
+
* ```typescript
|
|
761
|
+
* const results = await qb.dlq.retryAll();
|
|
762
|
+
* console.log(`Retried ${results.length} entries`);
|
|
763
|
+
* ```
|
|
764
|
+
*/
|
|
765
|
+
retryAll(): Promise<RetryDLQResponse[]>;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Workflows API client for triggering and managing workflow runs
|
|
770
|
+
*/
|
|
771
|
+
declare class WorkflowsAPI extends BaseClient {
|
|
772
|
+
constructor(options: BaseClientOptions);
|
|
773
|
+
/**
|
|
774
|
+
* Trigger a new workflow run
|
|
775
|
+
*
|
|
776
|
+
* @param workflowId - Unique identifier for this workflow type
|
|
777
|
+
* @param workflowUrl - URL of the workflow endpoint
|
|
778
|
+
* @param input - Input data for the workflow
|
|
779
|
+
* @param options - Optional settings (idempotencyKey, maxDuration, metadata)
|
|
780
|
+
* @returns The run ID
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```typescript
|
|
784
|
+
* const { runId } = await qb.workflows.trigger(
|
|
785
|
+
* "user-onboarding",
|
|
786
|
+
* "https://your-app.com/api/workflows/onboarding",
|
|
787
|
+
* { userId: "123", email: "user@example.com" },
|
|
788
|
+
* { idempotencyKey: "onboarding-user-123" }
|
|
789
|
+
* );
|
|
790
|
+
* ```
|
|
791
|
+
*/
|
|
792
|
+
trigger<T = unknown>(workflowId: string, workflowUrl: string, input?: T, options?: TriggerOptions): Promise<TriggerResponse>;
|
|
793
|
+
/**
|
|
794
|
+
* Get workflow run status with all steps
|
|
795
|
+
*
|
|
796
|
+
* @param runId - The workflow run ID
|
|
797
|
+
* @returns Full run details including steps
|
|
798
|
+
*
|
|
799
|
+
* @example
|
|
800
|
+
* ```typescript
|
|
801
|
+
* const status = await qb.workflows.getStatus(runId);
|
|
802
|
+
* console.log(status.status); // "running" | "sleeping" | "completed"
|
|
803
|
+
* console.log(status.steps); // Array of step details
|
|
804
|
+
* ```
|
|
805
|
+
*/
|
|
806
|
+
getStatus(runId: string): Promise<StatusResponse>;
|
|
807
|
+
/**
|
|
808
|
+
* Cancel a running workflow
|
|
809
|
+
*
|
|
810
|
+
* @param runId - The workflow run ID to cancel
|
|
811
|
+
*
|
|
812
|
+
* @example
|
|
813
|
+
* ```typescript
|
|
814
|
+
* await qb.workflows.cancel(runId);
|
|
815
|
+
* ```
|
|
816
|
+
*/
|
|
817
|
+
cancel(runId: string): Promise<void>;
|
|
818
|
+
/**
|
|
819
|
+
* Retry a failed or timed out workflow
|
|
820
|
+
* Resumes from the last completed step
|
|
821
|
+
*
|
|
822
|
+
* @param runId - The workflow run ID to retry
|
|
823
|
+
* @returns The new run ID if a new run was created
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* ```typescript
|
|
827
|
+
* const result = await qb.workflows.retry(runId);
|
|
828
|
+
* console.log(result.runId);
|
|
829
|
+
* console.log(result.resumed); // true
|
|
830
|
+
* ```
|
|
831
|
+
*/
|
|
832
|
+
retry(runId: string): Promise<{
|
|
833
|
+
runId: string;
|
|
834
|
+
resumed: boolean;
|
|
835
|
+
}>;
|
|
836
|
+
/**
|
|
837
|
+
* List runs for a specific workflow
|
|
838
|
+
*
|
|
839
|
+
* @param workflowId - The workflow type identifier
|
|
840
|
+
* @param options - Filter by status and pagination
|
|
841
|
+
* @returns Paginated list of workflow runs
|
|
842
|
+
*
|
|
843
|
+
* @example
|
|
844
|
+
* ```typescript
|
|
845
|
+
* const { runs, pagination } = await qb.workflows.listRuns("user-onboarding", {
|
|
846
|
+
* status: "completed",
|
|
847
|
+
* limit: 20
|
|
848
|
+
* });
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
listRuns(workflowId: string, options?: ListRunsOptions): Promise<ListRunsResponse>;
|
|
852
|
+
/**
|
|
853
|
+
* Send an event to workflows waiting with waitForEvent()
|
|
854
|
+
*
|
|
855
|
+
* @param eventName - Name of the event to send
|
|
856
|
+
* @param options - Optional event key and payload
|
|
857
|
+
* @returns The number of workflows that received the event
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* ```typescript
|
|
861
|
+
* const result = await qb.workflows.sendEvent("order.approved", {
|
|
862
|
+
* eventKey: "order-123",
|
|
863
|
+
* payload: { status: "approved" }
|
|
864
|
+
* });
|
|
865
|
+
* console.log(`Notified ${result.matchedRuns} workflows`);
|
|
866
|
+
* ```
|
|
867
|
+
*/
|
|
868
|
+
sendEvent(eventName: string, options?: SendEventOptions): Promise<SendEventResponse>;
|
|
869
|
+
/**
|
|
870
|
+
* Wait for a workflow to complete
|
|
871
|
+
* Polls the status until the workflow reaches a terminal state
|
|
872
|
+
*
|
|
873
|
+
* @param runId - The workflow run ID
|
|
874
|
+
* @param options - Polling options
|
|
875
|
+
* @returns The final workflow status
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
* ```typescript
|
|
879
|
+
* const result = await qb.workflows.waitForCompletion(runId, {
|
|
880
|
+
* pollIntervalMs: 2000,
|
|
881
|
+
* timeoutMs: 60000
|
|
882
|
+
* });
|
|
883
|
+
* console.log(result.status); // "completed" | "failed" | "cancelled"
|
|
884
|
+
* ```
|
|
885
|
+
*/
|
|
886
|
+
waitForCompletion(runId: string, options?: {
|
|
887
|
+
/** Polling interval in milliseconds (default: 1000) */
|
|
888
|
+
pollIntervalMs?: number;
|
|
889
|
+
/** Maximum time to wait in milliseconds (default: 300000 = 5 minutes) */
|
|
890
|
+
timeoutMs?: number;
|
|
891
|
+
}): Promise<StatusResponse>;
|
|
892
|
+
/**
|
|
893
|
+
* Trigger a workflow and wait for completion
|
|
894
|
+
*
|
|
895
|
+
* @param workflowId - Unique identifier for this workflow type
|
|
896
|
+
* @param workflowUrl - URL of the workflow endpoint
|
|
897
|
+
* @param input - Input data for the workflow
|
|
898
|
+
* @param options - Trigger and polling options
|
|
899
|
+
* @returns The final workflow status
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
* ```typescript
|
|
903
|
+
* const result = await qb.workflows.triggerAndWait(
|
|
904
|
+
* "user-onboarding",
|
|
905
|
+
* "https://your-app.com/api/workflows/onboarding",
|
|
906
|
+
* { userId: "123" },
|
|
907
|
+
* { timeoutMs: 120000 }
|
|
908
|
+
* );
|
|
909
|
+
* console.log(result.result); // Workflow output
|
|
910
|
+
* ```
|
|
911
|
+
*/
|
|
912
|
+
triggerAndWait<T = unknown>(workflowId: string, workflowUrl: string, input?: T, options?: TriggerOptions & {
|
|
913
|
+
pollIntervalMs?: number;
|
|
914
|
+
timeoutMs?: number;
|
|
915
|
+
}): Promise<StatusResponse>;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* QueueBear client options
|
|
920
|
+
*/
|
|
921
|
+
interface QueueBearOptions {
|
|
922
|
+
/** Base URL of your QueueBear instance */
|
|
923
|
+
baseUrl: string;
|
|
924
|
+
/** API key (qb_live_* or qb_test_*) */
|
|
925
|
+
apiKey: string;
|
|
926
|
+
/** Project ID */
|
|
927
|
+
projectId: string;
|
|
928
|
+
}
|
|
929
|
+
/**
|
|
930
|
+
* Unified QueueBear client for all API operations
|
|
931
|
+
*
|
|
932
|
+
* Provides access to Messages, Schedules, DLQ, and Workflows APIs
|
|
933
|
+
* through a single client instance.
|
|
934
|
+
*
|
|
935
|
+
* @example
|
|
936
|
+
* ```typescript
|
|
937
|
+
* import { QueueBear, serve } from "@queuebear/workflow";
|
|
938
|
+
*
|
|
939
|
+
* const qb = new QueueBear({
|
|
940
|
+
* baseUrl: "https://your-queuebear-instance.com",
|
|
941
|
+
* apiKey: "qb_live_xxx",
|
|
942
|
+
* projectId: "proj_xxx",
|
|
943
|
+
* });
|
|
944
|
+
*
|
|
945
|
+
* // Messages
|
|
946
|
+
* await qb.messages.publish("https://api.example.com/webhook", { data: "test" });
|
|
947
|
+
*
|
|
948
|
+
* // Schedules
|
|
949
|
+
* await qb.schedules.create({ destination: "...", cron: "0 9 * * *" });
|
|
950
|
+
*
|
|
951
|
+
* // DLQ
|
|
952
|
+
* await qb.dlq.list();
|
|
953
|
+
*
|
|
954
|
+
* // Workflows
|
|
955
|
+
* await qb.workflows.trigger("my-workflow", "https://...", input);
|
|
956
|
+
* ```
|
|
957
|
+
*/
|
|
958
|
+
declare class QueueBear {
|
|
959
|
+
private readonly options;
|
|
960
|
+
/**
|
|
961
|
+
* Messages API for publishing and managing webhook messages
|
|
962
|
+
*
|
|
963
|
+
* @example
|
|
964
|
+
* ```typescript
|
|
965
|
+
* // Publish a message
|
|
966
|
+
* const { messageId } = await qb.messages.publish(
|
|
967
|
+
* "https://api.example.com/webhook",
|
|
968
|
+
* { event: "user.created", userId: "123" },
|
|
969
|
+
* { delay: "30s", retries: 5 }
|
|
970
|
+
* );
|
|
971
|
+
*
|
|
972
|
+
* // Get message status
|
|
973
|
+
* const message = await qb.messages.get(messageId);
|
|
974
|
+
*
|
|
975
|
+
* // List messages
|
|
976
|
+
* const { messages } = await qb.messages.list({ status: "pending" });
|
|
977
|
+
*
|
|
978
|
+
* // Cancel a message
|
|
979
|
+
* await qb.messages.cancel(messageId);
|
|
980
|
+
* ```
|
|
981
|
+
*/
|
|
982
|
+
readonly messages: MessagesAPI;
|
|
983
|
+
/**
|
|
984
|
+
* Schedules API for managing cron-based recurring jobs
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```typescript
|
|
988
|
+
* // Create a schedule
|
|
989
|
+
* const schedule = await qb.schedules.create({
|
|
990
|
+
* destination: "https://api.example.com/cron-job",
|
|
991
|
+
* cron: "0 9 * * *", // Daily at 9 AM
|
|
992
|
+
* timezone: "America/New_York",
|
|
993
|
+
* });
|
|
994
|
+
*
|
|
995
|
+
* // Pause a schedule
|
|
996
|
+
* await qb.schedules.pause(schedule.scheduleId);
|
|
997
|
+
*
|
|
998
|
+
* // Resume a schedule
|
|
999
|
+
* await qb.schedules.resume(schedule.scheduleId);
|
|
1000
|
+
*
|
|
1001
|
+
* // Delete a schedule
|
|
1002
|
+
* await qb.schedules.delete(schedule.scheduleId);
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
1005
|
+
readonly schedules: SchedulesAPI;
|
|
1006
|
+
/**
|
|
1007
|
+
* DLQ API for managing failed messages in the dead letter queue
|
|
1008
|
+
*
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```typescript
|
|
1011
|
+
* // List failed messages
|
|
1012
|
+
* const { entries } = await qb.dlq.list();
|
|
1013
|
+
*
|
|
1014
|
+
* // Retry a failed message
|
|
1015
|
+
* const result = await qb.dlq.retry(entries[0].id);
|
|
1016
|
+
*
|
|
1017
|
+
* // Delete a DLQ entry
|
|
1018
|
+
* await qb.dlq.delete(entries[0].id);
|
|
1019
|
+
*
|
|
1020
|
+
* // Purge all DLQ entries
|
|
1021
|
+
* await qb.dlq.purge();
|
|
1022
|
+
* ```
|
|
1023
|
+
*/
|
|
1024
|
+
readonly dlq: DLQAPI;
|
|
1025
|
+
/**
|
|
1026
|
+
* Workflows API for triggering and managing durable workflows
|
|
1027
|
+
*
|
|
1028
|
+
* @example
|
|
1029
|
+
* ```typescript
|
|
1030
|
+
* // Trigger a workflow
|
|
1031
|
+
* const { runId } = await qb.workflows.trigger(
|
|
1032
|
+
* "user-onboarding",
|
|
1033
|
+
* "https://your-app.com/api/workflows/onboarding",
|
|
1034
|
+
* { userId: "123", email: "user@example.com" },
|
|
1035
|
+
* { idempotencyKey: "onboarding-user-123" }
|
|
1036
|
+
* );
|
|
1037
|
+
*
|
|
1038
|
+
* // Check status
|
|
1039
|
+
* const status = await qb.workflows.getStatus(runId);
|
|
1040
|
+
*
|
|
1041
|
+
* // Wait for completion
|
|
1042
|
+
* const result = await qb.workflows.waitForCompletion(runId);
|
|
1043
|
+
*
|
|
1044
|
+
* // Send event to waiting workflows
|
|
1045
|
+
* await qb.workflows.sendEvent("order.approved", {
|
|
1046
|
+
* eventKey: "order-123",
|
|
1047
|
+
* payload: { status: "approved" }
|
|
1048
|
+
* });
|
|
1049
|
+
* ```
|
|
1050
|
+
*/
|
|
1051
|
+
readonly workflows: WorkflowsAPI;
|
|
1052
|
+
constructor(options: QueueBearOptions);
|
|
1053
|
+
/**
|
|
1054
|
+
* Publish a message and wait for delivery completion
|
|
1055
|
+
*
|
|
1056
|
+
* Convenience method that combines publish + polling in one call.
|
|
1057
|
+
*
|
|
1058
|
+
* @param destination - The URL to deliver the message to
|
|
1059
|
+
* @param body - The message body
|
|
1060
|
+
* @param options - Publish options plus polling configuration
|
|
1061
|
+
* @returns The final message status after delivery
|
|
1062
|
+
*
|
|
1063
|
+
* @example
|
|
1064
|
+
* ```typescript
|
|
1065
|
+
* const message = await qb.publishAndWait(
|
|
1066
|
+
* "https://api.example.com/webhook",
|
|
1067
|
+
* { event: "user.created" },
|
|
1068
|
+
* { timeoutMs: 30000 }
|
|
1069
|
+
* );
|
|
1070
|
+
* console.log(message.status); // "completed"
|
|
1071
|
+
* ```
|
|
1072
|
+
*/
|
|
1073
|
+
publishAndWait(destination: string, body: unknown, options?: PublishOptions & {
|
|
1074
|
+
pollIntervalMs?: number;
|
|
1075
|
+
timeoutMs?: number;
|
|
1076
|
+
}): Promise<Message>;
|
|
1077
|
+
/**
|
|
1078
|
+
* Trigger a workflow and wait for completion
|
|
1079
|
+
*
|
|
1080
|
+
* Convenience method that combines trigger + polling in one call.
|
|
1081
|
+
*
|
|
1082
|
+
* @param workflowId - Unique identifier for this workflow type
|
|
1083
|
+
* @param workflowUrl - URL of the workflow endpoint
|
|
1084
|
+
* @param input - Input data for the workflow
|
|
1085
|
+
* @param options - Trigger and polling options
|
|
1086
|
+
* @returns The final workflow status
|
|
1087
|
+
*
|
|
1088
|
+
* @example
|
|
1089
|
+
* ```typescript
|
|
1090
|
+
* const result = await qb.triggerAndWait(
|
|
1091
|
+
* "user-onboarding",
|
|
1092
|
+
* "https://your-app.com/api/workflows/onboarding",
|
|
1093
|
+
* { userId: "123" },
|
|
1094
|
+
* { timeoutMs: 120000 }
|
|
1095
|
+
* );
|
|
1096
|
+
* console.log(result.result); // Workflow output
|
|
1097
|
+
* ```
|
|
1098
|
+
*/
|
|
1099
|
+
triggerAndWait<T = unknown>(workflowId: string, workflowUrl: string, input?: T, options?: TriggerOptions & {
|
|
1100
|
+
pollIntervalMs?: number;
|
|
1101
|
+
timeoutMs?: number;
|
|
1102
|
+
}): Promise<StatusResponse>;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
/**
|
|
1106
|
+
* Error thrown when workflow needs to pause (e.g., for sleep)
|
|
1107
|
+
*/
|
|
1108
|
+
declare class WorkflowPausedError extends Error {
|
|
1109
|
+
reason: string;
|
|
1110
|
+
constructor(reason: string);
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Context options for creating a new WorkflowContext
|
|
1114
|
+
*/
|
|
1115
|
+
interface WorkflowContextOptions<T> {
|
|
1116
|
+
runId: string;
|
|
1117
|
+
runToken: string;
|
|
1118
|
+
input: T;
|
|
1119
|
+
baseUrl: string;
|
|
1120
|
+
authHeader: string;
|
|
1121
|
+
}
|
|
1122
|
+
/**
|
|
1123
|
+
* WorkflowContext provides methods for executing workflow steps
|
|
1124
|
+
*/
|
|
1125
|
+
declare class WorkflowContext<T> {
|
|
1126
|
+
readonly runId: string;
|
|
1127
|
+
readonly input: T;
|
|
1128
|
+
private runToken;
|
|
1129
|
+
private baseUrl;
|
|
1130
|
+
private authHeader;
|
|
1131
|
+
private stepIndex;
|
|
1132
|
+
constructor(options: WorkflowContextOptions<T>);
|
|
1133
|
+
/**
|
|
1134
|
+
* Execute a step with caching
|
|
1135
|
+
* Step names must be unique within a workflow run
|
|
1136
|
+
* @param stepName - Unique name for this step
|
|
1137
|
+
* @param fn - Function to execute
|
|
1138
|
+
* @param options - Optional retry configuration
|
|
1139
|
+
*/
|
|
1140
|
+
run<R>(stepName: string, fn: () => Promise<R>, options?: StepRetryOptions): Promise<R>;
|
|
1141
|
+
/**
|
|
1142
|
+
* Sleep for specified seconds
|
|
1143
|
+
* Step names must be unique within a workflow run
|
|
1144
|
+
*/
|
|
1145
|
+
sleep(stepName: string, seconds: number): Promise<void>;
|
|
1146
|
+
/**
|
|
1147
|
+
* Sleep until specific date
|
|
1148
|
+
*/
|
|
1149
|
+
sleepUntil(stepName: string, until: Date): Promise<void>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Get all completed steps for the current run
|
|
1152
|
+
* Useful for inspecting progress or debugging
|
|
1153
|
+
*/
|
|
1154
|
+
getCompletedSteps(): Promise<CompletedStep[]>;
|
|
1155
|
+
/**
|
|
1156
|
+
* Make HTTP call (executed as a step)
|
|
1157
|
+
*/
|
|
1158
|
+
call<R>(stepName: string, config: CallConfig): Promise<R>;
|
|
1159
|
+
/**
|
|
1160
|
+
* Wait for an external event
|
|
1161
|
+
* @param stepName - Unique step name
|
|
1162
|
+
* @param eventName - Name of the event to wait for
|
|
1163
|
+
* @param options - Optional event key and timeout
|
|
1164
|
+
*/
|
|
1165
|
+
waitForEvent<T = unknown>(stepName: string, eventName: string, options?: WaitForEventOptions): Promise<T>;
|
|
1166
|
+
/**
|
|
1167
|
+
* Send a fire-and-forget notification event
|
|
1168
|
+
* @param eventName - Name of the event to send
|
|
1169
|
+
* @param payload - Optional payload to include
|
|
1170
|
+
*/
|
|
1171
|
+
notify(eventName: string, payload?: unknown): Promise<void>;
|
|
1172
|
+
/**
|
|
1173
|
+
* Execute multiple steps in parallel
|
|
1174
|
+
* @param steps - Array of step definitions with name and function
|
|
1175
|
+
*/
|
|
1176
|
+
parallel<T extends readonly unknown[]>(steps: {
|
|
1177
|
+
[K in keyof T]: {
|
|
1178
|
+
name: string;
|
|
1179
|
+
fn: () => Promise<T[K]>;
|
|
1180
|
+
};
|
|
1181
|
+
}): Promise<T>;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Error thrown when parallel execution has failures
|
|
1185
|
+
*/
|
|
1186
|
+
declare class ParallelExecutionError extends Error {
|
|
1187
|
+
errors: Array<{
|
|
1188
|
+
index: number;
|
|
1189
|
+
stepName: string;
|
|
1190
|
+
error: Error;
|
|
1191
|
+
}>;
|
|
1192
|
+
constructor(message: string, errors: Array<{
|
|
1193
|
+
index: number;
|
|
1194
|
+
stepName: string;
|
|
1195
|
+
error: Error;
|
|
1196
|
+
}>);
|
|
1197
|
+
get failedStepCount(): number;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/**
|
|
1201
|
+
* Workflow handler function type
|
|
1202
|
+
*/
|
|
1203
|
+
type WorkflowHandler<TInput = unknown, TOutput = unknown> = (context: WorkflowContext<TInput>) => Promise<TOutput>;
|
|
1204
|
+
/**
|
|
1205
|
+
* Create a workflow endpoint handler
|
|
1206
|
+
*/
|
|
1207
|
+
declare function serve<TInput = unknown, TOutput = unknown>(handler: WorkflowHandler<TInput, TOutput>, options?: ServeOptions): (request: Request) => Promise<Response>;
|
|
1208
|
+
|
|
1209
|
+
export { type CallConfig, type CancelMessageResponse, type CompletedStep, type CreateScheduleOptions, type CreateScheduleResponse, DLQAPI, type DLQEntry, type DLQEntrySummary, type DeleteDLQResponse, type DeleteScheduleResponse, type DeliveryLog, type LastResponse, type ListDLQOptions, type ListDLQResponse, type ListMessagesOptions, type ListMessagesResponse, type ListRunsOptions, type ListRunsResponse, type ListSchedulesOptions, type ListSchedulesResponse, type Message, type MessageMethod, type MessageStatus, type MessageSummary, MessagesAPI, type Pagination, ParallelExecutionError, type ParallelStepDefinition, type PauseScheduleResponse, type PublishOptions, type PublishResponse, type PurgeDLQResponse, QueueBear, QueueBearError, type QueueBearOptions, type ResumeScheduleResponse, type RetryDLQResponse, type Schedule, type ScheduleSummary, SchedulesAPI, type SendEventOptions, type SendEventResponse, type ServeOptions, type StatusResponse, type StepRetryOptions, type StepType, type TriggerOptions, type TriggerResponse, type WaitForEventOptions, WorkflowContext, type WorkflowContextOptions, type WorkflowHandler, WorkflowPausedError, type WorkflowRun, type WorkflowRunStatus, type WorkflowStep, WorkflowsAPI, serve };
|