Initial commit: LeadFlow lead generation platform

Full-stack Next.js 16 app with three scraping pipelines:
- AirScale CSV → Anymailfinder Bulk Decision Maker search
- LinkedIn Sales Navigator → Vayne → Anymailfinder email enrichment
- Apify Google SERP → domain extraction → Anymailfinder bulk enrichment

Includes Docker multi-stage build + docker-compose for Coolify deployment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Timo Uttenweiler
2026-03-17 11:21:11 +01:00
parent 5b84001c1e
commit facf8c9f69
59 changed files with 5800 additions and 233 deletions

53
lib/utils/csv.ts Normal file
View File

@@ -0,0 +1,53 @@
import Papa from "papaparse";
import * as XLSX from "xlsx";
export function parseCSV(content: string): { data: Record<string, string>[]; headers: string[] } {
const result = Papa.parse<Record<string, string>>(content, {
header: true,
skipEmptyLines: true,
transformHeader: (h) => h.trim(),
});
return {
data: result.data,
headers: result.meta.fields || [],
};
}
export function detectDomainColumn(headers: string[]): string | null {
const candidates = ["domain", "website", "url", "web", "site", "homepage", "company_domain", "company_url"];
for (const candidate of candidates) {
const found = headers.find(h => h.toLowerCase().includes(candidate));
if (found) return found;
}
return null;
}
export interface ExportRow {
company_name?: string;
domain?: string;
contact_name?: string;
contact_title?: string;
email?: string;
confidence_score?: number | string;
source_tab?: string;
job_id?: string;
found_at?: string;
}
export function exportToCSV(rows: ExportRow[], filename: string): void {
const csv = Papa.unparse(rows);
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = filename;
link.click();
URL.revokeObjectURL(url);
}
export function exportToExcel(rows: ExportRow[], filename: string): void {
const ws = XLSX.utils.json_to_sheet(rows);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Leads");
XLSX.writeFile(wb, filename);
}

34
lib/utils/domains.ts Normal file
View File

@@ -0,0 +1,34 @@
export function cleanDomain(raw: string): string {
if (!raw) return "";
let domain = raw.trim().toLowerCase();
// Remove protocol
domain = domain.replace(/^https?:\/\//i, "");
// Remove www.
domain = domain.replace(/^www\./i, "");
// Remove paths, query strings, fragments
domain = domain.split("/")[0];
domain = domain.split("?")[0];
domain = domain.split("#")[0];
// Remove trailing dots
domain = domain.replace(/\.$/, "");
return domain;
}
export function extractDomainFromUrl(url: string): string {
try {
const parsed = new URL(url.startsWith("http") ? url : `https://${url}`);
return parsed.hostname.replace(/^www\./i, "").toLowerCase();
} catch {
return cleanDomain(url);
}
}
const SOCIAL_DIRS = [
"linkedin.com", "facebook.com", "instagram.com", "twitter.com",
"x.com", "yelp.com", "google.com", "maps.google.com", "wikipedia.org",
"xing.com", "youtube.com", "tiktok.com", "pinterest.com",
];
export function isSocialOrDirectory(domain: string): boolean {
return SOCIAL_DIRS.some(d => domain === d || domain.endsWith(`.${d}`));
}

16
lib/utils/encryption.ts Normal file
View File

@@ -0,0 +1,16 @@
import CryptoJS from "crypto-js";
const SECRET = process.env.APP_ENCRYPTION_SECRET || "leadflow-default-secret-key-32ch";
export function encrypt(text: string): string {
return CryptoJS.AES.encrypt(text, SECRET).toString();
}
export function decrypt(ciphertext: string): string {
try {
const bytes = CryptoJS.AES.decrypt(ciphertext, SECRET);
return bytes.toString(CryptoJS.enc.Utf8);
} catch {
return "";
}
}