@magicfeedback/popup-sdk 1.22.0 → 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-36KEHE2P.mjs → chunk-7PNQVCOR.mjs} +156 -5
  9. package/dist/chunk-7PNQVCOR.mjs.map +1 -0
  10. package/dist/{chunk-7PVEXIUG.mjs → chunk-HDCZ2QGX.mjs} +156 -5
  11. package/dist/chunk-HDCZ2QGX.mjs.map +1 -0
  12. package/dist/{chunk-4MUHUL7W.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 +4028 -1312
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +128 -61
  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 +4028 -1312
  23. package/dist/index.native.js.map +1 -1
  24. package/dist/index.native.mjs +128 -61
  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 +2826 -182
  29. package/dist/react-native.js.map +1 -1
  30. package/dist/react-native.mjs +128 -61
  31. package/dist/react-native.mjs.map +1 -1
  32. package/dist/{renderPopup-I3LIC3W3.mjs → renderPopup-I565DNZX.mjs} +21 -29
  33. package/dist/renderPopup-I565DNZX.mjs.map +1 -0
  34. package/dist/{renderPopup-5VVYPKXP.mjs → renderPopup-KWAMONIN.mjs} +1213 -1149
  35. package/dist/renderPopup-KWAMONIN.mjs.map +1 -0
  36. package/dist/{renderPopup-VS5XFGTI.mjs → renderPopup-USTJXQJ6.mjs} +1213 -1149
  37. package/dist/renderPopup-USTJXQJ6.mjs.map +1 -0
  38. package/package.json +2 -2
  39. package/dist/chunk-36KEHE2P.mjs.map +0 -1
  40. package/dist/chunk-4MUHUL7W.mjs.map +0 -1
  41. package/dist/chunk-7PVEXIUG.mjs.map +0 -1
  42. package/dist/renderPopup-5VVYPKXP.mjs.map +0 -1
  43. package/dist/renderPopup-I3LIC3W3.mjs.map +0 -1
  44. package/dist/renderPopup-VS5XFGTI.mjs.map +0 -1
package/dist/index.mjs CHANGED
@@ -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,15 +28,30 @@ 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-7PVEXIUG.mjs";
38
+ } from "./chunk-HDCZ2QGX.mjs";
36
39
  import "./chunk-3QS3WKRC.mjs";
37
40
 
41
+ // src/core/local-dev-host.ts
42
+ function isLocalDevHost(hostname) {
43
+ if (!hostname) return false;
44
+ const h = hostname.toLowerCase().replace(/^\[|\]$/g, "");
45
+ return h === "localhost" || h.endsWith(".localhost") || h === "0.0.0.0" || h === "::1" || /^127(\.\d{1,3}){3}$/.test(h);
46
+ }
47
+ function currentHostname() {
48
+ try {
49
+ return typeof location !== "undefined" && typeof location.hostname === "string" ? location.hostname : void 0;
50
+ } catch {
51
+ return void 0;
52
+ }
53
+ }
54
+
38
55
  // src/types/index.ts
