Skip to main content
View as Markdown

Class: FlowBuilder<TMessageId>

Defined in: flow-builder.ts:234

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:521

Add an actor step.

Parameters​

ParameterTypeDescription
stepFlowActorStepInputThe 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:395

Add an agent step.

Parameters​

ParameterTypeDescription
stepFlowAgentStepInputThe 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:458

Add a container step.

Alias for addDataStoreStep.

Parameters​

ParameterType
stepFlowDataStoreStepInput

Returns​

FlowBuilder<TMessageId>


addCustomStep()​

addCustomStep(step): FlowBuilder<TMessageId>

Defined in: flow-builder.ts:637

Add a custom flow step.

Parameters​

ParameterTypeDescription
stepFlowCustomStepInputThe 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:484

Add a data product step.

If a version is not provided, EventCatalog resolves the latest matching data product version when rendering the flow.

Parameters​

ParameterTypeDescription
stepFlowDataProductStepInputThe 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:435

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​

ParameterTypeDescription
stepFlowDataStoreStepInputThe 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:561

Add an external system step.

Parameters​

ParameterTypeDescription
stepFlowExternalSystemStepInputThe 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:598

Add a sub-flow step.

Parameters​

ParameterTypeDescription
stepFlowSubFlowStepInputThe 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:323

Add a message step.

Message steps can reference an event, command, or query id.

Parameters​

ParameterTypeDescription
stepFlowMessageStepInput<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:359

Add a service step.

Parameters​

ParameterTypeDescription
stepFlowServiceStepInputThe 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:290

Add a generic flow step.

Generic steps are useful for business process stages that do not map to another catalog resource.

Parameters​

ParameterTypeDescription
stepFlowStepInputThe 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:666

Build the EventCatalog flow resource.

Returns​

Flow

A Flow resource that can be written with writeFlow.


create()​

static create<TMessageId>(flow): FlowBuilder<TMessageId>

Defined in: flow-builder.ts:263

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​

ParameterType
flowFlowBuilderInput

Returns​

FlowBuilder<TMessageId>

Example​

const flow = FlowBuilder.create({
id: 'PaymentFlow',
name: 'Payment Flow',
version: '1.0.0',
markdown: '# Payment Flow',
}).build();