@htilabs/platform-common-models 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +86 -0
  2. package/dist/age/index.cjs +136 -0
  3. package/dist/age/index.cjs.map +1 -0
  4. package/dist/age/index.d.cts +136 -0
  5. package/dist/age/index.d.ts +136 -0
  6. package/dist/age/index.js +105 -0
  7. package/dist/age/index.js.map +1 -0
  8. package/dist/index.cjs +159 -0
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +2 -1
  11. package/dist/index.d.ts +2 -1
  12. package/dist/index.js +150 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/share-rules/index.cjs +822 -0
  15. package/dist/share-rules/index.cjs.map +1 -0
  16. package/dist/share-rules/index.d.cts +804 -0
  17. package/dist/share-rules/index.d.ts +804 -0
  18. package/dist/share-rules/index.js +736 -0
  19. package/dist/share-rules/index.js.map +1 -0
  20. package/dist/sharing-ceiling/index.cjs +51 -0
  21. package/dist/sharing-ceiling/index.cjs.map +1 -1
  22. package/dist/sharing-ceiling/index.d.cts +87 -1
  23. package/dist/sharing-ceiling/index.d.ts +87 -1
  24. package/dist/sharing-ceiling/index.js +47 -0
  25. package/dist/sharing-ceiling/index.js.map +1 -1
  26. package/package.json +12 -1
  27. package/src/age/__tests__/ageFromDob.test.ts +192 -0
  28. package/src/age/ageFromDob.ts +269 -0
  29. package/src/age/index.ts +8 -0
  30. package/src/index.ts +4 -0
  31. package/src/shareRules/__tests__/caseShareLane.test.ts +259 -0
  32. package/src/shareRules/__tests__/magicLinkAddresses.test.ts +107 -0
  33. package/src/shareRules/__tests__/platformApps.test.ts +133 -0
  34. package/src/shareRules/__tests__/releaseTerms.test.ts +358 -0
  35. package/src/shareRules/__tests__/senderRoiPosture.test.ts +284 -0
  36. package/src/shareRules/__tests__/sharingMethods.test.ts +105 -0
  37. package/src/shareRules/caseShareLane.ts +289 -0
  38. package/src/shareRules/index.ts +31 -0
  39. package/src/shareRules/magicLinkAddresses.ts +185 -0
  40. package/src/shareRules/platformApps.ts +168 -0
  41. package/src/shareRules/releaseTerms.ts +359 -0
  42. package/src/shareRules/reportPurposes.ts +50 -0
  43. package/src/shareRules/senderRoiPosture.ts +296 -0
  44. package/src/shareRules/sharingMethods.ts +204 -0
  45. package/src/sharingCeiling/__tests__/threadLift.test.ts +353 -0
  46. package/src/sharingCeiling/coverage.ts +63 -0
  47. package/src/sharingCeiling/defaults.ts +106 -0
  48. package/src/sharingCeiling/index.ts +7 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/age/ageFromDob.ts"],"sourcesContent":["/**\n * Age from a date of birth — the ONE rule every HTI app uses.\n *\n * Before this module, Thread and PAVE computed age from a date of birth in six\n * hand-kept places with three different answers when the date of birth was\n * incomplete. A person entered with birth year 2008 and no month showed as 17\n * (a minor) on PAVE's profile but as 18 to PAVE's risk calculation, so the\n * minor risk input never fired. Every app now calls {@link ageFromDob}.\n *\n * The rule is the prototype's `deriveYearsFromDob` (HTI-LEADS-PAVE-Thread\n * prototype, Crysta directive 2026-04-28), which PAVE ported verbatim to\n * `packages/domain/src/personAge.ts`:\n *\n * - Whole years between the birth date and `today`.\n * - When we cannot tell whether this year's birthday has happened yet —\n * the month is unknown, or it is the birth month and the day is unknown —\n * count the person YOUNGER (assume the birthday has not happened). At the\n * 12/13 and 17/18 boundaries this picks the cautious, protective reading.\n * - No year → no age.\n * - A person who is known to be born is never \"no age\": counting younger\n * never takes the age below 0 (an infant entered with only this year as\n * the birth year is 0, a minor). Only a date of birth that is after\n * `today` — at the precision it is known — has no age.\n *\n * `today` is a calendar date the CALLER chooses (Crysta's date rule: moments\n * are stored as UTC, calendar days are local — so which day it is depends on\n * whose day you mean). Pass `{ y, m, d }`; in a server, compute it for the\n * zone you mean rather than passing `new Date()`, so the server and the\n * browser agree on a birthday evening. A `Date` is also accepted and read as\n * a calendar date (see {@link calendarDateOf}).\n *\n * A date-of-birth string is parsed into its year / month / day parts, never\n * through `new Date(string)` — that anchors \"YYYY-MM-DD\" to UTC midnight and,\n * read back with local getters, lands one day early in every negative-UTC\n * zone (the prototype's DATE-CANON note, 2026-08-25).\n *\n * Pure TypeScript: no mongoose, no I/O. Browser consumers import it from the\n * `@htilabs/platform-common-models/age` subpath.\n */\n\n/** A date of birth that may be partial: any of month, day and year can be unknown. */\nexport interface PartialDob {\n /** Month 1–12, or `null` when unknown. */\n m: number | null;\n /** Day 1–31, or `null` when unknown. */\n d: number | null;\n /** Four-digit year, or `null` when unknown. */\n y: number | null;\n}\n\n/**\n * Loose partial-DOB input: any subset of `{ m, d, y }`, as numbers or numeric\n * strings (what a form control hands back). A blank string is \"unknown\".\n */\nexport interface PartialDobLike {\n m?: number | string | null;\n d?: number | string | null;\n y?: number | string | null;\n}\n\n/**\n * Every date-of-birth shape {@link ageFromDob} accepts: the partial object; a\n * JS `Date` (a full date, read as a calendar date — see {@link calendarDateOf});\n * an ISO string `\"YYYY\"`, `\"YYYY-MM\"` or `\"YYYY-MM-DD\"` (precision by length; a\n * time suffix after the day is ignored); or the app-persisted `\"MM/DD/YYYY\"`\n * string with any part blank (`\"/05/1990\"`, `\"//2008\"`).\n */\nexport type DobLike = PartialDobLike | Date | string | null | undefined;\n\n/** A full calendar date: year, month 1–12, day 1–31. */\nexport interface CalendarDate {\n y: number;\n m: number;\n d: number;\n}\n\n/** The `today` argument of {@link ageFromDob}: a calendar date, or a `Date` read as one. */\nexport type CalendarDateLike = CalendarDate | Date;\n\n/** Earliest birth year the rule accepts (the prototype's floor). */\nexport const DOB_MIN_YEAR = 1850;\n\nfunction toNullableNumber(v: number | string | null | undefined): number | null {\n if (v == null) return null;\n if (typeof v === \"string\" && v.trim() === \"\") return null;\n const n = typeof v === \"number\" ? v : Number(v);\n return Number.isFinite(n) ? n : null;\n}\n\n/** A month outside 1–12 is not a month. */\nfunction toNullableMonth(v: number | string | null | undefined): number | null {\n const n = toNullableNumber(v);\n return n != null && n >= 1 && n <= 12 ? n : null;\n}\n\n/** A day outside 1–31 is not a day. */\nfunction toNullableDay(v: number | string | null | undefined): number | null {\n const n = toNullableNumber(v);\n return n != null && n >= 1 && n <= 31 ? n : null;\n}\n\n/** A year must be a positive whole number. */\nfunction toNullableYear(v: number | string | null | undefined): number | null {\n const n = toNullableNumber(v);\n return n != null && Number.isInteger(n) && n > 0 ? n : null;\n}\n\nfunction isDate(v: unknown): v is Date {\n return v instanceof Date || Object.prototype.toString.call(v) === \"[object Date]\";\n}\n\n/**\n * The calendar date a `Date` stands for, or `null` for an invalid `Date`.\n *\n * A `Date` at exactly UTC midnight is read by its UTC parts: that is how a\n * calendar date is stored (mongoose / JSON `\"2008-03-01T00:00:00.000Z\"`), and\n * local getters would land a day early west of UTC. Any other `Date` is read\n * by its local parts — `new Date(2008, 2, 1)` is 1 March in every zone, and\n * `new Date()` is the local day of the process that made it.\n *\n * A `Date` date of birth must be stored as UTC midnight. A local-midnight\n * `Date` made in a zone east of UTC is NOT supported: `new Date(2000, 2, 1)`\n * made in Berlin is `2000-02-29T23:00Z` and reads as 29 February on a UTC\n * server — one day early, so the person is counted older the day before the\n * birthday. The zone it was made in is lost, so no rule can recover it; prefer\n * `{ y, m, d }` or {@link ageInputFromStoredDob}.\n */\nexport function calendarDateOf(date: Date): CalendarDate | null {\n if (Number.isNaN(date.getTime())) return null;\n const utcMidnight =\n date.getUTCHours() === 0 &&\n date.getUTCMinutes() === 0 &&\n date.getUTCSeconds() === 0 &&\n date.getUTCMilliseconds() === 0;\n return utcMidnight\n ? { y: date.getUTCFullYear(), m: date.getUTCMonth() + 1, d: date.getUTCDate() }\n : { y: date.getFullYear(), m: date.getMonth() + 1, d: date.getDate() };\n}\n\n/**\n * The `{ dobYear, dobMonth, dobDay }` strings as stored on the demographics\n * sub-schema (`schemas/common.ts`), lifted into the `{ y, m, d }` input of\n * {@link ageFromDob}. Use it instead of mapping the fields by hand.\n */\nexport function ageInputFromStoredDob(stored: {\n dobYear?: string | number | null;\n dobMonth?: string | number | null;\n dobDay?: string | number | null;\n} | null | undefined): PartialDobLike {\n return { y: stored?.dobYear ?? null, m: stored?.dobMonth ?? null, d: stored?.dobDay ?? null };\n}\n\n/**\n * Lifts any accepted date-of-birth shape into `{ m, d, y }` (each part a number\n * or `null`), or `null` when nothing usable is present. An unrecognised string\n * returns `null` rather than risking an engine-dependent `new Date()` parse.\n */\nexport function normalizeDob(dobLike: DobLike): PartialDob | null {\n if (dobLike == null) return null;\n\n if (isDate(dobLike)) return calendarDateOf(dobLike);\n\n if (typeof dobLike === \"object\") {\n const m = toNullableMonth(dobLike.m);\n const d = toNullableDay(dobLike.d);\n const y = toNullableYear(dobLike.y);\n if (m == null && d == null && y == null) return null;\n return { m, d, y };\n }\n\n if (typeof dobLike === \"string\") {\n const s = dobLike.trim();\n if (!s) return null;\n\n const iso = /^(\\d{4})-(\\d{1,2})-(\\d{1,2})/.exec(s);\n if (iso) {\n return {\n y: toNullableYear(iso[1]),\n m: toNullableMonth(iso[2]),\n d: toNullableDay(iso[3]),\n };\n }\n\n // Partial ISO: \"YYYY-MM\" (day unknown) and \"YYYY\" (month and day unknown).\n const isoPartial = /^(\\d{4})(?:-(\\d{1,2}))?$/.exec(s);\n if (isoPartial) {\n const y = toNullableYear(isoPartial[1]);\n return y == null ? null : { y, m: toNullableMonth(isoPartial[2]), d: null };\n }\n\n const slash = /^(\\d{0,2})\\/(\\d{0,2})\\/(\\d{0,4})$/.exec(s);\n if (slash) {\n const m = toNullableMonth(slash[1]);\n const d = toNullableDay(slash[2]);\n const y = toNullableYear(slash[3]);\n if (m == null && d == null && y == null) return null;\n return { m, d, y };\n }\n\n return null;\n }\n\n return null;\n}\n\n/**\n * Whole years of age on `today`, from a full or partial date of birth — or\n * `null` when there is no usable year, the year is before {@link DOB_MIN_YEAR},\n * or the birth is after `today` at the precision it is known (a later year; this\n * year and a later month; this month and a later day). `null` also for an\n * invalid `today`.\n *\n * When it cannot be told whether this year's birthday has passed (no month, or\n * the birth month with no day), the person is counted younger — but never below\n * 0: a person known to be born is age 0 at least.\n *\n * A `Date` date of birth must be stored as UTC midnight (see\n * {@link calendarDateOf}); prefer `{ y, m, d }` or {@link ageInputFromStoredDob}.\n *\n * `today` is the calendar date the caller means — `{ y, m, d }`, or a `Date`\n * read by {@link calendarDateOf}. In a server, pass `{ y, m, d }` for the zone\n * you mean, not `new Date()` (which is the server's local, usually UTC, day).\n *\n * @example\n * // On 2026-10-24:\n * ageFromDob({ y: 2008 }, today) // 17 — month unknown, count younger\n * ageFromDob({ y: 2008, m: 10 }, today) // 17 — birth month, day unknown\n * ageFromDob({ y: 2008, m: 10, d: 24 }, today) // 18 — birthday is today\n * ageFromDob(\"2008-03-01\", today) // 18\n */\nexport function ageFromDob(dob: DobLike, today: CalendarDateLike): number | null {\n const parts = normalizeDob(dob);\n if (!parts || parts.y == null) return null;\n\n const t = isDate(today) ? calendarDateOf(today) : today;\n if (\n t == null ||\n !Number.isInteger(t.y) ||\n toNullableMonth(t.m) == null ||\n toNullableDay(t.d) == null\n ) {\n return null;\n }\n const todayY = t.y;\n const todayM = t.m;\n const todayD = t.d;\n if (parts.y < DOB_MIN_YEAR) return null;\n\n // Born after today, at the precision the date of birth is known → no age.\n if (parts.y > todayY) return null;\n if (parts.y === todayY && parts.m != null) {\n if (parts.m > todayM) return null;\n if (parts.m === todayM && parts.d != null && parts.d > todayD) return null;\n }\n\n let birthdayPassed: boolean;\n if (parts.m == null) {\n birthdayPassed = false; // month unknown → count younger\n } else if (parts.m < todayM) {\n birthdayPassed = true;\n } else if (parts.m > todayM) {\n birthdayPassed = false;\n } else {\n birthdayPassed = parts.d == null ? false : parts.d <= todayD; // day unknown → count younger\n }\n\n // Known to be born (checked above), so counting younger stops at 0.\n return Math.max(0, todayY - parts.y - (birthdayPassed ? 0 : 1));\n}\n"],"mappings":";AAgFO,IAAM,eAAe;AAE5B,SAAS,iBAAiB,GAAsD;AAC9E,MAAI,KAAK,KAAM,QAAO;A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QAAO;AAEtC,QAAM,IAAI,OAAO,KAAK,IAAI,eAAe,KAAK,IAAI;AAClD,MACE,KAAK,QACL,CAAC,OAAO,UAAU,EAAE,CAAC,KACrB,gBAAgB,EAAE,CAAC,KAAK,QACxB,cAAc,EAAE,CAAC,KAAK,MACtB;AACA,WAAO;AAAA,EACT;AACA,QAAM,SAAS,EAAE;AACjB,QAAM,SAAS,EAAE;AACjB,QAAM,SAAS,EAAE;AACjB,MAAI,MAAM,IAAI,aAAc,QAAO;AAGnC,MAAI,MAAM,IAAI,OAAQ,QAAO;AAC7B,MAAI,MAAM,MAAM,UAAU,MAAM,KAAK,MAAM;AACzC,QAAI,MAAM,IAAI,OAAQ,QAAO;AAC7B,QAAI,MAAM,MAAM,UAAU,MAAM,KAAK,QAAQ,MAAM,IAAI,OAAQ,QAAO;AAAA,EACxE;AAEA,MAAI;AACJ,MAAI,MAAM,KAAK,MAAM;AACnB,qBAAiB;AAAA,EACnB,WAAW,MAAM,IAAI,QAAQ;AAC3B,qBAAiB;AAAA,EACnB,WAAW,MAAM,IAAI,QAAQ;AAC3B,qBAAiB;AAAA,EACnB,OAAO;AACL,qBAAiB,MAAM,KAAK,OAAO,QAAQ,MAAM,KAAK;AAAA,EACxD;AAGA,SAAO,KAAK,IAAI,GAAG,SAAS,MAAM,KAAK,iBAAiB,IAAI,EAAE;AAChE;","names":[]}
