@dudousxd/nestjs-authz-typeorm 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,73 @@
1
1
  # @dudousxd/nestjs-authz-typeorm
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#9](https://github.com/DavideCarvalho/nestjs-authz/pull/9) [`07d01de`](https://github.com/DavideCarvalho/nestjs-authz/commit/07d01de286e7dfcae5fbeb10b7e8d48533214087) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Ecosystem improvements across the authz packages.
8
+
9
+ ### Permissions
10
+
11
+ - **Wildcard / hierarchical permissions.** Permission strings now support wildcard
12
+ and hierarchical matching (e.g. `posts:*` or `posts:read:*`), so a single granted
13
+ permission can authorize a family of related actions instead of enumerating each one.
14
+
15
+ ### Authorization decisions
16
+
17
+ - **Deny reason / message surfaced on `ForbiddenException`.** When a check fails, the
18
+ reason for the denial is propagated onto the thrown `ForbiddenException`, making it
19
+ possible to return a meaningful message to the caller and to debug authorization
20
+ failures.
21
+ - **Gate `after` hook.** The Gate now exposes an `after` hook that runs once a decision
22
+ has been made, enabling cross-cutting concerns such as auditing, logging, and metrics.
23
+
24
+ ### Batch authorization
25
+
26
+ - **`allowsMany`** for evaluating multiple permission checks in a single call.
27
+ - **Batch `/authz/can` endpoint** so clients can resolve many checks in one round trip.
28
+ - **`createCanBatch`** client helper that batches `can` calls transparently.
29
+
30
+ ### Performance
31
+
32
+ - **Request-scoped permission cache.** Permissions resolved during a request are cached
33
+ for the lifetime of that request, avoiding repeated lookups on the hot path.
34
+
35
+ ### RBAC adapters (TypeORM)
36
+
37
+ - **Direct user permissions** granted to a user independent of their roles.
38
+ - **Tenant-scoped roles** so the same role can be assigned per tenant in multi-tenant
39
+ deployments.
40
+
41
+ ### Query scoping / policy filter (ABAC)
42
+
43
+ - **ORM-neutral constraint AST.** Policies can produce a portable constraint
44
+ representation describing which rows a subject may access.
45
+ - **Per-ORM application.** The constraint AST is translated and applied for
46
+ **TypeORM**, **MikroORM**, and **Prisma**, giving ABAC-style query scoping that
47
+ filters data at the database layer regardless of the ORM in use.
48
+
49
+ ### Testing
50
+
51
+ - **New `@dudousxd/nestjs-authz-testing` package** with fakes and helpers for testing
52
+ authorization in consumer applications.
53
+ - **Postgres / MySQL testcontainers + contract tests** so the ORM stores are verified
54
+ against real database engines, and a shared contract suite keeps the adapters
55
+ behaviorally consistent.
56
+
57
+ ### Housekeeping
58
+
59
+ - **Packaging hygiene** across the published packages.
60
+
61
+ ## 0.2.1
62
+
63
+ ### Patch Changes
64
+
65
+ - [#2](https://github.com/DavideCarvalho/nestjs-authz/pull/2) [`2ecb0f4`](https://github.com/DavideCarvalho/nestjs-authz/commit/2ecb0f46342fa4527fc01f1097720f2e7bcf9aa7) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - `AuthzRbacModule` now registers a `RoleProvider` under the core `ROLE_PROVIDER` token
66
+ that returns `store.getRolesForUser(...)`, so coarse role checks (`gate.hasRole('teacher')`,
67
+ `@Roles('admin')`) consult the persisted RBAC store too — mirroring the existing
68
+ `PERMISSION_PROVIDER` wiring. Roles from the store are unioned with any read off the user
69
+ object by core's default resolver.
70
+
3
71
  ## 0.2.0
4
72
 
5
73
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"authz-rbac.module.d.ts","sourceRoot":"","sources":["../src/authz-rbac.module.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,aAAa,EAQnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,eAAqD,CAAC;AACnF,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,eAAuD,CAAC;AAEv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AAO,KAAK,OAAO,GAAG,SAAS,CAAC;AAEnE,MAAM,WAAW,sBAAsB;IACrC,uEAAuE;IACvE,KAAK,EAAE,iBAAiB,CAAC;IACzB;;;OAGG;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,SAAS,CAOvE;AA+FD;;;;;;GAMG;AACH,qBACa,eAAe;IAC1B,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,sBAAsB,GAAG,aAAa;IAa9D,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,2BAA2B,GAAG,aAAa;IAsBxE,OAAO,CAAC,MAAM,CAAC,eAAe;CAS/B"}
@@ -11,12 +11,49 @@ 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 { PERMISSION_PROVIDER } from '@dudousxd/nestjs-authz';
14
+ import { CONTEXT_ACCESSOR, PERMISSION_PROVIDER, ROLE_PROVIDER, } from '@dudousxd/nestjs-authz';
15
15
  import { Inject, Injectable, Module, Optional, } from '@nestjs/common';
16
+ import { ModuleRef } from '@nestjs/core';
16
17
  /** Injection token holding the {@link TypeOrmAuthzStore} the RBAC module manages. */
17
18
  export const AUTHZ_RBAC_STORE = Symbol.for('@dudousxd/nestjs-authz-typeorm:store');
18
19
  /** Injection token holding the resolved {@link AuthzRbacModuleOptions}. */
19
20
  export const AUTHZ_RBAC_OPTIONS = Symbol.for('@dudousxd/nestjs-authz-typeorm: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
+ }
34
+ /**
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.
40
+ */
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;
53
+ }
54
+ }
55
+ return cache.value;
56
+ }
20
57
  /** Default mapping: accept a `{ type, id }` ref, a `{ id }` object, or a bare id. */
21
58
  export function defaultUserRefMapper(user) {
22
59
  if (user == null)
@@ -36,22 +73,91 @@ export function defaultUserRefMapper(user) {
36
73
  */
37
74
  let RbacPermissionProvider = class RbacPermissionProvider {
38
75
  options;
39
- constructor(options) {
76
+ context;
77
+ moduleRef;
78
+ contextCache = {
79
+ resolved: false,
80
+ value: undefined,
81
+ };
82
+ constructor(options, context, moduleRef) {
40
83
  this.options = options;
84
+ this.context = context;
85
+ this.moduleRef = moduleRef;
86
+ }
87
+ scope() {
88
+ return tenantScopeFrom(resolveTenantContext(this.context, this.moduleRef, this.contextCache));
41
89
  }
90
+ // The core `PermissionProvider` interface passes an optional `resource` (3rd
91
+ // arg); it is intentionally ignored here. RBAC grants are model-less,
92
+ // named-ability grants (the Laravel/spatie `Gate::before` grant), so the
93
+ // verdict never depends on a specific resource instance. Permissions are scoped
94
+ // by the current tenant (from nestjs-context, when present) — a tenant-scoped
95
+ // role only grants within its tenant; direct user grants always apply.
42
96
  async hasPermission(user, permission) {
43
97
  const map = this.options.userRefFrom ?? defaultUserRefMapper;
44
98
  const ref = map(user);
45
99
  if (ref === undefined)
46
100
  return undefined;
47
- return this.options.store.userHasPermission(ref, permission);
101
+ return this.options.store.userHasPermission(ref, permission, this.scope());
102
+ }
103
+ // Expose the user's full granted permission set so the core can apply
104
+ // Laravel/spatie-style wildcard matching (a granted `posts.*` satisfies a check
105
+ // for `posts.update`, `*` satisfies anything). The matching itself lives in core,
106
+ // so every adapter that lists grants gets wildcard semantics for free.
107
+ async getPermissions(user) {
108
+ const map = this.options.userRefFrom ?? defaultUserRefMapper;
109
+ const ref = map(user);
110
+ if (ref === undefined)
111
+ return undefined;
112
+ return this.options.store.getPermissionsForUser(ref, this.scope());
48
113
  }
49
114
  };
50
115
  RbacPermissionProvider = __decorate([
51
116
  Injectable(),
52
117
  __param(0, Inject(AUTHZ_RBAC_OPTIONS)),
53
- __metadata("design:paramtypes", [Object])
118
+ __param(1, Optional()),
119
+ __param(1, Inject(CONTEXT_ACCESSOR)),
120
+ __param(2, Optional()),
121
+ __metadata("design:paramtypes", [Object, Object, ModuleRef])
54
122
  ], RbacPermissionProvider);
123
+ /**
124
+ * The RBAC {@link RoleProvider} the Gate consults (via the shared {@link ROLE_PROVIDER}
125
+ * token) for coarse role-checks (`gate.hasRole('teacher')`, `@Roles('admin')`). Returns
126
+ * the role names the current user holds in the persisted store. Core unions these with
127
+ * any roles read off the user object by the default `RoleResolver`.
128
+ */
129
+ let RbacRoleProvider = class RbacRoleProvider {
130
+ options;
131
+ context;
132
+ moduleRef;
133
+ contextCache = {
134
+ resolved: false,
135
+ value: undefined,
136
+ };
137
+ constructor(options, context, moduleRef) {
138
+ this.options = options;
139
+ this.context = context;
140
+ this.moduleRef = moduleRef;
141
+ }
142
+ async getRoles(user) {
143
+ const map = this.options.userRefFrom ?? defaultUserRefMapper;
144
+ const ref = map(user);
145
+ if (ref === undefined)
146
+ return undefined;
147
+ // Scope roles by the current tenant (when nestjs-context is present): a
148
+ // tenant-scoped role only counts within its tenant; global roles always count.
149
+ const scope = tenantScopeFrom(resolveTenantContext(this.context, this.moduleRef, this.contextCache));
150
+ return this.options.store.getRolesForUser(ref, scope);
151
+ }
152
+ };
153
+ RbacRoleProvider = __decorate([
154
+ Injectable(),
155
+ __param(0, Inject(AUTHZ_RBAC_OPTIONS)),
156
+ __param(1, Optional()),
157
+ __param(1, Inject(CONTEXT_ACCESSOR)),
158
+ __param(2, Optional()),
159
+ __metadata("design:paramtypes", [Object, Object, ModuleRef])
160
+ ], RbacRoleProvider);
55
161
  /** Runs `ensureAuthzSchema` on bootstrap when `autoCreateSchema` is not disabled. */
56
162
  let AuthzRbacBootstrap = class AuthzRbacBootstrap {
57
163
  options;
@@ -89,7 +195,7 @@ let AuthzRbacModule = AuthzRbacModule_1 = class AuthzRbacModule {
89
195
  { provide: AUTHZ_RBAC_STORE, useValue: options.store },
90
196
  ...AuthzRbacModule_1.commonProviders(),
91
197
  ],
92
- exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER],
198
+ exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER, ROLE_PROVIDER],
93
199
  };
94
200
  }
