/** * llmindex.io — public API helpers (envelope, maintainer credit, caching) * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * License: Proprietary — © Simon-Pierre Boucher, all rights reserved */ import 'server-only'; import { NextResponse } from 'next/server'; export const MAINTAINER = `${process.env.MAINTAINER_NAME ?? 'Simon-Pierre Boucher'} <${ process.env.MAINTAINER_EMAIL ?? 'contact@spboucher.ai' }>`; /** v1 envelope. Breaking changes go to /api/v2 — never mutate these shapes. */ export function apiJson(data: Record, opts?: { cacheSeconds?: number; status?: number }) { const res = NextResponse.json( { ...data, maintainer: MAINTAINER }, { status: opts?.status ?? 200 }, ); const cache = opts?.cacheSeconds ?? 0; if (cache > 0) { res.headers.set('Cache-Control', `public, s-maxage=${cache}, stale-while-revalidate=${cache}`); } return res; } export function apiError(status: number, error: string) { return NextResponse.json({ error, maintainer: MAINTAINER }, { status }); }