@thumbmarkjs/thumbmarkjs 1.1.3-rc.2 → 1.1.3-rc.4

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 (39) hide show
  1. package/dist/thumbmark.cjs.js +1 -1
  2. package/dist/thumbmark.cjs.js.map +1 -1
  3. package/dist/thumbmark.esm.d.ts +1 -0
  4. package/dist/thumbmark.esm.js +1 -1
  5. package/dist/thumbmark.esm.js.map +1 -1
  6. package/dist/thumbmark.umd.js +1 -1
  7. package/dist/thumbmark.umd.js.map +1 -1
  8. package/dist/types/components/audio/index.d.ts +2 -0
  9. package/dist/types/components/canvas/index.d.ts +3 -0
  10. package/dist/types/components/fonts/index.d.ts +4 -0
  11. package/dist/types/components/hardware/index.d.ts +2 -0
  12. package/dist/types/components/locales/index.d.ts +2 -0
  13. package/dist/types/components/math/index.d.ts +2 -0
  14. package/dist/types/components/permissions/index.d.ts +3 -0
  15. package/dist/types/components/plugins/index.d.ts +2 -0
  16. package/dist/types/components/screen/index.d.ts +2 -0
  17. package/dist/types/components/system/browser.d.ts +7 -0
  18. package/dist/types/components/system/index.d.ts +2 -0
  19. package/dist/types/components/webgl/index.d.ts +2 -0
  20. package/dist/types/factory.d.ts +51 -0
  21. package/dist/types/functions/filterComponents.d.ts +10 -0
  22. package/dist/types/functions/index.d.ts +89 -0
  23. package/dist/types/functions/legacy_functions.d.ts +27 -0
  24. package/dist/types/index.d.ts +8 -0
  25. package/dist/types/options.d.ts +43 -0
  26. package/dist/types/thumbmark.d.ts +26 -0
  27. package/dist/types/utils/commonPixels.d.ts +1 -0
  28. package/dist/types/utils/ephemeralIFrame.d.ts +4 -0
  29. package/dist/types/utils/getMostFrequent.d.ts +5 -0
  30. package/dist/types/utils/hash.d.ts +5 -0
  31. package/dist/types/utils/imageDataToDataURL.d.ts +1 -0
  32. package/dist/types/utils/log.d.ts +8 -0
  33. package/dist/types/utils/raceAll.d.ts +9 -0
  34. package/dist/types/utils/sort.d.ts +8 -0
  35. package/dist/types/utils/version.d.ts +4 -0
  36. package/dist/types/utils/visitorId.d.ts +11 -0
  37. package/package.json +1 -1
  38. package/src/functions/index.ts +27 -4
  39. package/src/utils/visitorId.ts +27 -0
