@@ -7,7 +7,6 @@ import { db } from "@/lib/db/client";
77import { replaceDns } from "@/lib/db/repos/dns" ;
88import { findDomainByName } from "@/lib/db/repos/domains" ;
99import { dnsRecords } from "@/lib/db/schema" ;
10- import { toRegistrableDomain } from "@/lib/domain-server" ;
1110import { fetchWithTimeoutAndRetry } from "@/lib/fetch" ;
1211import { simpleHash } from "@/lib/hash" ;
1312import { createLogger } from "@/lib/logger/server" ;
@@ -84,25 +83,20 @@ function buildDohUrl(
8483export const getDnsRecords = cache ( async function getDnsRecords (
8584 domain : string ,
8685) : Promise < DnsRecordsResponse > {
86+ // Input domain is already normalized to registrable domain by router schema
8787 logger . debug ( "start" , { domain } ) ;
8888
8989 const providers = providerOrderForLookup ( domain ) ;
9090 const durationByProvider : Record < string , number > = { } ;
9191 let lastError : unknown = null ;
9292 const types = DnsTypeSchema . options ;
9393
94- // Only support registrable domains (no subdomains, IPs, or invalid TLDs)
95- const registrable = toRegistrableDomain ( domain ) ;
96- if ( ! registrable ) {
97- throw new Error ( `Cannot extract registrable domain from ${ domain } ` ) ;
98- }
99-
10094 // Generate single timestamp for access tracking and scheduling
10195 const now = new Date ( ) ;
10296 const nowMs = now . getTime ( ) ;
10397
10498 // Fast path: Check Postgres for cached DNS records
105- const existingDomain = await findDomainByName ( registrable ) ;
99+ const existingDomain = await findDomainByName ( domain ) ;
106100 const rows = (
107101 existingDomain
108102 ? await db
@@ -171,7 +165,7 @@ export const getDnsRecords = cache(async function getDnsRecords(
171165 const sorted = sortDnsRecordsByType ( deduplicated , types ) ;
172166 if ( allFreshAcrossTypes ) {
173167 logger . info ( "cache hit" , {
174- domain : registrable ,
168+ domain,
175169 types : freshTypes . join ( "," ) ,
176170 cached : true ,
177171 } ) ;
@@ -244,13 +238,13 @@ export const getDnsRecords = cache(async function getDnsRecords(
244238 // Always schedule: use the soonest expiry if available, otherwise schedule immediately
245239 const soonest = times . length > 0 ? Math . min ( ...times ) : Date . now ( ) ;
246240 scheduleRevalidation (
247- registrable ,
241+ domain ,
248242 "dns" ,
249243 soonest ,
250244 existingDomain . lastAccessedAt ?? null ,
251245 ) . catch ( ( err ) => {
252246 logger . error ( "schedule failed partial" , err , {
253- domain : registrable ,
247+ domain,
254248 type : "partial" ,
255249 } ) ;
256250 } ) ;
@@ -285,7 +279,7 @@ export const getDnsRecords = cache(async function getDnsRecords(
285279 ) ;
286280
287281 logger . info ( "partial refresh done" , {
288- domain : registrable ,
282+ domain,
289283 counts,
290284 resolver : pinnedProvider . key ,
291285 durationMs : durationByProvider [ pinnedProvider . key ] ,
@@ -297,7 +291,7 @@ export const getDnsRecords = cache(async function getDnsRecords(
297291 } catch ( err ) {
298292 // Fall through to full provider loop below
299293 logger . error ( "partial refresh failed" , err , {
300- domain : registrable ,
294+ domain,
301295 provider : pinnedProvider . key ,
302296 } ) ;
303297 }
@@ -379,20 +373,20 @@ export const getDnsRecords = cache(async function getDnsRecords(
379373 ) ;
380374 const soonest = times . length > 0 ? Math . min ( ...times ) : now . getTime ( ) ;
381375 scheduleRevalidation (
382- registrable ,
376+ domain ,
383377 "dns" ,
384378 soonest ,
385379 existingDomain . lastAccessedAt ?? null ,
386380 ) . catch ( ( err ) => {
387381 logger . error ( "schedule failed full" , err , {
388- domain : registrable ,
382+ domain,
389383 type : "full" ,
390384 } ) ;
391385 } ) ;
392386 } ) ;
393387 }
394388 logger . info ( "done" , {
395- domain : registrable ,
389+ domain,
396390 counts,
397391 resolver : resolverUsed ,
398392 durationByProvider,
@@ -404,7 +398,7 @@ export const getDnsRecords = cache(async function getDnsRecords(
404398 return { records : sorted , resolver : resolverUsed } as DnsRecordsResponse ;
405399 } catch ( err ) {
406400 logger . warn ( "provider attempt failed" , {
407- domain : registrable ,
401+ domain,
408402 provider : provider . key ,
409403 } ) ;
410404 durationByProvider [ provider . key ] = Date . now ( ) - attemptStart ;
@@ -415,10 +409,10 @@ export const getDnsRecords = cache(async function getDnsRecords(
415409
416410 // All providers failed
417411 const error = new Error (
418- `All DoH providers failed for ${ registrable } : ${ String ( lastError ) } ` ,
412+ `All DoH providers failed for ${ domain } : ${ String ( lastError ) } ` ,
419413 ) ;
420414 logger . error ( "all providers failed" , error , {
421- domain : registrable ,
415+ domain,
422416 providers : providers . map ( ( p ) => p . key ) . join ( "," ) ,
423417 } ) ;
424418 throw error ;
0 commit comments