@atproto/ozone 0.10.10 → 0.11.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 CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atproto/ozone
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#5756](https://github.com/bluesky-social/atproto/pull/5756) [`54f54ea`](https://github.com/bluesky-social/atproto/commit/54f54ea831f37fe9f722844177f7e1bed8ae8bdc) Thanks [@gcwill70](https://github.com/gcwill70)! - Protect assigned and escalated reports from broad moderation-event and batch report closure, including owned subjects.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#5757](https://github.com/bluesky-social/atproto/pull/5757) [`6ed6fe3`](https://github.com/bluesky-social/atproto/commit/6ed6fe39dded20f1e8995042135fba83b31d7b26) Thanks [@foysalit](https://github.com/foysalit)! - Allow new appeals when a moderation action follows a resolved appeal.
12
+
13
+ - [#5750](https://github.com/bluesky-social/atproto/pull/5750) [`03a76ee`](https://github.com/bluesky-social/atproto/commit/03a76ee15e4acc123dc45446fc7b6fa46ba0e64e) Thanks [@gcwill70](https://github.com/gcwill70)! - Allow moderation events to succeed when reportAction.types matches no reports, while retaining strict validation for explicit report IDs.
14
+
15
+ - [#5746](https://github.com/bluesky-social/atproto/pull/5746) [`1c8c3a3`](https://github.com/bluesky-social/atproto/commit/1c8c3a3a8ea27a060f38cda71172339aa1728113) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update to OpenTelemetry JS SDK 3.x (`@opentelemetry/api` 1.10), which requires Node.js `>=22.15.0`. Event log records are now emitted through `@opentelemetry/api` (`@opentelemetry/api-logs` was removed upstream). The HTTP instrumentation only reports the stable `http.server.request.duration` and `http.client.request.duration` metrics: the legacy `http.server.duration` and `http.client.duration` metrics are gone, and `OTEL_SEMCONV_STABILITY_OPT_IN=http` no longer has any effect. Instrumentations passed to `setup()` now also instrument modules loaded through ESM imports, not only `require()`d ones, when built on the same `@opentelemetry/instrumentation` as `@atproto-labs/opentelemetry-node`; otherwise `setup()` now throws an `InstrumentationMismatchError` instead of silently missing them. The new `@atproto-labs/opentelemetry-node/better-sqlite3-plugin` export, a port of `opentelemetry-plugin-better-sqlite3` producing identical spans, replaces that package in the PDS.
16
+ - Updated dependencies [[`3bfd00f`](https://github.com/bluesky-social/atproto/commit/3bfd00f484dc144482c82a4ed248adc49e6be769), [`3bfd00f`](https://github.com/bluesky-social/atproto/commit/3bfd00f484dc144482c82a4ed248adc49e6be769), [`1c8c3a3`](https://github.com/bluesky-social/atproto/commit/1c8c3a3a8ea27a060f38cda71172339aa1728113), [`1c8c3a3`](https://github.com/bluesky-social/atproto/commit/1c8c3a3a8ea27a060f38cda71172339aa1728113), [`1c8c3a3`](https://github.com/bluesky-social/atproto/commit/1c8c3a3a8ea27a060f38cda71172339aa1728113), [`3bfd00f`](https://github.com/bluesky-social/atproto/commit/3bfd00f484dc144482c82a4ed248adc49e6be769), [`3bfd00f`](https://github.com/bluesky-social/atproto/commit/3bfd00f484dc144482c82a4ed248adc49e6be769), [`3bfd00f`](https://github.com/bluesky-social/atproto/commit/3bfd00f484dc144482c82a4ed248adc49e6be769)]:
17
+ - @atproto/common@0.8.7
18
+ - @atproto-labs/opentelemetry-node@0.5.0
19
+ - @atproto/xrpc-server@0.13.7
20
+ - @atproto/lex@0.4.4
21
+
3
22
  ## 0.10.10
4
23
 
5
24
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"appealActionedSubject.d.ts","sourceRoot":"","sources":["../../../src/api/inbox/appealActionedSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EACZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAiBlD,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,QA2GvD"}
1
+ {"version":3,"file":"appealActionedSubject.d.ts","sourceRoot":"","sources":["../../../src/api/inbox/appealActionedSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,MAAM,EACZ,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAiBlD,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,QA4GvD"}
@@ -29,7 +29,7 @@ export default function (server, ctx) {
29
29
  if (!canAppealForOthers && requester !== action.subjectDid) {
30
30
  throw new ForbiddenError('Moderation action is not appealable', 'NotAppealable');
31
31
  }
32
- if (!isAppealableEvent(action.action)) {
32
+ if (!isAppealableEvent(action)) {
33
33
  throw new ForbiddenError('Subject is not appealable', 'NotAppealable');
34
34
  }
35
35
  if (!isAppealWindowOpen(action.createdAt, ctx.cfg.inbox.appealWindowMonths)) {
@@ -56,6 +56,7 @@ export default function (server, ctx) {
56
56
  subject,
57
57
  action: actionInput,
58
58
  resolvedActionId: action?.id,
59
+ resolvedActionAt: action?.createdAt,
59
60
  reason: input.body.reason,
60
61
  modTool: input.body.modTool,
61
62
  });
@@ -1 +1 @@
1
- {"version":3,"file":"appealActionedSubject.js","sourceRoot":"","sources":["../../../src/api/inbox/appealActionedSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,GAEpB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,GACX,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EACL,mBAAmB,EACnB,gBAAg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AAC,GAAG,EAAE;gBACpB,SAAS,EAAE,OAAO,CAAC,GAAG;gBACtB,WAAW,EAAE,SAAS,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;gBAC9D,OAAO;gBACP,MAAM,EAAE,WAAW;gBACnB,gBAAgB,EAAE,MAAM,EAAE,EAAE;gBAC5B,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM;gBACzB,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO;aAC5B,CAAC,CAAA;YAEF,wEAAwE;YACxE,0EAA0E;YAC1E,yEAAyE;YACzE,wEAAwE;YACxE,oCAAoC;YACpC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;YAC/D,MAAM,IAAI,GAAG,MAAM,kBAAkB,CACnC,GAAG,CAAC,EAAE,EACN,OAAO,EACP,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EACnB,GAAG,CAAC,GAAG,CAAC,KAAK,EACb,MAAM,CACP,CAAA;YACD,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,mBAAmB,CAC3B,4DAA4D,CAC7D,CAAA;YACH,CAAC;YACD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QACrD,CAAC;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {\n ForbiddenError,\n InternalServerError,\n type Server,\n} from '@atproto/xrpc-server'\nimport type { AppContext } from '../../context.js'\nimport {\n fileAppeal,\n isAppealWindowOpen,\n isAppealableEvent,\n resolveAppealAction,\n subjectKey,\n} from '../../inbox/appeal.js'\nimport { getSeenAt } from '../../inbox/seen.js'\nimport { inboxHasStarted } from '../../inbox/start.js'\nimport { hydrateSubjectView, loadSubject } from '../../inbox/views.js'\nimport { tools } from '../../lexicons/index.js'\nimport {\n subjectFromEventRow,\n subjectFromInput,\n} from '../../mod-service/subject.js'\n\nexport default function (server: Server, ctx: AppContext) {\n server.add(tools.ozone.inbox.appealActionedSubject, {\n auth: ctx.authVerifier.standard,\n handler: async ({ input, auth }) => {\n if (!inboxHasStarted(ctx.cfg.inbox.startAt)) {\n throw new ForbiddenError(\n 'The moderation inbox has not started',\n 'NotAppealable',\n )\n }\n const { action: actionInput, subject: subjectInput } = input.body\n const requester = auth.credentials.iss\n const canAppealForOthers =\n auth.credentials.isAdmin ||\n auth.credentials.isModerator ||\n auth.credentials.isTriage\n\n const inputSubject = subjectFromInput(subjectInput)\n const action = await resolveAppealAction(ctx, inputSubject, actionInput)\n if (\n ctx.cfg.inbox.startAt &&\n ((actionInput && !action) ||\n (action && action.createdAt < ctx.cfg.inbox.startAt))\n ) {\n throw new ForbiddenError(\n 'Moderation action is not visible in the inbox',\n 'NotAppealable',\n )\n }\n\n // validate action event\n if (action) {\n if (!canAppealForOthers && requester !== action.subjectDid) {\n throw new ForbiddenError(\n 'Moderation action is not appealable',\n 'NotAppealable',\n )\n }\n if (!isAppealableEvent(action.action)) {\n throw new ForbiddenError('Subject is not appealable', 'NotAppealable')\n }\n if (\n !isAppealWindowOpen(\n action.createdAt,\n ctx.cfg.inbox.appealWindowMonths,\n )\n ) {\n throw new ForbiddenError(\n 'Appeal window has expired',\n 'AppealWindowExpired',\n )\n }\n }\n\n // parse subject and validate\n const subject = action ? subjectFromEventRow(action) : inputSubject\n if (\n inputSubject &&\n action &&\n subjectKey(inputSubject) !== subjectKey(subject)\n ) {\n throw new ForbiddenError('Subject is not appealable', 'NotAppealable')\n }\n if (!canAppealForOthers && requester !== subject.did) {\n throw new ForbiddenError('Subject is not appealable', 'NotAppealable')\n }\n if (\n ctx.cfg.inbox.startAt &&\n !(await loadSubject(ctx.db, subject, ctx.cfg.inbox.startAt)).actionCount\n ) {\n throw new ForbiddenError(\n 'Subject is not visible in the inbox',\n 'NotAppealable',\n )\n }\n\n await fileAppeal(ctx, {\n requester: subject.did,\n submittedBy: requester !== subject.did ? requester : undefined,\n subject,\n action: actionInput,\n resolvedActionId: action?.id,\n reason: input.body.reason,\n modTool: input.body.modTool,\n })\n\n // The appeal report ID stays internal: callers track the appeal through\n // the subject view. Read after the commit so the view reflects the appeal\n // that was just filed, and treat a missing snapshot as a bug rather than\n // papering over it - the subject provably has moderation history, since\n // the write above just added to it.\n const seenAt = await getSeenAt(ctx.db, subject.did, 'subjects')\n const view = await hydrateSubjectView(\n ctx.db,\n subject,\n ctx.cfg.service.did,\n ctx.cfg.inbox,\n seenAt,\n )\n if (!view) {\n throw new InternalServerError(\n 'Appeal was recorded but its subject could not be read back',\n )\n }\n return { encoding: 'application/json', body: view }\n },\n })\n}\n"]}
1
+ {"version":3,"file":"appealActionedSubject.js","sourceRoot":"","sources":["../../../src/api/inbox/appealActionedSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,GAEpB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,GACX,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EACL,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,8BAA8B,CAAA;AAErC,MAAM,CAAC,OAAO,WAAW,MAAc,EAAE,GAAe;IACtD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,EAAE;QAClD,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,QAAQ;QAC/B,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,E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E,SAAS;gBACnC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM;gBACzB,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,OAAO;aAC5B,CAAC,CAAA;YAEF,wEAAwE;YACxE,0EAA0E;YAC1E,yEAAyE;YACzE,wEAAwE;YACxE,oCAAoC;YACpC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;YAC/D,MAAM,IAAI,GAAG,MAAM,kBAAkB,CACnC,GAAG,CAAC,EAAE,EACN,OAAO,EACP,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EACnB,GAAG,CAAC,GAAG,CAAC,KAAK,EACb,MAAM,CACP,CAAA;YACD,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,MAAM,IAAI,mBAAmB,CAC3B,4DAA4D,CAC7D,CAAA;YACH,CAAC;YACD,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;QACrD,CAAC;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {\n ForbiddenError,\n InternalServerError,\n type Server,\n} from '@atproto/xrpc-server'\nimport type { AppContext } from '../../context.js'\nimport {\n fileAppeal,\n isAppealWindowOpen,\n isAppealableEvent,\n resolveAppealAction,\n subjectKey,\n} from '../../inbox/appeal.js'\nimport { getSeenAt } from '../../inbox/seen.js'\nimport { inboxHasStarted } from '../../inbox/start.js'\nimport { hydrateSubjectView, loadSubject } from '../../inbox/views.js'\nimport { tools } from '../../lexicons/index.js'\nimport {\n subjectFromEventRow,\n subjectFromInput,\n} from '../../mod-service/subject.js'\n\nexport default function (server: Server, ctx: AppContext) {\n server.add(tools.ozone.inbox.appealActionedSubject, {\n auth: ctx.authVerifier.standard,\n handler: async ({ input, auth }) => {\n if (!inboxHasStarted(ctx.cfg.inbox.startAt)) {\n throw new ForbiddenError(\n 'The moderation inbox has not started',\n 'NotAppealable',\n )\n }\n const { action: actionInput, subject: subjectInput } = input.body\n const requester = auth.credentials.iss\n const canAppealForOthers =\n auth.credentials.isAdmin ||\n auth.credentials.isModerator ||\n auth.credentials.isTriage\n\n const inputSubject = subjectFromInput(subjectInput)\n const action = await resolveAppealAction(ctx, inputSubject, actionInput)\n if (\n ctx.cfg.inbox.startAt &&\n ((actionInput && !action) ||\n (action && action.createdAt < ctx.cfg.inbox.startAt))\n ) {\n throw new ForbiddenError(\n 'Moderation action is not visible in the inbox',\n 'NotAppealable',\n )\n }\n\n // validate action event\n if (action) {\n if (!canAppealForOthers && requester !== action.subjectDid) {\n throw new ForbiddenError(\n 'Moderation action is not appealable',\n 'NotAppealable',\n )\n }\n if (!isAppealableEvent(action)) {\n throw new ForbiddenError('Subject is not appealable', 'NotAppealable')\n }\n if (\n !isAppealWindowOpen(\n action.createdAt,\n ctx.cfg.inbox.appealWindowMonths,\n )\n ) {\n throw new ForbiddenError(\n 'Appeal window has expired',\n 'AppealWindowExpired',\n )\n }\n }\n\n // parse subject and validate\n const subject = action ? subjectFromEventRow(action) : inputSubject\n if (\n inputSubject &&\n action &&\n subjectKey(inputSubject) !== subjectKey(subject)\n ) {\n throw new ForbiddenError('Subject is not appealable', 'NotAppealable')\n }\n if (!canAppealForOthers && requester !== subject.did) {\n throw new ForbiddenError('Subject is not appealable', 'NotAppealable')\n }\n if (\n ctx.cfg.inbox.startAt &&\n !(await loadSubject(ctx.db, subject, ctx.cfg.inbox.startAt)).actionCount\n ) {\n throw new ForbiddenError(\n 'Subject is not visible in the inbox',\n 'NotAppealable',\n )\n }\n\n await fileAppeal(ctx, {\n requester: subject.did,\n submittedBy: requester !== subject.did ? requester : undefined,\n subject,\n action: actionInput,\n resolvedActionId: action?.id,\n resolvedActionAt: action?.createdAt,\n reason: input.body.reason,\n modTool: input.body.modTool,\n })\n\n // The appeal report ID stays internal: callers track the appeal through\n // the subject view. Read after the commit so the view reflects the appeal\n // that was just filed, and treat a missing snapshot as a bug rather than\n // papering over it - the subject provably has moderation history, since\n // the write above just added to it.\n const seenAt = await getSeenAt(ctx.db, subject.did, 'subjects')\n const view = await hydrateSubjectView(\n ctx.db,\n subject,\n ctx.cfg.service.did,\n ctx.cfg.inbox,\n seenAt,\n )\n if (!view) {\n throw new InternalServerError(\n 'Appeal was recorded but its subject could not be read back',\n )\n }\n return { encoding: 'application/json', body: view }\n },\n })\n}\n"]}
@@ -8,7 +8,7 @@ import type { AppealView } from '../lexicons/tools/ozone/inbox/defs.js';
8
8
  import type { ModSubject } from '../mod-service/subject.js';
9
9
  import type { ModerationSubjectStatusRow } from '../mod-service/types.js';
10
10
  import { type AppealOutcome } from './appeal-outcome.js';
11
- export declare const APPEAL_REASON_TYPE = "tools.ozone.report.defs#reasonAppeal";
11
+ export declare const APPEAL_REASON_TYPE: "tools.ozone.report.defs#reasonAppeal";
12
12
  export declare const TAKEDOWN = "tools.ozone.moderation.defs#modEventTakedown";
13
13
  export declare const REVERSE_TAKEDOWN = "tools.ozone.moderation.defs#modEventReverseTakedown";
14
14
  export declare const LABEL = "tools.ozone.moderation.defs#modEventLabel";
@@ -28,12 +28,18 @@ export type AppealReport = {
28
28
  closedAt: DatetimeString | null;
29
29
  outcome?: AppealOutcome | null;
30
30
  };
31
+ export type AppealEligibility = {
32
+ hasActiveAppeal: boolean;
33
+ lastClosedAt: DatetimeString | null;
34
+ hasUnknownClosure: boolean;
35
+ };
31
36
  export type AppealInput = {
32
37
  subject: ModSubject;
33
38
  status: Pick<ModerationSubjectStatusRow, 'appealed' | 'lastAppealedAt'> | null;
34
39
  report: AppealReport | null;
35
40
  /** Eligibility retains older appeals even when their history is hidden. */
36
41
  eligibilityReport?: AppealReport | null;
42
+ eligibility?: AppealEligibility;
37
43
  /** Calendar months an action stays appealable, from `InboxConfig`. */
38
44
  windowMonths: number;
39
45
  latestAppealableAt: DatetimeString | null;
@@ -44,13 +50,24 @@ export type AppealState = {
44
50
  };
45
51
  export declare const PUBLIC_EVENT_ACTIONS: readonly ["tools.ozone.moderation.defs#modEventTakedown", "tools.ozone.moderation.defs#modEventLabel", "tools.ozone.moderation.defs#modEventEmail", "tools.ozone.moderation.defs#modEventMuteReporter", "tools.ozone.moderation.defs#revokeAccountCredentialsEvent", "tools.ozone.moderation.defs#modEventReverseTakedown"];
46
52
  export declare const APPEALABLE_EVENT_ACTIONS: readonly ["tools.ozone.moderation.defs#modEventTakedown", "tools.ozone.moderation.defs#modEventLabel"];
47
- export declare const isAppealableEvent: (action: string) => boolean;
53
+ export declare const isAppealableEvent: (event: {
54
+ action: string;
55
+ createLabelVals: string | null;
56
+ }) => boolean;
57
+ export declare function hasKnownLatestAppealable(latest: DatetimeString | null, events: readonly {
58
+ createdAt: DatetimeString;
59
+ action: string;
60
+ createLabelVals: string | null;
61
+ }[]): boolean;
62
+ export declare const appealableEventFilter: import("kysely").RawBuilder<boolean>;
63
+ export declare const appealReportTypeFilter: import("kysely").RawBuilder<boolean>;
64
+ export declare const appealReportOrder: import("kysely").RawBuilder<number>;
48
65
  export declare const appealWindowEnd: (actionCreatedAt: DatetimeString, windowMonths: number) => DatetimeString;
49
66
  export declare const isAppealWindowOpen: (actionCreatedAt: DatetimeString, windowMonths: number, now?: Date) => boolean;
50
67
  /**
51
68
  * Appeal state, derived entirely from data Ozone already records.
52
69
  */
53
- export declare const toAppealState: ({ subject, status, report, eligibilityReport, latestAppealableAt, windowMonths, }: AppealInput) => AppealState;
70
+ export declare const toAppealState: ({ status, report, eligibilityReport, eligibility, latestAppealableAt, windowMonths, }: AppealInput) => AppealState;
54
71
  /**
55
72
  * Stable identity of a moderated subject, independent of which action touched
56
73
  * it. Two appeals against the same record - or the same message, or the same
@@ -135,24 +152,37 @@ export declare const resolveAppealAction: (ctx: AppContext, subject: ModSubject,
135
152
  */
136
153
  export declare const subjectLabelUri: (subject: ModSubject) => UriString;
137
154
  /**
138
- * Whether the subject has used up its appeals.
139
- *
140
- * Non-account subjects get one ever, closed or not. An account gets one at a
141
- * time, based on whether the latest appeal report is closed.
142
- *
143
- * The read path calls this to decide whether to offer `appeal`, and the write
144
- * path calls it to decide whether to accept one. They have to be the same
145
- * question: anything else advertises an appeal that submission will refuse.
155
+ * Whether the subject's appeal history blocks this action.
146
156
  */
147
- export declare const appealsExhausted: (subject: ModSubject, report: AppealReport | null) => boolean;
148
- export declare const findLatestAppealReport: (db: Database, subject: ModSubject) => Promise<AppealReport | null>;
157
+ export declare const eligibilityFromReport: (report: AppealReport | null) => AppealEligibility;
158
+ export declare const appealsExhausted: (eligibility: AppealEligibility, actionAt: DatetimeString | null) => boolean;
159
+ export declare const findAppealCandidates: (db: Database, subject: ModSubject) => Promise<{
160
+ activeId: number | null;
161
+ closedId: number | null;
162
+ closedAt: DatetimeString | null;
163
+ }>;
164
+ export declare const eligibilityFromCandidates: (candidates: {
165
+ activeId: number | null;
166
+ closedId: number | null;
167
+ closedAt: DatetimeString | null;
168
+ }) => AppealEligibility;
169
+ export declare const findAppealEligibility: (db: Database, subject: ModSubject) => Promise<AppealEligibility>;
170
+ export declare const findAppealHistory: (db: Database, subject: ModSubject) => Promise<{
171
+ eligibility: AppealEligibility;
172
+ report: AppealReport | null;
173
+ }>;
149
174
  /**
150
175
  * Reject an appeal the subject is no longer entitled to.
151
176
  *
152
177
  * Answers the same question as the `availableActions` the read path
153
178
  * advertises, through {@link appealsExhausted}, so the two cannot drift.
154
179
  */
155
- export declare const assertAppealAllowed: (dbTxn: Database, subject: ModSubject) => Promise<void>;
180
+ export declare const assertAppealAllowed: (dbTxn: Database, subject: ModSubject, options: {
181
+ actionAt?: DatetimeString;
182
+ unresolvedAction?: boolean;
183
+ startAt?: DatetimeString;
184
+ windowMonths: number;
185
+ }) => Promise<void>;
156
186
  export type FileAppealInput = {
157
187
  /** DID of the affected account, shown as the appeal reporter. */
158
188
  requester: DidString;
@@ -162,6 +192,7 @@ export type FileAppealInput = {
162
192
  subject: ModSubject;
163
193
  /** Resolved moderation event ID, when one could be found. */
164
194
  resolvedActionId?: number;
195
+ resolvedActionAt?: DatetimeString;
165
196
  /** The action reference supplied by the caller. */
166
197
  action?: tools.ozone.inbox.appealActionedSubject.$InputBody['action'];
167
198
  /** Optional: an appeal is a request for review, not an argued case. */
@@ -185,7 +216,7 @@ export type FileAppealInput = {
185
216
  * and the report row - shares one transaction. Everything that needs
186
217
  * not be, is already done by the time it opens.
187
218
  */
188
- export declare const fileAppeal: (ctx: AppContext, { requester, submittedBy, subject, resolvedActionId, action, reason, modTool, }: FileAppealInput) => Promise<{
219
+ export declare const fileAppeal: (ctx: AppContext, { requester, submittedBy, subject, resolvedActionId, resolvedActionAt, action, reason, modTool, }: FileAppealInput) => Promise<{
189
220
  reportId: number;
190
221
  }>;
191
222
  //# sourceMappingURL=appeal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"appeal.d.ts","sourceRoot":"","sources":["../../src/inbox/appeal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEpE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,SAAS,EAGf,MAAM,cAAc,CAAA;AAGrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAEzE,OAAO,EACL,KAAK,aAAa,EAInB,MAAM,qBAAqB,CAAA;AAE5B,eAAO,MAAM,kBAAkB,yCAAyC,CAA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AA;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,OAAO,CAAC,EAAE,cAAc,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;CACrB,kBA8CF,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,iEAAiE;IACjE,SAAS,EAAE,SAAS,CAAA;IACpB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,mEAAmE;IACnE,OAAO,EAAE,UAAU,CAAA;IACnB,6DAA6D;IAC7D,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,cAAc,CAAA;IACjC,mDAAmD;IACnD,MAAM,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IACrE,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE;aAAG,CAAC,IAAI,MAAM,GAAG,OAAO;SAAE,CAAA;KAAE,CAAA;CAC9D,CAAA;AA+HD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,QAChB,UAAU,qGAUZ,eAAe,KACjB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CA0C9B,CAAA"}
@@ -6,7 +6,7 @@ import { jsonb } from '../db/types.js';
6
6
  import { tools } from '../lexicons/index.js';
7
7
  import { findMatchingQueue, getQueueRoutingNote } from '../queue/service.js';
8
8
  import { appealActivityOutcome, appealReportSelection, appealResolutionFilter, } from './appeal-outcome.js';
9
- export const APPEAL_REASON_TYPE = 'tools.ozone.report.defs#reasonAppeal';
9
+ export const APPEAL_REASON_TYPE = tools.ozone.report.defs.ReasonAppeal;
10
10
  export const TAKEDOWN = 'tools.ozone.moderation.defs#modEventTakedown';
11
11
  export const REVERSE_TAKEDOWN = 'tools.ozone.moderation.defs#modEventReverseTakedown';
12
12
  export const LABEL = 'tools.ozone.moderation.defs#modEventLabel';
@@ -22,7 +22,17 @@ export const PUBLIC_EVENT_ACTIONS = [
22
22
  REVERSE_TAKEDOWN,
23
23
  ];
24
24
  export const APPEALABLE_EVENT_ACTIONS = [TAKEDOWN, LABEL];
25
- export const isAppealableEvent = (action) => APPEALABLE_EVENT_ACTIONS.includes(action);
25
+ export const isAppealableEvent = (event) => event.action === TAKEDOWN ||
26
+ (event.action === LABEL && !!event.createLabelVals?.trim());
27
+ export function hasKnownLatestAppealable(latest, events) {
28
+ return (!latest ||
29
+ events.some((event) => event.createdAt === latest && isAppealableEvent(event)));
30
+ }
31
+ // @NOTE Use the same predicate for history aggregates and submission checks.
32
+ export const appealableEventFilter = sql `(action = ${sql.lit(TAKEDOWN)} OR
33
+ (action = ${sql.lit(LABEL)} AND nullif(btrim("createLabelVals"), '') IS NOT NULL))`;
34
+ export const appealReportTypeFilter = sql `"reportType" = ${sql.lit(APPEAL_REASON_TYPE)}`;
35
+ export const appealReportOrder = sql `CASE WHEN status <> 'closed' THEN 0 ELSE 1 END`;
26
36
  export const appealWindowEnd = (actionCreatedAt, windowMonths) => {
27
37
  const end = new Date(actionCreatedAt);
28
38
  const day = end.getUTCDate();
@@ -36,7 +46,7 @@ export const isAppealWindowOpen = (actionCreatedAt, windowMonths, now = new Date
36
46
  /**
37
47
  * Appeal state, derived entirely from data Ozone already records.
38
48
  */
39
- export const toAppealState = ({ subject, status, report, eligibilityReport = report, latestAppealableAt, windowMonths, }) => {
49
+ export const toAppealState = ({ status, report, eligibilityReport = report, eligibility = eligibilityFromReport(eligibilityReport), latestAppealableAt, windowMonths, }) => {
40
50
  const appealableUntil = latestAppealableAt
41
51
  ? appealWindowEnd(latestAppealableAt, windowMonths)
42
52
  : null;
@@ -60,7 +70,7 @@ export const toAppealState = ({ subject, status, report, eligibilityReport = rep
60
70
  }
61
71
  if (appealableUntil)
62
72
  view.appealableUntil = appealableUntil;
63
- const availableActions = windowOpen && !appealsExhausted(subject, eligibilityReport)
73
+ const availableActions = windowOpen && !appealsExhausted(eligibility, latestAppealableAt)
64
74
  ? ['appeal']
65
75
  : [];
66
76
  return { view, availableActions };
@@ -151,12 +161,13 @@ export const findAppealedEvent = async (ctx, subject, action) => {
151
161
  if (action.type === 'label') {
152
162
  query = query.where(sql `${action.val} = ANY(string_to_array("createLabelVals", ' '))`);
153
163
  }
154
- const matches = await query
164
+ const match = await query
165
+ .orderBy('createdAt', 'desc')
155
166
  .orderBy('id', 'desc')
156
- .limit(2)
167
+ .limit(1)
157
168
  .selectAll()
158
- .execute();
159
- return matches.length === 1 ? matches[0] : undefined;
169
+ .executeTakeFirst();
170
+ return match;
160
171
  };
161
172
  export const resolveAppealAction = async (ctx, subject, action) => {
162
173
  if (!action)
@@ -179,28 +190,54 @@ export const resolveAppealAction = async (ctx, subject, action) => {
179
190
  */
180
191
  export const subjectLabelUri = (subject) => (subject.info().subjectUri ?? subject.did);
181
192
  /**
182
- * Whether the subject has used up its appeals.
183
- *
184
- * Non-account subjects get one ever, closed or not. An account gets one at a
185
- * time, based on whether the latest appeal report is closed.
186
- *
187
- * The read path calls this to decide whether to offer `appeal`, and the write
188
- * path calls it to decide whether to accept one. They have to be the same
189
- * question: anything else advertises an appeal that submission will refuse.
193
+ * Whether the subject's appeal history blocks this action.
190
194
  */
191
- export const appealsExhausted = (subject, report) => {
192
- if (!report)
193
- return false;
194
- return subject.isRepo() ? report.status !== 'closed' : true;
195
+ export const eligibilityFromReport = (report) => ({
196
+ hasActiveAppeal: !!report && report.status !== 'closed',
197
+ lastClosedAt: report?.status === 'closed' ? report.closedAt : null,
198
+ hasUnknownClosure: !!report && report.status === 'closed' && !report.closedAt,
199
+ });
200
+ export const appealsExhausted = (eligibility, actionAt) => eligibility.hasActiveAppeal ||
201
+ eligibility.hasUnknownClosure ||
202
+ (!!eligibility.lastClosedAt &&
203
+ (!actionAt || actionAt <= eligibility.lastClosedAt));
204
+ export const findAppealCandidates = async (db, subject) => {
205
+ const query = db.db
206
+ .selectFrom('report')
207
+ .where(appealReportTypeFilter)
208
+ .where((eb) => reportSubjectFilter(eb, subject));
209
+ const [active, closed] = await Promise.all([
210
+ query
211
+ .where(sql `status <> 'closed'`)
212
+ .select('id')
213
+ .orderBy('id', 'desc')
214
+ .limit(1)
215
+ .executeTakeFirst(),
216
+ query
217
+ .where(sql `status = 'closed'`)
218
+ .select(['id', 'closedAt'])
219
+ .orderBy(sql `"closedAt" DESC NULLS FIRST`)
220
+ .orderBy('id', 'desc')
221
+ .limit(1)
222
+ .executeTakeFirst(),
223
+ ]);
224
+ return {
225
+ activeId: active?.id ?? null,
226
+ closedId: closed?.id ?? null,
227
+ closedAt: closed?.closedAt ?? null,
228
+ };
195
229
  };
196
- export const findLatestAppealReport = async (db, subject) => {
230
+ export const eligibilityFromCandidates = (candidates) => ({
231
+ hasActiveAppeal: candidates.activeId !== null,
232
+ lastClosedAt: candidates.closedAt,
233
+ hasUnknownClosure: candidates.closedId !== null && candidates.closedAt === null,
234
+ });
235
+ export const findAppealEligibility = async (db, subject) => eligibilityFromCandidates(await findAppealCandidates(db, subject));
236
+ const findAppealReport = async (db, reportId) => {
197
237
  const report = await db.db
198
238
  .selectFrom(db.db
199
239
  .selectFrom('report')
200
- .where('reportType', '=', APPEAL_REASON_TYPE)
201
- .where((eb) => reportSubjectFilter(eb, subject))
202
- .orderBy('id', 'desc')
203
- .limit(1)
240
+ .where('id', '=', reportId)
204
241
  .select(appealReportSelection)
205
242
  .as('report'))
206
243
  .leftJoinLateral((eb) => eb
@@ -225,22 +262,55 @@ export const findLatestAppealReport = async (db, subject) => {
225
262
  .executeTakeFirst();
226
263
  return report ?? null;
227
264
  };
265
+ export const findAppealHistory = async (db, subject) => {
266
+ const candidates = await findAppealCandidates(db, subject);
267
+ const reportId = candidates.activeId ?? candidates.closedId;
268
+ return {
269
+ eligibility: eligibilityFromCandidates(candidates),
270
+ report: reportId === null ? null : await findAppealReport(db, reportId),
271
+ };
272
+ };
228
273
  /**
229
274
  * Reject an appeal the subject is no longer entitled to.
230
275
  *
231
276
  * Answers the same question as the `availableActions` the read path
232
277
  * advertises, through {@link appealsExhausted}, so the two cannot drift.
233
278
  */
234
- export const assertAppealAllowed = async (dbTxn, subject) => {
279
+ export const assertAppealAllowed = async (dbTxn, subject, options) => {
235
280
  dbTxn.assertTransaction();
236
281
  await sql `select pg_advisory_xact_lock(
237
282
  hashtextextended(${subjectKey(subject)}, 0)
238
283
  )`.execute(dbTxn.db);
239
- const existing = await findLatestAppealReport(dbTxn, subject);
240
- if (appealsExhausted(subject, existing)) {
241
- throw new ForbiddenError(subject.isRepo()
284
+ const eligibility = await findAppealEligibility(dbTxn, subject);
285
+ if (options.unresolvedAction &&
286
+ (eligibility.hasActiveAppeal ||
287
+ eligibility.hasUnknownClosure ||
288
+ eligibility.lastClosedAt)) {
289
+ throw new ForbiddenError('Moderation action not found', 'AlreadyAppealed');
290
+ }
291
+ let actionAt = options.actionAt ?? null;
292
+ if (!actionAt && eligibility.lastClosedAt && !eligibility.hasActiveAppeal) {
293
+ const latest = await dbTxn.db
294
+ .selectFrom('moderation_event')
295
+ .where((eb) => eventSubjectFilter(eb, subject))
296
+ .where('action', 'in', [...PUBLIC_EVENT_ACTIONS])
297
+ .where(appealableEventFilter)
298
+ .where('createdAt', '>', eligibility.lastClosedAt)
299
+ .$if(options.startAt !== undefined, (qb) => qb.where('createdAt', '>=', options.startAt))
300
+ .orderBy('createdAt', 'desc')
301
+ .orderBy('id', 'desc')
302
+ .select('createdAt')
303
+ .limit(1)
304
+ .executeTakeFirst();
305
+ actionAt = latest?.createdAt ?? null;
306
+ if (actionAt && !isAppealWindowOpen(actionAt, options.windowMonths)) {
307
+ actionAt = null;
308
+ }
309
+ }
310
+ if (appealsExhausted(eligibility, actionAt)) {
311
+ throw new ForbiddenError(eligibility.hasActiveAppeal
242
312
  ? 'Awaiting decision on previous appeal'
243
- : 'This has already been appealed', 'AlreadyAppealed');
313
+ : 'No new appealable action since the previous appeal', 'AlreadyAppealed');
244
314
  }
245
315
  };
246
316
  const buildAppealEventMeta = (action) => {
@@ -347,10 +417,15 @@ const selectQueue = async (ctx, subject, requester, resolvedActionId, action) =>
347
417
  * and the report row - shares one transaction. Everything that needs
348
418
  * not be, is already done by the time it opens.
349
419
  */
350
- export const fileAppeal = async (ctx, { requester, submittedBy, subject, resolvedActionId, action, reason, modTool, }) => {
420
+ export const fileAppeal = async (ctx, { requester, submittedBy, subject, resolvedActionId, resolvedActionAt, action, reason, modTool, }) => {
351
421
  const { queueId, queuedAt, routingNote } = await selectQueue(ctx, subject, requester, resolvedActionId, action);
352
422
  const reportId = await ctx.db.transaction(async (dbTxn) => {
353
- await assertAppealAllowed(dbTxn, subject);
423
+ await assertAppealAllowed(dbTxn, subject, {
424
+ actionAt: resolvedActionAt,
425
+ unresolvedAction: !!action && !resolvedActionAt,
426
+ startAt: ctx.cfg.inbox.startAt,
427
+ windowMonths: ctx.cfg.inbox.appealWindowMonths,
428
+ });
354
429
  // create event and report row
355
430
  const moderationTxn = ctx.modService(dbTxn);
356
431
  const { event: reportEvent } = await moderationTxn.report({