@cullet/erp-core 1.0.10 → 1.1.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 (62) hide show
  1. package/KIT_CONTEXT.md +67 -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 +2 -0
  6. package/dist/errors/index.d.ts +2 -1
  7. package/dist/errors/index.js +4 -2
  8. package/dist/gate-engine-registry.d.ts +80 -0
  9. package/dist/gate-v1-payload.schema.js +2 -28
  10. package/dist/gate-v1-payload.schema.js.map +1 -1
  11. package/dist/hashing.js +49 -0
  12. package/dist/hashing.js.map +1 -0
  13. package/dist/index.d.ts +122 -45
  14. package/dist/index.js +104 -85
  15. package/dist/index.js.map +1 -1
  16. package/dist/not-found-error.js +54 -0
  17. package/dist/not-found-error.js.map +1 -0
  18. package/dist/outcome.js +1 -1
  19. package/dist/parse-gate-payload.d.ts +3 -78
  20. package/dist/path.d.ts +89 -0
  21. package/dist/policies/engines/index.d.ts +2 -1
  22. package/dist/policies/index.d.ts +4 -2
  23. package/dist/policy-service.d.ts +102 -86
  24. package/dist/policy-service.js +78 -16
  25. package/dist/policy-service.js.map +1 -1
  26. package/dist/temporal-guards.js +30 -0
  27. package/dist/temporal-guards.js.map +1 -0
  28. package/dist/temporal-use-case.d.ts +309 -0
  29. package/dist/temporal-use-case.js +284 -0
  30. package/dist/temporal-use-case.js.map +1 -0
  31. package/dist/validation-code.js +34 -47
  32. package/dist/validation-code.js.map +1 -1
  33. package/dist/validation-error.d.ts +171 -74
  34. package/dist/validation-error.js +152 -38
  35. package/dist/validation-error.js.map +1 -1
  36. package/dist/validation-exception.js +18 -0
  37. package/dist/validation-exception.js.map +1 -0
  38. package/meta.json +4 -2
  39. package/package.json +5 -1
  40. package/src/application/index.ts +1 -0
  41. package/src/core/application/commands/index.ts +1 -0
  42. package/src/core/application/index.ts +12 -3
  43. package/src/core/application/ports/index.ts +2 -2
  44. package/src/core/application/ports/policy-port.ts +13 -3
  45. package/src/core/application/ports/repository.port.ts +37 -1
  46. package/src/core/application/temporal/temporal-use-case.ts +14 -2
  47. package/src/core/application/use-case.ts +133 -2
  48. package/src/core/domain/entity.ts +71 -0
  49. package/src/core/domain/value-object.ts +41 -0
  50. package/src/core/errors/app-error.ts +33 -0
  51. package/src/core/errors/authorization-error.ts +43 -0
  52. package/src/core/errors/conflict-error.ts +69 -0
  53. package/src/core/errors/integration-error.ts +25 -0
  54. package/src/core/errors/not-found-error.ts +14 -0
  55. package/src/core/errors/validation-error.ts +18 -0
  56. package/src/core/index.ts +1 -10
  57. package/src/core/policies/catalog/policy-catalog.ts +36 -0
  58. package/src/core/policies/resolver/policy-resolver.ts +10 -0
  59. package/src/core/policies/service/policy-service.ts +53 -0
  60. package/src/examples/application/cancel-order.example.ts +124 -0
  61. package/src/examples/application/in-memory-account-repository.example.ts +73 -0
  62. package/src/version.ts +1 -1
package/dist/index.js CHANGED
@@ -1,74 +1,56 @@
1
- import { a as stableStringify, c as ErrorCodes, i as sha256Hex, l as serializationErrorCode, n as UnexpectedError, o as AppError, r as payloadHash, s as assertJsonSafeMetadata } from "./validation-code.js";
2
- import { C as UniqueConstraintViolationError, D as AuthenticationError, E as AuthorizationError, S as DuplicateError, T as BusinessRuleViolationError, _ as IdempotencyKeyMissingError, a as evaluateTemporalWindow, b as AlreadyExistsError, c as SerializationInError, d as safePreview, f as NotFoundError, g as IdempotencyInProgressError, h as IdempotencyError, i as TemporalError, l as SerializationMessages, m as IntegrationError, n as ExpiredError, o as SerializationCodes, p as LegacyIncompatibleError, r as NotYetValidError, s as SerializationError, t as ValidationError, u as SerializationOutError, v as IdempotencyPayloadMismatchError, w as translateUniqueViolationToDuplicate, x as ConflictError, y as IdempotencyReplayNotSupportedError } from "./validation-error.js";
1
+ import { a as ErrorCodes, i as assertJsonSafeMetadata, n as UnexpectedError, o as serializationErrorCode, r as AppError } from "./validation-code.js";
2
+ import { C as translateUniqueViolationToDuplicate, S as UniqueConstraintViolationError, T as AuthenticationError, _ as IdempotencyPayloadMismatchError, a as evaluateTemporalWindow, b as ConflictError, c as SerializationInError, d as safePreview, f as LegacyIncompatibleError, g as IdempotencyKeyMissingError, h as IdempotencyInProgressError, i as TemporalError, l as SerializationMessages, m as IdempotencyError, n as ExpiredError, o as SerializationCodes, p as IntegrationError, r as NotYetValidError, s as SerializationError, t as ValidationError, u as SerializationOutError, v as IdempotencyReplayNotSupportedError, w as AuthorizationError, x as DuplicateError, y as AlreadyExistsError } from "./validation-error.js";
3
+ import { n as BusinessRuleViolationError, t as NotFoundError } from "./not-found-error.js";
4
+ import { n as sha256Hex, r as stableStringify, t as payloadHash } from "./hashing.js";
3
5
  import { t as ValidationField } from "./validation-field.js";
4
- import { c as Ok, d as CoreConfig, g as InvariantViolationException, l as Result, m as cloneDate, o as PolicyContextPath, p as assertValidDate, s as Err, u as coreConfig } from "./gate-v1-payload.schema.js";
6
+ import { a as Query, c as RequestedBy, d as version$1, i as makeImmutable, l as UseCase, n as assertTemporalContext, o as mapPolicyEvaluationError, r as createTemporalContext, s as Command, t as TemporalUseCase, u as __decorate } from "./temporal-use-case.js";
7
+ import { i as InvariantViolationException, n as cloneDate, t as assertValidDate } from "./temporal-guards.js";
8
+ 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";
5
9
  import { t as Outcome } from "./outcome.js";
6
10
  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";
7
11
  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";
8
12
  //#region src/version.ts
9
- const version$1 = "1.0.10";
10
- //#endregion
11
- //#region src/core/application/policy-error-mapper.ts
12
- function mapPolicyEvaluationError(err) {
13
- switch (err.kind) {
14
- case "INVALID_CONTEXT": return new BusinessRuleViolationError(`policy.${err.stage.toLowerCase()}`, err.message, {
15
- policyKey: err.policyKey,
16
- stage: err.stage
17
- }, { cause: err.cause });
18
- case "INVALID_POLICY_KEY": return new BusinessRuleViolationError("policy.invalid_key", err.message, { rawPolicyKey: err.rawPolicyKey }, { cause: err.cause });
19
- case "POLICY_NOT_FOUND": return new NotFoundError("Policy", { policyKey: err.policyKey }, { cause: err.cause });
20
- case "POLICY_DEFINITION_NOT_FOUND": return new NotFoundError("PolicyDefinition", {
21
- policyKey: err.policyKey,
22
- contextVersion: err.contextVersion,
23
- asOf: err.asOf.toISOString()
24
- }, { cause: err.cause });
25
- case "POLICY_VARIANT_NOT_FOUND": return new NotFoundError("PolicyVariant", {
26
- policyKey: err.policyKey,
27
- policyKind: err.policyKind,
28
- payloadSchemaVersion: err.payloadSchemaVersion
29
- }, { cause: err.cause });
30
- case "ENGINE_FAILURE": return new UnexpectedError(err.message, err.cause, { metadata: {
31
- policyKey: err.policyKey,
32
- engine: err.engine,
33
- engineVersion: err.engineVersion
34
- } });
35
- }
36
- }
13
+ const version = "1.1.0";
37
14
  //#endregion
