diff --git a/packages/features/auth/package.json b/packages/features/auth/package.json index ba504222041816..73c312f394a1d9 100644 --- a/packages/features/auth/package.json +++ b/packages/features/auth/package.json @@ -13,7 +13,7 @@ "@calcom/trpc": "*", "@calcom/ui": "*", "bcryptjs": "^2.4.3", - "dub": "^0.35.0", + "dub": "^0.46.15", "handlebars": "^4.7.7", "jose": "^4.13.1", "lru-cache": "^9.0.3", diff --git a/packages/features/ee/workflows/api/scheduleSMSReminders.ts b/packages/features/ee/workflows/api/scheduleSMSReminders.ts index 2319e9bff50d76..19f9d6fdafd8fb 100644 --- a/packages/features/ee/workflows/api/scheduleSMSReminders.ts +++ b/packages/features/ee/workflows/api/scheduleSMSReminders.ts @@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next"; import dayjs from "@calcom/dayjs"; -import { getShortenLink } from "@calcom/ee/workflows/lib/reminders/utils"; +import { bulkShortenLinks } from "@calcom/ee/workflows/lib/reminders/utils"; import { getCalEventResponses } from "@calcom/features/bookings/lib/getCalEventResponses"; import { getBookerBaseUrl } from "@calcom/lib/getBookerUrl/server"; import { defaultHandler } from "@calcom/lib/server"; @@ -127,26 +127,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { rescheduleLink: `${bookerUrl}/reschedule/${reminder.booking.uid}` || "", }; - const [meetingUrl, cancelLink, rescheduleLink] = await Promise.allSettled([ - getShortenLink(urls.meetingUrl), - getShortenLink(urls.cancelLink), - getShortenLink(urls.rescheduleLink), - ]).then((results) => { - return results.map((result) => { - let finalResult = ""; - - if (result.status === "fulfilled") { - const v = result.value; - if (typeof v === "string") { - finalResult = v; - } else { - finalResult = v.shortLink; - } - } - - return finalResult; - }); - }); + const [{ shortLink: meetingUrl }, { shortLink: cancelLink }, { shortLink: rescheduleLink }] = + await bulkShortenLinks([urls.meetingUrl, urls.cancelLink, urls.rescheduleLink]); const variables: VariablesType = { eventName: reminder.booking?.eventType?.title, diff --git a/packages/features/ee/workflows/lib/reminders/smsReminderManager.ts b/packages/features/ee/workflows/lib/reminders/smsReminderManager.ts index b2171e46c58254..c288d64216f103 100644 --- a/packages/features/ee/workflows/lib/reminders/smsReminderManager.ts +++ b/packages/features/ee/workflows/lib/reminders/smsReminderManager.ts @@ -1,5 +1,5 @@ import dayjs from "@calcom/dayjs"; -import { getShortenLink } from "@calcom/ee/workflows/lib/reminders/utils"; +import { bulkShortenLinks } from "@calcom/ee/workflows/lib/reminders/utils"; import { SENDER_ID, WEBSITE_URL } from "@calcom/lib/constants"; import logger from "@calcom/lib/logger"; import type { TimeFormat } from "@calcom/lib/timeFormat"; @@ -153,26 +153,8 @@ export const scheduleSMSReminder = async (args: ScheduleTextReminderArgs) => { rescheduleLink: `${evt.bookerUrl ?? WEBSITE_URL}/reschedule/${evt.uid}`, }; - const [meetingUrl, cancelLink, rescheduleLink] = await Promise.allSettled([ - getShortenLink(urls.meetingUrl), - getShortenLink(urls.cancelLink), - getShortenLink(urls.rescheduleLink), - ]).then((results) => { - return results.map((result) => { - let finalResult = ""; - - if (result.status === "fulfilled") { - const v = result.value; - if (typeof v === "string") { - finalResult = v; - } else { - finalResult = v.shortLink; - } - } - - return finalResult; - }); - }); + const [{ shortLink: meetingUrl }, { shortLink: cancelLink }, { shortLink: rescheduleLink }] = + await bulkShortenLinks([urls.meetingUrl, urls.cancelLink, urls.rescheduleLink]); const variables: VariablesType = { eventName: evt.title, diff --git a/packages/features/ee/workflows/lib/reminders/utils.ts b/packages/features/ee/workflows/lib/reminders/utils.ts index c976d8d0249e53..3a4d628072aab2 100644 --- a/packages/features/ee/workflows/lib/reminders/utils.ts +++ b/packages/features/ee/workflows/lib/reminders/utils.ts @@ -1,14 +1,19 @@ import { dub } from "@calcom/features/auth/lib/dub"; -export const getShortenLink = (link: string) => { - // don't hit dub with with empty string - if (!link.length) { - const pr: Promise = new Promise((resolve) => resolve(link)); - return pr; - } else { - return dub.links.create({ - url: link, - domain: "sms.cal.com", - }); - } +export const bulkShortenLinks = async (links: string[]) => { + const linksToShorten = links.filter((link) => link); + const results = await dub.links.createMany( + linksToShorten.map((link) => ({ domain: "sms.cal.com", url: link })) + ); + return links.map((link) => { + const createdLink = results.find( + (result): result is Extract => + !("error" in result) && result.url === link + ); + if (createdLink) { + return { shortLink: createdLink.shortLink }; + } else { + return { shortLink: link }; + } + }); }; diff --git a/yarn.lock b/yarn.lock index a5315cfee1a180..2186ba8e1b52ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4132,7 +4132,7 @@ __metadata: "@calcom/trpc": "*" "@calcom/ui": "*" bcryptjs: ^2.4.3 - dub: ^0.35.0 + dub: ^0.46.15 handlebars: ^4.7.7 jose: ^4.13.1 lru-cache: ^9.0.3 @@ -23405,12 +23405,12 @@ __metadata: languageName: node linkType: hard -"dub@npm:^0.35.0": - version: 0.35.0 - resolution: "dub@npm:0.35.0" +"dub@npm:^0.46.15": + version: 0.46.15 + resolution: "dub@npm:0.46.15" peerDependencies: zod: ">= 3" - checksum: 162bd1ff62b62044e3840d3128f341baa8d07828aaf9ca2e94a562b7196df857c1fcdbf2495edfd8b7055970eb1c64298a2265dca81cb4d7bdc65ddc97980905 + checksum: 36b1260bc3115e5a9122bd165785ecfcc208ff6e6f8dc38c339d9b98132e3d49fe05740659106dcf870cc0bc8037ff6181620347076186e1a82644fb9513983b languageName: node linkType: hard