@onlineapps/conn-orch-orchestrator 1.0.20 → 1.0.22
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 +1 -1
- package/src/WorkflowOrchestrator.js +53 -8
package/package.json
CHANGED
|
@@ -303,7 +303,9 @@ class WorkflowOrchestrator {
|
|
|
303
303
|
|
|
304
304
|
/**
|
|
305
305
|
* Resolve variable references in input object
|
|
306
|
-
* Supports
|
|
306
|
+
* Supports both syntaxes:
|
|
307
|
+
* - {{steps.step_id.output.field}}, {{api_input.field}} (preferred, V2)
|
|
308
|
+
* - ${steps[N].output.field}, ${api_input.field} (legacy)
|
|
307
309
|
* @private
|
|
308
310
|
* @param {Object} input - Input object with potential references
|
|
309
311
|
* @param {Object} context - Current context with steps, api_input, etc
|
|
@@ -313,12 +315,39 @@ class WorkflowOrchestrator {
|
|
|
313
315
|
if (!input) return input;
|
|
314
316
|
|
|
315
317
|
const resolveValue = (value) => {
|
|
316
|
-
if (typeof value === 'string'
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
if (typeof value === 'string') {
|
|
319
|
+
let result = value;
|
|
320
|
+
|
|
321
|
+
// Replace {{...}} references (V2 preferred syntax)
|
|
322
|
+
if (result.includes('{{')) {
|
|
323
|
+
result = result.replace(/\{\{([^}]+)\}\}/g, (match, path) => {
|
|
324
|
+
const resolved = this._getValueFromPath(path.trim(), context);
|
|
325
|
+
if (resolved !== undefined) {
|
|
326
|
+
// If resolved value is an object, stringify it for embedding in strings
|
|
327
|
+
if (typeof resolved === 'object' && result !== match) {
|
|
328
|
+
return JSON.stringify(resolved);
|
|
329
|
+
}
|
|
330
|
+
return resolved;
|
|
331
|
+
}
|
|
332
|
+
return match;
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Replace ${...} references (legacy syntax)
|
|
337
|
+
if (result.includes('${')) {
|
|
338
|
+
result = result.replace(/\$\{([^}]+)\}/g, (match, path) => {
|
|
339
|
+
const resolved = this._getValueFromPath(path.trim(), context);
|
|
340
|
+
if (resolved !== undefined) {
|
|
341
|
+
if (typeof resolved === 'object' && result !== match) {
|
|
342
|
+
return JSON.stringify(resolved);
|
|
343
|
+
}
|
|
344
|
+
return resolved;
|
|
345
|
+
}
|
|
346
|
+
return match;
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
return result;
|
|
322
351
|
}
|
|
323
352
|
if (Array.isArray(value)) {
|
|
324
353
|
return value.map(resolveValue);
|
|
@@ -488,6 +517,21 @@ class WorkflowOrchestrator {
|
|
|
488
517
|
// Delivery Dispatcher requires: workflow_id, status, delivery (must be object, not null)
|
|
489
518
|
const delivery = finalContext?.delivery || cookbookDef?.delivery || { handler: 'none' };
|
|
490
519
|
|
|
520
|
+
// Extract api_output from the last completed step
|
|
521
|
+
// steps is an object keyed by step_id in V2
|
|
522
|
+
let api_output = null;
|
|
523
|
+
if (lastStepId && finalContext?.steps?.[lastStepId]?.output) {
|
|
524
|
+
api_output = finalContext.steps[lastStepId].output;
|
|
525
|
+
} else if (finalContext?.steps) {
|
|
526
|
+
// Fallback: find any step with output
|
|
527
|
+
const stepKeys = Object.keys(finalContext.steps);
|
|
528
|
+
for (const key of stepKeys) {
|
|
529
|
+
if (finalContext.steps[key]?.output) {
|
|
530
|
+
api_output = finalContext.steps[key].output;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
491
535
|
// Build message in format expected by Delivery Dispatcher
|
|
492
536
|
const workflowCompletedMessage = {
|
|
493
537
|
workflow_id,
|
|
@@ -495,10 +539,11 @@ class WorkflowOrchestrator {
|
|
|
495
539
|
service: serviceName, // Service that completed the workflow (for monitoring)
|
|
496
540
|
step_id: lastStepId, // Last step ID for monitoring
|
|
497
541
|
step_index: lastStepIndex, // Last step index for monitoring
|
|
542
|
+
api_output: api_output, // Output from last step - for frontend/delivery
|
|
498
543
|
cookbook: cookbookDef, // Full cookbook for monitoring trace
|
|
499
544
|
delivery: delivery, // Delivery configuration from Gateway context (must be object)
|
|
500
545
|
context: finalContext, // Full context for output resolution
|
|
501
|
-
steps: finalContext?.steps ||
|
|
546
|
+
steps: finalContext?.steps || {}, // Steps results (object) for output resolution
|
|
502
547
|
completed_at: new Date().toISOString()
|
|
503
548
|
};
|
|
504
549
|
|