-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: on delete cascade * feat: status page form danger section * chore: add badge to quick actions * ci: apply automated fixes * fix: export * chore: link email templates * fix: lint * chore: remove workflows api route * fix: int64 * fix: go --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
8412ca5
commit 1af6c3e
Showing
47 changed files
with
454 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ export class MemoryCache { | |
} | ||
} | ||
|
||
const cache = new MemoryCache(); | ||
const _cache = new MemoryCache(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,15 @@ import { | |
statusReport, | ||
statusReportUpdate, | ||
} from "@openstatus/db/src/schema"; | ||
import { sendEmailHtml } from "@openstatus/emails"; | ||
|
||
import { env } from "@/env"; | ||
import { OpenStatusApiError, openApiErrorResponses } from "@/libs/errors"; | ||
import { EmailClient } from "@openstatus/emails"; | ||
import type { statusReportUpdatesApi } from "./index"; | ||
import { StatusReportUpdateSchema } from "./schema"; | ||
|
||
const emailClient = new EmailClient({ apiKey: env.RESEND_API_KEY }); | ||
|
||
const createStatusUpdate = createRoute({ | ||
method: "post", | ||
tags: ["status_report_update"], | ||
|
@@ -89,21 +92,27 @@ export function registerPostStatusReportUpdate( | |
) | ||
.all(); | ||
|
||
const pageInfo = await db | ||
.select() | ||
.from(page) | ||
.where(eq(page.id, _statusReport.pageId)) | ||
.get(); | ||
if (pageInfo) { | ||
const subscribersEmails = subscribers.map((subscriber) => ({ | ||
to: subscriber.email, | ||
subject: `New status update for ${pageInfo.title}`, | ||
html: `<p>Hi,</p><p>${pageInfo.title} just posted an update on their status page:</p><p>New Status : ${statusReportUpdate.status}</p><p>${statusReportUpdate.message}</p></p><p></p><p>Powered by OpenStatus</p><p></p><p></p><p></p><p></p><p></p> | ||
`, | ||
from: "Notification OpenStatus <[email protected]>", | ||
})); | ||
const _page = await db.query.page.findFirst({ | ||
where: eq(page.id, _statusReport.pageId), | ||
with: { | ||
monitorsToPages: { | ||
with: { | ||
monitor: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await sendEmailHtml(subscribersEmails); | ||
if (_page && subscribers.length > 0) { | ||
await emailClient.sendStatusReportUpdate({ | ||
to: subscribers.map((subscriber) => subscriber.email), | ||
pageTitle: _page.title, | ||
reportTitle: _statusReport.title, | ||
status: _statusReport.status, | ||
message: _statusReportUpdate.message, | ||
date: _statusReportUpdate.date.toISOString(), | ||
monitors: _page.monitorsToPages.map((i) => i.monitor.name), | ||
}); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,14 @@ import { | |
statusReportUpdate, | ||
} from "@openstatus/db/src/schema"; | ||
|
||
import { env } from "@/env"; | ||
import { OpenStatusApiError, openApiErrorResponses } from "@/libs/errors"; | ||
import { sendBatchEmailHtml } from "@openstatus/emails/src/send"; | ||
import { EmailClient } from "@openstatus/emails"; | ||
import type { statusReportsApi } from "./index"; | ||
import { StatusReportSchema } from "./schema"; | ||
|
||
const emailClient = new EmailClient({ apiKey: env.RESEND_API_KEY }); | ||
|
||
const postRoute = createRoute({ | ||
method: "post", | ||
tags: ["status_report"], | ||
|
@@ -142,24 +145,27 @@ export function registerPostStatusReport(api: typeof statusReportsApi) { | |
) | ||
.all(); | ||
|
||
const pageInfo = await db | ||
.select() | ||
.from(page) | ||
.where(eq(page.id, _newStatusReport.pageId)) | ||
.get(); | ||
|
||
if (pageInfo) { | ||
const emails = subscribers.map((subscriber) => { | ||
return { | ||
to: subscriber.email, | ||
subject: `New status update for ${pageInfo.title}`, | ||
html: `<p>Hi,</p><p>${pageInfo.title} just posted an update on their status page:</p><p>New Status : ${statusReportUpdate.status}</p><p>${statusReportUpdate.message}</p></p><p></p><p>Powered by OpenStatus</p><p></p><p></p><p></p><p></p><p></p> | ||
`, | ||
from: "Notification OpenStatus <[email protected]>", | ||
}; | ||
}); | ||
const pageInfo = await db.query.page.findFirst({ | ||
where: eq(page.id, _newStatusReport.pageId), | ||
with: { | ||
monitorsToPages: { | ||
with: { | ||
monitor: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
await sendBatchEmailHtml(emails); | ||
if (pageInfo && subscribers.length > 0) { | ||
await emailClient.sendStatusReportUpdate({ | ||
to: subscribers.map((subscriber) => subscriber.email), | ||
pageTitle: pageInfo.title, | ||
reportTitle: _newStatusReport.title, | ||
status: _newStatusReport.status, | ||
message: _newStatusReportUpdate.message, | ||
date: _newStatusReportUpdate.date.toISOString(), | ||
monitors: pageInfo.monitorsToPages.map((i) => i.monitor.name), | ||
}); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.