@open-mercato/core 0.11.1-develop.8557.1.e615240a3e → 0.11.1-develop.8567.1.a167594505
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/api_keys/di.js +6 -2
- package/dist/modules/api_keys/di.js.map +2 -2
- package/dist/modules/api_keys/services/oneTimeIssuerService.js +47 -0
- package/dist/modules/api_keys/services/oneTimeIssuerService.js.map +7 -0
- package/dist/modules/audit_logs/di.js +2 -1
- package/dist/modules/audit_logs/di.js.map +2 -2
- package/dist/modules/audit_logs/services/actionLogService.js +65 -1
- package/dist/modules/audit_logs/services/actionLogService.js.map +2 -2
- package/dist/modules/auth/cli.js +1 -0
- package/dist/modules/auth/cli.js.map +2 -2
- package/dist/modules/auth/commands/users.js +10 -2
- package/dist/modules/auth/commands/users.js.map +2 -2
- package/dist/modules/auth/lib/setup-app.js +19 -5
- package/dist/modules/auth/lib/setup-app.js.map +2 -2
- package/dist/modules/configs/cli.js +26 -29
- package/dist/modules/configs/cli.js.map +2 -2
- package/dist/modules/configs/di.js +3 -1
- package/dist/modules/configs/di.js.map +2 -2
- package/dist/modules/configs/lib/instance-config-initializer.js +44 -0
- package/dist/modules/configs/lib/instance-config-initializer.js.map +7 -0
- package/dist/modules/configs/lib/instance-defaults.js +204 -0
- package/dist/modules/configs/lib/instance-defaults.js.map +7 -0
- package/dist/modules/configs/lib/module-config-service.js +115 -1
- package/dist/modules/configs/lib/module-config-service.js.map +2 -2
- package/dist/modules/entities/api/definitions.batch.js +55 -25
- package/dist/modules/entities/api/definitions.batch.js.map +2 -2
- package/dist/modules/entities/api/definitions.js +35 -8
- package/dist/modules/entities/api/definitions.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/page.js +14 -8
- package/dist/modules/entities/backend/entities/user/[entityId]/page.js.map +2 -2
- package/dist/modules/notifications/lib/deliveryConfig.js +19 -12
- package/dist/modules/notifications/lib/deliveryConfig.js.map +2 -2
- package/dist/modules/notifications/setup.js +10 -0
- package/dist/modules/notifications/setup.js.map +2 -2
- package/dist/modules/translations/components/TranslationManager.js +47 -10
- package/dist/modules/translations/components/TranslationManager.js.map +2 -2
- package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js +8 -1
- package/dist/modules/wms/components/backend/CompletePutawayTaskDialog.js.map +2 -2
- package/dist/modules/workflows/ai-tools/authoring-pack.js +1 -1
- package/dist/modules/workflows/ai-tools/authoring-pack.js.map +2 -2
- package/dist/modules/workflows/api/instances/[id]/advance/route.js +1 -0
- package/dist/modules/workflows/api/instances/[id]/advance/route.js.map +2 -2
- package/dist/modules/workflows/api/instances/route.js +1 -1
- package/dist/modules/workflows/api/instances/route.js.map +2 -2
- package/dist/modules/workflows/api/instances/validate-start/route.js +3 -1
- package/dist/modules/workflows/api/instances/validate-start/route.js.map +2 -2
- package/dist/modules/workflows/di.js +3 -1
- package/dist/modules/workflows/di.js.map +2 -2
- package/dist/modules/workflows/lib/activity-executor.js +35 -7
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/dist/modules/workflows/lib/condition-handler.js +1 -1
- package/dist/modules/workflows/lib/condition-handler.js.map +2 -2
- package/dist/modules/workflows/lib/error-handler.js +1 -1
- package/dist/modules/workflows/lib/error-handler.js.map +2 -2
- package/dist/modules/workflows/lib/event-trigger-service.js +1 -1
- package/dist/modules/workflows/lib/event-trigger-service.js.map +2 -2
- package/dist/modules/workflows/lib/example-definition-authoring.js +90 -0
- package/dist/modules/workflows/lib/example-definition-authoring.js.map +7 -0
- package/dist/modules/workflows/lib/named-rules.js +42 -0
- package/dist/modules/workflows/lib/named-rules.js.map +7 -0
- package/dist/modules/workflows/lib/owned-definition.js +2 -0
- package/dist/modules/workflows/lib/owned-definition.js.map +2 -2
- package/dist/modules/workflows/lib/parallel-handler.js +1 -1
- package/dist/modules/workflows/lib/parallel-handler.js.map +2 -2
- package/dist/modules/workflows/lib/signal-handler.js +1 -0
- package/dist/modules/workflows/lib/signal-handler.js.map +2 -2
- package/dist/modules/workflows/lib/start-validator.js +87 -85
- package/dist/modules/workflows/lib/start-validator.js.map +2 -2
- package/dist/modules/workflows/lib/step-handler.js +1 -1
- package/dist/modules/workflows/lib/step-handler.js.map +2 -2
- package/dist/modules/workflows/lib/task-handler.js +1 -0
- package/dist/modules/workflows/lib/task-handler.js.map +2 -2
- package/dist/modules/workflows/lib/timer-handler.js +1 -0
- package/dist/modules/workflows/lib/timer-handler.js.map +2 -2
- package/dist/modules/workflows/lib/transition-handler.js +48 -166
- package/dist/modules/workflows/lib/transition-handler.js.map +3 -3
- package/dist/modules/workflows/lib/workflow-executor.js +3 -2
- package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
- package/package.json +8 -8
- package/src/modules/api_keys/di.ts +7 -2
- package/src/modules/api_keys/services/oneTimeIssuerService.ts +61 -0
- package/src/modules/audit_logs/di.ts +1 -0
- package/src/modules/audit_logs/services/actionLogService.ts +132 -1
- package/src/modules/auth/cli.ts +1 -0
- package/src/modules/auth/commands/users.ts +10 -2
- package/src/modules/auth/i18n/de.json +2 -0
- package/src/modules/auth/i18n/en.json +2 -0
- package/src/modules/auth/i18n/es.json +2 -0
- package/src/modules/auth/i18n/ko.json +2 -0
- package/src/modules/auth/i18n/pl.json +2 -0
- package/src/modules/auth/lib/setup-app.ts +30 -7
- package/src/modules/configs/cli.ts +39 -37
- package/src/modules/configs/di.ts +2 -0
- package/src/modules/configs/lib/instance-config-initializer.ts +56 -0
- package/src/modules/configs/lib/instance-defaults.ts +262 -0
- package/src/modules/configs/lib/module-config-service.ts +156 -0
- package/src/modules/entities/api/definitions.batch.ts +65 -27
- package/src/modules/entities/api/definitions.ts +40 -11
- package/src/modules/entities/backend/entities/user/[entityId]/page.tsx +14 -7
- package/src/modules/notifications/lib/deliveryConfig.ts +20 -11
- package/src/modules/notifications/setup.ts +11 -0
- package/src/modules/translations/components/TranslationManager.tsx +49 -10
- package/src/modules/translations/i18n/de.json +1 -0
- package/src/modules/translations/i18n/en.json +1 -0
- package/src/modules/translations/i18n/es.json +1 -0
- package/src/modules/translations/i18n/ko.json +1 -0
- package/src/modules/translations/i18n/pl.json +1 -0
- package/src/modules/wms/components/backend/CompletePutawayTaskDialog.tsx +8 -1
- package/src/modules/wms/i18n/de.json +1 -0
- package/src/modules/wms/i18n/en.json +1 -0
- package/src/modules/wms/i18n/es.json +1 -0
- package/src/modules/wms/i18n/ko.json +1 -0
- package/src/modules/wms/i18n/pl.json +1 -0
- package/src/modules/workflows/ai-tools/authoring-pack.ts +3 -1
- package/src/modules/workflows/api/instances/[id]/advance/route.ts +1 -0
- package/src/modules/workflows/api/instances/route.ts +1 -1
- package/src/modules/workflows/api/instances/validate-start/route.ts +3 -1
- package/src/modules/workflows/di.ts +2 -0
- package/src/modules/workflows/lib/activity-executor.ts +48 -30
- package/src/modules/workflows/lib/condition-handler.ts +1 -1
- package/src/modules/workflows/lib/error-handler.ts +1 -1
- package/src/modules/workflows/lib/event-trigger-service.ts +1 -1
- package/src/modules/workflows/lib/example-definition-authoring.ts +114 -0
- package/src/modules/workflows/lib/named-rules.ts +54 -0
- package/src/modules/workflows/lib/owned-definition.ts +4 -1
- package/src/modules/workflows/lib/parallel-handler.ts +1 -1
- package/src/modules/workflows/lib/signal-handler.ts +1 -0
- package/src/modules/workflows/lib/start-validator.ts +96 -94
- package/src/modules/workflows/lib/step-handler.ts +1 -1
- package/src/modules/workflows/lib/task-handler.ts +1 -0
- package/src/modules/workflows/lib/timer-handler.ts +1 -0
- package/src/modules/workflows/lib/transition-handler.ts +74 -238
- package/src/modules/workflows/lib/workflow-executor.ts +7 -4
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import * as ruleEngine from "../../business_rules/lib/rule-engine.js";
|
|
2
1
|
import { findWorkflowDefinition } from "./find-definition.js";
|
|
3
|
-
import {
|
|
2
|
+
import { withNamedWorkflowRuleRunner } from "./named-rules.js";
|
|
4
3
|
import { defaultLocale } from "@open-mercato/shared/lib/i18n/config";
|
|
5
4
|
import { resolveLocaleFromCandidates } from "@open-mercato/shared/lib/i18n/locale";
|
|
6
5
|
import { getSupportedLocales, loadDictionary } from "@open-mercato/shared/lib/i18n/server";
|
|
7
6
|
import { createTranslator } from "@open-mercato/shared/lib/i18n/translate";
|
|
8
7
|
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
9
8
|
const logger = createLogger("workflows");
|
|
10
|
-
async function validateWorkflowStart(em, options) {
|
|
9
|
+
async function validateWorkflowStart(em, options, runtime) {
|
|
11
10
|
const { workflowId, version, context, locale = "en", tenantId, organizationId } = options;
|
|
12
11
|
const definition = await findWorkflowDefinition(em, {
|
|
13
12
|
workflowId,
|
|
@@ -66,98 +65,101 @@ async function validateWorkflowStart(em, options) {
|
|
|
66
65
|
validatedRules: []
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
return withNamedWorkflowRuleRunner(runtime?.container, async (runner) => {
|
|
69
|
+
if (!runner) {
|
|
70
|
+
const required = preConditions.filter((condition) => condition.required);
|
|
71
|
+
if (required.length === 0) return { canStart: true, errors: [], validatedRules: [] };
|
|
72
|
+
const language = resolveLocaleFromCandidates([locale], getSupportedLocales()) ?? defaultLocale;
|
|
73
|
+
const t = createTranslator(await loadDictionary(language));
|
|
74
|
+
return {
|
|
75
|
+
canStart: false,
|
|
76
|
+
errors: required.map((condition) => ({
|
|
77
|
+
ruleId: condition.ruleId,
|
|
78
|
+
message: getLocalizedMessage(
|
|
79
|
+
condition,
|
|
80
|
+
null,
|
|
81
|
+
locale,
|
|
82
|
+
t("workflows.errors.businessRulesModuleDisabled", "Business rules module is disabled: {ruleId}", {
|
|
83
|
+
ruleId: condition.ruleId
|
|
84
|
+
})
|
|
85
|
+
),
|
|
86
|
+
code: "RULE_ENGINE_UNAVAILABLE"
|
|
87
|
+
})),
|
|
88
|
+
validatedRules: []
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const errors = [];
|
|
92
|
+
const validatedRules = [];
|
|
93
|
+
for (const condition of preConditions) {
|
|
94
|
+
const result = await runner.executeRuleByRuleId(em, {
|
|
77
95
|
ruleId: condition.ruleId,
|
|
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
|
-
|
|
96
|
+
// String identifier like "workflow_checkout_inventory_available"
|
|
97
|
+
data: {
|
|
98
|
+
workflowId,
|
|
99
|
+
workflowContext: context
|
|
100
|
+
},
|
|
101
|
+
tenantId,
|
|
102
|
+
organizationId,
|
|
103
|
+
entityType: `workflow:${workflowId}:start`,
|
|
104
|
+
entityId: "pre_start_validation",
|
|
105
|
+
eventType: "validate_start",
|
|
106
|
+
dryRun: true,
|
|
107
|
+
// Don't log execution during validation
|
|
108
|
+
...runtime?.skipActions ? { skipActions: true } : {}
|
|
109
|
+
});
|
|
110
|
+
validatedRules.push({
|
|
111
|
+
ruleId: condition.ruleId,
|
|
112
|
+
passed: result.conditionResult,
|
|
113
|
+
executionTime: result.executionTime
|
|
114
|
+
});
|
|
115
|
+
if (result.error === "Rule not found") {
|
|
116
|
+
if (condition.required) {
|
|
117
|
+
errors.push({
|
|
118
|
+
ruleId: condition.ruleId,
|
|
119
|
+
message: getLocalizedMessage(condition, null, locale, `Business rule not found: ${condition.ruleId}`),
|
|
120
|
+
code: "RULE_NOT_FOUND"
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (result.error === "Rule is disabled") {
|
|
126
|
+
if (condition.required) {
|
|
127
|
+
errors.push({
|
|
128
|
+
ruleId: condition.ruleId,
|
|
129
|
+
message: getLocalizedMessage(condition, null, locale, `Business rule is disabled: ${result.ruleName}`),
|
|
130
|
+
code: "RULE_DISABLED"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (result.error && condition.required) {
|
|
116
136
|
errors.push({
|
|
117
137
|
ruleId: condition.ruleId,
|
|
118
|
-
message: getLocalizedMessage(condition, null, locale, `
|
|
119
|
-
code: "
|
|
138
|
+
message: getLocalizedMessage(condition, null, locale, `Rule error: ${result.error}`),
|
|
139
|
+
code: "RULE_ERROR"
|
|
120
140
|
});
|
|
141
|
+
continue;
|
|
121
142
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
if (!result.conditionResult && condition.required) {
|
|
144
|
+
const message = getLocalizedMessage(
|
|
145
|
+
condition,
|
|
146
|
+
null,
|
|
147
|
+
locale,
|
|
148
|
+
`Pre-condition '${result.ruleName || condition.ruleId}' failed`
|
|
149
|
+
);
|
|
126
150
|
errors.push({
|
|
127
151
|
ruleId: condition.ruleId,
|
|
128
|
-
message
|
|
129
|
-
code: "
|
|
152
|
+
message,
|
|
153
|
+
code: "PRE_CONDITION_FAILED"
|
|
130
154
|
});
|
|
131
155
|
}
|
|
132
|
-
continue;
|
|
133
156
|
}
|
|
134
|
-
|
|
135
|
-
errors.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (!result.conditionResult && condition.required) {
|
|
143
|
-
const message = getLocalizedMessage(
|
|
144
|
-
condition,
|
|
145
|
-
null,
|
|
146
|
-
locale,
|
|
147
|
-
`Pre-condition '${result.ruleName || condition.ruleId}' failed`
|
|
148
|
-
);
|
|
149
|
-
errors.push({
|
|
150
|
-
ruleId: condition.ruleId,
|
|
151
|
-
message,
|
|
152
|
-
code: "PRE_CONDITION_FAILED"
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return {
|
|
157
|
-
canStart: errors.length === 0,
|
|
158
|
-
errors,
|
|
159
|
-
validatedRules
|
|
160
|
-
};
|
|
157
|
+
return {
|
|
158
|
+
canStart: errors.length === 0,
|
|
159
|
+
errors,
|
|
160
|
+
validatedRules
|
|
161
|
+
};
|
|
162
|
+
});
|
|
161
163
|
}
|
|
162
164
|
function getLocalizedMessage(condition, rule, locale, defaultMessage) {
|
|
163
165
|
if (condition.validationMessage?.[locale]) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/workflows/lib/start-validator.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Workflows Module - Start Validator Service\n *\n * Validates pre-conditions on START step before workflow instance creation.\n * This enables guard rules that determine whether a workflow can be started\n * based on the initial context provided.\n */\n\nimport { EntityManager } from '@mikro-orm/core'\nimport {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Workflows Module - Start Validator Service\n *\n * Validates pre-conditions on START step before workflow instance creation.\n * This enables guard rules that determine whether a workflow can be started\n * based on the initial context provided.\n */\n\nimport { EntityManager } from '@mikro-orm/core'\nimport { findWorkflowDefinition } from './find-definition'\nimport { withNamedWorkflowRuleRunner, type WorkflowRuleContainer } from './named-rules'\nimport type { StartPreCondition } from '../data/validators'\nimport { defaultLocale } from '@open-mercato/shared/lib/i18n/config'\nimport { resolveLocaleFromCandidates } from '@open-mercato/shared/lib/i18n/locale'\nimport { getSupportedLocales, loadDictionary } from '@open-mercato/shared/lib/i18n/server'\nimport { createTranslator } from '@open-mercato/shared/lib/i18n/translate'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('workflows')\n\n// ============================================================================\n// Types and Interfaces\n// ============================================================================\n\nexport interface ValidateStartOptions {\n workflowId: string\n version?: number\n context: Record<string, any>\n locale?: string\n tenantId: string\n organizationId: string\n}\n\nexport interface ValidationError {\n ruleId: string\n message: string\n code: string\n}\n\nexport interface ValidatedRule {\n ruleId: string\n passed: boolean\n executionTime?: number\n}\n\nexport interface ValidateStartResult {\n canStart: boolean\n errors: ValidationError[]\n validatedRules: ValidatedRule[]\n}\n\n// ============================================================================\n// Main Validation Function\n// ============================================================================\n\n/**\n * Validate if a workflow can be started with the given context\n *\n * @param em - Entity manager for database operations\n * @param options - Validation options including workflowId, context, and scope\n * @returns Validation result with canStart flag, errors, and validated rules\n */\nexport async function validateWorkflowStart(\n em: EntityManager,\n options: ValidateStartOptions,\n runtime?: { container?: WorkflowRuleContainer | null; skipActions?: boolean },\n): Promise<ValidateStartResult> {\n const { workflowId, version, context, locale = 'en', tenantId, organizationId } = options\n\n // Find workflow definition\n const definition = await findWorkflowDefinition(em, {\n workflowId,\n version,\n tenantId,\n organizationId,\n })\n\n if (!definition) {\n return {\n canStart: false,\n errors: [{\n ruleId: '_DEFINITION_NOT_FOUND',\n message: `Workflow definition not found: ${workflowId}`,\n code: 'DEFINITION_NOT_FOUND',\n }],\n validatedRules: [],\n }\n }\n\n if (!definition.enabled) {\n return {\n canStart: false,\n errors: [{\n ruleId: '_DEFINITION_DISABLED',\n message: `Workflow is disabled: ${workflowId}`,\n code: 'DEFINITION_DISABLED',\n }],\n validatedRules: [],\n }\n }\n\n // Find START step and get pre-conditions\n const startStep = definition.definition.steps.find(\n (s: any) => s.stepType === 'START'\n )\n\n if (!startStep) {\n return {\n canStart: false,\n errors: [{\n ruleId: '_NO_START_STEP',\n message: 'Workflow has no START step',\n code: 'INVALID_DEFINITION',\n }],\n validatedRules: [],\n }\n }\n\n const preConditions: StartPreCondition[] = startStep.preConditions || []\n\n logger.debug('Evaluating START step pre-conditions', {\n component: 'start-validator',\n startStep,\n preConditionCount: preConditions.length,\n preConditions,\n })\n\n // If no pre-conditions, workflow can start\n if (preConditions.length === 0) {\n logger.debug('No pre-conditions defined, allowing start', { component: 'start-validator' })\n return {\n canStart: true,\n errors: [],\n validatedRules: [],\n }\n }\n\n return withNamedWorkflowRuleRunner(runtime?.container, async (runner) => {\n if (!runner) {\n const required = preConditions.filter((condition) => condition.required)\n if (required.length === 0) return { canStart: true, errors: [], validatedRules: [] }\n const language = resolveLocaleFromCandidates([locale], getSupportedLocales()) ?? defaultLocale\n const t = createTranslator(await loadDictionary(language))\n return {\n canStart: false,\n errors: required.map((condition) => ({\n ruleId: condition.ruleId,\n message: getLocalizedMessage(\n condition,\n null,\n locale,\n t('workflows.errors.businessRulesModuleDisabled', 'Business rules module is disabled: {ruleId}', {\n ruleId: condition.ruleId,\n }),\n ),\n code: 'RULE_ENGINE_UNAVAILABLE',\n })),\n validatedRules: [],\n }\n }\n\n // Evaluate each pre-condition using rule engine\n const errors: ValidationError[] = []\n const validatedRules: ValidatedRule[] = []\n\n for (const condition of preConditions) {\n // Execute rule directly by string rule_id\n const result = await runner.executeRuleByRuleId(em, {\n ruleId: condition.ruleId, // String identifier like \"workflow_checkout_inventory_available\"\n data: {\n workflowId,\n workflowContext: context,\n },\n tenantId,\n organizationId,\n entityType: `workflow:${workflowId}:start`,\n entityId: 'pre_start_validation',\n eventType: 'validate_start',\n dryRun: true, // Don't log execution during validation\n ...(runtime?.skipActions ? { skipActions: true } : {}),\n })\n\n validatedRules.push({\n ruleId: condition.ruleId,\n passed: result.conditionResult,\n executionTime: result.executionTime,\n })\n\n // Handle rule not found\n if (result.error === 'Rule not found') {\n if (condition.required) {\n errors.push({\n ruleId: condition.ruleId,\n message: getLocalizedMessage(condition, null, locale, `Business rule not found: ${condition.ruleId}`),\n code: 'RULE_NOT_FOUND',\n })\n }\n continue\n }\n\n // Handle disabled rule\n if (result.error === 'Rule is disabled') {\n if (condition.required) {\n errors.push({\n ruleId: condition.ruleId,\n message: getLocalizedMessage(condition, null, locale, `Business rule is disabled: ${result.ruleName}`),\n code: 'RULE_DISABLED',\n })\n }\n continue\n }\n\n // Handle other errors (not yet effective, expired, etc.)\n if (result.error && condition.required) {\n errors.push({\n ruleId: condition.ruleId,\n message: getLocalizedMessage(condition, null, locale, `Rule error: ${result.error}`),\n code: 'RULE_ERROR',\n })\n continue\n }\n\n // Handle condition failure\n if (!result.conditionResult && condition.required) {\n // Get localized message from condition or use default with rule name\n const message = getLocalizedMessage(\n condition,\n null,\n locale,\n `Pre-condition '${result.ruleName || condition.ruleId}' failed`\n )\n errors.push({\n ruleId: condition.ruleId,\n message,\n code: 'PRE_CONDITION_FAILED',\n })\n }\n }\n\n return {\n canStart: errors.length === 0,\n errors,\n validatedRules,\n }\n })\n}\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Get localized message with fallback chain\n *\n * Priority:\n * 1. condition.validationMessage[locale]\n * 2. condition.validationMessage['en']\n * 3. rule.failureActions[BLOCK_TRANSITION].config.message\n * 4. rule.description\n * 5. defaultMessage\n */\nfunction getLocalizedMessage(\n condition: StartPreCondition,\n rule: any | null,\n locale: string,\n defaultMessage: string\n): string {\n // Priority 1: Localized message in condition definition (requested locale)\n if (condition.validationMessage?.[locale]) {\n return condition.validationMessage[locale]\n }\n\n // Priority 2: English fallback in condition\n if (condition.validationMessage?.['en']) {\n return condition.validationMessage['en']\n }\n\n if (rule) {\n // Priority 3: Message from rule's failureActions\n if (rule.failureActions && Array.isArray(rule.failureActions)) {\n const blockAction = rule.failureActions.find(\n (a: any) => a.type === 'BLOCK_TRANSITION'\n )\n if (blockAction?.config?.message) {\n return blockAction.config.message\n }\n }\n\n // Priority 4: Rule description\n if (rule.description) {\n return rule.description\n }\n }\n\n // Priority 5: Default message\n return defaultMessage\n}\n\n// findWorkflowDefinition is imported from ./find-definition\n"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U,oBAAoB,MAAM,GAAG;AACzC,WAAO,UAAU,kBAAkB,MAAM;AAAA,EAC3C;AAGA,MAAI,UAAU,oBAAoB,IAAI,GAAG;AACvC,WAAO,UAAU,kBAAkB,IAAI;AAAA,EACzC;AAEA,MAAI,MAAM;AAER,QAAI,KAAK,kBAAkB,MAAM,QAAQ,KAAK,cAAc,GAAG;AAC7D,YAAM,cAAc,KAAK,eAAe;AAAA,QACtC,CAAC,MAAW,EAAE,SAAS;AAAA,MACzB;AACA,UAAI,aAAa,QAAQ,SAAS;AAChC,eAAO,YAAY,OAAO;AAAA,MAC5B;AAAA,IACF;AAGA,QAAI,KAAK,aAAa;AACpB,aAAO,KAAK;AAAA,IACd;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -767,7 +767,7 @@ async function handleSubWorkflowStep(em, container, instance, stepInstance, step
|
|
|
767
767
|
},
|
|
768
768
|
tenantId: instance.tenantId,
|
|
769
769
|
organizationId: instance.organizationId
|
|
770
|
-
});
|
|
770
|
+
}, container);
|
|
771
771
|
await logStepEvent(em, {
|
|
772
772
|
workflowInstanceId: instance.id,
|
|
773
773
|
stepInstanceId: stepInstance.id,
|