@onlineapps/conn-orch-orchestrator 1.0.33 → 1.0.34

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.33",
3
+ "version": "1.0.34",
4
4
  "description": "Workflow orchestration connector for OA Drive - handles message routing and workflow execution",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -61,6 +61,25 @@ class WorkflowOrchestrator {
61
61
  return step?.step_id || step?.id;
62
62
  }
63
63
 
64
+ /**
65
+ * Get steps as array (supports both V1 array and V2 object formats)
66
+ * V2 FORMAT: steps is an object keyed by step_id
67
+ * V1 FORMAT (deprecated): steps is an array
68
+ * @private
69
+ * @param {Object} cookbookDef - Cookbook definition
70
+ * @returns {Array} Array of step objects
71
+ */
72
+ _getStepsArray(cookbookDef) {
73
+ if (!cookbookDef?.steps) return [];
74
+ if (Array.isArray(cookbookDef.steps)) {
75
+ // V1 format (deprecated) - steps is already an array
76
+ this.logger.warn('Using deprecated V1 cookbook format (steps as array). Please migrate to V2 (steps as object).');
77
+ return cookbookDef.steps;
78
+ }
79
+ // V2 format - steps is an object keyed by step_id
80
+ return Object.values(cookbookDef.steps);
81
+ }
82
+
64
83
  /**
65
84
  * Process a workflow message
66
85
  * @async
@@ -97,7 +116,9 @@ class WorkflowOrchestrator {
97
116
  };
98
117
 
99
118
  // Find current step (supports both V1 'id' and V2 'step_id')
100
- const step = cookbookDef.steps.find(s => this._getStepId(s) === current_step);
119
+ // V2 FORMAT: steps is an object keyed by step_id
120
+ const stepsArray = this._getStepsArray(cookbookDef);
121
+ const step = stepsArray.find(s => this._getStepId(s) === current_step);
101
122
  if (!step) {
102
123
  throw new Error(`Step not found: ${current_step}`);
103
124
  }
@@ -135,13 +156,14 @@ class WorkflowOrchestrator {
135
156
 
136
157
  // Update context with result - steps as ARRAY (consistent with cookbook.steps)
137
158
  // Each step preserves its definition (id/step_id, type, service, operation, input) and adds output
138
- const currentIndex = cookbookDef.steps.findIndex(s => this._getStepId(s) === current_step);
139
- const stepDefinition = cookbookDef.steps[currentIndex];
159
+ // stepsArray is already defined above via _getStepsArray()
160
+ const currentIndex = stepsArray.findIndex(s => this._getStepId(s) === current_step);
161
+ const stepDefinition = stepsArray[currentIndex];
140
162
 
141
163
  // Initialize steps array from cookbook if not present
142
164
  const existingSteps = Array.isArray(enrichedContext.steps)
143
165
  ? [...enrichedContext.steps]
144
- : cookbookDef.steps.map(s => ({ ...s })); // Deep copy of step definitions
166
+ : stepsArray.map(s => ({ ...s })); // Deep copy of step definitions
145
167
 
146
168
  // Update the current step with output (preserve id, type, service, operation, input)
147
169
  existingSteps[currentIndex] = {
@@ -182,8 +204,8 @@ class WorkflowOrchestrator {
182
204
  });
183
205
  }
184
206
 
185
- // Find next step (currentIndex already defined above)
186
- const nextStep = cookbookDef.steps[currentIndex + 1];
207
+ // Find next step (currentIndex and stepsArray already defined above)
208
+ const nextStep = stepsArray[currentIndex + 1];
187
209
 
188
210
  if (nextStep) {
189
211
  // Route to next step