@thumbmarkjs/thumbmarkjs 1.0.0-rc.2 → 1.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +9 -10
  2. package/dist/thumbmark.cjs.js +1 -1
  3. package/dist/thumbmark.cjs.js.map +1 -1
  4. package/dist/thumbmark.esm.d.ts +5 -5
  5. package/dist/thumbmark.esm.js +1 -1
  6. package/dist/thumbmark.esm.js.map +1 -1
  7. package/dist/thumbmark.umd.js +1 -1
  8. package/dist/thumbmark.umd.js.map +1 -1
  9. package/dist/types/components/audio/index.d.ts +2 -0
  10. package/dist/types/components/canvas/index.d.ts +3 -0
  11. package/dist/types/components/fonts/index.d.ts +4 -0
  12. package/dist/types/components/hardware/index.d.ts +2 -0
  13. package/dist/types/components/locales/index.d.ts +2 -0
  14. package/dist/types/components/math/index.d.ts +2 -0
  15. package/dist/types/components/permissions/index.d.ts +3 -0
  16. package/dist/types/components/plugins/index.d.ts +2 -0
  17. package/dist/types/components/screen/index.d.ts +2 -0
  18. package/dist/types/components/system/browser.d.ts +7 -0
  19. package/dist/types/components/system/index.d.ts +2 -0
  20. package/dist/types/components/webgl/index.d.ts +2 -0
  21. package/dist/types/factory.d.ts +51 -0
  22. package/dist/types/functions/filterComponents.d.ts +11 -0
  23. package/dist/types/functions/index.d.ts +87 -0
  24. package/dist/types/functions/legacy_functions.d.ts +27 -0
  25. package/dist/types/index.d.ts +7 -0
  26. package/dist/types/options.d.ts +28 -0
  27. package/dist/types/thumbmark.d.ts +26 -0
  28. package/dist/types/utils/commonPixels.d.ts +1 -0
  29. package/dist/types/utils/ephemeralIFrame.d.ts +4 -0
  30. package/dist/types/utils/getMostFrequent.d.ts +5 -0
  31. package/dist/types/utils/hash.d.ts +5 -0
  32. package/dist/types/utils/imageDataToDataURL.d.ts +1 -0
  33. package/dist/types/utils/log.d.ts +8 -0
  34. package/dist/types/utils/raceAll.d.ts +9 -0
  35. package/dist/types/utils/version.d.ts +4 -0
  36. package/package.json +1 -1
  37. package/src/components/audio/index.ts +1 -2
  38. package/src/components/canvas/index.ts +6 -9
  39. package/src/components/plugins/index.ts +26 -17
  40. package/src/components/screen/index.ts +19 -8
  41. package/src/components/system/browser.test.ts +113 -0
  42. package/src/components/system/browser.ts +76 -44
  43. package/src/components/system/index.ts +4 -2
  44. package/src/functions/functions.test.ts +1 -1
  45. package/src/functions/index.ts +18 -55
  46. package/src/index.ts +2 -1
  47. package/src/options.ts +4 -2
  48. package/src/thumbmark.ts +2 -1
  49. package/src/utils/log.ts +34 -0
  50. package/src/utils/version.ts +8 -0
@@ -8,7 +8,6 @@
8
8
  * - getThumbmark
9
9
  * - getThumbmarkDataFromPromiseMap
10
10
  * - resolveClientComponents
11
- * - getVersion
12
11
  * - filterThumbmarkData
13
12
  *
14
13
  * Internal helpers and types are also defined here.
@@ -25,8 +24,10 @@ import {
25
24
  } from "../factory";
26
25
  import { hash } from "../utils/hash";
27
26
  import { raceAllPerformance } from "../utils/raceAll";
28
- import * as packageJson from '../../package.json';
27
+ import { getVersion } from "../utils/version";
29
28
  import { filterThumbmarkData } from './filterComponents'
29
+ import { logThumbmarkData } from '../utils/log';
30
+ import { API_ENDPOINT } from "../options";
30
31
 
31
32
  // ===================== Types & Interfaces =====================
32
33
 
