@htilabs/platform-common-models 0.41.0 → 0.42.1

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/index.cjs CHANGED
@@ -270,6 +270,7 @@ __export(src_exports, {
270
270
  GoalWithdrawalReasonKeys: () => GoalWithdrawalReasonKeys,
271
271
  HEALTHCARE_ORG_TYPE_KEYS: () => HEALTHCARE_ORG_TYPE_KEYS,
272
272
  HTI_SHARE_PLATFORM_PURPOSE_ENABLED: () => HTI_SHARE_PLATFORM_PURPOSE_ENABLED,
273
+ HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE: () => HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE,
273
274
  HTI_SHARE_PLATFORM_STARTER: () => HTI_SHARE_PLATFORM_STARTER,
274
275
  HTI_SHARE_PLATFORM_STARTER_SOURCE: () => HTI_SHARE_PLATFORM_STARTER_SOURCE,
275
276
  HairColorKeys: () => HairColorKeys,
@@ -470,6 +471,10 @@ __export(src_exports, {
470
471
  SERVICE_STATE_STAMP_CROSSWALK: () => SERVICE_STATE_STAMP_CROSSWALK,
471
472
  SESSION_STATES: () => SESSION_STATES,
472
473
  SESSION_STATE_LABELS: () => SESSION_STATE_LABELS,
474
+ SHARE_LEVEL_LABEL: () => SHARE_LEVEL_LABEL,
475
+ SHARE_PLATFORM_STATE_LABEL: () => SHARE_PLATFORM_STATE_LABEL,
476
+ SHARE_POSTURE_RANK: () => SHARE_POSTURE_RANK,
477
+ SHARE_REPORTING_PURPOSES: () => SHARE_REPORTING_PURPOSES,
473
478
  SHARE_VIEW: () => SHARE_VIEW,
474
479
  SHARE_VIEW_LABELS: () => SHARE_VIEW_LABELS,
475
480
  SHARE_VIEW_VALUES: () => SHARE_VIEW_VALUES,
@@ -562,6 +567,7 @@ __export(src_exports, {
562
567
  applyRunValidatorsIfUnset: () => applyRunValidatorsIfUnset,
563
568
  assertionDomainSot: () => assertionDomain_v1_1_0_default,
564
569
  assertionStatusSot: () => assertionStatus_v2_0_0_default,
570
+ attachmentIndexFromPolicies: () => attachmentIndexFromPolicies,
565
571
  basisQuickPicksSot: () => basisQuickPicks_v1_0_0_default,
566
572
  buildCvcEntrySchema: () => buildCvcEntrySchema,
567
573
  buildCvcRegistrySchema: () => buildCvcRegistrySchema,
@@ -619,6 +625,7 @@ __export(src_exports, {
619
625
  daIncidentSeveritySot: () => daIncidentSeverity_v1_0_0_default,
620
626
  demographicsSchema: () => demographicsSchema,
621
627
  deriveAgeBinFromAge: () => deriveAgeBinFromAge,
628
+ derivePlatformDefault: () => derivePlatformDefault,
622
629
  determinationHelperCategoriesSot: () => determinationHelperCategories_v1_0_0_default,
623
630
  determinationLevelSot: () => determinationLevel_v1_0_0_default,
624
631
  disabilitySubtypeSot: () => disabilitySubtype_v1_0_0_default,
@@ -720,10 +727,12 @@ __export(src_exports, {
720
727
  layoutSchema: () => layoutSchema,
721
728
  leReportStatusSot: () => leReportStatus_v1_0_0_default,
722
729
  legalActionTypeSot: () => legalActionType_v1_0_0_default,
730
+ liveCategories: () => liveCategories,
723
731
  livingSituationSot: () => livingSituation_v1_0_0_default,
724
732
  locationTypeSot: () => locationType_v1_0_0_default,
725
733
  maritalStatusLegalSot: () => maritalStatusLegal_v1_0_0_default,
726
734
  maskSelectionToCeiling: () => maskSelectionToCeiling,
735
+ matchTeamRow: () => matchTeamRow,
727
736
  mentalHealthStatusSot: () => mentalHealthStatus_v1_0_0_default,
728
737
  messageReportReasonSot: () => messageReportReason_v1_0_0_default,
729
738
  midStayEventTypeSot: () => midStayEventType_v1_0_0_default,
@@ -760,6 +769,7 @@ __export(src_exports, {
760
769
  petExitReasonSot: () => petExitReason_v1_0_0_default,
761
770
  petRelationshipBasisSot: () => petRelationshipBasis_v1_0_0_default,
762
771
  phoneSchema: () => phoneSchema,
772
+ platformDefaultFor: () => platformDefaultFor,
763
773
  platformFunctionModel: () => platformFunctionModel_exports,
764
774
  platformFunctionSchemaDefinition: () => platformFunctionSchemaDefinition,
765
775
  platformFunctionSchemaOptions: () => platformFunctionSchemaOptions,
@@ -800,6 +810,7 @@ __export(src_exports, {
800
810
  resolveOrgTypeKeyFromLegacyNumeric: () => resolveOrgTypeKeyFromLegacyNumeric,
801
811
  resolveReferralEntityKeyFromLegacyNumeric: () => resolveReferralEntityKeyFromLegacyNumeric,
802
812
  resolveRegistryWithInheritance: () => resolveRegistryWithInheritance,
813
+ resolveShare: () => resolveShare,
803
814
  returnedToAbuserStatusSot: () => returnedToAbuserStatus_v1_0_0_default,
804
815
  riskCategorySot: () => riskCategory_v1_0_0_default,
805
816
  riskIdentificationMilestoneSot: () => riskIdentificationMilestone_v1_0_0_default,
@@ -813,6 +824,8 @@ __export(src_exports, {
813
824
  rowsOutsideCeiling: () => rowsOutsideCeiling,
814
825
  rowsOverCeiling: () => rowsOverCeiling,
815
826
  rsvpResponseSot: () => rsvpResponse_v1_0_0_default,
827
+ scopeListCovers: () => scopeListCovers,
828
+ scopeListStrictlyCovers: () => scopeListStrictlyCovers,
816
829
  scopeMigrationsFromSot: () => scopeMigrationsFromSot,
817
830
  scopeRowWithinCeiling: () => scopeRowWithinCeiling,
818
831
  scopeRowsFromSot: () => scopeRowsFromSot,
@@ -848,6 +861,7 @@ __export(src_exports, {
848
861
  shareDefaultScopeFor: () => shareDefaultScopeFor,
849
862
  sharePurposeSot: () => sharePurpose_v1_0_0_default,
850
863
  shareResponseReasonSot: () => shareResponseReason_v1_0_0_default,
864
+ shareRowCeiling: () => shareRowCeiling,
851
865
  sharingCeilingCellList: () => sharingCeilingCellList,
852
866
  sharingCeilingRowKey: () => sharingCeilingRowKey,
853
867
  sharingScopeEditsFromCells: () => sharingScopeEditsFromCells,
@@ -868,6 +882,7 @@ __export(src_exports, {
868
882
  suggestionSourceSot: () => suggestionSource_v1_0_0_default,
869
883
  supportStrengthSot: () => supportStrength_v1_0_0_default,
870
884
  supportTopicSot: () => supportTopic_v1_0_0_default,
885
+ systemCategoryOf: () => systemCategoryOf,
871
886
  teamDirectorySchemaDefinition: () => teamDirectorySchemaDefinition,
872
887
  threadStatusSot: () => threadStatus_v1_0_0_default,
873
888
  threadTypeSot: () => threadType_v1_0_0_default,
@@ -16650,6 +16665,602 @@ function shareDefaultScopeFor(edits, purpose, opts = {}) {
16650
16665
  }
16651
16666
  var accountSharePurposePolicy = shareDefaultScopeFor;
16652
16667
 
16668
+ // src/sharingCeiling/resolve.ts
16669
+ var SHARE_REPORTING_PURPOSES = /* @__PURE__ */ new Set([
16670
+ "mandatory_reporting",
16671
+ "authority_reporting"
16672
+ ]);
16673
+ var SHARE_POSTURE_RANK = Object.freeze({
16674
+ open: 0,
16675
+ approval: 1,
16676
+ blocked: 2
16677
+ });
16678
+ var SHARE_PLATFORM_STATE_LABEL = Object.freeze({
16679
+ always: "Required",
16680
+ default_on: "Default On",
16681
+ default_off: "Default Off",
16682
+ never: "Blocked"
16683
+ });
16684
+ var SHARE_LEVEL_LABEL = Object.freeze({
16685
+ team_row: "attached on the team-to-team row",
16686
+ relationship: "attached to this relationship",
16687
+ agency_default: "your account's default for this purpose",
16688
+ account_internal: "your account's default for sharing between its own teams",
16689
+ team: "your account's rule for this team",
16690
+ platform_starter: "Platform default",
16691
+ inside_starter: "the platform's default for sharing inside your account"
16692
+ });
16693
+ var own3 = (record, key) => record !== null && typeof record === "object" && Object.prototype.hasOwnProperty.call(record, key) ? record[key] : void 0;
16694
+ var isStringList2 = (v) => Array.isArray(v) && v.every((c) => typeof c === "string");
16695
+ var versionOf = (v) => {
16696
+ const n = typeof v === "number" ? v : parseInt(String(v), 10);
16697
+ return Number.isFinite(n) && n > 0 ? Math.trunc(n) : 1;
16698
+ };
16699
+ var docList = (v) => v === null || v === void 0 ? null : isStringList2(v) ? [...v] : [];
16700
+ function scopeListCovers(scope, list, categoryCode, rowCode) {
16701
+ if (!Array.isArray(list)) return true;
16702
+ const set = new Set(list);
16703
+ if (scope.ancestorsOf(categoryCode).some((c) => set.has(c))) return true;
16704
+ if (rowCode !== void 0)
16705
+ return scope.ancestorsOf(rowCode).some((c) => set.has(c));
16706
+ return list.some(
16707
+ (id) => scope.ancestorsOf(id).slice(1).includes(categoryCode)
16708
+ );
16709
+ }
16710
+ function scopeListStrictlyCovers(scope, list, categoryCode) {
16711
+ if (!Array.isArray(list)) return true;
16712
+ const set = new Set(list);
16713
+ return scope.ancestorsOf(categoryCode).some((c) => set.has(c));
16714
+ }
16715
+ var isLiveDoc = (p) => p !== null && typeof p === "object" && typeof p.id === "string" && p.id !== "" && typeof p.purpose === "string" && p.active !== false;
16716
+ function attachmentIndexFromPolicies(policies) {
16717
+ const nullMap = () => /* @__PURE__ */ Object.create(null);
16718
+ const agencyDefaults = nullMap();
16719
+ const internalDefaults = nullMap();
16720
+ const relationships = nullMap();
16721
+ const teamRows = nullMap();
16722
+ const teams = nullMap();
16723
+ const put = (map, key, purpose, id) => {
16724
+ const row = Object.prototype.hasOwnProperty.call(map, key) ? map[key] : map[key] = nullMap();
16725
+ row[purpose] = id;
16726
+ };
16727
+ for (const p of Array.isArray(policies) ? policies : []) {
16728
+ if (!isLiveDoc(p)) continue;
16729
+ for (const a of Array.isArray(p.assignments) ? p.assignments : []) {
16730
+ if (a === null || typeof a !== "object") continue;
16731
+ switch (a.scope) {
16732
+ case "account":
16733
+ agencyDefaults[p.purpose] = p.id;
16734
+ break;
16735
+ case "account_internal":
16736
+ internalDefaults[p.purpose] = p.id;
16737
+ break;
16738
+ case "account_partner":
16739
+ if (typeof a.partnerId === "string" && a.partnerId !== "")
16740
+ put(relationships, a.partnerId, p.purpose, p.id);
16741
+ break;
16742
+ case "team":
16743
+ if (typeof a.teamId === "string" && a.teamId !== "")
16744
+ put(teams, a.teamId, p.purpose, p.id);
16745
+ break;
16746
+ case "team_pair":
16747
+ if (typeof a.teamRowId === "string" && a.teamRowId !== "")
16748
+ put(teamRows, a.teamRowId, p.purpose, p.id);
16749
+ break;
16750
+ default:
16751
+ break;
16752
+ }
16753
+ }
16754
+ }
16755
+ return { agencyDefaults, internalDefaults, relationships, teamRows, teams };
16756
+ }
16757
+ function matchTeamRow(rows, teamId, recipient, options = {}) {
16758
+ if (typeof teamId !== "string" || teamId === "" || !Array.isArray(rows))
16759
+ return null;
16760
+ const drop = new Set(options.shareBackOnlyRowIds ?? []);
16761
+ const live = rows.filter(
16762
+ (r) => r !== null && typeof r === "object" && typeof r.id === "string" && !drop.has(r.id)
16763
+ );
16764
+ if (recipient.kind === "sibling_team") {
16765
+ return live.find(
16766
+ (r) => r.myTeamId === teamId && r.their?.id === recipient.teamId
16767
+ )?.id ?? null;
16768
+ }
16769
+ if (recipient.kind === "external") return null;
16770
+ if (options.scopeMode === "team_scoped")
16771
+ return live.find((r) => r.myTeamId === teamId)?.id ?? null;
16772
+ return live.find(
16773
+ (r) => r.myTeamId === teamId && (!r.their || r.their.type !== "team" || r.their.id === recipient.id)
16774
+ )?.id ?? null;
16775
+ }
16776
+ function derivePlatformDefault(scope, purpose, seedList, options = {}) {
16777
+ const seed = isStringList2(seedList) ? [...seedList] : [];
16778
+ const req = new Set(options.required ?? []);
16779
+ const states = {};
16780
+ const required = [];
16781
+ const blocked = [];
16782
+ const systemCode = systemCategoryOf(scope);
16783
+ for (const g of liveCategories(scope)) {
16784
+ let state;
16785
+ if (g === systemCode) state = "always";
16786
+ else if (req.has(g)) state = "always";
16787
+ else if (scope.row(g)?.shareableDefault === false) state = "never";
16788
+ else state = scopeListCovers(scope, seed, g) ? "default_on" : "default_off";
16789
+ const bound = own3(options.bounds, g);
16790
+ if (g !== systemCode && (bound === "always" || bound === "default_on" || bound === "default_off" || bound === "never"))
16791
+ state = bound;
16792
+ states[g] = state;
16793
+ if (state === "always" && g !== systemCode) required.push(g);
16794
+ if (state === "never") blocked.push(g);
16795
+ }
16796
+ const categoryOf = (code) => scope.ancestorsOf(code).find((c) => scope.row(c)?.rowType === "category");
16797
+ const raw = [];
16798
+ const push = (c) => {
16799
+ if (!raw.includes(c)) raw.push(c);
16800
+ };
16801
+ for (const code of seed) {
16802
+ const g = categoryOf(code);
16803
+ if (g === void 0) {
16804
+ for (const [cat, st2] of Object.entries(states)) {
16805
+ if ((st2 === "always" || st2 === "default_on") && scope.ancestorsOf(cat).includes(code))
16806
+ push(cat);
16807
+ }
16808
+ continue;
16809
+ }
16810
+ const st = states[g];
16811
+ if (st === "never" || st === "default_off") continue;
16812
+ push(code);
16813
+ }
16814
+ for (const [g, st] of Object.entries(states)) {
16815
+ if ((st === "always" || st === "default_on") && !scopeListCovers(scope, raw, g))
16816
+ push(g);
16817
+ }
16818
+ if (systemCode !== void 0) push(systemCode);
16819
+ return {
16820
+ purpose,
16821
+ version: versionOf(options.version),
16822
+ raw,
16823
+ states,
16824
+ required,
16825
+ blocked,
16826
+ edited: options.edited === true
16827
+ };
16828
+ }
16829
+ var treeCache = /* @__PURE__ */ new WeakMap();
16830
+ function treeIndex(scope) {
16831
+ const hit = treeCache.get(scope);
16832
+ if (hit) return hit;
16833
+ const live = (code) => scope.row(code) !== void 0 && scope.ancestorsOf(code).every((c) => scope.row(c)?.status !== "retired");
16834
+ const categories = scope.rows.filter((r) => r.rowType === "category" && live(r.scopeCode)).map((r) => r.scopeCode);
16835
+ const systemInfoPath = scope.row("system_info") !== void 0 ? scope.ancestorsOf("system_info") : [];
16836
+ const system = systemInfoPath.find((c) => categories.includes(c)) ?? categories.find((g) => g === "system");
16837
+ const descendants = /* @__PURE__ */ new Map();
16838
+ const leaves = /* @__PURE__ */ new Map();
16839
+ for (const g of categories) {
16840
+ const all = [];
16841
+ const walk = (code) => {
16842
+ for (const c of scope.childrenOf(code)) {
16843
+ if (!live(c)) continue;
16844
+ all.push(c);
16845
+ walk(c);
16846
+ }
16847
+ };
16848
+ walk(g);
16849
+ descendants.set(g, all);
16850
+ leaves.set(
16851
+ g,
16852
+ all.filter((c) => !scope.childrenOf(c).some(live))
16853
+ );
16854
+ }
16855
+ const out = { categories, system, leaves, descendants };
16856
+ treeCache.set(scope, out);
16857
+ return out;
16858
+ }
16859
+ function liveCategories(scope) {
16860
+ return [...treeIndex(scope).categories];
16861
+ }
16862
+ function systemCategoryOf(scope) {
16863
+ return treeIndex(scope).system;
16864
+ }
16865
+ function legacyCeilingList(v) {
16866
+ if (v === null || v === void 0) return null;
16867
+ if (isStringList2(v)) return [...v];
16868
+ if (typeof v === "object" && "rung" in v) {
16869
+ const r = v.rung;
16870
+ if (r === "partner_rule" || r === "seeded_partner_rule" || r === "account_default") {
16871
+ return isStringList2(v.allowed) ? [...v.allowed] : [];
16872
+ }
16873
+ return null;
16874
+ }
16875
+ return null;
16876
+ }
16877
+ var HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE = Object.freeze({
16878
+ mandatory_reporting: Object.freeze(["identifying"]),
16879
+ authority_reporting: Object.freeze(["identifying"])
16880
+ });
16881
+ function platformDefaultFor(scope, purpose, options = {}) {
16882
+ const starter = options.starter ?? HTI_SHARE_PLATFORM_STARTER;
16883
+ const seed = own3(starter.scopeByPurpose, purpose);
16884
+ if (!isStringList2(seed)) return null;
16885
+ return derivePlatformDefault(scope, purpose, seed, {
16886
+ required: own3(HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE, purpose) ?? [],
16887
+ bounds: options.bounds ?? null,
16888
+ version: options.version ?? 1,
16889
+ edited: options.edited === true
16890
+ });
16891
+ }
16892
+ function shareRowCeiling(resolution, scope) {
16893
+ if (!resolution.allowed) return [];
16894
+ const out = [];
16895
+ for (const g of resolution.allowedCategories) {
16896
+ const e = own3(resolution.scope, g);
16897
+ if (e === void 0) continue;
16898
+ const withheld = /* @__PURE__ */ new Set([
16899
+ ...e.excludedItems,
16900
+ ...e.teamExcludedItems,
16901
+ ...e.floorItems
16902
+ ]);
16903
+ if (withheld.size === 0) {
16904
+ out.push(g);
16905
+ continue;
16906
+ }
16907
+ const live = (c) => scope.row(c) !== void 0 && scope.ancestorsOf(c).every((a) => scope.row(a)?.status !== "retired");
16908
+ const anyWithheldBeneath = (c) => scope.childrenOf(c).some((k) => live(k) && (withheld.has(k) || anyWithheldBeneath(k)));
16909
+ const visit = (c) => {
16910
+ if (withheld.has(c) || !live(c)) return;
16911
+ if (!anyWithheldBeneath(c)) {
16912
+ out.push(c);
16913
+ return;
16914
+ }
16915
+ for (const k of scope.childrenOf(c)) visit(k);
16916
+ };
16917
+ for (const k of scope.childrenOf(g)) visit(k);
16918
+ }
16919
+ return out;
16920
+ }
16921
+ function named(h) {
16922
+ const p = h.policy;
16923
+ return {
16924
+ id: p.id,
16925
+ familyId: typeof p.familyId === "string" && p.familyId !== "" ? p.familyId : p.id,
16926
+ name: typeof p.name === "string" ? p.name : p.id,
16927
+ version: h.version,
16928
+ level: h.level,
16929
+ levelLabel: SHARE_LEVEL_LABEL[h.level],
16930
+ posture: p.posture === "open" || p.posture === "approval" || p.posture === "blocked" ? p.posture : null,
16931
+ infoScope: docList(p.infoScope),
16932
+ infoScopeItems: copyItems(p.infoScopeItems),
16933
+ edited: p.edited === true,
16934
+ origin: typeof p.origin?.kind === "string" ? p.origin.kind : null,
16935
+ rulePath: h.rulePath
16936
+ };
16937
+ }
16938
+ var uniq = (list) => [...new Set(list)];
16939
+ var copyItems = (v) => {
16940
+ if (v === null || typeof v !== "object") return null;
16941
+ const out = {};
16942
+ for (const [k, rows] of Object.entries(v)) {
16943
+ if (isStringList2(rows)) out[k] = [...rows];
16944
+ }
16945
+ return out;
16946
+ };
16947
+ function resolveShare(input) {
16948
+ const { scope, purpose, recipient } = input;
16949
+ if (typeof purpose !== "string" || purpose === "")
16950
+ throw new TypeError("resolveShare: purpose must be a share purpose code");
16951
+ const teamId = typeof input.sender?.teamId === "string" && input.sender.teamId !== "" ? input.sender.teamId : null;
16952
+ const inside = recipient.kind === "sibling_team";
16953
+ const recipientKey = recipient.kind === "partner" ? recipient.id : recipient.kind === "external" ? "__external__" : null;
16954
+ if (recipient.kind === "partner" && (typeof recipient.id !== "string" || recipient.id === "")) {
16955
+ throw new TypeError("resolveShare: a partner recipient needs an id");
16956
+ }
16957
+ const report = SHARE_REPORTING_PURPOSES.has(purpose);
16958
+ const pd = input.platformDefault ?? null;
16959
+ const purposeLabel = typeof input.purposeLabel === "string" && input.purposeLabel !== "" ? input.purposeLabel : purpose;
16960
+ const pdRaw = pd === null ? [] : isStringList2(pd.raw) ? [...pd.raw] : [];
16961
+ const pdRequired = pd === null ? [] : isStringList2(pd.required) ? [...pd.required] : [];
16962
+ const pdBlocked = pd === null ? [] : isStringList2(pd.blocked) ? [...pd.blocked] : [];
16963
+ const policies = (Array.isArray(input.policies) ? input.policies : []).filter(
16964
+ isLiveDoc
16965
+ );
16966
+ const byId = /* @__PURE__ */ new Map();
16967
+ for (const p of policies) byId.set(p.id, p);
16968
+ const att = attachmentIndexFromPolicies(policies);
16969
+ const tree = treeIndex(scope);
16970
+ const systemCode = tree.system;
16971
+ const hit = (id, level2) => {
16972
+ const p = id === void 0 ? void 0 : byId.get(id);
16973
+ if (p === void 0 || p.purpose !== purpose) return null;
16974
+ if (p.trigger?.answers === "received") return null;
16975
+ const v = versionOf(p.version);
16976
+ const name = typeof p.name === "string" ? p.name : p.id;
16977
+ return {
16978
+ policy: p,
16979
+ level: level2,
16980
+ version: v,
16981
+ rulePath: `sharingPurposePolicies[${p.id}] v${v} (policy \u201C${name}\u201D \u2014 ${SHARE_LEVEL_LABEL[level2]})`
16982
+ };
16983
+ };
16984
+ const cell = (map, key) => own3(own3(map, key), purpose);
16985
+ let gov = null;
16986
+ const purposeKnown = pd !== null;
16987
+ const teamRowId = purposeKnown && teamId !== null && recipient.kind !== "external" && typeof input.teamRowId === "string" && input.teamRowId !== "" ? input.teamRowId : null;
16988
+ if (teamRowId !== null) gov = hit(cell(att.teamRows, teamRowId), "team_row");
16989
+ if (gov === null && inside && purposeKnown) {
16990
+ gov = hit(own3(att.internalDefaults, purpose), "account_internal");
16991
+ if (gov === null && pd !== null) {
16992
+ const starter = {
16993
+ id: `pol-inside-starter-${purpose}`,
16994
+ name: `${purposeLabel} \u2014 Inside your account (platform default)`,
16995
+ purpose,
16996
+ infoScope: null,
16997
+ posture: "open",
16998
+ version: 1,
16999
+ origin: { kind: "starter" }
17000
+ };
17001
+ gov = {
17002
+ policy: starter,
17003
+ level: "inside_starter",
17004
+ version: 1,
17005
+ rulePath: `${starter.id} v1 (${SHARE_LEVEL_LABEL.inside_starter} \u2014 the full record, open)`
17006
+ };
17007
+ }
17008
+ }
17009
+ if (gov === null && !inside && purposeKnown && recipientKey !== null) {
17010
+ gov = hit(cell(att.relationships, recipientKey), "relationship");
17011
+ if (gov === null)
17012
+ gov = hit(own3(att.agencyDefaults, purpose), "agency_default");
17013
+ if (gov === null && pd !== null) {
17014
+ const starter = {
17015
+ id: `pol-starter-${purpose}`,
17016
+ name: `${purposeLabel} \u2014 Platform default`,
17017
+ purpose,
17018
+ infoScope: pdRaw.filter((c) => c !== systemCode),
17019
+ posture: "open",
17020
+ version: pd.version,
17021
+ origin: { kind: "platform_starter" },
17022
+ edited: false
17023
+ };
17024
+ gov = {
17025
+ policy: starter,
17026
+ level: "platform_starter",
17027
+ version: pd.version,
17028
+ rulePath: `${starter.id} v${pd.version} (${SHARE_LEVEL_LABEL.platform_starter})`
17029
+ };
17030
+ }
17031
+ }
17032
+ let tc = null;
17033
+ if (teamId !== null && gov !== null) {
17034
+ const t = hit(cell(att.teams, teamId), "team");
17035
+ if (t !== null && t.policy.id !== gov.policy.id) tc = t;
17036
+ }
17037
+ const govNamed = gov === null ? null : named(gov);
17038
+ const tcNamed = tc === null ? null : named(tc);
17039
+ const rulePath = gov === null ? `no Platform default for purpose \u201C${purpose}\u201D \u2014 nothing governs (fails closed)` : tc === null ? gov.rulePath : `${gov.rulePath} \u2229 ${tc.rulePath} (the sending team's own policy is a ceiling \u2014 only what both allow)`;
17040
+ let posture = input.relationshipPosture === "approval" || input.relationshipPosture === "blocked" ? input.relationshipPosture : "open";
17041
+ let postureSource = "relationship";
17042
+ let posturePol = null;
17043
+ if (govNamed?.posture && SHARE_POSTURE_RANK[govNamed.posture] > SHARE_POSTURE_RANK[posture]) {
17044
+ posture = govNamed.posture;
17045
+ postureSource = "policy";
17046
+ posturePol = govNamed;
17047
+ }
17048
+ if (tcNamed?.posture && SHARE_POSTURE_RANK[tcNamed.posture] > SHARE_POSTURE_RANK[posture]) {
17049
+ posture = tcNamed.posture;
17050
+ postureSource = "team_ceiling";
17051
+ posturePol = tcNamed;
17052
+ }
17053
+ let excluded = null;
17054
+ let reportCarveOut = null;
17055
+ if (gov === null) {
17056
+ excluded = {
17057
+ reason: `No Platform default for purpose \u201C${purpose}\u201D \u2014 nothing may leave under it`,
17058
+ rulePath
17059
+ };
17060
+ } else if (input.purposeOff === true) {
17061
+ excluded = {
17062
+ reason: "Share purpose disabled by your account's sharing policy",
17063
+ rulePath: `purposeOverrides[${purpose}] = false`
17064
+ };
17065
+ } else if (posture === "blocked") {
17066
+ const pol = posturePol;
17067
+ const path = pol === null ? "relationship posture = blocked" : `sharingPurposePolicies[${pol.id}].posture=blocked (policy \u201C${pol.name}\u201D \u2014 ${pol.levelLabel})`;
17068
+ if (report) {
17069
+ reportCarveOut = {
17070
+ note: pol === null ? "Blocked for ordinary sharing \u2014 reachable for reports (nothing at the partner layer extinguishes the duty)" : `The \u201C${pol.name}\u201D policy blocks ordinary sharing \u2014 reachable for reports`,
17071
+ rulePath: path
17072
+ };
17073
+ } else {
17074
+ excluded = {
17075
+ reason: pol === null ? "Blocked for this purpose by the relationship" : `Blocked for this purpose by your account's \u201C${pol.name}\u201D policy`,
17076
+ rulePath: path
17077
+ };
17078
+ }
17079
+ }
17080
+ const excludedAll = excluded !== null;
17081
+ const level = gov?.level ?? null;
17082
+ const govList = govNamed?.infoScope ?? null;
17083
+ const polScopeBinds = gov !== null && Array.isArray(govList) && (level === "team_row" || level === "relationship" || level === "account_internal" || level === "inside_starter" || level === "agency_default" && gov.policy.edited === true);
17084
+ const legacy = legacyCeilingList(input.legacyCeiling);
17085
+ const ceilingIsStarter = legacy === null;
17086
+ let groupCeiling = legacy ?? pdRaw;
17087
+ let ceilingPath = legacy !== null ? "sharingScopeEdits (the account's partner / default rule \u2014 the legacy cell chain)" : pd === null ? "no Platform default" : `pol-starter-${purpose} v${pd.version} (Platform default \u2014 the starting scope for this purpose)`;
17088
+ if (ceilingIsStarter && polScopeBinds) {
17089
+ groupCeiling = null;
17090
+ ceilingPath = "";
17091
+ }
17092
+ if (inside) {
17093
+ groupCeiling = null;
17094
+ ceilingPath = "";
17095
+ }
17096
+ const tcScope = tcNamed?.infoScope ?? null;
17097
+ const tcItems = tc?.policy.infoScopeItems ?? null;
17098
+ const govItems = gov?.policy.infoScopeItems ?? null;
17099
+ const required = (g) => g === systemCode || !inside && pd !== null && pdRequired.includes(g);
17100
+ const blockedSet = new Set(pdBlocked);
17101
+ const asSet2 = (v) => new Set(isStringList2(v) ? v : []);
17102
+ const categoriesOff = asSet2(input.accountScope?.categoriesOff);
17103
+ const rowsOff = asSet2(input.accountScope?.rowsOff);
17104
+ const categoriesOn = asSet2(input.accountScope?.categoriesOn);
17105
+ const rowsOn = asSet2(input.accountScope?.rowsOn);
17106
+ const underFloor = (code) => scope.ancestorsOf(code).some((c) => scope.row(c)?.platformFloor === true);
17107
+ const categoryOffByDefault = (g) => !categoriesOn.has(g) && scope.row(g)?.shareableDefault === false;
17108
+ const heightenedOff = (code, g) => {
17109
+ const chain = scope.ancestorsOf(code);
17110
+ if (chain.some((c) => rowsOff.has(c))) return true;
17111
+ const below = chain.slice(0, Math.max(chain.indexOf(g), 0));
17112
+ return below.some(
17113
+ (c) => !rowsOn.has(c) && scope.row(c)?.shareableDefault === false
17114
+ );
17115
+ };
17116
+ const out = {};
17117
+ const allowedCategories = [];
17118
+ const govName = govNamed?.name ?? "";
17119
+ for (const g of tree.categories) {
17120
+ const items = tree.descendants.get(g) ?? [];
17121
+ const leaves = tree.leaves.get(g) ?? [];
17122
+ const platformRequired = !inside && pd !== null && pdRequired.includes(g) ? {
17123
+ rulePath: `pol-starter-${purpose} v${pd.version} \xB7 ${g} = Required (Platform default \u2014 set by the Platform Admin)`
17124
+ } : null;
17125
+ const req = required(g);
17126
+ let allowed = true;
17127
+ let reason = excluded !== null ? excluded.reason : "Allowed";
17128
+ let path = excluded !== null ? excluded.rulePath : rulePath;
17129
+ const floorItems = items.filter(underFloor);
17130
+ const excludedItems = [];
17131
+ let excludedReason = null;
17132
+ const teamExcludedItems = [];
17133
+ let teamExcludedReason = null;
17134
+ const outside = (covered) => items.filter(
17135
+ (r) => !covered(r) && !items.some((d) => d !== r && covered(d) && scope.ancestorsOf(d).includes(r))
17136
+ );
17137
+ const addExcluded = (rows, why) => {
17138
+ for (const r of rows)
17139
+ if (!floorItems.includes(r) && !excludedItems.includes(r))
17140
+ excludedItems.push(r);
17141
+ if (rows.length > 0 && excludedReason === null) excludedReason = why;
17142
+ };
17143
+ if (gov === null) {
17144
+ allowed = false;
17145
+ } else if ((!req || platformRequired !== null) && excludedAll) {
17146
+ allowed = false;
17147
+ } else if (excludedAll) {
17148
+ reason = "Allowed";
17149
+ path = rulePath;
17150
+ }
17151
+ if (allowed && !req && (categoriesOff.has(g) || categoryOffByDefault(g))) {
17152
+ allowed = false;
17153
+ reason = "Excluded by your account's Information Scope policy";
17154
+ path = categoriesOff.has(g) ? `policies.scopeCatalog[${g}].shareable = false` : `policies.scopeCatalog[${g}] not turned on \u2014 codebook core-information_scope shareableDefault = false (CVC-236 heightened protection: off until the account turns it on)`;
17155
+ }
17156
+ if (allowed && !req && !inside && blockedSet.has(g)) {
17157
+ allowed = false;
17158
+ reason = "Blocked for this purpose by the Platform default \u2014 no account can share it under this purpose";
17159
+ path = `pol-starter-${purpose} v${pd?.version ?? 1} \xB7 ${g} = Blocked (Platform default \u2014 CVC-236 heightened protection | set by the Platform Admin)`;
17160
+ }
17161
+ addExcluded(
17162
+ g === systemCode ? [] : items.filter((r) => !underFloor(r) && heightenedOff(r, g)),
17163
+ "Heightened protection (CVC-236) \u2014 off in your account's Information Scope until the account turns it on"
17164
+ );
17165
+ if (allowed && !req && groupCeiling !== null && !scopeListCovers(scope, groupCeiling, g)) {
17166
+ allowed = false;
17167
+ reason = "Outside the payload for this purpose";
17168
+ path = ceilingPath;
17169
+ }
17170
+ if (allowed && !req && groupCeiling !== null && !scopeListStrictlyCovers(scope, groupCeiling, g)) {
17171
+ addExcluded(
17172
+ outside((r) => scopeListCovers(scope, groupCeiling, g, r)),
17173
+ "Outside the payload for this purpose"
17174
+ );
17175
+ }
17176
+ if (allowed && !req && polScopeBinds && !scopeListCovers(scope, govList, g)) {
17177
+ allowed = false;
17178
+ reason = `Outside what the \u201C${govName}\u201D policy allows for this purpose`;
17179
+ path = `sharingPurposePolicies[${gov?.policy.id}].infoScope (policy \u201C${govName}\u201D \u2014 ${govNamed?.levelLabel})`;
17180
+ }
17181
+ if (allowed && !req && polScopeBinds && !scopeListStrictlyCovers(scope, govList, g)) {
17182
+ addExcluded(
17183
+ outside((r) => scopeListCovers(scope, govList, g, r)),
17184
+ `Outside what the \u201C${govName}\u201D policy allows for this purpose`
17185
+ );
17186
+ }
17187
+ const govRows = polScopeBinds ? own3(govItems, g) : void 0;
17188
+ if (allowed && !req && isStringList2(govRows)) {
17189
+ const keep = new Set(govRows);
17190
+ const kept = (r) => keep.has(r) || scope.ancestorsOf(r).some((a) => a !== g && keep.has(a));
17191
+ addExcluded(
17192
+ outside(kept),
17193
+ `Outside what the \u201C${govName}\u201D policy allows for this purpose`
17194
+ );
17195
+ }
17196
+ if (allowed && !req && tcScope !== null && !scopeListCovers(scope, tcScope, g)) {
17197
+ allowed = false;
17198
+ reason = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;
17199
+ path = `sharingPurposePolicies[${tc?.policy.id}].infoScope (policy \u201C${tcNamed?.name}\u201D \u2014 ${SHARE_LEVEL_LABEL.team}; a ceiling over \u201C${govName}\u201D)`;
17200
+ }
17201
+ if (allowed && !req && tc !== null) {
17202
+ const why = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;
17203
+ const outRows = /* @__PURE__ */ new Set();
17204
+ if (tcScope !== null && !scopeListStrictlyCovers(scope, tcScope, g)) {
17205
+ for (const r of outside((x) => scopeListCovers(scope, tcScope, g, x))) outRows.add(r);
17206
+ }
17207
+ const tcRows = own3(tcItems, g);
17208
+ if (isStringList2(tcRows)) {
17209
+ const keep = new Set(tcRows);
17210
+ const kept = (r) => keep.has(r) || scope.ancestorsOf(r).some((a) => a !== g && keep.has(a));
17211
+ for (const r of outside(kept)) outRows.add(r);
17212
+ }
17213
+ for (const r of outRows)
17214
+ if (!floorItems.includes(r) && !excludedItems.includes(r))
17215
+ teamExcludedItems.push(r);
17216
+ if (teamExcludedItems.length > 0) teamExcludedReason = why;
17217
+ }
17218
+ if (allowed && (!req || platformRequired !== null) && leaves.length > 0) {
17219
+ const gone = new Set(
17220
+ [...floorItems, ...excludedItems, ...teamExcludedItems].filter(
17221
+ (r) => leaves.includes(r)
17222
+ )
17223
+ );
17224
+ if (gone.size >= leaves.length) {
17225
+ allowed = false;
17226
+ if (leaves.every((r) => floorItems.includes(r))) {
17227
+ reason = "Never shared \u2014 under the platform safety floor";
17228
+ path = "HTI_PLATFORM_SAFETY_FLOOR";
17229
+ } else if (leaves.some((r) => excludedItems.includes(r))) {
17230
+ reason = excludedReason ?? reason;
17231
+ } else {
17232
+ reason = teamExcludedReason ?? reason;
17233
+ }
17234
+ }
17235
+ }
17236
+ out[g] = {
17237
+ allowed,
17238
+ reason,
17239
+ rulePath: path,
17240
+ platformRequired,
17241
+ floorItems: uniq(floorItems),
17242
+ excludedItems: uniq(excludedItems),
17243
+ excludedReason,
17244
+ teamExcludedItems: uniq(teamExcludedItems),
17245
+ teamExcludedReason
17246
+ };
17247
+ if (allowed) allowedCategories.push(g);
17248
+ }
17249
+ return {
17250
+ allowed: !excludedAll,
17251
+ posture,
17252
+ postureSource,
17253
+ excluded,
17254
+ reportCarveOut,
17255
+ governing: govNamed,
17256
+ teamCeiling: tcNamed,
17257
+ inside,
17258
+ scope: out,
17259
+ allowedCategories,
17260
+ rulePath
17261
+ };
17262
+ }
17263
+
16653
17264
  // src/validation/cvc.ts
16654
17265
  var import_zod = require("zod");
16655
17266
  var CvcCodeSchema = import_zod.z.string().regex(/^\d{3}(-\d{3}){6}$/);
@@ -69545,6 +70156,7 @@ var CVC_197_VALUES = selectableCodes(
69545
70156
  GoalWithdrawalReasonKeys,
69546
70157
  HEALTHCARE_ORG_TYPE_KEYS,
69547
70158
  HTI_SHARE_PLATFORM_PURPOSE_ENABLED,
70159
+ HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE,
69548
70160
  HTI_SHARE_PLATFORM_STARTER,
69549
70161
  HTI_SHARE_PLATFORM_STARTER_SOURCE,
69550
70162
  HairColorKeys,
@@ -69745,6 +70357,10 @@ var CVC_197_VALUES = selectableCodes(
69745
70357
  SERVICE_STATE_STAMP_CROSSWALK,
69746
70358
  SESSION_STATES,
69747
70359
  SESSION_STATE_LABELS,
70360
+ SHARE_LEVEL_LABEL,
70361
+ SHARE_PLATFORM_STATE_LABEL,
70362
+ SHARE_POSTURE_RANK,
70363
+ SHARE_REPORTING_PURPOSES,
69748
70364
  SHARE_VIEW,
69749
70365
  SHARE_VIEW_LABELS,
69750
70366
  SHARE_VIEW_VALUES,
@@ -69837,6 +70453,7 @@ var CVC_197_VALUES = selectableCodes(
69837
70453
  applyRunValidatorsIfUnset,
69838
70454
  assertionDomainSot,
69839
70455
  assertionStatusSot,
70456
+ attachmentIndexFromPolicies,
69840
70457
  basisQuickPicksSot,
69841
70458
  buildCvcEntrySchema,
69842
70459
  buildCvcRegistrySchema,
@@ -69894,6 +70511,7 @@ var CVC_197_VALUES = selectableCodes(
69894
70511
  daIncidentSeveritySot,
69895
70512
  demographicsSchema,
69896
70513
  deriveAgeBinFromAge,
70514
+ derivePlatformDefault,
69897
70515
  determinationHelperCategoriesSot,
69898
70516
  determinationLevelSot,
69899
70517
  disabilitySubtypeSot,
@@ -69995,10 +70613,12 @@ var CVC_197_VALUES = selectableCodes(
69995
70613
  layoutSchema,
69996
70614
  leReportStatusSot,
69997
70615
  legalActionTypeSot,
70616
+ liveCategories,
69998
70617
  livingSituationSot,
69999
70618
  locationTypeSot,
70000
70619
  maritalStatusLegalSot,
70001
70620
  maskSelectionToCeiling,
70621
+ matchTeamRow,
70002
70622
  mentalHealthStatusSot,
70003
70623
  messageReportReasonSot,
70004
70624
  midStayEventTypeSot,
@@ -70035,6 +70655,7 @@ var CVC_197_VALUES = selectableCodes(
70035
70655
  petExitReasonSot,
70036
70656
  petRelationshipBasisSot,
70037
70657
  phoneSchema,
70658
+ platformDefaultFor,
70038
70659
  platformFunctionModel,
70039
70660
  platformFunctionSchemaDefinition,
70040
70661
  platformFunctionSchemaOptions,
@@ -70075,6 +70696,7 @@ var CVC_197_VALUES = selectableCodes(
70075
70696
  resolveOrgTypeKeyFromLegacyNumeric,
70076
70697
  resolveReferralEntityKeyFromLegacyNumeric,
70077
70698
  resolveRegistryWithInheritance,
70699
+ resolveShare,
70078
70700
  returnedToAbuserStatusSot,
70079
70701
  riskCategorySot,
70080
70702
  riskIdentificationMilestoneSot,
@@ -70088,6 +70710,8 @@ var CVC_197_VALUES = selectableCodes(
70088
70710
  rowsOutsideCeiling,
70089
70711
  rowsOverCeiling,
70090
70712
  rsvpResponseSot,
70713
+ scopeListCovers,
70714
+ scopeListStrictlyCovers,
70091
70715
  scopeMigrationsFromSot,
70092
70716
  scopeRowWithinCeiling,
70093
70717
  scopeRowsFromSot,
@@ -70123,6 +70747,7 @@ var CVC_197_VALUES = selectableCodes(
70123
70747
  shareDefaultScopeFor,
70124
70748
  sharePurposeSot,
70125
70749
  shareResponseReasonSot,
70750
+ shareRowCeiling,
70126
70751
  sharingCeilingCellList,
70127
70752
  sharingCeilingRowKey,
70128
70753
  sharingScopeEditsFromCells,
@@ -70143,6 +70768,7 @@ var CVC_197_VALUES = selectableCodes(
70143
70768
  suggestionSourceSot,
70144
70769
  supportStrengthSot,
70145
70770
  supportTopicSot,
70771
+ systemCategoryOf,
70146
70772
  teamDirectorySchemaDefinition,
70147
70773
  threadStatusSot,
70148
70774
  threadTypeSot,