@atproto/api 0.6.6 → 0.6.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.
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { LabelPreference } from './moderation/types';
1
2
  export declare type AtpSessionEvent = 'create' | 'create-failed' | 'update' | 'expired';
2
3
  export interface AtpSessionData {
3
4
  refreshJwt: string;
@@ -31,4 +32,13 @@ export declare type AtpAgentFetchHandler = (httpUri: string, httpMethod: string,
31
32
  export interface AtpAgentGlobalOpts {
32
33
  fetch: AtpAgentFetchHandler;
33
34
  }
35
+ export declare type BskyLabelPreference = LabelPreference | 'show';
36
+ export interface BskyPreferences {
37
+ feeds: {
38
+ saved?: string[];
39
+ pinned?: string[];
40
+ };
41
+ adultContentEnabled: boolean;
42
+ contentLabels: Record<string, BskyLabelPreference>;
43
+ }
34
44
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atproto/api",
3
- "version": "0.6.6",
3
+ "version": "0.6.8",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "codegen": "yarn docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@atproto/common-web": "*",
26
- "@atproto/uri": "*",
26
+ "@atproto/syntax": "*",
27
27
  "@atproto/xrpc": "*",
28
28
  "tlds": "^1.234.0",
29
29
  "typed-emitter": "^2.1.0"
package/src/bsky-agent.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { AtUri } from '@atproto/uri'
1
+ import { AtUri } from '@atproto/syntax'
2
2
  import { AtpAgent } from './agent'
3
3
  import {
4
4
  AppBskyFeedPost,
5
5
  AppBskyActorProfile,
6
+ AppBskyActorDefs,
6
7
  ComAtprotoRepoPutRecord,
7
8
  } from './client'
9
+ import { BskyPreferences, BskyLabelPreference } from './types'
8
10
 
9
11
  export class BskyAgent extends AtpAgent {
10
12
  get app() {
@@ -236,4 +238,182 @@ export class BskyAgent extends AtpAgent {
236
238
  seenAt,
237
239
  })
238
240
  }
241
+
242
+ async getPreferences(): Promise<BskyPreferences> {
243
+ const prefs: BskyPreferences = {
244
+ feeds: {
245
+ saved: undefined,
246
+ pinned: undefined,
247
+ },
248
+ adultContentEnabled: false,
249
+ contentLabels: {},
250
+ }
251
+ const res = await this.app.bsky.actor.getPreferences({})
252
+ for (const pref of res.data.preferences) {
253
+ if (
254
+ AppBskyActorDefs.isAdultContentPref(pref) &&
255
+ AppBskyActorDefs.validateAdultContentPref(pref).success
256
+ ) {
257
+ prefs.adultContentEnabled = pref.enabled
258
+ } else if (
259
+ AppBskyActorDefs.isContentLabelPref(pref) &&
260
+ AppBskyActorDefs.validateAdultContentPref(pref).success
261
+ ) {
262
+ let value = pref.visibility
263
+ if (value === 'show') {
264
+ value = 'ignore'
265
+ }
266
+ if (value === 'ignore' || value === 'warn' || value === 'hide') {
267
+ prefs.contentLabels[pref.label] = value as BskyLabelPreference
268
+ }
269
+ } else if (
270
+ AppBskyActorDefs.isSavedFeedsPref(pref) &&
271
+ AppBskyActorDefs.validateSavedFeedsPref(pref).success
272
+ ) {
273
+ prefs.feeds.saved = pref.saved
274
+ prefs.feeds.pinned = pref.pinned
275
+ }
276
+ }
277
+ return prefs
278
+ }
279
+
280
+ async setSavedFeeds(saved: string[], pinned: string[]) {
281
+ return updateFeedPreferences(this, () => ({
282
+ saved,
283
+ pinned,
284
+ }))
285
+ }
286
+
287
+ async addSavedFeed(v: string) {
288
+ return updateFeedPreferences(this, (saved: string[], pinned: string[]) => ({
289
+ saved: [...saved.filter((uri) => uri !== v), v],
290
+ pinned,
291
+ }))
292
+ }
293
+
294
+ async removeSavedFeed(v: string) {
295
+ return updateFeedPreferences(this, (saved: string[], pinned: string[]) => ({
296
+ saved: saved.filter((uri) => uri !== v),
297
+ pinned: pinned.filter((uri) => uri !== v),
298
+ }))
299
+ }
300
+
301
+ async addPinnedFeed(v: string) {
302
+ return updateFeedPreferences(this, (saved: string[], pinned: string[]) => ({
303
+ saved: [...saved.filter((uri) => uri !== v), v],
304
+ pinned: [...pinned.filter((uri) => uri !== v), v],
305
+ }))
306
+ }
307
+
308
+ async removePinnedFeed(v: string) {
309
+ return updateFeedPreferences(this, (saved: string[], pinned: string[]) => ({
310
+ saved,
311
+ pinned: pinned.filter((uri) => uri !== v),
312
+ }))
313
+ }
314
+
315
+ async setAdultContentEnabled(v: boolean) {
316
+ await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => {
317
+ const existing = prefs.find(
318
+ (pref) =>
319
+ AppBskyActorDefs.isAdultContentPref(pref) &&
320
+ AppBskyActorDefs.validateAdultContentPref(pref).success,
321
+ )
322
+ if (existing) {
323
+ existing.enabled = v
324
+ } else {
325
+ prefs.push({
326
+ $type: 'app.bsky.actor.defs#adultContentPref',
327
+ enabled: v,
328
+ })
329
+ }
330
+ return prefs
331
+ })
332
+ }
333
+
334
+ async setContentLabelPref(key: string, value: BskyLabelPreference) {
335
+ // TEMP update old value
336
+ if (value === 'show') {
337
+ value = 'ignore'
338
+ }
339
+
340
+ await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => {
341
+ const existing = prefs.find(
342
+ (pref) =>
343
+ AppBskyActorDefs.isContentLabelPref(pref) &&
344
+ AppBskyActorDefs.validateAdultContentPref(pref).success &&
345
+ pref.label === key,
346
+ )
347
+ if (existing) {
348
+ existing.visibility = value
349
+ } else {
350
+ prefs.push({
351
+ $type: 'app.bsky.actor.defs#contentLabelPref',
352
+ label: key,
353
+ visibility: value,
354
+ })
355
+ }
356
+ return prefs
357
+ })
358
+ }
359
+ }
360
+
361
+ /**
362
+ * This function updates the preferences of a user and allows for a callback function to be executed
363
+ * before the update.
364
+ * @param cb - cb is a callback function that takes in a single parameter of type
365
+ * AppBskyActorDefs.Preferences and returns either a boolean or void. This callback function is used to
366
+ * update the preferences of the user. The function is called with the current preferences as an
367
+ * argument and if the callback returns false, the preferences are not updated.
368
+ */
369
+ async function updatePreferences(
370
+ agent: BskyAgent,
371
+ cb: (
372
+ prefs: AppBskyActorDefs.Preferences,
373
+ ) => AppBskyActorDefs.Preferences | false,
374
+ ) {
375
+ const res = await agent.app.bsky.actor.getPreferences({})
376
+ const newPrefs = cb(res.data.preferences)
377
+ if (newPrefs === false) {
378
+ return
379
+ }
380
+ await agent.app.bsky.actor.putPreferences({
381
+ preferences: newPrefs,
382
+ })
383
+ }
384
+
385
+ /**
386
+ * A helper specifically for updating feed preferences
387
+ */
388
+ async function updateFeedPreferences(
389
+ agent: BskyAgent,
390
+ cb: (
391
+ saved: string[],
392
+ pinned: string[],
393
+ ) => { saved: string[]; pinned: string[] },
394
+ ): Promise<{ saved: string[]; pinned: string[] }> {
395
+ let res
396
+ await updatePreferences(agent, (prefs: AppBskyActorDefs.Preferences) => {
397
+ let feedsPref = prefs.find(
398
+ (pref) =>
399
+ AppBskyActorDefs.isSavedFeedsPref(pref) &&
400
+ AppBskyActorDefs.validateSavedFeedsPref(pref).success,
401
+ ) as AppBskyActorDefs.SavedFeedsPref | undefined
402
+ if (feedsPref) {
403
+ res = cb(feedsPref.saved, feedsPref.pinned)
404
+ feedsPref.saved = res.saved
405
+ feedsPref.pinned = res.pinned
406
+ } else {
407
+ res = cb([], [])
408
+ feedsPref = {
409
+ $type: 'app.bsky.actor.defs#savedFeedsPref',
410
+ saved: res.saved,
411
+ pinned: res.pinned,
412
+ }
413
+ }
414
+ return prefs
415
+ .filter((pref) => !AppBskyActorDefs.isSavedFeedsPref(pref))
416
+ .concat([feedsPref])
417
+ })
418
+ return res
239
419
  }
