@cullet/erp-core 1.0.11 → 1.2.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 (118) hide show
  1. package/KIT_CONTEXT.md +1 -0
  2. package/README.md +128 -1
  3. package/dist/app-error.d.ts +108 -0
  4. package/dist/application/index.d.ts +2 -0
  5. package/dist/application/index.js +3 -0
  6. package/dist/domain/index.d.ts +3 -0
  7. package/dist/domain/index.js +3 -0
  8. package/dist/domain-event-contracts.d.ts +27 -0
  9. package/dist/domain-event-contracts.js +22 -0
  10. package/dist/domain-event-contracts.js.map +1 -0
  11. package/dist/domain-exception.d.ts +7 -0
  12. package/dist/domain-exception.js +12 -0
  13. package/dist/domain-exception.js.map +1 -0
  14. package/dist/errors/index.d.ts +2 -1
  15. package/dist/errors/index.js +4 -2
  16. package/dist/exceptions/index.d.ts +5 -0
  17. package/dist/exceptions/index.js +7 -0
  18. package/dist/gate-engine-registry.d.ts +81 -0
  19. package/dist/gate-engine-registry.js +2 -1
  20. package/dist/gate-engine-registry.js.map +1 -1
  21. package/dist/gate-types.d.ts +3 -139
  22. package/dist/gate-v1-payload.schema.js +3 -143
  23. package/dist/gate-v1-payload.schema.js.map +1 -1
  24. package/dist/hashing.js +49 -0
  25. package/dist/hashing.js.map +1 -0
  26. package/dist/immutable.d.ts +6 -0
  27. package/dist/immutable.js +54 -0
  28. package/dist/immutable.js.map +1 -0
  29. package/dist/index.d.ts +21 -200
  30. package/dist/index.js +21 -251
  31. package/dist/index.js.map +1 -1
  32. package/dist/invalid-state-transition-exception.js +30 -0
  33. package/dist/invalid-state-transition-exception.js.map +1 -0
  34. package/dist/invariant-violation-exception.js +11 -0
  35. package/dist/invariant-violation-exception.js.map +1 -0
  36. package/dist/not-found-error.js +54 -0
  37. package/dist/not-found-error.js.map +1 -0
  38. package/dist/outcome.d.ts +140 -0
  39. package/dist/outcome.js +1 -1
  40. package/dist/parse-gate-payload.d.ts +4 -78
  41. package/dist/path.d.ts +90 -0
  42. package/dist/plugin.d.ts +85 -0
  43. package/dist/plugin.js +74 -0
  44. package/dist/plugin.js.map +1 -0
  45. package/dist/plugins/index.d.ts +2 -0
  46. package/dist/plugins/index.js +2 -0
  47. package/dist/policies/engines/index.d.ts +3 -2
  48. package/dist/policies/engines/v1/gate/index.d.ts +2 -1
  49. package/dist/policies/engines/v1/gate/index.js +2 -1
  50. package/dist/policies/engines/v1/gate/index.js.map +1 -1
  51. package/dist/policies/index.d.ts +6 -3
  52. package/dist/policies/index.js +2 -1
  53. package/dist/policy-service.d.ts +4 -86
  54. package/dist/policy-service.js +8 -16
  55. package/dist/policy-service.js.map +1 -1
  56. package/dist/result/index.d.ts +2 -0
  57. package/dist/result/index.js +3 -0
  58. package/dist/result.js +118 -0
  59. package/dist/result.js.map +1 -0
  60. package/dist/ruleset-registry.js +42 -0
  61. package/dist/ruleset-registry.js.map +1 -0
  62. package/dist/rulesets/index.d.ts +2 -0
  63. package/dist/rulesets/index.js +2 -0
  64. package/dist/temporal-guards.js +15 -0
  65. package/dist/temporal-guards.js.map +1 -0
  66. package/dist/temporal-use-case.d.ts +304 -0
  67. package/dist/temporal-use-case.js +150 -0
  68. package/dist/temporal-use-case.js.map +1 -0
  69. package/dist/unexpected-error.js +179 -0
  70. package/dist/unexpected-error.js.map +1 -0
  71. package/dist/use-case.js +91 -0
  72. package/dist/use-case.js.map +1 -0
  73. package/dist/uuid-identifier.d.ts +230 -0
  74. package/dist/uuid-identifier.js +60 -0
  75. package/dist/uuid-identifier.js.map +1 -0
  76. package/dist/validation-code.d.ts +23 -0
  77. package/dist/validation-code.js +1 -223
  78. package/dist/validation-code.js.map +1 -1
  79. package/dist/validation-error.d.ts +3 -128
  80. package/dist/validation-error.js +2 -52
  81. package/dist/validation-error.js.map +1 -1
  82. package/dist/validation-exception.d.ts +50 -0
  83. package/dist/validation-exception.js +24 -0
  84. package/dist/validation-exception.js.map +1 -0
  85. package/dist/value-object-ruleset.contracts.d.ts +36 -0
  86. package/dist/value-object.js +191 -0
  87. package/dist/value-object.js.map +1 -0
  88. package/dist/version.d.ts +10 -0
  89. package/dist/versioning/index.d.ts +3 -0
  90. package/dist/versioning/index.js +3 -0
  91. package/meta.json +18 -3
  92. package/package.json +37 -4
  93. package/src/application/index.ts +1 -0
  94. package/src/core/application/commands/index.ts +1 -0
  95. package/src/core/application/index.ts +12 -3
  96. package/src/core/application/ports/index.ts +2 -2
  97. package/src/core/application/ports/policy-port.ts +13 -3
  98. package/src/core/application/ports/repository.port.ts +37 -1
  99. package/src/core/application/temporal/temporal-use-case.ts +14 -2
  100. package/src/core/application/use-case.ts +133 -2
  101. package/src/core/domain/rulesets/index.ts +7 -0
  102. package/src/core/domain/uuid-identifier.ts +72 -0
  103. package/src/core/domain/value-object.ts +37 -5
  104. package/src/core/exceptions/index.ts +13 -0
  105. package/src/core/index.ts +15 -12
  106. package/src/core/plugins/index.ts +7 -0
  107. package/src/core/plugins/plugin.ts +99 -0
  108. package/src/core/plugins/types.ts +53 -0
  109. package/src/core/versioning/index.ts +14 -0
  110. package/src/domain/index.ts +7 -0
  111. package/src/examples/application/cancel-order.example.ts +124 -0
  112. package/src/examples/application/in-memory-account-repository.example.ts +73 -0
  113. package/src/exceptions/index.ts +1 -0
  114. package/src/plugins/index.ts +1 -0
  115. package/src/result/index.ts +2 -0
  116. package/src/rulesets/index.ts +1 -0
  117. package/src/version.ts +1 -1
  118. package/src/versioning/index.ts +1 -0
