forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigService.js
More file actions
98 lines (88 loc) · 2.66 KB
/
Copy pathconfigService.js
File metadata and controls
98 lines (88 loc) · 2.66 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Configuration service for managing environment variables.
* Requirements: #181, #184
*/
const {
DEFAULT_REFERRAL_BONUS_POINTS,
} = require('../config/constants');
/**
* Gets a configuration value with optional default.
* @param {string} key - Environment variable key
* @param {*} defaultValue - Default value if not set
* @returns {*}
*/
function getConfig(key, defaultValue = null) {
return process.env[key] || defaultValue;
}
/**
* Gets a required configuration value or throws an error.
* @param {string} key - Environment variable key
* @returns {string}
*/
function getRequiredConfig(key) {
const value = process.env[key];
if (!value) {
throw new Error(`Required configuration missing: ${key}`);
}
return value;
}
/**
* Gets a numeric configuration value.
* @param {string} key - Environment variable key
* @param {number} defaultValue - Default value if not set
* @returns {number}
*/
function getNumericConfig(key, defaultValue = 0) {
const value = process.env[key];
if (!value) return defaultValue;
const parsed = parseFloat(value);
if (isNaN(parsed)) {
throw new Error(`Invalid numeric configuration for ${key}: ${value}`);
}
return parsed;
}
/**
* Gets a boolean configuration value.
* @param {string} key - Environment variable key
* @param {boolean} defaultValue - Default value if not set
* @returns {boolean}
*/
function getBooleanConfig(key, defaultValue = false) {
const value = process.env[key];
if (!value) return defaultValue;
return value.toLowerCase() === 'true' || value === '1';
}
// Referral configuration
const REFERRAL_BONUS_POINTS = getNumericConfig('REFERRAL_BONUS_POINTS', DEFAULT_REFERRAL_BONUS_POINTS);
// Email configuration
const SMTP_HOST = getConfig('SMTP_HOST');
const SMTP_PORT = getNumericConfig('SMTP_PORT', 587);
const SMTP_USER = getConfig('SMTP_USER');
const SMTP_PASSWORD = getConfig('SMTP_PASSWORD');
const EMAIL_FROM = getConfig('EMAIL_FROM', 'noreply@novarewards.com');
const SENDGRID_API_KEY = getConfig('SENDGRID_API_KEY');
// Stellar configuration
const STELLAR_NETWORK = getRequiredConfig('STELLAR_NETWORK');
const HORIZON_URL = getRequiredConfig('HORIZON_URL');
const ISSUER_PUBLIC = getRequiredConfig('ISSUER_PUBLIC');
// Contract configuration
const NOVA_TOKEN_CONTRACT_ID = getConfig('NOVA_TOKEN_CONTRACT_ID');
const REWARD_POOL_CONTRACT_ID = getConfig('REWARD_POOL_CONTRACT_ID');
module.exports = {
getConfig,
getRequiredConfig,
getNumericConfig,
getBooleanConfig,
REFERRAL_BONUS_POINTS,
SMTP_HOST,
SMTP_PORT,
SMTP_USER,
SMTP_PASSWORD,
EMAIL_FROM,
SENDGRID_API_KEY,
STELLAR_NETWORK,
HORIZON_URL,
ISSUER_PUBLIC,
NOVA_TOKEN_CONTRACT_ID,
REWARD_POOL_CONTRACT_ID,
};