UNPKG

moonito

Version:

Moonito is a simple but powerful real-time web traffic filtering service and analytics that not only helps you to track, analyse and understand your visitors but also protects your website from bot attacks, data scraping, and other unwanted activities.

76 lines (75 loc) 3.19 kB
interface Config { isProtected: boolean; apiPublicKey: string; apiSecretKey: string; unwantedVisitorTo?: string; unwantedVisitorAction?: number; } export declare class VisitorTrafficFiltering { private config; /** * Creates an instance of AnalyticsHandler. * @param config - The configuration for the handler, including protection settings and API keys. */ constructor(config: Config); /** * Handles visitor requests by checking IP address and interacting with the analytics API. * This method: * 1. Checks if protection is enabled. * 2. Retrieves and validates the client's IP address and other request details. * 3. Makes a request to the analytics API to check if the visitor should be blocked. * 4. Takes action based on the API response and configuration, such as redirecting or displaying content. * * @param req - The request object, typically from an Express.js application. * @param res - The response object, typically from an Express.js application. * @returns {Promise<void>} A promise that resolves when the response is sent. * @throws {Error} Throws an error if there's an issue with the IP address or the API request. */ evaluateVisitor(req: any, res: any): Promise<void>; /** * Manually handles visitor data using provided IP address, user agent, and event. * * @param ip - The IP address of the visitor. * @param userAgent - The user agent string of the visitor. * @param event - The event associated with the visitor. * @param domain - The domain to be sent to the analytics API. * @returns {Promise<string>} The response content for blocked visitors. * @throws {Error} Throws an error if there's an issue with the IP address or the API request. */ evaluateVisitorManually(ip: string, userAgent: string, event: string, domain: string): Promise<any>; /** * Makes a request to the analytics API. * @param ip - The IP address to query. * @param userAgent - The user agent to send. * @param event - The event to query. * @param domain - The domain to send. * @returns {Promise<string>} The response body from the API. */ private requestAnalyticsAPI; /** * Handles blocked visitors based on the configured action. * @param res - The response object. */ private handleBlockedVisitor; /** * Returns content for blocked visitors based on the configured action. * @returns {Promise<string>} The response content for blocked visitors. */ private getBlockedContent; /** * Makes an HTTPS request. * @param url - The URL to request. * @param options - The options for the request. * @returns {Promise<string>} The response body. */ private httpRequest; /** * Validates if an IP address is valid. * Uses the `net` module to check if the IP address is a valid IPv4 or IPv6 address. * * @param {string} ip - The IP address to validate. * @returns {boolean} True if the IP address is valid, false otherwise. */ isValidIp(ip: string): boolean; } export {};