@htilabs/platform-common-models 0.55.0 → 0.56.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.
package/dist/index.cjs CHANGED
@@ -546,6 +546,8 @@ __export(src_exports, {
546
546
  VALID_RECORD_STATES: () => VALID_RECORD_STATES,
547
547
  VICTIM_SERVING_ORG_TYPE_KEYS: () => VICTIM_SERVING_ORG_TYPE_KEYS,
548
548
  VIEWING_LEVEL_FUNCTIONS: () => VIEWING_LEVEL_FUNCTIONS,
549
+ VIEWING_POLICY_SPECIES: () => VIEWING_POLICY_SPECIES,
550
+ VIEWING_POLICY_VOCABULARIES: () => VIEWING_POLICY_VOCABULARIES,
549
551
  VSP_TWO_STEP_ISSUE: () => VSP_TWO_STEP_ISSUE,
550
552
  VehicleBodyTypeKeys: () => VehicleBodyTypeKeys,
551
553
  VehicleColorKeys: () => VehicleColorKeys,
@@ -602,6 +604,9 @@ __export(src_exports, {
602
604
  carCorrectionReasonSot: () => carCorrectionReason_v2_1_0_default,
603
605
  cascadeExclusions: () => cascadeExclusions,
604
606
  caseShareStateSot: () => caseShareState_v1_2_0_default,
607
+ caseSurfacesAsStub: () => caseSurfacesAsStub,
608
+ caseSurfacesOn: () => caseSurfacesOn,
609
+ caseViewingAccess: () => caseViewingAccess,
605
610
  ceilingCoverage: () => ceilingCoverage,
606
611
  checkInActivitySot: () => checkInActivity_v1_0_0_default,
607
612
  checkInPhaseSot: () => checkInPhase_v1_1_0_default,
@@ -820,6 +825,7 @@ __export(src_exports, {
820
825
  radiusBucketSot: () => radiusBucket_v1_0_0_default,
821
826
  recencyBandSot: () => recencyBand_v1_0_0_default,
822
827
  recordRemovalReasonSot: () => recordRemovalReason_v1_0_0_default,
828
+ recordViewing: () => recordViewing,
823
829
  referenceLinkTypeSot: () => referenceLinkType_v1_0_0_default,
824
830
  referralEntityCategorySot: () => referralEntityCategory_v1_2_0_default,
825
831
  referralOriginSot: () => referralOrigin_v1_0_0_default,
@@ -838,6 +844,7 @@ __export(src_exports, {
838
844
  resolveReferralEntityKeyFromLegacyNumeric: () => resolveReferralEntityKeyFromLegacyNumeric,
839
845
  resolveRegistryWithInheritance: () => resolveRegistryWithInheritance,
840
846
  resolveShare: () => resolveShare,
847
+ resolveViewingPolicy: () => resolveViewingPolicy,
841
848
  returnedToAbuserStatusSot: () => returnedToAbuserStatus_v1_0_0_default,
842
849
  riskCategorySot: () => riskCategory_v1_0_0_default,
843
850
  riskIdentificationMilestoneSot: () => riskIdentificationMilestone_v1_0_0_default,
@@ -916,11 +923,13 @@ __export(src_exports, {
916
923
  supportTopicSot: () => supportTopic_v1_0_0_default,
917
924
  systemCategoryOf: () => systemCategoryOf,
918
925
  teamDirectorySchemaDefinition: () => teamDirectorySchemaDefinition,
926
+ teamViewingLevelFromPolicy: () => teamViewingLevelFromPolicy,
919
927
  threadStatusSot: () => threadStatus_v1_0_0_default,
920
928
  threadTypeSot: () => threadType_v1_0_0_default,
921
929
  timeScopeSot: () => timeScope_v1_0_0_default,
922
930
  traffickingRelevantRoleSot: () => traffickingRelevantRole_v1_0_0_default,
923
931
  tribesSot: () => tribes_v1_0_0_default,
932
+ unavailableViewingPolicy: () => unavailableViewingPolicy,
924
933
  userRolesSot: () => userRoles_v2_0_0_default,
925
934
  vehicleBodyTypeSot: () => vehicleBodyType_v1_0_0_default,
926
935
  vehicleColorSot: () => vehicleColor_v1_0_0_default,
@@ -929,7 +938,11 @@ __export(src_exports, {
929
938
  veteranStatusSot: () => veteranStatus_v1_0_0_default,
930
939
  victimAbuseTypesSot: () => victimAbuseTypes_v1_1_0_default,
931
940
  victimStatusFamilySot: () => victimStatusFamily_v1_0_0_default,
941
+ viewingComponentOpen: () => viewingComponentOpen,
932
942
  viewingLevelFromFunctions: () => viewingLevelFromFunctions,
943
+ viewingPolicyVocabulary: () => viewingPolicyVocabulary,
944
+ viewingRowVisible: () => viewingRowVisible,
945
+ viewingWhitelistFromPolicy: () => viewingWhitelistFromPolicy,
933
946
  visaTypeSot: () => visaType_v1_0_0_default,
934
947
  visibilityRuleSchema: () => visibilityRuleSchema,
935
948
  vspTwoStepHolds: () => vspTwoStepHolds,
@@ -25044,6 +25057,331 @@ function functionDoor(input) {
25044
25057
  };
25045
25058
  }
25046
25059
 
25060
+ // src/authz/viewingPolicy.ts
25061
+ var VIEWING_POLICY_SPECIES = "viewing";
25062
+ var VIEWING_POLICY_VOCABULARIES = Object.freeze({
25063
+ 3: Object.freeze({ scopeVersion: 3, oneHomeCarry: true, identifyingAlias: true }),
25064
+ 4: Object.freeze({ scopeVersion: 3, oneHomeCarry: false, identifyingAlias: true }),
25065
+ 5: Object.freeze({ scopeVersion: 4, oneHomeCarry: false, identifyingAlias: false })
25066
+ });
25067
+ function viewingPolicyVocabulary(scopeVocab) {
25068
+ return scopeVocab === 3 || scopeVocab === 4 || scopeVocab === 5 ? VIEWING_POLICY_VOCABULARIES[scopeVocab] : null;
25069
+ }
25070
+ function unavailableViewingPolicy(reason, policyId) {
25071
+ return {
25072
+ source: "unavailable",
25073
+ level: 0,
25074
+ visibleGroups: [],
25075
+ scopeVocab: null,
25076
+ policy: null,
25077
+ reason,
25078
+ policyId: policyId ?? null,
25079
+ rulePath: `viewing policy unavailable: ${reason}` + (policyId ? ` (${policyId})` : "") + " \u2014 no view of other teams' cases"
25080
+ };
25081
+ }
25082
+ var HEX_OBJECT_ID = /^[0-9a-fA-F]{24}$/;
25083
+ function objectIdHex(v) {
25084
+ if (typeof v === "object" && v !== null && "toHexString" in v) {
25085
+ const toHex = v.toHexString;
25086
+ if (typeof toHex === "function") {
25087
+ const hex = toHex.call(v);
25088
+ if (typeof hex === "string") return hex.toLowerCase();
25089
+ }
25090
+ }
25091
+ return null;
25092
+ }
25093
+ function idText(v) {
25094
+ if (typeof v === "string") return v === "" ? null : v;
25095
+ return objectIdHex(v);
25096
+ }
25097
+ function normalizedId(id) {
25098
+ return HEX_OBJECT_ID.test(id) ? id.toLowerCase() : id;
25099
+ }
25100
+ function policyIdOf(d) {
25101
+ return idText(d.entity_id) ?? idText(d.id) ?? idText(d._id) ?? "(no id)";
25102
+ }
25103
+ function placementOf(d) {
25104
+ if (!Array.isArray(d.assignments) || d.assignments.length !== 1) {
25105
+ return { kind: "unreadable" };
25106
+ }
25107
+ const [a] = d.assignments;
25108
+ if (typeof a !== "object" || a === null) return { kind: "unreadable" };
25109
+ const { scope, teamId } = a;
25110
+ if (scope === "account") return { kind: "account" };
25111
+ const team = idText(teamId);
25112
+ if (scope === "team" && team !== null) {
25113
+ return { kind: "team", teamId: normalizedId(team) };
25114
+ }
25115
+ return { kind: "unreadable" };
25116
+ }
25117
+ function positiveIntOrNull(v) {
25118
+ if (v === void 0 || v === null) return null;
25119
+ return typeof v === "number" && Number.isInteger(v) && v >= 1 ? v : void 0;
25120
+ }
25121
+ function governingRowOf(rows) {
25122
+ const [only] = rows;
25123
+ if (rows.length === 1 && only !== void 0) return { row: only };
25124
+ const family = idText(rows[0]?.familyId);
25125
+ const versions = rows.map((r) => positiveIntOrNull(r.version));
25126
+ const ordered = family !== null && rows.every((r) => idText(r.familyId) === family) && versions.every((v) => typeof v === "number") && new Set(versions).size === versions.length;
25127
+ if (!ordered) {
25128
+ return unavailableViewingPolicy("ambiguous_rows", policyIdOf(rows[0] ?? {}));
25129
+ }
25130
+ let best = rows[0];
25131
+ for (const r of rows) {
25132
+ if (r.version > best.version) best = r;
25133
+ }
25134
+ return { row: best };
25135
+ }
25136
+ function whitelistProblem(visibleGroups, vocab, scope) {
25137
+ const reading = scope.readSelection(visibleGroups, vocab.scopeVersion, {
25138
+ subject: "policy"
25139
+ });
25140
+ if (reading.unsupportedVersion) return "unsupported_scope_vocab";
25141
+ if (reading.unknown.length > 0 || reading.retired.length > 0) {
25142
+ return "unknown_visible_group";
25143
+ }
25144
+ return null;
25145
+ }
25146
+ function withoutRestRows(visibleGroups, scope) {
25147
+ return visibleGroups.filter((code) => scope.row(code)?.rowType !== "category_rest");
25148
+ }
25149
+ function ruleText(source, ref) {
25150
+ const v = ref.version === null ? "" : ` v${ref.version}`;
25151
+ return source === "team" ? `${ref.id}${v} (the team's own row \u2014 it governs this team in place of the account-wide rule)` : `${ref.id}${v} (the account-wide viewing rule \u2014 no row for this team)`;
25152
+ }
25153
+ function readRow(d, source, accountId, scope) {
25154
+ const policyId = policyIdOf(d);
25155
+ const level = d.level;
25156
+ if (level !== 0 && level !== 1 && level !== 2 && level !== 3) {
25157
+ return unavailableViewingPolicy("malformed_level", policyId);
25158
+ }
25159
+ let visibleGroups = [];
25160
+ if (d.visibleGroups !== void 0 && d.visibleGroups !== null) {
25161
+ if (!Array.isArray(d.visibleGroups) || !d.visibleGroups.every((g) => typeof g === "string")) {
25162
+ return unavailableViewingPolicy("malformed_visible_groups", policyId);
25163
+ }
25164
+ visibleGroups = [...d.visibleGroups];
25165
+ }
25166
+ const scopeVocab = positiveIntOrNull(d.scopeVocab);
25167
+ if (scopeVocab === void 0) {
25168
+ return unavailableViewingPolicy("malformed_scope_vocab", policyId);
25169
+ }
25170
+ const vocab = viewingPolicyVocabulary(scopeVocab);
25171
+ if (scopeVocab === null || vocab === null) {
25172
+ return unavailableViewingPolicy("unsupported_scope_vocab", policyId);
25173
+ }
25174
+ const problem = whitelistProblem(visibleGroups, vocab, scope);
25175
+ if (problem !== null) return unavailableViewingPolicy(problem, policyId);
25176
+ const policy = {
25177
+ id: policyId,
25178
+ familyId: idText(d.familyId),
25179
+ version: positiveIntOrNull(d.version) ?? null
25180
+ };
25181
+ return {
25182
+ source,
25183
+ level,
25184
+ visibleGroups: withoutRestRows(visibleGroups, scope),
25185
+ scopeVocab,
25186
+ policy,
25187
+ accountId,
25188
+ rulePath: ruleText(source, policy)
25189
+ };
25190
+ }
25191
+ function resolveViewingPolicy(docs, query, scope) {
25192
+ const accountRaw = typeof query.accountId === "string" ? query.accountId.trim() : "";
25193
+ if (accountRaw === "") return unavailableViewingPolicy("account_unresolved");
25194
+ if (!Array.isArray(docs)) return unavailableViewingPolicy("read_error");
25195
+ const accountId = normalizedId(accountRaw);
25196
+ const teamRaw = typeof query.teamId === "string" ? query.teamId.trim() : "";
25197
+ const actingTeamId = teamRaw !== "" ? normalizedId(teamRaw) : null;
25198
+ const rows = [];
25199
+ for (const raw of docs) {
25200
+ if (typeof raw !== "object" || raw === null) {
25201
+ return unavailableViewingPolicy("read_error");
25202
+ }
25203
+ const d = raw;
25204
+ if (d.species !== VIEWING_POLICY_SPECIES) continue;
25205
+ const owner = idText(d.account_id);
25206
+ if (owner === null || normalizedId(owner) !== accountId) continue;
25207
+ rows.push(d);
25208
+ }
25209
+ const teamRows = [];
25210
+ const accountRows = [];
25211
+ for (const d of rows) {
25212
+ if (d.active === false) continue;
25213
+ const placement = placementOf(d);
25214
+ if (placement.kind === "unreadable") {
25215
+ return unavailableViewingPolicy("unreadable_assignment", policyIdOf(d));
25216
+ }
25217
+ const governsHere = placement.kind === "account" || actingTeamId !== null && placement.teamId === actingTeamId;
25218
+ if (!governsHere) continue;
25219
+ if (d.active !== true) {
25220
+ return unavailableViewingPolicy("malformed_active", policyIdOf(d));
25221
+ }
25222
+ if (placement.kind === "account") accountRows.push(d);
25223
+ else teamRows.push(d);
25224
+ }
25225
+ const [source, candidates] = teamRows.length > 0 ? ["team", teamRows] : ["account", accountRows];
25226
+ if (candidates.length === 0) {
25227
+ const retiredRowsOnly = rows.length > 0 && rows.every((d) => d.active === false);
25228
+ return {
25229
+ source: "none",
25230
+ level: null,
25231
+ visibleGroups: null,
25232
+ scopeVocab: null,
25233
+ policy: null,
25234
+ accountId,
25235
+ retiredRowsOnly,
25236
+ rulePath: retiredRowsOnly ? "no viewing policy on file (every viewing row is retired) \u2014 the role level alone decides" : "no viewing policy on file \u2014 the role level alone decides"
25237
+ };
25238
+ }
25239
+ const governing = governingRowOf(candidates);
25240
+ if (!("row" in governing)) return governing;
25241
+ return readRow(governing.row, source, accountId, scope);
25242
+ }
25243
+ function teamViewingLevelFromPolicy(policy) {
25244
+ switch (policy.source) {
25245
+ case "team":
25246
+ case "account":
25247
+ return policy.level;
25248
+ case "none":
25249
+ return null;
25250
+ default:
25251
+ return 0;
25252
+ }
25253
+ }
25254
+
25255
+ // src/authz/viewingScope.ts
25256
+ var CURRENT_VIEWING_POLICY_VOCAB = 5;
25257
+ var RELATIONSHIPS_HOUSEHOLD = "relationships_household";
25258
+ var RELATIONSHIP_DYNAMICS2 = "relationship_dynamics";
25259
+ function viewingWhitelistFromPolicy(policy) {
25260
+ switch (policy.source) {
25261
+ case "none":
25262
+ return null;
25263
+ case "team":
25264
+ case "account":
25265
+ return { informationScope: [...policy.visibleGroups], scopeVocab: policy.scopeVocab };
25266
+ default:
25267
+ return { informationScope: [], scopeVocab: null };
25268
+ }
25269
+ }
25270
+ function caseViewingAccess(ctx, scope) {
25271
+ if (ctx.canSeeCase !== true) {
25272
+ return { mode: "none", reason: "cannot_see_case" };
25273
+ }
25274
+ if (ctx.ownedByViewer === true) return { mode: "full", reason: "owned" };
25275
+ if (ctx.level === 1 || ctx.level === 2) {
25276
+ return { mode: "stub", level: ctx.level };
25277
+ }
25278
+ if (ctx.level !== 3) return { mode: "none", reason: "level_0" };
25279
+ if (ctx.whitelist === null) {
25280
+ return { mode: "full", reason: "no_viewing_policy" };
25281
+ }
25282
+ const stored = ctx.whitelist ?? {
25283
+ informationScope: [],
25284
+ scopeVocab: CURRENT_VIEWING_POLICY_VOCAB
25285
+ };
25286
+ const stamp = typeof stored.scopeVocab === "number" ? stored.scopeVocab : null;
25287
+ const vocab = viewingPolicyVocabulary(stamp);
25288
+ const reading = scope.readSelection(
25289
+ stored.informationScope,
25290
+ vocab !== null ? vocab.scopeVersion : stamp,
25291
+ { subject: "policy" }
25292
+ );
25293
+ const identifyingAlias = vocab !== null && vocab.identifyingAlias && reading.informationScope.includes("identifying");
25294
+ return {
25295
+ mode: "whitelist",
25296
+ reading,
25297
+ visibleScope: identifyingAlias ? [...reading.informationScope, RELATIONSHIPS_HOUSEHOLD] : reading.informationScope,
25298
+ oneHomeCarry: vocab !== null && vocab.oneHomeCarry,
25299
+ relationshipDynamicsCarry: identifyingAlias
25300
+ };
25301
+ }
25302
+ function caseSurfacesOn(access, surface) {
25303
+ switch (access.mode) {
25304
+ case "none":
25305
+ return false;
25306
+ case "full":
25307
+ case "whitelist":
25308
+ return true;
25309
+ case "stub":
25310
+ if (surface === "search") return true;
25311
+ if (surface === "autocomplete") return access.level === 2;
25312
+ return false;
25313
+ }
25314
+ }
25315
+ function caseSurfacesAsStub(access) {
25316
+ return access.mode === "stub";
25317
+ }
25318
+ var ONE_HOME_CARRY = [
25319
+ { homeRow: "summary_ida", domains: /* @__PURE__ */ new Set(["ida_determination"]), unlockedBy: "risk" },
25320
+ {
25321
+ homeRow: "summary_needs_assessment",
25322
+ domains: /* @__PURE__ */ new Set(["needs_assessment", "recommended_followup"]),
25323
+ unlockedBy: "services"
25324
+ }
25325
+ ];
25326
+ function isClientStubRow(scope, code) {
25327
+ const row = scope.row(code);
25328
+ return row !== void 0 && row.levelFloor === 1 && row.rowType !== "branch" && (row.kindBranch === "client" || row.kindBranch === null);
25329
+ }
25330
+ function recordViewing(access, record, viewerUserId, scope) {
25331
+ if (access.mode === "none" && access.reason === "cannot_see_case") {
25332
+ return { visible: false, reason: "cannot_see_case" };
25333
+ }
25334
+ const author = record.authorUserId;
25335
+ if (typeof author === "string" && author.trim().length > 0 && author === viewerUserId) {
25336
+ return { visible: true, reason: "author" };
25337
+ }
25338
+ switch (access.mode) {
25339
+ case "none":
25340
+ return { visible: false, reason: access.reason };
25341
+ case "full":
25342
+ return { visible: true, reason: "full" };
25343
+ case "stub":
25344
+ return { visible: false, reason: "not_opened" };
25345
+ case "whitelist":
25346
+ return whitelistDecision(access, record, scope);
25347
+ }
25348
+ }
25349
+ function whitelistDecision(access, record, scope) {
25350
+ const home = scope.row(record.homeRow);
25351
+ if (home === void 0 || home.kindRow !== void 0) {
25352
+ return { visible: false, reason: "unknown_row" };
25353
+ }
25354
+ if ((record.subjectKind === "client" || home.kindBranch !== "client") && isClientStubRow(scope, record.homeRow)) {
25355
+ return { visible: true, reason: "stub_row" };
25356
+ }
25357
+ const list2 = access.visibleScope;
25358
+ if (scope.isCovered(list2, record.homeRow)) {
25359
+ return { visible: true, reason: "covered" };
25360
+ }
25361
+ if (access.relationshipDynamicsCarry && record.domain === RELATIONSHIP_DYNAMICS2) {
25362
+ return { visible: true, reason: "identifying_alias_carry" };
25363
+ }
25364
+ if (access.oneHomeCarry && !scope.isCovered(list2, "instruments") && typeof record.domain === "string") {
25365
+ for (const carry of ONE_HOME_CARRY) {
25366
+ if (record.homeRow === carry.homeRow && carry.domains.has(record.domain) && scope.isCovered(list2, carry.unlockedBy)) {
25367
+ return { visible: true, reason: "one_home_carry" };
25368
+ }
25369
+ }
25370
+ }
25371
+ return { visible: false, reason: "not_covered" };
25372
+ }
25373
+ function viewingRowVisible(access, homeRow, scope) {
25374
+ return recordViewing(access, { homeRow, subjectKind: "client" }, null, scope).visible;
25375
+ }
25376
+ function viewingComponentOpen(access, homeRow, scope) {
25377
+ if (access.mode === "full") return true;
25378
+ if (access.mode !== "whitelist") return false;
25379
+ const row = scope.row(homeRow);
25380
+ if (row === void 0 || row.kindRow !== void 0) return false;
25381
+ if (row.status === "retired") return false;
25382
+ return scope.isCovered(access.visibleScope, homeRow);
25383
+ }
25384
+
25047
25385
  // src/generated/sharingPlatformStarter.ts
25048
25386
  var SHARING_PLATFORM_STARTER_SOURCE = {
25049
25387
  "monolith": {
@@ -73998,6 +74336,8 @@ var CVC_197_VALUES = selectableCodes(
73998
74336
  VALID_RECORD_STATES,
73999
74337
  VICTIM_SERVING_ORG_TYPE_KEYS,
74000
74338
  VIEWING_LEVEL_FUNCTIONS,
74339
+ VIEWING_POLICY_SPECIES,
74340
+ VIEWING_POLICY_VOCABULARIES,
74001
74341
  VSP_TWO_STEP_ISSUE,
74002
74342
  VehicleBodyTypeKeys,
74003
74343
  VehicleColorKeys,
@@ -74054,6 +74394,9 @@ var CVC_197_VALUES = selectableCodes(
74054
74394
  carCorrectionReasonSot,
74055
74395
  cascadeExclusions,
74056
74396
  caseShareStateSot,
74397
+ caseSurfacesAsStub,
74398
+ caseSurfacesOn,
74399
+ caseViewingAccess,
74057
74400
  ceilingCoverage,
74058
74401
  checkInActivitySot,
74059
74402
  checkInPhaseSot,
@@ -74272,6 +74615,7 @@ var CVC_197_VALUES = selectableCodes(
74272
74615
  radiusBucketSot,
74273
74616
  recencyBandSot,
74274
74617
  recordRemovalReasonSot,
74618
+ recordViewing,
74275
74619
  referenceLinkTypeSot,
74276
74620
  referralEntityCategorySot,
74277
74621
  referralOriginSot,
@@ -74290,6 +74634,7 @@ var CVC_197_VALUES = selectableCodes(
74290
74634
  resolveReferralEntityKeyFromLegacyNumeric,
74291
74635
  resolveRegistryWithInheritance,
74292
74636
  resolveShare,
74637
+ resolveViewingPolicy,
74293
74638
  returnedToAbuserStatusSot,
74294
74639
  riskCategorySot,
74295
74640
  riskIdentificationMilestoneSot,
@@ -74368,11 +74713,13 @@ var CVC_197_VALUES = selectableCodes(
74368
74713
  supportTopicSot,
74369
74714
  systemCategoryOf,
74370
74715
  teamDirectorySchemaDefinition,
74716
+ teamViewingLevelFromPolicy,
74371
74717
  threadStatusSot,
74372
74718
  threadTypeSot,
74373
74719
  timeScopeSot,
74374
74720
  traffickingRelevantRoleSot,
74375
74721
  tribesSot,
74722
+ unavailableViewingPolicy,
74376
74723
  userRolesSot,
74377
74724
  vehicleBodyTypeSot,
74378
74725
  vehicleColorSot,
@@ -74381,7 +74728,11 @@ var CVC_197_VALUES = selectableCodes(
74381
74728
  veteranStatusSot,
74382
74729
  victimAbuseTypesSot,
74383
74730
  victimStatusFamilySot,
74731
+ viewingComponentOpen,
74384
74732
  viewingLevelFromFunctions,
74733
+ viewingPolicyVocabulary,
74734
+ viewingRowVisible,
74735
+ viewingWhitelistFromPolicy,
74385
74736
  visaTypeSot,
74386
74737
  visibilityRuleSchema,
74387
74738
  vspTwoStepHolds,