import { Client, simpleFetchHandler } from "@atcute/client"; import { resolvePdsEndpoint } from "../identity.ts"; // `com.atproto.repo.listRecords` is a public, unauthenticated query, so the // backfill crawler talks to each PDS with a bare fetch handler — no OAuth session, // no app password. `fetchImpl` is an injection seam for tests (a canned fetch). export function makePdsClient( endpoint: string, fetchImpl?: typeof fetch, ): Client { return new Client({ handler: simpleFetchHandler({ service: endpoint, ...(fetchImpl ? { fetch: fetchImpl } : {}), }), }); } export interface ResolvedPdsClient { client: Client; endpoint: string; } // Resolve a DID's PDS endpoint and build an unauthenticated client for it. // Returns null when the DID document can't be resolved or exposes no PDS. export async function resolvePdsClient( did: string, ): Promise { const endpoint = await resolvePdsEndpoint(did); if (!endpoint) return null; return { client: makePdsClient(endpoint), endpoint }; }