@htilabs/platform-common-models 0.41.0 → 0.42.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.
package/dist/index.js CHANGED
@@ -15759,6 +15759,602 @@ function shareDefaultScopeFor(edits, purpose, opts = {}) {
15759
15759
  }
15760
15760
  var accountSharePurposePolicy = shareDefaultScopeFor;
15761
15761
 
15762
+ // src/sharingCeiling/resolve.ts
15763
+ var SHARE_REPORTING_PURPOSES = /* @__PURE__ */ new Set([
15764
+ "mandatory_reporting",
15765
+ "authority_reporting"
15766
+ ]);
15767
+ var SHARE_POSTURE_RANK = Object.freeze({
15768
+ open: 0,
15769
+ approval: 1,
15770
+ blocked: 2
15771
+ });
15772
+ var SHARE_PLATFORM_STATE_LABEL = Object.freeze({
15773
+ always: "Required",
15774
+ default_on: "Default On",
15775
+ default_off: "Default Off",
15776
+ never: "Blocked"
15777
+ });
15778
+ var SHARE_LEVEL_LABEL = Object.freeze({
15779
+ team_row: "attached on the team-to-team row",
15780
+ relationship: "attached to this relationship",
15781
+ agency_default: "your account's default for this purpose",
15782
+ account_internal: "your account's default for sharing between its own teams",
15783
+ team: "your account's rule for this team",
15784
+ platform_starter: "Platform default",
15785
+ inside_starter: "the platform's default for sharing inside your account"
15786
+ });
15787
+ var own3 = (record, key) => record !== null && typeof record === "object" && Object.prototype.hasOwnProperty.call(record, key) ? record[key] : void 0;
15788
+ var isStringList2 = (v) => Array.isArray(v) && v.every((c) => typeof c === "string");
15789
+ var versionOf = (v) => {
15790
+ const n = typeof v === "number" ? v : parseInt(String(v), 10);
15791
+ return Number.isFinite(n) && n > 0 ? Math.trunc(n) : 1;
15792
+ };
15793
+ var docList = (v) => v === null || v === void 0 ? null : isStringList2(v) ? [...v] : [];
15794
+ function scopeListCovers(scope, list, categoryCode, rowCode) {
15795
+ if (!Array.isArray(list)) return true;
15796
+ const set = new Set(list);
15797
+ if (scope.ancestorsOf(categoryCode).some((c) => set.has(c))) return true;
15798
+ if (rowCode !== void 0)
15799
+ return scope.ancestorsOf(rowCode).some((c) => set.has(c));
15800
+ return list.some(
15801
+ (id) => scope.ancestorsOf(id).slice(1).includes(categoryCode)
15802
+ );
15803
+ }
15804
+ function scopeListStrictlyCovers(scope, list, categoryCode) {
15805
+ if (!Array.isArray(list)) return true;
15806
+ const set = new Set(list);
15807
+ return scope.ancestorsOf(categoryCode).some((c) => set.has(c));
15808
+ }
15809
+ var isLiveDoc = (p) => p !== null && typeof p === "object" && typeof p.id === "string" && p.id !== "" && typeof p.purpose === "string" && p.active !== false;
15810
+ function attachmentIndexFromPolicies(policies) {
15811
+ const nullMap = () => /* @__PURE__ */ Object.create(null);
15812
+ const agencyDefaults = nullMap();
15813
+ const internalDefaults = nullMap();
15814
+ const relationships = nullMap();
15815
+ const teamRows = nullMap();
15816
+ const teams = nullMap();
15817
+ const put = (map, key, purpose, id) => {
15818
+ const row = Object.prototype.hasOwnProperty.call(map, key) ? map[key] : map[key] = nullMap();
15819
+ row[purpose] = id;
15820
+ };
15821
+ for (const p of Array.isArray(policies) ? policies : []) {
15822
+ if (!isLiveDoc(p)) continue;
15823
+ for (const a of Array.isArray(p.assignments) ? p.assignments : []) {
15824
+ if (a === null || typeof a !== "object") continue;
15825
+ switch (a.scope) {
15826
+ case "account":
15827
+ agencyDefaults[p.purpose] = p.id;
15828
+ break;
15829
+ case "account_internal":
15830
+ internalDefaults[p.purpose] = p.id;
15831
+ break;
15832
+ case "account_partner":
15833
+ if (typeof a.partnerId === "string" && a.partnerId !== "")
15834
+ put(relationships, a.partnerId, p.purpose, p.id);
15835
+ break;
15836
+ case "team":
15837
+ if (typeof a.teamId === "string" && a.teamId !== "")
15838
+ put(teams, a.teamId, p.purpose, p.id);
15839
+ break;
15840
+ case "team_pair":
15841
+ if (typeof a.teamRowId === "string" && a.teamRowId !== "")
15842
+ put(teamRows, a.teamRowId, p.purpose, p.id);
15843
+ break;
15844
+ default:
15845
+ break;
15846
+ }
15847
+ }
15848
+ }
15849
+ return { agencyDefaults, internalDefaults, relationships, teamRows, teams };
15850
+ }
15851
+ function matchTeamRow(rows, teamId, recipient, options = {}) {
15852
+ if (typeof teamId !== "string" || teamId === "" || !Array.isArray(rows))
15853
+ return null;
15854
+ const drop = new Set(options.shareBackOnlyRowIds ?? []);
15855
+ const live = rows.filter(
15856
+ (r) => r !== null && typeof r === "object" && typeof r.id === "string" && !drop.has(r.id)
15857
+ );
15858
+ if (recipient.kind === "sibling_team") {
15859
+ return live.find(
15860
+ (r) => r.myTeamId === teamId && r.their?.id === recipient.teamId
15861
+ )?.id ?? null;
15862
+ }
15863
+ if (recipient.kind === "external") return null;
15864
+ if (options.scopeMode === "team_scoped")
15865
+ return live.find((r) => r.myTeamId === teamId)?.id ?? null;
15866
+ return live.find(
15867
+ (r) => r.myTeamId === teamId && (!r.their || r.their.type !== "team" || r.their.id === recipient.id)
15868
+ )?.id ?? null;
15869
+ }
15870
+ function derivePlatformDefault(scope, purpose, seedList, options = {}) {
15871
+ const seed = isStringList2(seedList) ? [...seedList] : [];
15872
+ const req = new Set(options.required ?? []);
15873
+ const states = {};
15874
+ const required = [];
15875
+ const blocked = [];
15876
+ const systemCode = systemCategoryOf(scope);
15877
+ for (const g of liveCategories(scope)) {
15878
+ let state;
15879
+ if (g === systemCode) state = "always";
15880
+ else if (req.has(g)) state = "always";
15881
+ else if (scope.row(g)?.shareableDefault === false) state = "never";
15882
+ else state = scopeListCovers(scope, seed, g) ? "default_on" : "default_off";
15883
+ const bound = own3(options.bounds, g);
15884
+ if (g !== systemCode && (bound === "always" || bound === "default_on" || bound === "default_off" || bound === "never"))
15885
+ state = bound;
15886
+ states[g] = state;
15887
+ if (state === "always" && g !== systemCode) required.push(g);
15888
+ if (state === "never") blocked.push(g);
15889
+ }
15890
+ const categoryOf = (code) => scope.ancestorsOf(code).find((c) => scope.row(c)?.rowType === "category");
15891
+ const raw = [];
15892
+ const push = (c) => {
15893
+ if (!raw.includes(c)) raw.push(c);
15894
+ };
15895
+ for (const code of seed) {
15896
+ const g = categoryOf(code);
15897
+ if (g === void 0) {
15898
+ for (const [cat, st2] of Object.entries(states)) {
15899
+ if ((st2 === "always" || st2 === "default_on") && scope.ancestorsOf(cat).includes(code))
15900
+ push(cat);
15901
+ }
15902
+ continue;
15903
+ }
15904
+ const st = states[g];
15905
+ if (st === "never" || st === "default_off") continue;
15906
+ push(code);
15907
+ }
15908
+ for (const [g, st] of Object.entries(states)) {
15909
+ if ((st === "always" || st === "default_on") && !scopeListCovers(scope, raw, g))
15910
+ push(g);
15911
+ }
15912
+ if (systemCode !== void 0) push(systemCode);
15913
+ return {
15914
+ purpose,
15915
+ version: versionOf(options.version),
15916
+ raw,
15917
+ states,
15918
+ required,
15919
+ blocked,
15920
+ edited: options.edited === true
15921
+ };
15922
+ }
15923
+ var treeCache = /* @__PURE__ */ new WeakMap();
15924
+ function treeIndex(scope) {
15925
+ const hit = treeCache.get(scope);
15926
+ if (hit) return hit;
15927
+ const live = (code) => scope.row(code) !== void 0 && scope.ancestorsOf(code).every((c) => scope.row(c)?.status !== "retired");
15928
+ const categories = scope.rows.filter((r) => r.rowType === "category" && live(r.scopeCode)).map((r) => r.scopeCode);
15929
+ const systemInfoPath = scope.row("system_info") !== void 0 ? scope.ancestorsOf("system_info") : [];
15930
+ const system = systemInfoPath.find((c) => categories.includes(c)) ?? categories.find((g) => g === "system");
15931
+ const descendants = /* @__PURE__ */ new Map();
15932
+ const leaves = /* @__PURE__ */ new Map();
15933
+ for (const g of categories) {
15934
+ const all = [];
15935
+ const walk = (code) => {
15936
+ for (const c of scope.childrenOf(code)) {
15937
+ if (!live(c)) continue;
15938
+ all.push(c);
15939
+ walk(c);
15940
+ }
15941
+ };
15942
+ walk(g);
15943
+ descendants.set(g, all);
15944
+ leaves.set(
15945
+ g,
15946
+ all.filter((c) => !scope.childrenOf(c).some(live))
15947
+ );
15948
+ }
15949
+ const out = { categories, system, leaves, descendants };
15950
+ treeCache.set(scope, out);
15951
+ return out;
15952
+ }
15953
+ function liveCategories(scope) {
15954
+ return [...treeIndex(scope).categories];
15955
+ }
15956
+ function systemCategoryOf(scope) {
15957
+ return treeIndex(scope).system;
15958
+ }
15959
+ function legacyCeilingList(v) {
15960
+ if (v === null || v === void 0) return null;
15961
+ if (isStringList2(v)) return [...v];
15962
+ if (typeof v === "object" && "rung" in v) {
15963
+ const r = v.rung;
15964
+ if (r === "partner_rule" || r === "seeded_partner_rule" || r === "account_default") {
15965
+ return isStringList2(v.allowed) ? [...v.allowed] : [];
15966
+ }
15967
+ return null;
15968
+ }
15969
+ return null;
15970
+ }
15971
+ var HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE = Object.freeze({
15972
+ mandatory_reporting: Object.freeze(["identifying"]),
15973
+ authority_reporting: Object.freeze(["identifying"])
15974
+ });
15975
+ function platformDefaultFor(scope, purpose, options = {}) {
15976
+ const starter = options.starter ?? HTI_SHARE_PLATFORM_STARTER;
15977
+ const seed = own3(starter.scopeByPurpose, purpose);
15978
+ if (!isStringList2(seed)) return null;
15979
+ return derivePlatformDefault(scope, purpose, seed, {
15980
+ required: own3(HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE, purpose) ?? [],
15981
+ bounds: options.bounds ?? null,
15982
+ version: options.version ?? 1,
15983
+ edited: options.edited === true
15984
+ });
15985
+ }
15986
+ function shareRowCeiling(resolution, scope) {
15987
+ if (!resolution.allowed) return [];
15988
+ const out = [];
15989
+ for (const g of resolution.allowedCategories) {
15990
+ const e = own3(resolution.scope, g);
15991
+ if (e === void 0) continue;
15992
+ const withheld = /* @__PURE__ */ new Set([
15993
+ ...e.excludedItems,
15994
+ ...e.teamExcludedItems,
15995
+ ...e.floorItems
15996
+ ]);
15997
+ if (withheld.size === 0) {
15998
+ out.push(g);
15999
+ continue;
16000
+ }
16001
+ const live = (c) => scope.row(c) !== void 0 && scope.ancestorsOf(c).every((a) => scope.row(a)?.status !== "retired");
16002
+ const anyWithheldBeneath = (c) => scope.childrenOf(c).some((k) => live(k) && (withheld.has(k) || anyWithheldBeneath(k)));
16003
+ const visit = (c) => {
16004
+ if (withheld.has(c) || !live(c)) return;
16005
+ if (!anyWithheldBeneath(c)) {
16006
+ out.push(c);
16007
+ return;
16008
+ }
16009
+ for (const k of scope.childrenOf(c)) visit(k);
16010
+ };
16011
+ for (const k of scope.childrenOf(g)) visit(k);
16012
+ }
16013
+ return out;
16014
+ }
16015
+ function named(h) {
16016
+ const p = h.policy;
16017
+ return {
16018
+ id: p.id,
16019
+ familyId: typeof p.familyId === "string" && p.familyId !== "" ? p.familyId : p.id,
16020
+ name: typeof p.name === "string" ? p.name : p.id,
16021
+ version: h.version,
16022
+ level: h.level,
16023
+ levelLabel: SHARE_LEVEL_LABEL[h.level],
16024
+ posture: p.posture === "open" || p.posture === "approval" || p.posture === "blocked" ? p.posture : null,
16025
+ infoScope: docList(p.infoScope),
16026
+ infoScopeItems: copyItems(p.infoScopeItems),
16027
+ edited: p.edited === true,
16028
+ origin: typeof p.origin?.kind === "string" ? p.origin.kind : null,
16029
+ rulePath: h.rulePath
16030
+ };
16031
+ }
16032
+ var uniq = (list) => [...new Set(list)];
16033
+ var copyItems = (v) => {
16034
+ if (v === null || typeof v !== "object") return null;
16035
+ const out = {};
16036
+ for (const [k, rows] of Object.entries(v)) {
16037
+ if (isStringList2(rows)) out[k] = [...rows];
16038
+ }
16039
+ return out;
16040
+ };
16041
+ function resolveShare(input) {
16042
+ const { scope, purpose, recipient } = input;
16043
+ if (typeof purpose !== "string" || purpose === "")
16044
+ throw new TypeError("resolveShare: purpose must be a share purpose code");
16045
+ const teamId = typeof input.sender?.teamId === "string" && input.sender.teamId !== "" ? input.sender.teamId : null;
16046
+ const inside = recipient.kind === "sibling_team";
16047
+ const recipientKey = recipient.kind === "partner" ? recipient.id : recipient.kind === "external" ? "__external__" : null;
16048
+ if (recipient.kind === "partner" && (typeof recipient.id !== "string" || recipient.id === "")) {
16049
+ throw new TypeError("resolveShare: a partner recipient needs an id");
16050
+ }
16051
+ const report = SHARE_REPORTING_PURPOSES.has(purpose);
16052
+ const pd = input.platformDefault ?? null;
16053
+ const purposeLabel = typeof input.purposeLabel === "string" && input.purposeLabel !== "" ? input.purposeLabel : purpose;
16054
+ const pdRaw = pd === null ? [] : isStringList2(pd.raw) ? [...pd.raw] : [];
16055
+ const pdRequired = pd === null ? [] : isStringList2(pd.required) ? [...pd.required] : [];
16056
+ const pdBlocked = pd === null ? [] : isStringList2(pd.blocked) ? [...pd.blocked] : [];
16057
+ const policies = (Array.isArray(input.policies) ? input.policies : []).filter(
16058
+ isLiveDoc
16059
+ );
16060
+ const byId = /* @__PURE__ */ new Map();
16061
+ for (const p of policies) byId.set(p.id, p);
16062
+ const att = attachmentIndexFromPolicies(policies);
16063
+ const tree = treeIndex(scope);
16064
+ const systemCode = tree.system;
16065
+ const hit = (id, level2) => {
16066
+ const p = id === void 0 ? void 0 : byId.get(id);
16067
+ if (p === void 0 || p.purpose !== purpose) return null;
16068
+ if (p.trigger?.answers === "received") return null;
16069
+ const v = versionOf(p.version);
16070
+ const name = typeof p.name === "string" ? p.name : p.id;
16071
+ return {
16072
+ policy: p,
16073
+ level: level2,
16074
+ version: v,
16075
+ rulePath: `sharingPurposePolicies[${p.id}] v${v} (policy \u201C${name}\u201D \u2014 ${SHARE_LEVEL_LABEL[level2]})`
16076
+ };
16077
+ };
16078
+ const cell = (map, key) => own3(own3(map, key), purpose);
16079
+ let gov = null;
16080
+ const purposeKnown = pd !== null;
16081
+ const teamRowId = purposeKnown && teamId !== null && recipient.kind !== "external" && typeof input.teamRowId === "string" && input.teamRowId !== "" ? input.teamRowId : null;
16082
+ if (teamRowId !== null) gov = hit(cell(att.teamRows, teamRowId), "team_row");
16083
+ if (gov === null && inside && purposeKnown) {
16084
+ gov = hit(own3(att.internalDefaults, purpose), "account_internal");
16085
+ if (gov === null && pd !== null) {
16086
+ const starter = {
16087
+ id: `pol-inside-starter-${purpose}`,
16088
+ name: `${purposeLabel} \u2014 Inside your account (platform default)`,
16089
+ purpose,
16090
+ infoScope: null,
16091
+ posture: "open",
16092
+ version: 1,
16093
+ origin: { kind: "starter" }
16094
+ };
16095
+ gov = {
16096
+ policy: starter,
16097
+ level: "inside_starter",
16098
+ version: 1,
16099
+ rulePath: `${starter.id} v1 (${SHARE_LEVEL_LABEL.inside_starter} \u2014 the full record, open)`
16100
+ };
16101
+ }
16102
+ }
16103
+ if (gov === null && !inside && purposeKnown && recipientKey !== null) {
16104
+ gov = hit(cell(att.relationships, recipientKey), "relationship");
16105
+ if (gov === null)
16106
+ gov = hit(own3(att.agencyDefaults, purpose), "agency_default");
16107
+ if (gov === null && pd !== null) {
16108
+ const starter = {
16109
+ id: `pol-starter-${purpose}`,
16110
+ name: `${purposeLabel} \u2014 Platform default`,
16111
+ purpose,
16112
+ infoScope: pdRaw.filter((c) => c !== systemCode),
16113
+ posture: "open",
16114
+ version: pd.version,
16115
+ origin: { kind: "platform_starter" },
16116
+ edited: false
16117
+ };
16118
+ gov = {
16119
+ policy: starter,
16120
+ level: "platform_starter",
16121
+ version: pd.version,
16122
+ rulePath: `${starter.id} v${pd.version} (${SHARE_LEVEL_LABEL.platform_starter})`
16123
+ };
16124
+ }
16125
+ }
16126
+ let tc = null;
16127
+ if (teamId !== null && gov !== null) {
16128
+ const t = hit(cell(att.teams, teamId), "team");
16129
+ if (t !== null && t.policy.id !== gov.policy.id) tc = t;
16130
+ }
16131
+ const govNamed = gov === null ? null : named(gov);
16132
+ const tcNamed = tc === null ? null : named(tc);
16133
+ 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)`;
16134
+ let posture = input.relationshipPosture === "approval" || input.relationshipPosture === "blocked" ? input.relationshipPosture : "open";
16135
+ let postureSource = "relationship";
16136
+ let posturePol = null;
16137
+ if (govNamed?.posture && SHARE_POSTURE_RANK[govNamed.posture] > SHARE_POSTURE_RANK[posture]) {
16138
+ posture = govNamed.posture;
16139
+ postureSource = "policy";
16140
+ posturePol = govNamed;
16141
+ }
16142
+ if (tcNamed?.posture && SHARE_POSTURE_RANK[tcNamed.posture] > SHARE_POSTURE_RANK[posture]) {
16143
+ posture = tcNamed.posture;
16144
+ postureSource = "team_ceiling";
16145
+ posturePol = tcNamed;
16146
+ }
16147
+ let excluded = null;
16148
+ let reportCarveOut = null;
16149
+ if (gov === null) {
16150
+ excluded = {
16151
+ reason: `No Platform default for purpose \u201C${purpose}\u201D \u2014 nothing may leave under it`,
16152
+ rulePath
16153
+ };
16154
+ } else if (input.purposeOff === true) {
16155
+ excluded = {
16156
+ reason: "Share purpose disabled by your account's sharing policy",
16157
+ rulePath: `purposeOverrides[${purpose}] = false`
16158
+ };
16159
+ } else if (posture === "blocked") {
16160
+ const pol = posturePol;
16161
+ const path = pol === null ? "relationship posture = blocked" : `sharingPurposePolicies[${pol.id}].posture=blocked (policy \u201C${pol.name}\u201D \u2014 ${pol.levelLabel})`;
16162
+ if (report) {
16163
+ reportCarveOut = {
16164
+ 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`,
16165
+ rulePath: path
16166
+ };
16167
+ } else {
16168
+ excluded = {
16169
+ reason: pol === null ? "Blocked for this purpose by the relationship" : `Blocked for this purpose by your account's \u201C${pol.name}\u201D policy`,
16170
+ rulePath: path
16171
+ };
16172
+ }
16173
+ }
16174
+ const excludedAll = excluded !== null;
16175
+ const level = gov?.level ?? null;
16176
+ const govList = govNamed?.infoScope ?? null;
16177
+ 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);
16178
+ const legacy = legacyCeilingList(input.legacyCeiling);
16179
+ const ceilingIsStarter = legacy === null;
16180
+ let groupCeiling = legacy ?? pdRaw;
16181
+ 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)`;
16182
+ if (ceilingIsStarter && polScopeBinds) {
16183
+ groupCeiling = null;
16184
+ ceilingPath = "";
16185
+ }
16186
+ if (inside) {
16187
+ groupCeiling = null;
16188
+ ceilingPath = "";
16189
+ }
16190
+ const tcScope = tcNamed?.infoScope ?? null;
16191
+ const tcItems = tc?.policy.infoScopeItems ?? null;
16192
+ const govItems = gov?.policy.infoScopeItems ?? null;
16193
+ const required = (g) => g === systemCode || !inside && pd !== null && pdRequired.includes(g);
16194
+ const blockedSet = new Set(pdBlocked);
16195
+ const asSet2 = (v) => new Set(isStringList2(v) ? v : []);
16196
+ const categoriesOff = asSet2(input.accountScope?.categoriesOff);
16197
+ const rowsOff = asSet2(input.accountScope?.rowsOff);
16198
+ const categoriesOn = asSet2(input.accountScope?.categoriesOn);
16199
+ const rowsOn = asSet2(input.accountScope?.rowsOn);
16200
+ const underFloor = (code) => scope.ancestorsOf(code).some((c) => scope.row(c)?.platformFloor === true);
16201
+ const categoryOffByDefault = (g) => !categoriesOn.has(g) && scope.row(g)?.shareableDefault === false;
16202
+ const heightenedOff = (code, g) => {
16203
+ const chain = scope.ancestorsOf(code);
16204
+ if (chain.some((c) => rowsOff.has(c))) return true;
16205
+ const below = chain.slice(0, Math.max(chain.indexOf(g), 0));
16206
+ return below.some(
16207
+ (c) => !rowsOn.has(c) && scope.row(c)?.shareableDefault === false
16208
+ );
16209
+ };
16210
+ const out = {};
16211
+ const allowedCategories = [];
16212
+ const govName = govNamed?.name ?? "";
16213
+ for (const g of tree.categories) {
16214
+ const items = tree.descendants.get(g) ?? [];
16215
+ const leaves = tree.leaves.get(g) ?? [];
16216
+ const platformRequired = !inside && pd !== null && pdRequired.includes(g) ? {
16217
+ rulePath: `pol-starter-${purpose} v${pd.version} \xB7 ${g} = Required (Platform default \u2014 set by the Platform Admin)`
16218
+ } : null;
16219
+ const req = required(g);
16220
+ let allowed = true;
16221
+ let reason = excluded !== null ? excluded.reason : "Allowed";
16222
+ let path = excluded !== null ? excluded.rulePath : rulePath;
16223
+ const floorItems = items.filter(underFloor);
16224
+ const excludedItems = [];
16225
+ let excludedReason = null;
16226
+ const teamExcludedItems = [];
16227
+ let teamExcludedReason = null;
16228
+ const addExcluded = (rows, why) => {
16229
+ for (const r of rows)
16230
+ if (!floorItems.includes(r) && !excludedItems.includes(r))
16231
+ excludedItems.push(r);
16232
+ if (rows.length > 0 && excludedReason === null) excludedReason = why;
16233
+ };
16234
+ if (gov === null) {
16235
+ allowed = false;
16236
+ } else if ((!req || platformRequired !== null) && excludedAll) {
16237
+ allowed = false;
16238
+ } else if (excludedAll) {
16239
+ reason = "Allowed";
16240
+ path = rulePath;
16241
+ }
16242
+ if (allowed && !req && (categoriesOff.has(g) || categoryOffByDefault(g))) {
16243
+ allowed = false;
16244
+ reason = "Excluded by your account's Information Scope policy";
16245
+ 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)`;
16246
+ }
16247
+ if (allowed && !req && !inside && blockedSet.has(g)) {
16248
+ allowed = false;
16249
+ reason = "Blocked for this purpose by the Platform default \u2014 no account can share it under this purpose";
16250
+ path = `pol-starter-${purpose} v${pd?.version ?? 1} \xB7 ${g} = Blocked (Platform default \u2014 CVC-236 heightened protection | set by the Platform Admin)`;
16251
+ }
16252
+ addExcluded(
16253
+ g === systemCode ? [] : items.filter((r) => !underFloor(r) && heightenedOff(r, g)),
16254
+ "Heightened protection (CVC-236) \u2014 off in your account's Information Scope until the account turns it on"
16255
+ );
16256
+ if (allowed && !req && groupCeiling !== null && !scopeListCovers(scope, groupCeiling, g)) {
16257
+ allowed = false;
16258
+ reason = "Outside the payload for this purpose";
16259
+ path = ceilingPath;
16260
+ }
16261
+ if (allowed && !req && groupCeiling !== null && !scopeListStrictlyCovers(scope, groupCeiling, g)) {
16262
+ addExcluded(
16263
+ items.filter((r) => !scopeListCovers(scope, groupCeiling, g, r)),
16264
+ "Outside the payload for this purpose"
16265
+ );
16266
+ }
16267
+ if (allowed && !req && polScopeBinds && !scopeListCovers(scope, govList, g)) {
16268
+ allowed = false;
16269
+ reason = `Outside what the \u201C${govName}\u201D policy allows for this purpose`;
16270
+ path = `sharingPurposePolicies[${gov?.policy.id}].infoScope (policy \u201C${govName}\u201D \u2014 ${govNamed?.levelLabel})`;
16271
+ }
16272
+ if (allowed && !req && polScopeBinds && !scopeListStrictlyCovers(scope, govList, g)) {
16273
+ addExcluded(
16274
+ items.filter((r) => !scopeListCovers(scope, govList, g, r)),
16275
+ `Outside what the \u201C${govName}\u201D policy allows for this purpose`
16276
+ );
16277
+ }
16278
+ const govRows = polScopeBinds ? own3(govItems, g) : void 0;
16279
+ if (allowed && !req && isStringList2(govRows)) {
16280
+ const keep = new Set(govRows);
16281
+ addExcluded(
16282
+ items.filter(
16283
+ (r) => !keep.has(r) && !scope.ancestorsOf(r).some((a) => a !== g && keep.has(a))
16284
+ ),
16285
+ `Outside what the \u201C${govName}\u201D policy allows for this purpose`
16286
+ );
16287
+ }
16288
+ if (allowed && !req && tcScope !== null && !scopeListCovers(scope, tcScope, g)) {
16289
+ allowed = false;
16290
+ reason = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;
16291
+ path = `sharingPurposePolicies[${tc?.policy.id}].infoScope (policy \u201C${tcNamed?.name}\u201D \u2014 ${SHARE_LEVEL_LABEL.team}; a ceiling over \u201C${govName}\u201D)`;
16292
+ }
16293
+ if (allowed && !req && tc !== null) {
16294
+ const why = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;
16295
+ const outRows = /* @__PURE__ */ new Set();
16296
+ if (tcScope !== null && !scopeListStrictlyCovers(scope, tcScope, g)) {
16297
+ for (const r of items)
16298
+ if (!scopeListCovers(scope, tcScope, g, r)) outRows.add(r);
16299
+ }
16300
+ const tcRows = own3(tcItems, g);
16301
+ if (isStringList2(tcRows)) {
16302
+ const keep = new Set(tcRows);
16303
+ for (const r of items)
16304
+ if (!keep.has(r) && !scope.ancestorsOf(r).some((a) => a !== g && keep.has(a)))
16305
+ outRows.add(r);
16306
+ }
16307
+ for (const r of outRows)
16308
+ if (!floorItems.includes(r) && !excludedItems.includes(r))
16309
+ teamExcludedItems.push(r);
16310
+ if (teamExcludedItems.length > 0) teamExcludedReason = why;
16311
+ }
16312
+ if (allowed && (!req || platformRequired !== null) && leaves.length > 0) {
16313
+ const gone = new Set(
16314
+ [...floorItems, ...excludedItems, ...teamExcludedItems].filter(
16315
+ (r) => leaves.includes(r)
16316
+ )
16317
+ );
16318
+ if (gone.size >= leaves.length) {
16319
+ allowed = false;
16320
+ if (leaves.every((r) => floorItems.includes(r))) {
16321
+ reason = "Never shared \u2014 under the platform safety floor";
16322
+ path = "HTI_PLATFORM_SAFETY_FLOOR";
16323
+ } else if (leaves.some((r) => excludedItems.includes(r))) {
16324
+ reason = excludedReason ?? reason;
16325
+ } else {
16326
+ reason = teamExcludedReason ?? reason;
16327
+ }
16328
+ }
16329
+ }
16330
+ out[g] = {
16331
+ allowed,
16332
+ reason,
16333
+ rulePath: path,
16334
+ platformRequired,
16335
+ floorItems: uniq(floorItems),
16336
+ excludedItems: uniq(excludedItems),
16337
+ excludedReason,
16338
+ teamExcludedItems: uniq(teamExcludedItems),
16339
+ teamExcludedReason
16340
+ };
16341
+ if (allowed) allowedCategories.push(g);
16342
+ }
16343
+ return {
16344
+ allowed: !excludedAll,
16345
+ posture,
16346
+ postureSource,
16347
+ excluded,
16348
+ reportCarveOut,
16349
+ governing: govNamed,
16350
+ teamCeiling: tcNamed,
16351
+ inside,
16352
+ scope: out,
16353
+ allowedCategories,
16354
+ rulePath
16355
+ };
16356
+ }
16357
+
15762
16358
  // src/validation/cvc.ts
