UNPKG

@thumbmarkjs/thumbmarkjs

Version:

![GitHub package.json dynamic](https://img.shields.io/github/package-json/version/ilkkapeltola/thumbmarkjs) ![NPM Version](https://img.shields.io/npm/v/@thumbmarkjs/thumbmarkjs) ![NPM Downloads](https://img.shields.io/npm/dm/%40thumbmarkjs%2Fthumbmarkjs

74 lines (73 loc) 2.1 kB
import { OptionsAfterDefaults } from '../options'; import { componentInterface } from '../factory'; /** * Info returned from the API (IP, classification, uniqueness, etc) */ export interface infoInterface { ip_address?: { ip_address: string; ip_identifier: string; autonomous_system_number: number; ip_version: 'v6' | 'v4'; }; classification?: { tor: boolean; vpn: boolean; bot: boolean; datacenter: boolean; danger_level: number; }; uniqueness?: { score: number | string; }; country?: { iso_code: string; name: string; continent: { code: string; name: string; }; }; visitor?: { id: string; isNew: boolean; firstSeen: string; lastSeen: string; }; signals?: { timezone_country_mismatch?: boolean; }; timed_out?: boolean; } /** * API response structure */ export interface apiResponse { info?: infoInterface; version?: string; components?: componentInterface; visitorId?: string; thumbmark?: string; requestId?: string; metadata?: string | object; } export declare class ApiError extends Error { status: number; constructor(status: number); } /** * Calls the Thumbmark API with the given components, using caching and deduplication. * Returns a promise for the API response or null on error. */ export declare const getApiPromise: (options: OptionsAfterDefaults, components: componentInterface) => Promise<apiResponse | null>; /** * If a valid cached api response exists, returns it * @param options */ export declare function getCachedApiResponse(options: Pick<OptionsAfterDefaults, 'property_name_factory'>): apiResponse | undefined; /** * Writes the api response to the cache according to the options * @param options * @param response */ export declare function setCachedApiResponse(options: Pick<OptionsAfterDefaults, 'cache_api_call' | 'cache_lifetime_in_ms' | 'property_name_factory'>, response: apiResponse): void;