@xenia-martech/sdk-js 1.2.0-dev.1 → 1.2.0-dev.2

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.
@@ -911,9 +911,11 @@ declare class Identity {
911
911
  * a browser-entered journey. No-op when disabled or off-DOM.
912
912
  */
913
913
  private writeVisitorCookie;
914
+ /** The visitor id already in the cookie — e.g. minted by `xeniaProxy()` on the first request. */
915
+ private readVisitorCookie;
914
916
  /**
915
- * Resolve a stable device id: localStorage cache → MediaDevices → SHA-256
916
- * browser fingerprint. Cached for the session and across reloads.
917
+ * Resolve a stable device id: localStorage cache → the visitor cookie a server already set →
918
+ * MediaDevices → SHA-256 browser fingerprint. Cached for the session and across reloads.
917
919
  */
918
920
  resolveDeviceId(): Promise<string>;
919
921
  getDeviceId(): string | null;
@@ -911,9 +911,11 @@ declare class Identity {
911
911
  * a browser-entered journey. No-op when disabled or off-DOM.
912
912
  */
913
913
  private writeVisitorCookie;
914
+ /** The visitor id already in the cookie — e.g. minted by `xeniaProxy()` on the first request. */
915
+ private readVisitorCookie;
914
916
  /**
915
- * Resolve a stable device id: localStorage cache → MediaDevices → SHA-256
916
- * browser fingerprint. Cached for the session and across reloads.
917
+ * Resolve a stable device id: localStorage cache → the visitor cookie a server already set →
918
+ * MediaDevices → SHA-256 browser fingerprint. Cached for the session and across reloads.
917
919
  */
918
920
  resolveDeviceId(): Promise<string>;
919
921
  getDeviceId(): string | null;
@@ -1231,6 +1231,20 @@ var AutoTracker = class {
1231
1231
  }
1232
1232
  };
1233
1233
 
1234
+ // src/server/cookies.ts
1235
+ function parseCookies(header) {
1236
+ const out = {};
1237
+ if (!header) return out;
1238
+ for (const part of header.split(";")) {
1239
+ const idx = part.indexOf("=");
1240
+ if (idx === -1) continue;
1241
+ const key = part.slice(0, idx).trim();
1242
+ const value = part.slice(idx + 1).trim();
1243
+ if (key) out[key] = decodeURIComponent(value);
1244
+ }
1245
+ return out;
1246
+ }
1247
+
1234
1248
  // src/client/identity.ts
1235
1249
  var SESSION_TIMEOUT_MS = 30 * 60 * 1e3;
1236
1250
  var Identity = class {
@@ -1278,10 +1292,19 @@ var Identity = class {
1278
1292
  } catch {
1279
1293
  }
1280
1294
  }
1295
+ /** The visitor id already in the cookie — e.g. minted by `xeniaProxy()` on the first request. */
1296
+ readVisitorCookie() {
1297
+ if (!this.cookie || typeof document === "undefined") return null;
1298
+ try {
1299
+ return parseCookies(document.cookie)[this.cookieName()] || null;
1300
+ } catch {
1301
+ return null;
1302
+ }
1303
+ }
1281
1304
  // ── Device id ────────────────────────────────────────────────────────────
1282
1305
  /**
1283
- * Resolve a stable device id: localStorage cache → MediaDevices → SHA-256
1284
- * browser fingerprint. Cached for the session and across reloads.
1306
+ * Resolve a stable device id: localStorage cache → the visitor cookie a server already set →
1307
+ * MediaDevices → SHA-256 browser fingerprint. Cached for the session and across reloads.
1285
1308
  */
1286
1309
  async resolveDeviceId() {
1287
1310
  if (this.deviceId) {
@@ -1298,7 +1321,8 @@ var Identity = class {
1298
1321
  }
1299
1322
  } catch {
1300
1323
  }
1301
- let id = await this.mediaDeviceId();
1324
+ let id = this.readVisitorCookie();
1325
+ if (!id) id = await this.mediaDeviceId();
1302
1326
  if (!id) id = await this.fingerprint();
1303
1327
  this.deviceId = id;
1304
1328
  try {