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.

add ReferralsEmbedLinkSchema

Kiran K1389485b0008
diff --git a/apps/web/app/api/embed/referrals/links/[linkId]/route.ts b/apps/web/app/api/embed/referrals/links/[linkId]/route.ts
index 9ae977a83c..f9050035c8 100644
--- a/apps/web/app/api/embed/referrals/links/[linkId]/route.ts
+++ b/apps/web/app/api/embed/referrals/links/[linkId]/route.ts
@@ -2,8 +2,8 @@ import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { processLink, updateLink } from "@/lib/api/links";
import { parseRequestBody } from "@/lib/api/utils";
import { withReferralsEmbedToken } from "@/lib/embed/referrals/auth";
-import { LinkSchema } from "@/lib/zod/schemas/links";
import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";
+import { ReferralsEmbedLinkSchema } from "@/lib/zod/schemas/referrals-embed";
import { getApexDomain } from "@dub/utils";
import { NextResponse } from "next/server";
@@ -86,12 +86,7 @@ export const PATCH = withReferralsEmbedToken(
updatedLink: processedLink,
});
- const updatedLink = LinkSchema.pick({
- id: true,
- domain: true,
- key: true,
- url: true,
- }).parse(partnerLink);
+ const updatedLink = ReferralsEmbedLinkSchema.parse(partnerLink);
return NextResponse.json(updatedLink);
},
diff --git a/apps/web/app/api/embed/referrals/links/route.ts b/apps/web/app/api/embed/referrals/links/route.ts
index de80905bf3..6ac62b815d 100644
--- a/apps/web/app/api/embed/referrals/links/route.ts
+++ b/apps/web/app/api/embed/referrals/links/route.ts
@@ -1,15 +1,13 @@
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { createLink, processLink } from "@/lib/api/links";
+import { PARTNER_LINKS_LIMIT } from "@/lib/api/partners/constants";
import { parseRequestBody } from "@/lib/api/utils";
import { withReferralsEmbedToken } from "@/lib/embed/referrals/auth";
-import { LinkSchema } from "@/lib/zod/schemas/links";
import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";
+import { ReferralsEmbedLinkSchema } from "@/lib/zod/schemas/referrals-embed";
import { getApexDomain } from "@dub/utils";
import { NextResponse } from "next/server";
-// TODO: Move this to a constant
-const PARTNER_LINKS_LIMIT = 5;
-
// POST /api/embed/referrals/links – create links for a partner
export const POST = withReferralsEmbedToken(
async ({ req, programEnrollment, program, links }) => {
@@ -78,13 +76,7 @@ export const POST = withReferralsEmbedToken(
}
const partnerLink = await createLink(link);
-
- const createdLink = LinkSchema.pick({
- id: true,
- domain: true,
- key: true,
- url: true,
- }).parse(partnerLink);
+ const createdLink = ReferralsEmbedLinkSchema.parse(partnerLink);
return NextResponse.json(createdLink, { status: 201 });
},
diff --git a/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts
index f0bf0f7293..e738224425 100644
--- a/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts
+++ b/apps/web/app/api/partner-profile/programs/[programId]/links/route.ts
@@ -1,5 +1,6 @@
import { DubApiError, ErrorCodes } from "@/lib/api/errors";
import { createLink, processLink } from "@/lib/api/links";
+import { PARTNER_LINKS_LIMIT } from "@/lib/api/partners/constants";
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { parseRequestBody } from "@/lib/api/utils";
import { withPartnerProfile } from "@/lib/auth/partner";
@@ -8,8 +9,6 @@ import { createPartnerLinkSchema } from "@/lib/zod/schemas/partners";
import { getApexDomain } from "@dub/utils";
import { NextResponse } from "next/server";
-const PARTNER_LINKS_LIMIT = 5;
-
// GET /api/partner-profile/programs/[programId]/links - get a partner's links in a program
export const GET = withPartnerProfile(async ({ partner, params }) => {
const { links } = await getProgramEnrollmentOrThrow({
diff --git a/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx b/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx
index 11b52f3206..9e57fae6e5 100644
--- a/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/add-edit-link.tsx
@@ -1,6 +1,5 @@
import { mutateSuffix } from "@/lib/swr/mutate";
import { Lock } from "@/ui/shared/icons";
-import { Link } from "@dub/prisma/client";
import {
Button,
InfoTooltip,
@@ -12,11 +11,12 @@ import { cn, linkConstructor, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/utils";
import { motion } from "framer-motion";
import { useMemo, useState } from "react";
import { useForm } from "react-hook-form";
+import { ReferralsEmbedLink } from "./types";
interface Props {
destinationDomain: string;
shortLinkDomain: string;
- link?: Link | null;
+ link?: ReferralsEmbedLink | null;
onCancel: () => void;
}
diff --git a/apps/web/app/app.dub.co/embed/referrals/links-list.tsx b/apps/web/app/app.dub.co/embed/referrals/links-list.tsx
index 0337f5cc0e..9a720ea7cc 100644
--- a/apps/web/app/app.dub.co/embed/referrals/links-list.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/links-list.tsx
@@ -1,14 +1,14 @@
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
-import { Link } from "@dub/prisma/client";
import { Button, CopyButton, Table, Users, useTable } from "@dub/ui";
import { Pen2, Plus2 } from "@dub/ui/icons";
import { getPrettyUrl, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/utils";
import { motion } from "framer-motion";
+import { ReferralsEmbedLink } from "./types";
interface Props {
- links: Link[];
+ links: ReferralsEmbedLink[];
onCreateLink: () => void;
- onEditLink: (link: Link) => void;
+ onEditLink: (link: ReferralsEmbedLink) => void;
}
export function ReferralsEmbedLinksList({
diff --git a/apps/web/app/app.dub.co/embed/referrals/links.tsx b/apps/web/app/app.dub.co/embed/referrals/links.tsx
index 745aae4773..ca0d8ce5bf 100644
--- a/apps/web/app/app.dub.co/embed/referrals/links.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/links.tsx
@@ -1,10 +1,10 @@
-import { Link } from "@dub/prisma/client";
import { useState } from "react";
import { ReferralsEmbedCreateUpdateLink } from "./add-edit-link";
import { ReferralsEmbedLinksList } from "./links-list";
+import { ReferralsEmbedLink } from "./types";
interface Props {
- links: Link[];
+ links: ReferralsEmbedLink[];
destinationDomain: string;
shortLinkDomain: string;
}
@@ -15,7 +15,7 @@ export default function ReferralsEmbedLinks({
shortLinkDomain,
}: Props) {
const [createLink, setCreateLink] = useState(false);
- const [link, setLink] = useState<Link | null>(null);
+ const [link, setLink] = useState<ReferralsEmbedLink | null>(null);
return (
<div className="flex flex-col space-y-6">
diff --git a/apps/web/app/app.dub.co/embed/referrals/page-client.tsx b/apps/web/app/app.dub.co/embed/referrals/page-client.tsx
index 735686dbd8..c6b3307785 100644
--- a/apps/web/app/app.dub.co/embed/referrals/page-client.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/page-client.tsx
@@ -6,7 +6,7 @@ import { programResourcesSchema } from "@/lib/zod/schemas/program-resources";
import { HeroBackground } from "@/ui/partners/hero-background";
import { ProgramRewardList } from "@/ui/partners/program-reward-list";
import { ThreeDots } from "@/ui/shared/icons";
-import { Link, PayoutStatus, Program } from "@dub/prisma/client";
+import { PayoutStatus, Program } from "@dub/prisma/client";
import {
Button,
Check,
@@ -31,6 +31,7 @@ import { ReferralsEmbedQuickstart } from "./quickstart";
import { ReferralsEmbedResources } from "./resources";
import { ThemeOptions } from "./theme-options";
import { ReferralsReferralsEmbedToken } from "./token";
+import { ReferralsEmbedLink } from "./types";
export function ReferralsEmbedPageClient({
program,
@@ -42,7 +43,7 @@ export function ReferralsEmbedPageClient({
themeOptions,
}: {
program: Program;
- links: Link[];
+ links: ReferralsEmbedLink[];
rewards: RewardProps[];
discount?: DiscountProps | null;
payouts: {
diff --git a/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx b/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx
index a5b77426b1..f1304d8630 100644
--- a/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx
+++ b/apps/web/app/app.dub.co/embed/referrals/quickstart.tsx
@@ -1,4 +1,4 @@
-import { Link, Program } from "@dub/prisma/client";
+import { Program } from "@dub/prisma/client";
import {
Button,
Carousel,
@@ -12,6 +12,7 @@ import {
} from "@dub/ui";
import { cn, DUB_LOGO, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/utils";
import { motion } from "framer-motion";
+import { ReferralsEmbedLink } from "./types";
const BUTTON_CLASSNAME = "h-9 rounded-lg bg-bg-inverted hover:bg-neutral-800";
@@ -21,7 +22,7 @@ export function ReferralsEmbedQuickstart({
onViewResources,
}: {
program: Program;
- link: Link;
+ link: ReferralsEmbedLink;
onViewResources?: () => void;
}) {
const [copied, copyToClipboard] = useCopyToClipboard();
diff --git a/apps/web/app/app.dub.co/embed/referrals/types.ts b/apps/web/app/app.dub.co/embed/referrals/types.ts
new file mode 100644
index 0000000000..80e2d10fe4
--- /dev/null
+++ b/apps/web/app/app.dub.co/embed/referrals/types.ts
@@ -0,0 +1,4 @@
+import { ReferralsEmbedLinkSchema } from "@/lib/zod/schemas/referrals-embed";
+import { z } from "zod";
+
+export type ReferralsEmbedLink = z.infer<typeof ReferralsEmbedLinkSchema>;
diff --git a/apps/web/app/app.dub.co/embed/referrals/utils.ts b/apps/web/app/app.dub.co/embed/referrals/utils.ts
index eb56a45f18..2eb0268ab7 100644
--- a/apps/web/app/app.dub.co/embed/referrals/utils.ts
+++ b/apps/web/app/app.dub.co/embed/referrals/utils.ts
@@ -2,8 +2,10 @@ import { referralsEmbedToken } from "@/lib/embed/referrals/token-class";
import { determinePartnerDiscount } from "@/lib/partners/determine-partner-discount";
import { determinePartnerRewards } from "@/lib/partners/determine-partner-rewards";
import { RewardProps } from "@/lib/types";
+import { ReferralsEmbedLinkSchema } from "@/lib/zod/schemas/referrals-embed";
import { prisma } from "@dub/prisma";
import { notFound } from "next/navigation";
+import { z } from "zod";
export const getReferralsEmbedData = async (token: string) => {
const { programId, partnerId } = (await referralsEmbedToken.get(token)) ?? {};
@@ -56,7 +58,7 @@ export const getReferralsEmbedData = async (token: string) => {
return {
program,
- links,
+ links: z.array(ReferralsEmbedLinkSchema).parse(links),
rewards: rewards as RewardProps[],
discount,
payouts: payouts.map((payout) => ({
diff --git a/apps/web/lib/api/partners/constants.ts b/apps/web/lib/api/partners/constants.ts
new file mode 100644
index 0000000000..0438d6d8f3
--- /dev/null
+++ b/apps/web/lib/api/partners/constants.ts
@@ -0,0 +1 @@
+export const PARTNER_LINKS_LIMIT = 5;
diff --git a/apps/web/lib/zod/schemas/referrals-embed.ts b/apps/web/lib/zod/schemas/referrals-embed.ts
new file mode 100644
index 0000000000..43a1728db7
--- /dev/null
+++ b/apps/web/lib/zod/schemas/referrals-embed.ts
@@ -0,0 +1,13 @@
+import { LinkSchema } from "./links";
+
+export const ReferralsEmbedLinkSchema = LinkSchema.pick({
+ id: true,
+ domain: true,
+ key: true,
+ url: true,
+ shortLink: true,
+ clicks: true,
+ leads: true,
+ sales: true,
+ saleAmount: true,
+});