// Lightweight User-Agent -> "Browser on OS" summary for account-activity logging. // No UA-parsing library is installed in this project; this covers the common cases // (desktop/mobile browsers, major OSes) without pulling one in for a single display string. function detectBrowser(ua) { if (/Edg\//.test(ua)) return 'Edge'; if (/OPR\//.test(ua) || /Opera/.test(ua)) return 'Opera'; if (/SamsungBrowser/.test(ua)) return 'Samsung Internet'; if (/CriOS/.test(ua)) return 'Chrome'; if (/FxiOS/.test(ua)) return 'Firefox'; if (/Firefox\//.test(ua)) return 'Firefox'; if (/Chrome\//.test(ua)) return 'Chrome'; if (/Safari\//.test(ua) && /Version\//.test(ua)) return 'Safari'; return null; } function detectOS(ua) { if (/Windows/.test(ua)) return 'Windows'; if (/iPhone|iPad|iPod/.test(ua)) return 'iOS'; if (/Mac OS X/.test(ua)) return 'macOS'; if (/Android/.test(ua)) return 'Android'; if (/Linux/.test(ua)) return 'Linux'; return null; } function describeUserAgent(uaString) { if (!uaString) return 'Unknown device'; const browser = detectBrowser(uaString); const os = detectOS(uaString); if (browser && os) return `${browser} on ${os}`; if (browser) return browser; if (os) return os; return 'Unknown device'; } module.exports = { describeUserAgent };