Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
7ad643e
Set referral discount via Dub Customer object
steven-tey Dec 23, 2024
b6cba92
add comment
steven-tey Dec 23, 2024
db11493
Merge branch 'main' into dub-customer
steven-tey Dec 23, 2024
d514efc
Merge branch 'main' into dub-customer
steven-tey Dec 23, 2024
1ea12f1
EmbedWidgetActivity, EmbedWidgetSales, etc.
steven-tey Dec 24, 2024
95188dc
improve sale table
steven-tey Dec 24, 2024
9d2c1cf
small tweaks
steven-tey Dec 24, 2024
5246dd8
more tweaks
steven-tey Dec 24, 2024
58cb99b
fix ts
steven-tey Dec 24, 2024
2fb18ea
rename
steven-tey Dec 24, 2024
b484548
Update page-client.tsx
steven-tey Dec 24, 2024
9d57df0
EmbedLeaderboard
steven-tey Dec 24, 2024
5b7f35a
revalidate token on expire
steven-tey Dec 24, 2024
e1fd647
revert onTokenExpired
steven-tey Dec 24, 2024
1bab3fb
tabular-nums
steven-tey Dec 24, 2024
878c2f3
remove `onTokenExpired` option
devkiran Dec 24, 2024
135c21d
update createSaleData
devkiran Dec 24, 2024
45876b6
Update backfill-sales.ts
devkiran Dec 24, 2024
7d48eec
Update commission.ts
devkiran Dec 24, 2024
99cf016
use partner commissionAmount
devkiran Dec 24, 2024
01e57aa
stash
steven-tey Dec 24, 2024
76a9747
Merge branch 'main' into dub-customer
steven-tey Dec 24, 2024
d9d146c
Merge branch 'dub-customer' into dub-customer-contd
steven-tey Dec 24, 2024
e30b0dd
Update pnpm-lock.yaml
steven-tey Dec 24, 2024
2362897
formateDateTime as title
steven-tey Dec 25, 2024
1171234
rename files, fix types, calculateEarnings
steven-tey Dec 25, 2024
04a6b59
animatepresence
steven-tey Dec 25, 2024
915b40d
Update constants.ts
steven-tey Dec 25, 2024
3eaf985
Merge branch 'dub-customer' of https://github.com/dubinc/dub into dub…
steven-tey Dec 25, 2024
e015f7d
Merge branch 'dub-customer' into dub-customer-contd
steven-tey Dec 25, 2024
9736b28
Merge pull request #1834 from dubinc/dub-customer-contd
steven-tey Dec 25, 2024
d10e653
add EmbedQuickstart (WIP)
steven-tey Dec 25, 2024
9e449e7
add illustrations
steven-tey Dec 25, 2024
6c30092
fix height to match quickstart
steven-tey Dec 25, 2024
6b37c38
fixes
steven-tey Dec 26, 2024
88f1251
Update quickstart.tsx
steven-tey Dec 26, 2024
65d5804
useMediaQuery
steven-tey Dec 26, 2024
9f5c245
Merge branch 'main' into dub-customer
steven-tey Dec 26, 2024
ce7c2f9
Merge branch 'main' into dub-customer
steven-tey Dec 27, 2024
9e7cfc1
Merge branch 'main' into dub-customer
steven-tey Dec 27, 2024
59cf530
Update hero background & "powered by"
TWilson023 Dec 27, 2024
a1342b4
small fixes
steven-tey Dec 27, 2024
9342c9f
Update quickstart.tsx
steven-tey Dec 27, 2024
8dceec7
Update hero-background.tsx
TWilson023 Dec 27, 2024
0f99ae3
Merge branch 'dub-customer' of github.com:dubinc/dub into dub-customer
TWilson023 Dec 27, 2024
4bbb76c
Add `MiniAreaChart`s
TWilson023 Dec 27, 2024
5c329bd
add timeseries data
steven-tey Dec 27, 2024
1dea99c
Update hero-background.tsx
steven-tey Dec 27, 2024
11f08d4
fix FAQs with default templated questions
steven-tey Dec 27, 2024
19d00d0
remove embed popup + updating naming for DubEmbed
steven-tey Dec 27, 2024
a8f8b26
Update constants.ts
steven-tey Dec 27, 2024
f5d8c08
fix type error
steven-tey Dec 27, 2024
9a63064
disable payouts for saleAmount === 0
steven-tey Dec 27, 2024
486c807
missed a spot
steven-tey Dec 27, 2024
bd75712
Update page-client.tsx
steven-tey Dec 27, 2024
cd302c3
ExpandedCustomerSchema
steven-tey Dec 28, 2024
d4cc92e
transformCustomer
steven-tey Dec 28, 2024
500cb48
Merge branch 'main' into dub-customer
steven-tey Dec 28, 2024
5afa7e0
more transformCustomer
steven-tey Dec 28, 2024
0ee5d3e
Update index.test.ts
steven-tey Dec 28, 2024
88dea7f
remove old constant
steven-tey Dec 28, 2024
ead832a
fix formatDate timezone
steven-tey Dec 28, 2024
52c16e4
INFINITY_NUMBER
steven-tey Dec 28, 2024
2727311
Simplify commission details + add discount details
steven-tey Dec 28, 2024
bb974ca
simplify commission
steven-tey Dec 29, 2024
f302dc1
Update program-settings.tsx
steven-tey Dec 29, 2024
497c2b6
Update create-sale-data.ts
steven-tey Dec 29, 2024
dfe7e51
fix discount
steven-tey Dec 29, 2024
6d8d705
fix programEnrollment.discount
steven-tey Dec 29, 2024
5700ba5
fix programEnrollment discount
steven-tey Dec 29, 2024
8dd1af6
fix test
steven-tey Dec 29, 2024
c359eea
standardize discount to programEnrollment only
steven-tey Dec 29, 2024
df66265
Update transform-customer.ts
steven-tey Dec 29, 2024
3e26427
Update discount.ts
steven-tey Dec 29, 2024
5cbaee9
fix ts error
steven-tey Dec 29, 2024
b2e5b9b
Merge pull request #1842 from dubinc/dub-customers-simplify
steven-tey Dec 29, 2024
56fe30b
fix calculateEarnings
steven-tey Dec 29, 2024
0df5be6
Merge branch 'dub-customer' of https://github.com/dubinc/dub into dub…
steven-tey Dec 29, 2024
63e4383
remove unused columns
steven-tey Dec 29, 2024
dacd59b
fixes
steven-tey Dec 29, 2024
82bfcb7
improve programEnrollment.findUniqueOrThrow
steven-tey Dec 29, 2024
fc8af76
Update customers.ts
steven-tey Dec 29, 2024
d206c89
Update customers.ts
steven-tey Dec 29, 2024
d483467
improve faq & quickstart styles
steven-tey Dec 29, 2024
e5aa987
fix DetailsGrid
steven-tey Dec 29, 2024
d08c503
improve backfillLinkData
steven-tey Dec 29, 2024
28ae53c
getProgramOrThrow
steven-tey Dec 29, 2024
77ca6b5
Merge branch 'main' into dub-customer
steven-tey Dec 29, 2024
1272b01
use actual payouts data
steven-tey Dec 29, 2024
e5221b3
Merge branch 'dub-customer' of https://github.com/dubinc/dub into dub…
steven-tey Dec 29, 2024
3d80948
Update utils.ts
steven-tey Dec 29, 2024
32f1bb6
Update faq.tsx
steven-tey Dec 29, 2024
99f0145
improve <Usage /> indicator
steven-tey Dec 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/web/app/api/analytics/client/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { calculateEarnings } from "@/lib/api/sales/commission";
import { calculateEarnings } from "@/lib/api/sales/calculate-earnings";
import { withEmbedToken } from "@/lib/embed/auth";
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics";
import { NextResponse } from "next/server";
Expand Down
18 changes: 15 additions & 3 deletions apps/web/app/api/customers/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCustomerOrThrow } from "@/lib/api/customers/get-customer-or-throw";
import { transformCustomer } from "@/lib/api/customers/transform-customer";
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
Expand All @@ -24,7 +25,7 @@ export const GET = withWorkspace(
},
);

return NextResponse.json(CustomerSchema.parse(customer));
return NextResponse.json(CustomerSchema.parse(transformCustomer(customer)));
},
{
requiredAddOn: "conversion",
Expand Down Expand Up @@ -52,11 +53,22 @@ export const PATCH = withWorkspace(
},
data: { name, email, avatar, externalId },
include: {
link: true,
link: {
include: {
programEnrollment: {
include: {
partner: true,
discount: true,
},
},
},
},
},
});

return NextResponse.json(CustomerSchema.parse(updatedCustomer));
return NextResponse.json(
CustomerSchema.parse(transformCustomer(updatedCustomer)),
);
} catch (error) {
if (error.code === "P2002") {
throw new DubApiError({
Expand Down
17 changes: 10 additions & 7 deletions apps/web/app/api/customers/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { transformCustomer } from "@/lib/api/customers/transform-customer";
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
Expand All @@ -22,7 +23,9 @@ export const GET = withWorkspace(
},
});

return NextResponse.json(CustomerSchema.array().parse(customers));
return NextResponse.json(
CustomerSchema.array().parse(customers.map(transformCustomer)),
);
},
{
requiredAddOn: "conversion",
Expand All @@ -48,14 +51,14 @@ export const POST = withWorkspace(
projectId: workspace.id,
projectConnectId: workspace.stripeConnectId,
},
include: {
link: true,
},
});

return NextResponse.json(CustomerSchema.parse(customer), {
status: 201,
});
return NextResponse.json(
CustomerSchema.parse(transformCustomer(customer)),
{
status: 201,
},
);
} catch (error) {
if (error.code === "P2002") {
throw new DubApiError({
Expand Down
15 changes: 15 additions & 0 deletions apps/web/app/api/embed/analytics/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { withEmbedToken } from "@/lib/embed/auth";
import { NextResponse } from "next/server";

// GET /api/embed/analytics – get timeseries analytics for a link from an embed token
export const GET = withEmbedToken(async ({ link }) => {
const analytics = await getAnalytics({
event: "composite",
groupBy: "timeseries",
linkId: link.id,
interval: "1y",
});

return NextResponse.json(analytics);
});
40 changes: 40 additions & 0 deletions apps/web/app/api/embed/leaderboard/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { withEmbedToken } from "@/lib/embed/auth";
import { LeaderboardPartnerSchema } from "@/lib/zod/schemas/partners";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
import z from "node_modules/zod/lib";

// GET /api/embed/sales – get sales for a link from an embed token
export const GET = withEmbedToken(async ({ program, searchParams }) => {
const programEnrollments = await prisma.programEnrollment.findMany({
where: {
programId: program.id,
},
orderBy: [
{
link: {
saleAmount: "desc",
},
},
{
link: {
leads: "desc",
},
},
{
link: {
clicks: "desc",
},
},
],
select: {
partner: true,
link: true,
},
take: 20,
});

return NextResponse.json(
z.array(LeaderboardPartnerSchema).parse(programEnrollments),
);
});
10 changes: 8 additions & 2 deletions apps/web/app/api/embed/sales/route.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { withEmbedToken } from "@/lib/embed/auth";
import { SALES_PAGE_SIZE } from "@/lib/partners/constants";
import z from "@/lib/zod";
import { PartnerSaleResponseSchema } from "@/lib/zod/schemas/partners";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";

// GET /api/embed/sales – get sales for a link from an embed token
export const GET = withEmbedToken(async ({ link }) => {
export const GET = withEmbedToken(async ({ link, searchParams }) => {
const { page } = z
.object({ page: z.coerce.number().optional().default(1) })
.parse(searchParams);

const sales = await prisma.sale.findMany({
where: {
linkId: link.id,
Expand All @@ -25,7 +30,8 @@ export const GET = withEmbedToken(async ({ link }) => {
},
},
},
take: 3,
take: SALES_PAGE_SIZE,
skip: (page - 1) * SALES_PAGE_SIZE,
orderBy: {
createdAt: "desc",
},
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/events/client/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getEvents } from "@/lib/analytics/get-events";
import { calculateEarnings } from "@/lib/api/sales/commission";
import { calculateEarnings } from "@/lib/api/sales/calculate-earnings";
import { withEmbedToken } from "@/lib/embed/auth";
import { eventsQuerySchema } from "@/lib/zod/schemas/analytics";
import { NextResponse } from "next/server";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { calculateEarnings } from "@/lib/api/sales/commission";
import { calculateEarnings } from "@/lib/api/sales/calculate-earnings";
import { withPartner } from "@/lib/auth/partner";
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics";
import { NextResponse } from "next/server";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/analytics/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAnalytics } from "@/lib/analytics/get-analytics";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { analyticsQuerySchema } from "@/lib/zod/schemas/analytics";
import { NextResponse } from "next/server";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/customers/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
CustomerSchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/invites/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { partnerInvitesQuerySchema } from "@/lib/zod/schemas/partners";
import { ProgramInviteSchema } from "@/lib/zod/schemas/programs";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/metrics/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { getProgramMetricsQuerySchema } from "@/lib/zod/schemas/programs";
import { prisma } from "@dub/prisma";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { PartnerSchema } from "@/lib/zod/schemas/partners";
import { prisma } from "@dub/prisma";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { partnersCountQuerySchema } from "@/lib/zod/schemas/partners";
import { prisma } from "@dub/prisma";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/partners/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
EnrolledPartnerSchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { MIN_PAYOUT_AMOUNT } from "@/lib/partners/constants";
import { payoutsCountQuerySchema } from "@/lib/zod/schemas/payouts";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/payouts/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
PayoutResponseSchema,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { NextResponse } from "next/server";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { getSalesAmountQuerySchema } from "@/lib/zod/schemas/partners";
import { prisma } from "@dub/prisma";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/sales/count/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import { getSalesCountQuerySchema } from "@/lib/zod/schemas/partners";
import { prisma } from "@dub/prisma";
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/api/programs/[programId]/sales/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { getProgramOrThrow } from "@/lib/api/programs/get-program";
import { getProgramOrThrow } from "@/lib/api/programs/get-program-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
getSalesQuerySchema,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { notifyPartnerSale } from "@/lib/api/partners/notify-partner-sale";
import { createSaleData } from "@/lib/api/sales/sale";
import { createSaleData } from "@/lib/api/sales/create-sale-data";
import { getLeadEvent, recordSale } from "@/lib/tinybird";
import { redis } from "@/lib/upstash";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
Expand Down Expand Up @@ -129,32 +129,36 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {

// for program links
if (link.programId) {
const { program, partner } =
const { program, partnerId, commissionAmount } =
await prisma.programEnrollment.findUniqueOrThrow({
where: {
linkId: link.id,
},
select: {
program: true,
partner: {
select: {
id: true,
},
},
partnerId: true,
commissionAmount: true,
},
});

const saleRecord = createSaleData({
customerId: saleData.customer_id,
linkId: saleData.link_id,
clickId: saleData.click_id,
invoiceId: saleData.invoice_id,
eventId: saleData.event_id,
paymentProcessor: saleData.payment_processor,
amount: saleData.amount,
currency: saleData.currency,
partnerId: partner.id,
program,
partner: {
id: partnerId,
commissionAmount,
},
customer: {
id: saleData.customer_id,
linkId: saleData.link_id,
clickId: saleData.click_id,
},
sale: {
amount: saleData.amount,
currency: saleData.currency,
invoiceId: saleData.invoice_id,
eventId: saleData.event_id,
paymentProcessor: saleData.payment_processor,
},
metadata: {
...leadEvent.data[0],
stripeMetadata: charge,
Expand All @@ -168,7 +172,7 @@ export async function checkoutSessionCompleted(event: Stripe.Event) {
waitUntil(
notifyPartnerSale({
partner: {
id: partner.id,
id: partnerId,
referralLink: link.shortLink,
},
program,
Expand Down
Loading
Loading