Files
wikideck/server/wikimedia-user-agent.ts
T
claudeandClaude Opus 5.5 e7e51aecdb Night 1: env-configurable Wikimedia User-Agent, WIKIDECK_USER_AGENT (#19)
Default UA unchanged; the testnet sets a contact URL in deploy/night only. Testnet wallet password moves to an env var.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 04:12:48 +00:00

14 lines
871 B
TypeScript

// 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<string, string | undefined> = 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;
}