npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

acl-checker

v0.1.0

Published

ACL checker library

Downloads

4

Readme

ACL Checker

This is a NodeJS module that allows you to setup roles/resources/permissions and then allows you to check to see if a role has a particular permission for a resource.

Installation

You can install this using npm:

npm install acl-checker

Quick Guide

First thing you need to do is create a instance of the ACL class:

var AclChecker = require('acl-checker');
var acl = new AclChecker();

Setup Allowable Permissions

Next you have to load roles/resources/permissions. You can do this a few different way, all which use the allow() method.

Strings

You can use simple strings where you pass the role, resource, and then permissions:

acl.allow('guest', 'post', 'read');

This will give the guest roles the read permission on the post resources.

Arrays

Same parameters as strings but using arrays. It will give all the permissions to all the resources, for all the roles, for example:

acl.allow([
  'blogger',
  'admin'
], [
  'post',
  'comment'
], [
  'create',
  'read'
]);

This will give the blogger and admin roles the create and read permissions for both the post and comment resources.

You can also mix and match strings and arrays:

acl.allow([
  'blogger',
  'admin'
], 'post', [
  'create',
  'read'
]);

Object

You can also use an object with allow(). The object would be structure like:

roleName:
  resourceName:
    [permissions]

Defining however many you want, for example:

var permissions = {
  guest: {
    post: [
      'read'
    ],
    comment: [
      'create',
      'read'
    ]
  },
  blogger: {
    post: [
      'create',
      'read',
      'update',
      'delete'
    ],
    comment: [
      'create',
      'read',
      'approve'
    ]
  },
  admin: {
    post: [
      'create',
      'read',
      'update',
      'delete'
    ],
    comment: [
      'create',
      'read',
      'update',
      'delete',
      'approve'
    ]
  }
};

acl.allow(permissions);

Where Does The Data Come From?

This library is designed very specifically to handle the task of validating permissions on roles and resources, it does nothing with get or retrieving that data.

It is up to your application to prodive the data where it uses low level libraries like node-mysql or node_redis or using an Object Mapper like Simple ORM, Bookshelf, or Mongoose or a combination. You have full control in how the ACL data is retrieve and stored.

Removing Permissions

To remove permission, use the removeAllow() method which has the same structure as the allow() method.

acl.removeAllow('guest', 'post', 'read');

acl.removeAllow('guest', [
  'post',
  'comment'
], 'read');

acl.removeAllow({
  guest: {
    post: [
      'read'
    ]
  }
});

Checking Permission

To check if a permission is valid, use the either isAllowed() or allIsAllowed() method which has the same structure as the allow() method.

isAllowed() requires just one of the permission to be valid while isAllAllowed() requires all permissions to be valid.

acl.isAllowed('guest', 'post', 'read');

acl.isAllowed('guest', [
  'post',
  'comment'
], 'read');

acl.allIsAllowed({
  guest: {
    post: [
      'read'
    ]
  }
});

LICENSE

MIT