@atproto/bsky 0.0.7 → 0.0.9

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.
@@ -0,0 +1,3 @@
1
+ import { Kysely } from 'kysely';
2
+ export declare function up(db: Kysely<unknown>): Promise<void>;
3
+ export declare function down(db: Kysely<unknown>): Promise<void>;
@@ -24,3 +24,4 @@ export * as _20230817T195936007Z from './20230817T195936007Z-native-notification
24
24
  export * as _20230830T205507322Z from './20230830T205507322Z-suggested-feeds';
25
25
  export * as _20230904T211011773Z from './20230904T211011773Z-block-lists';
26
26
  export * as _20230906T222220386Z from './20230906T222220386Z-thread-gating';
27
+ export * as _20230920T213858047Z from './20230920T213858047Z-add-tags-to-post';
@@ -10,6 +10,7 @@ export interface Post {
10
10
  replyParent: string | null;
11
11
  replyParentCid: string | null;
12
12
  langs: string[] | null;
13
+ tags: string[] | null;
13
14
  invalidReplyRoot: boolean | null;
14
15
  violatesThreadGate: boolean | null;
15
16
  createdAt: string;
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 up27 = +matches[1];
27867
+ const up28 = +matches[1];
27868
27868
  jsonPointer = matches[2];
27869
27869
  if (jsonPointer === "#") {
27870
- if (up27 >= dataLevel)
27871
- throw new Error(errorMsg("property/index", up27));
27872
- return dataPathArr[dataLevel - up27];
27870
+ if (up28 >= dataLevel)
27871
+ throw new Error(errorMsg("property/index", up28));
27872
+ return dataPathArr[dataLevel - up28];
27873
27873
  }
27874
- if (up27 > dataLevel)
27875
- throw new Error(errorMsg("data", up27));
27876
- data = dataNames[dataLevel - up27];
27874
+ if (up28 > dataLevel)
27875
+ throw new Error(errorMsg("data", up28));
27876
+ data = dataNames[dataLevel - up28];
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, up27) {
27890
- return `Cannot access ${pointerType} ${up27} levels up, current level is ${dataLevel}`;
27889
+ function errorMsg(pointerType, up28) {
27890
+ return `Cannot access ${pointerType} ${up28} levels up, current level is ${dataLevel}`;
27891
27891
  }
27892
27892
  }
27893
27893
  exports.getData = getData;
@@ -124352,6 +124352,16 @@ var schemaDict = {
124352
124352
  type: "union",
124353
124353
  refs: ["lex:com.atproto.label.defs#selfLabels"]
124354
124354
  },
124355
+ tags: {
124356
+ type: "array",
124357
+ maxLength: 8,
124358
+ items: {
124359
+ type: "string",
124360
+ maxLength: 640,
124361
+ maxGraphemes: 64
124362
+ },
124363
+ description: "Additional non-inline tags describing this post."
124364
+ },
124355
124365
  createdAt: {
124356
124366
  type: "string",
124357
124367
  format: "datetime"
@@ -125485,7 +125495,8 @@ var schemaDict = {
125485
125495
  type: "union",
125486
125496
  refs: [
125487
125497
  "lex:app.bsky.richtext.facet#mention",
125488
- "lex:app.bsky.richtext.facet#link"
125498
+ "lex:app.bsky.richtext.facet#link",
125499
+ "lex:app.bsky.richtext.facet#tag"
125489
125500
  ]
125490
125501
  }
125491
125502
  }
@@ -125513,6 +125524,18 @@ var schemaDict = {
125513
125524
  }
125514
125525
  }
125515
125526
  },
