friday-sdk
Version:
Official JavaScript/TypeScript SDK for the Friday API
136 lines (135 loc) • 5.25 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FridayClient = void 0;
class FridayClient {
/**
* Initialize the Friday API client.
* @param apiKey - Your Friday API key
* @param baseUrl - Optional base URL for the API
*/
constructor(apiKey, baseUrl) {
this.apiKey = apiKey;
this.baseUrl = (baseUrl === null || baseUrl === void 0 ? void 0 : baseUrl.replace(/\/$/, '')) || 'https://friday-data-production.up.railway.app';
}
makeRequest(method_1, endpoint_1) {
return __awaiter(this, arguments, void 0, function* (method, endpoint, options = {}) {
const url = `${this.baseUrl}${endpoint}`;
const headers = Object.assign({ 'X-API-Key': this.apiKey, 'Content-Type': 'application/json' }, options.headers);
try {
const response = yield fetch(url, Object.assign({ method,
headers }, options));
if (!response.ok) {
const error = yield response.json().catch(() => ({ message: 'Unknown error' }));
throw new Error(error.message || `HTTP error! status: ${response.status}`);
}
return response.json();
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Request failed: ${error.message}`);
}
throw error;
}
});
}
/**
* Fetch and analyze a LinkedIn profile.
* @param profileUrl - LinkedIn profile URL to analyze
*/
getProfile(profileUrl) {
return __awaiter(this, void 0, void 0, function* () {
return this.makeRequest('GET', `/profile?profile_url=${profileUrl}`);
});
}
/**
* Analyze a company based on its LinkedIn URL.
* @param linkedinUrl - Company's LinkedIn URL
*/
analyzeCompany(linkedinUrl) {
return __awaiter(this, void 0, void 0, function* () {
return this.makeRequest('POST', '/analyze-company', {
body: JSON.stringify({ linkedin_url: linkedinUrl }),
});
});
}
/**
* Scrape a website.
* @param url - URL to scrape
* @param formats - Output formats (default: ['html'])
*/
scrape(url_1) {
return __awaiter(this, arguments, void 0, function* (url, formats = ['html']) {
return this.makeRequest('POST', '/scrape', {
body: JSON.stringify({
url,
formats,
}),
});
});
}
/**
* Crawl a website.
* @param url - Starting URL to crawl
* @param formats - Output formats (default: ['html'])
* @param maxPages - Maximum number of pages to crawl (default: 10)
*/
crawl(url_1) {
return __awaiter(this, arguments, void 0, function* (url, formats = ['html'], maxPages = 10) {
return this.makeRequest('POST', '/crawl', {
body: JSON.stringify({
url,
formats,
max_pages: maxPages,
}),
});
});
}
/**
* Perform a Google search.
* @param query - Search query
* @param location - Search location (default: 'US')
* @param numResults - Number of results to return (default: 15)
* @returns Promise<ApiResponse> - Returns either an object or array response
*/
search(query_1) {
return __awaiter(this, arguments, void 0, function* (query, location = 'US', numResults = 5) {
return this.makeRequest('POST', '/search', {
body: JSON.stringify({
query,
location,
num_results: numResults,
}),
});
});
}
/**
* Extract specific information from a website using AI.
* @param url - Website URL to analyze
* @param query - Query describing what information to extract
*/
extract(url, query) {
return __awaiter(this, void 0, void 0, function* () {
return this.makeRequest('POST', '/extract', {
body: JSON.stringify({ url, query }),
});
});
}
/**
* Get current API key status and rate limit information.
*/
getStatus() {
return __awaiter(this, void 0, void 0, function* () {
return this.makeRequest('GET', '/status');
});
}
}
exports.FridayClient = FridayClient;