@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.
@@ -211,6 +211,9 @@ declare function resolveEffectiveFunctions(input: ResolveEffectiveFunctionsInput
211
211
  * `teams.members[]` through its membership checker; `users.teams` is not kept
212
212
  * in step with it), so this helper does not second-guess the caller against
213
213
  * `seatTeamIds`. Pass only a team the caller has confirmed the seat sits on.
214
+ * A caller that derives its own acting team (Thread's `resolveActingTeamId`
215
+ * picks the first seat team whose apps include THREAD) MUST pass that answer
216
+ * here — the primary-team fallback below knows nothing about apps.
214
217
  * - otherwise → the primary team, `seatTeamIds[0]`;
215
218
  * - no teams → `null` (pass-through).
216
219
  */
@@ -316,4 +319,164 @@ declare const CORE_FUNCTION_DEFAULT_BOUNDS: Readonly<Record<string, Readonly<Rec
316
319
  */
317
320
  declare function codebookDefaultBound(functionCode: string, roleCode: string): DefaultBoundStateValue | null;
318
321
 
319
- export { type AuthzFunctionRow, type AuthzRoleOverrides, type AuthzRoleRow, type AuthzStateMap, type AuthzTeamPolicy, type AuthzTier1StateMap, CORE_FUNCTION_DEFAULT_BOUNDS, CORE_FUNCTION_DEFAULT_BOUNDS_SOT_VERSION, DefaultBoundStateValue, type ResolveEffectiveFunctionsInput, VIEWING_LEVEL_FUNCTIONS, type ViewingLevel, codebookDefaultBound, isCanonEvaluableFunction, resolveEffectiveFunctions, resolveEffectiveViewingLevel, selectActingTeamId, viewingLevelFromFunctions };
322
+ /**
323
+ * @htilabs/platform-common-models — the function door (Kickoff 08b § 11)
324
+ *
325
+ * STATUS: DRAFT (Tier B, 0.48.0).
326
+ *
327
+ * The resolver half (`resolveEffectiveFunctions`) decides what a seat may do.
328
+ * This is the other half: it carries that answer to the screen in the shape
329
+ * the shared components take, so no shared piece decides anything (Crysta,
330
+ * 2026-10-20: "A shared piece never decides who may view, access, or edit it
331
+ * … It receives those decisions and only shows them."). The host app runs
332
+ * this over the seat's resolved answer and hands the result to the piece —
333
+ * `{ allowed, reason }` is what `SharePurposeAccess` (`vspToLe`) and
334
+ * `ShareRow`'s `revokeAccess` read; `offered` tells the host whether to draw
335
+ * the control at all.
336
+ *
337
+ * THE ENCODING (§ 11). Per seat, the function's Tier-1 bound for each of
338
+ * the seat's roles, stacked:
339
+ *
340
+ * - NEVER (or NA, "Not relevant", which the resolver reads as NEVER) for
341
+ * every role the seat holds, or no role bound at all → the control is not
342
+ * part of this seat's job: `{ offered: false, allowed: false, reason: null }`.
343
+ * - some role bound ALWAYS / PREF_YES (Default On) / PREF_NO (Default Off),
344
+ * but the function is NOT in the seat's effective set → drawn and refused:
345
+ * `{ offered: true, allowed: false, reason: "<label> is not part of your roles" }`.
346
+ * - in the effective set → `{ offered: true, allowed: true, reason: null }`.
347
+ *
348
+ * The § 11 reading on ALWAYS / Default On: a seat whose role is bound ALWAYS
349
+ * or Default On but whose effective set lacks the function (an agency or team
350
+ * layer, or the server's answer, took it away) still gets the drawn, refused
351
+ * control — only NEVER / NA / unbound leave it off.
352
+ *
353
+ * WHICH BOUND — precedence. The server decides on the LIVE Tier-1 rows
354
+ * (`platformRoles`, PLT-ADM-editable), so the door reads them when the host
355
+ * has them:
356
+ *
357
+ * 1. `roles` given (the same `AuthzRoleRow[]` the host passes to
358
+ * `resolveEffectiveFunctions`) → each seat role's bound is its live row's
359
+ * stored state, read exactly as the resolver reads it: no row, or no
360
+ * stored state → unbound; a malformed `functions` container → the role is
361
+ * bound for nothing; a malformed state or `NA` → NEVER. The codebook is
362
+ * not consulted at all.
363
+ * 2. `roles` absent → the codebook default bound (`codebookDefaultBound`,
364
+ * CVC-133 `bounds:`) — what platform seeds and what "clear" reverts to.
365
+ * 3. `functions` given (the `AuthzFunctionRow[]` catalog the host passes to
366
+ * the resolver) → the function must have a catalog row the resolver would
367
+ * keep (`retired` absent or exactly false), or it is not offered. Absent →
368
+ * canon alone decides (rule 8).
369
+ *
370
+ * A `roles` / `functions` value that is present but not an array is read as
371
+ * an empty list (fail closed: nothing bound / no catalog row), as the
372
+ * resolver would grant nothing from it.
373
+ *
374
+ * Stacking: roles stack and NEVER stays local to its role (resolver rule 2),
375
+ * so one role's NEVER never hides a door another held role is bound for.
376
+ * `allowed` follows the effective set alone — the resolved answer is the
377
+ * decision; the bound only decides whether a refusal is drawn or the control
378
+ * is left off. A function the effective set grants is always offered and
379
+ * allowed — the door never refuses what the server grants.
380
+ *
381
+ * Unknown / retired / not-v1 functions are never offered (resolver rule 8).
382
+ *
383
+ * THE DOOR IS THE EARLY ANSWER ONLY. It keeps a seat from reaching a dead
384
+ * end; it is not the gate. The server's `requireFunction` (each app's route
385
+ * guard over the same resolver) stays the authority, and a request the door
386
+ * would have allowed is still refused there when the server's answer differs.
387
+ *
388
+ * Pure, browser-safe, no I/O.
389
+ */
390
+
391
+ /**
392
+ * A door's state. Field names and types match the components' door shape
393
+ * (`@htilabs/platform-common-components` 0.2.1 `ShareDoorState`
394
+ * `{ allowed, reason, offered }`; since 0.3.0 the pieces read the
395
+ * `{ allowed, reason }` half — `SharePurposeAccess`, `ShareRow.revokeAccess` —
396
+ * and the host reads `offered` to decide whether to draw the control).
397
+ */
398
+ interface FunctionDoorState {
399
+ allowed: boolean;
400
+ reason: string | null;
401
+ offered: boolean;
402
+ }
403
+ /** A label for a function key: a lookup function or a key → label map. */
404
+ type FunctionLabelLookup = ((functionKey: string) => string | null | undefined) | Readonly<Record<string, string>>;
405
+ interface FunctionDoorInput {
406
+ /** The seat's resolved answer: `resolveEffectiveFunctions(…)`'s function keys. */
407
+ readonly effectiveFunctions: Iterable<string>;
408
+ /**
409
+ * The seat's role codes (CVC-134 / CVC-135). Each is run through
410
+ * `canonicalRoleCode` first, so a stored re-keyed spelling (`hotline_op`)
411
+ * reads as its live role; an unresolvable code is dropped.
412
+ */
413
+ readonly roleCodes: readonly string[];
414
+ /** The CVC-133 function key the control performs (e.g. `share_revoke`). */
415
+ readonly functionKey: string;
416
+ /**
417
+ * Optional: the words for the function in the refusal. Absent, or returning
418
+ * nothing → the codebook row's title; no title → the key itself.
419
+ */
420
+ readonly label?: FunctionLabelLookup | undefined;
421
+ /**
422
+ * Optional: the LIVE Tier-1 role rows — the same `roles` the host passes to
423
+ * `resolveEffectiveFunctions`. Given → they decide each role's bound; absent
424
+ * → the codebook default bound (see "WHICH BOUND" above).
425
+ */
426
+ readonly roles?: readonly AuthzRoleRow[] | null | undefined;
427
+ /**
428
+ * Optional: the LIVE function catalog — the same `functions` the host passes
429
+ * to `resolveEffectiveFunctions`. Given → a function with no kept row
430
+ * (missing or retired) is not offered.
431
+ */
432
+ readonly functions?: readonly AuthzFunctionRow[] | null | undefined;
433
+ }
434
+ /**
435
+ * STATUS: DRAFT. The door for one function on one seat (§ 11 encoding above).
436
+ * The UI's early answer only — the server's `requireFunction` is the authority.
437
+ */
438
+ declare function functionDoor(input: FunctionDoorInput): FunctionDoorState;
439
+
440
+ /**
441
+ * @htilabs/platform-common-models — stored role codes → live canon role codes
442
+ *
443
+ * STATUS: DRAFT (Tier B, 0.48.0). Ported verbatim in behaviour from the two
444
+ * local copies the apps carry today — Thread
445
+ * `packages/db/src/services/seatRoleCodes.ts` and platform
446
+ * `lib/authz/roleCodes.ts` — so PAVE 2.0 (which has no copy) and every later
447
+ * caller read one translation. The apps are not switched over in this
448
+ * release; when they are, their local copies go.
449
+ *
450
+ * Canon re-keys roles IN PLACE and migrates ON READ: nothing stored is ever
451
+ * rewritten (`userRolesSot._supersedes`, quoting canon
452
+ * `data/cvcs/core_user_role.yaml` `legacy_codes`). A seat that still stores
453
+ * `hotline_op` holds canon's `crisis_response` — the same role at the same
454
+ * wire code 135-004. Every reader of a seat's role codes resolves them here
455
+ * before it looks up a `platformRoles` row or a codebook bound, or a re-keyed
456
+ * seat finds no row under its stored code and resolves to no functions.
457
+ *
458
+ * EXACT SPELLINGS ONLY. A code resolves when it is, character for character:
459
+ * - a live canon code (an entry's `canonicalCode`: `crisis_response`, `MEM-ADM`);
460
+ * - a re-key SOURCE in CVC-135 `userRolesSot._supersedes.keyMap`
461
+ * (`hotline_op` → `crisis_response`, `case_advocate` → `case_nav`,
462
+ * `leads_investigator` → `investigator`);
463
+ * - a re-key SOURCE in CVC-134 `adminRolesSot._supersedes.keyMap`, in its key
464
+ * spelling (`acct_adm`) or canon's own spelling of it (`ACCT-ADM`) → `MEM-ADM`.
465
+ * Nothing is case- or separator-folded (`plt_adm`, `Plt-Adm` match no role —
466
+ * fail closed). Identity keyMap lines are key-space bookkeeping, not stored
467
+ * spellings, so they are not sources. A withdrawn code with no successor (the
468
+ * 1.0.0 missingness keys) means no role.
469
+ *
470
+ * Browser-safe: reads a small generated table
471
+ * (`src/generated/authzBrowserTables.ts`, held to the SOT files by
472
+ * `gen:authz-tables:check`), never the SOT JSON itself. No I/O.
473
+ */
474
+ /**
475
+ * STATUS: DRAFT. The live canon role code a stored role code means, or `null`
476
+ * when it means no role (a withdrawn code with no successor, or any spelling
477
+ * that is neither a live code nor an exact re-key source). A non-string is no
478
+ * role.
479
+ */
480
+ declare function canonicalRoleCode(code: unknown): string | null;
481
+
482
+ export { type AuthzFunctionRow, type AuthzRoleOverrides, type AuthzRoleRow, type AuthzStateMap, type AuthzTeamPolicy, type AuthzTier1StateMap, CORE_FUNCTION_DEFAULT_BOUNDS, CORE_FUNCTION_DEFAULT_BOUNDS_SOT_VERSION, DefaultBoundStateValue, type FunctionDoorInput, type FunctionDoorState, type FunctionLabelLookup, type ResolveEffectiveFunctionsInput, VIEWING_LEVEL_FUNCTIONS, type ViewingLevel, canonicalRoleCode, codebookDefaultBound, functionDoor, isCanonEvaluableFunction, resolveEffectiveFunctions, resolveEffectiveViewingLevel, selectActingTeamId, viewingLevelFromFunctions };
@@ -211,6 +211,9 @@ declare function resolveEffectiveFunctions(input: ResolveEffectiveFunctionsInput
211
211
  * `teams.members[]` through its membership checker; `users.teams` is not kept
212
212
  * in step with it), so this helper does not second-guess the caller against