125527
+ tag: {
125528
+ type: "object",
125529
+ description: "A hashtag.",
125530
+ required: ["tag"],
125531
+ properties: {
125532
+ tag: {
125533
+ type: "string",
125534
+ maxLength: 640,
125535
+ maxGraphemes: 64
125536
+ }
125537
+ }
125538
+ },
125516
125539
  byteSlice: {
125517
125540
  type: "object",
125518
125541
  description: "A text segment. Start is inclusive, end is exclusive. Indices are for utf8-encoded strings.",
@@ -134634,6 +134657,16 @@ var schemaDict2 = {
134634
134657
  type: "union",
134635
134658
  refs: ["lex:com.atproto.label.defs#selfLabels"]
134636
134659
  },
134660
+ tags: {
134661
+ type: "array",
134662
+ maxLength: 8,
134663
+ items: {
134664
+ type: "string",
134665
+ maxLength: 640,
134666
+ maxGraphemes: 64
134667
+ },
134668
+ description: "Additional non-inline tags describing this post."
134669
+ },
134637
134670
  createdAt: {
134638
134671
  type: "string",
134639
134672
  format: "datetime"
@@ -135767,7 +135800,8 @@ var schemaDict2 = {
135767
135800
  type: "union",
135768
135801
  refs: [
135769
135802
  "lex:app.bsky.richtext.facet#mention",
135770
- "lex:app.bsky.richtext.facet#link"
135803
+ "lex:app.bsky.richtext.facet#link",
135804
+ "lex:app.bsky.richtext.facet#tag"
135771
135805
  ]
135772
135806
  }
135773
135807
  }
@@ -135795,6 +135829,18 @@ var schemaDict2 = {
135795
135829
  }
135796
135830
  }
135797
135831
  },
135832
+ tag: {
135833
+ type: "object",
135834
+ description: "A hashtag.",
135835
+ required: ["tag"],
135836
+ properties: {
135837
+ tag: {
135838
+ type: "string",
135839
+ maxLength: 640,
135840
+ maxGraphemes: 64
135841
+ }
135842
+ }
135843
+ },
135798
135844
  byteSlice: {
135799
135845
  type: "object",
135800
135846
  description: "A text segment. Start is inclusive, end is exclusive. Indices are for utf8-encoded strings.",
@@ -141484,8 +141530,8 @@ var ActorViews = class {
141484
141530
  mutedByList,
141485
141531
  blockedBy: !!bam.blockedBy([viewer, did2]),
141486
141532
  blocking: bam.blocking([viewer, did2]) ?? void 0,
141487
- following: prof?.viewerFollowing || void 0,
141488
- followedBy: prof?.viewerFollowedBy || void 0
141533
+ following: prof?.viewerFollowing && !bam.block([viewer, did2]) ? prof.viewerFollowing : void 0,
141534
+ followedBy: prof?.viewerFollowedBy && !bam.block([viewer, did2]) ? prof.viewerFollowedBy : void 0
141489
141535
  } : void 0,
141490
141536
  labels: [...actorLabels, ...selfLabels]
141491
141537
  };
@@ -141550,8 +141596,8 @@ var ActorViews = class {
141550
141596
  mutedByList,
141551
141597
  blockedBy: !!bam.blockedBy([viewer, did2]),
141552
141598
  blocking: bam.blocking([viewer, did2]) ?? void 0,
141553
- following: prof?.viewerFollowing || void 0,
141554
- followedBy: prof?.viewerFollowedBy || void 0
141599
+ following: prof?.viewerFollowing && !bam.block([viewer, did2]) ? prof.viewerFollowing : void 0,
141600
+ followedBy: prof?.viewerFollowedBy && !bam.block([viewer, did2]) ? prof.viewerFollowedBy : void 0
141555
141601
  } : void 0,
141556
141602
  labels: [...actorLabels, ...selfLabels]
141557
141603
  };
@@ -141987,6 +142033,7 @@ var FeedService = class {
141987
142033
  "post_agg.likeCount as likeCount",
141988
142034
  "post_agg.repostCount as repostCount",
141989
142035
  "post_agg.replyCount as replyCount",
142036
+ "post.tags as tags",
141990
142037
  db.selectFrom("repost").if(!viewer, (q) => q.where(noMatch)).where("creator", "=", viewer ?? "").whereRef("subject", "=", ref("post.uri")).select("uri").as("requesterRepost"),
141991
142038
  db.selectFrom("like").if(!viewer, (q) => q.where(noMatch)).where("creator", "=", viewer ?? "").whereRef("subject", "=", ref("post.uri")).select("uri").as("requesterLike")
141992
142039
  ]).execute();
