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.

Remove cron guard (cleanup/expired-fraud-groups)

Steven Teye70414577e34
diff --git a/apps/web/app/(ee)/api/cron/cleanup/expired-fraud-groups/route.ts b/apps/web/app/(ee)/api/cron/cleanup/expired-fraud-groups/route.ts
index fa2e888630..12aae35655 100644
--- a/apps/web/app/(ee)/api/cron/cleanup/expired-fraud-groups/route.ts
+++ b/apps/web/app/(ee)/api/cron/cleanup/expired-fraud-groups/route.ts
@@ -12,12 +12,6 @@ const BATCH_SIZE = 250;
// Runs once every day at 02:30:00 AM UTC (30 2 * * *)
// POST /api/cron/cleanup/expired-fraud-groups
export const POST = withCron(async () => {
- // TODO: remove this after July 9th, 2026
- // skip cron if it's before July 9th, 2026
- if (new Date() < new Date("2026-07-09")) {
- return logAndRespond("Skipping cron because it's before July 9th, 2026.");
- }
-
let expiredCount = 0;
while (true) {
const { count } = await prisma.fraudEventGroup.updateMany({
diff --git a/apps/web/lib/email/email-templates-map.ts b/apps/web/lib/email/email-templates-map.ts
index fb2ccc9f25..674b007fb9 100644
--- a/apps/web/lib/email/email-templates-map.ts
+++ b/apps/web/lib/email/email-templates-map.ts
@@ -1,7 +1,6 @@
import BountyApproved from "@dub/email/templates/bounty-approved";
import IdentityVerificationAnnouncement from "@dub/email/templates/broadcasts/identity-verification-announcement";
import DubLaunchWeekDay5 from "@dub/email/templates/broadcasts/launch-week-day-5";
-import RiskCenterChangeAnnouncement from "@dub/email/templates/broadcasts/risk-center-change-announcement";
import ConnectPayoutReminder from "@dub/email/templates/connect-payout-reminder";
import ConnectPlatformsReminder from "@dub/email/templates/connect-platforms-reminder";
import PartnerBanned from "@dub/email/templates/partner-banned";
@@ -34,5 +33,4 @@ export const EMAIL_TEMPLATES_MAP = {
// ProgramMarketplaceAnnouncement,
// StablecoinPayoutsAnnouncement,
DubLaunchWeekDay5,
- RiskCenterChangeAnnouncement,
} as const;
diff --git a/apps/web/scripts/send-risk-center-change-announcement.ts b/apps/web/scripts/send-risk-center-change-announcement.ts
deleted file mode 100644
index db69a0e828..0000000000
--- a/apps/web/scripts/send-risk-center-change-announcement.ts
+++ /dev/null
@@ -1,152 +0,0 @@
-import "dotenv-flow/config";
-
-import { prisma } from "@/lib/prisma";
-import type RiskCenterChangeAnnouncement from "@dub/email/templates/broadcasts/risk-center-change-announcement";
-import { FRAUD_RULES_BY_TYPE } from "../lib/api/fraud/constants";
-import { queueBatchEmail } from "../lib/email/queue-batch-email";
-
-const BATCH_SIZE = 50;
-
-async function main() {
- let cursor: string | undefined;
-
- while (true) {
- const programs = await prisma.program.findMany({
- where: {
- workspace: {
- plan: {
- in: ["advanced", "enterprise"],
- },
- },
- fraudEventGroups: {
- some: {
- status: "pending",
- },
- },
- },
- select: {
- id: true,
- name: true,
- slug: true,
- workspace: {
- select: {
- slug: true,
- users: {
- select: {
- user: {
- select: {
- email: true,
- },
- },
- },
- where: {
- user: {
- isMachine: false,
- email: {
- not: null,
- },
- },
- },
- },
- },
- },
- fraudEventGroups: {
- where: {
- status: "pending",
- },
- select: {
- id: true,
- type: true,
- eventCount: true,
- partner: {
- select: {
- name: true,
- image: true,
- },
- },
- },
- },
- },
- take: BATCH_SIZE,
- ...(cursor && {
- skip: 1,
- cursor: {
- id: cursor,
- },
- }),
- orderBy: {
- id: "asc",
- },
- });
-
- if (programs.length === 0) {
- console.log("No more programs to notify.");
- break;
- }
-
- console.log(`Processing ${programs.length} programs...`);
-
- for (const program of programs) {
- try {
- if (program.fraudEventGroups.length === 0) {
- continue;
- }
-
- const users = program.workspace.users.map(({ user }) => user);
-
- if (users.length === 0) {
- console.log(`No owners found for program ${program.name}, skipping.`);
- continue;
- }
-
- const transformedFraudGroups = program.fraudEventGroups.map(
- ({ id, type, eventCount, partner }) => ({
- id,
- name: FRAUD_RULES_BY_TYPE[type].name,
- count: eventCount,
- partner,
- }),
- );
-
- await queueBatchEmail<typeof RiskCenterChangeAnnouncement>(
- users.map((user) => ({
- to: user.email!,
- subject: `[Action Required]: Review unresolved risk events for ${program.name}`,
- variant: "notifications",
- templateName: "RiskCenterChangeAnnouncement",
- templateProps: {
- email: user.email!,
- workspace: program.workspace,
- program: {
- name: program.name,
- },
- fraudGroups: transformedFraudGroups,
- },
- })),
- {
- idempotencyKey: `risk-center-announcement/${program.id}`,
- },
- );
-
- console.log(
- `Queued emails for program ${program.name} (${users.length} users(s))`,
- );
- } catch (error) {
- console.error(
- `Error sending email for program ${program.name}: ${error.message}`,
- );
- continue;
- }
- }
-
- if (programs.length < BATCH_SIZE) {
- break;
- }
-
- cursor = programs[programs.length - 1].id;
- }
-
- console.log("Done.");
-}
-
-main();
diff --git a/packages/email/src/templates/broadcasts/risk-center-change-announcement.tsx b/packages/email/src/templates/broadcasts/risk-center-change-announcement.tsx
deleted file mode 100644
index bdcf08653b..0000000000
--- a/packages/email/src/templates/broadcasts/risk-center-change-announcement.tsx
+++ /dev/null
@@ -1,236 +0,0 @@
-import { DUB_WORDMARK, OG_AVATAR_URL } from "@dub/utils";
-import {
- Body,
- Column,
- Container,
- Head,
- Heading,
- Html,
- Img,
- Link,
- Preview,
- Row,
- Section,
- Tailwind,
- Text,
-} from "@react-email/components";
-import { Footer } from "../../components/footer";
-
-const MAX_DISPLAYED_GROUPS = 5;
-
-export default function RiskCenterChangeAnnouncement({
- email = "[email protected]",
- workspace = {
- slug: "acme",
- },
- program = {
- name: "Acme",
- },
- fraudGroups = [
- {
- id: "frg_1KBEY53HESGDK7RAPX960FEWA",
- name: "Customer email match",
- count: 2,
- partner: {
- name: "Lauren Anderson",
- image: `${OG_AVATAR_URL}Lauren Anderson`,
- },
- },
- {
- id: "frg_1KBEZRKC1GB716J5AKV62MK8H",
- name: "Referral source",
- count: 1,
- partner: {
- name: "Charlie Anderson",
- image: `${OG_AVATAR_URL}Charlie Anderson`,
- },
- },
- ],
-}: {
- email: string;
- workspace: {
- slug: string;
- };
- program: {
- name: string;
- };
- fraudGroups: {
- id: string;
- name: string;
- count: number;
- partner: {
- name: string;
- image: string | null;
- };
- }[];
-}) {
- const displayedGroups = fraudGroups.slice(0, MAX_DISPLAYED_GROUPS);
- const remainingCount = fraudGroups.length - MAX_DISPLAYED_GROUPS;
- const hiddenCount = Math.max(0, remainingCount);
-
- return (
- <Html>
- <Head>
- <style>{`
- @media only screen and (max-width: 600px) {
- .email-container {
- padding-left: 16px !important;
- padding-right: 16px !important;
- }
- }
- `}</style>
- </Head>
- <Preview>
- Risk events now expire after 30 days if left unresolved, please review
- them before they expire.
- </Preview>
- <Tailwind>
- <Body className="mx-auto my-auto bg-white font-sans">
- <Container className="email-container mx-auto my-10 max-w-[600px] px-10 py-5">
- <Section className="mt-2">
- <Img src={DUB_WORDMARK} height="32" alt="Dub" />
- </Section>
-
- <Heading className="mx-0 mb-2 mt-10 text-xl font-semibold text-black">
- Important updates to your Dub program
- </Heading>
-
- <Text className="text-sm leading-6 text-neutral-600">
- We've made some important changes to the fraud detection tools for
- your <strong className="text-black">{program.name}</strong>{" "}
- program on Dub that we wanted to let you know about.
- </Text>
-
- <Text className="mt-0 text-sm leading-6 text-neutral-600">
- Unresolved risk events will now{" "}
- <strong className="text-black">
- automatically expire after 30 days
- </strong>{" "}
- if no new activity is detected. This is to ensure there are no
- delay in partner payouts due to unresolved risk events.
- </Text>
-
- <Text className="text-sm leading-6 text-neutral-600">
- You currently have pending risk events for your program – please
- review them before they expire:
- </Text>
-
- <Section className="my-6 rounded-xl border border-solid border-neutral-200 bg-white p-0">
- {displayedGroups.map((group, index) => {
- const isLastDisplayedItem =
- index === displayedGroups.length - 1;
- const shouldShowBottomBorder = !isLastDisplayedItem;
- return (
- <Row
- key={group.id}
- className={`border-solid border-neutral-200 ${
- shouldShowBottomBorder ? "border-b" : ""
- }`}
- >
- <Column className="px-3 py-3" valign="middle">
- <Row>
- <Column width="32" valign="middle">
- <Img
- src={
- group.partner.image ||
- `${OG_AVATAR_URL}${group.partner.name}`
- }
- width={32}
- height={32}
- alt={group.partner.name}
- className="rounded-full"
- />
- </Column>
-
- <Column className="pl-2 pt-1" valign="middle">
- <Text className="m-0 text-sm font-medium leading-[16px] text-neutral-800">
- {group.partner.name}
- </Text>
-
- <div className="mt-0">
- <span className="m-0 inline text-xs font-medium text-neutral-500">
- {group.name}
- </span>
- {group.count > 1 && (
- <span className="m-0 ml-1 inline rounded-md bg-neutral-100 px-1 py-0 text-xs font-semibold text-neutral-700">
- {group.count}
- </span>
- )}
- </div>
- </Column>
-
- <Column align="right" valign="middle">
- <Link
- className="inline-block rounded-lg border border-solid border-neutral-300 bg-white px-2.5 py-1.5 text-sm font-medium text-neutral-800 no-underline"
- href={`https://app.dub.co/${workspace.slug}/program/risks?groupId=${group.id}`}
- >
- View
- </Link>
- </Column>
- </Row>
- </Column>
- </Row>
- );
- })}
-
- {hiddenCount > 0 && (
- <Row className="h-11 rounded-b-xl border-t border-solid border-neutral-200 bg-neutral-50">
- <Column
- className="px-4"
- align="center"
- valign="middle"
- colSpan={2}
- >
- <Text className="m-0 text-sm font-medium text-neutral-600">
- Plus {hiddenCount} more
- </Text>
- </Column>
- </Row>
- )}
- </Section>
-
- <Text className="mt-0 text-sm leading-6 text-neutral-600">
- To give you more time to review them, we've extended the
- expiration period for all events to July 9th, 2026 (30 days from
- now).
- </Text>
-
- <Text className="mt-0 text-sm leading-6 text-neutral-600">
- Last but not least, the{" "}
- <strong className="text-black">Fraud Detection</strong> tab has
- been renamed to{" "}
- <strong className="text-black">Risk Center</strong>. All existing
- events, rules, and settings remain unchanged – just the names that
- are different.
- </Text>
-
- <Section className="mb-10 mt-4">
- <Link
- href={`https://app.dub.co/${workspace.slug}/program/risks`}
- className="block w-full rounded-lg bg-neutral-900 py-2.5 text-center text-sm font-medium text-white no-underline"
- style={{
- backgroundColor: "#171717",
- color: "#ffffff",
- borderRadius: "8px",
- padding: "10px 16px",
- textDecoration: "none",
- fontWeight: "500",
- fontSize: "14px",
- width: "100%",
- boxSizing: "border-box",
- }}
- >
- Go to Risk Center
- </Link>
- </Section>
-
- <Footer
- email={email}
- notificationSettingsUrl={`https://app.dub.co/${workspace.slug}/settings/notifications`}
- />
- </Container>
- </Body>
- </Tailwind>
- </Html>
- );
-}