@@ -124,4 +124,51 @@ abstract final class EnvironmentConfig {
124124 final hours = int .tryParse (_env['JWT_EXPIRY_HOURS' ] ?? '1' );
125125 return Duration (hours: hours ?? 1 );
126126 }
127+
128+ /// Retrieves the SendGrid API key from the environment.
129+ ///
130+ /// Throws a [StateError] if the `SENDGRID_API_KEY` is not set.
131+ static String get sendGridApiKey {
132+ final apiKey = _env['SENDGRID_API_KEY' ];
133+ if (apiKey == null || apiKey.isEmpty) {
134+ _log.severe ('SENDGRID_API_KEY not found in environment variables.' );
135+ throw StateError (
136+ 'FATAL: SENDGRID_API_KEY environment variable is not set.' ,
137+ );
138+ }
139+ return apiKey;
140+ }
141+
142+ /// Retrieves the default sender email from the environment.
143+ ///
144+ /// Throws a [StateError] if the `DEFAULT_SENDER_EMAIL` is not set.
145+ static String get defaultSenderEmail {
146+ final email = _env['DEFAULT_SENDER_EMAIL' ];
147+ if (email == null || email.isEmpty) {
148+ _log.severe ('DEFAULT_SENDER_EMAIL not found in environment variables.' );
149+ throw StateError (
150+ 'FATAL: DEFAULT_SENDER_EMAIL environment variable is not set.' ,
151+ );
152+ }
153+ return email;
154+ }
155+
156+ /// Retrieves the SendGrid OTP template ID from the environment.
157+ ///
158+ /// Throws a [StateError] if the `OTP_TEMPLATE_ID` is not set.
159+ static String get otpTemplateId {
160+ final templateId = _env['OTP_TEMPLATE_ID' ];
161+ if (templateId == null || templateId.isEmpty) {
162+ _log.severe ('OTP_TEMPLATE_ID not found in environment variables.' );
163+ throw StateError (
164+ 'FATAL: OTP_TEMPLATE_ID environment variable is not set.' ,
165+ );
166+ }
167+ return templateId;
168+ }
169+
170+ /// Retrieves the SendGrid API URL from the environment, if provided.
171+ ///
172+ /// Returns `null` if the `SENDGRID_API_URL` is not set.
173+ static String ? get sendGridApiUrl => _env['SENDGRID_API_URL' ];
127174}
0 commit comments