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.

fix formatRedisLink

Steven Tey4585c62f42ad
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index f008522705..fbf59361b2 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -104,10 +104,7 @@ export async function createLink(link: ProcessedLinkProps) {
Promise.all([
// record link in Redis
redis.hset(link.domain.toLowerCase(), {
- [link.key.toLowerCase()]: await formatRedisLink({
- ...response,
- ...(webhookIds && { webhookIds }),
- }),
+ [link.key.toLowerCase()]: await formatRedisLink(response),
}),
// record link in Tinybird
diff --git a/apps/web/lib/api/links/update-link.ts b/apps/web/lib/api/links/update-link.ts
index 504f7e3631..d198aaa6f6 100644
--- a/apps/web/lib/api/links/update-link.ts
+++ b/apps/web/lib/api/links/update-link.ts
@@ -142,10 +142,7 @@ export async function updateLink({
Promise.all([
// record link in Redis
redis.hset(updatedLink.domain.toLowerCase(), {
- [updatedLink.key.toLowerCase()]: await formatRedisLink({
- ...response,
- ...(webhookIds && { webhookIds }),
- }),
+ [updatedLink.key.toLowerCase()]: await formatRedisLink(response),
}),
// record link in Tinybird
recordLink({
diff --git a/apps/web/lib/upstash/format-redis-link.ts b/apps/web/lib/upstash/format-redis-link.ts
index 1d4a8d8076..dbfa7f0737 100644
--- a/apps/web/lib/upstash/format-redis-link.ts
+++ b/apps/web/lib/upstash/format-redis-link.ts
@@ -2,7 +2,9 @@ import { isIframeable } from "@dub/utils";
import { LinkProps, RedisLinkProps } from "../types";
export async function formatRedisLink(
- link: LinkProps & { webhookIds?: string[] },
+ link: LinkProps & {
+ webhooks?: { webhookId: string }[];
+ },
): Promise<RedisLinkProps> {
const {
id,
@@ -19,15 +21,16 @@ export async function formatRedisLink(
geo,
doIndex,
projectId,
- webhookIds,
+ webhooks,
} = link;
- const hasPassword = password && password.length > 0 ? true : false;
+
+ const webhookIds = webhooks?.map(({ webhookId }) => webhookId) ?? [];
return {
id,
...(url && { url }), // on free plans you cannot set a root domain redirect, hence URL is undefined
...(trackConversion && { trackConversion: true }),
- ...(hasPassword && { password: true }),
+ ...(password && password.length > 0 && { password: true }),
...(proxy && { proxy: true }),
...(url &&
rewrite && {
@@ -41,6 +44,6 @@ export async function formatRedisLink(
...(geo && { geo: geo as object }),
...(projectId && { projectId }), // projectId can be undefined for anonymous links
...(doIndex && { doIndex: true }),
- ...(webhookIds && { webhookIds }),
+ ...(webhookIds.length > 0 && { webhookIds }),
};
}