@niscorp/charter 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @niscorp/charter
2
2
 
3
+ ## 0.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - febd8b7: The docs cover the `functions` section: what it selects, which checks run on it (no leaves-only), and that moss enforces it.
8
+
9
+ **What to change:** nothing. Documentation only.
10
+
11
+ ## 0.1.4
12
+
13
+ ### Patch Changes
14
+
15
+ - 9e6a7c3: The charter decides which of an app's functions a principal may call. **Breaking.**
16
+
17
+ BREAKING — approved by moccadroid, 2026-10-14: give every role of the charter a `functions` part, the functions its actions call, or `functions: ['*']` to keep calling all of them; a role written as a list (`member: ['home', 'settings']`) becomes `member: { actions: ['home', 'settings'], functions: [...] }`.
18
+ - **A shell holds only the functions its principal's roles grant** (`functions`, beside `actions`, `data` and `layouts`, with the same globs, `extends` and `deny`). A role with no `functions` may call none. Before, every shell held every function. A living shell follows the roles an adopt answers, as its actions do.
19
+ - **The boot is refused, with the list of what to grant**, where a role on its own, a combination people wear, or `public` holds an action (or the shells ship a fragment) that calls a function its grants miss: `"member" hold "chrome.topbar", which calls "auth.leave": their functions do not grant it`. A name with a template in it is decided when it is called.
20
+ - **`'*'` is said at boot**: `role "member" allows every function ('*'): the generated actions of the people who hold it, or a role that extends it, may call any it does not deny`.
21
+ - **A grant that names no function** (a typo) is said at the first shell a process builds, with a deny that matches nothing and a function no role grants: the names of the app's functions are known once `functions(session)` has run, and are read as that first session's.
22
+ - **A generated action or fragment may call a function its owner's roles grant**, named written out; one they do not grant is refused when it is saved and left out when a shell is built. `session.functions()` lists the functions a session may call, `{ id, description? }`, for the model that writes one.
23
+ - `@niscorp/charter` has the `functions` section, and `verifyCharter` checks it where a `functions` universe is handed in.
24
+
25
+ For whoever upgrades an app, person or agent: boot it. The refusal lists, per role combination, each function an action calls that the charter does not grant. Add those names to the `functions` of the role that holds the action, or `['*']` to the roles whose people may call everything. This is the app's permissions table: write it deliberately, and do not generate it.
26
+
3
27
  ## 0.1.3
4
28
 
5
29
  ### Patch Changes
package/DESIGN.md CHANGED
@@ -172,12 +172,14 @@ glob.
172
172
 
173
173
  ## Sections
174
174
 
175
- A `Section` is `'actions' | 'data' | 'layouts'` — each a universe. `actions`
176
- selects Nova action ids; `data` selects `table.verb` capabilities; `layouts`
177
- selects layout-variant ids (ring 2). The sugar keeps the common role terse: a
175
+ A `Section` is `'actions' | 'data' | 'layouts' | 'functions'` — each a
176
+ universe. `actions` selects Nova action ids; `data` selects `table.verb`
177
+ capabilities; `layouts` selects layout-variant ids (ring 2); `functions` selects
178
+ the names of the app's functions. The sugar keeps the common role terse: a
178
179
  bare `string[]` is an actions-only role, and top-level `allow`/`deny` are the
179
180
  `actions` section (so an actions-only role never names a section). Explicit
180
- `actions:`/`data:`/`layouts:` selections address each universe directly. Having
181
+ `actions:`/`data:`/`layouts:`/`functions:` selections address each universe
182
+ directly. Having
181
183
  *both* the sugar and an explicit `actions:` on one role is the
182
184
  `ambiguous-selection` error — resolution would silently drop one.
183
185
 
@@ -193,7 +195,9 @@ and the verifier all run per section against the right universe — one matcher,
193
195
  one resolver, one set of lints, reused. **Adding a governed surface is adding a
194
196
  `Section` value, a universe, and a compiler in the *target* — never a grammar
195
197
  change here.** The `layouts` section was exactly that: one enum value, moss
196
- hands the universe in, moss compiles it to substituted layouts.
198
+ hands the universe in, moss compiles it to substituted layouts. So was
199
+ `functions`: moss hands each shell only the functions its principal's roles
200
+ select.
197
201
 
198
202
  ---
199
203
 
@@ -216,6 +220,7 @@ two:
216
220
  | `actions` | action ids | the action map, filtered by ids | Nova's shell |
217
221
  | `data` | `SCOPE_VERBS` leaves (`deals.write.insert`) | `createScopePolicy(grants, behaviors, scoping)` | Vex |
218
222
  | `layouts` | variant ids | substitute the variant's layout on the definition | moss / Nova |
223
+ | `functions` | function names | a call is allowed when its name is in the resolved set | moss |
219
224
  | (future) | tool names | a `ToolPolicy` constructor | Cortex's `policyGate` |
220
225
 
221
226
  Each side stays pure and standalone: the charter is a string-set engine always
package/DOCS.md CHANGED
@@ -26,6 +26,7 @@ type RoleDef =
26
26
  actions?: Selection; // the actions universe
27
27
  data?: Selection; // the data universe
28
28
  layouts?: Selection; // the layouts universe
29
+ functions?: Selection; // the app's functions this role may call
29
30
  scoping?: string; // how far this role reaches (see below)
30
31
  };
31
32
  ```
@@ -94,12 +95,13 @@ Within a section: a bare glob list (sugar for `{ allow }`) or explicit
94
95
  ### `Section`
95
96
 
96
97
  ```typescript
