@magicfeedback/popup-sdk 1.19.0 → 1.20.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-FROREHRG.mjs} +23 -3
  2. package/dist/chunk-FROREHRG.mjs.map +1 -0
  3. package/dist/{chunk-XOEEBDBJ.mjs → chunk-OPR5I7WO.mjs} +26 -4
  4. package/dist/chunk-OPR5I7WO.mjs.map +1 -0
  5. package/dist/{chunk-7ZQOAKXR.mjs → chunk-ZJ5HG3QF.mjs} +26 -4
  6. package/dist/chunk-ZJ5HG3QF.mjs.map +1 -0
  7. package/dist/index.d.mts +67 -2
  8. package/dist/index.d.ts +67 -2
  9. package/dist/index.js +121 -15
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +98 -14
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/index.native.d.mts +67 -2
  14. package/dist/index.native.d.ts +67 -2
  15. package/dist/index.native.js +139 -20
  16. package/dist/index.native.js.map +1 -1
  17. package/dist/index.native.mjs +116 -19
  18. package/dist/index.native.mjs.map +1 -1
  19. package/dist/react-native.d.mts +15 -0
  20. package/dist/react-native.d.ts +15 -0
  21. package/dist/react-native.js +135 -19
  22. package/dist/react-native.js.map +1 -1
  23. package/dist/react-native.mjs +115 -19
  24. package/dist/react-native.mjs.map +1 -1
  25. package/dist/{renderPopup-ZHTRMFO2.mjs → renderPopup-I6CPIR75.mjs} +2 -2
  26. package/dist/{renderPopup-2Y4QMWR7.mjs → renderPopup-RUY3OBYV.mjs} +2 -2
  27. package/dist/{renderPopup-YDJUON42.mjs → renderPopup-XNVNP2ZU.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-ZHTRMFO2.mjs.map → renderPopup-I6CPIR75.mjs.map} +0 -0
  33. /package/dist/{renderPopup-2Y4QMWR7.mjs.map → renderPopup-RUY3OBYV.mjs.map} +0 -0
  34. /package/dist/{renderPopup-YDJUON42.mjs.map → renderPopup-XNVNP2ZU.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  style_default,
30
30
  surveySdkCssUrls,
31
31
  surveySdkUrls
32
- } from "./chunk-XOEEBDBJ.mjs";
32
+ } from "./chunk-OPR5I7WO.mjs";
33
33
  import "./chunk-3QS3WKRC.mjs";
34
34
 
35
35
  // src/types/index.ts
@@ -997,7 +997,7 @@ function logRnSurveySdkChoice(choice, debug) {
997
997
  }
998
998
 
999
999
  // src/ui/preload.ts
1000
- var defaultLoader = () => import("./renderPopup-2Y4QMWR7.mjs");
1000
+ var defaultLoader = () => import("./renderPopup-XNVNP2ZU.mjs");
1001
1001
  var pending = null;
