@magicfeedback/popup-sdk 1.19.0 → 1.21.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 (34) hide show
  1. package/dist/{chunk-EW2ARDEY.mjs → chunk-BWYWXAIQ.mjs} +23 -3
  2. package/dist/chunk-BWYWXAIQ.mjs.map +1 -0
  3. package/dist/{chunk-7ZQOAKXR.mjs → chunk-H434NTBB.mjs} +26 -4
  4. package/dist/chunk-H434NTBB.mjs.map +1 -0
  5. package/dist/{chunk-XOEEBDBJ.mjs → chunk-UBUY6G6Z.mjs} +26 -4
  6. package/dist/chunk-UBUY6G6Z.mjs.map +1 -0
  7. package/dist/index.d.mts +105 -10
  8. package/dist/index.d.ts +105 -10
  9. package/dist/index.js +186 -37
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +163 -36
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/index.native.d.mts +105 -10
  14. package/dist/index.native.d.ts +105 -10
  15. package/dist/index.native.js +204 -42
  16. package/dist/index.native.js.map +1 -1
  17. package/dist/index.native.mjs +181 -41
  18. package/dist/index.native.mjs.map +1 -1
  19. package/dist/react-native.d.mts +47 -8
  20. package/dist/react-native.d.ts +47 -8
  21. package/dist/react-native.js +200 -41
  22. package/dist/react-native.js.map +1 -1
  23. package/dist/react-native.mjs +180 -41
  24. package/dist/react-native.mjs.map +1 -1
  25. package/dist/{renderPopup-2Y4QMWR7.mjs → renderPopup-HNSFPFVT.mjs} +2 -2
  26. package/dist/{renderPopup-ZHTRMFO2.mjs → renderPopup-VXKWSZ4E.mjs} +2 -2
  27. package/dist/{renderPopup-YDJUON42.mjs → renderPopup-WNF67H5T.mjs} +2 -2
  28. package/package.json +1 -1
  29. package/dist/chunk-7ZQOAKXR.mjs.map +0 -1
  30. package/dist/chunk-EW2ARDEY.mjs.map +0 -1
  31. package/dist/chunk-XOEEBDBJ.mjs.map +0 -1
  32. /package/dist/{renderPopup-2Y4QMWR7.mjs.map → renderPopup-HNSFPFVT.mjs.map} +0 -0
  33. /package/dist/{renderPopup-ZHTRMFO2.mjs.map → renderPopup-VXKWSZ4E.mjs.map} +0 -0
  34. /package/dist/{renderPopup-YDJUON42.mjs.map → renderPopup-WNF67H5T.mjs.map} +0 -0
@@ -146,6 +146,12 @@ interface AnalyticsFlushMeta {
146
146
  * registro nuevo, igual que tras `sessionEnd`, pero sin POST.
147
147
  */
148
148
  resetSession?: boolean;
149
+ /**
150
+ * `true` cuando el lote puede ser lo último que salga de la sesión sin cerrarla (app a
151
+ * background en RN: la sesión queda suspendida). El sink lo guarda ANTES de enviarlo, como
152
+ * el lote de cierre, para reenviarlo en el arranque siguiente si el SO mata la app.
153
+ */
154
+ persist?: boolean;
149
155
  }
150
156
  /**
151
157
  * Envío del lote. Si devuelve una promesa que **rechaza**, el manager re-encola los
@@ -308,6 +314,12 @@ interface FeedbackSession {
308
314
  interface AutoTrackOptions {
309
315
  /** React Native: listen to `AppState` for session start/end. Default `true`. */
310
316
  lifecycle?: boolean;
317
+ /**
318
+ * Uncaught errors: `window` `error`/`unhandledrejection` (web), `ErrorUtils` and promise
319
+ * rejections without `catch` under Hermes (React Native). Default `true`. Handlers installed
320
+ * by other tools (Sentry, Crashlytics) keep receiving everything.
321
+ */
322
+ errors?: boolean;
311
323
  }
