import { initTRPC } from "@trpc/server" import type { Request, Response } from "express" import superjson from "superjson" import type { SessionId } from "../session" export interface Context { res?: Response sessionId: SessionId isCrew: boolean } export async function createContext(req: Request, res: Response | undefined): Promise { const sessionId = req.headers["auio-session-id"] if (sessionId === null || typeof sessionId !== "string" || sessionId.length !== 64) throw new Error(`Missing or invalid session ID: ${sessionId}`) return { res, sessionId: sessionId as SessionId, isCrew: req.headers["auio-crew-token"] === process.env.AUIO_CREW_TOKEN } } export const t = initTRPC.context().create({ transformer: superjson })