@thumbmarkjs/thumbmarkjs
Version:
   • 6.19 kB
TypeScript
interface OptionsAfterDefaults {
/**
* A function to customise localStorage names used by thumbmark
* @param name Original name of the storage property eg. visitor_id
* @returns The name under which the storage property should be saved eg. myprefix_visitor_id
*/
property_name_factory: (name: string) => string;
/**
* @deprecated use property_name_factory
*/
storage_property_name?: string;
exclude?: string[];
include?: string[];
permissions_to_check?: PermissionName[];
timeout?: number;
logging?: boolean;
api_key?: string;
api_endpoint?: string;
/**
* @deprecated This will be removed in Thumbmarkjs 2.0, use cache_lifetime_in_ms instead
*/
cache_api_call?: boolean;
/**
* How long the cache will be valid for, maximum is 72h (259_200_000)
*/
cache_lifetime_in_ms: number;
performance?: boolean;
stabilize?: string[];
experimental?: boolean;
}
type optionsInterface = Partial<OptionsAfterDefaults>;
/**
*
* @param key @deprecated this function will be removed
* @param value
*/
declare function setOption<K extends keyof optionsInterface>(key: K, value: OptionsAfterDefaults[K]): void;
declare const stabilizationExclusionRules: {
private: {
exclude: string[];
browsers: string[];
}[];
iframe: ({
exclude: string[];
browsers: string[];
} | {
exclude: string[];
browsers?: undefined;
})[];
vpn: {
exclude: string[];
}[];
};
/**
* This file is used to create the includeComponent function as well as the interfaces each of the
* fingerprint components must implement.
*
*/
interface componentInterface {
[key: string]: string | string[] | number | boolean | componentInterface;
}
interface componentFunctionInterface {
(options?: optionsInterface): Promise<componentInterface | null>;
}
/**
* includeComponent is the function each custom component function needs to call in order for the component to be included
* in the fingerprint.
* @param {string} name - the name identifier of the component
* @param {componentFunctionInterface} creationFunction - the function that implements the component
* @returns nothing
*/
declare const includeComponent: (name: string, creationFunction: componentFunctionInterface, options?: optionsInterface) => void;
/**
* This file is here to support legacy implementations.
* Eventually, these functions will be removed to keep the library small.
*/
/**
*
* @deprecated
*/
declare function getFingerprintData(): Promise<componentInterface>;
/**
*
* @param includeData boolean
* @deprecated this function is going to be removed. use getThumbmark or Thumbmark class instead.
*/
declare function getFingerprint(includeData?: false): Promise<string>;
declare function getFingerprint(includeData: true): Promise<{
hash: string;
data: componentInterface;
}>;
/**
*
* @deprecated use Thumbmark or getThumbmark instead with options
*/
declare function getFingerprintPerformance(): Promise<{
elapsed: Record<string, number>;
}>;
/**
* ThumbmarkJS: Main fingerprinting and API logic
*
* This module handles component collection, API calls, uniqueness scoring, and data filtering
* for the ThumbmarkJS browser fingerprinting library.
*
*/
/**
* Final thumbmark response structure
*/
interface thumbmarkResponse {
components: componentInterface;
info: {
[key: string]: any;
};
version: string;
thumbmark: string;
visitorId?: string;
elapsed?: any;
error?: string;
experimental?: componentInterface;
}
/**
* Main entry point: collects all components, optionally calls API, and returns thumbmark data.
*
* @param options - Options for fingerprinting and API
* @returns thumbmarkResponse (elapsed is present only if options.performance is true)
*/
declare function getThumbmark(options?: optionsInterface): Promise<thumbmarkResponse>;
/**
* Returns the current package version
*/
declare function getVersion(): string;
/**
* A client for generating thumbmarks with a persistent configuration.
*/
declare class Thumbmark {
private options;
/**
* Creates a new Thumbmarker client instance.
* @param options - Default configuration options for this instance.
*/
constructor(options?: optionsInterface);
/**
* Generates a thumbmark using the instance's configuration.
* @param overrideOptions - Options to override for this specific call.
* @returns The thumbmark result.
*/
get(overrideOptions?: optionsInterface): Promise<any>;
getVersion(): string;
/**
* Register a custom component to be included in the fingerprint.
* @param key - The component name
* @param fn - The component function
*/
includeComponent(key: string, fn: (options?: optionsInterface) => Promise<componentInterface | null>): void;
}
/**
* Filters a componentInterface object based on include/exclude and stabilization options.
*
* @param obj - The object to filter
* @param options - Filtering options
* @returns Filtered object
*/
declare function filterThumbmarkData(obj: componentInterface, options?: optionsInterface): componentInterface;
/**
* Stable JSON stringify implementation
* Based on fast-json-stable-stringify by Evgeny Poberezkin
* https://github.com/epoberezkin/fast-json-stable-stringify
*
* This implementation ensures consistent JSON serialization by sorting object keys,
* which is critical for generating stable hashes from fingerprint data.
*/
/**
* Converts data to a stable JSON string with sorted keys
*
* @param data - The data to stringify
* @returns Stable JSON string representation
* @throws TypeError if circular reference is detected
*
* @example
* ```typescript
* const obj = { b: 2, a: 1 };
* stableStringify(obj); // '{"a":1,"b":2}'
* ```
*/
declare function stableStringify(data: any): string;
export { Thumbmark, filterThumbmarkData, getFingerprint, getFingerprintData, getFingerprintPerformance, getThumbmark, getVersion, includeComponent, type optionsInterface, setOption, stabilizationExclusionRules, stableStringify };