Charter · guide

A variant of a screen

Two people open the same screen and one sees more on it. The richer layout is a name a role is granted.

Install it
pnpm add @niscorp/charter
Step 1 of 3

The variants that exist

The programme screen has a plain layout that everybody gets. The app also ships two richer layouts of it, each under a name of its own.

Those names are a third list, beside the screens and the table grants.

The variants that exist
import { resolvePrincipal } from '@niscorp/charter';

const variants = ['programme.with-takings', 'programme.with-notes'];
Step 2 of 3

Grant a variant

A role’s layouts selects from that list. An usher gets the stage notes. A manager extends the usher and also gets the takings.

A member is granted no variant, and that is the point: with none, they get the plain layout. A grant that somebody forgets shows a person less, never more.

Grant a variant
const charter = {
  member: { actions: ['programme'] },
  usher: { actions: ['programme'], layouts: ['programme.with-notes'] },
  manager: { extends: ['usher'], layouts: ['programme.with-takings'] },
};
Step 3 of 3

Resolve the same way

The same function, asked for the layouts section. Whoever builds the person’s app swaps in the layout of the variant they were granted. In Nisc that is Moss.

Resolve the same way
for (const role of ['member', 'usher', 'manager']) {
  console.log(role + ':', [...resolvePrincipal(charter, variants, [role], 'layouts')]);
}
Then

Run it.

No variant for a member, the notes for an usher, and both for a manager.

Run it
npx tsx variants.mts
It prints
member: []
usher: [ 'programme.with-notes' ]
manager: [ 'programme.with-notes', 'programme.with-takings' ]