@valentine-efagene/qshelter-common 2.0.66 → 2.0.68

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