domain-hound 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.agents/plugins/marketplace.json +1 -0
  2. package/.claude-plugin/marketplace.json +1 -0
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/README.md +106 -13
  5. package/assets/readme-search.png +0 -0
  6. package/clis/domain-check/broker-atom.mjs +78 -0
  7. package/clis/domain-check/com-site.mjs +64 -25
  8. package/clis/domain-check/confirm.mjs +10 -5
  9. package/clis/domain-check/dossier.mjs +603 -0
  10. package/clis/domain-check/google-play.mjs +24 -11
  11. package/clis/domain-check/handles.mjs +337 -0
  12. package/clis/domain-check/index.mjs +69 -20
  13. package/clis/domain-check/marketplaces.mjs +107 -0
  14. package/clis/domain-check/meaning-words.LICENSE.txt +408 -0
  15. package/clis/domain-check/meaning-words.json +2397 -0
  16. package/clis/domain-check/meaning.mjs +77 -0
  17. package/clis/domain-check/name-search.mjs +83 -13
  18. package/clis/domain-check/naming-method.mjs +6 -4
  19. package/clis/domain-check/price-catalog.mjs +20 -12
  20. package/clis/domain-check/price-snapshot.json +142 -10
  21. package/clis/domain-check/registry.mjs +112 -19
  22. package/clis/domain-check/safe-web.mjs +207 -0
  23. package/clis/domain-check/traction.mjs +2 -2
  24. package/clis/domain-check/trademarks.mjs +372 -0
  25. package/clis/domain-check/triage-sources.mjs +52 -64
  26. package/clis/domain-check/triage.mjs +262 -72
  27. package/clis/spaceship/buy.mjs +327 -0
  28. package/clis/spaceship/client.mjs +170 -0
  29. package/clis/spaceship/dns.mjs +292 -0
  30. package/clis/spaceship/quote.mjs +123 -0
  31. package/clis/spaceship/setup.mjs +81 -0
  32. package/clis/spaceship/store.mjs +104 -0
  33. package/clis/spaceship/tools.mjs +258 -0
  34. package/display.mjs +16 -9
  35. package/dossier.mjs +185 -0
  36. package/package.json +36 -5
  37. package/plugin.json +4 -3
  38. package/results-style.mjs +10 -0
  39. package/results.mjs +291 -61
  40. package/server.json +3 -3
  41. package/server.mjs +275 -59
  42. package/share.mjs +43 -0
  43. package/site/r/share-format.mjs +125 -0
@@ -14,9 +14,95 @@ const rdapRateLimit = 'Registry RDAP returned HTTP 429';
14
14
  // A rate-limited registry host is left alone for its Retry-After in this process and the next.
15
15
  const legacyIdentityCooldown = 'rdap-identity-digital-cooldown.json';
16
16
  const cooldownFile = origin => 'rdap-cooldown-' + new URL(origin).hostname + '.json';
17
+
18
+ export async function registryCooldown(origin, directory) {
19
+ const current = await readCache(directory, cooldownFile(origin));
20
+ const legacy = new URL(origin).origin === identityDigital ? await readCache(directory, legacyIdentityCooldown) : null;
21
+ return Math.max(current?.until || 0, legacy?.until || 0);
22
+ }
17
23
  // The fallback steps (registry WHOIS, then DNS) keep this much of the lookup time.
18
24
  const fallbackReserve = 800;
19
25
 
