An Access Control library for multi-tenant systems
Installation
yarn add @endemolshinegroup/acl
Usage
import AccessControl from '@endemolshinegroup/acl';
const roles = {
User: {
GetUsers: {
dev: true,
staging: false,
prod: false,
}
}
}
// Create an instance of AccessControl
const ac = new AccessControl(rolesObj);
// you can also do the following at any time
ac.setRoles(rolesObj);
// Checking permissions
ac.does(`${role}`).havePermission(`${permission}`).for(`${stage}`); // true
// Granting a permission
ac.grant(`${role}`).permission(`${permission}`).for(`${stage[]}`);
// Denying a permission
ac.deny(`${role}`).permission(`${permission}`).for(`${stage[]}`);
// Extending permission
ac.allow(`${role}`).toExtend(`${role2}`);
// Removing role
ac.remove(`${role}`);
// Retrieving roles
ac.getRoles();
// Retrieving a list of role names
ac.getRolesList();
// Retrieving permissions for role
ac.getPermissions(role: string);