n8n-nodes-leadmagic
Version:
n8n community node for LeadMagic - B2B data enrichment, email finder, company intelligence, and lead generation API integration
413 lines (412 loc) • 22.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LeadMagic = void 0;
const EmailDescription_1 = require("./descriptions/EmailDescription");
const CompanyDescription_1 = require("./descriptions/CompanyDescription");
const ProfileDescription_1 = require("./descriptions/ProfileDescription");
const JobDescription_1 = require("./descriptions/JobDescription");
const AdvertisementDescription_1 = require("./descriptions/AdvertisementDescription");
const CreditDescription_1 = require("./descriptions/CreditDescription");
class LeadMagic {
constructor() {
this.description = {
displayName: 'LeadMagic',
name: 'leadMagic',
icon: 'file:leadmagic.png',
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'B2B data enrichment and lead generation with email finding, company intelligence, and profile enrichment',
defaults: {
name: 'LeadMagic',
color: '#5456DF',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'leadMagicApi',
required: true,
},
],
requestDefaults: {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
},
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: '📧 Email',
value: 'email',
description: '🔍 Find & validate email addresses - Most popular feature',
},
{
name: '🏢 Company',
value: 'company',
description: '🏛️ Company intelligence, funding data & business details',
},
{
name: '👤 Profile',
value: 'profile',
description: '🎯 Professional profile enrichment & social data',
},
{
name: '👥 People',
value: 'people',
description: '🔍 Find employees, roles & team members within companies',
},
{
name: '💼 Job',
value: 'job',
description: '📋 Job posting discovery & recruitment intelligence',
},
{
name: '📱 Advertisement',
value: 'advertisement',
description: '📊 Competitive ad intelligence across platforms',
},
{
name: '💳 Credit',
value: 'credit',
description: '📈 API usage & credit management',
},
],
default: 'email',
},
// Resource Operations
...CreditDescription_1.creditOperations,
...EmailDescription_1.emailOperations,
...CompanyDescription_1.companyOperations,
...ProfileDescription_1.profileOperations,
...ProfileDescription_1.peopleOperations,
...JobDescription_1.jobOperations,
...AdvertisementDescription_1.advertisementOperations,
// Resource Fields
...EmailDescription_1.emailValidateFields,
...EmailDescription_1.emailFinderFields,
...EmailDescription_1.personalEmailFields,
...EmailDescription_1.socialToWorkEmailFields,
...CompanyDescription_1.companySearchFields,
...CompanyDescription_1.companyFundingFields,
...ProfileDescription_1.profileSearchFields,
...ProfileDescription_1.emailToProfileFields,
...ProfileDescription_1.mobileFinderFields,
...ProfileDescription_1.roleFinderFields,
...ProfileDescription_1.employeeFinderFields,
...JobDescription_1.jobSearchFields,
...AdvertisementDescription_1.googleAdsFields,
...AdvertisementDescription_1.metaAdsFields,
...AdvertisementDescription_1.b2bAdsFields,
...AdvertisementDescription_1.b2bAdDetailsFields,
],
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
const resource = this.getNodeParameter('resource', 0);
const operation = this.getNodeParameter('operation', 0);
// Handle single item processing (bulk mode will be handled in templates)
for (let i = 0; i < items.length; i++) {
try {
let requestOptions = {
method: 'POST',
body: {},
url: '',
json: true,
};
if (resource === 'credit') {
if (operation === 'getCredits') {
requestOptions.url = 'https://api.leadmagic.io/credits';
requestOptions.body = {};
}
}
else if (resource === 'email') {
if (operation === 'validateEmail') {
const inputMode = this.getNodeParameter('inputMode', i);
if (inputMode === 'bulk') {
// Handle bulk email validation
const bulkEmails = this.getNodeParameter('bulkEmails', i);
const emails = bulkEmails
.split(/[\n,]+/)
.map(email => email.trim())
.filter(email => email.length > 0);
if (emails.length > 1000) {
throw new Error(`Too many emails provided. Maximum allowed: 1000, provided: ${emails.length}`);
}
// Process each email with rate limiting
for (let emailIndex = 0; emailIndex < emails.length; emailIndex++) {
const email = emails[emailIndex];
const emailRequestOptions = {
method: 'POST',
url: 'https://api.leadmagic.io/email-validate',
body: { email },
json: true,
};
try {
const emailResponse = await this.helpers.requestWithAuthentication.call(this, 'leadMagicApi', emailRequestOptions);
const emailExecutionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(emailResponse), { itemData: { item: i } });
returnData.push(...emailExecutionData);
// Note: Rate limiting can be handled by n8n's native wait nodes
}
catch (emailError) {
if (this.continueOnFail()) {
const errorMessage = emailError instanceof Error ? emailError.message : String(emailError);
const errorExecutionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: errorMessage, email }), { itemData: { item: i } });
returnData.push(...errorExecutionData);
}
else {
throw emailError;
}
}
}
continue; // Skip the normal processing for this item
}
else {
// Handle single email validation
const email = this.getNodeParameter('email', i);
const firstName = this.getNodeParameter('first_name', i);
const lastName = this.getNodeParameter('last_name', i);
requestOptions.url = 'https://api.leadmagic.io/email-validate';
requestOptions.body = {
email,
...(firstName && { first_name: firstName }),
...(lastName && { last_name: lastName }),
};
}
}
else if (operation === 'findEmail') {
const firstName = this.getNodeParameter('first_name', i);
const lastName = this.getNodeParameter('last_name', i);
const domain = this.getNodeParameter('domain', i);
const companyName = this.getNodeParameter('company_name', i);
requestOptions.url = 'https://api.leadmagic.io/email-finder';
requestOptions.body = {
first_name: firstName,
last_name: lastName,
...(domain && { domain }),
...(companyName && { company_name: companyName }),
};
}
else if (operation === 'findPersonalEmail') {
const profileUrl = this.getNodeParameter('profile_url', i);
requestOptions.url = 'https://api.leadmagic.io/personal-email-finder';
requestOptions.body = {
profile_url: profileUrl,
};
}
else if (operation === 'socialToWorkEmail') {
const profileUrl = this.getNodeParameter('profile_url', i);
requestOptions.url = 'https://api.leadmagic.io/b2b-social-email';
requestOptions.body = {
profile_url: profileUrl,
};
}
}
else if (resource === 'company') {
if (operation === 'searchCompany') {
const companyDomain = this.getNodeParameter('company_domain', i);
const companyName = this.getNodeParameter('company_name', i);
const linkedinUrl = this.getNodeParameter('linkedin_url', i);
requestOptions.url = 'https://api.leadmagic.io/company-search';
requestOptions.body = {
company_domain: companyDomain,
...(companyName && { company_name: companyName }),
...(linkedinUrl && { linkedin_url: linkedinUrl }),
};
}
else if (operation === 'getCompanyFunding') {
const companyDomain = this.getNodeParameter('company_domain', i);
const companyName = this.getNodeParameter('company_name', i);
const linkedinUrl = this.getNodeParameter('linkedin_url', i);
requestOptions.url = 'https://api.leadmagic.io/company-funding';
requestOptions.body = {
company_domain: companyDomain,
...(companyName && { company_name: companyName }),
...(linkedinUrl && { linkedin_url: linkedinUrl }),
};
}
}
else if (resource === 'profile') {
if (operation === 'searchProfile') {
const profileUrl = this.getNodeParameter('profile_url', i);
requestOptions.url = 'https://api.leadmagic.io/profile-search';
requestOptions.body = {
profile_url: profileUrl,
};
}
else if (operation === 'emailToProfile') {
const workEmail = this.getNodeParameter('work_email', i);
requestOptions.url = 'https://api.leadmagic.io/b2b-profile';
requestOptions.body = {
work_email: workEmail,
};
}
else if (operation === 'findMobile') {
const searchMethod = this.getNodeParameter('searchMethod', i);
requestOptions.url = 'https://api.leadmagic.io/mobile-finder';
requestOptions.body = {};
if (searchMethod === 'profile') {
const profileUrl = this.getNodeParameter('profile_url', i);
requestOptions.body = { profile_url: profileUrl };
}
else if (searchMethod === 'workEmail') {
const workEmail = this.getNodeParameter('work_email', i);
requestOptions.body = { work_email: workEmail };
}
else if (searchMethod === 'personalEmail') {
const personalEmail = this.getNodeParameter('personal_email', i);
requestOptions.body = { personal_email: personalEmail };
}
}
}
else if (resource === 'people') {
if (operation === 'findRole') {
const jobTitle = this.getNodeParameter('job_title', i);
const searchMethod = this.getNodeParameter('searchMethod', i);
requestOptions.url = 'https://api.leadmagic.io/role-finder';
requestOptions.body = {
job_title: jobTitle,
};
if (searchMethod === 'name') {
const companyName = this.getNodeParameter('company_name', i);
requestOptions.body.company_name = companyName;
}
else if (searchMethod === 'domain') {
const companyDomain = this.getNodeParameter('company_domain', i);
requestOptions.body.company_domain = companyDomain;
}
else if (searchMethod === 'profile') {
const companyProfileUrl = this.getNodeParameter('company_profile_url', i);
requestOptions.body.company_profile_url = companyProfileUrl;
}
}
else if (operation === 'findEmployees') {
const companyName = this.getNodeParameter('company_name', i);
const page = this.getNodeParameter('page', i);
const perPage = this.getNodeParameter('per_page', i);
requestOptions.url = 'https://api.leadmagic.io/employee-finder';
requestOptions.body = {
company_name: companyName,
page,
per_page: perPage,
};
}
}
else if (resource === 'job') {
if (operation === 'findJobs') {
requestOptions.url = 'https://api.leadmagic.io/jobs-finder';
const body = {};
const companyName = this.getNodeParameter('company_name', i);
const companyWebsite = this.getNodeParameter('company_website', i);
const jobTitle = this.getNodeParameter('job_title', i);
const location = this.getNodeParameter('location', i);
const experienceLevel = this.getNodeParameter('experience_level', i);
const jobDescription = this.getNodeParameter('job_description', i);
const countryId = this.getNodeParameter('country_id', i);
const page = this.getNodeParameter('page', i);
const perPage = this.getNodeParameter('per_page', i);
if (companyName)
body.company_name = companyName;
if (companyWebsite)
body.company_website = companyWebsite;
if (jobTitle)
body.job_title = jobTitle;
if (location)
body.location = location;
if (experienceLevel)
body.experience_level = experienceLevel;
if (jobDescription)
body.job_description = jobDescription;
if (countryId)
body.country_id = countryId;
if (page)
body.page = page;
if (perPage)
body.per_page = perPage;
requestOptions.body = body;
}
else if (operation === 'getJobCountries') {
requestOptions.method = 'GET';
requestOptions.url = 'https://api.leadmagic.io/job-country';
requestOptions.body = undefined;
}
else if (operation === 'getJobTypes') {
requestOptions.method = 'GET';
requestOptions.url = 'https://api.leadmagic.io/job-types';
requestOptions.body = undefined;
}
}
else if (resource === 'advertisement') {
if (operation === 'searchGoogleAds') {
const searchMethod = this.getNodeParameter('searchMethod', i);
requestOptions.url = 'https://api.leadmagic.io/google/searchads';
requestOptions.body = {};
if (searchMethod === 'domain') {
const companyDomain = this.getNodeParameter('company_domain', i);
requestOptions.body = { company_domain: companyDomain };
}
else if (searchMethod === 'name') {
const companyName = this.getNodeParameter('company_name', i);
requestOptions.body = { company_name: companyName };
}
}
else if (operation === 'searchMetaAds') {
const searchMethod = this.getNodeParameter('searchMethod', i);
requestOptions.url = 'https://api.leadmagic.io/meta/searchads';
requestOptions.body = {};
if (searchMethod === 'domain') {
const companyDomain = this.getNodeParameter('company_domain', i);
requestOptions.body = { company_domain: companyDomain };
}
else if (searchMethod === 'name') {
const companyName = this.getNodeParameter('company_name', i);
requestOptions.body = { company_name: companyName };
}
}
else if (operation === 'searchB2BAds') {
const searchMethod = this.getNodeParameter('searchMethod', i);
requestOptions.url = 'https://api.leadmagic.io/b2b/searchads';
requestOptions.body = {};
if (searchMethod === 'domain') {
const companyDomain = this.getNodeParameter('company_domain', i);
requestOptions.body = { company_domain: companyDomain };
}
else if (searchMethod === 'name') {
const companyName = this.getNodeParameter('company_name', i);
requestOptions.body = { company_name: companyName };
}
}
else if (operation === 'getB2BAdDetails') {
const adId = this.getNodeParameter('ad_id', i);
requestOptions.url = 'https://api.leadmagic.io/b2b/ad-details';
requestOptions.body = {
ad_id: adId,
};
}
}
const responseData = await this.helpers.requestWithAuthentication.call(this, 'leadMagicApi', requestOptions);
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
returnData.push(...executionData);
}
catch (error) {
if (this.continueOnFail()) {
const errorMessage = error instanceof Error ? error.message : String(error);
const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: errorMessage }), { itemData: { item: i } });
returnData.push(...executionErrorData);
continue;
}
throw error;
}
}
return [returnData];
}
}
exports.LeadMagic = LeadMagic;