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

simple-grant-lang

v0.9.4

Published

Simple Grant Language (SGL)

Downloads

13

Readme

SGL (Simple Grant Language)

This is the JavaScript implementation of SGL. It is usable in both node.js and browser environments. There is also a python implementation.

SGL is a simple but flexible DSL for matching people against criteria (typically, authorization). It is like XACML but simpler and JSON-oriented. You can use it to write rules about who should be able to do what, and then to compare circumstances to the rules to enforce custom logic. This lets you create your own Role-Based Access Control mechanisms, as well as authorizations based on other criteria.

For example, here's an SGL rule that says only members of the press should be allowed backstage at a concert:

{"grant": ["backstage"], "when": { "roles": "press" }}

And here's how you might use that rule in JavaScript/Node.JS code (Compare the python equivalent):

var sgl = require('simple-grant-lang')

my_rule = {grant: ["backstage"], when: { "roles": "press" }};

people = [
    {id: "Alex", roles: ["ticket-holder"]},
    {id: "Sofia", roles: ["ticket-holder", "press"]}
];

for (var i = 0; i < people.length; ++i) {
    name = people[i].id;
    if (sgl.satisfies(person, my_rule)) {
        console.print("Welcome backstage, " + name);
    } else {
        console.print("Sorry, this area is restricted, " + name);
    }
}

If you ran this code, you'd see:

$ node sampleCode.js
Sorry, this area is restricted, Alex.
Welcome backstage, Sofia.

SGL supports arbitrarily complex rules with boolean operators, as well as rules that require multiple people to jointly exercise a privilege. However, it's simple enough that you should be able to learn it in just a few minutes. See the tutorial.

Note: SGL can be rendered in various styles. The example above uses the recommended JSON rendering, since JSON is familiar, broadly supported, and easy to read. Other possibilities include ProtoBuf, MsgPack, CBOR, and human-friendly text.

SGL is not integrated with any particular enforcement mechanism, because it's designed for problems where you have to do your own enforcement. Hooking it up to enforcement mechanisms is trivial, though.

See also