@onlineapps/service-wrapper 2.0.45 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/service-wrapper",
3
- "version": "2.0.45",
3
+ "version": "2.0.46",
4
4
  "description": "Thin orchestration layer for microservices - delegates all infrastructure concerns to specialized connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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,
@@ -1118,33 +1135,53 @@ class ServiceWrapper {
1118
1135
 
1119
1136
  try {
1120
1137
  // Detailed logging before publish
1121
- this.logger?.info(`[ServiceWrapper] Preparing to publish workflow.completed`, {
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`, {
1122
1147
  workflowId: message.workflow_id,
1123
1148
  service: serviceName,
1124
1149
  operation: workflowResponse.operation,
1125
- mqClientConnected: this.mqClient._connected,
1126
- hasTransport: !!this.mqClient._transport,
1127
- hasChannel: !!(this.mqClient._transport?._channel)
1150
+ queue: 'workflow.completed',
1151
+ ...channelState
1128
1152
  });
1153
+
1154
+ console.log(`[ServiceWrapper] [PUBLISH] Publishing workflow.completed for workflow ${message.workflow_id}`, channelState);
1129
1155
 
1130
1156
  await this.mqClient.publish('workflow.completed', workflowResponse);
1131
1157
 
1132
1158
  // Log success with details
1133
- this.logger?.info(`✓ Workflow response sent to workflow.completed: ${message.workflow_id}`, {
1159
+ this.logger?.info(`[ServiceWrapper] [PUBLISH] ✓ Workflow response sent to workflow.completed: ${message.workflow_id}`, {
1134
1160
  workflowId: message.workflow_id,
1135
1161
  queue: 'workflow.completed',
1136
1162
  responseSize: JSON.stringify(workflowResponse).length
1137
1163
  });
1164
+ console.log(`[ServiceWrapper] [PUBLISH] ✓ Successfully published workflow.completed for ${message.workflow_id}`);
1138
1165
  } catch (error) {
1139
1166
  // Use error handler to log and handle the error
1140
- this.logger?.error(`[ServiceWrapper] Failed to publish workflow.completed`, {
1167
+ const errorContext = {
1141
1168
  workflowId: message.workflow_id,
1142
1169
  queue: 'workflow.completed',
1143
1170
  error: error.message,
1144
1171
  errorStack: error.stack,
1145
1172
  mqClientConnected: this.mqClient?._connected,
1146
1173
  hasTransport: !!this.mqClient?._transport,
1147
- 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
1148
1185
  });
1149
1186
 
1150
1187
  if (this.errorHandler) {