Adds the EgressService that probes a configurable set of reliability targets
(ping, TCP or HTTP) when asked, persists a single instance-wide egress state
document, and runs a recovery poll loop while egress is degraded. Adds the four
egress settings fields with validation. The worker constructs and initialises
the service but nothing calls assessAfterFailure yet, so behaviour is unchanged.
🔧
59 lines
2.3 KiB
TypeScript
59 lines
2.3 KiB
TypeScript
import { Schema, model, type Types } from "mongoose";
|
|
import type { Settings, SettingsThresholds } from "@/domain/app-settings/app-settings.type.js";
|
|
import { DEFAULT_EGRESS_POLL_INTERVAL_SECONDS, DEFAULT_EGRESS_TARGETS } from "@/domain/egress/egress.type.js";
|
|
|
|
interface AppSettingsDocument extends Omit<Settings, "id" | "createdAt" | "updatedAt"> {
|
|
_id: Types.ObjectId;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
}
|
|
|
|
const thresholdsSchema = new Schema<SettingsThresholds>(
|
|
{
|
|
cpu: { type: Number },
|
|
memory: { type: Number },
|
|
disk: { type: Number },
|
|
temperature: { type: Number },
|
|
},
|
|
{ _id: false }
|
|
);
|
|
|
|
const AppSettingsSchema = new Schema<AppSettingsDocument>(
|
|
{
|
|
checkTTL: { type: Number, default: 30 },
|
|
language: { type: String, default: "gb" },
|
|
jwtSecret: { type: String },
|
|
pagespeedApiKey: { type: String },
|
|
systemEmailHost: { type: String },
|
|
systemEmailPort: { type: Number },
|
|
systemEmailAddress: { type: String },
|
|
systemEmailDisplayName: { type: String },
|
|
systemEmailPassword: { type: String },
|
|
systemEmailUser: { type: String },
|
|
systemEmailConnectionHost: { type: String, default: "localhost" },
|
|
systemEmailTLSServername: { type: String },
|
|
systemEmailSecure: { type: Boolean, default: false },
|
|
systemEmailPool: { type: Boolean, default: false },
|
|
systemEmailIgnoreTLS: { type: Boolean, default: false },
|
|
systemEmailRequireTLS: { type: Boolean, default: false },
|
|
systemEmailRejectUnauthorized: { type: Boolean, default: true },
|
|
showURL: { type: Boolean, default: false },
|
|
singleton: { type: Boolean, required: true, unique: true, default: true },
|
|
version: { type: Number, default: 1 },
|
|
globalThresholds: { type: thresholdsSchema },
|
|
globalProxyEnabled: { type: Boolean, default: false },
|
|
globalProxyId: { type: String, default: null },
|
|
egressCheckEnabled: { type: Boolean, default: false },
|
|
egressCheckTargets: { type: [String], default: () => [...DEFAULT_EGRESS_TARGETS] },
|
|
egressPollIntervalSeconds: { type: Number, default: DEFAULT_EGRESS_POLL_INTERVAL_SECONDS },
|
|
egressNotifications: { type: [String], default: () => [] }, // Notification ids, stored as strings like globalProxyId
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
const AppSettingsModel = model<AppSettingsDocument>("AppSettings", AppSettingsSchema);
|
|
|
|
export type { AppSettingsDocument };
|
|
export { AppSettingsModel };
|
|
export default AppSettingsModel;
|