@valentine-efagene/qshelter-common 2.0.65 → 2.0.67
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/browser.d.ts +29 -0
- package/dist/generated/client/client.d.ts +29 -0
- package/dist/generated/client/commonInputTypes.d.ts +120 -0
- package/dist/generated/client/enums.d.ts +32 -0
- package/dist/generated/client/enums.js +28 -0
- package/dist/generated/client/internal/class.d.ts +55 -0
- package/dist/generated/client/internal/class.js +2 -2
- package/dist/generated/client/internal/prismaNamespace.d.ts +475 -1
- package/dist/generated/client/internal/prismaNamespace.js +113 -0
- package/dist/generated/client/internal/prismaNamespaceBrowser.d.ts +123 -0
- package/dist/generated/client/internal/prismaNamespaceBrowser.js +113 -0
- package/dist/generated/client/models/EventChannel.d.ts +1305 -0
- package/dist/generated/client/models/EventChannel.js +1 -0
- package/dist/generated/client/models/EventHandler.d.ts +1749 -0
- package/dist/generated/client/models/EventHandler.js +1 -0
- package/dist/generated/client/models/EventHandlerExecution.d.ts +1525 -0
- package/dist/generated/client/models/EventHandlerExecution.js +1 -0
- package/dist/generated/client/models/EventType.d.ts +1653 -0
- package/dist/generated/client/models/EventType.js +1 -0
- package/dist/generated/client/models/Tenant.d.ts +796 -0
- package/dist/generated/client/models/WorkflowEvent.d.ts +1654 -0
- package/dist/generated/client/models/WorkflowEvent.js +1 -0
- package/dist/generated/client/models/index.d.ts +5 -0
- package/dist/generated/client/models/index.js +5 -0
- package/dist/generated/client/models.d.ts +5 -0
- package/dist/src/events/event-config.service.d.ts +123 -0
- package/dist/src/events/event-config.service.js +416 -0
- package/dist/src/events/index.d.ts +3 -0
- package/dist/src/events/index.js +5 -0
- package/dist/src/events/workflow-event.service.d.ts +189 -0
- package/dist/src/events/workflow-event.service.js +588 -0
- package/dist/src/events/workflow-types.d.ts +288 -0
- package/dist/src/events/workflow-types.js +14 -0
- package/package.json +1 -1
- package/prisma/migrations/20260105151535_add_event_workflow_system/migration.sql +132 -0
- package/prisma/schema.prisma +271 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Event Service
|
|
3
|
+
*
|
|
4
|
+
* Handles emission and processing of workflow events.
|
|
5
|
+
* Events are stored in the database and processed by registered handlers.
|
|
6
|
+
*
|
|
7
|
+
* Design principles:
|
|
8
|
+
* 1. Events are immutable once emitted
|
|
9
|
+
* 2. Handlers are configured by admins, not hardcoded
|
|
10
|
+
* 3. Each handler execution is logged for audit
|
|
11
|
+
* 4. Failed handlers can be retried
|
|
12
|
+
* 5. Events can be correlated for tracing
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const eventService = new WorkflowEventService(prisma);
|
|
17
|
+
*
|
|
18
|
+
* // Emit an event
|
|
19
|
+
* const event = await eventService.emit(tenantId, {
|
|
20
|
+
* eventType: 'DOCUMENT_UPLOADED',
|
|
21
|
+
* payload: {
|
|
22
|
+
* contractId: 'ctr_123',
|
|
23
|
+
* stepId: 'step_456',
|
|
24
|
+
* documentUrl: 'https://...',
|
|
25
|
+
* },
|
|
26
|
+
* source: 'contract-service',
|
|
27
|
+
* actor: { id: 'user_789', type: 'USER' },
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Process the event (run all handlers)
|
|
31
|
+
* const result = await eventService.processEvent(event.id);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
import { PrismaClient } from '../../generated/client/client';
|
|
35
|
+
import type { EmitEventInput, WorkflowEventData, ProcessEventResult } from './workflow-types';
|
|
36
|
+
/**
|
|
37
|
+
* Service registry interface for internal handlers
|
|
38
|
+
*/
|
|
39
|
+
export interface ServiceRegistry {
|
|
40
|
+
get(serviceName: string): any | undefined;
|
|
41
|
+
register(serviceName: string, service: any): void;
|
|
42
|
+
}
|
|
43
|
+
export declare class WorkflowEventService {
|
|
44
|
+
private prisma;
|
|
45
|
+
private serviceRegistry;
|
|
46
|
+
constructor(prisma: PrismaClient, serviceRegistry?: ServiceRegistry);
|
|
47
|
+
/**
|
|
48
|
+
* Register a service for internal event handlers
|
|
49
|
+
*
|
|
50
|
+
* Services can be called by INTERNAL handler type configurations.
|
|
51
|
+
* The service should expose methods that match the handler config.
|
|
52
|
+
*/
|
|
53
|
+
registerService(name: string, service: any): void;
|
|
54
|
+
/**
|
|
55
|
+
* Emit an event
|
|
56
|
+
*
|
|
57
|
+
* This creates an event record and optionally processes it immediately
|
|
58
|
+
* or leaves it for async processing by a worker.
|
|
59
|
+
*
|
|
60
|
+
* @param tenantId - Tenant context
|
|
61
|
+
* @param input - Event details
|
|
62
|
+
* @param processImmediately - Whether to process handlers now (default: false)
|
|
63
|
+
*/
|
|
64
|
+
emit(tenantId: string, input: EmitEventInput, processImmediately?: boolean): Promise<WorkflowEventData>;
|
|
65
|
+
/**
|
|
66
|
+
* Process an event by executing all registered handlers
|
|
67
|
+
*
|
|
68
|
+
* This is typically called by a worker/queue processor,
|
|
69
|
+
* but can also be called synchronously for simple cases.
|
|
70
|
+
*/
|
|
71
|
+
processEvent(eventId: string): Promise<ProcessEventResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Get pending events for processing (for worker/queue)
|
|
74
|
+
*/
|
|
75
|
+
getPendingEvents(tenantId?: string, limit?: number): Promise<WorkflowEventData[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Get events by correlation ID (for tracing related events)
|
|
78
|
+
*/
|
|
79
|
+
getEventsByCorrelation(tenantId: string, correlationId: string): Promise<WorkflowEventData[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Get event with executions (for debugging/auditing)
|
|
82
|
+
*/
|
|
83
|
+
getEventWithExecutions(tenantId: string, eventId: string): Promise<({
|
|
84
|
+
eventType: {
|
|
85
|
+
channel: {
|
|
86
|
+
name: string;
|
|
87
|
+
id: string;
|
|
88
|
+
tenantId: string;
|
|
89
|
+
createdAt: Date;
|
|
90
|
+
updatedAt: Date;
|
|
91
|
+
description: string | null;
|
|
92
|
+
enabled: boolean;
|
|
93
|
+
code: string;
|
|
94
|
+
};
|
|
95
|
+
} & {
|
|
96
|
+
name: string;
|
|
97
|
+
id: string;
|
|
98
|
+
tenantId: string;
|
|
99
|
+
createdAt: Date;
|
|
100
|
+
updatedAt: Date;
|
|
101
|
+
description: string | null;
|
|
102
|
+
enabled: boolean;
|
|
103
|
+
code: string;
|
|
104
|
+
channelId: string;
|
|
105
|
+
payloadSchema: import("@prisma/client/runtime/client").JsonValue | null;
|
|
106
|
+
};
|
|
107
|
+
executions: ({
|
|
108
|
+
handler: {
|
|
109
|
+
name: string;
|
|
110
|
+
id: string;
|
|
111
|
+
handlerType: import("./workflow-types").EventHandlerType;
|
|
112
|
+
};
|
|
113
|
+
} & {
|
|
114
|
+
id: string;
|
|
115
|
+
createdAt: Date;
|
|
116
|
+
status: import("./workflow-types").ExecutionStatus;
|
|
117
|
+
completedAt: Date | null;
|
|
118
|
+
error: string | null;
|
|
119
|
+
eventId: string;
|
|
120
|
+
handlerId: string;
|
|
121
|
+
attempt: number;
|
|
122
|
+
input: import("@prisma/client/runtime/client").JsonValue | null;
|
|
123
|
+
output: import("@prisma/client/runtime/client").JsonValue | null;
|
|
124
|
+
errorCode: string | null;
|
|
125
|
+
startedAt: Date | null;
|
|
126
|
+
durationMs: number | null;
|
|
127
|
+
})[];
|
|
128
|
+
} & {
|
|
129
|
+
id: string;
|
|
130
|
+
tenantId: string;
|
|
131
|
+
createdAt: Date;
|
|
132
|
+
status: import("./workflow-types").WorkflowEventStatus;
|
|
133
|
+
processedAt: Date | null;
|
|
134
|
+
actorId: string | null;
|
|
135
|
+
actorType: import("./workflow-types").ActorType;
|
|
136
|
+
eventTypeId: string;
|
|
137
|
+
payload: import("@prisma/client/runtime/client").JsonValue;
|
|
138
|
+
correlationId: string | null;
|
|
139
|
+
causationId: string | null;
|
|
140
|
+
source: string;
|
|
141
|
+
error: string | null;
|
|
142
|
+
}) | null>;
|
|
143
|
+
/**
|
|
144
|
+
* Execute a handler based on its type
|
|
145
|
+
*/
|
|
146
|
+
private executeHandler;
|
|
147
|
+
/**
|
|
148
|
+
* Execute an internal service method
|
|
149
|
+
*/
|
|
150
|
+
private executeInternalHandler;
|
|
151
|
+
/**
|
|
152
|
+
* Execute a webhook handler
|
|
153
|
+
*/
|
|
154
|
+
private executeWebhookHandler;
|
|
155
|
+
/**
|
|
156
|
+
* Execute a workflow handler
|
|
157
|
+
*
|
|
158
|
+
* This emits a new event that the workflow service can pick up,
|
|
159
|
+
* creating loose coupling between event system and workflow engine.
|
|
160
|
+
*/
|
|
161
|
+
private executeWorkflowHandler;
|
|
162
|
+
/**
|
|
163
|
+
* Execute a notification handler
|
|
164
|
+
*
|
|
165
|
+
* This would integrate with a notification service.
|
|
166
|
+
* Returns what would be sent for logging purposes.
|
|
167
|
+
*/
|
|
168
|
+
private executeNotificationHandler;
|
|
169
|
+
/**
|
|
170
|
+
* Evaluate a filter condition against the payload
|
|
171
|
+
*/
|
|
172
|
+
private evaluateFilterCondition;
|
|
173
|
+
/**
|
|
174
|
+
* Transform payload using a mapping
|
|
175
|
+
*/
|
|
176
|
+
private transformPayload;
|
|
177
|
+
/**
|
|
178
|
+
* Resolve a dot-notation path in an object
|
|
179
|
+
*/
|
|
180
|
+
private resolvePath;
|
|
181
|
+
/**
|
|
182
|
+
* Resolve recipients from config, potentially using payload variables
|
|
183
|
+
*/
|
|
184
|
+
private resolveRecipients;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Create a workflow event service instance
|
|
188
|
+
*/
|
|
189
|
+
export declare function createWorkflowEventService(prisma: PrismaClient, serviceRegistry?: ServiceRegistry): WorkflowEventService;
|