import { isDid, type AtprotoDid } from "@atcute/lexicons/syntax"; import { env } from "process"; interface Config { repoDid: AtprotoDid; appPass: string; hostName?: string; hostDescription?: string; } const required = (value: unknown) => typeof value !== "undefined"; const getConfig = (prefix: string): Config => { const get = ( name: string, check: (value: unknown) => boolean = () => true, ): Value => { const value = env[`${prefix}${name}`]; if (check(value)) return value as Value; throw `config key ${name} is invalid`; }; return { repoDid: get("REPO_DID", isDid), appPass: get("APP_PASSWORD", required), hostName: get("HOST_NAME"), hostDescription: get("HOST_DESCRIPTION"), }; }; export const config = getConfig("BAROMETER_");