{"_id":"@allstar/hemera-permission","_rev":"3-67247af87cfef61a014b081d73222e0d","name":"@allstar/hemera-permission","description":"Access control pluging for hemera applications","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"@allstar/hemera-permission","version":"1.0.0","description":"Access control pluging for hemera applications","main":"index.js","scripts":{"test":"tap -j4 -Rtap test --cov"},"repository":{"type":"git","url":"git+https://bitbucket.org/hitlist/hemera-permissions.git"},"keywords":["ACL","permissions","role","acl","'access","control'"],"author":{"name":"Eric Satterwhite","email":"esatterwhite@wi.rr.com"},"license":"MIT","homepage":"https://bitbucket.org/hitlist/hemera-permissions#readme","dependencies":{"hemera-plugin":"0.0.17"},"devDependencies":{"nats":"^0.7.24","nats-hemera":"^2.3.1","tap":"^10.7.2"},"gitHead":"1ac4f7ff22dad1740b6b9a3069017c52232fc2e5","_id":"@allstar/hemera-permission@1.0.0","_npmVersion":"5.4.2","_nodeVersion":"8.7.0","_npmUser":{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"},"dist":{"integrity":"sha512-Ozpv3+wUV97Wu4fsSheHXoPRDBBgJAe8Nc7xK3g3OsBEtUcSlH2xe7bjMFLLXPU+z2sV2NeiozBJlVHf7NsWgw==","shasum":"bf8709154341c439006fced5553e6f96dd6b5815","tarball":"https://registry.npmjs.org/@allstar/hemera-permission/-/hemera-permission-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCID4xBJ6zqC0ojdvkN35z/qL35RSFVmNMfBPZooGzHOTuAiEA+CGPhhZgeEdVDgjyczw0AZtYGx+ZgG3RTIxzyiZaniY="}]},"maintainers":[{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hemera-permission-1.0.0.tgz_1508619782437_0.1751211741939187"},"directories":{}},"2.0.0":{"name":"@allstar/hemera-permission","version":"2.0.0","description":"Access control pluging for hemera applications","main":"index.js","scripts":{"test":"tap -j4 -Rtap test --cov"},"repository":{"type":"git","url":"git+https://bitbucket.org/hitlist/hemera-permissions.git"},"keywords":["ACL","permissions","role","acl","'access","control'"],"author":{"name":"Eric Satterwhite","email":"esatterwhite@wi.rr.com"},"license":"MIT","homepage":"https://bitbucket.org/hitlist/hemera-permissions#readme","dependencies":{"hemera-plugin":"^0.1.1"},"devDependencies":{"nats":"^0.7.29","nats-hemera":"^3.2.0","tap":"^10.7.2"},"gitHead":"c8b9044ccf9347b066dfd2e5f5a40876efae84aa","_id":"@allstar/hemera-permission@2.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.3","_npmUser":{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"},"dist":{"integrity":"sha512-mlalutWfBQXXDMrVn44tDml8I7Wrd1rmr8YTtxb00L4Ojauxh2VdPhdRnCI1dI5JZWiaqcgSC3hZqeupyhaLuw==","shasum":"10dd24578596daa211107f4a51754fbc8ee39e42","tarball":"https://registry.npmjs.org/@allstar/hemera-permission/-/hemera-permission-2.0.0.tgz","fileCount":4,"unpackedSize":6988,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHirAb0XpeEWxQU6xFeO16y7eIJsbFG996GotKfciJquAiAVXKg44SpVo7Qw4LVOKMdU0g6JYkTkoXIJNI6N8Qu6Lg=="}]},"maintainers":[{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/hemera-permission_2.0.0_1519963753772_0.40392132964752125"},"_hasShrinkwrap":false}},"readme":"## Hemera ACL\n\nHemera pluging adding Access control via coarse based roles, or granular permissions\n\n### Installation\n\n```bash\n$ npm install @allstar/hemera-acl\n```\n\n### Usage\n\nBasic Setup\n\n```javascript\nconst Hemera = require('nats-hemera')\nconst nats = require('nats')\nconst Acl = require('@allstar/hemera-acl')\n\nconst nc = nats.connect({\n  servers: ['nats://0.0.0.0:4222']\n})\n\nconst hmera = new Hemera(nc)\nhemera.use(acl, {\n  separator: ':' // default\n})\n\nhemera.ready(() => {\n  // go!\n})\n```\n\n#### Roles\n\nFor coarse control, handlers can define a `roles` array (or single string) specifying the roles that are allowed\n\n```javascript\nhemera.add({\n  topic: 'math'\n, cmd: 'add'\n, auth$: {\n    roles: 'admin' // only admin access\n  }\n}, function(req, cb) {\n  // admin user\n  console.log(this.user$)\n  cb(null, true)\n})\n\nhemera.add({\n  topic: 'math'\n, cmd: 'subtract'\n, auth$: {\n    roles: ['admin', 'manager'] // admin OR manager access\n  }\n}, function(req, cb) {\n  // admin user\n  console.log(this.user$)\n  cb(null, true)\n})\n\nhemera.add({\n  topic: 'math'\n, cmd: 'divide'\n, auth$: {\n    roles: [] // no roles - superuser access only\n  }\n}, function(req, cb) {\n  // admin user\n  console.log(this.user$)\n  cb(null, true)\n})\n```\n\n##### Calling w/ roles\n\nAdding a `user`object to the hemera `metadata` with the `roles` array key populated to pass acl validation.\nRequest that do not pass authorization will return an `error` with the code **EAUTH**. Users with the special key **superuser**\nset tot `true` will always pass authorization\n\n```javascript\nhemera.act({\n  topic: 'math'\n, cmd: 'add'\n, meta$: {\n    user: {\n      roles: ['salesman', 'admin'] // passes authorization for the add handler\n    }\n  }\n}, function(err, res) {\n  console.log(res)\n})\n\nhemera.act({\n  topic: 'math'\n, cmd: 'subtract'\n, meta$: {\n    user: {\n      roles: ['grunt'] // fails validatin for the subtract handler\n    }\n  }\n}, function(err, res) {\n  console.log(err.code) // EAUTH\n})\n\nhemera.act({\n  topic: 'math'\n, cmd: 'divide'\n, meta$: {\n    user: {\n      superuser: true  // always authorized\n    }\n  }\n}, function(err, res) {\n  console.log('success!')\n})\n```\n\n#### Permissions\n\nPermissions allow you to specify an arbitry level of granularity from 1 level to as deep as you wish to go. Giving the **user** object\na nested `permissions` object will dictate what a user has access to. The terminal key in the object tree should be a boolean\nvalue (**true** or **false**). The absence of a key is equivelent to false\n\n\n```javascript\nconst user = {\n  roles: ['grunt']\n, permissions: {\n    auth: {\n      user: {\n        create: true\n      , read: true\n      , update: true\n      , delete: false\n      }\n    }\n  , blog: {\n      post: {\n        create: true\n      , update: true\n      , read: true\n      , delete: true\n      }\n    , tag: {\n        read: true\n      }\n    }\n  }\n}\n```\n\nTo mark a handler with the desired permission include a `permissions` key to the auth object.\n\n\n```javascript\nhemera.add({\n  topic: 'blog'\n, cmd: 'post'\n, auth$: {\n    permissions: 'blog:post:create' // need to permission to create blog posts\n  }\n}, function(req, cb) {\n  console.log(this.user$)\n  cb(null, true)\n})\n\nhemera.add({\n  topic: 'user'\n, cmd: 'delete'\n, auth$: {\n    permissions: 'one:very:very:specific:perm:only:few:people:have' // very granular permission\n  }\n}, function(req, cb) {\n  console.log(this.user$)\n  cb(null, true)\n})\n\nhemera.add({\n  topic: 'internal'\n, cmd: 'dangerous'\n, auth$: {\n    permissions: ' '  // super user only access (empty string)\n  }\n}, function(req, cb) {\n  console.log(this.user$)\n  cb(null, true)\n})\n```\n\n##### Calling with permissions\n\n```javascript\nhemera.act({\n  topic: 'math'\n, cmd: 'add'\n, meta$: {\n    user: {\n      permissions: {\n        auth: {\n          user: {\n            create: true\n          }\n        }\n      , one: {\n          very: {\n            very: {\n              specific: {\n                perm: {\n                  only: {\n                    few: {\n                      people: {\n                        have: true\n                      }\n                    }\n                  }\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n}, function(err, res) {\n  console.log(res)\n})\n```\n","maintainers":[{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"}],"time":{"modified":"2022-04-04T13:34:48.120Z","created":"2017-10-21T21:03:03.525Z","1.0.0":"2017-10-21T21:03:03.525Z","2.0.0":"2018-03-02T04:09:13.858Z"},"homepage":"https://bitbucket.org/hitlist/hemera-permissions#readme","keywords":["ACL","permissions","role","acl","'access","control'"],"repository":{"type":"git","url":"git+https://bitbucket.org/hitlist/hemera-permissions.git"},"author":{"name":"Eric Satterwhite","email":"esatterwhite@wi.rr.com"},"license":"MIT","readmeFilename":"README.md"}