- Replace getEnv with getEnvVar for environment variable access - Update MailgunConfig types to allow undefined values - Enhance isMailgunConfigured to check for undefined and empty values - Update isDevelopmentMode to check production status - Improve test mocks for environment variable handling
55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
// Mailgun Configuration
|
|
// This file handles Mailgun credentials and configuration
|
|
|
|
import { getEnvVar, isProduction } from '../utils/env';
|
|
|
|
export interface MailgunConfig {
|
|
apiKey: string | undefined;
|
|
domain: string | undefined;
|
|
baseUrl: string;
|
|
fromName: string;
|
|
fromEmail: string | undefined;
|
|
}
|
|
|
|
// Default configuration for development
|
|
const defaultConfig: MailgunConfig = {
|
|
apiKey: 'demo-key',
|
|
domain: 'demo.mailgun.org',
|
|
baseUrl: 'https://api.mailgun.net/v3',
|
|
fromName: 'Medication Reminder',
|
|
fromEmail: 'noreply@demo.mailgun.org',
|
|
};
|
|
|
|
// Load configuration from environment variables or use defaults
|
|
export const getMailgunConfig = (): MailgunConfig => {
|
|
return {
|
|
apiKey: getEnvVar('VITE_MAILGUN_API_KEY'),
|
|
domain: getEnvVar('VITE_MAILGUN_DOMAIN'),
|
|
baseUrl: getEnvVar('VITE_MAILGUN_BASE_URL', defaultConfig.baseUrl),
|
|
fromName: getEnvVar('VITE_MAILGUN_FROM_NAME', defaultConfig.fromName),
|
|
fromEmail: getEnvVar('VITE_MAILGUN_FROM_EMAIL'),
|
|
};
|
|
};
|
|
|
|
// Check if Mailgun is properly configured (not using demo values)
|
|
export const isMailgunConfigured = (): boolean => {
|
|
const config = getMailgunConfig();
|
|
return (
|
|
config.apiKey !== defaultConfig.apiKey &&
|
|
config.domain !== defaultConfig.domain &&
|
|
config.fromEmail !== defaultConfig.fromEmail &&
|
|
config.apiKey !== undefined &&
|
|
config.apiKey !== '' &&
|
|
config.apiKey.trim().length > 0 &&
|
|
config.domain !== undefined &&
|
|
config.domain !== '' &&
|
|
config.fromEmail !== undefined &&
|
|
config.fromEmail !== ''
|
|
);
|
|
};
|
|
|
|
// Development mode check
|
|
export const isDevelopmentMode = (): boolean => {
|
|
return !isProduction() && !isMailgunConfigured();
|
|
};
|