// Centralized, lazy env access. Throws a helpful error if a required // var is missing — keeps "is this set?" out of every callsite. function required(name: string): string { const v = process.env[name]; if (!v) throw new Error(`Missing required env var: ${name}`); return v; } function optional(name: string, fallback = ''): string { return process.env[name] ?? fallback; } export const env = { cf: { accountId: () => required('CF_ACCOUNT_ID'), imagesHash: () => required('CF_IMAGES_HASH'), imagesApiToken: () => required('CF_IMAGES_API_TOKEN'), }, stripe: { secretKey: () => required('STRIPE_SECRET_KEY'), publishableKey: () => required('STRIPE_PUBLISHABLE_KEY'), webhookSecret: () => required('STRIPE_WEBHOOK_SECRET'), }, email: { from: () => optional('EMAIL_FROM', 'Lumen & Gesso '), }, pinterest: { // Two supported wiring modes: // // 1. **Trial / direct-bearer** (simplest): paste the access token from // Pinterest's dev console into PINTEREST_ACCESS_TOKEN. No OAuth flow // needed; works as long as the token is valid (Pinterest's trial // tokens are long-lived but not refreshable). // // 2. **OAuth refresh flow** (long-term): set CLIENT_ID + CLIENT_SECRET, // run /admin/pinterest → Connect, paste the captured refresh token // into PINTEREST_REFRESH_TOKEN. Auto-mints a new access token every // ~25 minutes; the refresh token lasts ~1 year. // // pinterest.ts prefers mode 1 if ACCESS_TOKEN is set; otherwise mode 2. accessTokenMaybe: () => optional('PINTEREST_ACCESS_TOKEN'), clientId: () => required('PINTEREST_CLIENT_ID'), clientSecret: () => required('PINTEREST_CLIENT_SECRET'), refreshToken: () => required('PINTEREST_REFRESH_TOKEN'), // Read without throwing — used by the setup page to render status. clientIdMaybe: () => optional('PINTEREST_CLIENT_ID'), refreshTokenMaybe: () => optional('PINTEREST_REFRESH_TOKEN'), }, cron: { // Shared secret Vercel Cron sends as `Authorization: Bearer `. // Guards /api/cron/* so only the scheduler can trigger those routes. secret: () => required('CRON_SECRET'), }, site: { url: () => optional('NEXT_PUBLIC_SITE_URL', 'http://localhost:3000'), // Allowlist for /admin access. Anyone whose verified email is // in this set can reach the admin UI; everyone else is bounced to // /orders. Defaults to admin@lumengesso.com (a Cloudflare Email // Routing alias that forwards to the owner's personal gmail). adminEmails: () => optional('ADMIN_EMAILS', 'admin@lumengesso.com') .split(',') .map(s => s.trim().toLowerCase()) .filter(Boolean), // Where internal studio notifications go (new-commission emails, // revision requests, etc.). Separate from adminEmails so the // "where it goes" inbox can differ from the "who can log in" // allowlist. Defaults to orders@lumengesso.com. studioEmail: () => optional('STUDIO_EMAIL', 'orders@lumengesso.com'), }, };