@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
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-4TNJ2IBB.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);
@@ -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};
@@ -767,6 +768,7 @@ ${REVEAL_JS}
767
768
  if(progressPref===null){ progressEnabled=s.showProgressBar===true; }
768
769
  if(s.showProgressUnit!==undefined){ progressShowUnit=s.showProgressUnit!==false; }
769
770
  if(s.progressUnit){ progressUnit=s.progressUnit; }
771
+ if(s.progressMode){ progressMode=s.progressMode; }
770
772
  // Fondo, textos, botones y barra: Style + theme + modo de la app (DD-247, DD-241).
771
773
  ddApplyAppearanceColors(s);
772
774
  if(s.contentAlign){ main.style.justifyContent = s.contentAlign==='center' ? 'center' : 'flex-start'; }
@@ -932,6 +934,8 @@ var ReactNativePopupRenderer = class {
932
934
  font: style?.font,
933
935
  theme: style?.theme,
934
936
  position: style?.position,
937
+ size: style?.size,
938
+ blockPage: style?.blockPage,
935
939
  actions,
936
940
  // renderChrome:false (init) → HTML sin tarjeta/overlay: el host lo envuelve en su Modal.
937
941
  chrome: renderChrome,
@@ -1033,7 +1037,7 @@ function logRnSurveySdkChoice(choice, debug) {
1033
1037
  }
1034
1038
 
1035
1039
  // src/ui/preload.ts
1036
- var defaultLoader = () => import("./renderPopup-UXD7L3FX.mjs");
1040
+ var defaultLoader = () => import("./renderPopup-KWAMONIN.mjs");
1037
1041
  var pending = null;
1038
1042
  function preloadRenderPopup(loader = defaultLoader) {
1039
1043
  if (pending) return pending;
@@ -1106,7 +1110,7 @@ var BrowserPopupRenderer = class {
1106
1110
  if (!this.container) return;
1107
1111
  this.visible = true;
1108
1112
  const container = this.container;
1109
- void import("./renderPopup-UXD7L3FX.mjs").then(
1113
+ void import("./renderPopup-KWAMONIN.mjs").then(
1110
1114
  ({ renderPopup }) => {
1111
1115
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1112
1116
  },
@@ -1994,6 +1998,35 @@ var ContactManager = class {
1994
1998
  var STACK_MAX = 8e3;
1995
1999
  var QUEUE_KEY = "deepdots.crash.queue";
1996
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
+ }
1997
2030
  function crashRecordToParams(r) {
1998
2031
  const params = {
1999
2032
  crashed_at: r.crashedAt,
@@ -2051,7 +2084,8 @@ var CrashReporter = class {
2051
2084
  /** API pública del host: reporta un error (app viva) → emite el evento ya. */
2052
2085
  reportError(error, options = {}) {
2053
2086
  if (!this.isEnabled()) return;
2054
- const severity = options.severity ?? "error";
2087
+ if (isBenignError(error)) return;
2088
+ const severity = isNonFatalNoise(error) ? "warning" : options.severity ?? "error";
2055
2089
  const handled = options.handled ?? true;
2056
2090
  const fatal = severity === "fatal";
2057
2091
  const record = this.buildRecord(error, severity, handled, fatal, options.context);
@@ -2059,6 +2093,11 @@ var CrashReporter = class {
2059
2093
  }
2060
2094
  /** Captura un error no manejado (fatal) → persiste a disco para replay en el siguiente arranque. */
2061
2095
  captureUnhandled(error) {
2096
+ if (isBenignError(error)) return;
2097
+ if (isNonFatalNoise(error)) {
2098
+ this.persist(this.buildRecord(error, "warning", false, false));
2099
+ return;
2100
+ }
2062
2101
  this.persist(this.buildRecord(error, "fatal", false, true));
2063
2102
  }
2064
2103
  /** Persiste un crash no capturado a disco para reenviarlo en el siguiente arranque. */
@@ -2094,7 +2133,7 @@ var CrashReporter = class {
2094
2133
  } catch {
2095
2134
  }
2096
2135
  }
2097
- return queue;
2136
+ return queue.map(reclassify).filter((r) => r !== null);
2098
2137
  }
2099
2138
  /** Instala los handlers globales de errores no capturados (no-op sin `window`). Idempotente. */
2100
2139
  install() {
@@ -2387,6 +2426,7 @@ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2387
2426
  var RESERVED_EVENT_PREFIX = "deepdots_";
2388
2427
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2389
2428
  var MAX_PENDING_TRIGGERS = 20;
2429
+ var CONTACT_SYNC_TIMEOUT_MS = 1500;
2390
2430
  function triggerDelayMs(delaySeconds) {
2391
2431
  const n = typeof delaySeconds === "number" ? delaySeconds : Number(delaySeconds);
2392
2432
  return Number.isFinite(n) && n > 0 ? Math.round(n * 1e3) : 0;
@@ -2459,6 +2499,8 @@ var DeepdotsPopups = class {
2459
2499
  this.engagement = null;
2460
2500
  /** Atributos internos del usuario identificado → POST /sdk/popups/contact. Null si no hay userId. */
2461
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;
2462
2504
  /** Storage resuelto en init() (inyectado por el host o localStorage). Reusado al cambiar de usuario. */
2463
2505
  this.storage = null;
2464
2506
  /** Marca si ya se inició la navegación manual (setScreen) — para RN sin History API. */
@@ -2546,19 +2588,24 @@ var DeepdotsPopups = class {
2546
2588
  post: (body) => this.postContact(body)
2547
2589
  });
2548
2590
  if (config.contactAttributes) {
2549
- void this.setContactAttributes(config.contactAttributes);
2591
+ this.contactSync = this.setContactAttributes(config.contactAttributes);
2550
2592
  }
2551
2593
  }
2552
2594
  this.log("tracking \xB7 user_id:", this.tracking.getUserId(), "\xB7 new_user:", this.tracking.isNewUser(), "\xB7 enabled:", this.tracking.isTrackingEnabled());
2553
- 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;
2554
2601
  const resumable = this.readResumableSession();
2555
2602
  if (resumable) {
2556
2603
  this.analyticsFeedbackSessionId = resumable.sessionId;
2557
2604
  this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2558
2605
  }
2559
- const analyticsSink = config.analytics ? createFeedbackSink({
2606
+ const analyticsSink = analyticsKeys ? createFeedbackSink({
2560
2607
  baseUrl: this.baseUrl,
2561
- keys: config.analytics,
2608
+ keys: analyticsKeys,
2562
2609
  log: (...a) => this.log(...a),
2563
2610
  initialSessionId: resumable?.sessionId,
2564
2611
  // En móvil (RN) la app puede morir con el lote de cierre sin entregar: se
@@ -2606,7 +2653,7 @@ var DeepdotsPopups = class {
2606
2653
  });
2607
2654
  this.installCrashHandlers();
2608
2655
  this.geoEnabled = config.geolocation ?? true;
2609
- this.geoWanted = this.geoEnabled && !!config.analytics;
2656
+ this.geoWanted = this.geoEnabled && !!analyticsKeys;
2610
2657
  this.resolveGeo();
2611
2658
  this.navObserver = new NavigationObserver();
2612
2659
  this.navObserver.onVisit(
@@ -3464,38 +3511,38 @@ var DeepdotsPopups = class {
3464
3511
  this.debug("No language available for lang comparison", { popupId: def.id, langs });
3465
3512
  return true;
3466
3513
  }
3467
- const matches = langs.some(
3514
+ const matches2 = langs.some(
3468
3515
  (lang) => typeof lang === "string" && currentLang.startsWith(lang.toLowerCase())
3469
3516
  );
3470
- if (!matches) {
3517
+ if (!matches2) {
3471
3518
  this.debug("Lang mismatch for popup", { popupId: def.id, langs, currentLang });
3472
3519
  }
3473
- return matches;
3520
+ return matches2;
3474
3521
  }
3475
3522
  /** `segments.path`: rutas donde el popup PUEDE mostrarse. Sin lista, en todas. */
3476
3523
  matchesSegmentsPath(def, pathUrl) {
3477
3524
  const paths = def.segments?.path;
3478
3525
  if (!Array.isArray(paths) || paths.length === 0) return true;
3479
- const location = this.resolveCurrentLocation(pathUrl);
3480
- if (!location) {
3526
+ const location2 = this.resolveCurrentLocation(pathUrl);
3527
+ if (!location2) {
3481
3528
  this.debug("No window.location available for path comparison", { popupId: def.id, paths });
3482
3529
  return true;
3483
3530
  }
3484
- const matches = paths.some((rawCandidate) => {
3485
- const match = this.matchesPathCandidate(rawCandidate, location);
3531
+ const matches2 = paths.some((rawCandidate) => {
3532
+ const match = this.matchesPathCandidate(rawCandidate, location2);
3486
3533
  this.debug("Path comparison", {
3487
3534
  popupId: def.id,
3488
3535
  candidate: rawCandidate,
3489
- currentPath: location.path,
3490
- currentHref: location.href,
3536
+ currentPath: location2.path,
3537
+ currentHref: location2.href,
3491
3538
  match
3492
3539
  });
3493
3540
  return match;
3494
3541
  });
3495
- if (!matches) {
3496
- 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 });
3497
3544
  }
3498
- return matches;
3545
+ return matches2;
3499
3546
  }
3500
3547
  /**
3501
3548
  * `segments.excludedPaths`: rutas donde el popup NO debe mostrarse. Gana sobre
@@ -3505,18 +3552,18 @@ var DeepdotsPopups = class {
3505
3552
  isPathExcluded(def, pathUrl) {
3506
3553
  const excluded = def.segments?.excludedPaths;
3507
3554
  if (!Array.isArray(excluded) || excluded.length === 0) return false;
3508
- const location = this.resolveCurrentLocation(pathUrl);
3509
- if (!location) {
3555
+ const location2 = this.resolveCurrentLocation(pathUrl);
3556
+ if (!location2) {
3510
3557
  this.debug("No window.location available for excluded path comparison", { popupId: def.id, excluded });
3511
3558
  return false;
3512
3559
  }
3513
- const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location));
3560
+ const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location2));
3514
3561
  if (hit !== void 0) {
3515
3562
  this.debug("Popup excluded by path", {
3516
3563
  popupId: def.id,
3517
3564
  candidate: hit,
3518
- currentPath: location.path,
3519
- currentHref: location.href
3565
+ currentPath: location2.path,
3566
+ currentHref: location2.href
3520
3567
  });
3521
3568
  return true;
3522
3569
  }
@@ -3532,17 +3579,17 @@ var DeepdotsPopups = class {
3532
3579
  * y no puede tumbar la evaluación del trigger entero (mismo fallo que hubo con
3533
3580
  * `segments.lang`).
3534
3581
  */
3535
- matchesPathCandidate(rawCandidate, location) {
3582
+ matchesPathCandidate(rawCandidate, location2) {
3536
3583
  if (typeof rawCandidate !== "string") return false;
3537
3584
  const candidate = this.normalizeUrl(rawCandidate);
3538
3585
  if (!candidate) return false;
3539
3586
  if (candidate.startsWith("http://") || candidate.startsWith("https://")) {
3540
- return location.href === candidate;
3587
+ return location2.href === candidate;
3541
3588
  }
3542
3589
  if (candidate.startsWith("/")) {
3543
- return location.href.includes(candidate);
3590
+ return location2.href.includes(candidate);
3544
3591
  }
3545
- return location.path === candidate;
3592
+ return location2.path === candidate;
3546
3593
  }
3547
3594
  /** href + pathname normalizados de la ruta a evaluar, o null si no hay `window.location`. */
3548
3595
  resolveCurrentLocation(pathUrl) {
@@ -3708,6 +3755,7 @@ var DeepdotsPopups = class {
3708
3755
  this.log("Missing apiKey or baseUrl. Skipping popups fetch.");
3709
3756
  return [];
3710
3757
  }
3758
+ if (this.contactSync) await this.waitForContactSync();
3711
3759
  const filter = userId ? { where: { userId } } : null;
3712
3760
  const query = filter ? `?filter=${encodeURIComponent(JSON.stringify(filter))}` : "";
3713
3761
  const endpoint = `${baseUrl}/sdk/${encodeURIComponent(apiKey)}/popups${query}`;
@@ -3730,6 +3778,23 @@ var DeepdotsPopups = class {
3730
3778
  return null;
3731
3779
  }
3732
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
+ }
3733
3798
  /**
3734
3799
  * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
3735
3800
  * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché