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.
Files changed (65) hide show
  1. package/.env.example +23 -0
  2. package/LICENSE +21 -0
  3. package/README.md +410 -2
  4. package/assets/logo.svg +41 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +144 -0
  7. package/dist/env.d.ts +5 -0
  8. package/dist/env.js +24 -0
  9. package/dist/eval.d.ts +30 -0
  10. package/dist/eval.js +78 -0
  11. package/dist/mcp/client.d.ts +31 -0
  12. package/dist/mcp/client.js +94 -0
  13. package/dist/mcp/oauth.d.ts +13 -0
  14. package/dist/mcp/oauth.js +93 -0
  15. package/dist/mcp/server.d.ts +87 -0
  16. package/dist/mcp/server.js +125 -0
  17. package/dist/merge.d.ts +7 -0
  18. package/dist/merge.js +39 -0
  19. package/dist/providers/devplatforms.d.ts +34 -0
  20. package/dist/providers/devplatforms.js +612 -0
  21. package/dist/providers/finders.d.ts +38 -0
  22. package/dist/providers/finders.js +708 -0
  23. package/dist/providers/freetier.d.ts +9 -0
  24. package/dist/providers/freetier.js +254 -0
  25. package/dist/providers/github.d.ts +8 -0
  26. package/dist/providers/github.js +109 -0
  27. package/dist/providers/identity.d.ts +5 -0
  28. package/dist/providers/identity.js +62 -0
  29. package/dist/providers/index.d.ts +10 -0
  30. package/dist/providers/index.js +68 -0
  31. package/dist/providers/knowledge.d.ts +52 -0
  32. package/dist/providers/knowledge.js +302 -0
  33. package/dist/providers/pattern.d.ts +6 -0
  34. package/dist/providers/pattern.js +99 -0
  35. package/dist/providers/registries.d.ts +36 -0
  36. package/dist/providers/registries.js +396 -0
  37. package/dist/providers/research.d.ts +30 -0
  38. package/dist/providers/research.js +471 -0
  39. package/dist/providers/signals.d.ts +15 -0
  40. package/dist/providers/signals.js +116 -0
  41. package/dist/providers/smtp.d.ts +25 -0
  42. package/dist/providers/smtp.js +97 -0
  43. package/dist/providers/social.d.ts +37 -0
  44. package/dist/providers/social.js +657 -0
  45. package/dist/providers/verifiers.d.ts +47 -0
  46. package/dist/providers/verifiers.js +455 -0
  47. package/dist/providers/websearch.d.ts +32 -0
  48. package/dist/providers/websearch.js +346 -0
  49. package/dist/router.d.ts +31 -0
  50. package/dist/router.js +214 -0
  51. package/dist/server.d.ts +2 -0
  52. package/dist/server.js +52 -0
  53. package/dist/store.d.ts +32 -0
  54. package/dist/store.js +95 -0
  55. package/dist/types.d.ts +82 -0
  56. package/dist/types.js +1 -0
  57. package/dist/util/http.d.ts +19 -0
  58. package/dist/util/http.js +34 -0
  59. package/dist/util/match.d.ts +23 -0
  60. package/dist/util/match.js +72 -0
  61. package/dist/util/names.d.ts +11 -0
  62. package/dist/util/names.js +56 -0
  63. package/dist/util/patterns.d.ts +14 -0
  64. package/dist/util/patterns.js +61 -0
  65. package/package.json +55 -4