@@ -18,7 +18,6 @@ import * as ComAtprotoAdminGetModerationReport from './types/com/atproto/admin/g
18
18
  import * as ComAtprotoAdminGetModerationReports from './types/com/atproto/admin/getModerationReports'
19
19
  import * as ComAtprotoAdminGetRecord from './types/com/atproto/admin/getRecord'
20
20
  import * as ComAtprotoAdminGetRepo from './types/com/atproto/admin/getRepo'
21
- import * as ComAtprotoAdminRebaseRepo from './types/com/atproto/admin/rebaseRepo'
22
21
  import * as ComAtprotoAdminResolveModerationReports from './types/com/atproto/admin/resolveModerationReports'
23
22
  import * as ComAtprotoAdminReverseModerationAction from './types/com/atproto/admin/reverseModerationAction'
24
23
  import * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRepos'
@@ -40,7 +39,6 @@ import * as ComAtprotoRepoDescribeRepo from './types/com/atproto/repo/describeRe
40
39
  import * as ComAtprotoRepoGetRecord from './types/com/atproto/repo/getRecord'
41
40
  import * as ComAtprotoRepoListRecords from './types/com/atproto/repo/listRecords'
42
41
  import * as ComAtprotoRepoPutRecord from './types/com/atproto/repo/putRecord'
