@venizia/ignis-kernel 0.4.8-0 → 0.4.8-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +5 -4
  2. package/dist/esm/base/applications/abstract.d.ts +1 -0
  3. package/dist/esm/base/applications/abstract.js +1 -0
  4. package/dist/esm/base/applications/abstract.js.map +1 -1
  5. package/dist/esm/base/applications/boot-sequence.d.ts +2 -0
  6. package/dist/esm/base/applications/boot-sequence.js.map +1 -1
  7. package/dist/esm/base/applications/common/constants.d.ts +2 -0
  8. package/dist/esm/base/applications/common/constants.js +1 -0
  9. package/dist/esm/base/applications/common/constants.js.map +1 -1
  10. package/dist/esm/base/applications/common/types/application.d.ts +30 -8
  11. package/dist/esm/base/applications/common/types/application.js.map +1 -1
  12. package/dist/esm/base/applications/common/types/middlewares.d.ts +16 -1
  13. package/dist/esm/base/applications/common/types/middlewares.js.map +1 -1
  14. package/dist/esm/base/auth/authenticate/common/codecs.d.ts +1 -0
  15. package/dist/esm/base/auth/authenticate/common/codecs.js +1 -0
  16. package/dist/esm/base/auth/authenticate/common/codecs.js.map +1 -1
  17. package/dist/esm/base/auth/authenticate/common/constants/authentication.d.ts +6 -0
  18. package/dist/esm/base/auth/authenticate/common/constants/authentication.js +4 -0
  19. package/dist/esm/base/auth/authenticate/common/constants/authentication.js.map +1 -1
  20. package/dist/esm/base/auth/authenticate/common/constants/jose.d.ts +8 -0
  21. package/dist/esm/base/auth/authenticate/common/constants/jose.js +4 -0
  22. package/dist/esm/base/auth/authenticate/common/constants/jose.js.map +1 -1
  23. package/dist/esm/base/auth/authenticate/common/keys.d.ts +1 -0
  24. package/dist/esm/base/auth/authenticate/common/keys.js +1 -0
  25. package/dist/esm/base/auth/authenticate/common/keys.js.map +1 -1
  26. package/dist/esm/base/auth/authenticate/common/types/basic.d.ts +1 -0
  27. package/dist/esm/base/auth/authenticate/common/types/basic.js.map +1 -1
  28. package/dist/esm/base/auth/authenticate/common/types/jwt.d.ts +42 -0
  29. package/dist/esm/base/auth/authenticate/common/types/jwt.js.map +1 -1
  30. package/dist/esm/base/auth/authenticate/common/types/rest.d.ts +2 -0
  31. package/dist/esm/base/auth/authenticate/common/types/rest.js.map +1 -1
  32. package/dist/esm/base/auth/authenticate/common/types/service.d.ts +10 -1
  33. package/dist/esm/base/auth/authenticate/common/types/service.js.map +1 -1
  34. package/dist/esm/base/auth/authenticate/common/types/strategy.d.ts +5 -0
  35. package/dist/esm/base/auth/authenticate/common/types/strategy.js.map +1 -1
  36. package/dist/esm/base/auth/authenticate/middlewares/authenticate.middleware.d.ts +1 -0
  37. package/dist/esm/base/auth/authenticate/middlewares/authenticate.middleware.js +1 -0
  38. package/dist/esm/base/auth/authenticate/middlewares/authenticate.middleware.js.map +1 -1
  39. package/dist/esm/base/auth/authenticate/providers/authentication.provider.d.ts +5 -0
  40. package/dist/esm/base/auth/authenticate/providers/authentication.provider.js +5 -0
  41. package/dist/esm/base/auth/authenticate/providers/authentication.provider.js.map +1 -1
  42. package/dist/esm/base/auth/authenticate/strategies/strategy-registry.d.ts +1 -0
  43. package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js +1 -0
  44. package/dist/esm/base/auth/authenticate/strategies/strategy-registry.js.map +1 -1
  45. package/dist/esm/base/auth/authorize/builders/grant.builder.d.ts +1 -0
  46. package/dist/esm/base/auth/authorize/builders/grant.builder.js +1 -0
  47. package/dist/esm/base/auth/authorize/builders/grant.builder.js.map +1 -1
  48. package/dist/esm/base/auth/authorize/builders/policy.builder.d.ts +1 -0
  49. package/dist/esm/base/auth/authorize/builders/policy.builder.js +1 -0
  50. package/dist/esm/base/auth/authorize/builders/policy.builder.js.map +1 -1
  51. package/dist/esm/base/auth/authorize/common/constants/authorization.d.ts +8 -0
  52. package/dist/esm/base/auth/authorize/common/constants/authorization.js +5 -0
  53. package/dist/esm/base/auth/authorize/common/constants/authorization.js.map +1 -1
  54. package/dist/esm/base/auth/authorize/common/constants/binding-keys.d.ts +1 -0
  55. package/dist/esm/base/auth/authorize/common/constants/binding-keys.js +1 -0
  56. package/dist/esm/base/auth/authorize/common/constants/binding-keys.js.map +1 -1
  57. package/dist/esm/base/auth/authorize/common/constants/enforcer.d.ts +9 -0
  58. package/dist/esm/base/auth/authorize/common/constants/enforcer.js +4 -0
  59. package/dist/esm/base/auth/authorize/common/constants/enforcer.js.map +1 -1
  60. package/dist/esm/base/auth/authorize/common/types/enforcer.d.ts +21 -3
  61. package/dist/esm/base/auth/authorize/common/types/enforcer.js.map +1 -1
  62. package/dist/esm/base/auth/authorize/common/types/grant.d.ts +1 -0
  63. package/dist/esm/base/auth/authorize/common/types/grant.js.map +1 -1
  64. package/dist/esm/base/auth/authorize/common/types/request.d.ts +3 -0
  65. package/dist/esm/base/auth/authorize/common/types/request.js.map +1 -1
  66. package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.d.ts +1 -0
  67. package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js +1 -0
  68. package/dist/esm/base/auth/authorize/enforcers/enforcer-registry.js.map +1 -1
  69. package/dist/esm/base/auth/authorize/middlewares/authorize.middleware.d.ts +1 -0
  70. package/dist/esm/base/auth/authorize/middlewares/authorize.middleware.js +1 -0
  71. package/dist/esm/base/auth/authorize/middlewares/authorize.middleware.js.map +1 -1
  72. package/dist/esm/base/auth/authorize/models/authorization-role.model.d.ts +6 -0
  73. package/dist/esm/base/auth/authorize/models/authorization-role.model.js +1 -0
  74. package/dist/esm/base/auth/authorize/models/authorization-role.model.js.map +1 -1
  75. package/dist/esm/base/auth/authorize/providers/authorization.provider.d.ts +1 -0
  76. package/dist/esm/base/auth/authorize/providers/authorization.provider.js +1 -0
  77. package/dist/esm/base/auth/authorize/providers/authorization.provider.js.map +1 -1
  78. package/dist/esm/base/auth/base/abstract-auth-registry.d.ts +2 -0
  79. package/dist/esm/base/auth/base/abstract-auth-registry.js +1 -0
  80. package/dist/esm/base/auth/base/abstract-auth-registry.js.map +1 -1
  81. package/dist/esm/base/auth/models/requests/change-password.schema.d.ts +2 -0
  82. package/dist/esm/base/auth/models/requests/change-password.schema.js +1 -0
  83. package/dist/esm/base/auth/models/requests/change-password.schema.js.map +1 -1
  84. package/dist/esm/base/auth/models/requests/sign-in.schema.d.ts +2 -0
  85. package/dist/esm/base/auth/models/requests/sign-in.schema.js +1 -0
  86. package/dist/esm/base/auth/models/requests/sign-in.schema.js.map +1 -1
  87. package/dist/esm/base/auth/models/requests/sign-up.schema.d.ts +2 -0
  88. package/dist/esm/base/auth/models/requests/sign-up.schema.js +1 -0
  89. package/dist/esm/base/auth/models/requests/sign-up.schema.js.map +1 -1
  90. package/dist/esm/base/components/base.d.ts +1 -0
  91. package/dist/esm/base/components/base.js +1 -0
  92. package/dist/esm/base/components/base.js.map +1 -1
  93. package/dist/esm/base/components/controller/rest/common/types.d.ts +2 -0
  94. package/dist/esm/base/components/controller/rest/common/types.js +1 -0
  95. package/dist/esm/base/components/controller/rest/common/types.js.map +1 -1
  96. package/dist/esm/base/configurations/base.d.ts +1 -0
  97. package/dist/esm/base/configurations/base.js +1 -0
  98. package/dist/esm/base/configurations/base.js.map +1 -1
  99. package/dist/esm/base/configurations/common/types.d.ts +1 -0
  100. package/dist/esm/base/configurations/common/types.js.map +1 -1
  101. package/dist/esm/base/controllers/common/constants.d.ts +4 -0
  102. package/dist/esm/base/controllers/common/constants.js +2 -0
  103. package/dist/esm/base/controllers/common/constants.js.map +1 -1
  104. package/dist/esm/base/controllers/common/schema-builders.d.ts +3 -0
  105. package/dist/esm/base/controllers/common/schema-builders.js +1 -0
  106. package/dist/esm/base/controllers/common/schema-builders.js.map +1 -1
  107. package/dist/esm/base/controllers/common/schemas.d.ts +2 -0
  108. package/dist/esm/base/controllers/common/schemas.js +2 -0
  109. package/dist/esm/base/controllers/common/schemas.js.map +1 -1
  110. package/dist/esm/base/controllers/common/types/context.d.ts +2 -0
  111. package/dist/esm/base/controllers/common/types/context.js.map +1 -1
  112. package/dist/esm/base/controllers/common/types/controller.d.ts +5 -1
  113. package/dist/esm/base/controllers/common/types/controller.js.map +1 -1
  114. package/dist/esm/base/controllers/common/types/route.d.ts +7 -1
  115. package/dist/esm/base/controllers/common/types/route.js.map +1 -1
  116. package/dist/esm/base/datasources/common/types.d.ts +5 -0
  117. package/dist/esm/base/datasources/common/types.js +1 -0
  118. package/dist/esm/base/datasources/common/types.js.map +1 -1
  119. package/dist/esm/base/events/common/constants.d.ts +4 -0
  120. package/dist/esm/base/events/common/constants.js +3 -0
  121. package/dist/esm/base/events/common/constants.js.map +1 -1
  122. package/dist/esm/base/events/common/types.d.ts +10 -2
  123. package/dist/esm/base/events/common/types.js.map +1 -1
  124. package/dist/esm/base/metadata/injectable.d.ts +46 -0
  125. package/dist/esm/base/metadata/injectable.js +46 -0
  126. package/dist/esm/base/metadata/injectable.js.map +1 -1
  127. package/dist/esm/base/metadata/persistents.d.ts +47 -2
  128. package/dist/esm/base/metadata/persistents.js +47 -2
  129. package/dist/esm/base/metadata/persistents.js.map +1 -1
  130. package/dist/esm/base/metadata/routes/controller.d.ts +17 -0
  131. package/dist/esm/base/metadata/routes/controller.js +17 -0
  132. package/dist/esm/base/metadata/routes/controller.js.map +1 -1
  133. package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.d.ts +1 -0
  134. package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js +1 -0
  135. package/dist/esm/base/middlewares/emoji-favicon/emoji-favicon.middleware.js.map +1 -1
  136. package/dist/esm/base/middlewares/not-found/not-found.middleware.d.ts +1 -0
  137. package/dist/esm/base/middlewares/not-found/not-found.middleware.js +1 -0
  138. package/dist/esm/base/middlewares/not-found/not-found.middleware.js.map +1 -1
  139. package/dist/esm/base/mixins/common/types.d.ts +14 -1
  140. package/dist/esm/base/mixins/common/types.js.map +1 -1
  141. package/dist/esm/base/models/common/constants.d.ts +2 -0
  142. package/dist/esm/base/models/common/constants.js +1 -0
  143. package/dist/esm/base/models/common/constants.js.map +1 -1
  144. package/dist/esm/base/models/common/schemas.d.ts +1 -0
  145. package/dist/esm/base/models/common/schemas.js.map +1 -1
  146. package/dist/esm/base/models/common/types/id.d.ts +4 -0
  147. package/dist/esm/base/models/common/types/id.js.map +1 -1
  148. package/dist/esm/base/providers/base.d.ts +1 -0
  149. package/dist/esm/base/providers/base.js +1 -0
  150. package/dist/esm/base/providers/base.js.map +1 -1
  151. package/dist/esm/base/repositories/common/constants.d.ts +2 -2
  152. package/dist/esm/base/repositories/common/constants.js +2 -2
  153. package/dist/esm/base/repositories/common/constants.js.map +1 -1
  154. package/dist/esm/base/repositories/common/scope-through.d.ts +18 -1
  155. package/dist/esm/base/repositories/common/scope-through.js +18 -1
  156. package/dist/esm/base/repositories/common/scope-through.js.map +1 -1
  157. package/dist/esm/base/repositories/common/types/options.d.ts +10 -4
  158. package/dist/esm/base/repositories/common/types/options.js.map +1 -1
  159. package/dist/esm/base/repositories/query-schemas/index.d.ts +18 -3
  160. package/dist/esm/base/repositories/query-schemas/index.js +17 -1
  161. package/dist/esm/base/repositories/query-schemas/index.js.map +1 -1
  162. package/dist/esm/base/request-context/registry.d.ts +1 -0
  163. package/dist/esm/base/request-context/registry.js +1 -0
  164. package/dist/esm/base/request-context/registry.js.map +1 -1
  165. package/dist/esm/base/services/base.d.ts +1 -0
  166. package/dist/esm/base/services/base.js +1 -0
  167. package/dist/esm/base/services/base.js.map +1 -1
  168. package/dist/esm/base/services/common/types.d.ts +1 -0
  169. package/dist/esm/base/services/common/types.js.map +1 -1
  170. package/dist/esm/common/bindings.d.ts +1 -0
  171. package/dist/esm/common/bindings.js.map +1 -1
  172. package/dist/esm/common/error-codes.d.ts +2 -0
  173. package/dist/esm/common/error-codes.js.map +1 -1
  174. package/dist/esm/helpers/inversion/common/keys.d.ts +1 -0
  175. package/dist/esm/helpers/inversion/common/keys.js +1 -0
  176. package/dist/esm/helpers/inversion/common/keys.js.map +1 -1
  177. package/dist/esm/helpers/inversion/common/relation-builder.d.ts +1 -0
  178. package/dist/esm/helpers/inversion/common/relation-builder.js +1 -0
  179. package/dist/esm/helpers/inversion/common/relation-builder.js.map +1 -1
  180. package/dist/esm/helpers/inversion/common/types/artifact.d.ts +9 -2
  181. package/dist/esm/helpers/inversion/common/types/artifact.js.map +1 -1
  182. package/dist/esm/helpers/inversion/common/types/controller.d.ts +4 -0
  183. package/dist/esm/helpers/inversion/common/types/controller.js.map +1 -1
  184. package/dist/esm/helpers/inversion/common/types/model.d.ts +80 -8
  185. package/dist/esm/helpers/inversion/common/types/model.js.map +1 -1
  186. package/dist/esm/helpers/inversion/common/types/persistence.d.ts +9 -1
  187. package/dist/esm/helpers/inversion/common/types/persistence.js.map +1 -1
  188. package/dist/esm/helpers/inversion/container.d.ts +1 -0
  189. package/dist/esm/helpers/inversion/container.js +1 -0
  190. package/dist/esm/helpers/inversion/container.js.map +1 -1
  191. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"policy.builder.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/builders/policy.builder.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAuC7B,MAAM,OAAO,0BAA0B;aACrB,qBAAgB,GAAG,QAAQ,CAAC;IAE5C,sJAAsJ;IAC9I,MAAM,CAAC,WAAW,CAAC,MAAsC;QAI/D,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM,KAAK,yBAAyB,CAAC,UAAU,EAAE,CAAC;YACtE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAC9C,CAAC;QAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;QAChD,CAAC;QAED,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM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CAAC,EAAE,EAAE;gBACnD,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE;gBAC5D,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAC;YAEH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import type { IdType } from '@/base';\nimport type { TNullable } from '@venizia/ignis-helpers/common';\nimport type { TAuthorizationAction, TAuthorizationDecision } from '../common/constants';\nimport {\n AuthorizationActions,\n AuthorizationDomainScopes,\n AuthorizationPolicyVariants,\n} from '../common/constants';\n\n/** A grant/assignment domain: a scope literal (`SYSTEM_WIDE`/`ANY_MEMBER`) or a typed domain entity. */\nexport type TPolicyDomainInput = string | { type: string; id: IdType };\n\n/**\n * Explicit on purpose: `TAuthorizationDecision` is `Extract<ValueOf<T>, string | number>`, and its\n * literal members widen to `string` when a method's return type is inferred rather than declared.\n * Without this annotation `grant()`'s `effect` stops satisfying `PolicyDefinition`'s narrowed column.\n * Not exported - `TGrantRow`/`TCustomGrantRow` already name unrelated adapter-side row shapes\n * downstream; consumers derive this shape via `ReturnType<typeof AuthorizationPolicyBuilder.grant>`.\n */\ntype TBuilderGrantRow = {\n variant: typeof AuthorizationPolicyVariants.GRANT.action;\n subjectType: string;\n subjectId: IdType;\n targetType: string;\n targetId: IdType;\n action: string;\n effect: TAuthorizationDecision;\n domainType: TNullable<string>;\n domainId: TNullable<IdType>;\n};\n\n/**\n * What IGNIS itself stores in `PolicyDefinition.metadata`: the operations of a subset grant, read\n * back by `ScopedCasbinAdapter` through `parseCustomGrantMetadata`. An application whose own\n * metadata has a different shape points the adapter at a different column\n * (`entities.policyDefinition.metadata.columnName`) rather than widening this one.\n *\n * Declared here, beside the only writer, so the column type and the row type cannot drift.\n */\nexport type TSubsetGrantMetadata = { ops: string[] };\n\ntype TBuilderCustomGrantRow = Omit<TBuilderGrantRow, 'action'> & {\n action: typeof AuthorizationActions.CUSTOM;\n metadata: TSubsetGrantMetadata;\n};\n\nexport class AuthorizationPolicyBuilder {\n static readonly ACTION_PRINCIPAL = 'Action';\n\n /** A domain as the two columns that store it. `ANY_MEMBER` normalises to null - admitting both spellings would leave one state reachable two ways. */\n private static splitDomain(domain?: TNullable<TPolicyDomainInput>): {\n domainType: TNullable<string>;\n domainId: TNullable<IdType>;\n } {\n if (domain == null || domain === AuthorizationDomainScopes.ANY_MEMBER) {\n return { domainType: null, domainId: null };\n }\n\n if (typeof domain === 'string') {\n return { domainType: domain, domainId: null };\n }\n\n return { domainType: domain.type, domainId: domain.id };\n }\n\n /** A grant (casbin `p`): role/user -> permission, carrying action + effect + domain. A null `domain` means `ANY_MEMBER` (adapter default); pass a scope literal or a typed `{ type, id }` domain. */\n static grant(opts: {\n subject: { type: string; id: IdType };\n permission: { type: string; id: IdType };\n action: string;\n domain?: TNullable<TPolicyDomainInput>;\n effect: TAuthorizationDecision;\n }): TBuilderGrantRow {\n return {\n variant: AuthorizationPolicyVariants.GRANT.action,\n subjectType: opts.subject.type,\n subjectId: opts.subject.id,\n targetType: opts.permission.type,\n targetId: opts.permission.id,\n action: opts.action,\n effect: opts.effect,\n ...AuthorizationPolicyBuilder.splitDomain(opts.domain),\n };\n }\n\n /** A subset grant (casbin `p` x N): role/user -> resource node with the granted operations in metadata. `action` is fixed to the CUSTOM sentinel; the adapter expands `ops` at read time. */\n static customGrant(opts: {\n subject: { type: string; id: IdType };\n permission: { type: string; id: IdType };\n ops: string[];\n domain?: TNullable<TPolicyDomainInput>;\n effect: TAuthorizationDecision;\n }): TBuilderCustomGrantRow {\n return {\n variant: AuthorizationPolicyVariants.GRANT.action,\n subjectType: opts.subject.type,\n subjectId: opts.subject.id,\n targetType: opts.permission.type,\n targetId: opts.permission.id,\n action: AuthorizationActions.CUSTOM,\n effect: opts.effect,\n ...AuthorizationPolicyBuilder.splitDomain(opts.domain),\n metadata: { ops: opts.ops },\n };\n }\n\n /** Assign a role to a user (casbin `g`). `domain` null ⇒ `*` (every domain). */\n static assignRole(opts: {\n user: { type: string; id: IdType };\n role: { type: string; id: IdType };\n domain?: TNullable<TPolicyDomainInput>;\n }) {\n return {\n variant: AuthorizationPolicyVariants.ASSIGN_ROLE.action,\n subjectType: opts.user.type,\n subjectId: opts.user.id,\n targetType: opts.role.type,\n targetId: opts.role.id,\n ...AuthorizationPolicyBuilder.splitDomain(opts.domain),\n };\n }\n\n /** A user joins a domain (casbin `g2`) - backs the `ANY_MEMBER` grant scope. */\n static joinDomain(opts: {\n user: { type: string; id: IdType };\n domain: { type: string; id: IdType };\n }) {\n return {\n variant: AuthorizationPolicyVariants.JOIN_DOMAIN.action,\n subjectType: opts.user.type,\n subjectId: opts.user.id,\n targetType: opts.domain.type,\n targetId: opts.domain.id,\n };\n }\n\n /** A role inherits another role (casbin `g`, shared relation with assign_role). */\n static roleInherits(opts: {\n child: { type: string; id: IdType };\n parent: { type: string; id: IdType };\n }) {\n return {\n variant: AuthorizationPolicyVariants.ROLE_INHERITS.action,\n subjectType: opts.child.type,\n subjectId: opts.child.id,\n targetType: opts.parent.type,\n targetId: opts.parent.id,\n };\n }\n\n /** A resource inherits another (casbin `g4`): a grant on the PARENT covers the CHILD. Many-to-many - a subject may inherit several module parents, one edge each. */\n static resourceInherits(opts: {\n child: { type: string; id: IdType }; // Permission\n parent: { type: string; id: IdType }; // Permission\n }) {\n return {\n variant: AuthorizationPolicyVariants.RESOURCE_INHERITS.action,\n subjectType: opts.child.type,\n subjectId: opts.child.id,\n targetType: opts.parent.type,\n targetId: opts.parent.id,\n };\n }\n\n /** An action inherits another (casbin `g5`): the child action is implied by the parent, e.g. read ⊂ manage. */\n static actionInherits(opts: { child: TAuthorizationAction; parent: TAuthorizationAction }) {\n return {\n variant: AuthorizationPolicyVariants.ACTION_INHERITS.action,\n subjectType: this.ACTION_PRINCIPAL,\n subjectId: opts.child,\n targetType: this.ACTION_PRINCIPAL,\n targetId: opts.parent,\n };\n }\n\n /** All `action_inherits` rows for the standard {@link AuthorizationActions.LATTICE}. Seed once, idempotently. */\n static actionLattice() {\n return AuthorizationActions.LATTICE.map((action) => this.actionInherits(action));\n }\n\n /** A domain inherits another (casbin `g3`): a grant in the parent domain cascades to the child. e.g. Merchant ⊂ Organizer. */\n static domainInherits(opts: {\n child: { type: string; id: IdType };\n parent: { type: string; id: IdType };\n }) {\n return {\n variant: AuthorizationPolicyVariants.DOMAIN_INHERITS.action,\n subjectType: opts.child.type,\n subjectId: opts.child.id,\n targetType: opts.parent.type,\n targetId: opts.parent.id,\n };\n }\n\n /** Build a role's coarse grant rows from resolved permission ids. The caller resolves each `resourceCode` (subject/module) to a `Permission` and supplies the lookup; unresolved codes are skipped. */\n static roleGrants(opts: {\n role: { type: string; id: IdType };\n permission: {\n type: string;\n idByCode: ReadonlyMap<string, string>;\n };\n\n grants: ReadonlyArray<{\n resourceCode: string;\n action: string;\n domain?: TNullable<TPolicyDomainInput>;\n effect: TAuthorizationDecision;\n }>;\n }) {\n const rows: Array<ReturnType<typeof AuthorizationPolicyBuilder.grant>> = [];\n\n for (const grant of opts.grants) {\n const permissionId = opts.permission.idByCode.get(grant.resourceCode);\n\n if (!permissionId) {\n continue;\n }\n\n const policy = AuthorizationPolicyBuilder.grant({\n subject: { type: opts.role.type, id: opts.role.id },\n permission: { type: opts.permission.type, id: permissionId },\n action: grant.action,\n domain: grant.domain,\n effect: grant.effect,\n });\n\n rows.push(policy);\n }\n\n return rows;\n }\n}\n"]}
