mirror of
https://github.com/jakejarvis/rdapper.git
synced 2026-09-23 01:25:31 -04:00
Rename lookupDomain() to lookup() (with backwards compatibility)
This commit is contained in:
+28
-2
@@ -1,5 +1,4 @@
|
||||
import { toISO } from "../lib/dates";
|
||||
import { isWhoisAvailable } from "../lib/domain";
|
||||
import { isPrivacyName } from "../lib/privacy";
|
||||
import { parseKeyValueLines, uniq } from "../lib/text";
|
||||
import type {
|
||||
@@ -9,6 +8,33 @@ import type {
|
||||
RegistrarInfo,
|
||||
} from "../types";
|
||||
|
||||
// Common WHOIS availability phrases seen across registries/registrars
|
||||
const WHOIS_AVAILABLE_PATTERNS: RegExp[] = [
|
||||
/\bno match\b/i,
|
||||
/\bnot found\b/i,
|
||||
/\bno entries found\b/i,
|
||||
/\bno data found\b/i,
|
||||
/\bavailable for registration\b/i,
|
||||
/\bdomain\s+available\b/i,
|
||||
/\bdomain status[:\s]+available\b/i,
|
||||
/\bobject does not exist\b/i,
|
||||
/\bthe queried object does not exist\b/i,
|
||||
// Common variants across ccTLDs/registrars
|
||||
/\bstatus:\s*free\b/i,
|
||||
/\bstatus:\s*available\b/i,
|
||||
/\bno object found\b/i,
|
||||
/\bnicht gefunden\b/i,
|
||||
/\bpending release\b/i, // often signals not registered/being deleted
|
||||
];
|
||||
|
||||
/**
|
||||
* Best-effort heuristic to determine if a WHOIS response indicates the domain is available.
|
||||
*/
|
||||
export function isAvailableByWhois(text: string | undefined): boolean {
|
||||
if (!text) return false;
|
||||
return WHOIS_AVAILABLE_PATTERNS.some((re) => re.test(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert raw WHOIS text into our normalized DomainRecord.
|
||||
* Heuristics cover many gTLD and ccTLD formats; exact fields vary per registry.
|
||||
@@ -163,7 +189,7 @@ export function normalizeWhois(
|
||||
const record: DomainRecord = {
|
||||
domain,
|
||||
tld,
|
||||
isRegistered: !isWhoisAvailable(whoisText),
|
||||
isRegistered: !isAvailableByWhois(whoisText),
|
||||
isIDN: /(^|\.)xn--/i.test(domain),
|
||||
unicodeName: undefined,
|
||||
punycodeName: undefined,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { isWhoisAvailable } from "../lib/domain";
|
||||
import type { LookupOptions } from "../types";
|
||||
import type { WhoisQueryResult } from "./client";
|
||||
import { whoisQuery } from "./client";
|
||||
import { extractWhoisReferral } from "./discovery";
|
||||
import { isAvailableByWhois } from "./normalize";
|
||||
|
||||
/**
|
||||
* Follow registrar WHOIS referrals up to a configured hop limit.
|
||||
@@ -30,8 +30,8 @@ export async function followWhoisReferrals(
|
||||
try {
|
||||
const res = await whoisQuery(next, domain, opts);
|
||||
// Prefer authoritative TLD response when registrar contradicts availability
|
||||
const registeredBefore = !isWhoisAvailable(current.text);
|
||||
const registeredAfter = !isWhoisAvailable(res.text);
|
||||
const registeredBefore = !isAvailableByWhois(current.text);
|
||||
const registeredAfter = !isAvailableByWhois(res.text);
|
||||
if (registeredBefore && !registeredAfter) {
|
||||
// Registrar claims availability but TLD shows registered: keep TLD
|
||||
break;
|
||||
@@ -74,8 +74,8 @@ export async function collectWhoisReferralChain(
|
||||
try {
|
||||
const res = await whoisQuery(next, domain, opts);
|
||||
// If registrar claims availability while TLD indicated registered, stop.
|
||||
const registeredBefore = !isWhoisAvailable(current.text);
|
||||
const registeredAfter = !isWhoisAvailable(res.text);
|
||||
const registeredBefore = !isAvailableByWhois(current.text);
|
||||
const registeredAfter = !isAvailableByWhois(res.text);
|
||||
if (registeredBefore && !registeredAfter) {
|
||||
// Do not adopt or append contradictory registrar; keep authoritative TLD only.
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user