Skip to content
Prose v0.3.2

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.

flow.event('orders', (ctx) => ({
eventType: 'order.created',
orderId: ctx.state.orderId,
}));

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 }),
]);

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.

const eventPublisher: FlowEventPublisher = {
async publish(channel, event) {
await redis.publish(channel, JSON.stringify(event));
},
};
await flow.execute(input, { db, eventPublisher });

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,
},
});