@atproto/api 0.6.20 → 0.6.22

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 (49) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE.txt +7 -0
  3. package/README.md +10 -1
  4. package/definitions/moderation-behaviors.d.ts +1 -0
  5. package/definitions/profile-moderation-behaviors.json +25 -0
  6. package/dist/agent.d.ts +2 -0
  7. package/dist/bsky-agent.d.ts +7 -0
  8. package/dist/client/index.d.ts +12 -0
  9. package/dist/client/lexicons.d.ts +243 -3
  10. package/dist/client/types/app/bsky/actor/defs.d.ts +1 -0
  11. package/dist/client/types/com/atproto/admin/defs.d.ts +28 -0
  12. package/dist/client/types/com/atproto/admin/getAccountInfo.d.ts +16 -0
  13. package/dist/client/types/com/atproto/admin/getSubjectStatus.d.ts +26 -0
  14. package/dist/client/types/com/atproto/admin/searchRepos.d.ts +0 -1
  15. package/dist/client/types/com/atproto/admin/updateSubjectStatus.d.ts +32 -0
  16. package/dist/client/types/com/atproto/server/createAccount.d.ts +4 -2
  17. package/dist/client/types/com/atproto/server/createSession.d.ts +1 -0
  18. package/dist/client/types/com/atproto/server/refreshSession.d.ts +1 -0
  19. package/dist/client/types/com/atproto/server/reserveSigningKey.d.ts +22 -0
  20. package/dist/client/types/com/atproto/sync/listRepos.d.ts +1 -0
  21. package/dist/index.js +878 -425
  22. package/dist/index.js.map +3 -3
  23. package/dist/moderation/accumulator.d.ts +1 -0
  24. package/docs/moderation-behaviors/profiles.md +17 -0
  25. package/package.json +8 -7
  26. package/src/agent.ts +28 -1
  27. package/src/bsky-agent.ts +43 -0
  28. package/src/client/index.ts +52 -0
  29. package/src/client/lexicons.ts +259 -5
  30. package/src/client/types/app/bsky/actor/defs.ts +1 -0
  31. package/src/client/types/com/atproto/admin/defs.ts +61 -0
  32. package/src/client/types/com/atproto/admin/getAccountInfo.ts +32 -0
  33. package/src/client/types/com/atproto/admin/getSubjectStatus.ts +44 -0
  34. package/src/client/types/com/atproto/admin/searchRepos.ts +0 -1
  35. package/src/client/types/com/atproto/admin/updateSubjectStatus.ts +50 -0
  36. package/src/client/types/com/atproto/server/createAccount.ts +4 -2
  37. package/src/client/types/com/atproto/server/createSession.ts +1 -0
  38. package/src/client/types/com/atproto/server/refreshSession.ts +1 -0
  39. package/src/client/types/com/atproto/server/reserveSigningKey.ts +40 -0
  40. package/src/client/types/com/atproto/sync/listRepos.ts +1 -0
  41. package/src/moderation/accumulator.ts +13 -0
  42. package/src/moderation/subjects/account.ts +7 -1
  43. package/tests/agent.test.ts +18 -21
  44. package/tests/bsky-agent.test.ts +19 -25
  45. package/tests/errors.test.ts +5 -11
  46. package/tests/rich-text-detection.test.ts +3 -3
  47. package/tests/util/index.ts +3 -0
  48. package/tests/util/moderation-behavior.ts +10 -2
  49. package/LICENSE +0 -21
