UNPKG

business-as-code

Version:

Primitives for expressing business logic and processes as code

115 lines 3.33 kB
/** * Workflow definition (automation sequences) */ import type { WorkflowDefinition, WorkflowAction, WorkflowTrigger } from './types.js'; /** * Define an automated workflow with triggers and actions * * @example * ```ts * const workflow = Workflow({ * name: 'New Customer Welcome', * description: 'Automated welcome sequence for new customers', * trigger: { * type: 'event', * event: 'Customer.created', * }, * actions: [ * { * order: 1, * type: 'send', * description: 'Send welcome email', * params: { * template: 'welcome_email', * to: '{{customer.email}}', * }, * }, * { * order: 2, * type: 'create', * description: 'Create onboarding task', * params: { * type: 'Task', * title: 'Onboard {{customer.name}}', * assignee: 'customer_success_team', * }, * }, * { * order: 3, * type: 'wait', * description: 'Wait 24 hours', * params: { * duration: '24 hours', * }, * }, * { * order: 4, * type: 'notify', * description: 'Send setup reminder', * params: { * channel: 'email', * message: 'Reminder to complete setup', * }, * condition: 'customer.setupCompleted === false', * }, * ], * }) * ``` */ export declare function Workflow(definition: WorkflowDefinition): WorkflowDefinition; /** * Get actions in execution order */ export declare function getActionsInOrder(workflow: WorkflowDefinition): WorkflowAction[]; /** * Get actions by type */ export declare function getActionsByType(workflow: WorkflowDefinition, type: WorkflowAction['type']): WorkflowAction[]; /** * Get conditional actions */ export declare function getConditionalActions(workflow: WorkflowDefinition): WorkflowAction[]; /** * Add action to workflow */ export declare function addAction(workflow: WorkflowDefinition, action: WorkflowAction): WorkflowDefinition; /** * Remove action from workflow */ export declare function removeAction(workflow: WorkflowDefinition, order: number): WorkflowDefinition; /** * Update action in workflow */ export declare function updateAction(workflow: WorkflowDefinition, order: number, updates: Partial<WorkflowAction>): WorkflowDefinition; /** * Check if trigger is event-based */ export declare function isEventTrigger(trigger: WorkflowTrigger): boolean; /** * Check if trigger is schedule-based */ export declare function isScheduleTrigger(trigger: WorkflowTrigger): boolean; /** * Check if trigger is webhook-based */ export declare function isWebhookTrigger(trigger: WorkflowTrigger): boolean; /** * Parse wait duration to milliseconds */ export declare function parseWaitDuration(duration: string): number; /** * Evaluate condition (simple implementation) */ export declare function evaluateCondition(condition: string, context: Record<string, unknown>): boolean; /** * Fill template with context values */ export declare function fillTemplate(template: string, context: Record<string, unknown>): string; /** * Validate workflow definition */ export declare function validateWorkflow(workflow: WorkflowDefinition): { valid: boolean; errors: string[]; }; //# sourceMappingURL=workflow.d.ts.map