Files
blitzkit/src/core/node/secrets.ts
T

21 lines
499 B
TypeScript
Raw Normal View History

2023-07-18 00:17:00 +00:00
export const SECRET_KEYS = [
'DISCORD_TOKEN',
'WARGAMING_APPLICATION_ID',
'GH_TOKEN',
] as const;
2023-07-16 18:26:33 +00:00
2023-07-18 00:17:00 +00:00
export type SECRET = typeof SECRET_KEYS extends readonly (infer T)[]
? T
: never;
2023-07-16 18:26:33 +00:00
2023-07-18 00:17:00 +00:00
export const secrets = SECRET_KEYS.reduce<Partial<Record<SECRET, string>>>(
2023-07-16 18:26:33 +00:00
(accumulator, key) => ({
...accumulator,
get [key](): string {
if (!(key in process.env)) throw new Error(`Key ${key} not provided`);
return process.env[key]!;
},
}),
{},
2023-07-18 00:17:00 +00:00
) as Record<SECRET, string>;