@oneuptime/common 7.0.4917 → 7.0.4972
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/Models/DatabaseModels/CallLog.ts +578 -0
- package/Models/DatabaseModels/EmailLog.ts +579 -0
- package/Models/DatabaseModels/IncidentStateTimeline.ts +1 -1
- package/Models/DatabaseModels/Index.ts +4 -0
- package/Models/DatabaseModels/PushNotificationLog.ts +877 -0
- package/Models/DatabaseModels/SmsLog.ts +578 -0
- package/Models/DatabaseModels/WorkspaceNotificationLog.ts +931 -0
- package/Server/API/StatusPageAPI.ts +2 -0
- package/Server/API/UserPushAPI.ts +12 -1
- package/Server/Infrastructure/Postgres/SchemaMigrations/1754776130988-MigrationName.ts +259 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1754828812691-MigrationName.ts +105 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1754910440587-MigrationName.ts +105 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1755030730926-MigrationName.ts +101 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1755088852971-MigrationName.ts +371 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1755093133870-MigrationName.ts +29 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1755109893911-MigrationName.ts +23 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1755110936888-MigrationName.ts +41 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +16 -0
- package/Server/Infrastructure/Queue.ts +28 -0
- package/Server/Services/CallService.ts +26 -1
- package/Server/Services/Index.ts +2 -0
- package/Server/Services/MailService.ts +60 -0
- package/Server/Services/OnCallDutyPolicyEscalationRuleUserService.ts +6 -0
- package/Server/Services/OnCallDutyPolicyScheduleService.ts +12 -0
- package/Server/Services/ProjectService.ts +3 -7
- package/Server/Services/PushNotificationLogService.ts +14 -0
- package/Server/Services/PushNotificationService.ts +129 -13
- package/Server/Services/ScheduledMaintenanceService.ts +4 -0
- package/Server/Services/SmsService.ts +25 -0
- package/Server/Services/StatusPagePrivateUserService.ts +1 -0
- package/Server/Services/StatusPageService.ts +1 -0
- package/Server/Services/StatusPageSubscriberService.ts +3 -0
- package/Server/Services/TeamMemberService.ts +1 -0
- package/Server/Services/UserCallService.ts +1 -0
- package/Server/Services/UserEmailService.ts +1 -0
- package/Server/Services/UserNotificationRuleService.ts +85 -6
- package/Server/Services/UserNotificationSettingService.ts +58 -0
- package/Server/Services/UserOnCallLogService.ts +1 -0
- package/Server/Services/UserSmsService.ts +1 -0
- package/Server/Services/WorkspaceNotificationLogService.ts +276 -0
- package/Server/Services/WorkspaceNotificationRuleService.ts +290 -33
- package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +21 -6
- package/Server/Utils/Workspace/Slack/Actions/Alert.ts +66 -0
- package/Server/Utils/Workspace/Slack/Actions/Incident.ts +66 -1
- package/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.ts +65 -0
- package/Server/Utils/Workspace/Slack/Slack.ts +21 -6
- package/Types/Permission.ts +20 -0
- package/Types/PushNotification/PushNotificationRequest.ts +4 -1
- package/Types/PushNotification/PushStatus.ts +6 -0
- package/Types/Workspace/WorkspaceNotificationActionType.ts +8 -0
- package/Types/Workspace/WorkspaceNotificationStatus.ts +6 -0
- package/Typings/elkjs.d.ts +30 -0
- package/UI/Components/Detail/Detail.tsx +1 -1
- package/UI/Components/Graphs/ServiceDependencyGraph.tsx +281 -0
- package/UI/Components/Tabs/Tab.tsx +8 -9
- package/UI/Components/Tabs/Tabs.tsx +17 -16
- package/Utils/Uptime/UptimeUtil.ts +20 -1
- package/build/dist/Models/DatabaseModels/CallLog.js +580 -0
- package/build/dist/Models/DatabaseModels/CallLog.js.map +1 -1
- package/build/dist/Models/DatabaseModels/EmailLog.js +580 -0
- package/build/dist/Models/DatabaseModels/EmailLog.js.map +1 -1
- package/build/dist/Models/DatabaseModels/IncidentStateTimeline.js +1 -1
- package/build/dist/Models/DatabaseModels/IncidentStateTimeline.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Index.js +4 -0
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/PushNotificationLog.js +904 -0
- package/build/dist/Models/DatabaseModels/PushNotificationLog.js.map +1 -0
- package/build/dist/Models/DatabaseModels/SmsLog.js +580 -0
- package/build/dist/Models/DatabaseModels/SmsLog.js.map +1 -1
- package/build/dist/Models/DatabaseModels/WorkspaceNotificationLog.js +961 -0
- package/build/dist/Models/DatabaseModels/WorkspaceNotificationLog.js.map +1 -0
- package/build/dist/Server/API/StatusPageAPI.js +2 -0
- package/build/dist/Server/API/StatusPageAPI.js.map +1 -1
- package/build/dist/Server/API/UserPushAPI.js +9 -1
- package/build/dist/Server/API/UserPushAPI.js.map +1 -1
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1754776130988-MigrationName.js +104 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1754776130988-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1754828812691-MigrationName.js +42 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1754828812691-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1754910440587-MigrationName.js +42 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1754910440587-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755030730926-MigrationName.js +44 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755030730926-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755088852971-MigrationName.js +134 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755088852971-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755093133870-MigrationName.js +16 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755093133870-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755109893911-MigrationName.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755109893911-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755110936888-MigrationName.js +20 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1755110936888-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +16 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Infrastructure/Queue.js +28 -0
- package/build/dist/Server/Infrastructure/Queue.js.map +1 -1
- package/build/dist/Server/Services/CallService.js +12 -1
- package/build/dist/Server/Services/CallService.js.map +1 -1
- package/build/dist/Server/Services/Index.js +2 -0
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/MailService.js +37 -0
- package/build/dist/Server/Services/MailService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleUserService.js +4 -0
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleUserService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js +9 -0
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js.map +1 -1
- package/build/dist/Server/Services/ProjectService.js +3 -5
- package/build/dist/Server/Services/ProjectService.js.map +1 -1
- package/build/dist/Server/Services/PushNotificationLogService.js +13 -0
- package/build/dist/Server/Services/PushNotificationLogService.js.map +1 -0
- package/build/dist/Server/Services/PushNotificationService.js +98 -13
- package/build/dist/Server/Services/PushNotificationService.js.map +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceService.js +4 -0
- package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
- package/build/dist/Server/Services/SmsService.js +12 -1
- package/build/dist/Server/Services/SmsService.js.map +1 -1
- package/build/dist/Server/Services/StatusPagePrivateUserService.js +1 -0
- package/build/dist/Server/Services/StatusPagePrivateUserService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageService.js +1 -0
- package/build/dist/Server/Services/StatusPageService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageSubscriberService.js +3 -0
- package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
- package/build/dist/Server/Services/TeamMemberService.js +1 -0
- package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
- package/build/dist/Server/Services/UserCallService.js +1 -0
- package/build/dist/Server/Services/UserCallService.js.map +1 -1
- package/build/dist/Server/Services/UserEmailService.js +1 -0
- package/build/dist/Server/Services/UserEmailService.js.map +1 -1
- package/build/dist/Server/Services/UserNotificationRuleService.js +70 -6
- package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
- package/build/dist/Server/Services/UserNotificationSettingService.js +43 -0
- package/build/dist/Server/Services/UserNotificationSettingService.js.map +1 -1
- package/build/dist/Server/Services/UserOnCallLogService.js +1 -0
- package/build/dist/Server/Services/UserOnCallLogService.js.map +1 -1
- package/build/dist/Server/Services/UserSmsService.js +1 -0
- package/build/dist/Server/Services/UserSmsService.js.map +1 -1
- package/build/dist/Server/Services/WorkspaceNotificationLogService.js +181 -0
- package/build/dist/Server/Services/WorkspaceNotificationLogService.js.map +1 -0
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +193 -3
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +19 -6
- package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js +48 -0
- package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js +48 -1
- package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js +47 -0
- package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js +19 -6
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
- package/build/dist/Types/Permission.js +16 -0
- package/build/dist/Types/Permission.js.map +1 -1
- package/build/dist/Types/PushNotification/PushStatus.js +7 -0
- package/build/dist/Types/PushNotification/PushStatus.js.map +1 -0
- package/build/dist/Types/Workspace/WorkspaceNotificationActionType.js +9 -0
- package/build/dist/Types/Workspace/WorkspaceNotificationActionType.js.map +1 -0
- package/build/dist/Types/Workspace/WorkspaceNotificationStatus.js +7 -0
- package/build/dist/Types/Workspace/WorkspaceNotificationStatus.js.map +1 -0
- package/build/dist/UI/Components/Detail/Detail.js +1 -1
- package/build/dist/UI/Components/Detail/Detail.js.map +1 -1
- package/build/dist/UI/Components/Graphs/ServiceDependencyGraph.js +206 -0
- package/build/dist/UI/Components/Graphs/ServiceDependencyGraph.js.map +1 -0
- package/build/dist/UI/Components/Tabs/Tab.js +6 -5
- package/build/dist/UI/Components/Tabs/Tab.js.map +1 -1
- package/build/dist/UI/Components/Tabs/Tabs.js +5 -6
- package/build/dist/UI/Components/Tabs/Tabs.js.map +1 -1
- package/build/dist/Utils/Uptime/UptimeUtil.js +10 -1
- package/build/dist/Utils/Uptime/UptimeUtil.js.map +1 -1
- package/package.json +2 -1
|
@@ -21,6 +21,18 @@ export class MailService extends BaseService {
|
|
|
21
21
|
mailServer?: EmailServer | undefined;
|
|
22
22
|
userOnCallLogTimelineId?: ObjectID;
|
|
23
23
|
projectId?: ObjectID | undefined;
|
|
24
|
+
incidentId?: ObjectID | undefined;
|
|
25
|
+
alertId?: ObjectID | undefined;
|
|
26
|
+
scheduledMaintenanceId?: ObjectID | undefined;
|
|
27
|
+
statusPageId?: ObjectID | undefined;
|
|
28
|
+
statusPageAnnouncementId?: ObjectID | undefined;
|
|
29
|
+
userId?: ObjectID | undefined;
|
|
30
|
+
// On-call policy related fields
|
|
31
|
+
onCallPolicyId?: ObjectID | undefined;
|
|
32
|
+
onCallPolicyEscalationRuleId?: ObjectID | undefined;
|
|
33
|
+
onCallDutyPolicyExecutionLogTimelineId?: ObjectID | undefined;
|
|
34
|
+
onCallScheduleId?: ObjectID | undefined;
|
|
35
|
+
teamId?: ObjectID | undefined;
|
|
24
36
|
},
|
|
25
37
|
): Promise<HTTPResponse<EmptyResponseData>> {
|
|
26
38
|
const body: JSONObject = {
|
|
@@ -48,6 +60,54 @@ export class MailService extends BaseService {
|
|
|
48
60
|
body["projectId"] = options.projectId.toString();
|
|
49
61
|
}
|
|
50
62
|
|
|
63
|
+
if (options?.incidentId) {
|
|
64
|
+
body["incidentId"] = options.incidentId.toString();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (options?.alertId) {
|
|
68
|
+
body["alertId"] = options.alertId.toString();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (options?.scheduledMaintenanceId) {
|
|
72
|
+
body["scheduledMaintenanceId"] =
|
|
73
|
+
options.scheduledMaintenanceId.toString();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (options?.statusPageId) {
|
|
77
|
+
body["statusPageId"] = options.statusPageId.toString();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (options?.statusPageAnnouncementId) {
|
|
81
|
+
body["statusPageAnnouncementId"] =
|
|
82
|
+
options.statusPageAnnouncementId.toString();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (options?.userId) {
|
|
86
|
+
body["userId"] = options.userId.toString();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (options?.onCallPolicyId) {
|
|
90
|
+
body["onCallPolicyId"] = options.onCallPolicyId.toString();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (options?.onCallPolicyEscalationRuleId) {
|
|
94
|
+
body["onCallPolicyEscalationRuleId"] =
|
|
95
|
+
options.onCallPolicyEscalationRuleId.toString();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (options?.onCallDutyPolicyExecutionLogTimelineId) {
|
|
99
|
+
body["onCallDutyPolicyExecutionLogTimelineId"] =
|
|
100
|
+
options.onCallDutyPolicyExecutionLogTimelineId.toString();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (options?.onCallScheduleId) {
|
|
104
|
+
body["onCallScheduleId"] = options.onCallScheduleId.toString();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (options?.teamId) {
|
|
108
|
+
body["teamId"] = options.teamId.toString();
|
|
109
|
+
}
|
|
110
|
+
|
|
51
111
|
return await API.post<EmptyResponseData>(
|
|
52
112
|
new URL(
|
|
53
113
|
Protocol.HTTP,
|
|
@@ -126,6 +126,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
126
126
|
pushNotificationMessage: pushMessage,
|
|
127
127
|
eventType:
|
|
128
128
|
NotificationSettingEventType.SEND_WHEN_USER_IS_ADDED_TO_ON_CALL_POLICY,
|
|
129
|
+
onCallPolicyId: createdModel.onCallDutyPolicy!.id!,
|
|
130
|
+
onCallPolicyEscalationRuleId:
|
|
131
|
+
createdModel.onCallDutyPolicyEscalationRule!.id!,
|
|
129
132
|
});
|
|
130
133
|
|
|
131
134
|
// add workspace message.
|
|
@@ -328,6 +331,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
328
331
|
pushNotificationMessage: pushMessage,
|
|
329
332
|
eventType:
|
|
330
333
|
NotificationSettingEventType.SEND_WHEN_USER_IS_REMOVED_FROM_ON_CALL_POLICY,
|
|
334
|
+
onCallPolicyId: deletedItem.onCallDutyPolicy!.id!,
|
|
335
|
+
onCallPolicyEscalationRuleId:
|
|
336
|
+
deletedItem.onCallDutyPolicyEscalationRule!.id!,
|
|
331
337
|
});
|
|
332
338
|
}
|
|
333
339
|
|
|
@@ -272,6 +272,10 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
272
272
|
pushNotificationMessage: pushMessage,
|
|
273
273
|
eventType:
|
|
274
274
|
NotificationSettingEventType.SEND_WHEN_USER_IS_NO_LONGER_ACTIVE_ON_ON_CALL_ROSTER,
|
|
275
|
+
onCallPolicyId: escalationRule.onCallDutyPolicy!.id!,
|
|
276
|
+
onCallPolicyEscalationRuleId:
|
|
277
|
+
escalationRule.onCallDutyPolicyEscalationRule!.id!,
|
|
278
|
+
onCallScheduleId: data.scheduleId,
|
|
275
279
|
});
|
|
276
280
|
|
|
277
281
|
// add end log for user.
|
|
@@ -388,6 +392,10 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
388
392
|
pushNotificationMessage: pushMessage,
|
|
389
393
|
eventType:
|
|
390
394
|
NotificationSettingEventType.SEND_WHEN_USER_IS_ON_CALL_ROSTER,
|
|
395
|
+
onCallPolicyId: escalationRule.onCallDutyPolicy!.id!,
|
|
396
|
+
onCallPolicyEscalationRuleId:
|
|
397
|
+
escalationRule.onCallDutyPolicyEscalationRule!.id!,
|
|
398
|
+
onCallScheduleId: data.scheduleId,
|
|
391
399
|
});
|
|
392
400
|
|
|
393
401
|
// add start log for user.
|
|
@@ -524,6 +532,10 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
524
532
|
pushNotificationMessage: pushMessage,
|
|
525
533
|
eventType:
|
|
526
534
|
NotificationSettingEventType.SEND_WHEN_USER_IS_NEXT_ON_CALL_ROSTER,
|
|
535
|
+
onCallPolicyId: escalationRule.onCallDutyPolicy!.id!,
|
|
536
|
+
onCallPolicyEscalationRuleId:
|
|
537
|
+
escalationRule.onCallDutyPolicyEscalationRule!.id!,
|
|
538
|
+
onCallScheduleId: data.scheduleId,
|
|
527
539
|
});
|
|
528
540
|
|
|
529
541
|
const onCallDutyPolicyId: ObjectID =
|
|
@@ -45,7 +45,6 @@ import {
|
|
|
45
45
|
import Color from "../../Types/Color";
|
|
46
46
|
import LIMIT_MAX from "../../Types/Database/LimitMax";
|
|
47
47
|
import OneUptimeDate from "../../Types/Date";
|
|
48
|
-
import Email from "../../Types/Email";
|
|
49
48
|
import EmailTemplateType from "../../Types/Email/EmailTemplateType";
|
|
50
49
|
import BadDataException from "../../Types/Exception/BadDataException";
|
|
51
50
|
import NotAuthorizedException from "../../Types/Exception/NotAuthorizedException";
|
|
@@ -1276,14 +1275,10 @@ export class ProjectService extends DatabaseService<Model> {
|
|
|
1276
1275
|
return;
|
|
1277
1276
|
}
|
|
1278
1277
|
|
|
1279
|
-
const
|
|
1280
|
-
return owner.email!;
|
|
1281
|
-
});
|
|
1282
|
-
|
|
1283
|
-
for (const email of emails) {
|
|
1278
|
+
for (const owner of owners) {
|
|
1284
1279
|
MailService.sendMail(
|
|
1285
1280
|
{
|
|
1286
|
-
toEmail: email
|
|
1281
|
+
toEmail: owner.email!,
|
|
1287
1282
|
templateType: EmailTemplateType.SimpleMessage,
|
|
1288
1283
|
vars: {
|
|
1289
1284
|
subject: subject,
|
|
@@ -1293,6 +1288,7 @@ export class ProjectService extends DatabaseService<Model> {
|
|
|
1293
1288
|
},
|
|
1294
1289
|
{
|
|
1295
1290
|
projectId,
|
|
1291
|
+
userId: owner.id!,
|
|
1296
1292
|
},
|
|
1297
1293
|
).catch((err: Error) => {
|
|
1298
1294
|
logger.error(err);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IsBillingEnabled } from "../EnvironmentConfig";
|
|
2
|
+
import DatabaseService from "./DatabaseService";
|
|
3
|
+
import Model from "../../Models/DatabaseModels/PushNotificationLog";
|
|
4
|
+
|
|
5
|
+
export class Service extends DatabaseService<Model> {
|
|
6
|
+
public constructor() {
|
|
7
|
+
super(Model);
|
|
8
|
+
if (IsBillingEnabled) {
|
|
9
|
+
this.hardDeleteItemsOlderThanInDays("createdAt", 3);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default new Service();
|
|
@@ -14,11 +14,27 @@ import webpush from "web-push";
|
|
|
14
14
|
import PushNotificationUtil from "../Utils/PushNotificationUtil";
|
|
15
15
|
import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
|
|
16
16
|
import UserPush from "../../Models/DatabaseModels/UserPush";
|
|
17
|
+
import PushNotificationLog from "../../Models/DatabaseModels/PushNotificationLog";
|
|
18
|
+
import PushNotificationLogService from "./PushNotificationLogService";
|
|
19
|
+
import PushStatus from "../../Types/PushNotification/PushStatus";
|
|
17
20
|
|
|
18
21
|
export interface PushNotificationOptions {
|
|
19
22
|
projectId?: ObjectID | undefined;
|
|
20
23
|
isSensitive?: boolean;
|
|
21
24
|
userOnCallLogTimelineId?: ObjectID | undefined;
|
|
25
|
+
// Optional relations for richer logging
|
|
26
|
+
incidentId?: ObjectID | undefined;
|
|
27
|
+
alertId?: ObjectID | undefined;
|
|
28
|
+
scheduledMaintenanceId?: ObjectID | undefined;
|
|
29
|
+
statusPageId?: ObjectID | undefined;
|
|
30
|
+
statusPageAnnouncementId?: ObjectID | undefined;
|
|
31
|
+
userId?: ObjectID | undefined;
|
|
32
|
+
// On-call policy related fields
|
|
33
|
+
onCallPolicyId?: ObjectID | undefined;
|
|
34
|
+
onCallPolicyEscalationRuleId?: ObjectID | undefined;
|
|
35
|
+
onCallDutyPolicyExecutionLogTimelineId?: ObjectID | undefined;
|
|
36
|
+
onCallScheduleId?: ObjectID | undefined;
|
|
37
|
+
teamId?: ObjectID | undefined;
|
|
22
38
|
}
|
|
23
39
|
|
|
24
40
|
export default class PushNotificationService {
|
|
@@ -50,12 +66,12 @@ export default class PushNotificationService {
|
|
|
50
66
|
options: PushNotificationOptions = {},
|
|
51
67
|
): Promise<void> {
|
|
52
68
|
logger.info(
|
|
53
|
-
`Sending push notification to ${request.
|
|
69
|
+
`Sending push notification to ${request.devices?.length} devices`,
|
|
54
70
|
);
|
|
55
71
|
|
|
56
|
-
if (!request.
|
|
57
|
-
logger.error("No
|
|
58
|
-
throw new Error("No
|
|
72
|
+
if (!request.devices || request.devices.length === 0) {
|
|
73
|
+
logger.error("No devices provided for push notification");
|
|
74
|
+
throw new Error("No devices provided");
|
|
59
75
|
}
|
|
60
76
|
|
|
61
77
|
if (request.deviceType !== "web") {
|
|
@@ -64,15 +80,24 @@ export default class PushNotificationService {
|
|
|
64
80
|
}
|
|
65
81
|
|
|
66
82
|
logger.info(
|
|
67
|
-
`Sending web push notifications to ${request.
|
|
83
|
+
`Sending web push notifications to ${request.devices.length} devices`,
|
|
68
84
|
);
|
|
69
85
|
logger.info(`Notification message: ${JSON.stringify(request.message)}`);
|
|
70
86
|
|
|
87
|
+
const deviceNames: (string | undefined)[] = request.devices
|
|
88
|
+
.map((device: { token: string; name?: string }) => {
|
|
89
|
+
return device.name;
|
|
90
|
+
})
|
|
91
|
+
.filter(Boolean);
|
|
92
|
+
if (deviceNames.length > 0) {
|
|
93
|
+
logger.info(`Device names: ${deviceNames.join(", ")}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
71
96
|
const promises: Promise<void>[] = [];
|
|
72
97
|
|
|
73
|
-
for (const
|
|
98
|
+
for (const device of request.devices) {
|
|
74
99
|
promises.push(
|
|
75
|
-
this.sendWebPushNotification(
|
|
100
|
+
this.sendWebPushNotification(device.token, request.message, options),
|
|
76
101
|
);
|
|
77
102
|
}
|
|
78
103
|
|
|
@@ -82,13 +107,23 @@ export default class PushNotificationService {
|
|
|
82
107
|
let errorCount: number = 0;
|
|
83
108
|
|
|
84
109
|
results.forEach((result: any, index: number) => {
|
|
110
|
+
const device:
|
|
111
|
+
| {
|
|
112
|
+
token: string;
|
|
113
|
+
name?: string;
|
|
114
|
+
}
|
|
115
|
+
| undefined = request.devices[index];
|
|
116
|
+
const deviceInfo: string = device?.name
|
|
117
|
+
? `device "${device.name}" (${index + 1})`
|
|
118
|
+
: `device ${index + 1}`;
|
|
119
|
+
|
|
85
120
|
if (result.status === "fulfilled") {
|
|
86
121
|
successCount++;
|
|
87
|
-
logger.info(
|
|
122
|
+
logger.info(`${deviceInfo}: Notification sent successfully`);
|
|
88
123
|
} else {
|
|
89
124
|
errorCount++;
|
|
90
125
|
logger.error(
|
|
91
|
-
`Failed to send notification to
|
|
126
|
+
`Failed to send notification to ${deviceInfo}: ${result.reason}`,
|
|
92
127
|
);
|
|
93
128
|
}
|
|
94
129
|
});
|
|
@@ -97,6 +132,83 @@ export default class PushNotificationService {
|
|
|
97
132
|
`Push notification results: ${successCount} successful, ${errorCount} failed`,
|
|
98
133
|
);
|
|
99
134
|
|
|
135
|
+
// Create one push log per device if projectId provided
|
|
136
|
+
if (options.projectId) {
|
|
137
|
+
for (let i: number = 0; i < results.length; i++) {
|
|
138
|
+
const result: any = results[i];
|
|
139
|
+
const device:
|
|
140
|
+
| {
|
|
141
|
+
token: string;
|
|
142
|
+
name?: string;
|
|
143
|
+
}
|
|
144
|
+
| undefined = request.devices[i];
|
|
145
|
+
const log: PushNotificationLog = new PushNotificationLog();
|
|
146
|
+
log.projectId = options.projectId;
|
|
147
|
+
log.title = request.message.title || "";
|
|
148
|
+
log.body = options.isSensitive
|
|
149
|
+
? "Sensitive message not logged"
|
|
150
|
+
: request.message.body || "";
|
|
151
|
+
log.deviceType = request.deviceType;
|
|
152
|
+
|
|
153
|
+
// Set device name if available
|
|
154
|
+
if (device?.name) {
|
|
155
|
+
log.deviceName = device.name;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// relations if provided
|
|
159
|
+
if (options.incidentId) {
|
|
160
|
+
log.incidentId = options.incidentId;
|
|
161
|
+
}
|
|
162
|
+
if (options.alertId) {
|
|
163
|
+
log.alertId = options.alertId;
|
|
164
|
+
}
|
|
165
|
+
if (options.scheduledMaintenanceId) {
|
|
166
|
+
log.scheduledMaintenanceId = options.scheduledMaintenanceId;
|
|
167
|
+
}
|
|
168
|
+
if (options.statusPageId) {
|
|
169
|
+
log.statusPageId = options.statusPageId;
|
|
170
|
+
}
|
|
171
|
+
if (options.statusPageAnnouncementId) {
|
|
172
|
+
log.statusPageAnnouncementId = options.statusPageAnnouncementId;
|
|
173
|
+
}
|
|
174
|
+
if (options.userId) {
|
|
175
|
+
log.userId = options.userId;
|
|
176
|
+
}
|
|
177
|
+
if (options.teamId) {
|
|
178
|
+
log.teamId = options.teamId;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Set OnCall-related fields
|
|
182
|
+
if (options.onCallPolicyId) {
|
|
183
|
+
log.onCallDutyPolicyId = options.onCallPolicyId;
|
|
184
|
+
}
|
|
185
|
+
if (options.onCallPolicyEscalationRuleId) {
|
|
186
|
+
log.onCallDutyPolicyEscalationRuleId =
|
|
187
|
+
options.onCallPolicyEscalationRuleId;
|
|
188
|
+
}
|
|
189
|
+
if (options.onCallScheduleId) {
|
|
190
|
+
log.onCallDutyPolicyScheduleId = options.onCallScheduleId;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (result.status === "fulfilled") {
|
|
194
|
+
log.status = PushStatus.Success;
|
|
195
|
+
log.statusMessage = "Push notification sent";
|
|
196
|
+
} else {
|
|
197
|
+
log.status = PushStatus.Error;
|
|
198
|
+
const reason: string =
|
|
199
|
+
(result &&
|
|
200
|
+
(result.reason?.message || result.reason?.toString?.())) ||
|
|
201
|
+
`Failed to send push notification`;
|
|
202
|
+
log.statusMessage = reason;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
await PushNotificationLogService.create({
|
|
206
|
+
data: log,
|
|
207
|
+
props: { isRoot: true },
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
100
212
|
// Update user on call log timeline status if provided
|
|
101
213
|
if (options.userOnCallLogTimelineId) {
|
|
102
214
|
const status: UserNotificationStatus =
|
|
@@ -213,6 +325,7 @@ export default class PushNotificationService {
|
|
|
213
325
|
select: {
|
|
214
326
|
deviceToken: true,
|
|
215
327
|
deviceType: true,
|
|
328
|
+
deviceName: true,
|
|
216
329
|
_id: true,
|
|
217
330
|
},
|
|
218
331
|
limit: LIMIT_PER_PROJECT,
|
|
@@ -229,12 +342,15 @@ export default class PushNotificationService {
|
|
|
229
342
|
return;
|
|
230
343
|
}
|
|
231
344
|
|
|
232
|
-
// Get web
|
|
233
|
-
const webDevices: string
|
|
345
|
+
// Get web devices with tokens and names
|
|
346
|
+
const webDevices: Array<{ token: string; name?: string }> = [];
|
|
234
347
|
|
|
235
348
|
for (const device of userPushDevices) {
|
|
236
349
|
if (device.deviceType === "web") {
|
|
237
|
-
webDevices.push(
|
|
350
|
+
webDevices.push({
|
|
351
|
+
token: device.deviceToken!,
|
|
352
|
+
name: device.deviceName || "Unknown Device",
|
|
353
|
+
});
|
|
238
354
|
}
|
|
239
355
|
}
|
|
240
356
|
|
|
@@ -242,7 +358,7 @@ export default class PushNotificationService {
|
|
|
242
358
|
if (webDevices.length > 0) {
|
|
243
359
|
await this.sendPushNotification(
|
|
244
360
|
{
|
|
245
|
-
|
|
361
|
+
devices: webDevices,
|
|
246
362
|
message: message,
|
|
247
363
|
deviceType: "web",
|
|
248
364
|
},
|
|
@@ -251,6 +251,8 @@ export class Service extends DatabaseService<Model> {
|
|
|
251
251
|
customTwilioConfig: ProjectCallSMSConfigService.toTwilioConfig(
|
|
252
252
|
statuspage.callSmsConfig,
|
|
253
253
|
),
|
|
254
|
+
statusPageId: statuspage.id!,
|
|
255
|
+
scheduledMaintenanceId: event.id!,
|
|
254
256
|
}).catch((err: Error) => {
|
|
255
257
|
logger.error(err);
|
|
256
258
|
});
|
|
@@ -319,6 +321,8 @@ ${resourcesAffected ? `**Resources Affected:** ${resourcesAffected}` : ""}
|
|
|
319
321
|
statuspage.smtpConfig,
|
|
320
322
|
),
|
|
321
323
|
projectId: statuspage.projectId!,
|
|
324
|
+
statusPageId: statuspage.id!,
|
|
325
|
+
scheduledMaintenanceId: event.id!,
|
|
322
326
|
},
|
|
323
327
|
).catch((err: Error) => {
|
|
324
328
|
logger.error(err);
|
|
@@ -26,6 +26,18 @@ export class SmsService extends BaseService {
|
|
|
26
26
|
isSensitive?: boolean; // if true, message will not be logged
|
|
27
27
|
userOnCallLogTimelineId?: ObjectID;
|
|
28
28
|
customTwilioConfig?: TwilioConfig | undefined;
|
|
29
|
+
incidentId?: ObjectID | undefined;
|
|
30
|
+
alertId?: ObjectID | undefined;
|
|
31
|
+
scheduledMaintenanceId?: ObjectID | undefined;
|
|
32
|
+
statusPageId?: ObjectID | undefined;
|
|
33
|
+
statusPageAnnouncementId?: ObjectID | undefined;
|
|
34
|
+
userId?: ObjectID | undefined;
|
|
35
|
+
// On-call policy related fields
|
|
36
|
+
onCallPolicyId?: ObjectID | undefined;
|
|
37
|
+
onCallPolicyEscalationRuleId?: ObjectID | undefined;
|
|
38
|
+
onCallDutyPolicyExecutionLogTimelineId?: ObjectID | undefined;
|
|
39
|
+
onCallScheduleId?: ObjectID | undefined;
|
|
40
|
+
teamId?: ObjectID | undefined;
|
|
29
41
|
},
|
|
30
42
|
): Promise<HTTPResponse<EmptyResponseData>> {
|
|
31
43
|
const body: JSONObject = {
|
|
@@ -44,6 +56,19 @@ export class SmsService extends BaseService {
|
|
|
44
56
|
options.customTwilioConfig.secondaryPhoneNumbers?.toString(),
|
|
45
57
|
}
|
|
46
58
|
: undefined,
|
|
59
|
+
incidentId: options.incidentId?.toString(),
|
|
60
|
+
alertId: options.alertId?.toString(),
|
|
61
|
+
scheduledMaintenanceId: options.scheduledMaintenanceId?.toString(),
|
|
62
|
+
statusPageId: options.statusPageId?.toString(),
|
|
63
|
+
statusPageAnnouncementId: options.statusPageAnnouncementId?.toString(),
|
|
64
|
+
userId: options.userId?.toString(),
|
|
65
|
+
onCallPolicyId: options.onCallPolicyId?.toString(),
|
|
66
|
+
onCallPolicyEscalationRuleId:
|
|
67
|
+
options.onCallPolicyEscalationRuleId?.toString(),
|
|
68
|
+
onCallDutyPolicyExecutionLogTimelineId:
|
|
69
|
+
options.onCallDutyPolicyExecutionLogTimelineId?.toString(),
|
|
70
|
+
onCallScheduleId: options.onCallScheduleId?.toString(),
|
|
71
|
+
teamId: options.teamId?.toString(),
|
|
47
72
|
};
|
|
48
73
|
|
|
49
74
|
return await API.post<EmptyResponseData>(
|
|
@@ -313,6 +313,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
313
313
|
customTwilioConfig: ProjectCallSMSConfigService.toTwilioConfig(
|
|
314
314
|
statusPage.callSmsConfig,
|
|
315
315
|
),
|
|
316
|
+
statusPageId: createdItem.statusPageId!,
|
|
316
317
|
},
|
|
317
318
|
).catch((err: Error) => {
|
|
318
319
|
logger.error(err);
|
|
@@ -509,6 +510,7 @@ Stay informed about service availability! 🚀`;
|
|
|
509
510
|
mailServer: ProjectSMTPConfigService.toEmailServer(
|
|
510
511
|
statusPage.smtpConfig,
|
|
511
512
|
),
|
|
513
|
+
statusPageId: statusPage.id!,
|
|
512
514
|
},
|
|
513
515
|
).catch((err: Error) => {
|
|
514
516
|
logger.error(err);
|
|
@@ -635,6 +637,7 @@ Stay informed about service availability! 🚀`;
|
|
|
635
637
|
mailServer: ProjectSMTPConfigService.toEmailServer(
|
|
636
638
|
statusPage.smtpConfig,
|
|
637
639
|
),
|
|
640
|
+
statusPageId: statusPage.id!,
|
|
638
641
|
},
|
|
639
642
|
).catch((err: Error) => {
|
|
640
643
|
logger.error("Error sending subscription email:");
|