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,
|
MonitorTypes,
|
||||||
MonitorStatus,
|
MonitorStatus,
|
||||||
MonitorStatuses,
|
MonitorStatuses,
|
||||||
|
ISystemInfo,
|
||||||
|
ICaptureInfo,
|
||||||
|
ICheckLighthouseFields,
|
||||||
|
IDockerContainerHealth,
|
||||||
|
IDockerExposedPort,
|
||||||
} from "@/types/domain/index.js";
|
} from "@/types/domain/index.js";
|
||||||
import type { Response } from "got";
|
import type { Response } from "got";
|
||||||
export type GotTimings = Response["timings"];
|
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 {
|
export interface ICheck extends Document {
|
||||||
_id: Types.ObjectId;
|
_id: Types.ObjectId;
|
||||||
@@ -143,18 +37,7 @@ export interface ICheck extends Document {
|
|||||||
expiry: Date;
|
expiry: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IDockerContainerHealth {
|
interface IDockerContainerSummary {
|
||||||
healthy: boolean;
|
|
||||||
source?: string;
|
|
||||||
message?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IDockerExposedPort {
|
|
||||||
port: string;
|
|
||||||
protocol: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IDockerContainerSummary {
|
|
||||||
container_id: string;
|
container_id: string;
|
||||||
container_name: string;
|
container_name: string;
|
||||||
status: string;
|
status: string;
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
export { Check } from "./checks/Check.js";
|
export { Check } from "./checks/Check.js";
|
||||||
export type {
|
export type { ICheck } from "./checks/Check.js";
|
||||||
ICheck,
|
|
||||||
ISystemInfo,
|
|
||||||
ICaptureInfo,
|
|
||||||
ILighthouseResult,
|
|
||||||
IDockerContainerSummary,
|
|
||||||
} from "./checks/Check.js";
|
|
||||||
|
|
||||||
export { Monitor } from "./monitors/Monitor.js";
|
export { Monitor } from "./monitors/Monitor.js";
|
||||||
export type { IMonitor } from "./monitors/Monitor.js";
|
export type { IMonitor } from "./monitors/Monitor.js";
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import mongoose, { Schema, Document, Types } from "mongoose";
|
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 {
|
import {
|
||||||
Check,
|
Check,
|
||||||
Incident,
|
Incident,
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
import { ISystemInfo } from "@/types/domain/index.js";
|
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 { MonitorStatus, MonitorType } from "@/types/domain/index.js";
|
||||||
import { StatusResponse } from "@/services/infrastructure/NetworkService.js";
|
import { StatusResponse } from "@/services/infrastructure/NetworkService.js";
|
||||||
import type {
|
import type { ICapturePayload } from "@/services/infrastructure/NetworkService.js";
|
||||||
ICapturePayload,
|
|
||||||
ILighthousePayload,
|
|
||||||
} from "@/services/infrastructure/NetworkService.js";
|
|
||||||
import ApiError from "@/utils/ApiError.js";
|
import ApiError from "@/utils/ApiError.js";
|
||||||
import { getChildLogger } from "@/logger/Logger.js";
|
import { getChildLogger } from "@/logger/Logger.js";
|
||||||
import { getStartDate } from "@/utils/TimeUtils.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 {
|
import type {
|
||||||
IChecksRepository,
|
IChecksRepository,
|
||||||
IMonitorRepository,
|
IMonitorRepository,
|
||||||
@@ -100,9 +103,7 @@ class CheckService implements ICheckService {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
private isPagespeedPayload = (
|
private isPagespeedPayload = (payload: any): payload is IPageSpeedPayload => {
|
||||||
payload: any
|
|
||||||
): payload is ILighthousePayload => {
|
|
||||||
if (!payload || typeof payload !== "object") return false;
|
if (!payload || typeof payload !== "object") return false;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -165,7 +166,7 @@ class CheckService implements ICheckService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private buildPagespeedCheck = (
|
private buildPagespeedCheck = (
|
||||||
statusResponse: StatusResponse<ILighthousePayload>
|
statusResponse: StatusResponse<IPageSpeedPayload>
|
||||||
) => {
|
) => {
|
||||||
if (!this.isPagespeedPayload(statusResponse.payload)) {
|
if (!this.isPagespeedPayload(statusResponse.payload)) {
|
||||||
throw new Error("Invalid payload for pagespeed monitor");
|
throw new Error("Invalid payload for pagespeed monitor");
|
||||||
@@ -226,7 +227,7 @@ class CheckService implements ICheckService {
|
|||||||
|
|
||||||
case "pagespeed":
|
case "pagespeed":
|
||||||
return this.buildPagespeedCheck(
|
return this.buildPagespeedCheck(
|
||||||
statusResponse as StatusResponse<ILighthousePayload>
|
statusResponse as StatusResponse<IPageSpeedPayload>
|
||||||
);
|
);
|
||||||
case "http":
|
case "http":
|
||||||
case "https":
|
case "https":
|
||||||
|
|||||||
@@ -6,15 +6,14 @@ import type { Response } from "got";
|
|||||||
import type {
|
import type {
|
||||||
ISystemInfo,
|
ISystemInfo,
|
||||||
ICaptureInfo,
|
ICaptureInfo,
|
||||||
ILighthouseResult,
|
IDockerContainerSummary,
|
||||||
} from "@/db/models/index.js";
|
} from "@/types/domain/index.js";
|
||||||
import type { TLSSocket } from "node:tls";
|
import type { TLSSocket } from "node:tls";
|
||||||
import { MonitorType, MonitorStatus } from "@/types/domain/index.js";
|
import { MonitorType, MonitorStatus } from "@/types/domain/index.js";
|
||||||
import ApiError from "@/utils/ApiError.js";
|
import ApiError from "@/utils/ApiError.js";
|
||||||
import { config } from "@/config/index.js";
|
import { config } from "@/config/index.js";
|
||||||
import CacheableLookup from "cacheable-lookup";
|
import CacheableLookup from "cacheable-lookup";
|
||||||
import { getChildLogger } from "@/logger/Logger.js";
|
import { getChildLogger } from "@/logger/Logger.js";
|
||||||
import type { IDockerContainerSummary } from "@/db/models/index.js";
|
|
||||||
import type { Monitor } from "@/types/domain/monitor.js";
|
import type { Monitor } from "@/types/domain/monitor.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "NetworkService";
|
const SERVICE_NAME = "NetworkService";
|
||||||
@@ -33,15 +32,25 @@ export interface ICapturePayload {
|
|||||||
capture: ICaptureInfo;
|
capture: ICaptureInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ILighthousePayload {
|
|
||||||
lighthouseResult: ILighthouseResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IDockerPayload {
|
export interface IDockerPayload {
|
||||||
data: IDockerContainerSummary[];
|
data: IDockerContainerSummary[];
|
||||||
capture: ICaptureInfo;
|
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> {
|
export interface StatusResponse<TPayload = unknown> {
|
||||||
monitorId: string;
|
monitorId: string;
|
||||||
teamId: string;
|
teamId: string;
|
||||||
@@ -235,7 +244,7 @@ class NetworkService implements INetworkService {
|
|||||||
throw new Error("No URL provided");
|
throw new Error("No URL provided");
|
||||||
}
|
}
|
||||||
|
|
||||||
let statusResponse: StatusResponse<ILighthousePayload>;
|
let statusResponse: StatusResponse<IPageSpeedPayload>;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response: Response = await this.client(url);
|
const response: Response = await this.client(url);
|
||||||
@@ -244,13 +253,13 @@ class NetworkService implements INetworkService {
|
|||||||
response,
|
response,
|
||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
) as StatusResponse<ILighthousePayload>;
|
) as StatusResponse<IPageSpeedPayload>;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
statusResponse = this.buildStatusResponse(monitor, null, null, 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 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,
|
pagespeedUrl,
|
||||||
{
|
{
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { ICheck } from "@/db/models/index.js";
|
|
||||||
import { StatusResponse } from "./NetworkService.js";
|
import { StatusResponse } from "./NetworkService.js";
|
||||||
import {
|
import {
|
||||||
IMonitorRepository,
|
IMonitorRepository,
|
||||||
|
|||||||
Reference in new issue
Block a user