@zaplier/sdk 1.6.2 → 1.6.3
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/index.cjs +38 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +38 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +38 -9
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/modules/fingerprint/hashing.d.ts +1 -0
- package/dist/src/modules/fingerprint/hashing.d.ts.map +1 -1
- package/dist/src/modules/visitor-persistence.d.ts +1 -0
- package/dist/src/modules/visitor-persistence.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -203,10 +203,19 @@ function hashFingerprint(components, debug = false) {
|
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* Generate a visitor ID from fingerprint hash
|
|
206
|
+
* Returns a proper UUID v4 format for database compatibility
|
|
206
207
|
*/
|
|
207
208
|
function generateVisitorId(fingerprintHash) {
|
|
208
|
-
//
|
|
209
|
-
|
|
209
|
+
// Generate UUID v4 format from fingerprint hash
|
|
210
|
+
const hash = fingerprintHash.length >= 32 ? fingerprintHash : (fingerprintHash + fingerprintHash + fingerprintHash + fingerprintHash).substring(0, 32);
|
|
211
|
+
// Extract bytes for UUID construction
|
|
212
|
+
const hex = hash.substring(0, 32);
|
|
213
|
+
// Set version 4 and variant bits according to RFC 4122
|
|
214
|
+
const chars = hex.split('');
|
|
215
|
+
chars[12] = '4'; // Version 4
|
|
216
|
+
chars[16] = (parseInt(chars[16] || '0', 16) & 0x3 | 0x8).toString(16); // Variant 10
|
|
217
|
+
// Format as UUID: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
218
|
+
return `${chars.slice(0, 8).join('')}-${chars.slice(8, 12).join('')}-${chars.slice(12, 16).join('')}-${chars.slice(16, 20).join('')}-${chars.slice(20, 32).join('')}`;
|
|
210
219
|
}
|
|
211
220
|
/**
|
|
212
221
|
* Check if a key represents an unstable component that should be excluded from hashing
|
|
@@ -19767,9 +19776,27 @@ PersistenceManager.memoryStore = new Map();
|
|
|
19767
19776
|
*/
|
|
19768
19777
|
class VisitorIdentityManager {
|
|
19769
19778
|
generateVisitorId() {
|
|
19770
|
-
|
|
19771
|
-
|
|
19772
|
-
|
|
19779
|
+
// Generate UUID v4 format instead of vis_ prefix
|
|
19780
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
19781
|
+
// Set version 4
|
|
19782
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
19783
|
+
// Set variant
|
|
19784
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
19785
|
+
const hex = Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
19786
|
+
return `${hex.substr(0, 8)}-${hex.substr(8, 4)}-${hex.substr(12, 4)}-${hex.substr(16, 4)}-${hex.substr(20, 12)}`;
|
|
19787
|
+
}
|
|
19788
|
+
generateVisitorIdFromHash(hash) {
|
|
19789
|
+
// Generate deterministic UUID v4 format from fingerprint hash
|
|
19790
|
+
// This ensures same fingerprint = same visitor ID
|
|
19791
|
+
const hashExtended = hash.length >= 32 ? hash : (hash + hash + hash + hash).substring(0, 32);
|
|
19792
|
+
// Extract hex characters for UUID construction
|
|
19793
|
+
const hex = hashExtended.substring(0, 32);
|
|
19794
|
+
const chars = hex.split('');
|
|
19795
|
+
// Set version 4 and variant bits according to RFC 4122
|
|
19796
|
+
chars[12] = '4'; // Version 4
|
|
19797
|
+
chars[16] = (parseInt(chars[16] || '0', 16) & 0x3 | 0x8).toString(16); // Variant 10
|
|
19798
|
+
// Format as UUID: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
19799
|
+
return `${chars.slice(0, 8).join('')}-${chars.slice(8, 12).join('')}-${chars.slice(12, 16).join('')}-${chars.slice(16, 20).join('')}-${chars.slice(20, 32).join('')}`;
|
|
19773
19800
|
}
|
|
19774
19801
|
generateSessionId() {
|
|
19775
19802
|
return "ses_" + Array.from(crypto.getRandomValues(new Uint8Array(8)))
|
|
@@ -19828,11 +19855,13 @@ class VisitorIdentityManager {
|
|
|
19828
19855
|
};
|
|
19829
19856
|
}
|
|
19830
19857
|
}
|
|
19831
|
-
// Create new visitor identity
|
|
19832
|
-
|
|
19858
|
+
// Create new visitor identity (deterministic from fingerprint)
|
|
19859
|
+
// Use stableCoreHash for deterministic visitor ID generation
|
|
19860
|
+
// This ensures same fingerprint = same visitor ID across devices and sessions
|
|
19861
|
+
const deterministicVisitorId = this.generateVisitorIdFromHash(params.stableCoreHash);
|
|
19833
19862
|
const newSessionId = params.sessionId || this.generateSessionId();
|
|
19834
19863
|
const newIdentity = {
|
|
19835
|
-
visitorId:
|
|
19864
|
+
visitorId: deterministicVisitorId,
|
|
19836
19865
|
sessionId: newSessionId,
|
|
19837
19866
|
stableCoreHash,
|
|
19838
19867
|
deviceFingerprint: params.deviceFingerprint,
|
|
@@ -19843,7 +19872,7 @@ class VisitorIdentityManager {
|
|
|
19843
19872
|
reused: false,
|
|
19844
19873
|
};
|
|
19845
19874
|
// Store in camouflaged format
|
|
19846
|
-
const camouflageData = this.createCamouflageData(
|
|
19875
|
+
const camouflageData = this.createCamouflageData(deterministicVisitorId, newSessionId, stableCoreHash);
|
|
19847
19876
|
const { method: storageMethod } = PersistenceManager.set(STORAGE_KEYS.prefs, JSON.stringify(camouflageData));
|
|
19848
19877
|
newIdentity.persistenceMethod = storageMethod;
|
|
19849
19878
|
// Also store device fingerprint cache for faster lookups
|