{"id":19560099,"url":"https://github.com/plotdb/permcheck","last_synced_at":"2025-06-29T17:05:35.485Z","repository":{"id":79658052,"uuid":"238188345","full_name":"plotdb/permcheck","owner":"plotdb","description":null,"archived":false,"fork":false,"pushed_at":"2020-06-15T05:12:31.000Z","size":271,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T11:02:31.942Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","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/plotdb.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-04T11:17:53.000Z","updated_at":"2020-06-15T05:12:33.000Z","dependencies_parsed_at":"2023-05-14T07:00:34.699Z","dependency_job_id":null,"html_url":"https://github.com/plotdb/permcheck","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/plotdb/permcheck","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fpermcheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fpermcheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fpermcheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fpermcheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plotdb","download_url":"https://codeload.github.com/plotdb/permcheck/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plotdb%2Fpermcheck/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262632335,"owners_count":23340214,"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":"2024-11-11T05:05:56.289Z","updated_at":"2025-06-29T17:05:35.473Z","avatar_url":"https://github.com/plotdb.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# permcheck\n\nPermission Control\n\n\n## Spec\n\npermcheck specifies the action level of a certain role over certain permission:\n\n```\n    permcheck({role, perm, action})\n      .then( ... )\n      .catch( ... );\n```\n\n### role\n\n`role` provides information of the attributes of a certain instance, such as an user. For example, assume an user with key `1` is a member of team `1`, `2`, `3` and access certain resource with a token `a`, then the `role` will be:\n\n```\n    {\n      user: [1]\n      team: [1,2,3]\n      token: [\"a\"]\n    }\n```\n \n### perm - by action level\n\nIn the meanwhile, the requested resource contains permission information for controlling access to it. It will be an object in following format:\n\n```\n    {\n      list: [\n        {type: \"...\", key: \"...\", action: \"...\"},\n        ...\n      ]\n    }\n```\n\nEach entry in the list contains following fields:\n\n * type - can be `user`, `team`, `token` or any string defined by user, or `null` to apply to any request.\n * key - primary key for certain type.\n * action - what kind of action does this entry grant. could be user defined or one of following:\n   - list: can access metadata of this resource.\n   - read: can read full content of this resource.\n   - write: can modify content of this resource.\n   - admin: full control ( delete )\n\nFor default actions, admin action is by default can write, write action is by default can read, etc.\n\n### perm - by action type\n\n```\n    {\n      name: 'optional-group-name',\n      list: [\n        {type: \"...\", key: \"...\"},\n        ...\n      ]\n      config: { ... }\n    }\n```\n\nAdditionally, if config is supplied within the perm object, permcheck will instead check if\n\n * `role` matches any entry in `list`\n * action is true in `config`.\n\n`config` is an object with actions as each of its key.\n\nIf `perm` is an array, then permission should be granted if `role` matches any of the permission matched.\n\n\n## Usage\n\nTo check permission for specific role over certain resource, prepare both `role` and `perm` object, and check for desired action:\n\n```\n    permcheck({role, perm, action})\n      .then( ... )   # action granted\n      .catch( ... ); # action denied\n```\n\n`action` could be an array ( for checking multiple actions ) or a simple string:\n\n```\n    permcheck({role, perm, action: [\"read\", \"fork\"]});\n```\n\nYou can also ignore the `action` parameter at all for listing all granted actions for certain object:\n\n```\n    permcheck({role, perm}).then(function(actionList) { ... });\n```\n\nAll available actions will be listed as strings ( above `actionList` argument ) with Promise.\n\n\n### Multiple Permission Sets\n\nYou can combine multiple permission objects to make it easier to check through different set of permission rules:\n\n```\n    permcheck({role, perm: [perm1, perm2]}).then( ... );\n```\n\nFor example, following example controls permission with a per-object permission and per-type permission:\n\n```\n    require(\"perms\");\n    objperm = {\n      list: [\n        {action: 'list'},\n        {type: 'user', key: 1, action: 'read'},\n      ]\n    };\n    role = {\n      user: [2],\n      role: [\"reviewer\"]\n    };\n    permcheck({role, perm: [objperm, perms.article]}).then( ... );\n```\n\nwhere perms can be a hardcoded file with following content:\n\n```\n    module.exports {\n      article: {\n        list: [\n          {'type': 'role', 'key': 'admin', action: 'admin'},\n          {'type': 'role', 'key': 'owner', action: 'admin'}\n          {'type': 'role', 'key': 'reviewer', action: 'comment'}\n        ]\n      }\n    };\n```\n\n\n## Compatibility\n\npermcheck uses following modern APIs and thus might need polyfill for using in older browsers:\n\n * Array.isArray\n * Promise\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fpermcheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplotdb%2Fpermcheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplotdb%2Fpermcheck/lists"}