Charter · guides
How to do things with Charter.
Each guide is a file you can run, set in the theatre’s world. What it prints is what the installed package printed.
First steps.
A charter of three roles is verified, and the file prints what Linus can use, who is a member and an usher, and what the manager can.
pnpm add @niscorp/charternpx tsx first.mtsimport { resolvePrincipal, verifyCharter } from '@niscorp/charter';
const charter = {
member: ['programme', 'seats', 'me.*'],
usher: ['programme', 'door.*'],
manager: { extends: ['usher'], allow: ['*'], deny: ['me.*'] },
};
const actions = ['programme', 'seats', 'me.tickets', 'me.pass', 'door.list', 'takings'];
const report = verifyCharter(charter, { actions, data: [] });
if (report.errors.length > 0) throw new Error('charter is incoherent');
console.log(resolvePrincipal(charter, actions, ['member', 'usher']));
console.log(resolvePrincipal(charter, actions, ['manager']));Set(5) { 'programme', 'seats', 'me.tickets', 'me.pass', 'door.list' }
Set(4) { 'programme', 'door.list', 'seats', 'takings' }A charter is plain data, and resolving it is one call. The manager extends the usher, is allowed everything, and is denied me.*: the deny wins.
Then, one at a time.
Each is a file of its own and adds one thing. Read them in order, or go to the one you need.