39
56
  var POPUP_TRIGGER_CONDITION_STATUSES = [
40
57
  "SHOWED",
@@ -248,15 +265,6 @@ function ddCreateReveal(popup, onReveal, timeoutMs){
248
265
  timer=setTimeout(reveal, timeoutMs);
249
266
  return { reveal: reveal, whenPainted: revealWhenPainted };
250
267
  }`;
251
- var POSITION_MAP = {
252
- center: { justifyContent: "center", alignItems: "center", padding: "0", background: "rgba(0,0,0,0.5)" },
253
- bottom: { justifyContent: "center", alignItems: "flex-end", padding: "16px", background: "transparent" },
254
- "bottom-right": { justifyContent: "flex-end", alignItems: "flex-end", padding: "16px", background: "transparent" },
255
- "bottom-left": { justifyContent: "flex-start", alignItems: "flex-end", padding: "16px", background: "transparent" },
256
- top: { justifyContent: "center", alignItems: "flex-start", padding: "16px", background: "transparent" },
257
- "top-right": { justifyContent: "flex-end", alignItems: "flex-start", padding: "16px", background: "transparent" },
258
- "top-left": { justifyContent: "flex-start", alignItems: "flex-start", padding: "16px", background: "transparent" }
259
- };
260
268
  function jsonForScript(value) {
261
269
  return JSON.stringify(value ?? null).replace(/</g, "\\u003C").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
262
270
  }
@@ -285,7 +293,7 @@ function buildSurveyHtml(opts) {
285
293
  const textPrimary = isDark ? "#f0f0f0" : "#111";
286
294
  const textMuted = isDark ? "#9ca3af" : "#6b7280";
287
295
  const trackBg = isDark ? "#3f3f46" : "#e5e7eb";
288
- const pos = POSITION_MAP[opts.position ?? "center"] ?? POSITION_MAP.center;
296
+ const pos = resolvePlacement({ position: opts.position, size: opts.size, blockPage: opts.blockPage });
289
297
  const chrome = opts.chrome !== false;
290
298
  const bodyBg = chrome ? pos.background : "transparent";
291
299
  const bodyPadding = chrome ? pos.padding : "0";
@@ -293,12 +301,12 @@ function buildSurveyHtml(opts) {
293
301
  const cardBg = chrome ? popupBg : "transparent";
294
302
  const cardShadow = chrome ? "0 4px 6px rgba(0,0,0,0.1)" : "none";
295
303
  const cardRadius = chrome ? "8px" : "0";
296
- const cardMaxWidth = chrome ? "600px" : "none";
304
+ const cardMaxWidth = chrome ? `${pos.cardMaxWidthPx}px` : "none";
297
305
  const cardWidth = chrome ? "90%" : "100%";
298
306
  const cardMinHeight = chrome ? "200px" : "0";
299
307
  const cardHeight = chrome ? "auto" : "100%";
300
308
  const cardMaxHeight = chrome ? "90vh" : "100%";
301
- 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}`;
309
+ 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}`;
302
310
  const titleJson = jsonForScript(opts.title ?? "");
303
311
  const customCss = (opts.surveyCss ?? "").replace(/<\/\s*style/gi, "<\\/style");
304
312
  const progressPref = opts.showProgressBar === void 0 ? "null" : String(opts.showProgressBar);
@@ -382,7 +390,7 @@ body.dd-ready #dd-popup{visibility:visible}
382
390
  .deepdots-load-error{display:none;width:100%;text-align:center;padding:24px 0;font-size:15px;color:var(--dd-text-primary,${textPrimary})}
383
391
  .deepdots-success{display:none;width:100%;text-align:center;padding:24px 0;color:var(--dd-text-primary,${textPrimary})}
384
392
  .deepdots-success img{max-width:100%;height:auto;margin:0 auto 16px auto;display:block}
385
- .deepdots-success p{margin:0;font-size:16px;font-weight:600;line-height:1.4}
393
+ .deepdots-success p{margin:0;font-size:16px;font-weight:600;line-height:1.4;color:var(--dd-success-text,var(--mf-text-secondary))}
386
394
  .deepdots-popup-footer{display:flex;flex-direction:row-reverse;justify-content:space-between;align-items:center;gap:4px;margin-top:auto;width:100%;padding-top:12px}
387
395
  .dd-nav-btn{display:none;border:none;min-height:44px;padding:12px 24px;border-radius:999px;cursor:pointer;font-size:15px;font-weight:600;align-items:center;justify-content:center;text-align:center}
388
396
  /* Secundario como bot\xF3n de texto: sin borde ni fondo, para que el primario sea la \xFAnica CTA. */
@@ -510,13 +518,17 @@ ${customCss}
510
518
  var progressEnabled=progressPref===true;
511
519
  var progressShowUnit=true;
512
520
  var progressUnit='fraction';
521
+ // DD-210: qu\xE9 cuenta la barra (style.progressMode).
522
+ var progressMode='current';
523
+ ${PROGRESS_VIEW_JS}
513
524
  var onStartPage=false;
514
525
 
515
526
  function updateProgress(p){
516
527
  var total=p&&typeof p.total==='number'?p.total:0;
517
528
  var progress=p&&typeof p.progress==='number'?p.progress:0;
518
- // Solo tiene sentido con m\xE1s de una p\xE1gina, fuera de la pantalla de inicio y sin completar.
519
- if(!progressEnabled||onStartPage||p&&p.completed||total<=1){
529
+ // Reglas en ddProgressView (espejo de progressView.ts, MagicSurvey y el SDK nativo).
530
+ var view=ddProgressView({progress:progress,total:total,completed:!!(p&&p.completed),mode:progressMode,unit:progressUnit},DD_LABELS_ACTIVE);
531
+ if(!progressEnabled||onStartPage||!view.visible){
520
532
  progressEl.style.display='none';
521
533
  // Sin barra, el hueco cabecera\u2192pregunta lo pone el contenido.
522
534
  content.style.paddingTop='16px';
@@ -525,22 +537,11 @@ ${customCss}
525
537
  progressEl.style.display='flex';
526
538
  // Con barra, el hueco inferior ya lo pone el bloque de progreso: no duplicarlo.
527
539
  content.style.paddingTop='0';
528
- // Espejo de LineProgressQuestion (MagicSurvey): la barra usa el valor real (las follow-up
529
- // suman +0.5 y avanzan media casilla) y la etiqueta redondea hacia abajo, porque una
530
- // follow-up es un paso DENTRO de la misma pregunta, no la siguiente.
531
- var current=Math.min(total,Math.max(1,progress+1));
532
- var pct=Math.min(100,Math.max(0,(current/total)*100));
533
- progressBar.style.width=pct+'%';
534
- var label=Math.min(total,Math.max(1,Math.floor(progress)+1));
540
+ progressBar.style.width=view.percent+'%';
535
541
  progressLabel.style.display=progressShowUnit?'block':'none';
536
- if(progressUnit==='percentage'){
537
- progressCurrent.textContent=Math.round(pct)+'%';
538
- progressTotal.textContent='';
539
- } else {
540
- progressCurrent.textContent=DD_LABELS_ACTIVE.question+' '+label;
541
- progressTotal.textContent=' '+DD_LABELS_ACTIVE.of+' '+total;
542
- }
543
- progressFollowUp.style.display=p&&p.followup?'inline-block':'none';
542
+ progressCurrent.textContent=view.current;
543
+ progressTotal.textContent=view.rest;
544
+ progressFollowUp.style.display=p&&p.followup&&!p.completed?'inline-block':'none';
544
545
  }
545
546
 
546
547
  backBtn.textContent=${backLabel};
@@ -638,6 +639,8 @@ function ddApplyChromeContrast(bg){
638
639
  el.style.setProperty('--dd-text-primary', pal.textPrimary);
639
640
  el.style.setProperty('--dd-text-muted', pal.textMuted);
640
641
  el.style.setProperty('--dd-progress-track', pal.progressTrack);
642
+ // DD-248: el gracias va fuera del contenedor del survey, donde el gris del survey es el claro.
643
+ if(dark){ el.style.setProperty('--dd-success-text', pal.textPrimary); } else { el.style.removeProperty('--dd-success-text'); }
641
644
  var meta=document.querySelector('meta[name="color-scheme"]');
642
645
  if(meta){ meta.setAttribute('content', pal.colorScheme); }
643
646
  }
@@ -765,6 +768,7 @@ ${REVEAL_JS}
765
768
  if(progressPref===null){ progressEnabled=s.showProgressBar===true; }
766
769
  if(s.showProgressUnit!==undefined){ progressShowUnit=s.showProgressUnit!==false; }
767
770
  if(s.progressUnit){ progressUnit=s.progressUnit; }
771
+ if(s.progressMode){ progressMode=s.progressMode; }
768
772
  // Fondo, textos, botones y barra: Style + theme + modo de la app (DD-247, DD-241).
769
773
  ddApplyAppearanceColors(s);
770
774
  if(s.contentAlign){ main.style.justifyContent = s.contentAlign==='center' ? 'center' : 'flex-start'; }
@@ -930,6 +934,8 @@ var ReactNativePopupRenderer = class {
930
934
  font: style?.font,
931
935
  theme: style?.theme,
932
936
  position: style?.position,
937
+ size: style?.size,
938
+ blockPage: style?.blockPage,
933
939
  actions,
934
940
  // renderChrome:false (init) → HTML sin tarjeta/overlay: el host lo envuelve en su Modal.
935
941
  chrome: renderChrome,
@@ -1031,7 +1037,7 @@ function logRnSurveySdkChoice(choice, debug) {
1031
1037
  }
1032
1038
 
1033
1039
  // src/ui/preload.ts
1034
- var defaultLoader = () => import("./renderPopup-VS5XFGTI.mjs");
1040
+ var defaultLoader = () => import("./renderPopup-KWAMONIN.mjs");
1035
1041
  var pending = null;
1036
1042
  function preloadRenderPopup(loader = defaultLoader) {
1037
1043
  if (pending) return pending;
@@ -1104,7 +1110,7 @@ var BrowserPopupRenderer = class {
1104
1110
  if (!this.container) return;
1105
1111
  this.visible = true;
1106
1112
  const container = this.container;
1107
- void import("./renderPopup-VS5XFGTI.mjs").then(
1113
+ void import("./renderPopup-KWAMONIN.mjs").then(
1108
1114
  ({ renderPopup }) => {
1109
1115
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1110
1116
  },
@@ -1992,6 +1998,35 @@ var ContactManager = class {
1992
1998
  var STACK_MAX = 8e3;
1993
1999
  var QUEUE_KEY = "deepdots.crash.queue";
1994
2000
  var MAX_QUEUED = 20;
2001
+ var BENIGN_ERROR_PATTERNS = [
2002
+ /ResizeObserver loop completed with undelivered notifications/i,
2003
+ /ResizeObserver loop limit exceeded/i
2004
+ ];
2005
+ var NON_FATAL_ERROR_PATTERNS = [
2006
+ /auth\/network-request-failed/i,
2007
+ // IndexedDB cerrándose (pestaña en segundo plano, otra pestaña actualiza la versión, logout).
2008
+ /connection is closing/i
2009
+ ];
2010
+ function errorText(error) {
2011
+ if (error && typeof error === "object") {
2012
+ const e = error;
2013
+ return [e.name, e.code, e.message].filter((v) => typeof v === "string").join(" ");
2014
+ }
2015
+ return String(error ?? "");
2016
+ }
2017
+ var matches = (text, patterns) => patterns.some((p) => p.test(text));
2018
+ function isBenignError(error) {
2019
+ return matches(errorText(error), BENIGN_ERROR_PATTERNS);
2020
+ }
2021
+ function isNonFatalNoise(error) {
2022
+ return matches(errorText(error), NON_FATAL_ERROR_PATTERNS);
2023
+ }
2024
+ function reclassify(r) {
2025
+ const text = `${r.crashType} ${r.message}`;
2026
+ if (matches(text, BENIGN_ERROR_PATTERNS)) return null;
2027
+ if (matches(text, NON_FATAL_ERROR_PATTERNS)) return { ...r, fatal: false, severity: "warning" };
2028
+ return r;
2029
+ }
1995
2030
  function crashRecordToParams(r) {
1996
2031
  const params = {
1997
2032
  crashed_at: r.crashedAt,
@@ -2049,7 +2084,8 @@ var CrashReporter = class {
2049
2084
  /** API pública del host: reporta un error (app viva) → emite el evento ya. */
2050
2085
  reportError(error, options = {}) {
2051
2086
  if (!this.isEnabled()) return;
2052
- const severity = options.severity ?? "error";
2087
+ if (isBenignError(error)) return;
2088
+ const severity = isNonFatalNoise(error) ? "warning" : options.severity ?? "error";
2053
2089
  const handled = options.handled ?? true;
2054
2090
  const fatal = severity === "fatal";
2055
2091
  const record = this.buildRecord(error, severity, handled, fatal, options.context);
@@ -2057,6 +2093,11 @@ var CrashReporter = class {
2057
2093
  }
2058
2094
  /** Captura un error no manejado (fatal) → persiste a disco para replay en el siguiente arranque. */
2059
2095
  captureUnhandled(error) {
2096
+ if (isBenignError(error)) return;
2097
+ if (isNonFatalNoise(error)) {
2098
+ this.persist(this.buildRecord(error, "warning", false, false));
2099
+ return;
2100
+ }
2060
2101
  this.persist(this.buildRecord(error, "fatal", false, true));
2061
2102
  }
2062
2103
  /** Persiste un crash no capturado a disco para reenviarlo en el siguiente arranque. */
@@ -2092,7 +2133,7 @@ var CrashReporter = class {
2092
2133
  } catch {
2093
2134
  }
2094
2135
  }
2095
- return queue;
2136
+ return queue.map(reclassify).filter((r) => r !== null);
2096
2137
  }
2097
2138
  /** Instala los handlers globales de errores no capturados (no-op sin `window`). Idempotente. */
2098
2139
  install() {
@@ -2385,6 +2426,7 @@ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2385
2426
  var RESERVED_EVENT_PREFIX = "deepdots_";
2386
2427
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2387
2428
  var MAX_PENDING_TRIGGERS = 20;
2429
+ var CONTACT_SYNC_TIMEOUT_MS = 1500;
2388
2430
  function triggerDelayMs(delaySeconds) {
2389
2431
  const n = typeof delaySeconds === "number" ? delaySeconds : Number(delaySeconds);
2390
2432
  return Number.isFinite(n) && n > 0 ? Math.round(n * 1e3) : 0;
@@ -2457,6 +2499,8 @@ var DeepdotsPopups = class {
2457
2499
  this.engagement = null;
2458
2500
  /** Atributos internos del usuario identificado → POST /sdk/popups/contact. Null si no hay userId. */
2459
2501
  this.contact = null;
2502
+ /** DD-561: contact POST of `init()`, awaited (with a cap) by the popups GET. Null if none. */
2503
+ this.contactSync = null;
2460
2504
  /** Storage resuelto en init() (inyectado por el host o localStorage). Reusado al cambiar de usuario. */
2461
2505
  this.storage = null;
2462
2506
  /** Marca si ya se inició la navegación manual (setScreen) — para RN sin History API. */
@@ -2544,19 +2588,24 @@ var DeepdotsPopups = class {
2544
2588
  post: (body) => this.postContact(body)
2545
2589
  });
2546
2590
  if (config.contactAttributes) {
2547
- void this.setContactAttributes(config.contactAttributes);
2591
+ this.contactSync = this.setContactAttributes(config.contactAttributes);
2548
2592
  }
2549
2593
  }
2550
2594
  this.log("tracking \xB7 user_id:", this.tracking.getUserId(), "\xB7 new_user:", this.tracking.isNewUser(), "\xB7 enabled:", this.tracking.isTrackingEnabled());
2551
- this.analyticsIntegration = config.analytics?.integration;
2595
+ const localDev = (config.platform ?? "web") === "web" && !config.trackLocalhost && isLocalDevHost(currentHostname());
2596
+ const analyticsKeys = localDev ? void 0 : config.analytics;
2597
+ if (localDev && config.analytics) {
2598
+ this.log("analytics \xB7 localhost: no se env\xEDa (trackLocalhost: true para enviar)");
2599
+ }
2600
+ this.analyticsIntegration = analyticsKeys?.integration;
2552
2601
  const resumable = this.readResumableSession();
2553
2602
  if (resumable) {
2554
2603
  this.analyticsFeedbackSessionId = resumable.sessionId;
2555
2604
  this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2556
2605
  }
2557
- const analyticsSink = config.analytics ? createFeedbackSink({
2606
+ const analyticsSink = analyticsKeys ? createFeedbackSink({
2558
2607
  baseUrl: this.baseUrl,
2559
- keys: config.analytics,
2608
+ keys: analyticsKeys,
2560
2609
  log: (...a) => this.log(...a),
2561
2610
  initialSessionId: resumable?.sessionId,
2562
2611
  // En móvil (RN) la app puede morir con el lote de cierre sin entregar: se
@@ -2604,7 +2653,7 @@ var DeepdotsPopups = class {
2604
2653
  });
2605
2654
  this.installCrashHandlers();
2606
2655
  this.geoEnabled = config.geolocation ?? true;
2607
- this.geoWanted = this.geoEnabled && !!config.analytics;
2656
+ this.geoWanted = this.geoEnabled && !!analyticsKeys;
2608
2657
  this.resolveGeo();
2609
2658
  this.navObserver = new NavigationObserver();
2610
2659
  this.navObserver.onVisit(
@@ -3462,38 +3511,38 @@ var DeepdotsPopups = class {
3462
3511
  this.debug("No language available for lang comparison", { popupId: def.id, langs });
3463
3512
  return true;
3464
3513
  }
3465
- const matches = langs.some(
3514
+ const matches2 = langs.some(
3466
3515
  (lang) => typeof lang === "string" && currentLang.startsWith(lang.toLowerCase())
3467
3516
  );
3468
- if (!matches) {
3517
+ if (!matches2) {
3469
3518
  this.debug("Lang mismatch for popup", { popupId: def.id, langs, currentLang });
3470
3519
  }
3471
- return matches;
3520
+ return matches2;
3472
3521
  }
3473
3522
  /** `segments.path`: rutas donde el popup PUEDE mostrarse. Sin lista, en todas. */
3474
3523
  matchesSegmentsPath(def, pathUrl) {
3475
3524
  const paths = def.segments?.path;
3476
3525
  if (!Array.isArray(paths) || paths.length === 0) return true;
3477
- const location = this.resolveCurrentLocation(pathUrl);
3478
- if (!location) {
3526
+ const location2 = this.resolveCurrentLocation(pathUrl);
3527
+ if (!location2) {
3479
3528
  this.debug("No window.location available for path comparison", { popupId: def.id, paths });
3480
3529
  return true;
3481
3530
  }
3482
- const matches = paths.some((rawCandidate) => {
3483
- const match = this.matchesPathCandidate(rawCandidate, location);
3531
+ const matches2 = paths.some((rawCandidate) => {
3532
+ const match = this.matchesPathCandidate(rawCandidate, location2);
3484
3533
  this.debug("Path comparison", {
3485
3534
  popupId: def.id,
3486
3535
  candidate: rawCandidate,
3487
- currentPath: location.path,
3488
- currentHref: location.href,
3536
+ currentPath: location2.path,
3537
+ currentHref: location2.href,
3489
3538
  match
3490
3539
  });
3491
3540
  return match;
3492
3541
  });
3493
- if (!matches) {
3494
- this.debug("No path match for popup", { popupId: def.id, paths, currentPath: location.path });
3542
+ if (!matches2) {
3543
+ this.debug("No path match for popup", { popupId: def.id, paths, currentPath: location2.path });
3495
3544
  }
3496
- return matches;
3545
+ return matches2;
3497
3546
  }
3498
3547
  /**
3499
3548
  * `segments.excludedPaths`: rutas donde el popup NO debe mostrarse. Gana sobre
@@ -3503,18 +3552,18 @@ var DeepdotsPopups = class {
3503
3552
  isPathExcluded(def, pathUrl) {
3504
3553
  const excluded = def.segments?.excludedPaths;
3505
3554
  if (!Array.isArray(excluded) || excluded.length === 0) return false;
3506
- const location = this.resolveCurrentLocation(pathUrl);
3507
- if (!location) {
3555
+ const location2 = this.resolveCurrentLocation(pathUrl);
3556
+ if (!location2) {
3508
3557
  this.debug("No window.location available for excluded path comparison", { popupId: def.id, excluded });
3509
3558
  return false;
3510
3559
  }
3511
- const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location));
3560
+ const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location2));
3512
3561
  if (hit !== void 0) {
3513
3562
  this.debug("Popup excluded by path", {
3514
3563
  popupId: def.id,
3515
3564
  candidate: hit,
3516
- currentPath: location.path,
3517
- currentHref: location.href
3565
+ currentPath: location2.path,
3566
+ currentHref: location2.href
3518
3567
  });
3519
3568
  return true;
3520
3569
  }
@@ -3530,17 +3579,17 @@ var DeepdotsPopups = class {
3530
3579
  * y no puede tumbar la evaluación del trigger entero (mismo fallo que hubo con
3531
3580
  * `segments.lang`).
3532
3581
  */
3533
- matchesPathCandidate(rawCandidate, location) {
3582
+ matchesPathCandidate(rawCandidate, location2) {
3534
3583
  if (typeof rawCandidate !== "string") return false;
3535
3584
  const candidate = this.normalizeUrl(rawCandidate);
3536
3585
  if (!candidate) return false;
3537
3586
  if (candidate.startsWith("http://") || candidate.startsWith("https://")) {
3538
- return location.href === candidate;
3587
+ return location2.href === candidate;
3539
3588
  }
3540
3589
  if (candidate.startsWith("/")) {
3541
- return location.href.includes(candidate);
3590
+ return location2.href.includes(candidate);
3542
3591
  }
3543
- return location.path === candidate;
3592
+ return location2.path === candidate;
3544
3593
  }
3545
3594
  /** href + pathname normalizados de la ruta a evaluar, o null si no hay `window.location`. */
3546
3595
  resolveCurrentLocation(pathUrl) {
@@ -3706,6 +3755,7 @@ var DeepdotsPopups = class {
3706
3755
  this.log("Missing apiKey or baseUrl. Skipping popups fetch.");
3707
3756
  return [];
3708
3757
  }
3758
+ if (this.contactSync) await this.waitForContactSync();
3709
3759
  const filter = userId ? { where: { userId } } : null;
3710
3760
  const query = filter ? `?filter=${encodeURIComponent(JSON.stringify(filter))}` : "";
3711
3761
  const endpoint = `${baseUrl}/sdk/${encodeURIComponent(apiKey)}/popups${query}`;
@@ -3728,6 +3778,23 @@ var DeepdotsPopups = class {
3728
3778
  return null;
3729
3779
  }
3730
3780
  }
3781
+ /**
3782
+ * DD-561: espera al POST de contact de `init()` antes del GET de popups, como mucho
3783
+ * `CONTACT_SYNC_TIMEOUT_MS`. Sin atributos nuevos la promesa ya está resuelta y no hay espera.
3784
+ * Nunca rechaza.
3785
+ */
3786
+ async waitForContactSync() {
3787
+ const pending2 = this.contactSync;
3788
+ this.contactSync = null;
3789
+ if (!pending2) return;
3790
+ let timer;
3791
+ const timeout = new Promise((resolve) => {
3792
+ timer = setTimeout(() => resolve("timeout"), CONTACT_SYNC_TIMEOUT_MS);
3793
+ });
3794
+ const result = await Promise.race([pending2.then(() => "done", () => "done"), timeout]);
3795
+ if (timer) clearTimeout(timer);
3796
+ if (result === "timeout") this.log("contact \xB7 POST still pending, fetching popups anyway");
3797
+ }
3731
3798
  /**
3732
3799
  * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
3733
3800
  * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché