@reopt-ai/data-sdk-client 0.1.3 → 0.1.5

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as ReoptClient, a as ReoptClientConfig, b as ReoptClientDefaults, U as UTMParams, Q as QueueResult, W as WebVitalMetric, F as FlushResult, D as DecrementOptions, C as ConsentCategory, I as IdentifyOptions, c as IncrementOptions, P as PageViewOptions, T as TrackEventOptions } from './client-CW9DfTlm.js';
2
- export { B as BatchConfig, d as CaptureConfig, e as CircuitBreakerConfig, f as ConsentConfig, E as EventIdentity, g as EventPayload, h as FetchInit, i as FetchLike, j as FetchResponseLike, k as IdentityConfig, l as IdentityStorageKind, N as NormalizePath, m as QueueDropReason, n as RetryConfig, S as StorageBackend, o as WebVitalProperties } from './client-CW9DfTlm.js';
1
+ import { R as ReoptClient, a as ReoptClientConfig, b as ReoptClientDefaults, U as UTMParams, Q as QueueResult, W as WebVitalMetric, F as FlushResult, D as DecrementOptions, C as ConsentCategory, I as IdentifyOptions, c as IncrementOptions, P as PageViewOptions, T as TrackEventOptions } from './client-TesmBLXd.js';
2
+ export { B as BatchConfig, d as CaptureConfig, e as CircuitBreakerConfig, f as ConsentConfig, E as EventIdentity, g as EventPayload, h as FetchInit, i as FetchLike, j as FetchResponseLike, k as IdentityConfig, l as IdentityStorageKind, N as NormalizePath, m as QueueDropReason, n as RetryConfig, S as StorageBackend, o as WebVitalProperties } from './client-TesmBLXd.js';
3
3
  export { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
4
4
 
5
5
  /**
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  forgetClient,
5
5
  getClient,
6
6
  getOrCreateClient
7
- } from "./chunk-SRHWNG2G.js";
7
+ } from "./chunk-BJGIHFDA.js";
8
8
  import "./chunk-4MTDZBRS.js";
9
9
 
10
10
  // src/index.ts
package/dist/next.cjs CHANGED
@@ -1556,6 +1556,7 @@ var ReoptClient = class extends ReoptCore {
1556
1556
  uninstallers = [];
1557
1557
  torndown = false;
1558
1558
  session;
1559
+ optedOut;
1559
1560
  normalize;
1560
1561
  /** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
1561
1562
  disabled;
@@ -1566,7 +1567,16 @@ var ReoptClient = class extends ReoptCore {
1566
1567
  }
1567
1568
  const writeKey = config.writeKey || "disabled";
1568
1569
  const storagePrefix = config.storagePrefix ?? DEFAULT_STORAGE_PREFIX;
1569
- const store = createIdentityStore(writeKey, { ...config.identity, ...disabled ? { storage: "memory" } : {} });
1570
+ const rawStore = createIdentityStore(writeKey, { ...config.identity, ...disabled ? { storage: "memory" } : {} });
1571
+ const optedOut = {
1572
+ value: (0, import_identity5.isOptedOut)(rawStore.readConsent() ?? config.bootstrap?.consent ?? null) || config.consent?.defaultConsent === false
1573
+ };
1574
+ const store = {
1575
+ ...rawStore,
1576
+ writeDevice: (state) => {
1577
+ if (!optedOut.value) rawStore.writeDevice(state);
1578
+ }
1579
+ };
1570
1580
  const identity = resolveDeviceId(store, config.bootstrap?.deviceId, storagePrefix);
1571
1581
  const now = correctedClock(config.bootstrap);
1572
1582
  const queueStorage = disabled ? memoryStorage() : config.queueStorage ?? localStorageBackend() ?? memoryStorage();
@@ -1619,6 +1629,7 @@ var ReoptClient = class extends ReoptCore {
1619
1629
  this.writeKey = config.writeKey;
1620
1630
  this.disabled = disabled;
1621
1631
  this.session = session;
1632
+ this.optedOut = optedOut;
1622
1633
  this.normalize = config.normalizePath;
1623
1634
  this.store = store;
1624
1635
  this.capture = resolveCapture(config.capture, defaults.pageview);
@@ -1677,6 +1688,34 @@ var ReoptClient = class extends ReoptCore {
1677
1688
  this.scroll?.reset();
1678
1689
  return super.pageView(options);
1679
1690
  }
1691
+ setConsent(category, allowed) {
1692
+ super.setConsent(category, allowed);
1693
+ this.syncOptOut();
1694
+ }
1695
+ setAllConsent(allowed) {
1696
+ super.setAllConsent(allowed);
1697
+ this.syncOptOut();
1698
+ }
1699
+ replaceConsentState(state) {
1700
+ super.replaceConsentState(state);
1701
+ this.syncOptOut();
1702
+ }
1703
+ /**
1704
+ * Refusing `analytics` removes the stored identity (the proxy does the
1705
+ * same on its side); granting it again writes the current device through
1706
+ * so the visit is attributable from that point on.
1707
+ */
1708
+ syncOptOut() {
1709
+ const now = (0, import_identity5.isOptedOut)(this.getConsentState());
1710
+ if (now === this.optedOut.value) return;
1711
+ this.optedOut.value = now;
1712
+ if (now) {
1713
+ this.store.clearDevice();
1714
+ this.session.header = null;
1715
+ } else {
1716
+ this.store.writeDevice({ deviceId: this.getDeviceId() });
1717
+ }
1718
+ }
1680
1719
  identify(options) {
1681
1720
  const result = super.identify(options);
1682
1721
  if (!options.identity && result.queued) {
@@ -1861,7 +1900,7 @@ function PageViewTracker() {
1861
1900
  const key = search ? `${pathname}?${search}` : pathname;
1862
1901
  if (lastKey.current === key) return;
1863
1902
  lastKey.current = key;
1864
- pageView({ path: pathname, properties: search ? { search } : void 0 });
1903
+ pageView({ properties: search ? { search } : void 0 });
1865
1904
  }, [pathname, searchParams, pageView]);
1866
1905
  return null;
1867
1906
  }