@magicfeedback/popup-sdk 1.22.1 → 1.23.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 (44) hide show
  1. package/README.md +8 -2
  2. package/dist/2.2.47-BYEZ6PUX.mjs +2428 -0
  3. package/dist/2.2.47-BYEZ6PUX.mjs.map +1 -0
  4. package/dist/2.2.47-ZZQRJNYY.mjs +2428 -0
  5. package/dist/2.2.47-ZZQRJNYY.mjs.map +1 -0
  6. package/dist/assets/assets/style.css +8 -1
  7. package/dist/assets/assets/survey-css/2.2.47.css +2420 -0
  8. package/dist/{chunk-5UURWEOR.mjs → chunk-7PNQVCOR.mjs} +156 -5
  9. package/dist/chunk-7PNQVCOR.mjs.map +1 -0
  10. package/dist/{chunk-4TNJ2IBB.mjs → chunk-HDCZ2QGX.mjs} +156 -5
  11. package/dist/chunk-HDCZ2QGX.mjs.map +1 -0
  12. package/dist/{chunk-6HPKIMVM.mjs → chunk-OXAYYIUH.mjs} +156 -5
  13. package/dist/chunk-OXAYYIUH.mjs.map +1 -0
  14. package/dist/index.d.mts +36 -0
  15. package/dist/index.d.ts +36 -0
  16. package/dist/index.js +4022 -1311
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +125 -60
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/index.native.d.mts +36 -0
  21. package/dist/index.native.d.ts +36 -0
  22. package/dist/index.native.js +4022 -1311
  23. package/dist/index.native.js.map +1 -1
  24. package/dist/index.native.mjs +125 -60
  25. package/dist/index.native.mjs.map +1 -1
  26. package/dist/react-native.d.mts +25 -0
  27. package/dist/react-native.d.ts +25 -0
  28. package/dist/react-native.js +2820 -181
  29. package/dist/react-native.js.map +1 -1
  30. package/dist/react-native.mjs +125 -60
  31. package/dist/react-native.mjs.map +1 -1
  32. package/dist/{renderPopup-SFDIFFUT.mjs → renderPopup-I565DNZX.mjs} +18 -29
  33. package/dist/renderPopup-I565DNZX.mjs.map +1 -0
  34. package/dist/{renderPopup-L5TROMDQ.mjs → renderPopup-KWAMONIN.mjs} +1210 -1149
  35. package/dist/renderPopup-KWAMONIN.mjs.map +1 -0
  36. package/dist/{renderPopup-UXD7L3FX.mjs → renderPopup-USTJXQJ6.mjs} +1210 -1149
  37. package/dist/renderPopup-USTJXQJ6.mjs.map +1 -0
  38. package/package.json +2 -2
  39. package/dist/chunk-4TNJ2IBB.mjs.map +0 -1
  40. package/dist/chunk-5UURWEOR.mjs.map +0 -1
  41. package/dist/chunk-6HPKIMVM.mjs.map +0 -1
  42. package/dist/renderPopup-L5TROMDQ.mjs.map +0 -1
  43. package/dist/renderPopup-SFDIFFUT.mjs.map +0 -1
  44. package/dist/renderPopup-UXD7L3FX.mjs.map +0 -1
@@ -6,10 +6,12 @@ import {
6
6
  InMemoryStorage,
7
7
  LABELS,
8
8
  PRIMARY_COLOR_JS,
9
+ PROGRESS_VIEW_JS,
9
10
  RESOLVE_LOCALE_JS,
10
11
  REVEAL_TIMEOUT_MS,
11
12
  RTL_LOCALES,
12
13
  SDK_IDENTIFIER,
14
+ SMALL_CARD_MOBILE_MAX_PX,
13
15
  STORAGE_KEYS,
14
16
  SUBMIT_ERROR_JS,
15
17
  SUPPORTED_LANGUAGES,
@@ -26,13 +28,14 @@ import {
26
28
  normalizeAppearance,
27
29
  resolveActionLabels,
28
30
  resolveLocale,
31
+ resolvePlacement,
29
32
  sdkLog,
30
33
  sdkWarn,
31
34
  setLogger,
32
35
  style_default,
33
36
  surveySdkCssUrls,
34
37
  surveySdkUrls
35
- } from "./chunk-6HPKIMVM.mjs";
38
+ } from "./chunk-OXAYYIUH.mjs";
36
39
  import "./chunk-3QS3WKRC.mjs";
