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

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.
Files changed (57) hide show
  1. package/README.md +141 -7
  2. package/dist/client-B1GlWwVq.d.ts +744 -0
  3. package/dist/client-B1GlWwVq.d.ts.map +1 -0
  4. package/dist/client-BCrui21p.d.cts +744 -0
  5. package/dist/client-BCrui21p.d.cts.map +1 -0
  6. package/dist/exceptions-C9Fh0BIR.js +285 -0
  7. package/dist/exceptions-C9Fh0BIR.js.map +1 -0
  8. package/dist/exceptions-CuhGo9A5.cjs +289 -0
  9. package/dist/exceptions-CuhGo9A5.cjs.map +1 -0
  10. package/dist/index.cjs +75 -1874
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +83 -0
  13. package/dist/index.d.cts.map +1 -0
  14. package/dist/index.d.ts +35 -33
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +49 -70
  17. package/dist/index.js.map +1 -1
  18. package/dist/next.cjs +51 -1919
  19. package/dist/next.cjs.map +1 -1
  20. package/dist/next.d.cts +31 -0
  21. package/dist/next.d.cts.map +1 -0
  22. package/dist/next.d.ts +8 -10
  23. package/dist/next.d.ts.map +1 -0
  24. package/dist/next.js +36 -49
  25. package/dist/next.js.map +1 -1
  26. package/dist/observe-D-BHMwrO.cjs +54 -0
  27. package/dist/observe-D-BHMwrO.cjs.map +1 -0
  28. package/dist/observe-D1pNg1qL.js +54 -0
  29. package/dist/observe-D1pNg1qL.js.map +1 -0
  30. package/dist/react.cjs +105 -1863
  31. package/dist/react.cjs.map +1 -1
  32. package/dist/react.d.cts +80 -0
  33. package/dist/react.d.cts.map +1 -0
  34. package/dist/react.d.ts +52 -46
  35. package/dist/react.d.ts.map +1 -0
  36. package/dist/react.js +118 -23
  37. package/dist/react.js.map +1 -1
  38. package/dist/registry-BPhiH_l9.js +1775 -0
  39. package/dist/registry-BPhiH_l9.js.map +1 -0
  40. package/dist/registry-CGqrOtf4.cjs +1810 -0
  41. package/dist/registry-CGqrOtf4.cjs.map +1 -0
  42. package/dist/tracing-DAhaKkl0.cjs +93 -0
  43. package/dist/tracing-DAhaKkl0.cjs.map +1 -0
  44. package/dist/tracing-Dt1RVuQ9.js +93 -0
  45. package/dist/tracing-Dt1RVuQ9.js.map +1 -0
  46. package/package.json +31 -16
  47. package/dist/chunk-4MTDZBRS.js +0 -57
  48. package/dist/chunk-4MTDZBRS.js.map +0 -1
  49. package/dist/chunk-SYCBGBTH.js +0 -1627
  50. package/dist/chunk-SYCBGBTH.js.map +0 -1
  51. package/dist/chunk-YRP3I3OD.js +0 -106
  52. package/dist/chunk-YRP3I3OD.js.map +0 -1
  53. package/dist/client-BCd2fgmx.d.ts +0 -581
  54. package/dist/exceptions-NQHZUDYO.js +0 -9
  55. package/dist/exceptions-NQHZUDYO.js.map +0 -1
  56. package/dist/tracing-LC3NZND7.js +0 -91
  57. package/dist/tracing-LC3NZND7.js.map +0 -1