@@ -0,0 +1 @@
1
+ export declare function imageDataToDataURL(imageData: ImageData): string;
@@ -0,0 +1,8 @@
1
+ import { componentInterface } from '../factory';
2
+ import { optionsInterface } from '../options';
3
+ /**
4
+ * Logs thumbmark data to remote logging endpoint (only once per session)
5
+ * You can disable this by setting options.logging to false.
6
+ * @internal
7
+ */
8
+ export declare function logThumbmarkData(thisHash: string, thumbmarkData: componentInterface, options: optionsInterface): Promise<void>;
@@ -0,0 +1,9 @@
1
+ type DelayedPromise<T> = Promise<T>;
2
+ export declare function delay<T>(t: number, val: T): DelayedPromise<T>;
3
+ export interface RaceResult<T> {
4
+ value: T;
5
+ elapsed?: number;
6
+ }
7
+ export declare function raceAllPerformance<T>(promises: Promise<T>[], timeoutTime: number, timeoutVal: T): Promise<RaceResult<T>[]>;
8
+ export declare function raceAll<T>(promises: Promise<T>[], timeoutTime: number, timeoutVal: T): Promise<(T | undefined)[]>;
9
+ export {};
@@ -0,0 +1,8 @@
1
+ import { componentInterface } from '../factory';
2
+ /**
3
+ * Recursively sorts the keys of a component object alphabetically.
4
+ * This ensures a consistent order for hashing.
5
+ * @param obj The component object to sort.
6
+ * @returns A new object with sorted keys.
7
+ */
8
+ export declare function sortComponentKeys(obj: componentInterface): componentInterface;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns the current package version
3
+ */
4
+ export declare function getVersion(): string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Visitor ID storage utilities - localStorage only, server generates IDs
3
+ */
4
+ /**
5
+ * Gets visitor ID from localStorage, returns null if unavailable
6
+ */
7
+ export declare function getVisitorId(): string | null;
8
+ /**
9
+ * Sets visitor ID in localStorage
10
+ */
11
+ export declare function setVisitorId(visitorId: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thumbmarkjs/thumbmarkjs",
3
- "version": "1.1.3-rc.2",
3
+ "version": "1.1.3-rc.4",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./dist/thumbmark.cjs.js",
@@ -28,6 +28,7 @@ import { getVersion } from "../utils/version";
28
28
  import { filterThumbmarkData } from './filterComponents'
29
29
  import { logThumbmarkData } from '../utils/log';
30
30
  import { API_ENDPOINT } from "../options";
31
+ import { getVisitorId, setVisitorId } from "../utils/visitorId";
31
32
 
32
33
  // ===================== Types & Interfaces =====================
33
34
 
@@ -58,10 +59,10 @@ interface infoInterface {
58
59
  * API response structure
59
60
  */
60
61
  interface apiResponse {
61
- thumbmark?: string;
62
62
  info?: infoInterface;
63
63
  version?: string;
64
64
  components?: componentInterface;
65
+ visitorId?: string;
65
66
  }
66
67
 
67
68
  /**
@@ -72,6 +73,7 @@ interface thumbmarkResponse {
72
73
  info: { [key: string]: any },
73
74
  version: string,
74
75
  thumbmark: string,
76
+ visitorId?: string,
75
77
  /**
76
78
  * Only present if options.performance is true.
77
79
  */
@@ -105,6 +107,17 @@ export const getApiPromise = (
105
107
 
106
108
  // 3. Otherwise, initiate a new API call with timeout.
107
109
  const endpoint = `${API_ENDPOINT}/thumbmark`;
110
+ const visitorId = getVisitorId();
111
+ const requestBody: any = {
112
+ components,
113
+ options,
114
+ clientHash: hash(JSON.stringify(components)),
115
+ version: getVersion()
116
+ };
117
+ if (visitorId) {
118
+ requestBody.visitorId = visitorId;
119
+ }
120
+
108
121
  const fetchPromise = fetch(endpoint, {
109
122
  method: 'POST',
110
123
  headers: {
@@ -112,7 +125,7 @@ export const getApiPromise = (
112
125
  'Authorization': 'custom-authorized',
113
126
  'Content-Type': 'application/json',
114
127
  },
115
- body: JSON.stringify({ components, options, clientHash: hash(JSON.stringify(components)), version: getVersion()}),
128
+ body: JSON.stringify(requestBody),
116
129
  })
117
130
  .then(response => {
118
131
  // Handle HTTP errors that aren't network errors
@@ -122,6 +135,10 @@ export const getApiPromise = (
122
135
  return response.json();
123
136
  })
124
137
  .then(data => {
138
+ // Handle visitor ID from server response
139
+ if (data.visitorId && data.visitorId !== visitorId) {
140
+ setVisitorId(data.visitorId);
141
+ }
125
142
  apiPromiseResult = data; // Cache the successful result
126
143
  currentApiPromise = null; // Clear the in-flight promise
127
144
  return data;
@@ -138,7 +155,6 @@ export const getApiPromise = (
138
155
  const timeoutPromise = new Promise<apiResponse>((resolve) => {
139
156
  setTimeout(() => {
140
157
  resolve({
141
- thumbmark: hash(JSON.stringify(components)),
142
158
  info: { timed_out: true },
143
159
  version: getVersion(),
144
160
  });
@@ -176,13 +192,20 @@ export async function getThumbmark(options?: optionsInterface): Promise<thumbmar
176
192
  const thumbmark = hash(JSON.stringify(components));
177
193
  const version = getVersion();
178
194
  logThumbmarkData(thumbmark, components, _options).catch(() => { /* do nothing */ });
179
- return {
195
+
196
+ const result: thumbmarkResponse = {
180
197
  thumbmark,
181
198
  components: components,
182
199
  info,
183
200
  version,
184
201
  ...maybeElapsed,
185
202
  };
203
+
204
+ if (apiResult?.visitorId) {
205
+ result.visitorId = apiResult.visitorId;
206
+ }
207
+
208
+ return result;
186
209
  }
187
210
 
188
211
  // ===================== Component Resolution & Performance =====================
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Visitor ID storage utilities - localStorage only, server generates IDs
3
+ */
4
+
5
+ const VISITOR_ID_KEY = 'thumbmark_visitor_id';
6
+
7
+ /**
8
+ * Gets visitor ID from localStorage, returns null if unavailable
9
+ */
10
+ export function getVisitorId(): string | null {
11
+ try {
12
+ return localStorage.getItem(VISITOR_ID_KEY);
13
+ } catch {
14
+ return null;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * Sets visitor ID in localStorage
20
+ */
21
+ export function setVisitorId(visitorId: string): void {
22
+ try {
23
+ localStorage.setItem(VISITOR_ID_KEY, visitorId);
24
+ } catch {
25
+ // Ignore storage errors
26
+ }
27
+ }