@fabricorg/platform 1.10.0 → 1.10.1

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/CHANGELOG.md +46 -0
  2. package/README.md +31 -2
  3. package/dist/actions/index.cjs +45 -26
  4. package/dist/actions/index.cjs.map +1 -1
  5. package/dist/actions/index.d.cts +225 -226
  6. package/dist/actions/index.d.ts +225 -226
  7. package/dist/actions/index.js +41 -2
  8. package/dist/actions/index.js.map +1 -1
  9. package/dist/adapters/index.cjs +696 -66
  10. package/dist/adapters/index.cjs.map +1 -1
  11. package/dist/adapters/index.d.cts +367 -365
  12. package/dist/adapters/index.d.ts +367 -365
  13. package/dist/adapters/index.js +682 -2
  14. package/dist/adapters/index.js.map +1 -1
  15. package/dist/agent-hitl/index.cjs +21 -10
  16. package/dist/agent-hitl/index.cjs.map +1 -1
  17. package/dist/agent-hitl/index.d.cts +30 -30
  18. package/dist/agent-hitl/index.d.ts +30 -30
  19. package/dist/agent-hitl/index.js +21 -2
  20. package/dist/agent-hitl/index.js.map +1 -1
  21. package/dist/certification/index.cjs +109 -24
  22. package/dist/certification/index.cjs.map +1 -1
  23. package/dist/certification/index.d.cts +33 -39
  24. package/dist/certification/index.d.ts +33 -39
  25. package/dist/certification/index.js +107 -8
  26. package/dist/certification/index.js.map +1 -1
  27. package/dist/discovery/index.cjs +12 -10
  28. package/dist/discovery/index.cjs.map +1 -1
  29. package/dist/discovery/index.d.cts +2 -10
  30. package/dist/discovery/index.d.ts +2 -10
  31. package/dist/discovery/index.js +12 -2
  32. package/dist/discovery/index.js.map +1 -1
  33. package/dist/engine-B4csEOEc.js +223 -0
  34. package/dist/engine-B4csEOEc.js.map +1 -0
  35. package/dist/engine-BqScuhrT.cjs +246 -0
  36. package/dist/engine-BqScuhrT.cjs.map +1 -0
  37. package/dist/events/index.cjs +39 -10
  38. package/dist/events/index.cjs.map +1 -1
  39. package/dist/events/index.d.cts +43 -43
  40. package/dist/events/index.d.ts +43 -43
  41. package/dist/events/index.js +39 -2
  42. package/dist/events/index.js.map +1 -1
  43. package/dist/evidence/index.cjs +12 -50
  44. package/dist/evidence/index.d.cts +2 -229
  45. package/dist/evidence/index.d.ts +2 -229
  46. package/dist/evidence/index.js +1 -5
  47. package/dist/evidence-BuCICb0c.js +516 -0
  48. package/dist/evidence-BuCICb0c.js.map +1 -0
  49. package/dist/evidence-Cq48eDvA.cjs +575 -0
  50. package/dist/evidence-Cq48eDvA.cjs.map +1 -0
  51. package/dist/governance/index.cjs +24 -18
  52. package/dist/governance/index.cjs.map +1 -1
  53. package/dist/governance/index.d.cts +80 -83
  54. package/dist/governance/index.d.ts +80 -83
  55. package/dist/governance/index.js +22 -2
  56. package/dist/governance/index.js.map +1 -1
  57. package/dist/ids/index.cjs +52 -22
  58. package/dist/ids/index.cjs.map +1 -1
  59. package/dist/ids/index.d.cts +17 -17
  60. package/dist/ids/index.d.ts +17 -17
  61. package/dist/ids/index.js +49 -2
  62. package/dist/ids/index.js.map +1 -1
  63. package/dist/index-9jasmw76.d.cts +124 -0
  64. package/dist/index-BXpeFdk2.d.cts +190 -0
  65. package/dist/index-BXpeFdk2.d.ts +190 -0
  66. package/dist/index-BnbsKZsT.d.cts +231 -0
  67. package/dist/index-CIl1rYRv.d.cts +11 -0
  68. package/dist/index-CIl1rYRv.d.ts +11 -0
  69. package/dist/index-CVHA1ypT.d.cts +262 -0
  70. package/dist/index-DZ4mnNb7.d.cts +78 -0
  71. package/dist/index-DZ4mnNb7.d.ts +78 -0
  72. package/dist/index-IqcDvl69.d.ts +124 -0
  73. package/dist/index-fmUiRBXu.d.cts +57 -0
  74. package/dist/index-fmUiRBXu.d.ts +57 -0
  75. package/dist/index-sPUPs8pr.d.ts +262 -0
  76. package/dist/index-z9-CYOIo.d.ts +231 -0
  77. package/dist/index.cjs +111 -393
  78. package/dist/index.d.cts +18 -17
  79. package/dist/index.d.ts +18 -17
  80. package/dist/index.js +19 -20
  81. package/dist/manifest/index.cjs +224 -35
  82. package/dist/manifest/index.cjs.map +1 -1
  83. package/dist/manifest/index.d.cts +130 -131
  84. package/dist/manifest/index.d.ts +130 -131
  85. package/dist/manifest/index.js +219 -7
  86. package/dist/manifest/index.js.map +1 -1
  87. package/dist/modules/index.cjs +281 -42
  88. package/dist/modules/index.cjs.map +1 -1
  89. package/dist/modules/index.d.cts +157 -159
  90. package/dist/modules/index.d.ts +157 -159
  91. package/dist/modules/index.js +274 -6
  92. package/dist/modules/index.js.map +1 -1
  93. package/dist/objects/index.cjs +355 -22
  94. package/dist/objects/index.cjs.map +1 -1
  95. package/dist/objects/index.d.cts +2 -77
  96. package/dist/objects/index.d.ts +2 -77
  97. package/dist/objects/index.js +352 -2
  98. package/dist/objects/index.js.map +1 -1
  99. package/dist/policies/index.cjs +14 -56
  100. package/dist/policies/index.d.cts +2 -261
  101. package/dist/policies/index.d.ts +2 -261
  102. package/dist/policies/index.js +1 -3
  103. package/dist/policies-DH_GCXQ-.js +627 -0
  104. package/dist/policies-DH_GCXQ-.js.map +1 -0
  105. package/dist/policies-Nxbp1CH8.cjs +698 -0
  106. package/dist/policies-Nxbp1CH8.cjs.map +1 -0
  107. package/dist/privacy/index.cjs +26 -43
  108. package/dist/privacy/index.cjs.map +1 -1
  109. package/dist/privacy/index.d.cts +2 -189
  110. package/dist/privacy/index.d.ts +2 -189
  111. package/dist/privacy/index.js +18 -3
  112. package/dist/privacy/index.js.map +1 -1
  113. package/dist/projections/index.cjs +241 -23
  114. package/dist/projections/index.cjs.map +1 -1
  115. package/dist/projections/index.d.cts +2 -125
  116. package/dist/projections/index.d.ts +2 -125
  117. package/dist/projections/index.js +238 -3
  118. package/dist/projections/index.js.map +1 -1
  119. package/dist/state-machines/index.cjs +76 -18
  120. package/dist/state-machines/index.cjs.map +1 -1
  121. package/dist/state-machines/index.d.cts +2 -55
  122. package/dist/state-machines/index.d.ts +2 -55
  123. package/dist/state-machines/index.js +74 -2
  124. package/dist/state-machines/index.js.map +1 -1
  125. package/dist/testing/index.cjs +27 -19
  126. package/dist/testing/index.cjs.map +1 -1
  127. package/dist/testing/index.d.cts +17 -19
  128. package/dist/testing/index.d.ts +17 -19
  129. package/dist/testing/index.js +25 -3
  130. package/dist/testing/index.js.map +1 -1
  131. package/package.json +6 -5
  132. package/dist/chunk-2AE6TMAX.cjs +0 -44
  133. package/dist/chunk-2AE6TMAX.cjs.map +0 -1
  134. package/dist/chunk-6HY35TKB.cjs +0 -491
  135. package/dist/chunk-6HY35TKB.cjs.map +0 -1
  136. package/dist/chunk-6UGEIDLC.cjs +0 -26
  137. package/dist/chunk-6UGEIDLC.cjs.map +0 -1
  138. package/dist/chunk-7GAWSUOG.js +0 -64
  139. package/dist/chunk-7GAWSUOG.js.map +0 -1
  140. package/dist/chunk-A42JJIPL.cjs +0 -699
  141. package/dist/chunk-A42JJIPL.cjs.map +0 -1
  142. package/dist/chunk-AFXKSIVI.cjs +0 -540
  143. package/dist/chunk-AFXKSIVI.cjs.map +0 -1
  144. package/dist/chunk-B5DOGDPG.js +0 -42
  145. package/dist/chunk-B5DOGDPG.js.map +0 -1
  146. package/dist/chunk-BJGZE3GE.js +0 -20
  147. package/dist/chunk-BJGZE3GE.js.map +0 -1
  148. package/dist/chunk-CRZXTZ36.cjs +0 -258
  149. package/dist/chunk-CRZXTZ36.cjs.map +0 -1
  150. package/dist/chunk-D4SWRBUH.cjs +0 -22
  151. package/dist/chunk-D4SWRBUH.cjs.map +0 -1
  152. package/dist/chunk-DBTAUI6C.cjs +0 -395
  153. package/dist/chunk-DBTAUI6C.cjs.map +0 -1
  154. package/dist/chunk-EMSAFNPX.js +0 -98
  155. package/dist/chunk-EMSAFNPX.js.map +0 -1
  156. package/dist/chunk-F3E5SXPN.cjs +0 -28
  157. package/dist/chunk-F3E5SXPN.cjs.map +0 -1
  158. package/dist/chunk-HEYMMVDP.js +0 -480
  159. package/dist/chunk-HEYMMVDP.js.map +0 -1
  160. package/dist/chunk-IFW43ELT.cjs +0 -331
  161. package/dist/chunk-IFW43ELT.cjs.map +0 -1
  162. package/dist/chunk-LFE74IJX.js +0 -20
  163. package/dist/chunk-LFE74IJX.js.map +0 -1
  164. package/dist/chunk-LZSE6QGQ.cjs +0 -60
  165. package/dist/chunk-LZSE6QGQ.cjs.map +0 -1
  166. package/dist/chunk-MCWSUGB3.cjs +0 -102
  167. package/dist/chunk-MCWSUGB3.cjs.map +0 -1
  168. package/dist/chunk-MLBALEUR.js +0 -290
  169. package/dist/chunk-MLBALEUR.js.map +0 -1
  170. package/dist/chunk-NNXQZPB3.cjs +0 -31
  171. package/dist/chunk-NNXQZPB3.cjs.map +0 -1
  172. package/dist/chunk-OFCCZ27Z.js +0 -26
  173. package/dist/chunk-OFCCZ27Z.js.map +0 -1
  174. package/dist/chunk-PDN5DOLQ.js +0 -242
  175. package/dist/chunk-PDN5DOLQ.js.map +0 -1
  176. package/dist/chunk-PIDZQAEL.js +0 -50
  177. package/dist/chunk-PIDZQAEL.js.map +0 -1
  178. package/dist/chunk-PXD7NG6X.js +0 -686
  179. package/dist/chunk-PXD7NG6X.js.map +0 -1
  180. package/dist/chunk-Q4Q4JPR3.js +0 -524
  181. package/dist/chunk-Q4Q4JPR3.js.map +0 -1
  182. package/dist/chunk-RALMUSOX.js +0 -55
  183. package/dist/chunk-RALMUSOX.js.map +0 -1
  184. package/dist/chunk-SNTV45LH.cjs +0 -295
  185. package/dist/chunk-SNTV45LH.cjs.map +0 -1
  186. package/dist/chunk-TBS2S5AX.cjs +0 -40
  187. package/dist/chunk-TBS2S5AX.cjs.map +0 -1
  188. package/dist/chunk-TYNIFC7J.js +0 -253
  189. package/dist/chunk-TYNIFC7J.js.map +0 -1
  190. package/dist/chunk-UGWGHTNC.cjs +0 -56
  191. package/dist/chunk-UGWGHTNC.cjs.map +0 -1
  192. package/dist/chunk-WI7CWNYI.cjs +0 -68
  193. package/dist/chunk-WI7CWNYI.cjs.map +0 -1
  194. package/dist/chunk-WNZP53GI.js +0 -386
  195. package/dist/chunk-WNZP53GI.js.map +0 -1
  196. package/dist/chunk-WQ3BYI7T.cjs +0 -249
  197. package/dist/chunk-WQ3BYI7T.cjs.map +0 -1
  198. package/dist/chunk-Y2PJLRIY.js +0 -36
  199. package/dist/chunk-Y2PJLRIY.js.map +0 -1
  200. package/dist/chunk-ZAEVQSB5.js +0 -326
  201. package/dist/chunk-ZAEVQSB5.js.map +0 -1
  202. package/dist/chunk-ZMQTV5OJ.js +0 -27
  203. package/dist/chunk-ZMQTV5OJ.js.map +0 -1
  204. package/dist/evidence/index.cjs.map +0 -1
  205. package/dist/evidence/index.js.map +0 -1
  206. package/dist/index.cjs.map +0 -1
  207. package/dist/index.js.map +0 -1
  208. package/dist/policies/index.cjs.map +0 -1
  209. package/dist/policies/index.js.map +0 -1
