@tracetail/js 2.3.8 → 2.3.10
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/core.d.ts +47 -0
- package/dist/index.d.ts +7 -44
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TraceTail Core Fingerprinting Module
|
|
3
|
+
*
|
|
4
|
+
* Shared fingerprinting primitives used by both the script-tag SDK
|
|
5
|
+
* and the @tracetail/js NPM package, ensuring identical visitor IDs.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* SHA-256 based hash, returning the first 32 hex chars (128 bits).
|
|
9
|
+
*/
|
|
10
|
+
export declare function complexHash(str: string): Promise<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Sort object keys recursively for deterministic JSON.stringify output.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sortObjectKeysRecursively(obj: unknown): unknown;
|
|
15
|
+
export interface CoreComponents {
|
|
16
|
+
screen?: {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
colorDepth: number;
|
|
20
|
+
pixelRatio: number;
|
|
21
|
+
};
|
|
22
|
+
timezone?: string;
|
|
23
|
+
language?: string;
|
|
24
|
+
platform?: string;
|
|
25
|
+
userAgent?: string;
|
|
26
|
+
cookiesEnabled?: boolean;
|
|
27
|
+
localStorage?: boolean;
|
|
28
|
+
sessionStorage?: boolean;
|
|
29
|
+
indexedDB?: boolean;
|
|
30
|
+
canvas?: string;
|
|
31
|
+
webgl?: string;
|
|
32
|
+
audio?: string;
|
|
33
|
+
fonts?: string[];
|
|
34
|
+
webRTC?: string;
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Collect core fingerprinting signals.
|
|
39
|
+
* Both SDKs use this to guarantee identical inputs to the hash.
|
|
40
|
+
*/
|
|
41
|
+
export declare function collectCoreComponents(): Promise<CoreComponents>;
|
|
42
|
+
/**
|
|
43
|
+
* Generate a visitor ID from collected components.
|
|
44
|
+
* @param components - Signal map (from collectCoreComponents or full SDK)
|
|
45
|
+
* @param isFree - Whether this is the free (no API key) version
|
|
46
|
+
*/
|
|
47
|
+
export declare function generateCoreVisitorId(components: Record<string, unknown>, isFree: boolean): Promise<string>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @tracetail/js - Enterprise Browser Fingerprinting SDK
|
|
3
|
-
* Version: 2.3.
|
|
3
|
+
* Version: 2.3.10
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Thin wrapper around the core TraceTail fingerprinting engine.
|
|
6
|
+
* Produces the SAME visitor ID as the script-tag SDK.
|
|
7
7
|
*/
|
|
8
|
+
import { type CoreComponents } from './core';
|
|
8
9
|
export interface FingerprintOptions {
|
|
9
10
|
apiKey: string;
|
|
10
11
|
endpoint?: string;
|
|
@@ -22,29 +23,9 @@ export interface FingerprintResult {
|
|
|
22
23
|
visitorId: string;
|
|
23
24
|
confidence: number;
|
|
24
25
|
processingTime: number;
|
|
25
|
-
components?:
|
|
26
|
-
}
|
|
27
|
-
export interface ComponentData {
|
|
28
|
-
canvas?: string;
|
|
29
|
-
webgl?: string;
|
|
30
|
-
audio?: string;
|
|
31
|
-
fonts?: string[];
|
|
32
|
-
screen?: {
|
|
33
|
-
width: number;
|
|
34
|
-
height: number;
|
|
35
|
-
colorDepth: number;
|
|
36
|
-
pixelRatio: number;
|
|
37
|
-
};
|
|
38
|
-
timezone?: string;
|
|
39
|
-
language?: string;
|
|
40
|
-
platform?: string;
|
|
41
|
-
userAgent?: string;
|
|
42
|
-
cookiesEnabled?: boolean;
|
|
43
|
-
localStorage?: boolean;
|
|
44
|
-
sessionStorage?: boolean;
|
|
45
|
-
indexedDB?: boolean;
|
|
46
|
-
webRTC?: string;
|
|
26
|
+
components?: CoreComponents;
|
|
47
27
|
}
|
|
28
|
+
export { CoreComponents as ComponentData };
|
|
48
29
|
/**
|
|
49
30
|
* TraceTail SDK - Enterprise Browser Fingerprinting
|
|
50
31
|
*
|
|
@@ -62,10 +43,7 @@ export declare class TraceTail {
|
|
|
62
43
|
private cache;
|
|
63
44
|
constructor(options: FingerprintOptions);
|
|
64
45
|
/**
|
|
65
|
-
* Generate a browser fingerprint with server-side processing
|
|
66
|
-
*
|
|
67
|
-
* @param options Optional generation parameters
|
|
68
|
-
* @returns Promise resolving to fingerprint result
|
|
46
|
+
* Generate a browser fingerprint with optional server-side processing
|
|
69
47
|
*/
|
|
70
48
|
generateFingerprint(options?: {
|
|
71
49
|
timeout?: number;
|
|
@@ -73,26 +51,11 @@ export declare class TraceTail {
|
|
|
73
51
|
}): Promise<FingerprintResult>;
|
|
74
52
|
/**
|
|
75
53
|
* Send fingerprint components to server for enhanced processing
|
|
76
|
-
* @private
|
|
77
54
|
*/
|
|
78
55
|
private sendToServer;
|
|
79
|
-
/**
|
|
80
|
-
* Get the current SDK version
|
|
81
|
-
*/
|
|
82
56
|
static getVersion(): string;
|
|
83
|
-
/**
|
|
84
|
-
* Validate an API key format
|
|
85
|
-
*/
|
|
86
57
|
static validateApiKey(apiKey: string): boolean;
|
|
87
|
-
private collectComponents;
|
|
88
|
-
private generateVisitorId;
|
|
89
58
|
private calculateConfidence;
|
|
90
|
-
private generateCanvasFingerprint;
|
|
91
|
-
private generateWebGLFingerprint;
|
|
92
|
-
private generateAudioFingerprint;
|
|
93
|
-
private detectFonts;
|
|
94
|
-
private generateWebRTCFingerprint;
|
|
95
|
-
private testStorage;
|
|
96
59
|
private isDNTEnabled;
|
|
97
60
|
private log;
|
|
98
61
|
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";function e(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(e);const n={},r=Object.keys(t).sort();for(const o of r)n[o]=e(t[o]);return n}async function t(){const e={};try{e.screen={width:screen.width,height:screen.height,colorDepth:screen.colorDepth,pixelRatio:window.devicePixelRatio||1},e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.language=navigator.language,e.platform=navigator.platform,e.userAgent=navigator.userAgent,e.cookiesEnabled=navigator.cookieEnabled,e.localStorage=r("localStorage"),e.sessionStorage=r("sessionStorage"),e.indexedDB="indexedDB"in window,e.canvas=await async function(){try{const e=document.createElement("canvas"),t=e.getContext("2d");return t?(e.width=200,e.height=50,t.textBaseline="top",t.font="14px Arial",t.fillStyle="#f60",t.fillRect(125,1,62,20),t.fillStyle="#069",t.fillText("TraceTail 🔒",2,15),t.fillStyle="rgba(102, 204, 0, 0.2)",t.fillText("TraceTail 🔒",4,17),e.toDataURL().substring(0,100)):"unsupported"}catch(e){return"error"}}(),e.webgl=function(){try{const e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");if(!t)return"unsupported";const n=t.getParameter(t.RENDERER);return`${t.getParameter(t.VENDOR)}-${n}`.substring(0,100)}catch(e){return"error"}}(),e.audio=await async function(){try{const e=window.AudioContext||window.webkitAudioContext;if(!e)return"unsupported";const t=new e,n=t.createOscillator(),r=t.createAnalyser(),o=t.createDynamicsCompressor();n.type="triangle",n.frequency.setValueAtTime(1e4,t.currentTime),n.connect(o),o.connect(r),n.start(0),await new Promise(e=>setTimeout(e,100));const i=new Float32Array(r.frequencyBinCount);return r.getFloatFrequencyData(i),n.stop(),await t.close(),Array.from(i.slice(0,30)).map(e=>Math.abs(e)).join(",")}catch(e){return"error"}}(),e.fonts=function(){const e=["Arial","Helvetica","Times","Courier","Verdana","Georgia","Palatino","Garamond","Bookman","Comic Sans MS","Trebuchet MS","Arial Black","Impact"],t=[],n="mmmmmmmmmmlli",r="72px",o=document.createElement("div");o.style.position="absolute",o.style.left="-9999px",document.body.appendChild(o);try{for(const i of e){const e=document.createElement("span");e.style.fontSize=r,e.style.fontFamily=i,e.textContent=n,o.appendChild(e),e.offsetWidth>0&&t.push(i)}}finally{document.body.removeChild(o)}return t}(),e.webRTC=await async function(){try{if(!window.RTCPeerConnection)return"unsupported";const e=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});e.createDataChannel("tracetail");const t=new Promise(t=>{const n=setTimeout(()=>t(),1e3);e.onicegatheringstatechange=()=>{"complete"===e.iceGatheringState&&(clearTimeout(n),t())}});await e.createOffer(),await e.setLocalDescription(),await t;const n=e.localDescription;e.close();return((null==n?void 0:n.sdp)||"error").split("\n").filter(e=>!e.includes("a=ice-pwd")&&!e.includes("a=ice-ufrag")).join("").substring(0,100)}catch(e){return"error"}}()}catch(e){}return e}async function n(t,n){const r=e(t),o=JSON.stringify(r);return"fp2_"+(await async function(e){if(!e.length)return"0000000000000000";const t=(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("").substring(0,32)}(o)).substring(0,16)}function r(e){try{const t=window[e],n="__tt_test__";return t.setItem(n,"test"),t.removeItem(n),!0}catch(e){return!1}}Object.defineProperty(exports,"__esModule",{value:!0});class o{constructor(e){if(this.cache=new Map,!e.apiKey)throw new Error("TraceTail: API key is required. Get yours at https://tracetail.io");this.options={apiKey:e.apiKey,endpoint:e.endpoint||"/api",timeout:e.timeout||1e4,debug:e.debug||!1,caching:!1!==e.caching,respectDNT:e.respectDNT||!1,includeIP:!1!==e.includeIP,storeFingerprints:!1!==e.storeFingerprints,enableWorkers:!1!==e.enableWorkers,batchRequests:!1!==e.batchRequests,fallbackMode:e.fallbackMode||"basic"},this.log("TraceTail SDK initialized",{version:"2.3.7",options:this.options})}async generateFingerprint(e){const r=performance.now();try{if(this.options.respectDNT&&this.isDNTEnabled())throw new Error("TraceTail: Do Not Track is enabled");const o=!0===(null==e?void 0:e.verbose),i=o?"fingerprint_verbose":"fingerprint_basic";if(this.options.caching&&this.cache.has(i)){const e=this.cache.get(i);if(e)return this.log("Using cached fingerprint",e),e}const a=await t(),s=Math.round(performance.now()-r);if(this.options.apiKey&&this.options.endpoint)try{const e={...await this.sendToServer(a,o),processingTime:Math.round(performance.now()-r)};return this.options.caching&&this.cache.set(i,e),this.log("Server-enhanced fingerprint generated",e),e}catch(e){this.log("Server processing failed, falling back to client-side",e)}const c=await n(a),l={visitorId:c,confidence:this.calculateConfidence(a),processingTime:s,...o&&{components:a}};return this.options.caching&&this.cache.set(i,l),this.log("Client-side fingerprint generated",l),l}catch(e){throw this.log("Fingerprint generation failed",e),e}}async sendToServer(e,t){const n=new AbortController,r=setTimeout(()=>n.abort(),this.options.timeout);try{const o=await fetch(`${this.options.endpoint}/id`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.options.apiKey}`,"X-TraceTail-SDK":"js/2.3.7"},body:JSON.stringify({components:e,verbose:t||!1,clientCapabilities:{timestamp:Date.now(),sdkVersion:"2.3.7"}}),signal:n.signal});if(clearTimeout(r),!o.ok){if(401===o.status)throw new Error("Invalid API key");throw new Error(`Server returned ${o.status}`)}const i=await o.json(),a={visitorId:i.visitorId,confidence:i.confidence,processingTime:i.processingTime||0};if(t){if(!i.components)throw new Error("Server did not return components in verbose mode");a.components=i.components}return a}catch(e){throw clearTimeout(r),this.options.debug&&console.error("[TraceTail] Server error:",e),e}}static getVersion(){return"2.3.7"}static validateApiKey(e){return/^tt_(test|prod)_[a-zA-Z0-9]{32,}$/.test(e)}calculateConfidence(e){let t=1;e.canvas||(t-=.03),e.webgl||(t-=.03),e.audio||(t-=.02),e.fonts||(t-=.02),e.webRTC||(t-=.01);const n=Object.values(e).filter(e=>null!=e).length;return n<3?t-=.1:n<5&&(t-=.03),Math.min(.999,Math.max(.5,t))}isDNTEnabled(){return"1"===navigator.doNotTrack||"1"===window.doNotTrack||"1"===navigator.msDoNotTrack}log(e,t){this.options.debug&&console.log(`[TraceTail] ${e}`,t)}}exports.TraceTail=o,exports.default=o;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function e(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(e);const n={},r=Object.keys(t).sort();for(const o of r)n[o]=e(t[o]);return n}async function t(){const e={};try{e.screen={width:screen.width,height:screen.height,colorDepth:screen.colorDepth,pixelRatio:window.devicePixelRatio||1},e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.language=navigator.language,e.platform=navigator.platform,e.userAgent=navigator.userAgent,e.cookiesEnabled=navigator.cookieEnabled,e.localStorage=r("localStorage"),e.sessionStorage=r("sessionStorage"),e.indexedDB="indexedDB"in window,e.canvas=await async function(){try{const e=document.createElement("canvas"),t=e.getContext("2d");return t?(e.width=200,e.height=50,t.textBaseline="top",t.font="14px Arial",t.fillStyle="#f60",t.fillRect(125,1,62,20),t.fillStyle="#069",t.fillText("TraceTail 🔒",2,15),t.fillStyle="rgba(102, 204, 0, 0.2)",t.fillText("TraceTail 🔒",4,17),e.toDataURL().substring(0,100)):"unsupported"}catch(e){return"error"}}(),e.webgl=function(){try{const e=document.createElement("canvas"),t=e.getContext("webgl")||e.getContext("experimental-webgl");if(!t)return"unsupported";const n=t.getParameter(t.RENDERER);return`${t.getParameter(t.VENDOR)}-${n}`.substring(0,100)}catch(e){return"error"}}(),e.audio=await async function(){try{const e=window.AudioContext||window.webkitAudioContext;if(!e)return"unsupported";const t=new e,n=t.createOscillator(),r=t.createAnalyser(),o=t.createDynamicsCompressor();n.type="triangle",n.frequency.setValueAtTime(1e4,t.currentTime),n.connect(o),o.connect(r),n.start(0),await new Promise(e=>setTimeout(e,100));const i=new Float32Array(r.frequencyBinCount);return r.getFloatFrequencyData(i),n.stop(),await t.close(),Array.from(i.slice(0,30)).map(e=>Math.abs(e)).join(",")}catch(e){return"error"}}(),e.fonts=function(){const e=["Arial","Helvetica","Times","Courier","Verdana","Georgia","Palatino","Garamond","Bookman","Comic Sans MS","Trebuchet MS","Arial Black","Impact"],t=[],n="mmmmmmmmmmlli",r="72px",o=document.createElement("div");o.style.position="absolute",o.style.left="-9999px",document.body.appendChild(o);try{for(const i of e){const e=document.createElement("span");e.style.fontSize=r,e.style.fontFamily=i,e.textContent=n,o.appendChild(e),e.offsetWidth>0&&t.push(i)}}finally{document.body.removeChild(o)}return t}(),e.webRTC=await async function(){try{if(!window.RTCPeerConnection)return"unsupported";const e=new RTCPeerConnection({iceServers:[{urls:"stun:stun.l.google.com:19302"}]});e.createDataChannel("tracetail");const t=new Promise(t=>{const n=setTimeout(()=>t(),1e3);e.onicegatheringstatechange=()=>{"complete"===e.iceGatheringState&&(clearTimeout(n),t())}});await e.createOffer(),await e.setLocalDescription(),await t;const n=e.localDescription;e.close();return((null==n?void 0:n.sdp)||"error").split("\n").filter(e=>!e.includes("a=ice-pwd")&&!e.includes("a=ice-ufrag")).join("").substring(0,100)}catch(e){return"error"}}()}catch(e){}return e}async function n(t,n){const r=e(t),o=JSON.stringify(r);return"fp2_"+(await async function(e){if(!e.length)return"0000000000000000";const t=(new TextEncoder).encode(e),n=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,"0")).join("").substring(0,32)}(o)).substring(0,16)}function r(e){try{const t=window[e],n="__tt_test__";return t.setItem(n,"test"),t.removeItem(n),!0}catch(e){return!1}}class o{constructor(e){if(this.cache=new Map,!e.apiKey)throw new Error("TraceTail: API key is required. Get yours at https://tracetail.io");this.options={apiKey:e.apiKey,endpoint:e.endpoint||"/api",timeout:e.timeout||1e4,debug:e.debug||!1,caching:!1!==e.caching,respectDNT:e.respectDNT||!1,includeIP:!1!==e.includeIP,storeFingerprints:!1!==e.storeFingerprints,enableWorkers:!1!==e.enableWorkers,batchRequests:!1!==e.batchRequests,fallbackMode:e.fallbackMode||"basic"},this.log("TraceTail SDK initialized",{version:"2.3.7",options:this.options})}async generateFingerprint(e){const r=performance.now();try{if(this.options.respectDNT&&this.isDNTEnabled())throw new Error("TraceTail: Do Not Track is enabled");const o=!0===(null==e?void 0:e.verbose),i=o?"fingerprint_verbose":"fingerprint_basic";if(this.options.caching&&this.cache.has(i)){const e=this.cache.get(i);if(e)return this.log("Using cached fingerprint",e),e}const a=await t(),s=Math.round(performance.now()-r);if(this.options.apiKey&&this.options.endpoint)try{const e={...await this.sendToServer(a,o),processingTime:Math.round(performance.now()-r)};return this.options.caching&&this.cache.set(i,e),this.log("Server-enhanced fingerprint generated",e),e}catch(e){this.log("Server processing failed, falling back to client-side",e)}const c=await n(a),l={visitorId:c,confidence:this.calculateConfidence(a),processingTime:s,...o&&{components:a}};return this.options.caching&&this.cache.set(i,l),this.log("Client-side fingerprint generated",l),l}catch(e){throw this.log("Fingerprint generation failed",e),e}}async sendToServer(e,t){const n=new AbortController,r=setTimeout(()=>n.abort(),this.options.timeout);try{const o=await fetch(`${this.options.endpoint}/id`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.options.apiKey}`,"X-TraceTail-SDK":"js/2.3.7"},body:JSON.stringify({components:e,verbose:t||!1,clientCapabilities:{timestamp:Date.now(),sdkVersion:"2.3.7"}}),signal:n.signal});if(clearTimeout(r),!o.ok){if(401===o.status)throw new Error("Invalid API key");throw new Error(`Server returned ${o.status}`)}const i=await o.json(),a={visitorId:i.visitorId,confidence:i.confidence,processingTime:i.processingTime||0};if(t){if(!i.components)throw new Error("Server did not return components in verbose mode");a.components=i.components}return a}catch(e){throw clearTimeout(r),this.options.debug&&console.error("[TraceTail] Server error:",e),e}}static getVersion(){return"2.3.7"}static validateApiKey(e){return/^tt_(test|prod)_[a-zA-Z0-9]{32,}$/.test(e)}calculateConfidence(e){let t=1;e.canvas||(t-=.03),e.webgl||(t-=.03),e.audio||(t-=.02),e.fonts||(t-=.02),e.webRTC||(t-=.01);const n=Object.values(e).filter(e=>null!=e).length;return n<3?t-=.1:n<5&&(t-=.03),Math.min(.999,Math.max(.5,t))}isDNTEnabled(){return"1"===navigator.doNotTrack||"1"===window.doNotTrack||"1"===navigator.msDoNotTrack}log(e,t){this.options.debug&&console.log(`[TraceTail] ${e}`,t)}}export{o as TraceTail,o as default};
|