@contractspec/example.workflow-system 1.57.0 → 1.59.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
@@ -0,0 +1,484 @@
1
+ // src/approval/approval.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var ApprovalStatusEnum = defineEnum("ApprovalStatus", [
4
+ "PENDING",
5
+ "APPROVED",
6
+ "REJECTED",
7
+ "DELEGATED",
8
+ "ESCALATED",
9
+ "WITHDRAWN",
10
+ "EXPIRED"
11
+ ]);
12
+ var ApprovalDecisionEnum = defineEnum("ApprovalDecision", [
13
+ "APPROVE",
14
+ "REJECT",
15
+ "REQUEST_CHANGES",
16
+ "DELEGATE",
17
+ "ABSTAIN"
18
+ ]);
19
+
20
+ // src/approval/approval.event.ts
21
+ import { defineEvent, defineSchemaModel } from "@contractspec/lib.contracts";
22
+ import { ScalarTypeEnum } from "@contractspec/lib.schema";
23
+ var ApprovalRequestedPayload = defineSchemaModel({
24
+ name: "ApprovalRequestedEventPayload",
25
+ description: "Payload when approval is requested",
26
+ fields: {
27
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
28
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
29
+ workflowKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
30
+ approverId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
31
+ approverRole: {
32
+ type: ScalarTypeEnum.String_unsecure(),
33
+ isOptional: true
34
+ },
35
+ title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
36
+ dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
37
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
38
+ }
39
+ });
40
+ var ApprovalDecidedPayload = defineSchemaModel({
41
+ name: "ApprovalDecidedEventPayload",
42
+ description: "Payload when approval decision is made",
43
+ fields: {
44
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
45
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
46
+ decision: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
47
+ decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
48
+ comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
49
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
50
+ }
51
+ });
52
+ var ApprovalDelegatedPayload = defineSchemaModel({
53
+ name: "ApprovalDelegatedEventPayload",
54
+ description: "Payload when approval is delegated",
55
+ fields: {
56
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
57
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
58
+ fromUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
59
+ toUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
60
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
61
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
62
+ }
63
+ });
64
+ var ApprovalEscalatedPayload = defineSchemaModel({
65
+ name: "ApprovalEscalatedEventPayload",
66
+ description: "Payload when approval is escalated",
67
+ fields: {
68
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
69
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
70
+ escalationLevel: {
71
+ type: ScalarTypeEnum.Int_unsecure(),
72
+ isOptional: false
73
+ },
74
+ escalatedTo: {
75
+ type: ScalarTypeEnum.String_unsecure(),
76
+ isOptional: false
77
+ },
78
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
79
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
80
+ }
81
+ });
82
+ var ApprovalRequestedEvent = defineEvent({
83
+ meta: {
84
+ key: "workflow.approval.requested",
85
+ version: "1.0.0",
86
+ description: "An approval has been requested.",
87
+ stability: "stable",
88
+ owners: ["@workflow-team"],
89
+ tags: ["workflow", "approval", "requested"]
90
+ },
91
+ payload: ApprovalRequestedPayload
92
+ });
93
+ var ApprovalDecidedEvent = defineEvent({
94
+ meta: {
95
+ key: "workflow.approval.decided",
96
+ version: "1.0.0",
97
+ description: "An approval decision has been made.",
98
+ stability: "stable",
99
+ owners: ["@workflow-team"],
100
+ tags: ["workflow", "approval", "decided"]
101
+ },
102
+ payload: ApprovalDecidedPayload
103
+ });
104
+ var ApprovalDelegatedEvent = defineEvent({
105
+ meta: {
106
+ key: "workflow.approval.delegated",
107
+ version: "1.0.0",
108
+ description: "An approval has been delegated.",
109
+ stability: "stable",
110
+ owners: ["@workflow-team"],
111
+ tags: ["workflow", "approval", "delegated"]
112
+ },
113
+ payload: ApprovalDelegatedPayload
114
+ });
115
+ var ApprovalEscalatedEvent = defineEvent({
116
+ meta: {
117
+ key: "workflow.approval.escalated",
118
+ version: "1.0.0",
119
+ description: "An approval has been escalated.",
120
+ stability: "stable",
121
+ owners: ["@workflow-team"],
122
+ tags: ["workflow", "approval", "escalated"]
123
+ },
124
+ payload: ApprovalEscalatedPayload
125
+ });
126
+
127
+ // src/approval/approval.schema.ts
128
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
129
+ var ApprovalRequestModel = defineSchemaModel2({
130
+ name: "ApprovalRequestModel",
131
+ description: "An approval request",
132
+ fields: {
133
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
134
+ workflowInstanceId: {
135
+ type: ScalarTypeEnum2.String_unsecure(),
136
+ isOptional: false
137
+ },
138
+ stepExecutionId: {
139
+ type: ScalarTypeEnum2.String_unsecure(),
140
+ isOptional: false
141
+ },
142
+ approverId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
143
+ approverRole: {
144
+ type: ScalarTypeEnum2.String_unsecure(),
145
+ isOptional: true
146
+ },
147
+ title: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
148
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
149
+ status: { type: ApprovalStatusEnum, isOptional: false },
150
+ decision: { type: ApprovalDecisionEnum, isOptional: true },
151
+ decisionComment: {
152
+ type: ScalarTypeEnum2.String_unsecure(),
153
+ isOptional: true
154
+ },
155
+ decidedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
156
+ dueAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
157
+ contextSnapshot: { type: ScalarTypeEnum2.JSON(), isOptional: true },
158
+ sequenceOrder: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
159
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
160
+ }
161
+ });
162
+ var ApprovalCommentModel = defineSchemaModel2({
163
+ name: "ApprovalCommentModel",
164
+ description: "A comment on an approval",
165
+ fields: {
166
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
167
+ approvalRequestId: {
168
+ type: ScalarTypeEnum2.String_unsecure(),
169
+ isOptional: false
170
+ },
171
+ authorId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
172
+ content: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
173
+ isInternal: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
174
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
175
+ }
176
+ });
177
+
178
+ // src/approval/approval.operations.ts
179
+ import {
180
+ defineCommand,
181
+ defineQuery
182
+ } from "@contractspec/lib.contracts/operations";
183
+ import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
184
+ var OWNERS = ["@example.workflow-system"];
185
+ var SubmitDecisionContract = defineCommand({
186
+ meta: {
187
+ key: "workflow.approval.decide",
188
+ version: "1.0.0",
189
+ stability: "stable",
190
+ owners: [...OWNERS],
191
+ tags: ["workflow", "approval", "decision"],
192
+ description: "Submit an approval decision (approve/reject).",
193
+ goal: "Allow approvers to make decisions on requests.",
194
+ context: "Approval inbox, workflow detail."
195
+ },
196
+ io: {
197
+ input: defineSchemaModel3({
198
+ name: "ApproveRejectInput",
199
+ fields: {
200
+ requestId: {
201
+ type: ScalarTypeEnum3.String_unsecure(),
202
+ isOptional: false
203
+ },
204
+ decision: { type: ApprovalDecisionEnum, isOptional: false },
205
+ comment: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
206
+ data: { type: ScalarTypeEnum3.JSON(), isOptional: true }
207
+ }
208
+ }),
209
+ output: ApprovalRequestModel
210
+ },
211
+ policy: { auth: "user" },
212
+ sideEffects: {
213
+ emits: [
214
+ {
215
+ key: "workflow.approval.decided",
216
+ version: "1.0.0",
217
+ when: "Decision is made",
218
+ payload: ApprovalRequestModel
219
+ }
220
+ ],
221
+ audit: ["workflow.approval.decided"]
222
+ },
223
+ acceptance: {
224
+ scenarios: [
225
+ {
226
+ key: "approve-request-happy-path",
227
+ given: ["Approval request is pending", "User is assignee"],
228
+ when: ["User approves request"],
229
+ then: ["Request is approved", "ApprovalDecided event is emitted"]
230
+ }
231
+ ],
232
+ examples: [
233
+ {
234
+ key: "approve-basic",
235
+ input: {
236
+ requestId: "req-123",
237
+ decision: "approve",
238
+ comment: "Looks good"
239
+ },
240
+ output: { id: "req-123", status: "approved" }
241
+ }
242
+ ]
243
+ }
244
+ });
245
+ var DelegateApprovalContract = defineCommand({
246
+ meta: {
247
+ key: "workflow.approval.delegate",
248
+ version: "1.0.0",
249
+ stability: "stable",
250
+ owners: [...OWNERS],
251
+ tags: ["workflow", "approval", "delegate"],
252
+ description: "Delegate an approval request to another user.",
253
+ goal: "Allow approvers to pass approval to others.",
254
+ context: "Approval inbox."
255
+ },
256
+ io: {
257
+ input: defineSchemaModel3({
258
+ name: "DelegateInput",
259
+ fields: {
260
+ requestId: {
261
+ type: ScalarTypeEnum3.String_unsecure(),
262
+ isOptional: false
263
+ },
264
+ delegateTo: {
265
+ type: ScalarTypeEnum3.String_unsecure(),
266
+ isOptional: false
267
+ },
268
+ reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
269
+ }
270
+ }),
271
+ output: ApprovalRequestModel
272
+ },
273
+ policy: { auth: "user" },
274
+ sideEffects: {
275
+ emits: [
276
+ {
277
+ key: "workflow.approval.delegated",
278
+ version: "1.0.0",
279
+ when: "Approval is delegated",
280
+ payload: ApprovalRequestModel
281
+ }
282
+ ],
283
+ audit: ["workflow.approval.delegated"]
284
+ },
285
+ acceptance: {
286
+ scenarios: [
287
+ {
288
+ key: "delegate-approval-happy-path",
289
+ given: ["Approval request is pending", "User is assignee"],
290
+ when: ["User delegates to another user"],
291
+ then: ["Assignee is updated", "ApprovalDelegated event is emitted"]
292
+ }
293
+ ],
294
+ examples: [
295
+ {
296
+ key: "delegate-to-manager",
297
+ input: {
298
+ requestId: "req-123",
299
+ delegateTo: "user-456",
300
+ reason: "Out of office"
301
+ },
302
+ output: { id: "req-123", assigneeId: "user-456" }
303
+ }
304
+ ]
305
+ }
306
+ });
307
+ var AddApprovalCommentContract = defineCommand({
308
+ meta: {
309
+ key: "workflow.approval.comment.add",
310
+ version: "1.0.0",
311
+ stability: "stable",
312
+ owners: [...OWNERS],
313
+ tags: ["workflow", "approval", "comment"],
314
+ description: "Add a comment to an approval request.",
315
+ goal: "Allow discussion on approval requests.",
316
+ context: "Approval detail view."
317
+ },
318
+ io: {
319
+ input: defineSchemaModel3({
320
+ name: "AddCommentInput",
321
+ fields: {
322
+ requestId: {
323
+ type: ScalarTypeEnum3.String_unsecure(),
324
+ isOptional: false
325
+ },
326
+ content: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
327
+ isInternal: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
328
+ }
329
+ }),
330
+ output: ApprovalCommentModel
331
+ },
332
+ policy: { auth: "user" },
333
+ sideEffects: {
334
+ emits: [
335
+ {
336
+ key: "workflow.approval.comment.added",
337
+ version: "1.0.0",
338
+ when: "Comment is added",
339
+ payload: ApprovalCommentModel
340
+ }
341
+ ]
342
+ },
343
+ acceptance: {
344
+ scenarios: [
345
+ {
346
+ key: "add-comment-happy-path",
347
+ given: ["Approval request exists"],
348
+ when: ["User adds a comment"],
349
+ then: ["Comment is added", "CommentAdded event is emitted"]
350
+ }
351
+ ],
352
+ examples: [
353
+ {
354
+ key: "add-question",
355
+ input: {
356
+ requestId: "req-123",
357
+ content: "Can you clarify budget?",
358
+ isInternal: false
359
+ },
360
+ output: { id: "com-789", content: "Can you clarify budget?" }
361
+ }
362
+ ]
363
+ }
364
+ });
365
+ var ListMyApprovalsContract = defineQuery({
366
+ meta: {
367
+ key: "workflow.approval.list.mine",
368
+ version: "1.0.0",
369
+ stability: "stable",
370
+ owners: [...OWNERS],
371
+ tags: ["workflow", "approval", "list", "inbox"],
372
+ description: "List approval requests assigned to current user.",
373
+ goal: "Show pending approvals in user inbox.",
374
+ context: "Approval inbox, dashboard widget."
375
+ },
376
+ io: {
377
+ input: defineSchemaModel3({
378
+ name: "ListMyApprovalsInput",
379
+ fields: {
380
+ status: { type: ApprovalStatusEnum, isOptional: true },
381
+ limit: {
382
+ type: ScalarTypeEnum3.Int_unsecure(),
383
+ isOptional: true,
384
+ defaultValue: 20
385
+ },
386
+ offset: {
387
+ type: ScalarTypeEnum3.Int_unsecure(),
388
+ isOptional: true,
389
+ defaultValue: 0
390
+ }
391
+ }
392
+ }),
393
+ output: defineSchemaModel3({
394
+ name: "ListMyApprovalsOutput",
395
+ fields: {
396
+ requests: {
397
+ type: ApprovalRequestModel,
398
+ isArray: true,
399
+ isOptional: false
400
+ },
401
+ total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
402
+ pendingCount: {
403
+ type: ScalarTypeEnum3.Int_unsecure(),
404
+ isOptional: false
405
+ }
406
+ }
407
+ })
408
+ },
409
+ policy: { auth: "user" },
410
+ acceptance: {
411
+ scenarios: [
412
+ {
413
+ key: "list-approvals-happy-path",
414
+ given: ["User has assigned approvals"],
415
+ when: ["User lists approvals"],
416
+ then: ["List of requests is returned"]
417
+ }
418
+ ],
419
+ examples: [
420
+ {
421
+ key: "list-pending",
422
+ input: { status: "pending", limit: 10 },
423
+ output: { requests: [], total: 2, pendingCount: 2 }
424
+ }
425
+ ]
426
+ }
427
+ });
428
+ var GetApprovalContract = defineQuery({
429
+ meta: {
430
+ key: "workflow.approval.get",
431
+ version: "1.0.0",
432
+ stability: "stable",
433
+ owners: [...OWNERS],
434
+ tags: ["workflow", "approval", "get"],
435
+ description: "Get an approval request with details.",
436
+ goal: "View approval request details.",
437
+ context: "Approval detail view."
438
+ },
439
+ io: {
440
+ input: defineSchemaModel3({
441
+ name: "GetApprovalInput",
442
+ fields: {
443
+ requestId: {
444
+ type: ScalarTypeEnum3.String_unsecure(),
445
+ isOptional: false
446
+ }
447
+ }
448
+ }),
449
+ output: ApprovalRequestModel
450
+ },
451
+ policy: { auth: "user" },
452
+ acceptance: {
453
+ scenarios: [
454
+ {
455
+ key: "get-approval-happy-path",
456
+ given: ["Approval request exists"],
457
+ when: ["User requests approval details"],
458
+ then: ["Approval details are returned"]
459
+ }
460
+ ],
461
+ examples: [
462
+ {
463
+ key: "get-basic",
464
+ input: { requestId: "req-123" },
465
+ output: { id: "req-123", status: "pending" }
466
+ }
467
+ ]
468
+ }
469
+ });
470
+ export {
471
+ SubmitDecisionContract,
472
+ ListMyApprovalsContract,
473
+ GetApprovalContract,
474
+ DelegateApprovalContract,
475
+ ApprovalStatusEnum,
476
+ ApprovalRequestedEvent,
477
+ ApprovalRequestModel,
478
+ ApprovalEscalatedEvent,
479
+ ApprovalDelegatedEvent,
480
+ ApprovalDecisionEnum,
481
+ ApprovalDecidedEvent,
482
+ ApprovalCommentModel,
483
+ AddApprovalCommentContract
484
+ };
@@ -0,0 +1,103 @@
1
+ // src/docs/workflow-system.docblock.ts
2
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
3
+ var workflowSystemDocBlocks = [
4
+ {
5
+ id: "docs.examples.workflow-system",
6
+ title: "Workflow / Approval System",
7
+ summary: "Reference app showing state-machine driven approvals with RBAC, audit trail, notifications, and jobs.",
8
+ kind: "reference",
9
+ visibility: "public",
10
+ route: "/docs/examples/workflow-system",
11
+ tags: ["workflow", "approval", "state-machine", "rbac"],
12
+ body: `## Entities
13
+
14
+ - WorkflowDefinition, WorkflowStep, WorkflowInstance, Approval.
15
+ - State machine expressed in \`src/state-machine\` with allowed transitions and role gates.
16
+
17
+ ## Contracts
18
+
19
+ - \`workflow.definition.create\`, \`workflow.instance.start\`, \`workflow.step.approve\`, \`workflow.step.reject\`, \`workflow.instance.comment\`.
20
+ - Policies enforced via Identity/RBAC module; audit trail emitted on each transition.
21
+
22
+ ## Events & Jobs
23
+
24
+ - Emits \`workflow.instance.started\`, \`workflow.step.completed\`, \`workflow.step.rejected\`, \`workflow.instance.finished\`.
25
+ - Reminder jobs can be scheduled via @contractspec/lib.jobs for pending approvals.
26
+
27
+ ## UI / Presentations
28
+
29
+ - Dashboard, definition list/editor, instance detail with action buttons derived from state machine.
30
+ - Templates registered in Studio Template Registry under \`workflow-system\`.
31
+
32
+ ## Notes
33
+
34
+ - Keep transitions declarative to enable safe regeneration; role guards live in spec.
35
+ - Use Notification Center for approval requests and outcomes; attach files via Files module if needed.
36
+ `
37
+ },
38
+ {
39
+ id: "docs.examples.workflow-system.goal",
40
+ title: "Workflow System — Goal",
41
+ summary: "Why the workflow/approval template exists and outcomes it targets.",
42
+ kind: "goal",
43
+ visibility: "public",
44
+ route: "/docs/examples/workflow-system/goal",
45
+ tags: ["workflow", "goal"],
46
+ body: `## Why it matters
47
+ - Provides a regenerable, role-gated approval engine using declarative state machines.
48
+ - Keeps workflow rules consistent across UI/API/events with auditability.
49
+
50
+ ## Business/Product goal
51
+ - Enable approvals with clear transitions, reminders, and notifications.
52
+ - Support compliance via Audit Trail and Feature Flags for staged changes.
53
+
54
+ ## Success criteria
55
+ - State changes are declarative and regenerate cleanly.
56
+ - Every transition emits auditable events and respects RBAC guards.`
57
+ },
58
+ {
59
+ id: "docs.examples.workflow-system.usage",
60
+ title: "Workflow System — Usage",
61
+ summary: "How to configure workflows, transitions, and regenerate safely.",
62
+ kind: "usage",
63
+ visibility: "public",
64
+ route: "/docs/examples/workflow-system/usage",
65
+ tags: ["workflow", "usage"],
66
+ body: `## Setup
67
+ 1) Define WorkflowDefinition steps and allowed transitions with role gates in spec.
68
+ 2) Seed sample workflows/instances (if provided) or create via UI; enable reminders via Jobs.
69
+
70
+ ## Extend & regenerate
71
+ 1) Add steps/transitions or approval conditions in spec; include PII paths if comments/files.
72
+ 2) Regenerate to sync UI action buttons and API/state machine behavior.
73
+ 3) Use Feature Flags to trial new transitions or escalation rules.
74
+
75
+ ## Guardrails
76
+ - Emit events for every transition; log to Audit Trail.
77
+ - Use Notifications for approvals/rejections; schedule reminders for pending steps.
78
+ - Keep transitions declarative; avoid imperative branching in handlers.`
79
+ },
80
+ {
81
+ id: "docs.examples.workflow-system.constraints",
82
+ title: "Workflow System — Constraints & Safety",
83
+ summary: "Internal guardrails for state machines, RBAC, and regeneration semantics.",
84
+ kind: "reference",
85
+ visibility: "internal",
86
+ route: "/docs/examples/workflow-system/constraints",
87
+ tags: ["workflow", "constraints", "internal"],
88
+ body: `## Constraints
89
+ - State machine (steps/transitions) must stay declarative in spec; no hidden code paths.
90
+ - Events to emit: instance.started, step.completed/rejected, instance.finished.
91
+ - Regeneration must not change approval logic without explicit spec diff.
92
+
93
+ ## PII & Compliance
94
+ - Mark any PII in comments/attachments; redact in markdown/JSON.
95
+ - Ensure Audit Trail captures every transition; Notifications for approvals/rejections.
96
+
97
+ ## Verification
98
+ - Add fixtures for transition changes and role gates.
99
+ - Validate reminders (Jobs) stay aligned with pending states after regeneration.
100
+ - Use Feature Flags for new transitions/escalation rules; default safe/off.`
101
+ }
102
+ ];
103
+ registerDocBlocks(workflowSystemDocBlocks);
@@ -0,0 +1,103 @@
1
+ // src/docs/workflow-system.docblock.ts
2
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
3
+ var workflowSystemDocBlocks = [
4
+ {
5
+ id: "docs.examples.workflow-system",
6
+ title: "Workflow / Approval System",
7
+ summary: "Reference app showing state-machine driven approvals with RBAC, audit trail, notifications, and jobs.",
8
+ kind: "reference",
9
+ visibility: "public",
10
+ route: "/docs/examples/workflow-system",
11
+ tags: ["workflow", "approval", "state-machine", "rbac"],
12
+ body: `## Entities
13
+
14
+ - WorkflowDefinition, WorkflowStep, WorkflowInstance, Approval.
15
+ - State machine expressed in \`src/state-machine\` with allowed transitions and role gates.
16
+
17
+ ## Contracts
18
+
19
+ - \`workflow.definition.create\`, \`workflow.instance.start\`, \`workflow.step.approve\`, \`workflow.step.reject\`, \`workflow.instance.comment\`.
20
+ - Policies enforced via Identity/RBAC module; audit trail emitted on each transition.
21
+
22
+ ## Events & Jobs
23
+
24
+ - Emits \`workflow.instance.started\`, \`workflow.step.completed\`, \`workflow.step.rejected\`, \`workflow.instance.finished\`.
25
+ - Reminder jobs can be scheduled via @contractspec/lib.jobs for pending approvals.
26
+
27
+ ## UI / Presentations
28
+
29
+ - Dashboard, definition list/editor, instance detail with action buttons derived from state machine.
30
+ - Templates registered in Studio Template Registry under \`workflow-system\`.
31
+
32
+ ## Notes
33
+
34
+ - Keep transitions declarative to enable safe regeneration; role guards live in spec.
35
+ - Use Notification Center for approval requests and outcomes; attach files via Files module if needed.
36
+ `
37
+ },
38
+ {
39
+ id: "docs.examples.workflow-system.goal",
40
+ title: "Workflow System — Goal",
41
+ summary: "Why the workflow/approval template exists and outcomes it targets.",
42
+ kind: "goal",
43
+ visibility: "public",
44
+ route: "/docs/examples/workflow-system/goal",
45
+ tags: ["workflow", "goal"],
46
+ body: `## Why it matters
47
+ - Provides a regenerable, role-gated approval engine using declarative state machines.
48
+ - Keeps workflow rules consistent across UI/API/events with auditability.
49
+
50
+ ## Business/Product goal
51
+ - Enable approvals with clear transitions, reminders, and notifications.
52
+ - Support compliance via Audit Trail and Feature Flags for staged changes.
53
+
54
+ ## Success criteria
55
+ - State changes are declarative and regenerate cleanly.
56
+ - Every transition emits auditable events and respects RBAC guards.`
57
+ },
58
+ {
59
+ id: "docs.examples.workflow-system.usage",
60
+ title: "Workflow System — Usage",
61
+ summary: "How to configure workflows, transitions, and regenerate safely.",
62
+ kind: "usage",
63
+ visibility: "public",
64
+ route: "/docs/examples/workflow-system/usage",
65
+ tags: ["workflow", "usage"],
66
+ body: `## Setup
67
+ 1) Define WorkflowDefinition steps and allowed transitions with role gates in spec.
68
+ 2) Seed sample workflows/instances (if provided) or create via UI; enable reminders via Jobs.
69
+
70
+ ## Extend & regenerate
71
+ 1) Add steps/transitions or approval conditions in spec; include PII paths if comments/files.
72
+ 2) Regenerate to sync UI action buttons and API/state machine behavior.
73
+ 3) Use Feature Flags to trial new transitions or escalation rules.
74
+
75
+ ## Guardrails
76
+ - Emit events for every transition; log to Audit Trail.
77
+ - Use Notifications for approvals/rejections; schedule reminders for pending steps.
78
+ - Keep transitions declarative; avoid imperative branching in handlers.`
79
+ },
80
+ {
81
+ id: "docs.examples.workflow-system.constraints",
82
+ title: "Workflow System — Constraints & Safety",
83
+ summary: "Internal guardrails for state machines, RBAC, and regeneration semantics.",
84
+ kind: "reference",
85
+ visibility: "internal",
86
+ route: "/docs/examples/workflow-system/constraints",
87
+ tags: ["workflow", "constraints", "internal"],
88
+ body: `## Constraints
89
+ - State machine (steps/transitions) must stay declarative in spec; no hidden code paths.
90
+ - Events to emit: instance.started, step.completed/rejected, instance.finished.
91
+ - Regeneration must not change approval logic without explicit spec diff.
92
+
93
+ ## PII & Compliance
94
+ - Mark any PII in comments/attachments; redact in markdown/JSON.
95
+ - Ensure Audit Trail captures every transition; Notifications for approvals/rejections.
96
+
97
+ ## Verification
98
+ - Add fixtures for transition changes and role gates.
99
+ - Validate reminders (Jobs) stay aligned with pending states after regeneration.
100
+ - Use Feature Flags for new transitions/escalation rules; default safe/off.`
101
+ }
102
+ ];
103
+ registerDocBlocks(workflowSystemDocBlocks);