package/dist/plugin.js ADDED
@@ -0,0 +1,74 @@
1
+ //#region src/core/plugins/plugin.ts
2
+ /**
3
+ * Registry that holds a set of plugins implementing a shared {@link PluginContract}
4
+ * and resolves which of them answer a given extension point.
5
+ *
6
+ * Plugins are kept sorted by priority (descending). For a given method,
7
+ * {@link invoke} either delegates to the highest-priority enabled plugin
8
+ * (`'first'`) or folds every enabled plugin into a single value (`'pipeline'`).
9
+ * When no plugin is enabled, the supplied `fallback` runs instead, so the host
10
+ * always has defined behaviour even with an empty registry.
11
+ *
12
+ * @typeParam P - The plugin contract this manager coordinates.
13
+ */
14
+ var PluginManager = class {
15
+ constructor() {
16
+ this.plugins = [];
17
+ }
18
+ /** Registers one or more plugins and re-sorts by priority. */
19
+ register(...plugins) {
20
+ this.plugins.push(...plugins);
21
+ this.reorder();
22
+ }
23
+ /** Removes a previously registered plugin by name. */
24
+ unregister(name) {
25
+ this.plugins = this.plugins.filter((p) => p.name !== name);
26
+ }
27
+ /** Enables a registered plugin by name. */
28
+ enable(name) {
29
+ const plugin = this.plugins.find((p) => p.name === name);
30
+ if (plugin) plugin.enabled = true;
31
+ }
32
+ /** Disables a registered plugin by name (without removing it). */
33
+ disable(name) {
34
+ const plugin = this.plugins.find((p) => p.name === name);
35
+ if (plugin) plugin.enabled = false;
36
+ }
37
+ /** Lists enabled plugins only, already in priority order. */
38
+ list() {
39
+ return this.plugins.filter((p) => p.enabled !== false);
40
+ }
41
+ /**
42
+ * Resolves `method` against the registered plugins.
43
+ *
44
+ * In `'first'` mode the highest-priority enabled plugin that implements
45
+ * `method` answers. In `'pipeline'` mode every enabled plugin runs and the
46
+ * results are folded with `reducer` (defaults to "keep the last result").
47
+ * When no enabled plugin implements `method`, `fallback` is called.
48
+ */
49
+ invoke(method, args, opts) {
50
+ const { mode = "first", fallback, reducer } = opts;
51
+ const enabled = this.list().filter((p) => method in p);
52
+ if (enabled.length === 0) return fallback(...args);
53
+ if (mode === "first") {
54
+ const fn = enabled[0][method];
55
+ return fn(...args);
56
+ }
57
+ const defaultReducer = (_, curr) => curr;
58
+ const red = reducer ?? defaultReducer;
59
+ let acc = enabled[0][method](...args);
60
+ enabled.slice(1).forEach((plugin, idx) => {
61
+ const res = plugin[method](...args);
62
+ acc = red(acc, res, plugin, idx + 1);
63
+ });
64
+ return acc;
65
+ }
66
+ /** Re-sorts the internal list by priority (desc; default priority = 0). */
67
+ reorder() {
68
+ this.plugins.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
69
+ }
70
+ };
71
+ //#endregion
72
+ export { PluginManager as t };
73
+
74
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","names":[],"sources":["../src/core/plugins/plugin.ts"],"sourcesContent":["import {\n type BasePlugin,\n type InvokeOptions,\n type PipelineReducer,\n type PluginContract,\n} from \"./types.js\";\n\n/**\n * Registry that holds a set of plugins implementing a shared {@link PluginContract}\n * and resolves which of them answer a given extension point.\n *\n * Plugins are kept sorted by priority (descending). For a given method,\n * {@link invoke} either delegates to the highest-priority enabled plugin\n * (`'first'`) or folds every enabled plugin into a single value (`'pipeline'`).\n * When no plugin is enabled, the supplied `fallback` runs instead, so the host\n * always has defined behaviour even with an empty registry.\n *\n * @typeParam P - The plugin contract this manager coordinates.\n */\nclass PluginManager<P extends PluginContract> {\n /** Internal list, kept sorted by priority (desc). */\n private plugins: (P & BasePlugin)[] = [];\n\n /** Registers one or more plugins and re-sorts by priority. */\n public register(...plugins: (P & BasePlugin)[]): void {\n this.plugins.push(...plugins);\n this.reorder();\n }\n\n /** Removes a previously registered plugin by name. */\n public unregister(name: string): void {\n this.plugins = this.plugins.filter((p) => p.name !== name);\n }\n\n /** Enables a registered plugin by name. */\n public enable(name: string): void {\n const plugin = this.plugins.find((p) => p.name === name);\n if (plugin) plugin.enabled = true;\n }\n\n /** Disables a registered plugin by name (without removing it). */\n public disable(name: string): void {\n const plugin = this.plugins.find((p) => p.name === name);\n if (plugin) plugin.enabled = false;\n }\n\n /** Lists enabled plugins only, already in priority order. */\n public list(): readonly (P & BasePlugin)[] {\n return this.plugins.filter((p) => p.enabled !== false);\n }\n\n /**\n * Resolves `method` against the registered plugins.\n *\n * In `'first'` mode the highest-priority enabled plugin that implements\n * `method` answers. In `'pipeline'` mode every enabled plugin runs and the\n * results are folded with `reducer` (defaults to \"keep the last result\").\n * When no enabled plugin implements `method`, `fallback` is called.\n */\n public invoke<K extends keyof P>(\n method: K,\n args: Parameters<P[K]>,\n opts: InvokeOptions<P, K>,\n ): ReturnType<P[K]> {\n const { mode = \"first\", fallback, reducer } = opts;\n const enabled = this.list().filter((p) => method in p) as Array<\n P & BasePlugin\n >;\n\n if (enabled.length === 0) {\n return (fallback as P[K])(...args);\n }\n\n if (mode === \"first\") {\n const fn = enabled[0][method] as P[K];\n return fn(...args);\n }\n\n const defaultReducer: PipelineReducer<ReturnType<P[K]>, P> = (\n _,\n curr,\n ) => curr;\n const red = reducer ?? defaultReducer;\n\n let acc: ReturnType<P[K]> = enabled[0][method]!(...args);\n enabled.slice(1).forEach((plugin, idx) => {\n const res = plugin[method]!(...args);\n acc = red(acc, res, plugin, idx + 1);\n });\n return acc;\n }\n\n /** Re-sorts the internal list by priority (desc; default priority = 0). */\n private reorder(): void {\n this.plugins.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));\n }\n}\n\nexport { PluginManager };\n"],"mappings":";;;;;;;;;;;;;AAmBA,IAAM,gBAAN,MAA8C;;iBAEJ,CAAC;;;CAGvC,SAAgB,GAAG,SAAmC;EAClD,KAAK,QAAQ,KAAK,GAAG,OAAO;EAC5B,KAAK,QAAQ;CACjB;;CAGA,WAAkB,MAAoB;EAClC,KAAK,UAAU,KAAK,QAAQ,QAAQ,MAAM,EAAE,SAAS,IAAI;CAC7D;;CAGA,OAAc,MAAoB;EAC9B,MAAM,SAAS,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,IAAI;EACvD,IAAI,QAAQ,OAAO,UAAU;CACjC;;CAGA,QAAe,MAAoB;EAC/B,MAAM,SAAS,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,IAAI;EACvD,IAAI,QAAQ,OAAO,UAAU;CACjC;;CAGA,OAA2C;EACvC,OAAO,KAAK,QAAQ,QAAQ,MAAM,EAAE,YAAY,KAAK;CACzD;;;;;;;;;CAUA,OACI,QACA,MACA,MACgB;EAChB,MAAM,EAAE,OAAO,SAAS,UAAU,YAAY;EAC9C,MAAM,UAAU,KAAK,KAAK,EAAE,QAAQ,MAAM,UAAU,CAAC;EAIrD,IAAI,QAAQ,WAAW,GACnB,OAAQ,SAAkB,GAAG,IAAI;EAGrC,IAAI,SAAS,SAAS;GAClB,MAAM,KAAK,QAAQ,GAAG;GACtB,OAAO,GAAG,GAAG,IAAI;EACrB;EAEA,MAAM,kBACF,GACA,SACC;EACL,MAAM,MAAM,WAAW;EAEvB,IAAI,MAAwB,QAAQ,GAAG,QAAS,GAAG,IAAI;EACvD,QAAQ,MAAM,CAAC,EAAE,SAAS,QAAQ,QAAQ;GACtC,MAAM,MAAM,OAAO,QAAS,GAAG,IAAI;GACnC,MAAM,IAAI,KAAK,KAAK,QAAQ,MAAM,CAAC;EACvC,CAAC;EACD,OAAO;CACX;;CAGA,UAAwB;EACpB,KAAK,QAAQ,MAAM,GAAG,OAAO,EAAE,YAAY,MAAM,EAAE,YAAY,EAAE;CACrE;AACJ"}
@@ -0,0 +1,2 @@
1
+ import { a as PluginContract, i as PipelineReducer, n as BasePlugin, r as InvokeOptions, t as PluginManager } from "../plugin.js";
2
+ export { BasePlugin, InvokeOptions, PipelineReducer, PluginContract, PluginManager };
@@ -0,0 +1,2 @@
1
+ import { t as PluginManager } from "../plugin.js";
2
+ export { PluginManager };
@@ -1,3 +1,4 @@
1
- import { A as ConditionEvaluationReport, M as ConditionEvaluationReportTag, N as ConditionEvaluatorReporter, O as ConditionEvaluationCause, a as GateTraceNodeSnapshot, c as PolicyViolation, d as GatePayloadV1, i as GateTraceLeafSnapshot, j as ConditionEvaluationReportLevel, k as ConditionEvaluationOptions, l as VersionedGateEngine, n as GateOutcomeData, o as GateViolationTrace, r as GateStatus, s as PolicyContext, t as GateOutcome, u as GatePayload } from "../../gate-types.js";
2
- import { _ as ComputePayload, a as ComputePayloadParserRegistry, b as ComputeParamsPayload, c as ComputeRegistry, d as ComputeEvaluator, f as ComputeEvaluatorRegistration, g as VersionedComputeEngine, h as ComputeStatus, i as ComputePayloadParser, l as ComputeEngineRegistry, m as ComputeOutcomeData, n as GatePayloadParserRegistry, o as ComputePayloadParsers, p as ComputeOutcome, r as GatePayloadParsers, s as GateEngineRegistry, t as GatePayloadParser, u as ComputeEvaluatorRegistry, v as ComputeDecisionTablePayload, x as ComputePayloadV1, y as ComputeDecisionTableRule } from "../../parse-gate-payload.js";
1
+ import { A as ConditionEvaluationReportTag, D as ConditionEvaluationOptions, E as ConditionEvaluationCause, O as ConditionEvaluationReport, a as GateTraceNodeSnapshot, c as PolicyViolation, d as GatePayloadV1, i as GateTraceLeafSnapshot, j as ConditionEvaluatorReporter, k as ConditionEvaluationReportLevel, l as VersionedGateEngine, n as GateOutcomeData, o as GateViolationTrace, r as GateStatus, s as PolicyContext, t as GateOutcome, u as GatePayload } from "../../gate-types.js";
2
+ import { a as ComputeOutcome, c as VersionedComputeEngine, d as ComputeDecisionTableRule, f as ComputeParamsPayload, i as ComputeEvaluatorRegistration, l as ComputePayload, n as ComputeRegistry, o as ComputeOutcomeData, p as ComputePayloadV1, r as ComputeEvaluator, s as ComputeStatus, t as GateEngineRegistry, u as ComputeDecisionTablePayload } from "../../gate-engine-registry.js";
3
+ import { a as ComputePayloadParserRegistry, c as ComputeEvaluatorRegistry, i as ComputePayloadParser, n as GatePayloadParserRegistry, o as ComputePayloadParsers, r as GatePayloadParsers, s as ComputeEngineRegistry, t as GatePayloadParser } from "../../parse-gate-payload.js";
3
4
  export { ComputeDecisionTablePayload, ComputeDecisionTableRule, ComputeEngineRegistry, ComputeEvaluator, ComputeEvaluatorRegistration, ComputeEvaluatorRegistry, ComputeOutcome, ComputeOutcomeData, ComputeParamsPayload, ComputePayload, ComputePayloadParser, ComputePayloadParserRegistry, ComputePayloadParsers, ComputePayloadV1, ComputeRegistry, ComputeStatus, ConditionEvaluationCause, ConditionEvaluationOptions, ConditionEvaluationReport, ConditionEvaluationReportLevel, ConditionEvaluationReportTag, ConditionEvaluatorReporter, GateEngineRegistry, GateOutcome, GateOutcomeData, GatePayload, GatePayloadParser, GatePayloadParserRegistry, GatePayloadParsers, GatePayloadV1, GateStatus, GateTraceLeafSnapshot, GateTraceNodeSnapshot, GateViolationTrace, PolicyContext, PolicyViolation, VersionedComputeEngine, VersionedGateEngine };
