Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Only flag similar email matches when the raw emails differ

Kiran K8f107c02ff3e
diff --git a/apps/web/lib/api/fraud/rules/check-customer-email-match.ts b/apps/web/lib/api/fraud/rules/check-customer-email-match.ts
index 205d64eb62..554695e3d7 100644
--- a/apps/web/lib/api/fraud/rules/check-customer-email-match.ts
+++ b/apps/web/lib/api/fraud/rules/check-customer-email-match.ts
@@ -39,7 +39,10 @@ export const checkCustomerEmailMatch = defineFraudRule({
!("isFirstConversion" in customer);
// 2. Similar email match — customer's normalized email matches
- // a previously referred customer from the same partner
+ // a previously referred customer from the same partner.
+ // Require the raw emails to differ so duplicate rows for the same
+ // address (e.g. created by importers or promo-code attribution)
+ // don't trigger; only actual variants do.
if (shouldCheckHistoricalMatch) {
const similarCustomer = await prisma.customer.findFirst({
where: {
@@ -49,6 +52,9 @@ export const checkCustomerEmailMatch = defineFraudRule({
id: {
not: customer.id,
},
+ email: {
+ not: customer.email,
+ },
},
select: {
id: true,
diff --git a/apps/web/tests/fraud/index.test.ts b/apps/web/tests/fraud/index.test.ts
index f3a45ce731..6c1f829f51 100644
--- a/apps/web/tests/fraud/index.test.ts
+++ b/apps/web/tests/fraud/index.test.ts
@@ -1,5 +1,5 @@
import { extractEmailDomain } from "@/lib/email/extract-email-domain";
-import { TrackLeadResponse } from "@/lib/types";
+import { Customer, TrackLeadResponse } from "@/lib/types";
import { CustomerEmailMatchType } from "@/lib/zod/schemas/fraud";
import { randomCustomer, randomId } from "tests/utils/helpers";
import {
@@ -181,6 +181,13 @@ describe.concurrent("/fraud/**", async () => {
});
}
+ const { data: firstCustomers } = await http.get<Customer[]>({
+ path: "/customers",
+ query: { externalId: firstCustomer.externalId },
+ });
+
+ expect(firstCustomers.length).toBe(1);
+
await verifyFraudEvent({
http,
partner: E2E_FRAUD_PARTNER,
@@ -188,7 +195,7 @@ describe.concurrent("/fraud/**", async () => {
ruleType: "customerEmailMatch",
metadata: {
matchType: CustomerEmailMatchType.SIMILAR_EMAIL_MATCH,
- matchedCustomerId: expect.any(String),
+ matchedCustomerId: firstCustomers[0].id,
},
});
});