@htilabs/platform-common-models 0.54.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.
Files changed (41) hide show
  1. package/README.md +90 -0
  2. package/dist/authz/index.cjs +353 -2
  3. package/dist/authz/index.cjs.map +1 -1
  4. package/dist/authz/index.d.cts +330 -9
  5. package/dist/authz/index.d.ts +330 -9
  6. package/dist/authz/index.js +339 -1
  7. package/dist/authz/index.js.map +1 -1
  8. package/dist/{index-XWSYon40.d.cts → index-Bj-s0nZy.d.cts} +1 -1
  9. package/dist/{index-Bh1zO_Vu.d.ts → index-DvAypMJV.d.ts} +1 -1
  10. package/dist/index.cjs +503 -2
  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 +483 -2
  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 +152 -2
  21. package/dist/sharing-ceiling/index.cjs.map +1 -1
  22. package/dist/sharing-ceiling/index.d.cts +214 -2
  23. package/dist/sharing-ceiling/index.d.ts +214 -2
  24. package/dist/sharing-ceiling/index.js +145 -2
  25. package/dist/sharing-ceiling/index.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/__tests__/authz-resolve.test.ts +5 -0
  28. package/src/__tests__/authz-viewing-policy.test.ts +685 -0
  29. package/src/__tests__/authz-viewing-scope.test.ts +1037 -0
  30. package/src/__tests__/core-function-default-bounds.test.ts +2 -2
  31. package/src/authz/functionDoor.ts +4 -4
  32. package/src/authz/index.ts +2 -0
  33. package/src/authz/resolveEffectiveFunctions.ts +6 -4
  34. package/src/authz/viewingPolicy.ts +525 -0
  35. package/src/authz/viewingScope.ts +359 -0
  36. package/src/sharingCeiling/__tests__/fireShareEvent.test.ts +437 -0
  37. package/src/sharingCeiling/fireShareEvent.ts +352 -0
  38. package/src/sharingCeiling/index.ts +4 -0
  39. package/src/sharingCeiling/resolve.ts +31 -5
  40. package/dist/{cvcEntry-D787utvP.d.cts → cvcEntry-BLeRivoF.d.cts} +8 -8
  41. package/dist/{cvcEntry-D787utvP.d.ts → cvcEntry-BLeRivoF.d.ts} +8 -8
