(domain: string)
| 27 | * Returns null if no match is found. |
| 28 | */ |
| 29 | export async function resolveOrgByDomain(domain: string): Promise<DomainResolution | null> { |
| 30 | const normalized = domain.toLowerCase().trim(); |
| 31 | |
| 32 | // Try database lookups first (fast) |
| 33 | const dbResult = await resolveFromDatabase(normalized); |
| 34 | if (dbResult) return dbResult; |
| 35 | |
| 36 | // No DB match — check if the domain redirects to a different one |
| 37 | const redirectTarget = await resolveRedirectDomain(normalized); |
| 38 | if (redirectTarget && redirectTarget !== normalized) { |
| 39 | const redirectResult = await resolveFromDatabase(redirectTarget); |
| 40 | if (redirectResult) { |
| 41 | // Persist the alias so future lookups skip the HTTP check |
| 42 | persistRedirectAlias(normalized, redirectTarget); |
| 43 | return { ...redirectResult, method: 'redirect' }; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Batch resolve multiple domains to organizations using database-only lookups. |
no test coverage detected