@dudousxd/nestjs-authz-prisma 0.5.1 → 1.0.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +20 -6
  3. package/package.json +10 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @dudousxd/nestjs-authz-prisma
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`750a6b3`](https://github.com/DavideCarvalho/nestjs-authz/commit/750a6b3f80deea3803dec8df5f9f8cf67a046ac1)]:
8
+ - @dudousxd/nestjs-authz@0.10.0
9
+
10
+ ## 0.6.0
11
+
12
+ ### Minor Changes
13
+
14
+ - [#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
15
+ permissions now guard routes through the official guard as the core's `RolePolicy` /
16
+ `PermissionPolicy` (`@Roles('editor')`, `@Permission('posts.publish')`), and the guard and the
17
+ handler's `Gate` calls share one permission and role fetch per request. The store API
18
+ (role sources, admin management, tenant-scoped roles where supported) and `AuthzRbacModule`
19
+ are unchanged. A persisted permission named like a policy ability no longer bypasses that
20
+ policy (see the core changeset). Requires NestJS 12, `@nestjs/authorization` ^0.1.3 and Node 22+.
21
+
22
+ ### Patch Changes
23
+
24
+ - [#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.
25
+
3
26
  ## 0.5.1
4
27
 
5
28
  ### Patch Changes
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @dudousxd/nestjs-authz-prisma
2
2
 
3
3
  Prisma RBAC persistence for [`@dudousxd/nestjs-authz`](https://github.com/DavideCarvalho/nestjs-authz) —
4
- roles, permissions, and a Gate seam, with **zero connection ownership** (your app owns the
4
+ roles and permissions for the official `@nestjs/authorization` policies, with **zero connection ownership** (your app owns the
5
5
  `PrismaClient`; this package never opens a connection and never imports `@prisma/client`).
6
6
 
7
7
  This is the Prisma sibling of `@dudousxd/nestjs-authz-typeorm`: identical store surface and
@@ -10,7 +10,7 @@ This is the Prisma sibling of `@dudousxd/nestjs-authz-typeorm`: identical store
10
10
  ## Install
11
11
 
12
12
  ```bash
13
- pnpm add @dudousxd/nestjs-authz-prisma @dudousxd/nestjs-authz
13
+ pnpm add @dudousxd/nestjs-authz-prisma @dudousxd/nestjs-authz @nestjs/authorization
14
14
  ```
15
15
 
16
16
  No `@prisma/client` is required by this package — it depends only on the structural
@@ -92,16 +92,30 @@ AuthzRbacModule.forRootAsync({
92
92
  });
93
93
  ```
94
94
 
95
- Once wired, the Gate consults persisted RBAC:
95
+ Once wired, persisted roles and permissions guard routes through the official
96
+ `@nestjs/authorization` guard, as the core's `RolePolicy` / `PermissionPolicy`:
96
97
 
97
98
  ```ts
98
- await store.givePermissionToRole('editor', 'posts.publish');
99
+ await store.givePermissionToRole('editor', 'posts.*');
99
100
  await store.assignRole({ type: 'user', id: 7 }, 'editor');
100
101
 
101
- gate.forUser(user).allows('posts.publish'); // true (PERMISSION_PROVIDER seam, wildcards supported)
102
- gate.forUser(user).hasRole('editor'); // true (ROLE_PROVIDER seam)
102
+ @Permission('posts.publish') // posts.* grants it
103
+ @Can(PermissionPolicy, 'has', permission('posts.publish')) // the same, spelled out
104
+ @Roles('editor') // @Can(RolePolicy, 'has', roles('editor'))
103
105
  ```
104
106
 
107
+ and in services, through the `Gate`:
108
+
109
+ ```ts
110
+ gate.forUser(user).allows('posts.publish'); // true (PERMISSION_PROVIDER seam)
111
+ gate.forUser(user).allows(PermissionPolicy, 'has', 'posts.publish');
112
+ gate.forUser(user).hasRole('editor'); // true (ROLE_PROVIDER seam)
113
+ ```
114
+
115
+ The user is the one the official guard reads (`AuthorizationModule.forRoot({ getUser })`,
116
+ default `request.user`), mapped to a store ref with `userRefFrom` (default `{ type, id }` or
117
+ `{ id }`).
118
+
105
119
  ## Role sources (manual vs SSO/SCIM)
106
120
 
107
121
  Every role assignment records a `source`. It defaults to `'manual'`, so existing calls and existing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-authz-prisma",
3
- "version": "0.5.1",
3
+ "version": "1.0.0",
4
4
  "description": "Prisma RBAC persistence for @dudousxd/nestjs-authz — roles, permissions, and a Gate seam (zero connection ownership, structural client).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,30 +38,32 @@
38
38
  "CHANGELOG.md"
39
39
  ],
40
40
  "peerDependencies": {
41
- "@dudousxd/nestjs-authz": ">=0.8.0",
42
- "@nestjs/common": ">=10.0.0",
43
- "@nestjs/core": ">=10.0.0",
41
+ "@dudousxd/nestjs-authz": ">=0.10.0",
42
+ "@nestjs/authorization": "^0.1.3",
43
+ "@nestjs/common": "^12.0.0",
44
+ "@nestjs/core": "^12.0.0",
44
45
  "reflect-metadata": ">=0.1.13"
45
46
  },
46
47
  "devDependencies": {
48
+ "@nestjs/authorization": "0.1.3",
47
49
  "@nestjs/common": "12.0.1",
48
50
  "@nestjs/core": "12.0.1",
49
51
  "@nestjs/testing": "12.0.1",
50
52
  "@testcontainers/postgresql": "12.1.0",
51
- "@types/node": "20.19.43",
53
+ "@types/node": "22.20.5",
52
54
  "@types/pg": "8.23.1",
53
55
  "pg": "8.23.0",
54
56
  "reflect-metadata": "0.2.2",
55
57
  "rxjs": "7.8.2",
56
58
  "typescript": "5.9.3",
57
59
  "vitest": "3.2.7",
58
- "@dudousxd/nestjs-authz": "^0.8.1"
60
+ "@dudousxd/nestjs-authz": "^0.10.0"
59
61
  },
60
62
  "engines": {
61
- "node": ">=20"
63
+ "node": ">=22"
62
64
  },
63
65
  "scripts": {
64
- "build": "tsc -p tsconfig.json",
66
+ "build": "tsc -p tsconfig.json --incremental false",
65
67
  "test": "vitest run --passWithNoTests",
66
68
  "test:db:pg": "AUTHZ_TEST_DIALECT=postgres vitest run --config vitest.db.config.ts",
67
69
  "test:watch": "vitest",