@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
@@ -1,4 +1,4 @@
1
- import { F as Form, l as buildFormSchema, h as Section, q as buildSectionSchema, Q as Question, o as buildQuestionSchema, f as ScoringRule, p as buildScoringRuleSchema, P as PlatformFunction, m as buildPlatformFunctionSchema, d as PlatformRole, n as buildPlatformRoleSchema, b as CvcRegistry, k as buildCvcRegistrySchema, a as CvcEntry, j as buildCvcEntrySchema } from './cvcEntry-D787utvP.cjs';
1
+ import { F as Form, l as buildFormSchema, h as Section, q as buildSectionSchema, Q as Question, o as buildQuestionSchema, f as ScoringRule, p as buildScoringRuleSchema, P as PlatformFunction, m as buildPlatformFunctionSchema, d as PlatformRole, n as buildPlatformRoleSchema, b as CvcRegistry, k as buildCvcRegistrySchema, a as CvcEntry, j as buildCvcEntrySchema } from './cvcEntry-DAuhe0cd.cjs';
2
2
  import * as mongoose from 'mongoose';
3
3
  import { HydratedDocument, Connection, Model } from 'mongoose';
4
4
 
@@ -1,4 +1,4 @@
1
- import { F as Form, l as buildFormSchema, h as Section, q as buildSectionSchema, Q as Question, o as buildQuestionSchema, f as ScoringRule, p as buildScoringRuleSchema, P as PlatformFunction, m as buildPlatformFunctionSchema, d as PlatformRole, n as buildPlatformRoleSchema, b as CvcRegistry, k as buildCvcRegistrySchema, a as CvcEntry, j as buildCvcEntrySchema } from './cvcEntry-D787utvP.js';
1
+ import { F as Form, l as buildFormSchema, h as Section, q as buildSectionSchema, Q as Question, o as buildQuestionSchema, f as ScoringRule, p as buildScoringRuleSchema, P as PlatformFunction, m as buildPlatformFunctionSchema, d as PlatformRole, n as buildPlatformRoleSchema, b as CvcRegistry, k as buildCvcRegistrySchema, a as CvcEntry, j as buildCvcEntrySchema } from './cvcEntry-DAuhe0cd.js';
2
2
  import * as mongoose from 'mongoose';
3
3
  import { HydratedDocument, Connection, Model } from 'mongoose';
4
4
 
package/dist/index.cjs CHANGED
@@ -611,6 +611,7 @@ __export(src_exports, {
611
611
  WHY_NOT_REPORTING_AXES: () => WHY_NOT_REPORTING_AXES,
612
612
  WhyNotKeys: () => WhyNotKeys,
613
613
  accommodationTypeSot: () => accommodationType_v1_0_0_default,
614
+ accountAppGrant: () => accountAppGrant,
614
615
  accountSharePurposePolicy: () => accountSharePurposePolicy,
615
616
  actionStepCompletionStatusSot: () => actionStepCompletionStatus_v1_0_0_default,
616
617
  actionStepTypeSot: () => actionStepType_v1_0_0_default,
@@ -979,6 +980,8 @@ __export(src_exports, {
979
980
  scoringRuleSchemaDefinition: () => scoringRuleSchemaDefinition,
980
981
  scoringRuleSchemaOptions: () => scoringRuleSchemaOptions,
981
982
  scoringThresholdSchema: () => scoringThresholdSchema,
983
+ seatAppAccess: () => seatAppAccess,
984
+ seatTeamApps: () => seatTeamApps,
982
985
  sectionModel: () => sectionModel_exports,
983
986
  sectionQuestionRefSchema: () => sectionQuestionRefSchema,
984
987
  sectionSchemaDefinition: () => sectionSchemaDefinition,
@@ -27754,8 +27757,8 @@ function governingRowOf(rows) {
27754
27757
  if (rows.length === 1 && only !== void 0) return { row: only };
27755
27758
  const family = idText(rows[0]?.familyId);
27756
27759
  const versions = rows.map((r) => positiveIntOrNull(r.version));
27757
- const ordered = family !== null && rows.every((r) => idText(r.familyId) === family) && versions.every((v) => typeof v === "number") && new Set(versions).size === versions.length;
27758
- if (!ordered) {
27760
+ const ordered2 = family !== null && rows.every((r) => idText(r.familyId) === family) && versions.every((v) => typeof v === "number") && new Set(versions).size === versions.length;
27761
+ if (!ordered2) {
27759
27762
  return unavailableViewingPolicy("ambiguous_rows", policyIdOf(rows[0] ?? {}));
27760
27763
  }
27761
27764
  let best = rows[0];
@@ -28013,6 +28016,91 @@ function viewingComponentOpen(access, homeRow, scope) {
28013
28016
  return scope.isCovered(access.visibleScope, homeRow);
28014
28017
  }
28015
28018
 
28019
+ // src/authz/seatAppAccess.ts
28020
+ var UNIVERSAL = new Set(UNIVERSAL_APP_IDS);
28021
+ var TRAIL = "trail";
28022
+ function toolCode(id) {
28023
+ return id.toUpperCase();
28024
+ }
28025
+ function asWritten(v) {
28026
+ if (typeof v === "string") return v;
28027
+ try {
28028
+ const json = JSON.stringify(v);
28029
+ return json === void 0 ? String(v) : json;
28030
+ } catch {
28031
+ return String(v);
28032
+ }
28033
+ }
28034
+ function listOf(value, unrecognized) {
28035
+ if (value === null || value === void 0) return [];
28036
+ if (typeof value === "string") return [value];
28037
+ if (Array.isArray(value)) return value;
28038
+ unrecognized.push(asWritten(value));
28039
+ return [];
28040
+ }
28041
+ function readApps(value, unrecognized) {
28042
+ const out = /* @__PURE__ */ new Set();
28043
+ for (const v of listOf(value, unrecognized)) {
28044
+ const app = platformAppById(v);
28045
+ if (app) out.add(app.id);
28046
+ else unrecognized.push(asWritten(v));
28047
+ }
28048
+ return out;
28049
+ }
28050
+ function ordered(ids) {
28051
+ return PLATFORM_APP_IDS.filter((id) => ids.has(id)).map(toolCode);
28052
+ }
28053
+ function readGrant(value, unrecognized) {
28054
+ if (value === null || value === void 0) return null;
28055
+ return readApps(value, unrecognized);
28056
+ }
28057
+ function accountAppGrant(account) {
28058
+ if (!account || typeof account !== "object") return null;
28059
+ const grant = account.apps_subscribed;
28060
+ return grant === null || grant === void 0 ? null : grant;
28061
+ }
28062
+ function teamSide(teams, accountGrant, accountPreLaunch) {
28063
+ const unrecognized = [];
28064
+ const grant = readGrant(accountGrant, unrecognized);
28065
+ const union = /* @__PURE__ */ new Set();
28066
+ for (const team of Array.isArray(teams) ? teams : []) {
28067
+ if (!team || typeof team !== "object") continue;
28068
+ const t = team;
28069
+ if (t.active === false) continue;
28070
+ for (const id of readApps(t.apps, unrecognized)) union.add(id);
28071
+ }
28072
+ const granted = /* @__PURE__ */ new Set();
28073
+ if (accountPreLaunch === true) {
28074
+ granted.add(TRAIL);
28075
+ return { granted, union, grant, unrecognized };
28076
+ }
28077
+ for (const id of UNIVERSAL) granted.add(id);
28078
+ for (const id of CASEWORK_APP_IDS) {
28079
+ if (union.has(id) && (grant === null || grant.has(id))) granted.add(id);
28080
+ }
28081
+ return { granted, union, grant, unrecognized };
28082
+ }
28083
+ function seatTeamApps(input) {
28084
+ return ordered(teamSide(input.teams, input.accountGrant, input.accountPreLaunch).granted);
28085
+ }
28086
+ function seatAppAccess(input) {
28087
+ const side = teamSide(input.teams, input.accountGrant, input.accountPreLaunch);
28088
+ const app = platformAppById(input.app);
28089
+ const teamAllows = app !== null && side.granted.has(app.id);
28090
+ const auth0Allows = input.auth0Allows === true;
28091
+ const via = auth0Allows && teamAllows ? "both" : auth0Allows ? "auth0" : teamAllows ? "teams" : "none";
28092
+ return {
28093
+ allowed: auth0Allows || teamAllows,
28094
+ via,
28095
+ app: app ? toolCode(app.id) : null,
28096
+ teamAllows,
28097
+ teamApps: ordered(side.granted),
28098
+ teamUnion: ordered(side.union),
28099
+ accountGrant: side.grant ? ordered(side.grant) : null,
28100
+ unrecognized: side.unrecognized
28101
+ };
28102
+ }
28103
+
28016
28104
  // src/generated/sharingPlatformStarter.ts
28017
28105
  var SHARING_PLATFORM_STARTER_SOURCE = {
28018
28106
  "monolith": {
@@ -28286,10 +28374,11 @@ function treeFacts(scope) {
28286
28374
  const coverageChildren = memoize(
28287
28375
  (code) => Object.freeze(scope.childrenOf(code).filter(isCoverageRow))
28288
28376
  );
28377
+ const kindHomed = kindHomedRows(scope);
28289
28378
  const hasOwnContent = memoize((code) => {
28290
28379
  const row = scope.row(code);
28291
28380
  if (row === void 0) return false;
28292
- const homed = INFORMATION_SCOPE_FIELD_HOME_ROWS.has(code) || row.kindRow !== void 0 && INFORMATION_SCOPE_FIELD_HOME_ROWS.has(row.kindRow);
28381
+ const homed = INFORMATION_SCOPE_FIELD_HOME_ROWS.has(code) || kindHomed.has(code);
28293
28382
  if (!homed) return false;
28294
28383
  return !scope.childrenOf(code).some((c) => scope.row(c)?.rowType === "category_rest" && isLive(c));
28295
28384
  });
@@ -28304,6 +28393,28 @@ function treeFacts(scope) {
28304
28393
  factsCache.set(scope, facts);
28305
28394
  return facts;
28306
28395
  }
28396
+ function kindHomedRows(scope) {
28397
+ const perKind = /* @__PURE__ */ new Map();
28398
+ const kinds = /* @__PURE__ */ new Map();
28399
+ for (const r of scope.rows) {
28400
+ if (r.status === "retired" || r.kindBranch === null) continue;
28401
+ if (r.rowType === "person_type") kinds.set(r.kindBranch, r.scopeCode);
28402
+ else if (r.kindRow !== void 0) perKind.set(`${r.kindBranch}\0${r.kindRow}`, r.scopeCode);
28403
+ }
28404
+ const out = /* @__PURE__ */ new Set();
28405
+ for (const home of INFORMATION_SCOPE_FIELD_HOME_ROWS) {
28406
+ const row = scope.row(home);
28407
+ if (row === void 0 || row.specialDataType === "criminal_intelligence") continue;
28408
+ const chain = scope.ancestorsOf(home);
28409
+ if (scope.row(chain[chain.length - 1])?.rowType !== "branch") continue;
28410
+ for (const [kind, root] of kinds) {
28411
+ if (chain.includes(root)) continue;
28412
+ const hit = chain.map((c) => perKind.get(`${kind}\0${c}`)).find((c) => c !== void 0);
28413
+ if (hit !== void 0) out.add(hit);
28414
+ }
28415
+ }
28416
+ return out;
28417
+ }
28307
28418
  function asCeilingSet(allowed) {
28308
28419
  if (allowed === null) return null;
28309
28420
  if (allowed instanceof Set) return allowed;
@@ -28328,6 +28439,7 @@ function ceilingCoverage(scope, allowed) {
28328
28439
  let out;
28329
28440
  if (!facts.isLive(code)) out = false;
28330
28441
  else if (set === null) out = true;
28442
+ else if (facts.underFloor(code)) out = set.has(code);
28331
28443
  else if (scope.ancestorsOf(code).some((c) => set.has(c))) out = true;
28332
28444
  else if (facts.hasOwnContent(code)) out = false;
28333
28445
  else {
@@ -28425,6 +28537,10 @@ function maskSelectionToCeiling(scope, selection, allowed) {
28425
28537
  for (const child of scope.childrenOf(code)) if (!sel.includes(child)) sel.push(child);
28426
28538
  }
28427
28539
  for (const code of outside) sel = subtractRow(scope, sel, code);
28540
+ if (asCeilingSet(allowed) !== null) {
28541
+ const within = ceilingCoverage(scope, allowed);
28542
+ sel = sel.filter((c) => !facts.underFloor(c) || within(c));
28543
+ }
28428
28544
  return withSystemInfo(sel.filter((c) => facts.isLive(c)));
28429
28545
  }
28430
28546
  function isPermittedByCeiling(scope, ceiling, code) {
@@ -28706,7 +28822,8 @@ function shareRowCeiling(resolution, scope) {
28706
28822
  ...e.teamExcludedItems,
28707
28823
  ...e.floorItems
28708
28824
  ]);
28709
- if (withheld.size === 0) {
28825
+ const onlyFloorWithheld = [...withheld].every((r) => e.floorItems.includes(r));
28826
+ if (withheld.size === 0 || onlyFloorWithheld && hasOwnScopeContent(scope, g)) {
28710
28827
  out.push(g);
28711
28828
  continue;
28712
28829
  }
@@ -29098,7 +29215,8 @@ function resolveShare(input) {
29098
29215
  teamExcludedItems.push(r);
29099
29216
  if (teamExcludedItems.length > 0) teamExcludedReason = why;
29100
29217
  }
29101
- if (allowed && (!req || platformRequired !== null) && leaves.length > 0) {
29218
+ const floorOnlyOwnContent = leaves.length > 0 && leaves.every((r) => floorItems.includes(r)) && hasOwnScopeContent(scope, g);
29219
+ if (allowed && (!req || platformRequired !== null) && leaves.length > 0 && !floorOnlyOwnContent) {
29102
29220
  const gone = new Set(
29103
29221
  [...floorItems, ...excludedItems, ...teamExcludedItems].filter(
29104
29222
  (r) => leaves.includes(r)
@@ -77381,6 +77499,7 @@ var CVC_197_VALUES = selectableCodes(
77381
77499
  WHY_NOT_REPORTING_AXES,
77382
77500
  WhyNotKeys,
77383
77501
  accommodationTypeSot,
77502
+ accountAppGrant,
77384
77503
  accountSharePurposePolicy,
77385
77504
  actionStepCompletionStatusSot,
77386
77505
  actionStepTypeSot,
@@ -77749,6 +77868,8 @@ var CVC_197_VALUES = selectableCodes(
77749
77868
  scoringRuleSchemaDefinition,
77750
77869
  scoringRuleSchemaOptions,
77751
77870
  scoringThresholdSchema,
77871
+ seatAppAccess,
77872
+ seatTeamApps,
77752
77873
  sectionModel,
77753
77874
  sectionQuestionRefSchema,
77754
77875
  sectionSchemaDefinition,