@a38/core
Core of the A38 hierarchical RBAC library
Installation
npm install @a38/core
yarn add @a38/core
pnpm add @a38/core
Usage
import { HRBAC, PermissionManager, ResourceManager, RoleManager } from '@a38/core';
const roleManager = new RoleManager();
roleManager.setParents('guest', []);
roleManager.setParents('user', ['guest']);
roleManager.setParents('admin', ['user']);
const resourceManager = new ResourceManager();
resourceManager.setParents('dashboard', []);
resourceManager.setParents('login', []);
resourceManager.setParents('profile', []);
resourceManager.setParents('admin', []);
const permissionManager = new PermissionManager();
permissionManager.allow('guest', 'dashboard');
permissionManager.allow('guest', 'login');
permissionManager.allow('user', 'profile');
permissionManager.deny('user', 'login');
permissionManager.allow('admin');
permissionManager.deny('admin', 'login');
const hrbac = new HRBAC(roleManager, resourceManager, permissionManager);
hrbac.isAllowed('guest', 'dashboard');
hrbac.isAllowed('guest', 'login');
hrbac.isAllowed('guest', 'profile');
hrbac.isAllowed('guest', 'admin');
hrbac.isAllowed('user', 'login');
hrbac.isAllowed('user', 'profile');
hrbac.isAllowed('admin', 'login');
hrbac.isAllowed('admin', 'profile');
hrbac.isAllowed('admin', 'admin');
Docs
See the documentation
License
@a38/core is licensed under the MIT License, See the LICENSE file for more details
The project development and maintenance is sponsored by Neoskop.