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

feathers-mongoose-acl

v1.0.3

Published

Providing document and field based access layer for mongoose documents

Downloads

9

Readme

Build Status Coverage Status

feathers-mongoose-acl

feathers-mongoose-acl (or fma for short) gives you the power to adds a simple yet powerful access layer mechanism to your feathers-mongoose app.

fma comes built it with two layers of access control.
Document level access control and Field level access control.

With document level access layer, you can control which user role can have access to a document inside each service method call.
With field level access layer, you can control which user can a field in the document.

Getting Started

npm i feathers-mongoose-acl

Basic Usage Example

import {OR, ACCESS_LAYER, AccessLayerHookExternal} from 'feathers-mongoose-acl'
const createdByUser = context => {createdBy: context.params.user._id}
const assignedToUser = context => {assignedTo: context.params.user._id}

const access: ACCESS_LAYER = {
  DOC_ACCESS: {
    find: { ADMIN: true, '*': OR(createdByUser, assignedToUser)},
    remove: { ADMIN: true }
  },
  NONE_PATCHABLE_FIELDS: {
    ADMIN: {},
    '*': {
      fields: ['deleted', 'role', 'account'],
      throw: true
    }
  }
}


const before: Partial<HookMap> = {
  all: [index.authenticate(['jwt']), AccessLayerHookExternal(access)]
}

Let's unpack what we've done here.

  1. we create access layer object. each access layer object has doc access, and none_patchable_fields.
    in doc access, we defined for each method the user roles that have access to a document through service method calls. for example in "find" method, we give admin user permission to access all documents, but for all other user roles we only allow a user to access a document if he created it or if he is assigned to it.
  2. we defined none patchable fields, as their name indicates, once defined for a role, if he tries to modify them through patch, he will recieve an error.(if defined throw: true)

Typescript

feathers-mongoose-acl comes with internal typescript support

Test

To test it locally please run

npm run test:local

Contribution

Any type of contribution is welcomed, feel free to pm me 💓