26
+ // Registry WHOIS servers as listed in the IANA Root Zone Database, so the fallback needs no whois.iana.org referral:
27
+ // https://www.iana.org/domains/root/db/ai.html, https://www.iana.org/domains/root/db/io.html and
28
+ // https://www.iana.org/domains/root/db/me.html (Identity Digital runs all three; checked 2026-11-25).
29
+ export const documentedWhois = new Map([
30
+ ['ai', 'whois.nic.ai'],
31
+ ['io', 'whois.nic.io'],
32
+ ['me', 'whois.nic.me'],
33
+ ]);
34
+ // Queries to one WHOIS host start at least this far apart. Identity Digital's hosts get the wider gap: they stand in
35
+ // for an RDAP service that is already rate limiting this machine.
36
+ export const whoisSpacing = { identity: 400, other: 150 };
37
+ // A WHOIS host that answers with a rate-limit notice is left alone this long, in this process and the next.
38
+ export const whoisCooldownMs = 15 * 60_000;
39
+ const whoisCooldownFile = host => 'whois-cooldown-' + host + '.json';
40
+ const whoisLimitWords = /\b(?:rate limit|limit exceeded|exceeded (?:the |your )?(?:query |request )?(?:limit|quota)|too many (?:queries|requests))\b/i;
41
+ const whoisTurns = new Map();
42
+
43
+ function whoisPacer(host) {
44
+ if (!whoisTurns.has(host)) whoisTurns.set(host, { nextStart: 0, limitedUntil: 0 });
45
+ return whoisTurns.get(host);
46
+ }
47
+
48
+ // Run one registry query at a time per host, spacing starts on a monotonic clock.
49
+ async function queryRegistryWhois(host, domain, query, timeLeft, pause, directory) {
50
+ const pacer = whoisPacer(host);
51
+ if (!pacer.loaded) {
52
+ pacer.loaded = readCache(directory, whoisCooldownFile(host)).then(saved => {
53
+ pacer.limitedUntil = Math.max(pacer.limitedUntil, saved?.until || 0);
54
+ });
55
+ }
56
+ const previous = pacer.tail ?? Promise.resolve();
57
+ let release;
58
+ pacer.tail = new Promise(resolve => { release = resolve; });
59
+ try {
60
+ await Promise.all([pacer.loaded, previous]);
61
+ const spacing = [...documentedWhois.values()].includes(host) ? whoisSpacing.identity : whoisSpacing.other;
62
+ let waitForSlot = pause;
63
+ let timeout;
64
+ while (true) {
65
+ if (pacer.limitedUntil > Date.now()) return { reason: 'Registry WHOIS rate limit' };
66
+ const wait = Math.max(0, pacer.nextStart - performance.now());
67
+ const remaining = timeLeft();
68
+ // Leave at least 300 ms for the query itself, even after a late wake-up.
69
+ if (wait + 300 > remaining) return { reason: 'Registry WHOIS timed out' };
70
+ if (wait === 0) {
71
+ timeout = Math.min(1500, remaining);
72
+ break;
73
+ }
74
+ await waitForSlot(Math.ceil(wait));
75
+ // An early wake-up still needs a timer until the slot opens.
76
+ waitForSlot = delay;
77
+ }
78
+ let response;
79
+ try {
80
+ response = query(host, domain, timeout);
81
+ } finally {
82
+ // Start the gap once the query has been dispatched, before waiting for its reply.
83
+ pacer.nextStart = performance.now() + spacing;
84
+ }
85
+ const reply = String(await response ?? '');
86
+ if (await whoisLimited(host, reply, directory)) return { reason: 'Registry WHOIS rate limit' };
87
+ return { reply };
88
+ } finally {
89
+ release();
90
+ }
91
+ }
92
+
93
+ async function whoisLimited(host, reply, directory) {
94
+ if (!whoisLimitWords.test(reply.split(/^\s*Terms of Use:/im, 1)[0])) return false;
95
+ const pacer = whoisPacer(host);
96
+ pacer.limitedUntil = Math.max(pacer.limitedUntil, Date.now() + whoisCooldownMs);
97
+ await writeCache(directory, whoisCooldownFile(host), { until: pacer.limitedUntil }).catch(() => {});
98
+ return true;
99
+ }
100
+
101
+ // For tests: forget the pacing state of earlier lookups in this process.
102
+ export function resetWhoisPacing() {
103
+ whoisTurns.clear();
104
+ }
105
+
20
106
  const overrides = new Map([
21
107
  ['co', 'https://rdap.registry.co/co/'],
22
108
  ['io', identityDigital + '/rdap/'],
@@ -26,6 +112,7 @@ const overrides = new Map([
26
112
  ]);
27
113
 
28
114
  export function rdapBase(tld, services) {
115
+ if (tld === 'co.uk') tld = 'uk';
29
116
  const urls = services?.find(([tlds]) => tlds.includes(tld))?.[1];
30
117
  return overrides.get(tld) ?? urls?.find(url => url.startsWith('https://')) ?? urls?.[0];
31
118
  }
@@ -34,7 +121,7 @@ export function rdapDomainUrl(base, domain) {
34
121
  return base.replace(/\/?$/, '/') + 'domain/' + encodeURIComponent(domain);
35
122
  }
36
123
 
37
- async function bootstrap(directory, fetcher, now, timeLeft) {
124
+ export async function bootstrap(directory, fetcher, now, timeLeft) {
38
125
  const saved = await readCache(directory, 'iana.json');
39
126
  const day = 86_400_000;
40
127
  const age = now - saved?.savedAt;
@@ -170,23 +257,29 @@ export function systemQueryWhois(host, query, timeout) {
170
257
  });
171
258
  }
172
259
 
173
- async function lookupWhois(domain, tld, query, timeLeft, referrals) {
174
- if (!referrals.has(tld)) referrals.set(tld, query('whois.iana.org', tld, Math.min(1150, timeLeft())));
175
- const iana = await referrals.get(tld);
176
- const host = iana.match(/^(?:refer|whois):[ \t]*([a-z\d.-]+)[ \t\r]*$/im)?.[1];
260
+ async function lookupWhois(domain, tld, query, timeLeft, referrals, { pause = delay, directory } = {}) {
261
+ if (tld === 'co.uk') tld = 'uk';
262
+ let host = documentedWhois.get(tld);
263
+ if (!host) {
264
+ if (!referrals.has(tld)) referrals.set(tld, query('whois.iana.org', tld, Math.min(1150, timeLeft())));
265
+ const iana = await referrals.get(tld);
266
+ host = iana.match(/^(?:refer|whois):[ \t]*([a-z\d.-]+)[ \t\r]*$/im)?.[1];
267
+ }
177
268
  if (!host) return unknown('whois', 'IANA WHOIS has no registry referral');
178
- const timeout = Math.min(1500, timeLeft());
179
- if (timeout <= 0) return unknown('whois', 'Registry WHOIS timed out');
180
- const result = await query(host, domain, timeout);
181
- const name = result.match(/^\s*Domain Name:[ \t]*(\S+)/im)?.[1];
182
- if (name?.toLowerCase() === domain) {
269
+ const { reply: result, reason } = await queryRegistryWhois(host, domain, query, timeLeft, pause, directory);
270
+ if (reason) return unknown('whois', reason);
271
+ const name = result.match(/^\s*Domain(?: Name)?:[ \t]*(\S+)/im)?.[1];
272
+ // DENIC and EURid echo the queried name on negative answers.
273
+ const statusFree = /^\s*Status:[ \t]*free\s*$/im.test(result)
274
+ || tld === 'eu' && name?.toLowerCase() === domain && /^\s*Status:[ \t]*available\s*$/im.test(result);
275
+ if (name?.toLowerCase() === domain && !statusFree) {
183
276
  const expiry = result.match(/^Registry Expiry Date:[ \t]*(\S+)/im)?.[1];
184
277
  const expires = Number.isFinite(Date.parse(expiry)) ? new Date(expiry).toISOString() : null;
185
278
  return { status: 'taken', source: 'whois', ...(expires && { expires }) };
186
279
  }
187
280
  const signal = registrySignal(result);
188
281
  if (signal) return signalled('whois', signal);
189
- if (/^\s*(?:(?:%|>>>|#)\s*)?(?:no (?:match|entries found|data found|object found)|(?:domain\s+)?not found|no such domain|the queried object does not exist)/im.test(result)) {
282
+ if (statusFree || /^\s*(?:(?:%|>>>|#)\s*)?(?:no (?:match|entries found|data found|object found)|(?:domain\s+)?not found|no such domain|the queried object does not exist|domain "[^"\s]+" not found)/im.test(result)) {
190
283
  return { status: 'free', source: 'whois' };
191
284
  }
192
285
  return unknown('whois', 'Registry WHOIS returned no definitive answer');
@@ -294,7 +387,7 @@ export async function lookupRegistrations(candidates, {
294
387
  function record({ candidate, index, dns }, registry) {
295
388
  if (registry.status === 'unknown' && dns?.reason) registry.reason = dns.reason + '; ' + registry.reason;
296
389
  results[index] = registry;
297
- onResult(candidate, registry);
390
+ onResult(candidate, registry, dns?.code);
298
391
  }
299
392
  async function finish(row, result, filename) {
300
393
  record(row, result);
@@ -343,9 +436,7 @@ export async function lookupRegistrations(candidates, {
343
436
  const unsettled = [];
344
437
  await Promise.all([...registries].map(async ([origin, registry]) => {
345
438
  if (origin.startsWith('https:')) {
346
- const saved = await readCache(directory, cooldownFile(origin));
347
- const legacy = origin === identityDigital ? await readCache(directory, legacyIdentityCooldown) : null;
348
- registry.limitedUntil = Math.max(saved?.until || 0, legacy?.until || 0);
439
+ registry.limitedUntil = await registryCooldown(origin, directory);
349
440
  }
350
441
  return mapLimit(registry.jobs, registry.limit, async ({ base, entry }) => {
351
442
  const row = await entry;
@@ -359,11 +450,13 @@ export async function lookupRegistrations(candidates, {
359
450
  record(row, { ...cached.result, checkedAt: new Date(cached.at).toISOString() });
360
451
  return;
361
452
  }
362
- const result = base ? await lookupRdap(base, domain, fetcher, rdapLeft, readExpiry, pause, registry, rdapAttempts, directory)
363
- : await services ? await lookupWhois(domain, tld, whois, timeLeft, referrals)
453
+ const coolingDown = registry.identity && registry.limitedUntil > Date.now() && documentedWhois.has(tld) && fallbackWhois;
454
+ const result = coolingDown || !base && await services
455
+ ? await lookupWhois(domain, tld, coolingDown ? fallbackWhois : whois, timeLeft, referrals, { pause, directory })
364
456
  .catch(() => unknown('whois', 'Registry WHOIS did not respond'))
457
+ : base ? await lookupRdap(base, domain, fetcher, rdapLeft, readExpiry, pause, registry, rdapAttempts, directory)
365
458
  : unknown('rdap', 'IANA RDAP bootstrap is unavailable');
366
- if (result.status === 'unknown' && !result.signal) unsettled.push({ row, result, filename, viaWhois: !base });
459
+ if (result.status === 'unknown' && !result.signal) unsettled.push({ row, result, filename, viaWhois: !base || coolingDown });
367
460
  else await finish(row, result, filename);
368
461
  });
369
462
  }));
@@ -375,7 +468,7 @@ export async function lookupRegistrations(candidates, {
375
468
  const query = ['app', 'dev'].includes(tld) ? null : fallbackWhois;
376
469
  const [answer, likely] = await Promise.all([
377
470
  query && !viaWhois && timeLeft() > 600
378
- ? lookupWhois(domain, tld, query, () => timeLeft() - 300, referrals)
471
+ ? lookupWhois(domain, tld, query, () => timeLeft() - 300, referrals, { pause, directory })
379
472
  .catch(() => unknown('whois', 'Registry WHOIS did not respond')) : null,
380
473
  dnsLikely(row),
381
474
  ]);
@@ -0,0 +1,207 @@
1
+ // Outbound HTTP for untrusted websites (a taken domain's own site and wherever it redirects). Every hop is checked
2
+ // before it is fetched: http or https on the default port, a public DNS name (never an IP literal, credentials or a
3
+ // local suffix), and an address that resolves to the public internet. Bodies are capped and only read as HTML.
4
+ // Nothing read here is passed on as text: callers keep only classifications, hosts and sanitized URLs.
5
+ import { get as httpGet } from 'node:http';
6
+ import { get as httpsGet } from 'node:https';
7
+ import { isIP } from 'node:net';
8
+ import { lookupPublic } from './com-site.mjs';
9
+
10
+ export const maxPageBytes = 200_000;
11
+ export const maxHops = 5;
12
+ const hostLabel = /^(?!-)[a-z0-9-]{1,63}(?<!-)$/;
13
+ const localSuffixes = ['localhost', 'local', 'internal', 'intranet', 'lan', 'home', 'corp', 'home.arpa', 'onion',
14
+ 'test', 'invalid', 'arpa'];
15
+
16
+ // A URL safe to request, or null. Relative values resolve against base (a redirect Location).
17
+ export function safeUrl(value, base) {
18
+ if (typeof value !== 'string' && !(value instanceof URL)) return null;
19
+ const text = String(value);
20
+ if (text.length > 2048 || /[\u0000-\u001f\u007f\s\\]/.test(text.trim())) return null;
21
+ let url;
22
+ try { url = new URL(text.trim(), base); } catch { return null; }
23
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.port) return null;
24
+ const host = url.hostname.toLowerCase();
25
+ if (!host || host.length > 253 || isIP(host) || host.startsWith('[')) return null;
26
+ const labels = host.split('.');
27
+ if (labels.length < 2 || !labels.every(part => hostLabel.test(part)) || /^\d+$/.test(labels.at(-1))) return null;
28
+ if (localSuffixes.some(suffix => host === suffix || host.endsWith('.' + suffix))) return null;
29
+ url.hash = '';
30
+ return url;
31
+ }
32
+
33
+ // Leave tracking parameters and other private values out of evidence.
34
+ export function evidenceUrl(value) {
35
+ const url = safeUrl(value);
36
+ if (!url) return null;
37
+ const text = url.origin + url.pathname;
38
+ return text.length <= 300 ? text : url.origin + '/';
39
+ }
40
+
41
+ export const hostMatches = (host, suffixes) => Boolean(host) && suffixes.some(suffix => host === suffix || host.endsWith('.' + suffix));
42
+
43
+ const userAgent = 'DomainHound (+https://domainhound.dev; read-only domain dossier)';
44
+
45
+ // One request without following redirects. Keep only bounded HTML or crawl rules.
46
+ function requestPage(url, signal, robots = false) {
47
+ return new Promise((resolve, reject) => {
48
+ if (signal?.aborted) return reject(new Error('timed out'));
49
+ const get = url.protocol === 'https:' ? httpsGet : httpGet;
50
+ const request = get(url, {
51
+ lookup: lookupPublic(signal), signal, agent: false,
52
+ headers: { accept: robots ? 'text/plain' : 'text/html, application/xhtml+xml',
53
+ 'user-agent': userAgent, 'accept-encoding': 'identity' },
54
+ }, response => {
55
+ const status = response.statusCode;
56
+ const contentType = String(response.headers['content-type'] ?? '');
57
+ const location = [301, 302, 303, 307, 308].includes(status) && typeof response.headers.location === 'string'
58
+ ? response.headers.location : null;
59
+ const encoded = !/^(?:identity)?$/i.test(String(response.headers['content-encoding'] ?? '').trim());
60
+ if (location || !(status >= 200 && status < 300) || encoded
61
+ || (!robots && !/^(?:text\/html|application\/xhtml\+xml)\b/i.test(contentType))) {
62
+ response.destroy();
63
+ resolve({ status, contentType, location });
64
+ return;
65
+ }
66
+ const chunks = [];
67
+ let size = 0;
68
+ let done = false;
69
+ const finish = (truncated = false) => {
70
+ if (done) return;
71
+ done = true;
72
+ const body = robots && truncated ? undefined : Buffer.concat(chunks).toString('utf8');
73
+ resolve({ status, contentType, body, truncated });
74
+ };
75
+ response.on('data', chunk => {
76
+ const part = chunk.subarray(0, maxPageBytes - size);
77
+ chunks.push(part);
78
+ size += part.length;
79
+ if (size >= maxPageBytes) {
80
+ finish(true);
81
+ response.destroy();
82
+ }
83
+ });
84
+ response.on('end', () => finish());
85
+ response.on('error', error => done ? undefined : reject(error));
86
+ });
87
+ request.on('error', reject);
88
+ });
89
+ }
90
+
91
+ function ruleMatches(pattern, path) {
92
+ const anchored = pattern.endsWith('$');
93
+ const [prefix, ...rest] = (anchored ? pattern.slice(0, -1) : pattern).split('*');
94
+ if (!path.startsWith(prefix)) return false;
95
+ if (!rest.length) return !anchored || path === prefix;
96
+ const suffix = anchored ? rest.pop() : '';
97
+ if (anchored && !path.endsWith(suffix)) return false;
98
+ let position = prefix.length;
99
+ for (const part of rest) {
100
+ const next = path.indexOf(part, position);
101
+ if (next === -1) return false;
102
+ position = next + part.length;
103
+ }
104
+ return position + suffix.length <= path.length;
105
+ }
106
+
107
+ export function robotsAllow(body, path) {
108
+ const groups = [];
109
+ let group = { agents: [], rules: [] };
110
+ for (const line of body.split('\n')) {
111
+ const [key, value] = line.split('#', 1)[0].split(/:(.*)/s, 2).map(part => part.trim());
112
+ const field = key.toLowerCase();
113
+ if (field === 'user-agent' && value) {
114
+ if (group.rules.length) group = { agents: [], rules: [] };
115
+ if (!group.agents.length) groups.push(group);
116
+ group.agents.push(value.toLowerCase());
117
+ } else if (group.agents.length && ['allow', 'disallow'].includes(field)) {
118
+ group.rules.push({ allow: field === 'allow', pattern: value ?? '' });
119
+ }
120
+ }
121
+ const agent = groups.some(row => row.agents.includes('domainhound')) ? 'domainhound' : '*';
122
+ let best = { length: -1, allow: true };
123
+ for (const { agents, rules } of groups) {
124
+ if (!agents.includes(agent)) continue;
125
+ for (const { allow, pattern } of rules) {
126
+ if (!pattern.startsWith('/') || !ruleMatches(pattern, path)) continue;
127
+ const length = pattern.replace(/[\*$]/g, '').length;
128
+ if (length > best.length || (length === best.length && allow)) best = { length, allow };
129
+ }
130
+ }
131
+ return best.allow;
132
+ }
133
+
134
+ async function crawlAllowed(url, signal, stopAt) {
135
+ let rules = new URL('/robots.txt', url);
136
+ for (let attempt = 0; attempt < 3; attempt++) {
137
+ const response = await requestPage(rules, signal, true);
138
+ if ([404, 410].includes(response.status)) return true;
139
+ if (typeof response.body === 'string') return robotsAllow(response.body, url.pathname + url.search);
140
+ const next = safeUrl(response.location, rules);
141
+ if (!next || stopAt(next)) return false;
142
+ rules = next.pathname.endsWith('.txt') ? next : new URL('/robots.txt', next);
143
+ }
144
+ return false;
145
+ }
146
+
147
+ export async function loadPage(url, signal = AbortSignal.timeout(5000), stopAt = () => null) {
148
+ if (!await crawlAllowed(url, signal, stopAt)) return { blocked: true };
149
+ return requestPage(url, signal);
150
+ }
151
+
152
+ // A <meta http-equiv="refresh"> target that fires within ten seconds, or null.
153
+ export function metaRefresh(body) {
154
+ const tags = String(body ?? '').slice(0, 50_000).match(/<meta\b[^>]*>/gi) ?? [];
155
+ for (const tag of tags) {
156
+ if (!/http-equiv\s*=\s*["']?refresh\b/i.test(tag)) continue;
157
+ const content = tag.match(/\bcontent\s*=\s*(?:"([^"]*)"|'([^']*)')/i);
158
+ const value = content?.[1] ?? content?.[2] ?? '';
159
+ const match = value.match(/^\s*(\d+)\s*[;,]\s*url\s*=\s*['"]?([^'"]+)['"]?\s*$/i);
160
+ if (match && Number(match[1]) <= 10) return match[2].trim();
161
+ }
162
+ return null;
163
+ }
164
+
165
+ // Follow a site from start, hop by hop. stopAt(url) names a reason not to fetch a hop (such as a marketplace whose
166
+ // terms do not permit automated reads); the chain then ends there without a request to that host.
167
+ export async function followSite(start, { signal, stopAt = () => null, load = loadPage } = {}) {
168
+ const hops = [];
169
+ let url = safeUrl(start);
170
+ if (!url) return { hops, failed: { url: null, reason: 'unsafe address' } };
171
+ for (let hop = 0; hop <= maxHops; hop++) {
172
+ const stop = stopAt(url);
173
+ if (stop) return { hops, stopped: { url, reason: stop } };
174
+ let response;
175
+ try {
176
+ response = await load(url, signal, stopAt);
177
+ } catch {
178
+ return { hops, failed: { url, reason: signal?.aborted ? 'timed out' : 'no response' } };
179
+ }
180
+ if (response?.blocked) return { hops, stopped: { url, reason: 'crawl rules unavailable or disallow this page' } };
181
+ const status = Number.isInteger(response?.status) ? response.status : null;
182
+ hops.push({ url, status });
183
+ let target = response?.location ?? null;
184
+ if (!target && typeof response?.body === 'string') target = metaRefresh(response.body);
185
+ if (!target) return { hops, final: { url, status, contentType: String(response?.contentType ?? ''),
186
+ body: response?.body ?? '', truncated: response?.truncated === true } };
187
+ const next = safeUrl(target, url);
188
+ if (!next) return { hops, stopped: { url: null, reason: 'unsafe redirect' } };
189
+ url = next;
190
+ }
191
+ return { hops, stopped: { url, reason: 'too many redirects' } };
192
+ }
193
+
194
+ // Visible text of an HTML page for local pattern checks only. It is never returned to the caller of a tool.
195
+ export function pageText(body) {
196
+ const entities = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
197
+ return String(body ?? '').slice(0, maxPageBytes)
198
+ .replace(/<!--[\s\S]*?(?:-->|$)|<(script|style|noscript|template)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)/gi, ' ')
199
+ .replace(/<[^>]*>/g, ' ')
200
+ .replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (match, entity) => {
201
+ if (!entity.startsWith('#')) return entities[entity.toLowerCase()] ?? match;
202
+ const point = entity[1].toLowerCase() === 'x' ? parseInt(entity.slice(2), 16) : Number(entity.slice(1));
203
+ return point > 0 && point <= 0x10ffff ? String.fromCodePoint(point) : ' ';
204
+ })
205
+ .replace(/[\s ​-‏‪-‮⁦-⁩]+/g, ' ')
206
+ .trim();
207
+ }
@@ -4,7 +4,7 @@ import { mkdir, open, readFile, rename, stat, unlink, writeFile } from 'node:fs/
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { inflateRawSync } from 'node:zlib';
6
6
  import { cacheDir, mapLimit, readCache, writeCache } from './cache.mjs';
7
- import { bootstrapUrl, rdapBase, rdapDomainUrl } from './registry.mjs';
7
+ import { bootstrapUrl, rdapBase, rdapDomainUrl, registryCooldown } from './registry.mjs';
8
8
  import { compactText, day, letters, readJson, request } from './triage-sources.mjs';
9
9
 
10
10
  // Every traction threshold lives in this table. Tuned with the strong, no-traction and some-traction
@@ -234,7 +234,7 @@ async function rdapServices(options) {
234
234
  // The RDAP registration date, null when the registry gives none, or undefined when it did not answer.
235
235
  export async function registeredOn(domain, options) {
236
236
  const base = rdapBase(domain.split('.').at(-1), await rdapServices(options));
237
- if (!base || options.timeLeft() < 300) return undefined;
237
+ if (!base || options.timeLeft() < 300 || await registryCooldown(base, options.directory) > Date.now()) return undefined;
238
238
  try {
239
239
  const response = await request(rdapDomainUrl(base, domain), options, {
240
240
  timeout: Math.min(2500, options.timeLeft()), headers: { Accept: 'application/rdap+json, application/json' },