@cullet/erp-core 1.0.2 → 1.0.4

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 (146) hide show
  1. package/README.md +24 -24
  2. package/dist/gate-engine-registry.js.map +1 -1
  3. package/dist/gate-v1-payload.schema.js +5 -0
  4. package/dist/gate-v1-payload.schema.js.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/outcome.js.map +1 -1
  9. package/dist/policies/engines/v1/gate/index.d.ts +1 -0
  10. package/dist/policies/engines/v1/gate/index.js.map +1 -1
  11. package/dist/policy-service.js.map +1 -1
  12. package/dist/validation-code.js.map +1 -1
  13. package/dist/validation-error.js.map +1 -1
  14. package/dist/validation-field.js.map +1 -1
  15. package/meta.json +67 -67
  16. package/package.json +56 -56
  17. package/src/core/application/commands/command.ts +3 -3
  18. package/src/core/application/commands/requested-by.ts +60 -60
  19. package/src/core/application/index.ts +21 -21
  20. package/src/core/application/policy-error-mapper.ts +54 -54
  21. package/src/core/application/ports/index.ts +6 -6
  22. package/src/core/application/ports/logger.port.ts +4 -4
  23. package/src/core/application/ports/metrics.port.ts +3 -3
  24. package/src/core/application/ports/policy-port.ts +7 -7
  25. package/src/core/application/ports/repository.port.ts +3 -3
  26. package/src/core/application/ports/temporal-repository.port.ts +4 -4
  27. package/src/core/application/ports/tracer.port.ts +7 -7
  28. package/src/core/application/queries/query.ts +13 -13
  29. package/src/core/application/temporal/index.ts +7 -7
  30. package/src/core/application/temporal/temporal-context.ts +20 -20
  31. package/src/core/application/temporal/temporal-use-case.ts +22 -22
  32. package/src/core/application/use-case.ts +10 -10
  33. package/src/core/config/core-config.instance.ts +1 -1
  34. package/src/core/config/core-config.ts +59 -59
  35. package/src/core/config/index.ts +6 -6
  36. package/src/core/config/policy-reporter.ts +31 -31
  37. package/src/core/config/silent-policy-reporter.ts +1 -1
  38. package/src/core/domain/entity.ts +44 -44
  39. package/src/core/domain/rulesets/entity-ruleset.contracts.ts +6 -6
  40. package/src/core/domain/rulesets/ruleset-registry.ts +49 -49
  41. package/src/core/domain/rulesets/ruleset.contracts.ts +6 -6
  42. package/src/core/domain/rulesets/value-object-ruleset.contracts.ts +5 -5
  43. package/src/core/domain/temporal/index.ts +11 -11
  44. package/src/core/domain/temporal/temporal-range.ts +16 -16
  45. package/src/core/domain/temporal/temporal-snapshot.ts +24 -24
  46. package/src/core/domain/temporal/transaction-time.ts +30 -30
  47. package/src/core/domain/temporal/valid-time.ts +29 -29
  48. package/src/core/domain/value-object.ts +16 -16
  49. package/src/core/errors/app-error.ts +64 -64
  50. package/src/core/errors/authentication-error.ts +134 -134
  51. package/src/core/errors/authorization-error.ts +154 -154
  52. package/src/core/errors/business-rule-violation-error.ts +15 -15
  53. package/src/core/errors/conflict-error.ts +202 -201
  54. package/src/core/errors/error-codes.ts +48 -48
  55. package/src/core/errors/idempotency-error.ts +324 -320
  56. package/src/core/errors/index.ts +50 -50
  57. package/src/core/errors/integration-error.ts +120 -120
  58. package/src/core/errors/legacy-incompatible-error.ts +13 -13
  59. package/src/core/errors/not-found-error.ts +14 -14
  60. package/src/core/errors/serialization-error.ts +167 -167
  61. package/src/core/errors/temporal-error.ts +109 -107
  62. package/src/core/errors/types.ts +35 -35
  63. package/src/core/errors/unexpected-error.ts +10 -10
  64. package/src/core/errors/utils/index.ts +2 -2
  65. package/src/core/errors/utils/json-safe.ts +53 -53
  66. package/src/core/errors/validation-error.ts +18 -18
  67. package/src/core/exceptions/business-rule-violation-exception.ts +6 -6
  68. package/src/core/exceptions/domain-exception.ts +5 -5
  69. package/src/core/exceptions/entity-not-found-exception.ts +6 -6
  70. package/src/core/exceptions/invalid-state-transition-exception.ts +8 -8
  71. package/src/core/exceptions/invariant-violation-exception.ts +3 -3
  72. package/src/core/exceptions/validation-code.ts +35 -29
  73. package/src/core/exceptions/validation-exception.ts +19 -19
  74. package/src/core/exceptions/validation-field.ts +20 -19
  75. package/src/core/index.ts +7 -7
  76. package/src/core/policies/asof/asof.ts +47 -47
  77. package/src/core/policies/catalog/catalog.instance.ts +8 -6
  78. package/src/core/policies/catalog/index.ts +4 -4
  79. package/src/core/policies/catalog/policy-catalog-entry.ts +199 -197
  80. package/src/core/policies/catalog/policy-catalog.ts +101 -101
  81. package/src/core/policies/catalog/policy-key.ts +51 -51
  82. package/src/core/policies/context/context-builder.ts +335 -313
  83. package/src/core/policies/context/context-registry.instance.ts +9 -9
  84. package/src/core/policies/context/context-registry.ts +61 -61
  85. package/src/core/policies/context/context-resolver.ts +12 -12
  86. package/src/core/policies/context/context-seed.ts +19 -15
  87. package/src/core/policies/context/index.ts +9 -9
  88. package/src/core/policies/context/path.ts +135 -128
  89. package/src/core/policies/defs/in-memory-policy-definition-repo.ts +56 -55
  90. package/src/core/policies/defs/index.ts +10 -10
  91. package/src/core/policies/defs/policy-definition-repository.ts +3 -3
  92. package/src/core/policies/defs/policy-definition.ts +143 -142
  93. package/src/core/policies/defs/policy-scope.ts +21 -19
  94. package/src/core/policies/defs/policy-semver.ts +51 -51
  95. package/src/core/policies/engines/compute-engine-registry.ts +43 -43
  96. package/src/core/policies/engines/compute-evaluator-registry.ts +20 -20
  97. package/src/core/policies/engines/compute-registry.ts +45 -45
  98. package/src/core/policies/engines/compute-types.ts +15 -15
  99. package/src/core/policies/engines/condition-evaluator-reporter.ts +17 -17
  100. package/src/core/policies/engines/gate-engine-registry.ts +27 -25
  101. package/src/core/policies/engines/gate-types.ts +28 -28
  102. package/src/core/policies/engines/index.ts +28 -28
  103. package/src/core/policies/engines/parse-compute-payload.ts +51 -45
  104. package/src/core/policies/engines/parse-gate-payload.ts +42 -42
  105. package/src/core/policies/engines/v1/compute/compute-engine-v1.ts +39 -37
  106. package/src/core/policies/engines/v1/compute/compute-payload.schema.ts +43 -41
  107. package/src/core/policies/engines/v1/compute/index.ts +6 -6
  108. package/src/core/policies/engines/v1/compute/resolve-decision-table-v1.ts +41 -39
  109. package/src/core/policies/engines/v1/condition-evaluator.ts +557 -504
  110. package/src/core/policies/engines/v1/condition-schema.ts +35 -35
  111. package/src/core/policies/engines/v1/condition-types.ts +21 -21
  112. package/src/core/policies/engines/v1/gate/gate-engine-v1.ts +134 -130
  113. package/src/core/policies/engines/v1/gate/gate-types-v1.ts +5 -5
  114. package/src/core/policies/engines/v1/gate/gate-v1-payload.schema.ts +32 -30
  115. package/src/core/policies/engines/v1/gate/index.ts +4 -4
  116. package/src/core/policies/engines/v1/index.ts +8 -8
  117. package/src/core/policies/index.ts +72 -72
  118. package/src/core/policies/package/policy-package.ts +3 -3
  119. package/src/core/policies/policy-ids.ts +25 -25
  120. package/src/core/policies/resolver/policy-resolver.ts +34 -34
  121. package/src/core/policies/service/index.ts +6 -6
  122. package/src/core/policies/service/policy-evaluation-error.ts +141 -133
  123. package/src/core/policies/service/policy-service.ts +432 -419
  124. package/src/core/policies/utils/date.ts +3 -3
  125. package/src/core/policies/utils/hash.ts +61 -61
  126. package/src/core/result/outcome.ts +131 -126
  127. package/src/core/result/result.ts +130 -127
  128. package/src/core/shared/aggregate-version.ts +5 -5
  129. package/src/core/shared/hashing.ts +18 -18
  130. package/src/core/shared/immutable.ts +29 -29
  131. package/src/core/shared/temporal-guards.ts +9 -9
  132. package/src/core/versioning/domain-event-contracts.ts +40 -40
  133. package/src/core/versioning/version.ts +19 -19
  134. package/src/examples/rulesets/entity/order-creation-rules-v1.ts +18 -18
  135. package/src/examples/rulesets/entity/order-invariants-v1.ts +31 -29
  136. package/src/examples/rulesets/entity/order-invariants-v2.ts +12 -12
  137. package/src/examples/rulesets/entity/order.ts +127 -127
  138. package/src/examples/rulesets/value-object/cpf-rules-v1.ts +41 -39
  139. package/src/examples/rulesets/value-object/cpf-rules-v2.ts +14 -12
  140. package/src/examples/rulesets/value-object/cpf.ts +24 -24
  141. package/src/examples/rulesets/value-object/customer.ts +42 -39
  142. package/src/examples/rulesets/value-object/person-name-rules-v1.ts +27 -27
  143. package/src/examples/rulesets/value-object/person-name-rules-v2.ts +13 -13
  144. package/src/examples/rulesets/value-object/person-name.ts +29 -26
  145. package/src/index.ts +2 -2
  146. package/src/version.ts +1 -1
