This document details the platform.flows library. This package manages and executes complex workflow logic within your application. It provides a complete set of tools including state management, API services, model definitions, and (when needed) UI components to capture and operate on flows, flow nodes, flow prompts, and flow containers.
The platform.flows package provides a framework for managing complex flows within your application. It supports:
This package is designed to be integrated with your Angular application, supporting both development (with mock APIs) and production (with live APIs) environments.
A high-level overview of the flows package layout:
.eslintrc.json, jest.config.ts, ng-package.json, package.json, project.jsontsconfig.json, tsconfig.lib.json, tsconfig.lib.prod.json, tsconfig.spec.jsonindex.ts – Main entry point re-exporting the module.test-setup.ts – Jest test configuration.FLOW_NODE_STATE_FEATURE_KEY, FLOW_CONTAINER_STATE_FEATURE_KEY).createNamespacedFeatureKey. For example, the flow container state is registered as:
provideState(
createNamespacedFeatureKey(
Identifiers.FLOWS_ACTION_IDENTIFIER,
Identifiers.FLOW_CONTAINER_STATE_FEATURE_KEY
), flowContainerReducer
)
live() and mock()) for setting up API providers based on the current environment.The flows package uses NgRx to manage state changes and side effects in a predictable manner.
FLOWS_ACTION_IDENTIFIER, FLOW_NODE_STATE_FEATURE_KEY, and FLOW_CONTAINER_STATE_FEATURE_KEY to ensure consistency.Actions trigger state changes. Here we detail the main action groups:
createFlowNode:
Initiates the creation of a new flow node.
Payload: Node details (e.g. title, content, continuation options).
File: flow-node.actions.ts
updateFlowNode:
Triggers an update to an existing flow node.
Payload: Node ID and updated fields.
File: flow-node.actions.ts
deleteFlowNode:
Initiates removal of a specified flow node.
Payload: Node ID.
File: flow-node.actions.ts
loadFlowNode:
Requests to load detailed information for a given flow node (used to refresh node data).
File: flow-node.actions.ts
createFlowContainer:
Dispatches an action to create a new flow container.
Payload: Container details such as name and configuration options.
File: flow-container.actions.ts
updateFlowContainer:
Updates an existing container’s details.
Payload: Container ID and updates.
File: flow-container.actions.ts
deleteFlowContainer:
Removes a flow container by ID.
File: flow-container.actions.ts
getFlowContainer:
Triggers retrieval of a specific container’s details.
File: flow-container.actions.ts
listFlowContainers:
Requests a listing/pagination of available flow containers.
File: flow-container.actions.ts
createFlowNode and calls the appropriate API service.switchMap, catchError, and debounceTime to manage side effects and dispatch subsequent actions.createReducer and on functions from NgRx.Facades provide an abstraction layer over NgRx so components can interact with the flows state easily.
createNode(payload: FlowNodePayload): void – Dispatches the createFlowNode action.updateNode(nodeId: string, updates: Partial<FlowNodePayload>): void – Dispatches updateFlowNode.deleteNode(nodeId: string): void – Dispatches deleteFlowNode.loadNode(nodeId: string): Observable<FlowNode> – Returns an Observable for the node details using selectors.createContainer(payload: FlowContainerPayload): void – Dispatches createFlowContainer.updateContainer(id: string, updates: Partial<FlowContainerPayload>): void – Dispatches updateFlowContainer.deleteContainer(id: string): void – Dispatches deleteFlowContainer.getContainer(id: string): Observable<FlowContainer> – Returns the container details via an appropriate selector.listContainers(): Observable<FlowContainer[]> – Subscribes to state slices containing the container list.Note: These facades subscribe to relevant selectors (e.g. for loading status, data, and error messages) and dispatch corresponding actions, thereby simplifying component code.
Models in the flows package define the data structures across the package:
model/filters and model/requests.The flows package provides API services for backend interactions.
addNode(payload: FlowNodePayload): Observable<FlowNodeResponse>getNodeById(nodeId: string): Observable<FlowNodeResponse>updateNode(nodeId: string, updates: Partial<FlowNodePayload>): Observable<FlowNodeResponse>removeNode(nodeId: string): Observable<void>createContainer(payload: FlowContainerPayload): Observable<FlowContainerResponse>getContainerById(id: string): Observable<FlowContainerResponse>updateContainer(id: string, updates: Partial<FlowContainerPayload>): Observable<FlowContainerResponse>listContainers(params?: ContainerQueryParams): Observable<FlowContainerResponse[]>deleteContainer(id: string): Observable<void>Configuration:
Both live and mock API services are wired through the module’s provider configuration in zwp.flows.module.ts using static methods live() or mock().
nx build platform.flows
nx test platform.flows
import { ZWPFlowsModule } from '@zwp/platform.flows';
@NgModule({
imports: [
// For production:
ZWPFlowsModule.live(),
// For development/testing:
// ZWPFlowsModule.mock()
]
})
export class AppModule {}
constructor(private flowContainerFacade: FlowContainerFacade) {}
createNewContainer() {
this.flowContainerFacade.createContainer({ name: 'New Container' });
}
The platform.flows package delivers a powerful foundation for managing workflow logic in your application. With detailed NgRx state management (including comprehensive actions, selectors, and facades), clearly defined models, and robust API services for both live and mock environments, this package provides a scalable and maintainable solution for implementing complex flows.