@venturialstd/workflow
v0.1.114
Published
Workflow Module for Venturial
Keywords
Readme
Workflow Module
A comprehensive workflow management module for Venturial that handles workflow creation, execution, and session management.
Features
- Workflow Management: Create, update, and manage workflows with nodes and edges
- Node Types: Support for multiple node types (Chatbot, AI, Conditional, Twilio)
- Execution Tracking: Track workflow executions with status and data
- Session Management: Persistent sessions for multi-step workflows
- Execution Modes: Support for single-run and persistent session workflows
Installation
npm install @venturialstd/workflowEntities
Workflow
Main workflow entity containing:
name: Workflow nameactive: Whether the workflow is activeexecutionMode:singleorpersistentstatus:active,inactive, ordraft- Relationships to nodes, edges, executions, and sessions
WorkflowNode
Represents a node in the workflow:
nodeId: ReactFlow node identifiertype: Node type (chatbot, ai, conditional, twilio)actionType: Specific trigger or action identifierproperties: Node-specific properties (JSONB)position: Node position on canvas (x, y)
WorkflowEdge
Represents connections between nodes:
edgeId: ReactFlow edge identifiersource: Source node IDtarget: Target node IDsourceHandle/targetHandle: Handle identifiers
WorkflowExecution
Tracks individual workflow runs:
status:pending,running,completed,failed,cancelledsessionId: Optional session ID for persistent workflowscurrentNodeId: Current node being executedinputData/outputData/errorData: Execution data
WorkflowSession
Manages persistent workflow sessions:
userId: Optional user identifierexternalId: External identifier (phone, email, etc.)currentNodeId: Current node in sessioncontext: Session context/variables (JSONB)history: Array of node execution history
WorkflowModuleCredential
Stores credentials for workflow modules:
moduleId: Module identifier (e.g., 'twilio', 'ai')name: User-defined name for this credential setcredentials: Encrypted credential values (JSONB)organizationId: Optional organization scopeuserId: Optional user scopeisActive: Whether the credential is active
Services
All services extend TypeOrmCrudService and provide CRUD operations via @dataui/crud.
WorkflowService
getWorkflowsByOrganization(organizationId)getActiveWorkflows(organizationId?)activateWorkflow(workflowId)deactivateWorkflow(workflowId)getWorkflowWithNodesAndEdges(workflowId)
WorkflowNodeService
getNodesByWorkflowId(workflowId)getNodeByNodeId(workflowId, nodeId)updateNodeProperties(id, properties)updateNodePosition(id, position)
WorkflowEdgeService
getEdgesByWorkflowId(workflowId)getEdgeByEdgeId(workflowId, edgeId)getEdgesBySourceNode(workflowId, sourceNodeId)getEdgesByTargetNode(workflowId, targetNodeId)
WorkflowExecutionService
getExecutionsByWorkflowId(workflowId)getExecutionsBySessionId(sessionId)getActiveExecutions(workflowId?)startExecution(executionId)completeExecution(executionId, outputData?)failExecution(executionId, errorMessage, errorData?)updateCurrentNode(executionId, currentNodeId)
WorkflowSessionService
getSessionsByWorkflowId(workflowId)getActiveSessions(workflowId?)getSessionByExternalId(workflowId, externalId)getSessionByUserId(workflowId, userId)updateSessionContext(sessionId, context)addToSessionHistory(sessionId, nodeId, data?)deactivateSession(sessionId)
WorkflowModuleCredentialService
getCredentialsByModule(moduleId, organizationId?, userId?)getCredentialByName(moduleId, name, organizationId?, userId?)getActiveCredentials(moduleId, organizationId?)updateCredential(id, credentials)activateCredential(id)deactivateCredential(id)
Usage
Import the Module
import { WorkflowModule } from '@venturialstd/workflow';
@Module({
imports: [WorkflowModule],
})
export class AppModule {}Use Services
import { WorkflowService } from '@venturialstd/workflow';
@Injectable()
export class MyService {
constructor(private workflowService: WorkflowService) {}
async createWorkflow(data: CreateWorkflowDto) {
return this.workflowService.create(data);
}
}Constants
Execution Modes
EXECUTION_MODE.SINGLE: One-time executionEXECUTION_MODE.PERSISTENT: Maintains session state
Node Types
NODE_TYPE.CHATBOTNODE_TYPE.AINODE_TYPE.CONDITIONALNODE_TYPE.TWILIO
Node Categories
NODE_CATEGORY.TRIGGERNODE_CATEGORY.ACTION
Workflow Status
WORKFLOW_STATUS.ACTIVEWORKFLOW_STATUS.INACTIVEWORKFLOW_STATUS.DRAFT
Execution Status
EXECUTION_STATUS.PENDINGEXECUTION_STATUS.RUNNINGEXECUTION_STATUS.COMPLETEDEXECUTION_STATUS.FAILEDEXECUTION_STATUS.CANCELLED
DTOs
All DTOs follow the Create*Dto pattern:
CreateWorkflowDtoCreateWorkflowNodeDtoCreateWorkflowEdgeDtoCreateWorkflowExecutionDtoCreateWorkflowSessionDtoCreateWorkflowModuleCredentialDtoUpdateWorkflowModuleCredentialDto
Database Schema
The module uses PostgreSQL with JSONB columns for flexible data storage:
- Node properties stored as JSONB
- Edge data stored as JSONB
- Execution input/output/error data as JSONB
- Session context and history as JSONB
- Module credentials stored as JSONB (should be encrypted at application level)
Module Credentials
Each module can define required credential fields. Users can create multiple credential sets per module:
Defining Credential Fields in Modules
Modules can define credentialFields in their module definition:
credentialFields: [
{
id: 'apiKey',
name: 'API Key',
description: 'API key for the service',
type: FIELD_TYPE.STRING,
validation: { required: true },
sensitive: true, // Will be encrypted/masked
required: true,
},
]Managing Credentials
// Create credentials for a module
const credential = await credentialService.create({
moduleId: 'twilio',
name: 'Production Twilio',
credentials: {
accountSid: 'AC...',
authToken: '...',
},
organizationId: 'org-123',
});
// Get all credentials for a module
const credentials = await credentialService.getCredentialsByModule(
'twilio',
'org-123'
);License
Part of the Venturial Core NPM package.
