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

fellowship

v1.0.0

Published

An unopinionated bitwise memory based ACL

Downloads

22

Readme

Fellowship

build status Coverage Status

An unopinionated bitwise memory based ACL. To be used as a low level base for implementing a persistant module.

Installation

npm install fellowship --save

Usage

var Fellowship = require('fellowship')
  , resources = { resourceOne: { permission1: 1, permission2: 2, permission3: 4 }  }
  , groups = { Admin: { resourceOne: 6 }}
  , acl = new Fellowship(resources, groups)

acl.hasPermission('Admin', 'resourceOne', 'permission1') // false
acl.hasPermission('Admin', 'resourceOne', 'permission2') // true
acl.hasPermission('Admin', 'resourceOne', 'permission3') // true

// Moderator
acl.addResource('Blog', [ 'create,', 'read', 'update', 'delete' ])
acl.addGroup('Moderator')
acl.addPermission('Moderator', 'Blog', 'create')
acl.hasPermission('Moderator', 'Blog', 'create') // true

// Root
acl.addGroup('Root')
acl.addPermission('Root', 'Blog', '*')
acl.hasPermission('Root', 'Blog', 'read') // true

Methods

addGroup (name, [resourcePermissions])

  • name - The identifier to the group, either a name or a data based id
  • resourcePermissions - An optional object of permissions, e.g. { permission1: 1, permission2: 2, permission3: 4 }

addResource (name, permissions)

  • name - The identifier to the resource, either a name or a data based id
  • permissions - An array of permissions, e.g. [ 'create,', 'read', 'update', 'delete' ]

addPermission (groupName, resourceName, permissionName)

  • groupName - The identifier to the group, either a name or a data based id
  • resourceName - The identifier to the resource, either a name or a data based id
  • permissionName - Self explanatory, will throw an error if resource does not have such a permission

addPermission (groupName, resourceName, permissionNames)

  • groupName - The identifier to the group, either a name or a data based id
  • resourceName - The identifier to the resource, either a name or a data based id
  • permissionNames - Self explanatory, array of permission names, will throw an error if resource does not have such a permission

Internally uses addPermission

deleteGroup (groupName)

  • groupName - The identifier to the group, either a name or a data based id

deletePermission (resourceName, permissionName)

  • resourceName - The identifier to the resource, either a name or a data based id
  • permissionName - Self explanatory, will throw an error if resource does not have such a permission

Recalculates permission values and group resource values

deleteResource (resourceName)

  • resourceName - The identifier to the resource, either a name or a data based id

Also removes the resource from all groups, use removeResource to only remove it from a particular group

getGroup (name)

  • groupName - The identifier to the group, either a name or a data based id

Returns the groups resource permissions

getResource (name)

  • name - The identifier to the resource, either a name or a data based id

Returns the resources permissions and their associated 'bit' value

hasPermission (groupName, resourceName, permissionName)

  • groupName - The identifier to the group, either a name or a data based id
  • resourceName - The identifier to the resource, either a name or a data based id
  • permissionName - Self explanatory, will throw an error if resource does not have such a permission

Returns true if group has permission, false if not

newPermission (resourceName, permissionName)

  • resourceName - The identifier to the resource, either a name or a data based id
  • permissionName - Self explanatory, will throw an error if resource does not have such a permission

Adds a new permission to the resource, maximum of 31 permissions per resource

removePermission (groupName, resourceName, permissionName)

  • groupName - The identifier to the group, either a name or a data based id
  • resourceName - The identifier to the resource, either a name or a data based id
  • permissionName - Self explanatory, will throw an error if resource does not have such a permission

Removes the permission from the group, and recalculates resource value for group

removeResource (groupName, resourceName)

  • groupName - The identifier to the group, either a name or a data based id
  • resourceName - The identifier to the resource, either a name or a data based id

Removes the resource from the group

Events

Every method apart from getters emit an event

fellowship.on('permission.removed', function (groupName, resourceName, permissionName) {
  console.log(groupName, resourceName, permissionName)
})
  • group.added (name, resourcePermissions)

  • permission.added (groupName, resourceName, permissionName)

  • permissions.added (groupName, resourceName, permissions)

  • resource.added (name, permissions)

  • group.deleted (name)

  • permission.deleted (resourceName, permissionName)

  • resource.deleted (resourceName)

  • permission.new (resourceName, permissionName)

  • permission.removed (groupName, resourceName, permission)

  • resource.removed (groupName, resourceName)

FAQ

Why is there a limit on the amount of permissions per resource?

This is due to 32bit operations within JavaScript. If you find yourself needing a resource with more than 31 permissions, you should look into refactoring.

Bad

fellowship.addResource('Forum', [ 'createtopic', 'createpost', 'locktopic' ])

Good

fellowship.addResource('Topic', [ 'create', 'lock' ])
fellowship.addResource('Post', [ 'create', 'edit', 'delete' ])