@atproto/api 0.6.7 → 0.6.9
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/build.js +8 -0
- package/dist/agent.d.ts +25 -44
- package/dist/bsky-agent.d.ts +24 -0
- package/dist/client/index.d.ts +14 -9
- package/dist/client/lexicons.d.ts +103 -100
- package/dist/client/types/app/bsky/actor/defs.d.ts +65 -74
- package/dist/client/types/app/bsky/actor/getFeedSuggestions.d.ts +21 -0
- package/dist/client/types/app/bsky/embed/external.d.ts +23 -23
- package/dist/client/types/app/bsky/embed/images.d.ts +20 -20
- package/dist/client/types/app/bsky/embed/recordWithMedia.d.ts +20 -26
- package/dist/client/types/{com/atproto/sync/getCommitPath.d.ts → app/bsky/feed/getFeedSuggestions.d.ts} +5 -4
- package/dist/client/types/app/bsky/feed/getSuggestedFeeds.d.ts +21 -0
- package/dist/client/types/app/bsky/feed/like.d.ts +7 -7
- package/dist/client/types/app/bsky/feed/repost.d.ts +7 -7
- package/dist/client/types/app/bsky/graph/block.d.ts +6 -6
- package/dist/client/types/app/bsky/graph/defs.d.ts +36 -36
- package/dist/client/types/app/bsky/graph/follow.d.ts +6 -6
- package/dist/client/types/app/bsky/graph/listitem.d.ts +7 -7
- package/dist/client/types/app/bsky/richtext/facet.d.ts +22 -26
- package/dist/client/types/com/atproto/label/subscribeLabels.d.ts +12 -12
- package/dist/client/types/com/atproto/moderation/defs.d.ts +7 -16
- package/dist/client/types/com/atproto/repo/strongRef.d.ts +6 -6
- package/dist/client/types/com/atproto/server/defs.d.ts +16 -16
- package/dist/client/types/com/atproto/sync/getCheckout.d.ts +0 -1
- package/dist/client/types/com/atproto/{admin/rebaseRepo.d.ts → sync/getLatestCommit.d.ts} +7 -9
- package/dist/client/types/com/atproto/sync/getRepo.d.ts +1 -2
- package/dist/client/types/com/atproto/sync/listBlobs.d.ts +4 -2
- package/dist/client/types/com/atproto/sync/subscribeRepos.d.ts +48 -46
- package/dist/client/types/{app/bsky/unspecced/registerPushNotification.d.ts → com/atproto/temp/upgradeRepoVersion.d.ts} +7 -5
- package/dist/client/util.d.ts +2 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1651 -1277
- package/dist/index.js.map +4 -4
- package/dist/rich-text/detection.d.ts +4 -4
- package/dist/rich-text/rich-text.d.ts +31 -31
- package/dist/rich-text/sanitization.d.ts +4 -7
- package/dist/rich-text/unicode.d.ts +9 -9
- package/dist/types.d.ts +32 -34
- package/package.json +24 -23
- package/src/bsky-agent.ts +181 -1
- package/src/client/index.ts +49 -39
- package/src/client/lexicons.ts +123 -129
- package/src/client/types/{com/atproto/sync/getCommitPath.ts → app/bsky/feed/getSuggestedFeeds.ts} +5 -7
- package/src/client/types/com/atproto/sync/getCheckout.ts +0 -2
- package/src/client/types/com/atproto/{admin/rebaseRepo.ts → sync/getLatestCommit.ts} +12 -17
- package/src/client/types/com/atproto/sync/getRepo.ts +2 -4
- package/src/client/types/com/atproto/sync/listBlobs.ts +5 -4
- package/src/client/types/com/atproto/sync/subscribeRepos.ts +5 -1
- package/src/client/types/com/atproto/{repo/rebaseRepo.ts → temp/upgradeRepoVersion.ts} +2 -18
- package/src/index.ts +1 -1
- package/src/types.ts +20 -0
- package/tests/bsky-agent.test.ts +149 -0
- package/update-pkg.js +14 -0
- package/LICENSE +0 -21
- package/dist/client/types/com/atproto/repo/rebaseRepo.d.ts +0 -24
- package/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppBskyRichtextFacet } from '../client'
|
|
2
|
-
import { UnicodeString } from './unicode'
|
|
3
|
-
export declare type Facet = AppBskyRichtextFacet.Main
|
|
4
|
-
export declare function detectFacets(text: UnicodeString): Facet[] | undefined
|
|
1
|
+
import { AppBskyRichtextFacet } from '../client';
|
|
2
|
+
import { UnicodeString } from './unicode';
|
|
3
|
+
export declare type Facet = AppBskyRichtextFacet.Main;
|
|
4
|
+
export declare function detectFacets(text: UnicodeString): Facet[] | undefined;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { AtpAgent } from '../agent'
|
|
2
|
-
import { AppBskyFeedPost, AppBskyRichtextFacet } from '../client'
|
|
3
|
-
import { UnicodeString } from './unicode'
|
|
4
|
-
export declare type Facet = AppBskyRichtextFacet.Main
|
|
5
|
-
export declare type FacetLink = AppBskyRichtextFacet.Link
|
|
6
|
-
export declare type FacetMention = AppBskyRichtextFacet.Mention
|
|
7
|
-
export declare type Entity = AppBskyFeedPost.Entity
|
|
1
|
+
import { AtpAgent } from '../agent';
|
|
2
|
+
import { AppBskyFeedPost, AppBskyRichtextFacet } from '../client';
|
|
3
|
+
import { UnicodeString } from './unicode';
|
|
4
|
+
export declare type Facet = AppBskyRichtextFacet.Main;
|
|
5
|
+
export declare type FacetLink = AppBskyRichtextFacet.Link;
|
|
6
|
+
export declare type FacetMention = AppBskyRichtextFacet.Mention;
|
|
7
|
+
export declare type Entity = AppBskyFeedPost.Entity;
|
|
8
8
|
export interface RichTextProps {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
text: string;
|
|
10
|
+
facets?: Facet[];
|
|
11
|
+
entities?: Entity[];
|
|
12
12
|
}
|
|
13
13
|
export interface RichTextOpts {
|
|
14
|
-
|
|
14
|
+
cleanNewlines?: boolean;
|
|
15
15
|
}
|
|
16
16
|
export declare class RichTextSegment {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
text: string;
|
|
18
|
+
facet?: AppBskyRichtextFacet.Main | undefined;
|
|
19
|
+
constructor(text: string, facet?: AppBskyRichtextFacet.Main | undefined);
|
|
20
|
+
get link(): FacetLink | undefined;
|
|
21
|
+
isLink(): boolean;
|
|
22
|
+
get mention(): FacetMention | undefined;
|
|
23
|
+
isMention(): boolean;
|
|
24
24
|
}
|
|
25
25
|
export declare class RichText {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
unicodeText: UnicodeString;
|
|
27
|
+
facets?: Facet[];
|
|
28
|
+
constructor(props: RichTextProps, opts?: RichTextOpts);
|
|
29
|
+
get text(): string;
|
|
30
|
+
get length(): number;
|
|
31
|
+
get graphemeLength(): number;
|
|
32
|
+
clone(): RichText;
|
|
33
|
+
copyInto(target: RichText): void;
|
|
34
|
+
segments(): Generator<RichTextSegment, void, void>;
|
|
35
|
+
insert(insertIndex: number, insertText: string): this;
|
|
36
|
+
delete(removeStartIndex: number, removeEndIndex: number): this;
|
|
37
|
+
detectFacets(agent: AtpAgent): Promise<void>;
|
|
38
|
+
detectFacetsWithoutResolution(): void;
|
|
39
39
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { RichText } from './rich-text'
|
|
2
|
-
export declare function sanitizeRichText(
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
cleanNewlines?: boolean
|
|
6
|
-
},
|
|
7
|
-
): RichText
|
|
1
|
+
import { RichText } from './rich-text';
|
|
2
|
+
export declare function sanitizeRichText(richText: RichText, opts: {
|
|
3
|
+
cleanNewlines?: boolean;
|
|
4
|
+
}): RichText;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare class UnicodeString {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
utf16: string;
|
|
3
|
+
utf8: Uint8Array;
|
|
4
|
+
private _graphemeLen?;
|
|
5
|
+
constructor(utf16: string);
|
|
6
|
+
get length(): number;
|
|
7
|
+
get graphemeLength(): number;
|
|
8
|
+
slice(start?: number, end?: number): string;
|
|
9
|
+
utf16IndexToUtf8Index(i: number): number;
|
|
10
|
+
toString(): string;
|
|
11
11
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,46 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
| 'create-failed'
|
|
4
|
-
| 'update'
|
|
5
|
-
| 'expired'
|
|
1
|
+
import { LabelPreference } from './moderation/types';
|
|
2
|
+
export declare type AtpSessionEvent = 'create' | 'create-failed' | 'update' | 'expired';
|
|
6
3
|
export interface AtpSessionData {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
refreshJwt: string;
|
|
5
|
+
accessJwt: string;
|
|
6
|
+
handle: string;
|
|
7
|
+
did: string;
|
|
8
|
+
email?: string;
|
|
12
9
|
}
|
|
13
|
-
export declare type AtpPersistSessionHandler = (
|
|
14
|
-
evt: AtpSessionEvent,
|
|
15
|
-
session: AtpSessionData | undefined,
|
|
16
|
-
) => void | Promise<void>
|
|
10
|
+
export declare type AtpPersistSessionHandler = (evt: AtpSessionEvent, session: AtpSessionData | undefined) => void | Promise<void>;
|
|
17
11
|
export interface AtpAgentOpts {
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
service: string | URL;
|
|
13
|
+
persistSession?: AtpPersistSessionHandler;
|
|
20
14
|
}
|
|
21
15
|
export interface AtpAgentCreateAccountOpts {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
email: string;
|
|
17
|
+
password: string;
|
|
18
|
+
handle: string;
|
|
19
|
+
inviteCode?: string;
|
|
26
20
|
}
|
|
27
21
|
export interface AtpAgentLoginOpts {
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
identifier: string;
|
|
23
|
+
password: string;
|
|
30
24
|
}
|
|
31
|
-
declare type AtpAgentFetchHeaders = Record<string, string
|
|
25
|
+
declare type AtpAgentFetchHeaders = Record<string, string>;
|
|
32
26
|
export interface AtpAgentFetchHandlerResponse {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
status: number;
|
|
28
|
+
headers: Record<string, string>;
|
|
29
|
+
body: any;
|
|
36
30
|
}
|
|
37
|
-
export declare type AtpAgentFetchHandler = (
|
|
38
|
-
httpUri: string,
|
|
39
|
-
httpMethod: string,
|
|
40
|
-
httpHeaders: AtpAgentFetchHeaders,
|
|
41
|
-
httpReqBody: any,
|
|
42
|
-
) => Promise<AtpAgentFetchHandlerResponse>
|
|
31
|
+
export declare type AtpAgentFetchHandler = (httpUri: string, httpMethod: string, httpHeaders: AtpAgentFetchHeaders, httpReqBody: any) => Promise<AtpAgentFetchHandlerResponse>;
|
|
43
32
|
export interface AtpAgentGlobalOpts {
|
|
44
|
-
|
|
33
|
+
fetch: AtpAgentFetchHandler;
|
|
45
34
|
}
|
|
46
|
-
export
|
|
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
|
+
}
|
|
44
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/api",
|
|
3
|
-
"version": "0.6.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "0.6.9",
|
|
4
|
+
"main": "src/index.ts",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"codegen": "yarn docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
|
|
7
|
+
"docgen": "node ./scripts/generate-docs.mjs",
|
|
8
|
+
"build": "node ./build.js",
|
|
9
|
+
"postbuild": "tsc --build tsconfig.build.json",
|
|
10
|
+
"update-main-to-dist": "node ./update-pkg.js --update-main-to-dist",
|
|
11
|
+
"update-main-to-src": "node ./update-pkg.js --update-main-to-src",
|
|
12
|
+
"prepublish": "npm run update-main-to-dist",
|
|
13
|
+
"postpublish": "npm run update-main-to-src",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"bench": "jest --config jest.bench.config.js",
|
|
16
|
+
"bench:profile": "node --inspect-brk ../../node_modules/.bin/jest --config jest.bench.config.js"
|
|
17
|
+
},
|
|
5
18
|
"license": "MIT",
|
|
6
19
|
"repository": {
|
|
7
20
|
"type": "git",
|
|
@@ -9,27 +22,15 @@
|
|
|
9
22
|
"directory": "packages/api"
|
|
10
23
|
},
|
|
11
24
|
"dependencies": {
|
|
12
|
-
"
|
|
25
|
+
"@atproto/common-web": "*",
|
|
26
|
+
"@atproto/syntax": "*",
|
|
27
|
+
"@atproto/xrpc": "*",
|
|
13
28
|
"tlds": "^1.234.0",
|
|
14
|
-
"typed-emitter": "^2.1.0"
|
|
15
|
-
"@atproto/common-web": "^0.2.0",
|
|
16
|
-
"@atproto/lexicon": "^0.2.0",
|
|
17
|
-
"@atproto/uri": "^0.1.0",
|
|
18
|
-
"@atproto/xrpc": "^0.2.0"
|
|
29
|
+
"typed-emitter": "^2.1.0"
|
|
19
30
|
},
|
|
20
31
|
"devDependencies": {
|
|
21
|
-
"
|
|
22
|
-
"@atproto/
|
|
23
|
-
"
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
"codegen": "pnpm docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
|
|
27
|
-
"docgen": "node ./scripts/generate-docs.mjs",
|
|
28
|
-
"build": "node ./build.js",
|
|
29
|
-
"postbuild": "tsc --build tsconfig.build.json",
|
|
30
|
-
"test": "jest",
|
|
31
|
-
"bench": "jest --config jest.bench.config.js",
|
|
32
|
-
"bench:profile": "node --inspect-brk ../../node_modules/.bin/jest --config jest.bench.config.js"
|
|
33
|
-
},
|
|
34
|
-
"types": "dist/index.d.ts"
|
|
35
|
-
}
|
|
32
|
+
"@atproto/lex-cli": "*",
|
|
33
|
+
"@atproto/pds": "*",
|
|
34
|
+
"common-tags": "^1.8.2"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/bsky-agent.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { AtUri } from '@atproto/
|
|
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
|
}
|
package/src/client/index.ts
CHANGED
|
@@ -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'
|
|
@@ -99,6 +98,7 @@ import * as AppBskyFeedGetLikes from './types/app/bsky/feed/getLikes'
|
|
|
99
98
|
import * as AppBskyFeedGetPostThread from './types/app/bsky/feed/getPostThread'
|
|
100
99
|
import * as AppBskyFeedGetPosts from './types/app/bsky/feed/getPosts'
|
|
101
100
|
import * as AppBskyFeedGetRepostedBy from './types/app/bsky/feed/getRepostedBy'
|
|
101
|
+
import * as AppBskyFeedGetSuggestedFeeds from './types/app/bsky/feed/getSuggestedFeeds'
|
|
102
102
|
import * as AppBskyFeedGetTimeline from './types/app/bsky/feed/getTimeline'
|
|
103
103
|
import * as AppBskyFeedLike from './types/app/bsky/feed/like'
|
|
104
104
|
import * as AppBskyFeedPost from './types/app/bsky/feed/post'
|
|
@@ -140,7 +140,6 @@ export * as ComAtprotoAdminGetModerationReport from './types/com/atproto/admin/g
|
|
|
140
140
|
export * as ComAtprotoAdminGetModerationReports from './types/com/atproto/admin/getModerationReports'
|
|
141
141
|
export * as ComAtprotoAdminGetRecord from './types/com/atproto/admin/getRecord'
|
|
142
142
|
export * as ComAtprotoAdminGetRepo from './types/com/atproto/admin/getRepo'
|
|
143
|
-
export * as ComAtprotoAdminRebaseRepo from './types/com/atproto/admin/rebaseRepo'
|
|
144
143
|
export * as ComAtprotoAdminResolveModerationReports from './types/com/atproto/admin/resolveModerationReports'
|
|
145
144
|
export * as ComAtprotoAdminReverseModerationAction from './types/com/atproto/admin/reverseModerationAction'
|
|
146
145
|
export * as ComAtprotoAdminSearchRepos from './types/com/atproto/admin/searchRepos'
|
|
@@ -162,7 +161,6 @@ export * as ComAtprotoRepoDescribeRepo from './types/com/atproto/repo/describeRe
|
|
|
162
161
|
export * as ComAtprotoRepoGetRecord from './types/com/atproto/repo/getRecord'
|
|
163
162
|
export * as ComAtprotoRepoListRecords from './types/com/atproto/repo/listRecords'
|
|
164
163
|
export * as ComAtprotoRepoPutRecord from './types/com/atproto/repo/putRecord'
|
|
165
|
-
export * as ComAtprotoRepoRebaseRepo from './types/com/atproto/repo/rebaseRepo'
|
|
166
164
|
export * as ComAtprotoRepoStrongRef from './types/com/atproto/repo/strongRef'
|
|
167
165
|
export * as ComAtprotoRepoUploadBlob from './types/com/atproto/repo/uploadBlob'
|
|
168
166
|
export * as ComAtprotoServerCreateAccount from './types/com/atproto/server/createAccount'
|
|
@@ -185,8 +183,8 @@ export * as ComAtprotoServerRevokeAppPassword from './types/com/atproto/server/r
|
|
|
185
183
|
export * as ComAtprotoSyncGetBlob from './types/com/atproto/sync/getBlob'
|
|
186
184
|
export * as ComAtprotoSyncGetBlocks from './types/com/atproto/sync/getBlocks'
|
|
187
185
|
export * as ComAtprotoSyncGetCheckout from './types/com/atproto/sync/getCheckout'
|
|
188
|
-
export * as ComAtprotoSyncGetCommitPath from './types/com/atproto/sync/getCommitPath'
|
|
189
186
|
export * as ComAtprotoSyncGetHead from './types/com/atproto/sync/getHead'
|
|
187
|
+
export * as ComAtprotoSyncGetLatestCommit from './types/com/atproto/sync/getLatestCommit'
|
|
190
188
|
export * as ComAtprotoSyncGetRecord from './types/com/atproto/sync/getRecord'
|
|
191
189
|
export * as ComAtprotoSyncGetRepo from './types/com/atproto/sync/getRepo'
|
|
192
190
|
export * as ComAtprotoSyncListBlobs from './types/com/atproto/sync/listBlobs'
|
|
@@ -194,6 +192,7 @@ export * as ComAtprotoSyncListRepos from './types/com/atproto/sync/listRepos'
|
|
|
194
192
|
export * as ComAtprotoSyncNotifyOfUpdate from './types/com/atproto/sync/notifyOfUpdate'
|
|
195
193
|
export * as ComAtprotoSyncRequestCrawl from './types/com/atproto/sync/requestCrawl'
|
|
196
194
|
export * as ComAtprotoSyncSubscribeRepos from './types/com/atproto/sync/subscribeRepos'
|
|
195
|
+
export * as ComAtprotoTempUpgradeRepoVersion from './types/com/atproto/temp/upgradeRepoVersion'
|
|
197
196
|
export * as AppBskyActorDefs from './types/app/bsky/actor/defs'
|
|
198
197
|
export * as AppBskyActorGetPreferences from './types/app/bsky/actor/getPreferences'
|
|
199
198
|
export * as AppBskyActorGetProfile from './types/app/bsky/actor/getProfile'
|
|
@@ -221,6 +220,7 @@ export * as AppBskyFeedGetLikes from './types/app/bsky/feed/getLikes'
|
|
|
221
220
|
export * as AppBskyFeedGetPostThread from './types/app/bsky/feed/getPostThread'
|
|
222
221
|
export * as AppBskyFeedGetPosts from './types/app/bsky/feed/getPosts'
|
|
223
222
|
export * as AppBskyFeedGetRepostedBy from './types/app/bsky/feed/getRepostedBy'
|
|
223
|
+
export * as AppBskyFeedGetSuggestedFeeds from './types/app/bsky/feed/getSuggestedFeeds'
|
|
224
224
|
export * as AppBskyFeedGetTimeline from './types/app/bsky/feed/getTimeline'
|
|
225
225
|
export * as AppBskyFeedLike from './types/app/bsky/feed/like'
|
|
226
226
|
export * as AppBskyFeedPost from './types/app/bsky/feed/post'
|
|
@@ -318,6 +318,7 @@ export class AtprotoNS {
|
|
|
318
318
|
repo: RepoNS
|
|
319
319
|
server: ServerNS
|
|
320
320
|
sync: SyncNS
|
|
321
|
+
temp: TempNS
|
|
321
322
|
|
|
322
323
|
constructor(service: AtpServiceClient) {
|
|
323
324
|
this._service = service
|
|
@@ -328,6 +329,7 @@ export class AtprotoNS {
|
|
|
328
329
|
this.repo = new RepoNS(service)
|
|
329
330
|
this.server = new ServerNS(service)
|
|
330
331
|
this.sync = new SyncNS(service)
|
|
332
|
+
this.temp = new TempNS(service)
|
|
331
333
|
}
|
|
332
334
|
}
|
|
333
335
|
|
|
@@ -448,17 +450,6 @@ export class AdminNS {
|
|
|
448
450
|
})
|
|
449
451
|
}
|
|
450
452
|
|
|
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
453
|
resolveModerationReports(
|
|
463
454
|
data?: ComAtprotoAdminResolveModerationReports.InputSchema,
|
|
464
455
|
opts?: ComAtprotoAdminResolveModerationReports.CallOptions,
|
|
@@ -689,17 +680,6 @@ export class RepoNS {
|
|
|
689
680
|
})
|
|
690
681
|
}
|
|
691
682
|
|
|
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
683
|
uploadBlob(
|
|
704
684
|
data?: ComAtprotoRepoUploadBlob.InputSchema,
|
|
705
685
|
opts?: ComAtprotoRepoUploadBlob.CallOptions,
|
|
@@ -936,17 +916,6 @@ export class SyncNS {
|
|
|
936
916
|
})
|
|
937
917
|
}
|
|
938
918
|
|
|
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
919
|
getHead(
|
|
951
920
|
params?: ComAtprotoSyncGetHead.QueryParams,
|
|
952
921
|
opts?: ComAtprotoSyncGetHead.CallOptions,
|
|
@@ -958,6 +927,17 @@ export class SyncNS {
|
|
|
958
927
|
})
|
|
959
928
|
}
|
|
960
929
|
|
|
930
|
+
getLatestCommit(
|
|
931
|
+
params?: ComAtprotoSyncGetLatestCommit.QueryParams,
|
|
932
|
+
opts?: ComAtprotoSyncGetLatestCommit.CallOptions,
|
|
933
|
+
): Promise<ComAtprotoSyncGetLatestCommit.Response> {
|
|
934
|
+
return this._service.xrpc
|
|
935
|
+
.call('com.atproto.sync.getLatestCommit', params, undefined, opts)
|
|
936
|
+
.catch((e) => {
|
|
937
|
+
throw ComAtprotoSyncGetLatestCommit.toKnownErr(e)
|
|
938
|
+
})
|
|
939
|
+
}
|
|
940
|
+
|
|
961
941
|
getRecord(
|
|
962
942
|
params?: ComAtprotoSyncGetRecord.QueryParams,
|
|
963
943
|
opts?: ComAtprotoSyncGetRecord.CallOptions,
|
|
@@ -1025,6 +1005,25 @@ export class SyncNS {
|
|
|
1025
1005
|
}
|
|
1026
1006
|
}
|
|
1027
1007
|
|
|
1008
|
+
export class TempNS {
|
|
1009
|
+
_service: AtpServiceClient
|
|
1010
|
+
|
|
1011
|
+
constructor(service: AtpServiceClient) {
|
|
1012
|
+
this._service = service
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
upgradeRepoVersion(
|
|
1016
|
+
data?: ComAtprotoTempUpgradeRepoVersion.InputSchema,
|
|
1017
|
+
opts?: ComAtprotoTempUpgradeRepoVersion.CallOptions,
|
|
1018
|
+
): Promise<ComAtprotoTempUpgradeRepoVersion.Response> {
|
|
1019
|
+
return this._service.xrpc
|
|
1020
|
+
.call('com.atproto.temp.upgradeRepoVersion', opts?.qp, data, opts)
|
|
1021
|
+
.catch((e) => {
|
|
1022
|
+
throw ComAtprotoTempUpgradeRepoVersion.toKnownErr(e)
|
|
1023
|
+
})
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1028
1027
|
export class AppNS {
|
|
1029
1028
|
_service: AtpServiceClient
|
|
1030
1029
|
bsky: BskyNS
|
|
@@ -1360,6 +1359,17 @@ export class FeedNS {
|
|
|
1360
1359
|
})
|
|
1361
1360
|
}
|
|
1362
1361
|
|
|
1362
|
+
getSuggestedFeeds(
|
|
1363
|
+
params?: AppBskyFeedGetSuggestedFeeds.QueryParams,
|
|
1364
|
+
opts?: AppBskyFeedGetSuggestedFeeds.CallOptions,
|
|
1365
|
+
): Promise<AppBskyFeedGetSuggestedFeeds.Response> {
|
|
1366
|
+
return this._service.xrpc
|
|
1367
|
+
.call('app.bsky.feed.getSuggestedFeeds', params, undefined, opts)
|
|
1368
|
+
.catch((e) => {
|
|
1369
|
+
throw AppBskyFeedGetSuggestedFeeds.toKnownErr(e)
|
|
1370
|
+
})
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1363
1373
|
getTimeline(
|
|
1364
1374
|
params?: AppBskyFeedGetTimeline.QueryParams,
|
|
1365
1375
|
opts?: AppBskyFeedGetTimeline.CallOptions,
|