@magicfeedback/popup-sdk 1.17.1 → 1.18.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.
@@ -6,6 +6,7 @@ import {
6
6
  REVEAL_TIMEOUT_MS,
7
7
  RTL_LOCALES,
8
8
  STORAGE_KEYS,
9
+ SUBMIT_ERROR_JS,
9
10
  TrackingManager,
10
11
  __require,
11
12
  buildFontFaceCss,
@@ -18,7 +19,7 @@ import {
18
19
  sdkWarn,
19
20
  setLogger,
20
21
  style_default
21
- } from "./chunk-VHTN5UXD.mjs";
22
+ } from "./chunk-7ZVOPIWE.mjs";
22
23
 
23
24
  // src/react-native/index.tsx
24
25
  import { createContext, useContext, useEffect, useRef, useState } from "react";
@@ -256,7 +257,7 @@ function trimmedOrNull(value) {
256
257
  }
257
258
  function buildSurveyHtml(opts) {
258
259
  const env = opts.env === "development" ? "dev" : "prod";
259
- const version = opts.version ?? "2.2.33";
260
+ const version = opts.version ?? "2.2.37";
260
261
  const cdn = `https://cdn.jsdelivr.net/npm/@magicfeedback/native@${version}/dist/magicfeedback-sdk.browser.js`;
261
262
  const sid = jsonForScript(opts.surveyId);
262
263
  const pid = jsonForScript(opts.productId);
@@ -428,6 +429,7 @@ ${customCss}
428
429
  (function(){
429
430
  function emit(s){ try{ if(window.ReactNativeWebView){ window.ReactNativeWebView.postMessage(s); } }catch(e){} }
430
431
  function emitJSON(n,p){ try{ emit(JSON.stringify({name:n,payload:p||{}})); }catch(e){} }
432
+ var ddLastReportedError=null;
431
433
  window.DeepdotsClose = function(){ emitJSON('popup_close'); };
432
434
  var chromeOn=${chrome ? "true" : "false"};
433
435
 
@@ -608,6 +610,7 @@ ${customCss}
608
610
 
609
611
  ${PRIMARY_COLOR_JS}
610
612
  ${BUSY_JS}
613
+ ${SUBMIT_ERROR_JS}
611
614
  ${REVEAL_JS}
612
615
  // Foco en la primera pregunta si es de escribir. Al navegar lo pone @magicfeedback/native
613
616
  // (autofocus:'navigation'); la apertura la decide el popup, que es quien sabe cu\xE1ndo se revela.
@@ -759,10 +762,10 @@ ${REVEAL_JS}
759
762
  emitJSON('before_submit');
760
763
  },
761
764
  afterSubmitEvent:function(p){
762
- var error=p && p.error ? (typeof p.error==='string' ? p.error : String(p.error)) : '';
763
- if(error){
765
+ if(p && p.error){
764
766
  setLoading(false);
765
- if(error.toLowerCase().indexOf('no response')!==-1){
767
+ var ddErr=ddClassifySubmitError(p.error);
768
+ if(ddErr.reason==='required'){
766
769
  // La p\xE1gina no ha cambiado: el estado de navegaci\xF3n se queda como estaba.
767
770
  errorHint.textContent=DD_LABELS_ACTIVE.errorRequired;
768
771
  errorHint.style.display='block';
@@ -771,6 +774,11 @@ ${REVEAL_JS}
771
774
  }
772
775
  errorHint.textContent=DD_LABELS_ACTIVE.errorSubmit;
773
776
  errorHint.style.display='block';
777
+ // Un solo aviso por fallo: native repite el mismo objeto al cerrar el survey.
778
+ if(p.error!==ddLastReportedError){
779
+ ddLastReportedError=p.error;
780
+ emitJSON('survey_error', ddErr);
781
+ }
774
782
  return;
775
783
  }
776
784
  errorHint.style.display='none';
@@ -893,8 +901,9 @@ var ReactNativePopupRenderer = class {
893
901
  const surveyId = this.currentSurveyId;
894
902
  if (!surveyId || !this.emitFn) return;
895
903
  let name;
904
+ let payload;
896
905
  try {
897
- name = JSON.parse(raw).name;
906
+ ({ name, payload } = JSON.parse(raw));
898
907
  } catch {
899
908
  name = raw;
900
909
  }
@@ -915,6 +924,9 @@ var ReactNativePopupRenderer = class {
915
924
  case "survey_completed":
916
925
  this.emitFn("survey_completed", surveyId);
917
926
  break;
927
+ case "survey_error":
928
+ this.emitFn("survey_error", surveyId, { reason: payload?.reason, message: payload?.message });
929
+ break;
918
930
  case "popup_close":
919
931
  this.onCloseFn?.();
920
932
  break;
@@ -932,7 +944,7 @@ function createReactNativeRenderer() {
932
944
  }
933
945
 
934
946
  // src/ui/preload.ts
935
- var defaultLoader = () => import("./renderPopup-S3RU3Y6J.mjs");
947
+ var defaultLoader = () => import("./renderPopup-B6VIV4VS.mjs");
936
948
  var pending = null;
937
949
  function preloadRenderPopup(loader = defaultLoader) {
938
950
  if (pending) return pending;
@@ -1005,9 +1017,18 @@ var BrowserPopupRenderer = class {
1005
1017
  if (!this.container) return;
1006
1018
  this.visible = true;
1007
1019
  const container = this.container;
1008
- void import("./renderPopup-S3RU3Y6J.mjs").then(({ renderPopup }) => {
1009
- renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1010
- });
1020
+ void import("./renderPopup-B6VIV4VS.mjs").then(
1021
+ ({ renderPopup }) => {
1022
+ renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1023
+ },
1024
+ (error) => {
1025
+ this.visible = false;
1026
+ sdkWarn("[Deepdots] popup renderer failed to load:", error);
1027
+ }
1028
+ );
1029
+ }
1030
+ isShowing() {
1031
+ return this.visible;
1011
1032
  }
1012
1033
  hide() {
1013
1034
  this.visible = false;
@@ -2950,6 +2971,10 @@ var DeepdotsPopups = class {
2950
2971
  });
2951
2972
  }
2952
2973
  showDefinition(def) {
2974
+ if (this.renderer.isShowing?.()) {
2975
+ this.debug("Popup skipped: another popup is already open", def.id);
2976
+ return;
2977
+ }
2953
2978
  this.log("Showing popup (definition)", def);
2954
2979
  this.surveyToPopupId.set(def.surveyId, def.id);
2955
2980
  this.lastShown.set(def.id, Date.now());
@@ -3356,6 +3381,15 @@ var DeepdotsPopups = class {
3356
3381
  emitEvent(type, surveyId, data) {
3357
3382
  const event = { type, surveyId, timestamp: Date.now(), data };
3358
3383
  this.log("Event emitted", event);
3384
+ if (type === "survey_error") {
3385
+ const popupId = data?.popupId || this.surveyToPopupId.get(surveyId);
3386
+ this.track("deepdots_survey_error", {
3387
+ survey_id: surveyId,
3388
+ ...popupId ? { popup_id: popupId } : {},
3389
+ reason: data?.reason,
3390
+ message: data?.message
3391
+ });
3392
+ }
3359
3393
  const isPartialClick = type === "popup_clicked" && data?.action === "partial";
3360
3394
  if (isPartialClick) {
3361
3395
  this.markSurveyProgress(surveyId, "PARTIAL");