@oneuptime/common 7.0.3707 → 7.0.3712
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/Server/API/StatusPageAPI.ts +44 -1
- package/Server/Services/ScheduledMaintenanceService.ts +2 -1
- package/Server/Services/StatusPageSubscriberService.ts +160 -12
- package/Server/Services/WorkspaceNotificationRuleService.ts +205 -11
- package/Server/Services/WorkspaceProjectAuthTokenService.ts +1 -0
- package/Server/Types/Workflow/Components/BaseModel/OnTriggerBaseModel.ts +18 -7
- package/Server/Utils/Workspace/Slack/Slack.ts +352 -45
- package/Server/Utils/Workspace/Slack/app-manifest.json +9 -4
- package/Server/Utils/Workspace/WorkspaceBase.ts +31 -2
- package/Types/Workflow/Component.ts +1 -0
- package/Types/Workflow/Components/BaseModel.ts +30 -0
- package/Types/Workflow/Components/Manual.ts +10 -0
- package/Types/Workflow/Components/Schedule.ts +1 -0
- package/Types/Workflow/Components/Webhook.ts +26 -0
- package/UI/Components/Workflow/RunForm.tsx +23 -25
- package/build/dist/Server/API/StatusPageAPI.js +19 -0
- package/build/dist/Server/API/StatusPageAPI.js.map +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceService.js +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
- package/build/dist/Server/Services/StatusPageSubscriberService.js +116 -7
- package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +136 -8
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
- package/build/dist/Server/Services/WorkspaceProjectAuthTokenService.js +1 -0
- package/build/dist/Server/Services/WorkspaceProjectAuthTokenService.js.map +1 -1
- package/build/dist/Server/Types/Workflow/Components/BaseModel/OnTriggerBaseModel.js +14 -5
- package/build/dist/Server/Types/Workflow/Components/BaseModel/OnTriggerBaseModel.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js +251 -36
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +9 -4
- package/build/dist/Server/Utils/Workspace/WorkspaceBase.js +12 -2
- package/build/dist/Server/Utils/Workspace/WorkspaceBase.js.map +1 -1
- package/build/dist/Types/Workflow/Components/BaseModel.js +30 -0
- package/build/dist/Types/Workflow/Components/BaseModel.js.map +1 -1
- package/build/dist/Types/Workflow/Components/Manual.js +10 -0
- package/build/dist/Types/Workflow/Components/Manual.js.map +1 -1
- package/build/dist/Types/Workflow/Components/Schedule.js +1 -0
- package/build/dist/Types/Workflow/Components/Schedule.js.map +1 -1
- package/build/dist/Types/Workflow/Components/Webhook.js +26 -0
- package/build/dist/Types/Workflow/Components/Webhook.js.map +1 -1
- package/build/dist/UI/Components/Workflow/RunForm.js +16 -14
- package/build/dist/UI/Components/Workflow/RunForm.js.map +1 -1
- package/package.json +2 -2
- /package/Server/Utils/Workspace/Slack/{app-manifest-temp.json → app-manifest.example.json} +0 -0
|
@@ -39,28 +39,38 @@ export class Service extends DatabaseService<Model> {
|
|
|
39
39
|
protected override async onBeforeCreate(
|
|
40
40
|
data: CreateBy<Model>,
|
|
41
41
|
): Promise<OnCreate<Model>> {
|
|
42
|
+
logger.debug("onBeforeCreate called with data:");
|
|
43
|
+
logger.debug(data);
|
|
44
|
+
|
|
42
45
|
if (!data.data.statusPageId) {
|
|
46
|
+
logger.debug("Status Page ID is missing.");
|
|
43
47
|
throw new BadDataException("Status Page ID is required.");
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
if (!data.data.projectId) {
|
|
51
|
+
logger.debug("Project ID is missing.");
|
|
47
52
|
throw new BadDataException("Project ID is required.");
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
const projectId: ObjectID = data.data.projectId;
|
|
56
|
+
logger.debug(`Project ID: ${projectId}`);
|
|
51
57
|
|
|
52
58
|
// if the project is on the free plan, then only allow 1 status page.
|
|
53
59
|
if (IsBillingEnabled) {
|
|
60
|
+
logger.debug("Billing is enabled.");
|
|
54
61
|
const currentPlan: CurrentPlan =
|
|
55
62
|
await ProjectService.getCurrentPlan(projectId);
|
|
63
|
+
logger.debug(`Current Plan: ${JSON.stringify(currentPlan)}`);
|
|
56
64
|
|
|
57
65
|
if (currentPlan.isSubscriptionUnpaid) {
|
|
66
|
+
logger.debug("Subscription is unpaid.");
|
|
58
67
|
throw new BadDataException(
|
|
59
68
|
"Your subscription is unpaid. Please update your payment method and to add subscribers.",
|
|
60
69
|
);
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
if (currentPlan.plan === PlanType.Free) {
|
|
73
|
+
logger.debug("Current plan is Free.");
|
|
64
74
|
const subscribersCount: PositiveNumber = await this.countBy({
|
|
65
75
|
query: {
|
|
66
76
|
projectId: projectId,
|
|
@@ -69,8 +79,12 @@ export class Service extends DatabaseService<Model> {
|
|
|
69
79
|
isRoot: true,
|
|
70
80
|
},
|
|
71
81
|
});
|
|
82
|
+
logger.debug(`Subscribers Count: ${subscribersCount.toNumber()}`);
|
|
72
83
|
|
|
73
84
|
if (subscribersCount.toNumber() >= AllowedSubscribersCountInFreePlan) {
|
|
85
|
+
logger.debug(
|
|
86
|
+
"Reached maximum allowed subscriber limit for the free plan.",
|
|
87
|
+
);
|
|
74
88
|
throw new BadDataException(
|
|
75
89
|
`You have reached the maximum allowed subscriber limit for the free plan. Please upgrade your plan to add more subscribers.`,
|
|
76
90
|
);
|
|
@@ -81,6 +95,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
81
95
|
let subscriber: Model | null = null;
|
|
82
96
|
|
|
83
97
|
if (data.data.subscriberEmail) {
|
|
98
|
+
logger.debug(`Subscriber Email: ${data.data.subscriberEmail}`);
|
|
84
99
|
subscriber = await this.findOneBy({
|
|
85
100
|
query: {
|
|
86
101
|
statusPageId: data.data.statusPageId,
|
|
@@ -95,15 +110,18 @@ export class Service extends DatabaseService<Model> {
|
|
|
95
110
|
ignoreHooks: true,
|
|
96
111
|
},
|
|
97
112
|
});
|
|
113
|
+
logger.debug(`Found Subscriber by Email: ${JSON.stringify(subscriber)}`);
|
|
98
114
|
}
|
|
99
115
|
|
|
100
116
|
if (data.data.subscriberPhone) {
|
|
117
|
+
logger.debug(`Subscriber Phone: ${data.data.subscriberPhone}`);
|
|
101
118
|
// check if this project has SMS enabled.
|
|
102
|
-
|
|
103
119
|
const isSMSEnabled: boolean =
|
|
104
120
|
await ProjectService.isSMSNotificationsEnabled(projectId);
|
|
121
|
+
logger.debug(`Is SMS Enabled: ${isSMSEnabled}`);
|
|
105
122
|
|
|
106
123
|
if (!isSMSEnabled) {
|
|
124
|
+
logger.debug("SMS notifications are not enabled for this project.");
|
|
107
125
|
throw new BadDataException(
|
|
108
126
|
"SMS notifications are not enabled for this project. Please enable SMS notifications in the Project Settings > Notifications Settings.",
|
|
109
127
|
);
|
|
@@ -123,9 +141,11 @@ export class Service extends DatabaseService<Model> {
|
|
|
123
141
|
ignoreHooks: true,
|
|
124
142
|
},
|
|
125
143
|
});
|
|
144
|
+
logger.debug(`Found Subscriber by Phone: ${JSON.stringify(subscriber)}`);
|
|
126
145
|
}
|
|
127
146
|
|
|
128
147
|
if (subscriber && !subscriber.isUnsubscribed) {
|
|
148
|
+
logger.debug("Subscriber is already subscribed and not unsubscribed.");
|
|
129
149
|
throw new BadDataException(
|
|
130
150
|
"You are already subscribed to this status page.",
|
|
131
151
|
);
|
|
@@ -133,6 +153,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
133
153
|
|
|
134
154
|
// if the user is unsubscribed, delete this record and it'll create a new one.
|
|
135
155
|
if (subscriber) {
|
|
156
|
+
logger.debug("Subscriber is unsubscribed. Deleting old record.");
|
|
136
157
|
await this.deleteOneBy({
|
|
137
158
|
query: {
|
|
138
159
|
_id: subscriber?._id as string,
|
|
@@ -146,6 +167,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
146
167
|
|
|
147
168
|
const statuspages: Array<StatusPage> =
|
|
148
169
|
await this.getStatusPagesToSendNotification([data.data.statusPageId]);
|
|
170
|
+
logger.debug(`Status Pages: ${JSON.stringify(statuspages)}`);
|
|
149
171
|
|
|
150
172
|
const statuspage: StatusPage | undefined = statuspages.find(
|
|
151
173
|
(statuspage: StatusPage) => {
|
|
@@ -156,26 +178,39 @@ export class Service extends DatabaseService<Model> {
|
|
|
156
178
|
);
|
|
157
179
|
|
|
158
180
|
if (!statuspage || !statuspage.projectId) {
|
|
181
|
+
logger.debug("Status Page not found or Project ID is missing.");
|
|
159
182
|
throw new BadDataException("Status Page not found");
|
|
160
183
|
}
|
|
161
184
|
|
|
162
185
|
data.data.projectId = statuspage.projectId;
|
|
186
|
+
logger.debug(`Updated Project ID: ${data.data.projectId}`);
|
|
163
187
|
|
|
164
188
|
const isEmailSubscriber: boolean = Boolean(data.data.subscriberEmail);
|
|
165
189
|
const isSubscriptionConfirmed: boolean = Boolean(
|
|
166
190
|
data.data.isSubscriptionConfirmed,
|
|
167
191
|
);
|
|
192
|
+
logger.debug(`Is Email Subscriber: ${isEmailSubscriber}`);
|
|
193
|
+
logger.debug(`Is Subscription Confirmed: ${isSubscriptionConfirmed}`);
|
|
168
194
|
|
|
169
195
|
if (isEmailSubscriber && !isSubscriptionConfirmed) {
|
|
170
196
|
data.data.isSubscriptionConfirmed = false;
|
|
171
197
|
} else {
|
|
172
198
|
data.data.isSubscriptionConfirmed = true; // if the subscriber is not email, then set it to true for SMS subscribers.
|
|
173
199
|
}
|
|
200
|
+
logger.debug(
|
|
201
|
+
`Final Subscription Confirmed: ${data.data.isSubscriptionConfirmed}`,
|
|
202
|
+
);
|
|
174
203
|
|
|
175
204
|
data.data.subscriptionConfirmationToken = NumberUtil.getRandomNumber(
|
|
176
205
|
100000,
|
|
177
206
|
999999,
|
|
178
207
|
).toString();
|
|
208
|
+
logger.debug(
|
|
209
|
+
`Subscription Confirmation Token: ${data.data.subscriptionConfirmationToken}`,
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
logger.debug("onBeforeCreate processed data:");
|
|
213
|
+
logger.debug(data);
|
|
179
214
|
|
|
180
215
|
return { createBy: data, carryForward: statuspage };
|
|
181
216
|
}
|
|
@@ -184,23 +219,30 @@ export class Service extends DatabaseService<Model> {
|
|
|
184
219
|
onCreate: OnCreate<Model>,
|
|
185
220
|
createdItem: Model,
|
|
186
221
|
): Promise<Model> {
|
|
222
|
+
logger.debug("onCreateSuccess called with createdItem:");
|
|
223
|
+
logger.debug(createdItem);
|
|
224
|
+
|
|
187
225
|
if (!createdItem.statusPageId) {
|
|
226
|
+
logger.debug("Status Page ID is missing in createdItem.");
|
|
188
227
|
return createdItem;
|
|
189
228
|
}
|
|
190
229
|
|
|
191
230
|
const statusPageURL: string = await StatusPageService.getStatusPageURL(
|
|
192
231
|
createdItem.statusPageId,
|
|
193
232
|
);
|
|
233
|
+
logger.debug(`Status Page URL: ${statusPageURL}`);
|
|
194
234
|
|
|
195
235
|
const statusPageName: string =
|
|
196
236
|
onCreate.carryForward.pageTitle ||
|
|
197
237
|
onCreate.carryForward.name ||
|
|
198
238
|
"Status Page";
|
|
239
|
+
logger.debug(`Status Page Name: ${statusPageName}`);
|
|
199
240
|
|
|
200
241
|
const unsubscribeLink: string = this.getUnsubscribeLink(
|
|
201
242
|
URL.fromString(statusPageURL),
|
|
202
243
|
createdItem.id!,
|
|
203
244
|
).toString();
|
|
245
|
+
logger.debug(`Unsubscribe Link: ${unsubscribeLink}`);
|
|
204
246
|
|
|
205
247
|
if (
|
|
206
248
|
createdItem.statusPageId &&
|
|
@@ -208,6 +250,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
208
250
|
createdItem._id &&
|
|
209
251
|
createdItem.sendYouHaveSubscribedMessage
|
|
210
252
|
) {
|
|
253
|
+
logger.debug(
|
|
254
|
+
"Subscriber has a phone number and sendYouHaveSubscribedMessage is true.",
|
|
255
|
+
);
|
|
211
256
|
const statusPage: StatusPage | null = await StatusPageService.findOneBy({
|
|
212
257
|
query: {
|
|
213
258
|
_id: createdItem.statusPageId.toString(),
|
|
@@ -227,9 +272,14 @@ export class Service extends DatabaseService<Model> {
|
|
|
227
272
|
});
|
|
228
273
|
|
|
229
274
|
if (!statusPage) {
|
|
275
|
+
logger.debug("Status Page not found.");
|
|
230
276
|
return createdItem;
|
|
231
277
|
}
|
|
232
278
|
|
|
279
|
+
logger.debug(
|
|
280
|
+
`Status Page Call SMS Config: ${JSON.stringify(statusPage.callSmsConfig)}`,
|
|
281
|
+
);
|
|
282
|
+
|
|
233
283
|
SmsService.sendSms(
|
|
234
284
|
{
|
|
235
285
|
to: createdItem.subscriberPhone,
|
|
@@ -252,34 +302,41 @@ export class Service extends DatabaseService<Model> {
|
|
|
252
302
|
createdItem.subscriberEmail &&
|
|
253
303
|
createdItem._id
|
|
254
304
|
) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// get status page domain for this status page.
|
|
258
|
-
// if the domain is not found, use the internal status page preview link.
|
|
259
|
-
|
|
305
|
+
logger.debug("Subscriber has an email.");
|
|
260
306
|
const isSubcriptionConfirmed: boolean = Boolean(
|
|
261
307
|
createdItem.isSubscriptionConfirmed,
|
|
262
308
|
);
|
|
309
|
+
logger.debug(`Is Subscription Confirmed: ${isSubcriptionConfirmed}`);
|
|
263
310
|
|
|
264
311
|
if (!isSubcriptionConfirmed) {
|
|
312
|
+
logger.debug(
|
|
313
|
+
"Subscription is not confirmed. Sending confirmation email.",
|
|
314
|
+
);
|
|
265
315
|
await this.sendConfirmSubscriptionEmail({
|
|
266
316
|
subscriberId: createdItem.id!,
|
|
267
317
|
});
|
|
268
318
|
}
|
|
269
319
|
|
|
270
320
|
if (isSubcriptionConfirmed && createdItem.sendYouHaveSubscribedMessage) {
|
|
321
|
+
logger.debug(
|
|
322
|
+
"Subscription is confirmed and sendYouHaveSubscribedMessage is true. Sending 'You have subscribed' email.",
|
|
323
|
+
);
|
|
271
324
|
await this.sendYouHaveSubscribedEmail({
|
|
272
325
|
subscriberId: createdItem.id!,
|
|
273
326
|
});
|
|
274
327
|
}
|
|
275
328
|
}
|
|
276
329
|
|
|
330
|
+
logger.debug("onCreateSuccess completed.");
|
|
277
331
|
return createdItem;
|
|
278
332
|
}
|
|
279
333
|
|
|
280
334
|
public async sendConfirmSubscriptionEmail(data: {
|
|
281
335
|
subscriberId: ObjectID;
|
|
282
336
|
}): Promise<void> {
|
|
337
|
+
logger.debug("sendConfirmSubscriptionEmail called with data:");
|
|
338
|
+
logger.debug(data);
|
|
339
|
+
|
|
283
340
|
// get subscriber
|
|
284
341
|
const subscriber: Model | null = await this.findOneBy({
|
|
285
342
|
query: {
|
|
@@ -298,9 +355,11 @@ export class Service extends DatabaseService<Model> {
|
|
|
298
355
|
ignoreHooks: true,
|
|
299
356
|
},
|
|
300
357
|
});
|
|
358
|
+
logger.debug(`Found Subscriber: ${JSON.stringify(subscriber)}`);
|
|
301
359
|
|
|
302
360
|
// get status page
|
|
303
361
|
if (!subscriber || !subscriber.statusPageId) {
|
|
362
|
+
logger.debug("Subscriber or Status Page ID is missing.");
|
|
304
363
|
return;
|
|
305
364
|
}
|
|
306
365
|
|
|
@@ -329,27 +388,34 @@ export class Service extends DatabaseService<Model> {
|
|
|
329
388
|
ignoreHooks: true,
|
|
330
389
|
},
|
|
331
390
|
});
|
|
391
|
+
logger.debug(`Found Status Page: ${JSON.stringify(statusPage)}`);
|
|
332
392
|
|
|
333
393
|
if (!statusPage || !statusPage.id) {
|
|
394
|
+
logger.debug("Status Page not found or ID is missing.");
|
|
334
395
|
return;
|
|
335
396
|
}
|
|
336
397
|
|
|
337
398
|
const statusPageURL: string = await StatusPageService.getStatusPageURL(
|
|
338
399
|
statusPage.id,
|
|
339
400
|
);
|
|
401
|
+
logger.debug(`Status Page URL: ${statusPageURL}`);
|
|
340
402
|
|
|
341
403
|
const statusPageName: string =
|
|
342
404
|
statusPage.pageTitle || statusPage.name || "Status Page";
|
|
405
|
+
logger.debug(`Status Page Name: ${statusPageName}`);
|
|
343
406
|
|
|
344
407
|
const host: Hostname = await DatabaseConfig.getHost();
|
|
408
|
+
logger.debug(`Host: ${host}`);
|
|
345
409
|
|
|
346
410
|
const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol();
|
|
411
|
+
logger.debug(`HTTP Protocol: ${httpProtocol}`);
|
|
347
412
|
|
|
348
413
|
const confirmSubscriptionLink: string = this.getConfirmSubscriptionLink({
|
|
349
414
|
statusPageUrl: statusPageURL,
|
|
350
415
|
confirmationToken: subscriber.subscriptionConfirmationToken || "",
|
|
351
416
|
statusPageSubscriberId: subscriber.id!,
|
|
352
417
|
}).toString();
|
|
418
|
+
logger.debug(`Confirm Subscription Link: ${confirmSubscriptionLink}`);
|
|
353
419
|
|
|
354
420
|
if (
|
|
355
421
|
subscriber.statusPageId &&
|
|
@@ -360,6 +426,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
360
426
|
URL.fromString(statusPageURL),
|
|
361
427
|
subscriber.id!,
|
|
362
428
|
).toString();
|
|
429
|
+
logger.debug(`Unsubscribe URL: ${unsubscribeUrl}`);
|
|
363
430
|
|
|
364
431
|
MailService.sendMail(
|
|
365
432
|
{
|
|
@@ -391,12 +458,18 @@ export class Service extends DatabaseService<Model> {
|
|
|
391
458
|
).catch((err: Error) => {
|
|
392
459
|
logger.error(err);
|
|
393
460
|
});
|
|
461
|
+
logger.debug("Confirmation email sent.");
|
|
462
|
+
} else {
|
|
463
|
+
logger.debug("Subscriber email or ID is missing.");
|
|
394
464
|
}
|
|
395
465
|
}
|
|
396
466
|
|
|
397
467
|
public async sendYouHaveSubscribedEmail(data: {
|
|
398
468
|
subscriberId: ObjectID;
|
|
399
469
|
}): Promise<void> {
|
|
470
|
+
logger.debug("sendYouHaveSubscribedEmail called with data:");
|
|
471
|
+
logger.debug(data);
|
|
472
|
+
|
|
400
473
|
// get subscriber
|
|
401
474
|
const subscriber: Model | null = await this.findOneBy({
|
|
402
475
|
query: {
|
|
@@ -414,9 +487,11 @@ export class Service extends DatabaseService<Model> {
|
|
|
414
487
|
ignoreHooks: true,
|
|
415
488
|
},
|
|
416
489
|
});
|
|
490
|
+
logger.debug(`Found Subscriber: ${JSON.stringify(subscriber)}`);
|
|
417
491
|
|
|
418
492
|
// get status page
|
|
419
493
|
if (!subscriber || !subscriber.statusPageId) {
|
|
494
|
+
logger.debug("Subscriber or Status Page ID is missing.");
|
|
420
495
|
return;
|
|
421
496
|
}
|
|
422
497
|
|
|
@@ -445,32 +520,40 @@ export class Service extends DatabaseService<Model> {
|
|
|
445
520
|
ignoreHooks: true,
|
|
446
521
|
},
|
|
447
522
|
});
|
|
523
|
+
logger.debug(`Found Status Page: ${JSON.stringify(statusPage)}`);
|
|
448
524
|
|
|
449
525
|
if (!statusPage || !statusPage.id) {
|
|
526
|
+
logger.debug("Status Page not found or ID is missing.");
|
|
450
527
|
return;
|
|
451
528
|
}
|
|
452
529
|
|
|
453
530
|
const statusPageURL: string = await StatusPageService.getStatusPageURL(
|
|
454
531
|
statusPage.id,
|
|
455
532
|
);
|
|
533
|
+
logger.debug(`Status Page URL: ${statusPageURL}`);
|
|
456
534
|
|
|
457
535
|
const statusPageName: string =
|
|
458
536
|
statusPage.pageTitle || statusPage.name || "Status Page";
|
|
537
|
+
logger.debug(`Status Page Name: ${statusPageName}`);
|
|
459
538
|
|
|
460
539
|
const host: Hostname = await DatabaseConfig.getHost();
|
|
540
|
+
logger.debug(`Host: ${host}`);
|
|
461
541
|
|
|
462
542
|
const httpProtocol: Protocol = await DatabaseConfig.getHttpProtocol();
|
|
543
|
+
logger.debug(`HTTP Protocol: ${httpProtocol}`);
|
|
463
544
|
|
|
464
545
|
const unsubscribeLink: string = this.getUnsubscribeLink(
|
|
465
546
|
URL.fromString(statusPageURL),
|
|
466
547
|
subscriber.id!,
|
|
467
548
|
).toString();
|
|
549
|
+
logger.debug(`Unsubscribe Link: ${unsubscribeLink}`);
|
|
468
550
|
|
|
469
551
|
if (
|
|
470
552
|
subscriber.statusPageId &&
|
|
471
553
|
subscriber.subscriberEmail &&
|
|
472
554
|
subscriber._id
|
|
473
555
|
) {
|
|
556
|
+
logger.debug("Subscriber has an email and ID.");
|
|
474
557
|
MailService.sendMail(
|
|
475
558
|
{
|
|
476
559
|
toEmail: subscriber.subscriberEmail,
|
|
@@ -498,8 +581,12 @@ export class Service extends DatabaseService<Model> {
|
|
|
498
581
|
),
|
|
499
582
|
},
|
|
500
583
|
).catch((err: Error) => {
|
|
584
|
+
logger.error("Error sending subscription email:");
|
|
501
585
|
logger.error(err);
|
|
502
586
|
});
|
|
587
|
+
logger.debug("Subscription email sent successfully.");
|
|
588
|
+
} else {
|
|
589
|
+
logger.debug("Subscriber email or ID is missing.");
|
|
503
590
|
}
|
|
504
591
|
}
|
|
505
592
|
|
|
@@ -508,16 +595,31 @@ export class Service extends DatabaseService<Model> {
|
|
|
508
595
|
confirmationToken: string;
|
|
509
596
|
statusPageSubscriberId: ObjectID;
|
|
510
597
|
}): URL {
|
|
511
|
-
|
|
598
|
+
logger.debug("getConfirmSubscriptionLink called with data:");
|
|
599
|
+
logger.debug(data);
|
|
600
|
+
|
|
601
|
+
const confirmSubscriptionLink: URL = URL.fromString(
|
|
602
|
+
data.statusPageUrl,
|
|
603
|
+
).addRoute(
|
|
512
604
|
`/confirm-subscription/${data.statusPageSubscriberId.toString()}?verification-token=${data.confirmationToken}`,
|
|
513
605
|
);
|
|
606
|
+
|
|
607
|
+
logger.debug(
|
|
608
|
+
`Generated Confirm Subscription Link: ${confirmSubscriptionLink.toString()}`,
|
|
609
|
+
);
|
|
610
|
+
return confirmSubscriptionLink;
|
|
514
611
|
}
|
|
515
612
|
|
|
516
613
|
public async getSubscribersByStatusPage(
|
|
517
614
|
statusPageId: ObjectID,
|
|
518
615
|
props: DatabaseCommonInteractionProps,
|
|
519
616
|
): Promise<Array<Model>> {
|
|
520
|
-
|
|
617
|
+
logger.debug("getSubscribersByStatusPage called with statusPageId:");
|
|
618
|
+
logger.debug(statusPageId);
|
|
619
|
+
logger.debug("DatabaseCommonInteractionProps:");
|
|
620
|
+
logger.debug(props);
|
|
621
|
+
|
|
622
|
+
const subscribers: Array<Model> = await this.findBy({
|
|
521
623
|
query: {
|
|
522
624
|
statusPageId: statusPageId,
|
|
523
625
|
isUnsubscribed: false,
|
|
@@ -537,15 +639,30 @@ export class Service extends DatabaseService<Model> {
|
|
|
537
639
|
limit: LIMIT_MAX,
|
|
538
640
|
props: props,
|
|
539
641
|
});
|
|
642
|
+
|
|
643
|
+
logger.debug("Found subscribers:");
|
|
644
|
+
logger.debug(subscribers);
|
|
645
|
+
|
|
646
|
+
return subscribers;
|
|
540
647
|
}
|
|
541
648
|
|
|
542
649
|
public getUnsubscribeLink(
|
|
543
650
|
statusPageUrl: URL,
|
|
544
651
|
statusPageSubscriberId: ObjectID,
|
|
545
652
|
): URL {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
);
|
|
653
|
+
logger.debug("getUnsubscribeLink called with statusPageUrl:");
|
|
654
|
+
logger.debug(statusPageUrl);
|
|
655
|
+
logger.debug("statusPageSubscriberId:");
|
|
656
|
+
logger.debug(statusPageSubscriberId);
|
|
657
|
+
|
|
658
|
+
const unsubscribeLink: URL = URL.fromString(
|
|
659
|
+
statusPageUrl.toString(),
|
|
660
|
+
).addRoute("/update-subscription/" + statusPageSubscriberId.toString());
|
|
661
|
+
|
|
662
|
+
logger.debug("Generated Unsubscribe Link:");
|
|
663
|
+
logger.debug(unsubscribeLink);
|
|
664
|
+
|
|
665
|
+
return unsubscribeLink;
|
|
549
666
|
}
|
|
550
667
|
|
|
551
668
|
public shouldSendNotification(data: {
|
|
@@ -554,9 +671,13 @@ export class Service extends DatabaseService<Model> {
|
|
|
554
671
|
statusPage: StatusPage;
|
|
555
672
|
eventType: StatusPageEventType;
|
|
556
673
|
}): boolean {
|
|
674
|
+
logger.debug("shouldSendNotification called with data:");
|
|
675
|
+
logger.debug(data);
|
|
676
|
+
|
|
557
677
|
let shouldSendNotification: boolean = true; // default to true.
|
|
558
678
|
|
|
559
679
|
if (data.subscriber.isUnsubscribed) {
|
|
680
|
+
logger.debug("Subscriber is unsubscribed.");
|
|
560
681
|
shouldSendNotification = false;
|
|
561
682
|
return shouldSendNotification;
|
|
562
683
|
}
|
|
@@ -566,6 +687,9 @@ export class Service extends DatabaseService<Model> {
|
|
|
566
687
|
!data.subscriber.isSubscribedToAllResources &&
|
|
567
688
|
data.eventType !== StatusPageEventType.Announcement // announcements dont have resources
|
|
568
689
|
) {
|
|
690
|
+
logger.debug(
|
|
691
|
+
"Subscriber can choose resources and is not subscribed to all resources.",
|
|
692
|
+
);
|
|
569
693
|
const subscriberResourceIds: Array<string> =
|
|
570
694
|
data.subscriber.statusPageResources?.map(
|
|
571
695
|
(resource: StatusPageResource) => {
|
|
@@ -573,21 +697,27 @@ export class Service extends DatabaseService<Model> {
|
|
|
573
697
|
},
|
|
574
698
|
) || [];
|
|
575
699
|
|
|
700
|
+
logger.debug(`Subscriber Resource IDs: ${subscriberResourceIds}`);
|
|
701
|
+
|
|
576
702
|
let shouldSendNotificationForResource: boolean = false;
|
|
577
703
|
|
|
578
704
|
if (subscriberResourceIds.length === 0) {
|
|
705
|
+
logger.debug("Subscriber has no resource IDs.");
|
|
579
706
|
shouldSendNotificationForResource = false;
|
|
580
707
|
} else {
|
|
581
708
|
for (const resource of data.statusPageResources) {
|
|
709
|
+
logger.debug(`Checking resource: ${resource.id}`);
|
|
582
710
|
if (
|
|
583
711
|
subscriberResourceIds.includes(resource.id?.toString() as string)
|
|
584
712
|
) {
|
|
713
|
+
logger.debug("Resource ID matches subscriber's resource ID.");
|
|
585
714
|
shouldSendNotificationForResource = true;
|
|
586
715
|
}
|
|
587
716
|
}
|
|
588
717
|
}
|
|
589
718
|
|
|
590
719
|
if (!shouldSendNotificationForResource) {
|
|
720
|
+
logger.debug("Should not send notification for resource.");
|
|
591
721
|
shouldSendNotification = false;
|
|
592
722
|
}
|
|
593
723
|
}
|
|
@@ -598,27 +728,40 @@ export class Service extends DatabaseService<Model> {
|
|
|
598
728
|
data.statusPage.allowSubscribersToChooseEventTypes &&
|
|
599
729
|
!data.subscriber.isSubscribedToAllEventTypes
|
|
600
730
|
) {
|
|
731
|
+
logger.debug(
|
|
732
|
+
"Subscriber can choose event types and is not subscribed to all event types.",
|
|
733
|
+
);
|
|
601
734
|
const subscriberEventTypes: Array<StatusPageEventType> =
|
|
602
735
|
data.subscriber.statusPageEventTypes || [];
|
|
603
736
|
|
|
737
|
+
logger.debug(`Subscriber Event Types: ${subscriberEventTypes}`);
|
|
738
|
+
|
|
604
739
|
let shouldSendNotificationForEventType: boolean = false;
|
|
605
740
|
|
|
606
741
|
if (subscriberEventTypes.includes(data.eventType)) {
|
|
742
|
+
logger.debug("Event type matches subscriber's event type.");
|
|
607
743
|
shouldSendNotificationForEventType = true;
|
|
608
744
|
}
|
|
609
745
|
|
|
610
746
|
if (!shouldSendNotificationForEventType) {
|
|
747
|
+
logger.debug("Should not send notification for event type.");
|
|
611
748
|
shouldSendNotification = false;
|
|
612
749
|
}
|
|
613
750
|
}
|
|
614
751
|
|
|
752
|
+
logger.debug(
|
|
753
|
+
`Final decision on shouldSendNotification: ${shouldSendNotification}`,
|
|
754
|
+
);
|
|
615
755
|
return shouldSendNotification;
|
|
616
756
|
}
|
|
617
757
|
|
|
618
758
|
public async getStatusPagesToSendNotification(
|
|
619
759
|
statusPageIds: Array<ObjectID>,
|
|
620
760
|
): Promise<Array<StatusPage>> {
|
|
621
|
-
|
|
761
|
+
logger.debug("getStatusPagesToSendNotification called with statusPageIds:");
|
|
762
|
+
logger.debug(statusPageIds);
|
|
763
|
+
|
|
764
|
+
const statusPages: Array<StatusPage> = await StatusPageService.findBy({
|
|
622
765
|
query: {
|
|
623
766
|
_id: QueryHelper.any(statusPageIds),
|
|
624
767
|
},
|
|
@@ -659,6 +802,11 @@ export class Service extends DatabaseService<Model> {
|
|
|
659
802
|
isReportEnabled: true,
|
|
660
803
|
},
|
|
661
804
|
});
|
|
805
|
+
|
|
806
|
+
logger.debug("Found status pages:");
|
|
807
|
+
logger.debug(statusPages);
|
|
808
|
+
|
|
809
|
+
return statusPages;
|
|
662
810
|
}
|
|
663
811
|
}
|
|
664
812
|
export default new Service();
|