All files / src/common/config email.ts

50% Statements 12/24
0% Branches 0/2
100% Functions 0/0
50% Lines 12/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 401x     1x     1x     1x 1x     1x 1x 1x     1x         1x                         1x   1x  
import { logger } from "../utils/logger";
 
// Initialize logger
const log = logger;
 
// Email configuration with environment variable support
const emailConfig = {
  // Default domain for email aliases
  // Can be overridden by VITE_EMAIL_DEFAULT_DOMAIN environment variable
  defaultDomain: 'newsletterhub.com',
};
 
// Only try to access import.meta.env in browser environment
if (typeof import.meta !== 'undefined' && import.meta.env) {
  emailConfig.defaultDomain = import.meta.env.VITE_EMAIL_DEFAULT_DOMAIN || emailConfig.defaultDomain;
}
 
// Fallback to process.env for test environment
if (process.env.VITE_EMAIL_DEFAULT_DOMAIN) {
  emailConfig.defaultDomain = process.env.VITE_EMAIL_DEFAULT_DOMAIN;
}
 
// Validate configuration
if (!emailConfig.defaultDomain.includes(".")) {
  log.warn("Invalid default email domain. Using fallback domain.", {
    component: "EmailConfig",
    action: "validate_domain",
    metadata: {
      invalidDomain: emailConfig.defaultDomain,
      fallbackDomain: "newsletterhub.com",
    },
  });
  emailConfig.defaultDomain = "newsletterhub.com";
}
 
// Freeze config after validation
Object.freeze(emailConfig);
 
export default emailConfig;