botblocker.pro
Version:
BotBlocker.Pro is an essential package for protecting your website from unwanted bots that can harm performance and security. Our powerful real-time web traffic filtering and analytics service helps you track and understand your visitors while effectively
58 lines (57 loc) • 2.06 kB
TypeScript
interface Request {
headers: Record<string, string>;
connection: {
remoteAddress: string;
};
url?: string;
}
interface CheckResponse {
success: boolean;
[key: string]: any;
}
export declare class BotBlocker {
private readonly apiKey;
/**
* Constructor for the BotBlocker class that initializes with an API key.
* @param apiKey - The API key necessary to access the remote BotBlocker service.
*/
constructor(apiKey: string);
/**
* Extracts the IP address and User-Agent from an HTTP request object.
* @param req - The HTTP request object from which to extract the IP and User-Agent.
* @returns An object containing the IP address and User-Agent string.
*/
extractInfoFromReq(req: Request): {
ip: string;
userAgent: string;
url: string;
};
/**
* Processes an HTTP request object to check if it should be blocked based on IP and User-Agent.
* @param req - The request object to be checked.
* @returns A promise that resolves to the blocking decision.
*/
checkReq(req: Request): Promise<CheckResponse>;
/**
* Checks if the IP and User-Agent should be blocked by consulting the BotBlocker API.
* Throws an error if the IP address is invalid.
* @param ip - The IP address to check.
* @param userAgent - The User-Agent string to check.
* @param url - The URL string to check.
* @returns A promise that resolves to the API response.
*/
check(ip: string, userAgent: string, url: string): Promise<CheckResponse>;
/**
* Makes an HTTP GET request and returns the JSON-parsed response.
* @param options - The options for the HTTP request.
* @returns A promise that resolves to the parsed JSON response or rejects with an error.
*/
private httpGet;
/**
* Validates if an IP address is valid.
* @param ip - The IP address to validate.
* @returns True if the IP address is valid, false otherwise.
*/
private isValidIp;
}
export {};