@voltro/plugin-rbac 0.32.0 → 0.34.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 +2006 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +35 -31
- package/package.json +6 -5
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,13 @@ export declare interface RbacContext {
|
|
|
117
117
|
export declare const rbacPlugin: (options: RbacPluginOptions) => VoltroPlugin;
|
|
118
118
|
|
|
119
119
|
export declare interface RbacPluginOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Namespace for this plugin's inspect surface + any rpc tags it contributes. Default `rbac`.
|
|
122
|
+
*
|
|
123
|
+
* Set it when your app already publishes under that name — an exact tag
|
|
124
|
+
* collision is fatal at codegen, and this is the way out.
|
|
125
|
+
*/
|
|
126
|
+
readonly alias?: string;
|
|
120
127
|
/**
|
|
121
128
|
* Declarative role → permission map. Each role lists the permission
|
|
122
129
|
* strings (== scope strings) it grants. `'*'` in any role's list
|
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, p as c, r as l, s as u, t as d, u as f } from "./permission-DhL6E-Nc.js";
|
|
2
2
|
import { Effect as p } from "effect";
|
|
3
|
-
import { ADMIN_SCOPE as m, ScopeError as h, ScopeError as g, definePlugin as _,
|
|
4
|
-
import { createLogger as
|
|
5
|
-
import { and as
|
|
3
|
+
import { ADMIN_SCOPE as m, ScopeError as h, ScopeError as g, definePlugin as _, pluginInstanceName as v, setResourceScopeResolver as y } from "@voltro/protocol";
|
|
4
|
+
import { createLogger as b } from "@voltro/logger";
|
|
5
|
+
import { and as x, boolean as S, eq as C, id as w, json as T, or as E, reference as D, requireTenants as O, table as k, text as A } from "@voltro/database";
|
|
6
6
|
//#region src/tables.ts
|
|
7
|
-
var
|
|
8
|
-
id:
|
|
9
|
-
slug:
|
|
10
|
-
name:
|
|
11
|
-
permissions:
|
|
12
|
-
isDefault:
|
|
13
|
-
}).index("byRolesSlug", ["slug"]),
|
|
14
|
-
id:
|
|
15
|
-
userId:
|
|
16
|
-
tenantId: e.multitenant ?
|
|
17
|
-
roleSlug:
|
|
18
|
-
}).index("byUserTenant", ["userId", "tenantId"]).index("byRoleSlug", ["roleSlug"]),
|
|
19
|
-
table:
|
|
7
|
+
var j = "_voltro_rbac_roles", M = "_voltro_rbac_user_roles", N = k(j, {
|
|
8
|
+
id: w({ prefix: "role" }),
|
|
9
|
+
slug: A().unique(),
|
|
10
|
+
name: A(),
|
|
11
|
+
permissions: T(),
|
|
12
|
+
isDefault: S().default(!1)
|
|
13
|
+
}).index("byRolesSlug", ["slug"]), P = (e = {}) => k(M, {
|
|
14
|
+
id: w({ prefix: "urole" }),
|
|
15
|
+
userId: A(),
|
|
16
|
+
tenantId: e.multitenant ? D(O(), { index: !1 }).nullable() : A().nullable(),
|
|
17
|
+
roleSlug: A()
|
|
18
|
+
}).index("byUserTenant", ["userId", "tenantId"]).index("byRoleSlug", ["roleSlug"]), F = P(), I = (e = {}) => [N, P(e)], L = (e, t) => e.query({
|
|
19
|
+
table: M,
|
|
20
20
|
predicate: t,
|
|
21
21
|
order: [{
|
|
22
22
|
column: "id",
|
|
@@ -25,11 +25,11 @@ var A = "_voltro_rbac_roles", j = "_voltro_rbac_user_roles", M = O(A, {
|
|
|
25
25
|
take: void 0,
|
|
26
26
|
skip: void 0,
|
|
27
27
|
projection: void 0
|
|
28
|
-
}),
|
|
29
|
-
let t = (t, n, r) =>
|
|
28
|
+
}), R = (e) => {
|
|
29
|
+
let t = (t, n, r) => L(e, x(C("userId", t), C("roleSlug", n), C("tenantId", r)));
|
|
30
30
|
return {
|
|
31
31
|
assign: async (n, r, i = null) => {
|
|
32
|
-
(await t(n, r, i)).length > 0 || await e.insert(
|
|
32
|
+
(await t(n, r, i)).length > 0 || await e.insert(M, {
|
|
33
33
|
userId: n,
|
|
34
34
|
roleSlug: r,
|
|
35
35
|
tenantId: i
|
|
@@ -37,38 +37,38 @@ var A = "_voltro_rbac_roles", j = "_voltro_rbac_user_roles", M = O(A, {
|
|
|
37
37
|
},
|
|
38
38
|
revoke: async (n, r, i = null) => {
|
|
39
39
|
let a = await t(n, r, i);
|
|
40
|
-
for (let t of a) await e.delete(
|
|
40
|
+
for (let t of a) await e.delete(M, String(t.id));
|
|
41
41
|
},
|
|
42
42
|
rolesOf: async (t, n) => {
|
|
43
|
-
let r = (n === void 0 ? await
|
|
43
|
+
let r = (n === void 0 ? await L(e, C("userId", t)) : await L(e, x(C("userId", t), z(n)))).map((e) => String(e.roleSlug));
|
|
44
44
|
return [...new Set(r)];
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
|
-
},
|
|
47
|
+
}, z = (e) => e === null ? C("tenantId", null) : E(C("tenantId", e), C("tenantId", null)), B = (e) => (t) => {
|
|
48
48
|
let n = ("tenantId" in t ? t.tenantId : void 0) ?? null, r = ("id" in t ? t.id : void 0) ?? null;
|
|
49
49
|
return r ? e.rolesOf(r, n) : [];
|
|
50
|
-
},
|
|
50
|
+
}, V = b({ scope: "@voltro/plugin-rbac" }), H = (e) => p.suspend(() => {
|
|
51
51
|
let t = e();
|
|
52
52
|
return t instanceof Promise ? p.promise(() => t) : p.succeed(t);
|
|
53
|
-
}),
|
|
53
|
+
}), U = "@voltro/plugin-rbac", W = (t) => {
|
|
54
54
|
let i = t.resolveRoles ?? s, o = t.resolvePermissions, c = t.tables !== void 0 && t.tables !== !1, l = typeof t.tables == "object" ? t.tables : {};
|
|
55
55
|
if (t.resolveResourceRoles) {
|
|
56
56
|
let e = t.resolveResourceRoles;
|
|
57
|
-
|
|
57
|
+
y(({ subject: r, scope: i, resource: a }) => H(() => e(r, a)).pipe(p.map((e) => {
|
|
58
58
|
let r = n(e, t.roles);
|
|
59
59
|
return r.includes(m) || r.includes(i);
|
|
60
|
-
}), p.catchAllCause((e) => (
|
|
60
|
+
}), p.catchAllCause((e) => (V.warn("resolveResourceRoles failed; denying (fail-closed)", {
|
|
61
61
|
scope: i,
|
|
62
62
|
resource: a,
|
|
63
63
|
cause: String(e)
|
|
64
64
|
}), p.succeed(!1)))));
|
|
65
65
|
}
|
|
66
66
|
let u = (n, r) => p.gen(function* () {
|
|
67
|
-
let s = yield*
|
|
67
|
+
let s = yield* H(() => i(r.subject)).pipe(p.catchAllCause((e) => (V.warn("resolveRoles failed; falling back to raw subject scopes", {
|
|
68
68
|
tag: r.tag,
|
|
69
69
|
traceId: r.traceId,
|
|
70
70
|
cause: String(e)
|
|
71
|
-
}), p.succeed([])))), c = o ? yield*
|
|
71
|
+
}), p.succeed([])))), c = o ? yield* H(() => o(r.subject)).pipe(p.catchAllCause(() => p.succeed([]))) : [], l = e(r.subject, s, t.roles, c);
|
|
72
72
|
return a(r.subject, l, s), yield* n;
|
|
73
73
|
}), d = [
|
|
74
74
|
"rpc:intercept:mutation",
|
|
@@ -77,7 +77,11 @@ var A = "_voltro_rbac_roles", j = "_voltro_rbac_user_roles", M = O(A, {
|
|
|
77
77
|
...c ? ["store:write"] : []
|
|
78
78
|
], f = o === void 0 ? r(t.roles) : void 0;
|
|
79
79
|
return _({
|
|
80
|
-
name:
|
|
80
|
+
name: v({
|
|
81
|
+
base: U,
|
|
82
|
+
alias: t.alias
|
|
83
|
+
}),
|
|
84
|
+
baseName: U,
|
|
81
85
|
...f === void 0 ? {} : { declaredScopes: f },
|
|
82
86
|
description: "Role-based access control — roles compile to scopes on top of the protocol scope system. Ships the permission() handler guard + a role→scope interceptor + a resource-aware guard resolver, failing with protocol's typed ScopeError (one denial tag framework-wide).",
|
|
83
87
|
permissions: d,
|
|
@@ -91,8 +95,8 @@ var A = "_voltro_rbac_roles", j = "_voltro_rbac_user_roles", M = O(A, {
|
|
|
91
95
|
name: "ScopeError"
|
|
92
96
|
}
|
|
93
97
|
}],
|
|
94
|
-
...c ? { extendSchema: { tables: [...
|
|
98
|
+
...c ? { extendSchema: { tables: [...I(l)] } } : {}
|
|
95
99
|
});
|
|
96
100
|
};
|
|
97
101
|
//#endregion
|
|
98
|
-
export {
|
|
102
|
+
export { j as ROLES_TABLE, h as ScopeError, M as USER_ROLES_TABLE, f as WILDCARD_PERMISSION, d as anyPermission, o as assertPermission, P as buildUserRolesTable, l as can, n as compileRoles, B as dataStoreRoleResolver, e as mergeResolvedScopes, s as metadataRoleResolver, i as permission, W as rbacPlugin, I as rbacTables, u as resolvedRoles, t as resolvedScopes, c as rolesFromMap, N as rolesTable, a as setResolvedScopes, R as userRoleStore, F as userRolesTable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-rbac",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "Role-based access control — roles compile to scopes on top of @voltro/protocol's scope system. Ships rbacPlugin() (role→scope interceptor + resource-aware guard resolver, failing with protocol's typed ScopeError), the permission()/assertPermission()/anyPermission() handler guards, the compileRoles() pure compiler, cross-dialect roles + userRoles tables. The UI gate lives in @voltro/client (useCan / useCanAny) — scopes are a framework concept, so gating a button must not require this plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
23
23
|
"import": "./dist/index.js",
|
|
24
24
|
"default": "./dist/index.js"
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
26
27
|
},
|
|
27
28
|
"main": "./dist/index.js",
|
|
28
29
|
"module": "./dist/index.js",
|
|
@@ -32,9 +33,9 @@
|
|
|
32
33
|
"node": ">=24.0.0"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
|
-
"@voltro/database": "0.
|
|
36
|
-
"@voltro/logger": "0.
|
|
37
|
-
"@voltro/protocol": "0.
|
|
36
|
+
"@voltro/database": "0.34.0",
|
|
37
|
+
"@voltro/logger": "0.34.0",
|
|
38
|
+
"@voltro/protocol": "0.34.0"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"effect": "^3.22.0",
|