38
15
  //#region src/core/shared/aggregate-version.ts
39
16
  function assertValidAggregateVersion(aggregateVersion) {
40
17
  if (!Number.isInteger(aggregateVersion) || aggregateVersion < 0) throw new InvariantViolationException(`aggregateVersion must be a non-negative integer. Received: ${aggregateVersion}`);
41
18
  }
42
19
  //#endregion
43
- //#region src/core/versioning/version.ts
44
- const CONTRACT_VERSION_PROPERTY = "CONTRACT_VERSION";
45
- const CONTRACT_VERSION_PATTERN = /^\d+\.\d+$/;
46
- function version(contractVersion) {
47
- if (!CONTRACT_VERSION_PATTERN.test(contractVersion)) throw new TypeError(`Invalid contract version "${contractVersion}". Expected MAJOR.MINOR.`);
48
- return (target) => {
49
- Object.defineProperty(target, CONTRACT_VERSION_PROPERTY, {
50
- value: contractVersion,
51
- writable: false,
52
- configurable: false,
53
- enumerable: false
54
- });
55
- };
56
- }
57
- //#endregion
58
- //#region \0@oxc-project+runtime@0.132.0/helpers/decorate.js
59
- function __decorate(decorators, target, key, desc) {
60
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
62
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
63
- return c > 3 && r && Object.defineProperty(target, key, r), r;
64
- }
65
- //#endregion
66
20
  //#region src/core/domain/entity.ts
67
21
  var _Entity;