95
201
  static forRootAsync(options) {
@@ -110,13 +216,15 @@ let AuthzRbacModule = AuthzRbacModule_1 = class AuthzRbacModule {
110
216
  },
111
217
  ...AuthzRbacModule_1.commonProviders(),
112
218
  ],
113
- exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER],
219
+ exports: [AUTHZ_RBAC_STORE, PERMISSION_PROVIDER, ROLE_PROVIDER],
114
220
  };
115
221
  }
116
222
  static commonProviders() {
117
223
  return [
118
224
  RbacPermissionProvider,
119
225
  { provide: PERMISSION_PROVIDER, useExisting: RbacPermissionProvider },
226
+ RbacRoleProvider,
227
+ { provide: ROLE_PROVIDER, useExisting: RbacRoleProvider },
120
228
  AuthzRbacBootstrap,
121
229
  ];
122
230
  }
@@ -1 +1 @@
1
- {"version":3,"file":"authz-rbac.module.js","sourceRoot":"","sources":["../src/authz-rbac.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAE,mBAAmB,EAA2B,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAEL,MAAM,EACN,UAAU,EACV,MAAM,EAEN,QAAQ,GAGT,MAAM,gBAAgB,CAAC;AAIxB,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;AA6BvF,qFAAqF;AACrF,MAAM,UAAU,oBAAoB,CAAC,IAAa;IAChD,IAAI,IAAI,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IACnC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACtE,MAAM,CAAC,GAAG,IAAwC,CAAC;IACnD,IAAI,CAAC,CAAC,EAAE,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IACnC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAqB,CAAC;IACnC,OAAO,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;AACpE,CAAC;AAED;;;;GAIG;AACH,IACM,sBAAsB,GAD5B,MACM,sBAAsB;IAC+B;IAAzD,YAAyD,OAA+B;QAA/B,YAAO,GAAP,OAAO,CAAwB;IAAG,CAAC;IAE5F,KAAK,CAAC,aAAa,CAAC,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";
10
10
  readonly rolePermission: "authz_role_permission";
11
11
  readonly userRole: "authz_user_role";
12
+ readonly userPermission: "authz_user_permission";
12
13
  };
14
+ /**
15
+ * The "no tenant" sentinel for the user-role pivot's `tenantId`. A GLOBAL (unscoped)
16
+ * assignment stores this empty string rather than `NULL` so the column stays part of
17
+ * the composite primary key with portable, dialect-correct uniqueness (SQL treats
18
+ * `NULL`s as distinct, which would break idempotency of a global grant and silently
19
+ * permit duplicates). The column is added post-v1 with a default of this value, so an
20
+ * older populated table self-heals via `ensureAuthzSchema` (`ADD COLUMN ... DEFAULT ''`).
21
+ */
22
+ export declare const GLOBAL_TENANT = "";
13
23
  /**
14
24
  * A named role (e.g. `editor`). Permissions are attached via {@link RolePermissionEntity};
15
25
  * users are attached via {@link UserRoleEntity}.
@@ -40,12 +50,31 @@ export declare class RolePermissionEntity {
40
50
  * Pivot: user ↔ role. References the user BY ID ONLY — this package NEVER defines or
41
51
  * owns a users table. `userType` lets the same table key polymorphic principals
42
52
  * (mirrors nestjs-context's `UserRef` shape).
53
+ *
54
+ * `tenantId` (post-v1, defaulted to {@link GLOBAL_TENANT} = `''`) scopes the
55
+ * assignment to a tenant: an empty value = global (applies in every tenant), a
56
+ * non-empty value = only within that tenant. It is part of the composite PK so the
57
+ * same `(user, role)` can be granted independently in multiple tenants while staying
58
+ * idempotent per tenant. Defaulted (not nullable) so the column belongs to the PK
59
+ * with portable uniqueness — see {@link GLOBAL_TENANT}.
43
60
  */
44
61
  export declare class UserRoleEntity {
45
62
  userType: string;
46
63
  userId: string;
47
64
  roleId: string;
65
+ tenantId: string;
66
+ }
67
+ /**
68
+ * Pivot: user ↔ permission (a DIRECT grant, no role needed — Laravel/spatie's
69
+ * `$user->givePermissionTo(...)`). Mirrors {@link UserRoleEntity}: the user is
70
+ * referenced BY ID ONLY and `userType` keys polymorphic principals. Composite PK
71
+ * `(userType, userId, permissionId)`.
72
+ */
73
+ export declare class UserPermissionEntity {
74
+ userType: string;
75
+ userId: string;
76
+ permissionId: string;
48
77
  }
49
78
  /** All entities, in dependency order — convenient for `entities: [...]` registration. */
50
- export declare const AUTHZ_ENTITIES: readonly [typeof RoleEntity, typeof PermissionEntity, typeof RolePermissionEntity, typeof UserRoleEntity];
79
+ export declare const AUTHZ_ENTITIES: readonly [typeof RoleEntity, typeof PermissionEntity, typeof RolePermissionEntity, typeof UserRoleEntity, typeof UserPermissionEntity];
51
80
  //# sourceMappingURL=entities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;CAKtB,CAAC;AAEX;;;;;;;GAOG;AACH,qBACa,UAAU;IAErB,EAAE,EAAG,MAAM,CAAC;IAIZ,IAAI,EAAG,MAAM,CAAC;IAGd,KAAK,EAAG,MAAM,GAAG,IAAI,CAAC;IAGtB,SAAS,EAAG,IAAI,CAAC;CAClB;AAED,oGAAoG;AACpG,qBACa,gBAAgB;IAE3B,EAAE,EAAG,MAAM,CAAC;IAIZ,IAAI,EAAG,MAAM,CAAC;IAGd,KAAK,EAAG,MAAM,GAAG,IAAI,CAAC;IAGtB,SAAS,EAAG,IAAI,CAAC;CAClB;AAED,uEAAuE;AACvE,qBACa,oBAAoB;IAE/B,MAAM,EAAG,MAAM,CAAC;IAGhB,YAAY,EAAG,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,qBAEa,cAAc;IAEzB,QAAQ,EAAG,MAAM,CAAC;IAGlB,MAAM,EAAG,MAAM,CAAC;IAGhB,MAAM,EAAG,MAAM,CAAC;CACjB;AAED,yFAAyF;AACzF,eAAO,MAAM,cAAc,2GAKjB,CAAC"}
1
+ {"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;CAMtB,CAAC;AAEX;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC;;;;;;;GAOG;AACH,qBACa,UAAU;IAErB,EAAE,EAAG,MAAM,CAAC;IAIZ,IAAI,EAAG,MAAM,CAAC;IAGd,KAAK,EAAG,MAAM,GAAG,IAAI,CAAC;IAGtB,SAAS,EAAG,IAAI,CAAC;CAClB;AAED,oGAAoG;AACpG,qBACa,gBAAgB;IAE3B,EAAE,EAAG,MAAM,CAAC;IAIZ,IAAI,EAAG,MAAM,CAAC;IAGd,KAAK,EAAG,MAAM,GAAG,IAAI,CAAC;IAGtB,SAAS,EAAG,IAAI,CAAC;CAClB;AAED,uEAAuE;AACvE,qBACa,oBAAoB;IAE/B,MAAM,EAAG,MAAM,CAAC;IAGhB,YAAY,EAAG,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;GAWG;AACH,qBAEa,cAAc;IAEzB,QAAQ,EAAG,MAAM,CAAC;IAGlB,MAAM,EAAG,MAAM,CAAC;IAGhB,MAAM,EAAG,MAAM,CAAC;IAGhB,QAAQ,EAAG,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,qBAEa,oBAAoB;IAE/B,QAAQ,EAAG,MAAM,CAAC;IAGlB,MAAM,EAAG,MAAM,CAAC;IAGhB,YAAY,EAAG,MAAM,CAAC;CACvB;AAED,yFAAyF;AACzF,eAAO,MAAM,cAAc,wIAMjB,CAAC"}
package/dist/entities.js CHANGED
@@ -19,7 +19,17 @@ export const DEFAULT_TABLE_NAMES = {
19
19
  permissions: 'authz_permissions',
20
20
  rolePermission: 'authz_role_permission',
21
21
  userRole: 'authz_user_role',
22
+ userPermission: 'authz_user_permission',
22
23
  };
24
+ /**
25
+ * The "no tenant" sentinel for the user-role pivot's `tenantId`. A GLOBAL (unscoped)
26
+ * assignment stores this empty string rather than `NULL` so the column stays part of
27
+ * the composite primary key with portable, dialect-correct uniqueness (SQL treats
28
+ * `NULL`s as distinct, which would break idempotency of a global grant and silently
29
+ * permit duplicates). The column is added post-v1 with a default of this value, so an
30
+ * older populated table self-heals via `ensureAuthzSchema` (`ADD COLUMN ... DEFAULT ''`).
31
+ */
32
+ export const GLOBAL_TENANT = '';
23
33
  /**
24
34
  * A named role (e.g. `editor`). Permissions are attached via {@link RolePermissionEntity};
25
35
  * users are attached via {@link UserRoleEntity}.
@@ -104,11 +114,19 @@ export { RolePermissionEntity };
104
114
  * Pivot: user ↔ role. References the user BY ID ONLY — this package NEVER defines or
105
115
  * owns a users table. `userType` lets the same table key polymorphic principals
106
116
  * (mirrors nestjs-context's `UserRef` shape).
117
+ *
118
+ * `tenantId` (post-v1, defaulted to {@link GLOBAL_TENANT} = `''`) scopes the
119
+ * assignment to a tenant: an empty value = global (applies in every tenant), a
120
+ * non-empty value = only within that tenant. It is part of the composite PK so the
121
+ * same `(user, role)` can be granted independently in multiple tenants while staying
122
+ * idempotent per tenant. Defaulted (not nullable) so the column belongs to the PK
123
+ * with portable uniqueness — see {@link GLOBAL_TENANT}.
107
124
  */
108
125
  let UserRoleEntity = class UserRoleEntity {
109
126
  userType;
110
127
  userId;
111
128
  roleId;
129
+ tenantId;
112
130
  };
113
131
  __decorate([
114
132
  PrimaryColumn({ type: 'varchar', length: 191 }),
@@ -122,16 +140,49 @@ __decorate([
122
140
  PrimaryColumn({ type: 'varchar', length: 191 }),
123
141
  __metadata("design:type", String)
124
142
  ], UserRoleEntity.prototype, "roleId", void 0);
143
+ __decorate([
144
+ PrimaryColumn({ type: 'varchar', length: 191, default: GLOBAL_TENANT }),
145
+ __metadata("design:type", String)
146
+ ], UserRoleEntity.prototype, "tenantId", void 0);
125
147
  UserRoleEntity = __decorate([
126
148
  Entity({ name: DEFAULT_TABLE_NAMES.userRole }),
127
149
  Index(['userType', 'userId'])
128
150
  ], UserRoleEntity);
129
151
  export { UserRoleEntity };
152
+ /**
153
+ * Pivot: user ↔ permission (a DIRECT grant, no role needed — Laravel/spatie's
154
+ * `$user->givePermissionTo(...)`). Mirrors {@link UserRoleEntity}: the user is
155
+ * referenced BY ID ONLY and `userType` keys polymorphic principals. Composite PK
156
+ * `(userType, userId, permissionId)`.
157
+ */
158
+ let UserPermissionEntity = class UserPermissionEntity {
159
+ userType;
160
+ userId;
161
+ permissionId;
162
+ };
163
+ __decorate([
164
+ PrimaryColumn({ type: 'varchar', length: 191 }),
165
+ __metadata("design:type", String)
166
+ ], UserPermissionEntity.prototype, "userType", void 0);
167
+ __decorate([
168
+ PrimaryColumn({ type: 'varchar', length: 191 }),
169
+ __metadata("design:type", String)
170
+ ], UserPermissionEntity.prototype, "userId", void 0);
171
+ __decorate([
172
+ PrimaryColumn({ type: 'varchar', length: 191 }),
173
+ __metadata("design:type", String)
174
+ ], UserPermissionEntity.prototype, "permissionId", void 0);
175
+ UserPermissionEntity = __decorate([
176
+ Entity({ name: DEFAULT_TABLE_NAMES.userPermission }),
177
+ Index(['userType', 'userId'])
178
+ ], UserPermissionEntity);
179
+ export { UserPermissionEntity };
130
180
  /** All entities, in dependency order — convenient for `entities: [...]` registration. */
131
181
  export const AUTHZ_ENTITIES = [
132
182
  RoleEntity,
133
183
  PermissionEntity,
134
184
  RolePermissionEntity,
135
185
  UserRoleEntity,
186
+ UserPermissionEntity,
136
187
  ];
137
188
  //# sourceMappingURL=entities.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"entities.js","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,KAAK,EAAE,aAAa;IACpB,WAAW,EAAE,mBAAmB;IAChC,cAAc,EAAE,uBAAuB;IACvC,QAAQ,EAAE,iBAAiB;CACnB,CAAC;AAEX;;;;;;;GAOG;AAEI,IAAM,UAAU,GAAhB,MAAM,UAAU;IAErB,EAAE,CAAU;IAIZ,IAAI,CAAU;IAGd,KAAK,CAAiB;IAGtB,SAAS,CAAQ;CAClB,C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,EAAE,CAAC;;gDACtD;AAXP,cAAc;IAF1B,MAAM,CAAC,EAAE,IAAI,EAAE,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IAC9C,KAAK,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;GACjB,cAAc,CAY1B;;AAED;;;;;GAKG;AAGI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAE/B,QAAQ,CAAU;IAGlB,MAAM,CAAU;IAGhB,YAAY,CAAU;CACvB,CAAA;AAPC;IADC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;sDAC9B;AAGlB;IADC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;oDAChC;AAGhB;IADC,aAAa,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;;0DAC1B;AARX,oBAAoB;IAFhC,MAAM,CAAC,EAAE,IAAI,EAAE,mBAAmB,CAAC,cAAc,EAAE,CAAC;IACpD,KAAK,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;GACjB,oBAAoB,CAShC;;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,UAAU;IACV,gBAAgB;IAChB,oBAAoB;IACpB,cAAc;IACd,oBAAoB;CACZ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export { AUTHZ_ENTITIES, DEFAULT_TABLE_NAMES, PermissionEntity, RoleEntity, RolePermissionEntity, UserRoleEntity, } from './entities.js';
1
+ export { AUTHZ_ENTITIES, DEFAULT_TABLE_NAMES, GLOBAL_TENANT, PermissionEntity, RoleEntity, RolePermissionEntity, UserPermissionEntity, UserRoleEntity, } from './entities.js';
2
2
  export { createAuthzTables, ensureAuthzSchema } from './schema.js';
3
3
  export { TypeOrmAuthzStore } from './typeorm-authz.store.js';
4
4
  export type { UserAuthz } from './typeorm-authz.store.js';
5
5
  export { AUTHZ_RBAC_OPTIONS, AUTHZ_RBAC_STORE, AuthzRbacModule, defaultUserRefMapper, } from './authz-rbac.module.js';
6
6
  export type { AuthzRbacModuleAsyncOptions, AuthzRbacModuleOptions, UserRefMapper, } from './authz-rbac.module.js';
7
- export type { AuthzStoreOptions, TableNames, UserRef, UserRefInput } from './types.js';
7
+ export type { AuthzStoreOptions, TableNames, TenantScope, UserRef, UserRefInput, } from './types.js';
8
+ export { applyScope, applyScopeConstraint, compileScope } from './scope.js';
9
+ export type { CompiledScope, ScopeResolver } from './scope.js';
8
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,oBAAoB,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,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,EAAE,iBAAiB,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,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,UAAU,EACV,WAAW,EACX,OAAO,EACP,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5E,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
- export { AUTHZ_ENTITIES, DEFAULT_TABLE_NAMES, PermissionEntity, RoleEntity, RolePermissionEntity, UserRoleEntity, } from './entities.js';
1
+ export { AUTHZ_ENTITIES, DEFAULT_TABLE_NAMES, GLOBAL_TENANT, PermissionEntity, RoleEntity, RolePermissionEntity, UserPermissionEntity, UserRoleEntity, } from './entities.js';
2
2
  export { createAuthzTables, ensureAuthzSchema } from './schema.js';
3
3
  export { TypeOrmAuthzStore } from './typeorm-authz.store.js';
4
4
  export { AUTHZ_RBAC_OPTIONS, AUTHZ_RBAC_STORE, AuthzRbacModule, defaultUserRefMapper, } from './authz-rbac.module.js';
5
+ export { applyScope, applyScopeConstraint, compileScope } from './scope.js';
5
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,oBAAoB,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,WAAW,EAGjB,MAAM,SAAS,CAAC;AAUjB,OAAO,KAAK,EAAE,iBAAiB,EAAc,MAAM,YAAY,CAAC;AAuDhE;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,WAAW,EACxB,IAAI,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAOf;AA4BD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,UAAU,EACtB,IAAI,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAef"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,WAAW,EAGjB,MAAM,SAAS,CAAC;AAWjB,OAAO,KAAK,EAAE,iBAAiB,EAAc,MAAM,YAAY,CAAC;AAqFhE;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CACrC,WAAW,EAAE,WAAW,EACxB,IAAI,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAUf;AA4BD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,UAAU,EACtB,IAAI,CAAC,EAAE,iBAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAkBf"}
package/dist/schema.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Table, TableColumn, } from 'typeorm';
2
2
  import { TableUtils } from 'typeorm/schema-builder/util/TableUtils.js';
3
- import { DEFAULT_TABLE_NAMES, PermissionEntity, RoleEntity, RolePermissionEntity, UserRoleEntity, } from './entities.js';
3
+ import { DEFAULT_TABLE_NAMES, PermissionEntity, RoleEntity, RolePermissionEntity, UserPermissionEntity, UserRoleEntity, } from './entities.js';
4
4
  import { assertSafeIdentifier } from './sql.js';
5
5
  /** Resolve the (schema-qualified) table name for an entity, applying BYO overrides. */
6
6
  function tableName(base, schema) {
@@ -12,6 +12,7 @@ function resolveNames(tableNames) {
12
12
  permissions: tableNames?.permissions ?? DEFAULT_TABLE_NAMES.permissions,
13
13
  rolePermission: tableNames?.rolePermission ?? DEFAULT_TABLE_NAMES.rolePermission,
14
14
  userRole: tableNames?.userRole ?? DEFAULT_TABLE_NAMES.userRole,
15
+ userPermission: tableNames?.userPermission ?? DEFAULT_TABLE_NAMES.userPermission,
15
16
  };
16
17
  }
17
18
  /** The four table plans (entity + resolved name) for a given options set. */
@@ -29,16 +30,39 @@ function plans(opts) {
29
30
  { entity: PermissionEntity, name: tableName(names.permissions, schema) },
30
31
  { entity: RolePermissionEntity, name: tableName(names.rolePermission, schema) },
31
32
  { entity: UserRoleEntity, name: tableName(names.userRole, schema) },
33
+ { entity: UserPermissionEntity, name: tableName(names.userPermission, schema) },
32
34
  ];
33
35
  }
