@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.d.ts
CHANGED
|
@@ -1356,6 +1356,7 @@ declare function hash32(input: string): string;
|
|
|
1356
1356
|
declare function hashFingerprint(components: Record<string, any>, debug?: boolean): string;
|
|
1357
1357
|
/**
|
|
1358
1358
|
* Generate a visitor ID from fingerprint hash
|
|
1359
|
+
* Returns a proper UUID v4 format for database compatibility
|
|
1359
1360
|
*/
|
|
1360
1361
|
declare function generateVisitorId(fingerprintHash: string): string;
|
|
1361
1362
|
|
package/dist/index.esm.js
CHANGED
|
@@ -199,10 +199,19 @@ function hashFingerprint(components, debug = false) {
|
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* Generate a visitor ID from fingerprint hash
|
|
202
|
+
* Returns a proper UUID v4 format for database compatibility
|
|
202
203
|
*/
|
|
203
204
|
function generateVisitorId(fingerprintHash) {
|
|
204
|
-
//
|
|
205
|
-
|
|
205
|
+
// Generate UUID v4 format from fingerprint hash
|
|
206
|
+
const hash = fingerprintHash.length >= 32 ? fingerprintHash : (fingerprintHash + fingerprintHash + fingerprintHash + fingerprintHash).substring(0, 32);
|
|
207
|
+
// Extract bytes for UUID construction
|
|
208
|
+
const hex = hash.substring(0, 32);
|
|
209
|
+
// Set version 4 and variant bits according to RFC 4122
|
|
210
|
+
const chars = hex.split('');
|
|
211
|
+
chars[12] = '4'; // Version 4
|
|
212
|
+
chars[16] = (parseInt(chars[16] || '0', 16) & 0x3 | 0x8).toString(16); // Variant 10
|
|
213
|
+
// Format as UUID: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
214
|
+
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('')}`;
|
|
206
215
|
}
|
|
207
216
|
/**
|
|
208
217
|
* Check if a key represents an unstable component that should be excluded from hashing
|
|
@@ -19763,9 +19772,27 @@ PersistenceManager.memoryStore = new Map();
|
|
|
19763
19772
|
*/
|
|
19764
19773
|
class VisitorIdentityManager {
|
|
19765
19774
|
generateVisitorId() {
|
|
19766
|
-
|
|
19767
|
-
|
|
19768
|
-
|
|
19775
|
+
// Generate UUID v4 format instead of vis_ prefix
|
|
19776
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
19777
|
+
// Set version 4
|
|
19778
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
19779
|
+
// Set variant
|
|
19780
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
19781
|
+
const hex = Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
19782
|
+
return `${hex.substr(0, 8)}-${hex.substr(8, 4)}-${hex.substr(12, 4)}-${hex.substr(16, 4)}-${hex.substr(20, 12)}`;
|
|
19783
|
+
}
|
|
19784
|
+
generateVisitorIdFromHash(hash) {
|
|
19785
|
+
// Generate deterministic UUID v4 format from fingerprint hash
|
|
19786
|
+
// This ensures same fingerprint = same visitor ID
|
|
19787
|
+
const hashExtended = hash.length >= 32 ? hash : (hash + hash + hash + hash).substring(0, 32);
|
|
19788
|
+
// Extract hex characters for UUID construction
|
|
19789
|
+
const hex = hashExtended.substring(0, 32);
|
|
19790
|
+
const chars = hex.split('');
|
|
19791
|
+
// Set version 4 and variant bits according to RFC 4122
|
|
19792
|
+
chars[12] = '4'; // Version 4
|
|
19793
|
+
chars[16] = (parseInt(chars[16] || '0', 16) & 0x3 | 0x8).toString(16); // Variant 10
|
|
19794
|
+
// Format as UUID: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
|
|
19795
|
+
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('')}`;
|
|
19769
19796
|
}
|
|
19770
19797
|
generateSessionId() {
|
|
19771
19798
|
return "ses_" + Array.from(crypto.getRandomValues(new Uint8Array(8)))
|
|
@@ -19824,11 +19851,13 @@ class VisitorIdentityManager {
|
|
|
19824
19851
|
};
|
|
19825
19852
|
}
|
|
19826
19853
|
}
|
|
19827
|
-
// Create new visitor identity
|
|
19828
|
-
|
|
19854
|
+
// Create new visitor identity (deterministic from fingerprint)
|
|
19855
|
+
// Use stableCoreHash for deterministic visitor ID generation
|
|
19856
|
+
// This ensures same fingerprint = same visitor ID across devices and sessions
|
|
19857
|
+
const deterministicVisitorId = this.generateVisitorIdFromHash(params.stableCoreHash);
|
|
19829
19858
|
const newSessionId = params.sessionId || this.generateSessionId();
|
|
19830
19859
|
const newIdentity = {
|
|
19831
|
-
visitorId:
|
|
19860
|
+
visitorId: deterministicVisitorId,
|
|
19832
19861
|
sessionId: newSessionId,
|
|
19833
19862
|
stableCoreHash,
|
|
19834
19863
|
deviceFingerprint: params.deviceFingerprint,
|
|
@@ -19839,7 +19868,7 @@ class VisitorIdentityManager {
|
|
|
19839
19868
|
reused: false,
|
|
19840
19869
|
};
|
|
19841
19870
|
// Store in camouflaged format
|
|
19842
|
-
const camouflageData = this.createCamouflageData(
|
|
19871
|
+
const camouflageData = this.createCamouflageData(deterministicVisitorId, newSessionId, stableCoreHash);
|
|
19843
19872
|
const { method: storageMethod } = PersistenceManager.set(STORAGE_KEYS.prefs, JSON.stringify(camouflageData));
|
|
19844
19873
|
newIdentity.persistenceMethod = storageMethod;
|
|
19845
19874
|
// Also store device fingerprint cache for faster lookups
|