43
- import * as ComAtprotoRepoRebaseRepo from './types/com/atproto/repo/rebaseRepo'
44
42
  import * as ComAtprotoRepoStrongRef from './types/com/atproto/repo/strongRef'
45
43
  import * as ComAtprotoRepoUploadBlob from './types/com/atproto/repo/uploadBlob'
46
44
  import * as ComAtprotoServerCreateAccount from './types/com/atproto/server/createAccount'
@@ -63,8 +61,8 @@ import * as ComAtprotoServerRevokeAppPassword from './types/com/atproto/server/r
63
61
  import * as ComAtprotoSyncGetBlob from './types/com/atproto/sync/getBlob'
64
62
  import * as ComAtprotoSyncGetBlocks from './types/com/atproto/sync/getBlocks'
65
63
  import * as ComAtprotoSyncGetCheckout from './types/com/atproto/sync/getCheckout'
66
- import * as ComAtprotoSyncGetCommitPath from './types/com/atproto/sync/getCommitPath'
67
64
  import * as ComAtprotoSyncGetHead from './types/com/atproto/sync/getHead'
65
+ import * as ComAtprotoSyncGetLatestCommit from './types/com/atproto/sync/getLatestCommit'
68
66
  import * as ComAtprotoSyncGetRecord from './types/com/atproto/sync/getRecord'
69
67
  import * as ComAtprotoSyncGetRepo from './types/com/atproto/sync/getRepo'
70
68
  import * as ComAtprotoSyncListBlobs from './types/com/atproto/sync/listBlobs'
@@ -72,6 +70,7 @@ import * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
72
70
  import * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
73
71
  import * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
74
72
  import * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
73
+ import * as ComAtprotoTempUpgradeRepoVersion from './types/com/atproto/temp/upgradeRepoVersion'
75
74
  import * as AppBskyActorDefs from './types/app/bsky/actor/defs'
76
75
  import * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
77
76
  import * as AppBskyActorGetProfile from './types/app/bsky/actor/getProfile'
@@ -140,7 +139,6 @@ export * as ComAtprotoAdminGetModerationReport from './types/com/atproto/admin/g
140
139
  export * as ComAtprotoAdminGetModerationReports from './types/com/atproto/admin/getModerationReports'
