@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
@@ -0,0 +1,109 @@
1
+ // src/instance/instance.enum.ts
2
+ import { defineEnum } from "@contractspec/lib.schema";
3
+ var InstanceStatusEnum = defineEnum("InstanceStatus", [
4
+ "PENDING",
5
+ "RUNNING",
6
+ "WAITING",
7
+ "PAUSED",
8
+ "COMPLETED",
9
+ "CANCELLED",
10
+ "FAILED",
11
+ "TIMEOUT"
12
+ ]);
13
+
14
+ // src/instance/instance.schema.ts
15
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
16
+ var WorkflowInstanceModel = defineSchemaModel({
17
+ name: "WorkflowInstanceModel",
18
+ description: "A running workflow instance",
19
+ fields: {
20
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
21
+ workflowDefinitionId: {
22
+ type: ScalarTypeEnum.String_unsecure(),
23
+ isOptional: false
24
+ },
25
+ referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
26
+ referenceType: {
27
+ type: ScalarTypeEnum.String_unsecure(),
28
+ isOptional: true
29
+ },
30
+ status: { type: InstanceStatusEnum, isOptional: false },
31
+ currentStepId: {
32
+ type: ScalarTypeEnum.String_unsecure(),
33
+ isOptional: true
34
+ },
35
+ contextData: { type: ScalarTypeEnum.JSON(), isOptional: true },
36
+ triggeredBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
+ organizationId: {
38
+ type: ScalarTypeEnum.String_unsecure(),
39
+ isOptional: false
40
+ },
41
+ priority: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
42
+ dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
43
+ outcome: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
44
+ resultData: { type: ScalarTypeEnum.JSON(), isOptional: true },
45
+ errorMessage: {
46
+ type: ScalarTypeEnum.String_unsecure(),
47
+ isOptional: true
48
+ },
49
+ createdAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
50
+ startedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
51
+ completedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
52
+ }
53
+ });
54
+ var StartWorkflowInputModel = defineSchemaModel({
55
+ name: "StartWorkflowInput",
56
+ description: "Input for starting a workflow",
57
+ fields: {
58
+ workflowKey: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
59
+ contextData: { type: ScalarTypeEnum.JSON(), isOptional: true },
60
+ referenceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
61
+ referenceType: {
62
+ type: ScalarTypeEnum.String_unsecure(),
63
+ isOptional: true
64
+ },
65
+ priority: { type: ScalarTypeEnum.Int_unsecure(), isOptional: true },
66
+ dueAt: { type: ScalarTypeEnum.DateTime(), isOptional: true }
67
+ }
68
+ });
69
+ var TransitionInputModel = defineSchemaModel({
70
+ name: "TransitionInput",
71
+ description: "Input for transitioning a workflow",
72
+ fields: {
73
+ instanceId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
74
+ action: { type: ScalarTypeEnum.NonEmptyString(), isOptional: false },
75
+ data: { type: ScalarTypeEnum.JSON(), isOptional: true },
76
+ comment: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
77
+ }
78
+ });
79
+ var TransitionResultModel = defineSchemaModel({
80
+ name: "TransitionResult",
81
+ description: "Result of a workflow transition",
82
+ fields: {
83
+ success: { type: ScalarTypeEnum.Boolean(), isOptional: false },
84
+ instance: { type: WorkflowInstanceModel, isOptional: false },
85
+ previousStepKey: {
86
+ type: ScalarTypeEnum.String_unsecure(),
87
+ isOptional: true
88
+ },
89
+ currentStepKey: {
90
+ type: ScalarTypeEnum.String_unsecure(),
91
+ isOptional: true
92
+ },
93
+ message: { type: ScalarTypeEnum.String_unsecure(), isOptional: true }
94
+ }
95
+ });
96
+ export {
97
+ WorkflowSystemPresentations,
98
+ WorkflowMetricsPresentation,
99
+ WorkflowListPresentation,
100
+ WorkflowDetailPresentation,
101
+ WorkflowDesignerPresentation,
102
+ ProgressTrackerPresentation,
103
+ PendingApprovalsBadgePresentation,
104
+ InstanceListPresentation,
105
+ InstanceDetailPresentation,
106
+ ApprovalInboxPresentation,
107
+ ApprovalFormPresentation,
108
+ ApprovalDetailPresentation
109
+ };
@@ -0,0 +1,3 @@
1
+ export {
2
+ seedWorkflowSystem
3
+ };
@@ -0,0 +1,3 @@
1
+ export {
2
+ mockDataStore
3
+ };
@@ -0,0 +1,11 @@
1
+ // src/shared/mock-data.ts
2
+ var mockDataStore = {
3
+ workflows: new Map,
4
+ steps: new Map,
5
+ instances: new Map,
6
+ approvals: new Map,
7
+ stepExecutions: new Map
8
+ };
9
+ export {
10
+ mockDataStore
11
+ };
File without changes
@@ -0,0 +1,6 @@
1
+ export {
2
+ createStateMachineEngine,
3
+ createInitialState,
4
+ buildStateMachineDefinition,
5
+ BasicStateMachineEngine
6
+ };
@@ -0,0 +1,6 @@
1
+ export {
2
+ InstanceListTest,
3
+ DefinitionListTest,
4
+ ApprovalListMineTest,
5
+ ApprovalDecideTest
6
+ };
@@ -0,0 +1,3 @@
1
+ export {
2
+ WorkflowDashboard
3
+ };
@@ -0,0 +1,50 @@
1
+ // src/ui/hooks/useWorkflowList.ts
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ "use client";
5
+ function useWorkflowList(projectId = "local-project") {
6
+ const { handlers } = useTemplateRuntime();
7
+ const workflow = handlers.workflow;
8
+ const [definitions, setDefinitions] = useState([]);
9
+ const [instances, setInstances] = useState([]);
10
+ const [loading, setLoading] = useState(true);
11
+ const [error, setError] = useState(null);
12
+ const fetchData = useCallback(async () => {
13
+ try {
14
+ setLoading(true);
15
+ setError(null);
16
+ const [defResult, instResult] = await Promise.all([
17
+ workflow.listDefinitions({ projectId, limit: 100 }),
18
+ workflow.listInstances({ projectId, limit: 100 })
19
+ ]);
20
+ setDefinitions(defResult.definitions);
21
+ setInstances(instResult.instances);
22
+ } catch (err) {
23
+ setError(err instanceof Error ? err : new Error("Failed to load workflows"));
24
+ } finally {
25
+ setLoading(false);
26
+ }
27
+ }, [handlers, projectId]);
28
+ useEffect(() => {
29
+ fetchData();
30
+ }, [fetchData]);
31
+ const stats = {
32
+ totalDefinitions: definitions.length,
33
+ activeDefinitions: definitions.filter((d) => d.status === "ACTIVE").length,
34
+ totalInstances: instances.length,
35
+ pendingInstances: instances.filter((i) => i.status === "PENDING").length,
36
+ completedInstances: instances.filter((i) => i.status === "COMPLETED").length,
37
+ rejectedInstances: instances.filter((i) => i.status === "REJECTED").length
38
+ };
39
+ return {
40
+ definitions,
41
+ instances,
42
+ loading,
43
+ error,
44
+ stats,
45
+ refetch: fetchData
46
+ };
47
+ }
48
+ export {
49
+ useWorkflowList
50
+ };
@@ -0,0 +1,50 @@
1
+ // src/ui/hooks/useWorkflowList.ts
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ "use client";
5
+ function useWorkflowList(projectId = "local-project") {
6
+ const { handlers } = useTemplateRuntime();
7
+ const workflow = handlers.workflow;
8
+ const [definitions, setDefinitions] = useState([]);
9
+ const [instances, setInstances] = useState([]);
10
+ const [loading, setLoading] = useState(true);
11
+ const [error, setError] = useState(null);
12
+ const fetchData = useCallback(async () => {
13
+ try {
14
+ setLoading(true);
15
+ setError(null);
16
+ const [defResult, instResult] = await Promise.all([
17
+ workflow.listDefinitions({ projectId, limit: 100 }),
18
+ workflow.listInstances({ projectId, limit: 100 })
19
+ ]);
20
+ setDefinitions(defResult.definitions);
21
+ setInstances(instResult.instances);
22
+ } catch (err) {
23
+ setError(err instanceof Error ? err : new Error("Failed to load workflows"));
24
+ } finally {
25
+ setLoading(false);
26
+ }
27
+ }, [handlers, projectId]);
28
+ useEffect(() => {
29
+ fetchData();
30
+ }, [fetchData]);
31
+ const stats = {
32
+ totalDefinitions: definitions.length,
33
+ activeDefinitions: definitions.filter((d) => d.status === "ACTIVE").length,
34
+ totalInstances: instances.length,
35
+ pendingInstances: instances.filter((i) => i.status === "PENDING").length,
36
+ completedInstances: instances.filter((i) => i.status === "COMPLETED").length,
37
+ rejectedInstances: instances.filter((i) => i.status === "REJECTED").length
38
+ };
39
+ return {
40
+ definitions,
41
+ instances,
42
+ loading,
43
+ error,
44
+ stats,
45
+ refetch: fetchData
46
+ };
47
+ }
48
+ export {
49
+ useWorkflowList
50
+ };
@@ -0,0 +1,54 @@
1
+ // src/ui/hooks/useWorkflowList.ts
2
+ import { useCallback, useEffect, useState } from "react";
3
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
4
+ "use client";
5
+ function useWorkflowList(projectId = "local-project") {
6
+ const { handlers } = useTemplateRuntime();
7
+ const workflow = handlers.workflow;
8
+ const [definitions, setDefinitions] = useState([]);
9
+ const [instances, setInstances] = useState([]);
10
+ const [loading, setLoading] = useState(true);
11
+ const [error, setError] = useState(null);
12
+ const fetchData = useCallback(async () => {
13
+ try {
14
+ setLoading(true);
15
+ setError(null);
16
+ const [defResult, instResult] = await Promise.all([
17
+ workflow.listDefinitions({ projectId, limit: 100 }),
18
+ workflow.listInstances({ projectId, limit: 100 })
19
+ ]);
20
+ setDefinitions(defResult.definitions);
21
+ setInstances(instResult.instances);
22
+ } catch (err) {
23
+ setError(err instanceof Error ? err : new Error("Failed to load workflows"));
24
+ } finally {
25
+ setLoading(false);
26
+ }
27
+ }, [handlers, projectId]);
28
+ useEffect(() => {
29
+ fetchData();
30
+ }, [fetchData]);
31
+ const stats = {
32
+ totalDefinitions: definitions.length,
33
+ activeDefinitions: definitions.filter((d) => d.status === "ACTIVE").length,
34
+ totalInstances: instances.length,
35
+ pendingInstances: instances.filter((i) => i.status === "PENDING").length,
36
+ completedInstances: instances.filter((i) => i.status === "COMPLETED").length,
37
+ rejectedInstances: instances.filter((i) => i.status === "REJECTED").length
38
+ };
39
+ return {
40
+ definitions,
41
+ instances,
42
+ loading,
43
+ error,
44
+ stats,
45
+ refetch: fetchData
46
+ };
47
+ }
48
+ export {
49
+ workflowInstanceDetailMarkdownRenderer,
50
+ workflowDefinitionListMarkdownRenderer,
51
+ workflowDashboardMarkdownRenderer,
52
+ useWorkflowList,
53
+ WorkflowDashboard
54
+ };
@@ -0,0 +1,227 @@
1
+ // src/ui/renderers/workflow.markdown.ts
2
+ var mockWorkflowDefinitions = [
3
+ {
4
+ id: "wf-1",
5
+ name: "Purchase Approval",
6
+ type: "APPROVAL",
7
+ steps: [
8
+ {
9
+ id: "s1",
10
+ name: "Manager Review",
11
+ order: 1,
12
+ requiredRoles: ["manager"]
13
+ },
14
+ {
15
+ id: "s2",
16
+ name: "Finance Review",
17
+ order: 2,
18
+ requiredRoles: ["finance"]
19
+ },
20
+ { id: "s3", name: "Final Approval", order: 3, requiredRoles: ["admin"] }
21
+ ],
22
+ status: "ACTIVE"
23
+ },
24
+ {
25
+ id: "wf-2",
26
+ name: "Leave Request",
27
+ type: "APPROVAL",
28
+ steps: [
29
+ {
30
+ id: "s1",
31
+ name: "Supervisor Approval",
32
+ order: 1,
33
+ requiredRoles: ["supervisor"]
34
+ },
35
+ { id: "s2", name: "HR Review", order: 2, requiredRoles: ["hr"] }
36
+ ],
37
+ status: "ACTIVE"
38
+ },
39
+ {
40
+ id: "wf-3",
41
+ name: "Document Review",
42
+ type: "SEQUENTIAL",
43
+ steps: [
44
+ { id: "s1", name: "Author Review", order: 1, requiredRoles: ["author"] },
45
+ { id: "s2", name: "Peer Review", order: 2, requiredRoles: ["reviewer"] },
46
+ { id: "s3", name: "Publish", order: 3, requiredRoles: ["publisher"] }
47
+ ],
48
+ status: "DRAFT"
49
+ }
50
+ ];
51
+ var mockWorkflowInstances = [
52
+ {
53
+ id: "inst-1",
54
+ definitionId: "wf-1",
55
+ definitionName: "Purchase Approval",
56
+ status: "IN_PROGRESS",
57
+ currentStepId: "s2",
58
+ startedAt: "2024-01-15T10:00:00Z",
59
+ requestedBy: "John Doe"
60
+ },
61
+ {
62
+ id: "inst-2",
63
+ definitionId: "wf-1",
64
+ definitionName: "Purchase Approval",
65
+ status: "COMPLETED",
66
+ currentStepId: null,
67
+ startedAt: "2024-01-10T09:00:00Z",
68
+ completedAt: "2024-01-12T14:00:00Z",
69
+ requestedBy: "Jane Smith"
70
+ },
71
+ {
72
+ id: "inst-3",
73
+ definitionId: "wf-2",
74
+ definitionName: "Leave Request",
75
+ status: "PENDING",
76
+ currentStepId: "s1",
77
+ startedAt: "2024-01-16T08:00:00Z",
78
+ requestedBy: "Bob Wilson"
79
+ }
80
+ ];
81
+ var workflowDashboardMarkdownRenderer = {
82
+ target: "markdown",
83
+ render: async (desc) => {
84
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDashboard") {
85
+ throw new Error("workflowDashboardMarkdownRenderer: not WorkflowDashboard");
86
+ }
87
+ const definitions = mockWorkflowDefinitions;
88
+ const instances = mockWorkflowInstances;
89
+ const activeDefinitions = definitions.filter((d) => d.status === "ACTIVE");
90
+ const pendingInstances = instances.filter((i) => i.status === "PENDING");
91
+ const inProgressInstances = instances.filter((i) => i.status === "IN_PROGRESS");
92
+ const completedInstances = instances.filter((i) => i.status === "COMPLETED");
93
+ const lines = [
94
+ "# Workflow Dashboard",
95
+ "",
96
+ "> Workflow and approval management overview",
97
+ "",
98
+ "## Summary",
99
+ "",
100
+ "| Metric | Value |",
101
+ "|--------|-------|",
102
+ `| Active Workflows | ${activeDefinitions.length} |`,
103
+ `| Pending Approvals | ${pendingInstances.length} |`,
104
+ `| In Progress | ${inProgressInstances.length} |`,
105
+ `| Completed | ${completedInstances.length} |`,
106
+ "",
107
+ "## Active Workflow Definitions",
108
+ ""
109
+ ];
110
+ if (activeDefinitions.length === 0) {
111
+ lines.push("_No active workflow definitions._");
112
+ } else {
113
+ lines.push("| Name | Type | Steps | Status |");
114
+ lines.push("|------|------|-------|--------|");
115
+ for (const def of activeDefinitions) {
116
+ lines.push(`| ${def.name} | ${def.type} | ${def.steps.length} | ${def.status} |`);
117
+ }
118
+ }
119
+ lines.push("");
120
+ lines.push("## Recent Instances");
121
+ lines.push("");
122
+ if (instances.length === 0) {
123
+ lines.push("_No workflow instances._");
124
+ } else {
125
+ lines.push("| Workflow | Requested By | Status | Started |");
126
+ lines.push("|----------|--------------|--------|---------|");
127
+ for (const inst of instances.slice(0, 10)) {
128
+ const startedDate = new Date(inst.startedAt).toLocaleDateString();
129
+ lines.push(`| ${inst.definitionName} | ${inst.requestedBy} | ${inst.status} | ${startedDate} |`);
130
+ }
131
+ }
132
+ return {
133
+ mimeType: "text/markdown",
134
+ body: lines.join(`
135
+ `)
136
+ };
137
+ }
138
+ };
139
+ var workflowDefinitionListMarkdownRenderer = {
140
+ target: "markdown",
141
+ render: async (desc) => {
142
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDefinitionList") {
143
+ throw new Error("workflowDefinitionListMarkdownRenderer: not WorkflowDefinitionList");
144
+ }
145
+ const definitions = mockWorkflowDefinitions;
146
+ const lines = [
147
+ "# Workflow Definitions",
148
+ "",
149
+ "> Configure automated approval and process workflows",
150
+ ""
151
+ ];
152
+ for (const def of definitions) {
153
+ lines.push(`## ${def.name}`);
154
+ lines.push("");
155
+ lines.push(`**Type:** ${def.type} | **Status:** ${def.status}`);
156
+ lines.push("");
157
+ lines.push("### Steps");
158
+ lines.push("");
159
+ for (const step of def.steps) {
160
+ lines.push(`${step.order}. **${step.name}** - Roles: ${step.requiredRoles.join(", ")}`);
161
+ }
162
+ lines.push("");
163
+ }
164
+ return {
165
+ mimeType: "text/markdown",
166
+ body: lines.join(`
167
+ `)
168
+ };
169
+ }
170
+ };
171
+ var workflowInstanceDetailMarkdownRenderer = {
172
+ target: "markdown",
173
+ render: async (desc) => {
174
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowInstanceDetail") {
175
+ throw new Error("workflowInstanceDetailMarkdownRenderer: not WorkflowInstanceDetail");
176
+ }
177
+ const instance = mockWorkflowInstances[0];
178
+ if (!instance) {
179
+ return {
180
+ mimeType: "text/markdown",
181
+ body: `# No Workflow Instances
182
+
183
+ No workflow instances available.`
184
+ };
185
+ }
186
+ const definition = mockWorkflowDefinitions.find((d) => d.id === instance.definitionId);
187
+ const lines = [
188
+ `# Workflow: ${instance.definitionName}`,
189
+ "",
190
+ `**Instance ID:** ${instance.id}`,
191
+ `**Status:** ${instance.status}`,
192
+ `**Requested By:** ${instance.requestedBy}`,
193
+ `**Started:** ${new Date(instance.startedAt).toLocaleString()}`,
194
+ "",
195
+ "## Steps Progress",
196
+ ""
197
+ ];
198
+ if (definition) {
199
+ for (const step of definition.steps) {
200
+ const isCurrent = step.id === instance.currentStepId;
201
+ const isCompleted = definition.steps.indexOf(step) < definition.steps.findIndex((s) => s.id === instance.currentStepId);
202
+ let status = "⬜ Pending";
203
+ if (isCompleted)
204
+ status = "✅ Completed";
205
+ if (isCurrent)
206
+ status = "\uD83D\uDD04 In Progress";
207
+ lines.push(`- ${status} **${step.name}**`);
208
+ }
209
+ }
210
+ lines.push("");
211
+ lines.push("## Actions");
212
+ lines.push("");
213
+ lines.push("- **Approve** - Move to next step");
214
+ lines.push("- **Reject** - Reject and return");
215
+ lines.push("- **Delegate** - Assign to another approver");
216
+ return {
217
+ mimeType: "text/markdown",
218
+ body: lines.join(`
219
+ `)
220
+ };
221
+ }
222
+ };
223
+ export {
224
+ workflowInstanceDetailMarkdownRenderer,
225
+ workflowDefinitionListMarkdownRenderer,
226
+ workflowDashboardMarkdownRenderer
227
+ };