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.

Improve `isGenericEmail` flag (#3597)

Steven Tey94205fabe5fb
diff --git a/apps/web/lib/actions/partners/start-partner-platform-verification.ts b/apps/web/lib/actions/partners/start-partner-platform-verification.ts
index e41d85ea27..c167742ae2 100644
--- a/apps/web/lib/actions/partners/start-partner-platform-verification.ts
+++ b/apps/web/lib/actions/partners/start-partner-platform-verification.ts
@@ -7,7 +7,8 @@ import {
import { PARTNER_PLATFORMS_PROVIDERS } from "@/lib/api/partner-profile/partner-platforms-providers";
import { upsertPartnerPlatform } from "@/lib/api/partner-profile/upsert-partner-platform";
import { generateOTP } from "@/lib/auth/utils";
-import { GENERIC_EMAIL_DOMAINS } from "@/lib/is-generic-email";
+import { extractEmailDomain } from "@/lib/email/extract-email-domain";
+import { isGenericEmail } from "@/lib/is-generic-email";
import {
sanitizeSocialHandle,
SOCIAL_PLATFORM_CONFIGS,
@@ -100,7 +101,7 @@ async function startWebsiteVerification({
| Extract<VerificationResult, { type: "auto_verified" }>
> {
const websiteDomain = getDomainWithoutWWW(handle)?.toLowerCase();
- const emailDomain = partner.email?.split("@")[1]?.toLowerCase();
+ const emailDomain = extractEmailDomain(partner.email!);
if (websiteDomain && emailDomain) {
const isDisposableEmailDomain = await redis.sismember(
@@ -112,7 +113,7 @@ async function startWebsiteVerification({
// - is not a disposable email domain
// - matches the website domain exactly
if (
- !GENERIC_EMAIL_DOMAINS.includes(emailDomain) &&
+ !isGenericEmail(partner.email!) &&
!isDisposableEmailDomain &&
emailDomain === websiteDomain
) {
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 d2a48a801c..bbdbb02f70 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
@@ -1,9 +1,10 @@
+import { extractEmailDomain } from "@/lib/email/extract-email-domain";
import { isGenericEmail } from "@/lib/is-generic-email";
import { FraudEventContext } from "@/lib/types";
import { CustomerEmailMatchType } from "@/lib/zod/schemas/fraud";
import { prisma } from "@dub/prisma";
import { defineFraudRule } from "../define-fraud-rule";
-import { extractEmailDomain, normalizeEmail } from "../utils";
+import { normalizeEmail } from "../utils";
// Partner's email matches a customer's email, shares the same email domain,
// or the customer's domain matches a previously referred customer.
diff --git a/apps/web/lib/api/fraud/rules/check-customer-email-suspicious.ts b/apps/web/lib/api/fraud/rules/check-customer-email-suspicious.ts
index 3090acb913..285e09e265 100644
--- a/apps/web/lib/api/fraud/rules/check-customer-email-suspicious.ts
+++ b/apps/web/lib/api/fraud/rules/check-customer-email-suspicious.ts
@@ -1,7 +1,7 @@
+import { extractEmailDomain } from "@/lib/email/extract-email-domain";
import { FraudEventContext } from "@/lib/types";
import { redis } from "@/lib/upstash/redis";
import { defineFraudRule } from "../define-fraud-rule";
-import { extractEmailDomain } from "../utils";
export const checkCustomerEmailSuspicious = defineFraudRule({
type: "customerEmailSuspiciousDomain",
diff --git a/apps/web/lib/api/fraud/rules/check-partner-email-masked.ts b/apps/web/lib/api/fraud/rules/check-partner-email-masked.ts
index 4d7f180963..9c896e2945 100644
--- a/apps/web/lib/api/fraud/rules/check-partner-email-masked.ts
+++ b/apps/web/lib/api/fraud/rules/check-partner-email-masked.ts
@@ -1,5 +1,5 @@
+import { extractEmailDomain } from "@/lib/email/extract-email-domain";
import { PartnerProps } from "@/lib/types";
-import { extractEmailDomain } from "../utils";
// Checks if the partner is using an Apple private relay email address
export function checkPartnerEmailMasked(partner: Pick<PartnerProps, "email">) {
diff --git a/apps/web/lib/api/fraud/utils.ts b/apps/web/lib/api/fraud/utils.ts
index 52abbb1564..4369f9ebaf 100644
--- a/apps/web/lib/api/fraud/utils.ts
+++ b/apps/web/lib/api/fraud/utils.ts
@@ -16,17 +16,6 @@ type GetIdentityFieldsForFraudEventInput = Pick<
"type" | "partnerId" | "customerId" | "sourceProgramId" | "metadata"
>;
-// Extract domain from email
-export function extractEmailDomain(email: string) {
- const parts = email.toLowerCase().trim().split("@");
-
- if (parts.length !== 2 || !parts[0] || !parts[1]) {
- return null;
- }
-
- return parts[1];
-}
-
// Normalize email for comparison
export function normalizeEmail(email: string) {
const trimmed = email.toLowerCase().trim();
diff --git a/apps/web/lib/email/extract-email-domain.ts b/apps/web/lib/email/extract-email-domain.ts
new file mode 100644
index 0000000000..80389ff9dc
--- /dev/null
+++ b/apps/web/lib/email/extract-email-domain.ts
@@ -0,0 +1,10 @@
+// Extract domain from email
+export function extractEmailDomain(email: string) {
+ const parts = email.toLowerCase().trim().split("@");
+
+ if (parts.length !== 2 || !parts[0] || !parts[1]) {
+ return null;
+ }
+
+ return parts[1];
+}
diff --git a/apps/web/lib/is-generic-email.ts b/apps/web/lib/is-generic-email.ts
index 917787c3dc..51bb03da08 100644
--- a/apps/web/lib/is-generic-email.ts
+++ b/apps/web/lib/is-generic-email.ts
@@ -1,14 +1,9 @@
-export const GENERIC_EMAIL_DOMAINS = [
+import { extractEmailDomain } from "./email/extract-email-domain";
+
+const GENERIC_EMAIL_DOMAINS = [
"gmail.com",
"googlemail.com",
- "yahoo.com",
- "yahoo.co.uk",
- "yahoo.co.jp",
- "yahoo.fr",
- "yahoo.de",
- "hotmail.com",
- "hotmail.co.uk",
- "outlook.com",
+ "ymail.com",
"icloud.com",
"aol.com",
"comcast.net",
@@ -18,22 +13,42 @@ export const GENERIC_EMAIL_DOMAINS = [
"mac.com",
"msn.com",
"live.com",
+ "web.de",
"protonmail.com",
"proton.me",
+ "passinbox.com",
+ "163.com",
+ "duck.com",
+ "qq.com",
"zoho.com",
- "yandex.com",
- "yandex.ru",
- "mail.com",
- "mail.ru",
- "gmx.com",
- "gmx.net",
"fastmail.com",
"tutanota.com",
"tuta.com",
"privaterelay.appleid.com",
+ "qyver.online",
+ "naver.com",
+ "yeah.net",
"example.com",
];
+const GENERIC_EMAIL_DOMAIN_PREFIXES = [
+ "yahoo.",
+ "hotmail.",
+ "outlook.",
+ "gmx.",
+ "yandex.",
+];
+
export const isGenericEmail = (email: string) => {
- return GENERIC_EMAIL_DOMAINS.some((domain) => email.endsWith(`@${domain}`));
+ const emailDomain = extractEmailDomain(email);
+ if (!emailDomain) {
+ return false;
+ }
+
+ return (
+ GENERIC_EMAIL_DOMAINS.includes(emailDomain) ||
+ GENERIC_EMAIL_DOMAIN_PREFIXES.some((prefix) =>
+ emailDomain.startsWith(prefix),
+ )
+ );
};
diff --git a/apps/web/scripts/migrations/backfill-plain-customers.ts b/apps/web/scripts/migrations/backfill-plain-customers.ts
index fdcde718f2..c9f86b82fc 100644
--- a/apps/web/scripts/migrations/backfill-plain-customers.ts
+++ b/apps/web/scripts/migrations/backfill-plain-customers.ts
@@ -1,4 +1,3 @@
-import { GENERIC_EMAIL_DOMAINS } from "@/lib/is-generic-email";
import { prisma } from "@dub/prisma";
import { chunk } from "@dub/utils";
import "dotenv-flow/config";
@@ -12,11 +11,11 @@ async function main() {
email: true,
},
where: {
- NOT: GENERIC_EMAIL_DOMAINS.map((domain) => ({
- email: {
- endsWith: `@${domain}`,
- },
- })),
+ // NOT: GENERIC_EMAIL_DOMAINS.map((domain) => ({
+ // email: {
+ // endsWith: `@${domain}`,
+ // },
+ // })),
projects: {
some: {
project: {
diff --git a/apps/web/scripts/misc/cleanup-fraud-events.ts b/apps/web/scripts/misc/cleanup-fraud-events.ts
index 729729b9f7..975ad17acb 100644
--- a/apps/web/scripts/misc/cleanup-fraud-events.ts
+++ b/apps/web/scripts/misc/cleanup-fraud-events.ts
@@ -19,11 +19,12 @@ async function main() {
},
},
},
- select: {
- id: true,
+ include: {
+ partner: true,
+ customer: true,
fraudEventGroup: {
select: {
- id: true,
+ program: true,
},
},
},
@@ -32,7 +33,15 @@ async function main() {
},
});
- console.table(fraudEvents);
+ console.table(
+ fraudEvents.map((event) => ({
+ id: event.id,
+ program: event.fraudEventGroup?.program?.name,
+ partner: event.partner?.email,
+ customer: event.customer?.email,
+ createdAt: event.createdAt,
+ })),
+ );
// Remove fraud events
if (fraudEvents.length > 0) {
diff --git a/apps/web/scripts/misc/cleanup-generic-email-fraud-events.ts b/apps/web/scripts/misc/cleanup-generic-email-fraud-events.ts
new file mode 100644
index 0000000000..df8bb695cb
--- /dev/null
+++ b/apps/web/scripts/misc/cleanup-generic-email-fraud-events.ts
@@ -0,0 +1,99 @@
+import "dotenv-flow/config";
+
+import { isGenericEmail } from "@/lib/is-generic-email";
+import { prisma } from "@dub/prisma";
+
+async function main() {
+ let fraudEvents = await prisma.fraudEvent.findMany({
+ where: {
+ fraudEventGroup: {
+ type: "customerEmailMatch",
+ resolvedAt: null,
+ },
+ OR: [
+ {
+ metadata: {
+ path: "$.matchType",
+ equals: "domainMatch",
+ },
+ },
+ {
+ metadata: {
+ path: "$.matchType",
+ equals: "historicalDomainMatch",
+ },
+ },
+ ],
+ },
+ include: {
+ partner: true,
+ customer: true,
+ fraudEventGroup: {
+ select: {
+ program: true,
+ },
+ },
+ },
+ orderBy: {
+ createdAt: "desc",
+ },
+ });
+
+ // Find fraud events with generic email
+ fraudEvents = fraudEvents.filter(
+ (event) => event.customer?.email && isGenericEmail(event.customer.email),
+ );
+
+ console.table(
+ fraudEvents.map((event) => ({
+ id: event.id,
+ program: event.fraudEventGroup?.program?.name,
+ partner: event.partner?.email,
+ customer: event.customer?.email,
+ createdAt: event.createdAt,
+ })),
+ );
+
+ // Remove fraud events
+ if (fraudEvents.length > 0) {
+ const { count } = await prisma.fraudEvent.deleteMany({
+ where: {
+ id: {
+ in: fraudEvents.map((event) => event.id),
+ },
+ },
+ });
+
+ console.log(`Removed ${count} fraud events`);
+ }
+
+ // Find fraud event groups with no events left
+ const fraudEventGroupsWithNoEvents = await prisma.fraudEventGroup.findMany({
+ where: {
+ fraudEvents: {
+ none: {},
+ },
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ console.log(
+ `Found ${fraudEventGroupsWithNoEvents.length} with no events left.`,
+ );
+
+ if (fraudEventGroupsWithNoEvents.length > 0) {
+ const { count } = await prisma.fraudEventGroup.deleteMany({
+ where: {
+ id: {
+ in: fraudEventGroupsWithNoEvents.map((group) => group.id),
+ },
+ },
+ });
+
+ console.log(`Removed ${count} fraud event groups`);
+ }
+}
+
+main();
diff --git a/apps/web/tests/fraud/index.test.ts b/apps/web/tests/fraud/index.test.ts
index 5c77358350..831c7f9a3e 100644
--- a/apps/web/tests/fraud/index.test.ts
+++ b/apps/web/tests/fraud/index.test.ts
@@ -1,4 +1,4 @@
-import { extractEmailDomain } from "@/lib/api/fraud/utils";
+import { extractEmailDomain } from "@/lib/email/extract-email-domain";
import { Customer, TrackLeadResponse } from "@/lib/types";
import {
CustomerEmailMatchType,
diff --git a/packages/email/src/templates/broadcasts/stablecoin-payouts-announcement.tsx b/packages/email/src/templates/broadcasts/stablecoin-payouts-announcement.tsx
index 9210148afb..9f179c7032 100644
--- a/packages/email/src/templates/broadcasts/stablecoin-payouts-announcement.tsx
+++ b/packages/email/src/templates/broadcasts/stablecoin-payouts-announcement.tsx
@@ -4,6 +4,7 @@ import {
Container,
Head,
Heading,
+ Hr,
Html,
Img,
Link,
@@ -108,6 +109,57 @@ export default function StablecoinPayoutsAnnouncement({
</Link>
</Section>
+ <Hr className="mx-0 my-6 w-full border border-neutral-200" />
+
+ <Section className="mb-8 text-center">
+ <Link
+ href="https://ship.dub.co/marketplace"
+ style={{ textDecoration: "none" }}
+ >
+ <Img
+ src="https://assets.dub.co/misc/program-marketplace-email-header.jpg"
+ width="500"
+ height="292"
+ alt="Dub Program Marketplace"
+ style={{
+ display: "block",
+ maxWidth: "100%",
+ height: "auto",
+ margin: "0 auto",
+ }}
+ />
+ </Link>
+ </Section>
+
+ <Heading className="mx-0 mb-3 mt-0 p-0 text-center text-lg font-semibold text-black">
+ Dub Program Marketplace is now generally available
+ </Heading>
+
+ <Text className="mx-auto mb-8 mt-0 max-w-[420px] text-center text-sm leading-6 text-neutral-600">
+ Find programs that fit your audience, compare rewards, and submit
+ your application. It is the easiest way to expand your reach and
+ unlock new earning possibilities.
+ </Text>
+
+ <Section className="mb-8 text-center">
+ <Link
+ href="https://ship.dub.co/marketplace"
+ className="box-border inline-block rounded-lg bg-neutral-900 px-6 py-3 text-center text-sm font-medium text-white no-underline"
+ style={{
+ backgroundColor: "#171717",
+ color: "#ffffff",
+ borderRadius: "8px",
+ padding: "12px 24px",
+ textDecoration: "none",
+ display: "inline-block",
+ fontWeight: "500",
+ fontSize: "14px",
+ }}
+ >
+ Explore the program marketplace
+ </Link>
+ </Section>
+
<Section className="mx-auto max-w-[400px] text-center">
<Footer email={email} marketing unsubscribeUrl={unsubscribeUrl} />
</Section>