@htilabs/platform-common-models 0.47.0 → 0.48.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/README.md +38 -0
- package/dist/authz/index.cjs +243 -16
- package/dist/authz/index.cjs.map +1 -1
- package/dist/authz/index.d.cts +164 -1
- package/dist/authz/index.d.ts +164 -1
- package/dist/authz/index.js +241 -16
- package/dist/authz/index.js.map +1 -1
- package/dist/index.cjs +243 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +241 -16
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
- package/src/__tests__/authz-function-door.test.ts +461 -0
- package/src/__tests__/authz-resolve.test.ts +46 -0
- package/src/authz/functionDoor.ts +229 -0
- package/src/authz/index.ts +2 -0
- package/src/authz/resolveEffectiveFunctions.ts +17 -52
- package/src/authz/roleCodes.ts +59 -0
- package/src/authz/storedReads.ts +92 -0
- package/src/generated/authzBrowserTables.ts +151 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — the function door (Kickoff 08b § 11)
|
|
3
|
+
*
|
|
4
|
+
* STATUS: DRAFT (Tier B, 0.48.0).
|
|
5
|
+
*
|
|
6
|
+
* The resolver half (`resolveEffectiveFunctions`) decides what a seat may do.
|
|
7
|
+
* This is the other half: it carries that answer to the screen in the shape
|
|
8
|
+
* the shared components take, so no shared piece decides anything (Crysta,
|
|
9
|
+
* 2026-10-20: "A shared piece never decides who may view, access, or edit it
|
|
10
|
+
* … It receives those decisions and only shows them."). The host app runs
|
|
11
|
+
* this over the seat's resolved answer and hands the result to the piece —
|
|
12
|
+
* `{ allowed, reason }` is what `SharePurposeAccess` (`vspToLe`) and
|
|
13
|
+
* `ShareRow`'s `revokeAccess` read; `offered` tells the host whether to draw
|
|
14
|
+
* the control at all.
|
|
15
|
+
*
|
|
16
|
+
* THE ENCODING (§ 11). Per seat, the function's Tier-1 bound for each of
|
|
17
|
+
* the seat's roles, stacked:
|
|
18
|
+
*
|
|
19
|
+
* - NEVER (or NA, "Not relevant", which the resolver reads as NEVER) for
|
|
20
|
+
* every role the seat holds, or no role bound at all → the control is not
|
|
21
|
+
* part of this seat's job: `{ offered: false, allowed: false, reason: null }`.
|
|
22
|
+
* - some role bound ALWAYS / PREF_YES (Default On) / PREF_NO (Default Off),
|
|
23
|
+
* but the function is NOT in the seat's effective set → drawn and refused:
|
|
24
|
+
* `{ offered: true, allowed: false, reason: "<label> is not part of your roles" }`.
|
|
25
|
+
* - in the effective set → `{ offered: true, allowed: true, reason: null }`.
|
|
26
|
+
*
|
|
27
|
+
* The § 11 reading on ALWAYS / Default On: a seat whose role is bound ALWAYS
|
|
28
|
+
* or Default On but whose effective set lacks the function (an agency or team
|
|
29
|
+
* layer, or the server's answer, took it away) still gets the drawn, refused
|
|
30
|
+
* control — only NEVER / NA / unbound leave it off.
|
|
31
|
+
*
|
|
32
|
+
* WHICH BOUND — precedence. The server decides on the LIVE Tier-1 rows
|
|
33
|
+
* (`platformRoles`, PLT-ADM-editable), so the door reads them when the host
|
|
34
|
+
* has them:
|
|
35
|
+
*
|
|
36
|
+
* 1. `roles` given (the same `AuthzRoleRow[]` the host passes to
|
|
37
|
+
* `resolveEffectiveFunctions`) → each seat role's bound is its live row's
|
|
38
|
+
* stored state, read exactly as the resolver reads it: no row, or no
|
|
39
|
+
* stored state → unbound; a malformed `functions` container → the role is
|
|
40
|
+
* bound for nothing; a malformed state or `NA` → NEVER. The codebook is
|
|
41
|
+
* not consulted at all.
|
|
42
|
+
* 2. `roles` absent → the codebook default bound (`codebookDefaultBound`,
|
|
43
|
+
* CVC-133 `bounds:`) — what platform seeds and what "clear" reverts to.
|
|
44
|
+
* 3. `functions` given (the `AuthzFunctionRow[]` catalog the host passes to
|
|
45
|
+
* the resolver) → the function must have a catalog row the resolver would
|
|
46
|
+
* keep (`retired` absent or exactly false), or it is not offered. Absent →
|
|
47
|
+
* canon alone decides (rule 8).
|
|
48
|
+
*
|
|
49
|
+
* A `roles` / `functions` value that is present but not an array is read as
|
|
50
|
+
* an empty list (fail closed: nothing bound / no catalog row), as the
|
|
51
|
+
* resolver would grant nothing from it.
|
|
52
|
+
*
|
|
53
|
+
* Stacking: roles stack and NEVER stays local to its role (resolver rule 2),
|
|
54
|
+
* so one role's NEVER never hides a door another held role is bound for.
|
|
55
|
+
* `allowed` follows the effective set alone — the resolved answer is the
|
|
56
|
+
* decision; the bound only decides whether a refusal is drawn or the control
|
|
57
|
+
* is left off. A function the effective set grants is always offered and
|
|
58
|
+
* allowed — the door never refuses what the server grants.
|
|
59
|
+
*
|
|
60
|
+
* Unknown / retired / not-v1 functions are never offered (resolver rule 8).
|
|
61
|
+
*
|
|
62
|
+
* THE DOOR IS THE EARLY ANSWER ONLY. It keeps a seat from reaching a dead
|
|
63
|
+
* end; it is not the gate. The server's `requireFunction` (each app's route
|
|
64
|
+
* guard over the same resolver) stays the authority, and a request the door
|
|
65
|
+
* would have allowed is still refused there when the server's answer differs.
|
|
66
|
+
*
|
|
67
|
+
* Pure, browser-safe, no I/O.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
import { DEFAULT_BOUND_STATE, PERMISSION_STATE } from "../constants/platform-auth.js";
|
|
71
|
+
import { CORE_FUNCTION_TITLES } from "../generated/authzBrowserTables.js";
|
|
72
|
+
import { codebookDefaultBound } from "./defaultBounds.js";
|
|
73
|
+
import {
|
|
74
|
+
isCanonEvaluableFunction,
|
|
75
|
+
type AuthzFunctionRow,
|
|
76
|
+
type AuthzRoleRow,
|
|
77
|
+
} from "./resolveEffectiveFunctions.js";
|
|
78
|
+
import { canonicalRoleCode } from "./roleCodes.js";
|
|
79
|
+
import { catalogRowCode, isPlainObject, own, readContainer, tier1State } from "./storedReads.js";
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A door's state. Field names and types match the components' door shape
|
|
83
|
+
* (`@htilabs/platform-common-components` 0.2.1 `ShareDoorState`
|
|
84
|
+
* `{ allowed, reason, offered }`; since 0.3.0 the pieces read the
|
|
85
|
+
* `{ allowed, reason }` half — `SharePurposeAccess`, `ShareRow.revokeAccess` —
|
|
86
|
+
* and the host reads `offered` to decide whether to draw the control).
|
|
87
|
+
*/
|
|
88
|
+
export interface FunctionDoorState {
|
|
89
|
+
allowed: boolean;
|
|
90
|
+
reason: string | null;
|
|
91
|
+
offered: boolean;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A label for a function key: a lookup function or a key → label map. */
|
|
95
|
+
export type FunctionLabelLookup =
|
|
96
|
+
((functionKey: string) => string | null | undefined) | Readonly<Record<string, string>>;
|
|
97
|
+
|
|
98
|
+
export interface FunctionDoorInput {
|
|
99
|
+
/** The seat's resolved answer: `resolveEffectiveFunctions(…)`'s function keys. */
|
|
100
|
+
readonly effectiveFunctions: Iterable<string>;
|
|
101
|
+
/**
|
|
102
|
+
* The seat's role codes (CVC-134 / CVC-135). Each is run through
|
|
103
|
+
* `canonicalRoleCode` first, so a stored re-keyed spelling (`hotline_op`)
|
|
104
|
+
* reads as its live role; an unresolvable code is dropped.
|
|
105
|
+
*/
|
|
106
|
+
readonly roleCodes: readonly string[];
|
|
107
|
+
/** The CVC-133 function key the control performs (e.g. `share_revoke`). */
|
|
108
|
+
readonly functionKey: string;
|
|
109
|
+
/**
|
|
110
|
+
* Optional: the words for the function in the refusal. Absent, or returning
|
|
111
|
+
* nothing → the codebook row's title; no title → the key itself.
|
|
112
|
+
*/
|
|
113
|
+
readonly label?: FunctionLabelLookup | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Optional: the LIVE Tier-1 role rows — the same `roles` the host passes to
|
|
116
|
+
* `resolveEffectiveFunctions`. Given → they decide each role's bound; absent
|
|
117
|
+
* → the codebook default bound (see "WHICH BOUND" above).
|
|
118
|
+
*/
|
|
119
|
+
readonly roles?: readonly AuthzRoleRow[] | null | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Optional: the LIVE function catalog — the same `functions` the host passes
|
|
122
|
+
* to `resolveEffectiveFunctions`. Given → a function with no kept row
|
|
123
|
+
* (missing or retired) is not offered.
|
|
124
|
+
*/
|
|
125
|
+
readonly functions?: readonly AuthzFunctionRow[] | null | undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const NOT_OFFERED: FunctionDoorState = Object.freeze({
|
|
129
|
+
offered: false,
|
|
130
|
+
allowed: false,
|
|
131
|
+
reason: null,
|
|
132
|
+
}) as FunctionDoorState;
|
|
133
|
+
|
|
134
|
+
function labelFor(functionKey: string, lookup: FunctionLabelLookup | undefined): string {
|
|
135
|
+
let label: string | null | undefined;
|
|
136
|
+
if (typeof lookup === "function") label = lookup(functionKey);
|
|
137
|
+
else if (lookup && Object.hasOwn(lookup, functionKey)) label = lookup[functionKey];
|
|
138
|
+
if (typeof label === "string" && label.trim()) return label;
|
|
139
|
+
return Object.hasOwn(CORE_FUNCTION_TITLES, functionKey)
|
|
140
|
+
? CORE_FUNCTION_TITLES[functionKey]!
|
|
141
|
+
: functionKey;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** A bound that draws the control: ALWAYS, PREF_YES (Default On) or PREF_NO (Default Off). */
|
|
145
|
+
function drawsControl(state: string | null | undefined): boolean {
|
|
146
|
+
return (
|
|
147
|
+
state === PERMISSION_STATE.ALWAYS ||
|
|
148
|
+
state === PERMISSION_STATE.PREF_YES ||
|
|
149
|
+
state === PERMISSION_STATE.PREF_NO
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Live rows by code, as the resolver indexes them (plain objects with a string `code`). */
|
|
154
|
+
function indexRoleRows(rows: unknown): Map<string, Readonly<Record<string, unknown>>> {
|
|
155
|
+
const byCode = new Map<string, Readonly<Record<string, unknown>>>();
|
|
156
|
+
if (!Array.isArray(rows)) return byCode;
|
|
157
|
+
for (const r of rows as readonly unknown[]) {
|
|
158
|
+
const code = isPlainObject(r) ? own(r, "code") : undefined;
|
|
159
|
+
if (isPlainObject(r) && typeof code === "string") byCode.set(code, r);
|
|
160
|
+
}
|
|
161
|
+
return byCode;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Is `roleCode` bound for `functionKey` on the live row (resolver's Tier-1 read)? */
|
|
165
|
+
function liveRoleBound(
|
|
166
|
+
rows: Map<string, Readonly<Record<string, unknown>>>,
|
|
167
|
+
roleCode: string,
|
|
168
|
+
functionKey: string,
|
|
169
|
+
): boolean {
|
|
170
|
+
const row = rows.get(roleCode);
|
|
171
|
+
if (row === undefined) return false;
|
|
172
|
+
const container = readContainer(own(row, "functions"));
|
|
173
|
+
if (container.kind === "malformed") return false;
|
|
174
|
+
return drawsControl(tier1State(container, functionKey));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Is `roleCode` bound for `functionKey` by the codebook default (NEVER / NA / unbound → no)? */
|
|
178
|
+
function codebookRoleBound(roleCode: string, functionKey: string): boolean {
|
|
179
|
+
const bound = codebookDefaultBound(functionKey, roleCode);
|
|
180
|
+
return bound !== DEFAULT_BOUND_STATE.NA && drawsControl(bound);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* STATUS: DRAFT. The door for one function on one seat (§ 11 encoding above).
|
|
185
|
+
* The UI's early answer only — the server's `requireFunction` is the authority.
|
|
186
|
+
*/
|
|
187
|
+
export function functionDoor(input: FunctionDoorInput): FunctionDoorState {
|
|
188
|
+
const { functionKey } = input;
|
|
189
|
+
if (typeof functionKey !== "string" || !isCanonEvaluableFunction(functionKey)) {
|
|
190
|
+
return { ...NOT_OFFERED };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
let granted = false;
|
|
194
|
+
for (const fn of input.effectiveFunctions) {
|
|
195
|
+
if (fn === functionKey) {
|
|
196
|
+
granted = true;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (granted) return { offered: true, allowed: true, reason: null };
|
|
201
|
+
|
|
202
|
+
const functions: unknown = input.functions;
|
|
203
|
+
if (functions !== undefined && functions !== null) {
|
|
204
|
+
const kept =
|
|
205
|
+
Array.isArray(functions) &&
|
|
206
|
+
(functions as readonly unknown[]).some((row) => catalogRowCode(row) === functionKey);
|
|
207
|
+
if (!kept) return { ...NOT_OFFERED };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const liveRows: unknown = input.roles;
|
|
211
|
+
const live = liveRows !== undefined && liveRows !== null ? indexRoleRows(liveRows) : null;
|
|
212
|
+
const roleCodes: unknown = input.roleCodes;
|
|
213
|
+
const bound = (Array.isArray(roleCodes) ? (roleCodes as readonly unknown[]) : []).some((code) => {
|
|
214
|
+
const canon = canonicalRoleCode(code);
|
|
215
|
+
if (canon === null) return false;
|
|
216
|
+
if (live === null) return codebookRoleBound(canon, functionKey);
|
|
217
|
+
return (
|
|
218
|
+
liveRoleBound(live, canon, functionKey) ||
|
|
219
|
+
(typeof code === "string" && code !== canon && liveRoleBound(live, code, functionKey))
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
if (!bound) return { ...NOT_OFFERED };
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
offered: true,
|
|
226
|
+
allowed: false,
|
|
227
|
+
reason: `${labelFor(functionKey, input.label)} is not part of your roles`,
|
|
228
|
+
};
|
|
229
|
+
}
|
package/src/authz/index.ts
CHANGED
|
@@ -109,13 +109,21 @@
|
|
|
109
109
|
*/
|
|
110
110
|
|
|
111
111
|
import {
|
|
112
|
-
DEFAULT_BOUND_STATE,
|
|
113
112
|
PERMISSION_STATE,
|
|
114
113
|
type DefaultBoundStateValue,
|
|
115
114
|
type PermissionStateValue,
|
|
116
115
|
} from "../constants/platform-auth.js";
|
|
117
116
|
import { CoreFunctionsKeys } from "../generated/cvc-enums.js";
|
|
118
117
|
import { CORE_FUNCTIONS_EVALUABLE_KEYS } from "../generated/coreFunctionsEvaluable.js";
|
|
118
|
+
import {
|
|
119
|
+
catalogRowCode,
|
|
120
|
+
isPlainObject,
|
|
121
|
+
own,
|
|
122
|
+
readContainer,
|
|
123
|
+
readState,
|
|
124
|
+
tier1State,
|
|
125
|
+
type StoredMap,
|
|
126
|
+
} from "./storedReads.js";
|
|
119
127
|
|
|
120
128
|
// ─── Canon (rule 8) ─────────────────────────────────────────────────────────
|
|
121
129
|
|
|
@@ -219,48 +227,7 @@ export interface ResolveEffectiveFunctionsInput {
|
|
|
219
227
|
}
|
|
220
228
|
|
|
221
229
|
// ─── Defensive reads ────────────────────────────────────────────────────────
|
|
222
|
-
|
|
223
|
-
type StoredMap = Readonly<Record<string, unknown>>;
|
|
224
|
-
|
|
225
|
-
/** A container read: not set, a usable plain object, or malformed. */
|
|
226
|
-
type Container = { readonly kind: "absent" } | { readonly kind: "malformed" } | {
|
|
227
|
-
readonly kind: "map";
|
|
228
|
-
readonly map: StoredMap;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const ABSENT: Container = { kind: "absent" };
|
|
232
|
-
const MALFORMED: Container = { kind: "malformed" };
|
|
233
|
-
|
|
234
|
-
function isPlainObject(v: unknown): v is StoredMap {
|
|
235
|
-
if (v === null || typeof v !== "object") return false;
|
|
236
|
-
const proto: unknown = Object.getPrototypeOf(v);
|
|
237
|
-
return proto === Object.prototype || proto === null;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function readContainer(v: unknown): Container {
|
|
241
|
-
if (v === undefined || v === null) return ABSENT;
|
|
242
|
-
return isPlainObject(v) ? { kind: "map", map: v } : MALFORMED;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/** An own property of a plain-object map (never an inherited key). */
|
|
246
|
-
function own(map: StoredMap, key: string): unknown {
|
|
247
|
-
return Object.hasOwn(map, key) ? map[key] : undefined;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const STATES: ReadonlySet<string> = new Set<string>(Object.values(PERMISSION_STATE));
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* One stored state: not set, a recognised state, or `"malformed"`. The
|
|
254
|
-
* codebook's `NA` ("Not relevant") is a recognised value, not a malformed one
|
|
255
|
-
* (a platform that seeds from CORE_FUNCTION_DEFAULT_BOUNDS stores it
|
|
256
|
-
* verbatim), and it is read as NEVER: non-grantable at every tier.
|
|
257
|
-
*/
|
|
258
|
-
function readState(map: StoredMap, code: string): PermissionStateValue | "malformed" | undefined {
|
|
259
|
-
const v = own(map, code);
|
|
260
|
-
if (v === undefined || v === null) return undefined;
|
|
261
|
-
if (v === DEFAULT_BOUND_STATE.NA) return PERMISSION_STATE.NEVER;
|
|
262
|
-
return typeof v === "string" && STATES.has(v) ? (v as PermissionStateValue) : "malformed";
|
|
263
|
-
}
|
|
230
|
+
// Shared with `functionDoor` (./storedReads.ts) so both read stored rows alike.
|
|
264
231
|
|
|
265
232
|
/** Rule 4: anything but "not set", PREF_YES or ALWAYS restricts. */
|
|
266
233
|
function teamValueRestricts(map: StoredMap, code: string): boolean {
|
|
@@ -364,12 +331,8 @@ export function resolveEffectiveFunctions(
|
|
|
364
331
|
// absent or exactly-false flag keeps a row).
|
|
365
332
|
const vocabulary: string[] = [];
|
|
366
333
|
for (const fn of catalog as readonly unknown[]) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const retired = own(fn, "retired");
|
|
370
|
-
if (typeof code !== "string" || !isCanonEvaluableFunction(code)) continue;
|
|
371
|
-
if (retired !== undefined && retired !== false) continue;
|
|
372
|
-
vocabulary.push(code);
|
|
334
|
+
const code = catalogRowCode(fn);
|
|
335
|
+
if (code !== null && isCanonEvaluableFunction(code)) vocabulary.push(code);
|
|
373
336
|
}
|
|
374
337
|
|
|
375
338
|
const agencyAll = readContainer(input.agencyOverrides);
|
|
@@ -391,9 +354,8 @@ export function resolveEffectiveFunctions(
|
|
|
391
354
|
// `authzResolve` `role_ineligible`, `:578-584`). A malformed stored
|
|
392
355
|
// state is NEVER; a stored NA reads NEVER (readState). Either way it is
|
|
393
356
|
// local to this role (rule 2).
|
|
394
|
-
const
|
|
395
|
-
if (
|
|
396
|
-
const tier1: PermissionStateValue = listed === "malformed" ? PERMISSION_STATE.NEVER : listed;
|
|
357
|
+
const tier1 = tier1State(roleFunctions, fn);
|
|
358
|
+
if (tier1 === undefined) continue;
|
|
397
359
|
|
|
398
360
|
// Tier 2 — agency. Tier-1 ALWAYS / NEVER are locked (rule 3); a
|
|
399
361
|
// malformed override (or container) is NEVER for this role.
|
|
@@ -431,6 +393,9 @@ export function resolveEffectiveFunctions(
|
|
|
431
393
|
* `teams.members[]` through its membership checker; `users.teams` is not kept
|
|
432
394
|
* in step with it), so this helper does not second-guess the caller against
|
|
433
395
|
* `seatTeamIds`. Pass only a team the caller has confirmed the seat sits on.
|
|
396
|
+
* A caller that derives its own acting team (Thread's `resolveActingTeamId`
|
|
397
|
+
* picks the first seat team whose apps include THREAD) MUST pass that answer
|
|
398
|
+
* here — the primary-team fallback below knows nothing about apps.
|
|
434
399
|
* - otherwise → the primary team, `seatTeamIds[0]`;
|
|
435
400
|
* - no teams → `null` (pass-through).
|
|
436
401
|
*/
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — stored role codes → live canon role codes
|
|
3
|
+
*
|
|
4
|
+
* STATUS: DRAFT (Tier B, 0.48.0). Ported verbatim in behaviour from the two
|
|
5
|
+
* local copies the apps carry today — Thread
|
|
6
|
+
* `packages/db/src/services/seatRoleCodes.ts` and platform
|
|
7
|
+
* `lib/authz/roleCodes.ts` — so PAVE 2.0 (which has no copy) and every later
|
|
8
|
+
* caller read one translation. The apps are not switched over in this
|
|
9
|
+
* release; when they are, their local copies go.
|
|
10
|
+
*
|
|
11
|
+
* Canon re-keys roles IN PLACE and migrates ON READ: nothing stored is ever
|
|
12
|
+
* rewritten (`userRolesSot._supersedes`, quoting canon
|
|
13
|
+
* `data/cvcs/core_user_role.yaml` `legacy_codes`). A seat that still stores
|
|
14
|
+
* `hotline_op` holds canon's `crisis_response` — the same role at the same
|
|
15
|
+
* wire code 135-004. Every reader of a seat's role codes resolves them here
|
|
16
|
+
* before it looks up a `platformRoles` row or a codebook bound, or a re-keyed
|
|
17
|
+
* seat finds no row under its stored code and resolves to no functions.
|
|
18
|
+
*
|
|
19
|
+
* EXACT SPELLINGS ONLY. A code resolves when it is, character for character:
|
|
20
|
+
* - a live canon code (an entry's `canonicalCode`: `crisis_response`, `MEM-ADM`);
|
|
21
|
+
* - a re-key SOURCE in CVC-135 `userRolesSot._supersedes.keyMap`
|
|
22
|
+
* (`hotline_op` → `crisis_response`, `case_advocate` → `case_nav`,
|
|
23
|
+
* `leads_investigator` → `investigator`);
|
|
24
|
+
* - a re-key SOURCE in CVC-134 `adminRolesSot._supersedes.keyMap`, in its key
|
|
25
|
+
* spelling (`acct_adm`) or canon's own spelling of it (`ACCT-ADM`) → `MEM-ADM`.
|
|
26
|
+
* Nothing is case- or separator-folded (`plt_adm`, `Plt-Adm` match no role —
|
|
27
|
+
* fail closed). Identity keyMap lines are key-space bookkeeping, not stored
|
|
28
|
+
* spellings, so they are not sources. A withdrawn code with no successor (the
|
|
29
|
+
* 1.0.0 missingness keys) means no role.
|
|
30
|
+
*
|
|
31
|
+
* Browser-safe: reads a small generated table
|
|
32
|
+
* (`src/generated/authzBrowserTables.ts`, held to the SOT files by
|
|
33
|
+
* `gen:authz-tables:check`), never the SOT JSON itself. No I/O.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import { CANON_ROLE_CODE_LIST, ROLE_CODE_RE_KEYS } from "../generated/authzBrowserTables.js";
|
|
37
|
+
|
|
38
|
+
/** Every live canon role code (CVC-135 user roles + CVC-134 admin roles). */
|
|
39
|
+
const CANON_ROLE_CODES: ReadonlySet<string> = new Set(CANON_ROLE_CODE_LIST);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Exact source spelling → live canon code (or null: no role), generated from
|
|
43
|
+
* the two SOTs' `_supersedes.keyMap` by `scripts/gen-authz-tables.ts` with the
|
|
44
|
+
* apps' rule (identity lines skipped; an admin key also in canon's
|
|
45
|
+
* upper-dash spelling; a spelling that is itself a live code never a source).
|
|
46
|
+
*/
|
|
47
|
+
const SOURCES: ReadonlyMap<string, string | null> = new Map(Object.entries(ROLE_CODE_RE_KEYS));
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* STATUS: DRAFT. The live canon role code a stored role code means, or `null`
|
|
51
|
+
* when it means no role (a withdrawn code with no successor, or any spelling
|
|
52
|
+
* that is neither a live code nor an exact re-key source). A non-string is no
|
|
53
|
+
* role.
|
|
54
|
+
*/
|
|
55
|
+
export function canonicalRoleCode(code: unknown): string | null {
|
|
56
|
+
if (typeof code !== "string") return null;
|
|
57
|
+
if (CANON_ROLE_CODES.has(code)) return code;
|
|
58
|
+
return SOURCES.has(code) ? (SOURCES.get(code) ?? null) : null;
|
|
59
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defensive reads of stored authz rows — INTERNAL to `./authz` (not exported
|
|
3
|
+
* from the barrel). `resolveEffectiveFunctions` and `functionDoor` both read
|
|
4
|
+
* `platformRoles` / `platformFunctions` rows through these, so the door's
|
|
5
|
+
* "is this role bound?" and the resolver's Tier-1 read can never disagree.
|
|
6
|
+
* Moved verbatim out of resolveEffectiveFunctions.ts (0.48.0); behaviour
|
|
7
|
+
* unchanged.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_BOUND_STATE,
|
|
12
|
+
PERMISSION_STATE,
|
|
13
|
+
type PermissionStateValue,
|
|
14
|
+
} from "../constants/platform-auth.js";
|
|
15
|
+
|
|
16
|
+
export type StoredMap = Readonly<Record<string, unknown>>;
|
|
17
|
+
|
|
18
|
+
/** A container read: not set, a usable plain object, or malformed. */
|
|
19
|
+
export type Container =
|
|
20
|
+
| { readonly kind: "absent" }
|
|
21
|
+
| { readonly kind: "malformed" }
|
|
22
|
+
| {
|
|
23
|
+
readonly kind: "map";
|
|
24
|
+
readonly map: StoredMap;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const ABSENT: Container = { kind: "absent" };
|
|
28
|
+
export const MALFORMED: Container = { kind: "malformed" };
|
|
29
|
+
|
|
30
|
+
export function isPlainObject(v: unknown): v is StoredMap {
|
|
31
|
+
if (v === null || typeof v !== "object") return false;
|
|
32
|
+
const proto: unknown = Object.getPrototypeOf(v);
|
|
33
|
+
return proto === Object.prototype || proto === null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function readContainer(v: unknown): Container {
|
|
37
|
+
if (v === undefined || v === null) return ABSENT;
|
|
38
|
+
return isPlainObject(v) ? { kind: "map", map: v } : MALFORMED;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** An own property of a plain-object map (never an inherited key). */
|
|
42
|
+
export function own(map: StoredMap, key: string): unknown {
|
|
43
|
+
return Object.hasOwn(map, key) ? map[key] : undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const STATES: ReadonlySet<string> = new Set<string>(Object.values(PERMISSION_STATE));
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* One stored state: not set, a recognised state, or `"malformed"`. The
|
|
50
|
+
* codebook's `NA` ("Not relevant") is a recognised value, not a malformed one
|
|
51
|
+
* (a platform that seeds from CORE_FUNCTION_DEFAULT_BOUNDS stores it
|
|
52
|
+
* verbatim), and it is read as NEVER: non-grantable at every tier.
|
|
53
|
+
*/
|
|
54
|
+
export function readState(
|
|
55
|
+
map: StoredMap,
|
|
56
|
+
code: string,
|
|
57
|
+
): PermissionStateValue | "malformed" | undefined {
|
|
58
|
+
const v = own(map, code);
|
|
59
|
+
if (v === undefined || v === null) return undefined;
|
|
60
|
+
if (v === DEFAULT_BOUND_STATE.NA) return PERMISSION_STATE.NEVER;
|
|
61
|
+
return typeof v === "string" && STATES.has(v) ? (v as PermissionStateValue) : "malformed";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The Tier-1 state one role row's `functions` container gives `code`:
|
|
66
|
+
* `undefined` when UNBOUND (or the container is absent); a malformed stored
|
|
67
|
+
* state reads NEVER and a stored NA reads NEVER (`readState`). A malformed
|
|
68
|
+
* CONTAINER is the caller's check (the role grants nothing).
|
|
69
|
+
*/
|
|
70
|
+
export function tier1State(
|
|
71
|
+
roleFunctions: Container,
|
|
72
|
+
code: string,
|
|
73
|
+
): PermissionStateValue | undefined {
|
|
74
|
+
const listed = roleFunctions.kind === "map" ? readState(roleFunctions.map, code) : undefined;
|
|
75
|
+
if (listed === undefined) return undefined;
|
|
76
|
+
return listed === "malformed" ? PERMISSION_STATE.NEVER : listed;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The code a `platformFunctions` row keeps in the vocabulary, or `null`: the
|
|
81
|
+
* row must be a plain object with a string `code`, and its `retired` must be
|
|
82
|
+
* absent or exactly `false`. Canon narrowing (`isCanonEvaluableFunction`) is
|
|
83
|
+
* the caller's.
|
|
84
|
+
*/
|
|
85
|
+
export function catalogRowCode(row: unknown): string | null {
|
|
86
|
+
if (!isPlainObject(row)) return null;
|
|
87
|
+
const code = own(row, "code");
|
|
88
|
+
const retired = own(row, "retired");
|
|
89
|
+
if (typeof code !== "string") return null;
|
|
90
|
+
if (retired !== undefined && retired !== false) return null;
|
|
91
|
+
return code;
|
|
92
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @htilabs/platform-common-models — the browser-safe authz tables
|
|
3
|
+
*
|
|
4
|
+
* AUTO-GENERATED FILE — DO NOT EDIT BY HAND.
|
|
5
|
+
* Regenerate with: `npm run gen:authz-tables` (drift gate: `gen:authz-tables:check`).
|
|
6
|
+
*
|
|
7
|
+
* From coreFunctions.v1.4.0.json (evaluable keys only), userRoles.v2.0.0.json and
|
|
8
|
+
* adminRoles.v2.0.0.json: what `functionDoor` and `canonicalRoleCode` read, so the
|
|
9
|
+
* `./authz` entry never inlines the SOT JSON. Not exported from the barrel.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const CORE_FUNCTION_TITLES_SOT_VERSION = "1.4.0";
|
|
13
|
+
|
|
14
|
+
/** Evaluable CVC-133 function key → codebook title. */
|
|
15
|
+
export const CORE_FUNCTION_TITLES: Readonly<Record<string, string>> = {
|
|
16
|
+
"agency_info_manage": "Edit own agency's profile",
|
|
17
|
+
"announcement_publish": "Publish announcements",
|
|
18
|
+
"api_key_manage": "Manage API keys",
|
|
19
|
+
"assessments_conduct": "Conduct Assessments",
|
|
20
|
+
"auth_model_manage_platform": "Manage platform authorization model",
|
|
21
|
+
"case_assign_reassign": "Assign / reassign case ownership",
|
|
22
|
+
"case_claim": "Claim inbound share (PAVE)",
|
|
23
|
+
"case_close": "Close case",
|
|
24
|
+
"case_collaborator_add": "Share / Add Users to a case",
|
|
25
|
+
"case_edit": "Edit Cases (add intake, case notes, goals, services)",
|
|
26
|
+
"case_needs_action_flag_manage": "Manage case escalation / needs-action flags",
|
|
27
|
+
"case_reopen": "Case Re-open",
|
|
28
|
+
"case_side_panel_use": "Utilize side panel for comments/notes and uploads",
|
|
29
|
+
"case_status_manage": "Change case status",
|
|
30
|
+
"case_transfer_bulk": "Bulk transfer cases (turnover)",
|
|
31
|
+
"case_view": "View (agency) Cases",
|
|
32
|
+
"case_visibility_manage": "Go dark / restore case visibility",
|
|
33
|
+
"ci_periodic_review": "Review criminal intelligence record (periodic)",
|
|
34
|
+
"ci_record_purge_or_retire": "Retire or purge criminal intelligence record",
|
|
35
|
+
"ci_record_validate": "Validate criminal intelligence record",
|
|
36
|
+
"ci_to_evidence_export_authorize": "Authorize criminal intelligence → evidence export",
|
|
37
|
+
"deconfliction_alert_acknowledge": "Accept a deconfliction alert",
|
|
38
|
+
"deconfliction_unmask": "Unmask a deconfliction",
|
|
39
|
+
"determination_perform": "Perform Determinations",
|
|
40
|
+
"disclose_external_request": "Request External Disclosure",
|
|
41
|
+
"enrollment_manage": "Manage program enrollments",
|
|
42
|
+
"exit_discharge_conduct": "Conduct program exit / discharge",
|
|
43
|
+
"export_deidentified": "Export de-identified reports/datasets",
|
|
44
|
+
"goals_plan_manage": "Create and manage plans, goals, action steps",
|
|
45
|
+
"idb_record_create": "Create IDB record",
|
|
46
|
+
"indicator_manual_add": "Add a manual indicator",
|
|
47
|
+
"investigation_create_claim": "Create Investigation + Claim a Tip / Lead",
|
|
48
|
+
"investigation_session_run": "Run an investigation session",
|
|
49
|
+
"investigative_database_search": "Search account IDB",
|
|
50
|
+
"investigative_request_send": "Submit an investigative request (Ask HTI)",
|
|
51
|
+
"lead_create": "Create a Tip / Lead",
|
|
52
|
+
"lead_publish": "Publish a Tip / Lead",
|
|
53
|
+
"lead_route_assign": "Route / assign a lead to an agency",
|
|
54
|
+
"lead_triage_manage": "Triage leads",
|
|
55
|
+
"magic_link_share_send": "Send Magic Link Shares",
|
|
56
|
+
"mandatory_report_send": "Send mandatory report",
|
|
57
|
+
"member_account_report_generate": "Member Account Report generation",
|
|
58
|
+
"member_onboarding_support": "Assist member onboarding (support)",
|
|
59
|
+
"message_moderate": "Moderate messages",
|
|
60
|
+
"message_send": "Send platform messages",
|
|
61
|
+
"milestone_log": "Log investigative milestones",
|
|
62
|
+
"needs_priorities_conduct": "Conduct needs assessment and immediate priorities",
|
|
63
|
+
"network_corpus_access": "Access raw/worked machine-network corpus",
|
|
64
|
+
"note_open_departed_author": "Open a deactivated author's private notes",
|
|
65
|
+
"onboarding_config_sign_off": "Approve the configuration summary (Phase III sign-off)",
|
|
66
|
+
"open_source_search": "Search across all open source information",
|
|
67
|
+
"person_association_update": "Assign or update person’s role, relationships, phone numbers or social media associations",
|
|
68
|
+
"person_merge_manage": "Manage person identity merges",
|
|
69
|
+
"platform_perm_modify": "Modify Platform Permissions",
|
|
70
|
+
"profile_domain_edit": "Edit subject profile domains",
|
|
71
|
+
"record_activity_view": "View a record's activity log",
|
|
72
|
+
"record_print": "Export/Print",
|
|
73
|
+
"referral_receive_external": "Receive External Referrals",
|
|
74
|
+
"referral_receive_internal": "Receive Internal Referrals",
|
|
75
|
+
"referral_send_external": "Refer External (Excluding VSP to LE)",
|
|
76
|
+
"referral_send_internal": "Refer Internal",
|
|
77
|
+
"roi_submit_manage": "Upload/Edit/Submit ROI",
|
|
78
|
+
"role_assign": "Role Assignment",
|
|
79
|
+
"roles_accounts_toggle": "Toggle Roles / Accounts",
|
|
80
|
+
"sandbox_environment_manage": "Manage sandbox and testing environments",
|
|
81
|
+
"screening_conduct": "Conduct Screenings",
|
|
82
|
+
"screening_view": "View Victim/Abuse Screening Responses",
|
|
83
|
+
"service_log_manage": "Log and manage service instances",
|
|
84
|
+
"session_create": "Record creation (sessions, cases, etc.)",
|
|
85
|
+
"share_config": "Sharing Configuration",
|
|
86
|
+
"share_revoke": "Revoke an active share / ROI",
|
|
87
|
+
"share_rule_approve_cross_agency": "Approve cross-agency sharing rules",
|
|
88
|
+
"share_vsp_to_le": "VSP to LE Share",
|
|
89
|
+
"srl_manage": "Manage the agency's Service Registry (SRL)",
|
|
90
|
+
"supervisee_thread_view": "View supervisee threads",
|
|
91
|
+
"support_ticket_triage": "Triage support tickets / bug reports",
|
|
92
|
+
"system_diagnostics_view": "View system diagnostics and logs (support)",
|
|
93
|
+
"team_config_manage": "Team structure & admin scoping (account-level)",
|
|
94
|
+
"team_membership_manage": "Manage team membership",
|
|
95
|
+
"team_share_narrowing": "Narrow a team's sharing",
|
|
96
|
+
"team_workflow_config_manage": "Manage team workflow configuration",
|
|
97
|
+
"training_gate_manage": "Manage training/certification gates (i.e. required modules for roles + teams)",
|
|
98
|
+
"usr_manage": "User Management",
|
|
99
|
+
"viewing_config_manage": "Configure internal viewing (Type A)",
|
|
100
|
+
"viewing_level_1_search": "Non-owned case identity on search",
|
|
101
|
+
"viewing_level_2_autocomplete": "Non-owned case identity in autocomplete",
|
|
102
|
+
"viewing_level_3_components": "Non-owned case component access",
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const ROLE_CODES_SOT_VERSIONS = { userRoles: "2.0.0", adminRoles: "2.0.0" } as const;
|
|
106
|
+
|
|
107
|
+
/** Every live CVC-135 user-role and CVC-134 admin-role `canonicalCode`. */
|
|
108
|
+
export const CANON_ROLE_CODE_LIST: readonly string[] = [
|
|
109
|
+
"case_nav",
|
|
110
|
+
"healthcare_provider_medical",
|
|
111
|
+
"behavioral_health_provider",
|
|
112
|
+
"crisis_response",
|
|
113
|
+
"intel_analyst",
|
|
114
|
+
"investigator",
|
|
115
|
+
"le_liaison_vsp",
|
|
116
|
+
"legal_advocate",
|
|
117
|
+
"mandatory_reporter",
|
|
118
|
+
"mdt_participant",
|
|
119
|
+
"prosecutor_review",
|
|
120
|
+
"public_reporter",
|
|
121
|
+
"research_analytics",
|
|
122
|
+
"screener",
|
|
123
|
+
"volunteer",
|
|
124
|
+
"PLT-ADM",
|
|
125
|
+
"PLT-SUP",
|
|
126
|
+
"MEM-ADM",
|
|
127
|
+
"TEAM-ADM",
|
|
128
|
+
"AUD",
|
|
129
|
+
"DATA-ADM",
|
|
130
|
+
"GOV-AUD",
|
|
131
|
+
"CIRO",
|
|
132
|
+
"SUP",
|
|
133
|
+
"TRAIN-ADM",
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
/** Exact stored source spelling → live canon code, or null (withdrawn, no successor). */
|
|
137
|
+
export const ROLE_CODE_RE_KEYS: Readonly<Record<string, string | null>> = {
|
|
138
|
+
"missingness_root": null,
|
|
139
|
+
"unknown": null,
|
|
140
|
+
"anonymous": null,
|
|
141
|
+
"data_not_collected": null,
|
|
142
|
+
"hotline_op": "crisis_response",
|
|
143
|
+
"case_advocate": "case_nav",
|
|
144
|
+
"leads_investigator": "investigator",
|
|
145
|
+
"MISSINGNESS-ROOT": null,
|
|
146
|
+
"UNKNOWN": null,
|
|
147
|
+
"ANONYMOUS": null,
|
|
148
|
+
"DATA-NOT-COLLECTED": null,
|
|
149
|
+
"acct_adm": "MEM-ADM",
|
|
150
|
+
"ACCT-ADM": "MEM-ADM",
|
|
151
|
+
};
|