package/dist/index.cjs CHANGED
@@ -479,10 +479,12 @@ __export(src_exports, {
479
479
  SERVICE_STATE_STAMP_CROSSWALK: () => SERVICE_STATE_STAMP_CROSSWALK,
480
480
  SESSION_STATES: () => SESSION_STATES,
481
481
  SESSION_STATE_LABELS: () => SESSION_STATE_LABELS,
482
+ SHARE_EVENT: () => SHARE_EVENT,
482
483
  SHARE_LEVEL_LABEL: () => SHARE_LEVEL_LABEL,
483
484
  SHARE_PLATFORM_STATE_LABEL: () => SHARE_PLATFORM_STATE_LABEL,
484
485
  SHARE_POSTURE_RANK: () => SHARE_POSTURE_RANK,
485
486
  SHARE_REPORTING_PURPOSES: () => SHARE_REPORTING_PURPOSES,
487
+ SHARE_TRIGGER_EVENTS: () => SHARE_TRIGGER_EVENTS,
486
488
  SHARE_VIEW: () => SHARE_VIEW,
487
489
  SHARE_VIEW_LABELS: () => SHARE_VIEW_LABELS,
488
490
  SHARE_VIEW_VALUES: () => SHARE_VIEW_VALUES,
@@ -544,6 +546,8 @@ __export(src_exports, {
544
546
  VALID_RECORD_STATES: () => VALID_RECORD_STATES,
545
547
  VICTIM_SERVING_ORG_TYPE_KEYS: () => VICTIM_SERVING_ORG_TYPE_KEYS,
546
548
  VIEWING_LEVEL_FUNCTIONS: () => VIEWING_LEVEL_FUNCTIONS,
549
+ VIEWING_POLICY_SPECIES: () => VIEWING_POLICY_SPECIES,
550
+ VIEWING_POLICY_VOCABULARIES: () => VIEWING_POLICY_VOCABULARIES,
547
551
  VSP_TWO_STEP_ISSUE: () => VSP_TWO_STEP_ISSUE,
548
552
  VehicleBodyTypeKeys: () => VehicleBodyTypeKeys,
549
553
  VehicleColorKeys: () => VehicleColorKeys,
@@ -600,6 +604,9 @@ __export(src_exports, {
600
604
  carCorrectionReasonSot: () => carCorrectionReason_v2_1_0_default,
601
605
  cascadeExclusions: () => cascadeExclusions,
602
606
  caseShareStateSot: () => caseShareState_v1_2_0_default,
607
+ caseSurfacesAsStub: () => caseSurfacesAsStub,
608
+ caseSurfacesOn: () => caseSurfacesOn,
609
+ caseViewingAccess: () => caseViewingAccess,
603
610
  ceilingCoverage: () => ceilingCoverage,
604
611
  checkInActivitySot: () => checkInActivity_v1_0_0_default,
605
612
  checkInPhaseSot: () => checkInPhase_v1_1_0_default,
@@ -662,6 +669,8 @@ __export(src_exports, {
662
669
  facilitatorEntityTypeSot: () => facilitatorEntityType_v1_0_0_default,
663
670
  facilitatorLabelUsedInSourceSot: () => facilitatorLabelUsedInSource_v1_0_0_default,
664
671
  facilitatorSubroleSot: () => facilitatorSubrole_v1_0_0_default,
672
+ fireShareEvent: () => fireShareEvent,
673
+ firedShareKey: () => firedShareKey,
665
674
  formModel: () => formModel_exports,
666
675
  formSchemaDefinition: () => formSchemaDefinition,
667
676
  formSchemaOptions: () => formSchemaOptions,
@@ -799,6 +808,7 @@ __export(src_exports, {
799
808
  poPetitionBasisSot: () => poPetitionBasis_v1_0_0_default,
800
809
  poStatusSot: () => poStatus_v1_0_0_default,
801
810
  poViolationStatusSot: () => poViolationStatus_v1_0_0_default,
811
+ policyIsShareListener: () => policyIsShareListener,
802
812
  preferredContactMethodSot: () => preferredContactMethod_v1_0_0_default,
803
813
  primaryLanguageSot: () => primaryLanguage_v1_0_0_default,
804
814
  programEnrollmentChangeTypeSot: () => programEnrollmentChangeType_v1_0_0_default,
@@ -815,6 +825,7 @@ __export(src_exports, {
815
825
  radiusBucketSot: () => radiusBucket_v1_0_0_default,
816
826
  recencyBandSot: () => recencyBand_v1_0_0_default,
817
827
  recordRemovalReasonSot: () => recordRemovalReason_v1_0_0_default,
828
+ recordViewing: () => recordViewing,
818
829
  referenceLinkTypeSot: () => referenceLinkType_v1_0_0_default,
819
830
  referralEntityCategorySot: () => referralEntityCategory_v1_2_0_default,
820
831
  referralOriginSot: () => referralOrigin_v1_0_0_default,
@@ -833,6 +844,7 @@ __export(src_exports, {
833
844
  resolveReferralEntityKeyFromLegacyNumeric: () => resolveReferralEntityKeyFromLegacyNumeric,
834
845
  resolveRegistryWithInheritance: () => resolveRegistryWithInheritance,
835
846
  resolveShare: () => resolveShare,
847
+ resolveViewingPolicy: () => resolveViewingPolicy,
836
848
  returnedToAbuserStatusSot: () => returnedToAbuserStatus_v1_0_0_default,
837
849
  riskCategorySot: () => riskCategory_v1_0_0_default,
838
850
  riskIdentificationMilestoneSot: () => riskIdentificationMilestone_v1_0_0_default,
@@ -884,9 +896,11 @@ __export(src_exports, {
884
896
  sexProviderSubroleSot: () => sexProviderSubrole_v1_0_0_default,
885
897
  shareCadenceSot: () => shareCadence_v1_0_0_default,
886
898
  shareDefaultScopeFor: () => shareDefaultScopeFor,
899
+ shareListenersFor: () => shareListenersFor,
887
900
  sharePurposeSot: () => sharePurpose_v1_0_0_default,
888
901
  shareResponseReasonSot: () => shareResponseReason_v1_0_0_default,
889
902
  shareRowCeiling: () => shareRowCeiling,
903
+ shareTriggerLabel: () => shareTriggerLabel,
890
904
  sharingCeilingCellList: () => sharingCeilingCellList,
891
905
  sharingCeilingRowKey: () => sharingCeilingRowKey,
892
906
  sharingScopeEditsFromCells: () => sharingScopeEditsFromCells,
@@ -909,11 +923,13 @@ __export(src_exports, {
909
923
  supportTopicSot: () => supportTopic_v1_0_0_default,
910
924
  systemCategoryOf: () => systemCategoryOf,
911
925
  teamDirectorySchemaDefinition: () => teamDirectorySchemaDefinition,
926
+ teamViewingLevelFromPolicy: () => teamViewingLevelFromPolicy,
912
927
  threadStatusSot: () => threadStatus_v1_0_0_default,
913
928
  threadTypeSot: () => threadType_v1_0_0_default,
914
929
  timeScopeSot: () => timeScope_v1_0_0_default,
915
930
  traffickingRelevantRoleSot: () => traffickingRelevantRole_v1_0_0_default,
916
931
  tribesSot: () => tribes_v1_0_0_default,
932
+ unavailableViewingPolicy: () => unavailableViewingPolicy,
917
933
  userRolesSot: () => userRoles_v2_0_0_default,
918
934
  vehicleBodyTypeSot: () => vehicleBodyType_v1_0_0_default,
919
935
  vehicleColorSot: () => vehicleColor_v1_0_0_default,
@@ -922,7 +938,11 @@ __export(src_exports, {
922
938
  veteranStatusSot: () => veteranStatus_v1_0_0_default,
923
939
  victimAbuseTypesSot: () => victimAbuseTypes_v1_1_0_default,
924
940
  victimStatusFamilySot: () => victimStatusFamily_v1_0_0_default,
941
+ viewingComponentOpen: () => viewingComponentOpen,
925
942
  viewingLevelFromFunctions: () => viewingLevelFromFunctions,
943
+ viewingPolicyVocabulary: () => viewingPolicyVocabulary,
944
+ viewingRowVisible: () => viewingRowVisible,
945
+ viewingWhitelistFromPolicy: () => viewingWhitelistFromPolicy,
926
946
  visaTypeSot: () => visaType_v1_0_0_default,
927
947
  visibilityRuleSchema: () => visibilityRuleSchema,
928
948
  vspTwoStepHolds: () => vspTwoStepHolds,
@@ -25037,6 +25057,331 @@ function functionDoor(input) {
25037
25057
  };
25038
25058
  }
25039
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
+
25040
25385
  // src/generated/sharingPlatformStarter.ts
25041
25386
  var SHARING_PLATFORM_STARTER_SOURCE = {
25042
25387
  "monolith": {
@@ -25962,7 +26307,9 @@ function resolveShare(input) {
25962
26307
  const teamExcludedItems = [];
25963
26308
  let teamExcludedReason = null;
25964
26309
  const outside = (covered) => items.filter(
25965
- (r) => !covered(r) && !items.some((d) => d !== r && covered(d) && scope.ancestorsOf(d).includes(r))
26310
+ (r) => !covered(r) && !items.some(
26311
+ (d) => d !== r && covered(d) && scope.ancestorsOf(d).includes(r)
26312
+ )
25966
26313
  );
25967
26314
  const addExcluded = (rows, why) => {
25968
26315
  for (const r of rows)
@@ -26032,7 +26379,8 @@ function resolveShare(input) {
26032
26379
  const why = `Outside what your team's \u201C${tcNamed?.name}\u201D policy allows`;
26033
26380
  const outRows = /* @__PURE__ */ new Set();
26034
26381
  if (tcScope !== null && !scopeListStrictlyCovers(scope, tcScope, g)) {
26035
- for (const r of outside((x) => scopeListCovers(scope, tcScope, g, x))) outRows.add(r);
26382
+ for (const r of outside((x) => scopeListCovers(scope, tcScope, g, x)))
26383
+ outRows.add(r);
26036
26384
  }
26037
26385
  const tcRows = own3(tcItems, g);
26038
26386
  if (isStringList2(tcRows)) {
@@ -26091,6 +26439,139 @@ function resolveShare(input) {
26091
26439
  };
26092
26440
  }
26093
26441
 
26442
+ // src/sharingCeiling/fireShareEvent.ts
26443
+ var SHARE_TRIGGER_EVENTS = Object.freeze([
26444
+ { code: "sessionSubmitted", label: "Session submitted", group: "case" },
26445
+ { code: "caseOpened", label: "Case opened", group: "case" },
26446
+ { code: "caseStatusChanged", label: "Case status changed", group: "case" },
26447
+ { code: "caseCloseRuled", label: "Case closed", group: "case" },
26448
+ {
26449
+ code: "determinationIssued",
26450
+ label: "Determination issued",
26451
+ group: "case"
26452
+ },
26453
+ { code: "serviceLogged", label: "Service logged", group: "case" },
26454
+ { code: "noteAdded", label: "Note added", group: "case" },
26455
+ { code: "shareClaimed", label: "Share you sent claimed", group: "share" },
26456
+ {
26457
+ code: "referralClaimed",
26458
+ label: "Referral you sent claimed",
26459
+ group: "share"
26460
+ },
26461
+ {
26462
+ code: "shareAcknowledged",
26463
+ label: "Share you sent acknowledged",
26464
+ group: "share"
26465
+ }
26466
+ ]);
26467
+ var SHARE_EVENT = Object.freeze({
26468
+ SESSION_SUBMITTED: "sessionSubmitted",
26469
+ CASE_CLOSED: "caseCloseRuled"
26470
+ });
26471
+ function shareTriggerLabel(code) {
26472
+ return SHARE_TRIGGER_EVENTS.find((t) => t.code === code)?.label ?? code;
26473
+ }
26474
+ var str2 = (v) => typeof v === "string" && v !== "";
26475
+ function policyIsShareListener(p) {
26476
+ if (p === null || p === void 0 || typeof p !== "object") return false;
26477
+ if (p.active === false) return false;
26478
+ if (p.cadences?.ongoing !== true) return false;
26479
+ const on = p.trigger?.on;
26480
+ if (!Array.isArray(on) || !on.some(str2)) return false;
26481
+ return p.trigger?.answers !== "received";
26482
+ }
26483
+ function linkTarget(a) {
26484
+ const withTeam = a.with !== null && typeof a.with === "object" && a.with.type === "team" && str2(a.with.id) ? a.with.id : null;
26485
+ if (str2(a.partnerId)) {
26486
+ return {
26487
+ recipient: { kind: "partner", id: a.partnerId },
26488
+ partnerTeamId: withTeam
26489
+ };
26490
+ }
26491
+ if (withTeam !== null) {
26492
+ return {
26493
+ recipient: { kind: "sibling_team", teamId: withTeam },
26494
+ partnerTeamId: null
26495
+ };
26496
+ }
26497
+ return null;
26498
+ }
26499
+ var targetKey = (l) => l.recipient.kind === "partner" ? ["partner", l.recipient.id, l.partnerTeamId] : ["team", l.recipient.teamId, null];
26500
+ function rowAgrees(rows, a, target) {
26501
+ const row = rows.find(
26502
+ (r) => r !== null && typeof r === "object" && r.id === a.teamRowId
26503
+ );
26504
+ if (row === void 0 || row.myTeamId !== a.teamId) return false;
26505
+ const theirTeam = row.their?.type === "team" && str2(row.their.id) ? row.their.id : null;
26506
+ return target.recipient.kind === "sibling_team" ? theirTeam === target.recipient.teamId : theirTeam === target.partnerTeamId;
26507
+ }
26508
+ function shareListenersFor(policies, teamId, options = {}) {
26509
+ if (!Array.isArray(policies) || !str2(teamId)) return [];
26510
+ const cells = attachmentIndexFromPolicies(policies).teamRows;
26511
+ const rows = Array.isArray(options.teamRows) ? options.teamRows : null;
26512
+ const out = [];
26513
+ const seen = /* @__PURE__ */ new Set();
26514
+ for (const p of policies) {
26515
+ if (!policyIsShareListener(p) || !str2(p.id) || !str2(p.purpose)) continue;
26516
+ const events = (p.trigger?.on ?? []).filter(str2);
26517
+ if (str2(options.event) && !events.includes(options.event)) continue;
26518
+ for (const a of Array.isArray(p.assignments) ? p.assignments : []) {
26519
+ if (a === null || typeof a !== "object" || a.scope !== "team_pair")
26520
+ continue;
26521
+ if (!str2(a.teamRowId) || a.teamId !== teamId) continue;
26522
+ if (cells[a.teamRowId]?.[p.purpose] !== p.id) continue;
26523
+ const target = linkTarget(a);
26524
+ if (target === null) continue;
26525
+ if (rows !== null && !rowAgrees(rows, a, target)) continue;
26526
+ if (target.recipient.kind === "sibling_team" && target.recipient.teamId === teamId)
26527
+ continue;
26528
+ const dedupe = JSON.stringify([p.id, ...targetKey(target)]);
26529
+ if (seen.has(dedupe)) continue;
26530
+ seen.add(dedupe);
26531
+ out.push({
26532
+ policy: {
26533
+ id: p.id,
26534
+ familyId: str2(p.familyId) ? p.familyId : p.id,
26535
+ name: str2(p.name) ? p.name : p.id,
26536
+ version: parseInt(String(p.version), 10) || 1
26537
+ },
26538
+ purpose: p.purpose,
26539
+ fromTeamId: teamId,
26540
+ teamRowId: a.teamRowId,
26541
+ ...target,
26542
+ events
26543
+ });
26544
+ }
26545
+ }
26546
+ return out;
26547
+ }
26548
+ function firedShareKey(event, ref, listener) {
26549
+ return JSON.stringify([
26550
+ event,
26551
+ ref,
26552
+ listener.policy.id,
26553
+ listener.fromTeamId,
26554
+ ...targetKey(listener)
26555
+ ]);
26556
+ }
26557
+ function fireShareEvent(policies, event, options = {}) {
26558
+ if (event === null || event === void 0 || !str2(event.event)) return [];
26559
+ const session = str2(event.sessionId) ? event.sessionId : null;
26560
+ const kase = str2(event.caseId) ? event.caseId : null;
26561
+ const ref = str2(event.ref) ? event.ref : event.event === SHARE_EVENT.SESSION_SUBMITTED ? session ?? kase : kase ?? session;
26562
+ const done = new Set(options.alreadyFired ?? []);
26563
+ const fired = [];
26564
+ for (const l of shareListenersFor(policies, event.teamId, {
26565
+ event: event.event,
26566
+ teamRows: options.teamRows ?? null
26567
+ })) {
26568
+ const key = firedShareKey(event.event, ref, l);
26569
+ if (done.has(key)) continue;
26570
+ fired.push({ ...l, event: event.event, ref, key });
26571
+ }
26572
+ return fired;
26573
+ }
26574
+
26094
26575
  // src/validation/cvc.ts
26095
26576
  var import_zod = require("zod");
26096
26577
  var CvcCodeSchema = import_zod.z.string().regex(/^\d{3}(-\d{3}){6}$/);
@@ -73788,10 +74269,12 @@ var CVC_197_VALUES = selectableCodes(
73788
74269
  SERVICE_STATE_STAMP_CROSSWALK,
73789
74270
  SESSION_STATES,
73790
74271
  SESSION_STATE_LABELS,
74272
+ SHARE_EVENT,
73791
74273
  SHARE_LEVEL_LABEL,
73792
74274
  SHARE_PLATFORM_STATE_LABEL,
73793
74275
  SHARE_POSTURE_RANK,
73794
74276
  SHARE_REPORTING_PURPOSES,
74277
+ SHARE_TRIGGER_EVENTS,
73795
74278
  SHARE_VIEW,
73796
74279
  SHARE_VIEW_LABELS,
73797
74280
  SHARE_VIEW_VALUES,
@@ -73853,6 +74336,8 @@ var CVC_197_VALUES = selectableCodes(
73853
74336
  VALID_RECORD_STATES,
73854
74337
  VICTIM_SERVING_ORG_TYPE_KEYS,
73855
74338
  VIEWING_LEVEL_FUNCTIONS,
74339
+ VIEWING_POLICY_SPECIES,
74340
+ VIEWING_POLICY_VOCABULARIES,
73856
74341
  VSP_TWO_STEP_ISSUE,
73857
74342
  VehicleBodyTypeKeys,
73858
74343
  VehicleColorKeys,
@@ -73909,6 +74394,9 @@ var CVC_197_VALUES = selectableCodes(
73909
74394
  carCorrectionReasonSot,
73910
74395
  cascadeExclusions,
73911
74396
  caseShareStateSot,
74397
+ caseSurfacesAsStub,
74398
+ caseSurfacesOn,
74399
+ caseViewingAccess,
73912
74400
  ceilingCoverage,
73913
74401
  checkInActivitySot,
73914
74402
  checkInPhaseSot,
@@ -73971,6 +74459,8 @@ var CVC_197_VALUES = selectableCodes(
73971
74459
  facilitatorEntityTypeSot,
73972
74460
  facilitatorLabelUsedInSourceSot,
73973
74461
  facilitatorSubroleSot,
74462
+ fireShareEvent,
74463
+ firedShareKey,
73974
74464
  formModel,
73975
74465
  formSchemaDefinition,
73976
74466
  formSchemaOptions,
@@ -74108,6 +74598,7 @@ var CVC_197_VALUES = selectableCodes(
74108
74598
  poPetitionBasisSot,
74109
74599
  poStatusSot,
74110
74600
  poViolationStatusSot,
74601
+ policyIsShareListener,
74111
74602
  preferredContactMethodSot,
74112
74603
  primaryLanguageSot,
74113
74604
  programEnrollmentChangeTypeSot,
@@ -74124,6 +74615,7 @@ var CVC_197_VALUES = selectableCodes(
74124
74615
  radiusBucketSot,
74125
74616
  recencyBandSot,
74126
74617
  recordRemovalReasonSot,
74618
+ recordViewing,
74127
74619
  referenceLinkTypeSot,
74128
74620
  referralEntityCategorySot,
74129
74621
  referralOriginSot,
@@ -74142,6 +74634,7 @@ var CVC_197_VALUES = selectableCodes(
74142
74634
  resolveReferralEntityKeyFromLegacyNumeric,
74143
74635
  resolveRegistryWithInheritance,
74144
74636
  resolveShare,
74637
+ resolveViewingPolicy,
74145
74638
  returnedToAbuserStatusSot,
74146
74639
  riskCategorySot,
74147
74640
  riskIdentificationMilestoneSot,
@@ -74193,9 +74686,11 @@ var CVC_197_VALUES = selectableCodes(
74193
74686
  sexProviderSubroleSot,
74194
74687
  shareCadenceSot,
74195
74688
  shareDefaultScopeFor,
74689
+ shareListenersFor,
74196
74690
  sharePurposeSot,
74197
74691
  shareResponseReasonSot,
74198
74692
  shareRowCeiling,
74693
+ shareTriggerLabel,
74199
74694
  sharingCeilingCellList,
74200
74695
  sharingCeilingRowKey,
74201
74696
  sharingScopeEditsFromCells,
@@ -74218,11 +74713,13 @@ var CVC_197_VALUES = selectableCodes(
74218
74713
  supportTopicSot,
74219
74714
  systemCategoryOf,
74220
74715
  teamDirectorySchemaDefinition,
74716
+ teamViewingLevelFromPolicy,
74221
74717
  threadStatusSot,
74222
74718
  threadTypeSot,
74223
74719
  timeScopeSot,
74224
74720
  traffickingRelevantRoleSot,
74225
74721
  tribesSot,
74722
+ unavailableViewingPolicy,
74226
74723
  userRolesSot,
74227
74724
  vehicleBodyTypeSot,
74228
74725
  vehicleColorSot,
@@ -74231,7 +74728,11 @@ var CVC_197_VALUES = selectableCodes(
74231
74728
  veteranStatusSot,
74232
74729
  victimAbuseTypesSot,
74233
74730
  victimStatusFamilySot,
74731
+ viewingComponentOpen,
74234
74732
  viewingLevelFromFunctions,
74733
+ viewingPolicyVocabulary,
74734
+ viewingRowVisible,
74735
+ viewingWhitelistFromPolicy,
74235
74736
  visaTypeSot,
74236
74737
  visibilityRuleSchema,
74237
74738
  vspTwoStepHolds,