@@ -1,4 +1,5 @@
1
- import { I as Result, d as GatePayloadV1, f as ConditionLeafNode, g as CoreConfig, k as ConditionEvaluationOptions, l as VersionedGateEngine, p as ConditionNode, s as PolicyContext, t as GateOutcome, u as GatePayload } from "../../../../gate-types.js";
1
+ import { a as Result } from "../../../../outcome.js";
2
+ import { D as ConditionEvaluationOptions, d as GatePayloadV1, f as ConditionLeafNode, l as VersionedGateEngine, m as CoreConfig, p as ConditionNode, s as PolicyContext, t as GateOutcome, u as GatePayload } from "../../../../gate-types.js";
2
3
  import { z } from "zod";
3
4
 
4
5
  //#region src/core/policies/engines/v1/condition-evaluator.d.ts
@@ -1,4 +1,5 @@
1
- import { a as conditionNodeSchema, i as conditionLeafNodeSchema, l as Result, n as gatePayloadSchema, r as ConditionEvaluatorV1, t as GatePayloadSchemaV1, u as coreConfig } from "../../../../gate-v1-payload.schema.js";
1
+ import { a as conditionNodeSchema, i as conditionLeafNodeSchema, n as gatePayloadSchema, r as ConditionEvaluatorV1, s as coreConfig, t as GatePayloadSchemaV1 } from "../../../../gate-v1-payload.schema.js";
2
+ import { r as Result } from "../../../../result.js";
2
3
  import { t as Outcome } from "../../../../outcome.js";
3
4
  //#region src/core/policies/engines/v1/gate/gate-engine-v1.ts
