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

universal-acl

v1.3.1

Published

an access control module for all web apps

Downloads

4

Readme

universal-acl

an access control module for all web apps

Initialization

pass db instance. currenly it supports only mongodb

UniversalACL = new UniversalACL(UniversalACL.mongoAdapter(db));

Methods

updateMapData(mapData)

update map data. here in mapData object you have provide name for actions.

Arguments

mapData   {object}

mapping.json

{
    "mappings": {
        "ExtendedUser:findById": "/api/ExtendedUsers/:id",
        "ExtendedUser:list": "/api/ExtendedUsers/:id",
        "ExtendedUser:login": "/api/ExtendedUsers/login",
        "ExtendedUser:create": "/api/ExtendedUsers"
    }
}

you can say inside mappings object, keys are synonyms for actions.

updateRules (rules)

add / update set of rules. Below see the example of rules object

Arguments

rules   {object}

rules.json

{
    "guest": {
        "effect": "allow",
        "resources": [{
                "action": "/api/ExtendedUsers/login",
                "permissions": ["POST"]
            },
            {
                "name": "ExtendedUser:create",
                "permissions": ["POST"]
            }
        ],
        "privileges": [{
            "action": "/api/ExtendedUsers/:id",
            "options": {
                "DELETE_BUTTON": false,
                "EDIT_BUTTON": false
            }
        }]
    },
    "admin": {
        "effect": "deny",
        "resources": [{
            "action": "/api/ExtendedUsers",
            "permissions": ["GET"]
        }]
    }
}

Arguments

effect      {String}    [allow/deny] if allowed then user can access listed resources.
                        if denied then user can not access listed resources.
resources   {Array}
name        {String}    action name. but to use name you have to update map data.
action      {String}    url paths. not necessary if name is provided.
                        examples: 
                        /api/Products/:id+ (one or more parameter matches)
                        /api/Products/:id* (zero or more parameter matches)
                        /api/Products/(.*)* (includes products & its childs)
                        /api/Products/(.*) (excludes products but includes its childs)
permission  {Array}     url methods and use * to allow or deny all methods.
privileges  {Array}     list of privileges for listed resources.  
options     {Object}    resource attributes.

addRoles (userId, roles)

add new roles to a user

Arguments

userId  {String}
roles   {Array}

removeRoles (userId, roles)

remove roles from a user

Arguments

userId  {String}
roles   {Array}

modifyRoles (userId, roles)

replace existing roles and add new roles to user

Arguments

userId  {String}
roles   {Array}

isAllowed (req, userId, callback)

check if user is allowed to access a resource. Check the callback to get true false result. in the middleware check isAllowed. if isAllowed false send an error response

Arguments

req      {Object}   {method: "GET", url: "/api/foo"}
userId   {String}
callback {Function}

Example

UniversalACL.isAllowed(req, userId, function(err, isAllowed) {
    if (isAllowed) {
        next();
    } else {
        var error = new Error();
        error.status = 401;
        error.message = 'You need to be authenticated to access this endpoint';
        next(error);
    }
})

getRoles (roleNames, callback)

get role definitions.

Arguments

roleNames   {String}    example: ["member", "admin"]
callback    {Function}

Example

router.get('/api/universalACL/roles', function(req, res, next) {
    var roleNames = JSON.parse(req.query.roleNames);
    UniversalACL.getRoles( roleNames, function(err, roles){
        if(err){
            next(err);
        }
        else{
            res.send(roles);
        }
    })
});

addRoleToRules(filePath)

add a role to existing rules using a json file

Arguments

filePath    {String}    example: path.resolve(__dirname, '../lib/acl/acl-roles/superadmin.json')

superadmin.json

{
    "superadmin": {
        "effect": "deny",
        "resources": []
    }
}