mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* feat: Sink url shortner for sms workflow reminders * fix: remove hardcoded dub values * update .env.example * fix: unit tests * chore: add tests for scheduleSmsReminder and utils * review refactor * fix: type check * review refactor * fix: update test to account for smsReminderNumber fallback from main Co-Authored-By: unknown <> * feat: add feature flag for sink and more tests to verify * fix: type check * use proper feature flags for sink * Apply suggestion from @keithwillcode --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Keith Williams <[email protected]>
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { dub } from "@calcom/features/auth/lib/dub";
|
|
import logger from "@calcom/lib/logger";
|
|
import type { IUrlShortenerProvider, ShortenOptions, ShortenResult } from "../IUrlShortenerProvider";
|
|
|
|
const log = logger.getSubLogger({ prefix: ["dub-shortener"] });
|
|
|
|
export class DubShortener implements IUrlShortenerProvider {
|
|
static isConfigured(): boolean {
|
|
return Boolean(process.env.DUB_API_KEY);
|
|
}
|
|
|
|
async shortenMany(urls: string[], options?: ShortenOptions): Promise<ShortenResult[]> {
|
|
try {
|
|
const linksToShorten = urls.filter((link) => link);
|
|
const dubResults = await dub.links.createMany(
|
|
linksToShorten.map((url) => ({
|
|
domain: options?.domain,
|
|
url,
|
|
folderId: options?.folderId,
|
|
}))
|
|
);
|
|
|
|
return urls.map((url) => {
|
|
const createdLink = dubResults.find(
|
|
(result): result is Extract<typeof result, { url: string }> =>
|
|
!("error" in result) && result.url === url
|
|
);
|
|
return { shortLink: createdLink?.shortLink || url };
|
|
});
|
|
} catch (error) {
|
|
log.error("Dub shortening failed, returning original URLs", error);
|
|
return urls.map((url) => ({ shortLink: url }));
|
|
}
|
|
}
|
|
}
|