@onlineapps/service-wrapper 2.0.44 → 2.0.46
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/ServiceWrapper.js +49 -7
package/package.json
CHANGED
package/src/ServiceWrapper.js
CHANGED
|
@@ -1082,12 +1082,29 @@ class ServiceWrapper {
|
|
|
1082
1082
|
result = await this._executeOperation(message.step.operation, message.input || {});
|
|
1083
1083
|
} else if (this.orchestrator) {
|
|
1084
1084
|
// Delegate to orchestrator for complex workflow processing
|
|
1085
|
+
// Validate required fields before processing
|
|
1086
|
+
if (!message.workflow_id && !message.workflowId) {
|
|
1087
|
+
throw new Error('Workflow message must have workflow_id or workflowId field');
|
|
1088
|
+
}
|
|
1089
|
+
if (!message.current_step && (!message.cookbook?.steps || message.cookbook.steps.length === 0)) {
|
|
1090
|
+
throw new Error('Workflow message must have current_step field or cookbook with at least one step');
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1085
1093
|
// Normalize message format: Gateway sends workflowId, orchestrator expects workflow_id
|
|
1086
1094
|
const normalizedMessage = {
|
|
1087
1095
|
...message,
|
|
1088
1096
|
workflow_id: message.workflow_id || message.workflowId,
|
|
1089
1097
|
current_step: message.current_step || (message.cookbook?.steps?.[0]?.id)
|
|
1090
1098
|
};
|
|
1099
|
+
|
|
1100
|
+
// Validate normalized message has required fields
|
|
1101
|
+
if (!normalizedMessage.workflow_id) {
|
|
1102
|
+
throw new Error('Failed to normalize workflow_id: message must have workflow_id or workflowId');
|
|
1103
|
+
}
|
|
1104
|
+
if (!normalizedMessage.current_step) {
|
|
1105
|
+
throw new Error('Failed to normalize current_step: message must have current_step or cookbook with steps');
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1091
1108
|
this.logger?.info(`[ServiceWrapper] Calling orchestrator.processWorkflowMessage`, {
|
|
1092
1109
|
workflow_id: normalizedMessage.workflow_id,
|
|
1093
1110
|
current_step: normalizedMessage.current_step,
|
|
@@ -1101,45 +1118,70 @@ class ServiceWrapper {
|
|
|
1101
1118
|
|
|
1102
1119
|
// Send response to workflow.completed if workflow_id is present
|
|
1103
1120
|
if (message.workflow_id && this.mqClient) {
|
|
1121
|
+
// Extract delivery configuration from context (passed from Gateway)
|
|
1122
|
+
// Delivery can specify how to deliver the result (webhook, email, etc.)
|
|
1123
|
+
const delivery = message.context?.delivery || null;
|
|
1124
|
+
|
|
1104
1125
|
const workflowResponse = {
|
|
1105
1126
|
workflow_id: message.workflow_id,
|
|
1106
1127
|
service: serviceName,
|
|
1107
1128
|
operation: message.step?.operation || message.operation,
|
|
1108
1129
|
status: 'completed',
|
|
1109
1130
|
output: result,
|
|
1131
|
+
delivery: delivery, // Delivery configuration from Gateway context
|
|
1110
1132
|
flags,
|
|
1111
1133
|
timestamp: new Date().toISOString()
|
|
1112
1134
|
};
|
|
1113
1135
|
|
|
1114
1136
|
try {
|
|
1115
1137
|
// Detailed logging before publish
|
|
1116
|
-
|
|
1138
|
+
const channelState = {
|
|
1139
|
+
mqClientConnected: this.mqClient?._connected,
|
|
1140
|
+
hasTransport: !!this.mqClient?._transport,
|
|
1141
|
+
hasChannel: !!(this.mqClient?._transport?._channel),
|
|
1142
|
+
channelClosed: this.mqClient?._transport?._channel?.closed,
|
|
1143
|
+
hasConnection: !!(this.mqClient?._transport?._connection && !this.mqClient._transport._connection.closed)
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
this.logger?.info(`[ServiceWrapper] [PUBLISH] Preparing to publish workflow.completed`, {
|
|
1117
1147
|
workflowId: message.workflow_id,
|
|
1118
1148
|
service: serviceName,
|
|
1119
1149
|
operation: workflowResponse.operation,
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
hasChannel: !!(this.mqClient._transport?._channel)
|
|
1150
|
+
queue: 'workflow.completed',
|
|
1151
|
+
...channelState
|
|
1123
1152
|
});
|
|
1153
|
+
|
|
1154
|
+
console.log(`[ServiceWrapper] [PUBLISH] Publishing workflow.completed for workflow ${message.workflow_id}`, channelState);
|
|
1124
1155
|
|
|
1125
1156
|
await this.mqClient.publish('workflow.completed', workflowResponse);
|
|
1126
1157
|
|
|
1127
1158
|
// Log success with details
|
|
1128
|
-
this.logger?.info(
|
|
1159
|
+
this.logger?.info(`[ServiceWrapper] [PUBLISH] ✓ Workflow response sent to workflow.completed: ${message.workflow_id}`, {
|
|
1129
1160
|
workflowId: message.workflow_id,
|
|
1130
1161
|
queue: 'workflow.completed',
|
|
1131
1162
|
responseSize: JSON.stringify(workflowResponse).length
|
|
1132
1163
|
});
|
|
1164
|
+
console.log(`[ServiceWrapper] [PUBLISH] ✓ Successfully published workflow.completed for ${message.workflow_id}`);
|
|
1133
1165
|
} catch (error) {
|
|
1134
1166
|
// Use error handler to log and handle the error
|
|
1135
|
-
|
|
1167
|
+
const errorContext = {
|
|
1136
1168
|
workflowId: message.workflow_id,
|
|
1137
1169
|
queue: 'workflow.completed',
|
|
1138
1170
|
error: error.message,
|
|
1139
1171
|
errorStack: error.stack,
|
|
1140
1172
|
mqClientConnected: this.mqClient?._connected,
|
|
1141
1173
|
hasTransport: !!this.mqClient?._transport,
|
|
1142
|
-
hasChannel: !!(this.mqClient?._transport?._channel)
|
|
1174
|
+
hasChannel: !!(this.mqClient?._transport?._channel),
|
|
1175
|
+
channelClosed: this.mqClient?._transport?._channel?.closed,
|
|
1176
|
+
hasConnection: !!(this.mqClient?._transport?._connection && !this.mqClient._transport._connection.closed)
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
this.logger?.error(`[ServiceWrapper] [PUBLISH] ✗ Failed to publish workflow.completed`, errorContext);
|
|
1180
|
+
console.error(`[ServiceWrapper] [PUBLISH] ✗ Failed to publish workflow.completed for ${message.workflow_id}:`, error.message);
|
|
1181
|
+
console.error(`[ServiceWrapper] [PUBLISH] Channel state:`, {
|
|
1182
|
+
hasChannel: errorContext.hasChannel,
|
|
1183
|
+
channelClosed: errorContext.channelClosed,
|
|
1184
|
+
hasConnection: errorContext.hasConnection
|
|
1143
1185
|
});
|
|
1144
1186
|
|
|
1145
1187
|
if (this.errorHandler) {
|