@@ -3,146 +3,154 @@ import type { PolicyKind } from "../catalog";
3
3
  // ─── Error Union ─────────────────────────────────────────────────────────────
4
4
 
5
5
  export type PolicyEvaluationError =
6
- | {
7
- readonly kind: "INVALID_CONTEXT";
8
- readonly stage: "SEED_VALIDATION" | "AS_OF_DERIVATION" | "CONTEXT_BUILD";
9
- readonly policyKey: string;
10
- readonly message: string;
11
- readonly cause: string;
12
- }
13
- | {
14
- readonly kind: "INVALID_POLICY_KEY";
15
- readonly rawPolicyKey: string;
16
- readonly message: string;
17
- readonly cause: string;
18
- }
19
- | {
20
- readonly kind: "POLICY_NOT_FOUND";
21
- readonly policyKey: string;
22
- readonly message: string;
23
- readonly cause: string;
24
- }
25
- | {
26
- readonly kind: "POLICY_DEFINITION_NOT_FOUND";
27
- readonly policyKey: string;
28
- readonly contextVersion: number;
29
- readonly asOf: Date;
30
- readonly message: string;
31
- readonly cause: string;
32
- }
33
- | {
34
- readonly kind: "POLICY_VARIANT_NOT_FOUND";
35
- readonly policyKey: string;
36
- readonly policyKind: PolicyKind;
37
- readonly payloadSchemaVersion: number;
38
- readonly gateEngineVersion?: number;
39
- readonly computeEngineVersion?: number;
40
- readonly message: string;
41
- readonly cause: string;
42
- }
43
- | {
44
- readonly kind: "ENGINE_FAILURE";
45
- readonly policyKey: string;
46
- readonly engine: PolicyKind;
47
- readonly engineVersion: number;
48
- readonly message: string;
49
- readonly cause: string;
50
- };
6
+ | {
7
+ readonly kind: "INVALID_CONTEXT";
8
+ readonly stage:
9
+ | "SEED_VALIDATION"
10
+ | "AS_OF_DERIVATION"
11
+ | "CONTEXT_BUILD";
12
+ readonly policyKey: string;
13
+ readonly message: string;
14
+ readonly cause: string;
15
+ }
16
+ | {
17
+ readonly kind: "INVALID_POLICY_KEY";
18
+ readonly rawPolicyKey: string;
19
+ readonly message: string;
20
+ readonly cause: string;
21
+ }
22
+ | {
23
+ readonly kind: "POLICY_NOT_FOUND";
24
+ readonly policyKey: string;
25
+ readonly message: string;
26
+ readonly cause: string;
27
+ }
28
+ | {
29
+ readonly kind: "POLICY_DEFINITION_NOT_FOUND";
30
+ readonly policyKey: string;
31
+ readonly contextVersion: number;
32
+ readonly asOf: Date;
33
+ readonly message: string;
34
+ readonly cause: string;
35
+ }
36
+ | {
37
+ readonly kind: "POLICY_VARIANT_NOT_FOUND";
38
+ readonly policyKey: string;
39
+ readonly policyKind: PolicyKind;
40
+ readonly payloadSchemaVersion: number;
41
+ readonly gateEngineVersion?: number;
42
+ readonly computeEngineVersion?: number;
43
+ readonly message: string;
44
+ readonly cause: string;
45
+ }
46
+ | {
47
+ readonly kind: "ENGINE_FAILURE";
48
+ readonly policyKey: string;
49
+ readonly engine: PolicyKind;
50
+ readonly engineVersion: number;
51
+ readonly message: string;
52
+ readonly cause: string;
53
+ };
51
54
 
