// User-Agent for Wikimedia API requests. Wikimedia asks automated clients to identify // themselves with contact information; operators can opt in with WIKIDECK_USER_AGENT. // Unset (or blank), each caller keeps its historical default string unchanged. export const ARTICLE_USER_AGENT = 'Wikideck/0.1 (experimental Wikipedia article cards)'; export const ENRICHMENT_USER_AGENT = 'Wikideck/0.1 (Wikipedia off-chain page enrichment)'; const MAX_LENGTH = 256; export function wikimediaUserAgent(fallback: string, env: Record = process.env): string { const configured = env.WIKIDECK_USER_AGENT?.trim(); // Reject header-injection/control characters and oversized values; fall back to the default. if (!configured || configured.length > MAX_LENGTH || !/^[\x20-\x7e]+$/.test(configured)) return fallback; return configured; }