@dudousxd/nestjs-authz 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-authz",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Extras on top of @nestjs/authorization: persisted RBAC policies, @Can helpers (byId, roles, permission), a Gate with batch checks and ad-hoc gates, super-admin, query scoping.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -81,7 +81,7 @@
81
81
  "@nestjs/testing": "12.0.1",
82
82
  "@tanstack/intent": "0.4.0",
83
83
  "@types/express": "4.17.25",
84
- "@types/node": "22.20.5",
84
+ "@types/node": "24.19.2",
85
85
  "@types/supertest": "6.0.3",
86
86
  "express": "4.22.2",
87
87
  "reflect-metadata": "0.2.2",
@@ -91,7 +91,7 @@
91
91
  "vitest": "3.2.7"
92
92
  },
93
93
  "engines": {
94
- "node": ">=22"
94
+ "node": ">=24"
95
95
  },
96
96
  "scripts": {
97
97
  "build": "tsc -p tsconfig.json --incremental false",
@@ -85,6 +85,22 @@ with its links and assignments, `listRoleAssignments({ tenantId?, role?, user?,
85
85
  raw `{ userType, userId, role, source, tenantId }` rows (`tenantId: null` = global only, a string =
86
86
  that tenant's scoped rows only), and `removeUser(user)` drops all of a user's assignments.
87
87
 
88
+ Tenant scope: role assignments can be global or per tenant (`assignRole(user, role, { tenantId })`;
89
+ MikroORM needs `createAuthzEntitySchemas({}, { tenantScoped: true })`, Prisma a `tenantId` column
90
+ plus `tenantScoped: true`). Each `AuthzRbacModule` picks the tenant of a check: a scope
91
+ forced by `runInTenantScope` (the dev tools) first; then its `tenant`
92
+ resolver (`(user) => id | null | undefined`); then, with tenancy on (`tenancy: 'inherit'`
93
+ follows `ContextModule.forRoot({ tenancy: { enabled: true } })`; `false` opts out), the context
94
+ tenant from `Context.setTenant`; with tenancy off, TypeORM/Drizzle read `Context.tenantId()` and
95
+ MikroORM/Prisma check global assignments only. With nested tenants, assignments held at every
96
+ level of the active chain the module honours apply (`tenancy.kinds`, else the context's `kinds`;
97
+ `tenancy.family` narrows to one family). `tenancy: { roles: { owner: 'org_admin' } }` maps
98
+ the caller's `tenant.role` at each honoured level to authz roles (context user only). No tenant
99
+ (`tenantless`) or no request = global assignments only, unless `tenancy.required` (default: the
100
+ context's) is set — then a check with no tenant throws `TenantRequiredError` (403,
101
+ `E_TENANT_REQUIRED`). `all`/`system` (`Context.allTenants()` and siblings) stay global even
102
+ when required.
103
+
88
104
  ## Core patterns
89
105
 
90
106
  ### A hand-rolled PermissionProvider
@@ -28,7 +28,7 @@ frontend glue. It never authenticates.
28
28
  pnpm add @nestjs/authorization @dudousxd/nestjs-authz
29
29
  ```
30
30
 
31
- NestJS 12, Node 22+. Peers: `@nestjs/common`, `@nestjs/core`, `@nestjs/authorization`,
31
+ NestJS 12, Node 24+. Peers: `@nestjs/common`, `@nestjs/core`, `@nestjs/authorization`,
32
32
  `reflect-metadata`, `rxjs`; optional `@nestjs/authentication` and `@dudousxd/nestjs-context`.
33
33
 
34
34
  ```ts