@@ -60,41 +60,30 @@ abstract final class EnvironmentConfig {
60
60
return env; // Return even if fallback
61
61
}
62
62
63
+ static String _getRequiredEnv (String key) {
64
+ final value = _env[key];
65
+ if (value == null || value.isEmpty) {
66
+ _log.severe ('$key not found in environment variables.' );
67
+ throw StateError ('FATAL: $key environment variable is not set.' );
68
+ }
69
+ return value;
70
+ }
71
+
63
72
/// Retrieves the database connection URI from the environment.
64
73
///
65
74
/// The value is read from the `DATABASE_URL` environment variable.
66
75
///
67
76
/// Throws a [StateError] if the `DATABASE_URL` environment variable is not
68
77
/// set, as the application cannot function without it.
69
- static String get databaseUrl {
70
- final dbUrl = _env['DATABASE_URL' ];
71
- if (dbUrl == null || dbUrl.isEmpty) {
72
- _log.severe ('DATABASE_URL not found in environment variables.' );
73
- throw StateError (
74
- 'FATAL: DATABASE_URL environment variable is not set. '
75
- 'The application cannot start without a database connection.' ,
76
- );
77
- }
78
- return dbUrl;
79
- }
78
+ static String get databaseUrl => _getRequiredEnv ('DATABASE_URL' );
80
79
81
80
/// Retrieves the JWT secret key from the environment.
82
81
///
83
82
/// The value is read from the `JWT_SECRET_KEY` environment variable.
84
83
///
85
84
/// Throws a [StateError] if the `JWT_SECRET_KEY` environment variable is not
86
85
/// set, as the application cannot function without it.
87
- static String get jwtSecretKey {
88
- final jwtKey = _env['JWT_SECRET_KEY' ];
89
- if (jwtKey == null || jwtKey.isEmpty) {
90
- _log.severe ('JWT_SECRET_KEY not found in environment variables.' );
91
- throw StateError (
92
- 'FATAL: JWT_SECRET_KEY environment variable is not set. '
93
- 'The application cannot start without a JWT secret.' ,
94
- );
95
- }
96
- return jwtKey;
97
- }
86
+ static String get jwtSecretKey => _getRequiredEnv ('JWT_SECRET_KEY' );
98
87
99
88
/// Retrieves the current environment mode (e.g., 'development').
100
89
///
@@ -127,44 +116,18 @@ abstract final class EnvironmentConfig {
127
116
/// Retrieves the SendGrid API key from the environment.
128
117
///
129
118
/// Throws a [StateError] if the `SENDGRID_API_KEY` is not set.
130
- static String get sendGridApiKey {
131
- final apiKey = _env['SENDGRID_API_KEY' ];
132
- if (apiKey == null || apiKey.isEmpty) {
133
- _log.severe ('SENDGRID_API_KEY not found in environment variables.' );
134
- throw StateError (
135
- 'FATAL: SENDGRID_API_KEY environment variable is not set.' ,
136
- );
137
- }
138
- return apiKey;
139
- }
119
+ static String get sendGridApiKey => _getRequiredEnv ('SENDGRID_API_KEY' );
140
120
141
121
/// Retrieves the default sender email from the environment.
142
122
///
143
123
/// Throws a [StateError] if the `DEFAULT_SENDER_EMAIL` is not set.
144
- static String get defaultSenderEmail {
145
- final email = _env['DEFAULT_SENDER_EMAIL' ];
146
- if (email == null || email.isEmpty) {
147
- _log.severe ('DEFAULT_SENDER_EMAIL not found in environment variables.' );
148
- throw StateError (
149
- 'FATAL: DEFAULT_SENDER_EMAIL environment variable is not set.' ,
150
- );
151
- }
152
- return email;
153
- }
124
+ static String get defaultSenderEmail =>
125
+ _getRequiredEnv ('DEFAULT_SENDER_EMAIL' );
154
126
155
127
/// Retrieves the SendGrid OTP template ID from the environment.
156
128
///
157
129
/// Throws a [StateError] if the `OTP_TEMPLATE_ID` is not set.
158
- static String get otpTemplateId {
159
- final templateId = _env['OTP_TEMPLATE_ID' ];
160
- if (templateId == null || templateId.isEmpty) {
161
- _log.severe ('OTP_TEMPLATE_ID not found in environment variables.' );
162
- throw StateError (
163
- 'FATAL: OTP_TEMPLATE_ID environment variable is not set.' ,
164
- );
165
- }
166
- return templateId;
167
- }
130
+ static String get otpTemplateId => _getRequiredEnv ('OTP_TEMPLATE_ID' );
168
131
169
132
/// Retrieves the SendGrid API URL from the environment, if provided.
170
133
///
0 commit comments