15763
16359
  import { z } from "zod";
15764
16360
  var CvcCodeSchema = z.string().regex(/^\d{3}(-\d{3}){6}$/);
@@ -68653,6 +69249,7 @@ export {
68653
69249
  GoalWithdrawalReasonKeys,
68654
69250
  HEALTHCARE_ORG_TYPE_KEYS,
68655
69251
  HTI_SHARE_PLATFORM_PURPOSE_ENABLED,
69252
+ HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE,
68656
69253
  HTI_SHARE_PLATFORM_STARTER,
68657
69254
  HTI_SHARE_PLATFORM_STARTER_SOURCE,
68658
69255
  HairColorKeys,
@@ -68853,6 +69450,10 @@ export {
68853
69450
  SERVICE_STATE_STAMP_CROSSWALK,
68854
69451
  SESSION_STATES,
68855
69452
  SESSION_STATE_LABELS,
69453
+ SHARE_LEVEL_LABEL,
69454
+ SHARE_PLATFORM_STATE_LABEL,
69455
+ SHARE_POSTURE_RANK,
69456
+ SHARE_REPORTING_PURPOSES,
68856
69457
  SHARE_VIEW,
68857
69458
  SHARE_VIEW_LABELS,
68858
69459
  SHARE_VIEW_VALUES,
@@ -68945,6 +69546,7 @@ export {
68945
69546
  applyRunValidatorsIfUnset,
68946
69547
  assertionDomain_v1_1_0_default as assertionDomainSot,
68947
69548
  assertionStatus_v2_0_0_default as assertionStatusSot,
69549
+ attachmentIndexFromPolicies,
68948
69550
  basisQuickPicks_v1_0_0_default as basisQuickPicksSot,
68949
69551
  buildCvcEntrySchema,
68950
69552
  buildCvcRegistrySchema,
@@ -69002,6 +69604,7 @@ export {
69002
69604
  daIncidentSeverity_v1_0_0_default as daIncidentSeveritySot,
69003
69605
  demographicsSchema,
69004
69606
  deriveAgeBinFromAge,
69607
+ derivePlatformDefault,
69005
69608
  determinationHelperCategories_v1_0_0_default as determinationHelperCategoriesSot,
69006
69609
  determinationLevel_v1_0_0_default as determinationLevelSot,
69007
69610
  disabilitySubtype_v1_0_0_default as disabilitySubtypeSot,
@@ -69103,10 +69706,12 @@ export {
69103
69706
  layoutSchema,
69104
69707
  leReportStatus_v1_0_0_default as leReportStatusSot,
69105
69708
  legalActionType_v1_0_0_default as legalActionTypeSot,
69709
+ liveCategories,
69106
69710
  livingSituation_v1_0_0_default as livingSituationSot,
69107
69711
  locationType_v1_0_0_default as locationTypeSot,
69108
69712
  maritalStatusLegal_v1_0_0_default as maritalStatusLegalSot,
69109
69713
  maskSelectionToCeiling,
69714
+ matchTeamRow,
69110
69715
  mentalHealthStatus_v1_0_0_default as mentalHealthStatusSot,
69111
69716
  messageReportReason_v1_0_0_default as messageReportReasonSot,
69112
69717
  midStayEventType_v1_0_0_default as midStayEventTypeSot,
@@ -69143,6 +69748,7 @@ export {
69143
69748
  petExitReason_v1_0_0_default as petExitReasonSot,
69144
69749
  petRelationshipBasis_v1_0_0_default as petRelationshipBasisSot,
69145
69750
  phoneSchema,
69751
+ platformDefaultFor,
69146
69752
  platformFunctionModel_exports as platformFunctionModel,
69147
69753
  platformFunctionSchemaDefinition,
69148
69754
  platformFunctionSchemaOptions,
@@ -69183,6 +69789,7 @@ export {
69183
69789
  resolveOrgTypeKeyFromLegacyNumeric,
69184
69790
  resolveReferralEntityKeyFromLegacyNumeric,
69185
69791
  resolveRegistryWithInheritance,
69792
+ resolveShare,
69186
69793
  returnedToAbuserStatus_v1_0_0_default as returnedToAbuserStatusSot,
69187
69794
  riskCategory_v1_0_0_default as riskCategorySot,
69188
69795
  riskIdentificationMilestone_v1_0_0_default as riskIdentificationMilestoneSot,
@@ -69196,6 +69803,8 @@ export {
69196
69803
  rowsOutsideCeiling,
69197
69804
  rowsOverCeiling,
69198
69805
  rsvpResponse_v1_0_0_default as rsvpResponseSot,
69806
+ scopeListCovers,
69807
+ scopeListStrictlyCovers,
69199
69808
  scopeMigrationsFromSot,
69200
69809
  scopeRowWithinCeiling,
69201
69810
  scopeRowsFromSot,
@@ -69231,6 +69840,7 @@ export {
69231
69840
  shareDefaultScopeFor,
69232
69841
  sharePurpose_v1_0_0_default as sharePurposeSot,
69233
69842
  shareResponseReason_v1_0_0_default as shareResponseReasonSot,
69843
+ shareRowCeiling,
69234
69844
  sharingCeilingCellList,
69235
69845
  sharingCeilingRowKey,
69236
69846
  sharingScopeEditsFromCells,
@@ -69251,6 +69861,7 @@ export {
69251
69861
  suggestionSource_v1_0_0_default as suggestionSourceSot,
69252
69862
  supportStrength_v1_0_0_default as supportStrengthSot,
69253
69863
  supportTopic_v1_0_0_default as supportTopicSot,
69864
+ systemCategoryOf,
69254
69865
  teamDirectorySchemaDefinition,
69255
69866
  threadStatus_v1_0_0_default as threadStatusSot,
69256
69867
  threadType_v1_0_0_default as threadTypeSot,