awaitly 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/di-Biw_plBn.d.cts +15 -0
  2. package/dist/di-DxyH2N3i.d.ts +15 -0
  3. package/dist/durable.cjs +4670 -0
  4. package/dist/durable.cjs.map +1 -0
  5. package/dist/durable.d.cts +9 -0
  6. package/dist/durable.d.ts +9 -0
  7. package/dist/durable.js +4610 -0
  8. package/dist/durable.js.map +1 -0
  9. package/dist/{di-BbFFfO8y.d.ts → duration-BjVn3QpB.d.cts} +1 -15
  10. package/dist/{di-BDlT7InM.d.cts → duration-BjVn3QpB.d.ts} +1 -15
  11. package/dist/engine.cjs +4501 -0
  12. package/dist/engine.cjs.map +1 -0
  13. package/dist/engine.d.cts +113 -0
  14. package/dist/engine.d.ts +113 -0
  15. package/dist/engine.js +4474 -0
  16. package/dist/engine.js.map +1 -0
  17. package/dist/{errors-DtXvrCiO.d.cts → errors-sDSeaZBO.d.cts} +1 -1
  18. package/dist/{errors-DtXvrCiO.d.ts → errors-sDSeaZBO.d.ts} +1 -1
  19. package/dist/guards-CwQZro1F.d.ts +72 -0
  20. package/dist/guards-DhhOJZda.d.cts +72 -0
  21. package/dist/hitl-BnnnLzh2.d.cts +468 -0
  22. package/dist/hitl-pYfkQMv_.d.ts +468 -0
  23. package/dist/hitl.cjs +646 -0
  24. package/dist/hitl.cjs.map +1 -0
  25. package/dist/hitl.d.cts +440 -0
  26. package/dist/hitl.d.ts +440 -0
  27. package/dist/hitl.js +605 -0
  28. package/dist/hitl.js.map +1 -0
  29. package/dist/index-Bew12SZ8.d.ts +417 -0
  30. package/dist/index-Bwt-iz50.d.cts +417 -0
  31. package/dist/{types-B8NfNRGX.d.ts → index-Cv4K_3sZ.d.ts} +2 -1162
  32. package/dist/{types-BZ2f4MRR.d.cts → index-ICmfQi08.d.cts} +2 -1162
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +11 -1527
  35. package/dist/index.d.ts +11 -1527
  36. package/dist/persistence.cjs +552 -0
  37. package/dist/persistence.cjs.map +1 -0
  38. package/dist/persistence.d.cts +254 -0
  39. package/dist/persistence.d.ts +254 -0
  40. package/dist/persistence.js +499 -0
  41. package/dist/persistence.js.map +1 -0
  42. package/dist/reliability.cjs +1651 -0
  43. package/dist/reliability.cjs.map +1 -0
  44. package/dist/reliability.d.cts +1442 -0
  45. package/dist/reliability.d.ts +1442 -0
  46. package/dist/reliability.js +1589 -0
  47. package/dist/reliability.js.map +1 -0
  48. package/dist/result.d.cts +1 -1
  49. package/dist/result.d.ts +1 -1
  50. package/dist/run.cjs +2283 -0
  51. package/dist/run.cjs.map +1 -0
  52. package/dist/run.d.cts +90 -0
  53. package/dist/run.d.ts +90 -0
  54. package/dist/run.js +2247 -0
  55. package/dist/run.js.map +1 -0
  56. package/dist/saga.cjs +3699 -0
  57. package/dist/saga.cjs.map +1 -0
  58. package/dist/saga.d.cts +162 -0
  59. package/dist/saga.d.ts +162 -0
  60. package/dist/saga.js +3670 -0
  61. package/dist/saga.js.map +1 -0
  62. package/dist/store-contract-BI98VYmX.d.ts +66 -0
  63. package/dist/store-contract-C2HyR_o6.d.cts +66 -0
  64. package/dist/streaming.cjs +895 -0
  65. package/dist/streaming.cjs.map +1 -0
  66. package/dist/streaming.d.cts +594 -0
  67. package/dist/streaming.d.ts +594 -0
  68. package/dist/streaming.js +832 -0
  69. package/dist/streaming.js.map +1 -0
  70. package/dist/testing.d.cts +4 -2
  71. package/dist/testing.d.ts +4 -2
  72. package/dist/types-BDTxgKKc.d.ts +845 -0
  73. package/dist/types-C9Y71dua.d.cts +845 -0
  74. package/dist/types-d8q8iQlk.d.cts +323 -0
  75. package/dist/types-sObbY4mX.d.ts +323 -0
  76. package/dist/webhook.cjs +461 -0
  77. package/dist/webhook.cjs.map +1 -0
  78. package/dist/webhook.d.cts +497 -0
  79. package/dist/webhook.d.ts +497 -0
  80. package/dist/webhook.js +422 -0
  81. package/dist/webhook.js.map +1 -0
  82. package/dist/workflow.cjs +2 -2614
  83. package/dist/workflow.cjs.map +1 -1
  84. package/dist/workflow.d.cts +12 -3023
  85. package/dist/workflow.d.ts +12 -3023
  86. package/dist/workflow.js +2 -2535
  87. package/dist/workflow.js.map +1 -1
  88. package/package.json +46 -1
