feat: add daily email usage (#97)

* add daily email usage

* remove console
This commit is contained in:
KM Koushik
2025-02-02 07:57:49 +11:00
committed by GitHub
parent 6b9696e715
commit f60c66acbe
9 changed files with 283 additions and 158 deletions

View File

@@ -1,5 +1,5 @@
import { db } from "~/server/db";
import { parseSesHook } from "~/server/service/ses-hook-parser";
import { parseSesHook, SesHookParser } from "~/server/service/ses-hook-parser";
import { SesSettingsService } from "~/server/service/ses-settings-service";
import { SnsNotificationMessage } from "~/types/aws-types";
@@ -16,7 +16,7 @@ export async function POST(req: Request) {
const isEventValid = await checkEventValidity(data);
console.log("isEventValid: ", isEventValid);
console.log("Is event valid: ", isEventValid);
if (!isEventValid) {
return Response.json({ data: "Event is not valid" });
@@ -30,7 +30,10 @@ export async function POST(req: Request) {
try {
message = JSON.parse(data.Message || "{}");
const status = await parseSesHook(message);
const status = await SesHookParser.queue({
event: message,
messageId: data.MessageId,
});
console.log("Error is parsing hook", !status);
if (!status) {
return Response.json({ data: "Error is parsing hook" });
@@ -43,6 +46,9 @@ export async function POST(req: Request) {
}
}
/**
* Handles the subscription confirmation event. called only once for a webhook
*/
async function handleSubscription(message: any) {
await fetch(message.SubscribeURL, {
method: "GET",
@@ -73,7 +79,9 @@ async function handleSubscription(message: any) {
return Response.json({ data: "Success" });
}
// A simple check to ensure that the event is from the correct topic
/**
* A simple check to ensure that the event is from the correct topic
*/
async function checkEventValidity(message: SnsNotificationMessage) {
const { TopicArn } = message;
const configuredTopicArn = await SesSettingsService.getTopicArns();