@@ -6,6 +6,7 @@ export declare class ModerationCauseAccumulator {
6
6
  constructor();
7
7
  setDid(did: string): void;
8
8
  addBlocking(blocking: string | undefined): void;
9
+ addBlockingByList(blockingByList: AppBskyGraphDefs.ListViewBasic | undefined): void;
9
10
  addBlockedBy(blockedBy: boolean | undefined): void;
10
11
  addBlockOther(blockOther: boolean | undefined): void;
11
12
  addLabel(label: Label, opts: ModerationOpts): void;
@@ -547,6 +547,23 @@ Key:
547
547
  </td>
548
548
  </tr>
549
549
 
550
+ <tr>
551
+ <td><strong>Mute/block: Blocking-by-list user</strong></td>
552
+ <td>
553
+
554
+ </td>
555
+ <td>
556
+
557
+ </td>
558
+ <td>
559
+
560
+ </td>
561
+ <td>
562
+ 🚫
563
+
564
+ </td>
565
+ </tr>
566
+
550
567
  <tr>
551
568
  <td><strong>Mute/block: Blocked by user</strong></td>
552
569
  <td>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/api",
3
- "version": "0.6.20",
3
+ "version": "0.6.22",
4
4
  "license": "MIT",
5
5
  "description": "Client library for atproto and Bluesky",
6
6
  "keywords": [
@@ -19,15 +19,16 @@
19
19
  "multiformats": "^9.9.0",
20
20
  "tlds": "^1.234.0",
21
21
  "typed-emitter": "^2.1.0",
22
- "@atproto/common-web": "^0.2.1",
23
- "@atproto/lexicon": "^0.2.2",
24
- "@atproto/syntax": "^0.1.2",
25
- "@atproto/xrpc": "^0.3.2"
22
+ "zod": "^3.21.4",
23
+ "@atproto/common-web": "^0.2.3",
24
+ "@atproto/lexicon": "^0.3.0",
25
+ "@atproto/syntax": "^0.1.4",
26
+ "@atproto/xrpc": "^0.4.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "common-tags": "^1.8.2",
29
- "@atproto/lex-cli": "^0.2.2",
30
- "@atproto/pds": "^0.1.20"
30
+ "@atproto/lex-cli": "^0.2.4",
31
+ "@atproto/dev-env": "^0.2.13"
31
32
  },
32
33
  "scripts": {
33
34
  "codegen": "pnpm docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
package/src/agent.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ErrorResponseBody, errorResponseBody } from '@atproto/xrpc'
2
2
  import { defaultFetchHandler } from '@atproto/xrpc'
3
+ import { isValidDidDoc, getPdsEndpoint } from '@atproto/common-web'
3
4
  import {
4
5
  AtpBaseClient,
5
6
  AtpServiceClient,
@@ -30,6 +31,11 @@ export class AtpAgent {
30
31
  api: AtpServiceClient
31
32
  session?: AtpSessionData
32
33
 
34
+ /**
35
+ * The PDS URL, driven by the did doc. May be undefined.
36
+ */
37
+ pdsUrl: URL | undefined
38
+
33
39
  private _baseClient: AtpBaseClient
34
40
  private _persistSession?: AtpPersistSessionHandler
35
41
  private _refreshSessionPromise: Promise<void> | undefined
@@ -97,6 +103,7 @@ export class AtpAgent {
97
103
  email: opts.email,
98
104
  emailConfirmed: false,
99
105
  }
106
+ this._updateApiEndpoint(res.data.didDoc)
100
107
  return res
101
108
  } catch (e) {
102
109
  this.session = undefined
@@ -129,6 +136,7 @@ export class AtpAgent {
129
136
  email: res.data.email,
130
137
  emailConfirmed: res.data.emailConfirmed,
131
138
  }
139
+ this._updateApiEndpoint(res.data.didDoc)
132
140
  return res
133
141
  } catch (e) {
134
142
  this.session = undefined
@@ -253,7 +261,7 @@ export class AtpAgent {
253
261
  }
254
262
 
255
263
  // send the refresh request
256
- const url = new URL(this.service.origin)
264
+ const url = new URL((this.pdsUrl || this.service).origin)
257
265
  url.pathname = `/xrpc/${REFRESH_SESSION}`
258
266
  const res = await AtpAgent.fetch(
259
267
  url.toString(),
@@ -277,6 +285,7 @@ export class AtpAgent {
277
285
  handle: res.body.handle,
278
286
  did: res.body.did,
279
287
  }
288
+ this._updateApiEndpoint(res.body.didDoc)
280
289
  this._persistSession?.('update', this.session)
281
290
  }
282
291
  // else: other failures should be ignored - the issue will
@@ -311,6 +320,24 @@ export class AtpAgent {
311
320
  */
312
321
  createModerationReport: typeof this.api.com.atproto.moderation.createReport =
313
322
  (data, opts) => this.api.com.atproto.moderation.createReport(data, opts)
323
+
324
+ /**
325
+ * Helper to update the pds endpoint dynamically.
326
+ *
327
+ * The session methods (create, resume, refresh) may respond with the user's
328
+ * did document which contains the user's canonical PDS endpoint. That endpoint
329
+ * may differ from the endpoint used to contact the server. We capture that
330
+ * PDS endpoint and update the client to use that given endpoint for future
331
+ * requests. (This helps ensure smooth migrations between PDSes, especially
332
+ * when the PDSes are operated by a single org.)
333
+ */
334
+ private _updateApiEndpoint(didDoc: unknown) {
335
+ if (isValidDidDoc(didDoc)) {
336
+ const endpoint = getPdsEndpoint(didDoc)
337
+ this.pdsUrl = endpoint ? new URL(endpoint) : undefined
338
+ }
339
+ this.api.xrpc.uri = this.pdsUrl || this.service
340
+ }
314
341
  }
315
342
 
316
343
  function isErrorObject(v: unknown): v is ErrorResponseBody {
package/src/bsky-agent.ts CHANGED
@@ -258,6 +258,49 @@ export class BskyAgent extends AtpAgent {
258
258
  return this.api.app.bsky.graph.unmuteActor({ actor })
259
259
  }
260
260
 
261
+ async muteModList(uri: string) {
262
+ return this.api.app.bsky.graph.muteActorList({
263
+ list: uri,
264
+ })
265
+ }
266
+
267
+ async unmuteModList(uri: string) {
268
+ return this.api.app.bsky.graph.unmuteActorList({
269
+ list: uri,
270
+ })
271
+ }
272
+
273
+ async blockModList(uri: string) {
274
+ if (!this.session) {
275
+ throw new Error('Not logged in')
276
+ }
277
+ return await this.api.app.bsky.graph.listblock.create(
278
+ { repo: this.session.did },
279
+ {
280
+ subject: uri,
281
+ createdAt: new Date().toISOString(),
282
+ },
283
+ )
284
+ }
285
+
286
+ async unblockModList(uri: string) {
287
+ if (!this.session) {
288
+ throw new Error('Not logged in')
289
+ }
290
+ const listInfo = await this.api.app.bsky.graph.getList({
291
+ list: uri,
292
+ limit: 1,
293
+ })
294
+ if (!listInfo.data.list.viewer?.blocked) {
295
+ return
296
+ }
297
+ const { rkey } = new AtUri(listInfo.data.list.viewer.blocked)
298
+ return await this.api.app.bsky.graph.listblock.delete({
299
+ repo: this.session.did,
300
+ rkey,
301
+ })
302
+ }
303
+
261
304
  async updateSeenNotifications(seenAt?: string) {
262
305
  seenAt = seenAt || new Date().toISOString()
263
306
  return this.api.app.bsky.notification.updateSeen({
@@ -11,6 +11,7 @@ import * as ComAtprotoAdminDefs from './types/com/atproto/admin/defs'
11
11
  import * as ComAtprotoAdminDisableAccountInvites from './types/com/atproto/admin/disableAccountInvites'
12
12
  import * as ComAtprotoAdminDisableInviteCodes from './types/com/atproto/admin/disableInviteCodes'
13
13
  import * as ComAtprotoAdminEnableAccountInvites from './types/com/atproto/admin/enableAccountInvites'
14
+ import * as ComAtprotoAdminGetAccountInfo from './types/com/atproto/admin/getAccountInfo'
14
15
  import * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
15
16
  import * as ComAtprotoAdminGetModerationAction from './types/com/atproto/admin/getModerationAction'
16
17
  import * as ComAtprotoAdminGetModerationActions from './types/com/atproto/admin/getModerationActions'
@@ -18,6 +19,7 @@ import * as ComAtprotoAdminGetModerationReport from './types/com/atproto/admin/g
18
19
  import * as ComAtprotoAdminGetModerationReports from './types/com/atproto/admin/getModerationReports'
19
20
  import * as ComAtprotoAdminGetRecord from './types/com/atproto/admin/getRecord'
20
21
  import * as ComAtprotoAdminGetRepo from './types/com/atproto/admin/getRepo'
22
+ import * as ComAtprotoAdminGetSubjectStatus from './types/com/atproto/admin/getSubjectStatus'
21
23
  import * as ComAtprotoAdminResolveModerationReports from './types/com/atproto/admin/resolveModerationReports'
22
24
  import * as ComAtprotoAdminReverseModerationAction from './types/com/atproto/admin/reverseModerationAction'
23
25
  import * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRepos'
@@ -25,6 +27,7 @@ import * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
25
27
  import * as ComAtprotoAdminTakeModerationAction from './types/com/atproto/admin/takeModerationAction'
26
28
  import * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
27
29
  import * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
30
+ import * as ComAtprotoAdminUpdateSubjectStatus from './types/com/atproto/admin/updateSubjectStatus'
28
31
  import * as ComAtprotoIdentityResolveHandle from './types/com/atproto/identity/resolveHandle'
29
32
  import * as ComAtprotoIdentityUpdateHandle from './types/com/atproto/identity/updateHandle'
30
33
  import * as ComAtprotoLabelDefs from './types/com/atproto/label/defs'
@@ -59,6 +62,7 @@ import * as ComAtprotoServerRequestAccountDelete from './types/com/atproto/serve
59
62
  import * as ComAtprotoServerRequestEmailConfirmation from './types/com/atproto/server/requestEmailConfirmation'
60
63
  import * as ComAtprotoServerRequestEmailUpdate from './types/com/atproto/server/requestEmailUpdate'
61
64
  import * as ComAtprotoServerRequestPasswordReset from './types/com/atproto/server/requestPasswordReset'
65
+ import * as ComAtprotoServerReserveSigningKey from './types/com/atproto/server/reserveSigningKey'
62
66
  import * as ComAtprotoServerResetPassword from './types/com/atproto/server/resetPassword'
63
67
  import * as ComAtprotoServerRevokeAppPassword from './types/com/atproto/server/revokeAppPassword'
64
68
  import * as ComAtprotoServerUpdateEmail from './types/com/atproto/server/updateEmail'
@@ -144,6 +148,7 @@ export * as ComAtprotoAdminDefs from './types/com/atproto/admin/defs'
144
148
  export * as ComAtprotoAdminDisableAccountInvites from './types/com/atproto/admin/disableAccountInvites'
145
149
  export * as ComAtprotoAdminDisableInviteCodes from './types/com/atproto/admin/disableInviteCodes'
146
150
  export * as ComAtprotoAdminEnableAccountInvites from './types/com/atproto/admin/enableAccountInvites'
151
+ export * as ComAtprotoAdminGetAccountInfo from './types/com/atproto/admin/getAccountInfo'
147
152
  export * as ComAtprotoAdminGetInviteCodes from './types/com/atproto/admin/getInviteCodes'
148
153
  export * as ComAtprotoAdminGetModerationAction from './types/com/atproto/admin/getModerationAction'
149
154
  export * as ComAtprotoAdminGetModerationActions from './types/com/atproto/admin/getModerationActions'
@@ -151,6 +156,7 @@ export * as ComAtprotoAdminGetModerationReport from './types/com/atproto/admin/g
151
156
  export * as ComAtprotoAdminGetModerationReports from './types/com/atproto/admin/getModerationReports'
152
157
  export * as ComAtprotoAdminGetRecord from './types/com/atproto/admin/getRecord'
153
158
  export * as ComAtprotoAdminGetRepo from './types/com/atproto/admin/getRepo'
159
+ export * as ComAtprotoAdminGetSubjectStatus from './types/com/atproto/admin/getSubjectStatus'
154
160
  export * as ComAtprotoAdminResolveModerationReports from './types/com/atproto/admin/resolveModerationReports'
155
161
  export * as ComAtprotoAdminReverseModerationAction from './types/com/atproto/admin/reverseModerationAction'
156
162
  export * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRepos'
@@ -158,6 +164,7 @@ export * as ComAtprotoAdminSendEmail from './types/com/atproto/admin/sendEmail'
158
164
  export * as ComAtprotoAdminTakeModerationAction from './types/com/atproto/admin/takeModerationAction'
159
165
  export * as ComAtprotoAdminUpdateAccountEmail from './types/com/atproto/admin/updateAccountEmail'
160
166
  export * as ComAtprotoAdminUpdateAccountHandle from './types/com/atproto/admin/updateAccountHandle'
167
+ export * as ComAtprotoAdminUpdateSubjectStatus from './types/com/atproto/admin/updateSubjectStatus'
161
168
  export * as ComAtprotoIdentityResolveHandle from './types/com/atproto/identity/resolveHandle'
162
169
  export * as ComAtprotoIdentityUpdateHandle from './types/com/atproto/identity/updateHandle'
163
170
  export * as ComAtprotoLabelDefs from './types/com/atproto/label/defs'
@@ -192,6 +199,7 @@ export * as ComAtprotoServerRequestAccountDelete from './types/com/atproto/serve
192
199
  export * as ComAtprotoServerRequestEmailConfirmation from './types/com/atproto/server/requestEmailConfirmation'
193
200
  export * as ComAtprotoServerRequestEmailUpdate from './types/com/atproto/server/requestEmailUpdate'
194
201
  export * as ComAtprotoServerRequestPasswordReset from './types/com/atproto/server/requestPasswordReset'
202
+ export * as ComAtprotoServerReserveSigningKey from './types/com/atproto/server/reserveSigningKey'
195
203
  export * as ComAtprotoServerResetPassword from './types/com/atproto/server/resetPassword'
196
204
  export * as ComAtprotoServerRevokeAppPassword from './types/com/atproto/server/revokeAppPassword'
197
205
  export * as ComAtprotoServerUpdateEmail from './types/com/atproto/server/updateEmail'
@@ -394,6 +402,17 @@ export class AdminNS {
394
402
  })
395
403
  }
396
404
 
405
+ getAccountInfo(
406
+ params?: ComAtprotoAdminGetAccountInfo.QueryParams,
407
+ opts?: ComAtprotoAdminGetAccountInfo.CallOptions,
408
+ ): Promise<ComAtprotoAdminGetAccountInfo.Response> {
409
+ return this._service.xrpc
410
+ .call('com.atproto.admin.getAccountInfo', params, undefined, opts)
411
+ .catch((e) => {
412
+ throw ComAtprotoAdminGetAccountInfo.toKnownErr(e)
413
+ })
414
+ }
415
+
397
416
  getInviteCodes(
398
417
  params?: ComAtprotoAdminGetInviteCodes.QueryParams,
399
418
  opts?: ComAtprotoAdminGetInviteCodes.CallOptions,
@@ -471,6 +490,17 @@ export class AdminNS {
471
490
  })
472
491
  }
473
492
 
493
+ getSubjectStatus(
494
+ params?: ComAtprotoAdminGetSubjectStatus.QueryParams,
495
+ opts?: ComAtprotoAdminGetSubjectStatus.CallOptions,
496
+ ): Promise<ComAtprotoAdminGetSubjectStatus.Response> {
497
+ return this._service.xrpc
498
+ .call('com.atproto.admin.getSubjectStatus', params, undefined, opts)
499
+ .catch((e) => {
500
+ throw ComAtprotoAdminGetSubjectStatus.toKnownErr(e)
501
+ })
502
+ }
503
+
474
504
  resolveModerationReports(
475
505
  data?: ComAtprotoAdminResolveModerationReports.InputSchema,
476
506
  opts?: ComAtprotoAdminResolveModerationReports.CallOptions,
@@ -547,6 +577,17 @@ export class AdminNS {
547
577
  throw ComAtprotoAdminUpdateAccountHandle.toKnownErr(e)
548
578
  })
549
579
  }
580
+
581
+ updateSubjectStatus(
582
+ data?: ComAtprotoAdminUpdateSubjectStatus.InputSchema,
583
+ opts?: ComAtprotoAdminUpdateSubjectStatus.CallOptions,
584
+ ): Promise<ComAtprotoAdminUpdateSubjectStatus.Response> {
585
+ return this._service.xrpc
586
+ .call('com.atproto.admin.updateSubjectStatus', opts?.qp, data, opts)
587
+ .catch((e) => {
588
+ throw ComAtprotoAdminUpdateSubjectStatus.toKnownErr(e)
589
+ })
590
+ }
550
591
  }
551
592
 
552
593
  export class IdentityNS {
@@ -907,6 +948,17 @@ export class ServerNS {
907
948
  })
908
949
  }
909
950
 
951
+ reserveSigningKey(
952
+ data?: ComAtprotoServerReserveSigningKey.InputSchema,
953
+ opts?: ComAtprotoServerReserveSigningKey.CallOptions,
954
+ ): Promise<ComAtprotoServerReserveSigningKey.Response> {
955
+ return this._service.xrpc
956
+ .call('com.atproto.server.reserveSigningKey', opts?.qp, data, opts)
957
+ .catch((e) => {
958
+ throw ComAtprotoServerReserveSigningKey.toKnownErr(e)
959
+ })
960
+ }
961
+
910
962
  resetPassword(
911
963
  data?: ComAtprotoServerResetPassword.InputSchema,
912
964
  opts?: ComAtprotoServerResetPassword.CallOptions,