import axios, { AxiosInstance } from "axios";
import dotenv from "dotenv";
dotenv.config();
const API_KEY = process.env.FLASHLEADS_API_KEY;
const API_BASE_URL = process.env.FLASHLEADS_API_URL || "http://localhost:5000";
if (!API_KEY) {
throw new Error(
"FLASHLEADS_API_KEY environment variable is required. Get your API key from https://flashleads.io/settings/api-keys"
);
}
class FlashLeadsAPIClient {
private client: AxiosInstance;
constructor() {
this.client = axios.create({
baseURL: `${API_BASE_URL}/api/mcp`,
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
timeout: 30000, // 30 seconds
});
}
async runWebHarvest(params: {
searchQuery: string;
location: string;
limit?: number;
}) {
const response = await this.client.post("/web-harvest/run", params);
return response.data;
}
async getWebHarvestLeads(params?: { status?: string; limit?: number }) {
const response = await this.client.get("/web-harvest/leads", {
params,
});
return response.data;
}
async getWebHarvestStatus() {
const response = await this.client.get("/web-harvest/status");
return response.data;
}
}
export const apiClient = new FlashLeadsAPIClient();