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