diff --git a/packages/client/src/bsky/index.test.ts b/packages/client/src/bsky/index.test.ts index ba1319e..4ac6f2f 100644 --- a/packages/client/src/bsky/index.test.ts +++ b/packages/client/src/bsky/index.test.ts @@ -24,8 +24,6 @@ const TEST_CREDENTIALS = { }, }; -console.log('env keys', Object.keys(process.env)); - async function getAliceTsky() { const manager = new CredentialManager({ service: 'https://bsky.social' }); await manager.login({ @@ -60,5 +58,23 @@ describe('bsky', () => { 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'); + }); }); }); diff --git a/packages/client/src/tsky/client.ts b/packages/client/src/tsky/client.ts index 20fe1cd..d83d372 100644 --- a/packages/client/src/tsky/client.ts +++ b/packages/client/src/tsky/client.ts @@ -1,57 +1,56 @@ -import { - type FetchHandler, - type RPCOptions, - XRPC, - type XRPCRequestOptions, - type XRPCResponse, -} from '@atcute/client'; -import type { Procedures, Queries } from '@tsky/lexicons'; - -// From @atcute/client -type OutputOf = T extends { - // biome-ignore lint/suspicious/noExplicitAny: - output: any; -} - ? T['output'] - : never; - -export class Client { - xrpc: XRPC; - - constructor(handler: FetchHandler) { - this.xrpc = new XRPC({ handler }); - } - - /** - * 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( - nsid: K, - options: RPCOptions, - ): Promise>> { - // biome-ignore lint/suspicious/noExplicitAny: - 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( - nsid: K, - options: RPCOptions, - ): Promise>> { - // biome-ignore lint/suspicious/noExplicitAny: - return this.xrpc.call(nsid as any, options); - } - - /** Makes a request to the XRPC service */ - async request(options: XRPCRequestOptions): Promise { - return this.xrpc.request(options); - } -} +import type { + RPCOptions, + XRPC, + XRPCRequestOptions, + XRPCResponse, +} from '@atcute/client'; +import type { Procedures, Queries } from '@tsky/lexicons'; + +// From @atcute/client +type OutputOf = T extends { + // biome-ignore lint/suspicious/noExplicitAny: + output: any; +} + ? T['output'] + : never; + +export class Client { + 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( + nsid: K, + options: RPCOptions, + ): Promise>> { + // biome-ignore lint/suspicious/noExplicitAny: + 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( + nsid: K, + options: RPCOptions, + ): Promise>> { + // biome-ignore lint/suspicious/noExplicitAny: + return this.xrpc.call(nsid as any, options); + } + + /** Makes a request to the XRPC service */ + async request(options: XRPCRequestOptions): Promise { + return this.xrpc.request(options); + } +} diff --git a/packages/client/src/tsky/tsky.ts b/packages/client/src/tsky/tsky.ts index c221827..8f123af 100644 --- a/packages/client/src/tsky/tsky.ts +++ b/packages/client/src/tsky/tsky.ts @@ -1,4 +1,5 @@ -import type { FetchHandler } from '@atcute/client'; +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'; @@ -6,8 +7,9 @@ import { Client } from './client'; export class Tsky { client: Client; - constructor({ handle }: { handle: FetchHandler }) { - this.client = new Client(handle); + constructor(manager: CredentialManager) { + const xrpc = new XRPC({ handler: manager }); + this.client = new Client(xrpc); } get bsky() {