@htilabs/platform-common-models 0.40.0 → 0.41.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/README.md +51 -0
- package/dist/{index-uz57Fic9.d.ts → index-BHSRMJvd.d.ts} +1 -1
- package/dist/{index-1pWiqEBC.d.cts → index-DF469Qgd.d.cts} +1 -1
- package/dist/index.cjs +51 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/dist/models/index.d.cts +2 -2
- package/dist/models/index.d.ts +2 -2
- package/dist/schemas/index.d.cts +25 -25
- package/dist/schemas/index.d.ts +25 -25
- package/dist/share-rules/index.cjs +822 -0
- package/dist/share-rules/index.cjs.map +1 -0
- package/dist/share-rules/index.d.cts +804 -0
- package/dist/share-rules/index.d.ts +804 -0
- package/dist/share-rules/index.js +736 -0
- package/dist/share-rules/index.js.map +1 -0
- package/dist/sharing-ceiling/index.cjs +51 -0
- package/dist/sharing-ceiling/index.cjs.map +1 -1
- package/dist/sharing-ceiling/index.d.cts +87 -1
- package/dist/sharing-ceiling/index.d.ts +87 -1
- package/dist/sharing-ceiling/index.js +47 -0
- package/dist/sharing-ceiling/index.js.map +1 -1
- package/package.json +6 -1
- package/src/shareRules/__tests__/caseShareLane.test.ts +259 -0
- package/src/shareRules/__tests__/magicLinkAddresses.test.ts +107 -0
- package/src/shareRules/__tests__/platformApps.test.ts +133 -0
- package/src/shareRules/__tests__/releaseTerms.test.ts +358 -0
- package/src/shareRules/__tests__/senderRoiPosture.test.ts +284 -0
- package/src/shareRules/__tests__/sharingMethods.test.ts +105 -0
- package/src/shareRules/caseShareLane.ts +289 -0
- package/src/shareRules/index.ts +31 -0
- package/src/shareRules/magicLinkAddresses.ts +185 -0
- package/src/shareRules/platformApps.ts +168 -0
- package/src/shareRules/releaseTerms.ts +359 -0
- package/src/shareRules/reportPurposes.ts +50 -0
- package/src/shareRules/senderRoiPosture.ts +296 -0
- package/src/shareRules/sharingMethods.ts +204 -0
- package/src/sharingCeiling/__tests__/threadLift.test.ts +353 -0
- package/src/sharingCeiling/coverage.ts +63 -0
- package/src/sharingCeiling/defaults.ts +106 -0
- package/src/sharingCeiling/index.ts +7 -0
- package/dist/{cvcEntry-DAuhe0cd.d.cts → cvcEntry-DQEoFVL2.d.cts} +8 -8
- package/dist/{cvcEntry-DAuhe0cd.d.ts → cvcEntry-DQEoFVL2.d.ts} +8 -8
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
// src/constants/platform-auth.ts
|
|
2
|
+
var PERMISSION_STATE = {
|
|
3
|
+
/** Role can always perform this function (mandatory, cannot disable). */
|
|
4
|
+
ALWAYS: "ALWAYS",
|
|
5
|
+
/** Default On — user can opt off. */
|
|
6
|
+
PREF_YES: "PREF_YES",
|
|
7
|
+
/** Default Off — user can opt in. */
|
|
8
|
+
PREF_NO: "PREF_NO",
|
|
9
|
+
/** Role is explicitly barred from this function. */
|
|
10
|
+
NEVER: "NEVER"
|
|
11
|
+
};
|
|
12
|
+
var PERMISSION_STATE_VALUES = [
|
|
13
|
+
PERMISSION_STATE.ALWAYS,
|
|
14
|
+
PERMISSION_STATE.PREF_YES,
|
|
15
|
+
PERMISSION_STATE.PREF_NO,
|
|
16
|
+
PERMISSION_STATE.NEVER
|
|
17
|
+
];
|
|
18
|
+
var PERMISSION_STATE_LABELS = {
|
|
19
|
+
[PERMISSION_STATE.ALWAYS]: "Always",
|
|
20
|
+
[PERMISSION_STATE.PREF_YES]: "Default On",
|
|
21
|
+
[PERMISSION_STATE.PREF_NO]: "Default Off",
|
|
22
|
+
[PERMISSION_STATE.NEVER]: "Never"
|
|
23
|
+
};
|
|
24
|
+
var PERMISSION_STATE_DISPLAY = {
|
|
25
|
+
[PERMISSION_STATE.ALWAYS]: {
|
|
26
|
+
label: "Always",
|
|
27
|
+
color: "#2e7d32",
|
|
28
|
+
bgColor: "#e8f5e9",
|
|
29
|
+
icon: "\u{1F512}"
|
|
30
|
+
},
|
|
31
|
+
[PERMISSION_STATE.PREF_YES]: {
|
|
32
|
+
label: "Default On",
|
|
33
|
+
color: "#1565c0",
|
|
34
|
+
bgColor: "#e3f2fd",
|
|
35
|
+
icon: "\u{1F513}"
|
|
36
|
+
},
|
|
37
|
+
[PERMISSION_STATE.PREF_NO]: {
|
|
38
|
+
label: "Default Off",
|
|
39
|
+
color: "#e65100",
|
|
40
|
+
bgColor: "#fff3e0",
|
|
41
|
+
icon: "\u{1F513}"
|
|
42
|
+
},
|
|
43
|
+
[PERMISSION_STATE.NEVER]: {
|
|
44
|
+
label: "Never",
|
|
45
|
+
color: "#c62828",
|
|
46
|
+
bgColor: "#ffebee",
|
|
47
|
+
icon: "\u{1F512}"
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var DEFAULT_BOUND_STATE = {
|
|
51
|
+
...PERMISSION_STATE,
|
|
52
|
+
/** Not relevant — canon's `not_applicable_roles` for this function. */
|
|
53
|
+
NA: "NA"
|
|
54
|
+
};
|
|
55
|
+
var DEFAULT_BOUND_STATE_VALUES = [
|
|
56
|
+
...PERMISSION_STATE_VALUES,
|
|
57
|
+
DEFAULT_BOUND_STATE.NA
|
|
58
|
+
];
|
|
59
|
+
var DEFAULT_BOUND_STATE_LABELS = {
|
|
60
|
+
...PERMISSION_STATE_LABELS,
|
|
61
|
+
[DEFAULT_BOUND_STATE.NA]: "Not relevant"
|
|
62
|
+
};
|
|
63
|
+
var DEFAULT_BOUND_STATE_DISPLAY = {
|
|
64
|
+
...PERMISSION_STATE_DISPLAY,
|
|
65
|
+
[DEFAULT_BOUND_STATE.NA]: {
|
|
66
|
+
label: "Not relevant",
|
|
67
|
+
color: "#616161",
|
|
68
|
+
bgColor: "#f5f5f5",
|
|
69
|
+
icon: "\u25CC"
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var SHARE_VIEW = {
|
|
73
|
+
/** System metadata only (partial access). */
|
|
74
|
+
SYS_INFO: "sys_info",
|
|
75
|
+
/** Full case/record content. */
|
|
76
|
+
ALL: "all",
|
|
77
|
+
/** No data access. */
|
|
78
|
+
NONE: "none"
|
|
79
|
+
};
|
|
80
|
+
var SHARE_VIEW_VALUES = [
|
|
81
|
+
SHARE_VIEW.SYS_INFO,
|
|
82
|
+
SHARE_VIEW.ALL,
|
|
83
|
+
SHARE_VIEW.NONE
|
|
84
|
+
];
|
|
85
|
+
var SHARE_VIEW_LABELS = {
|
|
86
|
+
[SHARE_VIEW.SYS_INFO]: "System Info Only",
|
|
87
|
+
[SHARE_VIEW.ALL]: "Full Content",
|
|
88
|
+
[SHARE_VIEW.NONE]: "No Data Access"
|
|
89
|
+
};
|
|
90
|
+
var PLATFORM_TOOL = {
|
|
91
|
+
PAVE: "PAVE",
|
|
92
|
+
ECHO: "ECHO",
|
|
93
|
+
LEADS: "LEADS",
|
|
94
|
+
THREAD: "THREAD",
|
|
95
|
+
TRAIL: "TRAIL",
|
|
96
|
+
PLATFORM: "PLATFORM"
|
|
97
|
+
};
|
|
98
|
+
var PLATFORM_TOOL_VALUES = [
|
|
99
|
+
PLATFORM_TOOL.PAVE,
|
|
100
|
+
PLATFORM_TOOL.ECHO,
|
|
101
|
+
PLATFORM_TOOL.LEADS,
|
|
102
|
+
PLATFORM_TOOL.THREAD,
|
|
103
|
+
PLATFORM_TOOL.TRAIL,
|
|
104
|
+
PLATFORM_TOOL.PLATFORM
|
|
105
|
+
];
|
|
106
|
+
var PLATFORM_TOOL_LABELS = {
|
|
107
|
+
[PLATFORM_TOOL.PAVE]: "PAVE",
|
|
108
|
+
[PLATFORM_TOOL.ECHO]: "Echo",
|
|
109
|
+
[PLATFORM_TOOL.LEADS]: "LEADS",
|
|
110
|
+
[PLATFORM_TOOL.THREAD]: "Thread",
|
|
111
|
+
[PLATFORM_TOOL.TRAIL]: "Trail",
|
|
112
|
+
[PLATFORM_TOOL.PLATFORM]: "Platform"
|
|
113
|
+
};
|
|
114
|
+
var ROLE_LEVEL = {
|
|
115
|
+
/** User-facing roles (staff, volunteers, practitioners). */
|
|
116
|
+
OPERATIONAL: "operational",
|
|
117
|
+
/** Agency-level admin roles. */
|
|
118
|
+
AGENCY: "agency",
|
|
119
|
+
/** Team-level admin roles. */
|
|
120
|
+
TEAM: "team",
|
|
121
|
+
/** HTI-wide platform admin. */
|
|
122
|
+
PLATFORM: "platform",
|
|
123
|
+
/** External governance/oversight roles. */
|
|
124
|
+
OVERSIGHT: "oversight"
|
|
125
|
+
};
|
|
126
|
+
var ROLE_LEVEL_VALUES = [
|
|
127
|
+
ROLE_LEVEL.OPERATIONAL,
|
|
128
|
+
ROLE_LEVEL.AGENCY,
|
|
129
|
+
ROLE_LEVEL.TEAM,
|
|
130
|
+
ROLE_LEVEL.PLATFORM,
|
|
131
|
+
ROLE_LEVEL.OVERSIGHT
|
|
132
|
+
];
|
|
133
|
+
var ROLE_LEVEL_LABELS = {
|
|
134
|
+
[ROLE_LEVEL.OPERATIONAL]: "Operational",
|
|
135
|
+
[ROLE_LEVEL.AGENCY]: "Agency",
|
|
136
|
+
[ROLE_LEVEL.TEAM]: "Team",
|
|
137
|
+
[ROLE_LEVEL.PLATFORM]: "Platform",
|
|
138
|
+
[ROLE_LEVEL.OVERSIGHT]: "Oversight"
|
|
139
|
+
};
|
|
140
|
+
var FUNCTION_STATUS = {
|
|
141
|
+
NOT_STARTED: "Not started",
|
|
142
|
+
DEFINED_NEW: "Defined; new function",
|
|
143
|
+
DEFINED_EXISTING: "Defined; existing PAVE function",
|
|
144
|
+
FUNCTIONAL: "Functional on all apps",
|
|
145
|
+
FUTURE: "Future function (not v1)"
|
|
146
|
+
};
|
|
147
|
+
var FUNCTION_STATUS_VALUES = [
|
|
148
|
+
FUNCTION_STATUS.NOT_STARTED,
|
|
149
|
+
FUNCTION_STATUS.DEFINED_NEW,
|
|
150
|
+
FUNCTION_STATUS.DEFINED_EXISTING,
|
|
151
|
+
FUNCTION_STATUS.FUNCTIONAL,
|
|
152
|
+
FUNCTION_STATUS.FUTURE
|
|
153
|
+
];
|
|
154
|
+
var FUNCTION_STATUS_LABELS = {
|
|
155
|
+
[FUNCTION_STATUS.NOT_STARTED]: "Not Started",
|
|
156
|
+
[FUNCTION_STATUS.DEFINED_NEW]: "Defined (New)",
|
|
157
|
+
[FUNCTION_STATUS.DEFINED_EXISTING]: "Defined (Existing PAVE)",
|
|
158
|
+
[FUNCTION_STATUS.FUNCTIONAL]: "Functional",
|
|
159
|
+
[FUNCTION_STATUS.FUTURE]: "Future (Not v1)"
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/shareRules/platformApps.ts
|
|
163
|
+
var CASEWORK_APPS = [
|
|
164
|
+
PLATFORM_TOOL.THREAD,
|
|
165
|
+
PLATFORM_TOOL.PAVE,
|
|
166
|
+
PLATFORM_TOOL.LEADS
|
|
167
|
+
];
|
|
168
|
+
function trimAsciiWhitespace(s) {
|
|
169
|
+
return s.replace(/^[ \t\n\v\f\r]+|[ \t\n\v\f\r]+$/g, "");
|
|
170
|
+
}
|
|
171
|
+
function isCaseworkApp(app) {
|
|
172
|
+
return CASEWORK_APPS.some((c) => recipientUsesApp([app], c));
|
|
173
|
+
}
|
|
174
|
+
function appsAsRead(apps) {
|
|
175
|
+
const list = typeof apps === "string" ? [apps] : Array.isArray(apps) ? apps : [];
|
|
176
|
+
return list.filter((a) => typeof a === "string" && a.length > 0);
|
|
177
|
+
}
|
|
178
|
+
function recipientUsesApp(apps, app) {
|
|
179
|
+
const want = app.toLowerCase();
|
|
180
|
+
return appsAsRead(apps).some(
|
|
181
|
+
(a) => trimAsciiWhitespace(a).toLowerCase() === want
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
function agencyIdKey(id) {
|
|
185
|
+
const s = String(id);
|
|
186
|
+
return /^[0-9a-fA-F]{24}$/.test(s) ? s.toLowerCase() : s;
|
|
187
|
+
}
|
|
188
|
+
function recipientPlatformFromApps(apps) {
|
|
189
|
+
const basis = appsAsRead(apps);
|
|
190
|
+
return {
|
|
191
|
+
recipientOnPlatform: basis.some(isCaseworkApp),
|
|
192
|
+
recipientOnPlatformBasis: basis
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function teamLandingApp(apps) {
|
|
196
|
+
const first = Array.isArray(apps) ? apps[0] : void 0;
|
|
197
|
+
return typeof first === "string" && first.length > 0 ? first : void 0;
|
|
198
|
+
}
|
|
199
|
+
function teamLandsInPave(apps) {
|
|
200
|
+
return teamLandingApp(apps) === PLATFORM_TOOL.PAVE;
|
|
201
|
+
}
|
|
202
|
+
function teamLandsInThread(apps) {
|
|
203
|
+
return teamLandingApp(apps) === PLATFORM_TOOL.THREAD;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/generated/cvc-enums.ts
|
|
207
|
+
var RoiMethodKeys = {
|
|
208
|
+
missingness_root: "970-000-000-000-000-000-000",
|
|
209
|
+
unknown: "970-000-000-000-000-000-001",
|
|
210
|
+
anonymous: "970-000-000-000-000-000-002",
|
|
211
|
+
data_not_collected: "970-000-000-000-000-000-003",
|
|
212
|
+
thread_caseshare: "970-001-000-000-000-000-000",
|
|
213
|
+
thread_magic_link: "970-002-000-000-000-000-000",
|
|
214
|
+
email: "970-003-000-000-000-000-000",
|
|
215
|
+
fax: "970-004-000-000-000-000-000",
|
|
216
|
+
secure_portal: "970-005-000-000-000-000-000",
|
|
217
|
+
in_person: "970-006-000-000-000-000-000"
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
// src/shareRules/sharingMethods.ts
|
|
221
|
+
var SHARING_METHOD = {
|
|
222
|
+
CASE_SHARE: "case_share",
|
|
223
|
+
MAGIC_LINK: "magic_link",
|
|
224
|
+
EMAIL: "email",
|
|
225
|
+
FAX: "fax",
|
|
226
|
+
SECURE_PORTAL: "secure_portal",
|
|
227
|
+
PHYSICAL_MAIL: "physical_mail",
|
|
228
|
+
IN_PERSON: "in_person"
|
|
229
|
+
};
|
|
230
|
+
var SHARING_METHOD_VALUES = [
|
|
231
|
+
SHARING_METHOD.CASE_SHARE,
|
|
232
|
+
SHARING_METHOD.MAGIC_LINK,
|
|
233
|
+
SHARING_METHOD.EMAIL,
|
|
234
|
+
SHARING_METHOD.FAX,
|
|
235
|
+
SHARING_METHOD.SECURE_PORTAL,
|
|
236
|
+
SHARING_METHOD.PHYSICAL_MAIL,
|
|
237
|
+
SHARING_METHOD.IN_PERSON
|
|
238
|
+
];
|
|
239
|
+
var SHARING_METHOD_LABELS = {
|
|
240
|
+
[SHARING_METHOD.CASE_SHARE]: "CaseShare",
|
|
241
|
+
[SHARING_METHOD.MAGIC_LINK]: "Magic Link",
|
|
242
|
+
[SHARING_METHOD.EMAIL]: "Email",
|
|
243
|
+
[SHARING_METHOD.FAX]: "Fax",
|
|
244
|
+
[SHARING_METHOD.SECURE_PORTAL]: "Secure Portal",
|
|
245
|
+
[SHARING_METHOD.PHYSICAL_MAIL]: "Physical Mail",
|
|
246
|
+
[SHARING_METHOD.IN_PERSON]: "In-Person"
|
|
247
|
+
};
|
|
248
|
+
var ROI_METHOD_MISSINGNESS_KEYS = [
|
|
249
|
+
"missingness_root",
|
|
250
|
+
"unknown",
|
|
251
|
+
"anonymous",
|
|
252
|
+
"data_not_collected"
|
|
253
|
+
];
|
|
254
|
+
var MISSINGNESS = new Set(ROI_METHOD_MISSINGNESS_KEYS);
|
|
255
|
+
var RELEASE_METHOD_VALUES = Object.keys(RoiMethodKeys).filter((key) => !MISSINGNESS.has(key));
|
|
256
|
+
var RELEASE_METHOD = {
|
|
257
|
+
CASESHARE: "thread_caseshare",
|
|
258
|
+
MAGIC_LINK: "thread_magic_link",
|
|
259
|
+
EMAIL: "email",
|
|
260
|
+
FAX: "fax",
|
|
261
|
+
SECURE_PORTAL: "secure_portal",
|
|
262
|
+
IN_PERSON: "in_person"
|
|
263
|
+
};
|
|
264
|
+
var LEGACY_RELEASE_METHOD_ALIASES = {
|
|
265
|
+
[SHARING_METHOD.CASE_SHARE]: RELEASE_METHOD.CASESHARE,
|
|
266
|
+
[SHARING_METHOD.MAGIC_LINK]: RELEASE_METHOD.MAGIC_LINK
|
|
267
|
+
};
|
|
268
|
+
var RETIRED_RELEASE_METHODS = [
|
|
269
|
+
SHARING_METHOD.PHYSICAL_MAIL
|
|
270
|
+
];
|
|
271
|
+
var STORED_RELEASE_METHOD_VALUES = [
|
|
272
|
+
...RELEASE_METHOD_VALUES,
|
|
273
|
+
...Object.keys(LEGACY_RELEASE_METHOD_ALIASES),
|
|
274
|
+
...RETIRED_RELEASE_METHODS
|
|
275
|
+
];
|
|
276
|
+
var RELEASE_METHOD_SET = new Set(RELEASE_METHOD_VALUES);
|
|
277
|
+
function isReleaseMethod(value) {
|
|
278
|
+
return typeof value === "string" && RELEASE_METHOD_SET.has(value);
|
|
279
|
+
}
|
|
280
|
+
function normalizeReleaseMethod(value) {
|
|
281
|
+
const s = String(value);
|
|
282
|
+
return LEGACY_RELEASE_METHOD_ALIASES[s] ?? s;
|
|
283
|
+
}
|
|
284
|
+
function readReleaseMethods(methods) {
|
|
285
|
+
const out = [];
|
|
286
|
+
const unrecognized = [];
|
|
287
|
+
for (const raw of Array.isArray(methods) ? methods : []) {
|
|
288
|
+
const m = normalizeReleaseMethod(raw);
|
|
289
|
+
if (isReleaseMethod(m)) {
|
|
290
|
+
if (!out.includes(m)) out.push(m);
|
|
291
|
+
} else if (!unrecognized.includes(m)) {
|
|
292
|
+
unrecognized.push(m);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return { methods: out, unrecognized };
|
|
296
|
+
}
|
|
297
|
+
function releaseMethodOfShareMethod(method) {
|
|
298
|
+
if (method === void 0 || method === null || method === "") {
|
|
299
|
+
return RELEASE_METHOD.CASESHARE;
|
|
300
|
+
}
|
|
301
|
+
return normalizeReleaseMethod(method);
|
|
302
|
+
}
|
|
303
|
+
function sharingMethodOfReleaseMethod(value) {
|
|
304
|
+
const m = normalizeReleaseMethod(value);
|
|
305
|
+
return Object.entries(LEGACY_RELEASE_METHOD_ALIASES).find(
|
|
306
|
+
([, token]) => token === m
|
|
307
|
+
)?.[0] ?? m;
|
|
308
|
+
}
|
|
309
|
+
function releaseMethodLabel(value) {
|
|
310
|
+
const m = normalizeReleaseMethod(value);
|
|
311
|
+
const share = Object.entries(LEGACY_RELEASE_METHOD_ALIASES).find(
|
|
312
|
+
([, token]) => token === m
|
|
313
|
+
)?.[0] ?? m;
|
|
314
|
+
return SHARING_METHOD_LABELS[share] ?? m;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/shareRules/reportPurposes.ts
|
|
318
|
+
var ROI_WAIVER_EXEMPT_PURPOSES = [
|
|
319
|
+
"mandatory_reporting",
|
|
320
|
+
"authority_reporting"
|
|
321
|
+
];
|
|
322
|
+
var ROI_WAIVER_EXEMPT_PURPOSE_SET = new Set(
|
|
323
|
+
ROI_WAIVER_EXEMPT_PURPOSES
|
|
324
|
+
);
|
|
325
|
+
function isRoiWaiverExemptPurpose(purpose) {
|
|
326
|
+
return purpose !== void 0 && purpose !== null && ROI_WAIVER_EXEMPT_PURPOSE_SET.has(purpose);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/shareRules/magicLinkAddresses.ts
|
|
330
|
+
function derivesOffPlatformRecipient(recipient) {
|
|
331
|
+
return recipient.isSelf !== true && !recipientPlatformFromApps(recipient.apps).recipientOnPlatform;
|
|
332
|
+
}
|
|
333
|
+
var MAGIC_LINK_MAX_ADDRESSES = 25;
|
|
334
|
+
function magicLinkAddresses(...lists) {
|
|
335
|
+
const out = [];
|
|
336
|
+
const seen = /* @__PURE__ */ new Set();
|
|
337
|
+
for (const list of lists) {
|
|
338
|
+
for (const raw of list) {
|
|
339
|
+
const v = (raw ?? "").trim();
|
|
340
|
+
if (v.length === 0) continue;
|
|
341
|
+
const key = v.toLowerCase();
|
|
342
|
+
if (seen.has(key)) continue;
|
|
343
|
+
seen.add(key);
|
|
344
|
+
out.push(v);
|
|
345
|
+
if (out.length >= MAGIC_LINK_MAX_ADDRESSES) return out;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
350
|
+
function magicLinkAddressOverflow(...lists) {
|
|
351
|
+
const seen = /* @__PURE__ */ new Set();
|
|
352
|
+
for (const list of lists) {
|
|
353
|
+
for (const raw of list) {
|
|
354
|
+
const v = (raw ?? "").trim().toLowerCase();
|
|
355
|
+
if (v.length > 0) seen.add(v);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return Math.max(0, seen.size - MAGIC_LINK_MAX_ADDRESSES);
|
|
359
|
+
}
|
|
360
|
+
function magicLinkToText(to, confidentialCount) {
|
|
361
|
+
const v = (to ?? []).join(", ");
|
|
362
|
+
const n = confidentialCount ?? 0;
|
|
363
|
+
const c = n ? n + " confidential recipient" + (n === 1 ? "" : "s") : "";
|
|
364
|
+
return v && c ? v + " + " + c : v || c;
|
|
365
|
+
}
|
|
366
|
+
function magicLinkConfidentialOverflow(visibleCount, confidentialCount) {
|
|
367
|
+
const n = confidentialCount ?? 0;
|
|
368
|
+
return Math.max(0, visibleCount + n - MAGIC_LINK_MAX_ADDRESSES);
|
|
369
|
+
}
|
|
370
|
+
function magicLinkPocHasVisibleAddress(poc) {
|
|
371
|
+
if (!poc) return false;
|
|
372
|
+
return (poc.email ?? "").trim().length > 0 || (poc.contactEmails ?? []).length > 0 || (poc.addedEmails ?? []).length > 0;
|
|
373
|
+
}
|
|
374
|
+
function magicLinkConfidentialOnly(poc) {
|
|
375
|
+
return !magicLinkPocHasVisibleAddress(poc) && (poc?.confidentialCount ?? 0) > 0;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/shareRules/releaseTerms.ts
|
|
379
|
+
var ROI_BASIS_REASON_ROI_ON_FILE = "roi_on_file";
|
|
380
|
+
function isSameAgencySend(input) {
|
|
381
|
+
return input.senderAgencyId.length > 0 && input.senderAgencyId === input.recipientAgencyId;
|
|
382
|
+
}
|
|
383
|
+
var BROKERED_METHODS = /* @__PURE__ */ new Set([
|
|
384
|
+
SHARING_METHOD.CASE_SHARE,
|
|
385
|
+
SHARING_METHOD.MAGIC_LINK
|
|
386
|
+
]);
|
|
387
|
+
function shareMethodOf(method) {
|
|
388
|
+
return method === void 0 || method === null || method === "" ? SHARING_METHOD.CASE_SHARE : String(method);
|
|
389
|
+
}
|
|
390
|
+
function isBrokeredSharingMethod(method) {
|
|
391
|
+
return BROKERED_METHODS.has(shareMethodOf(method));
|
|
392
|
+
}
|
|
393
|
+
function sharingMethodLabel(method) {
|
|
394
|
+
return SHARING_METHOD_LABELS[method] ?? method;
|
|
395
|
+
}
|
|
396
|
+
function releaseListWords(words) {
|
|
397
|
+
if (words.length <= 1) return words.join("");
|
|
398
|
+
return `${words.slice(0, -1).join(", ")} and ${words[words.length - 1]}`;
|
|
399
|
+
}
|
|
400
|
+
function isReleaseTermsExemptRecipient(input) {
|
|
401
|
+
return isSameAgencySend(input);
|
|
402
|
+
}
|
|
403
|
+
function isReleaseMethodExemptPurpose(sharePurpose) {
|
|
404
|
+
return isRoiWaiverExemptPurpose(sharePurpose);
|
|
405
|
+
}
|
|
406
|
+
function operativeReleaseOf(input) {
|
|
407
|
+
if (input.release === null || input.release === void 0) return void 0;
|
|
408
|
+
if (input.roiBasis.reason !== ROI_BASIS_REASON_ROI_ON_FILE) return void 0;
|
|
409
|
+
if (isReleaseTermsExemptRecipient({
|
|
410
|
+
senderAgencyId: input.senderAgencyId,
|
|
411
|
+
recipientAgencyId: input.recipientAgencyId
|
|
412
|
+
})) {
|
|
413
|
+
return void 0;
|
|
414
|
+
}
|
|
415
|
+
return input.release;
|
|
416
|
+
}
|
|
417
|
+
function releaseListedMethods(release) {
|
|
418
|
+
const raw = release?.approvedSharingMethods;
|
|
419
|
+
if (!Array.isArray(raw)) return null;
|
|
420
|
+
const listed = [];
|
|
421
|
+
for (const entry of raw) {
|
|
422
|
+
const m = sharingMethodOfReleaseMethod(entry);
|
|
423
|
+
if (!listed.includes(m)) listed.push(m);
|
|
424
|
+
}
|
|
425
|
+
return listed.length === 0 ? null : listed;
|
|
426
|
+
}
|
|
427
|
+
function releaseMethodRefusal(input) {
|
|
428
|
+
const { release } = input;
|
|
429
|
+
if (release === void 0) return null;
|
|
430
|
+
if (isReleaseMethodExemptPurpose(input.sharePurpose)) return null;
|
|
431
|
+
const listed = releaseListedMethods(release);
|
|
432
|
+
if (listed === null) return null;
|
|
433
|
+
const method = shareMethodOf(input.method);
|
|
434
|
+
if (listed.includes(method)) return null;
|
|
435
|
+
const want = sharingMethodLabel(method);
|
|
436
|
+
return `The client's release for this recipient doesn't allow sending by ${want} \u2014 the client agreed to ${releaseListWords(listed.map(sharingMethodLabel))}. Nothing was sent. To send by ${want}, add it to the release by renewing it, or choose one of the methods it lists.`;
|
|
437
|
+
}
|
|
438
|
+
var asDate = (v) => {
|
|
439
|
+
if (v === void 0 || v === null || v === "") return null;
|
|
440
|
+
const d = new Date(v);
|
|
441
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
442
|
+
};
|
|
443
|
+
var utcCalendarDay = (d) => d.toISOString().slice(0, 10);
|
|
444
|
+
function endOfUtcDay(d) {
|
|
445
|
+
return /* @__PURE__ */ new Date(`${utcCalendarDay(d)}T23:59:59.999Z`);
|
|
446
|
+
}
|
|
447
|
+
function releaseEndOfDay(release) {
|
|
448
|
+
const end = asDate(release?.expirationDate);
|
|
449
|
+
return end === null ? null : endOfUtcDay(end);
|
|
450
|
+
}
|
|
451
|
+
function releaseEndDay(release) {
|
|
452
|
+
const end = releaseEndOfDay(release);
|
|
453
|
+
return end === null ? null : utcCalendarDay(end);
|
|
454
|
+
}
|
|
455
|
+
function shareExpiryUnderRelease(input) {
|
|
456
|
+
const noTimeLimit = input.noTimeLimit === true;
|
|
457
|
+
const own = noTimeLimit ? null : asDate(input.expirationDate);
|
|
458
|
+
const unbounded = {
|
|
459
|
+
kind: "ok",
|
|
460
|
+
expirationDate: own,
|
|
461
|
+
noTimeLimit,
|
|
462
|
+
fromRelease: false,
|
|
463
|
+
releaseEnd: null
|
|
464
|
+
};
|
|
465
|
+
if (!isBrokeredSharingMethod(input.method)) return unbounded;
|
|
466
|
+
const releaseEnd = releaseEndOfDay(input.release);
|
|
467
|
+
if (releaseEnd === null) return unbounded;
|
|
468
|
+
if (own === null) {
|
|
469
|
+
return {
|
|
470
|
+
kind: "ok",
|
|
471
|
+
expirationDate: releaseEnd,
|
|
472
|
+
noTimeLimit: false,
|
|
473
|
+
fromRelease: true,
|
|
474
|
+
releaseEnd
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
const shareDay = utcCalendarDay(own);
|
|
478
|
+
const releaseDay = utcCalendarDay(releaseEnd);
|
|
479
|
+
if (shareDay > releaseDay) {
|
|
480
|
+
return {
|
|
481
|
+
kind: "refused",
|
|
482
|
+
shareDay,
|
|
483
|
+
releaseDay,
|
|
484
|
+
message: `This share would end on ${shareDay}, after the client's release for this recipient ends (${releaseDay}). A share never outlives its release. Nothing was sent. Pick an end date on or before the release's, or leave it blank to end with the release.`
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
return { ...unbounded, releaseEnd };
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/shareRules/caseShareLane.ts
|
|
491
|
+
var CASE_SHARE_LANE = { THREAD: "thread", PAVE: "pave" };
|
|
492
|
+
var CASE_SHARE_LANE_FAILURE = {
|
|
493
|
+
MISMATCH: "case_share_lane_mismatch",
|
|
494
|
+
TEAM_UNAVAILABLE: "case_share_team_unavailable",
|
|
495
|
+
UNVERIFIED: "case_share_lane_unverified"
|
|
496
|
+
};
|
|
497
|
+
function recipientSubject(name) {
|
|
498
|
+
return name !== void 0 && name.trim().length > 0 ? name : "The recipient";
|
|
499
|
+
}
|
|
500
|
+
function recipientObject(name) {
|
|
501
|
+
return name !== void 0 && name.trim().length > 0 ? name : "the recipient";
|
|
502
|
+
}
|
|
503
|
+
function teamSubject(team) {
|
|
504
|
+
return team.name.trim().length > 0 ? `The team "${team.name}"` : "The receiving team";
|
|
505
|
+
}
|
|
506
|
+
function caseShareStaleTeamFailure(name) {
|
|
507
|
+
return {
|
|
508
|
+
code: CASE_SHARE_LANE_FAILURE.TEAM_UNAVAILABLE,
|
|
509
|
+
message: `The team you chose at ${recipientObject(name)} is no longer available \u2014 choose the team again.`
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
function caseShareLaneUnverified(name) {
|
|
513
|
+
return {
|
|
514
|
+
code: CASE_SHARE_LANE_FAILURE.UNVERIFIED,
|
|
515
|
+
message: `Thread could not read how ${recipientObject(name)} receives CaseShares, so the share was not sent. Try again in a few minutes.`
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
function leadsOnly(agencyApps) {
|
|
519
|
+
return recipientUsesApp(agencyApps, PLATFORM_TOOL.LEADS) && !recipientUsesApp(agencyApps, PLATFORM_TOOL.THREAD) && !recipientUsesApp(agencyApps, PLATFORM_TOOL.PAVE);
|
|
520
|
+
}
|
|
521
|
+
function caseShareLandingNeedsAgencyApps(team) {
|
|
522
|
+
if (team === "stale" || team === "unverified") return false;
|
|
523
|
+
return team === null || teamLandingApp(team.apps ?? void 0) === void 0;
|
|
524
|
+
}
|
|
525
|
+
function pickDefaultShareTeam(teams, configuredDefaultShareTeamId, inApp) {
|
|
526
|
+
if (teams.length === 0) return null;
|
|
527
|
+
if (configuredDefaultShareTeamId !== null) {
|
|
528
|
+
const configured = teams.find(
|
|
529
|
+
(t) => agencyIdKey(t.id) === agencyIdKey(configuredDefaultShareTeamId)
|
|
530
|
+
);
|
|
531
|
+
if (configured) return { team: configured, via: "configured" };
|
|
532
|
+
}
|
|
533
|
+
const declared = teams.filter((t) => t.defaultTeam === true);
|
|
534
|
+
if (declared.length === 1) {
|
|
535
|
+
return { team: declared[0], via: "account_declared" };
|
|
536
|
+
}
|
|
537
|
+
if (teams.length === 1) return { team: teams[0], via: "auto_single" };
|
|
538
|
+
const app = inApp ? teams.filter(inApp) : [];
|
|
539
|
+
if (app.length === 1) return { team: app[0], via: "auto_single_in_app" };
|
|
540
|
+
const pool = [...app.length > 0 ? app : teams].sort(
|
|
541
|
+
(a, b) => a.id.localeCompare(b.id)
|
|
542
|
+
);
|
|
543
|
+
return {
|
|
544
|
+
team: pool[0],
|
|
545
|
+
via: app.length > 0 ? "first_in_app" : "first_team"
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function caseShareLandingLane(recipient) {
|
|
549
|
+
const { team, name } = recipient;
|
|
550
|
+
if (team === "unverified") {
|
|
551
|
+
return { ok: false, ...caseShareLaneUnverified(name) };
|
|
552
|
+
}
|
|
553
|
+
if (team === "stale") {
|
|
554
|
+
return { ok: false, ...caseShareStaleTeamFailure(name) };
|
|
555
|
+
}
|
|
556
|
+
const apps = team?.apps ?? void 0;
|
|
557
|
+
if (teamLandsInThread(apps)) {
|
|
558
|
+
return { ok: true, lane: CASE_SHARE_LANE.THREAD, team };
|
|
559
|
+
}
|
|
560
|
+
if (teamLandsInPave(apps)) {
|
|
561
|
+
return { ok: true, lane: CASE_SHARE_LANE.PAVE, team };
|
|
562
|
+
}
|
|
563
|
+
if (teamLandingApp(apps) === PLATFORM_TOOL.LEADS) {
|
|
564
|
+
return { ok: true, lane: CASE_SHARE_LANE.THREAD, team };
|
|
565
|
+
}
|
|
566
|
+
if (caseShareLandingNeedsAgencyApps(team)) {
|
|
567
|
+
if (recipient.agencyAppsUnread === true) {
|
|
568
|
+
return { ok: false, ...caseShareLaneUnverified(name) };
|
|
569
|
+
}
|
|
570
|
+
if (leadsOnly(recipient.agencyApps)) {
|
|
571
|
+
return { ok: true, lane: CASE_SHARE_LANE.THREAD, team };
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return { ok: true, lane: CASE_SHARE_LANE.PAVE, team };
|
|
575
|
+
}
|
|
576
|
+
function caseShareLaneMismatch(recipient, landing, claimed) {
|
|
577
|
+
if (landing === claimed) return null;
|
|
578
|
+
const app = landing === CASE_SHARE_LANE.THREAD ? "Thread" : "PAVE";
|
|
579
|
+
const who = recipient.team !== null ? `${teamSubject(recipient.team)} at ${recipientObject(recipient.name)}` : recipientSubject(recipient.name);
|
|
580
|
+
return {
|
|
581
|
+
code: CASE_SHARE_LANE_FAILURE.MISMATCH,
|
|
582
|
+
message: `${who} receives CaseShares in ${app}, so this share was not sent as it was composed \u2014 compose it again.`
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/shareRules/senderRoiPosture.ts
|
|
587
|
+
function vspReleasePosture(affirmed) {
|
|
588
|
+
return affirmed === false ? "waived" : "required";
|
|
589
|
+
}
|
|
590
|
+
var AUTHORED_ROI_POSTURE_FIELD = "roiPolicy";
|
|
591
|
+
var ABSENT_AUTHORED_ROI_POSTURE = {
|
|
592
|
+
present: false,
|
|
593
|
+
agencyDefault: null,
|
|
594
|
+
requiredTeamKeys: [],
|
|
595
|
+
issues: []
|
|
596
|
+
};
|
|
597
|
+
function isPlainObject(value) {
|
|
598
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
|
|
599
|
+
}
|
|
600
|
+
function readAuthoredRoiPosture(raw) {
|
|
601
|
+
if (raw === void 0 || raw === null) return ABSENT_AUTHORED_ROI_POSTURE;
|
|
602
|
+
if (!isPlainObject(raw)) {
|
|
603
|
+
return {
|
|
604
|
+
present: true,
|
|
605
|
+
agencyDefault: null,
|
|
606
|
+
requiredTeamKeys: [],
|
|
607
|
+
issues: ["roi_policy_not_object"]
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
const issues = [];
|
|
611
|
+
const def = raw.agencyDefault;
|
|
612
|
+
let agencyDefault = null;
|
|
613
|
+
if (def === "required" || def === "waived") agencyDefault = def;
|
|
614
|
+
else if (def !== void 0 && def !== null) {
|
|
615
|
+
issues.push("agency_default_invalid");
|
|
616
|
+
}
|
|
617
|
+
const requiredTeamKeys = [];
|
|
618
|
+
const overrides = raw.teamOverrides;
|
|
619
|
+
if (overrides !== void 0 && overrides !== null) {
|
|
620
|
+
if (!isPlainObject(overrides)) {
|
|
621
|
+
issues.push("team_overrides_not_object");
|
|
622
|
+
} else {
|
|
623
|
+
let invalidTeamValue = false;
|
|
624
|
+
for (const [teamKey, value] of Object.entries(overrides)) {
|
|
625
|
+
if (value === "required") requiredTeamKeys.push(teamKey);
|
|
626
|
+
else invalidTeamValue = true;
|
|
627
|
+
}
|
|
628
|
+
if (invalidTeamValue) issues.push("team_override_value_invalid");
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return { present: true, agencyDefault, requiredTeamKeys, issues };
|
|
632
|
+
}
|
|
633
|
+
function resolveAgencyRoiPosture(input) {
|
|
634
|
+
const derivedDefault = vspReleasePosture(input.affirmedVsp);
|
|
635
|
+
const authored = input.authored.agencyDefault;
|
|
636
|
+
if (authored !== null) {
|
|
637
|
+
return {
|
|
638
|
+
posture: authored,
|
|
639
|
+
required: authored === "required",
|
|
640
|
+
source: "authored",
|
|
641
|
+
derivedDefault,
|
|
642
|
+
rulePath: `agencies.roiPolicy.agencyDefault=${authored} (Consent & ROI)`
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
return {
|
|
646
|
+
posture: derivedDefault,
|
|
647
|
+
required: derivedDefault === "required",
|
|
648
|
+
source: "derived_vsp",
|
|
649
|
+
derivedDefault,
|
|
650
|
+
rulePath: `agencies.vsp=${input.affirmedVsp === null ? "null (never captured)" : String(input.affirmedVsp)} \u2192 ${derivedDefault}`
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
function senderRoiPostureForTeam(view, sendingTeamId) {
|
|
654
|
+
if (view.agency.posture === "waived" && typeof sendingTeamId === "string" && sendingTeamId.length > 0 && view.tightenedTeamIds.includes(sendingTeamId)) {
|
|
655
|
+
return {
|
|
656
|
+
...view.agency,
|
|
657
|
+
posture: "required",
|
|
658
|
+
required: true,
|
|
659
|
+
source: "team_override",
|
|
660
|
+
rulePath: `agencies.roiPolicy.teamOverrides[${sendingTeamId}]=required (teams tighten, never relax)`
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
return view.agency;
|
|
664
|
+
}
|
|
665
|
+
function resolveSenderRoiPosture(input) {
|
|
666
|
+
return senderRoiPostureForTeam(
|
|
667
|
+
{
|
|
668
|
+
agency: resolveAgencyRoiPosture(input),
|
|
669
|
+
tightenedTeamIds: input.authored.requiredTeamKeys
|
|
670
|
+
},
|
|
671
|
+
input.sendingTeamId
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
export {
|
|
675
|
+
ABSENT_AUTHORED_ROI_POSTURE,
|
|
676
|
+
AUTHORED_ROI_POSTURE_FIELD,
|
|
677
|
+
CASE_SHARE_LANE,
|
|
678
|
+
CASE_SHARE_LANE_FAILURE,
|
|
679
|
+
LEGACY_RELEASE_METHOD_ALIASES,
|
|
680
|
+
MAGIC_LINK_MAX_ADDRESSES,
|
|
681
|
+
RELEASE_METHOD,
|
|
682
|
+
RELEASE_METHOD_VALUES,
|
|
683
|
+
RETIRED_RELEASE_METHODS,
|
|
684
|
+
ROI_BASIS_REASON_ROI_ON_FILE,
|
|
685
|
+
ROI_WAIVER_EXEMPT_PURPOSES,
|
|
686
|
+
SHARING_METHOD,
|
|
687
|
+
SHARING_METHOD_LABELS,
|
|
688
|
+
SHARING_METHOD_VALUES,
|
|
689
|
+
STORED_RELEASE_METHOD_VALUES,
|
|
690
|
+
agencyIdKey,
|
|
691
|
+
caseShareLandingLane,
|
|
692
|
+
caseShareLandingNeedsAgencyApps,
|
|
693
|
+
caseShareLaneMismatch,
|
|
694
|
+
caseShareLaneUnverified,
|
|
695
|
+
caseShareStaleTeamFailure,
|
|
696
|
+
derivesOffPlatformRecipient,
|
|
697
|
+
endOfUtcDay,
|
|
698
|
+
isBrokeredSharingMethod,
|
|
699
|
+
isReleaseMethod,
|
|
700
|
+
isReleaseMethodExemptPurpose,
|
|
701
|
+
isReleaseTermsExemptRecipient,
|
|
702
|
+
isRoiWaiverExemptPurpose,
|
|
703
|
+
magicLinkAddressOverflow,
|
|
704
|
+
magicLinkAddresses,
|
|
705
|
+
magicLinkConfidentialOnly,
|
|
706
|
+
magicLinkConfidentialOverflow,
|
|
707
|
+
magicLinkPocHasVisibleAddress,
|
|
708
|
+
magicLinkToText,
|
|
709
|
+
normalizeReleaseMethod,
|
|
710
|
+
operativeReleaseOf,
|
|
711
|
+
pickDefaultShareTeam,
|
|
712
|
+
readAuthoredRoiPosture,
|
|
713
|
+
readReleaseMethods,
|
|
714
|
+
recipientPlatformFromApps,
|
|
715
|
+
recipientUsesApp,
|
|
716
|
+
releaseEndDay,
|
|
717
|
+
releaseEndOfDay,
|
|
718
|
+
releaseListWords,
|
|
719
|
+
releaseListedMethods,
|
|
720
|
+
releaseMethodLabel,
|
|
721
|
+
releaseMethodOfShareMethod,
|
|
722
|
+
releaseMethodRefusal,
|
|
723
|
+
resolveAgencyRoiPosture,
|
|
724
|
+
resolveSenderRoiPosture,
|
|
725
|
+
senderRoiPostureForTeam,
|
|
726
|
+
shareExpiryUnderRelease,
|
|
727
|
+
shareMethodOf,
|
|
728
|
+
sharingMethodLabel,
|
|
729
|
+
sharingMethodOfReleaseMethod,
|
|
730
|
+
teamLandingApp,
|
|
731
|
+
teamLandsInPave,
|
|
732
|
+
teamLandsInThread,
|
|
733
|
+
utcCalendarDay,
|
|
734
|
+
vspReleasePosture
|
|
735
|
+
};
|
|
736
|
+
//# sourceMappingURL=index.js.map
|