-
-
Notifications
You must be signed in to change notification settings - Fork 7
ci: test to debug Secret is required
#37
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
Closed
Closed
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
451d64e
feat: add vitest
anbraten 29f1137
fix config
anbraten b305f7e
fix
anbraten 9cc36f8
adjust code a bit
anbraten b9d294c
adjust
anbraten 1bdc9a5
Merge remote-tracking branch 'upstream/main' into first-calls
anbraten c8fd884
undo and fix lint
anbraten 3d8b5c3
enahnce code
anbraten eb36b52
structure feed
anbraten 0acd74a
fix tests
anbraten 6100c16
init
anbraten f13f0b1
Merge remote-tracking branch 'upstream/main' into atcute
anbraten 1caecf7
feat: add client
anbraten 90bac23
fix types and tests
anbraten a7c79cb
enhance types
anbraten 54ccdfa
update readme
anbraten e1d448c
core => client
anbraten 6a95c94
fix readme
anbraten 1784683
cleanup
anbraten f68c814
fix tests
anbraten 9ee43bc
add secrets
anbraten 9a34f78
throw error
anbraten ccde5ee
adjust
anbraten 2cda0c3
print env keys
anbraten 025fd64
chore: fix lint errors fro type import
shuuji3 8d0e9d6
fix: fix private member #refreshSessionPromise error
shuuji3 28f9a1e
chore: remove debug log
shuuji3 54afc7a
test: add test for `tsky.bsky.feed.getFeed()`
shuuji3 c9c94e7
refactor: initialize `XRPC` within `Tsky` constructor
shuuji3 b61760a
chore: update process.env usage
patak-dev 8d99057
chore: update
patak-dev c24bc97
refactor: replace `APP_PASSWORD` with `PASSWORD`
shuuji3 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
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
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,50 @@ | ||
| import type { | ||
| AppBskyFeedGetFeed, | ||
| AppBskyFeedGetTimeline, | ||
| } from '@tsky/lexicons'; | ||
| import type { Client } from '~/tsky/client'; | ||
| import { Paginator } from '~/tsky/paginator'; | ||
|
|
||
| export class Feed { | ||
| constructor(private client: Client) {} | ||
|
|
||
| /** | ||
| * Get a hydrated feed from an actor's selected feed generator. Implemented by App View. | ||
| */ | ||
| async getFeed( | ||
| params: AppBskyFeedGetFeed.Params, | ||
| options?: AppBskyFeedGetFeed.Input, | ||
| ): Promise<Paginator<AppBskyFeedGetFeed.Output>> { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.feed.getFeed', { | ||
| ...(options ?? {}), | ||
| params: { | ||
| cursor, | ||
| ...params, | ||
| }, | ||
| }); | ||
|
|
||
| return res.data; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Get a view of the requesting account's home timeline. This is expected to be some form of reverse-chronological feed. | ||
| */ | ||
| getTimeline( | ||
| params: AppBskyFeedGetTimeline.Params, | ||
| options?: AppBskyFeedGetTimeline.Input, | ||
| ): Promise<Paginator<AppBskyFeedGetTimeline.Output>> { | ||
| return Paginator.init(async (cursor) => { | ||
| const res = await this.client.get('app.bsky.feed.getTimeline', { | ||
| ...(options ?? {}), | ||
| params: { | ||
| cursor, | ||
| ...params, | ||
| }, | ||
| }); | ||
|
|
||
| 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,79 @@ | ||
| import { CredentialManager } from '@atcute/client'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { Tsky } from '~/index'; | ||
|
|
||
| const formatSecret = (secret: string | undefined) => { | ||
| if (!secret) { | ||
| throw new Error('Secret is required'); | ||
| } | ||
|
|
||
| return secret.replace(/^tsky /g, '').trim(); | ||
| }; | ||
|
|
||
| const TEST_CREDENTIALS = { | ||
| alice: { | ||
| handle: 'alice.tsky.dev', | ||
| did: 'did:plc:jguhdmnjclquqf5lsvkyxqy3', | ||
| password: formatSecret(process.env.ALICE_PASSWORD), | ||
| }, | ||
| bob: { | ||
| handle: 'bob.tsky.dev', | ||
| did: 'did:plc:2ig7akkyfq256j42uxvc4g2h', | ||
| password: formatSecret(process.env.BOB_PASSWORD), | ||
| }, | ||
| }; | ||
|
|
||
| async function getAliceTsky() { | ||
| const manager = new CredentialManager({ service: 'https://bsky.social' }); | ||
| await manager.login({ | ||
| identifier: TEST_CREDENTIALS.alice.handle, | ||
| password: TEST_CREDENTIALS.alice.password, | ||
| }); | ||
|
|
||
| return new Tsky(manager); | ||
| } | ||
|
|
||
| describe('bsky', () => { | ||
| it('.profile()', async () => { | ||
| const tsky = await getAliceTsky(); | ||
| const profile = await tsky.bsky.profile(TEST_CREDENTIALS.alice.did); | ||
|
|
||
| expect(profile).toBeDefined(); | ||
| expect(profile).toHaveProperty('handle', TEST_CREDENTIALS.alice.handle); | ||
| }); | ||
|
|
||
| describe('feed', () => { | ||
| it('.timeline()', async () => { | ||
| const tsky = await getAliceTsky(); | ||
|
|
||
| const paginator = await tsky.bsky.feed.getTimeline({ | ||
| 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); // alice has some posts ;) | ||
| expect(paginator.values[0].feed[0]).toHaveProperty('post'); | ||
| }); | ||
|
|
||
| it('.feed()', async () => { | ||
| const tsky = await getAliceTsky(); | ||
|
|
||
| const paginator = await tsky.bsky.feed.getFeed({ | ||
| // "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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import type { AppBskyActorDefs } from '@tsky/lexicons'; | ||
| import { Feed } from '~/bsky/feed'; | ||
| import type { Client } from '~/tsky/client'; | ||
|
|
||
| export class Bsky { | ||
| client: Client; | ||
|
|
||
| constructor(client: Client) { | ||
| this.client = client; | ||
| } | ||
|
|
||
| /** | ||
| * Get detailed profile view of an actor. Does not require auth, but contains relevant metadata with auth. | ||
| */ | ||
| async profile( | ||
| identifier: string, | ||
| ): Promise<AppBskyActorDefs.ProfileViewDetailed> { | ||
| const res = await this.client.get('app.bsky.actor.getProfile', { | ||
| params: { actor: identifier }, | ||
| }); | ||
|
|
||
| return res.data; | ||
| } | ||
|
|
||
| get feed() { | ||
| return new Feed(this.client); | ||
| } | ||
| } |
File renamed without changes.
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,56 @@ | ||
| import type { | ||
| RPCOptions, | ||
| XRPC, | ||
| XRPCRequestOptions, | ||
| XRPCResponse, | ||
| } from '@atcute/client'; | ||
| import type { Procedures, Queries } from '@tsky/lexicons'; | ||
|
|
||
| // From @atcute/client | ||
| type OutputOf<T> = T extends { | ||
| // biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
| output: any; | ||
| } | ||
| ? T['output'] | ||
| : never; | ||
|
|
||
| export class Client<Q = Queries, P = Procedures> { | ||
| xrpc: XRPC; | ||
|
|
||
| constructor(xrpc: XRPC) { | ||
| this.xrpc = xrpc; | ||
| } | ||
|
|
||
| /** | ||
| * Makes a query (GET) request | ||
| * @param nsid Namespace ID of a query endpoint | ||
| * @param options Options to include like parameters | ||
| * @returns The response of the request | ||
| */ | ||
| async get<K extends keyof Q>( | ||
| nsid: K, | ||
| options: RPCOptions<Q[K]>, | ||
| ): Promise<XRPCResponse<OutputOf<Q[K]>>> { | ||
| // biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
| return this.xrpc.get(nsid as any, options); | ||
| } | ||
|
|
||
| /** | ||
| * Makes a procedure (POST) request | ||
| * @param nsid Namespace ID of a procedure endpoint | ||
| * @param options Options to include like input body or parameters | ||
| * @returns The response of the request | ||
| */ | ||
| async call<K extends keyof P>( | ||
| nsid: K, | ||
| options: RPCOptions<P[K]>, | ||
| ): Promise<XRPCResponse<OutputOf<P[K]>>> { | ||
| // biome-ignore lint/suspicious/noExplicitAny: <explanation> | ||
| return this.xrpc.call(nsid as any, options); | ||
| } | ||
|
|
||
| /** Makes a request to the XRPC service */ | ||
| async request(options: XRPCRequestOptions): Promise<XRPCResponse> { | ||
| return this.xrpc.request(options); | ||
| } | ||
| } |
File renamed without changes.
16 changes: 12 additions & 4 deletions
16
packages/core/src/tsky/paginator.ts → packages/client/src/tsky/paginator.ts
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,18 @@ | ||
| import type { CredentialManager } from '@atcute/client'; | ||
| import { XRPC } from '@atcute/client'; | ||
| import type { Queries } from '@tsky/lexicons'; | ||
| import { Bsky } from '~/bsky'; | ||
| import { Client } from './client'; | ||
|
|
||
| export class Tsky { | ||
| client: Client<Queries>; | ||
|
|
||
| constructor(manager: CredentialManager) { | ||
| const xrpc = new XRPC({ handler: manager }); | ||
| this.client = new Client(xrpc); | ||
| } | ||
|
|
||
| get bsky() { | ||
| return new Bsky(this.client); | ||
| } | ||
| } |
Oops, something went wrong.
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.