@reopt-ai/data-sdk-client 0.1.0 → 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 -3
- package/dist/chunk-BIR7OFR3.js.map +0 -1
- /package/dist/{chunk-47EC5ATF.js.map → chunk-JNIOYR44.js.map} +0 -0
package/dist/next.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
export { R as ReoptClient, a as ReoptClientConfig, W as WebVitalMetric } from './client-
|
|
2
|
+
export { R as ReoptClient, a as ReoptClientConfig, W as WebVitalMetric } from './client-B6gFgjju.js';
|
|
3
3
|
import { ReoptProviderProps } from './react.js';
|
|
4
4
|
export { ReoptContextValue, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount } from './react.js';
|
|
5
5
|
export { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
|
package/dist/next.js
CHANGED
package/dist/react.cjs
CHANGED
|
@@ -807,10 +807,13 @@ function readIngestCounts(rawBody) {
|
|
|
807
807
|
if (!record || record.status !== "ok" && record.status !== "accepted" || !count(record.accepted) || !count(record.duplicates) || !Array.isArray(record.rejected)) {
|
|
808
808
|
throw new TransportError("Track response did not match contract: unexpected shape", 409, true);
|
|
809
809
|
}
|
|
810
|
+
const session = record.session;
|
|
811
|
+
const credential = session && typeof session.id === "string" && typeof session.token === "string" ? { id: session.id, token: session.token } : void 0;
|
|
810
812
|
return {
|
|
811
813
|
accepted: record.accepted,
|
|
812
814
|
duplicates: record.duplicates,
|
|
813
|
-
rejected: record.rejected.length
|
|
815
|
+
rejected: record.rejected.length,
|
|
816
|
+
...credential ? { session: credential } : {}
|
|
814
817
|
};
|
|
815
818
|
}
|
|
816
819
|
function resolveBaseUrl(value) {
|
|
@@ -868,7 +871,11 @@ function createTransport(options) {
|
|
|
868
871
|
if (counts.accepted + counts.duplicates + counts.rejected !== batch.length) {
|
|
869
872
|
throw new TransportError("Track response counts do not reconcile with the submitted batch", 409, true);
|
|
870
873
|
}
|
|
871
|
-
return {
|
|
874
|
+
return {
|
|
875
|
+
sent: counts.accepted + counts.duplicates,
|
|
876
|
+
failed: counts.rejected,
|
|
877
|
+
...counts.session ? { session: counts.session } : {}
|
|
878
|
+
};
|
|
872
879
|
};
|
|
873
880
|
return { url, headers, send };
|
|
874
881
|
}
|
|
@@ -1178,6 +1185,9 @@ var ReoptCore = class {
|
|
|
1178
1185
|
onRetry: (attempt, waitMs) => this.log("retry", attempt, Math.round(waitMs))
|
|
1179
1186
|
});
|
|
1180
1187
|
this.log("flushed", delivery.sent, delivery.failed);
|
|
1188
|
+
if (delivery.session && !batch[0]?.identity) {
|
|
1189
|
+
this.runtime.onSession?.(delivery.session);
|
|
1190
|
+
}
|
|
1181
1191
|
if (this.breaker.getState() === "half-open") this.log("breaker closed");
|
|
1182
1192
|
this.breaker.recordSuccess();
|
|
1183
1193
|
this.queue.settle();
|
|
@@ -1421,13 +1431,14 @@ function cookiesAvailable() {
|
|
|
1421
1431
|
|
|
1422
1432
|
// src/identity/device.ts
|
|
1423
1433
|
var LEGACY_DEVICE_KEY = "device_id";
|
|
1424
|
-
function
|
|
1434
|
+
function localStorageBackend() {
|
|
1425
1435
|
try {
|
|
1426
1436
|
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1437
|
+
const storage = window.localStorage;
|
|
1427
1438
|
const probe = "reopt_probe";
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
return
|
|
1439
|
+
storage.setItem(probe, "1");
|
|
1440
|
+
storage.removeItem(probe);
|
|
1441
|
+
return storage;
|
|
1431
1442
|
} catch {
|
|
1432
1443
|
return null;
|
|
1433
1444
|
}
|
|
@@ -1466,7 +1477,7 @@ function createIdentityStore(writeKey, config) {
|
|
|
1466
1477
|
if (kind === "cookie" || kind === "auto" && cookiesAvailable()) {
|
|
1467
1478
|
return makeStore("cookie", writeKey, cookieBackend(cookie));
|
|
1468
1479
|
}
|
|
1469
|
-
const local = kind === "memory" ? null :
|
|
1480
|
+
const local = kind === "memory" ? null : localStorageBackend();
|
|
1470
1481
|
if (local) return makeStore("localStorage", writeKey, local);
|
|
1471
1482
|
return makeStore("memory", writeKey, memoryStorage());
|
|
1472
1483
|
}
|
|
@@ -1477,7 +1488,7 @@ function resolveDeviceId(store, bootstrapDeviceId, storagePrefix) {
|
|
|
1477
1488
|
store.writeDevice({ deviceId: bootstrapDeviceId });
|
|
1478
1489
|
return { deviceId: bootstrapDeviceId, source: "bootstrap" };
|
|
1479
1490
|
}
|
|
1480
|
-
const local =
|
|
1491
|
+
const local = localStorageBackend();
|
|
1481
1492
|
const legacy = local?.getItem(`${storagePrefix}${LEGACY_DEVICE_KEY}`);
|
|
1482
1493
|
if ((0, import_identity3.isValidIdentityId)(legacy)) {
|
|
1483
1494
|
store.writeDevice({ deviceId: legacy });
|
|
@@ -1497,19 +1508,6 @@ function regenerateDeviceId(store) {
|
|
|
1497
1508
|
// src/client.ts
|
|
1498
1509
|
var CLOCK_SKEW_THRESHOLD_MS = 3e4;
|
|
1499
1510
|
var MAX_CLOCK_SKEW_MS = 24 * 60 * 60 * 1e3;
|
|
1500
|
-
function localStorageBackend() {
|
|
1501
|
-
try {
|
|
1502
|
-
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1503
|
-
const storage = window.localStorage;
|
|
1504
|
-
return {
|
|
1505
|
-
getItem: (key) => storage.getItem(key),
|
|
1506
|
-
setItem: (key, value) => storage.setItem(key, value),
|
|
1507
|
-
removeItem: (key) => storage.removeItem(key)
|
|
1508
|
-
};
|
|
1509
|
-
} catch {
|
|
1510
|
-
return null;
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
1511
|
function routedStorage(consentKey, consent, rest) {
|
|
1514
1512
|
const pick = (key) => key === consentKey ? consent : rest;
|
|
1515
1513
|
return {
|
|
@@ -1550,6 +1548,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1550
1548
|
scroll;
|
|
1551
1549
|
uninstallers = [];
|
|
1552
1550
|
torndown = false;
|
|
1551
|
+
session;
|
|
1553
1552
|
normalize;
|
|
1554
1553
|
/** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
|
|
1555
1554
|
disabled;
|
|
@@ -1566,8 +1565,15 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1566
1565
|
const queueStorage = disabled ? memoryStorage() : config.queueStorage ?? localStorageBackend() ?? memoryStorage();
|
|
1567
1566
|
const transportFetch = config.fetch ?? (typeof window !== "undefined" ? window.fetch.bind(window) : void 0);
|
|
1568
1567
|
const box = {};
|
|
1568
|
+
const session = { header: store.readDevice()?.sessionId ?? null };
|
|
1569
1569
|
const runtime = {
|
|
1570
1570
|
deviceId: identity.deviceId,
|
|
1571
|
+
getSessionId: () => (0, import_identity5.parseSessionHeader)(session.header) ? session.header : null,
|
|
1572
|
+
onSession: (credential) => {
|
|
1573
|
+
session.header = (0, import_identity5.formatSessionHeader)(credential);
|
|
1574
|
+
const current = store.readDevice();
|
|
1575
|
+
store.writeDevice({ ...current, deviceId: current?.deviceId ?? identity.deviceId, sessionId: session.header });
|
|
1576
|
+
},
|
|
1571
1577
|
storage: routedStorage(`${storagePrefix}consent`, store.consentBackend(), queueStorage),
|
|
1572
1578
|
now,
|
|
1573
1579
|
fetch: transportFetch,
|
|
@@ -1605,6 +1611,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1605
1611
|
});
|
|
1606
1612
|
this.writeKey = config.writeKey;
|
|
1607
1613
|
this.disabled = disabled;
|
|
1614
|
+
this.session = session;
|
|
1608
1615
|
this.normalize = config.normalizePath;
|
|
1609
1616
|
this.store = store;
|
|
1610
1617
|
this.capture = resolveCapture(config.capture, defaults.pageview);
|
|
@@ -1700,6 +1707,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1700
1707
|
*/
|
|
1701
1708
|
reset() {
|
|
1702
1709
|
super.reset();
|
|
1710
|
+
this.session.header = null;
|
|
1703
1711
|
this.store.writeDevice({ deviceId: this.getDeviceId() });
|
|
1704
1712
|
}
|
|
1705
1713
|
async close() {
|