@entifix/authz 0.8.0 → 0.10.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.
@@ -1 +1 @@
1
- {"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../../src/values/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EAEX,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAGtB,KAAK,kBAAkB,EACxB,MAAM,eAAe,CAAC;AAEvB;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,sCAAiB,CAAC;AACtC,MAAM,MAAM,MAAM,GAAG,YAAY,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,WAAW,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAEzD,gFAAgF;AAChF,MAAM,MAAM,QAAQ,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAK7C,2EAA2E;AAC3E,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,EACd,WAAW,MAAM,EACjB,QAAQ,gBAAgB,KACvB,UAAgD,CAAC;AAEpD,wEAAwE;AACxE,eAAO,MAAM,YAAY,GACvB,UAAU,QAAQ,EAClB,QAAQ,gBAAgB,KACvB,UAAqC,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,EAClD,mBAAmB,iBAAiB,CAAC,CAAC,CAAC,EACvC,QAAQ,MAAM,KACb,UAQF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,UAAU,CAAC;AAC9E,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACn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AAiB,CAAC,CAAC,CAAC,EACvC,QAAQ,MAAM,KACb,UAQF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,UAAU,CAAC;AAC9E,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,iBAAiB,EAAE,iBAAiB,CAAC,CAAC,CAAC,EACvC,GAAG,EAAE,WAAW,GACf,UAAU,CAAC;AA2Bd;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC1B,YAAY,UAAU,KACrB;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAiBhD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,SAAS,UAAU,EACnB,UAAU,UAAU,KACnB,OAaF,CAAC"}
@@ -1,4 +1,4 @@
1
- import { describeEntityUseCases, EntifixBuildError, ENTITY_ACTIONS, extractMetaEntity, extractMetaUseCaseBinding } from '@entifix/core';
1
+ import { describeEntityUseCases, ENTITY_ACTIONS, extractMetaEntity, extractMetaUseCaseBinding } from '@entifix/core';
2
2
  /**
3
3
  * What a caller wants to do with a resource.
4
4
  *
@@ -19,7 +19,7 @@ const WILDCARD = '*';
19
19
  */ export const permissionForEntity = (entityConstructor, action)=>{
20
20
  const meta = extractMetaEntity(entityConstructor);
21
21
  if (meta.domain === undefined || meta.key === undefined) {
22
- throw new EntifixBuildError(`Entity ${entityConstructor.name} needs both a domain and a key to derive a permission`);
22
+ throw new Error(`Entity ${entityConstructor.name} needs both a domain and a key to derive a permission`);
23
23
  }
24
24
  return permissionFor(meta.domain, meta.key, action);
25
25
  };
@@ -30,11 +30,11 @@ export function permissionForUseCase(target, key) {
30
30
  };
31
31
  const meta = extractMetaEntity(binding.entity);
32
32
  if (meta.domain === undefined || meta.key === undefined) {
33
- throw new EntifixBuildError(`Entity ${binding.entity.name} needs both a domain and a key to derive a permission`);
33
+ throw new Error(`Entity ${binding.entity.name} needs both a domain and a key to derive a permission`);
34
34
  }
35
35
  const declares = describeEntityUseCases(binding.entity).some((useCase)=>useCase.key === binding.key);
36
36
  if (!declares) {
37
- throw new EntifixBuildError(`Entity ${binding.entity.name} does not declare the use case "${binding.key}"`);
37
+ throw new Error(`Entity ${binding.entity.name} does not declare the use case "${binding.key}"`);
38
38
  }
39
39
  return permissionFor(meta.domain, meta.key, binding.key);
40
40
  }