4
5
  var GateEngineV1 = class {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/core/policies/engines/v1/gate/gate-engine-v1.ts"],"sourcesContent":["import { type CoreConfig, coreConfig } from \"../../../../config/index.js\";\nimport { Outcome } from \"../../../../result/outcome.js\";\nimport { Result } from \"../../../../result/result.js\";\n\nimport {\n ConditionEvaluatorV1,\n type TracedConditionEvaluation,\n} from \"../condition-evaluator.js\";\nimport type { ConditionLeafNode, ConditionNode } from \"../condition-types.js\";\nimport type { GatePayload } from \"../../gate-payload.js\";\nimport type {\n GateOutcome,\n GateStatus,\n GateTraceLeafSnapshot,\n GateTraceNodeSnapshot,\n PolicyContext,\n PolicyViolation,\n VersionedGateEngine,\n} from \"../../gate-types.js\";\n\n// ─── Gate engine v1 ─────────────────────────────────────────────────────────\n\nexport class GateEngineV1 implements VersionedGateEngine {\n public readonly version = 1;\n private readonly coreConfig: CoreConfig;\n\n constructor(params: { readonly coreConfig?: CoreConfig } = {}) {\n this.coreConfig = params.coreConfig ?? coreConfig;\n }\n\n private allow(): Result<GateOutcome, string> {\n return Result.ok(Outcome.of(\"ALLOW\", { violations: [] }));\n }\n\n private deny(violation: PolicyViolation): Result<GateOutcome, string> {\n return Result.ok(\n Outcome.of(\"DENY\", {\n violations: [violation],\n }),\n );\n }\n\n private outcomeFromStatus(\n status: GateStatus,\n violation: PolicyViolation,\n ): Result<GateOutcome, string> {\n return status === \"ALLOW\" ? this.allow() : this.deny(violation);\n }\n\n private isLeafNode(node: ConditionNode): node is ConditionLeafNode {\n return \"field\" in node && \"op\" in node;\n }\n\n private toLeafSnapshot(node: ConditionLeafNode): GateTraceLeafSnapshot {\n return {\n kind: \"LEAF\",\n field: node.field,\n op: node.op,\n ...(node.allowNull === true ? { allowNull: true } : {}),\n };\n }\n\n private toNodeSnapshot(node: ConditionNode): GateTraceNodeSnapshot {\n if (this.isLeafNode(node)) {\n return this.toLeafSnapshot(node);\n }\n\n if (\"and\" in node) {\n return {\n kind: \"AND\",\n childCount: node.and.length,\n };\n }\n\n if (\"or\" in node) {\n return {\n kind: \"OR\",\n childCount: node.or.length,\n };\n }\n\n return {\n kind: \"NOT\",\n };\n }\n\n private buildDenyViolation(\n conditionResult: TracedConditionEvaluation,\n ): PolicyViolation {\n return {\n code: \"DENY_CONDITION_MET\",\n message: `Gate denied at ${conditionResult.trace.conditionPath}`,\n trace: {\n conditionPath: conditionResult.trace.conditionPath,\n decisiveNode: this.toNodeSnapshot(\n conditionResult.trace.decisiveNode,\n ),\n lastEvaluatedLeaf: this.toLeafSnapshot(\n conditionResult.trace.lastEvaluatedLeaf,\n ),\n lastEvaluatedLeafPath:\n conditionResult.trace.lastEvaluatedLeafPath,\n lastEvaluatedLeafResult:\n conditionResult.trace.lastEvaluatedLeafResult,\n field: conditionResult.trace.lastEvaluatedLeaf.field,\n op: conditionResult.trace.lastEvaluatedLeaf.op,\n },\n };\n }\n\n private normalizePayload(payload: GatePayload): {\n readonly allowIf: ConditionNode;\n readonly defaultOutcome: \"ALLOW\" | \"DENY\";\n } {\n if (\"condition\" in payload) {\n return {\n allowIf: payload.condition,\n defaultOutcome: \"DENY\",\n };\n }\n\n return payload;\n }\n\n /**\n * Evaluates a GATE payload against a context object.\n * Pure function — no side effects.\n *\n * Receives an already-parsed `GatePayload`; the registry is responsible\n * for parsing from raw `unknown` before calling this method.\n * Returns Result for technical failures (condition evaluation errors).\n * The Outcome inside carries the business decision (ALLOW/DENY).\n */\n evaluate(\n payload: GatePayload,\n context: PolicyContext,\n ): Result<GateOutcome, string> {\n const gatePayload = this.normalizePayload(payload);\n const conditionEvaluator = new ConditionEvaluatorV1(\n context,\n this.coreConfig.getConditionEvaluationOptions(this.version),\n );\n\n const isAllowedResult = conditionEvaluator.evaluateWithTrace(\n gatePayload.allowIf,\n );\n if (isAllowedResult.isErr()) {\n return Result.err(isAllowedResult.errorOrNull()!);\n }\n\n const isAllowed = isAllowedResult.getOrNull()!;\n if (isAllowed.matched) {\n return this.allow();\n }\n\n return this.outcomeFromStatus(\n gatePayload.defaultOutcome,\n this.buildDenyViolation(isAllowed),\n );\n }\n}\n"],"mappings":";;;AAsBA,IAAa,eAAb,MAAyD;CAIrD,YAAY,SAA+C,CAAC,GAAG;iBAHrC;EAItB,KAAK,aAAa,OAAO,cAAc;CAC3C;CAEA,QAA6C;EACzC,OAAO,OAAO,GAAG,QAAQ,GAAG,SAAS,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;CAC5D;CAEA,KAAa,WAAyD;EAClE,OAAO,OAAO,GACV,QAAQ,GAAG,QAAQ,EACf,YAAY,CAAC,SAAS,EAC1B,CAAC,CACL;CACJ;CAEA,kBACI,QACA,WAC2B;EAC3B,OAAO,WAAW,UAAU,KAAK,MAAM,IAAI,KAAK,KAAK,SAAS;CAClE;CAEA,WAAmB,MAAgD;EAC/D,OAAO,WAAW,QAAQ,QAAQ;CACtC;CAEA,eAAuB,MAAgD;EACnE,OAAO;GACH,MAAM;GACN,OAAO,KAAK;GACZ,IAAI,KAAK;GACT,GAAI,KAAK,cAAc,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;EACzD;CACJ;CAEA,eAAuB,MAA4C;EAC/D,IAAI,KAAK,WAAW,IAAI,GACpB,OAAO,KAAK,eAAe,IAAI;EAGnC,IAAI,SAAS,MACT,OAAO;GACH,MAAM;GACN,YAAY,KAAK,IAAI;EACzB;EAGJ,IAAI,QAAQ,MACR,OAAO;GACH,MAAM;GACN,YAAY,KAAK,GAAG;EACxB;EAGJ,OAAO,EACH,MAAM,MACV;CACJ;CAEA,mBACI,iBACe;EACf,OAAO;GACH,MAAM;GACN,SAAS,kBAAkB,gBAAgB,MAAM;GACjD,OAAO;IACH,eAAe,gBAAgB,MAAM;IACrC,cAAc,KAAK,eACf,gBAAgB,MAAM,YAC1B;IACA,mBAAmB,KAAK,eACpB,gBAAgB,MAAM,iBAC1B;IACA,uBACI,gBAAgB,MAAM;IAC1B,yBACI,gBAAgB,MAAM;IAC1B,OAAO,gBAAgB,MAAM,kBAAkB;IAC/C,IAAI,gBAAgB,MAAM,kBAAkB;GAChD;EACJ;CACJ;CAEA,iBAAyB,SAGvB;EACE,IAAI,eAAe,SACf,OAAO;GACH,SAAS,QAAQ;GACjB,gBAAgB;EACpB;EAGJ,OAAO;CACX;;;;;;;;;;CAWA,SACI,SACA,SAC2B;EAC3B,MAAM,cAAc,KAAK,iBAAiB,OAAO;EAMjD,MAAM,kBAAkB,IALO,qBAC3B,SACA,KAAK,WAAW,8BAA8B,KAAK,OAAO,CAGrB,EAAE,kBACvC,YAAY,OAChB;EACA,IAAI,gBAAgB,MAAM,GACtB,OAAO,OAAO,IAAI,gBAAgB,YAAY,CAAE;EAGpD,MAAM,YAAY,gBAAgB,UAAU;EAC5C,IAAI,UAAU,SACV,OAAO,KAAK,MAAM;EAGtB,OAAO,KAAK,kBACR,YAAY,gBACZ,KAAK,mBAAmB,SAAS,CACrC;CACJ;AACJ"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../../src/core/policies/engines/v1/gate/gate-engine-v1.ts"],"sourcesContent":["import { type CoreConfig, coreConfig } from \"../../../../config/index.js\";\nimport { Outcome } from \"../../../../result/outcome.js\";\nimport { Result } from \"../../../../result/result.js\";\n\nimport {\n ConditionEvaluatorV1,\n type TracedConditionEvaluation,\n} from \"../condition-evaluator.js\";\nimport type { ConditionLeafNode, ConditionNode } from \"../condition-types.js\";\nimport type { GatePayload } from \"../../gate-payload.js\";\nimport type {\n GateOutcome,\n GateStatus,\n GateTraceLeafSnapshot,\n GateTraceNodeSnapshot,\n PolicyContext,\n PolicyViolation,\n VersionedGateEngine,\n} from \"../../gate-types.js\";\n\n// ─── Gate engine v1 ─────────────────────────────────────────────────────────\n\nexport class GateEngineV1 implements VersionedGateEngine {\n public readonly version = 1;\n private readonly coreConfig: CoreConfig;\n\n constructor(params: { readonly coreConfig?: CoreConfig } = {}) {\n this.coreConfig = params.coreConfig ?? coreConfig;\n }\n\n private allow(): Result<GateOutcome, string> {\n return Result.ok(Outcome.of(\"ALLOW\", { violations: [] }));\n }\n\n private deny(violation: PolicyViolation): Result<GateOutcome, string> {\n return Result.ok(\n Outcome.of(\"DENY\", {\n violations: [violation],\n }),\n );\n }\n\n private outcomeFromStatus(\n status: GateStatus,\n violation: PolicyViolation,\n ): Result<GateOutcome, string> {\n return status === \"ALLOW\" ? this.allow() : this.deny(violation);\n }\n\n private isLeafNode(node: ConditionNode): node is ConditionLeafNode {\n return \"field\" in node && \"op\" in node;\n }\n\n private toLeafSnapshot(node: ConditionLeafNode): GateTraceLeafSnapshot {\n return {\n kind: \"LEAF\",\n field: node.field,\n op: node.op,\n ...(node.allowNull === true ? { allowNull: true } : {}),\n };\n }\n\n private toNodeSnapshot(node: ConditionNode): GateTraceNodeSnapshot {\n if (this.isLeafNode(node)) {\n return this.toLeafSnapshot(node);\n }\n\n if (\"and\" in node) {\n return {\n kind: \"AND\",\n childCount: node.and.length,\n };\n }\n\n if (\"or\" in node) {\n return {\n kind: \"OR\",\n childCount: node.or.length,\n };\n }\n\n return {\n kind: \"NOT\",\n };\n }\n\n private buildDenyViolation(\n conditionResult: TracedConditionEvaluation,\n ): PolicyViolation {\n return {\n code: \"DENY_CONDITION_MET\",\n message: `Gate denied at ${conditionResult.trace.conditionPath}`,\n trace: {\n conditionPath: conditionResult.trace.conditionPath,\n decisiveNode: this.toNodeSnapshot(\n conditionResult.trace.decisiveNode,\n ),\n lastEvaluatedLeaf: this.toLeafSnapshot(\n conditionResult.trace.lastEvaluatedLeaf,\n ),\n lastEvaluatedLeafPath:\n conditionResult.trace.lastEvaluatedLeafPath,\n lastEvaluatedLeafResult:\n conditionResult.trace.lastEvaluatedLeafResult,\n field: conditionResult.trace.lastEvaluatedLeaf.field,\n op: conditionResult.trace.lastEvaluatedLeaf.op,\n },\n };\n }\n\n private normalizePayload(payload: GatePayload): {\n readonly allowIf: ConditionNode;\n readonly defaultOutcome: \"ALLOW\" | \"DENY\";\n } {\n if (\"condition\" in payload) {\n return {\n allowIf: payload.condition,\n defaultOutcome: \"DENY\",\n };\n }\n\n return payload;\n }\n\n /**\n * Evaluates a GATE payload against a context object.\n * Pure function — no side effects.\n *\n * Receives an already-parsed `GatePayload`; the registry is responsible\n * for parsing from raw `unknown` before calling this method.\n * Returns Result for technical failures (condition evaluation errors).\n * The Outcome inside carries the business decision (ALLOW/DENY).\n */\n evaluate(\n payload: GatePayload,\n context: PolicyContext,\n ): Result<GateOutcome, string> {\n const gatePayload = this.normalizePayload(payload);\n const conditionEvaluator = new ConditionEvaluatorV1(\n context,\n this.coreConfig.getConditionEvaluationOptions(this.version),\n );\n\n const isAllowedResult = conditionEvaluator.evaluateWithTrace(\n gatePayload.allowIf,\n );\n if (isAllowedResult.isErr()) {\n return Result.err(isAllowedResult.errorOrNull()!);\n }\n\n const isAllowed = isAllowedResult.getOrNull()!;\n if (isAllowed.matched) {\n return this.allow();\n }\n\n return this.outcomeFromStatus(\n gatePayload.defaultOutcome,\n this.buildDenyViolation(isAllowed),\n );\n }\n}\n"],"mappings":";;;;AAsBA,IAAa,eAAb,MAAyD;CAIrD,YAAY,SAA+C,CAAC,GAAG;iBAHrC;EAItB,KAAK,aAAa,OAAO,cAAc;CAC3C;CAEA,QAA6C;EACzC,OAAO,OAAO,GAAG,QAAQ,GAAG,SAAS,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;CAC5D;CAEA,KAAa,WAAyD;EAClE,OAAO,OAAO,GACV,QAAQ,GAAG,QAAQ,EACf,YAAY,CAAC,SAAS,EAC1B,CAAC,CACL;CACJ;CAEA,kBACI,QACA,WAC2B;EAC3B,OAAO,WAAW,UAAU,KAAK,MAAM,IAAI,KAAK,KAAK,SAAS;CAClE;CAEA,WAAmB,MAAgD;EAC/D,OAAO,WAAW,QAAQ,QAAQ;CACtC;CAEA,eAAuB,MAAgD;EACnE,OAAO;GACH,MAAM;GACN,OAAO,KAAK;GACZ,IAAI,KAAK;GACT,GAAI,KAAK,cAAc,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;EACzD;CACJ;CAEA,eAAuB,MAA4C;EAC/D,IAAI,KAAK,WAAW,IAAI,GACpB,OAAO,KAAK,eAAe,IAAI;EAGnC,IAAI,SAAS,MACT,OAAO;GACH,MAAM;GACN,YAAY,KAAK,IAAI;EACzB;EAGJ,IAAI,QAAQ,MACR,OAAO;GACH,MAAM;GACN,YAAY,KAAK,GAAG;EACxB;EAGJ,OAAO,EACH,MAAM,MACV;CACJ;CAEA,mBACI,iBACe;EACf,OAAO;GACH,MAAM;GACN,SAAS,kBAAkB,gBAAgB,MAAM;GACjD,OAAO;IACH,eAAe,gBAAgB,MAAM;IACrC,cAAc,KAAK,eACf,gBAAgB,MAAM,YAC1B;IACA,mBAAmB,KAAK,eACpB,gBAAgB,MAAM,iBAC1B;IACA,uBACI,gBAAgB,MAAM;IAC1B,yBACI,gBAAgB,MAAM;IAC1B,OAAO,gBAAgB,MAAM,kBAAkB;IAC/C,IAAI,gBAAgB,MAAM,kBAAkB;GAChD;EACJ;CACJ;CAEA,iBAAyB,SAGvB;EACE,IAAI,eAAe,SACf,OAAO;GACH,SAAS,QAAQ;GACjB,gBAAgB;EACpB;EAGJ,OAAO;CACX;;;;;;;;;;CAWA,SACI,SACA,SAC2B;EAC3B,MAAM,cAAc,KAAK,iBAAiB,OAAO;EAMjD,MAAM,kBAAkB,IALO,qBAC3B,SACA,KAAK,WAAW,8BAA8B,KAAK,OAAO,CAGrB,EAAE,kBACvC,YAAY,OAChB;EACA,IAAI,gBAAgB,MAAM,GACtB,OAAO,OAAO,IAAI,gBAAgB,YAAY,CAAE;EAGpD,MAAM,YAAY,gBAAgB,UAAU;EAC5C,IAAI,UAAU,SACV,OAAO,KAAK,MAAM;EAGtB,OAAO,KAAK,kBACR,YAAY,gBACZ,KAAK,mBAAmB,SAAS,CACrC;CACJ;AACJ"}
