@atproto/ozone 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE.txt +1 -1
  3. package/dist/db/index.js +15 -1
  4. package/dist/db/index.js.map +3 -3
  5. package/dist/db/migrations/20240201T051104136Z-mod-event-blobs.d.ts +3 -0
  6. package/dist/db/migrations/index.d.ts +1 -0
  7. package/dist/db/schema/moderation_event.d.ts +1 -0
  8. package/dist/db/types.d.ts +1 -0
  9. package/dist/index.js +276 -202
  10. package/dist/index.js.map +3 -3
  11. package/dist/lexicon/index.d.ts +0 -2
  12. package/dist/lexicon/lexicons.d.ts +38 -47
  13. package/dist/lexicon/types/com/atproto/admin/defs.d.ts +2 -2
  14. package/dist/lexicon/types/com/atproto/admin/queryModerationEvents.d.ts +7 -0
  15. package/dist/mod-service/index.d.ts +13 -4
  16. package/dist/mod-service/subject.d.ts +3 -0
  17. package/dist/mod-service/types.d.ts +2 -0
  18. package/package.json +5 -5
  19. package/src/api/admin/emitModerationEvent.ts +9 -6
  20. package/src/api/admin/queryModerationEvents.ts +14 -0
  21. package/src/api/moderation/util.ts +1 -0
  22. package/src/api/temp/fetchLabels.ts +36 -21
  23. package/src/context.ts +1 -0
  24. package/src/daemon/context.ts +1 -0
  25. package/src/db/migrations/20240201T051104136Z-mod-event-blobs.ts +15 -0
  26. package/src/db/migrations/index.ts +1 -0
  27. package/src/db/schema/moderation_event.ts +1 -0
  28. package/src/db/types.ts +6 -1
  29. package/src/lexicon/index.ts +0 -12
  30. package/src/lexicon/lexicons.ts +43 -50
  31. package/src/lexicon/types/com/atproto/admin/defs.ts +2 -0
  32. package/src/lexicon/types/com/atproto/admin/queryModerationEvents.ts +13 -0
  33. package/src/mod-service/index.ts +142 -64
  34. package/src/mod-service/status.ts +3 -2
  35. package/src/mod-service/subject.ts +9 -2
  36. package/src/mod-service/types.ts +4 -0
  37. package/src/mod-service/views.ts +1 -1
  38. package/tests/__snapshots__/get-record.test.ts.snap +16 -0
  39. package/tests/__snapshots__/get-repo.test.ts.snap +9 -1
  40. package/tests/moderation-appeals.test.ts +1 -1
  41. package/tests/moderation-events.test.ts +161 -8
  42. package/tests/moderation-statuses.test.ts +55 -0
  43. package/tests/moderation.test.ts +133 -34
  44. package/dist/lexicon/types/app/bsky/unspecced/getTimelineSkeleton.d.ts +0 -35
  45. package/src/lexicon/types/app/bsky/unspecced/getTimelineSkeleton.ts +0 -49
package/dist/index.js CHANGED
@@ -27864,16 +27864,16 @@ var require_validate = __commonJS({
27864
27864
  const matches = RELATIVE_JSON_POINTER.exec($data);
27865
27865
  if (!matches)
27866
27866
  throw new Error(`Invalid JSON-pointer: ${$data}`);
27867
- const up3 = +matches[1];
27867
+ const up4 = +matches[1];
27868
27868
  jsonPointer = matches[2];
27869
27869
  if (jsonPointer === "#") {
27870
- if (up3 >= dataLevel)
27871
- throw new Error(errorMsg("property/index", up3));
27872
- return dataPathArr[dataLevel - up3];
27870
+ if (up4 >= dataLevel)
27871
+ throw new Error(errorMsg("property/index", up4));
27872
+ return dataPathArr[dataLevel - up4];
27873
27873
  }
27874
- if (up3 > dataLevel)
27875
- throw new Error(errorMsg("data", up3));
27876
- data = dataNames[dataLevel - up3];
27874
+ if (up4 > dataLevel)
27875
+ throw new Error(errorMsg("data", up4));
27876
+ data = dataNames[dataLevel - up4];
27877
27877
  if (!jsonPointer)
27878
27878
  return data;
27879
27879
  }
@@ -27886,8 +27886,8 @@ var require_validate = __commonJS({
27886
27886
  }
27887
27887
  }
27888
27888
  return expr;
27889
- function errorMsg(pointerType, up3) {
27890
- return `Cannot access ${pointerType} ${up3} levels up, current level is ${dataLevel}`;
27889
+ function errorMsg(pointerType, up4) {
27890
+ return `Cannot access ${pointerType} ${up4} levels up, current level is ${dataLevel}`;
27891
27891
  }
27892
27892
  }
27893
27893
  exports.getData = getData;
@@ -101683,7 +101683,8 @@ var schemaDict = {
101683
101683
  "lex:com.atproto.admin.defs#modEventAcknowledge",
101684
101684
  "lex:com.atproto.admin.defs#modEventEscalate",
101685
101685
  "lex:com.atproto.admin.defs#modEventMute",
101686
- "lex:com.atproto.admin.defs#modEventEmail"
101686
+ "lex:com.atproto.admin.defs#modEventEmail",
101687
+ "lex:com.atproto.admin.defs#modEventResolveAppeal"
101687
101688
  ]
101688
101689
  },