@@ -143652,7 +143699,8 @@ __export(migrations_exports, {
143652
143699
  _20230817T195936007Z: () => T195936007Z_native_notifications_exports,
143653
143700
  _20230830T205507322Z: () => T205507322Z_suggested_feeds_exports,
143654
143701
  _20230904T211011773Z: () => T211011773Z_block_lists_exports,
143655
- _20230906T222220386Z: () => T222220386Z_thread_gating_exports
143702
+ _20230906T222220386Z: () => T222220386Z_thread_gating_exports,
143703
+ _20230920T213858047Z: () => T213858047Z_add_tags_to_post_exports
143656
143704
  });
143657
143705
 
143658
143706
  // src/db/migrations/20230309T045948368Z-init.ts
@@ -144117,6 +144165,19 @@ async function down26(db) {
144117
144165
  await db.schema.alterTable("post").dropColumn("violatesThreadGate").execute();
144118
144166
  }
144119
144167
 
144168
+ // src/db/migrations/20230920T213858047Z-add-tags-to-post.ts
144169
+ var T213858047Z_add_tags_to_post_exports = {};
144170
+ __export(T213858047Z_add_tags_to_post_exports, {
144171
+ down: () => down27,
144172
+ up: () => up27
144173
+ });
144174
+ async function up27(db) {
144175
+ await db.schema.alterTable("post").addColumn("tags", "jsonb").execute();
144176
+ }
144177
+ async function down27(db) {
144178
+ await db.schema.alterTable("post").dropColumn("tags").execute();
144179
+ }
144180
+
144120
144181
  // src/db/migrations/provider.ts
