-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathconfig.ts
More file actions
46 lines (36 loc) · 1.18 KB
/
config.ts
File metadata and controls
46 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const variableKeysMap = {
coreSubgraphUrl: "CORE_SUBGRAPH_URL",
dtrSubgraphUrl: "DTR_SUBGRAPH_URL",
graphApiKey: "GRAPH_API_KEY",
ipfsUploadUrl: "IPFS_UPLOAD_URL",
disputeArchiveAddress: "DISPUTE_ARCHIVE_ADDRESS",
alchemyApiKey: "ALCHEMY_API_KEY",
privateKey: "PRIVATE_KEY",
} as const;
type VariableKey = keyof typeof variableKeysMap;
type EnvConfig = Record<VariableKey, string>;
export const getEnvConfig = (): EnvConfig => {
const config: EnvConfig = {
coreSubgraphUrl: "",
dtrSubgraphUrl: "",
graphApiKey: "",
ipfsUploadUrl: "",
disputeArchiveAddress: "",
alchemyApiKey: "",
privateKey: "",
};
for (const key of Object.keys(variableKeysMap) as VariableKey[]) {
const envKey = variableKeysMap[key];
const value = process.env[envKey];
if (!value || value.trim() === "") throw new EnvVariableNotConfiguredError(envKey);
config[key] = value;
}
return config;
};
class EnvVariableNotConfiguredError extends Error {
constructor(variableKey: string) {
super(`${variableKey} not configured!`);
Object.setPrototypeOf(this, EnvVariableNotConfiguredError.prototype);
this.name = "EnvVariableNotConfiguredError";
}
}