@onlineapps/conn-orch-orchestrator 1.0.27 → 1.0.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/conn-orch-orchestrator",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "Workflow orchestration connector for OA Drive - handles message routing and workflow execution",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -76,10 +76,11 @@ class WorkflowOrchestrator {
76
76
 
77
77
  try {
78
78
  // FAIL-FAST: Validate V2 format BEFORE anything else
79
+ // This replaces the old cookbook.validateCookbook() which only supports V1 (array steps)
79
80
  this._validateV2Format(cookbookDef);
80
81
 
81
- // Validate cookbook structure
82
- this.cookbook.validateCookbook(cookbookDef);
82
+ // NOTE: Skip cookbook.validateCookbook() - it uses V1 schema (steps as array)
83
+ // V2 validation is done by _validateV2Format() above
83
84
 
84
85
  // Ensure delivery configuration is preserved in context (required by Delivery Dispatcher)
85
86
  // Delivery comes from cookbook.delivery (set by Gateway) and must be passed through to workflow.completed
@@ -89,10 +90,10 @@ class WorkflowOrchestrator {
89
90
  delivery: context?.delivery || cookbookDef?.delivery || { handler: 'none' }
90
91
  };
91
92
 
92
- // Find current step (V2: step_id only)
93
- const step = cookbookDef.steps.find(s => s.step_id === current_step);
93
+ // Find current step (V2: steps is an object keyed by step_id)
94
+ const step = cookbookDef.steps[current_step];
94
95
  if (!step) {
95
- throw new Error(`Step not found: ${current_step}. Available steps: ${cookbookDef.steps.map(s => s.step_id).join(', ')}`);
96
+ throw new Error(`Step not found: ${current_step}. Available steps: ${Object.keys(cookbookDef.steps).join(', ')}`);
96
97
  }
97
98
 
98
99
  // Get step_id (V2)
@@ -131,19 +132,16 @@ class WorkflowOrchestrator {
131
132
 
132
133
  // Update context with result - steps as OBJECT (V2 format, keyed by step_id)
133
134
  // Each step preserves its definition (step_id, type, service, operation, input) and adds output
134
- const currentIndex = cookbookDef.steps.findIndex(s => s.step_id === current_step);
135
- const stepDefinition = cookbookDef.steps[currentIndex];
135
+ const stepDefinition = cookbookDef.steps[current_step];
136
136
 
137
137
  // Initialize steps object from cookbook if not present
138
- // V2: steps is an object keyed by step_id, not an array
138
+ // V2: steps is an object keyed by step_id
139
139
  let existingSteps = enrichedContext.steps || {};
140
140
 
141
141
  // Initialize from cookbook if empty
142
142
  if (Object.keys(existingSteps).length === 0) {
143
- cookbookDef.steps.forEach(s => {
144
- if (s.step_id) {
145
- existingSteps[s.step_id] = { ...s };
146
- }
143
+ Object.entries(cookbookDef.steps).forEach(([key, s]) => {
144
+ existingSteps[key] = { ...s };
147
145
  });
148
146
  }
149
147
 
@@ -175,6 +173,12 @@ class WorkflowOrchestrator {
175
173
  steps: existingSteps // Object keyed by step_id
176
174
  };
177
175
 
176
+ // V2: Get step order from object keys (JavaScript preserves insertion order for string keys)
177
+ const stepKeys = Object.keys(cookbookDef.steps);
178
+ const currentIndex = stepKeys.indexOf(current_step);
179
+ const nextStepKey = stepKeys[currentIndex + 1];
180
+ const nextStep = nextStepKey ? cookbookDef.steps[nextStepKey] : null;
181
+
178
182
  // Publish workflow.progress AFTER execution (so we have step output)
179
183
  const { publishToMonitoringWorkflow } = require('@onlineapps/mq-client-core').monitoring;
180
184
  try {
@@ -201,9 +205,6 @@ class WorkflowOrchestrator {
201
205
  });
202
206
  }
203
207
 
204
- // Find next step (currentIndex already defined above)
205
- const nextStep = cookbookDef.steps[currentIndex + 1];
206
-
207
208
  if (nextStep) {
208
209
  // Route to next step
209
210
  const nextStepId = nextStep.step_id;
@@ -752,22 +753,36 @@ class WorkflowOrchestrator {
752
753
  throw new Error(`FAIL-FAST: Invalid version format '${version}'. Must be 2.x.x (e.g., 2.0.0)`);
753
754
  }
754
755
 
755
- // Check steps
756
- if (!cookbook.steps || !Array.isArray(cookbook.steps) || cookbook.steps.length === 0) {
756
+ // Check steps - V2 FORMAT: steps MUST be an OBJECT (keyed by step_id), NOT an array!
757
+ if (!cookbook.steps || typeof cookbook.steps !== 'object') {
758
+ throw new Error('FAIL-FAST: Cookbook must have steps object');
759
+ }
760
+
761
+ // V1 format (array) is BANNED!
762
+ if (Array.isArray(cookbook.steps)) {
763
+ throw new Error('FAIL-FAST: V1 FORMAT BANNED! Cookbook steps must be an OBJECT (keyed by step_id), NOT an array!');
764
+ }
765
+
766
+ const stepKeys = Object.keys(cookbook.steps);
767
+ if (stepKeys.length === 0) {
757
768
  throw new Error('FAIL-FAST: Cookbook must have at least one step');
758
769
  }
759
770
 
760
771
  // Validate each step has step_id (V2) not id (V1)
761
772
  const invalidSteps = [];
762
- cookbook.steps.forEach((step, index) => {
773
+ stepKeys.forEach((stepKey) => {
774
+ const step = cookbook.steps[stepKey];
763
775
  if (step.id && !step.step_id) {
764
- invalidSteps.push(`Step ${index}: has 'id' (V1) but missing 'step_id' (V2)`);
776
+ invalidSteps.push(`Step '${stepKey}': has 'id' (V1) but missing 'step_id' (V2)`);
765
777
  }
766
778
  if (!step.step_id) {
767
- invalidSteps.push(`Step ${index}: missing required 'step_id'`);
779
+ invalidSteps.push(`Step '${stepKey}': missing required 'step_id'`);
780
+ }
781
+ if (step.step_id !== stepKey) {
782
+ invalidSteps.push(`Step '${stepKey}': step_id '${step.step_id}' does not match key '${stepKey}'`);
768
783
  }
769
784
  if (!step.type) {
770
- invalidSteps.push(`Step ${index} (${step.step_id || 'unknown'}): missing required 'type'`);
785
+ invalidSteps.push(`Step '${stepKey}': missing required 'type'`);
771
786
  }
772
787
  });
773
788
 
@@ -777,7 +792,7 @@ class WorkflowOrchestrator {
777
792
 
778
793
  this.logger.info('[WorkflowOrchestrator] V2 format validation passed', {
779
794
  version: cookbook.version,
780
- steps: cookbook.steps.map(s => s.step_id)
795
+ steps: Object.keys(cookbook.steps)
781
796
  });
782
797
  }
783
798
  }