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

grants

v1.5.2

Published

[![Greenkeeper badge](https://badges.greenkeeper.io/davidyaha/grants.svg)](https://greenkeeper.io/)

Downloads

29

Readme

Grants

Greenkeeper badge

CircleCI codecov

Grants is a metadata store for permissions business logic.

It allows you to have the flexibility to grant or deny users of access to any kind of resource. While access, can be whatever attribute you'd like.

Grants utilizes sets as it's main data structure. Core assumption: For any given resource set, there is a set of members that is granted a set of access attributes.

Any permissions that was not given to a member is not permitted.

This package is meant to be a flexible and consice, set of rules, that on top of it, any permissioning model can be implemented.

Permissions are stored in memory so persisting and syncing the permissions metadata is entierly up to the implementor. This approach allows the implementor to create far more complex permissioning systems then the regular role based system.

For example, you can give permission to user that will expire after a certain time.

Usage (Most Basic Permissioning Model)

Granting first permission

  grants.grant(privilegedUser._id, ['users', privilegedUser._id], ['read', 'update', 'delete']);

Granting to multiple members

  const humanUsers = [privilegedUser._id, nonPrivilegedUser._id];
  grants.grant(humanUsers, 'posts', ['read', 'create']);

Granting permissions to roles

A role is just a tagged set of members in a grant:

  const role = grants.role('human', humanUsers);
  grants.grant(role, 'posts', ['read', 'create']);

Checking weather a user is permitted to do something

  const permitted = grants.get(['users', privilegedUser._id], 'read');
  permitted(privilegedUser._id) // true
  permitted(nonPrivilegedUser._id) // false

Creatign super/admin users

grants.ALL is a universal set. meaning that providing it as resource or attribute on a grant will give the members of this grant access to all resources and/or all attributes (full access). This is usefull for creating admin/super users.

  const superUser = {_id: 'clark kent'};
  const role = grants.role('admin', superUser._id);
  grants.grant(role, grants.ALL, grants.ALL);
  
  const permitted = grants.get(['users', privilegedUser._id], 'read');
  permitted(superUser._id) // true

API

grant

grants.grant(members, resources, attributes): Grant - Call grant to add a new grant into the grant store.

It accepts members set, resources set, and attributes set.

Each of these fields can be an imuutable.js Set object, an Array, or a single any type

Returns the Grant record that was added.

get

get(resources, attributes?) - Call get to get a predicate function that allows you to check for a member if it is permitted to access certain resources with certain attributes.

It accepts resources set, and optionaly attributes set.

Returns a predicate function that accepts a member value and returns either true or false.

getMany

getMany(resorceList, attributes?) - Call getMany to get a predicate function that allows you to check for a member if it is permitted to access all resources included in the list with certain attributes.

It accepts a list of resources set, and optionaly attributes set.

Returns a predicate function that accepts a member value and returns either true or false.

deny

role

setRole

resource

member