@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
@@ -1,6 +1,485 @@
1
- import { ApprovalDecisionEnum, ApprovalStatusEnum } from "./approval.enum.js";
2
- import { ApprovalCommentModel, ApprovalRequestModel } from "./approval.schema.js";
3
- import { AddApprovalCommentContract, DelegateApprovalContract, GetApprovalContract, ListMyApprovalsContract, SubmitDecisionContract } from "./approval.operations.js";
4
- import { ApprovalDecidedEvent, ApprovalDelegatedEvent, ApprovalEscalatedEvent, ApprovalRequestedEvent } from "./approval.event.js";
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
+ ]);
5
20
 
6
- export { AddApprovalCommentContract, ApprovalCommentModel, ApprovalDecidedEvent, ApprovalDecisionEnum, ApprovalDelegatedEvent, ApprovalEscalatedEvent, ApprovalRequestModel, ApprovalRequestedEvent, ApprovalStatusEnum, DelegateApprovalContract, GetApprovalContract, ListMyApprovalsContract, SubmitDecisionContract };
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/approval/approval.schema.ts
129
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
130
+ var ApprovalRequestModel = defineSchemaModel2({
131
+ name: "ApprovalRequestModel",
132
+ description: "An approval request",
133
+ fields: {
134
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
135
+ workflowInstanceId: {
136
+ type: ScalarTypeEnum2.String_unsecure(),
137
+ isOptional: false
138
+ },
139
+ stepExecutionId: {
140
+ type: ScalarTypeEnum2.String_unsecure(),
141
+ isOptional: false
142
+ },
143
+ approverId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
144
+ approverRole: {
145
+ type: ScalarTypeEnum2.String_unsecure(),
146
+ isOptional: true
147
+ },
148
+ title: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
149
+ description: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
150
+ status: { type: ApprovalStatusEnum, isOptional: false },
151
+ decision: { type: ApprovalDecisionEnum, isOptional: true },
152
+ decisionComment: {
153
+ type: ScalarTypeEnum2.String_unsecure(),
154
+ isOptional: true
155
+ },
156
+ decidedAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
157
+ dueAt: { type: ScalarTypeEnum2.DateTime(), isOptional: true },
158
+ contextSnapshot: { type: ScalarTypeEnum2.JSON(), isOptional: true },
159
+ sequenceOrder: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
160
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
161
+ }
162
+ });
163
+ var ApprovalCommentModel = defineSchemaModel2({
164
+ name: "ApprovalCommentModel",
165
+ description: "A comment on an approval",
166
+ fields: {
167
+ id: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
168
+ approvalRequestId: {
169
+ type: ScalarTypeEnum2.String_unsecure(),
170
+ isOptional: false
171
+ },
172
+ authorId: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
173
+ content: { type: ScalarTypeEnum2.String_unsecure(), isOptional: false },
174
+ isInternal: { type: ScalarTypeEnum2.Boolean(), isOptional: false },
175
+ createdAt: { type: ScalarTypeEnum2.DateTime(), isOptional: false }
176
+ }
177
+ });
178
+
179
+ // src/approval/approval.operations.ts
180
+ import {
181
+ defineCommand,
182
+ defineQuery
183
+ } from "@contractspec/lib.contracts/operations";
184
+ import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
185
+ var OWNERS = ["@example.workflow-system"];
186
+ var SubmitDecisionContract = defineCommand({
187
+ meta: {
188
+ key: "workflow.approval.decide",
189
+ version: "1.0.0",
190
+ stability: "stable",
191
+ owners: [...OWNERS],
192
+ tags: ["workflow", "approval", "decision"],
193
+ description: "Submit an approval decision (approve/reject).",
194
+ goal: "Allow approvers to make decisions on requests.",
195
+ context: "Approval inbox, workflow detail."
196
+ },
197
+ io: {
198
+ input: defineSchemaModel3({
199
+ name: "ApproveRejectInput",
200
+ fields: {
201
+ requestId: {
202
+ type: ScalarTypeEnum3.String_unsecure(),
203
+ isOptional: false
204
+ },
205
+ decision: { type: ApprovalDecisionEnum, isOptional: false },
206
+ comment: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true },
207
+ data: { type: ScalarTypeEnum3.JSON(), isOptional: true }
208
+ }
209
+ }),
210
+ output: ApprovalRequestModel
211
+ },
212
+ policy: { auth: "user" },
213
+ sideEffects: {
214
+ emits: [
215
+ {
216
+ key: "workflow.approval.decided",
217
+ version: "1.0.0",
218
+ when: "Decision is made",
219
+ payload: ApprovalRequestModel
220
+ }
221
+ ],
222
+ audit: ["workflow.approval.decided"]
223
+ },
224
+ acceptance: {
225
+ scenarios: [
226
+ {
227
+ key: "approve-request-happy-path",
228
+ given: ["Approval request is pending", "User is assignee"],
229
+ when: ["User approves request"],
230
+ then: ["Request is approved", "ApprovalDecided event is emitted"]
231
+ }
232
+ ],
233
+ examples: [
234
+ {
235
+ key: "approve-basic",
236
+ input: {
237
+ requestId: "req-123",
238
+ decision: "approve",
239
+ comment: "Looks good"
240
+ },
241
+ output: { id: "req-123", status: "approved" }
242
+ }
243
+ ]
244
+ }
245
+ });
246
+ var DelegateApprovalContract = defineCommand({
247
+ meta: {
248
+ key: "workflow.approval.delegate",
249
+ version: "1.0.0",
250
+ stability: "stable",
251
+ owners: [...OWNERS],
252
+ tags: ["workflow", "approval", "delegate"],
253
+ description: "Delegate an approval request to another user.",
254
+ goal: "Allow approvers to pass approval to others.",
255
+ context: "Approval inbox."
256
+ },
257
+ io: {
258
+ input: defineSchemaModel3({
259
+ name: "DelegateInput",
260
+ fields: {
261
+ requestId: {
262
+ type: ScalarTypeEnum3.String_unsecure(),
263
+ isOptional: false
264
+ },
265
+ delegateTo: {
266
+ type: ScalarTypeEnum3.String_unsecure(),
267
+ isOptional: false
268
+ },
269
+ reason: { type: ScalarTypeEnum3.String_unsecure(), isOptional: true }
270
+ }
271
+ }),
272
+ output: ApprovalRequestModel
273
+ },
274
+ policy: { auth: "user" },
275
+ sideEffects: {
276
+ emits: [
277
+ {
278
+ key: "workflow.approval.delegated",
279
+ version: "1.0.0",
280
+ when: "Approval is delegated",
281
+ payload: ApprovalRequestModel
282
+ }
283
+ ],
284
+ audit: ["workflow.approval.delegated"]
285
+ },
286
+ acceptance: {
287
+ scenarios: [
288
+ {
289
+ key: "delegate-approval-happy-path",
290
+ given: ["Approval request is pending", "User is assignee"],
291
+ when: ["User delegates to another user"],
292
+ then: ["Assignee is updated", "ApprovalDelegated event is emitted"]
293
+ }
294
+ ],
295
+ examples: [
296
+ {
297
+ key: "delegate-to-manager",
298
+ input: {
299
+ requestId: "req-123",
300
+ delegateTo: "user-456",
301
+ reason: "Out of office"
302
+ },
303
+ output: { id: "req-123", assigneeId: "user-456" }
304
+ }
305
+ ]
306
+ }
307
+ });
308
+ var AddApprovalCommentContract = defineCommand({
309
+ meta: {
310
+ key: "workflow.approval.comment.add",
311
+ version: "1.0.0",
312
+ stability: "stable",
313
+ owners: [...OWNERS],
314
+ tags: ["workflow", "approval", "comment"],
315
+ description: "Add a comment to an approval request.",
316
+ goal: "Allow discussion on approval requests.",
317
+ context: "Approval detail view."
318
+ },
319
+ io: {
320
+ input: defineSchemaModel3({
321
+ name: "AddCommentInput",
322
+ fields: {
323
+ requestId: {
324
+ type: ScalarTypeEnum3.String_unsecure(),
325
+ isOptional: false
326
+ },
327
+ content: { type: ScalarTypeEnum3.NonEmptyString(), isOptional: false },
328
+ isInternal: { type: ScalarTypeEnum3.Boolean(), isOptional: true }
329
+ }
330
+ }),
331
+ output: ApprovalCommentModel
332
+ },
333
+ policy: { auth: "user" },
334
+ sideEffects: {
335
+ emits: [
336
+ {
337
+ key: "workflow.approval.comment.added",
338
+ version: "1.0.0",
339
+ when: "Comment is added",
340
+ payload: ApprovalCommentModel
341
+ }
342
+ ]
343
+ },
344
+ acceptance: {
345
+ scenarios: [
346
+ {
347
+ key: "add-comment-happy-path",
348
+ given: ["Approval request exists"],
349
+ when: ["User adds a comment"],
350
+ then: ["Comment is added", "CommentAdded event is emitted"]
351
+ }
352
+ ],
353
+ examples: [
354
+ {
355
+ key: "add-question",
356
+ input: {
357
+ requestId: "req-123",
358
+ content: "Can you clarify budget?",
359
+ isInternal: false
360
+ },
361
+ output: { id: "com-789", content: "Can you clarify budget?" }
362
+ }
363
+ ]
364
+ }
365
+ });
366
+ var ListMyApprovalsContract = defineQuery({
367
+ meta: {
368
+ key: "workflow.approval.list.mine",
369
+ version: "1.0.0",
370
+ stability: "stable",
371
+ owners: [...OWNERS],
372
+ tags: ["workflow", "approval", "list", "inbox"],
373
+ description: "List approval requests assigned to current user.",
374
+ goal: "Show pending approvals in user inbox.",
375
+ context: "Approval inbox, dashboard widget."
376
+ },
377
+ io: {
378
+ input: defineSchemaModel3({
379
+ name: "ListMyApprovalsInput",
380
+ fields: {
381
+ status: { type: ApprovalStatusEnum, isOptional: true },
382
+ limit: {
383
+ type: ScalarTypeEnum3.Int_unsecure(),
384
+ isOptional: true,
385
+ defaultValue: 20
386
+ },
387
+ offset: {
388
+ type: ScalarTypeEnum3.Int_unsecure(),
389
+ isOptional: true,
390
+ defaultValue: 0
391
+ }
392
+ }
393
+ }),
394
+ output: defineSchemaModel3({
395
+ name: "ListMyApprovalsOutput",
396
+ fields: {
397
+ requests: {
398
+ type: ApprovalRequestModel,
399
+ isArray: true,
400
+ isOptional: false
401
+ },
402
+ total: { type: ScalarTypeEnum3.Int_unsecure(), isOptional: false },
403
+ pendingCount: {
404
+ type: ScalarTypeEnum3.Int_unsecure(),
405
+ isOptional: false
406
+ }
407
+ }
408
+ })
409
+ },
410
+ policy: { auth: "user" },
411
+ acceptance: {
412
+ scenarios: [
413
+ {
414
+ key: "list-approvals-happy-path",
415
+ given: ["User has assigned approvals"],
416
+ when: ["User lists approvals"],
417
+ then: ["List of requests is returned"]
418
+ }
419
+ ],
420
+ examples: [
421
+ {
422
+ key: "list-pending",
423
+ input: { status: "pending", limit: 10 },
424
+ output: { requests: [], total: 2, pendingCount: 2 }
425
+ }
426
+ ]
427
+ }
428
+ });
429
+ var GetApprovalContract = defineQuery({
430
+ meta: {
431
+ key: "workflow.approval.get",
432
+ version: "1.0.0",
433
+ stability: "stable",
434
+ owners: [...OWNERS],
435
+ tags: ["workflow", "approval", "get"],
436
+ description: "Get an approval request with details.",
437
+ goal: "View approval request details.",
438
+ context: "Approval detail view."
439
+ },
440
+ io: {
441
+ input: defineSchemaModel3({
442
+ name: "GetApprovalInput",
443
+ fields: {
444
+ requestId: {
445
+ type: ScalarTypeEnum3.String_unsecure(),
446
+ isOptional: false
447
+ }
448
+ }
449
+ }),
450
+ output: ApprovalRequestModel
451
+ },
452
+ policy: { auth: "user" },
453
+ acceptance: {
454
+ scenarios: [
455
+ {
456
+ key: "get-approval-happy-path",
457
+ given: ["Approval request exists"],
458
+ when: ["User requests approval details"],
459
+ then: ["Approval details are returned"]
460
+ }
461
+ ],
462
+ examples: [
463
+ {
464
+ key: "get-basic",
465
+ input: { requestId: "req-123" },
466
+ output: { id: "req-123", status: "pending" }
467
+ }
468
+ ]
469
+ }
470
+ });
471
+ export {
472
+ SubmitDecisionContract,
473
+ ListMyApprovalsContract,
474
+ GetApprovalContract,
475
+ DelegateApprovalContract,
476
+ ApprovalStatusEnum,
477
+ ApprovalRequestedEvent,
478
+ ApprovalRequestModel,
479
+ ApprovalEscalatedEvent,
480
+ ApprovalDelegatedEvent,
481
+ ApprovalDecisionEnum,
482
+ ApprovalDecidedEvent,
483
+ ApprovalCommentModel,
484
+ AddApprovalCommentContract
485
+ };
@@ -0,0 +1,22 @@
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
+ export {
20
+ ApprovalStatusEnum,
21
+ ApprovalDecisionEnum
22
+ };
@@ -0,0 +1,112 @@
1
+ // src/approval/approval.event.ts
2
+ import { defineEvent, defineSchemaModel } from "@contractspec/lib.contracts";
3
+ import { ScalarTypeEnum } from "@contractspec/lib.schema";
4
+ var ApprovalRequestedPayload = defineSchemaModel({
5
+ name: "ApprovalRequestedEventPayload",
6
+ description: "Payload when approval is requested",
7
+ fields: {
8
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
9
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
10
+ workflowKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
11
+ approverId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
12
+ approverRole: {
13
+ type: ScalarTypeEnum.String_unsecure(),
14
+ isOptional: true
15
+ },
16
+ title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
17
+ dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
18
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
19
+ }
20
+ });
21
+ var ApprovalDecidedPayload = defineSchemaModel({
22
+ name: "ApprovalDecidedEventPayload",
23
+ description: "Payload when approval decision is made",
24
+ fields: {
25
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
26
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
27
+ decision: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
28
+ decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
29
+ comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
30
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
31
+ }
32
+ });
33
+ var ApprovalDelegatedPayload = defineSchemaModel({
34
+ name: "ApprovalDelegatedEventPayload",
35
+ description: "Payload when approval is delegated",
36
+ fields: {
37
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
38
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
39
+ fromUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
40
+ toUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
41
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
42
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
43
+ }
44
+ });
45
+ var ApprovalEscalatedPayload = defineSchemaModel({
46
+ name: "ApprovalEscalatedEventPayload",
47
+ description: "Payload when approval is escalated",
48
+ fields: {
49
+ requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
50
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
51
+ escalationLevel: {
52
+ type: ScalarTypeEnum.Int_unsecure(),
53
+ isOptional: false
54
+ },
55
+ escalatedTo: {
56
+ type: ScalarTypeEnum.String_unsecure(),
57
+ isOptional: false
58
+ },
59
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
60
+ timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
61
+ }
62
+ });
63
+ var ApprovalRequestedEvent = defineEvent({
64
+ meta: {
65
+ key: "workflow.approval.requested",
66
+ version: "1.0.0",
67
+ description: "An approval has been requested.",
68
+ stability: "stable",
69
+ owners: ["@workflow-team"],
70
+ tags: ["workflow", "approval", "requested"]
71
+ },
72
+ payload: ApprovalRequestedPayload
73
+ });
74
+ var ApprovalDecidedEvent = defineEvent({
75
+ meta: {
76
+ key: "workflow.approval.decided",
77
+ version: "1.0.0",
78
+ description: "An approval decision has been made.",
79
+ stability: "stable",
80
+ owners: ["@workflow-team"],
81
+ tags: ["workflow", "approval", "decided"]
82
+ },
83
+ payload: ApprovalDecidedPayload
84
+ });
85
+ var ApprovalDelegatedEvent = defineEvent({
86
+ meta: {
87
+ key: "workflow.approval.delegated",
88
+ version: "1.0.0",
89
+ description: "An approval has been delegated.",
90
+ stability: "stable",
91
+ owners: ["@workflow-team"],
92
+ tags: ["workflow", "approval", "delegated"]
93
+ },
94
+ payload: ApprovalDelegatedPayload
95
+ });
96
+ var ApprovalEscalatedEvent = defineEvent({
97
+ meta: {
98
+ key: "workflow.approval.escalated",
99
+ version: "1.0.0",
100
+ description: "An approval has been escalated.",
101
+ stability: "stable",
102
+ owners: ["@workflow-team"],
103
+ tags: ["workflow", "approval", "escalated"]
104
+ },
105
+ payload: ApprovalEscalatedPayload
106
+ });
107
+ export {
108
+ ApprovalRequestedEvent,
109
+ ApprovalEscalatedEvent,
110
+ ApprovalDelegatedEvent,
111
+ ApprovalDecidedEvent
112
+ };