import type { Config } from "./config.js"; import { NocoDBClient } from "./services/nocodb.js"; import { Mailer } from "./services/mailer.js"; import { RedeemQueue } from "./services/redeemQueue.js"; /** Shared services wired once at startup and hung off the Fastify instance. */ export interface AppContext { config: Config; nocodb: NocoDBClient; mailer: Mailer; queue: RedeemQueue; } export function buildContext(config: Config): AppContext { return { config, nocodb: new NocoDBClient(config), mailer: new Mailer(config), queue: new RedeemQueue(), }; } // Ambient module augmentation so `fastify.ctx` and `request.user` are typed. declare module "fastify" { interface FastifyInstance { ctx: AppContext; } } declare module "@fastify/jwt" { interface FastifyJWT { payload: { role: "staff" }; user: { role: "staff" }; } }