@aooth/arbac-core 0.1.85 → 0.2.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/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
- if (rule.scope) {
145
- if (!haveAttrs) {
146
- attrs = await getAttrs();
147
- haveAttrs = true;
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
- scope?: (userAttrs: TUserAttrs, userId: string) => TScope;
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
- scope?: (userAttrs: TUserAttrs, userId: string) => TScope;
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
- if (rule.scope) {
144
- if (!haveAttrs) {
145
- attrs = await getAttrs();
146
- haveAttrs = true;
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aooth/arbac-core",
3
- "version": "0.1.85",
3
+ "version": "0.2.1",
4
4
  "description": "Advanced Role-Based Access Control (ARBAC) engine",
5
5
  "keywords": [
6
6
  "access-control",