domain-hound 0.1.1 → 0.1.3

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,8 +1,10 @@
1
+ import { domainToASCII, domainToUnicode } from 'node:url';
1
2
  import { checkDomainSite } from './com-site.mjs';
2
- import { confirmingShops } from './confirm.mjs';
3
+ import { cachedSignals, confirmingShops } from './confirm.mjs';
3
4
  import { bundledCatalog, datedListPrices, getNameCatalog, loadCachedCatalog, targetEndings } from './price-catalog.mjs';
4
- import { shopSearchUrl } from './prices.mjs';
5
+ import { linkable, shopSearchUrl } from './prices.mjs';
5
6
  import { lookupRegistrations } from './registry.mjs';
7
+ import { foldLatin } from './triage-sources.mjs';
6
8
 
7
9
  const checked = '2026-11-23';
8
10
  const facts = {
@@ -11,6 +13,7 @@ const facts = {
11
13
  source: 'https://www.namecheap.com/domains/registration/cctld/ai/', checked,
12
14
  },
13
15
  no: {
16
+ need: 'Norwegian org/ID',
14
17
  note: 'Norwegian address plus organization number or personal ID required',
15
18
  eligibility: 'Norwegian organization or eligible individual, with a Norwegian postal address',
16
19
  source: 'https://www.norid.no/en/om-domenenavn/regelverk-for-no/', checked,
@@ -43,6 +46,11 @@ export function canRecommend(tld, eligible = []) {
43
46
  return !facts[tld]?.eligibility || eligible.includes(tld);
44
47
  }
45
48
 
49
+ // What a buyer needs for a restricted ending, in a few words: "Norwegian org/ID".
50
+ export function eligibilityNeed(tld) {
51
+ return facts[tld]?.eligibility ? facts[tld].need ?? 'eligibility' : null;
52
+ }
53
+
46
54
  export function eligibilityNotes(endings) {
47
55
  const notes = Object.fromEntries(restrictedEndings.filter(tld => endings.includes(tld))
48
56
  .map(tld => [tld, facts[tld].note]));
@@ -54,16 +62,65 @@ export function validEndings(endings) {
54
62
  && endings.every(ending => targetEndings.includes(ending));
55
63
  }
56
64
 
65
+ // One DNS label for a name. Spaces and punctuation go; letters never do. A name with non-ASCII letters (æ, ø, å, é)
66
+ // becomes its punycode label (xn--...), the form registries and shops use for that exact spelling.
57
67
  export function normalizeName(input) {
58
68
  if (typeof input !== 'string' || /[./\\]/.test(input)) return null;
59
- const name = input.normalize('NFKD').toLowerCase().replace(/[^a-z0-9-]/g, '');
60
- return label.test(name) ? name : null;
69
+ const name = input.normalize('NFC').toLowerCase().replace(/[^\p{L}\p{N}\p{M}-]/gu, '');
70
+ if (/^[a-z0-9-]*$/.test(name)) return label.test(name) ? name : null;
71
+ const ascii = domainToASCII(name);
72
+ return label.test(ascii) ? ascii : null;
73
+ }
74
+
75
+ // An exact domain in its DNS form: a Unicode domain becomes its punycode form; anything else returns null.
76
+ export function asciiDomain(input) {
77
+ if (typeof input !== 'string') return null;
78
+ const value = input.normalize('NFC').toLowerCase();
79
+ if (!/^[\p{L}\p{N}\p{M}.-]+$/u.test(value)) return null;
80
+ return /^[\x00-\x7f]+$/.test(value) ? value : domainToASCII(value) || null;
81
+ }
82
+
83
+ // The Unicode spelling of an ASCII label or domain, or null when it has no punycode part.
84
+ export function unicodeName(value) {
85
+ if (typeof value !== 'string' || !/(?:^|\.)xn--/.test(value)) return null;
86
+ const shown = domainToUnicode(value);
87
+ return shown && shown !== value ? shown : null;
88
+ }
89
+
90
+ // A Latin-letter key for name matching in rival, app, mark and handle sources: Grønnstue -> gronnstue.
91
+ // ASCII names keep their DNS label as the key.
92
+ export function searchKey(input) {
93
+ const dns = normalizeName(input);
94
+ if (!dns?.startsWith('xn--')) return dns;
95
+ const key = foldLatin(input).replace(/[^a-z0-9-]/g, '');
96
+ return label.test(key) ? key : dns;
97
+ }
98
+
99
+ // Short labels (four characters or fewer, counted in Unicode) are often premium at the registry or the shop.
100
+ // Their list price is withheld until a shop quote settles it.
101
+ export const premiumRiskLength = 4;
102
+ export function premiumRisk(domain) {
103
+ const first = String(domain ?? '').split('.')[0];
104
+ if (!first) return false;
105
+ return [...(unicodeName(first) ?? first)].length <= premiumRiskLength;
106
+ }
107
+
108
+ // A free row for a short label: the registry says free, but the price may be premium. No list price stays on it.
109
+ export function withPremiumRisk(row) {
110
+ if (!row || row.status !== 'probably-free' || !premiumRisk(row.domain)) {
111
+ if (row?.status === 'check-at-shop' && premiumRisk(row.domain) && row.price != null) {
112
+ return { ...withoutListPrice(row, 'check-at-shop'), premiumRisk: true };
113
+ }
114
+ return row;
115
+ }
116
+ return { ...withoutListPrice(row, 'premium'), premium: 'risk' };
61
117
  }
62
118
 
63
119
  export function nameCandidates(name, { variants: includeVariants = true, endings = defaultEndings } = {}) {
64
120
  const selected = endings;
65
121
  const exact = [...new Set(selected)].map(tld => ({ domain: name + '.' + tld, tld, exact: true }));
66
- if (!includeVariants || !selected.includes('com')) return exact;
122
+ // A punycode label takes no prefix or suffix: "get" + "xn--..." is not that spelling.
123
+ if (!includeVariants || !selected.includes('com') || name.startsWith('xn--')) return exact;
67
124
  const variants = ['get' + name, 'try' + name, 'use' + name, name + 'hq'];
68
125
  return [...exact, ...variants.filter(value => label.test(value)).map(value => ({
69
126
  domain: value + '.com', tld: 'com', exact: false,
@@ -86,7 +143,8 @@ export function termCosts(tld, price, renewal) {
86
143
  export function rankName(rows) {
87
144
  return rows.map(row => {
88
145
  const { tld, exact, status, price = null, renewal = null } = row;
89
- const reason = status === 'premium' ? 'Premium price' : status === 'taken' ? 'Already registered'
146
+ const reason = status === 'premium' ? row.premium === 'risk' ? 'May be premium' : 'Premium price' : status === 'reserved' ? 'Not offered for registration'
147
+ : status === 'taken' ? 'Already registered'
90
148
  : status === 'check-at-shop' ? 'Check at shop'
91
149
  : exact ? 'Exact name' : 'Name variation';
92
150
  return { ...row, ...termCosts(tld, price, renewal), reason, terms: facts[tld] ?? null,
@@ -97,19 +155,21 @@ export function rankName(rows) {
97
155
 
98
156
  export function pickName(rows, eligible) {
99
157
  return rows.reduce((best, row) => {
100
- if (!canRecommend(row.tld, eligible) || !['probably-free', 'confirmed'].includes(row.status)) return best;
158
+ if (!canRecommend(row.tld, eligible) || premiumRisk(row.domain) || !['probably-free', 'confirmed'].includes(row.status)) return best;
101
159
  return !best || firstCost(row) < firstCost(best) ||
102
160
  (firstCost(row) === firstCost(best) && row.exact && !best.exact) ? row : best;
103
161
  }, undefined);
104
162
  }
105
163
 
106
164
  export function registrationStatus(registry) {
107
- if (registry.status === 'free') return 'probably-free';
165
+ if (registry.signal === 'reserved') return 'reserved';
166
+ if (registry.status === 'free') return registry.signal === 'premium' ? 'premium' : 'probably-free';
108
167
  return registry.status === 'taken' ? 'taken' : 'check-at-shop';
109
168
  }
110
169
 
111
170
  export function listQuote(catalog, { domain, tld }, now, bundled = bundledCatalog) {
112
- const prices = datedListPrices(catalog, tld, now, bundled).sort((a, b) =>
171
+ // Data-only shops never become the listed pick or its checkout link.
172
+ const prices = datedListPrices(catalog, tld, now, bundled).filter(row => linkable(row.id)).sort((a, b) =>
113
173
  a.firstYear - b.firstYear || a.renewal - b.renewal);
114
174
  const best = prices[0];
115
175
  const confirmShop = prices.find(row => confirmingShops.includes(row.id))?.id ??
@@ -121,6 +181,20 @@ export function listQuote(catalog, { domain, tld }, now, bundled = bundledCatalo
121
181
  };
122
182
  }
123
183
 
184
+ // A premium, reserved or possible-premium signal never leaves a list price on the row.
185
+ export function withoutListPrice(row, status, reason) {
186
+ return { ...row, status, price: null, renewal: null, priceSource: null, priceCheckedAt: null,
187
+ ...(reason && { registryReason: reason }) };
188
+ }
189
+
190
+ // A quote above the same shop's list price without a standard-price marker may be premium.
191
+ export function possiblePremium(row, quote) {
192
+ return quote?.status === 'confirmed' && quote.standard !== true && row?.shop != null && quote.shopName === row.shop
193
+ && row.price != null && money(quote.price) > row.price + 0.01;
194
+ }
195
+
196
+ const money = value => typeof value === 'number' && Number.isFinite(value) ? value : null;
197
+
124
198
  export function mergeQuote(row, quote) {
125
199
  if (!quote || quote.status === 'could-not-confirm' || quote.error) {
126
200
  return row;
@@ -129,9 +203,18 @@ export function mergeQuote(row, quote) {
129
203
  return { ...row, status: 'taken', price: null, renewal: null, shop: null, buyUrl: null,
130
204
  priceCheckedAt: null, checkedAt: quote.checkedAt ?? row.checkedAt, source: 'shop' };
131
205
  }
132
- return { ...row, status: quote.status, price: quote.price, renewal: quote.renewal,
133
- shop: quote.shopName, buyUrl: quote.buyUrl, priceCheckedAt: null,
134
- checkedAt: quote.checkedAt ?? row.checkedAt, source: 'shop' };
206
+ if (quote.status === 'reserved') {
207
+ return { ...withoutListPrice(row, 'reserved', quote.reason ?? 'Not offered for registration'),
208
+ checkedAt: quote.checkedAt ?? row.checkedAt };
209
+ }
210
+ // A short name stays a possible premium unless the shop marks its quote as standard.
211
+ const premium = row.status === 'premium' && row.premium === true ? true
212
+ : quote.status === 'premium' ? quote.premium ?? true : possiblePremium(row, quote) ? 'possible'
213
+ : (row.premium === 'risk' || row.premiumRisk) && quote.standard !== true ? 'possible' : false;
214
+ const price = money(quote.price) > 0 ? quote.price : null;
215
+ return { ...row, status: premium ? 'premium' : quote.status, price, renewal: price == null ? null : quote.renewal ?? null,
216
+ ...(premium && { premium }), shop: quote.shopName, buyUrl: quote.buyUrl, priceCheckedAt: null, priceSource: null,
217
+ quotedAt: quote.checkedAt ?? null, checkedAt: quote.checkedAt ?? row.checkedAt, source: 'shop' };
135
218
  }
136
219
 
137
220
  export async function searchCandidates(groups, options = {}) {
@@ -151,6 +234,8 @@ export async function searchCandidates(groups, options = {}) {
151
234
  const onResult = ({ domain, tld, exact }, registry) => {
152
235
  if (timeLeft() <= 0) return;
153
236
  lookedUp.set(domain, registry);
237
+ const status = registrationStatus(registry);
238
+ options.onProgress?.({ domain, status: status === 'probably-free' && premiumRisk(domain) ? 'premium' : status });
154
239
  if (registry.status !== 'taken' || !exact || !siteEndings.includes(tld)) return;
155
240
  const timeout = Math.min(options.siteTimeout ?? 1200, timeLeft());
156
241
  sites.set(domain, { pending: (options.comSite ?? checkDomainSite)(domain, timeout, options.siteDetails).then(site => {
@@ -173,20 +258,31 @@ export async function searchCandidates(groups, options = {}) {
173
258
  clearTimeout(timer);
174
259
  }
175
260
  const checkedAt = (options.now ?? new Date()).toISOString();
261
+ // Premium and reserved answers from earlier shop checks also hold here, so a list price never covers them.
262
+ const signals = await cachedSignals([...candidates.keys()], { directory: options.directory, now });
176
263
  const results = groups.map(group => {
177
264
  const rows = rankName(group.candidates.map(row => {
178
265
  const lookup = lookedUp.get(row.domain);
179
- if (!lookup) return { ...row, status: 'check-at-shop', registryReason: 'Registry lookup timed out',
180
- ...listQuote(catalog, row, now, bundled) };
266
+ if (!lookup) {
267
+ const waiting = withPremiumRisk({ ...row, status: 'check-at-shop', registryReason: 'Registry lookup timed out',
268
+ ...listQuote(catalog, row, now, bundled) });
269
+ const signal = signals.get(row.domain);
270
+ return ['premium', 'reserved'].includes(signal?.status) ? mergeQuote(waiting, signal) : waiting;
271
+ }
181
272
  const status = registrationStatus(lookup);
182
273
  const quote = listQuote(catalog, row, now, bundled);
183
274
  const listPrice = status === 'taken' && quote.price != null
184
275
  ? { shop: quote.shop, checkedAt: quote.priceCheckedAt, ...termCosts(row.tld, quote.price, quote.renewal),
185
276
  renewalJump: quote.renewal > 2 * quote.price }
186
277
  : null;
187
- return { ...row, status, checkedAt: lookup.checkedAt ?? checkedAt, source: lookup.source, registryReason: lookup.reason,
188
- forSale: Boolean(lookup.forSale), ...(lookup.marketplace && { marketplace: lookup.marketplace }),
189
- ...(status !== 'taken' ? quote : listPrice && { listPrice }) };
278
+ const settled = withPremiumRisk({ ...row, status, checkedAt: lookup.checkedAt ?? checkedAt, source: lookup.source,
279
+ registryReason: lookup.reason, forSale: Boolean(lookup.forSale), ...(lookup.marketplace && { marketplace: lookup.marketplace }),
280
+ ...(status === 'check-at-shop' && lookup.likely && { likely: lookup.likely }),
281
+ ...(status !== 'taken' ? quote : listPrice && { listPrice }) });
282
+ if (status === 'premium') return { ...withoutListPrice(settled, 'premium'), premium: true };
283
+ if (status === 'reserved') return withoutListPrice(settled, 'reserved', lookup.reason);
284
+ const signal = status === 'taken' ? null : signals.get(row.domain);
285
+ return signal ? mergeQuote(settled, signal) : settled;
190
286
  }));
191
287
  const checkedSites = {};
192
288
  for (const row of rows) {
@@ -1,12 +1,12 @@
1
- export const showAsIs = 'Show `display` to the person as is, then add your advice below it.';
1
+ export const showAsIs = 'Show `display` exactly as written, then add at most two sentences of advice below it.';
2
+ export const purchaseLine = 'Domain Hound cannot buy or complete checkout; use the link above.';
2
3
 
3
4
  export const googleSearchInstruction = 'Before answering, use your built-in web search for each name marked google.search (up to 3). '
4
- + 'Search "<name>" and "<name>" app once each. Review the first 10 returned results of each search, or all results if fewer are returned. Fill google.result and update the Google line using its search link. '
5
+ + 'Search "<name>" and "<name>" app once each. Review the first 10 returned results of each search, or all results if fewer are returned. '
5
6
  + 'Count exact names only. Say Google: open if you find no same-name brand or product, Google: crowded for several unrelated uses, '
6
7
  + 'or Google: owned by <brand> if one brand dominates or a same-business product appears. '
7
- + 'Use Google results to update the Google line and cite additional same-name uses after the display. Keep the tool’s verdict, full reason, traction and dormant notes in the table. '
8
- + 'If you cannot search, keep the original Google line. Write the Google result and both app-store results with their links in every name row. '
9
- + 'Then answer directly. Do not run more searches, generate replacements, or repeat a Domain Hound call.';
8
+ + 'Put any Google findings below the display. Keep the tool’s verdict, reason, traction and search links in the display. '
9
+ + 'Then answer directly. Do not run more searches or generate replacement names.';
10
10
 
11
11
  export const geoInstruction = 'GEO (presence in AI answers): for each name, answer from your own knowledge only, without searching or calling tools, '
12
12
  + 'whether you know a specific brand, company or product by that exact name: "known: <what it is, a few words>" or "unknown". '
@@ -18,4 +18,4 @@ export const namingRecipe = (about = '') => 'Naming recipe (intermediate). Use t
18
18
  + '2. Generate about 30 words. Pair one with a familiar animal or object. 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
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: copy the final table. Update only the Google result. Keep every row with all prices and links. Never buy.';
21
+ + '5. Answer: ' + showAsIs + ' Keep all five candidates and let the person choose.';
@@ -13,6 +13,7 @@ const spaceshipEndings = targetEndings.filter(tld => !otherEndings.includes(tld)
13
13
  const filename = 'prices.json';
14
14
  const day = 86_400_000;
15
15
  const primaryShops = ['spaceship', 'porkbun', 'dynadot'];
16
+ const automaticShops = ['porkbun', 'dynadot'];
16
17
  const refreshMarker = 'price-refresh.attempt';
17
18
  const pricingPage = 'https://www.spaceship.com/domain-search/pricing/';
18
19
 
@@ -121,7 +122,7 @@ export async function getNameCatalog({ directory = cacheDir, now = new Date(), s
121
122
  coldWaitMs = 1900 } = {}) {
122
123
  const saved = await loadCachedCatalog(directory);
123
124
  const sources = sourcesOf(saved);
124
- const refresh = !saved || primaryShops.some(id => isCatalogStale(sources[id]?.checkedAt, now)) ||
125
+ const refresh = !saved || automaticShops.some(id => isCatalogStale(sources[id]?.checkedAt, now)) ||
125
126
  targetEndings.some(tld => !primaryShops.some(id => sources[id]?.prices[tld]) &&
126
127
  (!sources.gandi?.prices[tld] || isCatalogStale(sources.gandi.checkedAt, now)));
127
128
  if (directory && refresh) {
@@ -214,8 +215,8 @@ export function gandiPrice(html, tld) {
214
215
  return null;
215
216
  }
216
217
 
217
- async function loadGandiPrice(tld) {
218
- const response = await fetch('https://www.gandi.net/en/domain/tld/' + tld + '?currency=USD', {
218
+ async function loadGandiPrice(tld, fetcher) {
219
+ const response = await fetcher('https://www.gandi.net/en/domain/tld/' + tld + '?currency=USD', {
219
220
  signal: AbortSignal.timeout(5500),
220
221
  });
221
222
  return response.ok ? gandiPrice(await response.text(), tld) : null;
@@ -287,8 +288,9 @@ export async function loadDynadotPrices(fetcher = globalThis.fetch) {
287
288
  }
288
289
 
289
290
  export async function refreshPrices({
290
- directory = cacheDir, now = new Date(), spaceship = loadSpaceshipPrices, gandi = loadGandiPrice,
291
- porkbun = loadPorkbunPrices, dynadot = loadDynadotPrices,
291
+ directory = cacheDir, now = new Date(), fetcher = globalThis.fetch, browser = false,
292
+ spaceship = browser ? loadSpaceshipPrices : () => null, gandi = tld => loadGandiPrice(tld, fetcher),
293
+ porkbun = () => loadPorkbunPrices(fetcher), dynadot = () => loadDynadotPrices(fetcher),
292
294
  } = {}) {
293
295
  const checkedAt = now.toISOString();
294
296
  const results = await Promise.allSettled([spaceship, porkbun, dynadot].map(load => Promise.resolve().then(() => load())));
@@ -11,7 +11,8 @@ export const shops = {
11
11
  url: 'https://www.cloudflare.com/domains/search/?q=',
12
12
  note: 'Must use Cloudflare DNS',
13
13
  },
14
- porkbun: { name: 'Porkbun', url: 'https://porkbun.com/checkout/search?q=' },
14
+ // Porkbun's public price list is used as data only: never a recommended shop, a checkout link or a pick.
15
+ porkbun: { name: 'Porkbun', url: 'https://porkbun.com/checkout/search?q=', dataOnly: true },
15
16
  namecheap: { name: 'Namecheap', url: 'https://www.namecheap.com/domains/registration/results/?domain=' },
16
17
  dynadot: { name: 'Dynadot', url: 'https://www.dynadot.com/domain/search?domain=' },
17
18
  namesilo: { name: 'NameSilo', url: 'https://www.namesilo.com/domain/search-domains?query=' },
@@ -45,11 +46,16 @@ export function offer(shop, domain, details) {
45
46
  sources, checked, transferLockDays, payWithoutCard,
46
47
  },
47
48
  buyUrl: shopSearchUrl(shop, domain),
49
+ ...(shops[shop].dataOnly && { dataOnly: true }),
48
50
  };
49
51
  }
50
52
 
53
+ export function linkable(shop) {
54
+ return Object.hasOwn(shops, shop) && !shops[shop].dataOnly;
55
+ }
56
+
51
57
  export function shopSearchUrl(shop, domain) {
52
- if (!Object.hasOwn(shops, shop)) return null;
58
+ if (!linkable(shop)) return null;
53
59
  const { url, suffix = '' } = shops[shop];
54
60
  return url + encodeURIComponent(domain) + suffix;
55
61
  }
@@ -0,0 +1,14 @@
1
+ // Progress events for the MCP server while a lookup runs: one stderr line each, only when the server asks.
2
+ // Events: { domain, status } per registry answer, and { stage } for the step after the registry checks.
3
+ export const progressPrefix = 'domain-hound-progress ';
4
+
5
+ export function progressReporter(env = process.env, stream = process.stderr) {
6
+ if (env.DOMAIN_HOUND_PROGRESS !== '1') return undefined;
7
+ return event => {
8
+ try {
9
+ stream.write(progressPrefix + JSON.stringify(event) + '\n');
10
+ } catch {
11
+ // Progress is optional; the lookup result never depends on it.
12
+ }
13
+ };
14
+ }