@atproto/api 0.6.13 → 0.6.15
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/CHANGELOG.md +15 -0
- package/LICENSE +1 -1
- package/dist/bsky-agent.d.ts +3 -1
- package/dist/client/lexicons.d.ts +46 -0
- package/dist/client/types/app/bsky/actor/defs.d.ts +19 -1
- package/dist/client/types/app/bsky/feed/threadgate.d.ts +2 -0
- package/dist/index.js +109 -4
- package/dist/index.js.map +2 -2
- package/dist/types.d.ts +3 -0
- package/package.json +6 -6
- package/src/bsky-agent.ts +70 -0
- package/src/client/lexicons.ts +51 -0
- package/src/client/types/app/bsky/actor/defs.ts +50 -0
- package/src/client/types/app/bsky/feed/threadgate.ts +6 -2
- package/src/types.ts +3 -0
- package/tests/bsky-agent.test.ts +491 -17
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LabelPreference } from './moderation/types';
|
|
2
|
+
import { AppBskyActorDefs } from './client';
|
|
2
3
|
export declare type AtpSessionEvent = 'create' | 'create-failed' | 'update' | 'expired';
|
|
3
4
|
export interface AtpSessionData {
|
|
4
5
|
refreshJwt: string;
|
|
@@ -38,6 +39,8 @@ export interface BskyPreferences {
|
|
|
38
39
|
saved?: string[];
|
|
39
40
|
pinned?: string[];
|
|
40
41
|
};
|
|
42
|
+
feedViewPrefs: Record<string, Omit<AppBskyActorDefs.FeedViewPref, '$type'>>;
|
|
43
|
+
threadViewPrefs: Omit<AppBskyActorDefs.ThreadViewPref, '$type'>;
|
|
41
44
|
adultContentEnabled: boolean;
|
|
42
45
|
contentLabels: Record<string, BskyLabelPreference>;
|
|
43
46
|
birthDate: Date | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/api",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.15",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,14 +13,14 @@
|
|
|
13
13
|
"tlds": "^1.234.0",
|
|
14
14
|
"typed-emitter": "^2.1.0",
|
|
15
15
|
"@atproto/common-web": "^0.2.0",
|
|
16
|
-
"@atproto/lexicon": "^0.2.
|
|
17
|
-
"@atproto/syntax": "^0.1.
|
|
18
|
-
"@atproto/xrpc": "^0.3.
|
|
16
|
+
"@atproto/lexicon": "^0.2.1",
|
|
17
|
+
"@atproto/syntax": "^0.1.1",
|
|
18
|
+
"@atproto/xrpc": "^0.3.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"common-tags": "^1.8.2",
|
|
22
|
-
"@atproto/lex-cli": "^0.2.
|
|
23
|
-
"@atproto/pds": "^0.1.
|
|
22
|
+
"@atproto/lex-cli": "^0.2.1",
|
|
23
|
+
"@atproto/pds": "^0.1.15"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"codegen": "pnpm docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
|
package/src/bsky-agent.ts
CHANGED
|
@@ -8,6 +8,18 @@ import {
|
|
|
8
8
|
} from './client'
|
|
9
9
|
import { BskyPreferences, BskyLabelPreference } from './types'
|
|
10
10
|
|
|
11
|
+
const FEED_VIEW_PREF_DEFAULTS = {
|
|
12
|
+
hideReplies: false,
|
|
13
|
+
hideRepliesByUnfollowed: false,
|
|
14
|
+
hideRepliesByLikeCount: 0,
|
|
15
|
+
hideReposts: false,
|
|
16
|
+
hideQuotePosts: false,
|
|
17
|
+
}
|
|
18
|
+
const THREAD_VIEW_PREF_DEFAULTS = {
|
|
19
|
+
sort: 'oldest',
|
|
20
|
+
prioritizeFollowedUsers: true,
|
|
21
|
+
}
|
|
22
|
+
|
|
11
23
|
declare global {
|
|
12
24
|
interface Array<T> {
|
|
13
25
|
findLast(
|
|
@@ -254,6 +266,12 @@ export class BskyAgent extends AtpAgent {
|
|
|
254
266
|
saved: undefined,
|
|
255
267
|
pinned: undefined,
|
|
256
268
|
},
|
|
269
|
+
feedViewPrefs: {
|
|
270
|
+
home: {
|
|
271
|
+
...FEED_VIEW_PREF_DEFAULTS,
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
threadViewPrefs: { ...THREAD_VIEW_PREF_DEFAULTS },
|
|
257
275
|
adultContentEnabled: false,
|
|
258
276
|
contentLabels: {},
|
|
259
277
|
birthDate: undefined,
|
|
@@ -289,6 +307,18 @@ export class BskyAgent extends AtpAgent {
|
|
|
289
307
|
if (pref.birthDate) {
|
|
290
308
|
prefs.birthDate = new Date(pref.birthDate)
|
|
291
309
|
}
|
|
310
|
+
} else if (
|
|
311
|
+
AppBskyActorDefs.isFeedViewPref(pref) &&
|
|
312
|
+
AppBskyActorDefs.validateFeedViewPref(pref).success
|
|
313
|
+
) {
|
|
314
|
+
const { $type, feed, ...v } = pref
|
|
315
|
+
prefs.feedViewPrefs[pref.feed] = { ...FEED_VIEW_PREF_DEFAULTS, ...v }
|
|
316
|
+
} else if (
|
|
317
|
+
AppBskyActorDefs.isThreadViewPref(pref) &&
|
|
318
|
+
AppBskyActorDefs.validateThreadViewPref(pref).success
|
|
319
|
+
) {
|
|
320
|
+
const { $type, ...v } = pref
|
|
321
|
+
prefs.threadViewPrefs = { ...prefs.threadViewPrefs, ...v }
|
|
292
322
|
}
|
|
293
323
|
}
|
|
294
324
|
return prefs
|
|
@@ -406,6 +436,46 @@ export class BskyAgent extends AtpAgent {
|
|
|
406
436
|
.concat([personalDetailsPref])
|
|
407
437
|
})
|
|
408
438
|
}
|
|
439
|
+
|
|
440
|
+
async setFeedViewPrefs(
|
|
441
|
+
feed: string,
|
|
442
|
+
pref: Omit<AppBskyActorDefs.FeedViewPref, '$type' | 'feed'>,
|
|
443
|
+
) {
|
|
444
|
+
await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => {
|
|
445
|
+
const existing = prefs.findLast(
|
|
446
|
+
(pref) =>
|
|
447
|
+
AppBskyActorDefs.isFeedViewPref(pref) &&
|
|
448
|
+
AppBskyActorDefs.validateFeedViewPref(pref).success &&
|
|
449
|
+
pref.feed === feed,
|
|
450
|
+
)
|
|
451
|
+
if (existing) {
|
|
452
|
+
pref = { ...existing, ...pref }
|
|
453
|
+
}
|
|
454
|
+
return prefs
|
|
455
|
+
.filter(
|
|
456
|
+
(p) => !AppBskyActorDefs.isFeedViewPref(pref) || p.feed !== feed,
|
|
457
|
+
)
|
|
458
|
+
.concat([{ ...pref, $type: 'app.bsky.actor.defs#feedViewPref', feed }])
|
|
459
|
+
})
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
async setThreadViewPrefs(
|
|
463
|
+
pref: Omit<AppBskyActorDefs.ThreadViewPref, '$type'>,
|
|
464
|
+
) {
|
|
465
|
+
await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => {
|
|
466
|
+
const existing = prefs.findLast(
|
|
467
|
+
(pref) =>
|
|
468
|
+
AppBskyActorDefs.isThreadViewPref(pref) &&
|
|
469
|
+
AppBskyActorDefs.validateThreadViewPref(pref).success,
|
|
470
|
+
)
|
|
471
|
+
if (existing) {
|
|
472
|
+
pref = { ...existing, ...pref }
|
|
473
|
+
}
|
|
474
|
+
return prefs
|
|
475
|
+
.filter((p) => !AppBskyActorDefs.isThreadViewPref(p))
|
|
476
|
+
.concat([{ ...pref, $type: 'app.bsky.actor.defs#threadViewPref' }])
|
|
477
|
+
})
|
|
478
|
+
}
|
|
409
479
|
}
|
|
410
480
|
|
|
411
481
|
/**
|
package/src/client/lexicons.ts
CHANGED
|
@@ -3687,6 +3687,8 @@ export const schemaDict = {
|
|
|
3687
3687
|
'lex:app.bsky.actor.defs#contentLabelPref',
|
|
3688
3688
|
'lex:app.bsky.actor.defs#savedFeedsPref',
|
|
3689
3689
|
'lex:app.bsky.actor.defs#personalDetailsPref',
|
|
3690
|
+
'lex:app.bsky.actor.defs#feedViewPref',
|
|
3691
|
+
'lex:app.bsky.actor.defs#threadViewPref',
|
|
3690
3692
|
],
|
|
3691
3693
|
},
|
|
3692
3694
|
},
|
|
@@ -3743,6 +3745,53 @@ export const schemaDict = {
|
|
|
3743
3745
|
},
|
|
3744
3746
|
},
|
|
3745
3747
|
},
|
|
3748
|
+
feedViewPref: {
|
|
3749
|
+
type: 'object',
|
|
3750
|
+
required: ['feed'],
|
|
3751
|
+
properties: {
|
|
3752
|
+
feed: {
|
|
3753
|
+
type: 'string',
|
|
3754
|
+
description:
|
|
3755
|
+
'The URI of the feed, or an identifier which describes the feed.',
|
|
3756
|
+
},
|
|
3757
|
+
hideReplies: {
|
|
3758
|
+
type: 'boolean',
|
|
3759
|
+
description: 'Hide replies in the feed.',
|
|
3760
|
+
},
|
|
3761
|
+
hideRepliesByUnfollowed: {
|
|
3762
|
+
type: 'boolean',
|
|
3763
|
+
description:
|
|
3764
|
+
'Hide replies in the feed if they are not by followed users.',
|
|
3765
|
+
},
|
|
3766
|
+
hideRepliesByLikeCount: {
|
|
3767
|
+
type: 'integer',
|
|
3768
|
+
description:
|
|
3769
|
+
'Hide replies in the feed if they do not have this number of likes.',
|
|
3770
|
+
},
|
|
3771
|
+
hideReposts: {
|
|
3772
|
+
type: 'boolean',
|
|
3773
|
+
description: 'Hide reposts in the feed.',
|
|
3774
|
+
},
|
|
3775
|
+
hideQuotePosts: {
|
|
3776
|
+
type: 'boolean',
|
|
3777
|
+
description: 'Hide quote posts in the feed.',
|
|
3778
|
+
},
|
|
3779
|
+
},
|
|
3780
|
+
},
|
|
3781
|
+
threadViewPref: {
|
|
3782
|
+
type: 'object',
|
|
3783
|
+
properties: {
|
|
3784
|
+
sort: {
|
|
3785
|
+
type: 'string',
|
|
3786
|
+
description: 'Sorting mode.',
|
|
3787
|
+
knownValues: ['oldest', 'newest', 'most-likes', 'random'],
|
|
3788
|
+
},
|
|
3789
|
+
prioritizeFollowedUsers: {
|
|
3790
|
+
type: 'boolean',
|
|
3791
|
+
description: 'Show followed users at the top of all replies.',
|
|
3792
|
+
},
|
|
3793
|
+
},
|
|
3794
|
+
},
|
|
3746
3795
|
},
|
|
3747
3796
|
},
|
|
3748
3797
|
AppBskyActorGetPreferences: {
|
|
@@ -5693,10 +5742,12 @@ export const schemaDict = {
|
|
|
5693
5742
|
mentionRule: {
|
|
5694
5743
|
type: 'object',
|
|
5695
5744
|
description: 'Allow replies from actors mentioned in your post.',
|
|
5745
|
+
properties: {},
|
|
5696
5746
|
},
|
|
5697
5747
|
followingRule: {
|
|
5698
5748
|
type: 'object',
|
|
5699
5749
|
description: 'Allow replies from actors you follow.',
|
|
5750
|
+
properties: {},
|
|
5700
5751
|
},
|
|
5701
5752
|
listRule: {
|
|
5702
5753
|
type: 'object',
|
|
@@ -109,6 +109,8 @@ export type Preferences = (
|
|
|
109
109
|
| ContentLabelPref
|
|
110
110
|
| SavedFeedsPref
|
|
111
111
|
| PersonalDetailsPref
|
|
112
|
+
| FeedViewPref
|
|
113
|
+
| ThreadViewPref
|
|
112
114
|
| { $type: string; [k: string]: unknown }
|
|
113
115
|
)[]
|
|
114
116
|
|
|
@@ -182,3 +184,51 @@ export function isPersonalDetailsPref(v: unknown): v is PersonalDetailsPref {
|
|
|
182
184
|
export function validatePersonalDetailsPref(v: unknown): ValidationResult {
|
|
183
185
|
return lexicons.validate('app.bsky.actor.defs#personalDetailsPref', v)
|
|
184
186
|
}
|
|
187
|
+
|
|
188
|
+
export interface FeedViewPref {
|
|
189
|
+
/** The URI of the feed, or an identifier which describes the feed. */
|
|
190
|
+
feed: string
|
|
191
|
+
/** Hide replies in the feed. */
|
|
192
|
+
hideReplies?: boolean
|
|
193
|
+
/** Hide replies in the feed if they are not by followed users. */
|
|
194
|
+
hideRepliesByUnfollowed?: boolean
|
|
195
|
+
/** Hide replies in the feed if they do not have this number of likes. */
|
|
196
|
+
hideRepliesByLikeCount?: number
|
|
197
|
+
/** Hide reposts in the feed. */
|
|
198
|
+
hideReposts?: boolean
|
|
199
|
+
/** Hide quote posts in the feed. */
|
|
200
|
+
hideQuotePosts?: boolean
|
|
201
|
+
[k: string]: unknown
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function isFeedViewPref(v: unknown): v is FeedViewPref {
|
|
205
|
+
return (
|
|
206
|
+
isObj(v) &&
|
|
207
|
+
hasProp(v, '$type') &&
|
|
208
|
+
v.$type === 'app.bsky.actor.defs#feedViewPref'
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function validateFeedViewPref(v: unknown): ValidationResult {
|
|
213
|
+
return lexicons.validate('app.bsky.actor.defs#feedViewPref', v)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface ThreadViewPref {
|
|
217
|
+
/** Sorting mode. */
|
|
218
|
+
sort?: 'oldest' | 'newest' | 'most-likes' | 'random' | (string & {})
|
|
219
|
+
/** Show followed users at the top of all replies. */
|
|
220
|
+
prioritizeFollowedUsers?: boolean
|
|
221
|
+
[k: string]: unknown
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function isThreadViewPref(v: unknown): v is ThreadViewPref {
|
|
225
|
+
return (
|
|
226
|
+
isObj(v) &&
|
|
227
|
+
hasProp(v, '$type') &&
|
|
228
|
+
v.$type === 'app.bsky.actor.defs#threadViewPref'
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function validateThreadViewPref(v: unknown): ValidationResult {
|
|
233
|
+
return lexicons.validate('app.bsky.actor.defs#threadViewPref', v)
|
|
234
|
+
}
|
|
@@ -32,7 +32,9 @@ export function validateRecord(v: unknown): ValidationResult {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/** Allow replies from actors mentioned in your post. */
|
|
35
|
-
export interface MentionRule {
|
|
35
|
+
export interface MentionRule {
|
|
36
|
+
[k: string]: unknown
|
|
37
|
+
}
|
|
36
38
|
|
|
37
39
|
export function isMentionRule(v: unknown): v is MentionRule {
|
|
38
40
|
return (
|
|
@@ -47,7 +49,9 @@ export function validateMentionRule(v: unknown): ValidationResult {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/** Allow replies from actors you follow. */
|
|
50
|
-
export interface FollowingRule {
|
|
52
|
+
export interface FollowingRule {
|
|
53
|
+
[k: string]: unknown
|
|
54
|
+
}
|
|
51
55
|
|
|
52
56
|
export function isFollowingRule(v: unknown): v is FollowingRule {
|
|
53
57
|
return (
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LabelPreference } from './moderation/types'
|
|
2
|
+
import { AppBskyActorDefs } from './client'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Used by the PersistSessionHandler to indicate what change occurred
|
|
@@ -87,6 +88,8 @@ export interface BskyPreferences {
|
|
|
87
88
|
saved?: string[]
|
|
88
89
|
pinned?: string[]
|
|
89
90
|
}
|
|
91
|
+
feedViewPrefs: Record<string, Omit<AppBskyActorDefs.FeedViewPref, '$type'>>
|
|
92
|
+
threadViewPrefs: Omit<AppBskyActorDefs.ThreadViewPref, '$type'>
|
|
90
93
|
adultContentEnabled: boolean
|
|
91
94
|
contentLabels: Record<string, BskyLabelPreference>
|
|
92
95
|
birthDate: Date | undefined
|