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

alpha-ac

v2.0.2

Published

[![CircleCI](https://circleci.com/gh/wookieb/alpha-ac.svg?style=svg)](https://circleci.com/gh/wookieb/alpha-ac)

Downloads

7

Readme

Alpha AC

CircleCI

Alpha AC is a simple but powerful Access control system inspired by Symfony2 Voters. The idea is very simple. You ask Alpha AC whether a participant (anonymous, user, system or other) has given a privilege on a subject. For example whether UserParticipant has privilege to "view" the "post".

acl.isAllowed(new Participant.Account(user), "view", post)
.then((isAllowed) => {
    // :)
})

This simple approach allows to implement any type of Access system you want.

Install

npm install alpha-ac

Usage

import {AccessControl, Rule, Participant} from "alpha-ac";

const ac = new AccessControl();

// Allows user to view/edit post they own 
class SimpleRule implements Rule {
    supports(privilege: any, subject: any): boolean {
        return ['view', 'edit'].indexOf(privilege) !== -1;
    }
    
    isAllowed(participant: Participant, privilege: any, subject: any): Promise<boolean>|boolean {
        if (Participant.Account.is(participant)) {
            return subject.ownerId === participant.account.id;
        }
        return false;
    }
}

ac.registerRule(new SimpleRule());

ac.isAllowed(new Participant.Account(user), "view", post).then(/* ... */)

How it works

First you need to create a rule object (might be an instance of class or just an objeect) with 2 methods:

  • supports(privilege, subject) - tells whether the rule is able to make decision about given privilege and subject
  • isAllowed(participant, privilege, subject) - makes final decision

Once you have the object ready register it to AccessControl via "registerRule". The Access control will be looking for the first rule that is able to make decision about given privilege and subject and ask it for a decision.

Participants

A participant represents an identity that needs to perform some action on the system.

Alpha AC predefines few kinds of participants but you don't have to use all of them if it's not necessary.

  • Participant.Anonymous - represents anonymous participant (for example not logged in user)
  • Participant.Account - Represents logged in user assigned to some account
  • Participant.System - useful if you need more control about what operations might be performed for example from CLI

Every participant has "type" property so you can check in your rules what kind of participant you're dealing with.