{"id":22865554,"url":"https://github.com/tecfu/roleguard","last_synced_at":"2025-03-31T09:47:20.577Z","repository":{"id":44209540,"uuid":"209897730","full_name":"tecfu/roleguard","owner":"tecfu","description":"A role based acess control library that includes some extra features I couldn't find elsewhere.","archived":false,"fork":false,"pushed_at":"2022-12-30T18:42:08.000Z","size":60,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T14:32:08.635Z","etag":null,"topics":["rbac"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tecfu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-20T23:38:52.000Z","updated_at":"2020-08-14T04:56:52.000Z","dependencies_parsed_at":"2023-01-31T13:15:39.268Z","dependency_job_id":null,"html_url":"https://github.com/tecfu/roleguard","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/tecfu%2Froleguard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tecfu%2Froleguard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tecfu%2Froleguard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tecfu%2Froleguard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tecfu","download_url":"https://codeload.github.com/tecfu/roleguard/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246450403,"owners_count":20779406,"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":["rbac"],"created_at":"2024-12-13T11:37:36.760Z","updated_at":"2025-03-31T09:47:20.559Z","avatar_url":"https://github.com/tecfu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Roleguard\n\nA role based access control library with some unconventional options:\n\n- Add a conditional validation constraint to an access rule (facilitates more specificity than packages that limit access to roles and their granted actions).\n\n- Report which rule granted access.\n\n## Install\n\n```js\nnpm install https://github.com/tecfu/roleguard.git\n```\n\n### Example\n\n```js\nconst RoleGuard = require('@tecfu/roleguard')\n// or as ES6 module use\n// import RoleGuard from '@tecfu/roleguard'\n\nconst AccessRules = {\n  user: {\n    can: [\n      {\n        resource: 'chat',\n        actions: ['update'],\n        condition: (ctx) =\u003e {\n          // rule will only positive match if function returns boolean `true`\n          return ctx.request.body.id === ctx.state.jwt.sub.id\n        }\n      }\n    ]\n  }\n}\n\nconst abilities = RoleGuard(AccessRules)\nconst ctx = {\n  request: {\n    body: {\n      id: 2\n    }\n  },\n  state: {\n    jwt: {\n      sub: {\n        id: 2\n      }\n    }\n  }\n}\nconst test = abilities.can('update', 'chat', ['user'], ctx)\nconsole.log(test)\n\n//{\n//  can: true,\n//  message: 'user can update chat subject to rule condition',\n//  rule: {\n//    resource: 'chat',\n//    actions: [ 'update' ],\n//    condition: '(ctx) =\u003e {\\n' +\n//      '          return ctx.request.body.id === ctx.state.jwt.sub.id\\n' +\n//      '        }'\n//  },\n//  roles: [ 'user' ],\n//  requestedAction: 'update',\n//  requestedResource: 'chat'\n//}\n\n```\n\n## Test\n\n```\nnpm run-script test\n```\n\n## License\n\nGPL 3.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftecfu%2Froleguard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftecfu%2Froleguard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftecfu%2Froleguard/lists"}