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.

Make the createId function strongly typed for the prefix.

Kiran K1083206da184
diff --git a/apps/web/lib/api/utils.ts b/apps/web/lib/api/utils.ts
index d86d3aa767..8994209856 100644
--- a/apps/web/lib/api/utils.ts
+++ b/apps/web/lib/api/utils.ts
@@ -71,12 +71,29 @@ export const extractPublishableKey = (req: Request) => {
return authorizationHeader.replace("Bearer ", "");
};
+const prefixes = [
+ "link_",
+ "tag_",
+ "dom_",
+ "po_",
+ "dash_",
+ "int_",
+ "app_",
+ "cus_",
+ "utm_",
+ "wh_",
+ "pgi_",
+ "pge_",
+ "pn_",
+ "sale_",
+] as const;
+
export const createId = ({
- length = 24,
prefix,
+ length = 24,
}: {
+ prefix?: (typeof prefixes)[number];
length?: number;
- prefix?: string;
}) => {
return `${prefix || ""}${nanoid(length)}`;
};