@atproto/bsky 0.0.52 → 0.0.54

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 (55) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/api/app/bsky/feed/getPostThread.d.ts.map +1 -1
  3. package/dist/api/app/bsky/feed/getPostThread.js +13 -3
  4. package/dist/api/app/bsky/feed/getPostThread.js.map +1 -1
  5. package/dist/api/app/bsky/graph/getLists.d.ts.map +1 -1
  6. package/dist/api/app/bsky/graph/getLists.js +7 -3
  7. package/dist/api/app/bsky/graph/getLists.js.map +1 -1
  8. package/dist/api/com/atproto/admin/getAccountInfos.d.ts.map +1 -1
  9. package/dist/api/com/atproto/admin/getAccountInfos.js.map +1 -1
  10. package/dist/api/com/atproto/label/queryLabels.d.ts +4 -0
  11. package/dist/api/com/atproto/label/queryLabels.d.ts.map +1 -0
  12. package/dist/api/com/atproto/label/queryLabels.js +30 -0
  13. package/dist/api/com/atproto/label/queryLabels.js.map +1 -0
  14. package/dist/api/index.d.ts.map +1 -1
  15. package/dist/api/index.js +2 -0
  16. package/dist/api/index.js.map +1 -1
  17. package/dist/hydration/hydrator.js +1 -1
  18. package/dist/hydration/hydrator.js.map +1 -1
  19. package/dist/hydration/label.d.ts.map +1 -1
  20. package/dist/hydration/label.js.map +1 -1
  21. package/dist/lexicon/lexicons.d.ts +9 -4
  22. package/dist/lexicon/lexicons.d.ts.map +1 -1
  23. package/dist/lexicon/lexicons.js +12 -7
  24. package/dist/lexicon/lexicons.js.map +1 -1
  25. package/dist/lexicon/types/chat/bsky/convo/defs.d.ts +4 -4
  26. package/dist/lexicon/types/chat/bsky/convo/defs.d.ts.map +1 -1
  27. package/dist/lexicon/types/chat/bsky/convo/defs.js +7 -7
  28. package/dist/lexicon/types/chat/bsky/convo/defs.js.map +1 -1
  29. package/dist/lexicon/types/chat/bsky/convo/sendMessage.d.ts +1 -1
  30. package/dist/lexicon/types/chat/bsky/convo/sendMessage.d.ts.map +1 -1
  31. package/dist/lexicon/types/chat/bsky/convo/sendMessageBatch.d.ts +1 -1
  32. package/dist/lexicon/types/chat/bsky/convo/sendMessageBatch.d.ts.map +1 -1
  33. package/dist/lexicon/types/chat/bsky/moderation/getMessageContext.d.ts +2 -0
  34. package/dist/lexicon/types/chat/bsky/moderation/getMessageContext.d.ts.map +1 -1
  35. package/dist/views/index.d.ts +1 -1
  36. package/dist/views/index.d.ts.map +1 -1
  37. package/dist/views/index.js +6 -2
  38. package/dist/views/index.js.map +1 -1
  39. package/package.json +4 -4
  40. package/src/api/app/bsky/feed/getPostThread.ts +13 -3
  41. package/src/api/app/bsky/graph/getLists.ts +7 -3
  42. package/src/api/com/atproto/admin/getAccountInfos.ts +1 -0
  43. package/src/api/com/atproto/label/queryLabels.ts +35 -0
  44. package/src/api/index.ts +2 -0
  45. package/src/hydration/hydrator.ts +1 -1
  46. package/src/hydration/label.ts +1 -0
  47. package/src/lexicon/lexicons.ts +13 -7
  48. package/src/lexicon/types/chat/bsky/convo/defs.ts +6 -6
  49. package/src/lexicon/types/chat/bsky/convo/sendMessage.ts +1 -1
  50. package/src/lexicon/types/chat/bsky/convo/sendMessageBatch.ts +1 -1
  51. package/src/lexicon/types/chat/bsky/moderation/getMessageContext.ts +2 -0
  52. package/src/views/index.ts +7 -2
  53. package/tests/query-labels.test.ts +87 -0
  54. package/tests/views/__snapshots__/thread.test.ts.snap +177 -11
  55. package/tests/views/thread.test.ts +15 -0