@@ -1,4 +1,7 @@
1
- import { A as ConditionEvaluationReport, C as TenantId, D as asTenantId, E as asSchoolId, F as Ok, I as Result, M as ConditionEvaluationReportTag, N as ConditionEvaluatorReporter, O as ConditionEvaluationCause, P as Err, S as SchoolId, T as asPolicyDefinitionId, _ as CoreConfigOptions, a as GateTraceNodeSnapshot, b as PolicyDecisionId, c as PolicyViolation, g as CoreConfig, h as Outcome, i as GateTraceLeafSnapshot, j as ConditionEvaluationReportLevel, k as ConditionEvaluationOptions, l as VersionedGateEngine, m as CommonOutcomeStatus, n as GateOutcomeData, o as GateViolationTrace, r as GateStatus, s as PolicyContext, t as GateOutcome, u as GatePayload, v as CoreObservabilityConfig, w as asPolicyDecisionId, x as PolicyDefinitionId } from "../gate-types.js";
2
- import { A as FindCandidatesParams, B as PolicyKey, C as ContextSeed, D as InMemoryPolicyDefinitionRepository, E as PolicyPackage, F as PolicyScope, G as PolicyHashing, H as PolicyKind, I as PolicyScopeMatcher, K as coreConfig, L as ScopeChain, M as PolicyDefinition, N as PolicyDefinitionProps, O as BasePolicyDefinitionProps, P as PolicyDefinitionStatus, R as PolicyCatalog, S as ContextValueResolver, T as PolicyCatalogFactory, U as PolicyOwner, V as AsOfSource, W as PolicyScopeLevel, _ as ContextResolverRegistry, a as PolicyServiceOptions, b as ContextResolverResilienceOptions, c as PolicyEvaluationErrors, d as PolicyAsOfResolver, f as PolicyContextPath, g as PolicyContextBuilderOptions, h as PolicyContextBuilder, i as PolicyService, j as GatePolicyDefinitionProps, k as ComputePolicyDefinitionProps, l as PolicyResolver, m as registerNamespacedContextResolvers, n as PolicyDecision, o as PolicyServiceParams, p as contextResolverRegistry, r as PolicyEvaluationResult, s as PolicyEvaluationError, t as EvaluateInput, u as DeriveAsOfOptions, v as registerNamespacedContextResolversIn, w as ContextSeedValidator, x as ContextResolverRetryOptions, y as ContextResolverCircuitBreakerOptions, z as PolicyCatalogEntryProps } from "../policy-service.js";
3
- import { a as ComputePayloadParserRegistry, c as ComputeRegistry, d as ComputeEvaluator, f as ComputeEvaluatorRegistration, g as VersionedComputeEngine, h as ComputeStatus, l as ComputeEngineRegistry, m as ComputeOutcomeData, o as ComputePayloadParsers, p as ComputeOutcome, r as GatePayloadParsers, s as GateEngineRegistry, u as ComputeEvaluatorRegistry } from "../parse-gate-payload.js";
1
+ import { a as Result, i as Ok, n as Outcome, r as Err, t as CommonOutcomeStatus } from "../outcome.js";
2
+ import { A as ConditionEvaluationReportTag, C as asPolicyDefinitionId, D as ConditionEvaluationOptions, E as ConditionEvaluationCause, O as ConditionEvaluationReport, S as asPolicyDecisionId, T as asTenantId, a as GateTraceNodeSnapshot, b as SchoolId, c as PolicyViolation, g as CoreObservabilityConfig, h as CoreConfigOptions, i as GateTraceLeafSnapshot, j as ConditionEvaluatorReporter, k as ConditionEvaluationReportLevel, l as VersionedGateEngine, m as CoreConfig, n as GateOutcomeData, o as GateViolationTrace, r as GateStatus, s as PolicyContext, t as GateOutcome, u as GatePayload, v as PolicyDecisionId, w as asSchoolId, x as TenantId, y as PolicyDefinitionId } from "../gate-types.js";
3
+ import { a as PolicyPackage, c as coreConfig, i as PolicyCatalogFactory, n as contextResolverRegistry, o as InMemoryPolicyDefinitionRepository, r as registerNamespacedContextResolvers, s as PolicyHashing, t as PolicyContextPath } from "../path.js";
4
+ import { A as PolicyScope, C as BasePolicyDefinitionProps, D as PolicyDefinition, E as GatePolicyDefinitionProps, F as PolicyKey, I as AsOfSource, L as PolicyKind, M as ScopeChain, N as PolicyCatalog, O as PolicyDefinitionProps, P as PolicyCatalogEntryProps, R as PolicyOwner, T as FindCandidatesParams, _ as ContextResolverResilienceOptions, a as PolicyServiceOptions, b as ContextSeed, c as PolicyEvaluationErrors, d as PolicyAsOfResolver, f as PolicyContextBuilder, g as ContextResolverCircuitBreakerOptions, h as registerNamespacedContextResolversIn, i as PolicyService, j as PolicyScopeMatcher, k as PolicyDefinitionStatus, l as PolicyResolver, m as ContextResolverRegistry, n as PolicyDecision, o as PolicyServiceParams, p as PolicyContextBuilderOptions, r as PolicyEvaluationResult, s as PolicyEvaluationError, t as EvaluateInput, u as DeriveAsOfOptions, v as ContextResolverRetryOptions, w as ComputePolicyDefinitionProps, x as ContextSeedValidator, y as ContextValueResolver, z as PolicyScopeLevel } from "../policy-service.js";
5
+ import { a as ComputeOutcome, c as VersionedComputeEngine, i as ComputeEvaluatorRegistration, n as ComputeRegistry, o as ComputeOutcomeData, r as ComputeEvaluator, s as ComputeStatus, t as GateEngineRegistry } from "../gate-engine-registry.js";
6
+ import { a as ComputePayloadParserRegistry, c as ComputeEvaluatorRegistry, o as ComputePayloadParsers, r as GatePayloadParsers, s as ComputeEngineRegistry } from "../parse-gate-payload.js";
4
7
  export { AsOfSource, BasePolicyDefinitionProps, CommonOutcomeStatus, ComputeEngineRegistry, ComputeEvaluator, ComputeEvaluatorRegistration, ComputeEvaluatorRegistry, ComputeOutcome, ComputeOutcomeData, ComputePayloadParserRegistry, ComputePayloadParsers, ComputePolicyDefinitionProps, ComputeRegistry, ComputeStatus, ConditionEvaluationCause, ConditionEvaluationOptions, ConditionEvaluationReport, ConditionEvaluationReportLevel, ConditionEvaluationReportTag, ConditionEvaluatorReporter, ContextResolverCircuitBreakerOptions, ContextResolverRegistry, ContextResolverResilienceOptions, ContextResolverRetryOptions, ContextSeed, ContextSeedValidator, ContextValueResolver, CoreConfig, CoreConfigOptions, CoreObservabilityConfig, DeriveAsOfOptions, Err, EvaluateInput, FindCandidatesParams, GateEngineRegistry, GateOutcome, GateOutcomeData, GatePayload, GatePayloadParsers, GatePolicyDefinitionProps, GateStatus, GateTraceLeafSnapshot, GateTraceNodeSnapshot, GateViolationTrace, InMemoryPolicyDefinitionRepository, Ok, Outcome, PolicyAsOfResolver, PolicyCatalog, PolicyCatalogEntryProps, PolicyCatalogFactory, PolicyContext, PolicyContextBuilder, PolicyContextBuilderOptions, PolicyContextPath, PolicyDecision, PolicyDecisionId, PolicyDefinition, PolicyDefinitionId, PolicyDefinitionProps, PolicyDefinitionStatus, PolicyEvaluationError, PolicyEvaluationErrors, PolicyEvaluationResult, PolicyHashing, PolicyKey, PolicyKind, PolicyOwner, PolicyPackage, PolicyResolver, PolicyScope, PolicyScopeLevel, PolicyScopeMatcher, PolicyService, PolicyServiceOptions, PolicyServiceParams, PolicyViolation, Result, SchoolId, ScopeChain, TenantId, VersionedComputeEngine, VersionedGateEngine, asPolicyDecisionId, asPolicyDefinitionId, asSchoolId, asTenantId, contextResolverRegistry, coreConfig, registerNamespacedContextResolvers, registerNamespacedContextResolversIn };