97
- type Section = 'actions' | 'data' | 'layouts';
98
+ type Section = 'actions' | 'data' | 'layouts' | 'functions';
98
99
  ```
99
100
 
100
101
  Which universe a selection resolves in. `actions` selects Nova action ids,
101
102
  `data` selects `table.verb` capabilities, `layouts` selects layout-variant ids
102
- (ring 2 — moss's dialect).
103
+ (ring 2 — moss's dialect), `functions` selects the names of the app's
104
+ functions (moss's too). A role with no `functions` may call none.
103
105
 
104
106
  ---
105
107
 
@@ -163,11 +165,13 @@ catches these and reports them as `resolution` errors rather than throwing.
163
165
  Run every coherence check, per section, against that section's universe. Call
164
166
  at boot/CI; refuse to serve if `report.errors` is non-empty.
165
167
 
166
- - `universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[] }`
168
+ - `universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[]; functions?: readonly string[] }`
167
169
  — the id sets each section resolves against, handed in by the composer. The
168
170
  `layouts` universe is optional: absent, the section is inert (a charter's
169
171
  `layouts` keys resolve against nothing and are not verified); handed in, its
170
172
  dead-deny/dead-allow/orphan/leaves-only checks run like any other section.
173
+ So is `functions`, with the dead-deny, dead-allow and orphan checks;
174
+ leaves-only runs only on `actions` and `layouts`.
171
175
  - `wearable?: readonly (readonly string[])[]` — the role combinations a principal
172
176
  may wear, one entry per combination (not one per person). Defaults to `[]`.
173
177
  Read only by the `subtractive-assigned` check. A composer that has an
@@ -205,11 +209,11 @@ type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: s
205
209
  | rule | level | meaning |
206
210
  |---|---|---|
207
211
  | `resolution` | error | a cycle or unknown-role reference (per section) |
208
- | `leaves-only` | error | an id is a namespace of another id — namespaces are never actions (checked in the `actions` universe, and in `layouts` when handed in; not in `data`) |
212
+ | `leaves-only` | error | an id is a namespace of another id — namespaces are never actions (checked in the `actions` universe, and in `layouts` when handed in; not in `data` or `functions`) |
209
213
  | `ambiguous-selection` | error | a role has both top-level `allow`/`deny` and an explicit `actions:` |
210
214
  | `dead-deny` | error | a deny glob matches nothing — silent means unprotected |
211
215
  | `dead-allow` | warning | an allow glob matches nothing — noise |
212
- | `orphan` | warning | an action (or, when `layouts` is handed in, a layout variant) granted by no role — deployed but unreachable. An ungranted `data` id is not reported |
216
+ | `orphan` | warning | an action (or, when handed in, a layout variant or a function) granted by no role — deployed but unreachable. An ungranted `data` id is not reported |
213
217
  | `re-allow` | warning | a role re-allows an id an ancestor denied |
214
218
  | `subtractive-assigned` | warning | a role used in `without` also appears in a `wearable` combination |
215
219
  | *(closure)* | via `RoleClosure.issues` | cross-action wiring problems from the injected auditor |
package/README.md CHANGED
@@ -42,7 +42,7 @@ if (report.errors.length > 0) throw new Error('charter is incoherent');
42
42
 
43
43
  ## What it is
44
44
 
45
- - **Universe-blind.** `resolvePrincipal(charter, universe, roles, section)` runs the same resolution against any universe. `actions` selects Nova action ids; `data` selects `table.verb` capabilities (the vex-policy dialect); `layouts` selects layout-variant ids (ring 2 — moss's dialect: which variant of an action's layout a principal is served). Adding a governed domain is adding a universe, never new grammar.
45
+ - **Universe-blind.** `resolvePrincipal(charter, universe, roles, section)` runs the same resolution against any universe. `actions` selects Nova action ids; `data` selects `table.verb` capabilities (the vex-policy dialect); `layouts` selects layout-variant ids (ring 2 — moss's dialect: which variant of an action's layout a principal is served); `functions` selects the names of the app's functions a principal may call. Adding a governed domain is adding a universe, never new grammar.
46
46
  - **A small algebra.** `resolved(role) = (∪ extends ∪ match(allow)) − match(deny) − ∪ without`. Order-independent, deny wins within a role, denies don't inherit. Roles compose whole roles; each section resolves independently.
47
47
  - **Reach is named, not composed.** A role may carry `scoping` — a name the governed target resolves (vex: which scope behaviors apply). Unlike every section it is not inherited through `extends`: `resolveScoping(charter, role)` is that role's own answer or none, and a principal with several roles is resolved one role at a time.
48
48
  - **One glob rule.** `*` matches any run of characters including dots — `crm.*` matches `crm.deal.form`. No `**`, no braces, no regex. When a pattern can't be expressed, the fix is a better id.
@@ -50,6 +50,6 @@ if (report.errors.length > 0) throw new Error('charter is incoherent');
50
50
 
51
51
  ## What it is not
52
52
 
53
- It does not enforce, store documents, or know about HTTP, databases, or your app. The charter and the assignment rows are the **app's** artifacts. Enforcement is the governed target's job — vex compiles the resolved `data` set into a scope policy; a shell mounts only the resolved `actions`. Charter resolves and refuses; it never runs at request time.
53
+ It does not enforce, store documents, or know about HTTP, databases, or your app. The charter and the assignment rows are the **app's** artifacts. Enforcement is the governed target's job — vex compiles the resolved `data` set into a scope policy; a shell mounts only the resolved `actions`; moss lets a principal call only the resolved `functions`. Charter resolves and refuses; it never runs at request time.
54
54
 
55
55
  See [DESIGN.md](DESIGN.md) for the thesis and [DOCS.md](DOCS.md) for the full API.
package/dist/index.cjs CHANGED
@@ -60,16 +60,22 @@ var resolvePrincipal = (charter, universe, roles, section = "actions") => {
60
60
  // src/verify.ts
61
61
  var verifyCharter = (charter, universes, wearable = [], closure) => {
62
62
  const actionUniverse = universes.actions;
63
- const sections = universes.layouts === void 0 ? ["actions", "data"] : ["actions", "data", "layouts"];
63
+ const sections = [
64
+ "actions",
65
+ "data",
66
+ ...universes.layouts === void 0 ? [] : ["layouts"],
67
+ ...universes.functions === void 0 ? [] : ["functions"]
68
+ ];
64
69
  const universeOf = {
65
70
  actions: universes.actions,
66
71
  data: universes.data,
67
- layouts: universes.layouts ?? []
72
+ layouts: universes.layouts ?? [],
73
+ functions: universes.functions ?? []
68
74
  };
69
75
  const errors = [];
70
76
  const warnings = [];
71
77
  const perRole = [];
72
- const resolved = { actions: /* @__PURE__ */ new Map(), data: /* @__PURE__ */ new Map(), layouts: /* @__PURE__ */ new Map() };
78
+ const resolved = { actions: /* @__PURE__ */ new Map(), data: /* @__PURE__ */ new Map(), layouts: /* @__PURE__ */ new Map(), functions: /* @__PURE__ */ new Map() };
73
79
  for (const section of sections) {
74
80
  const memo = /* @__PURE__ */ new Map();
75
81
  for (const role of Object.keys(charter)) {
@@ -122,6 +128,7 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
122
128
  };
123
129
  orphans("actions", "action");
124
130
  if (universes.layouts !== void 0) orphans("layouts", "layout variant");
131
+ if (universes.functions !== void 0) orphans("functions", "function");
125
132
  const ancestorDenied = (role, section, seen = /* @__PURE__ */ new Set()) => {
126
133
  const out = /* @__PURE__ */ new Set();
127
134
  const def = charter[role];
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/glob.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";;;AAIA,IAAM,eAAe,CAAC,CAAA,KAAsB,CAAA,CAAE,OAAA,CAAQ,uBAAuB,MAAM,CAAA;AAEnF,IAAM,WAAW,CAAC,OAAA,KAA4B,IAAI,MAAA,CAAO,IAAI,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAI,YAAY,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,CAAA;AAExG,IAAM,SAAA,GAAY,CAAC,OAAA,EAAiB,EAAA,KAAwB,SAAS,OAAO,CAAA,CAAE,KAAK,EAAE;AAGrF,IAAM,QAAA,GAAW,CAAC,QAAA,EAA6B,GAAA,KAAwC;AAC5F,EAAA,MAAM,GAAA,uBAAU,GAAA,EAAY;AAC5B,EAAA,KAAA,MAAW,WAAW,QAAA,EAAU;AAC9B,IAAA,MAAM,EAAA,GAAK,SAAS,OAAO,CAAA;AAC3B,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,IAAI,EAAA,CA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K;AAC7D,IAAA,MAAM,MAAA,GAAS,OAAA,GAAU,OAAA,EAAS,OAAO,KAAK,EAAC;AAC/C,IAAA,OAAA,CAAQ,KAAK,EAAE,IAAA,EAAM,SAAS,IAAA,EAAM,OAAA,EAAS,QAAQ,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,OAAA,EAAQ;AACrC","file":"index.cjs","sourcesContent":["// One wildcard rule, no more: `*` matches any run of characters, including\n// dots — `crm.*` matches `crm.deal.form`. No `**`, no braces, no regex. The\n// day a pattern cannot be expressed, the answer is a better id, not a\n// richer glob.\nconst escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst toRegExp = (pattern: string): RegExp => new RegExp(`^${pattern.split('*').map(escapeRegExp).join('.*')}$`);\n\nexport const matchGlob = (pattern: string, id: string): boolean => toRegExp(pattern).test(id);\n\n// Every id the pattern list selects out of `ids`.\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) {\n const re = toRegExp(pattern);\n for (const id of ids) if (re.test(id)) out.add(id);\n }\n return out;\n};\n","import type { Charter, RoleDef, Section, Selection } from './types';\nimport { matchAll } from './glob';\n\n// Resolution is a pure function from (charter, universe, section) to a\n// concrete id set per role — the algebra from DESIGN.md § The algebra,\n// verbatim, per section:\n//\n// resolved(role) = (∪ resolved(extends) ∪ match(allow))\n// − match(deny)\n// − ∪ resolved(without)\n//\n// The engine is UNIVERSE-BLIND: it resolves globs over opaque strings and\n// never learns what a string means. `actions` and `data` run the SAME code\n// against different universes. Order-independent (all subtraction is\n// set-minus); deny wins within a role; denies do NOT inherit (a child may\n// re-add what a parent denied — the verifier flags it); cycles and unknown\n// references are errors.\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\n// NOTE deliberately absent: the engine never MANUFACTURES a universe — it is\n// always handed one. The data universe's atoms are the governed target's own\n// dialect (vex exports `SCOPE_VERBS` and `scopeGrants(tables)`); the app\n// wiring derives it and passes it in. That keeps this module free of any\n// foreign import, in either direction.\n\nconst asSelection = (s: Selection | undefined): { allow: string[]; deny: string[] } =>\n s === undefined ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };\n\n// A role's atoms for ONE section, plus its role-level composition (shared\n// across sections). A bare array is an actions-only role; top-level\n// `allow`/`deny` are sugar for the `actions` section.\nexport const normalizeRole = (\n def: RoleDef,\n section: Section,\n): { allow: string[]; deny: string[]; extends: string[]; without: string[] } => {\n if (Array.isArray(def)) {\n return section === 'actions'\n ? { allow: def, deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const composition = { extends: def.extends ?? [], without: def.without ?? [] };\n // Actions: explicit `actions:` wins, else the top-level allow/deny sugar.\n const sel =\n section === 'actions' && def.actions === undefined\n ? { allow: def.allow ?? [], deny: def.deny ?? [] }\n : asSelection(def[section]);\n return { ...sel, ...composition };\n};\n\nexport const resolveRole = (\n charter: Charter,\n universe: readonly string[],\n role: string,\n section: Section,\n memo: Map<string, ReadonlySet<string>> = new Map(),\n visiting: Set<string> = new Set(),\n): ReadonlySet<string> => {\n const cached = memo.get(role);\n if (cached !== undefined) return cached;\n const def = charter[role];\n if (def === undefined) throw new CharterError(`Unknown role \"${role}\"`);\n if (visiting.has(role)) throw new CharterError(`Role cycle through \"${role}\"`);\n visiting.add(role);\n\n const { allow, extends: parents, deny, without } = normalizeRole(def, section);\n const resolved = new Set<string>();\n for (const parent of parents) for (const id of resolveRole(charter, universe, parent, section, memo, visiting)) resolved.add(id);\n for (const id of matchAll(allow, universe)) resolved.add(id);\n for (const id of matchAll(deny, universe)) resolved.delete(id);\n for (const sub of without) for (const id of resolveRole(charter, universe, sub, section, memo, visiting)) resolved.delete(id);\n\n visiting.delete(role);\n memo.set(role, resolved);\n return resolved;\n};\n\n// A principal wears roles; a section's grant is the union of their resolved\n// sets in that section's universe.\n// The reach a ROLE was given: the profile it names, or none.\n//\n// SINGULAR ON PURPOSE. This took a list of roles and refused when two of them\n// named different profiles — \"incoherence rather than a precedence puzzle,\n// refused in the same spirit as two granted layout variants for one action.\"\n// That analogy was wrong. Two layout variants for one action genuinely conflict,\n// because a screen renders one of them; two roles naming different reaches is\n// somebody who teaches at a studio AND trains there, which is a person, not a\n// contradiction.\n//\n// A caller who holds several roles resolves each one separately and merges the\n// results (vex: `mergeScopePolicies`). That is where \"holding two roles\" is\n// decided, and it belongs there — reach is a property of a role, so a function\n// handed several of them has no answer to give, only a choice to refuse.\nexport const resolveScoping = (charter: Charter, role: string): string | undefined => {\n const def = charter[role];\n return def === undefined || Array.isArray(def) ? undefined : def.scoping;\n};\n\nexport const resolvePrincipal = (\n charter: Charter,\n universe: readonly string[],\n roles: readonly string[],\n section: Section = 'actions',\n): Set<string> => {\n const memo = new Map<string, ReadonlySet<string>>();\n const out = new Set<string>();\n for (const role of roles) for (const id of resolveRole(charter, universe, role, section, memo)) out.add(id);\n return out;\n};\n","import type { Charter, Section } from './types';\nimport { matchAll } from './glob';\nimport { CharterError, normalizeRole, resolveRole } from './resolve';\n\n// ═══════════════════════════════════════════════════════════\n// The verifier — the other half of the charter (DESIGN.md § The verifier\n// is the other half). The grammar\n// stays small; the opinions live here. Boot/CI runs it and refuses an\n// incoherent charter: \"if it boots, it's coherent.\"\n//\n// Every check runs PER SECTION against that section's universe. Like the\n// resolver, the verifier is universe-blind: every universe is HANDED IN\n// (the atoms are each governed target's own dialect — nova action ids, vex\n// verb leaves), and the per-role closure audit is an injected hook (nova\n// exports one), so this module imports nothing. Severities are asymmetric\n// on purpose: a dead DENY is an error (a typo'd deny fails silent, and\n// silent means unprotected); a dead allow is a warning.\n// ═══════════════════════════════════════════════════════════\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; issues: string[] };\n\nexport type VerifyReport = { errors: VerifyIssue[]; warnings: VerifyIssue[]; perRole: RoleClosure[] };\n\n// The per-role closure audit: given a role's granted action ids (and, when\n// the app governs layouts, its granted layout-variant ids), report the\n// cross-action wiring problems inside that closure (targets that aren't in\n// it, channels nobody serves). The consumer that OWNS actions provides it —\n// moss builds one from nova's audit, substituting granted variants so the\n// closure sees each role's EFFECTIVE definitions.\nexport type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];\n\nexport const verifyCharter = (\n charter: Charter,\n universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[] },\n // THE ROLE COMBINATIONS A PRINCIPAL MAY WEAR — one entry per combination, not\n // one per person. The only rule below that reads it (`subtractive-assigned`)\n // wants the set of roles somebody actually holds, and a population is a very\n // expensive way to spell a set. A composer that still holds an assignment map\n // passes `Object.values(map)`; one that declares its combinations passes them.\n wearable: readonly (readonly string[])[] = [],\n closure?: ClosureAuditor,\n): VerifyReport => {\n const actionUniverse = universes.actions;\n // The layouts section is verified only when the composer governs layouts\n // (hands a universe in) — absent, a charter's `layouts` keys are inert\n // here exactly as they are in resolution against an empty universe.\n const sections: Section[] = universes.layouts === undefined ? ['actions', 'data'] : ['actions', 'data', 'layouts'];\n const universeOf: Record<Section, readonly string[]> = {\n actions: universes.actions,\n data: universes.data,\n layouts: universes.layouts ?? [],\n };\n\n const errors: VerifyIssue[] = [];\n const warnings: VerifyIssue[] = [];\n const perRole: RoleClosure[] = [];\n\n // Resolve every role in every section up front (also surfaces cycles /\n // unknown references, per section).\n const resolved: Record<Section, Map<string, ReadonlySet<string>>> = { actions: new Map(), data: new Map(), layouts: new Map() };\n for (const section of sections) {\n const memo = new Map<string, ReadonlySet<string>>();\n for (const role of Object.keys(charter)) {\n try {\n resolved[section].set(role, resolveRole(charter, universeOf[section], role, section, memo));\n } catch (e) {\n errors.push({ level: 'error', rule: 'resolution', detail: `${section}: ${e instanceof CharterError ? e.message : String(e)}` });\n }\n }\n }\n\n // ── ids are leaves; namespaces are never actions. Same rule inside the\n // layouts universe — a variant id is never a namespace of another ──\n const leavesOnly = (universe: readonly string[], kind: string): void => {\n for (const a of universe) {\n for (const b of universe) {\n if (b.startsWith(`${a}.`)) {\n errors.push({ level: 'error', rule: 'leaves-only', detail: `id \"${a}\" is a namespace of \"${b}\" — namespaces are never ${kind}` });\n break;\n }\n }\n }\n };\n leavesOnly(actionUniverse, 'actions');\n if (universes.layouts !== undefined) leavesOnly(universes.layouts, 'variants');\n\n // ── one selection per section: top-level allow/deny (the actions sugar)\n // AND an `actions` key on the same role means resolution silently drops\n // the sugar — silent means wrong, so boot refuses ──\n for (const [role, def] of Object.entries(charter)) {\n if (Array.isArray(def)) continue;\n if (def.actions !== undefined && (def.allow !== undefined || def.deny !== undefined)) {\n errors.push({ level: 'error', rule: 'ambiguous-selection', detail: `role \"${role}\" has both top-level allow/deny and an \"actions\" section — one selection per section` });\n }\n }\n\n // ── dead deny = error, dead allow = warning; per glob, per role, per section ──\n for (const section of sections) {\n for (const [role, def] of Object.entries(charter)) {\n const { allow, deny } = normalizeRole(def, section);\n for (const glob of deny) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n errors.push({ level: 'error', rule: 'dead-deny', detail: `role \"${role}\" denies \"${glob}\" (${section}) which matches nothing — silent means unprotected` });\n }\n }\n for (const glob of allow) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n warnings.push({ level: 'warning', rule: 'dead-allow', detail: `role \"${role}\" allows \"${glob}\" (${section}) which matches nothing` });\n }\n }\n }\n }\n\n // ── orphans: matched by no role at all. Actions and layout variants share\n // the rule — both are deployed-but-unreachable artifacts. An ungranted\n // data phase is simply denied, not a mistake ──\n const orphans = (section: Section, kind: string): void => {\n const reachable = new Set<string>();\n for (const set of resolved[section].values()) for (const id of set) reachable.add(id);\n for (const id of universeOf[section]) {\n if (!reachable.has(id)) warnings.push({ level: 'warning', rule: 'orphan', detail: `${kind} \"${id}\" is granted by no role — deployed but unreachable` });\n }\n };\n orphans('actions', 'action');\n if (universes.layouts !== undefined) orphans('layouts', 'layout variant');\n\n // ── re-allow of an ancestor's deny (F1), per section ──\n const ancestorDenied = (role: string, section: Section, seen: Set<string> = new Set()): Set<string> => {\n const out = new Set<string>();\n const def = charter[role];\n if (def === undefined || seen.has(role)) return out;\n seen.add(role);\n for (const parent of normalizeRole(def, section).extends) {\n const parentDef = charter[parent];\n if (parentDef === undefined) continue;\n for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);\n for (const id of ancestorDenied(parent, section, seen)) out.add(id);\n }\n return out;\n };\n for (const section of sections) {\n for (const [role, set] of resolved[section]) {\n for (const id of ancestorDenied(role, section)) {\n if (set.has(id)) {\n warnings.push({ level: 'warning', rule: 're-allow', detail: `role \"${role}\" re-allows \"${id}\" (${section}) which an ancestor denied` });\n }\n }\n }\n }\n\n // ── a role referenced in `without` that principals also wear (F2) ──\n const subtractive = new Set<string>();\n for (const def of Object.values(charter)) {\n if (Array.isArray(def)) continue;\n for (const sub of def.without ?? []) subtractive.add(sub);\n }\n const worn = new Set(wearable.flat());\n for (const role of subtractive) {\n if (worn.has(role)) {\n warnings.push({ level: 'warning', rule: 'subtractive-assigned', detail: `role \"${role}\" is referenced in \"without\" but is also assigned to a principal` });\n }\n }\n\n // ── per-role closure: the action-catalog audit (cross-action wiring),\n // fed the role's granted variants so it audits EFFECTIVE definitions ──\n for (const role of Object.keys(charter)) {\n const actions = [...(resolved.actions.get(role) ?? [])].sort();\n const data = [...(resolved.data.get(role) ?? [])].sort();\n const layouts = [...(resolved.layouts.get(role) ?? [])].sort();\n const issues = closure?.(actions, layouts) ?? [];\n perRole.push({ role, actions, data, layouts, issues });\n }\n\n return { errors, warnings, perRole };\n};\n"]}
1
+ {"version":3,"sources":["../src/glob.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";;;AAAA,IAAM,eAAe,CAAC,CAAA,KAAsB,CAAA,CAAE,OAAA,CAAQ,uBAAuB,M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QAAA,CAAS,MAAM,CAAA;AACpC,EAAA,KAAA,MAAW,QAAQ,WAAA,EAAa;AAC9B,IAAA,IAAI,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA,EAAG;AAClB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,KAAA,EAAO,SAAA,EAAW,IAAA,EAAM,wBAAwB,MAAA,EAAQ,CAAA,MAAA,EAAS,IAAI,CAAA,gEAAA,CAAA,EAAoE,CAAA;AAAA,IAC3J;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,IAAA,IAAQ,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA,EAAG;AACvC,IAAA,MAAM,OAAA,GAAU,CAAC,GAAI,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA,IAAK,EAAG,CAAA,CAAE,IAAA,EAAK;AAC7D,IAAA,MAAM,IAAA,GAAO,CAAC,GAAI,QAAA,CAAS,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA,IAAK,EAAG,CAAA,CAAE,IAAA,EAAK;AACvD,IAAA,MAAM,OAAA,GAAU,CAAC,GAAI,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA,IAAK,EAAG,CAAA,CAAE,IAAA,EAAK;AAC7D,IAAA,MAAM,MAAA,GAAS,OAAA,GAAU,OAAA,EAAS,OAAO,KAAK,EAAC;AAC/C,IAAA,OAAA,CAAQ,KAAK,EAAE,IAAA,EAAM,SAAS,IAAA,EAAM,OAAA,EAAS,QAAQ,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,OAAA,EAAQ;AACrC","file":"index.cjs","sourcesContent":["const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst toRegExp = (pattern: string): RegExp => new RegExp(`^${pattern.split('*').map(escapeRegExp).join('.*')}$`);\n\nexport const matchGlob = (pattern: string, id: string): boolean => toRegExp(pattern).test(id);\n\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) {\n const re = toRegExp(pattern);\n for (const id of ids) if (re.test(id)) out.add(id);\n }\n return out;\n};\n","import type { Charter, RoleDef, Section, Selection } from './types';\nimport { matchAll } from './glob';\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\nconst asSelection = (s: Selection | undefined): { allow: string[]; deny: string[] } =>\n s === undefined ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };\n\nexport const normalizeRole = (\n def: RoleDef,\n section: Section,\n): { allow: string[]; deny: string[]; extends: string[]; without: string[] } => {\n if (Array.isArray(def)) {\n return section === 'actions'\n ? { allow: def, deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const composition = { extends: def.extends ?? [], without: def.without ?? [] };\n const sel =\n section === 'actions' && def.actions === undefined\n ? { allow: def.allow ?? [], deny: def.deny ?? [] }\n : asSelection(def[section]);\n return { ...sel, ...composition };\n};\n\nexport const resolveRole = (\n charter: Charter,\n universe: readonly string[],\n role: string,\n section: Section,\n memo: Map<string, ReadonlySet<string>> = new Map(),\n visiting: Set<string> = new Set(),\n): ReadonlySet<string> => {\n const cached = memo.get(role);\n if (cached !== undefined) return cached;\n const def = charter[role];\n if (def === undefined) throw new CharterError(`Unknown role \"${role}\"`);\n if (visiting.has(role)) throw new CharterError(`Role cycle through \"${role}\"`);\n visiting.add(role);\n\n const { allow, extends: parents, deny, without } = normalizeRole(def, section);\n const resolved = new Set<string>();\n for (const parent of parents) for (const id of resolveRole(charter, universe, parent, section, memo, visiting)) resolved.add(id);\n for (const id of matchAll(allow, universe)) resolved.add(id);\n for (const id of matchAll(deny, universe)) resolved.delete(id);\n for (const sub of without) for (const id of resolveRole(charter, universe, sub, section, memo, visiting)) resolved.delete(id);\n\n visiting.delete(role);\n memo.set(role, resolved);\n return resolved;\n};\n\n// One role, not a list: two roles naming different profiles are not a conflict\n// to refuse. A caller holding several resolves each and merges the results.\nexport const resolveScoping = (charter: Charter, role: string): string | undefined => {\n const def = charter[role];\n return def === undefined || Array.isArray(def) ? undefined : def.scoping;\n};\n\nexport const resolvePrincipal = (\n charter: Charter,\n universe: readonly string[],\n roles: readonly string[],\n section: Section = 'actions',\n): Set<string> => {\n const memo = new Map<string, ReadonlySet<string>>();\n const out = new Set<string>();\n for (const role of roles) for (const id of resolveRole(charter, universe, role, section, memo)) out.add(id);\n return out;\n};\n","import type { Charter, Section } from './types';\nimport { matchAll } from './glob';\nimport { CharterError, normalizeRole, resolveRole } from './resolve';\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; issues: string[] };\n\nexport type VerifyReport = { errors: VerifyIssue[]; warnings: VerifyIssue[]; perRole: RoleClosure[] };\n\nexport type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];\n\nexport const verifyCharter = (\n charter: Charter,\n // `layouts`, `functions`: verified where they are handed in.\n universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[]; functions?: readonly string[] },\n // One entry per combination of roles a principal may hold, not one per principal.\n wearable: readonly (readonly string[])[] = [],\n closure?: ClosureAuditor,\n): VerifyReport => {\n const actionUniverse = universes.actions;\n const sections: Section[] = [\n 'actions',\n 'data',\n ...(universes.layouts === undefined ? [] : (['layouts'] as const)),\n ...(universes.functions === undefined ? [] : (['functions'] as const)),\n ];\n const universeOf: Record<Section, readonly string[]> = {\n actions: universes.actions,\n data: universes.data,\n layouts: universes.layouts ?? [],\n functions: universes.functions ?? [],\n };\n\n const errors: VerifyIssue[] = [];\n const warnings: VerifyIssue[] = [];\n const perRole: RoleClosure[] = [];\n\n const resolved: Record<Section, Map<string, ReadonlySet<string>>> = { actions: new Map(), data: new Map(), layouts: new Map(), functions: new Map() };\n for (const section of sections) {\n const memo = new Map<string, ReadonlySet<string>>();\n for (const role of Object.keys(charter)) {\n try {\n resolved[section].set(role, resolveRole(charter, universeOf[section], role, section, memo));\n } catch (e) {\n errors.push({ level: 'error', rule: 'resolution', detail: `${section}: ${e instanceof CharterError ? e.message : String(e)}` });\n }\n }\n }\n\n const leavesOnly = (universe: readonly string[], kind: string): void => {\n for (const a of universe) {\n for (const b of universe) {\n if (b.startsWith(`${a}.`)) {\n errors.push({ level: 'error', rule: 'leaves-only', detail: `id \"${a}\" is a namespace of \"${b}\" — namespaces are never ${kind}` });\n break;\n }\n }\n }\n };\n leavesOnly(actionUniverse, 'actions');\n if (universes.layouts !== undefined) leavesOnly(universes.layouts, 'variants');\n\n for (const [role, def] of Object.entries(charter)) {\n if (Array.isArray(def)) continue;\n if (def.actions !== undefined && (def.allow !== undefined || def.deny !== undefined)) {\n errors.push({ level: 'error', rule: 'ambiguous-selection', detail: `role \"${role}\" has both top-level allow/deny and an \"actions\" section — one selection per section` });\n }\n }\n\n for (const section of sections) {\n for (const [role, def] of Object.entries(charter)) {\n const { allow, deny } = normalizeRole(def, section);\n for (const glob of deny) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n errors.push({ level: 'error', rule: 'dead-deny', detail: `role \"${role}\" denies \"${glob}\" (${section}) which matches nothing — silent means unprotected` });\n }\n }\n for (const glob of allow) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n warnings.push({ level: 'warning', rule: 'dead-allow', detail: `role \"${role}\" allows \"${glob}\" (${section}) which matches nothing` });\n }\n }\n }\n }\n\n // Not run for `data`: a data id no role grants is denied, which is not a mistake.\n const orphans = (section: Section, kind: string): void => {\n const reachable = new Set<string>();\n for (const set of resolved[section].values()) for (const id of set) reachable.add(id);\n for (const id of universeOf[section]) {\n if (!reachable.has(id)) warnings.push({ level: 'warning', rule: 'orphan', detail: `${kind} \"${id}\" is granted by no role — deployed but unreachable` });\n }\n };\n orphans('actions', 'action');\n if (universes.layouts !== undefined) orphans('layouts', 'layout variant');\n if (universes.functions !== undefined) orphans('functions', 'function');\n\n const ancestorDenied = (role: string, section: Section, seen: Set<string> = new Set()): Set<string> => {\n const out = new Set<string>();\n const def = charter[role];\n if (def === undefined || seen.has(role)) return out;\n seen.add(role);\n for (const parent of normalizeRole(def, section).extends) {\n const parentDef = charter[parent];\n if (parentDef === undefined) continue;\n for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);\n for (const id of ancestorDenied(parent, section, seen)) out.add(id);\n }\n return out;\n };\n for (const section of sections) {\n for (const [role, set] of resolved[section]) {\n for (const id of ancestorDenied(role, section)) {\n if (set.has(id)) {\n warnings.push({ level: 'warning', rule: 're-allow', detail: `role \"${role}\" re-allows \"${id}\" (${section}) which an ancestor denied` });\n }\n }\n }\n }\n\n const subtractive = new Set<string>();\n for (const def of Object.values(charter)) {\n if (Array.isArray(def)) continue;\n for (const sub of def.without ?? []) subtractive.add(sub);\n }\n const worn = new Set(wearable.flat());\n for (const role of subtractive) {\n if (worn.has(role)) {\n warnings.push({ level: 'warning', rule: 'subtractive-assigned', detail: `role \"${role}\" is referenced in \"without\" but is also assigned to a principal` });\n }\n }\n\n for (const role of Object.keys(charter)) {\n const actions = [...(resolved.actions.get(role) ?? [])].sort();\n const data = [...(resolved.data.get(role) ?? [])].sort();\n const layouts = [...(resolved.layouts.get(role) ?? [])].sort();\n const issues = closure?.(actions, layouts) ?? [];\n perRole.push({ role, actions, data, layouts, issues });\n }\n\n return { errors, warnings, perRole };\n};\n"]}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- type Section = 'actions' | 'data' | 'layouts';
1
+ type Section = 'actions' | 'data' | 'layouts' | 'functions';
2
2
  type Selection = string[] | {
3
3
  allow?: string[];
4
4
  deny?: string[];
@@ -11,6 +11,7 @@ type RoleDef = string[] | {
11
11
  actions?: Selection;
12
12
  data?: Selection;
13
13
  layouts?: Selection;
14
+ functions?: Selection;
14
15
  scoping?: string;
15
16
  };
16
17
  type Charter = Record<string, RoleDef>;
@@ -53,6 +54,7 @@ declare const verifyCharter: (charter: Charter, universes: {
53
54
  actions: readonly string[];
54
55
  data: readonly string[];
55
56
  layouts?: readonly string[];
57
+ functions?: readonly string[];
56
58
  }, wearable?: readonly (readonly string[])[], closure?: ClosureAuditor) => VerifyReport;
57
59
 
58
60
  export { type Charter, CharterError, type ClosureAuditor, type RoleClosure, type RoleDef, type Section, type Selection, type VerifyIssue, type VerifyReport, matchAll, matchGlob, normalizeRole, resolvePrincipal, resolveRole, resolveScoping, verifyCharter };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type Section = 'actions' | 'data' | 'layouts';
1
+ type Section = 'actions' | 'data' | 'layouts' | 'functions';
2
2
  type Selection = string[] | {
3
3
  allow?: string[];
4
4
  deny?: string[];
@@ -11,6 +11,7 @@ type RoleDef = string[] | {
11
11
  actions?: Selection;
12
12
  data?: Selection;
13
13
  layouts?: Selection;
14
+ functions?: Selection;
14
15
  scoping?: string;
15
16
  };
16
17
  type Charter = Record<string, RoleDef>;
@@ -53,6 +54,7 @@ declare const verifyCharter: (charter: Charter, universes: {
53
54
  actions: readonly string[];
54
55
  data: readonly string[];
55
56
  layouts?: readonly string[];
57
+ functions?: readonly string[];
56
58
  }, wearable?: readonly (readonly string[])[], closure?: ClosureAuditor) => VerifyReport;
57
59
 
58
60
  export { type Charter, CharterError, type ClosureAuditor, type RoleClosure, type RoleDef, type Section, type Selection, type VerifyIssue, type VerifyReport, matchAll, matchGlob, normalizeRole, resolvePrincipal, resolveRole, resolveScoping, verifyCharter };
package/dist/index.js CHANGED
@@ -58,16 +58,22 @@ var resolvePrincipal = (charter, universe, roles, section = "actions") => {
58
58
  // src/verify.ts
59
59
  var verifyCharter = (charter, universes, wearable = [], closure) => {
60
60
  const actionUniverse = universes.actions;
61
- const sections = universes.layouts === void 0 ? ["actions", "data"] : ["actions", "data", "layouts"];
61
+ const sections = [
62
+ "actions",
63
+ "data",
64
+ ...universes.layouts === void 0 ? [] : ["layouts"],
65
+ ...universes.functions === void 0 ? [] : ["functions"]
66
+ ];
62
67
  const universeOf = {
63
68
  actions: universes.actions,
64
69
  data: universes.data,
65
- layouts: universes.layouts ?? []
70
+ layouts: universes.layouts ?? [],
71
+ functions: universes.functions ?? []
66
72
  };
67
73
  const errors = [];
68
74
  const warnings = [];
69
75
  const perRole = [];
70
- const resolved = { actions: /* @__PURE__ */ new Map(), data: /* @__PURE__ */ new Map(), layouts: /* @__PURE__ */ new Map() };
76
+ const resolved = { actions: /* @__PURE__ */ new Map(), data: /* @__PURE__ */ new Map(), layouts: /* @__PURE__ */ new Map(), functions: /* @__PURE__ */ new Map() };
71
77
  for (const section of sections) {
72
78
  const memo = /* @__PURE__ */ new Map();
73
79
  for (const role of Object.keys(charter)) {
@@ -120,6 +126,7 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
120
126
  };
121
127
  orphans("actions", "action");
122
128
  if (universes.layouts !== void 0) orphans("layouts", "layout variant");
129
+ if (universes.functions !== void 0) orphans("functions", "function");
123
130
  const ancestorDenied = (role, section, seen = /* @__PURE__ */ new Set()) => {
124
131
  const out = /* @__PURE__ */ new Set();
125
132
  const def = charter[role];
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/glob.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";AAIA,IAAM,eAAe,CAAC,CAAA,KAAsB,CAAA,CAAE,OAAA,CAAQ,uBAAuB,MAAM,CAAA;AAEnF,IAAM,WAAW,CAAC,OAAA,KAA4B,IAAI,MAAA,CAAO,IAAI,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAI,YAAY,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,CAAA;AAExG,IAAM,SAAA,GAAY,CAAC,OAAA,EAAiB,EAAA,KAAwB,SAAS,OAAO,CAAA,CAAE,KAAK,EAAE;AAGrF,IAAM,QAAA,GAAW,CAAC,QAAA,EAA6B,GAAA,KA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S,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA,IAAK,EAAG,CAAA,CAAE,IAAA,EAAK;AACvD,IAAA,MAAM,OAAA,GAAU,CAAC,GAAI,QAAA,CAAS,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAA,IAAK,EAAG,CAAA,CAAE,IAAA,EAAK;AAC7D,IAAA,MAAM,MAAA,GAAS,OAAA,GAAU,OAAA,EAAS,OAAO,KAAK,EAAC;AAC/C,IAAA,OAAA,CAAQ,KAAK,EAAE,IAAA,EAAM,SAAS,IAAA,EAAM,OAAA,EAAS,QAAQ,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,OAAA,EAAQ;AACrC","file":"index.js","sourcesContent":["// One wildcard rule, no more: `*` matches any run of characters, including\n// dots — `crm.*` matches `crm.deal.form`. No `**`, no braces, no regex. The\n// day a pattern cannot be expressed, the answer is a better id, not a\n// richer glob.\nconst escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst toRegExp = (pattern: string): RegExp => new RegExp(`^${pattern.split('*').map(escapeRegExp).join('.*')}$`);\n\nexport const matchGlob = (pattern: string, id: string): boolean => toRegExp(pattern).test(id);\n\n// Every id the pattern list selects out of `ids`.\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) {\n const re = toRegExp(pattern);\n for (const id of ids) if (re.test(id)) out.add(id);\n }\n return out;\n};\n","import type { Charter, RoleDef, Section, Selection } from './types';\nimport { matchAll } from './glob';\n\n// Resolution is a pure function from (charter, universe, section) to a\n// concrete id set per role — the algebra from DESIGN.md § The algebra,\n// verbatim, per section:\n//\n// resolved(role) = (∪ resolved(extends) ∪ match(allow))\n// − match(deny)\n// − ∪ resolved(without)\n//\n// The engine is UNIVERSE-BLIND: it resolves globs over opaque strings and\n// never learns what a string means. `actions` and `data` run the SAME code\n// against different universes. Order-independent (all subtraction is\n// set-minus); deny wins within a role; denies do NOT inherit (a child may\n// re-add what a parent denied — the verifier flags it); cycles and unknown\n// references are errors.\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\n// NOTE deliberately absent: the engine never MANUFACTURES a universe — it is\n// always handed one. The data universe's atoms are the governed target's own\n// dialect (vex exports `SCOPE_VERBS` and `scopeGrants(tables)`); the app\n// wiring derives it and passes it in. That keeps this module free of any\n// foreign import, in either direction.\n\nconst asSelection = (s: Selection | undefined): { allow: string[]; deny: string[] } =>\n s === undefined ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };\n\n// A role's atoms for ONE section, plus its role-level composition (shared\n// across sections). A bare array is an actions-only role; top-level\n// `allow`/`deny` are sugar for the `actions` section.\nexport const normalizeRole = (\n def: RoleDef,\n section: Section,\n): { allow: string[]; deny: string[]; extends: string[]; without: string[] } => {\n if (Array.isArray(def)) {\n return section === 'actions'\n ? { allow: def, deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const composition = { extends: def.extends ?? [], without: def.without ?? [] };\n // Actions: explicit `actions:` wins, else the top-level allow/deny sugar.\n const sel =\n section === 'actions' && def.actions === undefined\n ? { allow: def.allow ?? [], deny: def.deny ?? [] }\n : asSelection(def[section]);\n return { ...sel, ...composition };\n};\n\nexport const resolveRole = (\n charter: Charter,\n universe: readonly string[],\n role: string,\n section: Section,\n memo: Map<string, ReadonlySet<string>> = new Map(),\n visiting: Set<string> = new Set(),\n): ReadonlySet<string> => {\n const cached = memo.get(role);\n if (cached !== undefined) return cached;\n const def = charter[role];\n if (def === undefined) throw new CharterError(`Unknown role \"${role}\"`);\n if (visiting.has(role)) throw new CharterError(`Role cycle through \"${role}\"`);\n visiting.add(role);\n\n const { allow, extends: parents, deny, without } = normalizeRole(def, section);\n const resolved = new Set<string>();\n for (const parent of parents) for (const id of resolveRole(charter, universe, parent, section, memo, visiting)) resolved.add(id);\n for (const id of matchAll(allow, universe)) resolved.add(id);\n for (const id of matchAll(deny, universe)) resolved.delete(id);\n for (const sub of without) for (const id of resolveRole(charter, universe, sub, section, memo, visiting)) resolved.delete(id);\n\n visiting.delete(role);\n memo.set(role, resolved);\n return resolved;\n};\n\n// A principal wears roles; a section's grant is the union of their resolved\n// sets in that section's universe.\n// The reach a ROLE was given: the profile it names, or none.\n//\n// SINGULAR ON PURPOSE. This took a list of roles and refused when two of them\n// named different profiles — \"incoherence rather than a precedence puzzle,\n// refused in the same spirit as two granted layout variants for one action.\"\n// That analogy was wrong. Two layout variants for one action genuinely conflict,\n// because a screen renders one of them; two roles naming different reaches is\n// somebody who teaches at a studio AND trains there, which is a person, not a\n// contradiction.\n//\n// A caller who holds several roles resolves each one separately and merges the\n// results (vex: `mergeScopePolicies`). That is where \"holding two roles\" is\n// decided, and it belongs there — reach is a property of a role, so a function\n// handed several of them has no answer to give, only a choice to refuse.\nexport const resolveScoping = (charter: Charter, role: string): string | undefined => {\n const def = charter[role];\n return def === undefined || Array.isArray(def) ? undefined : def.scoping;\n};\n\nexport const resolvePrincipal = (\n charter: Charter,\n universe: readonly string[],\n roles: readonly string[],\n section: Section = 'actions',\n): Set<string> => {\n const memo = new Map<string, ReadonlySet<string>>();\n const out = new Set<string>();\n for (const role of roles) for (const id of resolveRole(charter, universe, role, section, memo)) out.add(id);\n return out;\n};\n","import type { Charter, Section } from './types';\nimport { matchAll } from './glob';\nimport { CharterError, normalizeRole, resolveRole } from './resolve';\n\n// ═══════════════════════════════════════════════════════════\n// The verifier — the other half of the charter (DESIGN.md § The verifier\n// is the other half). The grammar\n// stays small; the opinions live here. Boot/CI runs it and refuses an\n// incoherent charter: \"if it boots, it's coherent.\"\n//\n// Every check runs PER SECTION against that section's universe. Like the\n// resolver, the verifier is universe-blind: every universe is HANDED IN\n// (the atoms are each governed target's own dialect — nova action ids, vex\n// verb leaves), and the per-role closure audit is an injected hook (nova\n// exports one), so this module imports nothing. Severities are asymmetric\n// on purpose: a dead DENY is an error (a typo'd deny fails silent, and\n// silent means unprotected); a dead allow is a warning.\n// ═══════════════════════════════════════════════════════════\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; issues: string[] };\n\nexport type VerifyReport = { errors: VerifyIssue[]; warnings: VerifyIssue[]; perRole: RoleClosure[] };\n\n// The per-role closure audit: given a role's granted action ids (and, when\n// the app governs layouts, its granted layout-variant ids), report the\n// cross-action wiring problems inside that closure (targets that aren't in\n// it, channels nobody serves). The consumer that OWNS actions provides it —\n// moss builds one from nova's audit, substituting granted variants so the\n// closure sees each role's EFFECTIVE definitions.\nexport type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];\n\nexport const verifyCharter = (\n charter: Charter,\n universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[] },\n // THE ROLE COMBINATIONS A PRINCIPAL MAY WEAR — one entry per combination, not\n // one per person. The only rule below that reads it (`subtractive-assigned`)\n // wants the set of roles somebody actually holds, and a population is a very\n // expensive way to spell a set. A composer that still holds an assignment map\n // passes `Object.values(map)`; one that declares its combinations passes them.\n wearable: readonly (readonly string[])[] = [],\n closure?: ClosureAuditor,\n): VerifyReport => {\n const actionUniverse = universes.actions;\n // The layouts section is verified only when the composer governs layouts\n // (hands a universe in) — absent, a charter's `layouts` keys are inert\n // here exactly as they are in resolution against an empty universe.\n const sections: Section[] = universes.layouts === undefined ? ['actions', 'data'] : ['actions', 'data', 'layouts'];\n const universeOf: Record<Section, readonly string[]> = {\n actions: universes.actions,\n data: universes.data,\n layouts: universes.layouts ?? [],\n };\n\n const errors: VerifyIssue[] = [];\n const warnings: VerifyIssue[] = [];\n const perRole: RoleClosure[] = [];\n\n // Resolve every role in every section up front (also surfaces cycles /\n // unknown references, per section).\n const resolved: Record<Section, Map<string, ReadonlySet<string>>> = { actions: new Map(), data: new Map(), layouts: new Map() };\n for (const section of sections) {\n const memo = new Map<string, ReadonlySet<string>>();\n for (const role of Object.keys(charter)) {\n try {\n resolved[section].set(role, resolveRole(charter, universeOf[section], role, section, memo));\n } catch (e) {\n errors.push({ level: 'error', rule: 'resolution', detail: `${section}: ${e instanceof CharterError ? e.message : String(e)}` });\n }\n }\n }\n\n // ── ids are leaves; namespaces are never actions. Same rule inside the\n // layouts universe — a variant id is never a namespace of another ──\n const leavesOnly = (universe: readonly string[], kind: string): void => {\n for (const a of universe) {\n for (const b of universe) {\n if (b.startsWith(`${a}.`)) {\n errors.push({ level: 'error', rule: 'leaves-only', detail: `id \"${a}\" is a namespace of \"${b}\" — namespaces are never ${kind}` });\n break;\n }\n }\n }\n };\n leavesOnly(actionUniverse, 'actions');\n if (universes.layouts !== undefined) leavesOnly(universes.layouts, 'variants');\n\n // ── one selection per section: top-level allow/deny (the actions sugar)\n // AND an `actions` key on the same role means resolution silently drops\n // the sugar — silent means wrong, so boot refuses ──\n for (const [role, def] of Object.entries(charter)) {\n if (Array.isArray(def)) continue;\n if (def.actions !== undefined && (def.allow !== undefined || def.deny !== undefined)) {\n errors.push({ level: 'error', rule: 'ambiguous-selection', detail: `role \"${role}\" has both top-level allow/deny and an \"actions\" section — one selection per section` });\n }\n }\n\n // ── dead deny = error, dead allow = warning; per glob, per role, per section ──\n for (const section of sections) {\n for (const [role, def] of Object.entries(charter)) {\n const { allow, deny } = normalizeRole(def, section);\n for (const glob of deny) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n errors.push({ level: 'error', rule: 'dead-deny', detail: `role \"${role}\" denies \"${glob}\" (${section}) which matches nothing — silent means unprotected` });\n }\n }\n for (const glob of allow) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n warnings.push({ level: 'warning', rule: 'dead-allow', detail: `role \"${role}\" allows \"${glob}\" (${section}) which matches nothing` });\n }\n }\n }\n }\n\n // ── orphans: matched by no role at all. Actions and layout variants share\n // the rule — both are deployed-but-unreachable artifacts. An ungranted\n // data phase is simply denied, not a mistake ──\n const orphans = (section: Section, kind: string): void => {\n const reachable = new Set<string>();\n for (const set of resolved[section].values()) for (const id of set) reachable.add(id);\n for (const id of universeOf[section]) {\n if (!reachable.has(id)) warnings.push({ level: 'warning', rule: 'orphan', detail: `${kind} \"${id}\" is granted by no role — deployed but unreachable` });\n }\n };\n orphans('actions', 'action');\n if (universes.layouts !== undefined) orphans('layouts', 'layout variant');\n\n // ── re-allow of an ancestor's deny (F1), per section ──\n const ancestorDenied = (role: string, section: Section, seen: Set<string> = new Set()): Set<string> => {\n const out = new Set<string>();\n const def = charter[role];\n if (def === undefined || seen.has(role)) return out;\n seen.add(role);\n for (const parent of normalizeRole(def, section).extends) {\n const parentDef = charter[parent];\n if (parentDef === undefined) continue;\n for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);\n for (const id of ancestorDenied(parent, section, seen)) out.add(id);\n }\n return out;\n };\n for (const section of sections) {\n for (const [role, set] of resolved[section]) {\n for (const id of ancestorDenied(role, section)) {\n if (set.has(id)) {\n warnings.push({ level: 'warning', rule: 're-allow', detail: `role \"${role}\" re-allows \"${id}\" (${section}) which an ancestor denied` });\n }\n }\n }\n }\n\n // ── a role referenced in `without` that principals also wear (F2) ──\n const subtractive = new Set<string>();\n for (const def of Object.values(charter)) {\n if (Array.isArray(def)) continue;\n for (const sub of def.without ?? []) subtractive.add(sub);\n }\n const worn = new Set(wearable.flat());\n for (const role of subtractive) {\n if (worn.has(role)) {\n warnings.push({ level: 'warning', rule: 'subtractive-assigned', detail: `role \"${role}\" is referenced in \"without\" but is also assigned to a principal` });\n }\n }\n\n // ── per-role closure: the action-catalog audit (cross-action wiring),\n // fed the role's granted variants so it audits EFFECTIVE definitions ──\n for (const role of Object.keys(charter)) {\n const actions = [...(resolved.actions.get(role) ?? [])].sort();\n const data = [...(resolved.data.get(role) ?? [])].sort();\n const layouts = [...(resolved.layouts.get(role) ?? [])].sort();\n const issues = closure?.(actions, layouts) ?? [];\n perRole.push({ role, actions, data, layouts, issues });\n }\n\n return { errors, warnings, perRole };\n};\n"]}
1
+ {"version":3,"sources":["../src/glob.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";AAAA,IAAM,eAAe,CAAC,CAAA,KAAsB,CAAA,CAAE,OAAA,CAAQ,uBAAuB,MAAM,CAAA;AAEnF,IAAM,WAAW,CAAC,OAAA,KAA4B,IAAI,MAAA,CAAO,IAAI,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAI,YAAY,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,CAAA;AAExG,IAAM,SAAA,GAAY,CAAC,OAAA,EAAiB,EAAA,KAAwB,SAAS,OAAO,CAAA,CAAE,KAAK,EAAE;AAErF,IAAM,QAAA,GAAW,CAAC,QAAA,EAA6B,GAAA,KAAwC;AAC5F,EAAA,MAAM,GAAA,uBAAU,GAAA,EAAY;AAC5B,EAAA,KAAA,MAAW,WAAW,QAAA,EAAU;AAC9B,IAAA,MAAM,EAAA,GAAK,SAAS,OAAO,CAAA;AAC3B,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,IAAI,EAAA,CAAG,KAAK,EAAE,CAAA,EAAG,GAAA,CAAI,GAAA,CAAI,EAAE,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,GAAA;AACT;;;ACVO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AAAA,EACd;AACF;AAEA,IAAM,WAAA,GAAc,CAAC,CAAA,KACnB,CAAA,KAAM,SAAY,EAAE,KAAA,EAAO,EAAC,EAAG,MAAM,EAAC,EAAE,GAAI,KAAA,CAAM,QAAQ,CAAC,CAAA,GAAI,EAAE,KAAA,EAAO,CAAA,EAAG,IAAA,EAAM,EAAC,KAAM,EAAE,KAAA,EAAO,CAAA,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const escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst toRegExp = (pattern: string): RegExp => new RegExp(`^${pattern.split('*').map(escapeRegExp).join('.*')}$`);\n\nexport const matchGlob = (pattern: string, id: string): boolean => toRegExp(pattern).test(id);\n\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) {\n const re = toRegExp(pattern);\n for (const id of ids) if (re.test(id)) out.add(id);\n }\n return out;\n};\n","import type { Charter, RoleDef, Section, Selection } from './types';\nimport { matchAll } from './glob';\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\nconst asSelection = (s: Selection | undefined): { allow: string[]; deny: string[] } =>\n s === undefined ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };\n\nexport const normalizeRole = (\n def: RoleDef,\n section: Section,\n): { allow: string[]; deny: string[]; extends: string[]; without: string[] } => {\n if (Array.isArray(def)) {\n return section === 'actions'\n ? { allow: def, deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const composition = { extends: def.extends ?? [], without: def.without ?? [] };\n const sel =\n section === 'actions' && def.actions === undefined\n ? { allow: def.allow ?? [], deny: def.deny ?? [] }\n : asSelection(def[section]);\n return { ...sel, ...composition };\n};\n\nexport const resolveRole = (\n charter: Charter,\n universe: readonly string[],\n role: string,\n section: Section,\n memo: Map<string, ReadonlySet<string>> = new Map(),\n visiting: Set<string> = new Set(),\n): ReadonlySet<string> => {\n const cached = memo.get(role);\n if (cached !== undefined) return cached;\n const def = charter[role];\n if (def === undefined) throw new CharterError(`Unknown role \"${role}\"`);\n if (visiting.has(role)) throw new CharterError(`Role cycle through \"${role}\"`);\n visiting.add(role);\n\n const { allow, extends: parents, deny, without } = normalizeRole(def, section);\n const resolved = new Set<string>();\n for (const parent of parents) for (const id of resolveRole(charter, universe, parent, section, memo, visiting)) resolved.add(id);\n for (const id of matchAll(allow, universe)) resolved.add(id);\n for (const id of matchAll(deny, universe)) resolved.delete(id);\n for (const sub of without) for (const id of resolveRole(charter, universe, sub, section, memo, visiting)) resolved.delete(id);\n\n visiting.delete(role);\n memo.set(role, resolved);\n return resolved;\n};\n\n// One role, not a list: two roles naming different profiles are not a conflict\n// to refuse. A caller holding several resolves each and merges the results.\nexport const resolveScoping = (charter: Charter, role: string): string | undefined => {\n const def = charter[role];\n return def === undefined || Array.isArray(def) ? undefined : def.scoping;\n};\n\nexport const resolvePrincipal = (\n charter: Charter,\n universe: readonly string[],\n roles: readonly string[],\n section: Section = 'actions',\n): Set<string> => {\n const memo = new Map<string, ReadonlySet<string>>();\n const out = new Set<string>();\n for (const role of roles) for (const id of resolveRole(charter, universe, role, section, memo)) out.add(id);\n return out;\n};\n","import type { Charter, Section } from './types';\nimport { matchAll } from './glob';\nimport { CharterError, normalizeRole, resolveRole } from './resolve';\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; issues: string[] };\n\nexport type VerifyReport = { errors: VerifyIssue[]; warnings: VerifyIssue[]; perRole: RoleClosure[] };\n\nexport type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];\n\nexport const verifyCharter = (\n charter: Charter,\n // `layouts`, `functions`: verified where they are handed in.\n universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[]; functions?: readonly string[] },\n // One entry per combination of roles a principal may hold, not one per principal.\n wearable: readonly (readonly string[])[] = [],\n closure?: ClosureAuditor,\n): VerifyReport => {\n const actionUniverse = universes.actions;\n const sections: Section[] = [\n 'actions',\n 'data',\n ...(universes.layouts === undefined ? [] : (['layouts'] as const)),\n ...(universes.functions === undefined ? [] : (['functions'] as const)),\n ];\n const universeOf: Record<Section, readonly string[]> = {\n actions: universes.actions,\n data: universes.data,\n layouts: universes.layouts ?? [],\n functions: universes.functions ?? [],\n };\n\n const errors: VerifyIssue[] = [];\n const warnings: VerifyIssue[] = [];\n const perRole: RoleClosure[] = [];\n\n const resolved: Record<Section, Map<string, ReadonlySet<string>>> = { actions: new Map(), data: new Map(), layouts: new Map(), functions: new Map() };\n for (const section of sections) {\n const memo = new Map<string, ReadonlySet<string>>();\n for (const role of Object.keys(charter)) {\n try {\n resolved[section].set(role, resolveRole(charter, universeOf[section], role, section, memo));\n } catch (e) {\n errors.push({ level: 'error', rule: 'resolution', detail: `${section}: ${e instanceof CharterError ? e.message : String(e)}` });\n }\n }\n }\n\n const leavesOnly = (universe: readonly string[], kind: string): void => {\n for (const a of universe) {\n for (const b of universe) {\n if (b.startsWith(`${a}.`)) {\n errors.push({ level: 'error', rule: 'leaves-only', detail: `id \"${a}\" is a namespace of \"${b}\" — namespaces are never ${kind}` });\n break;\n }\n }\n }\n };\n leavesOnly(actionUniverse, 'actions');\n if (universes.layouts !== undefined) leavesOnly(universes.layouts, 'variants');\n\n for (const [role, def] of Object.entries(charter)) {\n if (Array.isArray(def)) continue;\n if (def.actions !== undefined && (def.allow !== undefined || def.deny !== undefined)) {\n errors.push({ level: 'error', rule: 'ambiguous-selection', detail: `role \"${role}\" has both top-level allow/deny and an \"actions\" section — one selection per section` });\n }\n }\n\n for (const section of sections) {\n for (const [role, def] of Object.entries(charter)) {\n const { allow, deny } = normalizeRole(def, section);\n for (const glob of deny) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n errors.push({ level: 'error', rule: 'dead-deny', detail: `role \"${role}\" denies \"${glob}\" (${section}) which matches nothing — silent means unprotected` });\n }\n }\n for (const glob of allow) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n warnings.push({ level: 'warning', rule: 'dead-allow', detail: `role \"${role}\" allows \"${glob}\" (${section}) which matches nothing` });\n }\n }\n }\n }\n\n // Not run for `data`: a data id no role grants is denied, which is not a mistake.\n const orphans = (section: Section, kind: string): void => {\n const reachable = new Set<string>();\n for (const set of resolved[section].values()) for (const id of set) reachable.add(id);\n for (const id of universeOf[section]) {\n if (!reachable.has(id)) warnings.push({ level: 'warning', rule: 'orphan', detail: `${kind} \"${id}\" is granted by no role — deployed but unreachable` });\n }\n };\n orphans('actions', 'action');\n if (universes.layouts !== undefined) orphans('layouts', 'layout variant');\n if (universes.functions !== undefined) orphans('functions', 'function');\n\n const ancestorDenied = (role: string, section: Section, seen: Set<string> = new Set()): Set<string> => {\n const out = new Set<string>();\n const def = charter[role];\n if (def === undefined || seen.has(role)) return out;\n seen.add(role);\n for (const parent of normalizeRole(def, section).extends) {\n const parentDef = charter[parent];\n if (parentDef === undefined) continue;\n for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);\n for (const id of ancestorDenied(parent, section, seen)) out.add(id);\n }\n return out;\n };\n for (const section of sections) {\n for (const [role, set] of resolved[section]) {\n for (const id of ancestorDenied(role, section)) {\n if (set.has(id)) {\n warnings.push({ level: 'warning', rule: 're-allow', detail: `role \"${role}\" re-allows \"${id}\" (${section}) which an ancestor denied` });\n }\n }\n }\n }\n\n const subtractive = new Set<string>();\n for (const def of Object.values(charter)) {\n if (Array.isArray(def)) continue;\n for (const sub of def.without ?? []) subtractive.add(sub);\n }\n const worn = new Set(wearable.flat());\n for (const role of subtractive) {\n if (worn.has(role)) {\n warnings.push({ level: 'warning', rule: 'subtractive-assigned', detail: `role \"${role}\" is referenced in \"without\" but is also assigned to a principal` });\n }\n }\n\n for (const role of Object.keys(charter)) {\n const actions = [...(resolved.actions.get(role) ?? [])].sort();\n const data = [...(resolved.data.get(role) ?? [])].sort();\n const layouts = [...(resolved.layouts.get(role) ?? [])].sort();\n const issues = closure?.(actions, layouts) ?? [];\n perRole.push({ role, actions, data, layouts, issues });\n }\n\n return { errors, warnings, perRole };\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niscorp/charter",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "A universe-blind policy engine — roles resolve glob selections over opaque string universes; the verifier refuses incoherence. Zero dependencies.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {