|
| 1 | +import type { |
| 2 | + AppBskyActorDefs, |
| 3 | + AppBskyFeedGetAuthorFeed, |
| 4 | +} from '@tsky/lexicons'; |
| 5 | +import type { Client } from '~/tsky/client'; |
| 6 | +import type { RPCOptions } from '~/types'; |
| 7 | +import { Paginator } from '~/utils'; |
| 8 | + |
| 9 | +export class Actor { |
| 10 | + client: Client; |
| 11 | + identifier: string; |
| 12 | + |
| 13 | + constructor(client: Client, identifier: string) { |
| 14 | + this.client = client; |
| 15 | + this.identifier = identifier; |
| 16 | + } |
| 17 | + |
| 18 | + /** |
| 19 | + * Get detailed profile view of an actor. Does not require auth, but contains relevant metadata with auth. |
| 20 | + */ |
| 21 | + async profile(): Promise<AppBskyActorDefs.ProfileViewDetailed> { |
| 22 | + const res = await this.client.get('app.bsky.actor.getProfile', { |
| 23 | + params: { actor: this.identifier }, |
| 24 | + }); |
| 25 | + |
| 26 | + return res.data; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * Get a list of starter packs created by the actor. |
| 31 | + */ |
| 32 | + starterPacks(limit?: number, options: RPCOptions = {}) { |
| 33 | + return Paginator.init(async (cursor) => { |
| 34 | + const res = await this.client.get('app.bsky.graph.getActorStarterPacks', { |
| 35 | + params: { cursor, actor: this.identifier, limit }, |
| 36 | + ...options, |
| 37 | + }); |
| 38 | + |
| 39 | + return res.data; |
| 40 | + }); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Enumerates accounts which follow a specified account (actor). |
| 45 | + */ |
| 46 | + followers(limit?: number, options: RPCOptions = {}) { |
| 47 | + return Paginator.init(async (cursor) => { |
| 48 | + const res = await this.client.get('app.bsky.graph.getFollowers', { |
| 49 | + params: { |
| 50 | + cursor, |
| 51 | + actor: this.identifier, |
| 52 | + limit, |
| 53 | + }, |
| 54 | + ...options, |
| 55 | + }); |
| 56 | + |
| 57 | + return res.data; |
| 58 | + }); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Enumerates accounts which a specified account (actor) follows. |
| 63 | + */ |
| 64 | + follows(limit?: number, options: RPCOptions = {}) { |
| 65 | + return Paginator.init(async (cursor) => { |
| 66 | + const res = await this.client.get('app.bsky.graph.getFollows', { |
| 67 | + params: { |
| 68 | + cursor, |
| 69 | + actor: this.identifier, |
| 70 | + limit, |
| 71 | + }, |
| 72 | + ...options, |
| 73 | + }); |
| 74 | + |
| 75 | + return res.data; |
| 76 | + }); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Enumerates the lists created by a specified account (actor). |
| 81 | + */ |
| 82 | + lists(limit?: number, options: RPCOptions = {}) { |
| 83 | + return Paginator.init(async (cursor) => { |
| 84 | + const res = await this.client.get('app.bsky.graph.getLists', { |
| 85 | + params: { |
| 86 | + cursor, |
| 87 | + actor: this.identifier, |
| 88 | + limit, |
| 89 | + }, |
| 90 | + ...options, |
| 91 | + }); |
| 92 | + |
| 93 | + return res.data; |
| 94 | + }); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Enumerates public relationships between one account, and a list of other accounts. Does not require auth. |
| 99 | + */ |
| 100 | + async relationships(others?: string[], options?: RPCOptions) { |
| 101 | + const res = await this.client.get('app.bsky.graph.getRelationships', { |
| 102 | + params: { |
| 103 | + actor: this.identifier, |
| 104 | + others, |
| 105 | + }, |
| 106 | + ...options, |
| 107 | + }); |
| 108 | + |
| 109 | + return res.data; |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Get a view of an actor's 'author feed' (post and reposts by the author). Does not require auth. |
| 114 | + */ |
| 115 | + feeds(limit?: number, options?: RPCOptions) { |
| 116 | + return Paginator.init(async (cursor) => { |
| 117 | + const res = await this.client.get('app.bsky.feed.getActorFeeds', { |
| 118 | + params: { cursor, actor: this.identifier, limit }, |
| 119 | + ...options, |
| 120 | + }); |
| 121 | + |
| 122 | + return res.data; |
| 123 | + }); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Get a list of feeds (feed generator records) created by the actor (in the actor's repo). |
| 128 | + */ |
| 129 | + feed( |
| 130 | + params?: Omit<AppBskyFeedGetAuthorFeed.Params, 'actor'>, |
| 131 | + options?: RPCOptions, |
| 132 | + ) { |
| 133 | + return Paginator.init(async (cursor) => { |
| 134 | + const res = await this.client.get('app.bsky.feed.getAuthorFeed', { |
| 135 | + params: { cursor, ...params, actor: this.identifier }, |
| 136 | + ...options, |
| 137 | + }); |
| 138 | + |
| 139 | + return res.data; |
| 140 | + }); |
| 141 | + } |
| 142 | +} |
0 commit comments