// services/enrichment/normalizers.js // // Shared normalization helpers for AV device enrichment (MDM, RED, OptiSigns, Atlas, etc.). // Central place for name/MAC/RED-ID canonicalization so we don't have 4-5 copies. // // Re-exports normalizePlayerName from utils for convenience in the enrichment context. // Extracted during Option A consolidation. // Re-export the core player name normalizer for AV enrichment consumers. export { normalizePlayerName } from '../../utils/normalize.js'; /** * Normalize a MAC address for comparison (strip separators, lowercase). * Used across Meraki matching, phone service fallbacks, etc. */ export const normalizeMac = (mac) => mac ? String(mac).toLowerCase().replace(/[:.-]/g, '') : ''; /** * Translate a RED DeviceID (e.g. "US.OFFLINE.2477" or "US.AE.1234") * into the canonical MDM-style identifier used for matching * (e.g. "US002477MSCOFF" or "US001234MSCAE"). * * This is the inverse direction of some name normalizations and is * critical for stores using "OFFLINE", "AE", "AERIE" branded RED players. * * Moved from avDeviceBuilder during consolidation. */ export function translateREDDeviceID(deviceID) { if (!deviceID) return null; const parts = String(deviceID).trim().toUpperCase().split('.'); if (parts.length < 3) return null; const country = parts[0]; // US, CA, MX, etc. const brand = parts[1]; // OFFLINE, AE, AERIE, ... const store = parts[2]; // 2477, 3876, etc. // Pad store number to 6 digits (e.g. 2477 → 002477) const paddedStore = store.padStart(6, '0'); // Brand mapping (kept identical to original for zero behavior change) let brandSuffix = ''; switch (brand) { case 'OFFLINE': brandSuffix = 'MSCOFF'; break; case 'AE': brandSuffix = 'MSCAE'; break; case 'AERIE': brandSuffix = 'MSCAERIE'; break; default: brandSuffix = `MSC${brand}`; // fallback for unknown brands } // Return full identifier with correct country prefix return `${country}${paddedStore}${brandSuffix}`; }