sms-compliance.js
1 /** 2 * SMS Compliance Utilities 3 * Determines which countries require TCPA-style compliance 4 */ 5 6 /** 7 * Countries that require TCPA-style compliance for SMS 8 * TCPA (Telephone Consumer Protection Act) requirements: 9 * - Sender identification in message body 10 * - Informational-only content (no promotional language without consent) 11 * - Clear opt-out instructions 12 * - Business hours restrictions 13 * 14 * Similar laws exist in: 15 * - US: TCPA (Telephone Consumer Protection Act) 16 * - CA: CASL (Canadian Anti-Spam Legislation) - covers SMS 17 * - AU: Spam Act 2003 - covers SMS 18 * - UK: PECR (Privacy and Electronic Communications Regulations) 19 * - EU countries: GDPR + national telecom regulations 20 */ 21 const TCPA_COUNTRIES = new Set([ 22 // North America 23 'US', // TCPA 24 'CA', // CASL 25 26 // Oceania (Australia has Spam Act, but less strict than TCPA for SMS) 27 // 'AU', // Spam Act 2003 - less strict, doesn't require sender ID in body 28 // 'NZ', // Less strict than US 29 30 // Europe (GDPR + PECR apply, but less strict SMS rules than TCPA) 31 // UK, EU countries don't require sender ID in SMS body like TCPA does 32 ]); 33 34 /** 35 * Check if a country requires TCPA-style SMS compliance 36 * (sender ID in message body, no promotional language) 37 * 38 * @param {string} countryCode - ISO 3166-1 alpha-2 country code (e.g., 'US', 'CA') 39 * @returns {boolean} - True if country requires TCPA compliance 40 */ 41 export function requiresTcpaCompliance(countryCode) { 42 if (!countryCode) { 43 // Default to NOT requiring TCPA compliance if country unknown 44 // Better to be less restrictive than overly cautious 45 return false; 46 } 47 48 return TCPA_COUNTRIES.has(countryCode.toUpperCase()); 49 } 50 51 /** 52 * Check if a country requires sender identification in SMS body 53 * @param {string} countryCode - ISO 3166-1 alpha-2 country code 54 * @returns {boolean} 55 */ 56 export function requiresSenderIdInBody(countryCode) { 57 return requiresTcpaCompliance(countryCode); 58 } 59 60 /** 61 * Check if a country prohibits promotional language in initial SMS 62 * @param {string} countryCode - ISO 3166-1 alpha-2 country code 63 * @returns {boolean} 64 */ 65 export function prohibitsPromotionalLanguage(countryCode) { 66 return requiresTcpaCompliance(countryCode); 67 } 68 69 /** 70 * Get sender ID string for SMS based on env vars 71 * Format: "-{SENDER_NAME}, {SENDER_COMPANY}" 72 * Example: "-Mike, Audit&Fix" 73 * 74 * @returns {string} - Sender ID string 75 */ 76 export function getSmsEnderId() { 77 const senderName = process.env.SENDER_NAME || 'Team'; 78 const senderCompany = process.env.SENDER_COMPANY || 'Support'; 79 80 // Keep it short to save SMS characters 81 // Use short company name if available (e.g., "Audit&Fix" instead of "Audit & Fix Pty Ltd") 82 const companyShort = senderCompany 83 .replace(' Pty Ltd', '') 84 .replace(' LLC', '') 85 .replace(' Inc', ''); 86 87 return `-${senderName}, ${companyShort}`; 88 }