diff --git a/types/fingerprintjs2/fingerprintjs2-tests.ts b/types/fingerprintjs2/fingerprintjs2-tests.ts index d295ab7aab..f11caae127 100644 --- a/types/fingerprintjs2/fingerprintjs2-tests.ts +++ b/types/fingerprintjs2/fingerprintjs2-tests.ts @@ -1,123 +1,135 @@ -function defaultCallback(result: string, components: [{ key: string, value: string }]) { - console.log(`res: ${result}; components: ${components}`); +import * as fingerprint2 from 'fingerprintjs2'; + +function defaultCallback(components: fingerprint2.Component[]) {} +function v18Callback(murmur: string, components: fingerprint2.V18Component[]) {} + +function test_x64hash128() { + // $ExpectType string + fingerprint2.x64hash128('abc', 99); } -function test_default_settings() { - const fingerprint = new Fingerprint2().get(defaultCallback); +function test_get_default_settings() { + fingerprint2.get(defaultCallback); } -function test_get_exclude_swfContainerId() { - const fingerprint = new Fingerprint2({ swfContainerId: 'swfContainerId' }).get(defaultCallback); +function test_get_with_options() { + fingerprint2.get({ excludes: { userAgent: true } }, defaultCallback); } -function test_get_exclude_swfPath() { - const fingerprint = new Fingerprint2({swfPath: 'pathToSwf'}).get(defaultCallback); +function test_getPromise_default_settings() { + // $ExpectType Promise + fingerprint2.getPromise(); } -function test_get_exclude_userDefinedFonts() { - const fingerprint = new Fingerprint2({ userDefinedFonts: ['font1', 'font2']}).get(defaultCallback); +function test_getPromise_with_options() { + // $ExpectType Promise + fingerprint2.getPromise({ excludes: { userAgent: true } }); } -function test_get_excludeUserAgent() { - const fingerprint = new Fingerprint2({ excludeUserAgent: true }).get(defaultCallback); +function test_getV18_default_settings() { + fingerprint2.getV18(v18Callback); } -function test_get_excludeLanguage() { - const fingerprint = new Fingerprint2({ excludeLanguage: true }).get(defaultCallback); +function test_getV18_with_options() { + fingerprint2.getV18({ excludes: { userAgent: true } }, v18Callback); } -function test_get_excludeColorDepth() { - const fingerprint = new Fingerprint2({ excludeColorDepth: true }).get(defaultCallback); +function test_get_audio_options() { + const options: fingerprint2.Options = { + audio: { + timeout: 10, + excludeIOS11: true, + }, + }; + fingerprint2.get(options, defaultCallback); } -function test_get_excludeScreenResolution() { - const fingerprint = new Fingerprint2({ excludeScreenResolution: true }).get(defaultCallback); +function test_get_fonts_options() { + const options: fingerprint2.Options = { + fonts: { + swfContainerId: 'swfContainerId', + swfPath: 'pathToSwf', + userDefinedFonts: ['font1', 'font2'], + extendedJsFonts: true, + }, + }; + fingerprint2.get(options, defaultCallback); } -function test_get_excludeTimezoneOffset() { - const fingerprint = new Fingerprint2({ excludeTimezoneOffset: true }).get(defaultCallback); +function test_get_screen_options() { + const options: fingerprint2.Options = { + screen: { + detectScreenOrientation: true, + }, + }; + fingerprint2.get(options, defaultCallback); } -function test_get_excludeSessionStorage() { - const fingerprint = new Fingerprint2({ excludeSessionStorage: true }).get(defaultCallback); +function test_get_plugins_options() { + const options: fingerprint2.Options = { + plugins: { + sortPluginsFor: [/foo/i], + excludeIE: true, + }, + }; + fingerprint2.get(options, defaultCallback); } -function test_get_excludeIndexedDB() { - const fingerprint = new Fingerprint2({ excludeIndexedDB: true }).get(defaultCallback); +function test_get_extraComponents_options() { + const options: fingerprint2.Options = { + extraComponents: [ + { + key: 'foo', + getData(done, options) { + // $ExpectType (value: any) => void + done; + // $ExpectType Options + options; + + done('foo'); + }, + pauseBefore: false, + }, + ], + }; + fingerprint2.get(options, defaultCallback); } -function test_get_excludeAddBehavior() { - const fingerprint = new Fingerprint2({ excludeAddBehavior: true }).get(defaultCallback); -} +function test_get_excludes_options() { + let options: fingerprint2.Options; -function test_get_excludeOpenDatabase() { - const fingerprint = new Fingerprint2({ excludeOpenDatabase: true }).get(defaultCallback); -} + options = { excludes: { userAgent: true } }; + options = { excludes: { language: true } }; + options = { excludes: { colorDepth: true } }; + options = { excludes: { deviceMemory: true } }; + options = { excludes: { pixelRatio: true } }; + options = { excludes: { hardwareConcurrency: true } }; + options = { excludes: { screenResolution: true } }; + options = { excludes: { availableScreenResolution: true } }; + options = { excludes: { timezoneOffset: true } }; + options = { excludes: { timezone: true } }; + options = { excludes: { sessionStorage: true } }; + options = { excludes: { localStorage: true } }; + options = { excludes: { indexedDb: true } }; + options = { excludes: { addBehavior: true } }; + options = { excludes: { openDatabase: true } }; + options = { excludes: { cpuClass: true } }; + options = { excludes: { platform: true } }; + options = { excludes: { doNotTrack: true } }; + options = { excludes: { plugins: true } }; + options = { excludes: { canvas: true } }; + options = { excludes: { webgl: true } }; + options = { excludes: { webglVendorAndRenderer: true } }; + options = { excludes: { adBlock: true } }; + options = { excludes: { hasLiedLanguages: true } }; + options = { excludes: { hasLiedResolution: true } }; + options = { excludes: { hasLiedOs: true } }; + options = { excludes: { hasLiedBrowser: true } }; + options = { excludes: { touchSupport: true } }; + options = { excludes: { fonts: true } }; + options = { excludes: { fontsFlash: true } }; + options = { excludes: { audio: true } }; + options = { excludes: { enumerateDevices: true } }; -function test_get_excludeCpuClass() { - const fingerprint = new Fingerprint2({ excludeCpuClass: true }).get(defaultCallback); -} - -function test_get_excludePlatform() { - const fingerprint = new Fingerprint2({ excludePlatform: true }).get(defaultCallback); -} - -function test_get_excludeDoNotTrack() { - const fingerprint = new Fingerprint2({ excludeDoNotTrack: true }).get(defaultCallback); -} - -function test_get_excludeCanvas() { - const fingerprint = new Fingerprint2({ excludeCanvas: true }).get(defaultCallback); -} - -function test_get_excludeWebGL() { - const fingerprint = new Fingerprint2({ excludeWebGL: true }).get(defaultCallback); -} - -function test_get_excludeAdBlock() { - const fingerprint = new Fingerprint2({ excludeAdBlock: true }).get(defaultCallback); -} - -function test_get_excludeHasLiedLanguages() { - const fingerprint = new Fingerprint2({ excludeHasLiedLanguages: true }).get(defaultCallback); -} - -function test_get_excludeHasLiedResolution() { - const fingerprint = new Fingerprint2({ excludeHasLiedResolution: true }).get(defaultCallback); -} - -function test_get_excludeHasLiedOs() { - const fingerprint = new Fingerprint2({ excludeHasLiedOs: true }).get(defaultCallback); -} - -function test_get_excludeHasLiedBrowser() { - const fingerprint = new Fingerprint2({ excludeHasLiedBrowser: true }).get(defaultCallback); -} - -function test_get_excludeJsFonts() { - const fingerprint = new Fingerprint2({ excludeJsFonts: true }).get(defaultCallback); -} - -function test_get_excludeFlashFonts() { - const fingerprint = new Fingerprint2({ excludeFlashFonts: true }).get(defaultCallback); -} - -function test_get_excludePlugins() { - const fingerprint = new Fingerprint2({ excludePlugins: true }).get(defaultCallback); -} - -function test_get_excludeIEPlugins() { - const fingerprint = new Fingerprint2({ excludeIEPlugins: true }).get(defaultCallback); -} - -function test_get_excludeTouchSupport() { - const fingerprint = new Fingerprint2({ excludeTouchSupport: true }).get(defaultCallback); -} - -function test_get_excludePixelRatio() { - const fingerprint = new Fingerprint2({ excludePixelRatio: true }).get(defaultCallback); -} - -function test_get_excludeHardwareConcurrency() { - const fingerprint = new Fingerprint2({ excludeHardwareConcurrency: true }).get(defaultCallback); + fingerprint2.get(options, defaultCallback); } diff --git a/types/fingerprintjs2/index.d.ts b/types/fingerprintjs2/index.d.ts index 5778eebeed..1b8a50fe77 100644 --- a/types/fingerprintjs2/index.d.ts +++ b/types/fingerprintjs2/index.d.ts @@ -1,46 +1,124 @@ -// Type definitions for fingerprintjs2 1.5 +// Type definitions for fingerprintjs2 2.0 // Project: https://github.com/Valve/fingerprintjs2 // Definitions by: Curt Mullin +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare class Fingerprint2 { - static VERSION: string; - constructor(options?: Fingerprint2Options); - - get(callback: (result: string, components: [{ key: string, value: string }]) => void): number; -} - -interface Fingerprint2Options { - swfContainerId?: string; - swfPath?: string; - userDefinedFonts?: string[]; - excludeUserAgent?: boolean; - excludeLanguage?: boolean; - excludeColorDepth?: boolean; - excludeScreenResolution?: boolean; - excludeTimezoneOffset?: boolean; - excludeSessionStorage?: boolean; - excludeIndexedDB?: boolean; - excludeAddBehavior?: boolean; - excludeOpenDatabase?: boolean; - excludeCpuClass?: boolean; - excludePlatform?: boolean; - excludeDoNotTrack?: boolean; - excludeCanvas?: boolean; - excludeWebGL?: boolean; - excludeAdBlock?: boolean; - excludeHasLiedLanguages?: boolean; - excludeHasLiedResolution?: boolean; - excludeHasLiedOs?: boolean; - excludeHasLiedBrowser?: boolean; - excludeJsFonts?: boolean; - excludeFlashFonts?: boolean; - excludePlugins?: boolean; - excludeIEPlugins?: boolean; - excludeTouchSupport?: boolean; - excludePixelRatio?: boolean; - excludeHardwareConcurrency?: boolean; -} - -export = Fingerprint2; export as namespace Fingerprint2; +export = Fingerprint2; + +declare var Fingerprint2: Fingerprint2.Static; + +declare namespace Fingerprint2 { + interface Static { + VERSION: string; + + get(options: Options, callback: (components: Component[]) => void): void; + get(callback: (components: Component[]) => void): void; + getPromise(options?: Options): Promise; + getV18( + options: Options, + callback: (murmur: string, components: V18Component[]) => void + ): void; + getV18(callback: (murmur: string, components: V18Component[]) => void): void; + + x64hash128(value: string, num: number): string; + } + + interface Component { + key: string; + value: any; + } + + interface V18Component { + key: string; + value: string; + } + + interface Options { + preprocessor?: (key: string, value: any) => any; + + audio?: { + timeout: number; + /** + * On iOS 11, audio context can only be used in response to user interaction. + * We require users to explicitly enable audio fingerprinting on iOS 11. + * See https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088 + */ + excludeIOS11: boolean; + }; + + fonts?: { + swfContainerId: string; + swfPath: string; + userDefinedFonts: string[]; + extendedJsFonts: boolean; + }; + + screen?: { + /** + * To ensure consistent fingerprints when users rotate their mobile devices + */ + detectScreenOrientation: boolean; + }; + + plugins?: { + sortPluginsFor: RegExp[]; + excludeIE: boolean; + }; + + extraComponents?: Array<{ + key: string; + getData(done: (value: any) => void, options: Options): void; + pauseBefore?: boolean; + }>; + + excludes?: { + userAgent?: boolean; + language?: boolean; + colorDepth?: boolean; + deviceMemory?: boolean; + /** + * devicePixelRatio depends on browser zoom, and it's impossible to detect browser zoom + */ + pixelRatio?: boolean; + hardwareConcurrency?: boolean; + screenResolution?: boolean; + availableScreenResolution?: boolean; + timezoneOffset?: boolean; + timezone?: boolean; + sessionStorage?: boolean; + localStorage?: boolean; + indexedDb?: boolean; + addBehavior?: boolean; + openDatabase?: boolean; + cpuClass?: boolean; + platform?: boolean; + /** + * DNT depends on incognito mode for some browsers (Chrome) and it's impossible to detect incognito mode + */ + doNotTrack?: boolean; + plugins?: boolean; + canvas?: boolean; + webgl?: boolean; + webglVendorAndRenderer?: boolean; + adBlock?: boolean; + hasLiedLanguages?: boolean; + hasLiedResolution?: boolean; + hasLiedOs?: boolean; + hasLiedBrowser?: boolean; + touchSupport?: boolean; + fonts?: boolean; + fontsFlash?: boolean; + audio?: boolean; + /** + * Unreliable on Windows, see https://github.com/Valve/fingerprintjs2/issues/375 + */ + enumerateDevices?: boolean; + }; + + NOT_AVAILABLE?: string; + ERROR?: string; + EXCLUDED?: string; + } +} diff --git a/types/fingerprintjs2/v1/fingerprintjs2-tests.ts b/types/fingerprintjs2/v1/fingerprintjs2-tests.ts new file mode 100644 index 0000000000..d295ab7aab --- /dev/null +++ b/types/fingerprintjs2/v1/fingerprintjs2-tests.ts @@ -0,0 +1,123 @@ +function defaultCallback(result: string, components: [{ key: string, value: string }]) { + console.log(`res: ${result}; components: ${components}`); +} + +function test_default_settings() { + const fingerprint = new Fingerprint2().get(defaultCallback); +} + +function test_get_exclude_swfContainerId() { + const fingerprint = new Fingerprint2({ swfContainerId: 'swfContainerId' }).get(defaultCallback); +} + +function test_get_exclude_swfPath() { + const fingerprint = new Fingerprint2({swfPath: 'pathToSwf'}).get(defaultCallback); +} + +function test_get_exclude_userDefinedFonts() { + const fingerprint = new Fingerprint2({ userDefinedFonts: ['font1', 'font2']}).get(defaultCallback); +} + +function test_get_excludeUserAgent() { + const fingerprint = new Fingerprint2({ excludeUserAgent: true }).get(defaultCallback); +} + +function test_get_excludeLanguage() { + const fingerprint = new Fingerprint2({ excludeLanguage: true }).get(defaultCallback); +} + +function test_get_excludeColorDepth() { + const fingerprint = new Fingerprint2({ excludeColorDepth: true }).get(defaultCallback); +} + +function test_get_excludeScreenResolution() { + const fingerprint = new Fingerprint2({ excludeScreenResolution: true }).get(defaultCallback); +} + +function test_get_excludeTimezoneOffset() { + const fingerprint = new Fingerprint2({ excludeTimezoneOffset: true }).get(defaultCallback); +} + +function test_get_excludeSessionStorage() { + const fingerprint = new Fingerprint2({ excludeSessionStorage: true }).get(defaultCallback); +} + +function test_get_excludeIndexedDB() { + const fingerprint = new Fingerprint2({ excludeIndexedDB: true }).get(defaultCallback); +} + +function test_get_excludeAddBehavior() { + const fingerprint = new Fingerprint2({ excludeAddBehavior: true }).get(defaultCallback); +} + +function test_get_excludeOpenDatabase() { + const fingerprint = new Fingerprint2({ excludeOpenDatabase: true }).get(defaultCallback); +} + +function test_get_excludeCpuClass() { + const fingerprint = new Fingerprint2({ excludeCpuClass: true }).get(defaultCallback); +} + +function test_get_excludePlatform() { + const fingerprint = new Fingerprint2({ excludePlatform: true }).get(defaultCallback); +} + +function test_get_excludeDoNotTrack() { + const fingerprint = new Fingerprint2({ excludeDoNotTrack: true }).get(defaultCallback); +} + +function test_get_excludeCanvas() { + const fingerprint = new Fingerprint2({ excludeCanvas: true }).get(defaultCallback); +} + +function test_get_excludeWebGL() { + const fingerprint = new Fingerprint2({ excludeWebGL: true }).get(defaultCallback); +} + +function test_get_excludeAdBlock() { + const fingerprint = new Fingerprint2({ excludeAdBlock: true }).get(defaultCallback); +} + +function test_get_excludeHasLiedLanguages() { + const fingerprint = new Fingerprint2({ excludeHasLiedLanguages: true }).get(defaultCallback); +} + +function test_get_excludeHasLiedResolution() { + const fingerprint = new Fingerprint2({ excludeHasLiedResolution: true }).get(defaultCallback); +} + +function test_get_excludeHasLiedOs() { + const fingerprint = new Fingerprint2({ excludeHasLiedOs: true }).get(defaultCallback); +} + +function test_get_excludeHasLiedBrowser() { + const fingerprint = new Fingerprint2({ excludeHasLiedBrowser: true }).get(defaultCallback); +} + +function test_get_excludeJsFonts() { + const fingerprint = new Fingerprint2({ excludeJsFonts: true }).get(defaultCallback); +} + +function test_get_excludeFlashFonts() { + const fingerprint = new Fingerprint2({ excludeFlashFonts: true }).get(defaultCallback); +} + +function test_get_excludePlugins() { + const fingerprint = new Fingerprint2({ excludePlugins: true }).get(defaultCallback); +} + +function test_get_excludeIEPlugins() { + const fingerprint = new Fingerprint2({ excludeIEPlugins: true }).get(defaultCallback); +} + +function test_get_excludeTouchSupport() { + const fingerprint = new Fingerprint2({ excludeTouchSupport: true }).get(defaultCallback); +} + +function test_get_excludePixelRatio() { + const fingerprint = new Fingerprint2({ excludePixelRatio: true }).get(defaultCallback); +} + +function test_get_excludeHardwareConcurrency() { + const fingerprint = new Fingerprint2({ excludeHardwareConcurrency: true }).get(defaultCallback); +} diff --git a/types/fingerprintjs2/v1/index.d.ts b/types/fingerprintjs2/v1/index.d.ts new file mode 100644 index 0000000000..5778eebeed --- /dev/null +++ b/types/fingerprintjs2/v1/index.d.ts @@ -0,0 +1,46 @@ +// Type definitions for fingerprintjs2 1.5 +// Project: https://github.com/Valve/fingerprintjs2 +// Definitions by: Curt Mullin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class Fingerprint2 { + static VERSION: string; + constructor(options?: Fingerprint2Options); + + get(callback: (result: string, components: [{ key: string, value: string }]) => void): number; +} + +interface Fingerprint2Options { + swfContainerId?: string; + swfPath?: string; + userDefinedFonts?: string[]; + excludeUserAgent?: boolean; + excludeLanguage?: boolean; + excludeColorDepth?: boolean; + excludeScreenResolution?: boolean; + excludeTimezoneOffset?: boolean; + excludeSessionStorage?: boolean; + excludeIndexedDB?: boolean; + excludeAddBehavior?: boolean; + excludeOpenDatabase?: boolean; + excludeCpuClass?: boolean; + excludePlatform?: boolean; + excludeDoNotTrack?: boolean; + excludeCanvas?: boolean; + excludeWebGL?: boolean; + excludeAdBlock?: boolean; + excludeHasLiedLanguages?: boolean; + excludeHasLiedResolution?: boolean; + excludeHasLiedOs?: boolean; + excludeHasLiedBrowser?: boolean; + excludeJsFonts?: boolean; + excludeFlashFonts?: boolean; + excludePlugins?: boolean; + excludeIEPlugins?: boolean; + excludeTouchSupport?: boolean; + excludePixelRatio?: boolean; + excludeHardwareConcurrency?: boolean; +} + +export = Fingerprint2; +export as namespace Fingerprint2; diff --git a/types/fingerprintjs2/v1/tsconfig.json b/types/fingerprintjs2/v1/tsconfig.json new file mode 100644 index 0000000000..4f7e97d591 --- /dev/null +++ b/types/fingerprintjs2/v1/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "fingerprintjs2": [ + "fingerprintjs2/v1" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fingerprintjs2-tests.ts" + ] +} diff --git a/types/fingerprintjs2/v1/tslint.json b/types/fingerprintjs2/v1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fingerprintjs2/v1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }