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.

placeholder

Kiran K4a504b813a4a
diff --git a/apps/web/lib/zod/schemas/domains.ts b/apps/web/lib/zod/schemas/domains.ts
index 7ab19ed9d0..3aee962347 100644
--- a/apps/web/lib/zod/schemas/domains.ts
+++ b/apps/web/lib/zod/schemas/domains.ts
@@ -92,13 +92,13 @@ export const createDomainBodySchema = z.object({
.max(190, "slug cannot be longer than 190 characters.")
.describe("Name of the domain.")
.openapi({ example: "acme.com" }),
- expiredUrl: parseUrlSchemaAllowEmpty
+ expiredUrl: parseUrlSchemaAllowEmpty()
.nullish()
.describe(
"Redirect users to a specific URL when any link under this domain has expired.",
)
.openapi({ example: "https://acme.com/expired" }),
- notFoundUrl: parseUrlSchemaAllowEmpty
+ notFoundUrl: parseUrlSchemaAllowEmpty()
.nullish()
.describe(
"Redirect users to a specific URL when a link under this domain doesn't exist.",
@@ -112,7 +112,7 @@ export const createDomainBodySchema = z.object({
"Whether to archive this domain. `false` will unarchive a previously archived domain.",
)
.openapi({ example: false }),
- placeholder: parseUrlSchemaAllowEmpty
+ placeholder: parseUrlSchemaAllowEmpty({ maxLength: 100 })
.nullish()
.default("https://dub.co/help/article/what-is-dub")
.describe(
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index a2246e26c1..660a58b7c0 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -133,7 +133,7 @@ export const domainKeySchema = z.object({
});
export const createLinkBodySchema = z.object({
- url: parseUrlSchemaAllowEmpty
+ url: parseUrlSchemaAllowEmpty()
.describe("The destination URL of the short link.")
.openapi({
example: "https://google.com",
diff --git a/apps/web/lib/zod/schemas/utils.ts b/apps/web/lib/zod/schemas/utils.ts
index ff82f56751..5f63b48534 100644
--- a/apps/web/lib/zod/schemas/utils.ts
+++ b/apps/web/lib/zod/schemas/utils.ts
@@ -6,9 +6,21 @@ export const parseUrlSchema = z
.transform((v) => getUrlFromString(v))
.refine((v) => isValidUrl(v), { message: "Invalid URL" });
-export const parseUrlSchemaAllowEmpty = z
- .string()
- .transform((v) => getUrlFromString(v));
+export const parseUrlSchemaAllowEmpty = ({
+ maxLength,
+}: {
+ maxLength?: number;
+} = {}) => {
+ let schema = z.string();
+
+ if (maxLength) {
+ schema = schema.max(maxLength, {
+ message: `Must be ${maxLength} or fewer characters long`,
+ });
+ }
+
+ return schema.transform((v) => getUrlFromString(v));
+};
export const parseDateSchema = z
.string()