@htilabs/platform-common-models 0.12.2 → 0.12.4

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 (54) hide show
  1. package/dist/cvcs/index.cjs +170 -21
  2. package/dist/cvcs/index.cjs.map +1 -1
  3. package/dist/cvcs/index.d.cts +182 -27
  4. package/dist/cvcs/index.d.ts +182 -27
  5. package/dist/cvcs/index.js +170 -21
  6. package/dist/cvcs/index.js.map +1 -1
  7. package/dist/enums/index.cjs +2 -0
  8. package/dist/enums/index.cjs.map +1 -1
  9. package/dist/enums/index.d.cts +5 -3
  10. package/dist/enums/index.d.ts +5 -3
  11. package/dist/enums/index.js +2 -0
  12. package/dist/enums/index.js.map +1 -1
  13. package/dist/{index-4DiJrn7y.d.ts → index-C0J3f169.d.ts} +1 -1
  14. package/dist/{index-qreOzXYS.d.cts → index-EPjPjR0z.d.cts} +1 -1
  15. package/dist/index.cjs +227 -28
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +4 -4
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.js +222 -28
  20. package/dist/index.js.map +1 -1
  21. package/dist/models/index.d.cts +2 -2
  22. package/dist/models/index.d.ts +2 -2
  23. package/dist/schemas/index.cjs +41 -7
  24. package/dist/schemas/index.cjs.map +1 -1
  25. package/dist/schemas/index.d.cts +130 -26
  26. package/dist/schemas/index.d.ts +130 -26
  27. package/dist/schemas/index.js +38 -7
  28. package/dist/schemas/index.js.map +1 -1
  29. package/dist/{cvc-Cp4uWnAa.d.cts → team-C4LJ5Tex.d.cts} +36 -1
  30. package/dist/{cvc-Cp4uWnAa.d.ts → team-C4LJ5Tex.d.ts} +36 -1
  31. package/dist/validation/index.cjs +155 -0
  32. package/dist/validation/index.cjs.map +1 -1
  33. package/dist/validation/index.d.cts +1 -1
  34. package/dist/validation/index.d.ts +1 -1
  35. package/dist/validation/index.js +153 -0
  36. package/dist/validation/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/__tests__/__snapshots__/cvc-sot.snap +5 -1
  39. package/src/__tests__/core-information-scope-invariant.test.ts +179 -2
  40. package/src/__tests__/cvc-sot-snapshot.test.ts +10 -0
  41. package/src/__tests__/cvc-structural.test.ts +3 -0
  42. package/src/__tests__/location-type-routing-invariant.test.ts +202 -0
  43. package/src/__tests__/team-directory-fields.test.ts +252 -0
  44. package/src/cvcs/coreInformationScope.v1.0.0.json +39 -5
  45. package/src/cvcs/index.ts +3 -0
  46. package/src/cvcs/locationType.v1.0.0.json +131 -16
  47. package/src/generated/cvc-enums.ts +5 -3
  48. package/src/index.ts +7 -0
  49. package/src/schemas/index.ts +8 -0
  50. package/src/schemas/team.ts +118 -0
  51. package/src/validation/index.ts +1 -0
  52. package/src/validation/team.ts +48 -0
  53. package/dist/{cvcEntry-ctHTp2df.d.cts → cvcEntry-DaDrEuTa.d.cts} +8 -8
  54. package/dist/{cvcEntry-ctHTp2df.d.ts → cvcEntry-DaDrEuTa.d.ts} +8 -8
