@atproto/ozone 0.12.3 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +16 -0
- package/dist/api/moderation/emitEvent.d.ts.map +1 -1
- package/dist/api/moderation/emitEvent.js +4 -1
- package/dist/api/moderation/emitEvent.js.map +1 -1
- package/dist/api/report/createReport.d.ts.map +1 -1
- package/dist/api/report/createReport.js +3 -1
- package/dist/api/report/createReport.js.map +1 -1
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +0 -2
- package/dist/config/config.js.map +1 -1
- package/dist/config/env.d.ts +0 -2
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +0 -2
- package/dist/config/env.js.map +1 -1
- package/dist/context.d.ts +2 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +2 -2
- package/dist/context.js.map +1 -1
- package/dist/daemon/context.d.ts +0 -3
- package/dist/daemon/context.d.ts.map +1 -1
- package/dist/daemon/context.js +0 -10
- package/dist/daemon/context.js.map +1 -1
- package/dist/daemon/locks.d.ts +0 -1
- package/dist/daemon/locks.d.ts.map +1 -1
- package/dist/daemon/locks.js +0 -1
- package/dist/daemon/locks.js.map +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/schema/index.d.ts +1 -5
- package/dist/db/schema/index.d.ts.map +1 -1
- package/dist/db/schema/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.d.ts +1 -1
- package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.d.ts.map +1 -1
- package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.js +1 -1
- package/dist/lexicons/app/bsky/unspecced/getAtmosphereExploreTab.defs.js.map +1 -1
- package/dist/lexicons/tools/ozone/moderation/defs.defs.d.ts +0 -76
- package/dist/lexicons/tools/ozone/moderation/defs.defs.d.ts.map +1 -1
- package/dist/lexicons/tools/ozone/moderation/defs.defs.js +1 -7
- package/dist/lexicons/tools/ozone/moderation/defs.defs.js.map +1 -1
- package/dist/lexicons/tools/ozone/moderation/queryStatuses.defs.d.ts +0 -6
- package/dist/lexicons/tools/ozone/moderation/queryStatuses.defs.d.ts.map +1 -1
- package/dist/lexicons/tools/ozone/moderation/queryStatuses.defs.js +1 -1
- package/dist/lexicons/tools/ozone/moderation/queryStatuses.defs.js.map +1 -1
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +2 -1
- package/dist/logger.js.map +1 -1
- package/dist/mod-service/index.d.ts +1 -1
- package/dist/mod-service/index.d.ts.map +1 -1
- package/dist/mod-service/index.js +8 -17
- package/dist/mod-service/index.js.map +1 -1
- package/dist/mod-service/profile.d.ts +8 -5
- package/dist/mod-service/profile.d.ts.map +1 -1
- package/dist/mod-service/profile.js +44 -60
- package/dist/mod-service/profile.js.map +1 -1
- package/dist/mod-service/report.d.ts +6 -0
- package/dist/mod-service/report.d.ts.map +1 -1
- package/dist/mod-service/report.js +20 -6
- package/dist/mod-service/report.js.map +1 -1
- package/dist/mod-service/status.d.ts +1 -33
- package/dist/mod-service/status.d.ts.map +1 -1
- package/dist/mod-service/status.js +0 -26
- package/dist/mod-service/status.js.map +1 -1
- package/dist/mod-service/types.d.ts +0 -13
- package/dist/mod-service/types.d.ts.map +1 -1
- package/dist/mod-service/types.js.map +1 -1
- package/dist/mod-service/views.d.ts.map +1 -1
- package/dist/mod-service/views.js +0 -22
- package/dist/mod-service/views.js.map +1 -1
- package/dist/set/service.d.ts +1 -1
- package/package.json +6 -6
- package/dist/daemon/materialized-view-refresher.d.ts +0 -5
- package/dist/daemon/materialized-view-refresher.d.ts.map +0 -1
- package/dist/daemon/materialized-view-refresher.js +0 -58
- package/dist/daemon/materialized-view-refresher.js.map +0 -1
- package/dist/db/schema/account_events_stats.d.ts +0 -15
- package/dist/db/schema/account_events_stats.d.ts.map +0 -1
- package/dist/db/schema/account_events_stats.js +0 -2
- package/dist/db/schema/account_events_stats.js.map +0 -1
- package/dist/db/schema/account_record_events_stats.d.ts +0 -15
- package/dist/db/schema/account_record_events_stats.d.ts.map +0 -1
- package/dist/db/schema/account_record_events_stats.js +0 -2
- package/dist/db/schema/account_record_events_stats.js.map +0 -1
- package/dist/db/schema/account_record_status_stats.d.ts +0 -15
- package/dist/db/schema/account_record_status_stats.d.ts.map +0 -1
- package/dist/db/schema/account_record_status_stats.js +0 -2
- package/dist/db/schema/account_record_status_stats.js.map +0 -1
|
@@ -1,58 +1,40 @@
|
|
|
1
|
+
import { Counter } from 'prom-client';
|
|
2
|
+
import { TokenSchema } from '@atproto/lex-schema';
|
|
1
3
|
import { InvalidRequestError } from '@atproto/xrpc-server';
|
|
2
|
-
import {
|
|
4
|
+
import { isAppealReport } from '../api/util.js';
|
|
5
|
+
import { app, com, tools } from '../lexicons/index.js';
|
|
3
6
|
import { httpLogger } from '../logger.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'tools.ozone.report.defs#reasonOther': com.atproto.moderation.defs.ReasonOther,
|
|
8
|
-
'tools.ozone.report.defs#reasonViolenceAnimal': com.atproto.moderation.defs.ReasonViolation,
|
|
9
|
-
'tools.ozone.report.defs#reasonViolenceThreats': com.atproto.moderation.defs.ReasonViolation,
|
|
10
|
-
'tools.ozone.report.defs#reasonViolenceGraphicContent': com.atproto.moderation.defs.ReasonViolation,
|
|
11
|
-
'tools.ozone.report.defs#reasonViolenceGlorification': com.atproto.moderation.defs.ReasonViolation,
|
|
12
|
-
'tools.ozone.report.defs#reasonViolenceExtremistContent': com.atproto.moderation.defs.ReasonViolation,
|
|
13
|
-
'tools.ozone.report.defs#reasonViolenceTrafficking': com.atproto.moderation.defs.ReasonViolation,
|
|
14
|
-
'tools.ozone.report.defs#reasonViolenceOther': com.atproto.moderation.defs.ReasonViolation,
|
|
15
|
-
'tools.ozone.report.defs#reasonSexualAbuseContent': com.atproto.moderation.defs.ReasonSexual,
|
|
16
|
-
'tools.ozone.report.defs#reasonSexualNCII': com.atproto.moderation.defs.ReasonSexual,
|
|
17
|
-
'tools.ozone.report.defs#reasonSexualDeepfake': com.atproto.moderation.defs.ReasonSexual,
|
|
18
|
-
'tools.ozone.report.defs#reasonSexualAnimal': com.atproto.moderation.defs.ReasonSexual,
|
|
19
|
-
'tools.ozone.report.defs#reasonSexualUnlabeled': com.atproto.moderation.defs.ReasonSexual,
|
|
20
|
-
'tools.ozone.report.defs#reasonSexualOther': com.atproto.moderation.defs.ReasonSexual,
|
|
21
|
-
'tools.ozone.report.defs#reasonChildSafetyCSAM': com.atproto.moderation.defs.ReasonViolation,
|
|
22
|
-
'tools.ozone.report.defs#reasonChildSafetyGroom': com.atproto.moderation.defs.ReasonViolation,
|
|
23
|
-
'tools.ozone.report.defs#reasonChildSafetyPrivacy': com.atproto.moderation.defs.ReasonViolation,
|
|
24
|
-
'tools.ozone.report.defs#reasonChildSafetyHarassment': com.atproto.moderation.defs.ReasonViolation,
|
|
25
|
-
'tools.ozone.report.defs#reasonChildSafetyOther': com.atproto.moderation.defs.ReasonViolation,
|
|
26
|
-
'tools.ozone.report.defs#reasonHarassmentTroll': com.atproto.moderation.defs.ReasonRude,
|
|
27
|
-
'tools.ozone.report.defs#reasonHarassmentTargeted': com.atproto.moderation.defs.ReasonRude,
|
|
28
|
-
'tools.ozone.report.defs#reasonHarassmentHateSpeech': com.atproto.moderation.defs.ReasonRude,
|
|
29
|
-
'tools.ozone.report.defs#reasonHarassmentDoxxing': com.atproto.moderation.defs.ReasonRude,
|
|
30
|
-
'tools.ozone.report.defs#reasonHarassmentOther': com.atproto.moderation.defs.ReasonRude,
|
|
31
|
-
'tools.ozone.report.defs#reasonMisleadingBot': com.atproto.moderation.defs.ReasonMisleading,
|
|
32
|
-
'tools.ozone.report.defs#reasonMisleadingImpersonation': com.atproto.moderation.defs.ReasonMisleading,
|
|
33
|
-
'tools.ozone.report.defs#reasonMisleadingSpam': com.atproto.moderation.defs.ReasonSpam,
|
|
34
|
-
'tools.ozone.report.defs#reasonMisleadingScam': com.atproto.moderation.defs.ReasonMisleading,
|
|
35
|
-
'tools.ozone.report.defs#reasonMisleadingElections': com.atproto.moderation.defs.ReasonMisleading,
|
|
36
|
-
'tools.ozone.report.defs#reasonMisleadingOther': com.atproto.moderation.defs.ReasonMisleading,
|
|
37
|
-
'tools.ozone.report.defs#reasonRuleSiteSecurity': com.atproto.moderation.defs.ReasonViolation,
|
|
38
|
-
'tools.ozone.report.defs#reasonRuleProhibitedSales': com.atproto.moderation.defs.ReasonViolation,
|
|
39
|
-
'tools.ozone.report.defs#reasonRuleBanEvasion': com.atproto.moderation.defs.ReasonViolation,
|
|
40
|
-
'tools.ozone.report.defs#reasonRuleOther': com.atproto.moderation.defs.ReasonViolation,
|
|
41
|
-
'tools.ozone.report.defs#reasonSelfHarmContent': com.atproto.moderation.defs.ReasonViolation,
|
|
42
|
-
'tools.ozone.report.defs#reasonSelfHarmED': com.atproto.moderation.defs.ReasonViolation,
|
|
43
|
-
'tools.ozone.report.defs#reasonSelfHarmStunts': com.atproto.moderation.defs.ReasonViolation,
|
|
44
|
-
'tools.ozone.report.defs#reasonSelfHarmSubstances': com.atproto.moderation.defs.ReasonViolation,
|
|
45
|
-
'tools.ozone.report.defs#reasonSelfHarmOther': com.atproto.moderation.defs.ReasonViolation,
|
|
46
|
-
};
|
|
7
|
+
const KNOWN_REASON_TYPES = new Set([com.atproto.moderation.defs, tools.ozone.report.defs].flatMap((defs) => Object.values(defs)
|
|
8
|
+
.filter((value) => value instanceof TokenSchema)
|
|
9
|
+
.map((token) => token.value)));
|
|
47
10
|
export class ModerationServiceProfile {
|
|
48
|
-
constructor(cfg, appviewClient, cacheTTL) {
|
|
11
|
+
constructor(cfg, appviewClient, cacheTTL, reasonRejections) {
|
|
49
12
|
this.cfg = cfg;
|
|
50
13
|
this.appviewClient = appviewClient;
|
|
14
|
+
this.reasonRejections = reasonRejections;
|
|
51
15
|
this.cache = null;
|
|
52
16
|
this.CACHE_TTL = cacheTTL || cfg.service.serviceRecordCacheTTL;
|
|
53
17
|
}
|
|
54
|
-
static creator(cfg, appviewClient) {
|
|
55
|
-
|
|
18
|
+
static creator(cfg, appviewClient, register) {
|
|
19
|
+
const reasonRejections = register
|
|
20
|
+
? new Counter({
|
|
21
|
+
name: 'ozone_report_reason_rejections_total',
|
|
22
|
+
help: 'Report attempts rejected because the reason type is not in the labeler allowlist',
|
|
23
|
+
labelNames: ['nsid', 'reason_type'],
|
|
24
|
+
registers: [register],
|
|
25
|
+
})
|
|
26
|
+
: undefined;
|
|
27
|
+
if (reasonRejections) {
|
|
28
|
+
for (const nsid of [
|
|
29
|
+
com.atproto.moderation.createReport.$lxm,
|
|
30
|
+
tools.ozone.moderation.emitEvent.$lxm,
|
|
31
|
+
]) {
|
|
32
|
+
for (const reason_type of [...KNOWN_REASON_TYPES, 'unknown']) {
|
|
33
|
+
reasonRejections.inc({ nsid, reason_type }, 0);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return () => new ModerationServiceProfile(cfg, appviewClient, undefined, reasonRejections);
|
|
56
38
|
}
|
|
57
39
|
async getProfile() {
|
|
58
40
|
const now = Date.now();
|
|
@@ -73,22 +55,24 @@ export class ModerationServiceProfile {
|
|
|
73
55
|
}
|
|
74
56
|
return this.cache?.profile || null;
|
|
75
57
|
}
|
|
76
|
-
async validateReasonType(reasonType) {
|
|
77
|
-
|
|
78
|
-
if (
|
|
58
|
+
async validateReasonType(reasonType, nsid) {
|
|
59
|
+
// @NOTE appeals remain available regardless of the report-type allowlist.
|
|
60
|
+
if (isAppealReport(reasonType)) {
|
|
79
61
|
return reasonType;
|
|
80
62
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
63
|
+
const profile = await this.getProfile();
|
|
64
|
+
if (Array.isArray(profile?.reasonTypes) &&
|
|
65
|
+
!profile.reasonTypes.includes(reasonType)) {
|
|
66
|
+
// @NOTE caller-supplied custom values must not create unbounded series.
|
|
67
|
+
this.reasonRejections?.inc({
|
|
68
|
+
nsid,
|
|
69
|
+
reason_type: KNOWN_REASON_TYPES.has(reasonType)
|
|
70
|
+
? reasonType
|
|
71
|
+
: 'unknown',
|
|
72
|
+
});
|
|
73
|
+
throw new InvalidRequestError(`Invalid reason type: ${reasonType}`);
|
|
90
74
|
}
|
|
91
|
-
|
|
75
|
+
return reasonType;
|
|
92
76
|
}
|
|
93
77
|
}
|
|
94
78
|
//# sourceMappingURL=profile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/mod-service/profile.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAE1D,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,oGAAoG;AACpG,MAAM,CAAC,MAAM,yBAAyB,GAA2B;IAC/D,sCAAsC,EACpC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY;IAC1C,qCAAqC,EACnC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW;IAEzC,8CAA8C,EAC5C,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe;IAC7C,+CAA+C,EAC7C,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe;IAC7C,sDAAsD,EACpD,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe;IAC7C,qDAAqD,EACn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AAG;wBACX,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;wBACtB,SAAS,EAAE,GAAG;qBACf,CAAA;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,sBAAsB;gBACtB,UAAU,CAAC,KAAK,CAAC,oCAAoC,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;YACxE,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,UAAkB;QACzC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAA;QAEvC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,CAAC;YACzC,OAAO,UAAU,CAAA;QACnB,CAAC;QAED,MAAM,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAA;QAEhD,iDAAiD;QACjD,IAAI,oBAAoB,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9C,OAAO,UAAU,CAAA;QACnB,CAAC;QAED,yEAAyE;QACzE,MAAM,eAAe,GAAG,yBAAyB,CAAC,UAAU,CAAC,CAAA;QAC7D,IAAI,eAAe,IAAI,oBAAoB,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YACtE,OAAO,UAAU,CAAA;QACnB,CAAC;QAED,MAAM,IAAI,mBAAmB,CAAC,wBAAwB,UAAU,EAAE,CAAC,CAAA;IACrE,CAAC;CACF","sourcesContent":["import type { Client } from '@atproto/lex-client'\nimport { InvalidRequestError } from '@atproto/xrpc-server'\nimport type { OzoneConfig } from '../config/index.js'\nimport { app, com } from '../lexicons/index.js'\nimport { httpLogger } from '../logger.js'\n\n// Reverse mapping from new ozone namespaced reason types to old com.atproto namespaced reason types\nexport const NEW_TO_OLD_REASON_MAPPING: Record<string, string> = {\n 'tools.ozone.report.defs#reasonAppeal':\n com.atproto.moderation.defs.ReasonAppeal,\n 'tools.ozone.report.defs#reasonOther':\n com.atproto.moderation.defs.ReasonOther,\n\n 'tools.ozone.report.defs#reasonViolenceAnimal':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonViolenceThreats':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonViolenceGraphicContent':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonViolenceGlorification':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonViolenceExtremistContent':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonViolenceTrafficking':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonViolenceOther':\n com.atproto.moderation.defs.ReasonViolation,\n\n 'tools.ozone.report.defs#reasonSexualAbuseContent':\n com.atproto.moderation.defs.ReasonSexual,\n 'tools.ozone.report.defs#reasonSexualNCII':\n com.atproto.moderation.defs.ReasonSexual,\n 'tools.ozone.report.defs#reasonSexualDeepfake':\n com.atproto.moderation.defs.ReasonSexual,\n 'tools.ozone.report.defs#reasonSexualAnimal':\n com.atproto.moderation.defs.ReasonSexual,\n 'tools.ozone.report.defs#reasonSexualUnlabeled':\n com.atproto.moderation.defs.ReasonSexual,\n 'tools.ozone.report.defs#reasonSexualOther':\n com.atproto.moderation.defs.ReasonSexual,\n\n 'tools.ozone.report.defs#reasonChildSafetyCSAM':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonChildSafetyGroom':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonChildSafetyPrivacy':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonChildSafetyHarassment':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonChildSafetyOther':\n com.atproto.moderation.defs.ReasonViolation,\n\n 'tools.ozone.report.defs#reasonHarassmentTroll':\n com.atproto.moderation.defs.ReasonRude,\n 'tools.ozone.report.defs#reasonHarassmentTargeted':\n com.atproto.moderation.defs.ReasonRude,\n 'tools.ozone.report.defs#reasonHarassmentHateSpeech':\n com.atproto.moderation.defs.ReasonRude,\n 'tools.ozone.report.defs#reasonHarassmentDoxxing':\n com.atproto.moderation.defs.ReasonRude,\n 'tools.ozone.report.defs#reasonHarassmentOther':\n com.atproto.moderation.defs.ReasonRude,\n\n 'tools.ozone.report.defs#reasonMisleadingBot':\n com.atproto.moderation.defs.ReasonMisleading,\n 'tools.ozone.report.defs#reasonMisleadingImpersonation':\n com.atproto.moderation.defs.ReasonMisleading,\n 'tools.ozone.report.defs#reasonMisleadingSpam':\n com.atproto.moderation.defs.ReasonSpam,\n 'tools.ozone.report.defs#reasonMisleadingScam':\n com.atproto.moderation.defs.ReasonMisleading,\n 'tools.ozone.report.defs#reasonMisleadingElections':\n com.atproto.moderation.defs.ReasonMisleading,\n 'tools.ozone.report.defs#reasonMisleadingOther':\n com.atproto.moderation.defs.ReasonMisleading,\n\n 'tools.ozone.report.defs#reasonRuleSiteSecurity':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonRuleProhibitedSales':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonRuleBanEvasion':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonRuleOther':\n com.atproto.moderation.defs.ReasonViolation,\n\n 'tools.ozone.report.defs#reasonSelfHarmContent':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonSelfHarmED':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonSelfHarmStunts':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonSelfHarmSubstances':\n com.atproto.moderation.defs.ReasonViolation,\n 'tools.ozone.report.defs#reasonSelfHarmOther':\n com.atproto.moderation.defs.ReasonViolation,\n}\n\ninterface CacheEntry {\n profile: app.bsky.labeler.defs.LabelerViewDetailed | null\n timestamp: number\n}\n\nexport type ModerationServiceProfileCreator = () => ModerationServiceProfile\n\nexport class ModerationServiceProfile {\n private cache: CacheEntry | null = null\n private CACHE_TTL: number\n\n constructor(\n private cfg: OzoneConfig,\n private appviewClient: Client,\n cacheTTL?: number,\n ) {\n this.CACHE_TTL = cacheTTL || cfg.service.serviceRecordCacheTTL\n }\n\n static creator(\n cfg: OzoneConfig,\n appviewClient: Client,\n ): ModerationServiceProfileCreator {\n return () => new ModerationServiceProfile(cfg, appviewClient)\n }\n\n async getProfile() {\n const now = Date.now()\n\n if (!this.cache || now - this.cache.timestamp > this.CACHE_TTL) {\n try {\n const body = await this.appviewClient.call(\n app.bsky.labeler.getServices,\n { dids: [this.cfg.service.did], detailed: true },\n )\n\n if (\n app.bsky.labeler.defs.labelerViewDetailed.$isTypeOf(body.views?.[0])\n ) {\n this.cache = {\n profile: body.views[0],\n timestamp: now,\n }\n }\n } catch (e) {\n // On error, fail open\n httpLogger.error(`Failed to fetch labeler profile: ${e?.['message']}`)\n }\n }\n\n return this.cache?.profile || null\n }\n\n async validateReasonType(reasonType: string): Promise<string> {\n const profile = await this.getProfile()\n\n if (!Array.isArray(profile?.reasonTypes)) {\n return reasonType\n }\n\n const supportedReasonTypes = profile.reasonTypes\n\n // Check if the reason type is directly supported\n if (supportedReasonTypes.includes(reasonType)) {\n return reasonType\n }\n\n // Allow new reason types only if they map to a supported old reason type\n const mappedOldReason = NEW_TO_OLD_REASON_MAPPING[reasonType]\n if (mappedOldReason && supportedReasonTypes.includes(mappedOldReason)) {\n return reasonType\n }\n\n throw new InvalidRequestError(`Invalid reason type: ${reasonType}`)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../src/mod-service/profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,aAAa,CAAA;AAEpD,OAAO,EAAE,WAAW,EA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AC,CAAC,CAAC;wBACtB,SAAS,EAAE,GAAG;qBACf,CAAA;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,sBAAsB;gBACtB,UAAU,CAAC,KAAK,CAAC,oCAAoC,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;YACxE,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,IAAI,IAAI,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,UAAkB,EAClB,IAAkB;QAElB,0EAA0E;QAC1E,IAAI,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,OAAO,UAAU,CAAA;QACnB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAA;QAEvC,IACE,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC;YACnC,CAAC,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,EACzC,CAAC;YACD,wEAAwE;YACxE,IAAI,CAAC,gBAAgB,EAAE,GAAG,CAAC;gBACzB,IAAI;gBACJ,WAAW,EAAE,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC;oBAC7C,CAAC,CAAC,UAAU;oBACZ,CAAC,CAAC,SAAS;aACd,CAAC,CAAA;YACF,MAAM,IAAI,mBAAmB,CAAC,wBAAwB,UAAU,EAAE,CAAC,CAAA;QACrE,CAAC;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;CACF","sourcesContent":["import { Counter, type Registry } from 'prom-client'\nimport type { Client } from '@atproto/lex-client'\nimport { TokenSchema } from '@atproto/lex-schema'\nimport { InvalidRequestError } from '@atproto/xrpc-server'\nimport { isAppealReport } from '../api/util.js'\nimport type { OzoneConfig } from '../config/index.js'\nimport { app, com, tools } from '../lexicons/index.js'\nimport { httpLogger } from '../logger.js'\n\ntype ReportMethod =\n | typeof com.atproto.moderation.createReport.$lxm\n | typeof tools.ozone.moderation.emitEvent.$lxm\n\nconst KNOWN_REASON_TYPES = new Set<string>(\n [com.atproto.moderation.defs, tools.ozone.report.defs].flatMap((defs) =>\n Object.values(defs)\n .filter((value) => value instanceof TokenSchema)\n .map((token) => token.value),\n ),\n)\n\ninterface CacheEntry {\n profile: app.bsky.labeler.defs.LabelerViewDetailed | null\n timestamp: number\n}\n\nexport type ModerationServiceProfileCreator = () => ModerationServiceProfile\n\nexport class ModerationServiceProfile {\n private cache: CacheEntry | null = null\n private CACHE_TTL: number\n\n constructor(\n private cfg: OzoneConfig,\n private appviewClient: Client,\n cacheTTL?: number,\n private reasonRejections?: Counter<'nsid' | 'reason_type'>,\n ) {\n this.CACHE_TTL = cacheTTL || cfg.service.serviceRecordCacheTTL\n }\n\n static creator(\n cfg: OzoneConfig,\n appviewClient: Client,\n register?: Registry,\n ): ModerationServiceProfileCreator {\n const reasonRejections = register\n ? new Counter({\n name: 'ozone_report_reason_rejections_total',\n help: 'Report attempts rejected because the reason type is not in the labeler allowlist',\n labelNames: ['nsid', 'reason_type'] as const,\n registers: [register],\n })\n : undefined\n\n if (reasonRejections) {\n for (const nsid of [\n com.atproto.moderation.createReport.$lxm,\n tools.ozone.moderation.emitEvent.$lxm,\n ]) {\n for (const reason_type of [...KNOWN_REASON_TYPES, 'unknown']) {\n reasonRejections.inc({ nsid, reason_type }, 0)\n }\n }\n }\n\n return () =>\n new ModerationServiceProfile(\n cfg,\n appviewClient,\n undefined,\n reasonRejections,\n )\n }\n\n async getProfile() {\n const now = Date.now()\n\n if (!this.cache || now - this.cache.timestamp > this.CACHE_TTL) {\n try {\n const body = await this.appviewClient.call(\n app.bsky.labeler.getServices,\n { dids: [this.cfg.service.did], detailed: true },\n )\n\n if (\n app.bsky.labeler.defs.labelerViewDetailed.$isTypeOf(body.views?.[0])\n ) {\n this.cache = {\n profile: body.views[0],\n timestamp: now,\n }\n }\n } catch (e) {\n // On error, fail open\n httpLogger.error(`Failed to fetch labeler profile: ${e?.['message']}`)\n }\n }\n\n return this.cache?.profile || null\n }\n\n async validateReasonType(\n reasonType: string,\n nsid: ReportMethod,\n ): Promise<string> {\n // @NOTE appeals remain available regardless of the report-type allowlist.\n if (isAppealReport(reasonType)) {\n return reasonType\n }\n\n const profile = await this.getProfile()\n\n if (\n Array.isArray(profile?.reasonTypes) &&\n !profile.reasonTypes.includes(reasonType)\n ) {\n // @NOTE caller-supplied custom values must not create unbounded series.\n this.reasonRejections?.inc({\n nsid,\n reason_type: KNOWN_REASON_TYPES.has(reasonType)\n ? reasonType\n : 'unknown',\n })\n throw new InvalidRequestError(`Invalid reason type: ${reasonType}`)\n }\n\n return reasonType\n }\n}\n"]}
|
|
@@ -48,6 +48,11 @@ export type FindReportsForSubjectParams = {
|
|
|
48
48
|
* Whether to target all reports owned by the subject DID.
|
|
49
49
|
*/
|
|
50
50
|
includeAllOwned?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Allow explicit IDs to select records owned by an account subject.
|
|
53
|
+
* Broad selectors remain scoped to the account unless includeAllOwned is set.
|
|
54
|
+
*/
|
|
55
|
+
includeOwnedRecordIds?: boolean;
|
|
51
56
|
/**
|
|
52
57
|
* Whether to lock the selected reports for update.
|
|
53
58
|
*/
|
|
@@ -111,6 +116,7 @@ export type ProcessReportActionParams = {
|
|
|
111
116
|
metadata?: Record<string, unknown>;
|
|
112
117
|
subjectDid: DidString;
|
|
113
118
|
subjectUri: string | null;
|
|
119
|
+
subjectType: string;
|
|
114
120
|
eventId: number;
|
|
115
121
|
eventType: string;
|
|
116
122
|
createdBy: DidString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../src/mod-service/report.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,SAAS,EACT,SAAS,EACV,MAAM,qBAAqB,CAAA;AAI5B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,O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
@@ -189,8 +189,8 @@ export async function findReportsForSubject(db, params) {
|
|
|
189
189
|
.where('r.did', '=', params.subjectDid)
|
|
190
190
|
.where('me.subjectDid', '=', params.subjectDid);
|
|
191
191
|
if (!params.includeAllOwned) {
|
|
192
|
-
//
|
|
193
|
-
//
|
|
192
|
+
// Match the exact subject, optionally including explicitly selected record
|
|
193
|
+
// reports for account actions. Broad selectors retain their subject scope.
|
|
194
194
|
if (params.subjectUri) {
|
|
195
195
|
const uri = new AtUri(params.subjectUri);
|
|
196
196
|
if (uri.collection === CHAT_MESSAGE_COLLECTION) {
|
|
@@ -206,10 +206,22 @@ export async function findReportsForSubject(db, params) {
|
|
|
206
206
|
}
|
|
207
207
|
}
|
|
208
208
|
else {
|
|
209
|
-
builder = builder
|
|
210
|
-
.
|
|
211
|
-
|
|
212
|
-
|
|
209
|
+
builder = builder.where((eb) => eb.or([
|
|
210
|
+
eb.and([
|
|
211
|
+
eb('r.recordPath', '=', ''),
|
|
212
|
+
eb('r.subjectMessageId', 'is', null),
|
|
213
|
+
eb('r.subjectConvoId', 'is', null),
|
|
214
|
+
]),
|
|
215
|
+
...(params.includeOwnedRecordIds && params.reportIds?.length
|
|
216
|
+
? [
|
|
217
|
+
eb.and([
|
|
218
|
+
eb('r.id', 'in', params.reportIds),
|
|
219
|
+
eb('me.subjectType', '=', com.atproto.repo.strongRef.$type),
|
|
220
|
+
eb('r.recordPath', '!=', ''),
|
|
221
|
+
]),
|
|
222
|
+
]
|
|
223
|
+
: []),
|
|
224
|
+
]));
|
|
213
225
|
}
|
|
214
226
|
}
|
|
215
227
|
if (params.protectActiveReview) {
|
|
@@ -482,6 +494,8 @@ export async function processReportAction(params) {
|
|
|
482
494
|
reportTypes: reportAction.types,
|
|
483
495
|
targetAll: reportAction.all || reportAction.allOwned,
|
|
484
496
|
includeAllOwned: reportAction.allOwned,
|
|
497
|
+
includeOwnedRecordIds: closesReports &&
|
|
498
|
+
params.subjectType === com.atproto.admin.defs.repoRef.$type,
|
|
485
499
|
protectActiveReview: closesReports,
|
|
486
500
|
lockForUpdate: closesReports,
|
|
487
501
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","sourceRoot":"","sources":["../../src/mod-service/report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAO5B,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACxE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAG1D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAgB7E,SAAS,WAAW,CAAC,EAAY;IAC/B,OAAO,EAAE,CAAC,EAAE;SACT,UAAU,CAAC,aAAa,CAAC;SACzB,SAAS,CAAC,wBAAwB,EAAE,OAAO,EAAE,WAAW,CAAC;SACzD,KAAK,CAAC,WAAW,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;AAC9E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,EAAY,EACZ,MAA+C;IAE/C,IAAI,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC,CAAA;IAE7B,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,EA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,CACL,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAChB,QAAQ,EAAE,CAAC,CAAC,EAAE;YACd,YAAY,EAAE,CAAC,CAAC,YAAY;YAC5B,cAAc,EAAE,CAAC,CAAC,cAAc;YAChC,YAAY,EAAE,IAAI;YAClB,UAAU,EAAE,YAAY,CAAC,IAAI,IAAI,IAAI;YACrC,IAAI,EACF,CAAC,CAAC,YAAY,KAAK,eAAe;gBAChC,CAAC,CAAC;oBACE,GAAG,MAAM,CAAC,QAAQ;oBAClB,UAAU,EAAE,QAAQ;oBACpB,aAAa,EAAE,OAAO;iBACvB;gBACH,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,IAAI,IAAI,CAAC;YAC/B,WAAW,EAAE,YAAY,CAAC,WAAW,IAAI,KAAK;YAC9C,SAAS;YACT,SAAS,EAAE,GAAG;SACf,CAAC,CAAC,CACJ;aACA,SAAS,CAAC,CAAC,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC;aAC1D,OAAO,EAAE,CAAA;QAEZ,MAAM,sBAAsB,CAC1B,EAAE,EACF,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC5B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,UAAU,EAAE,QAAQ,CAAC,EAAE;YACvB,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,SAAS,EAAE,QAAQ,CAAC,SAAS;SAC9B,CAAC,CAAC,EACH,MAAM,CAAC,YAAY,CACpB,CAAA;IACH,CAAC;IAED,OAAO,YAAY,CAAC,MAAM,CAAA;AAC5B,CAAC","sourcesContent":["import { sql } from 'kysely'\nimport type {\n AtUriString,\n DatetimeString,\n DidString,\n UriString,\n} from '@atproto/lex-schema'\nimport { currentDatetimeString, isDidString } from '@atproto/lex-schema'\nimport { AtUri } from '@atproto/syntax'\nimport { InvalidRequestError } from '@atproto/xrpc-server'\nimport type { Database } from '../db/index.js'\nimport type { Report } from '../db/schema/report.js'\nimport { chat, com, tools } from '../lexicons/index.js'\nimport {\n AlreadyInTargetState,\n InvalidStateTransition,\n handleReportUpdate,\n} from '../report/handle-report-update.js'\nimport { getActivityMetadata } from '../report/metadata.js'\nimport { notifyReportActivities } from '../report/notifications.js'\nimport { CHAT_CONVO_COLLECTION, CHAT_MESSAGE_COLLECTION } from './subject.js'\n\nexport type ReportWithEvent = Omit<Report, 'id'> & {\n id: number\n subjectDid: DidString\n subjectUri: UriString | null\n subjectCid: string | null\n reportedBy: DidString\n comment: string | null\n meta: Record<string, string | boolean | number> | null\n}\n\nexport type QueryReportsResult = {\n reports: ReportWithEvent[]\n cursor: string | undefined\n}\nfunction reportQuery(db: Database) {\n return db.db\n .selectFrom('report as r')\n .innerJoin('moderation_event as me', 'me.id', 'r.eventId')\n .where('me.action', '=', tools.ozone.moderation.defs.modEventReport.$type)\n}\n\nexport async function queryReports(\n db: Database,\n params: tools.ozone.report.queryReports.$Params,\n): Promise<QueryReportsResult> {\n let builder = reportQuery(db)\n\n if (params.queueId !== undefined) {\n builder = builder.where('r.queueId', '=', params.queueId)\n }\n\n builder = builder.where('r.status', '=', params.status)\n\n if (params.subject) {\n const isAtUri = params.subject.startsWith('at://')\n if (isAtUri) {\n const uri = new AtUri(params.subject)\n if (uri.collection === CHAT_MESSAGE_COLLECTION) {\n builder = builder\n .where('r.did', '=', uri.did)\n .where('r.subjectMessageId', '=', uri.rkey)\n } else if (uri.collection === CHAT_CONVO_COLLECTION) {\n builder = builder\n .where('r.did', '=', uri.did)\n .where('r.subjectConvoId', '=', uri.rkey)\n .where('r.subjectMessageId', 'is', null)\n } else {\n builder = builder\n .where('r.did', '=', uri.did)\n .where('r.recordPath', '=', `${uri.collection}/${uri.rkey}`)\n }\n } else if (isDidString(params.subject)) {\n builder = builder\n .where('r.did', '=', params.subject)\n .where('r.recordPath', '=', '')\n .where('r.subjectMessageId', 'is', null)\n .where('r.subjectConvoId', 'is', null)\n } else {\n throw new Error('Subject must be a DID or an AT-URI')\n }\n }\n\n if (params.did) {\n builder = builder.where('r.did', '=', params.did)\n }\n\n if (params.subjectType === 'account') {\n builder = builder\n .where('r.recordPath', '=', '')\n .where('r.subjectMessageId', 'is', null)\n .where('r.subjectConvoId', 'is', null)\n } else if (params.subjectType === 'record') {\n builder = builder.where('r.recordPath', '!=', '')\n } else if (params.subjectType === 'message') {\n builder = builder.where('r.subjectMessageId', 'is not', null)\n } else if (params.subjectType === 'conversation') {\n builder = builder\n .where('r.subjectConvoId', 'is not', null)\n .where('r.subjectMessageId', 'is', null)\n }\n\n if (params.collections?.length) {\n // Filter by collection prefix on recordPath (uses text_pattern_ops index)\n const collectionConditions = params.collections.map(\n (collection) => sql`r.\"recordPath\" LIKE ${`${collection}/%`}`,\n )\n builder = builder.where(\n sql<boolean>`(${sql.join(collectionConditions, sql` OR `)})`,\n )\n }\n\n if (params.reportTypes?.length) {\n builder = builder.where('r.reportType', 'in', params.reportTypes)\n }\n\n if (params.isMuted !== undefined) {\n builder = builder.where('r.isMuted', '=', params.isMuted)\n }\n\n if (params.reportedAfter) {\n builder = builder.where('r.createdAt', '>', params.reportedAfter)\n }\n\n if (params.reportedBefore) {\n builder = builder.where('r.createdAt', '<', params.reportedBefore)\n }\n\n if (params.assignedTo) {\n builder = builder.where('r.assignedTo', '=', params.assignedTo)\n }\n\n const sortField = params.sortField ?? 'createdAt'\n const sortDirection = params.sortDirection ?? 'desc'\n\n builder = builder\n .orderBy(\n sortField === 'updatedAt' ? 'r.updatedAt' : 'r.createdAt',\n sortDirection,\n )\n // Keep the tie-breaker aligned with the primary sort for consistent keyset pagination and index scans.\n .orderBy('r.id', sortDirection)\n\n const limit = params.limit ?? 50\n if (params.cursor) {\n const [sortValue, id] = params.cursor.split('::')\n const sortCol = sortField === 'updatedAt' ? 'r.updatedAt' : 'r.createdAt'\n if (sortDirection === 'desc') {\n builder = builder.where(sql<boolean>`(\n ${sql.ref(sortCol)} < ${sortValue}\n OR (${sql.ref(sortCol)} = ${sortValue} AND r.id < ${Number(id)})\n )`)\n } else {\n builder = builder.where(sql<boolean>`(\n ${sql.ref(sortCol)} > ${sortValue}\n OR (${sql.ref(sortCol)} = ${sortValue} AND r.id > ${Number(id)})\n )`)\n }\n }\n\n const finalQuery = builder\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .limit(limit + 1)\n\n const reports = await finalQuery.execute()\n\n let cursor: string | undefined\n const hasMore = reports.length > limit\n if (hasMore) {\n const last = reports[limit - 1]\n const sortValue =\n sortField === 'updatedAt' ? last.updatedAt : last.createdAt\n cursor = `${sortValue}::${last.id}`\n }\n\n const reportsToReturn = hasMore ? reports.slice(0, limit) : reports\n\n return {\n reports: reportsToReturn,\n cursor,\n }\n}\n\nexport async function getReportById(\n db: Database,\n id: number,\n): Promise<ReportWithEvent | undefined> {\n return reportQuery(db)\n .where('r.id', '=', id)\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .executeTakeFirst()\n}\n\nexport async function getReportsByIds(\n db: Database,\n ids: number[],\n): Promise<ReportWithEvent[]> {\n if (!ids.length) return []\n return reportQuery(db)\n .where('r.id', 'in', ids)\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .execute()\n}\n\nexport async function getLatestReport(\n db: Database,\n): Promise<ReportWithEvent | undefined> {\n return reportQuery(db)\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .orderBy('r.id', 'desc')\n .limit(1)\n .executeTakeFirst()\n}\n\nexport type FindReportsForSubjectParams = {\n /**\n * The DID of the subject for which to find reports.\n */\n subjectDid: DidString\n /**\n * The URI of the subject for which to find reports. If not provided, will match repo-level subjects.\n */\n subjectUri?: AtUriString | null\n /**\n * The IDs of the reports to include. If not provided, all reports are considered.\n */\n reportIds?: number[]\n /**\n * The types of reports to include. If not provided, all types are considered.\n */\n reportTypes?: string[]\n /**\n * The types of reports to exclude. If not provided, no types are excluded.\n */\n excludedReportTypes?: string[]\n /**\n * Whether to target all reports for the subject.\n */\n targetAll?: boolean\n /**\n * Whether to target all reports owned by the subject DID.\n */\n includeAllOwned?: boolean\n /**\n * Whether to lock the selected reports for update.\n */\n lockForUpdate?: boolean\n /**\n * Whether to protect active reviews from being included.\n */\n protectActiveReview?: boolean\n}\n\nexport type ReportResult = {\n id: number\n eventId: number\n queueId: number | null\n queuedAt: DatetimeString | null\n actionEventIds: number[] | null\n actionNote: string | null\n subjectConvoId: string | null\n isMuted: boolean\n status: string\n reportType: string\n createdAt: DatetimeString\n updatedAt: DatetimeString\n}\n\nexport async function findReportsForSubject(\n db: Database,\n params: FindReportsForSubjectParams,\n): Promise<ReportResult[]> {\n let builder = reportQuery(db)\n .where('r.did', '=', params.subjectDid)\n .where('me.subjectDid', '=', params.subjectDid)\n\n if (!params.includeAllOwned) {\n // Filter by subject URI (if provided, match exactly; if null/undefined,\n // match repo-level and exclude chat subjects owned by the same DID).\n if (params.subjectUri) {\n const uri = new AtUri(params.subjectUri)\n if (uri.collection === CHAT_MESSAGE_COLLECTION) {\n builder = builder.where('r.subjectMessageId', '=', uri.rkey)\n } else if (uri.collection === CHAT_CONVO_COLLECTION) {\n builder = builder\n .where('r.subjectConvoId', '=', uri.rkey)\n .where('r.subjectMessageId', 'is', null)\n } else {\n builder = builder.where(\n 'r.recordPath',\n '=',\n `${uri.collection}/${uri.rkey}`,\n )\n }\n } else {\n builder = builder\n .where('r.recordPath', '=', '')\n .where('r.subjectMessageId', 'is', null)\n .where('r.subjectConvoId', 'is', null)\n }\n }\n\n if (params.protectActiveReview) {\n const explicitIds = params.reportIds ?? []\n const reportTypes = params.reportTypes ?? []\n if (!explicitIds.length && !params.targetAll && !reportTypes.length) {\n return []\n }\n builder = builder.where('r.status', '!=', 'closed').where((eb) =>\n eb.or([\n ...(explicitIds.length ? [eb('r.id', 'in', explicitIds)] : []),\n ...(params.targetAll || reportTypes.length\n ? [\n eb.and([\n eb('r.status', 'not in', ['assigned', 'escalated']),\n eb.not(\n eb.exists(\n eb\n .selectFrom('moderator_assignment as ma')\n .select('ma.reportId')\n .whereRef('ma.reportId', '=', 'r.id')\n .where('ma.endAt', 'is', null)\n // @NOTE Keep the lookup correlated instead of hashing all assignments.\n .offset(0),\n ),\n ),\n ...(params.targetAll\n ? []\n : [eb('r.reportType', 'in', reportTypes)]),\n ]),\n ]\n : []),\n ]),\n )\n } else if (params.targetAll) {\n // Target all open/escalated reports on the subject\n builder = builder.where('r.status', 'not in', ['closed'])\n } else if (params.reportIds?.length) {\n // Target specific report IDs — still enforce state transition rules\n builder = builder\n .where('r.id', 'in', params.reportIds)\n .where('r.status', 'not in', ['closed'])\n } else if (params.reportTypes?.length) {\n // Target reports matching specific report types\n builder = builder\n .where('r.reportType', 'in', params.reportTypes)\n .where('r.status', 'not in', ['closed'])\n } else {\n // No targeting criteria provided\n return []\n }\n\n if (params.excludedReportTypes?.length) {\n builder = builder.where(\n 'r.reportType',\n 'not in',\n params.excludedReportTypes,\n )\n }\n\n let query = builder.selectAll('r')\n if (params.lockForUpdate) {\n query = query.orderBy('r.id').forUpdate('r')\n }\n\n const reports = await query.execute()\n\n return reports\n}\n\nexport type CloseReportsForSubjectParams = {\n db: Database\n inboxStartAt?: DatetimeString\n subjectDid: DidString\n subjectUri: string | null\n includeAllOwned?: boolean\n reportTypes?: string[]\n excludedReportTypes?: string[]\n actionEventId?: number\n internalNote?: string\n isAutomated: boolean\n meta?: Record<string, unknown>\n createdBy: DidString\n}\n\nexport type CloseReportsResult = {\n closedCount: number\n reportIds: number[]\n}\n\n/**\n * Closes eligible reports matching the subject and report type filters.\n * Assigned and escalated reports are preserved for explicit review actions.\n * Reports whose current status doesn't permit a transition to closed are\n * skipped silently. An existing moderation event can be linked to each closure.\n */\nexport async function closeReportsForSubject(\n params: CloseReportsForSubjectParams,\n): Promise<CloseReportsResult> {\n const {\n db,\n subjectDid,\n subjectUri,\n reportTypes,\n internalNote,\n isAutomated,\n createdBy,\n } = params\n\n const metadata = getActivityMetadata(params.meta)\n\n return db.transaction(async (dbTxn) => {\n let messageConvoId: string | undefined\n if (params.actionEventId !== undefined) {\n const event = await dbTxn.db\n .selectFrom('moderation_event')\n .select([\n 'action',\n 'subjectDid',\n 'subjectType',\n 'subjectUri',\n 'subjectMessageId',\n 'subjectConvoId',\n ])\n .where('id', '=', params.actionEventId)\n .executeTakeFirst()\n const accountEvent =\n event?.subjectType === com.atproto.admin.defs.repoRef.$type\n const uri = subjectUri ? new AtUri(subjectUri) : null\n const exactRecordEvent =\n !params.includeAllOwned &&\n uri &&\n uri.collection !== CHAT_MESSAGE_COLLECTION &&\n uri.collection !== CHAT_CONVO_COLLECTION &&\n event?.subjectType === com.atproto.repo.strongRef.$type &&\n event.subjectUri === subjectUri\n const exactMessageEvent =\n !params.includeAllOwned &&\n uri?.collection === CHAT_MESSAGE_COLLECTION &&\n event?.subjectType === chat.bsky.convo.defs.messageRef.$type &&\n event.subjectMessageId === uri.rkey\n const exactConvoEvent =\n !params.includeAllOwned &&\n uri?.collection === CHAT_CONVO_COLLECTION &&\n event?.subjectType === chat.bsky.convo.defs.convoRef.$type &&\n event.subjectConvoId === uri.rkey\n if (\n !event ||\n event.subjectDid !== subjectDid ||\n (!accountEvent &&\n !exactRecordEvent &&\n !exactMessageEvent &&\n !exactConvoEvent) ||\n handleReportUpdate('open', { type: 'event', eventType: event.action })\n .nextStatus !== 'closed'\n ) {\n throw new InvalidRequestError(\n 'actionEventId must reference a report-closing event on the subject or its owning account',\n )\n }\n if (exactMessageEvent) {\n messageConvoId = event.subjectConvoId ?? ''\n }\n }\n const matchingReports = await findReportsForSubject(dbTxn, {\n subjectDid,\n subjectUri: subjectUri as AtUriString,\n includeAllOwned: params.includeAllOwned,\n reportTypes: reportTypes?.length ? reportTypes : undefined,\n excludedReportTypes: params.excludedReportTypes,\n targetAll: !reportTypes?.length,\n lockForUpdate: true,\n protectActiveReview: true,\n })\n\n const validUpdates: {\n id: number\n previousStatus: string\n reportType: string\n }[] = []\n for (const report of matchingReports) {\n // Synthetic message URIs omit the conversation ID; keep the link scoped\n // to the conversation identified by the action event.\n if (\n messageConvoId !== undefined &&\n (report.subjectConvoId ?? '') !== messageConvoId\n ) {\n continue\n }\n try {\n const result = handleReportUpdate(report.status, {\n type: 'activity',\n activityType: 'closeActivity',\n })\n if (result.nextStatus && result.activity) {\n validUpdates.push({\n id: report.id,\n previousStatus: result.activity.previousStatus,\n reportType: report.reportType,\n })\n }\n } catch (err) {\n if (\n err instanceof AlreadyInTargetState ||\n err instanceof InvalidStateTransition\n ) {\n continue\n }\n throw err\n }\n }\n\n if (!validUpdates.length) {\n return { closedCount: 0, reportIds: [] }\n }\n\n const now = currentDatetimeString()\n const updateIds = validUpdates.map((u) => u.id)\n\n for (let offset = 0; offset < validUpdates.length; offset += 500) {\n const batch = validUpdates.slice(offset, offset + 500)\n await dbTxn.db\n .updateTable('report')\n .set({\n status: 'closed',\n updatedAt: now,\n closedAt: now,\n ...(params.actionEventId !== undefined && {\n actionEventIds: sql`CASE WHEN \"actionEventIds\" ->> -1 = ${String(params.actionEventId)} THEN \"actionEventIds\" ELSE COALESCE(\"actionEventIds\", '[]'::jsonb) || ${JSON.stringify(params.actionEventId)}::jsonb END`,\n }),\n })\n .where(\n 'id',\n 'in',\n batch.map((u) => u.id),\n )\n .execute()\n\n const activities = await dbTxn.db\n .insertInto('report_activity')\n .values(\n batch.map((u) => ({\n reportId: u.id,\n activityType: 'closeActivity',\n previousStatus: u.previousStatus,\n internalNote: internalNote ?? null,\n publicNote: null,\n meta:\n params.actionEventId !== undefined\n ? {\n ...metadata,\n resolution: 'linked',\n actionEventId: params.actionEventId,\n }\n : u.reportType === tools.ozone.report.defs.ReasonAppeal\n ? {\n ...metadata,\n resolution: 'noAction',\n appealOutcome: 'denied',\n }\n : { ...metadata, resolution: 'noAction' },\n isAutomated,\n createdBy,\n createdAt: now,\n })),\n )\n .returning(['id', 'reportId', 'activityType', 'createdAt'])\n .execute()\n\n await notifyReportActivities(\n dbTxn,\n activities.map((activity) => ({\n reportId: activity.reportId,\n activityId: activity.id,\n activityType: activity.activityType,\n createdAt: activity.createdAt,\n })),\n params.inboxStartAt,\n )\n }\n\n return { closedCount: validUpdates.length, reportIds: updateIds }\n })\n}\n\nexport type ProcessReportActionParams = {\n db: Database\n inboxStartAt?: DatetimeString\n reportAction: {\n ids?: number[]\n types?: string[]\n all?: boolean\n allOwned?: boolean\n note?: string\n isAutomated?: boolean\n }\n metadata?: Record<string, unknown>\n subjectDid: DidString\n subjectUri: string | null\n eventId: number\n eventType: string\n createdBy: DidString\n}\n\nasync function processEmailReportAction(\n db: Database,\n reportAction: ProcessReportActionParams['reportAction'],\n subjectDid: DidString,\n eventId: number,\n): Promise<number> {\n if (\n !reportAction.ids?.length ||\n reportAction.types?.length ||\n reportAction.all\n ) {\n return 0\n }\n\n const reportIds = [...new Set(reportAction.ids)]\n // Email events target a repo DID even when the associated report is\n // record-level; the explicit report IDs disambiguate reports on that repo.\n const matchingReports = await reportQuery(db)\n .where('r.did', '=', subjectDid)\n .where('r.id', 'in', reportIds)\n .select('r.id')\n .execute()\n\n const foundIds = new Set(matchingReports.map((report) => report.id))\n if (!foundIds.size) {\n throw new Error(\n 'No matching reports found for the specified report IDs on this subject',\n )\n }\n\n const missingIds = reportIds.filter((id) => !foundIds.has(id))\n if (missingIds.length) {\n throw new Error(\n `Report IDs ${missingIds.join(', ')} do not exist or do not belong to this subject`,\n )\n }\n\n // Email events are supplemental report history; they must not reopen or\n // otherwise change the status of reports that were already actioned.\n await db.db\n .updateTable('report')\n .set({\n actionEventIds: sql`COALESCE(\"actionEventIds\", '[]'::jsonb) || ${JSON.stringify(eventId)}::jsonb`,\n })\n .where('id', 'in', reportIds)\n .execute()\n\n return matchingReports.length\n}\n\n/**\n * Apply the report action to the matching reports.\n * Returns the number of reports successfully updated.\n *\n * Validates and processes a report action by:\n * 1. Finding matching reports based on targeting criteria\n * 2. Validating that specified report IDs exist and belong to the subject\n * 3. Bulk-updating reports with the action event ID, note, and status\n * 4. Bulk-inserting a report_activity row for each updated report\n *\n * Email events only associate explicit report IDs and do not change report\n * status or create report activities.\n *\n * @throws InvalidRequestError if validation fails\n */\nexport async function processReportAction(\n params: ProcessReportActionParams,\n): Promise<number> {\n const {\n db,\n reportAction,\n subjectDid,\n subjectUri,\n eventId,\n eventType,\n createdBy,\n } = params\n\n if (eventType === tools.ozone.moderation.defs.modEventEmail.$type) {\n return processEmailReportAction(db, reportAction, subjectDid, eventId)\n }\n\n const closesReports =\n handleReportUpdate('open', { type: 'event', eventType }).nextStatus ===\n 'closed'\n // @NOTE Explicit IDs preserve deliberate review actions; broad closure must\n // not interrupt assigned or escalated reports. Lock targets until commit.\n const matchingReports = await findReportsForSubject(db, {\n subjectDid,\n subjectUri: subjectUri as AtUriString,\n reportIds: reportAction.ids,\n reportTypes: reportAction.types,\n targetAll: reportAction.all || reportAction.allOwned,\n includeAllOwned: reportAction.allOwned,\n protectActiveReview: closesReports,\n lockForUpdate: closesReports,\n })\n\n if (matchingReports.length === 0) {\n if (reportAction.ids?.length) {\n throw new Error(\n 'No matching reports found for the specified report IDs on this subject',\n )\n }\n return 0\n }\n\n // Validate that all specified report IDs were found\n if (reportAction.ids?.length) {\n const foundIds = new Set(matchingReports.map((r) => r.id))\n const requestedIds = new Set(reportAction.ids)\n const missingIds = [...requestedIds].filter((id) => !foundIds.has(id))\n\n if (missingIds.length > 0) {\n throw new Error(\n `Report IDs ${missingIds.join(', ')} do not exist, are already closed, or do not belong to this subject`,\n )\n }\n }\n\n // Determine per-report transitions via the pure state machine.\n // Skip reports whose current status doesn't allow the transition.\n const validUpdates: {\n id: number\n nextStatus: string\n activityType: string\n previousStatus: string\n }[] = []\n\n for (const report of matchingReports) {\n try {\n const result = handleReportUpdate(report.status, {\n type: 'event',\n eventType,\n })\n if (result.nextStatus && result.activity) {\n validUpdates.push({\n id: report.id,\n nextStatus: result.nextStatus,\n activityType: result.activity.activityType,\n previousStatus: result.activity.previousStatus,\n })\n }\n } catch (err) {\n if (\n err instanceof AlreadyInTargetState ||\n err instanceof InvalidStateTransition\n ) {\n // Skip reports that can't transition — silent per design\n continue\n }\n throw err\n }\n }\n\n if (!validUpdates.length) {\n return 0\n }\n\n const now = currentDatetimeString()\n for (let offset = 0; offset < validUpdates.length; offset += 500) {\n const batch = validUpdates.slice(offset, offset + 500)\n // All transitions from this event share a target status.\n const status = batch[0].nextStatus\n await db.db\n .updateTable('report')\n .set({\n actionEventIds: sql`COALESCE(\"actionEventIds\", '[]'::jsonb) || ${JSON.stringify(eventId)}::jsonb`,\n actionNote: reportAction.note ?? null,\n status,\n updatedAt: now,\n closedAt: status === 'closed' ? now : null,\n })\n .where(\n 'id',\n 'in',\n batch.map((u) => u.id),\n )\n .execute()\n\n const activities = await db.db\n .insertInto('report_activity')\n .values(\n batch.map((u) => ({\n reportId: u.id,\n activityType: u.activityType,\n previousStatus: u.previousStatus,\n internalNote: null,\n publicNote: reportAction.note ?? null,\n meta:\n u.activityType === 'closeActivity'\n ? {\n ...params.metadata,\n resolution: 'linked',\n actionEventId: eventId,\n }\n : (params.metadata ?? null),\n isAutomated: reportAction.isAutomated ?? false,\n createdBy,\n createdAt: now,\n })),\n )\n .returning(['id', 'reportId', 'activityType', 'createdAt'])\n .execute()\n\n await notifyReportActivities(\n db,\n activities.map((activity) => ({\n reportId: activity.reportId,\n activityId: activity.id,\n activityType: activity.activityType,\n createdAt: activity.createdAt,\n })),\n params.inboxStartAt,\n )\n }\n\n return validUpdates.length\n}\n"]}
|
|
1
|
+
{"version":3,"file":"report.js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BAAsB,CAC1B,EAAE,EACF,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC5B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,UAAU,EAAE,QAAQ,CAAC,EAAE;YACvB,YAAY,EAAE,QAAQ,CAAC,YAAY;YACnC,SAAS,EAAE,QAAQ,CAAC,SAAS;SAC9B,CAAC,CAAC,EACH,MAAM,CAAC,YAAY,CACpB,CAAA;IACH,CAAC;IAED,OAAO,YAAY,CAAC,MAAM,CAAA;AAC5B,CAAC","sourcesContent":["import { sql } from 'kysely'\nimport type {\n AtUriString,\n DatetimeString,\n DidString,\n UriString,\n} from '@atproto/lex-schema'\nimport { currentDatetimeString, isDidString } from '@atproto/lex-schema'\nimport { AtUri } from '@atproto/syntax'\nimport { InvalidRequestError } from '@atproto/xrpc-server'\nimport type { Database } from '../db/index.js'\nimport type { Report } from '../db/schema/report.js'\nimport { chat, com, tools } from '../lexicons/index.js'\nimport {\n AlreadyInTargetState,\n InvalidStateTransition,\n handleReportUpdate,\n} from '../report/handle-report-update.js'\nimport { getActivityMetadata } from '../report/metadata.js'\nimport { notifyReportActivities } from '../report/notifications.js'\nimport { CHAT_CONVO_COLLECTION, CHAT_MESSAGE_COLLECTION } from './subject.js'\n\nexport type ReportWithEvent = Omit<Report, 'id'> & {\n id: number\n subjectDid: DidString\n subjectUri: UriString | null\n subjectCid: string | null\n reportedBy: DidString\n comment: string | null\n meta: Record<string, string | boolean | number> | null\n}\n\nexport type QueryReportsResult = {\n reports: ReportWithEvent[]\n cursor: string | undefined\n}\nfunction reportQuery(db: Database) {\n return db.db\n .selectFrom('report as r')\n .innerJoin('moderation_event as me', 'me.id', 'r.eventId')\n .where('me.action', '=', tools.ozone.moderation.defs.modEventReport.$type)\n}\n\nexport async function queryReports(\n db: Database,\n params: tools.ozone.report.queryReports.$Params,\n): Promise<QueryReportsResult> {\n let builder = reportQuery(db)\n\n if (params.queueId !== undefined) {\n builder = builder.where('r.queueId', '=', params.queueId)\n }\n\n builder = builder.where('r.status', '=', params.status)\n\n if (params.subject) {\n const isAtUri = params.subject.startsWith('at://')\n if (isAtUri) {\n const uri = new AtUri(params.subject)\n if (uri.collection === CHAT_MESSAGE_COLLECTION) {\n builder = builder\n .where('r.did', '=', uri.did)\n .where('r.subjectMessageId', '=', uri.rkey)\n } else if (uri.collection === CHAT_CONVO_COLLECTION) {\n builder = builder\n .where('r.did', '=', uri.did)\n .where('r.subjectConvoId', '=', uri.rkey)\n .where('r.subjectMessageId', 'is', null)\n } else {\n builder = builder\n .where('r.did', '=', uri.did)\n .where('r.recordPath', '=', `${uri.collection}/${uri.rkey}`)\n }\n } else if (isDidString(params.subject)) {\n builder = builder\n .where('r.did', '=', params.subject)\n .where('r.recordPath', '=', '')\n .where('r.subjectMessageId', 'is', null)\n .where('r.subjectConvoId', 'is', null)\n } else {\n throw new Error('Subject must be a DID or an AT-URI')\n }\n }\n\n if (params.did) {\n builder = builder.where('r.did', '=', params.did)\n }\n\n if (params.subjectType === 'account') {\n builder = builder\n .where('r.recordPath', '=', '')\n .where('r.subjectMessageId', 'is', null)\n .where('r.subjectConvoId', 'is', null)\n } else if (params.subjectType === 'record') {\n builder = builder.where('r.recordPath', '!=', '')\n } else if (params.subjectType === 'message') {\n builder = builder.where('r.subjectMessageId', 'is not', null)\n } else if (params.subjectType === 'conversation') {\n builder = builder\n .where('r.subjectConvoId', 'is not', null)\n .where('r.subjectMessageId', 'is', null)\n }\n\n if (params.collections?.length) {\n // Filter by collection prefix on recordPath (uses text_pattern_ops index)\n const collectionConditions = params.collections.map(\n (collection) => sql`r.\"recordPath\" LIKE ${`${collection}/%`}`,\n )\n builder = builder.where(\n sql<boolean>`(${sql.join(collectionConditions, sql` OR `)})`,\n )\n }\n\n if (params.reportTypes?.length) {\n builder = builder.where('r.reportType', 'in', params.reportTypes)\n }\n\n if (params.isMuted !== undefined) {\n builder = builder.where('r.isMuted', '=', params.isMuted)\n }\n\n if (params.reportedAfter) {\n builder = builder.where('r.createdAt', '>', params.reportedAfter)\n }\n\n if (params.reportedBefore) {\n builder = builder.where('r.createdAt', '<', params.reportedBefore)\n }\n\n if (params.assignedTo) {\n builder = builder.where('r.assignedTo', '=', params.assignedTo)\n }\n\n const sortField = params.sortField ?? 'createdAt'\n const sortDirection = params.sortDirection ?? 'desc'\n\n builder = builder\n .orderBy(\n sortField === 'updatedAt' ? 'r.updatedAt' : 'r.createdAt',\n sortDirection,\n )\n // Keep the tie-breaker aligned with the primary sort for consistent keyset pagination and index scans.\n .orderBy('r.id', sortDirection)\n\n const limit = params.limit ?? 50\n if (params.cursor) {\n const [sortValue, id] = params.cursor.split('::')\n const sortCol = sortField === 'updatedAt' ? 'r.updatedAt' : 'r.createdAt'\n if (sortDirection === 'desc') {\n builder = builder.where(sql<boolean>`(\n ${sql.ref(sortCol)} < ${sortValue}\n OR (${sql.ref(sortCol)} = ${sortValue} AND r.id < ${Number(id)})\n )`)\n } else {\n builder = builder.where(sql<boolean>`(\n ${sql.ref(sortCol)} > ${sortValue}\n OR (${sql.ref(sortCol)} = ${sortValue} AND r.id > ${Number(id)})\n )`)\n }\n }\n\n const finalQuery = builder\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .limit(limit + 1)\n\n const reports = await finalQuery.execute()\n\n let cursor: string | undefined\n const hasMore = reports.length > limit\n if (hasMore) {\n const last = reports[limit - 1]\n const sortValue =\n sortField === 'updatedAt' ? last.updatedAt : last.createdAt\n cursor = `${sortValue}::${last.id}`\n }\n\n const reportsToReturn = hasMore ? reports.slice(0, limit) : reports\n\n return {\n reports: reportsToReturn,\n cursor,\n }\n}\n\nexport async function getReportById(\n db: Database,\n id: number,\n): Promise<ReportWithEvent | undefined> {\n return reportQuery(db)\n .where('r.id', '=', id)\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .executeTakeFirst()\n}\n\nexport async function getReportsByIds(\n db: Database,\n ids: number[],\n): Promise<ReportWithEvent[]> {\n if (!ids.length) return []\n return reportQuery(db)\n .where('r.id', 'in', ids)\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .execute()\n}\n\nexport async function getLatestReport(\n db: Database,\n): Promise<ReportWithEvent | undefined> {\n return reportQuery(db)\n .selectAll('r')\n .select([\n 'me.subjectDid',\n 'me.subjectUri',\n 'me.subjectCid',\n 'me.createdBy as reportedBy',\n 'me.comment',\n 'me.meta',\n ])\n .orderBy('r.id', 'desc')\n .limit(1)\n .executeTakeFirst()\n}\n\nexport type FindReportsForSubjectParams = {\n /**\n * The DID of the subject for which to find reports.\n */\n subjectDid: DidString\n /**\n * The URI of the subject for which to find reports. If not provided, will match repo-level subjects.\n */\n subjectUri?: AtUriString | null\n /**\n * The IDs of the reports to include. If not provided, all reports are considered.\n */\n reportIds?: number[]\n /**\n * The types of reports to include. If not provided, all types are considered.\n */\n reportTypes?: string[]\n /**\n * The types of reports to exclude. If not provided, no types are excluded.\n */\n excludedReportTypes?: string[]\n /**\n * Whether to target all reports for the subject.\n */\n targetAll?: boolean\n /**\n * Whether to target all reports owned by the subject DID.\n */\n includeAllOwned?: boolean\n /**\n * Allow explicit IDs to select records owned by an account subject.\n * Broad selectors remain scoped to the account unless includeAllOwned is set.\n */\n includeOwnedRecordIds?: boolean\n /**\n * Whether to lock the selected reports for update.\n */\n lockForUpdate?: boolean\n /**\n * Whether to protect active reviews from being included.\n */\n protectActiveReview?: boolean\n}\n\nexport type ReportResult = {\n id: number\n eventId: number\n queueId: number | null\n queuedAt: DatetimeString | null\n actionEventIds: number[] | null\n actionNote: string | null\n subjectConvoId: string | null\n isMuted: boolean\n status: string\n reportType: string\n createdAt: DatetimeString\n updatedAt: DatetimeString\n}\n\nexport async function findReportsForSubject(\n db: Database,\n params: FindReportsForSubjectParams,\n): Promise<ReportResult[]> {\n let builder = reportQuery(db)\n .where('r.did', '=', params.subjectDid)\n .where('me.subjectDid', '=', params.subjectDid)\n\n if (!params.includeAllOwned) {\n // Match the exact subject, optionally including explicitly selected record\n // reports for account actions. Broad selectors retain their subject scope.\n if (params.subjectUri) {\n const uri = new AtUri(params.subjectUri)\n if (uri.collection === CHAT_MESSAGE_COLLECTION) {\n builder = builder.where('r.subjectMessageId', '=', uri.rkey)\n } else if (uri.collection === CHAT_CONVO_COLLECTION) {\n builder = builder\n .where('r.subjectConvoId', '=', uri.rkey)\n .where('r.subjectMessageId', 'is', null)\n } else {\n builder = builder.where(\n 'r.recordPath',\n '=',\n `${uri.collection}/${uri.rkey}`,\n )\n }\n } else {\n builder = builder.where((eb) =>\n eb.or([\n eb.and([\n eb('r.recordPath', '=', ''),\n eb('r.subjectMessageId', 'is', null),\n eb('r.subjectConvoId', 'is', null),\n ]),\n ...(params.includeOwnedRecordIds && params.reportIds?.length\n ? [\n eb.and([\n eb('r.id', 'in', params.reportIds),\n eb('me.subjectType', '=', com.atproto.repo.strongRef.$type),\n eb('r.recordPath', '!=', ''),\n ]),\n ]\n : []),\n ]),\n )\n }\n }\n\n if (params.protectActiveReview) {\n const explicitIds = params.reportIds ?? []\n const reportTypes = params.reportTypes ?? []\n if (!explicitIds.length && !params.targetAll && !reportTypes.length) {\n return []\n }\n builder = builder.where('r.status', '!=', 'closed').where((eb) =>\n eb.or([\n ...(explicitIds.length ? [eb('r.id', 'in', explicitIds)] : []),\n ...(params.targetAll || reportTypes.length\n ? [\n eb.and([\n eb('r.status', 'not in', ['assigned', 'escalated']),\n eb.not(\n eb.exists(\n eb\n .selectFrom('moderator_assignment as ma')\n .select('ma.reportId')\n .whereRef('ma.reportId', '=', 'r.id')\n .where('ma.endAt', 'is', null)\n // @NOTE Keep the lookup correlated instead of hashing all assignments.\n .offset(0),\n ),\n ),\n ...(params.targetAll\n ? []\n : [eb('r.reportType', 'in', reportTypes)]),\n ]),\n ]\n : []),\n ]),\n )\n } else if (params.targetAll) {\n // Target all open/escalated reports on the subject\n builder = builder.where('r.status', 'not in', ['closed'])\n } else if (params.reportIds?.length) {\n // Target specific report IDs — still enforce state transition rules\n builder = builder\n .where('r.id', 'in', params.reportIds)\n .where('r.status', 'not in', ['closed'])\n } else if (params.reportTypes?.length) {\n // Target reports matching specific report types\n builder = builder\n .where('r.reportType', 'in', params.reportTypes)\n .where('r.status', 'not in', ['closed'])\n } else {\n // No targeting criteria provided\n return []\n }\n\n if (params.excludedReportTypes?.length) {\n builder = builder.where(\n 'r.reportType',\n 'not in',\n params.excludedReportTypes,\n )\n }\n\n let query = builder.selectAll('r')\n if (params.lockForUpdate) {\n query = query.orderBy('r.id').forUpdate('r')\n }\n\n const reports = await query.execute()\n\n return reports\n}\n\nexport type CloseReportsForSubjectParams = {\n db: Database\n inboxStartAt?: DatetimeString\n subjectDid: DidString\n subjectUri: string | null\n includeAllOwned?: boolean\n reportTypes?: string[]\n excludedReportTypes?: string[]\n actionEventId?: number\n internalNote?: string\n isAutomated: boolean\n meta?: Record<string, unknown>\n createdBy: DidString\n}\n\nexport type CloseReportsResult = {\n closedCount: number\n reportIds: number[]\n}\n\n/**\n * Closes eligible reports matching the subject and report type filters.\n * Assigned and escalated reports are preserved for explicit review actions.\n * Reports whose current status doesn't permit a transition to closed are\n * skipped silently. An existing moderation event can be linked to each closure.\n */\nexport async function closeReportsForSubject(\n params: CloseReportsForSubjectParams,\n): Promise<CloseReportsResult> {\n const {\n db,\n subjectDid,\n subjectUri,\n reportTypes,\n internalNote,\n isAutomated,\n createdBy,\n } = params\n\n const metadata = getActivityMetadata(params.meta)\n\n return db.transaction(async (dbTxn) => {\n let messageConvoId: string | undefined\n if (params.actionEventId !== undefined) {\n const event = await dbTxn.db\n .selectFrom('moderation_event')\n .select([\n 'action',\n 'subjectDid',\n 'subjectType',\n 'subjectUri',\n 'subjectMessageId',\n 'subjectConvoId',\n ])\n .where('id', '=', params.actionEventId)\n .executeTakeFirst()\n const accountEvent =\n event?.subjectType === com.atproto.admin.defs.repoRef.$type\n const uri = subjectUri ? new AtUri(subjectUri) : null\n const exactRecordEvent =\n !params.includeAllOwned &&\n uri &&\n uri.collection !== CHAT_MESSAGE_COLLECTION &&\n uri.collection !== CHAT_CONVO_COLLECTION &&\n event?.subjectType === com.atproto.repo.strongRef.$type &&\n event.subjectUri === subjectUri\n const exactMessageEvent =\n !params.includeAllOwned &&\n uri?.collection === CHAT_MESSAGE_COLLECTION &&\n event?.subjectType === chat.bsky.convo.defs.messageRef.$type &&\n event.subjectMessageId === uri.rkey\n const exactConvoEvent =\n !params.includeAllOwned &&\n uri?.collection === CHAT_CONVO_COLLECTION &&\n event?.subjectType === chat.bsky.convo.defs.convoRef.$type &&\n event.subjectConvoId === uri.rkey\n if (\n !event ||\n event.subjectDid !== subjectDid ||\n (!accountEvent &&\n !exactRecordEvent &&\n !exactMessageEvent &&\n !exactConvoEvent) ||\n handleReportUpdate('open', { type: 'event', eventType: event.action })\n .nextStatus !== 'closed'\n ) {\n throw new InvalidRequestError(\n 'actionEventId must reference a report-closing event on the subject or its owning account',\n )\n }\n if (exactMessageEvent) {\n messageConvoId = event.subjectConvoId ?? ''\n }\n }\n const matchingReports = await findReportsForSubject(dbTxn, {\n subjectDid,\n subjectUri: subjectUri as AtUriString,\n includeAllOwned: params.includeAllOwned,\n reportTypes: reportTypes?.length ? reportTypes : undefined,\n excludedReportTypes: params.excludedReportTypes,\n targetAll: !reportTypes?.length,\n lockForUpdate: true,\n protectActiveReview: true,\n })\n\n const validUpdates: {\n id: number\n previousStatus: string\n reportType: string\n }[] = []\n for (const report of matchingReports) {\n // Synthetic message URIs omit the conversation ID; keep the link scoped\n // to the conversation identified by the action event.\n if (\n messageConvoId !== undefined &&\n (report.subjectConvoId ?? '') !== messageConvoId\n ) {\n continue\n }\n try {\n const result = handleReportUpdate(report.status, {\n type: 'activity',\n activityType: 'closeActivity',\n })\n if (result.nextStatus && result.activity) {\n validUpdates.push({\n id: report.id,\n previousStatus: result.activity.previousStatus,\n reportType: report.reportType,\n })\n }\n } catch (err) {\n if (\n err instanceof AlreadyInTargetState ||\n err instanceof InvalidStateTransition\n ) {\n continue\n }\n throw err\n }\n }\n\n if (!validUpdates.length) {\n return { closedCount: 0, reportIds: [] }\n }\n\n const now = currentDatetimeString()\n const updateIds = validUpdates.map((u) => u.id)\n\n for (let offset = 0; offset < validUpdates.length; offset += 500) {\n const batch = validUpdates.slice(offset, offset + 500)\n await dbTxn.db\n .updateTable('report')\n .set({\n status: 'closed',\n updatedAt: now,\n closedAt: now,\n ...(params.actionEventId !== undefined && {\n actionEventIds: sql`CASE WHEN \"actionEventIds\" ->> -1 = ${String(params.actionEventId)} THEN \"actionEventIds\" ELSE COALESCE(\"actionEventIds\", '[]'::jsonb) || ${JSON.stringify(params.actionEventId)}::jsonb END`,\n }),\n })\n .where(\n 'id',\n 'in',\n batch.map((u) => u.id),\n )\n .execute()\n\n const activities = await dbTxn.db\n .insertInto('report_activity')\n .values(\n batch.map((u) => ({\n reportId: u.id,\n activityType: 'closeActivity',\n previousStatus: u.previousStatus,\n internalNote: internalNote ?? null,\n publicNote: null,\n meta:\n params.actionEventId !== undefined\n ? {\n ...metadata,\n resolution: 'linked',\n actionEventId: params.actionEventId,\n }\n : u.reportType === tools.ozone.report.defs.ReasonAppeal\n ? {\n ...metadata,\n resolution: 'noAction',\n appealOutcome: 'denied',\n }\n : { ...metadata, resolution: 'noAction' },\n isAutomated,\n createdBy,\n createdAt: now,\n })),\n )\n .returning(['id', 'reportId', 'activityType', 'createdAt'])\n .execute()\n\n await notifyReportActivities(\n dbTxn,\n activities.map((activity) => ({\n reportId: activity.reportId,\n activityId: activity.id,\n activityType: activity.activityType,\n createdAt: activity.createdAt,\n })),\n params.inboxStartAt,\n )\n }\n\n return { closedCount: validUpdates.length, reportIds: updateIds }\n })\n}\n\nexport type ProcessReportActionParams = {\n db: Database\n inboxStartAt?: DatetimeString\n reportAction: {\n ids?: number[]\n types?: string[]\n all?: boolean\n allOwned?: boolean\n note?: string\n isAutomated?: boolean\n }\n metadata?: Record<string, unknown>\n subjectDid: DidString\n subjectUri: string | null\n subjectType: string\n eventId: number\n eventType: string\n createdBy: DidString\n}\n\nasync function processEmailReportAction(\n db: Database,\n reportAction: ProcessReportActionParams['reportAction'],\n subjectDid: DidString,\n eventId: number,\n): Promise<number> {\n if (\n !reportAction.ids?.length ||\n reportAction.types?.length ||\n reportAction.all\n ) {\n return 0\n }\n\n const reportIds = [...new Set(reportAction.ids)]\n // Email events target a repo DID even when the associated report is\n // record-level; the explicit report IDs disambiguate reports on that repo.\n const matchingReports = await reportQuery(db)\n .where('r.did', '=', subjectDid)\n .where('r.id', 'in', reportIds)\n .select('r.id')\n .execute()\n\n const foundIds = new Set(matchingReports.map((report) => report.id))\n if (!foundIds.size) {\n throw new Error(\n 'No matching reports found for the specified report IDs on this subject',\n )\n }\n\n const missingIds = reportIds.filter((id) => !foundIds.has(id))\n if (missingIds.length) {\n throw new Error(\n `Report IDs ${missingIds.join(', ')} do not exist or do not belong to this subject`,\n )\n }\n\n // Email events are supplemental report history; they must not reopen or\n // otherwise change the status of reports that were already actioned.\n await db.db\n .updateTable('report')\n .set({\n actionEventIds: sql`COALESCE(\"actionEventIds\", '[]'::jsonb) || ${JSON.stringify(eventId)}::jsonb`,\n })\n .where('id', 'in', reportIds)\n .execute()\n\n return matchingReports.length\n}\n\n/**\n * Apply the report action to the matching reports.\n * Returns the number of reports successfully updated.\n *\n * Validates and processes a report action by:\n * 1. Finding matching reports based on targeting criteria\n * 2. Validating that specified report IDs exist and belong to the subject\n * 3. Bulk-updating reports with the action event ID, note, and status\n * 4. Bulk-inserting a report_activity row for each updated report\n *\n * Email events only associate explicit report IDs and do not change report\n * status or create report activities.\n *\n * @throws InvalidRequestError if validation fails\n */\nexport async function processReportAction(\n params: ProcessReportActionParams,\n): Promise<number> {\n const {\n db,\n reportAction,\n subjectDid,\n subjectUri,\n eventId,\n eventType,\n createdBy,\n } = params\n\n if (eventType === tools.ozone.moderation.defs.modEventEmail.$type) {\n return processEmailReportAction(db, reportAction, subjectDid, eventId)\n }\n\n const closesReports =\n handleReportUpdate('open', { type: 'event', eventType }).nextStatus ===\n 'closed'\n // @NOTE Explicit IDs preserve deliberate review actions; broad closure must\n // not interrupt assigned or escalated reports. Lock targets until commit.\n const matchingReports = await findReportsForSubject(db, {\n subjectDid,\n subjectUri: subjectUri as AtUriString,\n reportIds: reportAction.ids,\n reportTypes: reportAction.types,\n targetAll: reportAction.all || reportAction.allOwned,\n includeAllOwned: reportAction.allOwned,\n includeOwnedRecordIds:\n closesReports &&\n params.subjectType === com.atproto.admin.defs.repoRef.$type,\n protectActiveReview: closesReports,\n lockForUpdate: closesReports,\n })\n\n if (matchingReports.length === 0) {\n if (reportAction.ids?.length) {\n throw new Error(\n 'No matching reports found for the specified report IDs on this subject',\n )\n }\n return 0\n }\n\n // Validate that all specified report IDs were found\n if (reportAction.ids?.length) {\n const foundIds = new Set(matchingReports.map((r) => r.id))\n const requestedIds = new Set(reportAction.ids)\n const missingIds = [...requestedIds].filter((id) => !foundIds.has(id))\n\n if (missingIds.length > 0) {\n throw new Error(\n `Report IDs ${missingIds.join(', ')} do not exist, are already closed, or do not belong to this subject`,\n )\n }\n }\n\n // Determine per-report transitions via the pure state machine.\n // Skip reports whose current status doesn't allow the transition.\n const validUpdates: {\n id: number\n nextStatus: string\n activityType: string\n previousStatus: string\n }[] = []\n\n for (const report of matchingReports) {\n try {\n const result = handleReportUpdate(report.status, {\n type: 'event',\n eventType,\n })\n if (result.nextStatus && result.activity) {\n validUpdates.push({\n id: report.id,\n nextStatus: result.nextStatus,\n activityType: result.activity.activityType,\n previousStatus: result.activity.previousStatus,\n })\n }\n } catch (err) {\n if (\n err instanceof AlreadyInTargetState ||\n err instanceof InvalidStateTransition\n ) {\n // Skip reports that can't transition — silent per design\n continue\n }\n throw err\n }\n }\n\n if (!validUpdates.length) {\n return 0\n }\n\n const now = currentDatetimeString()\n for (let offset = 0; offset < validUpdates.length; offset += 500) {\n const batch = validUpdates.slice(offset, offset + 500)\n // All transitions from this event share a target status.\n const status = batch[0].nextStatus\n await db.db\n .updateTable('report')\n .set({\n actionEventIds: sql`COALESCE(\"actionEventIds\", '[]'::jsonb) || ${JSON.stringify(eventId)}::jsonb`,\n actionNote: reportAction.note ?? null,\n status,\n updatedAt: now,\n closedAt: status === 'closed' ? now : null,\n })\n .where(\n 'id',\n 'in',\n batch.map((u) => u.id),\n )\n .execute()\n\n const activities = await db.db\n .insertInto('report_activity')\n .values(\n batch.map((u) => ({\n reportId: u.id,\n activityType: u.activityType,\n previousStatus: u.previousStatus,\n internalNote: null,\n publicNote: reportAction.note ?? null,\n meta:\n u.activityType === 'closeActivity'\n ? {\n ...params.metadata,\n resolution: 'linked',\n actionEventId: eventId,\n }\n : (params.metadata ?? null),\n isAutomated: reportAction.isAutomated ?? false,\n createdBy,\n createdAt: now,\n })),\n )\n .returning(['id', 'reportId', 'activityType', 'createdAt'])\n .execute()\n\n await notifyReportActivities(\n db,\n activities.map((activity) => ({\n reportId: activity.reportId,\n activityId: activity.id,\n activityType: activity.activityType,\n createdAt: activity.createdAt,\n })),\n params.inboxStartAt,\n )\n }\n\n return validUpdates.length\n}\n"]}
|
|
@@ -4,21 +4,6 @@ import type { Database } from '../db/index.js';
|
|
|
4
4
|
import type { DatabaseSchema } from '../db/schema/index.js';
|
|
5
5
|
import type { ModerationEventRow, ModerationSubjectStatusRow } from './types.js';
|
|
6
6
|
export declare const moderationSubjectStatusQueryBuilder: (db: DatabaseSchema) => import("kysely").SelectQueryBuilder<{
|
|
7
|
-
account_events_stats: import("kysely").Nullable<import("../db/schema/account_events_stats.js").AccountEventsStats>;
|
|
8
|
-
account_record_events_stats: import("kysely").Nullable<{
|
|
9
|
-
subjectDid: import("kysely").GeneratedAlways<string>;
|
|
10
|
-
totalReports: import("kysely").GeneratedAlways<number>;
|
|
11
|
-
reportedCount: import("kysely").GeneratedAlways<number>;
|
|
12
|
-
escalatedCount: import("kysely").GeneratedAlways<number>;
|
|
13
|
-
appealedCount: import("kysely").GeneratedAlways<number>;
|
|
14
|
-
}>;
|
|
15
|
-
account_record_status_stats: import("kysely").Nullable<{
|
|
16
|
-
did: import("kysely").GeneratedAlways<string>;
|
|
17
|
-
subjectCount: import("kysely").GeneratedAlways<number>;
|
|
18
|
-
pendingCount: import("kysely").GeneratedAlways<number>;
|
|
19
|
-
processedCount: import("kysely").GeneratedAlways<number>;
|
|
20
|
-
takendownCount: import("kysely").GeneratedAlways<number>;
|
|
21
|
-
}>;
|
|
22
7
|
account_strike: import("kysely").Nullable<import("../db/schema/account_strike.js").AccountStrike>;
|
|
23
8
|
blob_push_event: import("../db/schema/blob_push_event.js").BlobPushEvent;
|
|
24
9
|
communication_template: import("../db/schema/communication_template.js").CommunicationTemplate;
|
|
@@ -33,7 +18,6 @@ export declare const moderationSubjectStatusQueryBuilder: (db: DatabaseSchema) =
|
|
|
33
18
|
moderation_event: import("../db/schema/moderation_event.js").ModerationEvent;
|
|
34
19
|
moderation_subject_status: import("../db/schema/moderation_subject_status.js").ModerationSubjectStatus;
|
|
35
20
|
moderator_assignment: import("../db/schema/moderator_assignment.js").ModeratorAssignment;
|
|
36
|
-
record_events_stats: import("../db/schema/record_events_stats.js").RecordEventsStats;
|
|
37
21
|
record_push_event: import("../db/schema/record_push_event.js").RecordPushEvent;
|
|
38
22
|
repo_push_event: import("../db/schema/repo_push_event.js").RepoPushEvent;
|
|
39
23
|
report: import("../db/schema/report.js").Report;
|
|
@@ -48,7 +32,7 @@ export declare const moderationSubjectStatusQueryBuilder: (db: DatabaseSchema) =
|
|
|
48
32
|
setting: import("../db/schema/setting.js").Setting;
|
|
49
33
|
signing_key: import("../db/schema/signing_key.js").SigningKey;
|
|
50
34
|
verification: import("../db/schema/verification.js").Verification;
|
|
51
|
-
}, "
|
|
35
|
+
}, "account_strike" | "moderation_subject_status", {
|
|
52
36
|
ageAssuranceState: string;
|
|
53
37
|
ageAssuranceUpdatedBy: string | null | undefined;
|
|
54
38
|
appealed: boolean | null;
|
|
@@ -78,22 +62,6 @@ export declare const moderationSubjectStatusQueryBuilder: (db: DatabaseSchema) =
|
|
|
78
62
|
tags: string[] | null;
|
|
79
63
|
takendown: boolean;
|
|
80
64
|
updatedAt: DatetimeString;
|
|
81
|
-
} & {
|
|
82
|
-
appealCount: number | null;
|
|
83
|
-
escalateCount: number | null;
|
|
84
|
-
reportCount: number | null;
|
|
85
|
-
suspendCount: number | null;
|
|
86
|
-
takedownCount: number | null;
|
|
87
|
-
} & {
|
|
88
|
-
appealedCount: number | null;
|
|
89
|
-
escalatedCount: number | null;
|
|
90
|
-
reportedCount: number | null;
|
|
91
|
-
totalReports: number | null;
|
|
92
|
-
} & {
|
|
93
|
-
pendingCount: number | null;
|
|
94
|
-
processedCount: number | null;
|
|
95
|
-
subjectCount: number | null;
|
|
96
|
-
takendownCount: number | null;
|
|
97
65
|
} & {
|
|
98
66
|
firstStrikeAt: DatetimeString | null;
|
|
99
67
|
lastStrikeAt: DatetimeString | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/mod-service/status.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAO/E,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAI3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAuMhF,eAAO,MAAM,mCAAmC,OAAQ,cAAc
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/mod-service/status.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAO/E,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAI3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAA;AAuMhF,eAAO,MAAM,mCAAmC,OAAQ,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAarE,CAAA;AAKD,eAAO,MAAM,6BAA6B,OACpC,QAAQ,mBACK,kBAAkB,aACxB,MAAM,EAAE,oBACD,MAAM,KACvB,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAgP3C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,8BAA8B,YAChC,SAAS,GAAG,KAAK,YAChB,MAAM,GAAG,IAAI,KACtB;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CA6BvD,CAAA"}
|
|
@@ -169,35 +169,9 @@ const getSubjectStatusForRecordEvent = ({ event, currentStatus, }) => {
|
|
|
169
169
|
return {};
|
|
170
170
|
};
|
|
171
171
|
export const moderationSubjectStatusQueryBuilder = (db) => {
|
|
172
|
-
// @NOTE: Using select() instead of selectAll() below because the materialized
|
|
173
|
-
// views might be incomplete, and we don't want the null `did` columns to
|
|
174
|
-
// interfere with the (never null) `did` column from the
|
|
175
|
-
// `moderation_subject_status` table in the results
|
|
176
172
|
return db
|
|
177
173
|
.selectFrom('moderation_subject_status')
|
|
178
174
|
.selectAll('moderation_subject_status')
|
|
179
|
-
.leftJoin('account_events_stats', (join) => join.onRef('moderation_subject_status.did', '=', 'account_events_stats.subjectDid'))
|
|
180
|
-
.select([
|
|
181
|
-
'account_events_stats.takedownCount',
|
|
182
|
-
'account_events_stats.suspendCount',
|
|
183
|
-
'account_events_stats.escalateCount',
|
|
184
|
-
'account_events_stats.reportCount',
|
|
185
|
-
'account_events_stats.appealCount',
|
|
186
|
-
])
|
|
187
|
-
.leftJoin('account_record_events_stats', (join) => join.onRef('moderation_subject_status.did', '=', 'account_record_events_stats.subjectDid'))
|
|
188
|
-
.select([
|
|
189
|
-
'account_record_events_stats.totalReports',
|
|
190
|
-
'account_record_events_stats.reportedCount',
|
|
191
|
-
'account_record_events_stats.escalatedCount',
|
|
192
|
-
'account_record_events_stats.appealedCount',
|
|
193
|
-
])
|
|
194
|
-
.leftJoin('account_record_status_stats', (join) => join.onRef('moderation_subject_status.did', '=', 'account_record_status_stats.did'))
|
|
195
|
-
.select([
|
|
196
|
-
'account_record_status_stats.subjectCount',
|
|
197
|
-
'account_record_status_stats.pendingCount',
|
|
198
|
-
'account_record_status_stats.processedCount',
|
|
199
|
-
'account_record_status_stats.takendownCount',
|
|
200
|
-
])
|
|
201
175
|
.leftJoin('account_strike', (join) => join.onRef('moderation_subject_status.did', '=', 'account_strike.did'))
|
|
202
176
|
.select([
|
|
203
177
|
'account_strike.activeStrikeCount as strikeCount',
|