312
324
  interface DeepdotsInitParams {
313
325
  /** API key for authentication */
@@ -762,6 +774,10 @@ interface ReactNativeErrorUtils {
762
774
  getGlobalHandler?(): ((error: unknown, isFatal?: boolean) => void) | undefined;
763
775
  setGlobalHandler(handler: (error: unknown, isFatal?: boolean) => void): void;
764
776
  }
777
+ /** Fuente de promesas rechazadas sin `catch` (en RN, el hub del tracker de Hermes). */
778
+ interface UnhandledRejectionSource {
779
+ addUnhandledListener(listener: (error: unknown) => void): () => void;
780
+ }
765
781
  interface CrashReporterOptions {
766
782
  storage: KeyValueStorage;
767
783
  /** Emite un evento deepdots_app_crash AHORA (app viva). */
@@ -783,6 +799,8 @@ declare class CrashReporter {
783
799
  private windowInstalled;
784
800
  /** ErrorUtils ya enganchados: engancharlos dos veces capturaría cada error dos veces. */
785
801
  private hookedErrorUtils;
802
+ /** Fuentes de rejections ya enganchadas (idempotente, como ErrorUtils). */
803
+ private hookedRejections;
786
804
  constructor(options: CrashReporterOptions);
787
805
  private isEnabled;
788
806
  /** Construye un CrashRecord capturando contexto en el momento del crash. */
@@ -799,6 +817,12 @@ declare class CrashReporter {
799
817
  install(): void;
800
818
  /** Engancha `global.ErrorUtils` de RN (no hay `window`): persiste y encadena al handler previo. Idempotente por instancia de ErrorUtils. */
801
819
  installReactNative(errorUtils: ReactNativeErrorUtils): void;
820
+ /**
821
+ * Promesas rechazadas sin `catch` en React Native: como el `unhandledrejection` de web, se
822
+ * persisten y se reenvían en el arranque siguiente. La fuente encadena al tracker del host.
823
+ * Idempotente por fuente.
824
+ */
825
+ installPromiseRejections(source: UnhandledRejectionSource): void;
802
826
  /** @internal Test seam: ejercita el camino de persistencia (window handlers no son testeables en vitest). */
803
827
  _persistForTest(error: unknown): void;
804
828
  }
@@ -938,6 +962,8 @@ declare class DeepdotsPopups {
938
962
  private lastEngagementAt;
939
963
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
940
964
  private hiddenAt;
965
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
966
+ private autoTrackErrors;
941
967
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
942
968
  private appStateSubscription;
943
969
  /**
@@ -1036,14 +1062,21 @@ declare class DeepdotsPopups {
1036
1062
  * El host la llama en cada cambio de pantalla; emite `page_view` al salir de la anterior.
1037
1063
  */
1038
1064
  setScreen(name: string): void;
1039
- /** App a foreground (RN: AppState 'active'): reanuda el engagement time y abre sesión nueva. */
1065
+ /**
1066
+ * App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
1067
+ * background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
1068
+ * (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
1069
+ */
1040
1070
  onForeground(): void;
1041
1071
  /**
1042
- * App a background (RN: AppState 'background'): FIN DE SESIÓN. Cierra pantalla actual
1043
- * (page_view), mini-services (mini_service_exit), emite engagement + `session_end` y
1044
- * envía el último lote con `completed:true`.
1045
- *
1046
- * Es la única señal disponible en móvil: el kill de la app (swipe) NO da callback.
1072
+ * App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
1073
+ * actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
1074
+ * `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
1075
+ * - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
1076
+ * en el mismo registro;
1077
+ * - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
1078
+ * minutos con un `session_end` `background` a la hora de la suspensión.
1079
+ * Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
1047
1080
  */
1048
1081
  onBackground(): void;
1049
1082
  /**
@@ -1072,6 +1105,13 @@ declare class DeepdotsPopups {
1072
1105
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
1073
1106
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
1074
1107
  *
1108
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
1109
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
1110
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
1111
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
1112
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
1113
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
1114
+ *
1075
1115
  * Equivale a llamar a `init()` otra vez con otro `userId`.
1076
1116
  */
1077
1117
  setUserId(userId?: string): void;
@@ -1108,6 +1148,7 @@ declare class DeepdotsPopups {
1108
1148
  flushAnalytics(options?: {
1109
1149
  final?: boolean;
1110
1150
  sessionEnd?: boolean;
1151
+ persist?: boolean;
1111
1152
  }): void;
1112
1153
  /**
1113
1154
  * Emite un evento `user_engagement` con el tiempo activo acumulado (#8) y la pantalla en
@@ -1143,8 +1184,12 @@ declare class DeepdotsPopups {
1143
1184
  * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
1144
1185
  * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
1145
1186
  *
1187
+ * En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
1188
+ * background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
1189
+ *
1146
1190
  * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
1147
- * POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra como antes.
1191
+ * POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
1192
+ * como antes.
1148
1193
  */
1149
1194
  private suspendSession;
1150
1195
  /**
@@ -1155,11 +1200,23 @@ declare class DeepdotsPopups {
1155
1200
  private readResumableSession;
1156
1201
  /**
1157
1202
  * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
1158
- * ella (mismo usuario, dentro de ANALYTICS_RESUME_WINDOW_MS); null si no había o ya no toca.
1203
+ * ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
1204
+ * ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
1159
1205
  * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
1160
1206
  * se abre ahora va a uno nuevo.
1161
1207
  */
1162
1208
  private takeSuspendedSession;
1209
+ /**
1210
+ * `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
1211
+ * misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
1212
+ * (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
1213
+ * el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
1214
+ * #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
1215
+ * - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
1216
+ * - Más: el backend ya la cerró → se descarta sin enviar nada.
1217
+ * Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
1218
+ */
1219
+ private closeStaleHiddenSession;
1163
1220
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
1164
1221
  private discardSession;
1165
1222
  /**
@@ -1488,7 +1545,7 @@ declare const REVEAL_TIMEOUT_MS = 1200;
1488
1545
  * resolución, para que las tres rutas (popup DOM web, WebView de RN y Compose) digan lo mismo.
1489
1546
  */
1490
1547
  /** Locales con traducción propia. Cualquier otro idioma cae a `en`. */
1491
- type PopupLocale = 'en' | 'es' | 'da' | 'no' | 'sv' | 'fi' | 'de' | 'fr' | 'pt' | 'ar' | 'bn' | 'zh-CN' | 'bg' | 'cs' | 'el' | 'et' | 'ga' | 'hr' | 'hu' | 'it' | 'lt' | 'lv' | 'mt' | 'nl' | 'pl' | 'ro' | 'sk' | 'sl';
1548
+ type PopupLocale = 'en' | 'es' | 'da' | 'no' | 'sv' | 'fi' | 'de' | 'fr' | 'pt' | 'ar' | 'bn' | 'zh-CN' | 'bg' | 'cs' | 'el' | 'et' | 'ga' | 'hr' | 'hu' | 'it' | 'lt' | 'lv' | 'mt' | 'nl' | 'pl' | 'ro' | 'sk' | 'sl' | 'ca';
1492
1549
  interface PopupLabels {
1493
1550
  /** Acción principal: enviar la respuesta. */
1494
1551
  accept: string;
@@ -1613,4 +1670,42 @@ declare function collectRnDevice(d: DeviceInfoLike): DeviceInfo;
1613
1670
  */
1614
1671
  declare function setupReactNative(sdk: DeepdotsPopups, config: DeepdotsInitParams, deps?: ReactNativeSetupDeps): () => void;
1615
1672
 
1616
- export { type AnalyticsFeedbackBody, type AnalyticsKeys, type AppStateLike, type AutoTrackOptions, BACKGROUND_TASK_MAX_MS, type BackgroundTaskRunner, type BackgroundTimerLike, BrowserPopupRenderer, type BuildBodyOptions, type ContactAttributeValue, type ContactAttributes, type ContactBody, ContactManager, type CrashRecord, CrashReporter, type CrashSeverity, type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, type DeepdotsInitParams, type DeepdotsLogger, DeepdotsPopups, type DeviceInfo, type DeviceInfoLike, type DeviceSnapshot, type EventListener, type FeedbackKV, type FeedbackSession, InMemoryStorage, type KeyValueStorage, LABELS, MAX_TRACKED_MESSAGES, MESSAGE_CHANNELS, type MessageChannel, MessageGuard, type MessageGuardVerdict, type MessageRejectionReason, type MessageStage, type MmkvLike, NATIVE_READY_GRACE_MS, NoopPopupRenderer, POPUP_TRIGGER_CONDITION_STATUSES, type PopupDefinition, type PopupLabels, type PopupLocale, type PopupRenderer, type PopupTrigger, type PopupTriggerCondition, type PopupTriggerConditionStatus, REVEAL_TIMEOUT_MS, RTL_LOCALES, type ReactNativeErrorUtils, ReactNativePopupRenderer, type ReactNativeRendererOptions, type ReactNativeSetupDeps, type ReactNativeSurveyPayload, type ReportErrorOptions, type ResolvedActionLabels, SUPPORTED_LANGUAGES, type SessionEndReason, type SessionStartReason, type TrackMessageOptions, type TriggerConfig, backgroundTimerTask, buildAnalyticsFeedbackBody, buildMessageParams, buildSurveyHtml, collectRnDevice, crashRecordToParams, createDefaultRenderer, createFeedbackSink, directionFor, getLabels, isRtlLanguage, mmkvStorage, resolveActionLabels, resolveLocale, setupReactNative };
1673
+ /**
1674
+ * Lo que el SDK necesita de React Native para detectar solo el ciclo de vida y el tiempo de
1675
+ * background (DD-55, contrato de detección automática). El core no importa `react-native` (se
1676
+ * usa también en web): lo registra la entrada de React Native del paquete
1677
+ * (`src/index.native.ts`, que Metro elige por la condición `react-native`) y el Provider.
1678
+ */
1679
+
1680
+ /** Opciones de `HermesInternal.enablePromiseRejectionTracker` (las mismas que `promise/rejection-tracking`). */
1681
+ interface RejectionTrackingOptions {
1682
+ allRejections?: boolean;
1683
+ onUnhandled?: (id: number, error: unknown) => void;
1684
+ onHandled?: (id: number, error?: unknown) => void;
1685
+ }
1686
+ /** Lo que el SDK necesita de `global.HermesInternal`. */
1687
+ interface HermesRejectionTrackerLike {
1688
+ enablePromiseRejectionTracker?: (options?: RejectionTrackingOptions) => void;
1689
+ }
1690
+ interface PromiseRejectionHub {
1691
+ /** Avisa de cada promesa rechazada sin `catch`. Devuelve la función que lo quita. */
1692
+ addUnhandledListener(listener: (error: unknown) => void): () => void;
1693
+ }
1694
+ /**
1695
+ * Promesas rechazadas sin `catch` en React Native (contrato de detección automática, paso 2).
1696
+ *
1697
+ * Hermes solo admite UN tracker (`enablePromiseRejectionTracker` sustituye al anterior) y no deja
1698
+ * leer el que hay. Para no quitarle las rejections a Sentry/Crashlytics, la entrada de React
1699
+ * Native envuelve la función al importarse el paquete, que es antes de que el código de la app
1700
+ * llame a `Sentry.init()` (los imports se evalúan primero): lo que instale después cualquiera se
1701
+ * compone con lo nuestro en vez de sustituirlo. Antes del import solo lo pudo instalar React
1702
+ * Native, y solo en desarrollo (el aviso "Possible unhandled promise rejection"), que se mantiene
1703
+ * con `dev`. Mientras el SDK no se engancha, la función envuelta pasa todo tal cual a Hermes.
1704
+ *
1705
+ * Devuelve null sin Hermes o sin el tracker (JSC): el SDK sigue sin capturarlas, como antes.
1706
+ */
1707
+ declare function createHermesRejectionHub(hermes: HermesRejectionTrackerLike | null | undefined, options: {
1708
+ dev: boolean;
1709
+ }): PromiseRejectionHub | null;
1710
+
1711
+ export { type AnalyticsFeedbackBody, type AnalyticsKeys, type AppStateLike, type AutoTrackOptions, BACKGROUND_TASK_MAX_MS, type BackgroundTaskRunner, type BackgroundTimerLike, BrowserPopupRenderer, type BuildBodyOptions, type ContactAttributeValue, type ContactAttributes, type ContactBody, ContactManager, type CrashRecord, CrashReporter, type CrashSeverity, type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, type DeepdotsInitParams, type DeepdotsLogger, DeepdotsPopups, type DeviceInfo, type DeviceInfoLike, type DeviceSnapshot, type EventListener, type FeedbackKV, type FeedbackSession, type HermesRejectionTrackerLike, InMemoryStorage, type KeyValueStorage, LABELS, MAX_TRACKED_MESSAGES, MESSAGE_CHANNELS, type MessageChannel, MessageGuard, type MessageGuardVerdict, type MessageRejectionReason, type MessageStage, type MmkvLike, NATIVE_READY_GRACE_MS, NoopPopupRenderer, POPUP_TRIGGER_CONDITION_STATUSES, type PopupDefinition, type PopupLabels, type PopupLocale, type PopupRenderer, type PopupTrigger, type PopupTriggerCondition, type PopupTriggerConditionStatus, type PromiseRejectionHub, REVEAL_TIMEOUT_MS, RTL_LOCALES, type ReactNativeErrorUtils, ReactNativePopupRenderer, type ReactNativeRendererOptions, type ReactNativeSetupDeps, type ReactNativeSurveyPayload, type RejectionTrackingOptions, type ReportErrorOptions, type ResolvedActionLabels, SUPPORTED_LANGUAGES, type SessionEndReason, type SessionStartReason, type TrackMessageOptions, type TriggerConfig, backgroundTimerTask, buildAnalyticsFeedbackBody, buildMessageParams, buildSurveyHtml, collectRnDevice, crashRecordToParams, createDefaultRenderer, createFeedbackSink, createHermesRejectionHub, directionFor, getLabels, isRtlLanguage, mmkvStorage, resolveActionLabels, resolveLocale, setupReactNative };
@@ -146,6 +146,12 @@ interface AnalyticsFlushMeta {
146
146
  * registro nuevo, igual que tras `sessionEnd`, pero sin POST.
147
147
  */
148
148
  resetSession?: boolean;
149
+ /**
150
+ * `true` cuando el lote puede ser lo último que salga de la sesión sin cerrarla (app a
151
+ * background en RN: la sesión queda suspendida). El sink lo guarda ANTES de enviarlo, como
152
+ * el lote de cierre, para reenviarlo en el arranque siguiente si el SO mata la app.
153
+ */
154
+ persist?: boolean;
149
155
  }
150
156
  /**
151
157
  * Envío del lote. Si devuelve una promesa que **rechaza**, el manager re-encola los
@@ -308,6 +314,12 @@ interface FeedbackSession {
308
314
  interface AutoTrackOptions {
309
315
  /** React Native: listen to `AppState` for session start/end. Default `true`. */
310
316
  lifecycle?: boolean;
317
+ /**
318
+ * Uncaught errors: `window` `error`/`unhandledrejection` (web), `ErrorUtils` and promise
319
+ * rejections without `catch` under Hermes (React Native). Default `true`. Handlers installed
320
+ * by other tools (Sentry, Crashlytics) keep receiving everything.
321
+ */
322
+ errors?: boolean;
311
323
  }
312
324
  interface DeepdotsInitParams {
313
325
  /** API key for authentication */
@@ -762,6 +774,10 @@ interface ReactNativeErrorUtils {
762
774
  getGlobalHandler?(): ((error: unknown, isFatal?: boolean) => void) | undefined;
763
775
  setGlobalHandler(handler: (error: unknown, isFatal?: boolean) => void): void;
764
776
  }
777
+ /** Fuente de promesas rechazadas sin `catch` (en RN, el hub del tracker de Hermes). */
778
+ interface UnhandledRejectionSource {
779
+ addUnhandledListener(listener: (error: unknown) => void): () => void;
780
+ }
765
781
  interface CrashReporterOptions {
766
782
  storage: KeyValueStorage;
767
783
  /** Emite un evento deepdots_app_crash AHORA (app viva). */
@@ -783,6 +799,8 @@ declare class CrashReporter {
783
799
  private windowInstalled;
784
800
  /** ErrorUtils ya enganchados: engancharlos dos veces capturaría cada error dos veces. */
785
801
  private hookedErrorUtils;
802
+ /** Fuentes de rejections ya enganchadas (idempotente, como ErrorUtils). */
803
+ private hookedRejections;
786
804
  constructor(options: CrashReporterOptions);
787
805
  private isEnabled;
788
806
  /** Construye un CrashRecord capturando contexto en el momento del crash. */
@@ -799,6 +817,12 @@ declare class CrashReporter {
799
817
  install(): void;
800
818
  /** Engancha `global.ErrorUtils` de RN (no hay `window`): persiste y encadena al handler previo. Idempotente por instancia de ErrorUtils. */
801
819
  installReactNative(errorUtils: ReactNativeErrorUtils): void;
820
+ /**
821
+ * Promesas rechazadas sin `catch` en React Native: como el `unhandledrejection` de web, se
822
+ * persisten y se reenvían en el arranque siguiente. La fuente encadena al tracker del host.
823
+ * Idempotente por fuente.
824
+ */
825
+ installPromiseRejections(source: UnhandledRejectionSource): void;
802
826
  /** @internal Test seam: ejercita el camino de persistencia (window handlers no son testeables en vitest). */
803
827
  _persistForTest(error: unknown): void;
804
828
  }
@@ -938,6 +962,8 @@ declare class DeepdotsPopups {
938
962
  private lastEngagementAt;
939
963
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
940
964
  private hiddenAt;
965
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
966
+ private autoTrackErrors;
941
967
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
942
968
  private appStateSubscription;
943
969
  /**
@@ -1036,14 +1062,21 @@ declare class DeepdotsPopups {
1036
1062
  * El host la llama en cada cambio de pantalla; emite `page_view` al salir de la anterior.
1037
1063
  */
1038
1064
  setScreen(name: string): void;
1039
- /** App a foreground (RN: AppState 'active'): reanuda el engagement time y abre sesión nueva. */
1065
+ /**
1066
+ * App a foreground (RN: AppState 'active'): reanuda el engagement time. Si la app estuvo en
1067
+ * background menos de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS sigue en la misma sesión
1068
+ * (`deepdots_session_resume`); si no, abre una nueva (`session_start` `foreground`).
1069
+ */
1040
1070
  onForeground(): void;
1041
1071
  /**
1042
- * App a background (RN: AppState 'background'): FIN DE SESIÓN. Cierra pantalla actual
1043
- * (page_view), mini-services (mini_service_exit), emite engagement + `session_end` y
1044
- * envía el último lote con `completed:true`.
1045
- *
1046
- * Es la única señal disponible en móvil: el kill de la app (swipe) NO da callback.
1072
+ * App a background (RN: AppState 'background'): SUSPENDE la sesión. Cierra la pantalla
1073
+ * actual (page_view), los mini-services (mini_service_exit) y envía lo acumulado con un
1074
+ * `deepdots_session_suspend` (`reason: background`) y SIN `completed`:
1075
+ * - si la app vuelve dentro de ANALYTICS_BACKGROUND_RESUME_WINDOW_MS, `onForeground` sigue
1076
+ * en el mismo registro;
1077
+ * - si no vuelve (o la matan: el swipe NO da callback), el backend la cierra pasados unos
1078
+ * minutos con un `session_end` `background` a la hora de la suspensión.
1079
+ * Si aún no se conoce el registro (el primer POST sigue en vuelo), FIN DE SESIÓN como antes.
1047
1080
  */
1048
1081
  onBackground(): void;
1049
1082
  /**
@@ -1072,6 +1105,13 @@ declare class DeepdotsPopups {
1072
1105
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
1073
1106
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
1074
1107
  *
1108
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
1109
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
1110
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
1111
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
1112
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
1113
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
1114
+ *
1075
1115
  * Equivale a llamar a `init()` otra vez con otro `userId`.
1076
1116
  */
1077
1117
  setUserId(userId?: string): void;
@@ -1108,6 +1148,7 @@ declare class DeepdotsPopups {
1108
1148
  flushAnalytics(options?: {
1109
1149
  final?: boolean;
1110
1150
  sessionEnd?: boolean;
1151
+ persist?: boolean;
1111
1152
  }): void;
1112
1153
  /**
1113
1154
  * Emite un evento `user_engagement` con el tiempo activo acumulado (#8) y la pantalla en
@@ -1143,8 +1184,12 @@ declare class DeepdotsPopups {
1143
1184
  * - si la página vuelve a cargar en esta pestaña, `init()` sigue en el mismo registro;
1144
1185
  * - si la pestaña se cerró, el backend lo cierra a los pocos minutos sin otro lote.
1145
1186
  *
1187
+ * En React Native (`background`) la suspensión vive en memoria: la app sigue viva en
1188
+ * background y, si el SO la mata, el arranque siguiente es otra sesión (`cold_start`).
1189
+ *
1146
1190
  * Devuelve false cuando no se puede suspender — aún no se conoce el registro (el primer
1147
- * POST sigue en vuelo) o no hay `sessionStorage` — y entonces el caller cierra como antes.
1191
+ * POST sigue en vuelo) o, en web, no hay `sessionStorage` — y entonces el caller cierra
1192
+ * como antes.
1148
1193
  */
1149
1194
  private suspendSession;
1150
1195
  /**
@@ -1155,11 +1200,23 @@ declare class DeepdotsPopups {
1155
1200
  private readResumableSession;
1156
1201
  /**
1157
1202
  * Consume la sesión suspendida al abrir: los ms que estuvo suspendida si se puede seguir en
1158
- * ella (mismo usuario, dentro de ANALYTICS_RESUME_WINDOW_MS); null si no había o ya no toca.
1203
+ * ella (mismo usuario, dentro de su ventana: ANALYTICS_RESUME_WINDOW_MS tras un `pagehide`,
1204
+ * ANALYTICS_BACKGROUND_RESUME_WINDOW_MS tras un background); null si no había o ya no toca.
1159
1205
  * En ese caso se olvida su registro sin enviar nada: lo cierra el backend, y la sesión que
1160
1206
  * se abre ahora va a uno nuevo.
1161
1207
  */
1162
1208
  private takeSuspendedSession;
1209
+ /**
1210
+ * `pagehide` de una pestaña que llevaba oculta más de ANALYTICS_SESSION_TIMEOUT_MS: la
1211
+ * misma regla que `onDocumentVisible`. Suspenderla mandaba un lote más al registro viejo
1212
+ * (page_view + session_suspend) aunque el backend ya lo hubiera cerrado por inactividad:
1213
+ * el backend lo volvía a montar y las acciones de FEEDBACK_DONE (el aviso de Slack de
1214
+ * #platform-visitors) salían otra vez, horas después. Pasó con una pestaña oculta 7 h.
1215
+ * - Oculta menos de ANALYTICS_SESSION_DISCARD_MS: se cierra con `idle_timeout`.
1216
+ * - Más: el backend ya la cerró → se descarta sin enviar nada.
1217
+ * Devuelve false si la pestaña no llevaba tanto oculta (el caller suspende como siempre).
1218
+ */
1219
+ private closeStaleHiddenSession;
1163
1220
  /** Olvida la sesión abierta sin enviar nada (ver onDocumentVisible). */
1164
1221
  private discardSession;
1165
1222
  /**
@@ -1488,7 +1545,7 @@ declare const REVEAL_TIMEOUT_MS = 1200;
1488
1545
  * resolución, para que las tres rutas (popup DOM web, WebView de RN y Compose) digan lo mismo.
1489
1546
  */
1490
1547
  /** Locales con traducción propia. Cualquier otro idioma cae a `en`. */
1491
- type PopupLocale = 'en' | 'es' | 'da' | 'no' | 'sv' | 'fi' | 'de' | 'fr' | 'pt' | 'ar' | 'bn' | 'zh-CN' | 'bg' | 'cs' | 'el' | 'et' | 'ga' | 'hr' | 'hu' | 'it' | 'lt' | 'lv' | 'mt' | 'nl' | 'pl' | 'ro' | 'sk' | 'sl';
1548
+ type PopupLocale = 'en' | 'es' | 'da' | 'no' | 'sv' | 'fi' | 'de' | 'fr' | 'pt' | 'ar' | 'bn' | 'zh-CN' | 'bg' | 'cs' | 'el' | 'et' | 'ga' | 'hr' | 'hu' | 'it' | 'lt' | 'lv' | 'mt' | 'nl' | 'pl' | 'ro' | 'sk' | 'sl' | 'ca';
1492
1549
  interface PopupLabels {
1493
1550
  /** Acción principal: enviar la respuesta. */
1494
1551
  accept: string;
@@ -1613,4 +1670,42 @@ declare function collectRnDevice(d: DeviceInfoLike): DeviceInfo;
1613
1670
  */
1614
1671
  declare function setupReactNative(sdk: DeepdotsPopups, config: DeepdotsInitParams, deps?: ReactNativeSetupDeps): () => void;
1615
1672
 
1616
- export { type AnalyticsFeedbackBody, type AnalyticsKeys, type AppStateLike, type AutoTrackOptions, BACKGROUND_TASK_MAX_MS, type BackgroundTaskRunner, type BackgroundTimerLike, BrowserPopupRenderer, type BuildBodyOptions, type ContactAttributeValue, type ContactAttributes, type ContactBody, ContactManager, type CrashRecord, CrashReporter, type CrashSeverity, type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, type DeepdotsInitParams, type DeepdotsLogger, DeepdotsPopups, type DeviceInfo, type DeviceInfoLike, type DeviceSnapshot, type EventListener, type FeedbackKV, type FeedbackSession, InMemoryStorage, type KeyValueStorage, LABELS, MAX_TRACKED_MESSAGES, MESSAGE_CHANNELS, type MessageChannel, MessageGuard, type MessageGuardVerdict, type MessageRejectionReason, type MessageStage, type MmkvLike, NATIVE_READY_GRACE_MS, NoopPopupRenderer, POPUP_TRIGGER_CONDITION_STATUSES, type PopupDefinition, type PopupLabels, type PopupLocale, type PopupRenderer, type PopupTrigger, type PopupTriggerCondition, type PopupTriggerConditionStatus, REVEAL_TIMEOUT_MS, RTL_LOCALES, type ReactNativeErrorUtils, ReactNativePopupRenderer, type ReactNativeRendererOptions, type ReactNativeSetupDeps, type ReactNativeSurveyPayload, type ReportErrorOptions, type ResolvedActionLabels, SUPPORTED_LANGUAGES, type SessionEndReason, type SessionStartReason, type TrackMessageOptions, type TriggerConfig, backgroundTimerTask, buildAnalyticsFeedbackBody, buildMessageParams, buildSurveyHtml, collectRnDevice, crashRecordToParams, createDefaultRenderer, createFeedbackSink, directionFor, getLabels, isRtlLanguage, mmkvStorage, resolveActionLabels, resolveLocale, setupReactNative };
1673
+ /**
1674
+ * Lo que el SDK necesita de React Native para detectar solo el ciclo de vida y el tiempo de
1675
+ * background (DD-55, contrato de detección automática). El core no importa `react-native` (se
1676
+ * usa también en web): lo registra la entrada de React Native del paquete
1677
+ * (`src/index.native.ts`, que Metro elige por la condición `react-native`) y el Provider.
1678
+ */
1679
+
1680
+ /** Opciones de `HermesInternal.enablePromiseRejectionTracker` (las mismas que `promise/rejection-tracking`). */
1681
+ interface RejectionTrackingOptions {
1682
+ allRejections?: boolean;
1683
+ onUnhandled?: (id: number, error: unknown) => void;
1684
+ onHandled?: (id: number, error?: unknown) => void;
1685
+ }
1686
+ /** Lo que el SDK necesita de `global.HermesInternal`. */
1687
+ interface HermesRejectionTrackerLike {
1688
+ enablePromiseRejectionTracker?: (options?: RejectionTrackingOptions) => void;
1689
+ }
1690
+ interface PromiseRejectionHub {
1691
+ /** Avisa de cada promesa rechazada sin `catch`. Devuelve la función que lo quita. */
1692
+ addUnhandledListener(listener: (error: unknown) => void): () => void;
1693
+ }
1694
+ /**
1695
+ * Promesas rechazadas sin `catch` en React Native (contrato de detección automática, paso 2).
1696
+ *
1697
+ * Hermes solo admite UN tracker (`enablePromiseRejectionTracker` sustituye al anterior) y no deja
1698
+ * leer el que hay. Para no quitarle las rejections a Sentry/Crashlytics, la entrada de React
1699
+ * Native envuelve la función al importarse el paquete, que es antes de que el código de la app
1700
+ * llame a `Sentry.init()` (los imports se evalúan primero): lo que instale después cualquiera se
1701
+ * compone con lo nuestro en vez de sustituirlo. Antes del import solo lo pudo instalar React
1702
+ * Native, y solo en desarrollo (el aviso "Possible unhandled promise rejection"), que se mantiene
1703
+ * con `dev`. Mientras el SDK no se engancha, la función envuelta pasa todo tal cual a Hermes.
1704
+ *
1705
+ * Devuelve null sin Hermes o sin el tracker (JSC): el SDK sigue sin capturarlas, como antes.
1706
+ */
1707
+ declare function createHermesRejectionHub(hermes: HermesRejectionTrackerLike | null | undefined, options: {
1708
+ dev: boolean;
1709
+ }): PromiseRejectionHub | null;
1710
+
1711
+ export { type AnalyticsFeedbackBody, type AnalyticsKeys, type AppStateLike, type AutoTrackOptions, BACKGROUND_TASK_MAX_MS, type BackgroundTaskRunner, type BackgroundTimerLike, BrowserPopupRenderer, type BuildBodyOptions, type ContactAttributeValue, type ContactAttributes, type ContactBody, ContactManager, type CrashRecord, CrashReporter, type CrashSeverity, type DeepdotsConfig, type DeepdotsEvent, type DeepdotsEventType, type DeepdotsInitParams, type DeepdotsLogger, DeepdotsPopups, type DeviceInfo, type DeviceInfoLike, type DeviceSnapshot, type EventListener, type FeedbackKV, type FeedbackSession, type HermesRejectionTrackerLike, InMemoryStorage, type KeyValueStorage, LABELS, MAX_TRACKED_MESSAGES, MESSAGE_CHANNELS, type MessageChannel, MessageGuard, type MessageGuardVerdict, type MessageRejectionReason, type MessageStage, type MmkvLike, NATIVE_READY_GRACE_MS, NoopPopupRenderer, POPUP_TRIGGER_CONDITION_STATUSES, type PopupDefinition, type PopupLabels, type PopupLocale, type PopupRenderer, type PopupTrigger, type PopupTriggerCondition, type PopupTriggerConditionStatus, type PromiseRejectionHub, REVEAL_TIMEOUT_MS, RTL_LOCALES, type ReactNativeErrorUtils, ReactNativePopupRenderer, type ReactNativeRendererOptions, type ReactNativeSetupDeps, type ReactNativeSurveyPayload, type RejectionTrackingOptions, type ReportErrorOptions, type ResolvedActionLabels, SUPPORTED_LANGUAGES, type SessionEndReason, type SessionStartReason, type TrackMessageOptions, type TriggerConfig, backgroundTimerTask, buildAnalyticsFeedbackBody, buildMessageParams, buildSurveyHtml, collectRnDevice, crashRecordToParams, createDefaultRenderer, createFeedbackSink, createHermesRejectionHub, directionFor, getLabels, isRtlLanguage, mmkvStorage, resolveActionLabels, resolveLocale, setupReactNative };