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.

bump @dub package versions

Steven Teyc2b8ead06b94
diff --git a/apps/web/scripts/migrations/backfill-link-commissions.ts b/apps/web/scripts/migrations/backfill-link-commissions.ts
index 63c047fa97..3e01d05b99 100644
--- a/apps/web/scripts/migrations/backfill-link-commissions.ts
+++ b/apps/web/scripts/migrations/backfill-link-commissions.ts
@@ -1,6 +1,7 @@
import { SaleEvent } from "@/lib/types";
import { prisma } from "@dub/prisma";
import { EventType, Prisma } from "@dub/prisma/client";
+import { currencyFormatter } from "@dub/utils";
import "dotenv-flow/config";
import { getEvents } from "../../lib/analytics/get-events";
import { createId } from "../../lib/api/create-id";
@@ -11,9 +12,7 @@ import { determinePartnerReward } from "../../lib/partners/determine-partner-rew
// script to backfill link commissions
// NOTE: need to remove "server-only" from serialize-reward.ts to run this script
async function main() {
- const linkId = "link_1K51TBZPWY2WB401DTJHQBTZ3";
- const eventId = "Y9SMlkLFt9gt63fl";
-
+ const linkId = "link_xxx";
const link = await prisma.link.findUniqueOrThrow({
where: {
id: linkId,
@@ -24,18 +23,50 @@ async function main() {
}
const saleEvents = (await getEvents({
+ workspaceId: link.projectId!,
linkId: link.id,
event: "sales",
- interval: "all",
+ saleType: "new",
page: 1,
- limit: 5000,
+ limit: 10000,
sortOrder: "desc",
sortBy: "timestamp",
- os: undefined,
- device: undefined,
- browser: undefined,
+ start: new Date("2026-01-01"),
+ end: new Date("2026-03-06"),
})) as SaleEvent[];
+ const existingCommissions = await prisma.commission.findMany({
+ where: {
+ OR: [
+ {
+ eventId: {
+ in: saleEvents.map((e) => e.eventId),
+ },
+ },
+ {
+ invoiceId: {
+ in: saleEvents.map((e) => e.invoice_id),
+ },
+ },
+ {
+ customerId: {
+ in: saleEvents.map((e) => e.customer.id),
+ },
+ },
+ ],
+ },
+ });
+ const missedSaleEvents = saleEvents.filter(
+ (e) =>
+ e.saleAmount > 20_00 && // special condition for program
+ !existingCommissions.some(
+ (c) =>
+ c.eventId === e.eventId ||
+ c.invoiceId === e.invoice_id ||
+ c.customerId === e.customer.id,
+ ),
+ );
+
const programEnrollment = await prisma.programEnrollment.findUniqueOrThrow({
where: {
partnerId_programId: {
@@ -53,11 +84,8 @@ async function main() {
const { program } = programEnrollment;
- const data = saleEvents
+ const data = missedSaleEvents
.map((e) => {
- if (e.eventId !== eventId) {
- return null;
- }
const reward = determinePartnerReward({
event: "sale",
programEnrollment,
@@ -75,9 +103,7 @@ async function main() {
programId: program.id,
partnerId: link.partnerId!,
linkId: link.id,
- invoiceId: e.invoice_id
- ? `${e.invoice_id}${e.metadata?.productId ? `-${e.metadata?.productId}` : ""}`
- : null,
+ invoiceId: e.invoice_id,
customerId: e.customer.id,
eventId: e.eventId,
amount: e.sale.amount,
@@ -98,14 +124,22 @@ async function main() {
(c): c is NonNullable<typeof c> => c !== null,
) satisfies Prisma.CommissionCreateManyInput[];
- console.table(data);
+ console.table(data, [
+ "customerId",
+ "amount",
+ "earnings",
+ "invoiceId",
+ "createdAt",
+ ]);
// create commissions
const res = await prisma.commission.createMany({
data,
skipDuplicates: true,
});
- console.log(`Created ${res.count} commissions`);
+ console.log(
+ `Backfilled ${res.count} commissions for a total of ${currencyFormatter(res.count * 20_00)}`,
+ );
// sync total commissions for the partner in the program
await syncTotalCommissions({
diff --git a/packages/ui/package.json b/packages/ui/package.json
index 1503234857..4f8601b01d 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/ui",
"description": "UI components for Dub",
- "version": "0.2.69",
+ "version": "0.3.1",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.mjs",
diff --git a/packages/ui/src/footer.tsx b/packages/ui/src/footer.tsx
index 4b2e35f793..0897c6396a 100644
--- a/packages/ui/src/footer.tsx
+++ b/packages/ui/src/footer.tsx
@@ -89,10 +89,7 @@ const navigation = {
})).concat(
["Rewardful", "PartnerStack", "FirstPromoter", "Tolt"].map((name) => ({
name,
- href:
- name === "Rewardful"
- ? "/blog/dub-vs-rewardful"
- : `/help/article/migrating-from-${name.toLowerCase()}`,
+ href: `/blog/dub-vs-${name.toLowerCase()}`,
product: "partners",
})),
),
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 8d0267d1cc..d1adb9cd50 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -1,7 +1,7 @@
{
"name": "@dub/utils",
"description": "Utility functions and constants for Dub",
- "version": "0.1.53",
+ "version": "0.1.54",
"sideEffects": false,
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",