@cobuildlab/rbac
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -40,2 +40,3 @@ import { ValidatorFunctionType } from './types'; | ||
check(role: R | null, permission: P, data?: D[P]): [boolean, string?]; | ||
simpleCheck(role: R | null, permission: P, data?: D[P]): boolean; | ||
} |
@@ -101,4 +101,7 @@ "use strict"; | ||
}; | ||
RBAC.prototype.simpleCheck = function (role, permission, data) { | ||
return this.check(role, permission, data)[0]; | ||
}; | ||
return RBAC; | ||
}()); | ||
exports.RBAC = RBAC; |
{ | ||
"name": "@cobuildlab/rbac", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -95,1 +95,27 @@ import { test, expect } from '@jest/globals'; | ||
}); | ||
test('Test simple Check', () => { | ||
enum Roles { | ||
ADMIN = 'ADMIN', | ||
MANAGER = 'MANAGER', | ||
} | ||
enum Permissions { | ||
DASHBOARD = 'DASHBOARD', | ||
SETTINGS = 'SETTINGS', | ||
} | ||
const staticRules = new RBAC<Roles, Permissions>(Roles.ADMIN); | ||
staticRules.createRule(Roles.ADMIN, Permissions.DASHBOARD, true); | ||
staticRules.createRule(Roles.ADMIN, Permissions.SETTINGS, true); | ||
staticRules.createRule(Roles.MANAGER, Permissions.DASHBOARD, false); | ||
expect( | ||
staticRules.simpleCheck(Roles.ADMIN, Permissions.DASHBOARD), | ||
).toStrictEqual(true); | ||
expect( | ||
staticRules.simpleCheck(Roles.ADMIN, Permissions.SETTINGS), | ||
).toStrictEqual(true); | ||
expect( | ||
staticRules.simpleCheck(Roles.MANAGER, Permissions.DASHBOARD), | ||
).toStrictEqual(false); | ||
}); |
@@ -120,2 +120,6 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
} | ||
simpleCheck(role: R | null, permission: P, data?: D[P]): boolean { | ||
return this.check(role, permission, data)[0]; | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28323
506