@htilabs/platform-common-models 0.24.0 → 0.25.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.
Files changed (38) hide show
  1. package/README.md +65 -0
  2. package/dist/{index-Dr6GBCoY.d.ts → index-ClTjjJ_S.d.ts} +1 -1
  3. package/dist/{index-BTqHP4DM.d.cts → index-Pt82NxQg.d.cts} +1 -1
  4. package/dist/index.cjs +457 -2
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +5 -3
  7. package/dist/index.d.ts +5 -3
  8. package/dist/index.js +437 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/information-scope/index.d.cts +3 -350
  11. package/dist/information-scope/index.d.ts +3 -350
  12. package/dist/informationScopeResolver-BzYu97DE.d.cts +351 -0
  13. package/dist/informationScopeResolver-BzYu97DE.d.ts +351 -0
  14. package/dist/models/index.d.cts +2 -2
  15. package/dist/models/index.d.ts +2 -2
  16. package/dist/schemas/index.d.cts +25 -25
  17. package/dist/schemas/index.d.ts +25 -25
  18. package/dist/services/index.d.cts +2 -1
  19. package/dist/services/index.d.ts +2 -1
  20. package/dist/sharing-ceiling/index.cjs +497 -0
  21. package/dist/sharing-ceiling/index.cjs.map +1 -0
  22. package/dist/sharing-ceiling/index.d.cts +318 -0
  23. package/dist/sharing-ceiling/index.d.ts +318 -0
  24. package/dist/sharing-ceiling/index.js +451 -0
  25. package/dist/sharing-ceiling/index.js.map +1 -0
  26. package/package.json +7 -1
  27. package/src/__sot__/README.md +1 -0
  28. package/src/__sot__/sharingStarter.pin.json +229 -0
  29. package/src/__tests__/sharing-starter-canon.test.ts +178 -0
  30. package/src/generated/sharingPlatformStarter.ts +165 -0
  31. package/src/index.ts +5 -0
  32. package/src/sharingCeiling/__tests__/sharingCeiling.test.ts +678 -0
  33. package/src/sharingCeiling/chain.ts +269 -0
  34. package/src/sharingCeiling/coverage.ts +346 -0
  35. package/src/sharingCeiling/index.ts +14 -0
  36. package/src/sharingCeiling/starter.ts +89 -0
  37. package/dist/{cvcEntry-BqAGctqK.d.cts → cvcEntry-Asg7mxjB.d.cts} +8 -8
  38. package/dist/{cvcEntry-BqAGctqK.d.ts → cvcEntry-Asg7mxjB.d.ts} +8 -8
