@atproto/api 0.6.20 → 0.6.21

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 (37) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +4 -0
  3. package/definitions/moderation-behaviors.d.ts +1 -0
  4. package/definitions/profile-moderation-behaviors.json +25 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/bsky-agent.d.ts +7 -0
  7. package/dist/client/index.d.ts +3 -0
  8. package/dist/client/lexicons.d.ts +43 -0
  9. package/dist/client/types/app/bsky/actor/defs.d.ts +1 -0
  10. package/dist/client/types/com/atproto/server/createAccount.d.ts +2 -0
  11. package/dist/client/types/com/atproto/server/createSession.d.ts +1 -0
  12. package/dist/client/types/com/atproto/server/refreshSession.d.ts +1 -0
  13. package/dist/client/types/com/atproto/server/reserveSigningKey.d.ts +18 -0
  14. package/dist/client/types/com/atproto/sync/listRepos.d.ts +1 -0
  15. package/dist/index.js +456 -265
  16. package/dist/index.js.map +3 -3
  17. package/dist/moderation/accumulator.d.ts +1 -0
  18. package/docs/moderation-behaviors/profiles.md +17 -0
  19. package/package.json +8 -7
  20. package/src/agent.ts +28 -1
  21. package/src/bsky-agent.ts +43 -0
  22. package/src/client/index.ts +13 -0
  23. package/src/client/lexicons.ts +44 -1
  24. package/src/client/types/app/bsky/actor/defs.ts +1 -0
  25. package/src/client/types/com/atproto/server/createAccount.ts +2 -0
  26. package/src/client/types/com/atproto/server/createSession.ts +1 -0
  27. package/src/client/types/com/atproto/server/refreshSession.ts +1 -0
  28. package/src/client/types/com/atproto/server/reserveSigningKey.ts +35 -0
  29. package/src/client/types/com/atproto/sync/listRepos.ts +1 -0
  30. package/src/moderation/accumulator.ts +13 -0
  31. package/src/moderation/subjects/account.ts +7 -1
  32. package/tests/agent.test.ts +18 -21
  33. package/tests/bsky-agent.test.ts +19 -25
  34. package/tests/errors.test.ts +5 -11
  35. package/tests/rich-text-detection.test.ts +3 -3
  36. package/tests/util/index.ts +3 -0
  37. package/tests/util/moderation-behavior.ts +10 -2
@@ -1,23 +1,17 @@
1
- import {
2
- CloseFn,
3
- runTestServer,
4
- TestServerInfo,
5
- } from '@atproto/pds/tests/_util'
1
+ import { TestNetworkNoAppView } from '@atproto/dev-env'
6
2
  import { BskyAgent, ComAtprotoRepoPutRecord, AppBskyActorProfile } from '..'
7
3
 
