@chatwarden/core 0.1.0 → 0.1.2

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 (105) hide show
  1. package/README.md +202 -6
  2. package/dist/src/audit.d.ts +27 -5
  3. package/dist/src/audit.d.ts.map +1 -1
  4. package/dist/src/audit.js +59 -8
  5. package/dist/src/audit.js.map +1 -1
  6. package/dist/src/chat.d.ts +48 -0
  7. package/dist/src/chat.d.ts.map +1 -1
  8. package/dist/src/chat.js +94 -10
  9. package/dist/src/chat.js.map +1 -1
  10. package/dist/src/chatwarden.d.ts +209 -12
  11. package/dist/src/chatwarden.d.ts.map +1 -1
  12. package/dist/src/chatwarden.js +77 -11
  13. package/dist/src/chatwarden.js.map +1 -1
  14. package/dist/src/crypto.d.ts +22 -0
  15. package/dist/src/crypto.d.ts.map +1 -0
  16. package/dist/src/crypto.js +193 -0
  17. package/dist/src/crypto.js.map +1 -0
  18. package/dist/src/decide.d.ts.map +1 -1
  19. package/dist/src/decide.js +2 -4
  20. package/dist/src/decide.js.map +1 -1
  21. package/dist/src/documents.d.ts +12 -2
  22. package/dist/src/documents.d.ts.map +1 -1
  23. package/dist/src/documents.js +56 -34
  24. package/dist/src/documents.js.map +1 -1
  25. package/dist/src/events.d.ts +3 -0
  26. package/dist/src/events.d.ts.map +1 -1
  27. package/dist/src/events.js.map +1 -1
  28. package/dist/src/hasher.js +2 -2
  29. package/dist/src/hasher.js.map +1 -1
  30. package/dist/src/index.d.ts +21 -12
  31. package/dist/src/index.d.ts.map +1 -1
  32. package/dist/src/index.js +11 -6
  33. package/dist/src/index.js.map +1 -1
  34. package/dist/src/ladder.d.ts +2 -0
  35. package/dist/src/ladder.d.ts.map +1 -1
  36. package/dist/src/ladder.js +1 -1
  37. package/dist/src/ladder.js.map +1 -1
  38. package/dist/src/log.d.ts +16 -0
  39. package/dist/src/log.d.ts.map +1 -1
  40. package/dist/src/log.js +34 -0
  41. package/dist/src/log.js.map +1 -1
  42. package/dist/src/notices.js +2 -2
  43. package/dist/src/notices.js.map +1 -1
  44. package/dist/src/policy.d.ts +129 -0
  45. package/dist/src/policy.d.ts.map +1 -0
  46. package/dist/src/policy.js +242 -0
  47. package/dist/src/policy.js.map +1 -0
  48. package/dist/src/profile.d.ts +120 -7
  49. package/dist/src/profile.d.ts.map +1 -1
  50. package/dist/src/profile.js +295 -7
  51. package/dist/src/profile.js.map +1 -1
  52. package/dist/src/reporting.d.ts +127 -0
  53. package/dist/src/reporting.d.ts.map +1 -0
  54. package/dist/src/reporting.js +172 -0
  55. package/dist/src/reporting.js.map +1 -0
  56. package/dist/src/reports.d.ts +80 -4
  57. package/dist/src/reports.d.ts.map +1 -1
  58. package/dist/src/reports.js +122 -8
  59. package/dist/src/reports.js.map +1 -1
  60. package/dist/src/sanctions.js +3 -3
  61. package/dist/src/sanctions.js.map +1 -1
  62. package/dist/src/staffReports.d.ts +17 -5
  63. package/dist/src/staffReports.d.ts.map +1 -1
  64. package/dist/src/staffReports.js +22 -5
  65. package/dist/src/staffReports.js.map +1 -1
  66. package/dist/src/staffViews.d.ts +138 -0
  67. package/dist/src/staffViews.d.ts.map +1 -0
  68. package/dist/src/staffViews.js +205 -0
  69. package/dist/src/staffViews.js.map +1 -0
  70. package/dist/src/strikes.js +2 -2
  71. package/dist/src/strikes.js.map +1 -1
  72. package/dist/src/subjects.js +2 -2
  73. package/dist/src/subjects.js.map +1 -1
  74. package/dist/src/team.d.ts +149 -0
  75. package/dist/src/team.d.ts.map +1 -0
  76. package/dist/src/team.js +385 -0
  77. package/dist/src/team.js.map +1 -0
  78. package/dist/src/types.d.ts +245 -4
  79. package/dist/src/types.d.ts.map +1 -1
  80. package/dist/src/types.js +5 -0
  81. package/dist/src/types.js.map +1 -1
  82. package/package.json +4 -1
  83. package/src/audit.ts +73 -9
  84. package/src/chat.ts +109 -9
  85. package/src/chatwarden.ts +279 -22
  86. package/src/crypto.ts +206 -0
  87. package/src/decide.ts +2 -4
  88. package/src/documents.ts +70 -43
  89. package/src/events.ts +10 -1
  90. package/src/hasher.ts +2 -2
  91. package/src/index.ts +110 -5
  92. package/src/ladder.ts +1 -1
  93. package/src/log.ts +37 -0
  94. package/src/notices.ts +2 -2
  95. package/src/policy.ts +288 -0
  96. package/src/profile.ts +369 -14
  97. package/src/reporting.ts +251 -0
  98. package/src/reports.ts +165 -12
  99. package/src/sanctions.ts +3 -3
  100. package/src/staffReports.ts +33 -7
  101. package/src/staffViews.ts +325 -0
  102. package/src/strikes.ts +2 -2
  103. package/src/subjects.ts +2 -2
  104. package/src/team.ts +422 -0
  105. package/src/types.ts +257 -4
package/README.md CHANGED
@@ -17,7 +17,7 @@ What it does:
17
17
  - **Identity without identifiers.** Client keys and IP addresses are hashed on the way in, and people are tracked by an opaque