@@ -0,0 +1,178 @@
1
+ /**
2
+ * SHARING STARTER — GATE M: the platform sharing starter restates canon (co-2sx)
3
+ * =============================================================================
4
+ *
5
+ * `src/generated/sharingPlatformStarter.ts` is GENERATED from canon by
6
+ * `scripts/gen-sharing-starter.py` (monolith `HTI_SHARE_PLATFORM_STARTER` +
7
+ * platform-prototype `data.sharing.*`, refused unless the two copies agree).
8
+ * `src/__sot__/sharingStarter.pin.json` is derived INDEPENDENTLY from the same
9
+ * canon by `scripts/sot-pins.ts` (a separate TypeScript reader). This test is
10
+ * the hermetic enforcer: the shipped starter equals the pin, key order
11
+ * included, and every code it names is a live, non-floor CVC-236 v4 row; the
12
+ * field homes (`fieldHomeRows`) equal the pin and are live rows. Like
13
+ * `gen-sharing-starter.py --check`, it compares DATA only: a newer canon SHA
14
+ * with identical data passes, with the provenance printed as a note.
15
+ * `gen-sharing-starter.py --check` and `sot:pins:check` are the detectors for
16
+ * canon moving.
17
+ */
18
+ import { readFileSync } from "node:fs";
19
+ import path from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+ import { describe, expect, it } from "vitest";
22
+
23
+ import { coreInformationScopeSot, sharePurposeSot } from "../cvcs/index.js";
24
+ import {
25
+ createInformationScopeResolver,
26
+ scopeMigrationsFromSot,
27
+ scopeRowsFromSot,
28
+ type CoreInformationScopeSot,
29
+ } from "../services/informationScope.js";
30
+ import {
31
+ HTI_SHARE_PLATFORM_PURPOSE_ENABLED,
32
+ HTI_SHARE_PLATFORM_STARTER,
33
+ HTI_SHARE_PLATFORM_STARTER_SOURCE,
34
+ INFORMATION_SCOPE_FIELD_HOME_ROWS,
35
+ } from "../sharingCeiling/index.js";
36
+ import * as root from "../index.js";
37
+
38
+ const here = path.dirname(fileURLToPath(import.meta.url));
39
+ const pin = JSON.parse(
40
+ readFileSync(path.join(here, "..", "__sot__", "sharingStarter.pin.json"), "utf8"),
41
+ ) as {
42
+ sourceSha: string;
43
+ mirror: { sourceSha: string };
44
+ scopeVersion: number;
45
+ scopeByPurpose: Record<string, string[]>;
46
+ counterpartyOverrides: Record<string, Record<string, string[]>>;
47
+ purposeEnabled: Record<string, boolean>;
48
+ fieldHomeRows: string[];
49
+ };
50
+
51
+ const sot = coreInformationScopeSot as CoreInformationScopeSot;
52
+ const scope = createInformationScopeResolver({
53
+ rows: scopeRowsFromSot(sot),
54
+ migrations: scopeMigrationsFromSot(sot),
55
+ });
56
+
57
+ /** Every (where, code) the starter names. */
58
+ const namedCodes = (): [string, string][] => {
59
+ const out: [string, string][] = [];
60
+ for (const [p, codes] of Object.entries(HTI_SHARE_PLATFORM_STARTER.scopeByPurpose)) {
61
+ for (const c of codes) out.push([`scopeByPurpose.${p}`, c]);
62
+ }
63
+ for (const [cp, lists] of Object.entries(HTI_SHARE_PLATFORM_STARTER.counterpartyOverrides)) {
64
+ for (const [p, codes] of Object.entries(lists)) {
65
+ for (const c of codes) out.push([`counterpartyOverrides.${cp}.${p}`, c]);
66
+ }
67
+ }
68
+ return out;
69
+ };
70
+
71
+ type PurposeEntry = { key: string; wing?: string };
72
+ const purposes = (sharePurposeSot as unknown as { entries: PurposeEntry[] }).entries;
73
+ const corePurposes = purposes.filter((e) => e.wing === "core").map((e) => e.key);
74
+ const allPurposes = new Set(purposes.map((e) => e.key));
75
+
76
+ describe("sharing starter — GATE M: the shipped starter restates canon (@ the pin)", () => {
77
+ it("equals the independently derived pin, key order included", () => {
78
+ expect(pin.scopeVersion).toBe(4);
79
+ expect(HTI_SHARE_PLATFORM_STARTER.scopeVersion).toBe(4);
80
+ expect(JSON.stringify(HTI_SHARE_PLATFORM_STARTER.scopeByPurpose)).toBe(
81
+ JSON.stringify(pin.scopeByPurpose),
82
+ );
83
+ expect(JSON.stringify(HTI_SHARE_PLATFORM_STARTER.counterpartyOverrides)).toBe(
84
+ JSON.stringify(pin.counterpartyOverrides),
85
+ );
86
+ expect(JSON.stringify(HTI_SHARE_PLATFORM_PURPOSE_ENABLED)).toBe(
87
+ JSON.stringify(pin.purposeEnabled),
88
+ );
89
+ });
90
+
91
+ it("checks DATA only — a different canon SHA with identical data is a NOTE, not a failure", () => {
92
+ // Matches `gen-sharing-starter.py --check`: the monolith moves on nearly
93
+ // every canon commit, so provenance alone never fails the gate.
94
+ const src = HTI_SHARE_PLATFORM_STARTER_SOURCE;
95
+ const stale = [
96
+ src.monolith.sha.startsWith(pin.sourceSha) ? null : `prototype ${src.monolith.sha} vs pin ${pin.sourceSha}`,
97
+ src.mirror.sha.startsWith(pin.mirror.sourceSha)
98
+ ? null
99
+ : `platform-prototype ${src.mirror.sha} vs pin ${pin.mirror.sourceSha}`,
100
+ ].filter((n): n is string => n !== null);
101
+ if (stale.length > 0) {
102
+ console.info(`NOTE (GATE M): data in sync; provenance differs — ${stale.join("; ")}`);
103
+ }
104
+ expect(typeof src.monolith.sha).toBe("string");
105
+ });
106
+
107
+ it("ships canon's field homes (row_v4), each a live v4 row", () => {
108
+ expect([...INFORMATION_SCOPE_FIELD_HOME_ROWS]).toEqual(pin.fieldHomeRows);
109
+ const notLive = pin.fieldHomeRows.filter((c) => {
110
+ const row = scope.row(c);
111
+ return row === undefined || row.status === "retired";
112
+ });
113
+ expect(notLive).toEqual([]);
114
+ expect(pin.fieldHomeRows).toContain("instruments");
115
+ expect(pin.fieldHomeRows).toContain("commercial_activity");
116
+ });
117
+
118
+ it("names only live, non-floor CVC-236 v4 rows, each once per list", () => {
119
+ const bad: string[] = [];
120
+ for (const [where, code] of namedCodes()) {
121
+ const row = scope.row(code);
122
+ if (row === undefined || row.status === "retired") bad.push(`${where}: ${code} is not a live v4 row`);
123
+ else if (scope.ancestorsOf(code).some((a) => scope.row(a)?.platformFloor === true)) {
124
+ bad.push(`${where}: ${code} is (under) the platform safety floor`);
125
+ }
126
+ }
127
+ expect(bad).toEqual([]);
128
+ for (const lists of [
129
+ HTI_SHARE_PLATFORM_STARTER.scopeByPurpose,
130
+ ...Object.values(HTI_SHARE_PLATFORM_STARTER.counterpartyOverrides),
131
+ ]) {
132
+ for (const codes of Object.values(lists)) expect(new Set(codes).size).toBe(codes.length);
133
+ }
134
+ });
135
+
136
+ it("covers exactly the eight core-wing CVC-84 purposes; LEADS-wing purposes have no platform ceiling", () => {
137
+ const core = [...corePurposes].sort();
138
+ expect(core).toHaveLength(8);
139
+ expect(Object.keys(HTI_SHARE_PLATFORM_STARTER.scopeByPurpose).sort()).toEqual(core);
140
+ expect(Object.keys(HTI_SHARE_PLATFORM_PURPOSE_ENABLED).sort()).toEqual(core);
141
+ for (const lists of Object.values(HTI_SHARE_PLATFORM_STARTER.counterpartyOverrides)) {
142
+ for (const p of Object.keys(lists)) expect(allPurposes.has(p), p).toBe(true);
143
+ }
144
+ });
145
+
146
+ it("ships records_request disabled and every other core purpose enabled (data.js L32527)", () => {
147
+ expect(
148
+ Object.entries(HTI_SHARE_PLATFORM_PURPOSE_ENABLED)
149
+ .filter(([, e]) => !e)
150
+ .map(([p]) => p),
151
+ ).toEqual(["records_request"]);
152
+ });
153
+
154
+ it("CANON GAP — the seeded partner rules are keyed by canon's demonstration ids, shipped as canon has them", () => {
155
+ // No registry agency carries these ids, so the seeded-partner rung binds on
156
+ // no real data until the platform maps them. A change here is a canon change.
157
+ expect(Object.keys(HTI_SHARE_PLATFORM_STARTER.counterpartyOverrides)).toEqual([
158
+ "palomar",
159
+ "okcpd",
160
+ "legal_aid_ok",
161
+ ]);
162
+ });
163
+
164
+ it("is deep-frozen", () => {
165
+ expect(Object.isFrozen(HTI_SHARE_PLATFORM_STARTER)).toBe(true);
166
+ expect(Object.isFrozen(HTI_SHARE_PLATFORM_STARTER.scopeByPurpose)).toBe(true);
167
+ expect(Object.isFrozen(HTI_SHARE_PLATFORM_STARTER.scopeByPurpose["referral"])).toBe(true);
168
+ expect(Object.isFrozen(HTI_SHARE_PLATFORM_STARTER.counterpartyOverrides["okcpd"])).toBe(true);
169
+ expect(Object.isFrozen(HTI_SHARE_PLATFORM_PURPOSE_ENABLED)).toBe(true);
170
+ });
171
+
172
+ it("is re-exported from the package root", () => {
173
+ expect(root.HTI_SHARE_PLATFORM_STARTER).toBe(HTI_SHARE_PLATFORM_STARTER);
174
+ expect(root.HTI_SHARE_PLATFORM_PURPOSE_ENABLED).toBe(HTI_SHARE_PLATFORM_PURPOSE_ENABLED);
175
+ expect(typeof root.effectiveCeiling).toBe("function");
176
+ expect(typeof root.scopeRowWithinCeiling).toBe("function");
177
+ });
178
+ });
@@ -0,0 +1,165 @@
1
+ /**
2
+ * @htilabs/platform-common-models — the platform sharing starter (co-2sx)
3
+ *
4
+ * AUTO-GENERATED FILE — DO NOT EDIT BY HAND.
5
+ * Regenerate with:
6
+ * `python3 scripts/gen-sharing-starter.py <prototype root> <platform-prototype root>`.
7
+ *
8
+ * Canon (read from git objects at origin/main):
9
+ * - htilabstech/prototype HTI-LEADS-PAVE-Thread-prototype.html @ d85f05b7
10
+ * `HTI_SHARE_PLATFORM_STARTER` L326475-L326543
11
+ * (scopeVersion · scopeByPurpose · counterpartyOverrides);
12
+ * - htilabstech/platform-prototype src/data.js @ a6f1f3a5 (the contract of
13
+ * record, GDR § 5.79): `data.sharing.scopeByPurpose` /
14
+ * `counterpartyOverrides` L38170-L38190, and the
15
+ * platform purpose rows `sharing.purposes[].enabled`
16
+ * L32450-L32531;
17
+ * - htilabstech/prototype docs/share-roi/information_scope_v4.fields.csv @ d85f05b7: the distinct
18
+ * `row_v4` homes of its 517 fields (`fieldHomeRows`; the sentinel
19
+ * "rides with its record" is not a row and is left out).
20
+ * The two starter copies are equal (the generator refuses otherwise). GATE M
21
+ * (`src/__tests__/sharing-starter-canon.test.ts`) holds this module equal to
22
+ * `src/__sot__/sharingStarter.pin.json` and every code to a live, non-floor
23
+ * CVC-236 v4 row.
24
+ *
25
+ * CANON GAP: `counterpartyOverrides` is keyed by canon's DEMONSTRATION partner
26
+ * ids (palomar, okcpd, legal_aid_ok). No registry agency carries them, so the
27
+ * seeded-partner rung binds on no real data until the platform maps them.
28
+ */
29
+
30
+ /** Where this data was taken from (provenance, not compared by `--check`). */
31
+ export const SHARING_PLATFORM_STARTER_SOURCE = {
32
+ "monolith": {
33
+ "repo": "htilabstech/prototype",
34
+ "file": "HTI-LEADS-PAVE-Thread-prototype.html",
35
+ "sha": "d85f05b7",
36
+ "lines": [
37
+ 326475,
38
+ 326543
39
+ ]
40
+ },
41
+ "mirror": {
42
+ "repo": "htilabstech/platform-prototype",
43
+ "file": "src/data.js",
44
+ "sha": "a6f1f3a5",
45
+ "starterLines": [
46
+ 38170,
47
+ 38190
48
+ ],
49
+ "purposeLines": [
50
+ 32450,
51
+ 32531
52
+ ]
53
+ },
54
+ "fieldPlacements": {
55
+ "repo": "htilabstech/prototype",
56
+ "file": "docs/share-roi/information_scope_v4.fields.csv",
57
+ "sha": "d85f05b7"
58
+ }
59
+ } as const;
60
+
61
+ // <generated-data>
62
+ export const SHARING_PLATFORM_STARTER_DATA = {
63
+ scopeVersion: 4,
64
+ scopeByPurpose: {
65
+ "referral": ["identifying", "contact", "services", "system", "summary_needs_assessment"],
66
+ "case_collaboration": ["identifying", "risk", "contact", "services", "notes", "system", "summary_initial_screen", "summary_lap", "summary_danger_assessment", "summary_stalking_assessment", "summary_injury_and_strangulation", "summary_ae_intake", "summary_tra", "summary_needs_assessment"],
67
+ "deconfliction": ["identifying", "system"],
68
+ "mandatory_reporting": ["identifying", "risk", "contact", "services", "notes", "system", "summary_initial_screen", "summary_lap", "summary_danger_assessment", "summary_stalking_assessment", "summary_injury_and_strangulation", "summary_ae_intake", "summary_tra", "summary_needs_assessment", "offenders.identifying", "offenders.risk", "relationships_household", "family"],
69
+ "discretionary_share": ["identifying", "system"],
70
+ "authority_reporting": ["identifying", "risk", "system", "summary_initial_screen", "summary_lap", "summary_danger_assessment", "summary_stalking_assessment", "summary_injury_and_strangulation", "summary_ae_intake", "summary_tra", "offenders.identifying", "offenders.risk", "relationships_household", "family"],
71
+ "automatic_account_share": ["identifying", "system"],
72
+ "records_request": ["identifying", "system"],
73
+ },
74
+ counterpartyOverrides: {
75
+ "palomar": {
76
+ "case_collaboration": ["identifying", "risk", "contact", "services", "notes", "health_accommodation", "system", "summary_initial_screen", "summary_lap", "summary_danger_assessment", "summary_stalking_assessment", "summary_injury_and_strangulation", "summary_ae_intake", "summary_tra", "summary_mental_health_screen", "summary_behavioral_health_intake", "summary_trauma_and_coping_screen", "summary_needs_assessment"],
77
+ },
78
+ "okcpd": {
79
+ "mandatory_reporting": ["identifying", "risk", "contact", "services", "notes", "system", "summary_initial_screen", "summary_lap", "summary_danger_assessment", "summary_stalking_assessment", "summary_injury_and_strangulation", "summary_ae_intake", "summary_tra", "summary_needs_assessment", "offenders.identifying", "offenders.risk", "relationships_household", "family"],
80
+ "referral": ["identifying", "contact", "services", "system", "summary_needs_assessment"],
81
+ },
82
+ "legal_aid_ok": {
83
+ "referral": ["identifying", "contact", "services", "notes", "system", "summary_needs_assessment"],
84
+ },
85
+ },
86
+ purposeEnabled: {
87
+ "referral": true,
88
+ "case_collaboration": true,
89
+ "deconfliction": true,
90
+ "mandatory_reporting": true,
91
+ "discretionary_share": true,
92
+ "authority_reporting": true,
93
+ "automatic_account_share": true,
94
+ "records_request": false,
95
+ },
96
+ fieldHomeRows: [
97
+ "accommodation_needs",
98
+ "ad_content",
99
+ "additional_ids",
100
+ "addresses",
101
+ "case_attachments",
102
+ "case_determinations",
103
+ "case_lifecycle",
104
+ "case_notes",
105
+ "commercial_activity",
106
+ "contact_info",
107
+ "demographics",
108
+ "derived_risk_signals",
109
+ "dob",
110
+ "encounter_location",
111
+ "family.health_accommodation",
112
+ "family.identifying",
113
+ "family.risk",
114
+ "full_ae_intake",
115
+ "full_behavioral_health_intake",
116
+ "full_danger_assessment",
117
+ "full_findings",
118
+ "full_hope_scale",
119
+ "full_ida",
120
+ "full_initial_screen",
121
+ "full_injury_and_strangulation",
122
+ "full_lap",
123
+ "full_mental_health_screen",
124
+ "full_needs_assessment",
125
+ "full_stalking_assessment",
126
+ "full_tra",
127
+ "full_trauma_and_coping_screen",
128
+ "health_status",
129
+ "identifying",
130
+ "immigration_applications",
131
+ "immigration_status",
132
+ "instruments",
133
+ "names",
134
+ "network_membership",
135
+ "object_identity_attributes",
136
+ "offenders.risk",
137
+ "others.risk",
138
+ "persona_links",
139
+ "phone_identifiers",
140
+ "plans_goals",
141
+ "priorities_safety",
142
+ "relationships_household",
143
+ "screen_indicators",
144
+ "service_history",
145
+ "session_summary",
146
+ "summary_ae_intake",
147
+ "summary_behavioral_health_intake",
148
+ "summary_danger_assessment",
149
+ "summary_findings",
150
+ "summary_hope_scale",
151
+ "summary_ida",
152
+ "summary_initial_screen",
153
+ "summary_injury_and_strangulation",
154
+ "summary_lap",
155
+ "summary_mental_health_screen",
156
+ "summary_needs_assessment",
157
+ "summary_stalking_assessment",
158
+ "summary_tra",
159
+ "summary_trauma_and_coping_screen",
160
+ "system",
161
+ "system_involvement",
162
+ "victimization",
163
+ ],
164
+ } as const;
165
+ // </generated-data>
package/src/index.ts CHANGED
@@ -56,6 +56,11 @@ export * from "./services/index.js";
56
56
  // consumers import it from the `@htilabs/platform-common-models/authz` subpath.
57
57
  export * from "./authz/index.js";
58
58
 
59
+ // Inter-Agency Sharing ceiling on the CVC-236 v4 tree (pure; no mongoose, no
60
+ // I/O). Browser consumers import it from the
61
+ // `@htilabs/platform-common-models/sharing-ceiling` subpath.
62
+ export * from "./sharingCeiling/index.js";
63
+
59
64
  // ─── CVC validation surface (Zod schemas + inferred types) ──────────────────
60
65
  // Per co-am3.7 (Phase 1.7) bead: re-export the Zod schemas, plus the inferred
61
66
  // scalar types and `CvcDomain`. The Zod-inferred entry shape is exposed via