{"id":24738627,"url":"https://github.com/zweifisch/permitted","last_synced_at":"2026-05-03T09:33:32.184Z","repository":{"id":35752441,"uuid":"40031608","full_name":"zweifisch/permitted","owner":"zweifisch","description":"role \u0026 permission control","archived":false,"fork":false,"pushed_at":"2017-09-23T05:45:42.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T17:53:53.195Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zweifisch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-01T01:45:07.000Z","updated_at":"2017-09-23T05:45:44.000Z","dependencies_parsed_at":"2022-08-26T17:00:26.099Z","dependency_job_id":null,"html_url":"https://github.com/zweifisch/permitted","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fpermitted","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fpermitted/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fpermitted/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zweifisch%2Fpermitted/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zweifisch","download_url":"https://codeload.github.com/zweifisch/permitted/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245006616,"owners_count":20546136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-27T22:55:05.940Z","updated_at":"2026-05-03T09:33:32.146Z","avatar_url":"https://github.com/zweifisch.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# permitted\n\n[![NPM Version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n\nrole based access control\n\n## usage\n\n```js\nimport {User, Policy} from 'permitted'\n\nlet policy = new Policy({\n    article: {\n        read: ['user', 'editor'],\n        write: 'editor'\n    },\n    user: {\n        manage: 'admin'\n    }\n})\n\nlet user = new User('admin', policy)\n\nuser.can('read', 'article')  // false\nuser.can('manage', 'user')  // true\nuser.is('admin')  // true\n```\n\n### role inheritance\n\n```js\nimport {User, Policy} from 'permitted'\n\nlet hierachy = {\n    admin: ['user', 'editor'],\n    editor: 'user'\n}\nlet policy = {\n    article: {\n        read: 'user',\n        write: 'editor'\n    },\n    issue: {\n        report: ['user', '!admin']\n    }\n}\nlet user = new User('admin', new Policy(policy, hierarchy))\n\nuser.is('editor')  // true\nuser.can('read', 'article')  // true\nuser.can('report', 'issue')  // false\n```\n\n### the root role\n\nroot can do anything\n\n```js\nlet root = new User('root', new Policy(policy, hierarchy))\n```\n\nto specify another role other than `root`, provide a third params to Policy consturctor\n\n```js\nnew Policy(policy, hierarchy, 'admin')\n```\n\n### attach extra data to user object\n\n```js\nlet user = new User(['role', 'elor'], policy, {id: req.session.id})\nconsole.log(user.id)\n```\n\n## koa middleware\n\n```js\nimport {User, Policy, can} from permitted\napp.use((ctx, next) =\u003e {\n    req.user = new User(req.session.roles, new Policy(policy, hierachy))\n    next()\n})\n\napp.get('/articles/:id', can('read', 'article'), ctx =\u003e {\n    // ...\n})\n```\n\n[npm-image]: https://img.shields.io/npm/v/permitted.svg?style=flat\n[npm-url]: https://npmjs.org/package/permitted\n[travis-image]: https://img.shields.io/travis/zweifisch/permitted.svg?style=flat\n[travis-url]: https://travis-ci.org/zweifisch/permitted\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fpermitted","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzweifisch%2Fpermitted","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzweifisch%2Fpermitted/lists"}