import type { BentoClient } from '../client'; import type { LocationData } from '../types'; import type { BlacklistCheckInput, BlacklistParameters, BlacklistResponse, BlacklistResult, ContentModerationResult, GeolocateParameters, GeolocateResponse, GuessGenderParameters, GuessGenderResponse, ValidateEmailParameters, ValidateEmailResponse, } from './types'; export class BentoExperimental { private readonly _url = '/experimental'; constructor(private readonly _client: BentoClient) {} /** * **EXPERIMENTAL** - * This functionality is experimental and may change or stop working at any time. * * Attempts to validate the email. You can provide additional information to further * refine the validation. * * If a name is provided, it compares it against the US Census Data, and so the results * may be biased. * * @param parameters * @returns Promise\ */ public async validateEmail(parameters: ValidateEmailParameters): Promise { const result = await this._client.post(`${this._url}/validation`, { email: parameters.email, ip: parameters.ip, name: parameters.name, user_agent: parameters.userAgent, }); return result.valid; } /** * **EXPERIMENTAL** - * This functionality is experimental and may change or stop working at any time. * * Attempts to guess the gender of the person given a provided name. It compares * the name against the US Census Data, and so the results may be biased. * * It is possible for the gender to be unknown if the system cannot confidently * conclude what gender it may be. * * @param parameters * @returns Promise\ */ public async guessGender(parameters: GuessGenderParameters): Promise { const result = await this._client.post(`${this._url}/gender`, parameters); return result; } /** * **EXPERIMENTAL** - * This functionality is experimental and may change or stop working at any time. * * Attempts to provide location data given a provided IP address. * * @param parameters * @returns Promise\ */ public async geolocate(parameters: GeolocateParameters): Promise { const result = await this._client.get( `${this._url}/geolocation`, parameters ); if (Object.keys(result).length === 0) return null; return result as LocationData; } /** * **EXPERIMENTAL** - * This functionality is experimental and may change or stop working at any time. * * Looks up the provided URL or IP Address against various blacklists to see if the site has been * blacklisted anywhere. * * @param parameters * @returns Promise\ */ public async checkBlacklist(parameters: BlacklistParameters): Promise { const result = await this._client.get( `${this._url}/blacklist.json`, parameters ); return result; } /** * Checks if a domain or IP is blacklisted * @param input Domain or IP to check * @returns Promise */ public async getBlacklistStatus(input: BlacklistCheckInput): Promise { return this._client.get(`${this._url}/blacklist`, input); } /** * Performs content moderation on provided text * @param content Text content to moderate * @returns Promise */ public async getContentModeration(content: string): Promise { return this._client.post(`${this._url}/moderation`, { content }); } /** * Gets geolocation data for an IP address * @param ipAddress IP address to geolocate * @returns Promise */ public async geoLocateIP(ipAddress: string): Promise { return this._client.get(`${this._url}/geolocation`, { ip: ipAddress }); } }