@chronark/access
Simple 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
Usage
import { AccessControl, Role } from "@chronark/access";
type Statements = {
user: ["read", "write", "dance"];
team: ["read", "write"];
;
const ac = new AccessControl<Statements>();
const role = ac.newRole({
user: ["read", "write"],
team: ["read"],
});
const serialized = role.toString();
const recovered = Role.fromString<Statements>(serialized);
const res = recovered.authorize({"team", ["read"]});