Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@a38/nestjs

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@a38/nestjs

[NestJS](https://nestjs.com/) bindings for the [@a38/core](https://www.npmjs.com/package/@a38/core) hierarchical RBAC library.

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
0
Weekly downloads
 
Created
Source

@a38/core

NestJS bindings for the @a38/core hierarchical RBAC library.

Installation

npm install @a38/nestjs # for NPM
yarn add @a38/nestjs    # for Yarn
pnpm add @a38/nestjs    # for PNPM

Usage

import { HRBAC, PermissionManager, ResourceManager, RoleManager } from '@a38/core';

const roleManager = new RoleManager();
roleManager.setParents('guest', []); // optional
roleManager.setParents('user', ['guest']); // role 'user' extends role 'guest'
roleManager.setParents('admin', ['user']); // role 'admin' extends role 'user'

const resourceManager = new ResourceManager();
resourceManager.setParents('dashboard', []); // optional
resourceManager.setParents('login', []); // optional
resourceManager.setParents('profile', []); // optional
resourceManager.setParents('admin', []); // optional

const permissionManager = new PermissionManager();
permissionManager.allow('guest', 'dashboard'); // allow 'guest' access to 'dashboard'
permissionManager.allow('guest', 'login'); // allow 'guest' access to 'dashboard'

permissionManager.allow('user', 'profile'); // allow 'user' access to 'profile'
permissionManager.deny('user', 'login'); // deny 'user' access to login

permissionManager.allow('admin'); // allow 'admin' access to everything
permissionManager.deny('admin', 'login'); // deny 'admin' access to login

const hrbac = new HRBAC(roleManager, resourceManager, permissionManager);

hrbac.isAllowed('guest', 'dashboard'); // -> true
hrbac.isAllowed('guest', 'login'); // -> true
hrbac.isAllowed('guest', 'profile'); // -> false
hrbac.isAllowed('guest', 'admin'); // -> false

hrbac.isAllowed('user', 'login'); // -> false
hrbac.isAllowed('user', 'profile'); // -> true

hrbac.isAllowed('admin', 'login'); // -> false
hrbac.isAllowed('admin', 'profile'); // -> true
hrbac.isAllowed('admin', 'admin'); // -> true

Docs

See the documentation

License

@a38/core is licensed under the MIT License, See the LICENSE file for more details

Sponsoring

The project development and maintenance is sponsored by Neoskop.

FAQs

Package last updated on 12 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc