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,396 @@
|
|
|
1
|
+
import { fetchKey, getJson, UA } from "../util/http.js";
|
|
2
|
+
import { sameName } from "../util/match.js";
|
|
3
|
+
import { slug, splitName } from "../util/names.js";
|
|
4
|
+
const LEGAL = new Set([
|
|
5
|
+
'inc', 'incorporated', 'llc', 'llp', 'ltd', 'limited', 'plc', 'gmbh', 'ag', 'sa', 'sas', 'sasu', 'sarl', 'se', 'asa', 'as',
|
|
6
|
+
'ab', 'oy', 'nv', 'bv', 'corp', 'corporation', 'co', 'company', 'the',
|
|
7
|
+
]);
|
|
8
|
+
/** "Stripe Payments UK Ltd." -> "stripe payments uk" */
|
|
9
|
+
export function normCompany(s) {
|
|
10
|
+
return s
|
|
11
|
+
.normalize('NFD')
|
|
12
|
+
.replace(/[̀-ͯ]/g, '')
|
|
13
|
+
.toLowerCase()
|
|
14
|
+
.replace(/&/g, ' and ')
|
|
15
|
+
.replace(/\([^)]*\)/g, ' ')
|
|
16
|
+
.replace(/[^a-z0-9]+/g, ' ')
|
|
17
|
+
.split(' ')
|
|
18
|
+
.filter((w) => w && !LEGAL.has(w))
|
|
19
|
+
.join(' ');
|
|
20
|
+
}
|
|
21
|
+
function domainRoot(q) {
|
|
22
|
+
const r = q.domain?.split('.')[0];
|
|
23
|
+
return r && r.length >= 2 ? r : undefined;
|
|
24
|
+
}
|
|
25
|
+
/** The term we search the register with: the company name, else the domain root ("stripe" from stripe.com). */
|
|
26
|
+
function companyTerm(q) {
|
|
27
|
+
return q.company?.trim() || domainRoot(q);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Does a registered company name match the query's company?
|
|
31
|
+
* exact: same name once legal suffixes are gone (or equal to the domain root, spaces ignored).
|
|
32
|
+
* partial: the registered name starts with the query name as whole words ("stripe payments uk" for "Stripe").
|
|
33
|
+
*/
|
|
34
|
+
export function companyMatch(registered, q) {
|
|
35
|
+
if (!registered)
|
|
36
|
+
return null;
|
|
37
|
+
const r = normCompany(registered);
|
|
38
|
+
if (!r)
|
|
39
|
+
return null;
|
|
40
|
+
const wants = [q.company ? normCompany(q.company) : '', domainRoot(q) ?? ''].filter((w) => w.length >= 2);
|
|
41
|
+
for (const w of wants)
|
|
42
|
+
if (r === w || r.replace(/ /g, '') === w.replace(/ /g, ''))
|
|
43
|
+
return 'exact';
|
|
44
|
+
for (const w of wants)
|
|
45
|
+
if (w.length >= 3 && r.startsWith(`${w} `))
|
|
46
|
+
return 'partial';
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Person match. exact: sameName(). nick: same last name and one first name is a prefix of the other
|
|
51
|
+
* ("Tim" / "Timothy"), only trusted because we are already inside one company's officer list.
|
|
52
|
+
*/
|
|
53
|
+
export function personMatch(registered, q) {
|
|
54
|
+
const full = q.name ?? [q.firstName, q.lastName].filter(Boolean).join(' ');
|
|
55
|
+
if (!registered || !full)
|
|
56
|
+
return null;
|
|
57
|
+
if (sameName(registered, full))
|
|
58
|
+
return 'exact';
|
|
59
|
+
const parts = (s) => {
|
|
60
|
+
const { first, last } = splitName(s.includes(',') ? s.split(',').reverse().join(' ') : s);
|
|
61
|
+
return { first: slug(first), last: slug(last.split(/\s+/).pop() ?? '') };
|
|
62
|
+
};
|
|
63
|
+
const a = parts(registered);
|
|
64
|
+
const b = parts(full);
|
|
65
|
+
if (!a.last || a.last !== b.last || a.first.length < 3 || b.first.length < 3)
|
|
66
|
+
return null;
|
|
67
|
+
return a.first.startsWith(b.first) || b.first.startsWith(a.first) ? 'nick' : null;
|
|
68
|
+
}
|
|
69
|
+
function conf(company, person, top) {
|
|
70
|
+
let c = top;
|
|
71
|
+
if (company === 'partial')
|
|
72
|
+
c -= 0.15;
|
|
73
|
+
if (person === 'nick')
|
|
74
|
+
c -= 0.1;
|
|
75
|
+
return Math.round(c * 100) / 100;
|
|
76
|
+
}
|
|
77
|
+
const needsPersonAndCompany = (q) => Boolean(q.firstName && q.lastName && (q.company || q.domain));
|
|
78
|
+
function cap(s) {
|
|
79
|
+
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
80
|
+
}
|
|
81
|
+
function roleFindings(source, o) {
|
|
82
|
+
const out = [
|
|
83
|
+
{ field: 'title', value: o.title, source, confidence: o.confidence, evidence: o.evidence },
|
|
84
|
+
{ field: 'company', value: o.company, source, confidence: o.confidence, evidence: o.evidence },
|
|
85
|
+
];
|
|
86
|
+
if (o.profile)
|
|
87
|
+
out.push({ field: 'profile', value: o.profile, source, confidence: o.confidence, evidence: o.evidence });
|
|
88
|
+
if (o.location)
|
|
89
|
+
out.push({ field: 'location', value: o.location, source, confidence: Math.round(o.confidence * 0.8 * 100) / 100, evidence: `${o.evidence} (country of residence)` });
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
// ---------------------------------------------------------------- UK Companies House
|
|
93
|
+
const CH_API = 'https://api.company-information.service.gov.uk';
|
|
94
|
+
const CH_WEB = 'https://find-and-update.company-information.service.gov.uk';
|
|
95
|
+
/** "director" -> "Director", "llp-designated-member" -> "LLP designated member" */
|
|
96
|
+
function chRole(r) {
|
|
97
|
+
return cap(r.replace(/-/g, ' ').replace(/\bllp\b/g, 'LLP'));
|
|
98
|
+
}
|
|
99
|
+
/** UK Companies House (free key, basic auth "key:"; 600 requests / 5 min). */
|
|
100
|
+
export const ukCompaniesHouseProvider = {
|
|
101
|
+
id: 'uk-companies-house',
|
|
102
|
+
kind: 'free',
|
|
103
|
+
description: 'UK Companies House officers (directors, secretaries) of a company',
|
|
104
|
+
provides: ['title', 'company', 'location', 'profile'],
|
|
105
|
+
keyEnv: 'COMPANIES_HOUSE_API_KEY',
|
|
106
|
+
needs: needsPersonAndCompany,
|
|
107
|
+
async run(q, ctx) {
|
|
108
|
+
const term = companyTerm(q);
|
|
109
|
+
const key = ctx.env.COMPANIES_HOUSE_API_KEY;
|
|
110
|
+
if (!term || !key)
|
|
111
|
+
return [];
|
|
112
|
+
const headers = { 'User-Agent': UA, Authorization: `Basic ${Buffer.from(`${key}:`).toString('base64')}` };
|
|
113
|
+
const s = await getJson(ctx.fetch, `${CH_API}/search/companies?q=${encodeURIComponent(term)}&items_per_page=10`, { headers });
|
|
114
|
+
const companies = (s.data?.items ?? [])
|
|
115
|
+
.filter((c) => c.company_status === 'active')
|
|
116
|
+
.map((c) => ({ c, m: companyMatch(c.title, q) }))
|
|
117
|
+
.filter((x) => x.m !== null)
|
|
118
|
+
.sort((a, b) => (a.m === b.m ? 0 : a.m === 'exact' ? -1 : 1))
|
|
119
|
+
.slice(0, 3);
|
|
120
|
+
const out = [];
|
|
121
|
+
for (const { c, m } of companies) {
|
|
122
|
+
const r = await getJson(ctx.fetch, `${CH_API}/company/${encodeURIComponent(c.company_number)}/officers?items_per_page=100`, { headers });
|
|
123
|
+
for (const o of (r.data?.items ?? [])) {
|
|
124
|
+
if (o.resigned_on)
|
|
125
|
+
continue;
|
|
126
|
+
const pm = personMatch(o.name, q);
|
|
127
|
+
if (!pm)
|
|
128
|
+
continue;
|
|
129
|
+
const role = chRole(String(o.officer_role ?? 'officer'));
|
|
130
|
+
const occ = typeof o.occupation === 'string' && o.occupation.trim() && !/^none$/i.test(o.occupation) ? o.occupation.trim() : '';
|
|
131
|
+
const link = o.links?.officer?.appointments;
|
|
132
|
+
out.push(...roleFindings('uk-companies-house', {
|
|
133
|
+
title: occ ? `${role}, ${occ}` : role,
|
|
134
|
+
company: String(c.title),
|
|
135
|
+
profile: link ? `${CH_WEB}${link}` : `${CH_WEB}/company/${c.company_number}/officers`,
|
|
136
|
+
location: typeof o.country_of_residence === 'string' ? o.country_of_residence : undefined,
|
|
137
|
+
evidence: `Companies House officer of ${c.title} (${c.company_number})`,
|
|
138
|
+
confidence: conf(m, pm, 0.85),
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
if (out.length)
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
// ---------------------------------------------------------------- France, Recherche d'entreprises
|
|
148
|
+
const FR_API = 'https://recherche-entreprises.api.gouv.fr/search';
|
|
149
|
+
/** French company register via api.gouv.fr (free, no key, ~7 req/s). Titles are in French ("Président de SAS"). */
|
|
150
|
+
export const frRechercheEntreprisesProvider = {
|
|
151
|
+
id: 'fr-recherche-entreprises',
|
|
152
|
+
kind: 'free',
|
|
153
|
+
description: 'French company register (dirigeants) via recherche-entreprises.api.gouv.fr',
|
|
154
|
+
provides: ['title', 'company', 'profile'],
|
|
155
|
+
needs: needsPersonAndCompany,
|
|
156
|
+
async run(q, ctx) {
|
|
157
|
+
const term = companyTerm(q);
|
|
158
|
+
if (!term)
|
|
159
|
+
return [];
|
|
160
|
+
const url = `${FR_API}?q=${encodeURIComponent(term)}&nom_personne=${encodeURIComponent(q.lastName)}&per_page=10`;
|
|
161
|
+
const r = await getJson(ctx.fetch, url, { headers: { 'User-Agent': UA, Accept: 'application/json' } });
|
|
162
|
+
const out = [];
|
|
163
|
+
for (const e of (r.data?.results ?? [])) {
|
|
164
|
+
if (e.etat_administratif && e.etat_administratif !== 'A')
|
|
165
|
+
continue;
|
|
166
|
+
const m = companyMatch(e.nom_complet, q) ?? companyMatch(e.nom_raison_sociale, q) ?? companyMatch(e.sigle, q);
|
|
167
|
+
if (!m)
|
|
168
|
+
continue;
|
|
169
|
+
for (const d of (e.dirigeants ?? [])) {
|
|
170
|
+
if (d.type_dirigeant !== 'personne physique' || !d.nom || !d.prenoms || !d.qualite)
|
|
171
|
+
continue;
|
|
172
|
+
const noms = [String(d.nom).replace(/\([^)]*\)/g, '').trim(), ...(String(d.nom).match(/\(([^)]+)\)/)?.slice(1) ?? [])];
|
|
173
|
+
const pm = noms.map((n) => personMatch(`${n}, ${d.prenoms}`, q)).find(Boolean);
|
|
174
|
+
if (!pm)
|
|
175
|
+
continue;
|
|
176
|
+
out.push(...roleFindings('fr-recherche-entreprises', {
|
|
177
|
+
title: String(d.qualite),
|
|
178
|
+
company: String(e.nom_complet),
|
|
179
|
+
profile: `https://annuaire-entreprises.data.gouv.fr/entreprise/${e.siren}`,
|
|
180
|
+
evidence: `French register: dirigeant of ${e.nom_complet} (SIREN ${e.siren})`,
|
|
181
|
+
confidence: conf(m, pm, 0.85),
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
// ---------------------------------------------------------------- Norway, Brønnøysund register
|
|
189
|
+
const NO_API = 'https://data.brreg.no/enhetsregisteret/api';
|
|
190
|
+
const NO_ROLES = {
|
|
191
|
+
DAGL: 'Chief Executive (daglig leder)',
|
|
192
|
+
LEDE: 'Chair of the Board',
|
|
193
|
+
NEST: 'Deputy Chair of the Board',
|
|
194
|
+
MEDL: 'Board Member',
|
|
195
|
+
VARA: 'Deputy Board Member',
|
|
196
|
+
OBS: 'Board Observer',
|
|
197
|
+
KONT: 'Contact Person',
|
|
198
|
+
INNH: 'Owner (sole proprietor)',
|
|
199
|
+
DTPR: 'Partner',
|
|
200
|
+
DTSO: 'Partner',
|
|
201
|
+
BEST: 'Managing Shipowner',
|
|
202
|
+
FFØR: 'Business Manager',
|
|
203
|
+
KOMP: 'General Partner',
|
|
204
|
+
};
|
|
205
|
+
function noDomainMatch(site, q) {
|
|
206
|
+
if (!site || !q.domain)
|
|
207
|
+
return false;
|
|
208
|
+
return site.toLowerCase().replace(/^[a-z]+:\/\//, '').replace(/^www\./, '').replace(/\/.*$/, '') === q.domain;
|
|
209
|
+
}
|
|
210
|
+
/** Norwegian Brønnøysund Register Centre (free, no key). */
|
|
211
|
+
export const noBrregProvider = {
|
|
212
|
+
id: 'no-brreg',
|
|
213
|
+
kind: 'free',
|
|
214
|
+
description: 'Norwegian company register (Brønnøysund) roles: CEO, board',
|
|
215
|
+
provides: ['title', 'company', 'profile'],
|
|
216
|
+
needs: needsPersonAndCompany,
|
|
217
|
+
async run(q, ctx) {
|
|
218
|
+
const term = companyTerm(q);
|
|
219
|
+
if (!term)
|
|
220
|
+
return [];
|
|
221
|
+
const headers = { 'User-Agent': UA, Accept: 'application/json' };
|
|
222
|
+
const s = await getJson(ctx.fetch, `${NO_API}/enheter?navn=${encodeURIComponent(term)}&size=10`, { headers });
|
|
223
|
+
const units = (s.data?._embedded?.enheter ?? [])
|
|
224
|
+
.filter((u) => !u.konkurs && !u.underAvvikling && !u.slettedato)
|
|
225
|
+
.map((u) => ({ u, m: noDomainMatch(u.hjemmeside, q) ? 'exact' : companyMatch(u.navn, q) }))
|
|
226
|
+
.filter((x) => x.m !== null)
|
|
227
|
+
.sort((a, b) => (a.m === b.m ? 0 : a.m === 'exact' ? -1 : 1))
|
|
228
|
+
.slice(0, 3);
|
|
229
|
+
const out = [];
|
|
230
|
+
for (const { u, m } of units) {
|
|
231
|
+
const r = await getJson(ctx.fetch, `${NO_API}/enheter/${u.organisasjonsnummer}/roller`, { headers });
|
|
232
|
+
for (const g of (r.data?.rollegrupper ?? [])) {
|
|
233
|
+
for (const role of (g.roller ?? [])) {
|
|
234
|
+
const p = role.person;
|
|
235
|
+
if (!p?.navn || p.erDoed || role.avregistrert || role.fratraadt)
|
|
236
|
+
continue;
|
|
237
|
+
const pm = personMatch(`${p.navn.etternavn}, ${[p.navn.fornavn, p.navn.mellomnavn].filter(Boolean).join(' ')}`, q);
|
|
238
|
+
if (!pm)
|
|
239
|
+
continue;
|
|
240
|
+
const code = String(role.type?.kode ?? '');
|
|
241
|
+
out.push(...roleFindings('no-brreg', {
|
|
242
|
+
title: NO_ROLES[code] ?? String(role.type?.beskrivelse ?? code),
|
|
243
|
+
company: String(u.navn),
|
|
244
|
+
profile: `https://virksomhet.brreg.no/nb/oppslag/enheter/${u.organisasjonsnummer}`,
|
|
245
|
+
evidence: `Brønnøysund register: ${role.type?.beskrivelse ?? code} of ${u.navn} (${u.organisasjonsnummer})`,
|
|
246
|
+
confidence: conf(m, pm, 0.85),
|
|
247
|
+
}));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (out.length)
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
// ---------------------------------------------------------------- US SEC EDGAR (Form 4 insiders)
|
|
257
|
+
const tickerCache = new WeakMap();
|
|
258
|
+
function tickers(ctx, headers) {
|
|
259
|
+
let p = tickerCache.get(fetchKey(ctx.fetch));
|
|
260
|
+
if (!p) {
|
|
261
|
+
p = getJson(ctx.fetch, 'https://www.sec.gov/files/company_tickers.json', { headers }, 30000).then((r) => {
|
|
262
|
+
const seen = new Map();
|
|
263
|
+
for (const v of Object.values((r.data ?? {})))
|
|
264
|
+
if (!seen.has(v.cik_str))
|
|
265
|
+
seen.set(v.cik_str, String(v.title));
|
|
266
|
+
return [...seen].map(([cik, title]) => ({ cik, title }));
|
|
267
|
+
});
|
|
268
|
+
p.catch(() => tickerCache.delete(fetchKey(ctx.fetch)));
|
|
269
|
+
tickerCache.set(fetchKey(ctx.fetch), p);
|
|
270
|
+
}
|
|
271
|
+
return p;
|
|
272
|
+
}
|
|
273
|
+
/** "COOK TIMOTHY D (CIK 0001214156)" -> { name: "COOK, TIMOTHY D", cik: "0001214156" }. Form 4 names are "LAST FIRST MIDDLE". */
|
|
274
|
+
export function edgarOwner(display) {
|
|
275
|
+
const m = display.match(/^(.+?)\s+\(CIK (\d+)\)\s*$/);
|
|
276
|
+
if (!m)
|
|
277
|
+
return null;
|
|
278
|
+
const toks = m[1].trim().split(/\s+/);
|
|
279
|
+
if (toks.length < 2)
|
|
280
|
+
return null;
|
|
281
|
+
return { name: `${toks[0]}, ${toks.slice(1).join(' ')}`, cik: m[2] };
|
|
282
|
+
}
|
|
283
|
+
function xmlTag(block, tag) {
|
|
284
|
+
const m = block.match(new RegExp(`<${tag}>\\s*([^<]*?)\\s*</${tag}>`));
|
|
285
|
+
return m?.[1] || undefined;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* SEC EDGAR (free; SEC rejects requests without a contact User-Agent, so SEC_USER_AGENT="Name you@example.com" is required).
|
|
289
|
+
* company -> CIK via company_tickers.json (exact name or domain root only), then the person's latest Form 4 at that issuer
|
|
290
|
+
* in the last two years via full-text search, then officerTitle / isDirector from the Form 4 XML.
|
|
291
|
+
*/
|
|
292
|
+
export const secEdgarProvider = {
|
|
293
|
+
id: 'sec-edgar',
|
|
294
|
+
kind: 'free',
|
|
295
|
+
description: 'SEC EDGAR Form 4 insider filings (US public company officers and directors)',
|
|
296
|
+
provides: ['title', 'company', 'profile'],
|
|
297
|
+
keyEnv: 'SEC_USER_AGENT',
|
|
298
|
+
// SEC wants a contact in the User-Agent: SEC_USER_AGENT, or ENRICH_CONTACT if it is an email.
|
|
299
|
+
enabled: (env) => Boolean(env.SEC_USER_AGENT || /@/.test(env.ENRICH_CONTACT ?? '')),
|
|
300
|
+
needs: needsPersonAndCompany,
|
|
301
|
+
async run(q, ctx) {
|
|
302
|
+
const ua = ctx.env.SEC_USER_AGENT || (/@/.test(ctx.env.ENRICH_CONTACT ?? '') ? `openrich ${ctx.env.ENRICH_CONTACT}` : '');
|
|
303
|
+
if (!ua)
|
|
304
|
+
return [];
|
|
305
|
+
const headers = { 'User-Agent': ua, Accept: 'application/json' };
|
|
306
|
+
const issuers = (await tickers(ctx, headers)).filter((t) => companyMatch(t.title, q) === 'exact').slice(0, 2);
|
|
307
|
+
const since = new Date(Date.now() - 2 * 365 * 864e5).toISOString().slice(0, 10);
|
|
308
|
+
const until = new Date().toISOString().slice(0, 10);
|
|
309
|
+
for (const iss of issuers) {
|
|
310
|
+
const cik10 = String(iss.cik).padStart(10, '0');
|
|
311
|
+
const url = `https://efts.sec.gov/LATEST/search-index?q=${encodeURIComponent(`"${q.lastName}"`)}&forms=4&ciks=${cik10}` +
|
|
312
|
+
`&dateRange=custom&startdt=${since}&enddt=${until}`;
|
|
313
|
+
const r = await getJson(ctx.fetch, url, { headers });
|
|
314
|
+
const hits = (r.data?.hits?.hits ?? [])
|
|
315
|
+
.map((h) => {
|
|
316
|
+
const owner = (h._source?.display_names ?? [])
|
|
317
|
+
.map(edgarOwner)
|
|
318
|
+
.find((o) => o && o.cik !== cik10 && personMatch(o.name, q));
|
|
319
|
+
return owner ? { h, owner } : null;
|
|
320
|
+
})
|
|
321
|
+
.filter((x) => x !== null)
|
|
322
|
+
.sort((a, b) => String(b.h._source.file_date).localeCompare(String(a.h._source.file_date)));
|
|
323
|
+
const best = hits[0];
|
|
324
|
+
if (!best)
|
|
325
|
+
continue;
|
|
326
|
+
const [adsh, file] = String(best.h._id).split(':');
|
|
327
|
+
if (!adsh || !file)
|
|
328
|
+
continue;
|
|
329
|
+
const xmlUrl = `https://www.sec.gov/Archives/edgar/data/${iss.cik}/${adsh.replace(/-/g, '')}/${file}`;
|
|
330
|
+
const res = await ctx.fetch(xmlUrl, { headers: { 'User-Agent': ua }, signal: AbortSignal.timeout(15000) });
|
|
331
|
+
if (!res.ok)
|
|
332
|
+
continue;
|
|
333
|
+
const xml = await res.text();
|
|
334
|
+
const issuerName = xmlTag(xml, 'issuerName') ?? iss.title;
|
|
335
|
+
for (const block of xml.match(/<reportingOwner>[\s\S]*?<\/reportingOwner>/g) ?? []) {
|
|
336
|
+
const ownerName = xmlTag(block, 'rptOwnerName');
|
|
337
|
+
const pm = ownerName ? personMatch(edgarOwner(`${ownerName} (CIK 0)`)?.name ?? ownerName, q) : null;
|
|
338
|
+
if (!pm)
|
|
339
|
+
continue;
|
|
340
|
+
const isTrue = (t) => /^(1|true)$/i.test(xmlTag(block, t) ?? '');
|
|
341
|
+
const title = (isTrue('isOfficer') && xmlTag(block, 'officerTitle')) || (isTrue('isDirector') ? 'Director' : '');
|
|
342
|
+
if (!title)
|
|
343
|
+
continue; // a 10% owner is not a role at the company
|
|
344
|
+
return roleFindings('sec-edgar', {
|
|
345
|
+
title,
|
|
346
|
+
company: issuerName,
|
|
347
|
+
profile: `https://www.sec.gov/cgi-bin/browse-edgar?action=getcompany&CIK=${best.owner.cik}&type=4`,
|
|
348
|
+
evidence: `SEC Form 4 filed ${best.h._source.file_date} for ${issuerName}`,
|
|
349
|
+
confidence: conf('exact', pm, 0.9),
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return [];
|
|
354
|
+
},
|
|
355
|
+
};
|
|
356
|
+
// ---------------------------------------------------------------- UK Parliament
|
|
357
|
+
const isParliamentQuery = (q) => Boolean(q.domain?.endsWith('parliament.uk') || (q.company && /\b(uk parliament|parliament of the united kingdom|house of (commons|lords))\b/i.test(q.company)));
|
|
358
|
+
/** UK Parliament Members API (free, no key). Only for queries about Parliament itself. */
|
|
359
|
+
export const ukParliamentProvider = {
|
|
360
|
+
id: 'uk-parliament',
|
|
361
|
+
kind: 'free',
|
|
362
|
+
description: 'UK Parliament members (MPs and Lords)',
|
|
363
|
+
provides: ['title', 'company', 'profile', 'photo'],
|
|
364
|
+
needs: (q) => Boolean(q.firstName && q.lastName && isParliamentQuery(q)),
|
|
365
|
+
async run(q, ctx) {
|
|
366
|
+
const name = `${q.firstName} ${q.lastName}`;
|
|
367
|
+
const r = await getJson(ctx.fetch, `https://members-api.parliament.uk/api/Members/Search?Name=${encodeURIComponent(name)}&take=20`, {
|
|
368
|
+
headers: { 'User-Agent': UA, Accept: 'application/json' },
|
|
369
|
+
});
|
|
370
|
+
const ms = (r.data?.items ?? []).map((i) => i.value).filter((v) => v && sameName(v.nameDisplayAs, name));
|
|
371
|
+
if (ms.length !== 1)
|
|
372
|
+
return []; // none, or two members with the same name: do not guess
|
|
373
|
+
const m = ms[0];
|
|
374
|
+
const h = m.latestHouseMembership ?? {};
|
|
375
|
+
const ended = h.membershipEndDate && new Date(h.membershipEndDate).getTime() < Date.now();
|
|
376
|
+
const party = m.latestParty?.name ? ` (${m.latestParty.name})` : '';
|
|
377
|
+
const role = h.house === 2 ? 'Member of the House of Lords' : `Member of Parliament for ${h.membershipFrom ?? 'unknown'}`;
|
|
378
|
+
const out = roleFindings('uk-parliament', {
|
|
379
|
+
title: `${ended ? 'Former ' : ''}${role}${party}`,
|
|
380
|
+
company: h.house === 2 ? 'House of Lords' : 'House of Commons',
|
|
381
|
+
profile: `https://members.parliament.uk/member/${m.id}`,
|
|
382
|
+
evidence: `UK Parliament member ${m.id}`,
|
|
383
|
+
confidence: 0.85,
|
|
384
|
+
});
|
|
385
|
+
if (m.thumbnailUrl)
|
|
386
|
+
out.push({ field: 'photo', value: m.thumbnailUrl, source: 'uk-parliament', confidence: 0.8 });
|
|
387
|
+
return out;
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
export const REGISTRY_PROVIDERS = [
|
|
391
|
+
ukCompaniesHouseProvider,
|
|
392
|
+
frRechercheEntreprisesProvider,
|
|
393
|
+
noBrregProvider,
|
|
394
|
+
secEdgarProvider,
|
|
395
|
+
ukParliamentProvider,
|
|
396
|
+
];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PersonQuery, Provider } from '../types.ts';
|
|
2
|
+
/** Host or email domain equals the query domain or is a subdomain of it (cs.stanford.edu -> stanford.edu). */
|
|
3
|
+
export declare function onDomain(hostOrEmail: string | null | undefined, q: PersonQuery): boolean;
|
|
4
|
+
export declare function urlOnDomain(url: string | null | undefined, q: PersonQuery): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Does an institution name point at the query's company or domain?
|
|
7
|
+
* mentionsCompany, plus forms common for universities:
|
|
8
|
+
* an exact acronym token ("NYU" for nyu.edu), initials ("New York University" -> nyu),
|
|
9
|
+
* and the u-prefix form ("University of Toronto" -> utoronto.ca).
|
|
10
|
+
*/
|
|
11
|
+
export declare function orgMatches(text: string | null | undefined, q: PersonQuery): boolean;
|
|
12
|
+
/** Plausibly this person's mailbox: local part contains the last name (or exact first/last combos for short last names). */
|
|
13
|
+
export declare function plausibleLocal(local: string, first: string, last: string): boolean;
|
|
14
|
+
/** OpenAlex authors (free; OPENALEX_API_KEY or OPENALEX_MAILTO optional for a larger budget). */
|
|
15
|
+
export declare const openalexProvider: Provider;
|
|
16
|
+
/** ORCID public API v3 (free, no key). */
|
|
17
|
+
export declare const orcidProvider: Provider;
|
|
18
|
+
/** Semantic Scholar author search (free; SEMANTIC_SCHOLAR_API_KEY optional, unauthenticated pool is shared and 429s). */
|
|
19
|
+
export declare const semanticScholarProvider: Provider;
|
|
20
|
+
/** NSF Award Search (free, no key). PI email + awardee institution. */
|
|
21
|
+
export declare const nsfAwardsProvider: Provider;
|
|
22
|
+
/** NIH RePORTER v2 (free, no key). Organisation only: PI emails are not exposed. */
|
|
23
|
+
export declare const nihReporterProvider: Provider;
|
|
24
|
+
/** Europe PMC (free, no key). Author affiliation strings, which often carry the author's email. */
|
|
25
|
+
export declare const europePmcProvider: Provider;
|
|
26
|
+
/** OpenReview profiles. Search now requires a logged-in token (OPENREVIEW_TOKEN); guests get 403. */
|
|
27
|
+
export declare const openreviewProvider: Provider;
|
|
28
|
+
/** INSPIRE-HEP authors (free, no key). High-energy physics. */
|
|
29
|
+
export declare const inspireHepProvider: Provider;
|
|
30
|
+
export declare const RESEARCH_PROVIDERS: Provider[];
|