@cullet/erp-core 1.0.11 → 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.
- package/KIT_CONTEXT.md +67 -0
- package/README.md +128 -1
- package/dist/app-error.d.ts +108 -0
- package/dist/application/index.d.ts +2 -0
- package/dist/application/index.js +2 -0
- package/dist/errors/index.d.ts +2 -1
- package/dist/errors/index.js +4 -2
- package/dist/gate-engine-registry.d.ts +80 -0
- package/dist/gate-v1-payload.schema.js +2 -28
- package/dist/gate-v1-payload.schema.js.map +1 -1
- package/dist/hashing.js +49 -0
- package/dist/hashing.js.map +1 -0
- package/dist/index.d.ts +11 -45
- package/dist/index.js +12 -85
- package/dist/index.js.map +1 -1
- package/dist/not-found-error.js +54 -0
- package/dist/not-found-error.js.map +1 -0
- package/dist/outcome.js +1 -1
- package/dist/parse-gate-payload.d.ts +3 -78
- package/dist/path.d.ts +89 -0
- package/dist/policies/engines/index.d.ts +2 -1
- package/dist/policies/index.d.ts +4 -2
- package/dist/policy-service.d.ts +3 -86
- package/dist/policy-service.js +5 -16
- package/dist/policy-service.js.map +1 -1
- package/dist/temporal-guards.js +30 -0
- package/dist/temporal-guards.js.map +1 -0
- package/dist/temporal-use-case.d.ts +309 -0
- package/dist/temporal-use-case.js +284 -0
- package/dist/temporal-use-case.js.map +1 -0
- package/dist/validation-code.js +1 -47
- package/dist/validation-code.js.map +1 -1
- package/dist/validation-error.d.ts +2 -107
- package/dist/validation-error.js +2 -52
- package/dist/validation-error.js.map +1 -1
- package/dist/validation-exception.js +18 -0
- package/dist/validation-exception.js.map +1 -0
- package/meta.json +3 -2
- package/package.json +5 -1
- package/src/application/index.ts +1 -0
- package/src/core/application/commands/index.ts +1 -0
- package/src/core/application/index.ts +12 -3
- package/src/core/application/ports/index.ts +2 -2
- package/src/core/application/ports/policy-port.ts +13 -3
- package/src/core/application/ports/repository.port.ts +37 -1
- package/src/core/application/temporal/temporal-use-case.ts +14 -2
- package/src/core/application/use-case.ts +133 -2
- package/src/core/index.ts +1 -10
- package/src/examples/application/cancel-order.example.ts +124 -0
- package/src/examples/application/in-memory-account-repository.example.ts +73 -0
- package/src/version.ts +1 -1
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.11\";\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\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 { 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/**\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":"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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,58 +1,6 @@
|
|
|
1
|
-
import { I as Result,
|
|
2
|
-
import {
|
|
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 {
|
|
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 {
|
|
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 };
|
package/dist/policies/index.d.ts
CHANGED
|
@@ -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 {
|
|
3
|
-
import { a as
|
|
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 };
|
package/dist/policy-service.d.ts
CHANGED
|
@@ -1,36 +1,6 @@
|
|
|
1
|
-
import { C as TenantId, I as Result, S as SchoolId, b as PolicyDecisionId,
|
|
2
|
-
import {
|
|
1
|
+
import { C as TenantId, I as Result, S as SchoolId, b as PolicyDecisionId, t as GateOutcome, u as GatePayload, x as PolicyDefinitionId, y as PolicyReporter } from "./gate-types.js";
|
|
2
|
+
import { a as ComputeOutcome, l as ComputePayload, n as ComputeRegistry, t as GateEngineRegistry } from "./gate-engine-registry.js";
|
|
3
3
|
|
|
4
|
-
//#region src/core/config/core-config.instance.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Shared instance for the application composition root.
|
|
8
|
-
* Use `new CoreConfig()` for isolated runtimes, tests, or multi-tenant hosts.
|
|
9
|
-
*
|
|
10
|
-
* The default reporter is silent so the core has no runtime logging dependency.
|
|
11
|
-
* Hosts can swap in their own `PolicyReporter` via
|
|
12
|
-
* `coreConfig.configure({ observability: { reporter } })`.
|
|
13
|
-
*/
|
|
14
|
-
declare const coreConfig: CoreConfig;
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/core/policies/utils/hash.d.ts
|
|
17
|
-
/**
|
|
18
|
-
* Produces a deterministic SHA-256 hex digest of a canonical JSON representation.
|
|
19
|
-
* Object keys are sorted recursively so key order does not affect the hash.
|
|
20
|
-
* Array item order is preserved on purpose; callers that treat arrays as sets
|
|
21
|
-
* must normalize or sort them before hashing.
|
|
22
|
-
*
|
|
23
|
-
* Values that JSON.stringify would silently drop or coerce (undefined,
|
|
24
|
-
* non-finite numbers, functions, symbols, bigint) are rejected up-front to
|
|
25
|
-
* prevent semantically different payloads from collapsing to the same hash.
|
|
26
|
-
*/
|
|
27
|
-
declare class PolicyHashing {
|
|
28
|
-
static sha256(input: string): string;
|
|
29
|
-
private static assertHashable;
|
|
30
|
-
static canonicalJson(value: unknown): string;
|
|
31
|
-
static computePayloadHash(payload: unknown, policyKey: string, policyVersion: string): string;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
4
|
//#region src/core/policies/catalog/catalog-types.d.ts
|
|
35
5
|
type PolicyKind = "GATE" | "COMPUTE";
|
|
36
6
|
type PolicyOwner = "PLATFORM_OWNER" | "TENANT_ADMIN" | "SCHOOL_ADMIN";
|
|
@@ -289,39 +259,6 @@ interface PolicyDefinitionRepository {
|
|
|
289
259
|
findCandidates(params: FindCandidatesParams): PolicyDefinition[];
|
|
290
260
|
}
|
|
291
261
|
//#endregion
|
|
292
|
-
//#region src/core/policies/defs/in-memory-policy-definition-repo.d.ts
|
|
293
|
-
declare class InMemoryPolicyDefinitionRepository implements PolicyDefinitionRepository {
|
|
294
|
-
private readonly definitions;
|
|
295
|
-
private readonly definitionsByPolicyKey;
|
|
296
|
-
constructor(definitions: readonly PolicyDefinition[]);
|
|
297
|
-
findCandidates(params: FindCandidatesParams): PolicyDefinition[];
|
|
298
|
-
}
|
|
299
|
-
//#endregion
|
|
300
|
-
//#region src/core/policies/package/policy-package.d.ts
|
|
301
|
-
/**
|
|
302
|
-
* Protocol of contribution: a module declares what it wants to add to the
|
|
303
|
-
* policy system without the core knowing which module it is.
|
|
304
|
-
*
|
|
305
|
-
* - catalogEntries: static policy descriptors the catalog will register.
|
|
306
|
-
* - definitions: default policy definitions (rules/parameters) to seed.
|
|
307
|
-
* - evaluators: compute evaluator registrations keyed by policy/version.
|
|
308
|
-
*/
|
|
309
|
-
interface PolicyPackage {
|
|
310
|
-
readonly catalogEntries: readonly PolicyCatalogEntryProps[];
|
|
311
|
-
readonly definitions: readonly PolicyDefinition[];
|
|
312
|
-
readonly evaluators: readonly ComputeEvaluatorRegistration[];
|
|
313
|
-
}
|
|
314
|
-
//#endregion
|
|
315
|
-
//#region src/core/policies/catalog/catalog.instance.d.ts
|
|
316
|
-
/**
|
|
317
|
-
* Aggregates catalog entries contributed by each module package into a single
|
|
318
|
-
* PolicyCatalog. The core knows nothing about concrete modules — callers
|
|
319
|
-
* are responsible for passing all relevant packages at composition time.
|
|
320
|
-
*/
|
|
321
|
-
declare class PolicyCatalogFactory {
|
|
322
|
-
static build(packages: readonly PolicyPackage[]): PolicyCatalog;
|
|
323
|
-
}
|
|
324
|
-
//#endregion
|
|
325
262
|
//#region src/core/policies/context/context-seed.d.ts
|
|
326
263
|
/**
|
|
327
264
|
* Seed data provided by the use case / caller.
|
|
@@ -417,26 +354,6 @@ declare class PolicyContextBuilder {
|
|
|
417
354
|
build(requirements: readonly string[], seed: ContextSeed): Promise<Result<Record<string, unknown>, string>>;
|
|
418
355
|
}
|
|
419
356
|
//#endregion
|
|
420
|
-
//#region src/core/policies/context/context-registry.instance.d.ts
|
|
421
|
-
/**
|
|
422
|
-
* Official instance of the ContextResolverRegistry.
|
|
423
|
-
* Use `new ContextResolverRegistry()` plus `registerNamespacedContextResolversIn`
|
|
424
|
-
* when each runtime/composition root needs its own isolated resolver graph.
|
|
425
|
-
*/
|
|
426
|
-
declare const contextResolverRegistry: ContextResolverRegistry;
|
|
427
|
-
declare function registerNamespacedContextResolvers(namespace: string, resolvers: readonly ContextValueResolver[]): Result<ContextResolverRegistry, string>;
|
|
428
|
-
//#endregion
|
|
429
|
-
//#region src/core/policies/context/path.d.ts
|
|
430
|
-
declare class PolicyContextPath {
|
|
431
|
-
private static readonly FORBIDDEN_SEGMENTS;
|
|
432
|
-
private static resolve;
|
|
433
|
-
private static parseSegments;
|
|
434
|
-
private static isPlainRecord;
|
|
435
|
-
static getOrAbsent(obj: Record<string, unknown>, path: string): Result<unknown, "absent">;
|
|
436
|
-
static has(obj: Record<string, unknown>, path: string): boolean;
|
|
437
|
-
static set(obj: Record<string, unknown>, path: string, value: unknown): Result<void, string>;
|
|
438
|
-
}
|
|
439
|
-
//#endregion
|
|
440
357
|
//#region src/core/policies/asof/asof.d.ts
|
|
441
358
|
interface DeriveAsOfOptions {
|
|
442
359
|
readonly maxFutureYears?: number;
|
|
@@ -637,5 +554,5 @@ declare class PolicyService {
|
|
|
637
554
|
evaluate(input: EvaluateInput): Promise<Result<PolicyEvaluationResult, PolicyEvaluationError>>;
|
|
638
555
|
}
|
|
639
556
|
//#endregion
|
|
640
|
-
export {
|
|
557
|
+
export { PolicyScope as A, BasePolicyDefinitionProps as C, PolicyDefinition as D, GatePolicyDefinitionProps as E, PolicyKey as F, AsOfSource as I, PolicyKind as L, ScopeChain as M, PolicyCatalog as N, PolicyDefinitionProps as O, PolicyCatalogEntryProps as P, PolicyOwner as R, PolicyDefinitionRepository as S, FindCandidatesParams as T, ContextResolverResilienceOptions as _, PolicyServiceOptions as a, ContextSeed as b, PolicyEvaluationErrors as c, PolicyAsOfResolver as d, PolicyContextBuilder as f, ContextResolverCircuitBreakerOptions as g, registerNamespacedContextResolversIn as h, PolicyService as i, PolicyScopeMatcher as j, PolicyDefinitionStatus as k, PolicyResolver as l, ContextResolverRegistry as m, PolicyDecision as n, PolicyServiceParams as o, PolicyContextBuilderOptions as p, PolicyEvaluationResult as r, PolicyEvaluationError as s, EvaluateInput as t, DeriveAsOfOptions as u, ContextResolverRetryOptions as v, ComputePolicyDefinitionProps as w, ContextSeedValidator as x, ContextValueResolver as y, PolicyScopeLevel as z };
|
|
641
558
|
//# sourceMappingURL=policy-service.d.ts.map
|
package/dist/policy-service.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as UnexpectedError, t as ValidationCode } from "./validation-code.js";
|
|
2
|
+
import { n as sha256Hex, r as stableStringify } from "./hashing.js";
|
|
2
3
|
import { t as ValidationField } from "./validation-field.js";
|
|
3
|
-
import {
|
|
4
|
+
import { i as InvariantViolationException, r as isValidDate } from "./temporal-guards.js";
|
|
5
|
+
import { t as InvalidValueException } from "./validation-exception.js";
|
|
6
|
+
import { f as SilentPolicyReporter, l as Result, o as PolicyContextPath } from "./gate-v1-payload.schema.js";
|
|
4
7
|
//#region src/core/policies/utils/hash.ts
|
|
5
8
|
/**
|
|
6
9
|
* Produces a deterministic SHA-256 hex digest of a canonical JSON representation.
|
|
@@ -49,20 +52,6 @@ var PolicyHashing = class PolicyHashing {
|
|
|
49
52
|
}
|
|
50
53
|
};
|
|
51
54
|
//#endregion
|
|
52
|
-
//#region src/core/exceptions/validation-exception.ts
|
|
53
|
-
var ValidationException = class extends DomainException {
|
|
54
|
-
constructor(field, code, message) {
|
|
55
|
-
super(message);
|
|
56
|
-
this.field = field;
|
|
57
|
-
this.code = code;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var InvalidValueException = class extends ValidationException {
|
|
61
|
-
constructor(field, code, message) {
|
|
62
|
-
super(field, code, message);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
//#endregion
|
|
66
55
|
//#region src/core/policies/policy-ids.ts
|
|
67
56
|
const POLICY_DEFINITION_ID_FIELD = ValidationField.of("policyDefinitionId");
|
|
68
57
|
const POLICY_DECISION_ID_FIELD = ValidationField.of("policyDecisionId");
|