49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Config routes — GET /api/config and PATCH /api/config
|
|
* Manages server-side configuration for notifications and defaults.
|
|
*/
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getServerConfig = getServerConfig;
|
|
exports.createConfigRouter = createConfigRouter;
|
|
const express_1 = require("express");
|
|
const defaultConfig = {
|
|
slackWebhookUrl: process.env['ABE_SLACK_WEBHOOK_URL'] ?? null,
|
|
notifyMinSeverity: process.env['ABE_NOTIFY_MIN_SEVERITY'] ?? 'high',
|
|
defaultMaxStates: 50,
|
|
defaultMaxDepth: 5,
|
|
defaultActionDelayMs: 500,
|
|
defaultExcludedPaths: [],
|
|
};
|
|
let serverConfig = { ...defaultConfig };
|
|
function getServerConfig() {
|
|
return { ...serverConfig };
|
|
}
|
|
function createConfigRouter() {
|
|
const router = (0, express_1.Router)();
|
|
// GET /api/config — returns current config (without API key)
|
|
router.get('/', (_req, res) => {
|
|
res.json(serverConfig);
|
|
});
|
|
// PATCH /api/config — updates config fields
|
|
router.patch('/', (req, res) => {
|
|
const body = req.body;
|
|
const validKeys = [
|
|
'slackWebhookUrl',
|
|
'notifyMinSeverity',
|
|
'defaultMaxStates',
|
|
'defaultMaxDepth',
|
|
'defaultActionDelayMs',
|
|
'defaultExcludedPaths',
|
|
];
|
|
for (const key of validKeys) {
|
|
if (key in body) {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
serverConfig[key] = body[key];
|
|
}
|
|
}
|
|
res.json(serverConfig);
|
|
});
|
|
return router;
|
|
}
|