@@ -1,686 +0,0 @@
1
- // policies/reconciliation-required.ts
2
- var ReconciliationRequiredError = class extends Error {
3
- name = "ReconciliationRequiredError";
4
- code = "EXECUTION_RECONCILIATION_REQUIRED";
5
- constructor(message, options) {
6
- super(message, options);
7
- }
8
- };
9
- function isReconciliationRequiredError(error) {
10
- if (error instanceof ReconciliationRequiredError) return true;
11
- return typeof error === "object" && error !== null && error.name === "ReconciliationRequiredError" && error.code === "EXECUTION_RECONCILIATION_REQUIRED";
12
- }
13
-
14
- // policies/retryable-execution.ts
15
- var RetryableExecutionError = class extends Error {
16
- name = "RetryableExecutionError";
17
- code = "EXECUTION_RETRYABLE";
18
- constructor(message, options) {
19
- super(message, options);
20
- }
21
- };
22
- function isRetryableExecutionError(error) {
23
- if (error instanceof RetryableExecutionError) return true;
24
- return typeof error === "object" && error !== null && error.name === "RetryableExecutionError" && error.code === "EXECUTION_RETRYABLE";
25
- }
26
-
27
- // policies/index.ts
28
- function assertPolicyId(policyId) {
29
- if (!/^[a-z][a-z0-9_-]*(\.[a-z][a-z0-9_-]*)*\.v[0-9]+$/.test(policyId)) {
30
- throw new Error(`Invalid policy ID: ${policyId}`);
31
- }
32
- }
33
- function validatePolicyGuidance(guidance) {
34
- const errors = [];
35
- if (!isPlainRecord(guidance)) {
36
- return { valid: false, errors: ["guidance must be an object"] };
37
- }
38
- if (guidance.summary !== void 0 && typeof guidance.summary !== "string") {
39
- errors.push("guidance.summary must be a string when present");
40
- }
41
- if (!Array.isArray(guidance.factsUsed)) {
42
- errors.push("guidance.factsUsed must be an array");
43
- } else {
44
- guidance.factsUsed.forEach((fact, index) => {
45
- if (!isPlainRecord(fact)) {
46
- errors.push(`guidance.factsUsed[${index}] must be an object`);
47
- return;
48
- }
49
- if (typeof fact.name !== "string" || fact.name.length === 0) {
50
- errors.push(`guidance.factsUsed[${index}].name must be a non-empty string`);
51
- }
52
- if (fact.label !== void 0 && typeof fact.label !== "string") {
53
- errors.push(`guidance.factsUsed[${index}].label must be a string when present`);
54
- }
55
- });
56
- }
57
- if (!Array.isArray(guidance.correctiveActions)) {
58
- errors.push("guidance.correctiveActions must be an array");
59
- } else {
60
- guidance.correctiveActions.forEach((action, index) => {
61
- errors.push(...validatePolicyCorrectiveAction(action, index));
62
- });
63
- }
64
- return { valid: errors.length === 0, errors };
65
- }
66
- function validatePolicyCorrectiveAction(action, index) {
67
- const errors = [];
68
- const prefix = `guidance.correctiveActions[${index}]`;
69
- if (!isPlainRecord(action)) {
70
- return [`${prefix} must be an object`];
71
- }
72
- if (action.kind !== "invoke_action" && action.kind !== "navigate" && action.kind !== "manual") {
73
- errors.push(`${prefix}.kind must be "invoke_action" | "navigate" | "manual"`);
74
- }
75
- if (typeof action.label !== "string" || action.label.length === 0) {
76
- errors.push(`${prefix}.label must be a non-empty string`);
77
- }
78
- if (action.description !== void 0 && typeof action.description !== "string") {
79
- errors.push(`${prefix}.description must be a string when present`);
80
- }
81
- if (action.requiresConfirmation !== void 0 && typeof action.requiresConfirmation !== "boolean") {
82
- errors.push(`${prefix}.requiresConfirmation must be a boolean when present`);
83
- }
84
- if (action.requiresRole !== void 0) {
85
- if (!Array.isArray(action.requiresRole)) {
86
- errors.push(`${prefix}.requiresRole must be an array when present`);
87
- } else if (action.requiresRole.some((role) => typeof role !== "string" || role.length === 0)) {
88
- errors.push(`${prefix}.requiresRole must contain only non-empty strings`);
89
- }
90
- }
91
- if (action.kind === "invoke_action") {
92
- if (typeof action.actionId !== "string" || action.actionId.length === 0) {
93
- errors.push(`${prefix}.actionId must be a non-empty string for invoke_action`);
94
- }
95
- if (action.parameters !== void 0 && !isPlainRecord(action.parameters)) {
96
- errors.push(`${prefix}.parameters must be an object when present`);
97
- }
98
- }
99
- if (action.kind === "navigate") {
100
- if (action.route !== void 0 && typeof action.route !== "string") {
101
- errors.push(`${prefix}.route must be a string when present`);
102
- }
103
- if (action.target !== void 0 && !isPlainRecord(action.target)) {
104
- errors.push(`${prefix}.target must be an object when present`);
105
- }
106
- }
107
- return errors;
108
- }
109
- function isPlainRecord(value) {
110
- return value !== null && typeof value === "object" && !Array.isArray(value);
111
- }
112
- var DATA_POLICY_MAX_DEPTH = 5;
113
- var DATA_POLICY_MAX_CONDITIONS_PER_NODE = 20;
114
- var DATA_POLICY_MAX_TOTAL_CONDITIONS = 100;
115
- var DATA_POLICY_MAX_PATH_SEGMENTS = 12;
116
- var DATA_POLICY_MAX_STRING_LENGTH = 500;
117
- var DATA_POLICY_CONTEXT_PATHS = Object.freeze([
118
- "tenantId",
119
- "spaceId",
120
- "actionInvocationId",
121
- "actionId",
122
- "mode"
123
- ]);
124
- var DATA_POLICY_COMPARISON_OPERATORS = Object.freeze([
125
- "exists",
126
- "equals",
127
- "notEquals",
128
- "gt",
129
- "gte",
130
- "lt",
131
- "lte"
132
- ]);
133
- var POLICY_RESULTS = Object.freeze(["pass", "warn", "block"]);
134
- function createPolicyRegistry(evaluators = []) {
135
- const policies = /* @__PURE__ */ new Map();
136
- const register = (evaluator) => {
137
- assertPolicyId(evaluator.policyId);
138
- const existing = policies.get(evaluator.policyId);
139
- if (existing && existing !== evaluator) throw new Error(`Conflicting policy registration for "${evaluator.policyId}". A different evaluator is already registered.`);
140
- policies.set(evaluator.policyId, evaluator);
141
- };
142
- for (const evaluator of evaluators) register(evaluator);
143
- return {
144
- register,
145
- registerIfMissing(evaluator) {
146
- const existing = policies.get(evaluator.policyId);
147
- if (!existing) register(evaluator);
148
- else if (existing !== evaluator) throw new Error(`Conflicting policy registration for "${evaluator.policyId}". A different evaluator is already registered.`);
149
- },
150
- resolve: (policyId) => policies.get(policyId),
151
- ids: () => Array.from(policies.keys())
152
- };
153
- }
154
- async function evaluateRegisteredPolicies(policyIds, ctx) {
155
- return evaluatePolicyDefinitions(
156
- policyIds.map((policyId) => ({
157
- policyId,
158
- policyVersion: parsePolicyVersion(policyId),
159
- kind: "code",
160
- codeEvaluatorPolicyId: policyId
161
- })),
162
- ctx
163
- );
164
- }
165
- async function evaluatePolicyDefinitions(policies, ctx) {
166
- const outcomes = [];
167
- for (const policy of policies) {
168
- assertPolicyId(policy.policyId);
169
- outcomes.push(await evaluatePolicyDefinition(policy, ctx));
170
- }
171
- return outcomes;
172
- }
173
- async function evaluatePolicyDefinition(policy, ctx) {
174
- const authority = policy.authority ? { ...policy.authority } : void 0;
175
- const outcome = policy.kind === "data" ? await evaluateDataPolicy(policy, ctx) : policy.kind === "code" ? await evaluateCodePolicy(policy, ctx) : await evaluateHybridPolicy(policy, ctx);
176
- if (!authority) return outcome;
177
- return {
178
- ...outcome,
179
- dispatchEvidence: {
180
- ...outcome.dispatchEvidence ?? {
181
- policyKind: policy.kind,
182
- policyId: policy.policyId,
183
- policyVersion: policy.policyVersion,
184
- dispatchPath: []
185
- },
186
- authority
187
- }
188
- };
189
- }
190
- async function evaluateCodePolicy(policy, ctx) {
191
- const codeEvaluatorPolicyId = policy.codeEvaluatorPolicyId ?? policy.policyId;
192
- const evaluator = ctx.resolveCodePolicy?.(codeEvaluatorPolicyId);
193
- if (!evaluator) {
194
- return {
195
- policyId: policy.policyId,
196
- policyVersion: policy.policyVersion,
197
- policyKind: policy.kind,
198
- result: "block",
199
- reason: `No evaluator registered for policy ${codeEvaluatorPolicyId}`,
200
- metadata: {
201
- missingCodeEvaluatorPolicyId: codeEvaluatorPolicyId
202
- },
203
- dispatchEvidence: {
204
- policyKind: policy.kind,
205
- policyId: policy.policyId,
206
- policyVersion: policy.policyVersion,
207
- dispatchPath: ["code"],
208
- code: {
209
- requestedPolicyId: codeEvaluatorPolicyId,
210
- policyId: codeEvaluatorPolicyId,
211
- registered: false
212
- }
213
- }
214
- };
215
- }
216
- if (ctx.mode === "preview" && evaluator.previewSafe !== true) {
217
- const skipReason = `Policy ${evaluator.policyId} skipped in preview mode (evaluator is not declared previewSafe)`;
218
- return {
219
- policyId: policy.policyId,
220
- policyVersion: policy.policyVersion,
221
- policyKind: policy.kind,
222
- result: "warn",
223
- reason: skipReason,
224
- metadata: {
225
- codePolicyId: evaluator.policyId,
226
- codePolicyVersion: evaluator.version,
227
- previewSkipped: true
228
- },
229
- dispatchEvidence: {
230
- policyKind: policy.kind,
231
- policyId: policy.policyId,
232
- policyVersion: policy.policyVersion,
233
- dispatchPath: ["code"],
234
- code: {
235
- requestedPolicyId: codeEvaluatorPolicyId,
236
- policyId: evaluator.policyId,
237
- version: evaluator.version,
238
- registered: true,
239
- skipped: true,
240
- skipReason
241
- }
242
- }
243
- };
244
- }
245
- const outcome = await evaluator.evaluate(ctx);
246
- return normalizeOutcome(policy, outcome, {
247
- policyKind: policy.kind,
248
- policyId: policy.policyId,
249
- policyVersion: policy.policyVersion,
250
- dispatchPath: ["code"],
251
- code: {
252
- requestedPolicyId: codeEvaluatorPolicyId,
253
- policyId: evaluator.policyId,
254
- version: evaluator.version,
255
- registered: true
256
- }
257
- });
258
- }
259
- async function evaluateHybridPolicy(policy, ctx) {
260
- const dataOutcome = evaluateDataPolicy(policy, ctx);
261
- const fallback = policy.fallback;
262
- const fallbackDecision = fallback ? resolveFallbackDecision(policy, dataOutcome, fallback) : { shouldFallback: false, trigger: "not_triggered" };
263
- if (!fallback || !fallbackDecision.shouldFallback) {
264
- if (fallback && dataOutcome.dispatchEvidence) {
265
- return {
266
- ...dataOutcome,
267
- dispatchEvidence: {
268
- ...dataOutcome.dispatchEvidence,
269
- fallback: {
270
- used: false,
271
- trigger: "not_triggered",
272
- reason: "Data policy result did not trigger fallback",
273
- fromResult: dataOutcome.result,
274
- definitionVersion: policy.policyVersion,
275
- codeEvaluatorPolicyId: fallback.codeEvaluatorPolicyId
276
- }
277
- }
278
- };
279
- }
280
- return dataOutcome;
281
- }
282
- const codePolicy = {
283
- policyId: policy.policyId,
284
- policyVersion: policy.policyVersion,
285
- kind: "hybrid",
286
- codeEvaluatorPolicyId: fallback.codeEvaluatorPolicyId
287
- };
288
- const codeOutcome = await evaluateCodePolicy(codePolicy, ctx);
289
- return normalizeOutcome(policy, codeOutcome, {
290
- ...codeOutcome.dispatchEvidence ?? {
291
- policyKind: "hybrid",
292
- policyId: policy.policyId,
293
- policyVersion: policy.policyVersion,
294
- dispatchPath: ["code"]
295
- },
296
- policyKind: "hybrid",
297
- policyId: policy.policyId,
298
- policyVersion: policy.policyVersion,
299
- dispatchPath: ["data", "fallback", "code"],
300
- data: dataOutcome.dispatchEvidence?.data,
301
- fallback: {
302
- used: true,
303
- trigger: fallbackDecision.trigger,
304
- reason: fallback.reason ?? "Data policy result triggered code fallback",
305
- fromResult: dataOutcome.result,
306
- definitionVersion: policy.policyVersion,
307
- codeEvaluatorPolicyId: fallback.codeEvaluatorPolicyId
308
- }
309
- });
310
- }
311
- function resolveFallbackDecision(policy, dataOutcome, fallback) {
312
- const allowedTriggers = fallback.triggers ?? [
313
- "data_result",
314
- "missing_data_definition",
315
- "invalid_data_definition"
316
- ];
317
- const definitionStatus = dataOutcome.dispatchEvidence?.data?.definitionStatus;
318
- if (definitionStatus === "missing") {
319
- return {
320
- shouldFallback: allowedTriggers.includes("missing_data_definition"),
321
- trigger: "missing_data_definition"
322
- };
323
- }
324
- if (definitionStatus === "invalid") {
325
- return {
326
- shouldFallback: allowedTriggers.includes("invalid_data_definition"),
327
- trigger: "invalid_data_definition"
328
- };
329
- }
330
- const fallbackResults = fallback.onResults ?? ["warn", "block"];
331
- return {
332
- shouldFallback: policy.kind === "hybrid" && allowedTriggers.includes("data_result") && fallbackResults.includes(dataOutcome.result),
333
- trigger: "data_result"
334
- };
335
- }
336
- function evaluateDataPolicy(policy, ctx) {
337
- const definition = policy.dataDefinition;
338
- if (!definition) {
339
- return {
340
- policyId: policy.policyId,
341
- policyVersion: policy.policyVersion,
342
- policyKind: policy.kind,
343
- result: "block",
344
- reason: "Data policy definition is missing",
345
- dispatchEvidence: {
346
- policyKind: policy.kind,
347
- policyId: policy.policyId,
348
- policyVersion: policy.policyVersion,
349
- dispatchPath: ["data"],
350
- data: {
351
- definitionVersion: policy.policyVersion,
352
- definitionStatus: "missing",
353
- conditionResults: []
354
- }
355
- }
356
- };
357
- }
358
- const validation = validateDataPolicyDefinition(definition);
359
- if (!validation.valid) {
360
- return {
361
- policyId: policy.policyId,
362
- policyVersion: policy.policyVersion,
363
- policyKind: policy.kind,
364
- result: "block",
365
- reason: `Invalid data policy definition: ${validation.errors.join("; ")}`,
366
- metadata: {
367
- validationErrors: validation.errors
368
- },
369
- dispatchEvidence: {
370
- policyKind: policy.kind,
371
- policyId: policy.policyId,
372
- policyVersion: policy.policyVersion,
373
- dispatchPath: ["data"],
374
- data: {
375
- definitionVersion: policy.policyVersion,
376
- definitionStatus: "invalid",
377
- conditionResults: [],
378
- validationErrors: validation.errors
379
- }
380
- }
381
- };
382
- }
383
- const evaluations = definition.conditions.map((condition) => evaluateDataPolicyCondition(condition, ctx));
384
- const conditionResults = evaluations.flatMap((evaluation) => evaluation.evidence);
385
- const topLevelResults = evaluations.map((evaluation) => evaluation.result);
386
- const aggregate = topLevelResults.find((result2) => result2.result === "block") ?? topLevelResults.find((result2) => result2.result === "warn");
387
- const result = aggregate?.result ?? definition.defaultResult ?? "pass";
388
- return {
389
- policyId: policy.policyId,
390
- policyVersion: policy.policyVersion,
391
- policyKind: policy.kind,
392
- result,
393
- reason: aggregate?.reason ?? definition.reason,
394
- metadata: {
395
- conditionCount: definition.conditions.length,
396
- failedConditionId: aggregate?.conditionId
397
- },
398
- dispatchEvidence: {
399
- policyKind: policy.kind,
400
- policyId: policy.policyId,
401
- policyVersion: policy.policyVersion,
402
- dispatchPath: ["data"],
403
- data: {
404
- definitionVersion: policy.policyVersion,
405
- definitionStatus: "evaluated",
406
- conditionResults
407
- }
408
- }
409
- };
410
- }
411
- function validateDataPolicyDefinition(definition) {
412
- const errors = [];
413
- if (!Array.isArray(definition.conditions) || definition.conditions.length === 0) {
414
- errors.push("conditions must contain at least one condition");
415
- } else if (definition.conditions.length > DATA_POLICY_MAX_CONDITIONS_PER_NODE) {
416
- errors.push(
417
- `conditions must contain at most ${DATA_POLICY_MAX_CONDITIONS_PER_NODE} top-level conditions`
418
- );
419
- }
420
- if (definition.defaultResult && !POLICY_RESULTS.includes(definition.defaultResult)) {
421
- errors.push("defaultResult must be pass, warn, or block");
422
- }
423
- let totalConditions = 0;
424
- for (const condition of definition.conditions ?? []) {
425
- validateDataPolicyCondition(condition, errors, 1, () => {
426
- totalConditions += 1;
427
- });
428
- }
429
- if (totalConditions > DATA_POLICY_MAX_TOTAL_CONDITIONS) {
430
- errors.push(`policy must contain at most ${DATA_POLICY_MAX_TOTAL_CONDITIONS} total conditions`);
431
- }
432
- return { valid: errors.length === 0, errors };
433
- }
434
- function validateDataPolicyCondition(condition, errors, depth, count) {
435
- count();
436
- if (!condition || typeof condition !== "object") {
437
- errors.push("condition must be an object");
438
- return;
439
- }
440
- if (depth > DATA_POLICY_MAX_DEPTH) {
441
- errors.push(`condition depth must not exceed ${DATA_POLICY_MAX_DEPTH}`);
442
- return;
443
- }
444
- if (!isNonEmptyBoundedString(condition.conditionId)) {
445
- errors.push("conditionId must be a non-empty bounded string");
446
- }
447
- validateOptionalPolicyResult("onPass" in condition ? condition.onPass : void 0, "onPass", errors);
448
- validateOptionalPolicyResult("onFail" in condition ? condition.onFail : void 0, "onFail", errors);
449
- if (condition.reason !== void 0 && !isNonEmptyBoundedString(condition.reason)) {
450
- errors.push(`condition ${condition.conditionId} reason must be a bounded string`);
451
- }
452
- if (condition.type === "always") {
453
- if (!POLICY_RESULTS.includes(condition.result)) {
454
- errors.push(`condition ${condition.conditionId} result must be pass, warn, or block`);
455
- }
456
- return;
457
- }
458
- if (condition.type === "parameter") {
459
- validatePath(condition.path, `condition ${condition.conditionId} path`, errors);
460
- validateComparison(condition.operator, condition.value, condition.conditionId, errors);
461
- return;
462
- }
463
- if (condition.type === "comparison") {
464
- validateSourceReference(condition.left, condition.conditionId, errors);
465
- validateComparison(condition.operator, condition.value, condition.conditionId, errors);
466
- return;
467
- }
468
- if (condition.type === "all" || condition.type === "any") {
469
- if (!Array.isArray(condition.conditions) || condition.conditions.length === 0) {
470
- errors.push(`condition ${condition.conditionId} must contain child conditions`);
471
- return;
472
- }
473
- if (condition.conditions.length > DATA_POLICY_MAX_CONDITIONS_PER_NODE) {
474
- errors.push(
475
- `condition ${condition.conditionId} must contain at most ${DATA_POLICY_MAX_CONDITIONS_PER_NODE} child conditions`
476
- );
477
- }
478
- for (const child of condition.conditions) {
479
- validateDataPolicyCondition(child, errors, depth + 1, count);
480
- }
481
- return;
482
- }
483
- if (condition.type === "not") {
484
- validateDataPolicyCondition(condition.condition, errors, depth + 1, count);
485
- return;
486
- }
487
- errors.push(`condition ${condition.conditionId} has unsupported type`);
488
- }
489
- function validateOptionalPolicyResult(result, fieldName, errors) {
490
- if (result !== void 0 && !POLICY_RESULTS.includes(result)) {
491
- errors.push(`${fieldName} must be pass, warn, or block`);
492
- }
493
- }
494
- function validateSourceReference(reference, conditionId, errors) {
495
- if (!reference || typeof reference !== "object") {
496
- errors.push(`condition ${conditionId} left must be a source reference`);
497
- return;
498
- }
499
- if (reference.source !== "parameters" && reference.source !== "context") {
500
- errors.push(`condition ${conditionId} source must be parameters or context`);
501
- }
502
- validatePath(reference.path, `condition ${conditionId} left.path`, errors);
503
- if (reference.source === "context" && !DATA_POLICY_CONTEXT_PATHS.includes(reference.path)) {
504
- errors.push(`condition ${conditionId} uses an unsupported context path`);
505
- }
506
- }
507
- function validateComparison(operator, value, conditionId, errors) {
508
- if (!DATA_POLICY_COMPARISON_OPERATORS.includes(operator)) {
509
- errors.push(`condition ${conditionId} has unsupported operator`);
510
- return;
511
- }
512
- if (operator === "exists") {
513
- return;
514
- }
515
- if (!isDataPolicyLiteral(value)) {
516
- errors.push(`condition ${conditionId} comparison value must be a bounded literal`);
517
- return;
518
- }
519
- if (["gt", "gte", "lt", "lte"].includes(operator) && typeof value !== "number") {
520
- errors.push(`condition ${conditionId} numeric comparison requires a number value`);
521
- }
522
- }
523
- function validatePath(path, fieldName, errors) {
524
- if (!isNonEmptyBoundedString(path)) {
525
- errors.push(`${fieldName} must be a non-empty bounded string`);
526
- return;
527
- }
528
- const segments = path.split(".");
529
- if (segments.length > DATA_POLICY_MAX_PATH_SEGMENTS) {
530
- errors.push(`${fieldName} must contain at most ${DATA_POLICY_MAX_PATH_SEGMENTS} segments`);
531
- return;
532
- }
533
- for (const segment of segments) {
534
- if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(segment)) {
535
- errors.push(`${fieldName} contains an invalid path segment`);
536
- return;
537
- }
538
- if (["__proto__", "constructor", "prototype"].includes(segment)) {
539
- errors.push(`${fieldName} contains a forbidden path segment`);
540
- return;
541
- }
542
- }
543
- }
544
- function isDataPolicyLiteral(value) {
545
- if (value === null || typeof value === "number" || typeof value === "boolean") {
546
- return true;
547
- }
548
- return typeof value === "string" && value.length <= DATA_POLICY_MAX_STRING_LENGTH;
549
- }
550
- function isNonEmptyBoundedString(value) {
551
- return typeof value === "string" && value.length > 0 && value.length <= DATA_POLICY_MAX_STRING_LENGTH;
552
- }
553
- function evaluateDataPolicyCondition(condition, ctx) {
554
- if (condition.type === "always") {
555
- const result2 = {
556
- conditionId: condition.conditionId,
557
- passed: condition.result === "pass",
558
- result: condition.result,
559
- reason: condition.reason
560
- };
561
- return { result: result2, evidence: [result2] };
562
- }
563
- if (condition.type === "all" || condition.type === "any") {
564
- const childEvaluations = condition.conditions.map((child) => evaluateDataPolicyCondition(child, ctx));
565
- const passed2 = condition.type === "all" ? childEvaluations.every((evaluation) => evaluation.result.passed) : childEvaluations.some((evaluation) => evaluation.result.passed);
566
- const result2 = {
567
- conditionId: condition.conditionId,
568
- passed: passed2,
569
- result: passed2 ? condition.onPass ?? "pass" : condition.onFail ?? "block",
570
- reason: passed2 ? void 0 : condition.reason
571
- };
572
- return {
573
- result: result2,
574
- evidence: [result2, ...childEvaluations.flatMap((evaluation) => evaluation.evidence)]
575
- };
576
- }
577
- if (condition.type === "not") {
578
- const childEvaluation = evaluateDataPolicyCondition(condition.condition, ctx);
579
- const passed2 = !childEvaluation.result.passed;
580
- const result2 = {
581
- conditionId: condition.conditionId,
582
- passed: passed2,
583
- result: passed2 ? condition.onPass ?? "pass" : condition.onFail ?? "block",
584
- reason: passed2 ? void 0 : condition.reason
585
- };
586
- return { result: result2, evidence: [result2, ...childEvaluation.evidence] };
587
- }
588
- if (condition.type !== "parameter" && condition.type !== "comparison") {
589
- const result2 = {
590
- conditionId: condition.conditionId,
591
- passed: false,
592
- result: "block",
593
- reason: "Unsupported data policy condition type"
594
- };
595
- return { result: result2, evidence: [result2] };
596
- }
597
- const value = condition.type === "parameter" ? readPath(ctx.parameters, condition.path) : readDataPolicySource(ctx, condition.left);
598
- const operator = condition.operator;
599
- const expected = condition.value;
600
- const passed = evaluateOperator(value, operator, expected);
601
- const result = {
602
- conditionId: condition.conditionId,
603
- passed,
604
- result: passed ? condition.onPass ?? "pass" : condition.onFail ?? "block",
605
- reason: passed ? void 0 : condition.reason
606
- };
607
- return { result, evidence: [result] };
608
- }
609
- function evaluateOperator(actual, operator, expected) {
610
- switch (operator) {
611
- case "exists":
612
- return actual !== void 0 && actual !== null && actual !== "";
613
- case "equals":
614
- return actual === expected;
615
- case "notEquals":
616
- return actual !== expected;
617
- case "gt":
618
- return typeof actual === "number" && typeof expected === "number" && actual > expected;
619
- case "gte":
620
- return typeof actual === "number" && typeof expected === "number" && actual >= expected;
621
- case "lt":
622
- return typeof actual === "number" && typeof expected === "number" && actual < expected;
623
- case "lte":
624
- return typeof actual === "number" && typeof expected === "number" && actual <= expected;
625
- }
626
- }
627
- function readDataPolicySource(ctx, reference) {
628
- if (reference.source === "parameters") {
629
- return readPath(ctx.parameters, reference.path);
630
- }
631
- return readPath(
632
- {
633
- tenantId: ctx.tenantId,
634
- spaceId: ctx.spaceId,
635
- actionInvocationId: ctx.actionInvocationId,
636
- actionId: ctx.actionId,
637
- mode: ctx.mode
638
- },
639
- reference.path
640
- );
641
- }
642
- function readPath(source, path) {
643
- if (!source || typeof source !== "object") {
644
- return void 0;
645
- }
646
- return path.split(".").reduce((current, segment) => {
647
- if (!current || typeof current !== "object") {
648
- return void 0;
649
- }
650
- return current[segment];
651
- }, source);
652
- }
653
- function normalizeOutcome(policy, outcome, dispatchEvidence) {
654
- if (outcome.guidance !== void 0) {
655
- const guidanceValidation = validatePolicyGuidance(outcome.guidance);
656
- if (!guidanceValidation.valid) {
657
- throw new Error(
658
- `Invalid guidance for policy ${outcome.policyId}: ${guidanceValidation.errors.join("; ")}`
659
- );
660
- }
661
- }
662
- const engine = outcome.dispatchEvidence?.engine;
663
- return {
664
- ...outcome,
665
- policyId: policy.policyId,
666
- policyVersion: policy.policyVersion,
667
- policyKind: policy.kind,
668
- metadata: {
669
- ...outcome.metadata ?? {},
670
- codePolicyId: dispatchEvidence.code?.policyId ?? outcome.policyId,
671
- codePolicyVersion: dispatchEvidence.code?.version ?? outcome.policyVersion
672
- },
673
- dispatchEvidence: engine ? { ...dispatchEvidence, engine } : dispatchEvidence
674
- };
675
- }
676
- function parsePolicyVersion(policyId) {
677
- const segments = policyId.split(".v");
678
- return Number(segments[segments.length - 1] ?? 1);
679
- }
680
- function aggregatePolicyOutcomes(outcomes) {
681
- return outcomes.find((outcome) => outcome.result === "block") ?? outcomes.find((outcome) => outcome.result === "warn");
682
- }
683
-
684
- export { ReconciliationRequiredError, RetryableExecutionError, aggregatePolicyOutcomes, assertPolicyId, createPolicyRegistry, evaluatePolicyDefinition, evaluatePolicyDefinitions, evaluateRegisteredPolicies, isReconciliationRequiredError, isRetryableExecutionError, validateDataPolicyDefinition, validatePolicyGuidance };
685
- //# sourceMappingURL=chunk-PXD7NG6X.js.map
686
- //# sourceMappingURL=chunk-PXD7NG6X.js.map