@reopt-ai/data-sdk-client 0.1.1 → 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-g75DV57n.js';
4
- export { C as CaptureConfig, I as IdentityConfig, c as IdentityStorageKind, N as NormalizePath, d as WebVitalProperties } from './client-g75DV57n.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 CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  forgetClient,
5
5
  getClient,
6
6
  getOrCreateClient
7
- } from "./chunk-BIR7OFR3.js";
7
+ } from "./chunk-SRHWNG2G.js";
8
8
  import "./chunk-4MTDZBRS.js";
9
9
 
10
10
  // src/index.ts
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.cjs CHANGED
@@ -814,10 +814,13 @@ function readIngestCounts(rawBody) {
814
814
  if (!record || record.status !== "ok" && record.status !== "accepted" || !count(record.accepted) || !count(record.duplicates) || !Array.isArray(record.rejected)) {
815
815
  throw new TransportError("Track response did not match contract: unexpected shape", 409, true);
816
816
  }
817
+ const session = record.session;
818
+ const credential = session && typeof session.id === "string" && typeof session.token === "string" ? { id: session.id, token: session.token } : void 0;
817
819
  return {
818
820
  accepted: record.accepted,
819
821
  duplicates: record.duplicates,
820
- rejected: record.rejected.length
822
+ rejected: record.rejected.length,
823
+ ...credential ? { session: credential } : {}
821
824
  };
822
825
  }
823
826
  function resolveBaseUrl(value) {
@@ -875,7 +878,11 @@ function createTransport(options) {
875
878
  if (counts.accepted + counts.duplicates + counts.rejected !== batch.length) {
876
879
  throw new TransportError("Track response counts do not reconcile with the submitted batch", 409, true);
877
880
  }
878
- return { sent: counts.accepted + counts.duplicates, failed: counts.rejected };
881
+ return {
882
+ sent: counts.accepted + counts.duplicates,
883
+ failed: counts.rejected,
884
+ ...counts.session ? { session: counts.session } : {}
885
+ };
879
886
  };
880
887
  return { url, headers, send };
881
888
  }
@@ -1185,6 +1192,9 @@ var ReoptCore = class {
1185
1192
  onRetry: (attempt, waitMs) => this.log("retry", attempt, Math.round(waitMs))
1186
1193
  });
1187
1194
  this.log("flushed", delivery.sent, delivery.failed);
1195
+ if (delivery.session && !batch[0]?.identity) {
1196
+ this.runtime.onSession?.(delivery.session);
1197
+ }
1188
1198
  if (this.breaker.getState() === "half-open") this.log("breaker closed");
1189
1199
  this.breaker.recordSuccess();
1190
1200
  this.queue.settle();
