@reopt-ai/data-sdk-client 0.1.1 → 0.1.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.
- package/README.md +1 -1
- package/dist/{chunk-47EC5ATF.js → chunk-JNIOYR44.js} +2 -2
- package/dist/{chunk-BIR7OFR3.js → chunk-SRHWNG2G.js} +35 -23
- package/dist/chunk-SRHWNG2G.js.map +1 -0
- package/dist/{client-g75DV57n.d.ts → client-B6gFgjju.d.ts} +1 -0
- package/dist/index.cjs +29 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/next.cjs +29 -21
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/next.js +2 -2
- package/dist/react.cjs +29 -21
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +2 -2
- package/package.json +4 -4
- package/dist/chunk-BIR7OFR3.js.map +0 -1
- /package/dist/{chunk-47EC5ATF.js.map → chunk-JNIOYR44.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -822,10 +822,13 @@ function readIngestCounts(rawBody) {
|
|
|
822
822
|
if (!record || record.status !== "ok" && record.status !== "accepted" || !count(record.accepted) || !count(record.duplicates) || !Array.isArray(record.rejected)) {
|
|
823
823
|
throw new TransportError("Track response did not match contract: unexpected shape", 409, true);
|
|
824
824
|
}
|
|
825
|
+
const session = record.session;
|
|
826
|
+
const credential = session && typeof session.id === "string" && typeof session.token === "string" ? { id: session.id, token: session.token } : void 0;
|
|
825
827
|
return {
|
|
826
828
|
accepted: record.accepted,
|
|
827
829
|
duplicates: record.duplicates,
|
|
828
|
-
rejected: record.rejected.length
|
|
830
|
+
rejected: record.rejected.length,
|
|
831
|
+
...credential ? { session: credential } : {}
|
|
829
832
|
};
|
|
830
833
|
}
|
|
831
834
|
function resolveBaseUrl(value) {
|
|
@@ -883,7 +886,11 @@ function createTransport(options) {
|
|
|
883
886
|
if (counts.accepted + counts.duplicates + counts.rejected !== batch.length) {
|
|
884
887
|
throw new TransportError("Track response counts do not reconcile with the submitted batch", 409, true);
|
|
885
888
|
}
|
|
886
|
-
return {
|
|
889
|
+
return {
|
|
890
|
+
sent: counts.accepted + counts.duplicates,
|
|
891
|
+
failed: counts.rejected,
|
|
892
|
+
...counts.session ? { session: counts.session } : {}
|
|
893
|
+
};
|
|
887
894
|
};
|
|
888
895
|
return { url, headers, send };
|
|
889
896
|
}
|
|
@@ -1193,6 +1200,9 @@ var ReoptCore = class {
|
|
|
1193
1200
|
onRetry: (attempt, waitMs) => this.log("retry", attempt, Math.round(waitMs))
|
|
1194
1201
|
});
|
|
1195
1202
|
this.log("flushed", delivery.sent, delivery.failed);
|
|
1203
|
+
if (delivery.session && !batch[0]?.identity) {
|
|
1204
|
+
this.runtime.onSession?.(delivery.session);
|
|
1205
|
+
}
|
|
1196
1206
|
if (this.breaker.getState() === "half-open") this.log("breaker closed");
|
|
1197
1207
|
this.breaker.recordSuccess();
|
|
1198
1208
|
this.queue.settle();
|
|
@@ -1436,13 +1446,14 @@ function cookiesAvailable() {
|
|
|
1436
1446
|
|
|
1437
1447
|
// src/identity/device.ts
|
|
1438
1448
|
var LEGACY_DEVICE_KEY = "device_id";
|
|
1439
|
-
function
|
|
1449
|
+
function localStorageBackend() {
|
|
1440
1450
|
try {
|
|
1441
1451
|
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1452
|
+
const storage = window.localStorage;
|
|
1442
1453
|
const probe = "reopt_probe";
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
return
|
|
1454
|
+
storage.setItem(probe, "1");
|
|
1455
|
+
storage.removeItem(probe);
|
|
1456
|
+
return storage;
|
|
1446
1457
|
} catch {
|
|
1447
1458
|
return null;
|
|
1448
1459
|
}
|
|
@@ -1481,7 +1492,7 @@ function createIdentityStore(writeKey, config) {
|
|
|
1481
1492
|
if (kind === "cookie" || kind === "auto" && cookiesAvailable()) {
|
|
1482
1493
|
return makeStore("cookie", writeKey, cookieBackend(cookie));
|
|
1483
1494
|
}
|
|
1484
|
-
const local = kind === "memory" ? null :
|
|
1495
|
+
const local = kind === "memory" ? null : localStorageBackend();
|
|
1485
1496
|
if (local) return makeStore("localStorage", writeKey, local);
|
|
1486
1497
|
return makeStore("memory", writeKey, memoryStorage());
|
|
1487
1498
|
}
|
|
@@ -1492,7 +1503,7 @@ function resolveDeviceId(store, bootstrapDeviceId, storagePrefix) {
|
|
|
1492
1503
|
store.writeDevice({ deviceId: bootstrapDeviceId });
|
|
1493
1504
|
return { deviceId: bootstrapDeviceId, source: "bootstrap" };
|
|
1494
1505
|
}
|
|
1495
|
-
const local =
|
|
1506
|
+
const local = localStorageBackend();
|
|
1496
1507
|
const legacy = local?.getItem(`${storagePrefix}${LEGACY_DEVICE_KEY}`);
|
|
1497
1508
|
if ((0, import_identity3.isValidIdentityId)(legacy)) {
|
|
1498
1509
|
store.writeDevice({ deviceId: legacy });
|
|
@@ -1512,19 +1523,6 @@ function regenerateDeviceId(store) {
|
|
|
1512
1523
|
// src/client.ts
|
|
1513
1524
|
var CLOCK_SKEW_THRESHOLD_MS = 3e4;
|
|
1514
1525
|
var MAX_CLOCK_SKEW_MS = 24 * 60 * 60 * 1e3;
|
|
1515
|
-
function localStorageBackend() {
|
|
1516
|
-
try {
|
|
1517
|
-
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1518
|
-
const storage = window.localStorage;
|
|
1519
|
-
return {
|
|
1520
|
-
getItem: (key) => storage.getItem(key),
|
|
1521
|
-
setItem: (key, value) => storage.setItem(key, value),
|
|
1522
|
-
removeItem: (key) => storage.removeItem(key)
|
|
1523
|
-
};
|
|
1524
|
-
} catch {
|
|
1525
|
-
return null;
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
1526
|
function routedStorage(consentKey, consent, rest) {
|
|
1529
1527
|
const pick = (key) => key === consentKey ? consent : rest;
|
|
1530
1528
|
return {
|
|
@@ -1565,6 +1563,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1565
1563
|
scroll;
|
|
1566
1564
|
uninstallers = [];
|
|
1567
1565
|
torndown = false;
|
|
1566
|
+
session;
|
|
1568
1567
|
normalize;
|
|
1569
1568
|
/** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
|
|
1570
1569
|
disabled;
|
|
@@ -1581,8 +1580,15 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1581
1580
|
const queueStorage = disabled ? memoryStorage() : config.queueStorage ?? localStorageBackend() ?? memoryStorage();
|
|
1582
1581
|
const transportFetch = config.fetch ?? (typeof window !== "undefined" ? window.fetch.bind(window) : void 0);
|
|
1583
1582
|
const box = {};
|
|
1583
|
+
const session = { header: store.readDevice()?.sessionId ?? null };
|
|
1584
1584
|
const runtime = {
|
|
1585
1585
|
deviceId: identity.deviceId,
|
|
1586
|
+
getSessionId: () => (0, import_identity5.parseSessionHeader)(session.header) ? session.header : null,
|
|
1587
|
+
onSession: (credential) => {
|
|
1588
|
+
session.header = (0, import_identity5.formatSessionHeader)(credential);
|
|
1589
|
+
const current2 = store.readDevice();
|
|
1590
|
+
store.writeDevice({ ...current2, deviceId: current2?.deviceId ?? identity.deviceId, sessionId: session.header });
|
|
1591
|
+
},
|
|
1586
1592
|
storage: routedStorage(`${storagePrefix}consent`, store.consentBackend(), queueStorage),
|
|
1587
1593
|
now,
|
|
1588
1594
|
fetch: transportFetch,
|
|
@@ -1620,6 +1626,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1620
1626
|
});
|
|
1621
1627
|
this.writeKey = config.writeKey;
|
|
1622
1628
|
this.disabled = disabled;
|
|
1629
|
+
this.session = session;
|
|
1623
1630
|
this.normalize = config.normalizePath;
|
|
1624
1631
|
this.store = store;
|
|
1625
1632
|
this.capture = resolveCapture(config.capture, defaults.pageview);
|
|
@@ -1715,6 +1722,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1715
1722
|
*/
|
|
1716
1723
|
reset() {
|
|
1717
1724
|
super.reset();
|
|
1725
|
+
this.session.header = null;
|
|
1718
1726
|
this.store.writeDevice({ deviceId: this.getDeviceId() });
|
|
1719
1727
|
}
|
|
1720
1728
|
async close() {
|