Class: FlowBuilder<TMessageId>
Defined in: flow-builder.ts:232
Build EventCatalog flow resources using a fluent API.
FlowBuilder is useful when you want to define flows in code and then write
the generated Flow resource with writeFlow. The builder outputs the normal
EventCatalog Flow shape, so the persisted catalog remains standard
markdown/frontmatter.
nextSteps is the authoring API. When build() is called, a single next step
is normalized to next_step and multiple next steps are normalized to
next_steps.
Examples
import utils, { FlowBuilder } from '@eventcatalog/sdk';
const { writeFlow } = utils('/path/to/eventcatalog');
const flow = FlowBuilder.create({
id: 'PaymentFlow',
name: 'Payment Flow',
version: '1.0.0',
markdown: '# Payment Flow',
})
.addStep({
id: 'Customer places order',
nextSteps: [{ id: 'PlaceOrder', label: 'places order' }],
})
.addMessageStep({
id: 'PlaceOrder',
message: { id: 'PlaceOrder' },
nextSteps: [{ id: 'PaymentService', label: 'process payment' }],
})
.addServiceStep({
id: 'PaymentService',
service: { id: 'PaymentService' },
})
.build();
await writeFlow(flow);
import { FlowBuilder } from '@eventcatalog/sdk';
type PaymentMessageId = 'PlaceOrder' | 'PaymentProcessed';
const flow = FlowBuilder.create<PaymentMessageId>({
id: 'TypedPaymentFlow',
name: 'Typed Payment Flow',
version: '1.0.0',
markdown: '# Typed Payment Flow',
})
.addMessageStep({
id: 'PlaceOrder',
nextSteps: [{ id: 'PaymentProcessed' }],
})
.addMessageStep({
id: 'PaymentProcessed',
})
.build();
Type Parameters
| Type Parameter |
|---|
TMessageId extends string |
Methods
addActorStep()
addActorStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:519
Add an actor step.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowActorStepInput | The actor step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addActorStep({
id: 'Customer',
actor: { name: 'Customer' },
});
addAgentStep()
addAgentStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:393
Add an agent step.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowAgentStepInput | The agent step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addAgentStep({
id: 'FraudReviewAgent',
agent: { id: 'FraudReviewAgent', version: '1.0.0' },
});
addContainerStep()
addContainerStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:456
Add a container step.
Alias for addDataStoreStep.
Parameters
| Parameter | Type |
|---|---|
step | FlowDataStoreStepInput |
Returns
FlowBuilder<TMessageId>
addCustomStep()
addCustomStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:635
Add a custom flow step.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowCustomStepInput | The custom step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'PaymentFlow',
name: 'Payment Flow',
version: '1.0.0',
markdown: '',
})
.addCustomStep({
id: 'ManualReview',
custom: {
title: 'Manual review',
type: 'manual',
},
});
addDataProductStep()
addDataProductStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:482
Add a data product step.
If a version is not provided, EventCatalog resolves the latest matching data product version when rendering the flow.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowDataProductStepInput | The data product step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addDataProductStep({
id: 'OrderAnalytics',
dataProduct: { id: 'OrderAnalytics', version: '1.0.0' },
});
addDataStoreStep()
addDataStoreStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:433
Add a data store step.
Data store steps reference container resources in EventCatalog. If a version is not provided, EventCatalog resolves the latest matching container version when rendering the flow.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowDataStoreStepInput | The data store step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addDataStoreStep({
id: 'OrdersDB',
container: { id: 'OrdersDB', version: '1.0.0' },
});
addExternalSystemStep()
addExternalSystemStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:559
Add an external system step.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowExternalSystemStepInput | The external system step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'PaymentFlow',
name: 'Payment Flow',
version: '1.0.0',
markdown: '',
})
.addExternalSystemStep({
id: 'Stripe',
externalSystem: {
name: 'Stripe',
summary: 'Payment provider',
url: 'https://stripe.com',
},
});
addFlowStep()
addFlowStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:596
Add a sub-flow step.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowSubFlowStepInput | The sub-flow step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addFlowStep({
id: 'PaymentFlow',
flow: { id: 'PaymentFlow', version: '1.0.0' },
});
addMessageStep()
addMessageStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:321
Add a message step.
Message steps can reference an event, command, or query id.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowMessageStepInput<TMessageId> | The message step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addMessageStep({
id: 'OrderConfirmed',
title: 'Order confirmed',
message: { id: 'OrderConfirmed', version: '1.0.0' },
});
addServiceStep()
addServiceStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:357
Add a service step.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowServiceStepInput | The service step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addServiceStep({
id: 'OrderService',
service: { id: 'OrderService', version: '1.0.0' },
});
addStep()
addStep(
step):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:288
Add a generic flow step.
Generic steps are useful for business process stages that do not map to another catalog resource.
Parameters
| Parameter | Type | Description |
|---|---|---|
step | FlowStepInput | The step payload. |
Returns
FlowBuilder<TMessageId>
Example
FlowBuilder.create({
id: 'OrderFlow',
name: 'Order Flow',
version: '1.0.0',
markdown: '',
})
.addStep({
id: 'Calculate',
title: 'Calculate totals',
nextSteps: [{ id: 'OrderConfirmed' }],
});
build()
build():
Flow
Defined in: flow-builder.ts:664
Build the EventCatalog flow resource.
Returns
Flow
A Flow resource that can be written with writeFlow.
create()
staticcreate<TMessageId>(flow):FlowBuilder<TMessageId>
Defined in: flow-builder.ts:261
Create a flow builder.
The created builder can add steps and then produce a normal Flow resource
with build().
Type Parameters
| Type Parameter |
|---|
TMessageId extends string |
Parameters
| Parameter | Type |
|---|---|
flow | FlowBuilderInput |
Returns
FlowBuilder<TMessageId>
Example
const flow = FlowBuilder.create({
id: 'PaymentFlow',
name: 'Payment Flow',
version: '1.0.0',
markdown: '# Payment Flow',
}).build();