@@ -42,7 +43,7 @@ interface infoInterface {
42
43
  },
43
44
  classification?: {
44
45
  tor: boolean,
45
- proxy: boolean, // i.e. vpn and
46
+ proxy: boolean,
46
47
  datacenter: boolean,
47
48
  danger_level: number, // 5 is highest and should be blocked. 0 is no danger.
48
49
  },
@@ -59,6 +60,7 @@ interface apiResponse {
59
60
  thumbmark?: string;
60
61
  info?: infoInterface;
61
62
  version?: string;
63
+ components?: componentInterface;
62
64
  }
63
65
 
64
66
  /**
@@ -75,14 +77,7 @@ interface thumbmarkResponse {
75
77
  elapsed?: any;
76
78
  }
77
79
 
78
- // ===================== Version =====================
79
80
 
80
- /**
81
- * Returns the current package version
82
- */
83
- export function getVersion(): string {
84
- return packageJson.version;
85
- }
86
81
 
87
82
  // ===================== API Call Logic =====================
88
83
 
@@ -108,14 +103,15 @@ export const getApiPromise = (
108
103
  }
109
104
 
110
105
  // 3. Otherwise, initiate a new API call with timeout.
111
- const endpoint = 'https://api.thumbmarkjs.com/thumbmark';
106
+ const endpoint = `${API_ENDPOINT}/thumbmark`;
112
107
  const fetchPromise = fetch(endpoint, {
113
108
  method: 'POST',
114
109
  headers: {
115
110
  'x-api-key': options.api_key!,
116
111
  'Authorization': 'custom-authorized',
112
+ 'Content-Type': 'application/json',
117
113
  },
118
- body: JSON.stringify({ components: components, clientHash: hash(JSON.stringify(components)) }),
114
+ body: JSON.stringify({ components, options, clientHash: hash(JSON.stringify(components)) }),
119
115
  })
120
116
  .then(response => {
121
117
  // Handle HTTP errors that aren't network errors
@@ -143,7 +139,7 @@ export const getApiPromise = (
143
139
  resolve({
144
140
  thumbmark: hash(JSON.stringify(components)),
145
141
  info: { timed_out: true },
146
- version: packageJson.version,
142
+ version: getVersion(),
147
143
  });
148
144
  }, timeoutMs);
149
145
  });
@@ -171,24 +167,16 @@ export async function getThumbmark(options?: optionsInterface): Promise<thumbmar
171
167
 
172
168
  // Only add 'elapsed' if performance is true
173
169
  const maybeElapsed = _options.performance ? { elapsed } : {};
174
-
175
- if (apiResult) {
176
- const info: infoInterface = apiResult.info || {};
177
- return {
178
- components: clientComponentsResult,
179
- info,
180
- version: getVersion(),
181
- thumbmark: apiResult.thumbmark || 'undefined',
182
- ...maybeElapsed,
183
- };
184
- }
170
+ const components = {...clientComponentsResult, ...apiResult?.components || {}};
171
+ const info: infoInterface = apiResult?.info || { uniqueness: { score: 'api only' } };
172
+ const thumbmark = hash(JSON.stringify(components));
173
+ const version = getVersion();
174
+ logThumbmarkData(thumbmark, components, _options).catch(() => { /* do nothing */ });
185
175
  return {
186
- thumbmark: hash(JSON.stringify(clientComponentsResult)),
187
- components: clientComponentsResult,
188
- info: {
189
- uniqueness: 'api only'
190
- },
191
- version: getVersion(),
176
+ thumbmark,
177
+ components: components,
178
+ info,
179
+ version,
192
180
  ...maybeElapsed,
193
181
  };
194
182
  }
@@ -232,31 +220,6 @@ export async function resolveClientComponents(
232
220
  return { elapsed, resolvedComponents };
233
221
  }
234
222
 
235
- // ===================== Logging (Internal) =====================
236
223
 
