fix(opax): make operations console ESM-safe
This commit is contained in:
parent
b68fc41f61
commit
856b33832f
|
|
@ -1,5 +1,5 @@
|
||||||
const { Router } = require('express');
|
import { Router } from 'express';
|
||||||
const { callAgent } = require('../agentClient');
|
import { callAgent } from '../agentClient.js';
|
||||||
|
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
|
|
@ -67,4 +67,4 @@ router.get('/approvals', (req, res) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = router;
|
export default router;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import { createServer } from 'node:http';
|
||||||
import { Server } from 'socket.io';
|
import { Server } from 'socket.io';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
import consoleApiRouter from './routes/consoleApi.js';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const http = createServer(app);
|
const http = createServer(app);
|
||||||
|
|
@ -72,7 +73,6 @@ const ensureAuthenticated = (req, res, next) => {
|
||||||
res.status(401).end();
|
res.status(401).end();
|
||||||
};
|
};
|
||||||
|
|
||||||
const consoleApiRouter = require('./routes/consoleApi.js');
|
|
||||||
app.use('/api/console', ensureAuthenticated, consoleApiRouter);
|
app.use('/api/console', ensureAuthenticated, consoleApiRouter);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,22 +33,41 @@ const unavailableItem: ConsoleStatusItem = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Normalizer Function ---
|
// --- Normalizer Function ---
|
||||||
function normalizeStatusResponse(raw: any): ConsoleStatusResponse {
|
type UnknownRecord = Record<string, unknown>;
|
||||||
let health = unavailableItem;
|
|
||||||
|
|
||||||
if (raw?.health?.status === 'success' &&
|
function isRecord(value: unknown): value is UnknownRecord {
|
||||||
raw.health.summary?.status === 'ok' &&
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
||||||
typeof raw.health.summary.service === 'string' &&
|
}
|
||||||
typeof raw.health.summary.version === 'string') {
|
|
||||||
health = {
|
function isHealthSummary(value: unknown): value is SafeHealthSummary {
|
||||||
status: 'success',
|
return (
|
||||||
summary: {
|
isRecord(value) &&
|
||||||
status: 'ok',
|
value.status === 'ok' &&
|
||||||
service: raw.health.summary.service,
|
typeof value.service === 'string' &&
|
||||||
version: raw.health.summary.version,
|
typeof value.version === 'string'
|
||||||
},
|
);
|
||||||
message: 'Available',
|
}
|
||||||
};
|
|
||||||
|
function normalizeStatusResponse(raw: unknown): ConsoleStatusResponse {
|
||||||
|
let health: ConsoleStatusItem = unavailableItem;
|
||||||
|
|
||||||
|
if (isRecord(raw) && isRecord(raw.health)) {
|
||||||
|
const healthItem = raw.health;
|
||||||
|
|
||||||
|
if (
|
||||||
|
healthItem.status === 'success' &&
|
||||||
|
isHealthSummary(healthItem.summary)
|
||||||
|
) {
|
||||||
|
health = {
|
||||||
|
status: 'success',
|
||||||
|
summary: {
|
||||||
|
status: 'ok',
|
||||||
|
service: healthItem.summary.service,
|
||||||
|
version: healthItem.summary.version,
|
||||||
|
},
|
||||||
|
message: 'Available',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
@ -81,7 +100,7 @@ const OperationsConsole = () => {
|
||||||
const rawData = await res.json();
|
const rawData = await res.json();
|
||||||
setStatusData(normalizeStatusResponse(rawData));
|
setStatusData(normalizeStatusResponse(rawData));
|
||||||
setLastRefreshed(new Date().toLocaleTimeString());
|
setLastRefreshed(new Date().toLocaleTimeString());
|
||||||
} catch (e: any) {
|
} catch {
|
||||||
setError('Console data is unavailable. Please try again.');
|
setError('Console data is unavailable. Please try again.');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user