@wireai/activation 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +33 -4
  3. package/dist/analytics/index.d.mts +21 -3
  4. package/dist/analytics/index.d.ts +21 -3
  5. package/dist/analytics/index.js +94 -61
  6. package/dist/analytics/index.js.map +1 -1
  7. package/dist/analytics/index.mjs +91 -62
  8. package/dist/analytics/index.mjs.map +1 -1
  9. package/dist/{currentSession-DdDkprpM.d.mts → currentSession-C0_odnIW.d.mts} +101 -1
  10. package/dist/{currentSession-D0Vq7_VE.d.ts → currentSession-DdnUq2HQ.d.ts} +101 -1
  11. package/dist/index.d.mts +3 -49
  12. package/dist/index.d.ts +3 -49
  13. package/dist/index.js +50 -41
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +47 -42
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/questionnaire/index.js +10 -2
  18. package/dist/questionnaire/index.js.map +1 -1
  19. package/dist/questionnaire/index.mjs +10 -2
  20. package/dist/questionnaire/index.mjs.map +1 -1
  21. package/dist/reviews/index.d.mts +1 -1
  22. package/dist/reviews/index.d.ts +1 -1
  23. package/dist/reviews/index.js +24 -9
  24. package/dist/reviews/index.js.map +1 -1
  25. package/dist/reviews/index.mjs +24 -9
  26. package/dist/reviews/index.mjs.map +1 -1
  27. package/dist/{transport-Bzb-bcB2.d.mts → transport-BGW9uXZJ.d.mts} +0 -15
  28. package/dist/{transport-B31G0Cib.d.ts → transport-jUJd5kxu.d.ts} +0 -15
  29. package/llms.txt +8 -0
  30. package/package.json +1 -1
  31. package/src/analytics/analyticsFacade.ts +72 -9
  32. package/src/analytics/eventQueue.ts +12 -11
  33. package/src/analytics/index.ts +9 -0
  34. package/src/analytics/reportClientEvent.ts +12 -2
  35. package/src/context/userContext.ts +55 -0
  36. package/src/identity/userIdentity.ts +10 -0
  37. package/src/index.ts +5 -1
  38. package/src/questionnaire/transport.ts +5 -1
  39. package/src/reviews/decision.ts +8 -1
  40. package/src/reviews/transport.ts +6 -8
  41. package/src/session-analytics/lifecycle.ts +6 -11
  42. package/src/session-analytics/useLifecycleEvents.ts +41 -27
@@ -152,6 +152,16 @@ type ClientEvent = {
152
152
  * Lets the backend reconcile onboarding sessions to real users. Old servers ignore it.
153
153
  */
154
154
  user_id?: string;
155
+ /**
156
+ * Client-stamped epoch-ms timestamp of when the event was ENQUEUED on the device. Optional and
157
+ * ADDITIVE: the offline queue stamps it at enqueue time (see `createEventQueue`) so two otherwise
158
+ * byte-identical events fired seconds apart (a genuine repeat, e.g. the user taps "share" twice)
159
+ * are NOT collapsed by the queue's identical-JSON de-dup — while two truly simultaneous
160
+ * re-enqueues of the same instant (a redundant re-render) still share a `ts` and collapse. A raw
161
+ * `Date.now()`, never a wall-clock the server trusts (the server derives its own receive time);
162
+ * an old/strict server that does not model it simply ignores the unknown field.
163
+ */
164
+ ts?: number;
155
165
  };
156
166
  /** Where to POST. Derived from `WireOnboardingConfig` (`serverUrl` + `apiKey`). */
