@cullet/erp-core 1.0.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 (182) hide show
  1. package/KIT_CONTEXT.md +39 -0
  2. package/README.md +110 -0
  3. package/dist/errors/index.d.ts +2 -0
  4. package/dist/errors/index.js +3 -0
  5. package/dist/exceptions/validation-field.d.ts +2 -0
  6. package/dist/exceptions/validation-field.js +2 -0
  7. package/dist/gate-engine-registry.js +260 -0
  8. package/dist/gate-engine-registry.js.map +1 -0
  9. package/dist/gate-types.d.ts +307 -0
  10. package/dist/gate-v1-payload.schema.js +677 -0
  11. package/dist/gate-v1-payload.schema.js.map +1 -0
  12. package/dist/index.d.ts +88 -0
  13. package/dist/index.js +153 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/outcome.js +92 -0
  16. package/dist/outcome.js.map +1 -0
  17. package/dist/parse-gate-payload.d.ts +136 -0
  18. package/dist/policies/engines/index.d.ts +3 -0
  19. package/dist/policies/engines/index.js +2 -0
  20. package/dist/policies/engines/v1/gate/index.d.ts +115 -0
  21. package/dist/policies/engines/v1/gate/index.js +84 -0
  22. package/dist/policies/engines/v1/gate/index.js.map +1 -0
  23. package/dist/policies/index.d.ts +4 -0
  24. package/dist/policies/index.js +5 -0
  25. package/dist/policy-service.d.ts +541 -0
  26. package/dist/policy-service.js +992 -0
  27. package/dist/policy-service.js.map +1 -0
  28. package/dist/validation-code.js +210 -0
  29. package/dist/validation-code.js.map +1 -0
  30. package/dist/validation-error.d.ts +686 -0
  31. package/dist/validation-error.js +757 -0
  32. package/dist/validation-error.js.map +1 -0
  33. package/dist/validation-field.d.ts +12 -0
  34. package/dist/validation-field.js +23 -0
  35. package/dist/validation-field.js.map +1 -0
  36. package/meta.json +66 -0
  37. package/package.json +59 -0
  38. package/src/core/application/commands/command.ts +28 -0
  39. package/src/core/application/commands/index.ts +2 -0
  40. package/src/core/application/commands/requested-by.ts +97 -0
  41. package/src/core/application/index.ts +31 -0
  42. package/src/core/application/policy-error-mapper.ts +60 -0
  43. package/src/core/application/ports/index.ts +14 -0
  44. package/src/core/application/ports/logger.port.ts +10 -0
  45. package/src/core/application/ports/metrics.port.ts +9 -0
  46. package/src/core/application/ports/policy-port.ts +20 -0
  47. package/src/core/application/ports/repository.port.ts +7 -0
  48. package/src/core/application/ports/temporal-repository.port.ts +14 -0
  49. package/src/core/application/ports/tracer.port.ts +16 -0
  50. package/src/core/application/queries/index.ts +2 -0
  51. package/src/core/application/queries/query.ts +53 -0
  52. package/src/core/application/temporal/index.ts +11 -0
  53. package/src/core/application/temporal/temporal-context.ts +41 -0
  54. package/src/core/application/temporal/temporal-use-case.ts +41 -0
  55. package/src/core/application/use-case.ts +24 -0
  56. package/src/core/config/core-config.instance.ts +14 -0
  57. package/src/core/config/core-config.ts +87 -0
  58. package/src/core/config/index.ts +12 -0
  59. package/src/core/config/policy-reporter.ts +60 -0
  60. package/src/core/config/silent-policy-reporter.ts +5 -0
  61. package/src/core/domain/entity.ts +69 -0
  62. package/src/core/domain/rulesets/entity-ruleset.contracts.ts +16 -0
  63. package/src/core/domain/rulesets/ruleset-registry.ts +71 -0
  64. package/src/core/domain/rulesets/ruleset.contracts.ts +15 -0
  65. package/src/core/domain/rulesets/value-object-ruleset.contracts.ts +13 -0
  66. package/src/core/domain/temporal/index.ts +18 -0
  67. package/src/core/domain/temporal/temporal-range.ts +53 -0
  68. package/src/core/domain/temporal/temporal-snapshot.ts +47 -0
  69. package/src/core/domain/temporal/transaction-time.ts +60 -0
  70. package/src/core/domain/temporal/valid-time.ts +57 -0
  71. package/src/core/domain/value-object.ts +30 -0
  72. package/src/core/errors/app-error.ts +85 -0
  73. package/src/core/errors/authentication-error.ts +171 -0
  74. package/src/core/errors/authorization-error.ts +204 -0
  75. package/src/core/errors/business-rule-violation-error.ts +28 -0
  76. package/src/core/errors/conflict-error.ts +246 -0
  77. package/src/core/errors/error-codes.ts +60 -0
  78. package/src/core/errors/idempotency-error.ts +372 -0
  79. package/src/core/errors/index.ts +99 -0
  80. package/src/core/errors/integration-error.ts +157 -0
  81. package/src/core/errors/legacy-incompatible-error.ts +26 -0
  82. package/src/core/errors/not-found-error.ts +27 -0
  83. package/src/core/errors/serialization-error.ts +233 -0
  84. package/src/core/errors/temporal-error.ts +145 -0
  85. package/src/core/errors/types.ts +74 -0
  86. package/src/core/errors/unexpected-error.ts +22 -0
  87. package/src/core/errors/utils/index.ts +4 -0
  88. package/src/core/errors/utils/json-safe.ts +93 -0
  89. package/src/core/errors/validation-error.ts +34 -0
  90. package/src/core/exceptions/business-rule-violation-exception.ts +12 -0
  91. package/src/core/exceptions/domain-exception.ts +9 -0
  92. package/src/core/exceptions/entity-not-found-exception.ts +12 -0
  93. package/src/core/exceptions/invalid-state-transition-exception.ts +15 -0
  94. package/src/core/exceptions/invariant-violation-exception.ts +9 -0
  95. package/src/core/exceptions/validation-code.ts +39 -0
  96. package/src/core/exceptions/validation-exception.ts +39 -0
  97. package/src/core/exceptions/validation-field.ts +32 -0
  98. package/src/core/index.ts +15 -0
  99. package/src/core/policies/asof/asof.ts +68 -0
  100. package/src/core/policies/asof/index.ts +2 -0
  101. package/src/core/policies/catalog/catalog-types.ts +12 -0
  102. package/src/core/policies/catalog/catalog.instance.ts +21 -0
  103. package/src/core/policies/catalog/index.ts +11 -0
  104. package/src/core/policies/catalog/policy-catalog-entry.ts +220 -0
  105. package/src/core/policies/catalog/policy-catalog.ts +124 -0
  106. package/src/core/policies/catalog/policy-key.ts +78 -0
  107. package/src/core/policies/context/context-builder.ts +391 -0
  108. package/src/core/policies/context/context-registry.instance.ts +26 -0
  109. package/src/core/policies/context/context-registry.ts +95 -0
  110. package/src/core/policies/context/context-resolver.ts +31 -0
  111. package/src/core/policies/context/context-seed.ts +32 -0
  112. package/src/core/policies/context/index.ts +21 -0
  113. package/src/core/policies/context/path.ts +152 -0
  114. package/src/core/policies/defs/in-memory-policy-definition-repo.ts +73 -0
  115. package/src/core/policies/defs/index.ts +20 -0
  116. package/src/core/policies/defs/policy-definition-repository.ts +8 -0
  117. package/src/core/policies/defs/policy-definition.ts +192 -0
  118. package/src/core/policies/defs/policy-payload.contracts.ts +13 -0
  119. package/src/core/policies/defs/policy-scope.ts +53 -0
  120. package/src/core/policies/defs/policy-semver.ts +83 -0
  121. package/src/core/policies/engines/compute-engine-registry.ts +57 -0
  122. package/src/core/policies/engines/compute-evaluator-registry.ts +28 -0
  123. package/src/core/policies/engines/compute-payload.ts +5 -0
  124. package/src/core/policies/engines/compute-registry.ts +67 -0
  125. package/src/core/policies/engines/compute-types.ts +51 -0
  126. package/src/core/policies/engines/condition-evaluator-reporter.ts +34 -0
  127. package/src/core/policies/engines/gate-engine-registry.ts +38 -0
  128. package/src/core/policies/engines/gate-payload.ts +5 -0
  129. package/src/core/policies/engines/gate-types.ts +63 -0
  130. package/src/core/policies/engines/index.ts +48 -0
  131. package/src/core/policies/engines/parse-compute-payload.ts +71 -0
  132. package/src/core/policies/engines/parse-gate-payload.ts +68 -0
  133. package/src/core/policies/engines/v1/compute/compute-engine-v1.ts +55 -0
  134. package/src/core/policies/engines/v1/compute/compute-payload.schema.ts +75 -0
  135. package/src/core/policies/engines/v1/compute/index.ts +12 -0
  136. package/src/core/policies/engines/v1/compute/resolve-decision-table-v1.ts +54 -0
  137. package/src/core/policies/engines/v1/condition-evaluator.ts +592 -0
  138. package/src/core/policies/engines/v1/condition-schema.ts +50 -0
  139. package/src/core/policies/engines/v1/condition-types.ts +41 -0
  140. package/src/core/policies/engines/v1/gate/gate-engine-v1.ts +157 -0
  141. package/src/core/policies/engines/v1/gate/gate-types-v1.ts +12 -0
  142. package/src/core/policies/engines/v1/gate/gate-v1-payload.schema.ts +46 -0
  143. package/src/core/policies/engines/v1/gate/index.ts +9 -0
  144. package/src/core/policies/engines/v1/index.ts +13 -0
  145. package/src/core/policies/index.ts +132 -0
  146. package/src/core/policies/package/policy-package.ts +17 -0
  147. package/src/core/policies/policy-ids.ts +60 -0
  148. package/src/core/policies/resolver/index.ts +1 -0
  149. package/src/core/policies/resolver/policy-resolver.ts +57 -0
  150. package/src/core/policies/service/index.ts +10 -0
  151. package/src/core/policies/service/policy-evaluation-error.ts +148 -0
  152. package/src/core/policies/service/policy-service.ts +493 -0
  153. package/src/core/policies/utils/date.ts +7 -0
  154. package/src/core/policies/utils/hash.ts +90 -0
  155. package/src/core/policies/utils/index.ts +3 -0
  156. package/src/core/policies/utils/result.ts +4 -0
  157. package/src/core/result/outcome.ts +158 -0
  158. package/src/core/result/result.ts +153 -0
  159. package/src/core/shared/aggregate-version.ts +11 -0
  160. package/src/core/shared/hashing.ts +38 -0
  161. package/src/core/shared/immutable.ts +46 -0
  162. package/src/core/shared/temporal-guards.ts +22 -0
  163. package/src/core/versioning/domain-event-contracts.ts +73 -0
  164. package/src/core/versioning/version.ts +34 -0
  165. package/src/errors/index.ts +1 -0
  166. package/src/examples/rulesets/entity/order-creation-rules-v1.ts +31 -0
  167. package/src/examples/rulesets/entity/order-invariants-v1.ts +48 -0
  168. package/src/examples/rulesets/entity/order-invariants-v2.ts +28 -0
  169. package/src/examples/rulesets/entity/order.ts +162 -0
  170. package/src/examples/rulesets/value-object/cpf-rules-v1.ts +52 -0
  171. package/src/examples/rulesets/value-object/cpf-rules-v2.ts +27 -0
  172. package/src/examples/rulesets/value-object/cpf.ts +37 -0
  173. package/src/examples/rulesets/value-object/customer.ts +67 -0
  174. package/src/examples/rulesets/value-object/person-name-rules-v1.ts +37 -0
  175. package/src/examples/rulesets/value-object/person-name-rules-v2.ts +27 -0
  176. package/src/examples/rulesets/value-object/person-name.ts +39 -0
  177. package/src/exceptions/validation-field.ts +1 -0
  178. package/src/index.ts +11 -0
  179. package/src/policies/engines/index.ts +1 -0
  180. package/src/policies/engines/v1/gate/index.ts +1 -0
  181. package/src/policies/index.ts +1 -0
  182. package/src/version.ts +7 -0
