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.

Update `getLinkOrThrow` to accept `workspaceId` instead of `workspace` object.

Kiran K0dd224436538
diff --git a/apps/web/app/api/analytics/export/route.ts b/apps/web/app/api/analytics/export/route.ts
index 9c3efa1b10..3680d471f0 100644
--- a/apps/web/app/api/analytics/export/route.ts
+++ b/apps/web/app/api/analytics/export/route.ts
@@ -27,7 +27,7 @@ export const GET = withWorkspace(
if (linkId || externalId || (domain && key)) {
link = await getLinkOrThrow({
- workspace: workspace,
+ workspaceId: workspace.id,
linkId,
externalId,
domain,
diff --git a/apps/web/app/api/analytics/route.ts b/apps/web/app/api/analytics/route.ts
index cc52277426..a19915a122 100644
--- a/apps/web/app/api/analytics/route.ts
+++ b/apps/web/app/api/analytics/route.ts
@@ -47,7 +47,7 @@ export const GET = withWorkspace(
if (linkId || externalId || (domain && key)) {
link = await getLinkOrThrow({
- workspace: workspace,
+ workspaceId: workspace.id,
linkId,
externalId,
domain,
diff --git a/apps/web/app/api/dashboards/route.ts b/apps/web/app/api/dashboards/route.ts
index fa8d2b86fe..039ca9fba7 100644
--- a/apps/web/app/api/dashboards/route.ts
+++ b/apps/web/app/api/dashboards/route.ts
@@ -28,7 +28,7 @@ export const POST = withWorkspace(
const { domain, key } = domainKeySchema.parse(searchParams);
const link = await getLinkOrThrow({
- workspace,
+ workspaceId: workspace.id,
domain,
key,
});
diff --git a/apps/web/app/api/events/export/route.ts b/apps/web/app/api/events/export/route.ts
index b5a668b709..7f8dc98b3d 100644
--- a/apps/web/app/api/events/export/route.ts
+++ b/apps/web/app/api/events/export/route.ts
@@ -60,7 +60,9 @@ export const GET = withWorkspace(
}
const link =
- domain && key ? await getLinkOrThrow({ workspace, domain, key }) : null;
+ domain && key
+ ? await getLinkOrThrow({ workspaceId: workspace.id, domain, key })
+ : null;
validDateRangeForPlan({
plan: workspace.plan,
diff --git a/apps/web/app/api/events/route.ts b/apps/web/app/api/events/route.ts
index 5b1a68fd36..ecd77c3eff 100644
--- a/apps/web/app/api/events/route.ts
+++ b/apps/web/app/api/events/route.ts
@@ -24,7 +24,7 @@ export const GET = withWorkspace(
if (linkId || externalId || (domain && key)) {
link = await getLinkOrThrow({
- workspace: workspace,
+ workspaceId: workspace.id,
linkId,
externalId,
domain,
diff --git a/apps/web/app/api/links/[linkId]/dashboard/route.ts b/apps/web/app/api/links/[linkId]/dashboard/route.ts
index 9fe001341a..32965e8f01 100644
--- a/apps/web/app/api/links/[linkId]/dashboard/route.ts
+++ b/apps/web/app/api/links/[linkId]/dashboard/route.ts
@@ -11,7 +11,7 @@ export const GET = withWorkspace(
const link = await getLinkOrThrow({
linkId,
- workspace,
+ workspaceId: workspace.id,
});
const dashboard = await prisma.dashboard.findUnique({
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.ts
index 1bacf840d9..4faa318168 100644
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@ -20,7 +20,7 @@ import { NextResponse } from "next/server";
export const GET = withWorkspace(
async ({ headers, workspace, params }) => {
const link = await getLinkOrThrow({
- workspace,
+ workspaceId: workspace.id,
linkId: params.linkId,
});
@@ -57,7 +57,7 @@ export const GET = withWorkspace(
export const PATCH = withWorkspace(
async ({ req, headers, workspace, params }) => {
const link = await getLinkOrThrow({
- workspace,
+ workspaceId: workspace.id,
linkId: params.linkId,
});
@@ -173,7 +173,7 @@ export const PUT = PATCH;
export const DELETE = withWorkspace(
async ({ headers, params, workspace }) => {
const link = await getLinkOrThrow({
- workspace,
+ workspaceId: workspace.id,
linkId: params.linkId,
});
diff --git a/apps/web/app/api/links/[linkId]/transfer/route.ts b/apps/web/app/api/links/[linkId]/transfer/route.ts
index ca1643a8fe..71095db924 100644
--- a/apps/web/app/api/links/[linkId]/transfer/route.ts
+++ b/apps/web/app/api/links/[linkId]/transfer/route.ts
@@ -21,7 +21,7 @@ const transferLinkBodySchema = z.object({
export const POST = withWorkspace(
async ({ req, headers, session, params, workspace }) => {
const link = await getLinkOrThrow({
- workspace,
+ workspaceId: workspace.id,
linkId: params.linkId,
});
diff --git a/apps/web/app/api/links/info/route.ts b/apps/web/app/api/links/info/route.ts
index c3df9bb5d3..00ec4ebb6f 100644
--- a/apps/web/app/api/links/info/route.ts
+++ b/apps/web/app/api/links/info/route.ts
@@ -22,7 +22,7 @@ export const GET = withWorkspace(
}
const link = await getLinkOrThrow({
- workspace,
+ workspaceId: workspace.id,
linkId,
externalId,
domain,
diff --git a/apps/web/lib/actions/invite-partner.ts b/apps/web/lib/actions/invite-partner.ts
index e720a2c70d..f6328166a9 100644
--- a/apps/web/lib/actions/invite-partner.ts
+++ b/apps/web/lib/actions/invite-partner.ts
@@ -30,7 +30,7 @@ export const invitePartnerAction = authActionClient
}),
getLinkOrThrow({
- workspace,
+ workspaceId: workspace.id,
linkId,
}),
]);
diff --git a/apps/web/lib/api/links/get-link-or-throw.ts b/apps/web/lib/api/links/get-link-or-throw.ts
index 23d4b2ddcc..bdaeaf83a5 100644
--- a/apps/web/lib/api/links/get-link-or-throw.ts
+++ b/apps/web/lib/api/links/get-link-or-throw.ts
@@ -1,10 +1,9 @@
import { prisma } from "@/lib/prisma";
-import { WorkspaceWithUsers } from "@/lib/types";
import { Link } from "@prisma/client";
import { DubApiError } from "../errors";
interface GetLinkParams {
- workspace: Pick<WorkspaceWithUsers, "id">;
+ workspaceId: string;
linkId?: string;
externalId?: string;
domain?: string;
@@ -13,11 +12,10 @@ interface GetLinkParams {
// Find link
export const getLinkOrThrow = async (params: GetLinkParams) => {
- let { workspace, domain, key, externalId } = params;
+ let { workspaceId, domain, key, externalId } = params;
let link: Link | null = null;
const linkId = params.linkId || params.externalId || undefined;
- const { id: workspaceId } = workspace;
if (domain && (!key || key === "")) {
key = "_root";
@@ -68,7 +66,7 @@ export const getLinkOrThrow = async (params: GetLinkParams) => {
if (link.projectId !== workspaceId) {
throw new DubApiError({
code: "unauthorized",
- message: `Link does not belong to workspace ws_${workspace.id}.`,
+ message: `Link does not belong to workspace ws_${workspaceId}.`,
});
}