157
167
  type ClientEventTarget = {
@@ -676,6 +686,42 @@ declare const hashEmailFnv1a: (email: string) => string;
676
686
  * are DROPPED. Returns an object (possibly empty).
677
687
  */
678
688
  declare const namespaceExtra: (extra: Record<string, unknown> | undefined) => Record<string, string | number | boolean>;
689
+ /**
690
+ * The storage key the analytics façade persists the bound opaque `user_id` under (namespaced per
691
+ * `appId`, mirroring {@link deviceIdStorageKey}). Exported so a logout path can target it directly.
692
+ */
693
+ declare const analyticsUserIdStorageKey: (appId?: string) => string;
694
+ /**
695
+ * Return a COPY of a {@link WireUserContext} with every USER-scoped (PII / pseudonymous) field
696
+ * removed — `userId`, `userEmail`, `hashEmail`, and `extra` — while KEEPING the non-PII device-scope
697
+ * fields (`appVersion`, `deviceKey`). This is the in-memory half of logout: after it, the same
698
+ * analytics instance keeps its stable `device_key` (which groups a DEVICE, not a user) but no longer
699
+ * stamps the previous user's id/email onto events. Pure; never mutates the input.
700
+ */
701
+ declare const clearPiiFromContext: (ctx?: WireUserContext) => WireUserContext;
702
+ /** Options for {@link clearUserContext}. */
703
+ interface ClearUserContextOptions {
704
+ /** Host persistence (AsyncStorage subset) — the persisted bound `user_id` is removed from here. */
705
+ storage?: WireOnboardingStorage;
706
+ /** Tenant/app id — namespaces the persisted key (`wireai:analytics:userId:<appId>`). */
707
+ appId?: string;
708
+ }
709
+ /**
710
+ * LOGOUT primitive: purge the persisted, bound opaque `user_id` for an app so the NEXT user on a
711
+ * shared device is not silently attributed to the previous one. Removes the
712
+ * `wireai:analytics:userId:<appId>` key that the analytics façade persists and reuses across
713
+ * launches. Fire-and-forget: a missing storage or a failing adapter resolves quietly.
714
+ *
715
+ * COVERAGE. The stateful `createAnalytics(...)` instance also exposes {@link Analytics.reset}, which
716
+ * does this AND clears the in-memory binding + PII in one call — prefer it when you hold the
717
+ * instance. This standalone helper covers the `createWireActivation` / `wire` path (whose config is
718
+ * captured immutably, so it has no `reset`): call `clearUserContext({ storage, appId })` on logout,
719
+ * and RECREATE the `wire` / analytics instance without the user's `userContext` (userId/userEmail)
720
+ * so no further events carry the previous user's identity. The non-PII per-install `device_key`
721
+ * (`wireai:analytics:deviceKey:<appId>`) is intentionally left in place — it groups a device, not a
722
+ * person, and stays stable across users of the same install.
723
+ */
724
+ declare const clearUserContext: (opts?: ClearUserContextOptions) => Promise<void>;
679
725
  /** Options for {@link resolveUserContext}. */
680
726
  interface ResolveUserContextOptions {
681
727
  /**
@@ -691,6 +737,60 @@ interface ResolveUserContextOptions {
691
737
  */
692
738
  declare const resolveUserContext: (ctx?: WireUserContext, opts?: ResolveUserContextOptions) => ResolvedUserContext;
693
739
 
740
+ /** Max accepted user-id length. Longer strings are truncated (never rejected). Keep in sync
741
+ * with the server's `USER_ID_MAX_LENGTH` (analytics/events.py). */
742
+ declare const USER_ID_MAX_LENGTH = 128;
743
+ /**
744
+ * Normalize a host-supplied user id: trim, drop empty, and cap at {@link USER_ID_MAX_LENGTH}.
745
+ * Returns `undefined` for a missing/blank/non-string value so callers can `if (id)`-gate.
746
+ * PII is a host concern — this only bounds length, it does not (and cannot) detect an email.
747
+ */
748
+ declare const sanitizeUserId: (raw: unknown) => string | undefined;
749
+ /**
750
+ * A permissive email-SHAPE test (`local@domain.tld`) — NOT an RFC validator. Its ONE job is to
751
+ * catch the common integration mistake of binding a RAW EMAIL as the opaque `user_id`: that leaks
752
+ * PII into the top-level id (which the server treats as an opaque key and may surface), when the
753
+ * email belongs in the opt-in `user_context.user_email` field instead. `identify()` uses this to
754
+ * refuse an email-shaped id (with a dev warning) unless the host opts in explicitly. Trims first.
755
+ */
756
+ declare const looksLikeEmail: (value: unknown) => boolean;
757
+ /** Options for {@link identifyOnboarding}. */
758
+ type IdentifyOnboardingOptions = {
759
+ /** Tenant transport, same shape as `WireOnboardingConfig` (only these two fields are used). */
760
+ config: {
761
+ serverUrl: string;
762
+ apiKey: string;
763
+ };
764
+ /** The host's opaque user id to bind. Trimmed + capped; NO PII. */
765
+ userId: string;
766
+ /**
767
+ * The onboarding session id to bind to (the A2A contextId) — the `contextId` field carried on
768
+ * the `started`/`resumed` `onEvent`. Pass this when you captured it there. Required after the
769
+ * flow COMPLETED, since completion clears the persisted session. Wins over the storage lookup.
770
+ */
771
+ contextId?: string;
772
+ /**
773
+ * The SAME host storage you passed to `<WireOnboarding storage={…} />`. When `contextId` is
774
+ * omitted, the helper reads the persisted contextId from it (works while the session is still
775
+ * persisted — i.e. dropped or mid-flow, before completion clears it).
776
+ */
777
+ storage?: WireOnboardingStorage;
778
+ /** App id, to derive the default storage key `wireai:session:<appId>` when reading from storage. */
779
+ appId?: string;
780
+ /** Storage key override — pass the same `persistKey` you gave `<WireOnboarding>`, if any. */
781
+ persistKey?: string;
782
+ };
783
+ /**
784
+ * Attach a host user id to an onboarding session AFTER the fact (post-registration), by sending
785
+ * an `identify` client event to `/v1/events`. Resolves the contextId from an explicit
786
+ * `contextId` or, failing that, from the persisted session in the host `storage`.
787
+ *
788
+ * Fire-and-forget under the hood (never throws, never blocks onboarding). Resolves to `true`
789
+ * when an identify event was dispatched, `false` when it couldn't (no user id, no server url,
790
+ * or no resolvable contextId).
791
+ */
792
+ declare const identifyOnboarding: (opts: IdentifyOnboardingOptions) => Promise<boolean>;
793
+
694
794
  /**
695
795
  * currentSession — a tiny registry of the CURRENT per-open `session_id`.
696
796
  *
@@ -736,4 +836,4 @@ declare const getCurrentSessionId: () => string | undefined;
736
836
  /** Test-only: forget the current session id so a unit test starts from a clean registry. */
737
837
  declare const resetCurrentSessionId: () => void;
738
838
 
739
- export { type AnalyticsEvent as A, type ResolveUserContextOptions as B, type ClientEvent as C, type DeviceContext as D, type EventQueueOptions as E, type ResolvedUserContext as F, collectDeviceContext as G, hashEmailFnv1a as H, isWireScalar as I, namespaceExtra as J, resolveUserContext as K, type OnboardingResult as O, RESERVED_USER_CONTEXT_KEYS as R, type StepValidator as S, type WireUserContext as W, type ClientEventTarget as a, type ClientEventType as b, type ContextEnvelope as c, type ContextEnvelopeInput as d, type EnvelopeSource as e, type EventQueue as f, WIRE_ONBOARDING_EVENTS as g, type WireOnboardingEventName as h, buildContextEnvelope as i, createEventQueue as j, getCurrentSessionId as k, reportClientEventAwait as l, makeSessionId as m, reportClientEvents as n, reportClientEventsAwait as o, resetCurrentSessionId as p, type WireOnboardingProps as q, reportClientEvent as r, setCurrentSessionId as s, toAnalyticsEvent as t, type WireOnboardingConfig as u, type OnboardingEvent as v, type OnboardingCopy as w, type DeviceFormFactor as x, EXTRA_KEY_PREFIX as y, type OnboardingProgress as z };
839
+ export { type AnalyticsEvent as A, type OnboardingEvent as B, type ClearUserContextOptions as C, type OnboardingCopy as D, type EventQueueOptions as E, type DeviceContext as F, type DeviceFormFactor as G, EXTRA_KEY_PREFIX as H, type IdentifyOnboardingOptions as I, type OnboardingProgress as J, type ResolveUserContextOptions as K, type ResolvedUserContext as L, collectDeviceContext as M, hashEmailFnv1a as N, type OnboardingResult as O, identifyOnboarding as P, isWireScalar as Q, RESERVED_USER_CONTEXT_KEYS as R, type StepValidator as S, namespaceExtra as T, USER_ID_MAX_LENGTH as U, resolveUserContext as V, type WireUserContext as W, sanitizeUserId as X, type ClientEvent as a, type ClientEventTarget as b, type ClientEventType as c, type ContextEnvelope as d, type ContextEnvelopeInput as e, type EnvelopeSource as f, type EventQueue as g, WIRE_ONBOARDING_EVENTS as h, type WireOnboardingEventName as i, analyticsUserIdStorageKey as j, buildContextEnvelope as k, clearPiiFromContext as l, clearUserContext as m, createEventQueue as n, getCurrentSessionId as o, looksLikeEmail as p, makeSessionId as q, reportClientEvent as r, reportClientEventAwait as s, reportClientEvents as t, reportClientEventsAwait as u, resetCurrentSessionId as v, setCurrentSessionId as w, toAnalyticsEvent as x, type WireOnboardingProps as y, type WireOnboardingConfig as z };
@@ -152,6 +152,16 @@ type ClientEvent = {
152
152
  * Lets the backend reconcile onboarding sessions to real users. Old servers ignore it.
153
153
  */
154
154
  user_id?: string;
155
+ /**
156
+ * Client-stamped epoch-ms timestamp of when the event was ENQUEUED on the device. Optional and
157
+ * ADDITIVE: the offline queue stamps it at enqueue time (see `createEventQueue`) so two otherwise
158
+ * byte-identical events fired seconds apart (a genuine repeat, e.g. the user taps "share" twice)
159
+ * are NOT collapsed by the queue's identical-JSON de-dup — while two truly simultaneous
160
+ * re-enqueues of the same instant (a redundant re-render) still share a `ts` and collapse. A raw
161
+ * `Date.now()`, never a wall-clock the server trusts (the server derives its own receive time);
162
+ * an old/strict server that does not model it simply ignores the unknown field.
163
+ */
164
+ ts?: number;
155
165
  };
156
166
  /** Where to POST. Derived from `WireOnboardingConfig` (`serverUrl` + `apiKey`). */
157
167
  type ClientEventTarget = {
@@ -676,6 +686,42 @@ declare const hashEmailFnv1a: (email: string) => string;
676
686
  * are DROPPED. Returns an object (possibly empty).
677
687
  */
678
688
  declare const namespaceExtra: (extra: Record<string, unknown> | undefined) => Record<string, string | number | boolean>;
689
+ /**
690
+ * The storage key the analytics façade persists the bound opaque `user_id` under (namespaced per
691
+ * `appId`, mirroring {@link deviceIdStorageKey}). Exported so a logout path can target it directly.
692
+ */
693
+ declare const analyticsUserIdStorageKey: (appId?: string) => string;
694
+ /**
695
+ * Return a COPY of a {@link WireUserContext} with every USER-scoped (PII / pseudonymous) field
696
+ * removed — `userId`, `userEmail`, `hashEmail`, and `extra` — while KEEPING the non-PII device-scope
697
+ * fields (`appVersion`, `deviceKey`). This is the in-memory half of logout: after it, the same
698
+ * analytics instance keeps its stable `device_key` (which groups a DEVICE, not a user) but no longer
699
+ * stamps the previous user's id/email onto events. Pure; never mutates the input.
700
+ */
701
+ declare const clearPiiFromContext: (ctx?: WireUserContext) => WireUserContext;
702
+ /** Options for {@link clearUserContext}. */
703
+ interface ClearUserContextOptions {
704
+ /** Host persistence (AsyncStorage subset) — the persisted bound `user_id` is removed from here. */
705
+ storage?: WireOnboardingStorage;
706
+ /** Tenant/app id — namespaces the persisted key (`wireai:analytics:userId:<appId>`). */
707
+ appId?: string;
708
+ }
709
+ /**
710
+ * LOGOUT primitive: purge the persisted, bound opaque `user_id` for an app so the NEXT user on a
711
+ * shared device is not silently attributed to the previous one. Removes the
712
+ * `wireai:analytics:userId:<appId>` key that the analytics façade persists and reuses across
713
+ * launches. Fire-and-forget: a missing storage or a failing adapter resolves quietly.
714
+ *
715
+ * COVERAGE. The stateful `createAnalytics(...)` instance also exposes {@link Analytics.reset}, which
716
+ * does this AND clears the in-memory binding + PII in one call — prefer it when you hold the
717
+ * instance. This standalone helper covers the `createWireActivation` / `wire` path (whose config is
718
+ * captured immutably, so it has no `reset`): call `clearUserContext({ storage, appId })` on logout,
719
+ * and RECREATE the `wire` / analytics instance without the user's `userContext` (userId/userEmail)
720
+ * so no further events carry the previous user's identity. The non-PII per-install `device_key`
721
+ * (`wireai:analytics:deviceKey:<appId>`) is intentionally left in place — it groups a device, not a
722
+ * person, and stays stable across users of the same install.
723
+ */
724
+ declare const clearUserContext: (opts?: ClearUserContextOptions) => Promise<void>;
679
725
  /** Options for {@link resolveUserContext}. */
680
726
  interface ResolveUserContextOptions {
681
727
  /**
@@ -691,6 +737,60 @@ interface ResolveUserContextOptions {
691
737
  */
692
738
  declare const resolveUserContext: (ctx?: WireUserContext, opts?: ResolveUserContextOptions) => ResolvedUserContext;
693
739
 
740
+ /** Max accepted user-id length. Longer strings are truncated (never rejected). Keep in sync
741
+ * with the server's `USER_ID_MAX_LENGTH` (analytics/events.py). */
742
+ declare const USER_ID_MAX_LENGTH = 128;
743
+ /**
744
+ * Normalize a host-supplied user id: trim, drop empty, and cap at {@link USER_ID_MAX_LENGTH}.
745
+ * Returns `undefined` for a missing/blank/non-string value so callers can `if (id)`-gate.
746
+ * PII is a host concern — this only bounds length, it does not (and cannot) detect an email.
747
+ */
748
+ declare const sanitizeUserId: (raw: unknown) => string | undefined;
749
+ /**
750
+ * A permissive email-SHAPE test (`local@domain.tld`) — NOT an RFC validator. Its ONE job is to
751
+ * catch the common integration mistake of binding a RAW EMAIL as the opaque `user_id`: that leaks
752
+ * PII into the top-level id (which the server treats as an opaque key and may surface), when the
753
+ * email belongs in the opt-in `user_context.user_email` field instead. `identify()` uses this to
754
+ * refuse an email-shaped id (with a dev warning) unless the host opts in explicitly. Trims first.
755
+ */
756
+ declare const looksLikeEmail: (value: unknown) => boolean;
757
+ /** Options for {@link identifyOnboarding}. */
758
+ type IdentifyOnboardingOptions = {
759
+ /** Tenant transport, same shape as `WireOnboardingConfig` (only these two fields are used). */
760
+ config: {
761
+ serverUrl: string;
762
+ apiKey: string;
763
+ };
764
+ /** The host's opaque user id to bind. Trimmed + capped; NO PII. */
765
+ userId: string;
766
+ /**
767
+ * The onboarding session id to bind to (the A2A contextId) — the `contextId` field carried on
768
+ * the `started`/`resumed` `onEvent`. Pass this when you captured it there. Required after the
769
+ * flow COMPLETED, since completion clears the persisted session. Wins over the storage lookup.
770
+ */
771
+ contextId?: string;
772
+ /**
773
+ * The SAME host storage you passed to `<WireOnboarding storage={…} />`. When `contextId` is
774
+ * omitted, the helper reads the persisted contextId from it (works while the session is still
775
+ * persisted — i.e. dropped or mid-flow, before completion clears it).
776
+ */
777
+ storage?: WireOnboardingStorage;
778
+ /** App id, to derive the default storage key `wireai:session:<appId>` when reading from storage. */
779
+ appId?: string;
780
+ /** Storage key override — pass the same `persistKey` you gave `<WireOnboarding>`, if any. */
781
+ persistKey?: string;
782
+ };
783
+ /**
784
+ * Attach a host user id to an onboarding session AFTER the fact (post-registration), by sending
785
+ * an `identify` client event to `/v1/events`. Resolves the contextId from an explicit
786
+ * `contextId` or, failing that, from the persisted session in the host `storage`.
787
+ *
788
+ * Fire-and-forget under the hood (never throws, never blocks onboarding). Resolves to `true`
789
+ * when an identify event was dispatched, `false` when it couldn't (no user id, no server url,
790
+ * or no resolvable contextId).
791
+ */
792
+ declare const identifyOnboarding: (opts: IdentifyOnboardingOptions) => Promise<boolean>;
793
+
694
794
  /**
695
795
  * currentSession — a tiny registry of the CURRENT per-open `session_id`.
696
796
  *
@@ -736,4 +836,4 @@ declare const getCurrentSessionId: () => string | undefined;
736
836
  /** Test-only: forget the current session id so a unit test starts from a clean registry. */
737
837
  declare const resetCurrentSessionId: () => void;
738
838
 
739
- export { type AnalyticsEvent as A, type ResolveUserContextOptions as B, type ClientEvent as C, type DeviceContext as D, type EventQueueOptions as E, type ResolvedUserContext as F, collectDeviceContext as G, hashEmailFnv1a as H, isWireScalar as I, namespaceExtra as J, resolveUserContext as K, type OnboardingResult as O, RESERVED_USER_CONTEXT_KEYS as R, type StepValidator as S, type WireUserContext as W, type ClientEventTarget as a, type ClientEventType as b, type ContextEnvelope as c, type ContextEnvelopeInput as d, type EnvelopeSource as e, type EventQueue as f, WIRE_ONBOARDING_EVENTS as g, type WireOnboardingEventName as h, buildContextEnvelope as i, createEventQueue as j, getCurrentSessionId as k, reportClientEventAwait as l, makeSessionId as m, reportClientEvents as n, reportClientEventsAwait as o, resetCurrentSessionId as p, type WireOnboardingProps as q, reportClientEvent as r, setCurrentSessionId as s, toAnalyticsEvent as t, type WireOnboardingConfig as u, type OnboardingEvent as v, type OnboardingCopy as w, type DeviceFormFactor as x, EXTRA_KEY_PREFIX as y, type OnboardingProgress as z };
839
+ export { type AnalyticsEvent as A, type OnboardingEvent as B, type ClearUserContextOptions as C, type OnboardingCopy as D, type EventQueueOptions as E, type DeviceContext as F, type DeviceFormFactor as G, EXTRA_KEY_PREFIX as H, type IdentifyOnboardingOptions as I, type OnboardingProgress as J, type ResolveUserContextOptions as K, type ResolvedUserContext as L, collectDeviceContext as M, hashEmailFnv1a as N, type OnboardingResult as O, identifyOnboarding as P, isWireScalar as Q, RESERVED_USER_CONTEXT_KEYS as R, type StepValidator as S, namespaceExtra as T, USER_ID_MAX_LENGTH as U, resolveUserContext as V, type WireUserContext as W, sanitizeUserId as X, type ClientEvent as a, type ClientEventTarget as b, type ClientEventType as c, type ContextEnvelope as d, type ContextEnvelopeInput as e, type EnvelopeSource as f, type EventQueue as g, WIRE_ONBOARDING_EVENTS as h, type WireOnboardingEventName as i, analyticsUserIdStorageKey as j, buildContextEnvelope as k, clearPiiFromContext as l, clearUserContext as m, createEventQueue as n, getCurrentSessionId as o, looksLikeEmail as p, makeSessionId as q, reportClientEvent as r, reportClientEventAwait as s, reportClientEvents as t, reportClientEventsAwait as u, resetCurrentSessionId as v, setCurrentSessionId as w, toAnalyticsEvent as x, type WireOnboardingProps as y, type WireOnboardingConfig as z };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { ReactNode } from 'react';
3
- import { q as WireOnboardingProps, u as WireOnboardingConfig, O as OnboardingResult, S as StepValidator, v as OnboardingEvent, w as OnboardingCopy, a as ClientEventTarget, D as DeviceContext, W as WireUserContext, C as ClientEvent, e as EnvelopeSource } from './currentSession-DdDkprpM.mjs';
4
- export { A as AnalyticsEvent, b as ClientEventType, x as DeviceFormFactor, y as EXTRA_KEY_PREFIX, z as OnboardingProgress, R as RESERVED_USER_CONTEXT_KEYS, B as ResolveUserContextOptions, F as ResolvedUserContext, g as WIRE_ONBOARDING_EVENTS, h as WireOnboardingEventName, G as collectDeviceContext, k as getCurrentSessionId, H as hashEmailFnv1a, I as isWireScalar, m as makeSessionId, J as namespaceExtra, r as reportClientEvent, l as reportClientEventAwait, n as reportClientEvents, o as reportClientEventsAwait, p as resetCurrentSessionId, K as resolveUserContext, s as setCurrentSessionId, t as toAnalyticsEvent } from './currentSession-DdDkprpM.mjs';
3
+ import { y as WireOnboardingProps, z as WireOnboardingConfig, O as OnboardingResult, S as StepValidator, B as OnboardingEvent, D as OnboardingCopy, b as ClientEventTarget, F as DeviceContext, W as WireUserContext, a as ClientEvent, f as EnvelopeSource } from './currentSession-C0_odnIW.mjs';
4
+ export { A as AnalyticsEvent, C as ClearUserContextOptions, c as ClientEventType, G as DeviceFormFactor, H as EXTRA_KEY_PREFIX, I as IdentifyOnboardingOptions, J as OnboardingProgress, R as RESERVED_USER_CONTEXT_KEYS, K as ResolveUserContextOptions, L as ResolvedUserContext, U as USER_ID_MAX_LENGTH, h as WIRE_ONBOARDING_EVENTS, i as WireOnboardingEventName, j as analyticsUserIdStorageKey, l as clearPiiFromContext, m as clearUserContext, M as collectDeviceContext, o as getCurrentSessionId, N as hashEmailFnv1a, P as identifyOnboarding, Q as isWireScalar, p as looksLikeEmail, q as makeSessionId, T as namespaceExtra, r as reportClientEvent, s as reportClientEventAwait, t as reportClientEvents, u as reportClientEventsAwait, v as resetCurrentSessionId, V as resolveUserContext, X as sanitizeUserId, w as setCurrentSessionId, x as toAnalyticsEvent } from './currentSession-C0_odnIW.mjs';
5
5
  import { O as OnboardingTheme } from './types-BKfpdZzX.mjs';
6
6
  export { a as OnboardingButtonStyle, b as OnboardingColors, c as OnboardingFonts, d as OnboardingRadius, e as OnboardingSpacing } from './types-BKfpdZzX.mjs';
7
7
  export { C as CenteredModal, a as CenteredModalHandle, b as CenteredModalProps } from './CenteredModal-C3qQBHsA.mjs';
@@ -1436,52 +1436,6 @@ type OptionalRequire = (moduleName: string) => unknown;
1436
1436
  */
1437
1437
  declare const detectNativeModel: (requireModule?: OptionalRequire) => string | undefined;
1438
1438
 
1439
- /** Max accepted user-id length. Longer strings are truncated (never rejected). Keep in sync
1440
- * with the server's `USER_ID_MAX_LENGTH` (analytics/events.py). */
1441
- declare const USER_ID_MAX_LENGTH = 128;
1442
- /**
1443
- * Normalize a host-supplied user id: trim, drop empty, and cap at {@link USER_ID_MAX_LENGTH}.
1444
- * Returns `undefined` for a missing/blank/non-string value so callers can `if (id)`-gate.
1445
- * PII is a host concern — this only bounds length, it does not (and cannot) detect an email.
1446
- */
1447
- declare const sanitizeUserId: (raw: unknown) => string | undefined;
1448
- /** Options for {@link identifyOnboarding}. */
1449
- type IdentifyOnboardingOptions = {
1450
- /** Tenant transport, same shape as `WireOnboardingConfig` (only these two fields are used). */
1451
- config: {
1452
- serverUrl: string;
1453
- apiKey: string;
1454
- };
1455
- /** The host's opaque user id to bind. Trimmed + capped; NO PII. */
1456
- userId: string;
1457
- /**
1458
- * The onboarding session id to bind to (the A2A contextId) — the `contextId` field carried on
1459
- * the `started`/`resumed` `onEvent`. Pass this when you captured it there. Required after the
1460
- * flow COMPLETED, since completion clears the persisted session. Wins over the storage lookup.
1461
- */
1462
- contextId?: string;
1463
- /**
1464
- * The SAME host storage you passed to `<WireOnboarding storage={…} />`. When `contextId` is
1465
- * omitted, the helper reads the persisted contextId from it (works while the session is still
1466
- * persisted — i.e. dropped or mid-flow, before completion clears it).
1467
- */
1468
- storage?: WireOnboardingStorage;
1469
- /** App id, to derive the default storage key `wireai:session:<appId>` when reading from storage. */
1470
- appId?: string;
1471
- /** Storage key override — pass the same `persistKey` you gave `<WireOnboarding>`, if any. */
1472
- persistKey?: string;
1473
- };
1474
- /**
1475
- * Attach a host user id to an onboarding session AFTER the fact (post-registration), by sending
1476
- * an `identify` client event to `/v1/events`. Resolves the contextId from an explicit
1477
- * `contextId` or, failing that, from the persisted session in the host `storage`.
1478
- *
1479
- * Fire-and-forget under the hood (never throws, never blocks onboarding). Resolves to `true`
1480
- * when an identify event was dispatched, `false` when it couldn't (no user id, no server url,
1481
- * or no resolvable contextId).
1482
- */
1483
- declare const identifyOnboarding: (opts: IdentifyOnboardingOptions) => Promise<boolean>;
1484
-
1485
1439
  /**
1486
1440
  * deviceId — mint a stable, NON-PII, per-install device id the kit owns when the host supplies
1487
1441
  * none. This is the headline of "device fully automatic": the analytics façade auto-mints ONE id,
@@ -1852,4 +1806,4 @@ interface UseLifecycleEventsOptions {
1852
1806
  */
1853
1807
  declare const useLifecycleEvents: (config: LifecycleConfig | undefined, options?: UseLifecycleEventsOptions) => void;
1854
1808
 
1855
- export { AUTO_DEVICE_ID_PREFIX, AnimatedSparkle, BACKGROUND_SESSION_MS, type CachedFeatures, CardGridSelectCard, CardHandoff, type CardHandoffProps, type CardHandoffVariant, type CardOption, ChipSelectCard, ClientEvent, ClientEventTarget, CompletionView, DEFAULT_FEATURES_TTL_MS, DemoOnboarding, type DemoOnboardingProps, DeviceContext, DoneBlock, ErrorBlock, FIRST_OPEN_EVENT, IconRegistryProvider, type IdentifyOnboardingOptions, IllustrationProvider, type IllustrationRegistry, InterstitialCard, type LifecycleConfig, type LifecycleEventInput, LoadingBlock, LoadingScreen, NumberStepperCard, type OnboardingAttribution, Button as OnboardingButton, OnboardingCopy, OnboardingEvent, type OnboardingFlagOptions, OnboardingFlow, OnboardingResult, OnboardingScaffold, OnboardingTheme, OnboardingThemeProvider, type ReportFirstOpenOptions, type ReportSessionStartOptions, type ResolveFeaturesOptions, SESSION_STARTED_EVENT, SelectionCard, type SessionStartConfig, StatusCard, StepProgress, StepValidator, TextInputCard, type ThemeFromBrandInput, USER_ID_MAX_LENGTH, type UseLifecycleEventsOptions, type UseSessionStartOptions, type UseWireActivation, WIRE_ICON_GLYPHS, WIRE_ICON_NAMES, type WireActivation, type WireActivationConfig, type WireConfigOverrides, WireFeatures, WireFeaturesConfig, WireFeaturesProvider, type WireFeaturesProviderProps, WireIcon, type WireIconFamily, type WireIconGlyph, type WireIconName, type WireIconProps, type WireIconRegistry, type WireLifecycleOptions, WireOnboarding, WireOnboardingConfig, WireOnboardingProps, WireOnboardingStorage, WireUserContext, attributionMetadata, bumpActivationRevalidation, createWireActivation, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, detectAppVersion, detectNativeModel, deviceIdStorageKey, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, getActivationRevalidationVersion, identifyOnboarding, isFeaturesFresh, isOnboardingEnabled, lookupIconGlyph, mergeTheme, mintDeviceId, motionSpec, onboardingComponents, parseWireFeatures, readCachedFeatures, readProgress, reportFirstOpen, reportSessionStart, resetActivationRevalidation, resetFirstOpenLatch, resetSessionStartGuard, sanitizeUserId, subscribeActivationRevalidation, themeFromBrand, useActivationRevalidation, useHostIcon, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireActivation, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
1809
+ export { AUTO_DEVICE_ID_PREFIX, AnimatedSparkle, BACKGROUND_SESSION_MS, type CachedFeatures, CardGridSelectCard, CardHandoff, type CardHandoffProps, type CardHandoffVariant, type CardOption, ChipSelectCard, ClientEvent, ClientEventTarget, CompletionView, DEFAULT_FEATURES_TTL_MS, DemoOnboarding, type DemoOnboardingProps, DeviceContext, DoneBlock, ErrorBlock, FIRST_OPEN_EVENT, IconRegistryProvider, IllustrationProvider, type IllustrationRegistry, InterstitialCard, type LifecycleConfig, type LifecycleEventInput, LoadingBlock, LoadingScreen, NumberStepperCard, type OnboardingAttribution, Button as OnboardingButton, OnboardingCopy, OnboardingEvent, type OnboardingFlagOptions, OnboardingFlow, OnboardingResult, OnboardingScaffold, OnboardingTheme, OnboardingThemeProvider, type ReportFirstOpenOptions, type ReportSessionStartOptions, type ResolveFeaturesOptions, SESSION_STARTED_EVENT, SelectionCard, type SessionStartConfig, StatusCard, StepProgress, StepValidator, TextInputCard, type ThemeFromBrandInput, type UseLifecycleEventsOptions, type UseSessionStartOptions, type UseWireActivation, WIRE_ICON_GLYPHS, WIRE_ICON_NAMES, type WireActivation, type WireActivationConfig, type WireConfigOverrides, WireFeatures, WireFeaturesConfig, WireFeaturesProvider, type WireFeaturesProviderProps, WireIcon, type WireIconFamily, type WireIconGlyph, type WireIconName, type WireIconProps, type WireIconRegistry, type WireLifecycleOptions, WireOnboarding, WireOnboardingConfig, WireOnboardingProps, WireOnboardingStorage, WireUserContext, attributionMetadata, bumpActivationRevalidation, createWireActivation, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, detectAppVersion, detectNativeModel, deviceIdStorageKey, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, getActivationRevalidationVersion, isFeaturesFresh, isOnboardingEnabled, lookupIconGlyph, mergeTheme, mintDeviceId, motionSpec, onboardingComponents, parseWireFeatures, readCachedFeatures, readProgress, reportFirstOpen, reportSessionStart, resetActivationRevalidation, resetFirstOpenLatch, resetSessionStartGuard, subscribeActivationRevalidation, themeFromBrand, useActivationRevalidation, useHostIcon, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireActivation, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { ReactNode } from 'react';
3
- import { q as WireOnboardingProps, u as WireOnboardingConfig, O as OnboardingResult, S as StepValidator, v as OnboardingEvent, w as OnboardingCopy, a as ClientEventTarget, D as DeviceContext, W as WireUserContext, C as ClientEvent, e as EnvelopeSource } from './currentSession-D0Vq7_VE.js';
4
- export { A as AnalyticsEvent, b as ClientEventType, x as DeviceFormFactor, y as EXTRA_KEY_PREFIX, z as OnboardingProgress, R as RESERVED_USER_CONTEXT_KEYS, B as ResolveUserContextOptions, F as ResolvedUserContext, g as WIRE_ONBOARDING_EVENTS, h as WireOnboardingEventName, G as collectDeviceContext, k as getCurrentSessionId, H as hashEmailFnv1a, I as isWireScalar, m as makeSessionId, J as namespaceExtra, r as reportClientEvent, l as reportClientEventAwait, n as reportClientEvents, o as reportClientEventsAwait, p as resetCurrentSessionId, K as resolveUserContext, s as setCurrentSessionId, t as toAnalyticsEvent } from './currentSession-D0Vq7_VE.js';
3
+ import { y as WireOnboardingProps, z as WireOnboardingConfig, O as OnboardingResult, S as StepValidator, B as OnboardingEvent, D as OnboardingCopy, b as ClientEventTarget, F as DeviceContext, W as WireUserContext, a as ClientEvent, f as EnvelopeSource } from './currentSession-DdnUq2HQ.js';
4
+ export { A as AnalyticsEvent, C as ClearUserContextOptions, c as ClientEventType, G as DeviceFormFactor, H as EXTRA_KEY_PREFIX, I as IdentifyOnboardingOptions, J as OnboardingProgress, R as RESERVED_USER_CONTEXT_KEYS, K as ResolveUserContextOptions, L as ResolvedUserContext, U as USER_ID_MAX_LENGTH, h as WIRE_ONBOARDING_EVENTS, i as WireOnboardingEventName, j as analyticsUserIdStorageKey, l as clearPiiFromContext, m as clearUserContext, M as collectDeviceContext, o as getCurrentSessionId, N as hashEmailFnv1a, P as identifyOnboarding, Q as isWireScalar, p as looksLikeEmail, q as makeSessionId, T as namespaceExtra, r as reportClientEvent, s as reportClientEventAwait, t as reportClientEvents, u as reportClientEventsAwait, v as resetCurrentSessionId, V as resolveUserContext, X as sanitizeUserId, w as setCurrentSessionId, x as toAnalyticsEvent } from './currentSession-DdnUq2HQ.js';
5
5
  import { O as OnboardingTheme } from './types-BKfpdZzX.js';
6
6
  export { a as OnboardingButtonStyle, b as OnboardingColors, c as OnboardingFonts, d as OnboardingRadius, e as OnboardingSpacing } from './types-BKfpdZzX.js';
7
7
  export { C as CenteredModal, a as CenteredModalHandle, b as CenteredModalProps } from './CenteredModal-Cdgns6--.js';
@@ -1436,52 +1436,6 @@ type OptionalRequire = (moduleName: string) => unknown;
1436
1436
  */
1437
1437
  declare const detectNativeModel: (requireModule?: OptionalRequire) => string | undefined;
1438
1438
 
1439
- /** Max accepted user-id length. Longer strings are truncated (never rejected). Keep in sync
1440
- * with the server's `USER_ID_MAX_LENGTH` (analytics/events.py). */
1441
- declare const USER_ID_MAX_LENGTH = 128;
1442
- /**
1443
- * Normalize a host-supplied user id: trim, drop empty, and cap at {@link USER_ID_MAX_LENGTH}.
1444
- * Returns `undefined` for a missing/blank/non-string value so callers can `if (id)`-gate.
1445
- * PII is a host concern — this only bounds length, it does not (and cannot) detect an email.
1446
- */
1447
- declare const sanitizeUserId: (raw: unknown) => string | undefined;
1448
- /** Options for {@link identifyOnboarding}. */
1449
- type IdentifyOnboardingOptions = {
1450
- /** Tenant transport, same shape as `WireOnboardingConfig` (only these two fields are used). */
1451
- config: {
1452
- serverUrl: string;
1453
- apiKey: string;
1454
- };
1455
- /** The host's opaque user id to bind. Trimmed + capped; NO PII. */
1456
- userId: string;
1457
- /**
1458
- * The onboarding session id to bind to (the A2A contextId) — the `contextId` field carried on
1459
- * the `started`/`resumed` `onEvent`. Pass this when you captured it there. Required after the
1460
- * flow COMPLETED, since completion clears the persisted session. Wins over the storage lookup.
1461
- */
1462
- contextId?: string;
1463
- /**
1464
- * The SAME host storage you passed to `<WireOnboarding storage={…} />`. When `contextId` is
1465
- * omitted, the helper reads the persisted contextId from it (works while the session is still
1466
- * persisted — i.e. dropped or mid-flow, before completion clears it).
1467
- */
1468
- storage?: WireOnboardingStorage;
1469
- /** App id, to derive the default storage key `wireai:session:<appId>` when reading from storage. */
1470
- appId?: string;
1471
- /** Storage key override — pass the same `persistKey` you gave `<WireOnboarding>`, if any. */
1472
- persistKey?: string;
1473
- };
1474
- /**
1475
- * Attach a host user id to an onboarding session AFTER the fact (post-registration), by sending
1476
- * an `identify` client event to `/v1/events`. Resolves the contextId from an explicit
1477
- * `contextId` or, failing that, from the persisted session in the host `storage`.
1478
- *
1479
- * Fire-and-forget under the hood (never throws, never blocks onboarding). Resolves to `true`
1480
- * when an identify event was dispatched, `false` when it couldn't (no user id, no server url,
1481
- * or no resolvable contextId).
1482
- */
1483
- declare const identifyOnboarding: (opts: IdentifyOnboardingOptions) => Promise<boolean>;
1484
-
1485
1439
  /**
1486
1440
  * deviceId — mint a stable, NON-PII, per-install device id the kit owns when the host supplies
1487
1441
  * none. This is the headline of "device fully automatic": the analytics façade auto-mints ONE id,
@@ -1852,4 +1806,4 @@ interface UseLifecycleEventsOptions {
1852
1806
  */
1853
1807
  declare const useLifecycleEvents: (config: LifecycleConfig | undefined, options?: UseLifecycleEventsOptions) => void;
1854
1808
 
1855
- export { AUTO_DEVICE_ID_PREFIX, AnimatedSparkle, BACKGROUND_SESSION_MS, type CachedFeatures, CardGridSelectCard, CardHandoff, type CardHandoffProps, type CardHandoffVariant, type CardOption, ChipSelectCard, ClientEvent, ClientEventTarget, CompletionView, DEFAULT_FEATURES_TTL_MS, DemoOnboarding, type DemoOnboardingProps, DeviceContext, DoneBlock, ErrorBlock, FIRST_OPEN_EVENT, IconRegistryProvider, type IdentifyOnboardingOptions, IllustrationProvider, type IllustrationRegistry, InterstitialCard, type LifecycleConfig, type LifecycleEventInput, LoadingBlock, LoadingScreen, NumberStepperCard, type OnboardingAttribution, Button as OnboardingButton, OnboardingCopy, OnboardingEvent, type OnboardingFlagOptions, OnboardingFlow, OnboardingResult, OnboardingScaffold, OnboardingTheme, OnboardingThemeProvider, type ReportFirstOpenOptions, type ReportSessionStartOptions, type ResolveFeaturesOptions, SESSION_STARTED_EVENT, SelectionCard, type SessionStartConfig, StatusCard, StepProgress, StepValidator, TextInputCard, type ThemeFromBrandInput, USER_ID_MAX_LENGTH, type UseLifecycleEventsOptions, type UseSessionStartOptions, type UseWireActivation, WIRE_ICON_GLYPHS, WIRE_ICON_NAMES, type WireActivation, type WireActivationConfig, type WireConfigOverrides, WireFeatures, WireFeaturesConfig, WireFeaturesProvider, type WireFeaturesProviderProps, WireIcon, type WireIconFamily, type WireIconGlyph, type WireIconName, type WireIconProps, type WireIconRegistry, type WireLifecycleOptions, WireOnboarding, WireOnboardingConfig, WireOnboardingProps, WireOnboardingStorage, WireUserContext, attributionMetadata, bumpActivationRevalidation, createWireActivation, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, detectAppVersion, detectNativeModel, deviceIdStorageKey, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, getActivationRevalidationVersion, identifyOnboarding, isFeaturesFresh, isOnboardingEnabled, lookupIconGlyph, mergeTheme, mintDeviceId, motionSpec, onboardingComponents, parseWireFeatures, readCachedFeatures, readProgress, reportFirstOpen, reportSessionStart, resetActivationRevalidation, resetFirstOpenLatch, resetSessionStartGuard, sanitizeUserId, subscribeActivationRevalidation, themeFromBrand, useActivationRevalidation, useHostIcon, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireActivation, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
1809
+ export { AUTO_DEVICE_ID_PREFIX, AnimatedSparkle, BACKGROUND_SESSION_MS, type CachedFeatures, CardGridSelectCard, CardHandoff, type CardHandoffProps, type CardHandoffVariant, type CardOption, ChipSelectCard, ClientEvent, ClientEventTarget, CompletionView, DEFAULT_FEATURES_TTL_MS, DemoOnboarding, type DemoOnboardingProps, DeviceContext, DoneBlock, ErrorBlock, FIRST_OPEN_EVENT, IconRegistryProvider, IllustrationProvider, type IllustrationRegistry, InterstitialCard, type LifecycleConfig, type LifecycleEventInput, LoadingBlock, LoadingScreen, NumberStepperCard, type OnboardingAttribution, Button as OnboardingButton, OnboardingCopy, OnboardingEvent, type OnboardingFlagOptions, OnboardingFlow, OnboardingResult, OnboardingScaffold, OnboardingTheme, OnboardingThemeProvider, type ReportFirstOpenOptions, type ReportSessionStartOptions, type ResolveFeaturesOptions, SESSION_STARTED_EVENT, SelectionCard, type SessionStartConfig, StatusCard, StepProgress, StepValidator, TextInputCard, type ThemeFromBrandInput, type UseLifecycleEventsOptions, type UseSessionStartOptions, type UseWireActivation, WIRE_ICON_GLYPHS, WIRE_ICON_NAMES, type WireActivation, type WireActivationConfig, type WireConfigOverrides, WireFeatures, WireFeaturesConfig, WireFeaturesProvider, type WireFeaturesProviderProps, WireIcon, type WireIconFamily, type WireIconGlyph, type WireIconName, type WireIconProps, type WireIconRegistry, type WireLifecycleOptions, WireOnboarding, WireOnboardingConfig, WireOnboardingProps, WireOnboardingStorage, WireUserContext, attributionMetadata, bumpActivationRevalidation, createWireActivation, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, detectAppVersion, detectNativeModel, deviceIdStorageKey, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, getActivationRevalidationVersion, isFeaturesFresh, isOnboardingEnabled, lookupIconGlyph, mergeTheme, mintDeviceId, motionSpec, onboardingComponents, parseWireFeatures, readCachedFeatures, readProgress, reportFirstOpen, reportSessionStart, resetActivationRevalidation, resetFirstOpenLatch, resetSessionStartGuard, subscribeActivationRevalidation, themeFromBrand, useActivationRevalidation, useHostIcon, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireActivation, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
package/dist/index.js CHANGED
@@ -3382,6 +3382,7 @@ var sanitizeUserId = (raw) => {
3382
3382
  if (!trimmed) return void 0;
3383
3383
  return trimmed.length > USER_ID_MAX_LENGTH ? trimmed.slice(0, USER_ID_MAX_LENGTH) : trimmed;
3384
3384
  };
3385
+ var looksLikeEmail = (value) => typeof value === "string" && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value.trim());
3385
3386
  var identifyOnboarding = async (opts) => {
3386
3387
  var _a2, _b, _c;
3387
3388
  const userId = sanitizeUserId(opts.userId);
@@ -4097,6 +4098,21 @@ var namespaceExtra = (extra) => {
4097
4098
  }
4098
4099
  return out;
4099
4100
  };
4101
+ var analyticsUserIdStorageKey = (appId) => `wireai:analytics:userId:${appId != null ? appId : "default"}`;
4102
+ var clearPiiFromContext = (ctx = {}) => {
4103
+ const rest = {};
4104
+ if (typeof ctx.appVersion === "string") rest.appVersion = ctx.appVersion;
4105
+ if (typeof ctx.deviceKey === "string") rest.deviceKey = ctx.deviceKey;
4106
+ return rest;
4107
+ };
4108
+ var clearUserContext = async (opts = {}) => {
4109
+ const storage = opts.storage;
4110
+ if (!storage) return;
4111
+ try {
4112
+ await storage.removeItem(analyticsUserIdStorageKey(opts.appId));
4113
+ } catch {
4114
+ }
4115
+ };
4100
4116
  var resolveUserContext = (ctx = {}, opts = {}) => {
4101
4117
  var _a2;
4102
4118
  const result = {};
@@ -4390,16 +4406,9 @@ var routeLifecycleEvent = (event, opts) => {
4390
4406
  opts.sink(event);
4391
4407
  return;
4392
4408
  }
4393
- const target = opts.target;
4394
- if (!(target == null ? void 0 : target.serverUrl)) return;
4395
- const url = `${target.serverUrl.replace(/\/$/, "")}/v1/events`;
4396
- const headers = { "Content-Type": "application/json" };
4397
- if (target.apiKey) headers.Authorization = `Bearer ${target.apiKey}`;
4398
- void fetch(url, {
4399
- method: "POST",
4400
- headers,
4401
- body: JSON.stringify({ events: [event] })
4402
- }).catch(() => {
4409
+ const req = buildEventsRequest(opts.target, [event]);
4410
+ if (!req) return;
4411
+ void fetch(req.url, req.init).catch(() => {
4403
4412
  });
4404
4413
  } catch {
4405
4414
  }
@@ -4511,6 +4520,7 @@ var createEventQueue = (options) => {
4511
4520
  var _a3;
4512
4521
  const env = resolveEnvelope();
4513
4522
  const stamped = { ...event };
4523
+ if (stamped.ts === void 0) stamped.ts = Date.now();
4514
4524
  if (!env) return stamped;
4515
4525
  if (!stamped.device && env.device) stamped.device = env.device;
4516
4526
  if (!stamped.session_id && env.sessionId) stamped.session_id = env.sessionId;
@@ -4566,19 +4576,12 @@ var createEventQueue = (options) => {
4566
4576
  }
4567
4577
  })();
4568
4578
  const postBatch = async (events) => {
4569
- if (!(target == null ? void 0 : target.serverUrl) || events.length === 0) return false;
4579
+ const req = buildEventsRequest(target, events);
4580
+ if (!req) return false;
4570
4581
  const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
4571
4582
  const timer = setTimeout(() => controller == null ? void 0 : controller.abort(), 15e3);
4572
4583
  try {
4573
- const url = `${target.serverUrl.replace(/\/$/, "")}/v1/events`;
4574
- const headers = { "Content-Type": "application/json" };
4575
- if (target.apiKey) headers.Authorization = `Bearer ${target.apiKey}`;
4576
- const res = await fetch(url, {
4577
- method: "POST",
4578
- headers,
4579
- body: JSON.stringify({ events }),
4580
- signal: controller == null ? void 0 : controller.signal
4581
- });
4584
+ const res = await fetch(req.url, { ...req.init, signal: controller == null ? void 0 : controller.signal });
4582
4585
  return !!(res && res.ok);
4583
4586
  } catch {
4584
4587
  return false;
@@ -4684,6 +4687,28 @@ var useLifecycleEvents = (config, options = {}) => {
4684
4687
  var _a3;
4685
4688
  return (cfg == null ? void 0 : cfg.serverUrl) ? { serverUrl: cfg.serverUrl, apiKey: (_a3 = cfg.apiKey) != null ? _a3 : "" } : void 0;
4686
4689
  };
4690
+ const mountOpenSessionId = makeSessionId();
4691
+ const fireSession = (sessionId) => {
4692
+ var _a3;
4693
+ const { config: cfg, options: opts } = latest.current;
4694
+ if (opts.enabled === false) return;
4695
+ if (!(cfg == null ? void 0 : cfg.serverUrl) && !opts.sink) return;
4696
+ const device = collectDeviceContext();
4697
+ if (cfg == null ? void 0 : cfg.appVersion) device.appVersion = cfg.appVersion;
4698
+ reportSessionStart({
4699
+ target: targetOf(cfg),
4700
+ sink: resolveSink(),
4701
+ sessionId,
4702
+ userId: opts.userId,
4703
+ deviceKey: opts.deviceKey,
4704
+ sessionCount: opts.sessionCount,
4705
+ appVersion: (_a3 = cfg == null ? void 0 : cfg.appVersion) != null ? _a3 : device.appVersion,
4706
+ platform: reactNative.Platform.OS,
4707
+ device,
4708
+ meta: opts.meta
4709
+ });
4710
+ };
4711
+ fireSession(mountOpenSessionId);
4687
4712
  {
4688
4713
  const { config: cfg, options: opts } = latest.current;
4689
4714
  if (opts.enabled !== false) {
@@ -4692,6 +4717,7 @@ var useLifecycleEvents = (config, options = {}) => {
4692
4717
  reportFirstOpen({
4693
4718
  target: targetOf(cfg),
4694
4719
  sink: resolveSink(),
4720
+ sessionId: mountOpenSessionId,
4695
4721
  storage: cfg == null ? void 0 : cfg.storage,
4696
4722
  appId: cfg == null ? void 0 : cfg.appId,
4697
4723
  userId: opts.userId,
@@ -4704,27 +4730,6 @@ var useLifecycleEvents = (config, options = {}) => {
4704
4730
  });
4705
4731
  }
4706
4732
  }
4707
- const fireSession = () => {
4708
- var _a3;
4709
- const { config: cfg, options: opts } = latest.current;
4710
- if (opts.enabled === false) return;
4711
- if (!(cfg == null ? void 0 : cfg.serverUrl) && !opts.sink) return;
4712
- const device = collectDeviceContext();
4713
- if (cfg == null ? void 0 : cfg.appVersion) device.appVersion = cfg.appVersion;
4714
- reportSessionStart({
4715
- target: targetOf(cfg),
4716
- sink: resolveSink(),
4717
- // A fresh per-open id each fire; the emitter's once-guard dedupes within the open.
4718
- userId: opts.userId,
4719
- deviceKey: opts.deviceKey,
4720
- sessionCount: opts.sessionCount,
4721
- appVersion: (_a3 = cfg == null ? void 0 : cfg.appVersion) != null ? _a3 : device.appVersion,
4722
- platform: reactNative.Platform.OS,
4723
- device,
4724
- meta: opts.meta
4725
- });
4726
- };
4727
- fireSession();
4728
4733
  let backgroundedAt = null;
4729
4734
  const onChange = (state) => {
4730
4735
  if (state === "background" || state === "inactive") {
@@ -4782,9 +4787,12 @@ exports.WIRE_ONBOARDING_EVENTS = WIRE_ONBOARDING_EVENTS;
4782
4787
  exports.WireFeaturesProvider = WireFeaturesProvider;
4783
4788
  exports.WireIcon = WireIcon;
4784
4789
  exports.WireOnboarding = WireOnboarding;
4790
+ exports.analyticsUserIdStorageKey = analyticsUserIdStorageKey;
4785
4791
  exports.attributionMetadata = attributionMetadata;
4786
4792
  exports.bumpActivationRevalidation = bumpActivationRevalidation;
4787
4793
  exports.clearPersistedSession = clearPersistedSession;
4794
+ exports.clearPiiFromContext = clearPiiFromContext;
4795
+ exports.clearUserContext = clearUserContext;
4788
4796
  exports.collectDeviceContext = collectDeviceContext;
4789
4797
  exports.createWireActivation = createWireActivation;
4790
4798
  exports.defaultIllustrations = defaultIllustrations;
@@ -4806,6 +4814,7 @@ exports.isFeaturesFresh = isFeaturesFresh;
4806
4814
  exports.isOnboardingEnabled = isOnboardingEnabled;
4807
4815
  exports.isWireScalar = isWireScalar;
4808
4816
  exports.loadPersistedSession = loadPersistedSession;
4817
+ exports.looksLikeEmail = looksLikeEmail;
4809
4818
  exports.lookupIconGlyph = lookupIconGlyph;
4810
4819
  exports.makeSessionId = makeSessionId;
4811
4820
  exports.mergeTheme = mergeTheme;