Files
aris/apps/aelis-backend/src/tfl/provider.ts
Kenneth 98ce546eff feat: surface per-user credentials to feed source providers (#110)
Add credentials parameter to FeedSourceProvider.feedSourceForUser so
providers can receive decrypted per-user credentials (OAuth tokens,
passwords) from the user_sources table.

Wire CredentialEncryptor into UserSessionManager to handle
encrypt/decrypt. Providers receive plaintext and handle validation
internally. Existing providers ignore the new parameter.

Co-authored-by: Ona <no-reply@ona.com>
2026-04-11 15:18:24 +01:00

43 lines
1.1 KiB
TypeScript

import { TflSource, type ITflApi, type TflLineId } from "@aelis/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 = "aelis.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,
})
}
}