@niscorp/charter 0.1.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/DESIGN.md +464 -0
- package/DOCS.md +229 -0
- package/LICENSE +202 -0
- package/README.md +54 -0
- package/dist/index.cjs +177 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +168 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/glob.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";;;AAIA,IAAM,eAAe,CAAC,CAAA,KAAsB,CAAA,CAAE,OAAA,CAAQ,uBAAuB,MAAM,CAAA;AAEnF,IAAM,WAAW,CAAC,OAAA,KAA4B,IAAI,MAAA,CAAO,IAAI,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAI,YAAY,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,CAAA;AAExG,IAAM,SAAA,GAAY,CAAC,OAAA,EAAiB,EAAA,KAAwB,SAAS,OAAO,CAAA,CAAE,KAAK,EAAE;AAGrF,IAAM,QAAA,GAAW,CAAC,QAAA,EAA6B,GAAA,KAAwC;AAC5F,EAAA,MAAM,GAAA,uBAAU,GAAA,EAAY;AAC5B,EAAA,KAAA,MAAW,WAAW,QAAA,EAAU;AAC9B,IAAA,MAAM,EAAA,GAAK,SAAS,OAAO,CAAA;AAC3B,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,IAAI,EAAA,CAAG,KAAK,EAAE,CAAA,EAAG,GAAA,CAAI,GAAA,CAAI,EAAE,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,GAAA;AACT;;;ACAO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EACtC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;A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QAAA,EAAU,OAAA,EAAQ;AACrC","file":"index.cjs","sourcesContent":["// One wildcard rule, no more: `*` matches any run of characters, including\n// dots — `crm.*` matches `crm.deal.form`. No `**`, no braces, no regex. The\n// day a pattern cannot be expressed, the answer is a better id, not a\n// richer glob.\nconst escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst toRegExp = (pattern: string): RegExp => new RegExp(`^${pattern.split('*').map(escapeRegExp).join('.*')}$`);\n\nexport const matchGlob = (pattern: string, id: string): boolean => toRegExp(pattern).test(id);\n\n// Every id the pattern list selects out of `ids`.\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) {\n const re = toRegExp(pattern);\n for (const id of ids) if (re.test(id)) out.add(id);\n }\n return out;\n};\n","import type { Charter, RoleDef, Section, Selection } from './types';\nimport { matchAll } from './glob';\n\n// Resolution is a pure function from (charter, universe, section) to a\n// concrete id set per role — the algebra from DESIGN.md § The algebra,\n// verbatim, per section:\n//\n// resolved(role) = (∪ resolved(extends) ∪ match(allow))\n// − match(deny)\n// − ∪ resolved(without)\n//\n// The engine is UNIVERSE-BLIND: it resolves globs over opaque strings and\n// never learns what a string means. `actions` and `data` run the SAME code\n// against different universes. Order-independent (all subtraction is\n// set-minus); deny wins within a role; denies do NOT inherit (a child may\n// re-add what a parent denied — the verifier flags it); cycles and unknown\n// references are errors.\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\n// NOTE deliberately absent: the engine never MANUFACTURES a universe — it is\n// always handed one. The data universe's atoms are the governed target's own\n// dialect (vex exports `SCOPE_VERBS` and `scopeGrants(tables)`); the app\n// wiring derives it and passes it in. That keeps this module free of any\n// foreign import, in either direction.\n\nconst asSelection = (s: Selection | undefined): { allow: string[]; deny: string[] } =>\n s === undefined ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };\n\n// A role's atoms for ONE section, plus its role-level composition (shared\n// across sections). A bare array is an actions-only role; top-level\n// `allow`/`deny` are sugar for the `actions` section.\nexport const normalizeRole = (\n def: RoleDef,\n section: Section,\n): { allow: string[]; deny: string[]; extends: string[]; without: string[] } => {\n if (Array.isArray(def)) {\n return section === 'actions'\n ? { allow: def, deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const composition = { extends: def.extends ?? [], without: def.without ?? [] };\n // Actions: explicit `actions:` wins, else the top-level allow/deny sugar.\n const sel =\n section === 'actions' && def.actions === undefined\n ? { allow: def.allow ?? [], deny: def.deny ?? [] }\n : asSelection(def[section]);\n return { ...sel, ...composition };\n};\n\nexport const resolveRole = (\n charter: Charter,\n universe: readonly string[],\n role: string,\n section: Section,\n memo: Map<string, ReadonlySet<string>> = new Map(),\n visiting: Set<string> = new Set(),\n): ReadonlySet<string> => {\n const cached = memo.get(role);\n if (cached !== undefined) return cached;\n const def = charter[role];\n if (def === undefined) throw new CharterError(`Unknown role \"${role}\"`);\n if (visiting.has(role)) throw new CharterError(`Role cycle through \"${role}\"`);\n visiting.add(role);\n\n const { allow, extends: parents, deny, without } = normalizeRole(def, section);\n const resolved = new Set<string>();\n for (const parent of parents) for (const id of resolveRole(charter, universe, parent, section, memo, visiting)) resolved.add(id);\n for (const id of matchAll(allow, universe)) resolved.add(id);\n for (const id of matchAll(deny, universe)) resolved.delete(id);\n for (const sub of without) for (const id of resolveRole(charter, universe, sub, section, memo, visiting)) resolved.delete(id);\n\n visiting.delete(role);\n memo.set(role, resolved);\n return resolved;\n};\n\n// A principal wears roles; a section's grant is the union of their resolved\n// sets in that section's universe.\n// The reach a ROLE was given: the profile it names, or none.\n//\n// SINGULAR ON PURPOSE. This took a list of roles and refused when two of them\n// named different profiles — \"incoherence rather than a precedence puzzle,\n// refused in the same spirit as two granted layout variants for one action.\"\n// That analogy was wrong. Two layout variants for one action genuinely conflict,\n// because a screen renders one of them; two roles naming different reaches is\n// somebody who teaches at a studio AND trains there, which is a person, not a\n// contradiction.\n//\n// A caller who holds several roles resolves each one separately and merges the\n// results (vex: `mergeScopePolicies`). That is where \"holding two roles\" is\n// decided, and it belongs there — reach is a property of a role, so a function\n// handed several of them has no answer to give, only a choice to refuse.\nexport const resolveScoping = (charter: Charter, role: string): string | undefined => {\n const def = charter[role];\n return def === undefined || Array.isArray(def) ? undefined : def.scoping;\n};\n\nexport const resolvePrincipal = (\n charter: Charter,\n universe: readonly string[],\n roles: readonly string[],\n section: Section = 'actions',\n): Set<string> => {\n const memo = new Map<string, ReadonlySet<string>>();\n const out = new Set<string>();\n for (const role of roles) for (const id of resolveRole(charter, universe, role, section, memo)) out.add(id);\n return out;\n};\n","import type { Charter, Section } from './types';\nimport { matchAll } from './glob';\nimport { CharterError, normalizeRole, resolveRole } from './resolve';\n\n// ═══════════════════════════════════════════════════════════\n// The verifier — the other half of the charter (DESIGN.md § The verifier\n// is the other half). The grammar\n// stays small; the opinions live here. Boot/CI runs it and refuses an\n// incoherent charter: \"if it boots, it's coherent.\"\n//\n// Every check runs PER SECTION against that section's universe. Like the\n// resolver, the verifier is universe-blind: every universe is HANDED IN\n// (the atoms are each governed target's own dialect — nova action ids, vex\n// verb leaves), and the per-role closure audit is an injected hook (nova\n// exports one), so this module imports nothing. Severities are asymmetric\n// on purpose: a dead DENY is an error (a typo'd deny fails silent, and\n// silent means unprotected); a dead allow is a warning.\n// ═══════════════════════════════════════════════════════════\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; issues: string[] };\n\nexport type VerifyReport = { errors: VerifyIssue[]; warnings: VerifyIssue[]; perRole: RoleClosure[] };\n\n// The per-role closure audit: given a role's granted action ids (and, when\n// the app governs layouts, its granted layout-variant ids), report the\n// cross-action wiring problems inside that closure (targets that aren't in\n// it, channels nobody serves). The consumer that OWNS actions provides it —\n// moss builds one from nova's audit, substituting granted variants so the\n// closure sees each role's EFFECTIVE definitions.\nexport type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];\n\nexport const verifyCharter = (\n charter: Charter,\n universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[] },\n // THE ROLE COMBINATIONS A PRINCIPAL MAY WEAR — one entry per combination, not\n // one per person. The only rule below that reads it (`subtractive-assigned`)\n // wants the set of roles somebody actually holds, and a population is a very\n // expensive way to spell a set. A composer that still holds an assignment map\n // passes `Object.values(map)`; one that declares its combinations passes them.\n wearable: readonly (readonly string[])[] = [],\n closure?: ClosureAuditor,\n): VerifyReport => {\n const actionUniverse = universes.actions;\n // The layouts section is verified only when the composer governs layouts\n // (hands a universe in) — absent, a charter's `layouts` keys are inert\n // here exactly as they are in resolution against an empty universe.\n const sections: Section[] = universes.layouts === undefined ? ['actions', 'data'] : ['actions', 'data', 'layouts'];\n const universeOf: Record<Section, readonly string[]> = {\n actions: universes.actions,\n data: universes.data,\n layouts: universes.layouts ?? [],\n };\n\n const errors: VerifyIssue[] = [];\n const warnings: VerifyIssue[] = [];\n const perRole: RoleClosure[] = [];\n\n // Resolve every role in every section up front (also surfaces cycles /\n // unknown references, per section).\n const resolved: Record<Section, Map<string, ReadonlySet<string>>> = { actions: new Map(), data: new Map(), layouts: new Map() };\n for (const section of sections) {\n const memo = new Map<string, ReadonlySet<string>>();\n for (const role of Object.keys(charter)) {\n try {\n resolved[section].set(role, resolveRole(charter, universeOf[section], role, section, memo));\n } catch (e) {\n errors.push({ level: 'error', rule: 'resolution', detail: `${section}: ${e instanceof CharterError ? e.message : String(e)}` });\n }\n }\n }\n\n // ── ids are leaves; namespaces are never actions. Same rule inside the\n // layouts universe — a variant id is never a namespace of another ──\n const leavesOnly = (universe: readonly string[], kind: string): void => {\n for (const a of universe) {\n for (const b of universe) {\n if (b.startsWith(`${a}.`)) {\n errors.push({ level: 'error', rule: 'leaves-only', detail: `id \"${a}\" is a namespace of \"${b}\" — namespaces are never ${kind}` });\n break;\n }\n }\n }\n };\n leavesOnly(actionUniverse, 'actions');\n if (universes.layouts !== undefined) leavesOnly(universes.layouts, 'variants');\n\n // ── one selection per section: top-level allow/deny (the actions sugar)\n // AND an `actions` key on the same role means resolution silently drops\n // the sugar — silent means wrong, so boot refuses ──\n for (const [role, def] of Object.entries(charter)) {\n if (Array.isArray(def)) continue;\n if (def.actions !== undefined && (def.allow !== undefined || def.deny !== undefined)) {\n errors.push({ level: 'error', rule: 'ambiguous-selection', detail: `role \"${role}\" has both top-level allow/deny and an \"actions\" section — one selection per section` });\n }\n }\n\n // ── dead deny = error, dead allow = warning; per glob, per role, per section ──\n for (const section of sections) {\n for (const [role, def] of Object.entries(charter)) {\n const { allow, deny } = normalizeRole(def, section);\n for (const glob of deny) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n errors.push({ level: 'error', rule: 'dead-deny', detail: `role \"${role}\" denies \"${glob}\" (${section}) which matches nothing — silent means unprotected` });\n }\n }\n for (const glob of allow) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n warnings.push({ level: 'warning', rule: 'dead-allow', detail: `role \"${role}\" allows \"${glob}\" (${section}) which matches nothing` });\n }\n }\n }\n }\n\n // ── orphans: matched by no role at all. Actions and layout variants share\n // the rule — both are deployed-but-unreachable artifacts. An ungranted\n // data phase is simply denied, not a mistake ──\n const orphans = (section: Section, kind: string): void => {\n const reachable = new Set<string>();\n for (const set of resolved[section].values()) for (const id of set) reachable.add(id);\n for (const id of universeOf[section]) {\n if (!reachable.has(id)) warnings.push({ level: 'warning', rule: 'orphan', detail: `${kind} \"${id}\" is granted by no role — deployed but unreachable` });\n }\n };\n orphans('actions', 'action');\n if (universes.layouts !== undefined) orphans('layouts', 'layout variant');\n\n // ── re-allow of an ancestor's deny (F1), per section ──\n const ancestorDenied = (role: string, section: Section, seen: Set<string> = new Set()): Set<string> => {\n const out = new Set<string>();\n const def = charter[role];\n if (def === undefined || seen.has(role)) return out;\n seen.add(role);\n for (const parent of normalizeRole(def, section).extends) {\n const parentDef = charter[parent];\n if (parentDef === undefined) continue;\n for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);\n for (const id of ancestorDenied(parent, section, seen)) out.add(id);\n }\n return out;\n };\n for (const section of sections) {\n for (const [role, set] of resolved[section]) {\n for (const id of ancestorDenied(role, section)) {\n if (set.has(id)) {\n warnings.push({ level: 'warning', rule: 're-allow', detail: `role \"${role}\" re-allows \"${id}\" (${section}) which an ancestor denied` });\n }\n }\n }\n }\n\n // ── a role referenced in `without` that principals also wear (F2) ──\n const subtractive = new Set<string>();\n for (const def of Object.values(charter)) {\n if (Array.isArray(def)) continue;\n for (const sub of def.without ?? []) subtractive.add(sub);\n }\n const worn = new Set(wearable.flat());\n for (const role of subtractive) {\n if (worn.has(role)) {\n warnings.push({ level: 'warning', rule: 'subtractive-assigned', detail: `role \"${role}\" is referenced in \"without\" but is also assigned to a principal` });\n }\n }\n\n // ── per-role closure: the action-catalog audit (cross-action wiring),\n // fed the role's granted variants so it audits EFFECTIVE definitions ──\n for (const role of Object.keys(charter)) {\n const actions = [...(resolved.actions.get(role) ?? [])].sort();\n const data = [...(resolved.data.get(role) ?? [])].sort();\n const layouts = [...(resolved.layouts.get(role) ?? [])].sort();\n const issues = closure?.(actions, layouts) ?? [];\n perRole.push({ role, actions, data, layouts, issues });\n }\n\n return { errors, warnings, perRole };\n};\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type Section = 'actions' | 'data' | 'layouts';
|
|
2
|
+
type Selection = string[] | {
|
|
3
|
+
allow?: string[];
|
|
4
|
+
deny?: string[];
|
|
5
|
+
};
|
|
6
|
+
type RoleDef = string[] | {
|
|
7
|
+
extends?: string[];
|
|
8
|
+
without?: string[];
|
|
9
|
+
allow?: string[];
|
|
10
|
+
deny?: string[];
|
|
11
|
+
actions?: Selection;
|
|
12
|
+
data?: Selection;
|
|
13
|
+
layouts?: Selection;
|
|
14
|
+
scoping?: string;
|
|
15
|
+
};
|
|
16
|
+
type Charter = Record<string, RoleDef>;
|
|
17
|
+
|
|
18
|
+
declare const matchGlob: (pattern: string, id: string) => boolean;
|
|
19
|
+
declare const matchAll: (patterns: readonly string[], ids: readonly string[]) => Set<string>;
|
|
20
|
+
|
|
21
|
+
declare class CharterError extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
declare const normalizeRole: (def: RoleDef, section: Section) => {
|
|
25
|
+
allow: string[];
|
|
26
|
+
deny: string[];
|
|
27
|
+
extends: string[];
|
|
28
|
+
without: string[];
|
|
29
|
+
};
|
|
30
|
+
declare const resolveRole: (charter: Charter, universe: readonly string[], role: string, section: Section, memo?: Map<string, ReadonlySet<string>>, visiting?: Set<string>) => ReadonlySet<string>;
|
|
31
|
+
declare const resolveScoping: (charter: Charter, role: string) => string | undefined;
|
|
32
|
+
declare const resolvePrincipal: (charter: Charter, universe: readonly string[], roles: readonly string[], section?: Section) => Set<string>;
|
|
33
|
+
|
|
34
|
+
type VerifyIssue = {
|
|
35
|
+
level: 'error' | 'warning';
|
|
36
|
+
rule: string;
|
|
37
|
+
detail: string;
|
|
38
|
+
};
|
|
39
|
+
type RoleClosure = {
|
|
40
|
+
role: string;
|
|
41
|
+
actions: string[];
|
|
42
|
+
data: string[];
|
|
43
|
+
layouts: string[];
|
|
44
|
+
issues: string[];
|
|
45
|
+
};
|
|
46
|
+
type VerifyReport = {
|
|
47
|
+
errors: VerifyIssue[];
|
|
48
|
+
warnings: VerifyIssue[];
|
|
49
|
+
perRole: RoleClosure[];
|
|
50
|
+
};
|
|
51
|
+
type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];
|
|
52
|
+
declare const verifyCharter: (charter: Charter, universes: {
|
|
53
|
+
actions: readonly string[];
|
|
54
|
+
data: readonly string[];
|
|
55
|
+
layouts?: readonly string[];
|
|
56
|
+
}, wearable?: readonly (readonly string[])[], closure?: ClosureAuditor) => VerifyReport;
|
|
57
|
+
|
|
58
|
+
export { type Charter, CharterError, type ClosureAuditor, type RoleClosure, type RoleDef, type Section, type Selection, type VerifyIssue, type VerifyReport, matchAll, matchGlob, normalizeRole, resolvePrincipal, resolveRole, resolveScoping, verifyCharter };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type Section = 'actions' | 'data' | 'layouts';
|
|
2
|
+
type Selection = string[] | {
|
|
3
|
+
allow?: string[];
|
|
4
|
+
deny?: string[];
|
|
5
|
+
};
|
|
6
|
+
type RoleDef = string[] | {
|
|
7
|
+
extends?: string[];
|
|
8
|
+
without?: string[];
|
|
9
|
+
allow?: string[];
|
|
10
|
+
deny?: string[];
|
|
11
|
+
actions?: Selection;
|
|
12
|
+
data?: Selection;
|
|
13
|
+
layouts?: Selection;
|
|
14
|
+
scoping?: string;
|
|
15
|
+
};
|
|
16
|
+
type Charter = Record<string, RoleDef>;
|
|
17
|
+
|
|
18
|
+
declare const matchGlob: (pattern: string, id: string) => boolean;
|
|
19
|
+
declare const matchAll: (patterns: readonly string[], ids: readonly string[]) => Set<string>;
|
|
20
|
+
|
|
21
|
+
declare class CharterError extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
declare const normalizeRole: (def: RoleDef, section: Section) => {
|
|
25
|
+
allow: string[];
|
|
26
|
+
deny: string[];
|
|
27
|
+
extends: string[];
|
|
28
|
+
without: string[];
|
|
29
|
+
};
|
|
30
|
+
declare const resolveRole: (charter: Charter, universe: readonly string[], role: string, section: Section, memo?: Map<string, ReadonlySet<string>>, visiting?: Set<string>) => ReadonlySet<string>;
|
|
31
|
+
declare const resolveScoping: (charter: Charter, role: string) => string | undefined;
|
|
32
|
+
declare const resolvePrincipal: (charter: Charter, universe: readonly string[], roles: readonly string[], section?: Section) => Set<string>;
|
|
33
|
+
|
|
34
|
+
type VerifyIssue = {
|
|
35
|
+
level: 'error' | 'warning';
|
|
36
|
+
rule: string;
|
|
37
|
+
detail: string;
|
|
38
|
+
};
|
|
39
|
+
type RoleClosure = {
|
|
40
|
+
role: string;
|
|
41
|
+
actions: string[];
|
|
42
|
+
data: string[];
|
|
43
|
+
layouts: string[];
|
|
44
|
+
issues: string[];
|
|
45
|
+
};
|
|
46
|
+
type VerifyReport = {
|
|
47
|
+
errors: VerifyIssue[];
|
|
48
|
+
warnings: VerifyIssue[];
|
|
49
|
+
perRole: RoleClosure[];
|
|
50
|
+
};
|
|
51
|
+
type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];
|
|
52
|
+
declare const verifyCharter: (charter: Charter, universes: {
|
|
53
|
+
actions: readonly string[];
|
|
54
|
+
data: readonly string[];
|
|
55
|
+
layouts?: readonly string[];
|
|
56
|
+
}, wearable?: readonly (readonly string[])[], closure?: ClosureAuditor) => VerifyReport;
|
|
57
|
+
|
|
58
|
+
export { type Charter, CharterError, type ClosureAuditor, type RoleClosure, type RoleDef, type Section, type Selection, type VerifyIssue, type VerifyReport, matchAll, matchGlob, normalizeRole, resolvePrincipal, resolveRole, resolveScoping, verifyCharter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
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);
|
|
5
|
+
var matchAll = (patterns, ids) => {
|
|
6
|
+
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
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/resolve.ts
|
|
15
|
+
var CharterError = class extends Error {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "CharterError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var asSelection = (s) => s === void 0 ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };
|
|
22
|
+
var normalizeRole = (def, section) => {
|
|
23
|
+
if (Array.isArray(def)) {
|
|
24
|
+
return section === "actions" ? { allow: def, deny: [], extends: [], without: [] } : { allow: [], deny: [], extends: [], without: [] };
|
|
25
|
+
}
|
|
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 };
|
|
29
|
+
};
|
|
30
|
+
var resolveRole = (charter, universe, role, section, memo = /* @__PURE__ */ new Map(), visiting = /* @__PURE__ */ new Set()) => {
|
|
31
|
+
const cached = memo.get(role);
|
|
32
|
+
if (cached !== void 0) return cached;
|
|
33
|
+
const def = charter[role];
|
|
34
|
+
if (def === void 0) throw new CharterError(`Unknown role "${role}"`);
|
|
35
|
+
if (visiting.has(role)) throw new CharterError(`Role cycle through "${role}"`);
|
|
36
|
+
visiting.add(role);
|
|
37
|
+
const { allow, extends: parents, deny, without } = normalizeRole(def, section);
|
|
38
|
+
const resolved = /* @__PURE__ */ new Set();
|
|
39
|
+
for (const parent of parents) for (const id of resolveRole(charter, universe, parent, section, memo, visiting)) resolved.add(id);
|
|
40
|
+
for (const id of matchAll(allow, universe)) resolved.add(id);
|
|
41
|
+
for (const id of matchAll(deny, universe)) resolved.delete(id);
|
|
42
|
+
for (const sub of without) for (const id of resolveRole(charter, universe, sub, section, memo, visiting)) resolved.delete(id);
|
|
43
|
+
visiting.delete(role);
|
|
44
|
+
memo.set(role, resolved);
|
|
45
|
+
return resolved;
|
|
46
|
+
};
|
|
47
|
+
var resolveScoping = (charter, role) => {
|
|
48
|
+
const def = charter[role];
|
|
49
|
+
return def === void 0 || Array.isArray(def) ? void 0 : def.scoping;
|
|
50
|
+
};
|
|
51
|
+
var resolvePrincipal = (charter, universe, roles, section = "actions") => {
|
|
52
|
+
const memo = /* @__PURE__ */ new Map();
|
|
53
|
+
const out = /* @__PURE__ */ new Set();
|
|
54
|
+
for (const role of roles) for (const id of resolveRole(charter, universe, role, section, memo)) out.add(id);
|
|
55
|
+
return out;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// src/verify.ts
|
|
59
|
+
var verifyCharter = (charter, universes, wearable = [], closure) => {
|
|
60
|
+
const actionUniverse = universes.actions;
|
|
61
|
+
const sections = universes.layouts === void 0 ? ["actions", "data"] : ["actions", "data", "layouts"];
|
|
62
|
+
const universeOf = {
|
|
63
|
+
actions: universes.actions,
|
|
64
|
+
data: universes.data,
|
|
65
|
+
layouts: universes.layouts ?? []
|
|
66
|
+
};
|
|
67
|
+
const errors = [];
|
|
68
|
+
const warnings = [];
|
|
69
|
+
const perRole = [];
|
|
70
|
+
const resolved = { actions: /* @__PURE__ */ new Map(), data: /* @__PURE__ */ new Map(), layouts: /* @__PURE__ */ new Map() };
|
|
71
|
+
for (const section of sections) {
|
|
72
|
+
const memo = /* @__PURE__ */ new Map();
|
|
73
|
+
for (const role of Object.keys(charter)) {
|
|
74
|
+
try {
|
|
75
|
+
resolved[section].set(role, resolveRole(charter, universeOf[section], role, section, memo));
|
|
76
|
+
} catch (e) {
|
|
77
|
+
errors.push({ level: "error", rule: "resolution", detail: `${section}: ${e instanceof CharterError ? e.message : String(e)}` });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const leavesOnly = (universe, kind) => {
|
|
82
|
+
for (const a of universe) {
|
|
83
|
+
for (const b of universe) {
|
|
84
|
+
if (b.startsWith(`${a}.`)) {
|
|
85
|
+
errors.push({ level: "error", rule: "leaves-only", detail: `id "${a}" is a namespace of "${b}" \u2014 namespaces are never ${kind}` });
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
leavesOnly(actionUniverse, "actions");
|
|
92
|
+
if (universes.layouts !== void 0) leavesOnly(universes.layouts, "variants");
|
|
93
|
+
for (const [role, def] of Object.entries(charter)) {
|
|
94
|
+
if (Array.isArray(def)) continue;
|
|
95
|
+
if (def.actions !== void 0 && (def.allow !== void 0 || def.deny !== void 0)) {
|
|
96
|
+
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` });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const section of sections) {
|
|
100
|
+
for (const [role, def] of Object.entries(charter)) {
|
|
101
|
+
const { allow, deny } = normalizeRole(def, section);
|
|
102
|
+
for (const glob of deny) {
|
|
103
|
+
if (matchAll([glob], universeOf[section]).size === 0) {
|
|
104
|
+
errors.push({ level: "error", rule: "dead-deny", detail: `role "${role}" denies "${glob}" (${section}) which matches nothing \u2014 silent means unprotected` });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const glob of allow) {
|
|
108
|
+
if (matchAll([glob], universeOf[section]).size === 0) {
|
|
109
|
+
warnings.push({ level: "warning", rule: "dead-allow", detail: `role "${role}" allows "${glob}" (${section}) which matches nothing` });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const orphans = (section, kind) => {
|
|
115
|
+
const reachable = /* @__PURE__ */ new Set();
|
|
116
|
+
for (const set of resolved[section].values()) for (const id of set) reachable.add(id);
|
|
117
|
+
for (const id of universeOf[section]) {
|
|
118
|
+
if (!reachable.has(id)) warnings.push({ level: "warning", rule: "orphan", detail: `${kind} "${id}" is granted by no role \u2014 deployed but unreachable` });
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
orphans("actions", "action");
|
|
122
|
+
if (universes.layouts !== void 0) orphans("layouts", "layout variant");
|
|
123
|
+
const ancestorDenied = (role, section, seen = /* @__PURE__ */ new Set()) => {
|
|
124
|
+
const out = /* @__PURE__ */ new Set();
|
|
125
|
+
const def = charter[role];
|
|
126
|
+
if (def === void 0 || seen.has(role)) return out;
|
|
127
|
+
seen.add(role);
|
|
128
|
+
for (const parent of normalizeRole(def, section).extends) {
|
|
129
|
+
const parentDef = charter[parent];
|
|
130
|
+
if (parentDef === void 0) continue;
|
|
131
|
+
for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);
|
|
132
|
+
for (const id of ancestorDenied(parent, section, seen)) out.add(id);
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
};
|
|
136
|
+
for (const section of sections) {
|
|
137
|
+
for (const [role, set] of resolved[section]) {
|
|
138
|
+
for (const id of ancestorDenied(role, section)) {
|
|
139
|
+
if (set.has(id)) {
|
|
140
|
+
warnings.push({ level: "warning", rule: "re-allow", detail: `role "${role}" re-allows "${id}" (${section}) which an ancestor denied` });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const subtractive = /* @__PURE__ */ new Set();
|
|
146
|
+
for (const def of Object.values(charter)) {
|
|
147
|
+
if (Array.isArray(def)) continue;
|
|
148
|
+
for (const sub of def.without ?? []) subtractive.add(sub);
|
|
149
|
+
}
|
|
150
|
+
const worn = new Set(wearable.flat());
|
|
151
|
+
for (const role of subtractive) {
|
|
152
|
+
if (worn.has(role)) {
|
|
153
|
+
warnings.push({ level: "warning", rule: "subtractive-assigned", detail: `role "${role}" is referenced in "without" but is also assigned to a principal` });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
for (const role of Object.keys(charter)) {
|
|
157
|
+
const actions = [...resolved.actions.get(role) ?? []].sort();
|
|
158
|
+
const data = [...resolved.data.get(role) ?? []].sort();
|
|
159
|
+
const layouts = [...resolved.layouts.get(role) ?? []].sort();
|
|
160
|
+
const issues = closure?.(actions, layouts) ?? [];
|
|
161
|
+
perRole.push({ role, actions, data, layouts, issues });
|
|
162
|
+
}
|
|
163
|
+
return { errors, warnings, perRole };
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export { CharterError, matchAll, matchGlob, normalizeRole, resolvePrincipal, resolveRole, resolveScoping, verifyCharter };
|
|
167
|
+
//# sourceMappingURL=index.js.map
|
|
168
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/glob.ts","../src/resolve.ts","../src/verify.ts"],"names":[],"mappings":";AAIA,IAAM,eAAe,CAAC,CAAA,KAAsB,CAAA,CAAE,OAAA,CAAQ,uBAAuB,MAAM,CAAA;AAEnF,IAAM,WAAW,CAAC,OAAA,KAA4B,IAAI,MAAA,CAAO,IAAI,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,IAAI,YAAY,CAAA,CAAE,IAAA,CAAK,IAAI,CAAC,CAAA,CAAA,CAAG,CAAA;AAExG,IAAM,SAAA,GAAY,CAAC,OAAA,EAAiB,EAAA,KAAwB,SAAS,OAAO,CAAA,CAAE,KAAK,EAAE;AAGrF,IAAM,QAAA,GAAW,CAAC,QAAA,EAA6B,GAAA,KAAwC;AAC5F,EAAA,MAAM,GAAA,uBAAU,GAAA,EAAY;AAC5B,EAAA,KAAA,MAAW,WAAW,QAAA,EAAU;AAC9B,IAAA,MAAM,EAAA,GAAK,SAAS,OAAO,CAAA;AAC3B,IAAA,KAAA,MAAW,EAAA,IAAM,KAAK,IAAI,EAAA,CAAG,KAAK,EAAE,CAAA,EAAG,GAAA,CAAI,GAAA,CAAI,EAAE,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,GAAA;AACT;;;ACAO,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;AAQA,IA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`*` matches any run of characters, including\n// dots — `crm.*` matches `crm.deal.form`. No `**`, no braces, no regex. The\n// day a pattern cannot be expressed, the answer is a better id, not a\n// richer glob.\nconst escapeRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\nconst toRegExp = (pattern: string): RegExp => new RegExp(`^${pattern.split('*').map(escapeRegExp).join('.*')}$`);\n\nexport const matchGlob = (pattern: string, id: string): boolean => toRegExp(pattern).test(id);\n\n// Every id the pattern list selects out of `ids`.\nexport const matchAll = (patterns: readonly string[], ids: readonly string[]): Set<string> => {\n const out = new Set<string>();\n for (const pattern of patterns) {\n const re = toRegExp(pattern);\n for (const id of ids) if (re.test(id)) out.add(id);\n }\n return out;\n};\n","import type { Charter, RoleDef, Section, Selection } from './types';\nimport { matchAll } from './glob';\n\n// Resolution is a pure function from (charter, universe, section) to a\n// concrete id set per role — the algebra from DESIGN.md § The algebra,\n// verbatim, per section:\n//\n// resolved(role) = (∪ resolved(extends) ∪ match(allow))\n// − match(deny)\n// − ∪ resolved(without)\n//\n// The engine is UNIVERSE-BLIND: it resolves globs over opaque strings and\n// never learns what a string means. `actions` and `data` run the SAME code\n// against different universes. Order-independent (all subtraction is\n// set-minus); deny wins within a role; denies do NOT inherit (a child may\n// re-add what a parent denied — the verifier flags it); cycles and unknown\n// references are errors.\n\nexport class CharterError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'CharterError';\n }\n}\n\n// NOTE deliberately absent: the engine never MANUFACTURES a universe — it is\n// always handed one. The data universe's atoms are the governed target's own\n// dialect (vex exports `SCOPE_VERBS` and `scopeGrants(tables)`); the app\n// wiring derives it and passes it in. That keeps this module free of any\n// foreign import, in either direction.\n\nconst asSelection = (s: Selection | undefined): { allow: string[]; deny: string[] } =>\n s === undefined ? { allow: [], deny: [] } : Array.isArray(s) ? { allow: s, deny: [] } : { allow: s.allow ?? [], deny: s.deny ?? [] };\n\n// A role's atoms for ONE section, plus its role-level composition (shared\n// across sections). A bare array is an actions-only role; top-level\n// `allow`/`deny` are sugar for the `actions` section.\nexport const normalizeRole = (\n def: RoleDef,\n section: Section,\n): { allow: string[]; deny: string[]; extends: string[]; without: string[] } => {\n if (Array.isArray(def)) {\n return section === 'actions'\n ? { allow: def, deny: [], extends: [], without: [] }\n : { allow: [], deny: [], extends: [], without: [] };\n }\n const composition = { extends: def.extends ?? [], without: def.without ?? [] };\n // Actions: explicit `actions:` wins, else the top-level allow/deny sugar.\n const sel =\n section === 'actions' && def.actions === undefined\n ? { allow: def.allow ?? [], deny: def.deny ?? [] }\n : asSelection(def[section]);\n return { ...sel, ...composition };\n};\n\nexport const resolveRole = (\n charter: Charter,\n universe: readonly string[],\n role: string,\n section: Section,\n memo: Map<string, ReadonlySet<string>> = new Map(),\n visiting: Set<string> = new Set(),\n): ReadonlySet<string> => {\n const cached = memo.get(role);\n if (cached !== undefined) return cached;\n const def = charter[role];\n if (def === undefined) throw new CharterError(`Unknown role \"${role}\"`);\n if (visiting.has(role)) throw new CharterError(`Role cycle through \"${role}\"`);\n visiting.add(role);\n\n const { allow, extends: parents, deny, without } = normalizeRole(def, section);\n const resolved = new Set<string>();\n for (const parent of parents) for (const id of resolveRole(charter, universe, parent, section, memo, visiting)) resolved.add(id);\n for (const id of matchAll(allow, universe)) resolved.add(id);\n for (const id of matchAll(deny, universe)) resolved.delete(id);\n for (const sub of without) for (const id of resolveRole(charter, universe, sub, section, memo, visiting)) resolved.delete(id);\n\n visiting.delete(role);\n memo.set(role, resolved);\n return resolved;\n};\n\n// A principal wears roles; a section's grant is the union of their resolved\n// sets in that section's universe.\n// The reach a ROLE was given: the profile it names, or none.\n//\n// SINGULAR ON PURPOSE. This took a list of roles and refused when two of them\n// named different profiles — \"incoherence rather than a precedence puzzle,\n// refused in the same spirit as two granted layout variants for one action.\"\n// That analogy was wrong. Two layout variants for one action genuinely conflict,\n// because a screen renders one of them; two roles naming different reaches is\n// somebody who teaches at a studio AND trains there, which is a person, not a\n// contradiction.\n//\n// A caller who holds several roles resolves each one separately and merges the\n// results (vex: `mergeScopePolicies`). That is where \"holding two roles\" is\n// decided, and it belongs there — reach is a property of a role, so a function\n// handed several of them has no answer to give, only a choice to refuse.\nexport const resolveScoping = (charter: Charter, role: string): string | undefined => {\n const def = charter[role];\n return def === undefined || Array.isArray(def) ? undefined : def.scoping;\n};\n\nexport const resolvePrincipal = (\n charter: Charter,\n universe: readonly string[],\n roles: readonly string[],\n section: Section = 'actions',\n): Set<string> => {\n const memo = new Map<string, ReadonlySet<string>>();\n const out = new Set<string>();\n for (const role of roles) for (const id of resolveRole(charter, universe, role, section, memo)) out.add(id);\n return out;\n};\n","import type { Charter, Section } from './types';\nimport { matchAll } from './glob';\nimport { CharterError, normalizeRole, resolveRole } from './resolve';\n\n// ═══════════════════════════════════════════════════════════\n// The verifier — the other half of the charter (DESIGN.md § The verifier\n// is the other half). The grammar\n// stays small; the opinions live here. Boot/CI runs it and refuses an\n// incoherent charter: \"if it boots, it's coherent.\"\n//\n// Every check runs PER SECTION against that section's universe. Like the\n// resolver, the verifier is universe-blind: every universe is HANDED IN\n// (the atoms are each governed target's own dialect — nova action ids, vex\n// verb leaves), and the per-role closure audit is an injected hook (nova\n// exports one), so this module imports nothing. Severities are asymmetric\n// on purpose: a dead DENY is an error (a typo'd deny fails silent, and\n// silent means unprotected); a dead allow is a warning.\n// ═══════════════════════════════════════════════════════════\n\nexport type VerifyIssue = { level: 'error' | 'warning'; rule: string; detail: string };\n\nexport type RoleClosure = { role: string; actions: string[]; data: string[]; layouts: string[]; issues: string[] };\n\nexport type VerifyReport = { errors: VerifyIssue[]; warnings: VerifyIssue[]; perRole: RoleClosure[] };\n\n// The per-role closure audit: given a role's granted action ids (and, when\n// the app governs layouts, its granted layout-variant ids), report the\n// cross-action wiring problems inside that closure (targets that aren't in\n// it, channels nobody serves). The consumer that OWNS actions provides it —\n// moss builds one from nova's audit, substituting granted variants so the\n// closure sees each role's EFFECTIVE definitions.\nexport type ClosureAuditor = (grantedIds: readonly string[], layoutIds?: readonly string[]) => string[];\n\nexport const verifyCharter = (\n charter: Charter,\n universes: { actions: readonly string[]; data: readonly string[]; layouts?: readonly string[] },\n // THE ROLE COMBINATIONS A PRINCIPAL MAY WEAR — one entry per combination, not\n // one per person. The only rule below that reads it (`subtractive-assigned`)\n // wants the set of roles somebody actually holds, and a population is a very\n // expensive way to spell a set. A composer that still holds an assignment map\n // passes `Object.values(map)`; one that declares its combinations passes them.\n wearable: readonly (readonly string[])[] = [],\n closure?: ClosureAuditor,\n): VerifyReport => {\n const actionUniverse = universes.actions;\n // The layouts section is verified only when the composer governs layouts\n // (hands a universe in) — absent, a charter's `layouts` keys are inert\n // here exactly as they are in resolution against an empty universe.\n const sections: Section[] = universes.layouts === undefined ? ['actions', 'data'] : ['actions', 'data', 'layouts'];\n const universeOf: Record<Section, readonly string[]> = {\n actions: universes.actions,\n data: universes.data,\n layouts: universes.layouts ?? [],\n };\n\n const errors: VerifyIssue[] = [];\n const warnings: VerifyIssue[] = [];\n const perRole: RoleClosure[] = [];\n\n // Resolve every role in every section up front (also surfaces cycles /\n // unknown references, per section).\n const resolved: Record<Section, Map<string, ReadonlySet<string>>> = { actions: new Map(), data: new Map(), layouts: new Map() };\n for (const section of sections) {\n const memo = new Map<string, ReadonlySet<string>>();\n for (const role of Object.keys(charter)) {\n try {\n resolved[section].set(role, resolveRole(charter, universeOf[section], role, section, memo));\n } catch (e) {\n errors.push({ level: 'error', rule: 'resolution', detail: `${section}: ${e instanceof CharterError ? e.message : String(e)}` });\n }\n }\n }\n\n // ── ids are leaves; namespaces are never actions. Same rule inside the\n // layouts universe — a variant id is never a namespace of another ──\n const leavesOnly = (universe: readonly string[], kind: string): void => {\n for (const a of universe) {\n for (const b of universe) {\n if (b.startsWith(`${a}.`)) {\n errors.push({ level: 'error', rule: 'leaves-only', detail: `id \"${a}\" is a namespace of \"${b}\" — namespaces are never ${kind}` });\n break;\n }\n }\n }\n };\n leavesOnly(actionUniverse, 'actions');\n if (universes.layouts !== undefined) leavesOnly(universes.layouts, 'variants');\n\n // ── one selection per section: top-level allow/deny (the actions sugar)\n // AND an `actions` key on the same role means resolution silently drops\n // the sugar — silent means wrong, so boot refuses ──\n for (const [role, def] of Object.entries(charter)) {\n if (Array.isArray(def)) continue;\n if (def.actions !== undefined && (def.allow !== undefined || def.deny !== undefined)) {\n errors.push({ level: 'error', rule: 'ambiguous-selection', detail: `role \"${role}\" has both top-level allow/deny and an \"actions\" section — one selection per section` });\n }\n }\n\n // ── dead deny = error, dead allow = warning; per glob, per role, per section ──\n for (const section of sections) {\n for (const [role, def] of Object.entries(charter)) {\n const { allow, deny } = normalizeRole(def, section);\n for (const glob of deny) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n errors.push({ level: 'error', rule: 'dead-deny', detail: `role \"${role}\" denies \"${glob}\" (${section}) which matches nothing — silent means unprotected` });\n }\n }\n for (const glob of allow) {\n if (matchAll([glob], universeOf[section]).size === 0) {\n warnings.push({ level: 'warning', rule: 'dead-allow', detail: `role \"${role}\" allows \"${glob}\" (${section}) which matches nothing` });\n }\n }\n }\n }\n\n // ── orphans: matched by no role at all. Actions and layout variants share\n // the rule — both are deployed-but-unreachable artifacts. An ungranted\n // data phase is simply denied, not a mistake ──\n const orphans = (section: Section, kind: string): void => {\n const reachable = new Set<string>();\n for (const set of resolved[section].values()) for (const id of set) reachable.add(id);\n for (const id of universeOf[section]) {\n if (!reachable.has(id)) warnings.push({ level: 'warning', rule: 'orphan', detail: `${kind} \"${id}\" is granted by no role — deployed but unreachable` });\n }\n };\n orphans('actions', 'action');\n if (universes.layouts !== undefined) orphans('layouts', 'layout variant');\n\n // ── re-allow of an ancestor's deny (F1), per section ──\n const ancestorDenied = (role: string, section: Section, seen: Set<string> = new Set()): Set<string> => {\n const out = new Set<string>();\n const def = charter[role];\n if (def === undefined || seen.has(role)) return out;\n seen.add(role);\n for (const parent of normalizeRole(def, section).extends) {\n const parentDef = charter[parent];\n if (parentDef === undefined) continue;\n for (const id of matchAll(normalizeRole(parentDef, section).deny, universeOf[section])) out.add(id);\n for (const id of ancestorDenied(parent, section, seen)) out.add(id);\n }\n return out;\n };\n for (const section of sections) {\n for (const [role, set] of resolved[section]) {\n for (const id of ancestorDenied(role, section)) {\n if (set.has(id)) {\n warnings.push({ level: 'warning', rule: 're-allow', detail: `role \"${role}\" re-allows \"${id}\" (${section}) which an ancestor denied` });\n }\n }\n }\n }\n\n // ── a role referenced in `without` that principals also wear (F2) ──\n const subtractive = new Set<string>();\n for (const def of Object.values(charter)) {\n if (Array.isArray(def)) continue;\n for (const sub of def.without ?? []) subtractive.add(sub);\n }\n const worn = new Set(wearable.flat());\n for (const role of subtractive) {\n if (worn.has(role)) {\n warnings.push({ level: 'warning', rule: 'subtractive-assigned', detail: `role \"${role}\" is referenced in \"without\" but is also assigned to a principal` });\n }\n }\n\n // ── per-role closure: the action-catalog audit (cross-action wiring),\n // fed the role's granted variants so it audits EFFECTIVE definitions ──\n for (const role of Object.keys(charter)) {\n const actions = [...(resolved.actions.get(role) ?? [])].sort();\n const data = [...(resolved.data.get(role) ?? [])].sort();\n const layouts = [...(resolved.layouts.get(role) ?? [])].sort();\n const issues = closure?.(actions, layouts) ?? [];\n perRole.push({ role, actions, data, layouts, issues });\n }\n\n return { errors, warnings, perRole };\n};\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@niscorp/charter",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A universe-blind policy engine — roles resolve glob selections over opaque string universes; the verifier refuses incoherence. Zero dependencies.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/moccadroid/niscorp.git",
|
|
9
|
+
"directory": "packages/charter"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"*.md",
|
|
28
|
+
"LICENSE"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22.12"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.5.1",
|
|
38
|
+
"typescript": "^6.0.2",
|
|
39
|
+
"vitest": "^4.1.2"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"dev": "tsup --watch",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest",
|
|
46
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json"
|
|
47
|
+
}
|
|
48
|
+
}
|