@@ -0,0 +1,497 @@
1
+ import { R as Result, A as AsyncResult, a as RunStep } from './index-ICmfQi08.cjs';
2
+ import { W as Workflow } from './types-C9Y71dua.cjs';
3
+ import { U as UnexpectedError } from './errors-sDSeaZBO.cjs';
4
+ import './types-d8q8iQlk.cjs';
5
+ import '@standard-schema/spec';
6
+
7
+ /**
8
+ * awaitly/webhook
9
+ *
10
+ * Webhook and event trigger adapters for exposing workflows as HTTP endpoints.
11
+ * Framework-agnostic handlers that work with Express, Hono, Fastify, etc.
12
+ */
13
+
14
+ /**
15
+ * Generic HTTP request representation.
16
+ * Abstracts away framework-specific request objects.
17
+ */
18
+ interface WebhookRequest<Body = unknown> {
19
+ /** HTTP method (GET, POST, PUT, DELETE, etc.) */
20
+ method: string;
21
+ /** Request path (e.g., "/api/checkout") */
22
+ path: string;
23
+ /** Request headers */
24
+ headers: Record<string, string | string[] | undefined>;
25
+ /** Parsed request body (JSON) */
26
+ body: Body;
27
+ /** Query parameters */
28
+ query: Record<string, string | string[] | undefined>;
29
+ /** Path parameters (e.g., { id: "123" }) */
30
+ params: Record<string, string>;
31
+ /** Raw request object from framework (for advanced use cases) */
32
+ raw?: unknown;
33
+ }
34
+ /**
35
+ * Generic HTTP response representation.
36
+ */
37
+ interface WebhookResponse<T = unknown> {
38
+ /** HTTP status code */
39
+ status: number;
40
+ /** Response headers */
41
+ headers?: Record<string, string>;
42
+ /** Response body (will be JSON serialized) */
43
+ body: T;
44
+ }
45
+ /**
46
+ * Error response body structure.
47
+ */
48
+ interface ErrorResponseBody {
49
+ error: {
50
+ type: string;
51
+ message?: string;
52
+ details?: unknown;
53
+ };
54
+ }
55
+ /**
56
+ * Input validation result.
57
+ */
58
+ type ValidationResult<T, E = string> = Result<T, E>;
59
+ /**
60
+ * Standard validation error type.
61
+ */
62
+ interface ValidationError {
63
+ type: "VALIDATION_ERROR";
64
+ message: string;
65
+ field?: string;
66
+ details?: unknown;
67
+ }
68
+ /**
69
+ * Type guard for ValidationError.
70
+ */
71
+ declare function isValidationError(e: unknown): e is ValidationError;
72
+ /**
73
+ * Configuration for creating a webhook handler.
74
+ *
75
+ * @template TInput - The validated input type
76
+ * @template TOutput - The workflow output type
77
+ * @template TError - The workflow error type
78
+ * @template TBody - The raw request body type
79
+ * @template TUnexpected - The workflow's unexpected error type (default UnexpectedError)
80
+ */
81
+ interface WebhookHandlerConfig<TInput, TOutput, TError, TBody = unknown, TUnexpected = UnexpectedError> {
82
+ /**
83
+ * Validate and transform the incoming request.
84
+ * Return ok(input) to proceed, or err(validationError) to reject.
85
+ *
86
+ * @param req - The incoming request
87
+ * @returns Validated input or validation error
88
+ */
89
+ validateInput: (req: WebhookRequest<TBody>) => ValidationResult<TInput, ValidationError> | Promise<ValidationResult<TInput, ValidationError>>;
90
+ /**
91
+ * Map workflow result to HTTP response.
92
+ * Called for both success and error cases.
93
+ *
94
+ * @param result - The workflow result (error union is TError | TUnexpected)
95
+ * @param req - The original request (for context)
96
+ * @returns HTTP response
97
+ */
98
+ mapResult: (result: Result<TOutput, TError | TUnexpected>, req: WebhookRequest<TBody>) => WebhookResponse;
99
+ /**
100
+ * Optional: Map validation errors to HTTP response.
101
+ * Defaults to 400 Bad Request with error details.
102
+ *
103
+ * @param error - The validation error
104
+ * @param req - The original request
105
+ * @returns HTTP response
106
+ */
107
+ mapValidationError?: (error: ValidationError, req: WebhookRequest<TBody>) => WebhookResponse<ErrorResponseBody>;
108
+ /**
109
+ * Optional: Handle unexpected errors during request processing.
110
+ * Defaults to 500 Internal Server Error.
111
+ *
112
+ * @param error - The unexpected error
113
+ * @param req - The original request
114
+ * @returns HTTP response
115
+ */
116
+ mapUnexpectedError?: (error: unknown, req: WebhookRequest<TBody>) => WebhookResponse<ErrorResponseBody>;
117
+ /**
118
+ * Optional: Request middleware.
119
+ * Transform or enrich the request before validation.
120
+ *
121
+ * @param req - The incoming request
122
+ * @returns Transformed request
123
+ */
124
+ beforeValidation?: (req: WebhookRequest<TBody>) => WebhookRequest<TBody> | Promise<WebhookRequest<TBody>>;
125
+ /**
126
+ * Optional: Response middleware.
127
+ * Transform the response before sending.
128
+ *
129
+ * @param response - The response to send
130
+ * @param req - The original request
131
+ * @returns Transformed response
132
+ */
133
+ afterResponse?: (response: WebhookResponse, req: WebhookRequest<TBody>) => WebhookResponse | Promise<WebhookResponse>;
134
+ }
135
+ /**
136
+ * A webhook handler function that processes requests.
137
+ */
138
+ type WebhookHandler<TBody = unknown> = (req: WebhookRequest<TBody>) => Promise<WebhookResponse>;
139
+ /**
140
+ * Default validation error mapper.
141
+ * Returns 400 Bad Request with error details.
142
+ */
143
+ declare function defaultValidationErrorMapper(error: ValidationError): WebhookResponse<ErrorResponseBody>;
144
+ /**
145
+ * Default unexpected error mapper.
146
+ * Returns 500 Internal Server Error.
147
+ */
148
+ declare function defaultUnexpectedErrorMapper(error: unknown): WebhookResponse<ErrorResponseBody>;
149
+ /**
150
+ * Create a webhook handler for a workflow.
151
+ *
152
+ * This factory creates an HTTP handler function that:
153
+ * 1. Validates the incoming request
154
+ * 2. Executes the workflow with the validated input
155
+ * 3. Maps the result to an HTTP response
156
+ *
157
+ * The handler is framework-agnostic and returns a standard response object.
158
+ * Use framework adapters (createExpressHandler, createHonoHandler, etc.) to
159
+ * integrate with specific frameworks.
160
+ *
161
+ * @template TInput - The validated input type passed to the workflow
162
+ * @template TOutput - The workflow output type
163
+ * @template TError - The workflow error type
164
+ * @template TBody - The raw request body type
165
+ * @template TDeps - The workflow dependencies type
166
+ *
167
+ * @param workflow - The workflow function to execute
168
+ * @param workflowFn - The workflow body function ({ step, deps, args }) => output
169
+ * @param config - Handler configuration
170
+ * @returns A webhook handler function
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * const checkoutWorkflow = createWorkflow('checkout', { chargeCard, sendEmail });
175
+ *
176
+ * const handler = createWebhookHandler(
177
+ * checkoutWorkflow,
178
+ * async ({ step, deps, args: input }) => {
179
+ * const charge = await step('chargeCard', () => deps.chargeCard(input.amount));
180
+ * await step('sendEmail', () => deps.sendEmail(input.email, charge.receiptUrl));
181
+ * return { chargeId: charge.id };
182
+ * },
183
+ * {
184
+ * validateInput: (req) => {
185
+ * const { amount, email } = req.body;
186
+ * if (!amount || !email) {
187
+ * return err({ type: 'VALIDATION_ERROR', message: 'Missing required fields' });
188
+ * }
189
+ * return ok({ amount, email });
190
+ * },
191
+ * mapResult: (result) => {
192
+ * if (result.ok) {
193
+ * return { status: 200, body: result.value };
194
+ * }
195
+ * if (result.error === 'CARD_DECLINED') {
196
+ * return { status: 402, body: { error: { type: 'CARD_DECLINED' } } };
197
+ * }
198
+ * return { status: 500, body: { error: { type: 'UNKNOWN' } } };
199
+ * },
200
+ * }
201
+ * );
202
+ *
203
+ * // Use with Express
204
+ * app.post('/checkout', async (req, res) => {
205
+ * const response = await handler(toWebhookRequest(req));
206
+ * res.status(response.status).json(response.body);
207
+ * });
208
+ * ```
209
+ */
210
+ declare function createWebhookHandler<TInput, TOutput, TError, TUnexpected, TBody = unknown, TDeps = unknown>(workflow: Workflow<TError, TUnexpected, TDeps>, workflowFn: (context: {
211
+ step: RunStep<TError | TUnexpected>;
212
+ deps: TDeps;
213
+ args: TInput;
214
+ }) => TOutput | Promise<TOutput>, config: WebhookHandlerConfig<TInput, TOutput, TError, TBody, TUnexpected>): WebhookHandler<TBody>;
215
+ declare function createWebhookHandler<TInput, TOutput, TError, TBody = unknown, TDeps = unknown>(workflow: Workflow<TError, UnexpectedError, TDeps>, workflowFn: (context: {
216
+ step: RunStep<TError | UnexpectedError>;
217
+ deps: TDeps;
218
+ args: TInput;
219
+ }) => TOutput | Promise<TOutput>, config: WebhookHandlerConfig<TInput, TOutput, TError, TBody, UnexpectedError>): WebhookHandler<TBody>;
220
+ /**
221
+ * Configuration for a simple webhook handler without workflow.
222
+ * Use with createSimpleHandler for endpoints that don't need step orchestration.
223
+ *
224
+ * @template TInput - Validated input type
225
+ * @template TOutput - Handler success output type
226
+ * @template TError - Handler error type
227
+ * @template TBody - Raw request body type
228
+ */
229
+ interface SimpleHandlerConfig<TInput, TOutput, TError, TBody = unknown> {
230
+ /** Validate and transform the incoming request; return ok(input) or err(ValidationError). */
231
+ validateInput: (req: WebhookRequest<TBody>) => ValidationResult<TInput, ValidationError> | Promise<ValidationResult<TInput, ValidationError>>;
232
+ /** Execute the business logic; return Result. */
233
+ handler: (input: TInput, req: WebhookRequest<TBody>) => AsyncResult<TOutput, TError>;
234
+ /** Map the handler result to an HTTP response. */
235
+ mapResult: (result: Result<TOutput, TError>, req: WebhookRequest<TBody>) => WebhookResponse;
236
+ /** Optional: map validation errors to response. Defaults to 400 with error details. */
237
+ mapValidationError?: (error: ValidationError, req: WebhookRequest<TBody>) => WebhookResponse<ErrorResponseBody>;
238
+ /** Optional: handle unexpected errors. Defaults to 500. */
239
+ mapUnexpectedError?: (error: unknown, req: WebhookRequest<TBody>) => WebhookResponse<ErrorResponseBody>;
240
+ }
241
+ /**
242
+ * Create a simple webhook handler without workflow orchestration.
243
+ * Useful for simple endpoints that don't need step-based error handling.
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const handler = createSimpleHandler({
248
+ * validateInput: (req) => {
249
+ * const { id } = req.params;
250
+ * if (!id) return err({ type: 'VALIDATION_ERROR', message: 'Missing id' });
251
+ * return ok({ id });
252
+ * },
253
+ * handler: async ({ id }) => {
254
+ * const user = await db.findUser(id);
255
+ * return user ? ok(user) : err('NOT_FOUND' as const);
256
+ * },
257
+ * mapResult: (result) => {
258
+ * if (result.ok) return { status: 200, body: result.value };
259
+ * return { status: 404, body: { error: { type: 'NOT_FOUND' } } };
260
+ * },
261
+ * });
262
+ * ```
263
+ */
264
+ declare function createSimpleHandler<TInput, TOutput, TError, TBody = unknown>(config: SimpleHandlerConfig<TInput, TOutput, TError, TBody>): WebhookHandler<TBody>;
265
+ /**
266
+ * Standard error mapping configuration.
267
+ */
268
+ interface ErrorMapping<TError> {
269
+ /** The error value to match */
270
+ error: TError;
271
+ /** HTTP status code for this error */
272
+ status: number;
273
+ /** Optional custom message */
274
+ message?: string;
275
+ }
276
+ /**
277
+ * Create a result mapper from error mappings.
278
+ * Provides a declarative way to map workflow errors to HTTP responses.
279
+ *
280
+ * @param mappings - Array of error mappings
281
+ * @param defaultStatus - Default status for unmapped errors (default: 500)
282
+ * @returns A mapResult function for use in handler config
283
+ *
284
+ * @example
285
+ * ```typescript
286
+ * const mapResult = createResultMapper<CheckoutOutput, CheckoutError>([
287
+ * { error: 'NOT_FOUND', status: 404, message: 'Resource not found' },
288
+ * { error: 'CARD_DECLINED', status: 402, message: 'Payment failed' },
289
+ * { error: 'RATE_LIMITED', status: 429, message: 'Too many requests' },
290
+ * ]);
291
+ *
292
+ * const handler = createWebhookHandler(workflow, workflowFn, {
293
+ * validateInput,
294
+ * mapResult,
295
+ * });
296
+ * ```
297
+ */
298
+ declare function createResultMapper<TOutput, TError>(mappings: ErrorMapping<TError>[], options?: {
299
+ defaultStatus?: number;
300
+ successStatus?: number;
301
+ }): (result: Result<TOutput, TError | UnexpectedError>) => WebhookResponse;
302
+ /**
303
+ * Express-style request object (minimal interface).
304
+ */
305
+ interface ExpressLikeRequest {
306
+ method: string;
307
+ path: string;
308
+ headers: Record<string, string | string[] | undefined>;
309
+ body: unknown;
310
+ query: Record<string, string | string[] | undefined>;
311
+ params: Record<string, string>;
312
+ }
313
+ /**
314
+ * Express-style response object (minimal interface).
315
+ */
316
+ interface ExpressLikeResponse {
317
+ status(code: number): ExpressLikeResponse;
318
+ set(headers: Record<string, string>): ExpressLikeResponse;
319
+ json(body: unknown): void;
320
+ }
321
+ /**
322
+ * Convert an Express-like request to WebhookRequest.
323
+ *
324
+ * @param req - Express-like request object
325
+ * @returns WebhookRequest
326
+ *
327
+ * @example
328
+ * ```typescript
329
+ * app.post('/checkout', async (req, res) => {
330
+ * const webhookReq = toWebhookRequest(req);
331
+ * const response = await handler(webhookReq);
332
+ * res.status(response.status).json(response.body);
333
+ * });
334
+ * ```
335
+ */
336
+ declare function toWebhookRequest<TBody = unknown>(req: ExpressLikeRequest): WebhookRequest<TBody>;
337
+ /**
338
+ * Send a WebhookResponse using an Express-like response object.
339
+ *
340
+ * @param res - Express-like response object
341
+ * @param response - WebhookResponse to send
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * app.post('/checkout', async (req, res) => {
346
+ * const response = await handler(toWebhookRequest(req));
347
+ * sendWebhookResponse(res, response);
348
+ * });
349
+ * ```
350
+ */
351
+ declare function sendWebhookResponse(res: ExpressLikeResponse, response: WebhookResponse): void;
352
+ /**
353
+ * Create an Express-compatible middleware from a webhook handler.
354
+ *
355
+ * @param handler - Webhook handler function
356
+ * @returns Express middleware function
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * const handler = createWebhookHandler(workflow, workflowFn, config);
361
+ * const middleware = createExpressHandler(handler);
362
+ * app.post('/checkout', middleware);
363
+ * ```
364
+ */
365
+ declare function createExpressHandler<TBody = unknown>(handler: WebhookHandler<TBody>): (req: ExpressLikeRequest, res: ExpressLikeResponse) => Promise<void>;
366
+ /**
367
+ * Create a validation error.
368
+ *
369
+ * @param message - Error message
370
+ * @param field - Optional field name
371
+ * @param details - Optional additional details
372
+ * @returns ValidationError
373
+ */
374
+ declare function validationError(message: string, field?: string, details?: unknown): ValidationError;
375
+ /**
376
+ * Create a required field validator.
377
+ *
378
+ * @param fields - Field names to validate
379
+ * @returns Validation function
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * const validateRequired = requireFields(['email', 'password']);
384
+ *
385
+ * const validateInput = (req) => {
386
+ * const result = validateRequired(req.body);
387
+ * if (!result.ok) return result;
388
+ * return ok(req.body as LoginInput);
389
+ * };
390
+ * ```
391
+ */
392
+ declare function requireFields(fields: string[]): (body: Record<string, unknown>) => ValidationResult<void, ValidationError>;
393
+ /**
394
+ * Compose multiple validators into a single validator.
395
+ *
396
+ * @param validators - Validators to compose
397
+ * @returns Combined validator function
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * const validate = composeValidators(
402
+ * requireFields(['email', 'password']),
403
+ * validateEmailFormat,
404
+ * validatePasswordStrength
405
+ * );
406
+ * ```
407
+ */
408
+ declare function composeValidators<T>(...validators: Array<(input: T) => ValidationResult<void, ValidationError>>): (input: T) => ValidationResult<void, ValidationError>;
409
+ /**
410
+ * Generic event message for queue-based triggers.
411
+ */
412
+ interface EventMessage<T = unknown> {
413
+ /** Unique message ID */
414
+ id: string;
415
+ /** Event type/name */
416
+ type: string;
417
+ /** Event payload */
418
+ payload: T;
419
+ /** Event metadata */
420
+ metadata?: {
421
+ timestamp?: number;
422
+ source?: string;
423
+ correlationId?: string;
424
+ [key: string]: unknown;
425
+ };
426
+ }
427
+ /**
428
+ * Result of processing an event.
429
+ */
430
+ interface EventProcessingResult {
431
+ /** Whether the event was processed successfully */
432
+ success: boolean;
433
+ /** Should the message be acknowledged (removed from queue)? */
434
+ ack: boolean;
435
+ /** Optional error details */
436
+ error?: {
437
+ type: string;
438
+ message?: string;
439
+ retryable?: boolean;
440
+ };
441
+ }
442
+ /**
443
+ * Configuration for event trigger handlers.
444
+ */
445
+ interface EventTriggerConfig<TPayload, TOutput, TError, TUnexpected = UnexpectedError> {
446
+ /** Validate the event payload */
447
+ validatePayload: (event: EventMessage<TPayload>) => ValidationResult<TPayload, ValidationError>;
448
+ /** Map workflow result to processing result */
449
+ mapResult: (result: Result<TOutput, TError | TUnexpected>, event: EventMessage<TPayload>) => EventProcessingResult;
450
+ /** Optional: Determine if error is retryable */
451
+ isRetryable?: (error: TError | TUnexpected) => boolean;
452
+ }
453
+ /**
454
+ * Event handler function type.
455
+ */
456
+ type EventHandler<TPayload = unknown> = (event: EventMessage<TPayload>) => Promise<EventProcessingResult>;
457
+ /**
458
+ * Create an event handler for queue-based triggers.
459
+ *
460
+ * @example
461
+ * ```typescript
462
+ * const handler = createEventHandler(
463
+ * checkoutWorkflow,
464
+ * async ({ step, deps, args: payload }) => {
465
+ * const charge = await step('chargeCard', () => deps.chargeCard(payload.amount));
466
+ * return { chargeId: charge.id };
467
+ * },
468
+ * {
469
+ * validatePayload: (event) => {
470
+ * if (!event.payload.amount) {
471
+ * return err({ type: 'VALIDATION_ERROR', message: 'Missing amount' });
472
+ * }
473
+ * return ok(event.payload);
474
+ * },
475
+ * mapResult: (result) => ({
476
+ * success: result.ok,
477
+ * ack: result.ok || !isRetryableError(result.error),
478
+ * error: result.ok ? undefined : { type: String(result.error) },
479
+ * }),
480
+ * }
481
+ * );
482
+ *
483
+ * // Use with SQS, RabbitMQ, etc.
484
+ * queue.consume(async (message) => {
485
+ * const result = await handler(message);
486
+ * if (result.ack) await message.ack();
487
+ * else await message.nack();
488
+ * });
489
+ * ```
490
+ */
491
+ declare function createEventHandler<TPayload, TOutput, TError, TDeps = unknown, TUnexpected = UnexpectedError>(workflow: Workflow<TError, TUnexpected, TDeps>, workflowFn: (context: {
492
+ step: RunStep<TError | TUnexpected>;
493
+ deps: TDeps;
494
+ args: TPayload;
495
+ }) => TOutput | Promise<TOutput>, config: EventTriggerConfig<TPayload, TOutput, TError, TUnexpected>): EventHandler<TPayload>;
496
+
497
+ export { type ErrorMapping, type ErrorResponseBody, type EventHandler, type EventMessage, type EventProcessingResult, type EventTriggerConfig, type ExpressLikeRequest, type ExpressLikeResponse, type SimpleHandlerConfig, type ValidationError, type ValidationResult, type WebhookHandler, type WebhookHandlerConfig, type WebhookRequest, type WebhookResponse, composeValidators, createEventHandler, createExpressHandler, createResultMapper, createSimpleHandler, createWebhookHandler, defaultUnexpectedErrorMapper, defaultValidationErrorMapper, isValidationError, requireFields, sendWebhookResponse, toWebhookRequest, validationError };