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