@dudousxd/nestjs-authz-drizzle 0.2.1 → 0.4.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/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # @dudousxd/nestjs-authz-drizzle
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Back on the 0.x line. The 1.x and 2.x versions were published by accident: a release-tooling peer cascade bumped this package to a major, not an API decision. 0.4.0 contains everything those versions shipped (console `authorize` support, tenancy, Node 24+ `engines`) with no other change. Upgrade from 1.x/2.x to 0.4.0; those versions are deprecated.
8
+
9
+ ## 2.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - [#74](https://github.com/DavideCarvalho/nestjs-authz/pull/74) [`35421dc`](https://github.com/DavideCarvalho/nestjs-authz/commit/35421dc5b09bd271d5087d26e8536191ef6ba342) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - **Breaking:** require Node.js 24 or newer (`engines.node` is now `>=24`; it was `>=22`, and `>=20` for `-client` and `-react`). CI tests on Node 24 and 26. No API changes: see the Upgrading page in the docs.
14
+
15
+ ## 1.1.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [#72](https://github.com/DavideCarvalho/nestjs-authz/pull/72) [`58a5d72`](https://github.com/DavideCarvalho/nestjs-authz/commit/58a5d72d2964a7cfae9cbfe8506526c8518ba30a) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Tenancy for the RBAC modules, following the `@dudousxd/nestjs-context` tenancy switch.
20
+
21
+ - New `tenancy` option (`'inherit' | false | { enabled?, kinds?, nullRows?, roles? }`, default `'inherit'`). With context tenancy on, permission and role checks are scoped to the request's tenant from `Context.setTenant`. A request with no tenant, inside `Context.allTenants()`, or outside a request sees global assignments only. `kinds` limits the tenant kinds this module honours. With tenancy off nothing changes.
22
+ - `tenancy.roles` maps the caller's role inside the tenant (`tenant.role`) to authz roles that apply in that tenant only, e.g. `{ owner: 'org_admin' }`.
23
+ - New `tenant` resolver option, `(user) => tenantId | null | undefined`: an explicit tenant that wins over the context.
24
+ - MikroORM and Prisma can now store tenant-scoped role assignments like Drizzle and TypeORM: `assignRole`, `removeRole` and `setUserRoles` take `{ tenantId }`, and the read methods take a tenant scope. MikroORM: build the entities with `createAuthzEntitySchemas({}, { tenantScoped: true })`. Prisma: add `tenantId String @default("")` to `UserRole` and its `@@id`, then pass `tenantScoped: true`. Without that, every assignment stays global.
25
+
26
+ ## 1.0.0
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [[`750a6b3`](https://github.com/DavideCarvalho/nestjs-authz/commit/750a6b3f80deea3803dec8df5f9f8cf67a046ac1)]:
31
+ - @dudousxd/nestjs-authz@0.10.0
32
+
33
+ ## 0.3.0
34
+
35
+ ### Minor Changes
36
+
37
+ - [#67](https://github.com/DavideCarvalho/nestjs-authz/pull/67) [`32e967f`](https://github.com/DavideCarvalho/nestjs-authz/commit/32e967ffbcd68a97e8effc77af9c16bbbafdc918) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Run on `@dudousxd/nestjs-authz` 0.9 and `@nestjs/authorization`: persisted roles and
38
+ permissions now guard routes through the official guard as the core's `RolePolicy` /
39
+ `PermissionPolicy` (`@Roles('editor')`, `@Permission('posts.publish')`), and the guard and the
40
+ handler's `Gate` calls share one permission and role fetch per request. The store API
41
+ (role sources, admin management, tenant-scoped roles where supported) and `AuthzRbacModule`
42
+ are unchanged. A persisted permission named like a policy ability no longer bypasses that
43
+ policy (see the core changeset). Requires NestJS 12, `@nestjs/authorization` ^0.1.3 and Node 22+.
44
+
45
+ - [#67](https://github.com/DavideCarvalho/nestjs-authz/pull/67) [`32e967f`](https://github.com/DavideCarvalho/nestjs-authz/commit/32e967ffbcd68a97e8effc77af9c16bbbafdc918) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - `AuthzRbacModule.forRoot({ connectionName, storeOptions })` (and `forRootAsync({ connectionName, storeOptions, useFactory })`) builds the store from a connection registered with NestJS's `@nestjs/drizzle` / `@nestjs/typeorm`, injecting `getDrizzleToken(connectionName)` / `getDataSourceToken(connectionName)` (`'default'` for the default connection). Both are optional peers. Passing a `store` you built yourself works as before. `AuthzRbacModuleOptions` is now a union of the two forms, and `AuthzRbacModuleAsyncOptions` takes `connectionName` next to `useFactory`.
46
+
47
+ ### Patch Changes
48
+
49
+ - [#67](https://github.com/DavideCarvalho/nestjs-authz/pull/67) [`32e967f`](https://github.com/DavideCarvalho/nestjs-authz/commit/32e967ffbcd68a97e8effc77af9c16bbbafdc918) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Fix packages that could be published without files their `exports` point to. `tsc` builds no longer use a `.tsbuildinfo` that can outlive `dist/` and skip emitting files. A new `check:exports` step (also `prepack`) fails the release if any `exports`/`main`/`types` path is missing.
50
+
3
51
  ## 0.2.1
4
52
 
5
53
  ### Patch Changes
package/README.md CHANGED
@@ -6,7 +6,8 @@
6
6
  - **Query scopes** — compile `gate.scope(Entity)` into a Drizzle `WHERE` (`compileScope` /
7
7
  `applyScope`), so list endpoints filter at the database instead of over-fetching.
8
8
  - **RBAC persistence** — roles, permissions, tenant-scoped role assignments and direct user
9
- permissions, plus the `AuthzRbacModule` Gate seam. Your app owns the Drizzle database; this
9
+ permissions for the official `@nestjs/authorization` policies (the core's `RolePolicy` /
10
+ `PermissionPolicy`) and the `Gate`, through `AuthzRbacModule`. Your app owns the Drizzle database; this
10
11
  package never opens a connection.
11
12
 
12
13
  It's the Drizzle version of `@dudousxd/nestjs-authz-typeorm`. The store surface and
@@ -16,9 +17,10 @@ between adapters leaves your data where it is.
16
17
  ## Install
17
18
 
18
19
  ```bash
19
- pnpm add @dudousxd/nestjs-authz-drizzle @dudousxd/nestjs-authz drizzle-orm
20
+ pnpm add @dudousxd/nestjs-authz-drizzle @dudousxd/nestjs-authz @nestjs/authorization drizzle-orm
20
21
  ```
21
22
 
23
+ Requires NestJS 12, `@nestjs/authorization` ^0.1.3, `@dudousxd/nestjs-authz` 0.10+ and Node 24+.
22
24
  `drizzle-orm` is a peer (`>=0.40.0 <1.0.0`). Any Drizzle Postgres driver works:
23
25
  `node-postgres`, `postgres-js`, PGlite, Neon, and so on.
24
26
 
@@ -27,9 +29,11 @@ pnpm add @dudousxd/nestjs-authz-drizzle @dudousxd/nestjs-authz drizzle-orm
27
29
  Write a policy `scope` with the ORM-neutral builders from the core:
28
30
 
29
31
  ```ts
30
- import { Policy, eq, or, type ScopeConstraint } from '@dudousxd/nestjs-authz';
32
+ import { Policy } from '@nestjs/authorization';
33
+ import { PolicyFor, eq, or, type ScopeConstraint } from '@dudousxd/nestjs-authz';
31
34
 
32
- @Policy(Post)
35
+ @Policy()
36
+ @PolicyFor(Post)
33
37
  export class PostPolicy {
34
38
  scope(user: User): ScopeConstraint {
35
39
  return or(eq('authorId', user.id), eq('published', true));
@@ -44,7 +48,7 @@ import { applyScope, compileScope } from '@dudousxd/nestjs-authz-drizzle';
44
48
  import { and, eq } from 'drizzle-orm';
45
49
  import { posts } from './db/schema';
46
50
 
47
- const scope = await applyScope(gate, Post, posts); // = compileScope(await gate.scope(Post), posts)
51
+ const scope = await applyScope(gate.forUser(user), Post, posts); // = compileScope(await gate.forUser(user).scope(Post), posts)
48
52
  const rows = await db.select().from(posts).where(and(scope, eq(posts.archived, false)));
49
53
  ```
50
54
 
@@ -53,13 +57,37 @@ const rows = await db.select().from(posts).where(and(scope, eq(posts.archived, f
53
57
  the SQL.
54
58
  - To allowlist columns explicitly, or to scope over a JOIN, pass a column map instead of a
55
59
  table: `compileScope(constraint, { authorId: posts.authorId, orgId: orgs.id })`.
56
- - `allow-all` (super-admin, `before` grant, permission-provider grant) returns `undefined`.
60
+ - `allow-all` (super-admin, `before` grant, or a permission grant for an entity whose policy
61
+ has no scope method) returns `undefined`.
57
62
  Both `.where()` and `and()` ignore it, so no predicate is added. `deny-all` becomes `1 = 0`.
58
63
  - Values always go through Drizzle's operators. They're bound as parameters and mapped by the
59
64
  column (for example, a `Date` becomes a timestamp).
60
65
 
61
66
  ## RBAC store
62
67
 
68
+ With the database registered through NestJS's [`@nestjs/drizzle`](https://docs.nestjs.com/data/drizzle),
69
+ name the connection and the module builds the store from `getDrizzleToken(connectionName)`:
70
+
71
+ ```ts
72
+ import { DrizzleModule } from '@nestjs/drizzle';
73
+ import { AuthzRbacModule } from '@dudousxd/nestjs-authz-drizzle';
74
+
75
+ @Module({
76
+ imports: [
77
+ DrizzleModule.forRoot({ drizzle, connection: process.env.DATABASE_URL }),
78
+ AuthzRbacModule.forRoot({
79
+ connectionName: 'default', // or the `name` given to DrizzleModule
80
+ storeOptions: { schema: 'auth' }, // optional: DrizzleAuthzStore options
81
+ }),
82
+ ],
83
+ })
84
+ export class AppModule {}
85
+ ```
86
+
87
+ `forRootAsync({ connectionName, storeOptions, useFactory })` works the same way, its factory
88
+ returning the other options. `@nestjs/drizzle` is an optional peer. Or build the store yourself
89
+ from any Drizzle database:
90
+
63
91
  ```ts
64
92
  import { AuthzRbacModule, DrizzleAuthzStore } from '@dudousxd/nestjs-authz-drizzle';
65
93
 
@@ -75,19 +103,58 @@ export class AppModule {}
75
103
  ```
76
104
 
77
105
  ```ts
78
- await store.givePermissionToRole('editor', 'posts.publish');
106
+ await store.givePermissionToRole('editor', 'posts.*');
79
107
  await store.assignRole({ type: 'user', id: 7 }, 'editor'); // global
80
108
  await store.assignRole({ type: 'user', id: 7 }, 'admin', { tenantId: 'acme' }); // tenant-scoped
81
109
  await store.giveUserPermission(7, 'reports.export'); // direct grant
110
+ ```
82
111
 
83
- gate.forUser(user).allows('posts.publish'); // true (PERMISSION_PROVIDER seam, wildcards supported)
84
- gate.forUser(user).hasRole('editor'); // true (ROLE_PROVIDER seam)
112
+ Persisted roles and permissions then guard routes through the official guard:
113
+
114
+ ```ts
115
+ @Permission('posts.publish') // posts.* grants it
116
+ @Can(PermissionPolicy, 'has', permission('posts.publish')) // the same, spelled out
117
+ @Roles('editor') // @Can(RolePolicy, 'has', roles('editor'))
118
+ ```
119
+
120
+ and services, through the `Gate`:
121
+
122
+ ```ts
123
+ gate.forUser(user).allows('posts.publish'); // true (PERMISSION_PROVIDER seam)
124
+ gate.forUser(user).allows(PermissionPolicy, 'has', 'posts.publish');
125
+ gate.forUser(user).hasRole('editor'); // true (ROLE_PROVIDER seam)
85
126
  ```
86
127
 
128
+ The user is the one the official guard reads (`AuthorizationModule.forRoot({ getUser })`,
129
+ default `request.user`), mapped to a store ref with `userRefFrom` (default `{ type, id }` or
130
+ `{ id }`). Within one request, the guard and the handler's `Gate` calls share one permission
131
+ and one role query per user. A permission never bypasses a policy that defines the ability:
132
+ `gate.allows('update', post)` is `PostPolicy`'s to decide.
133
+
87
134
  With `@dudousxd/nestjs-context` installed, the module reads the current tenant from the context
88
135
  accessor. A tenant-scoped role then grants only inside its own tenant. Global roles and direct
89
136
  grants apply everywhere.
90
137
 
138
+ With tenancy on (`ContextModule.forRoot({ tenancy: { enabled: true } })` in
139
+ `@dudousxd/nestjs-context`), checks are scoped to the request's tenant from `Context.setTenant(...)`.
140
+ A request with no tenant, or inside `Context.allTenants()`, sees global assignments only.
141
+
142
+ ```ts
143
+ AuthzRbacModule.forRoot({
144
+ connectionName: 'default',
145
+ tenancy: {
146
+ kinds: ['organization'], // optional: tenant kinds this module honours
147
+ roles: { owner: 'org_admin', member: 'org_member' }, // optional: tenant.role → authz roles in that tenant
148
+ },
149
+ tenant: (user) => (user as { orgId?: string }).orgId, // optional: an explicit tenant wins over the context
150
+ });
151
+ ```
152
+
153
+ `tenancy` defaults to `'inherit'` (follow the context switch); `false` keeps this module out.
154
+ Roles mapped with `roles` apply only inside that tenant and only to the context's current user.
155
+ The `tenant` resolver returns a tenant id, `null` for the global scope, or `undefined` to fall
156
+ back to the context.
157
+
91
158
  To run the store inside your own transaction, use `store.withDb(tx)`.
92
159
 
93
160
  ## Schema
@@ -1,6 +1,8 @@
1
1
  import type { UserRef } from '@dudousxd/nestjs-authz/store-kit';
2
2
  import { type DynamicModule } from '@nestjs/common';
3
- import type { DrizzleAuthzStore } from './drizzle-authz.store.js';
3
+ import { DrizzleAuthzStore } from './drizzle-authz.store.js';
4
+ import { type AuthzTenancyOption, type TenantResolver } from './tenancy.js';
5
+ import type { AuthzStoreOptions } from './types.js';
4
6
  /** Injection token holding the {@link DrizzleAuthzStore} the RBAC module manages. */
5
7
  export declare const AUTHZ_RBAC_STORE: unique symbol;
6
8
  /** Injection token holding the resolved {@link AuthzRbacModuleOptions}. */
@@ -10,9 +12,7 @@ export declare const AUTHZ_RBAC_OPTIONS: unique symbol;
10
12
  * {@link UserRef} the store can key on. Defaults to reading `{ type, id }` / `{ id }`.
11
13
  */
12
14
  export type UserRefMapper = (user: unknown) => UserRef | undefined;
13
- export interface AuthzRbacModuleOptions {
14
- /** The Drizzle RBAC store (built with the app-provided Drizzle database). */
15
- store: DrizzleAuthzStore;
15
+ export interface AuthzRbacModuleBaseOptions {
16
16
  /**
17
17
  * Run the store's `ensureSchema` (`CREATE ... IF NOT EXISTS`, non-destructive) on bootstrap.
18
18
  * Default `false`: with Drizzle the schema is normally owned by drizzle-kit — spread the
@@ -24,20 +24,58 @@ export interface AuthzRbacModuleOptions {
24
24
  * {@link defaultUserRefMapper} (`{ type, id }` or `{ id }`).
25
25
  */
26
26
  userRefFrom?: UserRefMapper;
27
+ /**
28
+ * Tenancy, from `@dudousxd/nestjs-context`. `'inherit'` (default) follows `ContextModule`'s
29
+ * `tenancy.enabled`; with it on, checks are scoped to the context tenant. The object form adds
30
+ * `kinds` and `roles` (map the caller's `tenant.role` to authz roles in that tenant).
31
+ */
32
+ tenancy?: AuthzTenancyOption;
33
+ /**
34
+ * Explicit tenant for a check, from the user being checked. Wins over the context: return a
35
+ * tenant id, `null` for the global scope, or `undefined` to fall back to the context.
36
+ */
37
+ tenant?: TenantResolver;
27
38
  }
28
- export interface AuthzRbacModuleAsyncOptions {
39
+ /**
40
+ * Where the store comes from: build it yourself (`store`), or name a Drizzle connection
41
+ * registered with NestJS's `@nestjs/drizzle` (`connectionName`, `'default'` for the default one) and
42
+ * the module builds the store from `getDrizzleToken(connectionName)`, with `storeOptions`.
43
+ */
44
+ export type AuthzRbacModuleOptions = AuthzRbacModuleBaseOptions & ({
45
+ /** The RBAC store, built with the app-provided Drizzle connection. */
46
+ store: DrizzleAuthzStore;
47
+ connectionName?: never;
48
+ storeOptions?: never;
49
+ } | {
50
+ /** The `@nestjs/drizzle` connection to build the store from (`'default'` for the default one). */
51
+ connectionName: string;
52
+ /** Options for the store built from `connectionName` (table names, schema). */
53
+ storeOptions?: AuthzStoreOptions;
54
+ store?: never;
55
+ });
56
+ export type AuthzRbacModuleAsyncOptions = {
29
57
  imports?: unknown[];
30
58
  inject?: unknown[];
31
59
  useFactory: (...args: unknown[]) => Promise<AuthzRbacModuleOptions> | AuthzRbacModuleOptions;
32
- }
60
+ connectionName?: never;
61
+ storeOptions?: never;
62
+ } | {
63
+ /** Build the store from this `@nestjs/drizzle` connection; the factory returns the other options. */
64
+ connectionName: string;
65
+ storeOptions?: AuthzStoreOptions;
66
+ imports?: unknown[];
67
+ inject?: unknown[];
68
+ useFactory?: (...args: unknown[]) => Promise<AuthzRbacModuleBaseOptions> | AuthzRbacModuleBaseOptions;
69
+ };
33
70
  /** Default mapping: accept a `{ type, id }` ref, a `{ id }` object, or a bare id. */
34
71
  export declare function defaultUserRefMapper(user: unknown): UserRef | undefined;
35
72
  /**
36
- * Wires persisted RBAC into the core authz Gate. The app provides the Drizzle `db`
37
- * (via `inject`/`useFactory`) and constructs the {@link DrizzleAuthzStore} — this module
38
- * NEVER hardcodes a connection token. On init it registers the RBAC permission check into
39
- * the Gate via the {@link PERMISSION_PROVIDER} seam, so `gate.allows('some.permission')`
40
- * consults persisted permissions, and (with `autoCreateSchema: true`) ensures the schema exists.
73
+ * Wires persisted RBAC into the core authz Gate. Either the app builds the
74
+ * {@link DrizzleAuthzStore} from its Drizzle `db` (`store`, often in `forRootAsync`'s factory), or names a
75
+ * `@nestjs/drizzle` connection (`connectionName`) and the module builds the store from
76
+ * `getDrizzleToken(connectionName)` — never a hard-coded token. On init it registers the RBAC
77
+ * permission check into the Gate via the {@link PERMISSION_PROVIDER} seam, so
78
+ * `gate.allows('some.permission')` consults persisted permissions, and (with `autoCreateSchema: true`) ensures the schema exists.
41
79
  */
42
80
  export declare class AuthzRbacModule {
43
81
  static forRoot(options: AuthzRbacModuleOptions): DynamicModule;
@@ -1 +1 @@
1
- {"version":3,"file":"authz-rbac.module.d.ts","sourceRoot":"","sources":["../src/authz-rbac.module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EACL,KAAK,aAAa,EAQnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,eAAqD,CAAC;AACnF,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,eAAuD,CAAC;AAEvF;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,OAAO,GAAG,SAAS,CAAC;AAEnE,MAAM,WAAW,sBAAsB;IACrC,6EAA6E;IAC7E,KAAK,EAAE,iBAAiB,CAAC;IACzB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC;CAC7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,sBAAsB,CAAC,GAAG,sBAAsB,CAAC;CAC9F;AAgDD,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,S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K,CAAC;CACtB,GACD;IACE,kGAAkG;IAClG,cAAc,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CACJ,CAAC;AAKJ,MAAM,MAAM,2BAA2B,GACnC;IACE,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,sBAAsB,CAAC,GAAG,sBAAsB,CAAC;IAC7F,cAAc,CAAC,EAAE,KAAK,CAAC;IACvB,YAAY,CAAC,EAAE,KAAK,CAAC;CACtB,GACD;IACE,qGAAqG;IACrG,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,CACX,GAAG,IAAI,EAAE,OAAO,EAAE,KACf,OAAO,CAAC,0BAA0B,CAAC,GAAG,0BAA0B,CAAC;CACvE,CAAC;AA6BN,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAOvE;AA4HD;;;;;;;GAOG;AACH,qBACa,eAAe;IAC1B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,sBAAsB,GAAG,aAAa;IAqB9D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,2BAA2B,GAAG,aAAa;IA0CxE,OAAO,CAAC,MAAM,CAAC,eAAe;CAc/B"}
@@ -11,48 +11,37 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
11
  return function (target, key) { decorator(target, key, paramIndex); }
12
12
  };
13
13
  var AuthzRbacModule_1;
14
+ import { createRequire } from 'node:module';
14
15
  import { CONTEXT_ACCESSOR, PERMISSION_PROVIDER, ROLE_PROVIDER, } from '@dudousxd/nestjs-authz';
15
16
  import { Inject, Injectable, Module, Optional, } from '@nestjs/common';
16
17
  import { ModuleRef } from '@nestjs/core';
18
+ import { DrizzleAuthzStore } from './drizzle-authz.store.js';
19
+ import { rbacTenant, } from './tenancy.js';
17
20
  /** Injection token holding the {@link DrizzleAuthzStore} the RBAC module manages. */
18
21
  export const AUTHZ_RBAC_STORE = Symbol.for('@dudousxd/nestjs-authz-drizzle:store');
19
22
  /** Injection token holding the resolved {@link AuthzRbacModuleOptions}. */
20
23
  export const AUTHZ_RBAC_OPTIONS = Symbol.for('@dudousxd/nestjs-authz-drizzle:options');
21
- /** Read the current tenant from the (optional) context accessor, defensively. */
22
- function tenantScopeFrom(context) {
23
- if (!context || typeof context.tenantId !== 'function')
24
- return {};
25
- let tenantId;
26
- try {
27
- tenantId = context.tenantId();
28
- }
29
- catch {
30
- tenantId = undefined;
31
- }
32
- return tenantId == null ? {} : { tenantId };
33
- }
24
+ const requirePeer = createRequire(import.meta.url);
34
25
  /**
35
- * Locate the context accessor for tenant scoping. Prefers a value injected into
36
- * this module; falls back to a non-strict {@link ModuleRef} lookup so an accessor
37
- * provided by ANY module (the app root, a global ContextModule) is still found —
38
- * the RBAC module is global and its providers don't import the app's modules, so a
39
- * plain `@Inject` would miss a root-provided accessor. Mirrors the Gate's seam.
26
+ * The injection token `@nestjs/drizzle` registers the connection `name` under, from its own
27
+ * `getDrizzleToken()`. An optional peer, loaded only for `connectionName`.
40
28
  */
41
- function resolveTenantContext(injected, moduleRef, cache) {
42
- if (injected)
43
- return injected;
44
- if (cache.resolved)
45
- return cache.value;
46
- cache.resolved = true;
47
- if (moduleRef) {
48
- try {
49
- cache.value = moduleRef.get(CONTEXT_ACCESSOR, { strict: false });
50
- }
51
- catch {
52
- cache.value = undefined;
29
+ function connectionToken(name) {
30
+ let official;
31
+ try {
32
+ official = requirePeer('@nestjs/drizzle');
33
+ }
34
+ catch (error) {
35
+ const code = error.code;
36
+ const message = String(error.message ?? '');
37
+ if ((code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') &&
38
+ message.includes("'@nestjs/drizzle'")) {
39
+ throw new Error('AuthzRbacModule: connectionName needs @nestjs/drizzle, which is not installed. ' +
40
+ 'Install it, or build the store yourself and pass `store`.');
53
41
  }
42
+ throw error;
54
43
  }
55
- return cache.value;
44
+ return official.getDrizzleToken(name);
56
45
  }
57
46
  /** Default mapping: accept a `{ type, id }` ref, a `{ id }` object, or a bare id. */
58
47
  export function defaultUserRefMapper(user) {
@@ -86,8 +75,14 @@ let RbacPermissionProvider = class RbacPermissionProvider {
86
75
  this.context = context;
87
76
  this.moduleRef = moduleRef;
88
77
  }
89
- scope() {
90
- return tenantScopeFrom(resolveTenantContext(this.context, this.moduleRef, this.contextCache));
78
+ tenant(user, ref) {
79
+ return rbacTenant(this.options, user, ref, this.context, this.moduleRef, this.contextCache, true);
80
+ }
81
+ /** The permissions `tenancy.roles` grants through the caller's role in the tenant. */
82
+ async tenantRolePermissions(roles) {
83
+ if (roles.length === 0)
84
+ return [];
85
+ return Object.values(await this.options.store.getRolePermissions(roles)).flat();
91
86
  }
92
87
  // The core `PermissionProvider` interface passes an optional `resource` (3rd
93
88
  // arg); it is intentionally ignored here. RBAC grants are model-less,
@@ -100,7 +95,10 @@ let RbacPermissionProvider = class RbacPermissionProvider {
100
95
  const ref = map(user);
101
96
  if (ref === undefined)
102
97
  return undefined;
103
- return this.options.store.userHasPermission(ref, permission, this.scope());
98
+ const tenant = this.tenant(user, ref);
99
+ if (await this.options.store.userHasPermission(ref, permission, tenant.scope))
100
+ return true;
101
+ return (await this.tenantRolePermissions(tenant.roles)).includes(permission);
104
102
  }
105
103
  // Expose the user's full granted permission set so the core can apply
106
104
  // Laravel/spatie-style wildcard matching (a granted `posts.*` satisfies a check
@@ -111,7 +109,11 @@ let RbacPermissionProvider = class RbacPermissionProvider {
111
109
  const ref = map(user);
112
110
  if (ref === undefined)
113
111
  return undefined;
114
- return this.options.store.getPermissionsForUser(ref, this.scope());
112
+ const tenant = this.tenant(user, ref);
113
+ const own = await this.options.store.getPermissionsForUser(ref, tenant.scope);
114
+ if (tenant.roles.length === 0)
115
+ return own;
116
+ return [...new Set([...own, ...(await this.tenantRolePermissions(tenant.roles))])];
115
117
  }
116
118
  };
117
119
  RbacPermissionProvider = __decorate([
@@ -146,10 +148,11 @@ let RbacRoleProvider = class RbacRoleProvider {
146
148
  const ref = map(user);
147
149
  if (ref === undefined)
148
150
  return undefined;
149
- // Scope roles by the current tenant (when nestjs-context is present): a
150
- // tenant-scoped role only counts within its tenant; global roles always count.
151
- const scope = tenantScopeFrom(resolveTenantContext(this.context, this.moduleRef, this.contextCache));
152
- return this.options.store.getRolesForUser(ref, scope);
151
+ // Scope roles by the current tenant: a tenant-scoped role only counts within its
152
+ // tenant; global roles always count. `tenancy.roles` adds the caller's tenant roles.
153
+ const tenant = rbacTenant(this.options, user, ref, this.context, this.moduleRef, this.contextCache, true);
154
+ const own = await this.options.store.getRolesForUser(ref, tenant.scope);
155
+ return tenant.roles.length === 0 ? own : [...new Set([...own, ...tenant.roles])];
153
156
  }
154
157
  };
155
158
  RbacRoleProvider = __decorate([
@@ -181,43 +184,67 @@ AuthzRbacBootstrap = __decorate([
181
184
  __metadata("design:paramtypes", [Object])
182
185
  ], AuthzRbacBootstrap);
183
186
  /**
184
- * Wires persisted RBAC into the core authz Gate. The app provides the Drizzle `db`
185
- * (via `inject`/`useFactory`) and constructs the {@link DrizzleAuthzStore} — this module
186
- * NEVER hardcodes a connection token. On init it registers the RBAC permission check into
187
- * the Gate via the {@link PERMISSION_PROVIDER} seam, so `gate.allows('some.permission')`
188
- * consults persisted permissions, and (with `autoCreateSchema: true`) ensures the schema exists.
187
+ * Wires persisted RBAC into the core authz Gate. Either the app builds the
188
+ * {@link DrizzleAuthzStore} from its Drizzle `db` (`store`, often in `forRootAsync`'s factory), or names a
189
+ * `@nestjs/drizzle` connection (`connectionName`) and the module builds the store from
190
+ * `getDrizzleToken(connectionName)` — never a hard-coded token. On init it registers the RBAC
191
+ * permission check into the Gate via the {@link PERMISSION_PROVIDER} seam, so
192
+ * `gate.allows('some.permission')` consults persisted permissions, and (with `autoCreateSchema: true`) ensures the schema exists.
189
193
  */
190
194
  let AuthzRbacModule = AuthzRbacModule_1 = class AuthzRbacModule {
191
195
  static forRoot(options) {
196
+ const { connectionName, storeOptions, store, ...base } = options;
197
+ const optionsProvider = connectionName === undefined
198
+ ? { provide: AUTHZ_RBAC_OPTIONS, useValue: { ...base, store } }
199
+ : {
200
+ provide: AUTHZ_RBAC_OPTIONS,
201
+ useFactory: (connection) => ({
202
+ ...base,
203
+ store: new DrizzleAuthzStore(connection, storeOptions),
204
+ }),
205
+ inject: [connectionToken(connectionName)],
206
+ };
192
207
  return {
193
208
  module: AuthzRbacModule_1,
194
209
  global: true,
195
- providers: [
196
- { provide: AUTHZ_RBAC_OPTIONS, useValue: options },
197
- { provide: AUTHZ_RBAC_STORE, useValue: options.store },
198
- ...AuthzRbacModule_1.commonProviders(),
199
- ],
210
+ providers: [optionsProvider, ...AuthzRbacModule_1.commonProviders()],
200
211
  exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER, ROLE_PROVIDER],
201
212
  };
202
213
  }
203
214
  static forRootAsync(options) {
215
+ const inject = (options.inject ?? []);
216
+ let optionsProvider;
217
+ if (options.connectionName === undefined) {
218
+ const { useFactory } = options;
219
+ optionsProvider = {
220
+ provide: AUTHZ_RBAC_OPTIONS,
221
+ useFactory: async (...args) => {
222
+ const resolved = await useFactory(...args);
223
+ if (resolved.connectionName !== undefined) {
224
+ throw new Error('AuthzRbacModule.forRootAsync: pass connectionName next to useFactory, not in the options it returns.');
225
+ }
226
+ const { store, connectionName: _c, storeOptions: _s, ...base } = resolved;
227
+ return { ...base, store };
228
+ },
229
+ inject,
230
+ };
231
+ }
232
+ else {
233
+ const { useFactory, storeOptions } = options;
234
+ optionsProvider = {
235
+ provide: AUTHZ_RBAC_OPTIONS,
236
+ useFactory: async (connection, ...args) => ({
237
+ ...((await useFactory?.(...args)) ?? {}),
238
+ store: new DrizzleAuthzStore(connection, storeOptions),
239
+ }),
240
+ inject: [connectionToken(options.connectionName), ...inject],
241
+ };
242
+ }
204
243
  return {
205
244
  module: AuthzRbacModule_1,
206
245
  global: true,
207
246
  imports: (options.imports ?? []),
208
- providers: [
209
- {
210
- provide: AUTHZ_RBAC_OPTIONS,
211
- useFactory: options.useFactory,
212
- inject: (options.inject ?? []),
213
- },
214
- {
215
- provide: AUTHZ_RBAC_STORE,
216
- useFactory: (opts) => opts.store,
217
- inject: [AUTHZ_RBAC_OPTIONS],
218
- },
219
- ...AuthzRbacModule_1.commonProviders(),
220
- ],
247
+ providers: [optionsProvider, ...AuthzRbacModule_1.commonProviders()],
221
248
  exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER, ROLE_PROVIDER],
222
249
  };
223
250
  }
@@ -227,6 +254,11 @@ let AuthzRbacModule = AuthzRbacModule_1 = class AuthzRbacModule {
227
254
  { provide: PERMISSION_PROVIDER, useExisting: RbacPermissionProvider },
228
255
  RbacRoleProvider,
229
256
  { provide: ROLE_PROVIDER, useExisting: RbacRoleProvider },
257
+ {
258
+ provide: AUTHZ_RBAC_STORE,
259
+ useFactory: (opts) => opts.store,
260
+ inject: [AUTHZ_RBAC_OPTIONS],
261
+ },
230
262
  AuthzRbacBootstrap,
231
263
  ];
232
264
  }
@@ -1 +1 @@
1
- {"version":3,"file":"authz-rbac.module.js","sourceRoot":"","sources":["../src/authz-rbac.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EAEnB,aAAa,GAEd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAEL,MAAM,EACN,UAAU,EACV,MAAM,EAEN,QAAQ,GAGT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAA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AE,gBAAgB,EAAE;YACzD;gBACE,OAAO,EAAE,gBAAgB;gBACzB,UAAU,EAAE,CAAC,IAAyB,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK;gBACrD,MAAM,EAAE,CAAC,kBAAkB,CAAC;aAC7B;YACD,kBAAkB;SACnB,CAAC;IACJ,CAAC;CACF,CAAA;AA9EY,eAAe;IAD3B,MAAM,CAAC,EAAE,CAAC;GACE,eAAe,CA8E3B"}
package/dist/index.d.ts CHANGED
@@ -3,8 +3,9 @@ export type { AuthzTables } from './schema.js';
3
3
  export { DrizzleAuthzStore } from './drizzle-authz.store.js';
4
4
  export type { RoleAssignment, RoleAssignmentFilter, UserAuthz, UserRoleAssignment, } from './drizzle-authz.store.js';
5
5
  export { AUTHZ_RBAC_OPTIONS, AUTHZ_RBAC_STORE, AuthzRbacModule, defaultUserRefMapper, } from './authz-rbac.module.js';
6
- export type { AuthzRbacModuleAsyncOptions, AuthzRbacModuleOptions, UserRefMapper, } from './authz-rbac.module.js';
6
+ export type { AuthzRbacModuleAsyncOptions, AuthzRbacModuleBaseOptions, AuthzRbacModuleOptions, UserRefMapper, } from './authz-rbac.module.js';
7
7
  export type { AuthzStoreOptions, DrizzlePgDatabase, RoleAssignmentScope, TableNames, TenantScope, } from './types.js';
8
+ export type { AuthzTenancyOption, TenantResolver } from './tenancy.js';
8
9
  export type { UserRef, UserRefInput } from '@dudousxd/nestjs-authz/store-kit';
9
10
  export { applyScope, compileScope } from './scope.js';
10
11
  export type { ScopeColumns, ScopeResolver } from './scope.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,2BAA2B,EAC3B,sBAAsB,EACtB,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,SAAS,EACT,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,aAAa,GACd,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAO7D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAchC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAO7D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAgBhC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,100 @@
1
+ import { type UserRef } from '@dudousxd/nestjs-authz/store-kit';
2
+ import type { ModuleRef } from '@nestjs/core';
3
+ /** A tenant as published by `@dudousxd/nestjs-context` (`Context.tenant()`). */
4
+ export interface TenantRef {
5
+ id: string;
6
+ kind: string;
7
+ source: string;
8
+ slug?: string;
9
+ role?: string;
10
+ }
11
+ /** How the context says a lib must scope data right now (`Context.tenantFilter()`). */
12
+ export type TenantFilter = {
13
+ mode: 'system';
14
+ } | {
15
+ mode: 'all';
16
+ } | {
17
+ mode: 'tenantless';
18
+ } | {
19
+ mode: 'tenant';
20
+ tenant: TenantRef;
21
+ };
22
+ /**
23
+ * The RBAC module's `tenancy` option. `'inherit'` (default) follows `ContextModule`'s
24
+ * `tenancy.enabled`; `false` keeps this module out of tenancy.
25
+ */
26
+ export type AuthzTenancyOption = 'inherit' | false | {
27
+ /** `'inherit'` (default) follows the context switch; a boolean overrides it. */
28
+ enabled?: 'inherit' | boolean;
29
+ /** Tenant kinds this module honours, instead of the context's `kinds`. */
30
+ kinds?: string[];
31
+ /**
32
+ * Accepted for the shared shape. It changes nothing here: a GLOBAL role assignment
33
+ * always applies, in every tenant.
34
+ */
35
+ nullRows?: 'tenantless' | 'shared';
36
+ /**
37
+ * Map the caller's role inside the context tenant (`tenant.role`) to authz roles that
38
+ * apply in that tenant's scope only, e.g. `{ owner: 'org_admin', member: 'org_member' }`.
39
+ * Unmapped roles grant nothing.
40
+ */
41
+ roles?: Record<string, string | readonly string[]>;
42
+ };
43
+ /**
44
+ * An explicit tenant for a check, from the user being checked. Return a tenant id to scope the
45
+ * check to it, `null` for the global scope, or `undefined` to fall back to the context.
46
+ */
47
+ export type TenantResolver = (user: unknown) => string | null | undefined;
48
+ /** The structural slice of nestjs-context's accessor this module reads. */
49
+ export interface TenantContextAccessor {
50
+ tenantId?(): string | undefined;
51
+ userRef?(): {
52
+ type?: string;
53
+ id: string | number;
54
+ } | undefined;
55
+ tenancy?(): {
56
+ enabled: boolean;
57
+ kinds?: string[];
58
+ };
59
+ tenantFilter?(options?: {
60
+ kinds?: string[];
61
+ }): TenantFilter;
62
+ }
63
+ /** The tenant scope of one check, plus the roles `tenancy.roles` adds in that scope. */
64
+ export interface RbacTenant {
65
+ scope: {
66
+ tenantId?: string;
67
+ };
68
+ roles: string[];
69
+ }
70
+ export interface ResolveRbacTenantInput {
71
+ /** The user as the Gate passed it. */
72
+ user: unknown;
73
+ /** The same user mapped to a store ref. */
74
+ ref: UserRef;
75
+ /** The module's explicit `tenant` resolver, if any. */
76
+ resolver?: TenantResolver | undefined;
77
+ /** The module's `tenancy` option. */
78
+ tenancy?: AuthzTenancyOption | undefined;
79
+ /** The context accessor found through DI, if any (else the global slot is read). */
80
+ accessor?: TenantContextAccessor | undefined;
81
+ /** With tenancy off, scope by the context's plain `tenantId()` (drizzle/typeorm behaviour). */
82
+ legacyContextTenant: boolean;
83
+ }
84
+ /**
85
+ * Precedence: the explicit `tenant` resolver, then (tenancy on) the context tenant filter, then
86
+ * (tenancy off) the adapter's behaviour without tenancy. `tenant` mode scopes to that tenant;
87
+ * `tenantless`, `all` and `system` use the global scope.
88
+ */
89
+ export declare function resolveRbacTenant(input: ResolveRbacTenantInput): RbacTenant;
90
+ /** A provider's per-instance cache for {@link rbacTenant}'s accessor lookup. */
91
+ export interface TenantContextCache {
92
+ resolved: boolean;
93
+ value: TenantContextAccessor | undefined;
94
+ }
95
+ /** The tenant scope (and `tenancy.roles` roles) of one check for `user`. */
96
+ export declare function rbacTenant(options: {
97
+ tenant?: TenantResolver | undefined;
98
+ tenancy?: AuthzTenancyOption | undefined;
99
+ }, user: unknown, ref: UserRef, injected: TenantContextAccessor | undefined, moduleRef: ModuleRef | undefined, cache: TenantContextCache, legacyContextTenant: boolean): RbacTenant;
100
+ //# sourceMappingURL=tenancy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy.d.ts","sourceRoot":"","sources":["../src/tenancy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,OAAO,EAAoB,MAAM,kCAAkC,CAAC;AAClF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,gFAAgF;AAChF,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC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AM,WAAW,UAAU;IACzB,KAAK,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,IAAI,EAAE,OAAO,CAAC;IACd,2CAA2C;IAC3C,GAAG,EAAE,OAAO,CAAC;IACb,uDAAuD;IACvD,QAAQ,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IACtC,qCAAqC;IACrC,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACzC,oFAAoF;IACpF,QAAQ,CAAC,EAAE,qBAAqB,GAAG,SAAS,CAAC;IAC7C,+FAA+F;IAC/F,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,UAAU,CAgC3E;AA0BD,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC1C;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CACxB,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;IAAC,OAAO,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAA;CAAE,EAC1F,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,qBAAqB,GAAG,SAAS,EAC3C,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,KAAK,EAAE,kBAAkB,EACzB,mBAAmB,EAAE,OAAO,GAC3B,UAAU,CASZ"}
@@ -0,0 +1,128 @@
1
+ // Tenancy for the RBAC module: which tenant scope a permission/role check runs in, and which
2
+ // roles the caller's role inside the context tenant maps to. The same file ships in every
3
+ // store adapter. It reads the @dudousxd/nestjs-context tenancy contract STRUCTURALLY (no import),
4
+ // so it works with any context version, and with none: a missing or older context reads as
5
+ // tenancy off.
6
+ import { CONTEXT_ACCESSOR } from '@dudousxd/nestjs-authz';
7
+ import { normalizeUserRef } from '@dudousxd/nestjs-authz/store-kit';
8
+ const SLOT = Symbol.for('@dudousxd/nestjs-diagnostics:accessor');
9
+ /** Is tenancy on for this module? Call per check: the context can change between requests. */
10
+ function readTenancy(option, a) {
11
+ if (option === false)
12
+ return { enabled: false };
13
+ if (typeof a?.tenancy !== 'function' || typeof a.tenantFilter !== 'function') {
14
+ return { enabled: false };
15
+ }
16
+ const own = typeof option === 'object' ? option : {};
17
+ const inherit = own.enabled === undefined || own.enabled === 'inherit';
18
+ if (!(inherit ? a.tenancy().enabled : own.enabled))
19
+ return { enabled: false };
20
+ const kinds = own.kinds;
21
+ const tenantFilter = a.tenantFilter.bind(a);
22
+ return { enabled: true, filter: () => tenantFilter(kinds ? { kinds } : undefined) };
23
+ }
24
+ /** The accessor found through DI, else the global slot `ContextModule` publishes. */
25
+ function effectiveAccessor(injected) {
26
+ if (injected)
27
+ return injected;
28
+ const slot = globalThis[SLOT];
29
+ const current = slot?.current;
30
+ return current && typeof current === 'object' ? current : undefined;
31
+ }
32
+ /** Today's behaviour without tenancy: the context's plain `tenantId()`, read defensively. */
33
+ function legacyTenantId(accessor) {
34
+ if (!accessor || typeof accessor.tenantId !== 'function')
35
+ return undefined;
36
+ try {
37
+ return accessor.tenantId() ?? undefined;
38
+ }
39
+ catch {
40
+ return undefined;
41
+ }
42
+ }
43
+ /** Is `ref` the context's current user? Tenant roles belong to the caller, nobody else. */
44
+ function isContextUser(ref, accessor) {
45
+ let current;
46
+ try {
47
+ current = accessor?.userRef?.();
48
+ }
49
+ catch {
50
+ current = undefined;
51
+ }
52
+ if (!current || current.id === undefined || current.id === null)
53
+ return false;
54
+ const a = normalizeUserRef(ref);
55
+ const b = normalizeUserRef(current);
56
+ return a.type === b.type && a.id === b.id;
57
+ }
58
+ /**
59
+ * Precedence: the explicit `tenant` resolver, then (tenancy on) the context tenant filter, then
60
+ * (tenancy off) the adapter's behaviour without tenancy. `tenant` mode scopes to that tenant;
61
+ * `tenantless`, `all` and `system` use the global scope.
62
+ */
63
+ export function resolveRbacTenant(input) {
64
+ const explicit = input.resolver ? input.resolver(input.user) : undefined;
65
+ const accessor = effectiveAccessor(input.accessor);
66
+ const tenancy = readTenancy(input.tenancy, accessor);
67
+ const filter = tenancy.enabled ? tenancy.filter() : undefined;
68
+ let scope;
69
+ if (explicit !== undefined) {
70
+ scope = explicit === null ? {} : { tenantId: explicit };
71
+ }
72
+ else if (filter) {
73
+ scope = filter.mode === 'tenant' ? { tenantId: filter.tenant.id } : {};
74
+ }
75
+ else if (input.legacyContextTenant) {
76
+ const id = legacyTenantId(input.accessor);
77
+ scope = id === undefined ? {} : { tenantId: id };
78
+ }
79
+ else {
80
+ scope = {};
81
+ }
82
+ const map = typeof input.tenancy === 'object' ? input.tenancy.roles : undefined;
83
+ let roles = [];
84
+ if (map &&
85
+ filter?.mode === 'tenant' &&
86
+ filter.tenant.role !== undefined &&
87
+ scope.tenantId === filter.tenant.id &&
88
+ Object.prototype.hasOwnProperty.call(map, filter.tenant.role) &&
89
+ isContextUser(input.ref, accessor)) {
90
+ const mapped = map[filter.tenant.role];
91
+ roles = typeof mapped === 'string' ? [mapped] : [...(mapped ?? [])];
92
+ }
93
+ return { scope, roles };
94
+ }
95
+ /**
96
+ * Locate the context accessor. Prefers a value injected into the module; falls back to a
97
+ * non-strict {@link ModuleRef} lookup so an accessor provided by ANY module (the app root, a
98
+ * global ContextModule) is still found: the RBAC module is global and its providers don't import
99
+ * the app's modules, so a plain `@Inject` would miss a root-provided accessor.
100
+ */
101
+ function resolveTenantContext(injected, moduleRef, cache) {
102
+ if (injected)
103
+ return injected;
104
+ if (cache.resolved)
105
+ return cache.value;
106
+ cache.resolved = true;
107
+ if (moduleRef) {
108
+ try {
109
+ cache.value = moduleRef.get(CONTEXT_ACCESSOR, { strict: false });
110
+ }
111
+ catch {
112
+ cache.value = undefined;
113
+ }
114
+ }
115
+ return cache.value;
116
+ }
117
+ /** The tenant scope (and `tenancy.roles` roles) of one check for `user`. */
118
+ export function rbacTenant(options, user, ref, injected, moduleRef, cache, legacyContextTenant) {
119
+ return resolveRbacTenant({
120
+ user,
121
+ ref,
122
+ resolver: options.tenant,
123
+ tenancy: options.tenancy,
124
+ accessor: resolveTenantContext(injected, moduleRef, cache),
125
+ legacyContextTenant,
126
+ });
127
+ }
128
+ //# sourceMappingURL=tenancy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenancy.js","sourceRoot":"","sources":["../src/tenancy.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,0FAA0F;AAC1F,kGAAkG;AAClG,2FAA2F;AAC3F,eAAe;AACf,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAgB,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AA0DlF,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAIjE,8FAA8F;AAC9F,SAAS,WAAW,CAClB,MAAsC,EACtC,CAAoC;IAEpC,IAAI,MAAM,KAAK,KAAK;QAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAChD,IAAI,OAAO,CAAC,EAAE,OAAO,KAAK,UAAU,IAAI,OAAO,CAAC,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QAC7E,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IACD,MAAM,GAAG,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC;IACvE,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAA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AQ;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC;IACvC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;IACtB,IAAI,SAAS,EAAE,CAAC;QACd,IAAI,CAAC;YACH,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC,GAAG,CAAwB,gBAAgB,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAC1F,CAAC;QAAC,MAAM,CAAC;YACP,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC;AACrB,CAAC;AAQD,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CACxB,OAA0F,EAC1F,IAAa,EACb,GAAY,EACZ,QAA2C,EAC3C,SAAgC,EAChC,KAAyB,EACzB,mBAA4B;IAE5B,OAAO,iBAAiB,CAAC;QACvB,IAAI;QACJ,GAAG;QACH,QAAQ,EAAE,OAAO,CAAC,MAAM;QACxB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,oBAAoB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC;QAC1D,mBAAmB;KACpB,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-authz-drizzle",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Drizzle ORM RBAC persistence + query-scope compiler for @dudousxd/nestjs-authz — roles, permissions, a Gate seam, and gate.scope() → Drizzle WHERE (zero connection ownership).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -39,33 +39,45 @@
39
39
  "CHANGELOG.md"
40
40
  ],
41
41
  "peerDependencies": {
42
- "@dudousxd/nestjs-authz": ">=0.8.0",
43
- "@nestjs/common": ">=10.0.0",
44
- "@nestjs/core": ">=10.0.0",
42
+ "@dudousxd/nestjs-authz": ">=0.10.0",
43
+ "@nestjs/authorization": "^0.1.3",
44
+ "@nestjs/common": "^12.0.0",
45
+ "@nestjs/core": "^12.0.0",
45
46
  "drizzle-orm": ">=0.40.0 <1.0.0",
46
- "reflect-metadata": ">=0.1.13"
47
+ "reflect-metadata": ">=0.1.13",
48
+ "@nestjs/drizzle": ">=0.0.2"
47
49
  },
48
50
  "devDependencies": {
49
51
  "@electric-sql/pglite": "0.4.6",
52
+ "@nestjs/authorization": "0.1.3",
50
53
  "@nestjs/common": "12.0.1",
51
54
  "@nestjs/core": "12.0.1",
55
+ "@nestjs/drizzle": "0.0.2",
56
+ "@nestjs/platform-express": "12.0.1",
52
57
  "@nestjs/testing": "12.0.1",
53
58
  "@testcontainers/postgresql": "12.1.0",
54
- "@types/node": "20.19.43",
59
+ "@types/node": "24.19.2",
55
60
  "@types/pg": "8.23.1",
61
+ "@types/supertest": "6.0.3",
56
62
  "drizzle-orm": "0.45.2",
57
63
  "pg": "8.23.0",
58
64
  "reflect-metadata": "0.2.2",
59
65
  "rxjs": "7.8.2",
66
+ "supertest": "7.2.2",
60
67
  "typescript": "5.9.3",
61
68
  "vitest": "3.2.7",
62
- "@dudousxd/nestjs-authz": "^0.8.1"
69
+ "@dudousxd/nestjs-authz": "^0.11.0"
63
70
  },
64
71
  "engines": {
65
- "node": ">=20"
72
+ "node": ">=24"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "@nestjs/drizzle": {
76
+ "optional": true
77
+ }
66
78
  },
67
79
  "scripts": {
68
- "build": "tsc -p tsconfig.json",
80
+ "build": "tsc -p tsconfig.json --incremental false",
69
81
  "test": "vitest run --passWithNoTests",
70
82
  "test:db:pg": "AUTHZ_TEST_DIALECT=postgres vitest run --config vitest.db.config.ts",
71
83
  "test:watch": "vitest",