@usero/sdk 1.1.11 → 1.1.13

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/vanilla.cjs CHANGED
@@ -229,10 +229,13 @@ function rotateAnonymousId() {
229
229
  currentUserId = null;
230
230
  return id;
231
231
  }
232
+ function isValidSdkSessionId(id) {
233
+ return /^[a-z0-9-]{8,}$/i.test(id);
234
+ }
232
235
  function getOrMintSdkSessionId() {
233
236
  if (cachedSdkSessionId) return cachedSdkSessionId;
234
237
  const existing = safeReadSessionStorage(SDK_SESSION_STORAGE_KEY);
235
- if (existing && /^[a-z0-9-]{8,}$/i.test(existing)) {
238
+ if (existing && isValidSdkSessionId(existing)) {
236
239
  cachedSdkSessionId = existing;
237
240
  return existing;
238
241
  }
@@ -241,6 +244,12 @@ function getOrMintSdkSessionId() {
241
244
  cachedSdkSessionId = id;
242
245
  return id;
243
246
  }
247
+ function reseatSdkSessionId(id) {
248
+ if (!isValidSdkSessionId(id)) return;
249
+ if (cachedSdkSessionId === id) return;
250
+ cachedSdkSessionId = id;
251
+ safeWriteSessionStorage(SDK_SESSION_STORAGE_KEY, id);
252
+ }
244
253
  function getCurrentUserId() {
245
254
  return currentUserId;
246
255
  }
@@ -303,6 +312,19 @@ async function identifyIfChanged(transport, user) {
303
312
  function handleLogout() {
304
313
  rotateAnonymousId();
305
314
  }
315
+ var __test__ = {
316
+ ANON_STORAGE_KEY,
317
+ SDK_SESSION_STORAGE_KEY,
318
+ reseatSdkSessionId,
319
+ getOrMintSdkSessionId,
320
+ resetIdentityState: () => {
321
+ cachedAnonymousId = null;
322
+ cachedSdkSessionId = null;
323
+ currentUserId = null;
324
+ replayStartMs = null;
325
+ lastIdentifyFingerprint = null;
326
+ }
327
+ };
306
328
 
307
329
  // src/plugin.ts
308
330
  function createPluginLogger(name) {
@@ -777,6 +799,7 @@ var FEEDBACK_CSS = `
777
799
  `;
778
800
 
779
801
  // src/vanilla.ts
802
+ var __identityTest__ = __test__;
780
803
  function resolveBaseTheme() {
781
804
  if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
782
805
  return DARK_THEME;
@@ -952,6 +975,7 @@ function initUseroFeedbackWidget(props) {
952
975
  // source of truth in identity.ts, so user-test and session-replay
953
976
  // agree on the per-tab sdkSessionId without importing each other.
954
977
  getSdkSessionId: () => getOrMintSdkSessionId(),
978
+ reseatSdkSessionId: (id) => reseatSdkSessionId(id),
955
979
  getAnonymousId: () => getOrMintAnonymousId(),
956
980
  getUserId: () => getCurrentUserId(),
957
981
  getReplayStartMs: () => getReplayStartMs(),
@@ -1482,6 +1506,7 @@ function initUseroFeedbackWidget(props) {
1482
1506
 
1483
1507
  exports.DARK_THEME = DARK_THEME;
1484
1508
  exports.DEFAULT_THEME = DEFAULT_THEME;
1509
+ exports.__identityTest__ = __identityTest__;
1485
1510
  exports.initUseroFeedbackWidget = initUseroFeedbackWidget;
1486
1511
  exports.mergePluginPatches = mergePluginPatches;
1487
1512
  exports.mergeTheme = mergeTheme;