1
+ {"version":3,"file":"policy.builder.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/builders/policy.builder.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAuC7B,mNAAmN;AACnN,MAAM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;IACJ,CAAC;IAED,uMAAuM;IACvM,MAAM,CAAC,UAAU,CAAC,IAajB;QACC,MAAM,IAAI,GAA+D,EAAE,CAAC;QAE5E,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChC,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YAEtE,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,SAAS;YACX,CAAC;YAED,MAAM,MAAM,GAAG,0BAA0B,CAAC,KAAK,CAAC;gBAC9C,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE;gBACnD,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE;gBAC5D,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,MAAM,EAAE,KAAK,CAAC,MAAM;aACrB,CAAC,CAAC;YAEH,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC","sourcesContent":["import type { IdType } from '@/base';\nimport type { TNullable } from '@venizia/ignis-helpers/common';\nimport type { TAuthorizationAction, TAuthorizationDecision } from '../common/constants';\nimport {\n AuthorizationActions,\n AuthorizationDomainScopes,\n AuthorizationPolicyVariants,\n} from '../common/constants';\n\n/** A grant/assignment domain: a scope literal (`SYSTEM_WIDE`/`ANY_MEMBER`) or a typed domain entity. */\nexport type TPolicyDomainInput = string | { type: string; id: IdType };\n\n/**\n * Explicit on purpose: `TAuthorizationDecision` is `Extract<ValueOf<T>, string | number>`, and its\n * literal members widen to `string` when a method's return type is inferred rather than declared.\n * Without this annotation `grant()`'s `effect` stops satisfying `PolicyDefinition`'s narrowed column.\n * Not exported - `TGrantRow`/`TCustomGrantRow` already name unrelated adapter-side row shapes\n * downstream; consumers derive this shape via `ReturnType<typeof AuthorizationPolicyBuilder.grant>`.\n */\ntype TBuilderGrantRow = {\n variant: typeof AuthorizationPolicyVariants.GRANT.action;\n subjectType: string;\n subjectId: IdType;\n targetType: string;\n targetId: IdType;\n action: string;\n effect: TAuthorizationDecision;\n domainType: TNullable<string>;\n domainId: TNullable<IdType>;\n};\n\n/**\n * What IGNIS itself stores in `PolicyDefinition.metadata`: the operations of a subset grant, read\n * back by `ScopedCasbinAdapter` through `parseCustomGrantMetadata`. An application whose own\n * metadata has a different shape points the adapter at a different column\n * (`entities.policyDefinition.metadata.columnName`) rather than widening this one.\n *\n * Declared here, beside the only writer, so the column type and the row type cannot drift.\n */\nexport type TSubsetGrantMetadata = { ops: string[] };\n\ntype TBuilderCustomGrantRow = Omit<TBuilderGrantRow, 'action'> & {\n action: typeof AuthorizationActions.CUSTOM;\n metadata: TSubsetGrantMetadata;\n};\n\n/** Static factories for the `PolicyDefinition` rows behind each edge kind in `AuthorizationPolicyVariants` (grant, role assignment, domain join, inheritance). Returns plain row objects; nothing is persisted. */\nexport class AuthorizationPolicyBuilder {\n static readonly ACTION_PRINCIPAL = 'Action';\n\n /** A domain as the two columns that store it. `ANY_MEMBER` normalises to null - admitting both spellings would leave one state reachable two ways. */\n private static splitDomain(domain?: TNullable<TPolicyDomainInput>): {\n domainType: TNullable<string>;\n domainId: TNullable<IdType>;\n } {\n if (domain == null || domain === AuthorizationDomainScopes.ANY_MEMBER) {\n return { domainType: null, domainId: null };\n }\n\n if (typeof domain === 'string') {\n return { domainType: domain, domainId: null };\n }\n\n return { domainType: domain.type, domainId: domain.id };\n }\n\n /** A grant (casbin `p`): role/user -> permission, carrying action + effect + domain. A null `domain` means `ANY_MEMBER` (adapter default); pass a scope literal or a typed `{ type, id }` domain. */\n static grant(opts: {\n subject: { type: string; id: IdType };\n permission: { type: string; id: IdType };\n action: string;\n domain?: TNullable<TPolicyDomainInput>;\n effect: TAuthorizationDecision;\n }): TBuilderGrantRow {\n return {\n variant: AuthorizationPolicyVariants.GRANT.action,\n subjectType: opts.subject.type,\n subjectId: opts.subject.id,\n targetType: opts.permission.type,\n targetId: opts.permission.id,\n action: opts.action,\n effect: opts.effect,\n ...AuthorizationPolicyBuilder.splitDomain(opts.domain),\n };\n }\n\n /** A subset grant (casbin `p` x N): role/user -> resource node with the granted operations in metadata. `action` is fixed to the CUSTOM sentinel; the adapter expands `ops` at read time. */\n static customGrant(opts: {\n subject: { type: string; id: IdType };\n permission: { type: string; id: IdType };\n ops: string[];\n domain?: TNullable<TPolicyDomainInput>;\n effect: TAuthorizationDecision;\n }): TBuilderCustomGrantRow {\n return {\n variant: AuthorizationPolicyVariants.GRANT.action,\n subjectType: opts.subject.type,\n subjectId: opts.subject.id,\n targetType: opts.permission.type,\n targetId: opts.permission.id,\n action: AuthorizationActions.CUSTOM,\n effect: opts.effect,\n ...AuthorizationPolicyBuilder.splitDomain(opts.domain),\n metadata: { ops: opts.ops },\n };\n }\n\n /** Assign a role to a user (casbin `g`). `domain` null ⇒ `*` (every domain). */\n static assignRole(opts: {\n user: { type: string; id: IdType };\n role: { type: string; id: IdType };\n domain?: TNullable<TPolicyDomainInput>;\n }) {\n return {\n variant: AuthorizationPolicyVariants.ASSIGN_ROLE.action,\n subjectType: opts.user.type,\n subjectId: opts.user.id,\n targetType: opts.role.type,\n targetId: opts.role.id,\n ...AuthorizationPolicyBuilder.splitDomain(opts.domain),\n };\n }\n\n /** A user joins a domain (casbin `g2`) - backs the `ANY_MEMBER` grant scope. */\n static joinDomain(opts: {\n user: { type: string; id: IdType };\n domain: { type: string; id: IdType };\n }) {\n return {\n variant: AuthorizationPolicyVariants.JOIN_DOMAIN.action,\n subjectType: opts.user.type,\n subjectId: opts.user.id,\n targetType: opts.domain.type,\n targetId: opts.domain.id,\n };\n }\n\n /** A role inherits another role (casbin `g`, shared relation with assign_role). */\n static roleInherits(opts: {\n child: { type: string; id: IdType };\n parent: { type: string; id: IdType };\n }) {\n return {\n variant: AuthorizationPolicyVariants.ROLE_INHERITS.action,\n subjectType: opts.child.type,\n subjectId: opts.child.id,\n targetType: opts.parent.type,\n targetId: opts.parent.id,\n };\n }\n\n /** A resource inherits another (casbin `g4`): a grant on the PARENT covers the CHILD. Many-to-many - a subject may inherit several module parents, one edge each. */\n static resourceInherits(opts: {\n child: { type: string; id: IdType }; // Permission\n parent: { type: string; id: IdType }; // Permission\n }) {\n return {\n variant: AuthorizationPolicyVariants.RESOURCE_INHERITS.action,\n subjectType: opts.child.type,\n subjectId: opts.child.id,\n targetType: opts.parent.type,\n targetId: opts.parent.id,\n };\n }\n\n /** An action inherits another (casbin `g5`): the child action is implied by the parent, e.g. read ⊂ manage. */\n static actionInherits(opts: { child: TAuthorizationAction; parent: TAuthorizationAction }) {\n return {\n variant: AuthorizationPolicyVariants.ACTION_INHERITS.action,\n subjectType: this.ACTION_PRINCIPAL,\n subjectId: opts.child,\n targetType: this.ACTION_PRINCIPAL,\n targetId: opts.parent,\n };\n }\n\n /** All `action_inherits` rows for the standard {@link AuthorizationActions.LATTICE}. Seed once, idempotently. */\n static actionLattice() {\n return AuthorizationActions.LATTICE.map((action) => this.actionInherits(action));\n }\n\n /** A domain inherits another (casbin `g3`): a grant in the parent domain cascades to the child. e.g. Merchant ⊂ Organizer. */\n static domainInherits(opts: {\n child: { type: string; id: IdType };\n parent: { type: string; id: IdType };\n }) {\n return {\n variant: AuthorizationPolicyVariants.DOMAIN_INHERITS.action,\n subjectType: opts.child.type,\n subjectId: opts.child.id,\n targetType: opts.parent.type,\n targetId: opts.parent.id,\n };\n }\n\n /** Build a role's coarse grant rows from resolved permission ids. The caller resolves each `resourceCode` (subject/module) to a `Permission` and supplies the lookup; unresolved codes are skipped. */\n static roleGrants(opts: {\n role: { type: string; id: IdType };\n permission: {\n type: string;\n idByCode: ReadonlyMap<string, string>;\n };\n\n grants: ReadonlyArray<{\n resourceCode: string;\n action: string;\n domain?: TNullable<TPolicyDomainInput>;\n effect: TAuthorizationDecision;\n }>;\n }) {\n const rows: Array<ReturnType<typeof AuthorizationPolicyBuilder.grant>> = [];\n\n for (const grant of opts.grants) {\n const permissionId = opts.permission.idByCode.get(grant.resourceCode);\n\n if (!permissionId) {\n continue;\n }\n\n const policy = AuthorizationPolicyBuilder.grant({\n subject: { type: opts.role.type, id: opts.role.id },\n permission: { type: opts.permission.type, id: permissionId },\n action: grant.action,\n domain: grant.domain,\n effect: grant.effect,\n });\n\n rows.push(policy);\n }\n\n return rows;\n }\n}\n"]}
@@ -1,11 +1,13 @@
1
1
  import type { TConstValue } from '@venizia/ignis-helpers/common';
