Files
DataStack/core/adminSettings/settingsManager.ts
T

89 lines
2.7 KiB
TypeScript
Raw Normal View History

2026-10-23 19:56:38 -07:00
import { AuthService } from "../auth/jwt";
import { DataBufferEngine } from "../data/buffer";
import { SecurityEngine } from "../Security/security";
import { CSVStorageManager } from "../Storage/csvStorage";
2026-10-23 11:43:49 -05:00
export interface AdminSettings {
serverPort: number;
webPort: number;
maxEventsPerSec: number;
maxPayloadSizeKb: number;
batchFlushThreshold: number;
batchFlushIntervalMs: number;
fileRotationMb: number;
jwtSecret: string;
enableIdempotency: boolean;
autoPruneDays: number;
updatedAt: string;
}
export class SettingsManager {
private static settings: AdminSettings = {
serverPort: 4000,
webPort: 3000,
maxEventsPerSec: 100,
maxPayloadSizeKb: 100,
batchFlushThreshold: 500,
batchFlushIntervalMs: 2000,
fileRotationMb: 100,
2026-10-23 19:56:38 -07:00
jwtSecret: process.env.DATASTACK_JWT_SECRET || "",
2026-10-23 11:43:49 -05:00
enableIdempotency: true,
autoPruneDays: 30,
updatedAt: new Date().toISOString(),
};
public static getSettings(): AdminSettings {
return { ...this.settings };
}
2026-10-23 19:56:38 -07:00
public static getPublicSettings(): Omit<AdminSettings, "jwtSecret"> {
const settings = this.settings;
return {
serverPort: settings.serverPort,
webPort: settings.webPort,
maxEventsPerSec: settings.maxEventsPerSec,
maxPayloadSizeKb: settings.maxPayloadSizeKb,
batchFlushThreshold: settings.batchFlushThreshold,
batchFlushIntervalMs: settings.batchFlushIntervalMs,
fileRotationMb: settings.fileRotationMb,
enableIdempotency: settings.enableIdempotency,
autoPruneDays: settings.autoPruneDays,
updatedAt: settings.updatedAt,
};
}
2026-10-23 11:43:49 -05:00
public static updateSettings(updates: Partial<AdminSettings>): AdminSettings {
this.settings = {
...this.settings,
...updates,
updatedAt: new Date().toISOString(),
};
// Apply live updates to subsystems
2026-10-23 19:56:38 -07:00
if (updates.maxEventsPerSec !== undefined) {
SecurityEngine.maxEventsPerSec = updates.maxEventsPerSec;
}
if (updates.enableIdempotency !== undefined) {
SecurityEngine.enableIdempotency = updates.enableIdempotency;
}
2026-10-23 11:43:49 -05:00
if (updates.maxPayloadSizeKb !== undefined) {
SecurityEngine.maxPayloadSizeBytes = updates.maxPayloadSizeKb * 1024;
}
if (updates.batchFlushThreshold !== undefined) {
DataBufferEngine.batchFlushThreshold = updates.batchFlushThreshold;
}
if (updates.batchFlushIntervalMs !== undefined) {
DataBufferEngine.batchFlushIntervalMs = updates.batchFlushIntervalMs;
}
if (updates.jwtSecret !== undefined) {
AuthService.setSecret(updates.jwtSecret);
}
if (updates.fileRotationMb !== undefined) {
CSVStorageManager.maxFileSizeBytes = updates.fileRotationMb * 1024 * 1024;
}
return this.settings;
}
}
export default SettingsManager;