@@ -0,0 +1,202 @@
1
+ /**
2
+ * LOCATION TYPE (CVC-191) — the location reason carries the share routing
3
+ * ======================================================================
4
+ *
5
+ * Canon amendment 2026-10-01 (LOCATION-TYPE-LOGIC, Crysta R1–R4; prototype
6
+ * `data/cvcs/core_location_type.yaml` + the `Final CVCs/Location (IC-4)`
7
+ * codebook extracts @ 55088d44). Every location reason declares five columns:
8
+ * tier · anchors · anchor default · the CVC-236 unit it rides on a share ·
9
+ * safety default. Share routing for the address family moved from the
10
+ * assertion-domain grain (every location under `addresses`) to the TYPE grain:
11
+ * a stored location is delivered under the unit its reason names, and a reason
12
+ * that names nothing is never delivered.
13
+ *
14
+ * That makes `shareUnit` a consent fact. A reason that silently starts riding a
15
+ * broader unit sends a location the survivor never authorized for that pick, so
16
+ * the full routing table is pinned here, not just its shape.
17
+ *
18
+ * `scripts/gen-location-type.py` OVERLAYS these columns on the rows published
19
+ * 2026-04-22. It never adds, removes, re-keys or renumbers a row. Canon's eight
20
+ * rows the package does not publish (the trafficking, birthplace and legal
21
+ * reasons ratified 2026-08-28) are reported by that script, not absorbed.
22
+ */
23
+
24
+ import { readFileSync } from "node:fs";
25
+ import path from "node:path";
26
+ import { fileURLToPath } from "node:url";
27
+
28
+ import { describe, it, expect } from "vitest";
29
+
30
+ const here = path.dirname(fileURLToPath(import.meta.url));
31
+ const cvcDir = path.join(here, "..", "cvcs");
32
+
33
+ interface Entry {
34
+ code: string;
35
+ key: string;
36
+ selectable: boolean;
37
+ parentCode: string | null;
38
+ tier?: string;
39
+ anchors?: string[];
40
+ anchorDefault?: string | null;
41
+ shareUnit?: string | null;
42
+ safetyDefault?: string | null;
43
+ }
44
+
45
+ const read = (f: string): { entries: Entry[]; _source?: string } =>
46
+ JSON.parse(readFileSync(path.join(cvcDir, f), "utf8")) as {
47
+ entries: Entry[];
48
+ _source?: string;
49
+ };
50
+
51
+ const lt = read("locationType.v1.0.0.json");
52
+ const scope = read("coreInformationScope.v1.0.0.json");
53
+ const byKey = new Map(lt.entries.map((e) => [e.key, e]));
54
+ const scopeByKey = new Map(scope.entries.map((e) => [e.key, e]));
55
+ const reasons = lt.entries.filter((e) => e.key !== "missingness_root");
56
+
57
+ const SENTINELS = ["unknown", "anonymous", "data_not_collected"];
58
+
59
+ /**
60
+ * The published rows, at their frozen positional codes. The overlay may not
61
+ * move them; a new canon row joins only by appending, in its own change.
62
+ */
63
+ const PUBLISHED: ReadonlyArray<readonly [string, string]> = [
64
+ ["191-000-000-000-000-000-000", "missingness_root"],
65
+ ["191-000-000-000-000-000-001", "unknown"],
66
+ ["191-000-000-000-000-000-002", "anonymous"],
67
+ ["191-000-000-000-000-000-003", "data_not_collected"],
68
+ ["191-001-000-000-000-000-000", "current_residence"],
69
+ ["191-002-000-000-000-000-000", "service_delivery_location"],
70
+ ["191-003-000-000-000-000-000", "current_client_location"],
71
+ ["191-004-000-000-000-000-000", "meet_contact_location"],
72
+ ["191-005-000-000-000-000-000", "prior_residence"],
73
+ ["191-006-000-000-000-000-000", "jurisdiction_routing_location"],
74
+ ["191-007-000-000-000-000-000", "ad_location_derived"],
75
+ ["191-008-000-000-000-000-000", "travel_stop_visit"],
76
+ ["191-009-000-000-000-000-000", "work_school_business"],
77
+ ["191-010-000-000-000-000-000", "ip_derived_location"],
78
+ ["191-011-000-000-000-000-000", "program_project_location"],
79
+ ["191-012-000-000-000-000-000", "other"],
80
+ ["191-013-000-000-000-000-000", "incident"],
81
+ ];
82
+
83
+ /**
84
+ * Canon's routing for every published reason (the codebook's "Rides on a share
85
+ * (CVC-236)" column, R1). `null` = never delivered on a share.
86
+ */
87
+ const ROUTING: Record<string, string | null> = {
88
+ unknown: null,
89
+ anonymous: null,
90
+ data_not_collected: null,
91
+ current_residence: "addresses",
92
+ prior_residence: "addresses",
93
+ current_client_location: "addresses",
94
+ jurisdiction_routing_location: "addresses",
95
+ travel_stop_visit: "addresses",
96
+ work_school_business: "addresses",
97
+ other: "addresses",
98
+ meet_contact_location: "encounter_location",
99
+ incident: "encounter_location",
100
+ service_delivery_location: "service_history",
101
+ program_project_location: null,
102
+ ad_location_derived: "commercial_activity",
103
+ ip_derived_location: "commercial_activity",
104
+ };
105
+
106
+ describe("location_type — published rows never move", () => {
107
+ it("keeps every published row at its frozen code, and adds none", () => {
108
+ expect(lt.entries.map((e) => [e.code, e.key])).toEqual(PUBLISHED);
109
+ });
110
+
111
+ it("pins the overlay's provenance to canon, and names what it did not absorb", () => {
112
+ expect(lt._source).toContain("data/cvcs/core_location_type.yaml @ 55088d44");
113
+ expect(lt._source).toContain("NOT absorbed: 8 canon rows");
114
+ });
115
+ });
116
+
117
+ describe("location_type — every reason declares the five logic columns", () => {
118
+ it("carries all five columns on every reason, and none on the missingness root", () => {
119
+ for (const e of reasons) {
120
+ for (const f of ["tier", "anchors", "anchorDefault", "shareUnit", "safetyDefault"]) {
121
+ expect(e, `${e.key} lacks ${f}`).toHaveProperty(f);
122
+ }
123
+ }
124
+ expect(byKey.get("missingness_root")).not.toHaveProperty("tier");
125
+ });
126
+
127
+ it("draws each column from canon's closed value sets", () => {
128
+ const TIERS = ["residence", "encounter", "trafficking", "legal", "service", "derived", "sentinel"];
129
+ const ANCHORS = ["person", "session", "event", "service_instance", "agency_program"];
130
+ for (const e of reasons) {
131
+ expect(TIERS, e.key).toContain(e.tier);
132
+ for (const a of e.anchors ?? []) expect(ANCHORS, e.key).toContain(a);
133
+ expect([null, "ask", "unsafe", "safe"], e.key).toContain(e.safetyDefault);
134
+ }
135
+ });
136
+
137
+ it("lands a bare pick on one of the reason's own anchors", () => {
138
+ for (const e of reasons) {
139
+ if (e.anchorDefault === null) continue;
140
+ expect(e.anchors, e.key).toContain(e.anchorDefault);
141
+ }
142
+ });
143
+
144
+ it("treats the missingness sentinels as carrying no place", () => {
145
+ for (const k of SENTINELS) {
146
+ const e = byKey.get(k);
147
+ expect(e?.tier).toBe("sentinel");
148
+ expect(e?.anchors).toEqual([]);
149
+ expect(e?.anchorDefault).toBeNull();
150
+ expect(e?.shareUnit).toBeNull();
151
+ expect(e?.safetyDefault).toBeNull();
152
+ }
153
+ });
154
+ });
155
+
156
+ describe("location_type — share routing at type grain (R1/R2)", () => {
157
+ it("routes every published reason exactly as canon declares", () => {
158
+ expect(Object.fromEntries(reasons.map((e) => [e.key, e.shareUnit]))).toEqual(ROUTING);
159
+ });
160
+
161
+ it("names only CVC-236 keys the package publishes", () => {
162
+ for (const e of reasons) {
163
+ if (e.shareUnit === null) continue;
164
+ expect(scopeByKey.has(e.shareUnit as string), `${e.key} -> ${e.shareUnit}`).toBe(true);
165
+ }
166
+ });
167
+
168
+ it("names an authorization-grain UNIT, except canon's two LEADS-only derived reasons", () => {
169
+ // Canon's column names the category `commercial_activity` (not one of its
170
+ // units) for the two machine-derived reasons. Carried verbatim; a consumer
171
+ // authorizing at unit grain must resolve it as the category.
172
+ const isCategory = (k: string): boolean => scopeByKey.get(k)?.selectable === false;
173
+ const atCategory = reasons
174
+ .filter((e) => e.shareUnit !== null && isCategory(e.shareUnit as string))
175
+ .map((e) => e.key)
176
+ .sort();
177
+ expect(atCategory).toEqual(["ad_location_derived", "ip_derived_location"]);
178
+ });
179
+
180
+ it("sends only the session/event encounter reasons under encounter_location", () => {
181
+ const enc = reasons.filter((e) => e.shareUnit === "encounter_location");
182
+ expect(enc.map((e) => e.key).sort()).toEqual(["incident", "meet_contact_location"]);
183
+ // Meet / contact is the session card's Meetup role: session-anchored by default.
184
+ expect(byKey.get("meet_contact_location")?.anchorDefault).toBe("session");
185
+ expect(byKey.get("incident")?.anchorDefault).toBe("event");
186
+ expect(scopeByKey.get("encounter_location")?.selectable).toBe(true);
187
+ });
188
+
189
+ it("never delivers the agency's own program site, and presets it safe (R3)", () => {
190
+ const prog = byKey.get("program_project_location");
191
+ expect(prog?.shareUnit).toBeNull();
192
+ expect(prog?.anchors).toEqual(["agency_program"]);
193
+ expect(prog?.safetyDefault).toBe("safe");
194
+ });
195
+
196
+ it("keeps the survivor's own whereabouts on addresses", () => {
197
+ for (const k of ["current_client_location", "travel_stop_visit", "current_residence"]) {
198
+ expect(byKey.get(k)?.shareUnit, k).toBe("addresses");
199
+ expect(byKey.get(k)?.anchorDefault, k).toBe("person");
200
+ }
201
+ });
202
+ });
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Team directory fields: the Mongoose fragment and the Zod schema behind the
3
+ * Thread→PAVE "Refer to intake" preset (canon: kickoff § 2.8 L254-257 at
4
+ * prototype `c658d6f7`; Thread ADR-THREAD-PAVE-CASESHARE-CONVERGENCE D1).
5
+ *
6
+ * The load-bearing guarantee is backward compatibility: an existing team
7
+ * document, in either the legacy PAVE shape or Thread's mirror shape, must
8
+ * validate unchanged and must not gain new keys when it is re-saved.
9
+ *
10
+ * No database is needed. Each test compiles models on a private Mongoose
11
+ * instance and calls `validateSync()` / `toObject()`.
12
+ */
13
+
14
+ import { describe, expect, it } from "vitest";
15
+ import mongoose, { Schema, Types } from "mongoose";
16
+
17
+ import {
18
+ PLATFORM_TOOL,
19
+ TEAM_MODEL_NAME,
20
+ TeamAppSchema,
21
+ TeamDirectoryFieldsSchema,
22
+ addTeamDirectoryFields,
23
+ teamDirectorySchemaDefinition,
24
+ type TeamDirectoryFields,
25
+ } from "../index.js";
26
+ import * as validationBarrel from "../validation/index.js";
27
+ import { z } from "zod";
28
+
29
+ // ─── Fixtures ────────────────────────────────────────────────────────
30
+
31
+ /** The legacy PAVE `teams` shape (screening-tools `models/teamModel.js`). */
32
+ function legacyPaveTeamSchema(): Schema {
33
+ return new Schema({
34
+ agencyId: { type: Schema.Types.ObjectId, index: true },
35
+ defaultTeam: { type: Boolean, default: false },
36
+ members: [{ type: Schema.Types.ObjectId }],
37
+ multiAgencyTeam: { type: Boolean, default: false },
38
+ name: { type: String, required: true },
39
+ numUsersEstimate: Number,
40
+ sharingPolicyId: { type: Schema.Types.ObjectId },
41
+ summary: String,
42
+ trainingModules: [String],
43
+ roles: [String],
44
+ });
45
+ }
46
+
47
+ /** Thread's mirror (`packages/db/src/models/platform/Team.ts`). */
48
+ function threadMirrorTeamSchema(): Schema {
49
+ return new Schema(
50
+ {
51
+ _schemaVersion: { type: Number, required: true, default: 1 },
52
+ createdUser: { type: Schema.Types.ObjectId, required: true },
53
+ updatedUser: { type: Schema.Types.ObjectId },
54
+ name: { type: String, required: true },
55
+ agencyId: { type: Schema.Types.ObjectId, required: true, ref: "Agency" },
56
+ defaultTeam: { type: Boolean, default: false },
57
+ status: { type: Number, required: true },
58
+ },
59
+ { timestamps: { createdAt: "createdTime", updatedAt: "updatedTime" } },
60
+ );
61
+ }
62
+
63
+ let modelSeq = 0;
64
+ function compile(schema: Schema) {
65
+ const m = new mongoose.Mongoose();
66
+ modelSeq += 1;
67
+ return m.model(`${TEAM_MODEL_NAME}${modelSeq}`, schema, "teams");
68
+ }
69
+
70
+ const LEGACY_DOC = {
71
+ agencyId: new Types.ObjectId(),
72
+ defaultTeam: true,
73
+ members: [new Types.ObjectId()],
74
+ multiAgencyTeam: false,
75
+ name: "Crisis Contact Team",
76
+ numUsersEstimate: 12,
77
+ summary: "",
78
+ trainingModules: [],
79
+ roles: [],
80
+ };
81
+
82
+ const THREAD_DOC = {
83
+ createdUser: new Types.ObjectId(),
84
+ name: "Crisis Contact Team",
85
+ agencyId: new Types.ObjectId(),
86
+ defaultTeam: true,
87
+ status: 1,
88
+ };
89
+
90
+ // ─── Mongoose fragment ───────────────────────────────────────────────
91
+
92
+ describe("teamDirectorySchemaDefinition (Mongoose)", () => {
93
+ it("validates an existing legacy PAVE team doc unchanged and adds no keys", () => {
94
+ const Team = compile(addTeamDirectoryFields(legacyPaveTeamSchema()));
95
+ const doc = new Team(LEGACY_DOC);
96
+
97
+ expect(doc.validateSync()).toBeUndefined();
98
+ const obj = doc.toObject();
99
+ expect(obj).not.toHaveProperty("apps");
100
+ expect(obj).not.toHaveProperty("canReferTo");
101
+ });
102
+
103
+ it("validates an existing Thread-mirror team doc unchanged and adds no keys", () => {
104
+ const Team = compile(addTeamDirectoryFields(threadMirrorTeamSchema()));
105
+ const doc = new Team(THREAD_DOC);
106
+
107
+ expect(doc.validateSync()).toBeUndefined();
108
+ const obj = doc.toObject();
109
+ expect(obj).not.toHaveProperty("apps");
110
+ expect(obj).not.toHaveProperty("canReferTo");
111
+ });
112
+
113
+ it("hydrates a stored doc without the fields and leaves it unmodified", () => {
114
+ const Team = compile(addTeamDirectoryFields(legacyPaveTeamSchema()));
115
+ const hydrated = Team.hydrate({ _id: new Types.ObjectId(), ...LEGACY_DOC });
116
+
117
+ expect(hydrated.isModified()).toBe(false);
118
+ expect(hydrated.get("apps")).toBeUndefined();
119
+ expect(hydrated.get("canReferTo")).toBeUndefined();
120
+ });
121
+
122
+ it("accepts PLATFORM_TOOL app codes and keeps canReferTo in order", () => {
123
+ const Team = compile(addTeamDirectoryFields(legacyPaveTeamSchema()));
124
+ const shelter = new Types.ObjectId();
125
+ const nonResidential = new Types.ObjectId();
126
+ const doc = new Team({
127
+ ...LEGACY_DOC,
128
+ apps: [PLATFORM_TOOL.THREAD],
129
+ canReferTo: [shelter.toHexString(), nonResidential],
130
+ });
131
+
132
+ expect(doc.validateSync()).toBeUndefined();
133
+ const obj = doc.toObject() as unknown as { apps: string[]; canReferTo: Types.ObjectId[] };
134
+ expect(obj.apps).toEqual(["THREAD"]);
135
+ expect(obj.canReferTo.map(String)).toEqual([String(shelter), String(nonResidential)]);
136
+ expect(obj.canReferTo[0]).toBeInstanceOf(Types.ObjectId);
137
+ });
138
+
139
+ it("keeps a declared-empty list distinct from an absent one", () => {
140
+ const Team = compile(addTeamDirectoryFields(legacyPaveTeamSchema()));
141
+ const doc = new Team({ ...LEGACY_DOC, apps: [], canReferTo: [] });
142
+
143
+ expect(doc.validateSync()).toBeUndefined();
144
+ expect(doc.toObject()).toMatchObject({ apps: [], canReferTo: [] });
145
+ });
146
+
147
+ it("rejects an app outside PLATFORM_TOOL, including canon's lowercase 'pave'", () => {
148
+ const Team = compile(addTeamDirectoryFields(legacyPaveTeamSchema()));
149
+ const err = new Team({ ...LEGACY_DOC, apps: ["PAVE", "pave"] }).validateSync();
150
+
151
+ expect(err?.errors["apps.1"]).toBeDefined();
152
+ expect(err?.errors["apps.0"]).toBeUndefined();
153
+ });
154
+
155
+ it("rejects a canReferTo entry that is not an ObjectId", () => {
156
+ const Team = compile(addTeamDirectoryFields(legacyPaveTeamSchema()));
157
+ const err = new Team({ ...LEGACY_DOC, canReferTo: ["prog-spring-crisis-shelter"] })
158
+ .validateSync();
159
+
160
+ expect(err).toBeDefined();
161
+ expect(Object.keys(err?.errors ?? {}).some((k) => k.startsWith("canReferTo"))).toBe(true);
162
+ });
163
+
164
+ it("refs canReferTo at the Team model", () => {
165
+ const schema = addTeamDirectoryFields(legacyPaveTeamSchema());
166
+ const element = schema.path("canReferTo.$") as unknown as { options?: { ref?: string } };
167
+ expect(element.options?.ref).toBe(TEAM_MODEL_NAME);
168
+ expect(TEAM_MODEL_NAME).toBe("Team");
169
+ });
170
+
171
+ it("returns the same schema and adds no indexes", () => {
172
+ const schema = legacyPaveTeamSchema();
173
+ const before = JSON.stringify(schema.indexes());
174
+ const result = addTeamDirectoryFields(schema);
175
+
176
+ expect(result).toBe(schema);
177
+ expect(JSON.stringify(schema.indexes())).toBe(before);
178
+ });
179
+
180
+ it("infers TeamDirectoryFields as optional app codes and ObjectIds (compile-time)", () => {
181
+ // `tsc --noEmit` (npm run typecheck) is the real assertion here.
182
+ const declared: TeamDirectoryFields = {
183
+ apps: [PLATFORM_TOOL.PAVE],
184
+ canReferTo: [new Types.ObjectId()],
185
+ };
186
+ const absent: TeamDirectoryFields = {};
187
+ // @ts-expect-error canon's lowercase app id is not a PlatformToolValue
188
+ const lowercase: TeamDirectoryFields = { apps: ["pave"] };
189
+ // @ts-expect-error a program id string is not an ObjectId
190
+ const programId: TeamDirectoryFields = { canReferTo: ["prog-spring-crisis-shelter"] };
191
+
192
+ expect([declared, absent, lowercase, programId]).toHaveLength(4);
193
+ });
194
+
195
+ it("declares exactly the two directory fields", () => {
196
+ expect(Object.keys(teamDirectorySchemaDefinition).sort()).toEqual(["apps", "canReferTo"]);
197
+ });
198
+ });
199
+
200
+ // ─── Zod ─────────────────────────────────────────────────────────────
201
+
202
+ describe("TeamDirectoryFieldsSchema (Zod)", () => {
203
+ const idA = new Types.ObjectId().toHexString();
204
+ const idB = new Types.ObjectId().toHexString();
205
+
206
+ it("accepts a payload without the fields", () => {
207
+ expect(TeamDirectoryFieldsSchema.parse({})).toEqual({});
208
+ });
209
+
210
+ it("accepts apps and an ordered canReferTo", () => {
211
+ const parsed = TeamDirectoryFieldsSchema.parse({ apps: ["THREAD", "PAVE"], canReferTo: [idA, idB] });
212
+ expect(parsed).toEqual({ apps: ["THREAD", "PAVE"], canReferTo: [idA, idB] });
213
+ });
214
+
215
+ it("rejects canon's lowercase app id", () => {
216
+ expect(TeamAppSchema.safeParse("pave").success).toBe(false);
217
+ expect(TeamDirectoryFieldsSchema.safeParse({ apps: ["pave"] }).success).toBe(false);
218
+ });
219
+
220
+ it("rejects a repeated app or target team", () => {
221
+ expect(TeamDirectoryFieldsSchema.safeParse({ apps: ["PAVE", "PAVE"] }).success).toBe(false);
222
+ expect(
223
+ TeamDirectoryFieldsSchema.safeParse({ canReferTo: [idA, idA.toUpperCase()] }).success,
224
+ ).toBe(false);
225
+ });
226
+
227
+ it("rejects a non-ObjectId target", () => {
228
+ expect(
229
+ TeamDirectoryFieldsSchema.safeParse({ canReferTo: ["prog-spring-crisis-shelter"] }).success,
230
+ ).toBe(false);
231
+ });
232
+
233
+ it("merges into a consumer's team schema without touching existing fields", () => {
234
+ const ConsumerTeam = z
235
+ .object({ name: z.string(), defaultTeam: z.boolean().optional() })
236
+ .merge(TeamDirectoryFieldsSchema);
237
+
238
+ expect(ConsumerTeam.parse({ name: "Crisis Shelter", defaultTeam: false })).toEqual({
239
+ name: "Crisis Shelter",
240
+ defaultTeam: false,
241
+ });
242
+ expect(ConsumerTeam.parse({ name: "Crisis Shelter", apps: ["PAVE"] })).toEqual({
243
+ name: "Crisis Shelter",
244
+ apps: ["PAVE"],
245
+ });
246
+ });
247
+
248
+ it("is exported from the /validation barrel", () => {
249
+ expect(validationBarrel.TeamDirectoryFieldsSchema).toBe(TeamDirectoryFieldsSchema);
250
+ expect(validationBarrel.TeamAppSchema).toBe(TeamAppSchema);
251
+ });
252
+ });
@@ -2,8 +2,8 @@
2
2
  "domain": "core_information_scope",
