@onlineapps/service-wrapper 2.0.16 → 2.0.18
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/README.md +1 -1
- package/package.json +1 -1
- package/src/ServiceWrapper.js +34 -7
package/README.md
CHANGED
|
@@ -239,7 +239,7 @@ describe('My Service', () => {
|
|
|
239
239
|
If your service currently has workflow code:
|
|
240
240
|
|
|
241
241
|
1. Install service-wrapper: `npm install @onlineapps/service-wrapper`
|
|
242
|
-
2. Remove all
|
|
242
|
+
2. Remove all direct connector imports from service code (use wrapper instead)
|
|
243
243
|
3. Delete workflow processing files
|
|
244
244
|
4. Wrap your Express app with ServiceWrapper
|
|
245
245
|
5. Test that everything still works
|
package/package.json
CHANGED
package/src/ServiceWrapper.js
CHANGED
|
@@ -460,9 +460,16 @@ class ServiceWrapper {
|
|
|
460
460
|
message = rawMessage;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
+
// Extract and normalize flags
|
|
464
|
+
const flags = Array.isArray(message.flags) ? message.flags : [];
|
|
465
|
+
const isTest = flags.includes('test');
|
|
466
|
+
const isTier2Validation = flags.includes('tier2-validation');
|
|
467
|
+
|
|
463
468
|
console.log(`Processing message from ${queueName}:`, {
|
|
464
469
|
workflow_id: message.workflow_id,
|
|
465
|
-
step: message.step?.operation || message.operation
|
|
470
|
+
step: message.step?.operation || message.operation,
|
|
471
|
+
flags,
|
|
472
|
+
isTest
|
|
466
473
|
});
|
|
467
474
|
|
|
468
475
|
// Check if this message is for our service
|
|
@@ -473,22 +480,42 @@ class ServiceWrapper {
|
|
|
473
480
|
}
|
|
474
481
|
|
|
475
482
|
// Process based on message type
|
|
483
|
+
let result;
|
|
476
484
|
if (message.operation && this.operations?.operations?.[message.operation]) {
|
|
477
485
|
// Direct operation call
|
|
478
|
-
|
|
479
|
-
return result;
|
|
486
|
+
result = await this._executeOperation(message.operation, message.input || {});
|
|
480
487
|
} else if (message.step?.operation && this.operations?.operations?.[message.step.operation]) {
|
|
481
488
|
// Workflow step
|
|
482
|
-
|
|
483
|
-
return result;
|
|
489
|
+
result = await this._executeOperation(message.step.operation, message.input || {});
|
|
484
490
|
} else if (this.orchestrator) {
|
|
485
491
|
// Delegate to orchestrator for complex workflow processing
|
|
486
|
-
|
|
487
|
-
return result;
|
|
492
|
+
result = await this.orchestrator.processWorkflowMessage(message, serviceName);
|
|
488
493
|
} else {
|
|
489
494
|
throw new Error(`Unknown message format or operation: ${JSON.stringify(message)}`);
|
|
490
495
|
}
|
|
491
496
|
|
|
497
|
+
// Send response to workflow.completed if workflow_id is present
|
|
498
|
+
if (message.workflow_id && this.mqClient) {
|
|
499
|
+
const workflowResponse = {
|
|
500
|
+
workflow_id: message.workflow_id,
|
|
501
|
+
service: serviceName,
|
|
502
|
+
operation: message.step?.operation || message.operation,
|
|
503
|
+
status: 'completed',
|
|
504
|
+
output: result,
|
|
505
|
+
flags,
|
|
506
|
+
timestamp: new Date().toISOString()
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
try {
|
|
510
|
+
await this.mqClient.publish('workflow.completed', workflowResponse);
|
|
511
|
+
console.log(`✓ Workflow response sent to workflow.completed: ${message.workflow_id}`);
|
|
512
|
+
} catch (error) {
|
|
513
|
+
console.error(`Failed to send workflow response:`, error);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
return result;
|
|
518
|
+
|
|
492
519
|
} catch (error) {
|
|
493
520
|
console.error(`Error processing message from ${queueName}:`, error);
|
|
494
521
|
throw error;
|