@substrat-run/kernel 0.216.0 → 0.218.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attachment-gate.d.ts +42 -0
- package/dist/attachment-gate.d.ts.map +1 -0
- package/dist/attachment-gate.js +36 -0
- package/dist/attachment-gate.js.map +1 -0
- package/dist/broker-counts.d.ts +108 -0
- package/dist/broker-counts.d.ts.map +1 -0
- package/dist/broker-counts.js +101 -0
- package/dist/broker-counts.js.map +1 -0
- package/dist/broker-erasure.d.ts +51 -0
- package/dist/broker-erasure.d.ts.map +1 -0
- package/dist/broker-erasure.js +161 -0
- package/dist/broker-erasure.js.map +1 -0
- package/dist/broker-relay-erasure.d.ts +27 -0
- package/dist/broker-relay-erasure.d.ts.map +1 -0
- package/dist/broker-relay-erasure.js +115 -0
- package/dist/broker-relay-erasure.js.map +1 -0
- package/dist/broker-relay.d.ts +292 -0
- package/dist/broker-relay.d.ts.map +1 -0
- package/dist/broker-relay.js +494 -0
- package/dist/broker-relay.js.map +1 -0
- package/dist/broker-schema.d.ts +25 -0
- package/dist/broker-schema.d.ts.map +1 -0
- package/dist/broker-schema.js +256 -0
- package/dist/broker-schema.js.map +1 -0
- package/dist/broker-shadow.d.ts +258 -0
- package/dist/broker-shadow.d.ts.map +1 -0
- package/dist/broker-shadow.js +295 -0
- package/dist/broker-shadow.js.map +1 -0
- package/dist/broker-telemetry.d.ts +289 -0
- package/dist/broker-telemetry.d.ts.map +1 -0
- package/dist/broker-telemetry.js +336 -0
- package/dist/broker-telemetry.js.map +1 -0
- package/dist/cost-rollup.d.ts +6 -0
- package/dist/cost-rollup.d.ts.map +1 -1
- package/dist/cost-rollup.js +22 -1
- package/dist/cost-rollup.js.map +1 -1
- package/dist/delivery-broker.d.ts +320 -0
- package/dist/delivery-broker.d.ts.map +1 -0
- package/dist/delivery-broker.js +571 -0
- package/dist/delivery-broker.js.map +1 -0
- package/dist/delivery-policy.d.ts +105 -0
- package/dist/delivery-policy.d.ts.map +1 -0
- package/dist/delivery-policy.js +105 -0
- package/dist/delivery-policy.js.map +1 -0
- package/dist/directory-lake-keep.d.ts +9 -0
- package/dist/directory-lake-keep.d.ts.map +1 -0
- package/dist/directory-lake-keep.js +331 -0
- package/dist/directory-lake-keep.js.map +1 -0
- package/dist/directory-lake-projection.d.ts +50 -0
- package/dist/directory-lake-projection.d.ts.map +1 -0
- package/dist/directory-lake-projection.js +143 -0
- package/dist/directory-lake-projection.js.map +1 -0
- package/dist/directory-lake.d.ts +11 -1
- package/dist/directory-lake.d.ts.map +1 -1
- package/dist/directory-lake.js +3 -1
- package/dist/directory-lake.js.map +1 -1
- package/dist/index.d.ts +19 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/job-run.d.ts +21 -1
- package/dist/job-run.d.ts.map +1 -1
- package/dist/job-run.js +6 -0
- package/dist/job-run.js.map +1 -1
- package/dist/migration-digest.d.ts +2 -2
- package/dist/migration-digest.d.ts.map +1 -1
- package/dist/migration-digest.js +4 -2
- package/dist/migration-digest.js.map +1 -1
- package/dist/migration-fence.d.ts +1 -1
- package/dist/migration-fence.js +3 -3
- package/dist/migration-fence.js.map +1 -1
- package/dist/outbox-prune.d.ts +8 -1
- package/dist/outbox-prune.d.ts.map +1 -1
- package/dist/outbox-prune.js +6 -2
- package/dist/outbox-prune.js.map +1 -1
- package/dist/platform-sweep.d.ts +10 -1
- package/dist/platform-sweep.d.ts.map +1 -1
- package/dist/platform-sweep.js +37 -1
- package/dist/platform-sweep.js.map +1 -1
- package/dist/scope-host.d.ts +58 -8
- package/dist/scope-host.d.ts.map +1 -1
- package/dist/scope-host.js.map +1 -1
- package/dist/spine-guard.d.ts.map +1 -1
- package/dist/spine-guard.js +2 -0
- package/dist/spine-guard.js.map +1 -1
- package/dist/spine-restore.d.ts +14 -2
- package/dist/spine-restore.d.ts.map +1 -1
- package/dist/spine-restore.js.map +1 -1
- package/dist/store-driver-releases.d.ts +12 -3
- package/dist/store-driver-releases.d.ts.map +1 -1
- package/dist/store-driver-releases.js +12 -7
- package/dist/store-driver-releases.js.map +1 -1
- package/dist/subject-keys.d.ts +7 -0
- package/dist/subject-keys.d.ts.map +1 -1
- package/dist/subject-keys.js +29 -5
- package/dist/subject-keys.js.map +1 -1
- package/dist/subject-redaction.d.ts +7 -0
- package/dist/subject-redaction.d.ts.map +1 -1
- package/dist/subject-redaction.js +34 -27
- package/dist/subject-redaction.js.map +1 -1
- package/dist/table-ownership.d.ts +6 -0
- package/dist/table-ownership.d.ts.map +1 -1
- package/dist/table-ownership.js +17 -3
- package/dist/table-ownership.js.map +1 -1
- package/dist/vertical-owners.d.ts +1 -1
- package/dist/vertical-owners.d.ts.map +1 -1
- package/dist/vertical-owners.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The permission gate an attachment target is held to (#473, #3434), in one place so both
|
|
3
|
+
* adapters judge a declaration, and a remove, the same way.
|
|
4
|
+
*
|
|
5
|
+
* - `read` decides `list`, `open`, `openStream` and `search`.
|
|
6
|
+
* - `write` decides `upload` and `remove`. Absent from the declaration, it is `read`.
|
|
7
|
+
* - `remove`, when declared, admits a REMOVE beside `write` and nothing else (#3434). It is the
|
|
8
|
+
* key a retention schedule holds to delete a file it never uploaded, without holding the
|
|
9
|
+
* uploader's key (and so without being able to upload). Declared `holder: 'system'`, it is a
|
|
10
|
+
* key no person can hold.
|
|
11
|
+
*/
|
|
12
|
+
import type { Decision, EntityRef, PermissionKey } from '@substrat-run/contracts';
|
|
13
|
+
/** What a manifest's `attachmentTargets` entry declares about its keys. */
|
|
14
|
+
export interface AttachmentTargetKeys {
|
|
15
|
+
readonly readPermission: PermissionKey;
|
|
16
|
+
readonly writePermission?: PermissionKey;
|
|
17
|
+
readonly removePermission?: PermissionKey;
|
|
18
|
+
}
|
|
19
|
+
/** A target's keys, with the defaults applied. */
|
|
20
|
+
export interface AttachmentGate {
|
|
21
|
+
readonly read: PermissionKey;
|
|
22
|
+
readonly write: PermissionKey;
|
|
23
|
+
readonly remove?: PermissionKey;
|
|
24
|
+
}
|
|
25
|
+
/** The gate a declaration means. */
|
|
26
|
+
export declare function attachmentGateOf(target: AttachmentTargetKeys): AttachmentGate;
|
|
27
|
+
/**
|
|
28
|
+
* Refuse a second declaration of one entity type whose gate differs from the first: who may
|
|
29
|
+
* read or remove an entity's files must not depend on which module registered first. The same
|
|
30
|
+
* gate declared twice is idempotent.
|
|
31
|
+
*/
|
|
32
|
+
export declare function assertSameAttachmentGate(entityType: string, existing: AttachmentGate | undefined, gate: AttachmentGate): void;
|
|
33
|
+
/**
|
|
34
|
+
* Decide a remove: the write key, or else the declared remove key, on the owning entity, as
|
|
35
|
+
* whoever `check` checks as. A refusal names the remove key when one is declared, since that is
|
|
36
|
+
* the narrowest key that would have admitted it, and the write key otherwise.
|
|
37
|
+
*
|
|
38
|
+
* The write key is asked first so a person's remove decides exactly as it did before #3434
|
|
39
|
+
* whenever they hold it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function decideAttachmentRemove(check: (permission: PermissionKey, entity: EntityRef) => Promise<Decision>, gate: AttachmentGate, entity: EntityRef): Promise<Decision>;
|
|
42
|
+
//# sourceMappingURL=attachment-gate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment-gate.d.ts","sourceRoot":"","sources":["../src/attachment-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAElF,2EAA2E;AAC3E,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,cAAc,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,eAAe,CAAC,EAAE,aAAa,CAAC;IACzC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,aAAa,CAAC;CAC3C;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC;CACjC;AAED,oCAAoC;AACpC,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAM7E;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,cAAc,GAAG,SAAS,EACpC,IAAI,EAAE,cAAc,GACnB,IAAI,CAKN;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,KAAK,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,KAAK,OAAO,CAAC,QAAQ,CAAC,EAC1E,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,QAAQ,CAAC,CAInB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** The gate a declaration means. */
|
|
2
|
+
export function attachmentGateOf(target) {
|
|
3
|
+
return {
|
|
4
|
+
read: target.readPermission,
|
|
5
|
+
write: target.writePermission ?? target.readPermission,
|
|
6
|
+
...(target.removePermission !== undefined ? { remove: target.removePermission } : {}),
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Refuse a second declaration of one entity type whose gate differs from the first: who may
|
|
11
|
+
* read or remove an entity's files must not depend on which module registered first. The same
|
|
12
|
+
* gate declared twice is idempotent.
|
|
13
|
+
*/
|
|
14
|
+
export function assertSameAttachmentGate(entityType, existing, gate) {
|
|
15
|
+
if (!existing)
|
|
16
|
+
return;
|
|
17
|
+
if (existing.read === gate.read && existing.write === gate.write && existing.remove === gate.remove)
|
|
18
|
+
return;
|
|
19
|
+
const show = (g) => `${g.read}/${g.write}${g.remove !== undefined ? `/${g.remove}` : ''}`;
|
|
20
|
+
throw new Error(`conflicting attachmentTargets for '${entityType}': (${show(existing)}) vs (${show(gate)})`);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Decide a remove: the write key, or else the declared remove key, on the owning entity, as
|
|
24
|
+
* whoever `check` checks as. A refusal names the remove key when one is declared, since that is
|
|
25
|
+
* the narrowest key that would have admitted it, and the write key otherwise.
|
|
26
|
+
*
|
|
27
|
+
* The write key is asked first so a person's remove decides exactly as it did before #3434
|
|
28
|
+
* whenever they hold it.
|
|
29
|
+
*/
|
|
30
|
+
export async function decideAttachmentRemove(check, gate, entity) {
|
|
31
|
+
const byWrite = await check(gate.write, entity);
|
|
32
|
+
if (byWrite.allowed || gate.remove === undefined || gate.remove === gate.write)
|
|
33
|
+
return byWrite;
|
|
34
|
+
return check(gate.remove, entity);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=attachment-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment-gate.js","sourceRoot":"","sources":["../src/attachment-gate.ts"],"names":[],"mappings":"AA2BA,oCAAoC;AACpC,MAAM,UAAU,gBAAgB,CAAC,MAA4B;IAC3D,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,cAAc;QAC3B,KAAK,EAAE,MAAM,CAAC,eAAe,IAAI,MAAM,CAAC,cAAc;QACtD,GAAG,CAAC,MAAM,CAAC,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACtF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACtC,UAAkB,EAClB,QAAoC,EACpC,IAAoB;IAEpB,IAAI,CAAC,QAAQ;QAAE,OAAO;IACtB,IAAI,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM;QAAE,OAAO;IAC5G,MAAM,IAAI,GAAG,CAAC,CAAiB,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IAC1G,MAAM,IAAI,KAAK,CAAC,sCAAsC,UAAU,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/G,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAA0E,EAC1E,IAAoB,EACpB,MAAiB;IAEjB,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAChD,IAAI,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK;QAAE,OAAO,OAAO,CAAC;IAC/F,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3474 (rfc/broker-and-tenant-isolation.md §9.2, K-70): the delivery broker's EXACT counts, kept per
|
|
3
|
+
* UTC day in its own SQLite and shipped to the lake. Analytics Engine samples at volume, which is
|
|
4
|
+
* enough for trends and alarms (`broker-telemetry.ts`) and not for billing. These are counted in the
|
|
5
|
+
* same transaction as the decision they count, so a count is a fact about the store, never an
|
|
6
|
+
* estimate.
|
|
7
|
+
*
|
|
8
|
+
* **What is counted**, per (day, tenant, scope, channel, receiver, outcome): a message `received`
|
|
9
|
+
* (once, at its first acceptance; a duplicate handoff counts nothing; receiver `''`), and per
|
|
10
|
+
* receiver a delivery `delivered`, an attempt `retried` (a failure the broker will try again; a
|
|
11
|
+
* slow-down spends nothing and counts nothing), a delivery gone `dead`, a dead letter `resent` or
|
|
12
|
+
* `discarded` by a person, and one `expired` unresent. Never content: ids, the channel and the
|
|
13
|
+
* receiver's name.
|
|
14
|
+
*
|
|
15
|
+
* **Shipped, then bounded (K-70).** A row is shipped when its count moves past what the lake has: it
|
|
16
|
+
* carries its whole count, so the lake keeps a key's latest version (`BrokerLakeRow`, the directory's
|
|
17
|
+
* outbox shape, dataset `broker_count_days`). What was shipped is recorded as the count shipped, not
|
|
18
|
+
* as "shipped": a count that moved while the ship was in flight goes again. Shipping is at most
|
|
19
|
+
* every `BROKER_COUNT_SHIP_MS` (D-77's five minutes), from the broker's own alarm, so K-69 holds.
|
|
20
|
+
* A day is dropped once the lake has all of it and it is older than `BROKER_COUNT_KEEP_DAYS` (the
|
|
21
|
+
* current and the previous billing period, as the directory keeps meter days); a day never shipped,
|
|
22
|
+
* because no lake was ever bound, is dropped at `BROKER_COUNT_MAX_DAYS`, so an unbound broker is
|
|
23
|
+
* bounded too.
|
|
24
|
+
*
|
|
25
|
+
* Its table is step 5 of `broker-schema.ts`.
|
|
26
|
+
*/
|
|
27
|
+
import type { BrokerMessageKind, BrokerSql } from './delivery-broker.js';
|
|
28
|
+
/** What happened, as a count names it. */
|
|
29
|
+
export type BrokerCountOutcome = 'received' | 'delivered' | 'retried' | 'dead' | 'resent' | 'discarded' | 'expired';
|
|
30
|
+
export declare const BROKER_COUNT_OUTCOMES: readonly BrokerCountOutcome[];
|
|
31
|
+
/**
|
|
32
|
+
* The Pipelines stream binding a broker ships its counts through, on the app's script. No binding, no
|
|
33
|
+
* ship: the counts are kept, bounded by `BROKER_COUNT_MAX_DAYS`, and the lake has none of them.
|
|
34
|
+
*/
|
|
35
|
+
export declare const BROKER_LAKE_BINDING = "SUBSTRAT_BROKER_LAKE";
|
|
36
|
+
/** The least time between two ships of one broker's counts: D-77's freshness bound. */
|
|
37
|
+
export declare const BROKER_COUNT_SHIP_MS: number;
|
|
38
|
+
/** Days kept once the lake has them all: the current and the previous billing period. */
|
|
39
|
+
export declare const BROKER_COUNT_KEEP_DAYS = 62;
|
|
40
|
+
/** Days kept whatever the lake has: the bound of a broker that never had a lake to ship to. */
|
|
41
|
+
export declare const BROKER_COUNT_MAX_DAYS = 400;
|
|
42
|
+
/** Rows one ship carries; a larger backlog follows in the next. */
|
|
43
|
+
export declare const BROKER_COUNT_SHIP_BATCH = 500;
|
|
44
|
+
/** One count to add. `receiver` is `''` for what is not about a receiver (`received`). */
|
|
45
|
+
export interface BrokerCount {
|
|
46
|
+
tenantId: string;
|
|
47
|
+
scopeId: string;
|
|
48
|
+
channel: BrokerMessageKind;
|
|
49
|
+
receiver: string;
|
|
50
|
+
outcome: BrokerCountOutcome;
|
|
51
|
+
n: number;
|
|
52
|
+
}
|
|
53
|
+
/** One day's count, as the store keeps it. */
|
|
54
|
+
export interface BrokerCountDay extends BrokerCount {
|
|
55
|
+
/** The UTC day, `YYYY-MM-DD`. */
|
|
56
|
+
day: string;
|
|
57
|
+
/** How much of `n` the lake has. */
|
|
58
|
+
shipped: number;
|
|
59
|
+
}
|
|
60
|
+
/** The UTC day of an epoch-ms instant. */
|
|
61
|
+
export declare const utcDay: (at: number) => string;
|
|
62
|
+
/** Add counts for the day of `now`. Run inside the transaction that made the decision counted. */
|
|
63
|
+
export declare function addBrokerCounts(sql: BrokerSql, counts: readonly BrokerCount[], now: number): void;
|
|
64
|
+
/** The counts on or after `since` (a UTC day), oldest first: what a billing read or a test asks. */
|
|
65
|
+
export declare function readBrokerCounts(sql: BrokerSql, since?: string): BrokerCountDay[];
|
|
66
|
+
/** The rows the lake does not have all of yet, oldest change first. */
|
|
67
|
+
export declare function unshippedBrokerCounts(sql: BrokerSql, limit?: number): BrokerCountDay[];
|
|
68
|
+
/** Record that the lake has each row up to the count it was shipped with. Never moves one back. */
|
|
69
|
+
export declare function markBrokerCountsShipped(sql: BrokerSql, rows: readonly BrokerCountDay[]): void;
|
|
70
|
+
/** When the next ship is due: `BROKER_COUNT_SHIP_MS` after the oldest unshipped change, or null with none. */
|
|
71
|
+
export declare function nextBrokerCountShipAt(sql: BrokerSql): number | null;
|
|
72
|
+
/** Drop the days the bounds say are kept long enough. Run in the store's prune. */
|
|
73
|
+
export declare function pruneBrokerCounts(sql: BrokerSql, now: number): void;
|
|
74
|
+
/**
|
|
75
|
+
* One count as the lake gets it: the directory outbox's row shape (`DirectoryLakeRow`), dataset
|
|
76
|
+
* `broker_count_days`, keyed by (day, tenant, app, scope, channel, receiver, outcome). A key's latest
|
|
77
|
+
* version (the greatest `count`) is its count.
|
|
78
|
+
*/
|
|
79
|
+
export interface BrokerLakeRow {
|
|
80
|
+
dataset: 'broker_count_days';
|
|
81
|
+
rowKey: string;
|
|
82
|
+
tenantId: string;
|
|
83
|
+
scopeId: string;
|
|
84
|
+
/** The UTC day counted. */
|
|
85
|
+
at: string;
|
|
86
|
+
/** The outcome counted. */
|
|
87
|
+
kind: BrokerCountOutcome;
|
|
88
|
+
actor: null;
|
|
89
|
+
capturedAt: string;
|
|
90
|
+
/** The count, a JSON object text: `{ day, tenant_id, app, scope_id, channel, receiver, outcome, n }`. */
|
|
91
|
+
row: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Where a broker's counts go: a Pipelines stream on the Durable Object, a recorder in a test. Like
|
|
95
|
+
* `DirectoryLakeSink`, `ship` MUST be durable before it resolves: a resolved ship is what marks the
|
|
96
|
+
* counts shipped, and lets a day be dropped.
|
|
97
|
+
*/
|
|
98
|
+
export interface BrokerLakeSink {
|
|
99
|
+
ship(rows: BrokerLakeRow[]): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
/** The lake rows for some counts of one app's broker. */
|
|
102
|
+
export declare function brokerLakeRows(rows: readonly BrokerCountDay[], app: string, capturedAt: string): BrokerLakeRow[];
|
|
103
|
+
/**
|
|
104
|
+
* Ship one batch of what the lake does not have, and mark it. A sink that throws marks nothing: the
|
|
105
|
+
* rows go again at the next ship. Returns how many rows went.
|
|
106
|
+
*/
|
|
107
|
+
export declare function shipBrokerCounts(sql: BrokerSql, sink: BrokerLakeSink, app: string, now: number): Promise<number>;
|
|
108
|
+
//# sourceMappingURL=broker-counts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-counts.d.ts","sourceRoot":"","sources":["../src/broker-counts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEzE,0CAA0C;AAC1C,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;AAEpH,eAAO,MAAM,qBAAqB,EAAE,SAAS,kBAAkB,EAAmF,CAAC;AAEnJ;;;GAGG;AACH,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D,uFAAuF;AACvF,eAAO,MAAM,oBAAoB,QAAa,CAAC;AAC/C,yFAAyF;AACzF,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB,MAAM,CAAC;AACzC,mEAAmE;AACnE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,0FAA0F;AAC1F,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,CAAC,EAAE,MAAM,CAAC;CACX;AAED,8CAA8C;AAC9C,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,oCAAoC;IACpC,OAA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,CAAC;CAC5C;AAED,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,cAAc,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,aAAa,EAAE,CAchH;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMtH"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export const BROKER_COUNT_OUTCOMES = ['received', 'delivered', 'retried', 'dead', 'resent', 'discarded', 'expired'];
|
|
2
|
+
/**
|
|
3
|
+
* The Pipelines stream binding a broker ships its counts through, on the app's script. No binding, no
|
|
4
|
+
* ship: the counts are kept, bounded by `BROKER_COUNT_MAX_DAYS`, and the lake has none of them.
|
|
5
|
+
*/
|
|
6
|
+
export const BROKER_LAKE_BINDING = 'SUBSTRAT_BROKER_LAKE';
|
|
7
|
+
/** The least time between two ships of one broker's counts: D-77's freshness bound. */
|
|
8
|
+
export const BROKER_COUNT_SHIP_MS = 5 * 60_000;
|
|
9
|
+
/** Days kept once the lake has them all: the current and the previous billing period. */
|
|
10
|
+
export const BROKER_COUNT_KEEP_DAYS = 62;
|
|
11
|
+
/** Days kept whatever the lake has: the bound of a broker that never had a lake to ship to. */
|
|
12
|
+
export const BROKER_COUNT_MAX_DAYS = 400;
|
|
13
|
+
/** Rows one ship carries; a larger backlog follows in the next. */
|
|
14
|
+
export const BROKER_COUNT_SHIP_BATCH = 500;
|
|
15
|
+
/** The UTC day of an epoch-ms instant. */
|
|
16
|
+
export const utcDay = (at) => new Date(at).toISOString().slice(0, 10);
|
|
17
|
+
/** Add counts for the day of `now`. Run inside the transaction that made the decision counted. */
|
|
18
|
+
export function addBrokerCounts(sql, counts, now) {
|
|
19
|
+
const day = utcDay(now);
|
|
20
|
+
for (const c of counts) {
|
|
21
|
+
if (c.n <= 0)
|
|
22
|
+
continue;
|
|
23
|
+
sql.run(`INSERT INTO broker_count_days (day, tenant_id, scope_id, channel, receiver, outcome, n, updated_at)
|
|
24
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
25
|
+
ON CONFLICT (day, tenant_id, scope_id, channel, receiver, outcome)
|
|
26
|
+
DO UPDATE SET n = n + excluded.n, updated_at = excluded.updated_at`, day, c.tenantId, c.scopeId, c.channel, c.receiver, c.outcome, c.n, now);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const dayOf = (r) => ({
|
|
30
|
+
day: r.day,
|
|
31
|
+
tenantId: r.tenant_id,
|
|
32
|
+
scopeId: r.scope_id,
|
|
33
|
+
channel: r.channel,
|
|
34
|
+
receiver: r.receiver,
|
|
35
|
+
outcome: r.outcome,
|
|
36
|
+
n: Number(r.n),
|
|
37
|
+
shipped: Number(r.shipped_n),
|
|
38
|
+
});
|
|
39
|
+
/** The counts on or after `since` (a UTC day), oldest first: what a billing read or a test asks. */
|
|
40
|
+
export function readBrokerCounts(sql, since = '0000-00-00') {
|
|
41
|
+
return sql
|
|
42
|
+
.all(`SELECT day, tenant_id, scope_id, channel, receiver, outcome, n, shipped_n FROM broker_count_days
|
|
43
|
+
WHERE day >= ? ORDER BY day, tenant_id, scope_id, channel, receiver, outcome`, since)
|
|
44
|
+
.map(dayOf);
|
|
45
|
+
}
|
|
46
|
+
/** The rows the lake does not have all of yet, oldest change first. */
|
|
47
|
+
export function unshippedBrokerCounts(sql, limit = BROKER_COUNT_SHIP_BATCH) {
|
|
48
|
+
return sql
|
|
49
|
+
.all(`SELECT day, tenant_id, scope_id, channel, receiver, outcome, n, shipped_n FROM broker_count_days
|
|
50
|
+
WHERE n > shipped_n ORDER BY updated_at LIMIT ?`, limit)
|
|
51
|
+
.map(dayOf);
|
|
52
|
+
}
|
|
53
|
+
/** Record that the lake has each row up to the count it was shipped with. Never moves one back. */
|
|
54
|
+
export function markBrokerCountsShipped(sql, rows) {
|
|
55
|
+
sql.transaction(() => {
|
|
56
|
+
for (const r of rows) {
|
|
57
|
+
sql.run(`UPDATE broker_count_days SET shipped_n = MAX(shipped_n, ?)
|
|
58
|
+
WHERE day = ? AND tenant_id = ? AND scope_id = ? AND channel = ? AND receiver = ? AND outcome = ?`, r.n, r.day, r.tenantId, r.scopeId, r.channel, r.receiver, r.outcome);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/** When the next ship is due: `BROKER_COUNT_SHIP_MS` after the oldest unshipped change, or null with none. */
|
|
63
|
+
export function nextBrokerCountShipAt(sql) {
|
|
64
|
+
const row = sql.all('SELECT MIN(updated_at) AS at FROM broker_count_days WHERE n > shipped_n')[0];
|
|
65
|
+
return row?.at == null ? null : Number(row.at) + BROKER_COUNT_SHIP_MS;
|
|
66
|
+
}
|
|
67
|
+
/** Drop the days the bounds say are kept long enough. Run in the store's prune. */
|
|
68
|
+
export function pruneBrokerCounts(sql, now) {
|
|
69
|
+
const day = (days) => utcDay(now - days * 86_400_000);
|
|
70
|
+
sql.run('DELETE FROM broker_count_days WHERE day < ? AND n = shipped_n', day(BROKER_COUNT_KEEP_DAYS));
|
|
71
|
+
sql.run('DELETE FROM broker_count_days WHERE day < ?', day(BROKER_COUNT_MAX_DAYS));
|
|
72
|
+
}
|
|
73
|
+
/** The lake rows for some counts of one app's broker. */
|
|
74
|
+
export function brokerLakeRows(rows, app, capturedAt) {
|
|
75
|
+
return rows.map((r) => ({
|
|
76
|
+
dataset: 'broker_count_days',
|
|
77
|
+
rowKey: JSON.stringify([r.day, r.tenantId, app, r.scopeId, r.channel, r.receiver, r.outcome]),
|
|
78
|
+
tenantId: r.tenantId,
|
|
79
|
+
scopeId: r.scopeId,
|
|
80
|
+
at: r.day,
|
|
81
|
+
kind: r.outcome,
|
|
82
|
+
actor: null,
|
|
83
|
+
capturedAt,
|
|
84
|
+
row: JSON.stringify({
|
|
85
|
+
day: r.day, tenant_id: r.tenantId, app, scope_id: r.scopeId, channel: r.channel, receiver: r.receiver, outcome: r.outcome, n: r.n,
|
|
86
|
+
}),
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Ship one batch of what the lake does not have, and mark it. A sink that throws marks nothing: the
|
|
91
|
+
* rows go again at the next ship. Returns how many rows went.
|
|
92
|
+
*/
|
|
93
|
+
export async function shipBrokerCounts(sql, sink, app, now) {
|
|
94
|
+
const rows = unshippedBrokerCounts(sql);
|
|
95
|
+
if (rows.length === 0)
|
|
96
|
+
return 0;
|
|
97
|
+
await sink.ship(brokerLakeRows(rows, app, new Date(now).toISOString()));
|
|
98
|
+
markBrokerCountsShipped(sql, rows);
|
|
99
|
+
return rows.length;
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=broker-counts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-counts.js","sourceRoot":"","sources":["../src/broker-counts.ts"],"names":[],"mappings":"AA+BA,MAAM,CAAC,MAAM,qBAAqB,GAAkC,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;AAEnJ;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAE1D,uFAAuF;AACvF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAG,MAAM,CAAC;AAC/C,yFAAyF;AACzF,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,+FAA+F;AAC/F,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AACzC,mEAAmE;AACnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAoB3C,0CAA0C;AAC1C,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE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I,CAAC,CAAC;IACnC,OAAO,IAAI,CAAC,MAAM,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { BrokerMessage, BrokerMessageKind, BrokerSql } from './delivery-broker.js';
|
|
2
|
+
/**
|
|
3
|
+
* Every broker column that can hold a message's content or text about it, which the erasure
|
|
4
|
+
* reaches: the body (`broker_messages`, which is also every dead letter, a `dead` delivery of a row
|
|
5
|
+
* there) and each receiver's error text about delivering it (`broker_deliveries.last_error`). A new
|
|
6
|
+
* column holding either is added here and to `eraseSubjectFromBroker`; the kernel's
|
|
7
|
+
* `broker-erasure.test.ts` refuses a broker column named for a body, payload or error that this list
|
|
8
|
+
* does not name.
|
|
9
|
+
*/
|
|
10
|
+
export declare const BROKER_CONTENT_COLUMNS: readonly {
|
|
11
|
+
table: string;
|
|
12
|
+
column: string;
|
|
13
|
+
}[];
|
|
14
|
+
/** Which subjects' erasure reached one broker, and how many of its messages it rewrote. */
|
|
15
|
+
export interface BrokerErasure {
|
|
16
|
+
messages: number;
|
|
17
|
+
}
|
|
18
|
+
/** One subject's erasure, as a scope asks its broker for it. */
|
|
19
|
+
export interface BrokerErasureTarget {
|
|
20
|
+
tenantId: string;
|
|
21
|
+
scopeId: string;
|
|
22
|
+
subjectId: string;
|
|
23
|
+
/** The erasure's instant, ISO 8601: the one the spine's tombstones carry. */
|
|
24
|
+
at: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One message's body without the subject's content, or null when it carries none of it (or was
|
|
28
|
+
* already redacted). Pure: the erasure and the screen at acceptance both decide with it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function brokerBodyWithoutSubject(kind: BrokerMessageKind, body: string, subjectId: string, at: string): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Erase one subject from one broker: tombstone them for the scope, then rewrite every message of that
|
|
33
|
+
* scope whose body carries them, whatever the state of its deliveries (held, pending, delivered,
|
|
34
|
+
* dead), and put a note in place of each receiver's error text about them. The columns it reaches are
|
|
35
|
+
* `BROKER_CONTENT_COLUMNS`. Synchronous; `BrokerStore.eraseSubject` runs it in one transaction.
|
|
36
|
+
* Idempotent: a re-run finds the bodies rewritten and changes nothing.
|
|
37
|
+
*
|
|
38
|
+
* The read narrows by substring (`instr`), as the spine's intent redaction does, and the predicate
|
|
39
|
+
* decides. A subject id is a ULID, so the JSON text of a body holds it unescaped at any depth.
|
|
40
|
+
* Unindexed, and affordable: it runs once per staff-triggered erasure over what one broker holds, a
|
|
41
|
+
* bounded window (K-70).
|
|
42
|
+
*/
|
|
43
|
+
export declare function eraseSubjectFromBroker(sql: BrokerSql, target: BrokerErasureTarget): BrokerErasure;
|
|
44
|
+
/**
|
|
45
|
+
* The messages of one handoff with every tombstoned subject's content taken out, before the store
|
|
46
|
+
* keeps them: a handoff the scope read before an erasure, arriving after it, stores nothing in the
|
|
47
|
+
* clear. Messages of a scope with no tombstone pass as they are. A tombstone read that fails throws,
|
|
48
|
+
* so the handoff is not acknowledged and the scope retries it: fail closed.
|
|
49
|
+
*/
|
|
50
|
+
export declare function screenErasedSubjects(sql: BrokerSql, messages: readonly BrokerMessage[]): BrokerMessage[];
|
|
51
|
+
//# sourceMappingURL=broker-erasure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-erasure.d.ts","sourceRoot":"","sources":["../src/broker-erasure.ts"],"names":[],"mappings":"AAiDA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIxF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAK9E,CAAC;AAEF,2FAA2F;AAC3F,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,gEAAgE;AAChE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,EAAE,EAAE,MAAM,CAAC;CACZ;AAUD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAwB5H;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,mBAAmB,GAAG,aAAa,CAuCjG;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,aAAa,EAAE,GAAG,aAAa,EAAE,CAuBxG"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subject erasure in the delivery broker's storage (#3484, K-37, K-74).
|
|
3
|
+
*
|
|
4
|
+
* A broker keeps each message a scope hands it as the row's JSON (`BrokerMessage.body`), so an event
|
|
5
|
+
* carrying personal data has a copy there: held, due, retrying, delivered (kept for a duplicate
|
|
6
|
+
* handoff to find) or dead-lettered (#3470: a dead letter is the same row, its delivery `dead`, and a
|
|
7
|
+
* resend delivers the body as stored). This module is how a subject's erasure
|
|
8
|
+
* reaches every one of them, on both adapters, through the `BrokerStore` they share.
|
|
9
|
+
*
|
|
10
|
+
* **Redacted at erasure, not sealed at handoff.** K-37 splits erasure by store: a mutable store is
|
|
11
|
+
* redacted, an immutable copy is sealed under the subject's key. The broker's store is mutable, with
|
|
12
|
+
* bounded retention (K-70), so it is redacted. Sealing at handoff would also put the directory and
|
|
13
|
+
* the platform's `SecretBox` on every message's path: the broker sits in the app's own script, where
|
|
14
|
+
* neither may be reachable (module code in that script reaches every binding it declares), so each
|
|
15
|
+
* handoff would seal and each delivery open through the platform, the per-message hop K-69 and K-74
|
|
16
|
+
* take away. Every receiver but the lake needs the plaintext anyway, and the lake, once it is a
|
|
17
|
+
* receiver, seals what it ships with #3464's mechanism at its own egress.
|
|
18
|
+
*
|
|
19
|
+
* **What a redaction writes is what the spine's writes.** An event's copy loses its `payload` exactly
|
|
20
|
+
* when the scope's outbox row does (`subject_id` matches and `pii_class` is not `none`); an intent's
|
|
21
|
+
* copy is rewritten exactly when the scope's intent journal row is (`intentPayloadCarriesSubject`,
|
|
22
|
+
* and a `sweep-runs` entry's error naming the subject). A copy judged more harshly than its original
|
|
23
|
+
* is an incoherent rule, so the predicates are the spine's own, imported. A body that is not a row the
|
|
24
|
+
* broker can read, and names the subject, is replaced whole: fail closed, since nothing can say what
|
|
25
|
+
* in it is theirs. A message's `last_error`, a receiver's text about delivering it, goes with it.
|
|
26
|
+
*
|
|
27
|
+
* **The tombstone is what closes the race.** A handoff the scope read before its spine was redacted
|
|
28
|
+
* can reach the broker after the broker's own redaction ran (on the Durable Object the scope's handoff
|
|
29
|
+
* awaits an RPC, and the erasure interleaves). So the erasure leaves a tombstone per (tenant, scope,
|
|
30
|
+
* subject), and `BrokerStore.accept` screens every message against the scope's tombstones before it
|
|
31
|
+
* stores it: a tombstoned subject's content is refused, and the message is kept redacted. It is still
|
|
32
|
+
* acknowledged, or the scope's marks would stop at it for good. Tombstones are kept for good, as the
|
|
33
|
+
* directory's key tombstones are: one row per erased subject, and a scope restored from a dump taken
|
|
34
|
+
* before the erasure hands its rows off again.
|
|
35
|
+
*
|
|
36
|
+
* **What stays out of reach** is a delivery already started when the erasure lands: the receiver
|
|
37
|
+
* holds what it was handed, as a consumer mid-dispatch holds the payload (K-37's copies already
|
|
38
|
+
* handed out). A delivery pass re-reads each message just before it goes (`BrokerStore.current`), so
|
|
39
|
+
* the rest of a batch read before the erasure goes redacted.
|
|
40
|
+
*/
|
|
41
|
+
import { SWEEP_RUNS_KIND } from '@substrat-run/contracts';
|
|
42
|
+
import { REDACTED_FAILURE_NOTE, REDACTED_INTENT_MARKER, intentPayloadCarriesSubject, redactedIntentPayload, sweepRunPayloadWithoutSubject, } from './subject-redaction.js';
|
|
43
|
+
import { eraseSubjectFromRelay, RELAY_CONTENT_COLUMNS } from './broker-relay-erasure.js';
|
|
44
|
+
// The tombstones live in `broker_erased_subjects`, step 3 of `BROKER_SCHEMA` (`broker-schema.ts`).
|
|
45
|
+
/**
|
|
46
|
+
* Every broker column that can hold a message's content or text about it, which the erasure
|
|
47
|
+
* reaches: the body (`broker_messages`, which is also every dead letter, a `dead` delivery of a row
|
|
48
|
+
* there) and each receiver's error text about delivering it (`broker_deliveries.last_error`). A new
|
|
49
|
+
* column holding either is added here and to `eraseSubjectFromBroker`; the kernel's
|
|
50
|
+
* `broker-erasure.test.ts` refuses a broker column named for a body, payload or error that this list
|
|
51
|
+
* does not name.
|
|
52
|
+
*/
|
|
53
|
+
export const BROKER_CONTENT_COLUMNS = [
|
|
54
|
+
{ table: 'broker_messages', column: 'body' },
|
|
55
|
+
{ table: 'broker_deliveries', column: 'last_error' },
|
|
56
|
+
// #3469: the relay's requests, replies and failure texts, reached by `eraseSubjectFromRelay`.
|
|
57
|
+
...RELAY_CONTENT_COLUMNS,
|
|
58
|
+
];
|
|
59
|
+
const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
60
|
+
/** A body this module wrote in place of one it could not read: nothing but the marker. */
|
|
61
|
+
const isRedactedWhole = (v) => {
|
|
62
|
+
const keys = Object.keys(v);
|
|
63
|
+
return keys.length === 1 && keys[0] === REDACTED_INTENT_MARKER;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* One message's body without the subject's content, or null when it carries none of it (or was
|
|
67
|
+
* already redacted). Pure: the erasure and the screen at acceptance both decide with it.
|
|
68
|
+
*/
|
|
69
|
+
export function brokerBodyWithoutSubject(kind, body, subjectId, at) {
|
|
70
|
+
let row;
|
|
71
|
+
try {
|
|
72
|
+
row = JSON.parse(body);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
row = undefined;
|
|
76
|
+
}
|
|
77
|
+
// Fail closed: a body the broker cannot read as a row, and that names the subject, goes whole.
|
|
78
|
+
if (!isObject(row))
|
|
79
|
+
return body.includes(subjectId) ? redactedIntentPayload(subjectId, at) : null;
|
|
80
|
+
if (isRedactedWhole(row))
|
|
81
|
+
return null;
|
|
82
|
+
if (kind === 'event') {
|
|
83
|
+
// The outbox's own predicate: `subject_id = ? AND pii_class != 'none' AND payload IS NOT NULL`.
|
|
84
|
+
if (row.subject_id !== subjectId || row.pii_class === 'none' || row.payload === null || row.payload === undefined)
|
|
85
|
+
return null;
|
|
86
|
+
return JSON.stringify({ ...row, payload: null });
|
|
87
|
+
}
|
|
88
|
+
const payload = row.payload;
|
|
89
|
+
if (typeof payload !== 'string')
|
|
90
|
+
return body.includes(subjectId) ? redactedIntentPayload(subjectId, at) : null;
|
|
91
|
+
// The intent journal's own predicates (#1600, #1632).
|
|
92
|
+
if (intentPayloadCarriesSubject(payload, subjectId))
|
|
93
|
+
return JSON.stringify({ ...row, payload: redactedIntentPayload(subjectId, at) });
|
|
94
|
+
if (row.kind === SWEEP_RUNS_KIND) {
|
|
95
|
+
const rewritten = sweepRunPayloadWithoutSubject(payload, subjectId);
|
|
96
|
+
return rewritten === null ? null : JSON.stringify({ ...row, payload: rewritten });
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Erase one subject from one broker: tombstone them for the scope, then rewrite every message of that
|
|
102
|
+
* scope whose body carries them, whatever the state of its deliveries (held, pending, delivered,
|
|
103
|
+
* dead), and put a note in place of each receiver's error text about them. The columns it reaches are
|
|
104
|
+
* `BROKER_CONTENT_COLUMNS`. Synchronous; `BrokerStore.eraseSubject` runs it in one transaction.
|
|
105
|
+
* Idempotent: a re-run finds the bodies rewritten and changes nothing.
|
|
106
|
+
*
|
|
107
|
+
* The read narrows by substring (`instr`), as the spine's intent redaction does, and the predicate
|
|
108
|
+
* decides. A subject id is a ULID, so the JSON text of a body holds it unescaped at any depth.
|
|
109
|
+
* Unindexed, and affordable: it runs once per staff-triggered erasure over what one broker holds, a
|
|
110
|
+
* bounded window (K-70).
|
|
111
|
+
*/
|
|
112
|
+
export function eraseSubjectFromBroker(sql, target) {
|
|
113
|
+
const { tenantId, scopeId, subjectId, at } = target;
|
|
114
|
+
sql.run(`INSERT OR IGNORE INTO broker_erased_subjects (tenant_id, scope_id, subject_id, erased_at) VALUES (?, ?, ?, ?)`, tenantId, scopeId, subjectId, at);
|
|
115
|
+
const rows = sql.all('SELECT id, kind, body FROM broker_messages WHERE tenant_id = ? AND scope_id = ? AND instr(body, ?) > 0', tenantId, scopeId, subjectId);
|
|
116
|
+
const rewritten = [];
|
|
117
|
+
for (const row of rows) {
|
|
118
|
+
const body = brokerBodyWithoutSubject(row.kind, row.body, subjectId, at);
|
|
119
|
+
if (body === null)
|
|
120
|
+
continue;
|
|
121
|
+
sql.run('UPDATE broker_messages SET body = ? WHERE id = ?', body, row.id);
|
|
122
|
+
rewritten.push(row.id);
|
|
123
|
+
}
|
|
124
|
+
// Each receiver's error text goes with its message, and wherever it names the subject (#1632's
|
|
125
|
+
// rule), at every receiver and in every state: pending, delivered, dead.
|
|
126
|
+
sql.run(`UPDATE broker_deliveries SET last_error = ?
|
|
127
|
+
WHERE last_error IS NOT NULL AND last_error != ?
|
|
128
|
+
AND message_id IN (SELECT id FROM broker_messages WHERE tenant_id = ? AND scope_id = ?)
|
|
129
|
+
AND (message_id IN (SELECT value FROM json_each(?)) OR instr(last_error, ?) > 0)`, REDACTED_FAILURE_NOTE, REDACTED_FAILURE_NOTE, tenantId, scopeId, JSON.stringify(rewritten), subjectId);
|
|
130
|
+
// #3469: what the relay keeps for this scope (`broker-relay-erasure.ts`).
|
|
131
|
+
eraseSubjectFromRelay(sql, target, rewritten);
|
|
132
|
+
return { messages: rewritten.length };
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The messages of one handoff with every tombstoned subject's content taken out, before the store
|
|
136
|
+
* keeps them: a handoff the scope read before an erasure, arriving after it, stores nothing in the
|
|
137
|
+
* clear. Messages of a scope with no tombstone pass as they are. A tombstone read that fails throws,
|
|
138
|
+
* so the handoff is not acknowledged and the scope retries it: fail closed.
|
|
139
|
+
*/
|
|
140
|
+
export function screenErasedSubjects(sql, messages) {
|
|
141
|
+
const tombstones = new Map();
|
|
142
|
+
const of = (m) => {
|
|
143
|
+
const key = `${m.tenantId}/${m.scopeId}`;
|
|
144
|
+
let found = tombstones.get(key);
|
|
145
|
+
if (!found) {
|
|
146
|
+
found = sql.all('SELECT subject_id, erased_at FROM broker_erased_subjects WHERE tenant_id = ? AND scope_id = ?', m.tenantId, m.scopeId);
|
|
147
|
+
tombstones.set(key, found);
|
|
148
|
+
}
|
|
149
|
+
return found;
|
|
150
|
+
};
|
|
151
|
+
return messages.map((m) => {
|
|
152
|
+
let body = m.body;
|
|
153
|
+
for (const t of of(m)) {
|
|
154
|
+
if (!body.includes(t.subject_id))
|
|
155
|
+
continue;
|
|
156
|
+
body = brokerBodyWithoutSubject(m.kind, body, t.subject_id, t.erased_at) ?? body;
|
|
157
|
+
}
|
|
158
|
+
return body === m.body ? m : { ...m, body };
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=broker-erasure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-erasure.js","sourceRoot":"","sources":["../src/broker-erasure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,2BAA2B,EAC3B,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGzF,mGAAmG;AAE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AAG,GAAG,CAAC,GAAG,CACb,+FAA+F,EAC/F,CAAC,CAAC,QAAQ,EACV,CAAC,CAAC,OAAO,CACV,CAAC;YACF,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IACF,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACxB,IAAI,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;QAClB,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC;gBAAE,SAAS;YAC3C,IAAI,GAAG,wBAAwB,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;QACnF,CAAC;QACD,OAAO,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BrokerSql } from './delivery-broker.js';
|
|
2
|
+
/** The relay's columns that can hold content or text about it, which `BROKER_CONTENT_COLUMNS` lists. */
|
|
3
|
+
export declare const RELAY_CONTENT_COLUMNS: readonly {
|
|
4
|
+
table: string;
|
|
5
|
+
column: string;
|
|
6
|
+
}[];
|
|
7
|
+
/** A request's or reply's body without the subject: the marker when it names them, else null. */
|
|
8
|
+
export declare function relayBodyWithoutSubject(body: unknown, subjectId: string, at: string): unknown | null;
|
|
9
|
+
/** A body about to be stored for a scope, with every subject tombstoned there taken out of it. */
|
|
10
|
+
export declare function screenRelayBody(sql: BrokerSql, tenantId: string, scopeId: string, body: unknown): unknown;
|
|
11
|
+
/**
|
|
12
|
+
* A failure's text about to be stored for a scope: the redacted note when it names a subject tombstoned
|
|
13
|
+
* there. A call that was out when the erasure ran may fail with the content in its message, and that
|
|
14
|
+
* text is written after the erasure's own rewrite.
|
|
15
|
+
*/
|
|
16
|
+
export declare function screenRelayError(sql: BrokerSql, tenantId: string, scopeId: string, text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Erase one subject from the relay's tables, for one scope of this app. `rewritten` is the message
|
|
19
|
+
* ids `eraseSubjectFromBroker` redacted, whose hops' error texts go with them. Idempotent.
|
|
20
|
+
*/
|
|
21
|
+
export declare function eraseSubjectFromRelay(sql: BrokerSql, target: {
|
|
22
|
+
tenantId: string;
|
|
23
|
+
scopeId: string;
|
|
24
|
+
subjectId: string;
|
|
25
|
+
at: string;
|
|
26
|
+
}, rewritten: readonly string[]): void;
|
|
27
|
+
//# sourceMappingURL=broker-relay-erasure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker-relay-erasure.d.ts","sourceRoot":"","sources":["../src/broker-relay-erasure.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,wGAAwG;AACxG,eAAO,MAAM,qBAAqB,EAAE,SAAS;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,EAQ7E,CAAC;AAkBF,iGAAiG;AACjG,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAGpG;AAED,kGAAkG;AAClG,wBAAgB,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAYzG;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CASxG;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,SAAS,EACd,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EAC5E,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,IAAI,CAqEN"}
|