37
40
 
38
41
  // src/index.native.ts
@@ -165,6 +168,20 @@ function registerReactNativeDefaults(rn) {
165
168
  }
166
169
  }
167
170
 
171
+ // src/core/local-dev-host.ts
172
+ function isLocalDevHost(hostname) {
173
+ if (!hostname) return false;
174
+ const h = hostname.toLowerCase().replace(/^\[|\]$/g, "");
175
+ return h === "localhost" || h.endsWith(".localhost") || h === "0.0.0.0" || h === "::1" || /^127(\.\d{1,3}){3}$/.test(h);
176
+ }
177
+ function currentHostname() {
178
+ try {
179
+ return typeof location !== "undefined" && typeof location.hostname === "string" ? location.hostname : void 0;
180
+ } catch {
181
+ return void 0;
182
+ }
183
+ }
184
+
168
185
  // src/types/index.ts
169
186
  var POPUP_TRIGGER_CONDITION_STATUSES = [
170
187
  "SHOWED",
@@ -378,15 +395,6 @@ function ddCreateReveal(popup, onReveal, timeoutMs){
378
395
  timer=setTimeout(reveal, timeoutMs);
379
396
  return { reveal: reveal, whenPainted: revealWhenPainted };
380
397
  }`;
381
- var POSITION_MAP = {
382
- center: { justifyContent: "center", alignItems: "center", padding: "0", background: "rgba(0,0,0,0.5)" },
383
- bottom: { justifyContent: "center", alignItems: "flex-end", padding: "16px", background: "transparent" },
384
- "bottom-right": { justifyContent: "flex-end", alignItems: "flex-end", padding: "16px", background: "transparent" },
385
- "bottom-left": { justifyContent: "flex-start", alignItems: "flex-end", padding: "16px", background: "transparent" },
386
- top: { justifyContent: "center", alignItems: "flex-start", padding: "16px", background: "transparent" },
387
- "top-right": { justifyContent: "flex-end", alignItems: "flex-start", padding: "16px", background: "transparent" },
388
- "top-left": { justifyContent: "flex-start", alignItems: "flex-start", padding: "16px", background: "transparent" }
389
- };
390
398
  function jsonForScript(value) {
391
399
  return JSON.stringify(value ?? null).replace(/</g, "\\u003C").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
392
400
  }
@@ -415,7 +423,7 @@ function buildSurveyHtml(opts) {
415
423
  const textPrimary = isDark ? "#f0f0f0" : "#111";
416
424
  const textMuted = isDark ? "#9ca3af" : "#6b7280";
417
425
  const trackBg = isDark ? "#3f3f46" : "#e5e7eb";
418
- const pos = POSITION_MAP[opts.position ?? "center"] ?? POSITION_MAP.center;
426
+ const pos = resolvePlacement({ position: opts.position, size: opts.size, blockPage: opts.blockPage });
419
427
  const chrome = opts.chrome !== false;
420
428
  const bodyBg = chrome ? pos.background : "transparent";
421
429
  const bodyPadding = chrome ? pos.padding : "0";
@@ -423,12 +431,12 @@ function buildSurveyHtml(opts) {
423
431
  const cardBg = chrome ? popupBg : "transparent";
424
432
  const cardShadow = chrome ? "0 4px 6px rgba(0,0,0,0.1)" : "none";
425
433
  const cardRadius = chrome ? "8px" : "0";
426
- const cardMaxWidth = chrome ? "600px" : "none";
434
+ const cardMaxWidth = chrome ? `${pos.cardMaxWidthPx}px` : "none";
427
435
  const cardWidth = chrome ? "90%" : "100%";
428
436
  const cardMinHeight = chrome ? "200px" : "0";
429
437
  const cardHeight = chrome ? "auto" : "100%";
430
438
  const cardMaxHeight = chrome ? "90vh" : "100%";
431
- const mobileCard = chrome ? `.deepdots-popup{width:calc(100% - 24px);max-width:calc(100% - 24px);border-radius:12px;padding:calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)) 16px}` : `.deepdots-popup{width:100%;max-width:100%;border-radius:0;padding:16px}`;
439
+ const mobileCard = chrome ? `.deepdots-popup{width:calc(100% - 24px);max-width:${pos.size === "small" ? `min(${SMALL_CARD_MOBILE_MAX_PX}px, calc(100% - 24px))` : "calc(100% - 24px)"};border-radius:12px;padding:calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)) 16px}` : `.deepdots-popup{width:100%;max-width:100%;border-radius:0;padding:16px}`;
432
440
  const titleJson = jsonForScript(opts.title ?? "");
433
441
  const customCss = (opts.surveyCss ?? "").replace(/<\/\s*style/gi, "<\\/style");
434
442
  const progressPref = opts.showProgressBar === void 0 ? "null" : String(opts.showProgressBar);
@@ -640,13 +648,17 @@ ${customCss}
640
648
  var progressEnabled=progressPref===true;
641
649
  var progressShowUnit=true;
642
650
  var progressUnit='fraction';
651
+ // DD-210: qu\xE9 cuenta la barra (style.progressMode).
652
+ var progressMode='current';
653
+ ${PROGRESS_VIEW_JS}
643
654
  var onStartPage=false;
644
655
 
645
656
  function updateProgress(p){
646
657
  var total=p&&typeof p.total==='number'?p.total:0;
647
658
  var progress=p&&typeof p.progress==='number'?p.progress:0;
648
- // Solo tiene sentido con m\xE1s de una p\xE1gina, fuera de la pantalla de inicio y sin completar.
649
- if(!progressEnabled||onStartPage||p&&p.completed||total<=1){
659
+ // Reglas en ddProgressView (espejo de progressView.ts, MagicSurvey y el SDK nativo).
660
+ var view=ddProgressView({progress:progress,total:total,completed:!!(p&&p.completed),mode:progressMode,unit:progressUnit},DD_LABELS_ACTIVE);
661
+ if(!progressEnabled||onStartPage||!view.visible){
650
662
  progressEl.style.display='none';
651
663
  // Sin barra, el hueco cabecera\u2192pregunta lo pone el contenido.
652
664
  content.style.paddingTop='16px';
@@ -655,22 +667,11 @@ ${customCss}
655
667
  progressEl.style.display='flex';
656
668
  // Con barra, el hueco inferior ya lo pone el bloque de progreso: no duplicarlo.
657
669
  content.style.paddingTop='0';
658
- // Espejo de LineProgressQuestion (MagicSurvey): la barra usa el valor real (las follow-up
659
- // suman +0.5 y avanzan media casilla) y la etiqueta redondea hacia abajo, porque una
660
- // follow-up es un paso DENTRO de la misma pregunta, no la siguiente.
661
- var current=Math.min(total,Math.max(1,progress+1));
662
- var pct=Math.min(100,Math.max(0,(current/total)*100));
663
- progressBar.style.width=pct+'%';
664
- var label=Math.min(total,Math.max(1,Math.floor(progress)+1));
670
+ progressBar.style.width=view.percent+'%';
665
671
  progressLabel.style.display=progressShowUnit?'block':'none';
666
- if(progressUnit==='percentage'){
667
- progressCurrent.textContent=Math.round(pct)+'%';
668
- progressTotal.textContent='';
669
- } else {
670
- progressCurrent.textContent=DD_LABELS_ACTIVE.question+' '+label;
671
- progressTotal.textContent=' '+DD_LABELS_ACTIVE.of+' '+total;
672
- }
673
- progressFollowUp.style.display=p&&p.followup?'inline-block':'none';
672
+ progressCurrent.textContent=view.current;
673
+ progressTotal.textContent=view.rest;
674
+ progressFollowUp.style.display=p&&p.followup&&!p.completed?'inline-block':'none';
674
675
  }
675
676
 
676
677
  backBtn.textContent=${backLabel};
@@ -897,6 +898,7 @@ ${REVEAL_JS}
897
898
  if(progressPref===null){ progressEnabled=s.showProgressBar===true; }
898
899
  if(s.showProgressUnit!==undefined){ progressShowUnit=s.showProgressUnit!==false; }
899
900
  if(s.progressUnit){ progressUnit=s.progressUnit; }
901
+ if(s.progressMode){ progressMode=s.progressMode; }
900
902
  // Fondo, textos, botones y barra: Style + theme + modo de la app (DD-247, DD-241).
901
903
  ddApplyAppearanceColors(s);
902
904
  if(s.contentAlign){ main.style.justifyContent = s.contentAlign==='center' ? 'center' : 'flex-start'; }
@@ -1062,6 +1064,8 @@ var ReactNativePopupRenderer = class {
1062
1064
  font: style?.font,
1063
1065
  theme: style?.theme,
1064
1066
  position: style?.position,
1067
+ size: style?.size,
1068
+ blockPage: style?.blockPage,
1065
1069
  actions,
1066
1070
  // renderChrome:false (init) → HTML sin tarjeta/overlay: el host lo envuelve en su Modal.
1067
1071
  chrome: renderChrome,
@@ -1163,7 +1167,7 @@ function logRnSurveySdkChoice(choice, debug) {
1163
1167
  }
1164
1168
 
1165
1169
  // src/ui/preload.ts
1166
- var defaultLoader = () => import("./renderPopup-L5TROMDQ.mjs");
1170
+ var defaultLoader = () => import("./renderPopup-USTJXQJ6.mjs");
1167
1171
  var pending = null;
1168
1172
  function preloadRenderPopup(loader = defaultLoader) {
1169
1173
  if (pending) return pending;
@@ -1236,7 +1240,7 @@ var BrowserPopupRenderer = class {
1236
1240
  if (!this.container) return;
1237
1241
  this.visible = true;
1238
1242
  const container = this.container;
1239
- void import("./renderPopup-L5TROMDQ.mjs").then(
1243
+ void import("./renderPopup-USTJXQJ6.mjs").then(
1240
1244
  ({ renderPopup }) => {
1241
1245
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1242
1246
  },
@@ -2124,6 +2128,35 @@ var ContactManager = class {
2124
2128
  var STACK_MAX = 8e3;
2125
2129
  var QUEUE_KEY = "deepdots.crash.queue";
2126
2130
  var MAX_QUEUED = 20;
2131
+ var BENIGN_ERROR_PATTERNS = [
2132
+ /ResizeObserver loop completed with undelivered notifications/i,
2133
+ /ResizeObserver loop limit exceeded/i
2134
+ ];
2135
+ var NON_FATAL_ERROR_PATTERNS = [
2136
+ /auth\/network-request-failed/i,
2137
+ // IndexedDB cerrándose (pestaña en segundo plano, otra pestaña actualiza la versión, logout).
2138
+ /connection is closing/i
2139
+ ];
2140
+ function errorText(error) {
2141
+ if (error && typeof error === "object") {
2142
+ const e = error;
2143
+ return [e.name, e.code, e.message].filter((v) => typeof v === "string").join(" ");
2144
+ }
2145
+ return String(error ?? "");
2146
+ }
2147
+ var matches = (text, patterns) => patterns.some((p) => p.test(text));
2148
+ function isBenignError(error) {
2149
+ return matches(errorText(error), BENIGN_ERROR_PATTERNS);
2150
+ }
2151
+ function isNonFatalNoise(error) {
2152
+ return matches(errorText(error), NON_FATAL_ERROR_PATTERNS);
2153
+ }
2154
+ function reclassify(r) {
2155
+ const text = `${r.crashType} ${r.message}`;
2156
+ if (matches(text, BENIGN_ERROR_PATTERNS)) return null;
2157
+ if (matches(text, NON_FATAL_ERROR_PATTERNS)) return { ...r, fatal: false, severity: "warning" };
2158
+ return r;
2159
+ }
2127
2160
  function crashRecordToParams(r) {
2128
2161
  const params = {
2129
2162
  crashed_at: r.crashedAt,
@@ -2181,7 +2214,8 @@ var CrashReporter = class {
2181
2214
  /** API pública del host: reporta un error (app viva) → emite el evento ya. */
2182
2215
  reportError(error, options = {}) {
2183
2216
  if (!this.isEnabled()) return;
2184
- const severity = options.severity ?? "error";
2217
+ if (isBenignError(error)) return;
2218
+ const severity = isNonFatalNoise(error) ? "warning" : options.severity ?? "error";
2185
2219
  const handled = options.handled ?? true;
2186
2220
  const fatal = severity === "fatal";
2187
2221
  const record = this.buildRecord(error, severity, handled, fatal, options.context);
@@ -2189,6 +2223,11 @@ var CrashReporter = class {
2189
2223
  }
2190
2224
  /** Captura un error no manejado (fatal) → persiste a disco para replay en el siguiente arranque. */
2191
2225
  captureUnhandled(error) {
2226
+ if (isBenignError(error)) return;
2227
+ if (isNonFatalNoise(error)) {
2228
+ this.persist(this.buildRecord(error, "warning", false, false));
2229
+ return;
2230
+ }
2192
2231
  this.persist(this.buildRecord(error, "fatal", false, true));
2193
2232
  }
2194
2233
  /** Persiste un crash no capturado a disco para reenviarlo en el siguiente arranque. */
@@ -2224,7 +2263,7 @@ var CrashReporter = class {
2224
2263
  } catch {
2225
2264
  }
2226
2265
  }
2227
- return queue;
2266
+ return queue.map(reclassify).filter((r) => r !== null);
2228
2267
  }
2229
2268
  /** Instala los handlers globales de errores no capturados (no-op sin `window`). Idempotente. */
2230
2269
  install() {
@@ -2417,6 +2456,7 @@ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2417
2456
  var RESERVED_EVENT_PREFIX = "deepdots_";
2418
2457
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2419
2458
  var MAX_PENDING_TRIGGERS = 20;
2459
+ var CONTACT_SYNC_TIMEOUT_MS = 1500;
2420
2460
  function triggerDelayMs(delaySeconds) {
2421
2461
  const n = typeof delaySeconds === "number" ? delaySeconds : Number(delaySeconds);
2422
2462
  return Number.isFinite(n) && n > 0 ? Math.round(n * 1e3) : 0;
@@ -2489,6 +2529,8 @@ var DeepdotsPopups = class {
2489
2529
  this.engagement = null;
2490
2530
  /** Atributos internos del usuario identificado → POST /sdk/popups/contact. Null si no hay userId. */
2491
2531
  this.contact = null;
2532
+ /** DD-561: contact POST of `init()`, awaited (with a cap) by the popups GET. Null if none. */
2533
+ this.contactSync = null;
2492
2534
  /** Storage resuelto en init() (inyectado por el host o localStorage). Reusado al cambiar de usuario. */
2493
2535
  this.storage = null;
2494
2536
  /** Marca si ya se inició la navegación manual (setScreen) — para RN sin History API. */
@@ -2576,19 +2618,24 @@ var DeepdotsPopups = class {
2576
2618
  post: (body) => this.postContact(body)
2577
2619
  });
2578
2620
  if (config.contactAttributes) {
2579
- void this.setContactAttributes(config.contactAttributes);
2621
+ this.contactSync = this.setContactAttributes(config.contactAttributes);
2580
2622
  }
2581
2623
  }
2582
2624
  this.log("tracking \xB7 user_id:", this.tracking.getUserId(), "\xB7 new_user:", this.tracking.isNewUser(), "\xB7 enabled:", this.tracking.isTrackingEnabled());
2583
- this.analyticsIntegration = config.analytics?.integration;
2625
+ const localDev = (config.platform ?? "web") === "web" && !config.trackLocalhost && isLocalDevHost(currentHostname());
2626
+ const analyticsKeys = localDev ? void 0 : config.analytics;
2627
+ if (localDev && config.analytics) {
2628
+ this.log("analytics \xB7 localhost: no se env\xEDa (trackLocalhost: true para enviar)");
2629
+ }
2630
+ this.analyticsIntegration = analyticsKeys?.integration;
2584
2631
  const resumable = this.readResumableSession();
2585
2632
  if (resumable) {
2586
2633
  this.analyticsFeedbackSessionId = resumable.sessionId;
2587
2634
  this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2588
2635
  }
2589
- const analyticsSink = config.analytics ? createFeedbackSink({
2636
+ const analyticsSink = analyticsKeys ? createFeedbackSink({
2590
2637
  baseUrl: this.baseUrl,
2591
- keys: config.analytics,
2638
+ keys: analyticsKeys,
2592
2639
  log: (...a) => this.log(...a),
2593
2640
  initialSessionId: resumable?.sessionId,
2594
2641
  // En móvil (RN) la app puede morir con el lote de cierre sin entregar: se
@@ -2636,7 +2683,7 @@ var DeepdotsPopups = class {
2636
2683
  });
2637
2684
  this.installCrashHandlers();
2638
2685
  this.geoEnabled = config.geolocation ?? true;
2639
- this.geoWanted = this.geoEnabled && !!config.analytics;
2686
+ this.geoWanted = this.geoEnabled && !!analyticsKeys;
2640
2687
  this.resolveGeo();
2641
2688
  this.navObserver = new NavigationObserver();
2642
2689
  this.navObserver.onVisit(
@@ -3494,38 +3541,38 @@ var DeepdotsPopups = class {
3494
3541
  this.debug("No language available for lang comparison", { popupId: def.id, langs });
3495
3542
  return true;
3496
3543
  }
3497
- const matches = langs.some(
3544
+ const matches2 = langs.some(
3498
3545
  (lang) => typeof lang === "string" && currentLang.startsWith(lang.toLowerCase())
3499
3546
  );
3500
- if (!matches) {
3547
+ if (!matches2) {
3501
3548
  this.debug("Lang mismatch for popup", { popupId: def.id, langs, currentLang });
3502
3549
  }
3503
- return matches;
3550
+ return matches2;
3504
3551
  }
3505
3552
  /** `segments.path`: rutas donde el popup PUEDE mostrarse. Sin lista, en todas. */
3506
3553
  matchesSegmentsPath(def, pathUrl) {
3507
3554
  const paths = def.segments?.path;
3508
3555
  if (!Array.isArray(paths) || paths.length === 0) return true;
3509
- const location = this.resolveCurrentLocation(pathUrl);
3510
- if (!location) {
3556
+ const location2 = this.resolveCurrentLocation(pathUrl);
3557
+ if (!location2) {
3511
3558
  this.debug("No window.location available for path comparison", { popupId: def.id, paths });
3512
3559
  return true;
3513
3560
  }
3514
- const matches = paths.some((rawCandidate) => {
3515
- const match = this.matchesPathCandidate(rawCandidate, location);
3561
+ const matches2 = paths.some((rawCandidate) => {
3562
+ const match = this.matchesPathCandidate(rawCandidate, location2);
3516
3563
  this.debug("Path comparison", {
3517
3564
  popupId: def.id,
3518
3565
  candidate: rawCandidate,
3519
- currentPath: location.path,
3520
- currentHref: location.href,
3566
+ currentPath: location2.path,
3567
+ currentHref: location2.href,
3521
3568
  match
3522
3569
  });
3523
3570
  return match;
3524
3571
  });
3525
- if (!matches) {
3526
- this.debug("No path match for popup", { popupId: def.id, paths, currentPath: location.path });
3572
+ if (!matches2) {
3573
+ this.debug("No path match for popup", { popupId: def.id, paths, currentPath: location2.path });
3527
3574
  }
3528
- return matches;
3575
+ return matches2;
3529
3576
  }
3530
3577
  /**
3531
3578
  * `segments.excludedPaths`: rutas donde el popup NO debe mostrarse. Gana sobre
@@ -3535,18 +3582,18 @@ var DeepdotsPopups = class {
3535
3582
  isPathExcluded(def, pathUrl) {
3536
3583
  const excluded = def.segments?.excludedPaths;
3537
3584
  if (!Array.isArray(excluded) || excluded.length === 0) return false;
3538
- const location = this.resolveCurrentLocation(pathUrl);
3539
- if (!location) {
3585
+ const location2 = this.resolveCurrentLocation(pathUrl);
3586
+ if (!location2) {
3540
3587
  this.debug("No window.location available for excluded path comparison", { popupId: def.id, excluded });
3541
3588
  return false;
3542
3589
  }
3543
- const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location));
3590
+ const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location2));
3544
3591
  if (hit !== void 0) {
3545
3592
  this.debug("Popup excluded by path", {
3546
3593
  popupId: def.id,
3547
3594
  candidate: hit,
3548
- currentPath: location.path,
3549
- currentHref: location.href
3595
+ currentPath: location2.path,
3596
+ currentHref: location2.href
3550
3597
  });
3551
3598
  return true;
3552
3599
  }
@@ -3562,17 +3609,17 @@ var DeepdotsPopups = class {
3562
3609
  * y no puede tumbar la evaluación del trigger entero (mismo fallo que hubo con
3563
3610
  * `segments.lang`).
3564
3611
  */
3565
- matchesPathCandidate(rawCandidate, location) {
3612
+ matchesPathCandidate(rawCandidate, location2) {
3566
3613
  if (typeof rawCandidate !== "string") return false;
3567
3614
  const candidate = this.normalizeUrl(rawCandidate);
3568
3615
  if (!candidate) return false;
3569
3616
  if (candidate.startsWith("http://") || candidate.startsWith("https://")) {
3570
- return location.href === candidate;
3617
+ return location2.href === candidate;
3571
3618
  }
3572
3619
  if (candidate.startsWith("/")) {
3573
- return location.href.includes(candidate);
3620
+ return location2.href.includes(candidate);
3574
3621
  }
3575
- return location.path === candidate;
3622
+ return location2.path === candidate;
3576
3623
  }
3577
3624
  /** href + pathname normalizados de la ruta a evaluar, o null si no hay `window.location`. */
3578
3625
  resolveCurrentLocation(pathUrl) {
@@ -3738,6 +3785,7 @@ var DeepdotsPopups = class {
3738
3785
  this.log("Missing apiKey or baseUrl. Skipping popups fetch.");
3739
3786
  return [];
3740
3787
  }
3788
+ if (this.contactSync) await this.waitForContactSync();
3741
3789
  const filter = userId ? { where: { userId } } : null;
3742
3790
  const query = filter ? `?filter=${encodeURIComponent(JSON.stringify(filter))}` : "";
3743
3791
  const endpoint = `${baseUrl}/sdk/${encodeURIComponent(apiKey)}/popups${query}`;
@@ -3760,6 +3808,23 @@ var DeepdotsPopups = class {
3760
3808
  return null;
3761
3809
  }
3762
3810
  }
3811
+ /**
3812
+ * DD-561: espera al POST de contact de `init()` antes del GET de popups, como mucho
3813
+ * `CONTACT_SYNC_TIMEOUT_MS`. Sin atributos nuevos la promesa ya está resuelta y no hay espera.
3814
+ * Nunca rechaza.
3815
+ */
3816
+ async waitForContactSync() {
3817
+ const pending2 = this.contactSync;
3818
+ this.contactSync = null;
3819
+ if (!pending2) return;
3820
+ let timer;
3821
+ const timeout = new Promise((resolve) => {
3822
+ timer = setTimeout(() => resolve("timeout"), CONTACT_SYNC_TIMEOUT_MS);
3823
+ });
3824
+ const result = await Promise.race([pending2.then(() => "done", () => "done"), timeout]);
3825
+ if (timer) clearTimeout(timer);
3826
+ if (result === "timeout") this.log("contact \xB7 POST still pending, fetching popups anyway");
3827
+ }
3763
3828
  /**
3764
3829
  * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
3765
3830
  * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché