Files
calendar/packages/app-store/intercom/lib/isValidCalURL.ts
T
Peer RichelsenGitHubpeer@cal.com <peer@cal.com>Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
6f02fbe13b fix: expand Intercom allowed URLs and prevent double-prefixing (#25181)
Co-authored-by: peer@cal.com <peer@cal.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-12-04 05:36:24 +00:00

41 lines
758 B
TypeScript

import { CAL_URL } from "@calcom/lib/constants";
import type { TextComponent } from "../lib";
/**
* Check if the url is a valid cal.com url
* @param url
* @returns IsValid
*/
export async function isValidCalURL(url: string) {
const regex = new RegExp(
`^https://(?:[a-zA-Z0-9-]+\\.)?${CAL_URL.replace("https://", "")}/`,
"i"
);
const error: TextComponent = {
type: "text",
text: `This is not a valid ${CAL_URL.replace("https://", "")} link`,
style: "error",
align: "left",
};
if (!regex.test(url))
return {
isValid: false,
error,
};
const response = await fetch(url);
if (response.status !== 200)
return {
isValid: false,
error,
};
return {
isValid: true,
};
}