@voltro/plugin-rbac 0.84.0 → 0.86.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 +1215 -0
- package/THIRD-PARTY-NOTICES.md +5 -89
- package/dist/index.js +45 -85
- package/dist/permission.js +33 -2
- package/dist/resolve.js +20 -0
- package/dist/roles.js +22 -0
- package/dist/tables.js +16 -0
- package/dist/userRoleStore.js +40 -0
- package/package.json +5 -5
- package/dist/permission-DhL6E-Nc.js +0 -63
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -1,70 +1,14 @@
|
|
|
1
1
|
# Third-Party Notices — @voltro/plugin-rbac
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package uses the open-source software listed below. Each is the
|
|
4
4
|
property of its respective copyright holders and is used under the terms of
|
|
5
5
|
its license. This file is provided for attribution; it grants no rights in
|
|
6
6
|
@voltro/plugin-rbac itself, which is proprietary (see LICENSE).
|
|
7
7
|
|
|
8
|
-
Generated from the resolved runtime dependency closure (
|
|
8
|
+
Generated from the resolved runtime dependency closure (4 packages).
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
|
-
## @effect/experimental@0.61.1
|
|
13
|
-
|
|
14
|
-
License: MIT
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
MIT License
|
|
18
|
-
|
|
19
|
-
Copyright (c) 2023-present The Contributors
|
|
20
|
-
|
|
21
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
23
|
-
in the Software without restriction, including without limitation the rights
|
|
24
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
26
|
-
furnished to do so, subject to the following conditions:
|
|
27
|
-
|
|
28
|
-
The above copyright notice and this permission notice shall be included in all
|
|
29
|
-
copies or substantial portions of the Software.
|
|
30
|
-
|
|
31
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
-
SOFTWARE.
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## @effect/sql@0.52.1
|
|
41
|
-
|
|
42
|
-
License: MIT
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
MIT License
|
|
46
|
-
|
|
47
|
-
Copyright (c) 2023-present The Contributors
|
|
48
|
-
|
|
49
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
50
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
51
|
-
in the Software without restriction, including without limitation the rights
|
|
52
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
53
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
54
|
-
furnished to do so, subject to the following conditions:
|
|
55
|
-
|
|
56
|
-
The above copyright notice and this permission notice shall be included in all
|
|
57
|
-
copies or substantial portions of the Software.
|
|
58
|
-
|
|
59
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
60
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
61
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
62
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
63
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
64
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
65
|
-
SOFTWARE.
|
|
66
|
-
```
|
|
67
|
-
|
|
68
12
|
## jose@6.2.12
|
|
69
13
|
|
|
70
14
|
License: MIT
|
|
@@ -93,34 +37,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
93
37
|
SOFTWARE.
|
|
94
38
|
```
|
|
95
39
|
|
|
96
|
-
## layerr@3.0.0
|
|
97
|
-
|
|
98
|
-
License: MIT
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
MIT License
|
|
102
|
-
|
|
103
|
-
Copyright (c) 2020 Perry Mitchell
|
|
104
|
-
|
|
105
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
106
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
107
|
-
in the Software without restriction, including without limitation the rights
|
|
108
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
109
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
110
|
-
furnished to do so, subject to the following conditions:
|
|
111
|
-
|
|
112
|
-
The above copyright notice and this permission notice shall be included in all
|
|
113
|
-
copies or substantial portions of the Software.
|
|
114
|
-
|
|
115
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
116
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
117
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
118
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
119
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
120
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
121
|
-
SOFTWARE.
|
|
122
|
-
```
|
|
123
|
-
|
|
124
40
|
## typeid-js@1.2.0
|
|
125
41
|
|
|
126
42
|
License: Apache-2.0
|
|
@@ -329,14 +245,14 @@ Apache License
|
|
|
329
245
|
limitations under the License.
|
|
330
246
|
```
|
|
331
247
|
|
|
332
|
-
##
|
|
248
|
+
## ulid@3.0.2
|
|
333
249
|
|
|
334
250
|
License: MIT
|
|
335
251
|
|
|
336
252
|
```
|
|
337
|
-
MIT License
|
|
253
|
+
The MIT License (MIT)
|
|
338
254
|
|
|
339
|
-
Copyright (c)
|
|
255
|
+
Copyright (c) 2017 Alizain Feerasta
|
|
340
256
|
|
|
341
257
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
342
258
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/index.js
CHANGED
|
@@ -1,109 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
permissions: T(),
|
|
12
|
-
isDefault: S().default(!1)
|
|
13
|
-
}).index("_voltro_rbac_roles_by_slug", ["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("_voltro_rbac_user_roles_by_user_tenant", ["userId", "tenantId"]).index("_voltro_rbac_user_roles_by_role_slug", ["roleSlug"]), F = P(), I = (e = {}) => [N, P(e)], L = (e, t) => e.query({
|
|
19
|
-
table: M,
|
|
20
|
-
predicate: t,
|
|
21
|
-
order: [{
|
|
22
|
-
column: "id",
|
|
23
|
-
direction: "asc"
|
|
24
|
-
}],
|
|
25
|
-
take: void 0,
|
|
26
|
-
skip: void 0,
|
|
27
|
-
projection: void 0
|
|
28
|
-
}), R = (e) => {
|
|
29
|
-
let t = (t, n, r) => L(e, x(C("userId", t), C("roleSlug", n), C("tenantId", r)));
|
|
30
|
-
return {
|
|
31
|
-
assign: async (n, r, i = null) => {
|
|
32
|
-
(await t(n, r, i)).length > 0 || await e.insert(M, {
|
|
33
|
-
userId: n,
|
|
34
|
-
roleSlug: r,
|
|
35
|
-
tenantId: i
|
|
36
|
-
});
|
|
37
|
-
},
|
|
38
|
-
revoke: async (n, r, i = null) => {
|
|
39
|
-
let a = await t(n, r, i);
|
|
40
|
-
for (let t of a) await e.delete(M, String(t.id));
|
|
41
|
-
},
|
|
42
|
-
rolesOf: async (t, n) => {
|
|
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
|
-
return [...new Set(r)];
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}, z = (e) => e === null ? C("tenantId", null) : E(C("tenantId", e), C("tenantId", null)), B = (e) => (t, n) => {
|
|
48
|
-
let r = ("tenantId" in t ? t.tenantId : void 0) ?? null, i = ("id" in t ? t.id : void 0) ?? null;
|
|
49
|
-
if (!i) return [];
|
|
50
|
-
let a = e ?? (n?.store === void 0 ? void 0 : R(n.store));
|
|
51
|
-
return a === void 0 ? [] : a.rolesOf(i, r);
|
|
52
|
-
}, V = b({ scope: "@voltro/plugin-rbac" }), H = (e) => p.suspend(() => {
|
|
1
|
+
import { WILDCARD_PERMISSION as e, compileRoles as t, declaredScopesOf as n, rolesFromMap as r } from "./roles.js";
|
|
2
|
+
import { mergeResolvedScopes as i, metadataRoleResolver as a, resolvedRoles as o, resolvedScopes as s, setResolvedScopes as c } from "./resolve.js";
|
|
3
|
+
import { anyPermission as l, assertPermission as u, can as d, permission as f } from "./permission.js";
|
|
4
|
+
import { ROLES_TABLE as p, USER_ROLES_TABLE as m, buildUserRolesTable as h, rbacTables as g, rolesTable as _, userRolesTable as v } from "./tables.js";
|
|
5
|
+
import { dataStoreRoleResolver as y, userRoleStore as b } from "./userRoleStore.js";
|
|
6
|
+
import { Effect as x } from "effect";
|
|
7
|
+
import { ADMIN_SCOPE as S, ScopeError as C, ScopeError as w, definePlugin as T, pluginInstanceName as E, setEffectiveScopesRefresher as D, setResourceScopeResolver as O } from "@voltro/protocol";
|
|
8
|
+
import { createLogger as k } from "@voltro/logger";
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
var A = k({ scope: "@voltro/plugin-rbac" }), j = (e) => x.suspend(() => {
|
|
53
11
|
let t = e();
|
|
54
|
-
return t instanceof Promise ?
|
|
55
|
-
}),
|
|
56
|
-
let
|
|
57
|
-
if (
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
let r = n
|
|
61
|
-
return r.includes(
|
|
62
|
-
}),
|
|
12
|
+
return t instanceof Promise ? x.promise(() => t) : x.succeed(t);
|
|
13
|
+
}), M = "@voltro/plugin-rbac", N = (e) => {
|
|
14
|
+
let r = e.resolveRoles ?? a, o = e.resolvePermissions, s = e.tables !== void 0 && e.tables !== !1, l = typeof e.tables == "object" ? e.tables : {};
|
|
15
|
+
if (e.resolveResourceRoles) {
|
|
16
|
+
let n = e.resolveResourceRoles;
|
|
17
|
+
O(({ subject: r, scope: i, resource: a }) => j(() => n(r, a)).pipe(x.map((n) => {
|
|
18
|
+
let r = t(n, e.roles);
|
|
19
|
+
return r.includes(S) || r.includes(i);
|
|
20
|
+
}), x.catchCause((e) => (A.warn("resolveResourceRoles failed; denying (fail-closed)", {
|
|
63
21
|
scope: i,
|
|
64
22
|
resource: a,
|
|
65
23
|
cause: String(e)
|
|
66
|
-
}),
|
|
24
|
+
}), x.succeed(!1)))));
|
|
67
25
|
}
|
|
68
|
-
let u, d = (n,
|
|
69
|
-
let s = yield*
|
|
70
|
-
tag:
|
|
71
|
-
traceId:
|
|
26
|
+
let u, d = (t, n, a) => x.gen(function* () {
|
|
27
|
+
let s = yield* j(() => r(t, { ...u === void 0 ? {} : { store: u } })).pipe(x.catchCause((e) => (A.warn("resolveRoles failed; falling back to raw subject scopes", {
|
|
28
|
+
tag: n,
|
|
29
|
+
traceId: a,
|
|
72
30
|
cause: String(e)
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
}), f =
|
|
31
|
+
}), x.succeed([])))), l = o ? yield* j(() => o(t)).pipe(x.catchCause(() => x.succeed([]))) : [], d = i(t, s, e.roles, l);
|
|
32
|
+
c(t, d, s);
|
|
33
|
+
}), f = (e, t) => x.gen(function* () {
|
|
34
|
+
return yield* d(t.subject, t.tag, t.traceId), D(t.subject, (e) => x.runPromise(d(e, t.tag, t.traceId))), yield* e;
|
|
35
|
+
}), p = [
|
|
76
36
|
"rpc:intercept:mutation",
|
|
77
37
|
"rpc:intercept:query",
|
|
78
38
|
"rpc:intercept:action",
|
|
79
39
|
"rpc:intercept:workflow",
|
|
80
|
-
...
|
|
81
|
-
],
|
|
82
|
-
return
|
|
83
|
-
name:
|
|
84
|
-
base:
|
|
85
|
-
alias:
|
|
40
|
+
...s ? ["store:write"] : []
|
|
41
|
+
], m = o === void 0 ? n(e.roles) : void 0;
|
|
42
|
+
return T({
|
|
43
|
+
name: E({
|
|
44
|
+
base: M,
|
|
45
|
+
alias: e.alias
|
|
86
46
|
}),
|
|
87
|
-
baseName:
|
|
88
|
-
...
|
|
47
|
+
baseName: M,
|
|
48
|
+
...m === void 0 ? {} : { declaredScopes: m },
|
|
89
49
|
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).",
|
|
90
|
-
permissions:
|
|
50
|
+
permissions: p,
|
|
91
51
|
bindDataStore: (e) => {
|
|
92
52
|
u = e;
|
|
93
53
|
},
|
|
94
|
-
interceptMutation:
|
|
95
|
-
interceptQuery:
|
|
96
|
-
interceptAction:
|
|
97
|
-
interceptWorkflow:
|
|
54
|
+
interceptMutation: f,
|
|
55
|
+
interceptQuery: f,
|
|
56
|
+
interceptAction: f,
|
|
57
|
+
interceptWorkflow: f,
|
|
98
58
|
errorSchemas: [{
|
|
99
|
-
schema:
|
|
59
|
+
schema: w,
|
|
100
60
|
import: {
|
|
101
61
|
module: "@voltro/protocol",
|
|
102
62
|
name: "ScopeError"
|
|
103
63
|
}
|
|
104
64
|
}],
|
|
105
|
-
...
|
|
65
|
+
...s ? { extendSchema: { tables: [...g(l)] } } : {}
|
|
106
66
|
});
|
|
107
67
|
};
|
|
108
68
|
//#endregion
|
|
109
|
-
export {
|
|
69
|
+
export { p as ROLES_TABLE, C as ScopeError, m as USER_ROLES_TABLE, e as WILDCARD_PERMISSION, l as anyPermission, u as assertPermission, h as buildUserRolesTable, d as can, t as compileRoles, y as dataStoreRoleResolver, i as mergeResolvedScopes, a as metadataRoleResolver, f as permission, N as rbacPlugin, g as rbacTables, o as resolvedRoles, s as resolvedScopes, r as rolesFromMap, _ as rolesTable, c as setResolvedScopes, b as userRoleStore, v as userRolesTable };
|
package/dist/permission.js
CHANGED
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { resolvedScopes as e } from "./resolve.js";
|
|
2
|
+
import { Effect as t } from "effect";
|
|
3
|
+
import { ADMIN_SCOPE as n, ScopeError as r } from "@voltro/protocol";
|
|
4
|
+
//#region src/permission.ts
|
|
5
|
+
var i = (t, r) => {
|
|
6
|
+
let i = e(t);
|
|
7
|
+
return i.includes(n) || i.includes(r);
|
|
8
|
+
}, a = (e) => typeof e == "string" ? [e] : e, o = (e, t) => {
|
|
9
|
+
for (let n of t) if (!i(e, n)) return n;
|
|
10
|
+
return null;
|
|
11
|
+
}, s = (e, n) => {
|
|
12
|
+
let i = a(n), s = o(e.request.subject, i);
|
|
13
|
+
return s === null ? t.void : t.fail(new r({
|
|
14
|
+
required: s,
|
|
15
|
+
message: `missing required permission '${s}'`
|
|
16
|
+
}));
|
|
17
|
+
}, c = (e, n) => {
|
|
18
|
+
let a = e.request.subject;
|
|
19
|
+
if (n.length === 0) return t.void;
|
|
20
|
+
for (let e of n) if (i(a, e)) return t.void;
|
|
21
|
+
return t.fail(new r({
|
|
22
|
+
required: n[0],
|
|
23
|
+
message: `missing all of required permissions [${n.join(", ")}]`
|
|
24
|
+
}));
|
|
25
|
+
}, l = (e, t) => {
|
|
26
|
+
let n = o(e.request.subject, a(t));
|
|
27
|
+
if (n !== null) throw new r({
|
|
28
|
+
required: n,
|
|
29
|
+
message: `missing required permission '${n}'`
|
|
30
|
+
});
|
|
31
|
+
}, u = (e, t) => o(e.request.subject, a(t)) === null;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { c as anyPermission, l as assertPermission, u as can, s as permission };
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { compileRoles as e } from "./roles.js";
|
|
2
|
+
import { currentSubjectAuthority as t, effectiveScopes as n, setEffectiveScopes as r, subjectScopes as i } from "@voltro/protocol";
|
|
3
|
+
//#region src/resolve.ts
|
|
4
|
+
var a = /* @__PURE__ */ new WeakMap(), o = (e, t, n) => {
|
|
5
|
+
r(e, t), n !== void 0 && a.set(e, n);
|
|
6
|
+
}, s = (e) => n(e), c = (e) => a.get(t(e)) ?? [], l = (e) => {
|
|
7
|
+
if (!("metadata" in e) || e.metadata === void 0) return [];
|
|
8
|
+
let t = e.metadata.roles;
|
|
9
|
+
return Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
|
|
10
|
+
}, u = (t, n, r, a = []) => {
|
|
11
|
+
let o = e(n, r), s = [], c = /* @__PURE__ */ new Set();
|
|
12
|
+
for (let e of [
|
|
13
|
+
...i(t),
|
|
14
|
+
...o,
|
|
15
|
+
...a
|
|
16
|
+
]) c.has(e) || (c.add(e), s.push(e));
|
|
17
|
+
return s;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { u as mergeResolvedScopes, l as metadataRoleResolver, c as resolvedRoles, s as resolvedScopes, o as setResolvedScopes };
|
package/dist/roles.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ADMIN_SCOPE as e } from "@voltro/protocol";
|
|
2
|
+
//#region src/roles.ts
|
|
3
|
+
var t = "*", n = (e) => {
|
|
4
|
+
let t = /* @__PURE__ */ new Set();
|
|
5
|
+
for (let n of Object.values(e)) for (let e of n) e !== "*" && t.add(e);
|
|
6
|
+
return [...t].sort();
|
|
7
|
+
}, r = (t, n) => {
|
|
8
|
+
let r = [], i = /* @__PURE__ */ new Set();
|
|
9
|
+
for (let a of t) {
|
|
10
|
+
let t = n[a];
|
|
11
|
+
if (t !== void 0) for (let n of t) {
|
|
12
|
+
if (n === "*") return [e];
|
|
13
|
+
i.has(n) || (i.add(n), r.push(n));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return r;
|
|
17
|
+
}, i = (e) => Object.entries(e).map(([e, t]) => ({
|
|
18
|
+
slug: e,
|
|
19
|
+
permissions: t
|
|
20
|
+
}));
|
|
21
|
+
//#endregion
|
|
22
|
+
export { t as WILDCARD_PERMISSION, r as compileRoles, n as declaredScopesOf, i as rolesFromMap };
|
package/dist/tables.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { boolean as e, id as t, json as n, reference as r, requireTenants as i, table as a, text as o } from "@voltro/database";
|
|
2
|
+
//#region src/tables.ts
|
|
3
|
+
var s = "_voltro_rbac_roles", c = "_voltro_rbac_user_roles", l = a(s, {
|
|
4
|
+
id: t({ prefix: "role" }),
|
|
5
|
+
slug: o().unique(),
|
|
6
|
+
name: o(),
|
|
7
|
+
permissions: n(),
|
|
8
|
+
isDefault: e().default(!1)
|
|
9
|
+
}).index("_voltro_rbac_roles_by_slug", ["slug"]), u = (e = {}) => a(c, {
|
|
10
|
+
id: t({ prefix: "urole" }),
|
|
11
|
+
userId: o(),
|
|
12
|
+
tenantId: e.multitenant ? r(i(), { index: !1 }).nullable() : o().nullable(),
|
|
13
|
+
roleSlug: o()
|
|
14
|
+
}).index("_voltro_rbac_user_roles_by_user_tenant", ["userId", "tenantId"]).index("_voltro_rbac_user_roles_by_role_slug", ["roleSlug"]), d = u(), f = (e = {}) => [l, u(e)];
|
|
15
|
+
//#endregion
|
|
16
|
+
export { s as ROLES_TABLE, c as USER_ROLES_TABLE, u as buildUserRolesTable, f as rbacTables, l as rolesTable, d as userRolesTable };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { USER_ROLES_TABLE as e } from "./tables.js";
|
|
2
|
+
import { and as t, eq as n, or as r } from "@voltro/database";
|
|
3
|
+
//#region src/userRoleStore.ts
|
|
4
|
+
var i = (t, n) => t.query({
|
|
5
|
+
table: e,
|
|
6
|
+
predicate: n,
|
|
7
|
+
order: [{
|
|
8
|
+
column: "id",
|
|
9
|
+
direction: "asc"
|
|
10
|
+
}],
|
|
11
|
+
take: void 0,
|
|
12
|
+
skip: void 0,
|
|
13
|
+
projection: void 0
|
|
14
|
+
}), a = (r) => {
|
|
15
|
+
let a = (e, a, o) => i(r, t(n("userId", e), n("roleSlug", a), n("tenantId", o)));
|
|
16
|
+
return {
|
|
17
|
+
assign: async (t, n, i = null) => {
|
|
18
|
+
(await a(t, n, i)).length > 0 || await r.insert(e, {
|
|
19
|
+
userId: t,
|
|
20
|
+
roleSlug: n,
|
|
21
|
+
tenantId: i
|
|
22
|
+
});
|
|
23
|
+
},
|
|
24
|
+
revoke: async (t, n, i = null) => {
|
|
25
|
+
let o = await a(t, n, i);
|
|
26
|
+
for (let t of o) await r.delete(e, String(t.id));
|
|
27
|
+
},
|
|
28
|
+
rolesOf: async (e, a) => {
|
|
29
|
+
let s = (a === void 0 ? await i(r, n("userId", e)) : await i(r, t(n("userId", e), o(a)))).map((e) => String(e.roleSlug));
|
|
30
|
+
return [...new Set(s)];
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}, o = (e) => e === null ? n("tenantId", null) : r(n("tenantId", e), n("tenantId", null)), s = (e) => (t, n) => {
|
|
34
|
+
let r = ("tenantId" in t ? t.tenantId : void 0) ?? null, i = ("id" in t ? t.id : void 0) ?? null;
|
|
35
|
+
if (!i) return [];
|
|
36
|
+
let o = e ?? (n?.store === void 0 ? void 0 : a(n.store));
|
|
37
|
+
return o === void 0 ? [] : o.rolesOf(i, r);
|
|
38
|
+
};
|
|
39
|
+
//#endregion
|
|
40
|
+
export { s as dataStoreRoleResolver, a as userRoleStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-rbac",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.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",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"node": ">=24.0.0"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@voltro/database": "0.
|
|
37
|
-
"@voltro/logger": "0.
|
|
38
|
-
"@voltro/protocol": "0.
|
|
36
|
+
"@voltro/database": "0.86.0",
|
|
37
|
+
"@voltro/logger": "0.86.0",
|
|
38
|
+
"@voltro/protocol": "0.86.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"effect": "
|
|
41
|
+
"effect": "4.0.1",
|
|
42
42
|
"react": "^19.0.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Effect as e } from "effect";
|
|
2
|
-
import { ADMIN_SCOPE as t, ScopeError as n, effectiveScopes as r, setEffectiveScopes as i, subjectScopes as a } from "@voltro/protocol";
|
|
3
|
-
//#region src/roles.ts
|
|
4
|
-
var o = "*", s = (e) => {
|
|
5
|
-
let t = /* @__PURE__ */ new Set();
|
|
6
|
-
for (let n of Object.values(e)) for (let e of n) e !== "*" && t.add(e);
|
|
7
|
-
return [...t].sort();
|
|
8
|
-
}, c = (e, n) => {
|
|
9
|
-
let r = [], i = /* @__PURE__ */ new Set();
|
|
10
|
-
for (let a of e) {
|
|
11
|
-
let e = n[a];
|
|
12
|
-
if (e !== void 0) for (let n of e) {
|
|
13
|
-
if (n === "*") return [t];
|
|
14
|
-
i.has(n) || (i.add(n), r.push(n));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return r;
|
|
18
|
-
}, l = (e) => Object.entries(e).map(([e, t]) => ({
|
|
19
|
-
slug: e,
|
|
20
|
-
permissions: t
|
|
21
|
-
})), u = /* @__PURE__ */ new WeakMap(), d = (e, t, n) => {
|
|
22
|
-
i(e, t), n !== void 0 && u.set(e, n);
|
|
23
|
-
}, f = (e) => r(e), p = (e) => u.get(e) ?? [], m = (e) => {
|
|
24
|
-
if (!("metadata" in e) || e.metadata === void 0) return [];
|
|
25
|
-
let t = e.metadata.roles;
|
|
26
|
-
return Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
|
|
27
|
-
}, h = (e, t, n, r = []) => {
|
|
28
|
-
let i = c(t, n), o = [], s = /* @__PURE__ */ new Set();
|
|
29
|
-
for (let t of [
|
|
30
|
-
...a(e),
|
|
31
|
-
...i,
|
|
32
|
-
...r
|
|
33
|
-
]) s.has(t) || (s.add(t), o.push(t));
|
|
34
|
-
return o;
|
|
35
|
-
}, g = (e, n) => {
|
|
36
|
-
let r = f(e);
|
|
37
|
-
return r.includes(t) || r.includes(n);
|
|
38
|
-
}, _ = (e) => typeof e == "string" ? [e] : e, v = (e, t) => {
|
|
39
|
-
for (let n of t) if (!g(e, n)) return n;
|
|
40
|
-
return null;
|
|
41
|
-
}, y = (t, r) => {
|
|
42
|
-
let i = _(r), a = v(t.request.subject, i);
|
|
43
|
-
return a === null ? e.void : e.fail(new n({
|
|
44
|
-
required: a,
|
|
45
|
-
message: `missing required permission '${a}'`
|
|
46
|
-
}));
|
|
47
|
-
}, b = (t, r) => {
|
|
48
|
-
let i = t.request.subject;
|
|
49
|
-
if (r.length === 0) return e.void;
|
|
50
|
-
for (let t of r) if (g(i, t)) return e.void;
|
|
51
|
-
return e.fail(new n({
|
|
52
|
-
required: r[0],
|
|
53
|
-
message: `missing all of required permissions [${r.join(", ")}]`
|
|
54
|
-
}));
|
|
55
|
-
}, x = (e, t) => {
|
|
56
|
-
let r = v(e.request.subject, _(t));
|
|
57
|
-
if (r !== null) throw new n({
|
|
58
|
-
required: r,
|
|
59
|
-
message: `missing required permission '${r}'`
|
|
60
|
-
});
|
|
61
|
-
}, S = (e, t) => v(e.request.subject, _(t)) === null;
|
|
62
|
-
//#endregion
|
|
63
|
-
export { h as a, f as c, c as d, s as f, y as i, d as l, x as n, m as o, l as p, S as r, p as s, b as t, o as u };
|