collabSupport/integrations/cisco-mpp-phone/jsonRows.js
jmcqueen f7953b8eb5 Add MPP desk phone diagnostics follow-up to /phonestatus via relay.
Wire CP-78xx probe discovery, relay phone-probe commands, and a chat follow-up message so store desk phones get registration, switch, and provisioning detail alongside DECT and WAN diagnostics.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-28 18:01:01 -04:00

35 lines
929 B
JavaScript

// integrations/cisco-mpp-phone/jsonRows.js
//
// Shared helpers for MPP SPA JSON endpoints (array-of-rows format).
export function coerceRows(raw) {
if (Array.isArray(raw)) return raw;
if (typeof raw === 'string') {
try {
const parsed = JSON.parse(raw);
return Array.isArray(parsed) ? parsed : [];
} catch {
return [];
}
}
return [];
}
/** @param {Array} rows */
export function fieldsFromRows(rows) {
const fields = {};
for (const row of rows) {
const name = typeof row?.name === 'string' ? row.name.trim() : '';
if (!name) continue;
const value = row?.value == null ? '' : String(row.value).trim();
if (value) fields[name] = value;
}
return fields;
}
export function extractIndexed(fields, re) {
return Object.entries(fields)
.filter(([k]) => re.test(k))
.sort(([a], [b]) => a.localeCompare(b, undefined, { numeric: true }))
.map(([, v]) => v);
}