@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
@@ -29,7 +29,7 @@ import {
29
29
  style_default,
30
30
  surveySdkCssUrls,
31
31
  surveySdkUrls
32
- } from "./chunk-7ZQOAKXR.mjs";
32
+ } from "./chunk-ZJ5HG3QF.mjs";
33
33
  import "./chunk-3QS3WKRC.mjs";
34
34
 
35
35
  // src/index.native.ts
@@ -64,6 +64,68 @@ function resolveBackgroundTask(explicit, platform) {
64
64
  }
65
65
  return void 0;
66
66
  }
67
+ var DEFAULT_REJECTION_WHITELIST = [ReferenceError, TypeError, RangeError];
68
+ function createHermesRejectionHub(hermes, options) {
69
+ if (!hermes || typeof hermes.enablePromiseRejectionTracker !== "function") return null;
70
+ const original = hermes.enablePromiseRejectionTracker.bind(hermes);
71
+ const listeners = /* @__PURE__ */ new Set();
72
+ let hostOptions = null;
73
+ let active = false;
74
+ const forwardsToHost = (error) => !!hostOptions?.onUnhandled && (hostOptions.allRejections === true || DEFAULT_REJECTION_WHITELIST.some((type) => error instanceof type));
75
+ const apply = () => {
76
+ original({
77
+ allRejections: true,
78
+ onUnhandled: (id, error) => {
79
+ listeners.forEach((listener) => {
80
+ try {
81
+ listener(error);
82
+ } catch {
83
+ }
84
+ });
85
+ if (hostOptions?.onUnhandled) {
86
+ if (forwardsToHost(error)) hostOptions.onUnhandled(id, error);
87
+ } else if (options.dev) {
88
+ console.warn(`Possible unhandled promise rejection (id: ${id}):`, error);
89
+ }
90
+ },
91
+ onHandled: (id, error) => hostOptions?.onHandled?.(id, error)
92
+ });
93
+ };
94
+ hermes.enablePromiseRejectionTracker = (next) => {
95
+ hostOptions = next ?? null;
96
+ if (active) apply();
97
+ else original(next);
98
+ };
99
+ return {
100
+ addUnhandledListener(listener) {
101
+ listeners.add(listener);
102
+ if (!active) {
103
+ active = true;
104
+ apply();
105
+ }
106
+ return () => {
107
+ listeners.delete(listener);
108
+ };
109
+ }
110
+ };
111
+ }
112
+
113
+ // src/platform/react-native-defaults.ts
114
+ var hub;
115
+ function registerReactNativeDefaults(rn) {
116
+ if (hub === void 0) {
117
+ hub = getReactNativePlatform()?.promiseRejections ?? createHermesRejectionHub(
118
+ globalThis.HermesInternal,
119
+ { dev: typeof __DEV__ !== "undefined" && !!__DEV__ }
120
+ );
121
+ }
122
+ registerReactNativePlatform({
123
+ os: rn.Platform.OS,
124
+ appState: rn.AppState,
125
+ backgroundTaskModule: rn.NativeModules?.DeepdotsBackgroundTask ?? null,
126
+ promiseRejections: hub
127
+ });
128
+ }
67
129
 
68
130
  // src/types/index.ts
