1import { isDid, type AtprotoDid } from "@atcute/lexicons/syntax";
2import { env } from "process";
3
4interface Config {
5 repoDid: AtprotoDid;
6 appPass: string;
7 hostName?: string;
8 hostDescription?: string;
9}
10
11const required = (value: unknown) => typeof value !== "undefined";
12
13const getConfig = (prefix: string): Config => {
14 const get = <Value>(
15 name: string,
16 check: (value: unknown) => boolean = () => true,
17 ): Value => {
18 const value = env[`${prefix}${name}`];
19 if (check(value)) {
20 return value as Value;
21 }
22 throw `config key ${name} is invalid`;
23 };
24 return {
25 repoDid: get("REPO_DID", isDid),
26 appPass: get("APP_PASSWORD", required),
27 hostName: get("HOST_NAME"),
28 hostDescription: get("HOST_DESCRIPTION"),
29 };
30};
31
32export const config = getConfig("BAROMETER_");