diff --git a/types/fingerprintjs2/fingerprintjs2-tests.ts b/types/fingerprintjs2/fingerprintjs2-tests.ts new file mode 100644 index 0000000000..f11caae127 --- /dev/null +++ b/types/fingerprintjs2/fingerprintjs2-tests.ts @@ -0,0 +1,135 @@ +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_get_default_settings() { + fingerprint2.get(defaultCallback); +} + +function test_get_with_options() { + fingerprint2.get({ excludes: { userAgent: true } }, defaultCallback); +} + +function test_getPromise_default_settings() { + // $ExpectType Promise + fingerprint2.getPromise(); +} + +function test_getPromise_with_options() { + // $ExpectType Promise + fingerprint2.getPromise({ excludes: { userAgent: true } }); +} + +function test_getV18_default_settings() { + fingerprint2.getV18(v18Callback); +} + +function test_getV18_with_options() { + fingerprint2.getV18({ excludes: { userAgent: true } }, v18Callback); +} + +function test_get_audio_options() { + const options: fingerprint2.Options = { + audio: { + timeout: 10, + excludeIOS11: true, + }, + }; + fingerprint2.get(options, 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_screen_options() { + const options: fingerprint2.Options = { + screen: { + detectScreenOrientation: true, + }, + }; + fingerprint2.get(options, defaultCallback); +} + +function test_get_plugins_options() { + const options: fingerprint2.Options = { + plugins: { + sortPluginsFor: [/foo/i], + excludeIE: true, + }, + }; + fingerprint2.get(options, 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_excludes_options() { + let options: fingerprint2.Options; + + 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 } }; + + fingerprint2.get(options, defaultCallback); +} diff --git a/types/fingerprintjs2/index.d.ts b/types/fingerprintjs2/index.d.ts new file mode 100644 index 0000000000..1b8a50fe77 --- /dev/null +++ b/types/fingerprintjs2/index.d.ts @@ -0,0 +1,124 @@ +// Type definitions for fingerprintjs2 2.0 +// Project: https://github.com/Valve/fingerprintjs2 +// Definitions by: Curt Mullin +// BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +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/tsconfig.json b/types/fingerprintjs2/tsconfig.json new file mode 100644 index 0000000000..b274c3c488 --- /dev/null +++ b/types/fingerprintjs2/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fingerprintjs2-tests.ts" + ] +} \ No newline at end of file diff --git a/types/fingerprintjs2/tslint.json b/types/fingerprintjs2/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/fingerprintjs2/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/fingerprintjs2/v1/tsconfig.json b/types/fingerprintjs2/v1/tsconfig.json index b274c3c488..4f7e97d591 100644 --- a/types/fingerprintjs2/v1/tsconfig.json +++ b/types/fingerprintjs2/v1/tsconfig.json @@ -9,10 +9,15 @@ "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, - "baseUrl": "../", + "baseUrl": "../../", "typeRoots": [ - "../" + "../../" ], + "paths": { + "fingerprintjs2": [ + "fingerprintjs2/v1" + ] + }, "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true @@ -21,4 +26,4 @@ "index.d.ts", "fingerprintjs2-tests.ts" ] -} \ No newline at end of file +}