Files
Checkmate/server/src/service/infrastructure/notificationProviders/INotificationProvider.ts
T

30 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-02-17 17:28:43 +00:00
import type { Notification } from "@/types/index.js";
2026-02-16 20:55:00 +00:00
import type { NotificationMessage } from "@/types/notificationMessage.js";
import { ILogger } from "@/utils/logger.js";
import type { OptionsOfJSONResponseBody } from "got";
2026-01-18 06:02:07 +00:00
export const DEFAULT_NOTIFICATION_TIMEOUT_MS = 30_000;
2026-01-18 16:59:38 +00:00
export interface INotificationProvider {
2026-02-17 17:28:43 +00:00
sendMessage: (notification: Notification, message: NotificationMessage) => Promise<boolean>;
2026-03-11 13:40:35 -07:00
sendTestAlert(notification: Partial<Notification>): Promise<boolean>;
2026-01-18 16:34:20 +00:00
}
export abstract class NotificationProvider implements INotificationProvider {
protected readonly logger: ILogger;
protected readonly timeoutMs: number;
constructor(logger: ILogger, timeoutMs: number = DEFAULT_NOTIFICATION_TIMEOUT_MS) {
this.logger = logger;
this.timeoutMs = timeoutMs;
}
protected gotRequestOptions(): Pick<OptionsOfJSONResponseBody, "timeout" | "retry"> {
return {
timeout: { request: this.timeoutMs },
retry: { limit: 0 },
};
}
abstract sendMessage(notification: Notification, message: NotificationMessage): Promise<boolean>;
abstract sendTestAlert(notification: Partial<Notification>): Promise<boolean>;
}