@htilabs/platform-common-models 0.59.0 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +90 -1
  2. package/dist/index.cjs +91 -13
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +91 -13
  5. package/dist/index.js.map +1 -1
  6. package/dist/org-directory/index.cjs +5 -4
  7. package/dist/org-directory/index.cjs.map +1 -1
  8. package/dist/org-directory/index.d.cts +15 -7
  9. package/dist/org-directory/index.d.ts +15 -7
  10. package/dist/org-directory/index.js +5 -4
  11. package/dist/org-directory/index.js.map +1 -1
  12. package/dist/points-of-contact/index.cjs +4 -3
  13. package/dist/points-of-contact/index.cjs.map +1 -1
  14. package/dist/points-of-contact/index.js +4 -3
  15. package/dist/points-of-contact/index.js.map +1 -1
  16. package/dist/schemas/index.cjs +10 -6
  17. package/dist/schemas/index.cjs.map +1 -1
  18. package/dist/schemas/index.d.cts +8 -4
  19. package/dist/schemas/index.d.ts +8 -4
  20. package/dist/schemas/index.js +10 -6
  21. package/dist/schemas/index.js.map +1 -1
  22. package/dist/sharing-ceiling/index.cjs +81 -7
  23. package/dist/sharing-ceiling/index.cjs.map +1 -1
  24. package/dist/sharing-ceiling/index.d.cts +64 -4
  25. package/dist/sharing-ceiling/index.d.ts +64 -4
  26. package/dist/sharing-ceiling/index.js +81 -7
  27. package/dist/sharing-ceiling/index.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/orgDirectory/__tests__/orgRecord.test.ts +6 -3
  30. package/src/orgDirectory/orgRecord.ts +14 -6
  31. package/src/orgDirectory/rules.ts +3 -2
  32. package/src/schemas/organization.ts +7 -4
  33. package/src/sharingCeiling/__tests__/resolveShare.purposeRule.test.ts +836 -0
  34. package/src/sharingCeiling/index.ts +4 -0
  35. package/src/sharingCeiling/resolve.ts +219 -15
@@ -882,8 +882,31 @@ function resolveShare(input) {
882
882
  };
883
883
  }
884
884
  }
885
+ let fork = null;
885
886
  if (gov === null && !inside && purposeKnown && recipientKey !== null) {
886
887
  gov = hit(cell(att.relationships, recipientKey), "relationship");
888
+ const rule = input.partnerPurposeRule;
889
+ const rulePosture2 = rule?.posture;
890
+ if (gov === null && recipient.kind === "partner" && // `__external__` stays scope-only (data.js L55333)
891
+ (rulePosture2 === "open" || rulePosture2 === "approval" || rulePosture2 === "blocked")) {
892
+ const partnerName = typeof rule?.partnerName === "string" && rule.partnerName !== "" ? rule.partnerName : recipientKey;
893
+ fork = {
894
+ policy: {
895
+ id: `pol-bp-${recipientKey}-${purpose}`,
896
+ name: `${purposeLabel} \u2014 ${partnerName} variant`,
897
+ purpose,
898
+ posture: rulePosture2,
899
+ infoScope: null,
900
+ cadences: null,
901
+ version: 1,
902
+ origin: { kind: "fork" },
903
+ edited: true
904
+ },
905
+ level: "relationship",
906
+ version: 1,
907
+ rulePath: `policies.partnerOverrides[${recipientKey}].byPurpose[${purpose}] (purpose-specific rule, reported as its fork)`
908
+ };
909
+ }
887
910
  if (gov === null)
888
911
  gov = hit(own2(att.agencyDefaults, purpose), "agency_default");
889
912
  if (gov === null && pd !== null) {
@@ -905,18 +928,36 @@ function resolveShare(input) {
905
928
  };
906
929
  }
907
930
  }
931
+ let defaultProjection = null;
932
+ let defaultItems = null;
933
+ if (fork !== null) {
934
+ if (gov !== null && gov.level === "agency_default" && gov.policy.edited === true) {
935
+ if (isStringList2(gov.policy.infoScope))
936
+ defaultProjection = [...gov.policy.infoScope];
937
+ const items = copyItems(gov.policy.infoScopeItems);
938
+ if (items !== null)
939
+ defaultItems = {
940
+ rows: items,
941
+ name: typeof gov.policy.name === "string" ? gov.policy.name : gov.policy.id
942
+ };
943
+ }
944
+ gov = fork;
945
+ }
946
+ const rulePosture = input.partnerPurposeRule?.posture;
947
+ const ruleAuthored = !inside && recipient.kind === "partner" && (rulePosture === "open" || rulePosture === "approval" || rulePosture === "blocked");
908
948
  let tc = null;
909
949
  if (teamId !== null && gov !== null) {
910
950
  const t = hit(cell(att.teams, teamId), "team");
911
951
  if (t !== null && t.policy.id !== gov.policy.id) tc = t;
912
952
  }
913
- const govNamed = gov === null ? null : named(gov);
953
+ const govNamed = gov === null ? null : fork !== null ? { ...named(gov), virtual: true } : named(gov);
914
954
  const tcNamed = tc === null ? null : named(tc);
