gbflowengine 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +271 -271
  2. package/dist/gbflowengine.css +1 -1
  3. package/dist/gbflowengine.js +8232 -6913
  4. package/dist/gbflowengine.js.map +1 -1
  5. package/dist/gbflowengine.umd.cjs +2 -2
  6. package/dist/gbflowengine.umd.cjs.map +1 -1
  7. package/package.json +85 -84
  8. package/src/center/DefinitionInspect.vue +291 -291
  9. package/src/center/FlowCenter.vue +33 -33
  10. package/src/center/index.js +29 -29
  11. package/src/center/storage.js +748 -748
  12. package/src/core/flow/condition.js +160 -160
  13. package/src/core/flow/customNode.js +385 -385
  14. package/src/core/flow/defaults.js +124 -124
  15. package/src/core/flow/flowConstant.js +265 -265
  16. package/src/core/flow/flowNodeUtils.js +29 -29
  17. package/src/core/flow/index.js +47 -47
  18. package/src/core/flow/node.js +44 -44
  19. package/src/core/flow/nodeFactory.js +58 -58
  20. package/src/core/flow/prediction.js +325 -325
  21. package/src/core/flow/schema.js +864 -864
  22. package/src/definition/FlowDefinitionDesigner.vue +338 -338
  23. package/src/definition/index.js +9 -9
  24. package/src/index.js +39 -39
  25. package/src/storage.js +200 -200
  26. package/src/testing/FlowTestPanel.vue +2502 -2502
  27. package/src/testing/UserConfigDrawer.vue +376 -376
  28. package/src/testing/diagram/FlowProgressDiagram.vue +318 -318
  29. package/src/testing/diagramModel.js +517 -517
  30. package/src/testing/index.js +23 -23
  31. package/src/testing/mock.js +246 -246
  32. package/src/testing/oaExecutors.js +51 -51
  33. package/src/testing/oaSeed.js +467 -467
  34. package/src/testing/sample.js +412 -412
  35. package/src/testing/seed.js +122 -122
  36. package/src/utils/format.js +27 -27
  37. package/src/visual/FlowCanvas.vue +440 -440
  38. package/src/visual/NodeProgressDetail.vue +43 -43
  39. package/src/visual/NodeStatusBadge.vue +17 -17
  40. package/src/visual/NodeWrap.vue +46 -46
  41. package/src/visual/ScWorkflow.vue +49 -49
  42. package/src/visual/SelectDialog.vue +459 -459
  43. package/src/visual/conditionHelpers.js +116 -116
  44. package/src/visual/index.js +6 -6
  45. package/src/visual/nodes/AddNode.vue +222 -222
  46. package/src/visual/nodes/ApproverNode.vue +347 -347
  47. package/src/visual/nodes/BranchNode.vue +441 -441
  48. package/src/visual/nodes/CustomNode.vue +339 -339
  49. package/src/visual/nodes/EndNode.vue +21 -21
  50. package/src/visual/nodes/PassNode.vue +100 -100
  51. package/src/visual/nodes/PromoterNode.vue +134 -134
  52. package/src/visual/nodes/RejectNode.vue +100 -100
  53. package/src/visual/nodes/SendNode.vue +151 -151
  54. package/src/visual/styles.scss +879 -879
  55. package/src/visual/useScNodeStatus.js +18 -18
  56. package/src/workbench/OaWorkbench.vue +1341 -1341
  57. package/src/workbench/components/ApprovalWorkspace.vue +2090 -2090
  58. package/src/workbench/components/CategoryIcon.vue +74 -74
  59. package/src/workbench/components/NotificationIcon.vue +73 -73
  60. package/src/workbench/components/ProcessSteps.vue +557 -557
  61. package/src/workbench/components/ResubmitDialog.vue +227 -227
  62. package/src/workbench/components/SidebarNav.vue +138 -138
  63. package/src/workbench/components/StartFlowDialog.vue +1058 -1058
  64. package/src/workbench/components/UserAvatar.vue +68 -68
  65. package/src/workbench/model.js +1080 -1080
  66. package/src/workbench/pages/DesignPage.vue +798 -798
  67. package/src/workbench/pages/HomePage.vue +1050 -1050
  68. package/src/workbench/pages/MonitorPage.vue +1029 -1029
  69. package/src/workbench/pages/NotificationsPage.vue +554 -554
  70. package/src/workbench/pages/RequestsPage.vue +644 -644
  71. package/src/workbench/pages/TaskCenterPage.vue +1155 -1155
  72. package/src/workbench/pages/TemplatesPage.vue +680 -680
  73. package/src/workbench/styles.scss +555 -555
  74. package/types/center.d.ts +5 -5
  75. package/types/core.d.ts +479 -479
  76. package/types/definition.d.ts +4 -4
  77. package/types/index.d.ts +34 -34
  78. package/types/testing.d.ts +20 -20
  79. package/types/visual.d.ts +20 -20
