@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
@@ -5,10 +5,12 @@ import {
5
5
  CHROME_CONTRAST_JS,
6
6
  LABELS,
7
7
  PRIMARY_COLOR_JS,
8
+ PROGRESS_VIEW_JS,
8
9
  RESOLVE_LOCALE_JS,
9
10
  REVEAL_TIMEOUT_MS,
10
11
  RTL_LOCALES,
11
12
  SDK_IDENTIFIER,
13
+ SMALL_CARD_MOBILE_MAX_PX,
12
14
  STORAGE_KEYS,
13
15
  SUBMIT_ERROR_JS,
14
16
  TrackingManager,
@@ -22,13 +24,14 @@ import {
22
24
  getLabels,
23
25
  normalizeAppearance,
24
26
  resolveActionLabels,
27
+ resolvePlacement,
25
28
  sdkLog,
26
29
  sdkWarn,
27
30
  setLogger,
28
31
  style_default,
29
32
  surveySdkCssUrls,
30
33
  surveySdkUrls
31
- } from "./chunk-5UURWEOR.mjs";
34
+ } from "./chunk-7PNQVCOR.mjs";
32
35
  import {
33
36
  __require
34
37
  } from "./chunk-BJTO5JO5.mjs";
@@ -38,6 +41,20 @@ import { createContext, useContext, useEffect, useRef, useState } from "react";
38
41
  import { AppState, Modal, NativeModules, Platform, View } from "react-native";
39
42
  import { WebView } from "react-native-webview";
40
43
 
44
+ // src/core/local-dev-host.ts
45
+ function isLocalDevHost(hostname) {
46
+ if (!hostname) return false;
47
+ const h = hostname.toLowerCase().replace(/^\[|\]$/g, "");
48
+ return h === "localhost" || h.endsWith(".localhost") || h === "0.0.0.0" || h === "::1" || /^127(\.\d{1,3}){3}$/.test(h);
49
+ }
50
+ function currentHostname() {
51
+ try {
52
+ return typeof location !== "undefined" && typeof location.hostname === "string" ? location.hostname : void 0;
53
+ } catch {
54
+ return void 0;
55
+ }
56
+ }
57
+
41
58
  // src/types/index.ts
