Skip to content

A modern, self-hosted backup solution for secure, encrypted backups across local and cloud storage.

chore: make NotificationChannelResolver overridable for pro.

towfiqie0c245df9506
diff --git a/backend/src/notifications/BackupNotification.ts b/backend/src/notifications/BackupNotification.ts
index 5c9004e..f635761 100644
--- a/backend/src/notifications/BackupNotification.ts
+++ b/backend/src/notifications/BackupNotification.ts
@@ -1,5 +1,6 @@
import { BackupCompletionStats, BackupTaskStats } from '../types/backups';
import { PlanFull } from '../types/plans';
+import { INotificationChannelResolver } from '../types/notifications';
import { BackupStartedNotification } from './templates/email/backup/BackupStartedNotification';
import { BackupSuccessNotification } from './templates/email/backup/BackupSuccessNotification';
import { BackupFailedNotification } from './templates/email/backup/BackupFailedNotification';
@@ -21,6 +22,7 @@ export class BackupNotification {
protected BackupStartedNotificationClass = BackupStartedNotification;
protected BackupSuccessNotificationClass = BackupSuccessNotification;
protected BackupFailedNotificationClass = BackupFailedNotification;
+ protected notificationChannelResolver: INotificationChannelResolver = NotificationChannelResolver;
shouldSend(notificationCase: string, notificationType: string) {
return (
@@ -51,7 +53,7 @@ export class BackupNotification {
const emailType = notification?.email?.type || 'smtp';
if (!notification?.email?.emails) throw new Error('Email Notification Emails Missing.');
- const emailChannel = await NotificationChannelResolver.getChannel(emailType);
+ const emailChannel = await this.notificationChannelResolver.getChannel(emailType);
const notificationClass = await this.getNotificationClass(
plan,
notificationType,
diff --git a/backend/src/notifications/channels/NotificationChannelResolver.ts b/backend/src/notifications/channels/NotificationChannelResolver.ts
index 3972d26..4207316 100644
--- a/backend/src/notifications/channels/NotificationChannelResolver.ts
+++ b/backend/src/notifications/channels/NotificationChannelResolver.ts
@@ -5,11 +5,12 @@ import { getNestedValue, setNestedValue } from '../../utils/helpers';
import { db } from '../../db/index';
import { SettingsStore } from '../../stores/SettingsStore';
import { configService } from '../../services/ConfigService';
+import { NotificationChannel } from '../NotificationChannel';
export class NotificationChannelResolver {
static secretFields: string[] = ['smtp.password'];
- static async getChannel(channelType: IntegrationTypes = 'smtp') {
+ static async getChannel(channelType: IntegrationTypes = 'smtp'): Promise<NotificationChannel> {
const settingsStore = new SettingsStore(db);
const settingsData = await settingsStore.getFirst();
const integration = settingsData?.settings?.integration;
diff --git a/backend/src/services/SettingsService.ts b/backend/src/services/SettingsService.ts
index f9ae2ef..ecea4d8 100644
--- a/backend/src/services/SettingsService.ts
+++ b/backend/src/services/SettingsService.ts
@@ -4,6 +4,7 @@ import { Settings, settingsUpdateSchema } from '../db/schema/settings';
import { TestEmailNotification } from '../notifications/templates/email/test-email/TestEmailNotification';
import { SettingsStore } from '../stores/SettingsStore';
import { AppSettings, IntegrationTypes } from '../types/settings';
+import { INotificationChannelResolver } from '../types/notifications';
import { NotificationChannelResolver } from '../notifications/channels/NotificationChannelResolver';
import { appPaths } from '../utils/AppPaths';
import { AppError, NotFoundError } from '../utils/AppError';
@@ -12,6 +13,7 @@ import { AppError, NotFoundError } from '../utils/AppError';
* A class for managing settings operations.
*/
export class SettingsService {
+ protected notificationChannelResolver: INotificationChannelResolver = NotificationChannelResolver;
constructor(protected settingsStore: SettingsStore) {}
async getMainSettings(): Promise<Settings | null> {
@@ -63,7 +65,7 @@ export class SettingsService {
const appSettings = settings;
const integrationType = type;
- appSettings.integration = NotificationChannelResolver.encryptSecrets(
+ appSettings.integration = this.notificationChannelResolver.encryptSecrets(
appSettings.integration as AppSettings['integration']
);
try {
@@ -77,16 +79,12 @@ export class SettingsService {
// Send the test email
const notificationClass = new TestEmailNotification({ integrationType, appTitle });
- const senderChannel = await NotificationChannelResolver.getChannel(integrationType);
+ const senderChannel = await this.notificationChannelResolver.getChannel(integrationType);
const sendRes = await senderChannel.send(notificationClass, {
emails: test.email,
});
-
- console.log('sendRes :', sendRes);
- console.log(
- 'appSettings?.integration?.[integrationType] :',
- theAppSettings?.integration?.[integrationType]
- );
+ // console.log('senderChannel :', senderChannel);
+ // console.log('sendRes :', integrationType, sendRes);
// Set the integration status to connected
if (sendRes.success) {
diff --git a/backend/src/stores/SettingsStore.ts b/backend/src/stores/SettingsStore.ts
index 94596a7..e274976 100644
--- a/backend/src/stores/SettingsStore.ts
+++ b/backend/src/stores/SettingsStore.ts
@@ -4,12 +4,15 @@ import { DatabaseType } from '../db';
import { Settings, NewSettings, settings } from '../db/schema/settings';
import { AppSettings, INTEGRATIONS_AVAILABLE, IntegrationTypes } from '../types/settings';
import { NotificationChannelResolver } from '../notifications/channels/NotificationChannelResolver';
+import { INotificationChannelResolver } from '../types/notifications';
/**
* SettingsStore is a class for managing application settings records in the database.
*/
export class SettingsStore {
- constructor(private db: DatabaseType) {}
+ protected resolver: INotificationChannelResolver = NotificationChannelResolver;
+
+ constructor(protected db: DatabaseType) {}
async getFirst(): Promise<Settings | null> {
const appSettings = await this.db.query.settings.findFirst();
@@ -70,7 +73,7 @@ export class SettingsStore {
// Decrypt Secret Fields
if (theSettings?.integration) {
try {
- theSettings.integration = NotificationChannelResolver.decryptSecrets(
+ theSettings.integration = this.resolver.decryptSecrets(
theSettings.integration
);
return theSettings;
@@ -83,15 +86,15 @@ export class SettingsStore {
async encryptIntegrationSecrets(appSettings: AppSettings) {
const theSettings = { ...appSettings };
- // Decrypt Secret Fields
+ // Encrypt Secret Fields
if (theSettings?.integration) {
try {
- theSettings.integration = NotificationChannelResolver.encryptSecrets(
+ theSettings.integration = this.resolver.encryptSecrets(
theSettings.integration
);
return theSettings;
} catch (error: any) {
- console.log('Error decrypting password:', error);
+ console.log('Error encrypting password:', error);
false;
}
}
diff --git a/backend/src/types/notifications.ts b/backend/src/types/notifications.ts
index 57bcdc0..9b60368 100644
--- a/backend/src/types/notifications.ts
+++ b/backend/src/types/notifications.ts
@@ -1,4 +1,16 @@
import { BackupTaskStats } from './backups';
+import { NotificationChannel } from '../notifications/NotificationChannel';
+import { AppSettings, IntegrationTypes } from './settings';
+
+/**
+ * Interface for NotificationChannelResolver to allow extension in pro
+ */
+export interface INotificationChannelResolver {
+ secretFields: string[];
+ getChannel(channelType?: IntegrationTypes): Promise<NotificationChannel>;
+ encryptSecrets(integration: AppSettings['integration']): AppSettings['integration'];
+ decryptSecrets(integration: AppSettings['integration']): AppSettings['integration'];
+}
export interface BackupNotificationData {
planId: string;