cryptique-sdk 1.1.9 → 1.2.1
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/lib/cjs/index.js +29 -70
- package/lib/esm/index.js +29 -70
- package/lib/umd/index.js +29 -70
- package/package.json +1 -1
package/lib/cjs/index.js
CHANGED
|
@@ -161,7 +161,8 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
161
161
|
timer: null, // Session tracking interval timer
|
|
162
162
|
countryName: null, // Cached country name
|
|
163
163
|
isInitialized: false, // Prevents API calls during initialization
|
|
164
|
-
eip6963Providers: []
|
|
164
|
+
eip6963Providers: [], // EIP-6963 discovered wallet providers
|
|
165
|
+
reportedWalletAddress: null // Last wallet address reported to backend (prevents duplicate calls)
|
|
165
166
|
};
|
|
166
167
|
|
|
167
168
|
// Ready promise - resolves when SDK is fully initialized (allows consumers to await init)
|
|
@@ -431,12 +432,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
431
432
|
sessionData.utm_id = persistentData.utm_id;
|
|
432
433
|
}
|
|
433
434
|
|
|
434
|
-
|
|
435
|
-
wallet_address: sessionData.wallet_address,
|
|
436
|
-
is_web3_user: sessionData.is_web3_user,
|
|
437
|
-
referrer: sessionData.referrer,
|
|
438
|
-
utm_source: sessionData.utm_source
|
|
439
|
-
});
|
|
435
|
+
// Session-specific persistent data restored successfully (wallet, web3 status, referrer, UTM source)
|
|
440
436
|
|
|
441
437
|
} catch (err) {
|
|
442
438
|
console.warn('Failed to restore session-specific persistent data:', err);
|
|
@@ -460,11 +456,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
460
456
|
if (currentSessionId) {
|
|
461
457
|
const sessionKey = `${CONFIG.STORAGE_KEYS.PERSISTENT_DATA}_${currentSessionId}`;
|
|
462
458
|
localStorage.removeItem(sessionKey);
|
|
463
|
-
console.log(`✅ Cleared session-specific persistent data for session ${currentSessionId}`);
|
|
464
459
|
} else {
|
|
465
460
|
// Fallback: clear old global persistent data if session ID not available
|
|
466
461
|
localStorage.removeItem(CONFIG.STORAGE_KEYS.PERSISTENT_DATA);
|
|
467
|
-
console.log('✅ Cleared global persistent data from localStorage');
|
|
468
462
|
}
|
|
469
463
|
} catch (err) {
|
|
470
464
|
console.warn('Failed to clear persistent data:', err);
|
|
@@ -495,8 +489,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
495
489
|
keysToRemove.forEach(key => {
|
|
496
490
|
localStorage.removeItem(key);
|
|
497
491
|
});
|
|
498
|
-
|
|
499
|
-
console.log(`✅ Cleared all persistent data (${keysToRemove.length} keys removed)`);
|
|
500
492
|
} catch (err) {
|
|
501
493
|
console.warn('Failed to clear all persistent data:', err);
|
|
502
494
|
}
|
|
@@ -803,7 +795,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
803
795
|
_cachedDistinctId = distinctId;
|
|
804
796
|
|
|
805
797
|
const type = distinctId.startsWith('anon_') ? 'anonymous' : 'identified';
|
|
806
|
-
console.log(`✅ [Storage] Stored ${type} distinct_id in localStorage and sessionStorage: ${distinctId}`);
|
|
807
798
|
} catch (err) {
|
|
808
799
|
console.warn('Failed to set distinct_id:', err);
|
|
809
800
|
}
|
|
@@ -2319,7 +2310,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2319
2310
|
}
|
|
2320
2311
|
} catch (error) {
|
|
2321
2312
|
// API may not be available or user denied permission
|
|
2322
|
-
console.debug('User-Agent Client Hints API not available:', error);
|
|
2323
2313
|
}
|
|
2324
2314
|
} else {
|
|
2325
2315
|
// Fallback: parse from user agent string
|
|
@@ -2547,16 +2537,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2547
2537
|
// Current address is valid - only update to another valid address
|
|
2548
2538
|
if (newIsValid) {
|
|
2549
2539
|
sessionData.wallet_address = newAddress;
|
|
2550
|
-
console.log(`🔄 Wallet address updated: ${currentAddress} → ${newAddress}`);
|
|
2551
|
-
} else {
|
|
2552
|
-
console.log(`🔒 Wallet address protected: keeping ${currentAddress} (cannot set to ${newAddress})`);
|
|
2553
2540
|
}
|
|
2554
2541
|
} else {
|
|
2555
2542
|
// Current address is not valid - can set to any value
|
|
2556
2543
|
sessionData.wallet_address = newAddress;
|
|
2557
|
-
if (newIsValid) {
|
|
2558
|
-
console.log(`✅ Wallet address set: ${newAddress}`);
|
|
2559
|
-
}
|
|
2560
2544
|
}
|
|
2561
2545
|
},
|
|
2562
2546
|
|
|
@@ -2855,8 +2839,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2855
2839
|
// Invalid wallet type - only set if wallet_type is not already set to a valid value
|
|
2856
2840
|
if (!sessionData.wallet_type || sessionData.wallet_type === "No Wallet Detected") {
|
|
2857
2841
|
sessionData.wallet_type = walletType;
|
|
2858
|
-
} else {
|
|
2859
|
-
console.log(`🔒 Wallet type protected: keeping ${sessionData.wallet_type} (cannot set to ${walletType})`);
|
|
2860
2842
|
}
|
|
2861
2843
|
}
|
|
2862
2844
|
// Update chain_name with immutability protection
|
|
@@ -2868,8 +2850,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2868
2850
|
// Invalid chain name - only set if chain_name is not already set to a valid value
|
|
2869
2851
|
if (!sessionData.chain_name || sessionData.chain_name === "Not Connected") {
|
|
2870
2852
|
sessionData.chain_name = chainName;
|
|
2871
|
-
} else {
|
|
2872
|
-
console.log(`🔒 Chain name protected: keeping ${sessionData.chain_name} (cannot set to ${chainName})`);
|
|
2873
2853
|
}
|
|
2874
2854
|
}
|
|
2875
2855
|
// Keep is_web3_user as true if it's already true or if we detect a wallet
|
|
@@ -2894,11 +2874,16 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2894
2874
|
console.error('Error updating UTM event with wallet:', error);
|
|
2895
2875
|
});
|
|
2896
2876
|
|
|
2897
|
-
// Automatic wallet address matching -
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2877
|
+
// Automatic wallet address matching - only call once per address per session
|
|
2878
|
+
// Prevents repeated calls to /api/sdk/wallet-address on every interval tick
|
|
2879
|
+
if (walletAddress !== runtimeState.reportedWalletAddress) {
|
|
2880
|
+
runtimeState.reportedWalletAddress = walletAddress;
|
|
2881
|
+
IdentityManager.walletAddress(walletAddress).catch((error) => {
|
|
2882
|
+
console.warn('Error in automatic wallet address matching:', error);
|
|
2883
|
+
// Reset so it retries next time wallet info is updated
|
|
2884
|
+
runtimeState.reportedWalletAddress = null;
|
|
2885
|
+
});
|
|
2886
|
+
}
|
|
2902
2887
|
}
|
|
2903
2888
|
|
|
2904
2889
|
return {
|
|
@@ -3156,7 +3141,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
3156
3141
|
} else {
|
|
3157
3142
|
// Wallet disconnected - but protect wallet_address, chain_name, and wallet_type from becoming null/placeholder
|
|
3158
3143
|
// Keep the last known values for session consistency
|
|
3159
|
-
console.log('🔒 Wallet disconnected but keeping wallet data for session consistency');
|
|
3160
3144
|
sessionData.wallet_connected = false;
|
|
3161
3145
|
// Do NOT set wallet_address, chain_name, or wallet_type to null/placeholder - keep them for session attribution
|
|
3162
3146
|
// The updateWalletInfo() method already has immutability protection, so we don't need to call it here
|
|
@@ -5334,12 +5318,18 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5334
5318
|
*/
|
|
5335
5319
|
startNetworkTracking() {
|
|
5336
5320
|
try {
|
|
5337
|
-
// Track fetch errors
|
|
5321
|
+
// Track fetch errors - only intercept calls to our own backend
|
|
5338
5322
|
const originalFetch = window.fetch;
|
|
5339
5323
|
window.fetch = function(...args) {
|
|
5340
5324
|
const startTime = Date.now();
|
|
5341
|
-
const url = args[0];
|
|
5342
|
-
|
|
5325
|
+
const url = typeof args[0] === 'string' ? args[0] : (args[0]?.url || '');
|
|
5326
|
+
|
|
5327
|
+
// Pass third-party requests through completely untouched — no interception,
|
|
5328
|
+
// no involvement of our SDK in their call stack or error handling
|
|
5329
|
+
if (!url.includes('backend.cryptique.io')) {
|
|
5330
|
+
return originalFetch.apply(this, args);
|
|
5331
|
+
}
|
|
5332
|
+
|
|
5343
5333
|
return originalFetch.apply(this, args).then(response => {
|
|
5344
5334
|
// Only track error status codes (4xx, 5xx)
|
|
5345
5335
|
if (response.status >= 400) {
|
|
@@ -5374,7 +5364,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5374
5364
|
});
|
|
5375
5365
|
};
|
|
5376
5366
|
|
|
5377
|
-
// Track XMLHttpRequest errors
|
|
5367
|
+
// Track XMLHttpRequest errors - only intercept calls to our own backend
|
|
5378
5368
|
const originalXHROpen = XMLHttpRequest.prototype.open;
|
|
5379
5369
|
const originalXHRSend = XMLHttpRequest.prototype.send;
|
|
5380
5370
|
|
|
@@ -5387,6 +5377,11 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5387
5377
|
XMLHttpRequest.prototype.send = function(...args) {
|
|
5388
5378
|
const startTime = Date.now();
|
|
5389
5379
|
const xhr = this;
|
|
5380
|
+
|
|
5381
|
+
// Pass third-party XHR requests through completely untouched
|
|
5382
|
+
if (!xhr._cryptiqueUrl || !xhr._cryptiqueUrl.includes('backend.cryptique.io')) {
|
|
5383
|
+
return originalXHRSend.apply(this, args);
|
|
5384
|
+
}
|
|
5390
5385
|
|
|
5391
5386
|
xhr.addEventListener('load', function() {
|
|
5392
5387
|
if (xhr.status >= 400) {
|
|
@@ -5645,13 +5640,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5645
5640
|
try {
|
|
5646
5641
|
// Update session duration
|
|
5647
5642
|
DurationManager.updateSessionDuration();
|
|
5648
|
-
|
|
5649
|
-
// Update wallet info (non-blocking)
|
|
5650
|
-
try {
|
|
5651
|
-
await WalletManager.updateWalletInfo();
|
|
5652
|
-
} catch (walletError) {
|
|
5653
|
-
console.warn('Error updating wallet info:', walletError);
|
|
5654
|
-
}
|
|
5655
5643
|
|
|
5656
5644
|
// Update session activity
|
|
5657
5645
|
StorageManager.updateSessionActivity();
|
|
@@ -5712,15 +5700,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5712
5700
|
// Save session to storage
|
|
5713
5701
|
StorageManager.saveSession(sessionData);
|
|
5714
5702
|
|
|
5715
|
-
// Always sync distinctId from storage before
|
|
5703
|
+
// Always sync distinctId from storage before sending to ensure consistency
|
|
5716
5704
|
sessionData.distinctId = StorageManager.getDistinctId();
|
|
5717
5705
|
|
|
5718
|
-
// Console log raw session data intermittently
|
|
5719
|
-
console.log('📊 [Session] Raw Session Data:', {
|
|
5720
|
-
sessionData: sessionData,
|
|
5721
|
-
storedSession: storedSession
|
|
5722
|
-
});
|
|
5723
|
-
|
|
5724
5706
|
// Send session data
|
|
5725
5707
|
await APIClient.sendSessionData();
|
|
5726
5708
|
} catch (error) {
|
|
@@ -6441,8 +6423,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6441
6423
|
session.identified = true;
|
|
6442
6424
|
StorageManager.saveSession(session);
|
|
6443
6425
|
}
|
|
6444
|
-
|
|
6445
|
-
console.log(`✅ [Identity] Distinct ID updated: ${currentDistinctId} → ${result.distinctId}`);
|
|
6446
6426
|
} else if (result.merged && result.newDistinctId) {
|
|
6447
6427
|
// Fallback: use newDistinctId if distinctId not present
|
|
6448
6428
|
StorageManager.setDistinctId(result.newDistinctId);
|
|
@@ -6462,8 +6442,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6462
6442
|
session.identified = true;
|
|
6463
6443
|
StorageManager.saveSession(session);
|
|
6464
6444
|
}
|
|
6465
|
-
|
|
6466
|
-
console.log(`✅ [Identity] Distinct ID merged: ${currentDistinctId} → ${result.newDistinctId}`);
|
|
6467
6445
|
} else {
|
|
6468
6446
|
console.warn('⚠️ [Identity] No distinctId or newDistinctId in response:', result);
|
|
6469
6447
|
}
|
|
@@ -6562,8 +6540,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6562
6540
|
// Ignore errors
|
|
6563
6541
|
}
|
|
6564
6542
|
|
|
6565
|
-
console.log(`🔄 [Identity] Reset to anonymous: ${newDistinctId}`);
|
|
6566
|
-
|
|
6567
6543
|
return { success: true, distinctId: newDistinctId };
|
|
6568
6544
|
} catch (error) {
|
|
6569
6545
|
console.error('❌ [Identity] Error in reset():', error);
|
|
@@ -6619,8 +6595,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6619
6595
|
StorageManager.updateBackup({ id: sessionData.sessionId, userId: sessionData.userId });
|
|
6620
6596
|
// That's it - session sync will pick it up automatically, just like automatic detection
|
|
6621
6597
|
|
|
6622
|
-
console.log(`✅ [Identity] Wallet address set in sessionData: ${trimmedWalletAddress}`);
|
|
6623
|
-
|
|
6624
6598
|
// Get current distinct_id
|
|
6625
6599
|
const currentDistinctId = StorageManager.getDistinctId();
|
|
6626
6600
|
|
|
@@ -6667,12 +6641,8 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6667
6641
|
|
|
6668
6642
|
// Update userSession
|
|
6669
6643
|
userSession.userId = result.newUserId;
|
|
6670
|
-
|
|
6671
|
-
console.log(`✅ [Identity] User merged via wallet: ${currentUserId} → ${result.newUserId}`);
|
|
6672
6644
|
}
|
|
6673
6645
|
|
|
6674
|
-
console.log(`✅ [Identity] Wallet address set: ${trimmedWalletAddress}`);
|
|
6675
|
-
|
|
6676
6646
|
return result;
|
|
6677
6647
|
} catch (error) {
|
|
6678
6648
|
console.error('❌ [Identity] Error in walletAddress():', error);
|
|
@@ -7385,7 +7355,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7385
7355
|
return { success: false, error: result.message || 'Set failed' };
|
|
7386
7356
|
}
|
|
7387
7357
|
|
|
7388
|
-
console.log('✅ [People] Properties set successfully');
|
|
7389
7358
|
return result;
|
|
7390
7359
|
|
|
7391
7360
|
} catch (error) {
|
|
@@ -7435,7 +7404,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7435
7404
|
return { success: false, error: result.message || 'SetOnce failed' };
|
|
7436
7405
|
}
|
|
7437
7406
|
|
|
7438
|
-
console.log('✅ [People] Properties set once successfully');
|
|
7439
7407
|
return result;
|
|
7440
7408
|
|
|
7441
7409
|
} catch (error) {
|
|
@@ -7485,7 +7453,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7485
7453
|
return { success: false, error: result.message || 'Unset failed' };
|
|
7486
7454
|
}
|
|
7487
7455
|
|
|
7488
|
-
console.log('✅ [People] Properties unset successfully');
|
|
7489
7456
|
return result;
|
|
7490
7457
|
|
|
7491
7458
|
} catch (error) {
|
|
@@ -7542,7 +7509,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7542
7509
|
return { success: false, error: result.message || 'Increment failed' };
|
|
7543
7510
|
}
|
|
7544
7511
|
|
|
7545
|
-
console.log('✅ [People] Property incremented successfully');
|
|
7546
7512
|
return result;
|
|
7547
7513
|
|
|
7548
7514
|
} catch (error) {
|
|
@@ -7599,7 +7565,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7599
7565
|
return { success: false, error: result.message || 'Append failed' };
|
|
7600
7566
|
}
|
|
7601
7567
|
|
|
7602
|
-
console.log('✅ [People] Values appended successfully');
|
|
7603
7568
|
return result;
|
|
7604
7569
|
|
|
7605
7570
|
} catch (error) {
|
|
@@ -7656,7 +7621,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7656
7621
|
return { success: false, error: result.message || 'Union failed' };
|
|
7657
7622
|
}
|
|
7658
7623
|
|
|
7659
|
-
console.log('✅ [People] Values unioned successfully');
|
|
7660
7624
|
return result;
|
|
7661
7625
|
|
|
7662
7626
|
} catch (error) {
|
|
@@ -7713,7 +7677,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7713
7677
|
return { success: false, error: result.message || 'Remove failed' };
|
|
7714
7678
|
}
|
|
7715
7679
|
|
|
7716
|
-
console.log('✅ [People] Values removed successfully');
|
|
7717
7680
|
return result;
|
|
7718
7681
|
|
|
7719
7682
|
} catch (error) {
|
|
@@ -7765,7 +7728,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7765
7728
|
return { success: false, error: result.message || 'TrackCharge failed' };
|
|
7766
7729
|
}
|
|
7767
7730
|
|
|
7768
|
-
console.log('✅ [People] Charge tracked successfully');
|
|
7769
7731
|
return result;
|
|
7770
7732
|
|
|
7771
7733
|
} catch (error) {
|
|
@@ -7808,7 +7770,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7808
7770
|
return { success: false, error: result.message || 'ClearCharges failed' };
|
|
7809
7771
|
}
|
|
7810
7772
|
|
|
7811
|
-
console.log('✅ [People] Charges cleared successfully');
|
|
7812
7773
|
return result;
|
|
7813
7774
|
|
|
7814
7775
|
} catch (error) {
|
|
@@ -7851,8 +7812,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7851
7812
|
return { success: false, error: result.message || 'DeleteUser failed' };
|
|
7852
7813
|
}
|
|
7853
7814
|
|
|
7854
|
-
console.log('✅ [People] User deleted successfully');
|
|
7855
|
-
|
|
7856
7815
|
// Clear local storage after successful deletion
|
|
7857
7816
|
StorageManager.clearSession();
|
|
7858
7817
|
StorageManager.clearUserId();
|
package/lib/esm/index.js
CHANGED
|
@@ -159,7 +159,8 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
159
159
|
timer: null, // Session tracking interval timer
|
|
160
160
|
countryName: null, // Cached country name
|
|
161
161
|
isInitialized: false, // Prevents API calls during initialization
|
|
162
|
-
eip6963Providers: []
|
|
162
|
+
eip6963Providers: [], // EIP-6963 discovered wallet providers
|
|
163
|
+
reportedWalletAddress: null // Last wallet address reported to backend (prevents duplicate calls)
|
|
163
164
|
};
|
|
164
165
|
|
|
165
166
|
// Ready promise - resolves when SDK is fully initialized (allows consumers to await init)
|
|
@@ -429,12 +430,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
429
430
|
sessionData.utm_id = persistentData.utm_id;
|
|
430
431
|
}
|
|
431
432
|
|
|
432
|
-
|
|
433
|
-
wallet_address: sessionData.wallet_address,
|
|
434
|
-
is_web3_user: sessionData.is_web3_user,
|
|
435
|
-
referrer: sessionData.referrer,
|
|
436
|
-
utm_source: sessionData.utm_source
|
|
437
|
-
});
|
|
433
|
+
// Session-specific persistent data restored successfully (wallet, web3 status, referrer, UTM source)
|
|
438
434
|
|
|
439
435
|
} catch (err) {
|
|
440
436
|
console.warn('Failed to restore session-specific persistent data:', err);
|
|
@@ -458,11 +454,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
458
454
|
if (currentSessionId) {
|
|
459
455
|
const sessionKey = `${CONFIG.STORAGE_KEYS.PERSISTENT_DATA}_${currentSessionId}`;
|
|
460
456
|
localStorage.removeItem(sessionKey);
|
|
461
|
-
console.log(`✅ Cleared session-specific persistent data for session ${currentSessionId}`);
|
|
462
457
|
} else {
|
|
463
458
|
// Fallback: clear old global persistent data if session ID not available
|
|
464
459
|
localStorage.removeItem(CONFIG.STORAGE_KEYS.PERSISTENT_DATA);
|
|
465
|
-
console.log('✅ Cleared global persistent data from localStorage');
|
|
466
460
|
}
|
|
467
461
|
} catch (err) {
|
|
468
462
|
console.warn('Failed to clear persistent data:', err);
|
|
@@ -493,8 +487,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
493
487
|
keysToRemove.forEach(key => {
|
|
494
488
|
localStorage.removeItem(key);
|
|
495
489
|
});
|
|
496
|
-
|
|
497
|
-
console.log(`✅ Cleared all persistent data (${keysToRemove.length} keys removed)`);
|
|
498
490
|
} catch (err) {
|
|
499
491
|
console.warn('Failed to clear all persistent data:', err);
|
|
500
492
|
}
|
|
@@ -801,7 +793,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
801
793
|
_cachedDistinctId = distinctId;
|
|
802
794
|
|
|
803
795
|
const type = distinctId.startsWith('anon_') ? 'anonymous' : 'identified';
|
|
804
|
-
console.log(`✅ [Storage] Stored ${type} distinct_id in localStorage and sessionStorage: ${distinctId}`);
|
|
805
796
|
} catch (err) {
|
|
806
797
|
console.warn('Failed to set distinct_id:', err);
|
|
807
798
|
}
|
|
@@ -2317,7 +2308,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2317
2308
|
}
|
|
2318
2309
|
} catch (error) {
|
|
2319
2310
|
// API may not be available or user denied permission
|
|
2320
|
-
console.debug('User-Agent Client Hints API not available:', error);
|
|
2321
2311
|
}
|
|
2322
2312
|
} else {
|
|
2323
2313
|
// Fallback: parse from user agent string
|
|
@@ -2545,16 +2535,10 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2545
2535
|
// Current address is valid - only update to another valid address
|
|
2546
2536
|
if (newIsValid) {
|
|
2547
2537
|
sessionData.wallet_address = newAddress;
|
|
2548
|
-
console.log(`🔄 Wallet address updated: ${currentAddress} → ${newAddress}`);
|
|
2549
|
-
} else {
|
|
2550
|
-
console.log(`🔒 Wallet address protected: keeping ${currentAddress} (cannot set to ${newAddress})`);
|
|
2551
2538
|
}
|
|
2552
2539
|
} else {
|
|
2553
2540
|
// Current address is not valid - can set to any value
|
|
2554
2541
|
sessionData.wallet_address = newAddress;
|
|
2555
|
-
if (newIsValid) {
|
|
2556
|
-
console.log(`✅ Wallet address set: ${newAddress}`);
|
|
2557
|
-
}
|
|
2558
2542
|
}
|
|
2559
2543
|
},
|
|
2560
2544
|
|
|
@@ -2853,8 +2837,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2853
2837
|
// Invalid wallet type - only set if wallet_type is not already set to a valid value
|
|
2854
2838
|
if (!sessionData.wallet_type || sessionData.wallet_type === "No Wallet Detected") {
|
|
2855
2839
|
sessionData.wallet_type = walletType;
|
|
2856
|
-
} else {
|
|
2857
|
-
console.log(`🔒 Wallet type protected: keeping ${sessionData.wallet_type} (cannot set to ${walletType})`);
|
|
2858
2840
|
}
|
|
2859
2841
|
}
|
|
2860
2842
|
// Update chain_name with immutability protection
|
|
@@ -2866,8 +2848,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2866
2848
|
// Invalid chain name - only set if chain_name is not already set to a valid value
|
|
2867
2849
|
if (!sessionData.chain_name || sessionData.chain_name === "Not Connected") {
|
|
2868
2850
|
sessionData.chain_name = chainName;
|
|
2869
|
-
} else {
|
|
2870
|
-
console.log(`🔒 Chain name protected: keeping ${sessionData.chain_name} (cannot set to ${chainName})`);
|
|
2871
2851
|
}
|
|
2872
2852
|
}
|
|
2873
2853
|
// Keep is_web3_user as true if it's already true or if we detect a wallet
|
|
@@ -2892,11 +2872,16 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
2892
2872
|
console.error('Error updating UTM event with wallet:', error);
|
|
2893
2873
|
});
|
|
2894
2874
|
|
|
2895
|
-
// Automatic wallet address matching -
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2875
|
+
// Automatic wallet address matching - only call once per address per session
|
|
2876
|
+
// Prevents repeated calls to /api/sdk/wallet-address on every interval tick
|
|
2877
|
+
if (walletAddress !== runtimeState.reportedWalletAddress) {
|
|
2878
|
+
runtimeState.reportedWalletAddress = walletAddress;
|
|
2879
|
+
IdentityManager.walletAddress(walletAddress).catch((error) => {
|
|
2880
|
+
console.warn('Error in automatic wallet address matching:', error);
|
|
2881
|
+
// Reset so it retries next time wallet info is updated
|
|
2882
|
+
runtimeState.reportedWalletAddress = null;
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2900
2885
|
}
|
|
2901
2886
|
|
|
2902
2887
|
return {
|
|
@@ -3154,7 +3139,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
3154
3139
|
} else {
|
|
3155
3140
|
// Wallet disconnected - but protect wallet_address, chain_name, and wallet_type from becoming null/placeholder
|
|
3156
3141
|
// Keep the last known values for session consistency
|
|
3157
|
-
console.log('🔒 Wallet disconnected but keeping wallet data for session consistency');
|
|
3158
3142
|
sessionData.wallet_connected = false;
|
|
3159
3143
|
// Do NOT set wallet_address, chain_name, or wallet_type to null/placeholder - keep them for session attribution
|
|
3160
3144
|
// The updateWalletInfo() method already has immutability protection, so we don't need to call it here
|
|
@@ -5332,12 +5316,18 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5332
5316
|
*/
|
|
5333
5317
|
startNetworkTracking() {
|
|
5334
5318
|
try {
|
|
5335
|
-
// Track fetch errors
|
|
5319
|
+
// Track fetch errors - only intercept calls to our own backend
|
|
5336
5320
|
const originalFetch = window.fetch;
|
|
5337
5321
|
window.fetch = function(...args) {
|
|
5338
5322
|
const startTime = Date.now();
|
|
5339
|
-
const url = args[0];
|
|
5340
|
-
|
|
5323
|
+
const url = typeof args[0] === 'string' ? args[0] : (args[0]?.url || '');
|
|
5324
|
+
|
|
5325
|
+
// Pass third-party requests through completely untouched — no interception,
|
|
5326
|
+
// no involvement of our SDK in their call stack or error handling
|
|
5327
|
+
if (!url.includes('backend.cryptique.io')) {
|
|
5328
|
+
return originalFetch.apply(this, args);
|
|
5329
|
+
}
|
|
5330
|
+
|
|
5341
5331
|
return originalFetch.apply(this, args).then(response => {
|
|
5342
5332
|
// Only track error status codes (4xx, 5xx)
|
|
5343
5333
|
if (response.status >= 400) {
|
|
@@ -5372,7 +5362,7 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5372
5362
|
});
|
|
5373
5363
|
};
|
|
5374
5364
|
|
|
5375
|
-
// Track XMLHttpRequest errors
|
|
5365
|
+
// Track XMLHttpRequest errors - only intercept calls to our own backend
|
|
5376
5366
|
const originalXHROpen = XMLHttpRequest.prototype.open;
|
|
5377
5367
|
const originalXHRSend = XMLHttpRequest.prototype.send;
|
|
5378
5368
|
|
|
@@ -5385,6 +5375,11 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5385
5375
|
XMLHttpRequest.prototype.send = function(...args) {
|
|
5386
5376
|
const startTime = Date.now();
|
|
5387
5377
|
const xhr = this;
|
|
5378
|
+
|
|
5379
|
+
// Pass third-party XHR requests through completely untouched
|
|
5380
|
+
if (!xhr._cryptiqueUrl || !xhr._cryptiqueUrl.includes('backend.cryptique.io')) {
|
|
5381
|
+
return originalXHRSend.apply(this, args);
|
|
5382
|
+
}
|
|
5388
5383
|
|
|
5389
5384
|
xhr.addEventListener('load', function() {
|
|
5390
5385
|
if (xhr.status >= 400) {
|
|
@@ -5643,13 +5638,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5643
5638
|
try {
|
|
5644
5639
|
// Update session duration
|
|
5645
5640
|
DurationManager.updateSessionDuration();
|
|
5646
|
-
|
|
5647
|
-
// Update wallet info (non-blocking)
|
|
5648
|
-
try {
|
|
5649
|
-
await WalletManager.updateWalletInfo();
|
|
5650
|
-
} catch (walletError) {
|
|
5651
|
-
console.warn('Error updating wallet info:', walletError);
|
|
5652
|
-
}
|
|
5653
5641
|
|
|
5654
5642
|
// Update session activity
|
|
5655
5643
|
StorageManager.updateSessionActivity();
|
|
@@ -5710,15 +5698,9 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
5710
5698
|
// Save session to storage
|
|
5711
5699
|
StorageManager.saveSession(sessionData);
|
|
5712
5700
|
|
|
5713
|
-
// Always sync distinctId from storage before
|
|
5701
|
+
// Always sync distinctId from storage before sending to ensure consistency
|
|
5714
5702
|
sessionData.distinctId = StorageManager.getDistinctId();
|
|
5715
5703
|
|
|
5716
|
-
// Console log raw session data intermittently
|
|
5717
|
-
console.log('📊 [Session] Raw Session Data:', {
|
|
5718
|
-
sessionData: sessionData,
|
|
5719
|
-
storedSession: storedSession
|
|
5720
|
-
});
|
|
5721
|
-
|
|
5722
5704
|
// Send session data
|
|
5723
5705
|
await APIClient.sendSessionData();
|
|
5724
5706
|
} catch (error) {
|
|
@@ -6439,8 +6421,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6439
6421
|
session.identified = true;
|
|
6440
6422
|
StorageManager.saveSession(session);
|
|
6441
6423
|
}
|
|
6442
|
-
|
|
6443
|
-
console.log(`✅ [Identity] Distinct ID updated: ${currentDistinctId} → ${result.distinctId}`);
|
|
6444
6424
|
} else if (result.merged && result.newDistinctId) {
|
|
6445
6425
|
// Fallback: use newDistinctId if distinctId not present
|
|
6446
6426
|
StorageManager.setDistinctId(result.newDistinctId);
|
|
@@ -6460,8 +6440,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6460
6440
|
session.identified = true;
|
|
6461
6441
|
StorageManager.saveSession(session);
|
|
6462
6442
|
}
|
|
6463
|
-
|
|
6464
|
-
console.log(`✅ [Identity] Distinct ID merged: ${currentDistinctId} → ${result.newDistinctId}`);
|
|
6465
6443
|
} else {
|
|
6466
6444
|
console.warn('⚠️ [Identity] No distinctId or newDistinctId in response:', result);
|
|
6467
6445
|
}
|
|
@@ -6560,8 +6538,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6560
6538
|
// Ignore errors
|
|
6561
6539
|
}
|
|
6562
6540
|
|
|
6563
|
-
console.log(`🔄 [Identity] Reset to anonymous: ${newDistinctId}`);
|
|
6564
|
-
|
|
6565
6541
|
return { success: true, distinctId: newDistinctId };
|
|
6566
6542
|
} catch (error) {
|
|
6567
6543
|
console.error('❌ [Identity] Error in reset():', error);
|
|
@@ -6617,8 +6593,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6617
6593
|
StorageManager.updateBackup({ id: sessionData.sessionId, userId: sessionData.userId });
|
|
6618
6594
|
// That's it - session sync will pick it up automatically, just like automatic detection
|
|
6619
6595
|
|
|
6620
|
-
console.log(`✅ [Identity] Wallet address set in sessionData: ${trimmedWalletAddress}`);
|
|
6621
|
-
|
|
6622
6596
|
// Get current distinct_id
|
|
6623
6597
|
const currentDistinctId = StorageManager.getDistinctId();
|
|
6624
6598
|
|
|
@@ -6665,12 +6639,8 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
6665
6639
|
|
|
6666
6640
|
// Update userSession
|
|
6667
6641
|
userSession.userId = result.newUserId;
|
|
6668
|
-
|
|
6669
|
-
console.log(`✅ [Identity] User merged via wallet: ${currentUserId} → ${result.newUserId}`);
|
|
6670
6642
|
}
|
|
6671
6643
|
|
|
6672
|
-
console.log(`✅ [Identity] Wallet address set: ${trimmedWalletAddress}`);
|
|
6673
|
-
|
|
6674
6644
|
return result;
|
|
6675
6645
|
} catch (error) {
|
|
6676
6646
|
console.error('❌ [Identity] Error in walletAddress():', error);
|
|
@@ -7383,7 +7353,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7383
7353
|
return { success: false, error: result.message || 'Set failed' };
|
|
7384
7354
|
}
|
|
7385
7355
|
|
|
7386
|
-
console.log('✅ [People] Properties set successfully');
|
|
7387
7356
|
return result;
|
|
7388
7357
|
|
|
7389
7358
|
} catch (error) {
|
|
@@ -7433,7 +7402,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7433
7402
|
return { success: false, error: result.message || 'SetOnce failed' };
|
|
7434
7403
|
}
|
|
7435
7404
|
|
|
7436
|
-
console.log('✅ [People] Properties set once successfully');
|
|
7437
7405
|
return result;
|
|
7438
7406
|
|
|
7439
7407
|
} catch (error) {
|
|
@@ -7483,7 +7451,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7483
7451
|
return { success: false, error: result.message || 'Unset failed' };
|
|
7484
7452
|
}
|
|
7485
7453
|
|
|
7486
|
-
console.log('✅ [People] Properties unset successfully');
|
|
7487
7454
|
return result;
|
|
7488
7455
|
|
|
7489
7456
|
} catch (error) {
|
|
@@ -7540,7 +7507,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7540
7507
|
return { success: false, error: result.message || 'Increment failed' };
|
|
7541
7508
|
}
|
|
7542
7509
|
|
|
7543
|
-
console.log('✅ [People] Property incremented successfully');
|
|
7544
7510
|
return result;
|
|
7545
7511
|
|
|
7546
7512
|
} catch (error) {
|
|
@@ -7597,7 +7563,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7597
7563
|
return { success: false, error: result.message || 'Append failed' };
|
|
7598
7564
|
}
|
|
7599
7565
|
|
|
7600
|
-
console.log('✅ [People] Values appended successfully');
|
|
7601
7566
|
return result;
|
|
7602
7567
|
|
|
7603
7568
|
} catch (error) {
|
|
@@ -7654,7 +7619,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7654
7619
|
return { success: false, error: result.message || 'Union failed' };
|
|
7655
7620
|
}
|
|
7656
7621
|
|
|
7657
|
-
console.log('✅ [People] Values unioned successfully');
|
|
7658
7622
|
return result;
|
|
7659
7623
|
|
|
7660
7624
|
} catch (error) {
|
|
@@ -7711,7 +7675,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7711
7675
|
return { success: false, error: result.message || 'Remove failed' };
|
|
7712
7676
|
}
|
|
7713
7677
|
|
|
7714
|
-
console.log('✅ [People] Values removed successfully');
|
|
7715
7678
|
return result;
|
|
7716
7679
|
|
|
7717
7680
|
} catch (error) {
|
|
@@ -7763,7 +7726,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7763
7726
|
return { success: false, error: result.message || 'TrackCharge failed' };
|
|
7764
7727
|
}
|
|
7765
7728
|
|
|
7766
|
-
console.log('✅ [People] Charge tracked successfully');
|
|
7767
7729
|
return result;
|
|
7768
7730
|
|
|
7769
7731
|
} catch (error) {
|
|
@@ -7806,7 +7768,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7806
7768
|
return { success: false, error: result.message || 'ClearCharges failed' };
|
|
7807
7769
|
}
|
|
7808
7770
|
|
|
7809
|
-
console.log('✅ [People] Charges cleared successfully');
|
|
7810
7771
|
return result;
|
|
7811
7772
|
|
|
7812
7773
|
} catch (error) {
|
|
@@ -7849,8 +7810,6 @@ if (window.Cryptique && window.Cryptique.initialized) ; else {
|
|
|
7849
7810
|
return { success: false, error: result.message || 'DeleteUser failed' };
|
|
7850
7811
|
}
|
|
7851
7812
|
|
|
7852
|
-
console.log('✅ [People] User deleted successfully');
|
|
7853
|
-
|
|
7854
7813
|
// Clear local storage after successful deletion
|
|
7855
7814
|
StorageManager.clearSession();
|
|
7856
7815
|
StorageManager.clearUserId();
|
package/lib/umd/index.js
CHANGED
|
@@ -165,7 +165,8 @@
|
|
|
165
165
|
timer: null, // Session tracking interval timer
|
|
166
166
|
countryName: null, // Cached country name
|
|
167
167
|
isInitialized: false, // Prevents API calls during initialization
|
|
168
|
-
eip6963Providers: []
|
|
168
|
+
eip6963Providers: [], // EIP-6963 discovered wallet providers
|
|
169
|
+
reportedWalletAddress: null // Last wallet address reported to backend (prevents duplicate calls)
|
|
169
170
|
};
|
|
170
171
|
|
|
171
172
|
// Ready promise - resolves when SDK is fully initialized (allows consumers to await init)
|
|
@@ -435,12 +436,7 @@
|
|
|
435
436
|
sessionData.utm_id = persistentData.utm_id;
|
|
436
437
|
}
|
|
437
438
|
|
|
438
|
-
|
|
439
|
-
wallet_address: sessionData.wallet_address,
|
|
440
|
-
is_web3_user: sessionData.is_web3_user,
|
|
441
|
-
referrer: sessionData.referrer,
|
|
442
|
-
utm_source: sessionData.utm_source
|
|
443
|
-
});
|
|
439
|
+
// Session-specific persistent data restored successfully (wallet, web3 status, referrer, UTM source)
|
|
444
440
|
|
|
445
441
|
} catch (err) {
|
|
446
442
|
console.warn('Failed to restore session-specific persistent data:', err);
|
|
@@ -464,11 +460,9 @@
|
|
|
464
460
|
if (currentSessionId) {
|
|
465
461
|
const sessionKey = `${CONFIG.STORAGE_KEYS.PERSISTENT_DATA}_${currentSessionId}`;
|
|
466
462
|
localStorage.removeItem(sessionKey);
|
|
467
|
-
console.log(`✅ Cleared session-specific persistent data for session ${currentSessionId}`);
|
|
468
463
|
} else {
|
|
469
464
|
// Fallback: clear old global persistent data if session ID not available
|
|
470
465
|
localStorage.removeItem(CONFIG.STORAGE_KEYS.PERSISTENT_DATA);
|
|
471
|
-
console.log('✅ Cleared global persistent data from localStorage');
|
|
472
466
|
}
|
|
473
467
|
} catch (err) {
|
|
474
468
|
console.warn('Failed to clear persistent data:', err);
|
|
@@ -499,8 +493,6 @@
|
|
|
499
493
|
keysToRemove.forEach(key => {
|
|
500
494
|
localStorage.removeItem(key);
|
|
501
495
|
});
|
|
502
|
-
|
|
503
|
-
console.log(`✅ Cleared all persistent data (${keysToRemove.length} keys removed)`);
|
|
504
496
|
} catch (err) {
|
|
505
497
|
console.warn('Failed to clear all persistent data:', err);
|
|
506
498
|
}
|
|
@@ -807,7 +799,6 @@
|
|
|
807
799
|
_cachedDistinctId = distinctId;
|
|
808
800
|
|
|
809
801
|
const type = distinctId.startsWith('anon_') ? 'anonymous' : 'identified';
|
|
810
|
-
console.log(`✅ [Storage] Stored ${type} distinct_id in localStorage and sessionStorage: ${distinctId}`);
|
|
811
802
|
} catch (err) {
|
|
812
803
|
console.warn('Failed to set distinct_id:', err);
|
|
813
804
|
}
|
|
@@ -2323,7 +2314,6 @@
|
|
|
2323
2314
|
}
|
|
2324
2315
|
} catch (error) {
|
|
2325
2316
|
// API may not be available or user denied permission
|
|
2326
|
-
console.debug('User-Agent Client Hints API not available:', error);
|
|
2327
2317
|
}
|
|
2328
2318
|
} else {
|
|
2329
2319
|
// Fallback: parse from user agent string
|
|
@@ -2551,16 +2541,10 @@
|
|
|
2551
2541
|
// Current address is valid - only update to another valid address
|
|
2552
2542
|
if (newIsValid) {
|
|
2553
2543
|
sessionData.wallet_address = newAddress;
|
|
2554
|
-
console.log(`🔄 Wallet address updated: ${currentAddress} → ${newAddress}`);
|
|
2555
|
-
} else {
|
|
2556
|
-
console.log(`🔒 Wallet address protected: keeping ${currentAddress} (cannot set to ${newAddress})`);
|
|
2557
2544
|
}
|
|
2558
2545
|
} else {
|
|
2559
2546
|
// Current address is not valid - can set to any value
|
|
2560
2547
|
sessionData.wallet_address = newAddress;
|
|
2561
|
-
if (newIsValid) {
|
|
2562
|
-
console.log(`✅ Wallet address set: ${newAddress}`);
|
|
2563
|
-
}
|
|
2564
2548
|
}
|
|
2565
2549
|
},
|
|
2566
2550
|
|
|
@@ -2859,8 +2843,6 @@
|
|
|
2859
2843
|
// Invalid wallet type - only set if wallet_type is not already set to a valid value
|
|
2860
2844
|
if (!sessionData.wallet_type || sessionData.wallet_type === "No Wallet Detected") {
|
|
2861
2845
|
sessionData.wallet_type = walletType;
|
|
2862
|
-
} else {
|
|
2863
|
-
console.log(`🔒 Wallet type protected: keeping ${sessionData.wallet_type} (cannot set to ${walletType})`);
|
|
2864
2846
|
}
|
|
2865
2847
|
}
|
|
2866
2848
|
// Update chain_name with immutability protection
|
|
@@ -2872,8 +2854,6 @@
|
|
|
2872
2854
|
// Invalid chain name - only set if chain_name is not already set to a valid value
|
|
2873
2855
|
if (!sessionData.chain_name || sessionData.chain_name === "Not Connected") {
|
|
2874
2856
|
sessionData.chain_name = chainName;
|
|
2875
|
-
} else {
|
|
2876
|
-
console.log(`🔒 Chain name protected: keeping ${sessionData.chain_name} (cannot set to ${chainName})`);
|
|
2877
2857
|
}
|
|
2878
2858
|
}
|
|
2879
2859
|
// Keep is_web3_user as true if it's already true or if we detect a wallet
|
|
@@ -2898,11 +2878,16 @@
|
|
|
2898
2878
|
console.error('Error updating UTM event with wallet:', error);
|
|
2899
2879
|
});
|
|
2900
2880
|
|
|
2901
|
-
// Automatic wallet address matching -
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2881
|
+
// Automatic wallet address matching - only call once per address per session
|
|
2882
|
+
// Prevents repeated calls to /api/sdk/wallet-address on every interval tick
|
|
2883
|
+
if (walletAddress !== runtimeState.reportedWalletAddress) {
|
|
2884
|
+
runtimeState.reportedWalletAddress = walletAddress;
|
|
2885
|
+
IdentityManager.walletAddress(walletAddress).catch((error) => {
|
|
2886
|
+
console.warn('Error in automatic wallet address matching:', error);
|
|
2887
|
+
// Reset so it retries next time wallet info is updated
|
|
2888
|
+
runtimeState.reportedWalletAddress = null;
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2906
2891
|
}
|
|
2907
2892
|
|
|
2908
2893
|
return {
|
|
@@ -3160,7 +3145,6 @@
|
|
|
3160
3145
|
} else {
|
|
3161
3146
|
// Wallet disconnected - but protect wallet_address, chain_name, and wallet_type from becoming null/placeholder
|
|
3162
3147
|
// Keep the last known values for session consistency
|
|
3163
|
-
console.log('🔒 Wallet disconnected but keeping wallet data for session consistency');
|
|
3164
3148
|
sessionData.wallet_connected = false;
|
|
3165
3149
|
// Do NOT set wallet_address, chain_name, or wallet_type to null/placeholder - keep them for session attribution
|
|
3166
3150
|
// The updateWalletInfo() method already has immutability protection, so we don't need to call it here
|
|
@@ -5338,12 +5322,18 @@
|
|
|
5338
5322
|
*/
|
|
5339
5323
|
startNetworkTracking() {
|
|
5340
5324
|
try {
|
|
5341
|
-
// Track fetch errors
|
|
5325
|
+
// Track fetch errors - only intercept calls to our own backend
|
|
5342
5326
|
const originalFetch = window.fetch;
|
|
5343
5327
|
window.fetch = function(...args) {
|
|
5344
5328
|
const startTime = Date.now();
|
|
5345
|
-
const url = args[0];
|
|
5346
|
-
|
|
5329
|
+
const url = typeof args[0] === 'string' ? args[0] : (args[0]?.url || '');
|
|
5330
|
+
|
|
5331
|
+
// Pass third-party requests through completely untouched — no interception,
|
|
5332
|
+
// no involvement of our SDK in their call stack or error handling
|
|
5333
|
+
if (!url.includes('backend.cryptique.io')) {
|
|
5334
|
+
return originalFetch.apply(this, args);
|
|
5335
|
+
}
|
|
5336
|
+
|
|
5347
5337
|
return originalFetch.apply(this, args).then(response => {
|
|
5348
5338
|
// Only track error status codes (4xx, 5xx)
|
|
5349
5339
|
if (response.status >= 400) {
|
|
@@ -5378,7 +5368,7 @@
|
|
|
5378
5368
|
});
|
|
5379
5369
|
};
|
|
5380
5370
|
|
|
5381
|
-
// Track XMLHttpRequest errors
|
|
5371
|
+
// Track XMLHttpRequest errors - only intercept calls to our own backend
|
|
5382
5372
|
const originalXHROpen = XMLHttpRequest.prototype.open;
|
|
5383
5373
|
const originalXHRSend = XMLHttpRequest.prototype.send;
|
|
5384
5374
|
|
|
@@ -5391,6 +5381,11 @@
|
|
|
5391
5381
|
XMLHttpRequest.prototype.send = function(...args) {
|
|
5392
5382
|
const startTime = Date.now();
|
|
5393
5383
|
const xhr = this;
|
|
5384
|
+
|
|
5385
|
+
// Pass third-party XHR requests through completely untouched
|
|
5386
|
+
if (!xhr._cryptiqueUrl || !xhr._cryptiqueUrl.includes('backend.cryptique.io')) {
|
|
5387
|
+
return originalXHRSend.apply(this, args);
|
|
5388
|
+
}
|
|
5394
5389
|
|
|
5395
5390
|
xhr.addEventListener('load', function() {
|
|
5396
5391
|
if (xhr.status >= 400) {
|
|
@@ -5649,13 +5644,6 @@
|
|
|
5649
5644
|
try {
|
|
5650
5645
|
// Update session duration
|
|
5651
5646
|
DurationManager.updateSessionDuration();
|
|
5652
|
-
|
|
5653
|
-
// Update wallet info (non-blocking)
|
|
5654
|
-
try {
|
|
5655
|
-
await WalletManager.updateWalletInfo();
|
|
5656
|
-
} catch (walletError) {
|
|
5657
|
-
console.warn('Error updating wallet info:', walletError);
|
|
5658
|
-
}
|
|
5659
5647
|
|
|
5660
5648
|
// Update session activity
|
|
5661
5649
|
StorageManager.updateSessionActivity();
|
|
@@ -5716,15 +5704,9 @@
|
|
|
5716
5704
|
// Save session to storage
|
|
5717
5705
|
StorageManager.saveSession(sessionData);
|
|
5718
5706
|
|
|
5719
|
-
// Always sync distinctId from storage before
|
|
5707
|
+
// Always sync distinctId from storage before sending to ensure consistency
|
|
5720
5708
|
sessionData.distinctId = StorageManager.getDistinctId();
|
|
5721
5709
|
|
|
5722
|
-
// Console log raw session data intermittently
|
|
5723
|
-
console.log('📊 [Session] Raw Session Data:', {
|
|
5724
|
-
sessionData: sessionData,
|
|
5725
|
-
storedSession: storedSession
|
|
5726
|
-
});
|
|
5727
|
-
|
|
5728
5710
|
// Send session data
|
|
5729
5711
|
await APIClient.sendSessionData();
|
|
5730
5712
|
} catch (error) {
|
|
@@ -6445,8 +6427,6 @@
|
|
|
6445
6427
|
session.identified = true;
|
|
6446
6428
|
StorageManager.saveSession(session);
|
|
6447
6429
|
}
|
|
6448
|
-
|
|
6449
|
-
console.log(`✅ [Identity] Distinct ID updated: ${currentDistinctId} → ${result.distinctId}`);
|
|
6450
6430
|
} else if (result.merged && result.newDistinctId) {
|
|
6451
6431
|
// Fallback: use newDistinctId if distinctId not present
|
|
6452
6432
|
StorageManager.setDistinctId(result.newDistinctId);
|
|
@@ -6466,8 +6446,6 @@
|
|
|
6466
6446
|
session.identified = true;
|
|
6467
6447
|
StorageManager.saveSession(session);
|
|
6468
6448
|
}
|
|
6469
|
-
|
|
6470
|
-
console.log(`✅ [Identity] Distinct ID merged: ${currentDistinctId} → ${result.newDistinctId}`);
|
|
6471
6449
|
} else {
|
|
6472
6450
|
console.warn('⚠️ [Identity] No distinctId or newDistinctId in response:', result);
|
|
6473
6451
|
}
|
|
@@ -6566,8 +6544,6 @@
|
|
|
6566
6544
|
// Ignore errors
|
|
6567
6545
|
}
|
|
6568
6546
|
|
|
6569
|
-
console.log(`🔄 [Identity] Reset to anonymous: ${newDistinctId}`);
|
|
6570
|
-
|
|
6571
6547
|
return { success: true, distinctId: newDistinctId };
|
|
6572
6548
|
} catch (error) {
|
|
6573
6549
|
console.error('❌ [Identity] Error in reset():', error);
|
|
@@ -6623,8 +6599,6 @@
|
|
|
6623
6599
|
StorageManager.updateBackup({ id: sessionData.sessionId, userId: sessionData.userId });
|
|
6624
6600
|
// That's it - session sync will pick it up automatically, just like automatic detection
|
|
6625
6601
|
|
|
6626
|
-
console.log(`✅ [Identity] Wallet address set in sessionData: ${trimmedWalletAddress}`);
|
|
6627
|
-
|
|
6628
6602
|
// Get current distinct_id
|
|
6629
6603
|
const currentDistinctId = StorageManager.getDistinctId();
|
|
6630
6604
|
|
|
@@ -6671,12 +6645,8 @@
|
|
|
6671
6645
|
|
|
6672
6646
|
// Update userSession
|
|
6673
6647
|
userSession.userId = result.newUserId;
|
|
6674
|
-
|
|
6675
|
-
console.log(`✅ [Identity] User merged via wallet: ${currentUserId} → ${result.newUserId}`);
|
|
6676
6648
|
}
|
|
6677
6649
|
|
|
6678
|
-
console.log(`✅ [Identity] Wallet address set: ${trimmedWalletAddress}`);
|
|
6679
|
-
|
|
6680
6650
|
return result;
|
|
6681
6651
|
} catch (error) {
|
|
6682
6652
|
console.error('❌ [Identity] Error in walletAddress():', error);
|
|
@@ -7389,7 +7359,6 @@
|
|
|
7389
7359
|
return { success: false, error: result.message || 'Set failed' };
|
|
7390
7360
|
}
|
|
7391
7361
|
|
|
7392
|
-
console.log('✅ [People] Properties set successfully');
|
|
7393
7362
|
return result;
|
|
7394
7363
|
|
|
7395
7364
|
} catch (error) {
|
|
@@ -7439,7 +7408,6 @@
|
|
|
7439
7408
|
return { success: false, error: result.message || 'SetOnce failed' };
|
|
7440
7409
|
}
|
|
7441
7410
|
|
|
7442
|
-
console.log('✅ [People] Properties set once successfully');
|
|
7443
7411
|
return result;
|
|
7444
7412
|
|
|
7445
7413
|
} catch (error) {
|
|
@@ -7489,7 +7457,6 @@
|
|
|
7489
7457
|
return { success: false, error: result.message || 'Unset failed' };
|
|
7490
7458
|
}
|
|
7491
7459
|
|
|
7492
|
-
console.log('✅ [People] Properties unset successfully');
|
|
7493
7460
|
return result;
|
|
7494
7461
|
|
|
7495
7462
|
} catch (error) {
|
|
@@ -7546,7 +7513,6 @@
|
|
|
7546
7513
|
return { success: false, error: result.message || 'Increment failed' };
|
|
7547
7514
|
}
|
|
7548
7515
|
|
|
7549
|
-
console.log('✅ [People] Property incremented successfully');
|
|
7550
7516
|
return result;
|
|
7551
7517
|
|
|
7552
7518
|
} catch (error) {
|
|
@@ -7603,7 +7569,6 @@
|
|
|
7603
7569
|
return { success: false, error: result.message || 'Append failed' };
|
|
7604
7570
|
}
|
|
7605
7571
|
|
|
7606
|
-
console.log('✅ [People] Values appended successfully');
|
|
7607
7572
|
return result;
|
|
7608
7573
|
|
|
7609
7574
|
} catch (error) {
|
|
@@ -7660,7 +7625,6 @@
|
|
|
7660
7625
|
return { success: false, error: result.message || 'Union failed' };
|
|
7661
7626
|
}
|
|
7662
7627
|
|
|
7663
|
-
console.log('✅ [People] Values unioned successfully');
|
|
7664
7628
|
return result;
|
|
7665
7629
|
|
|
7666
7630
|
} catch (error) {
|
|
@@ -7717,7 +7681,6 @@
|
|
|
7717
7681
|
return { success: false, error: result.message || 'Remove failed' };
|
|
7718
7682
|
}
|
|
7719
7683
|
|
|
7720
|
-
console.log('✅ [People] Values removed successfully');
|
|
7721
7684
|
return result;
|
|
7722
7685
|
|
|
7723
7686
|
} catch (error) {
|
|
@@ -7769,7 +7732,6 @@
|
|
|
7769
7732
|
return { success: false, error: result.message || 'TrackCharge failed' };
|
|
7770
7733
|
}
|
|
7771
7734
|
|
|
7772
|
-
console.log('✅ [People] Charge tracked successfully');
|
|
7773
7735
|
return result;
|
|
7774
7736
|
|
|
7775
7737
|
} catch (error) {
|
|
@@ -7812,7 +7774,6 @@
|
|
|
7812
7774
|
return { success: false, error: result.message || 'ClearCharges failed' };
|
|
7813
7775
|
}
|
|
7814
7776
|
|
|
7815
|
-
console.log('✅ [People] Charges cleared successfully');
|
|
7816
7777
|
return result;
|
|
7817
7778
|
|
|
7818
7779
|
} catch (error) {
|
|
@@ -7855,8 +7816,6 @@
|
|
|
7855
7816
|
return { success: false, error: result.message || 'DeleteUser failed' };
|
|
7856
7817
|
}
|
|
7857
7818
|
|
|
7858
|
-
console.log('✅ [People] User deleted successfully');
|
|
7859
|
-
|
|
7860
7819
|
// Clear local storage after successful deletion
|
|
7861
7820
|
StorageManager.clearSession();
|
|
7862
7821
|
StorageManager.clearUserId();
|
package/package.json
CHANGED