domain-hound 0.0.0-stage → 0.1.2
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 +12 -0
- package/.claude-plugin/marketplace.json +12 -0
- package/.claude-plugin/plugin.json +28 -0
- package/LICENSE +21 -0
- package/README.md +63 -2
- package/assets/icon-1024.png +0 -0
- package/assets/icon-512.png +0 -0
- package/assets/icon.svg +14 -0
- package/bin/domain-hound.mjs +5 -0
- package/clis/domain-check/cache.mjs +64 -0
- package/clis/domain-check/com-site.mjs +159 -0
- package/clis/domain-check/company-search.mjs +90 -0
- package/clis/domain-check/confirm.mjs +612 -0
- package/clis/domain-check/google-play.mjs +191 -0
- package/clis/domain-check/google-search.mjs +244 -0
- package/clis/domain-check/index.mjs +636 -0
- package/clis/domain-check/name-search.mjs +248 -0
- package/clis/domain-check/naming-method.mjs +21 -0
- package/clis/domain-check/parking.mjs +27 -0
- package/clis/domain-check/price-catalog.mjs +343 -0
- package/clis/domain-check/price-snapshot.json +176 -0
- package/clis/domain-check/prices.mjs +196 -0
- package/clis/domain-check/progress.mjs +14 -0
- package/clis/domain-check/registry.mjs +274 -0
- package/clis/domain-check/terms.json +152 -0
- package/clis/domain-check/traction.mjs +603 -0
- package/clis/domain-check/triage-sources.mjs +321 -0
- package/clis/domain-check/triage.mjs +566 -0
- package/display.mjs +713 -0
- package/mcp.json +10 -0
- package/package.json +66 -4
- package/plugin.json +32 -0
- package/server.json +27 -0
- package/server.mjs +444 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "domain-hound-marketplace",
|
|
3
|
+
"interface": { "displayName": "Domain Hound" },
|
|
4
|
+
"plugins": [
|
|
5
|
+
{
|
|
6
|
+
"name": "domain-hound",
|
|
7
|
+
"source": { "source": "local", "path": "./" },
|
|
8
|
+
"policy": { "installation": "AVAILABLE", "authentication": "ON_INSTALL" },
|
|
9
|
+
"category": "Productivity"
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "domain-hound-marketplace",
|
|
3
|
+
"description": "Domain Hound for Claude Code.",
|
|
4
|
+
"owner": { "name": "Lars Hvinden" },
|
|
5
|
+
"plugins": [
|
|
6
|
+
{
|
|
7
|
+
"name": "domain-hound",
|
|
8
|
+
"source": "./",
|
|
9
|
+
"description": "Check domains, compare registrar prices, and screen product names."
|
|
10
|
+
}
|
|
11
|
+
]
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "domain-hound",
|
|
3
|
+
"displayName": "Domain Hound",
|
|
4
|
+
"version": "0.1.2",
|
|
5
|
+
"description": "Check domain availability and prices, and screen product names, from your AI assistant.",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Lars Hvinden"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://domainhound.dev",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"mcp",
|
|
13
|
+
"domains"
|
|
14
|
+
],
|
|
15
|
+
"mcpServers": {
|
|
16
|
+
"domain-hound": {
|
|
17
|
+
"command": "npx",
|
|
18
|
+
"args": [
|
|
19
|
+
"-y",
|
|
20
|
+
"domain-hound"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"icon": "./assets/icon-512.png",
|
|
25
|
+
"documentationUrl": "https://github.com/lars-hv/domain-hound#readme",
|
|
26
|
+
"supportUrl": "https://github.com/lars-hv/domain-hound/issues",
|
|
27
|
+
"privacyPolicyUrl": "https://domainhound.dev/privacy/"
|
|
28
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lars Hvinden
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Domain Hound
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Check whether domains are available, compare the first payment and renewal across registrars, and screen product names for conflicts. Domain Hound runs locally and never buys domains or completes checkout.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Requires Node.js 20 or later.
|
|
8
|
+
|
|
9
|
+
### Install
|
|
10
|
+
|
|
11
|
+
**Claude Code**
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
claude mcp add domain-hound -- npx -y domain-hound
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Codex**
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
codex mcp add domain-hound -- npx -y domain-hound
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Other MCP clients**
|
|
24
|
+
|
|
25
|
+
Add this to the client’s MCP configuration for a local stdio server.
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"mcpServers": {
|
|
30
|
+
"domain-hound": {
|
|
31
|
+
"command": "npx",
|
|
32
|
+
"args": ["-y", "domain-hound"]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The default install checks the registry and shows dated list prices. For a confirmed price, set `DOMAIN_HOUND_SPACESHIP_KEY` and `DOMAIN_HOUND_SPACESHIP_SECRET` (Spaceship permission `domains:read`), or `DOMAIN_HOUND_DYNADOT_KEY` (a production API key). Dynadot gives its production key account-wide access. Domain Hound only uses it to search. It shows premium pricing when it has a quote and points you to the shop when it has a premium signal without a price.
|
|
39
|
+
|
|
40
|
+
For the optional browser fallback, run `npm install domain-hound playwright && npx playwright install chromium` in a project directory and start your MCP client there. Ask for a live shop check to set the `confirm` tool flag, or use `--confirm` with the CLI.
|
|
41
|
+
|
|
42
|
+
## Tools
|
|
43
|
+
|
|
44
|
+
- `check_domains` checks one name or exact domain, or up to 20 at once. A bare name checks ten endings. The first lookup on a fresh install shows the list prices bundled with the package, labelled with their date, while the local price list refreshes in the background.
|
|
45
|
+
- `triage_names` screens names against public domain, trademark, app, company, and handle data.
|
|
46
|
+
- `naming_method` gives your assistant a recipe for generating and screening new names.
|
|
47
|
+
|
|
48
|
+
## Privacy
|
|
49
|
+
|
|
50
|
+
The server has no Domain Hound account or hosted backend. Lookups send the relevant name or domain to public sources. Domain searches use IANA and registry RDAP/WHOIS, public DNS, and public registrar pricing. When configured, the client sends selected domains to the Spaceship or Dynadot API for a quote. The optional browser check opens a registrar’s public search page. Name screening may also query the USPTO, Apple App Store, Google Play, Google Search and Trends, Wikidata, public company and package registries, social platforms, Tranco, Common Crawl, and candidate websites. If you configure a search provider via environment variables, queries can also go to Brave Search or Serper. Results may be cached locally.
|
|
51
|
+
|
|
52
|
+
## Daily checks
|
|
53
|
+
|
|
54
|
+
Run `node scripts/canary.mjs` to check live registries, the Spotify name screen, and the public Dynadot and Porkbun price lists. It prints JSON with the status of each source and exits with a failure when a required check breaks. The GitHub Actions workflow is scheduled for 06:17 UTC and opens or updates an issue for each failing source.
|
|
55
|
+
|
|
56
|
+
## Releases
|
|
57
|
+
|
|
58
|
+
`.github/workflows/publish.yml` publishes a matching `v*` version tag to npm with Trusted Publishing and provenance. After the first manual publish, open the package settings on npm and add GitHub Actions as a trusted publisher. Use owner `lars-hv`, repository `domain-hound`, workflow `publish.yml`, and allow `npm publish`. Use the workflow for the next unpublished version. [npm Trusted Publishing setup](https://docs.npmjs.com/trusted-publishers/)
|
|
59
|
+
|
|
60
|
+
To refresh the bundled list prices before a release, run `npm run snapshot-prices`. It copies only the local `prices.json` price list.
|
|
61
|
+
|
|
62
|
+
Run `npm run build-mcpb` on a build machine with Node.js, npm, and `zip`. It writes a standalone bundle to `dist/domain-hound-<version>.mcpb` and prints its SHA-256 for the MCPB entry in `server.json`.
|
|
63
|
+
|
|
64
|
+
[MIT license](LICENSE)
|
|
Binary file
|
|
Binary file
|
package/assets/icon.svg
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120">
|
|
2
|
+
<title>Snarl</title>
|
|
3
|
+
<path fill="#f4c64f" stroke="#05070d" stroke-width="4" stroke-linejoin="round" d="M5 79Q8 62 13 44Q15 29 29 23Q42 13 58 16L71 19L79 18L84 24L79 26L86 32L95 33L101 37L112 37Q118 38 117 46L112 56L103 58L97 67L87 61L77 59L66 64L76 70L86 76L99 77L105 71L105 82Q101 91 91 92Q80 93 69 86L55 75L49 74Q43 89 30 97Q20 105 13 102Q6 100 7 89Z"/>
|
|
4
|
+
<g fill="#05070d">
|
|
5
|
+
<path d="M8 87Q13 67 21 48Q27 32 39 28Q30 37 26 53Q20 74 8 94Z"/>
|
|
6
|
+
<path d="M18 99Q30 90 36 72Q41 56 39 43Q48 50 44 67Q40 88 25 98Z"/>
|
|
7
|
+
<path d="M45 23Q56 18 71 23L59 23L52 26Z"/>
|
|
8
|
+
<path d="M47 38L58 37L73 31L84 32L76 37L72 44L62 46L55 42Z"/>
|
|
9
|
+
<path d="M79 43L84 36L92 36L86 38ZM85 47L93 40L99 41L94 43Z"/>
|
|
10
|
+
<path d="M98 45L104 40L116 40Q118 45 111 52L102 53Z"/>
|
|
11
|
+
<path d="M46 59Q53 61 59 57L71 50Q79 45 88 48L97 53L108 53L103 58L98 62L88 57Q78 51 73 56L65 62L63 67L76 75Q84 82 97 80Q88 88 77 82L61 70Z"/>
|
|
12
|
+
</g>
|
|
13
|
+
<path fill="#f4c64f" d="M59 40L71 36L67 41L62 42ZM77 54L84 54L80 62ZM87 55L97 58L89 72L89 64ZM99 58L104 56L100 64Z"/>
|
|
14
|
+
</svg>
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join, resolve, sep } from 'node:path';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
|
|
7
|
+
// Runtime evidence lives in the user's cache, never inside the installed package.
|
|
8
|
+
// DOMAIN_HOUND_CACHE_DIR overrides the location (tests point it at a temporary folder).
|
|
9
|
+
export function userCacheDir(env = process.env, platform = process.platform, home = homedir()) {
|
|
10
|
+
if (env.DOMAIN_HOUND_CACHE_DIR) return resolve(env.DOMAIN_HOUND_CACHE_DIR);
|
|
11
|
+
if (platform === 'darwin') return join(home, 'Library', 'Caches', 'domain-hound');
|
|
12
|
+
if (platform === 'win32') return join(env.LOCALAPPDATA || join(home, 'AppData', 'Local'), 'domain-hound', 'Cache');
|
|
13
|
+
return join(env.XDG_CACHE_HOME || join(home, '.cache'), 'domain-hound');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const cacheDir = pathToFileURL(userCacheDir().replace(/[\\/]*$/, sep));
|
|
17
|
+
|
|
18
|
+
export async function readCache(directory, filename) {
|
|
19
|
+
if (!directory) return null;
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(await readFile(new URL(filename, directory), 'utf8'));
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function writeCache(directory, filename, value) {
|
|
28
|
+
if (!directory) return;
|
|
29
|
+
const temp = new URL(filename + '.' + randomUUID() + '.tmp', directory);
|
|
30
|
+
try {
|
|
31
|
+
await mkdir(directory, { recursive: true });
|
|
32
|
+
await writeFile(temp, JSON.stringify(value), { mode: 0o600 });
|
|
33
|
+
await rename(temp, new URL(filename, directory));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
await unlink(temp).catch(() => {});
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function mapLimit(items, limit, processItem) {
|
|
41
|
+
const results = [];
|
|
42
|
+
let next = 0;
|
|
43
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
44
|
+
while (next < items.length) {
|
|
45
|
+
const index = next++;
|
|
46
|
+
results[index] = await processItem(items[index]);
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
return results;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// AbortSignal.any arrived in Node 20.3; this keeps Node 20.0 to 20.2 working.
|
|
53
|
+
export function anySignal(signals) {
|
|
54
|
+
if (typeof AbortSignal.any === 'function') return AbortSignal.any(signals);
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
for (const signal of signals) {
|
|
57
|
+
if (signal.aborted) {
|
|
58
|
+
controller.abort(signal.reason);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
signal.addEventListener('abort', () => controller.abort(signal.reason), { once: true, signal: controller.signal });
|
|
62
|
+
}
|
|
63
|
+
return controller.signal;
|
|
64
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { Resolver } from 'node:dns/promises';
|
|
2
|
+
import { get as httpGet } from 'node:http';
|
|
3
|
+
import { get as httpsGet } from 'node:https';
|
|
4
|
+
import { BlockList, isIP } from 'node:net';
|
|
5
|
+
import { anySignal } from './cache.mjs';
|
|
6
|
+
|
|
7
|
+
const maxBytes = 200_000;
|
|
8
|
+
const restricted = new BlockList();
|
|
9
|
+
for (const [address, prefix] of [
|
|
10
|
+
['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8],
|
|
11
|
+
['169.254.0.0', 16], ['172.16.0.0', 12], ['192.0.0.0', 24], ['192.0.2.0', 24],
|
|
12
|
+
['192.168.0.0', 16], ['198.18.0.0', 15], ['198.51.100.0', 24], ['203.0.113.0', 24], ['224.0.0.0', 3],
|
|
13
|
+
]) restricted.addSubnet(address, prefix);
|
|
14
|
+
for (const [address, prefix] of [['2001::', 23], ['2001:db8::', 32], ['2002::', 16], ['3fff::', 20]]) {
|
|
15
|
+
restricted.addSubnet(address, prefix, 'ipv6');
|
|
16
|
+
}
|
|
17
|
+
const globalIpv6 = new BlockList();
|
|
18
|
+
globalIpv6.addSubnet('2000::', 3, 'ipv6');
|
|
19
|
+
|
|
20
|
+
function publicAddress({ address, family }) {
|
|
21
|
+
return family === 4 ? !restricted.check(address)
|
|
22
|
+
: globalIpv6.check(address, 'ipv6') && !restricted.check(address, 'ipv6');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function lookupPublic(signal) {
|
|
26
|
+
return (host, options, done) => {
|
|
27
|
+
if (signal.aborted) return done(new Error('Site lookup timed out'));
|
|
28
|
+
const resolver = new Resolver({ timeout: 950, tries: 1 });
|
|
29
|
+
const cancel = () => resolver.cancel();
|
|
30
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
31
|
+
const families = options.family ? [options.family] : [4, 6];
|
|
32
|
+
Promise.all(families.map(async family => {
|
|
33
|
+
const addresses = await (family === 4 ? resolver.resolve4(host) : resolver.resolve6(host)).catch(() => []);
|
|
34
|
+
return addresses.map(address => ({ address, family })).filter(publicAddress);
|
|
35
|
+
})).then(results => {
|
|
36
|
+
signal.removeEventListener('abort', cancel);
|
|
37
|
+
const usable = results.flat();
|
|
38
|
+
if (!usable.length) done(new Error('No public address'));
|
|
39
|
+
else if (options.all) done(null, usable);
|
|
40
|
+
else done(null, usable[0].address, usable[0].family);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const saleHosts = ['sedo.com', 'sedoparking.com', 'afternic.com', 'dan.com', 'hugedomains.com', 'atom.com', 'squadhelp.com'];
|
|
46
|
+
const parkingHosts = ['parkingcrew.net', 'bodis.com', 'above.com', 'parklogic.com', 'parked.com', 'parking-page.net'];
|
|
47
|
+
const hasHost = (host, choices) => choices.some(name => host === name || host.endsWith('.' + name));
|
|
48
|
+
const saleText = /\b(?:this domain (?:name )?(?:may be|is) for sale|buy this domain(?: name)?|buy this domain on (?:sedo|afternic|dan\.com)|domain (?:for sale|is listed for sale))\b/i;
|
|
49
|
+
const parkedText = /\b(?:this (?:domain|web page) is parked|domain parking(?: page)?|parked (?:free|by|with|courtesy of|domain)|website coming soon)\b/i;
|
|
50
|
+
const errorText = /^(?:403|404|503|access denied|just a moment|site not found|domain not configured|not found)\b/i;
|
|
51
|
+
|
|
52
|
+
function decodeText(value) {
|
|
53
|
+
const entities = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' };
|
|
54
|
+
return value.replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (match, entity) => {
|
|
55
|
+
if (!entity.startsWith('#')) return entities[entity.toLowerCase()] ?? match;
|
|
56
|
+
const point = entity[1].toLowerCase() === 'x' ? parseInt(entity.slice(2), 16) : Number(entity.slice(1));
|
|
57
|
+
return point <= 0x10ffff ? String.fromCodePoint(point) : match;
|
|
58
|
+
}).replace(/[\s\u202a-\u202e\u2066-\u2069]+/g, ' ').trim();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function classifyComSite({ url, status, contentType, lastModified, body = '' } = {}, detailed = false) {
|
|
62
|
+
const host = url ? new URL(url).hostname : '';
|
|
63
|
+
if (hasHost(host, saleHosts) || (hasHost(host, ['godaddy.com']) && /\/forsale(?:\/|$)/i.test(new URL(url).pathname))) {
|
|
64
|
+
return { state: 'for-sale' };
|
|
65
|
+
}
|
|
66
|
+
if (hasHost(host, parkingHosts)) return { state: 'parked' };
|
|
67
|
+
if (!(status >= 200 && status < 300) || !/^text\/html\b|^application\/xhtml\+xml\b/i.test(contentType) || !body) {
|
|
68
|
+
return { state: 'no-site' };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// A script-only page that sends visitors to /lander is a registrar parking page.
|
|
72
|
+
if (/^\s*(?:<!doctype html>)?\s*<html>\s*<head>\s*<script>[^<]*location(?:\.href)?\s*=\s*["']\/lander["'][^<]*<\/script>\s*<\/head>\s*<\/html>\s*$/i.test(body)) {
|
|
73
|
+
return { state: 'parked' };
|
|
74
|
+
}
|
|
75
|
+
const html = body.replace(/<!--[\s\S]*?(?:-->|$)|<(script|style|noscript)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)/gi, ' ');
|
|
76
|
+
const title = decodeText(html.match(/<title\b[^>]*>([^<]*)<\/title\s*>/i)?.[1] ?? '').slice(0, 140);
|
|
77
|
+
const text = decodeText(html.replace(/<[^>]*>/g, ' '));
|
|
78
|
+
if (saleText.test(text)) return { state: 'for-sale' };
|
|
79
|
+
if (parkedText.test(text) || (detailed && /^(?:domain )?parking page$/i.test(title))) return { state: 'parked' };
|
|
80
|
+
if (!text || errorText.test(title)) return { state: 'no-site' };
|
|
81
|
+
if (detailed) {
|
|
82
|
+
const meta = [...html.matchAll(/<meta\b((?:"[^"]*"|'[^']*'|[^'">])*)>/gi)].map(match =>
|
|
83
|
+
Object.fromEntries([...match[1].matchAll(/([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g)]
|
|
84
|
+
.map(([, key, double, single, bare]) => [key.toLowerCase(), double ?? single ?? bare])));
|
|
85
|
+
const description = meta.find(tag => tag.name?.toLowerCase() === 'description')?.content
|
|
86
|
+
|| meta.find(tag => tag.property?.toLowerCase() === 'og:description')?.content;
|
|
87
|
+
// The newest year next to a copyright sign; a stale year is one dormant-site signal.
|
|
88
|
+
const years = [...text.matchAll(/(?:©|\(c\)|copyright)\s*(?:[^\d\s]{0,3}\s*)?(?:(?:19|20)\d{2}\s*[-–]\s*)?((?:19|20)\d{2})/gi)]
|
|
89
|
+
.map(match => Number(match[1]));
|
|
90
|
+
const modified = Date.parse(lastModified);
|
|
91
|
+
return { state: 'live', title, description: decodeText(description ?? '').slice(0, 300), host,
|
|
92
|
+
...(years.length && { copyright: Math.max(...years) }),
|
|
93
|
+
...(Number.isFinite(modified) && { lastModified: new Date(modified).getUTCFullYear() }) };
|
|
94
|
+
}
|
|
95
|
+
return { state: 'live', ...(title && { title }) };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function load(url, signal) {
|
|
99
|
+
return new Promise((resolve, reject) => {
|
|
100
|
+
const request = url.protocol === 'https:' ? httpsGet : httpGet;
|
|
101
|
+
request(url, { lookup: lookupPublic(signal), signal, agent: false, headers: { accept: 'text/html, application/xhtml+xml' } }, response => {
|
|
102
|
+
const { statusCode: status, headers } = response;
|
|
103
|
+
const contentType = headers['content-type'];
|
|
104
|
+
const location = [301, 302, 303, 307, 308].includes(status) ? headers.location : null;
|
|
105
|
+
if (location || !(status >= 200 && status < 300) || !/^text\/html\b|^application\/xhtml\+xml\b/i.test(contentType)) {
|
|
106
|
+
resolve({ status, contentType, location });
|
|
107
|
+
response.destroy();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
const chunks = [];
|
|
111
|
+
let size = 0;
|
|
112
|
+
function finish() {
|
|
113
|
+
resolve({ status, contentType, lastModified: headers['last-modified'], body: Buffer.concat(chunks).toString('utf8') });
|
|
114
|
+
}
|
|
115
|
+
response.on('data', chunk => {
|
|
116
|
+
const part = chunk.subarray(0, maxBytes - size);
|
|
117
|
+
chunks.push(part);
|
|
118
|
+
size += part.length;
|
|
119
|
+
if (size >= maxBytes) {
|
|
120
|
+
finish();
|
|
121
|
+
response.destroy();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
response.on('end', finish);
|
|
125
|
+
response.on('error', reject);
|
|
126
|
+
}).on('error', reject);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function visit(url, signal, detailed) {
|
|
131
|
+
try {
|
|
132
|
+
for (let hops = 0; hops <= 5; hops++) {
|
|
133
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.port ||
|
|
134
|
+
isIP(url.hostname) || url.hostname.startsWith('[') || !url.hostname.includes('.')) break;
|
|
135
|
+
const response = await load(url, signal);
|
|
136
|
+
if (!response.location) return classifyComSite({ url, ...response }, detailed);
|
|
137
|
+
url = new URL(response.location, url);
|
|
138
|
+
}
|
|
139
|
+
} catch { /* The site did not respond within the public lookup. */ }
|
|
140
|
+
return { state: 'no-site' };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function checkDomainSite(domain, timeout = 5000, detailed = false) {
|
|
144
|
+
if (!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.(?:com|ai|io|app|dev|me|si|co|no|so)$/.test(domain)) return { state: 'no-site' };
|
|
145
|
+
const controller = new AbortController();
|
|
146
|
+
const signal = anySignal([controller.signal, AbortSignal.timeout(timeout)]);
|
|
147
|
+
const https = visit(new URL('https://' + domain), signal, detailed);
|
|
148
|
+
if (/\.(?:app|dev)$/.test(domain)) return https;
|
|
149
|
+
const http = visit(new URL('http://' + domain), signal, detailed);
|
|
150
|
+
const first = await Promise.race([http, https]);
|
|
151
|
+
if (first.state !== 'no-site') {
|
|
152
|
+
controller.abort();
|
|
153
|
+
return first;
|
|
154
|
+
}
|
|
155
|
+
const [secure, plain] = await Promise.all([https, http]);
|
|
156
|
+
return secure.state === 'no-site' ? plain : secure;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const checkComSite = checkDomainSite;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { cacheDir, readCache, writeCache } from './cache.mjs';
|
|
2
|
+
import { compactText, day, letters, oneEdit, readJson } from './triage-sources.mjs';
|
|
3
|
+
|
|
4
|
+
const brreg = 'https://data.brreg.no/enhetsregisteret/api/enheter';
|
|
5
|
+
const edgar = 'https://www.sec.gov/files/company_tickers_exchange.json';
|
|
6
|
+
const legalSuffix = /[\s,]+(?:asa?|aps|ans|da|enk|nuf|incorporated|inc|llc|llp|limited|ltd|corp(?:oration)?|plc|gmbh|aktiengesellschaft|ab|ag|oyj?|bv|n\.v|s\.a|se|co)\.?$/i;
|
|
7
|
+
const companyDescriptor = /[\s,]+(?:group|holding[s]?|laboratories|labs|technologies|ventures|capital|partners|international)$/i;
|
|
8
|
+
|
|
9
|
+
function withoutLegalSuffix(value) {
|
|
10
|
+
let name = String(value ?? '').trim();
|
|
11
|
+
let previous;
|
|
12
|
+
do {
|
|
13
|
+
previous = name;
|
|
14
|
+
name = name.replace(legalSuffix, '').trim();
|
|
15
|
+
} while (name !== previous);
|
|
16
|
+
return name;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function companyKey(value) {
|
|
20
|
+
return letters(withoutLegalSuffix(value));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function companyMatch(name, company) {
|
|
24
|
+
const withoutLegal = withoutLegalSuffix(company);
|
|
25
|
+
const key = letters(withoutLegal);
|
|
26
|
+
if (key === name) return 'exact';
|
|
27
|
+
const short = letters(withoutLegal.replace(companyDescriptor, ''));
|
|
28
|
+
if (short === name || (name.length >= 5 && oneEdit(name, key))) return 'near';
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function searchNorwegianCompanies(name, input, options) {
|
|
33
|
+
const first = await readJson(brreg + '?' + new URLSearchParams({
|
|
34
|
+
navn: input, konkurs: 'false', size: '100', page: '0',
|
|
35
|
+
}), options);
|
|
36
|
+
const pageRows = page => Array.isArray(page?._embedded?.enheter) ? page._embedded.enheter : null;
|
|
37
|
+
if (!Number.isInteger(first?.page?.totalPages) || (first.page.totalPages > 0 && !pageRows(first))) return null;
|
|
38
|
+
const pages = Math.min(3, first.page.totalPages);
|
|
39
|
+
const remaining = await Promise.all(Array.from({ length: Math.max(0, pages - 1) }, (_, index) =>
|
|
40
|
+
readJson(brreg + '?' + new URLSearchParams({
|
|
41
|
+
navn: input, konkurs: 'false', size: '100', page: String(index + 1),
|
|
42
|
+
}), options)));
|
|
43
|
+
const matches = new Map();
|
|
44
|
+
for (const page of [first, ...remaining]) {
|
|
45
|
+
for (const row of pageRows(page) ?? []) {
|
|
46
|
+
if (!row || row.konkurs || row.slettedato || row.underSletting || row.underAvvikling ||
|
|
47
|
+
row.underTvangsavviklingEllerTvangsopplosning || !/^\d{9}$/.test(row.organisasjonsnummer) ||
|
|
48
|
+
typeof row.navn !== 'string') continue;
|
|
49
|
+
const match = companyMatch(letters(name), row.navn);
|
|
50
|
+
if (match) matches.set(row.organisasjonsnummer, {
|
|
51
|
+
name: compactText(row.navn, 65), match, url: 'https://virksomhet.brreg.no/nb/oppslag/enheter/' + row.organisasjonsnummer,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return { matches: [...matches.values()], partial: first.page.totalPages > pages || remaining.some(page => !pageRows(page)) };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function loadEdgarCompanies(options = {}) {
|
|
59
|
+
const { directory = cacheDir, now = new Date() } = options;
|
|
60
|
+
const filename = 'triage-edgar-exchanges.json';
|
|
61
|
+
const cached = await readCache(directory, filename);
|
|
62
|
+
const age = now.getTime() - cached?.at;
|
|
63
|
+
if (age >= 0 && age < day && Array.isArray(cached.companies)) return cached.companies;
|
|
64
|
+
const declaredAgent = process.env.DOMAIN_HOUND_SEC_USER_AGENT;
|
|
65
|
+
const data = await readJson(edgar, options, declaredAgent ? { headers: { 'User-Agent': declaredAgent } } : {});
|
|
66
|
+
if (!Array.isArray(data?.fields) || !Array.isArray(data?.data)) return null;
|
|
67
|
+
const indices = ['cik', 'name', 'ticker', 'exchange'].map(field => data.fields.indexOf(field));
|
|
68
|
+
if (indices.includes(-1)) return null;
|
|
69
|
+
const companies = new Map();
|
|
70
|
+
for (const row of data.data) {
|
|
71
|
+
if (!Array.isArray(row)) continue;
|
|
72
|
+
const [cik, name, ticker, exchange] = indices.map(index => row[index]);
|
|
73
|
+
if (/^\d{1,10}$/.test(cik) && typeof name === 'string' && ticker && exchange && exchange !== 'OTC') {
|
|
74
|
+
companies.set(cik, { cik, name });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const result = [...companies.values()];
|
|
78
|
+
await writeCache(directory, filename, { at: now.getTime(), companies: result }).catch(() => {});
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function matchEdgarCompanies(name, companies) {
|
|
83
|
+
if (!companies) return null;
|
|
84
|
+
const matches = companies.flatMap(row => {
|
|
85
|
+
const match = companyMatch(letters(name), row.name);
|
|
86
|
+
return match ? [{ name: compactText(row.name, 65), match,
|
|
87
|
+
url: 'https://www.sec.gov/edgar/browse/?CIK=' + row.cik }] : [];
|
|
88
|
+
});
|
|
89
|
+
return { matches, partial: false };
|
|
90
|
+
}
|