18
18
  subject id.
19
19
 
20
- It has no runtime dependencies and imports nothing from `node:` except `node:crypto`.
20
+ It has no runtime dependencies and imports no `node:` module, so it also runs in a browser.
21
21
 
22
22
  Status: pre-release, as-is, no support promise.
23
23
 
@@ -93,7 +93,7 @@ const filed = await cw.reports.submit({
93
93
  roomId: 'lobby',
94
94
  reporterSeat: 'seat-1',
95
95
  targetSeat: 'seat-2',
96
- category: 'harassment',
96
+ reason: 'harassment', // optional: a one-tap report with no reason is fine (see "Reporting settings")
97
97
  note: 'kept at it after I asked them to stop',
98
98
  });
99
99
  console.log(filed.ok ? `report ${filed.reportId} filed` : `not filed: ${filed.refused}`);
@@ -111,20 +111,216 @@ For the moderators' screens and the player's notices, mount the routes in
111
111
  | Part | What it is for |
112
112
  | --- | --- |
113
113
  | `cw.rooms` | `seat`, `seatConnection`, `unseat`, `close`: who is in which seat of which room. |
114
- | `cw.chat.accept(room, seat, text)` | The answer for one line: `{ deliver }` or `{ refuse: { reason } }`. `visibleTo` applies a viewer's mutes. |
114
+ | `cw.chat.accept(room, seat, text)` | The answer for one line: `{ deliver }` or `{ refuse: { reason } }`. `visibleTo` applies a viewer's mutes. `restricted(who)` says whether a person is chat-restricted, for typing indicators. |
115
115
  | `cw.mutes` | A player mutes another player for themselves only. |
116
- | `cw.reports` | `submit` (players), `list` and `get` (staff). |
116
+ | `cw.reports` | `submit` and `addDetail` (players; see "Reporting settings"), `list`, `get` and `reporterRecord` (staff). `reporterRecord(person)` is how the reports a person filed stand: `{ reports, open, actioned, dismissed, badFaith, suspendedUntil, reasonMatched, reasonDecided }`. |
117
117
  | `cw.decide(input)` | A moderator closes a report and writes the sanctions and notices in one transaction. Safe to send twice. |
118
- | `cw.sanctions` | `apply` and `revoke`, for a moderator who acts without a report. |
118
+ | `cw.sanctions` | `apply` and `revoke`, for a moderator who acts without a report. `forPerson(subject)` and `list({ cursor?, limit?, source? })` (staff) read sanctions as `SanctionGroupView`s: one per group, built from the person's own row, so no IP, hash or stored value is in them. |
119
+ | `cw.blocked` | `list({ days })` and `countsByTerm({ days })` (staff), with `days` 1, 7 or 30: the lines the slur filter blocked, with the raw text, and the strikes per term. |
120
+ | `cw.cases` | The team workbench (staff): `claim(person, actor, { takeOver? })` and `release` a soft claim on a person's case (`releaseWhenDone` is what a decision does: it ends the claim only when the person has no other open report, so one case per person is held until its last report is decided), `next(actor, { category? })` to claim the oldest open case nobody holds, `holder` / `holders` to read claims, and `view` / `viewers` for who has a case open. A claim lasts 10 minutes from the last beat on your clock, lives in the store (so several server processes on one database agree, and two moderators racing for one case never both win), and is a courtesy: the core never refuses a decision because of one (the HTTP routes do). Viewing is a 30 second hint kept in this process's memory and never stored; it tracks only people with an open report, and one actor keeps at most 20 cases open. A claimer that loses a database lock race to another process is retried (3 attempts) and gets the normal "claimed" answer. |
121
+ | `cw.changes.token()` | A cheap, opaque change token for the queue. It differs after any report filed or decided, sanction applied or revoked, rule gap closed, claim taken, taken over or released, or saved reason changed, and is the same otherwise (a claim heartbeat does not move it). It is kept in the store, so a restart does not rewind it (the in-memory store is the exception: it starts again at "0"). |
122
+ | `cw.reasons` | Saved decision reasons (staff): `list`, `add({ label, text })`, `update(id, patch)` and `setActive(id, active)`. A label is up to 40 characters, a text up to 500 (counted as characters, an emoji is one), at most 200 reasons; a label holds no control character, a text none but a newline. |
119
123
  | `cw.notices` | A player's pending notices, acknowledgements and "My record". Built so no identifier can leak. |
120
124
  | `cw.doors` | `check` a person at the door (login, join) against bans. |
121
125
  | `cw.names.check` | May a player use this as a name? |
122
126
  | `cw.history`, `cw.suggest` | A person's recent record, and what the preset suggests as the next step. |
123
- | `cw.rules`, `cw.profile`, `cw.limits`, `cw.summary`, `cw.documents` | The rules, standard and numbers in force, and the written code of conduct and guides. |
127
+ | `cw.rules`, `cw.profile`, `cw.limits`, `cw.summary`, `cw.documents` | The rules, standard and numbers in force, and the written code of conduct and guides. `cw.profile` and `cw.summary` are read live: the profile in force is your code's profile with the owner's stored edits on top (see "The editable profile"), so read it when you need it and never keep it. |
128
+ | `cw.policy` | The editable profile: `get`, `save`, `preview`, `reset` and `refresh`. The lengths a moderator is offered, the ladder, the first offences, the repeat rule, the area and severe rules and the guideline outcome texts can be edited at runtime and are stored in your store. |
124
129
  | `cw.gaps`, `cw.audit` | Rule gaps for the periodic review, and the staff audit trail. |
125
130
  | `cw.on(type, listener)` | Events: `report.created`, `report.closed`, `sanction.applied`, `sanction.revoked`, `gap.created`, `auto.restricted`. |
126
131
  | `cw.purge`, `cw.ready`, `cw.flush`, `cw.close` | Housekeeping. |
127
132
 
