The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Improve integration creation flow
Steven Tey87494f438316
diff --git a/apps/web/lib/zod/schemas/images.ts b/apps/web/lib/zod/schemas/images.tsindex 1fb7dc433a..2651ad4917 100644--- a/apps/web/lib/zod/schemas/images.ts+++ b/apps/web/lib/zod/schemas/images.ts@@ -2,24 +2,33 @@ import { GOOGLE_FAVICON_URL, R2_URL } from "@dub/utils";import { fileTypeFromBuffer } from "file-type";import * as z from "zod/v4";-/** Raster data-URL prefix for link preview images (base64ImageSchema, preprocess, metatags). */-export const linkPreviewImageBase64PrefixRegex =- /^data:image\/(png|jpeg|jpg|gif|webp);base64,/i;-const allowedImageTypes = ["image/png","image/jpeg","image/jpg","image/gif","image/webp",+ "image/avif",];+const allowedImageFormats = allowedImageTypes+ .map((type) => type.replace("image/", ""))+ .join(", ");++export const invalidImageFormatMessage = `Invalid image format, supports only ${allowedImageFormats}.`;++/** Raster data-URL prefix for link preview images (base64ImageSchema, preprocess, metatags). */+export const linkPreviewImageBase64PrefixRegex = new RegExp(+ `^data:image/(${allowedImageTypes.map((type) => type.replace("image/", "")).join("|")});base64,`,+ "i",+);+// Base64 encoded imageexport const base64ImageSchema = z.string().trim().regex(linkPreviewImageBase64PrefixRegex, {- message: "Invalid image format, supports only png, jpeg, jpg, gif, webp.",+ message: invalidImageFormatMessage,}).refine(async (str) => {@@ -39,7 +48,7 @@ export const base64ImageSchema = z}},{- message: "Invalid image format, supports only png, jpeg, jpg, gif, webp.",+ message: invalidImageFormatMessage,},).transform((v) => v || null);diff --git a/apps/web/lib/zod/schemas/integration.ts b/apps/web/lib/zod/schemas/integration.tsindex 0d60875046..1873aac1ba 100644--- a/apps/web/lib/zod/schemas/integration.ts+++ b/apps/web/lib/zod/schemas/integration.ts@@ -57,8 +57,8 @@ export const createIntegrationSchema = z.object({.nullish(),readme: z.string()- .max(1000, {- message: "must be less than 1000 characters",+ .max(5000, {+ message: "must be less than 5000 characters",}).nullish(),screenshots: zdiff --git a/apps/web/tests/misc/base64.test.ts b/apps/web/tests/misc/base64.test.tsindex 1d6fce9b7f..9668a5f8fd 100644--- a/apps/web/tests/misc/base64.test.ts+++ b/apps/web/tests/misc/base64.test.ts@@ -1,4 +1,7 @@-import { base64ImageSchema } from "@/lib/zod/schemas/images";+import {+ base64ImageSchema,+ invalidImageFormatMessage,+} from "@/lib/zod/schemas/images";import { describe, expect, it } from "vitest";describe("base64ImageSchema", () => {@@ -10,20 +13,29 @@ describe("base64ImageSchema", () => {).resolves.not.toThrow();});+ it("should validate a correct base64 AVIF image", async () => {+ // ISO BMFF ftyp box with the avif brand — enough for file-type detection+ const avifHeader = Buffer.alloc(64);+ avifHeader.writeUInt32BE(0x1c, 0);+ avifHeader.write("ftypavif", 4);+ const validAvifImage = `data:image/avif;base64,${avifHeader.toString("base64")}`;+ await expect(+ base64ImageSchema.parseAsync(validAvifImage),+ ).resolves.not.toThrow();+ });+it("should reject an invalid image type", async () => {const invalidImageType ="data:image/invalid;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==";await expect(base64ImageSchema.parseAsync(invalidImageType),- ).rejects.toThrow(- "Invalid image format, supports only png, jpeg, jpg, gif, webp.",- );+ ).rejects.toThrow(invalidImageFormatMessage);});it("should reject malformed base64 data", async () => {const malformedBase64 = "data:image/png;base64,invalid-base64-data";await expect(base64ImageSchema.parseAsync(malformedBase64)).rejects.toThrow(- "Invalid image format, supports only png, jpeg, jpg, gif, webp.",+ invalidImageFormatMessage,);});@@ -31,7 +43,7 @@ describe("base64ImageSchema", () => {const noPrefix ="iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==";await expect(base64ImageSchema.parseAsync(noPrefix)).rejects.toThrow(- "Invalid image format, supports only png, jpeg, jpg, gif, webp.",+ invalidImageFormatMessage,);});@@ -41,7 +53,7 @@ describe("base64ImageSchema", () => {"data:image/png;base64," +Buffer.from("This is not an image").toString("base64");await expect(base64ImageSchema.parseAsync(textContent)).rejects.toThrow(- "Invalid image format, supports only png, jpeg, jpg, gif, webp.",+ invalidImageFormatMessage,);});@@ -70,7 +82,7 @@ describe("base64ImageSchema", () => {).toString("base64");await expect(base64ImageSchema.parseAsync(xssPayload)).rejects.toThrow(- "Invalid image format, supports only png, jpeg, jpg, gif, webp.",+ invalidImageFormatMessage,);});@@ -100,9 +112,7 @@ describe("base64ImageSchema", () => {await expect(base64ImageSchema.parseAsync(phishingPayload),- ).rejects.toThrow(- "Invalid image format, supports only png, jpeg, jpg, gif, webp.",- );+ ).rejects.toThrow(invalidImageFormatMessage);});});});diff --git a/apps/web/ui/account/upload-avatar.tsx b/apps/web/ui/account/upload-avatar.tsxindex 81e79f03ff..8537a0d5fd 100644--- a/apps/web/ui/account/upload-avatar.tsx+++ b/apps/web/ui/account/upload-avatar.tsx@@ -87,8 +87,8 @@ export default function UploadAvatar({<div className="flex flex-col items-start justify-start gap-4 rounded-b-xl border-t border-neutral-200 bg-neutral-50 px-6 py-4 sm:flex-row sm:items-center sm:justify-between sm:space-y-0 sm:py-3"><p className="text-sm text-neutral-500">- Square image recommended. Accepted file types: .png, .jpg. Max file- size: 2MB.+ Square image recommended. Accepted file types: .png, .jpg, .webp,+ .avif. Max file size: 2MB.</p><div className="shrink-0"><Buttondiff --git a/apps/web/ui/workspaces/upload-logo.tsx b/apps/web/ui/workspaces/upload-logo.tsxindex f8e6984617..af289df58f 100644--- a/apps/web/ui/workspaces/upload-logo.tsx+++ b/apps/web/ui/workspaces/upload-logo.tsx@@ -72,8 +72,8 @@ export default function UploadLogo() {<div className="flex flex-col items-start justify-between gap-4 rounded-b-xl border-t border-neutral-200 bg-neutral-50 px-5 py-4 sm:flex-row sm:items-center sm:justify-between sm:space-y-0 sm:py-3"><p className="text-sm text-neutral-500">- Square image recommended. Accepted file types: .png, .jpg. Max file- size: 2MB.+ Square image recommended. Accepted file types: .png, .jpg, .webp,+ .avif. Max file size: 2MB.</p><div className="shrink-0"><Buttondiff --git a/packages/ui/src/file-upload.tsx b/packages/ui/src/file-upload.tsxindex 4965450886..cc8b07987e 100644--- a/packages/ui/src/file-upload.tsx+++ b/packages/ui/src/file-upload.tsx@@ -22,14 +22,22 @@ const documentTypes = ["text/csv", // .csv];+const imageExtensionMimeTypes: Record<string, string> = {+ png: "image/png",+ jpg: "image/jpeg",+ jpeg: "image/jpeg",+ webp: "image/webp",+ avif: "image/avif",+};+const acceptFileTypes: Record<AcceptedFileFormats,{ types: string[]; errorMessage?: string }> = {any: { types: [] },images: {- types: ["image/png", "image/jpeg"],- errorMessage: "File type not supported (.png or .jpg only)",+ types: ["image/png", "image/jpeg", "image/webp", "image/avif"],+ errorMessage: "File type not supported (.png, .jpg, .webp, or .avif only)",},csv: {types: ["text/csv"],@@ -194,22 +202,32 @@ export function FileUpload({}const acceptedTypes = acceptFileTypes[accept].types;+ const extension = file.name.split(".").pop()?.toLowerCase();+ const mimeType =+ file.type ||+ (extension ? imageExtensionMimeTypes[extension] : "") ||+ "";- if (acceptedTypes.length && !acceptedTypes.includes(file.type)) {+ if (acceptedTypes.length && !acceptedTypes.includes(mimeType)) {toast.error(acceptFileTypes[accept].errorMessage ?? "File type not supported",);return;}- let fileToUse = file;+ let fileToUse =+ !file.type && mimeType+ ? new File([file], file.name, { type: mimeType })+ : file;// Add image resizing logic- if (targetResolution && file.type.startsWith("image/")) {+ if (targetResolution && mimeType.startsWith("image/")) {try {- const resizedFile = await resizeImage(file, targetResolution);+ const resizedFile = await resizeImage(fileToUse, targetResolution);const blob = await fetch(resizedFile).then((r) => r.blob());- fileToUse = new File([blob], file.name, { type: file.type });+ fileToUse = new File([blob], fileToUse.name, {+ type: blob.type || "image/jpeg",+ });} catch (error) {console.error("Error resizing image:", error);// Fallback to original file if resize fails