mirror of
https://github.com/kennethnym/freya
synced 2026-07-04 23:21:13 +01:00
chore: rename aelis to freya (#122)
This commit is contained in:
47
apps/freya-backend/src/weather/provider.ts
Normal file
47
apps/freya-backend/src/weather/provider.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { WeatherSource, type WeatherSourceOptions } from "@freya/source-weatherkit"
|
||||
import { type } from "arktype"
|
||||
|
||||
import type { FeedSourceProvider } from "../session/feed-source-provider.ts"
|
||||
|
||||
export interface WeatherSourceProviderOptions {
|
||||
credentials: WeatherSourceOptions["credentials"]
|
||||
client?: WeatherSourceOptions["client"]
|
||||
}
|
||||
|
||||
export const weatherConfig = type({
|
||||
"+": "reject",
|
||||
"units?": "'metric' | 'imperial'",
|
||||
"hourlyLimit?": "number",
|
||||
"dailyLimit?": "number",
|
||||
})
|
||||
|
||||
export class WeatherSourceProvider implements FeedSourceProvider {
|
||||
readonly sourceId = "freya.weather"
|
||||
readonly configSchema = weatherConfig
|
||||
private readonly credentials: WeatherSourceOptions["credentials"]
|
||||
private readonly client: WeatherSourceOptions["client"]
|
||||
|
||||
constructor(options: WeatherSourceProviderOptions) {
|
||||
this.credentials = options.credentials
|
||||
this.client = options.client
|
||||
}
|
||||
|
||||
async feedSourceForUser(
|
||||
_userId: string,
|
||||
config: unknown,
|
||||
_credentials: unknown,
|
||||
): Promise<WeatherSource> {
|
||||
const parsed = weatherConfig(config)
|
||||
if (parsed instanceof type.errors) {
|
||||
throw new Error(`Invalid weather config: ${parsed.summary}`)
|
||||
}
|
||||
|
||||
return new WeatherSource({
|
||||
credentials: this.credentials,
|
||||
client: this.client,
|
||||
units: parsed.units,
|
||||
hourlyLimit: parsed.hourlyLimit,
|
||||
dailyLimit: parsed.dailyLimit,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user