34
36
  /**
35
37
  * Build a driver-portable {@link Table} from entity metadata, overriding the table name
36
38
  * so BYO names + an optional Postgres schema are honored (the metadata's own name is the
37
39
  * entity-decorator default).
40
+ *
41
+ * Constraint-name rewrite (Postgres-critical): TypeORM derives index / unique / primary-key
42
+ * names by hashing the table name + columns (see `DefaultNamingStrategy.indexName` et al.).
43
+ * `Table.create` computes those from the entity's DEFAULT name, so simply reassigning
44
+ * `table.name` leaves the constraints carrying the OLD name's hash. Two tables created from
45
+ * the SAME entity metadata under DIFFERENT runtime names (BYO table names, or a per-test
46
+ * unique prefix) then emit IDENTICAL constraint names. SQLite scopes index names per-table
47
+ * and tolerates this; Postgres treats index/constraint names as schema-global and rejects
48
+ * the second `CREATE TABLE` with `relation "IDX_..." already exists`. So after renaming we
49
+ * regenerate every constraint name from the NEW table name via the connection's naming
50
+ * strategy, keeping each created table's constraints globally unique.
38
51
  */
39
- function tableFromMetadata(metadata, driver, name) {
52
+ function tableFromMetadata(connection, metadata, driver, name) {
40
53
  const table = Table.create(metadata, driver);
41
54
  table.name = name;
55
+ const naming = connection.namingStrategy;
56
+ for (const index of table.indices) {
57
+ index.name = naming.indexName(name, index.columnNames, index.where);
58
+ }
59
+ for (const unique of table.uniques) {
60
+ unique.name = naming.uniqueConstraintName(name, unique.columnNames);
61
+ }
62
+ for (const check of table.checks) {
63
+ if (check.expression)
64
+ check.name = naming.checkConstraintName(name, check.expression);
65
+ }
42
66
  return table;
43
67
  }
44
68
  /**
@@ -60,7 +84,7 @@ export async function createAuthzTables(queryRunner, opts) {
60
84
  if (await queryRunner.hasTable(plan.name))
61
85
  continue;
62
86
  const metadata = queryRunner.connection.getMetadata(plan.entity);
63
- await queryRunner.createTable(tableFromMetadata(metadata, driver, plan.name), true);
87
+ await queryRunner.createTable(tableFromMetadata(queryRunner.connection, metadata, driver, plan.name), true);
64
88
  }
65
89
  }
66
90
  /**
@@ -105,7 +129,7 @@ export async function ensureAuthzSchema(dataSource, opts) {
105
129
  }
106
130
  else {
107
131
  const metadata = queryRunner.connection.getMetadata(plan.entity);
108
- await queryRunner.createTable(tableFromMetadata(metadata, driver, plan.name), true);
132
+ await queryRunner.createTable(tableFromMetadata(queryRunner.connection, metadata, driver, plan.name), true);
109
133
  }
110
134
  }
111
135
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,EACL,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,UAAU,EACV,oBAAoB,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAShD,uFAAuF;AACvF,SAAS,SAAS,CAAC,IAAY,EAAE,MAA0B;IACzD,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7C,CAAC;AAED,SAAS,YAAY,CAAC,UAAkC;IAMtD,OAAO;QACL,KAAK,EAAE,UAAU,EAAE,KAAK,IAAI,mBAAmB,CAAC,KAAK;QACrD,WAAW,EAAE,UAAU,EAAE,WAAW,IAAI,mBAAmB,CAAC,WAAW;QACvE,cAAc,EAAE,UAAU,EAAE,cAAc,IAAI,mBAAmB,CAAC,cAAc;QAChF,QAAQ,EAAE,UAAU,EAAE,QAAQ,IAAI,mBAAmB,CAAC,QAAQ;KAC/D,CAAC;AACJ,CAAC;AAED,6EAA6E;AAC7E,SAAS,KAAK,CAAC,IAAmC;IAChD,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,EAAE,UA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U,iBAAiB,CACrC,UAAsB,EACtB,IAAwB;IAExB,MAAM,WAAW,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;IACnD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;QACjC,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,IAAI,MAAM,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1C,MAAM,iBAAiB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YAC7C,CAAC;iBAAM,CAAC;gBACN,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACjE,MAAM,WAAW,CAAC,WAAW,CAC3B,iBAAiB,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,EACtE,IAAI,CACL,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC"}
@@ -0,0 +1,75 @@
1
+ import type { ScopeConstraint } from '@dudousxd/nestjs-authz';
2
+ import type { Type } from '@nestjs/common';
3
+ import type { ObjectLiteral, SelectQueryBuilder } from 'typeorm';
4
+ /**
5
+ * The minimal scope-resolving surface shared by `Gate` and `BoundGate`. Accepting
6
+ * this (rather than `Gate`) lets {@link applyScope} take either a Gate (current/context
7
+ * user) or a `gate.forUser(...)` BoundGate without a cast.
8
+ */
9
+ export interface ScopeResolver {
10
+ scope(entity: Type<unknown>, ability?: string): Promise<ScopeConstraint>;
11
+ }
12
+ /**
13
+ * A compiled scope predicate: a SQL fragment using TypeORM named placeholders
14
+ * (`:name`, `:...name` for `IN`) plus the parameter map to bind. TypeORM binds the
15
+ * values itself (dialect-correct), so we never interpolate values — only identifiers,
16
+ * which are validated by {@link assertSafeIdentifier}.
17
+ */
18
+ export interface CompiledScope {
19
+ sql: string;
20
+ params: ObjectLiteral;
21
+ }
22
+ /**
23
+ * Quote a SQL identifier. Defaults to ANSI double-quotes (Postgres / SQLite), but a
24
+ * dialect-correct escaper can be injected — MySQL/MariaDB quote with backticks and
25
+ * REJECT `"..."` as an identifier, so `applyScopeConstraint` passes the DataSource's
26
+ * `driver.escape` to make the compiled predicate portable across engines.
27
+ */
28
+ export type EscapeIdentifier = (identifier: string) => string;
29
+ /**
30
+ * Compile an ORM-neutral {@link ScopeConstraint} into a parameterized SQL predicate
31
+ * for TypeORM. Returns:
32
+ * - `undefined` for `allow-all` — the caller adds NO `WHERE` (every row is visible);
33
+ * - `{ sql: '1 = 0', params: {} }` for `deny-all` — an always-false predicate;
34
+ * - otherwise the compiled condition tree.
35
+ *
36
+ * `paramPrefix` namespaces the generated placeholders so multiple `applyScope` calls
37
+ * (or other `andWhere`s) on one query never collide. `alias` (the entity's query
38
+ * alias) prefixes every column as `"alias"."field"`; omit it to emit bare `"field"`.
39
+ *
40
+ * SAFE: column names and the alias are interpolated into SQL, so each is validated
41
+ * against the package's `assertSafeIdentifier` allowlist (letters/digits/underscore,
42
+ * not leading-digit) — a hostile field/alias throws. Values are NEVER interpolated;
43
+ * they are returned in `params` for TypeORM to bind.
44
+ *
45
+ * `escapeId` controls identifier quoting; it defaults to ANSI double-quotes (Postgres /
46
+ * SQLite). `applyScopeConstraint` injects the DataSource's `driver.escape` so the
47
+ * predicate is also valid on MySQL/MariaDB (backtick-quoted), which rejects `"..."`.
48
+ */
49
+ export declare function compileScope(constraint: ScopeConstraint, paramPrefix: string, alias?: string, escapeId?: EscapeIdentifier): CompiledScope | undefined;
50
+ /**
51
+ * Apply a {@link ScopeConstraint} to a TypeORM {@link SelectQueryBuilder} as an
52
+ * `andWhere`, parameterized and identifier-safe. `allow-all` adds nothing; `deny-all`
53
+ * adds an always-false predicate so the query returns no rows.
54
+ *
55
+ * The query's primary alias is used to qualify columns (so the predicate is correct
56
+ * across joins). Each call uses a fresh parameter prefix, so repeated calls never
57
+ * clash. Returns the same builder for chaining.
58
+ */
59
+ export declare function applyScopeConstraint<T extends ObjectLiteral>(qb: SelectQueryBuilder<T>, constraint: ScopeConstraint): SelectQueryBuilder<T>;
60
+ /**
61
+ * Ergonomic entry point: resolve the query scope for the current (context) user via
62
+ * the {@link Gate} and apply it to `qb` in one call. Equivalent to
63
+ * `applyScopeConstraint(qb, await gate.scope(entity, ability))`.
64
+ *
65
+ * The manual path (`gate.scope(...)` + `applyScopeConstraint(...)`) remains primary;
66
+ * this just folds the two steps together for the common list-endpoint case.
67
+ *
68
+ * ```ts
69
+ * const qb = repo.createQueryBuilder('post');
70
+ * await applyScope(qb, gate, Post); // current user's accessible posts
71
+ * const posts = await qb.getMany();
72
+ * ```
73
+ */
74
+ export declare function applyScope<T extends ObjectLiteral>(qb: SelectQueryBuilder<T>, gate: ScopeResolver, entity: Type<unknown>, ability?: string): Promise<SelectQueryBuilder<T>>;
75
+ //# sourceMappingURL=scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.d.ts","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAGhB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGjE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC1E;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,aAAa,CAAC;CACvB;AAKD;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,CAAC;AAa9D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,eAAe,EAC3B,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,GAAE,gBAA4B,GACrC,aAAa,GAAG,SAAS,CA+C3B;AAID;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,aAAa,EAC1D,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EACzB,UAAU,EAAE,eAAe,GAC1B,kBAAkB,CAAC,CAAC,CAAC,CAQvB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAAC,CAAC,SAAS,aAAa,EACtD,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC,EACzB,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,EACrB,OAAO,SAAY,GAClB,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAEhC"}
package/dist/scope.js ADDED
@@ -0,0 +1,124 @@
1
+ import { assertSafeIdentifier } from './sql.js';
2
+ /** An always-false predicate (deny-all / empty `IN`). Binds no parameters. */
3
+ const ALWAYS_FALSE = { sql: '1 = 0', params: {} };
4
+ const ansiQuote = (id) => `"${id}"`;
5
+ /** TypeORM/SQL operator tokens for the binary comparison operators. */
6
+ const BINARY_OPS = {
7
+ eq: '=',
8
+ ne: '!=',
9
+ gt: '>',
10
+ gte: '>=',
11
+ lt: '<',
12
+ lte: '<=',
13
+ };
14
+ /**
15
+ * Compile an ORM-neutral {@link ScopeConstraint} into a parameterized SQL predicate
16
+ * for TypeORM. Returns:
17
+ * - `undefined` for `allow-all` — the caller adds NO `WHERE` (every row is visible);
18
+ * - `{ sql: '1 = 0', params: {} }` for `deny-all` — an always-false predicate;
19
+ * - otherwise the compiled condition tree.
20
+ *
21
+ * `paramPrefix` namespaces the generated placeholders so multiple `applyScope` calls
22
+ * (or other `andWhere`s) on one query never collide. `alias` (the entity's query
23
+ * alias) prefixes every column as `"alias"."field"`; omit it to emit bare `"field"`.
24
+ *
25
+ * SAFE: column names and the alias are interpolated into SQL, so each is validated
26
+ * against the package's `assertSafeIdentifier` allowlist (letters/digits/underscore,
27
+ * not leading-digit) — a hostile field/alias throws. Values are NEVER interpolated;
28
+ * they are returned in `params` for TypeORM to bind.
29
+ *
30
+ * `escapeId` controls identifier quoting; it defaults to ANSI double-quotes (Postgres /
31
+ * SQLite). `applyScopeConstraint` injects the DataSource's `driver.escape` so the
32
+ * predicate is also valid on MySQL/MariaDB (backtick-quoted), which rejects `"..."`.
33
+ */
34
+ export function compileScope(constraint, paramPrefix, alias, escapeId = ansiQuote) {
35
+ if (constraint.kind === 'all')
36
+ return undefined;
37
+ if (constraint.kind === 'none')
38
+ return ALWAYS_FALSE;
39
+ if (alias !== undefined)
40
+ assertSafeIdentifier(alias, `scope alias "${alias}"`);
41
+ const params = {};
42
+ let counter = 0;
43
+ const nextParam = () => `${paramPrefix}_${counter++}`;
44
+ const column = (field) => {
45
+ assertSafeIdentifier(field, `scope field "${field}"`);
46
+ return alias === undefined ? escapeId(field) : `${escapeId(alias)}.${escapeId(field)}`;
47
+ };
48
+ const compileCondition = (c) => {
49
+ const col = column(c.field);
50
+ if (c.op === 'isNull')
51
+ return `${col} IS NULL`;
52
+ if (c.op === 'isNotNull')
53
+ return `${col} IS NOT NULL`;
54
+ if (c.op === 'in' || c.op === 'nin') {
55
+ const values = Array.isArray(c.value) ? c.value : [c.value];
56
+ // An empty `IN ()` is invalid SQL and matches nothing; an empty `NOT IN ()`
57
+ // matches everything. Encode both with constant predicates.
58
+ if (values.length === 0)
59
+ return c.op === 'in' ? '1 = 0' : '1 = 1';
60
+ const name = nextParam();
61
+ params[name] = values;
62
+ const not = c.op === 'nin' ? 'NOT ' : '';
63
+ return `${col} ${not}IN (:...${name})`;
64
+ }
65
+ const token = BINARY_OPS[c.op];
66
+ if (!token)
67
+ throw new Error(`Unsupported scope operator: ${c.op}`);
68
+ const name = nextParam();
69
+ params[name] = c.value;
70
+ return `${col} ${token} :${name}`;
71
+ };
72
+ const compileNode = (node) => {
73
+ if (node.kind === 'condition')
74
+ return compileCondition(node);
75
+ const joiner = node.kind === 'and' ? ' AND ' : ' OR ';
76
+ // An empty AND is the identity (true); an empty OR is the zero (false).
77
+ if (node.nodes.length === 0)
78
+ return node.kind === 'and' ? '1 = 1' : '1 = 0';
79
+ return `(${node.nodes.map(compileNode).join(joiner)})`;
80
+ };
81
+ const sql = compileNode(constraint);
82
+ // A top-level empty `IN` collapses to the always-false constant with no params.
83
+ if (sql === '1 = 0' && Object.keys(params).length === 0)
84
+ return ALWAYS_FALSE;
85
+ return { sql, params };
86
+ }
87
+ let scopeApplyCounter = 0;
88
+ /**
89
+ * Apply a {@link ScopeConstraint} to a TypeORM {@link SelectQueryBuilder} as an
90
+ * `andWhere`, parameterized and identifier-safe. `allow-all` adds nothing; `deny-all`
91
+ * adds an always-false predicate so the query returns no rows.
92
+ *
93
+ * The query's primary alias is used to qualify columns (so the predicate is correct
94
+ * across joins). Each call uses a fresh parameter prefix, so repeated calls never
95
+ * clash. Returns the same builder for chaining.
96
+ */
97
+ export function applyScopeConstraint(qb, constraint) {
98
+ const prefix = `authz_scope_${scopeApplyCounter++}`;
99
+ // Quote identifiers with the DataSource's own dialect-correct escaper so the predicate
100
+ // is valid on MySQL/MariaDB (backticks) as well as Postgres/SQLite (double-quotes).
101
+ const escapeId = (id) => qb.connection.driver.escape(id);
102
+ const compiled = compileScope(constraint, prefix, qb.alias, escapeId);
103
+ if (compiled)
104
+ qb.andWhere(compiled.sql, compiled.params);
105
+ return qb;
106
+ }
107
+ /**
108
+ * Ergonomic entry point: resolve the query scope for the current (context) user via
109
+ * the {@link Gate} and apply it to `qb` in one call. Equivalent to
110
+ * `applyScopeConstraint(qb, await gate.scope(entity, ability))`.
111
+ *
112
+ * The manual path (`gate.scope(...)` + `applyScopeConstraint(...)`) remains primary;
113
+ * this just folds the two steps together for the common list-endpoint case.
114
+ *
115
+ * ```ts
116
+ * const qb = repo.createQueryBuilder('post');
117
+ * await applyScope(qb, gate, Post); // current user's accessible posts
118
+ * const posts = await qb.getMany();
119
+ * ```
120
+ */
121
+ export async function applyScope(qb, gate, entity, ability = 'viewAny') {
122
+ return applyScopeConstraint(qb, await gate.scope(entity, ability));
123
+ }
124
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAsBhD,8EAA8E;AAC9E,MAAM,YAAY,GAAkB,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AASjE,MAAM,SAAS,GAAqB,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC;AAEtD,uEAAuE;AACvE,MAAM,UAAU,GAA2C;IACzD,EAAE,EAAE,GAAG;IACP,EAAE,EAAE,IAAI;IACR,EAAE,EAAE,GAAG;IACP,GAAG,EAAE,IAAI;IACT,EAAE,EAAE,GAAG;IACP,GAAG,EAAE,IAAI;CACV,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,YAAY,CAC1B,UAA2B,EAC3B,WAAmB,EACnB,KAAc,EACd,WAA6B,SAAS;IAEtC,IAAI,UAAU,CAAC,IAAI,KAAK,KAAK;QAAE,OAAO,SAAS,CAAC;IAChD,IAAI,UAAU,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,YAAY,CAAC;IACpD,IAAI,KAAK,KAAK,SAAS;QAAE,oBAAoB,CAAC,KAAK,EAAE,gBAAgB,KAAK,GAAG,CAAC,CAAC;IAE/E,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,IAAI,OAAO,GA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AAG,EAAE,MAAM,EAAE,CAAC;AACzB,CAAC;AAED,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,EAAyB,EACzB,UAA2B;IAE3B,MAAM,MAAM,GAAG,eAAe,iBAAiB,EAAE,EAAE,CAAC;IACpD,uFAAuF;IACvF,oFAAoF;IACpF,MAAM,QAAQ,GAAqB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3E,MAAM,QAAQ,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACtE,IAAI,QAAQ;QAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACzD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,EAAyB,EACzB,IAAmB,EACnB,MAAqB,EACrB,OAAO,GAAG,SAAS;IAEnB,OAAO,oBAAoB,CAAC,EAAE,EAAE,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AACrE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { DataSource } from 'typeorm';
2
- import type { AuthzStoreOptions, UserRef } from './types.js';
2
+ import type { AuthzStoreOptions, TenantScope, UserRef } from './types.js';
3
3
  /**
4
4
  * A user's effective permissions: the role names they hold and the flattened set of
5
5
  * permission names granted by those roles.
@@ -48,17 +48,61 @@ export declare class TypeOrmAuthzStore {
48
48
  givePermissionToRole(roleName: string, permissionName: string): Promise<void>;
49
49
  /** Revoke a permission from a role. No-op if either is absent or not linked. */
50
50
  revokePermissionFromRole(roleName: string, permissionName: string): Promise<void>;
51
- /** Assign a role to a user (creating the role by name if needed). Idempotent. */
52
- assignRole(user: UserRef, roleName: string): Promise<void>;
53
- /** Remove a role from a user. No-op if the role or assignment is absent. */
54
- removeRole(user: UserRef, roleName: string): Promise<void>;
55
- /** The role names a user holds. */
56
- getRolesForUser(user: UserRef): Promise<string[]>;
57
- /** The flattened, distinct permission names a user has via their roles. */
58
- getPermissionsForUser(user: UserRef): Promise<string[]>;
59
- /** A user's roles + effective permissions in one shot. */
60
- getUserAuthz(user: UserRef): Promise<UserAuthz>;
61
- /** True when the user holds `permission` through any of their roles. */
62
- userHasPermission(user: UserRef, permission: string): Promise<boolean>;
51
+ /**
52
+ * Assign a role to a user (creating the role by name if needed). Idempotent.
53
+ *
54
+ * Pass `{ tenantId }` to scope the assignment to a tenant — it then applies ONLY
55
+ * within that tenant. Omitting it (the default) makes a GLOBAL assignment that
56
+ * applies in every tenant (and in an unscoped check). The same `(user, role)` can
57
+ * be assigned in multiple tenants independently.
58
+ */
59
+ assignRole(user: UserRef, roleName: string, scope?: TenantScope): Promise<void>;
60
+ /**
61
+ * Remove a role from a user. No-op if the role or assignment is absent. When
62
+ * `{ tenantId }` is given, only the assignment in THAT tenant is removed; omitting
63
+ * it removes the GLOBAL assignment (tenant `''`).
64
+ */
65
+ removeRole(user: UserRef, roleName: string, scope?: TenantScope): Promise<void>;
66
+ /**
67
+ * Grant a permission DIRECTLY to a user (creating the permission by name if
68
+ * needed) — no role required. Mirrors Laravel/spatie's `$user->givePermissionTo`.
69
+ * Idempotent.
70
+ */
71
+ giveUserPermission(user: UserRef, permissionName: string): Promise<void>;
72
+ /**
73
+ * Revoke a DIRECT user permission. No-op if the permission or grant is absent.
74
+ * Only the direct grant is removed — a permission the user ALSO has via a role
75
+ * survives.
76
+ */
77
+ revokeUserPermission(user: UserRef, permissionName: string): Promise<void>;
78
+ /**
79
+ * SQL fragment + params matching role assignments visible for a tenant scope: a
80
+ * GLOBAL assignment (tenant `''`) always applies; a tenant-scoped one applies only
81
+ * when its tenant matches the requested one. With no requested tenant, only global
82
+ * assignments are visible (a tenant-scoped role never leaks into an unscoped check).
83
+ */
84
+ private tenantFilter;
85
+ /** Bind values for {@link tenantFilter}, in the same order it emits placeholders. */
86
+ private tenantParams;
87
+ /**
88
+ * The role names a user holds, optionally restricted to a tenant scope (see
89
+ * {@link assignRole}). With no scope, only global roles are returned.
90
+ */
91
+ getRolesForUser(user: UserRef, scope?: TenantScope): Promise<string[]>;
92
+ /**
93
+ * The flattened, distinct permission names a user has — the UNION of role-derived
94
+ * permissions (honoring the tenant scope) and DIRECT user permissions (which are
95
+ * not tenant-scoped). With no scope, role-derived permissions come from global
96
+ * roles only.
97
+ */
98
+ getPermissionsForUser(user: UserRef, scope?: TenantScope): Promise<string[]>;
99
+ /** A user's roles + effective permissions in one shot (tenant-aware). */
100
+ getUserAuthz(user: UserRef, scope?: TenantScope): Promise<UserAuthz>;
101
+ /**
102
+ * True when the user holds `permission` — via a (tenant-scoped) role OR a direct
103
+ * grant. With no scope, only global role assignments count toward the role path;
104
+ * direct grants always count.
105
+ */
106
+ userHasPermission(user: UserRef, permission: string, scope?: TenantScope): Promise<boolean>;
63
107
  }
