mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: added more mature secrets handling
This commit is contained in:
1 parent
c72bfa9f71
commit
eca7cbbbeb
26 files changed
+81
-75
No files matched your search
@@ -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}');
|
||||
}
|
||||
@@ -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>;
|
||||
Reference in new issue
Block a user