mirror of
https://github.com/kennethnym/aris.git
synced 2026-06-13 19:11:18 +01:00
chore: rename aelis to freya
This commit is contained in:
42
apps/freya-backend/src/tfl/provider.ts
Normal file
42
apps/freya-backend/src/tfl/provider.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { TflSource, type ITflApi, type TflLineId } from "@freya/source-tfl"
|
||||
import { type } from "arktype"
|
||||
|
||||
import type { FeedSourceProvider } from "../session/feed-source-provider.ts"
|
||||
|
||||
export type TflSourceProviderOptions =
|
||||
| { apiKey: string; client?: never }
|
||||
| { apiKey?: never; client: ITflApi }
|
||||
|
||||
export const tflConfig = type({
|
||||
"+": "reject",
|
||||
"lines?": "string[]",
|
||||
})
|
||||
|
||||
export class TflSourceProvider implements FeedSourceProvider {
|
||||
readonly sourceId = "freya.tfl"
|
||||
readonly configSchema = tflConfig
|
||||
private readonly apiKey: string | undefined
|
||||
private readonly client: ITflApi | undefined
|
||||
|
||||
constructor(options: TflSourceProviderOptions) {
|
||||
this.apiKey = "apiKey" in options ? options.apiKey : undefined
|
||||
this.client = "client" in options ? options.client : undefined
|
||||
}
|
||||
|
||||
async feedSourceForUser(
|
||||
_userId: string,
|
||||
config: unknown,
|
||||
_credentials: unknown,
|
||||
): Promise<TflSource> {
|
||||
const parsed = tflConfig(config)
|
||||
if (parsed instanceof type.errors) {
|
||||
throw new Error(`Invalid TFL config: ${parsed.summary}`)
|
||||
}
|
||||
|
||||
return new TflSource({
|
||||
apiKey: this.apiKey,
|
||||
client: this.client,
|
||||
lines: parsed.lines as TflLineId[] | undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user