@entifix/business 0.23.2 → 0.23.3

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.
@@ -18,6 +18,8 @@ export type EntityApiGuard = {
18
18
  } | {
19
19
  readonly kind: 'crossing';
20
20
  readonly organization: boolean;
21
+ /** The named caller whose token alone this endpoint accepts. */
22
+ readonly caller?: string;
21
23
  };
22
24
  /** The affordances an entity's endpoints derive from the verbs they serve. */
23
25
  export interface EntityApiLinks {
@@ -1 +1 @@
1
- {"version":3,"file":"entity-api.d.ts","sourceRoot":"","sources":["../../src/entity-api/entity-api.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EAEb,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEtE,8DAA8D;AAC9D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5E;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAC/B;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GACjC;IAAE,QAAQ,CAAC,IAAI,EAAE,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C,CAAC;CACrB;AAED,+DAA+D;AAC/D,KAAK,KAAK,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,MAAM,EAChB,KAAK,CAAC,CAAC,SAAS,MAAM,EAEtB,KAAK,CAAC,CAAC,SAAS,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,EAExC,QAAQ,iBAAiB,CAAC,CAAC,CAAC,EAC5B,KAAK,CAAC,EAEN,SAAS,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAC1C,oBAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAA+B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/entity-api/entity-api.ts"],"sourcesContent":["import {\n type EndpointIdempotency,\n type EndpointSchema,\n type EntifixEnvelopeLink,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n extractUseCase,\n type FailureClass,\n type FilterGroup,\n type MetaUseCase,\n type UseCaseConstructor,\n} from '@entifix/core';\nimport type { Effect } from 'effect';\n\nimport type { RequestPrincipal } from '../request/request-context.js';\nimport type { ResolutionRule } from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** The five generic verbs an entity's endpoints can serve. */\nexport type EntityApiVerb = 'list' | 'get' | 'create' | 'update' | 'delete';\n\n/**\n * Who may reach an entity's endpoints. The permission is derived from the\n * entity and the verb, so it is never written here.\n */\nexport type EntityApiGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'permission' }\n | { readonly kind: 'organization' }\n | { readonly kind: 'crossing'; readonly organization: boolean };\n\n/** The affordances an entity's endpoints derive from the verbs they serve. */\nexport interface EntityApiLinks {\n readonly record: (id: EntityId) => EntifixEnvelopeLink[];\n readonly collection: () => EntifixEnvelopeLink[];\n}\n\n/** What a `prepare`, an override or a verb knows about the caller. */\nexport interface EntityApiContext {\n readonly organizationId?: string;\n readonly principal?: RequestPrincipal;\n readonly verified?: VerifiedContext;\n readonly links: EntityApiLinks;\n}\n\n/** What an override's handler receives: the decoded parts of its request. */\nexport interface EntityApiRequest {\n readonly params?: { readonly id?: string };\n readonly payload?: unknown;\n}\n\n/**\n * Which records of an entity a caller may see: every one, none, or those a\n * filter keeps ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n * A filter is conjoined onto the load request, so a query string can only\n * narrow it further and no `or` in it can escape.\n */\nexport type Narrowing<T extends Entity> =\n 'unscoped' | 'nothing' | FilterGroup<T>;\n\n/**\n * A read's narrowing as ordered resolver rules over the verified context: the\n * first variant the caller is entitled to and whose predicate holds builds the\n * narrowing. A caller no rule matches sees **nothing** — the direction a\n * missing rule must fail in.\n */\nexport type NarrowingRules<T extends Entity> = readonly ResolutionRule<\n (context: VerifiedContext) => Narrowing<T>\n>[];\n\n/**\n * One verb served by a handler of the host's instead of the generic one. It\n * keeps the group's path and links, and may change the guard, the payload,\n * the failures and the idempotency the verb declares.\n */\nexport interface EntityVerbOverride<R> {\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly errors?: readonly FailureClass[];\n /** The body the verb takes instead of an entity envelope. */\n readonly payload?: EndpointSchema;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/**\n * A `@useCase()` verb's endpoint: its path, method, permission and contract\n * come from the declaration, and only who may call it and what it does are\n * written here.\n */\nexport interface VerbEndpoint<R> {\n readonly useCase: MetaUseCase;\n /** Defaults to the group's write guard. */\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n /** The verb starts a flow and answers `202` with what to follow. */\n readonly accepted?: boolean;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n /**\n * The same verb over a selection, for a record-bound verb that also sits in\n * a collection cell (`alsoAt`): one permission for one act, whether it is\n * asked of a record or of twenty. Required exactly when that cell is\n * declared; its request carries the selection as its payload.\n */\n readonly bulk?: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/** Serve a `@useCase()` class's verb on its entity's endpoints. */\nexport const verbEndpoint = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends Omit<VerbEndpoint<any>, 'useCase'>,\n>(\n useCaseClass: UseCaseConstructor,\n options: O,\n): O & { readonly useCase: MetaUseCase } => ({\n ...options,\n useCase: extractUseCase(useCaseClass),\n});\n\n/** What an entity's endpoints serve, and under which rules. */\nexport interface EntityApiOptions<T extends Entity, R> {\n readonly verbs: readonly EntityApiVerb[];\n /** One guard for every verb, or one for the reads and one for the writes. */\n readonly guard:\n | EntityApiGuard\n | { readonly read: EntityApiGuard; readonly write: EntityApiGuard };\n /** Narrows the reads, and the facet counts, to what this caller may see. */\n readonly narrowing?: NarrowingRules<T>;\n /** Serve `$facets` beside the list, under the list's guard and narrowing. */\n readonly facets?: boolean;\n /** Runs on every generic create and update, before the save. */\n readonly prepare?: (\n entity: T,\n context: EntityApiContext & { readonly verb: 'create' | 'update' },\n ) => Effect.Effect<T, EntifixFailure, R>;\n /** The business failures `prepare` may answer with, for the contract. */\n readonly errors?: readonly FailureClass[];\n readonly override?: Partial<Record<EntityApiVerb, EntityVerbOverride<R>>>;\n /**\n * The entity's `@useCase()` verbs, one endpoint each. Every verb the entity\n * declares must be here and none another entity declares, or serving the\n * declaration throws.\n */\n readonly useCases?: readonly VerbEndpoint<R>[];\n}\n\n/**\n * An entity's endpoints as a value: which verbs, behind which guards, with\n * which handlers. Declaring them needs no HTTP — a domain's cell declares, and\n * the shell serves the declaration with `entityApi`\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n */\nexport interface EntityApiDeclaration<\n T extends Entity,\n K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n O extends EntityApiOptions<T, any>,\n> {\n readonly entity: EntityConstructor<T>;\n readonly key: K;\n readonly options: O;\n}\n\n/** `O`, with every key `Shape` does not name typed `never`. */\ntype Exact<O, Shape> = O & Record<Exclude<keyof O, keyof Shape>, never>;\n\n/**\n * Declare an entity's endpoints, to be served by the shell. An option the\n * declaration does not know is a compile error rather than a value nobody\n * reads — `compositions` included, which the shell adds when it serves.\n */\nexport const defineEntityApi = <\n T extends Entity,\n const K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends EntityApiOptions<T, any>,\n>(\n entity: EntityConstructor<T>,\n key: K,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n options: Exact<O, EntityApiOptions<T, any>>,\n): EntityApiDeclaration<T, K, O> => ({ entity, key, options });\n"],"names":["extractUseCase","verbEndpoint","useCaseClass","options","useCase","defineEntityApi","entity","key"],"mappings":";AAAA,SAQEA,cAAc,QAKT,gBAAgB;AAwGvB,iEAAiE,GACjE,OAAO,MAAMC,eAAe,CAI1BC,cACAC,UAC2C,aACxCA;QACHC,SAASJ,eAAeE;OACvB;AAiDH;;;;CAIC,GACD,OAAO,MAAMG,kBAAkB,CAM7BC,QACAC,KACA,2FAA2F;AAC3FJ,UACmC,CAAA;QAAEG;QAAQC;QAAKJ;IAAQ,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../src/entity-api/entity-api.ts"],"sourcesContent":["import {\n type EndpointIdempotency,\n type EndpointSchema,\n type EntifixEnvelopeLink,\n type EntifixFailure,\n type Entity,\n type EntityConstructor,\n type EntityId,\n extractUseCase,\n type FailureClass,\n type FilterGroup,\n type MetaUseCase,\n type UseCaseConstructor,\n} from '@entifix/core';\nimport type { Effect } from 'effect';\n\nimport type { RequestPrincipal } from '../request/request-context.js';\nimport type { ResolutionRule } from '../resolve/resolve.js';\nimport type { VerifiedContext } from '../resolve/verified-context.js';\n\n/** The five generic verbs an entity's endpoints can serve. */\nexport type EntityApiVerb = 'list' | 'get' | 'create' | 'update' | 'delete';\n\n/**\n * Who may reach an entity's endpoints. The permission is derived from the\n * entity and the verb, so it is never written here.\n */\nexport type EntityApiGuard =\n | { readonly kind: 'public' }\n | { readonly kind: 'permission' }\n | { readonly kind: 'organization' }\n | {\n readonly kind: 'crossing';\n readonly organization: boolean;\n /** The named caller whose token alone this endpoint accepts. */\n readonly caller?: string;\n };\n\n/** The affordances an entity's endpoints derive from the verbs they serve. */\nexport interface EntityApiLinks {\n readonly record: (id: EntityId) => EntifixEnvelopeLink[];\n readonly collection: () => EntifixEnvelopeLink[];\n}\n\n/** What a `prepare`, an override or a verb knows about the caller. */\nexport interface EntityApiContext {\n readonly organizationId?: string;\n readonly principal?: RequestPrincipal;\n readonly verified?: VerifiedContext;\n readonly links: EntityApiLinks;\n}\n\n/** What an override's handler receives: the decoded parts of its request. */\nexport interface EntityApiRequest {\n readonly params?: { readonly id?: string };\n readonly payload?: unknown;\n}\n\n/**\n * Which records of an entity a caller may see: every one, none, or those a\n * filter keeps ([ADR 0015](../../../../../docs/adr/0015-composed-flows-and-use-case-resolution.md)).\n * A filter is conjoined onto the load request, so a query string can only\n * narrow it further and no `or` in it can escape.\n */\nexport type Narrowing<T extends Entity> =\n 'unscoped' | 'nothing' | FilterGroup<T>;\n\n/**\n * A read's narrowing as ordered resolver rules over the verified context: the\n * first variant the caller is entitled to and whose predicate holds builds the\n * narrowing. A caller no rule matches sees **nothing** — the direction a\n * missing rule must fail in.\n */\nexport type NarrowingRules<T extends Entity> = readonly ResolutionRule<\n (context: VerifiedContext) => Narrowing<T>\n>[];\n\n/**\n * One verb served by a handler of the host's instead of the generic one. It\n * keeps the group's path and links, and may change the guard, the payload,\n * the failures and the idempotency the verb declares.\n */\nexport interface EntityVerbOverride<R> {\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n readonly errors?: readonly FailureClass[];\n /** The body the verb takes instead of an entity envelope. */\n readonly payload?: EndpointSchema;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/**\n * A `@useCase()` verb's endpoint: its path, method, permission and contract\n * come from the declaration, and only who may call it and what it does are\n * written here.\n */\nexport interface VerbEndpoint<R> {\n readonly useCase: MetaUseCase;\n /** Defaults to the group's write guard. */\n readonly guard?: EntityApiGuard;\n readonly idempotent?: EndpointIdempotency;\n /** The verb starts a flow and answers `202` with what to follow. */\n readonly accepted?: boolean;\n readonly handler: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n /**\n * The same verb over a selection, for a record-bound verb that also sits in\n * a collection cell (`alsoAt`): one permission for one act, whether it is\n * asked of a record or of twenty. Required exactly when that cell is\n * declared; its request carries the selection as its payload.\n */\n readonly bulk?: (\n request: EntityApiRequest,\n context: EntityApiContext,\n ) => Effect.Effect<unknown, EntifixFailure, R>;\n}\n\n/** Serve a `@useCase()` class's verb on its entity's endpoints. */\nexport const verbEndpoint = <\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends Omit<VerbEndpoint<any>, 'useCase'>,\n>(\n useCaseClass: UseCaseConstructor,\n options: O,\n): O & { readonly useCase: MetaUseCase } => ({\n ...options,\n useCase: extractUseCase(useCaseClass),\n});\n\n/** What an entity's endpoints serve, and under which rules. */\nexport interface EntityApiOptions<T extends Entity, R> {\n readonly verbs: readonly EntityApiVerb[];\n /** One guard for every verb, or one for the reads and one for the writes. */\n readonly guard:\n | EntityApiGuard\n | { readonly read: EntityApiGuard; readonly write: EntityApiGuard };\n /** Narrows the reads, and the facet counts, to what this caller may see. */\n readonly narrowing?: NarrowingRules<T>;\n /** Serve `$facets` beside the list, under the list's guard and narrowing. */\n readonly facets?: boolean;\n /** Runs on every generic create and update, before the save. */\n readonly prepare?: (\n entity: T,\n context: EntityApiContext & { readonly verb: 'create' | 'update' },\n ) => Effect.Effect<T, EntifixFailure, R>;\n /** The business failures `prepare` may answer with, for the contract. */\n readonly errors?: readonly FailureClass[];\n readonly override?: Partial<Record<EntityApiVerb, EntityVerbOverride<R>>>;\n /**\n * The entity's `@useCase()` verbs, one endpoint each. Every verb the entity\n * declares must be here and none another entity declares, or serving the\n * declaration throws.\n */\n readonly useCases?: readonly VerbEndpoint<R>[];\n}\n\n/**\n * An entity's endpoints as a value: which verbs, behind which guards, with\n * which handlers. Declaring them needs no HTTP — a domain's cell declares, and\n * the shell serves the declaration with `entityApi`\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)).\n */\nexport interface EntityApiDeclaration<\n T extends Entity,\n K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n O extends EntityApiOptions<T, any>,\n> {\n readonly entity: EntityConstructor<T>;\n readonly key: K;\n readonly options: O;\n}\n\n/** `O`, with every key `Shape` does not name typed `never`. */\ntype Exact<O, Shape> = O & Record<Exclude<keyof O, keyof Shape>, never>;\n\n/**\n * Declare an entity's endpoints, to be served by the shell. An option the\n * declaration does not know is a compile error rather than a value nobody\n * reads — `compositions` included, which the shell adds when it serves.\n */\nexport const defineEntityApi = <\n T extends Entity,\n const K extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n const O extends EntityApiOptions<T, any>,\n>(\n entity: EntityConstructor<T>,\n key: K,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any -- inferred from the options\n options: Exact<O, EntityApiOptions<T, any>>,\n): EntityApiDeclaration<T, K, O> => ({ entity, key, options });\n"],"names":["extractUseCase","verbEndpoint","useCaseClass","options","useCase","defineEntityApi","entity","key"],"mappings":";AAAA,SAQEA,cAAc,QAKT,gBAAgB;AA6GvB,iEAAiE,GACjE,OAAO,MAAMC,eAAe,CAI1BC,cACAC,UAC2C,aACxCA;QACHC,SAASJ,eAAeE;OACvB;AAiDH;;;;CAIC,GACD,OAAO,MAAMG,kBAAkB,CAM7BC,QACAC,KACA,2FAA2F;AAC3FJ,UACmC,CAAA;QAAEG;QAAQC;QAAKJ;IAAQ,CAAA,EAAG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/business",
3
- "version": "0.23.2",
3
+ "version": "0.23.3",
4
4
  "description": "The ports every adapter implements — repository, session, token, health — and the generic get, load, save and delete use-cases.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "dependencies": {
68
68
  "@swc/helpers": "0.5.23",
69
- "@entifix/core": "0.23.2"
69
+ "@entifix/core": "0.23.3"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "effect": "^4.0.7"