@contractspec/example.workflow-system 3.8.9 → 3.8.11

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 (95) hide show
  1. package/dist/approval/approval.enum.js +1 -22
  2. package/dist/approval/approval.event.js +1 -112
  3. package/dist/approval/approval.operations.js +1 -369
  4. package/dist/approval/approval.schema.js +1 -73
  5. package/dist/approval/index.js +1 -484
  6. package/dist/browser/approval/approval.enum.js +1 -22
  7. package/dist/browser/approval/approval.event.js +1 -112
  8. package/dist/browser/approval/approval.operations.js +1 -369
  9. package/dist/browser/approval/approval.schema.js +1 -73
  10. package/dist/browser/approval/index.js +1 -484
  11. package/dist/browser/docs/index.js +5 -49
  12. package/dist/browser/docs/workflow-system.docblock.js +5 -49
  13. package/dist/browser/entities/approval.js +1 -119
  14. package/dist/browser/entities/index.js +1 -508
  15. package/dist/browser/entities/instance.js +1 -161
  16. package/dist/browser/entities/step.js +1 -124
  17. package/dist/browser/entities/workflow.js +1 -82
  18. package/dist/browser/example.js +1 -42
  19. package/dist/browser/handlers/index.js +8 -253
  20. package/dist/browser/handlers/workflow.handlers.js +8 -253
  21. package/dist/browser/index.js +13 -3524
  22. package/dist/browser/instance/index.js +1 -677
  23. package/dist/browser/instance/instance.enum.js +1 -15
  24. package/dist/browser/instance/instance.event.js +1 -164
  25. package/dist/browser/instance/instance.handler.js +1 -356
  26. package/dist/browser/instance/instance.operations.js +1 -9
  27. package/dist/browser/instance/instance.schema.js +1 -101
  28. package/dist/browser/presentations/index.js +1 -109
  29. package/dist/browser/seeders/index.js +1 -3
  30. package/dist/browser/shared/demo-scenario.js +1 -213
  31. package/dist/browser/shared/index.js +1 -3
  32. package/dist/browser/shared/mock-data.js +1 -11
  33. package/dist/browser/state-machine/index.js +1 -6
  34. package/dist/browser/tests/operations.test-spec.js +1 -6
  35. package/dist/browser/ui/WorkflowDashboard.js +1 -3
  36. package/dist/browser/ui/WorkflowDashboard.visualizations.js +1 -239
  37. package/dist/browser/ui/hooks/index.js +1 -3
  38. package/dist/browser/ui/hooks/useWorkflowList.js +1 -52
  39. package/dist/browser/ui/index.js +1 -56
  40. package/dist/browser/ui/renderers/index.js +5 -562
  41. package/dist/browser/ui/renderers/workflow.markdown.js +5 -562
  42. package/dist/browser/visualizations/catalog.js +1 -132
  43. package/dist/browser/visualizations/index.js +1 -133
  44. package/dist/browser/visualizations/selectors.js +1 -195
  45. package/dist/browser/workflow/index.js +1 -21
  46. package/dist/browser/workflow/workflow.enum.js +1 -36
  47. package/dist/browser/workflow/workflow.event.js +1 -6
  48. package/dist/browser/workflow/workflow.handler.js +1 -5
  49. package/dist/browser/workflow/workflow.operations.js +1 -8
  50. package/dist/browser/workflow/workflow.schema.js +1 -151
  51. package/dist/browser/workflow-system.capability.js +1 -5
  52. package/dist/browser/workflow-system.feature.js +1 -3
  53. package/dist/docs/index.js +5 -49
  54. package/dist/docs/workflow-system.docblock.js +5 -49
  55. package/dist/entities/approval.js +1 -119
  56. package/dist/entities/index.js +1 -508
  57. package/dist/entities/instance.js +1 -161
  58. package/dist/entities/step.js +1 -124
  59. package/dist/entities/workflow.js +1 -82
  60. package/dist/example.js +1 -42
  61. package/dist/handlers/index.js +8 -253
  62. package/dist/handlers/workflow.handlers.js +8 -253
  63. package/dist/index.js +13 -3524
  64. package/dist/instance/index.js +1 -677
  65. package/dist/instance/instance.enum.js +1 -15
  66. package/dist/instance/instance.event.js +1 -164
  67. package/dist/instance/instance.handler.js +1 -356
  68. package/dist/instance/instance.operations.js +1 -9
  69. package/dist/instance/instance.schema.js +1 -101
  70. package/dist/presentations/index.js +1 -109
  71. package/dist/seeders/index.js +1 -3
  72. package/dist/shared/demo-scenario.js +1 -213
  73. package/dist/shared/index.js +1 -3
  74. package/dist/shared/mock-data.js +1 -11
  75. package/dist/state-machine/index.js +1 -6
  76. package/dist/tests/operations.test-spec.js +1 -6
  77. package/dist/ui/WorkflowDashboard.js +1 -3
  78. package/dist/ui/WorkflowDashboard.visualizations.js +1 -239
  79. package/dist/ui/hooks/index.js +1 -3
  80. package/dist/ui/hooks/useWorkflowList.js +1 -52
  81. package/dist/ui/index.js +1 -56
  82. package/dist/ui/renderers/index.js +5 -562
  83. package/dist/ui/renderers/workflow.markdown.js +5 -562
  84. package/dist/visualizations/catalog.js +1 -132
  85. package/dist/visualizations/index.js +1 -133
  86. package/dist/visualizations/selectors.js +1 -195
  87. package/dist/workflow/index.js +1 -21
  88. package/dist/workflow/workflow.enum.js +1 -36
  89. package/dist/workflow/workflow.event.js +1 -6
  90. package/dist/workflow/workflow.handler.js +1 -5
  91. package/dist/workflow/workflow.operations.js +1 -8
  92. package/dist/workflow/workflow.schema.js +1 -151
  93. package/dist/workflow-system.capability.js +1 -5
  94. package/dist/workflow-system.feature.js +1 -3
  95. package/package.json +8 -8
