@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.
@@ -21,29 +21,44 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var sharingCeiling_exports = {};
22
22
  __export(sharingCeiling_exports, {
23
23
  HTI_SHARE_PLATFORM_PURPOSE_ENABLED: () => HTI_SHARE_PLATFORM_PURPOSE_ENABLED,
24
+ HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE: () => HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE,
24
25
  HTI_SHARE_PLATFORM_STARTER: () => HTI_SHARE_PLATFORM_STARTER,
25
26
  HTI_SHARE_PLATFORM_STARTER_SOURCE: () => HTI_SHARE_PLATFORM_STARTER_SOURCE,
26
27
  INFORMATION_SCOPE_FIELD_HOME_ROWS: () => INFORMATION_SCOPE_FIELD_HOME_ROWS,
28
+ SHARE_LEVEL_LABEL: () => SHARE_LEVEL_LABEL,
29
+ SHARE_PLATFORM_STATE_LABEL: () => SHARE_PLATFORM_STATE_LABEL,
30
+ SHARE_POSTURE_RANK: () => SHARE_POSTURE_RANK,
31
+ SHARE_REPORTING_PURPOSES: () => SHARE_REPORTING_PURPOSES,
27
32
  SHARING_CEILING_DEFAULT_ROW_KEY: () => SHARING_CEILING_DEFAULT_ROW_KEY,
28
33
  SHARING_CEILING_EXTERNAL_ROW_KEY: () => SHARING_CEILING_EXTERNAL_ROW_KEY,
29
34
  SHARING_CEILING_SCOPE_VERSION: () => SHARING_CEILING_SCOPE_VERSION,
30
35
  accountSharePurposePolicy: () => accountSharePurposePolicy,
36
+ attachmentIndexFromPolicies: () => attachmentIndexFromPolicies,
31
37
  ceilingCoverage: () => ceilingCoverage,
38
+ derivePlatformDefault: () => derivePlatformDefault,
32
39
  effectiveCeiling: () => effectiveCeiling,
33
40
  hasOwnScopeContent: () => hasOwnScopeContent,
34
41
  intersectSharingCeilingLists: () => intersectSharingCeilingLists,
35
42
  isCeilingCoverageRow: () => isCeilingCoverageRow,
36
43
  isPermittedByCeiling: () => isPermittedByCeiling,
37
44
  isSharingPurposeDisabled: () => isSharingPurposeDisabled,
45
+ liveCategories: () => liveCategories,
38
46
  maskSelectionToCeiling: () => maskSelectionToCeiling,
47
+ matchTeamRow: () => matchTeamRow,
48
+ platformDefaultFor: () => platformDefaultFor,
49
+ resolveShare: () => resolveShare,
39
50
  rowsExpandedByCeiling: () => rowsExpandedByCeiling,
40
51
  rowsOutsideCeiling: () => rowsOutsideCeiling,
41
52
  rowsOverCeiling: () => rowsOverCeiling,
53
+ scopeListCovers: () => scopeListCovers,
54
+ scopeListStrictlyCovers: () => scopeListStrictlyCovers,
42
55
  scopeRowWithinCeiling: () => scopeRowWithinCeiling,
43
56
  shareDefaultScopeFor: () => shareDefaultScopeFor,
57
+ shareRowCeiling: () => shareRowCeiling,
44
58
  sharingCeilingCellList: () => sharingCeilingCellList,
45
59
  sharingCeilingRowKey: () => sharingCeilingRowKey,
46
- sharingScopeEditsFromCells: () => sharingScopeEditsFromCells
60
+ sharingScopeEditsFromCells: () => sharingScopeEditsFromCells,
61
+ systemCategoryOf: () => systemCategoryOf
47
62
  });
48
63
  module.exports = __toCommonJS(sharingCeiling_exports);
49
64
 
@@ -518,31 +533,642 @@ function shareDefaultScopeFor(edits, purpose, opts = {}) {
518
533
  };
519
534
  }
520
535
  var accountSharePurposePolicy = shareDefaultScopeFor;