3
3
  "name": "Core Information Scope",
4
4
  "version": "1.0.0",
5
- "_status": "DRAFT: canonical number 236, self-declared by the source YAML (`cvc_id: CVC-236`); CVC_INDEX.md carries no row for it yet, so the drift gate classifies it INDEX_ABSENT. Sourced from canonical CVC-236 `core_information_scope` v2 (authored 2026-08-13, restructured 2026-08-14): 12 categories / 54 units. TWO GRAINS, deliberately modelled as hierarchy: L1 categories are the POLICY grain and are NOT selectable; L2 units are the AUTHORIZATION grain and are what an ROI or a share actually authorizes. This is the axis the sibling `roi_scope` domain deliberately omits — `roi_scope` is the flat item vocabulary, and its 27 substantive keys are a strict SUBSET of the 54 units here, with no renames and no collisions. That subset relationship is what makes adopting this domain additive: every stored ROI keeps its exact recorded meaning. `safe_locations` is PROVISIONAL and may be re-keyed by the Notion steward batch — pin the id with the product owner before any consumer treats it as stable. PENDING canonical Notion authoring + steward ratification.",
6
- "_source": "htilabstech/prototype data/cvcs/core_information_scope.yaml (CVC-236 v2, restructured 2026-08-14)",
5
+ "_status": "DRAFT: canonical number 236, self-declared by the source YAML (`cvc_id: CVC-236`); CVC_INDEX.md carries no row for it yet, so the drift gate classifies it INDEX_ABSENT. Sourced from canonical CVC-236 `core_information_scope` v2 (authored 2026-08-13, restructured 2026-08-14): 12 categories / 56 units. TWO GRAINS, deliberately modelled as hierarchy: L1 categories are the POLICY grain and are NOT selectable; L2 units are the AUTHORIZATION grain and are what an ROI or a share actually authorizes. This is the axis the sibling `roi_scope` domain deliberately omits — `roi_scope` is the flat item vocabulary, and its 27 substantive keys are a strict SUBSET of the 56 units here, with no renames and no collisions. That subset relationship is what makes adopting this domain additive: every stored ROI keeps its exact recorded meaning. `safe_locations` is PROVISIONAL and may be re-keyed by the Notion steward batch — pin the id with the product owner before any consumer treats it as stable. PENDING canonical Notion authoring + steward ratification.",
6
+ "_source": "htilabstech/prototype/data/cvcs/core_information_scope.yaml @ 55088d44 (CVC-236 v2, restructured 2026-08-14, amended 2026-10-01; read from origin/main; structural columns cross-checked against htilabstech/prototype/Final CVCs/System Roles, Permissions, & Account Management (IC-66)/core-information_scope — codebook.csv @ 55088d44)",
7
7
  "levels": {
8
8
  "0": "Unknown or Missing",
9
9
  "1": "Category (policy grain, not selectable)",
@@ -114,7 +114,7 @@
114
114
  "selectable": true,
115
115
  "parentCode": "236-001-000-000-000-000-000",
116
116
  "childCodes": [],
117
- "definition": "Addresses. Category `identifying`.",
117
+ "definition": "Addresses. Category `identifying`. LOCATION-TYPE-LOGIC 2026-10-01 (Crysta R1/R3): routed at TYPE grain since this date — the location entries whose CVC-191 reason declares share_unit addresses (the residence tier: current / prior residence · birthplace; the survivor's own whereabouts: current client/victim location · jurisdiction / routing · work / school / business · travel stop · other), each delivered with its type label. Where we met / where it happened rides encounter_location; trafficking-event locations ride victimization; legal locations ride system_involvement; the agency's own site rides nothing. The `address` assertion_domain stays mapped here for the viewing axis and the ADDRESS_* audit verbs.",
118
118
  "levelFloor": 3,
119
119
  "appRelevance": [
120
120
  "PAVE",
@@ -470,9 +470,11 @@
470
470
  "parentCode": null,
471
471
  "childCodes": [
472
472
  "236-003-001-000-000-000-000",
473
- "236-003-002-000-000-000-000"
473
+ "236-003-002-000-000-000-000",
474
+ "236-003-003-000-000-000-000",
475
+ "236-003-004-000-000-000-000"
474
476
  ],
475
- "definition": "Contact & safety — policy-grain category. Units under it are the authorization grain. NARROWED 2026-08-14 (restructure ruling 2): contact/service history moved to the NEW services category. SUPERSEDES the 2026-08-13 deliberate-merge note; legacy `contact` grants resolve via the alias layer (CVC-69 precedent). LEADS flag dropped (no LEADS units — was an empty shell).",
477
+ "definition": "Contact & safety — policy-grain category. Units under it are the authorization grain. NARROWED 2026-08-14 (restructure ruling 2): contact/service history moved to the NEW services category. SUPERSEDES the 2026-08-13 deliberate-merge note; legacy `contact` grants resolve via the alias layer (CVC-69 precedent). LEADS flag dropped (no LEADS units — was an empty shell). | 2026-09-29 (PRIORITIES-SAFETY-SCOPE-UNIT, Crysta R1): third unit priorities_safety — the immediate-needs triage answers, one disclosure decision. | 2026-10-01 (LOCATION-TYPE-LOGIC, Crysta R2): fourth unit encounter_location — where we met / where it happened, the session- or event-anchored CVC-191 encounter reasons.",
476
478
  "levelFloor": 3,
477
479
  "appRelevance": [
478
480
  "PAVE",
@@ -514,6 +516,38 @@
514
516
  "specialDataType": "survivor_confidential",
515
517
  "platformFloor": true
516
518
  },
519
+ {
520
+ "code": "236-003-003-000-000-000-000",
521
+ "key": "priorities_safety",
522
+ "title": "Priorities & Safety (immediate needs triage)",
523
+ "selectable": true,
524
+ "parentCode": "236-003-000-000-000-000-000",
525
+ "childCodes": [],
526
+ "definition": "Priorities & Safety (immediate needs triage). Category `contact`. NEW 2026-09-29 (PRIORITIES-SAFETY-SCOPE-UNIT, Crysta R1): the completed Immediate Priorities / Priorities & Safety triage, authorized as ONE disclosure decision — Q1 immediate danger + source of the danger + harm-doer nearby + safe place to go · Q2 health needs · Q3 interpreter · Q4 urgent basic needs · Q5 transportation (method / time / pickup location) · Q6 emergency shelter · Q7 dependents at risk · Q8 other. Instrument-grain unit on the initial_screen / lap precedent (ruling 1, 2026-08-13), homed under Contact & safety because the answers that had no home are safety facts; the service instances the step derives ride services/service_history on their own. Bidirectional Thread Signal ↔ PAVE mirror on Q1 (GDR § 6.9.7) — one unit, both apps. domain_map: priorities_safety → this unit (R3 EXECUTED later the same day, PRIORITIES-SAFETY-RECORD): CVC-159 domain priorities_safety (Level 1) + monolith emitter emitPrioritiesAnswerCAR (one CAR per answered question) + UDD row capture.priorities_safety; production persistence of the answers stays with Nate under RWT-NEW-priorities-safety-record-and-udd-2026-09-29. Minted in the Notion codebook the same day; codebook row re-synced to the record 2026-09-29.",
527
+ "levelFloor": 3,
528
+ "appRelevance": [
529
+ "PAVE",
530
+ "Thread"
531
+ ],
532
+ "shareableDefault": true,
533
+ "specialDataType": "survivor_confidential"
534
+ },
535
+ {
536
+ "code": "236-003-004-000-000-000-000",
537
+ "key": "encounter_location",
538
+ "title": "Encounter location (where we met / where it happened)",
539
+ "selectable": true,
540
+ "parentCode": "236-003-000-000-000-000-000",
541
+ "childCodes": [],
542
+ "definition": "Encounter location (where we met / where it happened). Category `contact`. NEW 2026-10-01 (LOCATION-TYPE-LOGIC, Crysta R2): the location entries whose CVC-191 reason is session- or event-anchored — Meet / contact (the session card's Meetup / Incident role) and Incident — authorized as ONE disclosure decision, separate from Addresses. Why it exists: the session card's Meetup / Incident location is encounter-scoped (ADDRESS_INTEGRATION_PLAN row 3 — a meetup point that belongs to no person), so it was never on the survivor's record and never reached a share; Nate's PAVE 2.0 audit found the same hole from the other direction. Homed under Contact & safety on the 2026-09-29 R1 reasoning: where the survivor was found or met is the safety fact the next advocate needs. Routing is read from CVC-191 (`share_unit: encounter_location` on MEET_LOC + INCIDENT), never hand-listed here; the delivered copy carries each entry with its type label and the session it belongs to. The survivor's own current location stays under Addresses; the agency's own site rides nothing. UDD: capture.encounter_location (apps PAVE + Thread, assertion_domain address). Presets: full_collab (ROI) · Thread service_referral_packet + mandatory_report (derivation for veto, 2026-09-29 shape).",
543
+ "levelFloor": 3,
544
+ "appRelevance": [
545
+ "PAVE",
546
+ "Thread"
547
+ ],
548
+ "shareableDefault": true,
549
+ "specialDataType": "survivor_confidential"
550
+ },
517
551
  {
518
552
  "code": "236-004-000-000-000-000-000",
519
553
  "key": "services",
package/src/cvcs/index.ts CHANGED
@@ -62,6 +62,9 @@ import sexProviderSubroleSot from "./sexProviderSubrole.v1.0.0.json" with { type
62
62
  import relationshipTiesSot from "./relationshipTies.v1.0.0.json" with { type: "json" };
63
63
  import personRelationshipsSot from "./personRelationships.v1.0.0.json" with { type: "json" };
64
64
  import employmentStatusSot from "./employmentStatus.v1.0.0.json" with { type: "json" };
65
+ // CVC-191 — rows hand-authored 2026-04-22; the per-reason share-routing columns
66
+ // (tier · anchors · anchorDefault · shareUnit · safetyDefault) are overlaid from
67
+ // prototype canon by scripts/gen-location-type.py; re-run, don't hand-edit them.
65
68
  import locationTypeSot from "./locationType.v1.0.0.json" with { type: "json" };
66
69
  import referralEntityCategorySot from "./referralEntityCategory.v1.0.0.json" with { type: "json" };
67
70
  import incomeBenefitsSourcesSot from "./incomeBenefitsSources.v1.0.0.json" with { type: "json" };