@htilabs/platform-common-models 0.79.0 → 0.80.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 CHANGED
@@ -16,6 +16,29 @@ Package exports are organized into a public root API and a small number of
16
16
  dedicated subpaths (`/validation`, `/cvcs`) — consult `package.json` for the
17
17
  authoritative `exports` map.
18
18
 
19
+ ## 0.80.0 — seatAppAccess: a seat's app access from its teams, inside the account's grant (additive, `./authz` and the root)
20
+
21
+ **What changed.** One shared answer to "may this person open this app?" for Thread's and PAVE's sign-in doors and the platform's app tiles (Kickoff 08c), so the three stop deciding from the Auth0 role alone.
22
+
23
+ ```ts
24
+ import { seatAppAccess, seatTeamApps, accountAppGrant } from "@htilabs/platform-common-models/authz";
25
+
26
+ const r = seatAppAccess({
27
+ app: "THREAD", // any case
28
+ auth0Allows, // the app's own Auth0 decision for this tier
29
+ teams: seat.teams.map((t) => ({ apps: t.apps, active: t.status !== RETIRED })),
30
+ accountGrant: accountAppGrant(account), // the account's apps_subscribed; null = not known
31
+ accountPreLaunch, // member_status prospective / onboarding
32
+ });
33
+ // r.allowed, r.via ("auth0" | "teams" | "both" | "none"), r.teamApps, r.teamUnion, r.accountGrant, r.unrecognized
34
+ ```
35
+
36
+ **The rule.** Platform side: Echo and Trail for every seat (Crysta 2026-08-20 Ruling 2, "everyone with an account"); Thread, PAVE and LEADS when an active team of the seat carries the app and the account's grant includes it (grant unknown: no ceiling); Trail only while the account is not launched (2026-08-31). `allowed` = the app's Auth0 decision OR the platform side: the transition, so nobody loses access on day one; `via` lets the apps report where the two disagree. Canon: 2026-10-02 ("Contract grants apps to the Account, users gain access via teams"), 2026-08-20 Rulings 1 and 2, 2026-10-18, 2026-11-12; prototype `HTI_appsForUser`. Differences from the prototype's user grain, declared in the module comment: the Auth0 OR, inactive teams never grant (2026-11-12; the prototype is being updated), and the account ceiling (2026-11-12).
37
+
38
+ **The grant** is the account's `apps_subscribed`, "Apps the contract grants" (UDD Account Data Object; hti-features Account.v1; records `HTI_ACCOUNT_DIRECTORY.csv`), the list HTI sets; `accountAppGrant` reads it and nothing else. Never `apps_declared` (a retired 2026-10-18 generator artifact) and never the legacy PAVE-synced `accounts.apps`.
39
+
40
+ **Mechanics.** `src/authz/seatAppAccess.ts`, pure (imports only `constants/platform-apps.ts` and a type); tests `src/__tests__/authz-seat-app-access.test.ts`; the `./authz` import allowlist in `authz-resolve.test.ts` gains it and `../constants/platform-apps.js`.
41
+
19
42
  ## 0.79.0 — the Grant, the Award and the Award–Program link, shared: `@htilabs/platform-common-models/grant-registry` (additive; a new subpath, nothing existing changes)
20
43
 