144121
144182
  var CtxMigrationProvider = class {
144122
144183
  constructor(migrations, ctx) {
@@ -145014,6 +145075,7 @@ var insertFn = async (db, uri2, cid2, obj, timestamp) => {
145014
145075
  replyParent: obj.reply?.parent?.uri || null,
145015
145076
  replyParentCid: obj.reply?.parent?.cid || null,
145016
145077
  langs: obj.langs?.length ? sql`${JSON.stringify(obj.langs)}` : null,
145078
+ tags: obj.tags?.length ? sql`${JSON.stringify(obj.tags)}` : null,
145017
145079
  indexedAt: timestamp
145018
145080
  };
145019
145081
  const [insertedPost] = await Promise.all([
@@ -146645,11 +146707,11 @@ var Abyss = class {
146645
146707
  this.ctx = ctx;
146646
146708
  this.auth = basicAuth(this.password);
146647
146709
  }
146648
- async scanImage(did2, cid2) {
146710
+ async scanImage(did2, cid2, uri2) {
146649
146711
  const start = Date.now();
146650
146712
  const res = await retryHttp(async () => {
146651
146713
  try {
146652
- return await this.makeReq(did2, cid2);
146714
+ return await this.makeReq(did2, cid2, uri2);
146653
146715
  } catch (err) {
146654
146716
  labelerLogger.warn({ err, did: did2, cid: cid2.toString() }, "abyss request failed");
146655
146717
  throw err;
@@ -146658,9 +146720,9 @@ var Abyss = class {
146658
146720
  labelerLogger.info({ res, did: did2, cid: cid2.toString(), duration: Date.now() - start }, "abyss response");
146659
146721
  return this.parseRes(res);
146660
146722
  }
146661
- async makeReq(did2, cid2) {
146723
+ async makeReq(did2, cid2, uri2) {
146662
146724
  const { stream, contentType } = await resolveBlob(did2, cid2, this.ctx.db, this.ctx.idResolver);
146663
- const { data } = await import_axios8.default.post(this.getReqUrl({ did: did2 }), stream, {
146725
+ const { data } = await import_axios8.default.post(this.getReqUrl({ did: did2, uri: uri2.toString() }), stream, {
146664
146726
  headers: {
146665
146727
  "Content-Type": contentType,
146666
146728
  authorization: this.auth
@@ -146682,7 +146744,8 @@ var Abyss = class {
146682
146744
  return labels;
146683
146745
  }
146684
146746
  getReqUrl(params2) {
146685
- return `${this.endpoint}/xrpc/com.atproto.unspecced.scanBlob?did=${params2.did}`;
146747
+ const search = new URLSearchParams(params2);
146748
+ return `${this.endpoint}/xrpc/com.atproto.unspecced.scanBlob?${search.toString()}`;
146686
146749
  }
146687
146750
  };
146688
146751
  var TAKEDOWN_LABELS = ["csam", "csem"];
@@ -146859,7 +146922,7 @@ var AutoModerator = class {
146859
146922
  async checkImgForTakedown(uri2, recordCid, imgCids) {
146860
146923
  if (imgCids.length < 0)
146861
146924
  return;
146862
- const results = await Promise.all(imgCids.map((cid2) => this.imageFlagger?.scanImage(uri2.host, cid2)));
146925
+ const results = await Promise.all(imgCids.map((cid2) => this.imageFlagger?.scanImage(uri2.host, cid2, uri2)));
146863
146926
  const takedownCids = [];
146864
146927
  for (let i = 0; i < results.length; i++) {
146865
146928
  if (results.at(i)?.length) {
@@ -146880,7 +146943,30 @@ var AutoModerator = class {
146880
146943
  }
146881
146944
  }
146882
146945
  async persistTakedown(uri2, recordCid, takedownCids, labels) {
146883
- const reason = `automated takedown for labels: ${labels.join(", ")}`;
146946
+ const reportReason = `automated takedown (${labels.join(", ")}). account needs review and possibly additional action`;
146947
+ const takedownReason = `automated takedown for labels: ${labels.join(", ")}`;
146948
+ labelerLogger.warn({
146949
+ uri: uri2.toString(),
146950
+ blobCids: takedownCids,
146951
+ labels
146952
+ }, "hard takedown of record (and blobs) based on auto-matching");
146953
+ if (this.services.moderation) {
146954
+ await this.ctx.db.transaction(async (dbTxn) => {
146955
+ if (!this.services.moderation) {
146956
+ return;
146957
+ }
146958
+ const modSrvc = this.services.moderation(dbTxn);
146959
+ await modSrvc.report({
146960
+ reportedBy: this.ctx.cfg.labelerDid,
146961
+ reasonType: REASONVIOLATION,
146962
+ subject: {
146963
+ uri: uri2,
146964
+ cid: recordCid
146965
+ },
146966
+ reason: reportReason
146967
+ });
146968
+ });
146969
+ }
146884
146970
  if (this.pushAgent) {
146885
146971
  await this.pushAgent.com.atproto.admin.takeModerationAction({
146886
146972
  action: "com.atproto.admin.defs#takedown",
@@ -146890,7 +146976,7 @@ var AutoModerator = class {
146890
146976
  cid: recordCid.toString()
146891
146977
  },
146892
146978
  subjectBlobCids: takedownCids.map((c) => c.toString()),
146893
- reason,
146979
+ reason: takedownReason,
146894
146980
  createdBy: this.ctx.cfg.labelerDid
146895
146981
  });
146896
146982
  } else {
@@ -146903,7 +146989,7 @@ var AutoModerator = class {
146903
146989
  action: "com.atproto.admin.defs#takedown",
146904
146990
  subject: { uri: uri2, cid: recordCid },
146905
146991
  subjectBlobCids: takedownCids,
146906
- reason,
146992
+ reason: takedownReason,
146907
146993
  createdBy: this.ctx.cfg.labelerDid
146908
146994
  });
146909
146995
  await modSrvc.takedownRecord({