@@ -1,23 +1,2 @@
1
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
- export {
21
- ApprovalStatusEnum,
22
- ApprovalDecisionEnum
23
- };
2
+ import{defineEnum as g}from"@contractspec/lib.schema";var k=g("ApprovalStatus",["PENDING","APPROVED","REJECTED","DELEGATED","ESCALATED","WITHDRAWN","EXPIRED"]),q=g("ApprovalDecision",["APPROVE","REJECT","REQUEST_CHANGES","DELEGATE","ABSTAIN"]);export{k as ApprovalStatusEnum,q as ApprovalDecisionEnum};
@@ -1,113 +1,2 @@
1
1
  // @bun
2
- // src/approval/approval.event.ts
3
- import { defineEvent } from "@contractspec/lib.contracts-spec";
4
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
5
- var ApprovalRequestedPayload = defineSchemaModel({
6
- name: "ApprovalRequestedEventPayload",
7
- description: "Payload when approval is requested",
8
- fields: {
9
- requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
10
- instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
11
- workflowKey: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
12
- approverId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
13
- approverRole: {
14
- type: ScalarTypeEnum.String_unsecure(),
15
- isOptional: true
16
- },
17
- title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
18
- dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
19
- timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
20
- }
21
- });
22
- var ApprovalDecidedPayload = defineSchemaModel({
23
- name: "ApprovalDecidedEventPayload",
24
- description: "Payload when approval decision is made",
25
- fields: {
26
- requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
27
- instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
28
- decision: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
29
- decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
30
- comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
31
- timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
32
- }
33
- });
34
- var ApprovalDelegatedPayload = defineSchemaModel({
35
- name: "ApprovalDelegatedEventPayload",
36
- description: "Payload when approval is delegated",
37
- fields: {
38
- requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
39
- instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
40
- fromUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
41
- toUserId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
42
- reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
- timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
44
- }
45
- });
46
- var ApprovalEscalatedPayload = defineSchemaModel({
47
- name: "ApprovalEscalatedEventPayload",
48
- description: "Payload when approval is escalated",
49
- fields: {
50
- requestId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
51
- instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
52
- escalationLevel: {
53
- type: ScalarTypeEnum.Int_unsecure(),
54
- isOptional: false
55
- },
56
- escalatedTo: {
57
- type: ScalarTypeEnum.String_unsecure(),
58
- isOptional: false
59
- },
60
- reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
- timestamp: { type: ScalarTypeEnum.DateTime(), isOptional: false }
62
- }
63
- });
64
- var ApprovalRequestedEvent = defineEvent({
65
- meta: {
66
- key: "workflow.approval.requested",
67
- version: "1.0.0",
68
- description: "An approval has been requested.",
69
- stability: "stable",
70
- owners: ["@workflow-team"],
71
- tags: ["workflow", "approval", "requested"]
72
- },
73
- payload: ApprovalRequestedPayload
74
- });
75
- var ApprovalDecidedEvent = defineEvent({
76
- meta: {
77
- key: "workflow.approval.decided",
78
- version: "1.0.0",
79
- description: "An approval decision has been made.",
80
- stability: "stable",
81
- owners: ["@workflow-team"],
82
- tags: ["workflow", "approval", "decided"]
83
- },
84
- payload: ApprovalDecidedPayload
85
- });
86
- var ApprovalDelegatedEvent = defineEvent({
87
- meta: {
88
- key: "workflow.approval.delegated",
89
- version: "1.0.0",
90
- description: "An approval has been delegated.",
91
- stability: "stable",
92
- owners: ["@workflow-team"],
93
- tags: ["workflow", "approval", "delegated"]
94
- },
95
- payload: ApprovalDelegatedPayload
96
- });
97
- var ApprovalEscalatedEvent = defineEvent({
98
- meta: {
99
- key: "workflow.approval.escalated",
100
- version: "1.0.0",
101
- description: "An approval has been escalated.",
102
- stability: "stable",
103
- owners: ["@workflow-team"],
104
- tags: ["workflow", "approval", "escalated"]
105
- },
106
- payload: ApprovalEscalatedPayload
107
- });
108
- export {
109
- ApprovalRequestedEvent,
110
- ApprovalEscalatedEvent,
111
- ApprovalDelegatedEvent,
112
- ApprovalDecidedEvent
113
- };
2
+ import{defineEvent as k}from"@contractspec/lib.contracts-spec";import{defineSchemaModel as w,ScalarTypeEnum as j}from"@contractspec/lib.schema";var x=w({name:"ApprovalRequestedEventPayload",description:"Payload when approval is requested",fields:{requestId:{type:j.String_unsecure(),isOptional:!1},instanceId:{type:j.String_unsecure(),isOptional:!1},workflowKey:{type:j.String_unsecure(),isOptional:!1},approverId:{type:j.String_unsecure(),isOptional:!1},approverRole:{type:j.String_unsecure(),isOptional:!0},title:{type:j.String_unsecure(),isOptional:!1},dueAt:{type:j.DateTime(),isOptional:!0},timestamp:{type:j.DateTime(),isOptional:!1}}}),z=w({name:"ApprovalDecidedEventPayload",description:"Payload when approval decision is made",fields:{requestId:{type:j.String_unsecure(),isOptional:!1},instanceId:{type:j.String_unsecure(),isOptional:!1},decision:{type:j.String_unsecure(),isOptional:!1},decidedBy:{type:j.String_unsecure(),isOptional:!1},comment:{type:j.String_unsecure(),isOptional:!0},timestamp:{type:j.DateTime(),isOptional:!1}}}),B=w({name:"ApprovalDelegatedEventPayload",description:"Payload when approval is delegated",fields:{requestId:{type:j.String_unsecure(),isOptional:!1},instanceId:{type:j.String_unsecure(),isOptional:!1},fromUserId:{type:j.String_unsecure(),isOptional:!1},toUserId:{type:j.String_unsecure(),isOptional:!1},reason:{type:j.String_unsecure(),isOptional:!0},timestamp:{type:j.DateTime(),isOptional:!1}}}),C=w({name:"ApprovalEscalatedEventPayload",description:"Payload when approval is escalated",fields:{requestId:{type:j.String_unsecure(),isOptional:!1},instanceId:{type:j.String_unsecure(),isOptional:!1},escalationLevel:{type:j.Int_unsecure(),isOptional:!1},escalatedTo:{type:j.String_unsecure(),isOptional:!1},reason:{type:j.String_unsecure(),isOptional:!1},timestamp:{type:j.DateTime(),isOptional:!1}}}),H=k({meta:{key:"workflow.approval.requested",version:"1.0.0",description:"An approval has been requested.",stability:"stable",owners:["@workflow-team"],tags:["workflow","approval","requested"]},payload:x}),I=k({meta:{key:"workflow.approval.decided",version:"1.0.0",description:"An approval decision has been made.",stability:"stable",owners:["@workflow-team"],tags:["workflow","approval","decided"]},payload:z}),J=k({meta:{key:"workflow.approval.delegated",version:"1.0.0",description:"An approval has been delegated.",stability:"stable",owners:["@workflow-team"],tags:["workflow","approval","delegated"]},payload:B}),K=k({meta:{key:"workflow.approval.escalated",version:"1.0.0",description:"An approval has been escalated.",stability:"stable",owners:["@workflow-team"],tags:["workflow","approval","escalated"]},payload:C});export{H as ApprovalRequestedEvent,K as ApprovalEscalatedEvent,J as ApprovalDelegatedEvent,I as ApprovalDecidedEvent};
@@ -1,370 +1,2 @@
1
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.schema.ts
22
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
23
- var ApprovalRequestModel = defineSchemaModel({
24
- name: "ApprovalRequestModel",
25
- description: "An approval request",
26
- fields: {
27
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
28
- workflowInstanceId: {
29
- type: ScalarTypeEnum.String_unsecure(),
30
- isOptional: false
31
- },
32
- stepExecutionId: {
33
- type: ScalarTypeEnum.String_unsecure(),
34
- isOptional: false
35
- },
36
- approverId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
- approverRole: {
38
- type: ScalarTypeEnum.String_unsecure(),
39
- isOptional: true
40
- },
41
- title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
42
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
- status: { type: ApprovalStatusEnum, isOptional: false },
44
- decision: { type: ApprovalDecisionEnum, isOptional: true },
45
- decisionComment: {
46
- type: ScalarTypeEnum.String_unsecure(),
47
- isOptional: true
48
- },
49
- decidedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
50
- dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
51
- contextSnapshot: { type: ScalarTypeEnum.JSON(), isOptional: true },
52
- sequenceOrder: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
53
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
54
- }
55
- });
56
- var ApprovalCommentModel = defineSchemaModel({
57
- name: "ApprovalCommentModel",
58
- description: "A comment on an approval",
59
- fields: {
60
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
- approvalRequestId: {
62
- type: ScalarTypeEnum.String_unsecure(),
63
- isOptional: false
64
- },
65
- authorId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
66
- content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
67
- isInternal: { type: ScalarTypeEnum.Boolean(), isOptional: false },
68
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
69
- }
70
- });
71
-
72
- // src/approval/approval.operations.ts
73
- import {
74
- defineCommand,
75
- defineQuery
76
- } from "@contractspec/lib.contracts-spec/operations";
77
- import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
78
- var OWNERS = ["@example.workflow-system"];
79
- var SubmitDecisionContract = defineCommand({
80
- meta: {
81
- key: "workflow.approval.decide",
82
- version: "1.0.0",
83
- stability: "stable",
84
- owners: [...OWNERS],
85
- tags: ["workflow", "approval", "decision"],
86
- description: "Submit an approval decision (approve/reject).",
87
- goal: "Allow approvers to make decisions on requests.",
88
- context: "Approval inbox, workflow detail."
89
- },
90
- io: {
91
- input: defineSchemaModel2({
92
- name: "ApproveRejectInput",
93
- fields: {
94
- requestId: {
95
- type: ScalarTypeEnum2.String_unsecure(),
96
- isOptional: false
97
- },
98
- decision: { type: ApprovalDecisionEnum, isOptional: false },
99
- comment: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true },
100
- data: { type: ScalarTypeEnum2.JSON(), isOptional: true }
101
- }
102
- }),
103
- output: ApprovalRequestModel
104
- },
105
- policy: { auth: "user" },
106
- sideEffects: {
107
- emits: [
108
- {
109
- key: "workflow.approval.decided",
110
- version: "1.0.0",
111
- when: "Decision is made",
112
- payload: ApprovalRequestModel
113
- }
114
- ],
115
- audit: ["workflow.approval.decided"]
116
- },
117
- acceptance: {
118
- scenarios: [
119
- {
120
- key: "approve-request-happy-path",
121
- given: ["Approval request is pending", "User is assignee"],
122
- when: ["User approves request"],
123
- then: ["Request is approved", "ApprovalDecided event is emitted"]
124
- }
125
- ],
126
- examples: [
127
- {
128
- key: "approve-basic",
129
- input: {
130
- requestId: "req-123",
131
- decision: "approve",
132
- comment: "Looks good"
133
- },
134
- output: { id: "req-123", status: "approved" }
135
- }
136
- ]
137
- }
138
- });
139
- var DelegateApprovalContract = defineCommand({
140
- meta: {
141
- key: "workflow.approval.delegate",
142
- version: "1.0.0",
143
- stability: "stable",
144
- owners: [...OWNERS],
145
- tags: ["workflow", "approval", "delegate"],
146
- description: "Delegate an approval request to another user.",
147
- goal: "Allow approvers to pass approval to others.",
148
- context: "Approval inbox."
149
- },
150
- io: {
151
- input: defineSchemaModel2({
152
- name: "DelegateInput",
153
- fields: {
154
- requestId: {
155
- type: ScalarTypeEnum2.String_unsecure(),
156
- isOptional: false
157
- },
158
- delegateTo: {
159
- type: ScalarTypeEnum2.String_unsecure(),
160
- isOptional: false
161
- },
162
- reason: { type: ScalarTypeEnum2.String_unsecure(), isOptional: true }
163
- }
164
- }),
165
- output: ApprovalRequestModel
166
- },
167
- policy: { auth: "user" },
168
- sideEffects: {
169
- emits: [
170
- {
171
- key: "workflow.approval.delegated",
172
- version: "1.0.0",
173
- when: "Approval is delegated",
174
- payload: ApprovalRequestModel
175
- }
176
- ],
177
- audit: ["workflow.approval.delegated"]
178
- },
179
- acceptance: {
180
- scenarios: [
181
- {
182
- key: "delegate-approval-happy-path",
183
- given: ["Approval request is pending", "User is assignee"],
184
- when: ["User delegates to another user"],
185
- then: ["Assignee is updated", "ApprovalDelegated event is emitted"]
186
- }
187
- ],
188
- examples: [
189
- {
190
- key: "delegate-to-manager",
191
- input: {
192
- requestId: "req-123",
193
- delegateTo: "user-456",
194
- reason: "Out of office"
195
- },
196
- output: { id: "req-123", assigneeId: "user-456" }
197
- }
198
- ]
199
- }
200
- });
201
- var AddApprovalCommentContract = defineCommand({
202
- meta: {
203
- key: "workflow.approval.comment.add",
204
- version: "1.0.0",
205
- stability: "stable",
206
- owners: [...OWNERS],
207
- tags: ["workflow", "approval", "comment"],
208
- description: "Add a comment to an approval request.",
209
- goal: "Allow discussion on approval requests.",
210
- context: "Approval detail view."
211
- },
212
- io: {
213
- input: defineSchemaModel2({
214
- name: "AddCommentInput",
215
- fields: {
216
- requestId: {
217
- type: ScalarTypeEnum2.String_unsecure(),
218
- isOptional: false
219
- },
220
- content: { type: ScalarTypeEnum2.NonEmptyString(), isOptional: false },
221
- isInternal: { type: ScalarTypeEnum2.Boolean(), isOptional: true }
222
- }
223
- }),
224
- output: ApprovalCommentModel
225
- },
226
- policy: { auth: "user" },
227
- sideEffects: {
228
- emits: [
229
- {
230
- key: "workflow.approval.comment.added",
231
- version: "1.0.0",
232
- when: "Comment is added",
233
- payload: ApprovalCommentModel
234
- }
235
- ]
236
- },
237
- acceptance: {
238
- scenarios: [
239
- {
240
- key: "add-comment-happy-path",
241
- given: ["Approval request exists"],
242
- when: ["User adds a comment"],
243
- then: ["Comment is added", "CommentAdded event is emitted"]
244
- }
245
- ],
246
- examples: [
247
- {
248
- key: "add-question",
249
- input: {
250
- requestId: "req-123",
251
- content: "Can you clarify budget?",
252
- isInternal: false
253
- },
254
- output: { id: "com-789", content: "Can you clarify budget?" }
255
- }
256
- ]
257
- }
258
- });
259
- var ListMyApprovalsContract = defineQuery({
260
- meta: {
261
- key: "workflow.approval.list.mine",
262
- version: "1.0.0",
263
- stability: "stable",
264
- owners: [...OWNERS],
265
- tags: ["workflow", "approval", "list", "inbox"],
266
- description: "List approval requests assigned to current user.",
267
- goal: "Show pending approvals in user inbox.",
268
- context: "Approval inbox, dashboard widget."
269
- },
270
- io: {
271
- input: defineSchemaModel2({
272
- name: "ListMyApprovalsInput",
273
- fields: {
274
- status: { type: ApprovalStatusEnum, isOptional: true },
275
- limit: {
276
- type: ScalarTypeEnum2.Int_unsecure(),
277
- isOptional: true,
278
- defaultValue: 20
279
- },
280
- offset: {
281
- type: ScalarTypeEnum2.Int_unsecure(),
282
- isOptional: true,
283
- defaultValue: 0
284
- }
285
- }
286
- }),
287
- output: defineSchemaModel2({
288
- name: "ListMyApprovalsOutput",
289
- fields: {
290
- requests: {
291
- type: ApprovalRequestModel,
292
- isArray: true,
293
- isOptional: false
294
- },
295
- total: { type: ScalarTypeEnum2.Int_unsecure(), isOptional: false },
296
- pendingCount: {
297
- type: ScalarTypeEnum2.Int_unsecure(),
298
- isOptional: false
299
- }
300
- }
301
- })
302
- },
303
- policy: { auth: "user" },
304
- acceptance: {
305
- scenarios: [
306
- {
307
- key: "list-approvals-happy-path",
308
- given: ["User has assigned approvals"],
309
- when: ["User lists approvals"],
310
- then: ["List of requests is returned"]
311
- }
312
- ],
313
- examples: [
314
- {
315
- key: "list-pending",
316
- input: { status: "pending", limit: 10 },
317
- output: { requests: [], total: 2, pendingCount: 2 }
318
- }
319
- ]
320
- }
321
- });
322
- var GetApprovalContract = defineQuery({
323
- meta: {
324
- key: "workflow.approval.get",
325
- version: "1.0.0",
326
- stability: "stable",
327
- owners: [...OWNERS],
328
- tags: ["workflow", "approval", "get"],
329
- description: "Get an approval request with details.",
330
- goal: "View approval request details.",
331
- context: "Approval detail view."
332
- },
333
- io: {
334
- input: defineSchemaModel2({
335
- name: "GetApprovalInput",
336
- fields: {
337
- requestId: {
338
- type: ScalarTypeEnum2.String_unsecure(),
339
- isOptional: false
340
- }
341
- }
342
- }),
343
- output: ApprovalRequestModel
344
- },
345
- policy: { auth: "user" },
346
- acceptance: {
347
- scenarios: [
348
- {
349
- key: "get-approval-happy-path",
350
- given: ["Approval request exists"],
351
- when: ["User requests approval details"],
352
- then: ["Approval details are returned"]
353
- }
354
- ],
355
- examples: [
356
- {
357
- key: "get-basic",
358
- input: { requestId: "req-123" },
359
- output: { id: "req-123", status: "pending" }
360
- }
361
- ]
362
- }
363
- });
364
- export {
365
- SubmitDecisionContract,
366
- ListMyApprovalsContract,
367
- GetApprovalContract,
368
- DelegateApprovalContract,
369
- AddApprovalCommentContract
370
- };
2
+ import{defineEnum as H}from"@contractspec/lib.schema";var z=H("ApprovalStatus",["PENDING","APPROVED","REJECTED","DELEGATED","ESCALATED","WITHDRAWN","EXPIRED"]),B=H("ApprovalDecision",["APPROVE","REJECT","REQUEST_CHANGES","DELEGATE","ABSTAIN"]);import{defineSchemaModel as I,ScalarTypeEnum as g}from"@contractspec/lib.schema";var k=I({name:"ApprovalRequestModel",description:"An approval request",fields:{id:{type:g.String_unsecure(),isOptional:!1},workflowInstanceId:{type:g.String_unsecure(),isOptional:!1},stepExecutionId:{type:g.String_unsecure(),isOptional:!1},approverId:{type:g.String_unsecure(),isOptional:!1},approverRole:{type:g.String_unsecure(),isOptional:!0},title:{type:g.String_unsecure(),isOptional:!1},description:{type:g.String_unsecure(),isOptional:!0},status:{type:z,isOptional:!1},decision:{type:B,isOptional:!0},decisionComment:{type:g.String_unsecure(),isOptional:!0},decidedAt:{type:g.DateTime(),isOptional:!0},dueAt:{type:g.DateTime(),isOptional:!0},contextSnapshot:{type:g.JSON(),isOptional:!0},sequenceOrder:{type:g.Int_unsecure(),isOptional:!1},createdAt:{type:g.DateTime(),isOptional:!1}}}),F=I({name:"ApprovalCommentModel",description:"A comment on an approval",fields:{id:{type:g.String_unsecure(),isOptional:!1},approvalRequestId:{type:g.String_unsecure(),isOptional:!1},authorId:{type:g.String_unsecure(),isOptional:!1},content:{type:g.String_unsecure(),isOptional:!1},isInternal:{type:g.Boolean(),isOptional:!1},createdAt:{type:g.DateTime(),isOptional:!1}}});import{defineCommand as G,defineQuery as J}from"@contractspec/lib.contracts-spec/operations";import{defineSchemaModel as w,ScalarTypeEnum as j}from"@contractspec/lib.schema";var x=["@example.workflow-system"],$=G({meta:{key:"workflow.approval.decide",version:"1.0.0",stability:"stable",owners:[...x],tags:["workflow","approval","decision"],description:"Submit an approval decision (approve/reject).",goal:"Allow approvers to make decisions on requests.",context:"Approval inbox, workflow detail."},io:{input:w({name:"ApproveRejectInput",fields:{requestId:{type:j.String_unsecure(),isOptional:!1},decision:{type:B,isOptional:!1},comment:{type:j.String_unsecure(),isOptional:!0},data:{type:j.JSON(),isOptional:!0}}}),output:k},policy:{auth:"user"},sideEffects:{emits:[{key:"workflow.approval.decided",version:"1.0.0",when:"Decision is made",payload:k}],audit:["workflow.approval.decided"]},acceptance:{scenarios:[{key:"approve-request-happy-path",given:["Approval request is pending","User is assignee"],when:["User approves request"],then:["Request is approved","ApprovalDecided event is emitted"]}],examples:[{key:"approve-basic",input:{requestId:"req-123",decision:"approve",comment:"Looks good"},output:{id:"req-123",status:"approved"}}]}}),D=G({meta:{key:"workflow.approval.delegate",version:"1.0.0",stability:"stable",owners:[...x],tags:["workflow","approval","delegate"],description:"Delegate an approval request to another user.",goal:"Allow approvers to pass approval to others.",context:"Approval inbox."},io:{input:w({name:"DelegateInput",fields:{requestId:{type:j.String_unsecure(),isOptional:!1},delegateTo:{type:j.String_unsecure(),isOptional:!1},reason:{type:j.String_unsecure(),isOptional:!0}}}),output:k},policy:{auth:"user"},sideEffects:{emits:[{key:"workflow.approval.delegated",version:"1.0.0",when:"Approval is delegated",payload:k}],audit:["workflow.approval.delegated"]},acceptance:{scenarios:[{key:"delegate-approval-happy-path",given:["Approval request is pending","User is assignee"],when:["User delegates to another user"],then:["Assignee is updated","ApprovalDelegated event is emitted"]}],examples:[{key:"delegate-to-manager",input:{requestId:"req-123",delegateTo:"user-456",reason:"Out of office"},output:{id:"req-123",assigneeId:"user-456"}}]}}),Q=G({meta:{key:"workflow.approval.comment.add",version:"1.0.0",stability:"stable",owners:[...x],tags:["workflow","approval","comment"],description:"Add a comment to an approval request.",goal:"Allow discussion on approval requests.",context:"Approval detail view."},io:{input:w({name:"AddCommentInput",fields:{requestId:{type:j.String_unsecure(),isOptional:!1},content:{type:j.NonEmptyString(),isOptional:!1},isInternal:{type:j.Boolean(),isOptional:!0}}}),output:F},policy:{auth:"user"},sideEffects:{emits:[{key:"workflow.approval.comment.added",version:"1.0.0",when:"Comment is added",payload:F}]},acceptance:{scenarios:[{key:"add-comment-happy-path",given:["Approval request exists"],when:["User adds a comment"],then:["Comment is added","CommentAdded event is emitted"]}],examples:[{key:"add-question",input:{requestId:"req-123",content:"Can you clarify budget?",isInternal:!1},output:{id:"com-789",content:"Can you clarify budget?"}}]}}),b=J({meta:{key:"workflow.approval.list.mine",version:"1.0.0",stability:"stable",owners:[...x],tags:["workflow","approval","list","inbox"],description:"List approval requests assigned to current user.",goal:"Show pending approvals in user inbox.",context:"Approval inbox, dashboard widget."},io:{input:w({name:"ListMyApprovalsInput",fields:{status:{type:z,isOptional:!0},limit:{type:j.Int_unsecure(),isOptional:!0,defaultValue:20},offset:{type:j.Int_unsecure(),isOptional:!0,defaultValue:0}}}),output:w({name:"ListMyApprovalsOutput",fields:{requests:{type:k,isArray:!0,isOptional:!1},total:{type:j.Int_unsecure(),isOptional:!1},pendingCount:{type:j.Int_unsecure(),isOptional:!1}}})},policy:{auth:"user"},acceptance:{scenarios:[{key:"list-approvals-happy-path",given:["User has assigned approvals"],when:["User lists approvals"],then:["List of requests is returned"]}],examples:[{key:"list-pending",input:{status:"pending",limit:10},output:{requests:[],total:2,pendingCount:2}}]}}),C=J({meta:{key:"workflow.approval.get",version:"1.0.0",stability:"stable",owners:[...x],tags:["workflow","approval","get"],description:"Get an approval request with details.",goal:"View approval request details.",context:"Approval detail view."},io:{input:w({name:"GetApprovalInput",fields:{requestId:{type:j.String_unsecure(),isOptional:!1}}}),output:k},policy:{auth:"user"},acceptance:{scenarios:[{key:"get-approval-happy-path",given:["Approval request exists"],when:["User requests approval details"],then:["Approval details are returned"]}],examples:[{key:"get-basic",input:{requestId:"req-123"},output:{id:"req-123",status:"pending"}}]}});export{$ as SubmitDecisionContract,b as ListMyApprovalsContract,C as GetApprovalContract,D as DelegateApprovalContract,Q as AddApprovalCommentContract};
@@ -1,74 +1,2 @@
1
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.schema.ts
22
- import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
23
- var ApprovalRequestModel = defineSchemaModel({
24
- name: "ApprovalRequestModel",
25
- description: "An approval request",
26
- fields: {
27
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
28
- workflowInstanceId: {
29
- type: ScalarTypeEnum.String_unsecure(),
30
- isOptional: false
31
- },
32
- stepExecutionId: {
33
- type: ScalarTypeEnum.String_unsecure(),
34
- isOptional: false
35
- },
36
- approverId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
- approverRole: {
38
- type: ScalarTypeEnum.String_unsecure(),
39
- isOptional: true
40
- },
41
- title: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
42
- description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
43
- status: { type: ApprovalStatusEnum, isOptional: false },
44
- decision: { type: ApprovalDecisionEnum, isOptional: true },
45
- decisionComment: {
46
- type: ScalarTypeEnum.String_unsecure(),
47
- isOptional: true
48
- },
49
- decidedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
50
- dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
51
- contextSnapshot: { type: ScalarTypeEnum.JSON(), isOptional: true },
52
- sequenceOrder: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
53
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
54
- }
55
- });
56
- var ApprovalCommentModel = defineSchemaModel({
57
- name: "ApprovalCommentModel",
58
- description: "A comment on an approval",
59
- fields: {
60
- id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
- approvalRequestId: {
62
- type: ScalarTypeEnum.String_unsecure(),
63
- isOptional: false
64
- },
65
- authorId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
66
- content: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
67
- isInternal: { type: ScalarTypeEnum.Boolean(), isOptional: false },
68
- createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false }
69
- }
70
- });
71
- export {
72
- ApprovalRequestModel,
73
- ApprovalCommentModel
74
- };
2
+ import{defineEnum as j}from"@contractspec/lib.schema";var k=j("ApprovalStatus",["PENDING","APPROVED","REJECTED","DELEGATED","ESCALATED","WITHDRAWN","EXPIRED"]),q=j("ApprovalDecision",["APPROVE","REJECT","REQUEST_CHANGES","DELEGATE","ABSTAIN"]);import{defineSchemaModel as w,ScalarTypeEnum as g}from"@contractspec/lib.schema";var F=w({name:"ApprovalRequestModel",description:"An approval request",fields:{id:{type:g.String_unsecure(),isOptional:!1},workflowInstanceId:{type:g.String_unsecure(),isOptional:!1},stepExecutionId:{type:g.String_unsecure(),isOptional:!1},approverId:{type:g.String_unsecure(),isOptional:!1},approverRole:{type:g.String_unsecure(),isOptional:!0},title:{type:g.String_unsecure(),isOptional:!1},description:{type:g.String_unsecure(),isOptional:!0},status:{type:k,isOptional:!1},decision:{type:q,isOptional:!0},decisionComment:{type:g.String_unsecure(),isOptional:!0},decidedAt:{type:g.DateTime(),isOptional:!0},dueAt:{type:g.DateTime(),isOptional:!0},contextSnapshot:{type:g.JSON(),isOptional:!0},sequenceOrder:{type:g.Int_unsecure(),isOptional:!1},createdAt:{type:g.DateTime(),isOptional:!1}}}),G=w({name:"ApprovalCommentModel",description:"A comment on an approval",fields:{id:{type:g.String_unsecure(),isOptional:!1},approvalRequestId:{type:g.String_unsecure(),isOptional:!1},authorId:{type:g.String_unsecure(),isOptional:!1},content:{type:g.String_unsecure(),isOptional:!1},isInternal:{type:g.Boolean(),isOptional:!1},createdAt:{type:g.DateTime(),isOptional:!1}}});export{F as ApprovalRequestModel,G as ApprovalCommentModel};