21
44
  The shape Crysta confirmed on 2026-11-10 (hti-features
@@ -2764,6 +2787,21 @@ The connection URI comes from `MONGO_URI` (or `--mongo-uri`); the target databas
2764
2787
  is whatever the URI's path says. Pass `--dry-run` to validate and report counts
2765
2788
  without writing anything.
2766
2789
 
2790
+ `seed:cvc:all` checks every `DOMAINS` entry in `scripts/lib/seedAllCvcs.ts` before
2791
+ it writes anything (before the guard prompt and the connection): the SOT file
2792
+ `resolveSotPath(domain, version)` must exist, declare that domain and a version,
2793
+ carry entries, and pass the same envelope and structural checks `seed:cvc` runs.
2794
+ If any entry fails, it lists every failure and exits 1 with nothing written.
2795
+ `npm run test:seed-all` (a CI step) runs the same check over the table, so a SOT
2796
+ version bump that misses `DOMAINS` fails in CI rather than on a real seed.
2797
+
2798
+ The default registry's pins are **merged**, not replaced: `DOMAINS` sets the pins
2799
+ for the domains it lists, and every other pin already in the registry (a domain
2800
+ seeded with `seed:cvc`, say) is kept. The preview, in a dry run and a real run
2801
+ alike, prints each changed pin as `<domain>: <from> → <to>` and each kept one as
2802
+ `<domain>: <version> (kept, not in DOMAINS)`. The seeder never unpins a domain;
2803
+ removing one from the default registry is a deliberate edit of its `cvcVersions`.
2804
+
2767
2805
  ### service_categories 2.1.0 — LAP · INS · TRA as their own rows (0.43.0)
2768
2806
 
2769
2807
  Additive minor over 2.0.0 (Kickoff 04c; Crysta ruling 11 of 2026-10-18 — every
@@ -31,6 +31,7 @@ __export(authz_exports, {
31
31
  VIEWING_LEVEL_FUNCTIONS: () => VIEWING_LEVEL_FUNCTIONS,
32
32
  VIEWING_POLICY_SPECIES: () => VIEWING_POLICY_SPECIES,
33
33
  VIEWING_POLICY_VOCABULARIES: () => VIEWING_POLICY_VOCABULARIES,
34
+ accountAppGrant: () => accountAppGrant,
34
35
  canonicalRoleCode: () => canonicalRoleCode,
35
36
  caseSurfacesAsStub: () => caseSurfacesAsStub,
36
37
  caseSurfacesOn: () => caseSurfacesOn,
@@ -44,6 +45,8 @@ __export(authz_exports, {
44
45
  resolveEffectiveFunctions: () => resolveEffectiveFunctions,
45
46
  resolveEffectiveViewingLevel: () => resolveEffectiveViewingLevel,
46
47
  resolveViewingPolicy: () => resolveViewingPolicy,
48
+ seatAppAccess: () => seatAppAccess,
49
+ seatTeamApps: () => seatTeamApps,
47
50
  selectActingTeamId: () => selectActingTeamId,
48
51
  teamViewingLevelFromPolicy: () => teamViewingLevelFromPolicy,
49
52
  unavailableViewingPolicy: () => unavailableViewingPolicy,
@@ -1203,8 +1206,8 @@ function governingRowOf(rows) {
1203
1206
  if (rows.length === 1 && only !== void 0) return { row: only };
1204
1207
  const family = idText(rows[0]?.familyId);
1205
1208
  const versions = rows.map((r) => positiveIntOrNull(r.version));
1206
- const ordered = family !== null && rows.every((r) => idText(r.familyId) === family) && versions.every((v) => typeof v === "number") && new Set(versions).size === versions.length;
1207
- if (!ordered) {
1209
+ const ordered2 = family !== null && rows.every((r) => idText(r.familyId) === family) && versions.every((v) => typeof v === "number") && new Set(versions).size === versions.length;
1210
+ if (!ordered2) {
1208
1211
  return unavailableViewingPolicy("ambiguous_rows", policyIdOf(rows[0] ?? {}));
1209
1212
  }
1210
1213
  let best = rows[0];
@@ -1461,6 +1464,152 @@ function viewingComponentOpen(access, homeRow, scope) {
1461
1464
  if (row.status === "retired") return false;
1462
1465
  return scope.isCovered(access.visibleScope, homeRow);
1463
1466
  }
1467
+
1468
+ // src/generated/platformApps.ts
1469
+ var PLATFORM_APP_CATALOG = [
1470
+ {
1471
+ "id": "trail",
1472
+ "name": "Trail",
1473
+ "tag": "Certified Access & Training",
1474
+ "universal": true
1475
+ },
1476
+ {
1477
+ "id": "thread",
1478
+ "name": "Thread",
1479
+ "tag": "First Contact Routing",
1480
+ "universal": false
1481
+ },
1482
+ {
1483
+ "id": "pave",
1484
+ "name": "PAVE",
1485
+ "tag": "Survivor-Centered Navigation",
1486
+ "universal": false
1487
+ },
1488
+ {
1489
+ "id": "leads",
1490
+ "name": "LEADS",
1491
+ "tag": "Intelligence-Driven Investigation",
1492
+ "universal": false
1493
+ },
1494
+ {
1495
+ "id": "echo",
1496
+ "name": "Echo",
1497
+ "tag": "Outcomes, Learning, & Impact",
1498
+ "universal": true
1499
+ }
1500
+ ];
1501
+
1502
+ // src/constants/platform-apps.ts
1503
+ var PLATFORM_APP_IDS = ["trail", "thread", "pave", "leads", "echo"];
1504
+ if (PLATFORM_APP_CATALOG.length !== PLATFORM_APP_IDS.length || PLATFORM_APP_CATALOG.some((a, i) => a.id !== PLATFORM_APP_IDS[i])) {
1505
+ throw new Error(
1506
+ `platformApps.ts: canon lists [${PLATFORM_APP_CATALOG.map((a) => a.id).join(", ")}], PLATFORM_APP_IDS [${PLATFORM_APP_IDS.join(", ")}]`
1507
+ );
1508
+ }
1509
+ var PLATFORM_APPS = PLATFORM_APP_CATALOG.map((a) => ({
1510
+ id: a.id,
1511
+ name: a.name,
1512
+ tagline: a.tag,
1513
+ universal: a.universal
1514
+ }));
1515
+ var PLATFORM_APP_NAMES = Object.fromEntries(
1516
+ PLATFORM_APPS.map((a) => [a.id, a.name])
1517
+ );
1518
+ var CASEWORK_APP_IDS = PLATFORM_APPS.filter(
1519
+ (a) => !a.universal
1520
+ ).map((a) => a.id);
1521
+ var UNIVERSAL_APP_IDS = PLATFORM_APPS.filter(
1522
+ (a) => a.universal
1523
+ ).map((a) => a.id);
1524
+ var BY_ID = new Map(PLATFORM_APPS.map((a) => [a.id, a]));
1525
+ function platformAppById(id) {
1526
+ return typeof id === "string" ? BY_ID.get(id.trim().toLowerCase()) ?? null : null;
1527
+ }
1528
+
1529
+ // src/authz/seatAppAccess.ts
1530
+ var UNIVERSAL = new Set(UNIVERSAL_APP_IDS);
1531
+ var TRAIL = "trail";
1532
+ function toolCode(id) {
1533
+ return id.toUpperCase();
1534
+ }
1535
+ function asWritten(v) {
1536
+ if (typeof v === "string") return v;
1537
+ try {
1538
+ const json = JSON.stringify(v);
1539
+ return json === void 0 ? String(v) : json;
1540
+ } catch {
1541
+ return String(v);
1542
+ }
1543
+ }
1544
+ function listOf(value, unrecognized) {
1545
+ if (value === null || value === void 0) return [];
1546
+ if (typeof value === "string") return [value];
1547
+ if (Array.isArray(value)) return value;
1548
+ unrecognized.push(asWritten(value));
1549
+ return [];
1550
+ }
1551
+ function readApps(value, unrecognized) {
1552
+ const out = /* @__PURE__ */ new Set();
1553
+ for (const v of listOf(value, unrecognized)) {
1554
+ const app = platformAppById(v);
1555
+ if (app) out.add(app.id);
1556
+ else unrecognized.push(asWritten(v));
1557
+ }
1558
+ return out;
1559
+ }
1560
+ function ordered(ids) {
1561
+ return PLATFORM_APP_IDS.filter((id) => ids.has(id)).map(toolCode);
1562
+ }
1563
+ function readGrant(value, unrecognized) {
1564
+ if (value === null || value === void 0) return null;
1565
+ return readApps(value, unrecognized);
1566
+ }
1567
+ function accountAppGrant(account) {
1568
+ if (!account || typeof account !== "object") return null;
1569
+ const grant = account.apps_subscribed;
1570
+ return grant === null || grant === void 0 ? null : grant;
1571
+ }
1572
+ function teamSide(teams, accountGrant, accountPreLaunch) {
1573
+ const unrecognized = [];
1574
+ const grant = readGrant(accountGrant, unrecognized);
1575
+ const union = /* @__PURE__ */ new Set();
1576
+ for (const team of Array.isArray(teams) ? teams : []) {
1577
+ if (!team || typeof team !== "object") continue;
1578
+ const t = team;
1579
+ if (t.active === false) continue;
1580
+ for (const id of readApps(t.apps, unrecognized)) union.add(id);
1581
+ }
1582
+ const granted = /* @__PURE__ */ new Set();
1583
+ if (accountPreLaunch === true) {
1584
+ granted.add(TRAIL);
1585
+ return { granted, union, grant, unrecognized };
1586
+ }
1587
+ for (const id of UNIVERSAL) granted.add(id);
1588
+ for (const id of CASEWORK_APP_IDS) {
1589
+ if (union.has(id) && (grant === null || grant.has(id))) granted.add(id);
1590
+ }
1591
+ return { granted, union, grant, unrecognized };
1592
+ }
1593
+ function seatTeamApps(input) {
1594
+ return ordered(teamSide(input.teams, input.accountGrant, input.accountPreLaunch).granted);
1595
+ }
1596
+ function seatAppAccess(input) {
1597
+ const side = teamSide(input.teams, input.accountGrant, input.accountPreLaunch);
1598
+ const app = platformAppById(input.app);
1599
+ const teamAllows = app !== null && side.granted.has(app.id);
1600
+ const auth0Allows = input.auth0Allows === true;
1601
+ const via = auth0Allows && teamAllows ? "both" : auth0Allows ? "auth0" : teamAllows ? "teams" : "none";
1602
+ return {
1603
+ allowed: auth0Allows || teamAllows,
1604
+ via,
1605
+ app: app ? toolCode(app.id) : null,
1606
+ teamAllows,
1607
+ teamApps: ordered(side.granted),
1608
+ teamUnion: ordered(side.union),
1609
+ accountGrant: side.grant ? ordered(side.grant) : null,
1610
+ unrecognized: side.unrecognized
1611
+ };
1612
+ }
1464
1613
  // Annotate the CommonJS export names for ESM import in node:
1465
1614
  0 && (module.exports = {
1466
1615
  CORE_FUNCTION_DEFAULT_BOUNDS,
@@ -1474,6 +1623,7 @@ function viewingComponentOpen(access, homeRow, scope) {
1474
1623
  VIEWING_LEVEL_FUNCTIONS,
1475
1624
  VIEWING_POLICY_SPECIES,
1476
1625
  VIEWING_POLICY_VOCABULARIES,
1626
+ accountAppGrant,
1477
1627
  canonicalRoleCode,
1478
1628
  caseSurfacesAsStub,
1479
1629
  caseSurfacesOn,
@@ -1487,6 +1637,8 @@ function viewingComponentOpen(access, homeRow, scope) {
1487
1637
  resolveEffectiveFunctions,
1488
1638
  resolveEffectiveViewingLevel,
1489
1639
  resolveViewingPolicy,
1640
+ seatAppAccess,
1641
+ seatTeamApps,
1490
1642
  selectActingTeamId,
1491
1643
  teamViewingLevelFromPolicy,
1492
1644
  unavailableViewingPolicy,