domain-hound 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +18 -6
- package/README.md +13 -14
- package/assets/icon-1024.png +0 -0
- package/assets/icon-512.png +0 -0
- package/assets/icon.svg +14 -0
- package/clis/domain-check/confirm.mjs +212 -28
- package/clis/domain-check/google-play.mjs +1 -1
- package/clis/domain-check/index.mjs +197 -47
- package/clis/domain-check/name-search.mjs +113 -17
- package/clis/domain-check/naming-method.mjs +6 -6
- package/clis/domain-check/price-catalog.mjs +7 -5
- package/clis/domain-check/prices.mjs +8 -2
- package/clis/domain-check/progress.mjs +14 -0
- package/clis/domain-check/registry.mjs +180 -39
- package/clis/domain-check/traction.mjs +2 -2
- package/clis/domain-check/triage-sources.mjs +8 -1
- package/clis/domain-check/triage.mjs +52 -26
- package/display.mjs +491 -149
- package/package.json +5 -3
- package/plugin.json +22 -4
- package/server.json +15 -4
- package/server.mjs +206 -64
- package/clis/domain-check/spaceship-feed.mjs +0 -72
package/display.mjs
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { shopSearchUrl, shops } from './clis/domain-check/prices.mjs';
|
|
2
2
|
import { isSearchLink, nameCheckLines } from './clis/domain-check/google-search.mjs';
|
|
3
|
-
import { canRecommend } from './clis/domain-check/name-search.mjs';
|
|
3
|
+
import { canRecommend, eligibilityNeed, normalizeName, premiumRisk, unicodeName } from './clis/domain-check/name-search.mjs';
|
|
4
|
+
import { purchaseLine } from './clis/domain-check/naming-method.mjs';
|
|
4
5
|
|
|
5
|
-
export { showAsIs } from './clis/domain-check/naming-method.mjs';
|
|
6
|
+
export { purchaseLine, showAsIs } from './clis/domain-check/naming-method.mjs';
|
|
6
7
|
export const neverBuys = 'Domain Hound never buys; open the link to buy.';
|
|
7
8
|
export const attribution = 'via domainhound.dev';
|
|
8
9
|
|
|
9
|
-
// Every MCP display
|
|
10
|
-
|
|
10
|
+
// Every MCP display carries one attribution line. The blank line keeps it out of a preceding table or list.
|
|
11
|
+
// When the display can show a checkout link, an exact lookup or purchase request can add the purchase line after it.
|
|
12
|
+
export const attributed = (display, purchase = false) => String(display ?? '').trimEnd() + '\n\n' + attribution
|
|
13
|
+
+ (purchase ? '\n\n' + purchaseLine : '');
|
|
11
14
|
|
|
12
15
|
const registrarIds = Object.keys(shops);
|
|
13
16
|
const compactTriageLegend = 'USD ex. VAT. prices by ending, own by name. term is years per payment.';
|
|
@@ -22,11 +25,62 @@ export function md(value) {
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
const money = value => '$' + Number(value).toFixed(2);
|
|
25
|
-
|
|
28
|
+
// The DNS label of a screened name: punycode for æøå, never with letters removed.
|
|
29
|
+
const label = name => normalizeName(String(name ?? '')) ?? String(name ?? '').normalize('NFKD').toLowerCase().replace(/[^a-z0-9-]/g, '');
|
|
26
30
|
const fullDomain = (name, d) => d.includes('.') ? d : name + '.' + d;
|
|
31
|
+
const suffix = domain => domain.split('.').at(-1);
|
|
32
|
+
const registered = (row, ending) => row.taken?.includes(ending) || row.resale?.includes(ending);
|
|
33
|
+
const checkoutLimitation = 'Domain Hound cannot buy or complete checkout.';
|
|
34
|
+
const mayBePremium = 'may be premium, price at shop';
|
|
27
35
|
|
|
36
|
+
// A name or domain in its own spelling with the ASCII form registrars use beside it: "grønn.no (xn--grnn-zua.no)".
|
|
37
|
+
export function shown(value) {
|
|
38
|
+
const text = String(value ?? '');
|
|
39
|
+
const unicode = unicodeName(text);
|
|
40
|
+
return unicode ? md(unicode) + ' (' + md(text) + ')' : md(text);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// "not eligible: needs Norwegian org/ID" for a restricted ending the buyer has not said they qualify for.
|
|
44
|
+
function ineligible(ending, eligible) {
|
|
45
|
+
return canRecommend(ending, eligible ?? []) ? null : 'not eligible: needs ' + eligibilityNeed(ending);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// The shop whose search page is the fallback checkout for an ending.
|
|
49
|
+
const fallbackShop = ending => ending === 'no' ? 'dynadot' : ending === 'so' ? 'namecheap' : 'spaceship';
|
|
50
|
+
// A checkout link that is never empty: the given URL when it is a trusted shop search, else the fallback shop search.
|
|
51
|
+
function checkoutLink(url, domain) {
|
|
52
|
+
return safeLink(url, domain) ?? safeLink(shopSearchUrl(fallbackShop(suffix(domain)), domain), domain);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The renewal jump as a whole multiple, when the renewal is over twice the first payment for the same term.
|
|
56
|
+
// Both payments cover the same number of years (.ai: two), so the payments compare directly.
|
|
57
|
+
export function jumpRatio(price) {
|
|
58
|
+
if (!(price?.now > 0) || price.renew == null) return null;
|
|
59
|
+
const ratio = price.renew / price.now;
|
|
60
|
+
return ratio > 2 ? Math.round(ratio) : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Payments due in three years and the years they cover: .ai pays two years at a time, so it covers four.
|
|
64
|
+
function threeYears(price) {
|
|
65
|
+
if (price?.now == null || price.renew == null) return null;
|
|
66
|
+
if (price.y3 != null && !(price.term > 1)) return { total: price.y3, years: 3 };
|
|
67
|
+
const term = price.term > 1 ? price.term : 1;
|
|
68
|
+
const renewals = Math.ceil((3 - term) / term);
|
|
69
|
+
return { total: price.y3 ?? Math.round((price.now + renewals * price.renew) * 100) / 100, years: term + renewals * term };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function preferredFirst(values, preferred, endingOf = value => value) {
|
|
73
|
+
if (!preferred?.length) return values;
|
|
74
|
+
const rank = value => {
|
|
75
|
+
const index = preferred.indexOf(suffix(endingOf(value)));
|
|
76
|
+
return index < 0 ? preferred.length : index;
|
|
77
|
+
};
|
|
78
|
+
return [...values].sort((a, b) => rank(a) - rank(b));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// A data-only shop has no search URL (null), so a missing URL must never match it.
|
|
28
82
|
export function safeLink(url, domain) {
|
|
29
|
-
if (!/^[a-z0-9-]+\.[a-z0-9-]+$/i.test(domain) ||
|
|
83
|
+
if (typeof url !== 'string' || !url || !/^[a-z0-9-]+\.[a-z0-9-]+$/i.test(domain) ||
|
|
30
84
|
!registrarIds.some(id => shopSearchUrl(id, domain) === url)) return null;
|
|
31
85
|
return '[' + domain + '](' + url + ')';
|
|
32
86
|
}
|
|
@@ -37,8 +91,13 @@ function templateLink(templates, shop, domain) {
|
|
|
37
91
|
? safeLink(template.replace('{domain}', encodeURIComponent(domain)), domain) : null;
|
|
38
92
|
}
|
|
39
93
|
|
|
94
|
+
// ".no not eligible: needs Norwegian org/ID." unless the buyer said they qualify.
|
|
40
95
|
function eligibilityLine(result) {
|
|
41
|
-
return Object.
|
|
96
|
+
return Object.keys(result.eligibility ?? {}).map(ending => {
|
|
97
|
+
const need = eligibilityNeed(ending);
|
|
98
|
+
return '.' + ending + (ineligible(ending, result.eligible) ? ' not eligible: needs ' + need + '.'
|
|
99
|
+
: ': eligible, you said you qualify (' + need + ').');
|
|
100
|
+
}).join(' ');
|
|
42
101
|
}
|
|
43
102
|
|
|
44
103
|
// When the live shop check could not run (no Playwright or no browser), the domain still needs a shop check.
|
|
@@ -51,28 +110,25 @@ function liveCheckLine(result, withLink = true) {
|
|
|
51
110
|
+ (check.reason ? ' (' + md(check.reason) + ')' : '') + '. Any prices shown are list estimates.';
|
|
52
111
|
}
|
|
53
112
|
|
|
54
|
-
// ".
|
|
113
|
+
// ".com $9.48/$10.68", with the term when a payment covers more than one year. A renewal over twice the first
|
|
114
|
+
// payment is said in the same place: ".co $3.11, then $31.05/yr, 10x jump".
|
|
115
|
+
function priceText(price) {
|
|
116
|
+
const term = price.term > 1 ? ' ' + price.term + 'y' : '';
|
|
117
|
+
const ratio = jumpRatio(price);
|
|
118
|
+
if (ratio) return money(price.now) + term + ', then ' + money(price.renew) + (term ? '/' + price.term + 'y' : '/yr') + ', ' + ratio + 'x jump';
|
|
119
|
+
return money(price.now) + (price.renew != null ? '/' + money(price.renew) : '') + term;
|
|
120
|
+
}
|
|
121
|
+
|
|
55
122
|
function priced(ending, price) {
|
|
56
|
-
|
|
57
|
-
const renew = price.renew != null ? '/' + money(price.renew) : '';
|
|
58
|
-
return ending + ' ' + money(price.now) + renew + (price.term > 1 ? ' ' + price.term + 'y' : '');
|
|
123
|
+
return ending + ' ' + (price?.now == null ? 'price at shop' : priceText(price));
|
|
59
124
|
}
|
|
60
125
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return own ? priced(ending(option.d), option) + mark : ending(option.d) + mark;
|
|
68
|
-
});
|
|
69
|
-
const usesStandard = (row.free ?? []).filter(option => option.now == null).map(option => option.d);
|
|
70
|
-
return {
|
|
71
|
-
name, usesStandard,
|
|
72
|
-
free: free.join(' '),
|
|
73
|
-
taken: [...(row.taken ?? []).map(ending), ...(row.resale ?? []).map(d => ending(d) + ' (resale)')].join(' '),
|
|
74
|
-
check: (row.shop_check ?? []).map(ending).join(' '),
|
|
75
|
-
};
|
|
126
|
+
// "Best value: lanternbay.com, $30.84 over 3 years" (the lowest total of the payments due in three years).
|
|
127
|
+
function bestValueLine(domain, price) {
|
|
128
|
+
const value = threeYears(price);
|
|
129
|
+
if (!value) return '';
|
|
130
|
+
return 'Best value: ' + shown(domain) + ', ' + money(value.total) + ' over 3 years'
|
|
131
|
+
+ (value.years > 3 ? ' (covers ' + value.years + ' years)' : '');
|
|
76
132
|
}
|
|
77
133
|
|
|
78
134
|
// The date of the oldest list price shown, e.g. "list price from 2026-11-25".
|
|
@@ -80,92 +136,205 @@ function listDate(result) {
|
|
|
80
136
|
return /^\d{4}-\d{2}-\d{2}$/.test(result.priceListDate ?? '') ? result.priceListDate : null;
|
|
81
137
|
}
|
|
82
138
|
|
|
139
|
+
const clock = value => /^\d{2}:\d{2}$/.test(value ?? '') ? ' ' + value + ' UTC' : '';
|
|
140
|
+
|
|
141
|
+
// "confirmed at Spaceship 12:04 UTC" for a shop quote; "list price" otherwise.
|
|
142
|
+
function priceLabel(option, shop) {
|
|
143
|
+
if (option?.s !== 'ok') return 'list price';
|
|
144
|
+
const premium = option.prem === 'possible' ? 'possible premium, ' : option.prem ? 'premium, ' : '';
|
|
145
|
+
return premium + 'confirmed at ' + md(shop ?? 'the shop') + clock(option.at);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// "Other endings (list prices, availability not checked): .ai $159.96/$159.96 2y · .io $21.40/$53.50 · ..."
|
|
149
|
+
function otherEndingsLine(result) {
|
|
150
|
+
const entries = Object.entries(result.otherEndings ?? {}).filter(([ending, price]) =>
|
|
151
|
+
price?.now != null && !ineligible(ending, result.eligible));
|
|
152
|
+
return entries.length ? 'Other endings (list prices, availability not checked): '
|
|
153
|
+
+ entries.map(([ending, price]) => priced('.' + ending, price)).join(' · ') : '';
|
|
154
|
+
}
|
|
155
|
+
|
|
83
156
|
function exactDisplay(result) {
|
|
84
157
|
const row = result.names?.[0] ?? {};
|
|
85
158
|
const domain = row.name;
|
|
159
|
+
const name = shown(domain);
|
|
86
160
|
const ending = domain.split('.').at(-1);
|
|
87
161
|
const checked = result.checkedAt ? ' Checked ' + String(result.checkedAt).slice(0, 16).replace('T', ' ') + ' UTC.' : '';
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (row
|
|
93
|
-
|
|
94
|
-
|
|
162
|
+
const others = otherEndingsLine(result);
|
|
163
|
+
const tail = others ? [others] : [];
|
|
164
|
+
const notEligible = ineligible(ending, result.eligible);
|
|
165
|
+
const eligibility = result.eligibility ? [eligibilityLine(result)] : [];
|
|
166
|
+
if (registered(row, ending)) {
|
|
167
|
+
const resale = row.resale?.includes(ending) ? ' The owner may list it for resale.' : '';
|
|
168
|
+
// The ending's standard list price, labelled as a benchmark: this name is not for sale at it.
|
|
169
|
+
const standard = result.listPrices?.[ending];
|
|
170
|
+
const date = listDate(result);
|
|
171
|
+
const showBenchmark = standard?.now != null && !notEligible && (ending === 'ai' || !premiumRisk(domain));
|
|
172
|
+
const term = standard?.term ?? 1;
|
|
173
|
+
const renewal = ending === 'ai' && standard?.renew != null
|
|
174
|
+
? money(standard.renew / term) + '/yr renewal, billed as ' + money(standard.renew) + ' every ' + term + ' years'
|
|
175
|
+
: showBenchmark ? priceText(standard) : '';
|
|
176
|
+
const benchmark = showBenchmark
|
|
177
|
+
? ['Standard .' + ending + ' list price (benchmark' + (date ? ' from ' + date : '') + ', USD ex. VAT): ' + renewal + '.']
|
|
178
|
+
: [];
|
|
179
|
+
return ['**' + name + ' is taken, and ' + checkoutLimitation + '**' + resale + checked, ...benchmark, ...tail].join('\n');
|
|
95
180
|
}
|
|
96
181
|
const free = row.free?.find(option => option.d === ending);
|
|
182
|
+
if (free?.s === 'prem') {
|
|
183
|
+
if (notEligible) return ['**' + name + ' is free at the registry.** ' + notEligible + '.' + checked, ...tail].join('\n');
|
|
184
|
+
const shop = free.shop ?? Object.keys(result.buyUrlTemplate ?? {})[0];
|
|
185
|
+
const link = templateLink(result.buyUrlTemplate, shop, domain);
|
|
186
|
+
const head = free.risk ? '**' + name + ' is free at the registry.** May be premium, price at shop'
|
|
187
|
+
: '**' + name + ' is free at the registry, but premium.** Premium, price at shop';
|
|
188
|
+
return [head + (link ? ': ' + link : '') + '.' + (free.risk ? ' No list price shown.' : ' No list price applies.') + checked,
|
|
189
|
+
...eligibility, ...tail].join('\n');
|
|
190
|
+
}
|
|
97
191
|
if (free) {
|
|
98
|
-
const
|
|
192
|
+
const confirmed = free.s === 'ok';
|
|
193
|
+
// A shop quote never falls back to the list price.
|
|
194
|
+
const offer = confirmed ? free : { ...result.listPrices?.[ending], ...free };
|
|
99
195
|
const best = result.best?.domain === domain ? result.best : null;
|
|
100
196
|
const shop = offer.shop ?? best?.shop;
|
|
101
197
|
const link = safeLink(best?.buyUrl, domain) ?? templateLink(result.buyUrlTemplate, shop, domain);
|
|
102
|
-
const confirmed = offer.s === 'ok';
|
|
103
198
|
const term = offer.term > 1 ? ' for ' + offer.term + ' years' : '';
|
|
104
|
-
const live = !confirmed && result.liveCheck?.domain === domain ? liveCheckLine(result) : '';
|
|
199
|
+
const live = !notEligible && !confirmed && result.liveCheck?.domain === domain ? liveCheckLine(result) : '';
|
|
200
|
+
const date = listDate(result);
|
|
201
|
+
const ratio = jumpRatio(offer);
|
|
202
|
+
const checkout = notEligible ?? (link ? link + (shop ? ' at ' + md(shop) : '') : '—');
|
|
105
203
|
const lines = [
|
|
106
|
-
'**' +
|
|
107
|
-
|
|
204
|
+
'**' + name + (free.prem ? ' is free, at a premium price.** ' : ' is free.** ')
|
|
205
|
+
+ (confirmed ? 'Price ' + priceLabel(free, shop) + '.'
|
|
206
|
+
: 'The registry shows it free; the price is a list price' + (offer.now != null && date ? ' from ' + date : '')
|
|
207
|
+
+ ', not a shop quote.') + checked,
|
|
108
208
|
'',
|
|
109
209
|
'| Domain | Today | Renewal | 3 years | Checkout |',
|
|
110
210
|
'|---|---|---|---|---|',
|
|
111
|
-
'| ' +
|
|
112
|
-
+ (offer.renew != null ? money(offer.renew) + (offer.term > 1 ? term : '/yr') : '—') + (
|
|
113
|
-
+ ' | ' + (offer.y3 != null ? money(offer.y3) : '—') + ' | ' +
|
|
211
|
+
'| ' + name + ' | ' + (offer.now != null ? money(offer.now) + term : 'price at shop') + ' | '
|
|
212
|
+
+ (offer.renew != null ? money(offer.renew) + (offer.term > 1 ? term : '/yr') : '—') + (ratio ? ', ' + ratio + 'x jump' : '')
|
|
213
|
+
+ ' | ' + (offer.y3 != null ? money(offer.y3) : '—') + ' | ' + checkout + ' |',
|
|
114
214
|
'',
|
|
115
215
|
...(live ? [live] : []),
|
|
116
|
-
'USD ex. VAT.' + (confirmed ? '' :
|
|
117
|
-
|
|
118
|
-
...
|
|
119
|
-
neverBuys,
|
|
216
|
+
'USD ex. VAT.' + (confirmed ? '' : ' Estimate: the shop shows the final price.'),
|
|
217
|
+
...eligibility,
|
|
218
|
+
...tail,
|
|
120
219
|
];
|
|
121
220
|
return lines.join('\n');
|
|
122
221
|
}
|
|
123
|
-
|
|
222
|
+
if (notEligible) return ['**' + name + ': ' + notEligible + '.**' + checked, ...tail].join('\n');
|
|
223
|
+
const why = result.shopCheckWhy?.[domain] ?? result.shopCheckWhy?.[ending];
|
|
124
224
|
const shop = Object.keys(result.buyUrlTemplate ?? {})[0];
|
|
125
225
|
const link = templateLink(result.buyUrlTemplate, shop, domain);
|
|
226
|
+
if (result.shopCheckWhy?.[domain]) {
|
|
227
|
+
// Reserved or not offered: no list price applies.
|
|
228
|
+
return ['**' + name + ': not offered for registration.** ' + md(why) + '. Check at shop' + (link ? ': ' + link : '') + '.' + checked,
|
|
229
|
+
...tail].join('\n');
|
|
230
|
+
}
|
|
126
231
|
const live = result.liveCheck?.domain === domain ? liveCheckLine(result, !link) : '';
|
|
127
232
|
const estimate = result.listPrices?.[ending];
|
|
128
233
|
const date = listDate(result);
|
|
129
|
-
const hasEstimate = estimate?.now != null && date;
|
|
130
|
-
|
|
131
|
-
|
|
234
|
+
const hasEstimate = estimate?.now != null && date && !premiumRisk(domain);
|
|
235
|
+
// DNS is a likelihood only; the registry or the shop settles it.
|
|
236
|
+
const likely = row.likely_free?.includes(ending) ? ' Likely free (DNS), confirm at shop.'
|
|
237
|
+
: row.likely_taken?.includes(ending) ? ' Likely taken (DNS).' : '';
|
|
238
|
+
const risk = premiumRisk(domain) ? ' A short name ' + mayBePremium + '.' : '';
|
|
239
|
+
return ['**' + name + ': not settled.** The registry did not settle it' + (why ? ' (' + md(why) + ')' : '') + '.' + likely
|
|
240
|
+
+ ' Check at shop' + (link ? ': ' + link : '') + '.' + risk + (hasEstimate || risk ? '' : ' No price yet.') + checked,
|
|
132
241
|
...(hasEstimate ? [
|
|
133
242
|
priced('.' + ending, estimate) + ' at ' + md(estimate.shop) + ' (USD ex. VAT, list price from ' + date + ').',
|
|
134
|
-
...
|
|
243
|
+
...eligibility,
|
|
135
244
|
] : []),
|
|
136
|
-
...(live ? [live] : []),
|
|
137
|
-
|
|
245
|
+
...(live ? [live] : []), ...tail].join('\n');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// One line per free domain, so a copied answer cannot merge or drop an ending. Each price appears once.
|
|
249
|
+
// Level 1 drops the "list price" word (the header says it); level 2 leaves standard prices to the shared line;
|
|
250
|
+
// level 3, for the densest batches, names each name once above its own ending lines.
|
|
251
|
+
function freeLines(row, listPrices, level, eligible) {
|
|
252
|
+
return (row.free ?? []).map(option => {
|
|
253
|
+
const full = option.d.includes('.') ? option.d : row.name.includes('.') ? row.name : row.name + '.' + option.d;
|
|
254
|
+
const domain = level >= 3 && !option.d.includes('.') && !row.name.includes('.') ? '.' + option.d : shown(full);
|
|
255
|
+
const blocked = ineligible(suffix(full), eligible);
|
|
256
|
+
if (blocked) return '- ' + domain + ' ' + blocked;
|
|
257
|
+
if (option.s === 'prem') return '- ' + domain + ' ' + (option.risk ? mayBePremium : 'premium, price at shop');
|
|
258
|
+
const own = option.now != null;
|
|
259
|
+
if (!own && level >= 2) return '- ' + domain;
|
|
260
|
+
const quote = own ? option : listPrices[option.d];
|
|
261
|
+
const listed = jumpRatio(quote) ? ' (list price)' : ' list price';
|
|
262
|
+
const tag = option.s === 'ok' ? ' ✓ ' + priceLabel(option, option.shop) : level >= 1 || quote?.now == null ? '' : listed;
|
|
263
|
+
return '- ' + domain + ' ' + (quote?.now == null ? 'price at shop' : priceText(quote)) + tag;
|
|
264
|
+
});
|
|
138
265
|
}
|
|
139
266
|
|
|
140
|
-
|
|
267
|
+
function groupRows(rows, linesFor) {
|
|
268
|
+
const groups = new Map();
|
|
269
|
+
for (const row of rows) {
|
|
270
|
+
const lines = linesFor(row);
|
|
271
|
+
if (!lines.length) continue;
|
|
272
|
+
const key = lines.join('\n');
|
|
273
|
+
if (!groups.has(key)) groups.set(key, { names: [], lines });
|
|
274
|
+
groups.get(key).names.push(shown(row.name));
|
|
275
|
+
}
|
|
276
|
+
return [...groups.values()];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// For one bare name: the cheapest first payment and the best three-year value among the endings this buyer can register.
|
|
280
|
+
function choiceLines(row, listPrices, eligible) {
|
|
281
|
+
const options = (row.free ?? []).flatMap(option => {
|
|
282
|
+
const domain = option.d.includes('.') ? option.d : row.name + '.' + option.d;
|
|
283
|
+
if (option.s === 'prem' || option.prem || premiumRisk(domain) || ineligible(suffix(domain), eligible)) return [];
|
|
284
|
+
const price = option.now != null ? option : listPrices[option.d];
|
|
285
|
+
return price?.now != null ? [{ domain, price, value: threeYears(price)?.total ?? Infinity }] : [];
|
|
286
|
+
});
|
|
287
|
+
if (!options.length) return [];
|
|
288
|
+
const cheapest = options.reduce((best, row) => row.price.now < best.price.now ? row : best);
|
|
289
|
+
const value = options.reduce((best, row) => row.value < best.value
|
|
290
|
+
|| (row.value === best.value && row.price.now < best.price.now) ? row : best);
|
|
291
|
+
return ['Cheapest now: ' + shown(cheapest.domain), ...(value.value < Infinity ? [bestValueLine(value.domain, value.price)] : [])];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function checkDisplay(result, level = 0, purchase = false) {
|
|
141
295
|
const rows = (result.names ?? []).filter(Boolean);
|
|
142
296
|
if (rows.length === 1 && rows[0].name?.includes('.')) return exactDisplay(result);
|
|
143
297
|
const listPrices = result.listPrices ?? {};
|
|
144
|
-
const
|
|
298
|
+
const eligible = result.eligible ?? [];
|
|
299
|
+
// The shared line carries a standard price only where no free line shows it: free endings from level 2 on, and
|
|
300
|
+
// endings left to a shop check. Short names may be premium, so their open endings add no list price.
|
|
145
301
|
const standard = new Set();
|
|
146
302
|
for (const row of rows) {
|
|
147
|
-
const
|
|
148
|
-
|
|
303
|
+
for (const option of row.free ?? []) if (level >= 2 && option.now == null && option.s !== 'prem') standard.add(option.d);
|
|
304
|
+
if (premiumRisk(row.name)) continue;
|
|
149
305
|
for (const d of row.shop_check ?? []) if (listPrices[d]?.now != null) standard.add(d);
|
|
150
|
-
const key = JSON.stringify([cells.free, cells.taken, cells.check]);
|
|
151
|
-
if (!groups.has(key)) groups.set(key, { names: [], ...cells });
|
|
152
|
-
groups.get(key).names.push(cells.name);
|
|
153
306
|
}
|
|
154
|
-
const shared = [...standard].filter(d => !d.includes('.'))
|
|
307
|
+
const shared = [...standard].filter(d => !d.includes('.') && listPrices[d] && !ineligible(d, eligible))
|
|
155
308
|
.map(d => priced('.' + d, listPrices[d])).join(' · ');
|
|
156
309
|
const lines = [
|
|
157
310
|
'**Domain check, ' + rows.length + (rows.length === 1 ? ' name' : ' names') + '** (USD ex. VAT, today/renewal; '
|
|
158
|
-
+ '
|
|
311
|
+
+ 'list prices' + (listDate(result) ? ' from ' + listDate(result) : '') + ' unless ✓ confirmed at a shop'
|
|
159
312
|
+ '; 2y = two-year payments)',
|
|
160
313
|
];
|
|
161
314
|
if (shared) lines.push('Standard prices: ' + shared);
|
|
162
315
|
if (result.eligibility) lines.push(eligibilityLine(result));
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
316
|
+
const free = level >= 3
|
|
317
|
+
? groupRows(rows, row => freeLines(row, listPrices, level, eligible))
|
|
318
|
+
.flatMap(group => [group.names.join(', ') + ':', ...group.lines])
|
|
319
|
+
: rows.flatMap(row => freeLines(row, listPrices, level, eligible));
|
|
320
|
+
lines.push('', '**Free domains, one ending per line**' + (free.length ? '' : ': none found'), ...free, '');
|
|
321
|
+
const endingsOf = (row, key) => (row[key] ?? []).map(d => d.includes('.') ? d : '.' + d);
|
|
322
|
+
const statusLines = project => level >= 3
|
|
323
|
+
? groupRows(rows, project).map(group => group.names.join(', ') + ' ' + group.lines.join(' '))
|
|
324
|
+
: rows.flatMap(row => {
|
|
325
|
+
const endings = project(row);
|
|
326
|
+
return endings.length ? [shown(row.name) + ' ' + endings.join(' ')] : [];
|
|
327
|
+
});
|
|
328
|
+
const likely = row => new Set([...(row.likely_free ?? []), ...(row.likely_taken ?? [])]);
|
|
329
|
+
const taken = statusLines(row => [...endingsOf(row, 'taken'), ...endingsOf(row, 'resale').map(d => d + ' (resale)')]);
|
|
330
|
+
const likelyTaken = statusLines(row => endingsOf(row, 'likely_taken'));
|
|
331
|
+
const likelyFree = statusLines(row => endingsOf(row, 'likely_free'));
|
|
332
|
+
const check = statusLines(row => endingsOf({ open: (row.shop_check ?? []).filter(d => !likely(row).has(d)) }, 'open'));
|
|
333
|
+
if (taken.length) lines.push('Taken: ' + taken.join(' · '));
|
|
334
|
+
// DNS is a likelihood only; the registry or the shop settles these.
|
|
335
|
+
if (likelyTaken.length) lines.push('Likely taken (DNS): ' + likelyTaken.join(' · '));
|
|
336
|
+
if (likelyFree.length) lines.push('Likely free (DNS), confirm at shop: ' + likelyFree.join(' · '));
|
|
337
|
+
if (check.length) lines.push('Check at shop: ' + check.join(' · '));
|
|
169
338
|
const reasons = new Map();
|
|
170
339
|
for (const [ending, reason] of Object.entries(result.shopCheckWhy ?? {})) {
|
|
171
340
|
if (!reasons.has(reason)) reasons.set(reason, []);
|
|
@@ -173,26 +342,30 @@ export function checkDisplay(result) {
|
|
|
173
342
|
}
|
|
174
343
|
for (const [reason, endings] of reasons) lines.push(endings.join(', ') + ' — ' + md(reason) + '.');
|
|
175
344
|
if (result.complete === false) lines.push('Some checks did not finish in time; check those at a shop.');
|
|
345
|
+
if (rows.length === 1) lines.push(...choiceLines(rows[0], listPrices, eligible));
|
|
176
346
|
const best = result.best;
|
|
177
347
|
const link = best && safeLink(best.buyUrl, best.domain);
|
|
178
348
|
if (link) {
|
|
179
|
-
lines.push('Confirmed
|
|
180
|
-
+ (best.
|
|
181
|
-
+ (best.shop ? ' at ' + md(best.shop) : '') + '.');
|
|
349
|
+
lines.push('Confirmed at ' + md(best.shop ?? 'the shop') + clock(best.at) + ': ' + link + ' '
|
|
350
|
+
+ (best.priceNow != null ? priceText({ now: best.priceNow, renew: best.renewal, term: best.term }) : 'price at shop') + '.');
|
|
182
351
|
lines.push(neverBuys);
|
|
183
352
|
} else if (result.liveCheck) {
|
|
184
353
|
const live = liveCheckLine(result);
|
|
185
354
|
if (live) lines.push(live, neverBuys);
|
|
355
|
+
} else if (rows.length === 1 || purchase) {
|
|
356
|
+
const available = rows.flatMap(row => (row.free ?? []).flatMap(option => {
|
|
357
|
+
const domain = option.d.includes('.') ? option.d : row.name.includes('.') ? row.name : row.name + '.' + option.d;
|
|
358
|
+
if (!canRecommend(domain.split('.').at(-1), eligible)) return [];
|
|
359
|
+
const price = option.prem || option.s === 'prem' ? option : { ...listPrices[option.d], ...option };
|
|
360
|
+
const link = templateLink(result.buyUrlTemplate, price.shop, domain);
|
|
361
|
+
return link ? [{ link, price: price.now ?? Infinity }] : [];
|
|
362
|
+
}));
|
|
363
|
+
const cheapest = available.sort((a, b) => a.price - b.price)[0];
|
|
364
|
+
if (cheapest) lines.push('Check at shop: ' + cheapest.link);
|
|
186
365
|
}
|
|
187
366
|
return lines.join('\n').trim();
|
|
188
367
|
}
|
|
189
368
|
|
|
190
|
-
function bestValueLine(domain, quote) {
|
|
191
|
-
if (quote?.now == null || quote.renew == null) return '';
|
|
192
|
-
const term = quote.term > 1 ? ' (each payment covers ' + quote.term + ' years)' : '';
|
|
193
|
-
return 'Best value: ' + md(domain) + ' ' + money(quote.now) + ' now, ' + money(quote.renew) + ' renewal' + term;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
369
|
function rowBestValue(row, prices) {
|
|
197
370
|
const ending = row?.bestValue;
|
|
198
371
|
return ending ? bestValueLine(fullDomain(label(row.name), ending), row.own?.[ending] ?? prices?.[ending]) : '';
|
|
@@ -210,14 +383,55 @@ export function checkLines(row, short = false) {
|
|
|
210
383
|
});
|
|
211
384
|
}
|
|
212
385
|
|
|
386
|
+
const verdictRank = { 'No conflict found': 0, 'Check first': 1, Avoid: 2 };
|
|
387
|
+
|
|
388
|
+
// The cheapest free ending this buyer can register, at the name's own price or the standard list price.
|
|
389
|
+
function cheapestEligible(row, prices, eligible) {
|
|
390
|
+
let best = null;
|
|
391
|
+
for (const ending of Array.isArray(row?.free) ? row.free : []) {
|
|
392
|
+
const quote = row.own?.[ending] ?? prices?.[ending];
|
|
393
|
+
if (!canRecommend(ending, eligible) || quote?.now == null) continue;
|
|
394
|
+
if (!best || quote.now < best.now) best = { ending, now: quote.now, renew: quote.renew ?? null, term: quote.term ?? null };
|
|
395
|
+
}
|
|
396
|
+
return best;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Three ranked picks once three or more names are screened: the screen's own ranking first, then the other
|
|
400
|
+
// names by verdict and cheapest eligible price. Each pick carries its cheapest eligible domain and price.
|
|
401
|
+
export function topPicks(result) {
|
|
402
|
+
const rows = (result.names ?? []).filter(Boolean);
|
|
403
|
+
const prices = result.prices ?? {};
|
|
404
|
+
const picks = (Array.isArray(result.top) ? result.top : []).filter(Boolean).slice(0, 3).map(pick => {
|
|
405
|
+
if (pick.ending || pick.domain) return pick;
|
|
406
|
+
const cheapest = cheapestEligible(rows.find(row => row.name === pick.name), prices, result.eligible);
|
|
407
|
+
return cheapest ? { ...pick, ...cheapest } : pick;
|
|
408
|
+
});
|
|
409
|
+
if (rows.length < 3) return picks;
|
|
410
|
+
const rest = rows.map((row, index) => ({ row, index, cheapest: cheapestEligible(row, prices, result.eligible) }))
|
|
411
|
+
.filter(({ row }) => !picks.some(pick => pick.name === row.name))
|
|
412
|
+
.sort((a, b) => (verdictRank[a.row.verdict] ?? 3) - (verdictRank[b.row.verdict] ?? 3)
|
|
413
|
+
|| (a.cheapest?.now ?? Infinity) - (b.cheapest?.now ?? Infinity) || a.index - b.index);
|
|
414
|
+
for (const { row, cheapest } of rest.slice(0, 3 - picks.length)) {
|
|
415
|
+
picks.push({ name: row.name, verdict: row.verdict, reason: row.reason,
|
|
416
|
+
...(cheapest && { ...cheapest, domain: fullDomain(label(row.name), cheapest.ending) }) });
|
|
417
|
+
}
|
|
418
|
+
return picks;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// A screened name as typed, with its DNS label beside it when that is punycode: "Grønnstue (xn--grnnstue-64a)".
|
|
422
|
+
function nameLabel(name) {
|
|
423
|
+
const dns = label(name);
|
|
424
|
+
return md(name) + (dns.startsWith('xn--') ? ' (' + md(dns) + ')' : '');
|
|
425
|
+
}
|
|
426
|
+
|
|
213
427
|
function topLines(result, showReason, showValue = true) {
|
|
214
|
-
return ['**Top picks**', ...result.
|
|
215
|
-
const ending = row.domain
|
|
216
|
-
const domain = ending ? ', ' + priced(ending, row) : '';
|
|
428
|
+
return ['**Top picks**', ...topPicks(result).map(row => {
|
|
429
|
+
const ending = row.domain ? shown(row.domain) : row.ending && '.' + row.ending;
|
|
430
|
+
const domain = ending ? ', cheapest now ' + priced(ending, row) : ', no eligible free ending';
|
|
217
431
|
const value = !showValue ? '' : typeof row.bestValue === 'string'
|
|
218
432
|
? rowBestValue(result.names.find(candidate => candidate.name === row.name), result.prices)
|
|
219
433
|
: row.bestValue && bestValueLine(row.bestValue.domain, row.bestValue);
|
|
220
|
-
return '- **' +
|
|
434
|
+
return '- **' + nameLabel(row.name) + '** — ' + md(row.verdict) + domain + (showReason ? '. ' + md(row.reason) : '')
|
|
221
435
|
+ (value ? ' \n ' + value : '');
|
|
222
436
|
})];
|
|
223
437
|
}
|
|
@@ -238,64 +452,85 @@ export function tractionLine(row, compact = false) {
|
|
|
238
452
|
return parts.length ? '<br>' + md(parts.join(' · ')) : '';
|
|
239
453
|
}
|
|
240
454
|
|
|
241
|
-
|
|
455
|
+
// Every row lists each free ending on its own line with its price.
|
|
456
|
+
export function triageDisplay(result, prior, { short = false, compact = false, preferred } = {}) {
|
|
242
457
|
const prices = result.prices ?? {};
|
|
243
458
|
const rows = (result.names ?? []).filter(Boolean);
|
|
244
459
|
const earlierRows = new Map((prior?.names ?? []).map(row => [row.name, row.free ?? []]));
|
|
245
460
|
const lines = [];
|
|
246
|
-
if (result.
|
|
461
|
+
if (topPicks(result).length) lines.push(...topLines(result, !prior && rows.length !== 5, !prior && rows.length !== 5), '');
|
|
247
462
|
lines.push(prior ? '**Name screen** (USD ex. VAT, estimates)' :
|
|
248
|
-
'**Name screen** (USD ex. VAT; list
|
|
463
|
+
'**Name screen** (USD ex. VAT; list prices, the shop shows the final price; 2y = each payment covers two years)');
|
|
249
464
|
if (result.eligibility) lines.push(eligibilityLine(result));
|
|
250
|
-
if (sharePrices) {
|
|
251
|
-
const standard = Object.entries(prices).map(([ending, price]) => priced('.' + ending, price));
|
|
252
|
-
if (standard.length) lines.push('Standard today/renewal: ' + standard.join(', '));
|
|
253
|
-
}
|
|
254
465
|
const checkoutHeading = prior ? 'Cheapest eligible / checkout' : 'Checkout';
|
|
255
|
-
lines.push('', '| Name | Verdict and reason | Free endings, today/renewal
|
|
466
|
+
lines.push('', '| Name | Verdict and reason | Free endings, one per line, today/renewal | ' + checkoutHeading + ' | Search checks |',
|
|
256
467
|
'|---|---|---|---|---|');
|
|
257
468
|
for (const row of rows) {
|
|
258
469
|
const base = label(row.name);
|
|
259
470
|
const free = Array.isArray(row.free) ? row.free : [];
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const link = first && base ?
|
|
267
|
-
const
|
|
268
|
-
|
|
471
|
+
const earlier = earlierRows.get(base) ?? [];
|
|
472
|
+
// An earlier premium answer, or a shop quote above the list price, replaces the list price for that ending.
|
|
473
|
+
const premiumQuote = ending => earlier.find(option => option.d === ending && (option.s === 'prem' || option.prem ||
|
|
474
|
+
(option.s === 'ok' && option.now != null && option.now > ((row.own?.[ending] ?? prices[ending])?.now ?? Infinity) + 0.01)));
|
|
475
|
+
const first = free.find(ending => canRecommend(ending, result.eligible) && !premiumQuote(ending));
|
|
476
|
+
// The checkout always links a real shop search; it never renders an empty link.
|
|
477
|
+
const link = first && base ? checkoutLink(row.buy, fullDomain(base, first)) : null;
|
|
478
|
+
const cell = preferredFirst(free, preferred).map(ending => {
|
|
479
|
+
const blocked = ineligible(ending, result.eligible);
|
|
480
|
+
if (blocked) return '.' + ending + ' ' + blocked;
|
|
269
481
|
const own = row.own?.[ending];
|
|
270
|
-
|
|
271
|
-
|
|
482
|
+
const premium = premiumQuote(ending);
|
|
483
|
+
if (premium) {
|
|
484
|
+
return premium.s === 'prem' || premium.now == null ? '.' + ending + ' premium, price at shop'
|
|
485
|
+
: priced('.' + ending, premium) + (premium.prem === true ? ' premium' : ' possible premium') + ' shop quote';
|
|
486
|
+
}
|
|
487
|
+
return priced('.' + ending, own ?? prices[ending]);
|
|
272
488
|
});
|
|
273
|
-
const earlier = earlierRows.get(base) ?? [];
|
|
274
489
|
const previous = option => priced('.' + option.d, option.now != null ? option : prior.listPrices?.[option.d]);
|
|
275
490
|
const recheck = earlier.filter(option => row.shop_check?.includes(option.d));
|
|
276
491
|
const taken = earlier.filter(option => row.taken?.includes(option.d));
|
|
277
|
-
const exact = earlier.filter(option => option.s === 'ok' && free.includes(option.d) &&
|
|
492
|
+
const exact = earlier.filter(option => option.s === 'ok' && free.includes(option.d) && !premiumQuote(option.d) &&
|
|
278
493
|
option.now !== (row.own?.[option.d] ?? prices[option.d])?.now);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
494
|
+
const likely = new Set([...(row.likely_free ?? []), ...(row.likely_taken ?? [])]);
|
|
495
|
+
const groups = {
|
|
496
|
+
premium: row.premium, taken: row.taken, likely_taken: row.likely_taken, likely_free: row.likely_free,
|
|
497
|
+
shop_check: row.shop_check?.filter(ending => !likely.has(ending)),
|
|
498
|
+
};
|
|
499
|
+
for (const [key, heading] of [['premium', premiumRisk(base) ? mayBePremium : 'premium, price at shop'], ['taken', 'taken'],
|
|
500
|
+
['likely_taken', 'likely taken (DNS)'], ['likely_free', 'likely free (DNS), confirm at shop'], ['shop_check', 'check at shop']]) {
|
|
501
|
+
if (groups[key]?.length) cell.push(heading + ': ' + preferredFirst(groups[key], preferred).map(ending => '.' + ending).join(' '));
|
|
502
|
+
}
|
|
503
|
+
if (!compact && recheck.length) cell.push('earlier price, recheck: ' + recheck.map(previous).join(', '));
|
|
504
|
+
if (!compact && taken.length) cell.push('earlier price, now taken: ' + taken.map(previous).join(', '));
|
|
505
|
+
if (!compact && exact.length) cell.push('earlier shop quote: ' + exact.map(previous).join(', '));
|
|
506
|
+
// The price stays on the ending's own line, so the checkout cell carries only the link.
|
|
507
|
+
const checkout = compact ? '—' : link ?? '—';
|
|
508
|
+
const value = !compact && rowBestValue(row, prices);
|
|
509
|
+
const reason = compact ? shorten(String(row.reason ?? '').split(' · ', 1)[0], 80) : row.reason;
|
|
510
|
+
const checks = compact ? checkLines(row, false).map(line => line.split(' · [search]', 1)[0]) : checkLines(row, short);
|
|
511
|
+
lines.push('| ' + nameLabel(row.name) + ' | ' + md(row.verdict) + ': ' + md(reason) + (compact ? '' : tractionLine(row, Boolean(prior) || short)) + ' | '
|
|
512
|
+
+ (cell.join('<br>') || 'none free') + (value ? '<br>' + value : '') + ' | ' + checkout + ' | '
|
|
513
|
+
+ checks.join('<br>') + ' |');
|
|
288
514
|
}
|
|
289
|
-
|
|
515
|
+
lines.push('', 'Choose a favorite and ask for its exact quote.');
|
|
290
516
|
return lines.join('\n');
|
|
291
517
|
}
|
|
292
518
|
|
|
293
519
|
const shorten = (value, length) => value.length > length ? value.slice(0, length - 1).trimEnd() + '…' : value;
|
|
294
520
|
|
|
295
|
-
function denseDisplay(result, short = false) {
|
|
296
|
-
const heading = result.
|
|
297
|
-
const
|
|
298
|
-
|
|
521
|
+
function denseDisplay(result, short = false, links = true) {
|
|
522
|
+
const heading = topPicks(result).length ? topLines(result, false).join('\n') : '**Name screen**';
|
|
523
|
+
const results = (result.names ?? []).filter(Boolean);
|
|
524
|
+
const checksFor = row => checkLines(row, short).map(line =>
|
|
525
|
+
links ? line : line.replace(/\[([^\]]+)\]\(https:\/\/[^)]+\)/g, '$1'));
|
|
526
|
+
const names = results.map(row => '- **' + nameLabel(row.name) + '** — ' + md(row.verdict));
|
|
527
|
+
const individual = names.map((name, index) => name + ' \n ' + checksFor(results[index]).join(' \n '));
|
|
528
|
+
const groups = links ? [] : groupRows(results, checksFor);
|
|
529
|
+
const shared = groups.flatMap(({ names, lines }) => [
|
|
530
|
+
names.length === results.length ? '**Search checks for every name**' : names.join(', '), ...lines,
|
|
531
|
+
]);
|
|
532
|
+
const rows = shared.length && bytes([...names, ...shared].join('\n')) < bytes(individual.join('\n'))
|
|
533
|
+
? [...names, '', ...shared] : individual;
|
|
299
534
|
const eligibility = result.eligibility ? [eligibilityLine(result)] : [];
|
|
300
535
|
return [heading, '', ...eligibility, '**Every name** (reasons and prices are in the results below)', ...rows].join('\n');
|
|
301
536
|
}
|
|
@@ -312,10 +547,76 @@ const withDisplay = (display, { display: ignored, ...data } = {}) => JSON.string
|
|
|
312
547
|
|
|
313
548
|
export const errorText = message => withDisplay(attributed(message));
|
|
314
549
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
550
|
+
const progressStage = {
|
|
551
|
+
quotes: 'Registry checks are in; shop prices are being checked.',
|
|
552
|
+
browser: 'The live shop check is running.',
|
|
553
|
+
rivals: 'Domain checks are in; trademark, app and rival checks are still running.',
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// The answer when a lookup outlasts this call's budget: what the registries have answered so far, the elapsed
|
|
557
|
+
// time against the budget, and how to collect the finished result from the lookup that keeps running.
|
|
558
|
+
// rows lists every requested name in input order with the domains it checks: each requested ending for a bare name,
|
|
559
|
+
// or the exact domain itself. A row without answers yet still shows every ending as still checking.
|
|
560
|
+
export function progressText(progress, { rows = [], elapsedMs = 0, budgetMs = 0, triage = false, purchase = false } = {}) {
|
|
561
|
+
const answers = progress?.answers instanceof Map ? progress.answers : new Map(progress?.answers ?? []);
|
|
562
|
+
const kinds = { 'probably-free': 'free', taken: 'taken', premium: 'premium' };
|
|
563
|
+
const names = rows.map(({ name, domains }) => {
|
|
564
|
+
const exact = String(name).includes('.') && domains.length === 1 && domains[0] === name;
|
|
565
|
+
const groups = { free: [], taken: [], premium: [], shop_check: [], checking: [] };
|
|
566
|
+
for (const domain of domains) {
|
|
567
|
+
const status = answers.get(domain);
|
|
568
|
+
groups[status === undefined ? 'checking' : kinds[status] ?? 'shop_check'].push(exact ? domain : domain.slice(domain.indexOf('.') + 1));
|
|
569
|
+
}
|
|
570
|
+
// The same row shapes as the finished result: check_domains rows list free endings as objects.
|
|
571
|
+
const free = triage ? groups.free : [...groups.free.map(d => ({ d, s: 'nc' })), ...groups.premium.map(d => ({ d, s: 'prem' }))];
|
|
572
|
+
return { name, ...(groups.taken.length && { taken: groups.taken }), ...(free.length && { free }),
|
|
573
|
+
...(triage && groups.premium.length && { premium: groups.premium }),
|
|
574
|
+
...(groups.shop_check.length && { shop_check: groups.shop_check }), ...(groups.checking.length && { checking: groups.checking }),
|
|
575
|
+
_groups: groups, _exact: exact };
|
|
576
|
+
});
|
|
577
|
+
const waiting = names.reduce((count, row) => count + row._groups.checking.length, 0);
|
|
578
|
+
const total = names.reduce((count, row) => count + Object.values(row._groups).flat().length, 0);
|
|
579
|
+
const seconds = ms => (Math.max(0, ms) / 1000).toFixed(1) + ' s';
|
|
580
|
+
const show = (row, endings) => endings.map(d => row._exact ? md(d) : '.' + md(d)).join(' ');
|
|
581
|
+
const lines = [
|
|
582
|
+
'**Still checking** after ' + seconds(elapsedMs) + ' (answer budget ' + seconds(budgetMs) + '). The lookup keeps running.',
|
|
583
|
+
'Registry answers so far: ' + (total - waiting) + ' of ' + total + ' domains.',
|
|
584
|
+
...names.map(row => '- ' + md(row.name) + ': ' + [
|
|
585
|
+
['free', row._groups.free], ['taken', row._groups.taken], ['premium', row._groups.premium],
|
|
586
|
+
['not settled', row._groups.shop_check], ['still checking', row._groups.checking],
|
|
587
|
+
].filter(([, endings]) => endings.length).map(([kind, endings]) => kind + ' ' + show(row, endings)).join(' · ')
|
|
588
|
+
+ (row._groups.checking.length ? ', ask again' : '')),
|
|
589
|
+
...(progressStage[progress?.stage] ? [progressStage[progress.stage]] : []),
|
|
590
|
+
'Prices, ' + (triage ? 'verdicts, ' : '') + 'links and every ending come with the finished result. '
|
|
591
|
+
+ 'Call the same tool again with the same input to collect it from this lookup.',
|
|
592
|
+
];
|
|
593
|
+
for (const row of names) {
|
|
594
|
+
delete row._groups;
|
|
595
|
+
delete row._exact;
|
|
596
|
+
}
|
|
597
|
+
return withDisplay(attributed(lines.join('\n'), purchase), {
|
|
598
|
+
complete: false, pending: true, elapsedMs: Math.round(elapsedMs), budgetMs: Math.round(budgetMs),
|
|
599
|
+
...(progressStage[progress?.stage] && { stage: progress.stage }), names,
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function checkText(result, shortlist = false, { purchase = false, preferred } = {}) {
|
|
604
|
+
if (preferred?.length) result = { ...result, names: result.names.map(row => ({ ...row,
|
|
605
|
+
...(row.free && { free: preferredFirst(row.free, preferred, option => option.d) }),
|
|
606
|
+
...(row.taken && { taken: preferredFirst(row.taken, preferred) }),
|
|
607
|
+
...(row.resale && { resale: preferredFirst(row.resale, preferred) }),
|
|
608
|
+
...(row.shop_check && { shop_check: preferredFirst(row.shop_check, preferred) }),
|
|
609
|
+
})) };
|
|
610
|
+
const initialLevel = (result.names?.length ?? 0) >= 10 ? 3 : 0;
|
|
611
|
+
const shown = checkDisplay(result, initialLevel, purchase);
|
|
612
|
+
const [row] = result.names ?? [];
|
|
613
|
+
const exact = result.names?.length === 1 && row?.name?.includes('.');
|
|
614
|
+
// A registered exact domain already shows the limitation with its status and has no checkout link.
|
|
615
|
+
const taken = exact && registered(row, suffix(row.name));
|
|
616
|
+
const ending = (exact || purchase) && !taken;
|
|
617
|
+
let display = attributed(shown, ending);
|
|
318
618
|
const data = { ...result };
|
|
619
|
+
if (taken && data.purchaseAdvice) data.purchaseAdvice = checkoutLimitation;
|
|
319
620
|
if (shortlist) {
|
|
320
621
|
// The preliminary batch keeps statuses and payments. The display has the confirmed link.
|
|
321
622
|
const quote = ({ y3, jump, shop, ...fields }) => fields;
|
|
@@ -333,22 +634,36 @@ export function checkText(result, shortlist = false) {
|
|
|
333
634
|
}
|
|
334
635
|
const groups = new Map();
|
|
335
636
|
for (const row of data.names) {
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
637
|
+
const free = (row.free ?? []).map(option => '.' + option.d
|
|
638
|
+
+ (option.risk ? ' (may be premium)' : option.s === 'prem' || option.prem ? ' (premium)' : ''));
|
|
639
|
+
const statuses = ['Free ' + (free.join(' ') || 'none found')];
|
|
640
|
+
for (const [key, heading] of [['taken', 'taken'], ['resale', 'resale'], ['shop_check', 'check at shop']]) {
|
|
641
|
+
if (row[key]?.length) statuses.push(heading + ' ' + row[key].map(ending => '.' + ending).join(' '));
|
|
642
|
+
}
|
|
643
|
+
const statusesText = statuses.join(' · ');
|
|
644
|
+
if (!groups.has(statusesText)) groups.set(statusesText, []);
|
|
645
|
+
groups.get(statusesText).push(md(row.name));
|
|
339
646
|
}
|
|
340
|
-
const lines = ['**Preliminary domain screen**
|
|
647
|
+
const lines = ['**Preliminary domain screen**', ...[...groups].map(([available, names]) =>
|
|
341
648
|
names.join(', ') + ' — ' + available)];
|
|
342
649
|
if (result.eligibility) lines.push(eligibilityLine(result));
|
|
343
|
-
const confirmed = shown.split('\n').filter(line => line.startsWith('Confirmed
|
|
650
|
+
const confirmed = shown.split('\n').filter(line => line.startsWith('Confirmed at ') || line.startsWith('Check at shop: ['));
|
|
344
651
|
if (confirmed.length) lines.push(...confirmed);
|
|
345
|
-
return withDisplay(attributed(lines.join('\n')), data);
|
|
652
|
+
return withDisplay(attributed(lines.join('\n'), purchase), data);
|
|
346
653
|
}
|
|
347
654
|
const limit = 7900;
|
|
655
|
+
let level = initialLevel;
|
|
656
|
+
const compactDisplay = next => () => {
|
|
657
|
+
if (next <= level) return;
|
|
658
|
+
level = next;
|
|
659
|
+
display = attributed(checkDisplay(result, level, purchase), ending);
|
|
660
|
+
};
|
|
348
661
|
const steps = [
|
|
349
|
-
// Drop inline prices from unconfirmed rows; the shared list price
|
|
662
|
+
// Drop inline prices from unconfirmed rows; the display and the shared list price keep them.
|
|
350
663
|
() => { data.names = data.names.map(row => row?.free
|
|
351
664
|
? { ...row, free: row.free.map(({ d, s, ...price }) => s === 'nc' ? { d, s } : { d, s, ...price }) } : row); },
|
|
665
|
+
// The display header already says prices are list prices unless confirmed.
|
|
666
|
+
compactDisplay(1),
|
|
352
667
|
// Keep standard prices only for endings that some row could still buy.
|
|
353
668
|
() => {
|
|
354
669
|
const open = new Set(data.names.flatMap(row => [...(row?.free ?? []).map(option => option.d), ...(row?.shop_check ?? [])]));
|
|
@@ -357,11 +672,18 @@ export function checkText(result, shortlist = false) {
|
|
|
357
672
|
() => { data.listPrices = Object.fromEntries(Object.entries(data.listPrices).map(([d, { y3, ...price }]) => [d, price])); },
|
|
358
673
|
// The display header carries the currency and confirmation key.
|
|
359
674
|
() => { delete data.legend; },
|
|
675
|
+
// A dense batch keeps one line per free domain; standard prices stay on the shared line.
|
|
676
|
+
compactDisplay(2),
|
|
677
|
+
// Unconfirmed is the default status of a free ending.
|
|
678
|
+
() => { data.names = data.names.map(row => row?.free
|
|
679
|
+
? { ...row, free: row.free.map(({ s, ...option }) => s === 'nc' ? option : { ...option, s }) } : row); },
|
|
680
|
+
compactDisplay(3),
|
|
360
681
|
];
|
|
682
|
+
const needsPrices = steps.slice(2, 4);
|
|
361
683
|
let text = withDisplay(display, data);
|
|
362
684
|
for (const step of steps) {
|
|
363
685
|
if (bytes(text) <= limit) break;
|
|
364
|
-
if (
|
|
686
|
+
if (needsPrices.includes(step) && !data.listPrices) continue;
|
|
365
687
|
step();
|
|
366
688
|
text = withDisplay(display, data);
|
|
367
689
|
}
|
|
@@ -369,20 +691,22 @@ export function checkText(result, shortlist = false) {
|
|
|
369
691
|
}
|
|
370
692
|
|
|
371
693
|
// Keep structured evidence keys in the MCP response when secondary details need to fit a shortlist.
|
|
372
|
-
export function triageText(result, prior) {
|
|
373
|
-
let shared = false;
|
|
694
|
+
export function triageText(result, prior, { purchase = false, preferred } = {}) {
|
|
374
695
|
let dense = false;
|
|
375
696
|
let short = false;
|
|
376
|
-
const render = () => attributed(dense ? denseDisplay(result, short) : triageDisplay(result, prior,
|
|
697
|
+
const render = () => attributed(dense ? denseDisplay(result, short) : triageDisplay(result, prior, { short, preferred }), purchase);
|
|
377
698
|
let display = render();
|
|
378
699
|
const count = result.names?.length ?? 0;
|
|
379
700
|
const data = structuredClone(result);
|
|
380
701
|
if (typeof data.legend === 'string') data.legend = compactTriageLegend;
|
|
381
702
|
// The display carries the three check lines; google stays for the client to fill.
|
|
382
|
-
for (const row of data.names ?? [])
|
|
703
|
+
for (const row of data.names ?? []) {
|
|
704
|
+
delete row.checks;
|
|
705
|
+
for (const key of ['free', 'taken', 'premium', 'shop_check']) if (Array.isArray(row[key])) row[key] = preferredFirst(row[key], preferred);
|
|
706
|
+
}
|
|
383
707
|
let { top, ...fields } = data;
|
|
384
|
-
const serialize = () => JSON.stringify({ ...(top && { top }),
|
|
385
|
-
const limit = count <= 1 ? 5900 : count <= 5 ? (prior ? 3800 : 5900) :
|
|
708
|
+
const serialize = () => JSON.stringify({ display, ...(top && { top }), ...fields });
|
|
709
|
+
const limit = count <= 1 ? 5900 : count <= 5 ? (prior ? 3800 : 5900) : 7800;
|
|
386
710
|
let text = serialize();
|
|
387
711
|
for (const trim of [
|
|
388
712
|
row => { if (row.notes) row.notes = row.notes.slice(0, 1); },
|
|
@@ -407,21 +731,19 @@ export function triageText(result, prior) {
|
|
|
407
731
|
fields.names.forEach(trim);
|
|
408
732
|
text = serialize();
|
|
409
733
|
}
|
|
410
|
-
if (count > 1 && bytes(text) > limit) {
|
|
411
|
-
shared = true;
|
|
412
|
-
display = render();
|
|
413
|
-
text = serialize();
|
|
414
|
-
}
|
|
415
734
|
if (prior && count <= 5 && bytes(text) > limit) {
|
|
416
735
|
for (const row of fields.names) row.reason = row.reason?.split(' · ', 1)[0];
|
|
736
|
+
const earlier = new Map(prior.names?.map(row => [row.name, new Set((row.free ?? []).map(option => option.d))]));
|
|
737
|
+
const newlyFree = new Set(fields.names.flatMap(row => (Array.isArray(row.free) ? row.free : [])
|
|
738
|
+
.filter(ending => !earlier.get(label(row.name))?.has(ending))));
|
|
417
739
|
fields.prices = Object.fromEntries(Object.entries(fields.prices ?? {}).filter(([ending, quote]) => {
|
|
418
|
-
const
|
|
419
|
-
return !
|
|
420
|
-
(quote.term ?? 1) !== (
|
|
740
|
+
const listed = prior.listPrices?.[ending];
|
|
741
|
+
return newlyFree.has(ending) || !listed || quote.now !== listed.now || quote.renew !== listed.renew ||
|
|
742
|
+
(quote.term ?? 1) !== (listed.term ?? 1) || Boolean(quote.jump) !== Boolean(listed.jump);
|
|
421
743
|
}));
|
|
422
744
|
text = serialize();
|
|
423
745
|
}
|
|
424
|
-
const maxBytes = count <= 5 ? (prior ? 5200 : 6000) :
|
|
746
|
+
const maxBytes = count <= 5 ? (prior ? 5200 : 6000) : 8000;
|
|
425
747
|
const step = change => {
|
|
426
748
|
if (count <= 1 || bytes(text) < maxBytes) return;
|
|
427
749
|
change();
|
|
@@ -475,7 +797,31 @@ export function triageText(result, prior) {
|
|
|
475
797
|
delete fields.sources;
|
|
476
798
|
for (const row of fields.names) if (row.google && !row.google.search) delete row.google.link;
|
|
477
799
|
});
|
|
478
|
-
if (
|
|
800
|
+
if (bytes(text) < maxBytes || count <= 1) return text;
|
|
801
|
+
if (count > 5) {
|
|
802
|
+
const names = result.names.map(({ name, verdict, reason, free, own, taken, shop_check, premium, bestValue, google }) => ({
|
|
803
|
+
name, verdict, reason: shorten(reason?.split(' · ', 1)[0] ?? '', 60), free,
|
|
804
|
+
...(Object.keys(own ?? {}).length && { own }),
|
|
805
|
+
...(taken?.length && { taken }),
|
|
806
|
+
...(shop_check?.length && { shop_check }),
|
|
807
|
+
...(premium?.length && { premium }),
|
|
808
|
+
...(bestValue && { bestValue }),
|
|
809
|
+
...(google?.search && { google }),
|
|
810
|
+
}));
|
|
811
|
+
const renderWith = (links, repeatMetadata = true) => withDisplay(attributed(denseDisplay(result, true, links), purchase), {
|
|
812
|
+
names, prices: result.prices, ...(repeatMetadata && top && { top }),
|
|
813
|
+
...(repeatMetadata && result.eligibility && { eligibility: result.eligibility }),
|
|
814
|
+
});
|
|
815
|
+
const linked = renderWith(true);
|
|
816
|
+
if (bytes(linked) < maxBytes) return linked;
|
|
817
|
+
const unlinked = renderWith(false);
|
|
818
|
+
if (bytes(unlinked) < maxBytes) return unlinked;
|
|
819
|
+
for (const row of names) {
|
|
820
|
+
row.reason = shorten(row.reason, 24);
|
|
821
|
+
if (row.google) row.google = { result: row.google.result, search: true };
|
|
822
|
+
}
|
|
823
|
+
return renderWith(false, false);
|
|
824
|
+
}
|
|
479
825
|
|
|
480
826
|
// Long labels and their repeated search URLs can exhaust even the dense format.
|
|
481
827
|
// Keep every verdict, domain option and price, then add the source links where they fit.
|
|
@@ -490,11 +836,7 @@ export function triageText(result, prior) {
|
|
|
490
836
|
...(row.bestValue && { bestValue: row.bestValue }),
|
|
491
837
|
...(row.google?.search && { google: row.google }),
|
|
492
838
|
}));
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const dataOnly = { names, prices: result.prices };
|
|
497
|
-
const fit = lines => JSON.stringify({ display: attributed([...header, ...lines].join('\n')), ...dataOnly });
|
|
498
|
-
const links = fit(summary.map((line, index) => line + ' \n ' + checkLines(result.names[index], true).join(' \n ')));
|
|
499
|
-
return bytes(links) < maxBytes ? links : fit(summary);
|
|
839
|
+
for (const row of names) for (const key of ['free', 'taken', 'shop_check']) if (Array.isArray(row[key])) row[key] = preferredFirst(row[key], preferred);
|
|
840
|
+
const compactDisplay = attributed(triageDisplay(result, prior, { compact: true, preferred }), purchase);
|
|
841
|
+
return withDisplay(compactDisplay, { names, prices: result.prices });
|
|
500
842
|
}
|