Wondering what’s next for npm?Check out our public roadmap! »

    @asfweb/acl
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.12 • Public • Published

    The AccessControl.js with an extra function to create a custom action. Everything else is the same.

    New execute function

    Define roles and grants one by one.

    AccessControl.addAction(['move', 'login']); // Register your new actions here, note that: Create, Read, Update, Delete are added by default. This will set strict mode and you wont be able to create custom actions on fly exp:  ac.grant('user').execute('myaction').on('video'); will thow an error
    
    const ac = new AccessControl();
    ac.grant('user')                    		// define new or modify existing role. also takes an array.
      .execute('move').on('video')      		// equivalent to .execute('move:any').on('video', ['*'])
      .grant('admin')                   		// switch to another role without breaking the chain
      .extend('user')                   		// inherit role capabilities. also takes an array
      .execute('login').on('website');
    
    const permission = ac.can('user').execute('move').on('video');
    console.log(permission.granted);    // —> true
    console.log(permission.attributes); // —> ['*'] (all attributes)
    
    permission = ac.can('admin').execute('login').on('website');
    console.log(permission.granted);    // —> true
    console.log(permission.attributes); // —> ['*']

    Install

    npm i @asfweb/acl

    DownloadsWeekly Downloads

    15

    Version

    1.0.12

    License

    MIT

    Unpacked Size

    187 kB

    Total Files

    33

    Last publish

    Collaborators

    • avatar