@niscorp/charter 0.1.4 → 0.2.0

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,33 @@
1
1
  # @niscorp/charter
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 092b5f1: BREAKING — approved by moccadroid (owner), 2026-11-22: a charter that writes a string where a list belongs (`allow: "crm.deal.view*"`) and relied on it granting every id writes the patterns it means as a list.
8
+
9
+ A string where a charter expects a list (`allow: "crm.deal.view*"`) is read as a list of that one pattern instead of one pattern per character, so it no longer grants every id through a `*`. `verifyCharter` reports keys it does not read (a misspelt `denny` or `Deny`) and such strings as `shape` warnings. Any other value that is not a list of strings no longer crashes the verifier: it grants nothing (a warning), and in `deny` or `without`, or as a whole role that is `null`, it is a `shape` error. A `scoping` that is not a string is still handed on as written, so the role reaches no rows, and is now a `shape` warning. `*` now matches across line breaks in an id.
10
+
11
+ - 74a9a7a: BREAKING — approved by moccadroid (owner), 2026-11-22: nothing unless a host resolves, without `verifyCharter`, a role that has both an `actions:` section and a top-level `deny`, and relied on that `deny` being dropped.
12
+
13
+ A role with both an `actions:` section and a top-level `deny` (`{ actions: ['crm.*'], deny: ['crm.deal.delete'] }`) now takes away what the top-level `deny` names when it is resolved, instead of granting the whole section, and a role that extends it (`c: { extends: ['p'] }`) no longer gets `crm.deal.delete` from it either. The top-level `allow` beside an `actions:` section still grants nothing. `verifyCharter` refuses such a role as before (`ambiguous-selection`), so under moss nothing changes; it now also checks that top-level `deny` like any other, so a charter already refused can report more lines for it: `dead-deny` when it matches nothing (`{ r: { actions: ['crm.*'], deny: ['hr.nothing'] } }`), `orphan` for an action it leaves no role granting, and a re-allow warning for a child that grants back what it takes away.
14
+
15
+ ### Patch Changes
16
+
17
+ - c9158e2: A role named in `extends` or `without` by a name every object answers to (`constructor`, `toString`, `hasOwnProperty`, `__proto__`) that the charter does not define resolves as an empty role, and `verifyCharter` says so as a `shape` warning, as it does for a misspelt key.
18
+
19
+ A glob with many stars (`*a*a*a*a*a*a*a*a*a*a*b`) against a long id answers in milliseconds instead of seconds: globs are matched without a regular expression, with the same answers.
20
+
21
+ `RoleClosure` gains an optional `functions`: the functions a role is granted, listed in `verifyCharter`'s `perRole` when the functions universe is handed in. Without that universe the field is absent.
22
+
23
+ ## 0.1.5
24
+
25
+ ### Patch Changes
26
+
27
+ - febd8b7: The docs cover the `functions` section: what it selects, which checks run on it (no leaves-only), and that moss enforces it.
28
+
29
+ **What to change:** nothing. Documentation only.
30
+
3
31
  ## 0.1.4
4
32
 
5
33
  ### Patch Changes
package/DESIGN.md CHANGED
@@ -163,7 +163,8 @@ socket, and revocation is the same push with a smaller set.
163
163
 
164
164
  ### Globs
165
165
 
166
- One wildcard rule, no more: `*` matches any run of characters, including dots.
166
+ One wildcard rule, no more: `*` matches any run of characters, including dots
167
+ and line breaks.
167
168
  `crm.*` matches `crm.deal.form`. There is no `**`, no brace expansion, no regex.
168
169
  The day a pattern cannot be expressed, the answer is a better id, not a richer
169
170
  glob.
@@ -181,7 +182,10 @@ bare `string[]` is an actions-only role, and top-level `allow`/`deny` are the
181
182
  `actions:`/`data:`/`layouts:`/`functions:` selections address each universe
182
183
  directly. Having
183
184
  *both* the sugar and an explicit `actions:` on one role is the
184
- `ambiguous-selection` error — resolution would silently drop one.
185
+ `ambiguous-selection` error. Resolved without the verifier, such a role reads
186
+ the `actions:` section and takes away the top-level `deny` too; the top-level
187
+ `allow` is dropped, since reading it would grant more than one of the two
188
+ selections says.
185
189
 
186
190
  The `data` verb leaves mirror vex's phases: `read`, plus the three write ops
187
191
  under the `write` *namespace* — `deals.read`, `deals.write.insert`,
@@ -220,6 +224,7 @@ two:
220
224
  | `actions` | action ids | the action map, filtered by ids | Nova's shell |
221
225
  | `data` | `SCOPE_VERBS` leaves (`deals.write.insert`) | `createScopePolicy(grants, behaviors, scoping)` | Vex |
222
226
  | `layouts` | variant ids | substitute the variant's layout on the definition | moss / Nova |
227
+ | `functions` | function names | a call is allowed when its name is in the resolved set | moss |
223
228
  | (future) | tool names | a `ToolPolicy` constructor | Cortex's `policyGate` |
224
229
 
225
230
  Each side stays pure and standalone: the charter is a string-set engine always
@@ -421,6 +426,10 @@ verifier carries the opinions:
421
426
  reported
422
427
  - flags re-allows of an ancestor's deny (F1)
423
428
  - flags roles referenced in `without` that are also assigned (F2)
429
+ - reports a key it does not read and a string where a list belongs (`shape`):
430
+ a misspelt `deny` is ignored by resolution, so it is said. A `deny` or
431
+ `without` it cannot read is an error: read as nothing, it would grant what it
432
+ was written to take away
424
433
  - enforces id conventions (leaves only); overlay rules (no shadowing) are not
425
434
  built — there are no overlays yet (F7)
426
435
  - checks `assert` invariants (F6) — not built: `verifyCharter` takes no
package/DOCS.md CHANGED
@@ -34,7 +34,9 @@ type RoleDef =
34
34
  A bare `string[]` is an actions-only role. Top-level `allow`/`deny` are sugar
35
35
  for the `actions` section — an actions-only role never names a section. Using
36
36
  both the sugar and an explicit `actions:` on one role is an error (the verifier
37
- catches it).
37
+ catches it). A host that resolves such a role without verifying it gets the
38
+ `actions:` section with the top-level `deny` taken away as well; the top-level
39
+ `allow` grants nothing.
38
40
 
39
41
  #### `scoping` — how far a role reaches
40
42
 