@@ -51,7 +51,7 @@ export type Handler<HA extends HandlerAuth = never> = (
51
51
 
52
52
  export interface BatchItem {
53
53
  convoId: string
54
- message: ChatBskyConvoDefs.Message
54
+ message: ChatBskyConvoDefs.MessageInput
55
55
  [k: string]: unknown
56
56
  }
57
57
 
@@ -10,6 +10,8 @@ import { HandlerAuth, HandlerPipeThrough } from '@atproto/xrpc-server'
10
10
  import * as ChatBskyConvoDefs from '../convo/defs'
11
11
 
12
12
  export interface QueryParams {
13
+ /** Conversation that the message is from. NOTE: this field will eventually be required. */
14
+ convoId?: string
13
15
  messageId: string
14
16
  before: number
15
17
  after: number
@@ -654,7 +654,7 @@ export class Views {
654
654
  childrenByParentUri: Record<string, string[]>,
655
655
  state: HydrationState,
656
656
  depth: number,
657
- ): (ThreadViewPost | NotFoundPost | BlockedPost)[] | undefined {
657
+ ): (ThreadViewPost | BlockedPost)[] | undefined {
658
658
  if (depth < 1) return undefined
659
659
  const childrenUris = childrenByParentUri[parentUri] ?? []
660
660
  return mapDefined(childrenUris, (uri) => {
@@ -666,7 +666,12 @@ export class Views {
666
666
  return undefined
667
667
  }
668
668
  const post = this.post(uri, state)
669
- if (!postInfo || !post) return this.notFoundPost(uri)
669
+ if (!postInfo || !post) {
670
+ // in the future we might consider keeping a placeholder for deleted
671
+ // posts that have replies under them, but not supported at the moment.
672
+ // this case is mostly likely hit when a takedown was applied to a post.
673
+ return undefined
674
+ }
670
675
  if (rootUri !== getRootUri(uri, postInfo)) return // outside thread boundary
671
676
  if (this.viewerBlockExists(post.author.did, state)) {
672
677
  return this.blockedPost(uri, post.author.did, state)
@@ -0,0 +1,87 @@
1
+ import { AtpAgent } from '@atproto/api'
2
+ import { TestNetwork, SeedClient, basicSeed } from '@atproto/dev-env'
3
+ import axios from 'axios'
4
+
5
+ describe('label hydration', () => {
6
+ let network: TestNetwork
7
+ let agent: AtpAgent
8
+ let pdsAgent: AtpAgent
9
+ let sc: SeedClient
10
+
11
+ let alice: string
12
+ let bob: string
13
+ let carol: string
14
+ let labelerDid: string
15
+
16
+ beforeAll(async () => {
17
+ network = await TestNetwork.create({
18
+ dbPostgresSchema: 'bsky_label_hydration',
19
+ })
20
+ agent = network.bsky.getClient()
21
+ pdsAgent = network.pds.getClient()
22
+ sc = network.getSeedClient()
23
+ await basicSeed(sc)
24
+ alice = sc.dids.alice
25
+ bob = sc.dids.bob
26
+ carol = sc.dids.carol
27
+ labelerDid = network.bsky.ctx.cfg.labelsFromIssuerDids[0]
28
+ await createLabel({ src: alice, uri: carol, cid: '', val: 'spam' })
29
+ await createLabel({ src: bob, uri: carol, cid: '', val: 'impersonation' })
30
+ await createLabel({
31
+ src: labelerDid,
32
+ uri: carol,
33
+ cid: '',
34
+ val: 'misleading',
35
+ })
36
+ await network.processAll()
37
+ })
38
+
39
+ afterAll(async () => {
40
+ await network.close()
41
+ })
42
+
43
+ it('returns labels based for a subject', async () => {
44
+ const { data } = await pdsAgent.api.com.atproto.label.queryLabels(
45
+ { uriPatterns: [carol], sources: [alice] },
46
+ {
47
+ headers: sc.getHeaders(bob),
48
+ },
49
+ )
50
+ expect(data.labels?.length).toBe(1)
51
+ expect(data.labels?.[0].src).toBe(alice)
52
+ expect(data.labels?.[0].val).toBe('spam')
53
+ })
54
+
55
+ it('returns labels from supplied labelers as param', async () => {
56
+ const { data } = await pdsAgent.api.com.atproto.label.queryLabels(
57
+ { uriPatterns: [carol], sources: [alice, labelerDid] },
58
+ {
59
+ headers: sc.getHeaders(bob),
60
+ },
61
+ )
62
+ expect(data.labels?.length).toBe(2)
63
+ expect(data.labels?.find((l) => l.src === alice)?.val).toEqual('spam')
64
+ expect(data.labels?.find((l) => l.src === labelerDid)?.val).toEqual(
65
+ 'misleading',
66
+ )
67
+ })
68
+
69
+ const createLabel = async (opts: {
70
+ src?: string
71
+ uri: string
72
+ cid: string
73
+ val: string
74
+ }) => {
75
+ await network.bsky.db.db
76
+ .insertInto('label')
77
+ .values({
78
+ uri: opts.uri,
79
+ cid: opts.cid,
80
+ val: opts.val,
81
+ cts: new Date().toISOString(),
82
+ neg: false,
83
+ src: opts.src ?? labelerDid,
84
+ })
85
+ .execute()
86
+ }
87
+ })
@@ -594,6 +594,177 @@ Object {
594
594
  }
595
595
  `;
596
596
 
597
+ exports[`pds thread views fetches thread with handle in uri 1`] = `
598
+ Object {
599
+ "$type": "app.bsky.feed.defs#threadViewPost",
600
+ "post": Object {
601
+ "author": Object {
602
+ "avatar": "https://bsky.public.url/img/avatar/plain/user(1)/cids(1)@jpeg",
603
+ "did": "user(0)",
604
+ "displayName": "ali",
605
+ "handle": "alice.test",
606
+ "labels": Array [
607
+ Object {
608
+ "cid": "cids(2)",
609
+ "cts": "1970-01-01T00:00:00.000Z",
610
+ "src": "user(0)",
611
+ "uri": "record(3)",
612
+ "val": "self-label-a",
613
+ },
614
+ Object {
615
+ "cid": "cids(2)",
616
+ "cts": "1970-01-01T00:00:00.000Z",
617
+ "src": "user(0)",
618
+ "uri": "record(3)",
619
+ "val": "self-label-b",
620
+ },
621
+ ],
622
+ "viewer": Object {
623
+ "blockedBy": false,
624
+ "followedBy": "record(2)",
625
+ "following": "record(1)",
626
+ "muted": false,
627
+ },
628
+ },
629
+ "cid": "cids(0)",
630
+ "indexedAt": "1970-01-01T00:00:00.000Z",
631
+ "labels": Array [],
632
+ "likeCount": 3,
633
+ "record": Object {
634
+ "$type": "app.bsky.feed.post",
635
+ "createdAt": "1970-01-01T00:00:00.000000Z",
636
+ "text": "again",
637
+ },
638
+ "replyCount": 2,
639
+ "repostCount": 1,
640
+ "uri": "record(0)",
641
+ "viewer": Object {
642
+ "like": "record(4)",
643
+ },
644
+ },
645
+ "replies": Array [
646
+ Object {
647
+ "$type": "app.bsky.feed.defs#threadViewPost",
648
+ "post": Object {
649
+ "author": Object {
650
+ "did": "user(2)",
651
+ "handle": "carol.test",
652
+ "labels": Array [],
653
+ "viewer": Object {
654
+ "blockedBy": false,
655
+ "following": "record(6)",
656
+ "muted": false,
657
+ },
658
+ },
659
+ "cid": "cids(3)",
660
+ "indexedAt": "1970-01-01T00:00:00.000Z",
661
+ "labels": Array [],
662
+ "likeCount": 0,
663
+ "record": Object {
664
+ "$type": "app.bsky.feed.post",
665
+ "createdAt": "1970-01-01T00:00:00.000Z",
666
+ "reply": Object {
667
+ "parent": Object {
668
+ "cid": "cids(0)",
669
+ "uri": "record(0)",
670
+ },
671
+ "root": Object {
672
+ "cid": "cids(0)",
673
+ "uri": "record(0)",
674
+ },
675
+ },
676
+ "text": "of course",
677
+ },
678
+ "replyCount": 0,
679
+ "repostCount": 0,
680
+ "uri": "record(5)",
681
+ "viewer": Object {},
682
+ },
683
+ },
684
+ Object {
685
+ "$type": "app.bsky.feed.defs#threadViewPost",
686
+ "post": Object {
687
+ "author": Object {
688
+ "avatar": "https://bsky.public.url/img/avatar/plain/user(4)/cids(1)@jpeg",
689
+ "did": "user(3)",
690
+ "displayName": "bobby",
691
+ "handle": "bob.test",
692
+ "labels": Array [],
693
+ "viewer": Object {
694
+ "blockedBy": false,
695
+ "muted": false,
696
+ },
697
+ },
698
+ "cid": "cids(4)",
699
+ "embed": Object {
700
+ "$type": "app.bsky.embed.images#view",
701
+ "images": Array [
702
+ Object {
703
+ "alt": "../dev-env/src/seed/img/key-landscape-small.jpg",
704
+ "fullsize": "https://bsky.public.url/img/feed_fullsize/plain/user(4)/cids(5)@jpeg",
705
+ "thumb": "https://bsky.public.url/img/feed_thumbnail/plain/user(4)/cids(5)@jpeg",
706
+ },
707
+ ],
708
+ },
709
+ "indexedAt": "1970-01-01T00:00:00.000Z",
710
+ "labels": Array [
711
+ Object {
712
+ "cid": "cids(4)",
713
+ "cts": "1970-01-01T00:00:00.000Z",
714
+ "src": "did:example:labeler",
715
+ "uri": "record(7)",
716
+ "val": "test-label",
717
+ },
718
+ Object {
719
+ "cid": "cids(4)",
720
+ "cts": "1970-01-01T00:00:00.000Z",
721
+ "src": "did:example:labeler",
722
+ "uri": "record(7)",
723
+ "val": "test-label-2",
724
+ },
725
+ ],
726
+ "likeCount": 0,
727
+ "record": Object {
728
+ "$type": "app.bsky.feed.post",
729
+ "createdAt": "1970-01-01T00:00:00.000Z",
730
+ "embed": Object {
731
+ "$type": "app.bsky.embed.images",
732
+ "images": Array [
733
+ Object {
734
+ "alt": "../dev-env/src/seed/img/key-landscape-small.jpg",
735
+ "image": Object {
736
+ "$type": "blob",
737
+ "mimeType": "image/jpeg",
738
+ "ref": Object {
739
+ "$link": "cids(5)",
740
+ },
741
+ "size": 4114,
742
+ },
743
+ },
744
+ ],
745
+ },
746
+ "reply": Object {
747
+ "parent": Object {
748
+ "cid": "cids(0)",
749
+ "uri": "record(0)",
750
+ },
751
+ "root": Object {
752
+ "cid": "cids(0)",
753
+ "uri": "record(0)",
754
+ },
755
+ },
756
+ "text": "hear that label_me label_me_2",
757
+ },
758
+ "replyCount": 1,
759
+ "repostCount": 0,
760
+ "uri": "record(7)",
761
+ "viewer": Object {},
762
+ },
763
+ },
764
+ ],
765
+ }
766
+ `;
767
+
597
768
  exports[`pds thread views handles deleted posts correctly 1`] = `
598
769
  Object {
599
770
  "$type": "app.bsky.feed.defs#threadViewPost",
@@ -1041,11 +1212,6 @@ Object {
1041
1212
  },
1042
1213
  },
1043
1214
  "replies": Array [
1044
- Object {
1045
- "$type": "app.bsky.feed.defs#notFoundPost",
1046
- "notFound": true,
1047
- "uri": "record(5)",
1048
- },
1049
1215
  Object {
1050
1216
  "$type": "app.bsky.feed.defs#threadViewPost",
1051
1217
  "post": Object {
@@ -1077,14 +1243,14 @@ Object {
1077
1243
  "cid": "cids(3)",
1078
1244
  "cts": "1970-01-01T00:00:00.000Z",
1079
1245
  "src": "did:example:labeler",
1080
- "uri": "record(6)",
1246
+ "uri": "record(5)",
1081
1247
  "val": "test-label",
1082
1248
  },
1083
1249
  Object {
1084
1250
  "cid": "cids(3)",
1085
1251
  "cts": "1970-01-01T00:00:00.000Z",
1086
1252
  "src": "did:example:labeler",
1087
- "uri": "record(6)",
1253
+ "uri": "record(5)",
1088
1254
  "val": "test-label-2",
1089
1255
  },
1090
1256
  ],
@@ -1122,7 +1288,7 @@ Object {
1122
1288
  },
1123
1289
  "replyCount": 1,
1124
1290
  "repostCount": 0,
1125
- "uri": "record(6)",
1291
+ "uri": "record(5)",
1126
1292
  "viewer": Object {},
1127
1293
  },
1128
1294
  "replies": Array [
@@ -1167,7 +1333,7 @@ Object {
1167
1333
  "reply": Object {
1168
1334
  "parent": Object {
1169
1335
  "cid": "cids(3)",
1170
- "uri": "record(6)",
1336
+ "uri": "record(5)",
1171
1337
  },
1172
1338
  "root": Object {
1173
1339
  "cid": "cids(0)",
@@ -1178,9 +1344,9 @@ Object {
1178
1344
  },
1179
1345
  "replyCount": 0,
1180
1346
  "repostCount": 2,
1181
- "uri": "record(7)",
1347
+ "uri": "record(6)",
1182
1348
  "viewer": Object {
1183
- "repost": "record(8)",
1349
+ "repost": "record(7)",
1184
1350
  },
1185
1351
  },
1186
1352
  "replies": Array [],
@@ -56,6 +56,21 @@ describe('pds thread views', () => {
56
56
  expect(forSnapshot(thread.data.thread)).toMatchSnapshot()
57
57
  })
58
58
 
59
+ it('fetches thread with handle in uri', async () => {
60
+ const thread = await agent.api.app.bsky.feed.getPostThread(
61
+ {
62
+ depth: 1,
63
+ uri: sc.posts[alice][1].ref.uriStr.replace(
64
+ `at://${alice}`,
65
+ `at://${sc.accounts[alice].handle}`,
66
+ ),
67
+ },
68
+ { headers: await network.serviceHeaders(bob) },
69
+ )
70
+
71
+ expect(forSnapshot(thread.data.thread)).toMatchSnapshot()
72
+ })
73
+
59
74
  it('fetches ancestors', async () => {
60
75
  const thread = await agent.api.app.bsky.feed.getPostThread(
61
76
  { depth: 1, uri: sc.replies[alice][0].ref.uriStr },