This package has been deprecated

Author message:

this package has been deprecated

minimatch-permissions
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

minimatch-permissions

npm version

Define dot-notated permissions and match them using minimatch.

Usage

The api is very clean and simple. In this example, we use ES6 classes to define a User and a Tree.

import { Permissions, Authorization } from 'minimatch-permissions';
 
class NormalUser extends User {
    permissions = new Permissions({
        grant: [
            'Tree.Plant',        // subset in form of action
            'Tree.PlantedByYou', // subset in form of selection
            'Tree.Tall.Chop'     // combination of subsets
        ]
    })
}
 
class SuperUser extends User {
    permissions = new Permissions({
        grant: [
            'Tree',              // no subset
        ]
    })
}
 
class Tree {
 
    /**
     * The user is only permitted when he's granted "Tree" or "Tree.Plant"
     */
    plant() {
        new Authorization()
            .needs('Tree{,.Plant}')
            .check(user.permissions); // throws error for you
 
        // 💦🌱
    }
 
    /**
     * The user is only permitted to hug trees planted by himself
     */
    hug() {
        const auth = new Authorization()
            .has('Tree.PlantedByYou*', () => this.plantedByUser === user)
            .needs('Tree{,.PlantedByYou}{,.Hug}');
 
        if (auth.isPermitted(user.permissions)) {
            // 😙🌳
        }
    }
 
    /**
     * The user could be restricted to chop tall trees
     */
    chop() {
        new Authorization()
            .has('Tree.Tall*', () => this.height >= 30)
            .needs('Tree{,.Tall}{,.Chop}')
            .check(user.permissions);
 
        // 🌳⛏
    }
}

Package Sidebar

Install

npm i minimatch-permissions

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jessedvrs