@reopt-ai/data-sdk-client 0.1.4 → 0.1.6

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/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-CW9DfTlm.js';
2
+ export { R as ReoptClient, a as ReoptClientConfig, W as WebVitalMetric } from './client-BCd2fgmx.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
@@ -9,8 +9,8 @@ import {
9
9
  useReoptClient,
10
10
  useTrack,
11
11
  useTrackOnMount
12
- } from "./chunk-JNIOYR44.js";
13
- import "./chunk-SRHWNG2G.js";
12
+ } from "./chunk-YRP3I3OD.js";
13
+ import "./chunk-SYCBGBTH.js";
14
14
  import "./chunk-4MTDZBRS.js";
15
15
 
16
16
  // src/next/index.tsx
package/dist/react.cjs CHANGED
@@ -1549,6 +1549,7 @@ var ReoptClient = class extends ReoptCore {
1549
1549
  uninstallers = [];
1550
1550
  torndown = false;
1551
1551
  session;
1552
+ optedOut;
1552
1553
  normalize;
1553
1554
  /** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
1554
1555
  disabled;
@@ -1559,7 +1560,16 @@ var ReoptClient = class extends ReoptCore {
1559
1560
  }
1560
1561
  const writeKey = config.writeKey || "disabled";
1561
1562
  const storagePrefix = config.storagePrefix ?? DEFAULT_STORAGE_PREFIX;
1562
- const store = createIdentityStore(writeKey, { ...config.identity, ...disabled ? { storage: "memory" } : {} });
1563
+ const rawStore = createIdentityStore(writeKey, { ...config.identity, ...disabled ? { storage: "memory" } : {} });
1564
+ const optedOut = {
1565
+ value: (0, import_identity5.isOptedOut)(rawStore.readConsent() ?? config.bootstrap?.consent ?? null) || config.consent?.defaultConsent === false
1566
+ };
1567
+ const store = {
1568
+ ...rawStore,
1569
+ writeDevice: (state) => {
1570
+ if (!optedOut.value) rawStore.writeDevice(state);
1571
+ }
1572
+ };
1563
1573
  const identity = resolveDeviceId(store, config.bootstrap?.deviceId, storagePrefix);
1564
1574
  const now = correctedClock(config.bootstrap);
1565
1575
  const queueStorage = disabled ? memoryStorage() : config.queueStorage ?? localStorageBackend() ?? memoryStorage();
@@ -1612,6 +1622,7 @@ var ReoptClient = class extends ReoptCore {
1612
1622
  this.writeKey = config.writeKey;
1613
1623
  this.disabled = disabled;
1614
1624
  this.session = session;
1625
+ this.optedOut = optedOut;
1615
1626
  this.normalize = config.normalizePath;
1616
1627
  this.store = store;
1617
1628
  this.capture = resolveCapture(config.capture, defaults.pageview);
@@ -1670,6 +1681,34 @@ var ReoptClient = class extends ReoptCore {
1670
1681
  this.scroll?.reset();
1671
1682
  return super.pageView(options);
1672
1683
  }
1684
+ setConsent(category, allowed) {
1685
+ super.setConsent(category, allowed);
1686
+ this.syncOptOut();
1687
+ }
1688
+ setAllConsent(allowed) {
1689
+ super.setAllConsent(allowed);
1690
+ this.syncOptOut();
1691
+ }
1692
+ replaceConsentState(state) {
1693
+ super.replaceConsentState(state);
1694
+ this.syncOptOut();
1695
+ }
1696
+ /**
1697
+ * Refusing `analytics` removes the stored identity (the proxy does the
1698
+ * same on its side); granting it again writes the current device through
1699
+ * so the visit is attributable from that point on.
1700
+ */
1701
+ syncOptOut() {
1702
+ const now = (0, import_identity5.isOptedOut)(this.getConsentState());
1703
+ if (now === this.optedOut.value) return;
1704
+ this.optedOut.value = now;
1705
+ if (now) {
1706
+ this.store.clearDevice();
1707
+ this.session.header = null;
1708
+ } else {
1709
+ this.store.writeDevice({ deviceId: this.getDeviceId() });
1710
+ }
1711
+ }
1673
1712
  identify(options) {
1674
1713
  const result = super.identify(options);
1675
1714
  if (!options.identity && result.queued) {