1002
1002
  function preloadRenderPopup(loader = defaultLoader) {
1003
1003
  if (pending) return pending;
@@ -1070,7 +1070,7 @@ var BrowserPopupRenderer = class {
1070
1070
  if (!this.container) return;
1071
1071
  this.visible = true;
1072
1072
  const container = this.container;
1073
- void import("./renderPopup-2Y4QMWR7.mjs").then(
1073
+ void import("./renderPopup-XNVNP2ZU.mjs").then(
1074
1074
  ({ renderPopup }) => {
1075
1075
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1076
1076
  },
@@ -1981,6 +1981,8 @@ var CrashReporter = class {
1981
1981
  this.windowInstalled = false;
1982
1982
  /** ErrorUtils ya enganchados: engancharlos dos veces capturaría cada error dos veces. */
1983
1983
  this.hookedErrorUtils = /* @__PURE__ */ new Set();
1984
+ /** Fuentes de rejections ya enganchadas (idempotente, como ErrorUtils). */
1985
+ this.hookedRejections = /* @__PURE__ */ new Set();
1984
1986
  this.options = options;
1985
1987
  this.now = options.now ?? (() => Date.now());
1986
1988
  }
@@ -2080,6 +2082,18 @@ var CrashReporter = class {
2080
2082
  previous?.(error, isFatal);
2081
2083
  });
2082
2084
  }
2085
+ /**
2086
+ * Promesas rechazadas sin `catch` en React Native: como el `unhandledrejection` de web, se
2087
+ * persisten y se reenvían en el arranque siguiente. La fuente encadena al tracker del host.
2088
+ * Idempotente por fuente.
2089
+ */
2090
+ installPromiseRejections(source) {
2091
+ if (this.hookedRejections.has(source)) return;
2092
+ this.hookedRejections.add(source);
2093
+ source.addUnhandledListener((error) => {
2094
+ if (this.isEnabled()) this.captureUnhandled(error ?? "unhandledrejection");
2095
+ });
2096
+ }
2083
2097
  /** @internal Test seam: ejercita el camino de persistencia (window handlers no son testeables en vitest). */
2084
2098
  _persistForTest(error) {
2085
2099
  this.captureUnhandled(error);
@@ -2181,6 +2195,51 @@ function resolveBackgroundTask(explicit, platform) {
2181
2195
  }
2182
2196
  return void 0;
2183
2197
  }
2198
+ var DEFAULT_REJECTION_WHITELIST = [ReferenceError, TypeError, RangeError];
2199
+ function createHermesRejectionHub(hermes, options) {
2200
+ if (!hermes || typeof hermes.enablePromiseRejectionTracker !== "function") return null;
2201
+ const original = hermes.enablePromiseRejectionTracker.bind(hermes);
2202
+ const listeners = /* @__PURE__ */ new Set();
2203
+ let hostOptions = null;
2204
+ let active = false;
2205
+ const forwardsToHost = (error) => !!hostOptions?.onUnhandled && (hostOptions.allRejections === true || DEFAULT_REJECTION_WHITELIST.some((type) => error instanceof type));
2206
+ const apply = () => {
2207
+ original({
2208
+ allRejections: true,
2209
+ onUnhandled: (id, error) => {
2210
+ listeners.forEach((listener) => {
2211
+ try {
2212
+ listener(error);
2213
+ } catch {
2214
+ }
2215
+ });
2216
+ if (hostOptions?.onUnhandled) {
2217
+ if (forwardsToHost(error)) hostOptions.onUnhandled(id, error);
2218
+ } else if (options.dev) {
2219
+ console.warn(`Possible unhandled promise rejection (id: ${id}):`, error);
2220
+ }
2221
+ },
2222
+ onHandled: (id, error) => hostOptions?.onHandled?.(id, error)
2223
+ });
2224
+ };
2225
+ hermes.enablePromiseRejectionTracker = (next) => {
2226
+ hostOptions = next ?? null;
2227
+ if (active) apply();
2228
+ else original(next);
2229
+ };
2230
+ return {
2231
+ addUnhandledListener(listener) {
2232
+ listeners.add(listener);
2233
+ if (!active) {
2234
+ active = true;
2235
+ apply();
2236
+ }
2237
+ return () => {
2238
+ listeners.delete(listener);
2239
+ };
2240
+ }
2241
+ };
2242
+ }
2184
2243
 
2185
2244
  // src/analytics/messaging.ts
2186
2245
  var MESSAGE_CHANNELS = ["push", "in_app"];
@@ -2345,6 +2404,8 @@ var DeepdotsPopups = class {
2345
2404
  this.lastEngagementAt = 0;
2346
2405
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
2347
2406
  this.hiddenAt = null;
2407
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
2408
+ this.autoTrackErrors = true;
2348
2409
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
2349
2410
  this.appStateSubscription = void 0;
2350
2411
  /**
@@ -2391,6 +2452,7 @@ var DeepdotsPopups = class {
2391
2452
  this.surveyCss = config.surveyCss;
2392
2453
  this.cspNonce = config.cspNonce;
2393
2454
  this.onFeedbackSession = config.onFeedbackSession;
2455
+ this.autoTrackErrors = config.autoTrack?.errors !== false;
2394
2456
  this.config = {
2395
2457
  apiKey: config.apiKey || void 0,
2396
2458
  debug: config.debug || false,
@@ -2589,11 +2651,14 @@ var DeepdotsPopups = class {
2589
2651
  */
2590
2652
  installCrashHandlers() {
2591
2653
  if (!this.crashReporter || !this.tracking?.isTrackingEnabled()) return;
2592
- this.crashReporter.install();
2593
- const errorUtils = this.rnErrorUtils ?? globalThis.ErrorUtils;
2654
+ const auto = this.autoTrackErrors;
2655
+ if (auto) this.crashReporter.install();
2656
+ const errorUtils = this.rnErrorUtils ?? (auto ? globalThis.ErrorUtils : void 0);
2594
2657
  if (errorUtils && typeof errorUtils.setGlobalHandler === "function") {
2595
2658
  this.crashReporter.installReactNative(errorUtils);
2596
2659
  }
2660
+ const rejections = auto ? getReactNativePlatform()?.promiseRejections : null;
2661
+ if (rejections) this.crashReporter.installPromiseRejections(rejections);
2597
2662
  }
2598
2663
  /**
2599
2664
  * Info interna del usuario que solo conoce el host (idioma, edad, plan…), persistida en el
@@ -2739,11 +2804,24 @@ var DeepdotsPopups = class {
2739
2804
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
2740
2805
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
2741
2806
  *
2807
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
2808
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
2809
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
2810
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
2811
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
2812
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
2813
+ *
2742
2814
  * Equivale a llamar a `init()` otra vez con otro `userId`.
2743
2815
  */
2744
2816
  setUserId(userId) {
2745
2817
  const next = userId || void 0;
2746
2818
  if (!this.initialized || !this.config || next === this.config.userId) return;
2819
+ const identifying = !this.config.userId && !!next;
2820
+ const previous = identifying ? {
2821
+ identified: true,
2822
+ previous_user_id: this.tracking?.getUserId() ?? void 0,
2823
+ previous_session_id: this.analyticsFeedbackSessionId
2824
+ } : void 0;
2747
2825
  this.closeSession("user_change");
2748
2826
  const enabled = this.tracking?.isTrackingEnabled() ?? true;
2749
2827
  const storage = this.storage ?? createDefaultStorage();
@@ -2756,13 +2834,18 @@ var DeepdotsPopups = class {
2756
2834
  post: (body) => this.postContact(body)
2757
2835
  }) : null;
2758
2836
  this.analytics?.resetUserScope();
2759
- this.messageGuard.reset();
2760
- this.lastShown.clear();
2761
- this.surveyProgress.clear();
2762
- this.answeredSurveys.clear();
2763
- clearPopupState(storage);
2764
- this.log("tracking \xB7 user_change \xB7 user_id:", this.tracking.getUserId());
2765
- this.openSession("user_change");
2837
+ if (!identifying) {
2838
+ this.messageGuard.reset();
2839
+ this.lastShown.clear();
2840
+ this.surveyProgress.clear();
2841
+ this.answeredSurveys.clear();
2842
+ clearPopupState(storage);
2843
+ }
2844
+ this.log(
2845
+ identifying ? "tracking \xB7 user identified \xB7 user_id:" : "tracking \xB7 user_change \xB7 user_id:",
2846
+ this.tracking.getUserId()
2847
+ );
2848
+ this.openSession("user_change", previous);
2766
2849
  }
2767
2850
  /**
2768
2851
  * Cierra la sesión actual: vuelca todo lo que quedaba abierto y envía el último lote
@@ -2798,14 +2881,14 @@ var DeepdotsPopups = class {
2798
2881
  * - `bfcache_restore`: vuelta desde la bfcache fuera de la ventana de reanudación.
2799
2882
  * Si hay una sesión suspendida a tiempo emite `deepdots_session_resume` en su lugar, sin reason.
2800
2883
  */
2801
- openSession(reason) {
2884
+ openSession(reason, extra) {
2802
2885
  if (this.sessionOpen) return;
2803
2886
  if (!this.tracking?.isTrackingEnabled()) return;
2804
2887
  const suspendedMs = this.takeSuspendedSession();
2805
2888
  this.sessionOpen = true;
2806
2889
  this.lastEngagementAt = Date.now();
2807
2890
  if (suspendedMs === null) {
2808
- this.track("deepdots_session_start", { reason });
2891
+ this.track("deepdots_session_start", { reason, ...extra });
2809
2892
  } else {
2810
2893
  this.track("deepdots_session_resume", { suspended_ms: suspendedMs });
2811
2894
  this.log("tracking \xB7 session resumed after", suspendedMs, "ms:", this.analyticsFeedbackSessionId);
@@ -3890,6 +3973,7 @@ export {
3890
3973
  crashRecordToParams,
3891
3974
  createDefaultRenderer,
3892
3975
  createFeedbackSink,
3976
+ createHermesRejectionHub,
3893
3977
  directionFor,
3894
3978
  getLabels,
3895
3979
  isRtlLanguage,