-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.service.ts
More file actions
216 lines (171 loc) · 5.45 KB
/
config.service.ts
File metadata and controls
216 lines (171 loc) · 5.45 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { Injectable } from '@nestjs/common';
import { ConfigService as NestConfigService } from '@nestjs/config';
@Injectable()
export class ConfigService {
private static instance: ConfigService;
constructor(private nestConfigService: NestConfigService) {
if (ConfigService.instance) {
return ConfigService.instance;
}
ConfigService.instance = this;
}
get databaseHost(): string {
return this.nestConfigService.get<string>('DB_HOST') ?? 'localhost';
}
get databasePort(): number {
return Number(this.nestConfigService.get<number>('DB_PORT') ?? 3306);
}
get databaseUsername(): string {
return this.nestConfigService.get<string>('DB_USERNAME') ?? 'root';
}
get databasePassword(): string {
return this.nestConfigService.get<string>('DB_PASSWORD') ?? '';
}
get databaseName(): string {
return this.nestConfigService.get<string>('DB_NAME') ?? 'snapnet';
}
get databaseUrl(): string {
return this.nestConfigService.get<string>('DATABASE_URL');
}
get appUrl(): string {
return this.nestConfigService.get<string>('APP_URL') || 'http://localhost';
}
get jwtSecret(): string {
return this.nestConfigService.get<string>('JWT_SECRET');
}
get jwtExpirationTime(): string {
return this.nestConfigService.get<string>('JWT_EXPIRATION_TIME') || '1h';
}
get port(): number {
return this.nestConfigService.get<number>('PORT') || 3000;
}
get nodeEnv(): string {
return this.nestConfigService.get<string>('NODE_ENV') || 'development';
}
// Redis configuration
get redisHost(): string {
return this.nestConfigService.get<string>('REDIS_HOST') || 'localhost';
}
get redisPort(): number {
return this.nestConfigService.get<number>('REDIS_PORT') || 6379;
}
get redisUsername(): string | undefined {
return this.nestConfigService.get<string>('REDIS_USERNAME');
}
get redisPassword(): string | undefined {
return this.nestConfigService.get<string>('REDIS_PASSWORD');
}
get redisDb(): number {
return this.nestConfigService.get<number>('REDIS_DB') || 0;
}
// Mail configuration
get mailHost(): string {
return this.nestConfigService.get<string>('SMTP_HOST') || 'smtp.gmail.com';
}
get mailPort(): number {
return this.nestConfigService.get<number>('SMTP_PORT') || 587;
}
get mailUsername(): string {
return this.nestConfigService.get<string>('SMTP_USER') || '';
}
get mailPassword(): string {
return this.nestConfigService.get<string>('SMTP_PASS') || '';
}
get mailFrom(): string {
return (
this.nestConfigService.get<string>('SMTP_FROM') || 'noreply@egwu.com'
);
}
get appName(): string {
return this.nestConfigService.get<string>('APP_NAME') || 'Snapnet';
}
get adminEmail(): string {
return (
this.nestConfigService.get<string>('ADMIN_EMAIL') || 'admin@snapnet.com'
);
}
// JWT configuration
get jwtAccessSecret(): string {
return this.nestConfigService.get<string>('JWT_ACCESS_SECRET');
}
get jwtRefreshSecret(): string {
return this.nestConfigService.get<string>('JWT_REFRESH_SECRET');
}
get jwtAccessExpiry(): string {
return this.nestConfigService.get<string>('JWT_ACCESS_EXPIRY');
}
get jwtRefreshExpiry(): string {
return this.nestConfigService.get<string>('JWT_REFRESH_EXPIRY');
}
// Auth tokens TTL (in seconds)
get accessTokenTtl(): number {
return this.nestConfigService.get<number>('ACCESS_TOKEN_TTL') || 3600; // 1 hour
}
get refreshTokenTtl(): number {
return this.nestConfigService.get<number>('REFRESH_TOKEN_TTL') || 604800; // 7 days
}
// Cache configuration
get cacheMaxItems(): number {
return this.nestConfigService.get<number>('CACHE_MAX_ITEMS') || 1000;
}
// Rate limit configuration
get rateLimitMaxRequests(): number {
return this.nestConfigService.get<number>('RATE_LIMIT_MAX_REQUESTS') || 3;
}
get rateLimitWindowMs(): number {
return this.nestConfigService.get<number>('RATE_LIMIT_WINDOW_MS') || 60000; // 1 minute
}
// Return the default TTL for a given key
get defaultTTL(): number {
return this.nestConfigService.get<number>('DEFAULT_TTL') || 60000;
}
get cacheTTL(): number {
return this.nestConfigService.get<number>('CACHE_TTL') || 60000;
}
get rabbitmqExchange(): string {
return (
this.nestConfigService.get<string>('RABBITMQ_EXCHANGE') ||
'workforce.events'
);
}
get rabbitmqUrl(): string {
return (
this.nestConfigService.get<string>('RABBITMQ_URL') ||
'amqp://guest:guest@localhost:5672'
);
}
get rabbitmqDlq(): string {
return (
this.nestConfigService.get<string>('RABBITMQ_DLQ') || 'leave.requests.dlq'
);
}
get retryStrategy(): string {
return (
this.nestConfigService.get<string>('RETRY_STRATEGY') || 'exponential'
);
}
get retryFixedDelayMs(): number {
return Number(
this.nestConfigService.get<number>('RETRY_FIXED_DELAY_MS') ?? 2000
);
}
get retryBaseMs(): number {
const base = Number(
this.nestConfigService.get<number>('RETRY_BASE_MS') ?? 1000
);
return base;
}
get retryCapMs(): number {
const cap = Number(
this.nestConfigService.get<number>('RETRY_CAP_MS') ?? 30000
);
return cap;
}
get emailMaxRetries(): number {
return Number(this.nestConfigService.get<number>('EMAIL_MAX_RETRIES') ?? 5);
}
// Generic getter method for any config value
get<T = any>(key: string): T {
return this.nestConfigService.get<T>(key);
}
}