52
55
  // ─── Factory object ─────────────────────────────────────────────────────────
53
56
 
54
57
  export class PolicyEvaluationErrors {
55
- static invalidContext(
56
- stage: Extract<PolicyEvaluationError, { kind: "INVALID_CONTEXT" }>["stage"],
57
- policyKey: string,
58
- cause: string,
59
- ): PolicyEvaluationError {
60
- return {
61
- kind: "INVALID_CONTEXT",
62
- stage,
63
- policyKey,
64
- message: "Policy evaluation context is invalid",
65
- cause,
66
- };
67
- }
58
+ static invalidContext(
59
+ stage: Extract<
60
+ PolicyEvaluationError,
61
+ { kind: "INVALID_CONTEXT" }
62
+ >["stage"],
63
+ policyKey: string,
64
+ cause: string,
65
+ ): PolicyEvaluationError {
66
+ return {
67
+ kind: "INVALID_CONTEXT",
68
+ stage,
69
+ policyKey,
70
+ message: "Policy evaluation context is invalid",
71
+ cause,
72
+ };
73
+ }
68
74
 
69
- static invalidPolicyKey(
70
- rawPolicyKey: string,
71
- cause: string,
72
- ): PolicyEvaluationError {
73
- return {
74
- kind: "INVALID_POLICY_KEY",
75
- rawPolicyKey,
76
- message: "Policy key is invalid",
77
- cause,
78
- };
79
- }
75
+ static invalidPolicyKey(
76
+ rawPolicyKey: string,
77
+ cause: string,
78
+ ): PolicyEvaluationError {
79
+ return {
80
+ kind: "INVALID_POLICY_KEY",
81
+ rawPolicyKey,
82
+ message: "Policy key is invalid",
83
+ cause,
84
+ };
85
+ }
80
86
 
81
- static policyNotFound(
82
- policyKey: string,
83
- cause: string,
84
- ): PolicyEvaluationError {
85
- return {
86
- kind: "POLICY_NOT_FOUND",
87
- policyKey,
88
- message: "Policy is not registered in the catalog",
89
- cause,
90
- };
91
- }
87
+ static policyNotFound(
88
+ policyKey: string,
89
+ cause: string,
90
+ ): PolicyEvaluationError {
91
+ return {
92
+ kind: "POLICY_NOT_FOUND",
93
+ policyKey,
94
+ message: "Policy is not registered in the catalog",
95
+ cause,
96
+ };
97
+ }
92
98
 
93
- static policyDefinitionNotFound(
94
- policyKey: string,
95
- asOf: Date,
96
- contextVersion: number,
97
- cause: string,
98
- ): PolicyEvaluationError {
99
- return {
100
- kind: "POLICY_DEFINITION_NOT_FOUND",
101
- policyKey,
102
- contextVersion,
103
- asOf,
104
- message: "No published policy definition matched the evaluation inputs",
105
- cause,
106
- };
107
- }
99
+ static policyDefinitionNotFound(
100
+ policyKey: string,
101
+ asOf: Date,
102
+ contextVersion: number,
103
+ cause: string,
104
+ ): PolicyEvaluationError {
105
+ return {
106
+ kind: "POLICY_DEFINITION_NOT_FOUND",
107
+ policyKey,
108
+ contextVersion,
109
+ asOf,
110
+ message:
111
+ "No published policy definition matched the evaluation inputs",
112
+ cause,
113
+ };
114
+ }
108
115
 
109
- static policyVariantNotFound(params: {
110
- readonly policyKey: string;
111
- readonly policyKind: PolicyKind;
112
- readonly payloadSchemaVersion: number;
113
- readonly gateEngineVersion?: number;
114
- readonly computeEngineVersion?: number;
115
- readonly cause: string;
116
- }): PolicyEvaluationError {
117
- return {
118
- kind: "POLICY_VARIANT_NOT_FOUND",
119
- policyKey: params.policyKey,
120
- policyKind: params.policyKind,
121
- payloadSchemaVersion: params.payloadSchemaVersion,
122
- ...(params.gateEngineVersion !== undefined
123
- ? { gateEngineVersion: params.gateEngineVersion }
124
- : {}),
125
- ...(params.computeEngineVersion !== undefined
126
- ? { computeEngineVersion: params.computeEngineVersion }
127
- : {}),
128
- message: "No catalog variant matched the selected policy definition",
129
- cause: params.cause,
130
- };
131
- }
116
+ static policyVariantNotFound(params: {
117
+ readonly policyKey: string;
118
+ readonly policyKind: PolicyKind;
119
+ readonly payloadSchemaVersion: number;
120
+ readonly gateEngineVersion?: number;
121
+ readonly computeEngineVersion?: number;
122
+ readonly cause: string;
123
+ }): PolicyEvaluationError {
124
+ return {
125
+ kind: "POLICY_VARIANT_NOT_FOUND",
126
+ policyKey: params.policyKey,
127
+ policyKind: params.policyKind,
128
+ payloadSchemaVersion: params.payloadSchemaVersion,
129
+ ...(params.gateEngineVersion !== undefined
130
+ ? { gateEngineVersion: params.gateEngineVersion }
131
+ : {}),
132
+ ...(params.computeEngineVersion !== undefined
133
+ ? { computeEngineVersion: params.computeEngineVersion }
134
+ : {}),
135
+ message:
136
+ "No catalog variant matched the selected policy definition",
137
+ cause: params.cause,
138
+ };
139
+ }
132
140
 
133
- static engineFailure(
134
- policyKey: string,
135
- engine: PolicyKind,
136
- engineVersion: number,
137
- cause: string,
138
- ): PolicyEvaluationError {
139
- return {
140
- kind: "ENGINE_FAILURE",
141
- policyKey,
142
- engine,
143
- engineVersion,
144
- message: "Policy engine evaluation failed",
145
- cause,
146
- };
147
- }
141
+ static engineFailure(
142
+ policyKey: string,
143
+ engine: PolicyKind,
144
+ engineVersion: number,
145
+ cause: string,
146
+ ): PolicyEvaluationError {
147
+ return {
148
+ kind: "ENGINE_FAILURE",
149
+ policyKey,
150
+ engine,
151
+ engineVersion,
152
+ message: "Policy engine evaluation failed",
153
+ cause,
154
+ };
155
+ }
148
156
  }