-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: v0.1 #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
feat: v0.1 #47
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ee58534
chore: rename bsky module to feed and update imports
MathurAditya724 f4d8017
chore(client): add path mapping for @tsky/lexicons in tsconfig
MathurAditya724 f664762
chore(client): renamed the test file for feed
MathurAditya724 dc2e1b1
chore(client): added the paginator under utils
MathurAditya724 cda241a
chore(client): remove paginator export from tsky module
MathurAditya724 75838f7
chore(client): added manager
MathurAditya724 cd71e1b
chore(client): update Manager to accept options and integrate with Tsky
MathurAditya724 42622f0
chore: renamed manager to auth
MathurAditya724 c010241
chore: updated imports for auth
MathurAditya724 dada011
chore: restructured the bsky class
MathurAditya724 b813dea
chore: made client prop private
MathurAditya724 c7917f9
feat(client): added preference class
MathurAditya724 c296086
refactor(client): simplify client initialization and update feed tests
MathurAditya724 8d87378
chore(client): shifted profile in user class and added tests
MathurAditya724 211fcb6
feat(client): added feat generator
MathurAditya724 7ce0093
feat(client): added actor class
MathurAditya724 bc5b043
fix(client): added more props in the actor class
MathurAditya724 61ee237
feat(client): added the remaining modules
MathurAditya724 06573bb
chore: minor changes
MathurAditya724 b9a7237
chore: updated lockfile
MathurAditya724 88b0c22
fix: corrected the typo
MathurAditya724 2fc985a
chore: corrected the imports
MathurAditya724 a682320
fix: updated the mute and unmute api (#48)
MathurAditya724 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { | ||
| type AtpSessionData, | ||
| CredentialManager, | ||
| type CredentialManagerOptions, | ||
| } from '@atcute/client'; | ||
|
|
||
| export class Auth { | ||
| manager: CredentialManager; | ||
| sessions: Map<string, AtpSessionData> = new Map(); | ||
|
|
||
| constructor(options?: CredentialManagerOptions) { | ||
| this.manager = new CredentialManager( | ||
| options ?? { service: 'https://bsky.social' }, | ||
| ); | ||
| } | ||
|
|
||
| async login(identifier: string, password: string) { | ||
| const session = await this.manager.login({ | ||
| identifier, | ||
| password, | ||
| }); | ||
|
|
||
| this.sessions.set(session.did, session); | ||
|
|
||
| return session; | ||
| } | ||
|
|
||
| async switch(did: string) { | ||
| const session = this.sessions.get(did); | ||
|
|
||
| if (!session) { | ||
| throw new Error('Session not found'); | ||
| } | ||
|
|
||
| return await this.manager.resume(session); | ||
| } | ||
|
|
||
| logout(did: string) { | ||
| this.sessions.delete(did); | ||
| } | ||
|
|
||
| get currentSession() { | ||
| return this.manager.session; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './auth'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import type { | ||
| AppBskyActorDefs, | ||
| AppBskyFeedGetAuthorFeed, | ||
| } from '@tsky/lexicons'; | ||
| import type { Client } from '~/tsky/client'; | ||
| import type { RPCOptions } from '~/types'; | ||
| import { Paginator } from '~/utils'; | ||
|
|
||
| export class Actor { | ||
| client: Client; | ||
| identifier: string; | ||
|
|
||
| constructor(client: Client, identifier: string) { | ||
| this.client = client; | ||
| this.identifier = identifier; | ||
| } | ||
|
|
||
| /** | ||
| * Get detailed profile view of an actor. Does not require auth, but contains relevant metadata with auth. | ||
| */ | ||
| async profile(): Promise<AppBskyActorDefs.ProfileViewDetailed> { | ||
| const res = await this.client.get('app.bsky.actor.getProfile', { | ||
| params: { actor: this.identifier }, | ||
| }); | ||
|
|
||
| return res.data; | ||
| } | ||
|
|
||
| /** | ||
| * Get a list of starter packs created by the actor. | ||
| */ | ||
| starterPacks(limit?: number, options: RPCOptions = {}) { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.graph.getActorStarterPacks', { | ||
| params: { cursor, actor: this.identifier, limit }, | ||
| ...options, | ||
| }); | ||
|
|
||
| return res.data; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Enumerates accounts which follow a specified account (actor). | ||
| */ | ||
| followers(limit?: number, options: RPCOptions = {}) { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.graph.getFollowers', { | ||
| params: { | ||
| cursor, | ||
| actor: this.identifier, | ||
| limit, | ||
| }, | ||
| ...options, | ||
| }); | ||
|
|
||
| return res.data; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Enumerates accounts which a specified account (actor) follows. | ||
| */ | ||
| follows(limit?: number, options: RPCOptions = {}) { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.graph.getFollows', { | ||
| params: { | ||
| cursor, | ||
| actor: this.identifier, | ||
| limit, | ||
| }, | ||
| ...options, | ||
| }); | ||
|
|
||
| return res.data; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Enumerates the lists created by a specified account (actor). | ||
| */ | ||
| lists(limit?: number, options: RPCOptions = {}) { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.graph.getLists', { | ||
| params: { | ||
| cursor, | ||
| actor: this.identifier, | ||
| limit, | ||
| }, | ||
| ...options, | ||
| }); | ||
|
|
||
| return res.data; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Enumerates public relationships between one account, and a list of other accounts. Does not require auth. | ||
| */ | ||
| async relationships(others?: string[], options?: RPCOptions) { | ||
| const res = await this.client.get('app.bsky.graph.getRelationships', { | ||
| params: { | ||
| actor: this.identifier, | ||
| others, | ||
| }, | ||
| ...options, | ||
| }); | ||
|
|
||
| return res.data; | ||
| } | ||
|
|
||
| /** | ||
| * Get a view of an actor's 'author feed' (post and reposts by the author). Does not require auth. | ||
| */ | ||
| feeds(limit?: number, options?: RPCOptions) { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.feed.getActorFeeds', { | ||
| params: { cursor, actor: this.identifier, limit }, | ||
| ...options, | ||
| }); | ||
|
|
||
| return res.data; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Get a list of feeds (feed generator records) created by the actor (in the actor's repo). | ||
| */ | ||
| feed( | ||
| params?: Omit<AppBskyFeedGetAuthorFeed.Params, 'actor'>, | ||
| options?: RPCOptions, | ||
| ) { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.feed.getAuthorFeed', { | ||
| params: { cursor, ...params, actor: this.identifier }, | ||
| ...options, | ||
| }); | ||
|
|
||
| return res.data; | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './autor'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { Feed } from '~/bsky/feed'; | ||
| import type { Client } from '~/tsky/client'; | ||
| import { Actor } from './autor'; | ||
| import { List } from './list'; | ||
|
|
||
| export class Bsky { | ||
| constructor(private client: Client) {} | ||
|
|
||
| actor(identifier: string) { | ||
| return new Actor(this.client, identifier); | ||
| } | ||
|
|
||
| list(uri: string) { | ||
| return new List(this.client, uri); | ||
| } | ||
|
|
||
| get feed() { | ||
| return new Feed(this.client); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { Tsky } from '~/index'; | ||
|
|
||
| const TEST_CREDENTIALS = { | ||
| alice: { | ||
| handle: 'alice.tsky.dev', | ||
| did: 'did:plc:jguhdmnjclquqf5lsvkyxqy3', | ||
| password: 'alice_and_bob', | ||
| }, | ||
| bob: { | ||
| handle: 'bob.tsky.dev', | ||
| did: 'did:plc:2ig7akkyfq256j42uxvc4g2h', | ||
| password: 'alice_and_bob', | ||
| }, | ||
| }; | ||
|
|
||
| async function getAliceTsky() { | ||
| const tsky = new Tsky(); | ||
|
|
||
| await tsky.auth.login( | ||
| TEST_CREDENTIALS.alice.handle, | ||
| TEST_CREDENTIALS.alice.password, | ||
| ); | ||
|
|
||
| return tsky; | ||
| } | ||
|
|
||
| describe('feed', () => { | ||
| it('.getFeed()', async () => { | ||
| const tsky = await getAliceTsky(); | ||
| const paginator = await tsky.bsky.feed.get({ | ||
| // "Birds! 🦉" custom feed | ||
| // - https://bsky.app/profile/daryllmarie.bsky.social/feed/aaagllxbcbsje | ||
| feed: 'at://did:plc:ffkgesg3jsv2j7aagkzrtcvt/app.bsky.feed.generator/aaagllxbcbsje', | ||
| limit: 30, | ||
| }); | ||
| expect(paginator).toBeDefined(); | ||
| expect(paginator.values).toBeDefined(); | ||
| expect(paginator.values).toBeInstanceOf(Array); | ||
| expect(paginator.values.length).toBe(1); // we should get the first page from the paginator | ||
| expect(paginator.values[0].feed.length).toBeGreaterThan(0); // we found some birds posts ;) | ||
| expect(paginator.values[0].feed[0]).toHaveProperty('post'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.