@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/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { UTMParams, QueueResult, FlushResult, DecrementOptions, ConsentCategory, IdentifyOptions, IncrementOptions, PageViewOptions, TrackEventOptions } from '@reopt-ai/data-sdk-core';
|
|
2
2
|
export { BatchConfig, CircuitBreakerConfig, ConsentCategory, ConsentConfig, DecrementOptions, EventPayload, FlushResult, IdentifyOptions, IncrementOptions, PageViewOptions, QueueDropReason, QueueResult, RetryConfig, StorageBackend, TrackEventOptions, UTMParams } from '@reopt-ai/data-sdk-core';
|
|
3
|
-
import { R as ReoptClient, a as ReoptClientConfig, b as ReoptClientDefaults, W as WebVitalMetric } from './client-
|
|
4
|
-
export { C as CaptureConfig, I as IdentityConfig, c as IdentityStorageKind, N as NormalizePath, d as WebVitalProperties } from './client-
|
|
3
|
+
import { R as ReoptClient, a as ReoptClientConfig, b as ReoptClientDefaults, W as WebVitalMetric } from './client-B6gFgjju.js';
|
|
4
|
+
export { C as CaptureConfig, I as IdentityConfig, c as IdentityStorageKind, N as NormalizePath, d as WebVitalProperties } from './client-B6gFgjju.js';
|
|
5
5
|
export { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/index.js
CHANGED
package/dist/next.cjs
CHANGED
|
@@ -814,10 +814,13 @@ function readIngestCounts(rawBody) {
|
|
|
814
814
|
if (!record || record.status !== "ok" && record.status !== "accepted" || !count(record.accepted) || !count(record.duplicates) || !Array.isArray(record.rejected)) {
|
|
815
815
|
throw new TransportError("Track response did not match contract: unexpected shape", 409, true);
|
|
816
816
|
}
|
|
817
|
+
const session = record.session;
|
|
818
|
+
const credential = session && typeof session.id === "string" && typeof session.token === "string" ? { id: session.id, token: session.token } : void 0;
|
|
817
819
|
return {
|
|
818
820
|
accepted: record.accepted,
|
|
819
821
|
duplicates: record.duplicates,
|
|
820
|
-
rejected: record.rejected.length
|
|
822
|
+
rejected: record.rejected.length,
|
|
823
|
+
...credential ? { session: credential } : {}
|
|
821
824
|
};
|
|
822
825
|
}
|
|
823
826
|
function resolveBaseUrl(value) {
|
|
@@ -875,7 +878,11 @@ function createTransport(options) {
|
|
|
875
878
|
if (counts.accepted + counts.duplicates + counts.rejected !== batch.length) {
|
|
876
879
|
throw new TransportError("Track response counts do not reconcile with the submitted batch", 409, true);
|
|
877
880
|
}
|
|
878
|
-
return {
|
|
881
|
+
return {
|
|
882
|
+
sent: counts.accepted + counts.duplicates,
|
|
883
|
+
failed: counts.rejected,
|
|
884
|
+
...counts.session ? { session: counts.session } : {}
|
|
885
|
+
};
|
|
879
886
|
};
|
|
880
887
|
return { url, headers, send };
|
|
881
888
|
}
|
|
@@ -1185,6 +1192,9 @@ var ReoptCore = class {
|
|
|
1185
1192
|
onRetry: (attempt, waitMs) => this.log("retry", attempt, Math.round(waitMs))
|
|
1186
1193
|
});
|
|
1187
1194
|
this.log("flushed", delivery.sent, delivery.failed);
|
|
1195
|
+
if (delivery.session && !batch[0]?.identity) {
|
|
1196
|
+
this.runtime.onSession?.(delivery.session);
|
|
1197
|
+
}
|
|
1188
1198
|
if (this.breaker.getState() === "half-open") this.log("breaker closed");
|
|
1189
1199
|
this.breaker.recordSuccess();
|
|
1190
1200
|
this.queue.settle();
|
|
@@ -1428,13 +1438,14 @@ function cookiesAvailable() {
|
|
|
1428
1438
|
|
|
1429
1439
|
// src/identity/device.ts
|
|
1430
1440
|
var LEGACY_DEVICE_KEY = "device_id";
|
|
1431
|
-
function
|
|
1441
|
+
function localStorageBackend() {
|
|
1432
1442
|
try {
|
|
1433
1443
|
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1444
|
+
const storage = window.localStorage;
|
|
1434
1445
|
const probe = "reopt_probe";
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
return
|
|
1446
|
+
storage.setItem(probe, "1");
|
|
1447
|
+
storage.removeItem(probe);
|
|
1448
|
+
return storage;
|
|
1438
1449
|
} catch {
|
|
1439
1450
|
return null;
|
|
1440
1451
|
}
|
|
@@ -1473,7 +1484,7 @@ function createIdentityStore(writeKey, config) {
|
|
|
1473
1484
|
if (kind === "cookie" || kind === "auto" && cookiesAvailable()) {
|
|
1474
1485
|
return makeStore("cookie", writeKey, cookieBackend(cookie));
|
|
1475
1486
|
}
|
|
1476
|
-
const local = kind === "memory" ? null :
|
|
1487
|
+
const local = kind === "memory" ? null : localStorageBackend();
|
|
1477
1488
|
if (local) return makeStore("localStorage", writeKey, local);
|
|
1478
1489
|
return makeStore("memory", writeKey, memoryStorage());
|
|
1479
1490
|
}
|
|
@@ -1484,7 +1495,7 @@ function resolveDeviceId(store, bootstrapDeviceId, storagePrefix) {
|
|
|
1484
1495
|
store.writeDevice({ deviceId: bootstrapDeviceId });
|
|
1485
1496
|
return { deviceId: bootstrapDeviceId, source: "bootstrap" };
|
|
1486
1497
|
}
|
|
1487
|
-
const local =
|
|
1498
|
+
const local = localStorageBackend();
|
|
1488
1499
|
const legacy = local?.getItem(`${storagePrefix}${LEGACY_DEVICE_KEY}`);
|
|
1489
1500
|
if ((0, import_identity3.isValidIdentityId)(legacy)) {
|
|
1490
1501
|
store.writeDevice({ deviceId: legacy });
|
|
@@ -1504,19 +1515,6 @@ function regenerateDeviceId(store) {
|
|
|
1504
1515
|
// src/client.ts
|
|
1505
1516
|
var CLOCK_SKEW_THRESHOLD_MS = 3e4;
|
|
1506
1517
|
var MAX_CLOCK_SKEW_MS = 24 * 60 * 60 * 1e3;
|
|
1507
|
-
function localStorageBackend() {
|
|
1508
|
-
try {
|
|
1509
|
-
if (typeof window === "undefined" || !window.localStorage) return null;
|
|
1510
|
-
const storage = window.localStorage;
|
|
1511
|
-
return {
|
|
1512
|
-
getItem: (key) => storage.getItem(key),
|
|
1513
|
-
setItem: (key, value) => storage.setItem(key, value),
|
|
1514
|
-
removeItem: (key) => storage.removeItem(key)
|
|
1515
|
-
};
|
|
1516
|
-
} catch {
|
|
1517
|
-
return null;
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
1518
|
function routedStorage(consentKey, consent, rest) {
|
|
1521
1519
|
const pick = (key) => key === consentKey ? consent : rest;
|
|
1522
1520
|
return {
|
|
@@ -1557,6 +1555,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1557
1555
|
scroll;
|
|
1558
1556
|
uninstallers = [];
|
|
1559
1557
|
torndown = false;
|
|
1558
|
+
session;
|
|
1560
1559
|
normalize;
|
|
1561
1560
|
/** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
|
|
1562
1561
|
disabled;
|
|
@@ -1573,8 +1572,15 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1573
1572
|
const queueStorage = disabled ? memoryStorage() : config.queueStorage ?? localStorageBackend() ?? memoryStorage();
|
|
1574
1573
|
const transportFetch = config.fetch ?? (typeof window !== "undefined" ? window.fetch.bind(window) : void 0);
|
|
1575
1574
|
const box = {};
|
|
1575
|
+
const session = { header: store.readDevice()?.sessionId ?? null };
|
|
1576
1576
|
const runtime = {
|
|
1577
1577
|
deviceId: identity.deviceId,
|
|
1578
|
+
getSessionId: () => (0, import_identity5.parseSessionHeader)(session.header) ? session.header : null,
|
|
1579
|
+
onSession: (credential) => {
|
|
1580
|
+
session.header = (0, import_identity5.formatSessionHeader)(credential);
|
|
1581
|
+
const current = store.readDevice();
|
|
1582
|
+
store.writeDevice({ ...current, deviceId: current?.deviceId ?? identity.deviceId, sessionId: session.header });
|
|
1583
|
+
},
|
|
1578
1584
|
storage: routedStorage(`${storagePrefix}consent`, store.consentBackend(), queueStorage),
|
|
1579
1585
|
now,
|
|
1580
1586
|
fetch: transportFetch,
|
|
@@ -1612,6 +1618,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1612
1618
|
});
|
|
1613
1619
|
this.writeKey = config.writeKey;
|
|
1614
1620
|
this.disabled = disabled;
|
|
1621
|
+
this.session = session;
|
|
1615
1622
|
this.normalize = config.normalizePath;
|
|
1616
1623
|
this.store = store;
|
|
1617
1624
|
this.capture = resolveCapture(config.capture, defaults.pageview);
|
|
@@ -1707,6 +1714,7 @@ var ReoptClient = class extends ReoptCore {
|
|
|
1707
1714
|
*/
|
|
1708
1715
|
reset() {
|
|
1709
1716
|
super.reset();
|
|
1717
|
+
this.session.header = null;
|
|
1710
1718
|
this.store.writeDevice({ deviceId: this.getDeviceId() });
|
|
1711
1719
|
}
|
|
1712
1720
|
async close() {
|