@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.
- package/README.md +202 -6
- package/dist/src/audit.d.ts +27 -5
- package/dist/src/audit.d.ts.map +1 -1
- package/dist/src/audit.js +59 -8
- package/dist/src/audit.js.map +1 -1
- package/dist/src/chat.d.ts +48 -0
- package/dist/src/chat.d.ts.map +1 -1
- package/dist/src/chat.js +94 -10
- package/dist/src/chat.js.map +1 -1
- package/dist/src/chatwarden.d.ts +209 -12
- package/dist/src/chatwarden.d.ts.map +1 -1
- package/dist/src/chatwarden.js +77 -11
- package/dist/src/chatwarden.js.map +1 -1
- package/dist/src/crypto.d.ts +22 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +193 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/decide.d.ts.map +1 -1
- package/dist/src/decide.js +2 -4
- package/dist/src/decide.js.map +1 -1
- package/dist/src/documents.d.ts +12 -2
- package/dist/src/documents.d.ts.map +1 -1
- package/dist/src/documents.js +56 -34
- package/dist/src/documents.js.map +1 -1
- package/dist/src/events.d.ts +3 -0
- package/dist/src/events.d.ts.map +1 -1
- package/dist/src/events.js.map +1 -1
- package/dist/src/hasher.js +2 -2
- package/dist/src/hasher.js.map +1 -1
- package/dist/src/index.d.ts +21 -12
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/ladder.d.ts +2 -0
- package/dist/src/ladder.d.ts.map +1 -1
- package/dist/src/ladder.js +1 -1
- package/dist/src/ladder.js.map +1 -1
- package/dist/src/log.d.ts +16 -0
- package/dist/src/log.d.ts.map +1 -1
- package/dist/src/log.js +34 -0
- package/dist/src/log.js.map +1 -1
- package/dist/src/notices.js +2 -2
- package/dist/src/notices.js.map +1 -1
- package/dist/src/policy.d.ts +129 -0
- package/dist/src/policy.d.ts.map +1 -0
- package/dist/src/policy.js +242 -0
- package/dist/src/policy.js.map +1 -0
- package/dist/src/profile.d.ts +120 -7
- package/dist/src/profile.d.ts.map +1 -1
- package/dist/src/profile.js +295 -7
- package/dist/src/profile.js.map +1 -1
- package/dist/src/reporting.d.ts +127 -0
- package/dist/src/reporting.d.ts.map +1 -0
- package/dist/src/reporting.js +172 -0
- package/dist/src/reporting.js.map +1 -0
- package/dist/src/reports.d.ts +80 -4
- package/dist/src/reports.d.ts.map +1 -1
- package/dist/src/reports.js +122 -8
- package/dist/src/reports.js.map +1 -1
- package/dist/src/sanctions.js +3 -3
- package/dist/src/sanctions.js.map +1 -1
- package/dist/src/staffReports.d.ts +17 -5
- package/dist/src/staffReports.d.ts.map +1 -1
- package/dist/src/staffReports.js +22 -5
- package/dist/src/staffReports.js.map +1 -1
- package/dist/src/staffViews.d.ts +138 -0
- package/dist/src/staffViews.d.ts.map +1 -0
- package/dist/src/staffViews.js +205 -0
- package/dist/src/staffViews.js.map +1 -0
- package/dist/src/strikes.js +2 -2
- package/dist/src/strikes.js.map +1 -1
- package/dist/src/subjects.js +2 -2
- package/dist/src/subjects.js.map +1 -1
- package/dist/src/team.d.ts +149 -0
- package/dist/src/team.d.ts.map +1 -0
- package/dist/src/team.js +385 -0
- package/dist/src/team.js.map +1 -0
- package/dist/src/types.d.ts +245 -4
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +5 -0
- package/dist/src/types.js.map +1 -1
- package/package.json +4 -1
- package/src/audit.ts +73 -9
- package/src/chat.ts +109 -9
- package/src/chatwarden.ts +279 -22
- package/src/crypto.ts +206 -0
- package/src/decide.ts +2 -4
- package/src/documents.ts +70 -43
- package/src/events.ts +10 -1
- package/src/hasher.ts +2 -2
- package/src/index.ts +110 -5
- package/src/ladder.ts +1 -1
- package/src/log.ts +37 -0
- package/src/notices.ts +2 -2
- package/src/policy.ts +288 -0
- package/src/profile.ts +369 -14
- package/src/reporting.ts +251 -0
- package/src/reports.ts +165 -12
- package/src/sanctions.ts +3 -3
- package/src/staffReports.ts +33 -7
- package/src/staffViews.ts +325 -0
- package/src/strikes.ts +2 -2
- package/src/subjects.ts +2 -2
- package/src/team.ts +422 -0
- package/src/types.ts +257 -4
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { isValidAuditActor, AUDIT_REASON_MAX } from './audit.js';
|
|
2
|
+
import { suggest } from './ladder.js';
|
|
3
|
+
import { applyPolicyLayer, changedSections, frozenCopy, layerSections, POLICY_SECTIONS, ProfileError } from './profile.js';
|
|
4
|
+
import { playerReporting } from './reporting.js';
|
|
5
|
+
import { errorClass, safeWarn } from './log.js';
|
|
6
|
+
import { retryBusy } from './team.js';
|
|
7
|
+
import { CONDUCT_LEVELS } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* The editable moderation profile at runtime. The profile given in code (a preset plus `overrides`) is the BASE. A moderator's
|
|
10
|
+
* edits are stored in the adopter's own store as a versioned {@link PolicyLayer}; the EFFECTIVE profile is the base with that
|
|
11
|
+
* layer merged on top, validated. Every consumer in the kit reads {@link PolicyService.profileNow} at call time, so a save is
|
|
12
|
+
* seen by the very next suggestion, document or check, and a change another process saved is seen within
|
|
13
|
+
* {@link POLICY_REFRESH_MS}. A stored layer the kit cannot use is ignored (the base stays in force) and reported, never thrown.
|
|
14
|
+
*/
|
|
15
|
+
/** How often a read may look at the store for a newer version: 10 seconds. */
|
|
16
|
+
export const POLICY_REFRESH_MS = 10_000;
|
|
17
|
+
/** The four fixed sample records a preview is computed for. */
|
|
18
|
+
export const PREVIEW_SAMPLES = ['clean', 'oneWarning', 'chat24h', 'ban7d'];
|
|
19
|
+
const HOUR_MS = 3_600_000;
|
|
20
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
21
|
+
/** The records behind the samples, as of `now`: a clean record, one warning, a 24 hour chat restriction, a 7 day ban. */
|
|
22
|
+
function sampleRecords(now) {
|
|
23
|
+
const one = (kind, durationMs) => [
|
|
24
|
+
{ kind, durationMs, startsAt: now - HOUR_MS, revoked: false, automated: false, roomId: null },
|
|
25
|
+
];
|
|
26
|
+
return { clean: [], oneWarning: one('warning', null), chat24h: one('chat', DAY_MS), ban7d: one('ban', 7 * DAY_MS) };
|
|
27
|
+
}
|
|
28
|
+
const isRuleRef = (v) => v === 'uncovered' || (typeof v === 'number' && Number.isSafeInteger(v) && v >= 1);
|
|
29
|
+
export class PolicyService {
|
|
30
|
+
store;
|
|
31
|
+
clock;
|
|
32
|
+
logger;
|
|
33
|
+
base;
|
|
34
|
+
state;
|
|
35
|
+
/** When the store was last looked at (epoch ms), or null before the first read. */
|
|
36
|
+
lastCheck = null;
|
|
37
|
+
constructor(deps) {
|
|
38
|
+
this.store = deps.store;
|
|
39
|
+
this.clock = deps.clock;
|
|
40
|
+
this.logger = deps.logger;
|
|
41
|
+
this.base = deps.base;
|
|
42
|
+
this.state = { effective: applyPolicyLayer(deps.base, {}), layer: frozenCopy({}), version: 0 };
|
|
43
|
+
}
|
|
44
|
+
get supported() {
|
|
45
|
+
return typeof this.store.loadPolicyLayer === 'function' && typeof this.store.savePolicyLayer === 'function';
|
|
46
|
+
}
|
|
47
|
+
/** Read the stored layer once, at creation. A store failure here is the caller's (like every other load). */
|
|
48
|
+
load() {
|
|
49
|
+
if (!this.supported)
|
|
50
|
+
return;
|
|
51
|
+
this.lastCheck = this.clock.now();
|
|
52
|
+
this.adopt(this.store.loadPolicyLayer?.() ?? null);
|
|
53
|
+
}
|
|
54
|
+
/** Make `stored` the layer in force: the effective profile is rebuilt, or the base kept when the layer cannot be used. */
|
|
55
|
+
adopt(stored) {
|
|
56
|
+
const version = stored?.version ?? 0;
|
|
57
|
+
// A row the store could not read as a layer arrives as null (or any non-object): it is a layerError like any unusable layer.
|
|
58
|
+
const raw = stored === null ? {} : stored.layer;
|
|
59
|
+
const layer = frozenCopy(raw);
|
|
60
|
+
try {
|
|
61
|
+
this.state = { effective: applyPolicyLayer(this.base, layer), layer, version };
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (!(err instanceof ProfileError))
|
|
65
|
+
throw err;
|
|
66
|
+
// What `get()` shows is always an object: an unreadable layer reads as empty, with the error beside it.
|
|
67
|
+
const shown = typeof raw === 'object' && raw !== null && !Array.isArray(raw) ? layer : frozenCopy({});
|
|
68
|
+
const kind = typeof raw === 'object' && raw !== null && !Array.isArray(raw) ? 'invalid' : 'unreadable';
|
|
69
|
+
this.state = { effective: this.base, layer: shown, version, layerError: { path: err.path, kind } };
|
|
70
|
+
// Once per version: `adopt` runs only when the stored version changed (or at start-up), never on a plain re-read.
|
|
71
|
+
safeWarn(this.logger, 'chatwarden.policy_layer_invalid', { version, path: err.path });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Look at the store now and adopt a strictly newer version (an older one, say a restored backup, never regresses what is in force). A store failure throws. */
|
|
75
|
+
reload() {
|
|
76
|
+
const stored = this.store.loadPolicyLayer?.() ?? null;
|
|
77
|
+
if ((stored?.version ?? 0) > this.state.version)
|
|
78
|
+
this.adopt(stored);
|
|
79
|
+
}
|
|
80
|
+
/** The cheap check every read does: at most one store look per {@link POLICY_REFRESH_MS}; a failure keeps what is in force. */
|
|
81
|
+
maybeRefresh() {
|
|
82
|
+
if (!this.supported)
|
|
83
|
+
return;
|
|
84
|
+
let now;
|
|
85
|
+
try {
|
|
86
|
+
now = this.clock.now();
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// A clock that went backwards is not "recent": look again.
|
|
92
|
+
if (this.lastCheck !== null && now >= this.lastCheck && now - this.lastCheck < POLICY_REFRESH_MS)
|
|
93
|
+
return;
|
|
94
|
+
this.lastCheck = now;
|
|
95
|
+
try {
|
|
96
|
+
this.reload();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
safeWarn(this.logger, 'chatwarden.policy_refresh_failed', { error: errorClass(err) });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** The profile in force right now. Every consumer calls this, at call time, and never keeps the result. */
|
|
103
|
+
profileNow() {
|
|
104
|
+
this.maybeRefresh();
|
|
105
|
+
return this.state.effective;
|
|
106
|
+
}
|
|
107
|
+
get() {
|
|
108
|
+
this.maybeRefresh();
|
|
109
|
+
const { effective, layer, version, layerError } = this.state;
|
|
110
|
+
return { effective, base: this.base, layer, version, canSave: this.supported, ...(layerError === undefined ? {} : { layerError: { ...layerError } }) };
|
|
111
|
+
}
|
|
112
|
+
/** Look at the store now, whatever the interval. A store failure throws. */
|
|
113
|
+
refresh() {
|
|
114
|
+
if (!this.supported)
|
|
115
|
+
return;
|
|
116
|
+
this.lastCheck = this.clock.now();
|
|
117
|
+
this.reload();
|
|
118
|
+
}
|
|
119
|
+
persist(layer, expected) {
|
|
120
|
+
// What this save changes is judged against the layer at `expected`: ours when we are current, else read it.
|
|
121
|
+
const before = this.state.version === expected ? this.state.layer : (this.store.loadPolicyLayer?.()?.layer ?? {});
|
|
122
|
+
// One conditional write; when another process holds the database lock past the busy timeout it is tried again (as a claim is).
|
|
123
|
+
const next = retryBusy(() => this.store.savePolicyLayer?.(layer, expected) ?? null);
|
|
124
|
+
if (next === null) {
|
|
125
|
+
try {
|
|
126
|
+
this.refresh();
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
safeWarn(this.logger, 'chatwarden.policy_refresh_failed', { error: errorClass(err) });
|
|
130
|
+
}
|
|
131
|
+
return { ok: false, error: 'conflict' };
|
|
132
|
+
}
|
|
133
|
+
const changed = changedSections(before, layer);
|
|
134
|
+
this.lastCheck = this.clock.now();
|
|
135
|
+
this.adopt({ layer, version: next });
|
|
136
|
+
return { ok: true, version: next, changed };
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Replace the stored layer. `layer` is the WHOLE layer wanted: a section left out goes back to the base. Checked in this
|
|
140
|
+
* order: the store must support it (`unsupported`), `version`, `actor` and `reason` (`invalid`, path `version`, `actor` or
|
|
141
|
+
* `reason`), then the layer itself (`invalid`, with a `layer...` path; a setting outside the editable sections, such as
|
|
142
|
+
* `profanity`, is refused). A `version` that is no longer the stored one is `conflict`, and nothing is written. On success
|
|
143
|
+
* the effective profile changes at once, in this process.
|
|
144
|
+
*/
|
|
145
|
+
save(layer, ctx) {
|
|
146
|
+
if (!this.supported)
|
|
147
|
+
return { ok: false, error: 'unsupported' };
|
|
148
|
+
if (typeof ctx !== 'object' || ctx === null)
|
|
149
|
+
return { ok: false, error: 'invalid', path: 'version' };
|
|
150
|
+
if (!Number.isSafeInteger(ctx.version) || ctx.version < 0)
|
|
151
|
+
return { ok: false, error: 'invalid', path: 'version' };
|
|
152
|
+
if (!isValidAuditActor(ctx.actor))
|
|
153
|
+
return { ok: false, error: 'invalid', path: 'actor' };
|
|
154
|
+
if (typeof ctx.reason !== 'string' || ctx.reason.trim() === '' || ctx.reason.trim().length > AUDIT_REASON_MAX) {
|
|
155
|
+
return { ok: false, error: 'invalid', path: 'reason' };
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
applyPolicyLayer(this.base, layer);
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
if (err instanceof ProfileError)
|
|
162
|
+
return { ok: false, error: 'invalid', path: err.path };
|
|
163
|
+
throw err;
|
|
164
|
+
}
|
|
165
|
+
// Stored as plain JSON: exactly the sections given, nothing that is not data.
|
|
166
|
+
const clean = JSON.parse(JSON.stringify(layer));
|
|
167
|
+
return this.persist(clean, ctx.version);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Put one editable section (or, with no section, every section) back to the base, by storing the layer without it. It starts
|
|
171
|
+
* from the latest stored layer, so a reset never undoes another process's unrelated edit. With `version` it must still be
|
|
172
|
+
* the stored one (`conflict` otherwise). Nothing to reset is a no-op that writes nothing (`changed: []`).
|
|
173
|
+
*/
|
|
174
|
+
reset(section, o = {}) {
|
|
175
|
+
if (!this.supported)
|
|
176
|
+
return { ok: false, error: 'unsupported' };
|
|
177
|
+
if (section !== undefined && !POLICY_SECTIONS.includes(section))
|
|
178
|
+
return { ok: false, error: 'invalid', path: 'section' };
|
|
179
|
+
if (o.version !== undefined && (!Number.isSafeInteger(o.version) || o.version < 0))
|
|
180
|
+
return { ok: false, error: 'invalid', path: 'version' };
|
|
181
|
+
this.refresh();
|
|
182
|
+
if (o.version !== undefined && o.version !== this.state.version)
|
|
183
|
+
return { ok: false, error: 'conflict' };
|
|
184
|
+
const { layer, version, layerError } = this.state;
|
|
185
|
+
let next = {};
|
|
186
|
+
if (section !== undefined) {
|
|
187
|
+
next = { ...layer };
|
|
188
|
+
delete next[section];
|
|
189
|
+
if (layerError !== undefined) {
|
|
190
|
+
// A layer we cannot use may need more than this section gone: it must still be valid, or it is the full reset's job.
|
|
191
|
+
try {
|
|
192
|
+
applyPolicyLayer(this.base, next);
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
if (err instanceof ProfileError)
|
|
196
|
+
return { ok: false, error: 'invalid', path: err.path };
|
|
197
|
+
throw err;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const touches = section === undefined ? layerSections(layer).length > 0 : Object.hasOwn(layer, section);
|
|
202
|
+
if (!touches && layerError === undefined)
|
|
203
|
+
return { ok: true, version, changed: [] };
|
|
204
|
+
return this.persist(JSON.parse(JSON.stringify(next)), version);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* What would be suggested under the candidate `layer` (the whole layer, applied over the base, exactly as a save would
|
|
208
|
+
* store it), for four fixed sample records and each conduct level, without saving anything or reading the store. `rule`
|
|
209
|
+
* (default `'uncovered'`) is the Community Rule the sample incident cites: pass a rule from `areaRules` or `severeRules` to
|
|
210
|
+
* see those rules take effect.
|
|
211
|
+
*/
|
|
212
|
+
preview(layer, rule = 'uncovered') {
|
|
213
|
+
if (!isRuleRef(rule))
|
|
214
|
+
return { ok: false, error: 'invalid', path: 'rule' };
|
|
215
|
+
let candidate;
|
|
216
|
+
try {
|
|
217
|
+
candidate = applyPolicyLayer(this.base, layer);
|
|
218
|
+
}
|
|
219
|
+
catch (err) {
|
|
220
|
+
if (err instanceof ProfileError)
|
|
221
|
+
return { ok: false, error: 'invalid', path: err.path };
|
|
222
|
+
throw err;
|
|
223
|
+
}
|
|
224
|
+
const now = this.clock.now();
|
|
225
|
+
const records = sampleRecords(now);
|
|
226
|
+
const samples = {};
|
|
227
|
+
for (const sample of PREVIEW_SAMPLES) {
|
|
228
|
+
const levels = {};
|
|
229
|
+
for (const level of CONDUCT_LEVELS) {
|
|
230
|
+
const s = suggest(candidate, records[sample], level, rule, now);
|
|
231
|
+
const o = s.outcome;
|
|
232
|
+
levels[level] =
|
|
233
|
+
typeof o === 'string'
|
|
234
|
+
? { label: s.label, kind: o, durationMs: null }
|
|
235
|
+
: { label: s.label, kind: o.kind, durationMs: o.durationMs };
|
|
236
|
+
}
|
|
237
|
+
samples[sample] = levels;
|
|
238
|
+
}
|
|
239
|
+
return { ok: true, samples, reporting: playerReporting(candidate.reporting) };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE3H,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAG5C;;;;;;GAMG;AAEH,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xF,MAAM,GAAG,CAAC;QACZ,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,OAAO,GAAG,EAAiE,CAAC;QAClF,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;YACrC,MAAM,MAAM,GAAG,EAA0C,CAAC;YAC1D,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;gBACnC,MAAM,CAAC,GAAG,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;gBAChE,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;gBACpB,MAAM,CAAC,KAAK,CAAC;oBACX,OAAO,CAAC,KAAK,QAAQ;wBACnB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;wBAC/C,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC;YACnE,CAAC;YACD,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;QAC3B,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;IAChF,CAAC;CACF"}
|
package/dist/src/profile.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { LadderRow } from './ladder.js';
|
|
1
|
+
import type { LadderRow, LadderStep } from './ladder.js';
|
|
2
2
|
import type { ConductLevel } from './types.js';
|
|
3
|
+
import type { ReportingSettings, ResolvedReporting } from './reporting.js';
|
|
3
4
|
/** What happens on a first offense. Durations are milliseconds; `null` is permanent. */
|
|
4
5
|
export type Outcome = 'none' | 'note' | 'warning' | {
|
|
5
6
|
kind: 'chat' | 'area' | 'ban';
|
|
@@ -39,7 +40,8 @@ export interface GuidelineTier {
|
|
|
39
40
|
}
|
|
40
41
|
/** The starter Community Rules flavour that goes with the profile. */
|
|
41
42
|
export type RulesFlavour = 'relaxed' | 'standard' | 'strict';
|
|
42
|
-
|
|
43
|
+
/** Everything a moderation profile held in 0.1.1. The two fields added later are on {@link ModerationProfile} and {@link ResolvedProfile}. */
|
|
44
|
+
export interface ModerationProfileBase {
|
|
43
45
|
/** `'relaxed'`, `'standard'`, `'strict'` or your own. */
|
|
44
46
|
id: string;
|
|
45
47
|
/** Shown in the Guide and on the public page. */
|
|
@@ -88,6 +90,50 @@ export interface ModerationProfile {
|
|
|
88
90
|
*/
|
|
89
91
|
guidelines: GuidelineTier[];
|
|
90
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* A moderation profile as you write it. A profile from 0.1.1 (without `durations` and `customDuration`) is still one: the two
|
|
95
|
+
* fields are optional here and are filled with their defaults wherever the kit reads a profile. What the kit hands back is a
|
|
96
|
+
* {@link ResolvedProfile}, which has both.
|
|
97
|
+
*/
|
|
98
|
+
export interface ModerationProfile extends ModerationProfileBase {
|
|
99
|
+
/**
|
|
100
|
+
* The lengths a moderator is offered, in milliseconds: sorted from the shortest, no repeats, each from 1 up to 365
|
|
101
|
+
* days (at most {@link MAX_DURATIONS} of them). Permanent is always offered, subject to permission, and is never listed.
|
|
102
|
+
* Default {@link DEFAULT_DURATIONS}: 1 hour, 6 hours, 12 hours, 24 hours, 3 days, 7 days and 30 days. Only the offered
|
|
103
|
+
* list: a decision or a sanction may still name any valid length when `customDuration` is true, and the ladder's own
|
|
104
|
+
* lengths are always allowed.
|
|
105
|
+
*/
|
|
106
|
+
durations?: number[];
|
|
107
|
+
/** May a moderator type a length of their own? Default true. When false, only `durations`, permanent and the profile's own lengths are accepted. */
|
|
108
|
+
customDuration?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* How players report and what they are told: the flow (default one tap, reason optional), the ordered reasons (default
|
|
111
|
+
* grouped and game-style, each mapped to its starter Community Rules) and the thank-you copy. Every field is optional. See
|
|
112
|
+
* {@link ReportingSettings}.
|
|
113
|
+
*/
|
|
114
|
+
reporting?: ReportingSettings;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* What `defineProfile`, `resolveProfile`, `applyPolicyLayer`, `cw.profile` and `cw.policy.get()` return: a validated, deep-frozen
|
|
118
|
+
* profile with `durations` and `customDuration` filled in. It is a {@link ModerationProfile}, so it can be passed wherever one is
|
|
119
|
+
* taken.
|
|
120
|
+
*/
|
|
121
|
+
export interface ResolvedProfile extends ModerationProfileBase {
|
|
122
|
+
/**
|
|
123
|
+
* The lengths a moderator is offered, in milliseconds: sorted from the shortest, no repeats, each from 1 up to 365
|
|
124
|
+
* days (at most {@link MAX_DURATIONS} of them). Permanent is always offered, subject to permission, and is never listed.
|
|
125
|
+
* Default {@link DEFAULT_DURATIONS}: 1 hour, 6 hours, 12 hours, 24 hours, 3 days, 7 days and 30 days. Only the offered
|
|
126
|
+
* list: a decision or a sanction may still name any valid length when `customDuration` is true, and the ladder's own
|
|
127
|
+
* lengths are always allowed.
|
|
128
|
+
*/
|
|
129
|
+
durations: number[];
|
|
130
|
+
/** May a moderator type a length of their own? When false, only `durations`, permanent and the profile's own lengths are accepted. */
|
|
131
|
+
customDuration: boolean;
|
|
132
|
+
/** The reporting settings in force, every field filled in. */
|
|
133
|
+
reporting: ResolvedReporting;
|
|
134
|
+
}
|
|
135
|
+
/** @deprecated The same as {@link ModerationProfile}, which now has the two fields optional. */
|
|
136
|
+
export type ProfileInput = ModerationProfile;
|
|
91
137
|
/** Like `Partial`, all the way down. Arrays are replaced, not merged; `null` is a value. */
|
|
92
138
|
export type DeepPartial<T> = T extends readonly unknown[] ? T : T extends object ? {
|
|
93
139
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
@@ -97,8 +143,12 @@ export type ProfileOverrides = DeepPartial<ModerationProfile>;
|
|
|
97
143
|
/** A profile that fails validation. `path` names the field (`'profile.firstOffense.banter'`); the message never echoes a value. */
|
|
98
144
|
export declare class ProfileError extends Error {
|
|
99
145
|
readonly path: string;
|
|
146
|
+
/** The rule that was broken, without the path. Never a value. */
|
|
147
|
+
readonly reason: string;
|
|
100
148
|
constructor(path: string, reason: string);
|
|
101
149
|
}
|
|
150
|
+
/** The most rule numbers `areaRules` or `severeRules` may list. */
|
|
151
|
+
export declare const MAX_RULE_LIST = 100;
|
|
102
152
|
/**
|
|
103
153
|
* The longest any duration may be: 365 days, the same cap `decide` and `applySanction` enforce (one source of truth), so a
|
|
104
154
|
* suggested outcome or an automatic timeout can never name a length the moderator's own decision would refuse.
|
|
@@ -106,13 +156,22 @@ export declare class ProfileError extends Error {
|
|
|
106
156
|
export declare const MAX_DURATION_MS: number;
|
|
107
157
|
/** The longest `repeat.windowDays`: the history lookback (90 days), since the record reaches back no further. */
|
|
108
158
|
export declare const MAX_WINDOW_DAYS: number;
|
|
159
|
+
/** The most lengths `durations` may list: a picker with more than this is not a picker. */
|
|
160
|
+
export declare const MAX_DURATIONS = 50;
|
|
161
|
+
/** The lengths offered when a profile does not say: 1 hour, 6 hours, 12 hours, 24 hours, 3 days, 7 days and 30 days. */
|
|
162
|
+
export declare const DEFAULT_DURATIONS: readonly number[];
|
|
109
163
|
/**
|
|
110
164
|
* Check a profile of unknown shape, throwing {@link ProfileError} (with the field path) at the first problem. The
|
|
111
165
|
* message names the field and the rule, never the value, since a value may be chat text.
|
|
112
166
|
*/
|
|
113
167
|
export declare function validateProfile(value: unknown): asserts value is ModerationProfile;
|
|
168
|
+
/**
|
|
169
|
+
* A copy of a profile with `durations` and `customDuration` filled in where it has none (a 0.1.1 profile). The input is not
|
|
170
|
+
* changed and the profile is not validated here (`validateProfile` does that). Used by the document functions.
|
|
171
|
+
*/
|
|
172
|
+
export declare function withDurationDefaults(p: ModerationProfile): ResolvedProfile;
|
|
114
173
|
/** The three presets, complete, valid and deep-frozen. Values are the standards doc's tables. */
|
|
115
|
-
export declare const PRESETS: Readonly<Record<'relaxed' | 'standard' | 'strict',
|
|
174
|
+
export declare const PRESETS: Readonly<Record<'relaxed' | 'standard' | 'strict', ResolvedProfile>>;
|
|
116
175
|
/** The name of a built-in preset. */
|
|
117
176
|
export type PresetName = keyof typeof PRESETS;
|
|
118
177
|
/**
|
|
@@ -124,10 +183,64 @@ export type PresetName = keyof typeof PRESETS;
|
|
|
124
183
|
*
|
|
125
184
|
* Throws {@link ProfileError} for an unknown preset name, an unknown key at any depth, or any invalid value.
|
|
126
185
|
*/
|
|
127
|
-
export declare function resolveProfile(preset: ModerationProfile | PresetName, overrides?: ProfileOverrides):
|
|
186
|
+
export declare function resolveProfile(preset: ModerationProfile | PresetName, overrides?: ProfileOverrides): ResolvedProfile;
|
|
187
|
+
/**
|
|
188
|
+
* Validate a complete custom profile. Nothing is merged (a profile that leaves out `durations` or `customDuration` gets
|
|
189
|
+
* their defaults). Returns a deep-frozen copy, so editing the object you passed afterwards cannot change a profile that
|
|
190
|
+
* was already checked. Throws {@link ProfileError}.
|
|
191
|
+
*/
|
|
192
|
+
export declare function defineProfile(p: ModerationProfile): ResolvedProfile;
|
|
193
|
+
/**
|
|
194
|
+
* The parts of a profile the hub may edit, and the order they are listed in. Everything else (identity, the written
|
|
195
|
+
* levels, the AI context, profanity handling) stays in code: changing profanity means rebuilding the filter.
|
|
196
|
+
*/
|
|
197
|
+
export declare const POLICY_SECTIONS: readonly ["durations", "customDuration", "ladder", "firstOffense", "repeat", "areaRules", "severeRules", "guidelines", "reporting"];
|
|
198
|
+
export type PolicySection = (typeof POLICY_SECTIONS)[number];
|
|
199
|
+
/** One ladder cell as the editor sends it: the label may be left out and is then generated ("Restrict chat 6 hours"). */
|
|
200
|
+
export interface PolicyCell {
|
|
201
|
+
kind: 'chat' | 'area' | 'ban' | 'warning';
|
|
202
|
+
durationMs: number | null;
|
|
203
|
+
label?: string;
|
|
204
|
+
}
|
|
205
|
+
/** One ladder row as the editor sends it. */
|
|
206
|
+
export interface PolicyLadderRow {
|
|
207
|
+
step: LadderStep;
|
|
208
|
+
lowMedium: PolicyCell;
|
|
209
|
+
high: PolicyCell;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* The stored edits: a deep-partial of the editable sections. An object section merges key by key onto the profile
|
|
213
|
+
* (`firstOffense`, `repeat`); a list replaces the profile's list whole (`durations`, `ladder` as all 6 rows, `areaRules`,
|
|
214
|
+
* `severeRules`). `guidelines` is positional: entry `i` holds the new `outcome` text of the profile's guideline tier `i`,
|
|
215
|
+
* and `null` leaves that tier as it is. A layer that touches anything else is refused.
|
|
216
|
+
*/
|
|
217
|
+
export interface PolicyLayer {
|
|
218
|
+
durations?: number[];
|
|
219
|
+
customDuration?: boolean;
|
|
220
|
+
ladder?: PolicyLadderRow[];
|
|
221
|
+
firstOffense?: Partial<Record<ConductLevel, Outcome>>;
|
|
222
|
+
repeat?: Partial<ModerationProfile['repeat']>;
|
|
223
|
+
areaRules?: number[];
|
|
224
|
+
severeRules?: number[];
|
|
225
|
+
guidelines?: Array<{
|
|
226
|
+
outcome: string;
|
|
227
|
+
} | null>;
|
|
228
|
+
/** The reporting settings: `flow` and `thanks` replace the profile's; `reasons` replaces the whole list. Each is optional; a reason needs only `id` and `label`. */
|
|
229
|
+
reporting?: ReportingSettings;
|
|
230
|
+
}
|
|
231
|
+
/** The longest outcome text a layer may set on a guideline tier. */
|
|
232
|
+
export declare const MAX_GUIDELINE_OUTCOME = 1000;
|
|
128
233
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
234
|
+
* The effective profile: `base` (a preset with the code overrides) with the stored `layer` merged on top, validated. The
|
|
235
|
+
* result is a deep-frozen copy that shares nothing with either. Throws {@link ProfileError} whose `path` starts with
|
|
236
|
+
* `layer` (`layer.profanity`, `layer.ladder[2].high.durationMs`): a layer that touches a setting outside
|
|
237
|
+
* {@link POLICY_SECTIONS}, or one that would make the profile invalid.
|
|
131
238
|
*/
|
|
132
|
-
export declare function
|
|
239
|
+
export declare function applyPolicyLayer(base: ModerationProfile, layer: PolicyLayer): ResolvedProfile;
|
|
240
|
+
/** The editable sections a layer holds, in {@link POLICY_SECTIONS} order. */
|
|
241
|
+
export declare function layerSections(layer: unknown): PolicySection[];
|
|
242
|
+
/** The sections that differ between two layers (present in one and not the other, or with other values), in order. */
|
|
243
|
+
export declare function changedSections(before: unknown, after: unknown): PolicySection[];
|
|
244
|
+
/** A deep-frozen copy of a plain value (a stored layer, handed out read-only). */
|
|
245
|
+
export declare function frozenCopy<T>(v: T): T;
|
|
133
246
|
//# sourceMappingURL=profile.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/profile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../src/profile.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAe/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAa3E,wFAAwF;AACxF,MAAM,MAAM,OAAO,GACf,MAAM,GACN,MAAM,GACN,SAAS,GACT;IAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEjE,mHAAmH;AACnH,MAAM,WAAW,eAAe;IAC9B,iFAAiF;IACjF,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;IAClC,0DAA0D;IAC1D,KAAK,EAAE,MAAM,GAAG,W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