@htilabs/platform-common-models 0.79.0 → 0.81.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 (40) hide show
  1. package/README.md +55 -0
  2. package/dist/authz/index.cjs +154 -2
  3. package/dist/authz/index.cjs.map +1 -1
  4. package/dist/authz/index.d.cts +174 -2
  5. package/dist/authz/index.d.ts +174 -2
  6. package/dist/authz/index.js +151 -2
  7. package/dist/authz/index.js.map +1 -1
  8. package/dist/{index-XWSYon40.d.cts → index-1pWiqEBC.d.cts} +1 -1
  9. package/dist/{index-Bh1zO_Vu.d.ts → index-uz57Fic9.d.ts} +1 -1
  10. package/dist/index.cjs +126 -5
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +4 -4
  13. package/dist/index.d.ts +4 -4
  14. package/dist/index.js +123 -5
  15. package/dist/index.js.map +1 -1
  16. package/dist/models/index.d.cts +2 -2
  17. package/dist/models/index.d.ts +2 -2
  18. package/dist/schemas/index.d.cts +25 -25
  19. package/dist/schemas/index.d.ts +25 -25
  20. package/dist/sharing-ceiling/index.cjs +33 -3
  21. package/dist/sharing-ceiling/index.cjs.map +1 -1
  22. package/dist/sharing-ceiling/index.d.cts +11 -7
  23. package/dist/sharing-ceiling/index.d.ts +11 -7
  24. package/dist/sharing-ceiling/index.js +33 -3
  25. package/dist/sharing-ceiling/index.js.map +1 -1
  26. package/dist/validation/index.d.cts +1 -1
  27. package/dist/validation/index.d.ts +1 -1
  28. package/package.json +2 -1
  29. package/src/__tests__/authz-resolve.test.ts +3 -0
  30. package/src/__tests__/authz-seat-app-access.test.ts +304 -0
  31. package/src/authz/index.ts +1 -0
  32. package/src/authz/seatAppAccess.ts +304 -0
  33. package/src/sharingCeiling/__tests__/fixtures_starterVerdicts.json +1727 -0
  34. package/src/sharingCeiling/__tests__/personContactRows.test.ts +185 -0
  35. package/src/sharingCeiling/coverage.ts +55 -6
  36. package/src/sharingCeiling/resolve.ts +31 -8
  37. package/dist/{agency-CnVTwLeV.d.ts → agency-BHv54o79.d.ts} +4 -4
  38. package/dist/{agency-8ufZJJDH.d.cts → agency-Djp57S71.d.cts} +4 -4
  39. package/dist/{cvcEntry-D787utvP.d.cts → cvcEntry-DAuhe0cd.d.cts} +8 -8
  40. package/dist/{cvcEntry-D787utvP.d.ts → cvcEntry-DAuhe0cd.d.ts} +8 -8
@@ -238,8 +238,9 @@ declare function effectiveCeiling(rowKey: string, purpose: string, inputs: Effec
238
238
  *
239
239
  * OWN CONTENT (ruling, strict rule 2): a row with fields HOMED directly on it
240
240
  * (canon's field placements, {@link INFORMATION_SCOPE_FIELD_HOME_ROWS}; a
241
- * per-kind row reads its `kindRow`, since rule 1 routes another person's
242
- * record there) and NO rest row is within ONLY when it or an ancestor is
241
+ * per-kind row also holds every client home rule 1 routes to it — the deepest
242
+ * per-kind row whose `kindRow` is the home or an ancestor of it, so
243
+ * `contact_info` lands on `offenders.contact`) and NO rest row is within ONLY when it or an ancestor is
243
244
  * listed — listing its children does not carry its own fields. Examples:
244
245
  * `instruments` (`capture.assessment*`) and `commercial_activity`. A row with
245
246
  * a rest row (`identifying` + `identifying.other`) keeps rule 2: its own
@@ -248,7 +249,9 @@ declare function effectiveCeiling(rowKey: string, purpose: string, inputs: Effec
248
249
  * A COVERAGE child is live, not under the platform safety floor (never
249
250
  * shared) and not System metadata (always rides). A row is LIVE when it and
250
251
  * every row on its ancestor path are non-retired; a code outside the tree, or
251
- * not live, is never within.
252
+ * not live, is never within. Under a bound ceiling a row under the platform
253
+ * floor is within only when the list names it itself, never through a listed
254
+ * ancestor.
252
255
  *
253
256
  * Deliberately NOT the resolver's `isCovered`, under which a listed rest row
254
257
  * (`identifying.other`) would cover its whole category.
@@ -829,10 +832,11 @@ declare function platformDefaultFor(scope: SharingCeilingScope, purpose: string,
829
832
  /**
830
833
  * The ROW-grain ceiling one resolution amounts to — the list the item-grain readers take
831
834
  * (`maskSelectionToCeiling` for the composer, `rowsOverCeiling` for the send door): each
832
- * allowed category by its own code when no row of it is withheld, else its live rows minus
833
- * the withheld ones (the governing list's, the account's heightened rows, the field-group
834
- * limits, the team's). Rows under the platform floor are never listed (the readers never let
835
- * them through). `[]` for an excluded share — only System metadata rides.
835
+ * allowed category by its own code when no row of it is withheld (or, for a category with
836
+ * fields of its own, when only floor rows are), else its live rows minus the withheld ones
837
+ * (the governing list's, the account's heightened rows, the field-group limits, the team's).
838
+ * Rows under the platform floor are never listed, and never leave on a listed ancestor (the
839
+ * readers never let them through). `[]` for an excluded share — only System metadata rides.
836
840
  */
837
841
  declare function shareRowCeiling(resolution: Pick<ShareResolution, "allowed" | "scope" | "allowedCategories">, scope: SharingCeilingScope): string[];
838
842
  /**
@@ -238,8 +238,9 @@ declare function effectiveCeiling(rowKey: string, purpose: string, inputs: Effec
238
238
  *
239
239
  * OWN CONTENT (ruling, strict rule 2): a row with fields HOMED directly on it
240
240
  * (canon's field placements, {@link INFORMATION_SCOPE_FIELD_HOME_ROWS}; a
241
- * per-kind row reads its `kindRow`, since rule 1 routes another person's
242
- * record there) and NO rest row is within ONLY when it or an ancestor is
241
+ * per-kind row also holds every client home rule 1 routes to it — the deepest
242
+ * per-kind row whose `kindRow` is the home or an ancestor of it, so
243
+ * `contact_info` lands on `offenders.contact`) and NO rest row is within ONLY when it or an ancestor is
243
244
  * listed — listing its children does not carry its own fields. Examples:
244
245
  * `instruments` (`capture.assessment*`) and `commercial_activity`. A row with
245
246
  * a rest row (`identifying` + `identifying.other`) keeps rule 2: its own
@@ -248,7 +249,9 @@ declare function effectiveCeiling(rowKey: string, purpose: string, inputs: Effec
248
249
  * A COVERAGE child is live, not under the platform safety floor (never
249
250
  * shared) and not System metadata (always rides). A row is LIVE when it and
250
251
  * every row on its ancestor path are non-retired; a code outside the tree, or
251
- * not live, is never within.
252
+ * not live, is never within. Under a bound ceiling a row under the platform
253
+ * floor is within only when the list names it itself, never through a listed
254
+ * ancestor.
252
255
  *
253
256
  * Deliberately NOT the resolver's `isCovered`, under which a listed rest row
254
257
  * (`identifying.other`) would cover its whole category.
@@ -829,10 +832,11 @@ declare function platformDefaultFor(scope: SharingCeilingScope, purpose: string,
829
832
  /**
830
833
  * The ROW-grain ceiling one resolution amounts to — the list the item-grain readers take
831
834
  * (`maskSelectionToCeiling` for the composer, `rowsOverCeiling` for the send door): each
832
- * allowed category by its own code when no row of it is withheld, else its live rows minus
833
- * the withheld ones (the governing list's, the account's heightened rows, the field-group
834
- * limits, the team's). Rows under the platform floor are never listed (the readers never let
835
- * them through). `[]` for an excluded share — only System metadata rides.
835
+ * allowed category by its own code when no row of it is withheld (or, for a category with
836
+ * fields of its own, when only floor rows are), else its live rows minus the withheld ones
837
+ * (the governing list's, the account's heightened rows, the field-group limits, the team's).
838
+ * Rows under the platform floor are never listed, and never leave on a listed ancestor (the
839
+ * readers never let them through). `[]` for an excluded share — only System metadata rides.
836
840
  */
837
841
  declare function shareRowCeiling(resolution: Pick<ShareResolution, "allowed" | "scope" | "allowedCategories">, scope: SharingCeilingScope): string[];
838
842
  /**
@@ -285,10 +285,11 @@ function treeFacts(scope) {
285
285
  const coverageChildren = memoize(
286
286
  (code) => Object.freeze(scope.childrenOf(code).filter(isCoverageRow))
287
287
  );
288
+ const kindHomed = kindHomedRows(scope);
288
289
  const hasOwnContent = memoize((code) => {
289
290
  const row = scope.row(code);
290
291
  if (row === void 0) return false;
291
- const homed = INFORMATION_SCOPE_FIELD_HOME_ROWS.has(code) || row.kindRow !== void 0 && INFORMATION_SCOPE_FIELD_HOME_ROWS.has(row.kindRow);
292
+ const homed = INFORMATION_SCOPE_FIELD_HOME_ROWS.has(code) || kindHomed.has(code);
292
293
  if (!homed) return false;
293
294
  return !scope.childrenOf(code).some((c) => scope.row(c)?.rowType === "category_rest" && isLive(c));
294
295
  });
@@ -303,6 +304,28 @@ function treeFacts(scope) {
303
304
  factsCache.set(scope, facts);
304
305
  return facts;
305
306
  }
307
+ function kindHomedRows(scope) {
308
+ const perKind = /* @__PURE__ */ new Map();
309
+ const kinds = /* @__PURE__ */ new Map();
310
+ for (const r of scope.rows) {
311
+ if (r.status === "retired" || r.kindBranch === null) continue;
312
+ if (r.rowType === "person_type") kinds.set(r.kindBranch, r.scopeCode);
313
+ else if (r.kindRow !== void 0) perKind.set(`${r.kindBranch}\0${r.kindRow}`, r.scopeCode);
314
+ }
315
+ const out = /* @__PURE__ */ new Set();
316
+ for (const home of INFORMATION_SCOPE_FIELD_HOME_ROWS) {
317
+ const row = scope.row(home);
318
+ if (row === void 0 || row.specialDataType === "criminal_intelligence") continue;
319
+ const chain = scope.ancestorsOf(home);
320
+ if (scope.row(chain[chain.length - 1])?.rowType !== "branch") continue;
321
+ for (const [kind, root] of kinds) {
322
+ if (chain.includes(root)) continue;
323
+ const hit = chain.map((c) => perKind.get(`${kind}\0${c}`)).find((c) => c !== void 0);
324
+ if (hit !== void 0) out.add(hit);
325
+ }
326
+ }
327
+ return out;
328
+ }
306
329
  function asCeilingSet(allowed) {
307
330
  if (allowed === null) return null;
308
331
  if (allowed instanceof Set) return allowed;
@@ -327,6 +350,7 @@ function ceilingCoverage(scope, allowed) {
327
350
  let out;
328
351
  if (!facts.isLive(code)) out = false;
329
352
  else if (set === null) out = true;
353
+ else if (facts.underFloor(code)) out = set.has(code);
330
354
  else if (scope.ancestorsOf(code).some((c) => set.has(c))) out = true;
331
355
  else if (facts.hasOwnContent(code)) out = false;
332
356
  else {
@@ -424,6 +448,10 @@ function maskSelectionToCeiling(scope, selection, allowed) {
424
448
  for (const child of scope.childrenOf(code)) if (!sel.includes(child)) sel.push(child);
425
449
  }
426
450
  for (const code of outside) sel = subtractRow(scope, sel, code);
451
+ if (asCeilingSet(allowed) !== null) {
452
+ const within = ceilingCoverage(scope, allowed);
453
+ sel = sel.filter((c) => !facts.underFloor(c) || within(c));
454
+ }
427
455
  return withSystemInfo(sel.filter((c) => facts.isLive(c)));
428
456
  }
429
457
  function isPermittedByCeiling(scope, ceiling, code) {
@@ -705,7 +733,8 @@ function shareRowCeiling(resolution, scope) {
705
733
  ...e.teamExcludedItems,
706
734
  ...e.floorItems
707
735
  ]);
708
- if (withheld.size === 0) {
736
+ const onlyFloorWithheld = [...withheld].every((r) => e.floorItems.includes(r));
737
+ if (withheld.size === 0 || onlyFloorWithheld && hasOwnScopeContent(scope, g)) {
709
738
  out.push(g);
710
739
  continue;
711
740
  }
@@ -1097,7 +1126,8 @@ function resolveShare(input) {
1097
1126
  teamExcludedItems.push(r);
1098
1127
  if (teamExcludedItems.length > 0) teamExcludedReason = why;
1099
1128
  }
1100
- if (allowed && (!req || platformRequired !== null) && leaves.length > 0) {
1129
+ const floorOnlyOwnContent = leaves.length > 0 && leaves.every((r) => floorItems.includes(r)) && hasOwnScopeContent(scope, g);
1130
+ if (allowed && (!req || platformRequired !== null) && leaves.length > 0 && !floorOnlyOwnContent) {
1101
1131
  const gone = new Set(
1102
1132
  [...floorItems, ...excludedItems, ...teamExcludedItems].filter(
1103
1133
  (r) => leaves.includes(r)