JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 516
  • Score
    100M100P100Q90459F
  • License MIT

A Simple role based access control implementation for node

Package Exports

  • admittance

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (admittance) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status Coverage Status

Admittance (Version 2)

This is a rewrite of the original incomplete V1 version of admittance. I decided that V1 was trying to do too much and that V2 should be as simple as possible, both in API and in what it actually does under the hood.

Admittance now reads permissions from plain old javascript objects. This, I think helps to keep the module doing just one thing. To load data you just need create javascript objects and store them somewhere. You could simply require a json file and load it. This also makes it very easy to work with a nosql db. Just get and set your permissions to the db.

Basic usage

var admittance = require('admittance')

admittance.load({1: ['admin', 'subscriber'], 2: 'subscriber'})

admittance(1).is('admin') //true!

admittance(1).is('subscriber') //true!

admittance(2).is('subscriber') //true!

admittance(2).is('admin') //false!

Permission hierarchy usage

var permissions = {
  'admin': ['subscriber', 'editor'], //any userid assigned admin will also pass a subscriber or editor check
  'editor': 'blogger', //any userid assigned editor will also pass a blogger check
  1: 'admin'
}
admittance(1).is('admin') //true

admittance(1).is('subscriber') //true

admittance(1).is('editor') //true

admittance(1).is('blogger') //true

Permissions format

Admittance expects a simple map from userids to permissions. Permissions are strings or array of strings. The strings are simply permission names that make sense for your application context.

example:

var permissions = {
  1: 'admin',
  2: ['admin', 'subscriber', 'editor'],
  3: 'editor'
}

You can define nested hierarchies as well

var permissions = {
  'admin': ['subscriber', 'editor'], //any userid assigned admin will also pass a subscriber or editor check
  'editor': 'blogger', //any userid assigned editor will also pass a blogger check
  1: 'admin'
}

Tests

npm test