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
+13
-5
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* AK-P14a · P14 Email — open-tracking pixel.
|
||||
*
|
||||
* GET /e/o/:outboundEmailId
|
||||
* GET /e/o/:outboundEmailId?t=<stored-tracking-token>
|
||||
*
|
||||
* Returns a 1x1 transparent GIF and records an OutboundEmailOpen (the first open
|
||||
* of an email is flagged). Unauthenticated — it is fetched by the recipient's
|
||||
@@ -16,8 +16,10 @@
|
||||
import type { LoaderFunctionArgs } from "react-router";
|
||||
|
||||
import { anonymizeTrackingIp, recordEmailOpen } from "@hivegrid/db/email-tracking.server";
|
||||
import { resolveOutboundEmailOpenRlsIdentity } from "@hivegrid/db/rls-resolvers.server";
|
||||
import { runWithRlsContext } from "@hivegrid/db/rls-context.server";
|
||||
import { db } from "~/utils/db.server";
|
||||
import { getClientIPAddress } from "~/utils/server/IpUtils";
|
||||
import { getTrustedClientIpOrNull } from "~/utils/server/IpUtils";
|
||||
import { createScopedLogger } from "~/utils/logger.server";
|
||||
|
||||
const log = createScopedLogger("email.tracking.open");
|
||||
@@ -39,10 +41,16 @@ function pixelResponse(): Response {
|
||||
|
||||
export async function loader({ params, request }: LoaderFunctionArgs) {
|
||||
const outboundEmailId = params.outboundEmailId;
|
||||
if (outboundEmailId) {
|
||||
const trackingToken = new URL(request.url).searchParams.get("t");
|
||||
if (outboundEmailId && trackingToken) {
|
||||
try {
|
||||
const ipHash = anonymizeTrackingIp(getClientIPAddress(request));
|
||||
await recordEmailOpen({ outboundEmailId, ipHash }, db as never);
|
||||
const identity = await resolveOutboundEmailOpenRlsIdentity(outboundEmailId, trackingToken);
|
||||
if (identity) {
|
||||
const ipHash = anonymizeTrackingIp(getTrustedClientIpOrNull(request));
|
||||
await runWithRlsContext({ tenantId: identity.tenantId }, () =>
|
||||
recordEmailOpen({ tenantId: identity.tenantId, outboundEmailId: identity.resourceId, ipHash }, db as never)
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
// Tracking must never break pixel delivery.
|
||||
log.error({ outboundEmailId, err: error instanceof Error ? error.message : String(error) }, "email open tracking failed");
|
||||
|
||||
Reference in new issue
Block a user