Comparing version
@@ -27,6 +27,12 @@ "use strict"; | ||
} | ||
if (!Conditions[condition.Fn]) { | ||
throw new core_1.AccessControlError("Condtion function:" + condition.Fn + " not found"); | ||
if (typeof condition === 'function') { | ||
return condition(context); | ||
} | ||
return Conditions[condition.Fn].evaluate(condition.args, context); | ||
if (typeof condition === 'object') { | ||
if (!Conditions[condition.Fn]) { | ||
throw new core_1.AccessControlError("Condtion function:" + condition.Fn + " not found"); | ||
} | ||
return Conditions[condition.Fn].evaluate(condition.args, context); | ||
} | ||
return false; | ||
}; |
@@ -95,3 +95,3 @@ import { IAccessInfo } from '../core'; | ||
* Sets condition for this `Access` instance. | ||
* @param {Array<ICondition>|Array<Array<ICondition>>} value | ||
* @param {ICondition} value | ||
* Conditions to be set. | ||
@@ -98,0 +98,0 @@ * @returns {Access} |
@@ -120,3 +120,3 @@ "use strict"; | ||
* Sets condition for this `Access` instance. | ||
* @param {Array<ICondition>|Array<Array<ICondition>>} value | ||
* @param {ICondition} value | ||
* Conditions to be set. | ||
@@ -123,0 +123,0 @@ * @returns {Access} |
@@ -8,6 +8,9 @@ import { IDictionary } from './IDictionary'; | ||
*/ | ||
interface ICondition { | ||
export interface IStandardCondition { | ||
Fn: string; | ||
args: string | string[] | IDictionary<any> | ICondition | ICondition[]; | ||
args: string | string[] | IDictionary<any> | IStandardCondition | IStandardCondition[]; | ||
} | ||
export { ICondition }; | ||
export interface IFunctionCondition { | ||
(context: any): boolean; | ||
} | ||
export declare type ICondition = IStandardCondition | IFunctionCondition; |
{ | ||
"name": "role-acl", | ||
"version": "3.0.8", | ||
"version": "3.2.0", | ||
"description": "Role, Attribute and Condition based Access Control for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -60,3 +60,2 @@ Role, Attribute and conditions based Access Control for Node.js | ||
Define roles and grants one by one. | ||
```js | ||
@@ -79,3 +78,13 @@ const ac = new AccessControl(); | ||
console.log(permission.attributes); // —> [] | ||
// Using custom/own condition functions | ||
ac.grant('user').condition( | ||
(context) => { | ||
return context.category !== 'politics' | ||
} | ||
).execute('create').on('article'); | ||
permission = ac.can('user').context({ category: 'sports' }).execute('create').on('article'); | ||
console.log(permission.granted); // —> true | ||
``` | ||
### Wildcard (glob notation) Resource and Actions Examples | ||
@@ -82,0 +91,0 @@ ```js |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
118151
0.45%2725
0.33%401
2.3%0
-100%