@@ -1,4 +1,5 @@
1
- import { c as Ok, d as CoreConfig, l as Result, o as PolicyContextPath, s as Err, u as coreConfig } from "../gate-v1-payload.schema.js";
1
+ import { c as CoreConfig, o as PolicyContextPath, s as coreConfig } from "../gate-v1-payload.schema.js";
2
+ import { n as Ok, r as Result, t as Err } from "../result.js";
2
3
  import { t as Outcome } from "../outcome.js";
3
4
  import { _ as asPolicyDecisionId, a as ContextSeedValidator, b as asTenantId, c as ContextResolverRegistry, d as PolicyDefinition, f as InMemoryPolicyDefinitionRepository, g as PolicyCatalog, h as PolicyCatalogFactory, i as PolicyAsOfResolver, l as registerNamespacedContextResolversIn, m as PolicyKey, n as PolicyEvaluationErrors, o as contextResolverRegistry, p as PolicyScopeMatcher, r as PolicyResolver, s as registerNamespacedContextResolvers, t as PolicyService, u as PolicyContextBuilder, v as asPolicyDefinitionId, x as PolicyHashing, y as asSchoolId } from "../policy-service.js";
4
5
  import { a as ComputeEvaluatorRegistry, c as ComputePayloadParsers, i as ComputeRegistry, o as ComputeEngineRegistry, r as GatePayloadParsers, s as ComputePayloadParserRegistry, t as GateEngineRegistry } from "../gate-engine-registry.js";
