// Accès à l'API Météo France (portail-api.meteofrance.fr) via API Key longue durée. // // Le portail propose 2 modes : (a) token OAuth2 court 1h (pas adapté en prod // sans flow refresh) et (b) API Key permanente / longue durée. On utilise (b). // // Configuration via env : // METEOFRANCE_API_KEY → clé permanente, envoyée en header `apikey: ` // (PAS `Authorization: Bearer` — c'est le format des // tokens OAuth2 courts, pas des API Keys du portail). // // Quand la clé approche de l'expiration (cf. duration choisie à la création), // régénérer côté portail puis mettre à jour le vault `Infra/Météo France API`, // puis `make env` + redeploy. Voir CLAUDE.md projet info-canicule. const BASE = 'https://public-api.meteofrance.fr'; export async function fetchMF(path: string, init: RequestInit = {}): Promise { const key = process.env.METEOFRANCE_API_KEY; if (!key) { throw new Error('METEOFRANCE_API_KEY missing in env'); } // Le portail Météo France utilise le header `apikey:` pour les API Keys // longue durée (différent du `Authorization: Bearer` des tokens OAuth2 courts). return fetch(`${BASE}${path}`, { ...init, headers: { ...init.headers, apikey: key, Accept: 'application/json', }, }); } export function hasMeteoFranceCredentials(): boolean { return Boolean(process.env.METEOFRANCE_API_KEY); }