@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
@@ -151,6 +151,12 @@ interface FeedbackSession {
151
151
  interface AutoTrackOptions {
152
152
  /** React Native: listen to `AppState` for session start/end. Default `true`. */
153
153
  lifecycle?: boolean;
154
+ /**
155
+ * Uncaught errors: `window` `error`/`unhandledrejection` (web), `ErrorUtils` and promise
156
+ * rejections without `catch` under Hermes (React Native). Default `true`. Handlers installed
157
+ * by other tools (Sentry, Crashlytics) keep receiving everything.
158
+ */
159
+ errors?: boolean;
154
160
  }
155
161
  interface DeepdotsInitParams {
156
162
  /** API key for authentication */
@@ -532,6 +538,8 @@ declare class DeepdotsPopups {
532
538
  private lastEngagementAt;
533
539
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
534
540
  private hiddenAt;
541
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
542
+ private autoTrackErrors;
535
543
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
536
544
  private appStateSubscription;
537
545
  /**
@@ -666,6 +674,13 @@ declare class DeepdotsPopups {
666
674
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
667
675
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
668
676
  *
677
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
678
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
679
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
680
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
681
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
682
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
683
+ *
669
684
  * Equivale a llamar a `init()` otra vez con otro `userId`.
670
685
  */
671
686
  setUserId(userId?: string): void;
@@ -151,6 +151,12 @@ interface FeedbackSession {
151
151
  interface AutoTrackOptions {
152
152
  /** React Native: listen to `AppState` for session start/end. Default `true`. */
153
153
  lifecycle?: boolean;
154
+ /**
155
+ * Uncaught errors: `window` `error`/`unhandledrejection` (web), `ErrorUtils` and promise
156
+ * rejections without `catch` under Hermes (React Native). Default `true`. Handlers installed
157
+ * by other tools (Sentry, Crashlytics) keep receiving everything.
158
+ */
159
+ errors?: boolean;
154
160
  }
155
161
  interface DeepdotsInitParams {
156
162
  /** API key for authentication */
@@ -532,6 +538,8 @@ declare class DeepdotsPopups {
532
538
  private lastEngagementAt;
533
539
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
534
540
  private hiddenAt;
541
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
542
+ private autoTrackErrors;
535
543
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
536
544
  private appStateSubscription;
537
545
  /**
@@ -666,6 +674,13 @@ declare class DeepdotsPopups {
666
674
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
667
675
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
668
676
  *
677
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
678
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
679
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
680
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
681
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
682
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
683
+ *
669
684
  * Equivale a llamar a `init()` otra vez con otro `userId`.
670
685
  */
671
686
  setUserId(userId?: string): void;
@@ -38,7 +38,7 @@ var SDK_VERSION, SDK_IDENTIFIER, POPUP_CHANNEL;
38
38
  var init_version = __esm({
39
39
  "src/version.ts"() {
40
40
  "use strict";
41
- SDK_VERSION = "1.19.0";
41
+ SDK_VERSION = "1.20.0";
42
42
  SDK_IDENTIFIER = `${"react-native"}@${SDK_VERSION}`;
43
43
  POPUP_CHANNEL = "popup";
44
44
  }
@@ -307,6 +307,8 @@ function resolveLocale(lang) {
307
307
  return "sk";
308
308
  case "sl":
309
309
  return "sl";
310
+ case "ca":
311
+ return "ca";
310
312
  default:
311
313
  return "en";
312
314
  }
@@ -334,7 +336,7 @@ function resolveActionLabels(actions, lang) {
334
336
  back: pick(actions?.back?.label, labels.back)
335
337
  };
336
338
  }
337
- var 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, LABELS, RTL_LOCALES, RESOLVE_LOCALE_JS;
339
+ var 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, LABELS, RTL_LOCALES, RESOLVE_LOCALE_JS;
338
340
  var init_labels = __esm({
339
341
  "src/i18n/labels.ts"() {
340
342
  "use strict";
@@ -786,6 +788,22 @@ var init_labels = __esm({
786
788
  errorSubmit: "Pri po\u0161iljanju je pri\u0161lo do napake. Poskusite znova ali zaprite okno.",
787
789
  errorLoad: "Ankete ni bilo mogo\u010De nalo\u017Eiti."
788
790
  };
791
+ CA = {
792
+ accept: "Envia",
793
+ decline: "Cancel\xB7la",
794
+ start: "Comen\xE7a l'enquesta",
795
+ complete: "Completa l'enquesta",
796
+ back: "Enrere",
797
+ question: "Pregunta",
798
+ of: "de",
799
+ followUp: "Seguiment",
800
+ closeAria: "Tanca la finestra emergent",
801
+ loadingAria: "S'est\xE0 carregant l'enquesta",
802
+ errorRequired: "Respon la pregunta obligat\xF2ria per continuar.",
803
+ errorInvalidEmail: "Introdueix una adre\xE7a de correu electr\xF2nic v\xE0lida.",
804
+ errorSubmit: "S'ha produ\xEFt un error en enviar. Torna-ho a provar o tanca la finestra.",
805
+ errorLoad: "No s'ha pogut carregar l'enquesta."
806
+ };
789
807
  LABELS = {
790
808
  en: EN,
791
809
  es: ES,
@@ -814,7 +832,8 @@ var init_labels = __esm({
814
832
  pl: PL,
815
833
  ro: RO,
816
834
  sk: SK,
817
- sl: SL
835
+ sl: SL,
836
+ ca: CA
818
837
  };
819
838
  RTL_LOCALES = ["ar"];
820
839
  RESOLVE_LOCALE_JS = `function ddResolveLocale(lang){
@@ -850,6 +869,7 @@ var init_labels = __esm({
850
869
  if(p==='ro') return 'ro';
851
870
  if(p==='sk') return 'sk';
852
871
  if(p==='sl') return 'sl';
872
+ if(p==='ca') return 'ca';
853
873
  return 'en';
854
874
  }`;
855
875
  }
@@ -10971,6 +10991,8 @@ var CrashReporter = class {
10971
10991
  this.windowInstalled = false;
10972
10992
  /** ErrorUtils ya enganchados: engancharlos dos veces capturaría cada error dos veces. */
10973
10993
  this.hookedErrorUtils = /* @__PURE__ */ new Set();
10994
+ /** Fuentes de rejections ya enganchadas (idempotente, como ErrorUtils). */
10995
+ this.hookedRejections = /* @__PURE__ */ new Set();
10974
10996
  this.options = options;
10975
10997
  this.now = options.now ?? (() => Date.now());
10976
10998
  }
@@ -11070,6 +11092,18 @@ var CrashReporter = class {
11070
11092
  previous?.(error, isFatal);
11071
11093
  });
11072
11094
  }
11095
+ /**
11096
+ * Promesas rechazadas sin `catch` en React Native: como el `unhandledrejection` de web, se
11097
+ * persisten y se reenvían en el arranque siguiente. La fuente encadena al tracker del host.
11098
+ * Idempotente por fuente.
11099
+ */
11100
+ installPromiseRejections(source) {
11101
+ if (this.hookedRejections.has(source)) return;
11102
+ this.hookedRejections.add(source);
11103
+ source.addUnhandledListener((error) => {
11104
+ if (this.isEnabled()) this.captureUnhandled(error ?? "unhandledrejection");
11105
+ });
11106
+ }
11073
11107
  /** @internal Test seam: ejercita el camino de persistencia (window handlers no son testeables en vitest). */
11074
11108
  _persistForTest(error) {
11075
11109
  this.captureUnhandled(error);
@@ -11177,6 +11211,51 @@ function resolveBackgroundTask(explicit, platform) {
11177
11211
  }
11178
11212
  return void 0;
11179
11213
  }
11214
+ var DEFAULT_REJECTION_WHITELIST = [ReferenceError, TypeError, RangeError];
11215
+ function createHermesRejectionHub(hermes, options) {
11216
+ if (!hermes || typeof hermes.enablePromiseRejectionTracker !== "function") return null;
11217
+ const original = hermes.enablePromiseRejectionTracker.bind(hermes);
11218
+ const listeners = /* @__PURE__ */ new Set();
11219
+ let hostOptions = null;
11220
+ let active2 = false;
11221
+ const forwardsToHost = (error) => !!hostOptions?.onUnhandled && (hostOptions.allRejections === true || DEFAULT_REJECTION_WHITELIST.some((type) => error instanceof type));
11222
+ const apply = () => {
11223
+ original({
11224
+ allRejections: true,
11225
+ onUnhandled: (id, error) => {
11226
+ listeners.forEach((listener) => {
11227
+ try {
11228
+ listener(error);
11229
+ } catch {
11230
+ }
11231
+ });
11232
+ if (hostOptions?.onUnhandled) {
11233
+ if (forwardsToHost(error)) hostOptions.onUnhandled(id, error);
11234
+ } else if (options.dev) {
11235
+ console.warn(`Possible unhandled promise rejection (id: ${id}):`, error);
11236
+ }
11237
+ },
11238
+ onHandled: (id, error) => hostOptions?.onHandled?.(id, error)
11239
+ });
11240
+ };
11241
+ hermes.enablePromiseRejectionTracker = (next) => {
11242
+ hostOptions = next ?? null;
11243
+ if (active2) apply();
11244
+ else original(next);
11245
+ };
11246
+ return {
11247
+ addUnhandledListener(listener) {
11248
+ listeners.add(listener);
11249
+ if (!active2) {
11250
+ active2 = true;
11251
+ apply();
11252
+ }
11253
+ return () => {
11254
+ listeners.delete(listener);
11255
+ };
11256
+ }
11257
+ };
11258
+ }
11180
11259
 
11181
11260
  // src/analytics/messaging.ts
11182
11261
  var MESSAGE_CHANNELS = ["push", "in_app"];
@@ -11341,6 +11420,8 @@ var DeepdotsPopups = class {
11341
11420
  this.lastEngagementAt = 0;
11342
11421
  /** Cuándo se ocultó la pestaña por última vez (ms epoch); null si está visible. */
11343
11422
  this.hiddenAt = null;
11423
+ /** `init({ autoTrack: { errors } })`: captura automática de errores. Activa por defecto. */
11424
+ this.autoTrackErrors = true;
11344
11425
  /** Suscripción automática a AppState (React Native, `autoTrack.lifecycle`). */
11345
11426
  this.appStateSubscription = void 0;
11346
11427
  /**
@@ -11387,6 +11468,7 @@ var DeepdotsPopups = class {
11387
11468
  this.surveyCss = config.surveyCss;
11388
11469
  this.cspNonce = config.cspNonce;
11389
11470
  this.onFeedbackSession = config.onFeedbackSession;
11471
+ this.autoTrackErrors = config.autoTrack?.errors !== false;
11390
11472
  this.config = {
11391
11473
  apiKey: config.apiKey || void 0,
11392
11474
  debug: config.debug || false,
@@ -11585,11 +11667,14 @@ var DeepdotsPopups = class {
11585
11667
  */
11586
11668
  installCrashHandlers() {
11587
11669
  if (!this.crashReporter || !this.tracking?.isTrackingEnabled()) return;
11588
- this.crashReporter.install();
11589
- const errorUtils = this.rnErrorUtils ?? globalThis.ErrorUtils;
11670
+ const auto = this.autoTrackErrors;
11671
+ if (auto) this.crashReporter.install();
11672
+ const errorUtils = this.rnErrorUtils ?? (auto ? globalThis.ErrorUtils : void 0);
11590
11673
  if (errorUtils && typeof errorUtils.setGlobalHandler === "function") {
11591
11674
  this.crashReporter.installReactNative(errorUtils);
11592
11675
  }
11676
+ const rejections = auto ? getReactNativePlatform()?.promiseRejections : null;
11677
+ if (rejections) this.crashReporter.installPromiseRejections(rejections);
11593
11678
  }
11594
11679
  /**
11595
11680
  * Info interna del usuario que solo conoce el host (idioma, edad, plan…), persistida en el
@@ -11735,11 +11820,24 @@ var DeepdotsPopups = class {
11735
11820
  * anterior (`session_end` con `reason: 'user_change'` + `completed:true`), cambia la
11736
11821
  * identidad y abre una sesión nueva. Sin `userId` vuelve al id anónimo del SDK.
11737
11822
  *
11823
+ * Anónimo → identificado (la app arranca sin `userId` y lo pone al hacer login) es la MISMA
11824
+ * persona, no otra: el `session_start` de la sesión nueva lleva `identified: true`,
11825
+ * `previous_user_id` (el id anónimo) y `previous_session_id` (el registro que se acaba de
11826
+ * cerrar), para que el backend una las dos sin adivinar; y el estado de popups (mostrados,
11827
+ * respondidos, protecciones de mensajes) se conserva. Sin esto, cada persona que se registra
11828
+ * contaba dos veces: una que "abandona" en el login y otra registrada nueva.
11829
+ *
11738
11830
  * Equivale a llamar a `init()` otra vez con otro `userId`.
11739
11831
  */
11740
11832
  setUserId(userId) {
11741
11833
  const next = userId || void 0;
11742
11834
  if (!this.initialized || !this.config || next === this.config.userId) return;
11835
+ const identifying = !this.config.userId && !!next;
11836
+ const previous = identifying ? {
11837
+ identified: true,
11838
+ previous_user_id: this.tracking?.getUserId() ?? void 0,
11839
+ previous_session_id: this.analyticsFeedbackSessionId
11840
+ } : void 0;
11743
11841
  this.closeSession("user_change");
11744
11842
  const enabled = this.tracking?.isTrackingEnabled() ?? true;
11745
11843
  const storage = this.storage ?? createDefaultStorage();
@@ -11752,13 +11850,18 @@ var DeepdotsPopups = class {
11752
11850
  post: (body) => this.postContact(body)
11753
11851
  }) : null;
11754
11852
  this.analytics?.resetUserScope();
11755
- this.messageGuard.reset();
11756
- this.lastShown.clear();
11757
- this.surveyProgress.clear();
11758
- this.answeredSurveys.clear();
11759
- clearPopupState(storage);
11760
- this.log("tracking \xB7 user_change \xB7 user_id:", this.tracking.getUserId());
11761
- this.openSession("user_change");
11853
+ if (!identifying) {
11854
+ this.messageGuard.reset();
11855
+ this.lastShown.clear();
11856
+ this.surveyProgress.clear();
11857
+ this.answeredSurveys.clear();
11858
+ clearPopupState(storage);
11859
+ }
11860
+ this.log(
11861
+ identifying ? "tracking \xB7 user identified \xB7 user_id:" : "tracking \xB7 user_change \xB7 user_id:",
11862
+ this.tracking.getUserId()
11863
+ );
11864
+ this.openSession("user_change", previous);
11762
11865
  }
11763
11866
  /**
11764
11867
  * Cierra la sesión actual: vuelca todo lo que quedaba abierto y envía el último lote
@@ -11794,14 +11897,14 @@ var DeepdotsPopups = class {
11794
11897
  * - `bfcache_restore`: vuelta desde la bfcache fuera de la ventana de reanudación.
11795
11898
  * Si hay una sesión suspendida a tiempo emite `deepdots_session_resume` en su lugar, sin reason.
11796
11899
  */
11797
- openSession(reason) {
11900
+ openSession(reason, extra) {
11798
11901
  if (this.sessionOpen) return;
11799
11902
  if (!this.tracking?.isTrackingEnabled()) return;
11800
11903
  const suspendedMs = this.takeSuspendedSession();
11801
11904
  this.sessionOpen = true;
11802
11905
  this.lastEngagementAt = Date.now();
11803
11906
  if (suspendedMs === null) {
11804
- this.track("deepdots_session_start", { reason });
11907
+ this.track("deepdots_session_start", { reason, ...extra });
11805
11908
  } else {
11806
11909
  this.track("deepdots_session_resume", { suspended_ms: suspendedMs });
11807
11910
  this.log("tracking \xB7 session resumed after", suspendedMs, "ms:", this.analyticsFeedbackSessionId);
@@ -12861,13 +12964,26 @@ function setupReactNative(sdk2, config, deps = {}) {
12861
12964
  };
12862
12965
  }
12863
12966
 
12967
+ // src/platform/react-native-defaults.ts
12968
+ var hub;
12969
+ function registerReactNativeDefaults(rn) {
12970
+ if (hub === void 0) {
12971
+ hub = getReactNativePlatform()?.promiseRejections ?? createHermesRejectionHub(
12972
+ globalThis.HermesInternal,
12973
+ { dev: typeof __DEV__ !== "undefined" && !!__DEV__ }
12974
+ );
12975
+ }
12976
+ registerReactNativePlatform({
12977
+ os: rn.Platform.OS,
12978
+ appState: rn.AppState,
12979
+ backgroundTaskModule: rn.NativeModules?.DeepdotsBackgroundTask ?? null,
12980
+ promiseRejections: hub
12981
+ });
12982
+ }
12983
+
12864
12984
  // src/react-native/index.tsx
12865
12985
  var import_jsx_runtime = require("react/jsx-runtime");
12866
- registerReactNativePlatform({
12867
- os: import_react_native.Platform.OS,
12868
- appState: import_react_native.AppState,
12869
- backgroundTaskModule: import_react_native.NativeModules?.DeepdotsBackgroundTask ?? null
12870
- });
12986
+ registerReactNativeDefaults({ AppState: import_react_native.AppState, NativeModules: import_react_native.NativeModules, Platform: import_react_native.Platform });
12871
12987
  var sdk = new DeepdotsPopups();
12872
12988
  var DeepdotsContext = (0, import_react.createContext)(sdk);
12873
12989
  var useDeepdots = () => (0, import_react.useContext)(DeepdotsContext);