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.

Revert back to using `dub` SDK

Steven Teyef5bce702e5b
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 350e7c8288..7ee757364e 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -1,6 +1,7 @@
import { DubApiError } from "@/lib/api/errors";
import { deleteWorkspace } from "@/lib/api/workspaces";
import { withWorkspace } from "@/lib/auth";
+import { dub } from "@/lib/dub";
import { getFeatureFlags } from "@/lib/edge-config";
import { prisma } from "@/lib/prisma";
import {
@@ -74,17 +75,9 @@ export const PATCH = withWorkspace(
// Update the workspace's referral link to use the new slug
if (workspace.referralLinkId) {
waitUntil(
- // dub.links.update(workspace.referralLinkId, {
- // key: slug,
- // }),
- fetch(`https://api.dub.co/links/${workspace.referralLinkId}`, {
- method: "PATCH",
- body: JSON.stringify({ key: slug }),
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- }).then((res) => res.json()),
+ dub.links.update(workspace.referralLinkId, {
+ key: slug,
+ }),
);
}
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
index 197a275a62..e1ebd3c963 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/referrals/stats.tsx
@@ -1,5 +1,6 @@
import { getReferralLink } from "@/lib/actions/get-referral-link";
import { getTotalEvents } from "@/lib/actions/get-total-events";
+import { dub } from "@/lib/dub";
import {
REFERRAL_CLICKS_QUOTA_BONUS,
REFERRAL_CLICKS_QUOTA_BONUS_MAX,
@@ -121,38 +122,20 @@ async function StatsInner({ slug }: { slug: string }) {
async function loadData(linkId: string) {
const [clicks, sales, totalEvents] = await Promise.all([
// Clicks timeseries
- // dub.analytics.retrieve({
- // linkId,
- // event: "clicks",
- // interval: "30d",
- // groupBy: "timeseries",
- // }) as Promise<AnalyticsTimeseries[]>,
- fetch(
- `https://api.dub.co/analytics?linkId=${linkId}&event=clicks&interval=30d&groupBy=timeseries`,
- {
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- },
- ).then((res) => res.json()) as Promise<AnalyticsTimeseries[]>,
+ dub.analytics.retrieve({
+ linkId,
+ event: "clicks",
+ interval: "30d",
+ groupBy: "timeseries",
+ }) as Promise<AnalyticsTimeseries[]>,
// Sales timeseries
- // dub.analytics.retrieve({
- // linkId,
- // event: "sales",
- // interval: "30d",
- // groupBy: "timeseries",
- // }) as Promise<AnalyticsTimeseries[]>,
- fetch(
- `https://api.dub.co/analytics?linkId=${linkId}&event=sales&interval=30d&groupBy=timeseries`,
- {
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- },
- ).then((res) => res.json()) as Promise<AnalyticsTimeseries[]>,
+ dub.analytics.retrieve({
+ linkId,
+ event: "sales",
+ interval: "30d",
+ groupBy: "timeseries",
+ }) as Promise<AnalyticsTimeseries[]>,
// Total events
getTotalEvents(linkId),
diff --git a/apps/web/lib/actions/generate-referral-link.ts b/apps/web/lib/actions/generate-referral-link.ts
index bbd19aaaef..40f242de11 100644
--- a/apps/web/lib/actions/generate-referral-link.ts
+++ b/apps/web/lib/actions/generate-referral-link.ts
@@ -1,8 +1,8 @@
"use server";
import { linkConstructor } from "@dub/utils";
-import { Link } from "dub/dist/commonjs/models/components";
import { z } from "zod";
+import { dub } from "../dub";
import { prisma } from "../prisma";
import { authActionClient } from "./safe-action";
@@ -17,29 +17,14 @@ export const generateReferralLink = authActionClient
const { workspace } = ctx;
try {
- // const createdLink = await dub.links.create({
- // domain: "refer.dub.co",
- // key: workspace.slug,
- // url: "https://dub.co",
- // externalId: `ws_${workspace.id}`,
- // tagIds: ["cm000srqx0004o6ldehod07zc"],
- // trackConversion: true,
- // });
- const createdLink = (await fetch(`https://api.dub.co/links`, {
- method: "POST",
- body: JSON.stringify({
- domain: "refer.dub.co",
- key: workspace.slug,
- url: "https://dub.co",
- externalId: `ws_${workspace.id}`,
- tagIds: ["cm000srqx0004o6ldehod07zc"],
- trackConversion: true,
- }),
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- }).then((res) => res.json())) as Link;
+ const createdLink = await dub.links.create({
+ domain: "refer.dub.co",
+ key: workspace.slug,
+ url: "https://dub.co",
+ externalId: `ws_${workspace.id}`,
+ tagIds: ["cm000srqx0004o6ldehod07zc"],
+ trackConversion: true,
+ });
await prisma.project.update({
where: {
diff --git a/apps/web/lib/actions/get-conversion-events.ts b/apps/web/lib/actions/get-conversion-events.ts
index f4b64b3714..aaadd28577 100644
--- a/apps/web/lib/actions/get-conversion-events.ts
+++ b/apps/web/lib/actions/get-conversion-events.ts
@@ -6,6 +6,7 @@ import {
SaleEvent,
} from "dub/dist/commonjs/models/components";
import { EventType } from "../analytics/types";
+import { dub } from "../dub";
export type ConversionEvent = ClickEvent | LeadEvent | SaleEvent;
@@ -18,19 +19,10 @@ export const getConversionEvents = async ({
event: EventType;
page: number;
}) => {
- // return (await dub.events.list({
- // linkId,
- // event,
- // interval: "all",
- // page,
- // })) as ConversionEvent[];
- return (await fetch(
- `https://api.dub.co/events?linkId=${linkId}&event=${event}&interval=all&page=${page}`,
- {
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- },
- ).then((res) => res.json())) as ConversionEvent[];
+ return (await dub.events.list({
+ linkId,
+ event,
+ interval: "all",
+ page,
+ })) as ConversionEvent[];
};
diff --git a/apps/web/lib/actions/get-referral-link.ts b/apps/web/lib/actions/get-referral-link.ts
index 4ff6487132..5af75ebec7 100644
--- a/apps/web/lib/actions/get-referral-link.ts
+++ b/apps/web/lib/actions/get-referral-link.ts
@@ -1,7 +1,7 @@
"use server";
+import { dub } from "@/lib/dub";
import { prisma } from "@/lib/prisma";
-import { Link } from "dub/dist/commonjs/models/components";
export const getReferralLink = async (slug: string) => {
const workspace = await prisma.project.findUnique({
@@ -12,13 +12,7 @@ export const getReferralLink = async (slug: string) => {
if (!workspace || !workspace.referralLinkId) {
return null;
}
- // return await dub.links.get({
- // linkId: workspace.referralLinkId,
- // });
- return (await fetch(`https://api.dub.co/links/${workspace.referralLinkId}`, {
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- }).then((res) => res.json())) as Promise<Link>;
+ return await dub.links.get({
+ linkId: workspace.referralLinkId,
+ });
};
diff --git a/apps/web/lib/actions/get-total-events.ts b/apps/web/lib/actions/get-total-events.ts
index e93b48724a..7d29ded170 100644
--- a/apps/web/lib/actions/get-total-events.ts
+++ b/apps/web/lib/actions/get-total-events.ts
@@ -1,20 +1,12 @@
"use server";
+import { dub } from "@/lib/dub";
import { AnalyticsCount } from "dub/dist/commonjs/models/components";
export const getTotalEvents = async (linkId: string) => {
- // return (await dub.analytics.retrieve({
- // linkId,
- // event: "composite",
- // interval: "all_unfiltered",
- // })) as AnalyticsCount;
- return (await fetch(
- `https://api.dub.co/analytics?linkId=${linkId}&event=composite&interval=all_unfiltered`,
- {
- headers: {
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- "Content-Type": "application/json",
- },
- },
- ).then((res) => res.json())) as AnalyticsCount;
+ return (await dub.analytics.retrieve({
+ linkId,
+ event: "composite",
+ interval: "all_unfiltered",
+ })) as AnalyticsCount;
};
diff --git a/apps/web/lib/api/workspaces.ts b/apps/web/lib/api/workspaces.ts
index 8d65291b21..5f134f604f 100644
--- a/apps/web/lib/api/workspaces.ts
+++ b/apps/web/lib/api/workspaces.ts
@@ -209,9 +209,6 @@ export async function deleteWorkspaceAdmin(
archived: true,
}),
// delete the workspace
- // archived: true,
- // }),
- // delete the workspace
prisma.project.delete({
where: {
slug: workspace.slug,