reorg to domain and api

This commit is contained in:
Alex Holliday committed 2026-06-09 12:34:15 -07:00
1 parent 0fb210e9e1
commit d022f7d849
190 files changed
+643 -830

No files matched your search

File renamed without changes.
@@ -1,11 +1,11 @@
import { Mongoose } from "mongoose";
import mongoose from "mongoose";
import AppSettings from "@/db/models/AppSettings.js";
import AppSettings from "@/domain/app-settings/app-settings.model.js";
import { runMigrations } from "@/db/migration/index.js";
import { ILogger } from "@/utils/logger.js";
import { EnvConfig } from "@/service/system/settingsService.js";
import { EnvConfig } from "@/domain/app-settings/app-settings.service.js";
const SERVICE_NAME = "MongoDB";
import { IDb } from "@/db/IDb.js";
import { IDb } from "@/db/db.interface.js";
import { AppError } from "@/utils/AppError.js";
class MongoDB implements IDb<Mongoose> {
@@ -1,4 +1,4 @@
import Monitor from "@/db/models/Monitor.js";
import Monitor from "@/domain/monitors/monitor.model.js";
async function migrateStatusWindowThreshold() {
const monitors = await Monitor.find({ statusWindowThreshold: { $lt: 1 } });
for (const monitor of monitors) {
@@ -1,4 +1,4 @@
import { MonitorStatsModel } from "../models/MonitorStats.js";
import { MonitorStatsModel } from "../../domain/monitor-stats/monitor-stats.model.js";
import { logger } from "@/utils/logger.js";
/**
@@ -1,4 +1,4 @@
import { MonitorModel } from "../models/Monitor.js";
import { MonitorModel } from "../../domain/monitors/monitor.model.js";
import { logger } from "@/utils/logger.js";
/**
@@ -1,6 +1,6 @@
import mongoose from "mongoose";
import { logger } from "@/utils/logger.js";
import StatusPageModel from "../models/StatusPage.js";
import StatusPageModel from "../../domain/status-pages/status-page.model.js";
export async function migrateStatusPageTypeToArray(): Promise<void> {
const SERVICE_NAME = "Migration:MigrateStatusPageTypeToArray";
@@ -1,4 +1,4 @@
import { MonitorStatsModel } from "../models/MonitorStats.js";
import { MonitorStatsModel } from "../../domain/monitor-stats/monitor-stats.model.js";
import { logger } from "@/utils/logger.js";
/**
@@ -1,7 +1,7 @@
import mongoose from "mongoose";
import type { AnyBulkWriteOperation, Document } from "mongodb";
import { logger } from "@/utils/logger.js";
import MaintenanceWindowModel from "../models/MaintenanceWindow.js";
import MaintenanceWindowModel from "../../domain/maintenance-windows/maintenance-window.model.js";
type GroupResult = {
_id: {
+1 -1
View File
@@ -2,7 +2,7 @@ import { migrateStatusWindowThreshold } from "./0001_migrateStatusWindowThreshol
import { convertChecksToTimeSeries } from "./0002_convertChecksToTimeSeries.js";
import { cleanupDuplicateMonitorStats } from "./0003_cleanupDuplicateMonitorStats.js";
import { fixInfrastructureThresholds } from "./0004_fixInfrastructureThresholds.js";
import MigrationModel from "../models/Migration.js";
import MigrationModel from "../../domain/migrations/migration.model.js";
import { migrateStatusPageTypeToArray } from "./0005_migrateStatusPageTypeToArray.js";
import { cleanupDuplicateMonitorStatsForUniqueIndex } from "./0006_cleanupDuplicateMonitorStatsForUniqueIndex.js";
import { migrateMaintenanceWindowMonitorIdToArray } from "./0007_migrateMaintenanceWindowMonitorIdToArray.js";
-51
View File
@@ -1,51 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { Settings, SettingsThresholds } from "@/types/settings.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 },
},
{ timestamps: true }
);
const AppSettingsModel = model<AppSettingsDocument>("AppSettings", AppSettingsSchema);
export type { AppSettingsDocument };
export { AppSettingsModel };
export default AppSettingsModel;
-294
View File
@@ -1,294 +0,0 @@
import { Schema, model, Types } from "mongoose";
import { MonitorTypes, type MonitorType } from "@/types/monitor.js";
import type {
Check,
CheckAudits,
CheckCaptureInfo,
CheckCpuInfo,
CheckDiskInfo,
CheckErrorInfo,
CheckHostInfo,
CheckMemoryInfo,
CheckMetadata,
CheckNetworkInterfaceInfo,
GotTimings,
ILighthouseAudit,
} from "@/types/check.js";
type CheckMetadataDocument = Omit<CheckMetadata, "monitorId" | "teamId"> & {
monitorId: Types.ObjectId;
teamId: Types.ObjectId;
type: MonitorType;
};
type CheckDocumentBase = Omit<Check, "id" | "metadata" | "createdAt" | "updatedAt"> & {
metadata: CheckMetadataDocument;
createdAt: Date;
updatedAt: Date;
};
interface CheckDocument extends CheckDocumentBase {
_id: Types.ObjectId;
}
const timingPhasesSchema = new Schema<GotTimings["phases"]>(
{
wait: { type: Number, default: 0 },
dns: { type: Number, default: 0 },
tcp: { type: Number, default: 0 },
tls: { type: Number, default: 0 },
request: { type: Number, default: 0 },
firstByte: { type: Number, default: 0 },
download: { type: Number, default: 0 },
total: { type: Number, default: 0 },
},
{ _id: false }
);
const timingsSchema = new Schema<GotTimings>(
{
start: { type: Number, default: 0 },
socket: { type: Number, default: 0 },
lookup: { type: Number, default: 0 },
connect: { type: Number, default: 0 },
secureConnect: { type: Number, default: 0 },
upload: { type: Number, default: 0 },
response: { type: Number, default: 0 },
end: { type: Number, default: 0 },
phases: {
type: timingPhasesSchema,
default: () => ({}),
},
},
{ _id: false }
);
const cpuSchema = new Schema<CheckCpuInfo>(
{
physical_core: { type: Number, default: 0 },
logical_core: { type: Number, default: 0 },
frequency: { type: Number, default: 0 },
current_frequency: { type: Number, default: 0 },
temperature: { type: [Number], default: [] },
free_percent: { type: Number, default: 0 },
usage_percent: { type: Number, default: 0 },
},
{ _id: false }
);
const memorySchema = new Schema<CheckMemoryInfo>(
{
total_bytes: { type: Number, default: 0 },
available_bytes: { type: Number, default: 0 },
used_bytes: { type: Number, default: 0 },
usage_percent: { type: Number, default: 0 },
},
{ _id: false }
);
const diskSchema = new Schema<CheckDiskInfo>(
{
device: { type: String, default: "" },
mountpoint: { type: String, default: "" },
total_bytes: { type: Number, default: 0 },
free_bytes: { type: Number, default: 0 },
used_bytes: { type: Number, default: 0 },
usage_percent: { type: Number, default: 0 },
total_inodes: { type: Number, default: 0 },
free_inodes: { type: Number, default: 0 },
used_inodes: { type: Number, default: 0 },
inodes_usage_percent: { type: Number, default: 0 },
read_bytes: { type: Number, default: 0 },
write_bytes: { type: Number, default: 0 },
read_time: { type: Number, default: 0 },
write_time: { type: Number, default: 0 },
},
{ _id: false }
);
const hostSchema = new Schema<CheckHostInfo>(
{
os: { type: String, default: "" },
platform: { type: String, default: "" },
kernel_version: { type: String, default: "" },
pretty_name: { type: String, default: "" },
},
{ _id: false }
);
const errorSchema = new Schema<CheckErrorInfo>(
{
metric: { type: [String], default: [] },
err: { type: String, default: "" },
},
{ _id: false }
);
const captureSchema = new Schema<CheckCaptureInfo>(
{
version: { type: String, default: "" },
mode: { type: String, default: "" },
},
{ _id: false }
);
const networkInterfaceSchema = new Schema<CheckNetworkInterfaceInfo>(
{
name: { type: String, default: "" },
bytes_sent: { type: Number, default: 0 },
bytes_recv: { type: Number, default: 0 },
packets_sent: { type: Number, default: 0 },
packets_recv: { type: Number, default: 0 },
err_in: { type: Number, default: 0 },
err_out: { type: Number, default: 0 },
drop_in: { type: Number, default: 0 },
drop_out: { type: Number, default: 0 },
fifo_in: { type: Number, default: 0 },
fifo_out: { type: Number, default: 0 },
},
{ _id: false }
);
const lighthouseAuditSchema = new Schema<ILighthouseAudit>(
{
id: { type: String },
title: { type: String },
score: { type: Number },
displayValue: { type: String },
numericValue: { type: Number },
numericUnit: { type: String },
},
{ _id: false }
);
const auditsSchema = new Schema<CheckAudits>(
{
cls: { type: lighthouseAuditSchema, default: undefined },
si: { type: lighthouseAuditSchema, default: undefined },
fcp: { type: lighthouseAuditSchema, default: undefined },
lcp: { type: lighthouseAuditSchema, default: undefined },
tbt: { type: lighthouseAuditSchema, default: undefined },
},
{ _id: false }
);
const metadataSchema = new Schema<CheckMetadataDocument>(
{
monitorId: {
type: Schema.Types.ObjectId,
ref: "Monitor",
required: true,
immutable: true,
index: true,
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
required: true,
immutable: true,
index: true,
},
type: {
type: String,
enum: MonitorTypes,
required: true,
index: true,
},
},
{ _id: false }
);
const CheckSchema = new Schema<CheckDocument>(
{
metadata: {
type: metadataSchema,
required: true,
},
status: {
type: Boolean,
index: true,
},
responseTime: {
type: Number,
},
timings: {
type: timingsSchema,
default: undefined,
},
statusCode: {
type: Number,
index: true,
},
message: {
type: String,
},
cpu: {
type: cpuSchema,
default: () => ({}),
},
memory: {
type: memorySchema,
default: () => ({}),
},
disk: {
type: [diskSchema],
default: () => [],
},
host: {
type: hostSchema,
default: () => ({}),
},
errors: {
type: [errorSchema],
default: () => [],
},
capture: {
type: captureSchema,
default: () => ({}),
},
net: {
type: [networkInterfaceSchema],
default: () => [],
},
accessibility: {
type: Number,
},
bestPractices: {
type: Number,
},
seo: {
type: Number,
},
performance: {
type: Number,
},
audits: {
type: auditsSchema,
default: undefined,
},
},
{
timestamps: true,
strict: false,
suppressReservedKeysWarning: true,
timeseries: {
timeField: "createdAt",
metaField: "metadata",
granularity: "seconds",
},
}
);
CheckSchema.index({ "metadata.monitorId": 1, createdAt: -1 });
CheckSchema.index({ "metadata.monitorId": 1, createdAt: 1 });
CheckSchema.index({ createdAt: 1 });
CheckSchema.index({ "metadata.teamId": 1, createdAt: -1 });
CheckSchema.index({ "metadata.monitorId": 1, "metadata.type": 1, createdAt: -1 });
CheckSchema.index({ "metadata.teamId": 1, status: 1, createdAt: -1 });
const CheckModel = model<CheckDocument>("Check", CheckSchema);
export type { CheckDocument, CheckMetadataDocument };
export { CheckModel };
export default CheckModel;
-70
View File
@@ -1,70 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import { DLQItemTypes, DLQItemStatuses, type DLQItem } from "@/types/dlqItem.js";
export interface DLQItemDocument extends Omit<DLQItem, "id" | "monitorId" | "teamId" | "nextRetryAt" | "createdAt" | "updatedAt"> {
_id: Types.ObjectId;
monitorId: Types.ObjectId;
teamId: Types.ObjectId;
nextRetryAt: Date;
createdAt: Date;
updatedAt: Date;
}
const DLQItemSchema = new Schema<DLQItemDocument>(
{
type: {
type: String,
enum: DLQItemTypes,
required: true,
},
status: {
type: String,
enum: DLQItemStatuses,
default: "pending",
},
payload: {
type: Schema.Types.Mixed,
required: true,
},
monitorId: {
type: Schema.Types.ObjectId,
ref: "Monitor",
required: true,
immutable: true,
index: true,
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
required: true,
immutable: true,
index: true,
},
retryCount: {
type: Number,
default: 0,
},
maxRetries: {
type: Number,
default: 5,
},
lastError: {
type: String,
default: "",
},
nextRetryAt: {
type: Date,
required: true,
},
},
{ timestamps: true }
);
DLQItemSchema.index({ status: 1, nextRetryAt: 1 });
DLQItemSchema.index({ teamId: 1, status: 1 });
DLQItemSchema.index({ createdAt: 1 });
const DLQItemModel = model<DLQItemDocument>("DLQItem", DLQItemSchema);
export { DLQItemModel };
export default DLQItemModel;
-116
View File
@@ -1,116 +0,0 @@
import { Schema, model, Types } from "mongoose";
import { MonitorTypes, type MonitorType } from "@/types/monitor.js";
import type { GeoCheck, GeoCheckLocation, GeoCheckMetadata, GeoCheckResult, GeoCheckTimings } from "@/types/geoCheck.js";
type GeoCheckMetadataDocument = Omit<GeoCheckMetadata, "monitorId" | "teamId"> & {
monitorId: Types.ObjectId;
teamId: Types.ObjectId;
type: MonitorType;
};
type GeoCheckDocumentBase = Omit<GeoCheck, "id" | "metadata" | "expiry" | "createdAt" | "updatedAt" | "results"> & {
metadata: GeoCheckMetadataDocument;
results: GeoCheckResult[];
expiry: Date;
createdAt: Date;
updatedAt: Date;
__v: number;
};
export interface GeoCheckDocument extends GeoCheckDocumentBase {
_id: Types.ObjectId;
}
const geoCheckMetadataSchema = new Schema<GeoCheckMetadataDocument>(
{
monitorId: { type: Schema.Types.ObjectId, required: true, index: true },
teamId: { type: Schema.Types.ObjectId, required: true, index: true },
type: { type: String, required: true, enum: MonitorTypes },
},
{ _id: false }
);
const geoCheckTimingsSchema = new Schema<GeoCheckTimings>(
{
total: { type: Number, default: 0 },
dns: { type: Number, default: 0 },
tcp: { type: Number, default: 0 },
tls: { type: Number, default: 0 },
firstByte: { type: Number, default: 0 },
download: { type: Number, default: 0 },
},
{ _id: false }
);
const geoCheckLocationSchema = new Schema<GeoCheckLocation>(
{
continent: { type: String, required: true },
region: { type: String, default: "" },
country: { type: String, default: "" },
state: { type: String, default: "" },
city: { type: String, default: "" },
longitude: { type: Number, default: 0 },
latitude: { type: Number, default: 0 },
},
{ _id: false }
);
const geoCheckResultSchema = new Schema<GeoCheckResult>(
{
location: {
type: geoCheckLocationSchema,
required: true,
},
status: {
type: Boolean,
required: true,
},
statusCode: {
type: Number,
required: true,
},
timings: {
type: geoCheckTimingsSchema,
required: true,
},
},
{ _id: false }
);
const GeoCheckSchema = new Schema<GeoCheckDocument>(
{
metadata: {
type: geoCheckMetadataSchema,
required: true,
},
results: {
type: [geoCheckResultSchema],
required: true,
default: [],
},
expiry: {
type: Date,
default: Date.now,
},
},
{
timestamps: true,
strict: false,
timeseries: {
timeField: "createdAt",
metaField: "metadata",
granularity: "seconds",
},
}
);
GeoCheckSchema.index({ "metadata.monitorId": 1, createdAt: -1 });
GeoCheckSchema.index({ "metadata.monitorId": 1, createdAt: 1 });
GeoCheckSchema.index({ "metadata.teamId": 1, createdAt: -1 });
GeoCheckSchema.index({ createdAt: 1 });
const GeoCheckModel = model<GeoCheckDocument>("GeoCheck", GeoCheckSchema);
export type { GeoCheckMetadataDocument };
export { GeoCheckModel };
export default GeoCheckModel;
-90
View File
@@ -1,90 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import { IncidentResolutionTypes, type Incident } from "@/types/incident.js";
type IncidentDocumentBase = Omit<Incident, "id" | "monitorId" | "teamId" | "resolvedBy" | "startTime" | "endTime" | "createdAt" | "updatedAt"> & {
monitorId: Types.ObjectId;
teamId: Types.ObjectId;
resolvedBy?: Types.ObjectId | null;
startTime: Date;
endTime: Date | null;
createdAt: Date;
updatedAt: Date;
};
export interface IncidentDocument extends IncidentDocumentBase {
_id: Types.ObjectId;
}
const IncidentSchema = new Schema<IncidentDocument>(
{
monitorId: {
type: Schema.Types.ObjectId,
ref: "Monitor",
required: true,
immutable: true,
index: true,
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
required: true,
immutable: true,
index: true,
},
startTime: {
type: Date,
immutable: true,
required: true,
},
endTime: {
type: Date,
default: null,
},
status: {
type: Boolean,
default: true,
index: true,
},
message: {
type: String,
default: null,
},
statusCode: {
type: Number,
default: null,
index: true,
},
resolutionType: {
type: String,
enum: IncidentResolutionTypes,
default: null,
},
resolvedBy: {
type: Schema.Types.ObjectId,
ref: "User",
default: null,
},
resolvedByEmail: {
type: String,
default: null,
},
comment: {
type: String,
default: null,
},
},
{ timestamps: true }
);
IncidentSchema.index({ monitorId: 1, status: 1 });
IncidentSchema.index({ teamId: 1, status: 1 });
IncidentSchema.index({ teamId: 1, startTime: -1 });
IncidentSchema.index({ status: 1, startTime: -1 });
IncidentSchema.index({ resolutionType: 1, status: 1 });
IncidentSchema.index({ resolvedBy: 1, status: 1 });
IncidentSchema.index({ createdAt: -1 });
const IncidentModel = model<IncidentDocument>("Incident", IncidentSchema);
export { IncidentModel };
export default IncidentModel;
-30
View File
@@ -1,30 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { Invite } from "@/types/invite.js";
type InviteDocumentBase = Omit<Invite, "id" | "teamId" | "createdAt" | "updatedAt" | "expiry"> & {
teamId: Types.ObjectId;
expiry: Date;
};
interface InviteDocument extends InviteDocumentBase {
_id: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const InviteSchema = new Schema<InviteDocument>(
{
email: { type: String, required: true, unique: true },
teamId: { type: Schema.Types.ObjectId, ref: "Team", immutable: true, required: true },
role: { type: [String], required: true, default: ["user"] },
token: { type: String, required: true },
expiry: { type: Date, default: Date.now, expires: 3600 },
},
{ timestamps: true }
);
const InviteModel = model<InviteDocument>("Invite", InviteSchema);
export type { InviteDocument };
export { InviteModel };
export default InviteModel;
-67
View File
@@ -1,67 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import { DurationUnits, type MaintenanceWindow } from "@/types/maintenanceWindow.js";
type MaintenanceWindowDocumentBase = Omit<MaintenanceWindow, "id" | "monitorIds" | "teamId" | "start" | "end" | "createdAt" | "updatedAt"> & {
monitorIds: Types.ObjectId[];
teamId: Types.ObjectId;
start: Date;
end: Date;
expiry?: Date;
createdAt: Date;
updatedAt: Date;
};
interface MaintenanceWindowDocument extends MaintenanceWindowDocumentBase {
_id: Types.ObjectId;
}
const MaintenanceWindowSchema = new Schema<MaintenanceWindowDocument>(
{
monitorIds: {
type: [Schema.Types.ObjectId],
ref: "Monitor",
index: true,
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
immutable: true,
},
active: {
type: Boolean,
default: true,
},
name: {
type: String,
},
duration: {
type: Number,
},
durationUnit: {
type: String,
enum: DurationUnits,
},
repeat: {
type: Number,
},
start: {
type: Date,
},
end: {
type: Date,
},
expiry: {
type: Date,
index: { expires: "0s" },
},
},
{
timestamps: true,
}
);
const MaintenanceWindowModel = model<MaintenanceWindowDocument>("MaintenanceWindow", MaintenanceWindowSchema);
export type { MaintenanceWindowDocument };
export { MaintenanceWindowModel };
export default MaintenanceWindowModel;
-13
View File
@@ -1,13 +0,0 @@
import mongoose from "mongoose";
const MigrationSchema = new mongoose.Schema(
{
name: { type: String, required: true, unique: true },
status: { type: String, enum: ["completed", "failed"], default: "completed" },
completedAt: { type: Date },
error: { type: String },
},
{ timestamps: true }
);
export default mongoose.model("Migration", MigrationSchema);
-392
View File
@@ -1,392 +0,0 @@
import { Schema, model, Types } from "mongoose";
import type { Monitor, MonitorMatchMethod, CheckSnapshot } from "@/types/monitor.js";
import { DnsRecordTypes, MonitorTypes, MonitorStatuses, PageSpeedStrategies } from "@/types/monitor.js";
import type {
CheckAudits,
CheckCaptureInfo,
CheckCpuInfo,
CheckDiskInfo,
CheckErrorInfo,
CheckHostInfo,
CheckMemoryInfo,
CheckNetworkInterfaceInfo,
GotTimings,
ILighthouseAudit,
} from "@/types/check.js";
type CheckSnapshotDocument = Omit<CheckSnapshot, "createdAt"> & { createdAt: Date };
type MonitorDocumentBase = Omit<
Monitor,
"id" | "userId" | "teamId" | "notifications" | "tags" | "selectedDisks" | "statusWindow" | "recentChecks" | "createdAt" | "updatedAt"
> & {
statusWindow: boolean[];
recentChecks: CheckSnapshotDocument[];
notifications: Types.ObjectId[];
tags: Types.ObjectId[];
selectedDisks: string[];
matchMethod?: MonitorMatchMethod;
};
interface MonitorDocument extends MonitorDocumentBase {
_id: Types.ObjectId;
userId: Types.ObjectId;
teamId: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const snapshotTimingPhasesSchema = new Schema<GotTimings["phases"]>(
{
wait: { type: Number },
dns: { type: Number },
tcp: { type: Number },
tls: { type: Number },
request: { type: Number },
firstByte: { type: Number },
download: { type: Number },
total: { type: Number },
},
{ _id: false }
);
const snapshotTimingsSchema = new Schema<GotTimings>(
{
start: { type: Number },
socket: { type: Number },
lookup: { type: Number },
connect: { type: Number },
secureConnect: { type: Number },
upload: { type: Number },
response: { type: Number },
end: { type: Number },
phases: { type: snapshotTimingPhasesSchema },
},
{ _id: false }
);
const snapshotCpuSchema = new Schema<CheckCpuInfo>(
{
physical_core: { type: Number },
logical_core: { type: Number },
frequency: { type: Number },
current_frequency: { type: Number },
temperature: { type: [Number] },
free_percent: { type: Number },
usage_percent: { type: Number },
},
{ _id: false }
);
const snapshotMemorySchema = new Schema<CheckMemoryInfo>(
{
total_bytes: { type: Number },
available_bytes: { type: Number },
used_bytes: { type: Number },
usage_percent: { type: Number },
},
{ _id: false }
);
const snapshotDiskSchema = new Schema<CheckDiskInfo>(
{
device: { type: String },
mountpoint: { type: String },
total_bytes: { type: Number },
free_bytes: { type: Number },
used_bytes: { type: Number },
usage_percent: { type: Number },
total_inodes: { type: Number },
free_inodes: { type: Number },
used_inodes: { type: Number },
inodes_usage_percent: { type: Number },
read_bytes: { type: Number },
write_bytes: { type: Number },
read_time: { type: Number },
write_time: { type: Number },
},
{ _id: false }
);
const snapshotHostSchema = new Schema<CheckHostInfo>(
{
os: { type: String },
platform: { type: String },
kernel_version: { type: String },
pretty_name: { type: String },
},
{ _id: false }
);
const snapshotErrorSchema = new Schema<CheckErrorInfo>(
{
metric: { type: [String] },
err: { type: String },
},
{ _id: false }
);
const snapshotCaptureSchema = new Schema<CheckCaptureInfo>(
{
version: { type: String },
mode: { type: String },
},
{ _id: false }
);
const snapshotNetworkInterfaceSchema = new Schema<CheckNetworkInterfaceInfo>(
{
name: { type: String },
bytes_sent: { type: Number },
bytes_recv: { type: Number },
packets_sent: { type: Number },
packets_recv: { type: Number },
err_in: { type: Number },
err_out: { type: Number },
drop_in: { type: Number },
drop_out: { type: Number },
fifo_in: { type: Number },
fifo_out: { type: Number },
},
{ _id: false }
);
const snapshotLighthouseAuditSchema = new Schema<ILighthouseAudit>(
{
id: { type: String },
title: { type: String },
score: { type: Number },
displayValue: { type: String },
numericValue: { type: Number },
numericUnit: { type: String },
},
{ _id: false }
);
const snapshotAuditsSchema = new Schema<CheckAudits>(
{
cls: { type: snapshotLighthouseAuditSchema },
si: { type: snapshotLighthouseAuditSchema },
fcp: { type: snapshotLighthouseAuditSchema },
lcp: { type: snapshotLighthouseAuditSchema },
tbt: { type: snapshotLighthouseAuditSchema },
},
{ _id: false }
);
const checkSnapshotSchema = new Schema<CheckSnapshotDocument>(
{
id: { type: String, required: true },
status: { type: Boolean, required: true },
responseTime: { type: Number },
timings: { type: snapshotTimingsSchema },
statusCode: { type: Number },
message: { type: String },
cpu: { type: snapshotCpuSchema },
memory: { type: snapshotMemorySchema },
disk: { type: [snapshotDiskSchema] },
host: { type: snapshotHostSchema },
errors: { type: [snapshotErrorSchema] },
capture: { type: snapshotCaptureSchema },
net: { type: [snapshotNetworkInterfaceSchema] },
accessibility: { type: Number },
bestPractices: { type: Number },
seo: { type: Number },
performance: { type: Number },
audits: { type: snapshotAuditsSchema },
createdAt: { type: Date, required: true },
},
{ _id: false }
);
const MonitorSchema = new Schema<MonitorDocument>(
{
userId: {
type: Schema.Types.ObjectId,
ref: "User",
immutable: true,
required: true,
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
immutable: true,
required: true,
},
name: {
type: String,
required: true,
},
description: {
type: String,
},
status: {
type: String,
enum: MonitorStatuses,
default: "initializing",
},
statusWindow: {
type: [Boolean],
default: [],
},
statusWindowSize: {
type: Number,
default: 5,
},
statusWindowThreshold: {
type: Number,
default: 60,
},
type: {
type: String,
required: true,
enum: MonitorTypes,
},
ignoreTlsErrors: {
type: Boolean,
default: false,
},
useAdvancedMatching: {
type: Boolean,
default: false,
},
jsonPath: {
type: String,
},
expectedValue: {
type: String,
},
matchMethod: {
type: String,
enum: ["equal", "include", "regex", ""],
},
url: {
type: String,
required: true,
},
port: {
type: Number,
},
isActive: {
type: Boolean,
default: true,
},
interval: {
type: Number,
default: 60000,
},
uptimePercentage: {
type: Number,
default: undefined,
},
notifications: [
{
type: Schema.Types.ObjectId,
ref: "Notification",
},
],
tags: [
{
type: Schema.Types.ObjectId,
ref: "Tag",
},
],
customUpCodes: {
type: [Number],
default: [],
},
secret: {
type: String,
},
cpuAlertThreshold: {
type: Number,
default: 100,
},
cpuAlertCounter: {
type: Number,
default: 5,
},
memoryAlertThreshold: {
type: Number,
default: 100,
},
memoryAlertCounter: {
type: Number,
default: 5,
},
diskAlertThreshold: {
type: Number,
default: 100,
},
diskAlertCounter: {
type: Number,
default: 5,
},
tempAlertThreshold: {
type: Number,
default: 100,
},
tempAlertCounter: {
type: Number,
default: 5,
},
selectedDisks: {
type: [String],
default: [],
},
gameId: {
type: String,
},
grpcServiceName: {
type: String,
default: "",
},
strategy: {
type: String,
enum: PageSpeedStrategies,
},
group: {
type: String,
trim: true,
maxLength: 50,
default: null,
set(value: string | null) {
return value && value.trim() ? value.trim() : null;
},
},
geoCheckEnabled: {
type: Boolean,
default: false,
},
geoCheckLocations: {
type: [String],
default: [],
},
geoCheckInterval: {
type: Number,
default: 300000,
},
dnsServer: {
type: String,
},
dnsRecordType: {
type: String,
enum: DnsRecordTypes,
},
recentChecks: {
type: [checkSnapshotSchema],
default: [],
},
},
{
timestamps: true,
}
);
MonitorSchema.index({ teamId: 1, type: 1 });
const MonitorModel = model<MonitorDocument>("Monitor", MonitorSchema);
export type { MonitorDocument, CheckSnapshotDocument };
export { MonitorModel };
export default MonitorModel;
-66
View File
@@ -1,66 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { MonitorStats as MonitorStatsEntity } from "@/types/monitorStats.js";
type MonitorStatsDocumentBase = Omit<MonitorStatsEntity, "id" | "monitorId" | "createdAt" | "updatedAt"> & {
monitorId: Types.ObjectId;
};
interface MonitorStatsDocument extends MonitorStatsDocumentBase {
_id: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const MonitorStatsSchema = new Schema<MonitorStatsDocument>(
{
monitorId: {
type: Schema.Types.ObjectId,
ref: "Monitor",
unique: true,
required: true,
},
avgResponseTime: {
type: Number,
default: 0,
},
maxResponseTime: {
type: Number,
default: 0,
},
totalChecks: {
type: Number,
default: 0,
},
totalUpChecks: {
type: Number,
default: 0,
},
totalDownChecks: {
type: Number,
default: 0,
},
uptimePercentage: {
type: Number,
default: 0,
},
lastCheckTimestamp: {
type: Number,
default: 0,
},
lastResponseTime: {
type: Number,
default: 0,
},
timeOfLastFailure: {
type: Number,
default: undefined,
},
},
{ timestamps: true }
);
const MonitorStatsModel = model<MonitorStatsDocument>("MonitorStats", MonitorStatsSchema);
export type { MonitorStatsDocument };
export { MonitorStatsModel };
export default MonitorStatsModel;
-65
View File
@@ -1,65 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { Notification, NotificationChannel } from "@/types/notification.js";
interface NotificationDocument extends Omit<Notification, "id" | "userId" | "teamId" | "createdAt" | "updatedAt"> {
_id: Types.ObjectId;
userId: Types.ObjectId;
teamId: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const NotificationSchema = new Schema<NotificationDocument>(
{
userId: {
type: Schema.Types.ObjectId,
ref: "User",
immutable: true,
required: true,
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
immutable: true,
required: true,
},
type: {
type: String,
enum: [
"email",
"slack",
"discord",
"webhook",
"pager_duty",
"matrix",
"teams",
"telegram",
"pushover",
"twilio",
"ntfy",
] as NotificationChannel[],
required: true,
},
notificationName: {
type: String,
required: true,
},
address: { type: String },
phone: { type: String },
homeserverUrl: { type: String },
roomId: { type: String },
accessToken: { type: String },
accountSid: { type: String },
twilioPhoneNumber: { type: String },
topic: { type: String },
},
{
timestamps: true,
}
);
const NotificationModel = model<NotificationDocument>("Notification", NotificationSchema);
export type { NotificationDocument };
export { NotificationModel };
export default NotificationModel;
-28
View File
@@ -1,28 +0,0 @@
import { Schema, model } from "mongoose";
import { QueueModes, type QueueMode } from "@/types/settings.js";
// Heartbeat presence record for a scheduler instance. _id is the scheduler's
// workerId (hostname:pid:uuid). The TTL index on lastSeenAt garbage-collects
// records for instances that have stopped heartbeating.
interface QueueWorkerDocument {
_id: string;
mode: QueueMode;
lastSeenAt: Date;
createdAt: Date;
updatedAt: Date;
}
const QueueWorkerSchema = new Schema<QueueWorkerDocument>(
{
_id: { type: String, required: true },
mode: { type: String, enum: QueueModes, required: true },
lastSeenAt: { type: Date, default: Date.now, expires: 30 },
},
{ timestamps: true }
);
const QueueWorkerModel = model<QueueWorkerDocument>("QueueWorker", QueueWorkerSchema);
export type { QueueWorkerDocument };
export { QueueWorkerModel };
export default QueueWorkerModel;
-27
View File
@@ -1,27 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { RecoveryToken as RecoveryTokenEntity } from "@/types/recoveryToken.js";
type RecoveryTokenDocumentBase = Omit<RecoveryTokenEntity, "id" | "createdAt" | "updatedAt" | "expiry"> & {
expiry: Date;
};
interface RecoveryTokenDocument extends RecoveryTokenDocumentBase {
_id: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const RecoveryTokenSchema = new Schema<RecoveryTokenDocument>(
{
email: { type: String, required: true, unique: true },
token: { type: String, required: true },
expiry: { type: Date, default: Date.now, expires: 600 },
},
{ timestamps: true }
);
const RecoveryTokenModel = model<RecoveryTokenDocument>("RecoveryToken", RecoveryTokenSchema);
export type { RecoveryTokenDocument };
export { RecoveryTokenModel };
export default RecoveryTokenModel;
-135
View File
@@ -1,135 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { StatusPage, StatusPageLogoDocument } from "@/types/statusPage.js";
import {
DEFAULT_STATUS_PAGE_THEME,
DEFAULT_STATUS_PAGE_THEME_MODE,
StatusPageThemeModes,
StatusPageThemes,
StatusPageTypes,
} from "@/types/statusPage.js";
type StatusPageDocumentBase = Omit<
StatusPage,
"id" | "userId" | "teamId" | "monitors" | "subMonitors" | "originalMonitors" | "logo" | "createdAt" | "updatedAt"
> & {
monitors: Types.ObjectId[];
subMonitors: Types.ObjectId[];
originalMonitors?: Types.ObjectId[];
logo?: StatusPageLogoDocument | null;
};
interface StatusPageDocument extends StatusPageDocumentBase {
_id: Types.ObjectId;
userId: Types.ObjectId;
teamId: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const logoSchema = new Schema<StatusPageLogoDocument>(
{
data: { type: Buffer },
contentType: { type: String },
},
{ _id: false }
);
const StatusPageSchema = new Schema<StatusPageDocument>(
{
userId: {
type: Schema.Types.ObjectId,
ref: "User",
immutable: true,
required: true,
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
immutable: true,
required: true,
},
type: {
type: [String],
required: true,
default: ["uptime"],
enum: StatusPageTypes,
},
companyName: {
type: String,
required: true,
default: "",
},
url: {
type: String,
unique: true,
required: true,
default: "",
},
timezone: {
type: String,
},
color: {
type: String,
default: "#4169E1",
},
monitors: [
{
type: Schema.Types.ObjectId,
ref: "Monitor",
required: true,
},
],
subMonitors: [
{
type: Schema.Types.ObjectId,
ref: "Monitor",
required: true,
},
],
logo: {
type: logoSchema,
default: null,
},
isPublished: {
type: Boolean,
default: false,
},
showCharts: {
type: Boolean,
default: true,
},
showUptimePercentage: {
type: Boolean,
default: true,
},
showAdminLoginLink: {
type: Boolean,
default: false,
},
showInfrastructure: {
type: Boolean,
default: false,
},
customCSS: {
type: String,
default: "",
},
theme: {
type: String,
enum: StatusPageThemes,
default: DEFAULT_STATUS_PAGE_THEME,
},
themeMode: {
type: String,
enum: StatusPageThemeModes,
default: DEFAULT_STATUS_PAGE_THEME_MODE,
},
},
{ timestamps: true }
);
const StatusPageModel = model<StatusPageDocument>("StatusPage", StatusPageSchema);
export type { StatusPageDocument };
export { StatusPageModel };
export default StatusPageModel;
-33
View File
@@ -1,33 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { Tag as TagEntity } from "@/types/index.js";
type TagDocumentBase = Omit<TagEntity, "id" | "teamId" | "createdAt" | "updatedAt">;
interface TagDocument extends TagDocumentBase {
_id: Types.ObjectId;
teamId: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const TagSchema = new Schema<TagDocument>(
{
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
immutable: true,
required: true,
},
name: { type: String, required: true },
color: { type: String, required: true, default: "#13715B" },
},
{ timestamps: true }
);
TagSchema.index({ teamId: 1, name: 1 }, { unique: true });
const TagModel = model<TagDocument>("Tag", TagSchema);
export type { TagDocument };
export { TagModel };
export default TagModel;
-28
View File
@@ -1,28 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import type { Team } from "@/types/index.js";
type TeamDocumentBase = Omit<Team, "id" | "createdAt" | "updatedAt"> & {};
interface TeamDocument extends TeamDocumentBase {
_id: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const TeamSchema = new Schema<TeamDocument>(
{
email: {
type: String,
required: true,
unique: true,
},
},
{
timestamps: true,
}
);
const TeamModel = model<TeamDocument>("Team", TeamSchema);
export type { TeamDocument };
export { TeamModel };
export default TeamModel;
-77
View File
@@ -1,77 +0,0 @@
import { Schema, model, type Types } from "mongoose";
import bcrypt from "bcryptjs";
import type { User, UserProfileImage, UserRole } from "@/types/index.js";
import { MonitorModel } from "@/db/models/index.js";
import Team from "./Team.js";
import NotificationModel from "./Notification.js";
type UserDocumentBase = Omit<User, "id" | "teamId" | "createdAt" | "updatedAt"> & {
teamId?: Types.ObjectId;
profileImage?: Required<UserProfileImage>;
};
interface UserDocument extends UserDocumentBase {
_id: Types.ObjectId;
teamId?: Types.ObjectId;
createdAt: Date;
updatedAt: Date;
}
const profileImageSchema = new Schema<Required<UserProfileImage>>(
{
data: { type: Buffer },
contentType: { type: String },
},
{ _id: false }
);
const UserSchema = new Schema<UserDocument>(
{
firstName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
avatarImage: { type: String },
profileImage: { type: profileImageSchema },
isActive: { type: Boolean, default: true },
isVerified: { type: Boolean, default: false },
role: {
type: [String],
enum: ["user", "admin", "superadmin", "demo" satisfies UserRole],
default: ["user"],
},
teamId: {
type: Schema.Types.ObjectId,
ref: "Team",
immutable: true,
},
checkTTL: { type: Number },
},
{ timestamps: true }
);
UserSchema.pre("findOneAndDelete", async function (next) {
try {
const userToDelete = await this.model.findOne(this.getFilter());
if (!userToDelete) return next();
if (userToDelete.role.includes("superadmin")) {
await Team.deleteOne({ _id: userToDelete.teamId });
await MonitorModel.deleteMany({ userId: userToDelete._id });
await this.model.deleteMany({ teamId: userToDelete.teamId, _id: { $ne: userToDelete._id } });
await NotificationModel.deleteMany({ teamId: userToDelete.teamId });
}
next();
} catch (error) {
next(error as Error);
}
});
UserSchema.methods.comparePassword = async function (submittedPassword: string) {
return bcrypt.compare(submittedPassword, this.password);
};
const UserModel = model<UserDocument>("User", UserSchema);
export type { UserDocument };
export { UserModel };
export default UserModel;
-46
View File
@@ -1,46 +0,0 @@
export * from "@/db/models/Monitor.js";
export { default as MonitorModel } from "@/db/models/Monitor.js";
export * from "@/db/models/Check.js";
export { default as CheckModel } from "@/db/models/Check.js";
export * from "@/db/models/MonitorStats.js";
export { default as MonitorStatsModel } from "@/db/models/MonitorStats.js";
export * from "@/db/models/StatusPage.js";
export { default as StatusPageModel } from "@/db/models/StatusPage.js";
export * from "@/db/models/User.js";
export { default as UserModel } from "@/db/models/User.js";
export * from "@/db/models/Invite.js";
export { default as InviteModel } from "@/db/models/Invite.js";
export * from "@/db/models/AppSettings.js";
export { default as AppSettingsModel } from "@/db/models/AppSettings.js";
export * from "@/db/models/RecoveryToken.js";
export { default as RecoveryTokenModel } from "@/db/models/RecoveryToken.js";
export * from "@/db/models/Notification.js";
export { default as NotificationModel } from "@/db/models/Notification.js";
export * from "@/db/models/Incident.js";
export { default as IncidentModel } from "@/db/models/Incident.js";
export * from "@/db/models/Team.js";
export { default as TeamModel } from "@/db/models/Team.js";
export * from "@/db/models/MaintenanceWindow.js";
export { default as MaintenanceWindowModel } from "@/db/models/MaintenanceWindow.js";
export * from "@/db/models/GeoCheck.js";
export { default as GeoCheckModel } from "@/db/models/GeoCheck.js";
export * from "@/db/models/DLQItem.js";
export { default as DLQItemModel } from "@/db/models/DLQItem.js";
export * from "@/db/models/Tag.js";
export { default as TagModel } from "@/db/models/Tag.js";
export * from "@/db/models/QueueWorker.js";
export { default as QueueWorkerModel } from "@/db/models/QueueWorker.js";