The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fix schema
Kiran K7f33c5eaf8dc
diff --git a/apps/web/app/api/analytics/route.ts b/apps/web/app/api/analytics/route.tsindex 5383298f8c..4cb02277fb 100644--- a/apps/web/app/api/analytics/route.ts+++ b/apps/web/app/api/analytics/route.ts@@ -2,10 +2,11 @@ import { withAuth } from "@/lib/auth";import { handleAndReturnErrorResponse } from "@/lib/errors";import prisma from "@/lib/prisma";import z, { domainKeySchema } from "@/lib/zod";+import { booleanQuerySchema } from "@/lib/zod/schemas";import { NextResponse } from "next/server";const updatePublicStatsSchema = z.object({- publicStats: z.boolean(),+ publicStats: booleanQuerySchema,});// GET /api/analytics – get the publicStats setting for a linkdiff --git a/apps/web/app/api/tags/[id]/route.ts b/apps/web/app/api/tags/[id]/route.tsindex 8bf2c0a8b2..3f293c4014 100644--- a/apps/web/app/api/tags/[id]/route.ts+++ b/apps/web/app/api/tags/[id]/route.ts@@ -1,20 +1,14 @@import { withAuth } from "@/lib/auth";import { handleAndReturnErrorResponse } from "@/lib/errors";import prisma from "@/lib/prisma";-import z from "@/lib/zod";-import { tagColorSchema } from "@/lib/zod/schemas";+import { updateTagBodySchema } from "@/lib/zod/schemas/tags";import { NextResponse } from "next/server";-const updateTagSchema = z.object({- name: z.string().min(1),- color: tagColorSchema,-});-// PUT /api/projects/[slug]/tags/[id] – update a tag for a projectexport const PUT = withAuth(async ({ req, params }) => {const { id } = params;try {- const { name, color } = updateTagSchema.parse(await req.json());+ const { name, color } = updateTagBodySchema.parse(await req.json());const response = await prisma.tag.update({where: {id,diff --git a/apps/web/lib/zod/schemas/index.ts b/apps/web/lib/zod/schemas/index.tsindex 7db9b9d48a..df4c77bd46 100644--- a/apps/web/lib/zod/schemas/index.ts+++ b/apps/web/lib/zod/schemas/index.ts@@ -1,4 +1,4 @@-import { plans, roles, tagColors } from "@/lib/types";+import { plans, roles } from "@/lib/types";import z from "@/lib/zod";export const planSchema = z.enum(plans).describe("The plan of the project.");@@ -7,11 +7,6 @@ export const roleSchema = z.enum(roles).describe("The role of the authenticated user in the project.");-// TODO: Move to tags.ts-export const tagColorSchema = z- .enum(tagColors)- .describe("The color of the tag.");-// A boolean query schema that coerces the value to a booleanexport const booleanQuerySchema = z.enum(["true", "false"])diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex da64aafb50..3d43d49950 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -1,4 +1,5 @@import z from "@/lib/zod";+import { booleanQuerySchema } from ".";export const getLinksQuerySchema = z.object({projectSlug: z@@ -31,17 +32,15 @@ export const getLinksQuerySchema = z.object({.optional().describe("The page number for pagination (each page contains 100 links)."),userId: z.string().optional().describe("The user ID to filter the links by."),- showArchived: z.coerce- .boolean()+ showArchived: booleanQuerySchema.optional()- .default(false)+ .default("false").describe("Whether to include archived links in the response. Defaults to `false` if not provided.",),- withTags: z.coerce- .boolean()+ withTags: booleanQuerySchema.optional()- .default(false)+ .default("false").describe("Whether to include tags in the response. Defaults to `false` if not provided.",),@@ -173,10 +172,7 @@ export const getLinksCountParamsSchema = z.object({userId: z.string().optional(),tagId: z.string().optional(),domain: z.string().optional(),- showArchived: z- .enum(["true", "false"])- .optional()- .transform((value) => value == "true"),+ showArchived: booleanQuerySchema.optional(),search: z.string().optional(),groupBy: z.union([z.literal("domain"), z.literal("tagId")]).optional(),});diff --git a/apps/web/lib/zod/schemas/tags.ts b/apps/web/lib/zod/schemas/tags.tsindex 26e0cc8ab6..b483a3de63 100644--- a/apps/web/lib/zod/schemas/tags.ts+++ b/apps/web/lib/zod/schemas/tags.ts@@ -1,14 +1,24 @@+import { tagColors } from "@/lib/types";import z from "@/lib/zod";+export const tagColorSchema = z+ .enum(tagColors)+ .describe("The color of the tag.");+export const createTagBodySchema = z.object({tag: z.string().min(1).describe("The name of the tag to create."),});+export const updateTagBodySchema = z.object({+ name: z.string().min(1),+ color: tagColorSchema,+});+export const tagSchema = z.object({id: z.string().describe("The unique ID of the tag."),name: z.string().describe("The name of the tag."),- color: z.string().describe("The color of the tag."),+ color: tagColorSchema.describe("The color of the tag."),}).openapi({title: "Tag",