141
140
  export * as ComAtprotoAdminGetRecord from './types/com/atproto/admin/getRecord'
142
141
  export * as ComAtprotoAdminGetRepo from './types/com/atproto/admin/getRepo'
143
- export * as ComAtprotoAdminRebaseRepo from './types/com/atproto/admin/rebaseRepo'
144
142
  export * as ComAtprotoAdminResolveModerationReports from './types/com/atproto/admin/resolveModerationReports'
145
143
  export * as ComAtprotoAdminReverseModerationAction from './types/com/atproto/admin/reverseModerationAction'
146
144
  export * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRepos'
@@ -162,7 +160,6 @@ export * as ComAtprotoRepoDescribeRepo from './types/com/atproto/repo/describeRe
162
160
  export * as ComAtprotoRepoGetRecord from './types/com/atproto/repo/getRecord'
163
161
  export * as ComAtprotoRepoListRecords from './types/com/atproto/repo/listRecords'
164
162
  export * as ComAtprotoRepoPutRecord from './types/com/atproto/repo/putRecord'
165
- export * as ComAtprotoRepoRebaseRepo from './types/com/atproto/repo/rebaseRepo'
166
163
  export * as ComAtprotoRepoStrongRef from './types/com/atproto/repo/strongRef'
167
164
  export * as ComAtprotoRepoUploadBlob from './types/com/atproto/repo/uploadBlob'
168
165
  export * as ComAtprotoServerCreateAccount from './types/com/atproto/server/createAccount'
@@ -185,8 +182,8 @@ export * as ComAtprotoServerRevokeAppPassword from './types/com/atproto/server/r
185
182
  export * as ComAtprotoSyncGetBlob from './types/com/atproto/sync/getBlob'
186
183
  export * as ComAtprotoSyncGetBlocks from './types/com/atproto/sync/getBlocks'
187
184
  export * as ComAtprotoSyncGetCheckout from './types/com/atproto/sync/getCheckout'
188
- export * as ComAtprotoSyncGetCommitPath from './types/com/atproto/sync/getCommitPath'
189
185
  export * as ComAtprotoSyncGetHead from './types/com/atproto/sync/getHead'
186
+ export * as ComAtprotoSyncGetLatestCommit from './types/com/atproto/sync/getLatestCommit'
190
187
  export * as ComAtprotoSyncGetRecord from './types/com/atproto/sync/getRecord'
191
188
  export * as ComAtprotoSyncGetRepo from './types/com/atproto/sync/getRepo'
192
189
  export * as ComAtprotoSyncListBlobs from './types/com/atproto/sync/listBlobs'
@@ -194,6 +191,7 @@ export * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
194
191
  export * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
195
192
  export * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
196
193
  export * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
194
+ export * as ComAtprotoTempUpgradeRepoVersion from './types/com/atproto/temp/upgradeRepoVersion'
197
195
  export * as AppBskyActorDefs from './types/app/bsky/actor/defs'
198
196
  export * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
199
197
  export * as AppBskyActorGetProfile from './types/app/bsky/actor/getProfile'
@@ -318,6 +316,7 @@ export class AtprotoNS {
318
316
  repo: RepoNS
319
317
  server: ServerNS
320
318
  sync: SyncNS
319
+ temp: TempNS
321
320
 
322
321
  constructor(service: AtpServiceClient) {
323
322
  this._service = service
@@ -328,6 +327,7 @@ export class AtprotoNS {
328
327
  this.repo = new RepoNS(service)
329
328
  this.server = new ServerNS(service)
330
329
  this.sync = new SyncNS(service)
330
+ this.temp = new TempNS(service)
331
331
  }
332
332
  }
333
333
 
@@ -448,17 +448,6 @@ export class AdminNS {
448
448
  })
449
449
  }
450
450
 
451
- rebaseRepo(
452
- data?: ComAtprotoAdminRebaseRepo.InputSchema,
453
- opts?: ComAtprotoAdminRebaseRepo.CallOptions,
454
- ): Promise<ComAtprotoAdminRebaseRepo.Response> {
455
- return this._service.xrpc
456
- .call('com.atproto.admin.rebaseRepo', opts?.qp, data, opts)
457
- .catch((e) => {
458
- throw ComAtprotoAdminRebaseRepo.toKnownErr(e)
459
- })
460
- }
461
-
462
451
  resolveModerationReports(
463
452
  data?: ComAtprotoAdminResolveModerationReports.InputSchema,
464
453
  opts?: ComAtprotoAdminResolveModerationReports.CallOptions,
@@ -689,17 +678,6 @@ export class RepoNS {
689
678
  })
690
679
  }
691
680
 
692
- rebaseRepo(
693
- data?: ComAtprotoRepoRebaseRepo.InputSchema,
694
- opts?: ComAtprotoRepoRebaseRepo.CallOptions,
695
- ): Promise<ComAtprotoRepoRebaseRepo.Response> {
696
- return this._service.xrpc
697
- .call('com.atproto.repo.rebaseRepo', opts?.qp, data, opts)
698
- .catch((e) => {
699
- throw ComAtprotoRepoRebaseRepo.toKnownErr(e)
700
- })
701
- }
702
-
703
681
  uploadBlob(
704
682
  data?: ComAtprotoRepoUploadBlob.InputSchema,
705
683
  opts?: ComAtprotoRepoUploadBlob.CallOptions,
@@ -936,17 +914,6 @@ export class SyncNS {
936
914
  })
937
915
  }
938
916
 
939
- getCommitPath(
940
- params?: ComAtprotoSyncGetCommitPath.QueryParams,
941
- opts?: ComAtprotoSyncGetCommitPath.CallOptions,
942
- ): Promise<ComAtprotoSyncGetCommitPath.Response> {
943
- return this._service.xrpc
944
- .call('com.atproto.sync.getCommitPath', params, undefined, opts)
945
- .catch((e) => {
946
- throw ComAtprotoSyncGetCommitPath.toKnownErr(e)
947
- })
948
- }
949
-
950
917
  getHead(
951
918
  params?: ComAtprotoSyncGetHead.QueryParams,
952
919
  opts?: ComAtprotoSyncGetHead.CallOptions,
@@ -958,6 +925,17 @@ export class SyncNS {
958
925
  })
959
926
  }
960
927
 
928
+ getLatestCommit(
929
+ params?: ComAtprotoSyncGetLatestCommit.QueryParams,
930
+ opts?: ComAtprotoSyncGetLatestCommit.CallOptions,
931
+ ): Promise<ComAtprotoSyncGetLatestCommit.Response> {
932
+ return this._service.xrpc
933
+ .call('com.atproto.sync.getLatestCommit', params, undefined, opts)
934
+ .catch((e) => {
935
+ throw ComAtprotoSyncGetLatestCommit.toKnownErr(e)
936
+ })
937
+ }
938
+
961
939
  getRecord(
962
940
  params?: ComAtprotoSyncGetRecord.QueryParams,
963
941
  opts?: ComAtprotoSyncGetRecord.CallOptions,
@@ -1025,6 +1003,25 @@ export class SyncNS {
1025
1003
  }
1026
1004
  }
1027
1005
 
1006
+ export class TempNS {
1007
+ _service: AtpServiceClient
1008
+
1009
+ constructor(service: AtpServiceClient) {
1010
+ this._service = service
1011
+ }
1012
+
1013
+ upgradeRepoVersion(
1014
+ data?: ComAtprotoTempUpgradeRepoVersion.InputSchema,
1015
+ opts?: ComAtprotoTempUpgradeRepoVersion.CallOptions,
1016
+ ): Promise<ComAtprotoTempUpgradeRepoVersion.Response> {
1017
+ return this._service.xrpc
1018
+ .call('com.atproto.temp.upgradeRepoVersion', opts?.qp, data, opts)
1019
+ .catch((e) => {
1020
+ throw ComAtprotoTempUpgradeRepoVersion.toKnownErr(e)
1021
+ })
1022
+ }
1023
+ }
1024
+
1028
1025
  export class AppNS {
1029
1026
  _service: AtpServiceClient
1030
1027
  bsky: BskyNS