@dudousxd/nestjs-authz-mikro-orm 0.8.0 → 0.10.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 +59 -0
- package/README.md +67 -3
- package/dist/authz-rbac.module.d.ts +12 -0
- package/dist/authz-rbac.module.d.ts.map +1 -1
- package/dist/authz-rbac.module.js +74 -8
- package/dist/authz-rbac.module.js.map +1 -1
- package/dist/entities.d.ts +27 -1
- package/dist/entities.d.ts.map +1 -1
- package/dist/entities.js +36 -1
- package/dist/entities.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mikro-orm-authz.store.d.ts +47 -15
- package/dist/mikro-orm-authz.store.d.ts.map +1 -1
- package/dist/mikro-orm-authz.store.js +145 -39
- package/dist/mikro-orm-authz.store.js.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +129 -2
- package/dist/schema.js.map +1 -1
- package/dist/tenancy.d.ts +149 -0
- package/dist/tenancy.d.ts.map +1 -0
- package/dist/tenancy.js +227 -0
- package/dist/tenancy.js.map +1 -0
- package/package.json +11 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,64 @@
|
|
|
1
1
|
# @dudousxd/nestjs-authz-mikro-orm
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#76](https://github.com/DavideCarvalho/nestjs-authz/pull/76) [`d2a9b06`](https://github.com/DavideCarvalho/nestjs-authz/commit/d2a9b06c398b80c68957ae573c1f5bd866a9ff72) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Add MCP dev tools: `AuthzModule` registers `authz_explain_check`, `authz_list_effective_roles` and `authz_list_effective_permissions` in the Aviary dev-tools slot (`Symbol.for('@dudousxd/aviary:dev-tools')`, created when absent). They register without an `authorize`, so the agent dev endpoint's `devTools.authorize` gates them (open outside production, denied in production without it); a hub that cannot gate console-less libs leaves them out. `devTools: { loadSubject, loadResource }` hands checks your models (default: `resolveUser` and `resourceLoaders`); `devTools: false` turns the tools off. New: `gate.explainFor(user, ability, resource?)`, `runInTenantScope(tenantId, fn)`, and `RoleProvider.describeRbac?(user)`, which the RBAC adapters implement; the adapters honour a scope forced by `runInTenantScope` ahead of their `tenant` resolver and the context tenant.
|
|
8
|
+
|
|
9
|
+
- [#76](https://github.com/DavideCarvalho/nestjs-authz/pull/76) [`d2a9b06`](https://github.com/DavideCarvalho/nestjs-authz/commit/d2a9b06c398b80c68957ae573c1f5bd866a9ff72) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - A `schema` option puts the authz tables in their own database schema: a Postgres schema, or a MySQL database. Every statement names it, and `search_path` is never used.
|
|
10
|
+
|
|
11
|
+
- **TypeORM** (Postgres and MySQL): `storeOptions.schema`. Adds `authzEntities({ schema, type, tableNames })` for synchronize/migration-generated setups.
|
|
12
|
+
- **Drizzle** (Postgres): `createAuthzTables({ schema })` / `storeOptions.schema`.
|
|
13
|
+
- **MikroORM** (Postgres and MySQL): `createAuthzEntitySchemas(names, { schema })`. The store reads the schema from the entity metadata and qualifies its raw SQL. On MySQL, the heal narrows MikroORM's diff against the target database's `information_schema`. `authzSchemaSql()` includes the create statement.
|
|
14
|
+
- **Prisma** (Postgres): the `schema` option, for models with `@@schema`. The fast path uses `$queryRawUnsafe` with the schema in the SQL and every value bound.
|
|
15
|
+
|
|
16
|
+
Shared behaviour:
|
|
17
|
+
|
|
18
|
+
- Auto-create makes the schema only when the catalog says it is missing. A failure names the grant needed.
|
|
19
|
+
- On SQLite, a `schema` fails at boot. Prisma refuses it on MySQL and SQLite.
|
|
20
|
+
- Names are validated (a safe identifier, at most 63 characters).
|
|
21
|
+
- Without `schema`, nothing changes.
|
|
22
|
+
|
|
23
|
+
- [#76](https://github.com/DavideCarvalho/nestjs-authz/pull/76) [`d2a9b06`](https://github.com/DavideCarvalho/nestjs-authz/commit/d2a9b06c398b80c68957ae573c1f5bd866a9ff72) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Tenancy for nested tenants, tenant families and required tenants (nestjs-context's chain contract, read structurally, so older contexts keep working):
|
|
24
|
+
|
|
25
|
+
- A role or grant assigned at any level of the active tenant chain applies (a clinic role counts inside its units). `tenancy.kinds` picks the levels, and the context's own `kinds` apply when the module sets none.
|
|
26
|
+
- `tenancy.roles` maps the caller's role at every level of the chain.
|
|
27
|
+
- New `tenancy.family` option.
|
|
28
|
+
- New `tenancy.required` option, defaulting to the context's. A check with no tenant throws `TenantRequiredError` (403, `E_TENANT_REQUIRED`) instead of running in the global scope.
|
|
29
|
+
- Console `authorize` helpers, the MCP dev tools, and the new `runWithoutRequiredTenant(fn)` pass `required: false`.
|
|
30
|
+
- `describeRbac` reports the `tenantChain`.
|
|
31
|
+
|
|
32
|
+
## 0.9.0
|
|
33
|
+
|
|
34
|
+
### Minor Changes
|
|
35
|
+
|
|
36
|
+
- Back on the 0.x line. The 1.x and 2.x versions were published by accident: a release-tooling peer cascade bumped this package to a major, not an API decision. 0.9.0 contains everything those versions shipped (console `authorize` support, tenancy, Node 24+ `engines`) with no other change. Upgrade from 1.x/2.x to 0.9.0; those versions are deprecated.
|
|
37
|
+
|
|
38
|
+
## 2.0.0
|
|
39
|
+
|
|
40
|
+
### Major Changes
|
|
41
|
+
|
|
42
|
+
- [#74](https://github.com/DavideCarvalho/nestjs-authz/pull/74) [`35421dc`](https://github.com/DavideCarvalho/nestjs-authz/commit/35421dc5b09bd271d5087d26e8536191ef6ba342) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - **Breaking:** require Node.js 24 or newer (`engines.node` is now `>=24`; it was `>=22`, and `>=20` for `-client` and `-react`). CI tests on Node 24 and 26. No API changes: see the Upgrading page in the docs.
|
|
43
|
+
|
|
44
|
+
## 1.1.0
|
|
45
|
+
|
|
46
|
+
### Minor Changes
|
|
47
|
+
|
|
48
|
+
- [#72](https://github.com/DavideCarvalho/nestjs-authz/pull/72) [`58a5d72`](https://github.com/DavideCarvalho/nestjs-authz/commit/58a5d72d2964a7cfae9cbfe8506526c8518ba30a) Thanks [@DavideCarvalho](https://github.com/DavideCarvalho)! - Tenancy for the RBAC modules, following the `@dudousxd/nestjs-context` tenancy switch.
|
|
49
|
+
|
|
50
|
+
- New `tenancy` option (`'inherit' | false | { enabled?, kinds?, nullRows?, roles? }`, default `'inherit'`). With context tenancy on, permission and role checks are scoped to the request's tenant from `Context.setTenant`. A request with no tenant, inside `Context.allTenants()`, or outside a request sees global assignments only. `kinds` limits the tenant kinds this module honours. With tenancy off nothing changes.
|
|
51
|
+
- `tenancy.roles` maps the caller's role inside the tenant (`tenant.role`) to authz roles that apply in that tenant only, e.g. `{ owner: 'org_admin' }`.
|
|
52
|
+
- New `tenant` resolver option, `(user) => tenantId | null | undefined`: an explicit tenant that wins over the context.
|
|
53
|
+
- MikroORM and Prisma can now store tenant-scoped role assignments like Drizzle and TypeORM: `assignRole`, `removeRole` and `setUserRoles` take `{ tenantId }`, and the read methods take a tenant scope. MikroORM: build the entities with `createAuthzEntitySchemas({}, { tenantScoped: true })`. Prisma: add `tenantId String @default("")` to `UserRole` and its `@@id`, then pass `tenantScoped: true`. Without that, every assignment stays global.
|
|
54
|
+
|
|
55
|
+
## 1.0.0
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [[`750a6b3`](https://github.com/DavideCarvalho/nestjs-authz/commit/750a6b3f80deea3803dec8df5f9f8cf67a046ac1)]:
|
|
60
|
+
- @dudousxd/nestjs-authz@0.10.0
|
|
61
|
+
|
|
3
62
|
## 0.8.0
|
|
4
63
|
|
|
5
64
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -213,9 +213,73 @@ await store.listRoleAssignments({ user: { type: 'user', id: 7 } });
|
|
|
213
213
|
await store.removeUser({ type: 'user', id: 7 });
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
nothing.
|
|
216
|
+
`tenantId` filters: omitted = every tenant, `null` = global assignments only, a string = that
|
|
217
|
+
tenant's scoped assignments only. Without the tenant column (below) every row has
|
|
218
|
+
`tenantId: null`, so a tenant id string matches nothing.
|
|
219
|
+
|
|
220
|
+
## Tenant-scoped roles
|
|
221
|
+
|
|
222
|
+
Build the entities with `tenantScoped: true` to assign roles per tenant. The user-role table
|
|
223
|
+
gets a `tenant_id` column (default `''`, a global assignment) in its primary key:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
import { createAuthzEntitySchemas } from '@dudousxd/nestjs-authz-mikro-orm';
|
|
227
|
+
|
|
228
|
+
const authz = createAuthzEntitySchemas({}, { tenantScoped: true }); // or your own table names
|
|
229
|
+
MikroOrmModule.forRoot({ entities: [...authz.all /* , your entities */] });
|
|
230
|
+
|
|
231
|
+
await store.assignRole(user, 'editor', { tenantId: 'acme' }); // only inside acme
|
|
232
|
+
await store.assignRole(user, 'viewer'); // everywhere
|
|
233
|
+
await store.getRolesForUser(user, { tenantId: 'acme' }); // ['editor', 'viewer']
|
|
234
|
+
await store.getRolesForUser(user); // ['viewer']
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`removeRole` and `setUserRoles` take the same `{ tenantId }` (omitted = the global
|
|
238
|
+
assignments). Without `tenantScoped`, every assignment is global and reads ignore the tenant.
|
|
239
|
+
`assignRole` and `setUserRoles` with a `tenantId` throw; `removeRole` with one does nothing,
|
|
240
|
+
since there is no tenant assignment to remove.
|
|
241
|
+
|
|
242
|
+
### Migrating an existing database
|
|
243
|
+
|
|
244
|
+
`ensureAuthzSchema` / `autoCreateSchema` (or `authzSchemaSql` in a migration) add the `tenant_id`
|
|
245
|
+
column, so existing rows become global assignments. Widen the primary key once, so the same role
|
|
246
|
+
can be assigned in two tenants:
|
|
247
|
+
|
|
248
|
+
```sql
|
|
249
|
+
-- PostgreSQL (default constraint name; check yours with \d authz_user_role)
|
|
250
|
+
ALTER TABLE authz_user_role DROP CONSTRAINT authz_user_role_pkey,
|
|
251
|
+
ADD PRIMARY KEY (user_type, user_id, role_id, source, tenant_id);
|
|
252
|
+
-- MySQL
|
|
253
|
+
ALTER TABLE authz_user_role DROP PRIMARY KEY,
|
|
254
|
+
ADD PRIMARY KEY (user_type, user_id, role_id, source, tenant_id);
|
|
255
|
+
-- SQLite: recreate the table with the 5-column key (SQLite cannot alter a primary key).
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Tenancy
|
|
259
|
+
|
|
260
|
+
The RBAC module reads the tenant only when tenancy is on: turn it on with
|
|
261
|
+
`ContextModule.forRoot({ tenancy: { enabled: true } })` in `@dudousxd/nestjs-context`. Checks
|
|
262
|
+
are then scoped to the request's tenant from `Context.setTenant(...)`.
|
|
263
|
+
A request with no tenant, or inside `Context.allTenants()`, sees global assignments only.
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
AuthzRbacModule.forRoot({
|
|
267
|
+
store,
|
|
268
|
+
tenancy: {
|
|
269
|
+
kinds: ['organization'], // optional: tenant kinds this module honours
|
|
270
|
+
roles: { owner: 'org_admin', member: 'org_member' }, // optional: tenant.role → authz roles in that tenant
|
|
271
|
+
},
|
|
272
|
+
tenant: (user) => (user as { orgId?: string }).orgId, // optional: an explicit tenant wins over the context
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
`tenancy` defaults to `'inherit'` (follow the context switch); `false` keeps this module out.
|
|
277
|
+
Roles mapped with `roles` apply only inside that tenant and only to the context's current user.
|
|
278
|
+
The `tenant` resolver returns a tenant id, `null` for the global scope, or `undefined` to fall
|
|
279
|
+
back to the context.
|
|
280
|
+
|
|
281
|
+
With tenancy on and the default entities, every assignment is global, so only `roles` and the
|
|
282
|
+
`tenant` resolver change what a check sees.
|
|
219
283
|
|
|
220
284
|
## License
|
|
221
285
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UserRef } from '@dudousxd/nestjs-authz/store-kit';
|
|
2
2
|
import { type DynamicModule } from '@nestjs/common';
|
|
3
3
|
import type { MikroOrmAuthzStore } from './mikro-orm-authz.store.js';
|
|
4
|
+
import { type AuthzTenancyOption, type TenantResolver } from './tenancy.js';
|
|
4
5
|
/** Injection token holding the {@link MikroOrmAuthzStore} the RBAC module manages. */
|
|
5
6
|
export declare const AUTHZ_RBAC_STORE: unique symbol;
|
|
6
7
|
/** Injection token holding the resolved {@link AuthzRbacModuleOptions}. */
|
|
@@ -23,6 +24,17 @@ export interface AuthzRbacModuleOptions {
|
|
|
23
24
|
* {@link defaultUserRefMapper} (`{ type, id }` or `{ id }`).
|
|
24
25
|
*/
|
|
25
26
|
userRefFrom?: UserRefMapper;
|
|
27
|
+
/**
|
|
28
|
+
* Tenancy, from `@dudousxd/nestjs-context`. `'inherit'` (default) follows `ContextModule`'s
|
|
29
|
+
* `tenancy.enabled`; with it on, checks are scoped to the context tenant. The object form adds
|
|
30
|
+
* `kinds` and `roles` (map the caller's `tenant.role` to authz roles in that tenant).
|
|
31
|
+
*/
|
|
32
|
+
tenancy?: AuthzTenancyOption;
|
|
33
|
+
/**
|
|
34
|
+
* Explicit tenant for a check, from the user being checked. Wins over the context: return a
|
|
35
|
+
* tenant id, `null` for the global scope, or `undefined` to fall back to the context.
|
|
36
|
+
*/
|
|
37
|
+
tenant?: TenantResolver;
|
|
26
38
|
}
|
|
27
39
|
export interface AuthzRbacModuleAsyncOptions {
|
|
28
40
|
imports?: unknown[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authz-rbac.module.d.ts","sourceRoot":"","sources":["../src/authz-rbac.module.ts"],"names":[],"mappings":"
|
|
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,EA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Index, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
var AuthzRbacModule_1;
|
|
14
|
-
import { PERMISSION_PROVIDER, ROLE_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';
|
|
17
|
+
import { acrossScopes, inAnyScope, rbacTenant, } from './tenancy.js';
|
|
16
18
|
/** Injection token holding the {@link MikroOrmAuthzStore} the RBAC module manages. */
|
|
17
19
|
export const AUTHZ_RBAC_STORE = Symbol.for('@dudousxd/nestjs-authz-mikro-orm:store');
|
|
18
20
|
/** Injection token holding the resolved {@link AuthzRbacModuleOptions}. */
|
|
@@ -36,10 +38,24 @@ export function defaultUserRefMapper(user) {
|
|
|
36
38
|
*/
|
|
37
39
|
let RbacPermissionProvider = class RbacPermissionProvider {
|
|
38
40
|
options;
|
|
41
|
+
context;
|
|
42
|
+
moduleRef;
|
|
39
43
|
// `getPermissions` lists every grant `hasPermission` can find, for any resource.
|
|
40
44
|
exhaustivePermissions = true;
|
|
41
|
-
|
|
45
|
+
contextCache = { resolved: false, value: undefined };
|
|
46
|
+
constructor(options, context, moduleRef) {
|
|
42
47
|
this.options = options;
|
|
48
|
+
this.context = context;
|
|
49
|
+
this.moduleRef = moduleRef;
|
|
50
|
+
}
|
|
51
|
+
tenant(user, ref) {
|
|
52
|
+
return rbacTenant(this.options, user, ref, this.context, this.moduleRef, this.contextCache, false);
|
|
53
|
+
}
|
|
54
|
+
/** The permissions `tenancy.roles` grants through the caller's role in the tenant. */
|
|
55
|
+
async tenantRolePermissions(roles) {
|
|
56
|
+
if (roles.length === 0)
|
|
57
|
+
return [];
|
|
58
|
+
return Object.values(await this.options.store.getRolePermissions(roles)).flat();
|
|
43
59
|
}
|
|
44
60
|
// The core `PermissionProvider` interface passes an optional `resource` (3rd
|
|
45
61
|
// arg); it is intentionally ignored here. RBAC grants are model-less,
|
|
@@ -50,7 +66,11 @@ let RbacPermissionProvider = class RbacPermissionProvider {
|
|
|
50
66
|
const ref = map(user);
|
|
51
67
|
if (ref === undefined)
|
|
52
68
|
return undefined;
|
|
53
|
-
|
|
69
|
+
const tenant = this.tenant(user, ref);
|
|
70
|
+
if (await inAnyScope(tenant, (scope) => this.options.store.userHasPermission(ref, permission, scope))) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
return (await this.tenantRolePermissions(tenant.roles)).includes(permission);
|
|
54
74
|
}
|
|
55
75
|
// Expose the user's full granted permission set so the core can apply
|
|
56
76
|
// Laravel/spatie-style wildcard matching (a granted `posts.*` satisfies a check
|
|
@@ -60,13 +80,20 @@ let RbacPermissionProvider = class RbacPermissionProvider {
|
|
|
60
80
|
const ref = map(user);
|
|
61
81
|
if (ref === undefined)
|
|
62
82
|
return undefined;
|
|
63
|
-
|
|
83
|
+
const tenant = this.tenant(user, ref);
|
|
84
|
+
const own = await acrossScopes(tenant, (scope) => this.options.store.getPermissionsForUser(ref, scope));
|
|
85
|
+
if (tenant.roles.length === 0)
|
|
86
|
+
return own;
|
|
87
|
+
return [...new Set([...own, ...(await this.tenantRolePermissions(tenant.roles))])];
|
|
64
88
|
}
|
|
65
89
|
};
|
|
66
90
|
RbacPermissionProvider = __decorate([
|
|
67
91
|
Injectable(),
|
|
68
92
|
__param(0, Inject(AUTHZ_RBAC_OPTIONS)),
|
|
69
|
-
|
|
93
|
+
__param(1, Optional()),
|
|
94
|
+
__param(1, Inject(CONTEXT_ACCESSOR)),
|
|
95
|
+
__param(2, Optional()),
|
|
96
|
+
__metadata("design:paramtypes", [Object, Object, ModuleRef])
|
|
70
97
|
], RbacPermissionProvider);
|
|
71
98
|
/**
|
|
72
99
|
* The RBAC {@link RoleProvider} the Gate consults (via the shared {@link ROLE_PROVIDER}
|
|
@@ -76,21 +103,60 @@ RbacPermissionProvider = __decorate([
|
|
|
76
103
|
*/
|
|
77
104
|
let RbacRoleProvider = class RbacRoleProvider {
|
|
78
105
|
options;
|
|
79
|
-
|
|
106
|
+
context;
|
|
107
|
+
moduleRef;
|
|
108
|
+
contextCache = { resolved: false, value: undefined };
|
|
109
|
+
constructor(options, context, moduleRef) {
|
|
80
110
|
this.options = options;
|
|
111
|
+
this.context = context;
|
|
112
|
+
this.moduleRef = moduleRef;
|
|
113
|
+
}
|
|
114
|
+
tenant(user, ref) {
|
|
115
|
+
return rbacTenant(this.options, user, ref, this.context, this.moduleRef, this.contextCache, false);
|
|
81
116
|
}
|
|
82
117
|
async getRoles(user) {
|
|
83
118
|
const map = this.options.userRefFrom ?? defaultUserRefMapper;
|
|
84
119
|
const ref = map(user);
|
|
85
120
|
if (ref === undefined)
|
|
86
121
|
return undefined;
|
|
87
|
-
|
|
122
|
+
const tenant = this.tenant(user, ref);
|
|
123
|
+
const own = await acrossScopes(tenant, (scope) => this.options.store.getRolesForUser(ref, scope));
|
|
124
|
+
return tenant.roles.length === 0 ? own : [...new Set([...own, ...tenant.roles])];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Where the user's roles and permissions come from, for the core's dev tools
|
|
128
|
+
* (`authz_explain_check`): the scope the lookups ran in, store vs `tenancy.roles` roles,
|
|
129
|
+
* each role's permissions, and every permission granted in that scope.
|
|
130
|
+
*/
|
|
131
|
+
async describeRbac(user) {
|
|
132
|
+
const map = this.options.userRefFrom ?? defaultUserRefMapper;
|
|
133
|
+
const ref = map(user);
|
|
134
|
+
if (ref === undefined)
|
|
135
|
+
return undefined;
|
|
136
|
+
const tenant = this.tenant(user, ref);
|
|
137
|
+
const [own, permissions] = await Promise.all([
|
|
138
|
+
acrossScopes(tenant, (scope) => this.options.store.getRolesForUser(ref, scope)),
|
|
139
|
+
acrossScopes(tenant, (scope) => this.options.store.getPermissionsForUser(ref, scope)),
|
|
140
|
+
]);
|
|
141
|
+
const roles = [...new Set([...own, ...tenant.roles])];
|
|
142
|
+
const rolePermissions = roles.length === 0 ? {} : await this.options.store.getRolePermissions(roles);
|
|
143
|
+
const fromTenantRoles = tenant.roles.flatMap((role) => rolePermissions[role] ?? []);
|
|
144
|
+
return {
|
|
145
|
+
tenantId: tenant.scope.tenantId ?? null,
|
|
146
|
+
tenantChain: tenant.scopes.flatMap((scope) => (scope.tenantId ? [scope.tenantId] : [])),
|
|
147
|
+
roles: { store: own, tenant: tenant.roles },
|
|
148
|
+
rolePermissions,
|
|
149
|
+
permissions: [...new Set([...permissions, ...fromTenantRoles])],
|
|
150
|
+
};
|
|
88
151
|
}
|
|
89
152
|
};
|
|
90
153
|
RbacRoleProvider = __decorate([
|
|
91
154
|
Injectable(),
|
|
92
155
|
__param(0, Inject(AUTHZ_RBAC_OPTIONS)),
|
|
93
|
-
|
|
156
|
+
__param(1, Optional()),
|
|
157
|
+
__param(1, Inject(CONTEXT_ACCESSOR)),
|
|
158
|
+
__param(2, Optional()),
|
|
159
|
+
__metadata("design:paramtypes", [Object, Object, ModuleRef])
|
|
94
160
|
], RbacRoleProvider);
|
|
95
161
|
/** Runs `ensureAuthzSchema` on bootstrap when `autoCreateSchema` is not disabled. */
|
|
96
162
|
let AuthzRbacBootstrap = class AuthzRbacBootstrap {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authz-rbac.module.js","sourceRoot":"","sources":["../src/authz-rbac.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACL,mBAAmB,EAEnB,aAAa,GAEd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAEL,MAAM,EACN,UAAU,EACV,MAAM,EAEN,QAAQ,GAGT,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"authz-rbac.module.js","sourceRoot":"","sources":["../src/authz-rbac.module.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EACL,gBAAgB,EAChB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AAe,EAAE;aACrC;YACD,OAAO,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,EAAE,aAAa,CAAC;SAChE,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAoC;QACtD,OAAO;YACL,MAAM,EAAE,iBAAe;YACvB,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAoB;YACnD,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,kBAAkB;oBAC3B,UAAU,EAAE,OAAO,CAAC,UAAU;oBAC9B,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAyB;iBACvD;gBACD;oBACE,OAAO,EAAE,gBAAgB;oBACzB,UAAU,EAAE,CAAC,IAA4B,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK;oBACxD,MAAM,EAAE,CAAC,kBAAkB,CAAC;iBAC7B;gBACD,GAAG,iBAAe,CAAC,eAAe,EAAE;aACrC;YACD,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,kBAAkB;SACnB,CAAC;IACJ,CAAC;CACF,CAAA;AA7CY,eAAe;IAD3B,MAAM,CAAC,EAAE,CAAC;GACE,eAAe,CA6C3B"}
|
package/dist/entities.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare const DEFAULT_TABLE_NAMES: {
|
|
|
12
12
|
readonly rolePermission: "authz_role_permission";
|
|
13
13
|
readonly userRole: "authz_user_role";
|
|
14
14
|
};
|
|
15
|
+
/** The tenant id of a GLOBAL role assignment (applies in every tenant). */
|
|
16
|
+
export declare const GLOBAL_TENANT = "";
|
|
15
17
|
/** Physical table names for the four authz tables. */
|
|
16
18
|
export interface AuthzTableNames {
|
|
17
19
|
roles: string;
|
|
@@ -82,6 +84,27 @@ export declare class UserRoleEntity {
|
|
|
82
84
|
*/
|
|
83
85
|
source: string;
|
|
84
86
|
}
|
|
87
|
+
/** Options for {@link createAuthzEntitySchemas}. */
|
|
88
|
+
export interface AuthzEntitySchemaOptions {
|
|
89
|
+
/**
|
|
90
|
+
* Add a `tenantId` column (default `''` = global) to the user-role pivot, in its primary key,
|
|
91
|
+
* so role assignments can be scoped to a tenant. Default `false`: the tables keep their shape
|
|
92
|
+
* and every assignment is global.
|
|
93
|
+
*/
|
|
94
|
+
tenantScoped?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Put the four tables in this schema: a Postgres schema, or a MySQL database. MikroORM names
|
|
97
|
+
* it in every query (`"authz"."authz_roles"`), the store qualifies its raw SQL and
|
|
98
|
+
* `ensureAuthzSchema` creates it when missing; `search_path` is never used, so it is safe
|
|
99
|
+
* behind PgBouncer in transaction mode. SQLite has no schemas: the store throws there.
|
|
100
|
+
*/
|
|
101
|
+
schema?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Validate a `schema` option: a safe identifier (letters, digits, `_`, not starting with a
|
|
105
|
+
* digit) of at most 63 characters (the Postgres limit; MySQL allows 64).
|
|
106
|
+
*/
|
|
107
|
+
export declare function assertSchemaName(schema: string): void;
|
|
85
108
|
/** The four {@link EntitySchema} definitions produced by {@link createAuthzEntitySchemas}. */
|
|
86
109
|
export interface AuthzEntitySchemas {
|
|
87
110
|
role: EntitySchema<RoleEntity>;
|
|
@@ -108,8 +131,11 @@ export interface AuthzEntitySchemas {
|
|
|
108
131
|
* Going through the factory (rather than hand-writing `new EntitySchema({ tableName })`)
|
|
109
132
|
* keeps the custom repository binding and the index names attached to the renamed tables;
|
|
110
133
|
* a hand-rolled re-declaration silently drops both.
|
|
134
|
+
*
|
|
135
|
+
* `{ tenantScoped: true }` adds a `tenantId` column to the user-role pivot (in its primary key),
|
|
136
|
+
* so a role can be assigned per tenant. Pass `{}` as the names to keep the default table names.
|
|
111
137
|
*/
|
|
112
|
-
export declare function createAuthzEntitySchemas(tableNames?: Partial<AuthzTableNames
|
|
138
|
+
export declare function createAuthzEntitySchemas(tableNames?: Partial<AuthzTableNames>, options?: AuthzEntitySchemaOptions): AuthzEntitySchemas;
|
|
113
139
|
export declare const RoleEntitySchema: EntitySchema<RoleEntity, never>;
|
|
114
140
|
export declare const PermissionEntitySchema: EntitySchema<PermissionEntity, never>;
|
|
115
141
|
export declare const RolePermissionEntitySchema: EntitySchema<RolePermissionEntity, never>;
|
package/dist/entities.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,mBAAmB,CAAC;AAE3B;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;CAKtB,CAAC;AAEX,2EAA2E;AAC3E,eAAO,MAAM,aAAa,KAAK,CAAC;AAEhC,sDAAsD;AACtD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;GAGG;AACH,qBAAa,UAAU;IACb,CAAC,oBAAoB,CAAC,CAAC,EAAE,mBAAmB,CAAC;IACrD,EAAE,EAAG,MAAM,CAAC;IACZ,IAAI,EAAG,M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AAC;QACxB,YAAY,CAAC,gBAAgB,CAAC;QAC9B,YAAY,CAAC,oBAAoB,CAAC;QAClC,YAAY,CAAC,cAAc,CAAC;KAC7B,CAAC;CACH;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,GAAE,OAAO,CAAC,eAAe,CAAM,EACzC,OAAO,GAAE,wBAA6B,GACrC,kBAAkB,CA0FpB;AAID,eAAO,MAAM,gBAAgB,iCAAsB,CAAC;AACpD,eAAO,MAAM,sBAAsB,uCAA4B,CAAC;AAChE,eAAO,MAAM,0BAA0B,2CAAgC,CAAC;AACxE,eAAO,MAAM,oBAAoB,qCAA0B,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,cAAc,0JAAqB,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,2GAKvB,CAAC"}
|
package/dist/entities.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertSafeIdentifier } from '@dudousxd/nestjs-authz';
|
|
1
2
|
import { DEFAULT_ROLE_SOURCE } from '@dudousxd/nestjs-authz/store-kit';
|
|
2
3
|
import { EntitySchema } from '@mikro-orm/core';
|
|
3
4
|
import { AuthzPermissionRepository, AuthzRolePermissionRepository, AuthzRoleRepository, AuthzUserRoleRepository, } from './repositories.js';
|
|
@@ -13,6 +14,8 @@ export const DEFAULT_TABLE_NAMES = {
|
|
|
13
14
|
rolePermission: 'authz_role_permission',
|
|
14
15
|
userRole: 'authz_user_role',
|
|
15
16
|
};
|
|
17
|
+
/** The tenant id of a GLOBAL role assignment (applies in every tenant). */
|
|
18
|
+
export const GLOBAL_TENANT = '';
|
|
16
19
|
/**
|
|
17
20
|
* The entities are described with {@link EntitySchema} (the schema-first definition style)
|
|
18
21
|
* rather than property decorators. This is the ONE definition surface that lives entirely
|
|
@@ -72,6 +75,16 @@ export class UserRoleEntity {
|
|
|
72
75
|
*/
|
|
73
76
|
source;
|
|
74
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Validate a `schema` option: a safe identifier (letters, digits, `_`, not starting with a
|
|
80
|
+
* digit) of at most 63 characters (the Postgres limit; MySQL allows 64).
|
|
81
|
+
*/
|
|
82
|
+
export function assertSchemaName(schema) {
|
|
83
|
+
assertSafeIdentifier(schema, 'schema name');
|
|
84
|
+
if (schema.length > 63) {
|
|
85
|
+
throw new Error(`Schema name ${JSON.stringify(schema)} is longer than 63 characters.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
75
88
|
/**
|
|
76
89
|
* Build the four authz {@link EntitySchema} definitions, optionally under your own table
|
|
77
90
|
* names — this is the supported way to relocate the tables:
|
|
@@ -84,12 +97,23 @@ export class UserRoleEntity {
|
|
|
84
97
|
* Going through the factory (rather than hand-writing `new EntitySchema({ tableName })`)
|
|
85
98
|
* keeps the custom repository binding and the index names attached to the renamed tables;
|
|
86
99
|
* a hand-rolled re-declaration silently drops both.
|
|
100
|
+
*
|
|
101
|
+
* `{ tenantScoped: true }` adds a `tenantId` column to the user-role pivot (in its primary key),
|
|
102
|
+
* so a role can be assigned per tenant. Pass `{}` as the names to keep the default table names.
|
|
87
103
|
*/
|
|
88
|
-
export function createAuthzEntitySchemas(tableNames = {}) {
|
|
104
|
+
export function createAuthzEntitySchemas(tableNames = {}, options = {}) {
|
|
89
105
|
const names = { ...DEFAULT_TABLE_NAMES, ...tableNames };
|
|
106
|
+
for (const [key, name] of Object.entries(names)) {
|
|
107
|
+
assertSafeIdentifier(name, `table name "${key}"`);
|
|
108
|
+
}
|
|
109
|
+
const schema = options.schema;
|
|
110
|
+
if (schema !== undefined)
|
|
111
|
+
assertSchemaName(schema);
|
|
112
|
+
const where = schema === undefined ? {} : { schema };
|
|
90
113
|
const role = new EntitySchema({
|
|
91
114
|
class: RoleEntity,
|
|
92
115
|
tableName: names.roles,
|
|
116
|
+
...where,
|
|
93
117
|
repository: () => AuthzRoleRepository,
|
|
94
118
|
properties: {
|
|
95
119
|
id: { type: 'string', length: 191, primary: true },
|
|
@@ -106,6 +130,7 @@ export function createAuthzEntitySchemas(tableNames = {}) {
|
|
|
106
130
|
const permission = new EntitySchema({
|
|
107
131
|
class: PermissionEntity,
|
|
108
132
|
tableName: names.permissions,
|
|
133
|
+
...where,
|
|
109
134
|
repository: () => AuthzPermissionRepository,
|
|
110
135
|
properties: {
|
|
111
136
|
id: { type: 'string', length: 191, primary: true },
|
|
@@ -122,6 +147,7 @@ export function createAuthzEntitySchemas(tableNames = {}) {
|
|
|
122
147
|
const rolePermission = new EntitySchema({
|
|
123
148
|
class: RolePermissionEntity,
|
|
124
149
|
tableName: names.rolePermission,
|
|
150
|
+
...where,
|
|
125
151
|
repository: () => AuthzRolePermissionRepository,
|
|
126
152
|
properties: {
|
|
127
153
|
roleId: { type: 'string', length: 191, primary: true },
|
|
@@ -131,6 +157,7 @@ export function createAuthzEntitySchemas(tableNames = {}) {
|
|
|
131
157
|
const userRole = new EntitySchema({
|
|
132
158
|
class: UserRoleEntity,
|
|
133
159
|
tableName: names.userRole,
|
|
160
|
+
...where,
|
|
134
161
|
repository: () => AuthzUserRoleRepository,
|
|
135
162
|
properties: {
|
|
136
163
|
userType: { type: 'string', length: 191, primary: true },
|
|
@@ -145,6 +172,14 @@ export function createAuthzEntitySchemas(tableNames = {}) {
|
|
|
145
172
|
},
|
|
146
173
|
indexes: [{ name: `${names.userRole}_user_idx`, properties: ['userType', 'userId'] }],
|
|
147
174
|
});
|
|
175
|
+
if (options.tenantScoped) {
|
|
176
|
+
// `tenantId` is not a field of the class (the default schemas don't map it), hence the cast.
|
|
177
|
+
userRole.addProperty('tenantId', 'string', {
|
|
178
|
+
length: 191,
|
|
179
|
+
primary: true,
|
|
180
|
+
default: GLOBAL_TENANT,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
148
183
|
return {
|
|
149
184
|
role,
|
|
150
185
|
permission,
|
package/dist/entities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAwB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAE3B;;;;;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;
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAwB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAE3B;;;;;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,2EAA2E;AAC3E,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC;AAUhC;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;GAGG;AACH,MAAM,OAAO,UAAU;IAErB,EAAE,CAAU;IACZ,IAAI,CAAU;IACd,KAAK,CAAiB;IACtB,SAAS,CAAQ;CAClB;AAED,oGAAoG;AACpG,MAAM,OAAO,gBAAgB;IAE3B,EAAE,CAAU;IACZ,IAAI,CAAU;IACd,KAAK,CAAiB;IACtB,SAAS,CAAQ;CA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,cAAc,EAAE,QAAQ,CAAC;KAClD,CAAC;AACJ,CAAC;AAED,MAAM,cAAc,GAAG,wBAAwB,EAAE,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG,cAAc,CAAC,IAAI,CAAC;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,cAAc,CAAC,UAAU,CAAC;AAChE,MAAM,CAAC,MAAM,0BAA0B,GAAG,cAAc,CAAC,cAAc,CAAC;AACxE,MAAM,CAAC,MAAM,oBAAoB,GAAG,cAAc,CAAC,QAAQ,CAAC;AAE5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,cAAc,CAAC,GAAG,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,UAAU;IACV,gBAAgB;IAChB,oBAAoB;IACpB,cAAc;CACN,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
export { AUTHZ_ENTITIES, AUTHZ_ENTITY_CLASSES, createAuthzEntitySchemas, DEFAULT_TABLE_NAMES, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
|
|
2
|
-
export type { AuthzEntitySchemas, AuthzTableNames } from './entities.js';
|
|
1
|
+
export { AUTHZ_ENTITIES, AUTHZ_ENTITY_CLASSES, createAuthzEntitySchemas, DEFAULT_TABLE_NAMES, GLOBAL_TENANT, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
|
|
2
|
+
export type { AuthzEntitySchemaOptions, AuthzEntitySchemas, AuthzTableNames, } from './entities.js';
|
|
3
3
|
export { AuthzPermissionRepository, AuthzRolePermissionRepository, AuthzRoleRepository, AuthzUserRoleRepository, } from './repositories.js';
|
|
4
4
|
export { authzSchemaSql, ensureAuthzSchema } from './schema.js';
|
|
5
5
|
export { MikroOrmAuthzStore } from './mikro-orm-authz.store.js';
|
|
6
|
-
export type { RoleAssignment, RoleAssignmentFilter, RoleSourceOptions, UserAuthz, UserRoleAssignment, } from './mikro-orm-authz.store.js';
|
|
6
|
+
export type { RoleAssignment, RoleAssignmentFilter, RoleSourceOptions, TenantScope, UserAuthz, UserRoleAssignment, } from './mikro-orm-authz.store.js';
|
|
7
7
|
export { AUTHZ_RBAC_OPTIONS, AUTHZ_RBAC_STORE, AuthzRbacModule, defaultUserRefMapper, } from './authz-rbac.module.js';
|
|
8
8
|
export type { AuthzRbacModuleAsyncOptions, AuthzRbacModuleOptions, UserRefMapper, } from './authz-rbac.module.js';
|
|
9
9
|
export type { AuthzStoreOptions } from './types.js';
|
|
10
|
+
export type { AuthzTenancyOption, TenantResolver } from './tenancy.js';
|
|
10
11
|
export type { UserRef, UserRefInput } from '@dudousxd/nestjs-authz/store-kit';
|
|
11
12
|
export { applyScope, compileScope } from './scope.js';
|
|
12
13
|
export type { ScopeResolver } from './scope.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,YAAY,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,wBAAwB,EACxB,kBAAkB,EAClB,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,WAAW,EACX,SAAS,EACT,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,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,MAAM,YAAY,CAAC;AACpD,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACvE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AUTHZ_ENTITIES, AUTHZ_ENTITY_CLASSES, createAuthzEntitySchemas, DEFAULT_TABLE_NAMES, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
|
|
1
|
+
export { AUTHZ_ENTITIES, AUTHZ_ENTITY_CLASSES, createAuthzEntitySchemas, DEFAULT_TABLE_NAMES, GLOBAL_TENANT, PermissionEntity, PermissionEntitySchema, RoleEntity, RoleEntitySchema, RolePermissionEntity, RolePermissionEntitySchema, UserRoleEntity, UserRoleEntitySchema, } from './entities.js';
|
|
2
2
|
// VALUE exports on purpose: these classes are the DI tokens `MikroOrmModule.forFeature()`
|
|
3
3
|
// registers, so `export type` would compile green and be `undefined` at runtime.
|
|
4
4
|
export { AuthzPermissionRepository, AuthzRolePermissionRepository, AuthzRoleRepository, AuthzUserRoleRepository, } from './repositories.js';
|
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,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,sBAAsB,EACtB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,cAAc,EACd,oBAAoB,GACrB,MAAM,eAAe,CAAC;AAMvB,0FAA0F;AAC1F,iFAAiF;AACjF,OAAO,EACL,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAShE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|