mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-24 19:01:17 +00:00
Add "+": "reject" to all arktype schemas so undeclared keys return 400. Sources without a configSchema now reject the config field entirely at the HTTP layer. Co-authored-by: Ona <no-reply@ona.com>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { WeatherSource, type WeatherSourceOptions } from "@aelis/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 = "aelis.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): 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,
|
|
})
|
|
}
|
|
}
|