@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.
- package/README.md +90 -0
- package/dist/authz/index.cjs +353 -2
- package/dist/authz/index.cjs.map +1 -1
- package/dist/authz/index.d.cts +330 -9
- package/dist/authz/index.d.ts +330 -9
- package/dist/authz/index.js +339 -1
- package/dist/authz/index.js.map +1 -1
- package/dist/{index-XWSYon40.d.cts → index-Bj-s0nZy.d.cts} +1 -1
- package/dist/{index-Bh1zO_Vu.d.ts → index-DvAypMJV.d.ts} +1 -1
- package/dist/index.cjs +503 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +483 -2
- 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/sharing-ceiling/index.cjs +152 -2
- package/dist/sharing-ceiling/index.cjs.map +1 -1
- package/dist/sharing-ceiling/index.d.cts +214 -2
- package/dist/sharing-ceiling/index.d.ts +214 -2
- package/dist/sharing-ceiling/index.js +145 -2
- package/dist/sharing-ceiling/index.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/authz-resolve.test.ts +5 -0
- package/src/__tests__/authz-viewing-policy.test.ts +685 -0
- package/src/__tests__/authz-viewing-scope.test.ts +1037 -0
- package/src/__tests__/core-function-default-bounds.test.ts +2 -2
- package/src/authz/functionDoor.ts +4 -4
- package/src/authz/index.ts +2 -0
- package/src/authz/resolveEffectiveFunctions.ts +6 -4
- package/src/authz/viewingPolicy.ts +525 -0
- package/src/authz/viewingScope.ts +359 -0
- package/src/sharingCeiling/__tests__/fireShareEvent.test.ts +437 -0
- package/src/sharingCeiling/fireShareEvent.ts +352 -0
- package/src/sharingCeiling/index.ts +4 -0
- package/src/sharingCeiling/resolve.ts +31 -5
- package/dist/{cvcEntry-D787utvP.d.cts → cvcEntry-BLeRivoF.d.cts} +8 -8
- package/dist/{cvcEntry-D787utvP.d.ts → cvcEntry-BLeRivoF.d.ts} +8 -8
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVENT-DRIVEN SHARING — which listeners an event fires (Kickoff 13 build
|
|
3
|
+
* item 9a; Crysta 2026-10-19 14:26 "enabling vs firing"; home ruled
|
|
4
|
+
* 2026-11-01: platform-common exports `ShareEvent` + `fireShareEvent(policies,
|
|
5
|
+
* event)` as a pure function, and each app calls it after commit at session
|
|
6
|
+
* submit and case close).
|
|
7
|
+
*
|
|
8
|
+
* Contract of record: platform-prototype `src/data.js` — `TRIGGER_EVENTS`,
|
|
9
|
+
* `policyIsListener`, `listenersFor`, `fireShareEvent` (K13-9a
|
|
10
|
+
* EVENT-LISTENER 2026-10-22).
|
|
11
|
+
*
|
|
12
|
+
* ENABLING is a Policy with the `ongoing` cadence and a trigger, linked team
|
|
13
|
+
* → team or team → partner: standing permission, authored by the Member
|
|
14
|
+
* Admin. FIRING writes an ORDINARY share — the policy's purpose and version
|
|
15
|
+
* on it — down the normal notify → review → claim path; only the author
|
|
16
|
+
* differs.
|
|
17
|
+
*
|
|
18
|
+
* This module answers ONE question and decides nothing else: given the
|
|
19
|
+
* sending account's policy documents and an event raised by a team, which
|
|
20
|
+
* listeners fire, and to whom. Everything a manual share of that purpose
|
|
21
|
+
* would be held to still applies and stays where it lives — the app sends
|
|
22
|
+
* each answer through its own send door: `resolveShare` for what may leave
|
|
23
|
+
* (and the policy's posture — `approval` waits, `blocked` holds), the release
|
|
24
|
+
* for a partner (one that covers the `ongoing` cadence), the account's
|
|
25
|
+
* catalog, the floor. A fired share is never a way around a rule.
|
|
26
|
+
*
|
|
27
|
+
* THE CALLER'S TWO DUTIES. (1) A link is read from the policy document's own
|
|
28
|
+
* `assignments`; pass the account's team rows as `options.teamRows` (or check
|
|
29
|
+
* `teamRowId` against your row store before sending) so a link whose row was
|
|
30
|
+
* deleted, or no longer says what the document says, fires nothing. (2) An
|
|
31
|
+
* event that can happen more than once on one subject (a note, a service, a
|
|
32
|
+
* status change) needs its own `ref`, or the second is taken for the first.
|
|
33
|
+
*
|
|
34
|
+
* Pure: no I/O, no clock, no randomness. The same input gives the same
|
|
35
|
+
* output, so a caller can run it twice and compare `key`s to fire each
|
|
36
|
+
* listener ONCE per event per subject (pass the keys already written as
|
|
37
|
+
* `alreadyFired`).
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import {
|
|
41
|
+
attachmentIndexFromPolicies,
|
|
42
|
+
type SharePolicyAssignment,
|
|
43
|
+
type SharePolicyDoc,
|
|
44
|
+
type ShareRecipient,
|
|
45
|
+
type ShareTeamRowLike,
|
|
46
|
+
} from "./resolve.js";
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The events a listener may name. A trigger is a flag over EXISTING codes —
|
|
50
|
+
* the CVC-285 event names the platform already emits — and mints no new CVC
|
|
51
|
+
* (open point 5's default). The subset a case or a share can raise, in the
|
|
52
|
+
* prototype's order and words.
|
|
53
|
+
*/
|
|
54
|
+
export const SHARE_TRIGGER_EVENTS = Object.freeze([
|
|
55
|
+
{ code: "sessionSubmitted", label: "Session submitted", group: "case" },
|
|
56
|
+
{ code: "caseOpened", label: "Case opened", group: "case" },
|
|
57
|
+
{ code: "caseStatusChanged", label: "Case status changed", group: "case" },
|
|
58
|
+
{ code: "caseCloseRuled", label: "Case closed", group: "case" },
|
|
59
|
+
{
|
|
60
|
+
code: "determinationIssued",
|
|
61
|
+
label: "Determination issued",
|
|
62
|
+
group: "case",
|
|
63
|
+
},
|
|
64
|
+
{ code: "serviceLogged", label: "Service logged", group: "case" },
|
|
65
|
+
{ code: "noteAdded", label: "Note added", group: "case" },
|
|
66
|
+
{ code: "shareClaimed", label: "Share you sent claimed", group: "share" },
|
|
67
|
+
{
|
|
68
|
+
code: "referralClaimed",
|
|
69
|
+
label: "Referral you sent claimed",
|
|
70
|
+
group: "share",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
code: "shareAcknowledged",
|
|
74
|
+
label: "Share you sent acknowledged",
|
|
75
|
+
group: "share",
|
|
76
|
+
},
|
|
77
|
+
] as const);
|
|
78
|
+
|
|
79
|
+
export type ShareTriggerEventCode =
|
|
80
|
+
(typeof SHARE_TRIGGER_EVENTS)[number]["code"];
|
|
81
|
+
|
|
82
|
+
/** The two events the apps raise today (session submit · case close). */
|
|
83
|
+
export const SHARE_EVENT = Object.freeze({
|
|
84
|
+
SESSION_SUBMITTED: "sessionSubmitted",
|
|
85
|
+
CASE_CLOSED: "caseCloseRuled",
|
|
86
|
+
} as const satisfies Record<string, ShareTriggerEventCode>);
|
|
87
|
+
|
|
88
|
+
/** The words a person reads for a trigger code (the code itself when unknown). */
|
|
89
|
+
export function shareTriggerLabel(code: string): string {
|
|
90
|
+
return SHARE_TRIGGER_EVENTS.find((t) => t.code === code)?.label ?? code;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Something that happened on a case or a session, raised by the team that did it. */
|
|
94
|
+
export interface ShareEvent {
|
|
95
|
+
/** The CVC-285 event name (`SHARE_EVENT`, `SHARE_TRIGGER_EVENTS`). */
|
|
96
|
+
readonly event: string;
|
|
97
|
+
/**
|
|
98
|
+
* The ACTING team — a listener is a link FROM a team, so an event with no
|
|
99
|
+
* team fires nothing.
|
|
100
|
+
*/
|
|
101
|
+
readonly teamId: string | null | undefined;
|
|
102
|
+
/** Informational: `policies` must already be the sending account's documents. */
|
|
103
|
+
readonly accountId?: string | null;
|
|
104
|
+
readonly caseId?: string | null;
|
|
105
|
+
readonly sessionId?: string | null;
|
|
106
|
+
/**
|
|
107
|
+
* What the event is about, for the once-only key. Default: the session id
|
|
108
|
+
* for `sessionSubmitted`; for every other event the case id, else the
|
|
109
|
+
* session id; else none (every such event shares one key). Pass it
|
|
110
|
+
* explicitly for an event that can repeat on one case.
|
|
111
|
+
*/
|
|
112
|
+
readonly ref?: string | null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** One listener: a policy with the `ongoing` cadence and a trigger, on one team link. */
|
|
116
|
+
export interface ShareListener {
|
|
117
|
+
readonly policy: {
|
|
118
|
+
readonly id: string;
|
|
119
|
+
readonly familyId: string;
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly version: number;
|
|
122
|
+
};
|
|
123
|
+
readonly purpose: string;
|
|
124
|
+
readonly fromTeamId: string;
|
|
125
|
+
/** The link's row — what `resolveShare` takes as `teamRowId`. */
|
|
126
|
+
readonly teamRowId: string;
|
|
127
|
+
/** Who it sends to, in the resolver's own vocabulary. */
|
|
128
|
+
readonly recipient: Extract<
|
|
129
|
+
ShareRecipient,
|
|
130
|
+
{ kind: "partner" } | { kind: "sibling_team" }
|
|
131
|
+
>;
|
|
132
|
+
/** A team → partner-team link names the partner's team; else `null`. */
|
|
133
|
+
readonly partnerTeamId: string | null;
|
|
134
|
+
/** The events it listens for. */
|
|
135
|
+
readonly events: readonly string[];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** One listener an event raised — the share the app is to write. */
|
|
139
|
+
export interface FiredShare extends ShareListener {
|
|
140
|
+
readonly event: string;
|
|
141
|
+
readonly ref: string | null;
|
|
142
|
+
/**
|
|
143
|
+
* Stable for one event × subject × policy × sending team × recipient: the
|
|
144
|
+
* same event on the same case fires each listener ONCE. Opaque — compare
|
|
145
|
+
* it, never parse it.
|
|
146
|
+
*/
|
|
147
|
+
readonly key: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const str = (v: unknown): v is string => typeof v === "string" && v !== "";
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A policy that listens: live, `ongoing` cadence, at least one trigger event
|
|
154
|
+
* (data.js `policyIsListener`) — and NOT a share-back policy
|
|
155
|
+
* (`trigger.answers === "received"`, K13-9b), which answers a share received
|
|
156
|
+
* and never fires on a case event.
|
|
157
|
+
*/
|
|
158
|
+
export function policyIsShareListener(
|
|
159
|
+
p: SharePolicyDoc | null | undefined,
|
|
160
|
+
): boolean {
|
|
161
|
+
if (p === null || p === undefined || typeof p !== "object") return false;
|
|
162
|
+
if (p.active === false) return false;
|
|
163
|
+
// strictly `true` (the prototype accepts any truthy value; a stored `1` or
|
|
164
|
+
// `"true"` does not listen here — fail closed)
|
|
165
|
+
if (p.cadences?.ongoing !== true) return false;
|
|
166
|
+
const on = p.trigger?.on;
|
|
167
|
+
if (!Array.isArray(on) || !on.some(str)) return false;
|
|
168
|
+
return p.trigger?.answers !== "received";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
type PairLink = Extract<SharePolicyAssignment, { scope: "team_pair" }>;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Where a team link sends, or `null` when the link does not say (never
|
|
175
|
+
* guessed) — data.js `listenersFor`: a row with no partner whose `with` is a
|
|
176
|
+
* team is a team → team link; with a partner, `with` (a team) names the
|
|
177
|
+
* partner's team.
|
|
178
|
+
*/
|
|
179
|
+
function linkTarget(
|
|
180
|
+
a: PairLink,
|
|
181
|
+
): Pick<ShareListener, "recipient" | "partnerTeamId"> | null {
|
|
182
|
+
const withTeam =
|
|
183
|
+
a.with !== null &&
|
|
184
|
+
typeof a.with === "object" &&
|
|
185
|
+
a.with.type === "team" &&
|
|
186
|
+
str(a.with.id)
|
|
187
|
+
? a.with.id
|
|
188
|
+
: null;
|
|
189
|
+
if (str(a.partnerId)) {
|
|
190
|
+
return {
|
|
191
|
+
recipient: { kind: "partner", id: a.partnerId },
|
|
192
|
+
partnerTeamId: withTeam,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
if (withTeam !== null) {
|
|
196
|
+
return {
|
|
197
|
+
recipient: { kind: "sibling_team", teamId: withTeam },
|
|
198
|
+
partnerTeamId: null,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Collision-free whatever the ids contain. */
|
|
205
|
+
const targetKey = (
|
|
206
|
+
l: Pick<ShareListener, "recipient" | "partnerTeamId">,
|
|
207
|
+
): readonly (string | null)[] =>
|
|
208
|
+
l.recipient.kind === "partner"
|
|
209
|
+
? ["partner", l.recipient.id, l.partnerTeamId]
|
|
210
|
+
: ["team", l.recipient.teamId, null];
|
|
211
|
+
|
|
212
|
+
/** Does the account's row store still say what the link says? */
|
|
213
|
+
function rowAgrees(
|
|
214
|
+
rows: readonly ShareTeamRowLike[],
|
|
215
|
+
a: PairLink,
|
|
216
|
+
target: Pick<ShareListener, "recipient" | "partnerTeamId">,
|
|
217
|
+
): boolean {
|
|
218
|
+
const row = rows.find(
|
|
219
|
+
(r) => r !== null && typeof r === "object" && r.id === a.teamRowId,
|
|
220
|
+
);
|
|
221
|
+
if (row === undefined || row.myTeamId !== a.teamId) return false;
|
|
222
|
+
const theirTeam =
|
|
223
|
+
row.their?.type === "team" && str(row.their.id) ? row.their.id : null;
|
|
224
|
+
return target.recipient.kind === "sibling_team"
|
|
225
|
+
? theirTeam === target.recipient.teamId
|
|
226
|
+
: theirTeam === target.partnerTeamId;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The listeners linked FROM one team (data.js `listenersFor`): each listening
|
|
231
|
+
* policy × each of its team → team / team → partner links whose sending team
|
|
232
|
+
* is `teamId`. A link that names no sending team, a different team, or no
|
|
233
|
+
* target is not a listener for this team. The policy must also be the one
|
|
234
|
+
* that HOLDS the row's cell for its purpose (`attachmentIndexFromPolicies` —
|
|
235
|
+
* two live documents on one cell: the later wins, exactly as the ladder
|
|
236
|
+
* reads it), so the share a listener fires is governed by that same policy.
|
|
237
|
+
* Two links of one policy to the same place are one listener (the first, in
|
|
238
|
+
* document order). `options.event` keeps only the policies listening for
|
|
239
|
+
* that event; `options.teamRows`, when given, drops a link whose row is gone
|
|
240
|
+
* or disagrees with it.
|
|
241
|
+
*/
|
|
242
|
+
export function shareListenersFor(
|
|
243
|
+
policies: readonly SharePolicyDoc[] | null | undefined,
|
|
244
|
+
teamId: string | null | undefined,
|
|
245
|
+
options: {
|
|
246
|
+
readonly event?: string | null;
|
|
247
|
+
readonly teamRows?: readonly ShareTeamRowLike[] | null;
|
|
248
|
+
} = {},
|
|
249
|
+
): ShareListener[] {
|
|
250
|
+
if (!Array.isArray(policies) || !str(teamId)) return [];
|
|
251
|
+
const cells = attachmentIndexFromPolicies(policies).teamRows;
|
|
252
|
+
const rows = Array.isArray(options.teamRows) ? options.teamRows : null;
|
|
253
|
+
const out: ShareListener[] = [];
|
|
254
|
+
const seen = new Set<string>();
|
|
255
|
+
for (const p of policies) {
|
|
256
|
+
if (!policyIsShareListener(p) || !str(p.id) || !str(p.purpose)) continue;
|
|
257
|
+
const events = (p.trigger?.on ?? []).filter(str);
|
|
258
|
+
if (str(options.event) && !events.includes(options.event)) continue;
|
|
259
|
+
for (const a of Array.isArray(p.assignments) ? p.assignments : []) {
|
|
260
|
+
if (a === null || typeof a !== "object" || a.scope !== "team_pair")
|
|
261
|
+
continue;
|
|
262
|
+
if (!str(a.teamRowId) || a.teamId !== teamId) continue;
|
|
263
|
+
// the cell's holder listens; a document another one displaced does not
|
|
264
|
+
if (cells[a.teamRowId]?.[p.purpose] !== p.id) continue;
|
|
265
|
+
const target = linkTarget(a);
|
|
266
|
+
if (target === null) continue;
|
|
267
|
+
if (rows !== null && !rowAgrees(rows, a, target)) continue;
|
|
268
|
+
// a team never listens to itself
|
|
269
|
+
if (
|
|
270
|
+
target.recipient.kind === "sibling_team" &&
|
|
271
|
+
target.recipient.teamId === teamId
|
|
272
|
+
)
|
|
273
|
+
continue;
|
|
274
|
+
const dedupe = JSON.stringify([p.id, ...targetKey(target)]);
|
|
275
|
+
if (seen.has(dedupe)) continue;
|
|
276
|
+
seen.add(dedupe);
|
|
277
|
+
out.push({
|
|
278
|
+
policy: {
|
|
279
|
+
id: p.id,
|
|
280
|
+
familyId: str(p.familyId) ? p.familyId : p.id,
|
|
281
|
+
name: str(p.name) ? p.name : p.id,
|
|
282
|
+
version: parseInt(String(p.version), 10) || 1,
|
|
283
|
+
},
|
|
284
|
+
purpose: p.purpose,
|
|
285
|
+
fromTeamId: teamId,
|
|
286
|
+
teamRowId: a.teamRowId,
|
|
287
|
+
...target,
|
|
288
|
+
events,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** The once-only key of one fired share (see `FiredShare.key`). */
|
|
296
|
+
export function firedShareKey(
|
|
297
|
+
event: string,
|
|
298
|
+
ref: string | null,
|
|
299
|
+
listener: Pick<
|
|
300
|
+
ShareListener,
|
|
301
|
+
"policy" | "fromTeamId" | "recipient" | "partnerTeamId"
|
|
302
|
+
>,
|
|
303
|
+
): string {
|
|
304
|
+
return JSON.stringify([
|
|
305
|
+
event,
|
|
306
|
+
ref,
|
|
307
|
+
listener.policy.id,
|
|
308
|
+
listener.fromTeamId,
|
|
309
|
+
...targetKey(listener),
|
|
310
|
+
]);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* FIRING (data.js `fireShareEvent`, the pure half): the listeners linked from
|
|
315
|
+
* the acting team that listen for this event, each as the share to write.
|
|
316
|
+
* Call it AFTER the event's own write commits. `[]` when the event names no
|
|
317
|
+
* team or no event, when nothing listens — and for every listener whose key
|
|
318
|
+
* is in `alreadyFired` (what the app has written for this event before).
|
|
319
|
+
*
|
|
320
|
+
* The app then sends each one as an ordinary share of `purpose` to
|
|
321
|
+
* `recipient` from `fromTeamId` on `teamRowId`, stamped with `policy`, through
|
|
322
|
+
* its own send door. This function never decides what leaves or whether it
|
|
323
|
+
* may.
|
|
324
|
+
*/
|
|
325
|
+
export function fireShareEvent(
|
|
326
|
+
policies: readonly SharePolicyDoc[] | null | undefined,
|
|
327
|
+
event: ShareEvent | null | undefined,
|
|
328
|
+
options: {
|
|
329
|
+
readonly alreadyFired?: Iterable<string> | null;
|
|
330
|
+
readonly teamRows?: readonly ShareTeamRowLike[] | null;
|
|
331
|
+
} = {},
|
|
332
|
+
): FiredShare[] {
|
|
333
|
+
if (event === null || event === undefined || !str(event.event)) return [];
|
|
334
|
+
const session = str(event.sessionId) ? event.sessionId : null;
|
|
335
|
+
const kase = str(event.caseId) ? event.caseId : null;
|
|
336
|
+
const ref = str(event.ref)
|
|
337
|
+
? event.ref
|
|
338
|
+
: event.event === SHARE_EVENT.SESSION_SUBMITTED
|
|
339
|
+
? (session ?? kase)
|
|
340
|
+
: (kase ?? session);
|
|
341
|
+
const done = new Set(options.alreadyFired ?? []);
|
|
342
|
+
const fired: FiredShare[] = [];
|
|
343
|
+
for (const l of shareListenersFor(policies, event.teamId, {
|
|
344
|
+
event: event.event,
|
|
345
|
+
teamRows: options.teamRows ?? null,
|
|
346
|
+
})) {
|
|
347
|
+
const key = firedShareKey(event.event, ref, l);
|
|
348
|
+
if (done.has(key)) continue;
|
|
349
|
+
fired.push({ ...l, event: event.event, ref, key });
|
|
350
|
+
}
|
|
351
|
+
return fired;
|
|
352
|
+
}
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
* `intersectSharingCeilingLists`; ./coverage.ts).
|
|
18
18
|
*
|
|
19
19
|
* 0.42.0 adds THE share resolver (`resolveShare`; ./resolve.ts).
|
|
20
|
+
*
|
|
21
|
+
* 0.55.0 adds event-driven sharing's pure half (`ShareEvent`,
|
|
22
|
+
* `fireShareEvent`, `shareListenersFor`; ./fireShareEvent.ts).
|
|
20
23
|
*/
|
|
21
24
|
|
|
22
25
|
export * from "./starter.js";
|
|
@@ -24,3 +27,4 @@ export * from "./chain.js";
|
|
|
24
27
|
export * from "./coverage.js";
|
|
25
28
|
export * from "./defaults.js";
|
|
26
29
|
export * from "./resolve.js";
|
|
30
|
+
export * from "./fireShareEvent.js";
|
|
@@ -139,6 +139,16 @@ export type SharePolicyAssignment =
|
|
|
139
139
|
readonly teamRowId: string;
|
|
140
140
|
readonly teamId?: string;
|
|
141
141
|
readonly partnerId?: string | null;
|
|
142
|
+
/**
|
|
143
|
+
* The other end of the row, as the Admin Hub stores it on the link
|
|
144
|
+
* (data.js `policyRecord`): `{ type: "team", id }` names a receiving
|
|
145
|
+
* team — one of the account's own (no `partnerId`) or the partner's.
|
|
146
|
+
* The ladder does not read it (the row decides); `fireShareEvent` does.
|
|
147
|
+
*/
|
|
148
|
+
readonly with?: {
|
|
149
|
+
readonly type?: string;
|
|
150
|
+
readonly id?: string;
|
|
151
|
+
} | null;
|
|
142
152
|
};
|
|
143
153
|
|
|
144
154
|
/** A policy document as the Admin Hub stores it (data.js `policyRecord` L53540ff). */
|
|
@@ -166,8 +176,20 @@ export interface SharePolicyDoc {
|
|
|
166
176
|
readonly edited?: boolean;
|
|
167
177
|
/** `false` = retired: never governs. */
|
|
168
178
|
readonly active?: boolean;
|
|
169
|
-
/**
|
|
170
|
-
|
|
179
|
+
/**
|
|
180
|
+
* `answers: "received"` (K13-9b): a share-back policy never governs a share you start.
|
|
181
|
+
* `on` (K13-9a): the CVC-285 event names a LISTENER fires on — read by
|
|
182
|
+
* `fireShareEvent`, never by the ladder.
|
|
183
|
+
*/
|
|
184
|
+
readonly trigger?: {
|
|
185
|
+
readonly answers?: string;
|
|
186
|
+
readonly on?: readonly string[];
|
|
187
|
+
} | null;
|
|
188
|
+
/** CVC-85 cadences the policy grants; `ongoing` + a trigger makes it a listener (K13-9a). */
|
|
189
|
+
readonly cadences?: {
|
|
190
|
+
readonly ongoing?: boolean;
|
|
191
|
+
readonly automatic?: boolean;
|
|
192
|
+
} | null;
|
|
171
193
|
}
|
|
172
194
|
|
|
173
195
|
/** The Platform default for one purpose, as the four states (data.js `platformStarterScope` L53719ff). */
|
|
@@ -1128,7 +1150,9 @@ export function resolveShare(input: ShareResolveInput): ShareResolution {
|
|
|
1128
1150
|
items.filter(
|
|
1129
1151
|
(r) =>
|
|
1130
1152
|
!covered(r) &&
|
|
1131
|
-
!items.some(
|
|
1153
|
+
!items.some(
|
|
1154
|
+
(d) => d !== r && covered(d) && scope.ancestorsOf(d).includes(r),
|
|
1155
|
+
),
|
|
1132
1156
|
);
|
|
1133
1157
|
const addExcluded = (rows: readonly string[], why: string): void => {
|
|
1134
1158
|
for (const r of rows)
|
|
@@ -1230,13 +1254,15 @@ export function resolveShare(input: ShareResolveInput): ShareResolution {
|
|
|
1230
1254
|
const why = `Outside what your team's “${tcNamed?.name}” policy allows`;
|
|
1231
1255
|
const outRows = new Set<string>();
|
|
1232
1256
|
if (tcScope !== null && !scopeListStrictlyCovers(scope, tcScope, g)) {
|
|
1233
|
-
for (const r of outside((x) => scopeListCovers(scope, tcScope, g, x)))
|
|
1257
|
+
for (const r of outside((x) => scopeListCovers(scope, tcScope, g, x)))
|
|
1258
|
+
outRows.add(r);
|
|
1234
1259
|
}
|
|
1235
1260
|
const tcRows = own<unknown>(tcItems, g);
|
|
1236
1261
|
if (isStringList(tcRows)) {
|
|
1237
1262
|
const keep = new Set(tcRows);
|
|
1238
1263
|
const kept = (r: string): boolean =>
|
|
1239
|
-
keep.has(r) ||
|
|
1264
|
+
keep.has(r) ||
|
|
1265
|
+
scope.ancestorsOf(r).some((a) => a !== g && keep.has(a));
|
|
1240
1266
|
for (const r of outside(kept)) outRows.add(r);
|
|
1241
1267
|
}
|
|
1242
1268
|
for (const r of outRows)
|
|
@@ -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
|
} & {
|