42
59
  var POPUP_TRIGGER_CONDITION_STATUSES = [
43
60
  "SHOWED",
@@ -251,15 +268,6 @@ function ddCreateReveal(popup, onReveal, timeoutMs){
251
268
  timer=setTimeout(reveal, timeoutMs);
252
269
  return { reveal: reveal, whenPainted: revealWhenPainted };
253
270
  }`;
254
- var POSITION_MAP = {
255
- center: { justifyContent: "center", alignItems: "center", padding: "0", background: "rgba(0,0,0,0.5)" },
256
- bottom: { justifyContent: "center", alignItems: "flex-end", padding: "16px", background: "transparent" },
257
- "bottom-right": { justifyContent: "flex-end", alignItems: "flex-end", padding: "16px", background: "transparent" },
258
- "bottom-left": { justifyContent: "flex-start", alignItems: "flex-end", padding: "16px", background: "transparent" },
259
- top: { justifyContent: "center", alignItems: "flex-start", padding: "16px", background: "transparent" },
260
- "top-right": { justifyContent: "flex-end", alignItems: "flex-start", padding: "16px", background: "transparent" },
261
- "top-left": { justifyContent: "flex-start", alignItems: "flex-start", padding: "16px", background: "transparent" }
262
- };
263
271
  function jsonForScript(value) {
264
272
  return JSON.stringify(value ?? null).replace(/</g, "\\u003C").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
265
273
  }
@@ -288,7 +296,7 @@ function buildSurveyHtml(opts) {
288
296
  const textPrimary = isDark ? "#f0f0f0" : "#111";
289
297
  const textMuted = isDark ? "#9ca3af" : "#6b7280";
290
298
  const trackBg = isDark ? "#3f3f46" : "#e5e7eb";
291
- const pos = POSITION_MAP[opts.position ?? "center"] ?? POSITION_MAP.center;
299
+ const pos = resolvePlacement({ position: opts.position, size: opts.size, blockPage: opts.blockPage });
292
300
  const chrome = opts.chrome !== false;
293
301
  const bodyBg = chrome ? pos.background : "transparent";
294
302
  const bodyPadding = chrome ? pos.padding : "0";
@@ -296,12 +304,12 @@ function buildSurveyHtml(opts) {
296
304
  const cardBg = chrome ? popupBg : "transparent";
297
305
  const cardShadow = chrome ? "0 4px 6px rgba(0,0,0,0.1)" : "none";
298
306
  const cardRadius = chrome ? "8px" : "0";
299
- const cardMaxWidth = chrome ? "600px" : "none";
307
+ const cardMaxWidth = chrome ? `${pos.cardMaxWidthPx}px` : "none";
300
308
  const cardWidth = chrome ? "90%" : "100%";
301
309
  const cardMinHeight = chrome ? "200px" : "0";
302
310
  const cardHeight = chrome ? "auto" : "100%";
303
311
  const cardMaxHeight = chrome ? "90vh" : "100%";
304
- 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}`;
312
+ 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}`;
305
313
  const titleJson = jsonForScript(opts.title ?? "");
306
314
  const customCss = (opts.surveyCss ?? "").replace(/<\/\s*style/gi, "<\\/style");
307
315
  const progressPref = opts.showProgressBar === void 0 ? "null" : String(opts.showProgressBar);
@@ -513,13 +521,17 @@ ${customCss}
513
521
  var progressEnabled=progressPref===true;
514
522
  var progressShowUnit=true;
515
523
  var progressUnit='fraction';
524
+ // DD-210: qu\xE9 cuenta la barra (style.progressMode).
525
+ var progressMode='current';
526
+ ${PROGRESS_VIEW_JS}
516
527
  var onStartPage=false;
517
528
 
518
529
  function updateProgress(p){
519
530
  var total=p&&typeof p.total==='number'?p.total:0;
520
531
  var progress=p&&typeof p.progress==='number'?p.progress:0;
521
- // Solo tiene sentido con m\xE1s de una p\xE1gina, fuera de la pantalla de inicio y sin completar.
522
- if(!progressEnabled||onStartPage||p&&p.completed||total<=1){
532
+ // Reglas en ddProgressView (espejo de progressView.ts, MagicSurvey y el SDK nativo).
533
+ var view=ddProgressView({progress:progress,total:total,completed:!!(p&&p.completed),mode:progressMode,unit:progressUnit},DD_LABELS_ACTIVE);
534
+ if(!progressEnabled||onStartPage||!view.visible){
523
535
  progressEl.style.display='none';
524
536
  // Sin barra, el hueco cabecera\u2192pregunta lo pone el contenido.
525
537
  content.style.paddingTop='16px';
@@ -528,22 +540,11 @@ ${customCss}
528
540
  progressEl.style.display='flex';
529
541
  // Con barra, el hueco inferior ya lo pone el bloque de progreso: no duplicarlo.
530
542
  content.style.paddingTop='0';
531
- // Espejo de LineProgressQuestion (MagicSurvey): la barra usa el valor real (las follow-up
532
- // suman +0.5 y avanzan media casilla) y la etiqueta redondea hacia abajo, porque una
533
- // follow-up es un paso DENTRO de la misma pregunta, no la siguiente.
534
- var current=Math.min(total,Math.max(1,progress+1));
535
- var pct=Math.min(100,Math.max(0,(current/total)*100));
536
- progressBar.style.width=pct+'%';
537
- var label=Math.min(total,Math.max(1,Math.floor(progress)+1));
543
+ progressBar.style.width=view.percent+'%';
538
544
  progressLabel.style.display=progressShowUnit?'block':'none';
539
- if(progressUnit==='percentage'){
540
- progressCurrent.textContent=Math.round(pct)+'%';
541
- progressTotal.textContent='';
542
- } else {
543
- progressCurrent.textContent=DD_LABELS_ACTIVE.question+' '+label;
544
- progressTotal.textContent=' '+DD_LABELS_ACTIVE.of+' '+total;
545
- }
546
- progressFollowUp.style.display=p&&p.followup?'inline-block':'none';
545
+ progressCurrent.textContent=view.current;
546
+ progressTotal.textContent=view.rest;
547
+ progressFollowUp.style.display=p&&p.followup&&!p.completed?'inline-block':'none';
547
548
  }
548
549
 
549
550
  backBtn.textContent=${backLabel};
@@ -770,6 +771,7 @@ ${REVEAL_JS}
770
771
  if(progressPref===null){ progressEnabled=s.showProgressBar===true; }
771
772
  if(s.showProgressUnit!==undefined){ progressShowUnit=s.showProgressUnit!==false; }
772
773
  if(s.progressUnit){ progressUnit=s.progressUnit; }
774
+ if(s.progressMode){ progressMode=s.progressMode; }
773
775
  // Fondo, textos, botones y barra: Style + theme + modo de la app (DD-247, DD-241).
774
776
  ddApplyAppearanceColors(s);
775
777
  if(s.contentAlign){ main.style.justifyContent = s.contentAlign==='center' ? 'center' : 'flex-start'; }
@@ -935,6 +937,8 @@ var ReactNativePopupRenderer = class {
935
937
  font: style?.font,
936
938
  theme: style?.theme,
937
939
  position: style?.position,
940
+ size: style?.size,
941
+ blockPage: style?.blockPage,
938
942
  actions,
939
943
  // renderChrome:false (init) → HTML sin tarjeta/overlay: el host lo envuelve en su Modal.
940
944
  chrome: renderChrome,
@@ -1036,7 +1040,7 @@ function logRnSurveySdkChoice(choice, debug) {
1036
1040
  }
1037
1041
 
1038
1042
  // src/ui/preload.ts
1039
- var defaultLoader = () => import("./renderPopup-SFDIFFUT.mjs");
1043
+ var defaultLoader = () => import("./renderPopup-I565DNZX.mjs");
1040
1044
  var pending = null;
1041
1045
  function preloadRenderPopup(loader = defaultLoader) {
1042
1046
  if (pending) return pending;
@@ -1109,7 +1113,7 @@ var BrowserPopupRenderer = class {
1109
1113
  if (!this.container) return;
1110
1114
  this.visible = true;
1111
1115
  const container = this.container;
1112
- void import("./renderPopup-SFDIFFUT.mjs").then(
1116
+ void import("./renderPopup-I565DNZX.mjs").then(
1113
1117
  ({ renderPopup }) => {
1114
1118
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1115
1119
  },
@@ -1983,6 +1987,35 @@ var ContactManager = class {
1983
1987
  var STACK_MAX = 8e3;
1984
1988
  var QUEUE_KEY = "deepdots.crash.queue";
1985
1989
  var MAX_QUEUED = 20;
1990
+ var BENIGN_ERROR_PATTERNS = [
1991
+ /ResizeObserver loop completed with undelivered notifications/i,
1992
+ /ResizeObserver loop limit exceeded/i
1993
+ ];
1994
+ var NON_FATAL_ERROR_PATTERNS = [
1995
+ /auth\/network-request-failed/i,
1996
+ // IndexedDB cerrándose (pestaña en segundo plano, otra pestaña actualiza la versión, logout).
1997
+ /connection is closing/i
1998
+ ];
1999
+ function errorText(error) {
2000
+ if (error && typeof error === "object") {
2001
+ const e = error;
2002
+ return [e.name, e.code, e.message].filter((v) => typeof v === "string").join(" ");
2003
+ }
2004
+ return String(error ?? "");
2005
+ }
2006
+ var matches = (text, patterns) => patterns.some((p) => p.test(text));
2007
+ function isBenignError(error) {
2008
+ return matches(errorText(error), BENIGN_ERROR_PATTERNS);
2009
+ }
2010
+ function isNonFatalNoise(error) {
2011
+ return matches(errorText(error), NON_FATAL_ERROR_PATTERNS);
2012
+ }
2013
+ function reclassify(r) {
2014
+ const text = `${r.crashType} ${r.message}`;
2015
+ if (matches(text, BENIGN_ERROR_PATTERNS)) return null;
2016
+ if (matches(text, NON_FATAL_ERROR_PATTERNS)) return { ...r, fatal: false, severity: "warning" };
2017
+ return r;
2018
+ }
1986
2019
  function crashRecordToParams(r) {
1987
2020
  const params = {
1988
2021
  crashed_at: r.crashedAt,
@@ -2040,7 +2073,8 @@ var CrashReporter = class {
2040
2073
  /** API pública del host: reporta un error (app viva) → emite el evento ya. */
2041
2074
  reportError(error, options = {}) {
2042
2075
  if (!this.isEnabled()) return;
2043
- const severity = options.severity ?? "error";
2076
+ if (isBenignError(error)) return;
2077
+ const severity = isNonFatalNoise(error) ? "warning" : options.severity ?? "error";
2044
2078
  const handled = options.handled ?? true;
2045
2079
  const fatal = severity === "fatal";
2046
2080
  const record = this.buildRecord(error, severity, handled, fatal, options.context);
@@ -2048,6 +2082,11 @@ var CrashReporter = class {
2048
2082
  }
2049
2083
  /** Captura un error no manejado (fatal) → persiste a disco para replay en el siguiente arranque. */
2050
2084
  captureUnhandled(error) {
2085
+ if (isBenignError(error)) return;
2086
+ if (isNonFatalNoise(error)) {
2087
+ this.persist(this.buildRecord(error, "warning", false, false));
2088
+ return;
2089
+ }
2051
2090
  this.persist(this.buildRecord(error, "fatal", false, true));
2052
2091
  }
2053
2092
  /** Persiste un crash no capturado a disco para reenviarlo en el siguiente arranque. */
@@ -2083,7 +2122,7 @@ var CrashReporter = class {
2083
2122
  } catch {
2084
2123
  }
2085
2124
  }
2086
- return queue;
2125
+ return queue.map(reclassify).filter((r) => r !== null);
2087
2126
  }
2088
2127
  /** Instala los handlers globales de errores no capturados (no-op sin `window`). Idempotente. */
2089
2128
  install() {
@@ -2379,6 +2418,7 @@ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2379
2418
  var RESERVED_EVENT_PREFIX = "deepdots_";
2380
2419
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2381
2420
  var MAX_PENDING_TRIGGERS = 20;
2421
+ var CONTACT_SYNC_TIMEOUT_MS = 1500;
2382
2422
  function triggerDelayMs(delaySeconds) {
2383
2423
  const n = typeof delaySeconds === "number" ? delaySeconds : Number(delaySeconds);
2384
2424
  return Number.isFinite(n) && n > 0 ? Math.round(n * 1e3) : 0;
@@ -2451,6 +2491,8 @@ var DeepdotsPopups = class {
2451
2491
  this.engagement = null;
2452
2492
  /** Atributos internos del usuario identificado → POST /sdk/popups/contact. Null si no hay userId. */
2453
2493
  this.contact = null;
2494
+ /** DD-561: contact POST of `init()`, awaited (with a cap) by the popups GET. Null if none. */
2495
+ this.contactSync = null;
2454
2496
  /** Storage resuelto en init() (inyectado por el host o localStorage). Reusado al cambiar de usuario. */
2455
2497
  this.storage = null;
2456
2498
  /** Marca si ya se inició la navegación manual (setScreen) — para RN sin History API. */
@@ -2538,19 +2580,24 @@ var DeepdotsPopups = class {
2538
2580
  post: (body) => this.postContact(body)
2539
2581
  });
2540
2582
  if (config.contactAttributes) {
2541
- void this.setContactAttributes(config.contactAttributes);
2583
+ this.contactSync = this.setContactAttributes(config.contactAttributes);
2542
2584
  }
2543
2585
  }
2544
2586
  this.log("tracking \xB7 user_id:", this.tracking.getUserId(), "\xB7 new_user:", this.tracking.isNewUser(), "\xB7 enabled:", this.tracking.isTrackingEnabled());
2545
- this.analyticsIntegration = config.analytics?.integration;
2587
+ const localDev = (config.platform ?? "web") === "web" && !config.trackLocalhost && isLocalDevHost(currentHostname());
2588
+ const analyticsKeys = localDev ? void 0 : config.analytics;
2589
+ if (localDev && config.analytics) {
2590
+ this.log("analytics \xB7 localhost: no se env\xEDa (trackLocalhost: true para enviar)");
2591
+ }
2592
+ this.analyticsIntegration = analyticsKeys?.integration;
2546
2593
  const resumable = this.readResumableSession();
2547
2594
  if (resumable) {
2548
2595
  this.analyticsFeedbackSessionId = resumable.sessionId;
2549
2596
  this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2550
2597
  }
2551
- const analyticsSink = config.analytics ? createFeedbackSink({
2598
+ const analyticsSink = analyticsKeys ? createFeedbackSink({
2552
2599
  baseUrl: this.baseUrl,
2553
- keys: config.analytics,
2600
+ keys: analyticsKeys,
2554
2601
  log: (...a) => this.log(...a),
2555
2602
  initialSessionId: resumable?.sessionId,
2556
2603
  // En móvil (RN) la app puede morir con el lote de cierre sin entregar: se
@@ -2598,7 +2645,7 @@ var DeepdotsPopups = class {
2598
2645
  });
2599
2646
  this.installCrashHandlers();
2600
2647
  this.geoEnabled = config.geolocation ?? true;
2601
- this.geoWanted = this.geoEnabled && !!config.analytics;
2648
+ this.geoWanted = this.geoEnabled && !!analyticsKeys;
2602
2649
  this.resolveGeo();
2603
2650
  this.navObserver = new NavigationObserver();
2604
2651
  this.navObserver.onVisit(
@@ -3456,38 +3503,38 @@ var DeepdotsPopups = class {
3456
3503
  this.debug("No language available for lang comparison", { popupId: def.id, langs });
3457
3504
  return true;
3458
3505
  }
3459
- const matches = langs.some(
3506
+ const matches2 = langs.some(
3460
3507
  (lang) => typeof lang === "string" && currentLang.startsWith(lang.toLowerCase())
3461
3508
  );
3462
- if (!matches) {
3509
+ if (!matches2) {
3463
3510
  this.debug("Lang mismatch for popup", { popupId: def.id, langs, currentLang });
3464
3511
  }
3465
- return matches;
3512
+ return matches2;
3466
3513
  }
3467
3514
  /** `segments.path`: rutas donde el popup PUEDE mostrarse. Sin lista, en todas. */
3468
3515
  matchesSegmentsPath(def, pathUrl) {
3469
3516
  const paths = def.segments?.path;
3470
3517
  if (!Array.isArray(paths) || paths.length === 0) return true;
3471
- const location = this.resolveCurrentLocation(pathUrl);
3472
- if (!location) {
3518
+ const location2 = this.resolveCurrentLocation(pathUrl);
3519
+ if (!location2) {
3473
3520
  this.debug("No window.location available for path comparison", { popupId: def.id, paths });
3474
3521
  return true;
3475
3522
  }
3476
- const matches = paths.some((rawCandidate) => {
3477
- const match = this.matchesPathCandidate(rawCandidate, location);
3523
+ const matches2 = paths.some((rawCandidate) => {
3524
+ const match = this.matchesPathCandidate(rawCandidate, location2);
3478
3525
  this.debug("Path comparison", {
3479
3526
  popupId: def.id,
3480
3527
  candidate: rawCandidate,
3481
- currentPath: location.path,
3482
- currentHref: location.href,
3528
+ currentPath: location2.path,
3529
+ currentHref: location2.href,
3483
3530
  match
3484
3531
  });
3485
3532
  return match;
3486
3533
  });
3487
- if (!matches) {
3488
- this.debug("No path match for popup", { popupId: def.id, paths, currentPath: location.path });
3534
+ if (!matches2) {
3535
+ this.debug("No path match for popup", { popupId: def.id, paths, currentPath: location2.path });
3489
3536
  }
3490
- return matches;
3537
+ return matches2;
3491
3538
  }
3492
3539
  /**
3493
3540
  * `segments.excludedPaths`: rutas donde el popup NO debe mostrarse. Gana sobre
@@ -3497,18 +3544,18 @@ var DeepdotsPopups = class {
3497
3544
  isPathExcluded(def, pathUrl) {
3498
3545
  const excluded = def.segments?.excludedPaths;
3499
3546
  if (!Array.isArray(excluded) || excluded.length === 0) return false;
3500
- const location = this.resolveCurrentLocation(pathUrl);
3501
- if (!location) {
3547
+ const location2 = this.resolveCurrentLocation(pathUrl);
3548
+ if (!location2) {
3502
3549
  this.debug("No window.location available for excluded path comparison", { popupId: def.id, excluded });
3503
3550
  return false;
3504
3551
  }
3505
- const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location));
3552
+ const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location2));
3506
3553
  if (hit !== void 0) {
3507
3554
  this.debug("Popup excluded by path", {
3508
3555
  popupId: def.id,
3509
3556
  candidate: hit,
3510
- currentPath: location.path,
3511
- currentHref: location.href
3557
+ currentPath: location2.path,
3558
+ currentHref: location2.href
3512
3559
  });
3513
3560
  return true;
3514
3561
  }
@@ -3524,17 +3571,17 @@ var DeepdotsPopups = class {
3524
3571
  * y no puede tumbar la evaluación del trigger entero (mismo fallo que hubo con
3525
3572
  * `segments.lang`).
3526
3573
  */
3527
- matchesPathCandidate(rawCandidate, location) {
3574
+ matchesPathCandidate(rawCandidate, location2) {
3528
3575
  if (typeof rawCandidate !== "string") return false;
3529
3576
  const candidate = this.normalizeUrl(rawCandidate);
3530
3577
  if (!candidate) return false;
3531
3578
  if (candidate.startsWith("http://") || candidate.startsWith("https://")) {
3532
- return location.href === candidate;
3579
+ return location2.href === candidate;
3533
3580
  }
3534
3581
  if (candidate.startsWith("/")) {
3535
- return location.href.includes(candidate);
3582
+ return location2.href.includes(candidate);
3536
3583
  }
3537
- return location.path === candidate;
3584
+ return location2.path === candidate;
3538
3585
  }
3539
3586
  /** href + pathname normalizados de la ruta a evaluar, o null si no hay `window.location`. */
3540
3587
  resolveCurrentLocation(pathUrl) {
@@ -3700,6 +3747,7 @@ var DeepdotsPopups = class {
3700
3747
  this.log("Missing apiKey or baseUrl. Skipping popups fetch.");
3701
3748
  return [];
3702
3749
  }
3750
+ if (this.contactSync) await this.waitForContactSync();
3703
3751
  const filter = userId ? { where: { userId } } : null;
3704
3752
  const query = filter ? `?filter=${encodeURIComponent(JSON.stringify(filter))}` : "";
3705
3753
  const endpoint = `${baseUrl}/sdk/${encodeURIComponent(apiKey)}/popups${query}`;
@@ -3722,6 +3770,23 @@ var DeepdotsPopups = class {
3722
3770
  return null;
3723
3771
  }
3724
3772
  }
3773
+ /**
3774
+ * DD-561: espera al POST de contact de `init()` antes del GET de popups, como mucho
3775
+ * `CONTACT_SYNC_TIMEOUT_MS`. Sin atributos nuevos la promesa ya está resuelta y no hay espera.
3776
+ * Nunca rechaza.
3777
+ */
3778
+ async waitForContactSync() {
3779
+ const pending2 = this.contactSync;
3780
+ this.contactSync = null;
3781
+ if (!pending2) return;
3782
+ let timer;
3783
+ const timeout = new Promise((resolve) => {
3784
+ timer = setTimeout(() => resolve("timeout"), CONTACT_SYNC_TIMEOUT_MS);
3785
+ });
3786
+ const result = await Promise.race([pending2.then(() => "done", () => "done"), timeout]);
3787
+ if (timer) clearTimeout(timer);
3788
+ if (result === "timeout") this.log("contact \xB7 POST still pending, fetching popups anyway");
3789
+ }
3725
3790
  /**
3726
3791
  * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
3727
3792
  * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché