@contractspec/example.workflow-system 1.57.0 → 1.58.0

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 (209) hide show
  1. package/dist/approval/approval.enum.d.ts +2 -7
  2. package/dist/approval/approval.enum.d.ts.map +1 -1
  3. package/dist/approval/approval.enum.js +20 -26
  4. package/dist/approval/approval.event.d.ts +108 -114
  5. package/dist/approval/approval.event.d.ts.map +1 -1
  6. package/dist/approval/approval.event.js +103 -210
  7. package/dist/approval/approval.handler.d.ts +17 -18
  8. package/dist/approval/approval.handler.d.ts.map +1 -1
  9. package/dist/approval/approval.operations.d.ts +429 -435
  10. package/dist/approval/approval.operations.d.ts.map +1 -1
  11. package/dist/approval/approval.operations.js +364 -339
  12. package/dist/approval/approval.schema.d.ts +86 -91
  13. package/dist/approval/approval.schema.d.ts.map +1 -1
  14. package/dist/approval/approval.schema.js +71 -107
  15. package/dist/approval/index.d.ts +8 -5
  16. package/dist/approval/index.d.ts.map +1 -0
  17. package/dist/approval/index.js +484 -5
  18. package/dist/browser/approval/approval.enum.js +22 -0
  19. package/dist/browser/approval/approval.event.js +112 -0
  20. package/dist/browser/approval/approval.operations.js +369 -0
  21. package/dist/browser/approval/approval.schema.js +73 -0
  22. package/dist/browser/approval/index.js +484 -0
  23. package/dist/browser/docs/index.js +103 -0
  24. package/dist/browser/docs/workflow-system.docblock.js +103 -0
  25. package/dist/browser/entities/approval.js +119 -0
  26. package/dist/browser/entities/index.js +508 -0
  27. package/dist/browser/entities/instance.js +161 -0
  28. package/dist/browser/entities/step.js +124 -0
  29. package/dist/browser/entities/workflow.js +82 -0
  30. package/dist/browser/example.js +42 -0
  31. package/dist/browser/handlers/index.js +253 -0
  32. package/dist/browser/handlers/workflow.handlers.js +253 -0
  33. package/dist/browser/index.js +3120 -0
  34. package/dist/browser/instance/index.js +677 -0
  35. package/dist/browser/instance/instance.enum.js +15 -0
  36. package/dist/browser/instance/instance.event.js +164 -0
  37. package/dist/browser/instance/instance.handler.js +356 -0
  38. package/dist/browser/instance/instance.operations.js +9 -0
  39. package/dist/browser/instance/instance.schema.js +101 -0
  40. package/dist/browser/presentations/index.js +109 -0
  41. package/dist/browser/seeders/index.js +3 -0
  42. package/dist/browser/shared/index.js +3 -0
  43. package/dist/browser/shared/mock-data.js +11 -0
  44. package/dist/browser/shared/types.js +0 -0
  45. package/dist/browser/state-machine/index.js +6 -0
  46. package/dist/browser/tests/operations.test-spec.js +6 -0
  47. package/dist/browser/ui/WorkflowDashboard.js +3 -0
  48. package/dist/browser/ui/hooks/index.js +50 -0
  49. package/dist/browser/ui/hooks/useWorkflowList.js +50 -0
  50. package/dist/browser/ui/index.js +54 -0
  51. package/dist/browser/ui/renderers/index.js +227 -0
  52. package/dist/browser/ui/renderers/workflow.markdown.js +227 -0
  53. package/dist/browser/workflow/index.js +21 -0
  54. package/dist/browser/workflow/workflow.enum.js +36 -0
  55. package/dist/browser/workflow/workflow.event.js +6 -0
  56. package/dist/browser/workflow/workflow.handler.js +5 -0
  57. package/dist/browser/workflow/workflow.operations.js +8 -0
  58. package/dist/browser/workflow/workflow.schema.js +151 -0
  59. package/dist/browser/workflow-system.capability.js +5 -0
  60. package/dist/browser/workflow-system.feature.js +3 -0
  61. package/dist/docs/index.d.ts +2 -1
  62. package/dist/docs/index.d.ts.map +1 -0
  63. package/dist/docs/index.js +104 -1
  64. package/dist/docs/workflow-system.docblock.d.ts +2 -1
  65. package/dist/docs/workflow-system.docblock.d.ts.map +1 -0
  66. package/dist/docs/workflow-system.docblock.js +45 -56
  67. package/dist/entities/approval.d.ts +35 -40
  68. package/dist/entities/approval.d.ts.map +1 -1
  69. package/dist/entities/approval.js +116 -124
  70. package/dist/entities/index.d.ts +132 -137
  71. package/dist/entities/index.d.ts.map +1 -1
  72. package/dist/entities/index.js +506 -29
  73. package/dist/entities/instance.d.ts +46 -51
  74. package/dist/entities/instance.d.ts.map +1 -1
  75. package/dist/entities/instance.js +158 -164
  76. package/dist/entities/step.d.ts +31 -36
  77. package/dist/entities/step.d.ts.map +1 -1
  78. package/dist/entities/step.js +122 -132
  79. package/dist/entities/workflow.d.ts +22 -27
  80. package/dist/entities/workflow.d.ts.map +1 -1
  81. package/dist/entities/workflow.js +80 -99
  82. package/dist/example.d.ts +2 -6
  83. package/dist/example.d.ts.map +1 -1
  84. package/dist/example.js +41 -55
  85. package/dist/handlers/index.d.ts +2 -2
  86. package/dist/handlers/index.d.ts.map +1 -0
  87. package/dist/handlers/index.js +254 -3
  88. package/dist/handlers/workflow.handlers.d.ts +107 -106
  89. package/dist/handlers/workflow.handlers.d.ts.map +1 -1
  90. package/dist/handlers/workflow.handlers.js +237 -246
  91. package/dist/index.d.ts +15 -26
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +3121 -26
  94. package/dist/instance/index.d.ts +8 -5
  95. package/dist/instance/index.d.ts.map +1 -0
  96. package/dist/instance/index.js +677 -5
  97. package/dist/instance/instance.enum.d.ts +1 -6
  98. package/dist/instance/instance.enum.d.ts.map +1 -1
  99. package/dist/instance/instance.enum.js +14 -18
  100. package/dist/instance/instance.event.d.ts +313 -319
  101. package/dist/instance/instance.event.d.ts.map +1 -1
  102. package/dist/instance/instance.event.js +151 -279
  103. package/dist/instance/instance.handler.d.ts +21 -22
  104. package/dist/instance/instance.handler.d.ts.map +1 -1
  105. package/dist/instance/instance.handler.js +352 -89
  106. package/dist/instance/instance.operations.d.ts +819 -825
  107. package/dist/instance/instance.operations.d.ts.map +1 -1
  108. package/dist/instance/instance.operations.js +10 -464
  109. package/dist/instance/instance.schema.d.ts +196 -201
  110. package/dist/instance/instance.schema.d.ts.map +1 -1
  111. package/dist/instance/instance.schema.js +97 -167
  112. package/dist/presentations/index.d.ts +23 -28
  113. package/dist/presentations/index.d.ts.map +1 -1
  114. package/dist/presentations/index.js +104 -334
  115. package/dist/seeders/index.d.ts +4 -8
  116. package/dist/seeders/index.d.ts.map +1 -1
  117. package/dist/seeders/index.js +4 -19
  118. package/dist/shared/index.d.ts +6 -3
  119. package/dist/shared/index.d.ts.map +1 -0
  120. package/dist/shared/index.js +4 -3
  121. package/dist/shared/mock-data.d.ts +16 -16
  122. package/dist/shared/mock-data.d.ts.map +1 -1
  123. package/dist/shared/mock-data.js +11 -11
  124. package/dist/shared/types.d.ts +69 -72
  125. package/dist/shared/types.d.ts.map +1 -1
  126. package/dist/shared/types.js +1 -0
  127. package/dist/state-machine/index.d.ts +92 -95
  128. package/dist/state-machine/index.d.ts.map +1 -1
  129. package/dist/state-machine/index.js +6 -157
  130. package/dist/tests/operations.test-spec.d.ts +4 -9
  131. package/dist/tests/operations.test-spec.d.ts.map +1 -1
  132. package/dist/tests/operations.test-spec.js +7 -123
  133. package/dist/ui/WorkflowDashboard.d.ts +1 -6
  134. package/dist/ui/WorkflowDashboard.d.ts.map +1 -1
  135. package/dist/ui/WorkflowDashboard.js +3 -222
  136. package/dist/ui/hooks/index.d.ts +2 -2
  137. package/dist/ui/hooks/index.d.ts.map +1 -0
  138. package/dist/ui/hooks/index.js +51 -5
  139. package/dist/ui/hooks/useWorkflowList.d.ts +15 -19
  140. package/dist/ui/hooks/useWorkflowList.d.ts.map +1 -1
  141. package/dist/ui/hooks/useWorkflowList.js +47 -51
  142. package/dist/ui/index.d.ts +7 -6
  143. package/dist/ui/index.d.ts.map +1 -0
  144. package/dist/ui/index.js +55 -6
  145. package/dist/ui/renderers/index.d.ts +2 -2
  146. package/dist/ui/renderers/index.d.ts.map +1 -0
  147. package/dist/ui/renderers/index.js +227 -2
  148. package/dist/ui/renderers/workflow.markdown.d.ts +13 -14
  149. package/dist/ui/renderers/workflow.markdown.d.ts.map +1 -1
  150. package/dist/ui/renderers/workflow.markdown.js +223 -229
  151. package/dist/workflow/index.d.ts +8 -5
  152. package/dist/workflow/index.d.ts.map +1 -0
  153. package/dist/workflow/index.js +22 -6
  154. package/dist/workflow/workflow.enum.d.ts +4 -9
  155. package/dist/workflow/workflow.enum.d.ts.map +1 -1
  156. package/dist/workflow/workflow.enum.js +32 -42
  157. package/dist/workflow/workflow.event.d.ts +112 -118
  158. package/dist/workflow/workflow.event.d.ts.map +1 -1
  159. package/dist/workflow/workflow.event.js +7 -150
  160. package/dist/workflow/workflow.handler.d.ts +23 -24
  161. package/dist/workflow/workflow.handler.d.ts.map +1 -1
  162. package/dist/workflow/workflow.handler.js +6 -66
  163. package/dist/workflow/workflow.operations.d.ts +847 -853
  164. package/dist/workflow/workflow.operations.d.ts.map +1 -1
  165. package/dist/workflow/workflow.operations.js +9 -345
  166. package/dist/workflow/workflow.schema.d.ts +229 -234
  167. package/dist/workflow/workflow.schema.d.ts.map +1 -1
  168. package/dist/workflow/workflow.schema.js +146 -243
  169. package/dist/workflow-system.capability.d.ts +3 -8
  170. package/dist/workflow-system.capability.d.ts.map +1 -1
  171. package/dist/workflow-system.capability.js +6 -34
  172. package/dist/workflow-system.feature.d.ts +1 -6
  173. package/dist/workflow-system.feature.d.ts.map +1 -1
  174. package/dist/workflow-system.feature.js +4 -346
  175. package/package.json +415 -93
  176. package/dist/approval/approval.enum.js.map +0 -1
  177. package/dist/approval/approval.event.js.map +0 -1
  178. package/dist/approval/approval.handler.js +0 -72
  179. package/dist/approval/approval.handler.js.map +0 -1
  180. package/dist/approval/approval.operations.js.map +0 -1
  181. package/dist/approval/approval.schema.js.map +0 -1
  182. package/dist/docs/workflow-system.docblock.js.map +0 -1
  183. package/dist/entities/approval.js.map +0 -1
  184. package/dist/entities/index.js.map +0 -1
  185. package/dist/entities/instance.js.map +0 -1
  186. package/dist/entities/step.js.map +0 -1
  187. package/dist/entities/workflow.js.map +0 -1
  188. package/dist/example.js.map +0 -1
  189. package/dist/handlers/workflow.handlers.js.map +0 -1
  190. package/dist/instance/instance.enum.js.map +0 -1
  191. package/dist/instance/instance.event.js.map +0 -1
  192. package/dist/instance/instance.handler.js.map +0 -1
  193. package/dist/instance/instance.operations.js.map +0 -1
  194. package/dist/instance/instance.schema.js.map +0 -1
  195. package/dist/presentations/index.js.map +0 -1
  196. package/dist/seeders/index.js.map +0 -1
  197. package/dist/shared/mock-data.js.map +0 -1
  198. package/dist/state-machine/index.js.map +0 -1
  199. package/dist/tests/operations.test-spec.js.map +0 -1
  200. package/dist/ui/WorkflowDashboard.js.map +0 -1
  201. package/dist/ui/hooks/useWorkflowList.js.map +0 -1
  202. package/dist/ui/renderers/workflow.markdown.js.map +0 -1
  203. package/dist/workflow/workflow.enum.js.map +0 -1
  204. package/dist/workflow/workflow.event.js.map +0 -1
  205. package/dist/workflow/workflow.handler.js.map +0 -1
  206. package/dist/workflow/workflow.operations.js.map +0 -1
  207. package/dist/workflow/workflow.schema.js.map +0 -1
  208. package/dist/workflow-system.capability.js.map +0 -1
  209. package/dist/workflow-system.feature.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,26 +1,3121 @@
