@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,353 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sharing-ceiling readers lifted from Thread in 0.41.0 —
|
|
3
|
+
* `shareDefaultScopeFor` (alias `accountSharePurposePolicy`),
|
|
4
|
+
* `isPermittedByCeiling` and `intersectSharingCeilingLists`.
|
|
5
|
+
*
|
|
6
|
+
* Ported from Thread `@thread/shared` @ thread develop f021be2, adapted only
|
|
7
|
+
* for import paths and the injected tree:
|
|
8
|
+
* - `src/__tests__/sharingCeiling.test.ts` L459-L577 (the
|
|
9
|
+
* `isPermittedByCeiling` / `intersectSharingCeilingLists` cases and the
|
|
10
|
+
* `accountSharePurposePolicy` block). Thread's
|
|
11
|
+
* `sharingCeilingEditsFromCells` is a pass-through of this package's
|
|
12
|
+
* `sharingScopeEditsFromCells`; `SHARE_PURPOSE.*` are the CVC-84 key
|
|
13
|
+
* literals. NOT ported: the `findSharingCeilingViolations` case and the
|
|
14
|
+
* "every share unit the composer keys a box by" case — they read Thread's
|
|
15
|
+
* door wrapper and Thread's picker list (`HTI_SHARE_SCOPE_PICKER_ITEM_IDS`)
|
|
16
|
+
* and stay in Thread's suite, run there against the re-export.
|
|
17
|
+
* - `src/__tests__/ceilingCoverageInvariant.test.ts` — the properties that
|
|
18
|
+
* read only package functions plus the two lifted readers. Thread's door
|
|
19
|
+
* (`findSharingCeilingViolations(c, { informationScope: L }) === null`) is
|
|
20
|
+
* `rowsOverCeiling(scope, L, c.allowed)` returning `[]` (Thread
|
|
21
|
+
* `sharingCeiling.ts` L496-L509 wraps exactly that); the composer-picker
|
|
22
|
+
* properties (`toggleScopeRow` / `effectiveScopeSelection`) are Thread's
|
|
23
|
+
* and stay there.
|
|
24
|
+
*
|
|
25
|
+
* Thread's `INFORMATION_SCOPE_RESOLVER` is this package's resolver bound to
|
|
26
|
+
* `coreInformationScopeSot` — built the same way here.
|
|
27
|
+
*/
|
|
28
|
+
import { describe, expect, it } from "vitest";
|
|
29
|
+
|
|
30
|
+
import { coreInformationScopeSot } from "../../cvcs/index.js";
|
|
31
|
+
import {
|
|
32
|
+
createInformationScopeResolver,
|
|
33
|
+
scopeMigrationsFromSot,
|
|
34
|
+
scopeRowsFromSot,
|
|
35
|
+
type CoreInformationScopeSot,
|
|
36
|
+
} from "../../services/informationScope.js";
|
|
37
|
+
import {
|
|
38
|
+
HTI_SHARE_PLATFORM_STARTER,
|
|
39
|
+
accountSharePurposePolicy,
|
|
40
|
+
hasOwnScopeContent,
|
|
41
|
+
intersectSharingCeilingLists as intersectIn,
|
|
42
|
+
isPermittedByCeiling as permittedIn,
|
|
43
|
+
maskSelectionToCeiling,
|
|
44
|
+
rowsOverCeiling,
|
|
45
|
+
scopeRowWithinCeiling,
|
|
46
|
+
shareDefaultScopeFor,
|
|
47
|
+
sharingScopeEditsFromCells as sharingCeilingEditsFromCells,
|
|
48
|
+
type SharingScopeCeiling,
|
|
49
|
+
} from "../index.js";
|
|
50
|
+
import * as root from "../../index.js";
|
|
51
|
+
|
|
52
|
+
const sot = coreInformationScopeSot as CoreInformationScopeSot;
|
|
53
|
+
const scope = createInformationScopeResolver({
|
|
54
|
+
rows: scopeRowsFromSot(sot),
|
|
55
|
+
migrations: scopeMigrationsFromSot(sot),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/** Thread's two-argument forms, bound to the tree as Thread binds its own. */
|
|
59
|
+
const isPermittedByCeiling = (
|
|
60
|
+
ceiling: SharingScopeCeiling | null,
|
|
61
|
+
code: string,
|
|
62
|
+
): boolean => permittedIn(scope, ceiling, code);
|
|
63
|
+
const intersectSharingCeilingLists = (
|
|
64
|
+
a: ReadonlySet<string> | readonly string[],
|
|
65
|
+
b: ReadonlySet<string> | readonly string[],
|
|
66
|
+
): string[] => intersectIn(scope, a, b);
|
|
67
|
+
|
|
68
|
+
const SENDER = "aaaaaaaaaaaaaaaaaaaaaaaa";
|
|
69
|
+
const PARTNER = "bbbbbbbbbbbbbbbbbbbbbbbb";
|
|
70
|
+
const SCOPE_SYSTEM_INFO = "system_info";
|
|
71
|
+
const SHARE_PURPOSE = {
|
|
72
|
+
REFERRAL: "referral",
|
|
73
|
+
RECORDS_REQUEST: "records_request",
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
/** A stored ceiling cell, as the platform writes it. */
|
|
77
|
+
const cell = (
|
|
78
|
+
rowKey: string,
|
|
79
|
+
purpose: string,
|
|
80
|
+
informationScope: unknown,
|
|
81
|
+
scopeVersion: unknown = 4,
|
|
82
|
+
) => ({ agencyId: SENDER, rowKey, purpose, scopeVersion, informationScope });
|
|
83
|
+
|
|
84
|
+
const PLATFORM_REFERRAL = [
|
|
85
|
+
...HTI_SHARE_PLATFORM_STARTER.scopeByPurpose[SHARE_PURPOSE.REFERRAL]!,
|
|
86
|
+
].sort();
|
|
87
|
+
|
|
88
|
+
describe("the alias", () => {
|
|
89
|
+
it("accountSharePurposePolicy is shareDefaultScopeFor (the same function)", () => {
|
|
90
|
+
expect(accountSharePurposePolicy).toBe(shareDefaultScopeFor);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("both names, and the coverage readers, ride the package root too", () => {
|
|
94
|
+
expect(root.shareDefaultScopeFor).toBe(shareDefaultScopeFor);
|
|
95
|
+
expect(root.accountSharePurposePolicy).toBe(shareDefaultScopeFor);
|
|
96
|
+
expect(root.isPermittedByCeiling).toBe(permittedIn);
|
|
97
|
+
expect(root.intersectSharingCeilingLists).toBe(intersectIn);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// ─── The ONE scope-enforcement rule (the package's) ────────────────────────
|
|
102
|
+
|
|
103
|
+
describe("isPermittedByCeiling — the package's coverage rule", () => {
|
|
104
|
+
const ceiling = { allowed: new Set(["identifying", "case_notes"]) };
|
|
105
|
+
|
|
106
|
+
it("permits a listed row and every row beneath one; a child never covers its parent", () => {
|
|
107
|
+
expect(isPermittedByCeiling(ceiling, "names")).toBe(true);
|
|
108
|
+
expect(isPermittedByCeiling(ceiling, "identifying.other")).toBe(true);
|
|
109
|
+
expect(isPermittedByCeiling(ceiling, "contact_info")).toBe(false);
|
|
110
|
+
expect(isPermittedByCeiling(ceiling, "notes")).toBe(false);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("exempts System metadata; fails closed off the tree; no ceiling permits everything", () => {
|
|
114
|
+
expect(isPermittedByCeiling(ceiling, "system_info")).toBe(true);
|
|
115
|
+
expect(isPermittedByCeiling(ceiling, "not_a_row")).toBe(false);
|
|
116
|
+
expect(isPermittedByCeiling(null, "hiv_status")).toBe(true);
|
|
117
|
+
expect(isPermittedByCeiling({ allowed: null }, "offenders")).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("STRICT rule 2: a row with content of its own is within only when it or an ancestor is listed", () => {
|
|
121
|
+
// `instruments` carries fields homed on it and has no rest row: listing
|
|
122
|
+
// every instrument row beneath it never carries its own fields.
|
|
123
|
+
const summaries = { allowed: ["instrument_summary", "instrument_full"] };
|
|
124
|
+
expect(isPermittedByCeiling(summaries, "instruments")).toBe(false);
|
|
125
|
+
expect(isPermittedByCeiling(summaries, "summary_lap")).toBe(true);
|
|
126
|
+
// A row with a rest row keeps rule 2: every child of `identifying`.
|
|
127
|
+
const children = {
|
|
128
|
+
allowed: [
|
|
129
|
+
"names",
|
|
130
|
+
"dob",
|
|
131
|
+
"addresses",
|
|
132
|
+
"additional_ids",
|
|
133
|
+
"demographics",
|
|
134
|
+
"identifying.other",
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
expect(isPermittedByCeiling(children, "identifying")).toBe(true);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("intersectSharingCeilingLists keeps the deeper covering row of each pair", () => {
|
|
141
|
+
expect(
|
|
142
|
+
intersectSharingCeilingLists(
|
|
143
|
+
["identifying", "notes"],
|
|
144
|
+
["names", "dob", "contact_info", "notes"],
|
|
145
|
+
).sort(),
|
|
146
|
+
).toEqual(["dob", "names", "notes"]);
|
|
147
|
+
expect(
|
|
148
|
+
intersectSharingCeilingLists(["identifying.other"], ["names"]),
|
|
149
|
+
).toEqual([]);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("accountSharePurposePolicy — the account's standing per purpose (C12b)", () => {
|
|
154
|
+
it("the authored `__default__` cell is the account default; a partner cell never is", () => {
|
|
155
|
+
const edits = sharingCeilingEditsFromCells([
|
|
156
|
+
cell(PARTNER, "referral", ["names"]),
|
|
157
|
+
cell("__default__", "referral", ["identifying", "notes"]),
|
|
158
|
+
]);
|
|
159
|
+
expect(accountSharePurposePolicy(edits, "referral")).toEqual({
|
|
160
|
+
off: false,
|
|
161
|
+
accountDefault: ["identifying", "notes"],
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("falls to the platform default when the account authored none", () => {
|
|
166
|
+
const edits = sharingCeilingEditsFromCells([]);
|
|
167
|
+
const p = accountSharePurposePolicy(edits, SHARE_PURPOSE.REFERRAL);
|
|
168
|
+
expect(p.off).toBe(false);
|
|
169
|
+
expect([...p.accountDefault].sort()).toEqual(PLATFORM_REFERRAL);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("a purpose the platform ships off is `off` with nothing; the account may switch it on", () => {
|
|
173
|
+
const edits = sharingCeilingEditsFromCells([]);
|
|
174
|
+
expect(
|
|
175
|
+
accountSharePurposePolicy(edits, SHARE_PURPOSE.RECORDS_REQUEST),
|
|
176
|
+
).toEqual({ off: true, accountDefault: [] });
|
|
177
|
+
const on = accountSharePurposePolicy(edits, SHARE_PURPOSE.RECORDS_REQUEST, {
|
|
178
|
+
purposeOverrides: { records_request: true },
|
|
179
|
+
});
|
|
180
|
+
expect(on.off).toBe(false);
|
|
181
|
+
const switchedOff = accountSharePurposePolicy(
|
|
182
|
+
edits,
|
|
183
|
+
SHARE_PURPOSE.REFERRAL,
|
|
184
|
+
{
|
|
185
|
+
purposeOverrides: { referral: false },
|
|
186
|
+
},
|
|
187
|
+
);
|
|
188
|
+
expect(switchedOff).toEqual({ off: true, accountDefault: [] });
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("an unreadable store answers nothing, fail closed, with the purpose still on", () => {
|
|
192
|
+
expect(accountSharePurposePolicy(null, SHARE_PURPOSE.REFERRAL)).toEqual({
|
|
193
|
+
off: false,
|
|
194
|
+
accountDefault: [],
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// ─── Ported from Thread ceilingCoverageInvariant.test.ts ────────────────────
|
|
200
|
+
|
|
201
|
+
const isLive = (c: string) =>
|
|
202
|
+
scope.row(c) !== undefined &&
|
|
203
|
+
scope.ancestorsOf(c).every((a) => scope.row(a)?.status !== "retired");
|
|
204
|
+
const LIVE = scope.rows.map((r) => r.scopeCode).filter(isLive);
|
|
205
|
+
const isSystem = (c: string) => scope.ancestorsOf(c).includes("system");
|
|
206
|
+
const underFloor = (c: string) =>
|
|
207
|
+
scope.ancestorsOf(c).some((a) => scope.row(a)?.platformFloor === true);
|
|
208
|
+
/** The rows the coverage rule requires of a parent. */
|
|
209
|
+
const coverageChildren = (c: string) =>
|
|
210
|
+
scope
|
|
211
|
+
.childrenOf(c)
|
|
212
|
+
.filter((k) => isLive(k) && !isSystem(k) && !underFloor(k));
|
|
213
|
+
const within = (list: readonly string[], c: string) =>
|
|
214
|
+
scopeRowWithinCeiling(scope, list, c);
|
|
215
|
+
/** Thread's door, `findSharingCeilingViolations(...) === null`. */
|
|
216
|
+
const doorAccepts = (allowed: Iterable<string>, declared: readonly string[]) =>
|
|
217
|
+
rowsOverCeiling(scope, declared, [...allowed]).length === 0;
|
|
218
|
+
|
|
219
|
+
/** A small deterministic PRNG (mulberry32) — the generated set is stable. */
|
|
220
|
+
function rng(seed: number): () => number {
|
|
221
|
+
let a = seed;
|
|
222
|
+
return () => {
|
|
223
|
+
a |= 0;
|
|
224
|
+
a = (a + 0x6d2b79f5) | 0;
|
|
225
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
226
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
227
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function generatedCeilings(): { name: string; list: string[] }[] {
|
|
232
|
+
const out: { name: string; list: string[] }[] = [{ name: "empty", list: [] }];
|
|
233
|
+
const parents = LIVE.filter(
|
|
234
|
+
(c) => !isSystem(c) && coverageChildren(c).length > 0,
|
|
235
|
+
);
|
|
236
|
+
for (const p of parents) {
|
|
237
|
+
out.push({ name: `only ${p}`, list: [p] });
|
|
238
|
+
const kids = coverageChildren(p);
|
|
239
|
+
out.push({ name: `children-only of ${p}`, list: kids });
|
|
240
|
+
if (kids.length > 1) {
|
|
241
|
+
out.push({
|
|
242
|
+
name: `children-only of ${p} minus one`,
|
|
243
|
+
list: kids.slice(1),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
// Grandchildren-only: every coverage leaf beneath p, nothing above.
|
|
247
|
+
const leaves: string[] = [];
|
|
248
|
+
const walk = (c: string) => {
|
|
249
|
+
const ks = coverageChildren(c);
|
|
250
|
+
if (ks.length === 0) leaves.push(c);
|
|
251
|
+
else ks.forEach(walk);
|
|
252
|
+
};
|
|
253
|
+
walk(p);
|
|
254
|
+
out.push({ name: `leaves-only of ${p}`, list: leaves });
|
|
255
|
+
}
|
|
256
|
+
const pool = LIVE.filter((c) => !isSystem(c));
|
|
257
|
+
const next = rng(0x5eed);
|
|
258
|
+
for (let i = 0; i < 60; i += 1) {
|
|
259
|
+
const n = 1 + Math.floor(next() * 8);
|
|
260
|
+
const list = new Set<string>();
|
|
261
|
+
while (list.size < n) list.add(pool[Math.floor(next() * pool.length)]!);
|
|
262
|
+
out.push({ name: `random #${i}`, list: [...list] });
|
|
263
|
+
}
|
|
264
|
+
return out;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const CEILINGS = generatedCeilings();
|
|
268
|
+
|
|
269
|
+
describe("children-only ceilings — isPermittedByCeiling, strict rule 2 included", () => {
|
|
270
|
+
it.each(["identifying", "notes", "offenders"])(
|
|
271
|
+
"every coverage child of %s listed (the parent not): within exactly when %s carries no content of its own",
|
|
272
|
+
(parent) => {
|
|
273
|
+
const list = coverageChildren(parent);
|
|
274
|
+
expect(list.length).toBeGreaterThan(0);
|
|
275
|
+
expect(list).not.toContain(parent);
|
|
276
|
+
const expected = !hasOwnScopeContent(scope, parent);
|
|
277
|
+
expect(within(list, parent)).toBe(expected);
|
|
278
|
+
expect(isPermittedByCeiling({ allowed: list }, parent)).toBe(expected);
|
|
279
|
+
expect(doorAccepts(list, [SCOPE_SYSTEM_INFO, parent])).toBe(expected);
|
|
280
|
+
},
|
|
281
|
+
);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe(`property: isPermittedByCeiling agrees with the door, for every live row × ${CEILINGS.length} generated ceilings`, () => {
|
|
285
|
+
it("isPermittedByCeiling ⇔ the server door accepts the row alone", () => {
|
|
286
|
+
for (const { name, list } of CEILINGS) {
|
|
287
|
+
const ceiling = { allowed: new Set(list) };
|
|
288
|
+
for (const r of LIVE) {
|
|
289
|
+
if (isSystem(r) || underFloor(r)) continue;
|
|
290
|
+
expect(isPermittedByCeiling(ceiling, r), `${name}: ${r}`).toBe(
|
|
291
|
+
doorAccepts(ceiling.allowed, [r]),
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
// Thread th-v2sf1 review — the composer offers ONE selection for every
|
|
299
|
+
// selected recipient, masked to the INTERSECTION of their ceilings; each
|
|
300
|
+
// recipient's door then judges that selection against ITS OWN list. So the
|
|
301
|
+
// masked list must be accepted by BOTH lists, for every pair.
|
|
302
|
+
const PAIRS: { name: string; a: string[]; b: string[] }[] = (() => {
|
|
303
|
+
const out: { name: string; a: string[]; b: string[] }[] = [];
|
|
304
|
+
const n = CEILINGS.length;
|
|
305
|
+
for (let i = 0; i < n; i += 1) {
|
|
306
|
+
for (const stride of [1, 7, 31, Math.floor(n / 2)]) {
|
|
307
|
+
const j = (i + stride) % n;
|
|
308
|
+
if (j === i) continue;
|
|
309
|
+
const a = CEILINGS[i]!;
|
|
310
|
+
const b = CEILINGS[j]!;
|
|
311
|
+
out.push({ name: `${a.name} ∩ ${b.name}`, a: a.list, b: b.list });
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
})();
|
|
316
|
+
|
|
317
|
+
describe(`property: masking to intersectSharingCeilingLists(a, b) is accepted by both a and b (${PAIRS.length} pairs)`, () => {
|
|
318
|
+
it("the package's mask of any single live row, to the intersection, passes both doors", () => {
|
|
319
|
+
// Every eighth pair × every live row keeps this bounded and still walks
|
|
320
|
+
// every row under every ceiling shape.
|
|
321
|
+
for (const { name, a, b } of PAIRS.filter((_, i) => i % 8 === 0)) {
|
|
322
|
+
const both = intersectSharingCeilingLists(a, b);
|
|
323
|
+
for (const r of LIVE) {
|
|
324
|
+
const masked = maskSelectionToCeiling(
|
|
325
|
+
scope,
|
|
326
|
+
[SCOPE_SYSTEM_INFO, r],
|
|
327
|
+
both,
|
|
328
|
+
);
|
|
329
|
+
expect(rowsOverCeiling(scope, masked, a), `${name}: ${r} (a)`).toEqual(
|
|
330
|
+
[],
|
|
331
|
+
);
|
|
332
|
+
expect(rowsOverCeiling(scope, masked, b), `${name}: ${r} (b)`).toEqual(
|
|
333
|
+
[],
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("the intersection is no wider than either list: every row it permits, both permit", () => {
|
|
340
|
+
// A platform-floor row never leaves whatever a list says (the mask and
|
|
341
|
+
// the door both drop it), so coverage of it is not a release question.
|
|
342
|
+
const releasable = LIVE.filter(
|
|
343
|
+
(r) => !underFloor(r) && scope.row(r)?.platformFloor !== true,
|
|
344
|
+
);
|
|
345
|
+
for (const { name, a, b } of PAIRS) {
|
|
346
|
+
const both = intersectSharingCeilingLists(a, b);
|
|
347
|
+
for (const r of releasable) {
|
|
348
|
+
if (!within(both, r)) continue;
|
|
349
|
+
expect(within(a, r) && within(b, r), `${name}: ${r}`).toBe(true);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
});
|
|
@@ -344,3 +344,66 @@ export function maskSelectionToCeiling(
|
|
|
344
344
|
// which a caller's tree may populate with retired rows: keep live ones only.
|
|
345
345
|
return withSystemInfo(sel.filter((c) => facts.isLive(c)));
|
|
346
346
|
}
|
|
347
|
+
|
|
348
|
+
// ─── Two readers of the coverage rule, lifted from Thread ───────────────────
|
|
349
|
+
//
|
|
350
|
+
// Lifted unchanged from Thread `@thread/shared` `sharingCeiling.ts`
|
|
351
|
+
// L432-L480 @ thread develop f021be2. The one change is the tree: Thread
|
|
352
|
+
// bound its own `INFORMATION_SCOPE_RESOLVER`; here the caller passes it as
|
|
353
|
+
// `scope`, the first argument, like every other reader in this file (this
|
|
354
|
+
// subpath carries no SOT). Thread keeps its two-argument names as wrappers
|
|
355
|
+
// that bind its resolver; PAVE's twin `intersectSharingCeilingLists`
|
|
356
|
+
// (pave-2.0 `packages/domain/src/sharingScopeCeiling.ts`) does the same.
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* The part of a ceiling a scope check reads: the v4 rows that may leave, or
|
|
360
|
+
* `null` when no ceiling binds.
|
|
361
|
+
*/
|
|
362
|
+
export interface SharingScopeCeiling {
|
|
363
|
+
readonly allowed: ReadonlySet<string> | readonly string[] | null;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Whether the ceiling permits one v4 ROW — the coverage rule
|
|
368
|
+
* ({@link scopeRowWithinCeiling}).
|
|
369
|
+
*
|
|
370
|
+
* - `null` ceiling or `allowed: null` ⇒ permitted (no ceiling binds).
|
|
371
|
+
* - System metadata (any row under `system`) ⇒ permitted (GDR 5.17
|
|
372
|
+
* clause 5 — provenance rides).
|
|
373
|
+
* - A code outside the tree ⇒ NOT permitted (fail closed).
|
|
374
|
+
*/
|
|
375
|
+
export function isPermittedByCeiling(
|
|
376
|
+
scope: SharingCeilingScope,
|
|
377
|
+
ceiling: SharingScopeCeiling | null,
|
|
378
|
+
code: string,
|
|
379
|
+
): boolean {
|
|
380
|
+
if (ceiling === null || ceiling.allowed === null) return true;
|
|
381
|
+
if (scope.ancestorsOf(code).includes("system")) {
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
if (scope.row(code) === undefined) return false;
|
|
385
|
+
return scopeRowWithinCeiling(scope, ceiling.allowed, code);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* What BOTH of two ceiling lists permit: a row of either list that is within
|
|
390
|
+
* the other (the coverage rule). A composer intersects its selected
|
|
391
|
+
* recipients' ceilings with this — one selection serves every recipient, so
|
|
392
|
+
* the narrowest wins.
|
|
393
|
+
*/
|
|
394
|
+
export function intersectSharingCeilingLists(
|
|
395
|
+
scope: SharingCeilingScope,
|
|
396
|
+
a: ReadonlySet<string> | readonly string[],
|
|
397
|
+
b: ReadonlySet<string> | readonly string[],
|
|
398
|
+
): string[] {
|
|
399
|
+
const left = [...a];
|
|
400
|
+
const right = [...b];
|
|
401
|
+
const within = (list: readonly string[], code: string): boolean =>
|
|
402
|
+
scopeRowWithinCeiling(scope, list, code);
|
|
403
|
+
return [
|
|
404
|
+
...new Set([
|
|
405
|
+
...left.filter((code) => within(right, code)),
|
|
406
|
+
...right.filter((code) => within(left, code)),
|
|
407
|
+
]),
|
|
408
|
+
];
|
|
409
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The account's per-purpose DEFAULT share scope (C12b) — the prototype's
|
|
3
|
+
* `shareDefaultScopeFor`: the v4 rows a share of one purpose carries by the
|
|
4
|
+
* ACCOUNT's rule, before any recipient is named. The account's own
|
|
5
|
+
* `__default__` cell for the purpose, else the platform starter's
|
|
6
|
+
* `scopeByPurpose[purpose]`; `[]` when the purpose is off.
|
|
7
|
+
*
|
|
8
|
+
* Lifted unchanged from Thread `@thread/shared` `sharingCeiling.ts`
|
|
9
|
+
* L383-L427 @ thread develop f021be2 (`accountSharePurposePolicy`), so Thread
|
|
10
|
+
* and PAVE compute it once. Exported under the prototype's name
|
|
11
|
+
* {@link shareDefaultScopeFor}; {@link accountSharePurposePolicy} is the same
|
|
12
|
+
* function, kept so Thread's call sites do not change.
|
|
13
|
+
*
|
|
14
|
+
* It is the chain's `account_default` → `platform_default` tail
|
|
15
|
+
* (`effectiveCeiling`, ./chain.ts) — what every recipient without a partner
|
|
16
|
+
* rule is held to: the composer's and the release wizard's "your account's
|
|
17
|
+
* default for <purpose>" preset. Canon: prototype
|
|
18
|
+
* `HTI-LEADS-PAVE-Thread-prototype.html` @ d85f05b7 `shareEffectiveCeiling`
|
|
19
|
+
* L327966-L328090 (the chain's tail L328053-L328058); the off reading is
|
|
20
|
+
* clamp 1 (platform-prototype `src/data.js` @ a6f1f3a L51352-L51354).
|
|
21
|
+
*
|
|
22
|
+
* Pure: no mongoose, no I/O, no SOT import.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
SHARING_CEILING_DEFAULT_ROW_KEY,
|
|
27
|
+
isSharingPurposeDisabled,
|
|
28
|
+
type SharingScopeEdits,
|
|
29
|
+
} from "./chain.js";
|
|
30
|
+
import {
|
|
31
|
+
HTI_SHARE_PLATFORM_STARTER,
|
|
32
|
+
type SharingPlatformStarter,
|
|
33
|
+
} from "./starter.js";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The account's standing on ONE share purpose, before any recipient is named
|
|
37
|
+
* — what the composer's purpose card shows beside each pill:
|
|
38
|
+
*
|
|
39
|
+
* - `off`: the purpose is switched off for the account (canon's clamp 1 —
|
|
40
|
+
* the platform row's `enabled: false`, or the account's own Share
|
|
41
|
+
* Purposes switch once the platform writes one; `isSharingPurposeDisabled`
|
|
42
|
+
* is the package's one test). An off purpose binds `[]` at every door, so
|
|
43
|
+
* the card renders it DISABLED-WITH-REASON (Terry ruling 2026-08-12:
|
|
44
|
+
* policy exclusions on this surface stay visible).
|
|
45
|
+
* - `accountDefault`: the v4 rows a share of that purpose carries by the
|
|
46
|
+
* ACCOUNT'S rule — the `__default__` cell the account authored, else the
|
|
47
|
+
* platform default (`starter.scopeByPurpose`); `[]` when off.
|
|
48
|
+
*
|
|
49
|
+
* `edits === null` (the store could not be read) → `[]` for every purpose,
|
|
50
|
+
* fail closed, like the ceiling itself.
|
|
51
|
+
*/
|
|
52
|
+
export interface AccountSharePurposePolicy {
|
|
53
|
+
readonly off: boolean;
|
|
54
|
+
readonly accountDefault: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The options {@link shareDefaultScopeFor} reads. */
|
|
58
|
+
export interface ShareDefaultScopeOptions {
|
|
59
|
+
readonly starter?: SharingPlatformStarter;
|
|
60
|
+
/** The account's Share Purposes switches, when the platform writes them. */
|
|
61
|
+
readonly purposeOverrides?: Readonly<
|
|
62
|
+
Record<string, boolean | undefined>
|
|
63
|
+
> | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The account's default scope for `purpose` (see the module note). Total:
|
|
68
|
+
* never throws; a non-string entry in a stored list is dropped.
|
|
69
|
+
*/
|
|
70
|
+
export function shareDefaultScopeFor(
|
|
71
|
+
edits: SharingScopeEdits | null | undefined,
|
|
72
|
+
purpose: string,
|
|
73
|
+
opts: ShareDefaultScopeOptions = {},
|
|
74
|
+
): AccountSharePurposePolicy {
|
|
75
|
+
const off = isSharingPurposeDisabled(purpose, opts.purposeOverrides ?? null);
|
|
76
|
+
if (off || edits === null || edits === undefined) {
|
|
77
|
+
return { off, accountDefault: [] };
|
|
78
|
+
}
|
|
79
|
+
const starter = opts.starter ?? HTI_SHARE_PLATFORM_STARTER;
|
|
80
|
+
const authored = (
|
|
81
|
+
edits as Readonly<Record<string, Readonly<Record<string, unknown>>>>
|
|
82
|
+
)[SHARING_CEILING_DEFAULT_ROW_KEY]?.[purpose];
|
|
83
|
+
if (Array.isArray(authored)) {
|
|
84
|
+
return {
|
|
85
|
+
off,
|
|
86
|
+
accountDefault: authored.filter(
|
|
87
|
+
(v): v is string => typeof v === "string",
|
|
88
|
+
),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const platform = (
|
|
92
|
+
starter.scopeByPurpose as Readonly<Record<string, unknown>>
|
|
93
|
+
)[purpose];
|
|
94
|
+
return {
|
|
95
|
+
off,
|
|
96
|
+
accountDefault: Array.isArray(platform)
|
|
97
|
+
? platform.filter((v): v is string => typeof v === "string")
|
|
98
|
+
: [],
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Thread's name for {@link shareDefaultScopeFor} — the SAME function (not a
|
|
104
|
+
* wrapper), kept so `@thread/shared` call sites do not change.
|
|
105
|
+
*/
|
|
106
|
+
export const accountSharePurposePolicy = shareDefaultScopeFor;
|
|
@@ -7,8 +7,15 @@
|
|
|
7
7
|
* rule (`scopeRowWithinCeiling`, with its door and composer-mask readers).
|
|
8
8
|
* Pure TypeScript, no mongoose, no I/O, no SOT import — pass the v4 tree as
|
|
9
9
|
* an information-scope resolver. Also re-exported from the package root.
|
|
10
|
+
*
|
|
11
|
+
* 0.41.0 adds, lifted from Thread `@thread/shared` `sharingCeiling.ts`
|
|
12
|
+
* (behaviour unchanged): the account's per-purpose default
|
|
13
|
+
* (`shareDefaultScopeFor`, alias `accountSharePurposePolicy`; ./defaults.ts)
|
|
14
|
+
* and two coverage readers (`isPermittedByCeiling`,
|
|
15
|
+
* `intersectSharingCeilingLists`; ./coverage.ts).
|
|
10
16
|
*/
|
|
11
17
|
|
|
12
18
|
export * from "./starter.js";
|
|
13
19
|
export * from "./chain.js";
|
|
14
20
|
export * from "./coverage.js";
|
|
21
|
+
export * from "./defaults.js";
|
|
@@ -233,18 +233,18 @@ type SectionQuestionRef = InferRawDocType<typeof sectionQuestionRefSchema>;
|
|
|
233
233
|
declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
234
234
|
_id: false;
|
|
235
235
|
}, {
|
|
236
|
-
type: "tip" | "warning" | "prompt";
|
|
237
236
|
text: string;
|
|
238
|
-
}, mongoose.Document<unknown, {}, {
|
|
239
237
|
type: "tip" | "warning" | "prompt";
|
|
238
|
+
}, mongoose.Document<unknown, {}, {
|
|
240
239
|
text: string;
|
|
240
|
+
type: "tip" | "warning" | "prompt";
|
|
241
241
|
}, {
|
|
242
242
|
id: string;
|
|
243
243
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
244
244
|
_id: false;
|
|
245
245
|
}>> & Omit<{
|
|
246
|
-
type: "tip" | "warning" | "prompt";
|
|
247
246
|
text: string;
|
|
247
|
+
type: "tip" | "warning" | "prompt";
|
|
248
248
|
} & {
|
|
249
249
|
_id: mongoose.Types.ObjectId;
|
|
250
250
|
} & {
|
|
@@ -252,8 +252,8 @@ declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any
|
|
|
252
252
|
}, "id"> & {
|
|
253
253
|
id: string;
|
|
254
254
|
}, unknown, {
|
|
255
|
-
type: "tip" | "warning" | "prompt";
|
|
256
255
|
text: string;
|
|
256
|
+
type: "tip" | "warning" | "prompt";
|
|
257
257
|
} & {
|
|
258
258
|
_id: mongoose.Types.ObjectId;
|
|
259
259
|
} & {
|
|
@@ -294,18 +294,18 @@ declare const sectionSchemaDefinition: {
|
|
|
294
294
|
type: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
295
295
|
_id: false;
|
|
296
296
|
}, {
|
|
297
|
-
type: "tip" | "warning" | "prompt";
|
|
298
297
|
text: string;
|
|
299
|
-
}, mongoose.Document<unknown, {}, {
|
|
300
298
|
type: "tip" | "warning" | "prompt";
|
|
299
|
+
}, mongoose.Document<unknown, {}, {
|
|
301
300
|
text: string;
|
|
301
|
+
type: "tip" | "warning" | "prompt";
|
|
302
302
|
}, {
|
|
303
303
|
id: string;
|
|
304
304
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
305
305
|
_id: false;
|
|
306
306
|
}>> & Omit<{
|
|
307
|
-
type: "tip" | "warning" | "prompt";
|
|
308
307
|
text: string;
|
|
308
|
+
type: "tip" | "warning" | "prompt";
|
|
309
309
|
} & {
|
|
310
310
|
_id: mongoose.Types.ObjectId;
|
|
311
311
|
} & {
|
|
@@ -313,8 +313,8 @@ declare const sectionSchemaDefinition: {
|
|
|
313
313
|
}, "id"> & {
|
|
314
314
|
id: string;
|
|
315
315
|
}, unknown, {
|
|
316
|
-
type: "tip" | "warning" | "prompt";
|
|
317
316
|
text: string;
|
|
317
|
+
type: "tip" | "warning" | "prompt";
|
|
318
318
|
} & {
|
|
319
319
|
_id: mongoose.Types.ObjectId;
|
|
320
320
|
} & {
|
|
@@ -233,18 +233,18 @@ type SectionQuestionRef = InferRawDocType<typeof sectionQuestionRefSchema>;
|
|
|
233
233
|
declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
234
234
|
_id: false;
|
|
235
235
|
}, {
|
|
236
|
-
type: "tip" | "warning" | "prompt";
|
|
237
236
|
text: string;
|
|
238
|
-
}, mongoose.Document<unknown, {}, {
|
|
239
237
|
type: "tip" | "warning" | "prompt";
|
|
238
|
+
}, mongoose.Document<unknown, {}, {
|
|
240
239
|
text: string;
|
|
240
|
+
type: "tip" | "warning" | "prompt";
|
|
241
241
|
}, {
|
|
242
242
|
id: string;
|
|
243
243
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
244
244
|
_id: false;
|
|
245
245
|
}>> & Omit<{
|
|
246
|
-
type: "tip" | "warning" | "prompt";
|
|
247
246
|
text: string;
|
|
247
|
+
type: "tip" | "warning" | "prompt";
|
|
248
248
|
} & {
|
|
249
249
|
_id: mongoose.Types.ObjectId;
|
|
250
250
|
} & {
|
|
@@ -252,8 +252,8 @@ declare const guidanceSchema: Schema<any, mongoose.Model<any, any, any, any, any
|
|
|
252
252
|
}, "id"> & {
|
|
253
253
|
id: string;
|
|
254
254
|
}, unknown, {
|
|
255
|
-
type: "tip" | "warning" | "prompt";
|
|
256
255
|
text: string;
|
|
256
|
+
type: "tip" | "warning" | "prompt";
|
|
257
257
|
} & {
|
|
258
258
|
_id: mongoose.Types.ObjectId;
|
|
259
259
|
} & {
|
|
@@ -294,18 +294,18 @@ declare const sectionSchemaDefinition: {
|
|
|
294
294
|
type: Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
295
295
|
_id: false;
|
|
296
296
|
}, {
|
|
297
|
-
type: "tip" | "warning" | "prompt";
|
|
298
297
|
text: string;
|
|
299
|
-
}, mongoose.Document<unknown, {}, {
|
|
300
298
|
type: "tip" | "warning" | "prompt";
|
|
299
|
+
}, mongoose.Document<unknown, {}, {
|
|
301
300
|
text: string;
|
|
301
|
+
type: "tip" | "warning" | "prompt";
|
|
302
302
|
}, {
|
|
303
303
|
id: string;
|
|
304
304
|
}, mongoose.MergeType<mongoose.DefaultSchemaOptions, {
|
|
305
305
|
_id: false;
|
|
306
306
|
}>> & Omit<{
|
|
307
|
-
type: "tip" | "warning" | "prompt";
|
|
308
307
|
text: string;
|
|
308
|
+
type: "tip" | "warning" | "prompt";
|
|
309
309
|
} & {
|
|
310
310
|
_id: mongoose.Types.ObjectId;
|
|
311
311
|
} & {
|
|
@@ -313,8 +313,8 @@ declare const sectionSchemaDefinition: {
|
|
|
313
313
|
}, "id"> & {
|
|
314
314
|
id: string;
|
|
315
315
|
}, unknown, {
|
|
316
|
-
type: "tip" | "warning" | "prompt";
|
|
317
316
|
text: string;
|
|
317
|
+
type: "tip" | "warning" | "prompt";
|
|
318
318
|
} & {
|
|
319
319
|
_id: mongoose.Types.ObjectId;
|
|
320
320
|
} & {
|