netanalyzer/services/siw.js
Joseph McQueen 0a46d25bd6 chore: project cleanup — dead code, logging, tests, WS hardening
- Delete unused dataMerger, formatter, Device model, dead service exports,
  and the empty agents/ + .gitkeep placeholders.
- Extract STORE_MODES and MDM device-type filters into a shared constants.js.
- Anchor bot regexes (^help|^store|^analyze) so "analyze store 305" no
  longer fires both handlers; replace catch-all noise.
- Hoist inline require() calls in integrations to top-of-file imports.
- Harden WebSocket server: Authorization header support, single-agent
  enforcement, bounded pending requests, server-level error handler,
  coalesced cache refresh in Meraki client.
- Wrap Meraki/MDM network calls with withRetry; add request timeouts.
- Migrate all console.* calls onto utils/logger.js (LOG_LEVEL aware);
  drive Webex framework logLevel from env.
- Refactor storeDetail.js: shared renderClientLine + buildMdmSection
  helpers cut duplication roughly in half.
- Refresh README structure, document LOG_LEVEL, add npm run agent script,
  add jest testMatch + new tests (handlers, HealthReport, Store, ws).

Verified: npm run lint clean, 7 suites / 31 tests passing.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 17:21:22 -04:00

62 lines
1.9 KiB
JavaScript

const config = require('../config');
const { proxyRequest } = require('./websocket');
const { parseStoreNumber } = require('../utils/validate');
function getSiwAuthHeaders() {
const { username, password } = config.siw;
if (!username || !password) {
throw new Error('SIW credentials are not configured (SIW_USERNAME / SIW_PASSWORD)');
}
const authString = Buffer.from(`${username}:${password}`).toString('base64');
return { Authorization: `Basic ${authString}` };
}
function buildSiwRequest(path) {
if (!config.siw.baseUrl) {
throw new Error('SIW_BASE_URL is not configured');
}
return {
method: 'GET',
url: `${config.siw.baseUrl}${path}`,
headers: getSiwAuthHeaders(),
};
}
async function getStoreLocation(storeNumber) {
const normalized = parseStoreNumber(storeNumber);
if (!normalized) throw new Error('Invalid store number');
const result = await proxyRequest(buildSiwRequest(`/StoreLocation/${normalized}`));
return result.data;
}
async function getStoreRegisters(storeNumber) {
const normalized = parseStoreNumber(storeNumber);
if (!normalized) throw new Error('Invalid store number');
const result = await proxyRequest(buildSiwRequest(`/StoreRegister/${normalized}`));
return result.data || [];
}
async function getStorePrinters(storeNumber) {
const normalized = parseStoreNumber(storeNumber);
if (!normalized) throw new Error('Invalid store number');
const result = await proxyRequest(buildSiwRequest(`/StorePrinter/${normalized}`));
return result.data || [];
}
async function getStorePaymentTerminals(storeNumber) {
const normalized = parseStoreNumber(storeNumber);
if (!normalized) throw new Error('Invalid store number');
const result = await proxyRequest(buildSiwRequest(`/StorePayment/${normalized}`));
return result.data || [];
}
module.exports = {
getStoreLocation,
getStoreRegisters,
getStorePrinters,
getStorePaymentTerminals,
};