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.
pnpm add @niscorp/charterThe 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.
import { resolvePrincipal } from '@niscorp/charter';
const variants = ['programme.with-takings', 'programme.with-notes'];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.
const charter = {
member: { actions: ['programme'] },
usher: { actions: ['programme'], layouts: ['programme.with-notes'] },
manager: { extends: ['usher'], layouts: ['programme.with-takings'] },
};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.
for (const role of ['member', 'usher', 'manager']) {
console.log(role + ':', [...resolvePrincipal(charter, variants, [role], 'layouts')]);
}Run it.
No variant for a member, the notes for an usher, and both for a manager.
npx tsx variants.mtsmember: [] usher: [ 'programme.with-notes' ] manager: [ 'programme.with-notes', 'programme.with-takings' ]