import { connectJetstream, type IngestDeps, type IngestIndex } from './index/ingest.ts'; import { resolveDidPds } from './identity.ts'; import { upstream, type Upstream } from './upstream.ts'; /** The worker's composition root for outbound traffic: the one place that reads `globalThis.fetch`, * and only to wrap it. The UA test builds its dependencies here too, so it checks what ships. */ export interface OutboundEnv { /** The contact address our User-Agent names. Unset means `https://nibling.dev/contact`. */ CONTACT_URL?: string; } export function outbound(env: OutboundEnv): Upstream { return upstream(globalThis.fetch, env.CONTACT_URL || undefined); } export interface IngestEnv extends OutboundEnv { JETSTREAM_URL: string; RELAY_URL: string; } export function ingestDeps(env: IngestEnv, index: IngestIndex, now: () => number): IngestDeps { const fetch = outbound(env); return { jetstreamUrl: env.JETSTREAM_URL, connect: (url) => connectJetstream(fetch, url), index, backfill: { relayUrl: env.RELAY_URL, fetch, resolvePds: (did) => resolveDidPds(did, fetch) }, now, }; }