@plutonhq/core-backend 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plutonhq/core-backend",
3
3
  "description": "Pluton Core Backend Library",
4
- "version": "0.1.7",
4
+ "version": "0.1.8",
5
5
  "author": "plutonhq",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {
@@ -1,110 +0,0 @@
1
- import ejs from 'ejs';
2
- import { configService } from '../../../../services/ConfigService';
3
- import { Plan } from '../../../../db/schema/plans';
4
- import { providers } from '../../../../utils/providers';
5
- import { BackupNotificationJSONPayload, BackupTaskStats } from '../../../../types/backups';
6
- import { formatBytes, formatDuration, formatNumberToK } from '../../../../utils/formatter';
7
- import { BaseNotification } from '../../../BaseNotification';
8
- import { loadBackupTemplate } from '../../../templateLoader';
9
-
10
- export interface BackupFailedNotificationPayload {
11
- appTitle: string;
12
- deviceName: string;
13
- storageName: string;
14
- storageType: string;
15
- plan: Plan;
16
- startTime: Date;
17
- endTime: Date;
18
- error: string;
19
- stats?: BackupTaskStats;
20
- output?: 'html' | 'json' | 'push';
21
- }
22
-
23
- export class BackupFailedNotification extends BaseNotification {
24
- constructor(data: BackupFailedNotificationPayload) {
25
- super();
26
- this.subject = `Backup Failed: ${data.plan.title}`;
27
- this.contentType = data.output || 'html';
28
- this.content = this.buildContent(data);
29
- }
30
-
31
- protected buildContent(data: BackupFailedNotificationPayload): string {
32
- if (this.contentType === 'json') {
33
- return this.buildJSONContent(data);
34
- }
35
- return this.buildHTMLContent(data);
36
- }
37
-
38
- protected buildJSONContent(data: BackupFailedNotificationPayload): string {
39
- const {
40
- appTitle,
41
- deviceName,
42
- storageName,
43
- storageType,
44
- plan,
45
- stats,
46
- startTime,
47
- endTime,
48
- error,
49
- } = data;
50
- const payload: BackupNotificationJSONPayload = {
51
- appTitle,
52
- deviceName,
53
- storageName,
54
- storageType,
55
- storagePath: plan.storagePath || '',
56
- stats,
57
- startTime,
58
- endTime,
59
- error,
60
- planID: plan.id,
61
- planTitle: plan.title,
62
- planType: plan.method,
63
- planSource: {
64
- included: plan.sourceConfig?.includes.join(', ') || '',
65
- excluded: plan.sourceConfig?.excludes.join(', ') || '',
66
- },
67
- eventName: 'backup_failed',
68
- };
69
- return JSON.stringify(payload);
70
- }
71
-
72
- protected buildHTMLContent(data: BackupFailedNotificationPayload): string {
73
- // Generate the Email Body
74
- const startDate = new Date(data.startTime ? data.startTime : 0).toLocaleDateString('en-US', {
75
- year: 'numeric',
76
- month: 'long',
77
- day: 'numeric',
78
- hour: 'numeric',
79
- minute: 'numeric',
80
- });
81
- const endDate = new Date(data.endTime ? data.endTime : 0).toLocaleDateString('en-US', {
82
- year: 'numeric',
83
- month: 'long',
84
- day: 'numeric',
85
- hour: 'numeric',
86
- minute: 'numeric',
87
- });
88
- const storageTypeName = data.storageType
89
- ? providers[data.storageType]?.name || data.storageType
90
- : '';
91
-
92
- const templateString = loadBackupTemplate('BackupFailedNotification.ejs');
93
- const renderedBody = ejs.render(templateString, {
94
- ...data,
95
- appUrl: configService.config.APP_URL,
96
- storageTypeName,
97
- startDate,
98
- endDate,
99
- formatBytes,
100
- formatDuration,
101
- formatNumberToK,
102
- });
103
-
104
- return this.applyEmailTemplate(renderedBody, {
105
- appTitle: configService.config.APP_TITLE || 'Pluton',
106
- preHeader: `Backup Failed: ${data.plan.title}`,
107
- className: 'content--error',
108
- });
109
- }
110
- }
@@ -1,87 +0,0 @@
1
- import ejs from 'ejs';
2
- import { configService } from '../../../../services/ConfigService';
3
- import { Plan } from '../../../../db/schema/plans';
4
- import { providers } from '../../../../utils/providers';
5
- import { BackupNotificationJSONPayload, BackupTaskStats } from '../../../../types/backups';
6
- import { formatBytes, formatNumberToK } from '../../../../utils/formatter';
7
- import { BaseNotification } from '../../../BaseNotification';
8
- import { loadBackupTemplate } from '../../../templateLoader';
9
-
10
- export interface BackupStartedPayload {
11
- appTitle: string;
12
- deviceName: string;
13
- storageName: string;
14
- storageType: string;
15
- plan: Plan;
16
- startTime: Date;
17
- stats?: BackupTaskStats;
18
- output?: string;
19
- }
20
-
21
- export class BackupStartedNotification extends BaseNotification {
22
- constructor(data: BackupStartedPayload) {
23
- super();
24
- this.subject = `Backup Started: ${data.plan.title}`;
25
- this.contentType = data.output || 'html';
26
- this.content = this.buildContent(data);
27
- }
28
-
29
- buildContent(data: BackupStartedPayload): string {
30
- if (this.contentType === 'json') {
31
- return this.buildJSONContent(data);
32
- }
33
- return this.buildHTMLContent(data);
34
- }
35
-
36
- protected buildJSONContent(data: BackupStartedPayload): string {
37
- const { appTitle, deviceName, storageName, storageType, plan, stats, startTime } = data;
38
- const payload: BackupNotificationJSONPayload = {
39
- appTitle,
40
- deviceName,
41
- storageName,
42
- storageType,
43
- storagePath: plan.storagePath || '',
44
- stats,
45
- startTime,
46
- planID: plan.id,
47
- planTitle: plan.title,
48
- planType: plan.method,
49
- planSource: {
50
- included: plan.sourceConfig?.includes.join(', ') || '',
51
- excluded: plan.sourceConfig?.excludes.join(', ') || '',
52
- },
53
- eventName: 'backup_started',
54
- };
55
- return JSON.stringify(payload);
56
- }
57
-
58
- protected buildHTMLContent(data: BackupStartedPayload): string {
59
- // Generate the Email Body
60
- const startDate = new Date(data.startTime ? data.startTime : 0).toLocaleDateString('en-US', {
61
- year: 'numeric',
62
- month: 'long',
63
- day: 'numeric',
64
- hour: 'numeric',
65
- minute: 'numeric',
66
- });
67
-
68
- const storageTypeName = data.storageType
69
- ? providers[data.storageType]?.name || data.storageType
70
- : '';
71
-
72
- const templateString = loadBackupTemplate('BackupStartedNotification.ejs');
73
- const renderedBody = ejs.render(templateString, {
74
- ...data,
75
- appUrl: configService.config.APP_URL,
76
- storageTypeName,
77
- startDate,
78
- formatBytes,
79
- formatNumberToK,
80
- });
81
-
82
- return this.applyEmailTemplate(renderedBody, {
83
- appTitle: configService.config.APP_TITLE || 'Pluton',
84
- preHeader: `Backup Started: ${data.plan.title}`,
85
- });
86
- }
87
- }
@@ -1,97 +0,0 @@
1
- import ejs from 'ejs';
2
- import { configService } from '../../../../services/ConfigService';
3
- import { Plan } from '../../../../db/schema/plans';
4
- import { providers } from '../../../../utils/providers';
5
- import { BackupCompletionStats, BackupNotificationJSONPayload } from '../../../../types/backups';
6
- import { formatBytes, formatDuration, formatNumberToK } from '../../../../utils/formatter';
7
- import { BaseNotification } from '../../../BaseNotification';
8
- import { loadBackupTemplate } from '../../../templateLoader';
9
-
10
- export interface BackupSuccessNotificationPayload {
11
- appTitle: string;
12
- deviceName: string;
13
- storageName: string;
14
- storageType: string;
15
- plan: Plan;
16
- startTime: Date;
17
- endTime: Date;
18
- stats?: BackupCompletionStats;
19
- output?: 'html' | 'json' | 'push';
20
- }
21
-
22
- export class BackupSuccessNotification extends BaseNotification {
23
- constructor(data: BackupSuccessNotificationPayload) {
24
- super();
25
- this.subject = `Backup Complete: ${data.plan.title}`;
26
- this.contentType = data.output || 'html';
27
- this.content = this.buildContent(data);
28
- }
29
-
30
- protected buildContent(data: BackupSuccessNotificationPayload): string {
31
- if (this.contentType === 'json') {
32
- return this.buildJSONContent(data);
33
- }
34
- return this.buildHTMLContent(data);
35
- }
36
-
37
- protected buildJSONContent(data: BackupSuccessNotificationPayload): string {
38
- const { appTitle, deviceName, storageName, storageType, plan, stats, startTime, endTime } =
39
- data;
40
- const payload: BackupNotificationJSONPayload = {
41
- appTitle,
42
- deviceName,
43
- storageName,
44
- storageType,
45
- storagePath: plan.storagePath || '',
46
- stats,
47
- startTime,
48
- endTime,
49
- planID: plan.id,
50
- planTitle: plan.title,
51
- planType: plan.method,
52
- planSource: {
53
- included: plan.sourceConfig?.includes.join(', ') || '',
54
- excluded: plan.sourceConfig?.excludes.join(', ') || '',
55
- },
56
- eventName: 'backup_success',
57
- };
58
- return JSON.stringify(payload);
59
- }
60
-
61
- protected buildHTMLContent(data: BackupSuccessNotificationPayload): string {
62
- // Generate the Email Body
63
- const startDate = new Date(data.startTime ? data.startTime : 0).toLocaleDateString('en-US', {
64
- year: 'numeric',
65
- month: 'long',
66
- day: 'numeric',
67
- hour: 'numeric',
68
- minute: 'numeric',
69
- });
70
- const endDate = new Date(data.endTime ? data.endTime : 0).toLocaleDateString('en-US', {
71
- year: 'numeric',
72
- month: 'long',
73
- day: 'numeric',
74
- hour: 'numeric',
75
- minute: 'numeric',
76
- });
77
- const storageTypeName = data.storageType
78
- ? providers[data.storageType]?.name || data.storageType
79
- : '';
80
- const templateString = loadBackupTemplate('BackupSuccessNotification.ejs');
81
- const renderedBody = ejs.render(templateString, {
82
- ...data,
83
- appUrl: configService.config.APP_URL,
84
- storageTypeName,
85
- startDate,
86
- endDate,
87
- formatBytes,
88
- formatDuration,
89
- formatNumberToK,
90
- });
91
-
92
- return this.applyEmailTemplate(renderedBody, {
93
- appTitle: configService.config.APP_TITLE || 'Pluton',
94
- preHeader: `Backup Success: ${data.plan.title}`,
95
- });
96
- }
97
- }
@@ -1,27 +0,0 @@
1
- import { configService } from '../../../../services/ConfigService';
2
- import { INTEGRATIONS_AVAILABLE, IntegrationTypes } from '../../../../types/settings';
3
- import { BaseNotification } from '../../../BaseNotification';
4
-
5
- export class TestEmailNotification extends BaseNotification {
6
- integrationName = '';
7
- constructor(data: { integrationType: IntegrationTypes; appTitle: string }) {
8
- super();
9
- const integrationType = data.integrationType;
10
- this.integrationName = INTEGRATIONS_AVAILABLE[integrationType].name;
11
- this.subject = `${this.integrationName} Integration Successful`;
12
- this.content = this.buildContent(data);
13
- }
14
- protected buildContent(data: { integrationType: IntegrationTypes; appTitle: string }): string {
15
- // Generate the Email Body
16
- const content = `
17
- <div class="center">
18
- <h2>${this.integrationName} Integration Successful</h2>
19
- <p>${configService.config.APP_TITLE || 'Pluton'} can successfully send notifications using ${this.integrationName}</p>
20
- </div>
21
- `;
22
- return this.applyEmailTemplate(content, {
23
- appTitle: data.appTitle,
24
- preHeader: `${configService.config.APP_TITLE || 'Pluton'} can successfully send notifications using ${this.integrationName}`,
25
- });
26
- }
27
- }