@cloudhal/comments 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +86 -2
  3. package/dist/src/client/comments.browser.js +245 -0
  4. package/dist/src/client/index.d.ts +19 -0
  5. package/dist/src/client/index.js +39 -0
  6. package/dist/src/client/solver.browser.js +118 -0
  7. package/dist/src/crypto.d.ts +64 -0
  8. package/dist/src/crypto.js +170 -0
  9. package/dist/src/errors.d.ts +38 -0
  10. package/dist/src/errors.js +61 -0
  11. package/dist/src/fixtures/comment-text.json +335 -0
  12. package/dist/src/hashes.d.ts +70 -0
  13. package/dist/src/hashes.js +191 -0
  14. package/dist/src/index.d.ts +24 -0
  15. package/dist/src/index.js +24 -0
  16. package/dist/src/limits.d.ts +73 -0
  17. package/dist/src/limits.js +227 -0
  18. package/dist/src/linkify.d.ts +53 -0
  19. package/dist/src/linkify.js +142 -0
  20. package/dist/src/model.d.ts +287 -0
  21. package/dist/src/model.js +341 -0
  22. package/dist/src/normalize.d.ts +17 -0
  23. package/dist/src/normalize.js +125 -0
  24. package/dist/src/pipeline.d.ts +176 -0
  25. package/dist/src/pipeline.js +898 -0
  26. package/dist/src/pow.d.ts +86 -0
  27. package/dist/src/pow.js +239 -0
  28. package/dist/src/purge.d.ts +87 -0
  29. package/dist/src/purge.js +186 -0
  30. package/dist/src/retention.d.ts +32 -0
  31. package/dist/src/retention.js +106 -0
  32. package/dist/src/rules.d.ts +68 -0
  33. package/dist/src/rules.js +218 -0
  34. package/dist/src/settings.d.ts +108 -0
  35. package/dist/src/settings.js +347 -0
  36. package/dist/src/sql/index.d.ts +7 -0
  37. package/dist/src/sql/index.js +29 -0
  38. package/dist/src/sql/portability.d.ts +113 -0
  39. package/dist/src/sql/portability.js +514 -0
  40. package/dist/src/sql/rows.d.ts +54 -0
  41. package/dist/src/sql/rows.js +145 -0
  42. package/dist/src/sql/store.d.ts +312 -0
  43. package/dist/src/sql/store.js +2111 -0
  44. package/dist/src/thread.d.ts +35 -0
  45. package/dist/src/thread.js +64 -0
  46. package/package.json +61 -3
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Row ↔ record mapping for the comment tables. `toComment` is the only way a `comments` row
3
+ * leaves the store, and it reads none of `email_id`, `ip_hmac`, `challenge_id`, `proof` or `op`,
4
+ * so no returned record can carry them (invariant C1).
5
+ */
6
+
7
+ import { CommentSettingsError } from "../errors.js";
8
+ import { num } from "../model.js";
9
+ import {
10
+
11
+ clientDataDays,
12
+ DEFAULT_RETENTION,
13
+ defaultCommentSettings,
14
+
15
+ } from "../settings.js";
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+ const parse = (text ) =>
42
+ text === null || text === undefined ? undefined : (JSON.parse(text) );
43
+
44
+ export function toComment(r ) {
45
+ const labels = parse (r.labels) ?? [];
46
+ const origin = parse (r.origin);
47
+ const moderation = parse (r.moderation);
48
+ return {
49
+ schemaVersion: 1,
50
+ id: r.id,
51
+ siteId: r.site_id,
52
+ nodeId: r.node_id,
53
+ ...(r.parent_id ? { parentId: r.parent_id } : {}),
54
+ ...(r.in_reply_to_id ? { inReplyToId: r.in_reply_to_id } : {}),
55
+ source: r.source ,
56
+ ...(origin ? { origin } : {}),
57
+ author: JSON.parse(r.author) ,
58
+ ...(r.body !== null ? { body: { format: "text", text: r.body } } : {}),
59
+ status: r.status ,
60
+ ...(labels.length > 0 ? { labels } : {}),
61
+ ...(moderation ? { moderation } : {}),
62
+ createdAt: r.created_at,
63
+ ...(r.edited_at ? { editedAt: r.edited_at } : {}),
64
+ rev: num(r.rev),
65
+ };
66
+ }
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ /** Stored retention over the defaults; `clientDataDays` never above the 30-day ceiling (§9.1). */
90
+ function storedRetention(stored ) {
91
+ const r = { ...DEFAULT_RETENTION, ...stored };
92
+ return { ...r, clientDataDays: clientDataDays(r) };
93
+ }
94
+
95
+ export function toSettings(r ) {
96
+ const base = defaultCommentSettings(r.site_id);
97
+ try {
98
+ return {
99
+ ...base,
100
+ enabled: num(r.enabled) === 1,
101
+ showWhenOff: num(r.show_when_off) === 1,
102
+ collections: JSON.parse(r.collections) ,
103
+ closeAfterDays: r.close_after_days === null ? null : num(r.close_after_days),
104
+ protection: r.protection === "turnstile" ? "turnstile" : "pow",
105
+ turnstileSiteKey: r.turnstile_site_key,
106
+ // bit 0: allowed; bit 1: also while Turnstile is on (no migration: one INTEGER column)
107
+ allowWithoutScript: (num(r.allow_without_script) & 1) === 1,
108
+ allowWithoutScriptWithTurnstile: (num(r.allow_without_script) & 2) === 2,
109
+ linkLimit: num(r.link_limit),
110
+ watchWords: JSON.parse(r.watch_words) ,
111
+ blockedWords: JSON.parse(r.blocked_words) ,
112
+ dailyCap: num(r.daily_cap),
113
+ aiLabels: r.ai_labels === "workers-ai" ? "workers-ai" : "off",
114
+ retention: storedRetention(JSON.parse(r.retention) ),
115
+ planHint: r.plan_hint === "free" || r.plan_hint === "paid" ? r.plan_hint : null,
116
+ rev: num(r.rev),
117
+ updatedAt: r.updated_at,
118
+ updatedBy: r.updated_by,
119
+ };
120
+ } catch (cause) {
121
+ throw new CommentSettingsError(`stored comment settings are unreadable: ${String(cause)}`);
122
+ }
123
+ }
124
+
125
+ export function settingsValues(s ) {
126
+ return [
127
+ s.enabled ? 1 : 0,
128
+ s.showWhenOff ? 1 : 0,
129
+ JSON.stringify(s.collections),
130
+ s.closeAfterDays,
131
+ s.protection,
132
+ s.turnstileSiteKey,
133
+ (s.allowWithoutScript ? 1 : 0) | (s.allowWithoutScriptWithTurnstile ? 2 : 0),
134
+ s.linkLimit,
135
+ JSON.stringify(s.watchWords),
136
+ JSON.stringify(s.blockedWords),
137
+ s.dailyCap,
138
+ s.aiLabels,
139
+ JSON.stringify(s.retention),
140
+ s.planHint,
141
+ ];
142
+ }
143
+
144
+ export const SETTINGS_COLUMNS =
145
+ "enabled, show_when_off, collections, close_after_days, protection, turnstile_site_key, allow_without_script, link_limit, watch_words, blocked_words, daily_cap, ai_labels, retention, plan_hint";
@@ -0,0 +1,312 @@
1
+ /**
2
+ * `SqlCommentStore` — the comment tables of migration `0016_comments` through `SqlDriver` (SQLite
3
+ * locally and on Node, D1 on Cloudflare). Worker-safe.
4
+ *
5
+ * Writes follow RFC-0007 §4.4 and AGENTS.md rule 4: no interactive transactions, every write is
6
+ * one statement or one atomic `batch()`, and statements that follow a compare-and-swap in the
7
+ * same batch are guarded on what that CAS wrote (a fresh operation id `op` and the new content
8
+ * `hash`), never on `rev + 1`. Statement counts per path (asserted by the conformance suite):
9
+ *
10
+ * | Path | Statements |
11
+ * |---|---|
12
+ * | submit / report | 1–2 (+1 the first time a month's salt is stored) |
13
+ * | moderate (1–50 ids) | 2–3 + audit, however many comments |
14
+ * | label (1–50 ids) | 2 + audit |
15
+ * | staff reply | 3 + audit |
16
+ * | settings | 1 |
17
+ * | thread | 1–2 + audit |
18
+ * | erase | ≤ 5 + audit per 200 comments |
19
+ *
20
+ * Bulk statements pass their per-row data as one JSON parameter read with `json_each`, so they
21
+ * stay far below D1's 100 bound parameters whatever the number of comments.
22
+ */
23
+ import type { Actor, Comment } from "@cloudhal/core-contracts";
24
+ import type { SqlDriver } from "@cloudhal/storage";
25
+ import { type CommentKeys } from "../crypto.js";
26
+ import { type AuditStatement, type BanSubject, type CommentBan, type CommentCounts, type CommentEvent, type Commenter, type CommentId, type CommentQuery, type CommentReport, type CountQuery, type EraseResult, type EraseTarget, type LabelName, type LabelOp, type ModerationOp, type ModerationResult, type PreparedReport, type PreparedSubmission, type ReasonCode, type RenderPage, type StaffReply, type SubmitResult, type ThreadInput, type ThreadRow, type ThreadState } from "../model.js";
27
+ import type { SubmissionStore } from "../pipeline.js";
28
+ import { type PurgeLogEntry, type PurgePriority, type PurgeQueueRow } from "../purge.js";
29
+ import { type RetentionPlan, type RetentionReport } from "../retention.js";
30
+ import { type CommentSettings, type CommentSettingsInput } from "../settings.js";
31
+ export interface SqlCommentStoreOptions {
32
+ readonly now?: () => Date;
33
+ }
34
+ /** Thread write options: the purge the change needs (the caller knows the effective states). */
35
+ export interface PutThreadOptions {
36
+ readonly purge?: PurgePriority | null;
37
+ readonly audit?: readonly AuditStatement[];
38
+ }
39
+ /** What `comments_summary` and Studio's "Today" read (RFC-0007 §11.1): counts, never reader text. */
40
+ export interface CommentSummaryStats {
41
+ /** Guest comments created since `since`. */
42
+ readonly newComments: number;
43
+ /** Entries with the most new guest comments since `since`, at most 10. */
44
+ readonly busiest: readonly {
45
+ readonly nodeId: string;
46
+ readonly comments: number;
47
+ }[];
48
+ /** Labels on comments created since `since`. */
49
+ readonly labels: Readonly<Partial<Record<LabelName, number>>>;
50
+ /** Pending comments of any age: how many, the oldest and the median creation time. */
51
+ readonly pending: {
52
+ readonly count: number;
53
+ readonly oldestAt: string | null;
54
+ readonly medianAt: string | null;
55
+ };
56
+ /**
57
+ * Pending or approved comments since `since` labelled `question` or `needs-reply` that no staff
58
+ * reply answers yet.
59
+ */
60
+ readonly unansweredQuestions: number;
61
+ }
62
+ export interface BanInput {
63
+ /** The comment whose author is banned; the store resolves its hashes. */
64
+ readonly commentId: CommentId;
65
+ readonly subjects: readonly BanSubject[];
66
+ /** `null` = until lifted. */
67
+ readonly until: string | null;
68
+ readonly reasonCode: ReasonCode;
69
+ readonly note?: string;
70
+ readonly by: Actor;
71
+ }
72
+ export declare class SqlCommentStore implements SubmissionStore {
73
+ #private;
74
+ readonly sql: SqlDriver;
75
+ constructor(sql: SqlDriver, options?: SqlCommentStoreOptions);
76
+ /** A site's settings: the stored row, or the defaults (`rev: 0`, comments off). */
77
+ settings(siteId: string): Promise<CommentSettings>;
78
+ /**
79
+ * CAS on `rev` (one statement): `rev` 0 inserts the first row, later writes need the current
80
+ * `rev`. A stale `rev` throws `CommentConflictError` and changes nothing.
81
+ */
82
+ putSettings(siteId: string, input: CommentSettingsInput, rev: number, by: string): Promise<{
83
+ before: CommentSettings;
84
+ after: CommentSettings;
85
+ }>;
86
+ /** Stores an owner-supplied secret, encrypted (write-only through the API). */
87
+ putSecret(siteId: string, name: string, value: string, keys: CommentKeys, by: string): Promise<void>;
88
+ /** The decrypted secret (site Worker only), or `null`. */
89
+ readSecret(siteId: string, name: string, keys: CommentKeys): Promise<string | null>;
90
+ /** Whether a secret is stored and when (Studio shows "Saved"), never its value. */
91
+ secretInfo(siteId: string, name: string): Promise<{
92
+ updatedAt: string;
93
+ updatedBy: string;
94
+ } | null>;
95
+ deleteSecret(siteId: string, name: string): Promise<boolean>;
96
+ thread(siteId: string, nodeId: string): Promise<ThreadRow | null>;
97
+ /**
98
+ * Sets an entry's thread override with CAS on `rev` (`0` when no row exists). The purge row the
99
+ * change needs (`options.purge`, default `normal`; `hidden` should pass `takedown`) is upserted
100
+ * in the same batch, guarded on what the CAS wrote.
101
+ */
102
+ putThread(siteId: string, nodeId: string, input: ThreadInput, rev: number, by: string, options?: PutThreadOptions): Promise<ThreadRow>;
103
+ approvedComment(siteId: string, commentId: string): Promise<{
104
+ id: string;
105
+ nodeId: string;
106
+ parentId: string | null;
107
+ } | null>;
108
+ readSalt(month: string): Promise<string | undefined>;
109
+ clientActivity(siteId: string, ipHmac: string, since: {
110
+ hour: string;
111
+ day: string;
112
+ noScript: string;
113
+ }): Promise<{
114
+ hour: number;
115
+ day: number;
116
+ noScript: number;
117
+ }>;
118
+ isDuplicate(siteId: string, nodeId: string, text: string, since: string): Promise<boolean>;
119
+ storedSince(siteId: string, since: string): Promise<{
120
+ total: number;
121
+ withoutScript: number;
122
+ }>;
123
+ pendingOnEntry(siteId: string, nodeId: string): Promise<number>;
124
+ isBanned(siteId: string, subjects: {
125
+ emailHmac?: string;
126
+ ipHmac?: string;
127
+ }, now: string): Promise<boolean>;
128
+ reportActivity(siteId: string, ipHmac: string | null, since: {
129
+ hour: string;
130
+ day: string;
131
+ }): Promise<{
132
+ clientHour: number;
133
+ siteDay: number;
134
+ }>;
135
+ /**
136
+ * Stores a guest comment (§6.2 step 12) in one batch: the commenter email row when given
137
+ * (`INSERT OR IGNORE`, one row per address and site) and the comment, whose `email_id` comes from
138
+ * a sub-select. A replayed challenge hits the unique index on `challenge_id` and is answered
139
+ * `{ duplicate: true }` with nothing written.
140
+ */
141
+ submit(siteId: string, p: PreparedSubmission): Promise<SubmitResult>;
142
+ /** Stores a report (§6.6) of a comment that is still approved; a report never changes it. */
143
+ report(siteId: string, p: PreparedReport): Promise<SubmitResult>;
144
+ get(siteId: string, id: string): Promise<Comment | null>;
145
+ /** Several comments of a site in one read (≤ 50 ids; unknown ids are left out). */
146
+ getMany(siteId: string, ids: readonly string[]): Promise<Comment[]>;
147
+ /** Comments of a site, newest first by default, keyset-paginated (§11.1 `list_comments`). */
148
+ list(siteId: string, q?: CommentQuery): Promise<{
149
+ comments: Comment[];
150
+ nextCursor?: string;
151
+ }>;
152
+ /** A thread in display order (§4.3): top-level oldest first, each followed by its replies. */
153
+ threadComments(siteId: string, nodeId: string, options?: {
154
+ includePending?: boolean;
155
+ }): Promise<Comment[]>;
156
+ /**
157
+ * One rendered page of approved comments (§8.1): up to 50 top-level comments, oldest first, with
158
+ * their approved replies. A top-level comment that is no longer public but has approved replies
159
+ * renders as "removed". `page` past the end returns no items (the renderer answers 404).
160
+ */
161
+ renderPage(siteId: string, nodeId: string, page?: number): Promise<RenderPage>;
162
+ /** Counts by status and open reports, optionally for some entries (indexed COUNTs). */
163
+ counts(siteId: string, q?: CountQuery): Promise<CommentCounts>;
164
+ /** Entries of a site that have comments (the hourly job looks for deleted entries among them). */
165
+ nodeIds(siteId: string): Promise<string[]>;
166
+ /** Every thread override of a site (the hourly job computes closing times from them). */
167
+ threads(siteId: string): Promise<ThreadRow[]>;
168
+ /**
169
+ * Activity since `since` for summaries (RFC-0007 §11.1 `comments_summary`): five indexed reads,
170
+ * counts only. `nodeIds` limits it to some entries (an Author's own).
171
+ */
172
+ summary(siteId: string, since: string, q?: {
173
+ readonly nodeIds?: readonly string[];
174
+ }): Promise<CommentSummaryStats>;
175
+ /** The `cm1:` binding of an approval to these comments and threads (§10.3). */
176
+ stateHash(siteId: string, ids: readonly string[], threads: readonly {
177
+ readonly nodeId: string;
178
+ readonly state: ThreadState;
179
+ }[]): Promise<string>;
180
+ /** A comment's moderation history (statements of reasons), oldest first. */
181
+ history(siteId: string, commentId: string): Promise<CommentEvent[]>;
182
+ /**
183
+ * Moderates up to 50 comments in one batch of 2–3 statements plus the audit rows (§4.4):
184
+ * a set-based UPDATE marks every comment whose `(id, rev)` still matches with a fresh `op` (and
185
+ * its new `hash`); the events and the purge rows are inserted from the rows carrying that `op`.
186
+ * Each comment is independent: the result says which were done and which met a conflict,
187
+ * were not found, are not the caller's own, or cannot make that transition.
188
+ */
189
+ moderate(siteId: string, op: ModerationOp): Promise<ModerationResult[]>;
190
+ /**
191
+ * Adds and removes advisory labels (§6.7, §11.1) on up to 50 comments: one UPDATE with each
192
+ * comment's new labels and hash, one event insert, plus the audit rows. Labels bump `rev` (an
193
+ * approval requested before a label changed is void) but never change status or purge (C9).
194
+ * Agents add and remove only `agent` labels.
195
+ */
196
+ label(siteId: string, op: LabelOp): Promise<ModerationResult[]>;
197
+ /**
198
+ * A person's reply on the site's behalf (§4.2): stored `approved` at once, under the comment it
199
+ * answers (two levels). One batch: the comment (guarded on its parent still being approved), the
200
+ * `reply` event and the normal purge row (both guarded on the new hash), and the audit rows.
201
+ */
202
+ reply(siteId: string, input: StaffReply): Promise<Comment>;
203
+ /** Edits a person's own staff reply (sets `editedAt`), CAS on `rev`; purges the entry. */
204
+ editReply(siteId: string, id: string, text: string, rev: number, personId: string): Promise<Comment>;
205
+ /** A commenter's id from their address's keyed hash, or from one of their comments. */
206
+ findCommenter(siteId: string, by: {
207
+ emailHmac: string;
208
+ } | {
209
+ commentId: string;
210
+ }): Promise<string | null>;
211
+ /** A commenter with the decrypted address (`commenters:data` routes only, C10). */
212
+ commenter(siteId: string, commenterId: string, keys: CommentKeys): Promise<Commenter | null>;
213
+ /**
214
+ * Several commenters with their decrypted addresses in three reads, whatever their number (a
215
+ * personal-data export page stays inside D1 Free's 50 queries per invocation). Unknown ids are
216
+ * left out; the order is the order of `ids`.
217
+ */
218
+ commenters(siteId: string, ids: readonly string[], keys: CommentKeys): Promise<Commenter[]>;
219
+ /** Every comment linked to a commenter, oldest first, in one read (a commenter's export). */
220
+ commenterComments(siteId: string, commenterId: string): Promise<Comment[]>;
221
+ /**
222
+ * "Ban and hide past comments" (§14): hides the approved comments of a comment's author — every
223
+ * approved comment linked to the same email, or the comment itself when it has none. Runs at
224
+ * most `batches` set-based batches of `batch` comments (each one read and one batch of three
225
+ * statements, with the audit rows in the first), so one request stays inside D1 Free's 50
226
+ * queries per invocation; `more` says approved comments remain (send the request again).
227
+ */
228
+ hideApprovedOf(siteId: string, commentId: string, input: {
229
+ readonly actor: Actor;
230
+ readonly reasonCode: ReasonCode;
231
+ readonly note?: string;
232
+ readonly audit?: readonly AuditStatement[];
233
+ }, o?: {
234
+ readonly batch?: number;
235
+ readonly batches?: number;
236
+ }): Promise<{
237
+ hidden: number;
238
+ nodeIds: string[];
239
+ more: boolean;
240
+ }>;
241
+ /**
242
+ * Erasure (§9.4, GDPR Art. 17), people with `commenters:data` only. `anonymise` (the default)
243
+ * gives every comment the `erased` author and clears its email link, IP hash and challenge;
244
+ * `delete-text` also removes the text (status `deleted`). The commenter's email row is deleted
245
+ * and their reports lose the email. Each comment gets an `erase` event with reason
246
+ * `erasure-request`; approved ones a takedown purge. Up to 200 comments a batch of ≤ 5 statements
247
+ * plus the audit rows (on the last batch).
248
+ */
249
+ erase(siteId: string, target: EraseTarget, mode: "anonymise" | "delete-text", by: Actor, options?: {
250
+ note?: string;
251
+ audit?: readonly AuditStatement[];
252
+ }): Promise<EraseResult>;
253
+ /**
254
+ * Bans a comment's author by email and/or this month's IP hash (§10.1: REST only, people). The
255
+ * store resolves the hashes from the comment, so nobody needs to see an address. An IP ban
256
+ * lasts until the month's salt rotates; a comment whose IP hash was already cleared has none.
257
+ */
258
+ ban(siteId: string, input: BanInput): Promise<CommentBan[]>;
259
+ /**
260
+ * The site's bans, newest first; with `commentId`, only those that match that comment's author
261
+ * (its email's keyed hash or its network hash), so Studio can show and lift a commenter's ban
262
+ * without anyone seeing an address.
263
+ */
264
+ listBans(siteId: string, q?: {
265
+ commentId?: string;
266
+ }): Promise<CommentBan[]>;
267
+ liftBan(siteId: string, banId: string): Promise<boolean>;
268
+ listReports(siteId: string, q?: {
269
+ open?: boolean;
270
+ commentId?: string;
271
+ limit?: number;
272
+ }): Promise<CommentReport[]>;
273
+ /** One report of a site, or `null`. */
274
+ getReport(siteId: string, reportId: string): Promise<CommentReport | null>;
275
+ /** Commenter ids of a site, oldest first (a personal-data export; people only). */
276
+ commenterIds(siteId: string, limit?: number): Promise<string[]>;
277
+ /** Records a person's decision on a report; a resolved report cannot be resolved again (409). */
278
+ resolveReport(siteId: string, reportId: string, resolution: string, by: Actor): Promise<void>;
279
+ readonly purgeQueue: {
280
+ /** A site's queued tags. */
281
+ queued: (siteId: string) => Promise<PurgeQueueRow[]>;
282
+ /** Sites with queued tags (the hourly backstop). */
283
+ sites: () => Promise<string[]>;
284
+ /** Enqueues tags (settings changes, closing threads) in one statement. */
285
+ enqueue: (siteId: string, tags: readonly string[], priority: PurgePriority) => Promise<void>;
286
+ /** Purge requests of the last 60 s (any source), for the shared budget. */
287
+ recent: (now?: Date) => Promise<PurgeLogEntry[]>;
288
+ /** Records a purge request sent by publishing or anything else (the publish path's one statement). */
289
+ log: (source: string, requests?: number, at?: Date) => Promise<void>;
290
+ /**
291
+ * A request for `tags` succeeded: removes the rows not re-enqueued since `sentAt` (a change
292
+ * after the request keeps its row) and logs the request, in one batch.
293
+ */
294
+ sent: (siteId: string, tags: readonly string[], sentAt: Date) => Promise<void>;
295
+ /** A request failed: back off each row (30 s × 2^attempts, ≤ 5 min) and log the attempt. */
296
+ failed: (siteId: string, rows: readonly PurgeQueueRow[], at: Date) => Promise<void>;
297
+ };
298
+ readonly retention: {
299
+ /**
300
+ * Runs a site's retention plan in order, each step one bounded statement (two for client
301
+ * data), stopping when the plan's row budget is spent (`more: true`; the next run continues).
302
+ */
303
+ run: (siteId: string, plan: RetentionPlan) => Promise<RetentionReport>;
304
+ /** Comments, reports and threads of entries deleted ≥ 30 days ago (`deletedEntriesDue`). */
305
+ deleteEntries: (siteId: string, nodeIds: readonly string[], budget?: number) => Promise<number>;
306
+ /** Deployment-wide: salts older than the previous month, purge-log rows older than an hour. */
307
+ runDeployment: (now: Date, oldestMonthToKeep: string) => Promise<{
308
+ salts: number;
309
+ purgeLog: number;
310
+ }>;
311
+ };
312
+ }