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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { UTMParams, QueueResult, FlushResult, DecrementOptions, ConsentCategory, IdentifyOptions, IncrementOptions, PageViewOptions, TrackEventOptions } from '@reopt-ai/data-sdk-core';
2
- export { BatchConfig, CircuitBreakerConfig, ConsentCategory, ConsentConfig, DecrementOptions, EventPayload, FlushResult, IdentifyOptions, IncrementOptions, PageViewOptions, QueueDropReason, QueueResult, RetryConfig, StorageBackend, TrackEventOptions, UTMParams } from '@reopt-ai/data-sdk-core';
3
- import { R as ReoptClient, a as ReoptClientConfig, b as ReoptClientDefaults, W as WebVitalMetric } from './client-B6gFgjju.js';
4
- export { C as CaptureConfig, I as IdentityConfig, c as IdentityStorageKind, N as NormalizePath, d as WebVitalProperties } from './client-B6gFgjju.js';
1
+ import { R as ReoptClient, a as ReoptClientConfig, b as ReoptClientDefaults, U as UTMParams, Q as QueueResult, W as WebVitalMetric, F as FlushResult, D as DecrementOptions, C as ConsentCategory, I as IdentifyOptions, c as IncrementOptions, P as PageViewOptions, T as TrackEventOptions } from './client-CW9DfTlm.js';
2
+ export { B as BatchConfig, d as CaptureConfig, e as CircuitBreakerConfig, f as ConsentConfig, E as EventIdentity, g as EventPayload, h as FetchInit, i as FetchLike, j as FetchResponseLike, k as IdentityConfig, l as IdentityStorageKind, N as NormalizePath, m as QueueDropReason, n as RetryConfig, S as StorageBackend, o as WebVitalProperties } from './client-CW9DfTlm.js';
5
3
  export { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
6
4
 
7
5
  /**
@@ -80,4 +78,4 @@ declare function setAllConsent(allowed: boolean): void;
80
78
  declare function pauseTracking(): void;
81
79
  declare function resumeTracking(): void;
82
80
 
83
- export { type ExceptionProperties, type PageLeaveProperties, ReoptClient, ReoptClientConfig, WebVitalMetric, 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 };
81
+ export { ConsentCategory, DecrementOptions, type ExceptionProperties, FlushResult, IdentifyOptions, IncrementOptions, type PageLeaveProperties, PageViewOptions, QueueResult, ReoptClient, ReoptClientConfig, TrackEventOptions, UTMParams, WebVitalMetric, 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 };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"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/exceptions.js\";\nexport type { PageLeaveProperties } from \"./capture/pageleave.js\";\nexport type {\n CaptureConfig,\n IdentityConfig,\n IdentityStorageKind,\n NormalizePath,\n ReoptBootstrap,\n ReoptClientConfig,\n} from \"./config.js\";\nexport type {\n BatchConfig,\n CircuitBreakerConfig,\n ConsentCategory,\n ConsentConfig,\n DecrementOptions,\n EventPayload,\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":";;;;;;;;;;AA2DO,SAAS,KAAK,QAAwC;AAC3D,SAAO,kBAAkB,MAAM;AACjC;AAGO,SAAS,cAAkC;AAChD,SAAO,UAAU;AACnB;AAEA,SAAS,UAA8B;AACrC,QAAM,SAAS,UAAU;AACzB,MAAI,CAAC,OAAQ,SAAQ,KAAK,kDAA6C;AACvE,SAAO;AACT;AAGA,IAAM,SAAS,CACb,aACA,SACO,OAAO,gBAAgB,WAAW,cAAe,EAAE,WAAW,aAAa,GAAG,KAAK;AAIrF,SAAS,MACd,eACA,YACyB;AACzB,SAAO,QAAQ,GAAG,MAAM,OAAO,kBAAkB,WAAW,EAAE,MAAM,eAAe,WAAW,IAAI,aAAa;AACjH;AAIO,SAAS,SACd,aACA,YACyB;AACzB,SAAO,QAAQ,GAAG,SAAS,OAAwB,aAAa,EAAE,WAAW,CAAC,CAAC;AACjF;AAIO,SAAS,UACd,aACA,UACA,OACyB;AACzB,SAAO,QAAQ,GAAG,UAAU,OAAyB,aAAa,EAAE,UAAU,YAAY,IAAI,MAAM,CAAC,CAAC;AACxG;AAIO,SAAS,UACd,aACA,UACA,OACyB;AACzB,SAAO,QAAQ,GAAG,UAAU,OAAyB,aAAa,EAAE,UAAU,YAAY,IAAI,MAAM,CAAC,CAAC;AACxG;AAEO,SAAS,SAAS,SAAoD;AAC3E,SAAO,QAAQ,GAAG,SAAS,OAAO;AACpC;AAEO,SAAS,WAAW,YAAoB,YAA+D;AAC5G,SAAO,QAAQ,GAAG,WAAW,YAAY,UAAU;AACrD;AAEO,SAAS,gBAAgB,QAAiD;AAC/E,SAAO,QAAQ,GAAG,gBAAgB,MAAM;AAC1C;AAEO,SAAS,iBAAiB,OAAgB,YAA+D;AAC9G,SAAO,QAAQ,GAAG,iBAAiB,OAAO,UAAU;AACtD;AAOO,SAAS,cAA6B;AAC3C,QAAM,SAAS,UAAU;AACzB,SAAO,UAAU,CAAC,OAAO,WAAW,OAAO,YAAY,IAAI;AAC7D;AAGO,SAAS,SAAS,YAA2C;AAClE,UAAQ,GAAG,SAAS,UAAU;AAChC;AAEO,SAAS,cAAc,MAAsB;AAClD,UAAQ,GAAG,WAAW,GAAG,IAAI;AAC/B;AAEO,SAAS,aAAa,WAAyC;AACpE,UAAQ,GAAG,aAAa,SAAS;AACnC;AAEO,SAAS,QAAc;AAC5B,YAAU,GAAG,MAAM;AACrB;AAEO,SAAS,QAA0C;AACxD,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,OAAO,MAAM,IAAI,QAAQ,QAAQ,MAAS;AAC5D;AAGA,eAAsB,QAA0C;AAC9D,QAAM,SAAS,UAAU;AACzB,MAAI,CAAC,OAAQ,QAAO;AACpB,eAAa,MAAM;AACnB,SAAO,OAAO,MAAM;AACtB;AAEO,SAAS,WAAW,UAA2B,SAAwB;AAC5E,UAAQ,GAAG,WAAW,UAAU,OAAO;AACzC;AAEO,SAAS,WAAW,UAAoC;AAC7D,SAAO,QAAQ,GAAG,WAAW,QAAQ,KAAK;AAC5C;AAEO,SAAS,cAAc,SAAwB;AACpD,UAAQ,GAAG,cAAc,OAAO;AAClC;AAEO,SAAS,gBAAsB;AACpC,UAAQ,GAAG,cAAc;AAC3B;AAEO,SAAS,iBAAuB;AACrC,UAAQ,GAAG,eAAe;AAC5B;","names":[]}
1
+ {"version":3,"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/exceptions.js\";\nexport type { PageLeaveProperties } from \"./capture/pageleave.js\";\nexport type {\n CaptureConfig,\n IdentityConfig,\n IdentityStorageKind,\n NormalizePath,\n ReoptBootstrap,\n ReoptClientConfig,\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":";;;;;;;;;;AA+DO,SAAS,KAAK,QAAwC;AAC3D,SAAO,kBAAkB,MAAM;AACjC;AAGO,SAAS,cAAkC;AAChD,SAAO,UAAU;AACnB;AAEA,SAAS,UAA8B;AACrC,QAAM,SAAS,UAAU;AACzB,MAAI,CAAC,OAAQ,SAAQ,KAAK,kDAA6C;AACvE,SAAO;AACT;AAGA,IAAM,SAAS,CACb,aACA,SACO,OAAO,gBAAgB,WAAW,cAAe,EAAE,WAAW,aAAa,GAAG,KAAK;AAIrF,SAAS,MACd,eACA,YACyB;AACzB,SAAO,QAAQ,GAAG,MAAM,OAAO,kBAAkB,WAAW,EAAE,MAAM,eAAe,WAAW,IAAI,aAAa;AACjH;AAIO,SAAS,SACd,aACA,YACyB;AACzB,SAAO,QAAQ,GAAG,SAAS,OAAwB,aAAa,EAAE,WAAW,CAAC,CAAC;AACjF;AAIO,SAAS,UACd,aACA,UACA,OACyB;AACzB,SAAO,QAAQ,GAAG,UAAU,OAAyB,aAAa,EAAE,UAAU,YAAY,IAAI,MAAM,CAAC,CAAC;AACxG;AAIO,SAAS,UACd,aACA,UACA,OACyB;AACzB,SAAO,QAAQ,GAAG,UAAU,OAAyB,aAAa,EAAE,UAAU,YAAY,IAAI,MAAM,CAAC,CAAC;AACxG;AAEO,SAAS,SAAS,SAAoD;AAC3E,SAAO,QAAQ,GAAG,SAAS,OAAO;AACpC;AAEO,SAAS,WAAW,YAAoB,YAA+D;AAC5G,SAAO,QAAQ,GAAG,WAAW,YAAY,UAAU;AACrD;AAEO,SAAS,gBAAgB,QAAiD;AAC/E,SAAO,QAAQ,GAAG,gBAAgB,MAAM;AAC1C;AAEO,SAAS,iBAAiB,OAAgB,YAA+D;AAC9G,SAAO,QAAQ,GAAG,iBAAiB,OAAO,UAAU;AACtD;AAOO,SAAS,cAA6B;AAC3C,QAAM,SAAS,UAAU;AACzB,SAAO,UAAU,CAAC,OAAO,WAAW,OAAO,YAAY,IAAI;AAC7D;AAGO,SAAS,SAAS,YAA2C;AAClE,UAAQ,GAAG,SAAS,UAAU;AAChC;AAEO,SAAS,cAAc,MAAsB;AAClD,UAAQ,GAAG,WAAW,GAAG,IAAI;AAC/B;AAEO,SAAS,aAAa,WAAyC;AACpE,UAAQ,GAAG,aAAa,SAAS;AACnC;AAEO,SAAS,QAAc;AAC5B,YAAU,GAAG,MAAM;AACrB;AAEO,SAAS,QAA0C;AACxD,QAAM,SAAS,UAAU;AACzB,SAAO,SAAS,OAAO,MAAM,IAAI,QAAQ,QAAQ,MAAS;AAC5D;AAGA,eAAsB,QAA0C;AAC9D,QAAM,SAAS,UAAU;AACzB,MAAI,CAAC,OAAQ,QAAO;AACpB,eAAa,MAAM;AACnB,SAAO,OAAO,MAAM;AACtB;AAEO,SAAS,WAAW,UAA2B,SAAwB;AAC5E,UAAQ,GAAG,WAAW,UAAU,OAAO;AACzC;AAEO,SAAS,WAAW,UAAoC;AAC7D,SAAO,QAAQ,GAAG,WAAW,QAAQ,KAAK;AAC5C;AAEO,SAAS,cAAc,SAAwB;AACpD,UAAQ,GAAG,cAAc,OAAO;AAClC;AAEO,SAAS,gBAAsB;AACpC,UAAQ,GAAG,cAAc;AAC3B;AAEO,SAAS,iBAAuB;AACrC,UAAQ,GAAG,eAAe;AAC5B;","names":[]}
package/dist/next.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import * as react from 'react';
2
- export { R as ReoptClient, a as ReoptClientConfig, W as WebVitalMetric } from './client-B6gFgjju.js';
2
+ export { R as ReoptClient, a as ReoptClientConfig, W as WebVitalMetric } from './client-CW9DfTlm.js';
3
3
  import { ReoptProviderProps } from './react.js';
4
4
  export { ReoptContextValue, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount } from './react.js';
5
5
  export { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
6
- import '@reopt-ai/data-sdk-core';
7
6
 
8
7
  /**
9
8
  * `ReoptProvider` for the App Router. Identical to the React one except
package/dist/react.d.ts CHANGED
@@ -2,9 +2,7 @@ import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
3
  import { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
4
4
  export { ReoptBootstrap } from '@reopt-ai/data-contract/identity';
5
- import { TrackEventOptions, QueueResult, IdentifyOptions, IncrementOptions, DecrementOptions, PageViewOptions, FlushResult, ConsentCategory } from '@reopt-ai/data-sdk-core';
6
- export { ConsentCategory, DecrementOptions, FlushResult, IdentifyOptions, IncrementOptions, PageViewOptions, QueueResult, TrackEventOptions } from '@reopt-ai/data-sdk-core';
7
- import { R as ReoptClient, W as WebVitalMetric, a as ReoptClientConfig } from './client-B6gFgjju.js';
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-CW9DfTlm.js';
8
6
 
9
7
  interface ReoptContextValue {
10
8
  /** `null` during server rendering and before hydration. */
@@ -73,4 +71,4 @@ declare function useTrackOnMount(name: string, properties?: Record<string, unkno
73
71
  /** Sends one `$pageview` on mount with the options current at that moment. */
74
72
  declare function usePageViewOnMount(options?: PageViewOptions): void;
75
73
 
76
- export { ReoptClient, ReoptClientConfig, type ReoptContextValue, ReoptProvider, type ReoptProviderProps, WebVitalMetric, useConsent, useIdentify, usePageView, usePageViewOnMount, useReopt, useReoptClient, useTrack, useTrackOnMount };
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reopt-ai/data-sdk-client",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "reopt-data browser SDK — vanilla, React and Next.js App Router client components",
5
5
  "sideEffects": false,
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  }
52
52
  },