69
131
  var POPUP_TRIGGER_CONDITION_STATUSES = [
@@ -1030,7 +1092,7 @@ function logRnSurveySdkChoice(choice, debug) {
1030
1092
  }
1031
1093
 
1032
1094
  // src/ui/preload.ts
1033
- var defaultLoader = () => import("./renderPopup-YDJUON42.mjs");
1095
+ var defaultLoader = () => import("./renderPopup-RUY3OBYV.mjs");
1034
1096
  var pending = null;
1035
1097
  function preloadRenderPopup(loader = defaultLoader) {
1036
1098
  if (pending) return pending;
@@ -1103,7 +1165,7 @@ var BrowserPopupRenderer = class {
1103
1165
  if (!this.container) return;
1104
1166
  this.visible = true;
1105
1167
  const container = this.container;
1106
- void import("./renderPopup-YDJUON42.mjs").then(
1168
+ void import("./renderPopup-RUY3OBYV.mjs").then(
1107
1169
  ({ renderPopup }) => {
1108
1170
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1109
1171
  },
@@ -2014,6 +2076,8 @@ var CrashReporter = class {
2014
2076
  this.windowInstalled = false;
2015
2077
  /** ErrorUtils ya enganchados: engancharlos dos veces capturaría cada error dos veces. */
2016
2078
  this.hookedErrorUtils = /* @__PURE__ */ new Set();
2079
+ /** Fuentes de rejections ya enganchadas (idempotente, como ErrorUtils). */
2080
+ this.hookedRejections = /* @__PURE__ */ new Set();
2017
2081
  this.options = options;
2018
2082
  this.now = options.now ?? (() => Date.now());
2019
2083
  }
@@ -2113,6 +2177,18 @@ var CrashReporter = class {
2113
2177
  previous?.(error, isFatal);
2114
2178
  });
2115
2179
  }
2180
+ /**
2181
+ * Promesas rechazadas sin `catch` en React Native: como el `unhandledrejection` de web, se
2182
+ * persisten y se reenvían en el arranque siguiente. La fuente encadena al tracker del host.
2183
+ * Idempotente por fuente.
2184
+ */
2185
+ installPromiseRejections(source) {
2186
+ if (this.hookedRejections.has(source)) return;
2187
+ this.hookedRejections.add(source);
2188
+ source.addUnhandledListener((error) => {
2189
+ if (this.isEnabled()) this.captureUnhandled(error ?? "unhandledrejection");
2190
+ });
2191
+ }
2116
2192
  /** @internal Test seam: ejercita el camino de persistencia (window handlers no son testeables en vitest). */
2117
2193
  _persistForTest(error) {
2118
2194
  this.captureUnhandled(error);
@@ -2351,6 +2427,8 @@ var DeepdotsPopups = class {
2351
2427
  this.lastEngagementAt = 0;
2352
2428
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
2353
2429
  this.hiddenAt = null;
2430
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
2431
+ this.autoTrackErrors = true;
2354
2432
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
2355
2433
  this.appStateSubscription = void 0;
2356
2434
  /**
@@ -2397,6 +2475,7 @@ var DeepdotsPopups = class {
2397
2475
  this.surveyCss = config.surveyCss;
2398
2476
  this.cspNonce = config.cspNonce;
2399
2477
  this.onFeedbackSession = config.onFeedbackSession;
2478
+ this.autoTrackErrors = config.autoTrack?.errors !== false;
2400
2479
  this.config = {
2401
2480
  apiKey: config.apiKey || void 0,
2402
2481
  debug: config.debug || false,
@@ -2595,11 +2674,14 @@ var DeepdotsPopups = class {
2595
2674
  */
2596
2675
  installCrashHandlers() {
2597
2676
  if (!this.crashReporter || !this.tracking?.isTrackingEnabled()) return;
2598
- this.crashReporter.install();
2599
- const errorUtils = this.rnErrorUtils ?? globalThis.ErrorUtils;
2677
+ const auto = this.autoTrackErrors;
2678
+ if (auto) this.crashReporter.install();
2679
+ const errorUtils = this.rnErrorUtils ?? (auto ? globalThis.ErrorUtils : void 0);
2600
2680
  if (errorUtils && typeof errorUtils.setGlobalHandler === "function") {
2601
2681
  this.crashReporter.installReactNative(errorUtils);
2602
2682
  }
2683
+ const rejections = auto ? getReactNativePlatform()?.promiseRejections : null;
2684
+ if (rejections) this.crashReporter.installPromiseRejections(rejections);
2603
2685
  }
2604
2686
  /**
2605
2687
  * Info interna del usuario que solo conoce el host (idioma, edad, plan…), persistida en el
@@ -2745,11 +2827,24 @@ var DeepdotsPopups = class {
2745
2827
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
2746
2828
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
2747
2829
  *
2830
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
2831
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
2832
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
2833
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
2834
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
2835
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
2836
+ *
2748
2837
  * Equivale a llamar a `init()` otra vez con otro `userId`.
2749
2838
  */
2750
2839
  setUserId(userId) {
2751
2840
  const next = userId || void 0;
2752
2841
  if (!this.initialized || !this.config || next === this.config.userId) return;
2842
+ const identifying = !this.config.userId && !!next;
2843
+ const previous = identifying ? {
2844
+ identified: true,
2845
+ previous_user_id: this.tracking?.getUserId() ?? void 0,
2846
+ previous_session_id: this.analyticsFeedbackSessionId
2847
+ } : void 0;
2753
2848
  this.closeSession("user_change");
2754
2849
  const enabled = this.tracking?.isTrackingEnabled() ?? true;
2755
2850
  const storage = this.storage ?? createDefaultStorage();
@@ -2762,13 +2857,18 @@ var DeepdotsPopups = class {
2762
2857
  post: (body) => this.postContact(body)
2763
2858
  }) : null;
2764
2859
  this.analytics?.resetUserScope();
2765
- this.messageGuard.reset();
2766
- this.lastShown.clear();
2767
- this.surveyProgress.clear();
2768
- this.answeredSurveys.clear();
2769
- clearPopupState(storage);
2770
- this.log("tracking \xB7 user_change \xB7 user_id:", this.tracking.getUserId());
2771
- this.openSession("user_change");
2860
+ if (!identifying) {
2861
+ this.messageGuard.reset();
2862
+ this.lastShown.clear();
2863
+ this.surveyProgress.clear();
2864
+ this.answeredSurveys.clear();
2865
+ clearPopupState(storage);
2866
+ }
2867
+ this.log(
2868
+ identifying ? "tracking \xB7 user identified \xB7 user_id:" : "tracking \xB7 user_change \xB7 user_id:",
2869
+ this.tracking.getUserId()
2870
+ );
2871
+ this.openSession("user_change", previous);
2772
2872
  }
2773
2873
  /**
2774
2874
  * Cierra la sesión actual: vuelca todo lo que quedaba abierto y envía el último lote
@@ -2804,14 +2904,14 @@ var DeepdotsPopups = class {
2804
2904
  * - `bfcache_restore`: vuelta desde la bfcache fuera de la ventana de reanudación.
2805
2905
  * Si hay una sesión suspendida a tiempo emite `deepdots_session_resume` en su lugar, sin reason.
2806
2906
  */
2807
- openSession(reason) {
2907
+ openSession(reason, extra) {
2808
2908
  if (this.sessionOpen) return;
2809
2909
  if (!this.tracking?.isTrackingEnabled()) return;
2810
2910
  const suspendedMs = this.takeSuspendedSession();
2811
2911
  this.sessionOpen = true;
2812
2912
  this.lastEngagementAt = Date.now();
2813
2913
  if (suspendedMs === null) {
2814
- this.track("deepdots_session_start", { reason });
2914
+ this.track("deepdots_session_start", { reason, ...extra });
2815
2915
  } else {
2816
2916
  this.track("deepdots_session_resume", { suspended_ms: suspendedMs });
2817
2917
  this.log("tracking \xB7 session resumed after", suspendedMs, "ms:", this.analyticsFeedbackSessionId);
@@ -3872,11 +3972,7 @@ function setupReactNative(sdk, config, deps = {}) {
3872
3972
  }
3873
3973
 
3874
3974
  // src/index.native.ts
3875
- registerReactNativePlatform({
3876
- os: Platform.OS,
3877
- appState: AppState,
3878
- backgroundTaskModule: NativeModules?.DeepdotsBackgroundTask ?? null
3879
- });
3975
+ registerReactNativeDefaults({ AppState, NativeModules, Platform });
3880
3976
  export {
3881
3977
  BACKGROUND_TASK_MAX_MS,
3882
3978
  BrowserPopupRenderer,
@@ -3903,6 +3999,7 @@ export {
3903
3999
  crashRecordToParams,
3904
4000
  createDefaultRenderer,
3905
4001
  createFeedbackSink,
4002
+ createHermesRejectionHub,
3906
4003
  directionFor,
3907
4004
  getLabels,
3908
4005
  isRtlLanguage,