@lssm/example.workflow-system 0.0.0-canary-20251217063201 → 0.0.0-canary-20251217072406

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 (171) hide show
  1. package/dist/approval/approval.contracts.d.ts +134 -134
  2. package/dist/approval/approval.contracts.js +250 -1
  3. package/dist/approval/approval.enum.d.ts +3 -3
  4. package/dist/approval/approval.enum.js +29 -1
  5. package/dist/approval/approval.event.d.ts +32 -32
  6. package/dist/approval/approval.event.js +186 -1
  7. package/dist/approval/approval.handler.js +71 -1
  8. package/dist/approval/approval.schema.d.ts +24 -24
  9. package/dist/approval/approval.schema.js +111 -1
  10. package/dist/approval/index.js +6 -1
  11. package/dist/docs/index.js +1 -1
  12. package/dist/docs/workflow-system.docblock.js +61 -5
  13. package/dist/entities/approval.d.ts +36 -36
  14. package/dist/entities/approval.js +128 -1
  15. package/dist/entities/index.d.ts +127 -127
  16. package/dist/entities/index.js +31 -1
  17. package/dist/entities/instance.d.ts +47 -47
  18. package/dist/entities/instance.js +168 -1
  19. package/dist/entities/step.d.ts +32 -32
  20. package/dist/entities/step.js +135 -1
  21. package/dist/entities/workflow.d.ts +23 -23
  22. package/dist/entities/workflow.js +102 -1
  23. package/dist/example.js +50 -1
  24. package/dist/index.js +19 -1
  25. package/dist/instance/index.js +6 -1
  26. package/dist/instance/instance.contracts.d.ts +256 -256
  27. package/dist/instance/instance.contracts.js +334 -1
  28. package/dist/instance/instance.enum.d.ts +2 -2
  29. package/dist/instance/instance.enum.js +20 -1
  30. package/dist/instance/instance.event.d.ts +87 -87
  31. package/dist/instance/instance.event.js +214 -1
  32. package/dist/instance/instance.handler.js +93 -1
  33. package/dist/instance/instance.schema.d.ts +54 -54
  34. package/dist/instance/instance.schema.js +173 -1
  35. package/dist/libs/contracts/dist/capabilities/openbanking.js +88 -1
  36. package/dist/libs/contracts/dist/client/index.js +5 -1
  37. package/dist/libs/contracts/dist/client/react/feature-render.js +2 -1
  38. package/dist/libs/contracts/dist/client/react/form-render.js +4 -1
  39. package/dist/libs/contracts/dist/client/react/index.js +4 -1
  40. package/dist/libs/contracts/dist/contract-registry/index.js +1 -1
  41. package/dist/libs/contracts/dist/contract-registry/schemas.js +60 -1
  42. package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +16 -76
  43. package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -350
  44. package/dist/libs/contracts/dist/docs/index.js +29 -1
  45. package/dist/libs/contracts/dist/docs/presentations.js +71 -1
  46. package/dist/libs/contracts/dist/docs/registry.js +44 -1
  47. package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -383
  48. package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -68
  49. package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -140
  50. package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -86
  51. package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -1
  52. package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +24 -2
  53. package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +21 -2
  54. package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -213
  55. package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +73 -5
  56. package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -1
  57. package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -1
  58. package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +20 -262
  59. package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -1
  60. package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +24 -2
  61. package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +23 -2
  62. package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +25 -16
  63. package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -1
  64. package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +22 -2
  65. package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +40 -36
  66. package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -1
  67. package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +23 -2
  68. package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +36 -3
  69. package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -1
  70. package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +36 -3
  71. package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -1
  72. package/dist/libs/contracts/dist/events.js +10 -1
  73. package/dist/libs/contracts/dist/experiments/evaluator.js +1 -1
  74. package/dist/libs/contracts/dist/index.js +71 -1
  75. package/dist/libs/contracts/dist/install.js +2 -1
  76. package/dist/libs/contracts/dist/integrations/contracts.js +377 -1
  77. package/dist/libs/contracts/dist/integrations/index.js +18 -1
  78. package/dist/libs/contracts/dist/integrations/openbanking/contracts/accounts.js +228 -1
  79. package/dist/libs/contracts/dist/integrations/openbanking/contracts/balances.js +159 -1
  80. package/dist/libs/contracts/dist/integrations/openbanking/contracts/index.js +3 -1
  81. package/dist/libs/contracts/dist/integrations/openbanking/contracts/transactions.js +210 -1
  82. package/dist/libs/contracts/dist/integrations/openbanking/models.js +242 -1
  83. package/dist/libs/contracts/dist/integrations/openbanking/telemetry.js +13 -1
  84. package/dist/libs/contracts/dist/integrations/providers/elevenlabs.js +52 -1
  85. package/dist/libs/contracts/dist/integrations/providers/gcs-storage.js +75 -1
  86. package/dist/libs/contracts/dist/integrations/providers/gmail.js +87 -1
  87. package/dist/libs/contracts/dist/integrations/providers/google-calendar.js +66 -1
  88. package/dist/libs/contracts/dist/integrations/providers/index.js +11 -1
  89. package/dist/libs/contracts/dist/integrations/providers/mistral.js +68 -1
  90. package/dist/libs/contracts/dist/integrations/providers/postmark.js +68 -1
  91. package/dist/libs/contracts/dist/integrations/providers/powens.js +116 -1
  92. package/dist/libs/contracts/dist/integrations/providers/qdrant.js +73 -1
  93. package/dist/libs/contracts/dist/integrations/providers/registry.js +10 -1
  94. package/dist/libs/contracts/dist/integrations/providers/stripe.js +83 -1
  95. package/dist/libs/contracts/dist/integrations/providers/twilio-sms.js +61 -1
  96. package/dist/libs/contracts/dist/jsonschema.js +1 -1
  97. package/dist/libs/contracts/dist/knowledge/contracts.js +306 -1
  98. package/dist/libs/contracts/dist/knowledge/index.js +7 -1
  99. package/dist/libs/contracts/dist/knowledge/spaces/email-threads.js +34 -1
  100. package/dist/libs/contracts/dist/knowledge/spaces/financial-docs.js +34 -1
  101. package/dist/libs/contracts/dist/knowledge/spaces/financial-overview.js +38 -1
  102. package/dist/libs/contracts/dist/knowledge/spaces/index.js +6 -1
  103. package/dist/libs/contracts/dist/knowledge/spaces/product-canon.js +34 -1
  104. package/dist/libs/contracts/dist/knowledge/spaces/support-faq.js +37 -1
  105. package/dist/libs/contracts/dist/knowledge/spaces/uploaded-docs.js +34 -1
  106. package/dist/libs/contracts/dist/llm/exporters.js +19 -1
  107. package/dist/libs/contracts/dist/llm/index.js +2 -1
  108. package/dist/libs/contracts/dist/llm/prompts.js +1 -1
  109. package/dist/libs/contracts/dist/onboarding-base.js +196 -1
  110. package/dist/libs/contracts/dist/openapi.js +1 -1
  111. package/dist/libs/contracts/dist/ownership.js +21 -1
  112. package/dist/libs/contracts/dist/presentations.js +1 -1
  113. package/dist/libs/contracts/dist/presentations.v2.js +11 -1
  114. package/dist/libs/contracts/dist/prompt.js +1 -1
  115. package/dist/libs/contracts/dist/promptRegistry.js +1 -1
  116. package/dist/libs/contracts/dist/regenerator/index.js +1 -1
  117. package/dist/libs/contracts/dist/regenerator/service.js +6 -1
  118. package/dist/libs/contracts/dist/registry.js +2 -1
  119. package/dist/libs/contracts/dist/resources.js +1 -1
  120. package/dist/libs/contracts/dist/schema/dist/EnumType.js +2 -1
  121. package/dist/libs/contracts/dist/schema/dist/FieldType.js +49 -1
  122. package/dist/libs/contracts/dist/schema/dist/ScalarTypeEnum.js +236 -1
  123. package/dist/libs/contracts/dist/schema/dist/SchemaModel.js +39 -1
  124. package/dist/libs/contracts/dist/schema/dist/entity/defineEntity.js +1 -1
  125. package/dist/libs/contracts/dist/schema/dist/entity/index.js +2 -1
  126. package/dist/libs/contracts/dist/schema/dist/entity/types.js +1 -1
  127. package/dist/libs/contracts/dist/schema/dist/index.js +6 -1
  128. package/dist/libs/contracts/dist/server/graphql-pothos.js +6 -1
  129. package/dist/libs/contracts/dist/server/index.js +8 -1
  130. package/dist/libs/contracts/dist/server/mcp/createMcpServer.js +4 -1
  131. package/dist/libs/contracts/dist/server/mcp/registerPresentations.js +2 -1
  132. package/dist/libs/contracts/dist/server/mcp/registerPrompts.js +1 -1
  133. package/dist/libs/contracts/dist/server/mcp/registerResources.js +2 -1
  134. package/dist/libs/contracts/dist/server/mcp/registerTools.js +1 -1
  135. package/dist/libs/contracts/dist/server/provider-mcp.js +1 -1
  136. package/dist/libs/contracts/dist/server/rest-elysia.js +1 -1
  137. package/dist/libs/contracts/dist/server/rest-express.js +1 -1
  138. package/dist/libs/contracts/dist/server/rest-generic.js +1 -1
  139. package/dist/libs/contracts/dist/server/rest-next-app.js +1 -1
  140. package/dist/libs/contracts/dist/server/rest-next-pages.js +1 -1
  141. package/dist/libs/contracts/dist/spec.js +34 -1
  142. package/dist/libs/contracts/dist/telemetry/index.js +1 -1
  143. package/dist/libs/contracts/dist/telemetry/tracker.js +1 -1
  144. package/dist/libs/contracts/dist/tests/index.js +1 -1
  145. package/dist/libs/contracts/dist/tests/runner.js +2 -1
  146. package/dist/libs/contracts/dist/workflow/index.js +1 -1
  147. package/dist/libs/contracts/dist/workflow/runner.js +1 -1
  148. package/dist/libs/schema/dist/EnumType.js +56 -1
  149. package/dist/libs/schema/dist/FieldType.js +49 -1
  150. package/dist/libs/schema/dist/ScalarTypeEnum.js +236 -1
  151. package/dist/libs/schema/dist/SchemaModel.js +39 -1
  152. package/dist/libs/schema/dist/entity/defineEntity.js +236 -1
  153. package/dist/libs/schema/dist/entity/index.js +2 -1
  154. package/dist/libs/schema/dist/entity/types.js +1 -1
  155. package/dist/libs/schema/dist/index.js +6 -1
  156. package/dist/presentations/index.js +291 -1
  157. package/dist/shared/index.js +3 -1
  158. package/dist/shared/mock-data.js +11 -1
  159. package/dist/state-machine/index.js +157 -1
  160. package/dist/workflow/index.js +6 -1
  161. package/dist/workflow/workflow.contracts.d.ts +246 -246
  162. package/dist/workflow/workflow.contracts.js +239 -1
  163. package/dist/workflow/workflow.enum.d.ts +5 -5
  164. package/dist/workflow/workflow.enum.js +47 -1
  165. package/dist/workflow/workflow.event.d.ts +32 -32
  166. package/dist/workflow/workflow.event.js +116 -1
  167. package/dist/workflow/workflow.handler.js +65 -1
  168. package/dist/workflow/workflow.schema.d.ts +63 -63
  169. package/dist/workflow/workflow.schema.js +250 -1
  170. package/dist/workflow-system.feature.js +337 -1
  171. package/package.json +11 -11