133
+ ## Deciding a report
134
+
135
+ A moderator reads a report and decides it with one call. `cw.decide` closes the report, writes the sanction, writes the player's
136
+ notice and tells the people involved, all in one transaction, and sending the same decision twice applies nothing twice.
137
+
138
+ ```ts
139
+ import type { DecisionResult } from '@chatwarden/core';
140
+
141
+ // The moderator decides the open report: a warning that shows the player their latest line.
142
+ const report = cw.reports.list({ status: 'open' }).items[0]!;
143
+ const decided: DecisionResult = await cw.decide({
144
+ reportId: report.id,
145
+ verdict: 'upheld', // 'noted', 'no_action' and 'bad_faith' are the others
146
+ actor: 'moderator@example.com', // who decided, for the audit trail
147
+ reason: 'kept insulting a teammate', // private: a player never sees it
148
+ actions: [{ subject: report.targetPerson, kind: 'warning', durationMs: null, rule: 2, lineIds: report.ownLineIds[report.targetPerson]?.slice(-1) }],
149
+ });
150
+ console.log(decided.ok ? `applied ${decided.groups.length} action` : `not applied: ${decided.error}`);
151
+ ```
152
+
153
+ `subject` is the staff reference the report names (`report.targetPerson`); it never goes to a player. `rule` must be an active Community
154
+ Rule, or `'uncovered'` with a `gapNote`. `lineIds` picks up to five of that player's own lines in the report to quote in their notice,
155
+ with blocked words starred out. A timeout is `kind: 'chat'` with `durationMs`. `cw.suggest(subject, level, rule)` says what the preset
156
+ would do next, for a moderator who wants a starting point. A failing store rejects the call, so catch it.
157
+
158
+ ## The editable profile
159
+
160
+ The profile you give `createChatwarden` (a preset and `overrides`) is the **base**. An owner can change part of it while the game
161
+ runs: the lengths a moderator is offered (`durations`, and whether `customDuration` is allowed), the escalation `ladder`, the
162
+ `firstOffense` per conduct level, the `repeat` rule, `areaRules` and `severeRules`, and the outcome text of each written guideline
163
+ tier, and the reporting settings (see "Reporting settings"). The edits are a validated, versioned **layer** kept in your store, and `cw.profile` is the base with that layer on top.
164
+ Profanity handling is not editable: it stays in your code. Sanctions already given are not touched.
165
+
166
+ ```ts
167
+ import { createChatwarden, type Platform } from '@chatwarden/core';
168
+ import { createMemoryStore } from '@chatwarden/store-memory';
169
+
170
+ const platform: Platform = { identify: (ctx) => ctx as { clientKey: string } };
171
+ const cw = await createChatwarden({ store: createMemoryStore(), secret: 'a-long-random-secret', platform, retention: false });
172
+
173
+ const HOUR = 3_600_000;
174
+ const { version } = cw.policy.get(); // 0 until something is saved
175
+
176
+ // What would this suggest for a clean record, a warning, a 24 hour restriction and a 7 day ban? Nothing is saved.
177
+ const layer = { durations: [HOUR, 6 * HOUR, 12 * HOUR, 24 * HOUR], firstOffense: { rude: { kind: 'chat' as const, durationMs: 6 * HOUR } } };
178
+ const preview = cw.policy.preview(layer);
179
+ if (preview.ok) console.log(preview.samples.clean.rude); // { label: 'Restrict chat 6 hours', kind: 'chat', durationMs: 21600000 }
180
+
181
+ // Save it. `version` is the one you loaded: if someone saved since, the answer is { ok: false, error: 'conflict' }.
182
+ const saved = cw.policy.save(layer, { version, actor: 'owner@example.com', reason: 'offer shorter timeouts' });
183
+ if (saved.ok) console.log(cw.profile.durations, saved.changed); // in force at once, here
184
+
185
+ cw.policy.reset('durations'); // put one section back to the base; reset() puts everything back
186
+ ```
187
+
188
+ - **`cw.policy.get()`** returns `{ effective, base, layer, version, canSave }`. `layerError` (`{ path, kind }`) is also there when the stored layer
189
+ cannot be used: it is then ignored, the base stays in force, and one `chatwarden.policy_layer_invalid` line is logged. `kind` is `'unreadable'`
190
+ when the stored text could not be read at all (corrupted, not JSON, not an object), so the owner's edits are gone until they save again, and
191
+ `'invalid'` when it was read but a setting is not valid (a field from a newer kit, say). A save or a full `reset()` repairs either.
192
+ - **`save(layer, { version, actor, reason })`** stores the whole layer: a section you leave out goes back to the base. It answers
193
+ `{ ok: true, version, changed }`, `{ ok: false, error: 'conflict' }` for a stale `version` (nothing is written),
194
+ `{ ok: false, error: 'invalid', path }` for a layer that touches a setting that is not editable or would make the profile invalid
195
+ (`path` names the field, such as `layer.profanity` or `layer.ladder[2].high.durationMs`; no value), and
196
+ `{ ok: false, error: 'unsupported' }` when the store has no `loadPolicyLayer` and `savePolicyLayer`. `actor` and `reason` are
197
+ checked here; `@chatwarden/http` writes them to the audit trail.
198
+ - **`guidelines` is positional.** Entry `i` of the layer's `guidelines` list is the new `outcome` text for tier `i` of the profile's
199
+ own `guidelines` (`null` leaves a tier alone). If you reorder or add tiers in the profile in your code, stored texts keep their
200
+ positions, so they land on the wrong tiers: reset `guidelines` (or save it again) after such a change. A stored list longer than the
201
+ profile's tiers is unusable and reported as `layerError`.
202
+ - **Whole outcomes.** An outcome written as an object in a layer (`firstOffense`, `repeat.outcome`) needs both `kind` and `durationMs`, so a
203
+ stored layer never changes meaning when your base profile does. `areaRules` and `severeRules` list at most 100 rule numbers each.
204
+ - **Types.** `ModerationProfile` is what you write; `durations` and `customDuration` are optional in it, so a profile written for 0.1.1 still
205
+ compiles and works everywhere (`validateProfile`, the document functions, `defineProfile`, `createChatwarden`). What the kit hands back
206
+ (`cw.profile`, `cw.policy.get()`, `defineProfile`, `resolveProfile`) is a `ResolvedProfile` with both filled in, and `cw.documents.policyJson()`'s
207
+ `profile` therefore has the two keys even for a profile that had none.
208
+ - **Audit.** A save and a reset are recorded by `@chatwarden/http` as `policy.update` and `policy.reset` rows whose `detail` is
209
+ `{ sections, reason? }`. If you write your own `Store`, keep and return that `detail` from `insertAudit` and `listAudit`.
210
+ - **A ladder cell without a `label`** gets one from its kind and length: "Restrict chat 6 hours", "Ban from public rooms 12 hours",
211
+ "Full ban 3 days", "Full ban permanent".
212
+ - **`durations`** is a sorted list of lengths, each from 1 millisecond to 365 days, at most 50. It is only the list a moderator is offered:
213
+ `cw.decide` and `cw.sanctions.apply` still accept any valid length. The staff routes in `@chatwarden/http` refuse a length outside
214
+ the list (400 `duration_not_offered`) when `customDuration` is false.
215
+ - **Other processes** see a save within 10 seconds: a read of the profile looks at the stored version at most that often, on your
216
+ `clock`. `cw.policy.refresh()` looks now.
217
+ - **Your own store.** `loadPolicyLayer()` and `savePolicyLayer(layer, expectedVersion)` are optional on `Store`. The second must be
218
+ one atomic conditional write that returns the new version, or `null` when the stored version is not `expectedVersion`. A store
219
+ without them still works; `save` and `reset` answer `unsupported` and the profile stays code-only.
220
+
221
+ ## Reporting settings
222
+
223
+ How players report is part of the profile, so it has defaults and an owner can edit it with the rest (`cw.policy`, section `reporting`). Nothing
224
+ is required: a profile that says nothing about reporting gets the defaults.
225
+
226
+ - **`flow`**: `'one_tap'` (the default: "Report this message" sends at once, and an optional reason and note follow), `'reason_first'`
227
+ (the screen asks for a reason first; the kit takes a report with no reason all the same, only the screen differs) or `'reason_required'`
228
+ (a report with no reason is refused `reason_required`).
229
+ - **`reasons`**: the ordered list a player picks from, 1 to 20 of them. Each is `{ id, label, hint, group, rules, asksNote, enabled }`; only
230
+ `id` (a unique lowercase slug) and `label` are needed when you write one. `rules` are the Community Rule numbers the reason usually
231
+ means: the first citable one is the rule a moderator is suggested, and a decision under any of them counts as "matched" for the reporter's
232
+ accuracy. At least one reason must be on, and `other` can be relabelled and re-mapped but not removed or switched off. The defaults, in
233
+ order: **Chat**: `harassment` (Insults or harassment, CR 2), `hate` (Hate, CR 1), `sexual` (Sexual content, CR 3), `threat` (Threats, CR 2),
234
+ `spam` (Spam or ads, CR 4), `personal_info` (Sharing personal info, CR 2); **Gameplay**: `cheating` (Cheating, CR 5), `griefing` (Throwing or
235
+ griefing, CR 6), `afk` (Leaving or AFK, CR 6); then `other` (Something else, asks for a note).
236
+ - **`thanks`**: what the reporter is told afterwards. Default "Thanks for the report. We'll look into it."
237
+
238
+ ```ts
239
+ // One tap, no reason: accepted. (This is the default flow.)
240
+ await cw.reports.submit({ roomId: 'lobby', reporterSeat: 'seat-1', targetSeat: 'seat-2' });
241
+
242
+ // A reason the studio did not list, or switched off, is refused in every flow.
243
+ await cw.reports.submit({ roomId: 'lobby', reporterSeat: 'seat-1', targetSeat: 'seat-3', reason: 'not_a_reason' }); // { ok: false, refused: 'reason_unknown' }
244
+
245
+ // The one-tap follow-up: an optional reason and note on the same report.
246
+ const res = await cw.reports.addDetail(reportId, 'seat-1', { reason: 'cheating', note: 'speed hacking in the last round' });
247
+ // { ok: true }, or { ok: false, refused: 'not_found' | 'not_reporter' | 'too_late' | 'already_added' | 'reason_unknown' | 'off' }
248
+ ```
249
+
250
+ - **The reason is a hint, never the truth.** It is stored as `reportedReason` (a reason id, or null). What settles a case is the moderator's decision,
251
+ or later the AI read. The staff views show it as "Reported as ..." or "No reason given", and a report with no reason shows the lines and asks the
252
+ moderator which rule applies.
253
+ - **`submit` refusals**, in order: `off`, `reason_required`, `reason_unknown`, `not_player`, `self`, `suspended`, `rate`, `duplicate`. A refused reason
254
+ counts against nothing. The reason is read from the profile at that moment, so an edit applies to the next report.
255
+ - **`addDetail(reportId, reporterSeat, { reason?, note? })`** attaches the follow-up to the report. Only the reporter can add it: `reporterSeat` must be
256
+ the seat the report was filed from and must still hold the reporter in that room. It works once, within ten minutes of the report (exactly ten is
257
+ in time), and only while the report is open. It never changes the target or the excerpt. A reason given replaces the reported reason; a note replaces the
258
+ note; one left out keeps what was there. Refusals: `off` (the kit is off, your store does not support follow-ups because it has no `addReportDetail`, or the store failed), `not_found`, `not_reporter`,
259
+ `too_late`, `already_added`, `reason_unknown`. A call that gives neither a reason nor a note answers `ok: true` and does not use up the one allowed.
260
+ - **The kit has no player report route.** You call `cw.reports.submit` from your own route, and you do the same for `addDetail`: take the reporter's
261
+ seat from your own session (never from the request body) and the report id from what `submit` answered, and pass the player's choice through. The
262
+ player route `GET /rules` in `@chatwarden/http` hands the report screen its flow, enabled reasons and thank-you.
263
+ - **Reporter accuracy.** `cw.reports.reporterRecord(person)` adds `reasonDecided` (decided reports they filed that named a reason) and `reasonMatched` (those
264
+ where the decision cited, against the reported person, a rule in the reason's `rules`). A dismissal never matches. A reason that is no longer in the
265
+ list, and one that maps to no rule (`other` by default, so an honest "Something else" is never counted as inaccurate), cannot be judged and are left out; a
266
+ switched-off one still counts. It reads the newest 200 decided reports. It is read against the reasons in force now. It is a signal for moderators
267
+ and is never used to refuse a report.
268
+ - **From 0.1.1.** `ReportInput.category` is still accepted as an alias of `reason` (the six old ids are valid reasons, `disruption` reads as `griefing`),
269
+ and `reason` wins when both are given; a blank `reason` falls back to `category`. A report's stored `category` is still one of the six old ids, derived from its reason (`'other'` when none), so
270
+ code that reads it keeps working; `ReportCategory` is unchanged. The alias keeps its 0.1.1 leniency: a `category` that is not an enabled reason (unknown, not text, or switched off) is taken and stored as
271
+ `'other'`, as before. Only the new `reason` field is refused (`reason_unknown`). Reports stored before 0.1.2 read their old category as their `reportedReason`.
272
+ **Upgrading:** `ReportRefusal` has two new members (`reason_required`, `reason_unknown`), `addDetail` has its own result type, and `layerError` gains a required
273
+ `kind`; an exhaustive `Record<ReportRefusal, ...>` or a `switch` with a `never` check over them needs the new cases to compile.
274
+ - **Your own store.** `addReportDetail` and `loadReporterDecisions` are optional on `Store`. Without the first, `addDetail` answers `off`; without the
275
+ second, the accuracy counts are 0. `insertReport` must keep `reportedReason`, and `listReports` must apply the `reason` filter (`null` means none).
276
+
277
+ ## Typing indicators
278
+
279
+ Do not show a "typing..." indicator for a player who cannot chat. `cw.chat.restricted(who, { roomId, seatId })` runs the
280
+ same decision as `accept` (a chat restriction, a ban, or the automatic timeout), without sending a line. It is
281
+ synchronous and has no side effects: it spends no rate budget and writes no evidence, strike, event or notice.
282
+
283
+ ```ts
284
+ import type { Chatwarden, RawWho } from '@chatwarden/core';
285
+
286
+ // Call it when a client says "I am typing", after `cw.rooms.seat` for that seat. `who` is what your platform's
287
+ // `identify` returned for this connection on the server, never a key or account the client sent.
288
+ function relayTyping(cw: Chatwarden, who: RawWho, roomId: string, seatId: string, tell: () => void): void {
289
+ const { restricted, until, kind } = cw.chat.restricted(who, { roomId, seatId });
290
+ if (restricted) return; // drop it quietly: do not broadcast their typing
291
+ tell();
292
+ void until; // epoch ms when it ends (null = permanent), only for the person's own sanction
293
+ void kind; // 'chat', 'ban' or 'auto' (the automatic timeout), only for their own sanction
294
+ }
295
+ ```
296
+
297
+ With both `roomId` and `seatId` the answer equals what `accept` would say for that seat. Leave them out and an
298
+ automatic timeout that was kept only in memory (the store could not take it, or a guest with no key and no account earned
299
+ it) is looked up by person instead; a guest cannot be found that way, because one guest cannot be told from another.
300
+ The `gate` option is not consulted: a gate refusal is not a restriction.
301
+
302
+ It is safe to answer a player about themselves from their own client, because it reveals nothing about anyone else. A
303
+ player who is restricted only because they share an address with someone else's sanction gets
304
+ `{ restricted: true, until: null, kind: null }`: they cannot chat, and they are told nothing about the other person. The
305
+ address checked is the one `seat` last recorded for the person (as in `accept`), not `who.ip`, and an address alone finds
306
+ nobody. A lookup that fails reads as `restricted: false` and is logged at most once a minute (error class only, with a count of
307
+ the failures held back).
308
+
309
+ ## Browser support
310
+
311
+ The package imports no `node:` module, so a bundler (esbuild, Vite, webpack) builds it for a browser with nothing external and no
312
+ polyfill. Pair it with [`@chatwarden/store-memory`](https://github.com/hainix/chatwarden/tree/main/packages/store-memory), which
313
+ is also browser-safe, and with `@chatwarden/matcher` for the live matcher. That is what the repository's CI bundles and runs,
314
+ in a context with no `process`, `Buffer` or `require`, through a full report, decision and notice flow.
315
+
316
+ The hashing of client keys and IP addresses uses `node:crypto` when the runtime offers it (looked up at run time through
317
+ `process.getBuiltinModule`, never imported) and a small pure-JS SHA-256 and HMAC-SHA256 where it does not. Both give the same
318
+ bytes, and they match the hashes of 0.1.0, so moving a store between a server and a browser build never unlinks a stored hash.
319
+ The pure-JS path is slower, which only matters for a very large number of lookups. A browser build is meant for tests, demos and
320
+ tools; the kit still decides on a server you control, because anything running on a player's machine can be changed by that
321
+ player. `cw.chat.restricted(who, { roomId, seatId })` (see "Typing indicators") is a plain synchronous call and works the same
322
+ in a browser.
323
+
128
324
  ## Options
129
325
 
130
326
  `createChatwarden(options)`. Only `store`, `secret` and `platform` are required.
@@ -1,3 +1,4 @@
1
+ import type { PolicySection } from './profile.js';
1
2
  import type { Clock, Logger, Store } from './types.js';
2
3
  /** What a staff member may do. Ordered from least to most. */
3
4
  export declare const ROLES: readonly ["moderator", "senior", "owner"];
@@ -6,10 +7,21 @@ export type Role = (typeof ROLES)[number];
6
7
  * The closed list of things the audit trail records. The `term.*` and `exception.*` names also cover the rows the
7
8
  * term editor (`LiveTerms`) wrote before the trail existed.
8
9
  */
9
- export declare const AUDIT_ACTIONS: readonly ["report.view", "report.decide", "sanction.apply", "sanction.revoke", "gap.close", "term.add", "term.update", "term.toggle", "exception.add", "exception.update", "exception.toggle", "history.view", "suggest", "policy.view"];
10
+ export declare const AUDIT_ACTIONS: readonly ["report.view", "report.decide", "sanction.apply", "sanction.revoke", "gap.close", "term.add", "term.update", "term.toggle", "exception.add", "exception.update", "exception.toggle", "history.view", "suggest", "policy.view", "blocked.view", "case.takeover", "reason.add", "reason.update", "reason.toggle", "policy.update", "policy.reset"];
10
11
  export type AuditAction = (typeof AUDIT_ACTIONS)[number];
11
- /** What an entry points at: a report id, a sanction group id, a person (a staff ref), a term id or an exception id. */
12
- export declare const AUDIT_TARGET_TYPES: readonly ["report", "sanction", "person", "term", "exception"];
12
+ /**
13
+ * What a `policy.update` or `policy.reset` row says it did: the editable sections it changed, and the reason the owner gave.
14
+ * The reason is the one free text an audit row may carry (1 to {@link AUDIT_REASON_MAX} characters, trimmed); the sections are
15
+ * names from a closed list. No layer value is ever recorded.
16
+ */
17
+ export interface AuditDetail {
18
+ sections: PolicySection[];
19
+ reason?: string;
20
+ }
21
+ /** The longest reason a policy audit row keeps. */
22
+ export declare const AUDIT_REASON_MAX = 2000;
23
+ /** What an entry points at: a report id, a sanction group id, a person (a staff ref), a term id, an exception id or a saved reason id. */
24
+ export declare const AUDIT_TARGET_TYPES: readonly ["report", "sanction", "person", "term", "exception", "reason"];
13
25
  export type AuditTargetType = (typeof AUDIT_TARGET_TYPES)[number];
14
26
  export interface AuditTarget {
15
27
  type: AuditTargetType;
@@ -30,8 +42,13 @@ export interface AuditRecordInput {
30
42
  role: Role;
31
43
  action: AuditAction;
32
44
  target?: AuditTarget;
45
+ /** Required for `policy.update` and `policy.reset` (and refused for every other action). */
46
+ detail?: AuditDetail;
33
47
  }
34
- /** One entry as the store keeps and returns it. There is no field for chat text, a reason or a note. */
48
+ /**
49
+ * One entry as the store keeps and returns it. There is no field for chat text or a note. The one free text is the `reason` inside
50
+ * the `detail` of a `policy.update` or `policy.reset` row (the owner's own reason for changing the settings).
51
+ */
35
52
  export interface AuditRow {
36
53
  id: string;
37
54
  /** Epoch ms. */
@@ -41,6 +58,8 @@ export interface AuditRow {
41
58
  role: Role | null;
42
59
  action: AuditAction;
43
60
  target: AuditTarget | null;
61
+ /** Only on a `policy.update` or `policy.reset` row. */
62
+ detail?: AuditDetail;
44
63
  }
45
64
  /** What {@link Store.listAudit} takes. */
46
65
  export interface AuditListQuery {
@@ -60,6 +79,8 @@ export interface AuditItem {
60
79
  role: Role | null;
61
80
  action: AuditAction;
62
81
  target?: AuditTarget;
82
+ /** Only on a `policy.update` or `policy.reset` row. */
83
+ detail?: AuditDetail;
63
84
  }
64
85
  /** What `cw.audit.list` takes. `limit` is required. */
65
86
  export interface AuditQuery {
@@ -93,7 +114,8 @@ export declare function decodeAuditCursor(cursor: unknown): {
93
114
  };
94
115
  /**
95
116
  * The staff audit trail: who (actor and role) did what (a name from {@link AUDIT_ACTIONS}) to which id, and when.
96
- * It stores no chat text, reason, note or evidence: there is no field for any, and a target must look like an id.
117
+ * It stores no chat text, note or evidence: there is no field for any, and a target must look like an id. The one free text it
118
+ * keeps is the owner's `reason` in the `detail` of a `policy.update` or `policy.reset` row, next to the section names.
97
119
  */
98
120
  export declare class AuditService {
99
121
  private readonly store;
@@ -1 +1 @@
1
- {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/audit.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEvD,8DAA8D;AAC9D,eAAO,MAAM,KAAK,2CAA4C,CAAC;AAC/D,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1C;;;GAGG;AACH,eAAO,MAAM,aAAa,0OAehB,CAAC;AACX,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,uHAAuH;AACvH,eAAO,MAAM,kBAAkB,gEAAiE,CAAC;AACjG,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED,mGAAmG;AACnG,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H,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,yGAAyG;AACzG,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAQ7E;AA0CD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;gBAEhC,IAAI,EAAE;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE;IAM7E;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO;IAuBxC;;;;OAIG;IACH,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,SAAS;CAiC/B"}
package/dist/src/audit.js CHANGED
@@ -1,4 +1,5 @@
1
- import { randomBytes } from 'node:crypto';
1
+ import { randomId } from './crypto.js';
2
+ import { POLICY_SECTIONS } from './profile.js';
2
3
  import { safeWarn } from './log.js';
3
4
  import { b64urlDecode, b64urlEncode } from './staffReports.js';
4
5
  /** What a staff member may do. Ordered from least to most. */
@@ -22,9 +23,20 @@ export const AUDIT_ACTIONS = [
22
23
  'history.view',
23
24
  'suggest',
24
25
  'policy.view',
26
+ 'blocked.view',
27
+ 'case.takeover',
28
+ 'reason.add',
29
+ 'reason.update',
30
+ 'reason.toggle',
31
+ 'policy.update',
32
+ 'policy.reset',
25
33
  ];
26
- /** What an entry points at: a report id, a sanction group id, a person (a staff ref), a term id or an exception id. */
27
- export const AUDIT_TARGET_TYPES = ['report', 'sanction', 'person', 'term', 'exception'];
34
+ /** The longest reason a policy audit row keeps. */
35
+ export const AUDIT_REASON_MAX = 2000;
36
+ /** The actions whose row carries an {@link AuditDetail}, and the only ones that may. */
37
+ const DETAIL_ACTIONS = ['policy.update', 'policy.reset'];
38
+ /** What an entry points at: a report id, a sanction group id, a person (a staff ref), a term id, an exception id or a saved reason id. */
39
+ export const AUDIT_TARGET_TYPES = ['report', 'sanction', 'person', 'term', 'exception', 'reason'];
28
40
  /** The largest page. */
29
41
  export const AUDIT_PAGE_MAX = 200;
30
42
  /** A list query that cannot be answered: a `before` cursor we did not issue, or an unknown `action` / bad `actor`. */
@@ -40,7 +52,7 @@ const REF_RE = /^[A-Za-z0-9_.:-]{1,64}$/;
40
52
  const ACTOR_RE = /^[A-Za-z0-9_.:@+-]{1,128}$/;
41
53
  /** True when `actor` is a string the audit trail accepts: 1..128 characters of `A-Z a-z 0-9 _ . : @ + -`. */
42
54
  export const isValidAuditActor = (actor) => typeof actor === 'string' && ACTOR_RE.test(actor);
43
- const newId = () => randomBytes(16).toString('base64url');
55
+ const newId = () => randomId(16);
44
56
  const isAction = (v) => typeof v === 'string' && AUDIT_ACTIONS.includes(v);
45
57
  const isRole = (v) => typeof v === 'string' && ROLES.includes(v);
46
58
  const isTargetType = (v) => typeof v === 'string' && AUDIT_TARGET_TYPES.includes(v);
@@ -60,27 +72,64 @@ export function decodeAuditCursor(cursor) {
60
72
  throw new AuditQueryError('before');
61
73
  return { at, id: text.slice(sep + 1) };
62
74
  }
75
+ /** The detail of a policy row, or null when it is not valid: sections from the closed list, an optional reason, nothing else. */
76
+ function parseDetail(detail) {
77
+ if (typeof detail !== 'object' || detail === null || Array.isArray(detail))
78
+ return null;
79
+ const d = detail;
80
+ for (const k of Object.keys(d))
81
+ if (k !== 'sections' && k !== 'reason')
82
+ return null;
83
+ const sections = d.sections;
84
+ if (!Array.isArray(sections))
85
+ return null;
86
+ const known = POLICY_SECTIONS;
87
+ if (!sections.every((x) => typeof x === 'string' && known.includes(x)))
88
+ return null;
89
+ const unique = [...new Set(sections)];
90
+ if (d.reason === undefined)
91
+ return { sections: unique };
92
+ if (typeof d.reason !== 'string')
93
+ return null;
94
+ const reason = d.reason.trim();
95
+ if (reason === '' || reason.length > AUDIT_REASON_MAX)
96
+ return null;
97
+ return { sections: unique, reason };
98
+ }
63
99
  /** Parse the input of `record`; null when anything is off. Copies only the known fields. */
64
100
  function parse(input) {
65
101
  if (typeof input !== 'object' || input === null)
66
102
  return null;
67
- const { actor, role, action, target } = input;
103
+ const { actor, role, action, target, detail } = input;
68
104
  if (typeof actor !== 'string' || !ACTOR_RE.test(actor))
69
105
  return null;
70
106
  if (!isRole(role) || !isAction(action))
71
107
  return null;
108
+ // A policy row must say what it changed; no other row may carry anything but ids.
109
+ let parsedDetail;
110
+ if (DETAIL_ACTIONS.includes(action)) {
111
+ const d = parseDetail(detail);
112
+ if (d === null)
113
+ return null;
114
+ parsedDetail = d;
115
+ }
116
+ else if (detail !== undefined) {
117
+ return null;
118
+ }
119
+ const extra = parsedDetail === undefined ? {} : { detail: parsedDetail };
72
120
  if (target === undefined)
73
- return { actor, role, action };
121
+ return { actor, role, action, ...extra };
74
122
  if (typeof target !== 'object' || target === null)
75
123
  return null;
76
124
  const { type, ref } = target;
77
125
  if (!isTargetType(type) || typeof ref !== 'string' || !REF_RE.test(ref))
78
126
  return null;
79
- return { actor, role, action, target: { type, ref } };
127
+ return { actor, role, action, target: { type, ref }, ...extra };
80
128
  }
81
129
  /**
82
130
  * The staff audit trail: who (actor and role) did what (a name from {@link AUDIT_ACTIONS}) to which id, and when.
83
- * It stores no chat text, reason, note or evidence: there is no field for any, and a target must look like an id.
131
+ * It stores no chat text, note or evidence: there is no field for any, and a target must look like an id. The one free text it
132
+ * keeps is the owner's `reason` in the `detail` of a `policy.update` or `policy.reset` row, next to the section names.
84
133
  */
85
134
  export class AuditService {
86
135
  store;
@@ -109,6 +158,7 @@ export class AuditService {
109
158
  role: parsed.role,
110
159
  action: parsed.action,
111
160
  target: parsed.target ?? null,
161
+ ...(parsed.detail === undefined ? {} : { detail: parsed.detail }),
112
162
  });
113
163
  return true;
114
164
  }
@@ -149,6 +199,7 @@ export class AuditService {
149
199
  role: r.role,
150
200
  action: r.action,
151
201
  ...(r.target === null ? {} : { target: { type: r.target.type, ref: r.target.ref } }),
202
+ ...(r.detail === undefined ? {} : { detail: { sections: [...r.detail.sections], ...(r.detail.reason === undefined ? {} : { reason: r.detail.reason }) } }),
152
203
  })),
153
204
  next: rows.length === limit && last !== undefined ? encodeAuditCursor(last.at, last.id) : null,
154
205
  };
@@ -1 +1 @@
1
- {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../src/audit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAG/D,8DAA8D;AAC9D,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC;AAG/D;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,aAAa;IACb,eAAe;IACf,gBAAgB;IAChB,iBAAiB;IACjB,WAAW;IACX,UAAU;IACV,aAAa;IACb,aAAa;IACb,eAAe;IACf,kBAAkB;IAClB,kBAAkB;IAClB,cAAc;IACd,SAAS;IACT,aAAa;CACL,CAAC;AAGX,uHAAuH;AACvH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAU,CAAC;AA0EjG,wBAAwB;AACxB,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC,sHAAsH;AACtH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAC/B,KAAK,CAAgC;IAC9C,YAAY,KAAoC;QAC9C,KAAK,CAAC,uBAAuB,KAAK,EAAE,CAAC,CAA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;gBACR,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,KAAK,EAAE,CAAC,CAAC,KAAK;gBACd,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,MAAM,EAAE,CAAC,CAAC,MAAM;gBAChB,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC;gBACpF,GAAG,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;aAC3J,CAAC,CACH;YACD,IAAI,EAAE,IAAI,CAAC,MAAM,KAAK,KAAK,IAAI,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI;SAC/F,CAAC;IACJ,CAAC;CACF"}
@@ -101,6 +101,16 @@ export interface ChatServiceDeps {
101
101
  rate: Limits['chatRate'];
102
102
  };
103
103
  }
104
+ /**
105
+ * What {@link ChatService.restricted} answers. `until` is the epoch ms the restriction ends (`null` = permanent, or
106
+ * unknown), `kind` what it is. Both are `null` when the restriction is not the person's own (a shared-IP row of
107
+ * someone else's sanction): they are restricted, and are told nothing about the other person.
108
+ */
109
+ export interface RestrictedAnswer {
110
+ restricted: boolean;
111
+ until: number | null;
112
+ kind: 'chat' | 'ban' | 'auto' | null;
113
+ }
104
114
  export declare class ChatService {
105
115
  private readonly roster;
106
116
  private readonly buffer;
@@ -121,6 +131,8 @@ export declare class ChatService {
121
131
  private readonly autoRestrictRule;
122
132
  private readonly maxLength;
123
133
  private readonly rate;
134
+ /** The typing lookup runs at keystroke rate: its failure line is limited to one a minute. */
135
+ private readonly typingWarn;
124
136
  /**
125
137
  * Automatic restrictions that could not be stored (no subject to put a row on, or the write failed), by
126
138
  * room and seat (see `memKey`), with the epoch ms they end and the person they were earned by. The entry
@@ -142,6 +154,24 @@ export declare class ChatService {
142
154
  * error means visible: a broken mute store must not silence a room.
143
155
  */
144
156
  visibleTo(roomId: string, viewerSeat: string, senderSeat: string): boolean;
157
+ /**
158
+ * Is this person chat-restricted right now? For a typing indicator: show none while `restricted` is true. It runs
159
+ * the same decision as `accept` (`resolveRestriction`), and equals what `accept` would answer for the seat when
160
+ * `roomId` and `seatId` are both given. Without them the in-memory automatic timeout (the one that could not be
161
+ * stored, and every one earned by a guest with no identity) is looked up by person, over `roomId` or over every
162
+ * room, and a guest (no subject) cannot be found at all, since one guest cannot be told from another. The `gate`
163
+ * hook is not consulted: a gate refusal is not a restriction.
164
+ *
165
+ * Safe for a player's own client: it reveals nothing about others. A restriction that only reaches the person
166
+ * through a shared address of someone else's sanction reads `{ restricted: true, until: null, kind: null }`.
167
+ * Call it after the person is seated, with an identity from the platform and never one sent by the client; the
168
+ * address checked is the one the person last had recorded, as in `accept`.
169
+ *
170
+ * Synchronous and a pure read: no rate budget, nothing written, no event, no strike. It logs only a failure (event
171
+ * and error class), at most once a minute with a count of those held back; a failure reads as not restricted.
172
+ * An empty `roomId` or `seatId` counts as not given.
173
+ */
174
+ restricted(subject: SubjectId | null, roomId?: string | null, seatId?: string | null): RestrictedAnswer;
145
175
  private run;
146
176
  /** The gate hook; a throw is a refusal (it is access control, so it fails closed). */
147
177
  private gateAllows;
@@ -156,6 +186,24 @@ export declare class ChatService {
156
186
  * failure is logged and reads as "not restricted".
157
187
  */
158
188
  private activeRestriction;
189
+ /**
190
+ * The in-memory automatic timeout on one seat: its end, or null when there is none, it is over, or the seat now holds a
191
+ * different person (two guests count as the same). The one lookup `accept` and a seat-aware `restricted` share; `sweep`
192
+ * drops an expired entry (`accept` does, a read-only lookup does not).
193
+ */
194
+ private memoryHeldAt;
195
+ /**
196
+ * The in-memory automatic timeout held by a known person, found without a seat (the longest, over `roomId` or over
197
+ * every room). A guest (no subject) is never matched: with no seat there is no telling one guest from another.
198
+ * Read only: an expired entry is skipped, not swept.
199
+ */
200
+ private memoryHeldBy;
201
+ /**
202
+ * THE restriction decision, shared by `accept` (a seat) and `restricted` (a person): the longest of the stored chat
203
+ * restriction, the stored full ban and the in-memory automatic one, whose end `memory` reports (null = none).
204
+ * Permanent beats timed; on a tie the stored one wins.
205
+ */
206
+ private resolveRestriction;
159
207
  /**
160
208
  * Counts a blocked line and, when it earns one, applies the automatic timeout. Never throws: the sender
161
209
  * must still get their refusal, and a broken store must not take the chat path down with it.
@@ -1 +1 @@
1
- {"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EACV,KAAK,EAEL,MAAM,EACN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