@aooth/arbac-core 0.1.85 → 0.2.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/dist/index.cjs +11 -8
- package/dist/index.d.cts +6 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.mjs +11 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -139,15 +139,18 @@ var Arbac = class {
|
|
|
139
139
|
let allowed = false;
|
|
140
140
|
let attrs;
|
|
141
141
|
let haveAttrs = false;
|
|
142
|
-
for (const match of matches) for (const rule of match.allow) {
|
|
142
|
+
for (const match of matches) for (const rule of match.allow) if (rule.scope) {
|
|
143
|
+
if (!haveAttrs) {
|
|
144
|
+
attrs = await getAttrs();
|
|
145
|
+
haveAttrs = true;
|
|
146
|
+
}
|
|
147
|
+
const scope = rule.scope(attrs, String(id));
|
|
148
|
+
if (scope == null) continue;
|
|
143
149
|
allowed = true;
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
scopes.push(rule.scope(attrs, String(id)));
|
|
150
|
-
} else scopes.push({});
|
|
150
|
+
scopes.push(scope);
|
|
151
|
+
} else {
|
|
152
|
+
allowed = true;
|
|
153
|
+
scopes.push({});
|
|
151
154
|
}
|
|
152
155
|
return allowed ? {
|
|
153
156
|
allowed,
|
package/dist/index.d.cts
CHANGED
|
@@ -30,7 +30,12 @@ interface TArbacRoleForResource<TUserAttrs, TScope> {
|
|
|
30
30
|
type TArbacRule<TUserAttrs, TScope> = {
|
|
31
31
|
resource: string;
|
|
32
32
|
action: string;
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Scope of this grant. `null` / `undefined` = this rule grants nothing
|
|
35
|
+
* for the user (as if it did not match): with no other rule allowing,
|
|
36
|
+
* the evaluation is denied.
|
|
37
|
+
*/
|
|
38
|
+
scope?: (userAttrs: TUserAttrs, userId: string) => TScope | null | undefined;
|
|
34
39
|
effect?: never;
|
|
35
40
|
} | {
|
|
36
41
|
resource: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -30,7 +30,12 @@ interface TArbacRoleForResource<TUserAttrs, TScope> {
|
|
|
30
30
|
type TArbacRule<TUserAttrs, TScope> = {
|
|
31
31
|
resource: string;
|
|
32
32
|
action: string;
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Scope of this grant. `null` / `undefined` = this rule grants nothing
|
|
35
|
+
* for the user (as if it did not match): with no other rule allowing,
|
|
36
|
+
* the evaluation is denied.
|
|
37
|
+
*/
|
|
38
|
+
scope?: (userAttrs: TUserAttrs, userId: string) => TScope | null | undefined;
|
|
34
39
|
effect?: never;
|
|
35
40
|
} | {
|
|
36
41
|
resource: string;
|
package/dist/index.mjs
CHANGED
|
@@ -138,15 +138,18 @@ var Arbac = class {
|
|
|
138
138
|
let allowed = false;
|
|
139
139
|
let attrs;
|
|
140
140
|
let haveAttrs = false;
|
|
141
|
-
for (const match of matches) for (const rule of match.allow) {
|
|
141
|
+
for (const match of matches) for (const rule of match.allow) if (rule.scope) {
|
|
142
|
+
if (!haveAttrs) {
|
|
143
|
+
attrs = await getAttrs();
|
|
144
|
+
haveAttrs = true;
|
|
145
|
+
}
|
|
146
|
+
const scope = rule.scope(attrs, String(id));
|
|
147
|
+
if (scope == null) continue;
|
|
142
148
|
allowed = true;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
scopes.push(rule.scope(attrs, String(id)));
|
|
149
|
-
} else scopes.push({});
|
|
149
|
+
scopes.push(scope);
|
|
150
|
+
} else {
|
|
151
|
+
allowed = true;
|
|
152
|
+
scopes.push({});
|
|
150
153
|
}
|
|
151
154
|
return allowed ? {
|
|
152
155
|
allowed,
|