@@ -1 +1,71 @@
1
- import{mockDataStore as e}from"../shared/mock-data.js";import{handleTransitionWorkflow as t}from"../instance/instance.handler.js";async function n(t,n,r){let i=new Date;for(let r=0;r<n.approverRoles.length;r++){let a=n.approverRoles[r],o=`approval_${Date.now()}_${r}`,s={id:o,workflowInstanceId:t.id,stepExecutionId:`exec_${t.id}_${n.id}`,approverId:`user_${a}`,approverRole:a,title:`Approval required for ${n.name}`,description:n.description,status:`PENDING`,contextSnapshot:t.contextData,sequenceOrder:r,createdAt:i,updatedAt:i};e.approvals.set(o,s)}}async function r(n,r){let i=e.approvals.get(n.requestId);if(!i)throw Error(`Approval request ${n.requestId} not found`);if(i.approverId!==r.userId&&!r.userRoles.includes(i.approverRole??``))throw Error(`User is not authorized to make this decision`);let a=new Date;return i.decision=n.decision,i.decisionComment=n.comment,i.decidedAt=a,i.updatedAt=a,n.decision===`APPROVE`?(i.status=`APPROVED`,await t({instanceId:i.workflowInstanceId,action:`approve`,data:n.data,comment:n.comment},r)):n.decision===`REJECT`&&(i.status=`REJECTED`,await t({instanceId:i.workflowInstanceId,action:`reject`,data:n.data,comment:n.comment},r)),i}async function i(t,n){let r=Array.from(e.approvals.values()).filter(e=>e.approverId===n.userId||n.userRoles.includes(e.approverRole??``)),i=r.filter(e=>e.status===`PENDING`).length;t.status&&(r=r.filter(e=>e.status===t.status));let a=r.length,o=t.offset??0,s=t.limit??20;return r=r.sort((e,t)=>t.createdAt.getTime()-e.createdAt.getTime()).slice(o,o+s),{requests:r,total:a,pendingCount:i}}export{n as createApprovalRequests,i as handleListMyApprovals,r as handleSubmitDecision};
1
+ import { mockDataStore } from "../shared/mock-data.js";
2
+ import { handleTransitionWorkflow } from "../instance/instance.handler.js";
3
+
4
+ //#region src/approval/approval.handler.ts
5
+ async function createApprovalRequests(instance, step, _context) {
6
+ const now = /* @__PURE__ */ new Date();
7
+ for (let i = 0; i < step.approverRoles.length; i++) {
8
+ const role = step.approverRoles[i];
9
+ const id = `approval_${Date.now()}_${i}`;
10
+ const request = {
11
+ id,
12
+ workflowInstanceId: instance.id,
13
+ stepExecutionId: `exec_${instance.id}_${step.id}`,
14
+ approverId: `user_${role}`,
15
+ approverRole: role,
16
+ title: `Approval required for ${step.name}`,
17
+ description: step.description,
18
+ status: "PENDING",
19
+ contextSnapshot: instance.contextData,
20
+ sequenceOrder: i,
21
+ createdAt: now,
22
+ updatedAt: now
23
+ };
24
+ mockDataStore.approvals.set(id, request);
25
+ }
26
+ }
27
+ async function handleSubmitDecision(input, context) {
28
+ const request = mockDataStore.approvals.get(input.requestId);
29
+ if (!request) throw new Error(`Approval request ${input.requestId} not found`);
30
+ if (request.approverId !== context.userId && !context.userRoles.includes(request.approverRole ?? "")) throw new Error("User is not authorized to make this decision");
31
+ const now = /* @__PURE__ */ new Date();
32
+ request.decision = input.decision;
33
+ request.decisionComment = input.comment;
34
+ request.decidedAt = now;
35
+ request.updatedAt = now;
36
+ if (input.decision === "APPROVE") {
37
+ request.status = "APPROVED";
38
+ await handleTransitionWorkflow({
39
+ instanceId: request.workflowInstanceId,
40
+ action: "approve",
41
+ data: input.data,
42
+ comment: input.comment
43
+ }, context);
44
+ } else if (input.decision === "REJECT") {
45
+ request.status = "REJECTED";
46
+ await handleTransitionWorkflow({
47
+ instanceId: request.workflowInstanceId,
48
+ action: "reject",
49
+ data: input.data,
50
+ comment: input.comment
51
+ }, context);
52
+ }
53
+ return request;
54
+ }
55
+ async function handleListMyApprovals(input, context) {
56
+ let requests = Array.from(mockDataStore.approvals.values()).filter((r) => r.approverId === context.userId || context.userRoles.includes(r.approverRole ?? ""));
57
+ const pendingCount = requests.filter((r) => r.status === "PENDING").length;
58
+ if (input.status) requests = requests.filter((r) => r.status === input.status);
59
+ const total = requests.length;
60
+ const offset = input.offset ?? 0;
61
+ const limit = input.limit ?? 20;
62
+ requests = requests.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime()).slice(offset, offset + limit);
63
+ return {
64
+ requests,
65
+ total,
66
+ pendingCount
67
+ };
68
+ }
69
+
70
+ //#endregion
71
+ export { createApprovalRequests, handleListMyApprovals, handleSubmitDecision };
@@ -1,97 +1,97 @@
1
- import * as _lssm_lib_schema161 from "@lssm/lib.schema";
1
+ import * as _lssm_lib_schema260 from "@lssm/lib.schema";
2
2
 