213
213
  * `seatTeamIds`. Pass only a team the caller has confirmed the seat sits on.
214
+ * A caller that derives its own acting team (Thread's `resolveActingTeamId`
215
+ * picks the first seat team whose apps include THREAD) MUST pass that answer
216
+ * here — the primary-team fallback below knows nothing about apps.
214
217
  * - otherwise → the primary team, `seatTeamIds[0]`;
215
218
  * - no teams → `null` (pass-through).
216
219
  */
@@ -316,4 +319,164 @@ declare const CORE_FUNCTION_DEFAULT_BOUNDS: Readonly<Record<string, Readonly<Rec
316
319
  */
317
320
  declare function codebookDefaultBound(functionCode: string, roleCode: string): DefaultBoundStateValue | null;
318
321
 
319
- export { type AuthzFunctionRow, type AuthzRoleOverrides, type AuthzRoleRow, type AuthzStateMap, type AuthzTeamPolicy, type AuthzTier1StateMap, CORE_FUNCTION_DEFAULT_BOUNDS, CORE_FUNCTION_DEFAULT_BOUNDS_SOT_VERSION, DefaultBoundStateValue, type ResolveEffectiveFunctionsInput, VIEWING_LEVEL_FUNCTIONS, type ViewingLevel, codebookDefaultBound, isCanonEvaluableFunction, resolveEffectiveFunctions, resolveEffectiveViewingLevel, selectActingTeamId, viewingLevelFromFunctions };
322
+ /**
323
+ * @htilabs/platform-common-models — the function door (Kickoff 08b § 11)
324
+ *
325
+ * STATUS: DRAFT (Tier B, 0.48.0).
326
+ *
327
+ * The resolver half (`resolveEffectiveFunctions`) decides what a seat may do.
328
+ * This is the other half: it carries that answer to the screen in the shape
329
+ * the shared components take, so no shared piece decides anything (Crysta,
330
+ * 2026-10-20: "A shared piece never decides who may view, access, or edit it
331
+ * … It receives those decisions and only shows them."). The host app runs
332
+ * this over the seat's resolved answer and hands the result to the piece —
333
+ * `{ allowed, reason }` is what `SharePurposeAccess` (`vspToLe`) and
334
+ * `ShareRow`'s `revokeAccess` read; `offered` tells the host whether to draw
335
+ * the control at all.
336
+ *
337
+ * THE ENCODING (§ 11). Per seat, the function's Tier-1 bound for each of
338
+ * the seat's roles, stacked:
339
+ *
340
+ * - NEVER (or NA, "Not relevant", which the resolver reads as NEVER) for
341
+ * every role the seat holds, or no role bound at all → the control is not
342
+ * part of this seat's job: `{ offered: false, allowed: false, reason: null }`.
343
+ * - some role bound ALWAYS / PREF_YES (Default On) / PREF_NO (Default Off),
344
+ * but the function is NOT in the seat's effective set → drawn and refused:
345
+ * `{ offered: true, allowed: false, reason: "<label> is not part of your roles" }`.
346
+ * - in the effective set → `{ offered: true, allowed: true, reason: null }`.
347
+ *
348
+ * The § 11 reading on ALWAYS / Default On: a seat whose role is bound ALWAYS
349
+ * or Default On but whose effective set lacks the function (an agency or team
350
+ * layer, or the server's answer, took it away) still gets the drawn, refused
351
+ * control — only NEVER / NA / unbound leave it off.
352
+ *
353
+ * WHICH BOUND — precedence. The server decides on the LIVE Tier-1 rows
354
+ * (`platformRoles`, PLT-ADM-editable), so the door reads them when the host
355
+ * has them:
356
+ *
357
+ * 1. `roles` given (the same `AuthzRoleRow[]` the host passes to
358
+ * `resolveEffectiveFunctions`) → each seat role's bound is its live row's
359
+ * stored state, read exactly as the resolver reads it: no row, or no
360
+ * stored state → unbound; a malformed `functions` container → the role is
361
+ * bound for nothing; a malformed state or `NA` → NEVER. The codebook is
362
+ * not consulted at all.
363
+ * 2. `roles` absent → the codebook default bound (`codebookDefaultBound`,
364
+ * CVC-133 `bounds:`) — what platform seeds and what "clear" reverts to.
365
+ * 3. `functions` given (the `AuthzFunctionRow[]` catalog the host passes to
366
+ * the resolver) → the function must have a catalog row the resolver would
367
+ * keep (`retired` absent or exactly false), or it is not offered. Absent →
368
+ * canon alone decides (rule 8).
369
+ *
370
+ * A `roles` / `functions` value that is present but not an array is read as
371
+ * an empty list (fail closed: nothing bound / no catalog row), as the
372
+ * resolver would grant nothing from it.
373
+ *
374
+ * Stacking: roles stack and NEVER stays local to its role (resolver rule 2),
375
+ * so one role's NEVER never hides a door another held role is bound for.
376
+ * `allowed` follows the effective set alone — the resolved answer is the
377
+ * decision; the bound only decides whether a refusal is drawn or the control
378
+ * is left off. A function the effective set grants is always offered and
379
+ * allowed — the door never refuses what the server grants.
380
+ *
381
+ * Unknown / retired / not-v1 functions are never offered (resolver rule 8).
382
+ *
383
+ * THE DOOR IS THE EARLY ANSWER ONLY. It keeps a seat from reaching a dead
384
+ * end; it is not the gate. The server's `requireFunction` (each app's route
385
+ * guard over the same resolver) stays the authority, and a request the door
386
+ * would have allowed is still refused there when the server's answer differs.
387
+ *
388
+ * Pure, browser-safe, no I/O.
389
+ */
390
+
391
+ /**
392
+ * A door's state. Field names and types match the components' door shape
393
+ * (`@htilabs/platform-common-components` 0.2.1 `ShareDoorState`
394
+ * `{ allowed, reason, offered }`; since 0.3.0 the pieces read the
395
+ * `{ allowed, reason }` half — `SharePurposeAccess`, `ShareRow.revokeAccess` —
396
+ * and the host reads `offered` to decide whether to draw the control).
397
+ */
398
+ interface FunctionDoorState {
399
+ allowed: boolean;
400
+ reason: string | null;
401
+ offered: boolean;
402
+ }
403
+ /** A label for a function key: a lookup function or a key → label map. */
404
+ type FunctionLabelLookup = ((functionKey: string) => string | null | undefined) | Readonly<Record<string, string>>;
405
+ interface FunctionDoorInput {
406
+ /** The seat's resolved answer: `resolveEffectiveFunctions(…)`'s function keys. */
407
+ readonly effectiveFunctions: Iterable<string>;
408
+ /**
409
+ * The seat's role codes (CVC-134 / CVC-135). Each is run through
410
+ * `canonicalRoleCode` first, so a stored re-keyed spelling (`hotline_op`)
411
+ * reads as its live role; an unresolvable code is dropped.
412
+ */
413
+ readonly roleCodes: readonly string[];
414
+ /** The CVC-133 function key the control performs (e.g. `share_revoke`). */
415
+ readonly functionKey: string;
416
+ /**
417
+ * Optional: the words for the function in the refusal. Absent, or returning
418
+ * nothing → the codebook row's title; no title → the key itself.
419
+ */
420
+ readonly label?: FunctionLabelLookup | undefined;
421
+ /**
422
+ * Optional: the LIVE Tier-1 role rows — the same `roles` the host passes to
423
+ * `resolveEffectiveFunctions`. Given → they decide each role's bound; absent
424
+ * → the codebook default bound (see "WHICH BOUND" above).
425
+ */
426
+ readonly roles?: readonly AuthzRoleRow[] | null | undefined;
427
+ /**
428
+ * Optional: the LIVE function catalog — the same `functions` the host passes
429
+ * to `resolveEffectiveFunctions`. Given → a function with no kept row
430
+ * (missing or retired) is not offered.
431
+ */
432
+ readonly functions?: readonly AuthzFunctionRow[] | null | undefined;
433
+ }
434
+ /**
435
+ * STATUS: DRAFT. The door for one function on one seat (§ 11 encoding above).
436
+ * The UI's early answer only — the server's `requireFunction` is the authority.
437
+ */
438
+ declare function functionDoor(input: FunctionDoorInput): FunctionDoorState;
439
+
440
+ /**
441
+ * @htilabs/platform-common-models — stored role codes → live canon role codes
442
+ *
443
+ * STATUS: DRAFT (Tier B, 0.48.0). Ported verbatim in behaviour from the two
444
+ * local copies the apps carry today — Thread
445
+ * `packages/db/src/services/seatRoleCodes.ts` and platform
446
+ * `lib/authz/roleCodes.ts` — so PAVE 2.0 (which has no copy) and every later
447
+ * caller read one translation. The apps are not switched over in this
448
+ * release; when they are, their local copies go.
449
+ *
450
+ * Canon re-keys roles IN PLACE and migrates ON READ: nothing stored is ever
451
+ * rewritten (`userRolesSot._supersedes`, quoting canon
452
+ * `data/cvcs/core_user_role.yaml` `legacy_codes`). A seat that still stores
453
+ * `hotline_op` holds canon's `crisis_response` — the same role at the same
454
+ * wire code 135-004. Every reader of a seat's role codes resolves them here
455
+ * before it looks up a `platformRoles` row or a codebook bound, or a re-keyed
456
+ * seat finds no row under its stored code and resolves to no functions.
457
+ *
458
+ * EXACT SPELLINGS ONLY. A code resolves when it is, character for character:
459
+ * - a live canon code (an entry's `canonicalCode`: `crisis_response`, `MEM-ADM`);
460
+ * - a re-key SOURCE in CVC-135 `userRolesSot._supersedes.keyMap`
461
+ * (`hotline_op` → `crisis_response`, `case_advocate` → `case_nav`,
462
+ * `leads_investigator` → `investigator`);
463
+ * - a re-key SOURCE in CVC-134 `adminRolesSot._supersedes.keyMap`, in its key
464
+ * spelling (`acct_adm`) or canon's own spelling of it (`ACCT-ADM`) → `MEM-ADM`.
465
+ * Nothing is case- or separator-folded (`plt_adm`, `Plt-Adm` match no role —
466
+ * fail closed). Identity keyMap lines are key-space bookkeeping, not stored
467
+ * spellings, so they are not sources. A withdrawn code with no successor (the
468
+ * 1.0.0 missingness keys) means no role.
469
+ *
470
+ * Browser-safe: reads a small generated table
471
+ * (`src/generated/authzBrowserTables.ts`, held to the SOT files by
472
+ * `gen:authz-tables:check`), never the SOT JSON itself. No I/O.
473
+ */
474
+ /**
475
+ * STATUS: DRAFT. The live canon role code a stored role code means, or `null`
476
+ * when it means no role (a withdrawn code with no successor, or any spelling
477
+ * that is neither a live code nor an exact re-key source). A non-string is no
478
+ * role.
479
+ */
480
+ declare function canonicalRoleCode(code: unknown): string | null;
481
+
482
+ export { type AuthzFunctionRow, type AuthzRoleOverrides, type AuthzRoleRow, type AuthzStateMap, type AuthzTeamPolicy, type AuthzTier1StateMap, CORE_FUNCTION_DEFAULT_BOUNDS, CORE_FUNCTION_DEFAULT_BOUNDS_SOT_VERSION, DefaultBoundStateValue, type FunctionDoorInput, type FunctionDoorState, type FunctionLabelLookup, type ResolveEffectiveFunctionsInput, VIEWING_LEVEL_FUNCTIONS, type ViewingLevel, canonicalRoleCode, codebookDefaultBound, functionDoor, isCanonEvaluableFunction, resolveEffectiveFunctions, resolveEffectiveViewingLevel, selectActingTeamId, viewingLevelFromFunctions };
@@ -371,13 +371,7 @@ var CORE_FUNCTIONS_EVALUABLE_KEYS = [
371
371
  "viewing_level_3_components"
372
372
  ];
