@htilabs/platform-common-models 0.12.1 → 0.12.3

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 (55) hide show
  1. package/dist/{cvcEntry-0BIB9sen.d.cts → cvcEntry-ctHTp2df.d.cts} +36 -36
  2. package/dist/{cvcEntry-0BIB9sen.d.ts → cvcEntry-ctHTp2df.d.ts} +36 -36
  3. package/dist/cvcs/index.cjs +245 -4
  4. package/dist/cvcs/index.cjs.map +1 -1
  5. package/dist/cvcs/index.d.cts +533 -274
  6. package/dist/cvcs/index.d.ts +533 -274
  7. package/dist/cvcs/index.js +244 -4
  8. package/dist/cvcs/index.js.map +1 -1
  9. package/dist/enums/index.cjs +17 -0
  10. package/dist/enums/index.cjs.map +1 -1
  11. package/dist/enums/index.d.cts +24 -3
  12. package/dist/enums/index.d.ts +24 -3
  13. package/dist/enums/index.js +16 -0
  14. package/dist/enums/index.js.map +1 -1
  15. package/dist/{index-CDoqrfc1.d.ts → index-4DiJrn7y.d.ts} +1 -1
  16. package/dist/{index-Zu_mOJRn.d.cts → index-qreOzXYS.d.cts} +1 -1
  17. package/dist/index.cjs +317 -11
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +6 -6
  20. package/dist/index.d.ts +6 -6
  21. package/dist/index.js +310 -11
  22. package/dist/index.js.map +1 -1
  23. package/dist/models/index.d.cts +2 -2
  24. package/dist/models/index.d.ts +2 -2
  25. package/dist/schemas/index.cjs +41 -7
  26. package/dist/schemas/index.cjs.map +1 -1
  27. package/dist/schemas/index.d.cts +116 -12
  28. package/dist/schemas/index.d.ts +116 -12
  29. package/dist/schemas/index.js +38 -7
  30. package/dist/schemas/index.js.map +1 -1
  31. package/dist/{cvc-Cp4uWnAa.d.cts → team-C4LJ5Tex.d.cts} +36 -1
  32. package/dist/{cvc-Cp4uWnAa.d.ts → team-C4LJ5Tex.d.ts} +36 -1
  33. package/dist/validation/index.cjs +155 -0
  34. package/dist/validation/index.cjs.map +1 -1
  35. package/dist/validation/index.d.cts +1 -1
  36. package/dist/validation/index.d.ts +1 -1
  37. package/dist/validation/index.js +153 -0
  38. package/dist/validation/index.js.map +1 -1
  39. package/package.json +27 -26
  40. package/src/__tests__/__snapshots__/cvc-sot.snap +8 -0
  41. package/src/__tests__/core-information-scope-invariant.test.ts +125 -2
  42. package/src/__tests__/cvc-drift-gate.test.ts +18 -0
  43. package/src/__tests__/cvc-sot-snapshot.test.ts +17 -0
  44. package/src/__tests__/cvc-structural.test.ts +5 -0
  45. package/src/__tests__/share-response-reason-invariant.test.ts +167 -0
  46. package/src/__tests__/team-directory-fields.test.ts +252 -0
  47. package/src/cvcs/coreInformationScope.v1.0.0.json +21 -4
  48. package/src/cvcs/index.ts +4 -0
  49. package/src/cvcs/shareResponseReason.v1.0.0.json +220 -0
  50. package/src/generated/cvc-enums.ts +25 -2
  51. package/src/index.ts +7 -0
  52. package/src/schemas/index.ts +8 -0
  53. package/src/schemas/team.ts +118 -0
  54. package/src/validation/index.ts +1 -0
  55. package/src/validation/team.ts +48 -0