@@ -1,36 +1,7 @@
1
- import { C as TenantId, I as Result, S as SchoolId, b as PolicyDecisionId, g as CoreConfig, t as GateOutcome, u as GatePayload, x as PolicyDefinitionId, y as PolicyReporter } from "./gate-types.js";
2
- import { _ as ComputePayload, c as ComputeRegistry, f as ComputeEvaluatorRegistration, p as ComputeOutcome, s as GateEngineRegistry } from "./parse-gate-payload.js";
1
+ import { a as Result } from "./outcome.js";
2
+ import { _ as PolicyReporter, b as SchoolId, t as GateOutcome, u as GatePayload, v as PolicyDecisionId, x as TenantId, y as PolicyDefinitionId } from "./gate-types.js";
3
+ import { a as ComputeOutcome, l as ComputePayload, n as ComputeRegistry, t as GateEngineRegistry } from "./gate-engine-registry.js";
3
4
 
4
- //#region src/core/config/core-config.instance.d.ts
5
-
6
- /**
7
- * Shared instance for the application composition root.
8
- * Use `new CoreConfig()` for isolated runtimes, tests, or multi-tenant hosts.
9
- *
10
- * The default reporter is silent so the core has no runtime logging dependency.
11
- * Hosts can swap in their own `PolicyReporter` via
12
- * `coreConfig.configure({ observability: { reporter } })`.
13
- */
14
- declare const coreConfig: CoreConfig;
15
- //#endregion
16
- //#region src/core/policies/utils/hash.d.ts
17
- /**
18
- * Produces a deterministic SHA-256 hex digest of a canonical JSON representation.
19
- * Object keys are sorted recursively so key order does not affect the hash.
20
- * Array item order is preserved on purpose; callers that treat arrays as sets
21
- * must normalize or sort them before hashing.
22
- *
23
- * Values that JSON.stringify would silently drop or coerce (undefined,
24
- * non-finite numbers, functions, symbols, bigint) are rejected up-front to
25
- * prevent semantically different payloads from collapsing to the same hash.
26
- */
27
- declare class PolicyHashing {
28
- static sha256(input: string): string;
29
- private static assertHashable;
30
- static canonicalJson(value: unknown): string;
31
- static computePayloadHash(payload: unknown, policyKey: string, policyVersion: string): string;
32
- }
33
- //#endregion
34
5
  //#region src/core/policies/catalog/catalog-types.d.ts
35
6
  type PolicyKind = "GATE" | "COMPUTE";
36
7
  type PolicyOwner = "PLATFORM_OWNER" | "TENANT_ADMIN" | "SCHOOL_ADMIN";
@@ -289,39 +260,6 @@ interface PolicyDefinitionRepository {
289
260
  findCandidates(params: FindCandidatesParams): PolicyDefinition[];
290
261
  }
291
262
  //#endregion
292
- //#region src/core/policies/defs/in-memory-policy-definition-repo.d.ts
293
- declare class InMemoryPolicyDefinitionRepository implements PolicyDefinitionRepository {
294
- private readonly definitions;
295
- private readonly definitionsByPolicyKey;
296
- constructor(definitions: readonly PolicyDefinition[]);
297
- findCandidates(params: FindCandidatesParams): PolicyDefinition[];
298
- }
299
- //#endregion
300
- //#region src/core/policies/package/policy-package.d.ts
301
- /**
302
- * Protocol of contribution: a module declares what it wants to add to the
303
- * policy system without the core knowing which module it is.
304
- *
305
- * - catalogEntries: static policy descriptors the catalog will register.
306
- * - definitions: default policy definitions (rules/parameters) to seed.
307
- * - evaluators: compute evaluator registrations keyed by policy/version.
308
- */
309
- interface PolicyPackage {
310
- readonly catalogEntries: readonly PolicyCatalogEntryProps[];
311
- readonly definitions: readonly PolicyDefinition[];
312
- readonly evaluators: readonly ComputeEvaluatorRegistration[];
313
- }
314
- //#endregion
315
- //#region src/core/policies/catalog/catalog.instance.d.ts
316
- /**
317
- * Aggregates catalog entries contributed by each module package into a single
318
- * PolicyCatalog. The core knows nothing about concrete modules — callers
319
- * are responsible for passing all relevant packages at composition time.
320
- */
321
- declare class PolicyCatalogFactory {
322
- static build(packages: readonly PolicyPackage[]): PolicyCatalog;
323
- }
324
- //#endregion
325
263
  //#region src/core/policies/context/context-seed.d.ts
