@valentine-efagene/qshelter-common 2.0.69 → 2.0.71
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/generated/client/enums.d.ts +6 -6
- package/dist/generated/client/enums.js +6 -6
- package/dist/generated/client/internal/class.js +1 -1
- package/dist/src/events/workflow-event.service.d.ts +58 -33
- package/dist/src/events/workflow-event.service.js +190 -168
- package/dist/src/events/workflow-types.d.ts +136 -87
- package/dist/src/events/workflow-types.js +9 -1
- package/package.json +1 -1
- package/prisma/migrations/20260106003757_business_friendly_handler_types/migration.sql +28 -0
- package/prisma/schema.prisma +7 -6
|
@@ -7,121 +7,162 @@
|
|
|
7
7
|
* Architecture:
|
|
8
8
|
* 1. EventChannel - Logical grouping of events (e.g., "CONTRACTS", "PAYMENTS")
|
|
9
9
|
* 2. EventType - Specific event types (e.g., "DOCUMENT_UPLOADED", "STEP_COMPLETED")
|
|
10
|
-
* 3. EventHandler - What to do when an event fires (
|
|
10
|
+
* 3. EventHandler - What to do when an event fires (send email, call webhook, etc.)
|
|
11
11
|
* 4. WorkflowEvent - Actual event instances (audit log)
|
|
12
12
|
* 5. EventHandlerExecution - Log of handler executions
|
|
13
|
+
*
|
|
14
|
+
* Handler types are business-friendly so non-technical admins can configure them:
|
|
15
|
+
* - SEND_EMAIL: Send an email to someone
|
|
16
|
+
* - SEND_SMS: Send a text message
|
|
17
|
+
* - SEND_PUSH: Send a push notification
|
|
18
|
+
* - CALL_WEBHOOK: Call an external API
|
|
19
|
+
* - ADVANCE_WORKFLOW: Move workflow forward
|
|
20
|
+
* - RUN_AUTOMATION: Execute business logic
|
|
13
21
|
*/
|
|
14
22
|
export type { EventHandlerType, ActorType, WorkflowEventStatus, ExecutionStatus, } from '../../generated/client/enums';
|
|
15
23
|
/**
|
|
16
|
-
* Configuration for
|
|
17
|
-
*
|
|
24
|
+
* Configuration for SEND_EMAIL handler type
|
|
25
|
+
* Sends an email notification to specified recipients
|
|
18
26
|
*/
|
|
19
|
-
export interface
|
|
20
|
-
type: '
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
export interface SendEmailHandlerConfig {
|
|
28
|
+
type: 'SEND_EMAIL';
|
|
29
|
+
/** Email template name (e.g., "documentApproved", "paymentReminder") */
|
|
30
|
+
template: string;
|
|
31
|
+
/**
|
|
32
|
+
* Notification type for the notification service.
|
|
33
|
+
* This maps to templates in the notification service.
|
|
34
|
+
*/
|
|
35
|
+
notificationType: string;
|
|
36
|
+
/**
|
|
37
|
+
* Who to send the email to. Use JSONPath to extract from event payload.
|
|
38
|
+
* Examples: "$.buyer.email", "$.user.email"
|
|
39
|
+
*/
|
|
40
|
+
recipientPath: string;
|
|
41
|
+
/**
|
|
42
|
+
* Map event payload fields to template variables
|
|
43
|
+
* Example: { "userName": "$.buyer.firstName", "amount": "$.payment.amount" }
|
|
44
|
+
*/
|
|
45
|
+
templateData?: Record<string, string>;
|
|
46
|
+
/** Static data to always include in template */
|
|
47
|
+
staticData?: Record<string, unknown>;
|
|
48
|
+
/** Priority level */
|
|
49
|
+
priority?: 'low' | 'normal' | 'high' | 'urgent';
|
|
27
50
|
}
|
|
28
51
|
/**
|
|
29
|
-
* Configuration for
|
|
30
|
-
* Sends
|
|
52
|
+
* Configuration for SEND_SMS handler type
|
|
53
|
+
* Sends an SMS text message
|
|
31
54
|
*/
|
|
32
|
-
export interface
|
|
33
|
-
type: '
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
55
|
+
export interface SendSmsHandlerConfig {
|
|
56
|
+
type: 'SEND_SMS';
|
|
57
|
+
/** SMS template name */
|
|
58
|
+
template: string;
|
|
59
|
+
/**
|
|
60
|
+
* Notification type for the notification service.
|
|
61
|
+
*/
|
|
62
|
+
notificationType: string;
|
|
63
|
+
/**
|
|
64
|
+
* Phone number path in event payload
|
|
65
|
+
* Example: "$.buyer.phone"
|
|
66
|
+
*/
|
|
67
|
+
recipientPath: string;
|
|
68
|
+
/** Map event payload fields to template variables */
|
|
69
|
+
templateData?: Record<string, string>;
|
|
70
|
+
/** Static data to always include in template */
|
|
71
|
+
staticData?: Record<string, unknown>;
|
|
46
72
|
}
|
|
47
73
|
/**
|
|
48
|
-
* Configuration for
|
|
49
|
-
*
|
|
74
|
+
* Configuration for SEND_PUSH handler type
|
|
75
|
+
* Sends a push notification to user's device
|
|
50
76
|
*/
|
|
51
|
-
export interface
|
|
52
|
-
type: '
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
77
|
+
export interface SendPushHandlerConfig {
|
|
78
|
+
type: 'SEND_PUSH';
|
|
79
|
+
/** Push notification title */
|
|
80
|
+
title: string;
|
|
81
|
+
/** Push notification body (can use {{variables}}) */
|
|
82
|
+
body: string;
|
|
83
|
+
/**
|
|
84
|
+
* Notification type for the notification service.
|
|
85
|
+
*/
|
|
86
|
+
notificationType: string;
|
|
87
|
+
/**
|
|
88
|
+
* User ID path in event payload (to find their device)
|
|
89
|
+
* Example: "$.buyer.id"
|
|
90
|
+
*/
|
|
91
|
+
recipientPath: string;
|
|
92
|
+
/** Deep link to open in app */
|
|
93
|
+
deepLink?: string;
|
|
94
|
+
/** Map event payload fields to notification variables */
|
|
95
|
+
templateData?: Record<string, string>;
|
|
96
|
+
/** Static data to always include in notification */
|
|
97
|
+
staticData?: Record<string, unknown>;
|
|
61
98
|
}
|
|
62
99
|
/**
|
|
63
|
-
* Configuration for
|
|
64
|
-
*
|
|
100
|
+
* Configuration for CALL_WEBHOOK handler type
|
|
101
|
+
* Calls an external API endpoint
|
|
65
102
|
*/
|
|
66
|
-
export interface
|
|
67
|
-
type: '
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
103
|
+
export interface CallWebhookHandlerConfig {
|
|
104
|
+
type: 'CALL_WEBHOOK';
|
|
105
|
+
/** The URL to call */
|
|
106
|
+
url: string;
|
|
107
|
+
/** HTTP method */
|
|
108
|
+
method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
109
|
+
/** Optional headers to include */
|
|
110
|
+
headers?: Record<string, string>;
|
|
111
|
+
/**
|
|
112
|
+
* Map event payload fields to request body
|
|
113
|
+
* Example: { "orderId": "$.contract.id", "status": "$.status" }
|
|
114
|
+
*/
|
|
115
|
+
bodyMapping?: Record<string, string>;
|
|
116
|
+
/** Timeout in milliseconds (default: 30000) */
|
|
117
|
+
timeoutMs?: number;
|
|
80
118
|
}
|
|
81
119
|
/**
|
|
82
|
-
* Configuration for
|
|
83
|
-
*
|
|
84
|
-
* Uses the NotificationEvent format expected by notification-service
|
|
120
|
+
* Configuration for ADVANCE_WORKFLOW handler type
|
|
121
|
+
* Advances or modifies a workflow step
|
|
85
122
|
*/
|
|
86
|
-
export interface
|
|
87
|
-
type: '
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
/** Notification type (from NotificationType enum) */
|
|
91
|
-
notificationType: string;
|
|
92
|
-
/** Notification channel (email, sms, push) */
|
|
93
|
-
channel: 'email' | 'sms' | 'push';
|
|
94
|
-
/**
|
|
95
|
-
* Payload mapping - maps event payload to notification payload
|
|
96
|
-
* Uses JSONPath-like expressions (e.g., $.user.email -> to_email)
|
|
97
|
-
*/
|
|
98
|
-
payloadMapping?: Record<string, string>;
|
|
123
|
+
export interface AdvanceWorkflowHandlerConfig {
|
|
124
|
+
type: 'ADVANCE_WORKFLOW';
|
|
125
|
+
/** What action to take */
|
|
126
|
+
action: 'complete_step' | 'skip_step' | 'fail_step' | 'activate_phase';
|
|
99
127
|
/**
|
|
100
|
-
*
|
|
128
|
+
* Step ID path in event payload (if action targets a specific step)
|
|
129
|
+
* Example: "$.stepId"
|
|
101
130
|
*/
|
|
102
|
-
|
|
131
|
+
stepIdPath?: string;
|
|
103
132
|
/**
|
|
104
|
-
*
|
|
133
|
+
* Phase ID path in event payload (if action targets a phase)
|
|
134
|
+
* Example: "$.phaseId"
|
|
105
135
|
*/
|
|
106
|
-
|
|
136
|
+
phaseIdPath?: string;
|
|
137
|
+
/** Static step ID (if not using path) */
|
|
138
|
+
stepId?: string;
|
|
139
|
+
/** Static workflow ID */
|
|
140
|
+
workflowId?: string;
|
|
141
|
+
/** Static phase ID */
|
|
142
|
+
phaseId?: string;
|
|
143
|
+
/** Additional data to pass to the action */
|
|
144
|
+
data?: Record<string, unknown>;
|
|
145
|
+
/** Reason to record for the action */
|
|
146
|
+
reason?: string;
|
|
107
147
|
}
|
|
108
148
|
/**
|
|
109
|
-
* Configuration for
|
|
110
|
-
* Executes
|
|
149
|
+
* Configuration for RUN_AUTOMATION handler type
|
|
150
|
+
* Executes internal business logic
|
|
111
151
|
*/
|
|
112
|
-
export interface
|
|
113
|
-
type: '
|
|
114
|
-
/**
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
152
|
+
export interface RunAutomationHandlerConfig {
|
|
153
|
+
type: 'RUN_AUTOMATION';
|
|
154
|
+
/** The automation to run (registered automation name) */
|
|
155
|
+
automation: string;
|
|
156
|
+
/**
|
|
157
|
+
* Map event payload fields to automation inputs
|
|
158
|
+
* Example: { "contractId": "$.contract.id", "amount": "$.payment.amount" }
|
|
159
|
+
*/
|
|
160
|
+
inputMapping?: Record<string, string>;
|
|
120
161
|
}
|
|
121
162
|
/**
|
|
122
163
|
* Union type for all handler configurations
|
|
123
164
|
*/
|
|
124
|
-
export type HandlerConfig =
|
|
165
|
+
export type HandlerConfig = SendEmailHandlerConfig | SendSmsHandlerConfig | SendPushHandlerConfig | CallWebhookHandlerConfig | AdvanceWorkflowHandlerConfig | RunAutomationHandlerConfig;
|
|
125
166
|
/**
|
|
126
167
|
* Input for emitting an event
|
|
127
168
|
*/
|
|
@@ -216,12 +257,20 @@ export interface UpdateEventTypeInput {
|
|
|
216
257
|
}
|
|
217
258
|
/**
|
|
218
259
|
* Input for creating an event handler
|
|
260
|
+
*
|
|
261
|
+
* Handler types are business-friendly names:
|
|
262
|
+
* - SEND_EMAIL: Send email notification
|
|
263
|
+
* - SEND_SMS: Send SMS text message
|
|
264
|
+
* - SEND_PUSH: Send push notification
|
|
265
|
+
* - CALL_WEBHOOK: Call external API
|
|
266
|
+
* - ADVANCE_WORKFLOW: Move workflow forward
|
|
267
|
+
* - RUN_AUTOMATION: Execute business logic
|
|
219
268
|
*/
|
|
220
269
|
export interface CreateEventHandlerInput {
|
|
221
270
|
eventTypeId: string;
|
|
222
271
|
name: string;
|
|
223
272
|
description?: string;
|
|
224
|
-
handlerType: '
|
|
273
|
+
handlerType: 'SEND_EMAIL' | 'SEND_SMS' | 'SEND_PUSH' | 'CALL_WEBHOOK' | 'ADVANCE_WORKFLOW' | 'RUN_AUTOMATION';
|
|
225
274
|
config: HandlerConfig;
|
|
226
275
|
priority?: number;
|
|
227
276
|
enabled?: boolean;
|
|
@@ -7,8 +7,16 @@
|
|
|
7
7
|
* Architecture:
|
|
8
8
|
* 1. EventChannel - Logical grouping of events (e.g., "CONTRACTS", "PAYMENTS")
|
|
9
9
|
* 2. EventType - Specific event types (e.g., "DOCUMENT_UPLOADED", "STEP_COMPLETED")
|
|
10
|
-
* 3. EventHandler - What to do when an event fires (
|
|
10
|
+
* 3. EventHandler - What to do when an event fires (send email, call webhook, etc.)
|
|
11
11
|
* 4. WorkflowEvent - Actual event instances (audit log)
|
|
12
12
|
* 5. EventHandlerExecution - Log of handler executions
|
|
13
|
+
*
|
|
14
|
+
* Handler types are business-friendly so non-technical admins can configure them:
|
|
15
|
+
* - SEND_EMAIL: Send an email to someone
|
|
16
|
+
* - SEND_SMS: Send a text message
|
|
17
|
+
* - SEND_PUSH: Send a push notification
|
|
18
|
+
* - CALL_WEBHOOK: Call an external API
|
|
19
|
+
* - ADVANCE_WORKFLOW: Move workflow forward
|
|
20
|
+
* - RUN_AUTOMATION: Execute business logic
|
|
13
21
|
*/
|
|
14
22
|
export {};
|
package/package.json
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Warnings:
|
|
3
|
+
|
|
4
|
+
- The values [INTERNAL,WEBHOOK,WORKFLOW,NOTIFICATION,SNS,SCRIPT] on the enum `event_handlers_handlerType` will be removed. If these variants are still used in the database, this will fail.
|
|
5
|
+
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
-- First, migrate existing data to new enum values
|
|
9
|
+
-- INTERNAL -> RUN_AUTOMATION (internal service calls are now automations)
|
|
10
|
+
-- WEBHOOK -> CALL_WEBHOOK (external API calls)
|
|
11
|
+
-- WORKFLOW -> ADVANCE_WORKFLOW (workflow state changes)
|
|
12
|
+
-- NOTIFICATION -> SEND_EMAIL (general notifications default to email)
|
|
13
|
+
-- SNS -> SEND_EMAIL (SNS was for email notifications)
|
|
14
|
+
-- SCRIPT -> RUN_AUTOMATION (custom scripts are automations)
|
|
15
|
+
|
|
16
|
+
-- Add new enum values first (MySQL requires this approach)
|
|
17
|
+
ALTER TABLE `event_handlers` MODIFY `handlerType` ENUM('INTERNAL', 'WEBHOOK', 'WORKFLOW', 'NOTIFICATION', 'SNS', 'SCRIPT', 'SEND_EMAIL', 'SEND_SMS', 'SEND_PUSH', 'CALL_WEBHOOK', 'ADVANCE_WORKFLOW', 'RUN_AUTOMATION') NOT NULL;
|
|
18
|
+
|
|
19
|
+
-- Migrate data
|
|
20
|
+
UPDATE `event_handlers` SET `handlerType` = 'RUN_AUTOMATION' WHERE `handlerType` = 'INTERNAL';
|
|
21
|
+
UPDATE `event_handlers` SET `handlerType` = 'CALL_WEBHOOK' WHERE `handlerType` = 'WEBHOOK';
|
|
22
|
+
UPDATE `event_handlers` SET `handlerType` = 'ADVANCE_WORKFLOW' WHERE `handlerType` = 'WORKFLOW';
|
|
23
|
+
UPDATE `event_handlers` SET `handlerType` = 'SEND_EMAIL' WHERE `handlerType` = 'NOTIFICATION';
|
|
24
|
+
UPDATE `event_handlers` SET `handlerType` = 'SEND_EMAIL' WHERE `handlerType` = 'SNS';
|
|
25
|
+
UPDATE `event_handlers` SET `handlerType` = 'RUN_AUTOMATION' WHERE `handlerType` = 'SCRIPT';
|
|
26
|
+
|
|
27
|
+
-- Now remove old enum values
|
|
28
|
+
ALTER TABLE `event_handlers` MODIFY `handlerType` ENUM('SEND_EMAIL', 'SEND_SMS', 'SEND_PUSH', 'CALL_WEBHOOK', 'ADVANCE_WORKFLOW', 'RUN_AUTOMATION') NOT NULL;
|
package/prisma/schema.prisma
CHANGED
|
@@ -190,13 +190,14 @@ enum OfferLetterStatus {
|
|
|
190
190
|
// =============================================================================
|
|
191
191
|
|
|
192
192
|
/// Handler Type - What kind of action the handler performs
|
|
193
|
+
/// These are business-friendly names that admins can understand
|
|
193
194
|
enum EventHandlerType {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
195
|
+
SEND_EMAIL // Send an email notification to recipient(s)
|
|
196
|
+
SEND_SMS // Send an SMS text message
|
|
197
|
+
SEND_PUSH // Send a push notification
|
|
198
|
+
CALL_WEBHOOK // Call an external API/webhook
|
|
199
|
+
ADVANCE_WORKFLOW // Advance or complete a workflow step
|
|
200
|
+
RUN_AUTOMATION // Execute internal business logic
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
/// Actor Type - Who triggered an event
|