The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve naming conventions
Steven Teyb5b80383f8a8
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.tsindex d183631a67..2f801cf6e0 100644--- a/apps/web/app/(ee)/api/bounties/route.ts+++ b/apps/web/app/(ee)/api/bounties/route.ts@@ -116,7 +116,7 @@ export const POST = withWorkspace(submissionRequirements,groupIds,performanceCondition,- currentStatsOnly,+ performanceScope,} = createBountySchema.parse(await parseRequestBody(req));if (startsAt && endsAt && endsAt < startsAt) {@@ -142,10 +142,10 @@ export const POST = withWorkspace(}}- if (typeof currentStatsOnly !== "boolean" && type === "performance") {+ if (!performanceScope && type === "performance") {throw new DubApiError({code: "bad_request",- message: "currentStatsOnly must be set for performance bounties.",+ message: "performanceScope must be set for performance bounties.",});}@@ -209,7 +209,7 @@ export const POST = withWorkspace(endsAt,rewardAmount,rewardDescription,- currentStatsOnly: type === "performance" ? currentStatsOnly : null,+ performanceScope: type === "performance" ? performanceScope : null,...(submissionRequirements &&type === "submission" && {submissionRequirements,@@ -238,7 +238,7 @@ export const POST = withWorkspace(});const shouldScheduleDraftSubmissions =- bounty.type === "performance" && !currentStatsOnly;+ bounty.type === "performance" && bounty.performanceScope === "lifetime";waitUntil(Promise.allSettled([diff --git a/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts b/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.tsindex d5b0b4e137..b1ab351e24 100644--- a/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts+++ b/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts@@ -63,9 +63,9 @@ export async function POST(req: Request) {return logAndRespond(`Bounty ${bountyId} is not a performance bounty.`);}- if (bounty.currentStatsOnly) {+ if (bounty.performanceScope === "new") {return logAndRespond(- `Bounty ${bountyId} is limited to current stats; submission creation skipped.`,+ `Bounty ${bountyId} is limited to new stats; submission creation skipped.`,);}@@ -146,7 +146,7 @@ export async function POST(req: Request) {programId: bounty.programId,partnerId: partner.id,bountyId: bounty.id,- count: partner[condition.attribute] ?? 0,+ performanceCount: partner[condition.attribute] ?? 0,}));// Create bounty submissionsdiff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsxindex 98afb93d58..959d58e5d3 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx@@ -202,7 +202,7 @@ export function BountySubmissionsTable() {return "-";}- const value = row.original.count ?? 0;+ const value = row.original.performanceCount ?? 0;const attribute = performanceCondition.attribute;const target = performanceCondition.value;diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsxindex 52319d5a56..c9eef22c60 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx@@ -130,7 +130,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {operator: "gte",},...(bounty && {- currentStatsOnly: bounty.currentStatsOnly,+ performanceScope: bounty.performanceScope,}),},});diff --git a/apps/web/lib/api/bounties/get-bounty-submissions.ts b/apps/web/lib/api/bounties/get-bounty-submissions.tsindex e6449af303..5bb4dc1802 100644--- a/apps/web/lib/api/bounties/get-bounty-submissions.ts+++ b/apps/web/lib/api/bounties/get-bounty-submissions.ts@@ -1,22 +1,10 @@import { BountySubmissionsQueryFilters } from "@/lib/types";-import { BOUNTY_SUBMISSIONS_SORT_BY_COLUMNS } from "@/lib/zod/schemas/bounties";import { prisma } from "@dub/prisma";interface GetBountySubmissionsParams extends BountySubmissionsQueryFilters {bountyId: string;}-const SORT_COLUMNS_MAP: Record<- (typeof BOUNTY_SUBMISSIONS_SORT_BY_COLUMNS)[number],- string-> = {- createdAt: "createdAt",- commissions: "count",- leads: "count",- conversions: "count",- saleAmount: "count",-};-// Get list of submissions for a given bountyexport async function getBountySubmissions({bountyId,@@ -44,7 +32,7 @@ export async function getBountySubmissions({programEnrollment: true,},orderBy: {- [SORT_COLUMNS_MAP[sortBy]]: sortOrder,+ [sortBy === "createdAt" ? "createdAt" : "performanceCount"]: sortOrder,},skip: (page - 1) * pageSize,take: pageSize,diff --git a/apps/web/lib/api/bounties/get-bounty-with-details.ts b/apps/web/lib/api/bounties/get-bounty-with-details.tsindex c52603e945..5ca7384f9c 100644--- a/apps/web/lib/api/bounties/get-bounty-with-details.ts+++ b/apps/web/lib/api/bounties/get-bounty-with-details.ts@@ -19,7 +19,7 @@ export const getBountyWithDetails = async ({b.rewardAmount,b.rewardDescription,b.submissionRequirements,- b.currentStatsOnly,+ b.performanceScope,wf.triggerConditions,-- Partners count@@ -85,10 +85,7 @@ export const getBountyWithDetails = async ({const bounty = bounties[0];const performanceCondition =bounty.triggerConditions?.length > 0 ? bounty.triggerConditions[0] : null;- const currentStatsOnly =- typeof bounty.currentStatsOnly === "number"- ? bounty.currentStatsOnly === 1- : null;+ const performanceScope = bounty.performanceScope;return {id: bounty.id,@@ -100,7 +97,7 @@ export const getBountyWithDetails = async ({rewardAmount: bounty.rewardAmount,rewardDescription: bounty.rewardDescription,submissionRequirements: bounty.submissionRequirements,- currentStatsOnly,+ performanceScope,performanceCondition,groups: bounty.groups.filter((group) => group !== null) ?? [],partnersCount: Number(bounty.partners),diff --git a/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.ts b/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.tsindex 98041af36d..d3e420b7f4 100644--- a/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.ts+++ b/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.ts@@ -7,7 +7,7 @@ import { getBountiesByGroups } from "./get-bounties-by-groups";// TODO:// Need a better method name-// Trigger the creation of draft submissions for performance bounties that uses all-time stats for the given partners+// Trigger the creation of draft submissions for performance bounties that uses lifetime stats for the given partnersexport async function triggerDraftBountySubmissionCreation({programId,partnerIds,@@ -65,7 +65,7 @@ export async function triggerDraftBountySubmissionCreation({if (eligibleBounties.length === 0) {console.log(- `No eligible bounties found for the group ${groupId}. Either there are no performance bounties, or there are no all-time stats.`,+ `No eligible bounties found for the group ${groupId}. Either there are no performance bounties, or there are no lifetime stats.`,);continue;}@@ -99,7 +99,7 @@ function isEligiblePerformanceBounty(bounty: Bounty) {const now = new Date();if (bounty.type !== "performance") return false;- if (bounty.currentStatsOnly) return false;+ if (bounty.performanceScope === "new") return false;if (bounty.startsAt > now) return false;if (bounty.endsAt && bounty.endsAt <= now) return false;diff --git a/apps/web/lib/api/workflows/execute-award-bounty-action.ts b/apps/web/lib/api/workflows/execute-award-bounty-action.tsindex fdbd52c830..a6ff89a4f5 100644--- a/apps/web/lib/api/workflows/execute-award-bounty-action.ts+++ b/apps/web/lib/api/workflows/execute-award-bounty-action.ts@@ -138,10 +138,10 @@ export const executeAwardBountyAction = async ({partnerId,bountyId: bounty.id,status: "draft",- count,+ performanceCount: count,},update: {- count: {+ performanceCount: {increment: count,},},@@ -151,7 +151,7 @@ export const executeAwardBountyAction = async ({const shouldExecute = evaluateWorkflowCondition({condition,attributes: {- [condition.attribute]: bountySubmission.count,+ [condition.attribute]: bountySubmission.performanceCount,},});diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.tsindex 7b0f5bc0bd..eda8fc432d 100644--- a/apps/web/lib/zod/schemas/bounties.ts+++ b/apps/web/lib/zod/schemas/bounties.ts@@ -1,4 +1,5 @@import {+ BountyPerformanceScope,BountySubmissionRejectionReason,BountySubmissionStatus,BountyType,@@ -66,13 +67,13 @@ export const createBountySchema = z.object({submissionRequirements: submissionRequirementsSchema.nullish(),groupIds: z.array(z.string()).nullable(),performanceCondition: workflowConditionSchema.nullish(),- currentStatsOnly: z.boolean().nullish(),+ performanceScope: z.nativeEnum(BountyPerformanceScope).nullish(),});export const updateBountySchema = createBountySchema.omit({type: true,- currentStatsOnly: true,+ performanceScope: true,}).partial();@@ -95,7 +96,7 @@ export const BountySchema = z.object({performanceCondition: workflowConditionSchema.nullable().default(null),submissionRequirements: submissionRequirementsSchema.nullable().default(null),groups: z.array(GroupSchema.pick({ id: true })),- currentStatsOnly: z.boolean().nullable(),+ performanceScope: z.nativeEnum(BountyPerformanceScope).nullable(),});export const getBountiesQuerySchema = z.object({@@ -117,7 +118,7 @@ export const BountySubmissionSchema = z.object({urls: z.array(z.string()).nullable(),files: z.array(BountySubmissionFileSchema).nullable(),status: z.nativeEnum(BountySubmissionStatus),- count: z.number().nullable(),+ performanceCount: z.number().nullable(),createdAt: z.date(),updatedAt: z.date(),reviewedAt: z.date().nullable(),diff --git a/apps/web/scripts/migrations/backfill-bounties.ts b/apps/web/scripts/migrations/backfill-bounties.tsindex 882d358928..d081e43282 100644--- a/apps/web/scripts/migrations/backfill-bounties.ts+++ b/apps/web/scripts/migrations/backfill-bounties.ts@@ -4,13 +4,13 @@ import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";import "dotenv-flow/config";async function main() {- // Step 1: Set all existing performance bounties to all-time stats+ // Step 1: Set all existing performance bounties to lifetime statsawait prisma.bounty.updateMany({where: {type: "performance",},data: {- currentStatsOnly: false,+ performanceScope: "lifetime",},});diff --git a/apps/web/tests/bounties/index.test.ts b/apps/web/tests/bounties/index.test.tsindex 5b77fdb593..8016d3ea2d 100644--- a/apps/web/tests/bounties/index.test.ts+++ b/apps/web/tests/bounties/index.test.ts@@ -23,7 +23,7 @@ const performanceBounty = {startsAt,endsAt: null,rewardAmount: 1000,- currentStatsOnly: false,+ performanceScope: "lifetime",};describe.sequential("/bounties/**", async () => {@@ -99,13 +99,13 @@ describe.sequential("/bounties/**", async () => {});});- test("POST /bounties - performance based with currentStatsOnly set to true", async () => {+ test("POST /bounties - performance based with performanceScope set to new", async () => {const { status, data: bounty } = await http.post<Bounty>({path: "/bounties",body: {...performanceBounty,groupIds: [E2E_PARTNER_GROUP.id],- currentStatsOnly: true,+ performanceScope: "new",},});@@ -113,7 +113,7 @@ describe.sequential("/bounties/**", async () => {expect(bounty).toMatchObject({id: expect.any(String),...performanceBounty,- currentStatsOnly: true,+ performanceScope: "new",});onTestFinished(async () => {diff --git a/apps/web/ui/partners/bounties/bounty-logic.tsx b/apps/web/ui/partners/bounties/bounty-logic.tsxindex 378bf03aac..6a330de2d4 100644--- a/apps/web/ui/partners/bounties/bounty-logic.tsx+++ b/apps/web/ui/partners/bounties/bounty-logic.tsx@@ -38,24 +38,24 @@ export function BountyLogic({ className }: { className?: string }) {<div className="inline-flex items-center gap-1"><Controllercontrol={control}- name="currentStatsOnly"+ name="performanceScope"render={({ field }) => (<InlineBadgePopovertext={- field.value === true+ field.value === "new"? "new"- : field.value === false- ? "all-time"+ : field.value === "lifetime"+ ? "lifetime": "type"}- invalid={field.value === undefined || field.value === null}+ invalid={!field.value}><InlineBadgePopoverMenuselectedValue={field.value}onSelect={field.onChange}items={[- { text: "new", value: true },- { text: "all-time", value: false },+ { text: "new", value: "new" },+ { text: "lifetime", value: "lifetime" },]}/></InlineBadgePopover>diff --git a/apps/web/ui/partners/bounties/bounty-performance.tsx b/apps/web/ui/partners/bounties/bounty-performance.tsxindex 9d67b61419..1749b96445 100644--- a/apps/web/ui/partners/bounties/bounty-performance.tsx+++ b/apps/web/ui/partners/bounties/bounty-performance.tsx@@ -12,7 +12,7 @@ export function BountyPerformance({ bounty }: { bounty: PartnerBountyProps }) {const attribute = performanceCondition.attribute;const target = performanceCondition.value;- const value = bounty.submission?.count ?? 0;+ const value = bounty.submission?.performanceCount ?? 0;const formattedValue =value === undefineddiff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prismaindex 5b9010d97f..3680b5973c 100644--- a/packages/prisma/schema/bounty.prisma+++ b/packages/prisma/schema/bounty.prisma@@ -3,6 +3,11 @@ enum BountyType {submission}+enum BountyPerformanceScope {+ new+ lifetime+}+enum BountySubmissionStatus {draftsubmitted@@ -25,11 +30,11 @@ model Bounty {name Stringdescription String? @db.Texttype BountyType- currentStatsOnly Boolean?startsAt DateTimeendsAt DateTime?rewardAmount Int?rewardDescription String?+ performanceScope BountyPerformanceScope? @default(new)submissionRequirements Json?archivedAt DateTime?createdAt DateTime @default(now())@@ -60,7 +65,7 @@ model BountySubmission {programId StringpartnerId StringbountyId String- count Int?+ performanceCount Int?commissionId String? @uniqueuserId String?description String? @db.Text