@open-mercato/core 0.6.7-develop.6580.1.39ab1d9e62 → 0.6.7-develop.6582.1.04cac61287
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.
- package/.turbo/turbo-build.log +1 -1
- package/dist/modules/sales/commands/documents.js +8 -4
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/workflows.js +4 -0
- package/dist/modules/sales/workflows.js.map +2 -2
- package/dist/modules/workflows/api/instances/route.js +3 -1
- package/dist/modules/workflows/api/instances/route.js.map +2 -2
- package/dist/modules/workflows/lib/activity-executor.js +30 -2
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/dist/modules/workflows/lib/code-registry.js +10 -17
- package/dist/modules/workflows/lib/code-registry.js.map +2 -2
- package/dist/modules/workflows/lib/event-trigger-service.js +14 -2
- package/dist/modules/workflows/lib/event-trigger-service.js.map +2 -2
- package/dist/modules/workflows/lib/parallel-handler.js +10 -1
- package/dist/modules/workflows/lib/parallel-handler.js.map +2 -2
- package/dist/modules/workflows/lib/workflow-executor.js +13 -3
- package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
- package/dist/modules/workflows/lib/workflow-safe-commands.js +42 -0
- package/dist/modules/workflows/lib/workflow-safe-commands.js.map +7 -0
- package/package.json +7 -7
- package/src/modules/sales/commands/documents.ts +4 -0
- package/src/modules/sales/workflows.ts +5 -0
- package/src/modules/workflows/api/instances/route.ts +4 -2
- package/src/modules/workflows/lib/activity-executor.ts +47 -3
- package/src/modules/workflows/lib/code-registry.ts +16 -39
- package/src/modules/workflows/lib/event-trigger-service.ts +15 -2
- package/src/modules/workflows/lib/parallel-handler.ts +11 -1
- package/src/modules/workflows/lib/workflow-executor.ts +22 -3
- package/src/modules/workflows/lib/workflow-safe-commands.ts +48 -0
|
@@ -64,6 +64,24 @@ export interface WorkflowEventSummary {
|
|
|
64
64
|
data?: any
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
function normalizeWorkflowUserId(value: unknown): string | null {
|
|
68
|
+
if (typeof value !== 'string') return null
|
|
69
|
+
const trimmed = value.trim()
|
|
70
|
+
if (!trimmed || trimmed.startsWith('trigger:')) return null
|
|
71
|
+
return trimmed
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function resolveWorkflowExecutionUserId(
|
|
75
|
+
context: ExecutionContext | undefined,
|
|
76
|
+
instance: WorkflowInstance,
|
|
77
|
+
): string | undefined {
|
|
78
|
+
return (
|
|
79
|
+
normalizeWorkflowUserId(context?.userId) ??
|
|
80
|
+
normalizeWorkflowUserId(instance.metadata?.initiatedBy) ??
|
|
81
|
+
undefined
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
67
85
|
export class WorkflowExecutionError extends Error {
|
|
68
86
|
constructor(
|
|
69
87
|
message: string,
|
|
@@ -290,6 +308,7 @@ export async function executeWorkflow(
|
|
|
290
308
|
|
|
291
309
|
const maxIterations = 100
|
|
292
310
|
let iterations = 0
|
|
311
|
+
const executionUserId = resolveWorkflowExecutionUserId(context, instance)
|
|
293
312
|
|
|
294
313
|
while (iterations < maxIterations) {
|
|
295
314
|
iterations++
|
|
@@ -307,7 +326,7 @@ export async function executeWorkflow(
|
|
|
307
326
|
if (currentInstance.status === 'FORKED') {
|
|
308
327
|
const { advanceBranches } = await import('./parallel-handler')
|
|
309
328
|
const branchResult = await advanceBranches(trx, container, currentInstance, definition, {
|
|
310
|
-
userId:
|
|
329
|
+
userId: executionUserId,
|
|
311
330
|
})
|
|
312
331
|
|
|
313
332
|
if (branchResult.outcome === 'joined') {
|
|
@@ -393,7 +412,7 @@ export async function executeWorkflow(
|
|
|
393
412
|
const transitionHandler = await import('./transition-handler')
|
|
394
413
|
const evalContext: any = {
|
|
395
414
|
workflowContext: currentInstance.context,
|
|
396
|
-
userId:
|
|
415
|
+
userId: executionUserId,
|
|
397
416
|
}
|
|
398
417
|
|
|
399
418
|
const validTransitions = await transitionHandler.findValidTransitions(
|
|
@@ -882,7 +901,7 @@ export async function resumeWorkflowAfterActivities(
|
|
|
882
901
|
pendingTransition.toStepId,
|
|
883
902
|
{
|
|
884
903
|
workflowContext: instance.context || {},
|
|
885
|
-
userId: undefined,
|
|
904
|
+
userId: resolveWorkflowExecutionUserId(undefined, instance),
|
|
886
905
|
},
|
|
887
906
|
container
|
|
888
907
|
)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export type WorkflowSafeCommandDefinition = {
|
|
2
|
+
commandId: string
|
|
3
|
+
requiredFeatures: readonly [string, ...string[]]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const workflowSafeCommands = new Map<string, WorkflowSafeCommandDefinition>()
|
|
7
|
+
|
|
8
|
+
function normalizeCommandId(commandId: unknown): string | null {
|
|
9
|
+
if (typeof commandId !== 'string') return null
|
|
10
|
+
const trimmed = commandId.trim()
|
|
11
|
+
return trimmed.length > 0 ? trimmed : null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function normalizeFeatures(features: readonly string[]): [string, ...string[]] | null {
|
|
15
|
+
const normalized = features
|
|
16
|
+
.map((feature) => feature.trim())
|
|
17
|
+
.filter((feature) => feature.length > 0)
|
|
18
|
+
if (normalized.length === 0) return null
|
|
19
|
+
return normalized as [string, ...string[]]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function registerWorkflowSafeCommands(commands: readonly WorkflowSafeCommandDefinition[]): void {
|
|
23
|
+
for (const command of commands) {
|
|
24
|
+
const commandId = normalizeCommandId(command.commandId)
|
|
25
|
+
const requiredFeatures = normalizeFeatures(command.requiredFeatures)
|
|
26
|
+
if (!commandId || !requiredFeatures) {
|
|
27
|
+
throw new Error('[internal] Workflow-safe commands require a commandId and requiredFeatures')
|
|
28
|
+
}
|
|
29
|
+
workflowSafeCommands.set(commandId, { commandId, requiredFeatures })
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function getWorkflowSafeCommand(commandId: unknown): WorkflowSafeCommandDefinition | null {
|
|
34
|
+
const normalized = normalizeCommandId(commandId)
|
|
35
|
+
if (!normalized) return null
|
|
36
|
+
return workflowSafeCommands.get(normalized) ?? null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isWorkflowSafeCommandId(commandId: unknown): boolean {
|
|
40
|
+
return getWorkflowSafeCommand(commandId) !== null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function clearWorkflowSafeCommandsForTests(): void {
|
|
44
|
+
if (process.env.NODE_ENV !== 'test') {
|
|
45
|
+
throw new Error('[internal] clearWorkflowSafeCommandsForTests is test-only')
|
|
46
|
+
}
|
|
47
|
+
workflowSafeCommands.clear()
|
|
48
|
+
}
|