2
2
  import { AuthorizationRole } from '../../models/authorization-role.model.js';
3
+ /** Keys of the authorization state on the Hono context (`RULES`, `SKIP_AUTHORIZATION`, `DOMAIN`) and the binding prefix for registered enforcers (`ENFORCER`). */
3
4
  export declare class Authorization {
4
5
  static readonly RULES = "authorization.rules";
5
6
  static readonly SKIP_AUTHORIZATION = "authorization.skip";
6
7
  static readonly ENFORCER = "authorization.enforcer";
7
8
  static readonly DOMAIN = "authorization.domain";
8
9
  }
10
+ /** Actions a grant or request can name. `manage` covers `read`/`write`/`execute`, and `write` covers `create`/`update`/`delete` (see `LATTICE`). */
9
11
  export declare class AuthorizationActions {
10
12
  static readonly CREATE = "create";
11
13
  static readonly UPDATE = "update";
@@ -23,7 +25,9 @@ export declare class AuthorizationActions {
23
25
  }>;
24
26
  static isValid(input: string): boolean;
25
27
  }
28
+ /** Union of the `AuthorizationActions` values. */
26
29
  export type TAuthorizationAction = TConstValue<typeof AuthorizationActions>;
30
+ /** Outcome of a voter or enforcer. The `isAllow`/`isDeny`/`isAbstain` helpers also accept a number: positive allows, negative denies, zero abstains. */
27
31
  export declare class AuthorizationDecisions {
28
32
  static readonly ALLOW = "allow";
29
33
  static readonly DENY = "deny";
@@ -34,7 +38,9 @@ export declare class AuthorizationDecisions {
34
38
  static isDeny(input: string | number): boolean;
35
39
  static isAbstain(input: string | number): boolean;
36
40
  }
41
+ /** Union of the `AuthorizationDecisions` values. */
37
42
  export type TAuthorizationDecision = TConstValue<typeof AuthorizationDecisions>;
43
+ /** Built-in roles ordered by priority (`super-admin` 999, `admin` 900, `user` 10, `guest` 1, `unknown-user` 0). `SCHEME_SET` and `isValid` work on the role `identifier` (e.g. `010_user`), not the bare name. */
38
44
  export declare class AuthorizationRoles {
39
45
  static readonly SUPER_ADMIN: AuthorizationRole;
40
46
  static readonly ADMIN: AuthorizationRole;
@@ -44,6 +50,7 @@ export declare class AuthorizationRoles {
44
50
  static readonly SCHEME_SET: Set<string>;
45
51
  static isValid(input: string): boolean;
46
52
  }
53
+ /** Scope literals a grant can carry instead of a concrete domain. */
47
54
  export declare class AuthorizationDomainScopes {
48
55
  /** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */
49
56
  static readonly ANY_MEMBER = "ANY_MEMBER";
@@ -52,6 +59,7 @@ export declare class AuthorizationDomainScopes {
52
59
  static readonly SCHEME_SET: Set<string>;
53
60
  static isValid(input: string): boolean;
54
61
  }
62
+ /** Union of the `AuthorizationDomainScopes` values. */
55
63
  export type TAuthorizationDomainScope = TConstValue<typeof AuthorizationDomainScopes>;
56
64
  /** Edge kinds in the `PolicyDefinition` table (each row: subject -> target, `variant` = kind), carrying `action` (DB `variant` value) + `rule` (casbin prefix emitted per edge). Per-USER edges: GRANT, ASSIGN_ROLE, JOIN_DOMAIN; shared org-structure edges: the *_INHERITS ones. */
57
65
  export declare class AuthorizationPolicyVariants {
@@ -1,11 +1,13 @@
1
1
  import { AuthorizationRole } from '../../models/authorization-role.model.js';
2
2
  import { CasbinRuleVariants } from './enforcer.js';
3
+ /** Keys of the authorization state on the Hono context (`RULES`, `SKIP_AUTHORIZATION`, `DOMAIN`) and the binding prefix for registered enforcers (`ENFORCER`). */
3
4
  export class Authorization {
4
5
  static { this.RULES = 'authorization.rules'; }
5
6
  static { this.SKIP_AUTHORIZATION = 'authorization.skip'; }
6
7
  static { this.ENFORCER = 'authorization.enforcer'; }
7
8
  static { this.DOMAIN = 'authorization.domain'; }
8
9
  }
10
+ /** Actions a grant or request can name. `manage` covers `read`/`write`/`execute`, and `write` covers `create`/`update`/`delete` (see `LATTICE`). */
9
11
  export class AuthorizationActions {
10
12
  static { this.CREATE = 'create'; }
11
13
  static { this.UPDATE = 'update'; }
@@ -38,6 +40,7 @@ export class AuthorizationActions {
38
40
  return this.SCHEME_SET.has(input);
39
41
  }
40
42
  }
43
+ /** Outcome of a voter or enforcer. The `isAllow`/`isDeny`/`isAbstain` helpers also accept a number: positive allows, negative denies, zero abstains. */
41
44
  export class AuthorizationDecisions {
42
45
  static { this.ALLOW = 'allow'; }
43
46
  static { this.DENY = 'deny'; }
@@ -65,6 +68,7 @@ export class AuthorizationDecisions {
65
68
  return input.toLowerCase() === this.ABSTAIN;
66
69
  }
67
70
  }
71
+ /** Built-in roles ordered by priority (`super-admin` 999, `admin` 900, `user` 10, `guest` 1, `unknown-user` 0). `SCHEME_SET` and `isValid` work on the role `identifier` (e.g. `010_user`), not the bare name. */
68
72
  export class AuthorizationRoles {
69
73
  static { this.SUPER_ADMIN = AuthorizationRole.build({
70
74
  name: 'super-admin',
@@ -97,6 +101,7 @@ export class AuthorizationRoles {
97
101
  return this.SCHEME_SET.has(input);
98
102
  }
99
103
  }
104
+ /** Scope literals a grant can carry instead of a concrete domain. */
100
105
  export class AuthorizationDomainScopes {
101
106
  /** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */
102
107
  static { this.ANY_MEMBER = 'ANY_MEMBER'; }
@@ -1 +1 @@
1
- {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/authorization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,OAAO,aAAa;aACR,UA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AE,CAAC,CAAC,CAAC;IAE9F,MAAM,CAAC,aAAa,CAAC,KAAa;QAChC,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,KAAa;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;;AAOH,2EAA2E;AAC3E,MAAM,OAAO,0BAA0B;aACrB,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;aAClB,UAAK,GAAG,OAAO,CAAC;aAChB,YAAO,GAAG,SAAS,CAAC;aAEpB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAElG,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { AuthorizationRole } from '../../models/authorization-role.model';\nimport { CasbinRuleVariants } from './enforcer';\n\nexport class Authorization {\n static readonly RULES = 'authorization.rules';\n static readonly SKIP_AUTHORIZATION = 'authorization.skip';\n static readonly ENFORCER = 'authorization.enforcer';\n static readonly DOMAIN = 'authorization.domain';\n}\n\nexport class AuthorizationActions {\n static readonly CREATE = 'create';\n static readonly UPDATE = 'update';\n static readonly DELETE = 'delete';\n static readonly EXECUTE = 'execute';\n\n static readonly READ = 'read';\n static readonly WRITE = 'write';\n static readonly MANAGE = 'manage';\n\n /** Grant-mode marker for a subset grant carrying `metadata.ops`; never a member of LATTICE. */\n static readonly CUSTOM = 'custom';\n\n static readonly SCHEME_SET = new Set([\n this.CREATE,\n this.UPDATE,\n this.DELETE,\n this.EXECUTE,\n\n this.READ,\n this.WRITE,\n this.MANAGE,\n\n this.CUSTOM,\n ]);\n\n static readonly LATTICE: ReadonlyArray<{\n child: TAuthorizationAction;\n parent: TAuthorizationAction;\n }> = [\n { child: this.READ, parent: this.MANAGE },\n { child: this.WRITE, parent: this.MANAGE },\n { child: this.EXECUTE, parent: this.MANAGE },\n { child: this.CREATE, parent: this.WRITE },\n { child: this.UPDATE, parent: this.WRITE },\n { child: this.DELETE, parent: this.WRITE },\n ];\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\nexport type TAuthorizationAction = TConstValue<typeof AuthorizationActions>;\n\nexport class AuthorizationDecisions {\n static readonly ALLOW = 'allow';\n static readonly DENY = 'deny';\n static readonly ABSTAIN = 'abstain';\n\n static readonly SCHEME_SET = new Set([this.ALLOW, this.DENY, this.ABSTAIN]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n\n static isAllow(input: string | number): boolean {\n if (typeof input === 'number') {\n return input > 0;\n }\n\n return input.toLowerCase() === this.ALLOW;\n }\n\n static isDeny(input: string | number): boolean {\n if (typeof input === 'number') {\n return input < 0;\n }\n\n return input.toLowerCase() === this.DENY;\n }\n\n static isAbstain(input: string | number): boolean {\n if (typeof input === 'number') {\n return input === 0;\n }\n\n return input.toLowerCase() === this.ABSTAIN;\n }\n}\nexport type TAuthorizationDecision = TConstValue<typeof AuthorizationDecisions>;\n\nexport class AuthorizationRoles {\n static readonly SUPER_ADMIN = AuthorizationRole.build({\n name: 'super-admin',\n priority: 999,\n });\n\n static readonly ADMIN = AuthorizationRole.build({\n name: 'admin',\n priority: 900,\n });\n\n static readonly USER = AuthorizationRole.build({\n name: 'user',\n priority: 10,\n });\n\n static readonly GUEST = AuthorizationRole.build({\n name: 'guest',\n priority: 1,\n });\n\n static readonly UNKNOWN_USER = AuthorizationRole.build({\n name: 'unknown-user',\n priority: 0,\n });\n\n static readonly SCHEME_SET = new Set<string>([\n this.SUPER_ADMIN.identifier,\n this.ADMIN.identifier,\n this.USER.identifier,\n this.GUEST.identifier,\n this.UNKNOWN_USER.identifier,\n ]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport class AuthorizationDomainScopes {\n /** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */\n static readonly ANY_MEMBER = 'ANY_MEMBER';\n\n /** Grant applies system-wide, bypassing membership - super-admin only. */\n static readonly SYSTEM_WIDE = 'SYSTEM_WIDE';\n\n static readonly SCHEME_SET = new Set([this.ANY_MEMBER, this.SYSTEM_WIDE]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\nexport type TAuthorizationDomainScope = TConstValue<typeof AuthorizationDomainScopes>;\n\n/** Edge kinds in the `PolicyDefinition` table (each row: subject -> target, `variant` = kind), carrying `action` (DB `variant` value) + `rule` (casbin prefix emitted per edge). Per-USER edges: GRANT, ASSIGN_ROLE, JOIN_DOMAIN; shared org-structure edges: the *_INHERITS ones. */\nexport class AuthorizationPolicyVariants {\n /** Give a Permission to a User/Role (row also carries action / effect / domain). casbin `p`: `p, <Role|User>_<id>, <domain>, <permissionCode>, <action>, <allow|deny>` */\n static readonly GRANT = { action: 'grant', rule: CasbinRuleVariants.P } as const;\n\n /** Give a User a Role (optionally domain-scoped; no domain -> `*` = every domain). casbin `g`: `g, User_<id>, Role_<id>, <domain|*>` */\n static readonly ASSIGN_ROLE = { action: 'assign_role', rule: CasbinRuleVariants.G } as const;\n\n /** A Role inherits another Role (DAG). Shares `g` with ASSIGN_ROLE so user -> role -> parent-role resolves in one lookup. Emitted with domain `*`: `g, Role_<child>, Role_<parent>, *` */\n static readonly ROLE_INHERITS = { action: 'role_inherits', rule: CasbinRuleVariants.G } as const;\n\n /** User is a member of a Domain; powers the `ANY_MEMBER` grant scope via `g2(r.sub, r.dom)`. casbin `g2`: `g2, User_<id>, <Type>_<domainId>` */\n static readonly JOIN_DOMAIN = { action: 'join_domain', rule: CasbinRuleVariants.G2 } as const;\n\n /** DOMAIN axis (`dom`): domain nesting. Matcher: `g3(r.dom, p.dom)` + self-link so an exact domain always matches itself. casbin `g3`: `g3, <Type>_<childId>, <Type>_<parentId>` */\n static readonly DOMAIN_INHERITS = {\n action: 'domain_inherits',\n rule: CasbinRuleVariants.G3,\n } as const;\n\n /** RESOURCE axis (`obj`), NON-standard nesting only - dotted nesting (`Order.findById ⊂ Order`) is handled by `objectMatch` WITHOUT an edge. Matcher: `objectMatch(r.obj, p.obj) || g4(r.obj, p.obj)`, casbin `g4`: `g4, <childCode>, <parentCode>` */\n static readonly RESOURCE_INHERITS = {\n action: 'resource_inherits',\n rule: CasbinRuleVariants.G4,\n } as const;\n\n /** ACTION axis (`act`): a narrow action covered by a broader one; no dotted shortcut, so it needs an explicit edge. Matcher: `g5(r.act, p.act)`, casbin `g5`: `g5, <childAction>, <parentAction>`. g4 + g5 combine multiplicatively: `manage Order` covers a `read OrderItem` request. */\n static readonly ACTION_INHERITS = {\n action: 'action_inherits',\n rule: CasbinRuleVariants.G5,\n } as const;\n\n /** Every edge kind, in declaration order - the one place the scheme sets and the `variant` column's literal type both derive from. */\n static readonly ALL = [\n this.GRANT,\n this.ASSIGN_ROLE,\n this.ROLE_INHERITS,\n this.JOIN_DOMAIN,\n this.DOMAIN_INHERITS,\n this.RESOURCE_INHERITS,\n this.ACTION_INHERITS,\n ] as const;\n\n static readonly ACTION_SCHEME_SET = new Set(this.ALL.map((variant) => variant.action.toString()));\n\n static readonly RULE_SCHEME_SET = new Set(this.ALL.map((variant) => variant.rule.toString()));\n\n static isValidAction(input: string): boolean {\n return this.ACTION_SCHEME_SET.has(input);\n }\n\n static isValidRule(input: string): boolean {\n return this.RULE_SCHEME_SET.has(input);\n }\n}\n\n/** The `variant` column's full value set, derived from {@link AuthorizationPolicyVariants.ALL} - never hand-list the seven strings again. */\nexport type TAuthorizationPolicyVariant =\n (typeof AuthorizationPolicyVariants.ALL)[number]['action'];\n\n/** Where an `IAuthorizationDomainSource` reads the request domain from. */\nexport class AuthorizationDomainSources {\n static readonly PARAM = 'param';\n static readonly HEADER = 'header';\n static readonly QUERY = 'query';\n static readonly CONTEXT = 'context';\n\n static readonly SCHEME_SET = new Set<string>([this.PARAM, this.HEADER, this.QUERY, this.CONTEXT]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid authorization domain source values. */\nexport type TAuthorizationDomainSource = TConstValue<typeof AuthorizationDomainSources>;\n"]}
1
+ {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/authorization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,kKAAkK;AAClK,MAAM,OAAO,aAAa;aACR,UAAK,GAAG,qBAAqB,CAAC;aAC9B,uBAAkB,GAAG,oBAAoB,CAAC;aAC1C,aAAQ,GAAG,wBAAwB,CAAC;aACpC,WAAM,GAAG,sBAAsB,CAAC;;AAGlD,oJAAoJ;AACpJ,MAAM,OAAO,oBAAoB;aACf,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,YAAO,GAAG,SAAS,CAAC;aAEpB,SAAI,GAAG,MAAM,CAAC;aACd,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;IAElC,+FAA+F;aAC/E,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,OAAO;QAEZ,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,KAAK;QACV,IAAI,CAAC,MAAM;QAEX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;aAEa,YAAO,GAGlB;QACH,EAAE,KA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AAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\nimport { AuthorizationRole } from '../../models/authorization-role.model';\nimport { CasbinRuleVariants } from './enforcer';\n\n/** Keys of the authorization state on the Hono context (`RULES`, `SKIP_AUTHORIZATION`, `DOMAIN`) and the binding prefix for registered enforcers (`ENFORCER`). */\nexport class Authorization {\n static readonly RULES = 'authorization.rules';\n static readonly SKIP_AUTHORIZATION = 'authorization.skip';\n static readonly ENFORCER = 'authorization.enforcer';\n static readonly DOMAIN = 'authorization.domain';\n}\n\n/** Actions a grant or request can name. `manage` covers `read`/`write`/`execute`, and `write` covers `create`/`update`/`delete` (see `LATTICE`). */\nexport class AuthorizationActions {\n static readonly CREATE = 'create';\n static readonly UPDATE = 'update';\n static readonly DELETE = 'delete';\n static readonly EXECUTE = 'execute';\n\n static readonly READ = 'read';\n static readonly WRITE = 'write';\n static readonly MANAGE = 'manage';\n\n /** Grant-mode marker for a subset grant carrying `metadata.ops`; never a member of LATTICE. */\n static readonly CUSTOM = 'custom';\n\n static readonly SCHEME_SET = new Set([\n this.CREATE,\n this.UPDATE,\n this.DELETE,\n this.EXECUTE,\n\n this.READ,\n this.WRITE,\n this.MANAGE,\n\n this.CUSTOM,\n ]);\n\n static readonly LATTICE: ReadonlyArray<{\n child: TAuthorizationAction;\n parent: TAuthorizationAction;\n }> = [\n { child: this.READ, parent: this.MANAGE },\n { child: this.WRITE, parent: this.MANAGE },\n { child: this.EXECUTE, parent: this.MANAGE },\n { child: this.CREATE, parent: this.WRITE },\n { child: this.UPDATE, parent: this.WRITE },\n { child: this.DELETE, parent: this.WRITE },\n ];\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n/** Union of the `AuthorizationActions` values. */\nexport type TAuthorizationAction = TConstValue<typeof AuthorizationActions>;\n\n/** Outcome of a voter or enforcer. The `isAllow`/`isDeny`/`isAbstain` helpers also accept a number: positive allows, negative denies, zero abstains. */\nexport class AuthorizationDecisions {\n static readonly ALLOW = 'allow';\n static readonly DENY = 'deny';\n static readonly ABSTAIN = 'abstain';\n\n static readonly SCHEME_SET = new Set([this.ALLOW, this.DENY, this.ABSTAIN]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n\n static isAllow(input: string | number): boolean {\n if (typeof input === 'number') {\n return input > 0;\n }\n\n return input.toLowerCase() === this.ALLOW;\n }\n\n static isDeny(input: string | number): boolean {\n if (typeof input === 'number') {\n return input < 0;\n }\n\n return input.toLowerCase() === this.DENY;\n }\n\n static isAbstain(input: string | number): boolean {\n if (typeof input === 'number') {\n return input === 0;\n }\n\n return input.toLowerCase() === this.ABSTAIN;\n }\n}\n/** Union of the `AuthorizationDecisions` values. */\nexport type TAuthorizationDecision = TConstValue<typeof AuthorizationDecisions>;\n\n/** Built-in roles ordered by priority (`super-admin` 999, `admin` 900, `user` 10, `guest` 1, `unknown-user` 0). `SCHEME_SET` and `isValid` work on the role `identifier` (e.g. `010_user`), not the bare name. */\nexport class AuthorizationRoles {\n static readonly SUPER_ADMIN = AuthorizationRole.build({\n name: 'super-admin',\n priority: 999,\n });\n\n static readonly ADMIN = AuthorizationRole.build({\n name: 'admin',\n priority: 900,\n });\n\n static readonly USER = AuthorizationRole.build({\n name: 'user',\n priority: 10,\n });\n\n static readonly GUEST = AuthorizationRole.build({\n name: 'guest',\n priority: 1,\n });\n\n static readonly UNKNOWN_USER = AuthorizationRole.build({\n name: 'unknown-user',\n priority: 0,\n });\n\n static readonly SCHEME_SET = new Set<string>([\n this.SUPER_ADMIN.identifier,\n this.ADMIN.identifier,\n this.USER.identifier,\n this.GUEST.identifier,\n this.UNKNOWN_USER.identifier,\n ]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** Scope literals a grant can carry instead of a concrete domain. */\nexport class AuthorizationDomainScopes {\n /** Grant applies in EVERY domain the subject is a member of (checked via join_domain / g2). */\n static readonly ANY_MEMBER = 'ANY_MEMBER';\n\n /** Grant applies system-wide, bypassing membership - super-admin only. */\n static readonly SYSTEM_WIDE = 'SYSTEM_WIDE';\n\n static readonly SCHEME_SET = new Set([this.ANY_MEMBER, this.SYSTEM_WIDE]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n/** Union of the `AuthorizationDomainScopes` values. */\nexport type TAuthorizationDomainScope = TConstValue<typeof AuthorizationDomainScopes>;\n\n/** Edge kinds in the `PolicyDefinition` table (each row: subject -> target, `variant` = kind), carrying `action` (DB `variant` value) + `rule` (casbin prefix emitted per edge). Per-USER edges: GRANT, ASSIGN_ROLE, JOIN_DOMAIN; shared org-structure edges: the *_INHERITS ones. */\nexport class AuthorizationPolicyVariants {\n /** Give a Permission to a User/Role (row also carries action / effect / domain). casbin `p`: `p, <Role|User>_<id>, <domain>, <permissionCode>, <action>, <allow|deny>` */\n static readonly GRANT = { action: 'grant', rule: CasbinRuleVariants.P } as const;\n\n /** Give a User a Role (optionally domain-scoped; no domain -> `*` = every domain). casbin `g`: `g, User_<id>, Role_<id>, <domain|*>` */\n static readonly ASSIGN_ROLE = { action: 'assign_role', rule: CasbinRuleVariants.G } as const;\n\n /** A Role inherits another Role (DAG). Shares `g` with ASSIGN_ROLE so user -> role -> parent-role resolves in one lookup. Emitted with domain `*`: `g, Role_<child>, Role_<parent>, *` */\n static readonly ROLE_INHERITS = { action: 'role_inherits', rule: CasbinRuleVariants.G } as const;\n\n /** User is a member of a Domain; powers the `ANY_MEMBER` grant scope via `g2(r.sub, r.dom)`. casbin `g2`: `g2, User_<id>, <Type>_<domainId>` */\n static readonly JOIN_DOMAIN = { action: 'join_domain', rule: CasbinRuleVariants.G2 } as const;\n\n /** DOMAIN axis (`dom`): domain nesting. Matcher: `g3(r.dom, p.dom)` + self-link so an exact domain always matches itself. casbin `g3`: `g3, <Type>_<childId>, <Type>_<parentId>` */\n static readonly DOMAIN_INHERITS = {\n action: 'domain_inherits',\n rule: CasbinRuleVariants.G3,\n } as const;\n\n /** RESOURCE axis (`obj`), NON-standard nesting only - dotted nesting (`Order.findById ⊂ Order`) is handled by `objectMatch` WITHOUT an edge. Matcher: `objectMatch(r.obj, p.obj) || g4(r.obj, p.obj)`, casbin `g4`: `g4, <childCode>, <parentCode>` */\n static readonly RESOURCE_INHERITS = {\n action: 'resource_inherits',\n rule: CasbinRuleVariants.G4,\n } as const;\n\n /** ACTION axis (`act`): a narrow action covered by a broader one; no dotted shortcut, so it needs an explicit edge. Matcher: `g5(r.act, p.act)`, casbin `g5`: `g5, <childAction>, <parentAction>`. g4 + g5 combine multiplicatively: `manage Order` covers a `read OrderItem` request. */\n static readonly ACTION_INHERITS = {\n action: 'action_inherits',\n rule: CasbinRuleVariants.G5,\n } as const;\n\n /** Every edge kind, in declaration order - the one place the scheme sets and the `variant` column's literal type both derive from. */\n static readonly ALL = [\n this.GRANT,\n this.ASSIGN_ROLE,\n this.ROLE_INHERITS,\n this.JOIN_DOMAIN,\n this.DOMAIN_INHERITS,\n this.RESOURCE_INHERITS,\n this.ACTION_INHERITS,\n ] as const;\n\n static readonly ACTION_SCHEME_SET = new Set(this.ALL.map((variant) => variant.action.toString()));\n\n static readonly RULE_SCHEME_SET = new Set(this.ALL.map((variant) => variant.rule.toString()));\n\n static isValidAction(input: string): boolean {\n return this.ACTION_SCHEME_SET.has(input);\n }\n\n static isValidRule(input: string): boolean {\n return this.RULE_SCHEME_SET.has(input);\n }\n}\n\n/** The `variant` column's full value set, derived from {@link AuthorizationPolicyVariants.ALL} - never hand-list the seven strings again. */\nexport type TAuthorizationPolicyVariant =\n (typeof AuthorizationPolicyVariants.ALL)[number]['action'];\n\n/** Where an `IAuthorizationDomainSource` reads the request domain from. */\nexport class AuthorizationDomainSources {\n static readonly PARAM = 'param';\n static readonly HEADER = 'header';\n static readonly QUERY = 'query';\n static readonly CONTEXT = 'context';\n\n static readonly SCHEME_SET = new Set<string>([this.PARAM, this.HEADER, this.QUERY, this.CONTEXT]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid authorization domain source values. */\nexport type TAuthorizationDomainSource = TConstValue<typeof AuthorizationDomainSources>;\n"]}
@@ -1,3 +1,4 @@
1
+ /** Container binding keys for the authorize options, the always-allow roles, and (through `enforcerOptions`) the options of one named enforcer. */
1
2
  export declare class AuthorizeBindingKeys {
2
3
  static readonly OPTIONS = "@app/authorize/options";
3
4
  static readonly ALWAYS_ALLOW_ROLES = "@app/authorize/always-allow-roles";
@@ -1,3 +1,4 @@
1
+ /** Container binding keys for the authorize options, the always-allow roles, and (through `enforcerOptions`) the options of one named enforcer. */
1
2
  export class AuthorizeBindingKeys {
2
3
  static { this.OPTIONS = '@app/authorize/options'; }
3
4
  static { this.ALWAYS_ALLOW_ROLES = '@app/authorize/always-allow-roles'; }
@@ -1 +1 @@
1
- {"version":3,"file":"binding-keys.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/binding-keys.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,oBAAoB;aACf,YAAO,GAAG,wBAAwB,CAAC;aACnC,uBAAkB,GAAG,mCAAmC,CAAC;IAEzE,MAAM,CAAC,eAAe,CAAC,IAAY;QACjC,OAAO,4BAA4B,IAAI,UAAU,CAAC;IACpD,CAAC","sourcesContent":["export class AuthorizeBindingKeys {\n static readonly OPTIONS = '@app/authorize/options';\n static readonly ALWAYS_ALLOW_ROLES = '@app/authorize/always-allow-roles';\n\n static enforcerOptions(name: string): string {\n return `@app/authorize/enforcers/${name}/options`;\n }\n}\n"]}
1
+ {"version":3,"file":"binding-keys.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/binding-keys.ts"],"names":[],"mappings":"AAAA,mJAAmJ;AACnJ,MAAM,OAAO,oBAAoB;aACf,YAAO,GAAG,wBAAwB,CAAC;aACnC,uBAAkB,GAAG,mCAAmC,CAAC;IAEzE,MAAM,CAAC,eAAe,CAAC,IAAY;QACjC,OAAO,4BAA4B,IAAI,UAAU,CAAC;IACpD,CAAC","sourcesContent":["/** Container binding keys for the authorize options, the always-allow roles, and (through `enforcerOptions`) the options of one named enforcer. */\nexport class AuthorizeBindingKeys {\n static readonly OPTIONS = '@app/authorize/options';\n static readonly ALWAYS_ALLOW_ROLES = '@app/authorize/always-allow-roles';\n\n static enforcerOptions(name: string): string {\n return `@app/authorize/enforcers/${name}/options`;\n }\n}\n"]}
@@ -1,24 +1,31 @@
1
1
  import type { TConstValue } from '@venizia/ignis-helpers/common';
2
+ /** Kinds of enforcer a registration can declare; `casbin` takes `ICasbinEnforcerOptions`, `custom` takes untyped options. */
2
3
  export declare class AuthorizationEnforcerTypes {
3
4
  static readonly CASBIN = "casbin";
4
5
  static readonly CUSTOM = "custom";
5
6
  static readonly SCHEME_SET: Set<string>;
6
7
  static isValid(input: string): boolean;
7
8
  }
9
+ /** Union of the `AuthorizationEnforcerTypes` values. */
8
10
  export type TAuthorizationEnforcerType = TConstValue<typeof AuthorizationEnforcerTypes>;
11
+ /** Cache backends for a Casbin enforcer's per-user policy lines. */
9
12
  export declare class CasbinEnforcerCachedDrivers {
10
13
  static readonly REDIS = "redis";
11
14
  static readonly SCHEME_SET: Set<string>;
12
15
  static isValid(input: string): boolean;
13
16
  }
17
+ /** Union of the `CasbinEnforcerCachedDrivers` values. */
14
18
  export type TCasbinEnforcerCachedDriver = TConstValue<typeof CasbinEnforcerCachedDrivers>;
19
+ /** Where a Casbin enforcer reads its model from: a `file` path or inline `text`. */
15
20
  export declare class CasbinEnforcerModelDrivers {
16
21
  static readonly FILE = "file";
17
22
  static readonly TEXT = "text";
18
23
  static readonly SCHEME_SET: Set<string>;
19
24
  static isValid(input: string): boolean;
20
25
  }
26
+ /** Union of the `CasbinEnforcerModelDrivers` values. */
21
27
  export type TCasbinEnforcerModelDriver = TConstValue<typeof CasbinEnforcerModelDrivers>;
28
+ /** Casbin matching functions selectable for the domain match in `ICasbinEnforcerOptions.domainMatching`. */
22
29
  export declare class CasbinDomainMatchingFunctions {
23
30
  /** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */
24
31
  static readonly KEY_MATCH = "keyMatch";
@@ -33,6 +40,7 @@ export declare class CasbinDomainMatchingFunctions {
33
40
  static readonly SCHEME_SET: Set<string>;
34
41
  static isValid(input: string): boolean;
35
42
  }
43
+ /** Union of the `CasbinDomainMatchingFunctions` values. */
36
44
  export type TCasbinDomainMatchingFunction = TConstValue<typeof CasbinDomainMatchingFunctions>;
37
45
  /** Relation prefixes the Casbin MODEL declares (`p` + `g`..`g5`), which {@link AuthorizationPolicyVariants} maps onto (many app edge-types -> one rule). Keep in sync with the model's `[role_definition]`. */
38
46
  export declare class CasbinRuleVariants {
@@ -50,5 +58,6 @@ export declare class CasbinRuleVariants {
50
58
  /** Grouping #5 - action hierarchy. The `act` axis. */
51
59
  static readonly G5 = "g5";
52
60
  }
61
+ /** Union of the `CasbinRuleVariants` values. */
53
62
  export type TCasbinRuleVariant = TConstValue<typeof CasbinRuleVariants>;
54
63
  //# sourceMappingURL=enforcer.d.ts.map
@@ -1,3 +1,4 @@
1
+ /** Kinds of enforcer a registration can declare; `casbin` takes `ICasbinEnforcerOptions`, `custom` takes untyped options. */
1
2
  export class AuthorizationEnforcerTypes {
2
3
  static { this.CASBIN = 'casbin'; }
3
4
  static { this.CUSTOM = 'custom'; }
@@ -6,6 +7,7 @@ export class AuthorizationEnforcerTypes {
6
7
  return this.SCHEME_SET.has(input);
7
8
  }
8
9
  }
10
+ /** Cache backends for a Casbin enforcer's per-user policy lines. */
9
11
  export class CasbinEnforcerCachedDrivers {
10
12
  static { this.REDIS = 'redis'; }
11
13
  static { this.SCHEME_SET = new Set([this.REDIS]); }
@@ -13,6 +15,7 @@ export class CasbinEnforcerCachedDrivers {
13
15
  return this.SCHEME_SET.has(input);
14
16
  }
15
17
  }
18
+ /** Where a Casbin enforcer reads its model from: a `file` path or inline `text`. */
16
19
  export class CasbinEnforcerModelDrivers {
17
20
  static { this.FILE = 'file'; }
18
21
  static { this.TEXT = 'text'; }
@@ -21,6 +24,7 @@ export class CasbinEnforcerModelDrivers {
21
24
  return this.SCHEME_SET.has(input);
22
25
  }
23
26
  }
27
+ /** Casbin matching functions selectable for the domain match in `ICasbinEnforcerOptions.domainMatching`. */
24
28
  export class CasbinDomainMatchingFunctions {
25
29
  /** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */
26
30
  static { this.KEY_MATCH = 'keyMatch'; }
@@ -1 +1 @@
1
- {"version":3,"file":"enforcer.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/enforcer.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,0BAA0B;aACrB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAEjE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,OAAO,2BAA2B;aACtB,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnD,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,OAAO,0BAA0B;aACrB,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7D,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,OAAO,6BAA6B;IACxC,+FAA+F;aAC/E,cAAS,GAAG,UAAU,CAAC;IAEvC,+CAA+C;aAC/B,gBAAW,GAAG,WAAW,CAAC;IAE1C,uCAAuC;aACvB,gBAAW,GAAG,WAAW,CAAC;IAE1C,6DAA6D;aAC7C,gBAAW,GAAG,WAAW,CAAC;IAE1C,mEAAmE;aACnD,gBAAW,GAAG,YAAY,CAAC;aAE3B,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,WAAW;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,+MAA+M;AAC/M,MAAM,OAAO,kBAAkB;IAC7B,8BAA8B;aACd,MAAC,GAAG,GAAG,CAAC;IAExB,4GAA4G;IAE5G,+FAA+F;aAC/E,MAAC,GAAG,GAAG,CAAC;IAExB,uFAAuF;aACvE,OAAE,GAAG,IAAI,CAAC;IAE1B,gEAAgE;aAChD,OAAE,GAAG,IAAI,CAAC;IAE1B,wDAAwD;aACxC,OAAE,GAAG,IAAI,CAAC;IAE1B,sDAAsD;aACtC,OAAE,GAAG,IAAI,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\n\nexport class AuthorizationEnforcerTypes {\n static readonly CASBIN = 'casbin';\n static readonly CUSTOM = 'custom';\n\n static readonly SCHEME_SET = new Set([this.CASBIN, this.CUSTOM]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TAuthorizationEnforcerType = TConstValue<typeof AuthorizationEnforcerTypes>;\n\nexport class CasbinEnforcerCachedDrivers {\n static readonly REDIS = 'redis';\n\n static readonly SCHEME_SET = new Set([this.REDIS]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TCasbinEnforcerCachedDriver = TConstValue<typeof CasbinEnforcerCachedDrivers>;\n\nexport class CasbinEnforcerModelDrivers {\n static readonly FILE = 'file';\n static readonly TEXT = 'text';\n\n static readonly SCHEME_SET = new Set([this.FILE, this.TEXT]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TCasbinEnforcerModelDriver = TConstValue<typeof CasbinEnforcerModelDrivers>;\n\nexport class CasbinDomainMatchingFunctions {\n /** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */\n static readonly KEY_MATCH = 'keyMatch';\n\n /** Adds URL-path `:param` segment matching. */\n static readonly KEY_MATCH_2 = 'keyMatch2';\n\n /** Adds `{param}` segment matching. */\n static readonly KEY_MATCH_3 = 'keyMatch3';\n\n /** `{param}` matching with repeated-name equality checks. */\n static readonly KEY_MATCH_4 = 'keyMatch4';\n\n /** Treats the stored/policy value as a full regular expression. */\n static readonly REGEX_MATCH = 'regexMatch';\n\n static readonly SCHEME_SET = new Set([\n this.KEY_MATCH,\n this.KEY_MATCH_2,\n this.KEY_MATCH_3,\n this.KEY_MATCH_4,\n this.REGEX_MATCH,\n ]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\nexport type TCasbinDomainMatchingFunction = TConstValue<typeof CasbinDomainMatchingFunctions>;\n\n/** Relation prefixes the Casbin MODEL declares (`p` + `g`..`g5`), which {@link AuthorizationPolicyVariants} maps onto (many app edge-types -> one rule). Keep in sync with the model's `[role_definition]`. */\nexport class CasbinRuleVariants {\n /** Permission policy line. */\n static readonly P = 'p';\n\n /** Numbered in request-tuple order (sub -> dom -> obj -> act): g (sub), g2/g3 (dom), g4 (obj), g5 (act). */\n\n /** Grouping #1 - role membership + role inheritance (user→role, role→role). The `sub` axis. */\n static readonly G = 'g';\n\n /** Grouping #2 - user→domain membership (join_domain). The `dom` axis (membership). */\n static readonly G2 = 'g2';\n\n /** Grouping #3 - domain hierarchy. The `dom` axis (nesting). */\n static readonly G3 = 'g3';\n\n /** Grouping #4 - resource hierarchy. The `obj` axis. */\n static readonly G4 = 'g4';\n\n /** Grouping #5 - action hierarchy. The `act` axis. */\n static readonly G5 = 'g5';\n}\n\nexport type TCasbinRuleVariant = TConstValue<typeof CasbinRuleVariants>;\n"]}
1
+ {"version":3,"file":"enforcer.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/constants/enforcer.ts"],"names":[],"mappings":"AAEA,6HAA6H;AAC7H,MAAM,OAAO,0BAA0B;aACrB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAEjE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,oEAAoE;AACpE,MAAM,OAAO,2BAA2B;aACtB,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAEnD,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,oFAAoF;AACpF,MAAM,OAAO,0BAA0B;aACrB,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aAEd,eAAU,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAE7D,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,4GAA4G;AAC5G,MAAM,OAAO,6BAA6B;IACxC,+FAA+F;aAC/E,cAAS,GAAG,UAAU,CAAC;IAEvC,+CAA+C;aAC/B,gBAAW,GAAG,WAAW,CAAC;IAE1C,uCAAuC;aACvB,gBAAW,GAAG,WAAW,CAAC;IAE1C,6DAA6D;aAC7C,gBAAW,GAAG,WAAW,CAAC;IAE1C,mEAAmE;aACnD,gBAAW,GAAG,YAAY,CAAC;aAE3B,eAAU,GAAG,IAAI,GAAG,CAAC;QACnC,IAAI,CAAC,SAAS;QACd,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,WAAW;QAChB,IAAI,CAAC,WAAW;KACjB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAMH,+MAA+M;AAC/M,MAAM,OAAO,kBAAkB;IAC7B,8BAA8B;aACd,MAAC,GAAG,GAAG,CAAC;IAExB,4GAA4G;IAE5G,+FAA+F;aAC/E,MAAC,GAAG,GAAG,CAAC;IAExB,uFAAuF;aACvE,OAAE,GAAG,IAAI,CAAC;IAE1B,gEAAgE;aAChD,OAAE,GAAG,IAAI,CAAC;IAE1B,wDAAwD;aACxC,OAAE,GAAG,IAAI,CAAC;IAE1B,sDAAsD;aACtC,OAAE,GAAG,IAAI,CAAC","sourcesContent":["import type { TConstValue } from '@venizia/ignis-helpers/common';\n\n/** Kinds of enforcer a registration can declare; `casbin` takes `ICasbinEnforcerOptions`, `custom` takes untyped options. */\nexport class AuthorizationEnforcerTypes {\n static readonly CASBIN = 'casbin';\n static readonly CUSTOM = 'custom';\n\n static readonly SCHEME_SET = new Set([this.CASBIN, this.CUSTOM]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** Union of the `AuthorizationEnforcerTypes` values. */\nexport type TAuthorizationEnforcerType = TConstValue<typeof AuthorizationEnforcerTypes>;\n\n/** Cache backends for a Casbin enforcer's per-user policy lines. */\nexport class CasbinEnforcerCachedDrivers {\n static readonly REDIS = 'redis';\n\n static readonly SCHEME_SET = new Set([this.REDIS]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** Union of the `CasbinEnforcerCachedDrivers` values. */\nexport type TCasbinEnforcerCachedDriver = TConstValue<typeof CasbinEnforcerCachedDrivers>;\n\n/** Where a Casbin enforcer reads its model from: a `file` path or inline `text`. */\nexport class CasbinEnforcerModelDrivers {\n static readonly FILE = 'file';\n static readonly TEXT = 'text';\n\n static readonly SCHEME_SET = new Set([this.FILE, this.TEXT]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** Union of the `CasbinEnforcerModelDrivers` values. */\nexport type TCasbinEnforcerModelDriver = TConstValue<typeof CasbinEnforcerModelDrivers>;\n\n/** Casbin matching functions selectable for the domain match in `ICasbinEnforcerOptions.domainMatching`. */\nexport class CasbinDomainMatchingFunctions {\n /** `*` is the only wildcard; exact compare otherwise. Safest for `Merchant_<uuid>` domains. */\n static readonly KEY_MATCH = 'keyMatch';\n\n /** Adds URL-path `:param` segment matching. */\n static readonly KEY_MATCH_2 = 'keyMatch2';\n\n /** Adds `{param}` segment matching. */\n static readonly KEY_MATCH_3 = 'keyMatch3';\n\n /** `{param}` matching with repeated-name equality checks. */\n static readonly KEY_MATCH_4 = 'keyMatch4';\n\n /** Treats the stored/policy value as a full regular expression. */\n static readonly REGEX_MATCH = 'regexMatch';\n\n static readonly SCHEME_SET = new Set([\n this.KEY_MATCH,\n this.KEY_MATCH_2,\n this.KEY_MATCH_3,\n this.KEY_MATCH_4,\n this.REGEX_MATCH,\n ]);\n\n static isValid(input: string): boolean {\n return this.SCHEME_SET.has(input);\n }\n}\n\n/** Union of the `CasbinDomainMatchingFunctions` values. */\nexport type TCasbinDomainMatchingFunction = TConstValue<typeof CasbinDomainMatchingFunctions>;\n\n/** Relation prefixes the Casbin MODEL declares (`p` + `g`..`g5`), which {@link AuthorizationPolicyVariants} maps onto (many app edge-types -> one rule). Keep in sync with the model's `[role_definition]`. */\nexport class CasbinRuleVariants {\n /** Permission policy line. */\n static readonly P = 'p';\n\n /** Numbered in request-tuple order (sub -> dom -> obj -> act): g (sub), g2/g3 (dom), g4 (obj), g5 (act). */\n\n /** Grouping #1 - role membership + role inheritance (user→role, role→role). The `sub` axis. */\n static readonly G = 'g';\n\n /** Grouping #2 - user→domain membership (join_domain). The `dom` axis (membership). */\n static readonly G2 = 'g2';\n\n /** Grouping #3 - domain hierarchy. The `dom` axis (nesting). */\n static readonly G3 = 'g3';\n\n /** Grouping #4 - resource hierarchy. The `obj` axis. */\n static readonly G4 = 'g4';\n\n /** Grouping #5 - action hierarchy. The `act` axis. */\n static readonly G5 = 'g5';\n}\n\n/** Union of the `CasbinRuleVariants` values. */\nexport type TCasbinRuleVariant = TConstValue<typeof CasbinRuleVariants>;\n"]}
@@ -39,12 +39,14 @@ export interface IAuthorizationEnforcer<E extends Env = Env, TAction = string, T
39
39
  lineCount: number;
40
40
  }>;
41
41
  }
42
+ /** Per-route check run before the enforcer. `deny` rejects the request, `allow` accepts it without consulting the enforcer, `abstain` passes to the next voter and then the enforcer. */
42
43
  export type TAuthorizationVoter<E extends Env = Env, TAction = string, TResource = string> = (opts: {
43
44
  user: IAuthUser;
44
45
  action: TAction;
45
46
  resource: TResource;
46
47
  context: TContext<E, string>;
47
48
  }) => ValueOrPromise<TAuthorizationDecision>;
49
+ /** Per-route authorization requirement passed to `authorize()`. `allowedRoles` grants access to matching roles before voters and the enforcer run. */
48
50
  export interface IAuthorizationSpec<E extends Env = Env, TAction = string, TResource = string> {
49
51
  action: TAction;
50
52
  resource: TResource;
@@ -54,10 +56,12 @@ export interface IAuthorizationSpec<E extends Env = Env, TAction = string, TReso
54
56
  /** Optional per-route domain: declarative source OR a resolver method. Omitted → global resolver. */
55
57
  domain?: IAuthorizationDomainSource | TAuthorizationDomainResolver<E>;
56
58
  }
59
+ /** Factory that turns an `IAuthorizationSpec` (and optional enforcer name) into a Hono middleware. */
57
60
  export type TAuthorizeFn<E extends Env = Env, TAction = string, TResource = string> = (opts: {
58
61
  spec: IAuthorizationSpec<E, TAction, TResource>;
59
62
  enforcerName?: string;
60
63
  }) => MiddlewareHandler;
64
+ /** Redis cache for a Casbin enforcer's per-user policy lines. `keyFn` returns the cache key for a user and must not return an empty string. */
61
65
  export interface ICasbinEnforcerCachedRedis {
62
66
  driver: typeof CasbinEnforcerCachedDrivers.REDIS;
63
67
  options: {
@@ -68,6 +72,7 @@ export interface ICasbinEnforcerCachedRedis {
68
72
  }) => ValueOrPromise<string>;
69
73
  };
70
74
  }
75
+ /** Options of a Casbin enforcer: model source, policy cache, optional adapter, domain matching and enforcer pool sizing. */
71
76
  export interface ICasbinEnforcerOptions<E extends Env = Env, TAction = string, TResource = string, TAdapter = Adapter> {
72
77
  model: {
73
78
  driver: typeof CasbinEnforcerModelDrivers.FILE;
@@ -97,13 +102,26 @@ export interface ICasbinEnforcerOptions<E extends Env = Env, TAction = string, T
97
102
  action: string;
98
103
  domain?: string;
99
104
  };
100
- /** Domain-scoped RBAC model: requests become 4-token `(subject, domain, object, action)` and the enforcer registers the domain matcher (`keyMatch` on `g`) + resource matcher (`objectMatch`). A role assignment or grant declared at a parent domain (via a `g3` policy line, e.g. `Merchant_7 -> Organizer_3`) applies to every child domain - the adapter is what decides whether those edges exist. */
105
+ /**
106
+ * Domain-scoped RBAC model: requests become 4-token `(subject, domain, object, action)` and the enforcer registers the domain matcher (`keyMatch` on `g`) + resource matcher (`objectMatch`). A role assignment or grant declared at a parent domain (via a `g3` policy line, e.g. `Merchant_7 -> Organizer_3`) applies to every child domain - the adapter is what decides whether those edges exist.
107
+ *
108
+ * @default false
109
+ */
101
110
  isScoped?: boolean;
102
- /** Number of pooled enforcers (each request enforces on its own). Default 16. */
111
+ /**
112
+ * Number of pooled enforcers (each request enforces on its own).
113
+ *
114
+ * @default 16
115
+ */
103
116
  poolSize?: number;
104
- /** Max ms to wait for a free pooled enforcer before failing closed. Default 5000. */
117
+ /**
118
+ * Max ms to wait for a free pooled enforcer before failing closed.
119
+ *
120
+ * @default 5000
121
+ */
105
122
  poolAcquireTimeoutMs?: number;
106
123
  }
124
+ /** Application-wide authorize options. `defaultDecision` applies when an enforcer abstains and when no enforcer is registered (a `deny` default then fails the request). */
107
125
  export interface IAuthorizeOptions {
108
126
  defaultDecision: TAuthorizationDecision;
109
127
  alwaysAllowRoles?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"enforcer.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/types/enforcer.ts"],"names":[],"mappings":"","sourcesContent":["import type { TContext } from '@/base/controllers/common/types';\nimport { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { type IRedisHelper } from '@venizia/ignis-helpers/core';\nimport type { Adapter } from 'casbin';\nimport type { Env } from 'hono';\nimport { type MiddlewareHandler } from 'hono';\nimport type { IAuthUser } from '../../../authenticate/common/types';\nimport type {\n CasbinEnforcerCachedDrivers,\n CasbinEnforcerModelDrivers,\n TAuthorizationDecision,\n TCasbinDomainMatchingFunction,\n} from '../constants';\nimport type {\n IAuthorizationDomainSource,\n IAuthorizationRequest,\n IAuthorizationUser,\n TAuthorizationConditions,\n TAuthorizationDomainResolver,\n} from './request';\n\n/** What CasbinAuthorizationEnforcer.buildRules returns and evaluate consumes. */\nexport interface ICasbinRules {\n user: IAuthorizationUser;\n lines: string[];\n}\n\n/** Builds rules and evaluates requests. Cache management (`invalidateUserCache`/`rebuildUserCache`) is OPTIONAL - only on per-user-caching enforcers; the registry feature-detects it at runtime. */\nexport interface IAuthorizationEnforcer<\n E extends Env = Env,\n TAction = string,\n TResource = string,\n TRules = unknown,\n TBuildRulesReturn = ValueOrPromise<TRules>,\n TEvaluateReturn = ValueOrPromise<TAuthorizationDecision>,\n> {\n name: string;\n\n configure(): ValueOrPromise<void>;\n\n buildRules(opts: { user: IAuthorizationUser; context: TContext<E, string> }): TBuildRulesReturn;\n\n evaluate(opts: {\n rules: TRules;\n request: IAuthorizationRequest<TAction, TResource>;\n context: TContext<E, string>;\n }): TEvaluateReturn;\n\n /** Drop a user's cached policies. Implemented only by caching enforcers. */\n invalidateUserCache?(opts: { user: IAuthorizationUser }): Promise<{ invalidatedKeys: number }>;\n\n /** Drop + rebuild a user's cached policies. Implemented only by caching enforcers. */\n rebuildUserCache?(opts: {\n user: IAuthorizationUser;\n }): Promise<{ cacheKey: string; lineCount: number }>;\n}\n\nexport type TAuthorizationVoter<\n E extends Env = Env,\n TAction = string,\n TResource = string,\n> = (opts: {\n user: IAuthUser;\n action: TAction;\n resource: TResource;\n context: TContext<E, string>;\n}) => ValueOrPromise<TAuthorizationDecision>;\n\nexport interface IAuthorizationSpec<E extends Env = Env, TAction = string, TResource = string> {\n action: TAction;\n resource: TResource;\n conditions?: TAuthorizationConditions;\n allowedRoles?: string[];\n voters?: TAuthorizationVoter<E, TAction, TResource>[];\n /** Optional per-route domain: declarative source OR a resolver method. Omitted → global resolver. */\n domain?: IAuthorizationDomainSource | TAuthorizationDomainResolver<E>;\n}\n\nexport type TAuthorizeFn<E extends Env = Env, TAction = string, TResource = string> = (opts: {\n spec: IAuthorizationSpec<E, TAction, TResource>;\n enforcerName?: string;\n}) => MiddlewareHandler;\n\nexport interface ICasbinEnforcerCachedRedis {\n driver: typeof CasbinEnforcerCachedDrivers.REDIS;\n options: {\n connection: IRedisHelper;\n expiresIn: number;\n keyFn: (opts: { user: IAuthorizationUser }) => ValueOrPromise<string>;\n };\n}\n\nexport interface ICasbinEnforcerOptions<\n E extends Env = Env,\n TAction = string,\n TResource = string,\n TAdapter = Adapter,\n> {\n model:\n | { driver: typeof CasbinEnforcerModelDrivers.FILE; definition: string }\n | { driver: typeof CasbinEnforcerModelDrivers.TEXT; definition: string };\n cached: { use: false } | (ICasbinEnforcerCachedRedis & { use: true });\n adapter?: TAdapter;\n\n domainMatching?: {\n roleDefinition: string;\n fn: TCasbinDomainMatchingFunction;\n };\n\n normalizePayloadFn?(opts: {\n user: IAuthUser;\n action: TAction;\n resource: TResource;\n context: TContext<E, string>;\n }): {\n subject: string;\n resource: string;\n action: string;\n domain?: string;\n };\n\n /** Domain-scoped RBAC model: requests become 4-token `(subject, domain, object, action)` and the enforcer registers the domain matcher (`keyMatch` on `g`) + resource matcher (`objectMatch`). A role assignment or grant declared at a parent domain (via a `g3` policy line, e.g. `Merchant_7 -> Organizer_3`) applies to every child domain - the adapter is what decides whether those edges exist. */\n isScoped?: boolean;\n\n /** Number of pooled enforcers (each request enforces on its own). Default 16. */\n poolSize?: number;\n\n /** Max ms to wait for a free pooled enforcer before failing closed. Default 5000. */\n poolAcquireTimeoutMs?: number;\n}\n\nexport interface IAuthorizeOptions {\n defaultDecision: TAuthorizationDecision;\n alwaysAllowRoles?: string[];\n /** Fallback domain resolver used when a route's spec has no `domain`. */\n domainResolver?: TAuthorizationDomainResolver;\n}\n"]}
1
+ {"version":3,"file":"enforcer.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/types/enforcer.ts"],"names":[],"mappings":"","sourcesContent":["import type { TContext } from '@/base/controllers/common/types';\nimport { type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport { type IRedisHelper } from '@venizia/ignis-helpers/core';\nimport type { Adapter } from 'casbin';\nimport type { Env } from 'hono';\nimport { type MiddlewareHandler } from 'hono';\nimport type { IAuthUser } from '../../../authenticate/common/types';\nimport type {\n CasbinEnforcerCachedDrivers,\n CasbinEnforcerModelDrivers,\n TAuthorizationDecision,\n TCasbinDomainMatchingFunction,\n} from '../constants';\nimport type {\n IAuthorizationDomainSource,\n IAuthorizationRequest,\n IAuthorizationUser,\n TAuthorizationConditions,\n TAuthorizationDomainResolver,\n} from './request';\n\n/** What CasbinAuthorizationEnforcer.buildRules returns and evaluate consumes. */\nexport interface ICasbinRules {\n user: IAuthorizationUser;\n lines: string[];\n}\n\n/** Builds rules and evaluates requests. Cache management (`invalidateUserCache`/`rebuildUserCache`) is OPTIONAL - only on per-user-caching enforcers; the registry feature-detects it at runtime. */\nexport interface IAuthorizationEnforcer<\n E extends Env = Env,\n TAction = string,\n TResource = string,\n TRules = unknown,\n TBuildRulesReturn = ValueOrPromise<TRules>,\n TEvaluateReturn = ValueOrPromise<TAuthorizationDecision>,\n> {\n name: string;\n\n configure(): ValueOrPromise<void>;\n\n buildRules(opts: { user: IAuthorizationUser; context: TContext<E, string> }): TBuildRulesReturn;\n\n evaluate(opts: {\n rules: TRules;\n request: IAuthorizationRequest<TAction, TResource>;\n context: TContext<E, string>;\n }): TEvaluateReturn;\n\n /** Drop a user's cached policies. Implemented only by caching enforcers. */\n invalidateUserCache?(opts: { user: IAuthorizationUser }): Promise<{ invalidatedKeys: number }>;\n\n /** Drop + rebuild a user's cached policies. Implemented only by caching enforcers. */\n rebuildUserCache?(opts: {\n user: IAuthorizationUser;\n }): Promise<{ cacheKey: string; lineCount: number }>;\n}\n\n/** Per-route check run before the enforcer. `deny` rejects the request, `allow` accepts it without consulting the enforcer, `abstain` passes to the next voter and then the enforcer. */\nexport type TAuthorizationVoter<\n E extends Env = Env,\n TAction = string,\n TResource = string,\n> = (opts: {\n user: IAuthUser;\n action: TAction;\n resource: TResource;\n context: TContext<E, string>;\n}) => ValueOrPromise<TAuthorizationDecision>;\n\n/** Per-route authorization requirement passed to `authorize()`. `allowedRoles` grants access to matching roles before voters and the enforcer run. */\nexport interface IAuthorizationSpec<E extends Env = Env, TAction = string, TResource = string> {\n action: TAction;\n resource: TResource;\n conditions?: TAuthorizationConditions;\n allowedRoles?: string[];\n voters?: TAuthorizationVoter<E, TAction, TResource>[];\n /** Optional per-route domain: declarative source OR a resolver method. Omitted → global resolver. */\n domain?: IAuthorizationDomainSource | TAuthorizationDomainResolver<E>;\n}\n\n/** Factory that turns an `IAuthorizationSpec` (and optional enforcer name) into a Hono middleware. */\nexport type TAuthorizeFn<E extends Env = Env, TAction = string, TResource = string> = (opts: {\n spec: IAuthorizationSpec<E, TAction, TResource>;\n enforcerName?: string;\n}) => MiddlewareHandler;\n\n/** Redis cache for a Casbin enforcer's per-user policy lines. `keyFn` returns the cache key for a user and must not return an empty string. */\nexport interface ICasbinEnforcerCachedRedis {\n driver: typeof CasbinEnforcerCachedDrivers.REDIS;\n options: {\n connection: IRedisHelper;\n expiresIn: number;\n keyFn: (opts: { user: IAuthorizationUser }) => ValueOrPromise<string>;\n };\n}\n\n/** Options of a Casbin enforcer: model source, policy cache, optional adapter, domain matching and enforcer pool sizing. */\nexport interface ICasbinEnforcerOptions<\n E extends Env = Env,\n TAction = string,\n TResource = string,\n TAdapter = Adapter,\n> {\n model:\n | { driver: typeof CasbinEnforcerModelDrivers.FILE; definition: string }\n | { driver: typeof CasbinEnforcerModelDrivers.TEXT; definition: string };\n cached: { use: false } | (ICasbinEnforcerCachedRedis & { use: true });\n adapter?: TAdapter;\n\n domainMatching?: {\n roleDefinition: string;\n fn: TCasbinDomainMatchingFunction;\n };\n\n normalizePayloadFn?(opts: {\n user: IAuthUser;\n action: TAction;\n resource: TResource;\n context: TContext<E, string>;\n }): {\n subject: string;\n resource: string;\n action: string;\n domain?: string;\n };\n\n /**\n * Domain-scoped RBAC model: requests become 4-token `(subject, domain, object, action)` and the enforcer registers the domain matcher (`keyMatch` on `g`) + resource matcher (`objectMatch`). A role assignment or grant declared at a parent domain (via a `g3` policy line, e.g. `Merchant_7 -> Organizer_3`) applies to every child domain - the adapter is what decides whether those edges exist.\n *\n * @default false\n */\n isScoped?: boolean;\n\n /**\n * Number of pooled enforcers (each request enforces on its own).\n *\n * @default 16\n */\n poolSize?: number;\n\n /**\n * Max ms to wait for a free pooled enforcer before failing closed.\n *\n * @default 5000\n */\n poolAcquireTimeoutMs?: number;\n}\n\n/** Application-wide authorize options. `defaultDecision` applies when an enforcer abstains and when no enforcer is registered (a `deny` default then fails the request). */\nexport interface IAuthorizeOptions {\n defaultDecision: TAuthorizationDecision;\n alwaysAllowRoles?: string[];\n /** Fallback domain resolver used when a route's spec has no `domain`. */\n domainResolver?: TAuthorizationDomainResolver;\n}\n"]}
@@ -4,6 +4,7 @@ import type { TAuthorizationAction } from '../constants/index.js';
4
4
  export type TCustomGrantMetadata = {
5
5
  ops: string[];
6
6
  };
7
+ /** What a caller wants to grant: a whole `tier` action, or an explicit list of operation names (`ops`). */
7
8
  export type TGrantIntent = {
8
9
  tier: TAuthorizationAction;
9
10
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"grant.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/types/grant.ts"],"names":[],"mappings":"","sourcesContent":["import type { AuthorizationPolicyBuilder } from '../../builders/policy.builder';\nimport type { TAuthorizationAction } from '../constants';\n\n/** Shape of `PolicyDefinition.metadata` on a subset (\"custom\") grant. `ops` holds bare method names (e.g. `\"find\"`), not full permission codes. */\nexport type TCustomGrantMetadata = { ops: string[] };\n\nexport type TGrantIntent = { tier: TAuthorizationAction } | { ops: string[] };\n\n/** Per-operation rows carry `targetId` = the operation's code, not a database id; the consumer resolves codes to ids when persisting. */\nexport type TPlannedGrantRow = ReturnType<typeof AuthorizationPolicyBuilder.grant> & {\n metadata?: { ops: string[] };\n};\n"]}
1
+ {"version":3,"file":"grant.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/types/grant.ts"],"names":[],"mappings":"","sourcesContent":["import type { AuthorizationPolicyBuilder } from '../../builders/policy.builder';\nimport type { TAuthorizationAction } from '../constants';\n\n/** Shape of `PolicyDefinition.metadata` on a subset (\"custom\") grant. `ops` holds bare method names (e.g. `\"find\"`), not full permission codes. */\nexport type TCustomGrantMetadata = { ops: string[] };\n\n/** What a caller wants to grant: a whole `tier` action, or an explicit list of operation names (`ops`). */\nexport type TGrantIntent = { tier: TAuthorizationAction } | { ops: string[] };\n\n/** Per-operation rows carry `targetId` = the operation's code, not a database id; the consumer resolves codes to ids when persisting. */\nexport type TPlannedGrantRow = ReturnType<typeof AuthorizationPolicyBuilder.grant> & {\n metadata?: { ops: string[] };\n};\n"]}
@@ -4,6 +4,7 @@ import { type TNullable, type ValueOrPromise } from '@venizia/ignis-helpers/comm
4
4
  import type { Env } from 'hono';
5
5
  import type { IAuthUser } from '../../../authenticate/common/types/index.js';
6
6
  import type { TAuthorizationDomainSource } from '../constants/index.js';
7
+ /** A role with a numeric `priority` (higher outranks lower) and a string `identifier`. */
7
8
  export interface IAuthorizationRole {
8
9
  readonly name: string;
9
10
  readonly priority: number;
@@ -11,6 +12,7 @@ export interface IAuthorizationRole {
11
12
  }
12
13
  /** Key-value conditions for attribute-based access control. Values compared with strict equality. */
13
14
  export type TAuthorizationConditions<KeyType extends string | symbol = string | symbol, ValueType = string | number | boolean | null> = Record<KeyType, ValueType>;
15
+ /** What an enforcer evaluates: an action on a resource, with optional attribute conditions and domain. */
14
16
  export interface IAuthorizationRequest<TAction = string, TResource = string> {
15
17
  action: TAction;
16
18
  resource: TResource;
@@ -18,6 +20,7 @@ export interface IAuthorizationRequest<TAction = string, TResource = string> {
18
20
  /** Resolved domain scope for this request as a casbin domain string `"<DomainType>_<id>"` (e.g. `"Merchant_7"`), or the `"SYSTEM_WIDE"` sentinel to enforce across all domains. */
19
21
  domain?: string;
20
22
  }
23
+ /** An authenticated user whose `principalType` is set; enforcer-based authorization requires it. */
21
24
  export interface IAuthorizationUser extends IAuthUser {
22
25
  principalType: string;
23
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/types/request.ts"],"names":[],"mappings":"","sourcesContent":["import type { IdType } from '@/base';\nimport type { TContext } from '@/base/controllers/common/types';\nimport { type TNullable, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { Env } from 'hono';\nimport type { IAuthUser } from '../../../authenticate/common/types';\nimport type { TAuthorizationDomainSource } from '../constants';\n\nexport interface IAuthorizationRole {\n readonly name: string;\n readonly priority: number;\n readonly identifier: string;\n}\n\n/** Key-value conditions for attribute-based access control. Values compared with strict equality. */\nexport type TAuthorizationConditions<\n KeyType extends string | symbol = string | symbol,\n ValueType = string | number | boolean | null,\n> = Record<KeyType, ValueType>;\n\nexport interface IAuthorizationRequest<TAction = string, TResource = string> {\n action: TAction;\n resource: TResource;\n conditions?: TAuthorizationConditions;\n /** Resolved domain scope for this request as a casbin domain string `\"<DomainType>_<id>\"` (e.g. `\"Merchant_7\"`), or the `\"SYSTEM_WIDE\"` sentinel to enforce across all domains. */\n domain?: string;\n}\n\nexport interface IAuthorizationUser extends IAuthUser {\n principalType: string;\n}\n\n/** Declarative description of where to read the request domain from. */\nexport interface IAuthorizationDomainSource {\n from: TAuthorizationDomainSource;\n key: string;\n type: string; // domain type, e.g. 'Merchant' | 'Organizer'\n}\n\n/** Returns the current request domain; null = no domain (→ SYSTEM_WIDE). */\nexport type TAuthorizationDomainResolver<E extends Env = Env> = (opts: {\n context: TContext<E, string>;\n}) => ValueOrPromise<TNullable<{ type: string; id: IdType }>>;\n"]}
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../../../../../src/base/auth/authorize/common/types/request.ts"],"names":[],"mappings":"","sourcesContent":["import type { IdType } from '@/base';\nimport type { TContext } from '@/base/controllers/common/types';\nimport { type TNullable, type ValueOrPromise } from '@venizia/ignis-helpers/common';\nimport type { Env } from 'hono';\nimport type { IAuthUser } from '../../../authenticate/common/types';\nimport type { TAuthorizationDomainSource } from '../constants';\n\n/** A role with a numeric `priority` (higher outranks lower) and a string `identifier`. */\nexport interface IAuthorizationRole {\n readonly name: string;\n readonly priority: number;\n readonly identifier: string;\n}\n\n/** Key-value conditions for attribute-based access control. Values compared with strict equality. */\nexport type TAuthorizationConditions<\n KeyType extends string | symbol = string | symbol,\n ValueType = string | number | boolean | null,\n> = Record<KeyType, ValueType>;\n\n/** What an enforcer evaluates: an action on a resource, with optional attribute conditions and domain. */\nexport interface IAuthorizationRequest<TAction = string, TResource = string> {\n action: TAction;\n resource: TResource;\n conditions?: TAuthorizationConditions;\n /** Resolved domain scope for this request as a casbin domain string `\"<DomainType>_<id>\"` (e.g. `\"Merchant_7\"`), or the `\"SYSTEM_WIDE\"` sentinel to enforce across all domains. */\n domain?: string;\n}\n\n/** An authenticated user whose `principalType` is set; enforcer-based authorization requires it. */\nexport interface IAuthorizationUser extends IAuthUser {\n principalType: string;\n}\n\n/** Declarative description of where to read the request domain from. */\nexport interface IAuthorizationDomainSource {\n from: TAuthorizationDomainSource;\n key: string;\n type: string; // domain type, e.g. 'Merchant' | 'Organizer'\n}\n\n/** Returns the current request domain; null = no domain (→ SYSTEM_WIDE). */\nexport type TAuthorizationDomainResolver<E extends Env = Env> = (opts: {\n context: TContext<E, string>;\n}) => ValueOrPromise<TNullable<{ type: string; id: IdType }>>;\n"]}
@@ -3,6 +3,7 @@ import type { TClass } from '@venizia/ignis-helpers/common';
3
3
  import type { IAuthUser } from '../../authenticate/common/types/index.js';
4
4
  import { AbstractAuthRegistry } from '../../base/index.js';
5
5
  import type { AuthorizationEnforcerTypes, IAuthorizationEnforcer, IAuthorizationUser, IAuthorizeOptions, ICasbinEnforcerOptions } from '../common/index.js';
6
+ /** Singleton registry of named authorization enforcers. An enforcer is configured once, on first resolve; concurrent first resolves share one `configure()` call. */
6
7
  export declare class AuthorizationEnforcerRegistry extends AbstractAuthRegistry<IAuthorizationEnforcer> {
7
8
  static readonly SINGLETON_REAL_KEY = "authorization-enforcer-registry";
8
9
  private configuredEnforcers;
@@ -2,6 +2,7 @@ import { SingletonRealm } from '../../../../helpers/singleton-realm.js';
2
2
  import { getError } from '@venizia/ignis-helpers/core';
3
3
  import { AbstractAuthRegistry } from '../../base/index.js';
4
4
  import { Authorization, AuthorizeBindingKeys } from '../common/index.js';
5
+ /** Singleton registry of named authorization enforcers. An enforcer is configured once, on first resolve; concurrent first resolves share one `configure()` call. */
5
6
  export class AuthorizationEnforcerRegistry extends AbstractAuthRegistry {
6
7
  static { this.SINGLETON_REAL_KEY = 'authorization-enforcer-registry'; }
7
8
  constructor() {
@@ -1 +1 @@
1
- {"version":3,"file":"enforcer-registry.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/enforcers/enforcer-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAQlD,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEhE,MAAM,OAAO,6BAA8B,SAAQ,oBAA4C;aAC7E,uBAAkB,GAAG,iCAAiC,AAApC,CAAqC;IAWvE;QACE,KAAK,CAAC,EAAE,KAAK,EAAE,6BAA6B,CAAC,IAAI,EAAE,CAAC,CAAC;QALvD;iHACyG;QACjG,uBAAkB,GAAiC,IAAI,CAAC;QAI9D,IAAI,CAAC,mBAAmB,GAAG,IAAI,GAAG,EAAE,CAAC;QACrC,IAAI,CAAC,qBAAqB,GAAG,IAAI,GAAG,EAAE,CAAC;IACzC,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,OAAO,cAAc,CAAC,OAAO,CAAC;YAC5B,GAAG,EAAE,6BAA6B,CAAC,kBAAkB;YACrD,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,6BAA6B,EAAE;SAClD,CAAC,CAAC;IACL,CAAC;IAEQ,KAAK;QACZ,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;QACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;QACnC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC;IACjC,CAAC;IAES,gBAAgB;QACxB,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED,QAAQ,CAAC,IAgBR;QACC,MAAM,EA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AAO,CAAC;YACjB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC","sourcesContent":["import { SingletonRealm } from '@/helpers/singleton-realm';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { TClass, TNullable } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IAuthUser } from '../../authenticate/common/types';\nimport { AbstractAuthRegistry } from '../../base';\nimport type {\n AuthorizationEnforcerTypes,\n IAuthorizationEnforcer,\n IAuthorizationUser,\n IAuthorizeOptions,\n ICasbinEnforcerOptions,\n} from '../common';\nimport { Authorization, AuthorizeBindingKeys } from '../common';\n\nexport class AuthorizationEnforcerRegistry extends AbstractAuthRegistry<IAuthorizationEnforcer> {\n static readonly SINGLETON_REAL_KEY = 'authorization-enforcer-registry';\n\n private configuredEnforcers: Set<string>;\n\n /** In-flight `configure()` calls, so concurrent first requests share one warmup instead of racing. */\n private pendingConfigurations: Map<string, Promise<void>>;\n\n /** Set by AuthorizeComponent from the application container. Held here because the descriptor scan\n * below sees only registered enforcers, and `defaultDecision` has to be readable when there are none. */\n private applicationOptions: TNullable<IAuthorizeOptions> = null;\n\n constructor() {\n super({ scope: AuthorizationEnforcerRegistry.name });\n this.configuredEnforcers = new Set();\n this.pendingConfigurations = new Map();\n }\n\n static getInstance() {\n return SingletonRealm.resolve({\n key: AuthorizationEnforcerRegistry.SINGLETON_REAL_KEY,\n create: () => new AuthorizationEnforcerRegistry(),\n });\n }\n\n override reset(): void {\n super.reset();\n this.configuredEnforcers.clear();\n this.pendingConfigurations.clear();\n this.applicationOptions = null;\n }\n\n protected getBindingPrefix(): string {\n return Authorization.ENFORCER;\n }\n\n register(opts: {\n container: Container;\n enforcers: Array<\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CASBIN;\n options?: ICasbinEnforcerOptions;\n }\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CUSTOM;\n options?: unknown;\n }\n >;\n }) {\n const { container, enforcers } = opts;\n\n const names = enforcers.map((e) => e.name);\n const duplicateNames = names.filter((n, i) => names.indexOf(n) !== i);\n\n if (duplicateNames.length) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Duplicate enforcer name(s): ${[...new Set(duplicateNames)].join(', ')}`,\n });\n }\n\n for (const { enforcer, name, options } of enforcers) {\n if (this.descriptors.has(name)) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer already registered: ${name}`,\n });\n }\n\n this.registerDescriptor({ container, target: enforcer, name });\n\n if (options) {\n container.bind({ key: AuthorizeBindingKeys.enforcerOptions(name) }).toValue(options);\n }\n }\n\n return this;\n }\n\n hasEnforcers(): boolean {\n return this.descriptors.size > 0;\n }\n\n getDefaultEnforcerName(): string {\n return this.getDefaultName();\n }\n\n /**\n * The PROMISE is memoised, not just the completed flag.\n *\n * `configure()` yields (it dynamic-imports casbin), and the flag was only set after the await -\n * so a burst of first requests each saw an unconfigured enforcer and each built a full pool.\n * Measured: 40 concurrent first requests produced 40 configure() calls and 640 enforcers.\n * The entry is dropped on rejection so a failed warmup does not poison every later request.\n */\n async resolveEnforcer(opts: { name: string }): Promise<IAuthorizationEnforcer> {\n const enforcer = this.resolveDescriptor(opts);\n\n if (this.configuredEnforcers.has(opts.name)) {\n return enforcer;\n }\n\n const inFlight = this.pendingConfigurations.get(opts.name);\n\n if (inFlight) {\n await inFlight;\n\n return enforcer;\n }\n\n // `Promise.resolve` because `configure()` is declared `ValueOrPromise<void>` - a synchronous\n // implementation returns plain `void`, which has no `.then`.\n const pending = Promise.resolve(enforcer.configure())\n .then(() => {\n this.configuredEnforcers.add(opts.name);\n })\n .finally(() => {\n this.pendingConfigurations.delete(opts.name);\n });\n\n this.pendingConfigurations.set(opts.name, pending);\n\n await pending;\n\n return enforcer;\n }\n\n /** Drop a user's cached policies on the resolved enforcer. Lazy - next request rebuilds. */\n async invalidateUserCache(opts: {\n user: IAuthorizationUser;\n enforcerName?: string;\n }): Promise<{ invalidatedKeys: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n // Cache management is an optional IAuthorizationEnforcer capability - feature-detect it.\n if (typeof enforcer.invalidateUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.invalidateUserCache({ user: opts.user });\n }\n\n /** Drop then immediately rebuild + re-cache a user's policies on the resolved enforcer. */\n async rebuildUserCache(opts: {\n user: { principalType: string } & IAuthUser;\n enforcerName?: string;\n }): Promise<{ cacheKey: string; lineCount: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n if (typeof enforcer.rebuildUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.rebuildUserCache({ user: opts.user });\n }\n\n /** Options bound on the application, independent of any enforcer. */\n setOptions(opts: { options: IAuthorizeOptions }): void {\n this.applicationOptions = opts.options;\n }\n\n resolveOptions(): IAuthorizeOptions | undefined {\n if (this.applicationOptions) {\n return this.applicationOptions;\n }\n\n for (const [, metadata] of this.descriptors) {\n const { container } = metadata;\n const options = container.get<IAuthorizeOptions>({\n key: AuthorizeBindingKeys.OPTIONS,\n isOptional: true,\n });\n\n if (options) {\n return options;\n }\n }\n\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"enforcer-registry.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/enforcers/enforcer-registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAQlD,OAAO,EAAE,aAAa,EAAE,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,CAAC;QAChE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAEtD,IAAI,OAAO,QAAQ,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;YACpD,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,6CAA6C,IAAI,uCAAuC;aAClG,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,qEAAqE;IACrE,UAAU,CAAC,IAAoC;QAC7C,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,OAAO,CAAC;IACzC,CAAC;IAED,cAAc;QACZ,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,kBAAkB,CAAC;QACjC,CAAC;QAED,KAAK,MAAM,CAAC,EAAE,QAAQ,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC;YAC/B,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAoB;gBAC/C,GAAG,EAAE,oBAAoB,CAAC,OAAO;gBACjC,UAAU,EAAE,IAAI;aACjB,CAAC,CAAC;YAEH,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,OAAO,CAAC;YACjB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC","sourcesContent":["import { SingletonRealm } from '@/helpers/singleton-realm';\nimport type { Container } from '@/helpers/inversion/container';\nimport type { TClass, TNullable } from '@venizia/ignis-helpers/common';\nimport { getError } from '@venizia/ignis-helpers/core';\nimport type { IAuthUser } from '../../authenticate/common/types';\nimport { AbstractAuthRegistry } from '../../base';\nimport type {\n AuthorizationEnforcerTypes,\n IAuthorizationEnforcer,\n IAuthorizationUser,\n IAuthorizeOptions,\n ICasbinEnforcerOptions,\n} from '../common';\nimport { Authorization, AuthorizeBindingKeys } from '../common';\n\n/** Singleton registry of named authorization enforcers. An enforcer is configured once, on first resolve; concurrent first resolves share one `configure()` call. */\nexport class AuthorizationEnforcerRegistry extends AbstractAuthRegistry<IAuthorizationEnforcer> {\n static readonly SINGLETON_REAL_KEY = 'authorization-enforcer-registry';\n\n private configuredEnforcers: Set<string>;\n\n /** In-flight `configure()` calls, so concurrent first requests share one warmup instead of racing. */\n private pendingConfigurations: Map<string, Promise<void>>;\n\n /** Set by AuthorizeComponent from the application container. Held here because the descriptor scan\n * below sees only registered enforcers, and `defaultDecision` has to be readable when there are none. */\n private applicationOptions: TNullable<IAuthorizeOptions> = null;\n\n constructor() {\n super({ scope: AuthorizationEnforcerRegistry.name });\n this.configuredEnforcers = new Set();\n this.pendingConfigurations = new Map();\n }\n\n static getInstance() {\n return SingletonRealm.resolve({\n key: AuthorizationEnforcerRegistry.SINGLETON_REAL_KEY,\n create: () => new AuthorizationEnforcerRegistry(),\n });\n }\n\n override reset(): void {\n super.reset();\n this.configuredEnforcers.clear();\n this.pendingConfigurations.clear();\n this.applicationOptions = null;\n }\n\n protected getBindingPrefix(): string {\n return Authorization.ENFORCER;\n }\n\n register(opts: {\n container: Container;\n enforcers: Array<\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CASBIN;\n options?: ICasbinEnforcerOptions;\n }\n | {\n enforcer: TClass<IAuthorizationEnforcer>;\n name: string;\n type: typeof AuthorizationEnforcerTypes.CUSTOM;\n options?: unknown;\n }\n >;\n }) {\n const { container, enforcers } = opts;\n\n const names = enforcers.map((e) => e.name);\n const duplicateNames = names.filter((n, i) => names.indexOf(n) !== i);\n\n if (duplicateNames.length) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Duplicate enforcer name(s): ${[...new Set(duplicateNames)].join(', ')}`,\n });\n }\n\n for (const { enforcer, name, options } of enforcers) {\n if (this.descriptors.has(name)) {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer already registered: ${name}`,\n });\n }\n\n this.registerDescriptor({ container, target: enforcer, name });\n\n if (options) {\n container.bind({ key: AuthorizeBindingKeys.enforcerOptions(name) }).toValue(options);\n }\n }\n\n return this;\n }\n\n hasEnforcers(): boolean {\n return this.descriptors.size > 0;\n }\n\n getDefaultEnforcerName(): string {\n return this.getDefaultName();\n }\n\n /**\n * The PROMISE is memoised, not just the completed flag.\n *\n * `configure()` yields (it dynamic-imports casbin), and the flag was only set after the await -\n * so a burst of first requests each saw an unconfigured enforcer and each built a full pool.\n * Measured: 40 concurrent first requests produced 40 configure() calls and 640 enforcers.\n * The entry is dropped on rejection so a failed warmup does not poison every later request.\n */\n async resolveEnforcer(opts: { name: string }): Promise<IAuthorizationEnforcer> {\n const enforcer = this.resolveDescriptor(opts);\n\n if (this.configuredEnforcers.has(opts.name)) {\n return enforcer;\n }\n\n const inFlight = this.pendingConfigurations.get(opts.name);\n\n if (inFlight) {\n await inFlight;\n\n return enforcer;\n }\n\n // `Promise.resolve` because `configure()` is declared `ValueOrPromise<void>` - a synchronous\n // implementation returns plain `void`, which has no `.then`.\n const pending = Promise.resolve(enforcer.configure())\n .then(() => {\n this.configuredEnforcers.add(opts.name);\n })\n .finally(() => {\n this.pendingConfigurations.delete(opts.name);\n });\n\n this.pendingConfigurations.set(opts.name, pending);\n\n await pending;\n\n return enforcer;\n }\n\n /** Drop a user's cached policies on the resolved enforcer. Lazy - next request rebuilds. */\n async invalidateUserCache(opts: {\n user: IAuthorizationUser;\n enforcerName?: string;\n }): Promise<{ invalidatedKeys: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n // Cache management is an optional IAuthorizationEnforcer capability - feature-detect it.\n if (typeof enforcer.invalidateUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.invalidateUserCache({ user: opts.user });\n }\n\n /** Drop then immediately rebuild + re-cache a user's policies on the resolved enforcer. */\n async rebuildUserCache(opts: {\n user: { principalType: string } & IAuthUser;\n enforcerName?: string;\n }): Promise<{ cacheKey: string; lineCount: number }> {\n const name = opts.enforcerName ?? this.getDefaultEnforcerName();\n const enforcer = await this.resolveEnforcer({ name });\n\n if (typeof enforcer.rebuildUserCache !== 'function') {\n throw getError({\n message: `[AuthorizationEnforcerRegistry] Enforcer \"${name}\" does not support cache invalidation`,\n });\n }\n\n return enforcer.rebuildUserCache({ user: opts.user });\n }\n\n /** Options bound on the application, independent of any enforcer. */\n setOptions(opts: { options: IAuthorizeOptions }): void {\n this.applicationOptions = opts.options;\n }\n\n resolveOptions(): IAuthorizeOptions | undefined {\n if (this.applicationOptions) {\n return this.applicationOptions;\n }\n\n for (const [, metadata] of this.descriptors) {\n const { container } = metadata;\n const options = container.get<IAuthorizeOptions>({\n key: AuthorizeBindingKeys.OPTIONS,\n isOptional: true,\n });\n\n if (options) {\n return options;\n }\n }\n\n return undefined;\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { IAuthorizationSpec } from '../common/index.js';
2
+ /** Builds the authorization middleware for a route from an `IAuthorizationSpec`; `enforcerName` selects a registered enforcer, else the default one is used. */
2
3
  export declare const authorize: (opts: {
3
4
  spec: IAuthorizationSpec;
4
5
  enforcerName?: string;
@@ -1,6 +1,7 @@
1
1
  import { AuthorizationProvider } from '../providers/index.js';
2
2
  const authorizationProvider = new AuthorizationProvider();
3
3
  const authorizeFn = authorizationProvider.value();
4
+ /** Builds the authorization middleware for a route from an `IAuthorizationSpec`; `enforcerName` selects a registered enforcer, else the default one is used. */
4
5
  export const authorize = (opts) => {
5
6
  return authorizeFn(opts);
6
7
  };
@@ -1 +1 @@
1
- {"version":3,"file":"authorize.middleware.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/middlewares/authorize.middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAC1D,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,EAAE,CAAC;AAElD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAyD,EAAE,EAAE;IACrF,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import type { IAuthorizationSpec } from '../common';\nimport { AuthorizationProvider } from '../providers';\n\nconst authorizationProvider = new AuthorizationProvider();\nconst authorizeFn = authorizationProvider.value();\n\nexport const authorize = (opts: { spec: IAuthorizationSpec; enforcerName?: string }) => {\n return authorizeFn(opts);\n};\n"]}
1
+ {"version":3,"file":"authorize.middleware.js","sourceRoot":"","sources":["../../../../../../src/base/auth/authorize/middlewares/authorize.middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,qBAAqB,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAC1D,MAAM,WAAW,GAAG,qBAAqB,CAAC,KAAK,EAAE,CAAC;AAElD,gKAAgK;AAChK,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAyD,EAAE,EAAE;IACrF,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import type { IAuthorizationSpec } from '../common';\nimport { AuthorizationProvider } from '../providers';\n\nconst authorizationProvider = new AuthorizationProvider();\nconst authorizeFn = authorizationProvider.value();\n\n/** Builds the authorization middleware for a route from an `IAuthorizationSpec`; `enforcerName` selects a registered enforcer, else the default one is used. */\nexport const authorize = (opts: { spec: IAuthorizationSpec; enforcerName?: string }) => {\n return authorizeFn(opts);\n};\n"]}