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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bubojs/acl

v1.0.0

Published

<p align="center"> <a href="https://www.owlie.xyz"> <img src="https://owlie.xyz/bubo/bubo-js.png"> </a> </p>

Readme

Acl Middleware

Back to Main Menu

the Acl Set (Access Control List) allows to define the rights of each type of user, it is based on the library role-acl The Set provided by bubo is composed of 2 functions and 2 middlewares

acl

Acl

This decorator is placed on a controller class, it allows to assign all the rules that can be used on the controller in question

Example of a configuration object


import { DefaultActions } from '@bubojs/api'
import { UsersRepository } from './UsersRepository'
import { Right } from '@bubojs/catalog'

const usersRepository = new UsersRepository()

const userDefaultAccess = async (context: any) => {
  const { id } = context.params
  const userId = context.user.id
  const user = await usersRepository.findOneBy('id', id)
  return user.id === userId
}

export const userRights: Array<Omit<Right, 'resource'>> = [
  {
    role: 'admin',
    action: [
      DefaultActions.GET_MANY,
      DefaultActions.GET_ONE,
      DefaultActions.CREATE_ONE,
      DefaultActions.UPDATE_ONE,
      DefaultActions.DELETE_ONE,
      'checkPhone'
    ]
  },
  {
    role: 'regular',
    action: [DefaultActions.GET_ONE, DefaultActions.UPDATE_ONE, DefaultActions.DELETE_ONE],
    attributes: ['username', 'id', 'birthDate', 'email', 'gender', 'bio', 'phone'],
    condition: userDefaultAccess
  }
]

We define the possible actions for each role, the attributes to which they have access (this can be used for example for the attributes of sequelize) as well as the particular conditions to be fulfilled (here for example a classic user can only access himself and not the others)

On the controller:

import {Controller } from '@bubojs/api'
import { userRights } from './UsersAccess'
import { userValidation } from './UsersValidation'
import { userRepository } from '../../repositories'
import { User } from './User'
import { Acl } from '@bubojs/catalog'

@Acl(userRights)
@Controller({ repository: userRepository })
export class UsersController {
}

CheckAcl

This decorator is put on a route in order to activate the rights validation middleware for it, if the route is not defined in the rights then the route is systematically refused

import { Controller, DefaultActions } from '@bubojs/api'
import { AuthMiddleware } from '@bubojs/catalog'
import { userRights } from './UsersAccess'
import { userRepository } from '../../repositories'
import { User } from './User'
import { SequelizeAttributes } from '../../utils/middlewares/SequelizeAttributes.middleware'
import { Acl, CheckAcl } from '@bubojs/catalog'

@Acl(userRights)
@Controller({ repository: userRepository })
export class UsersController {
   @AuthMiddleware()
   @CheckAcl()
   @SequelizeAttributes(
           User,
           () => undefined,
           (req: any) => {
              const attr = req.permission.attributes
              return attr === ['*'] ? undefined : attr
           }
   )
   [DefaultActions.GET_ONE]() {
   }

   @AuthMiddleware()
   @CheckAcl()
   [DefaultActions.GET_MANY]() {
   }

   @AuthMiddleware()
   @CheckAcl()
   @SequelizeAttributes(
           User,
           () => undefined,
           (req: any) => {
              const attr = req.permission.attributes
              return attr === ['*'] ? undefined : attr
           }
   )
   [DefaultActions.CREATE_ONE]() {
   }

   @AuthMiddleware()
   @CheckAcl()
   @SequelizeAttributes(
           User,
           () => undefined,
           (req: any) => {
              const attr = req.permission.attributes
              return attr === ['*'] ? undefined : attr
           }
   )
   [DefaultActions.UPDATE_ONE]() {
   }

   @AuthMiddleware()
   @CheckAcl()
   [DefaultActions.DELETE_ONE]() {
   }
}

This decorator is put on a route in order to activate the rights validation middleware for it, if the route is not defined in the rights then the route is systematically refused

AclManager

Two functions are available on AclManager:

AclManager.applyRights which must be called to apply the rights in the manager, ideally just after the server startup once all controllers are registered

AclManager.roleCallback allows to redefine the role getter for a user, by default it will retrieve the "role" field

Back to Main Menu

Editor