22
*/
23
export function extractUrlPatterns(url: URI): string[] {
25
>
const normalized = URI.parse(normalizedStr);
26
>
const patterns = new Set<string>();
27
>
28
>
// Full URL (most specific)
29
>
const fullUrl = normalized.toString(true);
30
>
patterns.add(fullUrl);
31
>
32
>
// Domain-only pattern (without trailing slash)
33
>
const domainOnly = normalized.with({ path: '', query: '', fragment: '' }).toString(true);
34
>
patterns.add(domainOnly);
35
>
36
>
// Wildcard subdomain pattern (*.example.com)
37
>
const authority = normalized.authority;
38
>
const domainParts = authority.split('.');
39
>
40
>
// Only add wildcard subdomain if there are at least 2 parts and it's not an IP
41
>
const isIPv4 = domainParts.length === 4 && domainParts.every((segment: string) =>
42
Number.isInteger(+segment));
44
>
const isIP = isIPv4 || isIPv6;
45
>
46
>
// Only emit subdomain patterns if there are actually subdomains (more than 2 parts)
47
>
if (!isIP && domainParts.length > 2) {
48
// Create patterns by replacing each subdomain segment with *
49
// For example, foo.bar.example.com -> *.bar.example.com, *.example.com