package/dist/react.d.ts CHANGED
@@ -1,47 +1,52 @@
1
- import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
4
- export { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
5
- import { R as ReoptClient, T as TrackEventOptions, Q as QueueResult, I as IdentifyOptions, c as IncrementOptions, D as DecrementOptions, P as PageViewOptions, W as WebVitalMetric, F as FlushResult, C as ConsentCategory, a as ReoptClientConfig } from './client-BCd2fgmx.js';
6
-
1
+ import { D as IdentifyOptions, E as FlushResult, O as IncrementOptions, P as TrackEventOptions, b as DecrementOptions, h as ExceptionStepInput, j as QueueResult, k as PageViewOptions, l as ReoptClientConfig, n as ReoptClient, p as WebVitalMetric, t as CaptureExceptionOptions, v as ConsentCategory } from "./client-B1GlWwVq.js";
2
+ import { ReoptBootstrap } from "@reopt-ai/data-contract/identity";
3
+ import { ReactNode } from "react";
4
+ //#region src/react/index.d.ts
7
5
  interface ReoptContextValue {
8
- /** `null` during server rendering and before hydration. */
9
- client: ReoptClient | null;
10
- track: (options: TrackEventOptions) => QueueResult;
11
- identify: (options: IdentifyOptions) => QueueResult;
12
- increment: (options: IncrementOptions) => QueueResult;
13
- decrement: (options: DecrementOptions) => QueueResult;
14
- pageView: (options?: PageViewOptions) => QueueResult;
15
- screenView: (screenName: string, properties?: Record<string, unknown>) => QueueResult;
16
- captureWebVital: (metric: WebVitalMetric) => QueueResult;
17
- captureException: (error: unknown, properties?: Record<string, unknown>) => QueueResult;
18
- register: (properties: Record<string, unknown>) => void;
19
- unregister: (...keys: string[]) => void;
20
- setProfileId: (profileId: string | number | null) => void;
21
- getProfileId: () => string | number | null;
22
- getDeviceId: () => string | null;
23
- reset: () => void;
24
- flush: () => Promise<FlushResult>;
25
- setConsent: (category: ConsentCategory, allowed: boolean) => void;
26
- getConsent: (category: ConsentCategory) => boolean;
27
- setAllConsent: (allowed: boolean) => void;
28
- pauseTracking: () => void;
29
- resumeTracking: () => void;
6
+ /** `null` during server rendering and before hydration. */
7
+ client: ReoptClient | null;
8
+ track: (options: TrackEventOptions) => QueueResult;
9
+ identify: (options: IdentifyOptions) => QueueResult;
10
+ increment: (options: IncrementOptions) => QueueResult;
11
+ decrement: (options: DecrementOptions) => QueueResult;
12
+ pageView: (options?: PageViewOptions) => QueueResult;
13
+ screenView: (screenName: string, properties?: Record<string, unknown>) => QueueResult;
14
+ captureWebVital: (metric: WebVitalMetric) => QueueResult;
15
+ captureException: (error: unknown, optionsOrProperties?: CaptureExceptionOptions | Record<string, unknown>) => QueueResult;
16
+ /**
17
+ * Leave a breadcrumb for the next exception.
18
+ *
19
+ * Exposed here because a React host records these from event handlers, which
20
+ * is where the hook is the only handle on the client it has.
21
+ */
22
+ addExceptionStep: (step: ExceptionStepInput) => void;
23
+ register: (properties: Record<string, unknown>) => void;
24
+ unregister: (...keys: string[]) => void;
25
+ setProfileId: (profileId: string | number | null) => void;
26
+ getProfileId: () => string | number | null;
27
+ getDeviceId: () => string | null;
28
+ reset: () => void;
29
+ flush: () => Promise<FlushResult>;
30
+ setConsent: (category: ConsentCategory, allowed: boolean) => void;
31
+ getConsent: (category: ConsentCategory) => boolean;
32
+ setAllConsent: (allowed: boolean) => void;
33
+ pauseTracking: () => void;
34
+ resumeTracking: () => void;
30
35
  }
31
36
  interface ReoptProviderProps {
32
- children: ReactNode;
33
- /** `bootstrap` may also be passed here; the prop below wins. */
34
- config: Omit<ReoptClientConfig, "bootstrap"> & {
35
- bootstrap?: ReoptBootstrap | null | undefined;
36
- };
37
- /** From the server SDK's `getBootstrap()`. `null` = the server knows nothing about this visitor. */
37
+ children: ReactNode;
38
+ /** `bootstrap` may also be passed here; the prop below wins. */
39
+ config: Omit<ReoptClientConfig, "bootstrap"> & {
38
40
  bootstrap?: ReoptBootstrap | null | undefined;
39
- /**
40
- * Send `$pageview` when the client is created. Default `true`. Set to
41
- * `false` when a router-aware component owns page views (the Next entry
42
- * does this for you).
43
- */
44
- initialPageView?: boolean | undefined;
41
+ };
42
+ /** From the server SDK's `getBootstrap()`. `null` = the server knows nothing about this visitor. */
43
+ bootstrap?: ReoptBootstrap | null | undefined;
44
+ /**
45
+ * Send `$pageview` when the client is created. Default `true`. Set to
46
+ * `false` when a router-aware component owns page views (the Next entry
47
+ * does this for you).
48
+ */
49
+ initialPageView?: boolean | undefined;
45
50
  }
46
51
  /**
47
52
  * Creates the client **during render**, not in an effect. React runs effects
@@ -54,7 +59,7 @@ interface ReoptProviderProps {
54
59
  * that unmounts during a StrictMode simulation or a layout swap must not
55
60
  * tear down the queue. Call `client.close()` yourself if you need to.
56
61
  */
57
- declare function ReoptProvider({ children, config, bootstrap, initialPageView }: ReoptProviderProps): react.JSX.Element;
62
+ declare function ReoptProvider({ children, config, bootstrap, initialPageView }: ReoptProviderProps): import("react").JSX.Element;
58
63
  declare function useReopt(): ReoptContextValue;
59
64
  /** The underlying client, or `null` on the server. */
60
65
  declare function useReoptClient(): ReoptClient | null;
@@ -62,13 +67,14 @@ declare function useTrack(): (name: string, properties?: Record<string, unknown>
62
67
  declare function useIdentify(): (profileId: string | number, properties?: Record<string, unknown>) => QueueResult;
63
68
  declare function usePageView(): (options?: PageViewOptions) => QueueResult;
64
69
  declare function useConsent(): {
65
- setConsent: (category: ConsentCategory, allowed: boolean) => void;
66
- getConsent: (category: ConsentCategory) => boolean;
67
- setAllConsent: (allowed: boolean) => void;
70
+ setConsent: (category: ConsentCategory, allowed: boolean) => void;
71
+ getConsent: (category: ConsentCategory) => boolean;
72
+ setAllConsent: (allowed: boolean) => void;
68
73
  };
69
74
  /** Tracks `name` once per mount (and again if `name` changes). Property changes alone do not re-track. */
70
75
  declare function useTrackOnMount(name: string, properties?: Record<string, unknown>): void;
71
76
  /** Sends one `$pageview` on mount with the options current at that moment. */
72
77
  declare function usePageViewOnMount(options?: PageViewOptions): void;
73
-
74
- export { ConsentCategory, DecrementOptions, FlushResult, IdentifyOptions, IncrementOptions, PageViewOptions, QueueResult, ReoptClient, ReoptClientConfig, type ReoptContextValue, ReoptProvider, type ReoptProviderProps, TrackEventOptions, WebVitalMetric, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount };
78
+ //#endregion
79
+ export { type ConsentCategory, type DecrementOptions, type FlushResult, type IdentifyOptions, type IncrementOptions, type PageViewOptions, type QueueResult, type ReoptBootstrap, type ReoptClient, type ReoptClientConfig, ReoptContextValue, ReoptProvider, ReoptProviderProps, type TrackEventOptions, type WebVitalMetric, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount };
80
+ //# sourceMappingURL=react.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.d.ts","names":[],"sources":["../src/react/index.tsx"],"mappings":";;;;UAoBiB;;EAEf,QAAQ;EACR,QAAQ,SAAS,sBAAsB;EACvC,WAAW,SAAS,oBAAoB;EACxC,YAAY,SAAS,qBAAqB;EAC1C,YAAY,SAAS,qBAAqB;EAC1C,WAAW,UAAU,oBAAoB;EACzC,aAAa,oBAAoB,aAAa,4BAA4B;EAC1E,kBAAkB,QAAQ,mBAAmB;EAC7C,mBACE,gBACA,sBAAsB,0BAA0B,4BAC7C;;;;;;;EAOL,mBAAmB,MAAM;EACzB,WAAW,YAAY;EACvB,gBAAgB;EAChB,eAAe;EACf;EACA;EACA;EACA,aAAa,QAAQ;EACrB,aAAa,UAAU,iBAAiB;EACxC,aAAa,UAAU;EACvB,gBAAgB;EAChB;EACA;;UASe;EACf,UAAU;;EAEV,QAAQ,KAAK;IAAoC,YAAY;;;EAE7D,YAAY;;;;;;EAMZ;;;;;;;;;;;;;iBAcc,gBAAgB,UAAU,QAAQ,WAAW,mBAA0B,qCAAkB,IAAA;iBA0CzF,YAAY;;iBASZ,kBAAkB;iBAIlB,aAAQ,cAEU,aAAe,4BAAuB;iBAGxD,gBAAW,4BAGI,aAAe,4BAAuB;iBAKrD,gBAAW,UA/HJ,oBAAoB;iBAmI3B;EA9GS,aAAA,UAAA,iBAAe;EACf,aAAA,UAAA;EACE,gBAAA;;;iBA+HX,gBAAgB,cAAc,aAAa;;iBAS3C,mBAAmB,UAAU"}
package/dist/react.js CHANGED
@@ -1,26 +1,121 @@
1
1
  "use client";
2
- import {
3
- ReoptProvider,
4
- useConsent,
5
- useIdentify,
6
- usePageView,
7
- usePageViewOnMount,
8
- useReopt,
9
- useReoptClient,
10
- useTrack,
11
- useTrackOnMount
12
- } from "./chunk-YRP3I3OD.js";
13
- import "./chunk-SYCBGBTH.js";
14
- import "./chunk-4MTDZBRS.js";
15
- export {
16
- ReoptProvider,
17
- useConsent,
18
- useIdentify,
19
- usePageView,
20
- usePageViewOnMount,
21
- useReopt,
22
- useReoptClient,
23
- useTrack,
24
- useTrackOnMount
2
+ import { r as getOrCreateClient } from "./registry-BPhiH_l9.js";
3
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from "react";
4
+ import { jsx } from "react/jsx-runtime";
5
+ //#region src/react/index.tsx
6
+ const ReoptContext = createContext(null);
7
+ const NOT_AVAILABLE = {
8
+ eventId: "",
9
+ queued: false,
10
+ reason: "tracking_paused"
25
11
  };
12
+ const NO_FLUSH = {
13
+ status: "idle",
14
+ sent: 0,
15
+ failed: 0,
16
+ pending: 0
17
+ };
18
+ function ReoptProvider({ children, config, bootstrap, initialPageView = true }) {
19
+ const client = typeof window === "undefined" ? null : getOrCreateClient({
20
+ ...config,
21
+ bootstrap: bootstrap !== void 0 ? bootstrap : config.bootstrap ?? null
22
+ }, { pageview: initialPageView });
23
+ const value = useMemo(() => bindClient(client), [client]);
24
+ return jsx(ReoptContext.Provider, {
25
+ value,
26
+ children
27
+ });
28
+ }
29
+ function bindClient(client) {
30
+ const call = (fn, fallback) => client ? fn(client) : fallback;
31
+ return {
32
+ client,
33
+ track: (options) => call((c) => c.track(options), NOT_AVAILABLE),
34
+ identify: (options) => call((c) => c.identify(options), NOT_AVAILABLE),
35
+ increment: (options) => call((c) => c.increment(options), NOT_AVAILABLE),
36
+ decrement: (options) => call((c) => c.decrement(options), NOT_AVAILABLE),
37
+ pageView: (options) => call((c) => c.pageView(options), NOT_AVAILABLE),
38
+ screenView: (name, properties) => call((c) => c.screenView(name, properties), NOT_AVAILABLE),
39
+ captureWebVital: (metric) => call((c) => c.captureWebVital(metric), NOT_AVAILABLE),
40
+ captureException: (error, optionsOrProperties) => call((c) => c.captureException(error, optionsOrProperties), NOT_AVAILABLE),
41
+ addExceptionStep: (step) => call((c) => c.addExceptionStep(step), void 0),
42
+ register: (properties) => call((c) => c.register(properties), void 0),
43
+ unregister: (...keys) => call((c) => c.unregister(...keys), void 0),
44
+ setProfileId: (id) => call((c) => c.setProfileId(id), void 0),
45
+ getProfileId: () => call((c) => c.getProfileId(), null),
46
+ getDeviceId: () => call((c) => c.disabled ? null : c.getDeviceId(), null),
47
+ reset: () => call((c) => c.reset(), void 0),
48
+ flush: () => call((c) => c.flush(), Promise.resolve(NO_FLUSH)),
49
+ setConsent: (category, allowed) => call((c) => c.setConsent(category, allowed), void 0),
50
+ getConsent: (category) => call((c) => c.getConsent(category), false),
51
+ setAllConsent: (allowed) => call((c) => c.setAllConsent(allowed), void 0),
52
+ pauseTracking: () => call((c) => c.pauseTracking(), void 0),
53
+ resumeTracking: () => call((c) => c.resumeTracking(), void 0)
54
+ };
55
+ }
56
+ function useReopt() {
57
+ const context = useContext(ReoptContext);
58
+ if (!context) throw new Error("useReopt must be used within a ReoptProvider");
59
+ return context;
60
+ }
61
+ function useReoptClient() {
62
+ return useReopt().client;
63
+ }
64
+ function useTrack() {
65
+ const { track } = useReopt();
66
+ return useCallback((name, properties) => track({
67
+ name,
68
+ properties
69
+ }), [track]);
70
+ }
71
+ function useIdentify() {
72
+ const { identify } = useReopt();
73
+ return useCallback((profileId, properties) => identify({
74
+ profileId,
75
+ properties
76
+ }), [identify]);
77
+ }
78
+ function usePageView() {
79
+ return useReopt().pageView;
80
+ }
81
+ function useConsent() {
82
+ const { setConsent, getConsent, setAllConsent } = useReopt();
83
+ return useMemo(() => ({
84
+ setConsent,
85
+ getConsent,
86
+ setAllConsent
87
+ }), [
88
+ setConsent,
89
+ getConsent,
90
+ setAllConsent
91
+ ]);
92
+ }
93
+ function useLatest(value) {
94
+ const ref = useRef(value);
95
+ useEffect(() => {
96
+ ref.current = value;
97
+ });
98
+ return ref;
99
+ }
100
+ function useTrackOnMount(name, properties) {
101
+ const latest = useLatest({
102
+ track: useTrack(),
103
+ properties
104
+ });
105
+ useEffect(() => {
106
+ latest.current.track(name, latest.current.properties);
107
+ }, [name, latest]);
108
+ }
109
+ function usePageViewOnMount(options) {
110
+ const latest = useLatest({
111
+ pageView: usePageView(),
112
+ options
113
+ });
114
+ useEffect(() => {
115
+ latest.current.pageView(latest.current.options);
116
+ }, [latest]);
117
+ }
118
+ //#endregion
119
+ export { ReoptProvider, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount };
120
+
26
121
  //# sourceMappingURL=react.js.map
package/dist/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"react.js","names":[],"sources":["../src/react/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useCallback, useContext, useEffect, useMemo, useRef, type ReactNode } from \"react\";\nimport type { ReoptBootstrap } from \"@reopt-ai/data-contract/identity\";\nimport type {\n ConsentCategory,\n DecrementOptions,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueResult,\n TrackEventOptions,\n} from \"@reopt-ai/data-sdk-core\";\nimport type { WebVitalMetric } from \"../capture/web-vitals.js\";\nimport type { CaptureExceptionOptions, ReoptClient } from \"../client.js\";\nimport type { ExceptionStepInput } from \"../steps.js\";\nimport type { ReoptClientConfig } from \"../config.js\";\nimport { getOrCreateClient } from \"../registry.js\";\n\nexport interface ReoptContextValue {\n /** `null` during server rendering and before hydration. */\n client: ReoptClient | null;\n track: (options: TrackEventOptions) => QueueResult;\n identify: (options: IdentifyOptions) => QueueResult;\n increment: (options: IncrementOptions) => QueueResult;\n decrement: (options: DecrementOptions) => QueueResult;\n pageView: (options?: PageViewOptions) => QueueResult;\n screenView: (screenName: string, properties?: Record<string, unknown>) => QueueResult;\n captureWebVital: (metric: WebVitalMetric) => QueueResult;\n captureException: (\n error: unknown,\n optionsOrProperties?: CaptureExceptionOptions | Record<string, unknown>\n ) => QueueResult;\n /**\n * Leave a breadcrumb for the next exception.\n *\n * Exposed here because a React host records these from event handlers, which\n * is where the hook is the only handle on the client it has.\n */\n addExceptionStep: (step: ExceptionStepInput) => void;\n register: (properties: Record<string, unknown>) => void;\n unregister: (...keys: string[]) => void;\n setProfileId: (profileId: string | number | null) => void;\n getProfileId: () => string | number | null;\n getDeviceId: () => string | null;\n reset: () => void;\n flush: () => Promise<FlushResult>;\n setConsent: (category: ConsentCategory, allowed: boolean) => void;\n getConsent: (category: ConsentCategory) => boolean;\n setAllConsent: (allowed: boolean) => void;\n pauseTracking: () => void;\n resumeTracking: () => void;\n}\n\nconst ReoptContext = createContext<ReoptContextValue | null>(null);\n\n/** What a call returns when there is no client (server render). Never queued, never an error. */\nconst NOT_AVAILABLE: QueueResult = { eventId: \"\", queued: false, reason: \"tracking_paused\" };\nconst NO_FLUSH: FlushResult = { status: \"idle\", sent: 0, failed: 0, pending: 0 };\n\nexport interface ReoptProviderProps {\n children: ReactNode;\n /** `bootstrap` may also be passed here; the prop below wins. */\n config: Omit<ReoptClientConfig, \"bootstrap\"> & { bootstrap?: ReoptBootstrap | null | undefined };\n /** From the server SDK's `getBootstrap()`. `null` = the server knows nothing about this visitor. */\n bootstrap?: ReoptBootstrap | null | undefined;\n /**\n * Send `$pageview` when the client is created. Default `true`. Set to\n * `false` when a router-aware component owns page views (the Next entry\n * does this for you).\n */\n initialPageView?: boolean | undefined;\n}\n\n/**\n * Creates the client **during render**, not in an effect. React runs effects\n * children-first, so a child's `useEffect` (a consent banner, a\n * `useTrackOnMount`) would otherwise run before the provider's effect had\n * created anything. Creation is idempotent per write key — StrictMode's\n * double render and a remount reuse the same instance.\n *\n * The client is never closed on unmount: it is page-scoped, and a provider\n * that unmounts during a StrictMode simulation or a layout swap must not\n * tear down the queue. Call `client.close()` yourself if you need to.\n */\nexport function ReoptProvider({ children, config, bootstrap, initialPageView = true }: ReoptProviderProps) {\n const client =\n typeof window === \"undefined\"\n ? null\n : getOrCreateClient(\n { ...config, bootstrap: bootstrap !== undefined ? bootstrap : (config.bootstrap ?? null) },\n { pageview: initialPageView }\n );\n\n const value = useMemo<ReoptContextValue>(() => bindClient(client), [client]);\n return <ReoptContext.Provider value={value}>{children}</ReoptContext.Provider>;\n}\n\nfunction bindClient(client: ReoptClient | null): ReoptContextValue {\n const call = <T,>(fn: (client: ReoptClient) => T, fallback: T): T => (client ? fn(client) : fallback);\n return {\n client,\n track: (options) => call((c) => c.track(options), NOT_AVAILABLE),\n identify: (options) => call((c) => c.identify(options), NOT_AVAILABLE),\n increment: (options) => call((c) => c.increment(options), NOT_AVAILABLE),\n decrement: (options) => call((c) => c.decrement(options), NOT_AVAILABLE),\n pageView: (options) => call((c) => c.pageView(options), NOT_AVAILABLE),\n screenView: (name, properties) => call((c) => c.screenView(name, properties), NOT_AVAILABLE),\n captureWebVital: (metric) => call((c) => c.captureWebVital(metric), NOT_AVAILABLE),\n captureException: (error, optionsOrProperties) =>\n call((c) => c.captureException(error, optionsOrProperties), NOT_AVAILABLE),\n addExceptionStep: (step) => call((c) => c.addExceptionStep(step), undefined),\n register: (properties) => call((c) => c.register(properties), undefined),\n unregister: (...keys) => call((c) => c.unregister(...keys), undefined),\n setProfileId: (id) => call((c) => c.setProfileId(id), undefined),\n getProfileId: () => call((c) => c.getProfileId(), null),\n getDeviceId: () => call((c) => (c.disabled ? null : c.getDeviceId()), null),\n reset: () => call((c) => c.reset(), undefined),\n flush: () => call((c) => c.flush(), Promise.resolve(NO_FLUSH)),\n setConsent: (category, allowed) => call((c) => c.setConsent(category, allowed), undefined),\n getConsent: (category) => call((c) => c.getConsent(category), false),\n setAllConsent: (allowed) => call((c) => c.setAllConsent(allowed), undefined),\n pauseTracking: () => call((c) => c.pauseTracking(), undefined),\n resumeTracking: () => call((c) => c.resumeTracking(), undefined),\n };\n}\n\nexport function useReopt(): ReoptContextValue {\n const context = useContext(ReoptContext);\n if (!context) {\n throw new Error(\"useReopt must be used within a ReoptProvider\");\n }\n return context;\n}\n\n/** The underlying client, or `null` on the server. */\nexport function useReoptClient(): ReoptClient | null {\n return useReopt().client;\n}\n\nexport function useTrack() {\n const { track } = useReopt();\n return useCallback((name: string, properties?: Record<string, unknown>) => track({ name, properties }), [track]);\n}\n\nexport function useIdentify() {\n const { identify } = useReopt();\n return useCallback(\n (profileId: string | number, properties?: Record<string, unknown>) => identify({ profileId, properties }),\n [identify]\n );\n}\n\nexport function usePageView() {\n return useReopt().pageView;\n}\n\nexport function useConsent() {\n const { setConsent, getConsent, setAllConsent } = useReopt();\n return useMemo(() => ({ setConsent, getConsent, setAllConsent }), [setConsent, getConsent, setAllConsent]);\n}\n\n/**\n * The latest value of `value`, readable from an effect that must not rerun\n * when it changes. Stands in for `useEffectEvent`, which needs React 19.2\n * while this package supports 18.\n */\nfunction useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n });\n return ref;\n}\n\n/** Tracks `name` once per mount (and again if `name` changes). Property changes alone do not re-track. */\nexport function useTrackOnMount(name: string, properties?: Record<string, unknown>) {\n const track = useTrack();\n const latest = useLatest({ track, properties });\n useEffect(() => {\n latest.current.track(name, latest.current.properties);\n }, [name, latest]);\n}\n\n/** Sends one `$pageview` on mount with the options current at that moment. */\nexport function usePageViewOnMount(options?: PageViewOptions) {\n const pageView = usePageView();\n const latest = useLatest({ pageView, options });\n useEffect(() => {\n latest.current.pageView(latest.current.options);\n }, [latest]);\n}\n\nexport type { ReoptBootstrap, ReoptClient, ReoptClientConfig, WebVitalMetric };\nexport type {\n ConsentCategory,\n DecrementOptions,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueResult,\n TrackEventOptions,\n};\n"],"mappings":";;;;;AAuDA,MAAM,eAAe,cAAwC,IAAI;AAGjE,MAAM,gBAA6B;CAAE,SAAS;CAAI,QAAQ;CAAO,QAAQ;AAAkB;AAC3F,MAAM,WAAwB;CAAE,QAAQ;CAAQ,MAAM;CAAG,QAAQ;CAAG,SAAS;AAAE;AA2B/E,SAAgB,cAAc,EAAE,UAAU,QAAQ,WAAW,kBAAkB,QAA4B;CACzG,MAAM,SACJ,OAAO,WAAW,cACd,OACA,kBACE;EAAE,GAAG;EAAQ,WAAW,cAAc,KAAA,IAAY,YAAa,OAAO,aAAa;CAAM,GACzF,EAAE,UAAU,gBAAgB,CAC9B;CAEN,MAAM,QAAQ,cAAiC,WAAW,MAAM,GAAG,CAAC,MAAM,CAAC;CAC3E,OAAO,IAAC,aAAa,UAAd;EAA8B;EAAQ;CAAgC,CAAA;AAC/E;AAE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