package/types/core.d.ts CHANGED
@@ -1,479 +1,479 @@
1
- export type NodeId = string | number
2
- export type FlowNodeTypeValue =
3
- | 'start'
4
- | 'approve'
5
- | 'cc'
6
- | 'custom'
7
- | 'branch'
8
- | 'condition'
9
- | 'parallel'
10
- | 'parallel_branch'
11
- | 'inclusive'
12
- | 'inclusive_branch'
13
- | 'pass'
14
- | 'reject'
15
- | 'end'
16
-
17
- export interface FlowCondition {
18
- variable: string
19
- variableName?: string
20
- operator: string
21
- value?: unknown
22
- logic?: 'AND' | 'OR'
23
- fieldType?: string
24
- }
25
-
26
- export interface CustomNodeConfig {
27
- executorType?: 'http' | 'method'
28
- url?: string
29
- method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | string
30
- headers?: Array<{ key: string; value: string }>
31
- body?: string
32
- timeoutMs?: number
33
- methodKey?: string
34
- resultVariable?: string
35
- onError?: 'terminate' | 'continue'
36
- [key: string]: unknown
37
- }
38
-
39
- export interface FlowNode {
40
- nodeId: NodeId
41
- nodeName: string
42
- type: FlowNodeTypeValue | string
43
- childNode?: FlowNode | null
44
- branchList?: FlowNode[]
45
- conditions?: FlowCondition[]
46
- isDefaultCondition?: boolean
47
- isDefaultBranch?: boolean
48
- branchIndex?: number
49
- approverType?: 'user' | 'role' | 'superior_leader' | string
50
- userList?: Array<NodeId | Record<string, unknown>>
51
- roleList?: NodeId[]
52
- userNickNames?: Record<string, string>
53
- deptNameMap?: Record<string, string>
54
- roleNameMap?: Record<string, string>
55
- signMode?: 'and' | 'or'
56
- superiorLevel?: number
57
- allowTransfer?: boolean
58
- allowInitiatorAddUsers?: boolean
59
- rejectStrategy?: 'terminate' | 'to_previous' | 'to_initiator' | 'to_specified' | string
60
- rejectTargetNodeId?: NodeId | null
61
- rejectRetryLimit?: number
62
- termAuto?: boolean
63
- term?: number
64
- termMode?: 0 | 1 | number
65
- custom?: CustomNodeConfig
66
- [key: string]: unknown
67
- }
68
-
69
- export interface FlowForm {
70
- components: Array<Record<string, unknown>>
71
- options: Record<string, unknown>
72
- }
73
-
74
- export interface FlowDefinitionMeta {
75
- id: string
76
- name: string
77
- description?: string
78
- tags?: string[]
79
- groupId?: string | null
80
- status?: 'draft' | 'published' | 'disabled'
81
- version?: number
82
- publishedAt?: string
83
- createdAt?: string
84
- updatedAt?: string
85
- revisions?: DefinitionRevision[]
86
- [key: string]: unknown
87
- }
88
-
89
- export interface DefinitionRevision {
90
- version: number
91
- publishedAt: string
92
- name: string
93
- description?: string
94
- tags?: string[]
95
- workflow: FlowNode
96
- form: FlowForm
97
- }
98
-
99
- export interface FlowDefinition {
100
- schemaVersion: string
101
- kind: string
102
- meta: FlowDefinitionMeta
103
- workflow: FlowNode
104
- form: FlowForm
105
- }
106
-
107
- export interface ApprovalRecord {
108
- action: string
109
- approver: { id: NodeId; name: string; [key: string]: unknown }
110
- comment?: string
111
- at: string
112
- system?: boolean
113
- limitReached?: boolean
114
- }
115
-
116
- export interface FlowTask {
117
- id: string
118
- nodeId: NodeId
119
- nodeName: string
120
- tokenId: string
121
- kind?: 'approve' | 'submit' | 'custom'
122
- signMode: 'and' | 'or' | null
123
- approvers: Array<Record<string, any>>
124
- approvedBy: Array<Record<string, any>>
125
- records: ApprovalRecord[]
126
- status: 'pending' | 'approved' | 'rejected' | 'completed' | 'failed' | 'cancelled' | string
127
- cycle: number
128
- createdAt: string
129
- finishedAt?: string
130
- dueAt?: string
131
- termMode?: 0 | 1
132
- autoApproved?: boolean
133
- custom?: CustomNodeConfig
134
- attempts?: number
135
- result?: unknown
136
- lastError?: string
137
- [key: string]: unknown
138
- }
139
-
140
- export interface FlowEvent {
141
- id: string
142
- event: string
143
- at: string
144
- cycle: number
145
- [key: string]: unknown
146
- }
147
-
148
- export interface FlowToken {
149
- id: string
150
- nodeId: NodeId | null
151
- continuations: NodeId[]
152
- joins: Array<{
153
- groupId: string
154
- targetId: NodeId | null
155
- expected: number
156
- createdBy?: NodeId
157
- continuations?: NodeId[]
158
- }>
159
- blockedTaskId: string | null
160
- blockedJoinGroup: string | null
161
- }
162
-
163
- export interface RuntimeState {
164
- status: 'idle' | 'running' | 'completed' | 'rejected' | 'cancelled' | 'revoked'
165
- initiator: Record<string, any> | null
166
- tokens: FlowToken[]
167
- tasks: FlowTask[]
168
- ccRecords: Array<Record<string, any>>
169
- history: FlowEvent[]
170
- variables: Record<string, any>
171
- warnings: Array<{ code: string; message: string; at: string }>
172
- startedAt: string | null
173
- endedAt: string | null
174
- cycle: number
175
- currentNodeIds?: NodeId[]
176
- pendingTaskCount?: number
177
- [key: string]: unknown
178
- }
179
-
180
- export interface RuntimeContext {
181
- initiator?: Record<string, any>
182
- initiatorId?: NodeId
183
- resolveApprovers?: (
184
- node: FlowNode,
185
- variables: Record<string, any>,
186
- context: RuntimeContext
187
- ) => Array<Record<string, any>> | null | undefined
188
- resolveRoleUsers?: (roleIds: NodeId[], node: FlowNode) => Array<Record<string, any>>
189
- getSuperiorLeader?: (level: number, node: FlowNode) => Array<Record<string, any>> | Record<string, any> | null
190
- resolveUser?: (userId: NodeId) => Record<string, any> | null
191
- resolveExtraCcUsers?: (
192
- node: FlowNode,
193
- variables: Record<string, any>,
194
- context: RuntimeContext
195
- ) => Array<Record<string, any>>
196
- [key: string]: any
197
- }
198
-
199
- export type RuntimeHandlers = Partial<
200
- Record<
201
- | 'onStart'
202
- | 'onTaskCreated'
203
- | 'onTaskUpdated'
204
- | 'onTaskApproved'
205
- | 'onTaskTransferred'
206
- | 'onCustomTaskCompleted'
207
- | 'onCustomTaskFailed'
208
- | 'onNodeEnter'
209
- | 'onNodeLeave'
210
- | 'onCc'
211
- | 'onJoin'
212
- | 'onReturned'
213
- | 'onResubmitted'
214
- | 'onFinished'
215
- | 'onWarning',
216
- (payload: any) => void
217
- >
218
- >
219
-
220
- export interface FlowRuntimeOptions {
221
- workflow: FlowNode
222
- data?: Record<string, any>
223
- context?: RuntimeContext
224
- state?: RuntimeState | null
225
- handlers?: RuntimeHandlers | null
226
- }
227
-
228
- export class FlowRuntime {
229
- constructor(options: FlowRuntimeOptions)
230
- static restore(options: FlowRuntimeOptions): FlowRuntime
231
- workflow: FlowNode
232
- context: RuntimeContext
233
- handlers: RuntimeHandlers
234
- state: RuntimeState
235
- getNode(nodeId: NodeId): FlowNode | null
236
- getState(): RuntimeState
237
- getPendingTasks(): FlowTask[]
238
- getPendingTasksForUser(userId: NodeId): FlowTask[]
239
- getPendingCustomTasks(): FlowTask[]
240
- getCcRecordsForUser(userId: NodeId): Array<Record<string, any>>
241
- getRejectInfo(nodeId: NodeId): Record<string, any>
242
- setVariables(patch: Record<string, any>): Record<string, any>
243
- resolveApprovers(node: FlowNode): Array<Record<string, any>>
244
- resolveCcUsers(node: FlowNode): Array<Record<string, any>>
245
- start(initialData?: Record<string, any> | null, initiator?: Record<string, any> | null): RuntimeState
246
- approve(taskId: string, payload?: Record<string, any>): RuntimeState
247
- reject(taskId: string, payload?: Record<string, any>): RuntimeState
248
- transfer(taskId: string, payload?: Record<string, any>): RuntimeState
249
- resubmit(taskId: string, payload?: Record<string, any>): RuntimeState
250
- completeCustomTask(taskId: string, payload?: Record<string, any>): RuntimeState
251
- revoke(payload?: Record<string, any>): RuntimeState
252
- cancel(reason?: string): RuntimeState
253
- tick(now?: number | Date): RuntimeState
254
- }
255
-
256
- export function createFlowRuntime(options: FlowRuntimeOptions): FlowRuntime
257
- export function evaluateBranches(workflow: FlowNode, data?: Record<string, any>): Array<Record<string, any>>
258
-
259
- export interface PredictionNode {
260
- id: string
261
- nodeId: NodeId
262
- nodeName: string
263
- type: string
264
- typeLabel?: string
265
- kind: string
266
- depth: number
267
- path: string[]
268
- group?: Record<string, any> | null
269
- approvers?: Array<Record<string, any>>
270
- ccUsers?: Array<Record<string, any>>
271
- signMode?: string
272
- signModeLabel?: string
273
- note?: string
274
- [key: string]: unknown
275
- }
276
-
277
- export interface PredictionResult {
278
- rootNodeId: NodeId
279
- definitionName: string | null
280
- initiator: Record<string, any> | null
281
- status: 'completed' | 'rejected' | string
282
- nodeCount: number
283
- approvalNodeCount: number
284
- approvalTaskCount: number
285
- ccNodeCount: number
286
- ccUserCount: number
287
- branchCount: number
288
- decisions: Array<Record<string, any>>
289
- warnings: Array<{ code: string; message: string; nodeId?: NodeId | null; nodeName?: string }>
290
- nodes: PredictionNode[]
291
- }
292
-
293
- export function predictWorkflow(options: {
294
- definition?: FlowDefinition | null
295
- workflow?: FlowNode | null
296
- data?: Record<string, any>
297
- context?: RuntimeContext
298
- initiator?: Record<string, any> | null
299
- }): PredictionResult
300
- export function predictFlow(
301
- workflow: FlowNode,
302
- data?: Record<string, any>,
303
- context?: RuntimeContext,
304
- initiator?: Record<string, any> | null
305
- ): PredictionResult
306
-
307
- export const MAX_PREDICTION_NODES: number
308
- export const MAX_NODE_COUNT: number
309
- export const SCHEMA_VERSION: string
310
- export const SCHEMA_KIND: string
311
- export const WORKFLOW_KIND: string
312
- export const FORM_KIND: string
313
-
314
- export const FlowNodeType: {
315
- readonly START: 'start'
316
- readonly APPROVE: 'approve'
317
- readonly CC: 'cc'
318
- readonly BRANCH: 'branch'
319
- readonly CONDITION: 'condition'
320
- readonly PARALLEL: 'parallel'
321
- readonly PARALLEL_BRANCH: 'parallel_branch'
322
- readonly INCLUSIVE: 'inclusive'
323
- readonly INCLUSIVE_BRANCH: 'inclusive_branch'
324
- readonly PASS: 'pass'
325
- readonly REJECT: 'reject'
326
- readonly END: 'end'
327
- }
328
- export const NodeTypeLabel: Record<string, string>
329
- export const ApproverType: Record<string, string>
330
- export const ApproverTypeLabel: Record<string, string>
331
- export const ApproverTypeOptions: Array<{ value: string; label: string }>
332
- export const SignMode: Record<string, string>
333
- export const SignModeLabel: Record<string, string>
334
- export const RejectStrategy: Record<string, string>
335
- export const RejectStrategyLabel: Record<string, string>
336
- export const TaskAction: Record<string, string>
337
- export const TaskStatus: Record<string, string>
338
- export const FlowInstanceStatus: Record<string, string>
339
- export const FlowEventType: Record<string, string>
340
- export const BusinessType: Record<string, string>
341
-
342
- export function normalizeWorkflow(
343
- workflow: FlowNode,
344
- options?: { ensureEnd?: boolean }
345
- ): { workflow: FlowNode; repairs: string[] }
346
- export function createDefinition(input?: {
347
- workflow?: FlowNode | null
348
- form?: Array<Record<string, any>> | FlowForm | null
349
- meta?: Partial<FlowDefinitionMeta>
350
- }): FlowDefinition
351
- export function normalizeDefinition(input: FlowDefinition | Record<string, any> | string, options?: Record<string, any>): FlowDefinition
352
- export function importDefinition(input: string | Record<string, any> | Array<Record<string, any>>): {
353
- document: FlowDefinition
354
- repairs: string[]
355
- validation: ValidationResult
356
- }
357
- export function exportDefinition(input: FlowDefinition | Record<string, any>, options?: { raw?: boolean; space?: number; updateTimestamp?: boolean }): string | FlowDefinition
358
- export function exportWorkflow(workflow: FlowNode, meta?: Partial<FlowDefinitionMeta>, options?: { raw?: boolean; space?: number }): string | Record<string, any>
359
-
360
- export interface ValidationIssue {
361
- code: string
362
- message: string
363
- nodeId?: NodeId
364
- componentId?: string
365
- [key: string]: unknown
366
- }
367
-
368
- export interface ValidationResult {
369
- valid: boolean
370
- errors: ValidationIssue[]
371
- warnings: ValidationIssue[]
372
- nodeCount?: number
373
- }
374
-
375
- export function validateWorkflow(workflow: FlowNode, options?: { strict?: boolean; formVariables?: any[] }): ValidationResult
376
- export function validateDefinition(definition: FlowDefinition, options?: { strict?: boolean }): ValidationResult
377
-
378
- export function evaluateCondition(condition: FlowCondition, data?: Record<string, any>): boolean
379
- export function evaluateConditionGroup(conditions: FlowCondition[], data?: Record<string, any>): boolean
380
- export function getVariableValue(data: Record<string, any>, variable: string): unknown
381
- export function selectBranchNode(branchNode: FlowNode, data?: Record<string, any>): FlowNode | null
382
- export function selectInclusiveBranches(branchNode: FlowNode, data?: Record<string, any>): FlowNode[]
383
- export function isEmptyValue(value: unknown): boolean
384
- export function normalizeComparable(value: unknown): string
385
-
386
- export function isStructuralNode(node: FlowNode | null): boolean
387
- export function isTerminalNode(node: FlowNode | null): boolean
388
- export function isBranchNode(node: FlowNode | null): boolean
389
- export function getNodeTypeLabel(type: string): string
390
- export function createNodeDefaults(type: string): Record<string, unknown>
391
-
392
- export function findNodeById(node: FlowNode | null, targetId: NodeId): FlowNode | null
393
- export function hasEndNode(node: FlowNode | null): boolean
394
- export function ensureEndNode(rootNode: FlowNode): FlowNode
395
- export function createNewNode(type: string, name?: string): FlowNode
396
- export function createEndNode(): FlowNode
397
- export function generateNodeId(): number
398
- export function traverseNodes(root: FlowNode | null, visitor: (node: FlowNode) => void): void
399
- export function getAllNodes(root: FlowNode | null): FlowNode[]
400
- export function countNodes(root: FlowNode | null): number
401
- export function getNodeStatistics(root: FlowNode | null): Record<string, number>
402
-
403
- export const CUSTOM_EXECUTOR_TYPE: { HTTP: 'http'; METHOD: 'method' }
404
- export const CUSTOM_ERROR_POLICY: { TERMINATE: 'terminate'; CONTINUE: 'continue' }
405
- export const CUSTOM_HTTP_METHODS: string[]
406
- export const CUSTOM_TIMEOUT_DEFAULT: number
407
- export const CUSTOM_TIMEOUT_MIN: number
408
- export const CUSTOM_TIMEOUT_MAX: number
409
- export const CUSTOM_RESULT_LIMIT: number
410
-
411
- export function createCustomNodeConfig(overrides?: CustomNodeConfig): CustomNodeConfig
412
- export function normalizeCustomNodeConfig(input?: CustomNodeConfig | null): CustomNodeConfig
413
- export function validateCustomNodeConfig(input?: CustomNodeConfig | null): {
414
- errors: ValidationIssue[]
415
- warnings: ValidationIssue[]
416
- config: CustomNodeConfig
417
- }
418
- export function customNodeSummary(input?: CustomNodeConfig | null): string
419
- export function isValidCustomResultVariable(value: unknown): boolean
420
- export function interpolateCustomTemplate(template: unknown, variables?: Record<string, any>): any
421
- export function resolveCustomRequest(input: CustomNodeConfig, variables?: Record<string, any>): {
422
- url: string
423
- method: string
424
- headers: Record<string, string>
425
- body?: string
426
- timeoutMs: number
427
- }
428
- export function executeCustomNode(
429
- input: CustomNodeConfig,
430
- options?: {
431
- variables?: Record<string, any>
432
- executors?: Record<string, (context: Record<string, any>) => unknown>
433
- fetchImpl?: (...args: any[]) => Promise<any>
434
- signal?: any
435
- node?: FlowNode | null
436
- instance?: Record<string, any> | null
437
- }
438
- ): Promise<any>
439
-
440
- export const RUNTIME_RUNNING: 'running'
441
- export const RUNTIME_COMPLETED: 'completed'
442
- export const RUNTIME_REJECTED: 'rejected'
443
- export const RUNTIME_CANCELLED: 'cancelled'
444
- export const RUNTIME_REVOKED: 'revoked'
445
- export const RUNTIME_IDLE: 'idle'
446
-
447
- // Re-exported headless form helpers.
448
- export interface FormVariable {
449
- variableName: string
450
- label: string
451
- dataType: string
452
- componentType: string
453
- metadata: Record<string, any>
454
- getOptions(): Array<Record<string, any>>
455
- getDateFormat?(): string
456
- [key: string]: any
457
- }
458
- export const ConditionOperator: Record<string, string>
459
- export const OPERATOR_LABEL_MAP: Record<string, string>
460
- export function computeDataType(component: Record<string, any>): string
461
- export function enrichFormVariables(components: Array<Record<string, any>>): FormVariable[]
462
- export function findFormVariable(formVariables: FormVariable[], variableName: string): FormVariable | null
463
- export function normalizeForm(form: unknown): { components: Array<Record<string, any>>; options: Record<string, any>; repairs: string[] }
464
- export function validateForm(form: unknown): { valid: boolean; errors: ValidationIssue[]; warnings: ValidationIssue[] }
465
- export function importForm(input: unknown): { form: FlowForm; repairs: string[] }
466
- export function exportForm(input: unknown, meta?: Record<string, any>, options?: Record<string, any>): string | Record<string, any>
467
- export function downloadJSON(data: unknown, fileName?: string, space?: number): void
468
- export function downloadText(content: string, fileName: string, mime?: string): void
469
- export function readTextFile(file: File): Promise<string>
470
- export function pickJSONFile(): Promise<{ file: File; text: string } | null>
471
- export function sanitizeFileName(name: string, fallback?: string): string
472
- export const COMPONENT_TYPES: Record<string, string>
473
- export const COMPONENT_TYPE_LABELS: Record<string, string>
474
- export const OPTION_COMPONENT_TYPES: string[]
475
- export function generateComponentId(): string
476
- export function ensureComponentId(component: Record<string, any>): Record<string, any>
477
- export function getFieldName(component: Record<string, any>): string
478
- export const BaseDataType: Record<string, string>
479
- export const ComponentType: Record<string, string>
1
+ export type NodeId = string | number
2
+ export type FlowNodeTypeValue =
3
+ | 'start'
4
+ | 'approve'
5
+ | 'cc'
6
+ | 'custom'
7
+ | 'branch'
8
+ | 'condition'
9
+ | 'parallel'
10
+ | 'parallel_branch'
11
+ | 'inclusive'
12
+ | 'inclusive_branch'
13
+ | 'pass'
14
+ | 'reject'
15
+ | 'end'
16
+
17
+ export interface FlowCondition {
18
+ variable: string
19
+ variableName?: string
20
+ operator: string
21
+ value?: unknown
22
+ logic?: 'AND' | 'OR'
23
+ fieldType?: string
24
+ }
25
+
26
+ export interface CustomNodeConfig {
27
+ executorType?: 'http' | 'method'
28
+ url?: string
29
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | string
30
+ headers?: Array<{ key: string; value: string }>
31
+ body?: string
32
+ timeoutMs?: number
33
+ methodKey?: string
34
+ resultVariable?: string
35
+ onError?: 'terminate' | 'continue'
36
+ [key: string]: unknown
37
+ }
38
+
39
+ export interface FlowNode {
40
+ nodeId: NodeId
41
+ nodeName: string
42
+ type: FlowNodeTypeValue | string
43
+ childNode?: FlowNode | null
44
+ branchList?: FlowNode[]
45
+ conditions?: FlowCondition[]
46
+ isDefaultCondition?: boolean
47
+ isDefaultBranch?: boolean
48
+ branchIndex?: number
49
+ approverType?: 'user' | 'role' | 'superior_leader' | string
50
+ userList?: Array<NodeId | Record<string, unknown>>
51
+ roleList?: NodeId[]
52
+ userNickNames?: Record<string, string>
53
+ deptNameMap?: Record<string, string>
54
+ roleNameMap?: Record<string, string>
55
+ signMode?: 'and' | 'or'
56
+ superiorLevel?: number
57
+ allowTransfer?: boolean
58
+ allowInitiatorAddUsers?: boolean
59
+ rejectStrategy?: 'terminate' | 'to_previous' | 'to_initiator' | 'to_specified' | string
60
+ rejectTargetNodeId?: NodeId | null
61
+ rejectRetryLimit?: number
62
+ termAuto?: boolean
63
+ term?: number
64
+ termMode?: 0 | 1 | number
65
+ custom?: CustomNodeConfig
66
+ [key: string]: unknown
67
+ }
68
+
69
+ export interface FlowForm {
70
+ components: Array<Record<string, unknown>>
71
+ options: Record<string, unknown>
72
+ }
73
+
74
+ export interface FlowDefinitionMeta {
75
+ id: string
76
+ name: string
77
+ description?: string
78
+ tags?: string[]
79
+ groupId?: string | null
80
+ status?: 'draft' | 'published' | 'disabled'
81
+ version?: number
82
+ publishedAt?: string
83
+ createdAt?: string
84
+ updatedAt?: string
85
+ revisions?: DefinitionRevision[]
86
+ [key: string]: unknown
87
+ }
88
+
89
+ export interface DefinitionRevision {
90
+ version: number
91
+ publishedAt: string
92
+ name: string
93
+ description?: string
94
+ tags?: string[]
95
+ workflow: FlowNode
96
+ form: FlowForm
97
+ }
98
+
99
+ export interface FlowDefinition {
100
+ schemaVersion: string
101
+ kind: string
102
+ meta: FlowDefinitionMeta
103
+ workflow: FlowNode
104
+ form: FlowForm
105
+ }
106
+
107
+ export interface ApprovalRecord {
108
+ action: string
109
+ approver: { id: NodeId; name: string; [key: string]: unknown }
110
+ comment?: string
111
+ at: string
112
+ system?: boolean
113
+ limitReached?: boolean
114
+ }
115
+
116
+ export interface FlowTask {
117
+ id: string
118
+ nodeId: NodeId
119
+ nodeName: string
120
+ tokenId: string
121
+ kind?: 'approve' | 'submit' | 'custom'
122
+ signMode: 'and' | 'or' | null
123
+ approvers: Array<Record<string, any>>
124
+ approvedBy: Array<Record<string, any>>
125
+ records: ApprovalRecord[]
126
+ status: 'pending' | 'approved' | 'rejected' | 'completed' | 'failed' | 'cancelled' | string
127
+ cycle: number
128
+ createdAt: string
129
+ finishedAt?: string
130
+ dueAt?: string
131
+ termMode?: 0 | 1
132
+ autoApproved?: boolean
133
+ custom?: CustomNodeConfig
134
+ attempts?: number
135
+ result?: unknown
136
+ lastError?: string
137
+ [key: string]: unknown
138
+ }
139
+
140
+ export interface FlowEvent {
141
+ id: string
142
+ event: string
143
+ at: string
144
+ cycle: number
145
+ [key: string]: unknown
146
+ }
147
+
148
+ export interface FlowToken {
149
+ id: string
150
+ nodeId: NodeId | null
151
+ continuations: NodeId[]
152
+ joins: Array<{
153
+ groupId: string
154
+ targetId: NodeId | null
155
+ expected: number
156
+ createdBy?: NodeId
157
+ continuations?: NodeId[]
158
+ }>
159
+ blockedTaskId: string | null
160
+ blockedJoinGroup: string | null
161
+ }
162
+
163
+ export interface RuntimeState {
164
+ status: 'idle' | 'running' | 'completed' | 'rejected' | 'cancelled' | 'revoked'
165
+ initiator: Record<string, any> | null
166
+ tokens: FlowToken[]
167
+ tasks: FlowTask[]
168
+ ccRecords: Array<Record<string, any>>
169
+ history: FlowEvent[]
170
+ variables: Record<string, any>
171
+ warnings: Array<{ code: string; message: string; at: string }>
172
+ startedAt: string | null
173
+ endedAt: string | null
174
+ cycle: number
175
+ currentNodeIds?: NodeId[]
176
+ pendingTaskCount?: number
177
+ [key: string]: unknown
178
+ }
179
+
180
+ export interface RuntimeContext {
181
+ initiator?: Record<string, any>
182
+ initiatorId?: NodeId
183
+ resolveApprovers?: (
184
+ node: FlowNode,
185
+ variables: Record<string, any>,
186
+ context: RuntimeContext
187
+ ) => Array<Record<string, any>> | null | undefined
188
+ resolveRoleUsers?: (roleIds: NodeId[], node: FlowNode) => Array<Record<string, any>>
189
+ getSuperiorLeader?: (level: number, node: FlowNode) => Array<Record<string, any>> | Record<string, any> | null
190
+ resolveUser?: (userId: NodeId) => Record<string, any> | null
191
+ resolveExtraCcUsers?: (
192
+ node: FlowNode,
193
+ variables: Record<string, any>,
194
+ context: RuntimeContext
195
+ ) => Array<Record<string, any>>
196
+ [key: string]: any
197
+ }
198
+
199
+ export type RuntimeHandlers = Partial<
200
+ Record<
201
+ | 'onStart'
202
+ | 'onTaskCreated'
203
+ | 'onTaskUpdated'
204
+ | 'onTaskApproved'
205
+ | 'onTaskTransferred'
206
+ | 'onCustomTaskCompleted'
207
+ | 'onCustomTaskFailed'
208
+ | 'onNodeEnter'
209
+ | 'onNodeLeave'
210
+ | 'onCc'
211
+ | 'onJoin'
212
+ | 'onReturned'
213
+ | 'onResubmitted'
214
+ | 'onFinished'
215
+ | 'onWarning',
216
+ (payload: any) => void
217
+ >
218
+ >
219
+
220
+ export interface FlowRuntimeOptions {
221
+ workflow: FlowNode
222
+ data?: Record<string, any>
223
+ context?: RuntimeContext
224
+ state?: RuntimeState | null
225
+ handlers?: RuntimeHandlers | null
226
+ }
227
+
228
+ export class FlowRuntime {
229
+ constructor(options: FlowRuntimeOptions)
230
+ static restore(options: FlowRuntimeOptions): FlowRuntime
231
+ workflow: FlowNode
232
+ context: RuntimeContext
233
+ handlers: RuntimeHandlers
234
+ state: RuntimeState
235
+ getNode(nodeId: NodeId): FlowNode | null
236
+ getState(): RuntimeState
237
+ getPendingTasks(): FlowTask[]
238
+ getPendingTasksForUser(userId: NodeId): FlowTask[]
239
+ getPendingCustomTasks(): FlowTask[]
240
+ getCcRecordsForUser(userId: NodeId): Array<Record<string, any>>
241
+ getRejectInfo(nodeId: NodeId): Record<string, any>
242
+ setVariables(patch: Record<string, any>): Record<string, any>
243
+ resolveApprovers(node: FlowNode): Array<Record<string, any>>
244
+ resolveCcUsers(node: FlowNode): Array<Record<string, any>>
245
+ start(initialData?: Record<string, any> | null, initiator?: Record<string, any> | null): RuntimeState
246
+ approve(taskId: string, payload?: Record<string, any>): RuntimeState
247
+ reject(taskId: string, payload?: Record<string, any>): RuntimeState
248
+ transfer(taskId: string, payload?: Record<string, any>): RuntimeState
249
+ resubmit(taskId: string, payload?: Record<string, any>): RuntimeState
250
+ completeCustomTask(taskId: string, payload?: Record<string, any>): RuntimeState
251
+ revoke(payload?: Record<string, any>): RuntimeState
252
+ cancel(reason?: string): RuntimeState
253
+ tick(now?: number | Date): RuntimeState
254
+ }
255
+
256
+ export function createFlowRuntime(options: FlowRuntimeOptions): FlowRuntime
257
+ export function evaluateBranches(workflow: FlowNode, data?: Record<string, any>): Array<Record<string, any>>
258
+
259
+ export interface PredictionNode {
260
+ id: string
261
+ nodeId: NodeId
262
+ nodeName: string
263
+ type: string
264
+ typeLabel?: string
265
+ kind: string
266
+ depth: number
267
+ path: string[]
268
+ group?: Record<string, any> | null
269
+ approvers?: Array<Record<string, any>>
270
+ ccUsers?: Array<Record<string, any>>
271
+ signMode?: string
272
+ signModeLabel?: string
273
+ note?: string
274
+ [key: string]: unknown
275
+ }
276
+
277
+ export interface PredictionResult {
278
+ rootNodeId: NodeId
279
+ definitionName: string | null
280
+ initiator: Record<string, any> | null
281
+ status: 'completed' | 'rejected' | string
282
+ nodeCount: number
283
+ approvalNodeCount: number
284
+ approvalTaskCount: number
285
+ ccNodeCount: number
286
+ ccUserCount: number
287
+ branchCount: number
288
+ decisions: Array<Record<string, any>>
289
+ warnings: Array<{ code: string; message: string; nodeId?: NodeId | null; nodeName?: string }>
290
+ nodes: PredictionNode[]
291
+ }
292
+
293
+ export function predictWorkflow(options: {
294
+ definition?: FlowDefinition | null
295
+ workflow?: FlowNode | null
296
+ data?: Record<string, any>
297
+ context?: RuntimeContext
298
+ initiator?: Record<string, any> | null
299
+ }): PredictionResult
300
+ export function predictFlow(
301
+ workflow: FlowNode,
302
+ data?: Record<string, any>,
303
+ context?: RuntimeContext,
304
+ initiator?: Record<string, any> | null
305
+ ): PredictionResult
306
+
307
+ export const MAX_PREDICTION_NODES: number
308
+ export const MAX_NODE_COUNT: number
309
+ export const SCHEMA_VERSION: string
310
+ export const SCHEMA_KIND: string
311
+ export const WORKFLOW_KIND: string
312
+ export const FORM_KIND: string
313
+
314
+ export const FlowNodeType: {
315
+ readonly START: 'start'
316
+ readonly APPROVE: 'approve'
317
+ readonly CC: 'cc'
318
+ readonly BRANCH: 'branch'
319
+ readonly CONDITION: 'condition'
320
+ readonly PARALLEL: 'parallel'
321
+ readonly PARALLEL_BRANCH: 'parallel_branch'
322
+ readonly INCLUSIVE: 'inclusive'
323
+ readonly INCLUSIVE_BRANCH: 'inclusive_branch'
324
+ readonly PASS: 'pass'
325
+ readonly REJECT: 'reject'
326
+ readonly END: 'end'
327
+ }
328
+ export const NodeTypeLabel: Record<string, string>
329
+ export const ApproverType: Record<string, string>
330
+ export const ApproverTypeLabel: Record<string, string>
331
+ export const ApproverTypeOptions: Array<{ value: string; label: string }>
332
+ export const SignMode: Record<string, string>
333
+ export const SignModeLabel: Record<string, string>
334
+ export const RejectStrategy: Record<string, string>
335
+ export const RejectStrategyLabel: Record<string, string>
336
+ export const TaskAction: Record<string, string>
337
+ export const TaskStatus: Record<string, string>
338
+ export const FlowInstanceStatus: Record<string, string>
339
+ export const FlowEventType: Record<string, string>
340
+ export const BusinessType: Record<string, string>
341
+
342
+ export function normalizeWorkflow(
343
+ workflow: FlowNode,
344
+ options?: { ensureEnd?: boolean }
345
+ ): { workflow: FlowNode; repairs: string[] }
346
+ export function createDefinition(input?: {
347
+ workflow?: FlowNode | null
348
+ form?: Array<Record<string, any>> | FlowForm | null
349
+ meta?: Partial<FlowDefinitionMeta>
350
+ }): FlowDefinition
351
+ export function normalizeDefinition(input: FlowDefinition | Record<string, any> | string, options?: Record<string, any>): FlowDefinition
352
+ export function importDefinition(input: string | Record<string, any> | Array<Record<string, any>>): {
353
+ document: FlowDefinition
354
+ repairs: string[]
355
+ validation: ValidationResult
356
+ }
357
+ export function exportDefinition(input: FlowDefinition | Record<string, any>, options?: { raw?: boolean; space?: number; updateTimestamp?: boolean }): string | FlowDefinition
358
+ export function exportWorkflow(workflow: FlowNode, meta?: Partial<FlowDefinitionMeta>, options?: { raw?: boolean; space?: number }): string | Record<string, any>
359
+
360
+ export interface ValidationIssue {
361
+ code: string
362
+ message: string
363
+ nodeId?: NodeId
364
+ componentId?: string
365
+ [key: string]: unknown
366
+ }
367
+
368
+ export interface ValidationResult {
369
+ valid: boolean
370
+ errors: ValidationIssue[]
371
+ warnings: ValidationIssue[]
372
+ nodeCount?: number
373
+ }
374
+
375
+ export function validateWorkflow(workflow: FlowNode, options?: { strict?: boolean; formVariables?: any[] }): ValidationResult
376
+ export function validateDefinition(definition: FlowDefinition, options?: { strict?: boolean }): ValidationResult
377
+
378
+ export function evaluateCondition(condition: FlowCondition, data?: Record<string, any>): boolean
379
+ export function evaluateConditionGroup(conditions: FlowCondition[], data?: Record<string, any>): boolean
380
+ export function getVariableValue(data: Record<string, any>, variable: string): unknown
381
+ export function selectBranchNode(branchNode: FlowNode, data?: Record<string, any>): FlowNode | null
382
+ export function selectInclusiveBranches(branchNode: FlowNode, data?: Record<string, any>): FlowNode[]
383
+ export function isEmptyValue(value: unknown): boolean
384
+ export function normalizeComparable(value: unknown): string
385
+
386
+ export function isStructuralNode(node: FlowNode | null): boolean
387
+ export function isTerminalNode(node: FlowNode | null): boolean
388
+ export function isBranchNode(node: FlowNode | null): boolean
389
+ export function getNodeTypeLabel(type: string): string
390
+ export function createNodeDefaults(type: string): Record<string, unknown>
391
+
392
+ export function findNodeById(node: FlowNode | null, targetId: NodeId): FlowNode | null
393
+ export function hasEndNode(node: FlowNode | null): boolean
394
+ export function ensureEndNode(rootNode: FlowNode): FlowNode
395
+ export function createNewNode(type: string, name?: string): FlowNode
396
+ export function createEndNode(): FlowNode
397
+ export function generateNodeId(): number
398
+ export function traverseNodes(root: FlowNode | null, visitor: (node: FlowNode) => void): void
399
+ export function getAllNodes(root: FlowNode | null): FlowNode[]
400
+ export function countNodes(root: FlowNode | null): number
401
+ export function getNodeStatistics(root: FlowNode | null): Record<string, number>
402
+
403
+ export const CUSTOM_EXECUTOR_TYPE: { HTTP: 'http'; METHOD: 'method' }
404
+ export const CUSTOM_ERROR_POLICY: { TERMINATE: 'terminate'; CONTINUE: 'continue' }
405
+ export const CUSTOM_HTTP_METHODS: string[]
406
+ export const CUSTOM_TIMEOUT_DEFAULT: number
407
+ export const CUSTOM_TIMEOUT_MIN: number
408
+ export const CUSTOM_TIMEOUT_MAX: number
409
+ export const CUSTOM_RESULT_LIMIT: number
410
+
411
+ export function createCustomNodeConfig(overrides?: CustomNodeConfig): CustomNodeConfig
412
+ export function normalizeCustomNodeConfig(input?: CustomNodeConfig | null): CustomNodeConfig
413
+ export function validateCustomNodeConfig(input?: CustomNodeConfig | null): {
414
+ errors: ValidationIssue[]
415
+ warnings: ValidationIssue[]
416
+ config: CustomNodeConfig
417
+ }
418
+ export function customNodeSummary(input?: CustomNodeConfig | null): string
419
+ export function isValidCustomResultVariable(value: unknown): boolean
420
+ export function interpolateCustomTemplate(template: unknown, variables?: Record<string, any>): any
421
+ export function resolveCustomRequest(input: CustomNodeConfig, variables?: Record<string, any>): {
422
+ url: string
423
+ method: string
424
+ headers: Record<string, string>
425
+ body?: string
426
+ timeoutMs: number
427
+ }
428
+ export function executeCustomNode(
429
+ input: CustomNodeConfig,
430
+ options?: {
431
+ variables?: Record<string, any>
432
+ executors?: Record<string, (context: Record<string, any>) => unknown>
433
+ fetchImpl?: (...args: any[]) => Promise<any>
434
+ signal?: any
435
+ node?: FlowNode | null
436
+ instance?: Record<string, any> | null
437
+ }
438
+ ): Promise<any>
439
+
440
+ export const RUNTIME_RUNNING: 'running'
441
+ export const RUNTIME_COMPLETED: 'completed'
442
+ export const RUNTIME_REJECTED: 'rejected'
443
+ export const RUNTIME_CANCELLED: 'cancelled'
444
+ export const RUNTIME_REVOKED: 'revoked'
445
+ export const RUNTIME_IDLE: 'idle'
446
+
447
+ // Re-exported headless form helpers.
448
+ export interface FormVariable {
449
+ variableName: string
450
+ label: string
451
+ dataType: string
452
+ componentType: string
453
+ metadata: Record<string, any>
454
+ getOptions(): Array<Record<string, any>>
455
+ getDateFormat?(): string
456
+ [key: string]: any
457
+ }
458
+ export const ConditionOperator: Record<string, string>
459
+ export const OPERATOR_LABEL_MAP: Record<string, string>
460
+ export function computeDataType(component: Record<string, any>): string
461
+ export function enrichFormVariables(components: Array<Record<string, any>>): FormVariable[]
462
+ export function findFormVariable(formVariables: FormVariable[], variableName: string): FormVariable | null
463
+ export function normalizeForm(form: unknown): { components: Array<Record<string, any>>; options: Record<string, any>; repairs: string[] }
464
+ export function validateForm(form: unknown): { valid: boolean; errors: ValidationIssue[]; warnings: ValidationIssue[] }
465
+ export function importForm(input: unknown): { form: FlowForm; repairs: string[] }
466
+ export function exportForm(input: unknown, meta?: Record<string, any>, options?: Record<string, any>): string | Record<string, any>
467
+ export function downloadJSON(data: unknown, fileName?: string, space?: number): void
468
+ export function downloadText(content: string, fileName: string, mime?: string): void
469
+ export function readTextFile(file: File): Promise<string>
470
+ export function pickJSONFile(): Promise<{ file: File; text: string } | null>
471
+ export function sanitizeFileName(name: string, fallback?: string): string
472
+ export const COMPONENT_TYPES: Record<string, string>
473
+ export const COMPONENT_TYPE_LABELS: Record<string, string>
474
+ export const OPTION_COMPONENT_TYPES: string[]
475
+ export function generateComponentId(): string
476
+ export function ensureComponentId(component: Record<string, any>): Record<string, any>
477
+ export function getFieldName(component: Record<string, any>): string
478
+ export const BaseDataType: Record<string, string>
479
+ export const ComponentType: Record<string, string>