-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathworkflow-service.ts
More file actions
87 lines (80 loc) · 2.45 KB
/
Copy pathworkflow-service.ts
File metadata and controls
87 lines (80 loc) · 2.45 KB
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
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* IWorkflowService - Workflow State Machine Service Contract
*
* Defines the interface for workflow state management and approval processes
* in ObjectStack. Concrete implementations (state machine engines, BPMN, etc.)
* should implement this interface.
*
* Follows Dependency Inversion Principle - plugins depend on this interface,
* not on concrete workflow engine implementations.
*
* Aligned with CoreServiceName 'workflow' in core-services.zod.ts.
*/
/**
* A state transition request
*/
export interface WorkflowTransition {
/** Record identifier */
recordId: string;
/** Object name the record belongs to */
object: string;
/** Target state to transition to */
targetState: string;
/** Optional comment for the transition */
comment?: string;
/** User performing the transition */
userId?: string;
}
/**
* Result of a transition attempt
*/
export interface WorkflowTransitionResult {
/** Whether the transition succeeded */
success: boolean;
/** The new current state (if success) */
currentState?: string;
/** Error or rejection reason (if failure) */
error?: string;
}
/**
* Status of a workflow instance
*/
export interface WorkflowStatus {
/** Record identifier */
recordId: string;
/** Object name */
object: string;
/** Current state */
currentState: string;
/** Available transitions from the current state */
availableTransitions: string[];
}
export interface IWorkflowService {
/**
* Transition a record to a new workflow state
* @param transition - Transition request details
* @returns Transition result
*/
transition(transition: WorkflowTransition): Promise<WorkflowTransitionResult>;
/**
* Get the current workflow status of a record
* @param object - Object name
* @param recordId - Record identifier
* @returns Current workflow status with available transitions
*/
getStatus(object: string, recordId: string): Promise<WorkflowStatus>;
/**
* Get transition history for a record
* @param object - Object name
* @param recordId - Record identifier
* @returns Array of historical transitions
*/
getHistory?(object: string, recordId: string): Promise<Array<{
fromState: string;
toState: string;
userId?: string;
comment?: string;
timestamp: string;
}>>;
}