domain-hound 0.1.2 → 0.1.4
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/.claude-plugin/plugin.json +1 -1
- package/README.md +6 -1
- package/clis/domain-check/company-search.mjs +1 -0
- package/clis/domain-check/confirm.mjs +4 -2
- package/clis/domain-check/index.mjs +91 -23
- package/clis/domain-check/name-search.mjs +96 -17
- package/clis/domain-check/naming-method.mjs +3 -3
- package/clis/domain-check/registry.mjs +149 -36
- package/clis/domain-check/traction.mjs +9 -6
- package/clis/domain-check/triage-sources.mjs +8 -1
- package/clis/domain-check/triage.mjs +69 -31
- package/display.mjs +191 -62
- package/package.json +5 -2
- package/plugin.json +2 -2
- package/results-style.mjs +62 -0
- package/results.mjs +383 -0
- package/server.json +2 -11
- package/server.mjs +66 -40
- package/watch.mjs +93 -0
package/server.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { geoInstruction,
|
|
2
|
-
import { defaultEndings, normalizeName, restrictedEndings, validEligibility } from './clis/domain-check/name-search.mjs';
|
|
1
|
+
import { geoInstruction, namingRecipe } from './clis/domain-check/naming-method.mjs';
|
|
2
|
+
import { asciiDomain, defaultEndings, normalizeName, restrictedEndings, validEligibility } from './clis/domain-check/name-search.mjs';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { createInterface } from 'node:readline';
|
|
6
6
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
7
|
import { progressPrefix } from './clis/domain-check/progress.mjs';
|
|
8
|
-
import { attributed,
|
|
8
|
+
import { attributed, errorText, progressText } from './display.mjs';
|
|
9
|
+
import { resultPages } from './results.mjs';
|
|
10
|
+
import { watchDomain, watchTool } from './watch.mjs';
|
|
9
11
|
|
|
10
12
|
// The capability ships inside the package; tests inject another directory through serve({ cwd }).
|
|
11
13
|
export const capabilityDir = fileURLToPath(new URL('./clis/domain-check/', import.meta.url));
|
|
@@ -16,40 +18,48 @@ const serverVersion = JSON.parse(readFileSync(new URL('./package.json', import.m
|
|
|
16
18
|
const timeoutMs = 14_000;
|
|
17
19
|
// A lookup still running after this long is stopped.
|
|
18
20
|
const maxLookupMs = 120_000;
|
|
19
|
-
//
|
|
21
|
+
// Keep completed evidence stable for repeated calls during a short naming session.
|
|
20
22
|
const keepFinishedMs = 120_000;
|
|
21
23
|
const versions = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
// Letters may be non-ASCII (æøå, é): such a name or domain is checked as its punycode form. The ranges skip
|
|
26
|
+
// spaces, punctuation and symbols without needing a Unicode-aware regular expression in the client.
|
|
27
|
+
const letter = 'A-Za-z0-9\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u1FFF\\u3040-\\uD7FF\\uF900-\\uFDCF';
|
|
28
|
+
const entryPattern = new RegExp('^[' + letter + '](?:[' + letter + '-]{0,61}[' + letter + '])?'
|
|
29
|
+
+ '(?:\\.(?:[A-Za-z]{2,63}|[xX][nN]--[A-Za-z0-9](?:[A-Za-z0-9-]{0,57}[A-Za-z0-9])?))?$');
|
|
24
30
|
const nameSchema = { type: 'string', minLength: 1, maxLength: 127, pattern: entryPattern.source };
|
|
25
31
|
const endingsSchema = {
|
|
26
32
|
type: 'array', minItems: 1, maxItems: 10, uniqueItems: true,
|
|
27
33
|
items: { type: 'string', enum: defaultEndings },
|
|
28
|
-
description: '
|
|
34
|
+
description: 'Endings to consider for the recommendation, in preference order. For .com only use ["com"]. The page still shows all ten endings for bare names.',
|
|
29
35
|
};
|
|
30
36
|
const lookupProperties = {
|
|
31
37
|
ai: { type: 'boolean', description: 'Legacy option. .ai is now included by default.' },
|
|
32
38
|
endings: endingsSchema,
|
|
39
|
+
budget: { type: 'number', minimum: 0, maximum: 1000000,
|
|
40
|
+
description: 'Maximum upfront price in USD when the person gave a cap. Carry it from the registry screen into triage.' },
|
|
33
41
|
eligible: { type: 'array', uniqueItems: true, items: { type: 'string', enum: restrictedEndings },
|
|
34
42
|
description: 'Restricted endings the buyer qualifies to register. Pass ["no"] only when the buyer qualifies for .no.' },
|
|
35
43
|
};
|
|
44
|
+
const relay = 'Relay `say` as written. You may add advice, but no domain, price or verdict that is not in it. Keep advice consistent with the tool verdict. The complete local results page has all checked endings.';
|
|
36
45
|
const checkTool = {
|
|
37
46
|
name: 'check_domains',
|
|
38
|
-
description:
|
|
47
|
+
description: relay + ' '
|
|
39
48
|
+ 'For any request to buy or register, pass purchase: true and explicitly say “Domain Hound cannot buy or complete checkout,” even when the domain is taken. '
|
|
40
|
-
+ 'Input: query for one name or exact domain ({"query":"
|
|
49
|
+
+ 'Input: query for one name or exact domain ({"query":"lanternbay.me"}), or names for 1 to 20 names in one call ({"names":["lanternbay","lanternbay.me"]}). A bare name checks ten endings, including .ai. '
|
|
50
|
+
+ 'For a bare name, put any ending preference in endings. Use exact lookup for a full domain. '
|
|
41
51
|
+ 'For a batch, make one call and report check-at-shop endings as returned. Recheck only when the person asks. '
|
|
42
52
|
+ 'Set confirm true only when the person asks for a live shop check (slower). '
|
|
43
|
-
+ 'Prices are list prices unless marked confirmed at a shop; premium names show the shop price or "premium, price at shop".
|
|
53
|
+
+ 'Prices are list prices unless marked confirmed at a shop; premium names show the shop price or "premium, price at shop". For new names, call naming_method first; to screen an existing name, use triage_names. With shortlist true, pass one DNS label per name (Quiet Otter becomes quietotter).',
|
|
44
54
|
inputSchema: {
|
|
45
55
|
type: 'object',
|
|
46
56
|
properties: {
|
|
47
57
|
...lookupProperties,
|
|
48
58
|
query: { ...nameSchema,
|
|
49
|
-
description: 'One name or exact domain, e.g. "
|
|
59
|
+
description: 'One name or exact domain, e.g. "lanternbay.me" or "lanternbay". Supply either query or names.' },
|
|
50
60
|
names: { type: 'array', minItems: 1, maxItems: 20,
|
|
51
61
|
items: nameSchema,
|
|
52
|
-
description: '1 to 20 bare names, exact domains or both, e.g. ["
|
|
62
|
+
description: '1 to 20 bare names, exact domains or both, e.g. ["lanternbay","quietbook","lanternbay.me"]. Use one DNS label for a bare name, with no spaces or dots. A dot means an exact domain. Supply either names or query.' },
|
|
53
63
|
shortlist: { type: 'boolean', description: 'Use true for the preliminary bare-name batch specified by naming_method.' },
|
|
54
64
|
purchase: { type: 'boolean', description: 'Pass true when asked to buy or register, even for an exact domain that may be taken. State the checkout limitation from the display in the answer.' },
|
|
55
65
|
confirm: { type: 'boolean', description: 'True only when the person explicitly asks for a live shop check. Uses an optional headless browser and is slower.' },
|
|
@@ -60,14 +70,15 @@ const checkTool = {
|
|
|
60
70
|
};
|
|
61
71
|
|
|
62
72
|
const legacyTool = { ...checkTool, name: 'broker_find',
|
|
63
|
-
description:
|
|
73
|
+
description: relay + ' Legacy alias for Domain Hound check_domains, same input. Never buys.' };
|
|
64
74
|
|
|
65
75
|
const triageTool = {
|
|
66
76
|
name: 'triage_names',
|
|
67
|
-
description:
|
|
77
|
+
description: relay + ' '
|
|
68
78
|
+ 'Use to screen 1 to 20 product names, or once with a bare name when asked whether an existing name is safe: {"names":["Quiet Otter","Hush Room"],"about":"book quiet meeting rooms"}. Checks same-name rivals and their traction, live US marks, iOS and Android apps, handles and every domain ending, including .ai. '
|
|
69
79
|
+ 'Verdicts weigh each same-name rival by its traction: a strong rival (David vs Goliath) or a same-business rival with traction means Avoid; small or dormant same-name uses are notes that never lower the verdict. '
|
|
70
|
-
+ '
|
|
80
|
+
+ 'Put the name the person came with first. Fill geo for each name from memory, never from search. '
|
|
81
|
+
+ 'The tool checks Google itself. If you check a gap using built-in search, use it for context and keep the evidence-backed results unchanged. Let the person choose.',
|
|
71
82
|
inputSchema: {
|
|
72
83
|
type: 'object',
|
|
73
84
|
properties: {
|
|
@@ -88,7 +99,7 @@ const triageTool = {
|
|
|
88
99
|
|
|
89
100
|
const namingTool = {
|
|
90
101
|
name: 'naming_method',
|
|
91
|
-
description: 'Get the Domain Hound naming recipe for new names. For an existing name, use triage_names. The recipe and preliminary check are intermediate. For the final triage result,
|
|
102
|
+
description: 'Get the Domain Hound naming recipe for new names. For an existing name, use triage_names. The recipe and preliminary check are intermediate. For the final triage result, relay say as written.',
|
|
92
103
|
inputSchema: { type: 'object', properties: {
|
|
93
104
|
about: { type: 'string', minLength: 1, maxLength: 512, description: 'An optional one-sentence product description.' },
|
|
94
105
|
}, additionalProperties: false },
|
|
@@ -104,13 +115,17 @@ const errorResult = message => toolResult(errorText(message), true);
|
|
|
104
115
|
|
|
105
116
|
const showValue = value => JSON.stringify(String(value).slice(0, 40));
|
|
106
117
|
|
|
118
|
+
// The DNS form of a valid entry: a bare name as one label, an exact domain as itself, both in punycode when needed.
|
|
119
|
+
const dnsForm = value => value.includes('.') ? asciiDomain(value) : normalizeName(value);
|
|
120
|
+
|
|
107
121
|
function queryValue(value) {
|
|
108
122
|
if (typeof value !== 'string' || !value.trim()) {
|
|
109
|
-
throw new Error('query is empty. Enter one name or exact domain in query, such as
|
|
123
|
+
throw new Error('query is empty. Enter one name or exact domain in query, such as lanternbay or lanternbay.me.');
|
|
110
124
|
}
|
|
111
125
|
const query = value.toLowerCase();
|
|
112
|
-
if (
|
|
113
|
-
|
|
126
|
+
if (query.split('.')[0].length > 63) throw new Error('This name is too long. A DNS label can have up to 63 characters.');
|
|
127
|
+
if (!entryPattern.test(query) || !dnsForm(query)) {
|
|
128
|
+
throw new Error('query ' + showValue(value) + ' is not valid. Give a name like lanternbay or a domain like lanternbay.me in query.');
|
|
114
129
|
}
|
|
115
130
|
return query;
|
|
116
131
|
}
|
|
@@ -122,11 +137,12 @@ function batchNames(names) {
|
|
|
122
137
|
}
|
|
123
138
|
return names.map((value, index) => {
|
|
124
139
|
if (typeof value !== 'string' || !value.trim()) {
|
|
125
|
-
throw new Error('names[' + index + '] is empty. Use a bare name such as
|
|
140
|
+
throw new Error('names[' + index + '] is empty. Use a bare name such as lanternbay or an exact domain such as lanternbay.me.');
|
|
126
141
|
}
|
|
127
142
|
const name = value.toLowerCase();
|
|
128
|
-
if (
|
|
129
|
-
|
|
143
|
+
if (name.split('.')[0].length > 63) throw new Error('names[' + index + '] is too long. A DNS label can have up to 63 characters.');
|
|
144
|
+
if (!entryPattern.test(name) || !dnsForm(name)) {
|
|
145
|
+
throw new Error('names[' + index + '] ' + showValue(value) + ' is not valid. Give a name like lanternbay or a domain like lanternbay.me in names.');
|
|
130
146
|
}
|
|
131
147
|
return name;
|
|
132
148
|
});
|
|
@@ -134,6 +150,9 @@ function batchNames(names) {
|
|
|
134
150
|
|
|
135
151
|
function lookupFlags(args) {
|
|
136
152
|
const flags = [];
|
|
153
|
+
if (Object.hasOwn(args, 'budget') && (!Number.isFinite(args.budget) || args.budget < 0 || args.budget > 1_000_000)) {
|
|
154
|
+
throw new Error('The upfront budget must be a dollar amount between 0 and 1,000,000.');
|
|
155
|
+
}
|
|
137
156
|
if (Object.hasOwn(args, 'eligible')) {
|
|
138
157
|
if (!validEligibility(args.eligible)) throw new Error('Eligible endings must list supported restricted endings, such as no.');
|
|
139
158
|
if (args.eligible.length) flags.push('--eligible', args.eligible.join(','));
|
|
@@ -169,13 +188,13 @@ function cliArguments(args) {
|
|
|
169
188
|
if (args.shortlist && (hasQuery || names.some(name => name.includes('.')))) {
|
|
170
189
|
throw new Error('Use shortlist only with bare names in names.');
|
|
171
190
|
}
|
|
172
|
-
if (hasQuery) return ['--agent', queryValue(args.query), ...flags];
|
|
173
|
-
return ['--agent', '--names', names.join(','), ...flags];
|
|
191
|
+
if (hasQuery) return ['--agent', queryValue(args.query), '--receipt', ...flags];
|
|
192
|
+
return ['--agent', '--names', names.join(','), '--receipt', ...flags];
|
|
174
193
|
}
|
|
175
194
|
|
|
176
195
|
// The rows a progress answer lists, in input order: a bare name with every requested ending, an exact domain as itself.
|
|
177
196
|
function checkRows(args) {
|
|
178
|
-
const names = Object.hasOwn(args, 'query') ? [queryValue(args.query)] : batchNames(args.names);
|
|
197
|
+
const names = (Object.hasOwn(args, 'query') ? [queryValue(args.query)] : batchNames(args.names)).map(dnsForm);
|
|
179
198
|
const endings = [...new Set([...(args.endings ?? []), ...defaultEndings])];
|
|
180
199
|
return [...new Set(names)].map(name => name.includes('.')
|
|
181
200
|
? { name, domains: [name] } : { name, domains: endings.map(ending => name + '.' + ending) });
|
|
@@ -229,7 +248,7 @@ function triageArguments(args) {
|
|
|
229
248
|
flags.push('--about', args.about);
|
|
230
249
|
}
|
|
231
250
|
if (Object.hasOwn(args, 'geo')) flags.push('--geo', JSON.stringify(geoValue(args.geo, args.names)));
|
|
232
|
-
return ['--triage', args.names.join(','), '--compact', ...flags];
|
|
251
|
+
return ['--triage', args.names.join(','), '--compact', '--receipt', ...flags];
|
|
233
252
|
}
|
|
234
253
|
|
|
235
254
|
// The capability prints one JSON object on stdout.
|
|
@@ -318,6 +337,7 @@ async function within(lookup, budget) {
|
|
|
318
337
|
|
|
319
338
|
export async function serve({
|
|
320
339
|
input = process.stdin, output = process.stdout, cwd = capabilityDir, timeout = timeoutMs, maxLookup = maxLookupMs,
|
|
340
|
+
pages = resultPages(), watch = watchDomain,
|
|
321
341
|
} = {}) {
|
|
322
342
|
const send = response => output.write(JSON.stringify({ jsonrpc: '2.0', ...response }) + '\n');
|
|
323
343
|
const error = (id, code, message) => send({ id, error: { code, message } });
|
|
@@ -343,8 +363,7 @@ export async function serve({
|
|
|
343
363
|
lookups.set(key, lookup);
|
|
344
364
|
lookup.done.then(() => {
|
|
345
365
|
if (lookups.get(key) !== lookup) return;
|
|
346
|
-
|
|
347
|
-
if (!lookup.collect) {
|
|
366
|
+
if (lookup.outcome.error && !lookup.collect) {
|
|
348
367
|
lookups.delete(key);
|
|
349
368
|
return;
|
|
350
369
|
}
|
|
@@ -360,16 +379,16 @@ export async function serve({
|
|
|
360
379
|
return errorResult('Domain Hound could not format the progress.');
|
|
361
380
|
}
|
|
362
381
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
382
|
+
if (lookup.outcome.error) {
|
|
383
|
+
if (lookups.get(key) === lookup) lookups.delete(key);
|
|
384
|
+
return errorResult(lookup.outcome.error);
|
|
385
|
+
}
|
|
366
386
|
try {
|
|
367
|
-
return toolResult(render(lookup.outcome.data));
|
|
387
|
+
return toolResult(JSON.stringify(await render(lookup.outcome.data)));
|
|
368
388
|
} catch {
|
|
369
389
|
return errorResult('Domain Hound could not format the result.');
|
|
370
390
|
}
|
|
371
391
|
}
|
|
372
|
-
let shortlist;
|
|
373
392
|
let initialized = false;
|
|
374
393
|
let negotiated = false;
|
|
375
394
|
|
|
@@ -404,7 +423,7 @@ export async function serve({
|
|
|
404
423
|
}
|
|
405
424
|
if (method !== 'tools/list' && method !== 'tools/call') return error(id, -32601, 'Method not found');
|
|
406
425
|
if (!initialized) return error(id, -32000, 'Domain Hound has not been initialized');
|
|
407
|
-
if (method === 'tools/list') return reply({ tools: [checkTool, triageTool, namingTool, legacyTool] });
|
|
426
|
+
if (method === 'tools/list') return reply({ tools: [checkTool, triageTool, namingTool, legacyTool, watchTool] });
|
|
408
427
|
const { name, arguments: args } = params ?? {};
|
|
409
428
|
if (name === namingTool.name) {
|
|
410
429
|
if (args !== undefined && (!isObject(args) || Object.keys(args).some(key => key !== 'about') ||
|
|
@@ -412,22 +431,29 @@ export async function serve({
|
|
|
412
431
|
args.about.length > namingTool.inputSchema.properties.about.maxLength)))) {
|
|
413
432
|
return reply(errorResult('naming_method accepts an optional about description of up to 512 characters.'));
|
|
414
433
|
}
|
|
415
|
-
shortlist = undefined;
|
|
416
434
|
return reply(toolResult(JSON.stringify({ display: attributed(namingRecipe(args?.about?.slice(0, 160))) })));
|
|
417
435
|
}
|
|
436
|
+
if (name === watchTool.name) {
|
|
437
|
+
let result;
|
|
438
|
+
try {
|
|
439
|
+
result = await watch(args);
|
|
440
|
+
} catch (problem) {
|
|
441
|
+
return reply(errorResult(problem.message));
|
|
442
|
+
}
|
|
443
|
+
// Preserve a successful submission response even if disk space or local permissions prevent a receipt.
|
|
444
|
+
const data = await pages(result, {}, { watch: true }).catch(() => ({ ...result, display: result.say }));
|
|
445
|
+
return reply(toolResult(JSON.stringify(data)));
|
|
446
|
+
}
|
|
418
447
|
const purchase = isObject(args) && args.purchase === true;
|
|
419
448
|
if (name === triageTool.name) {
|
|
420
|
-
|
|
421
|
-
return reply(await runLookup(args, triageArguments, triageRows, data => triageText(data, prior, { purchase, preferred: args.endings }),
|
|
449
|
+
return reply(await runLookup(args, triageArguments, triageRows, data => pages(data, args, { triage: true }),
|
|
422
450
|
(progress, timing) => progressText(progress, { ...timing, triage: true, purchase })));
|
|
423
451
|
}
|
|
424
452
|
if (name !== checkTool.name && name !== legacyTool.name) return error(id, -32602, 'Unknown tool');
|
|
425
453
|
// An exact lookup includes the purchase line while its registration status is unsettled.
|
|
426
454
|
const exact = isObject(args) && typeof args.query === 'string' && args.query.includes('.');
|
|
427
|
-
return reply(await runLookup(args, cliArguments, checkRows, data =>
|
|
428
|
-
|
|
429
|
-
return checkText(data, args.shortlist, { purchase, preferred: args.endings });
|
|
430
|
-
}, (progress, timing) => progressText(progress, { ...timing, purchase: purchase || exact })));
|
|
455
|
+
return reply(await runLookup(args, cliArguments, checkRows, data => pages(data, args),
|
|
456
|
+
(progress, timing) => progressText(progress, { ...timing, purchase: purchase || exact })));
|
|
431
457
|
}
|
|
432
458
|
|
|
433
459
|
const lines = createInterface({ input, terminal: false, crlfDelay: Infinity });
|
package/watch.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { checkDomainSite } from './clis/domain-check/com-site.mjs';
|
|
2
|
+
import { asciiDomain, defaultEndings } from './clis/domain-check/name-search.mjs';
|
|
3
|
+
import { lookupRegistrations } from './clis/domain-check/registry.mjs';
|
|
4
|
+
|
|
5
|
+
export const newsQuestion = 'Domain Hound can also email you news about itself and other developer tools from its maker, BrightBoard AS, at most twice a month. It is optional and your watch works either way. Do you want that?';
|
|
6
|
+
const endpoint = 'https://domainhound-alerts.domainhound.workers.dev/watch';
|
|
7
|
+
const consentTextVersion = 'news-v1';
|
|
8
|
+
|
|
9
|
+
export const watchTool = {
|
|
10
|
+
name: 'watch_domain',
|
|
11
|
+
description: 'Check a specific domain’s registry, expiry and website and start a free release watch at the person’s request. '
|
|
12
|
+
+ 'Use the email and optional name they gave for this submission. If the email is missing, ask once and never guess. '
|
|
13
|
+
+ 'Before submitting, ask exactly: “' + newsQuestion + '” Pass news: true only on an explicit yes, or false if they decline or skip it. '
|
|
14
|
+
+ 'This highlights a choice in the confirmation email. Only the email confirmation can start news. Relay say as written.',
|
|
15
|
+
annotations: { title: 'Watch a domain', readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
domain: { type: 'string', maxLength: 127, description: 'The exact domain, like example.com.' },
|
|
20
|
+
email: { type: 'string', maxLength: 254, description: 'The email address the person provided. Omit to preview.' },
|
|
21
|
+
name: { type: 'string', maxLength: 80, description: 'Optional name provided by the person.' },
|
|
22
|
+
news: { type: 'boolean', description: 'True only after an explicit yes to the optional news question.' },
|
|
23
|
+
},
|
|
24
|
+
required: ['domain'],
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export async function watchDomain(input, { fetcher = globalThis.fetch, registry = lookupRegistrations,
|
|
30
|
+
siteCheck = checkDomainSite, now = new Date() } = {}) {
|
|
31
|
+
if (!input || typeof input !== 'object' || Array.isArray(input)
|
|
32
|
+
|| Object.keys(input).some(key => !Object.hasOwn(watchTool.inputSchema.properties, key))) {
|
|
33
|
+
throw Error('Enter the exact domain you want to watch.');
|
|
34
|
+
}
|
|
35
|
+
const domain = typeof input.domain === 'string' && input.domain.length <= 127 && asciiDomain(input.domain.trim());
|
|
36
|
+
const ending = domain && domain.split('.').at(-1);
|
|
37
|
+
if (!domain || !/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.[a-z]+$/.test(domain) || !defaultEndings.includes(ending)) {
|
|
38
|
+
throw Error('Enter a supported domain to watch, such as example.com.');
|
|
39
|
+
}
|
|
40
|
+
if (input.news !== undefined && typeof input.news !== 'boolean') throw Error('Optional news must be true or false.');
|
|
41
|
+
if (input.name !== undefined && (typeof input.name !== 'string' || input.name.length > 80 || /[\p{Cc}\p{Cf}]/u.test(input.name))) {
|
|
42
|
+
throw Error('Use up to 80 characters for the optional name.');
|
|
43
|
+
}
|
|
44
|
+
const email = typeof input.email === 'string' ? input.email.trim().toLowerCase() : null;
|
|
45
|
+
if (Object.hasOwn(input, 'email') && (!email || email.length > 254 ||
|
|
46
|
+
!/^[^\s@<>()[\]",;:\\]{1,64}@(?:[a-z0-9-]+\.)+[a-z]{2,63}$/.test(email))) {
|
|
47
|
+
throw Error('Enter the email address for the watch.');
|
|
48
|
+
}
|
|
49
|
+
const watchUrl = 'https://domainhound.dev/watch/?domain=' + encodeURIComponent(domain);
|
|
50
|
+
const started = performance.now();
|
|
51
|
+
const [[registration], site] = await Promise.all([
|
|
52
|
+
registry([{ domain, tld: ending }], { timeLeft: () => Math.max(0, 4800 - (performance.now() - started)),
|
|
53
|
+
now, dnsFirst: false, readExpiry: true, rdapAttempts: 1 }).catch(() => []),
|
|
54
|
+
siteCheck(domain, 2200, true).catch(() => null),
|
|
55
|
+
]);
|
|
56
|
+
const siteState = ['live', 'parked', 'for-sale'].includes(site?.state) ? site.state : 'no live site found';
|
|
57
|
+
const status = registration?.status === 'taken' || siteState === 'live' || siteState === 'parked' || siteState === 'for-sale'
|
|
58
|
+
? 'taken' : registration?.status === 'free' ? 'free' : 'unverified';
|
|
59
|
+
const expiryValue = registration?.expires;
|
|
60
|
+
const expiry = expiryValue && Number.isFinite(Date.parse(expiryValue)) ? expiryValue.slice(0, 10) : null;
|
|
61
|
+
const odds = status === 'free' ? 'The registry lists it as free. Check the price at a shop.'
|
|
62
|
+
: status === 'unverified' ? 'Release odds are unknown.'
|
|
63
|
+
: siteState === 'live' ? 'Low near-term odds. The site is live.'
|
|
64
|
+
: 'Release odds are unknown. Owners can renew after expiry.';
|
|
65
|
+
const lines = [domain + ': ' + status + ' | web: ' + siteState + ' | ' + (expiry ? 'expires ' + expiry : 'expiry unknown'), odds];
|
|
66
|
+
let submission = 'needs-email';
|
|
67
|
+
if (!email) {
|
|
68
|
+
lines.push('Ask for the email address once.', newsQuestion,
|
|
69
|
+
'[Start the free watch](' + watchUrl + '). You confirm by email.');
|
|
70
|
+
} else if (input.news === undefined) {
|
|
71
|
+
submission = 'needs-news-choice';
|
|
72
|
+
lines.push(newsQuestion);
|
|
73
|
+
} else {
|
|
74
|
+
let response;
|
|
75
|
+
try {
|
|
76
|
+
response = await fetcher(endpoint, { method: 'POST', redirect: 'error', signal: AbortSignal.timeout(5000),
|
|
77
|
+
headers: { 'content-type': 'application/json' },
|
|
78
|
+
body: JSON.stringify({ domain, email, ...(input.name?.trim() && { name: input.name.trim() }),
|
|
79
|
+
...(input.news === true && { news: 'yes' }), source: 'agent', consentTextVersion }) });
|
|
80
|
+
} catch { /* A timeout may occur after the worker has already accepted the request. */ }
|
|
81
|
+
const accepted = response?.status === 202 && (await response.json().catch(() => null))?.ok === true;
|
|
82
|
+
if (accepted) {
|
|
83
|
+
submission = 'accepted';
|
|
84
|
+
lines.push('Check your inbox to start watching. Choose “Confirm watch only” or “Confirm watch + news”. Already watching? Your watch stays on.');
|
|
85
|
+
} else {
|
|
86
|
+
submission = response?.status === 429 ? 'rate-limited' : 'unconfirmed';
|
|
87
|
+
lines.push(response?.status === 429 ? 'Too many tries. Wait a minute.' : 'Signup could not be verified. Check your inbox before trying again.',
|
|
88
|
+
'[Open the watch page](' + watchUrl + ').');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { domain, status, expiry, site: siteState, odds, watchUrl, submission, checkedAt: now.toISOString(),
|
|
92
|
+
source: registration?.source ?? null, newsConsentTextVersion: consentTextVersion, say: lines.join('\n') };
|
|
93
|
+
}
|