forked from
slices.network/slices
Highly ambitious ATProtocol AppView service and sdks
1// List of domains that are not supported as primary domains (trying to prevent long running syncs for now)
2const UNSUPPORTED_DOMAINS = ["app.bsky"];
3
4export function validateDomain(domain: string): string | null {
5 const trimmedDomain = domain.trim();
6
7 if (!trimmedDomain || trimmedDomain.length === 0) {
8 return "Domain is required";
9 }
10
11 if (UNSUPPORTED_DOMAINS.includes(trimmedDomain)) {
12 return `The domain '${trimmedDomain}' is not supported`;
13 }
14
15 // Domain must have at least two parts (e.g. social.grain)
16 if (!trimmedDomain.includes(".")) {
17 return "Domain must have at least two parts (e.g. social.grain)";
18 }
19
20 // Validate domain format
21 const domainRegex =
22 /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)+$/;
23 if (!domainRegex.test(trimmedDomain)) {
24 return "Domain must be a valid format (e.g. social.grain)";
25 }
26
27 return null; // Valid
28}
29
30// Function to get the list of unsupported domains (for debugging/admin purposes)
31export function getUnsupportedDomains(): readonly string[] {
32 return UNSUPPORTED_DOMAINS;
33}