openrich 0.0.0-stage → 0.1.0
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/.env.example +23 -0
- package/LICENSE +21 -0
- package/README.md +410 -2
- package/assets/logo.svg +41 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +144 -0
- package/dist/env.d.ts +5 -0
- package/dist/env.js +24 -0
- package/dist/eval.d.ts +30 -0
- package/dist/eval.js +78 -0
- package/dist/mcp/client.d.ts +31 -0
- package/dist/mcp/client.js +94 -0
- package/dist/mcp/oauth.d.ts +13 -0
- package/dist/mcp/oauth.js +93 -0
- package/dist/mcp/server.d.ts +87 -0
- package/dist/mcp/server.js +125 -0
- package/dist/merge.d.ts +7 -0
- package/dist/merge.js +39 -0
- package/dist/providers/devplatforms.d.ts +34 -0
- package/dist/providers/devplatforms.js +612 -0
- package/dist/providers/finders.d.ts +38 -0
- package/dist/providers/finders.js +708 -0
- package/dist/providers/freetier.d.ts +9 -0
- package/dist/providers/freetier.js +254 -0
- package/dist/providers/github.d.ts +8 -0
- package/dist/providers/github.js +109 -0
- package/dist/providers/identity.d.ts +5 -0
- package/dist/providers/identity.js +62 -0
- package/dist/providers/index.d.ts +10 -0
- package/dist/providers/index.js +68 -0
- package/dist/providers/knowledge.d.ts +52 -0
- package/dist/providers/knowledge.js +302 -0
- package/dist/providers/pattern.d.ts +6 -0
- package/dist/providers/pattern.js +99 -0
- package/dist/providers/registries.d.ts +36 -0
- package/dist/providers/registries.js +396 -0
- package/dist/providers/research.d.ts +30 -0
- package/dist/providers/research.js +471 -0
- package/dist/providers/signals.d.ts +15 -0
- package/dist/providers/signals.js +116 -0
- package/dist/providers/smtp.d.ts +25 -0
- package/dist/providers/smtp.js +97 -0
- package/dist/providers/social.d.ts +37 -0
- package/dist/providers/social.js +657 -0
- package/dist/providers/verifiers.d.ts +47 -0
- package/dist/providers/verifiers.js +455 -0
- package/dist/providers/websearch.d.ts +32 -0
- package/dist/providers/websearch.js +346 -0
- package/dist/router.d.ts +31 -0
- package/dist/router.js +214 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +52 -0
- package/dist/store.d.ts +32 -0
- package/dist/store.js +95 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.js +1 -0
- package/dist/util/http.d.ts +19 -0
- package/dist/util/http.js +34 -0
- package/dist/util/match.d.ts +23 -0
- package/dist/util/match.js +72 -0
- package/dist/util/names.d.ts +11 -0
- package/dist/util/names.js +56 -0
- package/dist/util/patterns.d.ts +14 -0
- package/dist/util/patterns.js +61 -0
- package/package.json +55 -4
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { getJson, UA } from "../util/http.js";
|
|
3
|
+
import { sameName, mentionsCompany } from "../util/match.js";
|
|
4
|
+
import { slug } from "../util/names.js";
|
|
5
|
+
import { detectPattern } from "../util/patterns.js";
|
|
6
|
+
import { sha256, userIdsFromArmored } from "./signals.js";
|
|
7
|
+
/**
|
|
8
|
+
* Keyless public sources: social profiles (Bluesky, Mastodon, Medium), domain-controlled
|
|
9
|
+
* signals (WKD, WebFinger, NIP-05, humans.txt) and the company's own team page.
|
|
10
|
+
* Rule everywhere: no finding unless the match rule holds. Wrong-person data is worse than none.
|
|
11
|
+
*/
|
|
12
|
+
// ---------- small helpers ----------
|
|
13
|
+
/** fetch that turns network errors and timeouts into null (optional URLs are misses, not errors). */
|
|
14
|
+
async function tryFetch(ctx, url, init = {}, timeoutMs = 10000) {
|
|
15
|
+
try {
|
|
16
|
+
return await ctx.fetch(url, {
|
|
17
|
+
...init,
|
|
18
|
+
headers: { 'User-Agent': UA, ...init.headers },
|
|
19
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Read a body up to maxBytes (pages can be huge). */
|
|
27
|
+
async function readCapped(res, maxBytes = 1_000_000) {
|
|
28
|
+
if (!res.body)
|
|
29
|
+
return new Uint8Array(await res.arrayBuffer()).subarray(0, maxBytes);
|
|
30
|
+
const reader = res.body.getReader();
|
|
31
|
+
const chunks = [];
|
|
32
|
+
let n = 0;
|
|
33
|
+
while (n < maxBytes) {
|
|
34
|
+
const { done, value } = await reader.read();
|
|
35
|
+
if (done)
|
|
36
|
+
break;
|
|
37
|
+
chunks.push(value);
|
|
38
|
+
n += value.length;
|
|
39
|
+
}
|
|
40
|
+
if (n >= maxBytes)
|
|
41
|
+
await reader.cancel().catch(() => { });
|
|
42
|
+
const out = new Uint8Array(Math.min(n, maxBytes));
|
|
43
|
+
let o = 0;
|
|
44
|
+
for (const c of chunks) {
|
|
45
|
+
const take = Math.min(c.length, out.length - o);
|
|
46
|
+
out.set(c.subarray(0, take), o);
|
|
47
|
+
o += take;
|
|
48
|
+
if (o >= out.length)
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
async function textCapped(res, maxBytes = 1_000_000) {
|
|
54
|
+
return new TextDecoder().decode(await readCapped(res, maxBytes));
|
|
55
|
+
}
|
|
56
|
+
const ENTITIES = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ', ndash: '–', mdash: '—', middot: '·', bull: '•', rsquo: '’', lsquo: '‘' };
|
|
57
|
+
export function decodeEntities(s) {
|
|
58
|
+
return s.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (m, e) => {
|
|
59
|
+
if (e[0] === '#') {
|
|
60
|
+
const cp = e[1] === 'x' || e[1] === 'X' ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10);
|
|
61
|
+
return Number.isFinite(cp) && cp > 0 && cp < 0x110000 ? String.fromCodePoint(cp) : m;
|
|
62
|
+
}
|
|
63
|
+
return ENTITIES[e.toLowerCase()] ?? m;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function stripHtml(s) {
|
|
67
|
+
return decodeEntities(s.replace(/<br\s*\/?>/gi, '\n').replace(/<\/p>/gi, '\n').replace(/<[^>]+>/g, ''))
|
|
68
|
+
.replace(/[ \t]+/g, ' ')
|
|
69
|
+
.trim();
|
|
70
|
+
}
|
|
71
|
+
/** Lowercased, deduped emails worth checking: q.email first, then router candidates. */
|
|
72
|
+
function emailsToCheck(q, max = 3) {
|
|
73
|
+
const all = [q.email, ...(q.emailCandidates ?? [])].filter((e) => Boolean(e && e.includes('@')));
|
|
74
|
+
return [...new Set(all.map((e) => e.trim().toLowerCase()))].slice(0, max);
|
|
75
|
+
}
|
|
76
|
+
function hostOf(url) {
|
|
77
|
+
try {
|
|
78
|
+
return new URL(url.startsWith('http') ? url : `https://${url}`).hostname.toLowerCase().replace(/^www\./, '');
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function onDomain(host, domain) {
|
|
85
|
+
if (!host || !domain)
|
|
86
|
+
return false;
|
|
87
|
+
return host === domain || host.endsWith(`.${domain}`);
|
|
88
|
+
}
|
|
89
|
+
/** Does an email local part plausibly belong to this person (pattern of first/last name)? */
|
|
90
|
+
function localPartMatches(email, q) {
|
|
91
|
+
if (!q.firstName || !q.lastName)
|
|
92
|
+
return false;
|
|
93
|
+
if (detectPattern(email, q.firstName, q.lastName))
|
|
94
|
+
return true;
|
|
95
|
+
const local = slug(email.split('@')[0]);
|
|
96
|
+
const last = slug(q.lastName);
|
|
97
|
+
return last.length >= 3 && local.includes(last);
|
|
98
|
+
}
|
|
99
|
+
// ---------- z-base-32 (RFC 6189 alphabet, used by WKD) ----------
|
|
100
|
+
const ZB32 = 'ybndrfg8ejkmcpqxot1uwisza345h769';
|
|
101
|
+
export function zbase32(buf) {
|
|
102
|
+
let out = '';
|
|
103
|
+
let bits = 0;
|
|
104
|
+
let acc = 0;
|
|
105
|
+
for (const b of buf) {
|
|
106
|
+
acc = (acc << 8) | b;
|
|
107
|
+
bits += 8;
|
|
108
|
+
while (bits >= 5) {
|
|
109
|
+
out += ZB32[(acc >>> (bits - 5)) & 31];
|
|
110
|
+
bits -= 5;
|
|
111
|
+
}
|
|
112
|
+
acc &= (1 << bits) - 1;
|
|
113
|
+
}
|
|
114
|
+
if (bits > 0)
|
|
115
|
+
out += ZB32[(acc << (5 - bits)) & 31];
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
/** WKD hashed local part: z-base-32(SHA-1(lowercase local part)). */
|
|
119
|
+
export function wkdHash(localPart) {
|
|
120
|
+
return zbase32(createHash('sha1').update(localPart.toLowerCase()).digest());
|
|
121
|
+
}
|
|
122
|
+
// ---------- bech32 (for nostr npub) ----------
|
|
123
|
+
const BECH = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
|
|
124
|
+
function bech32Polymod(values) {
|
|
125
|
+
const G = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
|
|
126
|
+
let chk = 1;
|
|
127
|
+
for (const v of values) {
|
|
128
|
+
const top = chk >>> 25;
|
|
129
|
+
chk = ((chk & 0x1ffffff) << 5) ^ v;
|
|
130
|
+
for (let i = 0; i < 5; i++)
|
|
131
|
+
if ((top >>> i) & 1)
|
|
132
|
+
chk ^= G[i];
|
|
133
|
+
}
|
|
134
|
+
return chk;
|
|
135
|
+
}
|
|
136
|
+
export function npub(hex) {
|
|
137
|
+
const bytes = Buffer.from(hex, 'hex');
|
|
138
|
+
const data = [];
|
|
139
|
+
let acc = 0;
|
|
140
|
+
let bits = 0;
|
|
141
|
+
for (const b of bytes) {
|
|
142
|
+
acc = (acc << 8) | b;
|
|
143
|
+
bits += 8;
|
|
144
|
+
while (bits >= 5) {
|
|
145
|
+
data.push((acc >>> (bits - 5)) & 31);
|
|
146
|
+
bits -= 5;
|
|
147
|
+
}
|
|
148
|
+
acc &= (1 << bits) - 1;
|
|
149
|
+
}
|
|
150
|
+
if (bits > 0)
|
|
151
|
+
data.push((acc << (5 - bits)) & 31);
|
|
152
|
+
const hrp = 'npub';
|
|
153
|
+
const exp = [...[...hrp].map((c) => c.charCodeAt(0) >> 5), 0, ...[...hrp].map((c) => c.charCodeAt(0) & 31)];
|
|
154
|
+
const mod = bech32Polymod([...exp, ...data, 0, 0, 0, 0, 0, 0]) ^ 1;
|
|
155
|
+
const chk = Array.from({ length: 6 }, (_, i) => (mod >>> (5 * (5 - i))) & 31);
|
|
156
|
+
return `${hrp}1${[...data, ...chk].map((d) => BECH[d]).join('')}`;
|
|
157
|
+
}
|
|
158
|
+
// ---------- 1. Bluesky ----------
|
|
159
|
+
export const blueskyProvider = {
|
|
160
|
+
id: 'bluesky',
|
|
161
|
+
kind: 'free',
|
|
162
|
+
description: 'Bluesky public profile (handle on the company domain, or name + company in bio)',
|
|
163
|
+
provides: ['profile', 'bio', 'photo', 'website'],
|
|
164
|
+
needs: (q) => Boolean(q.name && (q.domain || q.company)),
|
|
165
|
+
async run(q, ctx) {
|
|
166
|
+
const url = `https://public.api.bsky.app/xrpc/app.bsky.actor.searchActors?q=${encodeURIComponent(q.name)}&limit=25`;
|
|
167
|
+
const r = await getJson(ctx.fetch, url, { headers: { 'User-Agent': UA } }, 10000);
|
|
168
|
+
const actors = r.data?.actors ?? [];
|
|
169
|
+
const last = slug(q.lastName ?? '');
|
|
170
|
+
let best = null;
|
|
171
|
+
for (const a of actors) {
|
|
172
|
+
const handle = String(a.handle ?? '').toLowerCase();
|
|
173
|
+
const name = sameName(a.displayName, q.name, true);
|
|
174
|
+
const label = slug(handle.split('.')[0]);
|
|
175
|
+
// Handles are DNS-verified: a handle on the company domain was granted by the domain owner.
|
|
176
|
+
if (onDomain(handle, q.domain) && (name || (last.length >= 3 && label.includes(last)))) {
|
|
177
|
+
const c = { a, conf: 0.9, why: `handle ${handle} on ${q.domain}` };
|
|
178
|
+
if (!best || best.conf < c.conf)
|
|
179
|
+
best = c;
|
|
180
|
+
}
|
|
181
|
+
else if (name && mentionsCompany(a.description, q)) {
|
|
182
|
+
const c = { a, conf: 0.7, why: 'display name matches, bio mentions company' };
|
|
183
|
+
if (!best)
|
|
184
|
+
best = c;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!best)
|
|
188
|
+
return [];
|
|
189
|
+
const { a, conf, why } = best;
|
|
190
|
+
const handle = String(a.handle).toLowerCase();
|
|
191
|
+
const out = [{ field: 'profile', value: `https://bsky.app/profile/${handle}`, source: 'bluesky', confidence: conf, evidence: why }];
|
|
192
|
+
if (a.description?.trim())
|
|
193
|
+
out.push({ field: 'bio', value: a.description.trim(), source: 'bluesky', confidence: conf - 0.1 });
|
|
194
|
+
if (a.avatar)
|
|
195
|
+
out.push({ field: 'photo', value: a.avatar, source: 'bluesky', confidence: conf - 0.1 });
|
|
196
|
+
// A custom-domain handle the person owns is their website (not when it is just a company subdomain).
|
|
197
|
+
if (!handle.endsWith('.bsky.social') && !onDomain(handle, q.domain)) {
|
|
198
|
+
out.push({ field: 'website', value: `https://${handle}`, source: 'bluesky', confidence: conf - 0.1, evidence: 'DNS-verified handle' });
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
// ---------- 2. Mastodon / fediverse ----------
|
|
204
|
+
function verifiedLinks(fields) {
|
|
205
|
+
return (fields ?? [])
|
|
206
|
+
.filter((f) => f?.verified_at)
|
|
207
|
+
.map((f) => String(f.value ?? '').match(/href="([^"]+)"/)?.[1])
|
|
208
|
+
.filter((u) => Boolean(u));
|
|
209
|
+
}
|
|
210
|
+
function linksToKnown(url, q) {
|
|
211
|
+
const host = hostOf(url);
|
|
212
|
+
if (onDomain(host, q.domain))
|
|
213
|
+
return true;
|
|
214
|
+
if (q.github && host === 'github.com') {
|
|
215
|
+
const login = url.replace(/^https?:\/\/(www\.)?github\.com\//i, '').split(/[/?#]/)[0];
|
|
216
|
+
return login.toLowerCase() === q.github.toLowerCase();
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
async function fediverseFindings(q, acct, why, conf) {
|
|
221
|
+
const out = [{ field: 'profile', value: acct.url, source: 'mastodon', confidence: conf, evidence: why }];
|
|
222
|
+
const bio = acct.note ? stripHtml(acct.note) : acct.summary ? stripHtml(acct.summary) : '';
|
|
223
|
+
if (bio)
|
|
224
|
+
out.push({ field: 'bio', value: bio, source: 'mastodon', confidence: 0.6 });
|
|
225
|
+
const photo = acct.avatar ?? acct.icon?.url;
|
|
226
|
+
if (photo && !/missing\.png$/.test(photo))
|
|
227
|
+
out.push({ field: 'photo', value: photo, source: 'mastodon', confidence: 0.6 });
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
export const mastodonProvider = {
|
|
231
|
+
id: 'mastodon',
|
|
232
|
+
kind: 'free',
|
|
233
|
+
description: 'Mastodon: WebFinger on the company domain, or mastodon.social search with verified rel=me links',
|
|
234
|
+
provides: ['profile', 'bio', 'photo'],
|
|
235
|
+
needs: (q) => Boolean(q.name && (q.domain || q.github)),
|
|
236
|
+
async run(q, ctx) {
|
|
237
|
+
// a) The company runs its own fediverse server: acct:<local>@domain for name-shaped local parts.
|
|
238
|
+
if (q.domain) {
|
|
239
|
+
const locals = emailsToCheck(q)
|
|
240
|
+
.filter((e) => e.endsWith(`@${q.domain}`) && localPartMatches(e, q))
|
|
241
|
+
.map((e) => e.split('@')[0]);
|
|
242
|
+
for (const local of locals) {
|
|
243
|
+
const wf = await tryFetch(ctx, `https://${q.domain}/.well-known/webfinger?resource=${encodeURIComponent(`acct:${local}@${q.domain}`)}`, { headers: { Accept: 'application/jrd+json' } }, 8000);
|
|
244
|
+
if (!wf)
|
|
245
|
+
break;
|
|
246
|
+
// No fediverse server on this domain (HTML 404 page, homepage redirect): stop after one request.
|
|
247
|
+
const body = await textCapped(wf, 100_000);
|
|
248
|
+
let jrd = null;
|
|
249
|
+
try {
|
|
250
|
+
jrd = JSON.parse(body);
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
if (wf.status !== 200)
|
|
256
|
+
continue;
|
|
257
|
+
const self = jrd?.links?.find((l) => l.rel === 'self' && /activity\+json|ld\+json/.test(l.type ?? ''))?.href;
|
|
258
|
+
if (!self)
|
|
259
|
+
continue;
|
|
260
|
+
const ar = await tryFetch(ctx, self, { headers: { Accept: 'application/activity+json' } }, 8000);
|
|
261
|
+
let actor = ar && ar.ok ? await ar.json().catch(() => null) : null;
|
|
262
|
+
let name = actor?.name;
|
|
263
|
+
if (!actor) {
|
|
264
|
+
// Servers with signed fetch refuse the actor; the Mastodon API lookup is public.
|
|
265
|
+
const u = new URL(self);
|
|
266
|
+
const lk = await tryFetch(ctx, `${u.origin}/api/v1/accounts/lookup?acct=${encodeURIComponent(u.pathname.split('/').pop() ?? local)}`, {}, 8000);
|
|
267
|
+
actor = lk && lk.ok ? await lk.json().catch(() => null) : null;
|
|
268
|
+
name = actor?.display_name;
|
|
269
|
+
}
|
|
270
|
+
if (actor && sameName(name, q.name)) {
|
|
271
|
+
return fediverseFindings(q, { ...actor, url: actor.url ?? self }, `acct:${local}@${q.domain} via WebFinger`, 0.9);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// b) mastodon.social account search; only accept a display-name match with a verified link we already trust.
|
|
276
|
+
const r = await getJson(ctx.fetch, `https://mastodon.social/api/v2/search?q=${encodeURIComponent(q.name)}&type=accounts&limit=10`, { headers: { 'User-Agent': UA } }, 10000);
|
|
277
|
+
for (const a of r.data?.accounts ?? []) {
|
|
278
|
+
if (!sameName(a.display_name, q.name))
|
|
279
|
+
continue;
|
|
280
|
+
const link = verifiedLinks(a.fields).find((u) => linksToKnown(u, q));
|
|
281
|
+
if (link)
|
|
282
|
+
return fediverseFindings(q, a, `verified rel=me link to ${link}`, 0.85);
|
|
283
|
+
}
|
|
284
|
+
return [];
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
// ---------- 3. OpenPGP Web Key Directory ----------
|
|
288
|
+
/** Fetch a WKD key for an address (advanced then direct method). Returns user IDs, or null on miss. */
|
|
289
|
+
export async function wkdLookup(ctx, email) {
|
|
290
|
+
const [local, domain] = email.toLowerCase().split('@');
|
|
291
|
+
if (!local || !domain)
|
|
292
|
+
return null;
|
|
293
|
+
const h = wkdHash(local);
|
|
294
|
+
const l = encodeURIComponent(local);
|
|
295
|
+
const urls = [
|
|
296
|
+
`https://openpgpkey.${domain}/.well-known/openpgpkey/${domain}/hu/${h}?l=${l}`,
|
|
297
|
+
`https://${domain}/.well-known/openpgpkey/hu/${h}?l=${l}`,
|
|
298
|
+
];
|
|
299
|
+
for (const url of urls) {
|
|
300
|
+
const res = await tryFetch(ctx, url, {}, 8000);
|
|
301
|
+
if (!res || res.status !== 200)
|
|
302
|
+
continue;
|
|
303
|
+
const ct = res.headers.get('content-type') ?? '';
|
|
304
|
+
if (/text\/html/i.test(ct))
|
|
305
|
+
continue; // catch-all web servers
|
|
306
|
+
const bin = await readCapped(res, 500_000);
|
|
307
|
+
if (!bin.length || !(bin[0] & 0x80))
|
|
308
|
+
continue; // not an OpenPGP packet stream
|
|
309
|
+
const uids = userIdsFromArmored(Buffer.from(bin).toString('base64'));
|
|
310
|
+
if (uids.length)
|
|
311
|
+
return uids;
|
|
312
|
+
}
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
export const wkdProvider = {
|
|
316
|
+
id: 'wkd',
|
|
317
|
+
kind: 'free',
|
|
318
|
+
description: 'OpenPGP Web Key Directory: the email domain published a key for this exact address',
|
|
319
|
+
provides: ['email', 'name'],
|
|
320
|
+
needs: (q) => emailsToCheck(q).length > 0,
|
|
321
|
+
async run(q, ctx) {
|
|
322
|
+
const out = [];
|
|
323
|
+
for (const email of emailsToCheck(q)) {
|
|
324
|
+
const uids = await wkdLookup(ctx, email);
|
|
325
|
+
if (!uids)
|
|
326
|
+
continue;
|
|
327
|
+
const mine = uids.filter((u) => u.toLowerCase().includes(`<${email}>`) || u.toLowerCase() === email);
|
|
328
|
+
if (!mine.length)
|
|
329
|
+
continue;
|
|
330
|
+
const names = mine.map((u) => u.match(/^([^<]+?)\s*</)?.[1]).filter((n) => Boolean(n));
|
|
331
|
+
// A named key for someone else at this address means the guess is the wrong person.
|
|
332
|
+
if (q.name && names.length && !names.some((n) => sameName(n, q.name, true)))
|
|
333
|
+
continue;
|
|
334
|
+
out.push({ field: 'email', value: email, source: 'wkd', confidence: 0.9, evidence: 'domain publishes an OpenPGP key for this address (WKD)' });
|
|
335
|
+
const n = names.find((x) => !q.name || sameName(x, q.name, true));
|
|
336
|
+
if (n)
|
|
337
|
+
out.push({ field: 'name', value: n, source: 'wkd', confidence: 0.8 });
|
|
338
|
+
break;
|
|
339
|
+
}
|
|
340
|
+
return out;
|
|
341
|
+
},
|
|
342
|
+
};
|
|
343
|
+
// ---------- 4. Libravatar ----------
|
|
344
|
+
export const libravatarProvider = {
|
|
345
|
+
id: 'libravatar',
|
|
346
|
+
kind: 'free',
|
|
347
|
+
description: 'Libravatar: an avatar is registered for this email (exists signal)',
|
|
348
|
+
provides: ['email', 'photo'],
|
|
349
|
+
needs: (q) => emailsToCheck(q).length > 0,
|
|
350
|
+
async run(q, ctx) {
|
|
351
|
+
for (const email of emailsToCheck(q)) {
|
|
352
|
+
const url = `https://seccdn.libravatar.org/avatar/${sha256(email)}?d=404&s=200`;
|
|
353
|
+
const res = await tryFetch(ctx, url, {}, 8000);
|
|
354
|
+
if (!res || res.status !== 200 || !/^image\//.test(res.headers.get('content-type') ?? ''))
|
|
355
|
+
continue;
|
|
356
|
+
await res.body?.cancel().catch(() => { });
|
|
357
|
+
return [
|
|
358
|
+
{ field: 'email', value: email, source: 'libravatar', confidence: 0.5, evidence: 'libravatar avatar registered' },
|
|
359
|
+
{ field: 'photo', value: url.replace('?d=404&s=200', '?s=200'), source: 'libravatar', confidence: 0.5 },
|
|
360
|
+
];
|
|
361
|
+
}
|
|
362
|
+
return [];
|
|
363
|
+
},
|
|
364
|
+
};
|
|
365
|
+
// ---------- 5. Nostr NIP-05 ----------
|
|
366
|
+
export const nostrProvider = {
|
|
367
|
+
id: 'nostr-nip05',
|
|
368
|
+
kind: 'free',
|
|
369
|
+
description: 'Nostr NIP-05: the company domain vouches for a name-shaped identifier',
|
|
370
|
+
provides: ['profile'],
|
|
371
|
+
needs: (q) => Boolean(q.domain && q.lastName && nostrLocals(q).length),
|
|
372
|
+
async run(q, ctx) {
|
|
373
|
+
const locals = nostrLocals(q);
|
|
374
|
+
const res = await tryFetch(ctx, `https://${q.domain}/.well-known/nostr.json?name=${encodeURIComponent(locals[0])}`, {}, 8000);
|
|
375
|
+
if (!res || res.status !== 200)
|
|
376
|
+
return [];
|
|
377
|
+
const j = await res.json().catch(() => null);
|
|
378
|
+
const names = j?.names && typeof j.names === 'object' ? j.names : {};
|
|
379
|
+
// Servers often return all names at once, so one request covers every candidate.
|
|
380
|
+
for (const local of locals) {
|
|
381
|
+
const pk = names[local];
|
|
382
|
+
if (typeof pk === 'string' && /^[0-9a-f]{64}$/i.test(pk)) {
|
|
383
|
+
return [{ field: 'profile', value: `https://njump.me/${npub(pk.toLowerCase())}`, source: 'nostr-nip05', confidence: 0.6, evidence: `${local}@${q.domain} (NIP-05)` }];
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return [];
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
function nostrLocals(q) {
|
|
390
|
+
const out = new Set();
|
|
391
|
+
// Only identifiers that contain the last name: "jack@..." on a shared host could be anyone.
|
|
392
|
+
const last = slug(q.lastName ?? '');
|
|
393
|
+
for (const e of emailsToCheck(q))
|
|
394
|
+
if (q.domain && e.endsWith(`@${q.domain}`) && last.length >= 3 && slug(e.split('@')[0]).includes(last))
|
|
395
|
+
out.add(e.split('@')[0]);
|
|
396
|
+
for (const u of q.usernames ?? [])
|
|
397
|
+
if (last.length >= 3 && slug(u).includes(last))
|
|
398
|
+
out.add(u.toLowerCase());
|
|
399
|
+
return [...out].slice(0, 4);
|
|
400
|
+
}
|
|
401
|
+
/** Find the person's block in a humans.txt and pull role, contact, twitter and location from it. */
|
|
402
|
+
export function parseHumansTxt(txt, name) {
|
|
403
|
+
const blocks = txt.replace(/\r/g, '').split(/\n\s*\n|\/\*[^*]*\*\//);
|
|
404
|
+
for (const block of blocks) {
|
|
405
|
+
const lines = block.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
406
|
+
const kv = lines.map((l) => {
|
|
407
|
+
const m = l.match(/^([^:]{1,40}):\s*(.+)$/);
|
|
408
|
+
return m ? { k: m[1].trim().toLowerCase(), v: m[2].trim() } : { k: '', v: l };
|
|
409
|
+
});
|
|
410
|
+
const hit = kv.find((x) => sameName(x.v, name));
|
|
411
|
+
if (!hit)
|
|
412
|
+
continue;
|
|
413
|
+
const e = {};
|
|
414
|
+
const get = (re) => kv.find((x) => re.test(x.k))?.v;
|
|
415
|
+
const role = get(/^(role|title|position|job)/);
|
|
416
|
+
if (role)
|
|
417
|
+
e.title = role;
|
|
418
|
+
else if (hit.k && !/^(name|author|team|member|people)/.test(hit.k))
|
|
419
|
+
e.title = hit.k.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
420
|
+
const contact = get(/^(contact|e-?mail|mail)/);
|
|
421
|
+
if (contact) {
|
|
422
|
+
const em = contact.replace(/\s*[[(]\s*at\s*[\])]\s*/gi, '@').replace(/\s*[[(]\s*dot\s*[\])]\s*/gi, '.').match(/[\w.+-]+@[\w-]+(\.[\w-]+)+/);
|
|
423
|
+
if (em)
|
|
424
|
+
e.email = em[0].toLowerCase();
|
|
425
|
+
}
|
|
426
|
+
const tw = get(/^twitter|^x$/)?.match(/@?([A-Za-z0-9_]{1,15})\b/)?.[1];
|
|
427
|
+
if (tw)
|
|
428
|
+
e.twitter = `https://x.com/${tw}`;
|
|
429
|
+
const loc = get(/^(location|from|city|based)/);
|
|
430
|
+
if (loc)
|
|
431
|
+
e.location = loc;
|
|
432
|
+
return e;
|
|
433
|
+
}
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
export const humansTxtProvider = {
|
|
437
|
+
id: 'humans-txt',
|
|
438
|
+
kind: 'free',
|
|
439
|
+
description: "The company's humans.txt team list",
|
|
440
|
+
provides: ['title', 'email', 'twitter', 'location'],
|
|
441
|
+
needs: (q) => Boolean(q.name && q.lastName && q.domain),
|
|
442
|
+
async run(q, ctx) {
|
|
443
|
+
const res = await tryFetch(ctx, `https://${q.domain}/humans.txt`);
|
|
444
|
+
if (!res || res.status !== 200 || /text\/html/i.test(res.headers.get('content-type') ?? ''))
|
|
445
|
+
return [];
|
|
446
|
+
const e = parseHumansTxt(await textCapped(res, 200_000), q.name);
|
|
447
|
+
if (!e)
|
|
448
|
+
return [];
|
|
449
|
+
const src = 'humans-txt';
|
|
450
|
+
const ev = `${q.domain}/humans.txt`;
|
|
451
|
+
const out = [];
|
|
452
|
+
if (e.title && e.title.length <= 80)
|
|
453
|
+
out.push({ field: 'title', value: e.title, source: src, confidence: 0.6, evidence: ev });
|
|
454
|
+
if (e.email && localPartMatches(e.email, q))
|
|
455
|
+
out.push({ field: 'email', value: e.email, source: src, confidence: 0.85, evidence: ev });
|
|
456
|
+
if (e.twitter)
|
|
457
|
+
out.push({ field: 'twitter', value: e.twitter, source: src, confidence: 0.7, evidence: ev });
|
|
458
|
+
if (e.location)
|
|
459
|
+
out.push({ field: 'location', value: e.location, source: src, confidence: 0.6, evidence: ev });
|
|
460
|
+
return out;
|
|
461
|
+
},
|
|
462
|
+
};
|
|
463
|
+
// ---------- 7. Team / about page ----------
|
|
464
|
+
const TITLE_WORDS = /\b(ceo|cto|cfo|coo|cmo|cio|cpo|cro|ciso|vp|svp|evp|founder|co-?founder|owner|president|chair(man|woman|person)?|director|head|manager|lead|chief|officer|partner|principal|engineer|developer|designer|architect|scientist|analyst|consultant|advisor|adviser|associate|specialist|coordinator|administrator|assistant|executive|editor|writer|counsel|attorney|lawyer|accountant|controller|treasurer|secretary|recruiter|marketing|sales|operations|product|engineering|finance|research(er)?|professor|physician|doctor|dentist|nurse|therapist|agent|broker|realtor|strategist|producer|intern|member|board|investor|general manager|gm|md|managing)\b/i;
|
|
465
|
+
const BLOCK_TAGS = /<\/?(div|p|h[1-6]|li|ul|ol|br|tr|td|th|section|article|header|footer|figure|figcaption|dd|dt|dl|blockquote|table|main|aside|nav|button)\b[^>]*>/gi;
|
|
466
|
+
/** HTML -> lines of text, with links kept as [[url]] markers so we can find a card's mailto/LinkedIn. */
|
|
467
|
+
export function htmlToLines(html) {
|
|
468
|
+
const s = html
|
|
469
|
+
.replace(/<!--[\s\S]*?-->/g, ' ')
|
|
470
|
+
.replace(/<(script|style|svg|noscript|template|head)\b[\s\S]*?<\/\1>/gi, ' ')
|
|
471
|
+
.replace(/<a\b[^>]*?href\s*=\s*["']([^"']+)["'][^>]*>/gi, (_, href) => {
|
|
472
|
+
const h = decodeEntities(href).trim();
|
|
473
|
+
return /^mailto:|linkedin\.com\/in\//i.test(h) ? ` [[${h}]] ` : ' ';
|
|
474
|
+
})
|
|
475
|
+
.replace(BLOCK_TAGS, '\n')
|
|
476
|
+
.replace(/<[^>]+>/g, ' ');
|
|
477
|
+
return decodeEntities(s)
|
|
478
|
+
.split('\n')
|
|
479
|
+
.map((l) => l.replace(/\s+/g, ' ').trim())
|
|
480
|
+
.filter(Boolean);
|
|
481
|
+
}
|
|
482
|
+
function looksLikeTitle(line, name) {
|
|
483
|
+
const t = line.replace(/\[\[[^\]]*\]\]/g, '').trim();
|
|
484
|
+
if (!t || t.length > 70 || t.split(/\s+/).length > 9)
|
|
485
|
+
return false;
|
|
486
|
+
if (sameName(t, name))
|
|
487
|
+
return false;
|
|
488
|
+
return TITLE_WORDS.test(t);
|
|
489
|
+
}
|
|
490
|
+
function cleanTitle(s) {
|
|
491
|
+
return s.replace(/\[\[[^\]]*\]\]/g, '').replace(/^[\s,|:–—-]+|[\s,|:–—-]+$/g, '').trim();
|
|
492
|
+
}
|
|
493
|
+
/** Find the person on a team/about page: nearby job title, and a mailto/LinkedIn in the same card. */
|
|
494
|
+
export function parseTeamPage(html, q) {
|
|
495
|
+
const name = q.name;
|
|
496
|
+
const lines = htmlToLines(html);
|
|
497
|
+
for (let i = 0; i < lines.length; i++) {
|
|
498
|
+
const line = lines[i];
|
|
499
|
+
const plain = line.replace(/\[\[[^\]]*\]\]/g, ' ').trim();
|
|
500
|
+
if (plain.length > 120)
|
|
501
|
+
continue;
|
|
502
|
+
// "Jane Doe", "Jane Doe, CEO", "Jane Doe | Head of Sales", "Jane Doe - Founder"
|
|
503
|
+
const parts = plain.split(/\s+[|–—-]\s+|,\s+|\s*:\s+|\s*·\s*/).map((p) => p.trim()).filter(Boolean);
|
|
504
|
+
const idx = parts.findIndex((p) => p.split(/\s+/).length <= 5 && sameName(p, name));
|
|
505
|
+
if (idx < 0)
|
|
506
|
+
continue;
|
|
507
|
+
const card = {};
|
|
508
|
+
const rest = parts.filter((_, k) => k !== idx).join(', ');
|
|
509
|
+
if (rest && looksLikeTitle(rest, name)) {
|
|
510
|
+
card.title = cleanTitle(rest);
|
|
511
|
+
card.titleConfidence = 0.7;
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
// Card layout: title is usually the next short line; fall back to the line before (lower confidence).
|
|
515
|
+
for (let k = i + 1; k <= i + 2 && k < lines.length; k++) {
|
|
516
|
+
const c = lines[k].replace(/\[\[[^\]]*\]\]/g, '').trim();
|
|
517
|
+
if (!c)
|
|
518
|
+
continue;
|
|
519
|
+
if (looksLikeTitle(c, name)) {
|
|
520
|
+
card.title = cleanTitle(c);
|
|
521
|
+
card.titleConfidence = 0.7;
|
|
522
|
+
break;
|
|
523
|
+
}
|
|
524
|
+
if (c.split(/\s+/).length <= 4 && /^[A-Z][a-z]+ [A-Z]/.test(c))
|
|
525
|
+
break; // next person's name
|
|
526
|
+
}
|
|
527
|
+
if (!card.title && i > 0 && looksLikeTitle(lines[i - 1], name)) {
|
|
528
|
+
card.title = cleanTitle(lines[i - 1]);
|
|
529
|
+
card.titleConfidence = 0.6;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
// Links within ~200 chars around the name; only accept ones that are clearly this person's.
|
|
533
|
+
const before = lines.slice(Math.max(0, i - 3), i).join(' ').slice(-150);
|
|
534
|
+
const after = lines.slice(i, i + 8).join(' ').slice(0, 260 + line.length);
|
|
535
|
+
const first = slug(q.firstName ?? '');
|
|
536
|
+
const last = slug(q.lastName ?? '');
|
|
537
|
+
for (const m of `${before} ${after}`.matchAll(/\[\[([^\]]+)\]\]/g)) {
|
|
538
|
+
const href = m[1];
|
|
539
|
+
if (/^mailto:/i.test(href) && !card.email) {
|
|
540
|
+
const em = decodeURIComponent(href.slice(7).split('?')[0]).trim().toLowerCase();
|
|
541
|
+
if (/^[^@\s]+@[^@\s]+\.[a-z]{2,}$/.test(em) && localPartMatches(em, q))
|
|
542
|
+
card.email = em;
|
|
543
|
+
}
|
|
544
|
+
else if (/linkedin\.com\/in\//i.test(href) && !card.linkedin) {
|
|
545
|
+
const s = slug(href.split(/linkedin\.com\/in\//i)[1].split(/[/?#]/)[0]);
|
|
546
|
+
if ((last.length >= 3 && s.includes(last)) || (first.length >= 3 && s.startsWith(first) && last && s.includes(last[0]))) {
|
|
547
|
+
card.linkedin = href.replace(/^http:/, 'https:').split(/[?#]/)[0];
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (card.title || card.email || card.linkedin)
|
|
552
|
+
return card;
|
|
553
|
+
}
|
|
554
|
+
return null;
|
|
555
|
+
}
|
|
556
|
+
const TEAM_PATHS = ['/team', '/about', '/about-us', '/company', '/people', '/leadership'];
|
|
557
|
+
const TEAM_LINK = /\b(team|people|leadership|staff|management|founders|our-team|meet-the-team|who-we-are)\b/i;
|
|
558
|
+
/** Same-site links that look like a team page (by path or by link text), absolute URLs. */
|
|
559
|
+
export function teamLinks(html, base, domain) {
|
|
560
|
+
const out = new Set();
|
|
561
|
+
for (const m of html.matchAll(/<a\b[^>]*?href\s*=\s*["']([^"'#]+)["'][^>]*>([\s\S]{0,200}?)<\/a>/gi)) {
|
|
562
|
+
const text = m[2].replace(/<[^>]+>/g, ' ');
|
|
563
|
+
let path;
|
|
564
|
+
try {
|
|
565
|
+
const u = new URL(decodeEntities(m[1]), base);
|
|
566
|
+
if (!onDomain(u.hostname.replace(/^www\./, ''), domain))
|
|
567
|
+
continue;
|
|
568
|
+
u.hash = '';
|
|
569
|
+
path = u.toString();
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
if (TEAM_LINK.test(new URL(path).pathname.replace(/[-_/]/g, ' ')) || TEAM_LINK.test(text))
|
|
575
|
+
out.add(path);
|
|
576
|
+
}
|
|
577
|
+
return [...out];
|
|
578
|
+
}
|
|
579
|
+
export const teamPageProvider = {
|
|
580
|
+
id: 'team-page',
|
|
581
|
+
kind: 'free',
|
|
582
|
+
description: "The company's own team / about page: job title, email and LinkedIn next to the person's name",
|
|
583
|
+
provides: ['title', 'email', 'linkedin'],
|
|
584
|
+
needs: (q) => Boolean(q.name && q.lastName && q.domain),
|
|
585
|
+
async run(q, ctx) {
|
|
586
|
+
const queue = TEAM_PATHS.map((p) => `https://${q.domain}${p}`);
|
|
587
|
+
const seen = new Set();
|
|
588
|
+
let requests = 0;
|
|
589
|
+
let okPages = 0;
|
|
590
|
+
while (queue.length && requests < 6 && okPages < 3) {
|
|
591
|
+
const url = queue.shift();
|
|
592
|
+
if (seen.has(url))
|
|
593
|
+
continue;
|
|
594
|
+
seen.add(url);
|
|
595
|
+
requests++;
|
|
596
|
+
const res = await tryFetch(ctx, url, { headers: { Accept: 'text/html' } });
|
|
597
|
+
if (!res || res.status !== 200 || !/html/i.test(res.headers.get('content-type') ?? 'text/html'))
|
|
598
|
+
continue;
|
|
599
|
+
const finalUrl = res.url || url;
|
|
600
|
+
if ((finalUrl !== url && seen.has(finalUrl)) || !onDomain(hostOf(finalUrl), q.domain)) {
|
|
601
|
+
await res.body?.cancel().catch(() => { });
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
seen.add(finalUrl);
|
|
605
|
+
okPages++;
|
|
606
|
+
const html = await textCapped(res);
|
|
607
|
+
const card = parseTeamPage(html, q);
|
|
608
|
+
if (!card) {
|
|
609
|
+
// An about page often links to the real team page under another path: try those next.
|
|
610
|
+
queue.unshift(...teamLinks(html, finalUrl, q.domain).filter((u) => !seen.has(u)).slice(0, 2));
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
const out = [];
|
|
614
|
+
if (card.title)
|
|
615
|
+
out.push({ field: 'title', value: card.title, source: 'team-page', confidence: card.titleConfidence ?? 0.7, evidence: finalUrl });
|
|
616
|
+
if (card.email)
|
|
617
|
+
out.push({ field: 'email', value: card.email, source: 'team-page', confidence: 0.85, evidence: finalUrl });
|
|
618
|
+
if (card.linkedin)
|
|
619
|
+
out.push({ field: 'linkedin', value: card.linkedin, source: 'team-page', confidence: 0.8, evidence: finalUrl });
|
|
620
|
+
return out;
|
|
621
|
+
}
|
|
622
|
+
return [];
|
|
623
|
+
},
|
|
624
|
+
};
|
|
625
|
+
// ---------- 8. Medium ----------
|
|
626
|
+
export const mediumProvider = {
|
|
627
|
+
id: 'medium',
|
|
628
|
+
kind: 'free',
|
|
629
|
+
description: 'Medium author feed for a known username (author name must match)',
|
|
630
|
+
provides: ['profile'],
|
|
631
|
+
needs: (q) => Boolean(q.name && q.usernames?.length),
|
|
632
|
+
async run(q, ctx) {
|
|
633
|
+
for (const u of (q.usernames ?? []).slice(0, 2)) {
|
|
634
|
+
if (!/^[A-Za-z0-9._-]{2,30}$/.test(u))
|
|
635
|
+
continue;
|
|
636
|
+
const res = await tryFetch(ctx, `https://medium.com/feed/@${u}`, {}, 8000);
|
|
637
|
+
if (!res || res.status !== 200)
|
|
638
|
+
continue;
|
|
639
|
+
const xml = await textCapped(res, 300_000);
|
|
640
|
+
const title = xml.match(/<channel>[\s\S]*?<title>(?:<!\[CDATA\[)?\s*Stories by (.+?) on Medium/)?.[1];
|
|
641
|
+
if (title && sameName(decodeEntities(title), q.name)) {
|
|
642
|
+
return [{ field: 'profile', value: `https://medium.com/@${u}`, source: 'medium', confidence: 0.7, evidence: `Medium feed author "${title}"` }];
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return [];
|
|
646
|
+
},
|
|
647
|
+
};
|
|
648
|
+
export const SOCIAL_PROVIDERS = [
|
|
649
|
+
teamPageProvider,
|
|
650
|
+
humansTxtProvider,
|
|
651
|
+
wkdProvider,
|
|
652
|
+
libravatarProvider,
|
|
653
|
+
blueskyProvider,
|
|
654
|
+
mastodonProvider,
|
|
655
|
+
nostrProvider,
|
|
656
|
+
mediumProvider,
|
|
657
|
+
];
|