Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+56
@@ -0,0 +1,56 @@
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
|
||||
import { recordAdminEmailEvent } from "@hivegrid/db/admin-email-events.server";
|
||||
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
|
||||
import {
|
||||
hashAdminEmailTrackingToken,
|
||||
verifyAdminEmailTrackingToken,
|
||||
} from "@hivegrid/integrations/admin-email-tracking";
|
||||
import { createScopedLogger } from "~/utils/logger.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { getTranslations } from "~/locale/i18next.server";
|
||||
|
||||
const log = createScopedLogger("admin-email.tracking.click");
|
||||
|
||||
export async function loader({ params, request }: LoaderFunctionArgs) {
|
||||
const scheduledEmailId = params.scheduledEmailId ?? "";
|
||||
const token = new URL(request.url).searchParams.get("t");
|
||||
const claims = verifyAdminEmailTrackingToken({
|
||||
token,
|
||||
scheduledEmailId,
|
||||
kind: "click",
|
||||
secret: process.env.MARKETING_TOKEN_SECRET ?? "",
|
||||
});
|
||||
if (!claims?.destinationUrl || !token) {
|
||||
const { t } = await getTranslations(request);
|
||||
return new Response(t("mail:tracking.invalidOrExpiredLink"), { status: 400 });
|
||||
}
|
||||
try {
|
||||
await runWithRlsContext({ userId: claims.adminUserId }, () =>
|
||||
recordAdminEmailEvent(db, {
|
||||
adminUserId: claims.adminUserId,
|
||||
scheduledEmailId,
|
||||
type: "clicked",
|
||||
eventKey: hashAdminEmailTrackingToken(token),
|
||||
trackingTokenHash: hashAdminEmailTrackingToken(token),
|
||||
occurredAt: new Date(),
|
||||
})
|
||||
);
|
||||
} catch (error) {
|
||||
log.error(
|
||||
{
|
||||
scheduledEmailId,
|
||||
errorName: error instanceof Error ? error.name : "UnknownError",
|
||||
},
|
||||
"admin email click tracking failed"
|
||||
);
|
||||
}
|
||||
return new Response(null, {
|
||||
status: 302,
|
||||
headers: {
|
||||
Location: claims.destinationUrl,
|
||||
"Cache-Control": "no-store",
|
||||
"Referrer-Policy": "no-referrer",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user