64
108
  //# sourceMappingURL=typeorm-authz.store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeorm-authz.store.d.ts","sourceRoot":"","sources":["../src/typeorm-authz.store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAU7D;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,qBAAa,iBAAiB;IAK1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI;IALvB,OAAO,CAAC,QAAQ,CAAC,KAAK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1,5 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { DEFAULT_TABLE_NAMES } from './entities.js';
2
+ import { DEFAULT_TABLE_NAMES, GLOBAL_TENANT } from './entities.js';
3
3
  import { ensureAuthzSchema } from './schema.js';
4
4
  import { Placeholders, assertSafeIdentifier } from './sql.js';
5
5
  /** Normalize a {@link UserRef} to `{ type, id }` with `id` stringified. */
@@ -30,6 +30,7 @@ export class TypeOrmAuthzStore {
30
30
  permissions: opts.tableNames?.permissions ?? DEFAULT_TABLE_NAMES.permissions,
31
31
  rolePermission: opts.tableNames?.rolePermission ?? DEFAULT_TABLE_NAMES.rolePermission,
32
32
  userRole: opts.tableNames?.userRole ?? DEFAULT_TABLE_NAMES.userRole,
33
+ userPermission: opts.tableNames?.userPermission ?? DEFAULT_TABLE_NAMES.userPermission,
33
34
  };
