purge string service

This commit is contained in:
Alex Holliday committed 2026-01-20 23:06:23 +00:00
1 parent cc9850c975
commit 4957209307
16 files changed
+41 -1048

No files matched your search

@@ -20,26 +20,23 @@ class IncidentService {
private db: any;
private logger: any;
private errorService: any;
private stringService: any;
private: any;
private incidentsRepository: IIncidentsRepository;
constructor({
db,
logger,
errorService,
stringService,
incidentsRepository,
}: {
db: any;
logger: any;
errorService: any;
stringService: any;
incidentsRepository: IIncidentsRepository;
}) {
this.db = db;
this.logger = logger;
this.errorService = errorService;
this.stringService = stringService;
this.incidentsRepository = incidentsRepository;
}
@@ -5,27 +5,11 @@ const SERVICE_NAME = "maintenanceWindowService";
class MaintenanceWindowService {
static SERVICE_NAME = SERVICE_NAME;
private db: any;
private settingsService: any;
private stringService: any;
private errorService: any;
private monitorsRepository: IMonitorsRepository;
constructor({
db,
settingsService,
stringService,
errorService,
monitorsRepository,
}: {
db: any;
settingsService: any;
stringService: any;
errorService: any;
monitorsRepository: IMonitorsRepository;
}) {
constructor({ db, errorService, monitorsRepository }: { db: any; errorService: any; monitorsRepository: IMonitorsRepository }) {
this.db = db;
this.settingsService = settingsService;
this.stringService = stringService;
this.errorService = errorService;
this.monitorsRepository = monitorsRepository;
}
@@ -65,9 +65,7 @@ export interface IMonitorService {
export class MonitorService implements IMonitorService {
static SERVICE_NAME = SERVICE_NAME;
private db: any;
private jobQueue: any;
private stringService: any;
private emailService: any;
private papaparse: any;
private logger: any;
@@ -80,7 +78,6 @@ export class MonitorService implements IMonitorService {
constructor({
jobQueue,
stringService,
emailService,
papaparse,
logger,
@@ -92,7 +89,6 @@ export class MonitorService implements IMonitorService {
statusPagesRepository,
}: {
jobQueue: any;
stringService: any;
emailService: any;
papaparse: any;
logger: any;
@@ -104,7 +100,6 @@ export class MonitorService implements IMonitorService {
statusPagesRepository: IStatusPagesRepository;
}) {
this.jobQueue = jobQueue;
this.stringService = stringService;
this.emailService = emailService;
this.papaparse = papaparse;
this.logger = logger;
@@ -465,7 +460,7 @@ export class MonitorService implements IMonitorService {
};
sendTestEmail = async ({ to }: { to: string }): Promise<string> => {
const subject = this.stringService.testEmailSubject;
const subject = "Test email from Checkmate";
const context = { testName: "Monitoring System" };
const html = await this.emailService.buildEmail("testEmailTemplate", context);
+10 -16
View File
@@ -3,6 +3,7 @@ import Team from "@/db/models/Team.js";
import type { User } from "@/types/index.js";
import bcrypt from "bcryptjs";
import { AppError } from "@/utils/AppError.js";
import { ISuperSimpleQueue } from "../infrastructure/SuperSimpleQueue/SuperSimpleQueue.js";
const SERVICE_NAME = "userService";
@@ -12,10 +13,8 @@ class UserService {
private emailService: any;
private settingsService: any;
private logger: any;
private stringService: any;
private jwt: any;
private errorService: any;
private jobQueue: any;
private jobQueue: ISuperSimpleQueue;
private crypto: any;
private monitorsRepository: IMonitorsRepository;
private usersRepository: IUsersRepository;
@@ -28,9 +27,7 @@ class UserService {
emailService,
settingsService,
logger,
stringService,
jwt,
errorService,
jobQueue,
monitorsRepository,
usersRepository,
@@ -42,10 +39,9 @@ class UserService {
emailService: any;
settingsService: any;
logger: any;
stringService: any;
jwt: any;
errorService: any;
jobQueue: any;
jobQueue: ISuperSimpleQueue;
monitorsRepository: IMonitorsRepository;
usersRepository: IUsersRepository;
invitesRepository: IInvitesRepository;
@@ -55,9 +51,7 @@ class UserService {
this.emailService = emailService;
this.settingsService = settingsService;
this.logger = logger;
this.stringService = stringService;
this.jwt = jwt;
this.errorService = errorService;
this.jobQueue = jobQueue;
this.crypto = crypto;
this.monitorsRepository = monitorsRepository;
@@ -144,7 +138,7 @@ class UserService {
const match = await bcrypt.compare(password, user.password);
if (match !== true) {
throw this.errorService.createAuthenticationError(this.stringService.authIncorrectPassword);
throw new AppError({ message: "Incorrect password", service: SERVICE_NAME, status: 401 });
}
// Remove password from user object. Should this be abstracted to DB layer?
@@ -173,7 +167,7 @@ class UserService {
// If not a match, throw a 403
// 403 instead of 401 to avoid triggering axios interceptor
if (!match) {
throw this.errorService.createAuthorizationError(this.stringService.authIncorrectPassword);
throw new AppError({ message: "Incorrect current password", service: SERVICE_NAME, status: 403 });
}
// If a match, update the password
updates.password = updates.newPassword;
@@ -234,23 +228,23 @@ class UserService {
deleteUser = async (user: User) => {
const email = user?.email;
if (!email) {
throw this.errorService.createBadRequestError("No email in request");
throw new AppError({ message: "No email in request", service: SERVICE_NAME, method: "deleteUser", status: 400 });
}
const teamId = user?.teamId;
const userId = user?.id;
if (!teamId) {
throw this.errorService.createBadRequestError("No team ID in request");
throw new AppError({ message: "No team ID in request", service: SERVICE_NAME, method: "deleteUser", status: 400 });
}
if (!userId) {
throw this.errorService.createBadRequestError("No user ID in request");
throw new AppError({ message: "No user ID in request", service: SERVICE_NAME, method: "deleteUser", status: 400 });
}
const roles = user?.role;
if (roles.includes("demo")) {
throw this.errorService.createBadRequestError("Demo user cannot be deleted");
throw new AppError({ message: "Demo user cannot be deleted", service: SERVICE_NAME, method: "deleteUser", status: 400 });
}
// 1. Find all the monitors associated with the team ID if superadmin
@@ -262,7 +256,7 @@ class UserService {
res?.length > 0 &&
(await Promise.all(
res.map(async (monitor) => {
await this.jobQueue.deleteJob(monitor);
await this.jobQueue.deleteJob(monitor.id);
})
));
}
@@ -53,10 +53,8 @@ class NetworkService implements INetworkService {
private GameDig: any;
private ping: any;
private logger: any;
private http: any;
private Docker: any;
private net: any;
private stringService: any;
private settingsService: any;
private buildStatusResponse = <T>({
@@ -124,7 +122,6 @@ class NetworkService implements INetworkService {
http,
Docker,
net,
stringService,
settingsService,
}: {
axios: any;
@@ -137,7 +134,6 @@ class NetworkService implements INetworkService {
http: any;
Docker: any;
net: any;
stringService: any;
settingsService: any;
}) {
this.TYPE_PING = "ping";
@@ -152,14 +148,12 @@ class NetworkService implements INetworkService {
this.PING_ERROR = 5001;
this.axios = axios;
this.https = https;
this.http = http;
this.jmespath = jmespath;
this.GameDig = GameDig;
this.ping = ping;
this.logger = logger;
this.Docker = Docker;
this.net = net;
this.stringService = stringService;
this.settingsService = settingsService;
const cacheable = new CacheableLookup();
@@ -326,7 +320,7 @@ class NetworkService implements INetworkService {
} else {
httpResponse.code = 500;
httpResponse.status = false;
httpResponse.message = this.stringService.httpExpectedValueFail;
httpResponse.message = "Expected value did not match";
return httpResponse;
}
}
@@ -336,7 +330,7 @@ class NetworkService implements INetworkService {
const isJson = contentType?.includes("application/json");
if (!isJson) {
httpResponse.status = false;
httpResponse.message = this.stringService.httpNotJson;
httpResponse.message = "Response is not JSON";
return httpResponse;
}
try {
@@ -353,7 +347,7 @@ class NetworkService implements INetworkService {
} else {
httpResponse.status = false;
httpResponse.code = 500;
httpResponse.message = this.stringService.httpJsonPathFail;
httpResponse.message = "Expected value did not match";
httpResponse.extracted = extracted;
return httpResponse;
}
@@ -365,14 +359,14 @@ class NetworkService implements INetworkService {
} else {
httpResponse.status = false;
httpResponse.code = 500;
httpResponse.message = this.stringService.httpJsonPathFail;
httpResponse.message = "Expected value did not match";
httpResponse.extracted = extracted;
return httpResponse;
}
}
} catch {
httpResponse.status = false;
httpResponse.message = this.stringService.httpJsonPathError;
httpResponse.message = "Error evaluating JSON path";
return httpResponse;
}
}
@@ -486,7 +480,7 @@ class NetworkService implements INetworkService {
dockerResponse.code = 404;
dockerResponse.status = false;
dockerResponse.message = this.stringService.dockerNotFound;
dockerResponse.message = "Docker container not found";
return dockerResponse;
}
@@ -568,7 +562,7 @@ class NetworkService implements INetworkService {
overrides: {
code: 200,
status: (response as { success?: boolean })?.success ?? false,
message: this.stringService.portSuccess,
message: "Port check successful",
responseTime,
},
});
@@ -576,7 +570,7 @@ class NetworkService implements INetworkService {
if (error) {
portResponse.code = this.NETWORK_ERROR;
portResponse.status = false;
portResponse.message = this.stringService.portFail;
portResponse.message = "Port check failed";
return portResponse;
}
-452
View File
@@ -1,452 +0,0 @@
const SERVICE_NAME = "StringService";
class StringService {
static SERVICE_NAME = SERVICE_NAME;
constructor(translationService) {
if (StringService.instance) {
return StringService.instance;
}
this.translationService = translationService;
this._language = "en"; // default language
StringService.instance = this;
}
get serviceName() {
return StringService.SERVICE_NAME;
}
setLanguage(language) {
this._language = language;
}
get language() {
return this._language;
}
// Auth Messages
get dontHaveAccount() {
return this.translationService.getTranslation("dontHaveAccount");
}
get email() {
return this.translationService.getTranslation("email");
}
get forgotPassword() {
return this.translationService.getTranslation("forgotPassword");
}
get password() {
return this.translationService.getTranslation("password");
}
get signUp() {
return this.translationService.getTranslation("signUp");
}
get submit() {
return this.translationService.getTranslation("submit");
}
get title() {
return this.translationService.getTranslation("title");
}
get continue() {
return this.translationService.getTranslation("continue");
}
get enterEmail() {
return this.translationService.getTranslation("enterEmail");
}
get authLoginTitle() {
return this.translationService.getTranslation("authLoginTitle");
}
get authLoginEnterPassword() {
return this.translationService.getTranslation("authLoginEnterPassword");
}
get commonPassword() {
return this.translationService.getTranslation("commonPassword");
}
get commonBack() {
return this.translationService.getTranslation("commonBack");
}
get authForgotPasswordTitle() {
return this.translationService.getTranslation("authForgotPasswordTitle");
}
get authForgotPasswordResetPassword() {
return this.translationService.getTranslation("authForgotPasswordResetPassword");
}
get createPassword() {
return this.translationService.getTranslation("createPassword");
}
get createAPassword() {
return this.translationService.getTranslation("createAPassword");
}
get authRegisterAlreadyHaveAccount() {
return this.translationService.getTranslation("authRegisterAlreadyHaveAccount");
}
get commonAppName() {
return this.translationService.getTranslation("commonAppName");
}
get authLoginEnterEmail() {
return this.translationService.getTranslation("authLoginEnterEmail");
}
get authRegisterTitle() {
return this.translationService.getTranslation("authRegisterTitle");
}
get monitorGetAll() {
return this.translationService.getTranslation("monitorGetAll");
}
get monitorGetById() {
return this.translationService.getTranslation("monitorGetById");
}
get monitorGetByIdSuccess() {
return this.translationService.getTranslation("monitorGetByIdSuccess");
}
get monitorCreate() {
return this.translationService.getTranslation("monitorCreate");
}
get bulkMonitorsCreate() {
return this.translationService.getTranslation("bulkMonitorsCreate");
}
get monitorEdit() {
return this.translationService.getTranslation("monitorEdit");
}
get monitorDelete() {
return this.translationService.getTranslation("monitorDelete");
}
get monitorPause() {
return this.translationService.getTranslation("monitorPause");
}
get monitorResume() {
return this.translationService.getTranslation("monitorResume");
}
get monitorDemoAdded() {
return this.translationService.getTranslation("monitorDemoAdded");
}
get monitorStatsById() {
return this.translationService.getTranslation("monitorStatsById");
}
get monitorCertificate() {
return this.translationService.getTranslation("monitorCertificate");
}
// Maintenance Window Messages
get maintenanceWindowCreate() {
return this.translationService.getTranslation("maintenanceWindowCreate");
}
get maintenanceWindowGetById() {
return this.translationService.getTranslation("maintenanceWindowGetById");
}
get maintenanceWindowGetByTeam() {
return this.translationService.getTranslation("maintenanceWindowGetByTeam");
}
get maintenanceWindowDelete() {
return this.translationService.getTranslation("maintenanceWindowDelete");
}
get maintenanceWindowEdit() {
return this.translationService.getTranslation("maintenanceWindowEdit");
}
// Webhook Messages
get webhookUnsupportedPlatform() {
return this.translationService.getTranslation("webhookUnsupportedPlatform");
}
get webhookSendError() {
return this.translationService.getTranslation("webhookSendError");
}
get webhookSendSuccess() {
return this.translationService.getTranslation("webhookSendSuccess");
}
get telegramRequiresBotTokenAndChatId() {
return this.translationService.getTranslation("telegramRequiresBotTokenAndChatId");
}
get webhookUrlRequired() {
return this.translationService.getTranslation("webhookUrlRequired");
}
get platformRequired() {
return this.translationService.getTranslation("platformRequired");
}
get testNotificationFailed() {
return this.translationService.getTranslation("testNotificationFailed");
}
get monitorUpAlert() {
return this.translationService.getTranslation("monitorUpAlert");
}
get monitorDownAlert() {
return this.translationService.getTranslation("monitorDownAlert");
}
get discordNotification() {
return this.translationService.getTranslation("discordNotification");
}
getWebhookUnsupportedPlatform(platform) {
return this.translationService.getTranslation("webhookUnsupportedPlatform").replace("{platform}", platform);
}
getWebhookSendError(platform) {
return this.translationService.getTranslation("webhookSendError").replace("{platform}", platform);
}
getMonitorStatus(name, status, url) {
const translationKey = status === true ? "monitorStatusUp" : "monitorStatusDown";
return this.translationService.getTranslation(translationKey).replace("{name}", name).replace("{url}", url);
}
// Error Messages
get unknownError() {
return this.translationService.getTranslation("unknownError");
}
get friendlyError() {
return this.translationService.getTranslation("friendlyError");
}
get authIncorrectPassword() {
return this.translationService.getTranslation("authIncorrectPassword");
}
get unauthorized() {
return this.translationService.getTranslation("unauthorized");
}
get authAdminExists() {
return this.translationService.getTranslation("authAdminExists");
}
get authInviteNotFound() {
return this.translationService.getTranslation("authInviteNotFound");
}
get unknownService() {
return this.translationService.getTranslation("unknownService");
}
get noAuthToken() {
return this.translationService.getTranslation("noAuthToken");
}
get invalidAuthToken() {
return this.translationService.getTranslation("invalidAuthToken");
}
get expiredAuthToken() {
return this.translationService.getTranslation("expiredAuthToken");
}
// Queue Messages
get queueGetMetrics() {
return this.translationService.getTranslation("queueGetMetrics");
}
get queueGetJobs() {
return this.translationService.getTranslation("queueGetJobs");
}
get queueAddJob() {
return this.translationService.getTranslation("queueAddJob");
}
get queueObliterate() {
return this.translationService.getTranslation("queueObliterate");
}
// Job Queue Messages
get jobQueueDeleteJobSuccess() {
return this.translationService.getTranslation("jobQueueDeleteJobSuccess");
}
get jobQueuePauseJob() {
return this.translationService.getTranslation("jobQueuePauseJob");
}
get jobQueueResumeJob() {
return this.translationService.getTranslation("jobQueueResumeJob");
}
// Status Page Messages
get statusPageByUrl() {
return this.translationService.getTranslation("statusPageByUrl");
}
get statusPageCreate() {
return this.translationService.getTranslation("statusPageCreate");
}
get statusPageDelete() {
return this.translationService.getTranslation("statusPageDelete");
}
get statusPageUpdate() {
return this.translationService.getTranslation("statusPageUpdate");
}
get statusPageNotFound() {
return this.translationService.getTranslation("statusPageNotFound");
}
get statusPageByTeamId() {
return this.translationService.getTranslation("statusPageByTeamId");
}
get statusPageUrlNotUnique() {
return this.translationService.getTranslation("statusPageUrlNotUnique");
}
// Docker Messages
get dockerFail() {
return this.translationService.getTranslation("dockerFail");
}
get dockerNotFound() {
return this.translationService.getTranslation("dockerNotFound");
}
get dockerSuccess() {
return this.translationService.getTranslation("dockerSuccess");
}
// Port Messages
get portFail() {
return this.translationService.getTranslation("portFail");
}
get portSuccess() {
return this.translationService.getTranslation("portSuccess");
}
// Alert Messages
get alertCreate() {
return this.translationService.getTranslation("alertCreate");
}
get alertGetByUser() {
return this.translationService.getTranslation("alertGetByUser");
}
get alertGetByMonitor() {
return this.translationService.getTranslation("alertGetByMonitor");
}
get alertGetById() {
return this.translationService.getTranslation("alertGetById");
}
get alertEdit() {
return this.translationService.getTranslation("alertEdit");
}
get alertDelete() {
return this.translationService.getTranslation("alertDelete");
}
getDeletedCount(count) {
return this.translationService.getTranslation("deletedCount").replace("{count}", count);
}
get pingSuccess() {
return this.translationService.getTranslation("pingSuccess");
}
get getAppSettings() {
return this.translationService.getTranslation("getAppSettings");
}
get httpNetworkError() {
return this.translationService.getTranslation("httpNetworkError");
}
get httpNotJson() {
return this.translationService.getTranslation("httpNotJson");
}
get httpJsonPathError() {
return this.translationService.getTranslation("httpJsonPathError");
}
get httpEmptyResult() {
return this.translationService.getTranslation("httpEmptyResult");
}
get httpMatchSuccess() {
return this.translationService.getTranslation("httpMatchSuccess");
}
get httpMatchFail() {
return this.translationService.getTranslation("httpMatchFail");
}
get updateAppSettings() {
return this.translationService.getTranslation("updateAppSettings");
}
get insufficientPermissions() {
return this.translationService.getTranslation("insufficientPermissions");
}
getDbFindMonitorById(monitorId) {
return this.translationService.getTranslation("dbFindMonitorById").replace("${monitorId}", monitorId);
}
get dbUserExists() {
return this.translationService.getTranslation("dbUserExists");
}
get testEmailSubject() {
return this.translationService.getTranslation("testEmailSubject");
}
get verifyOwnerNotFound() {
return this.translationService.getTranslation("verifyOwnerNotFound");
}
get verifyOwnerUnauthorized() {
return this.translationService.getTranslation("verifyOwnerUnauthorized");
}
get dbUserNotFound() {
return this.translationService.getTranslation("dbUserNotFound");
}
}
export default StringService;