1
- import { ApprovalModeEnum, StepTypeEnum, TriggerTypeEnum, WorkflowStatusEnum } from "./workflow/workflow.enum.js";
2
- import { AddStepInputModel, CreateWorkflowInputModel, UpdateWorkflowInputModel, WorkflowDefinitionModel, WorkflowStepModel } from "./workflow/workflow.schema.js";
3
- import { AddStepContract, CreateWorkflowContract, GetWorkflowContract, ListWorkflowsContract, PublishWorkflowContract, UpdateWorkflowContract } from "./workflow/workflow.operations.js";
4
- import { StepAddedEvent, WorkflowCreatedEvent, WorkflowPublishedEvent, WorkflowUpdatedEvent } from "./workflow/workflow.event.js";
5
- import "./workflow/index.js";
6
- import { InstanceStatusEnum } from "./instance/instance.enum.js";
7
- import { StartWorkflowInputModel, TransitionInputModel, TransitionResultModel, WorkflowInstanceModel } from "./instance/instance.schema.js";
8
- import { CancelWorkflowContract, GetInstanceContract, ListInstancesContract, PauseWorkflowContract, ResumeWorkflowContract, StartWorkflowContract, TransitionWorkflowContract } from "./instance/instance.operations.js";
9
- import { InstanceCancelledEvent, InstanceCompletedEvent, InstanceFailedEvent, InstancePausedEvent, InstanceResumedEvent, InstanceStartedEvent, InstanceTimedOutEvent, StepEnteredEvent, StepExitedEvent } from "./instance/instance.event.js";
10
- import "./instance/index.js";
11
- import { ApprovalDecisionEnum, ApprovalStatusEnum } from "./approval/approval.enum.js";
12
- import { ApprovalCommentModel, ApprovalRequestModel } from "./approval/approval.schema.js";
13
- import { AddApprovalCommentContract, DelegateApprovalContract, GetApprovalContract, ListMyApprovalsContract, SubmitDecisionContract } from "./approval/approval.operations.js";
14
- import { ApprovalDecidedEvent, ApprovalDelegatedEvent, ApprovalEscalatedEvent, ApprovalRequestedEvent } from "./approval/approval.event.js";
15
- import "./approval/index.js";
16
- import { mockDataStore } from "./shared/mock-data.js";
17
- import { createWorkflowHandlers } from "./handlers/workflow.handlers.js";
18
- import { BasicStateMachineEngine, buildStateMachineDefinition, createInitialState, createStateMachineEngine } from "./state-machine/index.js";
19
- import { ApprovalDetailPresentation, ApprovalFormPresentation, ApprovalInboxPresentation, InstanceDetailPresentation, InstanceListPresentation, PendingApprovalsBadgePresentation, ProgressTrackerPresentation, WorkflowDesignerPresentation, WorkflowDetailPresentation, WorkflowListPresentation, WorkflowMetricsPresentation, WorkflowSystemPresentations } from "./presentations/index.js";
20
- import { WorkflowSystemFeature } from "./workflow-system.feature.js";
21
- import { workflowDashboardMarkdownRenderer, workflowDefinitionListMarkdownRenderer, workflowInstanceDetailMarkdownRenderer } from "./ui/renderers/workflow.markdown.js";
22
- import { useWorkflowList } from "./ui/hooks/useWorkflowList.js";
23
- import { WorkflowDashboard } from "./ui/WorkflowDashboard.js";
24
- import "./ui/index.js";
25
-
26
- export { AddApprovalCommentContract, AddStepContract, AddStepInputModel, ApprovalCommentModel, ApprovalDecidedEvent, ApprovalDecisionEnum, ApprovalDelegatedEvent, ApprovalDetailPresentation, ApprovalEscalatedEvent, ApprovalFormPresentation, ApprovalInboxPresentation, ApprovalModeEnum, ApprovalRequestModel, ApprovalRequestedEvent, ApprovalStatusEnum, BasicStateMachineEngine, CancelWorkflowContract, CreateWorkflowContract, CreateWorkflowInputModel, DelegateApprovalContract, GetApprovalContract, GetInstanceContract, GetWorkflowContract, InstanceCancelledEvent, InstanceCompletedEvent, InstanceDetailPresentation, InstanceFailedEvent, InstanceListPresentation, InstancePausedEvent, InstanceResumedEvent, InstanceStartedEvent, InstanceStatusEnum, InstanceTimedOutEvent, ListInstancesContract, ListMyApprovalsContract, ListWorkflowsContract, PauseWorkflowContract, PendingApprovalsBadgePresentation, ProgressTrackerPresentation, PublishWorkflowContract, ResumeWorkflowContract, StartWorkflowContract, StartWorkflowInputModel, StepAddedEvent, StepEnteredEvent, StepExitedEvent, StepTypeEnum, SubmitDecisionContract, TransitionInputModel, TransitionResultModel, TransitionWorkflowContract, TriggerTypeEnum, UpdateWorkflowContract, UpdateWorkflowInputModel, WorkflowCreatedEvent, WorkflowDashboard, WorkflowDefinitionModel, WorkflowDesignerPresentation, WorkflowDetailPresentation, WorkflowInstanceModel, WorkflowListPresentation, WorkflowMetricsPresentation, WorkflowPublishedEvent, WorkflowStatusEnum, WorkflowStepModel, WorkflowSystemFeature, WorkflowSystemPresentations, WorkflowUpdatedEvent, buildStateMachineDefinition, createInitialState, createStateMachineEngine, createWorkflowHandlers, mockDataStore, useWorkflowList, workflowDashboardMarkdownRenderer, workflowDefinitionListMarkdownRenderer, workflowInstanceDetailMarkdownRenderer };
1
+ // @bun
2
+ // src/approval/approval.enum.ts
3
+ import { defineEnum } from "@contractspec/lib.schema";
4
+ var ApprovalStatusEnum = defineEnum("ApprovalStatus", [
5
+ "PENDING",
6
+ "APPROVED",
7
+ "REJECTED",
8
+ "DELEGATED",
9
+ "ESCALATED",
10
+ "WITHDRAWN",
11
+ "EXPIRED"
12
+ ]);
13
+ var ApprovalDecisionEnum = defineEnum("ApprovalDecision", [
14
+ "APPROVE",
15
+ "REJECT",
16
+ "REQUEST_CHANGES",
17
+ "DELEGATE",
18
+ "ABSTAIN"
19
+ ]);
20
+
21
+ // src/approval/approval.event.ts
22
+ import { defineEvent, defineSchemaModel } from "@contractspec/lib.contracts";
23
+ import { ScalarTypeEnum } from "@contractspec/lib.schema";
24
+ var ApprovalRequestedPayload = defineSchemaModel({
25
+ name: "ApprovalRequestedEventPayload",
26
+ description: "Payload when approval is requested",
27
+ fields: {
28
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
29
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
30
+ workflowKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
31
+ approverId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
32
+ approverRole: {
33
+ type: ScalarTypeEnum.String_unsecure(),
34
+ isOptional: true
35
+ },
36
+ title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
+ dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
38
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
39
+ }
40
+ });
41
+ var ApprovalDecidedPayload = defineSchemaModel({
42
+ name: "ApprovalDecidedEventPayload",
43
+ description: "Payload when approval decision is made",
44
+ fields: {
45
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
46
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
47
+ decision: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
48
+ decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
49
+ comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
50
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
51
+ }
52
+ });
53
+ var ApprovalDelegatedPayload = defineSchemaModel({
54
+ name: "ApprovalDelegatedEventPayload",
55
+ description: "Payload when approval is delegated",
56
+ fields: {
57
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
58
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
+ fromUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
60
+ toUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
62
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
63
+ }
64
+ });
65
+ var ApprovalEscalatedPayload = defineSchemaModel({
66
+ name: "ApprovalEscalatedEventPayload",
67
+ description: "Payload when approval is escalated",
68
+ fields: {
69
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
70
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
71
+ escalationLevel: {
72
+ type: ScalarTypeEnum.Int_unsecure(),
73
+ isOptional: false
74
+ },
75
+ escalatedTo: {
76
+ type: ScalarTypeEnum.String_unsecure(),
77
+ isOptional: false
78
+ },
79
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
80
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
81
+ }
82
+ });
83
+ var ApprovalRequestedEvent = defineEvent({
84
+ meta: {
85
+ key: "workflow.approval.requested",
86
+ version: "1.0.0",
87
+ description: "An approval has been requested.",
88
+ stability: "stable",
89
+ owners: ["@workflow-team"],
90
+ tags: ["workflow", "approval", "requested"]
91
+ },
92
+ payload: ApprovalRequestedPayload
93
+ });
94
+ var ApprovalDecidedEvent = defineEvent({
95
+ meta: {
96
+ key: "workflow.approval.decided",
97
+ version: "1.0.0",
98
+ description: "An approval decision has been made.",
99
+ stability: "stable",
100
+ owners: ["@workflow-team"],
101
+ tags: ["workflow", "approval", "decided"]
102
+ },
103
+ payload: ApprovalDecidedPayload
104
+ });
105
+ var ApprovalDelegatedEvent = defineEvent({
106
+ meta: {
107
+ key: "workflow.approval.delegated",
108
+ version: "1.0.0",
109
+ description: "An approval has been delegated.",
110
+ stability: "stable",
111
+ owners: ["@workflow-team"],
112
+ tags: ["workflow", "approval", "delegated"]
113
+ },
114
+ payload: ApprovalDelegatedPayload
115
+ });
116
+ var ApprovalEscalatedEvent = defineEvent({
117
+ meta: {
118
+ key: "workflow.approval.escalated",
119
+ version: "1.0.0",
120
+ description: "An approval has been escalated.",
121
+ stability: "stable",
122
+ owners: ["@workflow-team"],
123
+ tags: ["workflow", "approval", "escalated"]
124
+ },
125
+ payload: ApprovalEscalatedPayload
126
+ });
127
+
128
+ // src/shared/mock-data.ts
129
+ var mockDataStore = {
130
+ workflows: new Map,
131
+ steps: new Map,
132
+ instances: new Map,
133
+ approvals: new Map,
134
+ stepExecutions: new Map
135
+ };
136
+
137
+ // src/state-machine/index.ts
138
+ class BasicStateMachineEngine {
139
+ canTransition(definition, state, action, context) {
140
+ if (state.status !== "RUNNING" && state.status !== "WAITING") {
141
+ return {
142
+ allowed: false,
143
+ reason: `Workflow is ${state.status}, cannot transition`
144
+ };
145
+ }
146
+ const currentStep = definition.steps[state.currentStepKey];
147
+ if (!currentStep) {
148
+ return {
149
+ allowed: false,
150
+ reason: `Step ${state.currentStepKey} not found`
151
+ };
152
+ }
153
+ const transition = currentStep.transitions[action];
154
+ if (!transition) {
155
+ return {
156
+ allowed: false,
157
+ reason: `Action ${action} not available in step ${state.currentStepKey}`
158
+ };
159
+ }
160
+ if (currentStep.allowedRoles && currentStep.allowedRoles.length > 0) {
161
+ const hasRole = currentStep.allowedRoles.some((role) => context.userRoles.includes(role));
162
+ if (!hasRole) {
163
+ return {
164
+ allowed: false,
165
+ reason: `User lacks required role for this action`
166
+ };
167
+ }
168
+ }
169
+ if (typeof transition === "object" && transition.allowedRoles && transition.allowedRoles.length > 0) {
170
+ const hasRole = transition.allowedRoles.some((role) => context.userRoles.includes(role));
171
+ if (!hasRole) {
172
+ return {
173
+ allowed: false,
174
+ reason: `User lacks required role for action ${action}`
175
+ };
176
+ }
177
+ }
178
+ return { allowed: true };
179
+ }
180
+ getAvailableActions(definition, state, context) {
181
+ if (state.status !== "RUNNING" && state.status !== "WAITING") {
182
+ return [];
183
+ }
184
+ const currentStep = definition.steps[state.currentStepKey];
185
+ if (!currentStep) {
186
+ return [];
187
+ }
188
+ return Object.keys(currentStep.transitions).filter((action) => {
189
+ const result = this.canTransition(definition, state, action, context);
190
+ return result.allowed;
191
+ });
192
+ }
193
+ transition(definition, state, action, context) {
194
+ const validation = this.canTransition(definition, state, action, context);
195
+ if (!validation.allowed) {
196
+ return {
197
+ success: false,
198
+ previousStepKey: state.currentStepKey,
199
+ currentStepKey: state.currentStepKey,
200
+ status: state.status,
201
+ error: validation.reason
202
+ };
203
+ }
204
+ const currentStep = definition.steps[state.currentStepKey];
205
+ if (!currentStep) {
206
+ return {
207
+ success: false,
208
+ previousStepKey: state.currentStepKey,
209
+ currentStepKey: state.currentStepKey,
210
+ status: state.status,
211
+ error: `Current step ${state.currentStepKey} not found`
212
+ };
213
+ }
214
+ const transition = currentStep.transitions[action];
215
+ if (!transition) {
216
+ return {
217
+ success: false,
218
+ previousStepKey: state.currentStepKey,
219
+ currentStepKey: state.currentStepKey,
220
+ status: state.status,
221
+ error: `Transition for action ${action} not found`
222
+ };
223
+ }
224
+ const targetStepKey = typeof transition === "string" ? transition : transition.targetStepKey;
225
+ const targetStep = definition.steps[targetStepKey];
226
+ if (!targetStep) {
227
+ return {
228
+ success: false,
229
+ previousStepKey: state.currentStepKey,
230
+ currentStepKey: state.currentStepKey,
231
+ status: state.status,
232
+ error: `Target step ${targetStepKey} not found`
233
+ };
234
+ }
235
+ let newStatus = "RUNNING";
236
+ if (targetStep.type === "END") {
237
+ newStatus = "COMPLETED";
238
+ } else if (targetStep.type === "APPROVAL" || targetStep.type === "WAIT") {
239
+ newStatus = "WAITING";
240
+ }
241
+ return {
242
+ success: true,
243
+ previousStepKey: state.currentStepKey,
244
+ currentStepKey: targetStepKey,
245
+ status: newStatus
246
+ };
247
+ }
248
+ evaluateCondition(expression, contextData) {
249
+ try {
250
+ const match = expression.match(/^(\w+)\s*(>=|<=|>|<|===|!==|==|!=)\s*(.+)$/);
251
+ if (match) {
252
+ const [, prop, operator, value] = match;
253
+ if (!prop || !operator || value === undefined) {
254
+ return false;
255
+ }
256
+ const propValue = contextData[prop];
257
+ const compareValue = JSON.parse(value);
258
+ switch (operator) {
259
+ case ">":
260
+ return Number(propValue) > Number(compareValue);
261
+ case "<":
262
+ return Number(propValue) < Number(compareValue);
263
+ case ">=":
264
+ return Number(propValue) >= Number(compareValue);
265
+ case "<=":
266
+ return Number(propValue) <= Number(compareValue);
267
+ case "===":
268
+ case "==":
269
+ return propValue === compareValue;
270
+ case "!==":
271
+ case "!=":
272
+ return propValue !== compareValue;
273
+ }
274
+ }
275
+ if (expression in contextData) {
276
+ return Boolean(contextData[expression]);
277
+ }
278
+ return false;
279
+ } catch {
280
+ return false;
281
+ }
282
+ }
283
+ }
284
+ function createStateMachineEngine() {
285
+ return new BasicStateMachineEngine;
286
+ }
287
+ function buildStateMachineDefinition(workflow, steps) {
288
+ const stepMap = {};
289
+ for (const step of steps) {
290
+ stepMap[step.key] = {
291
+ key: step.key,
292
+ name: step.name,
293
+ type: step.type,
294
+ transitions: step.transitions,
295
+ approvalMode: step.approvalMode,
296
+ allowedRoles: step.approverRoles,
297
+ timeoutSeconds: step.timeoutSeconds,
298
+ conditionExpression: step.conditionExpression
299
+ };
300
+ }
301
+ const startStep = steps.find((s) => s.type === "START");
302
+ const initialStepKey = startStep?.key ?? steps[0]?.key ?? "";
303
+ return {
304
+ key: workflow.key,
305
+ name: workflow.name,
306
+ version: workflow.version,
307
+ initialStepKey,
308
+ steps: stepMap
309
+ };
310
+ }
311
+ function createInitialState(definition, contextData = {}) {
312
+ return {
313
+ currentStepKey: definition.initialStepKey,
314
+ status: "RUNNING",
315
+ contextData,
316
+ history: []
317
+ };
318
+ }
319
+
320
+ // src/approval/approval.schema.ts
321
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
322
+ var ApprovalRequestModel = defineSchemaModel2({
323
+ name: "ApprovalRequestModel",
324
+ description: "An approval request",
325
+ fields: {
326
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
327
+ workflowInstanceId: {
328
+ type: ScalarTypeEnum2.String_unsecure(),
329
+ isOptional: false
330
+ },
331
+ stepExecutionId: {
332
+ type: ScalarTypeEnum2.String_unsecure(),
333
+ isOptional: false
334
+ },
335
+ approverId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
336
+ approverRole: {
337
+ type: ScalarTypeEnum2.String_unsecure(),
338
+ isOptional: true
339
+ },
340
+ title: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
341
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
342
+ status: { type: ApprovalStatusEnum, isOptional: false },
343
+ decision: { type: ApprovalDecisionEnum, isOptional: true },
344
+ decisionComment: {
345
+ type: ScalarTypeEnum2.String_unsecure(),
346
+ isOptional: true
347
+ },
348
+ decidedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
349
+ dueAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
350
+ contextSnapshot: { type: ScalarTypeEnum2.JSON(), isOptional: true },
351
+ sequenceOrder: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
352
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
353
+ }
354
+ });
355
+ var ApprovalCommentModel = defineSchemaModel2({
356
+ name: "ApprovalCommentModel",
357
+ description: "A comment on an approval",
358
+ fields: {
359
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
360
+ approvalRequestId: {
361
+ type: ScalarTypeEnum2.String_unsecure(),
362
+ isOptional: false
363
+ },
364
+ authorId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
365
+ content: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
366
+ isInternal: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
367
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
368
+ }
369
+ });
370
+
371
+ // src/approval/approval.operations.ts
372
+ import {
373
+ defineCommand,
374
+ defineQuery
375
+ } from "@contractspec/lib.contracts/operations";
376
+ import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
377
+ var OWNERS = ["@example.workflow-system"];
378
+ var SubmitDecisionContract = defineCommand({
379
+ meta: {
380
+ key: "workflow.approval.decide",
381
+ version: "1.0.0",
382
+ stability: "stable",
383
+ owners: [...OWNERS],
384
+ tags: ["workflow", "approval", "decision"],
385
+ description: "Submit an approval decision (approve/reject).",
386
+ goal: "Allow approvers to make decisions on requests.",
387
+ context: "Approval inbox, workflow detail."
388
+ },
389
+ io: {
390
+ input: defineSchemaModel3({
391
+ name: "ApproveRejectInput",
392
+ fields: {
393
+ requestId: {
394
+ type: ScalarTypeEnum3.String_unsecure(),
395
+ isOptional: false
396
+ },
397
+ decision: { type: ApprovalDecisionEnum, isOptional: false },
398
+ comment: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
399
+ data: { type: ScalarTypeEnum3.JSON(), isOptional: true }
400
+ }
401
+ }),
402
+ output: ApprovalRequestModel
403
+ },
404
+ policy: { auth: "user" },
405
+ sideEffects: {
406
+ emits: [
407
+ {
408
+ key: "workflow.approval.decided",
409
+ version: "1.0.0",
410
+ when: "Decision is made",
411
+ payload: ApprovalRequestModel
412
+ }
413
+ ],
414
+ audit: ["workflow.approval.decided"]
415
+ },
416
+ acceptance: {
417
+ scenarios: [
418
+ {
419
+ key: "approve-request-happy-path",
420
+ given: ["Approval request is pending", "User is assignee"],
421
+ when: ["User approves request"],
422
+ then: ["Request is approved", "ApprovalDecided event is emitted"]
423
+ }
424
+ ],
425
+ examples: [
426
+ {
427
+ key: "approve-basic",
428
+ input: {
429
+ requestId: "req-123",
430
+ decision: "approve",
431
+ comment: "Looks good"
432
+ },
433
+ output: { id: "req-123", status: "approved" }
434
+ }
435
+ ]
436
+ }
437
+ });
438
+ var DelegateApprovalContract = defineCommand({
439
+ meta: {
440
+ key: "workflow.approval.delegate",
441
+ version: "1.0.0",
442
+ stability: "stable",
443
+ owners: [...OWNERS],
444
+ tags: ["workflow", "approval", "delegate"],
445
+ description: "Delegate an approval request to another user.",
446
+ goal: "Allow approvers to pass approval to others.",
447
+ context: "Approval inbox."
448
+ },
449
+ io: {
450
+ input: defineSchemaModel3({
451
+ name: "DelegateInput",
452
+ fields: {
453
+ requestId: {
454
+ type: ScalarTypeEnum3.String_unsecure(),
455
+ isOptional: false
456
+ },
457
+ delegateTo: {
458
+ type: ScalarTypeEnum3.String_unsecure(),
459
+ isOptional: false
460
+ },
461
+ reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
462
+ }
463
+ }),
464
+ output: ApprovalRequestModel
465
+ },
466
+ policy: { auth: "user" },
467
+ sideEffects: {
468
+ emits: [
469
+ {
470
+ key: "workflow.approval.delegated",
471
+ version: "1.0.0",
472
+ when: "Approval is delegated",
473
+ payload: ApprovalRequestModel
474
+ }
475
+ ],
476
+ audit: ["workflow.approval.delegated"]
477
+ },
478
+ acceptance: {
479
+ scenarios: [
480
+ {
481
+ key: "delegate-approval-happy-path",
482
+ given: ["Approval request is pending", "User is assignee"],
483
+ when: ["User delegates to another user"],
484
+ then: ["Assignee is updated", "ApprovalDelegated event is emitted"]
485
+ }
486
+ ],
487
+ examples: [
488
+ {
489
+ key: "delegate-to-manager",
490
+ input: {
491
+ requestId: "req-123",
492
+ delegateTo: "user-456",
493
+ reason: "Out of office"
494
+ },
495
+ output: { id: "req-123", assigneeId: "user-456" }
496
+ }
497
+ ]
498
+ }
499
+ });
500
+ var AddApprovalCommentContract = defineCommand({
501
+ meta: {
502
+ key: "workflow.approval.comment.add",
503
+ version: "1.0.0",
504
+ stability: "stable",
505
+ owners: [...OWNERS],
506
+ tags: ["workflow", "approval", "comment"],
507
+ description: "Add a comment to an approval request.",
508
+ goal: "Allow discussion on approval requests.",
509
+ context: "Approval detail view."
510
+ },
511
+ io: {
512
+ input: defineSchemaModel3({
513
+ name: "AddCommentInput",
514
+ fields: {
515
+ requestId: {
516
+ type: ScalarTypeEnum3.String_unsecure(),
517
+ isOptional: false
518
+ },
519
+ content: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
520
+ isInternal: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
521
+ }
522
+ }),
523
+ output: ApprovalCommentModel
524
+ },
525
+ policy: { auth: "user" },
526
+ sideEffects: {
527
+ emits: [
528
+ {
529
+ key: "workflow.approval.comment.added",
530
+ version: "1.0.0",
531
+ when: "Comment is added",
532
+ payload: ApprovalCommentModel
533
+ }
534
+ ]
535
+ },
536
+ acceptance: {
537
+ scenarios: [
538
+ {
539
+ key: "add-comment-happy-path",
540
+ given: ["Approval request exists"],
541
+ when: ["User adds a comment"],
542
+ then: ["Comment is added", "CommentAdded event is emitted"]
543
+ }
544
+ ],
545
+ examples: [
546
+ {
547
+ key: "add-question",
548
+ input: {
549
+ requestId: "req-123",
550
+ content: "Can you clarify budget?",
551
+ isInternal: false
552
+ },
553
+ output: { id: "com-789", content: "Can you clarify budget?" }
554
+ }
555
+ ]
556
+ }
557
+ });
558
+ var ListMyApprovalsContract = defineQuery({
559
+ meta: {
560
+ key: "workflow.approval.list.mine",
561
+ version: "1.0.0",
562
+ stability: "stable",
563
+ owners: [...OWNERS],
564
+ tags: ["workflow", "approval", "list", "inbox"],
565
+ description: "List approval requests assigned to current user.",
566
+ goal: "Show pending approvals in user inbox.",
567
+ context: "Approval inbox, dashboard widget."
568
+ },
569
+ io: {
570
+ input: defineSchemaModel3({
571
+ name: "ListMyApprovalsInput",
572
+ fields: {
573
+ status: { type: ApprovalStatusEnum, isOptional: true },
574
+ limit: {
575
+ type: ScalarTypeEnum3.Int_unsecure(),
576
+ isOptional: true,
577
+ defaultValue: 20
578
+ },
579
+ offset: {
580
+ type: ScalarTypeEnum3.Int_unsecure(),
581
+ isOptional: true,
582
+ defaultValue: 0
583
+ }
584
+ }
585
+ }),
586
+ output: defineSchemaModel3({
587
+ name: "ListMyApprovalsOutput",
588
+ fields: {
589
+ requests: {
590
+ type: ApprovalRequestModel,
591
+ isArray: true,
592
+ isOptional: false
593
+ },
594
+ total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
595
+ pendingCount: {
596
+ type: ScalarTypeEnum3.Int_unsecure(),
597
+ isOptional: false
598
+ }
599
+ }
600
+ })
601
+ },
602
+ policy: { auth: "user" },
603
+ acceptance: {
604
+ scenarios: [
605
+ {
606
+ key: "list-approvals-happy-path",
607
+ given: ["User has assigned approvals"],
608
+ when: ["User lists approvals"],
609
+ then: ["List of requests is returned"]
610
+ }
611
+ ],
612
+ examples: [
613
+ {
614
+ key: "list-pending",
615
+ input: { status: "pending", limit: 10 },
616
+ output: { requests: [], total: 2, pendingCount: 2 }
617
+ }
618
+ ]
619
+ }
620
+ });
621
+ var GetApprovalContract = defineQuery({
622
+ meta: {
623
+ key: "workflow.approval.get",
624
+ version: "1.0.0",
625
+ stability: "stable",
626
+ owners: [...OWNERS],
627
+ tags: ["workflow", "approval", "get"],
628
+ description: "Get an approval request with details.",
629
+ goal: "View approval request details.",
630
+ context: "Approval detail view."
631
+ },
632
+ io: {
633
+ input: defineSchemaModel3({
634
+ name: "GetApprovalInput",
635
+ fields: {
636
+ requestId: {
637
+ type: ScalarTypeEnum3.String_unsecure(),
638
+ isOptional: false
639
+ }
640
+ }
641
+ }),
642
+ output: ApprovalRequestModel
643
+ },
644
+ policy: { auth: "user" },
645
+ acceptance: {
646
+ scenarios: [
647
+ {
648
+ key: "get-approval-happy-path",
649
+ given: ["Approval request exists"],
650
+ when: ["User requests approval details"],
651
+ then: ["Approval details are returned"]
652
+ }
653
+ ],
654
+ examples: [
655
+ {
656
+ key: "get-basic",
657
+ input: { requestId: "req-123" },
658
+ output: { id: "req-123", status: "pending" }
659
+ }
660
+ ]
661
+ }
662
+ });
663
+ // src/handlers/workflow.handlers.ts
664
+ import { web } from "@contractspec/lib.runtime-sandbox";
665
+ var { generateId } = web;
666
+ function rowToDefinition(row) {
667
+ return {
668
+ id: row.id,
669
+ projectId: row.projectId,
670
+ organizationId: row.organizationId,
671
+ name: row.name,
672
+ description: row.description ?? undefined,
673
+ type: row.type,
674
+ status: row.status,
675
+ createdAt: new Date(row.createdAt),
676
+ updatedAt: new Date(row.updatedAt)
677
+ };
678
+ }
679
+ function rowToStep(row) {
680
+ return {
681
+ id: row.id,
682
+ definitionId: row.definitionId,
683
+ name: row.name,
684
+ description: row.description ?? undefined,
685
+ stepOrder: row.stepOrder,
686
+ type: row.type,
687
+ requiredRoles: row.requiredRoles ? JSON.parse(row.requiredRoles) : [],
688
+ autoApproveCondition: row.autoApproveCondition ?? undefined,
689
+ timeoutHours: row.timeoutHours ?? undefined,
690
+ createdAt: new Date(row.createdAt)
691
+ };
692
+ }
693
+ function rowToInstance(row) {
694
+ return {
695
+ id: row.id,
696
+ projectId: row.projectId,
697
+ definitionId: row.definitionId,
698
+ status: row.status,
699
+ currentStepId: row.currentStepId ?? undefined,
700
+ data: row.data ? JSON.parse(row.data) : undefined,
701
+ requestedBy: row.requestedBy,
702
+ startedAt: new Date(row.startedAt),
703
+ completedAt: row.completedAt ? new Date(row.completedAt) : undefined
704
+ };
705
+ }
706
+ function rowToApproval(row) {
707
+ return {
708
+ id: row.id,
709
+ instanceId: row.instanceId,
710
+ stepId: row.stepId,
711
+ status: row.status,
712
+ actorId: row.actorId ?? undefined,
713
+ comment: row.comment ?? undefined,
714
+ decidedAt: row.decidedAt ? new Date(row.decidedAt) : undefined,
715
+ createdAt: new Date(row.createdAt)
716
+ };
717
+ }
718
+ function createWorkflowHandlers(db) {
719
+ async function listDefinitions(input) {
720
+ const { projectId, status, search, limit = 20, offset = 0 } = input;
721
+ let whereClause = "WHERE projectId = ?";
722
+ const params = [projectId];
723
+ if (status && status !== "all") {
724
+ whereClause += " AND status = ?";
725
+ params.push(status);
726
+ }
727
+ if (search) {
728
+ whereClause += " AND name LIKE ?";
729
+ params.push(`%${search}%`);
730
+ }
731
+ const countResult = (await db.query(`SELECT COUNT(*) as count FROM workflow_definition ${whereClause}`, params)).rows;
732
+ const total = countResult[0]?.count ?? 0;
733
+ const rows = (await db.query(`SELECT * FROM workflow_definition ${whereClause} ORDER BY updatedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
734
+ return {
735
+ definitions: rows.map(rowToDefinition),
736
+ total
737
+ };
738
+ }
739
+ async function createDefinition(input, context) {
740
+ const id = generateId("wfdef");
741
+ const now = new Date().toISOString();
742
+ await db.execute(`INSERT INTO workflow_definition (id, projectId, organizationId, name, description, type, status, createdAt, updatedAt)
743
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
744
+ id,
745
+ context.projectId,
746
+ context.organizationId,
747
+ input.name,
748
+ input.description ?? null,
749
+ input.type ?? "APPROVAL",
750
+ "DRAFT",
751
+ now,
752
+ now
753
+ ]);
754
+ const rows = (await db.query(`SELECT * FROM workflow_definition WHERE id = ?`, [id])).rows;
755
+ return rowToDefinition(rows[0]);
756
+ }
757
+ async function addStep(input) {
758
+ const id = generateId("wfstep");
759
+ const now = new Date().toISOString();
760
+ const maxOrderResult = (await db.query(`SELECT MAX(stepOrder) as maxOrder FROM workflow_step WHERE definitionId = ?`, [input.definitionId])).rows;
761
+ const nextOrder = (maxOrderResult[0]?.maxOrder ?? 0) + 1;
762
+ await db.execute(`INSERT INTO workflow_step (id, definitionId, name, description, stepOrder, type, requiredRoles, autoApproveCondition, timeoutHours, createdAt)
763
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
764
+ id,
765
+ input.definitionId,
766
+ input.name,
767
+ input.description ?? null,
768
+ nextOrder,
769
+ input.type ?? "APPROVAL",
770
+ JSON.stringify(input.requiredRoles),
771
+ input.autoApproveCondition ?? null,
772
+ input.timeoutHours ?? null,
773
+ now
774
+ ]);
775
+ const rows = (await db.query(`SELECT * FROM workflow_step WHERE id = ?`, [id])).rows;
776
+ return rowToStep(rows[0]);
777
+ }
778
+ async function getSteps(definitionId) {
779
+ const rows = (await db.query(`SELECT * FROM workflow_step WHERE definitionId = ? ORDER BY stepOrder`, [definitionId])).rows;
780
+ return rows.map(rowToStep);
781
+ }
782
+ async function listInstances(input) {
783
+ const {
784
+ projectId,
785
+ definitionId,
786
+ status,
787
+ requestedBy,
788
+ limit = 20,
789
+ offset = 0
790
+ } = input;
791
+ let whereClause = "WHERE projectId = ?";
792
+ const params = [projectId];
793
+ if (definitionId) {
794
+ whereClause += " AND definitionId = ?";
795
+ params.push(definitionId);
796
+ }
797
+ if (status && status !== "all") {
798
+ whereClause += " AND status = ?";
799
+ params.push(status);
800
+ }
801
+ if (requestedBy) {
802
+ whereClause += " AND requestedBy = ?";
803
+ params.push(requestedBy);
804
+ }
805
+ const countResult = (await db.query(`SELECT COUNT(*) as count FROM workflow_instance ${whereClause}`, params)).rows;
806
+ const total = countResult[0]?.count ?? 0;
807
+ const rows = (await db.query(`SELECT * FROM workflow_instance ${whereClause} ORDER BY startedAt DESC LIMIT ? OFFSET ?`, [...params, limit, offset])).rows;
808
+ return {
809
+ instances: rows.map(rowToInstance),
810
+ total
811
+ };
812
+ }
813
+ async function startInstance(input, context) {
814
+ const id = generateId("wfinst");
815
+ const now = new Date().toISOString();
816
+ const steps = (await db.query(`SELECT * FROM workflow_step WHERE definitionId = ? ORDER BY stepOrder LIMIT 1`, [input.definitionId])).rows;
817
+ const firstStepId = steps[0]?.id ?? null;
818
+ await db.execute(`INSERT INTO workflow_instance (id, projectId, definitionId, status, currentStepId, data, requestedBy, startedAt)
819
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [
820
+ id,
821
+ context.projectId,
822
+ input.definitionId,
823
+ firstStepId ? "IN_PROGRESS" : "PENDING",
824
+ firstStepId,
825
+ input.data ? JSON.stringify(input.data) : null,
826
+ context.requestedBy,
827
+ now
828
+ ]);
829
+ if (firstStepId) {
830
+ await db.execute(`INSERT INTO workflow_approval (id, instanceId, stepId, status, createdAt)
831
+ VALUES (?, ?, ?, ?, ?)`, [generateId("wfappr"), id, firstStepId, "PENDING", now]);
832
+ }
833
+ const rows = (await db.query(`SELECT * FROM workflow_instance WHERE id = ?`, [id])).rows;
834
+ return rowToInstance(rows[0]);
835
+ }
836
+ async function approveStep(input, context) {
837
+ const now = new Date().toISOString();
838
+ const instances = (await db.query(`SELECT * FROM workflow_instance WHERE id = ?`, [
839
+ input.instanceId
840
+ ])).rows;
841
+ if (!instances[0]) {
842
+ throw new Error("NOT_FOUND");
843
+ }
844
+ const instance = instances[0];
845
+ await db.execute(`UPDATE workflow_approval SET status = 'APPROVED', actorId = ?, comment = ?, decidedAt = ?
846
+ WHERE instanceId = ? AND stepId = ? AND status = 'PENDING'`, [
847
+ context.actorId,
848
+ input.comment ?? null,
849
+ now,
850
+ input.instanceId,
851
+ instance.currentStepId
852
+ ]);
853
+ const currentStep = (await db.query(`SELECT * FROM workflow_step WHERE id = ?`, [
854
+ instance.currentStepId
855
+ ])).rows;
856
+ const nextSteps = (await db.query(`SELECT * FROM workflow_step WHERE definitionId = ? AND stepOrder > ? ORDER BY stepOrder LIMIT 1`, [instance.definitionId, currentStep[0]?.stepOrder ?? 0])).rows;
857
+ if (nextSteps[0]) {
858
+ await db.execute(`UPDATE workflow_instance SET currentStepId = ? WHERE id = ?`, [nextSteps[0].id, input.instanceId]);
859
+ await db.execute(`INSERT INTO workflow_approval (id, instanceId, stepId, status, createdAt)
860
+ VALUES (?, ?, ?, ?, ?)`, [
861
+ generateId("wfappr"),
862
+ input.instanceId,
863
+ nextSteps[0].id,
864
+ "PENDING",
865
+ now
866
+ ]);
867
+ } else {
868
+ await db.execute(`UPDATE workflow_instance SET status = 'COMPLETED', currentStepId = NULL, completedAt = ? WHERE id = ?`, [now, input.instanceId]);
869
+ }
870
+ const updated = (await db.query(`SELECT * FROM workflow_instance WHERE id = ?`, [
871
+ input.instanceId
872
+ ])).rows;
873
+ return rowToInstance(updated[0]);
874
+ }
875
+ async function rejectStep(input, context) {
876
+ const now = new Date().toISOString();
877
+ const instances = (await db.query(`SELECT * FROM workflow_instance WHERE id = ?`, [
878
+ input.instanceId
879
+ ])).rows;
880
+ if (!instances[0]) {
881
+ throw new Error("NOT_FOUND");
882
+ }
883
+ await db.execute(`UPDATE workflow_approval SET status = 'REJECTED', actorId = ?, comment = ?, decidedAt = ?
884
+ WHERE instanceId = ? AND stepId = ? AND status = 'PENDING'`, [
885
+ context.actorId,
886
+ input.reason,
887
+ now,
888
+ input.instanceId,
889
+ instances[0].currentStepId
890
+ ]);
891
+ await db.execute(`UPDATE workflow_instance SET status = 'REJECTED', completedAt = ? WHERE id = ?`, [now, input.instanceId]);
892
+ const updated = (await db.query(`SELECT * FROM workflow_instance WHERE id = ?`, [
893
+ input.instanceId
894
+ ])).rows;
895
+ return rowToInstance(updated[0]);
896
+ }
897
+ async function getApprovals(instanceId) {
898
+ const rows = (await db.query(`SELECT * FROM workflow_approval WHERE instanceId = ? ORDER BY createdAt`, [instanceId])).rows;
899
+ return rows.map(rowToApproval);
900
+ }
901
+ return {
902
+ listDefinitions,
903
+ createDefinition,
904
+ addStep,
905
+ getSteps,
906
+ listInstances,
907
+ startInstance,
908
+ approveStep,
909
+ rejectStep,
910
+ getApprovals
911
+ };
912
+ }
913
+
914
+ // src/workflow/workflow.enum.ts
915
+ import { defineEnum as defineEnum2 } from "@contractspec/lib.schema";
916
+ var WorkflowStatusEnum = defineEnum2("WorkflowStatus", [
917
+ "DRAFT",
918
+ "ACTIVE",
919
+ "DEPRECATED",
920
+ "ARCHIVED"
921
+ ]);
922
+ var TriggerTypeEnum = defineEnum2("WorkflowTriggerType", [
923
+ "MANUAL",
924
+ "EVENT",
925
+ "SCHEDULED",
926
+ "API"
927
+ ]);
928
+ var StepTypeEnum = defineEnum2("StepType", [
929
+ "START",
930
+ "APPROVAL",
931
+ "TASK",
932
+ "CONDITION",
933
+ "PARALLEL",
934
+ "WAIT",
935
+ "ACTION",
936
+ "END"
937
+ ]);
938
+ var ApprovalModeEnum = defineEnum2("ApprovalMode", [
939
+ "ANY",
940
+ "ALL",
941
+ "MAJORITY",
942
+ "SEQUENTIAL"
943
+ ]);
944
+
945
+ // src/workflow/workflow.schema.ts
946
+ import { defineSchemaModel as defineSchemaModel4, ScalarTypeEnum as ScalarTypeEnum4 } from "@contractspec/lib.schema";
947
+ var WorkflowStepModel = defineSchemaModel4({
948
+ name: "WorkflowStepModel",
949
+ description: "A step in a workflow definition",
950
+ fields: {
951
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
952
+ key: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
953
+ name: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
954
+ description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
955
+ type: { type: StepTypeEnum, isOptional: false },
956
+ position: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
957
+ transitions: { type: ScalarTypeEnum4.JSON(), isOptional: false },
958
+ approvalMode: { type: ApprovalModeEnum, isOptional: true },
959
+ approverRoles: {
960
+ type: ScalarTypeEnum4.String_unsecure(),
961
+ isArray: true,
962
+ isOptional: true
963
+ }
964
+ }
965
+ });
966
+ var WorkflowDefinitionModel = defineSchemaModel4({
967
+ name: "WorkflowDefinitionModel",
968
+ description: "A workflow definition",
969
+ fields: {
970
+ id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
971
+ name: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
972
+ key: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
973
+ description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
974
+ version: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
975
+ status: { type: WorkflowStatusEnum, isOptional: false },
976
+ triggerType: { type: TriggerTypeEnum, isOptional: false },
977
+ initialStepId: {
978
+ type: ScalarTypeEnum4.String_unsecure(),
979
+ isOptional: true
980
+ },
981
+ featureFlagKey: {
982
+ type: ScalarTypeEnum4.String_unsecure(),
983
+ isOptional: true
984
+ },
985
+ organizationId: {
986
+ type: ScalarTypeEnum4.String_unsecure(),
987
+ isOptional: false
988
+ },
989
+ createdAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
990
+ updatedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
991
+ steps: { type: WorkflowStepModel, isArray: true, isOptional: true }
992
+ }
993
+ });
994
+ var CreateWorkflowInputModel = defineSchemaModel4({
995
+ name: "CreateWorkflowInput",
996
+ description: "Input for creating a workflow definition",
997
+ fields: {
998
+ name: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
999
+ key: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1000
+ description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1001
+ triggerType: { type: TriggerTypeEnum, isOptional: true },
1002
+ triggerConfig: { type: ScalarTypeEnum4.JSON(), isOptional: true },
1003
+ featureFlagKey: {
1004
+ type: ScalarTypeEnum4.String_unsecure(),
1005
+ isOptional: true
1006
+ },
1007
+ settings: { type: ScalarTypeEnum4.JSON(), isOptional: true }
1008
+ }
1009
+ });
1010
+ var UpdateWorkflowInputModel = defineSchemaModel4({
1011
+ name: "UpdateWorkflowInput",
1012
+ description: "Input for updating a workflow definition",
1013
+ fields: {
1014
+ workflowId: {
1015
+ type: ScalarTypeEnum4.String_unsecure(),
1016
+ isOptional: false
1017
+ },
1018
+ name: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1019
+ description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1020
+ triggerType: { type: TriggerTypeEnum, isOptional: true },
1021
+ triggerConfig: { type: ScalarTypeEnum4.JSON(), isOptional: true },
1022
+ featureFlagKey: {
1023
+ type: ScalarTypeEnum4.String_unsecure(),
1024
+ isOptional: true
1025
+ },
1026
+ settings: { type: ScalarTypeEnum4.JSON(), isOptional: true }
1027
+ }
1028
+ });
1029
+ var AddStepInputModel = defineSchemaModel4({
1030
+ name: "AddStepInput",
1031
+ description: "Input for adding a step to a workflow",
1032
+ fields: {
1033
+ workflowId: {
1034
+ type: ScalarTypeEnum4.String_unsecure(),
1035
+ isOptional: false
1036
+ },
1037
+ key: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1038
+ name: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1039
+ description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1040
+ type: { type: StepTypeEnum, isOptional: false },
1041
+ position: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
1042
+ transitions: { type: ScalarTypeEnum4.JSON(), isOptional: false },
1043
+ approvalMode: { type: ApprovalModeEnum, isOptional: true },
1044
+ approverRoles: {
1045
+ type: ScalarTypeEnum4.String_unsecure(),
1046
+ isArray: true,
1047
+ isOptional: true
1048
+ },
1049
+ approverUserIds: {
1050
+ type: ScalarTypeEnum4.String_unsecure(),
1051
+ isArray: true,
1052
+ isOptional: true
1053
+ },
1054
+ timeoutSeconds: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
1055
+ slaSeconds: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true }
1056
+ }
1057
+ });
1058
+
1059
+ // src/workflow/workflow.operations.ts
1060
+ import {
1061
+ defineCommand as defineCommand2,
1062
+ defineQuery as defineQuery2
1063
+ } from "@contractspec/lib.contracts/operations";
1064
+ import { defineSchemaModel as defineSchemaModel5, ScalarTypeEnum as ScalarTypeEnum5 } from "@contractspec/lib.schema";
1065
+ var OWNERS2 = ["@example.workflow-system"];
1066
+ var CreateWorkflowContract = defineCommand2({
1067
+ meta: {
1068
+ key: "workflow.definition.create",
1069
+ version: "1.0.0",
1070
+ stability: "stable",
1071
+ owners: [...OWNERS2],
1072
+ tags: ["workflow", "definition", "create"],
1073
+ description: "Create a new workflow definition.",
1074
+ goal: "Allow users to define new workflow blueprints.",
1075
+ context: "Workflow designer, admin panel."
1076
+ },
1077
+ io: {
1078
+ input: CreateWorkflowInputModel,
1079
+ output: WorkflowDefinitionModel
1080
+ },
1081
+ policy: { auth: "user" },
1082
+ sideEffects: {
1083
+ emits: [
1084
+ {
1085
+ key: "workflow.definition.created",
1086
+ version: "1.0.0",
1087
+ when: "Workflow is created",
1088
+ payload: WorkflowDefinitionModel
1089
+ }
1090
+ ],
1091
+ audit: ["workflow.definition.created"]
1092
+ },
1093
+ acceptance: {
1094
+ scenarios: [
1095
+ {
1096
+ key: "create-workflow-happy-path",
1097
+ given: ["User is admin"],
1098
+ when: ["User creates new workflow definition"],
1099
+ then: [
1100
+ "Definition is created",
1101
+ "WorkflowDefinitionCreated event is emitted"
1102
+ ]
1103
+ }
1104
+ ],
1105
+ examples: [
1106
+ {
1107
+ key: "create-onboarding",
1108
+ input: {
1109
+ key: "onboarding-v1",
1110
+ name: "Employee Onboarding",
1111
+ version: "1.0.0"
1112
+ },
1113
+ output: { id: "def-123", status: "draft" }
1114
+ }
1115
+ ]
1116
+ }
1117
+ });
1118
+ var UpdateWorkflowContract = defineCommand2({
1119
+ meta: {
1120
+ key: "workflow.definition.update",
1121
+ version: "1.0.0",
1122
+ stability: "stable",
1123
+ owners: [...OWNERS2],
1124
+ tags: ["workflow", "definition", "update"],
1125
+ description: "Update an existing workflow definition.",
1126
+ goal: "Allow users to modify workflow blueprints.",
1127
+ context: "Workflow designer."
1128
+ },
1129
+ io: {
1130
+ input: UpdateWorkflowInputModel,
1131
+ output: WorkflowDefinitionModel
1132
+ },
1133
+ policy: { auth: "user" },
1134
+ sideEffects: {
1135
+ emits: [
1136
+ {
1137
+ key: "workflow.definition.updated",
1138
+ version: "1.0.0",
1139
+ when: "Workflow is updated",
1140
+ payload: WorkflowDefinitionModel
1141
+ }
1142
+ ],
1143
+ audit: ["workflow.definition.updated"]
1144
+ },
1145
+ acceptance: {
1146
+ scenarios: [
1147
+ {
1148
+ key: "update-workflow-happy-path",
1149
+ given: ["Workflow definition exists"],
1150
+ when: ["User updates definition"],
1151
+ then: [
1152
+ "Definition is updated",
1153
+ "WorkflowDefinitionUpdated event is emitted"
1154
+ ]
1155
+ }
1156
+ ],
1157
+ examples: [
1158
+ {
1159
+ key: "update-name",
1160
+ input: { workflowId: "def-123", name: "New Employee Onboarding" },
1161
+ output: { id: "def-123", name: "New Employee Onboarding" }
1162
+ }
1163
+ ]
1164
+ }
1165
+ });
1166
+ var AddStepContract = defineCommand2({
1167
+ meta: {
1168
+ key: "workflow.step.add",
1169
+ version: "1.0.0",
1170
+ stability: "stable",
1171
+ owners: [...OWNERS2],
1172
+ tags: ["workflow", "step", "add"],
1173
+ description: "Add a step to a workflow definition.",
1174
+ goal: "Build workflow structure step by step.",
1175
+ context: "Workflow designer."
1176
+ },
1177
+ io: {
1178
+ input: AddStepInputModel,
1179
+ output: WorkflowStepModel
1180
+ },
1181
+ policy: { auth: "user" },
1182
+ sideEffects: {
1183
+ emits: [
1184
+ {
1185
+ key: "workflow.step.added",
1186
+ version: "1.0.0",
1187
+ when: "Step is added",
1188
+ payload: WorkflowStepModel
1189
+ }
1190
+ ],
1191
+ audit: ["workflow.step.added"]
1192
+ },
1193
+ acceptance: {
1194
+ scenarios: [
1195
+ {
1196
+ key: "add-step-happy-path",
1197
+ given: ["Workflow definition exists"],
1198
+ when: ["User adds a step"],
1199
+ then: ["Step is added", "StepAdded event is emitted"]
1200
+ }
1201
+ ],
1202
+ examples: [
1203
+ {
1204
+ key: "add-approval-step",
1205
+ input: {
1206
+ workflowId: "def-123",
1207
+ stepKey: "approve-contract",
1208
+ type: "approval"
1209
+ },
1210
+ output: { id: "step-456", key: "approve-contract" }
1211
+ }
1212
+ ]
1213
+ }
1214
+ });
1215
+ var PublishWorkflowContract = defineCommand2({
1216
+ meta: {
1217
+ key: "workflow.definition.publish",
1218
+ version: "1.0.0",
1219
+ stability: "stable",
1220
+ owners: [...OWNERS2],
1221
+ tags: ["workflow", "definition", "publish"],
1222
+ description: "Publish a workflow definition to make it available for use.",
1223
+ goal: "Activate workflow for production use.",
1224
+ context: "Workflow designer, deployment."
1225
+ },
1226
+ io: {
1227
+ input: defineSchemaModel5({
1228
+ name: "PublishWorkflowInput",
1229
+ fields: {
1230
+ workflowId: {
1231
+ type: ScalarTypeEnum5.String_unsecure(),
1232
+ isOptional: false
1233
+ }
1234
+ }
1235
+ }),
1236
+ output: WorkflowDefinitionModel
1237
+ },
1238
+ policy: { auth: "user" },
1239
+ sideEffects: {
1240
+ emits: [
1241
+ {
1242
+ key: "workflow.definition.published",
1243
+ version: "1.0.0",
1244
+ when: "Workflow is published",
1245
+ payload: WorkflowDefinitionModel
1246
+ }
1247
+ ],
1248
+ audit: ["workflow.definition.published"]
1249
+ },
1250
+ acceptance: {
1251
+ scenarios: [
1252
+ {
1253
+ key: "publish-workflow-happy-path",
1254
+ given: ["Workflow definition is valid"],
1255
+ when: ["User publishes workflow"],
1256
+ then: ["Workflow becomes active", "WorkflowPublished event is emitted"]
1257
+ }
1258
+ ],
1259
+ examples: [
1260
+ {
1261
+ key: "publish-onboarding",
1262
+ input: { workflowId: "def-123" },
1263
+ output: { id: "def-123", status: "published" }
1264
+ }
1265
+ ]
1266
+ }
1267
+ });
1268
+ var ListWorkflowsContract = defineQuery2({
1269
+ meta: {
1270
+ key: "workflow.definition.list",
1271
+ version: "1.0.0",
1272
+ stability: "stable",
1273
+ owners: [...OWNERS2],
1274
+ tags: ["workflow", "definition", "list"],
1275
+ description: "List workflow definitions with filtering.",
1276
+ goal: "Browse and search available workflows.",
1277
+ context: "Workflow list, search."
1278
+ },
1279
+ io: {
1280
+ input: defineSchemaModel5({
1281
+ name: "ListWorkflowsInput",
1282
+ fields: {
1283
+ status: { type: WorkflowStatusEnum, isOptional: true },
1284
+ search: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1285
+ limit: {
1286
+ type: ScalarTypeEnum5.Int_unsecure(),
1287
+ isOptional: true,
1288
+ defaultValue: 20
1289
+ },
1290
+ offset: {
1291
+ type: ScalarTypeEnum5.Int_unsecure(),
1292
+ isOptional: true,
1293
+ defaultValue: 0
1294
+ }
1295
+ }
1296
+ }),
1297
+ output: defineSchemaModel5({
1298
+ name: "ListWorkflowsOutput",
1299
+ fields: {
1300
+ workflows: {
1301
+ type: WorkflowDefinitionModel,
1302
+ isArray: true,
1303
+ isOptional: false
1304
+ },
1305
+ total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false }
1306
+ }
1307
+ })
1308
+ },
1309
+ policy: { auth: "user" },
1310
+ acceptance: {
1311
+ scenarios: [
1312
+ {
1313
+ key: "list-workflows-happy-path",
1314
+ given: ["Workflow definitions exist"],
1315
+ when: ["User lists workflows"],
1316
+ then: ["List of workflows is returned"]
1317
+ }
1318
+ ],
1319
+ examples: [
1320
+ {
1321
+ key: "list-all",
1322
+ input: { limit: 10 },
1323
+ output: { workflows: [], total: 5 }
1324
+ }
1325
+ ]
1326
+ }
1327
+ });
1328
+ var GetWorkflowContract = defineQuery2({
1329
+ meta: {
1330
+ key: "workflow.definition.get",
1331
+ version: "1.0.0",
1332
+ stability: "stable",
1333
+ owners: [...OWNERS2],
1334
+ tags: ["workflow", "definition", "get"],
1335
+ description: "Get a workflow definition with all steps.",
1336
+ goal: "View workflow details.",
1337
+ context: "Workflow designer, detail view."
1338
+ },
1339
+ io: {
1340
+ input: defineSchemaModel5({
1341
+ name: "GetWorkflowInput",
1342
+ fields: {
1343
+ workflowId: {
1344
+ type: ScalarTypeEnum5.String_unsecure(),
1345
+ isOptional: false
1346
+ }
1347
+ }
1348
+ }),
1349
+ output: WorkflowDefinitionModel
1350
+ },
1351
+ policy: { auth: "user" },
1352
+ acceptance: {
1353
+ scenarios: [
1354
+ {
1355
+ key: "get-workflow-happy-path",
1356
+ given: ["Workflow definition exists"],
1357
+ when: ["User requests workflow details"],
1358
+ then: ["Workflow details are returned"]
1359
+ }
1360
+ ],
1361
+ examples: [
1362
+ {
1363
+ key: "get-details",
1364
+ input: { workflowId: "def-123" },
1365
+ output: { id: "def-123", name: "Employee Onboarding" }
1366
+ }
1367
+ ]
1368
+ }
1369
+ });
1370
+
1371
+ // src/workflow/workflow.event.ts
1372
+ import { defineEvent as defineEvent2, defineSchemaModel as defineSchemaModel6 } from "@contractspec/lib.contracts";
1373
+ import { ScalarTypeEnum as ScalarTypeEnum6 } from "@contractspec/lib.schema";
1374
+ var WorkflowDefinitionPayload = defineSchemaModel6({
1375
+ name: "WorkflowDefinitionEventPayload",
1376
+ description: "Payload for workflow definition events",
1377
+ fields: {
1378
+ workflowId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1379
+ key: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1380
+ name: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1381
+ version: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1382
+ organizationId: {
1383
+ type: ScalarTypeEnum6.String_unsecure(),
1384
+ isOptional: false
1385
+ },
1386
+ createdBy: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1387
+ timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1388
+ }
1389
+ });
1390
+ var StepAddedPayload = defineSchemaModel6({
1391
+ name: "StepAddedEventPayload",
1392
+ description: "Payload when a step is added",
1393
+ fields: {
1394
+ stepId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1395
+ workflowId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1396
+ stepKey: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1397
+ stepType: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1398
+ position: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: false },
1399
+ timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1400
+ }
1401
+ });
1402
+ var WorkflowCreatedEvent = defineEvent2({
1403
+ meta: {
1404
+ key: "workflow.definition.created",
1405
+ version: "1.0.0",
1406
+ description: "A new workflow definition has been created.",
1407
+ stability: "stable",
1408
+ owners: ["@workflow-team"],
1409
+ tags: ["workflow", "definition", "created"]
1410
+ },
1411
+ payload: WorkflowDefinitionPayload
1412
+ });
1413
+ var WorkflowUpdatedEvent = defineEvent2({
1414
+ meta: {
1415
+ key: "workflow.definition.updated",
1416
+ version: "1.0.0",
1417
+ description: "A workflow definition has been updated.",
1418
+ stability: "stable",
1419
+ owners: ["@workflow-team"],
1420
+ tags: ["workflow", "definition", "updated"]
1421
+ },
1422
+ payload: WorkflowDefinitionPayload
1423
+ });
1424
+ var WorkflowPublishedEvent = defineEvent2({
1425
+ meta: {
1426
+ key: "workflow.definition.published",
1427
+ version: "1.0.0",
1428
+ description: "A workflow definition has been published and is now active.",
1429
+ stability: "stable",
1430
+ owners: ["@workflow-team"],
1431
+ tags: ["workflow", "definition", "published"]
1432
+ },
1433
+ payload: WorkflowDefinitionPayload
1434
+ });
1435
+ var StepAddedEvent = defineEvent2({
1436
+ meta: {
1437
+ key: "workflow.step.added",
1438
+ version: "1.0.0",
1439
+ description: "A step has been added to a workflow definition.",
1440
+ stability: "stable",
1441
+ owners: ["@workflow-team"],
1442
+ tags: ["workflow", "step", "added"]
1443
+ },
1444
+ payload: StepAddedPayload
1445
+ });
1446
+ // src/instance/instance.enum.ts
1447
+ import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
1448
+ var InstanceStatusEnum = defineEnum3("InstanceStatus", [
1449
+ "PENDING",
1450
+ "RUNNING",
1451
+ "WAITING",
1452
+ "PAUSED",
1453
+ "COMPLETED",
1454
+ "CANCELLED",
1455
+ "FAILED",
1456
+ "TIMEOUT"
1457
+ ]);
1458
+
1459
+ // src/instance/instance.schema.ts
1460
+ import { defineSchemaModel as defineSchemaModel7, ScalarTypeEnum as ScalarTypeEnum7 } from "@contractspec/lib.schema";
1461
+ var WorkflowInstanceModel = defineSchemaModel7({
1462
+ name: "WorkflowInstanceModel",
1463
+ description: "A running workflow instance",
1464
+ fields: {
1465
+ id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1466
+ workflowDefinitionId: {
1467
+ type: ScalarTypeEnum7.String_unsecure(),
1468
+ isOptional: false
1469
+ },
1470
+ referenceId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1471
+ referenceType: {
1472
+ type: ScalarTypeEnum7.String_unsecure(),
1473
+ isOptional: true
1474
+ },
1475
+ status: { type: InstanceStatusEnum, isOptional: false },
1476
+ currentStepId: {
1477
+ type: ScalarTypeEnum7.String_unsecure(),
1478
+ isOptional: true
1479
+ },
1480
+ contextData: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1481
+ triggeredBy: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1482
+ organizationId: {
1483
+ type: ScalarTypeEnum7.String_unsecure(),
1484
+ isOptional: false
1485
+ },
1486
+ priority: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
1487
+ dueAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true },
1488
+ outcome: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1489
+ resultData: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1490
+ errorMessage: {
1491
+ type: ScalarTypeEnum7.String_unsecure(),
1492
+ isOptional: true
1493
+ },
1494
+ createdAt: { type: ScalarTypeEnum7.DateTime(), isOptional: false },
1495
+ startedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true },
1496
+ completedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true }
1497
+ }
1498
+ });
1499
+ var StartWorkflowInputModel = defineSchemaModel7({
1500
+ name: "StartWorkflowInput",
1501
+ description: "Input for starting a workflow",
1502
+ fields: {
1503
+ workflowKey: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1504
+ contextData: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1505
+ referenceId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1506
+ referenceType: {
1507
+ type: ScalarTypeEnum7.String_unsecure(),
1508
+ isOptional: true
1509
+ },
1510
+ priority: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: true },
1511
+ dueAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true }
1512
+ }
1513
+ });
1514
+ var TransitionInputModel = defineSchemaModel7({
1515
+ name: "TransitionInput",
1516
+ description: "Input for transitioning a workflow",
1517
+ fields: {
1518
+ instanceId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1519
+ action: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1520
+ data: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1521
+ comment: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true }
1522
+ }
1523
+ });
1524
+ var TransitionResultModel = defineSchemaModel7({
1525
+ name: "TransitionResult",
1526
+ description: "Result of a workflow transition",
1527
+ fields: {
1528
+ success: { type: ScalarTypeEnum7.Boolean(), isOptional: false },
1529
+ instance: { type: WorkflowInstanceModel, isOptional: false },
1530
+ previousStepKey: {
1531
+ type: ScalarTypeEnum7.String_unsecure(),
1532
+ isOptional: true
1533
+ },
1534
+ currentStepKey: {
1535
+ type: ScalarTypeEnum7.String_unsecure(),
1536
+ isOptional: true
1537
+ },
1538
+ message: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true }
1539
+ }
1540
+ });
1541
+
1542
+ // src/instance/instance.operations.ts
1543
+ import {
1544
+ defineCommand as defineCommand3,
1545
+ defineQuery as defineQuery3
1546
+ } from "@contractspec/lib.contracts/operations";
1547
+ import { defineSchemaModel as defineSchemaModel8, ScalarTypeEnum as ScalarTypeEnum8 } from "@contractspec/lib.schema";
1548
+ var OWNERS3 = ["@example.workflow-system"];
1549
+ var StartWorkflowContract = defineCommand3({
1550
+ meta: {
1551
+ key: "workflow.instance.start",
1552
+ version: "1.0.0",
1553
+ stability: "stable",
1554
+ owners: [...OWNERS3],
1555
+ tags: ["workflow", "instance", "start"],
1556
+ description: "Start a new workflow instance.",
1557
+ goal: "Initiate a workflow for a business process.",
1558
+ context: "Order creation, request submission, etc."
1559
+ },
1560
+ io: {
1561
+ input: StartWorkflowInputModel,
1562
+ output: WorkflowInstanceModel
1563
+ },
1564
+ policy: { auth: "user" },
1565
+ sideEffects: {
1566
+ emits: [
1567
+ {
1568
+ key: "workflow.instance.started",
1569
+ version: "1.0.0",
1570
+ when: "Workflow starts",
1571
+ payload: WorkflowInstanceModel
1572
+ },
1573
+ {
1574
+ key: "workflow.step.entered",
1575
+ version: "1.0.0",
1576
+ when: "First step entered",
1577
+ payload: WorkflowInstanceModel
1578
+ }
1579
+ ],
1580
+ audit: ["workflow.instance.started"]
1581
+ },
1582
+ acceptance: {
1583
+ scenarios: [
1584
+ {
1585
+ key: "start-workflow-happy-path",
1586
+ given: ["Workflow definition exists"],
1587
+ when: ["User starts workflow"],
1588
+ then: ["Instance is created and started"]
1589
+ }
1590
+ ],
1591
+ examples: [
1592
+ {
1593
+ key: "start-onboarding",
1594
+ input: {
1595
+ workflowKey: "onboarding-v1",
1596
+ context: { employeeId: "emp-123" }
1597
+ },
1598
+ output: { id: "inst-456", status: "running" }
1599
+ }
1600
+ ]
1601
+ }
1602
+ });
1603
+ var TransitionWorkflowContract = defineCommand3({
1604
+ meta: {
1605
+ key: "workflow.instance.transition",
1606
+ version: "1.0.0",
1607
+ stability: "stable",
1608
+ owners: [...OWNERS3],
1609
+ tags: ["workflow", "instance", "transition", "state-machine"],
1610
+ description: "Transition a workflow instance to the next step.",
1611
+ goal: "Move workflow forward based on action.",
1612
+ context: "Task completion, approval decisions."
1613
+ },
1614
+ io: {
1615
+ input: TransitionInputModel,
1616
+ output: TransitionResultModel
1617
+ },
1618
+ policy: { auth: "user" },
1619
+ sideEffects: {
1620
+ emits: [
1621
+ {
1622
+ key: "workflow.step.exited",
1623
+ version: "1.0.0",
1624
+ when: "Step is exited",
1625
+ payload: WorkflowInstanceModel
1626
+ },
1627
+ {
1628
+ key: "workflow.step.entered",
1629
+ version: "1.0.0",
1630
+ when: "New step is entered",
1631
+ payload: WorkflowInstanceModel
1632
+ },
1633
+ {
1634
+ key: "workflow.instance.completed",
1635
+ version: "1.0.0",
1636
+ when: "Workflow reaches end",
1637
+ payload: WorkflowInstanceModel
1638
+ }
1639
+ ],
1640
+ audit: ["workflow.instance.transitioned"]
1641
+ },
1642
+ acceptance: {
1643
+ scenarios: [
1644
+ {
1645
+ key: "transition-workflow-happy-path",
1646
+ given: ["Workflow instance is waiting at step"],
1647
+ when: ["User provides input"],
1648
+ then: ["Instance moves to next step"]
1649
+ }
1650
+ ],
1651
+ examples: [
1652
+ {
1653
+ key: "complete-task",
1654
+ input: {
1655
+ instanceId: "inst-456",
1656
+ action: "complete",
1657
+ data: { approved: true }
1658
+ },
1659
+ output: { success: true, nextStep: "notify-hr" }
1660
+ }
1661
+ ]
1662
+ }
1663
+ });
1664
+ var PauseWorkflowContract = defineCommand3({
1665
+ meta: {
1666
+ key: "workflow.instance.pause",
1667
+ version: "1.0.0",
1668
+ stability: "stable",
1669
+ owners: [...OWNERS3],
1670
+ tags: ["workflow", "instance", "pause"],
1671
+ description: "Pause a running workflow instance.",
1672
+ goal: "Temporarily halt workflow execution.",
1673
+ context: "Administrative action, emergency stop."
1674
+ },
1675
+ io: {
1676
+ input: defineSchemaModel8({
1677
+ name: "PauseResumeInput",
1678
+ fields: {
1679
+ instanceId: {
1680
+ type: ScalarTypeEnum8.String_unsecure(),
1681
+ isOptional: false
1682
+ },
1683
+ reason: { type: ScalarTypeEnum8.String_unsecure(), isOptional: true }
1684
+ }
1685
+ }),
1686
+ output: WorkflowInstanceModel
1687
+ },
1688
+ policy: { auth: "user" },
1689
+ sideEffects: {
1690
+ emits: [
1691
+ {
1692
+ key: "workflow.instance.paused",
1693
+ version: "1.0.0",
1694
+ when: "Workflow is paused",
1695
+ payload: WorkflowInstanceModel
1696
+ }
1697
+ ],
1698
+ audit: ["workflow.instance.paused"]
1699
+ },
1700
+ acceptance: {
1701
+ scenarios: [
1702
+ {
1703
+ key: "pause-workflow-happy-path",
1704
+ given: ["Workflow is running"],
1705
+ when: ["Admin pauses workflow"],
1706
+ then: ["Instance status becomes PAUSED"]
1707
+ }
1708
+ ],
1709
+ examples: [
1710
+ {
1711
+ key: "pause-maintenance",
1712
+ input: { instanceId: "inst-456", reason: "System maintenance" },
1713
+ output: { id: "inst-456", status: "paused" }
1714
+ }
1715
+ ]
1716
+ }
1717
+ });
1718
+ var ResumeWorkflowContract = defineCommand3({
1719
+ meta: {
1720
+ key: "workflow.instance.resume",
1721
+ version: "1.0.0",
1722
+ stability: "stable",
1723
+ owners: [...OWNERS3],
1724
+ tags: ["workflow", "instance", "resume"],
1725
+ description: "Resume a paused workflow instance.",
1726
+ goal: "Continue workflow execution.",
1727
+ context: "Administrative action."
1728
+ },
1729
+ io: {
1730
+ input: defineSchemaModel8({
1731
+ name: "PauseResumeInput",
1732
+ fields: {
1733
+ instanceId: {
1734
+ type: ScalarTypeEnum8.String_unsecure(),
1735
+ isOptional: false
1736
+ },
1737
+ reason: { type: ScalarTypeEnum8.String_unsecure(), isOptional: true }
1738
+ }
1739
+ }),
1740
+ output: WorkflowInstanceModel
1741
+ },
1742
+ policy: { auth: "user" },
1743
+ sideEffects: {
1744
+ emits: [
1745
+ {
1746
+ key: "workflow.instance.resumed",
1747
+ version: "1.0.0",
1748
+ when: "Workflow is resumed",
1749
+ payload: WorkflowInstanceModel
1750
+ }
1751
+ ],
1752
+ audit: ["workflow.instance.resumed"]
1753
+ },
1754
+ acceptance: {
1755
+ scenarios: [
1756
+ {
1757
+ key: "resume-workflow-happy-path",
1758
+ given: ["Workflow is paused"],
1759
+ when: ["Admin resumes workflow"],
1760
+ then: ["Instance status becomes RUNNING"]
1761
+ }
1762
+ ],
1763
+ examples: [
1764
+ {
1765
+ key: "resume-normal",
1766
+ input: { instanceId: "inst-456", reason: "Issue resolved" },
1767
+ output: { id: "inst-456", status: "running" }
1768
+ }
1769
+ ]
1770
+ }
1771
+ });
1772
+ var CancelWorkflowContract = defineCommand3({
1773
+ meta: {
1774
+ key: "workflow.instance.cancel",
1775
+ version: "1.0.0",
1776
+ stability: "stable",
1777
+ owners: [...OWNERS3],
1778
+ tags: ["workflow", "instance", "cancel"],
1779
+ description: "Cancel a workflow instance.",
1780
+ goal: "Terminate workflow without completion.",
1781
+ context: "User request, system cancellation."
1782
+ },
1783
+ io: {
1784
+ input: defineSchemaModel8({
1785
+ name: "CancelWorkflowInput",
1786
+ fields: {
1787
+ instanceId: {
1788
+ type: ScalarTypeEnum8.String_unsecure(),
1789
+ isOptional: false
1790
+ },
1791
+ reason: {
1792
+ type: ScalarTypeEnum8.String_unsecure(),
1793
+ isOptional: false
1794
+ }
1795
+ }
1796
+ }),
1797
+ output: WorkflowInstanceModel
1798
+ },
1799
+ policy: { auth: "user" },
1800
+ sideEffects: {
1801
+ emits: [
1802
+ {
1803
+ key: "workflow.instance.cancelled",
1804
+ version: "1.0.0",
1805
+ when: "Workflow is cancelled",
1806
+ payload: WorkflowInstanceModel
1807
+ }
1808
+ ],
1809
+ audit: ["workflow.instance.cancelled"]
1810
+ },
1811
+ acceptance: {
1812
+ scenarios: [
1813
+ {
1814
+ key: "cancel-workflow-happy-path",
1815
+ given: ["Workflow is running"],
1816
+ when: ["User cancels workflow"],
1817
+ then: ["Instance status becomes CANCELLED"]
1818
+ }
1819
+ ],
1820
+ examples: [
1821
+ {
1822
+ key: "cancel-mistake",
1823
+ input: { instanceId: "inst-456", reason: "Created by mistake" },
1824
+ output: { id: "inst-456", status: "cancelled" }
1825
+ }
1826
+ ]
1827
+ }
1828
+ });
1829
+ var ListInstancesContract = defineQuery3({
1830
+ meta: {
1831
+ key: "workflow.instance.list",
1832
+ version: "1.0.0",
1833
+ stability: "stable",
1834
+ owners: [...OWNERS3],
1835
+ tags: ["workflow", "instance", "list"],
1836
+ description: "List workflow instances with filtering.",
1837
+ goal: "Browse and search running workflows.",
1838
+ context: "Dashboard, monitoring."
1839
+ },
1840
+ io: {
1841
+ input: defineSchemaModel8({
1842
+ name: "ListInstancesInput",
1843
+ fields: {
1844
+ workflowKey: {
1845
+ type: ScalarTypeEnum8.String_unsecure(),
1846
+ isOptional: true
1847
+ },
1848
+ status: { type: InstanceStatusEnum, isOptional: true },
1849
+ referenceType: {
1850
+ type: ScalarTypeEnum8.String_unsecure(),
1851
+ isOptional: true
1852
+ },
1853
+ referenceId: {
1854
+ type: ScalarTypeEnum8.String_unsecure(),
1855
+ isOptional: true
1856
+ },
1857
+ triggeredBy: {
1858
+ type: ScalarTypeEnum8.String_unsecure(),
1859
+ isOptional: true
1860
+ },
1861
+ limit: {
1862
+ type: ScalarTypeEnum8.Int_unsecure(),
1863
+ isOptional: true,
1864
+ defaultValue: 20
1865
+ },
1866
+ offset: {
1867
+ type: ScalarTypeEnum8.Int_unsecure(),
1868
+ isOptional: true,
1869
+ defaultValue: 0
1870
+ }
1871
+ }
1872
+ }),
1873
+ output: defineSchemaModel8({
1874
+ name: "ListInstancesOutput",
1875
+ fields: {
1876
+ instances: {
1877
+ type: WorkflowInstanceModel,
1878
+ isArray: true,
1879
+ isOptional: false
1880
+ },
1881
+ total: { type: ScalarTypeEnum8.Int_unsecure(), isOptional: false }
1882
+ }
1883
+ })
1884
+ },
1885
+ policy: { auth: "user" },
1886
+ acceptance: {
1887
+ scenarios: [
1888
+ {
1889
+ key: "list-instances-happy-path",
1890
+ given: ["Workflow instances exist"],
1891
+ when: ["User lists instances"],
1892
+ then: ["List of instances is returned"]
1893
+ }
1894
+ ],
1895
+ examples: [
1896
+ {
1897
+ key: "list-running",
1898
+ input: { status: "running", limit: 10 },
1899
+ output: { instances: [], total: 5 }
1900
+ }
1901
+ ]
1902
+ }
1903
+ });
1904
+ var GetInstanceContract = defineQuery3({
1905
+ meta: {
1906
+ key: "workflow.instance.get",
1907
+ version: "1.0.0",
1908
+ stability: "stable",
1909
+ owners: [...OWNERS3],
1910
+ tags: ["workflow", "instance", "get"],
1911
+ description: "Get a workflow instance with details.",
1912
+ goal: "View workflow instance details.",
1913
+ context: "Instance detail view."
1914
+ },
1915
+ io: {
1916
+ input: defineSchemaModel8({
1917
+ name: "GetInstanceInput",
1918
+ fields: {
1919
+ instanceId: {
1920
+ type: ScalarTypeEnum8.String_unsecure(),
1921
+ isOptional: false
1922
+ }
1923
+ }
1924
+ }),
1925
+ output: WorkflowInstanceModel
1926
+ },
1927
+ policy: { auth: "user" },
1928
+ acceptance: {
1929
+ scenarios: [
1930
+ {
1931
+ key: "get-instance-happy-path",
1932
+ given: ["Instance exists"],
1933
+ when: ["User requests instance details"],
1934
+ then: ["Instance details are returned"]
1935
+ }
1936
+ ],
1937
+ examples: [
1938
+ {
1939
+ key: "get-details",
1940
+ input: { instanceId: "inst-456" },
1941
+ output: { id: "inst-456", workflowKey: "onboarding-v1" }
1942
+ }
1943
+ ]
1944
+ }
1945
+ });
1946
+
1947
+ // src/instance/instance.event.ts
1948
+ import { defineEvent as defineEvent3, defineSchemaModel as defineSchemaModel9 } from "@contractspec/lib.contracts";
1949
+ import { ScalarTypeEnum as ScalarTypeEnum9 } from "@contractspec/lib.schema";
1950
+ var InstanceEventPayload = defineSchemaModel9({
1951
+ name: "InstanceEventPayload",
1952
+ description: "Base payload for instance events",
1953
+ fields: {
1954
+ instanceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1955
+ workflowId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1956
+ workflowKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1957
+ status: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1958
+ referenceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1959
+ referenceType: {
1960
+ type: ScalarTypeEnum9.String_unsecure(),
1961
+ isOptional: true
1962
+ },
1963
+ triggeredBy: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1964
+ organizationId: {
1965
+ type: ScalarTypeEnum9.String_unsecure(),
1966
+ isOptional: false
1967
+ },
1968
+ timestamp: { type: ScalarTypeEnum9.DateTime(), isOptional: false }
1969
+ }
1970
+ });
1971
+ var StepTransitionPayload = defineSchemaModel9({
1972
+ name: "StepTransitionEventPayload",
1973
+ description: "Payload for step transition events",
1974
+ fields: {
1975
+ instanceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1976
+ workflowId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1977
+ fromStepKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1978
+ toStepKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1979
+ action: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1980
+ executedBy: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1981
+ timestamp: { type: ScalarTypeEnum9.DateTime(), isOptional: false }
1982
+ }
1983
+ });
1984
+ var InstanceCompletedPayload = defineSchemaModel9({
1985
+ name: "InstanceCompletedEventPayload",
1986
+ description: "Payload when instance completes",
1987
+ fields: {
1988
+ instanceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1989
+ workflowId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1990
+ workflowKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1991
+ outcome: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1992
+ referenceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1993
+ referenceType: {
1994
+ type: ScalarTypeEnum9.String_unsecure(),
1995
+ isOptional: true
1996
+ },
1997
+ duration: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: false },
1998
+ timestamp: { type: ScalarTypeEnum9.DateTime(), isOptional: false }
1999
+ }
2000
+ });
2001
+ var InstanceStartedEvent = defineEvent3({
2002
+ meta: {
2003
+ key: "workflow.instance.started",
2004
+ version: "1.0.0",
2005
+ description: "A new workflow instance has been started.",
2006
+ stability: "stable",
2007
+ owners: ["@workflow-team"],
2008
+ tags: ["workflow", "instance", "started"]
2009
+ },
2010
+ payload: InstanceEventPayload
2011
+ });
2012
+ var StepEnteredEvent = defineEvent3({
2013
+ meta: {
2014
+ key: "workflow.step.entered",
2015
+ version: "1.0.0",
2016
+ description: "A workflow instance has entered a new step.",
2017
+ stability: "stable",
2018
+ owners: ["@workflow-team"],
2019
+ tags: ["workflow", "step", "entered"]
2020
+ },
2021
+ payload: StepTransitionPayload
2022
+ });
2023
+ var StepExitedEvent = defineEvent3({
2024
+ meta: {
2025
+ key: "workflow.step.exited",
2026
+ version: "1.0.0",
2027
+ description: "A workflow instance has exited a step.",
2028
+ stability: "stable",
2029
+ owners: ["@workflow-team"],
2030
+ tags: ["workflow", "step", "exited"]
2031
+ },
2032
+ payload: StepTransitionPayload
2033
+ });
2034
+ var InstanceCompletedEvent = defineEvent3({
2035
+ meta: {
2036
+ key: "workflow.instance.completed",
2037
+ version: "1.0.0",
2038
+ description: "A workflow instance has completed.",
2039
+ stability: "stable",
2040
+ owners: ["@workflow-team"],
2041
+ tags: ["workflow", "instance", "completed"]
2042
+ },
2043
+ payload: InstanceCompletedPayload
2044
+ });
2045
+ var InstanceCancelledEvent = defineEvent3({
2046
+ meta: {
2047
+ key: "workflow.instance.cancelled",
2048
+ version: "1.0.0",
2049
+ description: "A workflow instance has been cancelled.",
2050
+ stability: "stable",
2051
+ owners: ["@workflow-team"],
2052
+ tags: ["workflow", "instance", "cancelled"]
2053
+ },
2054
+ payload: InstanceEventPayload
2055
+ });
2056
+ var InstancePausedEvent = defineEvent3({
2057
+ meta: {
2058
+ key: "workflow.instance.paused",
2059
+ version: "1.0.0",
2060
+ description: "A workflow instance has been paused.",
2061
+ stability: "stable",
2062
+ owners: ["@workflow-team"],
2063
+ tags: ["workflow", "instance", "paused"]
2064
+ },
2065
+ payload: InstanceEventPayload
2066
+ });
2067
+ var InstanceResumedEvent = defineEvent3({
2068
+ meta: {
2069
+ key: "workflow.instance.resumed",
2070
+ version: "1.0.0",
2071
+ description: "A workflow instance has been resumed.",
2072
+ stability: "stable",
2073
+ owners: ["@workflow-team"],
2074
+ tags: ["workflow", "instance", "resumed"]
2075
+ },
2076
+ payload: InstanceEventPayload
2077
+ });
2078
+ var InstanceFailedEvent = defineEvent3({
2079
+ meta: {
2080
+ key: "workflow.instance.failed",
2081
+ version: "1.0.0",
2082
+ description: "A workflow instance has failed.",
2083
+ stability: "stable",
2084
+ owners: ["@workflow-team"],
2085
+ tags: ["workflow", "instance", "failed"]
2086
+ },
2087
+ payload: InstanceEventPayload
2088
+ });
2089
+ var InstanceTimedOutEvent = defineEvent3({
2090
+ meta: {
2091
+ key: "workflow.instance.timedOut",
2092
+ version: "1.0.0",
2093
+ description: "A workflow instance has timed out.",
2094
+ stability: "stable",
2095
+ owners: ["@workflow-team"],
2096
+ tags: ["workflow", "instance", "timeout"]
2097
+ },
2098
+ payload: InstanceEventPayload
2099
+ });
2100
+ // src/presentations/index.ts
2101
+ import { definePresentation, StabilityEnum } from "@contractspec/lib.contracts";
2102
+ var WorkflowDesignerPresentation = definePresentation({
2103
+ meta: {
2104
+ key: "workflow.designer",
2105
+ version: "1.0.0",
2106
+ title: "Workflow Designer",
2107
+ description: "Visual workflow designer with drag-and-drop steps",
2108
+ domain: "workflow-system",
2109
+ owners: ["@workflow-team"],
2110
+ tags: ["workflow", "designer", "admin"],
2111
+ stability: StabilityEnum.Experimental,
2112
+ goal: "Building and modifying workflow definitions",
2113
+ context: "Workflow administration and setup"
2114
+ },
2115
+ source: {
2116
+ type: "component",
2117
+ framework: "react",
2118
+ componentKey: "WorkflowDesigner",
2119
+ props: WorkflowDefinitionModel
2120
+ },
2121
+ targets: ["react"],
2122
+ policy: {
2123
+ flags: ["workflow.designer.enabled"]
2124
+ }
2125
+ });
2126
+ var WorkflowListPresentation = definePresentation({
2127
+ meta: {
2128
+ key: "workflow.definition.viewList",
2129
+ version: "1.0.0",
2130
+ title: "Workflow List",
2131
+ description: "List of workflow definitions with status and actions",
2132
+ domain: "workflow-system",
2133
+ owners: ["@workflow-team"],
2134
+ tags: ["workflow", "list", "admin"],
2135
+ stability: StabilityEnum.Experimental,
2136
+ goal: "Overview of all defined workflows",
2137
+ context: "Workflow management dashboard"
2138
+ },
2139
+ source: {
2140
+ type: "component",
2141
+ framework: "react",
2142
+ componentKey: "WorkflowDefinitionList",
2143
+ props: WorkflowDefinitionModel
2144
+ },
2145
+ targets: ["react", "markdown"],
2146
+ policy: {
2147
+ flags: ["workflow.enabled"]
2148
+ }
2149
+ });
2150
+ var WorkflowDetailPresentation = definePresentation({
2151
+ meta: {
2152
+ key: "workflow.definition.detail",
2153
+ version: "1.0.0",
2154
+ title: "Workflow Details",
2155
+ description: "Detailed view of a workflow definition with steps",
2156
+ domain: "workflow-system",
2157
+ owners: ["@workflow-team"],
2158
+ tags: ["workflow", "detail"],
2159
+ stability: StabilityEnum.Experimental,
2160
+ goal: "Viewing technical details of a workflow definition",
2161
+ context: "Workflow inspection and debugging"
2162
+ },
2163
+ source: {
2164
+ type: "component",
2165
+ framework: "react",
2166
+ componentKey: "WorkflowDefinitionDetail",
2167
+ props: WorkflowDefinitionModel
2168
+ },
2169
+ targets: ["react", "markdown"],
2170
+ policy: {
2171
+ flags: ["workflow.enabled"]
2172
+ }
2173
+ });
2174
+ var InstanceListPresentation = definePresentation({
2175
+ meta: {
2176
+ key: "workflow.instance.viewList",
2177
+ version: "1.0.0",
2178
+ title: "Instance List",
2179
+ description: "List of workflow instances with status and progress",
2180
+ domain: "workflow-system",
2181
+ owners: ["@workflow-team"],
2182
+ tags: ["workflow", "instance", "list"],
2183
+ stability: StabilityEnum.Experimental,
2184
+ goal: "Monitoring active and past workflow executions",
2185
+ context: "Operations monitoring"
2186
+ },
2187
+ source: {
2188
+ type: "component",
2189
+ framework: "react",
2190
+ componentKey: "WorkflowInstanceList",
2191
+ props: WorkflowInstanceModel
2192
+ },
2193
+ targets: ["react", "markdown"],
2194
+ policy: {
2195
+ flags: ["workflow.enabled"]
2196
+ }
2197
+ });
2198
+ var InstanceDetailPresentation = definePresentation({
2199
+ meta: {
2200
+ key: "workflow.instance.detail",
2201
+ version: "1.0.0",
2202
+ title: "Instance Details",
2203
+ description: "Detailed view of a workflow instance with step timeline",
2204
+ domain: "workflow-system",
2205
+ owners: ["@workflow-team"],
2206
+ tags: ["workflow", "instance", "detail", "timeline"],
2207
+ stability: StabilityEnum.Experimental,
2208
+ goal: "Detailed inspection of a specific workflow instance",
2209
+ context: "Case management and troubleshooting"
2210
+ },
2211
+ source: {
2212
+ type: "component",
2213
+ framework: "react",
2214
+ componentKey: "WorkflowInstanceDetail",
2215
+ props: WorkflowInstanceModel
2216
+ },
2217
+ targets: ["react", "markdown"],
2218
+ policy: {
2219
+ flags: ["workflow.enabled"]
2220
+ }
2221
+ });
2222
+ var ProgressTrackerPresentation = definePresentation({
2223
+ meta: {
2224
+ key: "workflow.instance.progress",
2225
+ version: "1.0.0",
2226
+ title: "Progress Tracker",
2227
+ description: "Visual progress tracker showing current step in workflow",
2228
+ domain: "workflow-system",
2229
+ owners: ["@workflow-team"],
2230
+ tags: ["workflow", "progress", "widget"],
2231
+ stability: StabilityEnum.Experimental,
2232
+ goal: "Quick view of current progress for a workflow",
2233
+ context: "Embedded progress indicator in entity views"
2234
+ },
2235
+ source: {
2236
+ type: "component",
2237
+ framework: "react",
2238
+ componentKey: "WorkflowProgressTracker",
2239
+ props: WorkflowInstanceModel
2240
+ },
2241
+ targets: ["react"],
2242
+ policy: {
2243
+ flags: ["workflow.enabled"]
2244
+ }
2245
+ });
2246
+ var ApprovalInboxPresentation = definePresentation({
2247
+ meta: {
2248
+ key: "workflow.approval.inbox",
2249
+ version: "1.0.0",
2250
+ title: "Approval Inbox",
2251
+ description: "Inbox showing pending approval requests for current user",
2252
+ domain: "workflow-system",
2253
+ owners: ["@workflow-team"],
2254
+ tags: ["workflow", "approval", "inbox"],
2255
+ stability: StabilityEnum.Experimental,
2256
+ goal: "Managing personal workload of approval requests",
2257
+ context: "Personal task management"
2258
+ },
2259
+ source: {
2260
+ type: "component",
2261
+ framework: "react",
2262
+ componentKey: "ApprovalInbox",
2263
+ props: ApprovalRequestModel
2264
+ },
2265
+ targets: ["react", "markdown"],
2266
+ policy: {
2267
+ flags: ["workflow.approvals.enabled"]
2268
+ }
2269
+ });
2270
+ var ApprovalDetailPresentation = definePresentation({
2271
+ meta: {
2272
+ key: "workflow.approval.detail",
2273
+ version: "1.0.0",
2274
+ title: "Approval Details",
2275
+ description: "Detailed approval request view with context and actions",
2276
+ domain: "workflow-system",
2277
+ owners: ["@workflow-team"],
2278
+ tags: ["workflow", "approval", "detail"],
2279
+ stability: StabilityEnum.Experimental,
2280
+ goal: "Decision support for an approval request",
2281
+ context: "Specific approval action"
2282
+ },
2283
+ source: {
2284
+ type: "component",
2285
+ framework: "react",
2286
+ componentKey: "ApprovalRequestDetail",
2287
+ props: ApprovalRequestModel
2288
+ },
2289
+ targets: ["react", "markdown"],
2290
+ policy: {
2291
+ flags: ["workflow.approvals.enabled"]
2292
+ }
2293
+ });
2294
+ var ApprovalFormPresentation = definePresentation({
2295
+ meta: {
2296
+ key: "workflow.approval.form",
2297
+ version: "1.0.0",
2298
+ title: "Approval Form",
2299
+ description: "Form for submitting approval decisions",
2300
+ domain: "workflow-system",
2301
+ owners: ["@workflow-team"],
2302
+ tags: ["workflow", "approval", "form"],
2303
+ stability: StabilityEnum.Experimental,
2304
+ goal: "Submitting a decision on an approval request",
2305
+ context: "Approval decision dialog"
2306
+ },
2307
+ source: {
2308
+ type: "component",
2309
+ framework: "react",
2310
+ componentKey: "ApprovalDecisionForm"
2311
+ },
2312
+ targets: ["react"],
2313
+ policy: {
2314
+ flags: ["workflow.approvals.enabled"]
2315
+ }
2316
+ });
2317
+ var PendingApprovalsBadgePresentation = definePresentation({
2318
+ meta: {
2319
+ key: "workflow.approval.badge",
2320
+ version: "1.0.0",
2321
+ title: "Pending Approvals Badge",
2322
+ description: "Badge showing count of pending approvals",
2323
+ domain: "workflow-system",
2324
+ owners: ["@workflow-team"],
2325
+ tags: ["workflow", "approval", "badge", "widget"],
2326
+ stability: StabilityEnum.Experimental,
2327
+ goal: "Visual notification of pending approvals",
2328
+ context: "Global navigation or sidebar"
2329
+ },
2330
+ source: {
2331
+ type: "component",
2332
+ framework: "react",
2333
+ componentKey: "PendingApprovalsBadge"
2334
+ },
2335
+ targets: ["react"],
2336
+ policy: {
2337
+ flags: ["workflow.approvals.enabled"]
2338
+ }
2339
+ });
2340
+ var WorkflowMetricsPresentation = definePresentation({
2341
+ meta: {
2342
+ key: "workflow.metrics",
2343
+ version: "1.0.0",
2344
+ title: "Workflow Metrics",
2345
+ description: "Dashboard widget showing workflow metrics and statistics",
2346
+ domain: "workflow-system",
2347
+ owners: ["@workflow-team"],
2348
+ tags: ["workflow", "metrics", "dashboard"],
2349
+ stability: StabilityEnum.Experimental,
2350
+ goal: "Monitoring throughput and bottlenecks",
2351
+ context: "System performance dashboard"
2352
+ },
2353
+ source: {
2354
+ type: "component",
2355
+ framework: "react",
2356
+ componentKey: "WorkflowMetricsDashboard"
2357
+ },
2358
+ targets: ["react", "markdown"],
2359
+ policy: {
2360
+ flags: ["workflow.metrics.enabled"]
2361
+ }
2362
+ });
2363
+ var WorkflowSystemPresentations = {
2364
+ WorkflowDesignerPresentation,
2365
+ WorkflowListPresentation,
2366
+ WorkflowDetailPresentation,
2367
+ InstanceListPresentation,
2368
+ InstanceDetailPresentation,
2369
+ ProgressTrackerPresentation,
2370
+ ApprovalInboxPresentation,
2371
+ ApprovalDetailPresentation,
2372
+ ApprovalFormPresentation,
2373
+ PendingApprovalsBadgePresentation,
2374
+ WorkflowMetricsPresentation
2375
+ };
2376
+
2377
+ // src/workflow-system.feature.ts
2378
+ import { defineFeature } from "@contractspec/lib.contracts";
2379
+ var WorkflowSystemFeature = defineFeature({
2380
+ meta: {
2381
+ key: "workflow-system",
2382
+ title: "Workflow & Approval System",
2383
+ description: "State machine-based workflow engine with role-based approvals, delegation, and escalation",
2384
+ domain: "workflow",
2385
+ owners: ["@workflow-team"],
2386
+ tags: ["workflow", "approval", "state-machine", "automation"],
2387
+ stability: "experimental",
2388
+ version: "1.0.0"
2389
+ },
2390
+ operations: [
2391
+ { key: "workflow.definition.create", version: "1.0.0" },
2392
+ { key: "workflow.definition.update", version: "1.0.0" },
2393
+ { key: "workflow.step.add", version: "1.0.0" },
2394
+ { key: "workflow.definition.publish", version: "1.0.0" },
2395
+ { key: "workflow.definition.list", version: "1.0.0" },
2396
+ { key: "workflow.definition.get", version: "1.0.0" },
2397
+ { key: "workflow.instance.start", version: "1.0.0" },
2398
+ { key: "workflow.instance.transition", version: "1.0.0" },
2399
+ { key: "workflow.instance.pause", version: "1.0.0" },
2400
+ { key: "workflow.instance.resume", version: "1.0.0" },
2401
+ { key: "workflow.instance.cancel", version: "1.0.0" },
2402
+ { key: "workflow.instance.list", version: "1.0.0" },
2403
+ { key: "workflow.instance.get", version: "1.0.0" },
2404
+ { key: "workflow.approval.decide", version: "1.0.0" },
2405
+ { key: "workflow.approval.delegate", version: "1.0.0" },
2406
+ { key: "workflow.approval.comment.add", version: "1.0.0" },
2407
+ { key: "workflow.approval.list.mine", version: "1.0.0" },
2408
+ { key: "workflow.approval.get", version: "1.0.0" }
2409
+ ],
2410
+ events: [
2411
+ { key: "workflow.definition.created", version: "1.0.0" },
2412
+ { key: "workflow.definition.updated", version: "1.0.0" },
2413
+ { key: "workflow.definition.published", version: "1.0.0" },
2414
+ { key: "workflow.step.added", version: "1.0.0" },
2415
+ { key: "workflow.instance.started", version: "1.0.0" },
2416
+ { key: "workflow.step.entered", version: "1.0.0" },
2417
+ { key: "workflow.step.exited", version: "1.0.0" },
2418
+ { key: "workflow.instance.completed", version: "1.0.0" },
2419
+ { key: "workflow.instance.cancelled", version: "1.0.0" },
2420
+ { key: "workflow.instance.paused", version: "1.0.0" },
2421
+ { key: "workflow.instance.resumed", version: "1.0.0" },
2422
+ { key: "workflow.instance.failed", version: "1.0.0" },
2423
+ { key: "workflow.instance.timedOut", version: "1.0.0" },
2424
+ { key: "workflow.approval.requested", version: "1.0.0" },
2425
+ { key: "workflow.approval.decided", version: "1.0.0" },
2426
+ { key: "workflow.approval.delegated", version: "1.0.0" },
2427
+ { key: "workflow.approval.escalated", version: "1.0.0" }
2428
+ ],
2429
+ presentations: [
2430
+ { key: "workflow.designer", version: "1.0.0" },
2431
+ { key: "workflow.definition.viewList", version: "1.0.0" },
2432
+ { key: "workflow.definition.detail", version: "1.0.0" },
2433
+ { key: "workflow.instance.viewList", version: "1.0.0" },
2434
+ { key: "workflow.instance.detail", version: "1.0.0" },
2435
+ { key: "workflow.instance.progress", version: "1.0.0" },
2436
+ { key: "workflow.approval.inbox", version: "1.0.0" },
2437
+ { key: "workflow.approval.detail", version: "1.0.0" },
2438
+ { key: "workflow.approval.form", version: "1.0.0" },
2439
+ { key: "workflow.approval.badge", version: "1.0.0" },
2440
+ { key: "workflow.metrics", version: "1.0.0" }
2441
+ ],
2442
+ opToPresentation: [
2443
+ {
2444
+ op: { key: "workflow.definition.list", version: "1.0.0" },
2445
+ pres: { key: "workflow.definition.viewList", version: "1.0.0" }
2446
+ },
2447
+ {
2448
+ op: { key: "workflow.instance.list", version: "1.0.0" },
2449
+ pres: { key: "workflow.instance.viewList", version: "1.0.0" }
2450
+ },
2451
+ {
2452
+ op: { key: "workflow.approval.list.mine", version: "1.0.0" },
2453
+ pres: { key: "workflow.approval.inbox", version: "1.0.0" }
2454
+ },
2455
+ {
2456
+ op: { key: "workflow.approval.decide", version: "1.0.0" },
2457
+ pres: { key: "workflow.approval.form", version: "1.0.0" }
2458
+ }
2459
+ ],
2460
+ presentationsTargets: [
2461
+ { key: "workflow.designer", version: "1.0.0", targets: ["react"] },
2462
+ {
2463
+ key: "workflow.definition.viewList",
2464
+ version: "1.0.0",
2465
+ targets: ["react", "markdown"]
2466
+ },
2467
+ {
2468
+ key: "workflow.definition.detail",
2469
+ version: "1.0.0",
2470
+ targets: ["react", "markdown"]
2471
+ },
2472
+ {
2473
+ key: "workflow.instance.viewList",
2474
+ version: "1.0.0",
2475
+ targets: ["react", "markdown"]
2476
+ },
2477
+ {
2478
+ key: "workflow.instance.detail",
2479
+ version: "1.0.0",
2480
+ targets: ["react", "markdown"]
2481
+ },
2482
+ { key: "workflow.instance.progress", version: "1.0.0", targets: ["react"] },
2483
+ {
2484
+ key: "workflow.approval.inbox",
2485
+ version: "1.0.0",
2486
+ targets: ["react", "markdown"]
2487
+ },
2488
+ {
2489
+ key: "workflow.approval.detail",
2490
+ version: "1.0.0",
2491
+ targets: ["react", "markdown"]
2492
+ },
2493
+ {
2494
+ key: "workflow.metrics",
2495
+ version: "1.0.0",
2496
+ targets: ["react", "markdown"]
2497
+ }
2498
+ ],
2499
+ capabilities: {
2500
+ requires: [
2501
+ { key: "identity", version: "1.0.0" },
2502
+ { key: "audit-trail", version: "1.0.0" },
2503
+ { key: "notifications", version: "1.0.0" },
2504
+ { key: "feature-flags", version: "1.0.0" }
2505
+ ],
2506
+ provides: [
2507
+ { key: "workflow", version: "1.0.0" },
2508
+ { key: "approval", version: "1.0.0" },
2509
+ { key: "state-machine", version: "1.0.0" }
2510
+ ]
2511
+ }
2512
+ });
2513
+
2514
+ // src/ui/renderers/workflow.markdown.ts
2515
+ var mockWorkflowDefinitions = [
2516
+ {
2517
+ id: "wf-1",
2518
+ name: "Purchase Approval",
2519
+ type: "APPROVAL",
2520
+ steps: [
2521
+ {
2522
+ id: "s1",
2523
+ name: "Manager Review",
2524
+ order: 1,
2525
+ requiredRoles: ["manager"]
2526
+ },
2527
+ {
2528
+ id: "s2",
2529
+ name: "Finance Review",
2530
+ order: 2,
2531
+ requiredRoles: ["finance"]
2532
+ },
2533
+ { id: "s3", name: "Final Approval", order: 3, requiredRoles: ["admin"] }
2534
+ ],
2535
+ status: "ACTIVE"
2536
+ },
2537
+ {
2538
+ id: "wf-2",
2539
+ name: "Leave Request",
2540
+ type: "APPROVAL",
2541
+ steps: [
2542
+ {
2543
+ id: "s1",
2544
+ name: "Supervisor Approval",
2545
+ order: 1,
2546
+ requiredRoles: ["supervisor"]
2547
+ },
2548
+ { id: "s2", name: "HR Review", order: 2, requiredRoles: ["hr"] }
2549
+ ],
2550
+ status: "ACTIVE"
2551
+ },
2552
+ {
2553
+ id: "wf-3",
2554
+ name: "Document Review",
2555
+ type: "SEQUENTIAL",
2556
+ steps: [
2557
+ { id: "s1", name: "Author Review", order: 1, requiredRoles: ["author"] },
2558
+ { id: "s2", name: "Peer Review", order: 2, requiredRoles: ["reviewer"] },
2559
+ { id: "s3", name: "Publish", order: 3, requiredRoles: ["publisher"] }
2560
+ ],
2561
+ status: "DRAFT"
2562
+ }
2563
+ ];
2564
+ var mockWorkflowInstances = [
2565
+ {
2566
+ id: "inst-1",
2567
+ definitionId: "wf-1",
2568
+ definitionName: "Purchase Approval",
2569
+ status: "IN_PROGRESS",
2570
+ currentStepId: "s2",
2571
+ startedAt: "2024-01-15T10:00:00Z",
2572
+ requestedBy: "John Doe"
2573
+ },
2574
+ {
2575
+ id: "inst-2",
2576
+ definitionId: "wf-1",
2577
+ definitionName: "Purchase Approval",
2578
+ status: "COMPLETED",
2579
+ currentStepId: null,
2580
+ startedAt: "2024-01-10T09:00:00Z",
2581
+ completedAt: "2024-01-12T14:00:00Z",
2582
+ requestedBy: "Jane Smith"
2583
+ },
2584
+ {
2585
+ id: "inst-3",
2586
+ definitionId: "wf-2",
2587
+ definitionName: "Leave Request",
2588
+ status: "PENDING",
2589
+ currentStepId: "s1",
2590
+ startedAt: "2024-01-16T08:00:00Z",
2591
+ requestedBy: "Bob Wilson"
2592
+ }
2593
+ ];
2594
+ var workflowDashboardMarkdownRenderer = {
2595
+ target: "markdown",
2596
+ render: async (desc) => {
2597
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDashboard") {
2598
+ throw new Error("workflowDashboardMarkdownRenderer: not WorkflowDashboard");
2599
+ }
2600
+ const definitions = mockWorkflowDefinitions;
2601
+ const instances = mockWorkflowInstances;
2602
+ const activeDefinitions = definitions.filter((d) => d.status === "ACTIVE");
2603
+ const pendingInstances = instances.filter((i) => i.status === "PENDING");
2604
+ const inProgressInstances = instances.filter((i) => i.status === "IN_PROGRESS");
2605
+ const completedInstances = instances.filter((i) => i.status === "COMPLETED");
2606
+ const lines = [
2607
+ "# Workflow Dashboard",
2608
+ "",
2609
+ "> Workflow and approval management overview",
2610
+ "",
2611
+ "## Summary",
2612
+ "",
2613
+ "| Metric | Value |",
2614
+ "|--------|-------|",
2615
+ `| Active Workflows | ${activeDefinitions.length} |`,
2616
+ `| Pending Approvals | ${pendingInstances.length} |`,
2617
+ `| In Progress | ${inProgressInstances.length} |`,
2618
+ `| Completed | ${completedInstances.length} |`,
2619
+ "",
2620
+ "## Active Workflow Definitions",
2621
+ ""
2622
+ ];
2623
+ if (activeDefinitions.length === 0) {
2624
+ lines.push("_No active workflow definitions._");
2625
+ } else {
2626
+ lines.push("| Name | Type | Steps | Status |");
2627
+ lines.push("|------|------|-------|--------|");
2628
+ for (const def of activeDefinitions) {
2629
+ lines.push(`| ${def.name} | ${def.type} | ${def.steps.length} | ${def.status} |`);
2630
+ }
2631
+ }
2632
+ lines.push("");
2633
+ lines.push("## Recent Instances");
2634
+ lines.push("");
2635
+ if (instances.length === 0) {
2636
+ lines.push("_No workflow instances._");
2637
+ } else {
2638
+ lines.push("| Workflow | Requested By | Status | Started |");
2639
+ lines.push("|----------|--------------|--------|---------|");
2640
+ for (const inst of instances.slice(0, 10)) {
2641
+ const startedDate = new Date(inst.startedAt).toLocaleDateString();
2642
+ lines.push(`| ${inst.definitionName} | ${inst.requestedBy} | ${inst.status} | ${startedDate} |`);
2643
+ }
2644
+ }
2645
+ return {
2646
+ mimeType: "text/markdown",
2647
+ body: lines.join(`
2648
+ `)
2649
+ };
2650
+ }
2651
+ };
2652
+ var workflowDefinitionListMarkdownRenderer = {
2653
+ target: "markdown",
2654
+ render: async (desc) => {
2655
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDefinitionList") {
2656
+ throw new Error("workflowDefinitionListMarkdownRenderer: not WorkflowDefinitionList");
2657
+ }
2658
+ const definitions = mockWorkflowDefinitions;
2659
+ const lines = [
2660
+ "# Workflow Definitions",
2661
+ "",
2662
+ "> Configure automated approval and process workflows",
2663
+ ""
2664
+ ];
2665
+ for (const def of definitions) {
2666
+ lines.push(`## ${def.name}`);
2667
+ lines.push("");
2668
+ lines.push(`**Type:** ${def.type} | **Status:** ${def.status}`);
2669
+ lines.push("");
2670
+ lines.push("### Steps");
2671
+ lines.push("");
2672
+ for (const step of def.steps) {
2673
+ lines.push(`${step.order}. **${step.name}** - Roles: ${step.requiredRoles.join(", ")}`);
2674
+ }
2675
+ lines.push("");
2676
+ }
2677
+ return {
2678
+ mimeType: "text/markdown",
2679
+ body: lines.join(`
2680
+ `)
2681
+ };
2682
+ }
2683
+ };
2684
+ var workflowInstanceDetailMarkdownRenderer = {
2685
+ target: "markdown",
2686
+ render: async (desc) => {
2687
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowInstanceDetail") {
2688
+ throw new Error("workflowInstanceDetailMarkdownRenderer: not WorkflowInstanceDetail");
2689
+ }
2690
+ const instance = mockWorkflowInstances[0];
2691
+ if (!instance) {
2692
+ return {
2693
+ mimeType: "text/markdown",
2694
+ body: `# No Workflow Instances
2695
+
2696
+ No workflow instances available.`
2697
+ };
2698
+ }
2699
+ const definition = mockWorkflowDefinitions.find((d) => d.id === instance.definitionId);
2700
+ const lines = [
2701
+ `# Workflow: ${instance.definitionName}`,
2702
+ "",
2703
+ `**Instance ID:** ${instance.id}`,
2704
+ `**Status:** ${instance.status}`,
2705
+ `**Requested By:** ${instance.requestedBy}`,
2706
+ `**Started:** ${new Date(instance.startedAt).toLocaleString()}`,
2707
+ "",
2708
+ "## Steps Progress",
2709
+ ""
2710
+ ];
2711
+ if (definition) {
2712
+ for (const step of definition.steps) {
2713
+ const isCurrent = step.id === instance.currentStepId;
2714
+ const isCompleted = definition.steps.indexOf(step) < definition.steps.findIndex((s) => s.id === instance.currentStepId);
2715
+ let status = "\u2B1C Pending";
2716
+ if (isCompleted)
2717
+ status = "\u2705 Completed";
2718
+ if (isCurrent)
2719
+ status = "\uD83D\uDD04 In Progress";
2720
+ lines.push(`- ${status} **${step.name}**`);
2721
+ }
2722
+ }
2723
+ lines.push("");
2724
+ lines.push("## Actions");
2725
+ lines.push("");
2726
+ lines.push("- **Approve** - Move to next step");
2727
+ lines.push("- **Reject** - Reject and return");
2728
+ lines.push("- **Delegate** - Assign to another approver");
2729
+ return {
2730
+ mimeType: "text/markdown",
2731
+ body: lines.join(`
2732
+ `)
2733
+ };
2734
+ }
2735
+ };
2736
+ // src/ui/hooks/useWorkflowList.ts
2737
+ import { useCallback, useEffect, useState } from "react";
2738
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
2739
+ "use client";
2740
+ function useWorkflowList(projectId = "local-project") {
2741
+ const { handlers } = useTemplateRuntime();
2742
+ const workflow = handlers.workflow;
2743
+ const [definitions, setDefinitions] = useState([]);
2744
+ const [instances, setInstances] = useState([]);
2745
+ const [loading, setLoading] = useState(true);
2746
+ const [error, setError] = useState(null);
2747
+ const fetchData = useCallback(async () => {
2748
+ try {
2749
+ setLoading(true);
2750
+ setError(null);
2751
+ const [defResult, instResult] = await Promise.all([
2752
+ workflow.listDefinitions({ projectId, limit: 100 }),
2753
+ workflow.listInstances({ projectId, limit: 100 })
2754
+ ]);
2755
+ setDefinitions(defResult.definitions);
2756
+ setInstances(instResult.instances);
2757
+ } catch (err) {
2758
+ setError(err instanceof Error ? err : new Error("Failed to load workflows"));
2759
+ } finally {
2760
+ setLoading(false);
2761
+ }
2762
+ }, [handlers, projectId]);
2763
+ useEffect(() => {
2764
+ fetchData();
2765
+ }, [fetchData]);
2766
+ const stats = {
2767
+ totalDefinitions: definitions.length,
2768
+ activeDefinitions: definitions.filter((d) => d.status === "ACTIVE").length,
2769
+ totalInstances: instances.length,
2770
+ pendingInstances: instances.filter((i) => i.status === "PENDING").length,
2771
+ completedInstances: instances.filter((i) => i.status === "COMPLETED").length,
2772
+ rejectedInstances: instances.filter((i) => i.status === "REJECTED").length
2773
+ };
2774
+ return {
2775
+ definitions,
2776
+ instances,
2777
+ loading,
2778
+ error,
2779
+ stats,
2780
+ refetch: fetchData
2781
+ };
2782
+ }
2783
+
2784
+ // src/ui/WorkflowDashboard.tsx
2785
+ import { useState as useState2 } from "react";
2786
+ import {
2787
+ Button,
2788
+ ErrorState,
2789
+ LoaderBlock,
2790
+ StatCard,
2791
+ StatCardGroup
2792
+ } from "@contractspec/lib.design-system";
2793
+ import { jsxDEV } from "react/jsx-dev-runtime";
2794
+ "use client";
2795
+ var STATUS_COLORS = {
2796
+ ACTIVE: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
2797
+ DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
2798
+ ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",
2799
+ PENDING: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
2800
+ IN_PROGRESS: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
2801
+ COMPLETED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
2802
+ REJECTED: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
2803
+ CANCELLED: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
2804
+ };
2805
+ function WorkflowDashboard() {
2806
+ const [activeTab, setActiveTab] = useState2("definitions");
2807
+ const { definitions, instances, loading, error, stats, refetch } = useWorkflowList();
2808
+ const tabs = [
2809
+ { id: "definitions", label: "Definitions", icon: "\uD83D\uDCCB" },
2810
+ { id: "instances", label: "Instances", icon: "\uD83D\uDD04" }
2811
+ ];
2812
+ if (loading) {
2813
+ return /* @__PURE__ */ jsxDEV(LoaderBlock, {
2814
+ label: "Loading Workflows..."
2815
+ }, undefined, false, undefined, this);
2816
+ }
2817
+ if (error) {
2818
+ return /* @__PURE__ */ jsxDEV(ErrorState, {
2819
+ title: "Failed to load Workflows",
2820
+ description: error.message,
2821
+ onRetry: refetch,
2822
+ retryLabel: "Retry"
2823
+ }, undefined, false, undefined, this);
2824
+ }
2825
+ return /* @__PURE__ */ jsxDEV("div", {
2826
+ className: "space-y-6",
2827
+ children: [
2828
+ /* @__PURE__ */ jsxDEV("div", {
2829
+ className: "flex items-center justify-between",
2830
+ children: [
2831
+ /* @__PURE__ */ jsxDEV("h2", {
2832
+ className: "text-2xl font-bold",
2833
+ children: "Workflow System"
2834
+ }, undefined, false, undefined, this),
2835
+ /* @__PURE__ */ jsxDEV(Button, {
2836
+ onClick: () => alert("Create workflow modal"),
2837
+ children: [
2838
+ /* @__PURE__ */ jsxDEV("span", {
2839
+ className: "mr-2",
2840
+ children: "+"
2841
+ }, undefined, false, undefined, this),
2842
+ " New Workflow"
2843
+ ]
2844
+ }, undefined, true, undefined, this)
2845
+ ]
2846
+ }, undefined, true, undefined, this),
2847
+ /* @__PURE__ */ jsxDEV(StatCardGroup, {
2848
+ children: [
2849
+ /* @__PURE__ */ jsxDEV(StatCard, {
2850
+ label: "Workflows",
2851
+ value: stats.totalDefinitions,
2852
+ hint: `${stats.activeDefinitions} active`
2853
+ }, undefined, false, undefined, this),
2854
+ /* @__PURE__ */ jsxDEV(StatCard, {
2855
+ label: "Instances",
2856
+ value: stats.totalInstances,
2857
+ hint: "total runs"
2858
+ }, undefined, false, undefined, this),
2859
+ /* @__PURE__ */ jsxDEV(StatCard, {
2860
+ label: "Pending",
2861
+ value: stats.pendingInstances,
2862
+ hint: "awaiting action"
2863
+ }, undefined, false, undefined, this),
2864
+ /* @__PURE__ */ jsxDEV(StatCard, {
2865
+ label: "Completed",
2866
+ value: stats.completedInstances,
2867
+ hint: "finished"
2868
+ }, undefined, false, undefined, this)
2869
+ ]
2870
+ }, undefined, true, undefined, this),
2871
+ /* @__PURE__ */ jsxDEV("nav", {
2872
+ className: "bg-muted flex gap-1 rounded-lg p-1",
2873
+ role: "tablist",
2874
+ children: tabs.map((tab) => /* @__PURE__ */ jsxDEV(Button, {
2875
+ type: "button",
2876
+ role: "tab",
2877
+ "aria-selected": activeTab === tab.id,
2878
+ onClick: () => setActiveTab(tab.id),
2879
+ className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-medium transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
2880
+ children: [
2881
+ /* @__PURE__ */ jsxDEV("span", {
2882
+ children: tab.icon
2883
+ }, undefined, false, undefined, this),
2884
+ tab.label
2885
+ ]
2886
+ }, tab.id, true, undefined, this))
2887
+ }, undefined, false, undefined, this),
2888
+ /* @__PURE__ */ jsxDEV("div", {
2889
+ className: "min-h-[400px]",
2890
+ role: "tabpanel",
2891
+ children: [
2892
+ activeTab === "definitions" && /* @__PURE__ */ jsxDEV("div", {
2893
+ className: "border-border rounded-lg border",
2894
+ children: /* @__PURE__ */ jsxDEV("table", {
2895
+ className: "w-full",
2896
+ children: [
2897
+ /* @__PURE__ */ jsxDEV("thead", {
2898
+ className: "border-border bg-muted/30 border-b",
2899
+ children: /* @__PURE__ */ jsxDEV("tr", {
2900
+ children: [
2901
+ /* @__PURE__ */ jsxDEV("th", {
2902
+ className: "px-4 py-3 text-left text-sm font-medium",
2903
+ children: "Name"
2904
+ }, undefined, false, undefined, this),
2905
+ /* @__PURE__ */ jsxDEV("th", {
2906
+ className: "px-4 py-3 text-left text-sm font-medium",
2907
+ children: "Type"
2908
+ }, undefined, false, undefined, this),
2909
+ /* @__PURE__ */ jsxDEV("th", {
2910
+ className: "px-4 py-3 text-left text-sm font-medium",
2911
+ children: "Status"
2912
+ }, undefined, false, undefined, this),
2913
+ /* @__PURE__ */ jsxDEV("th", {
2914
+ className: "px-4 py-3 text-left text-sm font-medium",
2915
+ children: "Created"
2916
+ }, undefined, false, undefined, this)
2917
+ ]
2918
+ }, undefined, true, undefined, this)
2919
+ }, undefined, false, undefined, this),
2920
+ /* @__PURE__ */ jsxDEV("tbody", {
2921
+ className: "divide-border divide-y",
2922
+ children: [
2923
+ definitions.map((def) => /* @__PURE__ */ jsxDEV("tr", {
2924
+ className: "hover:bg-muted/50",
2925
+ children: [
2926
+ /* @__PURE__ */ jsxDEV("td", {
2927
+ className: "px-4 py-3",
2928
+ children: [
2929
+ /* @__PURE__ */ jsxDEV("div", {
2930
+ className: "font-medium",
2931
+ children: def.name
2932
+ }, undefined, false, undefined, this),
2933
+ /* @__PURE__ */ jsxDEV("div", {
2934
+ className: "text-muted-foreground text-sm",
2935
+ children: def.description
2936
+ }, undefined, false, undefined, this)
2937
+ ]
2938
+ }, undefined, true, undefined, this),
2939
+ /* @__PURE__ */ jsxDEV("td", {
2940
+ className: "px-4 py-3 font-mono text-sm",
2941
+ children: def.type
2942
+ }, undefined, false, undefined, this),
2943
+ /* @__PURE__ */ jsxDEV("td", {
2944
+ className: "px-4 py-3",
2945
+ children: /* @__PURE__ */ jsxDEV("span", {
2946
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[def.status] ?? ""}`,
2947
+ children: def.status
2948
+ }, undefined, false, undefined, this)
2949
+ }, undefined, false, undefined, this),
2950
+ /* @__PURE__ */ jsxDEV("td", {
2951
+ className: "text-muted-foreground px-4 py-3 text-sm",
2952
+ children: def.createdAt.toLocaleDateString()
2953
+ }, undefined, false, undefined, this)
2954
+ ]
2955
+ }, def.id, true, undefined, this)),
2956
+ definitions.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
2957
+ children: /* @__PURE__ */ jsxDEV("td", {
2958
+ colSpan: 4,
2959
+ className: "text-muted-foreground px-4 py-8 text-center",
2960
+ children: "No workflow definitions found"
2961
+ }, undefined, false, undefined, this)
2962
+ }, undefined, false, undefined, this)
2963
+ ]
2964
+ }, undefined, true, undefined, this)
2965
+ ]
2966
+ }, undefined, true, undefined, this)
2967
+ }, undefined, false, undefined, this),
2968
+ activeTab === "instances" && /* @__PURE__ */ jsxDEV("div", {
2969
+ className: "border-border rounded-lg border",
2970
+ children: /* @__PURE__ */ jsxDEV("table", {
2971
+ className: "w-full",
2972
+ children: [
2973
+ /* @__PURE__ */ jsxDEV("thead", {
2974
+ className: "border-border bg-muted/30 border-b",
2975
+ children: /* @__PURE__ */ jsxDEV("tr", {
2976
+ children: [
2977
+ /* @__PURE__ */ jsxDEV("th", {
2978
+ className: "px-4 py-3 text-left text-sm font-medium",
2979
+ children: "Instance ID"
2980
+ }, undefined, false, undefined, this),
2981
+ /* @__PURE__ */ jsxDEV("th", {
2982
+ className: "px-4 py-3 text-left text-sm font-medium",
2983
+ children: "Status"
2984
+ }, undefined, false, undefined, this),
2985
+ /* @__PURE__ */ jsxDEV("th", {
2986
+ className: "px-4 py-3 text-left text-sm font-medium",
2987
+ children: "Requested By"
2988
+ }, undefined, false, undefined, this),
2989
+ /* @__PURE__ */ jsxDEV("th", {
2990
+ className: "px-4 py-3 text-left text-sm font-medium",
2991
+ children: "Started"
2992
+ }, undefined, false, undefined, this)
2993
+ ]
2994
+ }, undefined, true, undefined, this)
2995
+ }, undefined, false, undefined, this),
2996
+ /* @__PURE__ */ jsxDEV("tbody", {
2997
+ className: "divide-border divide-y",
2998
+ children: [
2999
+ instances.map((inst) => /* @__PURE__ */ jsxDEV("tr", {
3000
+ className: "hover:bg-muted/50",
3001
+ children: [
3002
+ /* @__PURE__ */ jsxDEV("td", {
3003
+ className: "px-4 py-3 font-mono text-sm",
3004
+ children: inst.id
3005
+ }, undefined, false, undefined, this),
3006
+ /* @__PURE__ */ jsxDEV("td", {
3007
+ className: "px-4 py-3",
3008
+ children: /* @__PURE__ */ jsxDEV("span", {
3009
+ className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[inst.status] ?? ""}`,
3010
+ children: inst.status
3011
+ }, undefined, false, undefined, this)
3012
+ }, undefined, false, undefined, this),
3013
+ /* @__PURE__ */ jsxDEV("td", {
3014
+ className: "px-4 py-3 text-sm",
3015
+ children: inst.requestedBy
3016
+ }, undefined, false, undefined, this),
3017
+ /* @__PURE__ */ jsxDEV("td", {
3018
+ className: "text-muted-foreground px-4 py-3 text-sm",
3019
+ children: inst.startedAt.toLocaleDateString()
3020
+ }, undefined, false, undefined, this)
3021
+ ]
3022
+ }, inst.id, true, undefined, this)),
3023
+ instances.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
3024
+ children: /* @__PURE__ */ jsxDEV("td", {
3025
+ colSpan: 4,
3026
+ className: "text-muted-foreground px-4 py-8 text-center",
3027
+ children: "No workflow instances found"
3028
+ }, undefined, false, undefined, this)
3029
+ }, undefined, false, undefined, this)
3030
+ ]
3031
+ }, undefined, true, undefined, this)
3032
+ ]
3033
+ }, undefined, true, undefined, this)
3034
+ }, undefined, false, undefined, this)
3035
+ ]
3036
+ }, undefined, true, undefined, this)
3037
+ ]
3038
+ }, undefined, true, undefined, this);
3039
+ }
3040
+
3041
+ // src/ui/hooks/index.ts
3042
+ "use client";
3043
+ export {
3044
+ workflowInstanceDetailMarkdownRenderer,
3045
+ workflowDefinitionListMarkdownRenderer,
3046
+ workflowDashboardMarkdownRenderer,
3047
+ useWorkflowList,
3048
+ mockDataStore,
3049
+ createWorkflowHandlers,
3050
+ createStateMachineEngine,
3051
+ createInitialState,
3052
+ buildStateMachineDefinition,
3053
+ WorkflowUpdatedEvent,
3054
+ WorkflowSystemPresentations,
3055
+ WorkflowSystemFeature,
3056
+ WorkflowStepModel,
3057
+ WorkflowStatusEnum,
3058
+ WorkflowPublishedEvent,
3059
+ WorkflowMetricsPresentation,
3060
+ WorkflowListPresentation,
3061
+ WorkflowInstanceModel,
3062
+ WorkflowDetailPresentation,
3063
+ WorkflowDesignerPresentation,
3064
+ WorkflowDefinitionModel,
3065
+ WorkflowDashboard,
3066
+ WorkflowCreatedEvent,
3067
+ UpdateWorkflowInputModel,
3068
+ UpdateWorkflowContract,
3069
+ TriggerTypeEnum,
3070
+ TransitionWorkflowContract,
3071
+ TransitionResultModel,
3072
+ TransitionInputModel,
3073
+ SubmitDecisionContract,
3074
+ StepTypeEnum,
3075
+ StepExitedEvent,
3076
+ StepEnteredEvent,
3077
+ StepAddedEvent,
3078
+ StartWorkflowInputModel,
3079
+ StartWorkflowContract,
3080
+ ResumeWorkflowContract,
3081
+ PublishWorkflowContract,
3082
+ ProgressTrackerPresentation,
3083
+ PendingApprovalsBadgePresentation,
3084
+ PauseWorkflowContract,
3085
+ ListWorkflowsContract,
3086
+ ListMyApprovalsContract,
3087
+ ListInstancesContract,
3088
+ InstanceTimedOutEvent,
3089
+ InstanceStatusEnum,
3090
+ InstanceStartedEvent,
3091
+ InstanceResumedEvent,
3092
+ InstancePausedEvent,
3093
+ InstanceListPresentation,
3094
+ InstanceFailedEvent,
3095
+ InstanceDetailPresentation,
3096
+ InstanceCompletedEvent,
3097
+ InstanceCancelledEvent,
3098
+ GetWorkflowContract,
3099
+ GetInstanceContract,
3100
+ GetApprovalContract,
3101
+ DelegateApprovalContract,
3102
+ CreateWorkflowInputModel,
3103
+ CreateWorkflowContract,
3104
+ CancelWorkflowContract,
3105
+ BasicStateMachineEngine,
3106
+ ApprovalStatusEnum,
3107
+ ApprovalRequestedEvent,
3108
+ ApprovalRequestModel,
3109
+ ApprovalModeEnum,
3110
+ ApprovalInboxPresentation,
3111
+ ApprovalFormPresentation,
3112
+ ApprovalEscalatedEvent,
3113
+ ApprovalDetailPresentation,
3114
+ ApprovalDelegatedEvent,
3115
+ ApprovalDecisionEnum,
3116
+ ApprovalDecidedEvent,
3117
+ ApprovalCommentModel,
3118
+ AddStepInputModel,
3119
+ AddStepContract,
3120
+ AddApprovalCommentContract
3121
+ };