1.0.4 • Published 9 months ago

complete-rbac v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

RBAC (Role-Based Access Control)

RBAC is a super lightweight npm package written in typescript that provides Role-Based Access Control functionality. It allows you to define roles and permissions, and check whether a role has permission for a specific action.

Installation

You can install the RBAC package using npm:

npm install complete-rbac

Usage

// Import the RBAC module
import RBAC from 'complete-rbac'

// Define your RBAC rules
const rbac_rules = {
  user: {
    can: ['blog:read'],
  },
  admin: {
    can: ['blog:read', 'blog:create', 'blog:update', 'comments:*', 'users:*'],
  },
  superadmin: {
    can: ['*'],
    inherits: ['admin'],
  },
};

// Create an instance of RBAC
const rbac = new RBAC(rbac_rules);

// Check permissions
console.log(rbac.can('user', 'blog:read')); // Output: true
console.log(rbac.can('admin', 'blog:delete')); // Output: false
console.log(rbac.can('user', ["blog:read", "blog:delete"])); // Output: true
1.0.2

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.1

11 months ago

1.0.0

11 months ago