101689
101690
  subject: {
@@ -101740,6 +101741,7 @@ var schemaDict = {
101740
101741
  "lex:com.atproto.admin.defs#modEventAcknowledge",
101741
101742
  "lex:com.atproto.admin.defs#modEventEscalate",
101742
101743
  "lex:com.atproto.admin.defs#modEventMute",
101744
+ "lex:com.atproto.admin.defs#modEventEmail",
101743
101745
  "lex:com.atproto.admin.defs#modEventResolveAppeal"
101744
101746
  ]
101745
101747
  },
@@ -103029,6 +103031,16 @@ var schemaDict = {
103029
103031
  enum: ["asc", "desc"],
103030
103032
  description: "Sort direction for the events. Defaults to descending order of created at timestamp."
103031
103033
  },
103034
+ createdAfter: {
103035
+ type: "string",
103036
+ format: "datetime",
103037
+ description: "Retrieve events created after a given timestamp"
103038
+ },
103039
+ createdBefore: {
103040
+ type: "string",
103041
+ format: "datetime",
103042
+ description: "Retrieve events created before a given timestamp"
103043
+ },
103032
103044
  subject: {
103033
103045
  type: "string",
103034
103046
  format: "uri"
@@ -103044,6 +103056,34 @@ var schemaDict = {
103044
103056
  maximum: 100,
103045
103057
  default: 50
103046
103058
  },
103059
+ hasComment: {
103060
+ type: "boolean",
103061
+ description: "If true, only events with comments are returned"
103062
+ },
103063
+ comment: {
103064
+ type: "string",
103065
+ description: "If specified, only events with comments containing the keyword are returned"
103066
+ },
103067
+ addedLabels: {
103068
+ type: "array",
103069
+ items: {
103070
+ type: "string"
103071
+ },
103072
+ description: "If specified, only events where all of these labels were added are returned"
103073
+ },
103074
+ removedLabels: {
103075
+ type: "array",
103076
+ items: {
103077
+ type: "string"
103078
+ },
103079
+ description: "If specified, only events where all of these labels were removed are returned"
103080
+ },
103081
+ reportTypes: {
103082
+ type: "array",
103083
+ items: {
103084
+ type: "string"
103085
+ }
103086
+ },
103047
103087
  cursor: {
103048
103088
  type: "string"
103049
103089
  }
@@ -109608,54 +109648,6 @@ var schemaDict = {
109608
109648
  }
109609
109649
  }
109610
109650
  },
