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.

update scripts

Steven Tey39254f81002e
diff --git a/apps/web/scripts/fix-broken-applications.ts b/apps/web/scripts/fix-broken-applications.ts
new file mode 100644
index 0000000000..daa043ea1f
--- /dev/null
+++ b/apps/web/scripts/fix-broken-applications.ts
@@ -0,0 +1,78 @@
+import { sendBatchEmail } from "@dub/email";
+import NotifyPartnerReapply from "@dub/email/templates/notify-partner-reapply";
+import { prisma } from "@dub/prisma";
+import { chunk, groupBy } from "@dub/utils";
+import "dotenv-flow/config";
+
+async function main() {
+ const pendingProgramEnrollments = await prisma.programEnrollment.findMany({
+ where: {
+ status: "pending",
+ applicationId: {
+ not: null,
+ },
+ },
+ include: {
+ partner: true,
+ program: true,
+ application: true,
+ },
+ });
+
+ const missingApplications = pendingProgramEnrollments.filter(
+ (p) => !p.application,
+ );
+
+ console.log(`Found ${missingApplications.length} missing applications`);
+
+ console.table(
+ missingApplications.map((p) => ({
+ partner: p.partner.email,
+ program: p.program.name,
+ applicationId: p.applicationId,
+ createdAt: p.createdAt,
+ })),
+ );
+
+ const missingApplicationsByPartner = Object.entries(
+ groupBy(missingApplications, (p) => p.partnerId),
+ ).map(([_partnerId, enrollments]) => ({
+ partner: {
+ name: enrollments[0].partner.name,
+ email: enrollments[0].partner.email!,
+ },
+ programs: enrollments.map((e) => ({
+ name: e.program.name,
+ slug: e.program.slug,
+ logo: e.program.logo!,
+ })),
+ }));
+
+ const chunks = chunk(missingApplicationsByPartner, 100);
+
+ for (const chunk of chunks) {
+ await sendBatchEmail(
+ chunk.map((p) => ({
+ subject: "Please resubmit your applications to these programs",
+ to: p.partner.email,
+ replyTo: "[email protected]",
+ react: NotifyPartnerReapply({
+ partner: p.partner,
+ programs: p.programs,
+ }),
+ })),
+ );
+ }
+
+ const res = await prisma.programEnrollment.deleteMany({
+ where: {
+ id: {
+ in: missingApplications.map((p) => p.id),
+ },
+ },
+ });
+
+ console.log("Deleted program enrollments", res);
+}
+
+main();
diff --git a/apps/web/scripts/programs/backfill-custom-commissions.ts b/apps/web/scripts/programs/backfill-custom-commissions.ts
new file mode 100644
index 0000000000..156fac36f4
--- /dev/null
+++ b/apps/web/scripts/programs/backfill-custom-commissions.ts
@@ -0,0 +1,73 @@
+import { createId } from "@/lib/api/create-id";
+import { prisma } from "@dub/prisma";
+import { Prisma } from "@dub/prisma/client";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+import { syncTotalCommissions } from "../../lib/api/partners/sync-total-commissions";
+
+const commissionsToBackfill: {
+ partnerId: string;
+ commissionAmount: number;
+ createdAt: Date;
+}[] = [];
+
+const programId = "prog_xxx";
+
+async function main() {
+ Papa.parse(fs.createReadStream("custom_commissions.csv", "utf-8"), {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: {
+ data: {
+ partner_id: string;
+ total_commission: string;
+ created_at: string;
+ };
+ }) => {
+ commissionsToBackfill.push({
+ partnerId: result.data.partner_id,
+ commissionAmount: parseInt(result.data.total_commission) * 100,
+ createdAt: new Date(result.data.created_at),
+ });
+ },
+ complete: async () => {
+ console.log(
+ `Found ${commissionsToBackfill.length} commissions to backfill`,
+ );
+
+ const commissionsToCreate: Prisma.CommissionCreateManyInput[] =
+ commissionsToBackfill.map((commission) => ({
+ id: createId({ prefix: "cm_" }),
+ programId,
+ partnerId: commission.partnerId,
+ type: "custom",
+ quantity: 1,
+ amount: 0,
+ earnings: commission.commissionAmount,
+ createdAt: commission.createdAt,
+ userId: "user_xxx",
+ description: "Commission backfill",
+ }));
+
+ console.table(commissionsToCreate);
+
+ const res = await prisma.commission.createMany({
+ data: commissionsToCreate,
+ skipDuplicates: true,
+ });
+ console.log(`Created ${res.count} commissions`);
+
+ await Promise.all(
+ commissionsToCreate.map(async (commission) => {
+ syncTotalCommissions({
+ partnerId: commission.partnerId,
+ programId,
+ });
+ }),
+ );
+ },
+ });
+}
+
+main();
diff --git a/packages/email/src/templates/notify-partner-reapply.tsx b/packages/email/src/templates/notify-partner-reapply.tsx
new file mode 100644
index 0000000000..838ec38381
--- /dev/null
+++ b/packages/email/src/templates/notify-partner-reapply.tsx
@@ -0,0 +1,116 @@
+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";
+
+export default function NotifyPartnerReapply({
+ partner = {
+ name: "John Doe",
+ email: "[email protected]",
+ },
+ programs = [
+ {
+ name: "Acme",
+ slug: "acme",
+ logo: "https://dubassets.com/programs/prog_CYCu7IMAapjkRpTnr8F1azjN/logo_HPEaC8P",
+ },
+ {
+ name: "Dub",
+ slug: "dub",
+ logo: "https://dubassets.com/programs/prog_d8pl69xXCv4AoHNT281pHQdo/logo_TMLMTHs",
+ },
+ ],
+}: {
+ partner: {
+ name?: string | null;
+ email: string;
+ };
+ programs: {
+ name: string;
+ slug: string;
+ logo?: string | null;
+ }[];
+}) {
+ return (
+ <Html>
+ <Head />
+ <Preview>
+ There was a problem with your applications to these programs. Please
+ reapply.
+ </Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[600px] rounded border border-solid border-neutral-200 px-10 py-5">
+ <Section className="mb-8 mt-6">
+ <Img src={DUB_WORDMARK} width="65" height="32" alt="dub" />
+ </Section>
+
+ <Heading className="mx-0 p-0 text-lg font-medium text-neutral-800">
+ Please resubmit your applications to these programs
+ </Heading>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ Hi {partner.name ? partner.name.split(" ")[0] : "there"}! Due to a
+ technical issue, your applications to the following programs were
+ not submitted correctly:
+ </Text>
+
+ <Section className="text-base">
+ {programs.map((program) => (
+ <Row key={program.slug} className="h-10">
+ <Column>
+ <Row>
+ <Column width="32">
+ <Img
+ src={
+ program.logo || `${OG_AVATAR_URL}${program.name}`
+ }
+ width="20"
+ height="20"
+ alt="Program logo"
+ className="rounded-full border border-neutral-200"
+ />
+ </Column>
+ <Column className="text-sm font-semibold text-neutral-800">
+ {program.name}
+ </Column>
+ </Row>
+ </Column>
+ <Column className="text-right text-sm">
+ <Link
+ href={`https://partners.dub.co/programs/marketplace/${program.slug}`}
+ className="rounded-lg border border-neutral-200 px-2 py-1 text-sm font-medium text-neutral-600 no-underline"
+ >
+ Reapply
+ </Link>
+ </Column>
+ </Row>
+ ))}
+ </Section>
+
+ <Text className="text-sm leading-6 text-neutral-600">
+ The issue has been fixed, but you will need to resubmit your
+ applications to these programs. We truly apologize for the
+ inconvenience.
+ </Text>
+
+ <Footer email={partner.email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}