mirror of
https://github.com/kennethnym/aris.git
synced 2026-02-02 13:11:17 +00:00
Implements FeedSource for WeatherKit API. Depends on location source, provides weather context for downstream sources, and produces weather feed items. Co-authored-by: Ona <no-reply@ona.com>
@aris/source-weatherkit
Weather feed source using Apple WeatherKit API.
Usage
Basic Setup
import { WeatherSource, Units } from "@aris/source-weatherkit"
const weatherSource = new WeatherSource({
credentials: {
privateKey: process.env.WEATHERKIT_PRIVATE_KEY!,
keyId: process.env.WEATHERKIT_KEY_ID!,
teamId: process.env.WEATHERKIT_TEAM_ID!,
serviceId: process.env.WEATHERKIT_SERVICE_ID!,
},
units: Units.metric,
})
With Feed Source Graph
import { LocationSource } from "@aris/source-location"
import { WeatherSource } from "@aris/source-weatherkit"
const locationSource = new LocationSource()
const weatherSource = new WeatherSource({ credentials })
// Weather depends on location - graph handles ordering
const sources = [locationSource, weatherSource]
Reading Weather Context
Downstream sources can access weather data:
import { contextValue } from "@aris/core"
import { WeatherKey } from "@aris/source-weatherkit"
async function fetchContext(context: Context) {
const weather = contextValue(context, WeatherKey)
if (weather?.condition === "Rain") {
// Suggest umbrella, indoor activities, etc.
}
if (weather && weather.uvIndex > 7) {
// Suggest sunscreen
}
}
Exports
| Export | Description |
|---|---|
WeatherSource |
FeedSource implementation |
WeatherKey |
Context key for simplified weather data |
Weather |
Type for weather context |
Units |
metric or imperial |
Options
| Option | Default | Description |
|---|---|---|
credentials |
- | WeatherKit API credentials |
client |
- | Custom WeatherKit client |
hourlyLimit |
12 |
Max hourly forecasts |
dailyLimit |
7 |
Max daily forecasts |
units |
metric |
Temperature/speed units |
Context
Provides simplified weather context for downstream sources:
interface Weather {
temperature: number
temperatureApparent: number
condition: ConditionCode
humidity: number
uvIndex: number
windSpeed: number
daylight: boolean
}
Feed Items
Produces feed items:
weather-current- Current conditionsweather-hourly- Hourly forecasts (up tohourlyLimit)weather-daily- Daily forecasts (up todailyLimit)weather-alert- Weather alerts when present
Priority is adjusted based on weather severity (storms, extreme temperatures).