53
53
  "dependencies": {
54
- "@reopt-ai/data-contract": "0.6.1"
54
+ "@reopt-ai/data-contract": "0.6.2"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@testing-library/react": "^16.3.2",
@@ -1,181 +0,0 @@
1
- import { ConsentConfig, BatchConfig, RetryConfig, CircuitBreakerConfig, StorageBackend, FetchLike, ReoptCore, PageViewOptions, QueueResult, IdentifyOptions, FlushResult } from '@reopt-ai/data-sdk-core';
2
- import { ReoptBootstrap, DeviceCookieState, ConsentCookieState } from '@reopt-ai/data-contract/identity';
3
-
4
- /**
5
- * The shape `next/web-vitals`' `useReportWebVitals` and the `web-vitals`
6
- * package both produce. Declared here so the vanilla entry does not have to
7
- * import either.
8
- */
9
- interface WebVitalMetric {
10
- id: string;
11
- name: string;
12
- value: number;
13
- delta?: number;
14
- rating?: "good" | "needs-improvement" | "poor";
15
- navigationType?: string;
16
- }
17
- type WebVitalProperties = {
18
- metric_name: string;
19
- metric_id: string;
20
- value: number;
21
- delta?: number;
22
- rating?: string;
23
- navigation_type?: string;
24
- path: string;
25
- };
26
-
27
- /**
28
- * Rewrites a pathname before it is attached to an event, and may lift the
29
- * parts it removed into properties so they stay available for breakdowns:
30
- * `/workspace/8f3…/crm/customers/2a1…` → `{ path: "/workspace/:id/crm/customers/:id",
31
- * properties: { workspace_id: "8f3…" } }`.
32
- *
33
- * Applied wherever the SDK fills in a path itself — the default `$pageview`
34
- * path, `$pageleave`, `$web_vitals`, `$exception`. A `path` you pass to
35
- * `pageView()` explicitly is used as-is, so run the same function on it
36
- * yourself; two different rules would give one visit two different paths.
37
- * Must be synchronous and pure. If it throws, the raw pathname is used.
38
- */
39
- type NormalizePath = (pathname: string) => string | {
40
- path: string;
41
- properties?: Record<string, unknown>;
42
- };
43
-
44
- type IdentityStorageKind = "auto" | "cookie" | "localStorage" | "memory";
45
- interface IdentityConfig {
46
- /**
47
- * Where the device id lives. `auto` (default) prefers a cookie: Safari
48
- * expires script-written `localStorage` after seven days of inactivity,
49
- * which turns every returning visitor into a new device. A cookie the
50
- * server also reads survives that, and lets server-side events join the
51
- * same device.
52
- */
53
- storage?: IdentityStorageKind;
54
- /** Cookie `Domain`; omit for host-only. Set to share across subdomains. */
55
- cookieDomain?: string;
56
- /** Cookie lifetime. Default 400 days (the longest Chrome honours). */
57
- cookieMaxAgeSeconds?: number;
58
- }
59
- interface CaptureConfig {
60
- /**
61
- * Send `$pageview` on `init()`. Default `true` for the vanilla entry.
62
- * The Next entry sets it to `false` because `<ReoptPageView />` owns page
63
- * views there — including the first one.
64
- */
65
- pageview?: boolean;
66
- /** Send `$pageleave` with time-on-page when the page is hidden or the route changes. Default `true`. */
67
- pageleave?: boolean;
68
- /** Attach max scroll depth to `$pageleave`. Default `true`. */
69
- scrollDepth?: boolean;
70
- /** Send `$exception` for uncaught errors and unhandled rejections. Default `false`. */
71
- exceptions?: boolean;
72
- }
73
- interface ReoptClientConfig {
74
- writeKey: string;
75
- /** reopt-data origin, or the same-origin proxy prefix (e.g. `/ingest`) the Next.js proxy rewrites. */
76
- baseUrl: string;
77
- /** What the server already knows about this visitor. `null` = nothing. */
78
- bootstrap?: ReoptBootstrap | null;
79
- identity?: IdentityConfig;
80
- capture?: CaptureConfig;
81
- /**
82
- * Hosts that receive the `reopt-device-id` header on outgoing `fetch`/XHR,
83
- * so a server-side `track()` lands on the same device. `true` = the page's
84
- * own hostname. **Default: off** — the trusted path is passing
85
- * `getDeviceId()` to your server call explicitly; this patches `fetch`
86
- * and loads as a separate chunk only when enabled.
87
- */
88
- tracingHeaders?: boolean | string[];
89
- /** See {@link NormalizePath}. */
90
- normalizePath?: NormalizePath;
91
- /**
92
- * Properties attached to every event from the very first one. Same as
93
- * calling `register()` right after `init()`, except that nothing can
94
- * slip out in between: web vitals arrive from a buffered
95
- * `PerformanceObserver` and can fire the instant the client exists.
96
- * Pass the page context the server already knows here; update it on
97
- * client-side navigation with `register()`.
98
- */
99
- properties?: Record<string, unknown>;
100
- consent?: ConsentConfig;
101
- batch?: BatchConfig;
102
- retry?: RetryConfig;
103
- circuitBreaker?: CircuitBreakerConfig;
104
- /** Upper bound on queued events. Default 10 000. */
105
- maxQueueSize?: number;
106
- /** Overrides the store for the offline queue. Default `localStorage`. */
107
- queueStorage?: StorageBackend;
108
- /** Prefix for storage keys. Default `reopt_`. */
109
- storagePrefix?: string;
110
- /**
111
- * Transport override. Tests hand in a recording function so a Playwright
112
- * spec can assert on the exact payload the SDK built, without intercepting
113
- * the network. Defaults to the page's `fetch` (captured at init, before the
114
- * tracing patch, so the SDK's own requests are never tagged twice).
115
- */
116
- fetch?: FetchLike;
117
- debug?: boolean;
118
- }
119
- interface ResolvedCaptureConfig {
120
- pageview: boolean;
121
- pageleave: boolean;
122
- scrollDepth: boolean;
123
- exceptions: boolean;
124
- }
125
-
126
- interface IdentityStore {
127
- readonly kind: Exclude<IdentityStorageKind, "auto">;
128
- readDevice(): DeviceCookieState | null;
129
- writeDevice(state: DeviceCookieState): void;
130
- clearDevice(): void;
131
- readConsent(): ConsentCookieState | null;
132
- writeConsent(state: ConsentCookieState): void;
133
- /** Engine-facing backend for the consent key, so consent decisions land in the same place. */
134
- consentBackend(): StorageBackend;
135
- }
136
-
137
- interface ReoptClientDefaults {
138
- /** Whether `init()` sends the first `$pageview`. The Next entry says no. */
139
- pageview: boolean;
140
- }
141
- /**
142
- * The browser client: the shared engine plus everything that only makes
143
- * sense in a document — cookie identity, tracing headers, page leave,
144
- * scroll depth, exception capture, and a clock corrected against the
145
- * server's.
146
- */
147
- declare class ReoptClient extends ReoptCore {
148
- readonly writeKey: string;
149
- readonly capture: ResolvedCaptureConfig;
150
- private readonly store;
151
- private readonly pageLeave;
152
- private readonly scroll;
153
- private readonly uninstallers;
154
- private torndown;
155
- private readonly session;
156
- private readonly normalize;
157
- /** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
158
- readonly disabled: boolean;
159
- constructor(config: ReoptClientConfig, defaults?: ReoptClientDefaults);
160
- /** Which store identity ended up in — `cookie`, `localStorage` or `memory`. */
161
- get identityStorage(): IdentityStore["kind"];
162
- pageView(options?: PageViewOptions): QueueResult;
163
- identify(options: IdentifyOptions): QueueResult;
164
- /** Feed a Web Vitals metric (from `next/web-vitals` or the `web-vitals` package). */
165
- captureWebVital(metric: WebVitalMetric): QueueResult;
166
- /** The page's path through `normalizePath`, for events the SDK stamps itself. */
167
- private currentPath;
168
- /** Report an error you caught yourself. */
169
- captureException(error: unknown, properties?: Record<string, unknown>): QueueResult;
170
- private trackException;
171
- private emitPageLeave;
172
- /**
173
- * Log out: forget the profile and the queue, and become a new device.
174
- * On a shared computer the next person must not inherit this one's
175
- * history.
176
- */
177
- reset(): void;
178
- close(): Promise<FlushResult>;
179
- }
180
-
181
- export { type CaptureConfig as C, type IdentityConfig as I, type NormalizePath as N, ReoptClient as R, type WebVitalMetric as W, type ReoptClientConfig as a, type ReoptClientDefaults as b, type IdentityStorageKind as c, type WebVitalProperties as d };