22
+ /**
23
+ * Base class for domain entities — objects defined by a stable identity rather
24
+ * than by their attributes. Two entities are "the same" when their `id`
25
+ * matches, even if every other field differs; this is the opposite of a
26
+ * {@link ValueObject}, which is defined entirely by its contents.
27
+ *
28
+ * The class owns the bookkeeping common to every aggregate root: a creation
29
+ * timestamp that never changes, a last-modified timestamp, and an
30
+ * `aggregateVersion` counter used for optimistic concurrency control. All three
31
+ * are validated on construction and the dates are defensively cloned, so an
32
+ * entity can never be built into — or leak — an inconsistent temporal state.
33
+ *
34
+ * @typeParam TIdentifier - The identity type (e.g. a branded string id or a VO).
35
+ */
68
36
  let Entity = class Entity {
69
37
  static {
70
38
  _Entity = this;
71
39
  }
40
+ /**
41
+ * Reconstitutes an entity from its persisted {@link EntityState}.
42
+ *
43
+ * Validates the temporal invariants up front so an invalid entity is
44
+ * impossible to construct: both dates must be valid, the aggregate version
45
+ * must be a non-negative integer, and `updatedAt` may not predate
46
+ * `createdAt`. Both dates are cloned on the way in so a later mutation of
47
+ * the caller's `Date` objects cannot reach into the entity's internal state.
48
+ *
49
+ * Declared `protected` because entities are reconstituted through a
50
+ * subclass factory, never instantiated directly by application code.
51
+ *
52
+ * @throws {InvariantViolationException} When `updatedAt` is earlier than `createdAt`.
53
+ */
72
54
  constructor(state) {
73
55
  assertValidDate("createdAt", state.createdAt);
74
56
  assertValidDate("updatedAt", state.updatedAt);
@@ -79,21 +61,56 @@ let Entity = class Entity {
79
61
  this._updatedAt = cloneDate(state.updatedAt);
80
62
  this._aggregateVersion = state.aggregateVersion;
81
63
  }
64
+ /** The entity's stable identity — the basis for equality between entities. */
82
65
  get id() {
83
66
  return this._id;
84
67
  }
68
+ /**
69
+ * When the entity was first created.
70
+ *
71
+ * Returns a clone so callers cannot mutate the entity's internal `Date`;
72
+ * the value is fixed at construction and never changes thereafter.
73
+ */
85
74
  get createdAt() {
86
75
  return cloneDate(this._createdAt);
87
76
  }
77
+ /**
78
+ * When the entity was last modified.
79
+ *
80
+ * Returns a clone for the same encapsulation reason as {@link createdAt};
81
+ * the underlying value advances only through {@link markAsModified}.
82
+ */
88
83
  get updatedAt() {
89
84
  return cloneDate(this._updatedAt);
90
85
  }
86
+ /**
87
+ * Monotonic counter incremented on every mutation, used for optimistic
88
+ * concurrency control: a writer reads this value, and the persistence layer
89
+ * rejects the write if the stored version has moved on in the meantime.
90
+ */
91
91
  get aggregateVersion() {
92
92
  return this._aggregateVersion;
93
93
  }
94
+ /**
95
+ * The schema/contract version stamped on this entity type by the
96
+ * `@version` decorator — used to detect and migrate state persisted under
97
+ * an older shape.
98
+ */
94
99
  get contractVersion() {
95
100
  return _Entity.CONTRACT_VERSION;
96
101
  }
102
+ /**
103
+ * The single seam through which an entity records a mutation: it advances
104
+ * `updatedAt` and bumps {@link aggregateVersion} by one. Subclasses must
105
+ * call this from every state-changing method so the version counter stays
106
+ * an accurate optimistic-lock token.
107
+ *
108
+ * @param updatedAt - The modification instant; defaults to now. Validated
109
+ * and required not to predate `createdAt`, preserving the same invariant
110
+ * the constructor enforces.
111
+ * @returns The new aggregate version after the increment.
112
+ * @throws {InvariantViolationException} When `updatedAt` is earlier than `createdAt`.
113
+ */
97
114
  markAsModified(updatedAt = /* @__PURE__ */ new Date()) {
98
115
  assertValidDate("updatedAt", updatedAt);
99
116
  if (updatedAt.getTime() < this._createdAt.getTime()) throw new InvariantViolationException("updatedAt cannot be earlier than createdAt");
@@ -102,44 +119,41 @@ let Entity = class Entity {
102
119
  return this._aggregateVersion;
103
120
  }
104
121
  };
105
- Entity = _Entity = __decorate([version("1.0")], Entity);
106
- //#endregion
107
- //#region src/core/shared/immutable.ts
108
- function deepFreeze(value) {
109
- return deepFreezeInternal(value, /* @__PURE__ */ new WeakSet());
110
- }
111
- function deepFreezeInternal(value, seen) {
112
- if (typeof value !== "object" || value === null || value instanceof Date) return value;
113
- if (seen.has(value)) return value;
114
- seen.add(value);
115
- if (Array.isArray(value)) {
116
- for (const item of value) deepFreezeInternal(item, seen);
117
- return Object.freeze(value);
118
- }
119
- const objectValue = value;
120
- for (const propertyKey of Reflect.ownKeys(objectValue)) deepFreezeInternal(objectValue[propertyKey], seen);
121
- return Object.freeze(value);
122
- }
123
- function makeImmutable(value) {
124
- if (typeof value !== "object" || value === null) return value;
125
- let snapshot;
126
- try {
127
- snapshot = structuredClone(value);
128
- } catch (error) {
129
- throw new InvariantViolationException(`makeImmutable requires a structured-cloneable value: ${error instanceof Error ? error.message : String(error)}`);
130
- }
131
- return deepFreeze(snapshot);
132
- }
122
+ Entity = _Entity = __decorate([version$1("1.0")], Entity);
133
123
  //#endregion
134
124
  //#region src/core/domain/value-object.ts
135
125
  var _ValueObject;
126
+ /**
127
+ * Base class for value objects — domain concepts defined entirely by their
128
+ * contents, with no identity of their own. Two value objects are
129
+ * interchangeable when they hold equal data, which is the opposite of an
130
+ * {@link Entity} (compared by id). Money, a CPF, a date range: replacing one
131
+ * instance with an equal one changes nothing about the model.
132
+ *
133
+ * Immutability is the defining guarantee here. The wrapped `value` is
134
+ * deep-frozen on construction, so a value object can be shared freely without
135
+ * any risk of a consumer mutating shared state. Subclasses seal the instance
136
+ * itself with {@link finalize} once their own fields are set.
137
+ *
138
+ * @typeParam T - The shape of the wrapped data.
139
+ * @typeParam P - The primitive form produced by {@link toPrimitive} / {@link toJSON}.
140
+ */
136
141
  let ValueObject = class ValueObject {
137
142
  static {
138
143
  _ValueObject = this;
139
144
  }
145
+ /**
146
+ * Wraps `value`, deep-freezing it so the value object is immutable from the
147
+ * moment it exists. Declared `protected` because value objects are built
148
+ * through a validating subclass factory, never instantiated directly.
149
+ */
140
150
  constructor(value) {
141
151
  this.value = makeImmutable(value);
142
152
  }
153
+ /**
154
+ * The schema/contract version stamped on this value-object type by the
155
+ * `@version` decorator — used to detect state persisted under an older shape.
156
+ */
143
157
  get contractVersion() {
144
158
  return _ValueObject.CONTRACT_VERSION;
145
159
  }
@@ -156,20 +170,25 @@ let ValueObject = class ValueObject {
156
170
  finalize() {
157
171
  Object.freeze(this);
158
172
  }
173
+ /**
174
+ * Hook for `JSON.stringify`. Delegates to {@link toPrimitive} so a value
175
+ * object serializes to its primitive form rather than exposing the internal
176
+ * `value` wrapper.
177
+ */
159
178
  toJSON() {
160
179
  return this.toPrimitive();
161
180
  }
162
181
  };
163
- ValueObject = _ValueObject = __decorate([version("1.0")], ValueObject);
182
+ ValueObject = _ValueObject = __decorate([version$1("1.0")], ValueObject);
164
183
  //#endregion
165
184
  //#region src/index.ts
166
185
  const ERP_CORE_NAME = "erp-core";
167
- const ERP_CORE_VERSION = version$1;
186
+ const ERP_CORE_VERSION = version;
168
187
  const erpCoreRelease = {
169
188
  name: ERP_CORE_NAME,
170
189
  version: ERP_CORE_VERSION
171
190
  };
172
191
  //#endregion
173
- export { AlreadyExistsError, AppError, AuthenticationError, AuthorizationError, BusinessRuleViolationError, ComputeEngineRegistry, ComputeEvaluatorRegistry, ComputePayloadParserRegistry, ComputePayloadParsers, ComputeRegistry, ConflictError, ContextResolverRegistry, ContextSeedValidator, CoreConfig, SerializationInError as DeserializationError, SerializationInError, DuplicateError, ERP_CORE_NAME, ERP_CORE_VERSION, Entity, Err, ErrorCodes, ExpiredError, GateEngineRegistry, GatePayloadParsers, IdempotencyError, IdempotencyInProgressError, IdempotencyKeyMissingError, IdempotencyPayloadMismatchError, IdempotencyReplayNotSupportedError, InMemoryPolicyDefinitionRepository, IntegrationError, LegacyIncompatibleError, NotFoundError, NotYetValidError, Ok, Outcome, PolicyAsOfResolver, PolicyCatalog, PolicyCatalogFactory, PolicyContextBuilder, PolicyContextPath, PolicyDefinition, PolicyEvaluationErrors, PolicyHashing, PolicyKey, PolicyResolver, PolicyScopeMatcher, PolicyService, Result, SerializationCodes, SerializationError, SerializationMessages, SerializationOutError, TemporalError, UnexpectedError, UniqueConstraintViolationError, ValidationError, ValidationField, ValueObject, asPolicyDecisionId, asPolicyDefinitionId, asSchoolId, asTenantId, assertJsonSafeMetadata, contextResolverRegistry, coreConfig, erpCoreRelease, evaluateTemporalWindow, mapPolicyEvaluationError, payloadHash, registerNamespacedContextResolvers, registerNamespacedContextResolversIn, safePreview, serializationErrorCode, sha256Hex, stableStringify, translateUniqueViolationToDuplicate };
192
+ export { AlreadyExistsError, AppError, AuthenticationError, AuthorizationError, BusinessRuleViolationError, Command, ComputeEngineRegistry, ComputeEvaluatorRegistry, ComputePayloadParserRegistry, ComputePayloadParsers, ComputeRegistry, ConflictError, ContextResolverRegistry, ContextSeedValidator, CoreConfig, SerializationInError as DeserializationError, SerializationInError, DuplicateError, ERP_CORE_NAME, ERP_CORE_VERSION, Entity, Err, ErrorCodes, ExpiredError, GateEngineRegistry, GatePayloadParsers, IdempotencyError, IdempotencyInProgressError, IdempotencyKeyMissingError, IdempotencyPayloadMismatchError, IdempotencyReplayNotSupportedError, InMemoryPolicyDefinitionRepository, IntegrationError, LegacyIncompatibleError, NotFoundError, NotYetValidError, Ok, Outcome, PolicyAsOfResolver, PolicyCatalog, PolicyCatalogFactory, PolicyContextBuilder, PolicyContextPath, PolicyDefinition, PolicyEvaluationErrors, PolicyHashing, PolicyKey, PolicyResolver, PolicyScopeMatcher, PolicyService, Query, RequestedBy, Result, SerializationCodes, SerializationError, SerializationMessages, SerializationOutError, TemporalError, TemporalUseCase, UnexpectedError, UniqueConstraintViolationError, UseCase, ValidationError, ValidationField, ValueObject, asPolicyDecisionId, asPolicyDefinitionId, asSchoolId, asTenantId, assertJsonSafeMetadata, assertTemporalContext, contextResolverRegistry, coreConfig, createTemporalContext, erpCoreRelease, evaluateTemporalWindow, mapPolicyEvaluationError, payloadHash, registerNamespacedContextResolvers, registerNamespacedContextResolversIn, safePreview, serializationErrorCode, sha256Hex, stableStringify, translateUniqueViolationToDuplicate };
174
193
 
175
194
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["version","version"],"sources":["../src/version.ts","../src/core/application/policy-error-mapper.ts","../src/core/shared/aggregate-version.ts","../src/core/versioning/version.ts","../src/core/domain/entity.ts","../src/core/shared/immutable.ts","../src/core/domain/value-object.ts","../src/index.ts"],"sourcesContent":["// Versao do kit, sincronizada com package.json por scripts/sync-kit-version.mjs.\n// Nao edite a mao: rode `npm run sync-kit-version` (ou e regenerado no release).\n//\n// Mantemos a versao aqui, dentro de src/, para que a copia full-control seja\n// auto-contida: ao copiar so o conteudo de src/, o entry nao depende de um\n// `../package.json` que deixaria de existir no projeto consumidor.\nexport const version = \"1.0.10\";\n","import {\n type AppError,\n BusinessRuleViolationError,\n NotFoundError,\n UnexpectedError,\n} from \"../errors/index.js\";\nimport type { PolicyEvaluationError } from \"../policies/index.js\";\n\nexport function mapPolicyEvaluationError(err: PolicyEvaluationError): AppError {\n switch (err.kind) {\n case \"INVALID_CONTEXT\":\n return new BusinessRuleViolationError(\n `policy.${err.stage.toLowerCase()}`,\n err.message,\n { policyKey: err.policyKey, stage: err.stage },\n { cause: err.cause },\n );\n case \"INVALID_POLICY_KEY\":\n return new BusinessRuleViolationError(\n \"policy.invalid_key\",\n err.message,\n { rawPolicyKey: err.rawPolicyKey },\n { cause: err.cause },\n );\n case \"POLICY_NOT_FOUND\":\n return new NotFoundError(\n \"Policy\",\n { policyKey: err.policyKey },\n { cause: err.cause },\n );\n case \"POLICY_DEFINITION_NOT_FOUND\":\n return new NotFoundError(\n \"PolicyDefinition\",\n {\n policyKey: err.policyKey,\n contextVersion: err.contextVersion,\n asOf: err.asOf.toISOString(),\n },\n { cause: err.cause },\n );\n case \"POLICY_VARIANT_NOT_FOUND\":\n return new NotFoundError(\n \"PolicyVariant\",\n {\n policyKey: err.policyKey,\n policyKind: err.policyKind,\n payloadSchemaVersion: err.payloadSchemaVersion,\n },\n { cause: err.cause },\n );\n case \"ENGINE_FAILURE\":\n return new UnexpectedError(err.message, err.cause, {\n metadata: {\n policyKey: err.policyKey,\n engine: err.engine,\n engineVersion: err.engineVersion,\n },\n });\n }\n}\n","import { InvariantViolationException } from \"../exceptions/invariant-violation-exception.js\";\n\nfunction assertValidAggregateVersion(aggregateVersion: number): void {\n if (!Number.isInteger(aggregateVersion) || aggregateVersion < 0) {\n throw new InvariantViolationException(\n `aggregateVersion must be a non-negative integer. Received: ${aggregateVersion}`,\n );\n }\n}\n\nexport { assertValidAggregateVersion };\n","type ContractVersion = `${number}.${number}`;\n\ntype VersionedTarget = {\n readonly prototype: object;\n};\n\nconst CONTRACT_VERSION_PROPERTY = \"CONTRACT_VERSION\" as const;\nconst CONTRACT_VERSION_PATTERN = /^\\d+\\.\\d+$/;\n\nfunction version<const TVersion extends ContractVersion>(\n contractVersion: TVersion,\n) {\n if (!CONTRACT_VERSION_PATTERN.test(contractVersion)) {\n throw new TypeError(\n `Invalid contract version \"${contractVersion}\". Expected MAJOR.MINOR.`,\n );\n }\n\n return (target: VersionedTarget): void => {\n Object.defineProperty(target, CONTRACT_VERSION_PROPERTY, {\n value: contractVersion,\n writable: false,\n configurable: false,\n enumerable: false,\n });\n };\n}\n\nexport {\n CONTRACT_VERSION_PROPERTY,\n type ContractVersion,\n version,\n type VersionedTarget,\n};\n","import { InvariantViolationException } from \"../exceptions/invariant-violation-exception.js\";\nimport { assertValidAggregateVersion } from \"../shared/aggregate-version.js\";\nimport { assertValidDate, cloneDate } from \"../shared/temporal-guards.js\";\nimport { type ContractVersion, version } from \"../versioning/version.js\";\n\ninterface EntityState<TIdentifier> {\n readonly id: TIdentifier;\n readonly createdAt: Date;\n readonly updatedAt: Date;\n readonly aggregateVersion: number;\n}\n\n@version(\"1.0\")\nabstract class Entity<TIdentifier> {\n declare public static readonly CONTRACT_VERSION: ContractVersion;\n\n private readonly _id: TIdentifier;\n private readonly _createdAt: Date;\n private _updatedAt: Date;\n private _aggregateVersion: number;\n\n protected constructor(state: EntityState<TIdentifier>) {\n assertValidDate(\"createdAt\", state.createdAt);\n assertValidDate(\"updatedAt\", state.updatedAt);\n assertValidAggregateVersion(state.aggregateVersion);\n\n if (state.updatedAt.getTime() < state.createdAt.getTime()) {\n throw new InvariantViolationException(\n \"updatedAt cannot be earlier than createdAt\",\n );\n }\n\n this._id = state.id;\n this._createdAt = cloneDate(state.createdAt);\n this._updatedAt = cloneDate(state.updatedAt);\n this._aggregateVersion = state.aggregateVersion;\n }\n\n public get id(): TIdentifier {\n return this._id;\n }\n\n public get createdAt(): Date {\n return cloneDate(this._createdAt);\n }\n\n public get updatedAt(): Date {\n return cloneDate(this._updatedAt);\n }\n\n public get aggregateVersion(): number {\n return this._aggregateVersion;\n }\n\n public get contractVersion(): ContractVersion {\n return Entity.CONTRACT_VERSION;\n }\n\n protected markAsModified(updatedAt: Date = new Date()): number {\n assertValidDate(\"updatedAt\", updatedAt);\n\n if (updatedAt.getTime() < this._createdAt.getTime()) {\n throw new InvariantViolationException(\n \"updatedAt cannot be earlier than createdAt\",\n );\n }\n\n this._updatedAt = cloneDate(updatedAt);\n this._aggregateVersion += 1;\n\n return this._aggregateVersion;\n }\n}\n\nexport { Entity, type EntityState };\n","import { InvariantViolationException } from \"../exceptions/invariant-violation-exception.js\";\n\ntype PrimitiveValue =\n | bigint\n | boolean\n | null\n | number\n | string\n | symbol\n | undefined;\n\ntype DeepReadonly<T> = T extends PrimitiveValue | Date\n ? T\n : T extends readonly (infer TItem)[]\n ? readonly DeepReadonly<TItem>[]\n : { readonly [TKey in keyof T]: DeepReadonly<T[TKey]> };\n\nfunction deepFreeze<T>(value: T): T {\n return deepFreezeInternal(value, new WeakSet<object>());\n}\n\nfunction deepFreezeInternal<T>(value: T, seen: WeakSet<object>): T {\n // Primitives and `null` need no freezing. `Date` is intentionally returned\n // as-is: `Object.freeze` cannot stop a Date's mutators (`setTime`,\n // `setFullYear`, …) because they write an internal slot, not an own\n // property — freezing it is a no-op against mutation. `makeImmutable`\n // already hands us a `structuredClone` copy, so the caller's original Date\n // is never aliased; deep-freezing of nested Dates is deliberately skipped.\n if (typeof value !== \"object\" || value === null || value instanceof Date) {\n return value;\n }\n\n // A value already on `seen` has been visited on this pass (cyclic graph or a\n // shared reference); revisiting it would recurse forever.\n if (seen.has(value)) {\n return value;\n }\n seen.add(value);\n\n if (Array.isArray(value)) {\n for (const item of value) {\n deepFreezeInternal(item, seen);\n }\n\n return Object.freeze(value);\n }\n\n const objectValue = value as Record<PropertyKey, object | PrimitiveValue>;\n\n for (const propertyKey of Reflect.ownKeys(objectValue)) {\n deepFreezeInternal(objectValue[propertyKey], seen);\n }\n\n return Object.freeze(value);\n}\n\nfunction makeImmutable<T>(value: T): DeepReadonly<T> {\n if (typeof value !== \"object\" || value === null) {\n return value as DeepReadonly<T>;\n }\n\n let snapshot: T;\n try {\n snapshot = structuredClone(value);\n } catch (error) {\n // `structuredClone` throws `DataCloneError` for functions, symbols and\n // class instances. Surface it as a domain invariant instead of leaking\n // a host-specific runtime error to callers building value objects.\n throw new InvariantViolationException(\n `makeImmutable requires a structured-cloneable value: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n }\n\n return deepFreeze(snapshot) as DeepReadonly<T>;\n}\n\nexport { deepFreeze, makeImmutable, type DeepReadonly };\n","import { type DeepReadonly, makeImmutable } from \"../shared/immutable.js\";\nimport { type ContractVersion, version } from \"../versioning/version.js\";\n\n@version(\"1.0\")\nabstract class ValueObject<T, P> {\n declare public static readonly CONTRACT_VERSION: ContractVersion;\n public readonly value: DeepReadonly<T>;\n\n protected constructor(value: T) {\n this.value = makeImmutable(value);\n }\n\n public get contractVersion(): ContractVersion {\n return ValueObject.CONTRACT_VERSION;\n }\n\n /**\n * Freezes the instance shell, blocking reassignment of any own field.\n *\n * `value` is already deep-frozen by the constructor, so the wrapped data is\n * immutable regardless. The instance itself is NOT frozen automatically\n * because a subclass may still need to assign its own fields after\n * `super(value)` runs. Call `finalize()` at the very end of the subclass\n * constructor (after all fields are set) to make the whole value object\n * immutable.\n */\n protected finalize(): void {\n Object.freeze(this);\n }\n\n public toJSON(): P {\n return this.toPrimitive();\n }\n\n public abstract equals(other: this): boolean;\n\n public abstract toPrimitive(): P;\n}\n\nexport { type DeepReadonly, ValueObject };\n","import { version } from \"./version.js\";\n\nexport * from \"./core/index.js\";\n\nexport const ERP_CORE_NAME = \"erp-core\";\nexport const ERP_CORE_VERSION = version;\n\nexport const erpCoreRelease = {\n name: ERP_CORE_NAME,\n version: ERP_CORE_VERSION,\n} as const;\n"],"mappings":"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"}
1
+ {"version":3,"file":"index.js","names":["version","version"],"sources":["../src/version.ts","../src/core/shared/aggregate-version.ts","../src/core/domain/entity.ts","../src/core/domain/value-object.ts","../src/index.ts"],"sourcesContent":["// Versao do kit, sincronizada com package.json por scripts/sync-kit-version.mjs.\n// Nao edite a mao: rode `npm run sync-kit-version` (ou e regenerado no release).\n//\n// Mantemos a versao aqui, dentro de src/, para que a copia full-control seja\n// auto-contida: ao copiar so o conteudo de src/, o entry nao depende de um\n// `../package.json` que deixaria de existir no projeto consumidor.\nexport const version = \"1.1.0\";\n","import { InvariantViolationException } from \"../exceptions/invariant-violation-exception.js\";\n\nfunction assertValidAggregateVersion(aggregateVersion: number): void {\n if (!Number.isInteger(aggregateVersion) || aggregateVersion < 0) {\n throw new InvariantViolationException(\n `aggregateVersion must be a non-negative integer. Received: ${aggregateVersion}`,\n );\n }\n}\n\nexport { assertValidAggregateVersion };\n","import { InvariantViolationException } from \"../exceptions/invariant-violation-exception.js\";\nimport { assertValidAggregateVersion } from \"../shared/aggregate-version.js\";\nimport { assertValidDate, cloneDate } from \"../shared/temporal-guards.js\";\nimport { type ContractVersion, version } from \"../versioning/version.js\";\n\n/**\n * The minimal persisted shape needed to reconstitute an {@link Entity}.\n *\n * This is the contract between storage and the domain: a repository maps a row\n * (or document) onto these four fields and hands them to a subclass constructor.\n * `aggregateVersion` travels with the state so optimistic-concurrency checks\n * survive a round-trip through the database.\n */\ninterface EntityState<TIdentifier> {\n readonly id: TIdentifier;\n readonly createdAt: Date;\n readonly updatedAt: Date;\n readonly aggregateVersion: number;\n}\n\n/**\n * Base class for domain entities — objects defined by a stable identity rather\n * than by their attributes. Two entities are \"the same\" when their `id`\n * matches, even if every other field differs; this is the opposite of a\n * {@link ValueObject}, which is defined entirely by its contents.\n *\n * The class owns the bookkeeping common to every aggregate root: a creation\n * timestamp that never changes, a last-modified timestamp, and an\n * `aggregateVersion` counter used for optimistic concurrency control. All three\n * are validated on construction and the dates are defensively cloned, so an\n * entity can never be built into — or leak — an inconsistent temporal state.\n *\n * @typeParam TIdentifier - The identity type (e.g. a branded string id or a VO).\n */\n@version(\"1.0\")\nabstract class Entity<TIdentifier> {\n declare public static readonly CONTRACT_VERSION: ContractVersion;\n\n private readonly _id: TIdentifier;\n private readonly _createdAt: Date;\n private _updatedAt: Date;\n private _aggregateVersion: number;\n\n /**\n * Reconstitutes an entity from its persisted {@link EntityState}.\n *\n * Validates the temporal invariants up front so an invalid entity is\n * impossible to construct: both dates must be valid, the aggregate version\n * must be a non-negative integer, and `updatedAt` may not predate\n * `createdAt`. Both dates are cloned on the way in so a later mutation of\n * the caller's `Date` objects cannot reach into the entity's internal state.\n *\n * Declared `protected` because entities are reconstituted through a\n * subclass factory, never instantiated directly by application code.\n *\n * @throws {InvariantViolationException} When `updatedAt` is earlier than `createdAt`.\n */\n protected constructor(state: EntityState<TIdentifier>) {\n assertValidDate(\"createdAt\", state.createdAt);\n assertValidDate(\"updatedAt\", state.updatedAt);\n assertValidAggregateVersion(state.aggregateVersion);\n\n if (state.updatedAt.getTime() < state.createdAt.getTime()) {\n throw new InvariantViolationException(\n \"updatedAt cannot be earlier than createdAt\",\n );\n }\n\n this._id = state.id;\n this._createdAt = cloneDate(state.createdAt);\n this._updatedAt = cloneDate(state.updatedAt);\n this._aggregateVersion = state.aggregateVersion;\n }\n\n /** The entity's stable identity — the basis for equality between entities. */\n public get id(): TIdentifier {\n return this._id;\n }\n\n /**\n * When the entity was first created.\n *\n * Returns a clone so callers cannot mutate the entity's internal `Date`;\n * the value is fixed at construction and never changes thereafter.\n */\n public get createdAt(): Date {\n return cloneDate(this._createdAt);\n }\n\n /**\n * When the entity was last modified.\n *\n * Returns a clone for the same encapsulation reason as {@link createdAt};\n * the underlying value advances only through {@link markAsModified}.\n */\n public get updatedAt(): Date {\n return cloneDate(this._updatedAt);\n }\n\n /**\n * Monotonic counter incremented on every mutation, used for optimistic\n * concurrency control: a writer reads this value, and the persistence layer\n * rejects the write if the stored version has moved on in the meantime.\n */\n public get aggregateVersion(): number {\n return this._aggregateVersion;\n }\n\n /**\n * The schema/contract version stamped on this entity type by the\n * `@version` decorator — used to detect and migrate state persisted under\n * an older shape.\n */\n public get contractVersion(): ContractVersion {\n return Entity.CONTRACT_VERSION;\n }\n\n /**\n * The single seam through which an entity records a mutation: it advances\n * `updatedAt` and bumps {@link aggregateVersion} by one. Subclasses must\n * call this from every state-changing method so the version counter stays\n * an accurate optimistic-lock token.\n *\n * @param updatedAt - The modification instant; defaults to now. Validated\n * and required not to predate `createdAt`, preserving the same invariant\n * the constructor enforces.\n * @returns The new aggregate version after the increment.\n * @throws {InvariantViolationException} When `updatedAt` is earlier than `createdAt`.\n */\n protected markAsModified(updatedAt: Date = new Date()): number {\n assertValidDate(\"updatedAt\", updatedAt);\n\n if (updatedAt.getTime() < this._createdAt.getTime()) {\n throw new InvariantViolationException(\n \"updatedAt cannot be earlier than createdAt\",\n );\n }\n\n this._updatedAt = cloneDate(updatedAt);\n this._aggregateVersion += 1;\n\n return this._aggregateVersion;\n }\n}\n\nexport { Entity, type EntityState };\n","import { type DeepReadonly, makeImmutable } from \"../shared/immutable.js\";\nimport { type ContractVersion, version } from \"../versioning/version.js\";\n\n/**\n * Base class for value objects — domain concepts defined entirely by their\n * contents, with no identity of their own. Two value objects are\n * interchangeable when they hold equal data, which is the opposite of an\n * {@link Entity} (compared by id). Money, a CPF, a date range: replacing one\n * instance with an equal one changes nothing about the model.\n *\n * Immutability is the defining guarantee here. The wrapped `value` is\n * deep-frozen on construction, so a value object can be shared freely without\n * any risk of a consumer mutating shared state. Subclasses seal the instance\n * itself with {@link finalize} once their own fields are set.\n *\n * @typeParam T - The shape of the wrapped data.\n * @typeParam P - The primitive form produced by {@link toPrimitive} / {@link toJSON}.\n */\n@version(\"1.0\")\nabstract class ValueObject<T, P> {\n declare public static readonly CONTRACT_VERSION: ContractVersion;\n\n /** The wrapped data, deep-frozen so it can never be mutated after construction. */\n public readonly value: DeepReadonly<T>;\n\n /**\n * Wraps `value`, deep-freezing it so the value object is immutable from the\n * moment it exists. Declared `protected` because value objects are built\n * through a validating subclass factory, never instantiated directly.\n */\n protected constructor(value: T) {\n this.value = makeImmutable(value);\n }\n\n /**\n * The schema/contract version stamped on this value-object type by the\n * `@version` decorator — used to detect state persisted under an older shape.\n */\n public get contractVersion(): ContractVersion {\n return ValueObject.CONTRACT_VERSION;\n }\n\n /**\n * Freezes the instance shell, blocking reassignment of any own field.\n *\n * `value` is already deep-frozen by the constructor, so the wrapped data is\n * immutable regardless. The instance itself is NOT frozen automatically\n * because a subclass may still need to assign its own fields after\n * `super(value)` runs. Call `finalize()` at the very end of the subclass\n * constructor (after all fields are set) to make the whole value object\n * immutable.\n */\n protected finalize(): void {\n Object.freeze(this);\n }\n\n /**\n * Hook for `JSON.stringify`. Delegates to {@link toPrimitive} so a value\n * object serializes to its primitive form rather than exposing the internal\n * `value` wrapper.\n */\n public toJSON(): P {\n return this.toPrimitive();\n }\n\n /**\n * Compares this value object with another by content. Because value objects\n * carry no identity, subclasses implement equality over the wrapped data\n * (typically the primitive form), so two independently constructed instances\n * holding the same data are considered equal.\n */\n public abstract equals(other: this): boolean;\n\n /**\n * Projects the value object down to a plain, serializable primitive form —\n * the representation suitable for persistence, transport, or comparison.\n */\n public abstract toPrimitive(): P;\n}\n\nexport { type DeepReadonly, ValueObject };\n","import { version } from \"./version.js\";\n\nexport * from \"./core/index.js\";\n\nexport const ERP_CORE_NAME = \"erp-core\";\nexport const ERP_CORE_VERSION = version;\n\nexport const erpCoreRelease = {\n name: ERP_CORE_NAME,\n version: ERP_CORE_VERSION,\n} as const;\n"],"mappings":";;;;;;;;;;;;AAMA,MAAa,UAAU;;;ACJvB,SAAS,4BAA4B,kBAAgC;CACjE,IAAI,CAAC,OAAO,UAAU,gBAAgB,KAAK,mBAAmB,GAC1D,MAAM,IAAI,4BACN,8DAA8D,kBAClE;AAER;;;;;;;;;;;;;;;;;;AC0BA,IAAA,SAAA,MACe,OAAoB;;;;;;;;;;;;;;;;;;CAsB/B,YAAsB,OAAiC;EACnD,gBAAgB,aAAa,MAAM,SAAS;EAC5C,gBAAgB,aAAa,MAAM,SAAS;EAC5C,4BAA4B,MAAM,gBAAgB;EAElD,IAAI,MAAM,UAAU,QAAQ,IAAI,MAAM,UAAU,QAAQ,GACpD,MAAM,IAAI,4BACN,4CACJ;EAGJ,KAAK,MAAM,MAAM;EACjB,KAAK,aAAa,UAAU,MAAM,SAAS;EAC3C,KAAK,aAAa,UAAU,MAAM,SAAS;EAC3C,KAAK,oBAAoB,MAAM;CACnC;;CAGA,IAAW,KAAkB;EACzB,OAAO,KAAK;CAChB;;;;;;;CAQA,IAAW,YAAkB;EACzB,OAAO,UAAU,KAAK,UAAU;CACpC;;;;;;;CAQA,IAAW,YAAkB;EACzB,OAAO,UAAU,KAAK,UAAU;CACpC;;;;;;CAOA,IAAW,mBAA2B;EAClC,OAAO,KAAK;CAChB;;;;;;CAOA,IAAW,kBAAmC;EAC1C,OAAA,QAAc;CAClB;;;;;;;;;;;;;CAcA,eAAyB,4BAAkB,IAAI,KAAK,GAAW;EAC3D,gBAAgB,aAAa,SAAS;EAEtC,IAAI,UAAU,QAAQ,IAAI,KAAK,WAAW,QAAQ,GAC9C,MAAM,IAAI,4BACN,4CACJ;EAGJ,KAAK,aAAa,UAAU,SAAS;EACrC,KAAK,qBAAqB;EAE1B,OAAO,KAAK;CAChB;AACJ;+BA7GCA,UAAQ,KAAK,CAAA,GAAA,MAAA;;;;;;;;;;;;;;;;;;;AChBd,IAAA,cAAA,MACe,YAAkB;;;;;;;;;CAW7B,YAAsB,OAAU;EAC5B,KAAK,QAAQ,cAAc,KAAK;CACpC;;;;;CAMA,IAAW,kBAAmC;EAC1C,OAAA,aAAmB;CACvB;;;;;;;;;;;CAYA,WAA2B;EACvB,OAAO,OAAO,IAAI;CACtB;;;;;;CAOA,SAAmB;EACf,OAAO,KAAK,YAAY;CAC5B;AAeJ;yCA5DCC,UAAQ,KAAK,CAAA,GAAA,WAAA;;;ACdd,MAAa,gBAAgB;AAC7B,MAAa,mBAAmB;AAEhC,MAAa,iBAAiB;CAC1B,MAAM;CACN,SAAS;AACb"}
@@ -0,0 +1,54 @@
1
+ import { a as ErrorCodes, r as AppError } from "./validation-code.js";
2
+ //#region src/core/errors/business-rule-violation-error.ts
3
+ var BusinessRuleViolationError = class extends AppError {
4
+ constructor(rule, message, detail, options) {
5
+ const baseMetadata = detail ? {
6
+ rule,
7
+ detail
8
+ } : { rule };
9
+ const mergedMetadata = options?.metadata ? {
10
+ ...baseMetadata,
11
+ ...options.metadata
12
+ } : baseMetadata;
13
+ super(message, ErrorCodes.businessRuleViolation, {
14
+ ...options,
15
+ metadata: mergedMetadata
16
+ });
17
+ }
18
+ };
19
+ //#endregion
20
+ //#region src/core/errors/not-found-error.ts
21
+ /**
22
+ * Raised when a requested resource does not exist. Maps naturally onto an HTTP
23
+ * 404 at the edge, but stays transport-agnostic here.
24
+ *
25
+ * The `resource` name builds the message (`"<resource> not found"`) and, with
26
+ * the optional lookup `criteria`, lands in the metadata so logs show *what* was
27
+ * searched for without the caller having to restate it in the message.
28
+ */
29
+ var NotFoundError = class extends AppError {
30
+ /**
31
+ * @param resource - Human-readable name of the missing resource (e.g. `"Order"`).
32
+ * @param criteria - Optional lookup keys used in the search; recorded in
33
+ * metadata to aid debugging. Avoid putting sensitive values here.
34
+ * @param options - Optional cause, correlation ids, and extra metadata.
35
+ */
36
+ constructor(resource, criteria, options) {
37
+ const baseMetadata = criteria ? {
38
+ resource,
39
+ criteria
40
+ } : { resource };
41
+ const mergedMetadata = options?.metadata ? {
42
+ ...baseMetadata,
43
+ ...options.metadata
44
+ } : baseMetadata;
45
+ super(`${resource} not found`, ErrorCodes.notFound, {
46
+ ...options,
47
+ metadata: mergedMetadata
48
+ });
49
+ }
50
+ };
51
+ //#endregion
52
+ export { BusinessRuleViolationError as n, NotFoundError as t };
53
+
54
+ //# sourceMappingURL=not-found-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"not-found-error.js","names":[],"sources":["../src/core/errors/business-rule-violation-error.ts","../src/core/errors/not-found-error.ts"],"sourcesContent":["import { AppError } from \"./app-error.js\";\nimport { ErrorCodes } from \"./error-codes.js\";\nimport type { AppErrorOptions } from \"./types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// BusinessRuleViolationError\n// ─────────────────────────────────────────────────────────────────────────────\n\nclass BusinessRuleViolationError extends AppError {\n constructor(\n rule: string,\n message: string,\n detail?: Record<string, unknown>,\n options?: AppErrorOptions,\n ) {\n const baseMetadata = detail ? { rule, detail } : { rule };\n const mergedMetadata = options?.metadata\n ? { ...baseMetadata, ...options.metadata }\n : baseMetadata;\n\n super(message, ErrorCodes.businessRuleViolation, {\n ...options,\n metadata: mergedMetadata,\n });\n }\n}\n\nexport { BusinessRuleViolationError };\n","import { AppError } from \"./app-error.js\";\nimport { ErrorCodes } from \"./error-codes.js\";\nimport type { AppErrorOptions } from \"./types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// NotFoundError\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Raised when a requested resource does not exist. Maps naturally onto an HTTP\n * 404 at the edge, but stays transport-agnostic here.\n *\n * The `resource` name builds the message (`\"<resource> not found\"`) and, with\n * the optional lookup `criteria`, lands in the metadata so logs show *what* was\n * searched for without the caller having to restate it in the message.\n */\nclass NotFoundError extends AppError {\n /**\n * @param resource - Human-readable name of the missing resource (e.g. `\"Order\"`).\n * @param criteria - Optional lookup keys used in the search; recorded in\n * metadata to aid debugging. Avoid putting sensitive values here.\n * @param options - Optional cause, correlation ids, and extra metadata.\n */\n constructor(\n resource: string,\n criteria?: Record<string, unknown>,\n options?: AppErrorOptions,\n ) {\n const baseMetadata = criteria ? { resource, criteria } : { resource };\n const mergedMetadata = options?.metadata\n ? { ...baseMetadata, ...options.metadata }\n : baseMetadata;\n\n super(`${resource} not found`, ErrorCodes.notFound, {\n ...options,\n metadata: mergedMetadata,\n });\n }\n}\n\nexport { NotFoundError };\n"],"mappings":";;AAQA,IAAM,6BAAN,cAAyC,SAAS;CAC9C,YACI,MACA,SACA,QACA,SACF;EACE,MAAM,eAAe,SAAS;GAAE;GAAM;EAAO,IAAI,EAAE,KAAK;EACxD,MAAM,iBAAiB,SAAS,WAC1B;GAAE,GAAG;GAAc,GAAG,QAAQ;EAAS,IACvC;EAEN,MAAM,SAAS,WAAW,uBAAuB;GAC7C,GAAG;GACH,UAAU;EACd,CAAC;CACL;AACJ;;;;;;;;;;;ACTA,IAAM,gBAAN,cAA4B,SAAS;;;;;;;CAOjC,YACI,UACA,UACA,SACF;EACE,MAAM,eAAe,WAAW;GAAE;GAAU;EAAS,IAAI,EAAE,SAAS;EACpE,MAAM,iBAAiB,SAAS,WAC1B;GAAE,GAAG;GAAc,GAAG,QAAQ;EAAS,IACvC;EAEN,MAAM,GAAG,SAAS,aAAa,WAAW,UAAU;GAChD,GAAG;GACH,UAAU;EACd,CAAC;CACL;AACJ"}
package/dist/outcome.js CHANGED
@@ -1,4 +1,4 @@
1
- import { g as InvariantViolationException } from "./gate-v1-payload.schema.js";
1
+ import { i as InvariantViolationException } from "./temporal-guards.js";
2
2
  //#region src/core/result/outcome.ts
3
3
  /**
4
4
  * Outcome — Business decision abstraction.
@@ -1,58 +1,6 @@
1
- import { I as Result, c as PolicyViolation, d as GatePayloadV1, g as CoreConfig, h as Outcome, l as VersionedGateEngine, p as ConditionNode, s as PolicyContext, t as GateOutcome, u as GatePayload } from "./gate-types.js";
2
- import { z } from "zod";
1
+ import { I as Result, d as GatePayloadV1, s as PolicyContext, u as GatePayload } from "./gate-types.js";
2
+ import { a as ComputeOutcome, c as VersionedComputeEngine, i as ComputeEvaluatorRegistration, l as ComputePayload, p as ComputePayloadV1, r as ComputeEvaluator } from "./gate-engine-registry.js";
3
3
 
4
- //#region src/core/policies/engines/v1/compute/compute-payload.schema.d.ts
5
- interface ComputeParamsPayload {
6
- readonly type: "params";
7
- readonly data: Readonly<Record<string, unknown>>;
8
- }
9
- interface ComputeDecisionTableRule<R = unknown> {
10
- readonly conditions: ConditionNode;
11
- readonly result: R;
12
- }
13
- interface ComputeDecisionTablePayload<R = unknown> {
14
- readonly type: "decision-table";
15
- readonly rules: readonly ComputeDecisionTableRule<R>[];
16
- readonly default: R;
17
- }
18
- type ComputePayloadV1 = ComputeDecisionTablePayload<unknown> | ComputeParamsPayload;
19
- //#endregion
20
- //#region src/core/policies/engines/compute-payload.d.ts
21
- type ComputePayload = ComputePayloadV1;
22
- //#endregion
23
- //#region src/core/policies/engines/compute-types.d.ts
24
- type ComputeStatus = "OK" | "NOT_APPLICABLE" | "ERROR";
25
- interface ComputeOutcomeData {
26
- readonly values: unknown | null;
27
- readonly violations: readonly PolicyViolation[];
28
- }
29
- /** Semantic outcome of a COMPUTE policy evaluation. */
30
- type ComputeOutcome = Outcome<ComputeStatus, ComputeOutcomeData>;
31
- /**
32
- * Pure compute operation: receives a resolved value + context, returns a
33
- * business decision. Registration metadata (policy key/version) lives outside
34
- * this contract.
35
- *
36
- * The engine resolves the structural payload before calling the evaluator:
37
- * - `params` -> `payload.data`
38
- * - `decision-table` -> matching `rule.result` or `default`
39
- *
40
- * Result wraps technical failures (invalid value shape).
41
- * Outcome carries the semantic business decision.
42
- */
43
- interface ComputeEvaluator {
44
- evaluate(resolvedValue: unknown, context: Record<string, unknown>): Result<ComputeOutcome, string>;
45
- }
46
- interface ComputeEvaluatorRegistration {
47
- readonly policyKey: string;
48
- readonly version: number;
49
- readonly evaluator: ComputeEvaluator;
50
- }
51
- interface VersionedComputeEngine {
52
- readonly version: number;
53
- evaluate(payload: ComputePayload, context: PolicyContext, evaluator: ComputeEvaluator): Result<ComputeOutcome, string>;
54
- }
55
- //#endregion
56
4
  //#region src/core/policies/engines/compute-evaluator-registry.d.ts
57
5
  declare class ComputeEvaluatorRegistry {
58
6
  private readonly evaluators;
@@ -75,29 +23,6 @@ declare class ComputeEngineRegistry {
75
23
  }): Result<ComputeOutcome, string>;
76
24
  }
77
25
  //#endregion
78
- //#region src/core/policies/engines/compute-registry.d.ts
79
- interface ComputeRegistryOptions {
80
- readonly coreConfig?: CoreConfig;
81
- }
82
- declare class ComputeRegistry {
83
- private readonly engines;
84
- private readonly evaluators;
85
- constructor(params?: ComputeRegistryOptions);
86
- register(registration: ComputeEvaluatorRegistration): void;
87
- registerEngine(engine: VersionedComputeEngine): void;
88
- getEngine(version: number): VersionedComputeEngine | undefined;
89
- getEvaluator(policyKey: string, version: number): ComputeEvaluator | undefined;
90
- evaluate(policyKey: string, computeEngineVersion: number, payloadSchemaVersion: number, payload: unknown, context: PolicyContext): Result<ComputeOutcome, string>;
91
- }
92
- //#endregion
93
- //#region src/core/policies/engines/gate-engine-registry.d.ts
94
- declare class GateEngineRegistry {
95
- private readonly engines;
96
- register(engine: VersionedGateEngine): void;
97
- get(version: number): VersionedGateEngine | undefined;
98
- evaluate(version: number, payload: unknown, context: PolicyContext): Result<GateOutcome, string>;
99
- }
100
- //#endregion
101
26
  //#region src/core/policies/engines/parse-compute-payload.d.ts
102
27
  type ComputePayloadParser = (payload: unknown) => Result<ComputePayload, string>;
103
28
  declare class ComputePayloadParserRegistry {
@@ -132,5 +57,5 @@ declare class GatePayloadParsers {
132
57
  static parse(engineVersion: number, payload: unknown): Result<GatePayloadV1, string>;
133
58
  }
134
59
  //#endregion
135
- export { ComputePayload as _, ComputePayloadParserRegistry as a, ComputeParamsPayload as b, ComputeRegistry as c, ComputeEvaluator as d, ComputeEvaluatorRegistration as f, VersionedComputeEngine as g, ComputeStatus as h, ComputePayloadParser as i, ComputeEngineRegistry as l, ComputeOutcomeData as m, GatePayloadParserRegistry as n, ComputePayloadParsers as o, ComputeOutcome as p, GatePayloadParsers as r, GateEngineRegistry as s, GatePayloadParser as t, ComputeEvaluatorRegistry as u, ComputeDecisionTablePayload as v, ComputePayloadV1 as x, ComputeDecisionTableRule as y };
60
+ export { ComputePayloadParserRegistry as a, ComputeEvaluatorRegistry as c, ComputePayloadParser as i, GatePayloadParserRegistry as n, ComputePayloadParsers as o, GatePayloadParsers as r, ComputeEngineRegistry as s, GatePayloadParser as t };
136
61
  //# sourceMappingURL=parse-gate-payload.d.ts.map
package/dist/path.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ import { I as Result, g as CoreConfig } from "./gate-types.js";
2
+ import { D as PolicyDefinition, N as PolicyCatalog, P as PolicyCatalogEntryProps, S as PolicyDefinitionRepository, T as FindCandidatesParams, m as ContextResolverRegistry, y as ContextValueResolver } from "./policy-service.js";
3
+ import { i as ComputeEvaluatorRegistration } from "./gate-engine-registry.js";
4
+
5
+ //#region src/core/config/core-config.instance.d.ts
6
+
7
+ /**
8
+ * Shared instance for the application composition root.
9
+ * Use `new CoreConfig()` for isolated runtimes, tests, or multi-tenant hosts.
10
+ *
11
+ * The default reporter is silent so the core has no runtime logging dependency.
12
+ * Hosts can swap in their own `PolicyReporter` via
13
+ * `coreConfig.configure({ observability: { reporter } })`.
14
+ */
15
+ declare const coreConfig: CoreConfig;
16
+ //#endregion
17
+ //#region src/core/policies/utils/hash.d.ts
18
+ /**
19
+ * Produces a deterministic SHA-256 hex digest of a canonical JSON representation.
20
+ * Object keys are sorted recursively so key order does not affect the hash.
21
+ * Array item order is preserved on purpose; callers that treat arrays as sets
22
+ * must normalize or sort them before hashing.
23
+ *
24
+ * Values that JSON.stringify would silently drop or coerce (undefined,
25
+ * non-finite numbers, functions, symbols, bigint) are rejected up-front to
26
+ * prevent semantically different payloads from collapsing to the same hash.
27
+ */
28
+ declare class PolicyHashing {
29
+ static sha256(input: string): string;
30
+ private static assertHashable;
31
+ static canonicalJson(value: unknown): string;
32
+ static computePayloadHash(payload: unknown, policyKey: string, policyVersion: string): string;
33
+ }
34
+ //#endregion
35
+ //#region src/core/policies/defs/in-memory-policy-definition-repo.d.ts
36
+ declare class InMemoryPolicyDefinitionRepository implements PolicyDefinitionRepository {
37
+ private readonly definitions;
38
+ private readonly definitionsByPolicyKey;
39
+ constructor(definitions: readonly PolicyDefinition[]);
40
+ findCandidates(params: FindCandidatesParams): PolicyDefinition[];
41
+ }
42
+ //#endregion
43
+ //#region src/core/policies/package/policy-package.d.ts
44
+ /**
45
+ * Protocol of contribution: a module declares what it wants to add to the
46
+ * policy system without the core knowing which module it is.
47
+ *
48
+ * - catalogEntries: static policy descriptors the catalog will register.
49
+ * - definitions: default policy definitions (rules/parameters) to seed.
50
+ * - evaluators: compute evaluator registrations keyed by policy/version.
51
+ */
52
+ interface PolicyPackage {
53
+ readonly catalogEntries: readonly PolicyCatalogEntryProps[];
54
+ readonly definitions: readonly PolicyDefinition[];
55
+ readonly evaluators: readonly ComputeEvaluatorRegistration[];
56
+ }
57
+ //#endregion
58
+ //#region src/core/policies/catalog/catalog.instance.d.ts
59
+ /**
60
+ * Aggregates catalog entries contributed by each module package into a single
61
+ * PolicyCatalog. The core knows nothing about concrete modules — callers
62
+ * are responsible for passing all relevant packages at composition time.
63
+ */
64
+ declare class PolicyCatalogFactory {
65
+ static build(packages: readonly PolicyPackage[]): PolicyCatalog;
66
+ }
67
+ //#endregion
68
+ //#region src/core/policies/context/context-registry.instance.d.ts
69
+ /**
70
+ * Official instance of the ContextResolverRegistry.
71
+ * Use `new ContextResolverRegistry()` plus `registerNamespacedContextResolversIn`
72
+ * when each runtime/composition root needs its own isolated resolver graph.
73
+ */
74
+ declare const contextResolverRegistry: ContextResolverRegistry;
75
+ declare function registerNamespacedContextResolvers(namespace: string, resolvers: readonly ContextValueResolver[]): Result<ContextResolverRegistry, string>;
76
+ //#endregion
77
+ //#region src/core/policies/context/path.d.ts
78
+ declare class PolicyContextPath {
79
+ private static readonly FORBIDDEN_SEGMENTS;
80
+ private static resolve;
81
+ private static parseSegments;
82
+ private static isPlainRecord;
83
+ static getOrAbsent(obj: Record<string, unknown>, path: string): Result<unknown, "absent">;
84
+ static has(obj: Record<string, unknown>, path: string): boolean;
85
+ static set(obj: Record<string, unknown>, path: string, value: unknown): Result<void, string>;
86
+ }
87
+ //#endregion
88
+ export { PolicyPackage as a, coreConfig as c, PolicyCatalogFactory as i, contextResolverRegistry as n, InMemoryPolicyDefinitionRepository as o, registerNamespacedContextResolvers as r, PolicyHashing as s, PolicyContextPath as t };
89
+ //# sourceMappingURL=path.d.ts.map
@@ -1,3 +1,4 @@
1
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";
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,6 @@
1
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";
2
+ 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";
3
+ 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";
4
+ 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";
5
+ import { a as ComputePayloadParserRegistry, c as ComputeEvaluatorRegistry, o as ComputePayloadParsers, r as GatePayloadParsers, s as ComputeEngineRegistry } from "../parse-gate-payload.js";
4
6
  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 };