@@ -109,7 +111,7 @@ functions (moss's too). A role with no `functions` may call none.
109
111
 
110
112
  ### `matchGlob(pattern, id): boolean`
111
113
 
112
- One wildcard: `*` matches any run of characters, including dots. `matchGlob('crm.*', 'crm.deal.form')` is `true`. No `**`, no braces, no regex.
114
+ One wildcard: `*` matches any run of characters, including dots and line breaks. `matchGlob('crm.*', 'crm.deal.form')` is `true`. No `**`, no braces, no regex. A pattern is matched without a regular expression, so however many stars it has, the time grows only with its length times the id's.
113
115
 
114
116
  ### `matchAll(patterns, ids): Set<string>`
115
117
 
@@ -126,7 +128,10 @@ Resolve one role in one section against `universe`. Applies the algebra
126
128
  accumulators for recursion and cycle detection; callers pass neither. (`memo` is
127
129
  keyed by role name alone, so one is never shared across sections or universes.)
128
130
 
129
- Throws `CharterError` on an unknown role reference or a role cycle.
131
+ Throws `CharterError` on an unknown role reference or a role cycle. A role is
132
+ one the charter defines as its own key: a name every object answers to
133
+ (`constructor`, `toString`, `hasOwnProperty`, `__proto__`) that the charter
134
+ does not define is an empty role, and the verifier says so (`shape`).
130
135
 
131
136
  ### `resolvePrincipal(charter, universe, roles, section?): Set<string>`
132
137
 
@@ -153,7 +158,8 @@ that inspect a role's raw selection (the verifier uses it); most callers want
153
158
 
154
159
  ### `CharterError`
155
160
 
156
- Thrown by the resolver for unknown-role and cycle errors. `verifyCharter`
161
+ Thrown by the resolver for unknown-role and cycle errors, and for a role whose
162
+ `deny` or `without` cannot be read (the verifier's `shape` error). `verifyCharter`
157
163
  catches these and reports them as `resolution` errors rather than throwing.
158
164
 
159
165
  ---
@@ -170,7 +176,8 @@ at boot/CI; refuse to serve if `report.errors` is non-empty.
170
176
  `layouts` universe is optional: absent, the section is inert (a charter's
171
177
  `layouts` keys resolve against nothing and are not verified); handed in, its
172
178
  dead-deny/dead-allow/orphan/leaves-only checks run like any other section.
173
- So is `functions`, with the same checks.
179
+ So is `functions`, with the dead-deny, dead-allow and orphan checks;
180
+ leaves-only runs only on `actions` and `layouts`.
174
181
  - `wearable?: readonly (readonly string[])[]` — the role combinations a principal
175
182
  may wear, one entry per combination (not one per person). Defaults to `[]`.
176
183
  Read only by the `subtractive-assigned` check. A composer that has an
@@ -196,11 +203,11 @@ role's effective definitions. Absent, every role's `issues` is empty.
196
203
  type VerifyReport = {
197
204
  errors: VerifyIssue[]; // refuse to boot if non-empty
198
205
  warnings: VerifyIssue[]; // deploy, but review
199
- perRole: RoleClosure[]; // resolved actions + data + layouts (sorted) + closure issues, per role
206
+ perRole: RoleClosure[]; // resolved actions + data + layouts (+ functions, when that universe is handed in) (sorted) + closure issues, per role
200
207
  };
201
208
 
202
209
  type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };
203
- type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; issues: string[] };
210
+ type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; functions?: string[]; issues: string[] };
204
211
  ```
205
212
 
206
213
  ### The checks
@@ -208,13 +215,14 @@ type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: s
208
215
  | rule | level | meaning |
209
216
  |---|---|---|
210
217
  | `resolution` | error | a cycle or unknown-role reference (per section) |
211
- | `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`) |
218
+ | `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`) |
212
219
  | `ambiguous-selection` | error | a role has both top-level `allow`/`deny` and an explicit `actions:` |
213
220
  | `dead-deny` | error | a deny glob matches nothing — silent means unprotected |
214
221
  | `dead-allow` | warning | an allow glob matches nothing — noise |
215
- | `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 |
222
+ | `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 |
216
223
  | `re-allow` | warning | a role re-allows an id an ancestor denied |
217
224
  | `subtractive-assigned` | warning | a role used in `without` also appears in a `wearable` combination |
225
+ | `shape` | warning, or error where it takes away | a key the charter does not read, in a role or in a section (`denny`, `Deny`, `actions.alow`): what it lists does not apply. A string where a list belongs: in `allow`, `deny`, `extends` and `without` it is read as a list of that one string. Any other value that is not a list of strings, and any entry of a list that is not a string, is read as nothing: where it would grant (a role, a section, `allow`, `extends`) that is a warning; in `deny` or `without` it is an error, and resolving that role throws a `CharterError`. A `null` list is an absent one; a role that is `null` is an error, since named in a `without` it would take away nothing. A `scoping` that is not a string is handed on as written and is a warning: vex gives a scoping that names no profile no rows. A name in `extends` or `without` that every object answers to (`constructor`, `toString`) and the charter does not define is a warning: it adds or takes away nothing. With a `shape` error the verifier reports the shape findings and checks nothing else |
218
226
  | *(closure)* | via `RoleClosure.issues` | cross-action wiring problems from the injected auditor |
219
227
 
220
228
  ---
package/README.md CHANGED
@@ -42,14 +42,14 @@ 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
- - **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.
49
- - **A verifier that refuses.** `verifyCharter` runs the opinions the grammar deliberately omits: a dead deny is an **error** (a typo'd deny fails silent, and silent means unprotected); a dead allow is a warning; ambiguous selections, namespace-as-action, orphan actions, re-allowed ancestor denies all surface. "If it boots, it's coherent."
48
+ - **One glob rule.** `*` matches any run of characters including dots and line breaks — `crm.*` matches `crm.deal.form`. No `**`, no braces, no regex. When a pattern can't be expressed, the fix is a better id.
49
+ - **A verifier that refuses.** `verifyCharter` runs the opinions the grammar deliberately omits: a dead deny is an **error** (a typo'd deny fails silent, and silent means unprotected); a dead allow is a warning; ambiguous selections, namespace-as-action, orphan actions, re-allowed ancestor denies all surface. "If it boots, it's coherent." A key the charter does not read (a misspelt `denny`) and a string where a list belongs are only warnings: the charter still boots, and moss prints them when it does. A `deny` or `without` the charter cannot read is an error.
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
@@ -1,18 +1,87 @@
1
1
  'use strict';
2
2
 
3
3
  // src/glob.ts
4
- var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
5
- var toRegExp = (pattern) => new RegExp(`^${pattern.split("*").map(escapeRegExp).join(".*")}$`);
6
- var matchGlob = (pattern, id) => toRegExp(pattern).test(id);
4
+ var matchGlob = (pattern, id) => {
5
+ const parts = pattern.split("*");
6
+ const first = parts[0] ?? "";
7
+ if (parts.length === 1) return id === first;
8
+ const last = parts[parts.length - 1] ?? "";
9
+ if (id.length < first.length + last.length || !id.startsWith(first) || !id.endsWith(last)) return false;
10
+ const middle = id.slice(first.length, id.length - last.length);
11
+ let at = 0;
12
+ for (const part of parts.slice(1, -1)) {
13
+ const found = middle.indexOf(part, at);
14
+ if (found < 0) return false;
15
+ at = found + part.length;
16
+ }
17
+ return true;
18
+ };
7
19
  var matchAll = (patterns, ids) => {
8
20
  const out = /* @__PURE__ */ new Set();
9
- for (const pattern of patterns) {
10
- const re = toRegExp(pattern);
11
- for (const id of ids) if (re.test(id)) out.add(id);
12
- }
21
+ for (const pattern of patterns) for (const id of ids) if (matchGlob(pattern, id)) out.add(id);
13
22
  return out;
14
23
  };
15
24
 
25
+ // src/shape.ts
26
+ var fieldsOf = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? new Map(Object.entries(value)) : void 0;
27
+ var listOf = (value) => typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" ? [entry] : []) : [];
28
+ var ROLE_KEYS = /* @__PURE__ */ new Set(["extends", "without", "allow", "deny", "actions", "data", "layouts", "functions", "scoping"]);
29
+ var SELECTION_KEYS = /* @__PURE__ */ new Set(["allow", "deny"]);
30
+ var SECTIONS = ["actions", "data", "layouts", "functions"];
31
+ var ADDING = ["extends", "allow"];
32
+ var TAKING_AWAY = ["without", "deny"];
33
+ var NOTHING = { errors: [], warnings: [] };
34
+ var merged = (shapes) => ({ errors: shapes.flatMap((shape) => shape.errors), warnings: shapes.flatMap((shape) => shape.warnings) });
35
+ var shown = (value) => typeof value === "string" ? `the string ${JSON.stringify(value)}` : String(JSON.stringify(value));
36
+ var unreadKeys = (role, fields, known, prefix) => ({
37
+ errors: [],
38
+ warnings: [...fields.keys()].flatMap((key) => known.has(key) ? [] : [`role "${role}" has the key "${prefix}${key}", which the charter does not read: what it lists does not apply`])
39
+ });
40
+ var listShape = (role, key, value, takesAway) => {
41
+ const why = takesAway ? "what it takes away cannot be read" : "it grants nothing";
42
+ const found = (detail) => takesAway ? { errors: [detail], warnings: [] } : { errors: [], warnings: [detail] };
43
+ if (value === void 0 || value === null) return NOTHING;
44
+ if (typeof value === "string") return { errors: [], warnings: [`role "${role}": "${key}" is ${shown(value)}, read as the list ${JSON.stringify([value])}`] };
45
+ if (!Array.isArray(value)) return found(`role "${role}": "${key}" is ${shown(value)}, which is not a list: ${why}`);
46
+ return merged(value.map((entry) => typeof entry === "string" ? NOTHING : found(`role "${role}": "${key}" lists ${shown(entry)}, which is not a string: ${why}`)));
47
+ };
48
+ var sectionShape = (role, section, value) => {
49
+ if (value === void 0) return NOTHING;
50
+ if (Array.isArray(value)) return listShape(role, section, value, false);
51
+ const fields = fieldsOf(value);
52
+ if (fields === void 0) {
53
+ return { errors: [], warnings: [`role "${role}": "${section}" is ${shown(value)}, which grants nothing: a section is a list of globs or { allow, deny }`] };
54
+ }
55
+ return merged([
56
+ unreadKeys(role, fields, SELECTION_KEYS, `${section}.`),
57
+ listShape(role, `${section}.allow`, fields.get("allow"), false),
58
+ listShape(role, `${section}.deny`, fields.get("deny"), true)
59
+ ]);
60
+ };
61
+ var scopingShape = (role, scoping) => scoping === void 0 || typeof scoping === "string" ? NOTHING : { errors: [], warnings: [`role "${role}": "scoping" is ${shown(scoping)}, which is not a name: the role reaches no rows`] };
62
+ var roleShape = (role, def) => {
63
+ if (Array.isArray(def)) return listShape(role, "actions", def, false);
64
+ if (def === null) return { errors: [`role "${role}" is null, which is not a list or an object: what it grants and takes away cannot be read`], warnings: [] };
65
+ const fields = fieldsOf(def);
66
+ if (fields === void 0) return { errors: [], warnings: [`role "${role}" is ${shown(def)}, which grants nothing: a role is a list of globs or an object`] };
67
+ return merged([
68
+ unreadKeys(role, fields, ROLE_KEYS, ""),
69
+ ...ADDING.map((key) => listShape(role, key, fields.get(key), false)),
70
+ ...TAKING_AWAY.map((key) => listShape(role, key, fields.get(key), true)),
71
+ ...SECTIONS.map((section) => sectionShape(role, section, fields.get(section))),
72
+ scopingShape(role, fields.get("scoping"))
73
+ ]);
74
+ };
75
+ var roleOf = (charter, role) => Object.hasOwn(charter, role) ? charter[role] : void 0;
76
+ var inheritedNames = (charter, role, def) => {
77
+ const fields = fieldsOf(def);
78
+ const said = (key, effect) => listOf(fields?.get(key)).flatMap(
79
+ (name) => name in charter && !Object.hasOwn(charter, name) ? [`role "${role}": "${key}" names "${name}", which the charter does not define: ${effect}`] : []
80
+ );
81
+ return { errors: [], warnings: [...said("extends", "it adds nothing"), ...said("without", "it takes nothing away")] };
82
+ };
83
+ var charterShape = (charter) => merged(Object.entries(charter).flatMap(([role, def]) => [roleShape(role, def), inheritedNames(charter, role, def)]));
84
+
16
85
  // src/resolve.ts
17
86
  var CharterError = class extends Error {
18
87
  constructor(message) {
@@ -20,21 +89,30 @@ var CharterError = class extends Error {
20
89
  this.name = "CharterError";
21
90
  }
22
91
  };
23
- var asSelection = (s) => s === void 0 ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };
92
+ var asSelection = (selection) => {
93
+ if (Array.isArray(selection)) return { allow: listOf(selection), deny: [] };
94
+ const fields = fieldsOf(selection);
95
+ return { allow: listOf(fields?.get("allow")), deny: listOf(fields?.get("deny")) };
96
+ };
24
97
  var normalizeRole = (def, section) => {
25
98
  if (Array.isArray(def)) {
26
- return section === "actions" ? { allow: def, deny: [], extends: [], without: [] } : { allow: [], deny: [], extends: [], without: [] };
99
+ return section === "actions" ? { allow: listOf(def), deny: [], extends: [], without: [] } : { allow: [], deny: [], extends: [], without: [] };
27
100
  }
28
- const composition = { extends: def.extends ?? [], without: def.without ?? [] };
29
- const sel = section === "actions" && def.actions === void 0 ? { allow: def.allow ?? [], deny: def.deny ?? [] } : asSelection(def[section]);
30
- return { ...sel, ...composition };
101
+ const fields = fieldsOf(def);
102
+ const composition = { extends: listOf(fields?.get("extends")), without: listOf(fields?.get("without")) };
103
+ if (section !== "actions") return { ...asSelection(fields?.get(section)), ...composition };
104
+ if (fields?.has("actions") !== true) return { allow: listOf(fields?.get("allow")), deny: listOf(fields?.get("deny")), ...composition };
105
+ const sel = asSelection(fields.get("actions"));
106
+ return { allow: sel.allow, deny: [...sel.deny, ...listOf(fields.get("deny"))], ...composition };
31
107
  };
32
108
  var resolveRole = (charter, universe, role, section, memo = /* @__PURE__ */ new Map(), visiting = /* @__PURE__ */ new Set()) => {
33
109
  const cached = memo.get(role);
34
110
  if (cached !== void 0) return cached;
35
- const def = charter[role];
111
+ const def = role in charter && !Object.hasOwn(charter, role) ? [] : charter[role];
36
112
  if (def === void 0) throw new CharterError(`Unknown role "${role}"`);
37
113
  if (visiting.has(role)) throw new CharterError(`Role cycle through "${role}"`);
114
+ const unreadable = roleShape(role, def).errors[0];
115
+ if (unreadable !== void 0) throw new CharterError(unreadable);
38
116
  visiting.add(role);
39
117
  const { allow, extends: parents, deny, without } = normalizeRole(def, section);
40
118
  const resolved = /* @__PURE__ */ new Set();
@@ -47,8 +125,8 @@ var resolveRole = (charter, universe, role, section, memo = /* @__PURE__ */ new
47
125
  return resolved;
48
126
  };
49
127
  var resolveScoping = (charter, role) => {
50
- const def = charter[role];
51
- return def === void 0 || Array.isArray(def) ? void 0 : def.scoping;
128
+ const def = roleOf(charter, role);
129
+ return !def || Array.isArray(def) ? void 0 : def.scoping;
52
130
  };
53
131
  var resolvePrincipal = (charter, universe, roles, section = "actions") => {
54
132
  const memo = /* @__PURE__ */ new Map();
@@ -72,9 +150,11 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
72
150
  layouts: universes.layouts ?? [],
73
151
  functions: universes.functions ?? []
74
152
  };
75
- const errors = [];
76
- const warnings = [];
153
+ const shape = charterShape(charter);
154
+ const errors = shape.errors.map((detail) => ({ level: "error", rule: "shape", detail }));
155
+ const warnings = shape.warnings.map((detail) => ({ level: "warning", rule: "shape", detail }));
77
156
  const perRole = [];
157
+ if (errors.length > 0) return { errors, warnings, perRole };
78
158
  const resolved = { actions: /* @__PURE__ */ new Map(), data: /* @__PURE__ */ new Map(), layouts: /* @__PURE__ */ new Map(), functions: /* @__PURE__ */ new Map() };
79
159
  for (const section of sections) {
80
160
  const memo = /* @__PURE__ */ new Map();
@@ -99,8 +179,8 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
99
179
  leavesOnly(actionUniverse, "actions");
100
180
  if (universes.layouts !== void 0) leavesOnly(universes.layouts, "variants");
101
181
  for (const [role, def] of Object.entries(charter)) {
102
- if (Array.isArray(def)) continue;
103
- if (def.actions !== void 0 && (def.allow !== void 0 || def.deny !== void 0)) {
182
+ const fields = fieldsOf(def);
183
+ if (fields?.has("actions") === true && (fields.has("allow") || fields.has("deny"))) {
104
184
  errors.push({ level: "error", rule: "ambiguous-selection", detail: `role "${role}" has both top-level allow/deny and an "actions" section \u2014 one selection per section` });
105
185
  }
106
186
  }
@@ -131,11 +211,11 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
131
211
  if (universes.functions !== void 0) orphans("functions", "function");
132
212
  const ancestorDenied = (role, section, seen = /* @__PURE__ */ new Set()) => {
133
213
  const out = /* @__PURE__ */ new Set();
134
- const def = charter[role];
214
+ const def = roleOf(charter, role);
135
215
  if (def === void 0 || seen.has(role)) return out;
136
216
  seen.add(role);
137
217
  for (const parent of normalizeRole(def, section).extends) {
138
- const parentDef = charter[parent];
218
+ const parentDef = roleOf(charter, parent);
139
219
  if (parentDef === void 0) continue;
140
220
  for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);
141
221
  for (const id of ancestorDenied(parent, section, seen)) out.add(id);
@@ -152,10 +232,7 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
152
232
  }
153
233
  }
154
234
  const subtractive = /* @__PURE__ */ new Set();
155
- for (const def of Object.values(charter)) {
156
- if (Array.isArray(def)) continue;
157
- for (const sub of def.without ?? []) subtractive.add(sub);
158
- }
235
+ for (const def of Object.values(charter)) for (const sub of normalizeRole(def, "actions").without) subtractive.add(sub);
159
236
  const worn = new Set(wearable.flat());
160
237
  for (const role of subtractive) {
161
238
  if (worn.has(role)) {
@@ -167,7 +244,8 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
167
244
  const data = [...resolved.data.get(role) ?? []].sort();
168
245
  const layouts = [...resolved.layouts.get(role) ?? []].sort();
169
246
  const issues = closure?.(actions, layouts) ?? [];
170
- perRole.push({ role, actions, data, layouts, issues });
247
+ const functions = universes.functions === void 0 ? {} : { functions: [...resolved.functions.get(role) ?? []].sort() };
248
+ perRole.push({ role, actions, data, layouts, ...functions, issues });
171
249
  }
172
250
  return { errors, warnings, perRole };
173
251
  };
@@ -1 +1 @@
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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.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"]}
1
+ {"version":3,"sources":["../src/glob.ts","../src/shape.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";;;AACO,IAAM,SAAA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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,MAAM,YAAY,SAAA,CAAU,SAAA,KAAc,SAAY,EAAC,GAAI,EAAE,SAAA,EAAW,CAAC,GAAI,QAAA,CAAS,SAAA,CAAU,IAAI,IAAI,CAAA,IAAK,EAAG,CAAA,CAAE,MAAK,EAAE;AACzH,IAAA,OAAA,CAAQ,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,EAAS,MAAM,OAAA,EAAS,GAAG,SAAA,EAAW,MAAA,EAAQ,CAAA;AAAA,EACrE;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,QAAA,EAAU,OAAA,EAAQ;AACrC","file":"index.cjs","sourcesContent":["// Not a regular expression: one made from a pattern with many stars backtracks for as long as the id allows.\nexport const matchGlob = (pattern: string, id: string): boolean => {\n const parts = pattern.split('*');\n const first = parts[0] ?? '';\n if (parts.length === 1) return id === first;\n const last = parts[parts.length - 1] ?? '';\n if (id.length < first.length + last.length || !id.startsWith(first) || !id.endsWith(last)) return false;\n const middle = id.slice(first.length, id.length - last.length);\n let at = 0;\n for (const part of parts.slice(1, -1)) {\n const found = middle.indexOf(part, at);\n if (found < 0) return false;\n at = found + part.length;\n }\n return true;\n};\n\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) for (const id of ids) if (matchGlob(pattern, id)) out.add(id);\n return out;\n};\n","import type { Charter } from './types';\n\nexport type RoleFields = ReadonlyMap<string, unknown>;\n\n// A charter read from JSON is whatever was written, so it is read from `unknown`.\nexport const fieldsOf = (value: unknown): RoleFields | undefined =>\n typeof value === 'object' && value !== null && !Array.isArray(value) ? new Map<string, unknown>(Object.entries(value)) : undefined;\n\nexport const listOf = (value: unknown): string[] =>\n typeof value === 'string' ? [value] : Array.isArray(value) ? value.flatMap((entry: unknown) => (typeof entry === 'string' ? [entry] : [])) : [];\n\nexport type CharterShape = { errors: string[]; warnings: string[] };\n\nconst ROLE_KEYS: ReadonlySet<string> = new Set(['extends', 'without', 'allow', 'deny', 'actions', 'data', 'layouts', 'functions', 'scoping']);\nconst SELECTION_KEYS: ReadonlySet<string> = new Set(['allow', 'deny']);\nconst SECTIONS = ['actions', 'data', 'layouts', 'functions'] as const;\nconst ADDING = ['extends', 'allow'] as const;\nconst TAKING_AWAY = ['without', 'deny'] as const;\n\nconst NOTHING: CharterShape = { errors: [], warnings: [] };\n\nconst merged = (shapes: readonly CharterShape[]): CharterShape => ({ errors: shapes.flatMap((shape) => shape.errors), warnings: shapes.flatMap((shape) => shape.warnings) });\n\nconst shown = (value: unknown): string => (typeof value === 'string' ? `the string ${JSON.stringify(value)}` : String(JSON.stringify(value)));\n\nconst unreadKeys = (role: string, fields: RoleFields, known: ReadonlySet<string>, prefix: string): CharterShape => ({\n errors: [],\n warnings: [...fields.keys()].flatMap((key) => (known.has(key) ? [] : [`role \"${role}\" has the key \"${prefix}${key}\", which the charter does not read: what it lists does not apply`])),\n});\n\n// What cannot be read is read as nothing. Where that grants less it is said; where it would take away less it is refused.\nconst listShape = (role: string, key: string, value: unknown, takesAway: boolean): CharterShape => {\n const why = takesAway ? 'what it takes away cannot be read' : 'it grants nothing';\n const found = (detail: string): CharterShape => (takesAway ? { errors: [detail], warnings: [] } : { errors: [], warnings: [detail] });\n if (value === undefined || value === null) return NOTHING;\n if (typeof value === 'string') return { errors: [], warnings: [`role \"${role}\": \"${key}\" is ${shown(value)}, read as the list ${JSON.stringify([value])}`] };\n if (!Array.isArray(value)) return found(`role \"${role}\": \"${key}\" is ${shown(value)}, which is not a list: ${why}`);\n return merged(value.map((entry: unknown) => (typeof entry === 'string' ? NOTHING : found(`role \"${role}\": \"${key}\" lists ${shown(entry)}, which is not a string: ${why}`))));\n};\n\nconst sectionShape = (role: string, section: string, value: unknown): CharterShape => {\n if (value === undefined) return NOTHING;\n if (Array.isArray(value)) return listShape(role, section, value, false);\n const fields = fieldsOf(value);\n if (fields === undefined) {\n return { errors: [], warnings: [`role \"${role}\": \"${section}\" is ${shown(value)}, which grants nothing: a section is a list of globs or { allow, deny }`] };\n }\n return merged([\n unreadKeys(role, fields, SELECTION_KEYS, `${section}.`),\n listShape(role, `${section}.allow`, fields.get('allow'), false),\n listShape(role, `${section}.deny`, fields.get('deny'), true),\n ]);\n};\n\n// vex gives a scoping that names no profile no rows.\nconst scopingShape = (role: string, scoping: unknown): CharterShape =>\n scoping === undefined || typeof scoping === 'string' ? NOTHING : { errors: [], warnings: [`role \"${role}\": \"scoping\" is ${shown(scoping)}, which is not a name: the role reaches no rows`] };\n\nexport const roleShape = (role: string, def: unknown): CharterShape => {\n if (Array.isArray(def)) return listShape(role, 'actions', def, false);\n // Read as an empty role, a null one named in a \"without\" would take away nothing.\n if (def === null) return { errors: [`role \"${role}\" is null, which is not a list or an object: what it grants and takes away cannot be read`], warnings: [] };\n const fields = fieldsOf(def);\n if (fields === undefined) return { errors: [], warnings: [`role \"${role}\" is ${shown(def)}, which grants nothing: a role is a list of globs or an object`] };\n return merged([\n unreadKeys(role, fields, ROLE_KEYS, ''),\n ...ADDING.map((key) => listShape(role, key, fields.get(key), false)),\n ...TAKING_AWAY.map((key) => listShape(role, key, fields.get(key), true)),\n ...SECTIONS.map((section) => sectionShape(role, section, fields.get(section))),\n scopingShape(role, fields.get('scoping')),\n ]);\n};\n\nexport const roleOf = (charter: Charter, role: string): Charter[string] | undefined => (Object.hasOwn(charter, role) ? charter[role] : undefined);\n\n// Every object answers to `constructor` or `toString`: named in \"extends\" or \"without\" and not defined by the charter, it reads as an empty role.\nconst inheritedNames = (charter: Charter, role: string, def: unknown): CharterShape => {\n const fields = fieldsOf(def);\n const said = (key: 'extends' | 'without', effect: string): string[] =>\n listOf(fields?.get(key)).flatMap((name) =>\n name in charter && !Object.hasOwn(charter, name) ? [`role \"${role}\": \"${key}\" names \"${name}\", which the charter does not define: ${effect}`] : [],\n );\n return { errors: [], warnings: [...said('extends', 'it adds nothing'), ...said('without', 'it takes nothing away')] };\n};\n\nexport const charterShape = (charter: Charter): CharterShape =>\n merged(Object.entries(charter).flatMap(([role, def]) => [roleShape(role, def), inheritedNames(charter, role, def)]));\n","import type { Charter, RoleDef, Section } from './types';\nimport { matchAll } from './glob';\nimport { fieldsOf, listOf, roleOf, roleShape } from './shape';\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\nconst asSelection = (selection: unknown): { allow: string[]; deny: string[] } => {\n if (Array.isArray(selection)) return { allow: listOf(selection), deny: [] };\n const fields = fieldsOf(selection);\n return { allow: listOf(fields?.get('allow')), deny: listOf(fields?.get('deny')) };\n};\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: listOf(def), deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const fields = fieldsOf(def);\n const composition = { extends: listOf(fields?.get('extends')), without: listOf(fields?.get('without')) };\n if (section !== 'actions') return { ...asSelection(fields?.get(section)), ...composition };\n if (fields?.has('actions') !== true) return { allow: listOf(fields?.get('allow')), deny: listOf(fields?.get('deny')), ...composition };\n // The verifier refuses this pair. Resolved anyway, the top-level deny still takes away; the top-level allow would grant more, so it is not read.\n const sel = asSelection(fields.get('actions'));\n return { allow: sel.allow, deny: [...sel.deny, ...listOf(fields.get('deny'))], ...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 // A name every object answers to and the charter does not define reads as an empty role; the shape check says so.\n const def = role in charter && !Object.hasOwn(charter, role) ? [] : 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 const unreadable = roleShape(role, def).errors[0];\n if (unreadable !== undefined) throw new CharterError(unreadable);\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 = roleOf(charter, role);\n return !def || 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';\nimport { charterShape, fieldsOf, roleOf } from './shape';\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; functions?: 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 shape = charterShape(charter);\n const errors: VerifyIssue[] = shape.errors.map((detail) => ({ level: 'error', rule: 'shape', detail }));\n const warnings: VerifyIssue[] = shape.warnings.map((detail) => ({ level: 'warning', rule: 'shape', detail }));\n const perRole: RoleClosure[] = [];\n // Resolving a role that cannot be read throws, so every check below would say it again.\n if (errors.length > 0) return { errors, warnings, perRole };\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 const fields = fieldsOf(def);\n if (fields?.has('actions') === true && (fields.has('allow') || fields.has('deny'))) {\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 = roleOf(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 = roleOf(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)) for (const sub of normalizeRole(def, 'actions').without) subtractive.add(sub);\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 const functions = universes.functions === undefined ? {} : { functions: [...(resolved.functions.get(role) ?? [])].sort() };\n perRole.push({ role, actions, data, layouts, ...functions, issues });\n }\n\n return { errors, warnings, perRole };\n};\n"]}
package/dist/index.d.cts CHANGED
@@ -42,6 +42,7 @@ type RoleClosure = {
42
42
  actions: string[];
43
43
  data: string[];
44
44
  layouts: string[];
45
+ functions?: string[];
45
46
  issues: string[];
46
47
  };