326
264
  /**
327
265
  * Seed data provided by the use case / caller.
@@ -417,26 +355,6 @@ declare class PolicyContextBuilder {
417
355
  build(requirements: readonly string[], seed: ContextSeed): Promise<Result<Record<string, unknown>, string>>;
418
356
  }
419
357
  //#endregion
420
- //#region src/core/policies/context/context-registry.instance.d.ts
421
- /**
422
- * Official instance of the ContextResolverRegistry.
423
- * Use `new ContextResolverRegistry()` plus `registerNamespacedContextResolversIn`
424
- * when each runtime/composition root needs its own isolated resolver graph.
425
- */
426
- declare const contextResolverRegistry: ContextResolverRegistry;
427
- declare function registerNamespacedContextResolvers(namespace: string, resolvers: readonly ContextValueResolver[]): Result<ContextResolverRegistry, string>;
428
- //#endregion
429
- //#region src/core/policies/context/path.d.ts
430
- declare class PolicyContextPath {
431
- private static readonly FORBIDDEN_SEGMENTS;
432
- private static resolve;
433
- private static parseSegments;
434
- private static isPlainRecord;
435
- static getOrAbsent(obj: Record<string, unknown>, path: string): Result<unknown, "absent">;
436
- static has(obj: Record<string, unknown>, path: string): boolean;
437
- static set(obj: Record<string, unknown>, path: string, value: unknown): Result<void, string>;
438
- }
439
- //#endregion
440
358
  //#region src/core/policies/asof/asof.d.ts
441
359
  interface DeriveAsOfOptions {
442
360
  readonly maxFutureYears?: number;
@@ -637,5 +555,5 @@ declare class PolicyService {
637
555
  evaluate(input: EvaluateInput): Promise<Result<PolicyEvaluationResult, PolicyEvaluationError>>;
638
556
  }
639
557
  //#endregion
640
- export { FindCandidatesParams as A, PolicyKey as B, ContextSeed as C, InMemoryPolicyDefinitionRepository as D, PolicyPackage as E, PolicyScope as F, PolicyHashing as G, PolicyKind as H, PolicyScopeMatcher as I, coreConfig as K, ScopeChain as L, PolicyDefinition as M, PolicyDefinitionProps as N, BasePolicyDefinitionProps as O, PolicyDefinitionStatus as P, PolicyCatalog as R, ContextValueResolver as S, PolicyCatalogFactory as T, PolicyOwner as U, AsOfSource as V, PolicyScopeLevel as W, ContextResolverRegistry as _, PolicyServiceOptions as a, ContextResolverResilienceOptions as b, PolicyEvaluationErrors as c, PolicyAsOfResolver as d, PolicyContextPath as f, PolicyContextBuilderOptions as g, PolicyContextBuilder as h, PolicyService as i, GatePolicyDefinitionProps as j, ComputePolicyDefinitionProps as k, PolicyResolver as l, registerNamespacedContextResolvers as m, PolicyDecision as n, PolicyServiceParams as o, contextResolverRegistry as p, PolicyEvaluationResult as r, PolicyEvaluationError as s, EvaluateInput as t, DeriveAsOfOptions as u, registerNamespacedContextResolversIn as v, ContextSeedValidator as w, ContextResolverRetryOptions as x, ContextResolverCircuitBreakerOptions as y, PolicyCatalogEntryProps as z };
558
+ export { PolicyScope as A, BasePolicyDefinitionProps as C, PolicyDefinition as D, GatePolicyDefinitionProps as E, PolicyKey as F, AsOfSource as I, PolicyKind as L, ScopeChain as M, PolicyCatalog as N, PolicyDefinitionProps as O, PolicyCatalogEntryProps as P, PolicyOwner as R, PolicyDefinitionRepository as S, FindCandidatesParams as T, ContextResolverResilienceOptions as _, PolicyServiceOptions as a, ContextSeed as b, PolicyEvaluationErrors as c, PolicyAsOfResolver as d, PolicyContextBuilder as f, ContextResolverCircuitBreakerOptions as g, registerNamespacedContextResolversIn as h, PolicyService as i, PolicyScopeMatcher as j, PolicyDefinitionStatus as k, PolicyResolver as l, ContextResolverRegistry as m, PolicyDecision as n, PolicyServiceParams as o, PolicyContextBuilderOptions as p, PolicyEvaluationResult as r, PolicyEvaluationError as s, EvaluateInput as t, DeriveAsOfOptions as u, ContextResolverRetryOptions as v, ComputePolicyDefinitionProps as w, ContextSeedValidator as x, ContextValueResolver as y, PolicyScopeLevel as z };
641
559
  //# sourceMappingURL=policy-service.d.ts.map
@@ -1,6 +1,12 @@
1
- import { a as stableStringify, i as sha256Hex, n as UnexpectedError, t as ValidationCode } from "./validation-code.js";
1
+ import { t as UnexpectedError } from "./unexpected-error.js";
2
+ import { n as sha256Hex, r as stableStringify } from "./hashing.js";
3
+ import { t as ValidationCode } from "./validation-code.js";
2
4
  import { t as ValidationField } from "./validation-field.js";
3
- import { _ as DomainException, f as SilentPolicyReporter, g as InvariantViolationException, h as isValidDate, l as Result, o as PolicyContextPath } from "./gate-v1-payload.schema.js";
5
+ import { t as InvariantViolationException } from "./invariant-violation-exception.js";
6
+ import { t as InvalidValueException } from "./validation-exception.js";
7
+ import { r as isValidDate } from "./temporal-guards.js";
8
+ import { l as SilentPolicyReporter, o as PolicyContextPath } from "./gate-v1-payload.schema.js";
9
+ import { r as Result } from "./result.js";
4
10
  //#region src/core/policies/utils/hash.ts
5
11
  /**
6
12
  * Produces a deterministic SHA-256 hex digest of a canonical JSON representation.
@@ -49,20 +55,6 @@ var PolicyHashing = class PolicyHashing {
49
55
  }
50
56
  };
51
57
  //#endregion
52
- //#region src/core/exceptions/validation-exception.ts
53
- var ValidationException = class extends DomainException {
54
- constructor(field, code, message) {
55
- super(message);
56
- this.field = field;
57
- this.code = code;
58
- }
59
- };
60
- var InvalidValueException = class extends ValidationException {
61
- constructor(field, code, message) {
62
- super(field, code, message);
63
- }
64
- };
65
- //#endregion
66
58
  //#region src/core/policies/policy-ids.ts
67
59
  const POLICY_DEFINITION_ID_FIELD = ValidationField.of("policyDefinitionId");
68
60
  const POLICY_DECISION_ID_FIELD = ValidationField.of("policyDecisionId");