ts errors
This commit is contained in:
1 parent
81d6c4651f
commit
605b4713af
6 files changed
+39
-154
No files matched your search
@@ -4,120 +4,14 @@ import {
|
||||
MonitorTypes,
|
||||
MonitorStatus,
|
||||
MonitorStatuses,
|
||||
ISystemInfo,
|
||||
ICaptureInfo,
|
||||
ICheckLighthouseFields,
|
||||
IDockerContainerHealth,
|
||||
IDockerExposedPort,
|
||||
} from "@/types/domain/index.js";
|
||||
import type { Response } from "got";
|
||||
export type GotTimings = Response["timings"];
|
||||
export interface ITimingPhases {
|
||||
wait: number;
|
||||
dns: number;
|
||||
tcp: number;
|
||||
tls: number;
|
||||
request: number;
|
||||
firstByte: number;
|
||||
download: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
export interface ICpuInfo {
|
||||
physical_core: number;
|
||||
logical_core: number;
|
||||
frequency: number;
|
||||
current_frequency: number;
|
||||
temperature: number[]; // per-core temps
|
||||
free_percent: number;
|
||||
usage_percent: number;
|
||||
}
|
||||
|
||||
export interface IMemoryInfo {
|
||||
total_bytes: number;
|
||||
available_bytes: number;
|
||||
used_bytes: number;
|
||||
usage_percent: number;
|
||||
}
|
||||
|
||||
export interface IHostInfo {
|
||||
os?: string;
|
||||
platform?: string;
|
||||
kernel_version?: string;
|
||||
pretty_name?: string;
|
||||
}
|
||||
|
||||
export interface IDiskInfo {
|
||||
device: string;
|
||||
total_bytes: number;
|
||||
free_bytes: number;
|
||||
used_bytes: number;
|
||||
usage_percent: number;
|
||||
total_inodes?: number;
|
||||
free_inodes?: number;
|
||||
used_inodes?: number;
|
||||
inodes_usage_percent?: number;
|
||||
read_bytes?: number;
|
||||
write_bytes?: number;
|
||||
read_time?: number;
|
||||
write_time?: number;
|
||||
}
|
||||
|
||||
export interface INetInfo {
|
||||
name: string;
|
||||
bytes_sent: number;
|
||||
bytes_recv: number;
|
||||
packets_sent: number;
|
||||
packets_recv: number;
|
||||
err_in: number;
|
||||
err_out: number;
|
||||
drop_in: number;
|
||||
drop_out: number;
|
||||
fifo_in: number;
|
||||
fifo_out: number;
|
||||
}
|
||||
|
||||
export interface ICaptureInfo {
|
||||
version?: string;
|
||||
mode?: string;
|
||||
}
|
||||
|
||||
export interface ISystemInfo {
|
||||
cpu: ICpuInfo;
|
||||
memory: IMemoryInfo;
|
||||
disk: IDiskInfo[];
|
||||
host: IHostInfo;
|
||||
net: INetInfo[];
|
||||
}
|
||||
|
||||
export interface ILighthouseAudit {
|
||||
id?: string;
|
||||
title?: string;
|
||||
score?: number | null;
|
||||
displayValue?: string;
|
||||
numericValue?: number;
|
||||
numericUnit?: string;
|
||||
}
|
||||
export interface ILighthouseCategories {
|
||||
accessibility?: { score?: number | null };
|
||||
"best-practices"?: { score?: number | null };
|
||||
seo?: { score?: number | null };
|
||||
performance?: { score?: number | null };
|
||||
}
|
||||
|
||||
export interface ILighthouseResult {
|
||||
categories?: ILighthouseCategories;
|
||||
audits?: Record<string, ILighthouseAudit>;
|
||||
}
|
||||
|
||||
export interface ICheckLighthouseFields {
|
||||
accessibility: number;
|
||||
bestPractices: number;
|
||||
seo: number;
|
||||
performance: number;
|
||||
audits: {
|
||||
cls: ILighthouseAudit;
|
||||
si: ILighthouseAudit;
|
||||
fcp: ILighthouseAudit;
|
||||
lcp: ILighthouseAudit;
|
||||
tbt: ILighthouseAudit;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ICheck extends Document {
|
||||
_id: Types.ObjectId;
|
||||
@@ -143,18 +37,7 @@ export interface ICheck extends Document {
|
||||
expiry: Date;
|
||||
}
|
||||
|
||||
export interface IDockerContainerHealth {
|
||||
healthy: boolean;
|
||||
source?: string;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
export interface IDockerExposedPort {
|
||||
port: string;
|
||||
protocol: string;
|
||||
}
|
||||
|
||||
export interface IDockerContainerSummary {
|
||||
interface IDockerContainerSummary {
|
||||
container_id: string;
|
||||
container_name: string;
|
||||
status: string;
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
export { Check } from "./checks/Check.js";
|
||||
export type {
|
||||
ICheck,
|
||||
ISystemInfo,
|
||||
ICaptureInfo,
|
||||
ILighthouseResult,
|
||||
IDockerContainerSummary,
|
||||
} from "./checks/Check.js";
|
||||
|
||||
export type { ICheck } from "./checks/Check.js";
|
||||
export { Monitor } from "./monitors/Monitor.js";
|
||||
export type { IMonitor } from "./monitors/Monitor.js";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import mongoose, { Schema, Document, Types } from "mongoose";
|
||||
import type { IDockerContainerSummary } from "@/db/models/checks/Check.js";
|
||||
import type { IDockerContainerSummary } from "@/types/domain/index.js";
|
||||
import {
|
||||
Check,
|
||||
Incident,
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { ISystemInfo } from "@/types/domain/index.js";
|
||||
import type { IDockerPayload } from "@/services/infrastructure/NetworkService.js";
|
||||
import type {
|
||||
IDockerPayload,
|
||||
IPageSpeedPayload,
|
||||
} from "@/services/infrastructure/NetworkService.js";
|
||||
import { MonitorStatus, MonitorType } from "@/types/domain/index.js";
|
||||
import { StatusResponse } from "@/services/infrastructure/NetworkService.js";
|
||||
import type {
|
||||
ICapturePayload,
|
||||
ILighthousePayload,
|
||||
} from "@/services/infrastructure/NetworkService.js";
|
||||
import type { ICapturePayload } from "@/services/infrastructure/NetworkService.js";
|
||||
import ApiError from "@/utils/ApiError.js";
|
||||
import { getChildLogger } from "@/logger/Logger.js";
|
||||
import { getStartDate } from "@/utils/TimeUtils.js";
|
||||
|
||||
import type { CheckEntity } from "@/types/domain/index.js";
|
||||
import type {
|
||||
CheckEntity,
|
||||
ICheckLighthouseFields,
|
||||
} from "@/types/domain/index.js";
|
||||
import type {
|
||||
IChecksRepository,
|
||||
IMonitorRepository,
|
||||
@@ -100,9 +103,7 @@ class CheckService implements ICheckService {
|
||||
return true;
|
||||
};
|
||||
|
||||
private isPagespeedPayload = (
|
||||
payload: any
|
||||
): payload is ILighthousePayload => {
|
||||
private isPagespeedPayload = (payload: any): payload is IPageSpeedPayload => {
|
||||
if (!payload || typeof payload !== "object") return false;
|
||||
|
||||
if (
|
||||
@@ -165,7 +166,7 @@ class CheckService implements ICheckService {
|
||||
};
|
||||
|
||||
private buildPagespeedCheck = (
|
||||
statusResponse: StatusResponse<ILighthousePayload>
|
||||
statusResponse: StatusResponse<IPageSpeedPayload>
|
||||
) => {
|
||||
if (!this.isPagespeedPayload(statusResponse.payload)) {
|
||||
throw new Error("Invalid payload for pagespeed monitor");
|
||||
@@ -226,7 +227,7 @@ class CheckService implements ICheckService {
|
||||
|
||||
case "pagespeed":
|
||||
return this.buildPagespeedCheck(
|
||||
statusResponse as StatusResponse<ILighthousePayload>
|
||||
statusResponse as StatusResponse<IPageSpeedPayload>
|
||||
);
|
||||
case "http":
|
||||
case "https":
|
||||
|
||||
@@ -6,15 +6,14 @@ import type { Response } from "got";
|
||||
import type {
|
||||
ISystemInfo,
|
||||
ICaptureInfo,
|
||||
ILighthouseResult,
|
||||
} from "@/db/models/index.js";
|
||||
IDockerContainerSummary,
|
||||
} from "@/types/domain/index.js";
|
||||
import type { TLSSocket } from "node:tls";
|
||||
import { MonitorType, MonitorStatus } from "@/types/domain/index.js";
|
||||
import ApiError from "@/utils/ApiError.js";
|
||||
import { config } from "@/config/index.js";
|
||||
import CacheableLookup from "cacheable-lookup";
|
||||
import { getChildLogger } from "@/logger/Logger.js";
|
||||
import type { IDockerContainerSummary } from "@/db/models/index.js";
|
||||
import type { Monitor } from "@/types/domain/monitor.js";
|
||||
|
||||
const SERVICE_NAME = "NetworkService";
|
||||
@@ -33,15 +32,25 @@ export interface ICapturePayload {
|
||||
capture: ICaptureInfo;
|
||||
}
|
||||
|
||||
export interface ILighthousePayload {
|
||||
lighthouseResult: ILighthouseResult;
|
||||
}
|
||||
|
||||
export interface IDockerPayload {
|
||||
data: IDockerContainerSummary[];
|
||||
capture: ICaptureInfo;
|
||||
}
|
||||
|
||||
interface ILighthouseCategories {
|
||||
accessibility?: { score?: number | null };
|
||||
"best-practices"?: { score?: number | null };
|
||||
seo?: { score?: number | null };
|
||||
performance?: { score?: number | null };
|
||||
}
|
||||
|
||||
export interface IPageSpeedPayload {
|
||||
lighthouseResult: {
|
||||
categories: ILighthouseCategories;
|
||||
audits: Record<string, unknown>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface StatusResponse<TPayload = unknown> {
|
||||
monitorId: string;
|
||||
teamId: string;
|
||||
@@ -235,7 +244,7 @@ class NetworkService implements INetworkService {
|
||||
throw new Error("No URL provided");
|
||||
}
|
||||
|
||||
let statusResponse: StatusResponse<ILighthousePayload>;
|
||||
let statusResponse: StatusResponse<IPageSpeedPayload>;
|
||||
|
||||
try {
|
||||
const response: Response = await this.client(url);
|
||||
@@ -244,13 +253,13 @@ class NetworkService implements INetworkService {
|
||||
response,
|
||||
null,
|
||||
null
|
||||
) as StatusResponse<ILighthousePayload>;
|
||||
) as StatusResponse<IPageSpeedPayload>;
|
||||
} catch (error) {
|
||||
statusResponse = this.buildStatusResponse(monitor, null, null, error);
|
||||
}
|
||||
|
||||
const pagespeedUrl = `https://pagespeedonline.googleapis.com/pagespeedonline/v5/runPagespeed?url=${url}&category=seo&category=accessibility&category=best-practices&category=performance&key=${apiKey}`;
|
||||
const pagespeedResponse = await this.client<ILighthousePayload>(
|
||||
const pagespeedResponse = await this.client<IPageSpeedPayload>(
|
||||
pagespeedUrl,
|
||||
{
|
||||
responseType: "json",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { ICheck } from "@/db/models/index.js";
|
||||
import { StatusResponse } from "./NetworkService.js";
|
||||
import {
|
||||
IMonitorRepository,
|
||||
|
||||
Reference in new issue
Block a user