{"_id":"koa-roles","_rev":"1214322","name":"koa-roles","description":"koa version of Connect-Roles","dist-tags":{"latest":"2.0.0"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"time":{"modified":"2021-10-13T05:47:21.000Z","created":"2014-03-26T11:05:02.689Z","2.0.0":"2017-11-23T07:29:48.297Z","1.0.3":"2017-01-25T05:27:11.446Z","1.0.2":"2015-12-10T08:20:24.682Z","1.0.1":"2015-08-23T15:18:37.823Z","1.0.0":"2015-05-12T15:20:34.937Z","0.1.0":"2014-06-11T03:58:31.316Z","0.0.1":"2014-03-27T12:38:22.590Z","0.0.0":"2014-03-26T11:05:02.689Z"},"users":{"snowdream":true,"nisimjoseph":true},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.com"},"repository":{"type":"git","url":"git://github.com/koajs/koa-roles.git","web":"https://github.com/koajs/koa-roles"},"versions":{"2.0.0":{"name":"koa-roles","version":"2.0.0","description":"koa version of Connect-Roles","main":"index.js","files":["index.js"],"scripts":{"test":"egg-bin test","test-cov":"egg-bin cov","ci":"npm run lint && egg-bin cov","lint":"eslint index.js test","autod":"autod -w --prefix '^'","cnpm":"npm install --registry=https://registry.npm.taobao.org","contributors":"contributors -f plain -o AUTHORS"},"dependencies":{"is-type-of":"^1.2.0"},"devDependencies":{"autod":"*","co-sleep":"^0.0.1","contributors":"*","egg-bin":"^4.3.5","egg-ci":"^1.8.0","eslint":"^4.11.0","eslint-config-egg":"^5.1.1","koa":"^2.4.1","koa-router":"^7.3.0","pedding":"^1.1.0","should":"^13.1.3","supertest":"^3.0.0"},"homepage":"https://github.com/koajs/koa-roles","repository":{"type":"git","url":"git://github.com/koajs/koa-roles.git","web":"https://github.com/koajs/koa-roles"},"bugs":{"url":"https://github.com/koajs/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles","roles","role","connect-roles","koa"],"engines":{"node":">= 8.0.0"},"ci":{"version":"8, 9"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.com"},"license":"MIT","contributors":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"Hugo Dozois","email":"hugo@dozoisch.com"},{"name":"Jason Lee","email":"huacnlee@gmail.com","url":"https://github.com/huacnlee"},{"name":"fengmk2","email":"m@fengmk2.com","url":"https://github.com/fengmk2"},{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com","url":"https://github.com/shaoshuai0102"},{"name":"Haoliang Gao","email":"sakura9515@gmail.com","url":"https://github.com/popomore"}],"gitHead":"4a84a0fc070effb9a7d25d069e9cba602212ef09","_id":"koa-roles@2.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"dist":{"shasum":"3974580a03ba3356fbfddd94546f14006678efc0","size":4006,"noattachment":false,"key":"/koa-roles/-/koa-roles-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-2.0.0.tgz"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/koa-roles-2.0.0.tgz_1511422188236_0.40355298202484846"},"directories":{},"publish_time":1511422188297,"_hasShrinkwrap":false,"_cnpm_publish_time":1511422188297},"1.0.3":{"name":"koa-roles","version":"1.0.3","description":"koa version of Connect-Roles","main":"index.js","files":["index.js"],"scripts":{"test":"mocha --check-leaks -R spec -t 5000 test/*.test.js","test-cov":"istanbul cover node_modules/.bin/_mocha -- --check-leaks -t 5000 test/*.test.js","test-travis":"npm run lint && istanbul cover node_modules/.bin/_mocha --report lcovonly -- --check-leaks -t 5000 test/*.test.js","lint":"eslint index.js","autod":"autod -w --prefix '~'","cnpm":"npm install --registry=https://registry.npm.taobao.org","contributors":"contributors -f plain -o AUTHORS"},"dependencies":{"is-type-of":"~0.3.1"},"devDependencies":{"autod":"*","bluebird":"^3.4.7","co-sleep":"0","contributors":"*","cov":"*","eslint":"1","istanbul-harmony":"*","jshint":"*","koa":"1","koa-router":"4","mocha":"*","pedding":"1","should":"7","supertest":"0"},"homepage":"https://github.com/koajs/koa-roles","repository":{"type":"git","url":"git://github.com/koajs/koa-roles.git","web":"https://github.com/koajs/koa-roles"},"bugs":{"url":"https://github.com/koajs/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles","roles","role","connect-roles","koa"],"engines":{"node":">= 1.0.0"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.com"},"license":"MIT","contributors":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"Hugo Dozois","email":"hugo@dozoisch.com"},{"name":"Jason Lee","email":"huacnlee@gmail.com","url":"https://github.com/huacnlee"},{"name":"fengmk2","email":"m@fengmk2.com","url":"https://github.com/fengmk2"},{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com","url":"https://github.com/shaoshuai0102"},{"name":"Haoliang Gao","email":"sakura9515@gmail.com","url":"https://github.com/popomore"}],"gitHead":"d0d9a3dfd7042c89be8ad4a13bb882b4e1cf6672","_id":"koa-roles@1.0.3","_shasum":"3220d57d5da4c21bd25be7dca8bf6d23535f0a79","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.9.4","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"dist":{"shasum":"3220d57d5da4c21bd25be7dca8bf6d23535f0a79","size":3955,"noattachment":false,"key":"/koa-roles/-/koa-roles-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-1.0.3.tgz"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/koa-roles-1.0.3.tgz_1485322029620_0.8656206885352731"},"directories":{},"publish_time":1485322031446,"_cnpm_publish_time":1485322031446,"_hasShrinkwrap":false},"1.0.2":{"name":"koa-roles","version":"1.0.2","description":"koa version of Connect-Roles","main":"index.js","files":["index.js"],"scripts":{"test":"mocha --check-leaks -R spec -t 5000 test/*.test.js","test-cov":"istanbul cover node_modules/.bin/_mocha -- --check-leaks -t 5000 test/*.test.js","test-travis":"npm run lint && istanbul cover node_modules/.bin/_mocha --report lcovonly -- --check-leaks -t 5000 test/*.test.js","lint":"eslint index.js","autod":"autod -w --prefix '~'","cnpm":"npm install --registry=https://registry.npm.taobao.org","contributors":"contributors -f plain -o AUTHORS"},"dependencies":{"is-type-of":"~0.3.1"},"devDependencies":{"autod":"*","co-sleep":"0","contributors":"*","cov":"*","eslint":"1","istanbul-harmony":"*","jshint":"*","koa":"1","koa-router":"4","mocha":"*","pedding":"1","should":"7","supertest":"0"},"homepage":"https://github.com/koajs/koa-roles","repository":{"type":"git","url":"git://github.com/koajs/koa-roles.git","web":"https://github.com/koajs/koa-roles"},"bugs":{"url":"https://github.com/koajs/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles","roles","role","connect-roles","koa"],"engines":{"node":">= 1.0.0"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.com"},"license":"MIT","contributors":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"Hugo Dozois","email":"hugo@dozoisch.com"},{"name":"Jason Lee","email":"huacnlee@gmail.com","url":"https://github.com/huacnlee"},{"name":"fengmk2","email":"m@fengmk2.com","url":"https://github.com/fengmk2"},{"name":"shaoshuai0102","email":"shaoshuai0102@gmail.com","url":"https://github.com/shaoshuai0102"}],"gitHead":"bce7f17698c24340971161d6c2d8e7752860dfd4","_id":"koa-roles@1.0.2","_shasum":"975ad201eaf435efb0fece0dae439ba380935fef","_from":".","_npmVersion":"3.3.9","_nodeVersion":"5.1.1","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"dist":{"shasum":"975ad201eaf435efb0fece0dae439ba380935fef","size":3913,"noattachment":false,"key":"/koa-roles/-/koa-roles-1.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-1.0.2.tgz"},"directories":{},"publish_time":1449735624682,"_cnpm_publish_time":1449735624682,"_hasShrinkwrap":false},"1.0.1":{"name":"koa-roles","version":"1.0.1","description":"koa version of Connect-Roles","main":"index.js","files":["index.js"],"scripts":{"test":"mocha --check-leaks -R spec -t 5000 test/*.test.js","test-cov":"istanbul cover node_modules/.bin/_mocha -- --check-leaks -t 5000 test/*.test.js","test-travis":"npm run lint && istanbul cover node_modules/.bin/_mocha --report lcovonly -- --check-leaks -t 5000 test/*.test.js","lint":"eslint index.js","autod":"autod -w --prefix '~'","cnpm":"npm install --registry=https://registry.npm.taobao.org","contributors":"contributors -f plain -o AUTHORS"},"dependencies":{"is-type-of":"~0.3.1"},"devDependencies":{"autod":"*","co-sleep":"0","contributors":"*","cov":"*","eslint":"1","istanbul-harmony":"*","jshint":"*","koa":"1","koa-router":"4","mocha":"*","pedding":"1","should":"7","supertest":"0"},"homepage":"https://github.com/koajs/koa-roles","repository":{"type":"git","url":"git://github.com/koajs/koa-roles.git","web":"https://github.com/koajs/koa-roles"},"bugs":{"url":"https://github.com/koajs/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles","roles","role","connect-roles","koa"],"engines":{"node":">= 1.0.0"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.com"},"license":"MIT","contributors":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"Hugo Dozois","email":"hugo@dozoisch.com"},{"name":"Jason Lee","email":"huacnlee@gmail.com","url":"https://github.com/huacnlee"},{"name":"fengmk2","email":"m@fengmk2.com","url":"https://github.com/fengmk2"}],"gitHead":"bd7210f72dac853897336cc32eec8d410b78a863","_id":"koa-roles@1.0.1","_shasum":"97d63191fc19487d0fe5e489c7a12772e9b80002","_from":".","_npmVersion":"2.13.2","_nodeVersion":"2.5.3","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"dist":{"shasum":"97d63191fc19487d0fe5e489c7a12772e9b80002","size":3773,"noattachment":false,"key":"/koa-roles/-/koa-roles-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-1.0.1.tgz"},"directories":{},"publish_time":1440343117823,"_cnpm_publish_time":1440343117823,"_hasShrinkwrap":false},"1.0.0":{"name":"koa-roles","version":"1.0.0","description":"koa version of Connect-Roles","main":"index.js","scripts":{"test":"make test-all"},"config":{"cov":{"threshold":95}},"dependencies":{"is-type-of":"~0.3.1","path-to-regexp":"~1.1.1"},"devDependencies":{"autod":"*","co-sleep":"~0.0.1","contributors":"*","cov":"*","istanbul-harmony":"*","jshint":"*","koa":"~0.20.0","koa-router":"~4.3.2","mocha":"*","pedding":"~1.0.0","should":"~6.0.1","supertest":"~0.15.0"},"homepage":"https://github.com/fengmk2/koa-roles","repository":{"type":"git","url":"git://github.com/fengmk2/koa-roles.git","web":"https://github.com/fengmk2/koa-roles"},"bugs":{"url":"https://github.com/fengmk2/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles","roles","role","connect-roles","koa"],"engines":{"node":">= 0.11.9"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.github.com"},"license":"MIT","contributors":[{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"}],"gitHead":"e08b4baa8976f7ce6cad94fc027fa63b2fcc9488","_id":"koa-roles@1.0.0","_shasum":"57d615107984c8fbc6931ec6814ac119ae6ff55d","_from":".","_npmVersion":"2.9.0","_nodeVersion":"2.0.1","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"dist":{"shasum":"57d615107984c8fbc6931ec6814ac119ae6ff55d","size":3530,"noattachment":false,"key":"/koa-roles/-/koa-roles-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-1.0.0.tgz"},"directories":{},"publish_time":1431444034937,"_cnpm_publish_time":1431444034937,"_hasShrinkwrap":false},"0.1.0":{"name":"koa-roles","version":"0.1.0","description":"koa version of Connect-Roles","main":"index.js","scripts":{"test":"make test-all"},"config":{"cov":{"threshold":95}},"dependencies":{"is-type-of":"~0.3.0","path-to-regexp":"~0.2.0"},"devDependencies":{"autod":"~*","co-sleep":"~0.0.1","contributors":"~*","cov":"~*","istanbul-harmony":"~*","jshint":"~*","koa":"~0.7.0","koa-router":"~3.1.4","mocha":"~*","pedding":"~0.0.3","should":"~4.0.4","supertest":"~0.13.0"},"homepage":"https://github.com/fengmk2/koa-roles","repository":{"type":"git","url":"git://github.com/fengmk2/koa-roles.git","web":"https://github.com/fengmk2/koa-roles"},"bugs":{"url":"https://github.com/fengmk2/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles","roles","role","connect-roles","koa"],"engines":{"node":">= 0.11.9"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.github.com"},"license":"MIT","contributors":[{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"}],"gitHead":"7455325ae4c58a3ccb2395889529c56b55056403","_id":"koa-roles@0.1.0","_shasum":"cd91b5f76de0176921f2a2d185f318099955271d","_from":".","_npmVersion":"1.4.13","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"dist":{"shasum":"cd91b5f76de0176921f2a2d185f318099955271d","size":3487,"noattachment":false,"key":"/koa-roles/-/koa-roles-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-0.1.0.tgz"},"directories":{},"publish_time":1402459111316,"_cnpm_publish_time":1402459111316,"_hasShrinkwrap":false},"0.0.1":{"name":"koa-roles","version":"0.0.1","description":"koa version of Connect-Roles","main":"index.js","scripts":{"test":"make test-all"},"config":{"cov":{"threshold":95}},"dependencies":{"is-type-of":"0.0.1","path-to-regexp":"0.1.2"},"devDependencies":{"autod":"*","co-sleep":"0.0.1","contributors":"*","cov":"*","istanbul-harmony":"*","jshint":"*","koa":"0.5.2","koa-router":"3.1.2","mocha":"*","pedding":"0.0.3","should":"3.2.0-beta1","supertest":"0.10.0"},"homepage":"https://github.com/fengmk2/koa-roles","repository":{"type":"git","url":"git://github.com/fengmk2/koa-roles.git","web":"https://github.com/fengmk2/koa-roles"},"bugs":{"url":"https://github.com/fengmk2/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles","roles","role","connect-roles","koa"],"engines":{"node":">= 0.11.9"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.github.com"},"license":"MIT","contributors":[{"name":"fengmk2","email":"fengmk2@gmail.com","url":"https://github.com/fengmk2"}],"_id":"koa-roles@0.0.1","dist":{"shasum":"a6505f1f36f3d143e2c699407fc421283ab91634","size":3411,"noattachment":false,"key":"/koa-roles/-/koa-roles-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-0.0.1.tgz"},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"directories":{},"publish_time":1395923902590,"_cnpm_publish_time":1395923902590,"_hasShrinkwrap":false},"0.0.0":{"name":"koa-roles","version":"0.0.0","description":"koa-roles","main":"index.js","scripts":{"test":"make test-all"},"config":{"cov":{"threshold":100}},"dependencies":{},"devDependencies":{"autod":"*","contributors":"*","should":"*","jshint":"*","cov":"*","istanbul":"git://github.com/gotwarlost/istanbul.git#harmony","mocha":"*"},"homepage":"https://github.com/fengmk2/koa-roles","repository":{"type":"git","url":"git://github.com/fengmk2/koa-roles.git","web":"https://github.com/fengmk2/koa-roles"},"bugs":{"url":"https://github.com/fengmk2/koa-roles/issues","email":"fengmk2@gmail.com"},"keywords":["koa-roles"],"engines":{"node":">= 0.10.0"},"author":{"name":"fengmk2","email":"fengmk2@gmail.com","url":"http://fengmk2.github.com"},"license":"MIT","contributors":[],"_id":"koa-roles@0.0.0","dist":{"shasum":"fec0f6c4beef93897acb1b5f0e392f438d37245d","size":1849,"noattachment":false,"key":"/koa-roles/-/koa-roles-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/koa-roles/download/koa-roles-0.0.0.tgz"},"_from":".","_npmVersion":"1.4.6","_npmUser":{"name":"fengmk2","email":"fengmk2@gmail.com"},"maintainers":[{"name":"fengmk2","email":"fengmk2@gmail.com"},{"name":"popomore","email":""}],"directories":{},"publish_time":1395831902689,"_cnpm_publish_time":1395831902689,"_hasShrinkwrap":false}},"readme":"koa-roles\n=======\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![Gittip][gittip-image]][gittip-url]\n[![David deps][david-image]][david-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/koa-roles.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-roles\n[travis-image]: https://img.shields.io/travis/koajs/koa-roles.svg?style=flat-square\n[travis-url]: https://travis-ci.org/koajs/koa-roles\n[coveralls-image]: https://img.shields.io/coveralls/koajs/koa-roles.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/koajs/koa-roles?branch=master\n[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat-square\n[gittip-url]: https://www.gittip.com/fengmk2/\n[david-image]: https://img.shields.io/david/koajs/koa-roles.svg?style=flat-square\n[david-url]: https://david-dm.org/koajs/koa-roles\n[download-image]: https://img.shields.io/npm/dm/koa-roles.svg?style=flat-square\n[download-url]: https://npmjs.org/package/koa-roles\n\nkoa version of [connect-roles](https://github.com/ForbesLindesay/connect-roles)\n\n## Install\n\n```bash\n$ npm install koa-roles\n```\n\n## Usage\n\n```js\nconst Roles = require('koa-roles');\nconst koa = require('koa');\nconst app = new koa();\n\nconst user = new Roles({\n  async failureHandler(ctx, action) {\n    // optional function to customise code that runs when\n    // user fails authorisation\n    ctx.status = 403;\n    var t = ctx.accepts('json', 'html');\n    if (t === 'json') {\n      ctx.body = {\n        message: 'Access Denied - You don\\'t have permission to: ' + action\n      };\n    } else if (t === 'html') {\n      ctx.render('access-denied', {action: action});\n    } else {\n      ctx.body = 'Access Denied - You don\\'t have permission to: ' + action;\n    }\n  }\n});\n\napp.use(user.middleware());\n\n// anonymous users can only access the home page\n// returning false stops any more rules from being\n// considered\nuser.use(async (ctx, action) => {\n  return ctx.user || action === 'access home page';\n});\n\n// moderator users can access private page, but\n// they might not be the only ones so we don't return\n// false if the user isn't a moderator\nuser.use('access private page', ctx => {\n  if (ctx.user.role === 'moderator') {\n    return true;\n  }\n})\n\n//admin users can access all pages\nuser.use((ctx, action) => {\n  if (ctx.user.role === 'admin') {\n    return true;\n  }\n});\n\napp.get('/', user.can('access home page'), async ctx => {\n  await ctx.render('private');\n});\napp.get('/private', user.can('access private page'), async ctx => {\n  await ctx.render('private');\n});\napp.get('/admin', user.can('access admin page'), async ctx => {\n  await ctx.render('admin');\n});\n\napp.listen(3000);\n```\n\n## License\n\n[MIT](LICENSE.txt)\n","_attachments":{},"homepage":"https://github.com/koajs/koa-roles","bugs":{"url":"https://github.com/koajs/koa-roles/issues","email":"fengmk2@gmail.com"},"license":"MIT"}