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
@@ -1,9 +1,14 @@
1
1
  import { canRecommend, defaultEndings, eligibilityNotes, nameCandidates, normalizeName, searchCandidates, searchKey,
2
2
  validEligibility, validEndings } from './name-search.mjs';
3
3
  import { shopSearchUrl } from './prices.mjs';
4
- import { checkHandles, compactText, handleSearches, letters, searchApps, searchEntities, searchMarks, trademarkSearches } from './triage-sources.mjs';
4
+ import { checkHandles, compactText, handleSearches, letters, markOrder, searchApps, searchEntities, searchMarks, trademarkSearches }
5
+ from './triage-sources.mjs';
6
+ import { checkOffice, officeAnswered, officeNames } from './trademarks.mjs';
7
+ import { screenMeaning } from './meaning.mjs';
5
8
  import { loadEdgarCompanies, matchEdgarCompanies, searchNorwegianCompanies } from './company-search.mjs';
6
9
  import { mapLimit } from './cache.mjs';
10
+ import { setTimeout as delay } from 'node:timers/promises';
11
+ import { checkSocialHandles } from './handles.mjs';
7
12
  import { checkDomainSite } from './com-site.mjs';
8
13
  import { playSearchLink, searchAndroidApps } from './google-play.mjs';
9
14
  import { googleSearchLink, lowerVerdict, nameCheckLines, searchGoogle } from './google-search.mjs';
@@ -11,6 +16,11 @@ import { autocompleteWords, collectRivals, createTraction, evidenceLifetime, jud
11
16
  tractionNotes, tractionSummary, tractionVerdict } from './traction.mjs';
12
17
 
13
18
  const coreWebsiteEndings = ['com', 'ai', 'io', 'app', 'co'];
