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

facl

v0.2.1

Published

This is an access control language (Firestore inspired DSL) for securing backend REST api's written in node.js.

Downloads

10

Readme

FACL

This is a firebase rules inspired access control language (DSL) for securing backend REST api's written in node.js.

It is based on firebase' security rule syntax.

This project aims to provide a similar and consistent syntax as that exemplified at the links above.

Installation / Running

To install run:

$ npm install facl

Usage

Use as expressjs middleware created from directly from inline source code like:

 import * as facl from 'facl'
 app.use(facl.fromSource(`
   service https.cloudfunctions.net {
     match /path { 
       allow read: if true;
     }
   }
 `));
 // will allow HTTP GETs but not POSTs at '/path'

Alternatively, you can pull in the rules from a local file as in:

 const facl = require('facl') // feel free to use commonjs
 app.use(facl.fromFile('/path/to/example.simple.rules'))

The functions fromSource and fromFile are only intended to be used for development purposes.

In production, simply store the rules in memory (as a string) in the FACL_ACCESS_CONTROL_RULES environment variable and then:

 import facl from 'facl' // Then import default for production. Or do commonjs equivalent 
 app.use(facl()) // Alternatively, you can pass in a custom env. varName e.g `facl('MY_ENV_VAR')`

Take a look at the file example.app.js for a basic example of how to use this lib. To the run example:

$ node node_modules/facl/example.app.js

Further Info

Here is an example of what we are aiming to be able to write with this language. This would be for the purpose of securing or controlling access to REST endpoints in a firebase cloud functions context:

// The `cloud.functions.https` namespace currently doesn't exist but would 
// allow things like `request.accepts("json")` and `request.body`
// that are expected in an http validation context (see below for example use)
service cloud.functions.https {
  match /app {

    // Allow all requests to e.g. "/my_apis/my_twitter/endpoints/my_followers_list",
    // only if user (i.e. requester) is signed in, 
    // and deny all requests to e.g. "/non_apis/my_twitter/non_endpoints/my_followers_list".
    // even if user is signed in.
    match /my_apis/{api}/endpoints {
      match /{endpoint=**} {
        allow read, write: if request.auth.uid != null;
      }
    }

    allow read: if true; // e.g. Anyone can execute "GET /app"

    match /other_api/{other_endpoint} {
      
      // Allow GET requests to e.g. "/other_api/my_youtube",
      // only if requester's `Content-Type` is "application/json".    
      // The `allow get` is the same as `allow read`.
      allow get: if request.accepts("json");  
          
      // Allow POST, PUT and DELETE requests to e.g. "/other_api/my_google_plus",
      // only if requester's has non-empty body.
      // The "allow post, put, delete" is the same as `allow write`.
      allow post, put, delete: if request.body != null;  
    
    }     
  }

  // all requests to anything that's not explicitly declared with `match` will be denied by default
}

Feel free to star / fork or open an issue if you have any questions!

Related project XACML