@@ -0,0 +1,686 @@
1
+ import { t as ValidationField } from "./validation-field.js";
2
+
3
+ //#region src/core/errors/types.d.ts
4
+ type ErrorSeverity = "low" | "medium" | "high" | "critical";
5
+ type JsonSafePrimitive = string | number | boolean | null;
6
+ type JsonSafeValue = JsonSafePrimitive | JsonSafeValue[] | {
7
+ [key: string]: JsonSafeValue;
8
+ };
9
+ type JsonSafeRecord = Record<string, JsonSafeValue>;
10
+ /**
11
+ * Options accepted by the AppError constructor.
12
+ * Subclasses can extend or pick from this type.
13
+ */
14
+ type AppErrorOptions = {
15
+ /** Original error or exception that caused this error. */
16
+ cause?: unknown;
17
+ /** Arbitrary key-value metadata (will be sanitized to JSON-safe values). */
18
+ metadata?: Record<string, unknown>;
19
+ /** Error category/type for grouping (e.g., "authentication", "validation"). */
20
+ type?: string;
21
+ /** severity level for alerting/logging prioritization. */
22
+ severity?: ErrorSeverity;
23
+ /**
24
+ * Identifies a single execution "story" in the system. All operations
25
+ * related to the same logical flow must share the same correlationId.
26
+ */
27
+ correlationId?: string;
28
+ /**
29
+ * Identifies a specific technical request attempt (each retry may produce
30
+ * a new requestId), even when the correlationId stays the same.
31
+ */
32
+ requestId?: string;
33
+ /**
34
+ * Identifies a unique business intent (idempotency key); stays the same
35
+ * across technical retries and multiple requests that represent the same intent.
36
+ */
37
+ commandId?: string;
38
+ /** ISO timestamp of when the error was created (defaults to now). */
39
+ createdAtIso?: string;
40
+ /** Safe message that can be exposed to end users (no internal details). */
41
+ publicMessage?: string;
42
+ };
43
+ //#endregion
44
+ //#region src/core/errors/error-codes.d.ts
45
+ declare const ErrorCodes: {
46
+ readonly authentication: {
47
+ readonly missingToken: "sec.authn.missing_token";
48
+ readonly invalidToken: "sec.authn.invalid_token";
49
+ readonly expiredToken: "sec.authn.expired_token";
50
+ readonly invalidCredentials: "sec.authn.invalid_credentials";
51
+ };
52
+ readonly authorization: {
53
+ readonly forbidden: "sec.authz.forbidden";
54
+ readonly policyDenied: "sec.authz.policy_denied";
55
+ readonly missingCapability: "sec.authz.missing_capability";
56
+ readonly outOfScope: "sec.authz.out_of_scope";
57
+ };
58
+ readonly businessRuleViolation: "business_rule_violation";
59
+ readonly conflict: {
60
+ readonly alreadyExists: "conf.already_exists";
61
+ readonly duplicate: "conf.duplicate";
62
+ readonly uniqueViolation: "conf.unique_violation";
63
+ };
64
+ readonly idempotency: {
65
+ readonly keyMissing: "idemp.key_missing";
66
+ readonly inProgress: "idemp.in_progress";
67
+ readonly payloadMismatch: "idemp.payload_mismatch";
68
+ readonly replayNotSupported: "idemp.replay_not_supported";
69
+ };
70
+ readonly integration: {
71
+ readonly timeout: "int.timeout";
72
+ readonly unreachable: "int.unreachable";
73
+ readonly badResponse: "int.bad_response";
74
+ };
75
+ readonly legacyIncompatible: "legacy_incompatible";
76
+ readonly notFound: "not_found";
77
+ readonly serialization: {
78
+ readonly deserializePrefix: "ser.des";
79
+ readonly serializePrefix: "ser.ser";
80
+ };
81
+ readonly temporal: {
82
+ readonly expired: "tmp.expired";
83
+ readonly notYetValid: "tmp.not_yet_valid";
84
+ };
85
+ readonly unexpected: "unexpected";
86
+ readonly validation: "validation_error";
87
+ };
88
+ type SerializationCodeDirection = "deserialize" | "serialize";
89
+ declare function serializationErrorCode(direction: SerializationCodeDirection, category: string): string;
90
+ //#endregion
91
+ //#region src/core/errors/utils/json-safe.d.ts
92
+ /**
93
+ * Ensures metadata is JSON-serializable.
94
+ *
95
+ * **Allowed:** string, number, boolean, null, arrays, and plain objects.
96
+ *
97
+ * **Converted to placeholder:** Date, BigInt, class instances, functions,
98
+ * symbols, undefined.
99
+ *
100
+ * @throws {TypeError} If `input` is not a plain object at the root level.
101
+ */
102
+ declare function assertJsonSafeMetadata(input: unknown): JsonSafeRecord;
103
+ //#endregion
104
+ //#region src/core/errors/app-error.d.ts
105
+ declare abstract class AppError extends Error {
106
+ readonly code: string;
107
+ readonly cause?: unknown;
108
+ readonly metadata?: JsonSafeRecord;
109
+ readonly type?: string;
110
+ readonly severity?: ErrorSeverity;
111
+ readonly createdAtIso: string;
112
+ readonly publicMessage?: string;
113
+ /**
114
+ * Identifies a single execution "story" in the system. All operations
115
+ * related to the same logical flow must share the same correlationId.
116
+ */
117
+ readonly correlationId?: string;
118
+ /**
119
+ * Identifies a specific technical request attempt (each retry may produce
120
+ * a new requestId), even when the correlationId stays the same.
121
+ */
122
+ readonly requestId?: string;
123
+ /**
124
+ * Marks the business intent / idempotency key; stays the same across
125
+ * technical retries and multiple requests that represent the same intent.
126
+ */
127
+ readonly commandId?: string;
128
+ protected constructor(message: string, code: string, options?: AppErrorOptions);
129
+ /**
130
+ * Returns a JSON-safe representation of the error.
131
+ * Does NOT include `cause` by default (to avoid leaking internal details).
132
+ */
133
+ toJSON(): Record<string, unknown>;
134
+ }
135
+ //#endregion
136
+ //#region src/core/errors/authentication-error.d.ts
137
+ type AuthenticationErrorReason = "missing_token" | "malformed_token" | "invalid_token" | "expired_token" | "revoked_token" | "invalid_credentials" | "session_not_found" | "session_expired" | "unknown";
138
+ type AuthenticationErrorMetadata = {
139
+ reason: AuthenticationErrorReason;
140
+ authScheme?: "bearer" | "cookie" | "basic" | "unknown";
141
+ tokenLocation?: "header" | "cookie" | "query" | "unknown";
142
+ expiresAtIso?: string;
143
+ correlationId?: string;
144
+ requestId?: string;
145
+ details?: string;
146
+ };
147
+ type AuthenticationErrorFactoryOptions = Omit<AuthenticationErrorMetadata, "reason"> & Omit<AppErrorOptions, "metadata">;
148
+ declare class AuthenticationError extends AppError {
149
+ readonly reason: AuthenticationErrorReason;
150
+ private constructor();
151
+ static missingToken(options?: AuthenticationErrorFactoryOptions): AuthenticationError;
152
+ static invalidToken(options?: AuthenticationErrorFactoryOptions & {
153
+ cause?: unknown;
154
+ }): AuthenticationError;
155
+ static expiredToken(options?: AuthenticationErrorFactoryOptions & {
156
+ sessionId?: string;
157
+ }): AuthenticationError;
158
+ static invalidCredentials(options?: Pick<AuthenticationErrorFactoryOptions, "correlationId" | "requestId" | "type" | "severity" | "createdAtIso" | "publicMessage">): AuthenticationError;
159
+ }
160
+ //#endregion
161
+ //#region src/core/errors/authorization-error.d.ts
162
+ type AuthorizationErrorReason = "forbidden" | "missing_role" | "missing_capability" | "out_of_scope" | "outside_time_window" | "policy_denied" | "unknown";
163
+ type AuthorizationRequirement = {
164
+ role?: string;
165
+ capability?: string;
166
+ scope?: string;
167
+ };
168
+ type AuthorizationErrorMetadata = {
169
+ reason: AuthorizationErrorReason;
170
+ /** Stable action you evaluated (not an HTTP route — a "business action") */
171
+ action: string;
172
+ /** Resource identification (without leaking the full payload) */
173
+ resource?: {
174
+ type: string;
175
+ id?: string;
176
+ };
177
+ /** Optional: actor (do not include sensitive data) */
178
+ actor?: {
179
+ userId: string;
180
+ role?: string;
181
+ };
182
+ /** Optional: expected requirement */
183
+ required?: AuthorizationRequirement;
184
+ /** Optional: policy (when you already have PolicyEvaluation or similar) */
185
+ policyId?: string;
186
+ policyVersion?: number;
187
+ evaluatedAtIso?: string;
188
+ decision?: "allow" | "deny";
189
+ reasonCode?: string;
190
+ /** Optional: additional non-sensitive info */
191
+ details?: string;
192
+ };
193
+ /**
194
+ * Options for AuthorizationError factory methods.
195
+ * Combines metadata fields (except 'reason') with common AppError options.
196
+ */
197
+ type AuthorizationErrorFactoryOptions = Omit<AuthorizationErrorMetadata, "reason"> & Omit<AppErrorOptions, "metadata">;
198
+ declare class AuthorizationError extends AppError {
199
+ readonly reason: AuthorizationErrorReason;
200
+ private constructor();
201
+ static forbidden(input: AuthorizationErrorFactoryOptions): AuthorizationError;
202
+ static policyDenied(input: AuthorizationErrorFactoryOptions & {
203
+ policyId: string;
204
+ policyVersion: number;
205
+ evaluatedAtIso: string;
206
+ }): AuthorizationError;
207
+ static missingCapability(input: AuthorizationErrorFactoryOptions & {
208
+ required: AuthorizationRequirement;
209
+ }): AuthorizationError;
210
+ static outOfScope(input: AuthorizationErrorFactoryOptions & {
211
+ required?: AuthorizationRequirement;
212
+ }): AuthorizationError;
213
+ }
214
+ //#endregion
215
+ //#region src/core/errors/business-rule-violation-error.d.ts
216
+ declare class BusinessRuleViolationError extends AppError {
217
+ constructor(rule: string, message: string, detail?: Record<string, unknown>, options?: AppErrorOptions);
218
+ }
219
+ //#endregion
220
+ //#region src/core/errors/conflict-error.d.ts
221
+ /**
222
+ * Conflict kinds we want to distinguish semantically.
223
+ */
224
+ type ConflictKind = "already_exists" | "duplicate" | "unique_violation";
225
+ /**
226
+ * Metadata attached to conflicts without exposing sensitive values.
227
+ */
228
+ type ConflictErrorMetadata = {
229
+ kind: ConflictKind;
230
+ entity: string;
231
+ operation?: string;
232
+ field?: string;
233
+ constraintName?: string;
234
+ existingId?: string;
235
+ valueHash?: string;
236
+ valuePreview?: string;
237
+ detectedAtIso?: string;
238
+ correlationId?: string;
239
+ requestId?: string;
240
+ commandId?: string;
241
+ hint?: string;
242
+ };
243
+ type UniqueConstraintViolation = {
244
+ kind: "unique_violation";
245
+ constraintName?: string;
246
+ table?: string;
247
+ columns?: string[];
248
+ };
249
+ declare abstract class ConflictError extends AppError {
250
+ readonly kind: ConflictKind;
251
+ protected constructor(params: {
252
+ message: string;
253
+ code: string;
254
+ kind: ConflictKind;
255
+ metadata: Omit<ConflictErrorMetadata, "kind">;
256
+ cause?: unknown;
257
+ } & AppErrorOptions);
258
+ }
259
+ declare class AlreadyExistsError extends ConflictError {
260
+ private constructor();
261
+ static detected(input: {
262
+ entity: string;
263
+ operation?: string;
264
+ field?: string;
265
+ existingId?: string;
266
+ valueHash?: string;
267
+ valuePreview?: string;
268
+ detectedAtIso?: string;
269
+ correlationId?: string;
270
+ requestId?: string;
271
+ commandId?: string;
272
+ hint?: string;
273
+ cause?: unknown;
274
+ }): AlreadyExistsError;
275
+ }
276
+ declare class DuplicateError extends ConflictError {
277
+ private constructor();
278
+ static detected(input: {
279
+ entity: string;
280
+ operation?: string;
281
+ field?: string;
282
+ constraintName?: string;
283
+ existingId?: string;
284
+ valueHash?: string;
285
+ valuePreview?: string;
286
+ detectedAtIso?: string;
287
+ correlationId?: string;
288
+ requestId?: string;
289
+ commandId?: string;
290
+ hint?: string;
291
+ cause?: unknown;
292
+ }): DuplicateError;
293
+ }
294
+ declare class UniqueConstraintViolationError extends ConflictError {
295
+ private constructor();
296
+ static detected(input: {
297
+ entity: string;
298
+ operation?: string;
299
+ constraintName?: string;
300
+ table?: string;
301
+ columns?: string[];
302
+ detectedAtIso?: string;
303
+ correlationId?: string;
304
+ requestId?: string;
305
+ commandId?: string;
306
+ cause?: unknown;
307
+ }): UniqueConstraintViolationError;
308
+ }
309
+ declare function translateUniqueViolationToDuplicate(input: {
310
+ entity: string;
311
+ operation?: string;
312
+ violation: UniqueConstraintViolation;
313
+ field?: string;
314
+ ctx?: {
315
+ correlationId?: string;
316
+ requestId?: string;
317
+ commandId?: string;
318
+ nowIso?: string;
319
+ };
320
+ cause?: unknown;
321
+ }): DuplicateError;
322
+ //#endregion
323
+ //#region src/core/shared/hashing.d.ts
324
+ declare function sha256Hex(value: string): string;
325
+ declare function stableStringify(value: unknown): string;
326
+ declare function payloadHash(value: unknown): string;
327
+ //#endregion
328
+ //#region src/core/errors/idempotency-error.d.ts
329
+ type IdempotencyFailureKind = "key_missing" | "in_progress" | "payload_mismatch" | "replay_not_supported" | "unknown";
330
+ type IdempotencyErrorMetadata = {
331
+ kind: IdempotencyFailureKind;
332
+ operation: string;
333
+ scope?: string;
334
+ entity?: string;
335
+ keyHash?: string;
336
+ keyPreview?: string;
337
+ incomingPayloadHash?: string;
338
+ existingPayloadHash?: string;
339
+ idempotencyRecordId?: string;
340
+ correlationId?: string;
341
+ requestId?: string;
342
+ commandId?: string;
343
+ detectedAtIso?: string;
344
+ hint?: string;
345
+ details?: string;
346
+ };
347
+ type IdempotencyErrorConstructorInput = {
348
+ message: string;
349
+ code: string;
350
+ kind: IdempotencyFailureKind;
351
+ metadata: Omit<IdempotencyErrorMetadata, "kind">;
352
+ cause?: unknown;
353
+ };
354
+ declare abstract class IdempotencyError extends AppError {
355
+ readonly kind: IdempotencyFailureKind;
356
+ protected constructor(input: IdempotencyErrorConstructorInput);
357
+ static keyMissing(input: {
358
+ operation: string;
359
+ scope?: string;
360
+ entity?: string;
361
+ correlationId?: string;
362
+ requestId?: string;
363
+ commandId?: string;
364
+ detectedAtIso?: string;
365
+ hint?: string;
366
+ details?: string;
367
+ cause?: unknown;
368
+ }): IdempotencyKeyMissingError;
369
+ static inProgress(input: {
370
+ operation: string;
371
+ scope?: string;
372
+ entity?: string;
373
+ key?: string;
374
+ keyHash?: string;
375
+ keyPreview?: string;
376
+ idempotencyRecordId?: string;
377
+ correlationId?: string;
378
+ requestId?: string;
379
+ commandId?: string;
380
+ detectedAtIso?: string;
381
+ hint?: string;
382
+ details?: string;
383
+ cause?: unknown;
384
+ }): IdempotencyInProgressError;
385
+ static payloadMismatch(input: {
386
+ operation: string;
387
+ scope?: string;
388
+ entity?: string;
389
+ key?: string;
390
+ keyHash?: string;
391
+ keyPreview?: string;
392
+ incomingPayloadHash?: string;
393
+ existingPayloadHash?: string;
394
+ idempotencyRecordId?: string;
395
+ correlationId?: string;
396
+ requestId?: string;
397
+ commandId?: string;
398
+ detectedAtIso?: string;
399
+ hint?: string;
400
+ details?: string;
401
+ cause?: unknown;
402
+ }): IdempotencyPayloadMismatchError;
403
+ static replayNotSupported(input: {
404
+ operation: string;
405
+ scope?: string;
406
+ entity?: string;
407
+ key?: string;
408
+ keyHash?: string;
409
+ keyPreview?: string;
410
+ idempotencyRecordId?: string;
411
+ correlationId?: string;
412
+ requestId?: string;
413
+ commandId?: string;
414
+ detectedAtIso?: string;
415
+ hint?: string;
416
+ details?: string;
417
+ cause?: unknown;
418
+ }): IdempotencyReplayNotSupportedError;
419
+ }
420
+ declare class IdempotencyKeyMissingError extends IdempotencyError {
421
+ private constructor();
422
+ static detected(input: {
423
+ operation: string;
424
+ scope?: string;
425
+ entity?: string;
426
+ correlationId?: string;
427
+ requestId?: string;
428
+ commandId?: string;
429
+ detectedAtIso?: string;
430
+ hint?: string;
431
+ details?: string;
432
+ cause?: unknown;
433
+ }): IdempotencyKeyMissingError;
434
+ }
435
+ declare class IdempotencyInProgressError extends IdempotencyError {
436
+ private constructor();
437
+ static detected(input: {
438
+ operation: string;
439
+ scope?: string;
440
+ entity?: string;
441
+ key?: string;
442
+ keyHash?: string;
443
+ keyPreview?: string;
444
+ idempotencyRecordId?: string;
445
+ correlationId?: string;
446
+ requestId?: string;
447
+ commandId?: string;
448
+ detectedAtIso?: string;
449
+ hint?: string;
450
+ details?: string;
451
+ cause?: unknown;
452
+ }): IdempotencyInProgressError;
453
+ }
454
+ declare class IdempotencyPayloadMismatchError extends IdempotencyError {
455
+ private constructor();
456
+ static detected(input: {
457
+ operation: string;
458
+ scope?: string;
459
+ entity?: string;
460
+ key?: string;
461
+ keyHash?: string;
462
+ keyPreview?: string;
463
+ incomingPayloadHash?: string;
464
+ existingPayloadHash?: string;
465
+ idempotencyRecordId?: string;
466
+ correlationId?: string;
467
+ requestId?: string;
468
+ commandId?: string;
469
+ detectedAtIso?: string;
470
+ hint?: string;
471
+ details?: string;
472
+ cause?: unknown;
473
+ }): IdempotencyPayloadMismatchError;
474
+ }
475
+ declare class IdempotencyReplayNotSupportedError extends IdempotencyError {
476
+ private constructor();
477
+ static detected(input: {
478
+ operation: string;
479
+ scope?: string;
480
+ entity?: string;
481
+ key?: string;
482
+ keyHash?: string;
483
+ keyPreview?: string;
484
+ idempotencyRecordId?: string;
485
+ correlationId?: string;
486
+ requestId?: string;
487
+ commandId?: string;
488
+ detectedAtIso?: string;
489
+ hint?: string;
490
+ details?: string;
491
+ cause?: unknown;
492
+ }): IdempotencyReplayNotSupportedError;
493
+ }
494
+ //#endregion
495
+ //#region src/core/errors/integration-error.d.ts
496
+ type IntegrationErrorReason = "timeout" | "unreachable" | "bad_response" | "unknown";
497
+ type IntegrationErrorMetadata = {
498
+ reason: IntegrationErrorReason;
499
+ provider: string;
500
+ operation: string;
501
+ startedAtIso: string;
502
+ durationMs: number;
503
+ detectedAtIso?: string;
504
+ correlationId?: string;
505
+ requestId?: string;
506
+ commandId?: string;
507
+ details?: string;
508
+ statusCode?: number;
509
+ responseCode?: string;
510
+ };
511
+ declare class IntegrationError extends AppError {
512
+ readonly reason: IntegrationErrorReason;
513
+ private constructor();
514
+ static timeout(options: IntegrationErrorTimeoutOptions): IntegrationError;
515
+ static unreachable(options: IntegrationErrorEndpointOptions): IntegrationError;
516
+ static badResponse(options: IntegrationErrorEndpointOptions): IntegrationError;
517
+ }
518
+ type IntegrationErrorBaseOptions = {
519
+ provider: string;
520
+ operation: string;
521
+ startedAtIso: string;
522
+ durationMs: number;
523
+ detectedAtIso?: string;
524
+ correlationId?: string;
525
+ requestId?: string;
526
+ commandId?: string;
527
+ details?: string;
528
+ statusCode?: number;
529
+ responseCode?: string;
530
+ cause?: unknown;
531
+ type?: string;
532
+ severity?: ErrorSeverity;
533
+ createdAtIso?: string;
534
+ publicMessage?: string;
535
+ };
536
+ type IntegrationErrorTimeoutOptions = IntegrationErrorBaseOptions;
537
+ type IntegrationErrorEndpointOptions = IntegrationErrorBaseOptions;
538
+ //#endregion
539
+ //#region src/core/errors/legacy-incompatible-error.d.ts
540
+ declare class LegacyIncompatibleError extends AppError {
541
+ constructor(message: string, context?: Record<string, unknown>, options?: AppErrorOptions);
542
+ }
543
+ //#endregion
544
+ //#region src/core/errors/not-found-error.d.ts
545
+ declare class NotFoundError extends AppError {
546
+ constructor(resource: string, criteria?: Record<string, unknown>, options?: AppErrorOptions);
547
+ }
548
+ //#endregion
549
+ //#region src/core/errors/serialization-error.d.ts
550
+ type SerializationDirection = "serialize" | "deserialize";
551
+ type SerializationFailureCategory = "invalid_json" | "invalid_shape" | "missing_field" | "unexpected_field" | "invalid_type" | "schema_version_missing" | "schema_version_unsupported" | "mapping_not_implemented" | "contract_mismatch" | "parse_failed" | "stringify_failed" | "unknown";
552
+ type SerializationBoundary = "http_in" | "http_out" | "graphql_in" | "graphql_out" | "dto_to_domain" | "domain_to_dto" | "persistence_to_domain" | "domain_to_persistence" | "event_in" | "event_out" | "projection" | "unknown";
553
+ /**
554
+ * Metadata shared by serialization/deserialization failures. Payload previews must be sanitized.
555
+ */
556
+ type SerializationErrorMetadata = {
557
+ direction: SerializationDirection;
558
+ category: SerializationFailureCategory;
559
+ boundary: SerializationBoundary;
560
+ contract: string;
561
+ schemaVersion?: number | string;
562
+ path?: string;
563
+ payloadPreview?: string;
564
+ correlationId?: string;
565
+ requestId?: string;
566
+ commandId?: string;
567
+ hint?: string;
568
+ details?: string;
569
+ };
570
+ type SerializationErrorOptions = Omit<AppErrorOptions, "metadata"> & {
571
+ message: string;
572
+ code: string;
573
+ metadata: Omit<SerializationErrorMetadata, "direction" | "category">;
574
+ direction: SerializationDirection;
575
+ category: SerializationFailureCategory;
576
+ };
577
+ declare abstract class SerializationError extends AppError {
578
+ readonly direction: SerializationDirection;
579
+ readonly category: SerializationFailureCategory;
580
+ readonly boundary: SerializationBoundary;
581
+ readonly contract: string;
582
+ protected constructor(input: SerializationErrorOptions);
583
+ }
584
+ declare class SerializationInError extends SerializationError {
585
+ private constructor();
586
+ static failure(category: SerializationFailureCategory, metadata: Omit<SerializationErrorMetadata, "direction" | "category"> & {
587
+ cause?: unknown;
588
+ }): SerializationInError;
589
+ }
590
+ declare class SerializationOutError extends SerializationError {
591
+ private constructor();
592
+ static failure(category: SerializationFailureCategory, metadata: Omit<SerializationErrorMetadata, "direction" | "category"> & {
593
+ cause?: unknown;
594
+ }): SerializationOutError;
595
+ }
596
+ declare class SerializationCodes {
597
+ static code(direction: SerializationDirection, category: SerializationFailureCategory): string;
598
+ }
599
+ declare class SerializationMessages {
600
+ static message(direction: SerializationDirection, category: SerializationFailureCategory): string;
601
+ }
602
+ declare function safePreview(value: unknown, limit?: number): string | undefined;
603
+ //#endregion
604
+ //#region src/core/errors/temporal-error.d.ts
605
+ type TemporalKind = "expired" | "not_yet_valid";
606
+ type TemporalPrecision = "EXACT" | "ESTIMATED" | "UNKNOWN" | "APPROXIMATE";
607
+ type TemporalErrorMetadata = {
608
+ resourceType: string;
609
+ resourceId?: string;
610
+ operation?: string;
611
+ validFromIso?: string | null;
612
+ validUntilIso?: string | null;
613
+ evaluatedAtIso: string;
614
+ policyId?: string;
615
+ precision?: TemporalPrecision;
616
+ hint?: string;
617
+ details?: string;
618
+ correlationId?: string;
619
+ requestId?: string;
620
+ commandId?: string;
621
+ };
622
+ type TemporalErrorOptions = {
623
+ message: string;
624
+ code: string;
625
+ kind: TemporalKind;
626
+ metadata: TemporalErrorMetadata;
627
+ } & AppErrorOptions;
628
+ declare abstract class TemporalError extends AppError {
629
+ readonly kind: TemporalKind;
630
+ readonly resourceType: string;
631
+ readonly evaluatedAtIso: string;
632
+ protected constructor(input: TemporalErrorOptions);
633
+ }
634
+ type TemporalCreationInput = TemporalErrorMetadata & Partial<Omit<AppErrorOptions, "metadata">> & {
635
+ cause?: unknown;
636
+ };
637
+ declare class ExpiredError extends TemporalError {
638
+ private constructor();
639
+ static detected(input: TemporalCreationInput): ExpiredError;
640
+ }
641
+ declare class NotYetValidError extends TemporalError {
642
+ private constructor();
643
+ static detected(input: TemporalCreationInput): NotYetValidError;
644
+ }
645
+ declare function evaluateTemporalWindow(input: {
646
+ validFromIso?: string | null;
647
+ validUntilIso?: string | null;
648
+ evaluatedAtIso: string;
649
+ }): {
650
+ expired: boolean;
651
+ notYetValid: boolean;
652
+ } | null;
653
+ //#endregion
654
+ //#region src/core/errors/unexpected-error.d.ts
655
+ declare class UnexpectedError extends AppError {
656
+ constructor(message?: string, cause?: unknown, options?: Omit<AppErrorOptions, "cause">);
657
+ }
658
+ //#endregion
659
+ //#region src/core/exceptions/validation-code.d.ts
660
+ declare class ValidationCode {
661
+ readonly value: string;
662
+ private constructor();
663
+ static of(value: string): ValidationCode;
664
+ static readonly BLANK: ValidationCode;
665
+ static readonly REQUIRED: ValidationCode;
666
+ static readonly INVALID_FORMAT: ValidationCode;
667
+ static readonly INVALID_CHARACTERS: ValidationCode;
668
+ static readonly INVALID_LENGTH: ValidationCode;
669
+ static readonly TOO_SHORT: ValidationCode;
670
+ static readonly TOO_LONG: ValidationCode;
671
+ static readonly OUT_OF_RANGE: ValidationCode;
672
+ static readonly INVALID_CHECKSUM: ValidationCode;
673
+ static readonly INVALID_CHECKING_DIGIT: ValidationCode;
674
+ static readonly ALREADY_EXISTS: ValidationCode;
675
+ static readonly NOT_FOUND: ValidationCode;
676
+ static readonly NOT_ALLOWED: ValidationCode;
677
+ static readonly UNEXPECTED: ValidationCode;
678
+ }
679
+ //#endregion
680
+ //#region src/core/errors/validation-error.d.ts
681
+ declare class ValidationError extends AppError {
682
+ constructor(field: ValidationField, code: ValidationCode, message: string, options?: AppErrorOptions);
683
+ }
684
+ //#endregion
685
+ export { ErrorCodes as $, IdempotencyPayloadMismatchError as A, UniqueConstraintViolation as B, IntegrationErrorMetadata as C, IdempotencyFailureKind as D, IdempotencyErrorMetadata as E, AlreadyExistsError as F, AuthorizationErrorMetadata as G, translateUniqueViolationToDuplicate as H, ConflictError as I, AuthenticationError as J, AuthorizationErrorReason as K, ConflictErrorMetadata as L, payloadHash as M, sha256Hex as N, IdempotencyInProgressError as O, stableStringify as P, assertJsonSafeMetadata as Q, ConflictKind as R, IntegrationError as S, IdempotencyError as T, BusinessRuleViolationError as U, UniqueConstraintViolationError as V, AuthorizationError as W, AuthenticationErrorReason as X, AuthenticationErrorMetadata as Y, AppError as Z, SerializationMessages as _, TemporalError as a, JsonSafeValue as at, NotFoundError as b, TemporalPrecision as c, SerializationCodes as d, serializationErrorCode as et, SerializationDirection as f, SerializationInError as g, SerializationFailureCategory as h, NotYetValidError as i, JsonSafeRecord as it, IdempotencyReplayNotSupportedError as j, IdempotencyKeyMissingError as k, evaluateTemporalWindow as l, SerializationErrorMetadata as m, UnexpectedError as n, ErrorSeverity as nt, TemporalErrorMetadata as o, SerializationError as p, AuthorizationRequirement as q, ExpiredError as r, JsonSafePrimitive as rt, TemporalKind as s, ValidationError as t, AppErrorOptions as tt, SerializationBoundary as u, SerializationOutError as v, IntegrationErrorReason as w, LegacyIncompatibleError as x, safePreview as y, DuplicateError as z };
686
+ //# sourceMappingURL=validation-error.d.ts.map