@@ -45,7 +45,7 @@ export function permissionForUseCase(target, key) {
45
45
  */ export const parsePermission = (permission)=>{
46
46
  const segments = permission.split(':');
47
47
  if (segments.length !== SEGMENT_COUNT) {
48
- throw new EntifixBuildError(`Malformed permission "${permission}" — expected <domain>:<entityKey>:<action>`);
48
+ throw new Error(`Malformed permission "${permission}" — expected <domain>:<entityKey>:<action>`);
49
49
  }
50
50
  // The cast is only the arity the length check above already established. It
51
51
  // deliberately does not narrow the action segment: that used to say `Action`,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/values/permission.ts"],"sourcesContent":["import {\n describeEntityUseCases,\n EntifixBuildError,\n type Entity,\n ENTITY_ACTIONS,\n type EntityAction,\n type EntityConstructor,\n extractMetaEntity,\n extractMetaUseCaseBinding,\n type UseCaseConstructor,\n} from '@entifix/core';\n\n/**\n * What a caller wants to do with a resource.\n *\n * Defined in `@entifix/core` and aliased here, not duplicated: a UI\n * reads the same triple off a served `EntityMetadataDocument` to decide whether\n * to render Save and Delete, and a T3 package may not import this one, which\n * is T4. Aliasing keeps one definition and leaves every call site below\n * unchanged.\n */\nexport const Actions = ENTITY_ACTIONS;\nexport type Action = EntityAction;\n\n/**\n * A verb declared by `@useCase()` — `publish`, `revoke-sessions`, `approve`.\n *\n * Per-entity and open, rather than one global union every domain appends to:\n * that would make an unrelated domain's verb assignable everywhere and grow\n * without bound. The check that a verb exists is therefore at runtime, in\n * {@link permissionForUseCase}, and in whatever source scan a host's register\n * runs.\n */\nexport type UseCaseVerb = string;\n\n/**\n * The third segment of a permission: the CRUD triple, or a use-case verb.\n *\n * `Action` stays the narrow three-value union, and every place that guards CRUD\n * keeps using it. This wider alias exists only where a segment has already been\n * parsed off a string and could legitimately be either.\n */\nexport type PermissionAction = Action | UseCaseVerb;\n\n/**\n * A permission is three colon-separated segments — `<domain>:<entityKey>:<action>`\n * — so it can be derived from an entity's own `@entity({ domain, key })`\n * metadata rather than maintained as a parallel list. `*` in any segment of a\n * **granted** permission is a wildcard (see {@link permissionMatches}); a\n * **required** permission is always concrete.\n */\nexport type Permission = `${string}:${string}:${string}`;\n\n/** The `<domain>:<entityKey>` half of a permission — what is being acted on. */\nexport type Resource = `${string}:${string}`;\n\nconst SEGMENT_COUNT = 3;\nconst WILDCARD = '*';\n\n/** Build a permission from its parts. `*` is a legal action on a grant. */\nexport const permissionFor = (\n domain: string,\n entityKey: string,\n action: PermissionAction,\n): Permission => `${domain}:${entityKey}:${action}`;\n\n/** Join a resource and an action into the permission that guards it. */\nexport const permissionOf = (\n resource: Resource,\n action: PermissionAction,\n): Permission => `${resource}:${action}`;\n\n/**\n * Derive the permission guarding an entity from the entity itself. This is the\n * point of the `<domain>:<key>:<action>` shape: making a new entity guardable\n * needs no new vocabulary, only its existing `@entity()` metadata.\n */\nexport const permissionForEntity = <T extends Entity>(\n entityConstructor: EntityConstructor<T>,\n action: Action,\n): Permission => {\n const meta = extractMetaEntity(entityConstructor);\n if (meta.domain === undefined || meta.key === undefined) {\n throw new EntifixBuildError(\n `Entity ${entityConstructor.name} needs both a domain and a key to derive a permission`,\n );\n }\n return permissionFor(meta.domain, meta.key, action);\n};\n\n/**\n * Derive the permission guarding a use case.\n *\n * The **one-argument** form is what call sites use: a `@useCase()` class knows\n * both the entity it acts on and its own verb, so the verb string is written\n * once — in the decorator — and every guard imports the derived constant instead\n * of retyping it. The **two-argument** form is for a caller that holds only the\n * entity, which is the `$metadata` route walking an entity's descriptors.\n *\n * Both check that the entity really declares the verb, so a typo throws at\n * module load rather than silently denying every request. That check is at\n * runtime because compile-time narrowing does not survive the decorator\n * boundary: `Symbol.metadata` erases types and `extractMetaEntity` hands back an\n * untyped `MetaEntity`. Nothing is lost that existed — `parsePermission` looks\n * like it validates the action segment and does not.\n */\nexport function permissionForUseCase(useCase: UseCaseConstructor): Permission;\nexport function permissionForUseCase<T extends Entity>(\n entityConstructor: EntityConstructor<T>,\n key: UseCaseVerb,\n): Permission;\nexport function permissionForUseCase(\n target: UseCaseConstructor | EntityConstructor<Entity>,\n key?: UseCaseVerb,\n): Permission {\n const binding =\n key === undefined\n ? extractMetaUseCaseBinding(target as UseCaseConstructor)\n : { entity: target as EntityConstructor<Entity>, key };\n\n const meta = extractMetaEntity(binding.entity);\n if (meta.domain === undefined || meta.key === undefined) {\n throw new EntifixBuildError(\n `Entity ${binding.entity.name} needs both a domain and a key to derive a permission`,\n );\n }\n const declares = describeEntityUseCases(binding.entity).some(\n useCase => useCase.key === binding.key,\n );\n if (!declares) {\n throw new EntifixBuildError(\n `Entity ${binding.entity.name} does not declare the use case \"${binding.key}\"`,\n );\n }\n return permissionFor(meta.domain, meta.key, binding.key);\n}\n\n/**\n * Split a permission back into the resource + action a policy decision reads.\n * Throws on anything that is not exactly three segments, so a typo in a guard\n * fails at the call site instead of silently denying every request.\n */\nexport const parsePermission = (\n permission: Permission,\n): { resource: Resource; action: PermissionAction } => {\n const segments = permission.split(':');\n if (segments.length !== SEGMENT_COUNT) {\n throw new EntifixBuildError(\n `Malformed permission \"${permission}\" — expected <domain>:<entityKey>:<action>`,\n );\n }\n // The cast is only the arity the length check above already established. It\n // deliberately does not narrow the action segment: that used to say `Action`,\n // which read as a typo check it never performed, and is now false as well —\n // a use-case verb is a legal third segment.\n const [domain, entityKey, action] = segments as [\n string,\n string,\n PermissionAction,\n ];\n return { resource: `${domain}:${entityKey}`, action };\n};\n\n/**\n * Does a granted permission cover a required one? Compared segment by segment,\n * with `*` on the granted side matching anything. `super-admin`'s `*:*:*` thus\n * covers everything, and `product-configuration-management:*:read` covers every\n * entity in that domain without naming them.\n */\nexport const permissionMatches = (\n granted: Permission,\n required: Permission,\n): boolean => {\n const grantedSegments = granted.split(':');\n const requiredSegments = required.split(':');\n if (\n grantedSegments.length !== SEGMENT_COUNT ||\n requiredSegments.length !== SEGMENT_COUNT\n ) {\n return false;\n }\n return grantedSegments.every(\n (segment, index) =>\n segment === WILDCARD || segment === requiredSegments[index],\n );\n};\n"],"names":["describeEntityUseCases","EntifixBuildError","ENTITY_ACTIONS","extractMetaEntity","extractMetaUseCaseBinding","Actions","SEGMENT_COUNT","WILDCARD","permissionFor","domain","entityKey","action","permissionOf","resource","permissionForEntity","entityConstructor","meta","undefined","key","name","permissionForUseCase","target","binding","entity","declares","some","useCase","parsePermission","permission","segments","split","length","permissionMatches","granted","required","grantedSegments","requiredSegments","every","segment","index"],"mappings":"AAAA,SACEA,sBAAsB,EACtBC,iBAAiB,EAEjBC,cAAc,EAGdC,iBAAiB,EACjBC,yBAAyB,QAEpB,gBAAgB;AAEvB;;;;;;;;CAQC,GACD,OAAO,MAAMC,UAAUH,eAAe;AAmCtC,MAAMI,gBAAgB;AACtB,MAAMC,WAAW;AAEjB,yEAAyE,GACzE,OAAO,MAAMC,gBAAgB,CAC3BC,QACAC,WACAC,SACe,GAAGF,OAAO,CAAC,EAAEC,UAAU,CAAC,EAAEC,QAAQ,CAAC;AAEpD,sEAAsE,GACtE,OAAO,MAAMC,eAAe,CAC1BC,UACAF,SACe,GAAGE,SAAS,CAAC,EAAEF,QAAQ,CAAC;AAEzC;;;;CAIC,GACD,OAAO,MAAMG,sBAAsB,CACjCC,mBACAJ;IAEA,MAAMK,OAAOb,kBAAkBY;IAC/B,IAAIC,KAAKP,MAAM,KAAKQ,aAAaD,KAAKE,GAAG,KAAKD,WAAW;QACvD,MAAM,IAAIhB,kBACR,CAAC,OAAO,EAAEc,kBAAkBI,IAAI,CAAC,qDAAqD,CAAC;IAE3F;IACA,OAAOX,cAAcQ,KAAKP,MAAM,EAAEO,KAAKE,GAAG,EAAEP;AAC9C,E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J,KAAK,CAAC;IACxC,IACEK,gBAAgBJ,MAAM,KAAKzB,iBAC3B8B,iBAAiBL,MAAM,KAAKzB,eAC5B;QACA,OAAO;IACT;IACA,OAAO6B,gBAAgBE,KAAK,CAC1B,CAACC,SAASC,QACRD,YAAY/B,YAAY+B,YAAYF,gBAAgB,CAACG,MAAM;AAEjE,EAAE"}
1
+ {"version":3,"sources":["../../src/values/permission.ts"],"sourcesContent":["import {\n describeEntityUseCases,\n type Entity,\n ENTITY_ACTIONS,\n type EntityAction,\n type EntityConstructor,\n extractMetaEntity,\n extractMetaUseCaseBinding,\n type UseCaseConstructor,\n} from '@entifix/core';\n\n/**\n * What a caller wants to do with a resource.\n *\n * Defined in `@entifix/core` and aliased here, not duplicated: a UI\n * reads the same triple off a served `EntityMetadataDocument` to decide whether\n * to render Save and Delete, and a T3 package may not import this one, which\n * is T4. Aliasing keeps one definition and leaves every call site below\n * unchanged.\n */\nexport const Actions = ENTITY_ACTIONS;\nexport type Action = EntityAction;\n\n/**\n * A verb declared by `@useCase()` — `publish`, `revoke-sessions`, `approve`.\n *\n * Per-entity and open, rather than one global union every domain appends to:\n * that would make an unrelated domain's verb assignable everywhere and grow\n * without bound. The check that a verb exists is therefore at runtime, in\n * {@link permissionForUseCase}, and in whatever source scan a host's register\n * runs.\n */\nexport type UseCaseVerb = string;\n\n/**\n * The third segment of a permission: the CRUD triple, or a use-case verb.\n *\n * `Action` stays the narrow three-value union, and every place that guards CRUD\n * keeps using it. This wider alias exists only where a segment has already been\n * parsed off a string and could legitimately be either.\n */\nexport type PermissionAction = Action | UseCaseVerb;\n\n/**\n * A permission is three colon-separated segments — `<domain>:<entityKey>:<action>`\n * — so it can be derived from an entity's own `@entity({ domain, key })`\n * metadata rather than maintained as a parallel list. `*` in any segment of a\n * **granted** permission is a wildcard (see {@link permissionMatches}); a\n * **required** permission is always concrete.\n */\nexport type Permission = `${string}:${string}:${string}`;\n\n/** The `<domain>:<entityKey>` half of a permission — what is being acted on. */\nexport type Resource = `${string}:${string}`;\n\nconst SEGMENT_COUNT = 3;\nconst WILDCARD = '*';\n\n/** Build a permission from its parts. `*` is a legal action on a grant. */\nexport const permissionFor = (\n domain: string,\n entityKey: string,\n action: PermissionAction,\n): Permission => `${domain}:${entityKey}:${action}`;\n\n/** Join a resource and an action into the permission that guards it. */\nexport const permissionOf = (\n resource: Resource,\n action: PermissionAction,\n): Permission => `${resource}:${action}`;\n\n/**\n * Derive the permission guarding an entity from the entity itself. This is the\n * point of the `<domain>:<key>:<action>` shape: making a new entity guardable\n * needs no new vocabulary, only its existing `@entity()` metadata.\n */\nexport const permissionForEntity = <T extends Entity>(\n entityConstructor: EntityConstructor<T>,\n action: Action,\n): Permission => {\n const meta = extractMetaEntity(entityConstructor);\n if (meta.domain === undefined || meta.key === undefined) {\n throw new Error(\n `Entity ${entityConstructor.name} needs both a domain and a key to derive a permission`,\n );\n }\n return permissionFor(meta.domain, meta.key, action);\n};\n\n/**\n * Derive the permission guarding a use case.\n *\n * The **one-argument** form is what call sites use: a `@useCase()` class knows\n * both the entity it acts on and its own verb, so the verb string is written\n * once — in the decorator — and every guard imports the derived constant instead\n * of retyping it. The **two-argument** form is for a caller that holds only the\n * entity, which is the `$metadata` route walking an entity's descriptors.\n *\n * Both check that the entity really declares the verb, so a typo throws at\n * module load rather than silently denying every request. That check is at\n * runtime because compile-time narrowing does not survive the decorator\n * boundary: `Symbol.metadata` erases types and `extractMetaEntity` hands back an\n * untyped `MetaEntity`. Nothing is lost that existed — `parsePermission` looks\n * like it validates the action segment and does not.\n */\nexport function permissionForUseCase(useCase: UseCaseConstructor): Permission;\nexport function permissionForUseCase<T extends Entity>(\n entityConstructor: EntityConstructor<T>,\n key: UseCaseVerb,\n): Permission;\nexport function permissionForUseCase(\n target: UseCaseConstructor | EntityConstructor<Entity>,\n key?: UseCaseVerb,\n): Permission {\n const binding =\n key === undefined\n ? extractMetaUseCaseBinding(target as UseCaseConstructor)\n : { entity: target as EntityConstructor<Entity>, key };\n\n const meta = extractMetaEntity(binding.entity);\n if (meta.domain === undefined || meta.key === undefined) {\n throw new Error(\n `Entity ${binding.entity.name} needs both a domain and a key to derive a permission`,\n );\n }\n const declares = describeEntityUseCases(binding.entity).some(\n useCase => useCase.key === binding.key,\n );\n if (!declares) {\n throw new Error(\n `Entity ${binding.entity.name} does not declare the use case \"${binding.key}\"`,\n );\n }\n return permissionFor(meta.domain, meta.key, binding.key);\n}\n\n/**\n * Split a permission back into the resource + action a policy decision reads.\n * Throws on anything that is not exactly three segments, so a typo in a guard\n * fails at the call site instead of silently denying every request.\n */\nexport const parsePermission = (\n permission: Permission,\n): { resource: Resource; action: PermissionAction } => {\n const segments = permission.split(':');\n if (segments.length !== SEGMENT_COUNT) {\n throw new Error(\n `Malformed permission \"${permission}\" — expected <domain>:<entityKey>:<action>`,\n );\n }\n // The cast is only the arity the length check above already established. It\n // deliberately does not narrow the action segment: that used to say `Action`,\n // which read as a typo check it never performed, and is now false as well —\n // a use-case verb is a legal third segment.\n const [domain, entityKey, action] = segments as [\n string,\n string,\n PermissionAction,\n ];\n return { resource: `${domain}:${entityKey}`, action };\n};\n\n/**\n * Does a granted permission cover a required one? Compared segment by segment,\n * with `*` on the granted side matching anything. `super-admin`'s `*:*:*` thus\n * covers everything, and `product-configuration-management:*:read` covers every\n * entity in that domain without naming them.\n */\nexport const permissionMatches = (\n granted: Permission,\n required: Permission,\n): boolean => {\n const grantedSegments = granted.split(':');\n const requiredSegments = required.split(':');\n if (\n grantedSegments.length !== SEGMENT_COUNT ||\n requiredSegments.length !== SEGMENT_COUNT\n ) {\n return false;\n }\n return grantedSegments.every(\n (segment, index) =>\n segment === WILDCARD || segment === requiredSegments[index],\n );\n};\n"],"names":["describeEntityUseCases","ENTITY_ACTIONS","extractMetaEntity","extractMetaUseCaseBinding","Actions","SEGMENT_COUNT","WILDCARD","permissionFor","domain","entityKey","action","permissionOf","resource","permissionForEntity","entityConstructor","meta","undefined","key","Error","name","permissionForUseCase","target","binding","entity","declares","some","useCase","parsePermission","permission","segments","split","length","permissionMatches","granted","required","grantedSegments","requiredSegments","every","segment","index"],"mappings":"AAAA,SACEA,sBAAsB,EAEtBC,cAAc,EAGdC,iBAAiB,EACjBC,yBAAyB,QAEpB,gBAAgB;AAEvB;;;;;;;;CAQC,GACD,OAAO,MAAMC,UAAUH,eAAe;AAmCtC,MAAMI,gBAAgB;AACtB,MAAMC,WAAW;AAEjB,yEAAyE,GACzE,OAAO,MAAMC,gBAAgB,CAC3BC,QACAC,WACAC,SACe,GAAGF,OAAO,CAAC,EAAEC,UAAU,CAAC,EAAEC,QAAQ,CAAC;AAEpD,sEAAsE,GACtE,OAAO,MAAMC,eAAe,CAC1BC,UACAF,SACe,GAAGE,SAAS,CAAC,EAAEF,QAAQ,CAAC;AAEzC;;;;CAIC,GACD,OAAO,MAAMG,sBAAsB,CACjCC,mBACAJ;IAEA,MAAMK,OAAOb,kBAAkBY;IAC/B,IAAIC,KAAKP,MAAM,KAAKQ,aAAaD,KAAKE,GAAG,KAAKD,WAAW;QACvD,MAAM,IAAIE,MACR,CAAC,OAAO,EAAEJ,kBAAkBK,IAAI,CAAC,qDAAqD,CAAC;IAE3F;IACA,OAAOZ,cAAcQ,KAAKP,MAAM,EAAEO,KAAKE,GAAG,EAAEP;AAC9C,EAAE;AAuBF,OAAO,SAASU,qBACdC,MAAsD,EACtDJ,GAAiB;IAEjB,MAAMK,UACJL,QAAQD,YACJb,0BAA0BkB,UAC1B;QAAEE,QAAQF;QAAqCJ;IAAI;IAEzD,MAAMF,OAAOb,kBAAkBoB,QAAQC,MAAM;IAC7C,IAAIR,KAAKP,MAAM,KAAKQ,aAAaD,KAAKE,GAAG,KAAKD,WAAW;QACvD,MAAM,IAAIE,MACR,CAAC,OAAO,EAAEI,QAAQC,MAAM,CAACJ,IAAI,CAAC,qDAAqD,CAAC;IAExF;IACA,MAAMK,WAAWxB,uBAAuBsB,QAAQC,MAAM,EAAEE,IAAI,CAC1DC,CAAAA,UAAWA,QAA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AC;IAC5B,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;IAC/C,+EAA+E;IAC/E,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,KAAK,CAAC;IACvC;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAAC;IAC9C;;;;OAIG;IACH,aAAa,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,GAAG,OAAO,CAAC;CACtE;AAED,gDAAgD;AAChD,MAAM,MAAM,MAAM,CAAC,OAAO,IACxB,OAAO,SAAS,UAAU,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC;AAE1D,MAAM,WAAW,iBAAiB,CAAC,KAAK,SAAS,MAAM;IACrD,mCAAmC;IACnC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;CAC9B;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,GAC3B,KAAK,CAAC,MAAM,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAEnD,OAAO,MAAM,EACb,UAAS,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAM,KAC9C,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CA2C3B,CAAC"}
@@ -1,5 +1,18 @@
1
- import { EntifixLogicError } from '@entifix/core';
2
1
  /**
2
+ * A host's role ladder: its roles in rank order, and the assignment rule bound
3
+ * to them ([ADR 0007](../../../../../docs/adr/0007-the-host-supplies-the-role-ladder.md)).
4
+ *
5
+ * The rungs are the host's — which roles exist is one product's hierarchy, and
6
+ * a framework that declared them would have decided it for every adopter. The
7
+ * rule over them is the framework's: a principal may assign a role at or below
8
+ * its own highest rank, and a principal carrying no recognised role can assign
9
+ * nothing. That rule is why a ladder exists at all; a host that wants another
10
+ * one wants a policy, which `GrantTable` and `can` already are.
11
+ *
12
+ * The ladder is the one attribute that rides in the access token, and an
13
+ * ordered tier is what makes the escalation rule expressible without a policy
14
+ * language.
15
+ */ /**
3
16
  * Define a ladder, once, in whichever package a host keeps its grant table:
4
17
  *
5
18
  * ```ts
@@ -14,25 +27,17 @@ import { EntifixLogicError } from '@entifix/core';
14
27
  */ export const defineRoleLadder = (roles, options = {})=>{
15
28
  var _options_defaultRole;
16
29
  if (roles.length === 0) {
17
- throw new EntifixLogicError('A role ladder needs at least one rung.', undefined, {
18
- roles
19
- });
30
+ throw new Error('A role ladder needs at least one rung.');
20
31
  }
21
32
  const repeated = roles.filter((role, index)=>roles.indexOf(role) !== index);
22
33
  if (repeated.length > 0) {
23
- throw new EntifixLogicError(`A role ladder names each rung once; repeated: ${[
34
+ throw new Error(`A role ladder names each rung once; repeated: ${[
24
35
  ...new Set(repeated)
25
- ].join(', ')}.`, undefined, {
26
- roles,
27
- repeated
28
- });
36
+ ].join(', ')}.`);
29
37
  }
30
38
  const defaultRole = (_options_defaultRole = options.defaultRole) != null ? _options_defaultRole : roles[0];
31
39
  if (!roles.includes(defaultRole)) {
32
- throw new EntifixLogicError(`The default role "${defaultRole}" is not a rung of the ladder.`, undefined, {
33
- roles,
34
- defaultRole
35
- });
40
+ throw new Error(`The default role "${defaultRole}" is not a rung of the ladder.`);
36
41
  }
37
42
  const rank = Object.fromEntries(roles.map((role, index)=>[
38
43
  role,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/values/role.ts"],"sourcesContent":["import { EntifixLogicError } from '@entifix/core';\n\n/**\n * A host's role ladder: its roles in rank order, and the assignment rule bound\n * to them ([ADR 0007](../../../../../docs/adr/0007-the-host-supplies-the-role-ladder.md)).\n *\n * The rungs are the host's — which roles exist is one product's hierarchy, and\n * a framework that declared them would have decided it for every adopter. The\n * rule over them is the framework's: a principal may assign a role at or below\n * its own highest rank, and a principal carrying no recognised role can assign\n * nothing. That rule is why a ladder exists at all; a host that wants another\n * one wants a policy, which `GrantTable` and `can` already are.\n *\n * The ladder is the one attribute that rides in the access token, and an\n * ordered tier is what makes the escalation rule expressible without a policy\n * language.\n */\nexport interface RoleLadder<TRole extends string> {\n /** Every role, from the lowest rung to the highest. Order is rank. */\n readonly roles: readonly TRole[];\n /** What a self-registered account starts as; never assignable by the caller. */\n readonly defaultRole: TRole;\n /** Seniority. Higher wins; used only for the assignment rule, never for grants. */\n readonly rank: Readonly<Record<TRole, number>>;\n /** Narrow an unknown value — a request body, a stored document — to a role. */\n isRole(value: unknown): value is TRole;\n /**\n * The highest rank among the roles a principal carries, or `-1` when it\n * carries none, or only unrecognised ones — which can never satisfy an\n * assignment.\n */\n highestRank(roles: readonly string[]): number;\n /**\n * May an actor create or promote someone to `target`? At or below the\n * actor's own rank, so the second rung mints its own rung and the first but\n * never the third, and a caller with no roles mints nothing.\n */\n canAssignRole(actorRoles: readonly string[], target: TRole): boolean;\n}\n\n/** The role union a ladder was defined over. */\nexport type RoleOf<TLadder> =\n TLadder extends RoleLadder<infer TRole> ? TRole : never;\n\nexport interface RoleLadderOptions<TRole extends string> {\n /** Defaults to the lowest rung. */\n readonly defaultRole?: TRole;\n}\n\n/**\n * Define a ladder, once, in whichever package a host keeps its grant table:\n *\n * ```ts\n * export const ladder = defineRoleLadder(['user', 'admin', 'owner'] as const);\n * export type Role = RoleOf<typeof ladder>;\n * ```\n *\n * ⚠️ **An empty ladder and a repeated rung throw here**, at definition rather\n * than at the first assignment: both make rank meaningless, and both would\n * otherwise fail in silence — an empty ladder refusing every assignment, a\n * repeated rung ranking itself by whichever copy was read last.\n */\nexport const defineRoleLadder = <\n const TRoles extends readonly [string, ...string[]],\n>(\n roles: TRoles,\n options: RoleLadderOptions<TRoles[number]> = {},\n): RoleLadder<TRoles[number]> => {\n type TRole = TRoles[number];\n\n if ((roles as readonly string[]).length === 0) {\n throw new EntifixLogicError(\n 'A role ladder needs at least one rung.',\n undefined,\n { roles },\n );\n }\n const repeated = roles.filter((role, index) => roles.indexOf(role) !== index);\n if (repeated.length > 0) {\n throw new EntifixLogicError(\n `A role ladder names each rung once; repeated: ${[...new Set(repeated)].join(', ')}.`,\n undefined,\n { roles, repeated },\n );\n }\n\n const defaultRole = options.defaultRole ?? (roles[0] as TRole);\n if (!(roles as readonly string[]).includes(defaultRole)) {\n throw new EntifixLogicError(\n `The default role \"${defaultRole}\" is not a rung of the ladder.`,\n undefined,\n { roles, defaultRole },\n );\n }\n\n const rank = Object.fromEntries(\n roles.map((role, index) => [role, index]),\n ) as Record<TRole, number>;\n\n const isRole = (value: unknown): value is TRole =>\n typeof value === 'string' && Object.hasOwn(rank, value);\n\n const highestRank = (carried: readonly string[]): number =>\n carried.reduce(\n (highest, role) =>\n isRole(role) ? Math.max(highest, rank[role]) : highest,\n -1,\n );\n\n return {\n roles,\n defaultRole,\n rank,\n isRole,\n highestRank,\n canAssignRole: (actorRoles, target) =>\n highestRank(actorRoles) >= rank[target],\n };\n};\n"],"names":["EntifixLogicError","defineRoleLadder","roles","options","length","undefined","repeated","filter","role","index","indexOf","Set","join","defaultRole","includes","rank","Object","fromEntries","map","isRole","value","hasOwn","highestRank","carried","reduce","highest","Math","max","canAssignRole","actorRoles","target"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,gBAAgB;AAiDlD;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,mBAAmB,CAG9BC,OACAC,UAA6C,CAAC,CAAC;QAoB3BA;IAhBpB,IAAI,AAACD,MAA4BE,MAAM,KAAK,GAAG;QAC7C,MAAM,IAAIJ,kBACR,0CACAK,WACA;YAAEH;QAAM;IAEZ;IACA,MAAMI,WAAWJ,MAAMK,MAAM,CAAC,CAACC,MAAMC,QAAUP,MAAMQ,OAAO,CAACF,UAAUC;IACvE,IAAIH,SAASF,MAAM,GAAG,GAAG;QACvB,MAAM,IAAIJ,kBACR,CAAC,8CAA8C,EAAE;eAAI,IAAIW,IAAIL;SAAU,CAACM,IAAI,CAAC,MAAM,CAAC,CAAC,EACrFP,WACA;YAAEH;YAAOI;QAAS;IAEtB;IAEA,MAAMO,eAAcV,uBAAAA,QAAQU,WAAW,YAAnBV,uBAAwBD,KAAK,CAAC,EAAE;IACpD,IAAI,CAAC,AAACA,MAA4BY,QAAQ,CAACD,cAAc;QACvD,MAAM,IAAIb,kBACR,CAAC,kBAAkB,EAAEa,YAAY,8BAA8B,CAAC,EAChER,WACA;YAAEH;YAAOW;QAAY;IAEzB;IAEA,MAAME,OAAOC,OAAOC,WAAW,CAC7Bf,MAAMgB,GAAG,CAAC,CAACV,MAAMC,QAAU;YAACD;YAAMC;SAAM;IAG1C,MAAMU,SAAS,CAACC,QACd,OAAOA,UAAU,YAAYJ,OAAOK,MAAM,CAACN,MAAMK;IAEnD,MAAME,cAAc,CAACC,UACnBA,QAAQC,MAAM,CACZ,CAACC,SAASjB,OACRW,OAAOX,QAAQkB,KAAKC,GAAG,CAACF,SAASV,IAAI,CAACP,KAAK,IAAIiB,SACjD,CAAC;IAGL,OAAO;QACLvB;QACAW;QACAE;QACAI;QACAG;QACAM,eAAe,CAACC,YAAYC,SAC1BR,YAAYO,eAAed,IAAI,CAACe,OAAO;IAC3C;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/values/role.ts"],"sourcesContent":["/**\n * A host's role ladder: its roles in rank order, and the assignment rule bound\n * to them ([ADR 0007](../../../../../docs/adr/0007-the-host-supplies-the-role-ladder.md)).\n *\n * The rungs are the host's — which roles exist is one product's hierarchy, and\n * a framework that declared them would have decided it for every adopter. The\n * rule over them is the framework's: a principal may assign a role at or below\n * its own highest rank, and a principal carrying no recognised role can assign\n * nothing. That rule is why a ladder exists at all; a host that wants another\n * one wants a policy, which `GrantTable` and `can` already are.\n *\n * The ladder is the one attribute that rides in the access token, and an\n * ordered tier is what makes the escalation rule expressible without a policy\n * language.\n */\nexport interface RoleLadder<TRole extends string> {\n /** Every role, from the lowest rung to the highest. Order is rank. */\n readonly roles: readonly TRole[];\n /** What a self-registered account starts as; never assignable by the caller. */\n readonly defaultRole: TRole;\n /** Seniority. Higher wins; used only for the assignment rule, never for grants. */\n readonly rank: Readonly<Record<TRole, number>>;\n /** Narrow an unknown value — a request body, a stored document — to a role. */\n isRole(value: unknown): value is TRole;\n /**\n * The highest rank among the roles a principal carries, or `-1` when it\n * carries none, or only unrecognised ones — which can never satisfy an\n * assignment.\n */\n highestRank(roles: readonly string[]): number;\n /**\n * May an actor create or promote someone to `target`? At or below the\n * actor's own rank, so the second rung mints its own rung and the first but\n * never the third, and a caller with no roles mints nothing.\n */\n canAssignRole(actorRoles: readonly string[], target: TRole): boolean;\n}\n\n/** The role union a ladder was defined over. */\nexport type RoleOf<TLadder> =\n TLadder extends RoleLadder<infer TRole> ? TRole : never;\n\nexport interface RoleLadderOptions<TRole extends string> {\n /** Defaults to the lowest rung. */\n readonly defaultRole?: TRole;\n}\n\n/**\n * Define a ladder, once, in whichever package a host keeps its grant table:\n *\n * ```ts\n * export const ladder = defineRoleLadder(['user', 'admin', 'owner'] as const);\n * export type Role = RoleOf<typeof ladder>;\n * ```\n *\n * ⚠️ **An empty ladder and a repeated rung throw here**, at definition rather\n * than at the first assignment: both make rank meaningless, and both would\n * otherwise fail in silence — an empty ladder refusing every assignment, a\n * repeated rung ranking itself by whichever copy was read last.\n */\nexport const defineRoleLadder = <\n const TRoles extends readonly [string, ...string[]],\n>(\n roles: TRoles,\n options: RoleLadderOptions<TRoles[number]> = {},\n): RoleLadder<TRoles[number]> => {\n type TRole = TRoles[number];\n\n if ((roles as readonly string[]).length === 0) {\n throw new Error('A role ladder needs at least one rung.');\n }\n const repeated = roles.filter((role, index) => roles.indexOf(role) !== index);\n if (repeated.length > 0) {\n throw new Error(\n `A role ladder names each rung once; repeated: ${[...new Set(repeated)].join(', ')}.`,\n );\n }\n\n const defaultRole = options.defaultRole ?? (roles[0] as TRole);\n if (!(roles as readonly string[]).includes(defaultRole)) {\n throw new Error(\n `The default role \"${defaultRole}\" is not a rung of the ladder.`,\n );\n }\n\n const rank = Object.fromEntries(\n roles.map((role, index) => [role, index]),\n ) as Record<TRole, number>;\n\n const isRole = (value: unknown): value is TRole =>\n typeof value === 'string' && Object.hasOwn(rank, value);\n\n const highestRank = (carried: readonly string[]): number =>\n carried.reduce(\n (highest, role) =>\n isRole(role) ? Math.max(highest, rank[role]) : highest,\n -1,\n );\n\n return {\n roles,\n defaultRole,\n rank,\n isRole,\n highestRank,\n canAssignRole: (actorRoles, target) =>\n highestRank(actorRoles) >= rank[target],\n };\n};\n"],"names":["defineRoleLadder","roles","options","length","Error","repeated","filter","role","index","indexOf","Set","join","defaultRole","includes","rank","Object","fromEntries","map","isRole","value","hasOwn","highestRank","carried","reduce","highest","Math","max","canAssignRole","actorRoles","target"],"mappings":"AAAA;;;;;;;;;;;;;;CAcC,GAiCD;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMA,mBAAmB,CAG9BC,OACAC,UAA6C,CAAC,CAAC;QAc3BA;IAVpB,IAAI,AAACD,MAA4BE,MAAM,KAAK,GAAG;QAC7C,MAAM,IAAIC,MAAM;IAClB;IACA,MAAMC,WAAWJ,MAAMK,MAAM,CAAC,CAACC,MAAMC,QAAUP,MAAMQ,OAAO,CAACF,UAAUC;IACvE,IAAIH,SAASF,MAAM,GAAG,GAAG;QACvB,MAAM,IAAIC,MACR,CAAC,8CAA8C,EAAE;eAAI,IAAIM,IAAIL;SAAU,CAACM,IAAI,CAAC,MAAM,CAAC,CAAC;IAEzF;IAEA,MAAMC,eAAcV,uBAAAA,QAAQU,WAAW,YAAnBV,uBAAwBD,KAAK,CAAC,EAAE;IACpD,IAAI,CAAC,AAACA,MAA4BY,QAAQ,CAACD,cAAc;QACvD,MAAM,IAAIR,MACR,CAAC,kBAAkB,EAAEQ,YAAY,8BAA8B,CAAC;IAEpE;IAEA,MAAME,OAAOC,OAAOC,WAAW,CAC7Bf,MAAMgB,GAAG,CAAC,CAACV,MAAMC,QAAU;YAACD;YAAMC;SAAM;IAG1C,MAAMU,SAAS,CAACC,QACd,OAAOA,UAAU,YAAYJ,OAAOK,MAAM,CAACN,MAAMK;IAEnD,MAAME,cAAc,CAACC,UACnBA,QAAQC,MAAM,CACZ,CAACC,SAASjB,OACRW,OAAOX,QAAQkB,KAAKC,GAAG,CAACF,SAASV,IAAI,CAACP,KAAK,IAAIiB,SACjD,CAAC;IAGL,OAAO;QACLvB;QACAW;QACAE;QACAI;QACAG;QACAM,eAAe,CAACC,YAAYC,SAC1BR,YAAYO,eAAed,IAAI,CAACe,OAAO;IAC3C;AACF,EAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@entifix/authz",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Authorization vocabulary: permissions derived from entities, roles, a grant table, and a PolicyDecision port.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -51,12 +51,12 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@swc/helpers": "0.5.23",
54
- "@entifix/core": "0.8.0"
54
+ "@entifix/core": "0.10.0"
55
55
  },
56
56
  "peerDependencies": {
57
- "effect": "^4.0.5"
57
+ "effect": "^4.0.6"
58
58
  },
59
59
  "devDependencies": {
60
- "effect": "4.0.5"
60
+ "effect": "4.0.6"
61
61
  }
62
62
  }