@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
|
@@ -295,4 +295,39 @@ declare function validateCvc(envelope: CvcEnvelope, options?: {
|
|
|
295
295
|
mechanismKeys?: ReadonlySet<string>;
|
|
296
296
|
}): CvcValidationError[];
|
|
297
297
|
|
|
298
|
-
|
|
298
|
+
/**
|
|
299
|
+
* @htilabs/platform-common-models — Team directory field validation
|
|
300
|
+
*
|
|
301
|
+
* Zod schemas for the team directory fields declared in
|
|
302
|
+
* `../schemas/team.ts`, the fields the Thread→PAVE "Refer to intake" preset
|
|
303
|
+
* reads. See that module for canon citations and the two deliberate
|
|
304
|
+
* divergences (`apps` uses the {@link PLATFORM_TOOL} codes, and `canReferTo`
|
|
305
|
+
* sits on the team because there is no Program model).
|
|
306
|
+
*
|
|
307
|
+
* This is the wire / API shape: ids are 24-hex strings, not ObjectIds. Merge
|
|
308
|
+
* {@link TeamDirectoryFieldsSchema} into a consumer's team schema with
|
|
309
|
+
* `.merge()` or `.extend(TeamDirectoryFieldsSchema.shape)`.
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
/** One platform app a team works in: a {@link PLATFORM_TOOL} code. */
|
|
313
|
+
declare const TeamAppSchema: z.ZodEnum<["PAVE", "ECHO", "LEADS", "THREAD", "TRAIL", "PLATFORM"]>;
|
|
314
|
+
/**
|
|
315
|
+
* The team directory fields. Both are optional, so a team payload without
|
|
316
|
+
* them validates unchanged. When present, neither list may repeat a value.
|
|
317
|
+
*/
|
|
318
|
+
declare const TeamDirectoryFieldsSchema: z.ZodObject<{
|
|
319
|
+
apps: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodEnum<["PAVE", "ECHO", "LEADS", "THREAD", "TRAIL", "PLATFORM"]>, "many">, ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[], ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[]>>;
|
|
320
|
+
canReferTo: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>>;
|
|
321
|
+
}, "strip", z.ZodTypeAny, {
|
|
322
|
+
apps?: ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[] | undefined;
|
|
323
|
+
canReferTo?: string[] | undefined;
|
|
324
|
+
}, {
|
|
325
|
+
apps?: ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[] | undefined;
|
|
326
|
+
canReferTo?: string[] | undefined;
|
|
327
|
+
}>;
|
|
328
|
+
/** A platform app code accepted on a team. */
|
|
329
|
+
type TeamApp = z.infer<typeof TeamAppSchema>;
|
|
330
|
+
/** Wire shape of the team directory fields (ids as hex strings). */
|
|
331
|
+
type TeamDirectoryFieldsInput = z.infer<typeof TeamDirectoryFieldsSchema>;
|
|
332
|
+
|
|
333
|
+
export { type CvcCode as C, type PrimaryLanguageEntry as P, type ServiceCategoryEntry as S, type TeamApp as T, CvcCodeSchema as a, type CvcDomain as b, CvcEntrySchema as c, type CvcEnvelope as d, CvcEnvelopeSchema as e, type CvcKey as f, CvcKeySchema as g, ServiceCategoryEntrySchema as h, TeamAppSchema as i, type TeamDirectoryFieldsInput as j, TeamDirectoryFieldsSchema as k, type CvcEntry as l, type CvcValidationError as m, PrimaryLanguageEntrySchema as n, getCvcLevel as o, validateCvc as v };
|
|
@@ -295,4 +295,39 @@ declare function validateCvc(envelope: CvcEnvelope, options?: {
|
|
|
295
295
|
mechanismKeys?: ReadonlySet<string>;
|
|
296
296
|
}): CvcValidationError[];
|
|
297
297
|
|
|
298
|
-
|
|
298
|
+
/**
|
|
299
|
+
* @htilabs/platform-common-models — Team directory field validation
|
|
300
|
+
*
|
|
301
|
+
* Zod schemas for the team directory fields declared in
|
|
302
|
+
* `../schemas/team.ts`, the fields the Thread→PAVE "Refer to intake" preset
|
|
303
|
+
* reads. See that module for canon citations and the two deliberate
|
|
304
|
+
* divergences (`apps` uses the {@link PLATFORM_TOOL} codes, and `canReferTo`
|
|
305
|
+
* sits on the team because there is no Program model).
|
|
306
|
+
*
|
|
307
|
+
* This is the wire / API shape: ids are 24-hex strings, not ObjectIds. Merge
|
|
308
|
+
* {@link TeamDirectoryFieldsSchema} into a consumer's team schema with
|
|
309
|
+
* `.merge()` or `.extend(TeamDirectoryFieldsSchema.shape)`.
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
/** One platform app a team works in: a {@link PLATFORM_TOOL} code. */
|
|
313
|
+
declare const TeamAppSchema: z.ZodEnum<["PAVE", "ECHO", "LEADS", "THREAD", "TRAIL", "PLATFORM"]>;
|
|
314
|
+
/**
|
|
315
|
+
* The team directory fields. Both are optional, so a team payload without
|
|
316
|
+
* them validates unchanged. When present, neither list may repeat a value.
|
|
317
|
+
*/
|
|
318
|
+
declare const TeamDirectoryFieldsSchema: z.ZodObject<{
|
|
319
|
+
apps: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodEnum<["PAVE", "ECHO", "LEADS", "THREAD", "TRAIL", "PLATFORM"]>, "many">, ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[], ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[]>>;
|
|
320
|
+
canReferTo: z.ZodOptional<z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>>;
|
|
321
|
+
}, "strip", z.ZodTypeAny, {
|
|
322
|
+
apps?: ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[] | undefined;
|
|
323
|
+
canReferTo?: string[] | undefined;
|
|
324
|
+
}, {
|
|
325
|
+
apps?: ("THREAD" | "PAVE" | "ECHO" | "LEADS" | "TRAIL" | "PLATFORM")[] | undefined;
|
|
326
|
+
canReferTo?: string[] | undefined;
|
|
327
|
+
}>;
|
|
328
|
+
/** A platform app code accepted on a team. */
|
|
329
|
+
type TeamApp = z.infer<typeof TeamAppSchema>;
|
|
330
|
+
/** Wire shape of the team directory fields (ids as hex strings). */
|
|
331
|
+
type TeamDirectoryFieldsInput = z.infer<typeof TeamDirectoryFieldsSchema>;
|
|
332
|
+
|
|
333
|
+
export { type CvcCode as C, type PrimaryLanguageEntry as P, type ServiceCategoryEntry as S, type TeamApp as T, CvcCodeSchema as a, type CvcDomain as b, CvcEntrySchema as c, type CvcEnvelope as d, CvcEnvelopeSchema as e, type CvcKey as f, CvcKeySchema as g, ServiceCategoryEntrySchema as h, TeamAppSchema as i, type TeamDirectoryFieldsInput as j, TeamDirectoryFieldsSchema as k, type CvcEntry as l, type CvcValidationError as m, PrimaryLanguageEntrySchema as n, getCvcLevel as o, validateCvc as v };
|
|
@@ -26,6 +26,8 @@ __export(validation_exports, {
|
|
|
26
26
|
CvcKeySchema: () => CvcKeySchema,
|
|
27
27
|
PrimaryLanguageEntrySchema: () => PrimaryLanguageEntrySchema,
|
|
28
28
|
ServiceCategoryEntrySchema: () => ServiceCategoryEntrySchema,
|
|
29
|
+
TeamAppSchema: () => TeamAppSchema,
|
|
30
|
+
TeamDirectoryFieldsSchema: () => TeamDirectoryFieldsSchema,
|
|
29
31
|
getCvcLevel: () => getCvcLevel,
|
|
30
32
|
parseCvcStatus: () => parseCvcStatus,
|
|
31
33
|
validateCvc: () => validateCvc
|
|
@@ -303,6 +305,157 @@ function parseCvcStatus(envelope) {
|
|
|
303
305
|
const { maturity, ambiguous } = detectMaturity(text);
|
|
304
306
|
return { maturity, rawStatus: text, sourceIsPrototype, sourcePath, ambiguous };
|
|
305
307
|
}
|
|
308
|
+
|
|
309
|
+
// src/validation/team.ts
|
|
310
|
+
var import_zod2 = require("zod");
|
|
311
|
+
|
|
312
|
+
// src/constants/platform-auth.ts
|
|
313
|
+
var PERMISSION_STATE = {
|
|
314
|
+
/** Role can always perform this function (mandatory, cannot disable). */
|
|
315
|
+
ALWAYS: "ALWAYS",
|
|
316
|
+
/** Default On — user can opt off. */
|
|
317
|
+
PREF_YES: "PREF_YES",
|
|
318
|
+
/** Default Off — user can opt in. */
|
|
319
|
+
PREF_NO: "PREF_NO",
|
|
320
|
+
/** Role is explicitly barred from this function. */
|
|
321
|
+
NEVER: "NEVER"
|
|
322
|
+
};
|
|
323
|
+
var PERMISSION_STATE_VALUES = [
|
|
324
|
+
PERMISSION_STATE.ALWAYS,
|
|
325
|
+
PERMISSION_STATE.PREF_YES,
|
|
326
|
+
PERMISSION_STATE.PREF_NO,
|
|
327
|
+
PERMISSION_STATE.NEVER
|
|
328
|
+
];
|
|
329
|
+
var PERMISSION_STATE_LABELS = {
|
|
330
|
+
[PERMISSION_STATE.ALWAYS]: "Always",
|
|
331
|
+
[PERMISSION_STATE.PREF_YES]: "Default On",
|
|
332
|
+
[PERMISSION_STATE.PREF_NO]: "Default Off",
|
|
333
|
+
[PERMISSION_STATE.NEVER]: "Never"
|
|
334
|
+
};
|
|
335
|
+
var PERMISSION_STATE_DISPLAY = {
|
|
336
|
+
[PERMISSION_STATE.ALWAYS]: {
|
|
337
|
+
label: "Always",
|
|
338
|
+
color: "#2e7d32",
|
|
339
|
+
bgColor: "#e8f5e9",
|
|
340
|
+
icon: "\u{1F512}"
|
|
341
|
+
},
|
|
342
|
+
[PERMISSION_STATE.PREF_YES]: {
|
|
343
|
+
label: "Default On",
|
|
344
|
+
color: "#1565c0",
|
|
345
|
+
bgColor: "#e3f2fd",
|
|
346
|
+
icon: "\u{1F513}"
|
|
347
|
+
},
|
|
348
|
+
[PERMISSION_STATE.PREF_NO]: {
|
|
349
|
+
label: "Default Off",
|
|
350
|
+
color: "#e65100",
|
|
351
|
+
bgColor: "#fff3e0",
|
|
352
|
+
icon: "\u{1F513}"
|
|
353
|
+
},
|
|
354
|
+
[PERMISSION_STATE.NEVER]: {
|
|
355
|
+
label: "Never",
|
|
356
|
+
color: "#c62828",
|
|
357
|
+
bgColor: "#ffebee",
|
|
358
|
+
icon: "\u{1F512}"
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
var SHARE_VIEW = {
|
|
362
|
+
/** System metadata only (partial access). */
|
|
363
|
+
SYS_INFO: "sys_info",
|
|
364
|
+
/** Full case/record content. */
|
|
365
|
+
ALL: "all",
|
|
366
|
+
/** No data access. */
|
|
367
|
+
NONE: "none"
|
|
368
|
+
};
|
|
369
|
+
var SHARE_VIEW_VALUES = [
|
|
370
|
+
SHARE_VIEW.SYS_INFO,
|
|
371
|
+
SHARE_VIEW.ALL,
|
|
372
|
+
SHARE_VIEW.NONE
|
|
373
|
+
];
|
|
374
|
+
var SHARE_VIEW_LABELS = {
|
|
375
|
+
[SHARE_VIEW.SYS_INFO]: "System Info Only",
|
|
376
|
+
[SHARE_VIEW.ALL]: "Full Content",
|
|
377
|
+
[SHARE_VIEW.NONE]: "No Data Access"
|
|
378
|
+
};
|
|
379
|
+
var PLATFORM_TOOL = {
|
|
380
|
+
PAVE: "PAVE",
|
|
381
|
+
ECHO: "ECHO",
|
|
382
|
+
LEADS: "LEADS",
|
|
383
|
+
THREAD: "THREAD",
|
|
384
|
+
TRAIL: "TRAIL",
|
|
385
|
+
PLATFORM: "PLATFORM"
|
|
386
|
+
};
|
|
387
|
+
var PLATFORM_TOOL_VALUES = [
|
|
388
|
+
PLATFORM_TOOL.PAVE,
|
|
389
|
+
PLATFORM_TOOL.ECHO,
|
|
390
|
+
PLATFORM_TOOL.LEADS,
|
|
391
|
+
PLATFORM_TOOL.THREAD,
|
|
392
|
+
PLATFORM_TOOL.TRAIL,
|
|
393
|
+
PLATFORM_TOOL.PLATFORM
|
|
394
|
+
];
|
|
395
|
+
var PLATFORM_TOOL_LABELS = {
|
|
396
|
+
[PLATFORM_TOOL.PAVE]: "PAVE",
|
|
397
|
+
[PLATFORM_TOOL.ECHO]: "Echo",
|
|
398
|
+
[PLATFORM_TOOL.LEADS]: "LEADS",
|
|
399
|
+
[PLATFORM_TOOL.THREAD]: "Thread",
|
|
400
|
+
[PLATFORM_TOOL.TRAIL]: "Trail",
|
|
401
|
+
[PLATFORM_TOOL.PLATFORM]: "Platform"
|
|
402
|
+
};
|
|
403
|
+
var ROLE_LEVEL = {
|
|
404
|
+
/** User-facing roles (staff, volunteers, practitioners). */
|
|
405
|
+
OPERATIONAL: "operational",
|
|
406
|
+
/** Agency-level admin roles. */
|
|
407
|
+
AGENCY: "agency",
|
|
408
|
+
/** Team-level admin roles. */
|
|
409
|
+
TEAM: "team",
|
|
410
|
+
/** HTI-wide platform admin. */
|
|
411
|
+
PLATFORM: "platform",
|
|
412
|
+
/** External governance/oversight roles. */
|
|
413
|
+
OVERSIGHT: "oversight"
|
|
414
|
+
};
|
|
415
|
+
var ROLE_LEVEL_VALUES = [
|
|
416
|
+
ROLE_LEVEL.OPERATIONAL,
|
|
417
|
+
ROLE_LEVEL.AGENCY,
|
|
418
|
+
ROLE_LEVEL.TEAM,
|
|
419
|
+
ROLE_LEVEL.PLATFORM,
|
|
420
|
+
ROLE_LEVEL.OVERSIGHT
|
|
421
|
+
];
|
|
422
|
+
var ROLE_LEVEL_LABELS = {
|
|
423
|
+
[ROLE_LEVEL.OPERATIONAL]: "Operational",
|
|
424
|
+
[ROLE_LEVEL.AGENCY]: "Agency",
|
|
425
|
+
[ROLE_LEVEL.TEAM]: "Team",
|
|
426
|
+
[ROLE_LEVEL.PLATFORM]: "Platform",
|
|
427
|
+
[ROLE_LEVEL.OVERSIGHT]: "Oversight"
|
|
428
|
+
};
|
|
429
|
+
var FUNCTION_STATUS = {
|
|
430
|
+
NOT_STARTED: "Not started",
|
|
431
|
+
DEFINED_NEW: "Defined; new function",
|
|
432
|
+
DEFINED_EXISTING: "Defined; existing PAVE function",
|
|
433
|
+
FUNCTIONAL: "Functional on all apps",
|
|
434
|
+
FUTURE: "Future function (not v1)"
|
|
435
|
+
};
|
|
436
|
+
var FUNCTION_STATUS_VALUES = [
|
|
437
|
+
FUNCTION_STATUS.NOT_STARTED,
|
|
438
|
+
FUNCTION_STATUS.DEFINED_NEW,
|
|
439
|
+
FUNCTION_STATUS.DEFINED_EXISTING,
|
|
440
|
+
FUNCTION_STATUS.FUNCTIONAL,
|
|
441
|
+
FUNCTION_STATUS.FUTURE
|
|
442
|
+
];
|
|
443
|
+
var FUNCTION_STATUS_LABELS = {
|
|
444
|
+
[FUNCTION_STATUS.NOT_STARTED]: "Not Started",
|
|
445
|
+
[FUNCTION_STATUS.DEFINED_NEW]: "Defined (New)",
|
|
446
|
+
[FUNCTION_STATUS.DEFINED_EXISTING]: "Defined (Existing PAVE)",
|
|
447
|
+
[FUNCTION_STATUS.FUNCTIONAL]: "Functional",
|
|
448
|
+
[FUNCTION_STATUS.FUTURE]: "Future (Not v1)"
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/validation/team.ts
|
|
452
|
+
var ObjectIdHexSchema = import_zod2.z.string().regex(/^[0-9a-fA-F]{24}$/, "must be a 24-character hex ObjectId");
|
|
453
|
+
var hasNoDuplicates = (values) => new Set(values.map((v) => v.toLowerCase())).size === values.length;
|
|
454
|
+
var TeamAppSchema = import_zod2.z.enum(PLATFORM_TOOL_VALUES);
|
|
455
|
+
var TeamDirectoryFieldsSchema = import_zod2.z.object({
|
|
456
|
+
apps: import_zod2.z.array(TeamAppSchema).refine(hasNoDuplicates, "apps must not repeat an app").optional(),
|
|
457
|
+
canReferTo: import_zod2.z.array(ObjectIdHexSchema).refine(hasNoDuplicates, "canReferTo must not repeat a team").optional()
|
|
458
|
+
});
|
|
306
459
|
// Annotate the CommonJS export names for ESM import in node:
|
|
307
460
|
0 && (module.exports = {
|
|
308
461
|
CvcCodeSchema,
|
|
@@ -311,6 +464,8 @@ function parseCvcStatus(envelope) {
|
|
|
311
464
|
CvcKeySchema,
|
|
312
465
|
PrimaryLanguageEntrySchema,
|
|
313
466
|
ServiceCategoryEntrySchema,
|
|
467
|
+
TeamAppSchema,
|
|
468
|
+
TeamDirectoryFieldsSchema,
|
|
314
469
|
getCvcLevel,
|
|
315
470
|
parseCvcStatus,
|
|
316
471
|
validateCvc
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/validation/index.ts","../../src/validation/cvc.ts","../../src/validation/cvcStatus.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models — Validation barrel\n *\n * Public entry point for the Zod validation surface. Consumers that want\n * the canonical Zod-inferred `CvcEntry` (rather than the Mongoose persistence\n * shape exported from the package root) should import from here:\n *\n * ```ts\n * import { CvcEntry, CvcEntrySchema } from '@htilabs/platform-common-models/validation';\n * ```\n *\n * See `./cvc.ts` for the schema and type definitions.\n */\n\nexport * from \"./cvc.js\";\nexport * from \"./cvcStatus.js\";\n","/**\n * @htilabs/platform-common-models — Controlled Vocabulary (CVC) Validation\n *\n * Zod schemas for validating CVC Source-of-Truth (SOT) JSON files and\n * individual CVC entries. Implements the locked spec §9.2 shapes.\n *\n * Used by:\n * - CI structural tests that parse every committed SOT file.\n * - The generalized seed CLI (`seedCvc`) prior to persistence.\n * - Downstream consumers that need to validate CVC payloads.\n *\n * Canonical spec:\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * Format v2 (2026-04-15):\n * - Positional 7-segment codes `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (3 digits per\n * segment). Segment 1 is the Notion-aligned domain prefix:\n * `022` service_categories (CVC-22)\n * `025` service_mechanisms (CVC-25)\n * `049` service_states (CVC-49)\n * - Missingness entries are embedded per-domain (synthetic `missingness_root`\n * at `<prefix>-000-000-000-000-000-000` plus three values at segment 7 =\n * `001`/`002`/`003`). The shared `missingness.v1.0.0.json` file was\n * retired in favor of per-domain missingness.\n * - Envelope `missingness` field and the C7 invariant have been removed; the\n * shared-merge pathway no longer exists.\n */\n\nimport { z } from \"zod\";\n\n// ─── Primitive schemas ───────────────────────────────────────────────────────\n\n/**\n * 7-segment positional CVC code: `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (three digits\n * per segment). Segment 1 is the Notion-aligned domain prefix. Remaining\n * hierarchy segments are filled left-to-right as levels deepen; unused\n * segments remain `000`. See locked spec §3 (format v2).\n */\nexport const CvcCodeSchema = z.string().regex(/^\\d{3}(-\\d{3}){6}$/);\n\n/**\n * Stable machine key for a CVC entry. Must start with a lowercase letter and\n * contain only lowercase alphanumerics or underscores. Used as a cross-CVC\n * reference target (e.g. `relevantMechanisms` pointing at mechanism keys).\n * See locked spec §3.2.\n */\nexport const CvcKeySchema = z.string().regex(/^[a-z][a-z0-9_]*$/);\n\n// ─── Entry schemas ───────────────────────────────────────────────────────────\n\n/**\n * Base entry shape shared by every CVC domain. Domain-specific extensions\n * (e.g. `ServiceCategoryEntrySchema`) should use `.extend()` to add fields.\n * See locked spec §9.2.\n *\n * Uses `.passthrough()` so that domain-specific fields (like\n * `relevantMechanisms` on service-category entries) survive base parsing\n * unmodified. This keeps cross-CVC reference validation honest: the §4.5\n * structural validator needs to see the raw referenced keys, and a strip-by-\n * default schema would silently hide them.\n */\nexport const CvcEntrySchema = z\n .object({\n code: CvcCodeSchema,\n key: CvcKeySchema,\n title: z.string().min(1),\n selectable: z.boolean(),\n parentCode: CvcCodeSchema.nullable(),\n childCodes: z.array(CvcCodeSchema),\n definition: z.string().nullable(),\n })\n .passthrough();\n\n/**\n * Service-category-specific entry. Adds `relevantMechanisms` — a cross-CVC\n * reference into the `service_mechanisms` domain via entry keys. `null` means\n * \"not applicable\" (e.g. structural L1 topic rows). See locked spec §9.2.\n */\nexport const ServiceCategoryEntrySchema = CvcEntrySchema.extend({\n relevantMechanisms: z.array(CvcKeySchema).nullable(),\n});\n\n/**\n * Primary-language-specific entry. Adds:\n * - `iso6391Code` — the ISO 639-1 alpha-2 code for the language, or `null`\n * for entries without an ISO 639-1 code (missingness entries, Chinese\n * varieties Mandarin/Cantonese, `other_language`). ASL is stored as\n * `\"ase\"` (ISO 639-3) per Notion's convention; the CVC header documents\n * this caveat.\n * - `priority` — `true` for front-end short-list entries (14 total in\n * CVC-122: 13 L1 languages plus the canonical `unknown` missingness\n * entry). See locked spec §9.2.\n */\nexport const PrimaryLanguageEntrySchema = CvcEntrySchema.extend({\n iso6391Code: z.string().nullable(),\n priority: z.boolean(),\n});\n\n// ─── Envelope schema ─────────────────────────────────────────────────────────\n\n/**\n * Top-level SOT JSON envelope. One envelope per (domain, version) pair.\n *\n * `levels` is a positional map from level number (`\"0\"`, `\"1\"`, …) to a human\n * label describing the level. Missingness entries are embedded in `entries`\n * (per-domain) rather than merged in from a shared SOT file; see module\n * header for the v2 format summary.\n */\nexport const CvcEnvelopeSchema = z.object({\n domain: z.string().min(1),\n name: z.string().min(1),\n version: z.string().min(1),\n levels: z.record(z.string(), z.string()),\n entries: z.array(CvcEntrySchema),\n});\n\n// ─── Inferred types ──────────────────────────────────────────────────────────\n\nexport type CvcCode = z.infer<typeof CvcCodeSchema>;\nexport type CvcKey = z.infer<typeof CvcKeySchema>;\nexport type CvcEntry = z.infer<typeof CvcEntrySchema>;\nexport type ServiceCategoryEntry = z.infer<typeof ServiceCategoryEntrySchema>;\nexport type PrimaryLanguageEntry = z.infer<typeof PrimaryLanguageEntrySchema>;\nexport type CvcEnvelope = z.infer<typeof CvcEnvelopeSchema>;\n\n/**\n * SOT family identifier (e.g. `\"service_categories\"`, `\"service_states\"`,\n * `\"service_mechanisms\"`, `\"missingness\"`). The canonical list of domains is\n * enumerated by the SOT JSON files in `src/cvcs/`. Typed as `string` rather\n * than a closed union so adding a new SOT file does not require touching this\n * type. See locked spec §2.\n */\nexport type CvcDomain = string;\n\n// ─── Structural validator (locked spec §4 / §9.3) ───────────────────────────\n\n/**\n * Derive an entry's level from its 7-segment code per locked spec §3.3.\n *\n * - Segment 7 non-zero → level 0 (missingness value entry, e.g. `unknown`).\n * - Otherwise return the index (1..5) of the last non-zero hierarchy segment.\n * - Hierarchy segments 2..7 all zero → level 0 (per-domain missingness root,\n * e.g. `022-000-000-000-000-000-000`). Segment 1 carries the domain prefix\n * and is intentionally not consulted by the level derivation.\n */\nexport function getCvcLevel(code: string): number {\n const segments = code.split(\"-\");\n // segments[6] is the missingness slot (positional segment 7).\n if (segments[6] !== \"000\") return 0;\n // Walk hierarchy segments 6..2 (indices 5..1) looking for the deepest\n // populated level.\n for (let i = 5; i >= 1; i -= 1) {\n if (segments[i] !== \"000\") return i;\n }\n return 0;\n}\n\n/**\n * Error collected by {@link validateCvc}. Each error names the invariant it\n * violates (`C1`..`C8`, skipping the retired `C7`) so CI output points\n * straight at the locked spec rule that failed. `code` or `key` narrow the\n * error to a specific entry when the violation is entry-scoped.\n */\nexport interface CvcValidationError {\n invariant: \"C1\" | \"C2\" | \"C3\" | \"C4\" | \"C5\" | \"C6\" | \"C8\";\n message: string;\n code?: string;\n key?: string;\n}\n\n/**\n * Structural invariants to enforce on every committed SOT file per locked spec\n * §4. Zod's schema `parse()` guarantees the *shape* of the envelope; this\n * function enforces the cross-entry *semantics* that Zod cannot express.\n *\n * Invariants (locked spec §4):\n * - **C1** Code format + uniqueness (§4.1). Format v2 uses 3-digit segments.\n * - **C2** Key format + uniqueness (§4.2).\n * - **C3** Tree: every `parentCode` resolves to an existing entry or null; no\n * cycles (§4.3).\n * - **C4** `childCodes` are the exact bidirectional inverse of `parentCode`\n * (§4.3).\n * - **C5** Selectability is a boolean (§4.4).\n * - **C6** Cross-CVC `relevantMechanisms` references resolve against a\n * provided `service_mechanisms` key set (§4.5, §7). Only checked when the\n * caller supplies `options.mechanismKeys`.\n * - **C7** _Retired in format v2_ (envelope no longer carries the shared\n * `missingness` field; missingness is per-domain and embedded in\n * `entries`). The invariant slot is intentionally left empty to preserve\n * the numbering of C1/C2/C3/C4/C5/C6/C8 in historical references.\n * - **C8** No entry anywhere contains a key `'provided'` (legacy Thread UI\n * label guard; not a canonical state).\n *\n * @param envelope Parsed envelope (typically from `CvcEnvelopeSchema.parse()`).\n * @param options.mechanismKeys Optional set of valid `service_mechanisms`\n * entry keys. If provided and the envelope entries have `relevantMechanisms`\n * fields, each referenced key must be in this set (C6).\n * @returns An array of {@link CvcValidationError}. An empty array means valid.\n */\nexport function validateCvc(\n envelope: CvcEnvelope,\n options: { mechanismKeys?: ReadonlySet<string> } = {},\n): CvcValidationError[] {\n const errors: CvcValidationError[] = [];\n const { entries } = envelope;\n\n // ── C1: code format + uniqueness ──────────────────────────────────────────\n const codeRe = /^\\d{3}(-\\d{3}){6}$/;\n const seenCodes = new Set<string>();\n for (const entry of entries) {\n if (!codeRe.test(entry.code)) {\n errors.push({\n invariant: \"C1\",\n message: `code does not match /^\\\\d{3}(-\\\\d{3}){6}$/`,\n code: entry.code,\n key: entry.key,\n });\n }\n if (seenCodes.has(entry.code)) {\n errors.push({\n invariant: \"C1\",\n message: `duplicate code`,\n code: entry.code,\n key: entry.key,\n });\n }\n seenCodes.add(entry.code);\n }\n\n // ── C2: key format + uniqueness ───────────────────────────────────────────\n const keyRe = /^[a-z][a-z0-9_]*$/;\n const seenKeys = new Set<string>();\n for (const entry of entries) {\n if (!keyRe.test(entry.key)) {\n errors.push({\n invariant: \"C2\",\n message: `key does not match /^[a-z][a-z0-9_]*$/`,\n code: entry.code,\n key: entry.key,\n });\n }\n if (seenKeys.has(entry.key)) {\n errors.push({\n invariant: \"C2\",\n message: `duplicate key`,\n code: entry.code,\n key: entry.key,\n });\n }\n seenKeys.add(entry.key);\n }\n\n // Build a lookup by code for the remaining tree checks. Skip entries whose\n // code we already know is malformed — their index would be meaningless.\n const byCode = new Map<string, CvcEntry>();\n for (const entry of entries) {\n if (codeRe.test(entry.code)) byCode.set(entry.code, entry);\n }\n\n // ── C3: tree — parents resolve, no cycles ─────────────────────────────────\n for (const entry of entries) {\n if (entry.parentCode === null) continue;\n if (!byCode.has(entry.parentCode)) {\n errors.push({\n invariant: \"C3\",\n message: `parentCode ${entry.parentCode} does not resolve to any entry in this CVC`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n\n // Cycle detection: walk parent chain from each entry, bail if we revisit.\n for (const entry of entries) {\n const visited = new Set<string>();\n let cursor: CvcEntry | undefined = entry;\n while (cursor && cursor.parentCode !== null) {\n if (visited.has(cursor.code)) {\n errors.push({\n invariant: \"C3\",\n message: `cycle detected in parentCode chain starting from ${entry.code}`,\n code: entry.code,\n key: entry.key,\n });\n break;\n }\n visited.add(cursor.code);\n cursor = byCode.get(cursor.parentCode);\n }\n }\n\n // ── C4: childCodes are exact inverse of parentCode ────────────────────────\n // Build the set of (parent, child) edges from parentCode, then from\n // childCodes, and require they match exactly.\n const parentToChildrenFromParent = new Map<string, Set<string>>();\n for (const entry of entries) {\n if (entry.parentCode !== null) {\n let set = parentToChildrenFromParent.get(entry.parentCode);\n if (!set) {\n set = new Set();\n parentToChildrenFromParent.set(entry.parentCode, set);\n }\n set.add(entry.code);\n }\n }\n\n for (const entry of entries) {\n const declared = new Set(entry.childCodes);\n const derived = parentToChildrenFromParent.get(entry.code) ?? new Set();\n\n for (const child of declared) {\n if (!derived.has(child)) {\n errors.push({\n invariant: \"C4\",\n message: `entry lists ${child} in childCodes but that entry's parentCode is not ${entry.code}`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n for (const child of derived) {\n if (!declared.has(child)) {\n errors.push({\n invariant: \"C4\",\n message: `entry ${child} has parentCode ${entry.code} but is missing from its childCodes`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n }\n\n // ── C5: selectability per §4.4 ────────────────────────────────────────────\n // Zod already enforces `selectable: boolean`; we make the invariant explicit\n // at validator level so a future schema loosening cannot silently bypass it.\n for (const entry of entries) {\n if (typeof entry.selectable !== \"boolean\") {\n errors.push({\n invariant: \"C5\",\n message: `selectable must be a boolean, got ${typeof entry.selectable}`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n\n // ── C6: cross-CVC refs — `relevantMechanisms` resolves against provided set\n if (options.mechanismKeys) {\n for (const entry of entries) {\n const raw = (entry as unknown as Record<string, unknown>)[\n \"relevantMechanisms\"\n ];\n if (raw === undefined || raw === null) continue;\n if (!Array.isArray(raw)) {\n errors.push({\n invariant: \"C6\",\n message: `relevantMechanisms must be an array or null`,\n code: entry.code,\n key: entry.key,\n });\n continue;\n }\n for (const mechKey of raw) {\n if (\n typeof mechKey !== \"string\" ||\n !options.mechanismKeys.has(mechKey)\n ) {\n errors.push({\n invariant: \"C6\",\n message: `relevantMechanisms references unknown service_mechanisms key: ${String(mechKey)}`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n }\n }\n\n // ── C8: legacy `'provided'` key guard ─────────────────────────────────────\n // Walk every property of every entry (including nested arrays) looking for\n // a key named `'provided'`. It is a Thread UI label, not a canonical state.\n const walkForProvided = (value: unknown, entry: CvcEntry): void => {\n if (value === null || value === undefined) return;\n if (Array.isArray(value)) {\n for (const item of value) walkForProvided(item, entry);\n return;\n }\n if (typeof value === \"object\") {\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (k === \"provided\") {\n errors.push({\n invariant: \"C8\",\n message: `entry contains forbidden legacy key 'provided' (see locked spec §4)`,\n code: entry.code,\n key: entry.key,\n });\n }\n walkForProvided(v, entry);\n }\n }\n };\n for (const entry of entries) {\n walkForProvided(entry, entry);\n // Also guard against a literal string value of 'provided' appearing as an\n // entry's `key`, which would be an obvious smuggling attempt.\n if (entry.key === \"provided\") {\n errors.push({\n invariant: \"C8\",\n message: `entry key must not be the legacy label 'provided'`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n\n return errors;\n}\n","/**\n * @htilabs/platform-common-models — CVC `_status`/`_source` provenance parser\n *\n * Problem this solves: `_status` on a SOT envelope (`src/cvcs/*.json`) is\n * unvalidated free text (115 of 179 domains carry it; the rest predate the\n * convention). A consumer that wants to know \"is this actually a draft?\" has\n * had to eyeball a string like\n *\n * \"DRAFT — TEMPORARY: net-new value-CVC not yet in Notion; provisional\n * 900+ numbering; codes from prototype/data/cvcs/core_accommodation_type\n * .yaml; PENDING canonical Notion authoring (PAVE Auditability backlog).\"\n *\n * and get it right past two real traps observed across the current\n * population:\n * - A leading `\"CANONICAL — …\"` marker is a PROVENANCE note on an\n * ALREADY-ratified file, not a maturity warning — it must not be lumped\n * in with `\"DRAFT\"`/`\"PROVISIONAL\"`.\n * - `core_functions` is self-contradictory: it leads\n * `\"DRAFTED — NEEDS REVIEW\"` but the same string continues\n * `\"…Canonical numbering (133), NOT provisional.\"` A naive\n * leading-word reader silently picks one side; this parser flags it.\n *\n * This module is a pure, additive, standalone export. It does NOT touch\n * `CvcEnvelopeSchema` (`./cvc.ts`) — `_status`/`_source` are intentionally\n * outside that Zod schema (see its module header), and adding them there\n * would risk changing parse behavior for every existing consumer. Callers\n * pass the RAW parsed JSON object (before or instead of\n * `CvcEnvelopeSchema.parse()`), not the Zod-inferred `CvcEnvelope`.\n *\n * Classification rule (leading token of `_status`, case-insensitive):\n * - contains \"draft\" → `maturity: \"draft\"`\n * - contains \"provisional\" → `maturity: \"provisional\"`\n * - contains \"canonical\" → `maturity: \"canonical\"` (a provenance note on\n * an already-ratified file, NOT a maturity flag — kept distinct from\n * `\"final\"` below so a caller can tell \"explicitly marked ratified\"\n * apart from \"predates the convention entirely\")\n * - `_status` absent entirely → `maturity: \"final\"` (legacy/unmarked)\n *\n * One real domain (`share_purpose` — \"Synced verbatim from canonical\n * CVC-84…\") has a present `_status` whose LEADING token (\"Synced\") is none\n * of the three convention words. Rather than mis-file it as `\"final\"` (which\n * per the rule above is reserved for an ABSENT field) this parser falls back\n * to scanning the full string for a single unambiguous keyword family before\n * giving up — see `detectMaturity` below.\n */\n\n// ─── Public shape ───────────────────────────────────────────────────────────\n\n/**\n * The subset of a raw (pre-validation) SOT envelope this parser reads.\n * Deliberately NOT the Zod-inferred `CvcEnvelope` from `./cvc.ts` — that type\n * is the *parsed* shape, which does not declare `_status`/`_source` at all\n * (they live outside the locked envelope schema on purpose). Pass the raw\n * `JSON.parse()` result of a `src/cvcs/*.json` file here.\n */\nexport interface RawCvcEnvelopeProvenance {\n _status?: unknown;\n _source?: unknown;\n}\n\n/** The four observed maturity states. See module header for the rule. */\nexport type CvcMaturity = \"draft\" | \"provisional\" | \"canonical\" | \"final\";\n\nexport interface CvcStatusInfo {\n /** One of the four states; see module header for the classification rule. */\n maturity: CvcMaturity;\n /**\n * The text this parser classified. For a string `_status` this is that\n * string verbatim. For the 11 domains authored with a structured\n * `_status` object (`{ vocabStatus, authoredBy, evidence, … }` — e.g.\n * `citizenship`, `core_functions`'s sibling `countries`), this is\n * `_status.vocabStatus` — the field those envelopes use for exactly this\n * purpose — not the whole object. `null` iff `_status` is absent.\n */\n rawStatus: string | null;\n /** True iff `_source` cites a `prototype/data/cvcs/*.yaml` path. */\n sourceIsPrototype: boolean;\n /** The cited `prototype/data/cvcs/*.yaml` path, or `null` if none. */\n sourcePath: string | null;\n /**\n * True when the classification is a judgment call rather than a clean\n * read: either the leading token disagrees with a later\n * \"NOT draft\"/\"NOT provisional\"/\"NOT canonical\" qualifier in the same\n * string (the `core_functions` shape — generic, not special-cased, so any\n * future domain authored in the same self-contradictory shape is also\n * caught), or the string carries more than one maturity keyword family\n * with no leading token to arbitrate between them.\n */\n ambiguous: boolean;\n}\n\n// ─── Implementation ─────────────────────────────────────────────────────────\n\nconst MATURITY_KEYWORDS: ReadonlyArray<{\n keyword: string;\n maturity: Exclude<CvcMaturity, \"final\">;\n}> = [\n { keyword: \"draft\", maturity: \"draft\" },\n { keyword: \"provisional\", maturity: \"provisional\" },\n { keyword: \"canonical\", maturity: \"canonical\" },\n];\n\n/** Matches a `prototype/data/cvcs/<file>.yaml` citation anywhere in `_source`. */\nconst PROTOTYPE_SOURCE_RE = /(prototype\\/data\\/cvcs\\/[A-Za-z0-9_.-]+\\.yaml)/;\n\n/**\n * A maturity keyword explicitly negated (\"NOT provisional.\") anywhere in the\n * string — the self-contradiction signal. Deliberately scans the WHOLE\n * string (not just past the leading token): the qualifier that disagrees\n * with the leading word is, by construction, never the leading word itself.\n */\nconst NEGATED_MATURITY_RE = /\\bnot\\s+(draft|provisional|canonical)\\b/i;\n\n/**\n * Extract the text this parser classifies against, from either `_status`\n * shape observed in the current SOT population:\n * - `string` (104 of 115 status-bearing domains) → the string itself.\n * - `{ vocabStatus: string, … }` (11 domains — a richer, hand-authored\n * provenance record) → `vocabStatus`, the field those envelopes use for\n * exactly this classification (values seen: `\"canonical\"` and\n * `\"provisional-pending-notion-ratification\"`).\n * - Anything else present but shapeless (unseen in the current 179-domain\n * population) → `JSON.stringify` as a last resort, so a future oddity\n * still gets a best-effort classification instead of silently vanishing.\n * - Absent → `null`.\n */\nfunction extractClassificationText(status: unknown): string | null {\n if (typeof status === \"string\") return status;\n if (status !== null && typeof status === \"object\") {\n const vocabStatus = (status as Record<string, unknown>).vocabStatus;\n if (typeof vocabStatus === \"string\") return vocabStatus;\n return JSON.stringify(status);\n }\n return null;\n}\n\n/** The first \"word\" of a status string, lowercased, for the leading-token rule. */\nfunction leadingToken(text: string): string {\n return (text.trim().split(/[\\s—–:-]+/, 1)[0] ?? \"\").toLowerCase();\n}\n\n/**\n * Classify a present, non-null `_status` text into a maturity + ambiguity\n * flag. Isolated from {@link parseCvcStatus} so the fallback path (the\n * `share_purpose` shape) and the negation check are each unit-testable in\n * isolation.\n */\nfunction detectMaturity(text: string): { maturity: Exclude<CvcMaturity, \"final\">; ambiguous: boolean } {\n const lead = leadingToken(text);\n const leadMatch = MATURITY_KEYWORDS.find(({ keyword }) => lead.includes(keyword));\n\n let maturity: Exclude<CvcMaturity, \"final\">;\n if (leadMatch) {\n maturity = leadMatch.maturity;\n } else {\n // The leading token is none of the three convention words. Observed once\n // in the current population: `share_purpose`'s\n // \"Synced verbatim from canonical CVC-84…\" — \"Synced\" leads, but the\n // string is unambiguously describing an already-ratified vocabulary.\n // Fall back to scanning the WHOLE string for maturity keyword families\n // rather than defaulting to \"final\": the field IS present, and \"final\"\n // per the module-header rule is reserved for an ABSENT `_status`.\n const foundFamilies = MATURITY_KEYWORDS.filter(({ keyword }) =>\n new RegExp(`\\\\b${keyword}\\\\w*\\\\b`, \"i\").test(text),\n );\n const distinctFamilies = new Set(foundFamilies.map((f) => f.maturity));\n if (distinctFamilies.size === 1) {\n // Single unambiguous family found in the body — safe to accept.\n maturity = foundFamilies[0].maturity;\n return { maturity, ambiguous: false };\n }\n if (distinctFamilies.size > 1) {\n // Multiple families present with no leading token to arbitrate.\n // Report the first-occurring family as a best-effort primary and let\n // the caller see `ambiguous: true` — never silently pick a winner.\n maturity = foundFamilies[0].maturity;\n return { maturity, ambiguous: true };\n }\n // No maturity keyword anywhere in a present `_status` string. Unseen in\n // the current 179-domain population; treat conservatively as\n // \"provisional\" (the least-committal non-final bucket) rather than\n // silently promoting an unrecognized status to a settled one, and flag\n // it for human attention.\n return { maturity: \"provisional\", ambiguous: true };\n }\n\n return { maturity, ambiguous: NEGATED_MATURITY_RE.test(text) };\n}\n\n/**\n * Parse a SOT envelope's `_status`/`_source` provenance fields into a\n * structured, typed result. Pure function — no filesystem access, no\n * dependency on `CvcEnvelopeSchema`. See module header for the full rule and\n * the two known traps it exists to catch.\n */\nexport function parseCvcStatus(envelope: RawCvcEnvelopeProvenance): CvcStatusInfo {\n const source = typeof envelope._source === \"string\" ? envelope._source : null;\n const protoMatch = source?.match(PROTOTYPE_SOURCE_RE) ?? null;\n const sourceIsPrototype = protoMatch !== null;\n const sourcePath = protoMatch?.[1] ?? null;\n\n const text = extractClassificationText(envelope._status);\n if (text === null) {\n return { maturity: \"final\", rawStatus: null, sourceIsPrototype, sourcePath, ambiguous: false };\n }\n\n const { maturity, ambiguous } = detectMaturity(text);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AY,kBAAkB,KAAK,CAAC,EAAE,QAAQ,MAAM,KAAK,SAAS,OAAO,CAAC;AAEhF,MAAI;AACJ,MAAI,WAAW;AACb,eAAW,UAAU;AAAA,EACvB,OAAO;AAQL,UAAM,gBAAgB,kBAAkB;AAAA,MAAO,CAAC,EAAE,QAAQ,MACxD,IAAI,OAAO,MAAM,OAAO,WAAW,GAAG,EAAE,KAAK,IAAI;AAAA,IACnD;AACA,UAAM,mBAAmB,IAAI,IAAI,cAAc,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC;AACrE,QAAI,iBAAiB,SAAS,GAAG;AAE/B,iBAAW,cAAc,CAAC,EAAE;AAC5B,aAAO,EAAE,UAAU,WAAW,MAAM;AAAA,IACtC;AACA,QAAI,iBAAiB,OAAO,GAAG;AAI7B,iBAAW,cAAc,CAAC,EAAE;AAC5B,aAAO,EAAE,UAAU,WAAW,KAAK;AAAA,IACrC;AAMA,WAAO,EAAE,UAAU,eAAe,WAAW,KAAK;AAAA,EACpD;AAEA,SAAO,EAAE,UAAU,WAAW,oBAAoB,KAAK,IAAI,EAAE;AAC/D;AAQO,SAAS,eAAe,UAAmD;AAChF,QAAM,SAAS,OAAO,SAAS,YAAY,WAAW,SAAS,UAAU;AACzE,QAAM,aAAa,QAAQ,MAAM,mBAAmB,KAAK;AACzD,QAAM,oBAAoB,eAAe;AACzC,QAAM,aAAa,aAAa,CAAC,KAAK;AAEtC,QAAM,OAAO,0BAA0B,SAAS,OAAO;AACvD,MAAI,SAAS,MAAM;AACjB,WAAO,EAAE,UAAU,SAAS,WAAW,MAAM,mBAAmB,YAAY,WAAW,MAAM;AAAA,EAC/F;AAEA,QAAM,EAAE,UAAU,UAAU,IAAI,eAAe,IAAI;AACnD,SAAO,EAAE,UAAU,WAAW,MAAM,mBAAmB,YAAY,UAAU;AAC/E;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/validation/index.ts","../../src/validation/cvc.ts","../../src/validation/cvcStatus.ts","../../src/validation/team.ts","../../src/constants/platform-auth.ts"],"sourcesContent":["/**\n * @htilabs/platform-common-models — Validation barrel\n *\n * Public entry point for the Zod validation surface. Consumers that want\n * the canonical Zod-inferred `CvcEntry` (rather than the Mongoose persistence\n * shape exported from the package root) should import from here:\n *\n * ```ts\n * import { CvcEntry, CvcEntrySchema } from '@htilabs/platform-common-models/validation';\n * ```\n *\n * See `./cvc.ts` for the schema and type definitions.\n */\n\nexport * from \"./cvc.js\";\nexport * from \"./cvcStatus.js\";\nexport * from \"./team.js\";\n","/**\n * @htilabs/platform-common-models — Controlled Vocabulary (CVC) Validation\n *\n * Zod schemas for validating CVC Source-of-Truth (SOT) JSON files and\n * individual CVC entries. Implements the locked spec §9.2 shapes.\n *\n * Used by:\n * - CI structural tests that parse every committed SOT file.\n * - The generalized seed CLI (`seedCvc`) prior to persistence.\n * - Downstream consumers that need to validate CVC payloads.\n *\n * Canonical spec:\n * /gt/docs/data/cvcs/CVC Implementation Spec 2780449faf8045258c67daab0f1c5569.md\n *\n * Format v2 (2026-04-15):\n * - Positional 7-segment codes `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (3 digits per\n * segment). Segment 1 is the Notion-aligned domain prefix:\n * `022` service_categories (CVC-22)\n * `025` service_mechanisms (CVC-25)\n * `049` service_states (CVC-49)\n * - Missingness entries are embedded per-domain (synthetic `missingness_root`\n * at `<prefix>-000-000-000-000-000-000` plus three values at segment 7 =\n * `001`/`002`/`003`). The shared `missingness.v1.0.0.json` file was\n * retired in favor of per-domain missingness.\n * - Envelope `missingness` field and the C7 invariant have been removed; the\n * shared-merge pathway no longer exists.\n */\n\nimport { z } from \"zod\";\n\n// ─── Primitive schemas ───────────────────────────────────────────────────────\n\n/**\n * 7-segment positional CVC code: `XXX-XXX-XXX-XXX-XXX-XXX-XXX` (three digits\n * per segment). Segment 1 is the Notion-aligned domain prefix. Remaining\n * hierarchy segments are filled left-to-right as levels deepen; unused\n * segments remain `000`. See locked spec §3 (format v2).\n */\nexport const CvcCodeSchema = z.string().regex(/^\\d{3}(-\\d{3}){6}$/);\n\n/**\n * Stable machine key for a CVC entry. Must start with a lowercase letter and\n * contain only lowercase alphanumerics or underscores. Used as a cross-CVC\n * reference target (e.g. `relevantMechanisms` pointing at mechanism keys).\n * See locked spec §3.2.\n */\nexport const CvcKeySchema = z.string().regex(/^[a-z][a-z0-9_]*$/);\n\n// ─── Entry schemas ───────────────────────────────────────────────────────────\n\n/**\n * Base entry shape shared by every CVC domain. Domain-specific extensions\n * (e.g. `ServiceCategoryEntrySchema`) should use `.extend()` to add fields.\n * See locked spec §9.2.\n *\n * Uses `.passthrough()` so that domain-specific fields (like\n * `relevantMechanisms` on service-category entries) survive base parsing\n * unmodified. This keeps cross-CVC reference validation honest: the §4.5\n * structural validator needs to see the raw referenced keys, and a strip-by-\n * default schema would silently hide them.\n */\nexport const CvcEntrySchema = z\n .object({\n code: CvcCodeSchema,\n key: CvcKeySchema,\n title: z.string().min(1),\n selectable: z.boolean(),\n parentCode: CvcCodeSchema.nullable(),\n childCodes: z.array(CvcCodeSchema),\n definition: z.string().nullable(),\n })\n .passthrough();\n\n/**\n * Service-category-specific entry. Adds `relevantMechanisms` — a cross-CVC\n * reference into the `service_mechanisms` domain via entry keys. `null` means\n * \"not applicable\" (e.g. structural L1 topic rows). See locked spec §9.2.\n */\nexport const ServiceCategoryEntrySchema = CvcEntrySchema.extend({\n relevantMechanisms: z.array(CvcKeySchema).nullable(),\n});\n\n/**\n * Primary-language-specific entry. Adds:\n * - `iso6391Code` — the ISO 639-1 alpha-2 code for the language, or `null`\n * for entries without an ISO 639-1 code (missingness entries, Chinese\n * varieties Mandarin/Cantonese, `other_language`). ASL is stored as\n * `\"ase\"` (ISO 639-3) per Notion's convention; the CVC header documents\n * this caveat.\n * - `priority` — `true` for front-end short-list entries (14 total in\n * CVC-122: 13 L1 languages plus the canonical `unknown` missingness\n * entry). See locked spec §9.2.\n */\nexport const PrimaryLanguageEntrySchema = CvcEntrySchema.extend({\n iso6391Code: z.string().nullable(),\n priority: z.boolean(),\n});\n\n// ─── Envelope schema ─────────────────────────────────────────────────────────\n\n/**\n * Top-level SOT JSON envelope. One envelope per (domain, version) pair.\n *\n * `levels` is a positional map from level number (`\"0\"`, `\"1\"`, …) to a human\n * label describing the level. Missingness entries are embedded in `entries`\n * (per-domain) rather than merged in from a shared SOT file; see module\n * header for the v2 format summary.\n */\nexport const CvcEnvelopeSchema = z.object({\n domain: z.string().min(1),\n name: z.string().min(1),\n version: z.string().min(1),\n levels: z.record(z.string(), z.string()),\n entries: z.array(CvcEntrySchema),\n});\n\n// ─── Inferred types ──────────────────────────────────────────────────────────\n\nexport type CvcCode = z.infer<typeof CvcCodeSchema>;\nexport type CvcKey = z.infer<typeof CvcKeySchema>;\nexport type CvcEntry = z.infer<typeof CvcEntrySchema>;\nexport type ServiceCategoryEntry = z.infer<typeof ServiceCategoryEntrySchema>;\nexport type PrimaryLanguageEntry = z.infer<typeof PrimaryLanguageEntrySchema>;\nexport type CvcEnvelope = z.infer<typeof CvcEnvelopeSchema>;\n\n/**\n * SOT family identifier (e.g. `\"service_categories\"`, `\"service_states\"`,\n * `\"service_mechanisms\"`, `\"missingness\"`). The canonical list of domains is\n * enumerated by the SOT JSON files in `src/cvcs/`. Typed as `string` rather\n * than a closed union so adding a new SOT file does not require touching this\n * type. See locked spec §2.\n */\nexport type CvcDomain = string;\n\n// ─── Structural validator (locked spec §4 / §9.3) ───────────────────────────\n\n/**\n * Derive an entry's level from its 7-segment code per locked spec §3.3.\n *\n * - Segment 7 non-zero → level 0 (missingness value entry, e.g. `unknown`).\n * - Otherwise return the index (1..5) of the last non-zero hierarchy segment.\n * - Hierarchy segments 2..7 all zero → level 0 (per-domain missingness root,\n * e.g. `022-000-000-000-000-000-000`). Segment 1 carries the domain prefix\n * and is intentionally not consulted by the level derivation.\n */\nexport function getCvcLevel(code: string): number {\n const segments = code.split(\"-\");\n // segments[6] is the missingness slot (positional segment 7).\n if (segments[6] !== \"000\") return 0;\n // Walk hierarchy segments 6..2 (indices 5..1) looking for the deepest\n // populated level.\n for (let i = 5; i >= 1; i -= 1) {\n if (segments[i] !== \"000\") return i;\n }\n return 0;\n}\n\n/**\n * Error collected by {@link validateCvc}. Each error names the invariant it\n * violates (`C1`..`C8`, skipping the retired `C7`) so CI output points\n * straight at the locked spec rule that failed. `code` or `key` narrow the\n * error to a specific entry when the violation is entry-scoped.\n */\nexport interface CvcValidationError {\n invariant: \"C1\" | \"C2\" | \"C3\" | \"C4\" | \"C5\" | \"C6\" | \"C8\";\n message: string;\n code?: string;\n key?: string;\n}\n\n/**\n * Structural invariants to enforce on every committed SOT file per locked spec\n * §4. Zod's schema `parse()` guarantees the *shape* of the envelope; this\n * function enforces the cross-entry *semantics* that Zod cannot express.\n *\n * Invariants (locked spec §4):\n * - **C1** Code format + uniqueness (§4.1). Format v2 uses 3-digit segments.\n * - **C2** Key format + uniqueness (§4.2).\n * - **C3** Tree: every `parentCode` resolves to an existing entry or null; no\n * cycles (§4.3).\n * - **C4** `childCodes` are the exact bidirectional inverse of `parentCode`\n * (§4.3).\n * - **C5** Selectability is a boolean (§4.4).\n * - **C6** Cross-CVC `relevantMechanisms` references resolve against a\n * provided `service_mechanisms` key set (§4.5, §7). Only checked when the\n * caller supplies `options.mechanismKeys`.\n * - **C7** _Retired in format v2_ (envelope no longer carries the shared\n * `missingness` field; missingness is per-domain and embedded in\n * `entries`). The invariant slot is intentionally left empty to preserve\n * the numbering of C1/C2/C3/C4/C5/C6/C8 in historical references.\n * - **C8** No entry anywhere contains a key `'provided'` (legacy Thread UI\n * label guard; not a canonical state).\n *\n * @param envelope Parsed envelope (typically from `CvcEnvelopeSchema.parse()`).\n * @param options.mechanismKeys Optional set of valid `service_mechanisms`\n * entry keys. If provided and the envelope entries have `relevantMechanisms`\n * fields, each referenced key must be in this set (C6).\n * @returns An array of {@link CvcValidationError}. An empty array means valid.\n */\nexport function validateCvc(\n envelope: CvcEnvelope,\n options: { mechanismKeys?: ReadonlySet<string> } = {},\n): CvcValidationError[] {\n const errors: CvcValidationError[] = [];\n const { entries } = envelope;\n\n // ── C1: code format + uniqueness ──────────────────────────────────────────\n const codeRe = /^\\d{3}(-\\d{3}){6}$/;\n const seenCodes = new Set<string>();\n for (const entry of entries) {\n if (!codeRe.test(entry.code)) {\n errors.push({\n invariant: \"C1\",\n message: `code does not match /^\\\\d{3}(-\\\\d{3}){6}$/`,\n code: entry.code,\n key: entry.key,\n });\n }\n if (seenCodes.has(entry.code)) {\n errors.push({\n invariant: \"C1\",\n message: `duplicate code`,\n code: entry.code,\n key: entry.key,\n });\n }\n seenCodes.add(entry.code);\n }\n\n // ── C2: key format + uniqueness ───────────────────────────────────────────\n const keyRe = /^[a-z][a-z0-9_]*$/;\n const seenKeys = new Set<string>();\n for (const entry of entries) {\n if (!keyRe.test(entry.key)) {\n errors.push({\n invariant: \"C2\",\n message: `key does not match /^[a-z][a-z0-9_]*$/`,\n code: entry.code,\n key: entry.key,\n });\n }\n if (seenKeys.has(entry.key)) {\n errors.push({\n invariant: \"C2\",\n message: `duplicate key`,\n code: entry.code,\n key: entry.key,\n });\n }\n seenKeys.add(entry.key);\n }\n\n // Build a lookup by code for the remaining tree checks. Skip entries whose\n // code we already know is malformed — their index would be meaningless.\n const byCode = new Map<string, CvcEntry>();\n for (const entry of entries) {\n if (codeRe.test(entry.code)) byCode.set(entry.code, entry);\n }\n\n // ── C3: tree — parents resolve, no cycles ─────────────────────────────────\n for (const entry of entries) {\n if (entry.parentCode === null) continue;\n if (!byCode.has(entry.parentCode)) {\n errors.push({\n invariant: \"C3\",\n message: `parentCode ${entry.parentCode} does not resolve to any entry in this CVC`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n\n // Cycle detection: walk parent chain from each entry, bail if we revisit.\n for (const entry of entries) {\n const visited = new Set<string>();\n let cursor: CvcEntry | undefined = entry;\n while (cursor && cursor.parentCode !== null) {\n if (visited.has(cursor.code)) {\n errors.push({\n invariant: \"C3\",\n message: `cycle detected in parentCode chain starting from ${entry.code}`,\n code: entry.code,\n key: entry.key,\n });\n break;\n }\n visited.add(cursor.code);\n cursor = byCode.get(cursor.parentCode);\n }\n }\n\n // ── C4: childCodes are exact inverse of parentCode ────────────────────────\n // Build the set of (parent, child) edges from parentCode, then from\n // childCodes, and require they match exactly.\n const parentToChildrenFromParent = new Map<string, Set<string>>();\n for (const entry of entries) {\n if (entry.parentCode !== null) {\n let set = parentToChildrenFromParent.get(entry.parentCode);\n if (!set) {\n set = new Set();\n parentToChildrenFromParent.set(entry.parentCode, set);\n }\n set.add(entry.code);\n }\n }\n\n for (const entry of entries) {\n const declared = new Set(entry.childCodes);\n const derived = parentToChildrenFromParent.get(entry.code) ?? new Set();\n\n for (const child of declared) {\n if (!derived.has(child)) {\n errors.push({\n invariant: \"C4\",\n message: `entry lists ${child} in childCodes but that entry's parentCode is not ${entry.code}`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n for (const child of derived) {\n if (!declared.has(child)) {\n errors.push({\n invariant: \"C4\",\n message: `entry ${child} has parentCode ${entry.code} but is missing from its childCodes`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n }\n\n // ── C5: selectability per §4.4 ────────────────────────────────────────────\n // Zod already enforces `selectable: boolean`; we make the invariant explicit\n // at validator level so a future schema loosening cannot silently bypass it.\n for (const entry of entries) {\n if (typeof entry.selectable !== \"boolean\") {\n errors.push({\n invariant: \"C5\",\n message: `selectable must be a boolean, got ${typeof entry.selectable}`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n\n // ── C6: cross-CVC refs — `relevantMechanisms` resolves against provided set\n if (options.mechanismKeys) {\n for (const entry of entries) {\n const raw = (entry as unknown as Record<string, unknown>)[\n \"relevantMechanisms\"\n ];\n if (raw === undefined || raw === null) continue;\n if (!Array.isArray(raw)) {\n errors.push({\n invariant: \"C6\",\n message: `relevantMechanisms must be an array or null`,\n code: entry.code,\n key: entry.key,\n });\n continue;\n }\n for (const mechKey of raw) {\n if (\n typeof mechKey !== \"string\" ||\n !options.mechanismKeys.has(mechKey)\n ) {\n errors.push({\n invariant: \"C6\",\n message: `relevantMechanisms references unknown service_mechanisms key: ${String(mechKey)}`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n }\n }\n\n // ── C8: legacy `'provided'` key guard ─────────────────────────────────────\n // Walk every property of every entry (including nested arrays) looking for\n // a key named `'provided'`. It is a Thread UI label, not a canonical state.\n const walkForProvided = (value: unknown, entry: CvcEntry): void => {\n if (value === null || value === undefined) return;\n if (Array.isArray(value)) {\n for (const item of value) walkForProvided(item, entry);\n return;\n }\n if (typeof value === \"object\") {\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n if (k === \"provided\") {\n errors.push({\n invariant: \"C8\",\n message: `entry contains forbidden legacy key 'provided' (see locked spec §4)`,\n code: entry.code,\n key: entry.key,\n });\n }\n walkForProvided(v, entry);\n }\n }\n };\n for (const entry of entries) {\n walkForProvided(entry, entry);\n // Also guard against a literal string value of 'provided' appearing as an\n // entry's `key`, which would be an obvious smuggling attempt.\n if (entry.key === \"provided\") {\n errors.push({\n invariant: \"C8\",\n message: `entry key must not be the legacy label 'provided'`,\n code: entry.code,\n key: entry.key,\n });\n }\n }\n\n return errors;\n}\n","/**\n * @htilabs/platform-common-models — CVC `_status`/`_source` provenance parser\n *\n * Problem this solves: `_status` on a SOT envelope (`src/cvcs/*.json`) is\n * unvalidated free text (115 of 179 domains carry it; the rest predate the\n * convention). A consumer that wants to know \"is this actually a draft?\" has\n * had to eyeball a string like\n *\n * \"DRAFT — TEMPORARY: net-new value-CVC not yet in Notion; provisional\n * 900+ numbering; codes from prototype/data/cvcs/core_accommodation_type\n * .yaml; PENDING canonical Notion authoring (PAVE Auditability backlog).\"\n *\n * and get it right past two real traps observed across the current\n * population:\n * - A leading `\"CANONICAL — …\"` marker is a PROVENANCE note on an\n * ALREADY-ratified file, not a maturity warning — it must not be lumped\n * in with `\"DRAFT\"`/`\"PROVISIONAL\"`.\n * - `core_functions` is self-contradictory: it leads\n * `\"DRAFTED — NEEDS REVIEW\"` but the same string continues\n * `\"…Canonical numbering (133), NOT provisional.\"` A naive\n * leading-word reader silently picks one side; this parser flags it.\n *\n * This module is a pure, additive, standalone export. It does NOT touch\n * `CvcEnvelopeSchema` (`./cvc.ts`) — `_status`/`_source` are intentionally\n * outside that Zod schema (see its module header), and adding them there\n * would risk changing parse behavior for every existing consumer. Callers\n * pass the RAW parsed JSON object (before or instead of\n * `CvcEnvelopeSchema.parse()`), not the Zod-inferred `CvcEnvelope`.\n *\n * Classification rule (leading token of `_status`, case-insensitive):\n * - contains \"draft\" → `maturity: \"draft\"`\n * - contains \"provisional\" → `maturity: \"provisional\"`\n * - contains \"canonical\" → `maturity: \"canonical\"` (a provenance note on\n * an already-ratified file, NOT a maturity flag — kept distinct from\n * `\"final\"` below so a caller can tell \"explicitly marked ratified\"\n * apart from \"predates the convention entirely\")\n * - `_status` absent entirely → `maturity: \"final\"` (legacy/unmarked)\n *\n * One real domain (`share_purpose` — \"Synced verbatim from canonical\n * CVC-84…\") has a present `_status` whose LEADING token (\"Synced\") is none\n * of the three convention words. Rather than mis-file it as `\"final\"` (which\n * per the rule above is reserved for an ABSENT field) this parser falls back\n * to scanning the full string for a single unambiguous keyword family before\n * giving up — see `detectMaturity` below.\n */\n\n// ─── Public shape ───────────────────────────────────────────────────────────\n\n/**\n * The subset of a raw (pre-validation) SOT envelope this parser reads.\n * Deliberately NOT the Zod-inferred `CvcEnvelope` from `./cvc.ts` — that type\n * is the *parsed* shape, which does not declare `_status`/`_source` at all\n * (they live outside the locked envelope schema on purpose). Pass the raw\n * `JSON.parse()` result of a `src/cvcs/*.json` file here.\n */\nexport interface RawCvcEnvelopeProvenance {\n _status?: unknown;\n _source?: unknown;\n}\n\n/** The four observed maturity states. See module header for the rule. */\nexport type CvcMaturity = \"draft\" | \"provisional\" | \"canonical\" | \"final\";\n\nexport interface CvcStatusInfo {\n /** One of the four states; see module header for the classification rule. */\n maturity: CvcMaturity;\n /**\n * The text this parser classified. For a string `_status` this is that\n * string verbatim. For the 11 domains authored with a structured\n * `_status` object (`{ vocabStatus, authoredBy, evidence, … }` — e.g.\n * `citizenship`, `core_functions`'s sibling `countries`), this is\n * `_status.vocabStatus` — the field those envelopes use for exactly this\n * purpose — not the whole object. `null` iff `_status` is absent.\n */\n rawStatus: string | null;\n /** True iff `_source` cites a `prototype/data/cvcs/*.yaml` path. */\n sourceIsPrototype: boolean;\n /** The cited `prototype/data/cvcs/*.yaml` path, or `null` if none. */\n sourcePath: string | null;\n /**\n * True when the classification is a judgment call rather than a clean\n * read: either the leading token disagrees with a later\n * \"NOT draft\"/\"NOT provisional\"/\"NOT canonical\" qualifier in the same\n * string (the `core_functions` shape — generic, not special-cased, so any\n * future domain authored in the same self-contradictory shape is also\n * caught), or the string carries more than one maturity keyword family\n * with no leading token to arbitrate between them.\n */\n ambiguous: boolean;\n}\n\n// ─── Implementation ─────────────────────────────────────────────────────────\n\nconst MATURITY_KEYWORDS: ReadonlyArray<{\n keyword: string;\n maturity: Exclude<CvcMaturity, \"final\">;\n}> = [\n { keyword: \"draft\", maturity: \"draft\" },\n { keyword: \"provisional\", maturity: \"provisional\" },\n { keyword: \"canonical\", maturity: \"canonical\" },\n];\n\n/** Matches a `prototype/data/cvcs/<file>.yaml` citation anywhere in `_source`. */\nconst PROTOTYPE_SOURCE_RE = /(prototype\\/data\\/cvcs\\/[A-Za-z0-9_.-]+\\.yaml)/;\n\n/**\n * A maturity keyword explicitly negated (\"NOT provisional.\") anywhere in the\n * string — the self-contradiction signal. Deliberately scans the WHOLE\n * string (not just past the leading token): the qualifier that disagrees\n * with the leading word is, by construction, never the leading word itself.\n */\nconst NEGATED_MATURITY_RE = /\\bnot\\s+(draft|provisional|canonical)\\b/i;\n\n/**\n * Extract the text this parser classifies against, from either `_status`\n * shape observed in the current SOT population:\n * - `string` (104 of 115 status-bearing domains) → the string itself.\n * - `{ vocabStatus: string, … }` (11 domains — a richer, hand-authored\n * provenance record) → `vocabStatus`, the field those envelopes use for\n * exactly this classification (values seen: `\"canonical\"` and\n * `\"provisional-pending-notion-ratification\"`).\n * - Anything else present but shapeless (unseen in the current 179-domain\n * population) → `JSON.stringify` as a last resort, so a future oddity\n * still gets a best-effort classification instead of silently vanishing.\n * - Absent → `null`.\n */\nfunction extractClassificationText(status: unknown): string | null {\n if (typeof status === \"string\") return status;\n if (status !== null && typeof status === \"object\") {\n const vocabStatus = (status as Record<string, unknown>).vocabStatus;\n if (typeof vocabStatus === \"string\") return vocabStatus;\n return JSON.stringify(status);\n }\n return null;\n}\n\n/** The first \"word\" of a status string, lowercased, for the leading-token rule. */\nfunction leadingToken(text: string): string {\n return (text.trim().split(/[\\s—–:-]+/, 1)[0] ?? \"\").toLowerCase();\n}\n\n/**\n * Classify a present, non-null `_status` text into a maturity + ambiguity\n * flag. Isolated from {@link parseCvcStatus} so the fallback path (the\n * `share_purpose` shape) and the negation check are each unit-testable in\n * isolation.\n */\nfunction detectMaturity(text: string): { maturity: Exclude<CvcMaturity, \"final\">; ambiguous: boolean } {\n const lead = leadingToken(text);\n const leadMatch = MATURITY_KEYWORDS.find(({ keyword }) => lead.includes(keyword));\n\n let maturity: Exclude<CvcMaturity, \"final\">;\n if (leadMatch) {\n maturity = leadMatch.maturity;\n } else {\n // The leading token is none of the three convention words. Observed once\n // in the current population: `share_purpose`'s\n // \"Synced verbatim from canonical CVC-84…\" — \"Synced\" leads, but the\n // string is unambiguously describing an already-ratified vocabulary.\n // Fall back to scanning the WHOLE string for maturity keyword families\n // rather than defaulting to \"final\": the field IS present, and \"final\"\n // per the module-header rule is reserved for an ABSENT `_status`.\n const foundFamilies = MATURITY_KEYWORDS.filter(({ keyword }) =>\n new RegExp(`\\\\b${keyword}\\\\w*\\\\b`, \"i\").test(text),\n );\n const distinctFamilies = new Set(foundFamilies.map((f) => f.maturity));\n if (distinctFamilies.size === 1) {\n // Single unambiguous family found in the body — safe to accept.\n maturity = foundFamilies[0].maturity;\n return { maturity, ambiguous: false };\n }\n if (distinctFamilies.size > 1) {\n // Multiple families present with no leading token to arbitrate.\n // Report the first-occurring family as a best-effort primary and let\n // the caller see `ambiguous: true` — never silently pick a winner.\n maturity = foundFamilies[0].maturity;\n return { maturity, ambiguous: true };\n }\n // No maturity keyword anywhere in a present `_status` string. Unseen in\n // the current 179-domain population; treat conservatively as\n // \"provisional\" (the least-committal non-final bucket) rather than\n // silently promoting an unrecognized status to a settled one, and flag\n // it for human attention.\n return { maturity: \"provisional\", ambiguous: true };\n }\n\n return { maturity, ambiguous: NEGATED_MATURITY_RE.test(text) };\n}\n\n/**\n * Parse a SOT envelope's `_status`/`_source` provenance fields into a\n * structured, typed result. Pure function — no filesystem access, no\n * dependency on `CvcEnvelopeSchema`. See module header for the full rule and\n * the two known traps it exists to catch.\n */\nexport function parseCvcStatus(envelope: RawCvcEnvelopeProvenance): CvcStatusInfo {\n const source = typeof envelope._source === \"string\" ? envelope._source : null;\n const protoMatch = source?.match(PROTOTYPE_SOURCE_RE) ?? null;\n const sourceIsPrototype = protoMatch !== null;\n const sourcePath = protoMatch?.[1] ?? null;\n\n const text = extractClassificationText(envelope._status);\n if (text === null) {\n return { maturity: \"final\", rawStatus: null, sourceIsPrototype, sourcePath, ambiguous: false };\n }\n\n const { maturity, ambiguous } = detectMaturity(text);\n return { maturity, rawStatus: text, sourceIsPrototype, sourcePath, ambiguous };\n}\n","/**\n * @htilabs/platform-common-models — Team directory field validation\n *\n * Zod schemas for the team directory fields declared in\n * `../schemas/team.ts`, the fields the Thread→PAVE \"Refer to intake\" preset\n * reads. See that module for canon citations and the two deliberate\n * divergences (`apps` uses the {@link PLATFORM_TOOL} codes, and `canReferTo`\n * sits on the team because there is no Program model).\n *\n * This is the wire / API shape: ids are 24-hex strings, not ObjectIds. Merge\n * {@link TeamDirectoryFieldsSchema} into a consumer's team schema with\n * `.merge()` or `.extend(TeamDirectoryFieldsSchema.shape)`.\n */\n\nimport { z } from \"zod\";\nimport { PLATFORM_TOOL_VALUES } from \"../constants/platform-auth.js\";\n\n/** A Mongo ObjectId serialized as a 24-character hex string. */\nconst ObjectIdHexSchema = z\n .string()\n .regex(/^[0-9a-fA-F]{24}$/, \"must be a 24-character hex ObjectId\");\n\nconst hasNoDuplicates = (values: readonly string[]): boolean =>\n new Set(values.map((v) => v.toLowerCase())).size === values.length;\n\n/** One platform app a team works in: a {@link PLATFORM_TOOL} code. */\nexport const TeamAppSchema = z.enum(PLATFORM_TOOL_VALUES);\n\n/**\n * The team directory fields. Both are optional, so a team payload without\n * them validates unchanged. When present, neither list may repeat a value.\n */\nexport const TeamDirectoryFieldsSchema = z.object({\n apps: z\n .array(TeamAppSchema)\n .refine(hasNoDuplicates, \"apps must not repeat an app\")\n .optional(),\n canReferTo: z\n .array(ObjectIdHexSchema)\n .refine(hasNoDuplicates, \"canReferTo must not repeat a team\")\n .optional(),\n});\n\n/** A platform app code accepted on a team. */\nexport type TeamApp = z.infer<typeof TeamAppSchema>;\n\n/** Wire shape of the team directory fields (ids as hex strings). */\nexport type TeamDirectoryFieldsInput = z.infer<typeof TeamDirectoryFieldsSchema>;\n","/**\n * @htilabs/platform-common-models — Platform Authorization Constants\n *\n * Enums and labels for the platform role/function permission model.\n * Includes permission states, share view levels, tool codes, role levels,\n * and function implementation statuses.\n *\n * Source: PLATFORM_AUTH_SPEC.md Sections 5 + 6\n */\n\n// ─── Permission State (4-state role→function mapping) ──────────────\n\nexport const PERMISSION_STATE = {\n /** Role can always perform this function (mandatory, cannot disable). */\n ALWAYS: \"ALWAYS\",\n /** Default On — user can opt off. */\n PREF_YES: \"PREF_YES\",\n /** Default Off — user can opt in. */\n PREF_NO: \"PREF_NO\",\n /** Role is explicitly barred from this function. */\n NEVER: \"NEVER\",\n} as const;\n\nexport type PermissionStateValue =\n (typeof PERMISSION_STATE)[keyof typeof PERMISSION_STATE];\n\nexport const PERMISSION_STATE_VALUES = [\n PERMISSION_STATE.ALWAYS,\n PERMISSION_STATE.PREF_YES,\n PERMISSION_STATE.PREF_NO,\n PERMISSION_STATE.NEVER,\n] as const;\n\nexport const PERMISSION_STATE_LABELS: Record<PermissionStateValue, string> = {\n [PERMISSION_STATE.ALWAYS]: \"Always\",\n [PERMISSION_STATE.PREF_YES]: \"Default On\",\n [PERMISSION_STATE.PREF_NO]: \"Default Off\",\n [PERMISSION_STATE.NEVER]: \"Never\",\n};\n\n/** UI display metadata for permission states (colors, icons). */\nexport const PERMISSION_STATE_DISPLAY: Record<\n PermissionStateValue,\n { label: string; color: string; bgColor: string; icon: string }\n> = {\n [PERMISSION_STATE.ALWAYS]: {\n label: \"Always\",\n color: \"#2e7d32\",\n bgColor: \"#e8f5e9\",\n icon: \"\\u{1F512}\",\n },\n [PERMISSION_STATE.PREF_YES]: {\n label: \"Default On\",\n color: \"#1565c0\",\n bgColor: \"#e3f2fd\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.PREF_NO]: {\n label: \"Default Off\",\n color: \"#e65100\",\n bgColor: \"#fff3e0\",\n icon: \"\\u{1F513}\",\n },\n [PERMISSION_STATE.NEVER]: {\n label: \"Never\",\n color: \"#c62828\",\n bgColor: \"#ffebee\",\n icon: \"\\u{1F512}\",\n },\n};\n\n// ─── Share View (data visibility for shared records) ───────────────\n\nexport const SHARE_VIEW = {\n /** System metadata only (partial access). */\n SYS_INFO: \"sys_info\",\n /** Full case/record content. */\n ALL: \"all\",\n /** No data access. */\n NONE: \"none\",\n} as const;\n\nexport type ShareViewValue = (typeof SHARE_VIEW)[keyof typeof SHARE_VIEW];\n\nexport const SHARE_VIEW_VALUES = [\n SHARE_VIEW.SYS_INFO,\n SHARE_VIEW.ALL,\n SHARE_VIEW.NONE,\n] as const;\n\nexport const SHARE_VIEW_LABELS: Record<ShareViewValue, string> = {\n [SHARE_VIEW.SYS_INFO]: \"System Info Only\",\n [SHARE_VIEW.ALL]: \"Full Content\",\n [SHARE_VIEW.NONE]: \"No Data Access\",\n};\n\n// ─── Platform Tool Codes ───────────────────────────────────────────\n\nexport const PLATFORM_TOOL = {\n PAVE: \"PAVE\",\n ECHO: \"ECHO\",\n LEADS: \"LEADS\",\n THREAD: \"THREAD\",\n TRAIL: \"TRAIL\",\n PLATFORM: \"PLATFORM\",\n} as const;\n\nexport type PlatformToolValue =\n (typeof PLATFORM_TOOL)[keyof typeof PLATFORM_TOOL];\n\nexport const PLATFORM_TOOL_VALUES = [\n PLATFORM_TOOL.PAVE,\n PLATFORM_TOOL.ECHO,\n PLATFORM_TOOL.LEADS,\n PLATFORM_TOOL.THREAD,\n PLATFORM_TOOL.TRAIL,\n PLATFORM_TOOL.PLATFORM,\n] as const;\n\nexport const PLATFORM_TOOL_LABELS: Record<PlatformToolValue, string> = {\n [PLATFORM_TOOL.PAVE]: \"PAVE\",\n [PLATFORM_TOOL.ECHO]: \"Echo\",\n [PLATFORM_TOOL.LEADS]: \"LEADS\",\n [PLATFORM_TOOL.THREAD]: \"Thread\",\n [PLATFORM_TOOL.TRAIL]: \"Trail\",\n [PLATFORM_TOOL.PLATFORM]: \"Platform\",\n};\n\n// ─── Role Level (hierarchy tiers) ──────────────────────────────────\n\nexport const ROLE_LEVEL = {\n /** User-facing roles (staff, volunteers, practitioners). */\n OPERATIONAL: \"operational\",\n /** Agency-level admin roles. */\n AGENCY: \"agency\",\n /** Team-level admin roles. */\n TEAM: \"team\",\n /** HTI-wide platform admin. */\n PLATFORM: \"platform\",\n /** External governance/oversight roles. */\n OVERSIGHT: \"oversight\",\n} as const;\n\nexport type RoleLevelValue = (typeof ROLE_LEVEL)[keyof typeof ROLE_LEVEL];\n\nexport const ROLE_LEVEL_VALUES = [\n ROLE_LEVEL.OPERATIONAL,\n ROLE_LEVEL.AGENCY,\n ROLE_LEVEL.TEAM,\n ROLE_LEVEL.PLATFORM,\n ROLE_LEVEL.OVERSIGHT,\n] as const;\n\nexport const ROLE_LEVEL_LABELS: Record<RoleLevelValue, string> = {\n [ROLE_LEVEL.OPERATIONAL]: \"Operational\",\n [ROLE_LEVEL.AGENCY]: \"Agency\",\n [ROLE_LEVEL.TEAM]: \"Team\",\n [ROLE_LEVEL.PLATFORM]: \"Platform\",\n [ROLE_LEVEL.OVERSIGHT]: \"Oversight\",\n};\n\n// ─── Function Implementation Status ────────────────────────────────\n\nexport const FUNCTION_STATUS = {\n NOT_STARTED: \"Not started\",\n DEFINED_NEW: \"Defined; new function\",\n DEFINED_EXISTING: \"Defined; existing PAVE function\",\n FUNCTIONAL: \"Functional on all apps\",\n FUTURE: \"Future function (not v1)\",\n} as const;\n\nexport type FunctionStatusValue =\n (typeof FUNCTION_STATUS)[keyof typeof FUNCTION_STATUS];\n\nexport const FUNCTION_STATUS_VALUES = [\n FUNCTION_STATUS.NOT_STARTED,\n FUNCTION_STATUS.DEFINED_NEW,\n FUNCTION_STATUS.DEFINED_EXISTING,\n FUNCTION_STATUS.FUNCTIONAL,\n FUNCTION_STATUS.FUTURE,\n] as const;\n\nexport const FUNCTION_STATUS_LABELS: Record<FunctionStatusValue, string> = {\n [FUNCTION_STATUS.NOT_STARTED]: \"Not Started\",\n [FUNCTION_STATUS.DEFINED_NEW]: \"Defined (New)\",\n [FUNCTION_STATUS.DEFINED_EXISTING]: \"Defined (Existing PAVE)\",\n [FUNCTION_STATUS.FUNCTIONAL]: \"Functional\",\n [FUNCTION_STATUS.FUTURE]: \"Future (Not v1)\",\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4BA,iBAAkB;AAUX,IAAM,gBAAgB,aAAE,OAAO,EAAE,MAAM,oBAAoB;AAQ3D,IAAM,eAAe,aAAE,OAAO,EAAE,MAAM,mBAAmB;AAezD,IAAM,iBAAiB,aAC3B,OAAO;AAAA,EACN,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO,aAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACvB,YAAY,aAAE,QAAQ;AAAA,EACtB,YAAY,cAAc,SAAS;AAAA,E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AY,cACT,MAAM,iBAAiB,EACvB,OAAO,iBAAiB,mCAAmC,EAC3D,SAAS;AACd,CAAC;","names":["import_zod"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as CvcCode, a as CvcCodeSchema, b as CvcDomain,
|
|
1
|
+
export { C as CvcCode, a as CvcCodeSchema, b as CvcDomain, l as CvcEntry, c as CvcEntrySchema, d as CvcEnvelope, e as CvcEnvelopeSchema, f as CvcKey, g as CvcKeySchema, m as CvcValidationError, P as PrimaryLanguageEntry, n as PrimaryLanguageEntrySchema, S as ServiceCategoryEntry, h as ServiceCategoryEntrySchema, T as TeamApp, i as TeamAppSchema, j as TeamDirectoryFieldsInput, k as TeamDirectoryFieldsSchema, o as getCvcLevel, v as validateCvc } from '../team-C4LJ5Tex.cjs';
|
|
2
2
|
import 'zod';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as CvcCode, a as CvcCodeSchema, b as CvcDomain,
|
|
1
|
+
export { C as CvcCode, a as CvcCodeSchema, b as CvcDomain, l as CvcEntry, c as CvcEntrySchema, d as CvcEnvelope, e as CvcEnvelopeSchema, f as CvcKey, g as CvcKeySchema, m as CvcValidationError, P as PrimaryLanguageEntry, n as PrimaryLanguageEntrySchema, S as ServiceCategoryEntry, h as ServiceCategoryEntrySchema, T as TeamApp, i as TeamAppSchema, j as TeamDirectoryFieldsInput, k as TeamDirectoryFieldsSchema, o as getCvcLevel, v as validateCvc } from '../team-C4LJ5Tex.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
|
|
4
4
|
/**
|
package/dist/validation/index.js
CHANGED
|
@@ -269,6 +269,157 @@ function parseCvcStatus(envelope) {
|
|
|
269
269
|
const { maturity, ambiguous } = detectMaturity(text);
|
|
270
270
|
return { maturity, rawStatus: text, sourceIsPrototype, sourcePath, ambiguous };
|
|
271
271
|
}
|
|
272
|
+
|
|
273
|
+
// src/validation/team.ts
|
|
274
|
+
import { z as z2 } from "zod";
|
|
275
|
+
|
|
276
|
+
// src/constants/platform-auth.ts
|
|
277
|
+
var PERMISSION_STATE = {
|
|
278
|
+
/** Role can always perform this function (mandatory, cannot disable). */
|
|
279
|
+
ALWAYS: "ALWAYS",
|
|
280
|
+
/** Default On — user can opt off. */
|
|
281
|
+
PREF_YES: "PREF_YES",
|
|
282
|
+
/** Default Off — user can opt in. */
|
|
283
|
+
PREF_NO: "PREF_NO",
|
|
284
|
+
/** Role is explicitly barred from this function. */
|
|
285
|
+
NEVER: "NEVER"
|
|
286
|
+
};
|
|
287
|
+
var PERMISSION_STATE_VALUES = [
|
|
288
|
+
PERMISSION_STATE.ALWAYS,
|
|
289
|
+
PERMISSION_STATE.PREF_YES,
|
|
290
|
+
PERMISSION_STATE.PREF_NO,
|
|
291
|
+
PERMISSION_STATE.NEVER
|
|
292
|
+
];
|
|
293
|
+
var PERMISSION_STATE_LABELS = {
|
|
294
|
+
[PERMISSION_STATE.ALWAYS]: "Always",
|
|
295
|
+
[PERMISSION_STATE.PREF_YES]: "Default On",
|
|
296
|
+
[PERMISSION_STATE.PREF_NO]: "Default Off",
|
|
297
|
+
[PERMISSION_STATE.NEVER]: "Never"
|
|
298
|
+
};
|
|
299
|
+
var PERMISSION_STATE_DISPLAY = {
|
|
300
|
+
[PERMISSION_STATE.ALWAYS]: {
|
|
301
|
+
label: "Always",
|
|
302
|
+
color: "#2e7d32",
|
|
303
|
+
bgColor: "#e8f5e9",
|
|
304
|
+
icon: "\u{1F512}"
|
|
305
|
+
},
|
|
306
|
+
[PERMISSION_STATE.PREF_YES]: {
|
|
307
|
+
label: "Default On",
|
|
308
|
+
color: "#1565c0",
|
|
309
|
+
bgColor: "#e3f2fd",
|
|
310
|
+
icon: "\u{1F513}"
|
|
311
|
+
},
|
|
312
|
+
[PERMISSION_STATE.PREF_NO]: {
|
|
313
|
+
label: "Default Off",
|
|
314
|
+
color: "#e65100",
|
|
315
|
+
bgColor: "#fff3e0",
|
|
316
|
+
icon: "\u{1F513}"
|
|
317
|
+
},
|
|
318
|
+
[PERMISSION_STATE.NEVER]: {
|
|
319
|
+
label: "Never",
|
|
320
|
+
color: "#c62828",
|
|
321
|
+
bgColor: "#ffebee",
|
|
322
|
+
icon: "\u{1F512}"
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
var SHARE_VIEW = {
|
|
326
|
+
/** System metadata only (partial access). */
|
|
327
|
+
SYS_INFO: "sys_info",
|
|
328
|
+
/** Full case/record content. */
|
|
329
|
+
ALL: "all",
|
|
330
|
+
/** No data access. */
|
|
331
|
+
NONE: "none"
|
|
332
|
+
};
|
|
333
|
+
var SHARE_VIEW_VALUES = [
|
|
334
|
+
SHARE_VIEW.SYS_INFO,
|
|
335
|
+
SHARE_VIEW.ALL,
|
|
336
|
+
SHARE_VIEW.NONE
|
|
337
|
+
];
|
|
338
|
+
var SHARE_VIEW_LABELS = {
|
|
339
|
+
[SHARE_VIEW.SYS_INFO]: "System Info Only",
|
|
340
|
+
[SHARE_VIEW.ALL]: "Full Content",
|
|
341
|
+
[SHARE_VIEW.NONE]: "No Data Access"
|
|
342
|
+
};
|
|
343
|
+
var PLATFORM_TOOL = {
|
|
344
|
+
PAVE: "PAVE",
|
|
345
|
+
ECHO: "ECHO",
|
|
346
|
+
LEADS: "LEADS",
|
|
347
|
+
THREAD: "THREAD",
|
|
348
|
+
TRAIL: "TRAIL",
|
|
349
|
+
PLATFORM: "PLATFORM"
|
|
350
|
+
};
|
|
351
|
+
var PLATFORM_TOOL_VALUES = [
|
|
352
|
+
PLATFORM_TOOL.PAVE,
|
|
353
|
+
PLATFORM_TOOL.ECHO,
|
|
354
|
+
PLATFORM_TOOL.LEADS,
|
|
355
|
+
PLATFORM_TOOL.THREAD,
|
|
356
|
+
PLATFORM_TOOL.TRAIL,
|
|
357
|
+
PLATFORM_TOOL.PLATFORM
|
|
358
|
+
];
|
|
359
|
+
var PLATFORM_TOOL_LABELS = {
|
|
360
|
+
[PLATFORM_TOOL.PAVE]: "PAVE",
|
|
361
|
+
[PLATFORM_TOOL.ECHO]: "Echo",
|
|
362
|
+
[PLATFORM_TOOL.LEADS]: "LEADS",
|
|
363
|
+
[PLATFORM_TOOL.THREAD]: "Thread",
|
|
364
|
+
[PLATFORM_TOOL.TRAIL]: "Trail",
|
|
365
|
+
[PLATFORM_TOOL.PLATFORM]: "Platform"
|
|
366
|
+
};
|
|
367
|
+
var ROLE_LEVEL = {
|
|
368
|
+
/** User-facing roles (staff, volunteers, practitioners). */
|
|
369
|
+
OPERATIONAL: "operational",
|
|
370
|
+
/** Agency-level admin roles. */
|
|
371
|
+
AGENCY: "agency",
|
|
372
|
+
/** Team-level admin roles. */
|
|
373
|
+
TEAM: "team",
|
|
374
|
+
/** HTI-wide platform admin. */
|
|
375
|
+
PLATFORM: "platform",
|
|
376
|
+
/** External governance/oversight roles. */
|
|
377
|
+
OVERSIGHT: "oversight"
|
|
378
|
+
};
|
|
379
|
+
var ROLE_LEVEL_VALUES = [
|
|
380
|
+
ROLE_LEVEL.OPERATIONAL,
|
|
381
|
+
ROLE_LEVEL.AGENCY,
|
|
382
|
+
ROLE_LEVEL.TEAM,
|
|
383
|
+
ROLE_LEVEL.PLATFORM,
|
|
384
|
+
ROLE_LEVEL.OVERSIGHT
|
|
385
|
+
];
|
|
386
|
+
var ROLE_LEVEL_LABELS = {
|
|
387
|
+
[ROLE_LEVEL.OPERATIONAL]: "Operational",
|
|
388
|
+
[ROLE_LEVEL.AGENCY]: "Agency",
|
|
389
|
+
[ROLE_LEVEL.TEAM]: "Team",
|
|
390
|
+
[ROLE_LEVEL.PLATFORM]: "Platform",
|
|
391
|
+
[ROLE_LEVEL.OVERSIGHT]: "Oversight"
|
|
392
|
+
};
|
|
393
|
+
var FUNCTION_STATUS = {
|
|
394
|
+
NOT_STARTED: "Not started",
|
|
395
|
+
DEFINED_NEW: "Defined; new function",
|
|
396
|
+
DEFINED_EXISTING: "Defined; existing PAVE function",
|
|
397
|
+
FUNCTIONAL: "Functional on all apps",
|
|
398
|
+
FUTURE: "Future function (not v1)"
|
|
399
|
+
};
|
|
400
|
+
var FUNCTION_STATUS_VALUES = [
|
|
401
|
+
FUNCTION_STATUS.NOT_STARTED,
|
|
402
|
+
FUNCTION_STATUS.DEFINED_NEW,
|
|
403
|
+
FUNCTION_STATUS.DEFINED_EXISTING,
|
|
404
|
+
FUNCTION_STATUS.FUNCTIONAL,
|
|
405
|
+
FUNCTION_STATUS.FUTURE
|
|
406
|
+
];
|
|
407
|
+
var FUNCTION_STATUS_LABELS = {
|
|
408
|
+
[FUNCTION_STATUS.NOT_STARTED]: "Not Started",
|
|
409
|
+
[FUNCTION_STATUS.DEFINED_NEW]: "Defined (New)",
|
|
410
|
+
[FUNCTION_STATUS.DEFINED_EXISTING]: "Defined (Existing PAVE)",
|
|
411
|
+
[FUNCTION_STATUS.FUNCTIONAL]: "Functional",
|
|
412
|
+
[FUNCTION_STATUS.FUTURE]: "Future (Not v1)"
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// src/validation/team.ts
|
|
416
|
+
var ObjectIdHexSchema = z2.string().regex(/^[0-9a-fA-F]{24}$/, "must be a 24-character hex ObjectId");
|
|
417
|
+
var hasNoDuplicates = (values) => new Set(values.map((v) => v.toLowerCase())).size === values.length;
|
|
418
|
+
var TeamAppSchema = z2.enum(PLATFORM_TOOL_VALUES);
|
|
419
|
+
var TeamDirectoryFieldsSchema = z2.object({
|
|
420
|
+
apps: z2.array(TeamAppSchema).refine(hasNoDuplicates, "apps must not repeat an app").optional(),
|
|
421
|
+
canReferTo: z2.array(ObjectIdHexSchema).refine(hasNoDuplicates, "canReferTo must not repeat a team").optional()
|
|
422
|
+
});
|
|
272
423
|
export {
|
|
273
424
|
CvcCodeSchema,
|
|
274
425
|
CvcEntrySchema,
|
|
@@ -276,6 +427,8 @@ export {
|
|
|
276
427
|
CvcKeySchema,
|
|
277
428
|
PrimaryLanguageEntrySchema,
|
|
278
429
|
ServiceCategoryEntrySchema,
|
|
430
|
+
TeamAppSchema,
|
|
431
|
+
TeamDirectoryFieldsSchema,
|
|
279
432
|
getCvcLevel,
|
|
280
433
|
parseCvcStatus,
|
|
281
434
|
validateCvc
|