https://github.com/chronark/access
E2E Typed Access Control
https://github.com/chronark/access
Last synced: about 1 year ago
JSON representation
E2E Typed Access Control
- Host: GitHub
- URL: https://github.com/chronark/access
- Owner: chronark
- License: mit
- Created: 2023-04-26T21:08:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-03T07:58:50.000Z (almost 3 years ago)
- Last Synced: 2025-07-19T04:41:35.454Z (about 1 year ago)
- Language: TypeScript
- Size: 133 KB
- Stars: 68
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
@chronark/access-*
E2E Typed Access Control
A minimal library for access control. It is designed to be used together with
opaque access tokens by providing a simple interface to define roles with
different access permissions and verifying requests to resources.
- Fully typed
- Zero dependencies
- Serializable to store in a database
## Install
```
npm i @chronark/access-policies
```
## Usage
```ts
type Resources = {
team: ["create", "invite" /* more */];
joke: ["create", "read", "vote"];
};
/**
* User or team id
*/
type TenantId = string;
/**
* Just some uuid
*/
type JokeId = string;
type ResourceIdentifier = `${TenantId}-${keyof Resources}-${JokeId}`;
/**
* Allow the policy owner to create jokes inside the vercel tenant
*/
const createJokesInVercel = new Policy({
resources: {
joke: {
"vercel-joke-*": ["create"],
},
},
});
/**
* Or
*
* Allow the policy owner to read and vote on all jokes across all tenants
*/
const readAndVoteJokesInAllTeams = new Policy({
resources: {
joke: {
"*-joke-*": ["read", "vote"],
},
},
});
/**
* Verifying a request
*/
const { valid, error } = readAndVoteJokesInAllTeams.validate("joke:read", "vercel-joke-jokeId")
```