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

21 lines
510 B
TypeScript
Raw Normal View History

2023-09-09 03:05:59 +00:00
import { config } from 'dotenv';
config();
2023-09-23 21:51:00 +00:00
export const SECRET_KEYS = ['DISCORD_TOKEN', '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 {
2023-09-19 15:52:39 +00:00
if (!(key in process.env)) throw new Error(`Secret ${key} not provided`);
2023-07-16 18:26:33 +00:00
return process.env[key]!;
},
}),
{},
2023-07-18 00:17:00 +00:00
) as Record<SECRET, string>;