237
- /**
238
- * Logs thumbmark data to remote logging endpoint (only once per session)
239
- * @internal
240
- */
241
- async function logThumbmarkData(thisHash: string, thumbmarkData: componentInterface) {
242
- const url = 'https://logging.thumbmarkjs.com/v1/log';
243
- const payload = {
244
- thumbmark: thisHash,
245
- components: thumbmarkData,
246
- version: getVersion()
247
- };
248
- if (!sessionStorage.getItem("_tmjs_l")) {
249
- sessionStorage.setItem("_tmjs_l", "1");
250
- try {
251
- await fetch(url, {
252
- method: 'POST',
253
- headers: {
254
- 'Content-Type': 'application/json'
255
- },
256
- body: JSON.stringify(payload)
257
- });
258
- } catch { /* do nothing */ }
259
- }
260
- }
261
224
 
262
225
  export { globalIncludeComponent as includeComponent };
package/src/index.ts CHANGED
@@ -3,7 +3,8 @@ import {
3
3
  getFingerprintData,
4
4
  getFingerprintPerformance
5
5
  } from './functions/legacy_functions'
6
- import { getThumbmark, getVersion } from './functions'
6
+ import { getThumbmark } from './functions'
7
+ import { getVersion } from './utils/version';
7
8
  import { setOption } from './options'
8
9
  import { includeComponent } from './factory'
9
10
  import { Thumbmark } from './thumbmark'
package/src/options.ts CHANGED
@@ -6,16 +6,18 @@ export interface optionsInterface {
6
6
  logging?: boolean,
7
7
  api_key?: string,
8
8
  cache_api_call?: boolean,
9
- performance?: boolean, // re-added
9
+ performance?: boolean,
10
10
  }
11
11
 
12
+ export const API_ENDPOINT = 'https://api.thumbmarkjs.com';
13
+
12
14
  export const defaultOptions: optionsInterface = {
13
15
  exclude: [],
14
16
  include: [],
15
17
  logging: true,
16
18
  timeout: 5000,
17
19
  cache_api_call: true,
18
- performance: false // re-added
20
+ performance: false
19
21
  };
20
22
 
21
23
  export let options = {...defaultOptions};
package/src/thumbmark.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { optionsInterface } from "./options";
2
- import { getThumbmark, getVersion, includeComponent as globalIncludeComponent } from './functions';
2
+ import { getThumbmark, includeComponent as globalIncludeComponent } from './functions';
3
+ import { getVersion } from "./utils/version";
3
4
  import { defaultOptions } from "./options";
4
5
  import { componentInterface } from "./factory";
5
6
 
@@ -0,0 +1,34 @@
1
+ import { componentInterface } from '../factory';
2
+ import { optionsInterface } from '../options';
3
+ import { getVersion } from './version';
4
+ import { API_ENDPOINT } from '../options';
5
+
6
+ // ===================== Logging (Internal) =====================
7
+
8
+ /**
9
+ * Logs thumbmark data to remote logging endpoint (only once per session)
10
+ * You can disable this by setting options.logging to false.
11
+ * @internal
12
+ */
13
+ export async function logThumbmarkData(thisHash: string, thumbmarkData: componentInterface, options: optionsInterface): Promise<void> {
14
+ const url = `${API_ENDPOINT}/log`;
15
+ const payload = {
16
+ thumbmark: thisHash,
17
+ components: thumbmarkData,
18
+ version: getVersion(),
19
+ options,
20
+ path: window?.location?.pathname,
21
+ };
22
+ if (!sessionStorage.getItem("_tmjs_l") && Math.random() < 0.0001) { // Only log once per session and very rarely
23
+ sessionStorage.setItem("_tmjs_l", "1");
24
+ try {
25
+ await fetch(url, {
26
+ method: 'POST',
27
+ headers: {
28
+ 'Content-Type': 'application/json'
29
+ },
30
+ body: JSON.stringify(payload)
31
+ });
32
+ } catch { /* do nothing */ }
33
+ }
34
+ }
@@ -0,0 +1,8 @@
1
+ import * as packageJson from '../../package.json';
2
+
3
+ /**
4
+ * Returns the current package version
5
+ */
6
+ export function getVersion(): string {
7
+ return packageJson.version;
8
+ }