Rebrand NetAnalyzer -> StoreHealthAnalyzer and consolidate the store
reporting surface into a single `st [number]` command with focused
sub-modes.
Commands
- st [number] - general info (SIW + brands + Meraki net link)
- st [number] network - switches, APs, store server
- st [number] pos - registers, payment terminals, customer display
- st [number] ios - MDM-tracked iOS hardware
- st [number] phone - wired 78xx + DECT basestations/handsets with
registration state, extensions and main DID
- st [number] av - Atlas AMPs + MDM-tracked Apple TVs, video
walls, music players, LED displays
- Removed `analyze` in favor of the unified `st` surface
Integrations
- integrations/webex: Service App OAuth with rotating refresh tokens,
seed + cleanup scripts, tokens/ storage (git-ignored)
- integrations/atlas: Xyte client + cached device discovery keyed on
zero-padded 6-digit store numbers, cold-cache failure -> unavailable
banner instead of a misleading empty result
- services/webexPhone, services/webexService, services/avService: shape
raw upstream data into the report layer's contract
- utils/merakiMatcher: FQDN hostname extraction so payment terminals
match Meraki descriptions; case-insensitive lookup
- utils/chunkReport: split long markdown replies at 7000-char boundaries
Reliability / ops
- server.js: awaited framework.stop() + 8s hard-kill timer so nodemon /
Docker restarts don't leak WDM device registrations ("excessive device
registrations")
- nodemon.json: SIGINT so the graceful path always runs
- scripts/cleanupWebexDevices.js: one-shot WDM cleanup utility
- Group-space routing: hears() regexes tolerate the leading @BotName
prefix Webex prepends to mentions
- Replaced HTML-unsafe <number> placeholders with [number] in all help
strings
Remote agent containerization
- docker/remote-agent/: multi-stage node:22-alpine image, non-root user,
tini for signal handling, minimal deps (ws/axios/dotenv)
- docker/remote-agent/package.sh: docker buildx build defaulting to
linux/amd64 (with override), saves image + assembles deploy/ + writes
SHA256 + zips for offline transfer
- docker/remote-agent/deploy/: runtime docker-compose.yml, install.sh
with platform sanity check, remote-host README
- .dockerignore + .gitignore updates for build artifacts and dist bundles
- npm run agent:package convenience script
Cleanup
- Dropped storeHealth.js / HealthReport.js and their tests/mocks in favor
of the shared storeDetail pipeline
- Store model handles null SIW records gracefully; toSummary always
ends with a newline so the Meraki link sits on its own line
Tests
- 144 tests across 14 suites passing; new coverage for atlasClient,
atlasDevices, avService, avCategory classification, webexPhone,
webexServiceAppAuth, storeDetail integration, siw, chunkReport and
the updated meraki matcher
Co-authored-by: Cursor <cursoragent@cursor.com>
140 lines
4.5 KiB
JavaScript
140 lines
4.5 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Seed the Webex Service App tokens file from an existing source.
|
|
*
|
|
* Two seed paths, both end with one immediate refresh against
|
|
* https://webexapis.com/v1/access_token. That verifies the seed actually
|
|
* works, rotates to a fresh pair (Cisco rotates refresh tokens), and writes
|
|
* the rotated pair to this project's WEBEX_TOKENS_PATH.
|
|
*
|
|
* Usage:
|
|
* npm run webex:seed # uses default --from-file path (collabFinder)
|
|
* npm run webex:seed -- --from-file /path/to/tokens.json
|
|
* npm run webex:seed -- --refresh-token <refresh-token-string>
|
|
*
|
|
* Requires WEBEX_CLIENT_ID + WEBEX_CLIENT_SECRET in .env.
|
|
*/
|
|
|
|
require('dotenv').config();
|
|
const fs = require('fs').promises;
|
|
const path = require('path');
|
|
const axios = require('axios');
|
|
|
|
const TOKEN_URL = 'https://webexapis.com/v1/access_token';
|
|
const DEFAULT_SOURCE = '/Volumes/jmcqueen/Docker/collabFinder/config/webex-service-tokens.json';
|
|
const SAFETY_BUFFER_MS = 5 * 60 * 1000;
|
|
|
|
const args = process.argv.slice(2);
|
|
function flag(name) {
|
|
const idx = args.indexOf(name);
|
|
if (idx >= 0 && idx + 1 < args.length) return args[idx + 1];
|
|
const inline = args.find(a => a.startsWith(`${name}=`));
|
|
if (inline) return inline.split('=').slice(1).join('=');
|
|
return null;
|
|
}
|
|
|
|
async function readSeedRefreshToken() {
|
|
const refreshTokenFlag = flag('--refresh-token');
|
|
if (refreshTokenFlag) {
|
|
return { source: 'refresh-token flag', refreshToken: refreshTokenFlag.trim() };
|
|
}
|
|
|
|
const fromFile = flag('--from-file') || DEFAULT_SOURCE;
|
|
console.log(`Seeding from file: ${fromFile}`);
|
|
|
|
let raw;
|
|
try {
|
|
raw = await fs.readFile(fromFile, 'utf8');
|
|
} catch (err) {
|
|
if (err.code === 'ENOENT') {
|
|
throw new Error(
|
|
`Source tokens file not found: ${fromFile}\n` +
|
|
'Pass --from-file <path> or --refresh-token <token>.',
|
|
{ cause: err }
|
|
);
|
|
}
|
|
throw err;
|
|
}
|
|
|
|
let parsed;
|
|
try {
|
|
parsed = JSON.parse(raw);
|
|
} catch (err) {
|
|
throw new Error(`Source tokens file is not valid JSON (${fromFile}): ${err.message}`, {
|
|
cause: err,
|
|
});
|
|
}
|
|
|
|
const refreshToken = parsed.refreshToken || parsed.refresh_token;
|
|
if (!refreshToken) {
|
|
throw new Error(`Source tokens file has no refreshToken / refresh_token field (${fromFile})`);
|
|
}
|
|
return { source: fromFile, refreshToken };
|
|
}
|
|
|
|
async function exchangeRefreshToken(refreshToken) {
|
|
const clientId = process.env.WEBEX_CLIENT_ID;
|
|
const clientSecret = process.env.WEBEX_CLIENT_SECRET;
|
|
if (!clientId || !clientSecret) {
|
|
throw new Error('WEBEX_CLIENT_ID and WEBEX_CLIENT_SECRET must be set in .env');
|
|
}
|
|
|
|
const params = new URLSearchParams({
|
|
grant_type: 'refresh_token',
|
|
client_id: clientId,
|
|
client_secret: clientSecret,
|
|
refresh_token: refreshToken,
|
|
});
|
|
|
|
try {
|
|
const res = await axios.post(TOKEN_URL, params.toString(), {
|
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
timeout: 15000,
|
|
});
|
|
return res.data;
|
|
} catch (err) {
|
|
const status = err.response?.status;
|
|
const detail = err.response?.data ? JSON.stringify(err.response.data) : err.message;
|
|
throw new Error(`Token refresh failed (status=${status || 'n/a'}): ${detail}`, {
|
|
cause: err,
|
|
});
|
|
}
|
|
}
|
|
|
|
async function writeTokens(targetPath, data) {
|
|
const payload = {
|
|
accessToken: data.access_token,
|
|
refreshToken: data.refresh_token,
|
|
expiresAt: Date.now() + Number(data.expires_in || 0) * 1000 - SAFETY_BUFFER_MS,
|
|
updatedAt: new Date().toISOString(),
|
|
};
|
|
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
|
await fs.writeFile(targetPath, JSON.stringify(payload, null, 2), 'utf8');
|
|
return payload;
|
|
}
|
|
|
|
(async () => {
|
|
try {
|
|
const targetPath = path.resolve(
|
|
process.env.WEBEX_TOKENS_PATH ||
|
|
path.join(process.cwd(), 'tokens', 'webex-service-tokens.json')
|
|
);
|
|
|
|
const { source, refreshToken } = await readSeedRefreshToken();
|
|
console.log(`Seed source: ${source}`);
|
|
console.log(`Target path: ${targetPath}`);
|
|
|
|
console.log('Performing initial refresh against Webex...');
|
|
const data = await exchangeRefreshToken(refreshToken);
|
|
|
|
const payload = await writeTokens(targetPath, data);
|
|
console.log('Webex tokens seeded successfully.');
|
|
console.log(` expiresIn: ${data.expires_in}s (buffered)`);
|
|
console.log(` expiresAt: ${new Date(payload.expiresAt).toISOString()}`);
|
|
console.log(` updatedAt: ${payload.updatedAt}`);
|
|
process.exit(0);
|
|
} catch (err) {
|
|
console.error('Seed failed:', err.message);
|
|
process.exit(1);
|
|
}
|
|
})();
|