{"id":26681298,"url":"https://github.com/slynova-org/fence","last_synced_at":"2025-04-12T12:35:04.446Z","repository":{"id":32690543,"uuid":"60535922","full_name":"Slynova-Org/fence","owner":"Slynova-Org","description":"🔰 Framework-agnostic package who provides powerful ACL abilities to JavaScript","archived":false,"fork":false,"pushed_at":"2023-09-05T15:17:30.000Z","size":386,"stargazers_count":65,"open_issues_count":13,"forks_count":6,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-04-11T20:08:45.057Z","etag":null,"topics":["acl","acl-abilities","framework-agnostic","javascript","nodejs","security"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Slynova-Org.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","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":"2016-06-06T14:46:37.000Z","updated_at":"2023-09-08T17:11:12.000Z","dependencies_parsed_at":"2024-06-18T22:54:56.664Z","dependency_job_id":"1683032d-68d4-4b18-8fc6-eed9195b8ae8","html_url":"https://github.com/Slynova-Org/fence","commit_stats":{"total_commits":116,"total_committers":6,"mean_commits":"19.333333333333332","dds":0.2068965517241379,"last_synced_commit":"9eb4a7509b7b6143174f6353b1fad9276b8f21d3"},"previous_names":["slynova-org/node-fence"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slynova-Org%2Ffence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slynova-Org%2Ffence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slynova-Org%2Ffence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Slynova-Org%2Ffence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Slynova-Org","download_url":"https://codeload.github.com/Slynova-Org/fence/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248567066,"owners_count":21125781,"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":["acl","acl-abilities","framework-agnostic","javascript","nodejs","security"],"created_at":"2025-03-26T07:15:15.585Z","updated_at":"2025-04-12T12:35:04.426Z","avatar_url":"https://github.com/Slynova-Org.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"fence\" src=\"https://user-images.githubusercontent.com/2793951/28426832-a49b1e36-6d74-11e7-906c-76de04742d39.png\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/Slynova-Org/fence\"\u003e\u003cimg src=\"https://img.shields.io/travis/Slynova-Org/fence/master.svg?style=flat-square\" alt=\"Build Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://coveralls.io/github/Slynova-Org/fence?branch=master\"\u003e\u003cimg src=\"https://img.shields.io/coveralls/Slynova-Org/fence/master.svg?style=flat-square\" alt=\"Coverage Status\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@slynova/fence\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@slynova/fence.svg?style=flat-square\" alt=\"Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/@slynova/fence\"\u003e\u003cimg src=\"https://img.shields.io/npm/dt/@slynova/fence.svg?style=flat-square\" alt=\"Downloads\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\u003cimg src=\"https://img.shields.io/npm/l/@slynova/fence.svg?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n`fence` is a framework-agnostic package which provides powerful ACL abilities to JavaScript.\u003cbr\u003e\nIt lets you easily manage ACL with a fluent API easy to learn and to work with. :rocket:\n\n\u003chr\u003e\n\u003cbr\u003e\n\n## Getting Started\n\nThis package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).\n\n```bash\n$ npm i @slynova/fence\n# or\n$ yarn add @slynova/fence\n```\n\nWhen you require the package in your file, it will give you access to the `Guard` and `Gate` class.\u003cbr\u003e\n\n```javascript\nconst { Gate, Guard } = require('@slynova/fence')\n```\n\n\u003cbr\u003e\n\n## Gate \u0026 Policy\n\nA `Gate` is a closure that returns a boolean to determine if the user is allowed to perform a certain action.\nInstead of using a closure, you can also write a `Policy`. Those are classes that let you organise your authorisation around a particular model or resource.\n\n### Writing a Gate\n\nTo define a new Gate you will need to call the `define` method on the `Gate` facade.\n\n```js\nGate.define('name-of-the-gate', async (user, resource) =\u003e {\n  // Payload\n  // e.g. return user.id === resource.author_id\n})\n```\n\n### Writing a Policy\n\nTo define a new Policy you will need to call the `policy` method on the `Gate` facade.\n\n```js\nGate.policy(post, PostPolicy)\n```\n\nThe first argument is the object you want to define the policy for. It can be a [simple JSON](https://github.com/Slynova-Org/node-fence/blob/master/tests/stubs/post.json) or an [ES2015 class](https://github.com/Slynova-Org/node-fence/blob/master/tests/stubs/Post.js).\n\nThe policy must be an [ES2015 class](https://github.com/Slynova-Org/node-fence/blob/master/tests/stubs/PostPolicy.js).\n\n\u003cbr\u003e\n\n## Guard\n\nThe `Guard` is the guardian of your gates.\n\nMost of the time, you'll want to use the authenticated user to test your gates. For this reason, `node-fence` let you use the method `Guard.setDefaultUser()`.\n\n```js\n// The user can be retrieve from the auth middleware you are using\nconst guard = Guard.setDefaultUser({ id: 1, username: 'romainlanz' })\n```\n\n### Public API\n\n```js\nguard.allows('gateName/Policy Method', resource) // It will use per default the defined user or return false if not defined\nguard.denies('gateName/Policy Method', resource) // It will use per default the defined user or return true if not defined\nguard.allows('gateName/Policy Method', resource, user)\nguard.denies('gateName/Policy Method', resource, user)\nguard.can(user).pass('gateName').for(resource)\nguard.can(user).callPolicy('Policy Method', resource)\n```\n\n\u003cbr\u003e\n\n## Contribution Guidelines\n\nAny pull requests or discussions are welcome.\u003cbr\u003e\nNote that every pull request providing a new feature or correcting a bug should be created with appropriate unit tests.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslynova-org%2Ffence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslynova-org%2Ffence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslynova-org%2Ffence/lists"}