@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.
- package/dist/thumbmark.cjs.js +1 -1
- package/dist/thumbmark.cjs.js.map +1 -1
- package/dist/thumbmark.esm.d.ts +1 -0
- package/dist/thumbmark.esm.js +1 -1
- package/dist/thumbmark.esm.js.map +1 -1
- package/dist/thumbmark.umd.js +1 -1
- package/dist/thumbmark.umd.js.map +1 -1
- package/dist/types/components/audio/index.d.ts +2 -0
- package/dist/types/components/canvas/index.d.ts +3 -0
- package/dist/types/components/fonts/index.d.ts +4 -0
- package/dist/types/components/hardware/index.d.ts +2 -0
- package/dist/types/components/locales/index.d.ts +2 -0
- package/dist/types/components/math/index.d.ts +2 -0
- package/dist/types/components/permissions/index.d.ts +3 -0
- package/dist/types/components/plugins/index.d.ts +2 -0
- package/dist/types/components/screen/index.d.ts +2 -0
- package/dist/types/components/system/browser.d.ts +7 -0
- package/dist/types/components/system/index.d.ts +2 -0
- package/dist/types/components/webgl/index.d.ts +2 -0
- package/dist/types/factory.d.ts +51 -0
- package/dist/types/functions/filterComponents.d.ts +10 -0
- package/dist/types/functions/index.d.ts +89 -0
- package/dist/types/functions/legacy_functions.d.ts +27 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/options.d.ts +43 -0
- package/dist/types/thumbmark.d.ts +26 -0
- package/dist/types/utils/commonPixels.d.ts +1 -0
- package/dist/types/utils/ephemeralIFrame.d.ts +4 -0
- package/dist/types/utils/getMostFrequent.d.ts +5 -0
- package/dist/types/utils/hash.d.ts +5 -0
- package/dist/types/utils/imageDataToDataURL.d.ts +1 -0
- package/dist/types/utils/log.d.ts +8 -0
- package/dist/types/utils/raceAll.d.ts +9 -0
- package/dist/types/utils/sort.d.ts +8 -0
- package/dist/types/utils/version.d.ts +4 -0
- package/dist/types/utils/visitorId.d.ts +11 -0
- package/package.json +1 -1
- package/src/functions/index.ts +27 -4
- 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,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
package/src/functions/index.ts
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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
|
+
}
|