The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add workspaceIdSchema and update descriptions in openapi files
Kiran Kaa1c13cf85d9
diff --git a/apps/web/lib/openapi/analytics/browser.ts b/apps/web/lib/openapi/analytics/browser.tsindex b7d406d31a..39ebfe73ef 100644--- a/apps/web/lib/openapi/analytics/browser.ts+++ b/apps/web/lib/openapi/analytics/browser.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getBrowserAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the top browsers by number of clicks for a link, a domain, or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/city.ts b/apps/web/lib/openapi/analytics/city.tsindex c356574afc..4d9f9b1dd7 100644--- a/apps/web/lib/openapi/analytics/city.ts+++ b/apps/web/lib/openapi/analytics/city.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { COUNTRY_CODES } from "@dub/utils";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -10,7 +10,7 @@ export const getCityAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the top countries by number of clicks for a link, a domain, or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/clicks.ts b/apps/web/lib/openapi/analytics/clicks.tsindex 5d823570d7..f930fa6f91 100644--- a/apps/web/lib/openapi/analytics/clicks.ts+++ b/apps/web/lib/openapi/analytics/clicks.ts@@ -1,4 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";+import { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -8,7 +9,7 @@ export const getClicksAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the number of clicks for a link, a domain, or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/country.ts b/apps/web/lib/openapi/analytics/country.tsindex 0a293f4140..3a12836e13 100644--- a/apps/web/lib/openapi/analytics/country.ts+++ b/apps/web/lib/openapi/analytics/country.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { COUNTRY_CODES } from "@dub/utils";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -10,7 +10,7 @@ export const getCountryAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the top countries by number of clicks for a link, a domain, or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/device.ts b/apps/web/lib/openapi/analytics/device.tsindex b3e422d5ad..af75ae6ef9 100644--- a/apps/web/lib/openapi/analytics/device.ts+++ b/apps/web/lib/openapi/analytics/device.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getDeviceAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the top devices by number of clicks for a link, a domain, or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/os.ts b/apps/web/lib/openapi/analytics/os.tsindex 5b52e81c2f..f2ce64867a 100644--- a/apps/web/lib/openapi/analytics/os.ts+++ b/apps/web/lib/openapi/analytics/os.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getOSAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the top OS by number of clicks for a link, a domain, or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/referer.ts b/apps/web/lib/openapi/analytics/referer.tsindex 2e1e400d8f..b17e5945bb 100644--- a/apps/web/lib/openapi/analytics/referer.ts+++ b/apps/web/lib/openapi/analytics/referer.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getRefererAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the top referers by number of clicks for a link, a domain, or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/timeseries.ts b/apps/web/lib/openapi/analytics/timeseries.tsindex 50a9ca6797..18f0b7af5d 100644--- a/apps/web/lib/openapi/analytics/timeseries.ts+++ b/apps/web/lib/openapi/analytics/timeseries.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getTimeseriesAnalytics: ZodOpenApiOperationObject = {description:"Retrieve the number of clicks for a link, a domain, or the authenticated workspace over a period of time.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/top-links.ts b/apps/web/lib/openapi/analytics/top-links.tsindex cbffa97b9e..5f0aa2e558 100644--- a/apps/web/lib/openapi/analytics/top-links.ts+++ b/apps/web/lib/openapi/analytics/top-links.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getTopLinks: ZodOpenApiOperationObject = {description:"Retrieve the top links by number of clicks for a domain or the authenticated workspace.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/analytics/top-urls.ts b/apps/web/lib/openapi/analytics/top-urls.tsindex 1d54467903..006c5c8370 100644--- a/apps/web/lib/openapi/analytics/top-urls.ts+++ b/apps/web/lib/openapi/analytics/top-urls.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getAnalyticsQuerySchema } from "@/lib/zod/schemas/analytics";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getTopURLs: ZodOpenApiOperationObject = {description:"Retrieve the top URLs by number of clicks for a given short link.",requestParams: {- query: getAnalyticsQuerySchema,+ query: workspaceIdSchema.merge(getAnalyticsQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/links/delete-link.ts b/apps/web/lib/openapi/links/delete-link.tsindex 2520035b54..16a1c89280 100644--- a/apps/web/lib/openapi/links/delete-link.ts+++ b/apps/web/lib/openapi/links/delete-link.ts@@ -12,7 +12,7 @@ export const deleteLink: ZodOpenApiOperationObject = {query: z.object({workspaceId: z.string()- .describe("The ID of the workspace to create the link for."),+ .describe("The ID of the workspace that the link belongs to."),}),path: z.object({linkId: z.string().openapi({diff --git a/apps/web/lib/openapi/links/edit-link.ts b/apps/web/lib/openapi/links/edit-link.tsindex 6e72f49688..1c61493819 100644--- a/apps/web/lib/openapi/links/edit-link.ts+++ b/apps/web/lib/openapi/links/edit-link.ts@@ -12,7 +12,7 @@ export const editLink: ZodOpenApiOperationObject = {query: z.object({workspaceId: z.string()- .describe("The ID of the workspace to create the link for."),+ .describe("The ID of the workspace that the link belongs to."),}),path: z.object({linkId: z.string().openapi({diff --git a/apps/web/lib/openapi/links/get-link-info.ts b/apps/web/lib/openapi/links/get-link-info.tsindex 21d9693187..99a89605d8 100644--- a/apps/web/lib/openapi/links/get-link-info.ts+++ b/apps/web/lib/openapi/links/get-link-info.ts@@ -1,6 +1,7 @@import { ZodOpenApiOperationObject } from "zod-openapi";import { openApiErrorResponses } from "@/lib/openapi/responses";+import { workspaceIdSchema } from "@/lib/zod";import { getLinkInfoQuerySchema, LinkSchema } from "@/lib/zod/schemas/links";export const getLinkInfo: ZodOpenApiOperationObject = {@@ -8,7 +9,7 @@ export const getLinkInfo: ZodOpenApiOperationObject = {summary: "Retrieve a link",description: "Retrieve the info for a link from their domain and key.",requestParams: {- query: getLinkInfoQuerySchema,+ query: workspaceIdSchema.merge(getLinkInfoQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/links/get-links-count.ts b/apps/web/lib/openapi/links/get-links-count.tsindex 7f2ccc5df3..057f98734c 100644--- a/apps/web/lib/openapi/links/get-links-count.ts+++ b/apps/web/lib/openapi/links/get-links-count.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getLinksCountQuerySchema, LinkSchema } from "@/lib/zod/schemas/links";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getLinksCount: ZodOpenApiOperationObject = {description:"Retrieve the number of links for the authenticated workspace. The provided query parameters allow filtering the returned links.",requestParams: {- query: getLinksCountQuerySchema,+ query: workspaceIdSchema.merge(getLinksCountQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/openapi/links/get-links.ts b/apps/web/lib/openapi/links/get-links.tsindex e80847fa03..e1fed6e06b 100644--- a/apps/web/lib/openapi/links/get-links.ts+++ b/apps/web/lib/openapi/links/get-links.ts@@ -1,5 +1,5 @@import { openApiErrorResponses } from "@/lib/openapi/responses";-import z from "@/lib/zod";+import z, { workspaceIdSchema } from "@/lib/zod";import { getLinksQuerySchema, LinkSchema } from "@/lib/zod/schemas/links";import { ZodOpenApiOperationObject } from "zod-openapi";@@ -9,7 +9,7 @@ export const getLinks: ZodOpenApiOperationObject = {description:"Retrieve a list of links for the authenticated workspace. The list will be paginated and the provided query parameters allow filtering the returned links.",requestParams: {- query: getLinksQuerySchema,+ query: workspaceIdSchema.merge(getLinksQuerySchema),},responses: {"200": {diff --git a/apps/web/lib/zod/index.ts b/apps/web/lib/zod/index.tsindex 057a09b53c..66105b0c43 100644--- a/apps/web/lib/zod/index.ts+++ b/apps/web/lib/zod/index.ts@@ -11,4 +11,11 @@ export const domainKeySchema = z.object({message: "Invalid domain format",}),key: z.string().min(1),-});\ No newline at end of file+});++export const workspaceIdSchema = z.object({+ workspaceId: z+ .string()+ .min(1, "Workspace ID is required.")+ .describe("The ID of the workspace the link belongs to."),+});diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.tsindex 7c86d79303..8030ba8766 100644--- a/apps/web/lib/zod/schemas/analytics.ts+++ b/apps/web/lib/zod/schemas/analytics.ts@@ -4,10 +4,6 @@ import { COUNTRY_CODES } from "@dub/utils";import { booleanQuerySchema } from ".";export const getAnalyticsQuerySchema = z.object({- workspaceId: z- .string()- .optional() // TODO: This should be required- .describe("The ID of the workspace that the link belongs to."),domain: z.string().optional().describe("The domain of the short link."),key: z.string().optional().describe("The short link slug."),interval: zdiff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.tsindex ecbe4926f1..87d2b38555 100644--- a/apps/web/lib/zod/schemas/links.ts+++ b/apps/web/lib/zod/schemas/links.ts@@ -2,10 +2,7 @@ import z from "@/lib/zod";import { booleanQuerySchema } from ".";import { TagSchema } from "./tags";-const LinksQuerySchema = {- workspaceId: z- .string()- .describe("The ID of the workspace that the link belongs to."),+const LinksQuerySchema = z.object({domain: z.string().optional()@@ -40,36 +37,36 @@ const LinksQuerySchema = {.describe("Whether to include tags in the response. Defaults to `false` if not provided.",),-};--export const getLinksQuerySchema = z.object({- ...LinksQuerySchema,- sort: z- .enum(["createdAt", "clicks", "lastClicked"])- .optional()- .default("createdAt")- .describe(- "The field to sort the links by. The default is `createdAt`, and sort order is always descending.",- ),- page: z.coerce- .number()- .optional()- .describe("The page number for pagination (each page contains 100 links)."),});-export const getLinksCountQuerySchema = z.object({- ...LinksQuerySchema,- groupBy: z- .union([z.literal("domain"), z.literal("tagId")])- .optional()- .describe("The field to group the links by."),-});+export const getLinksQuerySchema = LinksQuerySchema.merge(+ z.object({+ sort: z+ .enum(["createdAt", "clicks", "lastClicked"])+ .optional()+ .default("createdAt")+ .describe(+ "The field to sort the links by. The default is `createdAt`, and sort order is always descending.",+ ),+ page: z.coerce+ .number()+ .optional()+ .describe(+ "The page number for pagination (each page contains 100 links).",+ ),+ }),+);++export const getLinksCountQuerySchema = LinksQuerySchema.merge(+ z.object({+ groupBy: z+ .union([z.literal("domain"), z.literal("tagId")])+ .optional()+ .describe("The field to group the links by."),+ }),+);export const getLinkInfoQuerySchema = z.object({- workspaceId: z- .string()- .min(1, "Workspace id is required.")- .describe("The ID of the workspace to retrieve the links for."),domain: z.string().min(1, "Domain is required.")