@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.
- package/dist/cvcs/index.cjs +170 -21
- package/dist/cvcs/index.cjs.map +1 -1
- package/dist/cvcs/index.d.cts +182 -27
- package/dist/cvcs/index.d.ts +182 -27
- package/dist/cvcs/index.js +170 -21
- package/dist/cvcs/index.js.map +1 -1
- package/dist/enums/index.cjs +2 -0
- package/dist/enums/index.cjs.map +1 -1
- package/dist/enums/index.d.cts +5 -3
- package/dist/enums/index.d.ts +5 -3
- package/dist/enums/index.js +2 -0
- package/dist/enums/index.js.map +1 -1
- package/dist/{index-4DiJrn7y.d.ts → index-C0J3f169.d.ts} +1 -1
- package/dist/{index-qreOzXYS.d.cts → index-EPjPjR0z.d.cts} +1 -1
- package/dist/index.cjs +227 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +222 -28
- package/dist/index.js.map +1 -1
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/schemas/index.cjs +41 -7
- package/dist/schemas/index.cjs.map +1 -1
- package/dist/schemas/index.d.cts +130 -26
- package/dist/schemas/index.d.ts +130 -26
- package/dist/schemas/index.js +38 -7
- package/dist/schemas/index.js.map +1 -1
- package/dist/{cvc-Cp4uWnAa.d.cts → team-C4LJ5Tex.d.cts} +36 -1
- package/dist/{cvc-Cp4uWnAa.d.ts → team-C4LJ5Tex.d.ts} +36 -1
- package/dist/validation/index.cjs +155 -0
- package/dist/validation/index.cjs.map +1 -1
- package/dist/validation/index.d.cts +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +153 -0
- package/dist/validation/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/__snapshots__/cvc-sot.snap +5 -1
- package/src/__tests__/core-information-scope-invariant.test.ts +179 -2
- package/src/__tests__/cvc-sot-snapshot.test.ts +10 -0
- package/src/__tests__/cvc-structural.test.ts +3 -0
- package/src/__tests__/location-type-routing-invariant.test.ts +202 -0
- package/src/__tests__/team-directory-fields.test.ts +252 -0
- package/src/cvcs/coreInformationScope.v1.0.0.json +39 -5
- package/src/cvcs/index.ts +3 -0
- package/src/cvcs/locationType.v1.0.0.json +131 -16
- package/src/generated/cvc-enums.ts +5 -3
- package/src/index.ts +7 -0
- package/src/schemas/index.ts +8 -0
- package/src/schemas/team.ts +118 -0
- package/src/validation/index.ts +1 -0
- package/src/validation/team.ts +48 -0
- package/dist/{cvcEntry-ctHTp2df.d.cts → cvcEntry-DaDrEuTa.d.cts} +8 -8
- package/dist/{cvcEntry-ctHTp2df.d.ts → cvcEntry-DaDrEuTa.d.ts} +8 -8
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"domain": "location_type",
|
|
3
3
|
"name": "Core Location Type",
|
|
4
4
|
"version": "1.0.0",
|
|
5
|
+
"_source": "Rows: hand-authored 2026-04-22 from the April Notion codebook export (co-8ff.5.12); codes, keys, titles and definitions are unchanged since. LOGIC columns (tier · anchors · anchorDefault · shareUnit · safetyDefault): htilabstech/prototype/data/cvcs/core_location_type.yaml @ 55088d44 (CVC-191 v1.1, logic amended 2026-10-01; read from origin/main; cross-checked against htilabstech/prototype/Final CVCs/Location (IC-4)/core - location_type — codebook 1.csv + 2.csv @ 55088d44), overlaid by scripts/gen-location-type.py. NOT absorbed: 8 canon rows the package does not publish (TRAFFICKING_OCCURRENCE, VICTIM_IDENTIFICATION, COMMERCIAL_SEX_AD_POSTING, TRAFFICKING_RECRUITMENT, BIRTHPLACE, COURT_LOCATION, LE_INTERVIEW_LOCATION, LE_AGENCY_LOCATION) and the 4 labels canon reworded on 2026-08-28.",
|
|
5
6
|
"levels": {
|
|
6
7
|
"0": "Unknown or Missing",
|
|
7
8
|
"1": "Category"
|
|
@@ -27,7 +28,12 @@
|
|
|
27
28
|
"selectable": true,
|
|
28
29
|
"parentCode": "191-000-000-000-000-000-000",
|
|
29
30
|
"childCodes": [],
|
|
30
|
-
"definition": "Unknown or cannot be determined from the available information."
|
|
31
|
+
"definition": "Unknown or cannot be determined from the available information.",
|
|
32
|
+
"tier": "sentinel",
|
|
33
|
+
"anchors": [],
|
|
34
|
+
"anchorDefault": null,
|
|
35
|
+
"shareUnit": null,
|
|
36
|
+
"safetyDefault": null
|
|
31
37
|
},
|
|
32
38
|
{
|
|
33
39
|
"code": "191-000-000-000-000-000-002",
|
|
@@ -36,7 +42,12 @@
|
|
|
36
42
|
"selectable": true,
|
|
37
43
|
"parentCode": "191-000-000-000-000-000-000",
|
|
38
44
|
"childCodes": [],
|
|
39
|
-
"definition": "Information may be withheld by preference or due to redaction; identity is anonymous or redacted."
|
|
45
|
+
"definition": "Information may be withheld by preference or due to redaction; identity is anonymous or redacted.",
|
|
46
|
+
"tier": "sentinel",
|
|
47
|
+
"anchors": [],
|
|
48
|
+
"anchorDefault": null,
|
|
49
|
+
"shareUnit": null,
|
|
50
|
+
"safetyDefault": null
|
|
40
51
|
},
|
|
41
52
|
{
|
|
42
53
|
"code": "191-000-000-000-000-000-003",
|
|
@@ -45,7 +56,12 @@
|
|
|
45
56
|
"selectable": true,
|
|
46
57
|
"parentCode": "191-000-000-000-000-000-000",
|
|
47
58
|
"childCodes": [],
|
|
48
|
-
"definition": "No attempt was made to collect the information."
|
|
59
|
+
"definition": "No attempt was made to collect the information.",
|
|
60
|
+
"tier": "sentinel",
|
|
61
|
+
"anchors": [],
|
|
62
|
+
"anchorDefault": null,
|
|
63
|
+
"shareUnit": null,
|
|
64
|
+
"safetyDefault": null
|
|
49
65
|
},
|
|
50
66
|
{
|
|
51
67
|
"code": "191-001-000-000-000-000-000",
|
|
@@ -54,7 +70,14 @@
|
|
|
54
70
|
"selectable": true,
|
|
55
71
|
"parentCode": null,
|
|
56
72
|
"childCodes": [],
|
|
57
|
-
"definition": "Where the client/person currently resides (residential location)."
|
|
73
|
+
"definition": "Where the client/person currently resides (residential location).",
|
|
74
|
+
"tier": "residence",
|
|
75
|
+
"anchors": [
|
|
76
|
+
"person"
|
|
77
|
+
],
|
|
78
|
+
"anchorDefault": "person",
|
|
79
|
+
"shareUnit": "addresses",
|
|
80
|
+
"safetyDefault": "ask"
|
|
58
81
|
},
|
|
59
82
|
{
|
|
60
83
|
"code": "191-002-000-000-000-000-000",
|
|
@@ -63,7 +86,16 @@
|
|
|
63
86
|
"selectable": true,
|
|
64
87
|
"parentCode": null,
|
|
65
88
|
"childCodes": [],
|
|
66
|
-
"definition": "The physical site where a service instance was delivered (office, outreach site, partner site, on-scene)."
|
|
89
|
+
"definition": "The physical site where a service instance was delivered (office, outreach site, partner site, on-scene).",
|
|
90
|
+
"tier": "service",
|
|
91
|
+
"anchors": [
|
|
92
|
+
"service_instance",
|
|
93
|
+
"agency_program",
|
|
94
|
+
"person"
|
|
95
|
+
],
|
|
96
|
+
"anchorDefault": "service_instance",
|
|
97
|
+
"shareUnit": "service_history",
|
|
98
|
+
"safetyDefault": "ask"
|
|
67
99
|
},
|
|
68
100
|
{
|
|
69
101
|
"code": "191-003-000-000-000-000-000",
|
|
@@ -72,7 +104,14 @@
|
|
|
72
104
|
"selectable": true,
|
|
73
105
|
"parentCode": null,
|
|
74
106
|
"childCodes": [],
|
|
75
|
-
"definition": "Where the client/victim/caller is physically located at the time of contact or service (operational safety location)."
|
|
107
|
+
"definition": "Where the client/victim/caller is physically located at the time of contact or service (operational safety location).",
|
|
108
|
+
"tier": "encounter",
|
|
109
|
+
"anchors": [
|
|
110
|
+
"person"
|
|
111
|
+
],
|
|
112
|
+
"anchorDefault": "person",
|
|
113
|
+
"shareUnit": "addresses",
|
|
114
|
+
"safetyDefault": "ask"
|
|
76
115
|
},
|
|
77
116
|
{
|
|
78
117
|
"code": "191-004-000-000-000-000-000",
|
|
@@ -81,7 +120,16 @@
|
|
|
81
120
|
"selectable": true,
|
|
82
121
|
"parentCode": null,
|
|
83
122
|
"childCodes": [],
|
|
84
|
-
"definition": "A location where an in-person meeting/contact/event occurred (e.g., meet location, arrest location, outreach contact site)."
|
|
123
|
+
"definition": "A location where an in-person meeting/contact/event occurred (e.g., meet location, arrest location, outreach contact site).",
|
|
124
|
+
"tier": "encounter",
|
|
125
|
+
"anchors": [
|
|
126
|
+
"session",
|
|
127
|
+
"event",
|
|
128
|
+
"person"
|
|
129
|
+
],
|
|
130
|
+
"anchorDefault": "session",
|
|
131
|
+
"shareUnit": "encounter_location",
|
|
132
|
+
"safetyDefault": "ask"
|
|
85
133
|
},
|
|
86
134
|
{
|
|
87
135
|
"code": "191-005-000-000-000-000-000",
|
|
@@ -90,7 +138,14 @@
|
|
|
90
138
|
"selectable": true,
|
|
91
139
|
"parentCode": null,
|
|
92
140
|
"childCodes": [],
|
|
93
|
-
"definition": "Where the client/person previously resided (historical residential location)."
|
|
141
|
+
"definition": "Where the client/person previously resided (historical residential location).",
|
|
142
|
+
"tier": "residence",
|
|
143
|
+
"anchors": [
|
|
144
|
+
"person"
|
|
145
|
+
],
|
|
146
|
+
"anchorDefault": "person",
|
|
147
|
+
"shareUnit": "addresses",
|
|
148
|
+
"safetyDefault": "ask"
|
|
94
149
|
},
|
|
95
150
|
{
|
|
96
151
|
"code": "191-006-000-000-000-000-000",
|
|
@@ -99,7 +154,14 @@
|
|
|
99
154
|
"selectable": true,
|
|
100
155
|
"parentCode": null,
|
|
101
156
|
"childCodes": [],
|
|
102
|
-
"definition": "A location used to determine jurisdiction, eligibility, or referral routing (e.g., county, city, CoC code, service area)."
|
|
157
|
+
"definition": "A location used to determine jurisdiction, eligibility, or referral routing (e.g., county, city, CoC code, service area).",
|
|
158
|
+
"tier": "encounter",
|
|
159
|
+
"anchors": [
|
|
160
|
+
"person"
|
|
161
|
+
],
|
|
162
|
+
"anchorDefault": "person",
|
|
163
|
+
"shareUnit": "addresses",
|
|
164
|
+
"safetyDefault": "ask"
|
|
103
165
|
},
|
|
104
166
|
{
|
|
105
167
|
"code": "191-007-000-000-000-000-000",
|
|
@@ -108,7 +170,14 @@
|
|
|
108
170
|
"selectable": true,
|
|
109
171
|
"parentCode": null,
|
|
110
172
|
"childCodes": [],
|
|
111
|
-
"definition": "A location inferred from ads/postings (posting city/region/board) used for analytics such as base location, travel, and heat maps."
|
|
173
|
+
"definition": "A location inferred from ads/postings (posting city/region/board) used for analytics such as base location, travel, and heat maps.",
|
|
174
|
+
"tier": "derived",
|
|
175
|
+
"anchors": [
|
|
176
|
+
"person"
|
|
177
|
+
],
|
|
178
|
+
"anchorDefault": "person",
|
|
179
|
+
"shareUnit": "commercial_activity",
|
|
180
|
+
"safetyDefault": null
|
|
112
181
|
},
|
|
113
182
|
{
|
|
114
183
|
"code": "191-008-000-000-000-000-000",
|
|
@@ -117,7 +186,15 @@
|
|
|
117
186
|
"selectable": true,
|
|
118
187
|
"parentCode": null,
|
|
119
188
|
"childCodes": [],
|
|
120
|
-
"definition": "A location representing a travel instance or visit (part of a travel log/itinerary), with time bounds."
|
|
189
|
+
"definition": "A location representing a travel instance or visit (part of a travel log/itinerary), with time bounds.",
|
|
190
|
+
"tier": "encounter",
|
|
191
|
+
"anchors": [
|
|
192
|
+
"person",
|
|
193
|
+
"event"
|
|
194
|
+
],
|
|
195
|
+
"anchorDefault": "person",
|
|
196
|
+
"shareUnit": "addresses",
|
|
197
|
+
"safetyDefault": "ask"
|
|
121
198
|
},
|
|
122
199
|
{
|
|
123
200
|
"code": "191-009-000-000-000-000-000",
|
|
@@ -126,7 +203,14 @@
|
|
|
126
203
|
"selectable": true,
|
|
127
204
|
"parentCode": null,
|
|
128
205
|
"childCodes": [],
|
|
129
|
-
"definition": "A location associated with work, school, or business activity (legal or illicit), including known venues tied to an entity."
|
|
206
|
+
"definition": "A location associated with work, school, or business activity (legal or illicit), including known venues tied to an entity.",
|
|
207
|
+
"tier": "encounter",
|
|
208
|
+
"anchors": [
|
|
209
|
+
"person"
|
|
210
|
+
],
|
|
211
|
+
"anchorDefault": "person",
|
|
212
|
+
"shareUnit": "addresses",
|
|
213
|
+
"safetyDefault": "ask"
|
|
130
214
|
},
|
|
131
215
|
{
|
|
132
216
|
"code": "191-010-000-000-000-000-000",
|
|
@@ -135,7 +219,14 @@
|
|
|
135
219
|
"selectable": true,
|
|
136
220
|
"parentCode": null,
|
|
137
221
|
"childCodes": [],
|
|
138
|
-
"definition": "A location inferred from an IP address (geolocation-derived), used as a signal rather than a confirmed physical location."
|
|
222
|
+
"definition": "A location inferred from an IP address (geolocation-derived), used as a signal rather than a confirmed physical location.",
|
|
223
|
+
"tier": "derived",
|
|
224
|
+
"anchors": [
|
|
225
|
+
"person"
|
|
226
|
+
],
|
|
227
|
+
"anchorDefault": "person",
|
|
228
|
+
"shareUnit": "commercial_activity",
|
|
229
|
+
"safetyDefault": null
|
|
139
230
|
},
|
|
140
231
|
{
|
|
141
232
|
"code": "191-011-000-000-000-000-000",
|
|
@@ -144,7 +235,14 @@
|
|
|
144
235
|
"selectable": true,
|
|
145
236
|
"parentCode": null,
|
|
146
237
|
"childCodes": [],
|
|
147
|
-
"definition": "A location describing a program, shelter, project site, or provider location used for reporting (e.g., HMIS project descriptor)."
|
|
238
|
+
"definition": "A location describing a program, shelter, project site, or provider location used for reporting (e.g., HMIS project descriptor).",
|
|
239
|
+
"tier": "service",
|
|
240
|
+
"anchors": [
|
|
241
|
+
"agency_program"
|
|
242
|
+
],
|
|
243
|
+
"anchorDefault": "agency_program",
|
|
244
|
+
"shareUnit": null,
|
|
245
|
+
"safetyDefault": "safe"
|
|
148
246
|
},
|
|
149
247
|
{
|
|
150
248
|
"code": "191-012-000-000-000-000-000",
|
|
@@ -153,7 +251,16 @@
|
|
|
153
251
|
"selectable": true,
|
|
154
252
|
"parentCode": null,
|
|
155
253
|
"childCodes": [],
|
|
156
|
-
"definition": "A catch-all value used when none of the defined location types apply or when the role/context is unclear."
|
|
254
|
+
"definition": "A catch-all value used when none of the defined location types apply or when the role/context is unclear.",
|
|
255
|
+
"tier": "encounter",
|
|
256
|
+
"anchors": [
|
|
257
|
+
"person",
|
|
258
|
+
"session",
|
|
259
|
+
"event"
|
|
260
|
+
],
|
|
261
|
+
"anchorDefault": "person",
|
|
262
|
+
"shareUnit": "addresses",
|
|
263
|
+
"safetyDefault": "ask"
|
|
157
264
|
},
|
|
158
265
|
{
|
|
159
266
|
"code": "191-013-000-000-000-000-000",
|
|
@@ -162,7 +269,15 @@
|
|
|
162
269
|
"selectable": true,
|
|
163
270
|
"parentCode": null,
|
|
164
271
|
"childCodes": [],
|
|
165
|
-
"definition": "Location associated with an incident (e.g., where an event occurred, was reported, or was investigated), distinct from current residence, jurisdiction/routing, or service delivery context."
|
|
272
|
+
"definition": "Location associated with an incident (e.g., where an event occurred, was reported, or was investigated), distinct from current residence, jurisdiction/routing, or service delivery context.",
|
|
273
|
+
"tier": "encounter",
|
|
274
|
+
"anchors": [
|
|
275
|
+
"session",
|
|
276
|
+
"event"
|
|
277
|
+
],
|
|
278
|
+
"anchorDefault": "event",
|
|
279
|
+
"shareUnit": "encounter_location",
|
|
280
|
+
"safetyDefault": "ask"
|
|
166
281
|
}
|
|
167
282
|
]
|
|
168
283
|
}
|
|
@@ -1349,7 +1349,7 @@ export const EmploymentStatusKeys = {
|
|
|
1349
1349
|
export type EmploymentStatusKey = keyof typeof EmploymentStatusKeys;
|
|
1350
1350
|
|
|
1351
1351
|
/**
|
|
1352
|
-
* Key → positional code map for the `location_type` CVC domain.
|
|
1352
|
+
* Key → positional code map for the `location_type` CVC domain (CVC-191). Each entry also carries canon's 2026-10-01 share-routing columns (`tier` · `anchors` · `anchorDefault` · `shareUnit` · `safetyDefault`, overlaid by scripts/gen-location-type.py): route a stored location by its reason's `shareUnit` (a `core_information_scope` key; null = never delivered), not by a hand-kept map.
|
|
1353
1353
|
*
|
|
1354
1354
|
* Domain: `location_type` · Version: 1.0.0 · Entries: 17
|
|
1355
1355
|
*/
|
|
@@ -4085,9 +4085,9 @@ export const NeedsAssessmentChangeTypeKeys = {
|
|
|
4085
4085
|
export type NeedsAssessmentChangeTypeKey = keyof typeof NeedsAssessmentChangeTypeKeys;
|
|
4086
4086
|
|
|
4087
4087
|
/**
|
|
4088
|
-
* Key → positional code map for the `core_information_scope` CVC domain (DRAFT-TEMPORARY; canonical CVC-236, 12 policy-grain CATEGORIES +
|
|
4088
|
+
* Key → positional code map for the `core_information_scope` CVC domain (DRAFT-TEMPORARY; canonical CVC-236, 12 policy-grain CATEGORIES + 56 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 56 units, with no renames, so adoption is additive and no stored ROI changes meaning).
|
|
4089
4089
|
*
|
|
4090
|
-
* Domain: `core_information_scope` · Version: 1.0.0 · Entries:
|
|
4090
|
+
* Domain: `core_information_scope` · Version: 1.0.0 · Entries: 72
|
|
4091
4091
|
*/
|
|
4092
4092
|
export const CoreInformationScopeKeys = {
|
|
4093
4093
|
missingness_root: "236-000-000-000-000-000-000",
|
|
@@ -4121,6 +4121,8 @@ export const CoreInformationScopeKeys = {
|
|
|
4121
4121
|
contact: "236-003-000-000-000-000-000",
|
|
4122
4122
|
contact_info: "236-003-001-000-000-000-000",
|
|
4123
4123
|
safe_locations: "236-003-002-000-000-000-000",
|
|
4124
|
+
priorities_safety: "236-003-003-000-000-000-000",
|
|
4125
|
+
encounter_location: "236-003-004-000-000-000-000",
|
|
4124
4126
|
services: "236-004-000-000-000-000-000",
|
|
4125
4127
|
contact_history: "236-004-001-000-000-000-000",
|
|
4126
4128
|
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
|
package/src/schemas/index.ts
CHANGED
|
@@ -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
|
+
>;
|
package/src/validation/index.ts
CHANGED
|
@@ -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>;
|
|
@@ -233,18 +233,18 @@ type SectionQuestionRef = InferRawDocType<typeof sectionQuestionRefSchema>;
|
|
|
233
233
|
declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
234
234
|
_id: false;
|
|
235
235
|
}, {
|
|
236
|
-
type: "tip" | "warning" | "prompt";
|
|
237
236
|
text: string;
|
|
238
|
-
}, mongoose.Document<unknown, {}, {
|
|
239
237
|
type: "tip" | "warning" | "prompt";
|
|
238
|
+
}, mongoose.Document<unknown, {}, {
|
|
240
239
|
text: string;
|
|
240
|
+
type: "tip" | "warning" | "prompt";
|
|
241
241
|
}, {
|
|
242
242
|
id: string;
|
|
243
243
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
244
244
|
_id: false;
|
|
245
245
|
}>> & Omit<{
|
|
246
|
-
type: "tip" | "warning" | "prompt";
|
|
247
246
|
text: string;
|
|
247
|
+
type: "tip" | "warning" | "prompt";
|
|
248
248
|
} & {
|
|
249
249
|
_id: mongoose.Types.ObjectId;
|
|
250
250
|
} & {
|
|
@@ -252,8 +252,8 @@ declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any
|
|
|
252
252
|
}, "id"> & {
|
|
253
253
|
id: string;
|
|
254
254
|
}, unknown, {
|
|
255
|
-
type: "tip" | "warning" | "prompt";
|
|
256
255
|
text: string;
|
|
256
|
+
type: "tip" | "warning" | "prompt";
|
|
257
257
|
} & {
|
|
258
258
|
_id: mongoose.Types.ObjectId;
|
|
259
259
|
} & {
|
|
@@ -294,18 +294,18 @@ declare const sectionSchemaDefinition: {
|
|
|
294
294
|
type: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
295
295
|
_id: false;
|
|
296
296
|
}, {
|
|
297
|
-
type: "tip" | "warning" | "prompt";
|
|
298
297
|
text: string;
|
|
299
|
-
}, mongoose.Document<unknown, {}, {
|
|
300
298
|
type: "tip" | "warning" | "prompt";
|
|
299
|
+
}, mongoose.Document<unknown, {}, {
|
|
301
300
|
text: string;
|
|
301
|
+
type: "tip" | "warning" | "prompt";
|
|
302
302
|
}, {
|
|
303
303
|
id: string;
|
|
304
304
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
305
305
|
_id: false;
|
|
306
306
|
}>> & Omit<{
|
|
307
|
-
type: "tip" | "warning" | "prompt";
|
|
308
307
|
text: string;
|
|
308
|
+
type: "tip" | "warning" | "prompt";
|
|
309
309
|
} & {
|
|
310
310
|
_id: mongoose.Types.ObjectId;
|
|
311
311
|
} & {
|
|
@@ -313,8 +313,8 @@ declare const sectionSchemaDefinition: {
|
|
|
313
313
|
}, "id"> & {
|
|
314
314
|
id: string;
|
|
315
315
|
}, unknown, {
|
|
316
|
-
type: "tip" | "warning" | "prompt";
|
|
317
316
|
text: string;
|
|
317
|
+
type: "tip" | "warning" | "prompt";
|
|
318
318
|
} & {
|
|
319
319
|
_id: mongoose.Types.ObjectId;
|
|
320
320
|
} & {
|
|
@@ -233,18 +233,18 @@ type SectionQuestionRef = InferRawDocType<typeof sectionQuestionRefSchema>;
|
|
|
233
233
|
declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
234
234
|
_id: false;
|
|
235
235
|
}, {
|
|
236
|
-
type: "tip" | "warning" | "prompt";
|
|
237
236
|
text: string;
|
|
238
|
-
}, mongoose.Document<unknown, {}, {
|
|
239
237
|
type: "tip" | "warning" | "prompt";
|
|
238
|
+
}, mongoose.Document<unknown, {}, {
|
|
240
239
|
text: string;
|
|
240
|
+
type: "tip" | "warning" | "prompt";
|
|
241
241
|
}, {
|
|
242
242
|
id: string;
|
|
243
243
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
244
244
|
_id: false;
|
|
245
245
|
}>> & Omit<{
|
|
246
|
-
type: "tip" | "warning" | "prompt";
|
|
247
246
|
text: string;
|
|
247
|
+
type: "tip" | "warning" | "prompt";
|
|
248
248
|
} & {
|
|
249
249
|
_id: mongoose.Types.ObjectId;
|
|
250
250
|
} & {
|
|
@@ -252,8 +252,8 @@ declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any
|
|
|
252
252
|
}, "id"> & {
|
|
253
253
|
id: string;
|
|
254
254
|
}, unknown, {
|
|
255
|
-
type: "tip" | "warning" | "prompt";
|
|
256
255
|
text: string;
|
|
256
|
+
type: "tip" | "warning" | "prompt";
|
|
257
257
|
} & {
|
|
258
258
|
_id: mongoose.Types.ObjectId;
|
|
259
259
|
} & {
|
|
@@ -294,18 +294,18 @@ declare const sectionSchemaDefinition: {
|
|
|
294
294
|
type: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
295
295
|
_id: false;
|
|
296
296
|
}, {
|
|
297
|
-
type: "tip" | "warning" | "prompt";
|
|
298
297
|
text: string;
|
|
299
|
-
}, mongoose.Document<unknown, {}, {
|
|
300
298
|
type: "tip" | "warning" | "prompt";
|
|
299
|
+
}, mongoose.Document<unknown, {}, {
|
|
301
300
|
text: string;
|
|
301
|
+
type: "tip" | "warning" | "prompt";
|
|
302
302
|
}, {
|
|
303
303
|
id: string;
|
|
304
304
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
305
305
|
_id: false;
|
|
306
306
|
}>> & Omit<{
|
|
307
|
-
type: "tip" | "warning" | "prompt";
|
|
308
307
|
text: string;
|
|
308
|
+
type: "tip" | "warning" | "prompt";
|
|
309
309
|
} & {
|
|
310
310
|
_id: mongoose.Types.ObjectId;
|
|
311
311
|
} & {
|
|
@@ -313,8 +313,8 @@ declare const sectionSchemaDefinition: {
|
|
|
313
313
|
}, "id"> & {
|
|
314
314
|
id: string;
|
|
315
315
|
}, unknown, {
|
|
316
|
-
type: "tip" | "warning" | "prompt";
|
|
317
316
|
text: string;
|
|
317
|
+
type: "tip" | "warning" | "prompt";
|
|
318
318
|
} & {
|
|
319
319
|
_id: mongoose.Types.ObjectId;
|
|
320
320
|
} & {
|