package/dist/index.cjs CHANGED
@@ -231,6 +231,7 @@ __export(src_exports, {
231
231
  DEFAULT_BOUND_STATE_LABELS: () => DEFAULT_BOUND_STATE_LABELS,
232
232
  DEFAULT_BOUND_STATE_VALUES: () => DEFAULT_BOUND_STATE_VALUES,
233
233
  DEFAULT_PARTICIPATION_ROLE_BY_CATEGORY: () => DEFAULT_PARTICIPATION_ROLE_BY_CATEGORY,
234
+ DOB_MIN_YEAR: () => DOB_MIN_YEAR,
234
235
  DaIncidentArchiveReasonKeys: () => DaIncidentArchiveReasonKeys,
235
236
  DaIncidentConfidenceKeys: () => DaIncidentConfidenceKeys,
236
237
  DaIncidentDayApproxKeys: () => DaIncidentDayApproxKeys,
@@ -540,6 +541,7 @@ __export(src_exports, {
540
541
  WHY_NOT_REPORTING_AXES: () => WHY_NOT_REPORTING_AXES,
541
542
  WhyNotKeys: () => WhyNotKeys,
542
543
  accommodationTypeSot: () => accommodationType_v1_0_0_default,
544
+ accountSharePurposePolicy: () => accountSharePurposePolicy,
543
545
  actionStepCompletionStatusSot: () => actionStepCompletionStatus_v1_0_0_default,
544
546
  actionStepTypeSot: () => actionStepType_v1_0_0_default,
545
547
  activityTypeSot: () => activityType_v1_0_0_default,
@@ -551,6 +553,8 @@ __export(src_exports, {
551
553
  adminRolesSot: () => adminRoles_v2_0_0_default,
552
554
  administeringJurisdictionSot: () => administeringJurisdiction_v1_0_0_default,
553
555
  ageBinReportingSot: () => ageBinReporting_v1_0_0_default,
556
+ ageFromDob: () => ageFromDob,
557
+ ageInputFromStoredDob: () => ageInputFromStoredDob,
554
558
  agencyOrgTypeSchemaDefinition: () => agencyOrgTypeSchemaDefinition,
555
559
  announcementAudienceScopeSot: () => announcementAudienceScope_v1_0_0_default,
556
560
  announcementResponseTypeSot: () => announcementResponseType_v1_0_0_default,
@@ -569,6 +573,7 @@ __export(src_exports, {
569
573
  buildQuestionSchema: () => buildQuestionSchema,
570
574
  buildScoringRuleSchema: () => buildScoringRuleSchema,
571
575
  buildSectionSchema: () => buildSectionSchema,
576
+ calendarDateOf: () => calendarDateOf,
572
577
  canonicalCoreIndicator: () => canonicalCoreIndicator,
573
578
  canonicalIncidentParticipationRole: () => canonicalIncidentParticipationRole,
574
579
  canonicalServiceState: () => canonicalServiceState,
@@ -679,6 +684,7 @@ __export(src_exports, {
679
684
  incidentParticipationRolesSot: () => incidentParticipationRoles_v1_1_0_default,
680
685
  incomeBenefitsSourcesSot: () => incomeBenefitsSources_v1_1_0_default,
681
686
  inferenceTypeSot: () => inferenceType_v1_0_0_default,
687
+ intersectSharingCeilingLists: () => intersectSharingCeilingLists,
682
688
  investigativeRequestTypeSot: () => investigativeRequestType_v1_0_0_default,
683
689
  isAgencyTypeKey: () => isAgencyTypeKey,
684
690
  isCanonEvaluableFunction: () => isCanonEvaluableFunction,
@@ -695,6 +701,7 @@ __export(src_exports, {
695
701
  isLiveOrganizationProgram: () => isLiveOrganizationProgram,
696
702
  isNeverPickableServiceMechanism: () => isNeverPickableServiceMechanism,
697
703
  isOrgTypeKey: () => isOrgTypeKey,
704
+ isPermittedByCeiling: () => isPermittedByCeiling,
698
705
  isProgramReviewStatus: () => isProgramReviewStatus,
699
706
  isProtectedRelationship: () => isProtectedRelationship,
700
707
  isReportAuthorityOrgType: () => isReportAuthorityOrgType,
@@ -728,6 +735,7 @@ __export(src_exports, {
728
735
  nameTypeSot: () => nameType_v1_0_0_default,
729
736
  needsAssessmentChangeTypeSot: () => needsAssessmentChangeType_v1_0_0_default,
730
737
  needsResidentialAgainSot: () => needsResidentialAgain_v1_0_0_default,
738
+ normalizeDob: () => normalizeDob,
731
739
  normalizeServiceMechanismKeys: () => normalizeServiceMechanismKeys,
732
740
  normalizeServiceStampId: () => normalizeServiceStampId,
733
741
  normalizeServiceStamps: () => normalizeServiceStamps,
@@ -837,6 +845,7 @@ __export(src_exports, {
837
845
  severityFollowUpSot: () => severityFollowUp_v1_0_0_default,
838
846
  sexProviderSubroleSot: () => sexProviderSubrole_v1_0_0_default,
839
847
  shareCadenceSot: () => shareCadence_v1_0_0_default,
848
+ shareDefaultScopeFor: () => shareDefaultScopeFor,
840
849
  sharePurposeSot: () => sharePurpose_v1_0_0_default,
841
850
  shareResponseReasonSot: () => shareResponseReason_v1_0_0_default,
842
851
  sharingCeilingCellList: () => sharingCeilingCellList,
@@ -15749,6 +15758,104 @@ function scopeMigrationsFromSot(sot) {
15749
15758
  });
15750
15759
  }
15751
15760
 
15761
+ // src/age/ageFromDob.ts
15762
+ var DOB_MIN_YEAR = 1850;
15763
+ function toNullableNumber(v) {
15764
+ if (v == null) return null;
15765
+ if (typeof v === "string" && v.trim() === "") return null;
15766
+ const n = typeof v === "number" ? v : Number(v);
15767
+ return Number.isFinite(n) ? n : null;
15768
+ }
15769
+ function toNullableMonth(v) {
15770
+ const n = toNullableNumber(v);
15771
+ return n != null && n >= 1 && n <= 12 ? n : null;
15772
+ }
15773
+ function toNullableDay(v) {
15774
+ const n = toNullableNumber(v);
15775
+ return n != null && n >= 1 && n <= 31 ? n : null;
15776
+ }
15777
+ function toNullableYear(v) {
15778
+ const n = toNullableNumber(v);
15779
+ return n != null && Number.isInteger(n) && n > 0 ? n : null;
15780
+ }
15781
+ function isDate(v) {
15782
+ return v instanceof Date || Object.prototype.toString.call(v) === "[object Date]";
15783
+ }
15784
+ function calendarDateOf(date) {
15785
+ if (Number.isNaN(date.getTime())) return null;
15786
+ const utcMidnight = date.getUTCHours() === 0 && date.getUTCMinutes() === 0 && date.getUTCSeconds() === 0 && date.getUTCMilliseconds() === 0;
15787
+ return utcMidnight ? { y: date.getUTCFullYear(), m: date.getUTCMonth() + 1, d: date.getUTCDate() } : { y: date.getFullYear(), m: date.getMonth() + 1, d: date.getDate() };
15788
+ }
15789
+ function ageInputFromStoredDob(stored) {
15790
+ return { y: stored?.dobYear ?? null, m: stored?.dobMonth ?? null, d: stored?.dobDay ?? null };
15791
+ }
15792
+ function normalizeDob(dobLike) {
15793
+ if (dobLike == null) return null;
15794
+ if (isDate(dobLike)) return calendarDateOf(dobLike);
15795
+ if (typeof dobLike === "object") {
15796
+ const m = toNullableMonth(dobLike.m);
15797
+ const d = toNullableDay(dobLike.d);
15798
+ const y = toNullableYear(dobLike.y);
15799
+ if (m == null && d == null && y == null) return null;
15800
+ return { m, d, y };
15801
+ }
15802
+ if (typeof dobLike === "string") {
15803
+ const s = dobLike.trim();
15804
+ if (!s) return null;
15805
+ const iso = /^(\d{4})-(\d{1,2})-(\d{1,2})/.exec(s);
15806
+ if (iso) {
15807
+ return {
15808
+ y: toNullableYear(iso[1]),
15809
+ m: toNullableMonth(iso[2]),
15810
+ d: toNullableDay(iso[3])
15811
+ };
15812
+ }
15813
+ const isoPartial = /^(\d{4})(?:-(\d{1,2}))?$/.exec(s);
15814
+ if (isoPartial) {
15815
+ const y = toNullableYear(isoPartial[1]);
15816
+ return y == null ? null : { y, m: toNullableMonth(isoPartial[2]), d: null };
15817
+ }
15818
+ const slash = /^(\d{0,2})\/(\d{0,2})\/(\d{0,4})$/.exec(s);
15819
+ if (slash) {
15820
+ const m = toNullableMonth(slash[1]);
15821
+ const d = toNullableDay(slash[2]);
15822
+ const y = toNullableYear(slash[3]);
15823
+ if (m == null && d == null && y == null) return null;
15824
+ return { m, d, y };
15825
+ }
15826
+ return null;
15827
+ }
15828
+ return null;
15829
+ }
15830
+ function ageFromDob(dob, today) {
15831
+ const parts = normalizeDob(dob);
15832
+ if (!parts || parts.y == null) return null;
15833
+ const t = isDate(today) ? calendarDateOf(today) : today;
15834
+ if (t == null || !Number.isInteger(t.y) || toNullableMonth(t.m) == null || toNullableDay(t.d) == null) {
15835
+ return null;
15836
+ }
15837
+ const todayY = t.y;
15838
+ const todayM = t.m;
15839
+ const todayD = t.d;
15840
+ if (parts.y < DOB_MIN_YEAR) return null;
15841
+ if (parts.y > todayY) return null;
15842
+ if (parts.y === todayY && parts.m != null) {
15843
+ if (parts.m > todayM) return null;
15844
+ if (parts.m === todayM && parts.d != null && parts.d > todayD) return null;
15845
+ }
15846
+ let birthdayPassed;
15847
+ if (parts.m == null) {
15848
+ birthdayPassed = false;
15849
+ } else if (parts.m < todayM) {
15850
+ birthdayPassed = true;
15851
+ } else if (parts.m > todayM) {
15852
+ birthdayPassed = false;
15853
+ } else {
15854
+ birthdayPassed = parts.d == null ? false : parts.d <= todayD;
15855
+ }
15856
+ return Math.max(0, todayY - parts.y - (birthdayPassed ? 0 : 1));
15857
+ }
15858
+
15752
15859
  // src/generated/coreFunctionsEvaluable.ts
15753
15860
  var CORE_FUNCTIONS_EVALUABLE_KEYS = [
15754
15861
  "agency_info_manage",
@@ -16499,6 +16606,49 @@ function maskSelectionToCeiling(scope, selection, allowed) {
16499
16606
  for (const code of outside) sel = subtractRow(scope, sel, code);
16500
16607
  return withSystemInfo(sel.filter((c) => facts.isLive(c)));
16501
16608
  }
16609
+ function isPermittedByCeiling(scope, ceiling, code) {
16610
+ if (ceiling === null || ceiling.allowed === null) return true;
16611
+ if (scope.ancestorsOf(code).includes("system")) {
16612
+ return true;
16613
+ }
16614
+ if (scope.row(code) === void 0) return false;
16615
+ return scopeRowWithinCeiling(scope, ceiling.allowed, code);
16616
+ }
16617
+ function intersectSharingCeilingLists(scope, a, b) {
16618
+ const left = [...a];
16619
+ const right = [...b];
16620
+ const within = (list, code) => scopeRowWithinCeiling(scope, list, code);
16621
+ return [
16622
+ .../* @__PURE__ */ new Set([
16623
+ ...left.filter((code) => within(right, code)),
16624
+ ...right.filter((code) => within(left, code))
16625
+ ])
16626
+ ];
16627
+ }
16628
+
16629
+ // src/sharingCeiling/defaults.ts
16630
+ function shareDefaultScopeFor(edits, purpose, opts = {}) {
16631
+ const off = isSharingPurposeDisabled(purpose, opts.purposeOverrides ?? null);
16632
+ if (off || edits === null || edits === void 0) {
16633
+ return { off, accountDefault: [] };
16634
+ }
16635
+ const starter = opts.starter ?? HTI_SHARE_PLATFORM_STARTER;
16636
+ const authored = edits[SHARING_CEILING_DEFAULT_ROW_KEY]?.[purpose];
16637
+ if (Array.isArray(authored)) {
16638
+ return {
16639
+ off,
16640
+ accountDefault: authored.filter(
16641
+ (v) => typeof v === "string"
16642
+ )
16643
+ };
16644
+ }
16645
+ const platform = starter.scopeByPurpose[purpose];
16646
+ return {
16647
+ off,
16648
+ accountDefault: Array.isArray(platform) ? platform.filter((v) => typeof v === "string") : []
16649
+ };
16650
+ }
16651
+ var accountSharePurposePolicy = shareDefaultScopeFor;
16502
16652
 
16503
16653
  // src/validation/cvc.ts
16504
16654
  var import_zod = require("zod");
@@ -69356,6 +69506,7 @@ var CVC_197_VALUES = selectableCodes(
69356
69506
  DEFAULT_BOUND_STATE_LABELS,
69357
69507
  DEFAULT_BOUND_STATE_VALUES,
69358
69508
  DEFAULT_PARTICIPATION_ROLE_BY_CATEGORY,
69509
+ DOB_MIN_YEAR,
69359
69510
  DaIncidentArchiveReasonKeys,
69360
69511
  DaIncidentConfidenceKeys,
69361
69512
  DaIncidentDayApproxKeys,
@@ -69665,6 +69816,7 @@ var CVC_197_VALUES = selectableCodes(
69665
69816
  WHY_NOT_REPORTING_AXES,
69666
69817
  WhyNotKeys,
69667
69818
  accommodationTypeSot,
69819
+ accountSharePurposePolicy,
69668
69820
  actionStepCompletionStatusSot,
69669
69821
  actionStepTypeSot,
69670
69822
  activityTypeSot,
@@ -69676,6 +69828,8 @@ var CVC_197_VALUES = selectableCodes(
69676
69828
  adminRolesSot,
69677
69829
  administeringJurisdictionSot,
69678
69830
  ageBinReportingSot,
69831
+ ageFromDob,
69832
+ ageInputFromStoredDob,
69679
69833
  agencyOrgTypeSchemaDefinition,
69680
69834
  announcementAudienceScopeSot,
69681
69835
  announcementResponseTypeSot,
@@ -69694,6 +69848,7 @@ var CVC_197_VALUES = selectableCodes(
69694
69848
  buildQuestionSchema,
69695
69849
  buildScoringRuleSchema,
69696
69850
  buildSectionSchema,
69851
+ calendarDateOf,
69697
69852
  canonicalCoreIndicator,
69698
69853
  canonicalIncidentParticipationRole,
69699
69854
  canonicalServiceState,
@@ -69804,6 +69959,7 @@ var CVC_197_VALUES = selectableCodes(
69804
69959
  incidentParticipationRolesSot,
69805
69960
  incomeBenefitsSourcesSot,
69806
69961
  inferenceTypeSot,
69962
+ intersectSharingCeilingLists,
69807
69963
  investigativeRequestTypeSot,
69808
69964
  isAgencyTypeKey,
69809
69965
  isCanonEvaluableFunction,
@@ -69820,6 +69976,7 @@ var CVC_197_VALUES = selectableCodes(
69820
69976
  isLiveOrganizationProgram,
69821
69977
  isNeverPickableServiceMechanism,
69822
69978
  isOrgTypeKey,
69979
+ isPermittedByCeiling,
69823
69980
  isProgramReviewStatus,
69824
69981
  isProtectedRelationship,
69825
69982
  isReportAuthorityOrgType,
@@ -69853,6 +70010,7 @@ var CVC_197_VALUES = selectableCodes(
69853
70010
  nameTypeSot,
69854
70011
  needsAssessmentChangeTypeSot,
69855
70012
  needsResidentialAgainSot,
70013
+ normalizeDob,
69856
70014
  normalizeServiceMechanismKeys,
69857
70015
  normalizeServiceStampId,
69858
70016
  normalizeServiceStamps,
@@ -69962,6 +70120,7 @@ var CVC_197_VALUES = selectableCodes(
69962
70120
  severityFollowUpSot,
69963
70121
  sexProviderSubroleSot,
69964
70122
  shareCadenceSot,
70123
+ shareDefaultScopeFor,
69965
70124
  sharePurposeSot,
69966
70125
  shareResponseReasonSot,
69967
70126
  sharingCeilingCellList,