@dudousxd/nestjs-authz-drizzle 0.2.0 → 0.3.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,29 @@
1
1
  # @dudousxd/nestjs-authz-drizzle
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#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
8
+ permissions now guard routes through the official guard as the core's `RolePolicy` /
9
+ `PermissionPolicy` (`@Roles('editor')`, `@Permission('posts.publish')`), and the guard and the
10
+ handler's `Gate` calls share one permission and role fetch per request. The store API
11
+ (role sources, admin management, tenant-scoped roles where supported) and `AuthzRbacModule`
12
+ are unchanged. A persisted permission named like a policy ability no longer bypasses that
13
+ policy (see the core changeset). Requires NestJS 12, `@nestjs/authorization` ^0.1.3 and Node 22+.
14
+
15
+ - [#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`.
16
+
17
+ ### Patch Changes
18
+
19
+ - [#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.
20
+
21
+ ## 0.2.1
22
+
23
+ ### Patch Changes
24
+
25
+ - [#66](https://github.com/DavideCarvalho/nestjs-authz/pull/66) [`d5fdd23`](https://github.com/DavideCarvalho/nestjs-authz/commit/d5fdd23a2b72ae61fae0f913f11164bc4d2df77b) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Authorization checks within one request no longer hit the database per check. The Gate memoizes `resolveUser`, the permission set and the provider roles on the request context (keyed by the row a user names, its class or `type` plus `id`, so ORMs without an identity map share entries; a plain object without `type` is keyed by identity, so two users that only share an `id` never share an entry), and compiles the granted set once so a check is a hash lookup plus a scan of the wildcard grants. Providers can set the optional `exhaustivePermissions` flag to say `getPermissions` lists everything `hasPermission` grants; the ORM adapters do, and the MikroORM and Prisma providers now expose `getPermissions` (so persisted wildcard grants such as `posts.*` match there too). Grants changed mid-request apply from the next request.
26
+
3
27
  ## 0.2.0
4
28
 
5
29
  ### Minor 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.9 and Node 22+.
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,15 +103,34 @@ 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
+ ```
111
+
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`:
82
121
 
83
- gate.forUser(user).allows('posts.publish'); // true (PERMISSION_PROVIDER seam, wildcards supported)
84
- gate.forUser(user).hasRole('editor'); // true (ROLE_PROVIDER seam)
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.
@@ -1,6 +1,7 @@
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 { AuthzStoreOptions } from './types.js';
4
5
  /** Injection token holding the {@link DrizzleAuthzStore} the RBAC module manages. */
5
6
  export declare const AUTHZ_RBAC_STORE: unique symbol;
6
7
  /** Injection token holding the resolved {@link AuthzRbacModuleOptions}. */
@@ -10,9 +11,7 @@ export declare const AUTHZ_RBAC_OPTIONS: unique symbol;
10
11
  * {@link UserRef} the store can key on. Defaults to reading `{ type, id }` / `{ id }`.
11
12
  */
12
13
  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;
14
+ export interface AuthzRbacModuleBaseOptions {
16
15
  /**
17
16
  * Run the store's `ensureSchema` (`CREATE ... IF NOT EXISTS`, non-destructive) on bootstrap.
18
17
  * Default `false`: with Drizzle the schema is normally owned by drizzle-kit — spread the
@@ -25,19 +24,46 @@ export interface AuthzRbacModuleOptions {
25
24
  */
26
25
  userRefFrom?: UserRefMapper;
27
26
  }
28
- export interface AuthzRbacModuleAsyncOptions {
27
+ /**
28
+ * Where the store comes from: build it yourself (`store`), or name a Drizzle connection
29
+ * registered with NestJS's `@nestjs/drizzle` (`connectionName`, `'default'` for the default one) and
30
+ * the module builds the store from `getDrizzleToken(connectionName)`, with `storeOptions`.
31
+ */
32
+ export type AuthzRbacModuleOptions = AuthzRbacModuleBaseOptions & ({
33
+ /** The RBAC store, built with the app-provided Drizzle connection. */
34
+ store: DrizzleAuthzStore;
35
+ connectionName?: never;
36
+ storeOptions?: never;
37
+ } | {
38
+ /** The `@nestjs/drizzle` connection to build the store from (`'default'` for the default one). */
39
+ connectionName: string;
40
+ /** Options for the store built from `connectionName` (table names, schema). */
41
+ storeOptions?: AuthzStoreOptions;
42
+ store?: never;
43
+ });
44
+ export type AuthzRbacModuleAsyncOptions = {
29
45
  imports?: unknown[];
30
46
  inject?: unknown[];
31
47
  useFactory: (...args: unknown[]) => Promise<AuthzRbacModuleOptions> | AuthzRbacModuleOptions;
32
- }
48
+ connectionName?: never;
49
+ storeOptions?: never;
50
+ } | {
51
+ /** Build the store from this `@nestjs/drizzle` connection; the factory returns the other options. */
52
+ connectionName: string;
53
+ storeOptions?: AuthzStoreOptions;
54
+ imports?: unknown[];
55
+ inject?: unknown[];
56
+ useFactory?: (...args: unknown[]) => Promise<AuthzRbacModuleBaseOptions> | AuthzRbacModuleBaseOptions;
57
+ };
33
58
  /** Default mapping: accept a `{ type, id }` ref, a `{ id }` object, or a bare id. */
34
59
  export declare function defaultUserRefMapper(user: unknown): UserRef | undefined;
35
60
  /**
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.
61
+ * Wires persisted RBAC into the core authz Gate. Either the app builds the
62
+ * {@link DrizzleAuthzStore} from its Drizzle `db` (`store`, often in `forRootAsync`'s factory), or names a
63
+ * `@nestjs/drizzle` connection (`connectionName`) and the module builds the store from
64
+ * `getDrizzleToken(connectionName)` — never a hard-coded token. On init it registers the RBAC
65
+ * permission check into the Gate via the {@link PERMISSION_PROVIDER} seam, so
66
+ * `gate.allows('some.permission')` consults persisted permissions, and (with `autoCreateSchema: true`) ensures the schema exists.
41
67
  */
42
68
  export declare class AuthzRbacModule {
43
69
  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,sBA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sBAAsB,GAAG,aAAa;IAqB9D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,2BAA2B,GAAG,aAAa;IA0CxE,OAAO,CAAC,MAAM,CAAC,eAAe;CAc/B"}
@@ -11,13 +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';
17
19
  /** Injection token holding the {@link DrizzleAuthzStore} the RBAC module manages. */
18
20
  export const AUTHZ_RBAC_STORE = Symbol.for('@dudousxd/nestjs-authz-drizzle:store');
19
21
  /** Injection token holding the resolved {@link AuthzRbacModuleOptions}. */
20
22
  export const AUTHZ_RBAC_OPTIONS = Symbol.for('@dudousxd/nestjs-authz-drizzle:options');
23
+ const requirePeer = createRequire(import.meta.url);
24
+ /**
25
+ * The injection token `@nestjs/drizzle` registers the connection `name` under, from its own
26
+ * `getDrizzleToken()`. An optional peer, loaded only for `connectionName`.
27
+ */
28
+ function connectionToken(name) {
29
+ let official;
30
+ try {
31
+ official = requirePeer('@nestjs/drizzle');
32
+ }
33
+ catch (error) {
34
+ const code = error.code;
35
+ const message = String(error.message ?? '');
36
+ if ((code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND') &&
37
+ message.includes("'@nestjs/drizzle'")) {
38
+ throw new Error('AuthzRbacModule: connectionName needs @nestjs/drizzle, which is not installed. ' +
39
+ 'Install it, or build the store yourself and pass `store`.');
40
+ }
41
+ throw error;
42
+ }
43
+ return official.getDrizzleToken(name);
44
+ }
21
45
  /** Read the current tenant from the (optional) context accessor, defensively. */
22
46
  function tenantScopeFrom(context) {
23
47
  if (!context || typeof context.tenantId !== 'function')
@@ -75,6 +99,8 @@ let RbacPermissionProvider = class RbacPermissionProvider {
75
99
  options;
76
100
  context;
77
101
  moduleRef;
102
+ // `getPermissions` lists every grant `hasPermission` can find, for any resource.
103
+ exhaustivePermissions = true;
78
104
  contextCache = {
79
105
  resolved: false,
80
106
  value: undefined,
@@ -179,43 +205,67 @@ AuthzRbacBootstrap = __decorate([
179
205
  __metadata("design:paramtypes", [Object])
180
206
  ], AuthzRbacBootstrap);
181
207
  /**
182
- * Wires persisted RBAC into the core authz Gate. The app provides the Drizzle `db`
183
- * (via `inject`/`useFactory`) and constructs the {@link DrizzleAuthzStore} — this module
184
- * NEVER hardcodes a connection token. On init it registers the RBAC permission check into
185
- * the Gate via the {@link PERMISSION_PROVIDER} seam, so `gate.allows('some.permission')`
186
- * consults persisted permissions, and (with `autoCreateSchema: true`) ensures the schema exists.
208
+ * Wires persisted RBAC into the core authz Gate. Either the app builds the
209
+ * {@link DrizzleAuthzStore} from its Drizzle `db` (`store`, often in `forRootAsync`'s factory), or names a
210
+ * `@nestjs/drizzle` connection (`connectionName`) and the module builds the store from
211
+ * `getDrizzleToken(connectionName)` — never a hard-coded token. On init it registers the RBAC
212
+ * permission check into the Gate via the {@link PERMISSION_PROVIDER} seam, so
213
+ * `gate.allows('some.permission')` consults persisted permissions, and (with `autoCreateSchema: true`) ensures the schema exists.
187
214
  */
188
215
  let AuthzRbacModule = AuthzRbacModule_1 = class AuthzRbacModule {
189
216
  static forRoot(options) {
217
+ const { connectionName, storeOptions, store, ...base } = options;
218
+ const optionsProvider = connectionName === undefined
219
+ ? { provide: AUTHZ_RBAC_OPTIONS, useValue: { ...base, store } }
220
+ : {
221
+ provide: AUTHZ_RBAC_OPTIONS,
222
+ useFactory: (connection) => ({
223
+ ...base,
224
+ store: new DrizzleAuthzStore(connection, storeOptions),
225
+ }),
226
+ inject: [connectionToken(connectionName)],
227
+ };
190
228
  return {
191
229
  module: AuthzRbacModule_1,
192
230
  global: true,
193
- providers: [
194
- { provide: AUTHZ_RBAC_OPTIONS, useValue: options },
195
- { provide: AUTHZ_RBAC_STORE, useValue: options.store },
196
- ...AuthzRbacModule_1.commonProviders(),
197
- ],
231
+ providers: [optionsProvider, ...AuthzRbacModule_1.commonProviders()],
198
232
  exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER, ROLE_PROVIDER],
199
233
  };
200
234
  }
201
235
  static forRootAsync(options) {
236
+ const inject = (options.inject ?? []);
237
+ let optionsProvider;
238
+ if (options.connectionName === undefined) {
239
+ const { useFactory } = options;
240
+ optionsProvider = {
241
+ provide: AUTHZ_RBAC_OPTIONS,
242
+ useFactory: async (...args) => {
243
+ const resolved = await useFactory(...args);
244
+ if (resolved.connectionName !== undefined) {
245
+ throw new Error('AuthzRbacModule.forRootAsync: pass connectionName next to useFactory, not in the options it returns.');
246
+ }
247
+ const { store, connectionName: _c, storeOptions: _s, ...base } = resolved;
248
+ return { ...base, store };
249
+ },
250
+ inject,
251
+ };
252
+ }
253
+ else {
254
+ const { useFactory, storeOptions } = options;
255
+ optionsProvider = {
256
+ provide: AUTHZ_RBAC_OPTIONS,
257
+ useFactory: async (connection, ...args) => ({
258
+ ...((await useFactory?.(...args)) ?? {}),
259
+ store: new DrizzleAuthzStore(connection, storeOptions),
260
+ }),
261
+ inject: [connectionToken(options.connectionName), ...inject],
262
+ };
263
+ }
202
264
  return {
203
265
  module: AuthzRbacModule_1,
204
266
  global: true,
205
267
  imports: (options.imports ?? []),
206
- providers: [
207
- {
208
- provide: AUTHZ_RBAC_OPTIONS,
209
- useFactory: options.useFactory,
210
- inject: (options.inject ?? []),
211
- },
212
- {
213
- provide: AUTHZ_RBAC_STORE,
214
- useFactory: (opts) => opts.store,
215
- inject: [AUTHZ_RBAC_OPTIONS],
216
- },
217
- ...AuthzRbacModule_1.commonProviders(),
218
- ],
268
+ providers: [optionsProvider, ...AuthzRbacModule_1.commonProviders()],
219
269
  exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER, ROLE_PROVIDER],
220
270
  };
221
271
  }
@@ -225,6 +275,11 @@ let AuthzRbacModule = AuthzRbacModule_1 = class AuthzRbacModule {
225
275
  { provide: PERMISSION_PROVIDER, useExisting: RbacPermissionProvider },
226
276
  RbacRoleProvider,
227
277
  { provide: ROLE_PROVIDER, useExisting: RbacRoleProvider },
278
+ {
279
+ provide: AUTHZ_RBAC_STORE,
280
+ useFactory: (opts) => opts.store,
281
+ inject: [AUTHZ_RBAC_OPTIONS],
282
+ },
228
283
  AuthzRbacBootstrap,
229
284
  ];
230
285
  }
@@ -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,CAAC;AAGzC,qFAAqF;AACrF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;AACnF,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;AAuCvF,iFAAiF;AACjF,SAAS,eAAe,CAAC,OAA0C;IACjE,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,UAAU;QAAE,OAAO,EAAE,CAAC;IAClE,IAAI,QAA4B,CAAC;IACjC,IAAI,CAAC;QACH,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,QAAQ,GAAG,SAAS,CAAC;IACvB,CAAC;IACD,OAAO,QAAQ,IAAI,IAAI,CAAC,CAA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;YACZ,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAoB;YACnD,SAAS,EAAE,CAAC,eAAe,EAAE,GAAG,iBAAe,CAAC,eAAe,EAAE,CAAC;YAClE,OAAO,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,CAAC;SAChE,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,eAAe;QAC5B,OAAO;YACL,sBAAsB;YACtB,EAAE,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,sBAAsB,EAAE;YACrE,gBAAgB;YAChB,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,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,7 +3,7 @@ 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
8
  export type { UserRef, UserRefInput } from '@dudousxd/nestjs-authz/store-kit';
9
9
  export { applyScope, compileScope } 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,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;AAehC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-authz-drizzle",
3
- "version": "0.2.0",
3
+ "version": "0.3.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.9.0 <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": "22.20.5",
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.0"
69
+ "@dudousxd/nestjs-authz": "^0.9.0"
63
70
  },
64
71
  "engines": {
65
- "node": ">=20"
72
+ "node": ">=22"
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",