109611
- AppBskyUnspeccedGetTimelineSkeleton: {
109612
- lexicon: 1,
109613
- id: "app.bsky.unspecced.getTimelineSkeleton",
109614
- defs: {
109615
- main: {
109616
- type: "query",
109617
- description: "DEPRECATED: a skeleton of a timeline. Unspecced and will be unavailable soon.",
109618
- parameters: {
109619
- type: "params",
109620
- properties: {
109621
- limit: {
109622
- type: "integer",
109623
- minimum: 1,
109624
- maximum: 100,
109625
- default: 50
109626
- },
109627
- cursor: {
109628
- type: "string"
109629
- }
109630
- }
109631
- },
109632
- output: {
109633
- encoding: "application/json",
109634
- schema: {
109635
- type: "object",
109636
- required: ["feed"],
109637
- properties: {
109638
- cursor: {
109639
- type: "string"
109640
- },
109641
- feed: {
109642
- type: "array",
109643
- items: {
109644
- type: "ref",
109645
- ref: "lex:app.bsky.feed.defs#skeletonFeedPost"
109646
- }
109647
- }
109648
- }
109649
- }
109650
- },
109651
- errors: [
109652
- {
109653
- name: "UnknownFeed"
109654
- }
109655
- ]
109656
- }
109657
- }
109658
- },
109659
109651
  AppBskyUnspeccedSearchActorsSkeleton: {
109660
109652
  lexicon: 1,
109661
109653
  id: "app.bsky.unspecced.searchActorsSkeleton",
@@ -109855,7 +109847,8 @@ var eventTypes = /* @__PURE__ */ new Set([
109855
109847
  "com.atproto.admin.defs#modEventMute",
109856
109848
  "com.atproto.admin.defs#modEventUnmute",
109857
109849
  "com.atproto.admin.defs#modEventReverseTakedown",
109858
- "com.atproto.admin.defs#modEventEmail"
109850
+ "com.atproto.admin.defs#modEventEmail",
109851
+ "com.atproto.admin.defs#modEventResolveAppeal"
109859
109852
  ]);
109860
109853
 
109861
109854
  // src/mod-service/subject.ts
@@ -109873,7 +109866,7 @@ var subjectFromInput = (subject, blobs) => {
109873
109866
  };
109874
109867
  var subjectFromEventRow = (row) => {
109875
109868
  if (row.subjectType === "com.atproto.repo.strongRef" && row.subjectUri && row.subjectCid) {
109876
- return new RecordSubject(row.subjectUri, row.subjectCid);
109869
+ return new RecordSubject(row.subjectUri, row.subjectCid, row.subjectBlobCids ?? []);
109877
109870
  } else {
109878
109871
  return new RepoSubject(row.subjectDid);
109879
109872
  }
@@ -109881,7 +109874,7 @@ var subjectFromEventRow = (row) => {
109881
109874
  var subjectFromStatusRow = (row) => {
109882
109875
  if (row.recordPath && row.recordCid) {
109883
109876
  const uri2 = AtUri.make(row.did, ...row.recordPath.split("/")).toString();
109884
- return new RecordSubject(uri2.toString(), row.recordCid);
109877
+ return new RecordSubject(uri2.toString(), row.recordCid, row.blobCids ?? []);
109885
109878
  } else {
109886
109879
  return new RepoSubject(row.did);
109887
109880
  }
@@ -109903,7 +109896,8 @@ var RepoSubject = class {
109903
109896
  subjectType: "com.atproto.admin.defs#repoRef",
109904
109897
  subjectDid: this.did,
109905
109898
  subjectUri: null,
109906
- subjectCid: null
109899
+ subjectCid: null,
109900
+ subjectBlobCids: null
109907
109901
  };
109908
109902
  }
109909
109903
  lex() {
@@ -109933,7 +109927,8 @@ var RecordSubject = class {
109933
109927
  subjectType: "com.atproto.repo.strongRef",
109934
109928
  subjectDid: this.did,
109935
109929
  subjectUri: this.uri,
109936
- subjectCid: this.cid
109930
+ subjectCid: this.cid,
109931
+ subjectBlobCids: this.blobCids ?? []
109937
109932
  };
109938
109933
  }
109939
109934
  lex() {
@@ -110004,13 +109999,16 @@ function emitModerationEvent_default(server, ctx) {
110004
109999
  ]);
110005
110000
  }
110006
110001
  if (isTakedownEvent || isReverseTakedownEvent) {
110007
- const isSubjectTakendown = await moderationService.isSubjectTakendown(subject);
110008
- if (isSubjectTakendown && isTakedownEvent) {
110002
+ const status = await moderationService.getStatus(subject);
110003
+ if (status?.takendown && isTakedownEvent) {
110009
110004
  throw new InvalidRequestError(`Subject is already taken down`);
110010
110005
  }
110011
- if (!isSubjectTakendown && isReverseTakedownEvent) {
110006
+ if (!status?.takendown && isReverseTakedownEvent) {
110012
110007
  throw new InvalidRequestError(`Subject is not taken down`);
110013
110008
  }
110009
+ if (status?.takendown && isReverseTakedownEvent && subject.isRecord()) {
110010
+ subject.blobCids = status.blobCids ?? [];
110011
+ }
110014
110012
  }
110015
110013
  const moderationEvent = await db.transaction(async (dbTxn) => {
110016
110014
  const moderationTxn = ctx.modService(dbTxn);
@@ -110035,7 +110033,7 @@ function emitModerationEvent_default(server, ctx) {
110035
110033
  }
110036
110034
  }
110037
110035
  if (isLabelEvent) {
110038
- await moderationTxn.formatAndCreateLabels(ctx.cfg.service.did, result.subjectUri ?? result.subjectDid, result.subjectCid, {
110036
+ await moderationTxn.formatAndCreateLabels(result.subjectUri ?? result.subjectDid, result.subjectCid, {
110039
110037
  create: result.createLabelVals?.length ? result.createLabelVals.split(" ") : void 0,
110040
110038
  negate: result.negateLabelVals?.length ? result.negateLabelVals.split(" ") : void 0
110041
110039
  });
@@ -110241,7 +110239,14 @@ function queryModerationEvents_default(server, ctx) {
110241
110239
  sortDirection = "desc",
110242
110240
  types,
110243
110241
  includeAllUserRecords = false,
110244
- createdBy
110242
+ hasComment,
110243
+ comment,
110244
+ createdBy,
110245
+ createdAfter,
110246
+ createdBefore,
110247
+ addedLabels = [],
110248
+ removedLabels = [],
110249
+ reportTypes
110245
110250
  } = params2;
110246
110251
  const db = ctx.db;
110247
110252
  const modService = ctx.modService(db);
@@ -110252,7 +110257,14 @@ function queryModerationEvents_default(server, ctx) {
110252
110257
  limit,
110253
110258
  cursor,
110254
110259
  sortDirection,
110255
- includeAllUserRecords
110260
+ includeAllUserRecords,
110261
+ hasComment,
110262
+ comment,
110263
+ createdAfter,
110264
+ createdBefore,
110265
+ addedLabels,
110266
+ removedLabels,
110267
+ reportTypes
110256
110268
  });
110257
110269
  return {
110258
110270
  encoding: "application/json",
@@ -110283,22 +110295,33 @@ function getModerationEvent_default(server, ctx) {
110283
110295
  });
110284
110296
  }
110285
110297
 
110298
+ // src/mod-service/types.ts
110299
+ var UNSPECCED_TAKEDOWN_LABEL = "!unspecced-takedown";
110300
+ var UNSPECCED_TAKEDOWN_BLOBS_LABEL = "!unspecced-takedown-blobs";
110301
+
110286
110302
  // src/api/temp/fetchLabels.ts
110287
110303
  function fetchLabels_default(server, ctx) {
110288
- server.com.atproto.temp.fetchLabels(async ({ params: params2 }) => {
110289
- const { limit } = params2;
110290
- const since = params2.since !== void 0 ? new Date(params2.since).toISOString() : "";
110291
- const labelRes = await ctx.db.db.selectFrom("label").selectAll().orderBy("label.cts", "asc").where("cts", ">", since).limit(limit).execute();
110292
- const labels = labelRes.map((l) => ({
110293
- ...l,
110294
- cid: l.cid === "" ? void 0 : l.cid
110295
- }));
110296
- return {
110297
- encoding: "application/json",
110298
- body: {
110299
- labels
110300
- }
110301
- };
110304
+ server.com.atproto.temp.fetchLabels({
110305
+ auth: ctx.authOptionalAccessOrRoleVerifier,
110306
+ handler: async ({ auth, params: params2 }) => {
110307
+ const { limit } = params2;
110308
+ const since = params2.since !== void 0 ? new Date(params2.since).toISOString() : "";
110309
+ const includeUnspeccedTakedowns = auth.credentials.type === "role" && auth.credentials.admin;
110310
+ const labelRes = await ctx.db.db.selectFrom("label").selectAll().orderBy("label.cts", "asc").where("cts", ">", since).if(!includeUnspeccedTakedowns, (q) => q.where("label.val", "not in", [
110311
+ UNSPECCED_TAKEDOWN_LABEL,
110312
+ UNSPECCED_TAKEDOWN_BLOBS_LABEL
110313
+ ])).limit(limit).execute();
110314
+ const labels = labelRes.map((l) => ({
110315
+ ...l,
110316
+ cid: l.cid === "" ? void 0 : l.cid
110317
+ }));
110318
+ return {
110319
+ encoding: "application/json",
110320
+ body: {
110321
+ labels
110322
+ }
110323
+ };
110324
+ }
110302
110325
  });
110303
110326
  }
110304
110327
 
@@ -118631,10 +118654,6 @@ var AppBskyUnspeccedNS = class {
118631
118654
  const nsid2 = "app.bsky.unspecced.getTaggedSuggestions";
118632
118655
  return this._server.xrpc.method(nsid2, cfg);
118633
118656
  }
118634
- getTimelineSkeleton(cfg) {
118635
- const nsid2 = "app.bsky.unspecced.getTimelineSkeleton";
118636
- return this._server.xrpc.method(nsid2, cfg);
118637
- }
118638
118657
  searchActorsSkeleton(cfg) {
118639
118658
  const nsid2 = "app.bsky.unspecced.searchActorsSkeleton";
118640
118659
  return this._server.xrpc.method(nsid2, cfg);
@@ -119070,7 +119089,8 @@ var schemaDict2 = {
119070
119089
  "lex:com.atproto.admin.defs#modEventAcknowledge",
119071
119090
  "lex:com.atproto.admin.defs#modEventEscalate",
119072
119091
  "lex:com.atproto.admin.defs#modEventMute",
119073
- "lex:com.atproto.admin.defs#modEventEmail"
119092
+ "lex:com.atproto.admin.defs#modEventEmail",
119093
+ "lex:com.atproto.admin.defs#modEventResolveAppeal"
119074
119094
  ]
119075
119095
  },
119076
119096
  subject: {
@@ -119127,6 +119147,7 @@ var schemaDict2 = {
119127
119147
  "lex:com.atproto.admin.defs#modEventAcknowledge",
119128
119148
  "lex:com.atproto.admin.defs#modEventEscalate",
119129
119149
  "lex:com.atproto.admin.defs#modEventMute",
119150
+ "lex:com.atproto.admin.defs#modEventEmail",
119130
119151
  "lex:com.atproto.admin.defs#modEventResolveAppeal"
119131
119152
  ]
119132
119153
  },
@@ -120416,6 +120437,16 @@ var schemaDict2 = {
120416
120437
  enum: ["asc", "desc"],
120417
120438
  description: "Sort direction for the events. Defaults to descending order of created at timestamp."
120418
120439
  },
120440
+ createdAfter: {
120441
+ type: "string",
120442
+ format: "datetime",
120443
+ description: "Retrieve events created after a given timestamp"
120444
+ },
120445
+ createdBefore: {
120446
+ type: "string",
120447
+ format: "datetime",
120448
+ description: "Retrieve events created before a given timestamp"
120449
+ },
120419
120450
  subject: {
120420
120451
  type: "string",
120421
120452
  format: "uri"
@@ -120431,6 +120462,34 @@ var schemaDict2 = {
120431
120462
  maximum: 100,
120432
120463
  default: 50
120433
120464
  },
120465
+ hasComment: {
120466
+ type: "boolean",
120467
+ description: "If true, only events with comments are returned"
120468
+ },
120469
+ comment: {
120470
+ type: "string",
120471
+ description: "If specified, only events with comments containing the keyword are returned"
120472
+ },
120473
+ addedLabels: {
120474
+ type: "array",
120475
+ items: {
120476
+ type: "string"
120477
+ },
120478
+ description: "If specified, only events where all of these labels were added are returned"
120479
+ },
120480
+ removedLabels: {
120481
+ type: "array",
120482
+ items: {
120483
+ type: "string"
120484
+ },
120485
+ description: "If specified, only events where all of these labels were removed are returned"
120486
+ },
120487
+ reportTypes: {
120488
+ type: "array",
120489
+ items: {
120490
+ type: "string"
120491
+ }
120492
+ },
120434
120493
  cursor: {
120435
120494
  type: "string"
120436
120495
  }
@@ -126995,54 +127054,6 @@ var schemaDict2 = {
126995
127054
  }
126996
127055
  }
126997
127056
  },
126998
- AppBskyUnspeccedGetTimelineSkeleton: {
126999
- lexicon: 1,
127000
- id: "app.bsky.unspecced.getTimelineSkeleton",
127001
- defs: {
127002
- main: {
127003
- type: "query",
127004
- description: "DEPRECATED: a skeleton of a timeline. Unspecced and will be unavailable soon.",
127005
- parameters: {
127006
- type: "params",
127007
- properties: {
127008
- limit: {
127009
- type: "integer",
127010
- minimum: 1,
127011
- maximum: 100,
127012
- default: 50
127013
- },
127014
- cursor: {
127015
- type: "string"
127016
- }
127017
- }
127018
- },
127019
- output: {
127020
- encoding: "application/json",
127021
- schema: {
127022
- type: "object",
127023
- required: ["feed"],
127024
- properties: {
127025
- cursor: {
127026
- type: "string"
127027
- },
127028
- feed: {
127029
- type: "array",
127030
- items: {
127031
- type: "ref",
127032
- ref: "lex:app.bsky.feed.defs#skeletonFeedPost"
127033
- }
127034
- }
127035
- }
127036
- }
127037
- },
127038
- errors: [
127039
- {
127040
- name: "UnknownFeed"
127041
- }
127042
- ]
127043
- }
127044
- }
127045
- },
127046
127057
  AppBskyUnspeccedSearchActorsSkeleton: {
127047
127058
  lexicon: 1,
127048
127059
  id: "app.bsky.unspecced.searchActorsSkeleton",
@@ -128322,27 +128333,13 @@ function toKnownErr116(e) {
128322
128333
  return e;
128323
128334
  }
128324
128335
 
128325
- // ../api/src/client/types/app/bsky/unspecced/getTimelineSkeleton.ts
128326
- var UnknownFeedError3 = class extends XRPCError {
128327
- constructor(src3) {
128328
- super(src3.status, src3.error, src3.message, src3.headers);
128329
- }
128330
- };
128331
- function toKnownErr117(e) {
128332
- if (e instanceof XRPCError) {
128333
- if (e.error === "UnknownFeed")
128334
- return new UnknownFeedError3(e);
128335
- }
128336
- return e;
128337
- }
128338
-
128339
128336
  // ../api/src/client/types/app/bsky/unspecced/searchActorsSkeleton.ts
128340
128337
  var BadQueryStringError2 = class extends XRPCError {
128341
128338
  constructor(src3) {
128342
128339
  super(src3.status, src3.error, src3.message, src3.headers);
128343
128340
  }
128344
128341
  };
128345
- function toKnownErr118(e) {
128342
+ function toKnownErr117(e) {
128346
128343
  if (e instanceof XRPCError) {
128347
128344
  if (e.error === "BadQueryString")
128348
128345
  return new BadQueryStringError2(e);
@@ -128356,7 +128353,7 @@ var BadQueryStringError3 = class extends XRPCError {
128356
128353
  super(src3.status, src3.error, src3.message, src3.headers);
128357
128354
  }
128358
128355
  };
128359
- function toKnownErr119(e) {
128356
+ function toKnownErr118(e) {
128360
128357
  if (e instanceof XRPCError) {
128361
128358
  if (e.error === "BadQueryString")
128362
128359
  return new BadQueryStringError3(e);
@@ -129384,19 +129381,14 @@ var AppBskyUnspeccedNS2 = class {
129384
129381
  throw toKnownErr116(e);
129385
129382
  });
129386
129383
  }
129387
- getTimelineSkeleton(params2, opts) {
129388
- return this._service.xrpc.call("app.bsky.unspecced.getTimelineSkeleton", params2, void 0, opts).catch((e) => {
129389
- throw toKnownErr117(e);
129390
- });
129391
- }
129392
129384
  searchActorsSkeleton(params2, opts) {
129393
129385
  return this._service.xrpc.call("app.bsky.unspecced.searchActorsSkeleton", params2, void 0, opts).catch((e) => {
129394
- throw toKnownErr118(e);
129386
+ throw toKnownErr117(e);
129395
129387
  });
129396
129388
  }
129397
129389
  searchPostsSkeleton(params2, opts) {
129398
129390
  return this._service.xrpc.call("app.bsky.unspecced.searchPostsSkeleton", params2, void 0, opts).catch((e) => {
129399
- throw toKnownErr119(e);
129391
+ throw toKnownErr118(e);
129400
129392
  });
129401
129393
  }
129402
129394
  };
@@ -130541,7 +130533,8 @@ var import_stream8 = require("stream");
130541
130533
  var migrations_exports = {};
130542
130534
  __export(migrations_exports, {
130543
130535
  _20231219T205730722Z: () => T205730722Z_init_exports,
130544
- _20240116T085607200Z: () => T085607200Z_communication_template_exports
130536
+ _20240116T085607200Z: () => T085607200Z_communication_template_exports,
130537
+ _20240201T051104136Z: () => T051104136Z_mod_event_blobs_exports
130545
130538
  });
130546
130539
 
130547
130540
  // src/db/migrations/20231219T205730722Z-init.ts
@@ -130599,6 +130592,19 @@ async function down2(db) {
130599
130592
  await db.schema.dropTable("communication_template");
130600
130593
  }
130601
130594
 
130595
+ // src/db/migrations/20240201T051104136Z-mod-event-blobs.ts
130596
+ var T051104136Z_mod_event_blobs_exports = {};
130597
+ __export(T051104136Z_mod_event_blobs_exports, {
130598
+ down: () => down3,
130599
+ up: () => up3
130600
+ });
130601
+ async function up3(db) {
130602
+ await db.schema.alterTable("moderation_event").addColumn("subjectBlobCids", "jsonb").execute();
130603
+ }
130604
+ async function down3(db) {
130605
+ await db.schema.alterTable("moderation_event").dropColumn("subjectBlobCids").execute();
130606
+ }
130607
+
130602
130608
  // src/db/migrations/provider.ts
130603
130609
  var CtxMigrationProvider = class {
130604
130610
  constructor(migrations, ctx) {
@@ -130799,7 +130805,7 @@ var ModerationViews = class {
130799
130805
  comment: event.comment ?? void 0
130800
130806
  },
130801
130807
  subject: subjectFromEventRow(event).lex(),
130802
- subjectBlobCids: [],
130808
+ subjectBlobCids: event.subjectBlobCids ?? [],
130803
130809
  createdBy: event.createdBy,
130804
130810
  createdAt: event.createdAt,
130805
130811
  subjectHandle: event.subjectHandle ?? void 0,
@@ -131126,6 +131132,13 @@ function getSelfLabels(details) {
131126
131132
  });
131127
131133
  }
131128
131134
 
131135
+ // src/db/types.ts
131136
+ var jsonb = (val) => {
131137
+ if (val === null)
131138
+ return sql`null`;
131139
+ return sql`${JSON.stringify(val)}::jsonb`;
131140
+ };
131141
+
131129
131142
  // src/mod-service/status.ts
131130
131143
  var getSubjectStatusForModerationEvent = ({
131131
131144
  action,
@@ -131250,7 +131263,7 @@ var adjustModerationSubjectStatus = async (db, moderationEvent, blobCids) => {
131250
131263
  subjectStatus.comment = comment;
131251
131264
  }
131252
131265
  if (blobCids?.length) {
131253
- const newBlobCids = sql`${JSON.stringify(blobCids)}`;
131266
+ const newBlobCids = jsonb(blobCids);
131254
131267
  newStatus.blobCids = newBlobCids;
131255
131268
  subjectStatus.blobCids = newBlobCids;
131256
131269
  }
@@ -131423,16 +131436,17 @@ var paginate = (qb, opts) => {
131423
131436
 
131424
131437
  // src/mod-service/index.ts
131425
131438
  var ModerationService = class {
131426
- constructor(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth) {
131439
+ constructor(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid) {
131427
131440
  this.db = db;
131428
131441
  this.backgroundQueue = backgroundQueue;
131429
131442
  this.eventPusher = eventPusher;
131430
131443
  this.appviewAgent = appviewAgent;
131431
131444
  this.appviewAuth = appviewAuth;
131445
+ this.serverDid = serverDid;
131432
131446
  this.views = new ModerationViews(this.db, this.appviewAgent, this.appviewAuth);
131433
131447
  }
131434
- static creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth) {
131435
- return (db) => new ModerationService(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth);
131448
+ static creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid) {
131449
+ return (db) => new ModerationService(db, backgroundQueue, eventPusher, appviewAgent, appviewAuth, serverDid);
131436
131450
  }
131437
131451
  async getEvent(id) {
131438
131452
  return await this.db.db.selectFrom("moderation_event").selectAll().where("id", "=", id).executeTakeFirst();
@@ -131451,7 +131465,14 @@ var ModerationService = class {
131451
131465
  cursor,
131452
131466
  includeAllUserRecords,
131453
131467
  sortDirection = "desc",
131454
- types
131468
+ types,
131469
+ hasComment,
131470
+ comment,
131471
+ createdAfter,
131472
+ createdBefore,
131473
+ addedLabels,
131474
+ removedLabels,
131475
+ reportTypes
131455
131476
  } = opts;
131456
131477
  let builder = this.db.db.selectFrom("moderation_event").selectAll();
131457
131478
  if (subject) {
@@ -131477,6 +131498,31 @@ var ModerationService = class {
131477
131498
  if (createdBy) {
131478
131499
  builder = builder.where("createdBy", "=", createdBy);
131479
131500
  }
131501
+ if (createdAfter) {
131502
+ builder = builder.where("createdAt", ">=", createdAfter);
131503
+ }
131504
+ if (createdBefore) {
131505
+ builder = builder.where("createdAt", "<=", createdBefore);
131506
+ }
131507
+ if (comment) {
131508
+ builder = builder.where("comment", "ilike", `%${comment}%`);
131509
+ }
131510
+ if (hasComment) {
131511
+ builder = builder.where("comment", "is not", null);
131512
+ }
131513
+ if (addedLabels.length) {
131514
+ addedLabels.forEach((label) => {
131515
+ builder = builder.where("createLabelVals", "ilike", `%${label}%`);
131516
+ });
131517
+ }
131518
+ if (removedLabels.length) {
131519
+ removedLabels.forEach((label) => {
131520
+ builder = builder.where("negateLabelVals", "ilike", `%${label}%`);
131521
+ });
131522
+ }
131523
+ if (reportTypes?.length) {
131524
+ builder = builder.where(sql`meta->>'reportType'`, "in", reportTypes);
131525
+ }
131480
131526
  const { ref } = this.db.db.dynamic;
131481
131527
  const keyset = new TimeIdKeyset(ref(`moderation_event.createdAt`), ref("moderation_event.id"));
131482
131528
  const paginatedBuilder = paginate(builder, {
@@ -131525,6 +131571,7 @@ var ModerationService = class {
131525
131571
  if (isModEventEmail(event)) {
131526
131572
  meta.subjectLine = event.subjectLine;
131527
131573
  }
131574
+ const subjectInfo = subject.info();
131528
131575
  const modEvent = await this.db.db.insertInto("moderation_event").values({
131529
131576
  comment: event.comment ? `${event.comment}` : null,
131530
131577
  action: event.$type,
@@ -131535,7 +131582,11 @@ var ModerationService = class {
131535
131582
  durationInHours: event.durationInHours ? Number(event.durationInHours) : null,
131536
131583
  meta,
131537
131584
  expiresAt: (isModEventTakedown(event) || isModEventMute(event)) && event.durationInHours ? addHoursToDate(event.durationInHours, createdAt).toISOString() : void 0,
131538
- ...subject.info()
131585
+ subjectType: subjectInfo.subjectType,
131586
+ subjectDid: subjectInfo.subjectDid,
131587
+ subjectUri: subjectInfo.subjectUri,
131588
+ subjectCid: subjectInfo.subjectCid,
131589
+ subjectBlobCids: jsonb(subjectInfo.subjectBlobCids)
131539
131590
  }).returningAll().executeTakeFirstOrThrow();
131540
131591
  await adjustModerationSubjectStatus(this.db, modEvent, subject.blobCids);
131541
131592
  return modEvent;
@@ -131603,12 +131654,17 @@ var ModerationService = class {
131603
131654
  subjectDid: subject.did,
131604
131655
  takedownRef
131605
131656
  }));
131606
- const repoEvts = await this.db.db.insertInto("repo_push_event").values(values).onConflict((oc) => oc.columns(["subjectDid", "eventType"]).doUpdateSet({
131607
- takedownRef,
131608
- confirmedAt: null,
131609
- attempts: 0,
131610
- lastAttempted: null
131611
- })).returning("id").execute();
131657
+ const [repoEvts] = await Promise.all([
131658
+ this.db.db.insertInto("repo_push_event").values(values).onConflict((oc) => oc.columns(["subjectDid", "eventType"]).doUpdateSet({
131659
+ takedownRef,
131660
+ confirmedAt: null,
131661
+ attempts: 0,
131662
+ lastAttempted: null
131663
+ })).returning("id").execute(),
131664
+ this.formatAndCreateLabels(subject.did, null, {
131665
+ create: [UNSPECCED_TAKEDOWN_LABEL]
131666
+ })
131667
+ ]);
131612
131668
  this.db.onCommit(() => {
131613
131669
  this.backgroundQueue.add(async () => {
131614
131670
  await Promise.all(repoEvts.map((evt) => this.eventPusher.attemptRepoEvent(evt.id)));
@@ -131616,12 +131672,17 @@ var ModerationService = class {
131616
131672
  });
131617
131673
  }
131618
131674
  async reverseTakedownRepo(subject) {
131619
- const repoEvts = await this.db.db.updateTable("repo_push_event").where("eventType", "in", TAKEDOWNS).where("subjectDid", "=", subject.did).set({
131620
- takedownRef: null,
131621
- confirmedAt: null,
131622
- attempts: 0,
131623
- lastAttempted: null
131624
- }).returning("id").execute();
131675
+ const [repoEvts] = await Promise.all([
131676
+ this.db.db.updateTable("repo_push_event").where("eventType", "in", TAKEDOWNS).where("subjectDid", "=", subject.did).set({
131677
+ takedownRef: null,
131678
+ confirmedAt: null,
131679
+ attempts: 0,
131680
+ lastAttempted: null
131681
+ }).returning("id").execute(),
131682
+ this.formatAndCreateLabels(subject.did, null, {
131683
+ negate: [UNSPECCED_TAKEDOWN_LABEL]
131684
+ })
131685
+ ]);
131625
131686
  this.db.onCommit(() => {
131626
131687
  this.backgroundQueue.add(async () => {
131627
131688
  await Promise.all(repoEvts.map((evt) => this.eventPusher.attemptRepoEvent(evt.id)));
@@ -131638,18 +131699,25 @@ var ModerationService = class {
131638
131699
  subjectCid: subject.cid,
131639
131700
  takedownRef
131640
131701
  }));
131641
- const recordEvts = await this.db.db.insertInto("record_push_event").values(values).onConflict((oc) => oc.columns(["subjectUri", "eventType"]).doUpdateSet({
131642
- takedownRef,
131643
- confirmedAt: null,
131644
- attempts: 0,
131645
- lastAttempted: null
131646
- })).returning("id").execute();
131702
+ const blobCids = subject.blobCids;
131703
+ const labels = [UNSPECCED_TAKEDOWN_LABEL];
131704
+ if (blobCids && blobCids.length > 0) {
131705
+ labels.push(UNSPECCED_TAKEDOWN_BLOBS_LABEL);
131706
+ }
131707
+ const [recordEvts] = await Promise.all([
131708
+ this.db.db.insertInto("record_push_event").values(values).onConflict((oc) => oc.columns(["subjectUri", "eventType"]).doUpdateSet({
131709
+ takedownRef,
131710
+ confirmedAt: null,
131711
+ attempts: 0,
131712
+ lastAttempted: null
131713
+ })).returning("id").execute(),
131714
+ this.formatAndCreateLabels(subject.uri, subject.cid, { create: labels })
131715
+ ]);
131647
131716
  this.db.onCommit(() => {
131648
131717
  this.backgroundQueue.add(async () => {
131649
131718
  await Promise.all(recordEvts.map((evt) => this.eventPusher.attemptRecordEvent(evt.id)));
131650
131719
  });
131651
131720
  });
131652
- const blobCids = subject.blobCids;
131653
131721
  if (blobCids && blobCids.length > 0) {
131654
131722
  const blobValues = [];
131655
131723
  for (const eventType of TAKEDOWNS) {
@@ -131677,18 +131745,25 @@ var ModerationService = class {
131677
131745
  }
131678
131746
  async reverseTakedownRecord(subject) {
131679
131747
  this.db.assertTransaction();
131680
- const recordEvts = await this.db.db.updateTable("record_push_event").where("eventType", "in", TAKEDOWNS).where("subjectDid", "=", subject.did).where("subjectUri", "=", subject.uri).set({
131681
- takedownRef: null,
131682
- confirmedAt: null,
131683
- attempts: 0,
131684
- lastAttempted: null
131685
- }).returning("id").execute();
131748
+ const labels = [UNSPECCED_TAKEDOWN_LABEL];
131749
+ const blobCids = subject.blobCids;
131750
+ if (blobCids && blobCids.length > 0) {
131751
+ labels.push(UNSPECCED_TAKEDOWN_BLOBS_LABEL);
131752
+ }
131753
+ const [recordEvts] = await Promise.all([
131754
+ this.db.db.updateTable("record_push_event").where("eventType", "in", TAKEDOWNS).where("subjectDid", "=", subject.did).where("subjectUri", "=", subject.uri).set({
131755
+ takedownRef: null,
131756
+ confirmedAt: null,
131757
+ attempts: 0,
131758
+ lastAttempted: null
131759
+ }).returning("id").execute(),
131760
+ this.formatAndCreateLabels(subject.uri, subject.cid, { negate: labels })
131761
+ ]);
131686
131762
  this.db.onCommit(() => {
131687
131763
  this.backgroundQueue.add(async () => {
131688
131764
  await Promise.all(recordEvts.map((evt) => this.eventPusher.attemptRecordEvent(evt.id)));
131689
131765
  });
131690
131766
  });
131691
- const blobCids = subject.blobCids;
131692
131767
  if (blobCids && blobCids.length > 0) {
131693
131768
  const blobEvts = await this.db.db.updateTable("blob_push_event").where("eventType", "in", TAKEDOWNS).where("subjectDid", "=", subject.did).where("subjectBlobCid", "in", blobCids.map((c) => c.toString())).set({
131694
131769
  takedownRef: null,
@@ -131796,15 +131871,14 @@ var ModerationService = class {
131796
131871
  cursor: keyset.packFromResult(results)
131797
131872
  };
131798
131873
  }
131799
- async isSubjectTakendown(subject) {
131800
- const builder = this.db.db.selectFrom("moderation_subject_status").where("did", "=", subject.did).where("recordPath", "=", subject.recordPath || "");
131801
- const result = await builder.select("takendown").executeTakeFirst();
131802
- return !!result?.takendown;
131874
+ async getStatus(subject) {
131875
+ const result = await this.db.db.selectFrom("moderation_subject_status").where("did", "=", subject.did).where("recordPath", "=", subject.recordPath ?? "").selectAll().executeTakeFirst();
131876
+ return result ?? null;
131803
131877
  }
131804
- async formatAndCreateLabels(src3, uri2, cid2, labels) {
131878
+ async formatAndCreateLabels(uri2, cid2, labels) {
131805
131879
  const { create: create2 = [], negate = [] } = labels;
131806
131880
  const toCreate = create2.map((val) => ({
131807
- src: src3,
131881
+ src: this.serverDid,
131808
131882
  uri: uri2,
131809
131883
  cid: cid2 ?? void 0,
131810
131884
  val,
@@ -131812,7 +131886,7 @@ var ModerationService = class {
131812
131886
  cts: new Date().toISOString()
131813
131887
  }));
131814
131888
  const toNegate = negate.map((val) => ({
131815
- src: src3,
131889
+ src: this.serverDid,
131816
131890
  uri: uri2,
131817
131891
  cid: cid2 ?? void 0,
131818
131892
  val,
@@ -132232,7 +132306,7 @@ var DaemonContext = class {
132232
132306
  pds: cfg.pds ?? void 0
132233
132307
  });
132234
132308
  const backgroundQueue = new BackgroundQueue(db);
132235
- const modService = ModerationService.creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth);
132309
+ const modService = ModerationService.creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth, cfg.service.did);
132236
132310
  const eventReverser = new EventReverser(db, modService);
132237
132311
  return new DaemonContext({
132238
132312
  db,
@@ -132377,7 +132451,7 @@ var AppContext = class {
132377
132451
  appview: cfg.appview,
132378
132452
  pds: cfg.pds ?? void 0
132379
132453
  });
132380
- const modService = ModerationService.creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth);
132454
+ const modService = ModerationService.creator(backgroundQueue, eventPusher, appviewAgent, appviewAuth, cfg.service.did);
132381
132455
  const communicationTemplateService = CommunicationTemplateService.creator();
132382
132456
  const idResolver = new IdResolver({
132383
132457
  plcUrl: cfg.identity.plcUrl