536
+
537
+ // src/sharingCeiling/resolve.ts
538
+ var SHARE_REPORTING_PURPOSES = /* @__PURE__ */ new Set([
539
+ "mandatory_reporting",
540
+ "authority_reporting"
541
+ ]);
542
+ var SHARE_POSTURE_RANK = Object.freeze({
543
+ open: 0,
544
+ approval: 1,
545
+ blocked: 2
546
+ });
547
+ var SHARE_PLATFORM_STATE_LABEL = Object.freeze({
548
+ always: "Required",
549
+ default_on: "Default On",
550
+ default_off: "Default Off",
551
+ never: "Blocked"
552
+ });
553
+ var SHARE_LEVEL_LABEL = Object.freeze({
554
+ team_row: "attached on the team-to-team row",
555
+ relationship: "attached to this relationship",
556
+ agency_default: "your account's default for this purpose",
557
+ account_internal: "your account's default for sharing between its own teams",
558
+ team: "your account's rule for this team",
559
+ platform_starter: "Platform default",
560
+ inside_starter: "the platform's default for sharing inside your account"
561
+ });
562
+ var own2 = (record, key) => record !== null && typeof record === "object" && Object.prototype.hasOwnProperty.call(record, key) ? record[key] : void 0;
563
+ var isStringList2 = (v) => Array.isArray(v) && v.every((c) => typeof c === "string");
564
+ var versionOf = (v) => {
565
+ const n = typeof v === "number" ? v : parseInt(String(v), 10);
566
+ return Number.isFinite(n) && n > 0 ? Math.trunc(n) : 1;
567
+ };
568
+ var docList = (v) => v === null || v === void 0 ? null : isStringList2(v) ? [...v] : [];
569
+ function scopeListCovers(scope, list, categoryCode, rowCode) {
570
+ if (!Array.isArray(list)) return true;
571
+ const set = new Set(list);
572
+ if (scope.ancestorsOf(categoryCode).some((c) => set.has(c))) return true;
573
+ if (rowCode !== void 0)
574
+ return scope.ancestorsOf(rowCode).some((c) => set.has(c));
575
+ return list.some(
576
+ (id) => scope.ancestorsOf(id).slice(1).includes(categoryCode)
577
+ );
578
+ }
579
+ function scopeListStrictlyCovers(scope, list, categoryCode) {
580
+ if (!Array.isArray(list)) return true;
581
+ const set = new Set(list);
582
+ return scope.ancestorsOf(categoryCode).some((c) => set.has(c));
583
+ }
584
+ var isLiveDoc = (p) => p !== null && typeof p === "object" && typeof p.id === "string" && p.id !== "" && typeof p.purpose === "string" && p.active !== false;
585
+ function attachmentIndexFromPolicies(policies) {
586
+ const nullMap = () => /* @__PURE__ */ Object.create(null);
587
+ const agencyDefaults = nullMap();
588
+ const internalDefaults = nullMap();
589
+ const relationships = nullMap();
590
+ const teamRows = nullMap();
591
+ const teams = nullMap();
592
+ const put = (map, key, purpose, id) => {
593
+ const row = Object.prototype.hasOwnProperty.call(map, key) ? map[key] : map[key] = nullMap();
594
+ row[purpose] = id;
595
+ };
596
+ for (const p of Array.isArray(policies) ? policies : []) {
597
+ if (!isLiveDoc(p)) continue;
598
+ for (const a of Array.isArray(p.assignments) ? p.assignments : []) {
599
+ if (a === null || typeof a !== "object") continue;
600
+ switch (a.scope) {
601
+ case "account":
602
+ agencyDefaults[p.purpose] = p.id;
603
+ break;
604
+ case "account_internal":
605
+ internalDefaults[p.purpose] = p.id;
606
+ break;
607
+ case "account_partner":
608
+ if (typeof a.partnerId === "string" && a.partnerId !== "")
609
+ put(relationships, a.partnerId, p.purpose, p.id);
610
+ break;
611
+ case "team":
612
+ if (typeof a.teamId === "string" && a.teamId !== "")
613
+ put(teams, a.teamId, p.purpose, p.id);
614
+ break;
615
+ case "team_pair":
616
+ if (typeof a.teamRowId === "string" && a.teamRowId !== "")
617
+ put(teamRows, a.teamRowId, p.purpose, p.id);
618
+ break;
619
+ default:
620
+ break;
621
+ }
622
+ }
623
+ }
624
+ return { agencyDefaults, internalDefaults, relationships, teamRows, teams };
625
+ }
626
+ function matchTeamRow(rows, teamId, recipient, options = {}) {
627
+ if (typeof teamId !== "string" || teamId === "" || !Array.isArray(rows))
628
+ return null;
629
+ const drop = new Set(options.shareBackOnlyRowIds ?? []);
630
+ const live = rows.filter(
631
+ (r) => r !== null && typeof r === "object" && typeof r.id === "string" && !drop.has(r.id)
632
+ );
633
+ if (recipient.kind === "sibling_team") {
634
+ return live.find(
635
+ (r) => r.myTeamId === teamId && r.their?.id === recipient.teamId
636
+ )?.id ?? null;
637
+ }
638
+ if (recipient.kind === "external") return null;
639
+ if (options.scopeMode === "team_scoped")
640
+ return live.find((r) => r.myTeamId === teamId)?.id ?? null;
641
+ return live.find(
642
+ (r) => r.myTeamId === teamId && (!r.their || r.their.type !== "team" || r.their.id === recipient.id)
643
+ )?.id ?? null;
644
+ }
645
+ function derivePlatformDefault(scope, purpose, seedList, options = {}) {
646
+ const seed = isStringList2(seedList) ? [...seedList] : [];
647
+ const req = new Set(options.required ?? []);
648
+ const states = {};
649
+ const required = [];
650
+ const blocked = [];
651
+ const systemCode = systemCategoryOf(scope);
652
+ for (const g of liveCategories(scope)) {
653
+ let state;
654
+ if (g === systemCode) state = "always";
655
+ else if (req.has(g)) state = "always";
656
+ else if (scope.row(g)?.shareableDefault === false) state = "never";
657
+ else state = scopeListCovers(scope, seed, g) ? "default_on" : "default_off";
658
+ const bound = own2(options.bounds, g);
659
+ if (g !== systemCode && (bound === "always" || bound === "default_on" || bound === "default_off" || bound === "never"))
660
+ state = bound;
661
+ states[g] = state;
662
+ if (state === "always" && g !== systemCode) required.push(g);
663
+ if (state === "never") blocked.push(g);
664
+ }
665
+ const categoryOf = (code) => scope.ancestorsOf(code).find((c) => scope.row(c)?.rowType === "category");
666
+ const raw = [];
667
+ const push = (c) => {
668
+ if (!raw.includes(c)) raw.push(c);
669
+ };
670
+ for (const code of seed) {
671
+ const g = categoryOf(code);
672
+ if (g === void 0) {
673
+ for (const [cat, st2] of Object.entries(states)) {
674
+ if ((st2 === "always" || st2 === "default_on") && scope.ancestorsOf(cat).includes(code))
675
+ push(cat);
676
+ }
677
+ continue;
678
+ }
679
+ const st = states[g];
680
+ if (st === "never" || st === "default_off") continue;
681
+ push(code);
682
+ }
683
+ for (const [g, st] of Object.entries(states)) {
684
+ if ((st === "always" || st === "default_on") && !scopeListCovers(scope, raw, g))
685
+ push(g);
686
+ }
687
+ if (systemCode !== void 0) push(systemCode);
688
+ return {
689
+ purpose,
690
+ version: versionOf(options.version),
691
+ raw,
692
+ states,
693
+ required,
694
+ blocked,
695
+ edited: options.edited === true
696
+ };
697
+ }
698
+ var treeCache = /* @__PURE__ */ new WeakMap();
699
+ function treeIndex(scope) {
700
+ const hit = treeCache.get(scope);
701
+ if (hit) return hit;
702
+ const live = (code) => scope.row(code) !== void 0 && scope.ancestorsOf(code).every((c) => scope.row(c)?.status !== "retired");
703
+ const categories = scope.rows.filter((r) => r.rowType === "category" && live(r.scopeCode)).map((r) => r.scopeCode);
704
+ const systemInfoPath = scope.row("system_info") !== void 0 ? scope.ancestorsOf("system_info") : [];
705
+ const system = systemInfoPath.find((c) => categories.includes(c)) ?? categories.find((g) => g === "system");
706
+ const descendants = /* @__PURE__ */ new Map();
707
+ const leaves = /* @__PURE__ */ new Map();
708
+ for (const g of categories) {
709
+ const all = [];
710
+ const walk = (code) => {
711
+ for (const c of scope.childrenOf(code)) {
712
+ if (!live(c)) continue;
713
+ all.push(c);
714
+ walk(c);
715
+ }
716
+ };
717
+ walk(g);
718
+ descendants.set(g, all);
719
+ leaves.set(
720
+ g,
721
+ all.filter((c) => !scope.childrenOf(c).some(live))
722
+ );
723
+ }
724
+ const out = { categories, system, leaves, descendants };
725
+ treeCache.set(scope, out);
726
+ return out;
727
+ }
728
+ function liveCategories(scope) {
729
+ return [...treeIndex(scope).categories];
730
+ }
731
+ function systemCategoryOf(scope) {
732
+ return treeIndex(scope).system;
733
+ }
734
+ function legacyCeilingList(v) {
735
+ if (v === null || v === void 0) return null;
736
+ if (isStringList2(v)) return [...v];
737
+ if (typeof v === "object" && "rung" in v) {
738
+ const r = v.rung;
739
+ if (r === "partner_rule" || r === "seeded_partner_rule" || r === "account_default") {
740
+ return isStringList2(v.allowed) ? [...v.allowed] : [];
741
+ }
742
+ return null;
743
+ }
744
+ return null;
745
+ }
746
+ var HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE = Object.freeze({
747
+ mandatory_reporting: Object.freeze(["identifying"]),
748
+ authority_reporting: Object.freeze(["identifying"])
749
+ });
750
+ function platformDefaultFor(scope, purpose, options = {}) {
751
+ const starter = options.starter ?? HTI_SHARE_PLATFORM_STARTER;
752
+ const seed = own2(starter.scopeByPurpose, purpose);
753
+ if (!isStringList2(seed)) return null;
754
+ return derivePlatformDefault(scope, purpose, seed, {
755
+ required: own2(HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE, purpose) ?? [],
756
+ bounds: options.bounds ?? null,
757
+ version: options.version ?? 1,
758
+ edited: options.edited === true
759
+ });
760
+ }
761
+ function shareRowCeiling(resolution, scope) {
762
+ if (!resolution.allowed) return [];
763
+ const out = [];
764
+ for (const g of resolution.allowedCategories) {
765
+ const e = own2(resolution.scope, g);
766
+ if (e === void 0) continue;
767
+ const withheld = /* @__PURE__ */ new Set([
768
+ ...e.excludedItems,
769
+ ...e.teamExcludedItems,
770
+ ...e.floorItems
771
+ ]);
772
+ if (withheld.size === 0) {
773
+ out.push(g);
774
+ continue;
775
+ }
776
+ const live = (c) => scope.row(c) !== void 0 && scope.ancestorsOf(c).every((a) => scope.row(a)?.status !== "retired");
777
+ const anyWithheldBeneath = (c) => scope.childrenOf(c).some((k) => live(k) && (withheld.has(k) || anyWithheldBeneath(k)));
778
+ const visit = (c) => {
779
+ if (withheld.has(c) || !live(c)) return;
780
+ if (!anyWithheldBeneath(c)) {
781
+ out.push(c);
782
+ return;
783
+ }
784
+ for (const k of scope.childrenOf(c)) visit(k);
785
+ };
786
+ for (const k of scope.childrenOf(g)) visit(k);
787
+ }
788
+ return out;
789
+ }
790
+ function named(h) {
791
+ const p = h.policy;
792
+ return {
793
+ id: p.id,
794
+ familyId: typeof p.familyId === "string" && p.familyId !== "" ? p.familyId : p.id,
795
+ name: typeof p.name === "string" ? p.name : p.id,
796
+ version: h.version,
797
+ level: h.level,
798
+ levelLabel: SHARE_LEVEL_LABEL[h.level],
799
+ posture: p.posture === "open" || p.posture === "approval" || p.posture === "blocked" ? p.posture : null,
800
+ infoScope: docList(p.infoScope),
801
+ infoScopeItems: copyItems(p.infoScopeItems),
802
+ edited: p.edited === true,
803
+ origin: typeof p.origin?.kind === "string" ? p.origin.kind : null,
804
+ rulePath: h.rulePath
805
+ };
806
+ }
807
+ var uniq = (list) => [...new Set(list)];
808
+ var copyItems = (v) => {
809
+ if (v === null || typeof v !== "object") return null;
810
+ const out = {};
811
+ for (const [k, rows] of Object.entries(v)) {
812
+ if (isStringList2(rows)) out[k] = [...rows];
813
+ }
814
+ return out;
815
+ };
816
+ function resolveShare(input) {
817
+ const { scope, purpose, recipient } = input;
818
+ if (typeof purpose !== "string" || purpose === "")
819
+ throw new TypeError("resolveShare: purpose must be a share purpose code");
820
+ const teamId = typeof input.sender?.teamId === "string" && input.sender.teamId !== "" ? input.sender.teamId : null;
821
+ const inside = recipient.kind === "sibling_team";
822
+ const recipientKey = recipient.kind === "partner" ? recipient.id : recipient.kind === "external" ? "__external__" : null;
823
+ if (recipient.kind === "partner" && (typeof recipient.id !== "string" || recipient.id === "")) {
824
+ throw new TypeError("resolveShare: a partner recipient needs an id");
825
+ }
826
+ const report = SHARE_REPORTING_PURPOSES.has(purpose);
827
+ const pd = input.platformDefault ?? null;
828
+ const purposeLabel = typeof input.purposeLabel === "string" && input.purposeLabel !== "" ? input.purposeLabel : purpose;
829
+ const pdRaw = pd === null ? [] : isStringList2(pd.raw) ? [...pd.raw] : [];
830
+ const pdRequired = pd === null ? [] : isStringList2(pd.required) ? [...pd.required] : [];
831
+ const pdBlocked = pd === null ? [] : isStringList2(pd.blocked) ? [...pd.blocked] : [];
832
+ const policies = (Array.isArray(input.policies) ? input.policies : []).filter(
833
+ isLiveDoc
834
+ );
835
+ const byId = /* @__PURE__ */ new Map();
836
+ for (const p of policies) byId.set(p.id, p);
837
+ const att = attachmentIndexFromPolicies(policies);
838
+ const tree = treeIndex(scope);
839
+ const systemCode = tree.system;
840
+ const hit = (id, level2) => {
841
+ const p = id === void 0 ? void 0 : byId.get(id);
842
+ if (p === void 0 || p.purpose !== purpose) return null;
843
+ if (p.trigger?.answers === "received") return null;
844
+ const v = versionOf(p.version);
845
+ const name = typeof p.name === "string" ? p.name : p.id;
846
+ return {
847
+ policy: p,
848
+ level: level2,
849
+ version: v,
850
+ rulePath: `sharingPurposePolicies[${p.id}] v${v} (policy \u201C${name}\u201D \u2014 ${SHARE_LEVEL_LABEL[level2]})`
851
+ };
852
+ };
853
+ const cell = (map, key) => own2(own2(map, key), purpose);
854
+ let gov = null;
855
+ const purposeKnown = pd !== null;
856
+ const teamRowId = purposeKnown && teamId !== null && recipient.kind !== "external" && typeof input.teamRowId === "string" && input.teamRowId !== "" ? input.teamRowId : null;
857
+ if (teamRowId !== null) gov = hit(cell(att.teamRows, teamRowId), "team_row");
858
+ if (gov === null && inside && purposeKnown) {
859
+ gov = hit(own2(att.internalDefaults, purpose), "account_internal");
860
+ if (gov === null && pd !== null) {
861
+ const starter = {
862
+ id: `pol-inside-starter-${purpose}`,
863
+ name: `${purposeLabel} \u2014 Inside your account (platform default)`,
864
+ purpose,
865
+ infoScope: null,
866
+ posture: "open",
867
+ version: 1,
868
+ origin: { kind: "starter" }
869
+ };
870
+ gov = {
871
+ policy: starter,
872
+ level: "inside_starter",
873
+ version: 1,
874
+ rulePath: `${starter.id} v1 (${SHARE_LEVEL_LABEL.inside_starter} \u2014 the full record, open)`
875
+ };
876
+ }
877
+ }
878
+ if (gov === null && !inside && purposeKnown && recipientKey !== null) {
879
+ gov = hit(cell(att.relationships, recipientKey), "relationship");
880
+ if (gov === null)
881
+ gov = hit(own2(att.agencyDefaults, purpose), "agency_default");
882
+ if (gov === null && pd !== null) {
883
+ const starter = {
884
+ id: `pol-starter-${purpose}`,
885
+ name: `${purposeLabel} \u2014 Platform default`,
886
+ purpose,
887
+ infoScope: pdRaw.filter((c) => c !== systemCode),
888
+ posture: "open",
889
+ version: pd.version,
890
+ origin: { kind: "platform_starter" },
891
+ edited: false
892
+ };
893
+ gov = {
894
+ policy: starter,
895
+ level: "platform_starter",
896
+ version: pd.version,
897
+ rulePath: `${starter.id} v${pd.version} (${SHARE_LEVEL_LABEL.platform_starter})`
898
+ };
899
+ }
900
+ }
901
+ let tc = null;
902
+ if (teamId !== null && gov !== null) {
903
+ const t = hit(cell(att.teams, teamId), "team");
904
+ if (t !== null && t.policy.id !== gov.policy.id) tc = t;
905
+ }
906
+ const govNamed = gov === null ? null : named(gov);
907
+ const tcNamed = tc === null ? null : named(tc);
908
+ 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)`;
909
+ let posture = input.relationshipPosture === "approval" || input.relationshipPosture === "blocked" ? input.relationshipPosture : "open";
910
+ let postureSource = "relationship";
911
+ let posturePol = null;
912
+ if (govNamed?.posture && SHARE_POSTURE_RANK[govNamed.posture] > SHARE_POSTURE_RANK[posture]) {
913
+ posture = govNamed.posture;
914
+ postureSource = "policy";
915
+ posturePol = govNamed;
916
+ }
917
+ if (tcNamed?.posture && SHARE_POSTURE_RANK[tcNamed.posture] > SHARE_POSTURE_RANK[posture]) {
918
+ posture = tcNamed.posture;
919
+ postureSource = "team_ceiling";
920
+ posturePol = tcNamed;
921
+ }
922
+ let excluded = null;
923
+ let reportCarveOut = null;
924
+ if (gov === null) {
925
+ excluded = {
926
+ reason: `No Platform default for purpose \u201C${purpose}\u201D \u2014 nothing may leave under it`,
927
+ rulePath
928
+ };
929
+ } else if (input.purposeOff === true) {
930
+ excluded = {
931
+ reason: "Share purpose disabled by your account's sharing policy",
932
+ rulePath: `purposeOverrides[${purpose}] = false`
933
+ };
934
+ } else if (posture === "blocked") {
935
+ const pol = posturePol;
936
+ const path = pol === null ? "relationship posture = blocked" : `sharingPurposePolicies[${pol.id}].posture=blocked (policy \u201C${pol.name}\u201D \u2014 ${pol.levelLabel})`;
937
+ if (report) {
938
+ reportCarveOut = {
939
+ 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`,
940
+ rulePath: path
941
+ };
942
+ } else {
943
+ excluded = {
944
+ reason: pol === null ? "Blocked for this purpose by the relationship" : `Blocked for this purpose by your account's \u201C${pol.name}\u201D policy`,
945
+ rulePath: path
946
+ };
947
+ }
948
+ }
949
+ const excludedAll = excluded !== null;
950
+ const level = gov?.level ?? null;
951
+ const govList = govNamed?.infoScope ?? null;
952
+ 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);
953
+ const legacy = legacyCeilingList(input.legacyCeiling);
954
+ const ceilingIsStarter = legacy === null;
955
+ let groupCeiling = legacy ?? pdRaw;
956
+ 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)`;
957
+ if (ceilingIsStarter && polScopeBinds) {
958
+ groupCeiling = null;
959
+ ceilingPath = "";
960
+ }
961
+ if (inside) {
962
+ groupCeiling = null;
963
+ ceilingPath = "";
964
+ }
965
+ const tcScope = tcNamed?.infoScope ?? null;
966
+ const tcItems = tc?.policy.infoScopeItems ?? null;
967
+ const govItems = gov?.policy.infoScopeItems ?? null;
968
+ const required = (g) => g === systemCode || !inside && pd !== null && pdRequired.includes(g);
969
+ const blockedSet = new Set(pdBlocked);
970
+ const asSet = (v) => new Set(isStringList2(v) ? v : []);
971
+ const categoriesOff = asSet(input.accountScope?.categoriesOff);
972
+ const rowsOff = asSet(input.accountScope?.rowsOff);
973
+ const categoriesOn = asSet(input.accountScope?.categoriesOn);
974
+ const rowsOn = asSet(input.accountScope?.rowsOn);
975
+ const underFloor = (code) => scope.ancestorsOf(code).some((c) => scope.row(c)?.platformFloor === true);
976
+ const categoryOffByDefault = (g) => !categoriesOn.has(g) && scope.row(g)?.shareableDefault === false;
977
+ const heightenedOff = (code, g) => {
978
+ const chain = scope.ancestorsOf(code);
979
+ if (chain.some((c) => rowsOff.has(c))) return true;
980
+ const below = chain.slice(0, Math.max(chain.indexOf(g), 0));
981
+ return below.some(
982
+ (c) => !rowsOn.has(c) && scope.row(c)?.shareableDefault === false
983
+ );
984
+ };
985
+ const out = {};
986
+ const allowedCategories = [];
987
+ const govName = govNamed?.name ?? "";
988
+ for (const g of tree.categories) {
989
+ const items = tree.descendants.get(g) ?? [];
990
+ const leaves = tree.leaves.get(g) ?? [];
991
+ const platformRequired = !inside && pd !== null && pdRequired.includes(g) ? {
992
+ rulePath: `pol-starter-${purpose} v${pd.version} \xB7 ${g} = Required (Platform default \u2014 set by the Platform Admin)`
993
+ } : null;
994
+ const req = required(g);
995
+ let allowed = true;
996
+ let reason = excluded !== null ? excluded.reason : "Allowed";
997
+ let path = excluded !== null ? excluded.rulePath : rulePath;
998
+ const floorItems = items.filter(underFloor);
999
+ const excludedItems = [];
1000
+ let excludedReason = null;
1001
+ const teamExcludedItems = [];
1002
+ let teamExcludedReason = null;
1003
+ const addExcluded = (rows, why) => {
1004
+ for (const r of rows)
1005
+ if (!floorItems.includes(r) && !excludedItems.includes(r))
1006
+ excludedItems.push(r);
1007
+ if (rows.length > 0 && excludedReason === null) excludedReason = why;
1008
+ };
1009
+ if (gov === null) {
1010
+ allowed = false;
1011
+ } else if ((!req || platformRequired !== null) && excludedAll) {
1012
+ allowed = false;
1013
+ } else if (excludedAll) {
1014
+ reason = "Allowed";
1015
+ path = rulePath;
1016
+ }
1017
+ if (allowed && !req && (categoriesOff.has(g) || categoryOffByDefault(g))) {
1018
+ allowed = false;
1019
+ reason = "Excluded by your account's Information Scope policy";
1020
+ 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)`;
1021
+ }
1022
+ if (allowed && !req && !inside && blockedSet.has(g)) {
1023
+ allowed = false;
1024
+ reason = "Blocked for this purpose by the Platform default \u2014 no account can share it under this purpose";
1025
+ path = `pol-starter-${purpose} v${pd?.version ?? 1} \xB7 ${g} = Blocked (Platform default \u2014 CVC-236 heightened protection | set by the Platform Admin)`;
1026
+ }
1027
+ addExcluded(
1028
+ g === systemCode ? [] : items.filter((r) => !underFloor(r) && heightenedOff(r, g)),
1029
+ "Heightened protection (CVC-236) \u2014 off in your account's Information Scope until the account turns it on"
1030
+ );
1031
+ if (allowed && !req && groupCeiling !== null && !scopeListCovers(scope, groupCeiling, g)) {
1032
+ allowed = false;
1033
+ reason = "Outside the payload for this purpose";
1034
+ path = ceilingPath;
1035
+ }
1036
+ if (allowed && !req && groupCeiling !== null && !scopeListStrictlyCovers(scope, groupCeiling, g)) {
1037
+ addExcluded(
1038
+ items.filter((r) => !scopeListCovers(scope, groupCeiling, g, r)),
1039
+ "Outside the payload for this purpose"
1040
+ );
1041
+ }
1042
+ if (allowed && !req && polScopeBinds && !scopeListCovers(scope, govList, g)) {
1043
+ allowed = false;
1044
+ reason = `Outside what the \u201C${govName}\u201D policy allows for this purpose`;
1045
+ path = `sharingPurposePolicies[${gov?.policy.id}].infoScope (policy \u201C${govName}\u201D \u2014 ${govNamed?.levelLabel})`;
1046
+ }
1047
+ if (allowed && !req && polScopeBinds && !scopeListStrictlyCovers(scope, govList, g)) {
1048
+ addExcluded(
1049
+ items.filter((r) => !scopeListCovers(scope, govList, g, r)),
1050
+ `Outside what the \u201C${govName}\u201D policy allows for this purpose`
1051
+ );
1052
+ }
1053
+ const govRows = polScopeBinds ? own2(govItems, g) : void 0;
1054
+ if (allowed && !req && isStringList2(govRows)) {
1055
+ const keep = new Set(govRows);
1056
+ addExcluded(
1057
+ items.filter(
1058
+ (r) => !keep.has(r) && !scope.ancestorsOf(r).some((a) => a !== g && keep.has(a))
1059
+ ),
1060
+ `Outside what the \u201C${govName}\u201D policy allows for this purpose`
1061
+ );
1062
+ }
1063
+ if (allowed && !req && tcScope !== null && !scopeListCovers(scope, tcScope, g)) {
1064
+ allowed = false;
1065
+ reason = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;
1066
+ path = `sharingPurposePolicies[${tc?.policy.id}].infoScope (policy \u201C${tcNamed?.name}\u201D \u2014 ${SHARE_LEVEL_LABEL.team}; a ceiling over \u201C${govName}\u201D)`;
1067
+ }
1068
+ if (allowed && !req && tc !== null) {
1069
+ const why = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;
1070
+ const outRows = /* @__PURE__ */ new Set();
1071
+ if (tcScope !== null && !scopeListStrictlyCovers(scope, tcScope, g)) {
1072
+ for (const r of items)
1073
+ if (!scopeListCovers(scope, tcScope, g, r)) outRows.add(r);
1074
+ }
1075
+ const tcRows = own2(tcItems, g);
1076
+ if (isStringList2(tcRows)) {
1077
+ const keep = new Set(tcRows);
1078
+ for (const r of items)
1079
+ if (!keep.has(r) && !scope.ancestorsOf(r).some((a) => a !== g && keep.has(a)))
1080
+ outRows.add(r);
1081
+ }
1082
+ for (const r of outRows)
1083
+ if (!floorItems.includes(r) && !excludedItems.includes(r))
1084
+ teamExcludedItems.push(r);
1085
+ if (teamExcludedItems.length > 0) teamExcludedReason = why;
1086
+ }
1087
+ if (allowed && (!req || platformRequired !== null) && leaves.length > 0) {
1088
+ const gone = new Set(
1089
+ [...floorItems, ...excludedItems, ...teamExcludedItems].filter(
1090
+ (r) => leaves.includes(r)
1091
+ )
1092
+ );
1093
+ if (gone.size >= leaves.length) {
1094
+ allowed = false;
1095
+ if (leaves.every((r) => floorItems.includes(r))) {
1096
+ reason = "Never shared \u2014 under the platform safety floor";
1097
+ path = "HTI_PLATFORM_SAFETY_FLOOR";
1098
+ } else if (leaves.some((r) => excludedItems.includes(r))) {
1099
+ reason = excludedReason ?? reason;
1100
+ } else {
1101
+ reason = teamExcludedReason ?? reason;
1102
+ }
1103
+ }
1104
+ }
1105
+ out[g] = {
1106
+ allowed,
1107
+ reason,
1108
+ rulePath: path,
1109
+ platformRequired,
1110
+ floorItems: uniq(floorItems),
1111
+ excludedItems: uniq(excludedItems),
1112
+ excludedReason,
1113
+ teamExcludedItems: uniq(teamExcludedItems),
1114
+ teamExcludedReason
1115
+ };
1116
+ if (allowed) allowedCategories.push(g);
1117
+ }
1118
+ return {
1119
+ allowed: !excludedAll,
1120
+ posture,
1121
+ postureSource,
1122
+ excluded,
1123
+ reportCarveOut,
1124
+ governing: govNamed,
1125
+ teamCeiling: tcNamed,
1126
+ inside,
1127
+ scope: out,
1128
+ allowedCategories,
1129
+ rulePath
1130
+ };
1131
+ }
521
1132
  // Annotate the CommonJS export names for ESM import in node:
522
1133
  0 && (module.exports = {
523
1134
  HTI_SHARE_PLATFORM_PURPOSE_ENABLED,
1135
+ HTI_SHARE_PLATFORM_REQUIRED_BY_PURPOSE,
524
1136
  HTI_SHARE_PLATFORM_STARTER,
525
1137
  HTI_SHARE_PLATFORM_STARTER_SOURCE,
526
1138
  INFORMATION_SCOPE_FIELD_HOME_ROWS,
1139
+ SHARE_LEVEL_LABEL,
1140
+ SHARE_PLATFORM_STATE_LABEL,
1141
+ SHARE_POSTURE_RANK,
1142
+ SHARE_REPORTING_PURPOSES,
527
1143
  SHARING_CEILING_DEFAULT_ROW_KEY,
528
1144
  SHARING_CEILING_EXTERNAL_ROW_KEY,
529
1145
  SHARING_CEILING_SCOPE_VERSION,
530
1146
  accountSharePurposePolicy,
1147
+ attachmentIndexFromPolicies,
531
1148
  ceilingCoverage,
1149
+ derivePlatformDefault,
532
1150
  effectiveCeiling,
533
1151
  hasOwnScopeContent,
534
1152
  intersectSharingCeilingLists,
535
1153
  isCeilingCoverageRow,
536
1154
  isPermittedByCeiling,
537
1155
  isSharingPurposeDisabled,
1156
+ liveCategories,
538
1157
  maskSelectionToCeiling,
1158
+ matchTeamRow,
1159
+ platformDefaultFor,
1160
+ resolveShare,
539
1161
  rowsExpandedByCeiling,
540
1162
  rowsOutsideCeiling,
541
1163
  rowsOverCeiling,
1164
+ scopeListCovers,
1165
+ scopeListStrictlyCovers,
542
1166
  scopeRowWithinCeiling,
543
1167
  shareDefaultScopeFor,
1168
+ shareRowCeiling,
544
1169
  sharingCeilingCellList,
545
1170
  sharingCeilingRowKey,
546
- sharingScopeEditsFromCells
1171
+ sharingScopeEditsFromCells,
1172
+ systemCategoryOf
547
1173
  });
548
1174
  //# sourceMappingURL=index.cjs.map