@@ -0,0 +1,220 @@
1
+ {
2
+ "domain": "share_response_reason",
3
+ "name": "Core Share Response Reason",
4
+ "version": "1.0.0",
5
+ "_status": "CANONICAL — Notion CVC-306 `core-share_response_reason` v1.1, `vocab_status: active` (minted 2026-08-23 in the Crysta-approved steward batch; FULL AUDIT 2026-09-14, SHARING-FAMILY-AUDIT -> Active / 1.1). Exported from prototype canon @ 6c2cfc0a, where it had sat unexported. The STRUCTURED reasons a recipient gives when responding to an inbound case share: ONE codebook with per-CONTEXT selectability (`field_review` · `decline_share` · `reject_share`) carried per entry as `contexts` — a consumer building a picker for one context filters on it, never on `selectable` alone. Rulings encoded upstream (Crysta 2026-08-23): reasons are CHIPS, not prose — an optional free-text note may ride alongside, never instead (R14); reasons NEVER travel to the sender in v1 (R16); 'connected with the person and they didn't want services' is an ACCEPT + CVC-219 why-nots, never a decline (R15). WORDING (title, definition, `guidance`, `logicNotes`) is verbatim from the Notion codebook export, which the yaml mirror's own header says wins on wording; `tobyRetention` is the yaml mirror's policy-as-data column. Positional ordinals 306-001..010 are MINTED in codebook row order (the codebook's Code column carries slugs only) and FROZEN at that key assignment: a new reason appends at 306-011+, a published code is never renumbered or reused. MISSINGNESS is canon's v1.1 shape: ONE ingestion-only sentinel, UNK (key `unknown`, `canonicalCode: UNK`, `selectable: false` — canon: never a picker chip; a reason is required at the act). The codebook's archived row(s) DNC (\"Not a value; never emit\") are OMITTED entirely — no code is assigned, and none ever shipped in a platform-common release. NUMBER: self-declared `cvc_id: CVC-306` and carried by upstream CVC_INDEX.md (`core-share_response_reason`), but the cvcIndex pin (622410b) predates that row, so the drift gate files this domain INDEX_ABSENT until the next pin refresh promotes it to CANONICAL_BINDING.",
6
+ "_source": "htilabstech/prototype/data/cvcs/core_share_response_reason.yaml @ 6c2cfc0a + htilabstech/prototype/Final CVCs/Sharing (IC-65)/core - share_response_reason — codebook.csv @ 6c2cfc0a (Notion CVC-306 v1.1; read from origin/main)",
7
+ "contexts": {
8
+ "field_review": "Field review",
9
+ "decline_share": "Decline share",
10
+ "reject_share": "Reject share"
11
+ },
12
+ "levels": {
13
+ "0": "Unknown or Missing",
14
+ "1": "Share response reason"
15
+ },
16
+ "entries": [
17
+ {
18
+ "code": "306-000-000-000-000-000-000",
19
+ "key": "missingness_root",
20
+ "title": "Unknown, Redacted, or Missing",
21
+ "selectable": false,
22
+ "parentCode": null,
23
+ "childCodes": [
24
+ "306-000-000-000-000-000-001"
25
+ ],
26
+ "definition": "Root group for values indicating absent, withheld, or uncollected data. Non-standard variant (Unknown only): canonical CVC-306 v1.1 carries ONE ingestion-only sentinel (UNK, the CVC-216 R1 shape); ANON and DNC are deliberately absent, and the codebook's DNC row is [ARCHIVED]. The sentinel is never a picker chip in any context."
27
+ },
28
+ {
29
+ "code": "306-000-000-000-000-000-001",
30
+ "key": "unknown",
31
+ "title": "Unknown",
32
+ "selectable": false,
33
+ "parentCode": "306-000-000-000-000-000-000",
34
+ "childCodes": [],
35
+ "definition": "Unknown or cannot be determined from the available information.",
36
+ "canonicalCode": "UNK",
37
+ "contexts": [],
38
+ "guidance": null,
39
+ "logicNotes": "House missingness convention (L0) — the ONE sentinel (CVC-216 R1 shape, applied 2026-09-14): reserved for ingested share responses whose source never recorded a reason. Never a picker chip in any context (a reason is required at the act). ANON and DNC deliberately absent (declared).",
40
+ "tobyRetention": {
41
+ "class": "tombstone_retain",
42
+ "stewardFlag": true
43
+ }
44
+ },
45
+ {
46
+ "code": "306-001-000-000-000-000-000",
47
+ "key": "information_incorrect",
48
+ "title": "The information is incorrect",
49
+ "selectable": true,
50
+ "parentCode": null,
51
+ "childCodes": [],
52
+ "definition": "The value is wrong — it does not match reality as the recipient knows it.",
53
+ "contexts": [
54
+ "field_review"
55
+ ],
56
+ "guidance": "The highest-signal code for platform accuracy learning: an explicit human judgment that the sender's record is wrong on this point.",
57
+ "logicNotes": "Sibling of core - record_removal_reason's created_in_error / value-incorrect family.",
58
+ "tobyRetention": {
59
+ "class": "supersede"
60
+ }
61
+ },
62
+ {
63
+ "code": "306-002-000-000-000-000-000",
64
+ "key": "not_relevant_for_client",
65
+ "title": "Not relevant for my client",
66
+ "selectable": true,
67
+ "parentCode": null,
68
+ "childCodes": [],
69
+ "definition": "The information may be true, but it doesn't belong in this client's record for the services this agency provides.",
70
+ "contexts": [
71
+ "field_review"
72
+ ],
73
+ "guidance": "Deliberately distinct from information_incorrect — relevance and accuracy must never collapse into one code (the RemoveAssetFlow lesson).",
74
+ "logicNotes": null,
75
+ "tobyRetention": {
76
+ "class": "tombstone_retain"
77
+ }
78
+ },
79
+ {
80
+ "code": "306-003-000-000-000-000-000",
81
+ "key": "duplicate_already_have",
82
+ "title": "Duplicate of what we have",
83
+ "selectable": true,
84
+ "parentCode": null,
85
+ "childCodes": [],
86
+ "definition": "The recipient already holds this information (or this whole share duplicates one already received).",
87
+ "contexts": [
88
+ "field_review",
89
+ "decline_share"
90
+ ],
91
+ "guidance": "Field review: the incoming value adds nothing. Decline: the share as a whole duplicates a prior one.",
92
+ "logicNotes": null,
93
+ "tobyRetention": {
94
+ "class": "tombstone_retain",
95
+ "engineSignal": "same_thing"
96
+ }
97
+ },
98
+ {
99
+ "code": "306-004-000-000-000-000-000",
100
+ "key": "client_declined_recording",
101
+ "title": "Client asked us not to record this",
102
+ "selectable": true,
103
+ "parentCode": null,
104
+ "childCodes": [],
105
+ "definition": "The client asked this agency not to hold this information on file.",
106
+ "contexts": [
107
+ "field_review"
108
+ ],
109
+ "guidance": "A consent judgment, not an accuracy judgment — platform learning must never read this as evidence the value is wrong.",
110
+ "logicNotes": "Interacts with the subpoena-exposure balancing test (GDR § 5.61): the advocate is weighing legal-harm risk against service value.",
111
+ "tobyRetention": {
112
+ "class": "inclusion_register"
113
+ }
114
+ },
115
+ {
116
+ "code": "306-005-000-000-000-000-000",
117
+ "key": "wrong_agency_service_area",
118
+ "title": "Wrong agency / outside our service area",
119
+ "selectable": true,
120
+ "parentCode": null,
121
+ "childCodes": [],
122
+ "definition": "This share should not have come to this agency — wrong coverage area or wrong service type.",
123
+ "contexts": [
124
+ "decline_share"
125
+ ],
126
+ "guidance": "Decline-only: a routing miss, decided before engaging the content.",
127
+ "logicNotes": null,
128
+ "tobyRetention": {
129
+ "class": "retain_event"
130
+ }
131
+ },
132
+ {
133
+ "code": "306-006-000-000-000-000-000",
134
+ "key": "not_our_client",
135
+ "title": "Not our client",
136
+ "selectable": true,
137
+ "parentCode": null,
138
+ "childCodes": [],
139
+ "definition": "This person is not (and will not become) a client of this agency.",
140
+ "contexts": [
141
+ "decline_share"
142
+ ],
143
+ "guidance": "Decline-only. NOT for the turned-away scenario — if the person was actually reached and chose no services, that's an ACCEPT with offered services + why-nots recorded.",
144
+ "logicNotes": null,
145
+ "tobyRetention": {
146
+ "class": "retain_event"
147
+ }
148
+ },
149
+ {
150
+ "code": "306-007-000-000-000-000-000",
151
+ "key": "sent_in_error",
152
+ "title": "Sent in error",
153
+ "selectable": true,
154
+ "parentCode": null,
155
+ "childCodes": [],
156
+ "definition": "The sender shared this by mistake (confirmed with the sender or evident from the content).",
157
+ "contexts": [
158
+ "decline_share",
159
+ "reject_share"
160
+ ],
161
+ "guidance": "Available at decline (before engaging) and reject (discovered during review).",
162
+ "logicNotes": null,
163
+ "tobyRetention": {
164
+ "class": "retain_event"
165
+ }
166
+ },
167
+ {
168
+ "code": "306-008-000-000-000-000-000",
169
+ "key": "no_capacity",
170
+ "title": "No capacity right now",
171
+ "selectable": true,
172
+ "parentCode": null,
173
+ "childCodes": [],
174
+ "definition": "The agency cannot take this on at the moment.",
175
+ "contexts": [
176
+ "decline_share"
177
+ ],
178
+ "guidance": "Decline-only; honest operational reason — the sender can re-share later (a re-claim starts fresh).",
179
+ "logicNotes": null,
180
+ "tobyRetention": {
181
+ "class": "retain_event"
182
+ }
183
+ },
184
+ {
185
+ "code": "306-009-000-000-000-000-000",
186
+ "key": "cannot_verify_conflicts",
187
+ "title": "Can't verify — conflicts with the client's account",
188
+ "selectable": true,
189
+ "parentCode": null,
190
+ "childCodes": [],
191
+ "definition": "The delivered content conflicts with what the client has told this agency directly, and cannot be verified.",
192
+ "contexts": [
193
+ "reject_share"
194
+ ],
195
+ "guidance": "Reject-only: a whole-share trust judgment after review. High-signal for deconfliction/accuracy learning.",
196
+ "logicNotes": null,
197
+ "tobyRetention": {
198
+ "class": "retain_event"
199
+ }
200
+ },
201
+ {
202
+ "code": "306-010-000-000-000-000-000",
203
+ "key": "wrong_person",
204
+ "title": "Wrong person",
205
+ "selectable": true,
206
+ "parentCode": null,
207
+ "childCodes": [],
208
+ "definition": "Review made clear the shared content is about a different person than the recipient's client.",
209
+ "contexts": [
210
+ "reject_share"
211
+ ],
212
+ "guidance": "Reject-only. Case identity, never person identity: the fix is rejecting the share — no cross-agency person merge exists or ever will.",
213
+ "logicNotes": null,
214
+ "tobyRetention": {
215
+ "class": "retain_event",
216
+ "engineSignal": "cross_agency_wrongness"
217
+ }
218
+ }
219
+ ]
220
+ }
@@ -922,6 +922,28 @@ export const CaseShareStateKeys = {
922
922
 
923
923
  export type CaseShareStateKey = keyof typeof CaseShareStateKeys;
924
924
 
925
+ /**
926
+ * Key → positional code map for the `share_response_reason` CVC domain (CVC-306, canonical v1.1 `Active` after the 2026-09-14 SHARING-FAMILY-AUDIT; generated from prototype origin/main canon by scripts/gen-share-response-reason.py). The structured reasons a recipient gives when responding to an inbound case share. ONE codebook with per-CONTEXT selectability carried per entry as `contexts` (`field_review` · `decline_share` · `reject_share`) — build a context's picker by filtering on `contexts`, not on this key map. The single L0 sentinel (`unknown`, canonical UNK) is ingestion-only and never a picker chip; the codebook's archived DNC row is omitted.
927
+ *
928
+ * Domain: `share_response_reason` · Version: 1.0.0 · Entries: 12
929
+ */
930
+ export const ShareResponseReasonKeys = {
931
+ missingness_root: "306-000-000-000-000-000-000",
932
+ unknown: "306-000-000-000-000-000-001",
933
+ information_incorrect: "306-001-000-000-000-000-000",
934
+ not_relevant_for_client: "306-002-000-000-000-000-000",
935
+ duplicate_already_have: "306-003-000-000-000-000-000",
936
+ client_declined_recording: "306-004-000-000-000-000-000",
937
+ wrong_agency_service_area: "306-005-000-000-000-000-000",
938
+ not_our_client: "306-006-000-000-000-000-000",
939
+ sent_in_error: "306-007-000-000-000-000-000",
940
+ no_capacity: "306-008-000-000-000-000-000",
941
+ cannot_verify_conflicts: "306-009-000-000-000-000-000",
942
+ wrong_person: "306-010-000-000-000-000-000",
943
+ } as const;
944
+
945
+ export type ShareResponseReasonKey = keyof typeof ShareResponseReasonKeys;
946
+
925
947
  /**
926
948
  * Key → positional code map for the `facilitator_entity_type` CVC domain.
927
949
  *
@@ -4063,9 +4085,9 @@ export const NeedsAssessmentChangeTypeKeys = {
4063
4085
  export type NeedsAssessmentChangeTypeKey = keyof typeof NeedsAssessmentChangeTypeKeys;
4064
4086
 
4065
4087
  /**
4066
- * Key → positional code map for the `core_information_scope` CVC domain (DRAFT-TEMPORARY; canonical CVC-236, 12 policy-grain CATEGORIES + 54 authorization-grain UNITS. Categories are level 1 and NOT selectable; units are level 2 and are what an ROI or a share authorizes. Distinct from the sibling `roi_scope` domain, which is the FLAT item vocabulary and deliberately omits the category axis — roi_scope's 27 substantive keys are a strict SUBSET of these 54 units, with no renames, so adoption is additive and no stored ROI changes meaning).
4088
+ * Key → positional code map for the `core_information_scope` CVC domain (DRAFT-TEMPORARY; canonical CVC-236, 12 policy-grain CATEGORIES + 55 authorization-grain UNITS. Categories are level 1 and NOT selectable; units are level 2 and are what an ROI or a share authorizes. Distinct from the sibling `roi_scope` domain, which is the FLAT item vocabulary and deliberately omits the category axis — roi_scope's 27 substantive keys are a strict SUBSET of these 55 units, with no renames, so adoption is additive and no stored ROI changes meaning).
4067
4089
  *
4068
- * Domain: `core_information_scope` · Version: 1.0.0 · Entries: 70
4090
+ * Domain: `core_information_scope` · Version: 1.0.0 · Entries: 71
4069
4091
  */
4070
4092
  export const CoreInformationScopeKeys = {
4071
4093
  missingness_root: "236-000-000-000-000-000-000",
@@ -4099,6 +4121,7 @@ export const CoreInformationScopeKeys = {
4099
4121
  contact: "236-003-000-000-000-000-000",
4100
4122
  contact_info: "236-003-001-000-000-000-000",
4101
4123
  safe_locations: "236-003-002-000-000-000-000",
4124
+ priorities_safety: "236-003-003-000-000-000-000",
4102
4125
  services: "236-004-000-000-000-000-000",
4103
4126
  contact_history: "236-004-001-000-000-000-000",
4104
4127
  service_history: "236-004-002-000-000-000-000",
package/src/index.ts CHANGED
@@ -74,6 +74,13 @@ export type {
74
74
  CvcDomain,
75
75
  } from "./validation/cvc.js";
76
76
 
77
+ // ─── Team directory field validation (Zod) ──────────────────────────────────
78
+ // The Mongoose fragment (`teamDirectorySchemaDefinition`,
79
+ // `addTeamDirectoryFields`) comes in through `./schemas/index.js` above.
80
+
81
+ export { TeamAppSchema, TeamDirectoryFieldsSchema } from "./validation/team.js";
82
+ export type { TeamApp, TeamDirectoryFieldsInput } from "./validation/team.js";
83
+
77
84
  // ─── CVC factory model named aliases ────────────────────────────────────────
78
85
  // Per co-am3.7 bead: surface the model factories under explicit
79
86
  // `compileCvcRegistryModel` / `compileCvcEntryModel` names. The underlying
@@ -85,6 +85,14 @@ export {
85
85
  type PlatformRole,
86
86
  } from "./platform-role.js";
87
87
 
88
+ // Team directory fields (fragment added to each app's team schema)
89
+ export {
90
+ TEAM_MODEL_NAME,
91
+ teamDirectorySchemaDefinition,
92
+ addTeamDirectoryFields,
93
+ type TeamDirectoryFields,
94
+ } from "./team.js";
95
+
88
96
  // CVC Registry schema
89
97
  export {
90
98
  buildCvcRegistrySchema,
@@ -0,0 +1,118 @@
1
+ /**
2
+ * @htilabs/platform-common-models — Team directory fields
3
+ *
4
+ * Shared, additive fields for the platform-db `teams` collection that the
5
+ * Thread→PAVE "Refer to intake" preset reads to resolve the own-agency PAVE
6
+ * intake team.
7
+ *
8
+ * ## This is a FRAGMENT, not a Team model
9
+ *
10
+ * No canonical Team schema exists in this package. The `teams` collection is
11
+ * defined by legacy PAVE (`screening-tools` `models/teamModel.js`,
12
+ * `agencyManagementDb`), mirrored by Thread
13
+ * (`packages/db/src/models/platform/Team.ts`), written by the platform Admin
14
+ * Hub and identity sync, and read raw by pave-2.0 (`lookups/teamGraph.ts`).
15
+ * Declaring the whole Team contract here would mean resolving those shapes,
16
+ * which is out of scope. This module only declares the fields the referral
17
+ * preset needs. Each consumer adds them to its own team schema with
18
+ * {@link addTeamDirectoryFields}, or spreads {@link teamDirectorySchemaDefinition}.
19
+ *
20
+ * ## Canon
21
+ *
22
+ * Prototype `origin/main` @ `c658d6f7`:
23
+ * - `KICKOFF_SHARE_EDGE_CONVERGENCE_2026-09-29.md` § 2.8 L254-257: the intake
24
+ * team is resolved from the sending program's `can_refer_to` targets
25
+ * first, then from the default-share-team ladder restricted to PAVE teams.
26
+ * A referral to intake never routes back to the sender.
27
+ * - Monolith `HTI-LEADS-PAVE-Thread-prototype.html` L323796-323832
28
+ * (`resolveIntakeTeamMono`), directory `programs[]` L142246-142431 and
29
+ * `teams[]` from L142584.
30
+ *
31
+ * Thread ADR: `docs/ADR-THREAD-PAVE-CASESHARE-CONVERGENCE.md` D1 and staging
32
+ * row .2 (consumer th-ng838.2). PAVE consumer: pv-p6share-thread-ingest-v4.
33
+ *
34
+ * ## Divergences from canon (deliberate)
35
+ *
36
+ * 1. **`apps`, not `apps_used`.** Canon's team rows carry lowercase
37
+ * `apps_used` (`"pave"`). The live platform-db writers already stamp
38
+ * `apps` with the uppercase {@link PLATFORM_TOOL} codes on agencies,
39
+ * accounts, users and teams (platform `lib/sync/upserts.ts`,
40
+ * `$addToSet: { apps: APP }` with `APP = source.toUpperCase()`). This
41
+ * field matches that convention exactly.
42
+ * 2. **`canReferTo` lives on the team.** Canon carries `can_refer_to` on a
43
+ * first-class PROGRAM row (`programs[]`, one `team_id` per program), and
44
+ * its targets are PROGRAM ids. No Program model exists in this package or
45
+ * in platform-db, so the targets are carried here as TEAM ids on the
46
+ * sending team. Canon's resolver maps each target program to its single
47
+ * team before using it, so the resolved team is the same. If a Program
48
+ * model lands later, `canReferTo` should move onto it.
49
+ */
50
+
51
+ import { Schema } from "mongoose";
52
+ import type { InferRawDocType } from "mongoose";
53
+ import { PLATFORM_TOOL_VALUES } from "../constants/platform-auth.js";
54
+
55
+ /** Mongoose model name every app registers the `teams` collection under. */
56
+ export const TEAM_MODEL_NAME = "Team" as const;
57
+
58
+ // ─── Schema Definition ──────────────────────────────────────────────
59
+
60
+ /**
61
+ * The directory fields to add to a team schema.
62
+ *
63
+ * Both are OPTIONAL and default to `undefined`, not `[]`. A team document
64
+ * written before these fields existed hydrates and re-saves without gaining
65
+ * an `apps` or `canReferTo` key. That keeps "not declared" (absent) distinct
66
+ * from "declared empty" (`[]`).
67
+ */
68
+ export const teamDirectorySchemaDefinition = {
69
+ /**
70
+ * The platform apps this team works in, as {@link PLATFORM_TOOL} codes
71
+ * (`"PAVE"`, `"THREAD"`, `"LEADS"`, ...). The referral preset only resolves
72
+ * to a team whose `apps` includes `"PAVE"`.
73
+ */
74
+ apps: {
75
+ type: [String],
76
+ enum: [...PLATFORM_TOOL_VALUES],
77
+ default: undefined,
78
+ },
79
+ /**
80
+ * The teams this team refers to, in priority order. The resolver takes the
81
+ * first active target that works in PAVE and is not the sending team itself.
82
+ */
83
+ canReferTo: {
84
+ type: [{ type: Schema.Types.ObjectId, ref: TEAM_MODEL_NAME }],
85
+ default: undefined,
86
+ },
87
+ };
88
+
89
+ // ─── Schema Helper ──────────────────────────────────────────────────
90
+
91
+ /**
92
+ * Add the team directory fields to an existing team schema.
93
+ *
94
+ * Adds no indexes and no hooks. Indexes on the shared `teams` collection
95
+ * stay with the collection's owner.
96
+ *
97
+ * @param schema - The consumer's team schema
98
+ * @returns The same schema, for chaining
99
+ */
100
+ export function addTeamDirectoryFields<S extends Schema>(schema: S): S {
101
+ schema.add(teamDirectorySchemaDefinition);
102
+ return schema;
103
+ }
104
+
105
+ // ─── Type Inference ─────────────────────────────────────────────────
106
+
107
+ /**
108
+ * Raw (persistence) shape of the team directory fields: `apps` as
109
+ * `PlatformToolValue[]`, `canReferTo` as `ObjectId[]`.
110
+ *
111
+ * Inferred from the DEFINITION, not from a compiled `Schema`: given a
112
+ * `Schema` instance, `InferRawDocType` resolves to the Schema object's own
113
+ * members rather than the document fields. Wrapped in `Partial` because both
114
+ * fields are absent on documents that predate them.
115
+ */
116
+ export type TeamDirectoryFields = Partial<
117
+ InferRawDocType<typeof teamDirectorySchemaDefinition>
118
+ >;
@@ -14,3 +14,4 @@
14
14
 
15
15
  export * from "./cvc.js";
16
16
  export * from "./cvcStatus.js";
17
+ export * from "./team.js";
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @htilabs/platform-common-models — Team directory field validation
3
+ *
4
+ * Zod schemas for the team directory fields declared in
5
+ * `../schemas/team.ts`, the fields the Thread→PAVE "Refer to intake" preset
6
+ * reads. See that module for canon citations and the two deliberate
7
+ * divergences (`apps` uses the {@link PLATFORM_TOOL} codes, and `canReferTo`
8
+ * sits on the team because there is no Program model).
9
+ *
10
+ * This is the wire / API shape: ids are 24-hex strings, not ObjectIds. Merge
11
+ * {@link TeamDirectoryFieldsSchema} into a consumer's team schema with
12
+ * `.merge()` or `.extend(TeamDirectoryFieldsSchema.shape)`.
13
+ */
14
+
15
+ import { z } from "zod";
16
+ import { PLATFORM_TOOL_VALUES } from "../constants/platform-auth.js";
17
+
18
+ /** A Mongo ObjectId serialized as a 24-character hex string. */
19
+ const ObjectIdHexSchema = z
20
+ .string()
21
+ .regex(/^[0-9a-fA-F]{24}$/, "must be a 24-character hex ObjectId");
22
+
23
+ const hasNoDuplicates = (values: readonly string[]): boolean =>
24
+ new Set(values.map((v) => v.toLowerCase())).size === values.length;
25
+
26
+ /** One platform app a team works in: a {@link PLATFORM_TOOL} code. */
27
+ export const TeamAppSchema = z.enum(PLATFORM_TOOL_VALUES);
28
+
29
+ /**
30
+ * The team directory fields. Both are optional, so a team payload without
31
+ * them validates unchanged. When present, neither list may repeat a value.
32
+ */
33
+ export const TeamDirectoryFieldsSchema = z.object({
34
+ apps: z
35
+ .array(TeamAppSchema)
36
+ .refine(hasNoDuplicates, "apps must not repeat an app")
37
+ .optional(),
38
+ canReferTo: z
39
+ .array(ObjectIdHexSchema)
40
+ .refine(hasNoDuplicates, "canReferTo must not repeat a team")
41
+ .optional(),
42
+ });
43
+
44
+ /** A platform app code accepted on a team. */
45
+ export type TeamApp = z.infer<typeof TeamAppSchema>;
46
+
47
+ /** Wire shape of the team directory fields (ids as hex strings). */
48
+ export type TeamDirectoryFieldsInput = z.infer<typeof TeamDirectoryFieldsSchema>;