{"_id":"@bloxite/koa-access-guard","_rev":"5-49b0c808b4801900c2d3e15ce0aa3181","name":"@bloxite/koa-access-guard","description":"Permissions-based access guard for Koa@2","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@bloxite/koa-access-guard","version":"0.0.1","description":"Permissions-based access guard for Koa@2","main":"src/index.js","scripts":{"test":"NODE_ENV=testing mocha","test:watch":"NODE_ENV=testing mocha --watch"},"repository":{"type":"git","url":"git+ssh://git@github.com/bloxite/koa-access-guard.git"},"authors":"Pavel Kilin <pavel@asdf404.net>, Bloxite Team (bloxite.net)","license":"MIT","homepage":"https://github.com/bloxite/koa-access-guard#readme","keywords":["koa","access"],"devDependencies":{"babel-eslint":"^7.1.1","eslint":"^3.15.0","eslint-config-standard":"^6.1.0","eslint-plugin-mocha":"^4.8.0","eslint-plugin-promise":"^3.4.0","eslint-plugin-standard":"^2.0.1","mocha":"^2.5.3","sinon":"^1.17.7"},"dependencies":{"http-errors":"^1.6.1","minimatch":"^3.0.3"},"gitHead":"2c7747cb65c06e666c4d4374e0242a5812903e62","bugs":{"url":"https://github.com/bloxite/koa-access-guard/issues"},"_id":"@bloxite/koa-access-guard@0.0.1","_shasum":"5b5ec517e564d7b4441ad041dcc5c06250e06245","_from":".","_npmVersion":"4.1.2","_nodeVersion":"7.5.0","_npmUser":{"name":"bloxite","email":"admin@bloxite.net"},"dist":{"shasum":"5b5ec517e564d7b4441ad041dcc5c06250e06245","tarball":"https://registry.npmjs.org/@bloxite/koa-access-guard/-/koa-access-guard-0.0.1.tgz","integrity":"sha512-gGYiDPj67BcOJrNA7hcOT8mfB3SK3gC07AoRwaJLkFgJuVo8K9dUUhRgmkYax34+hT8VZeffb1ElztkAgSG+LA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDJ5kIkkw1bgbKOVCF6nC8r7iLQIvrtj/hWlQ0QWtB9AAIhAKQqwxzgWN9mks+rtAZc9vzBEeAMu6EbTLmN9c3ThpVG"}]},"maintainers":[{"name":"bloxite","email":"admin@bloxite.net"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/koa-access-guard-0.0.1.tgz_1487753240212_0.7963857124559581"}}},"readme":"# Koa DALs\n\n[![Build Status](https://travis-ci.org/Bloxite/koa-access-guard.svg?branch=master)](https://travis-ci.org/Bloxite/koa-access-guard)\n\nPermissions-based access guard for Koa@2\n\n[![Standard - JavaScript Style Guide](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)\n\n## Installation\n\n```\nnpm install @bloxite/koa-access-guard --save\n```\n\n## Usage\n\nImport guard object\n\n```js\nconst guard = require('@bloxite/koa-access-guard')\n// or in ES6-way\nimport guard from '@bloxite/koa-access-guard'\n```\n\nThis module made for work with [koa-router](https://www.npmjs.com/package/koa-router).\n\n`Guard#some` allows to restrict access only for users who have permissions `user` or `admin`:\n\n```js\nrouter.get(\n  '/profile', guard.some([ 'user', 'admin' ]),\n  () => { /* ... */ }\n)\n```\n\n`Guard#every` allows to restrict access only for users who have permissions `user` and `admin` both:\n\n```js\nrouter.get(\n  '/admin', guard.every([ 'user', 'admin' ]),\n  () => { /* ... */ }\n)\n```\n\n`Guard#some` and `Guard#every` works very similarly to [`Array#some`](https://mdn.io/Array/some) and [`Array#every`](https://mdn.io/Array/every) respectively.\n\nAlso you can pass function for permissions validation. Be noted: function will be executed for every user's permission from `ctx.state.user.permissions`:\n\n```js\nrouter.post(\n  '/profile/:id',\n  guard.some([ // allowed for \"admin\" or owner of profile\n    'admin',\n    (permission, context) =>  // permission name and Koa's context\n      context.user.id === context.params.id\n  ]),\n  () => { /* ... */ }\n)\n```\n\nYou can use wildcard rules with glob-syntax that provided by [minimatch](https://www.npmjs.com/package/minimatch) package:\n\n```js\nrouter.put(\n  '/posts',\n  guard.some([ 'admin', 'moderator:*' ]),\n  () => { /* ... */ }\n)\n```\n\nGuard is configurable:\n\n```js\nimport guard from '@bloxite/koa-access-guard'\n\nconst myGuard = guard({\n  userProperty: 'person', // property from `ctx.state` for store user object\n  permissionsProperty: 'scopes', // property for store permissions\n  errorConstructor: MyCustomErrorConstructor // custom error that will be thrown\n})\n\nrouter.get(\n  '/', myGuard.some(/*...*/),\n  () => { /* ... */ }\n)\n```\n\n## License\n\nMIT License\n\nCopyright (c) 2017 Bloxite\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","maintainers":[],"time":{"modified":"2022-06-12T15:22:33.551Z","created":"2017-02-22T08:47:20.761Z","0.0.1":"2017-02-22T08:47:20.761Z"},"homepage":"https://github.com/bloxite/koa-access-guard#readme","keywords":["koa","access"],"repository":{"type":"git","url":"git+ssh://git@github.com/bloxite/koa-access-guard.git"},"bugs":{"url":"https://github.com/bloxite/koa-access-guard/issues"},"license":"MIT","readmeFilename":"README.md"}