@contractspec/example.workflow-system 3.8.9 → 3.8.10
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.
- package/dist/approval/approval.enum.js +1 -22
- package/dist/approval/approval.event.js +1 -112
- package/dist/approval/approval.operations.js +1 -369
- package/dist/approval/approval.schema.js +1 -73
- package/dist/approval/index.js +1 -484
- package/dist/browser/approval/approval.enum.js +1 -22
- package/dist/browser/approval/approval.event.js +1 -112
- package/dist/browser/approval/approval.operations.js +1 -369
- package/dist/browser/approval/approval.schema.js +1 -73
- package/dist/browser/approval/index.js +1 -484
- package/dist/browser/docs/index.js +5 -49
- package/dist/browser/docs/workflow-system.docblock.js +5 -49
- package/dist/browser/entities/approval.js +1 -119
- package/dist/browser/entities/index.js +1 -508
- package/dist/browser/entities/instance.js +1 -161
- package/dist/browser/entities/step.js +1 -124
- package/dist/browser/entities/workflow.js +1 -82
- package/dist/browser/example.js +1 -42
- package/dist/browser/handlers/index.js +8 -253
- package/dist/browser/handlers/workflow.handlers.js +8 -253
- package/dist/browser/index.js +13 -3524
- package/dist/browser/instance/index.js +1 -677
- package/dist/browser/instance/instance.enum.js +1 -15
- package/dist/browser/instance/instance.event.js +1 -164
- package/dist/browser/instance/instance.handler.js +1 -356
- package/dist/browser/instance/instance.operations.js +1 -9
- package/dist/browser/instance/instance.schema.js +1 -101
- package/dist/browser/presentations/index.js +1 -109
- package/dist/browser/seeders/index.js +1 -3
- package/dist/browser/shared/demo-scenario.js +1 -213
- package/dist/browser/shared/index.js +1 -3
- package/dist/browser/shared/mock-data.js +1 -11
- package/dist/browser/state-machine/index.js +1 -6
- package/dist/browser/tests/operations.test-spec.js +1 -6
- package/dist/browser/ui/WorkflowDashboard.js +1 -3
- package/dist/browser/ui/WorkflowDashboard.visualizations.js +1 -239
- package/dist/browser/ui/hooks/index.js +1 -3
- package/dist/browser/ui/hooks/useWorkflowList.js +1 -52
- package/dist/browser/ui/index.js +1 -56
- package/dist/browser/ui/renderers/index.js +5 -562
- package/dist/browser/ui/renderers/workflow.markdown.js +5 -562
- package/dist/browser/visualizations/catalog.js +1 -132
- package/dist/browser/visualizations/index.js +1 -133
- package/dist/browser/visualizations/selectors.js +1 -195
- package/dist/browser/workflow/index.js +1 -21
- package/dist/browser/workflow/workflow.enum.js +1 -36
- package/dist/browser/workflow/workflow.event.js +1 -6
- package/dist/browser/workflow/workflow.handler.js +1 -5
- package/dist/browser/workflow/workflow.operations.js +1 -8
- package/dist/browser/workflow/workflow.schema.js +1 -151
- package/dist/browser/workflow-system.capability.js +1 -5
- package/dist/browser/workflow-system.feature.js +1 -3
- package/dist/docs/index.js +5 -49
- package/dist/docs/workflow-system.docblock.js +5 -49
- package/dist/entities/approval.js +1 -119
- package/dist/entities/index.js +1 -508
- package/dist/entities/instance.js +1 -161
- package/dist/entities/step.js +1 -124
- package/dist/entities/workflow.js +1 -82
- package/dist/example.js +1 -42
- package/dist/handlers/index.js +8 -253
- package/dist/handlers/workflow.handlers.js +8 -253
- package/dist/index.js +13 -3524
- package/dist/instance/index.js +1 -677
- package/dist/instance/instance.enum.js +1 -15
- package/dist/instance/instance.event.js +1 -164
- package/dist/instance/instance.handler.js +1 -356
- package/dist/instance/instance.operations.js +1 -9
- package/dist/instance/instance.schema.js +1 -101
- package/dist/presentations/index.js +1 -109
- package/dist/seeders/index.js +1 -3
- package/dist/shared/demo-scenario.js +1 -213
- package/dist/shared/index.js +1 -3
- package/dist/shared/mock-data.js +1 -11
- package/dist/state-machine/index.js +1 -6
- package/dist/tests/operations.test-spec.js +1 -6
- package/dist/ui/WorkflowDashboard.js +1 -3
- package/dist/ui/WorkflowDashboard.visualizations.js +1 -239
- package/dist/ui/hooks/index.js +1 -3
- package/dist/ui/hooks/useWorkflowList.js +1 -52
- package/dist/ui/index.js +1 -56
- package/dist/ui/renderers/index.js +5 -562
- package/dist/ui/renderers/workflow.markdown.js +5 -562
- package/dist/visualizations/catalog.js +1 -132
- package/dist/visualizations/index.js +1 -133
- package/dist/visualizations/selectors.js +1 -195
- package/dist/workflow/index.js +1 -21
- package/dist/workflow/workflow.enum.js +1 -36
- package/dist/workflow/workflow.event.js +1 -6
- package/dist/workflow/workflow.handler.js +1 -5
- package/dist/workflow/workflow.operations.js +1 -8
- package/dist/workflow/workflow.schema.js +1 -151
- package/dist/workflow-system.capability.js +1 -5
- package/dist/workflow-system.feature.js +1 -3
- package/package.json +8 -8
|
@@ -1,151 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { defineEnum } from "@contractspec/lib.schema";
|
|
3
|
-
var WorkflowStatusEnum = defineEnum("WorkflowStatus", [
|
|
4
|
-
"DRAFT",
|
|
5
|
-
"ACTIVE",
|
|
6
|
-
"DEPRECATED",
|
|
7
|
-
"ARCHIVED"
|
|
8
|
-
]);
|
|
9
|
-
var TriggerTypeEnum = defineEnum("WorkflowTriggerType", [
|
|
10
|
-
"MANUAL",
|
|
11
|
-
"EVENT",
|
|
12
|
-
"SCHEDULED",
|
|
13
|
-
"API"
|
|
14
|
-
]);
|
|
15
|
-
var StepTypeEnum = defineEnum("StepType", [
|
|
16
|
-
"START",
|
|
17
|
-
"APPROVAL",
|
|
18
|
-
"TASK",
|
|
19
|
-
"CONDITION",
|
|
20
|
-
"PARALLEL",
|
|
21
|
-
"WAIT",
|
|
22
|
-
"ACTION",
|
|
23
|
-
"END"
|
|
24
|
-
]);
|
|
25
|
-
var ApprovalModeEnum = defineEnum("ApprovalMode", [
|
|
26
|
-
"ANY",
|
|
27
|
-
"ALL",
|
|
28
|
-
"MAJORITY",
|
|
29
|
-
"SEQUENTIAL"
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
// src/workflow/workflow.schema.ts
|
|
33
|
-
import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
|
|
34
|
-
var WorkflowStepModel = defineSchemaModel({
|
|
35
|
-
name: "WorkflowStepModel",
|
|
36
|
-
description: "A step in a workflow definition",
|
|
37
|
-
fields: {
|
|
38
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
39
|
-
key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
40
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
41
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
42
|
-
type: { type: StepTypeEnum, isOptional: false },
|
|
43
|
-
position: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
|
|
44
|
-
transitions: { type: ScalarTypeEnum.JSON(), isOptional: false },
|
|
45
|
-
approvalMode: { type: ApprovalModeEnum, isOptional: true },
|
|
46
|
-
approverRoles: {
|
|
47
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
48
|
-
isArray: true,
|
|
49
|
-
isOptional: true
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
var WorkflowDefinitionModel = defineSchemaModel({
|
|
54
|
-
name: "WorkflowDefinitionModel",
|
|
55
|
-
description: "A workflow definition",
|
|
56
|
-
fields: {
|
|
57
|
-
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
58
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
59
|
-
key: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
60
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
61
|
-
version: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
62
|
-
status: { type: WorkflowStatusEnum, isOptional: false },
|
|
63
|
-
triggerType: { type: TriggerTypeEnum, isOptional: false },
|
|
64
|
-
initialStepId: {
|
|
65
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
66
|
-
isOptional: true
|
|
67
|
-
},
|
|
68
|
-
featureFlagKey: {
|
|
69
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
70
|
-
isOptional: true
|
|
71
|
-
},
|
|
72
|
-
organizationId: {
|
|
73
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
74
|
-
isOptional: false
|
|
75
|
-
},
|
|
76
|
-
createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
77
|
-
updatedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
78
|
-
steps: { type: WorkflowStepModel, isArray: true, isOptional: true }
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
var CreateWorkflowInputModel = defineSchemaModel({
|
|
82
|
-
name: "CreateWorkflowInput",
|
|
83
|
-
description: "Input for creating a workflow definition",
|
|
84
|
-
fields: {
|
|
85
|
-
name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
86
|
-
key: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
87
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
88
|
-
triggerType: { type: TriggerTypeEnum, isOptional: true },
|
|
89
|
-
triggerConfig: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
90
|
-
featureFlagKey: {
|
|
91
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
92
|
-
isOptional: true
|
|
93
|
-
},
|
|
94
|
-
settings: { type: ScalarTypeEnum.JSON(), isOptional: true }
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
var UpdateWorkflowInputModel = defineSchemaModel({
|
|
98
|
-
name: "UpdateWorkflowInput",
|
|
99
|
-
description: "Input for updating a workflow definition",
|
|
100
|
-
fields: {
|
|
101
|
-
workflowId: {
|
|
102
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
103
|
-
isOptional: false
|
|
104
|
-
},
|
|
105
|
-
name: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
106
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
107
|
-
triggerType: { type: TriggerTypeEnum, isOptional: true },
|
|
108
|
-
triggerConfig: { type: ScalarTypeEnum.JSON(), isOptional: true },
|
|
109
|
-
featureFlagKey: {
|
|
110
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
111
|
-
isOptional: true
|
|
112
|
-
},
|
|
113
|
-
settings: { type: ScalarTypeEnum.JSON(), isOptional: true }
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
var AddStepInputModel = defineSchemaModel({
|
|
117
|
-
name: "AddStepInput",
|
|
118
|
-
description: "Input for adding a step to a workflow",
|
|
119
|
-
fields: {
|
|
120
|
-
workflowId: {
|
|
121
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
122
|
-
isOptional: false
|
|
123
|
-
},
|
|
124
|
-
key: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
125
|
-
name: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
|
|
126
|
-
description: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
127
|
-
type: { type: StepTypeEnum, isOptional: false },
|
|
128
|
-
position: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
129
|
-
transitions: { type: ScalarTypeEnum.JSON(), isOptional: false },
|
|
130
|
-
approvalMode: { type: ApprovalModeEnum, isOptional: true },
|
|
131
|
-
approverRoles: {
|
|
132
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
133
|
-
isArray: true,
|
|
134
|
-
isOptional: true
|
|
135
|
-
},
|
|
136
|
-
approverUserIds: {
|
|
137
|
-
type: ScalarTypeEnum.String_unsecure(),
|
|
138
|
-
isArray: true,
|
|
139
|
-
isOptional: true
|
|
140
|
-
},
|
|
141
|
-
timeoutSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
|
|
142
|
-
slaSeconds: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true }
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
export {
|
|
146
|
-
WorkflowStepModel,
|
|
147
|
-
WorkflowDefinitionModel,
|
|
148
|
-
UpdateWorkflowInputModel,
|
|
149
|
-
CreateWorkflowInputModel,
|
|
150
|
-
AddStepInputModel
|
|
151
|
-
};
|
|
1
|
+
import{defineEnum as x}from"@contractspec/lib.schema";var D=x("WorkflowStatus",["DRAFT","ACTIVE","DEPRECATED","ARCHIVED"]),z=x("WorkflowTriggerType",["MANUAL","EVENT","SCHEDULED","API"]),B=x("StepType",["START","APPROVAL","TASK","CONDITION","PARALLEL","WAIT","ACTION","END"]),C=x("ApprovalMode",["ANY","ALL","MAJORITY","SEQUENTIAL"]);import{defineSchemaModel as q,ScalarTypeEnum as j}from"@contractspec/lib.schema";var F=q({name:"WorkflowStepModel",description:"A step in a workflow definition",fields:{id:{type:j.String_unsecure(),isOptional:!1},key:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},type:{type:B,isOptional:!1},position:{type:j.Int_unsecure(),isOptional:!1},transitions:{type:j.JSON(),isOptional:!1},approvalMode:{type:C,isOptional:!0},approverRoles:{type:j.String_unsecure(),isArray:!0,isOptional:!0}}}),L=q({name:"WorkflowDefinitionModel",description:"A workflow definition",fields:{id:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!1},key:{type:j.String_unsecure(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},version:{type:j.String_unsecure(),isOptional:!1},status:{type:D,isOptional:!1},triggerType:{type:z,isOptional:!1},initialStepId:{type:j.String_unsecure(),isOptional:!0},featureFlagKey:{type:j.String_unsecure(),isOptional:!0},organizationId:{type:j.String_unsecure(),isOptional:!1},createdAt:{type:j.DateTime(),isOptional:!1},updatedAt:{type:j.DateTime(),isOptional:!1},steps:{type:F,isArray:!0,isOptional:!0}}}),N=q({name:"CreateWorkflowInput",description:"Input for creating a workflow definition",fields:{name:{type:j.NonEmptyString(),isOptional:!1},key:{type:j.NonEmptyString(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},triggerType:{type:z,isOptional:!0},triggerConfig:{type:j.JSON(),isOptional:!0},featureFlagKey:{type:j.String_unsecure(),isOptional:!0},settings:{type:j.JSON(),isOptional:!0}}}),O=q({name:"UpdateWorkflowInput",description:"Input for updating a workflow definition",fields:{workflowId:{type:j.String_unsecure(),isOptional:!1},name:{type:j.String_unsecure(),isOptional:!0},description:{type:j.String_unsecure(),isOptional:!0},triggerType:{type:z,isOptional:!0},triggerConfig:{type:j.JSON(),isOptional:!0},featureFlagKey:{type:j.String_unsecure(),isOptional:!0},settings:{type:j.JSON(),isOptional:!0}}}),P=q({name:"AddStepInput",description:"Input for adding a step to a workflow",fields:{workflowId:{type:j.String_unsecure(),isOptional:!1},key:{type:j.NonEmptyString(),isOptional:!1},name:{type:j.NonEmptyString(),isOptional:!1},description:{type:j.String_unsecure(),isOptional:!0},type:{type:B,isOptional:!1},position:{type:j.Int_unsecure(),isOptional:!0},transitions:{type:j.JSON(),isOptional:!1},approvalMode:{type:C,isOptional:!0},approverRoles:{type:j.String_unsecure(),isArray:!0,isOptional:!0},approverUserIds:{type:j.String_unsecure(),isArray:!0,isOptional:!0},timeoutSeconds:{type:j.Int_unsecure(),isOptional:!0},slaSeconds:{type:j.Int_unsecure(),isOptional:!0}}});export{F as WorkflowStepModel,L as WorkflowDefinitionModel,O as UpdateWorkflowInputModel,N as CreateWorkflowInputModel,P as AddStepInputModel};
|
package/dist/docs/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
|
|
4
|
-
var workflowSystemDocBlocks = [
|
|
5
|
-
{
|
|
6
|
-
id: "docs.examples.workflow-system",
|
|
7
|
-
title: "Workflow / Approval System",
|
|
8
|
-
summary: "Reference app showing state-machine driven approvals with RBAC, audit trail, notifications, and jobs.",
|
|
9
|
-
kind: "reference",
|
|
10
|
-
visibility: "public",
|
|
11
|
-
route: "/docs/examples/workflow-system",
|
|
12
|
-
tags: ["workflow", "approval", "state-machine", "rbac"],
|
|
13
|
-
body: `## Entities
|
|
2
|
+
import{registerDocBlocks as h}from"@contractspec/lib.contracts-spec/docs";var j=[{id:"docs.examples.workflow-system",title:"Workflow / Approval System",summary:"Reference app showing state-machine driven approvals with RBAC, audit trail, notifications, and jobs.",kind:"reference",visibility:"public",route:"/docs/examples/workflow-system",tags:["workflow","approval","state-machine","rbac"],body:`## Entities
|
|
14
3
|
|
|
15
4
|
- WorkflowDefinition, WorkflowStep, WorkflowInstance, Approval.
|
|
16
5
|
- State machine expressed in \`src/state-machine\` with allowed transitions and role gates.
|
|
@@ -34,17 +23,7 @@ var workflowSystemDocBlocks = [
|
|
|
34
23
|
|
|
35
24
|
- Keep transitions declarative to enable safe regeneration; role guards live in spec.
|
|
36
25
|
- Use Notification Center for approval requests and outcomes; attach files via Files module if needed.
|
|
37
|
-
`
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
id: "docs.examples.workflow-system.goal",
|
|
41
|
-
title: "Workflow System \u2014 Goal",
|
|
42
|
-
summary: "Why the workflow/approval template exists and outcomes it targets.",
|
|
43
|
-
kind: "goal",
|
|
44
|
-
visibility: "public",
|
|
45
|
-
route: "/docs/examples/workflow-system/goal",
|
|
46
|
-
tags: ["workflow", "goal"],
|
|
47
|
-
body: `## Why it matters
|
|
26
|
+
`},{id:"docs.examples.workflow-system.goal",title:"Workflow System \u2014 Goal",summary:"Why the workflow/approval template exists and outcomes it targets.",kind:"goal",visibility:"public",route:"/docs/examples/workflow-system/goal",tags:["workflow","goal"],body:`## Why it matters
|
|
48
27
|
- Provides a regenerable, role-gated approval engine using declarative state machines.
|
|
49
28
|
- Keeps workflow rules consistent across UI/API/events with auditability.
|
|
50
29
|
|
|
@@ -54,17 +33,7 @@ var workflowSystemDocBlocks = [
|
|
|
54
33
|
|
|
55
34
|
## Success criteria
|
|
56
35
|
- State changes are declarative and regenerate cleanly.
|
|
57
|
-
- Every transition emits auditable events and respects RBAC guards.`
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: "docs.examples.workflow-system.usage",
|
|
61
|
-
title: "Workflow System \u2014 Usage",
|
|
62
|
-
summary: "How to configure workflows, transitions, and regenerate safely.",
|
|
63
|
-
kind: "usage",
|
|
64
|
-
visibility: "public",
|
|
65
|
-
route: "/docs/examples/workflow-system/usage",
|
|
66
|
-
tags: ["workflow", "usage"],
|
|
67
|
-
body: `## Setup
|
|
36
|
+
- Every transition emits auditable events and respects RBAC guards.`},{id:"docs.examples.workflow-system.usage",title:"Workflow System \u2014 Usage",summary:"How to configure workflows, transitions, and regenerate safely.",kind:"usage",visibility:"public",route:"/docs/examples/workflow-system/usage",tags:["workflow","usage"],body:`## Setup
|
|
68
37
|
1) Define WorkflowDefinition steps and allowed transitions with role gates in spec.
|
|
69
38
|
2) Seed sample workflows/instances (if provided) or create via UI; enable reminders via Jobs.
|
|
70
39
|
|
|
@@ -76,17 +45,7 @@ var workflowSystemDocBlocks = [
|
|
|
76
45
|
## Guardrails
|
|
77
46
|
- Emit events for every transition; log to Audit Trail.
|
|
78
47
|
- Use Notifications for approvals/rejections; schedule reminders for pending steps.
|
|
79
|
-
- Keep transitions declarative; avoid imperative branching in handlers.`
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
id: "docs.examples.workflow-system.constraints",
|
|
83
|
-
title: "Workflow System \u2014 Constraints & Safety",
|
|
84
|
-
summary: "Internal guardrails for state machines, RBAC, and regeneration semantics.",
|
|
85
|
-
kind: "reference",
|
|
86
|
-
visibility: "internal",
|
|
87
|
-
route: "/docs/examples/workflow-system/constraints",
|
|
88
|
-
tags: ["workflow", "constraints", "internal"],
|
|
89
|
-
body: `## Constraints
|
|
48
|
+
- Keep transitions declarative; avoid imperative branching in handlers.`},{id:"docs.examples.workflow-system.constraints",title:"Workflow System \u2014 Constraints & Safety",summary:"Internal guardrails for state machines, RBAC, and regeneration semantics.",kind:"reference",visibility:"internal",route:"/docs/examples/workflow-system/constraints",tags:["workflow","constraints","internal"],body:`## Constraints
|
|
90
49
|
- State machine (steps/transitions) must stay declarative in spec; no hidden code paths.
|
|
91
50
|
- Events to emit: instance.started, step.completed/rejected, instance.finished.
|
|
92
51
|
- Regeneration must not change approval logic without explicit spec diff.
|
|
@@ -98,7 +57,4 @@ var workflowSystemDocBlocks = [
|
|
|
98
57
|
## Verification
|
|
99
58
|
- Add fixtures for transition changes and role gates.
|
|
100
59
|
- Validate reminders (Jobs) stay aligned with pending states after regeneration.
|
|
101
|
-
- Use Feature Flags for new transitions/escalation rules; default safe/off.`
|
|
102
|
-
}
|
|
103
|
-
];
|
|
104
|
-
registerDocBlocks(workflowSystemDocBlocks);
|
|
60
|
+
- Use Feature Flags for new transitions/escalation rules; default safe/off.`}];h(j);
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import { registerDocBlocks } from "@contractspec/lib.contracts-spec/docs";
|
|
4
|
-
var workflowSystemDocBlocks = [
|
|
5
|
-
{
|
|
6
|
-
id: "docs.examples.workflow-system",
|
|
7
|
-
title: "Workflow / Approval System",
|
|
8
|
-
summary: "Reference app showing state-machine driven approvals with RBAC, audit trail, notifications, and jobs.",
|
|
9
|
-
kind: "reference",
|
|
10
|
-
visibility: "public",
|
|
11
|
-
route: "/docs/examples/workflow-system",
|
|
12
|
-
tags: ["workflow", "approval", "state-machine", "rbac"],
|
|
13
|
-
body: `## Entities
|
|
2
|
+
import{registerDocBlocks as h}from"@contractspec/lib.contracts-spec/docs";var j=[{id:"docs.examples.workflow-system",title:"Workflow / Approval System",summary:"Reference app showing state-machine driven approvals with RBAC, audit trail, notifications, and jobs.",kind:"reference",visibility:"public",route:"/docs/examples/workflow-system",tags:["workflow","approval","state-machine","rbac"],body:`## Entities
|
|
14
3
|
|
|
15
4
|
- WorkflowDefinition, WorkflowStep, WorkflowInstance, Approval.
|
|
16
5
|
- State machine expressed in \`src/state-machine\` with allowed transitions and role gates.
|
|
@@ -34,17 +23,7 @@ var workflowSystemDocBlocks = [
|
|
|
34
23
|
|
|
35
24
|
- Keep transitions declarative to enable safe regeneration; role guards live in spec.
|
|
36
25
|
- Use Notification Center for approval requests and outcomes; attach files via Files module if needed.
|
|
37
|
-
`
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
id: "docs.examples.workflow-system.goal",
|
|
41
|
-
title: "Workflow System \u2014 Goal",
|
|
42
|
-
summary: "Why the workflow/approval template exists and outcomes it targets.",
|
|
43
|
-
kind: "goal",
|
|
44
|
-
visibility: "public",
|
|
45
|
-
route: "/docs/examples/workflow-system/goal",
|
|
46
|
-
tags: ["workflow", "goal"],
|
|
47
|
-
body: `## Why it matters
|
|
26
|
+
`},{id:"docs.examples.workflow-system.goal",title:"Workflow System \u2014 Goal",summary:"Why the workflow/approval template exists and outcomes it targets.",kind:"goal",visibility:"public",route:"/docs/examples/workflow-system/goal",tags:["workflow","goal"],body:`## Why it matters
|
|
48
27
|
- Provides a regenerable, role-gated approval engine using declarative state machines.
|
|
49
28
|
- Keeps workflow rules consistent across UI/API/events with auditability.
|
|
50
29
|
|
|
@@ -54,17 +33,7 @@ var workflowSystemDocBlocks = [
|
|
|
54
33
|
|
|
55
34
|
## Success criteria
|
|
56
35
|
- State changes are declarative and regenerate cleanly.
|
|
57
|
-
- Every transition emits auditable events and respects RBAC guards.`
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
id: "docs.examples.workflow-system.usage",
|
|
61
|
-
title: "Workflow System \u2014 Usage",
|
|
62
|
-
summary: "How to configure workflows, transitions, and regenerate safely.",
|
|
63
|
-
kind: "usage",
|
|
64
|
-
visibility: "public",
|
|
65
|
-
route: "/docs/examples/workflow-system/usage",
|
|
66
|
-
tags: ["workflow", "usage"],
|
|
67
|
-
body: `## Setup
|
|
36
|
+
- Every transition emits auditable events and respects RBAC guards.`},{id:"docs.examples.workflow-system.usage",title:"Workflow System \u2014 Usage",summary:"How to configure workflows, transitions, and regenerate safely.",kind:"usage",visibility:"public",route:"/docs/examples/workflow-system/usage",tags:["workflow","usage"],body:`## Setup
|
|
68
37
|
1) Define WorkflowDefinition steps and allowed transitions with role gates in spec.
|
|
69
38
|
2) Seed sample workflows/instances (if provided) or create via UI; enable reminders via Jobs.
|
|
70
39
|
|
|
@@ -76,17 +45,7 @@ var workflowSystemDocBlocks = [
|
|
|
76
45
|
## Guardrails
|
|
77
46
|
- Emit events for every transition; log to Audit Trail.
|
|
78
47
|
- Use Notifications for approvals/rejections; schedule reminders for pending steps.
|
|
79
|
-
- Keep transitions declarative; avoid imperative branching in handlers.`
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
id: "docs.examples.workflow-system.constraints",
|
|
83
|
-
title: "Workflow System \u2014 Constraints & Safety",
|
|
84
|
-
summary: "Internal guardrails for state machines, RBAC, and regeneration semantics.",
|
|
85
|
-
kind: "reference",
|
|
86
|
-
visibility: "internal",
|
|
87
|
-
route: "/docs/examples/workflow-system/constraints",
|
|
88
|
-
tags: ["workflow", "constraints", "internal"],
|
|
89
|
-
body: `## Constraints
|
|
48
|
+
- Keep transitions declarative; avoid imperative branching in handlers.`},{id:"docs.examples.workflow-system.constraints",title:"Workflow System \u2014 Constraints & Safety",summary:"Internal guardrails for state machines, RBAC, and regeneration semantics.",kind:"reference",visibility:"internal",route:"/docs/examples/workflow-system/constraints",tags:["workflow","constraints","internal"],body:`## Constraints
|
|
90
49
|
- State machine (steps/transitions) must stay declarative in spec; no hidden code paths.
|
|
91
50
|
- Events to emit: instance.started, step.completed/rejected, instance.finished.
|
|
92
51
|
- Regeneration must not change approval logic without explicit spec diff.
|
|
@@ -98,7 +57,4 @@ var workflowSystemDocBlocks = [
|
|
|
98
57
|
## Verification
|
|
99
58
|
- Add fixtures for transition changes and role gates.
|
|
100
59
|
- Validate reminders (Jobs) stay aligned with pending states after regeneration.
|
|
101
|
-
- Use Feature Flags for new transitions/escalation rules; default safe/off.`
|
|
102
|
-
}
|
|
103
|
-
];
|
|
104
|
-
registerDocBlocks(workflowSystemDocBlocks);
|
|
60
|
+
- Use Feature Flags for new transitions/escalation rules; default safe/off.`}];h(j);
|
|
@@ -1,120 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
defineEntity,
|
|
5
|
-
defineEntityEnum,
|
|
6
|
-
field,
|
|
7
|
-
index
|
|
8
|
-
} from "@contractspec/lib.schema";
|
|
9
|
-
var ApprovalStatusEnum = defineEntityEnum({
|
|
10
|
-
name: "ApprovalStatus",
|
|
11
|
-
values: [
|
|
12
|
-
"PENDING",
|
|
13
|
-
"APPROVED",
|
|
14
|
-
"REJECTED",
|
|
15
|
-
"DELEGATED",
|
|
16
|
-
"ESCALATED",
|
|
17
|
-
"WITHDRAWN",
|
|
18
|
-
"EXPIRED"
|
|
19
|
-
],
|
|
20
|
-
schema: "workflow",
|
|
21
|
-
description: "Status of an approval request."
|
|
22
|
-
});
|
|
23
|
-
var ApprovalDecisionEnum = defineEntityEnum({
|
|
24
|
-
name: "ApprovalDecision",
|
|
25
|
-
values: [
|
|
26
|
-
"APPROVE",
|
|
27
|
-
"REJECT",
|
|
28
|
-
"REQUEST_CHANGES",
|
|
29
|
-
"DELEGATE",
|
|
30
|
-
"ABSTAIN"
|
|
31
|
-
],
|
|
32
|
-
schema: "workflow",
|
|
33
|
-
description: "Possible approval decisions."
|
|
34
|
-
});
|
|
35
|
-
var ApprovalRequestEntity = defineEntity({
|
|
36
|
-
name: "ApprovalRequest",
|
|
37
|
-
description: "A pending approval request for a workflow step.",
|
|
38
|
-
schema: "workflow",
|
|
39
|
-
map: "approval_request",
|
|
40
|
-
fields: {
|
|
41
|
-
id: field.id({ description: "Unique approval request ID" }),
|
|
42
|
-
workflowInstanceId: field.foreignKey(),
|
|
43
|
-
stepExecutionId: field.foreignKey(),
|
|
44
|
-
approverId: field.foreignKey({ description: "User requested to approve" }),
|
|
45
|
-
approverRole: field.string({
|
|
46
|
-
isOptional: true,
|
|
47
|
-
description: "Role of the approver"
|
|
48
|
-
}),
|
|
49
|
-
title: field.string({ description: "Approval request title" }),
|
|
50
|
-
description: field.string({ isOptional: true }),
|
|
51
|
-
status: field.enum("ApprovalStatus", { default: "PENDING" }),
|
|
52
|
-
decision: field.enum("ApprovalDecision", { isOptional: true }),
|
|
53
|
-
decisionComment: field.string({
|
|
54
|
-
isOptional: true,
|
|
55
|
-
description: "Comment explaining decision"
|
|
56
|
-
}),
|
|
57
|
-
decidedAt: field.dateTime({ isOptional: true }),
|
|
58
|
-
delegatedTo: field.string({
|
|
59
|
-
isOptional: true,
|
|
60
|
-
description: "User delegated to"
|
|
61
|
-
}),
|
|
62
|
-
delegationReason: field.string({ isOptional: true }),
|
|
63
|
-
escalationLevel: field.int({
|
|
64
|
-
default: 0,
|
|
65
|
-
description: "Current escalation level"
|
|
66
|
-
}),
|
|
67
|
-
escalatedAt: field.dateTime({ isOptional: true }),
|
|
68
|
-
dueAt: field.dateTime({
|
|
69
|
-
isOptional: true,
|
|
70
|
-
description: "When approval is due"
|
|
71
|
-
}),
|
|
72
|
-
reminderSentAt: field.dateTime({ isOptional: true }),
|
|
73
|
-
contextSnapshot: field.json({
|
|
74
|
-
isOptional: true,
|
|
75
|
-
description: "Snapshot of relevant data for review"
|
|
76
|
-
}),
|
|
77
|
-
sequenceOrder: field.int({
|
|
78
|
-
default: 0,
|
|
79
|
-
description: "Order in approval chain"
|
|
80
|
-
}),
|
|
81
|
-
createdAt: field.createdAt(),
|
|
82
|
-
updatedAt: field.updatedAt(),
|
|
83
|
-
workflowInstance: field.belongsTo("WorkflowInstance", ["workflowInstanceId"], ["id"], { onDelete: "Cascade" }),
|
|
84
|
-
stepExecution: field.belongsTo("StepExecution", ["stepExecutionId"], ["id"])
|
|
85
|
-
},
|
|
86
|
-
indexes: [
|
|
87
|
-
index.on(["approverId", "status"]),
|
|
88
|
-
index.on(["workflowInstanceId", "status"]),
|
|
89
|
-
index.on(["stepExecutionId"]),
|
|
90
|
-
index.on(["status", "dueAt"]),
|
|
91
|
-
index.on(["createdAt"])
|
|
92
|
-
],
|
|
93
|
-
enums: [ApprovalStatusEnum, ApprovalDecisionEnum]
|
|
94
|
-
});
|
|
95
|
-
var ApprovalCommentEntity = defineEntity({
|
|
96
|
-
name: "ApprovalComment",
|
|
97
|
-
description: "A comment on an approval request.",
|
|
98
|
-
schema: "workflow",
|
|
99
|
-
map: "approval_comment",
|
|
100
|
-
fields: {
|
|
101
|
-
id: field.id(),
|
|
102
|
-
approvalRequestId: field.foreignKey(),
|
|
103
|
-
authorId: field.foreignKey(),
|
|
104
|
-
content: field.string({ description: "Comment text" }),
|
|
105
|
-
isInternal: field.boolean({
|
|
106
|
-
default: false,
|
|
107
|
-
description: "Internal note vs public comment"
|
|
108
|
-
}),
|
|
109
|
-
createdAt: field.createdAt(),
|
|
110
|
-
updatedAt: field.updatedAt(),
|
|
111
|
-
approvalRequest: field.belongsTo("ApprovalRequest", ["approvalRequestId"], ["id"], { onDelete: "Cascade" })
|
|
112
|
-
},
|
|
113
|
-
indexes: [index.on(["approvalRequestId", "createdAt"])]
|
|
114
|
-
});
|
|
115
|
-
export {
|
|
116
|
-
ApprovalStatusEnum,
|
|
117
|
-
ApprovalRequestEntity,
|
|
118
|
-
ApprovalDecisionEnum,
|
|
119
|
-
ApprovalCommentEntity
|
|
120
|
-
};
|
|
2
|
+
import{defineEntity as k,defineEntityEnum as w,field as g,index as j}from"@contractspec/lib.schema";var z=w({name:"ApprovalStatus",values:["PENDING","APPROVED","REJECTED","DELEGATED","ESCALATED","WITHDRAWN","EXPIRED"],schema:"workflow",description:"Status of an approval request."}),B=w({name:"ApprovalDecision",values:["APPROVE","REJECT","REQUEST_CHANGES","DELEGATE","ABSTAIN"],schema:"workflow",description:"Possible approval decisions."}),G=k({name:"ApprovalRequest",description:"A pending approval request for a workflow step.",schema:"workflow",map:"approval_request",fields:{id:g.id({description:"Unique approval request ID"}),workflowInstanceId:g.foreignKey(),stepExecutionId:g.foreignKey(),approverId:g.foreignKey({description:"User requested to approve"}),approverRole:g.string({isOptional:!0,description:"Role of the approver"}),title:g.string({description:"Approval request title"}),description:g.string({isOptional:!0}),status:g.enum("ApprovalStatus",{default:"PENDING"}),decision:g.enum("ApprovalDecision",{isOptional:!0}),decisionComment:g.string({isOptional:!0,description:"Comment explaining decision"}),decidedAt:g.dateTime({isOptional:!0}),delegatedTo:g.string({isOptional:!0,description:"User delegated to"}),delegationReason:g.string({isOptional:!0}),escalationLevel:g.int({default:0,description:"Current escalation level"}),escalatedAt:g.dateTime({isOptional:!0}),dueAt:g.dateTime({isOptional:!0,description:"When approval is due"}),reminderSentAt:g.dateTime({isOptional:!0}),contextSnapshot:g.json({isOptional:!0,description:"Snapshot of relevant data for review"}),sequenceOrder:g.int({default:0,description:"Order in approval chain"}),createdAt:g.createdAt(),updatedAt:g.updatedAt(),workflowInstance:g.belongsTo("WorkflowInstance",["workflowInstanceId"],["id"],{onDelete:"Cascade"}),stepExecution:g.belongsTo("StepExecution",["stepExecutionId"],["id"])},indexes:[j.on(["approverId","status"]),j.on(["workflowInstanceId","status"]),j.on(["stepExecutionId"]),j.on(["status","dueAt"]),j.on(["createdAt"])],enums:[z,B]}),H=k({name:"ApprovalComment",description:"A comment on an approval request.",schema:"workflow",map:"approval_comment",fields:{id:g.id(),approvalRequestId:g.foreignKey(),authorId:g.foreignKey(),content:g.string({description:"Comment text"}),isInternal:g.boolean({default:!1,description:"Internal note vs public comment"}),createdAt:g.createdAt(),updatedAt:g.updatedAt(),approvalRequest:g.belongsTo("ApprovalRequest",["approvalRequestId"],["id"],{onDelete:"Cascade"})},indexes:[j.on(["approvalRequestId","createdAt"])]});export{z as ApprovalStatusEnum,G as ApprovalRequestEntity,B as ApprovalDecisionEnum,H as ApprovalCommentEntity};
|