47
48
  type VerifyReport = {
package/dist/index.d.ts CHANGED
@@ -42,6 +42,7 @@ type RoleClosure = {
42
42
  actions: string[];
43
43
  data: string[];
44
44
  layouts: string[];
45
+ functions?: string[];
45
46
  issues: string[];
46
47
  };
47
48
  type VerifyReport = {
package/dist/index.js CHANGED
@@ -1,16 +1,85 @@
1
1
  // src/glob.ts
2
- var escapeRegExp = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3
- var toRegExp = (pattern) => new RegExp(`^${pattern.split("*").map(escapeRegExp).join(".*")}$`);
4
- var matchGlob = (pattern, id) => toRegExp(pattern).test(id);
2
+ var matchGlob = (pattern, id) => {
3
+ const parts = pattern.split("*");
4
+ const first = parts[0] ?? "";
5
+ if (parts.length === 1) return id === first;
6
+ const last = parts[parts.length - 1] ?? "";
7
+ if (id.length < first.length + last.length || !id.startsWith(first) || !id.endsWith(last)) return false;
8
+ const middle = id.slice(first.length, id.length - last.length);
9
+ let at = 0;
10
+ for (const part of parts.slice(1, -1)) {
11
+ const found = middle.indexOf(part, at);
12
+ if (found < 0) return false;
13
+ at = found + part.length;
14
+ }
15
+ return true;
16
+ };
5
17
  var matchAll = (patterns, ids) => {
6
18
  const out = /* @__PURE__ */ new Set();
7
- for (const pattern of patterns) {
8
- const re = toRegExp(pattern);
9
- for (const id of ids) if (re.test(id)) out.add(id);
10
- }
19
+ for (const pattern of patterns) for (const id of ids) if (matchGlob(pattern, id)) out.add(id);
11
20
  return out;
12
21
  };
13
22
 
23
+ // src/shape.ts
24
+ var fieldsOf = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? new Map(Object.entries(value)) : void 0;
25
+ var listOf = (value) => typeof value === "string" ? [value] : Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" ? [entry] : []) : [];
26
+ var ROLE_KEYS = /* @__PURE__ */ new Set(["extends", "without", "allow", "deny", "actions", "data", "layouts", "functions", "scoping"]);
27
+ var SELECTION_KEYS = /* @__PURE__ */ new Set(["allow", "deny"]);
28
+ var SECTIONS = ["actions", "data", "layouts", "functions"];
29
+ var ADDING = ["extends", "allow"];
30
+ var TAKING_AWAY = ["without", "deny"];
31
+ var NOTHING = { errors: [], warnings: [] };
32
+ var merged = (shapes) => ({ errors: shapes.flatMap((shape) => shape.errors), warnings: shapes.flatMap((shape) => shape.warnings) });
33
+ var shown = (value) => typeof value === "string" ? `the string ${JSON.stringify(value)}` : String(JSON.stringify(value));
34
+ var unreadKeys = (role, fields, known, prefix) => ({
35
+ errors: [],
36
+ warnings: [...fields.keys()].flatMap((key) => known.has(key) ? [] : [`role "${role}" has the key "${prefix}${key}", which the charter does not read: what it lists does not apply`])
37
+ });
38
+ var listShape = (role, key, value, takesAway) => {
39
+ const why = takesAway ? "what it takes away cannot be read" : "it grants nothing";
40
+ const found = (detail) => takesAway ? { errors: [detail], warnings: [] } : { errors: [], warnings: [detail] };
41
+ if (value === void 0 || value === null) return NOTHING;
42
+ if (typeof value === "string") return { errors: [], warnings: [`role "${role}": "${key}" is ${shown(value)}, read as the list ${JSON.stringify([value])}`] };
43
+ if (!Array.isArray(value)) return found(`role "${role}": "${key}" is ${shown(value)}, which is not a list: ${why}`);
44
+ return merged(value.map((entry) => typeof entry === "string" ? NOTHING : found(`role "${role}": "${key}" lists ${shown(entry)}, which is not a string: ${why}`)));
45
+ };
46
+ var sectionShape = (role, section, value) => {
47
+ if (value === void 0) return NOTHING;
48
+ if (Array.isArray(value)) return listShape(role, section, value, false);
49
+ const fields = fieldsOf(value);
50
+ if (fields === void 0) {
51
+ return { errors: [], warnings: [`role "${role}": "${section}" is ${shown(value)}, which grants nothing: a section is a list of globs or { allow, deny }`] };
52
+ }
53
+ return merged([
54
+ unreadKeys(role, fields, SELECTION_KEYS, `${section}.`),
55
+ listShape(role, `${section}.allow`, fields.get("allow"), false),
56
+ listShape(role, `${section}.deny`, fields.get("deny"), true)
57
+ ]);
58
+ };
59
+ var scopingShape = (role, scoping) => scoping === void 0 || typeof scoping === "string" ? NOTHING : { errors: [], warnings: [`role "${role}": "scoping" is ${shown(scoping)}, which is not a name: the role reaches no rows`] };
60
+ var roleShape = (role, def) => {
61
+ if (Array.isArray(def)) return listShape(role, "actions", def, false);
62
+ if (def === null) return { errors: [`role "${role}" is null, which is not a list or an object: what it grants and takes away cannot be read`], warnings: [] };
63
+ const fields = fieldsOf(def);
64
+ if (fields === void 0) return { errors: [], warnings: [`role "${role}" is ${shown(def)}, which grants nothing: a role is a list of globs or an object`] };
65
+ return merged([
66
+ unreadKeys(role, fields, ROLE_KEYS, ""),
67
+ ...ADDING.map((key) => listShape(role, key, fields.get(key), false)),
68
+ ...TAKING_AWAY.map((key) => listShape(role, key, fields.get(key), true)),
69
+ ...SECTIONS.map((section) => sectionShape(role, section, fields.get(section))),
70
+ scopingShape(role, fields.get("scoping"))
71
+ ]);
72
+ };
73
+ var roleOf = (charter, role) => Object.hasOwn(charter, role) ? charter[role] : void 0;
74
+ var inheritedNames = (charter, role, def) => {
75
+ const fields = fieldsOf(def);
76
+ const said = (key, effect) => listOf(fields?.get(key)).flatMap(
77
+ (name) => name in charter && !Object.hasOwn(charter, name) ? [`role "${role}": "${key}" names "${name}", which the charter does not define: ${effect}`] : []
78
+ );
79
+ return { errors: [], warnings: [...said("extends", "it adds nothing"), ...said("without", "it takes nothing away")] };
80
+ };
81
+ var charterShape = (charter) => merged(Object.entries(charter).flatMap(([role, def]) => [roleShape(role, def), inheritedNames(charter, role, def)]));
82
+
14
83
  // src/resolve.ts
15
84
  var CharterError = class extends Error {
16
85
  constructor(message) {
@@ -18,21 +87,30 @@ var CharterError = class extends Error {
18
87
  this.name = "CharterError";
19
88
  }
20
89
  };
21
- var asSelection = (s) => s === void 0 ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };
90
+ var asSelection = (selection) => {
91
+ if (Array.isArray(selection)) return { allow: listOf(selection), deny: [] };
92
+ const fields = fieldsOf(selection);
93
+ return { allow: listOf(fields?.get("allow")), deny: listOf(fields?.get("deny")) };
94
+ };
22
95
  var normalizeRole = (def, section) => {
23
96
  if (Array.isArray(def)) {
24
- return section === "actions" ? { allow: def, deny: [], extends: [], without: [] } : { allow: [], deny: [], extends: [], without: [] };
97
+ return section === "actions" ? { allow: listOf(def), deny: [], extends: [], without: [] } : { allow: [], deny: [], extends: [], without: [] };
25
98
  }
26
- const composition = { extends: def.extends ?? [], without: def.without ?? [] };
27
- const sel = section === "actions" && def.actions === void 0 ? { allow: def.allow ?? [], deny: def.deny ?? [] } : asSelection(def[section]);
28
- return { ...sel, ...composition };
99
+ const fields = fieldsOf(def);
100
+ const composition = { extends: listOf(fields?.get("extends")), without: listOf(fields?.get("without")) };
101
+ if (section !== "actions") return { ...asSelection(fields?.get(section)), ...composition };
102
+ if (fields?.has("actions") !== true) return { allow: listOf(fields?.get("allow")), deny: listOf(fields?.get("deny")), ...composition };
103
+ const sel = asSelection(fields.get("actions"));
104
+ return { allow: sel.allow, deny: [...sel.deny, ...listOf(fields.get("deny"))], ...composition };
29
105
  };
30
106
  var resolveRole = (charter, universe, role, section, memo = /* @__PURE__ */ new Map(), visiting = /* @__PURE__ */ new Set()) => {
31
107
  const cached = memo.get(role);
32
108
  if (cached !== void 0) return cached;
33
- const def = charter[role];
109
+ const def = role in charter && !Object.hasOwn(charter, role) ? [] : charter[role];
34
110
  if (def === void 0) throw new CharterError(`Unknown role "${role}"`);
35
111
  if (visiting.has(role)) throw new CharterError(`Role cycle through "${role}"`);
112
+ const unreadable = roleShape(role, def).errors[0];
113
+ if (unreadable !== void 0) throw new CharterError(unreadable);
36
114
  visiting.add(role);
37
115
  const { allow, extends: parents, deny, without } = normalizeRole(def, section);
38
116
  const resolved = /* @__PURE__ */ new Set();
@@ -45,8 +123,8 @@ var resolveRole = (charter, universe, role, section, memo = /* @__PURE__ */ new
45
123
  return resolved;
46
124
  };
47
125
  var resolveScoping = (charter, role) => {
48
- const def = charter[role];
49
- return def === void 0 || Array.isArray(def) ? void 0 : def.scoping;
126
+ const def = roleOf(charter, role);
127
+ return !def || Array.isArray(def) ? void 0 : def.scoping;
50
128
  };
51
129
  var resolvePrincipal = (charter, universe, roles, section = "actions") => {
52
130
  const memo = /* @__PURE__ */ new Map();
@@ -70,9 +148,11 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
70
148
  layouts: universes.layouts ?? [],
71
149
  functions: universes.functions ?? []
72
150
  };
73
- const errors = [];
74
- const warnings = [];
151
+ const shape = charterShape(charter);
152
+ const errors = shape.errors.map((detail) => ({ level: "error", rule: "shape", detail }));
153
+ const warnings = shape.warnings.map((detail) => ({ level: "warning", rule: "shape", detail }));
75
154
  const perRole = [];
155
+ if (errors.length > 0) return { errors, warnings, perRole };
76
156
  const resolved = { actions: /* @__PURE__ */ new Map(), data: /* @__PURE__ */ new Map(), layouts: /* @__PURE__ */ new Map(), functions: /* @__PURE__ */ new Map() };
77
157
  for (const section of sections) {
78
158
  const memo = /* @__PURE__ */ new Map();
@@ -97,8 +177,8 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
97
177
  leavesOnly(actionUniverse, "actions");
98
178
  if (universes.layouts !== void 0) leavesOnly(universes.layouts, "variants");
99
179
  for (const [role, def] of Object.entries(charter)) {
100
- if (Array.isArray(def)) continue;
101
- if (def.actions !== void 0 && (def.allow !== void 0 || def.deny !== void 0)) {
180
+ const fields = fieldsOf(def);
181
+ if (fields?.has("actions") === true && (fields.has("allow") || fields.has("deny"))) {
102
182
  errors.push({ level: "error", rule: "ambiguous-selection", detail: `role "${role}" has both top-level allow/deny and an "actions" section \u2014 one selection per section` });
103
183
  }
104
184
  }
@@ -129,11 +209,11 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
129
209
  if (universes.functions !== void 0) orphans("functions", "function");
130
210
  const ancestorDenied = (role, section, seen = /* @__PURE__ */ new Set()) => {
131
211
  const out = /* @__PURE__ */ new Set();
132
- const def = charter[role];
212
+ const def = roleOf(charter, role);
133
213
  if (def === void 0 || seen.has(role)) return out;
134
214
  seen.add(role);
135
215
  for (const parent of normalizeRole(def, section).extends) {
136
- const parentDef = charter[parent];
216
+ const parentDef = roleOf(charter, parent);
137
217
  if (parentDef === void 0) continue;
138
218
  for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);
139
219
  for (const id of ancestorDenied(parent, section, seen)) out.add(id);
@@ -150,10 +230,7 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
150
230
  }
151
231
  }
152
232
  const subtractive = /* @__PURE__ */ new Set();
153
- for (const def of Object.values(charter)) {
154
- if (Array.isArray(def)) continue;
155
- for (const sub of def.without ?? []) subtractive.add(sub);
156
- }
233
+ for (const def of Object.values(charter)) for (const sub of normalizeRole(def, "actions").without) subtractive.add(sub);
157
234
  const worn = new Set(wearable.flat());
158
235
  for (const role of subtractive) {
159
236
  if (worn.has(role)) {
@@ -165,7 +242,8 @@ var verifyCharter = (charter, universes, wearable = [], closure) => {
165
242
  const data = [...resolved.data.get(role) ?? []].sort();
166
243
  const layouts = [...resolved.layouts.get(role) ?? []].sort();
167
244
  const issues = closure?.(actions, layouts) ?? [];
168
- perRole.push({ role, actions, data, layouts, issues });
245
+ const functions = universes.functions === void 0 ? {} : { functions: [...resolved.functions.get(role) ?? []].sort() };
246
+ perRole.push({ role, actions, data, layouts, ...functions, issues });
169
247
  }
170
248
  return { errors, warnings, perRole };
171
249
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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,IA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D,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":["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"]}
1
+ {"version":3,"sources":["../src/glob.ts","../src/shape.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";AACO,IAAM,SAAA,GAAY,CAAC,OAAA,EAAiB,EAAA,KAAwB;AACjE,EAAA,MAAM,KAAA,GAAQ,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA;AAC/B,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,IAAK,EAAA;AAC1B,EAAA,IAAI,KAAA,CAAM,MAAA,KAAW,CAAA,EAAG,OAAO,EAAA,KAAO,KAAA;AACtC,EAAA,MAAM,IAAA,GAAO,KAAA,CAAM,KAAA,CAAM,MAAA,GAAS,CAAC,CAAA,IAAK,EAAA;AACxC,EAAA,IAAI,GAAG,MAAA,GAAS,KAAA,CAAM,MAAA,GAAS,IAAA,CAAK,UAAU,CAAC,EAAA,CAAG,UAAA,CAAW,KAAK,KAAK,CAAC,EAAA,CAAG,QAAA,CAAS,IAAI,GAAG,OAAO,KAAA;AAClG,EAAA,MAAM,MAAA,GAAS,GAAG,KAAA,CAAM,KAAA,CAAM,QAAQ,EAAA,CAAG,MAAA,GAAS,KAAK,MAAM,CAAA;AAC7D,EAAA,IAAI,EAAA,GAAK,CAAA;AACT,EAAA,KAAA,MAAW,IAAA,IAAQ,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,EAAG;AACrC,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,OAAA,CAAQ,IAAA,EAAM,EAAE,CAAA;AACrC,IAAA,IAAI,KAA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port const matchGlob = (pattern: string, id: string): boolean => {\n const parts = pattern.split('*');\n const first = parts[0] ?? '';\n if (parts.length === 1) return id === first;\n const last = parts[parts.length - 1] ?? '';\n if (id.length < first.length + last.length || !id.startsWith(first) || !id.endsWith(last)) return false;\n const middle = id.slice(first.length, id.length - last.length);\n let at = 0;\n for (const part of parts.slice(1, -1)) {\n const found = middle.indexOf(part, at);\n if (found < 0) return false;\n at = found + part.length;\n }\n return true;\n};\n\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) for (const id of ids) if (matchGlob(pattern, id)) out.add(id);\n return out;\n};\n","import type { Charter } from './types';\n\nexport type RoleFields = ReadonlyMap<string, unknown>;\n\n// A charter read from JSON is whatever was written, so it is read from `unknown`.\nexport const fieldsOf = (value: unknown): RoleFields | undefined =>\n typeof value === 'object' && value !== null && !Array.isArray(value) ? new Map<string, unknown>(Object.entries(value)) : undefined;\n\nexport const listOf = (value: unknown): string[] =>\n typeof value === 'string' ? [value] : Array.isArray(value) ? value.flatMap((entry: unknown) => (typeof entry === 'string' ? [entry] : [])) : [];\n\nexport type CharterShape = { errors: string[]; warnings: string[] };\n\nconst ROLE_KEYS: ReadonlySet<string> = new Set(['extends', 'without', 'allow', 'deny', 'actions', 'data', 'layouts', 'functions', 'scoping']);\nconst SELECTION_KEYS: ReadonlySet<string> = new Set(['allow', 'deny']);\nconst SECTIONS = ['actions', 'data', 'layouts', 'functions'] as const;\nconst ADDING = ['extends', 'allow'] as const;\nconst TAKING_AWAY = ['without', 'deny'] as const;\n\nconst NOTHING: CharterShape = { errors: [], warnings: [] };\n\nconst merged = (shapes: readonly CharterShape[]): CharterShape => ({ errors: shapes.flatMap((shape) => shape.errors), warnings: shapes.flatMap((shape) => shape.warnings) });\n\nconst shown = (value: unknown): string => (typeof value === 'string' ? `the string ${JSON.stringify(value)}` : String(JSON.stringify(value)));\n\nconst unreadKeys = (role: string, fields: RoleFields, known: ReadonlySet<string>, prefix: string): CharterShape => ({\n errors: [],\n warnings: [...fields.keys()].flatMap((key) => (known.has(key) ? [] : [`role \"${role}\" has the key \"${prefix}${key}\", which the charter does not read: what it lists does not apply`])),\n});\n\n// What cannot be read is read as nothing. Where that grants less it is said; where it would take away less it is refused.\nconst listShape = (role: string, key: string, value: unknown, takesAway: boolean): CharterShape => {\n const why = takesAway ? 'what it takes away cannot be read' : 'it grants nothing';\n const found = (detail: string): CharterShape => (takesAway ? { errors: [detail], warnings: [] } : { errors: [], warnings: [detail] });\n if (value === undefined || value === null) return NOTHING;\n if (typeof value === 'string') return { errors: [], warnings: [`role \"${role}\": \"${key}\" is ${shown(value)}, read as the list ${JSON.stringify([value])}`] };\n if (!Array.isArray(value)) return found(`role \"${role}\": \"${key}\" is ${shown(value)}, which is not a list: ${why}`);\n return merged(value.map((entry: unknown) => (typeof entry === 'string' ? NOTHING : found(`role \"${role}\": \"${key}\" lists ${shown(entry)}, which is not a string: ${why}`))));\n};\n\nconst sectionShape = (role: string, section: string, value: unknown): CharterShape => {\n if (value === undefined) return NOTHING;\n if (Array.isArray(value)) return listShape(role, section, value, false);\n const fields = fieldsOf(value);\n if (fields === undefined) {\n return { errors: [], warnings: [`role \"${role}\": \"${section}\" is ${shown(value)}, which grants nothing: a section is a list of globs or { allow, deny }`] };\n }\n return merged([\n unreadKeys(role, fields, SELECTION_KEYS, `${section}.`),\n listShape(role, `${section}.allow`, fields.get('allow'), false),\n listShape(role, `${section}.deny`, fields.get('deny'), true),\n ]);\n};\n\n// vex gives a scoping that names no profile no rows.\nconst scopingShape = (role: string, scoping: unknown): CharterShape =>\n scoping === undefined || typeof scoping === 'string' ? NOTHING : { errors: [], warnings: [`role \"${role}\": \"scoping\" is ${shown(scoping)}, which is not a name: the role reaches no rows`] };\n\nexport const roleShape = (role: string, def: unknown): CharterShape => {\n if (Array.isArray(def)) return listShape(role, 'actions', def, false);\n // Read as an empty role, a null one named in a \"without\" would take away nothing.\n if (def === null) return { errors: [`role \"${role}\" is null, which is not a list or an object: what it grants and takes away cannot be read`], warnings: [] };\n const fields = fieldsOf(def);\n if (fields === undefined) return { errors: [], warnings: [`role \"${role}\" is ${shown(def)}, which grants nothing: a role is a list of globs or an object`] };\n return merged([\n unreadKeys(role, fields, ROLE_KEYS, ''),\n ...ADDING.map((key) => listShape(role, key, fields.get(key), false)),\n ...TAKING_AWAY.map((key) => listShape(role, key, fields.get(key), true)),\n ...SECTIONS.map((section) => sectionShape(role, section, fields.get(section))),\n scopingShape(role, fields.get('scoping')),\n ]);\n};\n\nexport const roleOf = (charter: Charter, role: string): Charter[string] | undefined => (Object.hasOwn(charter, role) ? charter[role] : undefined);\n\n// Every object answers to `constructor` or `toString`: named in \"extends\" or \"without\" and not defined by the charter, it reads as an empty role.\nconst inheritedNames = (charter: Charter, role: string, def: unknown): CharterShape => {\n const fields = fieldsOf(def);\n const said = (key: 'extends' | 'without', effect: string): string[] =>\n listOf(fields?.get(key)).flatMap((name) =>\n name in charter && !Object.hasOwn(charter, name) ? [`role \"${role}\": \"${key}\" names \"${name}\", which the charter does not define: ${effect}`] : [],\n );\n return { errors: [], warnings: [...said('extends', 'it adds nothing'), ...said('without', 'it takes nothing away')] };\n};\n\nexport const charterShape = (charter: Charter): CharterShape =>\n merged(Object.entries(charter).flatMap(([role, def]) => [roleShape(role, def), inheritedNames(charter, role, def)]));\n","import type { Charter, RoleDef, Section } from './types';\nimport { matchAll } from './glob';\nimport { fieldsOf, listOf, roleOf, roleShape } from './shape';\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\nconst asSelection = (selection: unknown): { allow: string[]; deny: string[] } => {\n if (Array.isArray(selection)) return { allow: listOf(selection), deny: [] };\n const fields = fieldsOf(selection);\n return { allow: listOf(fields?.get('allow')), deny: listOf(fields?.get('deny')) };\n};\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: listOf(def), deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const fields = fieldsOf(def);\n const composition = { extends: listOf(fields?.get('extends')), without: listOf(fields?.get('without')) };\n if (section !== 'actions') return { ...asSelection(fields?.get(section)), ...composition };\n if (fields?.has('actions') !== true) return { allow: listOf(fields?.get('allow')), deny: listOf(fields?.get('deny')), ...composition };\n // The verifier refuses this pair. Resolved anyway, the top-level deny still takes away; the top-level allow would grant more, so it is not read.\n const sel = asSelection(fields.get('actions'));\n return { allow: sel.allow, deny: [...sel.deny, ...listOf(fields.get('deny'))], ...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 // A name every object answers to and the charter does not define reads as an empty role; the shape check says so.\n const def = role in charter && !Object.hasOwn(charter, role) ? [] : 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 const unreadable = roleShape(role, def).errors[0];\n if (unreadable !== undefined) throw new CharterError(unreadable);\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 = roleOf(charter, role);\n return !def || 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';\nimport { charterShape, fieldsOf, roleOf } from './shape';\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; functions?: 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 shape = charterShape(charter);\n const errors: VerifyIssue[] = shape.errors.map((detail) => ({ level: 'error', rule: 'shape', detail }));\n const warnings: VerifyIssue[] = shape.warnings.map((detail) => ({ level: 'warning', rule: 'shape', detail }));\n const perRole: RoleClosure[] = [];\n // Resolving a role that cannot be read throws, so every check below would say it again.\n if (errors.length > 0) return { errors, warnings, perRole };\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 const fields = fieldsOf(def);\n if (fields?.has('actions') === true && (fields.has('allow') || fields.has('deny'))) {\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 = roleOf(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 = roleOf(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)) for (const sub of normalizeRole(def, 'actions').without) subtractive.add(sub);\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 const functions = universes.functions === undefined ? {} : { functions: [...(resolved.functions.get(role) ?? [])].sort() };\n perRole.push({ role, actions, data, layouts, ...functions, 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.4",
3
+ "version": "0.2.0",
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": {