Event Publishing
Prose lets you publish domain events as part of your flow, keeping event emission co-located with the business logic that produces them.
Single event
Section titled “Single event”flow.event('orders', (ctx) => ({ eventType: 'order.created', orderId: ctx.state.orderId,}));Multiple events
Section titled “Multiple events”Publish multiple events to the same channel in one step:
flow.events('notifications', [ (ctx) => ({ eventType: 'email.send', to: ctx.input.email }), (ctx) => ({ eventType: 'sms.send', to: ctx.input.phone }),]);FlowEventPublisher interface
Section titled “FlowEventPublisher interface”Event steps require an eventPublisher property in your dependencies:
interface FlowEventPublisher { publish(channel: string, event: FlowEvent): Promise<void> | void;}The FlowEvent object your builder returns is automatically enriched with a correlationId from the flow’s metadata.
Example implementation
Section titled “Example implementation”const eventPublisher: FlowEventPublisher = { async publish(channel, event) { await redis.publish(channel, JSON.stringify(event)); },};
await flow.execute(input, { db, eventPublisher });Missing event publisher
Section titled “Missing event publisher”By default, if an event step runs but no eventPublisher dependency is provided, Prose throws an error. You can change this to a warning:
await flow.execute(input, deps, { errorHandling: { throwOnMissingEventPublisher: false, },});