openrich 0.0.0-stage → 0.1.1
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,471 @@
|
|
|
1
|
+
import { getJson, UA } from "../util/http.js";
|
|
2
|
+
import { mentionsCompany, sameName } from "../util/match.js";
|
|
3
|
+
import { slug } from "../util/names.js";
|
|
4
|
+
/*
|
|
5
|
+
* Research / academic sources. Every provider follows the same rule:
|
|
6
|
+
* a record is used only if the name matches (sameName) AND an affiliation points at the query's
|
|
7
|
+
* company or domain. Wrong-person data is worse than none.
|
|
8
|
+
*/
|
|
9
|
+
const H = { 'User-Agent': UA };
|
|
10
|
+
const STOP = new Set(['of', 'the', 'and', 'at', 'for', 'de', 'in', 'du', 'la', 'des', 'der', 'und', '&']);
|
|
11
|
+
function fullName(q) {
|
|
12
|
+
return q.name ?? [q.firstName, q.lastName].filter(Boolean).join(' ');
|
|
13
|
+
}
|
|
14
|
+
function needsNameAndOrg(q) {
|
|
15
|
+
const n = fullName(q);
|
|
16
|
+
return Boolean(n && n.trim().includes(' ') && (q.company || q.domain));
|
|
17
|
+
}
|
|
18
|
+
function hostOf(url) {
|
|
19
|
+
try {
|
|
20
|
+
return new URL(/^[a-z]+:\/\//i.test(url) ? url : `https://${url}`).hostname.toLowerCase().replace(/^www\./, '');
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Host or email domain equals the query domain or is a subdomain of it (cs.stanford.edu -> stanford.edu). */
|
|
27
|
+
export function onDomain(hostOrEmail, q) {
|
|
28
|
+
if (!hostOrEmail || !q.domain)
|
|
29
|
+
return false;
|
|
30
|
+
const h = hostOrEmail.toLowerCase().split('@').pop().trim();
|
|
31
|
+
return h === q.domain || h.endsWith(`.${q.domain}`);
|
|
32
|
+
}
|
|
33
|
+
export function urlOnDomain(url, q) {
|
|
34
|
+
return Boolean(url) && onDomain(hostOf(url), q);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Does an institution name point at the query's company or domain?
|
|
38
|
+
* mentionsCompany, plus forms common for universities:
|
|
39
|
+
* an exact acronym token ("NYU" for nyu.edu), initials ("New York University" -> nyu),
|
|
40
|
+
* and the u-prefix form ("University of Toronto" -> utoronto.ca).
|
|
41
|
+
*/
|
|
42
|
+
export function orgMatches(text, q) {
|
|
43
|
+
if (!text)
|
|
44
|
+
return false;
|
|
45
|
+
if (mentionsCompany(text, q))
|
|
46
|
+
return true;
|
|
47
|
+
if (!q.domain)
|
|
48
|
+
return false;
|
|
49
|
+
const root = q.domain.split('.')[0];
|
|
50
|
+
if (root.length < 3)
|
|
51
|
+
return false;
|
|
52
|
+
const words = text.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '').split(/[^a-z0-9]+/).filter(Boolean);
|
|
53
|
+
if (words.includes(root))
|
|
54
|
+
return true;
|
|
55
|
+
// Initials of each comma/semicolon segment ("Dept of CS, New York University" -> "nyu").
|
|
56
|
+
for (const seg of text.split(/[,;]/)) {
|
|
57
|
+
const w = seg.toLowerCase().split(/[^a-z]+/).filter((x) => x && !STOP.has(x));
|
|
58
|
+
if (w.length >= 3 && w.map((x) => x[0]).join('') === root)
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (root.startsWith('u') && root.length >= 5 && words.includes(root.slice(1)) && words.some((x) => x.startsWith('univ')))
|
|
62
|
+
return true;
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
/** Plausibly this person's mailbox: local part contains the last name (or exact first/last combos for short last names). */
|
|
66
|
+
export function plausibleLocal(local, first, last) {
|
|
67
|
+
const l = slug(local);
|
|
68
|
+
const F = slug(first);
|
|
69
|
+
const L = slug(last);
|
|
70
|
+
if (!l || !L)
|
|
71
|
+
return false;
|
|
72
|
+
if (L.length >= 4)
|
|
73
|
+
return l.includes(L);
|
|
74
|
+
if (!F)
|
|
75
|
+
return false;
|
|
76
|
+
return [F + L, F[0] + L, L + F, L + F[0]].includes(l);
|
|
77
|
+
}
|
|
78
|
+
function titleCase(s) {
|
|
79
|
+
if (s !== s.toUpperCase())
|
|
80
|
+
return s;
|
|
81
|
+
return s
|
|
82
|
+
.toLowerCase()
|
|
83
|
+
.split(' ')
|
|
84
|
+
.map((w, i) => (i > 0 && STOP.has(w) ? w : w.charAt(0).toUpperCase() + w.slice(1)))
|
|
85
|
+
.join(' ');
|
|
86
|
+
}
|
|
87
|
+
function finder(source, out) {
|
|
88
|
+
return (field, value, confidence, evidence) => {
|
|
89
|
+
if (typeof value !== 'string' || !value.trim())
|
|
90
|
+
return;
|
|
91
|
+
const v = value.trim();
|
|
92
|
+
if (out.some((f) => f.field === field && f.value.toLowerCase() === v.toLowerCase()))
|
|
93
|
+
return;
|
|
94
|
+
out.push({ field, value: v, source, confidence, ...(evidence ? { evidence } : {}) });
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function orcidUrl(id) {
|
|
98
|
+
const m = String(id ?? '').match(/(\d{4}-\d{4}-\d{4}-\d{3}[\dX])/i);
|
|
99
|
+
return m ? `https://orcid.org/${m[1].toUpperCase()}` : null;
|
|
100
|
+
}
|
|
101
|
+
/** Email found in a record: work email if at the query domain, else personal. */
|
|
102
|
+
function addEmail(add, email, q, workConf, personalConf, ev) {
|
|
103
|
+
const e = email.toLowerCase().trim();
|
|
104
|
+
if (!/^[^@\s]+@[^@\s]+\.[a-z]{2,}$/.test(e))
|
|
105
|
+
return;
|
|
106
|
+
if (onDomain(e, q))
|
|
107
|
+
add('email', e, workConf, ev);
|
|
108
|
+
else
|
|
109
|
+
add('personal_email', e, personalConf, ev);
|
|
110
|
+
}
|
|
111
|
+
// ---------------------------------------------------------------- OpenAlex
|
|
112
|
+
/** OpenAlex authors (free; OPENALEX_API_KEY or OPENALEX_MAILTO optional for a larger budget). */
|
|
113
|
+
export const openalexProvider = {
|
|
114
|
+
id: 'openalex',
|
|
115
|
+
kind: 'free',
|
|
116
|
+
description: 'OpenAlex author records: institution, ORCID (OPENALEX_API_KEY / OPENALEX_MAILTO optional)',
|
|
117
|
+
provides: ['company', 'orcid', 'profile'],
|
|
118
|
+
needs: needsNameAndOrg,
|
|
119
|
+
async run(q, ctx) {
|
|
120
|
+
const name = fullName(q);
|
|
121
|
+
const auth = ctx.env.OPENALEX_API_KEY
|
|
122
|
+
? `&api_key=${encodeURIComponent(ctx.env.OPENALEX_API_KEY)}`
|
|
123
|
+
: ctx.env.OPENALEX_MAILTO
|
|
124
|
+
? `&mailto=${encodeURIComponent(ctx.env.OPENALEX_MAILTO)}`
|
|
125
|
+
: '';
|
|
126
|
+
const r = await getJson(ctx.fetch, `https://api.openalex.org/authors?search=${encodeURIComponent(name)}&per_page=10${auth}`, { headers: H });
|
|
127
|
+
const recent = new Date().getFullYear() - 3;
|
|
128
|
+
for (const a of r.data?.results ?? []) {
|
|
129
|
+
const names = [a.display_name, ...(a.display_name_alternatives ?? [])];
|
|
130
|
+
if (!names.some((n) => sameName(n, name)))
|
|
131
|
+
continue;
|
|
132
|
+
const insts = [...(a.last_known_institutions ?? [])];
|
|
133
|
+
for (const af of a.affiliations ?? [])
|
|
134
|
+
if (Math.max(...(af.years ?? [0])) >= recent)
|
|
135
|
+
insts.push(af.institution);
|
|
136
|
+
let hit = insts.find((i) => orgMatches(i?.display_name, q));
|
|
137
|
+
if (!hit && q.domain && insts.length) {
|
|
138
|
+
const ids = [...new Set(insts.map((i) => String(i?.id ?? '').split('/').pop()).filter(Boolean))].slice(0, 20);
|
|
139
|
+
const ir = await getJson(ctx.fetch, `https://api.openalex.org/institutions?filter=id:${ids.join('|')}&select=id,display_name,homepage_url${auth}`, { headers: H });
|
|
140
|
+
hit = (ir.data?.results ?? []).find((i) => urlOnDomain(i.homepage_url, q));
|
|
141
|
+
}
|
|
142
|
+
if (!hit)
|
|
143
|
+
continue;
|
|
144
|
+
const out = [];
|
|
145
|
+
const add = finder('openalex', out);
|
|
146
|
+
const ev = `OpenAlex author, institution ${hit.display_name}`;
|
|
147
|
+
add('company', hit.display_name, 0.7, ev);
|
|
148
|
+
add('orcid', orcidUrl(a.orcid), 0.85, ev);
|
|
149
|
+
add('profile', a.id, 0.85, ev);
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
return [];
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
// ---------------------------------------------------------------- ORCID
|
|
156
|
+
/** ORCID public API v3 (free, no key). */
|
|
157
|
+
export const orcidProvider = {
|
|
158
|
+
id: 'orcid',
|
|
159
|
+
kind: 'free',
|
|
160
|
+
description: 'ORCID public records: employment, role, researcher URLs, public emails',
|
|
161
|
+
provides: ['orcid', 'company', 'title', 'website', 'profile', 'email', 'personal_email'],
|
|
162
|
+
needs: needsNameAndOrg,
|
|
163
|
+
async run(q, ctx) {
|
|
164
|
+
const name = fullName(q);
|
|
165
|
+
const first = q.firstName ?? name.split(/\s+/)[0];
|
|
166
|
+
const last = q.lastName ?? name.split(/\s+/).slice(1).join(' ');
|
|
167
|
+
const esc = (s) => `"${s.replace(/["\\]/g, '')}"`;
|
|
168
|
+
let query = `given-names:${esc(first)} AND family-name:${esc(last)}`;
|
|
169
|
+
if (q.company)
|
|
170
|
+
query += ` AND affiliation-org-name:${esc(q.company)}`;
|
|
171
|
+
const h = { ...H, Accept: 'application/json' };
|
|
172
|
+
const r = await getJson(ctx.fetch, `https://pub.orcid.org/v3.0/expanded-search/?q=${encodeURIComponent(query)}&rows=10`, { headers: h });
|
|
173
|
+
const cands = (r.data?.['expanded-result'] ?? []).filter((x) => sameName(`${x['given-names'] ?? ''} ${x['family-names'] ?? ''}`, name) &&
|
|
174
|
+
((x['institution-name'] ?? []).some((i) => orgMatches(i, q)) || (x.email ?? []).some((e) => onDomain(e, q))));
|
|
175
|
+
for (const c of cands.slice(0, 3)) {
|
|
176
|
+
const id = c['orcid-id'];
|
|
177
|
+
const rec = (await getJson(ctx.fetch, `https://pub.orcid.org/v3.0/${id}/record`, { headers: h })).data;
|
|
178
|
+
if (!rec)
|
|
179
|
+
continue;
|
|
180
|
+
const emails = (rec.person?.emails?.email ?? []).map((e) => String(e.email ?? ''));
|
|
181
|
+
const current = (rec['activities-summary']?.employments?.['affiliation-group'] ?? [])
|
|
182
|
+
.flatMap((g) => g.summaries ?? [])
|
|
183
|
+
.map((s) => s['employment-summary'])
|
|
184
|
+
.filter((s) => s && !s['end-date']);
|
|
185
|
+
const job = current.find((s) => orgMatches(s.organization?.name, q));
|
|
186
|
+
// Current job at the company, or a public email at the domain. A past job alone is not enough.
|
|
187
|
+
if (!job && !emails.some((e) => onDomain(e, q)))
|
|
188
|
+
continue;
|
|
189
|
+
const out = [];
|
|
190
|
+
const add = finder('orcid', out);
|
|
191
|
+
const ev = job ? `ORCID ${id}, current employment ${job.organization?.name}` : `ORCID ${id}, public email at ${q.domain}`;
|
|
192
|
+
add('orcid', orcidUrl(id), 0.95, ev);
|
|
193
|
+
if (job) {
|
|
194
|
+
add('company', job.organization?.name, 0.85, ev);
|
|
195
|
+
add('title', job['role-title'], 0.8, ev);
|
|
196
|
+
}
|
|
197
|
+
for (const e of emails)
|
|
198
|
+
addEmail(add, e, q, 0.9, 0.75, `public email on ORCID ${id}`);
|
|
199
|
+
const urls = (rec.person?.['researcher-urls']?.['researcher-url'] ?? []).map((u) => String(u.url?.value ?? ''));
|
|
200
|
+
for (const [i, u] of urls.entries())
|
|
201
|
+
add(i === 0 ? 'website' : 'profile', u, 0.8, `researcher URL on ORCID ${id}`);
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
return [];
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
// ---------------------------------------------------------------- Semantic Scholar
|
|
208
|
+
/** Semantic Scholar author search (free; SEMANTIC_SCHOLAR_API_KEY optional, unauthenticated pool is shared and 429s). */
|
|
209
|
+
export const semanticScholarProvider = {
|
|
210
|
+
id: 'semantic-scholar',
|
|
211
|
+
kind: 'free',
|
|
212
|
+
description: 'Semantic Scholar author profiles: affiliation, homepage (SEMANTIC_SCHOLAR_API_KEY optional)',
|
|
213
|
+
provides: ['company', 'website', 'profile', 'orcid'],
|
|
214
|
+
needs: needsNameAndOrg,
|
|
215
|
+
async run(q, ctx) {
|
|
216
|
+
const name = fullName(q);
|
|
217
|
+
const h = { ...H };
|
|
218
|
+
if (ctx.env.SEMANTIC_SCHOLAR_API_KEY)
|
|
219
|
+
h['x-api-key'] = ctx.env.SEMANTIC_SCHOLAR_API_KEY;
|
|
220
|
+
const r = await getJson(ctx.fetch, `https://api.semanticscholar.org/graph/v1/author/search?query=${encodeURIComponent(name)}&fields=name,affiliations,homepage,url,externalIds&limit=10`, { headers: h });
|
|
221
|
+
for (const a of r.data?.data ?? []) {
|
|
222
|
+
if (!sameName(a.name, name))
|
|
223
|
+
continue;
|
|
224
|
+
const aff = (a.affiliations ?? []).find((x) => orgMatches(x, q));
|
|
225
|
+
const homeOk = urlOnDomain(a.homepage, q);
|
|
226
|
+
if (!aff && !homeOk)
|
|
227
|
+
continue;
|
|
228
|
+
const out = [];
|
|
229
|
+
const add = finder('semantic-scholar', out);
|
|
230
|
+
const ev = aff ? `Semantic Scholar affiliation ${aff}` : `Semantic Scholar homepage at ${q.domain}`;
|
|
231
|
+
add('company', aff, 0.6, ev);
|
|
232
|
+
add('website', a.homepage, 0.7, ev);
|
|
233
|
+
add('profile', a.url, 0.8, ev);
|
|
234
|
+
add('orcid', orcidUrl(a.externalIds?.ORCID), 0.8, ev);
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
return [];
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
// ---------------------------------------------------------------- NSF awards
|
|
241
|
+
function usDate(s) {
|
|
242
|
+
const m = String(s ?? '').match(/^(\d{2})\/(\d{2})\/(\d{4})$/);
|
|
243
|
+
return m ? Date.UTC(+m[3], +m[1] - 1, +m[2]) : 0;
|
|
244
|
+
}
|
|
245
|
+
/** NSF Award Search (free, no key). PI email + awardee institution. */
|
|
246
|
+
export const nsfAwardsProvider = {
|
|
247
|
+
id: 'nsf-awards',
|
|
248
|
+
kind: 'free',
|
|
249
|
+
description: 'NSF awards by PI name: PI email, awardee institution',
|
|
250
|
+
provides: ['email', 'personal_email', 'company', 'title'],
|
|
251
|
+
needs: needsNameAndOrg,
|
|
252
|
+
async run(q, ctx) {
|
|
253
|
+
const name = fullName(q);
|
|
254
|
+
const fields = 'id,title,awardeeName,piFirstName,piLastName,piEmail,startDate,date';
|
|
255
|
+
const r = await getJson(ctx.fetch, `https://api.nsf.gov/services/v1/awards.json?pdPIName=${encodeURIComponent(`"${name}"`)}&printFields=${fields}&rpp=25`, { headers: H });
|
|
256
|
+
const hits = (r.data?.response?.award ?? [])
|
|
257
|
+
.filter((a) => sameName(`${a.piFirstName ?? ''} ${a.piLastName ?? ''}`, name))
|
|
258
|
+
.filter((a) => orgMatches(a.awardeeName, q) || onDomain(a.piEmail, q))
|
|
259
|
+
.sort((a, b) => usDate(b.startDate ?? b.date) - usDate(a.startDate ?? a.date));
|
|
260
|
+
const a = hits[0];
|
|
261
|
+
if (!a)
|
|
262
|
+
return [];
|
|
263
|
+
const out = [];
|
|
264
|
+
const add = finder('nsf-awards', out);
|
|
265
|
+
const ev = `NSF award ${a.id} (${a.startDate ?? a.date ?? '?'}), awardee ${a.awardeeName}`;
|
|
266
|
+
if (a.piEmail)
|
|
267
|
+
addEmail(add, a.piEmail, q, 0.85, 0.6, ev);
|
|
268
|
+
if (orgMatches(a.awardeeName, q))
|
|
269
|
+
add('company', a.awardeeName, 0.7, ev);
|
|
270
|
+
add('title', 'Principal Investigator', 0.4, ev);
|
|
271
|
+
return out;
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
// ---------------------------------------------------------------- NIH RePORTER
|
|
275
|
+
/** NIH RePORTER v2 (free, no key). Organisation only: PI emails are not exposed. */
|
|
276
|
+
export const nihReporterProvider = {
|
|
277
|
+
id: 'nih-reporter',
|
|
278
|
+
kind: 'free',
|
|
279
|
+
description: 'NIH RePORTER projects by PI name: organisation',
|
|
280
|
+
provides: ['company'],
|
|
281
|
+
needs: needsNameAndOrg,
|
|
282
|
+
async run(q, ctx) {
|
|
283
|
+
const name = fullName(q);
|
|
284
|
+
const first = q.firstName ?? name.split(/\s+/)[0];
|
|
285
|
+
const last = q.lastName ?? name.split(/\s+/).slice(1).join(' ');
|
|
286
|
+
const body = {
|
|
287
|
+
criteria: { pi_names: [{ first_name: first, last_name: last }] },
|
|
288
|
+
include_fields: ['ProjectNum', 'Organization', 'PrincipalInvestigators', 'FiscalYear'],
|
|
289
|
+
limit: 25,
|
|
290
|
+
sort_field: 'fiscal_year',
|
|
291
|
+
sort_order: 'desc',
|
|
292
|
+
};
|
|
293
|
+
const r = await getJson(ctx.fetch, 'https://api.reporter.nih.gov/v2/projects/search', {
|
|
294
|
+
method: 'POST',
|
|
295
|
+
headers: { ...H, 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
296
|
+
body: JSON.stringify(body),
|
|
297
|
+
});
|
|
298
|
+
const hits = (r.data?.results ?? [])
|
|
299
|
+
.filter((p) => (p.principal_investigators ?? []).some((pi) => sameName(`${pi.first_name ?? ''} ${pi.last_name ?? ''}`, name)))
|
|
300
|
+
.filter((p) => orgMatches(p.organization?.org_name, q))
|
|
301
|
+
.sort((a, b) => (b.fiscal_year ?? 0) - (a.fiscal_year ?? 0));
|
|
302
|
+
const p = hits[0];
|
|
303
|
+
if (!p)
|
|
304
|
+
return [];
|
|
305
|
+
return [{
|
|
306
|
+
field: 'company',
|
|
307
|
+
value: titleCase(p.organization.org_name),
|
|
308
|
+
source: 'nih-reporter',
|
|
309
|
+
confidence: 0.65,
|
|
310
|
+
evidence: `NIH project ${p.project_num} (FY${p.fiscal_year})`,
|
|
311
|
+
}];
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
// ---------------------------------------------------------------- Europe PMC
|
|
315
|
+
const EMAIL_RE = /[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}/gi;
|
|
316
|
+
/** Europe PMC (free, no key). Author affiliation strings, which often carry the author's email. */
|
|
317
|
+
export const europePmcProvider = {
|
|
318
|
+
id: 'europe-pmc',
|
|
319
|
+
kind: 'free',
|
|
320
|
+
description: 'Europe PMC author affiliations: work email (when printed with the affiliation), institution, ORCID',
|
|
321
|
+
provides: ['email', 'company', 'orcid'],
|
|
322
|
+
needs: needsNameAndOrg,
|
|
323
|
+
async run(q, ctx) {
|
|
324
|
+
const name = fullName(q);
|
|
325
|
+
const first = q.firstName ?? name.split(/\s+/)[0];
|
|
326
|
+
const last = q.lastName ?? name.split(/\s+/).slice(1).join(' ');
|
|
327
|
+
const affs = [q.company, q.domain].filter(Boolean).map((a) => `AFF:"${a.replace(/"/g, '')}"`);
|
|
328
|
+
const query = `AUTH:"${last.replace(/"/g, '')} ${first[0]}" AND (${affs.join(' OR ')}) sort_date:y`;
|
|
329
|
+
const r = await getJson(ctx.fetch, `https://www.ebi.ac.uk/europepmc/webservices/rest/search?query=${encodeURIComponent(query)}&resultType=core&format=json&pageSize=25`, { headers: H });
|
|
330
|
+
const out = [];
|
|
331
|
+
const add = finder('europe-pmc', out);
|
|
332
|
+
for (const w of r.data?.resultList?.result ?? []) {
|
|
333
|
+
for (const a of w.authorList?.author ?? []) {
|
|
334
|
+
if (!a.firstName || !sameName(`${a.firstName} ${a.lastName ?? ''}`, name))
|
|
335
|
+
continue;
|
|
336
|
+
const affStrings = (a.authorAffiliationDetailsList?.authorAffiliation ?? []).map((x) => String(x.affiliation ?? ''));
|
|
337
|
+
const ev = `Europe PMC ${w.source ?? ''}${w.id ?? ''} (${w.firstPublicationDate ?? w.pubYear ?? '?'})`;
|
|
338
|
+
let matched = false;
|
|
339
|
+
for (const s of affStrings) {
|
|
340
|
+
const seg = s.split(/[,;]|\band\b/).map((x) => x.trim()).find((x) => orgMatches(x, q));
|
|
341
|
+
const emails = (s.match(EMAIL_RE) ?? []).map((e) => e.replace(/\.$/, '').toLowerCase());
|
|
342
|
+
const own = emails.filter((e) => onDomain(e, q) && plausibleLocal(e.split('@')[0], first, last));
|
|
343
|
+
if (!seg && own.length === 0)
|
|
344
|
+
continue;
|
|
345
|
+
matched = true;
|
|
346
|
+
if (seg)
|
|
347
|
+
add('company', seg, 0.5, ev);
|
|
348
|
+
for (const e of own)
|
|
349
|
+
add('email', e, 0.8, `${ev}: printed in author affiliation`);
|
|
350
|
+
}
|
|
351
|
+
if (matched && a.authorId?.type === 'ORCID')
|
|
352
|
+
add('orcid', orcidUrl(a.authorId.value), 0.8, ev);
|
|
353
|
+
}
|
|
354
|
+
if (out.some((f) => f.field === 'email'))
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
return out;
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
// ---------------------------------------------------------------- OpenReview
|
|
361
|
+
/** OpenReview profiles. Search now requires a logged-in token (OPENREVIEW_TOKEN); guests get 403. */
|
|
362
|
+
export const openreviewProvider = {
|
|
363
|
+
id: 'openreview',
|
|
364
|
+
kind: 'free',
|
|
365
|
+
keyEnv: 'OPENREVIEW_TOKEN',
|
|
366
|
+
description: 'OpenReview profiles: current position and institution, confirmed email domains (needs OPENREVIEW_TOKEN)',
|
|
367
|
+
provides: ['title', 'company', 'profile', 'website', 'orcid'],
|
|
368
|
+
needs: needsNameAndOrg,
|
|
369
|
+
async run(q, ctx) {
|
|
370
|
+
const name = fullName(q);
|
|
371
|
+
const r = await getJson(ctx.fetch, `https://api2.openreview.net/profiles/search?fullname=${encodeURIComponent(name)}`, {
|
|
372
|
+
headers: { ...H, Authorization: `Bearer ${ctx.env.OPENREVIEW_TOKEN}` },
|
|
373
|
+
});
|
|
374
|
+
const year = new Date().getFullYear();
|
|
375
|
+
for (const p of r.data?.profiles ?? []) {
|
|
376
|
+
const c = p.content ?? {};
|
|
377
|
+
if (!(c.names ?? []).some((n) => sameName(n.fullname, name)))
|
|
378
|
+
continue;
|
|
379
|
+
const history = c.history ?? [];
|
|
380
|
+
const current = history.filter((h) => !h.end || Number(h.end) >= year);
|
|
381
|
+
const job = current.find((h) => onDomain(h.institution?.domain, q) || orgMatches(h.institution?.name, q));
|
|
382
|
+
const masked = [...(c.emails ?? []), ...(c.emailsConfirmed ?? []), c.preferredEmail].filter(Boolean);
|
|
383
|
+
const emailOk = masked.some((e) => onDomain(e, q));
|
|
384
|
+
if (!job && !emailOk)
|
|
385
|
+
continue;
|
|
386
|
+
const out = [];
|
|
387
|
+
const add = finder('openreview', out);
|
|
388
|
+
const ev = job ? `OpenReview ${p.id}, current: ${job.institution?.name}` : `OpenReview ${p.id}, confirmed email at ${q.domain}`;
|
|
389
|
+
add('profile', `https://openreview.net/profile?id=${encodeURIComponent(p.id)}`, 0.85, ev);
|
|
390
|
+
if (job) {
|
|
391
|
+
add('company', job.institution?.name, 0.75, ev);
|
|
392
|
+
add('title', job.position, 0.75, ev);
|
|
393
|
+
}
|
|
394
|
+
add('website', c.homepage, 0.7, ev);
|
|
395
|
+
add('orcid', orcidUrl(c.orcid), 0.85, ev);
|
|
396
|
+
return out;
|
|
397
|
+
}
|
|
398
|
+
return [];
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
// ---------------------------------------------------------------- INSPIRE-HEP
|
|
402
|
+
/** INSPIRE-HEP authors (free, no key). High-energy physics. */
|
|
403
|
+
export const inspireHepProvider = {
|
|
404
|
+
id: 'inspire-hep',
|
|
405
|
+
kind: 'free',
|
|
406
|
+
description: 'INSPIRE-HEP author records: current institution, public emails, ORCID, links',
|
|
407
|
+
provides: ['company', 'email', 'personal_email', 'orcid', 'profile', 'website', 'twitter', 'linkedin'],
|
|
408
|
+
needs: needsNameAndOrg,
|
|
409
|
+
async run(q, ctx) {
|
|
410
|
+
const name = fullName(q);
|
|
411
|
+
const r = await getJson(ctx.fetch, `https://inspirehep.net/api/authors?q=${encodeURIComponent(name)}&size=10&fields=name,ids,email_addresses,positions,urls,control_number`, { headers: H });
|
|
412
|
+
for (const hit of r.data?.hits?.hits ?? []) {
|
|
413
|
+
const m = hit.metadata ?? {};
|
|
414
|
+
if (![m.name?.value, m.name?.preferred_name].some((n) => sameName(n, name)))
|
|
415
|
+
continue;
|
|
416
|
+
const current = (m.positions ?? []).filter((p) => p.current);
|
|
417
|
+
const emails = (m.email_addresses ?? []).filter((e) => !e.hidden).map((e) => String(e.value ?? ''));
|
|
418
|
+
let pos = current.find((p) => orgMatches(p.institution, q));
|
|
419
|
+
if (!pos && q.domain) {
|
|
420
|
+
for (const p of current.slice(0, 2)) {
|
|
421
|
+
const ref = p.record?.$ref;
|
|
422
|
+
if (!ref || !String(ref).startsWith('https://inspirehep.net/api/institutions/'))
|
|
423
|
+
continue;
|
|
424
|
+
const inst = (await getJson(ctx.fetch, `${ref}?fields=urls`, { headers: H })).data;
|
|
425
|
+
if ((inst?.metadata?.urls ?? []).some((u) => urlOnDomain(u.value, q))) {
|
|
426
|
+
pos = p;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const emailOk = emails.some((e) => onDomain(e, q));
|
|
432
|
+
if (!pos && !emailOk)
|
|
433
|
+
continue;
|
|
434
|
+
const out = [];
|
|
435
|
+
const add = finder('inspire-hep', out);
|
|
436
|
+
const ev = pos ? `INSPIRE author ${m.control_number}, current: ${pos.institution}` : `INSPIRE author ${m.control_number}, email at ${q.domain}`;
|
|
437
|
+
add('profile', `https://inspirehep.net/authors/${m.control_number}`, 0.85, ev);
|
|
438
|
+
if (pos)
|
|
439
|
+
add('company', pos.institution, 0.7, ev);
|
|
440
|
+
for (const e of emails)
|
|
441
|
+
addEmail(add, e, q, 0.85, 0.6, ev);
|
|
442
|
+
for (const id of m.ids ?? []) {
|
|
443
|
+
if (id.schema === 'ORCID')
|
|
444
|
+
add('orcid', orcidUrl(id.value), 0.9, ev);
|
|
445
|
+
else if (id.schema === 'TWITTER')
|
|
446
|
+
add('twitter', `https://x.com/${id.value}`, 0.8, ev);
|
|
447
|
+
else if (id.schema === 'LINKEDIN')
|
|
448
|
+
add('linkedin', `https://www.linkedin.com/in/${id.value}`, 0.8, ev);
|
|
449
|
+
}
|
|
450
|
+
for (const u of m.urls ?? [])
|
|
451
|
+
add('website', u.value, 0.7, ev);
|
|
452
|
+
return out;
|
|
453
|
+
}
|
|
454
|
+
return [];
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
/*
|
|
458
|
+
* Skipped:
|
|
459
|
+
* - dblp: the search API sits behind an Anubis bot challenge (HTTP 202 + HTML) for non-browser clients.
|
|
460
|
+
* - Crossref, Zenodo: author search on works is too noisy to tie to one person.
|
|
461
|
+
*/
|
|
462
|
+
export const RESEARCH_PROVIDERS = [
|
|
463
|
+
orcidProvider,
|
|
464
|
+
openalexProvider,
|
|
465
|
+
semanticScholarProvider,
|
|
466
|
+
inspireHepProvider,
|
|
467
|
+
nsfAwardsProvider,
|
|
468
|
+
nihReporterProvider,
|
|
469
|
+
europePmcProvider,
|
|
470
|
+
openreviewProvider,
|
|
471
|
+
];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Free, keyless checks that say "this email address really exists". */
|
|
2
|
+
export declare function sha256(s: string): string;
|
|
3
|
+
export declare function mxHosts(domain: string): Promise<string[]>;
|
|
4
|
+
/** Gravatar: an avatar for this email exists. */
|
|
5
|
+
export declare function gravatarExists(f: typeof fetch, email: string): Promise<boolean>;
|
|
6
|
+
/** keys.openpgp.org only publishes user IDs whose email the owner confirmed. Returns the user ID names. */
|
|
7
|
+
export declare function openpgpLookup(f: typeof fetch, email: string): Promise<string[] | null>;
|
|
8
|
+
/** Minimal OpenPGP packet walk: return User ID packet strings (tag 13). */
|
|
9
|
+
export declare function userIdsFromArmored(armored: string): string[];
|
|
10
|
+
export interface ReacherResult {
|
|
11
|
+
reachable: 'safe' | 'risky' | 'invalid' | 'unknown';
|
|
12
|
+
catchAll: boolean | null;
|
|
13
|
+
}
|
|
14
|
+
/** Self-hosted Reacher (github.com/reacherhq/check-if-email-exists). Needs outbound port 25. */
|
|
15
|
+
export declare function reacherCheck(f: typeof fetch, base: string, email: string): Promise<ReacherResult>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { resolveMx } from 'node:dns/promises';
|
|
3
|
+
import { UA } from "../util/http.js";
|
|
4
|
+
/** Free, keyless checks that say "this email address really exists". */
|
|
5
|
+
export function sha256(s) {
|
|
6
|
+
return createHash('sha256').update(s.trim().toLowerCase()).digest('hex');
|
|
7
|
+
}
|
|
8
|
+
export async function mxHosts(domain) {
|
|
9
|
+
try {
|
|
10
|
+
const mx = await resolveMx(domain);
|
|
11
|
+
return mx.sort((a, b) => a.priority - b.priority).map((m) => m.exchange.toLowerCase());
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Gravatar: an avatar for this email exists. */
|
|
18
|
+
export async function gravatarExists(f, email) {
|
|
19
|
+
try {
|
|
20
|
+
const res = await f(`https://gravatar.com/avatar/${sha256(email)}?d=404&s=1`, {
|
|
21
|
+
method: 'HEAD',
|
|
22
|
+
headers: { 'User-Agent': UA },
|
|
23
|
+
signal: AbortSignal.timeout(8000),
|
|
24
|
+
});
|
|
25
|
+
return res.status === 200;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** keys.openpgp.org only publishes user IDs whose email the owner confirmed. Returns the user ID names. */
|
|
32
|
+
export async function openpgpLookup(f, email) {
|
|
33
|
+
try {
|
|
34
|
+
const res = await f(`https://keys.openpgp.org/vks/v1/by-email/${encodeURIComponent(email)}`, {
|
|
35
|
+
headers: { 'User-Agent': UA },
|
|
36
|
+
signal: AbortSignal.timeout(8000),
|
|
37
|
+
});
|
|
38
|
+
if (res.status !== 200)
|
|
39
|
+
return null;
|
|
40
|
+
return userIdsFromArmored(await res.text());
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Minimal OpenPGP packet walk: return User ID packet strings (tag 13). */
|
|
47
|
+
export function userIdsFromArmored(armored) {
|
|
48
|
+
const body = armored
|
|
49
|
+
.split('\n')
|
|
50
|
+
.filter((l) => l && !l.startsWith('-----') && !l.includes(':') && !l.startsWith('='))
|
|
51
|
+
.join('');
|
|
52
|
+
const buf = Buffer.from(body, 'base64');
|
|
53
|
+
const out = [];
|
|
54
|
+
let i = 0;
|
|
55
|
+
while (i < buf.length) {
|
|
56
|
+
const h = buf[i];
|
|
57
|
+
if (!(h & 0x80))
|
|
58
|
+
break;
|
|
59
|
+
let tag;
|
|
60
|
+
let len;
|
|
61
|
+
let hdr;
|
|
62
|
+
if (h & 0x40) {
|
|
63
|
+
tag = h & 0x3f;
|
|
64
|
+
const o = buf[i + 1];
|
|
65
|
+
if (o < 192) {
|
|
66
|
+
len = o;
|
|
67
|
+
hdr = 2;
|
|
68
|
+
}
|
|
69
|
+
else if (o < 224) {
|
|
70
|
+
len = ((o - 192) << 8) + buf[i + 2] + 192;
|
|
71
|
+
hdr = 3;
|
|
72
|
+
}
|
|
73
|
+
else if (o === 255) {
|
|
74
|
+
len = buf.readUInt32BE(i + 2);
|
|
75
|
+
hdr = 6;
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
break; // partial lengths: not used for key packets
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
tag = (h >> 2) & 0x0f;
|
|
82
|
+
const lt = h & 3;
|
|
83
|
+
if (lt === 0) {
|
|
84
|
+
len = buf[i + 1];
|
|
85
|
+
hdr = 2;
|
|
86
|
+
}
|
|
87
|
+
else if (lt === 1) {
|
|
88
|
+
len = buf.readUInt16BE(i + 1);
|
|
89
|
+
hdr = 3;
|
|
90
|
+
}
|
|
91
|
+
else if (lt === 2) {
|
|
92
|
+
len = buf.readUInt32BE(i + 1);
|
|
93
|
+
hdr = 5;
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (tag === 13)
|
|
99
|
+
out.push(buf.subarray(i + hdr, i + hdr + len).toString('utf8'));
|
|
100
|
+
i += hdr + len;
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
/** Self-hosted Reacher (github.com/reacherhq/check-if-email-exists). Needs outbound port 25. */
|
|
105
|
+
export async function reacherCheck(f, base, email) {
|
|
106
|
+
const res = await f(`${base.replace(/\/$/, '')}/v0/check_email`, {
|
|
107
|
+
method: 'POST',
|
|
108
|
+
headers: { 'content-type': 'application/json' },
|
|
109
|
+
body: JSON.stringify({ to_email: email }),
|
|
110
|
+
signal: AbortSignal.timeout(60000),
|
|
111
|
+
});
|
|
112
|
+
if (!res.ok)
|
|
113
|
+
throw new Error(`Reacher HTTP ${res.status}`);
|
|
114
|
+
const j = await res.json();
|
|
115
|
+
return { reachable: j.is_reachable ?? 'unknown', catchAll: j.smtp?.is_catch_all ?? null };
|
|
116
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in SMTP mailbox check (the method Reacher uses), no dependencies.
|
|
3
|
+
* Connects to the domain's MX on port 25, asks RCPT TO for each address, never sends mail.
|
|
4
|
+
* One random address is probed first: if the server accepts it, the domain is catch-all and
|
|
5
|
+
* SMTP cannot tell real mailboxes apart.
|
|
6
|
+
*
|
|
7
|
+
* Opt-in (SMTP_CHECK=on): needs outbound port 25, and heavy use from one IP can get it blocklisted.
|
|
8
|
+
*/
|
|
9
|
+
export interface SmtpResult {
|
|
10
|
+
catchAll: boolean | null;
|
|
11
|
+
/** email -> true (accepted), false (rejected), null (unknown / temp failure) */
|
|
12
|
+
verdicts: Map<string, boolean | null>;
|
|
13
|
+
}
|
|
14
|
+
export declare function smtpCheck(mx: string, domain: string, emails: string[], opts?: {
|
|
15
|
+
helo?: string;
|
|
16
|
+
from?: string;
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
}): Promise<SmtpResult>;
|
|
19
|
+
/** 5.7.x = policy (blocklisted IP, no PTR, etc.): says nothing about the mailbox. */
|
|
20
|
+
export declare function isPolicyBlock(text: string): boolean;
|
|
21
|
+
/** A real "no such mailbox" answer: 5.1.x, or a 550 that talks about the user/mailbox. */
|
|
22
|
+
export declare function isMailboxReject(r: {
|
|
23
|
+
code: number;
|
|
24
|
+
text: string;
|
|
25
|
+
}): boolean;
|