@reopt-ai/data-sdk-client 0.4.0 → 0.5.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.
- package/README.md +50 -2
- package/dist/{client-BCrui21p.d.cts → client-BrtY8ZQB.d.cts} +72 -12
- package/dist/client-BrtY8ZQB.d.cts.map +1 -0
- package/dist/{client-B1GlWwVq.d.ts → client-BvSE7ErY.d.ts} +72 -12
- package/dist/client-BvSE7ErY.d.ts.map +1 -0
- package/dist/{exceptions-CuhGo9A5.cjs → exceptions-BPmC4TTt.cjs} +2 -2
- package/dist/exceptions-BPmC4TTt.cjs.map +1 -0
- package/dist/{exceptions-C9Fh0BIR.js → exceptions-CorACVsv.js} +2 -2
- package/dist/exceptions-CorACVsv.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/next.d.cts +1 -1
- package/dist/next.d.ts +1 -1
- package/dist/react.cjs +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/recorder-B993wv6b.js +390 -0
- package/dist/recorder-B993wv6b.js.map +1 -0
- package/dist/recorder-BSzzSd3Q.cjs +390 -0
- package/dist/recorder-BSzzSd3Q.cjs.map +1 -0
- package/dist/{registry-CGqrOtf4.cjs → registry-DR1N7wD5.cjs} +17 -4
- package/dist/registry-DR1N7wD5.cjs.map +1 -0
- package/dist/{registry-BPhiH_l9.js → registry-IzNqE02g.js} +18 -5
- package/dist/registry-IzNqE02g.js.map +1 -0
- package/package.json +7 -5
- package/dist/client-B1GlWwVq.d.ts.map +0 -1
- package/dist/client-BCrui21p.d.cts.map +0 -1
- package/dist/exceptions-C9Fh0BIR.js.map +0 -1
- package/dist/exceptions-CuhGo9A5.cjs.map +0 -1
- package/dist/registry-BPhiH_l9.js.map +0 -1
- package/dist/registry-CGqrOtf4.cjs.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["getOrCreateClient","getClient"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-sdk-client` — the browser SDK.\n *\n * This entry has no framework directive: it works from a `<script>` tag, a\n * plain SPA, or any framework. `./react` and `./next` add the components.\n *\n * The module-level functions (`track`, `identify`, …) operate on the client\n * created by `init()`. They warn and return `undefined` before `init()`, so a\n * call that runs too early is visible in the console rather than lost.\n */\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 { ReoptClient } from \"./client.js\";\nimport type { WebVitalMetric } from \"./capture/web-vitals.js\";\nimport type { ReoptClientConfig } from \"./config.js\";\nimport { forgetClient, getClient, getOrCreateClient } from \"./registry.js\";\n\nexport { ReoptClient } from \"./client.js\";\nexport { getClient, getOrCreateClient } from \"./registry.js\";\nexport { extractUTMParams } from \"./capture/utm.js\";\nexport type { WebVitalMetric, WebVitalProperties } from \"./capture/web-vitals.js\";\nexport type { ExceptionProperties } from \"./capture/
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["getOrCreateClient","getClient"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-sdk-client` — the browser SDK.\n *\n * This entry has no framework directive: it works from a `<script>` tag, a\n * plain SPA, or any framework. `./react` and `./next` add the components.\n *\n * The module-level functions (`track`, `identify`, …) operate on the client\n * created by `init()`. They warn and return `undefined` before `init()`, so a\n * call that runs too early is visible in the console rather than lost.\n */\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 { ReoptClient } from \"./client.js\";\nimport type { WebVitalMetric } from \"./capture/web-vitals.js\";\nimport type { ReoptClientConfig } from \"./config.js\";\nimport { forgetClient, getClient, getOrCreateClient } from \"./registry.js\";\n\nexport { ReoptClient } from \"./client.js\";\nexport { getClient, getOrCreateClient } from \"./registry.js\";\nexport { extractUTMParams } from \"./capture/utm.js\";\nexport type { WebVitalMetric, WebVitalProperties } from \"./capture/web-vitals.js\";\nexport type { ExceptionProperties } from \"./capture/exception-properties.js\";\nexport type { PageLeaveProperties } from \"./capture/pageleave.js\";\nexport type {\n CaptureConfig,\n SessionReplayConfig,\n IdentityConfig,\n IdentityStorageKind,\n NormalizePath,\n ReoptBootstrap,\n ReoptClientConfig,\n ReoptClientObservation,\n ReoptClientObserver,\n ReoptObservedEventType,\n} from \"./config.js\";\nexport type {\n BatchConfig,\n CircuitBreakerConfig,\n ConsentCategory,\n ConsentConfig,\n DecrementOptions,\n EventIdentity,\n EventPayload,\n FetchInit,\n FetchLike,\n FetchResponseLike,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueDropReason,\n QueueResult,\n RetryConfig,\n StorageBackend,\n TrackEventOptions,\n UTMParams,\n} from \"@reopt-ai/data-sdk-core\";\n\n/** Creates (or returns) the page's client for `config.writeKey`. */\nexport function init(config: ReoptClientConfig): ReoptClient {\n return getOrCreateClient(config);\n}\n\n/** The client created by `init()`, or `null`. */\nexport function getInstance(): ReoptClient | null {\n return getClient();\n}\n\nfunction current(): ReoptClient | null {\n const client = getClient();\n if (!client) console.warn(\"[reopt] not initialized — call init() first\");\n return client;\n}\n\n/** Normalises the `(id, …)` and `(options)` call forms the module functions accept. */\nconst withId = <T extends { profileId: string | number }>(\n idOrOptions: string | number | T,\n rest: Omit<T, \"profileId\">\n): T => (typeof idOrOptions === \"object\" ? idOrOptions : ({ profileId: idOrOptions, ...rest } as T));\n\nexport function track(options: TrackEventOptions): QueueResult | undefined;\nexport function track(name: string, properties?: Record<string, unknown>): QueueResult | undefined;\nexport function track(\n nameOrOptions: string | TrackEventOptions,\n properties?: Record<string, unknown>\n): QueueResult | undefined {\n return current()?.track(typeof nameOrOptions === \"string\" ? { name: nameOrOptions, properties } : nameOrOptions);\n}\n\nexport function identify(options: IdentifyOptions): QueueResult | undefined;\nexport function identify(profileId: string | number, properties?: Record<string, unknown>): QueueResult | undefined;\nexport function identify(\n idOrOptions: string | number | IdentifyOptions,\n properties?: Record<string, unknown>\n): QueueResult | undefined {\n return current()?.identify(withId<IdentifyOptions>(idOrOptions, { properties }));\n}\n\nexport function increment(options: IncrementOptions): QueueResult | undefined;\nexport function increment(profileId: string | number, property: string, value?: number): QueueResult | undefined;\nexport function increment(\n idOrOptions: string | number | IncrementOptions,\n property?: string,\n value?: number\n): QueueResult | undefined {\n return current()?.increment(withId<IncrementOptions>(idOrOptions, { property: property ?? \"\", value }));\n}\n\nexport function decrement(options: DecrementOptions): QueueResult | undefined;\nexport function decrement(profileId: string | number, property: string, value?: number): QueueResult | undefined;\nexport function decrement(\n idOrOptions: string | number | DecrementOptions,\n property?: string,\n value?: number\n): QueueResult | undefined {\n return current()?.decrement(withId<DecrementOptions>(idOrOptions, { property: property ?? \"\", value }));\n}\n\nexport function pageView(options?: PageViewOptions): QueueResult | undefined {\n return current()?.pageView(options);\n}\n\nexport function screenView(screenName: string, properties?: Record<string, unknown>): QueueResult | undefined {\n return current()?.screenView(screenName, properties);\n}\n\nexport function captureWebVital(metric: WebVitalMetric): QueueResult | undefined {\n return current()?.captureWebVital(metric);\n}\n\nexport function captureException(error: unknown, properties?: Record<string, unknown>): QueueResult | undefined {\n return current()?.captureException(error, properties);\n}\n\n/**\n * The device id this page is tracked under, for passing to your own server\n * calls explicitly (e.g. as a body field a route handler forwards as the\n * event's `deviceId`). `null` before `init()` or when analytics is disabled.\n */\nexport function getDeviceId(): string | null {\n const client = getClient();\n return client && !client.disabled ? client.getDeviceId() : null;\n}\n\n/** Attach `properties` to every event from now on (an event's own properties win). */\nexport function register(properties: Record<string, unknown>): void {\n current()?.register(properties);\n}\n\nexport function unregister(...keys: string[]): void {\n current()?.unregister(...keys);\n}\n\nexport function setProfileId(profileId: string | number | null): void {\n current()?.setProfileId(profileId);\n}\n\nexport function reset(): void {\n getClient()?.reset();\n}\n\nexport function flush(): Promise<FlushResult | undefined> {\n const client = getClient();\n return client ? client.flush() : Promise.resolve(undefined);\n}\n\n/** Flushes, tears down listeners, and forgets the client so `init()` starts fresh. */\nexport async function close(): Promise<FlushResult | undefined> {\n const client = getClient();\n if (!client) return undefined;\n forgetClient(client);\n return client.close();\n}\n\nexport function setConsent(category: ConsentCategory, allowed: boolean): void {\n current()?.setConsent(category, allowed);\n}\n\nexport function getConsent(category: ConsentCategory): boolean {\n return current()?.getConsent(category) ?? false;\n}\n\nexport function setAllConsent(allowed: boolean): void {\n current()?.setAllConsent(allowed);\n}\n\nexport function pauseTracking(): void {\n current()?.pauseTracking();\n}\n\nexport function resumeTracking(): void {\n current()?.resumeTracking();\n}\n"],"mappings":";;;AAmEA,SAAgB,KAAK,QAAwC;CAC3D,OAAOA,iBAAAA,kBAAkB,MAAM;AACjC;AAGA,SAAgB,cAAkC;CAChD,OAAOC,iBAAAA,UAAU;AACnB;AAEA,SAAS,UAA8B;CACrC,MAAM,SAASA,iBAAAA,UAAU;CACzB,IAAI,CAAC,QAAQ,QAAQ,KAAK,6CAA6C;CACvE,OAAO;AACT;AAGA,MAAM,UACJ,aACA,SACO,OAAO,gBAAgB,WAAW,cAAe;CAAE,WAAW;CAAa,GAAG;AAAK;AAI5F,SAAgB,MACd,eACA,YACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,MAAM,OAAO,kBAAkB,WAAW;EAAE,MAAM;EAAe;CAAW,IAAI,aAAa;AACjH;AAIA,SAAgB,SACd,aACA,YACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,SAAS,OAAwB,aAAa,EAAE,WAAW,CAAC,CAAC;AACjF;AAIA,SAAgB,UACd,aACA,UACA,OACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,UAAU,OAAyB,aAAa;EAAE,UAAU,YAAY;EAAI;CAAM,CAAC,CAAC;AACxG;AAIA,SAAgB,UACd,aACA,UACA,OACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,UAAU,OAAyB,aAAa;EAAE,UAAU,YAAY;EAAI;CAAM,CAAC,CAAC;AACxG;AAEA,SAAgB,SAAS,SAAoD;CAC3E,OAAO,QAAQ,CAAC,EAAE,SAAS,OAAO;AACpC;AAEA,SAAgB,WAAW,YAAoB,YAA+D;CAC5G,OAAO,QAAQ,CAAC,EAAE,WAAW,YAAY,UAAU;AACrD;AAEA,SAAgB,gBAAgB,QAAiD;CAC/E,OAAO,QAAQ,CAAC,EAAE,gBAAgB,MAAM;AAC1C;AAEA,SAAgB,iBAAiB,OAAgB,YAA+D;CAC9G,OAAO,QAAQ,CAAC,EAAE,iBAAiB,OAAO,UAAU;AACtD;AAOA,SAAgB,cAA6B;CAC3C,MAAM,SAASA,iBAAAA,UAAU;CACzB,OAAO,UAAU,CAAC,OAAO,WAAW,OAAO,YAAY,IAAI;AAC7D;AAGA,SAAgB,SAAS,YAA2C;CAClE,QAAQ,CAAC,EAAE,SAAS,UAAU;AAChC;AAEA,SAAgB,WAAW,GAAG,MAAsB;CAClD,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI;AAC/B;AAEA,SAAgB,aAAa,WAAyC;CACpE,QAAQ,CAAC,EAAE,aAAa,SAAS;AACnC;AAEA,SAAgB,QAAc;CAC5B,iBAAA,UAAU,CAAC,EAAE,MAAM;AACrB;AAEA,SAAgB,QAA0C;CACxD,MAAM,SAASA,iBAAAA,UAAU;CACzB,OAAO,SAAS,OAAO,MAAM,IAAI,QAAQ,QAAQ,KAAA,CAAS;AAC5D;AAGA,eAAsB,QAA0C;CAC9D,MAAM,SAASA,iBAAAA,UAAU;CACzB,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,iBAAA,aAAa,MAAM;CACnB,OAAO,OAAO,MAAM;AACtB;AAEA,SAAgB,WAAW,UAA2B,SAAwB;CAC5E,QAAQ,CAAC,EAAE,WAAW,UAAU,OAAO;AACzC;AAEA,SAAgB,WAAW,UAAoC;CAC7D,OAAO,QAAQ,CAAC,EAAE,WAAW,QAAQ,KAAK;AAC5C;AAEA,SAAgB,cAAc,SAAwB;CACpD,QAAQ,CAAC,EAAE,cAAc,OAAO;AAClC;AAEA,SAAgB,gBAAsB;CACpC,QAAQ,CAAC,EAAE,cAAc;AAC3B;AAEA,SAAgB,iBAAuB;CACrC,QAAQ,CAAC,EAAE,eAAe;AAC5B"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as PageViewOptions, C as EventPayload, D as FlushResult, E as FetchResponseLike, F as TrackEventOptions, I as UTMParams, M as QueueResult, N as RetryConfig, O as IdentifyOptions, P as StorageBackend, S as EventIdentity, T as FetchLike, _ as BatchConfig, a as IdentityConfig, b as ConsentConfig, c as ReoptBootstrap, d as ReoptClientObserver, f as ReoptObservedEventType, h as WebVitalProperties, i as CaptureConfig, j as QueueDropReason, k as IncrementOptions, l as ReoptClientConfig, m as WebVitalMetric, n as ReoptClient, o as IdentityStorageKind, p as SessionReplayConfig, r as ReoptClientDefaults, s as NormalizePath, u as ReoptClientObservation, v as CircuitBreakerConfig, w as FetchInit, x as DecrementOptions, y as ConsentCategory } from "./client-BrtY8ZQB.cjs";
|
|
2
2
|
import { ExceptionEntry } from "@reopt-ai/data-contract/events";
|
|
3
3
|
//#region src/registry.d.ts
|
|
4
4
|
/**
|
|
@@ -79,5 +79,5 @@ declare function setAllConsent(allowed: boolean): void;
|
|
|
79
79
|
declare function pauseTracking(): void;
|
|
80
80
|
declare function resumeTracking(): void;
|
|
81
81
|
//#endregion
|
|
82
|
-
export { type BatchConfig, type CaptureConfig, type CircuitBreakerConfig, type ConsentCategory, type ConsentConfig, type DecrementOptions, type EventIdentity, type EventPayload, type ExceptionProperties, type FetchInit, type FetchLike, type FetchResponseLike, type FlushResult, type IdentifyOptions, type IdentityConfig, type IdentityStorageKind, type IncrementOptions, type NormalizePath, type PageLeaveProperties, type PageViewOptions, type QueueDropReason, type QueueResult, type ReoptBootstrap, ReoptClient, type ReoptClientConfig, type ReoptClientObservation, type ReoptClientObserver, type ReoptObservedEventType, type RetryConfig, type StorageBackend, type TrackEventOptions, type UTMParams, type WebVitalMetric, type WebVitalProperties, captureException, captureWebVital, close, decrement, extractUTMParams, flush, getClient, getConsent, getDeviceId, getInstance, getOrCreateClient, identify, increment, init, pageView, pauseTracking, register, reset, resumeTracking, screenView, setAllConsent, setConsent, setProfileId, track, unregister };
|
|
82
|
+
export { type BatchConfig, type CaptureConfig, type CircuitBreakerConfig, type ConsentCategory, type ConsentConfig, type DecrementOptions, type EventIdentity, type EventPayload, type ExceptionProperties, type FetchInit, type FetchLike, type FetchResponseLike, type FlushResult, type IdentifyOptions, type IdentityConfig, type IdentityStorageKind, type IncrementOptions, type NormalizePath, type PageLeaveProperties, type PageViewOptions, type QueueDropReason, type QueueResult, type ReoptBootstrap, ReoptClient, type ReoptClientConfig, type ReoptClientObservation, type ReoptClientObserver, type ReoptObservedEventType, type RetryConfig, type SessionReplayConfig, type StorageBackend, type TrackEventOptions, type UTMParams, type WebVitalMetric, type WebVitalProperties, captureException, captureWebVital, close, decrement, extractUTMParams, flush, getClient, getConsent, getDeviceId, getInstance, getOrCreateClient, identify, increment, init, pageView, pauseTracking, register, reset, resumeTracking, screenView, setAllConsent, setConsent, setProfileId, track, unregister };
|
|
83
83
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/registry.ts","../src/capture/utm.ts","../src/capture/exception-properties.ts","../src/capture/pageleave.ts","../src/index.ts"],"mappings":";;;;;;;;iBA0BgB,kBAAkB,QAAQ,mBAAmB,WAAW,sBAAsB;iBAS9E,UAAU,oBAAoB;;;;iBC9B9B,iBAAiB,kBAA0E;;;KCQ/F;KAEA;EACV;EACA;EACA;EACA,mBAAmB;EACnB;;;;;;;;EAQA,kBAAkB;EAClB;;;;KCbU;EACV;EACA;EACA;EACA;;EAEA;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/registry.ts","../src/capture/utm.ts","../src/capture/exception-properties.ts","../src/capture/pageleave.ts","../src/index.ts"],"mappings":";;;;;;;;iBA0BgB,kBAAkB,QAAQ,mBAAmB,WAAW,sBAAsB;iBAS9E,UAAU,oBAAoB;;;;iBC9B9B,iBAAiB,kBAA0E;;;KCQ/F;KAEA;EACV;EACA;EACA;EACA,mBAAmB;EACnB;;;;;;;;EAQA,kBAAkB;EAClB;;;;KCbU;EACV;EACA;EACA;EACA;;EAEA;;;;;iBC6Cc,KAAK,QAAQ,oBAAoB;;iBAKjC,eAAe;iBAgBf,MAAM,SAAS,oBAAoB;iBACnC,MAAM,cAAc,aAAa,0BAA0B;iBAQ3D,SAAS,SAAS,kBAAkB;iBACpC,SAAS,4BAA4B,aAAa,0BAA0B;iBAQ5E,UAAU,SAAS,mBAAmB;iBACtC,UAAU,4BAA4B,kBAAkB,iBAAiB;iBASzE,UAAU,SAAS,mBAAmB;iBACtC,UAAU,4BAA4B,kBAAkB,iBAAiB;iBASzE,SAAS,UAAU,kBAAkB;iBAIrC,WAAW,oBAAoB,aAAa,0BAA0B;iBAItE,gBAAgB,QAAQ,iBAAiB;iBAIzC,iBAAiB,gBAAgB,aAAa,0BAA0B;;;;;;iBASxE;;iBAMA,SAAS,YAAY;iBAIrB,cAAc;iBAId,aAAa;iBAIb;iBAIA,SAAS,QAAQ;;iBAMX,SAAS,QAAQ;iBAOvB,WAAW,UAAU,iBAAiB;iBAItC,WAAW,UAAU;iBAIrB,cAAc;iBAId;iBAIA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as PageViewOptions, C as EventPayload, D as FlushResult, E as FetchResponseLike, F as TrackEventOptions, I as UTMParams, M as QueueResult, N as RetryConfig, O as IdentifyOptions, P as StorageBackend, S as EventIdentity, T as FetchLike, _ as BatchConfig, a as IdentityConfig, b as ConsentConfig, c as ReoptBootstrap, d as ReoptClientObserver, f as ReoptObservedEventType, h as WebVitalProperties, i as CaptureConfig, j as QueueDropReason, k as IncrementOptions, l as ReoptClientConfig, m as WebVitalMetric, n as ReoptClient, o as IdentityStorageKind, p as SessionReplayConfig, r as ReoptClientDefaults, s as NormalizePath, u as ReoptClientObservation, v as CircuitBreakerConfig, w as FetchInit, x as DecrementOptions, y as ConsentCategory } from "./client-BvSE7ErY.js";
|
|
2
2
|
import { ExceptionEntry } from "@reopt-ai/data-contract/events";
|
|
3
3
|
//#region src/registry.d.ts
|
|
4
4
|
/**
|
|
@@ -79,5 +79,5 @@ declare function setAllConsent(allowed: boolean): void;
|
|
|
79
79
|
declare function pauseTracking(): void;
|
|
80
80
|
declare function resumeTracking(): void;
|
|
81
81
|
//#endregion
|
|
82
|
-
export { type BatchConfig, type CaptureConfig, type CircuitBreakerConfig, type ConsentCategory, type ConsentConfig, type DecrementOptions, type EventIdentity, type EventPayload, type ExceptionProperties, type FetchInit, type FetchLike, type FetchResponseLike, type FlushResult, type IdentifyOptions, type IdentityConfig, type IdentityStorageKind, type IncrementOptions, type NormalizePath, type PageLeaveProperties, type PageViewOptions, type QueueDropReason, type QueueResult, type ReoptBootstrap, ReoptClient, type ReoptClientConfig, type ReoptClientObservation, type ReoptClientObserver, type ReoptObservedEventType, type RetryConfig, type StorageBackend, type TrackEventOptions, type UTMParams, type WebVitalMetric, type WebVitalProperties, captureException, captureWebVital, close, decrement, extractUTMParams, flush, getClient, getConsent, getDeviceId, getInstance, getOrCreateClient, identify, increment, init, pageView, pauseTracking, register, reset, resumeTracking, screenView, setAllConsent, setConsent, setProfileId, track, unregister };
|
|
82
|
+
export { type BatchConfig, type CaptureConfig, type CircuitBreakerConfig, type ConsentCategory, type ConsentConfig, type DecrementOptions, type EventIdentity, type EventPayload, type ExceptionProperties, type FetchInit, type FetchLike, type FetchResponseLike, type FlushResult, type IdentifyOptions, type IdentityConfig, type IdentityStorageKind, type IncrementOptions, type NormalizePath, type PageLeaveProperties, type PageViewOptions, type QueueDropReason, type QueueResult, type ReoptBootstrap, ReoptClient, type ReoptClientConfig, type ReoptClientObservation, type ReoptClientObserver, type ReoptObservedEventType, type RetryConfig, type SessionReplayConfig, type StorageBackend, type TrackEventOptions, type UTMParams, type WebVitalMetric, type WebVitalProperties, captureException, captureWebVital, close, decrement, extractUTMParams, flush, getClient, getConsent, getDeviceId, getInstance, getOrCreateClient, identify, increment, init, pageView, pauseTracking, register, reset, resumeTracking, screenView, setAllConsent, setConsent, setProfileId, track, unregister };
|
|
83
83
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/registry.ts","../src/capture/utm.ts","../src/capture/exception-properties.ts","../src/capture/pageleave.ts","../src/index.ts"],"mappings":";;;;;;;;iBA0BgB,kBAAkB,QAAQ,mBAAmB,WAAW,sBAAsB;iBAS9E,UAAU,oBAAoB;;;;iBC9B9B,iBAAiB,kBAA0E;;;KCQ/F;KAEA;EACV;EACA;EACA;EACA,mBAAmB;EACnB;;;;;;;;EAQA,kBAAkB;EAClB;;;;KCbU;EACV;EACA;EACA;EACA;;EAEA;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/registry.ts","../src/capture/utm.ts","../src/capture/exception-properties.ts","../src/capture/pageleave.ts","../src/index.ts"],"mappings":";;;;;;;;iBA0BgB,kBAAkB,QAAQ,mBAAmB,WAAW,sBAAsB;iBAS9E,UAAU,oBAAoB;;;;iBC9B9B,iBAAiB,kBAA0E;;;KCQ/F;KAEA;EACV;EACA;EACA;EACA,mBAAmB;EACnB;;;;;;;;EAQA,kBAAkB;EAClB;;;;KCbU;EACV;EACA;EACA;EACA;;EAEA;;;;;iBC6Cc,KAAK,QAAQ,oBAAoB;;iBAKjC,eAAe;iBAgBf,MAAM,SAAS,oBAAoB;iBACnC,MAAM,cAAc,aAAa,0BAA0B;iBAQ3D,SAAS,SAAS,kBAAkB;iBACpC,SAAS,4BAA4B,aAAa,0BAA0B;iBAQ5E,UAAU,SAAS,mBAAmB;iBACtC,UAAU,4BAA4B,kBAAkB,iBAAiB;iBASzE,UAAU,SAAS,mBAAmB;iBACtC,UAAU,4BAA4B,kBAAkB,iBAAiB;iBASzE,SAAS,UAAU,kBAAkB;iBAIrC,WAAW,oBAAoB,aAAa,0BAA0B;iBAItE,gBAAgB,QAAQ,iBAAiB;iBAIzC,iBAAiB,gBAAgB,aAAa,0BAA0B;;;;;;iBASxE;;iBAMA,SAAS,YAAY;iBAIrB,cAAc;iBAId,aAAa;iBAIb;iBAIA,SAAS,QAAQ;;iBAMX,SAAS,QAAQ;iBAOvB,WAAW,UAAU,iBAAiB;iBAItC,WAAW,UAAU;iBAIrB,cAAc;iBAId;iBAIA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as extractUTMParams, i as ReoptClient, n as getClient, r as getOrCreateClient, t as forgetClient } from "./registry-
|
|
1
|
+
import { a as extractUTMParams, i as ReoptClient, n as getClient, r as getOrCreateClient, t as forgetClient } from "./registry-IzNqE02g.js";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
function init(config) {
|
|
4
4
|
return getOrCreateClient(config);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-sdk-client` — the browser SDK.\n *\n * This entry has no framework directive: it works from a `<script>` tag, a\n * plain SPA, or any framework. `./react` and `./next` add the components.\n *\n * The module-level functions (`track`, `identify`, …) operate on the client\n * created by `init()`. They warn and return `undefined` before `init()`, so a\n * call that runs too early is visible in the console rather than lost.\n */\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 { ReoptClient } from \"./client.js\";\nimport type { WebVitalMetric } from \"./capture/web-vitals.js\";\nimport type { ReoptClientConfig } from \"./config.js\";\nimport { forgetClient, getClient, getOrCreateClient } from \"./registry.js\";\n\nexport { ReoptClient } from \"./client.js\";\nexport { getClient, getOrCreateClient } from \"./registry.js\";\nexport { extractUTMParams } from \"./capture/utm.js\";\nexport type { WebVitalMetric, WebVitalProperties } from \"./capture/web-vitals.js\";\nexport type { ExceptionProperties } from \"./capture/
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-sdk-client` — the browser SDK.\n *\n * This entry has no framework directive: it works from a `<script>` tag, a\n * plain SPA, or any framework. `./react` and `./next` add the components.\n *\n * The module-level functions (`track`, `identify`, …) operate on the client\n * created by `init()`. They warn and return `undefined` before `init()`, so a\n * call that runs too early is visible in the console rather than lost.\n */\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 { ReoptClient } from \"./client.js\";\nimport type { WebVitalMetric } from \"./capture/web-vitals.js\";\nimport type { ReoptClientConfig } from \"./config.js\";\nimport { forgetClient, getClient, getOrCreateClient } from \"./registry.js\";\n\nexport { ReoptClient } from \"./client.js\";\nexport { getClient, getOrCreateClient } from \"./registry.js\";\nexport { extractUTMParams } from \"./capture/utm.js\";\nexport type { WebVitalMetric, WebVitalProperties } from \"./capture/web-vitals.js\";\nexport type { ExceptionProperties } from \"./capture/exception-properties.js\";\nexport type { PageLeaveProperties } from \"./capture/pageleave.js\";\nexport type {\n CaptureConfig,\n SessionReplayConfig,\n IdentityConfig,\n IdentityStorageKind,\n NormalizePath,\n ReoptBootstrap,\n ReoptClientConfig,\n ReoptClientObservation,\n ReoptClientObserver,\n ReoptObservedEventType,\n} from \"./config.js\";\nexport type {\n BatchConfig,\n CircuitBreakerConfig,\n ConsentCategory,\n ConsentConfig,\n DecrementOptions,\n EventIdentity,\n EventPayload,\n FetchInit,\n FetchLike,\n FetchResponseLike,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueDropReason,\n QueueResult,\n RetryConfig,\n StorageBackend,\n TrackEventOptions,\n UTMParams,\n} from \"@reopt-ai/data-sdk-core\";\n\n/** Creates (or returns) the page's client for `config.writeKey`. */\nexport function init(config: ReoptClientConfig): ReoptClient {\n return getOrCreateClient(config);\n}\n\n/** The client created by `init()`, or `null`. */\nexport function getInstance(): ReoptClient | null {\n return getClient();\n}\n\nfunction current(): ReoptClient | null {\n const client = getClient();\n if (!client) console.warn(\"[reopt] not initialized — call init() first\");\n return client;\n}\n\n/** Normalises the `(id, …)` and `(options)` call forms the module functions accept. */\nconst withId = <T extends { profileId: string | number }>(\n idOrOptions: string | number | T,\n rest: Omit<T, \"profileId\">\n): T => (typeof idOrOptions === \"object\" ? idOrOptions : ({ profileId: idOrOptions, ...rest } as T));\n\nexport function track(options: TrackEventOptions): QueueResult | undefined;\nexport function track(name: string, properties?: Record<string, unknown>): QueueResult | undefined;\nexport function track(\n nameOrOptions: string | TrackEventOptions,\n properties?: Record<string, unknown>\n): QueueResult | undefined {\n return current()?.track(typeof nameOrOptions === \"string\" ? { name: nameOrOptions, properties } : nameOrOptions);\n}\n\nexport function identify(options: IdentifyOptions): QueueResult | undefined;\nexport function identify(profileId: string | number, properties?: Record<string, unknown>): QueueResult | undefined;\nexport function identify(\n idOrOptions: string | number | IdentifyOptions,\n properties?: Record<string, unknown>\n): QueueResult | undefined {\n return current()?.identify(withId<IdentifyOptions>(idOrOptions, { properties }));\n}\n\nexport function increment(options: IncrementOptions): QueueResult | undefined;\nexport function increment(profileId: string | number, property: string, value?: number): QueueResult | undefined;\nexport function increment(\n idOrOptions: string | number | IncrementOptions,\n property?: string,\n value?: number\n): QueueResult | undefined {\n return current()?.increment(withId<IncrementOptions>(idOrOptions, { property: property ?? \"\", value }));\n}\n\nexport function decrement(options: DecrementOptions): QueueResult | undefined;\nexport function decrement(profileId: string | number, property: string, value?: number): QueueResult | undefined;\nexport function decrement(\n idOrOptions: string | number | DecrementOptions,\n property?: string,\n value?: number\n): QueueResult | undefined {\n return current()?.decrement(withId<DecrementOptions>(idOrOptions, { property: property ?? \"\", value }));\n}\n\nexport function pageView(options?: PageViewOptions): QueueResult | undefined {\n return current()?.pageView(options);\n}\n\nexport function screenView(screenName: string, properties?: Record<string, unknown>): QueueResult | undefined {\n return current()?.screenView(screenName, properties);\n}\n\nexport function captureWebVital(metric: WebVitalMetric): QueueResult | undefined {\n return current()?.captureWebVital(metric);\n}\n\nexport function captureException(error: unknown, properties?: Record<string, unknown>): QueueResult | undefined {\n return current()?.captureException(error, properties);\n}\n\n/**\n * The device id this page is tracked under, for passing to your own server\n * calls explicitly (e.g. as a body field a route handler forwards as the\n * event's `deviceId`). `null` before `init()` or when analytics is disabled.\n */\nexport function getDeviceId(): string | null {\n const client = getClient();\n return client && !client.disabled ? client.getDeviceId() : null;\n}\n\n/** Attach `properties` to every event from now on (an event's own properties win). */\nexport function register(properties: Record<string, unknown>): void {\n current()?.register(properties);\n}\n\nexport function unregister(...keys: string[]): void {\n current()?.unregister(...keys);\n}\n\nexport function setProfileId(profileId: string | number | null): void {\n current()?.setProfileId(profileId);\n}\n\nexport function reset(): void {\n getClient()?.reset();\n}\n\nexport function flush(): Promise<FlushResult | undefined> {\n const client = getClient();\n return client ? client.flush() : Promise.resolve(undefined);\n}\n\n/** Flushes, tears down listeners, and forgets the client so `init()` starts fresh. */\nexport async function close(): Promise<FlushResult | undefined> {\n const client = getClient();\n if (!client) return undefined;\n forgetClient(client);\n return client.close();\n}\n\nexport function setConsent(category: ConsentCategory, allowed: boolean): void {\n current()?.setConsent(category, allowed);\n}\n\nexport function getConsent(category: ConsentCategory): boolean {\n return current()?.getConsent(category) ?? false;\n}\n\nexport function setAllConsent(allowed: boolean): void {\n current()?.setAllConsent(allowed);\n}\n\nexport function pauseTracking(): void {\n current()?.pauseTracking();\n}\n\nexport function resumeTracking(): void {\n current()?.resumeTracking();\n}\n"],"mappings":";;AAmEA,SAAgB,KAAK,QAAwC;CAC3D,OAAO,kBAAkB,MAAM;AACjC;AAGA,SAAgB,cAAkC;CAChD,OAAO,UAAU;AACnB;AAEA,SAAS,UAA8B;CACrC,MAAM,SAAS,UAAU;CACzB,IAAI,CAAC,QAAQ,QAAQ,KAAK,6CAA6C;CACvE,OAAO;AACT;AAGA,MAAM,UACJ,aACA,SACO,OAAO,gBAAgB,WAAW,cAAe;CAAE,WAAW;CAAa,GAAG;AAAK;AAI5F,SAAgB,MACd,eACA,YACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,MAAM,OAAO,kBAAkB,WAAW;EAAE,MAAM;EAAe;CAAW,IAAI,aAAa;AACjH;AAIA,SAAgB,SACd,aACA,YACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,SAAS,OAAwB,aAAa,EAAE,WAAW,CAAC,CAAC;AACjF;AAIA,SAAgB,UACd,aACA,UACA,OACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,UAAU,OAAyB,aAAa;EAAE,UAAU,YAAY;EAAI;CAAM,CAAC,CAAC;AACxG;AAIA,SAAgB,UACd,aACA,UACA,OACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,UAAU,OAAyB,aAAa;EAAE,UAAU,YAAY;EAAI;CAAM,CAAC,CAAC;AACxG;AAEA,SAAgB,SAAS,SAAoD;CAC3E,OAAO,QAAQ,CAAC,EAAE,SAAS,OAAO;AACpC;AAEA,SAAgB,WAAW,YAAoB,YAA+D;CAC5G,OAAO,QAAQ,CAAC,EAAE,WAAW,YAAY,UAAU;AACrD;AAEA,SAAgB,gBAAgB,QAAiD;CAC/E,OAAO,QAAQ,CAAC,EAAE,gBAAgB,MAAM;AAC1C;AAEA,SAAgB,iBAAiB,OAAgB,YAA+D;CAC9G,OAAO,QAAQ,CAAC,EAAE,iBAAiB,OAAO,UAAU;AACtD;AAOA,SAAgB,cAA6B;CAC3C,MAAM,SAAS,UAAU;CACzB,OAAO,UAAU,CAAC,OAAO,WAAW,OAAO,YAAY,IAAI;AAC7D;AAGA,SAAgB,SAAS,YAA2C;CAClE,QAAQ,CAAC,EAAE,SAAS,UAAU;AAChC;AAEA,SAAgB,WAAW,GAAG,MAAsB;CAClD,QAAQ,CAAC,EAAE,WAAW,GAAG,IAAI;AAC/B;AAEA,SAAgB,aAAa,WAAyC;CACpE,QAAQ,CAAC,EAAE,aAAa,SAAS;AACnC;AAEA,SAAgB,QAAc;CAC5B,UAAU,CAAC,EAAE,MAAM;AACrB;AAEA,SAAgB,QAA0C;CACxD,MAAM,SAAS,UAAU;CACzB,OAAO,SAAS,OAAO,MAAM,IAAI,QAAQ,QAAQ,KAAA,CAAS;AAC5D;AAGA,eAAsB,QAA0C;CAC9D,MAAM,SAAS,UAAU;CACzB,IAAI,CAAC,QAAQ,OAAO,KAAA;CACpB,aAAa,MAAM;CACnB,OAAO,OAAO,MAAM;AACtB;AAEA,SAAgB,WAAW,UAA2B,SAAwB;CAC5E,QAAQ,CAAC,EAAE,WAAW,UAAU,OAAO;AACzC;AAEA,SAAgB,WAAW,UAAoC;CAC7D,OAAO,QAAQ,CAAC,EAAE,WAAW,QAAQ,KAAK;AAC5C;AAEA,SAAgB,cAAc,SAAwB;CACpD,QAAQ,CAAC,EAAE,cAAc,OAAO;AAClC;AAEA,SAAgB,gBAAsB;CACpC,QAAQ,CAAC,EAAE,cAAc;AAC3B;AAEA,SAAgB,iBAAuB;CACrC,QAAQ,CAAC,EAAE,eAAe;AAC5B"}
|
package/dist/next.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ReoptBootstrap, l as ReoptClientConfig,
|
|
1
|
+
import { c as ReoptBootstrap, l as ReoptClientConfig, m as WebVitalMetric, n as ReoptClient } from "./client-BrtY8ZQB.cjs";
|
|
2
2
|
import { ReoptContextValue, ReoptProviderProps, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount } from "./react.cjs";
|
|
3
3
|
//#region src/next/index.d.ts
|
|
4
4
|
/**
|
package/dist/next.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as ReoptBootstrap, l as ReoptClientConfig,
|
|
1
|
+
import { c as ReoptBootstrap, l as ReoptClientConfig, m as WebVitalMetric, n as ReoptClient } from "./client-BvSE7ErY.js";
|
|
2
2
|
import { ReoptContextValue, ReoptProviderProps, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount } from "./react.js";
|
|
3
3
|
//#region src/next/index.d.ts
|
|
4
4
|
/**
|
package/dist/react.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const require_registry = require("./registry-
|
|
3
|
+
const require_registry = require("./registry-DR1N7wD5.cjs");
|
|
4
4
|
let react = require("react");
|
|
5
5
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
6
|
//#region src/react/index.tsx
|
package/dist/react.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as PageViewOptions, D as FlushResult, F as TrackEventOptions, M as QueueResult, O as IdentifyOptions, g as ExceptionStepInput, k as IncrementOptions, l as ReoptClientConfig, m as WebVitalMetric, n as ReoptClient, t as CaptureExceptionOptions, x as DecrementOptions, y as ConsentCategory } from "./client-BrtY8ZQB.cjs";
|
|
2
2
|
import { ReoptBootstrap } from "@reopt-ai/data-contract/identity";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
//#region src/react/index.d.ts
|
package/dist/react.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as PageViewOptions, D as FlushResult, F as TrackEventOptions, M as QueueResult, O as IdentifyOptions, g as ExceptionStepInput, k as IncrementOptions, l as ReoptClientConfig, m as WebVitalMetric, n as ReoptClient, t as CaptureExceptionOptions, x as DecrementOptions, y as ConsentCategory } from "./client-BvSE7ErY.js";
|
|
2
2
|
import { ReoptBootstrap } from "@reopt-ai/data-contract/identity";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
//#region src/react/index.d.ts
|
package/dist/react.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { r as getOrCreateClient } from "./registry-
|
|
2
|
+
import { r as getOrCreateClient } from "./registry-IzNqE02g.js";
|
|
3
3
|
import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/index.tsx
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { DEVICE_ID_HEADER, WRITE_KEY_HEADER } from "@reopt-ai/data-contract/identity";
|
|
2
|
+
import { REPLAY_LIMITS, REPLAY_PATHS, REPLAY_TOKEN_HEADER, createReplayAssetResolver, sanitizeReplayEvent } from "@reopt-ai/data-contract/replay";
|
|
3
|
+
//#region src/replay/recorder.ts
|
|
4
|
+
const utf8 = (value) => new TextEncoder().encode(value).byteLength;
|
|
5
|
+
let gzipSupported = typeof CompressionStream === "function";
|
|
6
|
+
async function gzipBody(body) {
|
|
7
|
+
if (!gzipSupported) return null;
|
|
8
|
+
try {
|
|
9
|
+
const stream = new Blob([body]).stream().pipeThrough(new CompressionStream("gzip"));
|
|
10
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
11
|
+
} catch {
|
|
12
|
+
gzipSupported = false;
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
let recordingOwner = null;
|
|
17
|
+
function createClientReplay(client, config, fetch, session, canRun, path) {
|
|
18
|
+
const replay = config.sessionReplay;
|
|
19
|
+
return createReplayController({
|
|
20
|
+
writeKey: config.writeKey,
|
|
21
|
+
baseUrl: config.baseUrl,
|
|
22
|
+
fetch,
|
|
23
|
+
path,
|
|
24
|
+
allowed: () => canRun() && client.getConsent("analytics") && client.getConsent(replay.consentCategory ?? "replay"),
|
|
25
|
+
deviceId: () => client.getDeviceId(),
|
|
26
|
+
sessionId: () => session.header?.split(".")[0] ?? null
|
|
27
|
+
}, replay);
|
|
28
|
+
}
|
|
29
|
+
function createReplayController(runtime, config, load = () => import("@rrweb/record")) {
|
|
30
|
+
const owner = Symbol();
|
|
31
|
+
const asset = createReplayAssetResolver(config.publicAssets ?? [], location.href);
|
|
32
|
+
let generation = 0;
|
|
33
|
+
let active = false;
|
|
34
|
+
let starting = false;
|
|
35
|
+
let permanentlyStopped = false;
|
|
36
|
+
let pageHidden = false;
|
|
37
|
+
let grant = null;
|
|
38
|
+
let stopRecord;
|
|
39
|
+
let buffer = [];
|
|
40
|
+
let bufferBytes = 2;
|
|
41
|
+
let queue = [];
|
|
42
|
+
let queuedBytes = 0;
|
|
43
|
+
let sequence = 0;
|
|
44
|
+
let lastTimestamp = 0;
|
|
45
|
+
let totalBytes = 0;
|
|
46
|
+
let lastActivity = Date.now();
|
|
47
|
+
let capturedDevice = "";
|
|
48
|
+
let capturedSession = null;
|
|
49
|
+
let inFlight = null;
|
|
50
|
+
let requestAbort = new AbortController();
|
|
51
|
+
let retryAt = 0;
|
|
52
|
+
let attempts = 0;
|
|
53
|
+
let failures = 0;
|
|
54
|
+
let exhausted = false;
|
|
55
|
+
let rotating = false;
|
|
56
|
+
let unsampledSession = null;
|
|
57
|
+
let flushingAt = Date.now();
|
|
58
|
+
const flushInterval = Math.min(Math.max(config.flushIntervalMs ?? 2e4, 1e3), 3e4);
|
|
59
|
+
const idleTimeout = Math.min(Math.max(config.idleTimeoutMs ?? 6e4, 1e4), 3e5);
|
|
60
|
+
const shouldRun = () => !permanentlyStopped && !exhausted && !pageHidden && runtime.allowed() && !document.hidden && Date.now() - lastActivity < idleTimeout;
|
|
61
|
+
function discard() {
|
|
62
|
+
generation++;
|
|
63
|
+
active = false;
|
|
64
|
+
starting = false;
|
|
65
|
+
stopRecord?.();
|
|
66
|
+
stopRecord = void 0;
|
|
67
|
+
if (recordingOwner === owner) recordingOwner = null;
|
|
68
|
+
requestAbort.abort();
|
|
69
|
+
requestAbort = new AbortController();
|
|
70
|
+
buffer = [];
|
|
71
|
+
bufferBytes = 2;
|
|
72
|
+
queue = [];
|
|
73
|
+
queuedBytes = 0;
|
|
74
|
+
grant = null;
|
|
75
|
+
sequence = 0;
|
|
76
|
+
totalBytes = 0;
|
|
77
|
+
inFlight = null;
|
|
78
|
+
lastTimestamp = 0;
|
|
79
|
+
}
|
|
80
|
+
function fail() {
|
|
81
|
+
discard();
|
|
82
|
+
failures++;
|
|
83
|
+
if (failures >= 3) exhausted = true;
|
|
84
|
+
retryAt = Date.now() + Math.min(6e5, 3e4 * 2 ** (failures - 1));
|
|
85
|
+
}
|
|
86
|
+
function seal() {
|
|
87
|
+
if (!buffer.length || !grant) return;
|
|
88
|
+
const body = `{"version":1,"streamId":${JSON.stringify(grant.streamId)},"sequence":${sequence++},"events":[${buffer.map((item) => item.json).join(",")}]}`;
|
|
89
|
+
const bytes = utf8(body);
|
|
90
|
+
buffer = [];
|
|
91
|
+
bufferBytes = 2;
|
|
92
|
+
if (bytes > REPLAY_LIMITS.requestBytes || queuedBytes + bytes > REPLAY_LIMITS.queueBytes) {
|
|
93
|
+
fail();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
queuedBytes += bytes;
|
|
97
|
+
queue.push({
|
|
98
|
+
sequence: sequence - 1,
|
|
99
|
+
body,
|
|
100
|
+
bytes
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function emit(raw) {
|
|
104
|
+
if (!active || !shouldRun()) return;
|
|
105
|
+
try {
|
|
106
|
+
const event = sanitizeReplayEvent(raw, runtime.path(), asset);
|
|
107
|
+
if (!event) return;
|
|
108
|
+
event.timestamp = Math.max(lastTimestamp, event.timestamp + clockOffset);
|
|
109
|
+
lastTimestamp = event.timestamp;
|
|
110
|
+
const json = JSON.stringify(event);
|
|
111
|
+
const bytes = utf8(json);
|
|
112
|
+
if (bytes > REPLAY_LIMITS.eventBytes || totalBytes + bytes > REPLAY_LIMITS.streamBytes) {
|
|
113
|
+
fail();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (event.type === 4 || bufferBytes + bytes > REPLAY_LIMITS.targetChunkBytes && !(event.type === 2 && buffer.length === 1 && buffer[0]?.type === 4) || buffer.length >= REPLAY_LIMITS.chunkEvents) seal();
|
|
117
|
+
if (!active) return;
|
|
118
|
+
buffer.push({
|
|
119
|
+
type: event.type,
|
|
120
|
+
json
|
|
121
|
+
});
|
|
122
|
+
bufferBytes += bytes + 1;
|
|
123
|
+
totalBytes += bytes;
|
|
124
|
+
if (bufferBytes + queuedBytes > REPLAY_LIMITS.queueBytes) fail();
|
|
125
|
+
} catch {
|
|
126
|
+
fail();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let clockOffset = 0;
|
|
130
|
+
async function request(path, body, token) {
|
|
131
|
+
const abort = requestAbort;
|
|
132
|
+
const timeout = new AbortController();
|
|
133
|
+
const onAbort = () => timeout.abort();
|
|
134
|
+
abort.signal.addEventListener("abort", onAbort, { once: true });
|
|
135
|
+
const timer = setTimeout(() => timeout.abort(), 15e3);
|
|
136
|
+
let rejectAbort;
|
|
137
|
+
try {
|
|
138
|
+
const compressed = token ? await gzipBody(body) : null;
|
|
139
|
+
if (abort.signal.aborted) throw new Error("Replay request cancelled");
|
|
140
|
+
const pending = runtime.fetch(`${runtime.baseUrl.replace(/\/+$/, "")}${path}`, {
|
|
141
|
+
method: "POST",
|
|
142
|
+
credentials: "omit",
|
|
143
|
+
headers: {
|
|
144
|
+
"Content-Type": "application/json",
|
|
145
|
+
[WRITE_KEY_HEADER]: runtime.writeKey,
|
|
146
|
+
[DEVICE_ID_HEADER]: capturedDevice,
|
|
147
|
+
...token ? { [REPLAY_TOKEN_HEADER]: token } : {},
|
|
148
|
+
...compressed ? { "Content-Encoding": "gzip" } : {}
|
|
149
|
+
},
|
|
150
|
+
body: compressed ?? body,
|
|
151
|
+
signal: timeout.signal,
|
|
152
|
+
keepalive: (compressed ? compressed.byteLength : utf8(body)) <= REPLAY_LIMITS.keepaliveBytes
|
|
153
|
+
});
|
|
154
|
+
return await Promise.race([pending, new Promise((_resolve, reject) => {
|
|
155
|
+
rejectAbort = () => reject(new Error("Replay request cancelled"));
|
|
156
|
+
timeout.signal.addEventListener("abort", rejectAbort, { once: true });
|
|
157
|
+
if (timeout.signal.aborted) rejectAbort();
|
|
158
|
+
})]);
|
|
159
|
+
} finally {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
abort.signal.removeEventListener("abort", onAbort);
|
|
162
|
+
if (rejectAbort) timeout.signal.removeEventListener("abort", rejectAbort);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async function flush() {
|
|
166
|
+
if (!runtime.allowed()) {
|
|
167
|
+
discard();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
seal();
|
|
171
|
+
if (inFlight) return inFlight;
|
|
172
|
+
if (!grant || !queue.length || Date.now() < retryAt) return;
|
|
173
|
+
const epoch = generation;
|
|
174
|
+
const currentGrant = grant;
|
|
175
|
+
inFlight = (async () => {
|
|
176
|
+
while (queue.length && generation === epoch && runtime.allowed()) {
|
|
177
|
+
const chunk = queue[0];
|
|
178
|
+
try {
|
|
179
|
+
const response = await request(REPLAY_PATHS.chunk, chunk.body, currentGrant.token);
|
|
180
|
+
if (generation !== epoch) return;
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
if (response.status >= 500 || response.status === 429 || response.status === 408) {
|
|
183
|
+
attempts++;
|
|
184
|
+
if (attempts >= 5) {
|
|
185
|
+
fail();
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const retryAfter = Number(response.headers.get("retry-after")) * 1e3;
|
|
189
|
+
retryAt = Date.now() + Math.min(6e4, Math.max(retryAfter || 0, 1e3 * 2 ** attempts + Math.random() * 500));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
fail();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
queue.shift();
|
|
196
|
+
queuedBytes -= chunk.bytes;
|
|
197
|
+
attempts = 0;
|
|
198
|
+
failures = 0;
|
|
199
|
+
retryAt = 0;
|
|
200
|
+
} catch {
|
|
201
|
+
if (generation === epoch) {
|
|
202
|
+
attempts++;
|
|
203
|
+
if (attempts >= 5) fail();
|
|
204
|
+
else retryAt = Date.now() + Math.min(3e4, 1e3 * 2 ** attempts);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
})().finally(() => {
|
|
210
|
+
if (generation === epoch) inFlight = null;
|
|
211
|
+
});
|
|
212
|
+
return inFlight;
|
|
213
|
+
}
|
|
214
|
+
async function start() {
|
|
215
|
+
if (starting || active || rotating || recordingOwner && recordingOwner !== owner || !shouldRun() || Date.now() < retryAt || unsampledSession !== null && runtime.sessionId() === unsampledSession) return;
|
|
216
|
+
starting = true;
|
|
217
|
+
const epoch = generation;
|
|
218
|
+
capturedDevice = runtime.deviceId();
|
|
219
|
+
capturedSession = runtime.sessionId();
|
|
220
|
+
const streamId = crypto.randomUUID();
|
|
221
|
+
try {
|
|
222
|
+
const response = await request(REPLAY_PATHS.start, JSON.stringify({
|
|
223
|
+
version: 1,
|
|
224
|
+
streamId
|
|
225
|
+
}));
|
|
226
|
+
if (generation !== epoch || !shouldRun()) return;
|
|
227
|
+
if (!response.ok) {
|
|
228
|
+
retryAt = Date.now() + (response.status === 409 ? 2e3 : response.status === 403 ? 6e5 : 6e4);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const result = JSON.parse(await response.text());
|
|
232
|
+
if (generation !== epoch || !shouldRun()) return;
|
|
233
|
+
if (!result.sampled) {
|
|
234
|
+
unsampledSession = result.sessionId || runtime.sessionId();
|
|
235
|
+
retryAt = Date.now() + 6e5;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (result.version !== 1 || result.streamId !== streamId || !result.token || !Number.isFinite(result.serverTime) || !Number.isFinite(result.expiresAt)) {
|
|
239
|
+
fail();
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const { record } = await load();
|
|
243
|
+
if (generation !== epoch || !shouldRun()) return;
|
|
244
|
+
if (recordingOwner && recordingOwner !== owner) return;
|
|
245
|
+
recordingOwner = owner;
|
|
246
|
+
grant = result;
|
|
247
|
+
capturedSession = result.sessionId;
|
|
248
|
+
clockOffset = result.serverTime - Date.now();
|
|
249
|
+
active = true;
|
|
250
|
+
const blockSelector = [
|
|
251
|
+
"[data-reopt-replay-block]",
|
|
252
|
+
"[data-reopt-private]",
|
|
253
|
+
"iframe",
|
|
254
|
+
"object",
|
|
255
|
+
"embed",
|
|
256
|
+
"input[type=password]",
|
|
257
|
+
config.blockSelector
|
|
258
|
+
].filter(Boolean).join(",");
|
|
259
|
+
document.querySelector(blockSelector);
|
|
260
|
+
const stop = record({
|
|
261
|
+
emit: (event) => {
|
|
262
|
+
if (generation === epoch) emit(event);
|
|
263
|
+
},
|
|
264
|
+
maskAllInputs: true,
|
|
265
|
+
maskTextSelector: "*",
|
|
266
|
+
blockSelector,
|
|
267
|
+
blockClass: "rr-block",
|
|
268
|
+
inlineStylesheet: true,
|
|
269
|
+
collectFonts: false,
|
|
270
|
+
inlineImages: false,
|
|
271
|
+
recordCanvas: false,
|
|
272
|
+
recordCrossOriginIframes: false,
|
|
273
|
+
checkoutEveryNms: 3e5,
|
|
274
|
+
sampling: {
|
|
275
|
+
mousemove: 100,
|
|
276
|
+
scroll: 150,
|
|
277
|
+
input: "last"
|
|
278
|
+
},
|
|
279
|
+
slimDOMOptions: {
|
|
280
|
+
script: true,
|
|
281
|
+
comment: true,
|
|
282
|
+
headMetaDescKeywords: true,
|
|
283
|
+
headMetaSocial: true,
|
|
284
|
+
headMetaRobots: true,
|
|
285
|
+
headMetaHttpEquiv: true,
|
|
286
|
+
headMetaAuthorship: true,
|
|
287
|
+
headMetaVerification: true
|
|
288
|
+
},
|
|
289
|
+
errorHandler: () => {
|
|
290
|
+
queueMicrotask(() => {
|
|
291
|
+
if (generation === epoch) fail();
|
|
292
|
+
});
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
if (!active || generation !== epoch) {
|
|
297
|
+
stop?.();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
stopRecord = stop;
|
|
301
|
+
if (!stopRecord) fail();
|
|
302
|
+
else flush();
|
|
303
|
+
} catch {
|
|
304
|
+
if (generation === epoch) fail();
|
|
305
|
+
} finally {
|
|
306
|
+
if (generation === epoch) starting = false;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
function rotate() {
|
|
310
|
+
rotating = true;
|
|
311
|
+
const epoch = generation;
|
|
312
|
+
stopRecord?.();
|
|
313
|
+
stopRecord = void 0;
|
|
314
|
+
active = false;
|
|
315
|
+
flush().finally(() => {
|
|
316
|
+
rotating = false;
|
|
317
|
+
if (generation === epoch) discard();
|
|
318
|
+
sync();
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function sync() {
|
|
322
|
+
const identityChanged = (active || starting) && (capturedDevice !== runtime.deviceId() || capturedSession && runtime.sessionId() && capturedSession !== runtime.sessionId());
|
|
323
|
+
if ((!shouldRun() || identityChanged) && (active || starting || grant || queue.length || inFlight)) discard();
|
|
324
|
+
else if (grant && active && !rotating && Date.now() + clockOffset >= grant.expiresAt - 3e5) rotate();
|
|
325
|
+
if (shouldRun()) start();
|
|
326
|
+
}
|
|
327
|
+
const onActivity = () => {
|
|
328
|
+
lastActivity = Date.now();
|
|
329
|
+
sync();
|
|
330
|
+
};
|
|
331
|
+
const onHidden = () => {
|
|
332
|
+
if (document.hidden || pageHidden) {
|
|
333
|
+
stopRecord?.();
|
|
334
|
+
stopRecord = void 0;
|
|
335
|
+
active = false;
|
|
336
|
+
flush().finally(() => {
|
|
337
|
+
if (document.hidden || pageHidden) discard();
|
|
338
|
+
});
|
|
339
|
+
} else {
|
|
340
|
+
discard();
|
|
341
|
+
lastActivity = Date.now();
|
|
342
|
+
sync();
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const onPageHide = () => {
|
|
346
|
+
pageHidden = true;
|
|
347
|
+
onHidden();
|
|
348
|
+
};
|
|
349
|
+
const onPageShow = () => {
|
|
350
|
+
pageHidden = false;
|
|
351
|
+
onHidden();
|
|
352
|
+
};
|
|
353
|
+
for (const name of [
|
|
354
|
+
"pointerdown",
|
|
355
|
+
"keydown",
|
|
356
|
+
"scroll"
|
|
357
|
+
]) document.addEventListener(name, onActivity, { passive: true });
|
|
358
|
+
document.addEventListener("visibilitychange", onHidden);
|
|
359
|
+
window.addEventListener("pagehide", onPageHide);
|
|
360
|
+
window.addEventListener("pageshow", onPageShow);
|
|
361
|
+
const timer = setInterval(() => {
|
|
362
|
+
sync();
|
|
363
|
+
if (queue.length > 0 && retryAt > 0 && Date.now() >= retryAt || Date.now() - flushingAt >= flushInterval) {
|
|
364
|
+
flushingAt = Date.now();
|
|
365
|
+
flush();
|
|
366
|
+
}
|
|
367
|
+
}, 1e3);
|
|
368
|
+
sync();
|
|
369
|
+
return {
|
|
370
|
+
sync,
|
|
371
|
+
flush,
|
|
372
|
+
stop() {
|
|
373
|
+
permanentlyStopped = true;
|
|
374
|
+
discard();
|
|
375
|
+
clearInterval(timer);
|
|
376
|
+
for (const name of [
|
|
377
|
+
"pointerdown",
|
|
378
|
+
"keydown",
|
|
379
|
+
"scroll"
|
|
380
|
+
]) document.removeEventListener(name, onActivity);
|
|
381
|
+
document.removeEventListener("visibilitychange", onHidden);
|
|
382
|
+
window.removeEventListener("pagehide", onPageHide);
|
|
383
|
+
window.removeEventListener("pageshow", onPageShow);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
export { createClientReplay as default };
|
|
389
|
+
|
|
390
|
+
//# sourceMappingURL=recorder-B993wv6b.js.map
|