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

role-guard

v1.3.0

Published

A role based access control package

Downloads

20

Readme

role-guard

Data Model

Decription

  1. a role based access control system for security of resources
  2. scalable as static lists are not used for creation of roles
  3. provides a huge scope for granular permissions
  4. logs unauthorized user activity which is accessible for 3 months

Usage

To install write the following command in the terminal
npm i role-guard It is recommended to wrap the all the function in a try-catch block The following example shows how to use any function of the package

    import * as roleg from "role-guard"
    try
    {
           console.log(await roleg.function_name(accesskey,parameters));
    }
    catch(error)
    {
      console.log(error.message);
    }

To use this package , first create an access key which will uniquely identifies your resources

    import * as roleg from "role-guard"
    try
    {
           const accessKey = await createKey();
    }
    catch(error)
    {
      console.log(error.message);
    }

Once key is created , you can do the following

Note: All kinds of id like user_id, role_id etc must be provided as string

1. users

1.1.create user

   console.log(await roleg.createUser(accessKey,user_id));

1.2 get user

     console.log(await roleg.getUser(accessKey,user_id));

1.3 suspend user

     console.log(await roleg.suspendUser(accessKey,user_id));

1.4 unsuspend user

     console.log(await roleg.unsuspendUser(accessKey,user_id));

1.5 delete user

 console.log(await roleg.deleteUser(accessKey,user_id));

2. resources

2.1.create resource

console.log(await roleg.createResource(accessKey,resource_id));

2.2 get resource

     console.log(await roleg.getResource(accessKey,resource_id));

2.3 delete resource

 console.log(await roleg.deleteResource(accessKey,resource_id));

3. roles

3.1.create role

console.log(await roleg.createRole(accessKey,role_id));

3.2 get Role

console.log(await roleg.getRole(accessKey,role_id));

3.3 delete Role

  console.log(await roleg.deleteRole(accessKey,role_id));

4. user roles

4.1.create userrole

console.log(await roleg.createUserRole(accessKey,user_id,role_id));

4.2 get all roles for user

console.log(await roleg.get_all_roles_for_user(accessKey,user_id));

4.2 get all users for role

console.log(await roleg.get_all_users_for_role(accessKey,role_id));

4.4 delete userRole

  console.log(await roleg.deleteUserRole(accessKey,user_id,role_id));

5. permissions

Here a permission object is required . Following is an example of the permission object . These are the only fields which are allowed

           const creationObject = 
           {
             permission_id :"1009", // string
            days:[true,false, false,false, false, false,false],
            // boolean array of size 7 . If days[i] = true , it signifies 
            the following role_id can access the resource on that particular day
            start_time:"10:00", // string  , the time from which resource can be accessed
            end_time:"14:00",
            role_id:"1014", // must already exist in database
            resource_id:"1232",
            max_duration:0.02, // maximum time for which resource can be accessed
            }

5.1.create permission

console.log(await roleg.createPermission(accessKey,permission_id, creationObject));

5.2 update permission

console.log(await roleg.updatePermission(accessKey,permission_id,  updationObject));

5.3 get permission

console.log(await roleg.getPermission(accessKey,permission_id));

5.4 delete permission

  console.log(await roleg.deletePermission(accessKey,permission_id));

To check whether a following user can access a particular resource or not , use the following function:

      console.log(await roleg.canAccess(accessKey, user_id, resource_id));

To get unauthorized activity of an user , use the following function

    console.log(await roleg.getUnauthorizedActivityofUser(user_id));

If you wish to uninstall the package use the following function before doing so

      console.log(await  roleg.deleteKey(accessKey));

Note: Using the above function would delete all resources corresponding to the given user key from the database