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.

wip

Kiran Kf3e6f3873242
diff --git a/apps/web/app/admin.dub.co/actions.ts b/apps/web/app/admin.dub.co/actions.ts
index af4c525ed1..c374b20b2a 100644
--- a/apps/web/app/admin.dub.co/actions.ts
+++ b/apps/web/app/admin.dub.co/actions.ts
@@ -174,8 +174,8 @@ export async function banUser(data: FormData) {
deleteProject({
id: project.id,
slug: project.slug,
- stripeId: project.stripeId || undefined,
- logo: project.logo || undefined,
+ stripeId: project.stripeId || null,
+ logo: project.logo || null,
}),
),
);
diff --git a/apps/web/app/api/projects/[slug]/route.ts b/apps/web/app/api/projects/[slug]/route.ts
index 4a7a0d3fb3..d1e1e2f994 100644
--- a/apps/web/app/api/projects/[slug]/route.ts
+++ b/apps/web/app/api/projects/[slug]/route.ts
@@ -4,10 +4,17 @@ import prisma from "@/lib/prisma";
import { deleteProject } from "@/lib/api/projects";
import { DEFAULT_REDIRECTS, validSlugRegex } from "@dub/utils";
import { isReservedKey } from "@/lib/edge-config";
+import { ErrorResponse, handleApiError } from "@/lib/errors";
+import { Project } from "@/lib/zod/schemas/projects";
// GET /api/projects/[slug] – get a specific project
export const GET = withAuth(async ({ project, headers }) => {
- return NextResponse.json(project, { headers });
+ try {
+ return NextResponse.json<{ data: Project }>({ data: project }, { headers });
+ } catch (err) {
+ const { error, status } = handleApiError(err);
+ return NextResponse.json<ErrorResponse>({ error }, { headers, status });
+ }
});
// PUT /api/projects/[slug] – update a specific project
diff --git a/apps/web/app/api/projects/route.ts b/apps/web/app/api/projects/route.ts
index 74e6f311ab..9647a1656c 100644
--- a/apps/web/app/api/projects/route.ts
+++ b/apps/web/app/api/projects/route.ts
@@ -13,30 +13,37 @@ import {
FREE_PROJECTS_LIMIT,
validSlugRegex,
} from "@dub/utils";
+import { Project } from "@/lib/zod/schemas/projects";
+import { ErrorResponse, handleApiError } from "@/lib/errors";
// GET /api/projects - get all projects for the current user
export const GET = withSession(async ({ session }) => {
- const projects = await prisma.project.findMany({
- where: {
- users: {
- some: {
- userId: session.user.id,
+ try {
+ const projects = await prisma.project.findMany({
+ where: {
+ users: {
+ some: {
+ userId: session.user.id,
+ },
},
},
- },
- include: {
- domains: true,
- users: {
- where: {
- userId: session.user.id,
- },
- select: {
- role: true,
+ include: {
+ domains: true,
+ users: {
+ where: {
+ userId: session.user.id,
+ },
+ select: {
+ role: true,
+ },
},
},
- },
- });
- return NextResponse.json(projects);
+ });
+ return NextResponse.json<{ data: Project[] }>({ data: projects });
+ } catch (err) {
+ const { error, status } = handleApiError(err);
+ return NextResponse.json<ErrorResponse>({ error }, { status });
+ }
});
export const POST = withSession(async ({ req, session }) => {
diff --git a/apps/web/lib/errors.ts b/apps/web/lib/errors.ts
index e703fe77ae..3c51260ce7 100644
--- a/apps/web/lib/errors.ts
+++ b/apps/web/lib/errors.ts
@@ -2,7 +2,7 @@ import { ZodError } from "zod";
import { generateErrorMessage } from "zod-error";
import { PrismaClientKnownRequestError } from "@prisma/client/runtime/library";
-import { z } from "./zod";
+import z from "./zod";
const ErrorCode = z.enum([
"bad_request",
diff --git a/apps/web/lib/swr/use-projects.ts b/apps/web/lib/swr/use-projects.ts
index 6af3741e2b..8983cd0602 100644
--- a/apps/web/lib/swr/use-projects.ts
+++ b/apps/web/lib/swr/use-projects.ts
@@ -3,7 +3,7 @@ import { fetcher } from "@dub/utils";
import useSWR from "swr";
export default function useProjects() {
- const { data, error } = useSWR<ProjectWithDomainProps[]>(
+ const { data, error } = useSWR<{ data: ProjectWithDomainProps[] }>(
"/api/projects",
fetcher,
{
@@ -11,7 +11,7 @@ export default function useProjects() {
},
);
- const projects = data?.map((project) => ({
+ const projects = data?.data.map((project) => ({
...project,
isOwner: project?.users && project.users[0].role === "owner",
primaryDomain:
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 2287375900..8c0bc0e8a7 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -48,7 +48,7 @@ export interface ProjectProps {
id: string;
name: string;
slug: string;
- logo?: string;
+ logo: string | null;
usage: number;
usageLimit: number;
linksUsage: number;
@@ -57,7 +57,7 @@ export interface ProjectProps {
tagsLimit: number;
usersLimit: number;
plan: PlanProps;
- stripeId?: string;
+ stripeId: string | null;
billingCycleStart: number;
createdAt: Date;
domains: {
diff --git a/apps/web/lib/zod/index.ts b/apps/web/lib/zod/index.ts
index 7a742a2c97..ae0541a9c7 100644
--- a/apps/web/lib/zod/index.ts
+++ b/apps/web/lib/zod/index.ts
@@ -1,6 +1,6 @@
-import { z } from "zod";
+import * as z from "zod";
import { extendZodWithOpenApi } from "zod-openapi";
extendZodWithOpenApi(z);
-export { z };
+export default z;
diff --git a/apps/web/lib/zod/openapi/index.ts b/apps/web/lib/zod/openapi/index.ts
index 6bf04ef516..fa46ca9af1 100644
--- a/apps/web/lib/zod/openapi/index.ts
+++ b/apps/web/lib/zod/openapi/index.ts
@@ -1,6 +1,7 @@
import { createDocument } from "zod-openapi";
import { TagSchemaOpenApi, tagPaths } from "../schemas/tags";
+import { ProjectSchemaOpenApi, projectPaths } from "../schemas/projects";
export const openAPIDocument = createDocument({
openapi: "3.0.0",
@@ -27,11 +28,12 @@ export const openAPIDocument = createDocument({
],
paths: {
...tagPaths,
- // TODO: Add remaining paths
+ ...projectPaths,
},
components: {
schemas: {
TagSchemaOpenApi,
+ ProjectSchemaOpenApi,
},
},
});
diff --git a/apps/web/lib/zod/schemas/projects.ts b/apps/web/lib/zod/schemas/projects.ts
index e69de29bb2..efac555b87 100644
--- a/apps/web/lib/zod/schemas/projects.ts
+++ b/apps/web/lib/zod/schemas/projects.ts
@@ -0,0 +1,77 @@
+import z from "@/lib/zod";
+import { ProjectSchema } from "prisma/zod";
+import { ZodOpenApiOperationObject, ZodOpenApiPathsObject } from "zod-openapi";
+
+export const ProjectSchemaOpenApi = ProjectSchema.pick({
+ id: true,
+ name: true,
+ slug: true,
+ logo: true,
+ usage: true,
+ usageLimit: true,
+ plan: true,
+ stripeId: true,
+ billingCycleStart: true,
+ createdAt: true,
+}).openapi({
+ title: "Project",
+ properties: {
+ id: {
+ description: "The unique ID of the project.",
+ },
+ name: {
+ description: "The name of the project.",
+ },
+ slug: {
+ description: "The slug of the project.",
+ },
+ logo: {
+ description: "The logo of the project.",
+ },
+ usage: {
+ description: "The usage of the project.",
+ },
+ usageLimit: {
+ description: "The usage limit of the project.",
+ },
+ plan: {
+ description: "The plan of the project.",
+ },
+ stripeId: {
+ description: "The Stripe ID of the project.",
+ },
+ billingCycleStart: {
+ description:
+ "The date and time when the billing cycle starts for the project.",
+ },
+ createdAt: {
+ description: "The date and time when the project was created.",
+ },
+ },
+});
+
+export type Project = z.infer<typeof ProjectSchemaOpenApi>;
+
+export const getProjects: ZodOpenApiOperationObject = {
+ operationId: "getProjects",
+ summary: "Retrieve a list of projects",
+ description: "Retrieve a list of projects for the authenticated user.",
+ responses: {
+ "200": {
+ description: "The projects were retrieved",
+ content: {
+ "application/json": {
+ schema: z.object({
+ data: z.array(ProjectSchemaOpenApi),
+ }),
+ },
+ },
+ },
+ },
+};
+
+export const projectPaths: ZodOpenApiPathsObject = {
+ "/projects": {
+ get: getProjects,
+ },
+};
diff --git a/apps/web/lib/zod/schemas/tags.ts b/apps/web/lib/zod/schemas/tags.ts
index 2e70184a58..479aeb5961 100644
--- a/apps/web/lib/zod/schemas/tags.ts
+++ b/apps/web/lib/zod/schemas/tags.ts
@@ -1,7 +1,6 @@
-import { ZodOpenApiOperationObject, ZodOpenApiPathsObject } from "zod-openapi";
-
-import { z } from "@/lib/zod";
+import z from "@/lib/zod";
import { TagSchema } from "prisma/zod";
+import { ZodOpenApiOperationObject, ZodOpenApiPathsObject } from "zod-openapi";
export const TagSchemaOpenApi = TagSchema.pick({
id: true,
diff --git a/apps/web/ui/links/link-card.tsx b/apps/web/ui/links/link-card.tsx
index a5829f6ef1..953836dde0 100644
--- a/apps/web/ui/links/link-card.tsx
+++ b/apps/web/ui/links/link-card.tsx
@@ -355,7 +355,7 @@ export default function LinkCard({
user?.email && (
<CopyButton
value={user.email}
- icon={Mail}
+ // icon={Mail}
className="[&>*]:w-3 [&>*]:h-3"
/>
)}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index ecbfcae553..3abd186de5 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -338,9 +338,6 @@ importers:
typescript:
specifier: ^5.1.6
version: 5.1.6
- zod-prisma-types:
- specifier: ^3.1.6
- version: 3.1.6
packages/tailwind-config:
dependencies:
@@ -4688,10 +4685,6 @@ packages:
prisma: 5.2.0
dev: false
- /@prisma/[email protected]:
- resolution: {integrity: sha512-yAHFSFCg8KVoL0oRUno3m60GAjsUKYUDkQ+9BA2X2JfVR3kRVSJFc/GpQ2fSORi4pSHZR9orfM4UC9OVXIFFTA==}
- dev: true
-
/@prisma/engines-version@5.2.0-25.2804dc98259d2ea960602aca6b8e7fdc03c1758f:
resolution: {integrity: sha512-jsnKT5JIDIE01lAeCj2ghY9IwxkedhKNvxQeoyLs6dr4ZXynetD0vTy7u6wMJt8vVPv8I5DPy/I4CFaoXAgbtg==}
dev: false
@@ -4701,12 +4694,6 @@ packages:
requiresBuild: true
dev: false
- /@prisma/[email protected]:
- resolution: {integrity: sha512-WMdEUPpPYxUGruRQM6e6IVTWXFjt1hHdF/m2TO7pWxhPo7/ZeoTOF9fH8JsvVSV78DYLOQkx9osjFLXZu447Kw==}
- dependencies:
- '@prisma/debug': 5.9.1
- dev: true
-
/@protobufjs/[email protected]:
resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==}
dev: false
@@ -9128,10 +9115,6 @@ packages:
phenomenon: 1.6.0
dev: false
- resolution: {integrity: sha512-q4dMFMlXtKR3XNBHyMHt/3pwYNA69EDk00lloMOaaUMKPUXBw6lpXtbu3MMVG6/uOihGnRDOlkyqsONEUj60+w==}
- dev: true
-
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
dependencies:
@@ -17084,18 +17067,9 @@ packages:
zod: 3.22.4
dev: false
- resolution: {integrity: sha512-ySaG91RraTm4J19zfvuX6S3OxhDMlK4dTfYWM4rS+4AlEGqDqGu5BbIn2trjTDt8OiCMBHoIjZmRXPKQCyNApA==}
- hasBin: true
- dependencies:
- '@prisma/generator-helper': 5.9.1
- code-block-writer: 12.0.0
- lodash: 4.17.21
- zod: 3.22.4
- dev: true
-
resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==}
+ dev: false
resolution: {integrity: sha512-PIJDIZKtokhof+9+60cpockVOq05sJzHCriyvaLBmEJixseQ1a5Kdov6fWZfWOu5SK9c+FhH1jU0tntLxRJYMA==}