3
3
  //#region src/approval/approval.schema.d.ts
4
4
  /**
5
5
  * An approval request.
6
6
  */
7
- declare const ApprovalRequestModel: _lssm_lib_schema161.SchemaModel<{
7
+ declare const ApprovalRequestModel: _lssm_lib_schema260.SchemaModel<{
8
8
  id: {
9
- type: _lssm_lib_schema161.FieldType<string, string>;
9
+ type: _lssm_lib_schema260.FieldType<string, string>;
10
10
  isOptional: false;
11
11
  };
12
12
  workflowInstanceId: {
13
- type: _lssm_lib_schema161.FieldType<string, string>;
13
+ type: _lssm_lib_schema260.FieldType<string, string>;
14
14
  isOptional: false;
15
15
  };
16
16
  stepExecutionId: {
17
- type: _lssm_lib_schema161.FieldType<string, string>;
17
+ type: _lssm_lib_schema260.FieldType<string, string>;
18
18
  isOptional: false;
19
19
  };
20
20
  approverId: {
21
- type: _lssm_lib_schema161.FieldType<string, string>;
21
+ type: _lssm_lib_schema260.FieldType<string, string>;
22
22
  isOptional: false;
23
23
  };
24
24
  approverRole: {
25
- type: _lssm_lib_schema161.FieldType<string, string>;
25
+ type: _lssm_lib_schema260.FieldType<string, string>;
26
26
  isOptional: true;
27
27
  };
28
28
  title: {
29
- type: _lssm_lib_schema161.FieldType<string, string>;
29
+ type: _lssm_lib_schema260.FieldType<string, string>;
30
30
  isOptional: false;
31
31
  };
32
32
  description: {
33
- type: _lssm_lib_schema161.FieldType<string, string>;
33
+ type: _lssm_lib_schema260.FieldType<string, string>;
34
34
  isOptional: true;
35
35
  };
36
36
  status: {
37
- type: _lssm_lib_schema161.EnumType<[string, string, string, string, string, string, string]>;
37
+ type: _lssm_lib_schema260.EnumType<[string, string, string, string, string, string, string]>;
38
38
  isOptional: false;
39
39
  };
40
40
  decision: {
41
- type: _lssm_lib_schema161.EnumType<[string, string, string, string, string]>;
41
+ type: _lssm_lib_schema260.EnumType<[string, string, string, string, string]>;
42
42
  isOptional: true;
43
43
  };
44
44
  decisionComment: {
45
- type: _lssm_lib_schema161.FieldType<string, string>;
45
+ type: _lssm_lib_schema260.FieldType<string, string>;
46
46
  isOptional: true;
47
47
  };
48
48
  decidedAt: {
49
- type: _lssm_lib_schema161.FieldType<Date, string>;
49
+ type: _lssm_lib_schema260.FieldType<Date, string>;
50
50
  isOptional: true;
51
51
  };
52
52
  dueAt: {
53
- type: _lssm_lib_schema161.FieldType<Date, string>;
53
+ type: _lssm_lib_schema260.FieldType<Date, string>;
54
54
  isOptional: true;
55
55
  };
56
56
  contextSnapshot: {
57
- type: _lssm_lib_schema161.FieldType<unknown, unknown>;
57
+ type: _lssm_lib_schema260.FieldType<unknown, unknown>;
58
58
  isOptional: true;
59
59
  };
60
60
  sequenceOrder: {
61
- type: _lssm_lib_schema161.FieldType<number, number>;
61
+ type: _lssm_lib_schema260.FieldType<number, number>;
62
62
  isOptional: false;
63
63
  };
64
64
  createdAt: {
65
- type: _lssm_lib_schema161.FieldType<Date, string>;
65
+ type: _lssm_lib_schema260.FieldType<Date, string>;
66
66
  isOptional: false;
67
67
  };
68
68
  }>;
69
69
  /**
70
70
  * A comment on an approval.
71
71
  */
72
- declare const ApprovalCommentModel: _lssm_lib_schema161.SchemaModel<{
72
+ declare const ApprovalCommentModel: _lssm_lib_schema260.SchemaModel<{
73
73
  id: {
74
- type: _lssm_lib_schema161.FieldType<string, string>;
74
+ type: _lssm_lib_schema260.FieldType<string, string>;
75
75
  isOptional: false;
76
76
  };
77
77
  approvalRequestId: {
78
- type: _lssm_lib_schema161.FieldType<string, string>;
78
+ type: _lssm_lib_schema260.FieldType<string, string>;
79
79
  isOptional: false;
80
80
  };
81
81
  authorId: {
82
- type: _lssm_lib_schema161.FieldType<string, string>;
82
+ type: _lssm_lib_schema260.FieldType<string, string>;
83
83
  isOptional: false;
84
84
  };
85
85
  content: {
86
- type: _lssm_lib_schema161.FieldType<string, string>;
86
+ type: _lssm_lib_schema260.FieldType<string, string>;
87
87
  isOptional: false;
88
88
  };
89
89
  isInternal: {
90
- type: _lssm_lib_schema161.FieldType<boolean, boolean>;
90
+ type: _lssm_lib_schema260.FieldType<boolean, boolean>;
91
91
  isOptional: false;
92
92
  };
93
93
  createdAt: {
94
- type: _lssm_lib_schema161.FieldType<Date, string>;
94
+ type: _lssm_lib_schema260.FieldType<Date, string>;
95
95
  isOptional: false;
96
96
  };
97
97
  }>;
@@ -1 +1,111 @@
1
- import{l as e}from"../libs/schema/dist/ScalarTypeEnum.js";import{n as t}from"../libs/schema/dist/SchemaModel.js";import"../libs/schema/dist/index.js";import{ApprovalDecisionEnum as n,ApprovalStatusEnum as r}from"./approval.enum.js";const i=t({name:`ApprovalRequestModel`,description:`An approval request`,fields:{id:{type:e.String_unsecure(),isOptional:!1},workflowInstanceId:{type:e.String_unsecure(),isOptional:!1},stepExecutionId:{type:e.String_unsecure(),isOptional:!1},approverId:{type:e.String_unsecure(),isOptional:!1},approverRole:{type:e.String_unsecure(),isOptional:!0},title:{type:e.String_unsecure(),isOptional:!1},description:{type:e.String_unsecure(),isOptional:!0},status:{type:r,isOptional:!1},decision:{type:n,isOptional:!0},decisionComment:{type:e.String_unsecure(),isOptional:!0},decidedAt:{type:e.DateTime(),isOptional:!0},dueAt:{type:e.DateTime(),isOptional:!0},contextSnapshot:{type:e.JSON(),isOptional:!0},sequenceOrder:{type:e.Int_unsecure(),isOptional:!1},createdAt:{type:e.DateTime(),isOptional:!1}}}),a=t({name:`ApprovalCommentModel`,description:`A comment on an approval`,fields:{id:{type:e.String_unsecure(),isOptional:!1},approvalRequestId:{type:e.String_unsecure(),isOptional:!1},authorId:{type:e.String_unsecure(),isOptional:!1},content:{type:e.String_unsecure(),isOptional:!1},isInternal:{type:e.Boolean(),isOptional:!1},createdAt:{type:e.DateTime(),isOptional:!1}}});export{a as ApprovalCommentModel,i as ApprovalRequestModel};
1
+ import { ScalarTypeEnum } from "../libs/schema/dist/ScalarTypeEnum.js";
2
+ import { defineSchemaModel } from "../libs/schema/dist/SchemaModel.js";
3
+ import "../libs/schema/dist/index.js";
4
+ import { ApprovalDecisionEnum, ApprovalStatusEnum } from "./approval.enum.js";
5
+
6
+ //#region src/approval/approval.schema.ts
7
+ /**
8
+ * An approval request.
9
+ */
10
+ const ApprovalRequestModel = defineSchemaModel({
11
+ name: "ApprovalRequestModel",
12
+ description: "An approval request",
13
+ fields: {
14
+ id: {
15
+ type: ScalarTypeEnum.String_unsecure(),
16
+ isOptional: false
17
+ },
18
+ workflowInstanceId: {
19
+ type: ScalarTypeEnum.String_unsecure(),
20
+ isOptional: false
21
+ },
22
+ stepExecutionId: {
23
+ type: ScalarTypeEnum.String_unsecure(),
24
+ isOptional: false
25
+ },
26
+ approverId: {
27
+ type: ScalarTypeEnum.String_unsecure(),
28
+ isOptional: false
29
+ },
30
+ approverRole: {
31
+ type: ScalarTypeEnum.String_unsecure(),
32
+ isOptional: true
33
+ },
34
+ title: {
35
+ type: ScalarTypeEnum.String_unsecure(),
36
+ isOptional: false
37
+ },
38
+ description: {
39
+ type: ScalarTypeEnum.String_unsecure(),
40
+ isOptional: true
41
+ },
42
+ status: {
43
+ type: ApprovalStatusEnum,
44
+ isOptional: false
45
+ },
46
+ decision: {
47
+ type: ApprovalDecisionEnum,
48
+ isOptional: true
49
+ },
50
+ decisionComment: {
51
+ type: ScalarTypeEnum.String_unsecure(),
52
+ isOptional: true
53
+ },
54
+ decidedAt: {
55
+ type: ScalarTypeEnum.DateTime(),
56
+ isOptional: true
57
+ },
58
+ dueAt: {
59
+ type: ScalarTypeEnum.DateTime(),
60
+ isOptional: true
61
+ },
62
+ contextSnapshot: {
63
+ type: ScalarTypeEnum.JSON(),
64
+ isOptional: true
65
+ },
66
+ sequenceOrder: {
67
+ type: ScalarTypeEnum.Int_unsecure(),
68
+ isOptional: false
69
+ },
70
+ createdAt: {
71
+ type: ScalarTypeEnum.DateTime(),
72
+ isOptional: false
73
+ }
74
+ }
75
+ });
76
+ /**
77
+ * A comment on an approval.
78
+ */
79
+ const ApprovalCommentModel = defineSchemaModel({
80
+ name: "ApprovalCommentModel",
81
+ description: "A comment on an approval",
82
+ fields: {
83
+ id: {
84
+ type: ScalarTypeEnum.String_unsecure(),
85
+ isOptional: false
86
+ },
87
+ approvalRequestId: {
88
+ type: ScalarTypeEnum.String_unsecure(),
89
+ isOptional: false
90
+ },
91
+ authorId: {
92
+ type: ScalarTypeEnum.String_unsecure(),
93
+ isOptional: false
94
+ },
95
+ content: {
96
+ type: ScalarTypeEnum.String_unsecure(),
97
+ isOptional: false
98
+ },
99
+ isInternal: {
100
+ type: ScalarTypeEnum.Boolean(),
101
+ isOptional: false
102
+ },
103
+ createdAt: {
104
+ type: ScalarTypeEnum.DateTime(),
105
+ isOptional: false
106
+ }
107
+ }
108
+ });
109
+
110
+ //#endregion
111
+ export { ApprovalCommentModel, ApprovalRequestModel };
@@ -1 +1,6 @@
1
- import{ApprovalDecisionEnum as e,ApprovalStatusEnum as t}from"./approval.enum.js";import{ApprovalCommentModel as n,ApprovalRequestModel as r}from"./approval.schema.js";import{AddApprovalCommentContract as i,DelegateApprovalContract as a,GetApprovalContract as o,ListMyApprovalsContract as s,SubmitDecisionContract as c}from"./approval.contracts.js";import{ApprovalDecidedEvent as l,ApprovalDelegatedEvent as u,ApprovalEscalatedEvent as d,ApprovalRequestedEvent as f}from"./approval.event.js";export{i as AddApprovalCommentContract,n as ApprovalCommentModel,l as ApprovalDecidedEvent,e as ApprovalDecisionEnum,u as ApprovalDelegatedEvent,d as ApprovalEscalatedEvent,r as ApprovalRequestModel,f as ApprovalRequestedEvent,t as ApprovalStatusEnum,a as DelegateApprovalContract,o as GetApprovalContract,s as ListMyApprovalsContract,c as SubmitDecisionContract};
1
+ import { ApprovalDecisionEnum, ApprovalStatusEnum } from "./approval.enum.js";
2
+ import { ApprovalCommentModel, ApprovalRequestModel } from "./approval.schema.js";
3
+ import { AddApprovalCommentContract, DelegateApprovalContract, GetApprovalContract, ListMyApprovalsContract, SubmitDecisionContract } from "./approval.contracts.js";
4
+ import { ApprovalDecidedEvent, ApprovalDelegatedEvent, ApprovalEscalatedEvent, ApprovalRequestedEvent } from "./approval.event.js";
5
+
6
+ export { AddApprovalCommentContract, ApprovalCommentModel, ApprovalDecidedEvent, ApprovalDecisionEnum, ApprovalDelegatedEvent, ApprovalEscalatedEvent, ApprovalRequestModel, ApprovalRequestedEvent, ApprovalStatusEnum, DelegateApprovalContract, GetApprovalContract, ListMyApprovalsContract, SubmitDecisionContract };
@@ -1 +1 @@
1
- import"./workflow-system.docblock.js";
1
+ import "./workflow-system.docblock.js";
@@ -1,4 +1,22 @@
1
- import{a as e}from"../libs/contracts/dist/docs/registry.js";import"../libs/contracts/dist/docs/index.js";e([{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
1
+ import { registerDocBlocks } from "../libs/contracts/dist/docs/registry.js";
2
+ import "../libs/contracts/dist/docs/index.js";
3
+
4
+ //#region src/docs/workflow-system.docblock.ts
5
+ registerDocBlocks([
6
+ {
7
+ id: "docs.examples.workflow-system",
8
+ title: "Workflow / Approval System",
9
+ summary: "Reference app showing state-machine driven approvals with RBAC, audit trail, notifications, and jobs.",
10
+ kind: "reference",
11
+ visibility: "public",
12
+ route: "/docs/examples/workflow-system",
13
+ tags: [
14
+ "workflow",
15
+ "approval",
16
+ "state-machine",
17
+ "rbac"
18
+ ],
19
+ body: `## Entities
2
20
 
3
21
  - WorkflowDefinition, WorkflowStep, WorkflowInstance, Approval.
4
22
  - State machine expressed in \`src/state-machine\` with allowed transitions and role gates.
@@ -22,7 +40,17 @@ import{a as e}from"../libs/contracts/dist/docs/registry.js";import"../libs/contr
22
40
 
23
41
  - Keep transitions declarative to enable safe regeneration; role guards live in spec.
24
42
  - Use Notification Center for approval requests and outcomes; attach files via Files module if needed.
25
- `},{id:`docs.examples.workflow-system.goal`,title:`Workflow System — 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
43
+ `
44
+ },
45
+ {
46
+ id: "docs.examples.workflow-system.goal",
47
+ title: "Workflow System — Goal",
48
+ summary: "Why the workflow/approval template exists and outcomes it targets.",
49
+ kind: "goal",
50
+ visibility: "public",
51
+ route: "/docs/examples/workflow-system/goal",
52
+ tags: ["workflow", "goal"],
53
+ body: `## Why it matters
26
54
  - Provides a regenerable, role-gated approval engine using declarative state machines.
27
55
  - Keeps workflow rules consistent across UI/API/events with auditability.
28
56
 
@@ -32,7 +60,17 @@ import{a as e}from"../libs/contracts/dist/docs/registry.js";import"../libs/contr
32
60
 
33
61
  ## Success criteria
34
62
  - State changes are declarative and regenerate cleanly.
35
- - Every transition emits auditable events and respects RBAC guards.`},{id:`docs.examples.workflow-system.usage`,title:`Workflow System — 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
63
+ - Every transition emits auditable events and respects RBAC guards.`
64
+ },
65
+ {
66
+ id: "docs.examples.workflow-system.usage",
67
+ title: "Workflow System — Usage",
68
+ summary: "How to configure workflows, transitions, and regenerate safely.",
69
+ kind: "usage",
70
+ visibility: "public",
71
+ route: "/docs/examples/workflow-system/usage",
72
+ tags: ["workflow", "usage"],
73
+ body: `## Setup
36
74
  1) Define WorkflowDefinition steps and allowed transitions with role gates in spec.
37
75
  2) Seed sample workflows/instances (if provided) or create via UI; enable reminders via Jobs.
38
76
 
@@ -44,7 +82,21 @@ import{a as e}from"../libs/contracts/dist/docs/registry.js";import"../libs/contr
44
82
  ## Guardrails
45
83
  - Emit events for every transition; log to Audit Trail.
46
84
  - Use Notifications for approvals/rejections; schedule reminders for pending steps.
47
- - Keep transitions declarative; avoid imperative branching in handlers.`},{id:`docs.examples.workflow-system.constraints`,title:`Workflow System — 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
85
+ - Keep transitions declarative; avoid imperative branching in handlers.`
86
+ },
87
+ {
88
+ id: "docs.examples.workflow-system.constraints",
89
+ title: "Workflow System — Constraints & Safety",
90
+ summary: "Internal guardrails for state machines, RBAC, and regeneration semantics.",
91
+ kind: "reference",
92
+ visibility: "internal",
93
+ route: "/docs/examples/workflow-system/constraints",
94
+ tags: [
95
+ "workflow",
96
+ "constraints",
97
+ "internal"
98
+ ],
99
+ body: `## Constraints
48
100
  - State machine (steps/transitions) must stay declarative in spec; no hidden code paths.
49
101
  - Events to emit: instance.started, step.completed/rejected, instance.finished.
50
102
  - Regeneration must not change approval logic without explicit spec diff.
@@ -56,4 +108,8 @@ import{a as e}from"../libs/contracts/dist/docs/registry.js";import"../libs/contr
56
108
  ## Verification
57
109
  - Add fixtures for transition changes and role gates.
58
110
  - Validate reminders (Jobs) stay aligned with pending states after regeneration.
59
- - Use Feature Flags for new transitions/escalation rules; default safe/off.`}]);
111
+ - Use Feature Flags for new transitions/escalation rules; default safe/off.`
112
+ }
113
+ ]);
114
+
115
+ //#endregion
@@ -1,57 +1,57 @@
1
- import * as _lssm_lib_schema1145 from "@lssm/lib.schema";
1
+ import * as _lssm_lib_schema61 from "@lssm/lib.schema";
2
2
 
3
3
  //#region src/entities/approval.d.ts
4
4
  /**
5
5
  * Approval status enum.
6
6
  */
7
- declare const ApprovalStatusEnum: _lssm_lib_schema1145.EntityEnumDef;
7
+ declare const ApprovalStatusEnum: _lssm_lib_schema61.EntityEnumDef;
8
8
  /**
9
9
  * Approval decision enum.
10
10
  */
11
- declare const ApprovalDecisionEnum: _lssm_lib_schema1145.EntityEnumDef;
11
+ declare const ApprovalDecisionEnum: _lssm_lib_schema61.EntityEnumDef;
12
12
  /**
13
13
  * ApprovalRequest entity - a request for approval from a user.
14
14
  *
15
15
  * Created when a workflow reaches an APPROVAL step. Multiple requests
16
16
  * may be created depending on the approval mode.
17
17
  */
18
- declare const ApprovalRequestEntity: _lssm_lib_schema1145.EntitySpec<{
19
- id: _lssm_lib_schema1145.EntityScalarField;
20
- workflowInstanceId: _lssm_lib_schema1145.EntityScalarField;
21
- stepExecutionId: _lssm_lib_schema1145.EntityScalarField;
22
- approverId: _lssm_lib_schema1145.EntityScalarField;
23
- approverRole: _lssm_lib_schema1145.EntityScalarField;
24
- title: _lssm_lib_schema1145.EntityScalarField;
25
- description: _lssm_lib_schema1145.EntityScalarField;
26
- status: _lssm_lib_schema1145.EntityEnumField;
27
- decision: _lssm_lib_schema1145.EntityEnumField;
28
- decisionComment: _lssm_lib_schema1145.EntityScalarField;
29
- decidedAt: _lssm_lib_schema1145.EntityScalarField;
30
- delegatedTo: _lssm_lib_schema1145.EntityScalarField;
31
- delegationReason: _lssm_lib_schema1145.EntityScalarField;
32
- escalationLevel: _lssm_lib_schema1145.EntityScalarField;
33
- escalatedAt: _lssm_lib_schema1145.EntityScalarField;
34
- dueAt: _lssm_lib_schema1145.EntityScalarField;
35
- reminderSentAt: _lssm_lib_schema1145.EntityScalarField;
36
- contextSnapshot: _lssm_lib_schema1145.EntityScalarField;
37
- sequenceOrder: _lssm_lib_schema1145.EntityScalarField;
38
- createdAt: _lssm_lib_schema1145.EntityScalarField;
39
- updatedAt: _lssm_lib_schema1145.EntityScalarField;
40
- workflowInstance: _lssm_lib_schema1145.EntityRelationField;
41
- stepExecution: _lssm_lib_schema1145.EntityRelationField;
18
+ declare const ApprovalRequestEntity: _lssm_lib_schema61.EntitySpec<{
19
+ id: _lssm_lib_schema61.EntityScalarField;
20
+ workflowInstanceId: _lssm_lib_schema61.EntityScalarField;
21
+ stepExecutionId: _lssm_lib_schema61.EntityScalarField;
22
+ approverId: _lssm_lib_schema61.EntityScalarField;
23
+ approverRole: _lssm_lib_schema61.EntityScalarField;
24
+ title: _lssm_lib_schema61.EntityScalarField;
25
+ description: _lssm_lib_schema61.EntityScalarField;
26
+ status: _lssm_lib_schema61.EntityEnumField;
27
+ decision: _lssm_lib_schema61.EntityEnumField;
28
+ decisionComment: _lssm_lib_schema61.EntityScalarField;
29
+ decidedAt: _lssm_lib_schema61.EntityScalarField;
30
+ delegatedTo: _lssm_lib_schema61.EntityScalarField;
31
+ delegationReason: _lssm_lib_schema61.EntityScalarField;
32
+ escalationLevel: _lssm_lib_schema61.EntityScalarField;
33
+ escalatedAt: _lssm_lib_schema61.EntityScalarField;
34
+ dueAt: _lssm_lib_schema61.EntityScalarField;
35
+ reminderSentAt: _lssm_lib_schema61.EntityScalarField;
36
+ contextSnapshot: _lssm_lib_schema61.EntityScalarField;
37
+ sequenceOrder: _lssm_lib_schema61.EntityScalarField;
38
+ createdAt: _lssm_lib_schema61.EntityScalarField;
39
+ updatedAt: _lssm_lib_schema61.EntityScalarField;
40
+ workflowInstance: _lssm_lib_schema61.EntityRelationField;
41
+ stepExecution: _lssm_lib_schema61.EntityRelationField;
42
42
  }>;
43
43
  /**
44
44
  * ApprovalComment entity - comments on approval requests.
45
45
  */
46
- declare const ApprovalCommentEntity: _lssm_lib_schema1145.EntitySpec<{
47
- id: _lssm_lib_schema1145.EntityScalarField;
48
- approvalRequestId: _lssm_lib_schema1145.EntityScalarField;
49
- authorId: _lssm_lib_schema1145.EntityScalarField;
50
- content: _lssm_lib_schema1145.EntityScalarField;
51
- isInternal: _lssm_lib_schema1145.EntityScalarField;
52
- createdAt: _lssm_lib_schema1145.EntityScalarField;
53
- updatedAt: _lssm_lib_schema1145.EntityScalarField;
54
- approvalRequest: _lssm_lib_schema1145.EntityRelationField;
46
+ declare const ApprovalCommentEntity: _lssm_lib_schema61.EntitySpec<{
47
+ id: _lssm_lib_schema61.EntityScalarField;
48
+ approvalRequestId: _lssm_lib_schema61.EntityScalarField;
49
+ authorId: _lssm_lib_schema61.EntityScalarField;
50
+ content: _lssm_lib_schema61.EntityScalarField;
51
+ isInternal: _lssm_lib_schema61.EntityScalarField;
52
+ createdAt: _lssm_lib_schema61.EntityScalarField;
53
+ updatedAt: _lssm_lib_schema61.EntityScalarField;
54
+ approvalRequest: _lssm_lib_schema61.EntityRelationField;
55
55
  }>;
56
56
  //#endregion
57
57
  export { ApprovalCommentEntity, ApprovalDecisionEnum, ApprovalRequestEntity, ApprovalStatusEnum };
@@ -1 +1,128 @@
1
- import{i as e,n as t,r as n,t as r}from"../libs/schema/dist/entity/defineEntity.js";import"../libs/schema/dist/index.js";const i=t({name:`ApprovalStatus`,values:[`PENDING`,`APPROVED`,`REJECTED`,`DELEGATED`,`ESCALATED`,`WITHDRAWN`,`EXPIRED`],schema:`workflow`,description:`Status of an approval request.`}),a=t({name:`ApprovalDecision`,values:[`APPROVE`,`REJECT`,`REQUEST_CHANGES`,`DELEGATE`,`ABSTAIN`],schema:`workflow`,description:`Possible approval decisions.`}),o=r({name:`ApprovalRequest`,description:`A pending approval request for a workflow step.`,schema:`workflow`,map:`approval_request`,fields:{id:n.id({description:`Unique approval request ID`}),workflowInstanceId:n.foreignKey(),stepExecutionId:n.foreignKey(),approverId:n.foreignKey({description:`User requested to approve`}),approverRole:n.string({isOptional:!0,description:`Role of the approver`}),title:n.string({description:`Approval request title`}),description:n.string({isOptional:!0}),status:n.enum(`ApprovalStatus`,{default:`PENDING`}),decision:n.enum(`ApprovalDecision`,{isOptional:!0}),decisionComment:n.string({isOptional:!0,description:`Comment explaining decision`}),decidedAt:n.dateTime({isOptional:!0}),delegatedTo:n.string({isOptional:!0,description:`User delegated to`}),delegationReason:n.string({isOptional:!0}),escalationLevel:n.int({default:0,description:`Current escalation level`}),escalatedAt:n.dateTime({isOptional:!0}),dueAt:n.dateTime({isOptional:!0,description:`When approval is due`}),reminderSentAt:n.dateTime({isOptional:!0}),contextSnapshot:n.json({isOptional:!0,description:`Snapshot of relevant data for review`}),sequenceOrder:n.int({default:0,description:`Order in approval chain`}),createdAt:n.createdAt(),updatedAt:n.updatedAt(),workflowInstance:n.belongsTo(`WorkflowInstance`,[`workflowInstanceId`],[`id`],{onDelete:`Cascade`}),stepExecution:n.belongsTo(`StepExecution`,[`stepExecutionId`],[`id`])},indexes:[e.on([`approverId`,`status`]),e.on([`workflowInstanceId`,`status`]),e.on([`stepExecutionId`]),e.on([`status`,`dueAt`]),e.on([`createdAt`])],enums:[i,a]}),s=r({name:`ApprovalComment`,description:`A comment on an approval request.`,schema:`workflow`,map:`approval_comment`,fields:{id:n.id(),approvalRequestId:n.foreignKey(),authorId:n.foreignKey(),content:n.string({description:`Comment text`}),isInternal:n.boolean({default:!1,description:`Internal note vs public comment`}),createdAt:n.createdAt(),updatedAt:n.updatedAt(),approvalRequest:n.belongsTo(`ApprovalRequest`,[`approvalRequestId`],[`id`],{onDelete:`Cascade`})},indexes:[e.on([`approvalRequestId`,`createdAt`])]});export{s as ApprovalCommentEntity,a as ApprovalDecisionEnum,o as ApprovalRequestEntity,i as ApprovalStatusEnum};
1
+ import { defineEntity, defineEntityEnum, field, index } from "../libs/schema/dist/entity/defineEntity.js";
2
+ import "../libs/schema/dist/index.js";
3
+
4
+ //#region src/entities/approval.ts
5
+ /**
6
+ * Approval status enum.
7
+ */
8
+ const ApprovalStatusEnum = defineEntityEnum({
9
+ name: "ApprovalStatus",
10
+ values: [
11
+ "PENDING",
12
+ "APPROVED",
13
+ "REJECTED",
14
+ "DELEGATED",
15
+ "ESCALATED",
16
+ "WITHDRAWN",
17
+ "EXPIRED"
18
+ ],
19
+ schema: "workflow",
20
+ description: "Status of an approval request."
21
+ });
22
+ /**
23
+ * Approval decision enum.
24
+ */
25
+ const ApprovalDecisionEnum = defineEntityEnum({
26
+ name: "ApprovalDecision",
27
+ values: [
28
+ "APPROVE",
29
+ "REJECT",
30
+ "REQUEST_CHANGES",
31
+ "DELEGATE",
32
+ "ABSTAIN"
33
+ ],
34
+ schema: "workflow",
35
+ description: "Possible approval decisions."
36
+ });
37
+ /**
38
+ * ApprovalRequest entity - a request for approval from a user.
39
+ *
40
+ * Created when a workflow reaches an APPROVAL step. Multiple requests
41
+ * may be created depending on the approval mode.
42
+ */
43
+ const ApprovalRequestEntity = defineEntity({
44
+ name: "ApprovalRequest",
45
+ description: "A pending approval request for a workflow step.",
46
+ schema: "workflow",
47
+ map: "approval_request",
48
+ fields: {
49
+ id: field.id({ description: "Unique approval request ID" }),
50
+ workflowInstanceId: field.foreignKey(),
51
+ stepExecutionId: field.foreignKey(),
52
+ approverId: field.foreignKey({ description: "User requested to approve" }),
53
+ approverRole: field.string({
54
+ isOptional: true,
55
+ description: "Role of the approver"
56
+ }),
57
+ title: field.string({ description: "Approval request title" }),
58
+ description: field.string({ isOptional: true }),
59
+ status: field.enum("ApprovalStatus", { default: "PENDING" }),
60
+ decision: field.enum("ApprovalDecision", { isOptional: true }),
61
+ decisionComment: field.string({
62
+ isOptional: true,
63
+ description: "Comment explaining decision"
64
+ }),
65
+ decidedAt: field.dateTime({ isOptional: true }),
66
+ delegatedTo: field.string({
67
+ isOptional: true,
68
+ description: "User delegated to"
69
+ }),
70
+ delegationReason: field.string({ isOptional: true }),
71
+ escalationLevel: field.int({
72
+ default: 0,
73
+ description: "Current escalation level"
74
+ }),
75
+ escalatedAt: field.dateTime({ isOptional: true }),
76
+ dueAt: field.dateTime({
77
+ isOptional: true,
78
+ description: "When approval is due"
79
+ }),
80
+ reminderSentAt: field.dateTime({ isOptional: true }),
81
+ contextSnapshot: field.json({
82
+ isOptional: true,
83
+ description: "Snapshot of relevant data for review"
84
+ }),
85
+ sequenceOrder: field.int({
86
+ default: 0,
87
+ description: "Order in approval chain"
88
+ }),
89
+ createdAt: field.createdAt(),
90
+ updatedAt: field.updatedAt(),
91
+ workflowInstance: field.belongsTo("WorkflowInstance", ["workflowInstanceId"], ["id"], { onDelete: "Cascade" }),
92
+ stepExecution: field.belongsTo("StepExecution", ["stepExecutionId"], ["id"])
93
+ },
94
+ indexes: [
95
+ index.on(["approverId", "status"]),
96
+ index.on(["workflowInstanceId", "status"]),
97
+ index.on(["stepExecutionId"]),
98
+ index.on(["status", "dueAt"]),
99
+ index.on(["createdAt"])
100
+ ],
101
+ enums: [ApprovalStatusEnum, ApprovalDecisionEnum]
102
+ });
103
+ /**
104
+ * ApprovalComment entity - comments on approval requests.
105
+ */
106
+ const ApprovalCommentEntity = defineEntity({
107
+ name: "ApprovalComment",
108
+ description: "A comment on an approval request.",
109
+ schema: "workflow",
110
+ map: "approval_comment",
111
+ fields: {
112
+ id: field.id(),
113
+ approvalRequestId: field.foreignKey(),
114
+ authorId: field.foreignKey(),
115
+ content: field.string({ description: "Comment text" }),
116
+ isInternal: field.boolean({
117
+ default: false,
118
+ description: "Internal note vs public comment"
119
+ }),
120
+ createdAt: field.createdAt(),
121
+ updatedAt: field.updatedAt(),
122
+ approvalRequest: field.belongsTo("ApprovalRequest", ["approvalRequestId"], ["id"], { onDelete: "Cascade" })
123
+ },
124
+ indexes: [index.on(["approvalRequestId", "createdAt"])]
125
+ });
126
+
127
+ //#endregion
128
+ export { ApprovalCommentEntity, ApprovalDecisionEnum, ApprovalRequestEntity, ApprovalStatusEnum };