import type { OAuthUserAgent } from "@atcute/oauth-browser-client"; import { mintServiceAuth, serviceDidForHost } from "$lib/auth/agent"; import type { BobbinContext, XrpcRequestInit } from "./client"; import { jsonGet } from "./_request"; import type * as ShTangledFeedGetTimeline from "./lexicons/types/sh/tangled/feed/getTimeline"; export const TIMELINE_NSID = "sh.tangled.feed.getTimeline"; export const TIMELINE_LIMIT = 50; export interface TimelineOptions { followingOnly?: boolean; limit?: number; cursor?: string; } export const getTimeline = ( ctx: BobbinContext, { followingOnly, limit, cursor }: TimelineOptions = {}, init?: XrpcRequestInit ) => jsonGet( ctx, TIMELINE_NSID, { followingOnly, limit, cursor }, init ); // the viewer is the verified `iss` of a service-auth token now, not a query param, so an // authenticated timeline can only be fetched from the browser where the oauth session lives. export const getTimelineAs = async ( ctx: BobbinContext, agent: OAuthUserAgent, options: TimelineOptions = {}, init?: XrpcRequestInit ) => { const token = await mintServiceAuth(agent, { aud: serviceDidForHost(new URL(ctx.serviceUrl).host), lxm: TIMELINE_NSID }); return getTimeline(ctx, options, { ...init, headers: { ...init?.headers, authorization: `Bearer ${token}` } }); };