feat: added more mature secrets handling

This commit is contained in:
TresAbhi committed 2023-07-16 18:26:33 +00:00
1 parent c72bfa9f71
commit eca7cbbbeb
26 files changed
+81 -75

No files matched your search

-9
View File
@@ -1,9 +0,0 @@
export const DISCORD_TOKEN = process.env.DISCORD_TOKEN!;
export const WARGAMING_APPLICATION_ID = process.env.WARGAMING_APPLICATION_ID!;
if (!DISCORD_TOKEN) {
throw new Error('No Discord token provided');
}
if (!WARGAMING_APPLICATION_ID) {
throw new Error('No Wargaming application id provided}');
}
+15
View File
@@ -0,0 +1,15 @@
const SECRET_KEYS = ['DISCORD_TOKEN', 'WARGAMING_APPLICATION_ID'] as const;
type SECRET_KEY = typeof SECRET_KEYS extends readonly (infer T)[] ? T : never;
export const secrets = SECRET_KEYS.reduce<Partial<Record<SECRET_KEY, string>>>(
(accumulator, key) => ({
...accumulator,
get [key](): string {
if (!(key in process.env)) throw new Error(`Key ${key} not provided`);
return process.env[key]!;
},
}),
{},
) as Record<SECRET_KEY, string>;