@@ -0,0 +1,708 @@
1
+ import { getJson, HttpError, QuotaExceeded } from "../util/http.js";
2
+ import { mentionsCompany, sameName } from "../util/match.js";
3
+ /**
4
+ * More email finders on their free plans. Each uses the user's OWN key, one account, no rotation.
5
+ * Built from each vendor's official API docs (Dec 2026); none has been live-verified with a real key.
6
+ * Quota = hits per period (the router counts only calls that returned findings), taken from the
7
+ * vendor's free plan. One-time signup credits are modelled as a month and say "one-time".
8
+ *
9
+ * Confidence: verified/valid 0.88-0.9, risky/catch-all 0.5, unknown 0.4, extra fields 0.7.
10
+ * Masked or partial emails are dropped.
11
+ */
12
+ /** Waits between polls. Tests replace `timing.sleep` so they run without real delays. */
13
+ export const timing = { sleep: (ms) => new Promise((r) => setTimeout(r, ms)), maxWaitMs: 60_000 };
14
+ const s = (v) => (typeof v === 'string' && v.trim() ? v.trim() : null);
15
+ const isEmail = (v) => typeof v === 'string' && /^[^\s@*]+@[^\s@*]+\.[^\s@*]+$/.test(v.trim());
16
+ const url = (v) => { const x = s(v); return x ? (/^https?:\/\//.test(x) ? x : `https://${x}`) : null; };
17
+ const place = (...parts) => parts.map(s).filter(Boolean).join(', ') || null;
18
+ const needsNameDomain = (q) => Boolean(q.firstName && q.lastName && q.domain && !q.email);
19
+ const needsNameCompany = (q) => Boolean(q.name && (q.domain || q.company) && !q.email);
20
+ /** Collects findings for one source; skips empty values and non-emails. */
21
+ function collector(source) {
22
+ const out = [];
23
+ return {
24
+ out,
25
+ email(v, confidence, evidence) {
26
+ if (isEmail(v))
27
+ out.push({ field: 'email', value: v.trim().toLowerCase(), source, confidence, evidence });
28
+ },
29
+ add(field, v, confidence = 0.7) {
30
+ const x = s(v);
31
+ if (x)
32
+ out.push({ field, value: x, source, confidence });
33
+ },
34
+ };
35
+ }
36
+ /**
37
+ * Polls `step` with backoff until it returns a value (not undefined), for at most timing.maxWaitMs.
38
+ * Returns null when it gave up.
39
+ */
40
+ async function poll(step, firstMs = 1000, maxStepMs = 8000) {
41
+ let waited = 0;
42
+ let ms = firstMs;
43
+ while (waited < timing.maxWaitMs) {
44
+ await timing.sleep(ms);
45
+ waited += ms;
46
+ const r = await step();
47
+ if (r !== undefined)
48
+ return r;
49
+ ms = Math.min(maxStepMs, ms * 2);
50
+ }
51
+ return null;
52
+ }
53
+ /** fetch + JSON body without throwing on HTTP status (for APIs that put errors in the body). */
54
+ async function call(ctx, u, init = {}, timeoutMs = 30000) {
55
+ const res = await ctx.fetch(u, { ...init, signal: AbortSignal.timeout(timeoutMs) });
56
+ const text = await res.text();
57
+ let j = null;
58
+ try {
59
+ j = text ? JSON.parse(text) : null;
60
+ }
61
+ catch { /* not JSON */ }
62
+ return { status: res.status, j, text };
63
+ }
64
+ const CREDITS = /credit|quota|limit reached|insufficient|exceeded/i;
65
+ // ---------------------------------------------------------------- Tomba
66
+ // Docs: https://docs.tomba.io/api/finder GET /v1/email-finder, headers X-Tomba-Key / X-Tomba-Secret.
67
+ export const tombaProvider = {
68
+ id: 'tomba',
69
+ kind: 'free-tier',
70
+ description: 'Tomba Email Finder (free plan: 25 searches/month, API included)',
71
+ provides: ['email', 'title', 'linkedin', 'company', 'location', 'twitter'],
72
+ keyEnv: 'TOMBA_KEY',
73
+ enabled: (env) => Boolean(env.TOMBA_KEY && env.TOMBA_SECRET),
74
+ quota: { limit: 25, period: 'month' },
75
+ needs: (q) => Boolean(q.name && (q.domain || q.company) && !q.email),
76
+ async run(q, ctx) {
77
+ const p = new URLSearchParams();
78
+ if (q.domain)
79
+ p.set('domain', q.domain);
80
+ else
81
+ p.set('company', q.company);
82
+ if (q.firstName && q.lastName) {
83
+ p.set('first_name', q.firstName);
84
+ p.set('last_name', q.lastName);
85
+ }
86
+ else
87
+ p.set('full_name', q.name);
88
+ const r = await getJson(ctx.fetch, `https://api.tomba.io/v1/email-finder?${p}`, {
89
+ headers: { 'X-Tomba-Key': ctx.env.TOMBA_KEY, 'X-Tomba-Secret': ctx.env.TOMBA_SECRET },
90
+ });
91
+ const d = r.data?.data;
92
+ if (!d?.email)
93
+ return [];
94
+ const st = String(d.verification?.status ?? '').toLowerCase();
95
+ const conf = st === 'valid' ? 0.88 : st === 'accept_all' || d.accept_all ? 0.5 : st === 'invalid' ? 0 : 0.4;
96
+ const c = collector('tomba');
97
+ if (conf > 0)
98
+ c.email(d.email, conf, `verification ${st || 'none'}, score ${d.score ?? '?'}`);
99
+ c.add('title', d.position);
100
+ c.add('linkedin', url(d.linkedin));
101
+ c.add('twitter', d.twitter ? url(String(d.twitter).includes('/') ? d.twitter : `x.com/${d.twitter}`) : null);
102
+ c.add('company', d.company);
103
+ c.add('location', d.country);
104
+ return c.out;
105
+ },
106
+ };
107
+ // ---------------------------------------------------------------- Snov.io
108
+ // Docs: https://snov.io/api OAuth client credentials, then v2 emails-by-domain-by-name start + result (async).
109
+ const snovTokens = new Map();
110
+ async function snovToken(ctx) {
111
+ const id = ctx.env.SNOV_CLIENT_ID;
112
+ const hit = snovTokens.get(id);
113
+ if (hit && hit.until > Date.now())
114
+ return hit.token;
115
+ const r = await getJson(ctx.fetch, 'https://api.snov.io/v1/oauth/access_token', {
116
+ method: 'POST',
117
+ headers: { 'content-type': 'application/x-www-form-urlencoded' },
118
+ body: new URLSearchParams({ grant_type: 'client_credentials', client_id: id, client_secret: ctx.env.SNOV_CLIENT_SECRET }).toString(),
119
+ });
120
+ const token = r.data?.access_token;
121
+ if (!token)
122
+ throw new Error('snov: no access_token in OAuth reply');
123
+ snovTokens.set(id, { token, until: Date.now() + (Number(r.data.expires_in ?? 3600) - 60) * 1000 });
124
+ return token;
125
+ }
126
+ export const snovProvider = {
127
+ id: 'snov',
128
+ kind: 'free-tier',
129
+ description: 'Snov.io Email Finder v2 (free plan: 50 credits/month, renews monthly)',
130
+ provides: ['email'],
131
+ keyEnv: 'SNOV_CLIENT_ID',
132
+ enabled: (env) => Boolean(env.SNOV_CLIENT_ID && env.SNOV_CLIENT_SECRET),
133
+ quota: { limit: 50, period: 'month' },
134
+ needs: needsNameDomain,
135
+ async run(q, ctx) {
136
+ const headers = { authorization: `Bearer ${await snovToken(ctx)}`, 'content-type': 'application/json' };
137
+ const start = await getJson(ctx.fetch, 'https://api.snov.io/v2/emails-by-domain-by-name/start', {
138
+ method: 'POST', headers, body: JSON.stringify({ rows: [{ first_name: q.firstName, last_name: q.lastName, domain: q.domain }] }),
139
+ });
140
+ const hash = start.data?.data?.task_hash;
141
+ if (!hash)
142
+ return [];
143
+ const done = await poll(async () => {
144
+ const r = await getJson(ctx.fetch, `https://api.snov.io/v2/emails-by-domain-by-name/result?task_hash=${encodeURIComponent(hash)}`, { headers });
145
+ const d = r.data;
146
+ if (d?.status === 'not_enough_credits')
147
+ throw new QuotaExceeded('snov: not enough credits');
148
+ if (d?.status === 'in_progress' || !d)
149
+ return undefined;
150
+ return d;
151
+ });
152
+ if (!done) {
153
+ ctx.log('snov: gave up waiting for result');
154
+ return [];
155
+ }
156
+ const c = collector('snov');
157
+ for (const row of done.data ?? []) {
158
+ for (const e of row.result ?? []) {
159
+ const st = String(e.smtp_status ?? '');
160
+ if (st === 'valid')
161
+ c.email(e.email, 0.88, 'smtp valid');
162
+ else if (st === 'unknown')
163
+ c.email(e.email, e.unknown_status_reason === 'catchall' ? 0.5 : 0.4, `smtp unknown (${e.unknown_status_reason ?? '?'})`);
164
+ }
165
+ }
166
+ return c.out;
167
+ },
168
+ };
169
+ // ---------------------------------------------------------------- Skrapp
170
+ // Docs: https://skrapp.io/api GET /api/v3/people/email, header X-Access-Key.
171
+ export const skrappProvider = {
172
+ id: 'skrapp',
173
+ kind: 'free-tier',
174
+ description: 'Skrapp Email Finder (free plan: about 50 email credits/month, API included; 150 searches/day cap)',
175
+ provides: ['email', 'company'],
176
+ keyEnv: 'SKRAPP_API_KEY',
177
+ quota: { limit: 50, period: 'month' },
178
+ needs: needsNameCompany,
179
+ async run(q, ctx) {
180
+ const p = new URLSearchParams();
181
+ if (q.firstName && q.lastName) {
182
+ p.set('firstName', q.firstName);
183
+ p.set('lastName', q.lastName);
184
+ }
185
+ else
186
+ p.set('fullName', q.name);
187
+ if (q.domain)
188
+ p.set('domain', q.domain);
189
+ else
190
+ p.set('company', q.company);
191
+ const r = await call(ctx, `https://api.skrapp.io/api/v3/people/email?${p}`, { headers: { 'X-Access-Key': ctx.env.SKRAPP_API_KEY } });
192
+ if (r.status === 429 || r.j?.email_limit_exeeded || (r.status === 403 && /forbidden|insufficient/i.test(r.text))) {
193
+ throw new QuotaExceeded(`skrapp HTTP ${r.status}`);
194
+ }
195
+ if (r.status === 404)
196
+ return [];
197
+ if (r.status === 408) {
198
+ ctx.log('skrapp: search timed out (408), not charged');
199
+ return [];
200
+ }
201
+ if (r.status >= 400)
202
+ throw new HttpError(r.status, r.text, 'https://api.skrapp.io/');
203
+ const st = String(r.j?.quality?.status ?? '').toLowerCase();
204
+ const conf = st === 'valid' ? 0.88 : st === 'catch-all' ? 0.5 : st === 'unknown' ? 0.4 : 0;
205
+ const c = collector('skrapp');
206
+ if (conf > 0)
207
+ c.email(r.j?.email, conf, `quality ${st}`);
208
+ if (c.out.length)
209
+ c.add('company', r.j?.companyData?.name);
210
+ return c.out;
211
+ },
212
+ };
213
+ // ---------------------------------------------------------------- VoilaNorbert
214
+ // Docs: https://api.voilanorbert.com/2018-01-08/ POST /search/name (Basic auth, key as password), poll /contacts/{id}.
215
+ const NORBERT = 'https://api.voilanorbert.com/2018-01-08';
216
+ function norbertFindings(d) {
217
+ const e = d?.email;
218
+ const c = collector('voilanorbert');
219
+ if (!e?.email)
220
+ return [];
221
+ const score = Number(e.score ?? 0);
222
+ c.email(e.email, score >= 100 ? 0.88 : score >= 80 ? 0.5 : 0.4, `score ${score}`);
223
+ return c.out;
224
+ }
225
+ export const voilanorbertProvider = {
226
+ id: 'voilanorbert',
227
+ kind: 'free-tier',
228
+ description: 'VoilaNorbert Search by name (free: first 50 leads, one-time; misses not charged)',
229
+ provides: ['email'],
230
+ keyEnv: 'VOILANORBERT_API_KEY',
231
+ quota: { limit: 50, period: 'month' },
232
+ needs: needsNameCompany,
233
+ async run(q, ctx) {
234
+ const auth = `Basic ${Buffer.from(`any:${ctx.env.VOILANORBERT_API_KEY}`).toString('base64')}`;
235
+ const body = new URLSearchParams({ name: q.name });
236
+ if (q.domain)
237
+ body.set('domain', q.domain);
238
+ else
239
+ body.set('company', q.company);
240
+ const start = await getJson(ctx.fetch, `${NORBERT}/search/name`, {
241
+ method: 'POST', headers: { authorization: auth, 'content-type': 'application/x-www-form-urlencoded' }, body: body.toString(),
242
+ });
243
+ const d = start.data;
244
+ if (!d)
245
+ return [];
246
+ if (!d.searching)
247
+ return norbertFindings(d);
248
+ const done = await poll(async () => {
249
+ const r = await getJson(ctx.fetch, `${NORBERT}/contacts/${encodeURIComponent(d.id)}`, { headers: { authorization: auth } });
250
+ return r.data?.searching === false ? r.data : undefined;
251
+ }, 2000, 10000);
252
+ if (!done) {
253
+ ctx.log('voilanorbert: gave up waiting for result');
254
+ return [];
255
+ }
256
+ return norbertFindings(done);
257
+ },
258
+ };
259
+ // ---------------------------------------------------------------- Dropcontact
260
+ // Docs: https://developer.dropcontact.com/ POST /v1/enrich/all, poll GET /v1/enrich/all/{request_id}, header X-Access-Token.
261
+ export const dropcontactProvider = {
262
+ id: 'dropcontact',
263
+ kind: 'free-tier',
264
+ description: 'Dropcontact enrich (trial: 50 credits, one-time; charged only for a verified email; API on trial unclear)',
265
+ provides: ['email', 'title', 'linkedin', 'company', 'phone'],
266
+ keyEnv: 'DROPCONTACT_API_KEY',
267
+ quota: { limit: 50, period: 'month' },
268
+ needs: (q) => Boolean(q.firstName && q.lastName && (q.domain || q.company) && !q.email),
269
+ async run(q, ctx) {
270
+ const headers = { 'X-Access-Token': ctx.env.DROPCONTACT_API_KEY, 'content-type': 'application/json' };
271
+ const rec = { first_name: q.firstName, last_name: q.lastName };
272
+ if (q.domain)
273
+ rec.website = q.domain;
274
+ if (q.company)
275
+ rec.company = q.company;
276
+ const start = await call(ctx, 'https://api.dropcontact.com/v1/enrich/all', {
277
+ method: 'POST', headers, body: JSON.stringify({ data: [rec], siren: false, language: 'en' }),
278
+ });
279
+ if (start.status === 429 || start.status === 402 || (start.status === 403 && CREDITS.test(String(start.j?.reason ?? start.text)))) {
280
+ throw new QuotaExceeded(`dropcontact: ${start.j?.reason ?? `HTTP ${start.status}`}`);
281
+ }
282
+ if (start.status >= 400 || start.j?.error)
283
+ throw new HttpError(start.status, start.text, 'https://api.dropcontact.com/');
284
+ const id = start.j?.request_id;
285
+ if (!id)
286
+ return [];
287
+ const done = await poll(async () => {
288
+ const r = await call(ctx, `https://api.dropcontact.com/v1/enrich/all/${encodeURIComponent(id)}`, { headers });
289
+ if (r.status === 429)
290
+ return undefined; // rate limited while polling: keep waiting
291
+ if (r.status >= 400)
292
+ throw new HttpError(r.status, r.text, 'https://api.dropcontact.com/');
293
+ return r.j?.success && Array.isArray(r.j.data) ? r.j : undefined; // success:false = not ready yet
294
+ }, 5000, 15000);
295
+ if (!done) {
296
+ ctx.log('dropcontact: gave up waiting for result');
297
+ return [];
298
+ }
299
+ const d = done.data[0];
300
+ if (!d)
301
+ return [];
302
+ const c = collector('dropcontact');
303
+ for (const e of Array.isArray(d.email) ? d.email : []) {
304
+ const qual = String(e?.qualification ?? '').toLowerCase();
305
+ if (/^(nominative|nominatif)@pro/.test(qual))
306
+ c.email(e.email, 0.9, `qualification ${qual}`);
307
+ else if (/catch/.test(qual) && /@pro/.test(qual))
308
+ c.email(e.email, 0.5, `qualification ${qual}`);
309
+ }
310
+ if (!c.out.length)
311
+ return [];
312
+ c.add('title', d.job);
313
+ c.add('linkedin', url(d.linkedin));
314
+ c.add('company', d.company);
315
+ c.add('phone', d.mobile_phone);
316
+ return c.out;
317
+ },
318
+ };
319
+ // ---------------------------------------------------------------- Icypeas
320
+ // Docs: https://api-doc.icypeas.com/ POST /api/email-search, poll POST /api/bulk-single-searchs/read {id}.
321
+ const ICY = 'https://app.icypeas.com/api';
322
+ const ICY_PENDING = new Set(['NONE', 'SCHEDULED', 'IN_PROGRESS']);
323
+ export const icypeasProvider = {
324
+ id: 'icypeas',
325
+ kind: 'free-tier',
326
+ description: 'Icypeas Email Search (free: 50 signup credits, one-time; 1 credit per email found; API on free credits unclear)',
327
+ provides: ['email'],
328
+ keyEnv: 'ICYPEAS_API_KEY',
329
+ quota: { limit: 50, period: 'month' },
330
+ needs: (q) => Boolean((q.firstName || q.lastName) && (q.domain || q.company) && !q.email),
331
+ async run(q, ctx) {
332
+ const headers = { authorization: ctx.env.ICYPEAS_API_KEY, 'content-type': 'application/json' };
333
+ const check = (r) => {
334
+ const code = JSON.stringify(r.j?.validationErrors ?? r.j?.message ?? r.j?.error ?? '');
335
+ if (r.status === 429 || r.status === 402 || /insufficient|unpaid|rate_limit/i.test(code))
336
+ throw new QuotaExceeded(`icypeas: ${code || r.status}`);
337
+ if (r.status >= 400 || r.j?.success === false)
338
+ throw new HttpError(r.status, r.text, `${ICY}/`);
339
+ };
340
+ const start = await call(ctx, `${ICY}/email-search`, {
341
+ method: 'POST', headers, body: JSON.stringify({ firstname: q.firstName ?? '', lastname: q.lastName ?? '', domainOrCompany: q.domain ?? q.company }),
342
+ });
343
+ check(start);
344
+ const id = start.j?.item?._id;
345
+ if (!id)
346
+ return [];
347
+ // read endpoint is limited to 30 requests/minute: start at 2s, back off to 8s.
348
+ const item = await poll(async () => {
349
+ const r = await call(ctx, `${ICY}/bulk-single-searchs/read`, { method: 'POST', headers, body: JSON.stringify({ id }) });
350
+ if (r.status === 429)
351
+ return undefined;
352
+ check(r);
353
+ const it = r.j?.items?.[0];
354
+ return it && !ICY_PENDING.has(it.status) ? it : undefined;
355
+ }, 2000);
356
+ if (!item) {
357
+ ctx.log('icypeas: gave up waiting for result');
358
+ return [];
359
+ }
360
+ if (item.status === 'INSUFFICIENT_FUNDS')
361
+ throw new QuotaExceeded('icypeas: insufficient funds');
362
+ if (item.status !== 'FOUND' && item.status !== 'DEBITED')
363
+ return [];
364
+ const c = collector('icypeas');
365
+ for (const e of item.results?.emails ?? []) {
366
+ const cert = String(e.certainty ?? '');
367
+ if (cert === 'ultra_sure' || cert === 'very_sure')
368
+ c.email(e.email, 0.9, `certainty ${cert}`);
369
+ else if (cert === 'sure')
370
+ c.email(e.email, 0.88, `certainty ${cert}`);
371
+ else if (cert === 'probable')
372
+ c.email(e.email, 0.5, `certainty ${cert}`);
373
+ }
374
+ return c.out;
375
+ },
376
+ };
377
+ // ---------------------------------------------------------------- CUFinder
378
+ // Docs: https://apidoc.cufinder.io/apis/person-enrichment.md (fields, errors). Path /v2/tep and
379
+ // form encoding come from CUFinder's official TypeScript SDK (@cufinder/cufinder-ts 1.6.0); the docs page omits the path.
380
+ export const cufinderProvider = {
381
+ id: 'cufinder',
382
+ kind: 'free-tier',
383
+ description: 'CUFinder Person Enrichment (free plan: 50 credits/month, about 16 hits since a hit with work email costs 3; API on free plan unclear)',
384
+ provides: ['email', 'title', 'linkedin', 'location', 'company', 'phone'],
385
+ keyEnv: 'CUFINDER_API_KEY',
386
+ quota: { limit: 16, period: 'month' },
387
+ needs: needsNameCompany,
388
+ async run(q, ctx) {
389
+ const r = await call(ctx, 'https://api.cufinder.io/v2/tep', {
390
+ method: 'POST',
391
+ headers: { 'x-api-key': ctx.env.CUFINDER_API_KEY, 'content-type': 'application/x-www-form-urlencoded' },
392
+ body: new URLSearchParams({ full_name: q.name, company: q.domain ?? q.company }).toString(),
393
+ });
394
+ const code = String(r.j?.error?.code ?? r.j?.message ?? '');
395
+ if (r.status === 402 || r.status === 429 || /insufficient_credits|rate_limited/.test(code) || (r.status === 400 && CREDITS.test(r.text))) {
396
+ throw new QuotaExceeded(`cufinder: ${code || r.status}`);
397
+ }
398
+ if (code === 'not_found' || r.status === 404)
399
+ return [];
400
+ if (r.status >= 400 || r.j?.success === false)
401
+ throw new HttpError(r.status, r.text, 'https://api.cufinder.io/');
402
+ const p = r.j?.data?.person ?? r.j?.data?.data?.person ?? r.j?.person;
403
+ if (!p || (p.full_name && !sameName(p.full_name, q.name)))
404
+ return [];
405
+ const c = collector('cufinder');
406
+ const w = p.emails?.work_email;
407
+ if (w?.email) {
408
+ const acc = Number(w.accuracy ?? 0);
409
+ c.email(w.email, w.is_catch_all_email ? 0.5 : acc >= 90 ? 0.88 : 0.4, `accuracy ${acc}${w.is_catch_all_email ? ', catch-all' : ''}`);
410
+ }
411
+ c.add('title', p.job?.title);
412
+ c.add('linkedin', url(p.social?.linkedin_url));
413
+ c.add('location', place(p.location?.city, p.location?.state, p.location?.country));
414
+ const cur = (p.experiences ?? []).find((x) => x?.is_primary) ?? r.j?.data?.company;
415
+ c.add('company', cur?.company?.name ?? cur?.name);
416
+ const ph = (p.phones ?? [])[0];
417
+ c.add('phone', typeof ph === 'string' ? ph : ph?.number ?? ph?.phone);
418
+ return c.out;
419
+ },
420
+ };
421
+ // ---------------------------------------------------------------- Minelead
422
+ // Docs: https://minelead.io/docs/ (OpenAPI api_docs.yml) GET /v1/find/?domain&firstname&lastname&key.
423
+ export const mineleadProvider = {
424
+ id: 'minelead',
425
+ kind: 'free-tier',
426
+ description: 'Minelead Email Finder (free plan: 25 credits/month, API included; each lookup costs 1, no verification status)',
427
+ provides: ['email'],
428
+ keyEnv: 'MINELEAD_API_KEY',
429
+ quota: { limit: 25, period: 'month' },
430
+ needs: needsNameDomain,
431
+ async run(q, ctx) {
432
+ const p = new URLSearchParams({ domain: q.domain, firstname: q.firstName, lastname: q.lastName, key: ctx.env.MINELEAD_API_KEY });
433
+ const r = await call(ctx, `https://api.minelead.io/v1/find/?${p}`);
434
+ if (r.status === 402 || r.status === 429 || (r.j?.status === 'error' && CREDITS.test(String(r.j?.message))))
435
+ throw new QuotaExceeded(`minelead: ${r.j?.message ?? r.status}`);
436
+ if (r.status === 404)
437
+ return [];
438
+ if (r.status >= 400)
439
+ throw new HttpError(r.status, r.text, 'https://api.minelead.io/');
440
+ if (r.j?.status !== 'success')
441
+ return [];
442
+ const c = collector('minelead');
443
+ c.email(r.j.email, 0.4, 'found, not verified');
444
+ return c.out;
445
+ },
446
+ };
447
+ // ---------------------------------------------------------------- GetEmail.io
448
+ // Docs: https://getemail.io/api/ GET /v2/find-email?api_key&fullname&domain, poll /v2/status-find-email?id.
449
+ export const getemailProvider = {
450
+ id: 'getemail',
451
+ kind: 'free-tier',
452
+ description: 'GetEmail.io Find Email (free plan: 10 credits/month, API included; every request costs 1, found or not)',
453
+ provides: ['email', 'title', 'linkedin', 'location'],
454
+ keyEnv: 'GETEMAIL_API_KEY',
455
+ quota: { limit: 10, period: 'month' },
456
+ needs: (q) => Boolean(q.name && q.domain && !q.email),
457
+ async run(q, ctx) {
458
+ const key = ctx.env.GETEMAIL_API_KEY;
459
+ const first = await getJson(ctx.fetch, `https://api.getemail.io/v2/find-email?${new URLSearchParams({ api_key: key, fullname: q.name, domain: q.domain, isEnrichToDo: 'true' })}`);
460
+ let d = first.data;
461
+ if (CREDITS.test(String(d?.code ?? '')) || /credit/i.test(String(d?.message ?? '')))
462
+ throw new QuotaExceeded(`getemail: ${d?.message ?? d?.code}`);
463
+ if (d && !d.is_terminated && d.id) {
464
+ d = await poll(async () => {
465
+ const r = await getJson(ctx.fetch, `https://api.getemail.io/v2/status-find-email?${new URLSearchParams({ id: String(d.id), api_key: key })}`);
466
+ return r.data?.is_terminated ? r.data : undefined;
467
+ }, 2000);
468
+ if (!d) {
469
+ ctx.log('getemail: gave up waiting for result');
470
+ return [];
471
+ }
472
+ }
473
+ if (!d?.is_success || !d.email)
474
+ return [];
475
+ const good = (d.email_search_details ?? []).flatMap((x) => x?.good_email ?? []).some((x) => String(x?.email).toLowerCase() === String(d.email).toLowerCase());
476
+ const c = collector('getemail');
477
+ c.email(d.email, good || /good/i.test(String(d.message)) ? 0.88 : 0.4, String(d.message ?? d.code ?? ''));
478
+ const en = d.enrich_data;
479
+ if (c.out.length && en) {
480
+ c.add('title', en.title ?? en.position);
481
+ c.add('linkedin', url(en.lkProfileLink));
482
+ c.add('location', en.locality);
483
+ }
484
+ return c.out;
485
+ },
486
+ };
487
+ // ---------------------------------------------------------------- Datagma
488
+ // Docs: https://datagmaapi.readme.io/ GET gateway.datagma.net/api/ingress/v8/findEmail?apiId&fullName&company.
489
+ export const datagmaProvider = {
490
+ id: 'datagma',
491
+ kind: 'free-tier',
492
+ description: 'Datagma Find Email (free plan: 100 credits/month per pricing page, API included; charged only for verified email)',
493
+ provides: ['email'],
494
+ keyEnv: 'DATAGMA_API_KEY',
495
+ quota: { limit: 100, period: 'month' },
496
+ needs: needsNameCompany,
497
+ async run(q, ctx) {
498
+ const p = new URLSearchParams({ apiId: ctx.env.DATAGMA_API_KEY, company: q.domain ?? q.company });
499
+ if (q.firstName && q.lastName) {
500
+ p.set('firstName', q.firstName);
501
+ p.set('lastName', q.lastName);
502
+ }
503
+ else
504
+ p.set('fullName', q.name);
505
+ const r = await call(ctx, `https://gateway.datagma.net/api/ingress/v8/findEmail?${p}`);
506
+ if (r.status === 402 || r.status === 429 || (r.status >= 400 && CREDITS.test(String(r.j?.message ?? r.text))))
507
+ throw new QuotaExceeded(`datagma: ${r.j?.message ?? r.status}`);
508
+ if (r.status === 404)
509
+ return [];
510
+ if (r.status >= 400)
511
+ throw new HttpError(r.status, r.text, 'https://gateway.datagma.net/');
512
+ const d = r.j?.email ? r.j : r.j?.data;
513
+ if (!d?.email)
514
+ return [];
515
+ const st = String(d.status ?? '').toLowerCase();
516
+ const c = collector('datagma');
517
+ c.email(d.email, st === 'verified' || st === 'valid' ? (d.cachAll ? 0.5 : 0.88) : d.cachAll || /probable|catch/.test(st) ? 0.5 : 0.4, `status ${st || '?'}${d.cachAll ? ', catch-all' : ''}`);
518
+ return c.out;
519
+ },
520
+ };
521
+ // ---------------------------------------------------------------- Apollo
522
+ // Docs: https://docs.apollo.io/reference/people-enrichment POST /api/v1/people/match (query params), header x-api-key.
523
+ export const apolloProvider = {
524
+ id: 'apollo',
525
+ kind: 'free-tier',
526
+ description: 'Apollo People Enrichment (free plan: API allowed for accounts on a work email per docs, pricing FAQ disagrees; credits ~75/month unverified)',
527
+ provides: ['email', 'title', 'linkedin', 'location', 'company', 'name'],
528
+ keyEnv: 'APOLLO_API_KEY',
529
+ quota: { limit: 75, period: 'month' },
530
+ needs: (q) => Boolean(q.name && (q.domain || q.company) && !q.email),
531
+ async run(q, ctx) {
532
+ const p = new URLSearchParams({ reveal_personal_emails: 'false', reveal_phone_number: 'false' });
533
+ if (q.firstName && q.lastName) {
534
+ p.set('first_name', q.firstName);
535
+ p.set('last_name', q.lastName);
536
+ }
537
+ else
538
+ p.set('name', q.name);
539
+ if (q.domain)
540
+ p.set('domain', q.domain);
541
+ else
542
+ p.set('organization_name', q.company);
543
+ const r = await call(ctx, `https://api.apollo.io/api/v1/people/match?${p}`, {
544
+ method: 'POST', headers: { 'x-api-key': ctx.env.APOLLO_API_KEY, 'content-type': 'application/json', 'cache-control': 'no-cache' },
545
+ });
546
+ const code = String(r.j?.error_details?.code ?? r.j?.error_code ?? r.j?.error ?? '');
547
+ if (r.status === 429 || r.status === 402 || /RATE_LIMIT|credit/i.test(code) || CREDITS.test(String(r.j?.error ?? '')))
548
+ throw new QuotaExceeded(`apollo: ${code || r.status}`);
549
+ if (r.status === 403 && /API_ACCESS_NOT_ENABLED/.test(code + r.text))
550
+ throw new Error('apollo: this plan has no API access (API_ACCESS_NOT_ENABLED)');
551
+ if (r.status === 404)
552
+ return [];
553
+ if (r.status >= 400)
554
+ throw new HttpError(r.status, r.text, 'https://api.apollo.io/');
555
+ const d = r.j?.person;
556
+ if (!d || d.match_confidence === 'none' || !sameName(d.name ?? `${d.first_name ?? ''} ${d.last_name ?? ''}`, q.name))
557
+ return [];
558
+ const c = collector('apollo');
559
+ const em = String(d.email ?? '');
560
+ if (em && !/email_not_unlocked/i.test(em)) {
561
+ const st = String(d.email_status ?? '');
562
+ if (st === 'verified')
563
+ c.email(em, 0.88, 'email_status verified');
564
+ else if (st === 'extrapolated')
565
+ c.email(em, 0.5, 'email_status extrapolated');
566
+ }
567
+ c.add('name', d.name);
568
+ c.add('title', d.title);
569
+ c.add('linkedin', url(d.linkedin_url));
570
+ c.add('location', place(d.city, d.state, d.country));
571
+ c.add('company', d.organization?.name);
572
+ return c.out;
573
+ },
574
+ };
575
+ // ---------------------------------------------------------------- Diffbot
576
+ // Docs: https://www.diffbot.com/docs/enhance/get , ontology https://www.diffbot.com/docs/ontology/person
577
+ // Free plan 10,000 credits/month; Enhance costs 25 credits per call (pricing page) -> 400 calls. 429 = credits used up.
578
+ export const diffbotProvider = {
579
+ id: 'diffbot',
580
+ kind: 'free-tier',
581
+ description: 'Diffbot Knowledge Graph Enhance, Person (free plan: 10,000 credits/month = 400 Enhance calls at 25 credits)',
582
+ provides: ['email', 'title', 'company', 'linkedin', 'location'],
583
+ keyEnv: 'DIFFBOT_TOKEN',
584
+ quota: { limit: 400, period: 'month' },
585
+ needs: (q) => Boolean(q.name && (q.domain || q.company)),
586
+ async run(q, ctx) {
587
+ const p = new URLSearchParams({ token: ctx.env.DIFFBOT_TOKEN, type: 'Person', name: q.name, employer: q.company ?? q.domain });
588
+ if (q.email)
589
+ p.set('email', q.email);
590
+ const r = await getJson(ctx.fetch, `https://kg.diffbot.com/kg/v3/enhance?${p}`, { headers: { accept: 'application/json' } }, 30000);
591
+ const hit = r.data?.data?.[0];
592
+ const e = hit?.entity;
593
+ if (!e || !sameName(e.name, q.name))
594
+ return [];
595
+ const score = Math.max(0, Math.min(1, Number(hit.score ?? 0)));
596
+ const jobs = e.employments ?? [];
597
+ const cur = jobs.find((j) => j?.isCurrent) ?? null;
598
+ const atCompany = jobs.some((j) => mentionsCompany(j?.employer?.name, q) || mentionsCompany(j?.employer?.homepageUri, q));
599
+ // Name matched; employer evidence and Diffbot's own match score decide how much to trust the rest.
600
+ const base = Math.min(0.7, 0.4 + 0.3 * score) * (atCompany ? 1 : 0.7);
601
+ const evidence = `score ${score.toFixed(2)}, importance ${e.importance ?? '?'}`;
602
+ const out = [];
603
+ const add = (field, v, c = base) => { const x = s(v); if (x)
604
+ out.push({ field, value: x, source: 'diffbot', confidence: Number(c.toFixed(2)), evidence }); };
605
+ for (const em of e.emailAddresses ?? []) {
606
+ const v = String(em?.contactString ?? '').toLowerCase();
607
+ if (!isEmail(v))
608
+ continue;
609
+ const atDomain = q.domain && v.endsWith(`@${q.domain}`);
610
+ add(atDomain ? 'email' : 'personal_email', v, atDomain ? Math.min(0.5, base) : 0.4);
611
+ }
612
+ if (cur) {
613
+ add('title', cur.title);
614
+ add('company', cur.employer?.name);
615
+ }
616
+ add('linkedin', url(e.linkedInUri));
617
+ const loc = e.location ?? (e.locations ?? []).find((l) => l?.isCurrent);
618
+ add('location', loc ? place(loc.city?.name, loc.region?.name, loc.country?.name) : null);
619
+ return out;
620
+ },
621
+ };
622
+ // ---------------------------------------------------------------- Surfe
623
+ // Docs: https://developers.surfe.com/ POST /v2/people/enrich (async), poll GET /v2/people/enrich/{id}.
624
+ export const surfeProvider = {
625
+ id: 'surfe',
626
+ kind: 'free-tier',
627
+ description: 'Surfe people enrichment (free plan: 20 email finds/month; API marked "Limited" on free)',
628
+ provides: ['email', 'title', 'company', 'linkedin', 'location'],
629
+ keyEnv: 'SURFE_API_KEY',
630
+ quota: { limit: 20, period: 'month' },
631
+ needs: (q) => Boolean(q.firstName && q.lastName && (q.domain || q.company) && !q.email),
632
+ async run(q, ctx) {
633
+ const headers = { authorization: `Bearer ${ctx.env.SURFE_API_KEY}`, 'content-type': 'application/json' };
634
+ const person = { firstName: q.firstName, lastName: q.lastName };
635
+ if (q.domain)
636
+ person.companyDomain = q.domain;
637
+ else
638
+ person.companyName = q.company;
639
+ const quota = (st) => st === 402 || st === 403 || st === 429;
640
+ const start = await call(ctx, 'https://api.surfe.com/v2/people/enrich', {
641
+ method: 'POST', headers, body: JSON.stringify({ include: { email: true, mobile: false }, people: [person] }),
642
+ });
643
+ if (quota(start.status))
644
+ throw new QuotaExceeded(`surfe HTTP ${start.status}: ${start.j?.message ?? ''}`);
645
+ if (start.status >= 400)
646
+ throw new HttpError(start.status, start.text, 'https://api.surfe.com/');
647
+ const id = start.j?.enrichmentID;
648
+ if (!id)
649
+ return [];
650
+ const done = await poll(async () => {
651
+ const r = await call(ctx, `https://api.surfe.com/v2/people/enrich/${encodeURIComponent(id)}`, { headers });
652
+ if (r.status === 429)
653
+ return undefined;
654
+ if (quota(r.status))
655
+ throw new QuotaExceeded(`surfe HTTP ${r.status}`);
656
+ if (r.status >= 400)
657
+ throw new HttpError(r.status, r.text, 'https://api.surfe.com/');
658
+ return r.j?.status && r.j.status !== 'IN_PROGRESS' ? r.j : undefined;
659
+ });
660
+ if (!done) {
661
+ ctx.log('surfe: gave up waiting for result');
662
+ return [];
663
+ }
664
+ const p = (done.people ?? done.data?.people ?? [])[0];
665
+ if (!p)
666
+ return [];
667
+ const c = collector('surfe');
668
+ const emails = p.emails?.length ? p.emails : p.email ? [{ email: p.email }] : [];
669
+ for (const e of emails) {
670
+ const st = String(e.validationStatus ?? '').toUpperCase();
671
+ if (st === 'VALID')
672
+ c.email(e.email, 0.88, 'validation VALID');
673
+ else if (/CATCH|RISK|ACCEPT/.test(st))
674
+ c.email(e.email, 0.5, `validation ${st}`);
675
+ else if (st !== 'INVALID')
676
+ c.email(e.email, 0.4, `validation ${st || 'unknown'}`);
677
+ }
678
+ c.add('title', p.jobTitle);
679
+ c.add('company', p.companyName);
680
+ c.add('linkedin', url(p.linkedInUrl));
681
+ c.add('location', place(p.city, p.state, p.country));
682
+ return c.out;
683
+ },
684
+ };
685
+ /**
686
+ * Not built (Dec 2026):
687
+ * - nymeria: no name + domain finder; /person/enrich needs a LinkedIn URL or email, /person/search takes only
688
+ * first/last name (no company filter documented) and bills 1 credit per person returned, on a 5/month plan.
689
+ * - findthatlead: no public API documented (api docs URL 404s; pricing page lists no API).
690
+ * - bettercontact: API listed only on paid plans; whether the 50 signup credits work through the API is not documented.
691
+ * - aviato: no name + domain lookup; access by contacting sales, no documented free plan.
692
+ * - crustdata: email enrich takes only LinkedIn URLs/emails/ids and needs enterprise access (self-serve keys get 403).
693
+ */
694
+ export const FINDER_PROVIDERS = [
695
+ tombaProvider,
696
+ snovProvider,
697
+ skrappProvider,
698
+ voilanorbertProvider,
699
+ dropcontactProvider,
700
+ icypeasProvider,
701
+ cufinderProvider,
702
+ mineleadProvider,
703
+ getemailProvider,
704
+ datagmaProvider,
705
+ apolloProvider,
706
+ diffbotProvider,
707
+ surfeProvider,
708
+ ];