@reopt-ai/data-sdk-client 0.1.5 → 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 +53 -47
  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-2UPF3C7D.js +0 -106
  48. package/dist/chunk-2UPF3C7D.js.map +0 -1
  49. package/dist/chunk-4MTDZBRS.js +0 -57
  50. package/dist/chunk-4MTDZBRS.js.map +0 -1
  51. package/dist/chunk-BJGIHFDA.js +0 -1627
  52. package/dist/chunk-BJGIHFDA.js.map +0 -1
  53. package/dist/client-TesmBLXd.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
@@ -1,581 +0,0 @@
1
- import { ReoptBootstrap, DeviceCookieState, ConsentCookieState } from '@reopt-ai/data-contract/identity';
2
-
3
- /**
4
- * Types shared by every runtime. Nothing here refers to `window`, `document`
5
- * or a Node built-in — the runtime-specific pieces are injected through
6
- * {@link ReoptRuntime}.
7
- */
8
- /** Consent categories. `analytics` is the one whose refusal stops everything. */
9
- type ConsentCategory = "analytics" | "marketing" | "functional" | "performance";
10
- interface ConsentConfig {
11
- /** Default decision for every configured category. Default: `true` (opt-out model). */
12
- defaultConsent?: boolean;
13
- /** Categories the integration recognises. Default: `["analytics"]`. */
14
- categories?: ConsentCategory[];
15
- /** Persist decisions through the runtime's storage. Default: `true`. */
16
- persist?: boolean;
17
- }
18
- /** Minimal synchronous key/value store — `localStorage`-shaped on purpose. */
19
- interface StorageBackend {
20
- getItem(key: string): string | null;
21
- setItem(key: string, value: string): void;
22
- removeItem(key: string): void;
23
- }
24
- interface RetryConfig {
25
- /** Attempts after the first. Default: 3. */
26
- maxRetries?: number;
27
- /** First back-off, milliseconds. Default: 1000. */
28
- baseDelay?: number;
29
- /** Back-off ceiling, milliseconds. Default: 30000. */
30
- maxDelay?: number;
31
- /** ± fraction of the delay. Default: 0.1. */
32
- jitter?: number;
33
- }
34
- interface CircuitBreakerConfig {
35
- /** Consecutive transient failures before the circuit opens. Default: 5. */
36
- failureThreshold?: number;
37
- /** How long the circuit stays open before one probe is allowed. Default: 60000. */
38
- recoveryTimeout?: number;
39
- }
40
- interface BatchConfig {
41
- /** Events per request. Default: 100. */
42
- size?: number;
43
- /** Milliseconds to wait for a batch to fill before sending. Default: 1000. */
44
- intervalMs?: number;
45
- /**
46
- * Serialized bytes per request. Default: 400 000, under the server's
47
- * 512 000 hard cap with room for the JSON envelope. A 413 is a 4xx, and 4xx
48
- * drops the batch — so overshooting the cap loses every event in it.
49
- */
50
- maxBytes?: number;
51
- }
52
- /** Browser credentials — public, ships in the page. */
53
- interface WriteKeyAuth {
54
- writeKey: string;
55
- }
56
- /** Server credentials — must never reach a client bundle. */
57
- interface ClientCredentialsAuth {
58
- clientId: string;
59
- clientSecret: string;
60
- }
61
- type ReoptAuth = WriteKeyAuth | ClientCredentialsAuth;
62
- type FetchLike = (input: string, init: FetchInit) => Promise<FetchResponseLike>;
63
- interface FetchInit {
64
- method: string;
65
- headers: Record<string, string>;
66
- body: string;
67
- keepalive?: boolean;
68
- }
69
- interface FetchResponseLike {
70
- ok: boolean;
71
- status: number;
72
- headers: {
73
- get(name: string): string | null;
74
- };
75
- text(): Promise<string>;
76
- }
77
- /** Context the runtime fills in for a `$pageview` when the caller does not. */
78
- interface PageContext {
79
- path?: string;
80
- origin?: string;
81
- title?: string;
82
- referrer?: string;
83
- utm?: UTMParams;
84
- /** Extra properties the runtime derived from the page, e.g. a `normalizePath` hook's output. */
85
- properties?: Record<string, unknown>;
86
- }
87
- /**
88
- * Everything the engine needs from the world around it. The browser package
89
- * fills this from cookies, `localStorage` and `window`; the server package
90
- * from request cookies and headers; tests from plain objects.
91
- */
92
- interface ReoptRuntime {
93
- /** Resolved device id. Identity resolution is the runtime's job, not the engine's. */
94
- deviceId: string;
95
- /**
96
- * Value for the `reopt-session-id` header — the `"<id>.<token>"` credential
97
- * ingest handed back, if the runtime kept it. Unsigned values are ignored
98
- * by ingest, so only send what came from `onSession`.
99
- */
100
- getSessionId?: () => string | null | undefined;
101
- /** Ingest assigned (or confirmed) a session for this batch. The runtime persists it. */
102
- onSession?: (credential: {
103
- id: string;
104
- token: string;
105
- }) => void;
106
- /** Durable store for the offline queue and consent. Absent = memory only. */
107
- storage?: StorageBackend;
108
- /** Clock. Defaults to `Date.now`; the browser package corrects for server skew. */
109
- now?: () => number;
110
- /** Id generator. Defaults to monotonic UUIDv7. */
111
- createId?: () => string;
112
- /** `fetch` implementation. Defaults to `globalThis.fetch`. */
113
- fetch?: FetchLike;
114
- /**
115
- * Subscribe to "the process is about to go away" signals (pagehide,
116
- * visibilitychange, SIGTERM). The engine flushes on each signal. Returns
117
- * the unsubscribe function.
118
- */
119
- onFlushSignal?: (flush: () => void) => () => void;
120
- /**
121
- * Last-chance delivery used when a flush signal fires, e.g. `sendBeacon`.
122
- * Return `true` if the runtime accepted the payload; `false` falls back to
123
- * keepalive fetch.
124
- */
125
- sendLastChance?: (url: string, body: string, headers: Record<string, string>) => boolean;
126
- /** Defaults for `$pageview` properties. */
127
- getPageContext?: () => PageContext;
128
- /**
129
- * Mint and persist a fresh device id. Called by `reset()`; without it a
130
- * reset keeps the old device, which is wrong on a shared machine.
131
- */
132
- regenerateDeviceId?: () => string;
133
- }
134
- interface ReoptCoreConfig {
135
- auth: ReoptAuth;
136
- /** Origin of the reopt-data deployment, or a same-origin proxy prefix like `/ingest`. */
137
- baseUrl: string;
138
- runtime: ReoptRuntime;
139
- debug?: boolean;
140
- batch?: BatchConfig;
141
- /** Upper bound on queued events; the oldest are dropped past it. Default: 10000. */
142
- maxQueueSize?: number;
143
- retry?: RetryConfig;
144
- circuitBreaker?: CircuitBreakerConfig;
145
- consent?: ConsentConfig;
146
- /** Prefix for storage keys. Default: `reopt_`. */
147
- storagePrefix?: string;
148
- /** Persist the queue through `runtime.storage`. Default: `true` when storage exists. */
149
- enableOfflineBuffer?: boolean;
150
- /** Flush on runtime flush signals. Default: `true` when the runtime provides them. */
151
- autoFlushOnUnload?: boolean;
152
- }
153
- /**
154
- * Identity a single event was recorded under, when it differs from the
155
- * runtime's. The server SDK uses this to file events from many requests
156
- * through one engine: each request's device travels with its events and
157
- * becomes that batch's `reopt-device-id`.
158
- */
159
- interface EventIdentity {
160
- deviceId?: string;
161
- sessionId?: string | null;
162
- }
163
- interface TrackEventOptions {
164
- /** File this event under another visitor than the runtime's. Server SDK use. */
165
- identity?: EventIdentity;
166
- name: string;
167
- properties?: Record<string, unknown>;
168
- profileId?: string | number;
169
- /** Consent category this event belongs to. Default: `analytics`. */
170
- consentCategory?: ConsentCategory;
171
- }
172
- interface IdentifyOptions {
173
- /** File this event under another visitor than the runtime's. Server SDK use. */
174
- identity?: EventIdentity;
175
- profileId: string | number;
176
- firstName?: string;
177
- lastName?: string;
178
- email?: string;
179
- avatar?: string;
180
- properties?: Record<string, unknown>;
181
- consentCategory?: ConsentCategory;
182
- }
183
- interface IncrementOptions {
184
- /** File this event under another visitor than the runtime's. Server SDK use. */
185
- identity?: EventIdentity;
186
- profileId: string | number;
187
- property: string;
188
- value?: number;
189
- consentCategory?: ConsentCategory;
190
- }
191
- interface DecrementOptions {
192
- /** File this event under another visitor than the runtime's. Server SDK use. */
193
- identity?: EventIdentity;
194
- profileId: string | number;
195
- property: string;
196
- value?: number;
197
- consentCategory?: ConsentCategory;
198
- }
199
- interface UTMParams {
200
- utm_source?: string;
201
- utm_medium?: string;
202
- utm_campaign?: string;
203
- utm_term?: string;
204
- utm_content?: string;
205
- }
206
- interface PageViewOptions {
207
- /** File this event under another visitor than the runtime's. Server SDK use. */
208
- identity?: EventIdentity;
209
- path?: string;
210
- /** Scheme + host. */
211
- origin?: string;
212
- title?: string;
213
- referrer?: string;
214
- properties?: Record<string, unknown>;
215
- utm?: UTMParams;
216
- consentCategory?: ConsentCategory;
217
- }
218
- type EventPayload = {
219
- type: "track";
220
- eventId: string;
221
- timestamp: number;
222
- payload: {
223
- name: string;
224
- properties?: Record<string, unknown>;
225
- profileId?: string | number;
226
- };
227
- } | {
228
- type: "identify";
229
- eventId: string;
230
- timestamp: number;
231
- payload: {
232
- profileId: string | number;
233
- firstName?: string;
234
- lastName?: string;
235
- email?: string;
236
- avatar?: string;
237
- properties?: Record<string, unknown>;
238
- };
239
- } | {
240
- type: "increment";
241
- eventId: string;
242
- timestamp: number;
243
- payload: {
244
- profileId: string | number;
245
- property: string;
246
- value?: number;
247
- };
248
- } | {
249
- type: "decrement";
250
- eventId: string;
251
- timestamp: number;
252
- payload: {
253
- profileId: string | number;
254
- property: string;
255
- value?: number;
256
- };
257
- };
258
- type QueueDropReason = "tracking_paused" | "consent_denied" | "validation_failed" | "payload_too_large";
259
- interface QueueResult {
260
- eventId: string;
261
- queued: boolean;
262
- reason?: QueueDropReason;
263
- errors?: Array<{
264
- field: string;
265
- message: string;
266
- }>;
267
- }
268
- interface FlushResult {
269
- status: "idle" | "success" | "failed" | "skipped";
270
- sent: number;
271
- failed: number;
272
- pending: number;
273
- }
274
- interface FlushOptions {
275
- /** Ask the transport to outlive the page (keepalive fetch / beacon). */
276
- keepalive?: boolean;
277
- /** Keep sending until the queue is empty or no progress is made. */
278
- drain?: boolean;
279
- }
280
-
281
- type ConsentState = Record<string, boolean>;
282
-
283
- interface BatchDelivery {
284
- sent: number;
285
- failed: number;
286
- /** The signed session credential ingest returned, when it did. */
287
- session?: {
288
- id: string;
289
- token: string;
290
- };
291
- }
292
- interface SendOptions {
293
- keepalive?: boolean;
294
- /** Overrides the runtime's device/session for this request only. */
295
- identity?: EventIdentity;
296
- }
297
- interface Transport {
298
- readonly url: string;
299
- headers(identity?: EventIdentity): Record<string, string>;
300
- send(batch: EventPayload[], options?: SendOptions): Promise<BatchDelivery>;
301
- }
302
-
303
- /**
304
- * The engine: queue → batch → transport, with retry, a circuit breaker and
305
- * consent gates. Everything that differs between browser and server comes in
306
- * through {@link ReoptRuntime}; the engine itself never touches `window`,
307
- * `document`, `process` or a Node built-in.
308
- */
309
- declare class ReoptCore {
310
- protected readonly runtime: ReoptRuntime;
311
- protected readonly transport: Transport;
312
- private readonly queue;
313
- private readonly consent;
314
- private readonly breaker;
315
- private readonly retry;
316
- private readonly batch;
317
- private readonly factory;
318
- private readonly debug;
319
- private deviceId;
320
- private profileId;
321
- private globalProperties;
322
- private activeFlush;
323
- private flushTimeout;
324
- private removeFlushSignal;
325
- private closed;
326
- /** Bumped by `reset()`; a batch from an older generation is never requeued. */
327
- private generation;
328
- private lastFlushRequeued;
329
- constructor(config: ReoptCoreConfig);
330
- protected log(...args: unknown[]): void;
331
- getDeviceId(): string;
332
- /** Swap the device id, e.g. after a server bootstrap or a `reset()`. */
333
- setDeviceId(deviceId: string): void;
334
- setProfileId(profileId: string | number | null): void;
335
- getProfileId(): string | number | null;
336
- setConsent(category: ConsentCategory, allowed: boolean): void;
337
- getConsent(category: ConsentCategory): boolean;
338
- setAllConsent(allowed: boolean): void;
339
- getConsentState(): ConsentState;
340
- replaceConsentState(state: ConsentState): void;
341
- pauseTracking(): void;
342
- resumeTracking(): void;
343
- /**
344
- * Properties attached to every `track` event (and so every automatic
345
- * event) from now on. An event's own properties win on conflict. This is
346
- * how a host adds its breakdown axis — a `page_id`, a tenant — to
347
- * `$web_vitals` and `$pageleave`, which the SDK otherwise stamps with
348
- * only a path.
349
- */
350
- register(properties: Record<string, unknown>): void;
351
- unregister(...keys: string[]): void;
352
- getGlobalProperties(): Record<string, unknown>;
353
- /**
354
- * `options.identity` files the event under another visitor than the
355
- * runtime's — the server SDK's way of serving many requests from one
356
- * engine. Such an event never reads or writes the engine's own profile:
357
- * that belongs to the runtime's visitor, not the request's.
358
- */
359
- track(options: TrackEventOptions): QueueResult;
360
- identify(options: IdentifyOptions): QueueResult;
361
- increment(options: IncrementOptions): QueueResult;
362
- decrement(options: DecrementOptions): QueueResult;
363
- pageView(options?: PageViewOptions): QueueResult;
364
- screenView(screenName: string, properties?: Record<string, unknown>, identity?: EventIdentity): QueueResult;
365
- get pending(): number;
366
- private enqueue;
367
- private scheduleFlush;
368
- private clearScheduledFlush;
369
- flush(options?: FlushOptions): Promise<FlushResult>;
370
- /**
371
- * The page (or process) is going away. Persist first so nothing is lost if
372
- * the request never completes, then send what can be sent with keepalive.
373
- */
374
- private flushOnSignal;
375
- /**
376
- * The identity a batch is sent under, fixed when it leaves the queue. A
377
- * `reset()` during a retry must not re-address the previous visitor's
378
- * events to the new device.
379
- */
380
- private identityFor;
381
- private flushExclusive;
382
- private flushAll;
383
- private flushOnce;
384
- private continueOrSettle;
385
- /**
386
- * Forget who this is: profile, queued events and — when the runtime can
387
- * mint one — the device id. A shared computer that logs out must not keep
388
- * attributing the next person to the previous one.
389
- */
390
- reset(): void;
391
- close(): Promise<FlushResult>;
392
- }
393
-
394
- /**
395
- * The shape `next/web-vitals`' `useReportWebVitals` and the `web-vitals`
396
- * package both produce. Declared here so the vanilla entry does not have to
397
- * import either.
398
- */
399
- interface WebVitalMetric {
400
- id: string;
401
- name: string;
402
- value: number;
403
- delta?: number;
404
- rating?: "good" | "needs-improvement" | "poor";
405
- navigationType?: string;
406
- }
407
- type WebVitalProperties = {
408
- metric_name: string;
409
- metric_id: string;
410
- value: number;
411
- delta?: number;
412
- rating?: string;
413
- navigation_type?: string;
414
- path: string;
415
- };
416
-
417
- /**
418
- * Rewrites a pathname before it is attached to an event, and may lift the
419
- * parts it removed into properties so they stay available for breakdowns:
420
- * `/workspace/8f3…/crm/customers/2a1…` → `{ path: "/workspace/:id/crm/customers/:id",
421
- * properties: { workspace_id: "8f3…" } }`.
422
- *
423
- * Applied wherever the SDK fills in a path itself — the default `$pageview`
424
- * path, `$pageleave`, `$web_vitals`, `$exception`. A `path` you pass to
425
- * `pageView()` explicitly is used as-is, so run the same function on it
426
- * yourself; two different rules would give one visit two different paths.
427
- * Must be synchronous and pure. If it throws, the raw pathname is used.
428
- */
429
- type NormalizePath = (pathname: string) => string | {
430
- path: string;
431
- properties?: Record<string, unknown>;
432
- };
433
-
434
- type IdentityStorageKind = "auto" | "cookie" | "localStorage" | "memory";
435
- interface IdentityConfig {
436
- /**
437
- * Where the device id lives. `auto` (default) prefers a cookie: Safari
438
- * expires script-written `localStorage` after seven days of inactivity,
439
- * which turns every returning visitor into a new device. A cookie the
440
- * server also reads survives that, and lets server-side events join the
441
- * same device.
442
- */
443
- storage?: IdentityStorageKind;
444
- /** Cookie `Domain`; omit for host-only. Set to share across subdomains. */
445
- cookieDomain?: string;
446
- /** Cookie lifetime. Default 400 days (the longest Chrome honours). */
447
- cookieMaxAgeSeconds?: number;
448
- }
449
- interface CaptureConfig {
450
- /**
451
- * Send `$pageview` on `init()`. Default `true` for the vanilla entry.
452
- * The Next entry sets it to `false` because `<ReoptPageView />` owns page
453
- * views there — including the first one.
454
- */
455
- pageview?: boolean;
456
- /** Send `$pageleave` with time-on-page when the page is hidden or the route changes. Default `true`. */
457
- pageleave?: boolean;
458
- /** Attach max scroll depth to `$pageleave`. Default `true`. */
459
- scrollDepth?: boolean;
460
- /** Send `$exception` for uncaught errors and unhandled rejections. Default `false`. */
461
- exceptions?: boolean;
462
- }
463
- interface ReoptClientConfig {
464
- writeKey: string;
465
- /** reopt-data origin, or the same-origin proxy prefix (e.g. `/ingest`) the Next.js proxy rewrites. */
466
- baseUrl: string;
467
- /** What the server already knows about this visitor. `null` = nothing. */
468
- bootstrap?: ReoptBootstrap | null;
469
- identity?: IdentityConfig;
470
- capture?: CaptureConfig;
471
- /**
472
- * Hosts that receive the `reopt-device-id` header on outgoing `fetch`/XHR,
473
- * so a server-side `track()` lands on the same device. `true` = the page's
474
- * own hostname. **Default: off** — the trusted path is passing
475
- * `getDeviceId()` to your server call explicitly; this patches `fetch`
476
- * and loads as a separate chunk only when enabled.
477
- */
478
- tracingHeaders?: boolean | string[];
479
- /** See {@link NormalizePath}. */
480
- normalizePath?: NormalizePath;
481
- /**
482
- * Properties attached to every event from the very first one. Same as
483
- * calling `register()` right after `init()`, except that nothing can
484
- * slip out in between: web vitals arrive from a buffered
485
- * `PerformanceObserver` and can fire the instant the client exists.
486
- * Pass the page context the server already knows here; update it on
487
- * client-side navigation with `register()`.
488
- */
489
- properties?: Record<string, unknown>;
490
- consent?: ConsentConfig;
491
- batch?: BatchConfig;
492
- retry?: RetryConfig;
493
- circuitBreaker?: CircuitBreakerConfig;
494
- /** Upper bound on queued events. Default 10 000. */
495
- maxQueueSize?: number;
496
- /** Overrides the store for the offline queue. Default `localStorage`. */
497
- queueStorage?: StorageBackend;
498
- /** Prefix for storage keys. Default `reopt_`. */
499
- storagePrefix?: string;
500
- /**
501
- * Transport override. Tests hand in a recording function so a Playwright
502
- * spec can assert on the exact payload the SDK built, without intercepting
503
- * the network. Defaults to the page's `fetch` (captured at init, before the
504
- * tracing patch, so the SDK's own requests are never tagged twice).
505
- */
506
- fetch?: FetchLike;
507
- debug?: boolean;
508
- }
509
- interface ResolvedCaptureConfig {
510
- pageview: boolean;
511
- pageleave: boolean;
512
- scrollDepth: boolean;
513
- exceptions: boolean;
514
- }
515
-
516
- interface IdentityStore {
517
- readonly kind: Exclude<IdentityStorageKind, "auto">;
518
- readDevice(): DeviceCookieState | null;
519
- writeDevice(state: DeviceCookieState): void;
520
- clearDevice(): void;
521
- readConsent(): ConsentCookieState | null;
522
- writeConsent(state: ConsentCookieState): void;
523
- /** Engine-facing backend for the consent key, so consent decisions land in the same place. */
524
- consentBackend(): StorageBackend;
525
- }
526
-
527
- interface ReoptClientDefaults {
528
- /** Whether `init()` sends the first `$pageview`. The Next entry says no. */
529
- pageview: boolean;
530
- }
531
- /**
532
- * The browser client: the shared engine plus everything that only makes
533
- * sense in a document — cookie identity, tracing headers, page leave,
534
- * scroll depth, exception capture, and a clock corrected against the
535
- * server's.
536
- */
537
- declare class ReoptClient extends ReoptCore {
538
- readonly writeKey: string;
539
- readonly capture: ResolvedCaptureConfig;
540
- private readonly store;
541
- private readonly pageLeave;
542
- private readonly scroll;
543
- private readonly uninstallers;
544
- private torndown;
545
- private readonly session;
546
- private readonly optedOut;
547
- private readonly normalize;
548
- /** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
549
- readonly disabled: boolean;
550
- constructor(config: ReoptClientConfig, defaults?: ReoptClientDefaults);
551
- /** Which store identity ended up in — `cookie`, `localStorage` or `memory`. */
552
- get identityStorage(): IdentityStore["kind"];
553
- pageView(options?: PageViewOptions): QueueResult;
554
- setConsent(category: ConsentCategory, allowed: boolean): void;
555
- setAllConsent(allowed: boolean): void;
556
- replaceConsentState(state: Record<string, boolean>): void;
557
- /**
558
- * Refusing `analytics` removes the stored identity (the proxy does the
559
- * same on its side); granting it again writes the current device through
560
- * so the visit is attributable from that point on.
561
- */
562
- private syncOptOut;
563
- identify(options: IdentifyOptions): QueueResult;
564
- /** Feed a Web Vitals metric (from `next/web-vitals` or the `web-vitals` package). */
565
- captureWebVital(metric: WebVitalMetric): QueueResult;
566
- /** The page's path through `normalizePath`, for events the SDK stamps itself. */
567
- private currentPath;
568
- /** Report an error you caught yourself. */
569
- captureException(error: unknown, properties?: Record<string, unknown>): QueueResult;
570
- private trackException;
571
- private emitPageLeave;
572
- /**
573
- * Log out: forget the profile and the queue, and become a new device.
574
- * On a shared computer the next person must not inherit this one's
575
- * history.
576
- */
577
- reset(): void;
578
- close(): Promise<FlushResult>;
579
- }
580
-
581
- export { type BatchConfig as B, type ConsentCategory as C, type DecrementOptions as D, type EventIdentity as E, type FlushResult as F, type IdentifyOptions as I, type NormalizePath as N, type PageViewOptions as P, type QueueResult as Q, ReoptClient as R, type StorageBackend as S, type TrackEventOptions as T, type UTMParams as U, type WebVitalMetric as W, type ReoptClientConfig as a, type ReoptClientDefaults as b, type IncrementOptions as c, type CaptureConfig as d, type CircuitBreakerConfig as e, type ConsentConfig as f, type EventPayload as g, type FetchInit as h, type FetchLike as i, type FetchResponseLike as j, type IdentityConfig as k, type IdentityStorageKind as l, type QueueDropReason as m, type RetryConfig as n, type WebVitalProperties as o };
@@ -1,9 +0,0 @@
1
- import {
2
- describeError,
3
- installExceptionCapture
4
- } from "./chunk-4MTDZBRS.js";
5
- export {
6
- describeError,
7
- installExceptionCapture
8
- };
9
- //# sourceMappingURL=exceptions-NQHZUDYO.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,91 +0,0 @@
1
- // src/identity/tracing.ts
2
- import { DEVICE_ID_HEADER } from "@reopt-ai/data-contract/identity";
3
- function hostOf(input) {
4
- try {
5
- const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
6
- return new URL(url, location.href).hostname;
7
- } catch {
8
- return null;
9
- }
10
- }
11
- function installTracingHeaders(options) {
12
- if (typeof window === "undefined") return () => {
13
- };
14
- const holder = window;
15
- if (holder.__reoptTracing) {
16
- const shared2 = holder.__reoptTracing;
17
- shared2.refs += 1;
18
- return () => {
19
- shared2.refs -= 1;
20
- if (shared2.refs === 0) shared2.uninstall();
21
- };
22
- }
23
- const hosts = new Set(options.hosts);
24
- const shouldTag = (input) => {
25
- const host = hostOf(input);
26
- return host !== null && hosts.has(host);
27
- };
28
- const originalFetch = window.fetch;
29
- const patchedFetch = (input, init) => {
30
- if (!shouldTag(input)) return originalFetch.call(window, input, init);
31
- const deviceId = options.getDeviceId();
32
- if (!deviceId) return originalFetch.call(window, input, init);
33
- try {
34
- if (input instanceof Request && !init) {
35
- const request = new Request(input);
36
- request.headers.set(DEVICE_ID_HEADER, deviceId);
37
- return originalFetch.call(window, request);
38
- }
39
- const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
40
- headers.set(DEVICE_ID_HEADER, deviceId);
41
- return originalFetch.call(window, input, { ...init, headers });
42
- } catch {
43
- return originalFetch.call(window, input, init);
44
- }
45
- };
46
- window.fetch = patchedFetch;
47
- const XHR = window.XMLHttpRequest;
48
- const originalOpen = XHR?.prototype.open;
49
- const originalSend = XHR?.prototype.send;
50
- const tagged = /* @__PURE__ */ new WeakSet();
51
- let patchedOpen;
52
- let patchedSend;
53
- if (XHR && originalOpen && originalSend) {
54
- XHR.prototype.open = function(method, url, ...rest) {
55
- if (shouldTag(typeof url === "string" ? url : url.href)) tagged.add(this);
56
- return originalOpen.call(this, method, url, ...rest);
57
- };
58
- XHR.prototype.send = function(body) {
59
- if (tagged.has(this)) {
60
- const deviceId = options.getDeviceId();
61
- if (deviceId) {
62
- try {
63
- this.setRequestHeader(DEVICE_ID_HEADER, deviceId);
64
- } catch {
65
- }
66
- }
67
- }
68
- return originalSend.call(this, body);
69
- };
70
- patchedOpen = XHR.prototype.open;
71
- patchedSend = XHR.prototype.send;
72
- }
73
- const uninstall = () => {
74
- if (window.fetch === patchedFetch) window.fetch = originalFetch;
75
- if (XHR && originalOpen && originalSend) {
76
- if (XHR.prototype.open === patchedOpen) XHR.prototype.open = originalOpen;
77
- if (XHR.prototype.send === patchedSend) XHR.prototype.send = originalSend;
78
- }
79
- delete holder.__reoptTracing;
80
- };
81
- const shared = { refs: 1, uninstall };
82
- holder.__reoptTracing = shared;
83
- return () => {
84
- shared.refs -= 1;
85
- if (shared.refs === 0) shared.uninstall();
86
- };
87
- }
88
- export {
89
- installTracingHeaders
90
- };
91
- //# sourceMappingURL=tracing-LC3NZND7.js.map