linkedin-secret-sauce 0.11.0 → 0.12.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.
@@ -87,6 +87,7 @@ function extractDomain(candidate) {
87
87
  function createConstructProvider(config) {
88
88
  const maxAttempts = config?.maxAttempts ?? 8;
89
89
  const timeoutMs = config?.timeoutMs ?? 5000;
90
+ const smtpVerifyDelayMs = config?.smtpVerifyDelayMs ?? 2000; // Delay between SMTP checks
90
91
  async function fetchEmail(candidate) {
91
92
  const { first, last } = extractNames(candidate);
92
93
  const domain = extractDomain(candidate);
@@ -100,22 +101,79 @@ function createConstructProvider(config) {
100
101
  }
101
102
  const candidates = buildCandidates({ first, last, domain });
102
103
  const max = Math.min(candidates.length, maxAttempts);
104
+ // First, check if domain is catch-all
105
+ const catchAllResult = await (0, mx_1.checkDomainCatchAll)(domain, { timeoutMs: 10000 });
106
+ const isCatchAll = catchAllResult.isCatchAll;
103
107
  // Collect ALL valid email patterns (not just first match)
104
108
  const validEmails = [];
105
- for (let i = 0; i < max; i++) {
106
- const email = candidates[i];
107
- const verification = await (0, mx_1.verifyEmailMx)(email, { timeoutMs });
108
- if (verification.valid === true && verification.confidence >= 50) {
109
- validEmails.push({
110
- email,
111
- verified: true,
112
- confidence: verification.confidence,
113
- isCatchAll: verification.isCatchAll,
114
- metadata: {
115
- pattern: email.split('@')[0], // The local part pattern used
116
- mxRecords: verification.mxRecords,
117
- },
118
- });
109
+ // Track all attempted patterns for debugging
110
+ const attemptedPatterns = [];
111
+ // If NOT catch-all, we can verify each email via SMTP
112
+ if (isCatchAll === false) {
113
+ // Verify emails one by one, stop when we find a valid one
114
+ const emailsToVerify = candidates.slice(0, max);
115
+ for (let i = 0; i < emailsToVerify.length; i++) {
116
+ const email = emailsToVerify[i];
117
+ // If we already found a valid email, skip the rest
118
+ if (validEmails.length > 0) {
119
+ attemptedPatterns.push({ email, status: 'skipped' });
120
+ continue;
121
+ }
122
+ // Add delay between checks (except first one)
123
+ if (i > 0) {
124
+ await new Promise((resolve) => setTimeout(resolve, smtpVerifyDelayMs));
125
+ }
126
+ // Verify single email
127
+ const results = await (0, mx_1.verifyEmailsExist)([email], { delayMs: 0, timeoutMs });
128
+ const result = results[0];
129
+ if (result.exists === true) {
130
+ // Email confirmed to exist!
131
+ attemptedPatterns.push({ email, status: 'exists' });
132
+ validEmails.push({
133
+ email: result.email,
134
+ verified: true,
135
+ confidence: 95, // High confidence - SMTP verified
136
+ isCatchAll: false,
137
+ metadata: {
138
+ pattern: result.email.split('@')[0],
139
+ mxRecords: catchAllResult.mxRecords,
140
+ smtpVerified: true,
141
+ attemptedPatterns, // Include what was tried
142
+ },
143
+ });
144
+ // Found one! Stop checking more
145
+ break;
146
+ }
147
+ else if (result.exists === false) {
148
+ attemptedPatterns.push({ email, status: 'not_found' });
149
+ }
150
+ else {
151
+ attemptedPatterns.push({ email, status: 'unknown' });
152
+ }
153
+ }
154
+ // If no valid email found, include attempted patterns in metadata
155
+ if (validEmails.length === 0 && attemptedPatterns.length > 0) {
156
+ // Return null but could add metadata about attempts
157
+ }
158
+ }
159
+ else {
160
+ // Catch-all or unknown - fall back to MX verification only
161
+ for (let i = 0; i < max; i++) {
162
+ const email = candidates[i];
163
+ const verification = await (0, mx_1.verifyEmailMx)(email, { timeoutMs });
164
+ if (verification.valid === true && verification.confidence >= 50) {
165
+ validEmails.push({
166
+ email,
167
+ verified: true,
168
+ confidence: verification.confidence,
169
+ isCatchAll: isCatchAll ?? undefined,
170
+ metadata: {
171
+ pattern: email.split('@')[0],
172
+ mxRecords: verification.mxRecords,
173
+ smtpVerified: false,
174
+ },
175
+ });
176
+ }
119
177
  }
120
178
  }
121
179
  if (validEmails.length === 0) {
@@ -7,62 +7,8 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.createHunterProvider = createHunterProvider;
10
+ const http_retry_1 = require("../utils/http-retry");
10
11
  const API_BASE = "https://api.hunter.io/v2";
11
- /**
12
- * Delay helper for retry logic
13
- */
14
- async function delay(ms) {
15
- return new Promise((r) => setTimeout(r, ms));
16
- }
17
- /**
18
- * Check if value is truthy
19
- */
20
- function truthy(v) {
21
- return v !== undefined && v !== null && String(v).length > 0;
22
- }
23
- /**
24
- * Map Hunter verification status to boolean
25
- */
26
- function mapVerified(status) {
27
- if (!status)
28
- return undefined;
29
- const s = String(status).toLowerCase();
30
- if (s === "valid" || s === "deliverable")
31
- return true;
32
- if (s === "invalid" || s === "undeliverable")
33
- return false;
34
- return undefined; // catch-all/unknown/webmail -> leave undefined
35
- }
36
- /**
37
- * HTTP request with retry on 429 rate limit
38
- */
39
- async function requestWithRetry(url, retries = 1, backoffMs = 200) {
40
- let lastErr;
41
- for (let i = 0; i <= retries; i++) {
42
- try {
43
- const res = await fetch(url);
44
- // Retry on rate limit
45
- if (res?.status === 429 && i < retries) {
46
- await delay(backoffMs * Math.pow(2, i));
47
- continue;
48
- }
49
- if (!res || res.status >= 400) {
50
- lastErr = new Error(`hunter_http_${res?.status ?? "error"}`);
51
- break;
52
- }
53
- const json = (await res.json());
54
- return json;
55
- }
56
- catch (err) {
57
- lastErr = err;
58
- if (i < retries) {
59
- await delay(backoffMs * Math.pow(2, i));
60
- continue;
61
- }
62
- }
63
- }
64
- throw lastErr ?? new Error("hunter_http_error");
65
- }
66
12
  /**
67
13
  * Extract name and domain from candidate
68
14
  */
@@ -99,7 +45,7 @@ function createHunterProvider(config) {
99
45
  let url = null;
100
46
  let isEmailFinder = false;
101
47
  // Use email-finder if we have name components
102
- if (truthy(first) && truthy(last) && truthy(domain)) {
48
+ if ((0, http_retry_1.truthy)(first) && (0, http_retry_1.truthy)(last) && (0, http_retry_1.truthy)(domain)) {
103
49
  const qs = new URLSearchParams({
104
50
  api_key: String(apiKey),
105
51
  domain: String(domain),
@@ -110,7 +56,7 @@ function createHunterProvider(config) {
110
56
  isEmailFinder = true;
111
57
  }
112
58
  // Fall back to domain-search if only domain available (can return multiple)
113
- else if (truthy(domain)) {
59
+ else if ((0, http_retry_1.truthy)(domain)) {
114
60
  const qs = new URLSearchParams({
115
61
  api_key: String(apiKey),
116
62
  domain: String(domain),
@@ -122,7 +68,7 @@ function createHunterProvider(config) {
122
68
  return null; // Can't search without domain
123
69
  }
124
70
  try {
125
- const json = await requestWithRetry(url, 1, 100);
71
+ const json = await (0, http_retry_1.getWithRetry)(url, undefined, { retries: 1, backoffMs: 100 });
126
72
  // Parse email-finder response shape (single result)
127
73
  if (isEmailFinder) {
128
74
  const ef = (json && (json.data || json.result));
@@ -131,7 +77,7 @@ function createHunterProvider(config) {
131
77
  const score = typeof ef.score === "number"
132
78
  ? ef.score
133
79
  : Number(ef.score ?? 0) || undefined;
134
- const verified = mapVerified(ef?.verification?.status ?? ef?.status);
80
+ const verified = (0, http_retry_1.mapVerifiedStatus)(ef?.verification?.status ?? ef?.status);
135
81
  if (!email)
136
82
  return null;
137
83
  return { email, verified, score };
@@ -158,7 +104,7 @@ function createHunterProvider(config) {
158
104
  const score = typeof hit?.confidence === "number"
159
105
  ? hit.confidence
160
106
  : Number(hit?.confidence ?? 0) || 50;
161
- const verified = mapVerified(hit?.verification?.status ?? hit?.status);
107
+ const verified = (0, http_retry_1.mapVerifiedStatus)(hit?.verification?.status ?? hit?.status);
162
108
  emails.push({
163
109
  email,
164
110
  verified,
@@ -5,7 +5,6 @@ export { createConstructProvider } from './construct';
5
5
  export { createLddProvider } from './ldd';
6
6
  export { createSmartProspectProvider } from './smartprospect';
7
7
  export { createHunterProvider } from './hunter';
8
- export { createApolloProvider } from './apollo';
9
8
  export { createDropcontactProvider } from './dropcontact';
10
9
  export { createBouncerProvider, verifyEmailWithBouncer, checkCatchAllDomain, verifyEmailsBatch } from './bouncer';
11
10
  export { createSnovioProvider, findEmailsWithSnovio, verifyEmailWithSnovio, clearSnovioTokenCache } from './snovio';
@@ -3,7 +3,7 @@
3
3
  * Email Enrichment Providers
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.clearSnovioTokenCache = exports.verifyEmailWithSnovio = exports.findEmailsWithSnovio = exports.createSnovioProvider = exports.verifyEmailsBatch = exports.checkCatchAllDomain = exports.verifyEmailWithBouncer = exports.createBouncerProvider = exports.createDropcontactProvider = exports.createApolloProvider = exports.createHunterProvider = exports.createSmartProspectProvider = exports.createLddProvider = exports.createConstructProvider = void 0;
6
+ exports.clearSnovioTokenCache = exports.verifyEmailWithSnovio = exports.findEmailsWithSnovio = exports.createSnovioProvider = exports.verifyEmailsBatch = exports.checkCatchAllDomain = exports.verifyEmailWithBouncer = exports.createBouncerProvider = exports.createDropcontactProvider = exports.createHunterProvider = exports.createSmartProspectProvider = exports.createLddProvider = exports.createConstructProvider = void 0;
7
7
  var construct_1 = require("./construct");
8
8
  Object.defineProperty(exports, "createConstructProvider", { enumerable: true, get: function () { return construct_1.createConstructProvider; } });
9
9
  var ldd_1 = require("./ldd");
@@ -12,8 +12,6 @@ var smartprospect_1 = require("./smartprospect");
12
12
  Object.defineProperty(exports, "createSmartProspectProvider", { enumerable: true, get: function () { return smartprospect_1.createSmartProspectProvider; } });
13
13
  var hunter_1 = require("./hunter");
14
14
  Object.defineProperty(exports, "createHunterProvider", { enumerable: true, get: function () { return hunter_1.createHunterProvider; } });
15
- var apollo_1 = require("./apollo");
16
- Object.defineProperty(exports, "createApolloProvider", { enumerable: true, get: function () { return apollo_1.createApolloProvider; } });
17
15
  var dropcontact_1 = require("./dropcontact");
18
16
  Object.defineProperty(exports, "createDropcontactProvider", { enumerable: true, get: function () { return dropcontact_1.createDropcontactProvider; } });
19
17
  var bouncer_1 = require("./bouncer");
@@ -13,43 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.extractNumericLinkedInId = extractNumericLinkedInId;
14
14
  exports.createLddProvider = createLddProvider;
15
15
  const validation_1 = require("../utils/validation");
16
- /**
17
- * Delay helper for retry logic
18
- */
19
- async function delay(ms) {
20
- return new Promise((r) => setTimeout(r, ms));
21
- }
22
- /**
23
- * HTTP request with retry on 429 rate limit
24
- */
25
- async function requestWithRetry(url, token, retries = 1, backoffMs = 200) {
26
- let lastErr;
27
- for (let i = 0; i <= retries; i++) {
28
- try {
29
- const res = await fetch(url, {
30
- method: "GET",
31
- headers: {
32
- Authorization: `Bearer ${token}`,
33
- "Content-Type": "application/json",
34
- },
35
- });
36
- // Retry on rate limit
37
- if (res?.status === 429 && i < retries) {
38
- await delay(backoffMs * Math.pow(2, i));
39
- continue;
40
- }
41
- return res;
42
- }
43
- catch (err) {
44
- lastErr = err;
45
- if (i < retries) {
46
- await delay(backoffMs * Math.pow(2, i));
47
- continue;
48
- }
49
- }
50
- }
51
- throw lastErr ?? new Error("ldd_http_error");
52
- }
16
+ const http_retry_1 = require("../utils/http-retry");
53
17
  /**
54
18
  * Extract numeric LinkedIn ID from various formats:
55
19
  * - Direct number: "307567"
@@ -162,11 +126,8 @@ function createLddProvider(config) {
162
126
  async function lookupByNumericId(numericId) {
163
127
  try {
164
128
  const endpoint = `${apiUrl}/api/v1/profiles/by-numeric-id/${encodeURIComponent(numericId)}`;
165
- const response = await requestWithRetry(endpoint, apiToken, 1, 100);
166
- if (!response.ok) {
167
- return null;
168
- }
169
- return parseResponse(await response.json());
129
+ const response = await (0, http_retry_1.getWithRetry)(endpoint, { Authorization: `Bearer ${apiToken}` }, { retries: 1, backoffMs: 100 });
130
+ return parseResponse(response);
170
131
  }
171
132
  catch {
172
133
  return null;
@@ -175,11 +136,8 @@ function createLddProvider(config) {
175
136
  async function lookupByUsername(username) {
176
137
  try {
177
138
  const endpoint = `${apiUrl}/api/v1/profiles/by-username/${encodeURIComponent(username)}`;
178
- const response = await requestWithRetry(endpoint, apiToken, 1, 100);
179
- if (!response.ok) {
180
- return null;
181
- }
182
- return parseResponse(await response.json());
139
+ const response = await (0, http_retry_1.getWithRetry)(endpoint, { Authorization: `Bearer ${apiToken}` }, { retries: 1, backoffMs: 100 });
140
+ return parseResponse(response);
183
141
  }
184
142
  catch {
185
143
  return null;
@@ -17,13 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.createSmartProspectProvider = createSmartProspectProvider;
18
18
  exports.createSmartProspectClient = createSmartProspectClient;
19
19
  const smartlead_auth_1 = require("../auth/smartlead-auth");
20
+ const http_retry_1 = require("../utils/http-retry");
20
21
  const DEFAULT_API_URL = "https://prospect-api.smartlead.ai/api/search-email-leads";
21
- /**
22
- * Delay helper for retry logic
23
- */
24
- async function delay(ms) {
25
- return new Promise((r) => setTimeout(r, ms));
26
- }
27
22
  const DEFAULT_POLLING_CONFIG = {
28
23
  initialDelay: 500,
29
24
  pollInterval: 1000,
@@ -40,7 +35,7 @@ async function requestWithRetry(url, options, retries = 2, backoffMs = 300) {
40
35
  const res = await fetch(url, options);
41
36
  // Retry on rate limit
42
37
  if (res.status === 429 && i < retries) {
43
- await delay(backoffMs * Math.pow(2, i));
38
+ await (0, http_retry_1.delay)(backoffMs * Math.pow(2, i));
44
39
  continue;
45
40
  }
46
41
  if (!res.ok) {
@@ -52,7 +47,7 @@ async function requestWithRetry(url, options, retries = 2, backoffMs = 300) {
52
47
  catch (err) {
53
48
  lastErr = err;
54
49
  if (i < retries) {
55
- await delay(backoffMs * Math.pow(2, i));
50
+ await (0, http_retry_1.delay)(backoffMs * Math.pow(2, i));
56
51
  continue;
57
52
  }
58
53
  }
@@ -214,7 +209,7 @@ function createSmartProspectProvider(config) {
214
209
  async function pollForContactResults(filterId, expectedCount) {
215
210
  const { initialDelay, pollInterval, maxAttempts, maxWaitTime } = DEFAULT_POLLING_CONFIG;
216
211
  const startTime = Date.now();
217
- await delay(initialDelay);
212
+ await (0, http_retry_1.delay)(initialDelay);
218
213
  const makeRequest = async (token) => {
219
214
  return requestWithRetry(`${apiUrl}/get-contacts`, {
220
215
  method: "POST",
@@ -243,13 +238,13 @@ function createSmartProspectProvider(config) {
243
238
  return result;
244
239
  }
245
240
  }
246
- await delay(pollInterval);
241
+ await (0, http_retry_1.delay)(pollInterval);
247
242
  }
248
243
  catch (err) {
249
244
  if (err instanceof Error && err.message.includes("401") && hasCredentials) {
250
245
  await handleAuthError();
251
246
  }
252
- await delay(pollInterval);
247
+ await (0, http_retry_1.delay)(pollInterval);
253
248
  }
254
249
  }
255
250
  // Return last result
@@ -628,7 +623,7 @@ function createSmartProspectClient(config) {
628
623
  const { initialDelay, pollInterval, maxAttempts, maxWaitTime } = pollingConfig;
629
624
  const startTime = Date.now();
630
625
  // Wait initial delay before first poll
631
- await delay(initialDelay);
626
+ await (0, http_retry_1.delay)(initialDelay);
632
627
  const makeRequest = async (token) => {
633
628
  return requestWithRetry(`${apiUrl}/get-contacts`, {
634
629
  method: "POST",
@@ -660,7 +655,7 @@ function createSmartProspectClient(config) {
660
655
  }
661
656
  }
662
657
  // Wait before next poll
663
- await delay(pollInterval);
658
+ await (0, http_retry_1.delay)(pollInterval);
664
659
  }
665
660
  catch (err) {
666
661
  // On 401, clear token and retry
@@ -670,7 +665,7 @@ function createSmartProspectClient(config) {
670
665
  await handleAuthError();
671
666
  }
672
667
  // Continue polling on errors
673
- await delay(pollInterval);
668
+ await (0, http_retry_1.delay)(pollInterval);
674
669
  }
675
670
  }
676
671
  // Return last result even if not complete
@@ -126,12 +126,6 @@ export interface EnrichmentCandidate {
126
126
  export interface HunterConfig {
127
127
  apiKey: string;
128
128
  }
129
- /**
130
- * Apollo.io provider configuration
131
- */
132
- export interface ApolloConfig {
133
- apiKey: string;
134
- }
135
129
  /**
136
130
  * SmartProspect/Smartlead provider configuration
137
131
  *
@@ -277,6 +271,8 @@ export interface ConstructConfig {
277
271
  maxAttempts?: number;
278
272
  /** Timeout for MX verification in ms (default: 5000) */
279
273
  timeoutMs?: number;
274
+ /** Delay between SMTP verification checks in ms (default: 2000) */
275
+ smtpVerifyDelayMs?: number;
280
276
  }
281
277
  /**
282
278
  * All provider configurations
@@ -286,7 +282,6 @@ export interface ProvidersConfig {
286
282
  ldd?: LddConfig;
287
283
  smartprospect?: SmartProspectConfig;
288
284
  hunter?: HunterConfig;
289
- apollo?: ApolloConfig;
290
285
  dropcontact?: DropcontactConfig;
291
286
  /** Bouncer.io for SMTP email verification (99%+ accuracy) */
292
287
  bouncer?: BouncerConfig;
@@ -301,7 +296,7 @@ export interface EnrichmentOptions {
301
296
  maxCostPerEmail?: number;
302
297
  /** Minimum confidence threshold 0-100 (default: 0) */
303
298
  confidenceThreshold?: number;
304
- /** Provider order (default: ['construct', 'ldd', 'smartprospect', 'hunter', 'apollo', 'dropcontact']) */
299
+ /** Provider order (default: ['ldd', 'smartprospect', 'construct', 'bouncer', 'snovio', 'hunter']) */
305
300
  providerOrder?: ProviderName[];
306
301
  /** Retry delay in ms on transient errors (default: 200) */
307
302
  retryMs?: number;
@@ -370,30 +365,34 @@ export interface EnrichmentClient {
370
365
  /**
371
366
  * Available provider names
372
367
  */
373
- export type ProviderName = "construct" | "ldd" | "smartprospect" | "hunter" | "apollo" | "dropcontact" | "bouncer" | "snovio";
368
+ export type ProviderName = "construct" | "ldd" | "smartprospect" | "hunter" | "dropcontact" | "bouncer" | "snovio";
374
369
  /**
375
- * Default provider order
370
+ * Default provider order - 2-Phase Strategy
371
+ *
372
+ * PHASE 1 - Free lookups (run in parallel):
373
+ * - ldd: LinkedIn Data Dump - real verified emails (FREE with subscription)
374
+ * - smartprospect: SmartLead API - real verified emails (FREE with subscription)
375
+ * - construct: Pattern guessing + MX check (FREE)
376
+ *
377
+ * PHASE 2 - Paid verification/finding (only if Phase 1 inconclusive):
378
+ * - bouncer: SMTP verify constructed emails ($0.006/email)
379
+ * - snovio: Email finder for catch-all domains ($0.02/email)
380
+ * - hunter: Hunter.io fallback ($0.005/email)
376
381
  *
377
- * Strategy:
378
- * 1. construct - FREE pattern guessing with MX check
379
- * 2. bouncer - SMTP verification of construct results ($0.006/email)
380
- * 3. ldd - FREE LinkedIn data dump lookup
381
- * 4. smartprospect - Paid SmartLead lookup ($0.01/email)
382
- * 5. snovio - Email finder for catch-all domains ($0.02/email)
383
- * 6. hunter - Hunter.io API ($0.005/email)
384
- * 7. apollo - FREE Apollo.io lookup
385
- * 8. dropcontact - Dropcontact API ($0.01/email)
382
+ * Note: dropcontact available but not in default order (expensive at $0.01)
386
383
  */
387
384
  export declare const DEFAULT_PROVIDER_ORDER: ProviderName[];
388
385
  /**
389
386
  * Provider costs in USD per lookup
390
387
  *
391
388
  * Costs based on 2025 pricing:
392
- * - Bouncer: $0.006/email at scale (best accuracy 99%+)
393
- * - Snov.io: $0.02/email (email finding + verification)
394
- * - Hunter: $0.005/email
395
- * - SmartProspect: $0.01/email
396
- * - Dropcontact: $0.01/email
389
+ * - ldd: FREE (subscription-based)
390
+ * - smartprospect: FREE (included in SmartLead subscription)
391
+ * - construct: FREE (pattern guessing + MX check)
392
+ * - bouncer: $0.006/email (SMTP verification, 99%+ accuracy)
393
+ * - snovio: $0.02/email (email finding + verification)
394
+ * - hunter: $0.005/email
395
+ * - dropcontact: $0.01/email (not in default order)
397
396
  */
398
397
  export declare const PROVIDER_COSTS: Record<ProviderName, number>;
399
398
  /**
@@ -8,44 +8,45 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.SMARTPROSPECT_SUB_INDUSTRIES = exports.PROVIDER_COSTS = exports.DEFAULT_PROVIDER_ORDER = void 0;
10
10
  /**
11
- * Default provider order
11
+ * Default provider order - 2-Phase Strategy
12
12
  *
13
- * Strategy:
14
- * 1. construct - FREE pattern guessing with MX check
15
- * 2. bouncer - SMTP verification of construct results ($0.006/email)
16
- * 3. ldd - FREE LinkedIn data dump lookup
17
- * 4. smartprospect - Paid SmartLead lookup ($0.01/email)
18
- * 5. snovio - Email finder for catch-all domains ($0.02/email)
19
- * 6. hunter - Hunter.io API ($0.005/email)
20
- * 7. apollo - FREE Apollo.io lookup
21
- * 8. dropcontact - Dropcontact API ($0.01/email)
13
+ * PHASE 1 - Free lookups (run in parallel):
14
+ * - ldd: LinkedIn Data Dump - real verified emails (FREE with subscription)
15
+ * - smartprospect: SmartLead API - real verified emails (FREE with subscription)
16
+ * - construct: Pattern guessing + MX check (FREE)
17
+ *
18
+ * PHASE 2 - Paid verification/finding (only if Phase 1 inconclusive):
19
+ * - bouncer: SMTP verify constructed emails ($0.006/email)
20
+ * - snovio: Email finder for catch-all domains ($0.02/email)
21
+ * - hunter: Hunter.io fallback ($0.005/email)
22
+ *
23
+ * Note: dropcontact available but not in default order (expensive at $0.01)
22
24
  */
23
25
  exports.DEFAULT_PROVIDER_ORDER = [
24
- "construct",
25
- "bouncer",
26
26
  "ldd",
27
27
  "smartprospect",
28
+ "construct",
29
+ "bouncer",
28
30
  "snovio",
29
31
  "hunter",
30
- "apollo",
31
- "dropcontact",
32
32
  ];
33
33
  /**
34
34
  * Provider costs in USD per lookup
35
35
  *
36
36
  * Costs based on 2025 pricing:
37
- * - Bouncer: $0.006/email at scale (best accuracy 99%+)
38
- * - Snov.io: $0.02/email (email finding + verification)
39
- * - Hunter: $0.005/email
40
- * - SmartProspect: $0.01/email
41
- * - Dropcontact: $0.01/email
37
+ * - ldd: FREE (subscription-based)
38
+ * - smartprospect: FREE (included in SmartLead subscription)
39
+ * - construct: FREE (pattern guessing + MX check)
40
+ * - bouncer: $0.006/email (SMTP verification, 99%+ accuracy)
41
+ * - snovio: $0.02/email (email finding + verification)
42
+ * - hunter: $0.005/email
43
+ * - dropcontact: $0.01/email (not in default order)
42
44
  */
43
45
  exports.PROVIDER_COSTS = {
44
46
  construct: 0,
45
47
  ldd: 0,
46
- smartprospect: 0.01,
48
+ smartprospect: 0,
47
49
  hunter: 0.005,
48
- apollo: 0,
49
50
  dropcontact: 0.01,
50
51
  bouncer: 0.006,
51
52
  snovio: 0.02,
@@ -0,0 +1,96 @@
1
+ /**
2
+ * HTTP Retry Utilities
3
+ *
4
+ * Shared utilities for HTTP requests with retry logic, rate limit handling,
5
+ * and exponential backoff. Used across all enrichment providers.
6
+ */
7
+ /**
8
+ * Delay execution for specified milliseconds
9
+ */
10
+ export declare function delay(ms: number): Promise<void>;
11
+ /**
12
+ * Check if a value is truthy (not null, undefined, or empty string)
13
+ */
14
+ export declare function truthy(v: unknown): boolean;
15
+ /**
16
+ * Map common verification status strings to boolean
17
+ */
18
+ export declare function mapVerifiedStatus(status: string | undefined | null): boolean | undefined;
19
+ /**
20
+ * Options for fetch with retry
21
+ */
22
+ export interface FetchWithRetryOptions {
23
+ /** Number of retries (default: 1) */
24
+ retries?: number;
25
+ /** Initial backoff in ms (default: 200) */
26
+ backoffMs?: number;
27
+ /** Timeout in ms (default: 30000) */
28
+ timeoutMs?: number;
29
+ /** HTTP status codes that should trigger retry (default: [429, 502, 503, 504]) */
30
+ retryOnStatus?: number[];
31
+ }
32
+ /**
33
+ * Generic API response type
34
+ */
35
+ export interface ApiResponse {
36
+ data?: unknown;
37
+ result?: unknown;
38
+ people?: unknown[];
39
+ matches?: unknown[];
40
+ emails?: unknown[];
41
+ success?: boolean;
42
+ message?: string;
43
+ [key: string]: unknown;
44
+ }
45
+ /**
46
+ * HTTP request with retry on rate limit and transient errors
47
+ *
48
+ * Features:
49
+ * - Exponential backoff on rate limit (429)
50
+ * - Retry on server errors (502, 503, 504)
51
+ * - Configurable timeout
52
+ * - Returns typed response
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const response = await fetchWithRetry<MyApiResponse>(
57
+ * 'https://api.example.com/data',
58
+ * {
59
+ * method: 'POST',
60
+ * headers: { 'Content-Type': 'application/json' },
61
+ * body: JSON.stringify({ query: 'test' }),
62
+ * },
63
+ * { retries: 2, backoffMs: 300 }
64
+ * );
65
+ * ```
66
+ */
67
+ export declare function fetchWithRetry<T = ApiResponse>(url: string, init?: RequestInit, options?: FetchWithRetryOptions): Promise<T>;
68
+ /**
69
+ * Simpler GET request with retry (no request body)
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const data = await getWithRetry<UserData>(
74
+ * `https://api.example.com/users/${id}`,
75
+ * { 'Authorization': `Bearer ${token}` }
76
+ * );
77
+ * ```
78
+ */
79
+ export declare function getWithRetry<T = ApiResponse>(url: string, headers?: Record<string, string>, options?: FetchWithRetryOptions): Promise<T>;
80
+ /**
81
+ * POST request with JSON body and retry
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const result = await postWithRetry<SearchResult>(
86
+ * 'https://api.example.com/search',
87
+ * { query: 'test', limit: 10 },
88
+ * { 'X-Api-Key': apiKey }
89
+ * );
90
+ * ```
91
+ */
92
+ export declare function postWithRetry<T = ApiResponse>(url: string, body: Record<string, unknown>, headers?: Record<string, string>, options?: FetchWithRetryOptions): Promise<T>;
93
+ /**
94
+ * Safe JSON parse with fallback
95
+ */
96
+ export declare function safeJsonParse<T>(str: string, fallback: T): T;