@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.
- 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 +33 -0
- package/dist/generated/client/enums.js +29 -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 +205 -0
- package/dist/src/events/workflow-event.service.js +660 -0
- package/dist/src/events/workflow-types.d.ts +315 -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 +272 -0
package/prisma/schema.prisma
CHANGED
|
@@ -185,6 +185,47 @@ enum OfferLetterStatus {
|
|
|
185
185
|
CANCELLED
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
// =============================================================================
|
|
189
|
+
// EVENT-DRIVEN WORKFLOW ENUMS
|
|
190
|
+
// =============================================================================
|
|
191
|
+
|
|
192
|
+
/// Handler Type - What kind of action the handler performs
|
|
193
|
+
enum EventHandlerType {
|
|
194
|
+
INTERNAL // Call an internal service method
|
|
195
|
+
WEBHOOK // Send a webhook to an external URL
|
|
196
|
+
WORKFLOW // Trigger or advance a workflow
|
|
197
|
+
NOTIFICATION // Send a notification (email, SMS, push) - internal
|
|
198
|
+
SNS // Publish to SNS topic (for notification-service)
|
|
199
|
+
SCRIPT // Execute a custom script/expression
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/// Actor Type - Who triggered an event
|
|
203
|
+
enum ActorType {
|
|
204
|
+
USER
|
|
205
|
+
API_KEY
|
|
206
|
+
SYSTEM
|
|
207
|
+
WEBHOOK
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/// Workflow Event Status
|
|
211
|
+
enum WorkflowEventStatus {
|
|
212
|
+
PENDING
|
|
213
|
+
PROCESSING
|
|
214
|
+
COMPLETED
|
|
215
|
+
FAILED
|
|
216
|
+
SKIPPED
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/// Handler Execution Status
|
|
220
|
+
enum ExecutionStatus {
|
|
221
|
+
PENDING
|
|
222
|
+
RUNNING
|
|
223
|
+
COMPLETED
|
|
224
|
+
FAILED
|
|
225
|
+
RETRYING
|
|
226
|
+
SKIPPED
|
|
227
|
+
}
|
|
228
|
+
|
|
188
229
|
// =============================================================================
|
|
189
230
|
// USER & AUTH DOMAIN
|
|
190
231
|
// =============================================================================
|
|
@@ -324,6 +365,12 @@ model Tenant {
|
|
|
324
365
|
// API keys for third-party integrations
|
|
325
366
|
apiKeys ApiKey[]
|
|
326
367
|
|
|
368
|
+
// Event-driven workflow
|
|
369
|
+
eventChannels EventChannel[]
|
|
370
|
+
eventTypes EventType[]
|
|
371
|
+
eventHandlers EventHandler[]
|
|
372
|
+
workflowEvents WorkflowEvent[]
|
|
373
|
+
|
|
327
374
|
@@index([subdomain])
|
|
328
375
|
@@map("tenants")
|
|
329
376
|
}
|
|
@@ -1616,6 +1663,231 @@ model DocumentRequirementRule {
|
|
|
1616
1663
|
@@map("document_requirement_rules")
|
|
1617
1664
|
}
|
|
1618
1665
|
|
|
1666
|
+
// =============================================================================
|
|
1667
|
+
// EVENT-DRIVEN WORKFLOW CONFIGURATION
|
|
1668
|
+
// =============================================================================
|
|
1669
|
+
// This system allows admins to configure event channels, types, and handlers
|
|
1670
|
+
// for a flexible, configurable event-driven workflow system.
|
|
1671
|
+
//
|
|
1672
|
+
// Architecture:
|
|
1673
|
+
// 1. EventChannel - Logical grouping of events (e.g., "contracts", "payments")
|
|
1674
|
+
// 2. EventType - Specific event types (e.g., "DOCUMENT_UPLOADED", "STEP_COMPLETED")
|
|
1675
|
+
// 3. EventHandler - What to do when an event fires (webhook, internal call, etc.)
|
|
1676
|
+
// 4. WorkflowEvent - Actual event instances (audit log)
|
|
1677
|
+
// 5. EventHandlerExecution - Log of handler executions
|
|
1678
|
+
// =============================================================================
|
|
1679
|
+
|
|
1680
|
+
/// Event Channel - A logical grouping of events
|
|
1681
|
+
/// Channels help organize events and route them to appropriate handlers
|
|
1682
|
+
model EventChannel {
|
|
1683
|
+
id String @id @default(cuid())
|
|
1684
|
+
tenantId String
|
|
1685
|
+
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1686
|
+
|
|
1687
|
+
/// Unique code for the channel (e.g., "CONTRACTS", "PAYMENTS")
|
|
1688
|
+
code String
|
|
1689
|
+
/// Human-readable name
|
|
1690
|
+
name String
|
|
1691
|
+
/// Description of what this channel handles
|
|
1692
|
+
description String? @db.Text
|
|
1693
|
+
|
|
1694
|
+
/// Whether this channel is active
|
|
1695
|
+
enabled Boolean @default(true)
|
|
1696
|
+
|
|
1697
|
+
/// Event types that belong to this channel
|
|
1698
|
+
eventTypes EventType[]
|
|
1699
|
+
|
|
1700
|
+
createdAt DateTime @default(now())
|
|
1701
|
+
updatedAt DateTime @updatedAt
|
|
1702
|
+
|
|
1703
|
+
@@unique([tenantId, code])
|
|
1704
|
+
@@index([tenantId])
|
|
1705
|
+
@@map("event_channels")
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
/// Event Type - Defines a type of event that can occur
|
|
1709
|
+
/// Each event type belongs to a channel and can have multiple handlers
|
|
1710
|
+
model EventType {
|
|
1711
|
+
id String @id @default(cuid())
|
|
1712
|
+
tenantId String
|
|
1713
|
+
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1714
|
+
|
|
1715
|
+
/// The channel this event type belongs to
|
|
1716
|
+
channelId String
|
|
1717
|
+
channel EventChannel @relation(fields: [channelId], references: [id], onDelete: Cascade)
|
|
1718
|
+
|
|
1719
|
+
/// Unique code for this event type (e.g., "DOCUMENT_UPLOADED")
|
|
1720
|
+
code String
|
|
1721
|
+
/// Human-readable name
|
|
1722
|
+
name String
|
|
1723
|
+
/// Description of when this event fires
|
|
1724
|
+
description String? @db.Text
|
|
1725
|
+
|
|
1726
|
+
/// JSON schema for event payload validation (optional)
|
|
1727
|
+
payloadSchema Json?
|
|
1728
|
+
|
|
1729
|
+
/// Whether this event type is active
|
|
1730
|
+
enabled Boolean @default(true)
|
|
1731
|
+
|
|
1732
|
+
/// Handlers subscribed to this event type
|
|
1733
|
+
handlers EventHandler[]
|
|
1734
|
+
|
|
1735
|
+
/// Actual event instances of this type
|
|
1736
|
+
events WorkflowEvent[]
|
|
1737
|
+
|
|
1738
|
+
createdAt DateTime @default(now())
|
|
1739
|
+
updatedAt DateTime @updatedAt
|
|
1740
|
+
|
|
1741
|
+
@@unique([tenantId, code])
|
|
1742
|
+
@@unique([channelId, code])
|
|
1743
|
+
@@index([tenantId])
|
|
1744
|
+
@@index([channelId])
|
|
1745
|
+
@@map("event_types")
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
/// Event Handler - Defines what should happen when an event fires
|
|
1749
|
+
/// Handlers can be internal (call a service), external (webhook), or workflow triggers
|
|
1750
|
+
model EventHandler {
|
|
1751
|
+
id String @id @default(cuid())
|
|
1752
|
+
tenantId String
|
|
1753
|
+
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1754
|
+
|
|
1755
|
+
/// The event type this handler responds to
|
|
1756
|
+
eventTypeId String
|
|
1757
|
+
eventType EventType @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
|
|
1758
|
+
|
|
1759
|
+
/// Human-readable name
|
|
1760
|
+
name String
|
|
1761
|
+
/// Description of what this handler does
|
|
1762
|
+
description String? @db.Text
|
|
1763
|
+
|
|
1764
|
+
/// Handler type determines how the event is processed
|
|
1765
|
+
handlerType EventHandlerType
|
|
1766
|
+
|
|
1767
|
+
/// Configuration for the handler (JSON, depends on handlerType)
|
|
1768
|
+
/// INTERNAL: { "service": "contract", "method": "completeStep" }
|
|
1769
|
+
/// WEBHOOK: { "url": "https://...", "method": "POST", "headers": {...} }
|
|
1770
|
+
/// WORKFLOW: { "workflowId": "...", "action": "advance" }
|
|
1771
|
+
/// NOTIFICATION: { "template": "...", "channels": ["email", "sms"] }
|
|
1772
|
+
config Json
|
|
1773
|
+
|
|
1774
|
+
/// Order of execution when multiple handlers exist (lower = first)
|
|
1775
|
+
priority Int @default(100)
|
|
1776
|
+
|
|
1777
|
+
/// Whether this handler is active
|
|
1778
|
+
enabled Boolean @default(true)
|
|
1779
|
+
|
|
1780
|
+
/// Retry configuration
|
|
1781
|
+
maxRetries Int @default(3)
|
|
1782
|
+
retryDelayMs Int @default(1000)
|
|
1783
|
+
|
|
1784
|
+
/// Filter condition (JSONPath expression) to conditionally run
|
|
1785
|
+
/// e.g., "$.payload.status == 'approved'"
|
|
1786
|
+
filterCondition String? @db.Text
|
|
1787
|
+
|
|
1788
|
+
/// Handler execution logs
|
|
1789
|
+
executions EventHandlerExecution[]
|
|
1790
|
+
|
|
1791
|
+
createdAt DateTime @default(now())
|
|
1792
|
+
updatedAt DateTime @updatedAt
|
|
1793
|
+
|
|
1794
|
+
@@index([tenantId])
|
|
1795
|
+
@@index([eventTypeId])
|
|
1796
|
+
@@index([handlerType])
|
|
1797
|
+
@@map("event_handlers")
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
/// Workflow Event - An actual event instance that occurred
|
|
1801
|
+
/// This is the audit log of all events in the system
|
|
1802
|
+
model WorkflowEvent {
|
|
1803
|
+
id String @id @default(cuid())
|
|
1804
|
+
tenantId String
|
|
1805
|
+
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
1806
|
+
|
|
1807
|
+
/// The type of this event
|
|
1808
|
+
eventTypeId String
|
|
1809
|
+
eventType EventType @relation(fields: [eventTypeId], references: [id], onDelete: Cascade)
|
|
1810
|
+
|
|
1811
|
+
/// The event payload (actual data)
|
|
1812
|
+
payload Json
|
|
1813
|
+
|
|
1814
|
+
/// Optional correlation ID to link related events
|
|
1815
|
+
correlationId String?
|
|
1816
|
+
|
|
1817
|
+
/// Optional causation ID (which event caused this one)
|
|
1818
|
+
causationId String?
|
|
1819
|
+
|
|
1820
|
+
/// Source of the event (service name, user action, etc.)
|
|
1821
|
+
source String
|
|
1822
|
+
|
|
1823
|
+
/// Actor who triggered the event (user ID, API key ID, "system")
|
|
1824
|
+
actorId String?
|
|
1825
|
+
actorType ActorType @default(SYSTEM)
|
|
1826
|
+
|
|
1827
|
+
/// Event status
|
|
1828
|
+
status WorkflowEventStatus @default(PENDING)
|
|
1829
|
+
|
|
1830
|
+
/// Error message if processing failed
|
|
1831
|
+
error String? @db.Text
|
|
1832
|
+
|
|
1833
|
+
/// When the event was processed
|
|
1834
|
+
processedAt DateTime?
|
|
1835
|
+
|
|
1836
|
+
/// Handler executions for this event
|
|
1837
|
+
executions EventHandlerExecution[]
|
|
1838
|
+
|
|
1839
|
+
createdAt DateTime @default(now())
|
|
1840
|
+
|
|
1841
|
+
@@index([tenantId])
|
|
1842
|
+
@@index([eventTypeId])
|
|
1843
|
+
@@index([correlationId])
|
|
1844
|
+
@@index([causationId])
|
|
1845
|
+
@@index([status])
|
|
1846
|
+
@@index([createdAt])
|
|
1847
|
+
@@map("workflow_events")
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
/// Event Handler Execution - Log of a handler processing an event
|
|
1851
|
+
model EventHandlerExecution {
|
|
1852
|
+
id String @id @default(cuid())
|
|
1853
|
+
|
|
1854
|
+
/// The event being processed
|
|
1855
|
+
eventId String
|
|
1856
|
+
event WorkflowEvent @relation(fields: [eventId], references: [id], onDelete: Cascade)
|
|
1857
|
+
|
|
1858
|
+
/// The handler that processed this event
|
|
1859
|
+
handlerId String
|
|
1860
|
+
handler EventHandler @relation(fields: [handlerId], references: [id], onDelete: Cascade)
|
|
1861
|
+
|
|
1862
|
+
/// Execution status
|
|
1863
|
+
status ExecutionStatus @default(PENDING)
|
|
1864
|
+
|
|
1865
|
+
/// Attempt number (1 for first try, increments on retry)
|
|
1866
|
+
attempt Int @default(1)
|
|
1867
|
+
|
|
1868
|
+
/// Input to the handler (may be transformed payload)
|
|
1869
|
+
input Json?
|
|
1870
|
+
|
|
1871
|
+
/// Output from the handler
|
|
1872
|
+
output Json?
|
|
1873
|
+
|
|
1874
|
+
/// Error details if failed
|
|
1875
|
+
error String? @db.Text
|
|
1876
|
+
errorCode String?
|
|
1877
|
+
|
|
1878
|
+
/// Timing
|
|
1879
|
+
startedAt DateTime?
|
|
1880
|
+
completedAt DateTime?
|
|
1881
|
+
durationMs Int?
|
|
1882
|
+
|
|
1883
|
+
createdAt DateTime @default(now())
|
|
1884
|
+
|
|
1885
|
+
@@index([eventId])
|
|
1886
|
+
@@index([handlerId])
|
|
1887
|
+
@@index([status])
|
|
1888
|
+
@@map("event_handler_executions")
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1619
1891
|
// =============================================================================
|
|
1620
1892
|
// EVENT OUTBOX - For guaranteed event delivery to SQS queues
|
|
1621
1893
|
// =============================================================================
|