@@ -1428,13 +1438,14 @@ function cookiesAvailable() {
1428
1438
 
1429
1439
  // src/identity/device.ts
1430
1440
  var LEGACY_DEVICE_KEY = "device_id";
1431
- function localStorageOrNull() {
1441
+ function localStorageBackend() {
1432
1442
  try {
1433
1443
  if (typeof window === "undefined" || !window.localStorage) return null;
1444
+ const storage = window.localStorage;
1434
1445
  const probe = "reopt_probe";
1435
- window.localStorage.setItem(probe, "1");
1436
- window.localStorage.removeItem(probe);
1437
- return window.localStorage;
1446
+ storage.setItem(probe, "1");
1447
+ storage.removeItem(probe);
1448
+ return storage;
1438
1449
  } catch {
1439
1450
  return null;
1440
1451
  }
@@ -1473,7 +1484,7 @@ function createIdentityStore(writeKey, config) {
1473
1484
  if (kind === "cookie" || kind === "auto" && cookiesAvailable()) {
1474
1485
  return makeStore("cookie", writeKey, cookieBackend(cookie));
1475
1486
  }
1476
- const local = kind === "memory" ? null : localStorageOrNull();
1487
+ const local = kind === "memory" ? null : localStorageBackend();
1477
1488
  if (local) return makeStore("localStorage", writeKey, local);
1478
1489
  return makeStore("memory", writeKey, memoryStorage());
1479
1490
  }
@@ -1484,7 +1495,7 @@ function resolveDeviceId(store, bootstrapDeviceId, storagePrefix) {
1484
1495
  store.writeDevice({ deviceId: bootstrapDeviceId });
1485
1496
  return { deviceId: bootstrapDeviceId, source: "bootstrap" };
1486
1497
  }
1487
- const local = localStorageOrNull();
1498
+ const local = localStorageBackend();
1488
1499
  const legacy = local?.getItem(`${storagePrefix}${LEGACY_DEVICE_KEY}`);
1489
1500
  if ((0, import_identity3.isValidIdentityId)(legacy)) {
1490
1501
  store.writeDevice({ deviceId: legacy });
@@ -1504,19 +1515,6 @@ function regenerateDeviceId(store) {
1504
1515
  // src/client.ts
1505
1516
  var CLOCK_SKEW_THRESHOLD_MS = 3e4;
1506
1517
  var MAX_CLOCK_SKEW_MS = 24 * 60 * 60 * 1e3;
1507
- function localStorageBackend() {
1508
- try {
1509
- if (typeof window === "undefined" || !window.localStorage) return null;
1510
- const storage = window.localStorage;
1511
- return {
1512
- getItem: (key) => storage.getItem(key),
1513
- setItem: (key, value) => storage.setItem(key, value),
1514
- removeItem: (key) => storage.removeItem(key)
1515
- };
1516
- } catch {
1517
- return null;
1518
- }
1519
- }
1520
1518
  function routedStorage(consentKey, consent, rest) {
1521
1519
  const pick = (key) => key === consentKey ? consent : rest;
1522
1520
  return {
@@ -1557,6 +1555,7 @@ var ReoptClient = class extends ReoptCore {
1557
1555
  scroll;
1558
1556
  uninstallers = [];
1559
1557
  torndown = false;
1558
+ session;
1560
1559
  normalize;
1561
1560
  /** True when `writeKey` or `baseUrl` was missing: every call is a silent no-op. */
1562
1561
  disabled;
@@ -1573,8 +1572,15 @@ var ReoptClient = class extends ReoptCore {
1573
1572
  const queueStorage = disabled ? memoryStorage() : config.queueStorage ?? localStorageBackend() ?? memoryStorage();
1574
1573
  const transportFetch = config.fetch ?? (typeof window !== "undefined" ? window.fetch.bind(window) : void 0);
1575
1574
  const box = {};
1575
+ const session = { header: store.readDevice()?.sessionId ?? null };
1576
1576
  const runtime = {
1577
1577
  deviceId: identity.deviceId,
1578
+ getSessionId: () => (0, import_identity5.parseSessionHeader)(session.header) ? session.header : null,
1579
+ onSession: (credential) => {
1580
+ session.header = (0, import_identity5.formatSessionHeader)(credential);
1581
+ const current = store.readDevice();
1582
+ store.writeDevice({ ...current, deviceId: current?.deviceId ?? identity.deviceId, sessionId: session.header });
1583
+ },
1578
1584
  storage: routedStorage(`${storagePrefix}consent`, store.consentBackend(), queueStorage),
1579
1585
  now,
1580
1586
  fetch: transportFetch,
@@ -1612,6 +1618,7 @@ var ReoptClient = class extends ReoptCore {
1612
1618
  });
1613
1619
  this.writeKey = config.writeKey;
1614
1620
  this.disabled = disabled;
1621
+ this.session = session;
1615
1622
  this.normalize = config.normalizePath;
1616
1623
  this.store = store;
1617
1624
  this.capture = resolveCapture(config.capture, defaults.pageview);
@@ -1707,6 +1714,7 @@ var ReoptClient = class extends ReoptCore {
1707
1714
  */
1708
1715
  reset() {
1709
1716
  super.reset();
1717
+ this.session.header = null;
1710
1718
  this.store.writeDevice({ deviceId: this.getDeviceId() });
1711
1719
  }
1712
1720
  async close() {