domain-hound 0.1.3 → 0.1.5

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.
@@ -1,7 +1,7 @@
1
1
  import { domainToASCII, domainToUnicode } from 'node:url';
2
2
  import { checkDomainSite } from './com-site.mjs';
3
3
  import { cachedSignals, confirmingShops } from './confirm.mjs';
4
- import { bundledCatalog, datedListPrices, getNameCatalog, loadCachedCatalog, targetEndings } from './price-catalog.mjs';
4
+ import { bundledCatalog, datedListPrices, getNameCatalog, loadCachedCatalog, requestEndings, supportedEndings, targetEndings } from './price-catalog.mjs';
5
5
  import { linkable, shopSearchUrl } from './prices.mjs';
6
6
  import { lookupRegistrations } from './registry.mjs';
7
7
  import { foldLatin } from './triage-sources.mjs';
@@ -18,6 +18,12 @@ const facts = {
18
18
  eligibility: 'Norwegian organization or eligible individual, with a Norwegian postal address',
19
19
  source: 'https://www.norid.no/en/om-domenenavn/regelverk-for-no/', checked,
20
20
  },
21
+ eu: {
22
+ need: 'EU or EEA eligibility',
23
+ eligibility: 'EU, Icelandic, Liechtenstein or Norwegian citizenship, residence or establishment',
24
+ note: 'Registration requires citizenship, residence or establishment in the EU, Iceland, Liechtenstein or Norway',
25
+ source: 'https://eurid.eu/en/knowledge-centre/rules-for-eu-domains/', checked: '2026-11-25',
26
+ },
21
27
  io: {
22
28
  note: 'Long-term registry uncertainty',
23
29
  source: 'https://www.icann.org/en/blogs/details/the-chagos-archipelago-and-the-io-domain-14-11-2024-en', checked,
@@ -33,7 +39,9 @@ const facts = {
33
39
  };
34
40
 
35
41
  const label = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
42
+ export const domainEnding = domain => domain.endsWith('.co.uk') ? 'co.uk' : domain.split('.').at(-1);
36
43
  export const defaultEndings = targetEndings;
44
+ export { requestEndings, supportedEndings };
37
45
  export const restrictedEndings = Object.keys(facts).filter(tld => facts[tld].eligibility);
38
46
  const firstCost = row => row.firstPayment ?? Infinity;
39
47
 
@@ -58,8 +66,8 @@ export function eligibilityNotes(endings) {
58
66
  }
59
67
 
60
68
  export function validEndings(endings) {
61
- return Array.isArray(endings) && endings.length > 0 && endings.length <= targetEndings.length
62
- && endings.every(ending => targetEndings.includes(ending));
69
+ return Array.isArray(endings) && endings.length > 0 && endings.length <= supportedEndings.length
70
+ && new Set(endings).size === endings.length && endings.every(ending => supportedEndings.includes(ending));
63
71
  }
64
72
 
65
73
  // One DNS label for a name. Spaces and punctuation go; letters never do. A name with non-ASCII letters (æ, ø, å, é)
@@ -150,7 +158,7 @@ export function rankName(rows) {
150
158
  return { ...row, ...termCosts(tld, price, renewal), reason, terms: facts[tld] ?? null,
151
159
  renewalJump: price != null && renewal > 2 * price };
152
160
  }).sort((a, b) => Number(b.exact) - Number(a.exact) || firstCost(a) - firstCost(b)
153
- || defaultEndings.indexOf(a.tld) - defaultEndings.indexOf(b.tld) || a.domain.localeCompare(b.domain));
161
+ || supportedEndings.indexOf(a.tld) - supportedEndings.indexOf(b.tld) || a.domain.localeCompare(b.domain));
154
162
  }
155
163
 