34
35
  this.schema = opts.schema;
35
36
  // P4: identifiers are interpolated into SQL — validate BYO names/schema up
@@ -134,63 +135,164 @@ export class TypeOrmAuthzStore {
134
135
  await this.dataSource.query(`DELETE FROM ${this.table('rolePermission')} WHERE ${this.col('roleId')} = ${p.next()} AND ${this.col('permissionId')} = ${p.next()}`, [roleId, permissionId]);
135
136
  }
136
137
  // --- user ↔ role ---
137
- /** Assign a role to a user (creating the role by name if needed). Idempotent. */
138
- async assignRole(user, roleName) {
138
+ /**
139
+ * Assign a role to a user (creating the role by name if needed). Idempotent.
140
+ *
141
+ * Pass `{ tenantId }` to scope the assignment to a tenant — it then applies ONLY
142
+ * within that tenant. Omitting it (the default) makes a GLOBAL assignment that
143
+ * applies in every tenant (and in an unscoped check). The same `(user, role)` can
144
+ * be assigned in multiple tenants independently.
145
+ */
146
+ async assignRole(user, roleName, scope) {
139
147
  const { type, id } = normalizeUserRef(user);
140
148
  const roleId = await this.createRole(roleName);
149
+ const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
141
150
  const p = this.params();
142
- await this.dataSource.query(`${this.insertIgnoreVerb()} INTO ${this.table('userRole')} (${this.col('userType')}, ${this.col('userId')}, ${this.col('roleId')}) VALUES (${p.next()}, ${p.next()}, ${p.next()})${this.insertIgnoreSuffix()}`, [type, id, roleId]);
151
+ await this.dataSource.query(`${this.insertIgnoreVerb()} INTO ${this.table('userRole')} (${this.col('userType')}, ${this.col('userId')}, ${this.col('roleId')}, ${this.col('tenantId')}) VALUES (${p.next()}, ${p.next()}, ${p.next()}, ${p.next()})${this.insertIgnoreSuffix()}`, [type, id, roleId, tenantId]);
143
152
  }
144
- /** Remove a role from a user. No-op if the role or assignment is absent. */
145
- async removeRole(user, roleName) {
153
+ /**
154
+ * Remove a role from a user. No-op if the role or assignment is absent. When
155
+ * `{ tenantId }` is given, only the assignment in THAT tenant is removed; omitting
156
+ * it removes the GLOBAL assignment (tenant `''`).
157
+ */
158
+ async removeRole(user, roleName, scope) {
146
159
  const { type, id } = normalizeUserRef(user);
147
160
  const roleId = await this.findRoleId(roleName);
148
161
  if (!roleId)
149
162
  return;
163
+ const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
164
+ const p = this.params();
165
+ await this.dataSource.query(`DELETE FROM ${this.table('userRole')} WHERE ${this.col('userType')} = ${p.next()} AND ${this.col('userId')} = ${p.next()} AND ${this.col('roleId')} = ${p.next()} AND ${this.col('tenantId')} = ${p.next()}`, [type, id, roleId, tenantId]);
166
+ }
167
+ // --- user ↔ permission (DIRECT grant, no role) ---
168
+ /**
169
+ * Grant a permission DIRECTLY to a user (creating the permission by name if
170
+ * needed) — no role required. Mirrors Laravel/spatie's `$user->givePermissionTo`.
171
+ * Idempotent.
172
+ */
173
+ async giveUserPermission(user, permissionName) {
174
+ const { type, id } = normalizeUserRef(user);
175
+ const permissionId = await this.createPermission(permissionName);
150
176
  const p = this.params();
151
- await this.dataSource.query(`DELETE FROM ${this.table('userRole')} WHERE ${this.col('userType')} = ${p.next()} AND ${this.col('userId')} = ${p.next()} AND ${this.col('roleId')} = ${p.next()}`, [type, id, roleId]);
177
+ await this.dataSource.query(`${this.insertIgnoreVerb()} INTO ${this.table('userPermission')} (${this.col('userType')}, ${this.col('userId')}, ${this.col('permissionId')}) VALUES (${p.next()}, ${p.next()}, ${p.next()})${this.insertIgnoreSuffix()}`, [type, id, permissionId]);
178
+ }
179
+ /**
180
+ * Revoke a DIRECT user permission. No-op if the permission or grant is absent.
181
+ * Only the direct grant is removed — a permission the user ALSO has via a role
182
+ * survives.
183
+ */
184
+ async revokeUserPermission(user, permissionName) {
185
+ const { type, id } = normalizeUserRef(user);
186
+ const permissionId = await this.findPermissionId(permissionName);
187
+ if (!permissionId)
188
+ return;
189
+ const p = this.params();
190
+ await this.dataSource.query(`DELETE FROM ${this.table('userPermission')} WHERE ${this.col('userType')} = ${p.next()} AND ${this.col('userId')} = ${p.next()} AND ${this.col('permissionId')} = ${p.next()}`, [type, id, permissionId]);
152
191
  }
153
192
  // --- queries ---
154
- /** The role names a user holds. */
155
- async getRolesForUser(user) {
193
+ /**
194
+ * SQL fragment + params matching role assignments visible for a tenant scope: a
195
+ * GLOBAL assignment (tenant `''`) always applies; a tenant-scoped one applies only
196
+ * when its tenant matches the requested one. With no requested tenant, only global
197
+ * assignments are visible (a tenant-scoped role never leaks into an unscoped check).
198
+ */
199
+ tenantFilter(alias, scope, p) {
200
+ const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
201
+ if (tenantId === GLOBAL_TENANT) {
202
+ return ` AND ${alias}.${this.col('tenantId')} = ${p.next()}`;
203
+ }
204
+ // Visible = global OR exactly this tenant.
205
+ return ` AND (${alias}.${this.col('tenantId')} = ${p.next()} OR ${alias}.${this.col('tenantId')} = ${p.next()})`;
206
+ }
207
+ /** Bind values for {@link tenantFilter}, in the same order it emits placeholders. */
208
+ tenantParams(scope) {
209
+ const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
210
+ return tenantId === GLOBAL_TENANT ? [GLOBAL_TENANT] : [GLOBAL_TENANT, tenantId];
211
+ }
212
+ /**
213
+ * The role names a user holds, optionally restricted to a tenant scope (see
214
+ * {@link assignRole}). With no scope, only global roles are returned.
215
+ */
216
+ async getRolesForUser(user, scope) {
156
217
  const { type, id } = normalizeUserRef(user);
157
218
  const p = this.params();
219
+ const userType = p.next();
220
+ const userId = p.next();
221
+ const filter = this.tenantFilter('ur', scope, p);
158
222
  const rows = (await this.dataSource.query(`SELECT r.${this.col('name')} AS name
159
223
  FROM ${this.table('userRole')} ur
160
224
  JOIN ${this.table('roles')} r ON r.${this.col('id')} = ur.${this.col('roleId')}
161
- WHERE ur.${this.col('userType')} = ${p.next()} AND ur.${this.col('userId')} = ${p.next()}`, [type, id]));
225
+ WHERE ur.${this.col('userType')} = ${userType} AND ur.${this.col('userId')} = ${userId}${filter}`, [type, id, ...this.tenantParams(scope)]));
162
226
  return rows.map((row) => row.name);
163
227
  }
164
- /** The flattened, distinct permission names a user has via their roles. */
165
- async getPermissionsForUser(user) {
228
+ /**
229
+ * The flattened, distinct permission names a user has — the UNION of role-derived
230
+ * permissions (honoring the tenant scope) and DIRECT user permissions (which are
231
+ * not tenant-scoped). With no scope, role-derived permissions come from global
232
+ * roles only.
233
+ */
234
+ async getPermissionsForUser(user, scope) {
166
235
  const { type, id } = normalizeUserRef(user);
167
- const p = this.params();
168
- const rows = (await this.dataSource.query(`SELECT DISTINCT p.${this.col('name')} AS name
236
+ // Role-derived (tenant-aware).
237
+ const pr = this.params();
238
+ const rUserType = pr.next();
239
+ const rUserId = pr.next();
240
+ const rFilter = this.tenantFilter('ur', scope, pr);
241
+ const roleRows = (await this.dataSource.query(`SELECT DISTINCT p.${this.col('name')} AS name
169
242
  FROM ${this.table('userRole')} ur
170
243
  JOIN ${this.table('rolePermission')} rp ON rp.${this.col('roleId')} = ur.${this.col('roleId')}
171
244
  JOIN ${this.table('permissions')} p ON p.${this.col('id')} = rp.${this.col('permissionId')}
172
- WHERE ur.${this.col('userType')} = ${p.next()} AND ur.${this.col('userId')} = ${p.next()}`, [type, id]));
173
- return rows.map((row) => row.name);
245
+ WHERE ur.${this.col('userType')} = ${rUserType} AND ur.${this.col('userId')} = ${rUserId}${rFilter}`, [type, id, ...this.tenantParams(scope)]));
246
+ // Direct grants (not tenant-scoped).
247
+ const pd = this.params();
248
+ const directRows = (await this.dataSource.query(`SELECT DISTINCT p.${this.col('name')} AS name
249
+ FROM ${this.table('userPermission')} up
250
+ JOIN ${this.table('permissions')} p ON p.${this.col('id')} = up.${this.col('permissionId')}
251
+ WHERE up.${this.col('userType')} = ${pd.next()} AND up.${this.col('userId')} = ${pd.next()}`, [type, id]));
252
+ const out = new Set();
253
+ for (const row of roleRows)
254
+ out.add(row.name);
255
+ for (const row of directRows)
256
+ out.add(row.name);
257
+ return [...out];
174
258
  }
175
- /** A user's roles + effective permissions in one shot. */
176
- async getUserAuthz(user) {
259
+ /** A user's roles + effective permissions in one shot (tenant-aware). */
260
+ async getUserAuthz(user, scope) {
177
261
  const [roles, permissions] = await Promise.all([
178
- this.getRolesForUser(user),
179
- this.getPermissionsForUser(user),
262
+ this.getRolesForUser(user, scope),
263
+ this.getPermissionsForUser(user, scope),
180
264
  ]);
181
265
  return { roles, permissions };
182
266
  }
183
- /** True when the user holds `permission` through any of their roles. */
184
- async userHasPermission(user, permission) {
267
+ /**
268
+ * True when the user holds `permission` — via a (tenant-scoped) role OR a direct
269
+ * grant. With no scope, only global role assignments count toward the role path;
270
+ * direct grants always count.
271
+ */
272
+ async userHasPermission(user, permission, scope) {
185
273
  const { type, id } = normalizeUserRef(user);
186
- const p = this.params();
187
- const rows = (await this.dataSource.query(`SELECT 1 AS x
274
+ // Role path (tenant-aware).
275
+ const pr = this.params();
276
+ const rUserType = pr.next();
277
+ const rUserId = pr.next();
278
+ const rName = pr.next();
279
+ const rFilter = this.tenantFilter('ur', scope, pr);
280
+ const roleRows = (await this.dataSource.query(`SELECT 1 AS x
188
281
  FROM ${this.table('userRole')} ur
189
282
  JOIN ${this.table('rolePermission')} rp ON rp.${this.col('roleId')} = ur.${this.col('roleId')}
190
283
  JOIN ${this.table('permissions')} p ON p.${this.col('id')} = rp.${this.col('permissionId')}
191
- WHERE ur.${this.col('userType')} = ${p.next()} AND ur.${this.col('userId')} = ${p.next()} AND p.${this.col('name')} = ${p.next()}
284
+ WHERE ur.${this.col('userType')} = ${rUserType} AND ur.${this.col('userId')} = ${rUserId} AND p.${this.col('name')} = ${rName}${rFilter}
285
+ LIMIT 1`, [type, id, permission, ...this.tenantParams(scope)]));
286
+ if (roleRows.length > 0)
287
+ return true;
288
+ // Direct path.
289
+ const pd = this.params();
290
+ const directRows = (await this.dataSource.query(`SELECT 1 AS x
291
+ FROM ${this.table('userPermission')} up
292
+ JOIN ${this.table('permissions')} p ON p.${this.col('id')} = up.${this.col('permissionId')}
293
+ WHERE up.${this.col('userType')} = ${pd.next()} AND up.${this.col('userId')} = ${pd.next()} AND p.${this.col('name')} = ${pd.next()}
192
294
  LIMIT 1`, [type, id, permission]));
193
- return rows.length > 0;
295
+ return directRows.length > 0;
194
296
  }
195
297
  }
196
298
  //# sourceMappingURL=typeorm-authz.store.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"typeorm-authz.store.js","sourceRoot":"","sources":["../src/typeorm-authz.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG9D,2EAA2E;AAC3E,SAAS,gBAAgB,CAAC,GAAY;IACpC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACvD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IAC3C,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,MAAM,EAAE,EAAE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CAAC,SAAS,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;kBAC/E,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,SAAS,WAAW,IAAI,CAAC,GAAG,CAC/D,QAAQ,CACT,MAAM,OAAO,UAAU,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,GAAG,OAAO;eACrD,EACT,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CACpD,CAAc,CAAC;QAChB,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAErC,eAAe;QACf,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,UAAU,GAAG,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAC7C;cACQ,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC;cAC5B,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,WAAW,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;kBAC/E,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,IAAI,CAAC,GAAG,CAC/D,QAAQ,CACT,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE;eACjD,EACT,CAAC,IAAI,EAAE,EAAE,EAAE,UAAU,CAAC,CACvB,CAAc,CAAC;QAChB,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,CAAC;CACF"}
package/dist/types.d.ts CHANGED
@@ -4,6 +4,17 @@ export interface TableNames {
4
4
  permissions?: string;
5
5
  rolePermission?: string;
6
6
  userRole?: string;
7
+ /** Direct user→permission pivot (post-v1). Defaults to `authz_user_permission`. */
8
+ userPermission?: string;
9
+ }
10
+ /** Optional tenant scope for a user-role assignment / role-or-permission query. */
11
+ export interface TenantScope {
12
+ /**
13
+ * Restrict a role assignment (or a query) to this tenant. Omitted/undefined →
14
+ * the GLOBAL scope (an assignment applies in every tenant; a query sees global
15
+ * assignments only — a tenant-scoped role does NOT leak into an unscoped check).
16
+ */
17
+ tenantId?: string;
7
18
  }
8
19
  /**
9
20
  * A reference to a user. Matches nestjs-context's `UserRef` shape (`{ type, id }`),
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;CACrB;AAED,4EAA4E;AAC5E,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mFAAmF;IACnF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;CACrB;AAED,4EAA4E;AAC5E,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dudousxd/nestjs-authz-typeorm",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "TypeORM RBAC persistence for @dudousxd/nestjs-authz — roles, permissions, and a Gate seam (zero connection ownership).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,14 +35,18 @@
35
35
  "@nestjs/common": "^11.0.0",
36
36
  "@nestjs/core": "^11.0.0",
37
37
  "@nestjs/testing": "^11.0.0",
38
+ "@testcontainers/mysql": "^12.0.3",
39
+ "@testcontainers/postgresql": "^12.0.3",
38
40
  "@types/node": "^20.0.0",
41
+ "mysql2": "^3.22.5",
42
+ "pg": "^8.21.0",
39
43
  "reflect-metadata": "^0.2.2",
40
44
  "rxjs": "^7.8.1",
41
45
  "sqlite3": "^5.1.7",
42
46
  "typeorm": "^0.3.20",
43
47
  "typescript": "^5.4.0",
44
48
  "vitest": "^3.0.0",
45
- "@dudousxd/nestjs-authz": "^0.2.0"
49
+ "@dudousxd/nestjs-authz": "^0.6.0"
46
50
  },
47
51
  "engines": {
48
52
  "node": ">=20"
@@ -59,6 +63,9 @@
59
63
  "scripts": {
60
64
  "build": "tsc -p tsconfig.json",
61
65
  "test": "vitest run --passWithNoTests",
66
+ "test:db": "pnpm test:db:pg && pnpm test:db:mysql",
67
+ "test:db:pg": "AUTHZ_TEST_DIALECT=postgres vitest run --config vitest.db.config.ts",
68
+ "test:db:mysql": "AUTHZ_TEST_DIALECT=mysql vitest run --config vitest.db.config.ts",
62
69
  "test:watch": "vitest",
63
70
  "typecheck": "tsc -p tsconfig.json --noEmit"
64
71
  }