@atproto/api 0.12.5 → 0.12.6
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 +8 -0
- package/dist/bsky-agent.d.ts +19 -0
- package/dist/bsky-agent.d.ts.map +1 -1
- package/dist/bsky-agent.js +179 -0
- package/dist/bsky-agent.js.map +1 -1
- package/dist/client/lexicons.d.ts +32 -0
- package/dist/client/lexicons.d.ts.map +1 -1
- package/dist/client/lexicons.js +33 -0
- package/dist/client/lexicons.js.map +1 -1
- package/dist/client/types/app/bsky/actor/defs.d.ts +16 -1
- package/dist/client/types/app/bsky/actor/defs.d.ts.map +1 -1
- package/dist/client/types/app/bsky/actor/defs.js +21 -1
- package/dist/client/types/app/bsky/actor/defs.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/util.d.ts +13 -0
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +55 -1
- package/dist/util.js.map +1 -1
- package/package.json +2 -2
- package/src/bsky-agent.ts +222 -1
- package/src/client/lexicons.ts +33 -0
- package/src/client/types/app/bsky/actor/defs.ts +38 -0
- package/src/types.ts +4 -0
- package/src/util.ts +72 -0
- package/tests/bsky-agent.test.ts +1021 -2
- package/tests/moderation-prefs.test.ts +4 -0
package/src/types.ts
CHANGED
|
@@ -112,10 +112,14 @@ export interface BskyInterestsPreference {
|
|
|
112
112
|
* Bluesky preferences
|
|
113
113
|
*/
|
|
114
114
|
export interface BskyPreferences {
|
|
115
|
+
/**
|
|
116
|
+
* @deprecated use `savedFeeds`
|
|
117
|
+
*/
|
|
115
118
|
feeds: {
|
|
116
119
|
saved?: string[]
|
|
117
120
|
pinned?: string[]
|
|
118
121
|
}
|
|
122
|
+
savedFeeds: AppBskyActorDefs.SavedFeed[]
|
|
119
123
|
feedViewPrefs: Record<string, BskyFeedViewPreference>
|
|
120
124
|
threadViewPrefs: BskyThreadViewPreference
|
|
121
125
|
moderationPrefs: ModerationPrefs
|
package/src/util.ts
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
|
+
import { AtUri } from '@atproto/syntax'
|
|
2
|
+
import { TID } from '@atproto/common-web'
|
|
3
|
+
|
|
4
|
+
import { AppBskyActorDefs } from './client'
|
|
5
|
+
|
|
1
6
|
export function sanitizeMutedWordValue(value: string) {
|
|
2
7
|
return value
|
|
3
8
|
.trim()
|
|
4
9
|
.replace(/^#(?!\ufe0f)/, '')
|
|
5
10
|
.replace(/[\r\n\u00AD\u2060\u200D\u200C\u200B]+/, '')
|
|
6
11
|
}
|
|
12
|
+
|
|
13
|
+
export function savedFeedsToUriArrays(
|
|
14
|
+
savedFeeds: AppBskyActorDefs.SavedFeed[],
|
|
15
|
+
): {
|
|
16
|
+
pinned: string[]
|
|
17
|
+
saved: string[]
|
|
18
|
+
} {
|
|
19
|
+
const pinned: string[] = []
|
|
20
|
+
const saved: string[] = []
|
|
21
|
+
|
|
22
|
+
for (const feed of savedFeeds) {
|
|
23
|
+
if (feed.pinned) {
|
|
24
|
+
pinned.push(feed.value)
|
|
25
|
+
// saved in v1 includes pinned
|
|
26
|
+
saved.push(feed.value)
|
|
27
|
+
} else {
|
|
28
|
+
saved.push(feed.value)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
pinned,
|
|
34
|
+
saved,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get the type of a saved feed, used by deprecated methods for backwards
|
|
40
|
+
* compat. Should not be used moving forward. *Invalid URIs will throw.*
|
|
41
|
+
*
|
|
42
|
+
* @param uri - The AT URI of the saved feed
|
|
43
|
+
*/
|
|
44
|
+
export function getSavedFeedType(
|
|
45
|
+
uri: string,
|
|
46
|
+
): AppBskyActorDefs.SavedFeed['type'] {
|
|
47
|
+
const urip = new AtUri(uri)
|
|
48
|
+
|
|
49
|
+
switch (urip.collection) {
|
|
50
|
+
case 'app.bsky.feed.generator':
|
|
51
|
+
return 'feed'
|
|
52
|
+
case 'app.bsky.graph.list':
|
|
53
|
+
return 'list'
|
|
54
|
+
default:
|
|
55
|
+
return 'unknown'
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function validateSavedFeed(savedFeed: AppBskyActorDefs.SavedFeed) {
|
|
60
|
+
new TID(savedFeed.id)
|
|
61
|
+
|
|
62
|
+
if (['feed', 'list'].includes(savedFeed.type)) {
|
|
63
|
+
const uri = new AtUri(savedFeed.value)
|
|
64
|
+
const isFeed = uri.collection === 'app.bsky.feed.generator'
|
|
65
|
+
const isList = uri.collection === 'app.bsky.graph.list'
|
|
66
|
+
|
|
67
|
+
if (savedFeed.type === 'feed' && !isFeed) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Saved feed of type 'feed' must be a feed, got ${uri.collection}`,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
if (savedFeed.type === 'list' && !isList) {
|
|
73
|
+
throw new Error(
|
|
74
|
+
`Saved feed of type 'list' must be a list, got ${uri.collection}`,
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|