8
4
  describe('agent', () => {
9
- let server: TestServerInfo
10
- let close: CloseFn
5
+ let network: TestNetworkNoAppView
11
6
 
12
7
  beforeAll(async () => {
13
- server = await runTestServer({
8
+ network = await TestNetworkNoAppView.create({
14
9
  dbPostgresSchema: 'bsky_agent',
15
10
  })
16
- close = server.close
17
11
  })
18
12
 
19
13
  afterAll(async () => {
20
- await close()
14
+ await network.close()
21
15
  })
22
16
 
23
17
  const getProfileDisplayName = async (
@@ -35,7 +29,7 @@ describe('agent', () => {
35
29
  }
36
30
 
37
31
  it('upsertProfile correctly creates and updates profiles.', async () => {
38
- const agent = new BskyAgent({ service: server.url })
32
+ const agent = new BskyAgent({ service: network.pds.url })
39
33
 
40
34
  await agent.createAccount({
41
35
  handle: 'user1.test',
@@ -67,7 +61,7 @@ describe('agent', () => {
67
61
  })
68
62
 
69
63
  it('upsertProfile correctly handles CAS failures.', async () => {
70
- const agent = new BskyAgent({ service: server.url })
64
+ const agent = new BskyAgent({ service: network.pds.url })
71
65
 
72
66
  await agent.createAccount({
73
67
  handle: 'user2.test',
@@ -106,7 +100,7 @@ describe('agent', () => {
106
100
  })
107
101
 
108
102
  it('upsertProfile wont endlessly retry CAS failures.', async () => {
109
- const agent = new BskyAgent({ service: server.url })
103
+ const agent = new BskyAgent({ service: network.pds.url })
110
104
 
111
105
  await agent.createAccount({
112
106
  handle: 'user3.test',
@@ -135,7 +129,7 @@ describe('agent', () => {
135
129
  })
136
130
 
137
131
  it('upsertProfile validates the record.', async () => {
138
- const agent = new BskyAgent({ service: server.url })
132
+ const agent = new BskyAgent({ service: network.pds.url })
139
133
 
140
134
  await agent.createAccount({
141
135
  handle: 'user4.test',
@@ -153,70 +147,70 @@ describe('agent', () => {
153
147
 
154
148
  describe('app', () => {
155
149
  it('should retrieve the api app', () => {
156
- const agent = new BskyAgent({ service: server.url })
150
+ const agent = new BskyAgent({ service: network.pds.url })
157
151
  expect(agent.app).toBe(agent.api.app)
158
152
  })
159
153
  })
160
154
 
161
155
  describe('post', () => {
162
156
  it('should throw if no session', async () => {
163
- const agent = new BskyAgent({ service: server.url })
157
+ const agent = new BskyAgent({ service: network.pds.url })
164
158
  await expect(agent.post({ text: 'foo' })).rejects.toThrow('Not logged in')
165
159
  })
166
160
  })
167
161
 
168
162
  describe('deletePost', () => {
169
163
  it('should throw if no session', async () => {
170
- const agent = new BskyAgent({ service: server.url })
164
+ const agent = new BskyAgent({ service: network.pds.url })
171
165
  await expect(agent.deletePost('foo')).rejects.toThrow('Not logged in')
172
166
  })
173
167
  })
174
168
 
175
169
  describe('like', () => {
176
170
  it('should throw if no session', async () => {
177
- const agent = new BskyAgent({ service: server.url })
171
+ const agent = new BskyAgent({ service: network.pds.url })
178
172
  await expect(agent.like('foo', 'bar')).rejects.toThrow('Not logged in')
179
173
  })
180
174
  })
181
175
 
182
176
  describe('deleteLike', () => {
183
177
  it('should throw if no session', async () => {
184
- const agent = new BskyAgent({ service: server.url })
178
+ const agent = new BskyAgent({ service: network.pds.url })
185
179
  await expect(agent.deleteLike('foo')).rejects.toThrow('Not logged in')
186
180
  })
187
181
  })
188
182
 
189
183
  describe('repost', () => {
190
184
  it('should throw if no session', async () => {
191
- const agent = new BskyAgent({ service: server.url })
185
+ const agent = new BskyAgent({ service: network.pds.url })
192
186
  await expect(agent.repost('foo', 'bar')).rejects.toThrow('Not logged in')
193
187
  })
194
188
  })
195
189
 
196
190
  describe('deleteRepost', () => {
197
191
  it('should throw if no session', async () => {
198
- const agent = new BskyAgent({ service: server.url })
192
+ const agent = new BskyAgent({ service: network.pds.url })
199
193
  await expect(agent.deleteRepost('foo')).rejects.toThrow('Not logged in')
200
194
  })
201
195
  })
202
196
 
203
197
  describe('follow', () => {
204
198
  it('should throw if no session', async () => {
205
- const agent = new BskyAgent({ service: server.url })
199
+ const agent = new BskyAgent({ service: network.pds.url })
206
200
  await expect(agent.follow('foo')).rejects.toThrow('Not logged in')
207
201
  })
208
202
  })
209
203
 
210
204
  describe('deleteFollow', () => {
211
205
  it('should throw if no session', async () => {
212
- const agent = new BskyAgent({ service: server.url })
206
+ const agent = new BskyAgent({ service: network.pds.url })
213
207
  await expect(agent.deleteFollow('foo')).rejects.toThrow('Not logged in')
214
208
  })
215
209
  })
216
210
 
217
211
  describe('preferences methods', () => {
218
212
  it('gets and sets preferences correctly', async () => {
219
- const agent = new BskyAgent({ service: server.url })
213
+ const agent = new BskyAgent({ service: network.pds.url })
220
214
 
221
215
  await agent.createAccount({
222
216
  handle: 'user5.test',
@@ -714,7 +708,7 @@ describe('agent', () => {
714
708
  })
715
709
 
716
710
  it('resolves duplicates correctly', async () => {
717
- const agent = new BskyAgent({ service: server.url })
711
+ const agent = new BskyAgent({ service: network.pds.url })
718
712
 
719
713
  await agent.createAccount({
720
714
  handle: 'user6.test',
@@ -1,25 +1,19 @@
1
- import {
2
- CloseFn,
3
- runTestServer,
4
- TestServerInfo,
5
- } from '@atproto/pds/tests/_util'
6
1
  import { AtpAgent, ComAtprotoServerCreateAccount } from '..'
2
+ import { TestNetworkNoAppView } from '@atproto/dev-env'
7
3
 
8
4
  describe('errors', () => {
9
- let server: TestServerInfo
5
+ let network: TestNetworkNoAppView
10
6
  let client: AtpAgent
11
- let close: CloseFn
12
7
 
13
8
  beforeAll(async () => {
14
- server = await runTestServer({
9
+ network = await TestNetworkNoAppView.create({
15
10
  dbPostgresSchema: 'known_errors',
16
11
  })
17
- client = new AtpAgent({ service: server.url })
18
- close = server.close
12
+ client = network.pds.getClient()
19
13
  })
20
14
 
21
15
  afterAll(async () => {
22
- await close()
16
+ await network.close()
23
17
  })
24
18
 
25
19
  it('constructs the correct error instance', async () => {
@@ -295,10 +295,10 @@ describe('detectFacets', () => {
295
295
  const rt = new RichText({ text: input })
296
296
  await rt.detectFacets(agent)
297
297
 
298
- let detectedTags: string[] = []
299
- let detectedIndices: { byteStart: number; byteEnd: number }[] = []
298
+ const detectedTags: string[] = []
299
+ const detectedIndices: { byteStart: number; byteEnd: number }[] = []
300
300
 
301
- for (const { facet, ...rest } of rt.segments()) {
301
+ for (const { facet } of rt.segments()) {
302
302
  if (!facet) continue
303
303
  for (const feature of facet.features) {
304
304
  if (isTag(feature)) {
@@ -135,6 +135,7 @@ export const mock = {
135
135
  mutedByList,
136
136
  blockedBy,
137
137
  blocking,
138
+ blockingByList,
138
139
  following,
139
140
  followedBy,
140
141
  }: {
@@ -142,6 +143,7 @@ export const mock = {
142
143
  mutedByList?: AppBskyGraphDefs.ListViewBasic
143
144
  blockedBy?: boolean
144
145
  blocking?: string
146
+ blockingByList?: AppBskyGraphDefs.ListViewBasic
145
147
  following?: string
146
148
  followedBy?: string
147
149
  }): AppBskyActorDefs.ViewerState {
@@ -150,6 +152,7 @@ export const mock = {
150
152
  mutedByList,
151
153
  blockedBy,
152
154
  blocking,
155
+ blockingByList,
153
156
  following,
154
157
  followedBy,
155
158
  }
@@ -25,6 +25,10 @@ expect.extend({
25
25
  if (actual.cause.source.type === 'list') {
26
26
  cause = 'muted-by-list'
27
27
  }
28
+ } else if (actual.cause?.type === 'blocking') {
29
+ if (actual.cause.source.type === 'list') {
30
+ cause = 'blocking-by-list'
31
+ }
28
32
  }
29
33
  if (!expected) {
30
34
  if (!ignoreCause && actual.cause) {
@@ -153,8 +157,12 @@ export class ModerationBehaviorSuiteRunner {
153
157
  ? m.listViewBasic({ name: 'Fake List' })
154
158
  : undefined,
155
159
  blockedBy: def.blockedBy,
156
- blocking: def.blocking
157
- ? 'at://did:web:self.test/app.bsky.graph.block/fake'
160
+ blocking:
161
+ def.blocking || def.blockingByList
162
+ ? 'at://did:web:self.test/app.bsky.graph.block/fake'
163
+ : undefined,
164
+ blockingByList: def.blockingByList
165
+ ? m.listViewBasic({ name: 'Fake List' })
158
166
  : undefined,
159
167
  }),
160
168
  })