domain-hound 0.1.5 → 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.
- package/.agents/plugins/marketplace.json +1 -0
- package/.claude-plugin/marketplace.json +1 -0
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +83 -12
- package/assets/readme-search.png +0 -0
- package/clis/domain-check/broker-atom.mjs +78 -0
- package/clis/domain-check/com-site.mjs +64 -25
- package/clis/domain-check/confirm.mjs +10 -5
- package/clis/domain-check/dossier.mjs +603 -0
- package/clis/domain-check/google-play.mjs +24 -11
- package/clis/domain-check/index.mjs +58 -15
- package/clis/domain-check/marketplaces.mjs +107 -0
- package/clis/domain-check/meaning-words.LICENSE.txt +408 -0
- package/clis/domain-check/meaning-words.json +2397 -0
- package/clis/domain-check/meaning.mjs +77 -0
- package/clis/domain-check/name-search.mjs +71 -9
- package/clis/domain-check/naming-method.mjs +6 -4
- package/clis/domain-check/registry.mjs +2 -2
- package/clis/domain-check/safe-web.mjs +207 -0
- package/clis/domain-check/trademarks.mjs +372 -0
- package/clis/domain-check/triage-sources.mjs +39 -12
- package/clis/domain-check/triage.mjs +162 -50
- package/clis/spaceship/buy.mjs +327 -0
- package/clis/spaceship/client.mjs +170 -0
- package/clis/spaceship/dns.mjs +292 -0
- package/clis/spaceship/quote.mjs +123 -0
- package/clis/spaceship/setup.mjs +81 -0
- package/clis/spaceship/store.mjs +104 -0
- package/clis/spaceship/tools.mjs +258 -0
- package/display.mjs +9 -5
- package/dossier.mjs +185 -0
- package/package.json +20 -2
- package/plugin.json +4 -3
- package/results-style.mjs +10 -0
- package/results.mjs +220 -54
- package/server.json +2 -2
- package/server.mjs +221 -96
- package/share.mjs +43 -0
- package/site/r/share-format.mjs +125 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cacheDir, mapLimit, readCache, writeCache } from './cache.mjs';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
3
|
import { withShopPages } from './confirm.mjs';
|
|
3
4
|
import { appNameMatches, compactText, day, request } from './triage-sources.mjs';
|
|
4
5
|
|
|
@@ -146,29 +147,38 @@ async function lookUp(source, name, input, deadline) {
|
|
|
146
147
|
});
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
// Leave room for a retry on slow pages or failed connections within the shared clock.
|
|
151
|
+
const playAttemptMs = 2800;
|
|
152
|
+
|
|
149
153
|
export async function searchAndroidApps(names, options = {}) {
|
|
150
154
|
const { directory = cacheDir, now = new Date(), playBudgetMs = 12000, cacheLifetime = day } = options;
|
|
151
|
-
const
|
|
155
|
+
const budget = Math.min(30000, playBudgetMs);
|
|
156
|
+
const deadline = performance.now() + budget;
|
|
157
|
+
const retryMs = Math.min(playAttemptMs, budget / 2);
|
|
158
|
+
const answered = (name, apps) => { results.set(name, apps); options.onResult?.(name, apps); };
|
|
152
159
|
const results = new Map();
|
|
153
160
|
const pending = (await Promise.all([...names].map(async ([name, input]) => {
|
|
154
161
|
const filename = 'triage-play-' + name + '.json';
|
|
155
162
|
const prior = await readCache(directory, filename);
|
|
156
163
|
const age = now.getTime() - prior?.at;
|
|
157
164
|
if (age >= 0 && age < cacheLifetime && Array.isArray(prior.apps) && prior.apps.every(app => Object.hasOwn(app, 'ratings')) && (!prior.apps.length || prior.version === 2)) {
|
|
158
|
-
|
|
165
|
+
answered(name, prior.apps);
|
|
159
166
|
return null;
|
|
160
167
|
}
|
|
161
168
|
return { name, input, filename };
|
|
162
169
|
}))).filter(Boolean);
|
|
170
|
+
const waits = budget < 1600 ? [0, 0] : [0, 350, 1200];
|
|
163
171
|
const search = useSource => mapLimit(pending, 5, async ({ name, input, filename }) => {
|
|
164
172
|
if (performance.now() >= deadline) return;
|
|
165
|
-
for (
|
|
173
|
+
for (const pause of waits) {
|
|
174
|
+
if (options.signal?.aborted || deadline - performance.now() < (pause ? retryMs + pause : 1)) break;
|
|
175
|
+
if (pause) await delay(pause);
|
|
166
176
|
let source;
|
|
167
177
|
try {
|
|
168
178
|
source = await useSource();
|
|
169
|
-
const apps = await lookUp(source, name, input, Math.min(deadline, performance.now() +
|
|
179
|
+
const apps = await lookUp(source, name, input, Math.min(deadline, performance.now() + 8000));
|
|
170
180
|
if (apps === null || performance.now() >= deadline) continue;
|
|
171
|
-
|
|
181
|
+
answered(name, apps);
|
|
172
182
|
await writeCache(directory, filename, { at: now.getTime(), apps, version: 2 }).catch(() => {});
|
|
173
183
|
return;
|
|
174
184
|
} catch { /* An unavailable search gives no evidence about the name. */ }
|
|
@@ -176,12 +186,15 @@ export async function searchAndroidApps(names, options = {}) {
|
|
|
176
186
|
}
|
|
177
187
|
});
|
|
178
188
|
if (pending.length && performance.now() < deadline) {
|
|
179
|
-
|
|
180
|
-
let browserFailed =
|
|
181
|
-
|
|
182
|
-
browserReady =
|
|
183
|
-
await
|
|
184
|
-
|
|
189
|
+
// The public search response includes the cards. A normal lookup needs no browser or page assets.
|
|
190
|
+
let browserFailed = !options.launch;
|
|
191
|
+
if (options.launch) {
|
|
192
|
+
let browserReady = false;
|
|
193
|
+
await withShopPages(deadline, async (_, openPage) => {
|
|
194
|
+
browserReady = true;
|
|
195
|
+
await search(async () => browserSource(await openPage()));
|
|
196
|
+
}, { ...options, onFailure: () => { browserFailed = !browserReady; return null; } });
|
|
197
|
+
}
|
|
185
198
|
if (browserFailed && performance.now() < deadline) {
|
|
186
199
|
const parse = await import('parse5').then(module => module.parse, () => null);
|
|
187
200
|
if (parse) await search(() => fetchSource(parse, options));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
+
import { getDefaultAutoSelectFamilyAttemptTimeout, setDefaultAutoSelectFamilyAttemptTimeout } from 'node:net';
|
|
2
3
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
4
|
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import { promisify } from 'node:util';
|
|
@@ -439,10 +440,16 @@ function compactAgentResult(groups, names, complete, checkedAt, batch, rateLimit
|
|
|
439
440
|
return result;
|
|
440
441
|
}
|
|
441
442
|
|
|
442
|
-
// The
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
443
|
+
// The light confirm uses registry signals first, then a keyed shop API (only with the person's own key). By default only
|
|
444
|
+
// the pick is sent to a shop, so no shop sees the other names. DOMAIN_HOUND_SHOP_QUOTES=top4 adds up to three runners-up.
|
|
445
|
+
export const shopQuoteCount = (env = process.env) => env?.DOMAIN_HOUND_SHOP_QUOTES === 'top4' ? 4 : 1;
|
|
446
|
+
|
|
447
|
+
export function lightTargets(rows, eligible, count = 1, preferred = [], cap) {
|
|
448
|
+
const inScope = rows.filter(row => (!preferred.length || preferred.includes(row.tld))
|
|
449
|
+
&& (cap == null || (row.firstPayment ?? Infinity) <= cap));
|
|
450
|
+
const top = preferred.length ? preferred.map(tld => pickName(inScope.filter(row => row.tld === tld), eligible)).find(Boolean)
|
|
451
|
+
: pickName(inScope, eligible);
|
|
452
|
+
const others = rankName(inScope.filter(row => row !== top && ['probably-free', 'premium'].includes(row.status)
|
|
446
453
|
&& canRecommend(row.tld, eligible)));
|
|
447
454
|
return [top, ...others].filter(Boolean).slice(0, count);
|
|
448
455
|
}
|
|
@@ -477,11 +484,14 @@ export async function agentResult(input, options = {}) {
|
|
|
477
484
|
const rows = fast.groups.flatMap(group => group.results);
|
|
478
485
|
const targets = domain ? rows.filter(row => canRecommend(row.tld, options.eligible)
|
|
479
486
|
&& ['probably-free', 'check-at-shop', 'premium'].includes(row.status))
|
|
480
|
-
: lightTargets(rows, options.eligible);
|
|
487
|
+
: lightTargets(rows, options.eligible, shopQuoteCount(options.env ?? process.env), options.preferredEndings, options.upfrontCap);
|
|
481
488
|
const [candidate] = targets;
|
|
482
489
|
// A Google retry can settle every row that the first pass left waiting.
|
|
483
490
|
let complete = fast.complete || !rows.some(row => row.registryReason === 'Registry lookup timed out');
|
|
484
491
|
const quotes = new Map();
|
|
492
|
+
// The domains a shop was asked about in this lookup, for the receipt's disclosure.
|
|
493
|
+
const asked = new Set();
|
|
494
|
+
const onShopQuery = (_shop, domain) => asked.add(domain);
|
|
485
495
|
if (targets.length) {
|
|
486
496
|
options.onProgress?.({ stage: 'quotes' });
|
|
487
497
|
const catalog = await loadCachedCatalog(options.directory);
|
|
@@ -489,7 +499,7 @@ export async function agentResult(input, options = {}) {
|
|
|
489
499
|
options.bundledCatalog === undefined ? bundledCatalog : options.bundledCatalog).find(row => row.id === shop) ?? null;
|
|
490
500
|
const light = options.lightConfirm ?? lightConfirm;
|
|
491
501
|
const found = await light(targets.map(row => row.domain), { env: options.env, fetcher: options.fetcher,
|
|
492
|
-
directory: options.directory, now: options.now, deadline: performance.now() + Math.max(0, remaining() - 150), listFor })
|
|
502
|
+
directory: options.directory, now: options.now, deadline: performance.now() + Math.max(0, remaining() - 150), listFor, onShopQuery })
|
|
493
503
|
.catch(() => new Map());
|
|
494
504
|
for (const [key, value] of found) quotes.set(key, value);
|
|
495
505
|
}
|
|
@@ -505,7 +515,7 @@ export async function agentResult(input, options = {}) {
|
|
|
505
515
|
try {
|
|
506
516
|
quote = await Promise.race([
|
|
507
517
|
confirm(candidate.confirmShop, candidate.domain, { deadline, directory: options.directory,
|
|
508
|
-
unsupported: ['so', 'no'], fresh: true, oneShop: batch }).catch(() => null),
|
|
518
|
+
unsupported: ['so', 'no'], fresh: true, oneShop: batch, onShopQuery }).catch(() => null),
|
|
509
519
|
new Promise(resolve => { timer = setTimeout(resolve, remaining()); }),
|
|
510
520
|
]);
|
|
511
521
|
if (!remaining() || quote === undefined) complete = false;
|
|
@@ -527,9 +537,11 @@ export async function agentResult(input, options = {}) {
|
|
|
527
537
|
const otherEndings = exactCom ? await endingBenchmarks(exactCom, options) : null;
|
|
528
538
|
const result = compactAgentResult(rankedGroups, names, complete, checkedAt, batch, rateLimited,
|
|
529
539
|
options.browser ? liveCheckFor(candidate, quote) : null, { eligible: options.eligible, otherEndings });
|
|
540
|
+
if (asked.size) result.shopAsked = [...asked];
|
|
530
541
|
if (options.receipt) result.receiptDetails = rankedGroups.map(({ results, sites }) => ({ endings: results.map(row => ({
|
|
531
542
|
domain: row.domain, source: row.source, checkedAt: row.checkedAt, priceAt: row.priceCheckedAt,
|
|
532
543
|
shop: row.shop, checkout: row.buyUrl, site: sites?.[row.tld], risk: row.premium === 'risk' || row.premiumRisk,
|
|
544
|
+
...(row.savings && { savings: row.savings }),
|
|
533
545
|
})) }));
|
|
534
546
|
return result;
|
|
535
547
|
}
|
|
@@ -656,6 +668,8 @@ function lookupArgs(args) {
|
|
|
656
668
|
const arg = args[index];
|
|
657
669
|
if (arg === '--ai') options.ai = true;
|
|
658
670
|
else if (arg === '--endings' && !options.endings) options.endings = (args[++index] ?? '').split(',');
|
|
671
|
+
else if (arg === '--prefer-endings' && !options.preferredEndings) options.preferredEndings = (args[++index] ?? '').split(',');
|
|
672
|
+
else if (arg === '--upfront-cap' && options.upfrontCap === undefined) options.upfrontCap = Number(args[++index]);
|
|
659
673
|
else if (arg === '--eligible' && !options.eligible) options.eligible = (args[++index] ?? '').split(',');
|
|
660
674
|
else if (arg === '--category' && !options.category) options.category = (args[++index] ?? '').slice(0, 100);
|
|
661
675
|
else if (arg === '--compact') options.compact = true;
|
|
@@ -669,12 +683,44 @@ function lookupArgs(args) {
|
|
|
669
683
|
return { options, positional };
|
|
670
684
|
}
|
|
671
685
|
|
|
686
|
+
function triageOutput(result, options) {
|
|
687
|
+
if (options.compact) {
|
|
688
|
+
for (const row of result.names ?? []) {
|
|
689
|
+
row.checks = nameCheckLines(row).map(({ label, text, link }) => label + ': ' + text + ' · ' + link);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return result;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function printResult(result) {
|
|
696
|
+
const packet = process.env.DOMAIN_HOUND_MCP_OUTPUT === '1' && !result.error ? { ...result, _mcpResult: true } : result;
|
|
697
|
+
console.log(JSON.stringify(packet));
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// The name screen's first answer comes by answerMs with the checks done so far. With followUp, the slow checks keep
|
|
701
|
+
// running in the same process (no lookup is repeated) and a second, re-assessed result follows on the next line.
|
|
702
|
+
export const firstAnswerMs = 8000;
|
|
703
|
+
export const followUpMs = 24000;
|
|
704
|
+
export const lateSiteMs = 8000;
|
|
705
|
+
export async function triageWithFollowUp(names, options, { followUp = false, answerMs = firstAnswerMs, print = () => {} } = {}) {
|
|
706
|
+
if (!followUp) return triageNames(names, options);
|
|
707
|
+
const memo = new Map();
|
|
708
|
+
const run = { ...options, memo, budgetMs: options.budgetMs ?? followUpMs, lateSiteMs };
|
|
709
|
+
const first = await triageNames(names, { ...run, answerAt: performance.now() + answerMs });
|
|
710
|
+
if (first.error || !first.followUp) return first;
|
|
711
|
+
print(first);
|
|
712
|
+
return triageNames(names, run);
|
|
713
|
+
}
|
|
714
|
+
|
|
672
715
|
function runConfirmation(shop, domain) {
|
|
673
716
|
return confirmDomain(shop, domain, { unsupported: ['so', 'no'], fresh: true });
|
|
674
717
|
}
|
|
675
718
|
|
|
676
719
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
677
720
|
const args = process.argv.slice(2);
|
|
721
|
+
// The 250 ms default was cutting off the IPv4 leg before several public sources could connect.
|
|
722
|
+
// The individual request deadlines and the first-answer deadline still apply.
|
|
723
|
+
if (args[0] === '--triage') setDefaultAutoSelectFamilyAttemptTimeout(Math.max(900, getDefaultAutoSelectFamilyAttemptTimeout()));
|
|
678
724
|
const { options, positional } = lookupArgs(args.slice(1));
|
|
679
725
|
// The MCP server reads these to answer with progress when a lookup outlasts its budget.
|
|
680
726
|
const onProgress = progressReporter();
|
|
@@ -696,15 +742,12 @@ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href)
|
|
|
696
742
|
: args[0] === '--refresh-tranco' && args.length === 1
|
|
697
743
|
? await refreshTranco({ directory: process.env.DOMAIN_HOUND_TRANCO_CACHE ? pathToFileURL(process.env.DOMAIN_HOUND_TRANCO_CACHE.replace(/\/?$/, '/')) : undefined })
|
|
698
744
|
: args[0] === '--presence' && args.length === 2 ? await namePresence(args[1], { refreshTranco: true })
|
|
699
|
-
: args[0] === '--triage' ? await
|
|
700
|
-
{ ...options, refreshTranco: true, deferHandles: process.env.DOMAIN_HOUND_DEFER_HANDLES === '1' }
|
|
745
|
+
: args[0] === '--triage' ? await triageWithFollowUp(positional.length === 1 ? positional[0].split(',') : null,
|
|
746
|
+
{ ...options, refreshTranco: true, deferHandles: process.env.DOMAIN_HOUND_DEFER_HANDLES === '1' },
|
|
747
|
+
{ followUp: process.env.DOMAIN_HOUND_FOLLOW_UP === '1', answerMs: Number(process.env.DOMAIN_HOUND_ANSWER_MS) || undefined,
|
|
748
|
+
print: first => printResult(triageOutput(first, options)) })
|
|
701
749
|
: await checkDomain(args.length === 1 ? args[0] : undefined);
|
|
702
750
|
if (result.error) process.exitCode = 1;
|
|
703
|
-
|
|
704
|
-
for (const row of result.names ?? []) {
|
|
705
|
-
row.checks = nameCheckLines(row).map(({ label, text, link }) => label + ': ' + text + ' · ' + link);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
console.log(JSON.stringify(result));
|
|
751
|
+
printResult(args[0] === '--triage' ? triageOutput(result, options) : result);
|
|
709
752
|
}
|
|
710
753
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Domain marketplaces for the taken-domain dossier. Fail closed: no marketplace is read automatically until its
|
|
2
|
+
// terms are confirmed to permit it and an authorized public endpoint is independently verified. Until then each
|
|
3
|
+
// one is a manual link and its listing state is "unchecked". An adapter that is enabled must bind its answer to the
|
|
4
|
+
// exact domain; a search page, parking page or failed request never counts as a listing.
|
|
5
|
+
import { shopSearchUrl } from './prices.mjs';
|
|
6
|
+
import { hostMatches, safeUrl, evidenceUrl } from './safe-web.mjs';
|
|
7
|
+
import { atomSearchDocs, exactAtomListingUrl, lookupAtomListing } from './broker-atom.mjs';
|
|
8
|
+
|
|
9
|
+
const godaddyTerms = 'https://www.godaddy.com/en/legal/agreements/universal-terms-of-service-agreement';
|
|
10
|
+
const policy = (note, url) => ({ automated: false, note, url });
|
|
11
|
+
const atomManualUrl = domain => 'https://www.atom.com/name/' + encodeURIComponent(domain.replace(/\.com$/, ''));
|
|
12
|
+
|
|
13
|
+
export const providers = Object.freeze([
|
|
14
|
+
{ id: 'afternic', name: 'Afternic / GoDaddy', hosts: ['afternic.com', 'godaddy.com'],
|
|
15
|
+
policy: policy('Public listings require a manual check. The designated portfolio API is for sellers.', godaddyTerms),
|
|
16
|
+
manualUrl: domain => 'https://www.afternic.com/domain/' + encodeURIComponent(domain) },
|
|
17
|
+
{ id: 'sedo', name: 'Sedo', hosts: ['sedo.com'],
|
|
18
|
+
policy: policy('Sedo prohibits scraping its marketplace.', 'https://sedo.com/us/about-us/policies/general-terms-and-conditions/'),
|
|
19
|
+
manualUrl: domain => 'https://sedo.com/search/details/?domain=' + encodeURIComponent(domain) },
|
|
20
|
+
// Dan.com forwarded to Afternic when checked on 2026-11-25.
|
|
21
|
+
{ id: 'dan', name: 'Dan.com', hosts: ['dan.com', 'undeveloped.com'],
|
|
22
|
+
policy: policy('Dan landers are part of GoDaddy’s aftermarket. Check through Afternic.', 'https://blog.afternic.com/dan-landers-afternic/'),
|
|
23
|
+
manualUrl: domain => 'https://dan.com/buy-domain/' + encodeURIComponent(domain) },
|
|
24
|
+
{ id: 'atom', name: 'Atom / Squadhelp', hosts: ['atom.com', 'squadhelp.com'],
|
|
25
|
+
policy: { automated: true, url: atomSearchDocs }, manualUrl: atomManualUrl,
|
|
26
|
+
async check(domain, { signal }) {
|
|
27
|
+
const result = await lookupAtomListing(domain, { signal });
|
|
28
|
+
if (result.status === 'unavailable') throw new Error('Public search unavailable');
|
|
29
|
+
return {
|
|
30
|
+
domain, url: result.listingUrl ?? atomManualUrl(domain), listed: result.status === 'listed',
|
|
31
|
+
price: result.price?.amount, currency: result.price?.currency, sourceUrl: result.url, checkedAt: result.checkedAt,
|
|
32
|
+
};
|
|
33
|
+
} },
|
|
34
|
+
{ id: 'spaceship', name: 'Spaceship marketplace', hosts: ['spaceship.com'],
|
|
35
|
+
policy: policy('The documented marketplace search requires signing in.', 'https://www.spaceship.com/knowledgebase/spaceship-connector-mcp/'),
|
|
36
|
+
manualUrl: domain => shopSearchUrl('spaceship', domain) },
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
// Hosts where a redirect chain stops without a request: marketplaces (terms not confirmed) and ad-parking services.
|
|
40
|
+
const otherSaleHosts = ['hugedomains.com', 'buydomains.com', 'brandbucket.com', 'sedoparking.com', 'uniregistry.com'];
|
|
41
|
+
const parkingHosts = ['parkingcrew.net', 'bodis.com', 'above.com', 'parklogic.com', 'parked.com', 'parking-page.net',
|
|
42
|
+
'cashparking.com', 'smartname.com', 'domaincontrol.com'];
|
|
43
|
+
|
|
44
|
+
export function marketplaceFor(host) {
|
|
45
|
+
return providers.find(provider => hostMatches(host, provider.hosts)) ?? null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Why a redirect target is not fetched, or null when it may be.
|
|
49
|
+
export function stopReason(url) {
|
|
50
|
+
const host = url?.hostname;
|
|
51
|
+
if (marketplaceFor(host) || hostMatches(host, otherSaleHosts)) return 'marketplace';
|
|
52
|
+
if (hostMatches(host, parkingHosts)) return 'parking';
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// True when a URL names the exact domain in its path or query (not a longer or shorter name).
|
|
57
|
+
export function urlBindsDomain(value, domain) {
|
|
58
|
+
const url = safeUrl(value);
|
|
59
|
+
if (!url) return false;
|
|
60
|
+
if (exactAtomListingUrl(url.href, domain)) return true;
|
|
61
|
+
let text;
|
|
62
|
+
try { text = decodeURIComponent(url.pathname + ' ' + url.search).toLowerCase(); } catch { return false; }
|
|
63
|
+
return new RegExp('(?:^|[^a-z0-9.-])' + domain.replace(/[.]/g, '\\.') + '(?![a-z0-9-]|\\.[a-z0-9])').test(text);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const currencies = new Set(['USD', 'EUR', 'GBP']);
|
|
67
|
+
const validPrice = value => typeof value === 'number' && Number.isFinite(value) && value >= 1 && value <= 100_000_000;
|
|
68
|
+
|
|
69
|
+
// One adapter answer checked against the exact domain and the provider's own hosts.
|
|
70
|
+
export function acceptAnswer(provider, domain, answer, checkedAt) {
|
|
71
|
+
const url = evidenceUrl(answer?.url);
|
|
72
|
+
const bound = typeof answer?.domain === 'string' && answer.domain.toLowerCase() === domain;
|
|
73
|
+
if (!bound || !url || !hostMatches(new URL(url).hostname, provider.hosts) || typeof answer.listed !== 'boolean') {
|
|
74
|
+
return { state: 'unavailable', reason: 'answer not bound to this exact domain', checkedAt };
|
|
75
|
+
}
|
|
76
|
+
const matchingPage = provider.id === 'atom' ? exactAtomListingUrl(answer.url, domain)
|
|
77
|
+
: urlBindsDomain(answer.url, domain) && !/^\/(?:search|listings)\/?$/i.test(new URL(url).pathname);
|
|
78
|
+
if (answer.listed && !matchingPage) {
|
|
79
|
+
return { state: 'unavailable', reason: 'listing page does not name this exact domain', checkedAt };
|
|
80
|
+
}
|
|
81
|
+
if (!answer.listed) {
|
|
82
|
+
// Only an endpoint that authoritatively covers every listing can confirm absence.
|
|
83
|
+
return provider.policy.authoritative ? { state: 'not-listed', url, checkedAt } : { state: 'unknown', url, checkedAt };
|
|
84
|
+
}
|
|
85
|
+
const price = validPrice(answer.price) && currencies.has(answer.currency) ? { amount: answer.price, currency: answer.currency } : null;
|
|
86
|
+
return { state: 'listed', url, checkedAt, ...(price && { price }) };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Listing state per marketplace. Unpermitted ones are not contacted and come back "unchecked" with a manual link.
|
|
90
|
+
export async function checkListings(domain, { list = providers, signal, clock = () => new Date() } = {}) {
|
|
91
|
+
return Promise.all(list.map(async provider => {
|
|
92
|
+
const row = { id: provider.id, name: provider.name, manualUrl: provider.manualUrl(domain) ?? null,
|
|
93
|
+
...(provider.policy?.url && { policyUrl: provider.policy.url }) };
|
|
94
|
+
if (provider.policy?.automated !== true || typeof provider.check !== 'function') {
|
|
95
|
+
return { ...row, state: 'unchecked', reason: provider.policy?.note ?? 'No permitted public lookup.',
|
|
96
|
+
checkedAt: clock().toISOString() };
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const answer = await provider.check(domain, { signal });
|
|
100
|
+
return { ...row, ...acceptAnswer(provider, domain, answer, answer?.checkedAt ?? clock().toISOString()),
|
|
101
|
+
...(answer?.sourceUrl && { sourceUrl: answer.sourceUrl }),
|
|
102
|
+
...(provider.id === 'atom' && answer?.listed === false && { reason: 'No exact match in the public search. Coverage is incomplete.' }) };
|
|
103
|
+
} catch {
|
|
104
|
+
return { ...row, state: 'unavailable', reason: signal?.aborted ? 'timed out' : 'no answer', checkedAt: clock().toISOString() };
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
}
|