Containerize the monitor with production and dev compose stacks, fix healthchecks and port handling, and make the dashboard base path configurable for direct or proxied access. Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
No EOL
1.8 KiB
JavaScript
62 lines
No EOL
1.8 KiB
JavaScript
import fetch from 'node-fetch';
|
|
import logger from '../utils/logger.js';
|
|
import { saveJson } from '../utils/file.js';
|
|
import config from '../config/index.js';
|
|
import { getAccessToken } from './token.js';
|
|
|
|
const BASE_URL = "https://api.wxcc-us1.cisco.com";
|
|
|
|
async function fetchAllPages(endpoint) {
|
|
const accessToken = getAccessToken();
|
|
if (!accessToken) {
|
|
throw new Error("No valid Webex access token found");
|
|
}
|
|
|
|
const url = new URL(`${BASE_URL}${endpoint}`);
|
|
const allItems = [];
|
|
let page = 0;
|
|
const pageSize = 50;
|
|
|
|
while (true) {
|
|
url.searchParams.set('page', page);
|
|
url.searchParams.set('pageSize', pageSize);
|
|
|
|
const res = await fetch(url, {
|
|
headers: { Authorization: `Bearer ${accessToken}` }
|
|
});
|
|
|
|
if (!res.ok) throw new Error(`API ${res.status}: ${await res.text()}`);
|
|
|
|
const items = await res.json();
|
|
allItems.push(...items);
|
|
|
|
if (items.length < pageSize) break;
|
|
page++;
|
|
}
|
|
|
|
return allItems;
|
|
}
|
|
|
|
export async function updateWxCCData() {
|
|
try {
|
|
const [agents, auxCodes, contactQueues, teams] = await Promise.all([
|
|
fetchAllPages(`/organization/${config.auth.webex.orgId}/user`),
|
|
fetchAllPages(`/organization/${config.auth.webex.orgId}/auxiliary-code`),
|
|
fetchAllPages(`/organization/${config.auth.webex.orgId}/contact-service-queue`),
|
|
fetchAllPages(`/organization/${config.auth.webex.orgId}/team`)
|
|
]);
|
|
|
|
await Promise.all([
|
|
saveJson(agents, './data/agents.json'),
|
|
saveJson(auxCodes, './data/auxCodes.json'),
|
|
saveJson(contactQueues, './data/contactQueues.json'),
|
|
saveJson(teams, './data/teams.json')
|
|
]);
|
|
|
|
logger.info(`WxCC data updated: ${agents.length} agents, ${auxCodes.length} aux codes`);
|
|
return { agents, auxCodes, contactQueues, teams };
|
|
} catch (error) {
|
|
logger.error('updateWxCCData failed', { error: error.message });
|
|
throw error;
|
|
}
|
|
} |