Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import type {
WorkflowTriggerType,
WorkflowStepType,
WorkflowExecutionStatus,
WorkflowStepStatus } from "@prisma/client";
// Re-export Prisma enums
export {
WorkflowTriggerType,
WorkflowStepType,
WorkflowExecutionStatus,
WorkflowStepStatus};
// Workflow step configuration
export interface WorkflowStepConfig {
id: string;
type: WorkflowStepType;
name: string;
config: WorkflowStepData;
position: { x: number; y: number };
connections: string[]; // IDs of next steps
}
// Different step type configurations
export type WorkflowStepData =
| SendEmailStepConfig
| WaitDelayStepConfig
| WaitUntilStepConfig
| ConditionStepConfig
| SplitABStepConfig
| UpdateSegmentStepConfig
| AddPointsStepConfig
| ApplyCouponStepConfig
| WebhookStepConfig
| EndStepConfig
| SendSmsStepConfig
| SendPushStepConfig;
export interface SendEmailStepConfig {
type: "SEND_EMAIL";
templateId?: number;
subject?: string;
body?: string;
variables?: Record<string, string>;
}
export interface SendSmsStepConfig {
type: "SEND_SMS";
message: string;
variables?: Record<string, string>;
}
export interface SendPushStepConfig {
type: "SEND_PUSH";
title: string;
body: string;
url?: string;
}
export interface WaitDelayStepConfig {
type: "WAIT_DELAY";
duration: number; // in seconds
unit: "seconds" | "minutes" | "hours" | "days";
}
export interface WaitUntilStepConfig {
type: "WAIT_UNTIL";
time: string; // ISO time string or cron expression
timezone?: string;
}
export interface ConditionStepConfig {
type: "CONDITION";
conditions: ConditionGroup[];
trueConnectionId?: string;
falseConnectionId?: string;
}
export interface ConditionGroup {
logic: "AND" | "OR";
rules: ConditionRule[];
}
export interface ConditionRule {
field: string;
operator: ConditionOperator;
value: string | number | boolean;
}
export type ConditionOperator =
| "equals"
| "not_equals"
| "greater_than"
| "less_than"
| "contains"
| "not_contains"
| "is_empty"
| "is_not_empty"
| "in"
| "not_in";
export interface SplitABStepConfig {
type: "SPLIT_AB";
variants: ABVariant[];
}
export interface ABVariant {
id: string;
name: string;
percentage: number;
connectionId?: string;
}
export interface UpdateSegmentStepConfig {
type: "UPDATE_SEGMENT";
action: "add" | "remove";
segmentId: number;
}
export interface AddPointsStepConfig {
type: "ADD_POINTS";
points: number;
reason?: string;
}
export interface ApplyCouponStepConfig {
type: "APPLY_COUPON";
couponCode?: string; // Specific code or generate new
discountType: "percentage" | "fixed";
discountValue: number;
expiresIn?: number; // days
}
export interface WebhookStepConfig {
type: "WEBHOOK";
url: string;
method: "GET" | "POST" | "PUT" | "DELETE";
headers?: Record<string, string>;
body?: Record<string, unknown>;
}
export interface EndStepConfig {
type: "END";
status: "completed" | "cancelled";
}
// Trigger configurations
export interface TriggerConfig {
type: WorkflowTriggerType;
config: TriggerConfigData;
}
export type TriggerConfigData =
| CartAbandonedTriggerConfig
| InactiveDaysTriggerConfig
| ScheduledTriggerConfig
| SegmentTriggerConfig
| DefaultTriggerConfig;
export interface CartAbandonedTriggerConfig {
delayMinutes: number; // How long after abandonment to trigger
}
export interface InactiveDaysTriggerConfig {
days: number; // Days of inactivity
}
export interface ScheduledTriggerConfig {
schedule: string; // Cron expression
timezone?: string;
}
export interface SegmentTriggerConfig {
segmentId: number;
}
// Type for triggers that don't need configuration
export type DefaultTriggerConfig = Record<string, never>;
// Workflow definition stored in JSON
export interface WorkflowDefinition {
version: number;
trigger: TriggerConfig;
steps: WorkflowStepConfig[];
startStepId: string;
}
// Execution context passed through workflow
export interface WorkflowExecutionContext {
userId: number;
executionId: number;
workflowId: number;
triggerData: Record<string, unknown>;
stepData: Record<string, unknown>;
variables: Record<string, unknown>;
}
// Result from step execution
export interface StepExecutionResult {
success: boolean;
data?: Record<string, unknown>;
nextStepId?: string;
error?: string;
shouldWait?: boolean;
waitUntil?: Date;
}
// Available template variables for personalization
export interface TemplateVariables {
user: {
id: number;
name: string;
email: string;
firstName?: string;
lastName?: string;
};
order?: {
id: number;
total: number;
items: Array<{ name: string; quantity: number; price: number }>;
};
cart?: {
itemCount: number;
total: number;
items: Array<{ name: string; quantity: number; price: number }>;
};
product?: {
id: number;
name: string;
price: number;
imageUrl?: string;
};
loyalty?: {
points: number;
tier: string;
};
coupon?: {
code: string;
discount: string;
expiresAt?: string;
};
custom: Record<string, unknown>;
}
// Workflow statistics
export interface WorkflowStats {
totalExecutions: number;
completedExecutions: number;
failedExecutions: number;
activeExecutions: number;
averageCompletionTime: number; // in seconds
conversionRate: number; // percentage
lastExecutedAt?: Date;
}
|