{"id":22382354,"url":"https://github.com/jcoreio/roles-calc","last_synced_at":"2025-09-06T02:44:09.956Z","repository":{"id":39817508,"uuid":"129426998","full_name":"jcoreio/roles-calc","owner":"jcoreio","description":"Resolves whether a user can perform an action based on hierarchical roles","archived":false,"fork":false,"pushed_at":"2025-06-26T17:58:01.000Z","size":617,"stargazers_count":0,"open_issues_count":20,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-27T10:56:26.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-04-13T16:21:19.000Z","updated_at":"2025-06-26T17:57:18.000Z","dependencies_parsed_at":"2025-02-01T01:44:14.109Z","dependency_job_id":"ed0125dc-b5af-45bc-9648-d0303d156716","html_url":"https://github.com/jcoreio/roles-calc","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/jcoreio/roles-calc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Froles-calc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Froles-calc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Froles-calc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Froles-calc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/roles-calc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Froles-calc/sbom","scorecard":{"id":511748,"data":{"date":"2025-08-11","repo":{"name":"github.com/jcoreio/roles-calc","commit":"655438fb39668d863253c810fbd035f71fad83b8"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.1,"checks":[{"name":"Code-Review","score":0,"reason":"Found 1/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":3,"reason":"4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"20 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-rmvr-2pp2-xj38","Warn: Project is vulnerable to: GHSA-xx4v-prfh-6cgc","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5","Warn: Project is vulnerable to: GHSA-jv35-xqg7-f92r","Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T00:43:10.718Z","repository_id":39817508,"created_at":"2025-08-20T00:43:10.718Z","updated_at":"2025-08-20T00:43:10.718Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273850604,"owners_count":25179356,"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","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-12-05T00:12:41.160Z","updated_at":"2025-09-06T02:44:09.931Z","avatar_url":"https://github.com/jcoreio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# roles-calc\n\nResolves whether a user can perform an action based on hierarchical roles\n\n## Installation\n\n```sh\nyarn add @jcoreio/roles-calc\n```\n\nor\n\n```sh\nnpm install --save @jcoreio/roles-calc\n```\n\n## Usage\n\nA collection of roles can be specified in one of four ways:\n\n- An `Array` of role names\n- A `Set` of role names\n- An `Object` where the key is the role name and the value is `true` iff the user has the role\n- A single role name (`string`)\n\n`@jcoreio/roles-calc` exports `rolesToArray`, `rolesToSet`, `rolesToObject`,\nand `rolesToIterable` for converting between these forms.\n\n```js\nrolesToArray({ employee: true, manager: true, owner: false }) // ['employee', 'manager']\nrolesToObject(new Set(['employee', 'manager'])) // {employee: true, manager: true}\n```\n\n#### Calculate basic roles\n\n```js\nconst RolesCalc = require('@jcoreio/roles-calc')\n\nconst rc = new RolesCalc()\n\nrc.isAuthorized({ required: 'employee', actual: ['employee', 'manager'] }) // true\nrc.isAuthorized({ required: 'owner', actual: ['employee', 'manager'] }) // false\nrc.isAuthorized({ required: 'owner', actual: 'owner' }) // true, 'actual' can be a string or array\n```\n\n#### Calculate roles with simple inheritance\n\n```js\nconst rc = new RolesCalc()\nrc.role('owner').extends(['manager', 'employee'])\n\nrc.isAuthorized({ required: 'employee', actual: 'owner' }) // true, owner \u003e employee\nrc.isAuthorized({ required: 'manager', actual: 'owner' }) // true, owner \u003e manager\nrc.isAuthorized({ required: 'owner', actual: 'manager' }) // false, manager \u003c owner\n```\n\n#### Calculate roles with multi level inheritance\n\n```js\nconst rc = new RolesCalc()\nrc.role('manager').extends('employee')\nrc.role('owner').extends('manager')\n\nrc.isAuthorized({ required: 'employee', actual: 'owner' }) // true, owner \u003e manager \u003e employee\nrc.isAuthorized({ required: 'employee', actual: 'manager' }) // true, manager \u003e employee\nrc.isAuthorized({ required: 'owner', actual: 'manager' }) // false, manager \u003c owner\n```\n\n#### Always allow 'admin' or similar permissions\n\n```js\nconst rc = new RolesCalc({ alwaysAllow: 'admin' })\n\nrc.isAuthorized({ required: 'employee', actual: 'admin' }) // true, admin is always authorized\nrc.isAuthorized({ required: 'employee', actual: 'owner' }) // false, owner wasn't included in alwaysAllow\n```\n\n```js\nconst rc = new RolesCalc({ alwaysAllow: ['admin', 'owner'] })\n\nrc.isAuthorized({ required: 'employee', actual: 'admin' }) // true, admin is always authorized\nrc.isAuthorized({ required: 'employee', actual: 'owner' }) // true, owner is always authorized\n```\n\n#### `resource:action` roles\n\n```js\nconst rc = new RolesCalc({ resourceActions: true })\n\nrc.isAuthorized({ required: 'site:read', actual: 'site:write' }) // false writeExtendsRead option is not enabled\nrc.isAuthorized({ required: 'site:explode', actual: 'site' }) // true, a general 'resource' role extends all 'resource:action' roles\n```\n\n#### `writeExtendsRead` option for resources\n\n```js\nconst rc = new RolesCalc({ resourceActions: true, writeExtendsRead: true })\n\nrc.isAuthorized({ required: 'site:read', actual: 'site:write' }) // true, resource:write \u003e resource:read\nrc.isAuthorized({ required: 'site:explode', actual: 'site:write' }) // false, resource:write does not extend unrelated actions by default\nrc.isAuthorized({ required: 'site:explode', actual: 'site' }) // true, a general 'resource' role extends all 'resource:action' roles\n```\n\n#### Get set of all parent roles\n\n```js\nconst rc = new RolesCalc()\nrc.role('manager').extends('employee')\nrc.role('owner').extends('manager')\n\nrc.getParentRolesSet('employee') // 'owner', 'manager'\nrc.getRoleAndParentRolesSet('employee') // 'owner', 'manager', 'employee'\n```\n\n#### Prune redundant roles\n\n```js\nconst rc = new RolesCalc()\nrc.role('manager').extends('employee')\nrc.role('owner').extends('manager')\n\nrc.pruneRedundantRolesSet(['manager', 'employee']) // new Set(['manager'])\nrc.pruneRedundantRoles(['owner', 'manager', 'employee']) // ['owner']\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Froles-calc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Froles-calc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Froles-calc/lists"}