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

ssacl

v0.1.3

Published

Simple ACL for Sequelize

Downloads

10

Readme

Simple ACL for Sequelize

Build Status

Effortlessly ensure that only the right actors can read and write objects.

ssacl will ensure that all reads have the appropriate where queries attached and that all writes are checked for appropriate ownership values.

ssacl needs Sequelize 2.0.7 or higher for all functionality to work

Getting Started

npm install --save ssacl
var ssacl = require('ssacl');

ssacl(sequelize|Model, {
  read: {
    attribute: 'reader'
  },
  write: {
    attribute: 'userId'
  }
});

Note: Either enable ssacl on the entire sequelize instance or specific Models. Mixing is not supported. Note: If using ssacl on specific models rather than on the sequelize instance the paranoia option needs to be the same for all models.

Usage

// will throw an error if the actor for instance does not match the passed actor
instance.update(values, {
  actor: actor
});

// will throw an error if the actor for instance does not match the passed actor
instance.destroy({
  actor: actor
});

// will ammend the where to match the actor
Model.update(values, {
  where: {..}
  actor: actor
});

// will ammend the where to match the actor
Model.destroy({
  where: {..}
  actor: actor
});

// will ammend the where to match the actor
Model.findAll({
  where: {..}
  actor: actor
});

// will ammend the where to match the actor
Model.findOne({
  where: {..}
  actor: actor
});

CLS

Passing actor to all calls can be cumbersome and error-prone so ssacl also supports passing the actor with CLS.

var cls = require('continuation-local-storage')
  , ns = cls.createNamespace('mynamespace');

ssacl(sequelize|Model, {
  cls: ns
});

// ssacl will look for the actor property in the name

ns.run(function () {
  ns.set('actor', 2);

  // both calls will automatically be scoped without explicitely setting actor
  return Model.findAll().then(function () {
    return Model.destroy();
  });
});

Note that this will apply CLS to Sequelize, so if using CLS with Sequelize, make sure it's the same namespace

Paranoia

By default ssacl will have paranoia enabled (disable with {paranoia: false} globally, or per call). With Paranoia enabled any query executed without an actor will result in an error. To perform actions as god/root use new ssacl.Omnipotent() as a placeholder actor that allows everything.

Note: null or any value matching the public value of read is also a valid read actor.

Options

ssacl

  • paranoia true|false Toggle paranoia mode, default: true
  • actor function Takes a function that parses an actor into a queryable primitive. Default function will take primary key value from a sequelize instance or return the passed input.
  • read object Defines the options for read restriction
  • read.attribute string The attribute/field to store allowed reader in
  • read.public Value for public read, default: null
  • read.none Value for no reads, default: 0
  • write object Defines the options for write restriction
  • write.attribute string The attribute/field to store allowed writeer in
  • write.none Value for no writes, default: 0

calls

  • actor null|primitive|object|instance|Omnipotent The actor for this call, default: null
  • paranoia true|false Toggle paranoia mode for this call default: true

Add-ons

ssacl-attributeq-roles

ssacl ships with ssacl-attribute-roles so you get role white-/blacklisting for free.

ssacl will automatically initialize the addon on the models you initialize ssacl on, so you simply have to configure your attributes as described on the add-ons github page.

koa-ssacl

koa-ssacl makes actor passing trivial by supporting cls with middleware.

Sponsored by PumpUp

The work on this project is being sponsored by the great people at PumpUp