// services/callReport/parseTarget.js // Token parsing for /callreport targets (no Webex dependencies). import { normalizeE164 } from '../callTest/config.js'; /** * @param {string} token * @returns {{ kind: 'store', storeNum: string } | { kind: 'user', email: string } | { kind: 'number', phoneNumber: string } | null} */ export function parseCallReportTarget(token) { const t = String(token || '').trim(); if (!t) return null; if (t.includes('@')) { return { kind: 'user', email: t.toLowerCase() }; } if (/^\d{2,4}$/.test(t)) { return { kind: 'store', storeNum: t }; } const e164 = normalizeE164(t); if (e164) { return { kind: 'number', phoneNumber: e164 }; } return null; } /** * Parse store number from location name like "Store 0782". * @param {string} locationName * @returns {string|null} */ export function parseStoreNumFromLocationName(locationName) { const m = String(locationName || '').match(/store\s*0*(\d{2,4})\b/i); return m ? m[1] : null; }