@atproto/api 0.12.4 → 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.
@@ -132,6 +132,7 @@ export type Preferences = (
132
132
  | AdultContentPref
133
133
  | ContentLabelPref
134
134
  | SavedFeedsPref
135
+ | SavedFeedsPrefV2
135
136
  | PersonalDetailsPref
136
137
  | FeedViewPref
137
138
  | ThreadViewPref
@@ -178,6 +179,43 @@ export function validateContentLabelPref(v: unknown): ValidationResult {
178
179
  return lexicons.validate('app.bsky.actor.defs#contentLabelPref', v)
179
180
  }
180
181
 
182
+ export interface SavedFeed {
183
+ id: string
184
+ type: 'feed' | 'list' | 'timeline' | (string & {})
185
+ value: string
186
+ pinned: boolean
187
+ [k: string]: unknown
188
+ }
189
+
190
+ export function isSavedFeed(v: unknown): v is SavedFeed {
191
+ return (
192
+ isObj(v) &&
193
+ hasProp(v, '$type') &&
194
+ v.$type === 'app.bsky.actor.defs#savedFeed'
195
+ )
196
+ }
197
+
198
+ export function validateSavedFeed(v: unknown): ValidationResult {
199
+ return lexicons.validate('app.bsky.actor.defs#savedFeed', v)
200
+ }
201
+
202
+ export interface SavedFeedsPrefV2 {
203
+ items: SavedFeed[]
204
+ [k: string]: unknown
205
+ }
206
+
207
+ export function isSavedFeedsPrefV2(v: unknown): v is SavedFeedsPrefV2 {
208
+ return (
209
+ isObj(v) &&
210
+ hasProp(v, '$type') &&
211
+ v.$type === 'app.bsky.actor.defs#savedFeedsPrefV2'
212
+ )
213
+ }
214
+
215
+ export function validateSavedFeedsPrefV2(v: unknown): ValidationResult {
216
+ return lexicons.validate('app.bsky.actor.defs#savedFeedsPrefV2', v)
217
+ }
218
+
181
219
  export interface SavedFeedsPref {
182
220
  pinned: string[]
183
221
  saved: string[]
package/src/types.ts CHANGED
@@ -26,6 +26,7 @@ export interface AtpSessionData {
26
26
  did: string
27
27
  email?: string
28
28
  emailConfirmed?: boolean
29
+ emailAuthFactor?: boolean
29
30
  }
30
31
 
31
32
  /**
@@ -50,6 +51,7 @@ export interface AtpAgentOpts {
50
51
  export interface AtpAgentLoginOpts {
51
52
  identifier: string
52
53
  password: string
54
+ authFactorToken?: string | undefined
53
55
  }
54
56
 
55
57
  /**
@@ -110,10 +112,14 @@ export interface BskyInterestsPreference {
110
112
  * Bluesky preferences
111
113
  */
112
114
  export interface BskyPreferences {
115
+ /**
116
+ * @deprecated use `savedFeeds`
117
+ */
113
118
  feeds: {
114
119
  saved?: string[]
115
120
  pinned?: string[]
116
121
  }
122
+ savedFeeds: AppBskyActorDefs.SavedFeed[]
117
123
  feedViewPrefs: Record<string, BskyFeedViewPreference>
118
124
  threadViewPrefs: BskyThreadViewPreference
119
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
+ }