156
164
  export function pickName(rows, eligible) {
@@ -167,6 +175,11 @@ export function registrationStatus(registry) {
167
175
  return registry.status === 'taken' ? 'taken' : 'check-at-shop';
168
176
  }
169
177
 
178
+ export function applyLiveSite(registry, site) {
179
+ if (registry.status !== 'free' || !['live', 'parked', 'for-sale'].includes(site?.state)) return registry;
180
+ return { status: 'taken', source: 'web', checkedAt: registry.checkedAt, forSale: site.state === 'for-sale' };
181
+ }
182
+
170
183
  export function listQuote(catalog, { domain, tld }, now, bundled = bundledCatalog) {
171
184
  // Data-only shops never become the listed pick or its checkout link.
172
185
  const prices = datedListPrices(catalog, tld, now, bundled).filter(row => linkable(row.id)).sort((a, b) =>
@@ -228,20 +241,33 @@ export async function searchCandidates(groups, options = {}) {
228
241
  const sites = new Map();
229
242
  const siteEndings = options.siteEndings ?? (options.skipComSite ? [] : ['com']);
230
243
  const lookedUp = new Map();
244
+ const checks = [];
231
245
  let catalog = null;
232
246
  let timer;
233
247
  let complete = false;
234
248
  const onResult = ({ domain, tld, exact }, registry) => {
235
249
  if (timeLeft() <= 0) return;
236
- lookedUp.set(domain, registry);
237
- const status = registrationStatus(registry);
238
- options.onProgress?.({ domain, status: status === 'probably-free' && premiumRisk(domain) ? 'premium' : status });
239
- if (registry.status !== 'taken' || !exact || !siteEndings.includes(tld)) return;
250
+ const publish = (result) => {
251
+ lookedUp.set(domain, result);
252
+ const status = registrationStatus(result);
253
+ options.onProgress?.({ domain, status: status === 'probably-free' && premiumRisk(domain) ? 'premium' : status });
254
+ };
255
+ // A negative registry answer can be wrong. A real response on the domain beats a free claim.
256
+ // Replay and unit callers that inject registry traffic can inject the site check as well.
257
+ const checkNegative = registry.status === 'free' && (options.fetcher === undefined || options.verifyFreeSite);
258
+ const checkTaken = registry.status === 'taken' && exact && siteEndings.includes(tld) && (options.siteFilter?.(domain) ?? true);
259
+ if (!checkNegative) publish(registry);
260
+ if (!checkNegative && !checkTaken) return;
240
261
  const timeout = Math.min(options.siteTimeout ?? 1200, timeLeft());
241
- sites.set(domain, { pending: (options.comSite ?? checkDomainSite)(domain, timeout, options.siteDetails).then(site => {
262
+ const visit = checkNegative ? options.verifyFreeSite ?? options.comSite ?? checkDomainSite
263
+ : options.comSite ?? checkDomainSite;
264
+ const pending = Promise.resolve().then(() => visit(domain, timeout, options.siteDetails || checkNegative)).then(site => {
242
265
  sites.get(domain).result = site;
243
266
  options.onSite?.(domain, site);
244
- }).catch(() => {}) });
267
+ if (checkNegative) publish(applyLiveSite(registry, site));
268
+ }, () => { if (checkNegative) publish(registry); });
269
+ sites.set(domain, { pending });
270
+ checks.push(pending);
245
271
  };
246
272
  const loadCatalog = options.cachedOnly ? loadCachedCatalog(options.directory)
247
273
  : getNameCatalog({ ...options, now, coldWaitMs: bundled ? 0 : Math.min(1900, budgetMs) });
@@ -249,7 +275,7 @@ export async function searchCandidates(groups, options = {}) {
249
275
  lookupRegistrations([...candidates.values()], { ...options, now, timeLeft, onResult }),
250
276
  loadCatalog.then(value => { catalog = value; }),
251
277
  ]).then(async () => {
252
- await Promise.all([...sites.values()].map(site => site.pending));
278
+ await Promise.all(checks);
253
279
  complete = lookedUp.size === candidates.size;
254
280
  });
255
281
  try {
@@ -15,7 +15,7 @@ export const geoInstruction = 'GEO (presence in AI answers): for each name, answ
15
15
  export const namingRecipe = (about = '') => 'Naming recipe (intermediate). Use the final triage display.\n'
16
16
  + (about ? '1. Brief: ' + about.replace(/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]+/gu, ' ').trim()
17
17
  + '.\n' : '1. Brief: product, audience and preferences.\n')
18
- + '2. Generate about 30 words. Pair one with a familiar animal or object. Avoid category-generic names.\n'
18
+ + '2. Generate about 30 words. Pair one with a familiar animal or object. Default to English unless the person asked for another language. Avoid category-generic names.\n'
19
19
  + '3. Check: call check_domains ONCE with seven bare names and shortlist: true (Quiet Otter → quietotter). No spaces or dots.\n'
20
- + '4. Triage: call triage_names ONCE on only the best FIVE with free endings, a short about and geo from memory. Follow its Google search instructions.\n'
21
- + '5. Answer: ' + showAsIs + ' Keep all five candidates and let the person choose.';
20
+ + '4. Triage: call triage_names ONCE on the best FIVE with free endings, a short about and geo from memory. Pass the same endings and budget to both calls.\n'
21
+ + '5. Answer: Relay say as written. Let the person choose from the complete local results page.';
@@ -7,9 +7,15 @@ import { cacheDir, readCache, writeCache } from './cache.mjs';
7
7
  import { withShopPages } from './confirm.mjs';
8
8
  import { catalogPrice, dynadotOffer, offer, shops } from './prices.mjs';
9
9
 
10
- export const targetEndings = ['com', 'ai', 'io', 'me', 'co', 'dev', 'app', 'si', 'so', 'no'];
10
+ // The endings every bare name is checked on. The first ten are the 0.1.4 set; .net, .org, .xyz and .tech joined in 0.1.5.
11
+ export const targetEndings = ['com', 'ai', 'io', 'me', 'co', 'dev', 'app', 'si', 'so', 'no', 'net', 'org', 'xyz', 'tech'];
12
+ // Checked only when the person asks for them (or names them in endings).
13
+ export const requestEndings = ['sh', 'gg', 'inc', 'studio', 'se', 'dk', 'de', 'uk', 'co.uk', 'eu'];
14
+ export const supportedEndings = [...targetEndings, ...requestEndings];
15
+ // A saved or bundled catalog must cover these; newer endings are priced once a refresh has them.
16
+ const coreEndings = targetEndings.slice(0, 10);
11
17
  const otherEndings = ['so', 'no'];
12
- const spaceshipEndings = targetEndings.filter(tld => !otherEndings.includes(tld));
18
+ const spaceshipEndings = coreEndings.filter(tld => !otherEndings.includes(tld));
13
19
  const filename = 'prices.json';
14
20
  const day = 86_400_000;
15
21
  const primaryShops = ['spaceship', 'porkbun', 'dynadot'];
@@ -26,7 +32,7 @@ function validSource(id, prices) {
26
32
  const entries = Object.entries(prices ?? {});
27
33
  const required = id === 'spaceship' ? spaceshipEndings : id === 'gandi' ? [] : ['com', 'io', 'me'];
28
34
  return entries.length > 0 && required.every(tld => Object.hasOwn(prices, tld)) &&
29
- entries.every(([tld, row]) => targetEndings.includes(tld) && validPrice(row, shops[id].name));
35
+ entries.every(([tld, row]) => supportedEndings.includes(tld) && validPrice(row, shops[id].name));
30
36
  }
31
37
 
32
38
  function validDate(value) {
@@ -36,7 +42,7 @@ function validDate(value) {
36
42
  export function validCatalog(value) {
37
43
  if (!validDate(value?.checkedAt)) return false;
38
44
  if (!value.catalogs) {
39
- return targetEndings.every(tld => validPrice(value.prices?.[tld], otherEndings.includes(tld) ? 'Gandi' : 'Spaceship'));
45
+ return coreEndings.every(tld => validPrice(value.prices?.[tld], otherEndings.includes(tld) ? 'Gandi' : 'Spaceship'));
40
46
  }
41
47
  return Object.keys(value.catalogs).length > 0 && Object.entries(value.catalogs).every(([id, source]) =>
42
48
  [...primaryShops, 'gandi'].includes(id) && validDate(source.checkedAt) && validSource(id, source.prices));
@@ -233,17 +239,19 @@ export async function loadPorkbunPrices(fetcher = globalThis.fetch) {
233
239
  const response = await fetcher(porkbunPricing, { ...options, signal });
234
240
  const catalog = response.ok ? await response.json() : null;
235
241
  if (catalog?.status !== 'SUCCESS' || !catalog.pricing) throw new Error('Porkbun catalog unavailable');
236
- return Object.fromEntries(targetEndings.flatMap(tld => {
242
+ return Object.fromEntries(supportedEndings.flatMap(tld => {
237
243
  const row = catalog.pricing[tld];
238
- if (!row) return [];
239
- return [[tld, { shop: 'Porkbun', firstYear: catalogPrice(row.registration),
240
- renewal: catalogPrice(row.renewal), transfer: catalogPrice(row.transfer) }]];
244
+ const price = { shop: 'Porkbun', firstYear: catalogPrice(row?.registration),
245
+ renewal: catalogPrice(row?.renewal), transfer: catalogPrice(row?.transfer) };
246
+ return validPrice(price, 'Porkbun') ? [[tld, price]] : [];
241
247
  }));
242
248
  }
243
249
  try {
244
250
  return await Promise.any([
245
- load({ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' }),
246
- delay(350, undefined, { signal }).then(() => load()),
251
+ load({ headers: { Accept: 'application/json' } }),
252
+ delay(350, undefined, { signal }).then(() => load({
253
+ method: 'POST', headers: { Accept: 'application/json', 'Content-Type': 'application/json' }, body: '{}',
254
+ })),
247
255
  ]);
248
256
  } finally {
249
257
  controller.abort();
@@ -263,7 +271,7 @@ export function dynadotPrices(html) {
263
271
  for (const row of values) {
264
272
  if (!row || typeof row !== 'object' || Array.isArray(row)) continue;
265
273
  const tld = values[row.name];
266
- if (!targetEndings.includes(tld)) continue;
274
+ if (!supportedEndings.includes(tld)) continue;
267
275
  const firstYear = usd(values[row.reg_price]);
268
276
  const renewal = usd(values[row.renew_price]);
269
277
  if (firstYear && renewal) prices[tld] = {
@@ -271,7 +279,7 @@ export function dynadotPrices(html) {
271
279
  };
272
280
  }
273
281
  }
274
- for (const tld of targetEndings.filter(tld => !prices[tld])) {
282
+ for (const tld of supportedEndings.filter(tld => !prices[tld])) {
275
283
  const row = dynadotOffer(html, tld, 'example.' + tld, new Date());
276
284
  if (row) prices[tld] = { shop: 'Dynadot', firstYear: row.regularFirstYear,
277
285
  renewal: row.renewal, transfer: row.regularTransferPrice };
@@ -1,5 +1,5 @@
1
1
  {
2
- "checkedAt": "2026-11-24T18:15:47.403Z",
2
+ "checkedAt": "2026-11-25T09:07:26.876Z",
3
3
  "catalogs": {
4
4
  "spaceship": {
5
5
  "checkedAt": "2026-11-24T18:15:47.403Z",
@@ -55,7 +55,7 @@
55
55
  }
56
56
  },
57
57
  "porkbun": {
58
- "checkedAt": "2026-11-24T18:15:47.403Z",
58
+ "checkedAt": "2026-11-25T09:07:26.876Z",
59
59
  "prices": {
60
60
  "com": {
61
61
  "shop": "Porkbun",
@@ -104,11 +104,77 @@
104
104
  "firstYear": 19.95,
105
105
  "renewal": 17.13,
106
106
  "transfer": null
107
+ },
108
+ "net": {
109
+ "shop": "Porkbun",
110
+ "firstYear": 12.52,
111
+ "renewal": 12.52,
112
+ "transfer": 12.52
113
+ },
114
+ "org": {
115
+ "shop": "Porkbun",
116
+ "firstYear": 7.98,
117
+ "renewal": 11.84,
118
+ "transfer": 11.84
119
+ },
120
+ "xyz": {
121
+ "shop": "Porkbun",
122
+ "firstYear": 1.29,
123
+ "renewal": 14.21,
124
+ "transfer": 14.21
125
+ },
126
+ "tech": {
127
+ "shop": "Porkbun",
128
+ "firstYear": 6.99,
129
+ "renewal": 50.98,
130
+ "transfer": 50.98
131
+ },
132
+ "sh": {
133
+ "shop": "Porkbun",
134
+ "firstYear": 31.2,
135
+ "renewal": 46.65,
136
+ "transfer": 46.65
137
+ },
138
+ "gg": {
139
+ "shop": "Porkbun",
140
+ "firstYear": 51.8,
141
+ "renewal": 51.8,
142
+ "transfer": 51.8
143
+ },
144
+ "studio": {
145
+ "shop": "Porkbun",
146
+ "firstYear": 11.84,
147
+ "renewal": 41.71,
148
+ "transfer": 41.71
149
+ },
150
+ "de": {
151
+ "shop": "Porkbun",
152
+ "firstYear": 2.9,
153
+ "renewal": 4.07,
154
+ "transfer": 5.1
155
+ },
156
+ "uk": {
157
+ "shop": "Porkbun",
158
+ "firstYear": 5.66,
159
+ "renewal": 5.66,
160
+ "transfer": null
161
+ },
162
+ "co.uk": {
163
+ "shop": "Porkbun",
164
+ "firstYear": 5.66,
165
+ "renewal": 5.66,
166
+ "transfer": null
167
+ },
168
+ "eu": {
169
+ "shop": "Porkbun",
170
+ "firstYear": 5.88,
171
+ "renewal": 5.88,
172
+ "transfer": 5.88
107
173
  }
108
174
  }
109
175
  },
110
176
  "dynadot": {
111
- "checkedAt": "2026-11-24T18:15:47.403Z",
177
+ "checkedAt": "2026-11-25T08:46:38.737Z",
112
178
  "prices": {
113
179
  "com": {
114
180
  "shop": "Dynadot",
@@ -116,6 +182,18 @@
116
182
  "renewal": 11.62,
117
183
  "transfer": 11.62
118
184
  },
185
+ "xyz": {
186
+ "shop": "Dynadot",
187
+ "firstYear": 1.5,
188
+ "renewal": 14.45,
189
+ "transfer": 14.45
190
+ },
191
+ "org": {
192
+ "shop": "Dynadot",
193
+ "firstYear": 7.99,
194
+ "renewal": 11.64,
195
+ "transfer": 11.64
196
+ },
119
197
  "co": {
120
198
  "shop": "Dynadot",
121
199
  "firstYear": 15.5,
@@ -128,11 +206,41 @@
128
206
  "renewal": 53.5,
129
207
  "transfer": 53.5
130
208
  },
209
+ "net": {
210
+ "shop": "Dynadot",
211
+ "firstYear": 7.49,
212
+ "renewal": 12.52,
213
+ "transfer": 12.52
214
+ },
131
215
  "me": {
132
216
  "shop": "Dynadot",
133
- "firstYear": 9.16,
134
- "renewal": 16.8,
135
- "transfer": 16.8
217
+ "firstYear": 9.21,
218
+ "renewal": 16.88,
219
+ "transfer": 16.88
220
+ },
221
+ "tech": {
222
+ "shop": "Dynadot",
223
+ "firstYear": 6.64,
224
+ "renewal": 52.65,
225
+ "transfer": 52.65
226
+ },
227
+ "eu": {
228
+ "shop": "Dynadot",
229
+ "firstYear": 4.21,
230
+ "renewal": 6.05,
231
+ "transfer": 6.05
232
+ },
233
+ "uk": {
234
+ "shop": "Dynadot",
235
+ "firstYear": 6.14,
236
+ "renewal": 6.14,
237
+ "transfer": null
238
+ },
239
+ "de": {
240
+ "shop": "Dynadot",
241
+ "firstYear": 3.84,
242
+ "renewal": 3.84,
243
+ "transfer": 3.84
136
244
  },
137
245
  "so": {
138
246
  "shop": "Dynadot",
@@ -146,6 +254,18 @@
146
254
  "renewal": 14.5,
147
255
  "transfer": 13.99
148
256
  },
257
+ "sh": {
258
+ "shop": "Dynadot",
259
+ "firstYear": 32.1,
260
+ "renewal": 48.15,
261
+ "transfer": 48.15
262
+ },
263
+ "studio": {
264
+ "shop": "Dynadot",
265
+ "firstYear": 11.99,
266
+ "renewal": 43.02,
267
+ "transfer": 43.02
268
+ },
149
269
  "dev": {
150
270
  "shop": "Dynadot",
151
271
  "firstYear": 8,
@@ -158,16 +278,28 @@
158
278
  "renewal": 85.6,
159
279
  "transfer": 171.2
160
280
  },
281
+ "gg": {
282
+ "shop": "Dynadot",
283
+ "firstYear": 53.5,
284
+ "renewal": 53.5,
285
+ "transfer": 53.5
286
+ },
287
+ "dk": {
288
+ "shop": "Dynadot",
289
+ "firstYear": 12.76,
290
+ "renewal": 12.76,
291
+ "transfer": 10.99
292
+ },
161
293
  "si": {
162
294
  "shop": "Dynadot",
163
- "firstYear": 11.24,
164
- "renewal": 11.24,
295
+ "firstYear": 11.29,
296
+ "renewal": 11.29,
165
297
  "transfer": null
166
298
  },
167
299
  "no": {
168
300
  "shop": "Dynadot",
169
- "firstYear": 7.91,
170
- "renewal": 7.91,
301
+ "firstYear": 7.97,
302
+ "renewal": 7.97,
171
303
  "transfer": null
172
304
  }
173
305
  }
@@ -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
  }
@@ -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');
@@ -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
  ]);
@@ -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' },
@@ -348,6 +348,7 @@ export function collectRivals({ name, input = name, sites = {}, entities, topics
348
348
  owner.wikipedia ??= rival.wikipedia;
349
349
  owner.apps.push(...rival.apps);
350
350
  owner.description ??= rival.description;
351
+ owner.website ??= rival.website;
351
352
  if (rival.sources.includes('wikidata') && !owner.sources.includes('wikidata-name')) {
352
353
  owner.name = rival.name;
353
354
  owner.sources.push('wikidata-name');
@@ -371,7 +372,9 @@ export function collectRivals({ name, input = name, sites = {}, entities, topics
371
372
  // A site that redirects to another home of the same name (notion.ai to notion.com) joins that rival.
372
373
  const final = site.state === 'live' && site.host ? siteDomain(site.host) : null;
373
374
  add(base(head?.head ?? domain, 'site', {
374
- domains: [domain, ...(final && final !== domain && ownsName(name, final) ? [final] : [])], refs: [domain], site: { domain, state: site.state, copyright: site.copyright, lastModified: site.lastModified },
375
+ domains: [domain, ...(final && final !== domain && ownsName(name, final) ? [final] : [])], refs: [domain],
376
+ website: final ?? (site.state === 'live' ? domain : undefined),
377
+ site: { domain, state: site.state, copyright: site.copyright, lastModified: site.lastModified },
375
378
  description: compactText([site.title, site.description].filter(Boolean).join(' '), 200) || undefined,
376
379
  sameBusiness: site.state === 'live' && sameBusiness([site.title, site.description].join(' ')),
377
380
  }));
@@ -380,7 +383,7 @@ export function collectRivals({ name, input = name, sites = {}, entities, topics
380
383
  if (!entity?.brand || letters(entity.name) !== letters(name)) continue;
381
384
  const homes = (entity.website ?? []).map(siteDomain).filter(domain => domain && ownsName(name, domain));
382
385
  add(base(entity.name, 'wikidata', {
383
- domains: [...new Set(homes)], refs: [entity], description: entity.description || undefined,
386
+ domains: [...new Set(homes)], website: homes[0], refs: [entity], description: entity.description || undefined,
384
387
  wikipedia: entity.wikipedia ?? null, sitelinks: entity.sitelinks ?? 0,
385
388
  sameBusiness: sameBusiness(entity.name + ' ' + (entity.description ?? '')),
386
389
  }));
@@ -481,7 +484,7 @@ export function assessRival(rival, evidence = new Map(), { now = Date.now(), ans
481
484
  if (best.age && yearsSince(best.age.date, now) >= T.some.domainYears) {
482
485
  signals.push(signal('domain since ' + best.age.date.slice(0, 4), 'some', 0.3));
483
486
  }
484
- const home = best.tranco?.domain ?? best.crawl?.domain ?? best.age?.domain ?? rival.domains[0];
487
+ const home = rival.website ?? (rival.site?.state === 'live' ? rival.site.domain : null);
485
488
  if (rival.wikipedia && T.strong.wikipediaArticle) signals.push(signal('Wikipedia article', 'strong', 0.9));
486
489
  for (const app of rival.apps) {
487
490
  if (!Number.isSafeInteger(app.ratings)) continue;
@@ -590,7 +593,7 @@ export function tractionSummary(judged) {
590
593
  if (!main || level[main.level] < 1) return judged.agent ? { geo } : null;
591
594
  return {
592
595
  rival: rivalLabel(main), level: main.level, ...(main.rival.sameBusiness && { sameBusiness: true }),
593
- signals: main.signals.slice(0, 2).map(item => item.text), geo,
596
+ ...(main.home && { domain: main.home }), signals: main.signals.slice(0, 2).map(item => item.text), geo,
594
597
  };
595
598
  }
596
599