19
+ // The slow, rate-limited sources (trademarks, app stores, rivals, web traction, GitHub and npm) screen only the first
20
+ // five names; registry answers and prices cover every name. Social handle rows go to the top three.
21
+ export const screenLimit = 5;
22
+ export const handleLimit = 3;
23
+ export const notScreened = 'Not screened (marks, apps, rivals: first ' + screenLimit + ' names only)';
14
24
  const typicalProducts = [
15
25
  [/(?:domain|whois)/, /\b(?:domains?|whois|registrar)\b/i],
16
26
  [/(?:accounting|bookkeep|invoice|ledger)/, /\b(?:accounting|bookkeeping|invoic(?:e|ing)|ledger)\b/i],
@@ -90,7 +100,7 @@ function counted(count, singular, plural = singular + 's') {
90
100
  return count + ' ' + (count === 1 ? singular : plural);
91
101
  }
92
102
 
93
- function sameNameEvidence({ name, live, norway, us, entities, entity, github, handles }) {
103
+ function sameNameEvidence({ name, live, norway, us, entities, entity, github, handles, deferHandles }) {
94
104
  const sameBusiness = live.filter(site => site.sameBusiness).length;
95
105
  const businesses = new Map();
96
106
  for (const { business } of live) if (business !== 'unknown') businesses.set(business, (businesses.get(business) ?? 0) + 1);
@@ -106,14 +116,13 @@ function sameNameEvidence({ name, live, norway, us, entities, entity, github, ha
106
116
  github.ownerType === 'Organization' && 'GitHub org taken',
107
117
  repos && counted(repos, 'GitHub repo'),
108
118
  handles.npm === 'taken' && 'npm package',
109
- handles.PyPI === 'taken' && 'PyPI package',
110
119
  ].filter(Boolean);
111
120
  const count = live.length + (norway?.matches.length ?? 0) + (us?.matches.length ?? 0) + (entities?.length ?? 0)
112
121
  + Math.min(repos * 0.25, 1) + Number(github.ownerType === 'Organization')
113
- + Number(handles.npm === 'taken') + Number(handles.PyPI === 'taken');
122
+ + Number(handles.npm === 'taken');
114
123
  const unchecked = [
115
- !norway && 'Brønnøysund', !us && 'EDGAR', !entities && 'Wikidata', github.status === 'unknown' && 'GitHub',
116
- handles.npm === 'unknown' && 'npm', handles.PyPI === 'unknown' && 'PyPI',
124
+ !norway && 'Brønnøysund', !us && 'EDGAR', !entities && 'Wikidata', !deferHandles && github.status === 'check' && 'GitHub',
125
+ !deferHandles && handles.npm === 'check' && 'npm',
117
126
  ].filter(Boolean);
118
127
  return {
119
128
  summary: 'Same name used by: ' + (summary.join(', ') || 'none found'),
@@ -135,24 +144,41 @@ function appStatus(ios, android) {
135
144
  + (android ? android.length ? taken('Android', android) : 'free on Android' : 'Android not checked');
136
145
  }
137
146
 
147
+ // US marks read as before; EU and Norwegian marks name their office and status first.
138
148
  function trademarkReason(mark) {
139
- return mark && mark.tier + ': ' + mark.name + ' (' + (mark.owner || 'owner unavailable') + ', '
149
+ const office = mark?.office && mark.office !== 'US' ? officeNames[mark.office] + ' ' + mark.status + ', ' : '';
150
+ return mark && mark.tier + ': ' + mark.name + ' (' + office + (mark.owner || 'owner unavailable') + ', '
140
151
  + (mark.classes.join('/') || 'class unavailable') + ')';
141
152
  }
142
153
 
143
- function verdict({ mark, otherMark, silent, ...evidence }) {
154
+ // The EU and Norwegian hits a person can open: office, mark, status, classes and the office's own record.
155
+ function officeMarkEntries(marks) {
156
+ const firstByOffice = Object.keys(officeNames).map(office => marks.find(mark => mark.office === office)).filter(Boolean);
157
+ const selected = [...firstByOffice, ...marks.filter(mark => !firstByOffice.includes(mark))].slice(0, 3).sort((a, b) =>
158
+ marks.indexOf(a) - marks.indexOf(b));
159
+ return selected.map(mark => ({ office: officeNames[mark.office], mark: mark.name,
160
+ tier: mark.tier, status: mark.status, classes: mark.classes, url: mark.url, ...(mark.checkedAt && { checkedAt: mark.checkedAt }) }));
161
+ }
162
+
163
+ function verdict({ mark, otherMark, silent, waiting = [], ...evidence }) {
144
164
  const [decision, reason] = baseVerdict({ mark, ...evidence });
145
165
  const trademark = trademarkReason(mark);
146
- const missing = silent.length ? silent.join(', ') + ' did not answer' : '';
166
+ const missing = [silent.length && silent.join(', ') + ' did not answer', waiting.length && 'still checking ' + waiting.join(', ')]
167
+ .filter(Boolean).join('; ');
147
168
  if (reason === 'A competition source did not answer' && missing) return [decision, missing];
169
+ // A clear verdict waits for the checks that are still running; the follow-up re-assesses it.
170
+ if (decision === 'No conflict found' && waiting.length) return ['Check first', missing];
148
171
  return [decision, [reason, trademark !== reason && trademark, trademarkReason(otherMark), missing].filter(Boolean).join(' · ')];
149
172
  }
150
173
 
151
- function silentSources({ marks, apps, android, entities, norway, edgar, github, handles }) {
174
+ function silentSources({ marks, offices, apps, android, entities, norway, edgar, github, handles }) {
152
175
  return Object.entries({
153
- USPTO: marks, 'App Store': apps, 'Google Play': android, Wikidata: entities, Brønnøysund: norway,
154
- EDGAR: edgar, GitHub: github.status === 'unknown' ? null : github.status,
155
- npm: handles.npm === 'unknown' ? null : handles.npm, PyPI: handles.PyPI === 'unknown' ? null : handles.PyPI,
176
+ USPTO: marks,
177
+ ...Object.fromEntries(offices.filter(result => result.state !== 'off')
178
+ .map(result => [officeNames[result.office], officeAnswered(result) ? true : null])),
179
+ 'App Store': apps, 'Google Play': android, Wikidata: entities, Brønnøysund: norway,
180
+ EDGAR: edgar, GitHub: github.status === 'check' ? null : github.status,
181
+ npm: handles.npm === 'check' ? null : handles.npm,
156
182
  }).filter(([, value]) => value == null).map(([source]) => source);
157
183
  }
158
184
 
@@ -217,7 +243,7 @@ export async function namePresence(input, options = {}) {
217
243
  // Same-name rivals with measured traction follow the traction rules first; evidence whose traction could not be
218
244
  // measured keeps the earlier same-name checks. Trademark and availability guardrails stay in place.
219
245
  function baseVerdict({ rival, overlap, sameName, activeApp, brand, app, entity, mark, site, best, available, marks, apps, android,
220
- androidAnswered = android, company, premium = [] }) {
246
+ androidAnswered = android, company, premium = [], offices = [] }) {
221
247
  if (rival?.[0] === 'Avoid') return rival;
222
248
  if (overlap) return ['Avoid', overlap.domain + ' is a live business in the same category'];
223
249
  if (activeApp) return ['Avoid', activeApp.name + ' is an app in the same category with ' + activeApp.ratings + ' ' + activeApp.store + ' ratings'];
@@ -232,12 +258,17 @@ function baseVerdict({ rival, overlap, sameName, activeApp, brand, app, entity,
232
258
  if (android?.length) return ['Check first', 'An exact-name Android app already exists'];
233
259
  if (site) return ['Check first', site.domain + ' has a live site under this name'];
234
260
  if (entity) return ['Check first', 'An exact-name Wikidata entity already exists'];
235
- if (!marks || !apps || !androidAnswered || sameName.unchecked?.length) return ['Check first', 'A competition source did not answer'];
261
+ const answeredOffices = offices.filter(result => result.state !== 'off');
262
+ if (!marks || !apps || !androidAnswered || sameName.unchecked?.length || !answeredOffices.every(officeAnswered)) {
263
+ return ['Check first', 'A competition source did not answer'];
264
+ }
236
265
  if (!best) {
237
266
  return ['Check first', available.length ? 'The free endings require buyer eligibility'
238
267
  : premium.length ? 'The free endings may be premium, price at shop' : 'No domain was found free at the registry'];
239
268
  }
240
- return ['No conflict found', 'No US mark, same-name app or active company found in the sources checked'];
269
+ const regions = ['US', ...answeredOffices.map(result => ({ EU: 'EU', NO: 'Norwegian' })[result.office])];
270
+ return ['No conflict found', 'No ' + regions.slice(0, -1).join(', ') + (regions.length > 1 ? ' or ' : '') + regions.at(-1)
271
+ + ' mark, same-name app or active company found in the sources checked'];
241
272
  }
242
273
 
243
274
  export async function triageNames(inputs, options = {}) {
@@ -262,14 +293,36 @@ export async function triageNames(inputs, options = {}) {
262
293
  const started = performance.now();
263
294
  const timeLeft = () => budgetMs - (performance.now() - started);
264
295
  const signal = AbortSignal.timeout(budgetMs);
265
- const sources = { ...options, signal, timeLeft, cacheLifetime: evidenceLifetime, retryUnavailable: true, githubSearch: names.size <= 5 };
266
- // Ask an unavailable source once more while the triage budget lasts.
267
- const retry = async (lookup, answered) => {
268
- const first = await lookup();
269
- return answered(first) || signal.aborted || timeLeft() < 300 ? first : lookup();
296
+ const sources = { ...options, signal, timeLeft, cacheLifetime: evidenceLifetime, retryUnavailable: true, githubSearch: true };
297
+ const retry = async (lookup, answered, waits = [0]) => {
298
+ let result = await lookup();
299
+ for (const wait of waits) {
300
+ if (answered(result) || signal.aborted || timeLeft() < wait + 300) break;
301
+ if (wait) await delay(wait);
302
+ if (!signal.aborted) result = await lookup();
303
+ }
304
+ return result;
270
305
  };
271
306
  const found = value => value != null;
272
- const traction = createTraction({ ...sources, refreshTranco: options.refreshTranco === true });
307
+ // A follow-up run calls triageNames twice with one memo. The first pass answers by options.answerAt with the checks
308
+ // done so far and lists the others as waiting; the second pass reuses every started lookup and re-assesses the names.
309
+ const memo = options.memo ?? new Map();
310
+ const once = (key, start) => {
311
+ if (!memo.has(key)) memo.set(key, start());
312
+ return memo.get(key);
313
+ };
314
+ const answerBy = options.answerAt == null ? null
315
+ : new Promise(resolve => setTimeout(resolve, Math.max(0, options.answerAt - performance.now())));
316
+ const waiting = new Map();
317
+ const wait = (index, source) => waiting.set(index, new Set([...waiting.get(index) ?? [], source]));
318
+ const waitingFor = index => [...new Set([...waiting.get('all') ?? [], ...waiting.get(index) ?? []])];
319
+ const byAnswer = (promise, index, source, fallback = null) => {
320
+ if (!answerBy) return promise;
321
+ let settled = false;
322
+ return Promise.race([promise.then(value => { settled = true; return value; }),
323
+ answerBy.then(() => { if (settled) return fallback; wait(index, source); return fallback; })]);
324
+ };
325
+ const traction = once('traction', () => createTraction({ ...sources, refreshTranco: options.refreshTranco === true }));
273
326
  const nameOf = new Map([...names.keys()].map((name, index) => [name, index]));
274
327
  // Start traction lookups as soon as a rival's home is known, so the slow free sources overlap the other checks.
275
328
  const startHomes = (name, domains, live = true) => {
@@ -277,7 +330,7 @@ export async function triageNames(inputs, options = {}) {
277
330
  };
278
331
  const onSite = (domain, site) => {
279
332
  const name = domain.slice(0, domain.indexOf('.'));
280
- if (!nameOf.has(name)) return;
333
+ if (!nameOf.has(name) || nameOf.get(name) >= screenLimit) return;
281
334
  if (site?.state === 'live') startHomes(name, [domain]);
282
335
  else if (site?.state === 'parked' || site?.state === 'for-sale') startHomes(name, [domain], false);
283
336
  };
@@ -285,8 +338,17 @@ export async function triageNames(inputs, options = {}) {
285
338
  name, candidates: nameCandidates(name, { variants: false, endings: websiteEndings }),
286
339
  }));
287
340
  const entries = [...names].map(([name, input], index) => [keys.get(name), input, index]);
341
+ // The names put first are screened in full: the person's own name and the strongest candidates.
342
+ const screened = entries.slice(0, screenLimit);
343
+ const isScreened = index => index < screenLimit;
344
+ const screenedDomains = new Set([...names.keys()].slice(0, screenLimit));
345
+ const sourceNames = new Map([[searchMarks, 'USPTO'], [searchApps, 'App Store'], [searchEntities, 'Wikidata'],
346
+ [searchNorwegianCompanies, 'Brønnøysund']]);
288
347
  const check = (concurrency, lookup, after = () => {}) => mapLimit(entries, concurrency, async ([name, input, index]) => {
289
- const result = signal.aborted ? null : await retry(() => lookup(name, input, sources), found);
348
+ const source = sourceNames.get(lookup) ?? lookup.name;
349
+ const waits = lookup === searchApps || lookup === searchEntities ? [450 + index * 110, 1600 + index * 110] : [0];
350
+ const result = signal.aborted || !isScreened(index) ? null
351
+ : await byAnswer(once(source + ':' + name, () => retry(() => lookup(name, input, sources), found, waits)), index, source);
290
352
  after(result, index);
291
353
  return result;
292
354
  });
@@ -302,24 +364,55 @@ export async function triageNames(inputs, options = {}) {
302
364
  startHomes(name, (result ?? []).filter(row => row.brand).flatMap(row => (row.website ?? []).map(siteDomain))
303
365
  .filter(domain => domain?.split('.')[0].includes(name)));
304
366
  });
305
- const [domains, marksByName, appsByName, entitiesByName, handlesByName, norwayByName, androidApps, edgar, googleByName] =
306
- await Promise.all([
367
+ // A caller that already holds registry answers and site evidence (the broker dossier) passes them in, so the screen
368
+ // reuses them and makes no registry or site calls of its own.
369
+ const domainsDone = once('domains', () => options.domainSearch ? Promise.resolve().then(() => options.domainSearch(groups))
370
+ : searchCandidates(groups, { ...options, budgetMs: Math.min(budgetMs, 11500),
371
+ siteEndings: websiteEndings, siteTimeout: 3000, siteDetails: true, onSite,
372
+ siteFilter: domain => screenedDomains.has(domain.slice(0, domain.indexOf('.'))) }));
373
+ // GitHub and npm accounts are same-name evidence for every screened name; they share one run of controls.
374
+ const evidenceHandles = options.deferHandles ? Promise.resolve(new Map()) : once('evidenceHandles', () => checkSocialHandles(screened.map(([name]) => ({ name, platforms: ['GitHub', 'npm'], links: false })),
375
+ { ...options, signal }));
376
+ // Once the registry answers are in, the top three names get the full handle row, with Bluesky and variants.
377
+ const handleRows = options.deferHandles || options.handleRows === false ? Promise.resolve(new Map()) : once('handleRows', () => domainsDone.then(domains => {
378
+ const order = handleOrder(domains.groups, keys, options.eligible).slice(0, handleLimit);
379
+ options.onProgress?.({ stage: 'handles' });
380
+ return evidenceHandles.then(() => checkSocialHandles(order.map(key => ({ name: key, variants: true })), { ...options, signal }));
381
+ }).catch(() => new Map()));
382
+ // Google Play answers per name, so the first pass keeps the names it has.
383
+ const playLive = once('playLive', () => new Map());
384
+ let playFinished = !answerBy;
385
+ const play = once('play', () => searchAndroidApps(new Map(screened.map(([key, input]) => [key, input])),
386
+ { ...sources, onResult: (name, apps) => playLive.set(name, apps),
387
+ playBudgetMs: Math.min(answerBy ? 20000 : 12000, options.playBudgetMs ?? Infinity, budgetMs) }));
388
+ const unverifiedHandles = { github: { status: 'check' }, handles: { GitHub: 'check', npm: 'check' } };
389
+ // Share the optional office lookups between passes and keep them off the first answer's critical path.
390
+ const officeCheck = office => mapLimit(entries, 4, ([name, input, index]) => isScreened(index)
391
+ ? byAnswer(once(office + ':' + name, () => checkOffice(office, name, input, sources)),
392
+ index, officeNames[office], { office, state: 'pending' }) : null);
393
+ const [domains, marksByName, appsByName, entitiesByName, handlesByName, norwayByName, androidApps, edgar, googleByName, socialByName,
394
+ euByName, noByName] = await Promise.all([
307
395
  // A cold cache still gets the bundled, dated list prices, so free endings never all read "price at shop".
308
- searchCandidates(groups, { ...options, budgetMs: Math.min(budgetMs, 11500),
309
- siteEndings: websiteEndings, siteTimeout: 3000, siteDetails: true, onSite }),
396
+ // The second pass also collects the slow website checks.
397
+ options.memo && !answerBy ? domainsDone.then(async done => { await done.settleSites?.(); return done; }) : domainsDone,
310
398
  check(6, searchMarks), check(8, searchApps, (result, index) => startHomes(entries[index][0],
311
399
  (result ?? []).map(row => siteDomain(row.sellerUrl)).filter(domain => domain?.split('.')[0].includes(entries[index][0])))),
312
400
  entityChecks,
313
- Promise.all(entries.map(([name]) => checkHandles(name, sources))),
401
+ Promise.all(entries.map(([name], index) => isScreened(index)
402
+ ? byAnswer(once('handles:' + name, () => checkHandles(name, {
403
+ ...sources, social: evidenceHandles.then(rows => rows.get(name)).catch(() => null),
404
+ })), index, 'GitHub repositories', unverifiedHandles) : null)),
314
405
  check(8, searchNorwegianCompanies),
315
- searchAndroidApps(new Map(entries.map(([key, input]) => [key, input])),
316
- { ...sources, playBudgetMs: Math.min(12000, options.playBudgetMs ?? Infinity, budgetMs) }),
317
- retry(() => loadEdgarCompanies(sources), found),
318
- mapLimit(entries, 5, ([name, input, index]) => searchGoogle(name, input, {
406
+ answerBy ? Promise.race([play.then(map => [map, true]), answerBy.then(() => [new Map(playLive), false])])
407
+ .then(([map, done]) => { playFinished = done; return map; }) : play,
408
+ byAnswer(once('edgar', () => retry(() => loadEdgarCompanies(sources), found)), 'all', 'EDGAR'),
409
+ mapLimit(entries, 5, ([name, input, index]) => isScreened(index) ? byAnswer(once('google:' + name, () => searchGoogle(name, input, {
319
410
  ...sources, timeoutMs: timeLeft(),
320
411
  entities: entities[index].promise,
321
412
  sameBusiness: text => describedBusiness(name, text, options.about, options.category),
322
- })),
413
+ })), index, 'Google', { unchecked: 'still checking' }) : { unchecked: 'not screened' }),
414
+ handleRows,
415
+ officeCheck('EU'), officeCheck('NO'),
323
416
  ]);
324
417
  const counts = {};
325
418
  function coverage(source, answered) { counts[source] = (counts[source] ?? 0) + Number(answered); }
@@ -329,6 +422,7 @@ export async function triageNames(inputs, options = {}) {
329
422
  ...(androidApps.get(keys.get(name)) ?? []).map(row => ({ ...row, store: 'Android', ref: row })),
330
423
  ]);
331
424
  const rivalsByName = domains.groups.map(({ name, sites }, index) => {
425
+ if (!isScreened(index)) return [];
332
426
  const raw = googleByName[index].raw ?? {};
333
427
  const key = keys.get(name);
334
428
  const rivals = collectRivals({
@@ -339,9 +433,46 @@ export async function triageNames(inputs, options = {}) {
339
433
  startEvidence(traction, rivals);
340
434
  return rivals;
341
435
  });
436
+ if (!playFinished) for (const [key, , index] of screened) if (!androidApps.has(key)) wait(index, 'Google Play');
342
437
  options.onProgress?.({ stage: 'rivals' });
343
- const evidence = await traction.settle();
438
+ // The first pass waits for rival traction only until its answer is due.
439
+ const evidence = await traction.settle(answerBy ? Math.max(150, timeLeft() - Math.max(0, options.answerAt - performance.now())) : undefined);
344
440
  const rows = domains.groups.map(({ name, results, sites }, index) => {
441
+ const requested = results.filter(row => endings.includes(row.tld));
442
+ const available = results.filter(row => row.status === 'probably-free' && endings.includes(row.tld));
443
+ const recommendable = available.filter(row => canRecommend(row.tld, options.eligible));
444
+ const [best] = recommendable;
445
+ const social = socialByName.get(keys.get(name)) ?? null;
446
+ const domainFields = {
447
+ taken: requested.filter(row => row.status === 'taken').map(row => row.tld),
448
+ shop_check: requested.filter(row => ['check-at-shop', 'reserved'].includes(row.status)).map(row => row.tld),
449
+ ...(requested.some(row => row.status === 'reserved') && {
450
+ reserved: requested.filter(row => row.status === 'reserved').map(row => row.tld) }),
451
+ // Subsets of shop_check with a DNS likelihood; only a registry or shop settles them.
452
+ ...likelyEndings(requested),
453
+ // Premium endings never carry a list price; the shop shows their price. A short name may be premium.
454
+ ...(requested.some(row => row.status === 'premium') && {
455
+ premium: requested.filter(row => row.status === 'premium').map(row => row.tld) }),
456
+ };
457
+ const receipt = options.receipt && { _receiptEndings: requested.map(row => ({ domain: row.domain, source: row.source,
458
+ checkedAt: row.checkedAt, priceAt: row.priceCheckedAt, shop: row.shop, checkout: row.buyUrl,
459
+ site: sites[row.tld], risk: row.premium === 'risk' || row.premiumRisk, ...(row.savings && { savings: row.savings }) })),
460
+ _handles: social, _waiting: () => isScreened(index) ? waitingFor(index) : [] };
461
+ if (!isScreened(index)) {
462
+ // Registry answers and prices only. The verdict never reads "No conflict found" without the checks.
463
+ return {
464
+ name: names.get(name), verdict: 'Check first', reason: notScreened,
465
+ _free: available, _recommendable: recommendable, _googleExplained: true,
466
+ google: { result: 'not checked', why: 'not screened', link: googleSearchLink(names.get(name)) },
467
+ ...domainFields,
468
+ competition: { US: null, mark: null, AppStore: null, GooglePlay: null, Wikidata: null,
469
+ sameName: { summary: 'Not screened', level: 'unknown' } },
470
+ buy: best ? best.buyUrl ?? shopSearchUrl(best.confirmShop, best.domain) : null,
471
+ ...receipt,
472
+ details: { memorable: memorability(keys.get(name), names.get(name)), presence: null, sites: {},
473
+ appName: 'App name: not checked', AndroidSearch: playSearchLink(names.get(name)) },
474
+ };
475
+ }
345
476
  const marks = marksByName[index];
346
477
  const apps = appsByName[index];
347
478
  const entities = entitiesByName[index];
@@ -360,12 +491,13 @@ export async function triageNames(inputs, options = {}) {
360
491
  const storeApps = storeAppsByName[index];
361
492
  const activeApp = storeApps.find(row => !explained.has(row.ref) && row.ratings >= 100 && describedBusiness(key,
362
493
  [row.name, row.category, row.description].join(' '), options.about, options.category));
363
- const mark = marks?.[0];
364
- const others = marks?.filter(item => letters(item.name) !== letters(mark?.name)) ?? [];
494
+ const offices = [euByName[index], noByName[index]].filter(Boolean);
495
+ const officeMarks = offices.flatMap(result => result.marks ?? []);
496
+ // US, EU and Norwegian hits share one order; a same-name mark at another office stays a separate hit.
497
+ const allMarks = [...(marks ?? []), ...officeMarks].sort(markOrder(key));
498
+ const mark = allMarks[0];
499
+ const others = allMarks.filter(item => item !== mark && (item.office !== mark?.office || letters(item.name) !== letters(mark?.name)));
365
500
  const otherMark = others.find(item => item.relevant) ?? others.find(item => item.tier === 'Fuzzy') ?? others[0];
366
- const available = results.filter(row => row.status === 'probably-free' && endings.includes(row.tld));
367
- const recommendable = available.filter(row => canRecommend(row.tld, options.eligible));
368
- const [best] = recommendable;
369
501
  const seen = websiteEndings.flatMap(tld => {
370
502
  const row = results.find(result => result.tld === tld);
371
503
  return tld === 'com' || row?.status === 'taken' ? [[tld, siteEvidence(row, sites[tld])]] : [];
@@ -386,59 +518,67 @@ export async function triageNames(inputs, options = {}) {
386
518
  const us = matchEdgarCompanies(key, edgar);
387
519
  const company = norway?.matches.find(row => row.employees > 0 && row.match === 'exact')
388
520
  ?? us?.matches.find(row => row.match === 'exact');
389
- const sameName = sameNameEvidence({ name: key, live, norway, us, entities, entity, github, handles });
521
+ const sameName = sameNameEvidence({ name: key, live, norway, us, entities, entity, github, handles, deferHandles: options.deferHandles });
390
522
  const otherEntities = entities?.filter(row => !explained.has(row));
391
- const legacy = sameNameEvidence({ name: key, live: unmeasured, norway, us, entities: otherEntities, entity, github, handles });
392
- const silent = silentSources({ marks, apps, android, entities, norway, edgar, github, handles });
523
+ const legacy = sameNameEvidence({ name: key, live: unmeasured, norway, us, entities: otherEntities, entity, github, handles, deferHandles: options.deferHandles });
524
+ // Taken endings whose website check is still running count as a waiting source.
525
+ const sitesWaiting = options.lateSiteMs > 0 && results.some(row => row.status === 'taken' && row.exact !== false
526
+ && websiteEndings.includes(row.tld) && !sites[row.tld]);
527
+ const sitesSilent = sitesWaiting || Object.values(sites).some(site => site?.state === 'unknown');
528
+ if (answerBy && sitesWaiting) wait(index, 'websites');
529
+ const pending = waitingFor(index);
530
+ const silent = silentSources({ marks, offices, apps, android, entities, norway, edgar, github, handles })
531
+ .filter(source => (!options.deferHandles || !['GitHub', 'npm'].includes(source)) && !pending.includes(source));
532
+ if (sitesSilent && !pending.includes('websites')) silent.push('websites');
393
533
  const otherEntity = otherEntities?.find(row => row.brand) ?? otherEntities?.[0];
394
534
  const [decision, reason] = verdict({
395
535
  rival: tractionVerdict(judged), overlap, sameName: legacy, activeApp,
396
536
  brand: otherEntity?.brand ? otherEntity : undefined, app: apps?.find(row => !explained.has(row)), entity: otherEntity,
397
- mark, otherMark, site, silent, best, available, marks, apps, premium: results.filter(row => row.status === 'premium'),
398
- android: android?.filter(row => !explained.has(row)), androidAnswered: android, company,
537
+ mark, otherMark, site, silent, waiting: pending, best, available, marks, apps, premium: results.filter(row => row.status === 'premium'),
538
+ android: android?.filter(row => !explained.has(row)), androidAnswered: android, company, offices,
399
539
  });
400
540
  const googleExplained = explainedGoogle(key, googleByName[index].raw, judged, entities);
401
541
  const summary = tractionSummary(judged);
402
542
  const answered = {
403
543
  USPTO: marks, 'App Store': apps, 'Google Play': android, Google: google.google, Wikidata: entities,
404
- Brønnøysund: norway, EDGAR: edgar,
405
- ...Object.fromEntries(Object.entries(handles).map(([service, status]) => [service, status === 'unknown' ? null : status])),
544
+ Brønnøysund: norway, EDGAR: edgar, ...(options.memo && { Websites: sitesSilent ? null : true }),
545
+ ...Object.fromEntries(offices.filter(result => result.state !== 'off')
546
+ .map(result => [officeNames[result.office], officeAnswered(result) ? true : null])),
547
+ ...!options.deferHandles && Object.fromEntries(Object.entries(handles).map(([service, status]) => [service, status === 'check' ? null : status])),
406
548
  };
407
549
  for (const [source, value] of Object.entries(answered)) coverage(source, value != null);
550
+ const usMark = marks?.[0];
408
551
  const competition = {
409
- US: mark ? trademarkReason(mark) : marks ? [] : null,
410
- mark: mark?.serial ? 'https://tsdr.uspto.gov/#caseNumber=' + mark.serial + '&caseSearchType=US_APPLICATION&caseType=DEFAULT&searchType=statusSearch' : null,
552
+ US: usMark ? trademarkReason(usMark) : marks ? [] : null,
553
+ mark: usMark?.url ?? null,
554
+ // EU and NO appear once a key is set: the strongest hit, [] when the office answered in full with none,
555
+ // null when it failed or answered in part (check yourself).
556
+ ...Object.fromEntries(offices.filter(result => result.state !== 'off').map(result => {
557
+ const best = result.marks?.[0];
558
+ return [result.office, officeAnswered(result) ? (best ? trademarkReason(best) : []) : null];
559
+ })),
560
+ ...(officeMarks.length > 0 && { marks: officeMarkEntries(officeMarks.sort(markOrder(key))) }),
411
561
  AppStore: app ? { name: app.name, developer: app.seller, ratings: app.ratings, url: app.url } : apps ? [] : null,
412
562
  GooglePlay: android?.map(({ name, seller, url, ratings }) => ({ name, developer: seller, url, ratings })).slice(0, 3) ?? null,
413
563
  Wikidata: entity ? { name: entity.name, description: entity.description, url: entity.url,
414
564
  ...(entity.brand && { brand: true }) } : entities ? [] : null,
415
565
  sameName,
416
566
  };
417
- const requested = results.filter(row => endings.includes(row.tld));
418
567
  return {
419
568
  // Small and dormant same-name uses are notes after the reason; they never change the verdict.
420
569
  name: names.get(name), verdict: decision, reason: [reason, ...tractionNotes(judged)].join(' · '),
421
570
  _free: available, _recommendable: recommendable, _mark: mark, _googleExplained: googleExplained,
422
571
  ...(summary && { traction: summary }),
423
572
  google: { ...(google.google ?? { result: 'not checked', why: google.unchecked }), link: googleSearchLink(names.get(name)) },
424
- taken: requested.filter(row => row.status === 'taken').map(row => row.tld),
425
- shop_check: requested.filter(row => ['check-at-shop', 'reserved'].includes(row.status)).map(row => row.tld),
426
- ...(requested.some(row => row.status === 'reserved') && {
427
- reserved: requested.filter(row => row.status === 'reserved').map(row => row.tld) }),
428
- // Subsets of shop_check with a DNS likelihood; only a registry or shop settles them.
429
- ...likelyEndings(requested),
430
- // Premium endings never carry a list price; the shop shows their price. A short name may be premium.
431
- ...(requested.some(row => row.status === 'premium') && {
432
- premium: requested.filter(row => row.status === 'premium').map(row => row.tld) }),
573
+ ...domainFields,
574
+ _social: compactHandles(social),
433
575
  // The checkout is the listed shop's search, or the confirming shop's search when no list price is known.
434
576
  competition, buy: best ? best.buyUrl ?? shopSearchUrl(best.confirmShop, best.domain) : null,
435
- ...(options.receipt && { _receiptEndings: requested.map(row => ({ domain: row.domain, source: row.source,
436
- checkedAt: row.checkedAt, priceAt: row.priceCheckedAt, shop: row.shop, checkout: row.buyUrl,
437
- site: sites[row.tld], risk: row.premium === 'risk' || row.premiumRisk })) }),
577
+ ...receipt,
438
578
  details: {
439
579
  memorable: memorability(key, names.get(name)),
440
580
  presence: Object.fromEntries(Object.entries(handles).map(([service, status]) =>
441
- [service, status === 'unknown' ? null : status])),
581
+ [service, status === 'check' ? null : status])),
442
582
  sites: Object.fromEntries(seen), appName: appStatus(apps, android),
443
583
  AndroidSearch: android ? null : playSearchLink(names.get(name)),
444
584
  },
@@ -447,23 +587,59 @@ export async function triageNames(inputs, options = {}) {
447
587
  for (const row of rows) {
448
588
  // Google evidence that a measured rival explains is judged by its traction, not by the Google floor.
449
589
  if (!row._googleExplained) lowerVerdict(row, row.google);
590
+ // A rude or embarrassing meaning is a note and at most Check first, for every name, screened or not.
591
+ const meaning = screenMeaning(row.name);
592
+ if (meaning) {
593
+ row.meaning = meaning.note;
594
+ if (row.verdict === 'No conflict found') {
595
+ row.verdict = 'Check first';
596
+ row.reason = 'Meaning: ' + meaning.note + ' · ' + row.reason;
597
+ } else row.reason += ' · Meaning: ' + meaning.note;
598
+ }
450
599
  row.checks = options.compact ? null
451
600
  : nameCheckLines(row).map(({ label, text, link }) => label + ': ' + text + ' · ' + link);
452
601
  }
453
602
  for (const row of googleCandidates(rows)) row.google.search = true;
454
603
  const sourcesSummary = Object.fromEntries(Object.entries(counts).map(([source, answered]) =>
455
- [source, Math.round(100 * answered / names.size)]));
456
- const receiptDetails = options.receipt ? structuredClone(rows.map(({ competition, details, traction, google, reason, _receiptEndings }) =>
457
- ({ competition, details, traction, google, reason, endings: _receiptEndings }))) : null;
604
+ [source, Math.round(100 * answered / Math.min(names.size, screenLimit))]));
605
+ const receiptDetails = options.receipt ? structuredClone(rows.map(({ competition, details, traction, google, reason, meaning, _receiptEndings, _handles, _waiting }) =>
606
+ ({ competition, details, traction, google, reason, meaning, endings: _receiptEndings, handles: _handles,
607
+ ...(_waiting?.().length && { waiting: _waiting() }) }))) : null;
458
608
  const result = packTriage(rows, sourcesSummary, options.compact, endings, options.eligible);
609
+ // The first pass of a follow-up run says more checks are coming.
610
+ if (answerBy && waiting.size) result.followUp = true;
459
611
  if (options.receipt) {
460
612
  result.checkedAt = (options.now ?? new Date()).toISOString();
461
613
  result.priceListDate = domains.priceDate?.slice(0, 10);
462
614
  result.receiptDetails = receiptDetails;
615
+ if (options.deferHandles) {
616
+ const targets = handleOrder(domains.groups, keys, options.eligible).slice(0, handleLimit);
617
+ result.handleTargets = targets.map(name => ({ name, index: [...keys.values()].indexOf(name) }));
618
+ }
463
619
  }
464
620
  return result;
465
621
  }
466
622
 
623
+ // The order the handle rows go in: the person's own name first, then names with a free recommendable ending,
624
+ // cheapest first, then the other screened names in input order.
625
+ export function handleOrder(groups, keys, eligible) {
626
+ const screened = groups.slice(0, screenLimit).map((group, index) => {
627
+ const free = group.results.filter(row => row.status === 'probably-free' && canRecommend(row.tld, eligible))
628
+ .map(row => row.firstPayment ?? Infinity);
629
+ return { key: keys.get(group.name), index, free: free.length > 0, cost: Math.min(...free, Infinity) };
630
+ });
631
+ const [first, ...rest] = screened;
632
+ rest.sort((a, b) => Number(b.free) - Number(a.free) || a.cost - b.cost || a.index - b.index);
633
+ return [first, ...rest].filter(Boolean).map(row => row.key);
634
+ }
635
+
636
+ function compactHandles(entries) {
637
+ if (!Array.isArray(entries)) return null;
638
+ const by = state => entries.filter(entry => entry.state === state).map(entry => entry.platform);
639
+ const [taken, notFound, check] = [by('taken'), by('not-found'), by('check')];
640
+ return { ...(taken.length && { taken }), ...(notFound.length && { not_found: notFound }), ...(check.length && { check }) };
641
+ }
642
+
467
643
  // The first three ranked names, filled from the screened names in input order when fewer than three rank.
468
644
  export function googleCandidates(rows) {
469
645
  const picked = rankedRows(rows).slice(0, 3);
@@ -489,7 +665,7 @@ function likelyEndings(rows) {
489
665
  }
490
666
 
491
667
  // Best value is the lowest total of the payments due in three years; the cheaper first payment breaks a tie.
492
- function bestValue(options) {
668
+ export function bestValue(options) {
493
669
  return options.filter(row => Number.isFinite(row.threeYear)).reduce((best, row) => !best || row.threeYear < best.threeYear
494
670
  || (row.threeYear === best.threeYear && row.firstPayment < best.firstPayment) ? row : best, undefined);
495
671
  }
@@ -518,7 +694,9 @@ function topChoices(rows) {
518
694
  function packTriage(rows, sources, compact, endings, eligible) {
519
695
  const prices = {};
520
696
  const top = topChoices(rows);
521
- const names = rows.map(({ _free, _recommendable, _mark, _googleExplained, _receiptEndings, ...row }) => {
697
+ // Handle states for the top names: taken, not_found (no public profile found) or check (check yourself).
698
+ const handles = Object.fromEntries(rows.filter(row => row._social).map(row => [row.name, row._social]));
699
+ const names = rows.map(({ _free, _recommendable, _mark, _googleExplained, _receiptEndings, _handles, _social, _waiting, ...row }) => {
522
700
  const own = {};
523
701
  for (const option of _free) {
524
702
  const entry = priceEntry(option);
@@ -529,6 +707,7 @@ function packTriage(rows, sources, compact, endings, eligible) {
529
707
  return { ...row, free: _free.map(option => option.tld), own, bestValue: bestValue(_recommendable)?.tld ?? null };
530
708
  });
531
709
  const result = { top, names, prices, sources, eligibility: eligibilityNotes(endings),
710
+ ...(Object.keys(handles).length && { handles }),
532
711
  ...(eligible?.length && { eligible }),
533
712
  ...(!compact && names.length <= 5 && { trademarkSearches, handleSearches }) };
534
713
  const limit = names.length <= 5 ? (compact ? 5600 : 5999) : compact ? 9150 : 9850;
@@ -538,11 +717,16 @@ function packTriage(rows, sources, compact, endings, eligible) {
538
717
  if (size() > limit) for (const row of names) row.buy = null;
539
718
  }
540
719
  for (const trim of [
720
+ // Platforms not listed under taken or not_found are "check yourself"; the results page lists them all.
721
+ () => { for (const value of Object.values(result.handles ?? {})) delete value.check; },
722
+ // GitHub and npm stand in the handle states and the same-name summary too.
723
+ row => { if (row.details) delete row.details.presence; },
541
724
  row => { row.details = null; },
542
725
  row => { row.buy = null; },
543
726
  row => { if (row.traction) delete row.traction.geo; },
727
+ row => { if (row.competition.marks) row.competition.marks = row.competition.marks.slice(0, 1); },
544
728
  row => {
545
- const { sameName, mark, ...remaining } = row.competition;
729
+ const { sameName, mark, marks, ...remaining } = row.competition;
546
730
  row.competition = { ...remaining, mark: null, sameName: { level: sameName.level } };
547
731
  },
548
732
  row => {
@@ -557,9 +741,13 @@ function packTriage(rows, sources, compact, endings, eligible) {
557
741
  row => { delete row.google.why; },
558
742
  row => { row.name = normalizeName(row.name); },
559
743
  row => {
560
- if (typeof row.competition.US === 'string') row.competition.US = row.competition.US.split(':', 1)[0];
744
+ for (const office of ['US', 'EU', 'NO']) {
745
+ if (typeof row.competition[office] === 'string') row.competition[office] = row.competition[office].split(':', 1)[0];
746
+ }
561
747
  row.reason = row.reason.split(' · ', 1)[0];
562
748
  },
749
+ // Last: the results page and say keep the full handle rows.
750
+ () => { delete result.handles; },
563
751
  ]) {
564
752
  if (size() <= limit) break;
565
753
  names.forEach(trim);
@@ -568,7 +756,7 @@ function packTriage(rows, sources, compact, endings, eligible) {
568
756
  const revised = new Map(rows.map(({ name }, index) => [name, names[index]]));
569
757
  for (const [index, row] of names.entries()) {
570
758
  row.reason = compactReason(row, rows[index]._mark, 60);
571
- if (typeof row.competition.US === 'string') row.competition.US = true;
759
+ for (const office of ['US', 'EU', 'NO']) if (typeof row.competition[office] === 'string') row.competition[office] = true;
572
760
  for (const source of ['AppStore', 'GooglePlay', 'Wikidata']) {
573
761
  if (typeof row.competition[source] === 'string') row.competition[source] = true;
574
762
  }
@@ -599,6 +787,8 @@ function compactReason(row, mark, budget) {
599
787
  const suffix = ', ' + (classes || 'class unavailable') + ')';
600
788
  const remaining = budget - Buffer.byteLength(prefix + ' (' + suffix);
601
789
  if (remaining < 6) return shortenBytes(row.reason, budget);
790
+ // A compact EU or Norwegian hit names its office in place of the owner.
791
+ const owner = mark.office && mark.office !== 'US' ? officeNames[mark.office] : mark.owner || 'owner unavailable';
602
792
  return prefix + shortenBytes(mark.name, Math.ceil(remaining / 2)) + ' ('
603
- + shortenBytes(mark.owner || 'owner unavailable', Math.floor(remaining / 2)) + suffix;
793
+ + shortenBytes(owner, Math.floor(remaining / 2)) + suffix;
604
794
  }