ts errors
This commit is contained in:
1 parent
81d6c4651f
commit
605b4713af
6 files changed
+39
-154
No files matched your search
@@ -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