@dynamatix/gb-schemas 2.3.370 → 2.3.371
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/dist/shared/workflow.init.d.ts.map +1 -1
- package/dist/shared/workflow.init.js +5 -4
- package/dist/shared/workflow.logger.d.ts +18 -0
- package/dist/shared/workflow.logger.d.ts.map +1 -0
- package/dist/shared/workflow.logger.js +41 -0
- package/dist/shared/workflow.middleware.d.ts.map +1 -1
- package/dist/shared/workflow.middleware.js +24 -23
- package/dist/shared/workflow.plugin.d.ts.map +1 -1
- package/dist/shared/workflow.plugin.js +15 -14
- package/dist/shared/workflow.service.d.ts.map +1 -1
- package/dist/shared/workflow.service.js +7 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.init.d.ts","sourceRoot":"","sources":["../../shared/workflow.init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"workflow.init.d.ts","sourceRoot":"","sources":["../../shared/workflow.init.ts"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,wBAAgB,4BAA4B,SAI3C;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,IAAI,OAAO,CAUxD;AAED;;;GAGG;AACH,wBAAgB,qCAAqC,CAAC,OAAO,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAE,WAQ5F"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import dotenv from 'dotenv';
|
|
2
2
|
import { registerWorkflowPlugin } from './workflow.plugin.js';
|
|
3
|
+
import { workflowLog, workflowWarn } from './workflow.logger.js';
|
|
3
4
|
// Load environment variables from .env file
|
|
4
5
|
dotenv.config();
|
|
5
6
|
/**
|
|
@@ -10,9 +11,9 @@ dotenv.config();
|
|
|
10
11
|
* The record type will be inferred from the model name (e.g., 'Application' -> 'applications')
|
|
11
12
|
*/
|
|
12
13
|
export function initializeWorkflowMiddleware() {
|
|
13
|
-
|
|
14
|
+
workflowLog('Initializing workflow middleware for all schemas...');
|
|
14
15
|
registerWorkflowPlugin();
|
|
15
|
-
|
|
16
|
+
workflowLog('Workflow middleware initialized successfully');
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
* Check if workflow middleware is properly configured
|
|
@@ -22,7 +23,7 @@ export function isWorkflowMiddlewareConfigured() {
|
|
|
22
23
|
const requiredEnvVars = ['WORKFLOW_API_KEY'];
|
|
23
24
|
const missingVars = requiredEnvVars.filter(varName => !process.env[varName]);
|
|
24
25
|
if (missingVars.length > 0) {
|
|
25
|
-
|
|
26
|
+
workflowWarn(`Missing required environment variables for workflow middleware: ${missingVars.join(', ')}`);
|
|
26
27
|
return false;
|
|
27
28
|
}
|
|
28
29
|
return true;
|
|
@@ -33,7 +34,7 @@ export function isWorkflowMiddlewareConfigured() {
|
|
|
33
34
|
*/
|
|
34
35
|
export function initializeWorkflowMiddlewareWithCheck(options) {
|
|
35
36
|
if (!options?.skipConfigCheck && !isWorkflowMiddlewareConfigured()) {
|
|
36
|
-
|
|
37
|
+
workflowWarn('Workflow middleware configuration incomplete. Middleware will be disabled.');
|
|
37
38
|
return false;
|
|
38
39
|
}
|
|
39
40
|
initializeWorkflowMiddleware();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for workflow engine logging
|
|
3
|
+
* Logs are controlled by the SHOW_WORKFLOW_ENGINE_LOGS environment variable
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Conditional console.log that only logs if SHOW_WORKFLOW_ENGINE_LOGS is enabled
|
|
7
|
+
*/
|
|
8
|
+
export declare function workflowLog(...args: any[]): void;
|
|
9
|
+
/**
|
|
10
|
+
* Conditional console.warn that only logs if SHOW_WORKFLOW_ENGINE_LOGS is enabled
|
|
11
|
+
*/
|
|
12
|
+
export declare function workflowWarn(...args: any[]): void;
|
|
13
|
+
/**
|
|
14
|
+
* Conditional console.error that only logs if SHOW_WORKFLOW_ENGINE_LOGS is enabled
|
|
15
|
+
* Note: Error logs might be important, but we'll respect the flag for consistency
|
|
16
|
+
*/
|
|
17
|
+
export declare function workflowError(...args: any[]): void;
|
|
18
|
+
//# sourceMappingURL=workflow.logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow.logger.d.ts","sourceRoot":"","sources":["../../shared/workflow.logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAIhD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAIjD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAIlD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for workflow engine logging
|
|
3
|
+
* Logs are controlled by the SHOW_WORKFLOW_ENGINE_LOGS environment variable
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Checks if workflow engine logs should be displayed
|
|
7
|
+
* @returns true if SHOW_WORKFLOW_ENGINE_LOGS is set to a truthy value
|
|
8
|
+
*/
|
|
9
|
+
function shouldShowLogs() {
|
|
10
|
+
const envValue = process.env.SHOW_WORKFLOW_ENGINE_LOGS;
|
|
11
|
+
if (!envValue)
|
|
12
|
+
return false;
|
|
13
|
+
// Check for truthy string values
|
|
14
|
+
const normalizedValue = envValue.toLowerCase().trim();
|
|
15
|
+
return normalizedValue === 'true' || normalizedValue === '1' || normalizedValue === 'yes';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Conditional console.log that only logs if SHOW_WORKFLOW_ENGINE_LOGS is enabled
|
|
19
|
+
*/
|
|
20
|
+
export function workflowLog(...args) {
|
|
21
|
+
if (shouldShowLogs()) {
|
|
22
|
+
console.log(...args);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Conditional console.warn that only logs if SHOW_WORKFLOW_ENGINE_LOGS is enabled
|
|
27
|
+
*/
|
|
28
|
+
export function workflowWarn(...args) {
|
|
29
|
+
if (shouldShowLogs()) {
|
|
30
|
+
console.warn(...args);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Conditional console.error that only logs if SHOW_WORKFLOW_ENGINE_LOGS is enabled
|
|
35
|
+
* Note: Error logs might be important, but we'll respect the flag for consistency
|
|
36
|
+
*/
|
|
37
|
+
export function workflowError(...args) {
|
|
38
|
+
if (shouldShowLogs()) {
|
|
39
|
+
console.error(...args);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.middleware.d.ts","sourceRoot":"","sources":["../../shared/workflow.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAGhC,OAAO,EACH,oBAAoB,EAEpB,yBAAyB,EAC5B,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"workflow.middleware.d.ts","sourceRoot":"","sources":["../../shared/workflow.middleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAGhC,OAAO,EACH,oBAAoB,EAEpB,yBAAyB,EAC5B,MAAM,4BAA4B,CAAC;AAKpC,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,OAAO,CAA4B;gBAE/B,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC;IAYxD;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAS/B;;;OAGG;IACH,UAAU;;;IAMV;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM;yBAGK,GAAG,OAAO,GAAG,QAAQ,QAAQ;2BAiB3B,GAAG,OAAO,GAAG,QAAQ,QAAQ;;IAkBvE;;;;OAIG;IACG,WAAW,CAAC,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B5E;;;;;OAKG;YACW,cAAc;IAqD5B;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAavB;;;;;OAKG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS5F;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC;;;EAGxG;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,QAShI"}
|
|
@@ -2,6 +2,7 @@ import WorkflowTriggerModel from './workflow-trigger.model.js';
|
|
|
2
2
|
import { WorkflowService } from './workflow.service.js';
|
|
3
3
|
// @ts-ignore - No type declarations available for @dynamatix/cat-shared/services
|
|
4
4
|
import { getContext as getSharedContext } from '@dynamatix/cat-shared/services';
|
|
5
|
+
import { workflowLog, workflowWarn, workflowError } from './workflow.logger.js';
|
|
5
6
|
export class WorkflowMiddleware {
|
|
6
7
|
constructor(options) {
|
|
7
8
|
// Read configuration from environment variables with fallbacks
|
|
@@ -22,7 +23,7 @@ export class WorkflowMiddleware {
|
|
|
22
23
|
return WorkflowTriggerModel;
|
|
23
24
|
}
|
|
24
25
|
catch (error) {
|
|
25
|
-
|
|
26
|
+
workflowError('Error accessing WorkflowTrigger model:', error);
|
|
26
27
|
throw new Error('WorkflowTrigger model is not properly registered');
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -47,7 +48,7 @@ export class WorkflowMiddleware {
|
|
|
47
48
|
// Post-save middleware for create and update operations
|
|
48
49
|
postSave: async function (doc, next) {
|
|
49
50
|
try {
|
|
50
|
-
|
|
51
|
+
workflowLog('Post-save middleware for create and update operations');
|
|
51
52
|
const middleware = new WorkflowMiddleware(this.options || {});
|
|
52
53
|
await middleware.handleEvent({
|
|
53
54
|
recordType,
|
|
@@ -56,7 +57,7 @@ export class WorkflowMiddleware {
|
|
|
56
57
|
}, doc);
|
|
57
58
|
}
|
|
58
59
|
catch (error) {
|
|
59
|
-
|
|
60
|
+
workflowError('Workflow middleware error:', error);
|
|
60
61
|
// Don't throw error to avoid breaking the main operation
|
|
61
62
|
}
|
|
62
63
|
next();
|
|
@@ -64,7 +65,7 @@ export class WorkflowMiddleware {
|
|
|
64
65
|
// Post-remove middleware for delete operations
|
|
65
66
|
postRemove: async function (doc, next) {
|
|
66
67
|
try {
|
|
67
|
-
|
|
68
|
+
workflowLog('Post-remove middleware for delete operations');
|
|
68
69
|
const middleware = new WorkflowMiddleware(this.options || {});
|
|
69
70
|
await middleware.handleEvent({
|
|
70
71
|
recordType,
|
|
@@ -73,7 +74,7 @@ export class WorkflowMiddleware {
|
|
|
73
74
|
}, doc);
|
|
74
75
|
}
|
|
75
76
|
catch (error) {
|
|
76
|
-
|
|
77
|
+
workflowError('Workflow middleware error:', error);
|
|
77
78
|
// Don't throw error to avoid breaking the main operation
|
|
78
79
|
}
|
|
79
80
|
next();
|
|
@@ -88,24 +89,24 @@ export class WorkflowMiddleware {
|
|
|
88
89
|
async handleEvent(event, document) {
|
|
89
90
|
try {
|
|
90
91
|
// Find active triggers for this event
|
|
91
|
-
|
|
92
|
+
workflowLog('Finding active triggers for this event');
|
|
92
93
|
const WorkflowTrigger = this.getWorkflowTriggerModel();
|
|
93
94
|
const triggers = await WorkflowTrigger.find({
|
|
94
95
|
triggerKey: event.triggerKey,
|
|
95
96
|
isActive: true
|
|
96
97
|
});
|
|
97
98
|
if (triggers.length === 0) {
|
|
98
|
-
|
|
99
|
+
workflowLog(`No active triggers found for ${event.triggerKey}`);
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
// Process each trigger
|
|
102
|
-
|
|
103
|
+
workflowLog('Processing each trigger');
|
|
103
104
|
for (const trigger of triggers) {
|
|
104
105
|
await this.processTrigger(trigger, document, event);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
catch (error) {
|
|
108
|
-
|
|
109
|
+
workflowError(`Error handling workflow event ${event.triggerKey}:`, error);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
@@ -116,28 +117,28 @@ export class WorkflowMiddleware {
|
|
|
116
117
|
*/
|
|
117
118
|
async processTrigger(trigger, document, event) {
|
|
118
119
|
try {
|
|
119
|
-
|
|
120
|
+
workflowLog('Processing trigger');
|
|
120
121
|
// Check if condition is met (if specified)
|
|
121
122
|
if (trigger.condition && !this.evaluateCondition(trigger.condition, document)) {
|
|
122
|
-
|
|
123
|
+
workflowLog(`Condition not met for trigger ${trigger.triggerKey}`);
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
126
|
// Extract variables from document
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
workflowLog('Extracting variables from document');
|
|
128
|
+
workflowLog(` Required variables: ${JSON.stringify(trigger.requiredVariables)}`);
|
|
129
|
+
workflowLog(` Optional variables: ${JSON.stringify(trigger.optionalVariables || [])}`);
|
|
129
130
|
const variables = this.workflowService.extractVariables(trigger.requiredVariables, trigger.optionalVariables || [], document);
|
|
130
|
-
|
|
131
|
+
workflowLog(` Extracted variables: ${JSON.stringify(variables, null, 2)}`);
|
|
131
132
|
// Validate required variables
|
|
132
133
|
if (!this.workflowService.validateRequiredVariables(trigger.requiredVariables, variables)) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
workflowWarn(`❌ Required variables missing for trigger ${trigger.triggerKey}`);
|
|
135
|
+
workflowWarn(` Required: ${JSON.stringify(trigger.requiredVariables)}`);
|
|
136
|
+
workflowWarn(` Got: ${JSON.stringify(variables)}`);
|
|
136
137
|
return;
|
|
137
138
|
}
|
|
138
139
|
// Add metadata
|
|
139
140
|
const metadata = this.extractMetadata(document, event, trigger.parentKey);
|
|
140
|
-
|
|
141
|
+
workflowLog(` Metadata: ${JSON.stringify(metadata, null, 2)}`);
|
|
141
142
|
const enrichedVariables = {
|
|
142
143
|
...variables,
|
|
143
144
|
...metadata
|
|
@@ -148,13 +149,13 @@ export class WorkflowMiddleware {
|
|
|
148
149
|
version: 1, // Default version, could be made configurable
|
|
149
150
|
variables: enrichedVariables
|
|
150
151
|
};
|
|
151
|
-
|
|
152
|
+
workflowLog('📦 Workflow payload:', JSON.stringify(payload, null, 2));
|
|
152
153
|
// Trigger workflow in background
|
|
153
154
|
await this.workflowService.triggerWorkflow(payload);
|
|
154
|
-
|
|
155
|
+
workflowLog(`Workflow ${trigger.workflowKey} triggered for ${event.triggerKey}`);
|
|
155
156
|
}
|
|
156
157
|
catch (error) {
|
|
157
|
-
|
|
158
|
+
workflowError(`Error processing trigger ${trigger.triggerKey}:`, error);
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
/**
|
|
@@ -176,7 +177,7 @@ export class WorkflowMiddleware {
|
|
|
176
177
|
return true;
|
|
177
178
|
}
|
|
178
179
|
catch (error) {
|
|
179
|
-
|
|
180
|
+
workflowError('Error evaluating condition:', error);
|
|
180
181
|
return false;
|
|
181
182
|
}
|
|
182
183
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.plugin.d.ts","sourceRoot":"","sources":["../../shared/workflow.plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"workflow.plugin.d.ts","sourceRoot":"","sources":["../../shared/workflow.plugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,QAyGnE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,SAGrC;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,QAE9E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import mongoose from 'mongoose';
|
|
2
2
|
import { WorkflowMiddleware } from './workflow.middleware.js';
|
|
3
|
+
import { workflowLog, workflowError } from './workflow.logger.js';
|
|
3
4
|
/**
|
|
4
5
|
* Workflow plugin that automatically applies workflow middleware to schemas
|
|
5
6
|
* This plugin reads the record type from schema options and applies the appropriate middleware
|
|
@@ -7,17 +8,17 @@ import { WorkflowMiddleware } from './workflow.middleware.js';
|
|
|
7
8
|
export function workflowPlugin(schema, options) {
|
|
8
9
|
// For global plugins, we'll determine the record type when the middleware is triggered
|
|
9
10
|
// by looking at the document's constructor name
|
|
10
|
-
|
|
11
|
+
workflowLog(`🔌 Workflow plugin applied to schema`);
|
|
11
12
|
// Create workflow middleware instance
|
|
12
13
|
const middleware = new WorkflowMiddleware();
|
|
13
14
|
// Apply post-save middleware
|
|
14
15
|
schema.post('save', async function (doc, next) {
|
|
15
16
|
// Determine record type from document constructor name
|
|
16
17
|
const recordType = doc.constructor.modelName?.toLowerCase() || 'unknown';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
workflowLog(`💾 Post-save middleware triggered for ${recordType}`);
|
|
19
|
+
workflowLog(` Document ID: ${doc._id}`);
|
|
20
|
+
workflowLog(` Is new: ${doc.isNew}`);
|
|
21
|
+
workflowLog(` Trigger key: ${recordType}.${doc.isNew ? 'created' : 'updated'}`);
|
|
21
22
|
try {
|
|
22
23
|
await middleware.handleEvent({
|
|
23
24
|
recordType,
|
|
@@ -26,7 +27,7 @@ export function workflowPlugin(schema, options) {
|
|
|
26
27
|
}, doc);
|
|
27
28
|
}
|
|
28
29
|
catch (error) {
|
|
29
|
-
|
|
30
|
+
workflowError('Workflow middleware error:', error);
|
|
30
31
|
// Don't throw error to avoid breaking the main operation
|
|
31
32
|
}
|
|
32
33
|
next();
|
|
@@ -34,9 +35,9 @@ export function workflowPlugin(schema, options) {
|
|
|
34
35
|
// Apply post-findOneAndUpdate middleware
|
|
35
36
|
schema.post('findOneAndUpdate', async function (doc, next) {
|
|
36
37
|
const recordType = doc.constructor.modelName?.toLowerCase() || 'unknown';
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
workflowLog(`🔄 Post-findOneAndUpdate middleware triggered for ${recordType}`);
|
|
39
|
+
workflowLog(` Document ID: ${doc._id}`);
|
|
40
|
+
workflowLog(` Trigger key: ${recordType}.updated`);
|
|
40
41
|
try {
|
|
41
42
|
await middleware.handleEvent({
|
|
42
43
|
recordType,
|
|
@@ -45,7 +46,7 @@ export function workflowPlugin(schema, options) {
|
|
|
45
46
|
}, doc);
|
|
46
47
|
}
|
|
47
48
|
catch (error) {
|
|
48
|
-
|
|
49
|
+
workflowError('Workflow middleware error:', error);
|
|
49
50
|
// Don't throw error to avoid breaking the main operation
|
|
50
51
|
}
|
|
51
52
|
next();
|
|
@@ -72,7 +73,7 @@ export function workflowPlugin(schema, options) {
|
|
|
72
73
|
else if (result?.constructor?.modelName) {
|
|
73
74
|
recordType = result.constructor.modelName.toLowerCase();
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
workflowLog(`🗑️ Post-delete middleware triggered for ${recordType}`);
|
|
76
77
|
try {
|
|
77
78
|
await middleware.handleEvent({
|
|
78
79
|
recordType,
|
|
@@ -81,14 +82,14 @@ export function workflowPlugin(schema, options) {
|
|
|
81
82
|
}, result);
|
|
82
83
|
}
|
|
83
84
|
catch (error) {
|
|
84
|
-
|
|
85
|
+
workflowError('Workflow middleware error:', error);
|
|
85
86
|
// Don't throw error to avoid breaking the main operation
|
|
86
87
|
}
|
|
87
88
|
next();
|
|
88
89
|
});
|
|
89
90
|
schema.post('findOneAndDelete', async function (doc, next) {
|
|
90
91
|
const recordType = doc.constructor.modelName?.toLowerCase() || 'unknown';
|
|
91
|
-
|
|
92
|
+
workflowLog(`🗑️ Post-findOneAndDelete middleware triggered for ${recordType}`);
|
|
92
93
|
try {
|
|
93
94
|
await middleware.handleEvent({
|
|
94
95
|
recordType,
|
|
@@ -97,7 +98,7 @@ export function workflowPlugin(schema, options) {
|
|
|
97
98
|
}, doc);
|
|
98
99
|
}
|
|
99
100
|
catch (error) {
|
|
100
|
-
|
|
101
|
+
workflowError('Workflow middleware error:', error);
|
|
101
102
|
// Don't throw error to avoid breaking the main operation
|
|
102
103
|
}
|
|
103
104
|
next();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.service.d.ts","sourceRoot":"","sources":["../../shared/workflow.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"workflow.service.d.ts","sourceRoot":"","sources":["../../shared/workflow.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAGxF,qBAAa,eAAe;IACxB,OAAO,CAAC,OAAO,CAA4B;gBAE/B,OAAO,EAAE,yBAAyB;IAS9C;;;;OAIG;IACG,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAYjE;;;OAGG;YACW,mBAAmB;IA6DjC;;;;;OAKG;IACH,yBAAyB,CAAC,iBAAiB,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO;IAO1F;;;;;;OAMG;IACH,gBAAgB,CACZ,iBAAiB,EAAE,MAAM,EAAE,EAC3B,iBAAiB,EAAE,MAAM,EAAE,EAC3B,QAAQ,EAAE,GAAG,GACd,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAmBtB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;CAKzB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { workflowLog, workflowWarn, workflowError } from './workflow.logger.js';
|
|
1
2
|
export class WorkflowService {
|
|
2
3
|
constructor(options) {
|
|
3
4
|
this.options = {
|
|
@@ -19,7 +20,7 @@ export class WorkflowService {
|
|
|
19
20
|
await this.executeWorkflowCall(payload);
|
|
20
21
|
}
|
|
21
22
|
catch (error) {
|
|
22
|
-
|
|
23
|
+
workflowError('Workflow execution failed:', error);
|
|
23
24
|
// Could implement retry logic or error reporting here
|
|
24
25
|
}
|
|
25
26
|
}, 1000);
|
|
@@ -47,9 +48,9 @@ export class WorkflowService {
|
|
|
47
48
|
let lastError = null;
|
|
48
49
|
for (let attempt = 1; attempt <= this.options.retryAttempts; attempt++) {
|
|
49
50
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
workflowLog(`🚀 Workflow API call attempt ${attempt}:`);
|
|
52
|
+
workflowLog(` URL: ${this.options.workflowApiUrl}`);
|
|
53
|
+
workflowLog(` Payload: ${JSON.stringify(payload, null, 2)}`);
|
|
53
54
|
const response = await fetch(this.options.workflowApiUrl, requestOptions);
|
|
54
55
|
if (!response.ok) {
|
|
55
56
|
// Try to get error details from response body
|
|
@@ -66,12 +67,12 @@ export class WorkflowService {
|
|
|
66
67
|
throw new Error(`HTTP ${response.status}: ${errorDetails}`);
|
|
67
68
|
}
|
|
68
69
|
const result = await response.json();
|
|
69
|
-
|
|
70
|
+
workflowLog(`✅ Workflow ${payload.workflowKey} triggered successfully: ${JSON.stringify(result, null, 2)}`);
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
73
|
catch (error) {
|
|
73
74
|
lastError = error;
|
|
74
|
-
|
|
75
|
+
workflowWarn(`Workflow API call attempt ${attempt} failed:`, error);
|
|
75
76
|
if (attempt < this.options.retryAttempts) {
|
|
76
77
|
// Wait before retrying
|
|
77
78
|
await new Promise(resolve => setTimeout(resolve, this.options.retryDelay * attempt));
|