/ src / utils / email-compliance.js
email-compliance.js
 1  /**
 2   * Email Compliance Utilities
 3   * Determines which countries require CAN-SPAM compliance elements
 4   */
 5  
 6  /**
 7   * Countries that require CAN-SPAM style compliance (physical address + unsubscribe)
 8   * Based on:
 9   * - CAN-SPAM Act: US, Canada
10   * - CASL: Canada (stricter than CAN-SPAM)
11   * - SPAM Act: Australia
12   * - PECR/GDPR: UK, EU countries
13   * - UDPA: New Zealand
14   */
15  const CAN_SPAM_COUNTRIES = new Set([
16    // North America
17    'US', // CAN-SPAM Act
18    'CA', // CASL (Canadian Anti-Spam Legislation)
19  
20    // Oceania
21    'AU', // Spam Act 2003
22    'NZ', // Unsolicited Electronic Messages Act
23  
24    // Europe (GDPR + PECR)
25    'UK', // UK GDPR + PECR
26    'GB', // Alternative code for UK
27    'DE', // Germany - GDPR
28    'FR', // France - GDPR
29    'IT', // Italy - GDPR
30    'ES', // Spain - GDPR
31    'NL', // Netherlands - GDPR
32    'BE', // Belgium - GDPR
33    'AT', // Austria - GDPR
34    'SE', // Sweden - GDPR
35    'DK', // Denmark - GDPR
36    'NO', // Norway - GDPR (EEA)
37    'FI', // Finland - GDPR
38    'PL', // Poland - GDPR
39    'IE', // Ireland - GDPR
40    'PT', // Portugal - GDPR
41    'GR', // Greece - GDPR
42    'CZ', // Czech Republic - GDPR
43    'RO', // Romania - GDPR
44    'HU', // Hungary - GDPR
45    'CH', // Switzerland - similar to GDPR
46  ]);
47  
48  /**
49   * Check if a country requires CAN-SPAM compliance elements
50   * @param {string} countryCode - ISO 3166-1 alpha-2 country code (e.g., 'US', 'AU', 'UK')
51   * @returns {boolean} - True if country requires physical address and unsubscribe
52   */
53  export function requiresCanSpamCompliance(countryCode) {
54    if (!countryCode) {
55      // Default to requiring compliance if country unknown
56      return true;
57    }
58  
59    return CAN_SPAM_COUNTRIES.has(countryCode.toUpperCase());
60  }
61  
62  /**
63   * Check if a country requires physical address in emails
64   * @param {string} countryCode - ISO 3166-1 alpha-2 country code
65   * @returns {boolean}
66   */
67  export function requiresPhysicalAddress(countryCode) {
68    return requiresCanSpamCompliance(countryCode);
69  }
70  
71  /**
72   * Check if a country requires unsubscribe link in emails
73   * @param {string} countryCode - ISO 3166-1 alpha-2 country code
74   * @returns {boolean}
75   */
76  export function requiresUnsubscribeLink(countryCode) {
77    // Most countries require unsubscribe, even if not CAN-SPAM
78    // Better to always include it as best practice
79    return true;
80  }