UNPKG

@ipranker/sdk

Version:

Professional IP Intelligence and Device Fingerprinting SDK - Comprehensive fraud detection with single API call

445 lines (442 loc) 12.5 kB
/** * IPRanker SDK TypeScript Type Definitions */ interface IPRankerOptions { /** Base URL for IPRanker API (default: https://api.ipranker.com) */ baseURL?: string; /** Collect behavioral data (mouse, scroll, clicks) - default: true */ collectBehavior?: boolean; /** Timeout for behavioral data collection in ms - default: 5000 */ behaviorTimeout?: number; /** Automatically retry failed requests - default: true */ autoRetry?: boolean; /** Maximum number of retries - default: 3 */ maxRetries?: number; /** Cache results to avoid duplicate API calls - default: true */ cache?: boolean; /** Cache timeout in ms - default: 300000 (5 minutes) */ cacheTimeout?: number; /** Enable debug logging - default: false */ debug?: boolean; /** Callback when SDK is ready */ onReady?: () => void; /** Callback when analysis starts */ onAnalyzing?: () => void; /** Callback when analysis completes */ onComplete?: (result: AnalysisResult) => void; /** Callback when error occurs */ onError?: (error: Error) => void; } /** Font fingerprint data (+15% device uniqueness) */ interface FontFingerprintData { /** List of detected installed fonts */ installedFonts: string[]; /** Total count of detected fonts */ fontCount: number; /** Hash of font combination for quick comparison */ fontFingerprint: string; /** Detection time in milliseconds */ detectionTimeMs?: number; } /** WebRTC fingerprint data (+5% device uniqueness) */ interface WebRTCFingerprintData { /** WebRTC API supported */ webrtcSupported: boolean; /** Number of media devices */ mediaDevicesCount: number; /** Has camera */ hasCamera: boolean; /** Has microphone */ hasMicrophone: boolean; /** Has speaker */ hasSpeaker: boolean; /** WebRTC fingerprint hash */ webrtcFingerprint: string; } /** Sensor fingerprint data (+3% device uniqueness) */ interface SensorFingerprintData { /** Accelerometer supported */ accelerometerSupported: boolean; /** Gyroscope supported */ gyroscopeSupported: boolean; /** Magnetometer supported */ magnetometerSupported: boolean; /** Ambient light sensor supported */ ambientLightSupported: boolean; /** Sensor fingerprint hash */ sensorFingerprint: string; } /** Advanced browser features data (+5% device uniqueness) */ interface AdvancedBrowserData { /** Local storage enabled */ localStorageEnabled: boolean; /** Session storage enabled */ sessionStorageEnabled: boolean; /** IndexedDB enabled */ indexedDBEnabled: boolean; /** Cache API enabled */ cacheAPIEnabled: boolean; /** WebGL2 supported */ webGL2Supported: boolean; /** WebAssembly supported */ webAssemblySupported: boolean; /** Service worker supported */ serviceWorkerSupported: boolean; /** Do Not Track enabled */ doNotTrack: boolean; /** PDF viewer enabled */ pdfViewerEnabled: boolean; /** Browser features fingerprint hash */ browserFeaturesFingerprint: string; } /** Hardware information */ interface HardwareData { /** CPU cores */ cores: number; /** Device memory in GB */ memory: number | null; /** Max touch points */ maxTouchPoints: number; /** GPU vendor */ gpuVendor: string | null; /** GPU renderer */ gpuRenderer: string | null; } /** Permissions state (0=denied, 1=prompt, 2=granted) */ interface PermissionsData { /** Geolocation permission */ geolocation: number; /** Notifications permission */ notifications: number; /** Camera permission */ camera: number; /** Microphone permission */ microphone: number; } interface FingerprintData { /** Installation ID - unique per browser installation */ installationId: string | null; /** Canvas fingerprints */ canvas: { text: string | null; geometry: string | null; blending: string | null; }; /** WebGL fingerprint */ webgl: { vendor: string | null; renderer: string | null; extensions: number; }; /** Audio fingerprint hash */ audio: string | null; /** Screen information */ screen: { width: number; height: number; colorDepth: number; pixelRatio: number; orientation: string; }; /** Timezone */ timezone: string; /** Language */ language: string; /** Platform */ platform: string; /** Font fingerprint data (+15% uniqueness) */ fonts?: FontFingerprintData; /** WebRTC fingerprint data (+5% uniqueness) */ webrtc?: WebRTCFingerprintData; /** Sensor fingerprint data (+3% uniqueness) */ sensors?: SensorFingerprintData; /** Advanced browser features (+5% uniqueness) */ advancedBrowser?: AdvancedBrowserData; /** Hardware information */ hardware?: HardwareData; /** Permissions state */ permissions?: PermissionsData; } interface BehaviorData { /** Mouse movement events */ mouseMovements: Array<{ x: number; y: number; timestamp: number; }>; /** Scroll events */ scrollEvents: Array<{ y: number; timestamp: number; }>; /** Click events */ clickEvents: Array<{ x: number; y: number; timestamp: number; }>; /** Session duration in milliseconds */ sessionDuration: number; /** Typing speed (keypresses per minute) */ typingSpeed: number; /** Total keypresses */ keypresses: number; } interface DeviceData { /** User agent string */ userAgent: string; /** Platform */ platform: string; /** Language */ language: string; /** Screen width */ screenWidth: number; /** Screen height */ screenHeight: number; /** Color depth */ colorDepth: number; /** Pixel ratio */ pixelRatio: number; /** Timezone */ timezone: string; /** Hardware concurrency */ hardwareConcurrency: number; /** Max touch points */ maxTouchPoints: number; /** Cookie enabled */ cookieEnabled: boolean; } interface LocationData { /** Country name */ country_name: string; /** Country code (ISO 2-letter) */ country_code: string; /** City name */ city: string; /** Region/State */ region: string; /** Latitude */ latitude: number; /** Longitude */ longitude: number; /** Timezone */ timezone: string; /** ISP name */ isp: string; /** AS number */ asn: string; /** Is data center */ is_data_center?: boolean; } interface ProxyData { /** Is proxy */ isProxy: boolean; /** Confidence score (0-1) */ confidence: number; /** Detection method used */ detectionMethod: string[]; /** Additional metadata */ metadata?: { proxyType: string; }; } interface TorData { /** Is Tor exit node */ isTor: boolean; /** Confidence score (0-1) */ confidence: number; /** Detection method used */ detectionMethod: string[]; } interface BotData { /** Is bot */ isBot: boolean; /** Confidence score (0-1) */ confidence: number; /** Detection method used */ detectionMethod: string[]; /** Additional metadata */ metadata?: { botType: string; }; } interface BlacklistData { /** Is blacklisted */ isBlacklisted: boolean; /** Blacklist sources */ blacklists: string[]; /** Reason for blacklist */ reason?: string | null; /** Removal request info */ removalRequest?: string | null; /** Blacklist probability */ blacklistProbability: number; } interface ReputationData { /** Risk level (Low, Medium, High) */ riskLevel: string; /** Reputation score (0-100) */ reputationScore: number; /** Risk factors */ riskFactors: string[]; /** Additional context */ reputationContext?: { riskLevel: string; reputationScore: number; riskFactors: string[]; }; } interface DeviceFingerprintData { /** Fraud probability (0-1) */ fraud_probability: number; /** Geo consistency (0-1) */ geo_consistency: number; /** Human confidence (0-1) */ human_confidence: number; /** IP risk score (0-1) */ ip_risk_score: number; /** Model confidence (0-1) */ model_confidence: number; /** Overall risk (0-1) */ overall_risk: number; /** Session risk (0-1) */ session_risk: number; /** Timezone consistency (0-1) */ timezone_consistency: number; } interface DataQualityMetrics { /** Overall quality score (0-100) */ overallQuality: number; /** Has sufficient mouse data */ hasMouseData: boolean; /** Has sufficient scroll data */ hasScrollData: boolean; /** Has sufficient click data */ hasClickData: boolean; /** Session duration is valid */ sessionDurationValid: boolean; /** User agent is valid */ userAgentValid: boolean; /** Behavioral analysis was performed */ behavioralAnalysisPerformed: boolean; } interface AnalysisResult { /** HTTP status code */ status: number; /** Status message */ message: string; /** Request was successful */ success: boolean; /** Has errors */ errors: boolean; /** Response data */ data: { /** Client IP address */ ip: string; /** Unique visitor ID */ visitorId?: string | null; /** Analysis timestamp */ analysisTimestamp: string; /** Location information */ location: LocationData; /** Proxy detection results */ proxy: ProxyData; /** Tor detection results */ tor: TorData; /** Bot detection results */ bot: BotData; /** Blacklist information */ blacklist: BlacklistData; /** Reputation information */ reputation: ReputationData; /** Device fingerprint data */ deviceFingerprint: DeviceFingerprintData; /** Threat intelligence (future use) */ threatIntel: any[]; /** Community reports (future use) */ communityReports: any[]; }; /** API response time in ms (added by SDK) */ responseTime?: number; } interface AnalyzeOptions { /** Custom IP address (optional - backend will detect if not provided) */ ip?: string; /** Include raw fingerprint data in response */ includeRawData?: boolean; /** Custom timeout for this request in ms */ timeout?: number; } declare class IPRanker { private apiKey; private apiClient; private fingerprintCollector; private behaviorCollector; private deviceCollector; private options; private callbacks; constructor(apiKey: string, options?: Partial<IPRankerOptions>); /** * Initialize SDK */ private _initialize; /** * Analyze current visitor - main method * Collects fingerprint + behavioral data and sends to IPRanker API */ analyze(customOptions?: AnalyzeOptions): Promise<AnalysisResult>; /** * Get fingerprint data only (without full analysis) */ getFingerprint(): Promise<FingerprintData>; /** * Get behavioral data only */ getBehaviorData(): BehaviorData; /** * Get device data only */ getDeviceData(): Promise<DeviceData>; /** * Clear cache */ clearCache(): void; /** * Stop behavioral data collection and cleanup */ destroy(): void; /** * Collect behavioral data with timeout */ private _collectBehaviorWithTimeout; /** * Send request with auto-retry */ private _sendWithRetry; /** * Get cached result if available and not expired (per IP address) */ private _getCachedResult; /** * Cache result to localStorage (per IP address) */ private _cacheResult; /** * Clear cache from localStorage */ private _clearCache; /** * Handle errors */ private _handleError; /** * Debug logging */ private _log; /** * Delay utility */ private _delay; } export { IPRanker, IPRanker as default }; export type { AnalysisResult, AnalyzeOptions, BehaviorData, BlacklistData, BotData, DataQualityMetrics, DeviceData, DeviceFingerprintData, FingerprintData, IPRankerOptions, LocationData, ProxyData, ReputationData, TorData };