373
373
 
374
- // src/authz/resolveEffectiveFunctions.ts
375
- var CANON_EVALUABLE = new Set(
376
- CORE_FUNCTIONS_EVALUABLE_KEYS.filter((k) => Object.hasOwn(CoreFunctionsKeys, k))
377
- );
378
- function isCanonEvaluableFunction(code) {
379
- return CANON_EVALUABLE.has(code);
380
- }
374
+ // src/authz/storedReads.ts
381
375
  var ABSENT = { kind: "absent" };
382
376
  var MALFORMED = { kind: "malformed" };
383
377
  function isPlainObject(v) {
@@ -399,6 +393,27 @@ function readState(map, code) {
399
393
  if (v === DEFAULT_BOUND_STATE.NA) return PERMISSION_STATE.NEVER;
400
394
  return typeof v === "string" && STATES.has(v) ? v : "malformed";
401
395
  }
396
+ function tier1State(roleFunctions, code) {
397
+ const listed = roleFunctions.kind === "map" ? readState(roleFunctions.map, code) : void 0;
398
+ if (listed === void 0) return void 0;
399
+ return listed === "malformed" ? PERMISSION_STATE.NEVER : listed;
400
+ }
401
+ function catalogRowCode(row) {
402
+ if (!isPlainObject(row)) return null;
403
+ const code = own(row, "code");
404
+ const retired = own(row, "retired");
405
+ if (typeof code !== "string") return null;
406
+ if (retired !== void 0 && retired !== false) return null;
407
+ return code;
408
+ }
409
+
410
+ // src/authz/resolveEffectiveFunctions.ts
411
+ var CANON_EVALUABLE = new Set(
412
+ CORE_FUNCTIONS_EVALUABLE_KEYS.filter((k) => Object.hasOwn(CoreFunctionsKeys, k))
413
+ );
414
+ function isCanonEvaluableFunction(code) {
415
+ return CANON_EVALUABLE.has(code);
416
+ }
402
417
  function teamValueRestricts(map, code) {
403
418
  const gate = readState(map, code);
404
419
  return gate !== void 0 && gate !== PERMISSION_STATE.PREF_YES && gate !== PERMISSION_STATE.ALWAYS;
@@ -466,12 +481,8 @@ function resolveEffectiveFunctions(input) {
466
481
  if (heldCodes.length === 0) return [];
467
482
  const vocabulary = [];
468
483
  for (const fn of catalog) {
469
- if (!isPlainObject(fn)) continue;
470
- const code = own(fn, "code");
471
- const retired = own(fn, "retired");
472
- if (typeof code !== "string" || !isCanonEvaluableFunction(code)) continue;
473
- if (retired !== void 0 && retired !== false) continue;
474
- vocabulary.push(code);
484
+ const code = catalogRowCode(fn);
485
+ if (code !== null && isCanonEvaluableFunction(code)) vocabulary.push(code);
475
486
  }
476
487
  const agencyAll = readContainer(input.agencyOverrides);
477
488
  const team = compileTeamGate(input.teamPolicy);
@@ -483,9 +494,8 @@ function resolveEffectiveFunctions(input) {
483
494
  const agency = agencyAll.kind === "map" ? readContainer(own(agencyAll.map, roleCode)) : agencyAll;
484
495
  for (const fn of vocabulary) {
485
496
  if (granted.has(fn)) continue;
486
- const listed = roleFunctions.kind === "map" ? readState(roleFunctions.map, fn) : void 0;
487
- if (listed === void 0) continue;
488
- const tier1 = listed === "malformed" ? PERMISSION_STATE.NEVER : listed;
497
+ const tier1 = tier1State(roleFunctions, fn);
498
+ if (tier1 === void 0) continue;
489
499
  let state = tier1;
490
500
  if (tier1 !== PERMISSION_STATE.ALWAYS && tier1 !== PERMISSION_STATE.NEVER) {
491
501
  const override = agency.kind === "malformed" ? "malformed" : agency.kind === "map" ? readState(agency.map, fn) : void 0;
@@ -615,6 +625,219 @@ function codebookDefaultBound(functionCode, roleCode) {
615
625
  const roles = CORE_FUNCTION_DEFAULT_BOUNDS[functionCode];
616
626
  return Object.hasOwn(roles, roleCode) ? roles[roleCode] : null;
617
627
  }
628
+
629
+ // src/generated/authzBrowserTables.ts
630
+ var CORE_FUNCTION_TITLES = {
631
+ "agency_info_manage": "Edit own agency's profile",
632
+ "announcement_publish": "Publish announcements",
633
+ "api_key_manage": "Manage API keys",
634
+ "assessments_conduct": "Conduct Assessments",
635
+ "auth_model_manage_platform": "Manage platform authorization model",
636
+ "case_assign_reassign": "Assign / reassign case ownership",
637
+ "case_claim": "Claim inbound share (PAVE)",
638
+ "case_close": "Close case",
639
+ "case_collaborator_add": "Share / Add Users to a case",
640
+ "case_edit": "Edit Cases (add intake, case notes, goals, services)",
641
+ "case_needs_action_flag_manage": "Manage case escalation / needs-action flags",
642
+ "case_reopen": "Case Re-open",
643
+ "case_side_panel_use": "Utilize side panel for comments/notes and uploads",
644
+ "case_status_manage": "Change case status",
645
+ "case_transfer_bulk": "Bulk transfer cases (turnover)",
646
+ "case_view": "View (agency) Cases",
647
+ "case_visibility_manage": "Go dark / restore case visibility",
648
+ "ci_periodic_review": "Review criminal intelligence record (periodic)",
649
+ "ci_record_purge_or_retire": "Retire or purge criminal intelligence record",
650
+ "ci_record_validate": "Validate criminal intelligence record",
651
+ "ci_to_evidence_export_authorize": "Authorize criminal intelligence \u2192 evidence export",
652
+ "deconfliction_alert_acknowledge": "Accept a deconfliction alert",
653
+ "deconfliction_unmask": "Unmask a deconfliction",
654
+ "determination_perform": "Perform Determinations",
655
+ "disclose_external_request": "Request External Disclosure",
656
+ "enrollment_manage": "Manage program enrollments",
657
+ "exit_discharge_conduct": "Conduct program exit / discharge",
658
+ "export_deidentified": "Export de-identified reports/datasets",
659
+ "goals_plan_manage": "Create and manage plans, goals, action steps",
660
+ "idb_record_create": "Create IDB record",
661
+ "indicator_manual_add": "Add a manual indicator",
662
+ "investigation_create_claim": "Create Investigation + Claim a Tip / Lead",
663
+ "investigation_session_run": "Run an investigation session",
664
+ "investigative_database_search": "Search account IDB",
665
+ "investigative_request_send": "Submit an investigative request (Ask HTI)",
666
+ "lead_create": "Create a Tip / Lead",
667
+ "lead_publish": "Publish a Tip / Lead",
668
+ "lead_route_assign": "Route / assign a lead to an agency",
669
+ "lead_triage_manage": "Triage leads",
670
+ "magic_link_share_send": "Send Magic Link Shares",
671
+ "mandatory_report_send": "Send mandatory report",
672
+ "member_account_report_generate": "Member Account Report generation",
673
+ "member_onboarding_support": "Assist member onboarding (support)",
674
+ "message_moderate": "Moderate messages",
675
+ "message_send": "Send platform messages",
676
+ "milestone_log": "Log investigative milestones",
677
+ "needs_priorities_conduct": "Conduct needs assessment and immediate priorities",
678
+ "network_corpus_access": "Access raw/worked machine-network corpus",
679
+ "note_open_departed_author": "Open a deactivated author's private notes",
680
+ "onboarding_config_sign_off": "Approve the configuration summary (Phase III sign-off)",
681
+ "open_source_search": "Search across all open source information",
682
+ "person_association_update": "Assign or update person\u2019s role, relationships, phone numbers or social media associations",
683
+ "person_merge_manage": "Manage person identity merges",
684
+ "platform_perm_modify": "Modify Platform Permissions",
685
+ "profile_domain_edit": "Edit subject profile domains",
686
+ "record_activity_view": "View a record's activity log",
687
+ "record_print": "Export/Print",
688
+ "referral_receive_external": "Receive External Referrals",
689
+ "referral_receive_internal": "Receive Internal Referrals",
690
+ "referral_send_external": "Refer External (Excluding VSP to LE)",
691
+ "referral_send_internal": "Refer Internal",
692
+ "roi_submit_manage": "Upload/Edit/Submit ROI",
693
+ "role_assign": "Role Assignment",
694
+ "roles_accounts_toggle": "Toggle Roles / Accounts",
695
+ "sandbox_environment_manage": "Manage sandbox and testing environments",
696
+ "screening_conduct": "Conduct Screenings",
697
+ "screening_view": "View Victim/Abuse Screening Responses",
698
+ "service_log_manage": "Log and manage service instances",
699
+ "session_create": "Record creation (sessions, cases, etc.)",
700
+ "share_config": "Sharing Configuration",
701
+ "share_revoke": "Revoke an active share / ROI",
702
+ "share_rule_approve_cross_agency": "Approve cross-agency sharing rules",
703
+ "share_vsp_to_le": "VSP to LE Share",
704
+ "srl_manage": "Manage the agency's Service Registry (SRL)",
705
+ "supervisee_thread_view": "View supervisee threads",
706
+ "support_ticket_triage": "Triage support tickets / bug reports",
707
+ "system_diagnostics_view": "View system diagnostics and logs (support)",
708
+ "team_config_manage": "Team structure & admin scoping (account-level)",
709
+ "team_membership_manage": "Manage team membership",
710
+ "team_share_narrowing": "Narrow a team's sharing",
711
+ "team_workflow_config_manage": "Manage team workflow configuration",
712
+ "training_gate_manage": "Manage training/certification gates (i.e. required modules for roles + teams)",
713
+ "usr_manage": "User Management",
714
+ "viewing_config_manage": "Configure internal viewing (Type A)",
715
+ "viewing_level_1_search": "Non-owned case identity on search",
716
+ "viewing_level_2_autocomplete": "Non-owned case identity in autocomplete",
717
+ "viewing_level_3_components": "Non-owned case component access"
718
+ };
719
+ var CANON_ROLE_CODE_LIST = [
720
+ "case_nav",
721
+ "healthcare_provider_medical",
722
+ "behavioral_health_provider",
723
+ "crisis_response",
724
+ "intel_analyst",
725
+ "investigator",
726
+ "le_liaison_vsp",
727
+ "legal_advocate",
728
+ "mandatory_reporter",
729
+ "mdt_participant",
730
+ "prosecutor_review",
731
+ "public_reporter",
732
+ "research_analytics",
733
+ "screener",
734
+ "volunteer",
735
+ "PLT-ADM",
736
+ "PLT-SUP",
737
+ "MEM-ADM",
738
+ "TEAM-ADM",
739
+ "AUD",
740
+ "DATA-ADM",
741
+ "GOV-AUD",
742
+ "CIRO",
743
+ "SUP",
744
+ "TRAIN-ADM"
745
+ ];
746
+ var ROLE_CODE_RE_KEYS = {
747
+ "missingness_root": null,
748
+ "unknown": null,
749
+ "anonymous": null,
750
+ "data_not_collected": null,
751
+ "hotline_op": "crisis_response",
752
+ "case_advocate": "case_nav",
753
+ "leads_investigator": "investigator",
754
+ "MISSINGNESS-ROOT": null,
755
+ "UNKNOWN": null,
756
+ "ANONYMOUS": null,
757
+ "DATA-NOT-COLLECTED": null,
758
+ "acct_adm": "MEM-ADM",
759
+ "ACCT-ADM": "MEM-ADM"
760
+ };
761
+
762
+ // src/authz/roleCodes.ts
763
+ var CANON_ROLE_CODES = new Set(CANON_ROLE_CODE_LIST);
764
+ var SOURCES = new Map(Object.entries(ROLE_CODE_RE_KEYS));
765
+ function canonicalRoleCode(code) {
766
+ if (typeof code !== "string") return null;
767
+ if (CANON_ROLE_CODES.has(code)) return code;
768
+ return SOURCES.has(code) ? SOURCES.get(code) ?? null : null;
769
+ }
770
+
771
+ // src/authz/functionDoor.ts
772
+ var NOT_OFFERED = Object.freeze({
773
+ offered: false,
774
+ allowed: false,
775
+ reason: null
776
+ });
777
+ function labelFor(functionKey, lookup) {
778
+ let label;
779
+ if (typeof lookup === "function") label = lookup(functionKey);
780
+ else if (lookup && Object.hasOwn(lookup, functionKey)) label = lookup[functionKey];
781
+ if (typeof label === "string" && label.trim()) return label;
782
+ return Object.hasOwn(CORE_FUNCTION_TITLES, functionKey) ? CORE_FUNCTION_TITLES[functionKey] : functionKey;
783
+ }
784
+ function drawsControl(state) {
785
+ return state === PERMISSION_STATE.ALWAYS || state === PERMISSION_STATE.PREF_YES || state === PERMISSION_STATE.PREF_NO;
786
+ }
787
+ function indexRoleRows(rows) {
788
+ const byCode = /* @__PURE__ */ new Map();
789
+ if (!Array.isArray(rows)) return byCode;
790
+ for (const r of rows) {
791
+ const code = isPlainObject(r) ? own(r, "code") : void 0;
792
+ if (isPlainObject(r) && typeof code === "string") byCode.set(code, r);
793
+ }
794
+ return byCode;
795
+ }
796
+ function liveRoleBound(rows, roleCode, functionKey) {
797
+ const row = rows.get(roleCode);
798
+ if (row === void 0) return false;
799
+ const container = readContainer(own(row, "functions"));
800
+ if (container.kind === "malformed") return false;
801
+ return drawsControl(tier1State(container, functionKey));
802
+ }
803
+ function codebookRoleBound(roleCode, functionKey) {
804
+ const bound = codebookDefaultBound(functionKey, roleCode);
805
+ return bound !== DEFAULT_BOUND_STATE.NA && drawsControl(bound);
806
+ }
807
+ function functionDoor(input) {
808
+ const { functionKey } = input;
809
+ if (typeof functionKey !== "string" || !isCanonEvaluableFunction(functionKey)) {
810
+ return { ...NOT_OFFERED };
811
+ }
812
+ let granted = false;
813
+ for (const fn of input.effectiveFunctions) {
814
+ if (fn === functionKey) {
815
+ granted = true;
816
+ break;
817
+ }
818
+ }
819
+ if (granted) return { offered: true, allowed: true, reason: null };
820
+ const functions = input.functions;
821
+ if (functions !== void 0 && functions !== null) {
822
+ const kept = Array.isArray(functions) && functions.some((row) => catalogRowCode(row) === functionKey);
823
+ if (!kept) return { ...NOT_OFFERED };
824
+ }
825
+ const liveRows = input.roles;
826
+ const live = liveRows !== void 0 && liveRows !== null ? indexRoleRows(liveRows) : null;
827
+ const roleCodes = input.roleCodes;
828
+ const bound = (Array.isArray(roleCodes) ? roleCodes : []).some((code) => {
829
+ const canon = canonicalRoleCode(code);
830
+ if (canon === null) return false;
831
+ if (live === null) return codebookRoleBound(canon, functionKey);
832
+ return liveRoleBound(live, canon, functionKey) || typeof code === "string" && code !== canon && liveRoleBound(live, code, functionKey);
833
+ });
834
+ if (!bound) return { ...NOT_OFFERED };
835
+ return {
836
+ offered: true,
837
+ allowed: false,
838
+ reason: `${labelFor(functionKey, input.label)} is not part of your roles`
839
+ };
840
+ }
618
841
  export {
619
842
  CORE_FUNCTION_DEFAULT_BOUNDS,
620
843
  CORE_FUNCTION_DEFAULT_BOUNDS_SOT_VERSION,
@@ -623,7 +846,9 @@ export {
623
846
  DEFAULT_BOUND_STATE_LABELS,
624
847
  DEFAULT_BOUND_STATE_VALUES,
625
848
  VIEWING_LEVEL_FUNCTIONS,
849
+ canonicalRoleCode,
626
850
  codebookDefaultBound,
851
+ functionDoor,
627
852
  isCanonEvaluableFunction,
628
853
  resolveEffectiveFunctions,
629
854
  resolveEffectiveViewingLevel,