915
955
  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)`;
916
- let posture = input.relationshipPosture === "approval" || input.relationshipPosture === "blocked" ? input.relationshipPosture : "open";
956
+ let posture = ruleAuthored && rulePosture !== void 0 ? rulePosture : input.relationshipPosture === "approval" || input.relationshipPosture === "blocked" ? input.relationshipPosture : "open";
917
957
  let postureSource = "relationship";
918
958
  let posturePol = null;
919
- if (govNamed?.posture && SHARE_POSTURE_RANK[govNamed.posture] > SHARE_POSTURE_RANK[posture]) {
959
+ if (fork === null && // data.js L55391: a virtual policy's posture is never applied
960
+ govNamed?.posture && SHARE_POSTURE_RANK[govNamed.posture] > SHARE_POSTURE_RANK[posture]) {
920
961
  posture = govNamed.posture;
921
962
  postureSource = "policy";
922
963
  posturePol = govNamed;
@@ -941,11 +982,22 @@ function resolveShare(input) {
941
982
  } else if (posture === "blocked") {
942
983
  const pol = posturePol;
943
984
  const path = pol === null ? "relationship posture = blocked" : `sharingPurposePolicies[${pol.id}].posture=blocked (policy \u201C${pol.name}\u201D \u2014 ${pol.levelLabel})`;
944
- if (report) {
985
+ const byRule = ruleAuthored && postureSource === "relationship";
986
+ if (report && byRule) {
987
+ reportCarveOut = {
988
+ note: "Partner is blocked for ordinary sharing \u2014 reachable for reports",
989
+ rulePath: `reports-never-blocked-at-partner-layer (Crysta ruling 2026-08-23; policies.partnerOverrides[${recipientKey}].byPurpose[${purpose}].sharingPosture=blocked does not bind a legal duty \u2014 who may send is a role/function question)`
990
+ };
991
+ } else if (report) {
945
992
  reportCarveOut = {
946
993
  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`,
947
994
  rulePath: path
948
995
  };
996
+ } else if (byRule) {
997
+ excluded = {
998
+ reason: "Partner is blocked for this purpose by your account's sharing policy",
999
+ rulePath: `policies.partnerOverrides[${recipientKey}].byPurpose[${purpose}].sharingPosture=blocked (Share Partners \u2014 purpose-specific rule)`
1000
+ };
949
1001
  } else {
950
1002
  excluded = {
951
1003
  reason: pol === null ? "Blocked for this purpose by the relationship" : `Blocked for this purpose by your account's \u201C${pol.name}\u201D policy`,
@@ -958,9 +1010,11 @@ function resolveShare(input) {
958
1010
  const govList = govNamed?.infoScope ?? null;
959
1011
  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);
960
1012
  const legacy = legacyCeilingList(input.legacyCeiling);
961
- const ceilingIsStarter = legacy === null;
962
- let groupCeiling = legacy ?? pdRaw;
963
- 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)`;
1013
+ const projectionPath = `policies.sharingScopeEdits[__default__][${purpose}] (projected from your account default policy)`;
1014
+ const projOverLegacy = legacy !== null ? defaultProjection : null;
1015
+ const ceilingIsStarter = legacy === null && defaultProjection === null;
1016
+ let groupCeiling = legacy ?? defaultProjection ?? pdRaw;
1017
+ let ceilingPath = legacy !== null ? "sharingScopeEdits (the account's partner / default rule \u2014 the legacy cell chain)" : defaultProjection !== null ? projectionPath : pd === null ? "no Platform default" : `pol-starter-${purpose} v${pd.version} (Platform default \u2014 the starting scope for this purpose)`;
964
1018
  if (ceilingIsStarter && polScopeBinds) {
965
1019
  groupCeiling = null;
966
1020
  ceilingPath = "";
@@ -1062,6 +1116,17 @@ function resolveShare(input) {
1062
1116
  `Outside what the \u201C${govName}\u201D policy allows for this purpose`
1063
1117
  );
1064
1118
  }
1119
+ if (allowed && !req && projOverLegacy !== null && !scopeListCovers(scope, projOverLegacy, g)) {
1120
+ allowed = false;
1121
+ reason = "Outside the payload for this purpose";
1122
+ path = projectionPath;
1123
+ }
1124
+ if (allowed && !req && projOverLegacy !== null && !scopeListStrictlyCovers(scope, projOverLegacy, g)) {
1125
+ addExcluded(
1126
+ outside((r) => scopeListCovers(scope, projOverLegacy, g, r)),
1127
+ "Outside the payload for this purpose"
1128
+ );
1129
+ }
1065
1130
  const govRows = polScopeBinds ? own2(govItems, g) : void 0;
1066
1131
  if (allowed && !req && isStringList2(govRows)) {
1067
1132
  const keep = new Set(govRows);
@@ -1071,6 +1136,15 @@ function resolveShare(input) {
1071
1136
  `Outside what the \u201C${govName}\u201D policy allows for this purpose`
1072
1137
  );
1073
1138
  }
1139
+ const defRows = defaultItems === null ? void 0 : own2(defaultItems.rows, g);
1140
+ if (allowed && !req && isStringList2(defRows)) {
1141
+ const keep = new Set(defRows);
1142
+ const kept = (r) => keep.has(r) || scope.ancestorsOf(r).some((a) => a !== g && keep.has(a));
1143
+ addExcluded(
1144
+ outside(kept),
1145
+ `Outside what the \u201C${defaultItems?.name ?? ""}\u201D policy allows for this purpose`
1146
+ );
1147
+ }
1074
1148
  if (allowed && !req && tcScope !== null && !scopeListCovers(scope, tcScope, g)) {
1075
1149
  allowed = false;
1076
1150
  reason = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;