wayfarer-weather/lib/weather/providers/openweather/index.ts
Cayden Schwechten 6250d23297 init
2026-10-31 21:20:16 -05:00

26 lines
962 B
TypeScript

import { readKey } from "../../http";
import type { WeatherProvider } from "../../types";
import { getFreeForecast } from "./free";
import { getOneCallForecast } from "./onecall";
/**
* OpenWeather (the default provider).
*
* Set OPENWEATHER_PLAN in .env.local:
* free (default) → 5 days in 3-hour steps
* onecall → One Call 4.0: 48 hours hourly + daily, plus dew point and UV
*/
const usesOneCall = () => process.env.OPENWEATHER_PLAN === "onecall";
export const openWeather: WeatherProvider = {
id: "openweather",
label: "OpenWeather",
envKey: "OPENWEATHER_API_KEY",
signupUrl: "https://home.openweathermap.org/users/sign_up",
limits: () => (usesOneCall() ? { forecastDays: 8, hourlyStepHours: 1 } : { forecastDays: 5, hourlyStepHours: 3 }),
getForecast(lat, lon) {
const key = readKey("OPENWEATHER_API_KEY");
return usesOneCall() ? getOneCallForecast(lat, lon, key) : getFreeForecast(lat, lon, key);
},
};