@dudousxd/nestjs-authz-typeorm 0.2.1 → 0.3.1
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 +64 -0
- package/dist/authz-rbac.module.d.ts +1 -1
- package/dist/authz-rbac.module.d.ts.map +1 -1
- package/dist/authz-rbac.module.js +86 -8
- package/dist/authz-rbac.module.js.map +1 -1
- package/dist/entities.d.ts +30 -1
- package/dist/entities.d.ts.map +1 -1
- package/dist/entities.js +51 -0
- package/dist/entities.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +28 -4
- package/dist/schema.js.map +1 -1
- package/dist/scope.d.ts +75 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +124 -0
- package/dist/scope.js.map +1 -0
- package/dist/sql.d.ts +1 -8
- package/dist/sql.d.ts.map +1 -1
- package/dist/sql.js +3 -19
- package/dist/sql.js.map +1 -1
- package/dist/typeorm-authz.store.d.ts +59 -21
- package/dist/typeorm-authz.store.d.ts.map +1 -1
- package/dist/typeorm-authz.store.js +129 -33
- package/dist/typeorm-authz.store.js.map +1 -1
- package/dist/types.d.ts +10 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -2
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,GAAG,CAAC,CAAC;IAChB,MAAM,SAAS,GAAG,GAAW,EAAE,CAAC,GAAG,WAAW,IAAI,OAAO,EAAE,EAAE,CAAC;IAE9D,MAAM,MAAM,GAAG,CAAC,KAAa,EAAU,EAA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A2B;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"}
|
package/dist/sql.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { DataSource } from 'typeorm';
|
|
2
|
+
export { assertSafeIdentifier } from '@dudousxd/nestjs-authz';
|
|
2
3
|
/** True when the DataSource's driver expects `$n` positional placeholders. */
|
|
3
4
|
export declare function isPostgresFamily(dataSource: DataSource): boolean;
|
|
4
5
|
/**
|
|
@@ -19,12 +20,4 @@ export declare class Placeholders {
|
|
|
19
20
|
/** The next placeholder token, advancing the positional counter. */
|
|
20
21
|
next(): string;
|
|
21
22
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Validate an identifier (table/schema name) against {@link SAFE_IDENTIFIER}.
|
|
24
|
-
* Throws on anything containing quotes, dots, whitespace, or other unsafe chars.
|
|
25
|
-
*
|
|
26
|
-
* @param value the identifier to check
|
|
27
|
-
* @param what a label for the error message (e.g. `table name "roles"`)
|
|
28
|
-
*/
|
|
29
|
-
export declare function assertSafeIdentifier(value: string, what: string): void;
|
|
30
23
|
//# sourceMappingURL=sql.d.ts.map
|
package/dist/sql.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAI1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAS9D,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAEhE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,qBAAa,YAAY;IAEX,OAAO,CAAC,QAAQ,CAAC,QAAQ;IADrC,OAAO,CAAC,KAAK,CAAK;gBACW,QAAQ,EAAE,OAAO;IAE9C,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,YAAY;IAIhD,oEAAoE;IACpE,IAAI,IAAI,MAAM;CAKf"}
|
package/dist/sql.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Re-exported so the package's existing `./sql.js` import sites (and tests) keep working while the
|
|
2
|
+
// guard itself is single-sourced in core.
|
|
3
|
+
export { assertSafeIdentifier } from '@dudousxd/nestjs-authz';
|
|
1
4
|
/**
|
|
2
5
|
* Database types whose driver binds parameters with positional `$1, $2, …`
|
|
3
6
|
* placeholders instead of `?`. Postgres (and its aurora/cockroach kin) reject the
|
|
@@ -36,23 +39,4 @@ export class Placeholders {
|
|
|
36
39
|
return token;
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
|
-
/**
|
|
40
|
-
* SQL identifiers (table / schema names) are interpolated into query text, NOT
|
|
41
|
-
* passed as bound parameters — `driver.escape()` only wraps them in quotes, it does
|
|
42
|
-
* NOT neutralize an embedded quote. To keep BYO `tableNames`/`schema` safe, restrict
|
|
43
|
-
* them to a conservative allowlist and reject anything else loudly.
|
|
44
|
-
*/
|
|
45
|
-
const SAFE_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
46
|
-
/**
|
|
47
|
-
* Validate an identifier (table/schema name) against {@link SAFE_IDENTIFIER}.
|
|
48
|
-
* Throws on anything containing quotes, dots, whitespace, or other unsafe chars.
|
|
49
|
-
*
|
|
50
|
-
* @param value the identifier to check
|
|
51
|
-
* @param what a label for the error message (e.g. `table name "roles"`)
|
|
52
|
-
*/
|
|
53
|
-
export function assertSafeIdentifier(value, what) {
|
|
54
|
-
if (!SAFE_IDENTIFIER.test(value)) {
|
|
55
|
-
throw new Error(`Unsafe ${what}: ${JSON.stringify(value)}. Identifiers must match /^[A-Za-z_][A-Za-z0-9_]*$/ (letters, digits, underscore; not starting with a digit). This blocks SQL injection via configured names.`);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
42
|
//# sourceMappingURL=sql.js.map
|
package/dist/sql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql.js","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC;AAE3F,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB,CAAC,UAAsB;IACrD,OAAO,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WA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E,CAAC,CAAC,CAAC,GAAG,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,YAAY;IAEM;IADrB,KAAK,GAAG,CAAC,CAAC;IAClB,YAA6B,QAAiB;QAAjB,aAAQ,GAAR,QAAQ,CAAS;IAAG,CAAC;IAElD,MAAM,CAAC,GAAG,CAAC,UAAsB;QAC/B,OAAO,IAAI,YAAY,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,oEAAoE;IACpE,IAAI;QACF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QACzD,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;QAChB,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
+
import { type UserAuthz, type UserRef } from '@dudousxd/nestjs-authz/store-kit';
|
|
1
2
|
import type { DataSource } from 'typeorm';
|
|
2
|
-
import type { AuthzStoreOptions,
|
|
3
|
-
|
|
4
|
-
* A user's effective permissions: the role names they hold and the flattened set of
|
|
5
|
-
* permission names granted by those roles.
|
|
6
|
-
*/
|
|
7
|
-
export interface UserAuthz {
|
|
8
|
-
roles: string[];
|
|
9
|
-
permissions: string[];
|
|
10
|
-
}
|
|
3
|
+
import type { AuthzStoreOptions, TenantScope } from './types.js';
|
|
4
|
+
export type { UserAuthz };
|
|
11
5
|
/**
|
|
12
6
|
* TypeORM-backed RBAC store. A plain POJO that receives the `DataSource` in its
|
|
13
7
|
* constructor — NOT `@Injectable`, no internal connection token (the app owns the
|
|
@@ -48,17 +42,61 @@ export declare class TypeOrmAuthzStore {
|
|
|
48
42
|
givePermissionToRole(roleName: string, permissionName: string): Promise<void>;
|
|
49
43
|
/** Revoke a permission from a role. No-op if either is absent or not linked. */
|
|
50
44
|
revokePermissionFromRole(roleName: string, permissionName: string): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Assign a role to a user (creating the role by name if needed). Idempotent.
|
|
47
|
+
*
|
|
48
|
+
* Pass `{ tenantId }` to scope the assignment to a tenant — it then applies ONLY
|
|
49
|
+
* within that tenant. Omitting it (the default) makes a GLOBAL assignment that
|
|
50
|
+
* applies in every tenant (and in an unscoped check). The same `(user, role)` can
|
|
51
|
+
* be assigned in multiple tenants independently.
|
|
52
|
+
*/
|
|
53
|
+
assignRole(user: UserRef, roleName: string, scope?: TenantScope): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Remove a role from a user. No-op if the role or assignment is absent. When
|
|
56
|
+
* `{ tenantId }` is given, only the assignment in THAT tenant is removed; omitting
|
|
57
|
+
* it removes the GLOBAL assignment (tenant `''`).
|
|
58
|
+
*/
|
|
59
|
+
removeRole(user: UserRef, roleName: string, scope?: TenantScope): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Grant a permission DIRECTLY to a user (creating the permission by name if
|
|
62
|
+
* needed) — no role required. Mirrors Laravel/spatie's `$user->givePermissionTo`.
|
|
63
|
+
* Idempotent.
|
|
64
|
+
*/
|
|
65
|
+
giveUserPermission(user: UserRef, permissionName: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Revoke a DIRECT user permission. No-op if the permission or grant is absent.
|
|
68
|
+
* Only the direct grant is removed — a permission the user ALSO has via a role
|
|
69
|
+
* survives.
|
|
70
|
+
*/
|
|
71
|
+
revokeUserPermission(user: UserRef, permissionName: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* SQL fragment + params matching role assignments visible for a tenant scope: a
|
|
74
|
+
* GLOBAL assignment (tenant `''`) always applies; a tenant-scoped one applies only
|
|
75
|
+
* when its tenant matches the requested one. With no requested tenant, only global
|
|
76
|
+
* assignments are visible (a tenant-scoped role never leaks into an unscoped check).
|
|
77
|
+
*/
|
|
78
|
+
private tenantFilter;
|
|
79
|
+
/** Bind values for {@link tenantFilter}, in the same order it emits placeholders. */
|
|
80
|
+
private tenantParams;
|
|
81
|
+
/**
|
|
82
|
+
* The role names a user holds, optionally restricted to a tenant scope (see
|
|
83
|
+
* {@link assignRole}). With no scope, only global roles are returned.
|
|
84
|
+
*/
|
|
85
|
+
getRolesForUser(user: UserRef, scope?: TenantScope): Promise<string[]>;
|
|
86
|
+
/**
|
|
87
|
+
* The flattened, distinct permission names a user has — the UNION of role-derived
|
|
88
|
+
* permissions (honoring the tenant scope) and DIRECT user permissions (which are
|
|
89
|
+
* not tenant-scoped). With no scope, role-derived permissions come from global
|
|
90
|
+
* roles only.
|
|
91
|
+
*/
|
|
92
|
+
getPermissionsForUser(user: UserRef, scope?: TenantScope): Promise<string[]>;
|
|
93
|
+
/** A user's roles + effective permissions in one shot (tenant-aware). */
|
|
94
|
+
getUserAuthz(user: UserRef, scope?: TenantScope): Promise<UserAuthz>;
|
|
95
|
+
/**
|
|
96
|
+
* True when the user holds `permission` — via a (tenant-scoped) role OR a direct
|
|
97
|
+
* grant. With no scope, only global role assignments count toward the role path;
|
|
98
|
+
* direct grants always count.
|
|
99
|
+
*/
|
|
100
|
+
userHasPermission(user: UserRef, permission: string, scope?: TenantScope): Promise<boolean>;
|
|
63
101
|
}
|
|
64
102
|
//# 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,
|
|
1
|
+
{"version":3,"file":"typeorm-authz.store.d.ts","sourceRoot":"","sources":["../src/typeorm-authz.store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,OAA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AO,CAAC,IAAI,CAAC;IAarF;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBrF;;;;OAIG;IACG,kBAAkB,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY9E;;;;OAIG;IACG,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAehF;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAWpB,qFAAqF;IACrF,OAAO,CAAC,YAAY;IAKpB;;;OAGG;IACG,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAgB5E;;;;;OAKG;IACG,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAqClF,yEAAyE;IACnE,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;IAQ1E;;;;OAIG;IACG,iBAAiB,CACrB,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,MAAM,EAClB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,OAAO,CAAC;CAsCpB"}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeUserRef } from '@dudousxd/nestjs-authz/store-kit';
|
|
3
|
+
import { DEFAULT_TABLE_NAMES, GLOBAL_TENANT } from './entities.js';
|
|
3
4
|
import { ensureAuthzSchema } from './schema.js';
|
|
4
5
|
import { Placeholders, assertSafeIdentifier } from './sql.js';
|
|
5
|
-
/** Normalize a {@link UserRef} to `{ type, id }` with `id` stringified. */
|
|
6
|
-
function normalizeUserRef(ref) {
|
|
7
|
-
if (typeof ref === 'string' || typeof ref === 'number') {
|
|
8
|
-
return { type: 'user', id: String(ref) };
|
|
9
|
-
}
|
|
10
|
-
return { type: ref.type ?? 'user', id: String(ref.id) };
|
|
11
|
-
}
|
|
12
6
|
/**
|
|
13
7
|
* TypeORM-backed RBAC store. A plain POJO that receives the `DataSource` in its
|
|
14
8
|
* constructor — NOT `@Injectable`, no internal connection token (the app owns the
|
|
@@ -30,6 +24,7 @@ export class TypeOrmAuthzStore {
|
|
|
30
24
|
permissions: opts.tableNames?.permissions ?? DEFAULT_TABLE_NAMES.permissions,
|
|
31
25
|
rolePermission: opts.tableNames?.rolePermission ?? DEFAULT_TABLE_NAMES.rolePermission,
|
|
32
26
|
userRole: opts.tableNames?.userRole ?? DEFAULT_TABLE_NAMES.userRole,
|
|
27
|
+
userPermission: opts.tableNames?.userPermission ?? DEFAULT_TABLE_NAMES.userPermission,
|
|
33
28
|
};
|
|
34
29
|
this.schema = opts.schema;
|
|
35
30
|
// P4: identifiers are interpolated into SQL — validate BYO names/schema up
|
|
@@ -134,63 +129,164 @@ export class TypeOrmAuthzStore {
|
|
|
134
129
|
await this.dataSource.query(`DELETE FROM ${this.table('rolePermission')} WHERE ${this.col('roleId')} = ${p.next()} AND ${this.col('permissionId')} = ${p.next()}`, [roleId, permissionId]);
|
|
135
130
|
}
|
|
136
131
|
// --- user ↔ role ---
|
|
137
|
-
/**
|
|
138
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Assign a role to a user (creating the role by name if needed). Idempotent.
|
|
134
|
+
*
|
|
135
|
+
* Pass `{ tenantId }` to scope the assignment to a tenant — it then applies ONLY
|
|
136
|
+
* within that tenant. Omitting it (the default) makes a GLOBAL assignment that
|
|
137
|
+
* applies in every tenant (and in an unscoped check). The same `(user, role)` can
|
|
138
|
+
* be assigned in multiple tenants independently.
|
|
139
|
+
*/
|
|
140
|
+
async assignRole(user, roleName, scope) {
|
|
139
141
|
const { type, id } = normalizeUserRef(user);
|
|
140
142
|
const roleId = await this.createRole(roleName);
|
|
143
|
+
const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
|
|
141
144
|
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]);
|
|
145
|
+
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
146
|
}
|
|
144
|
-
/**
|
|
145
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Remove a role from a user. No-op if the role or assignment is absent. When
|
|
149
|
+
* `{ tenantId }` is given, only the assignment in THAT tenant is removed; omitting
|
|
150
|
+
* it removes the GLOBAL assignment (tenant `''`).
|
|
151
|
+
*/
|
|
152
|
+
async removeRole(user, roleName, scope) {
|
|
146
153
|
const { type, id } = normalizeUserRef(user);
|
|
147
154
|
const roleId = await this.findRoleId(roleName);
|
|
148
155
|
if (!roleId)
|
|
149
156
|
return;
|
|
157
|
+
const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
|
|
150
158
|
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]);
|
|
159
|
+
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]);
|
|
160
|
+
}
|
|
161
|
+
// --- user ↔ permission (DIRECT grant, no role) ---
|
|
162
|
+
/**
|
|
163
|
+
* Grant a permission DIRECTLY to a user (creating the permission by name if
|
|
164
|
+
* needed) — no role required. Mirrors Laravel/spatie's `$user->givePermissionTo`.
|
|
165
|
+
* Idempotent.
|
|
166
|
+
*/
|
|
167
|
+
async giveUserPermission(user, permissionName) {
|
|
168
|
+
const { type, id } = normalizeUserRef(user);
|
|
169
|
+
const permissionId = await this.createPermission(permissionName);
|
|
170
|
+
const p = this.params();
|
|
171
|
+
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]);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Revoke a DIRECT user permission. No-op if the permission or grant is absent.
|
|
175
|
+
* Only the direct grant is removed — a permission the user ALSO has via a role
|
|
176
|
+
* survives.
|
|
177
|
+
*/
|
|
178
|
+
async revokeUserPermission(user, permissionName) {
|
|
179
|
+
const { type, id } = normalizeUserRef(user);
|
|
180
|
+
const permissionId = await this.findPermissionId(permissionName);
|
|
181
|
+
if (!permissionId)
|
|
182
|
+
return;
|
|
183
|
+
const p = this.params();
|
|
184
|
+
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
185
|
}
|
|
153
186
|
// --- queries ---
|
|
154
|
-
/**
|
|
155
|
-
|
|
187
|
+
/**
|
|
188
|
+
* SQL fragment + params matching role assignments visible for a tenant scope: a
|
|
189
|
+
* GLOBAL assignment (tenant `''`) always applies; a tenant-scoped one applies only
|
|
190
|
+
* when its tenant matches the requested one. With no requested tenant, only global
|
|
191
|
+
* assignments are visible (a tenant-scoped role never leaks into an unscoped check).
|
|
192
|
+
*/
|
|
193
|
+
tenantFilter(alias, scope, p) {
|
|
194
|
+
const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
|
|
195
|
+
if (tenantId === GLOBAL_TENANT) {
|
|
196
|
+
return ` AND ${alias}.${this.col('tenantId')} = ${p.next()}`;
|
|
197
|
+
}
|
|
198
|
+
// Visible = global OR exactly this tenant.
|
|
199
|
+
return ` AND (${alias}.${this.col('tenantId')} = ${p.next()} OR ${alias}.${this.col('tenantId')} = ${p.next()})`;
|
|
200
|
+
}
|
|
201
|
+
/** Bind values for {@link tenantFilter}, in the same order it emits placeholders. */
|
|
202
|
+
tenantParams(scope) {
|
|
203
|
+
const tenantId = scope?.tenantId ?? GLOBAL_TENANT;
|
|
204
|
+
return tenantId === GLOBAL_TENANT ? [GLOBAL_TENANT] : [GLOBAL_TENANT, tenantId];
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The role names a user holds, optionally restricted to a tenant scope (see
|
|
208
|
+
* {@link assignRole}). With no scope, only global roles are returned.
|
|
209
|
+
*/
|
|
210
|
+
async getRolesForUser(user, scope) {
|
|
156
211
|
const { type, id } = normalizeUserRef(user);
|
|
157
212
|
const p = this.params();
|
|
213
|
+
const userType = p.next();
|
|
214
|
+
const userId = p.next();
|
|
215
|
+
const filter = this.tenantFilter('ur', scope, p);
|
|
158
216
|
const rows = (await this.dataSource.query(`SELECT r.${this.col('name')} AS name
|
|
159
217
|
FROM ${this.table('userRole')} ur
|
|
160
218
|
JOIN ${this.table('roles')} r ON r.${this.col('id')} = ur.${this.col('roleId')}
|
|
161
|
-
WHERE ur.${this.col('userType')} = ${
|
|
219
|
+
WHERE ur.${this.col('userType')} = ${userType} AND ur.${this.col('userId')} = ${userId}${filter}`, [type, id, ...this.tenantParams(scope)]));
|
|
162
220
|
return rows.map((row) => row.name);
|
|
163
221
|
}
|
|
164
|
-
/**
|
|
165
|
-
|
|
222
|
+
/**
|
|
223
|
+
* The flattened, distinct permission names a user has — the UNION of role-derived
|
|
224
|
+
* permissions (honoring the tenant scope) and DIRECT user permissions (which are
|
|
225
|
+
* not tenant-scoped). With no scope, role-derived permissions come from global
|
|
226
|
+
* roles only.
|
|
227
|
+
*/
|
|
228
|
+
async getPermissionsForUser(user, scope) {
|
|
166
229
|
const { type, id } = normalizeUserRef(user);
|
|
167
|
-
|
|
168
|
-
const
|
|
230
|
+
// Role-derived (tenant-aware).
|
|
231
|
+
const pr = this.params();
|
|
232
|
+
const rUserType = pr.next();
|
|
233
|
+
const rUserId = pr.next();
|
|
234
|
+
const rFilter = this.tenantFilter('ur', scope, pr);
|
|
235
|
+
const roleRows = (await this.dataSource.query(`SELECT DISTINCT p.${this.col('name')} AS name
|
|
169
236
|
FROM ${this.table('userRole')} ur
|
|
170
237
|
JOIN ${this.table('rolePermission')} rp ON rp.${this.col('roleId')} = ur.${this.col('roleId')}
|
|
171
238
|
JOIN ${this.table('permissions')} p ON p.${this.col('id')} = rp.${this.col('permissionId')}
|
|
172
|
-
WHERE ur.${this.col('userType')} = ${
|
|
173
|
-
|
|
239
|
+
WHERE ur.${this.col('userType')} = ${rUserType} AND ur.${this.col('userId')} = ${rUserId}${rFilter}`, [type, id, ...this.tenantParams(scope)]));
|
|
240
|
+
// Direct grants (not tenant-scoped).
|
|
241
|
+
const pd = this.params();
|
|
242
|
+
const directRows = (await this.dataSource.query(`SELECT DISTINCT p.${this.col('name')} AS name
|
|
243
|
+
FROM ${this.table('userPermission')} up
|
|
244
|
+
JOIN ${this.table('permissions')} p ON p.${this.col('id')} = up.${this.col('permissionId')}
|
|
245
|
+
WHERE up.${this.col('userType')} = ${pd.next()} AND up.${this.col('userId')} = ${pd.next()}`, [type, id]));
|
|
246
|
+
const out = new Set();
|
|
247
|
+
for (const row of roleRows)
|
|
248
|
+
out.add(row.name);
|
|
249
|
+
for (const row of directRows)
|
|
250
|
+
out.add(row.name);
|
|
251
|
+
return [...out];
|
|
174
252
|
}
|
|
175
|
-
/** A user's roles + effective permissions in one shot. */
|
|
176
|
-
async getUserAuthz(user) {
|
|
253
|
+
/** A user's roles + effective permissions in one shot (tenant-aware). */
|
|
254
|
+
async getUserAuthz(user, scope) {
|
|
177
255
|
const [roles, permissions] = await Promise.all([
|
|
178
|
-
this.getRolesForUser(user),
|
|
179
|
-
this.getPermissionsForUser(user),
|
|
256
|
+
this.getRolesForUser(user, scope),
|
|
257
|
+
this.getPermissionsForUser(user, scope),
|
|
180
258
|
]);
|
|
181
259
|
return { roles, permissions };
|
|
182
260
|
}
|
|
183
|
-
/**
|
|
184
|
-
|
|
261
|
+
/**
|
|
262
|
+
* True when the user holds `permission` — via a (tenant-scoped) role OR a direct
|
|
263
|
+
* grant. With no scope, only global role assignments count toward the role path;
|
|
264
|
+
* direct grants always count.
|
|
265
|
+
*/
|
|
266
|
+
async userHasPermission(user, permission, scope) {
|
|
185
267
|
const { type, id } = normalizeUserRef(user);
|
|
186
|
-
|
|
187
|
-
const
|
|
268
|
+
// Role path (tenant-aware).
|
|
269
|
+
const pr = this.params();
|
|
270
|
+
const rUserType = pr.next();
|
|
271
|
+
const rUserId = pr.next();
|
|
272
|
+
const rName = pr.next();
|
|
273
|
+
const rFilter = this.tenantFilter('ur', scope, pr);
|
|
274
|
+
const roleRows = (await this.dataSource.query(`SELECT 1 AS x
|
|
188
275
|
FROM ${this.table('userRole')} ur
|
|
189
276
|
JOIN ${this.table('rolePermission')} rp ON rp.${this.col('roleId')} = ur.${this.col('roleId')}
|
|
190
277
|
JOIN ${this.table('permissions')} p ON p.${this.col('id')} = rp.${this.col('permissionId')}
|
|
191
|
-
WHERE ur.${this.col('userType')} = ${
|
|
278
|
+
WHERE ur.${this.col('userType')} = ${rUserType} AND ur.${this.col('userId')} = ${rUserId} AND p.${this.col('name')} = ${rName}${rFilter}
|
|
279
|
+
LIMIT 1`, [type, id, permission, ...this.tenantParams(scope)]));
|
|
280
|
+
if (roleRows.length > 0)
|
|
281
|
+
return true;
|
|
282
|
+
// Direct path.
|
|
283
|
+
const pd = this.params();
|
|
284
|
+
const directRows = (await this.dataSource.query(`SELECT 1 AS x
|
|
285
|
+
FROM ${this.table('userPermission')} up
|
|
286
|
+
JOIN ${this.table('permissions')} p ON p.${this.col('id')} = up.${this.col('permissionId')}
|
|
287
|
+
WHERE up.${this.col('userType')} = ${pd.next()} AND up.${this.col('userId')} = ${pd.next()} AND p.${this.col('name')} = ${pd.next()}
|
|
192
288
|
LIMIT 1`, [type, id, permission]));
|
|
193
|
-
return
|
|
289
|
+
return directRows.length > 0;
|
|
194
290
|
}
|
|
195
291
|
}
|
|
196
292
|
//# 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,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;AAC1D,CAAC;AAWD;;;;;;;GAOG;AACH,MAAM,OAAO,iBAAiB;IAKT;IACA;IALF,KAAK,CAA0E;IAC/E,MAAM,CAAqB;IAE5C,YACmB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AAM,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,17 +4,18 @@ 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;
|
|
7
9
|
}
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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;
|
|
15
18
|
}
|
|
16
|
-
/** A user reference, or just its id (treated as `{ type: 'user', id }`). */
|
|
17
|
-
export type UserRef = UserRefInput | string | number;
|
|
18
19
|
export interface AuthzStoreOptions {
|
|
19
20
|
/** BYO table names; each defaults to the matching {@link DEFAULT_TABLE_NAMES} entry. */
|
|
20
21
|
tableNames?: TableNames;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -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;
|
|
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,MAAM,WAAW,iBAAiB;IAChC,wFAAwF;IACxF,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|