@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
@@ -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-36KEHE2P.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);
@@ -385,7 +393,7 @@ body.dd-ready #dd-popup{visibility:visible}
385
393
  .deepdots-load-error{display:none;width:100%;text-align:center;padding:24px 0;font-size:15px;color:var(--dd-text-primary,${textPrimary})}
386
394
  .deepdots-success{display:none;width:100%;text-align:center;padding:24px 0;color:var(--dd-text-primary,${textPrimary})}
387
395
  .deepdots-success img{max-width:100%;height:auto;margin:0 auto 16px auto;display:block}
388
- .deepdots-success p{margin:0;font-size:16px;font-weight:600;line-height:1.4}
396
+ .deepdots-success p{margin:0;font-size:16px;font-weight:600;line-height:1.4;color:var(--dd-success-text,var(--mf-text-secondary))}
389
397
  .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}
390
398
  .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}
391
399
  /* Secundario como bot\xF3n de texto: sin borde ni fondo, para que el primario sea la \xFAnica CTA. */
@@ -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};
@@ -641,6 +642,8 @@ function ddApplyChromeContrast(bg){
641
642
  el.style.setProperty('--dd-text-primary', pal.textPrimary);
642
643
  el.style.setProperty('--dd-text-muted', pal.textMuted);
643
644
  el.style.setProperty('--dd-progress-track', pal.progressTrack);
645
+ // DD-248: el gracias va fuera del contenedor del survey, donde el gris del survey es el claro.
646
+ if(dark){ el.style.setProperty('--dd-success-text', pal.textPrimary); } else { el.style.removeProperty('--dd-success-text'); }
644
647
  var meta=document.querySelector('meta[name="color-scheme"]');
645
648
  if(meta){ meta.setAttribute('content', pal.colorScheme); }
646
649
  }
@@ -768,6 +771,7 @@ ${REVEAL_JS}
768
771
  if(progressPref===null){ progressEnabled=s.showProgressBar===true; }
769
772
  if(s.showProgressUnit!==undefined){ progressShowUnit=s.showProgressUnit!==false; }
770
773
  if(s.progressUnit){ progressUnit=s.progressUnit; }
774
+ if(s.progressMode){ progressMode=s.progressMode; }
771
775
  // Fondo, textos, botones y barra: Style + theme + modo de la app (DD-247, DD-241).
772
776
  ddApplyAppearanceColors(s);
773
777
  if(s.contentAlign){ main.style.justifyContent = s.contentAlign==='center' ? 'center' : 'flex-start'; }
@@ -933,6 +937,8 @@ var ReactNativePopupRenderer = class {
933
937
  font: style?.font,
934
938
  theme: style?.theme,
935
939
  position: style?.position,
940
+ size: style?.size,
941
+ blockPage: style?.blockPage,
936
942
  actions,
937
943
  // renderChrome:false (init) → HTML sin tarjeta/overlay: el host lo envuelve en su Modal.
938
944
  chrome: renderChrome,
@@ -1034,7 +1040,7 @@ function logRnSurveySdkChoice(choice, debug) {
1034
1040
  }
1035
1041
 
1036
1042
  // src/ui/preload.ts
1037
- var defaultLoader = () => import("./renderPopup-I3LIC3W3.mjs");
1043
+ var defaultLoader = () => import("./renderPopup-I565DNZX.mjs");
1038
1044
  var pending = null;
1039
1045
  function preloadRenderPopup(loader = defaultLoader) {
1040
1046
  if (pending) return pending;
@@ -1107,7 +1113,7 @@ var BrowserPopupRenderer = class {
1107
1113
  if (!this.container) return;
1108
1114
  this.visible = true;
1109
1115
  const container = this.container;
1110
- void import("./renderPopup-I3LIC3W3.mjs").then(
1116
+ void import("./renderPopup-I565DNZX.mjs").then(
1111
1117
  ({ renderPopup }) => {
1112
1118
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
1113
1119
  },
@@ -1981,6 +1987,35 @@ var ContactManager = class {
1981
1987
  var STACK_MAX = 8e3;
1982
1988
  var QUEUE_KEY = "deepdots.crash.queue";
1983
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
+ }
1984
2019
  function crashRecordToParams(r) {
1985
2020
  const params = {
1986
2021
  crashed_at: r.crashedAt,
@@ -2038,7 +2073,8 @@ var CrashReporter = class {
2038
2073
  /** API pública del host: reporta un error (app viva) → emite el evento ya. */
2039
2074
  reportError(error, options = {}) {
2040
2075
  if (!this.isEnabled()) return;
2041
- const severity = options.severity ?? "error";
2076
+ if (isBenignError(error)) return;
2077
+ const severity = isNonFatalNoise(error) ? "warning" : options.severity ?? "error";
2042
2078
  const handled = options.handled ?? true;
2043
2079
  const fatal = severity === "fatal";
2044
2080
  const record = this.buildRecord(error, severity, handled, fatal, options.context);
@@ -2046,6 +2082,11 @@ var CrashReporter = class {
2046
2082
  }
2047
2083
  /** Captura un error no manejado (fatal) → persiste a disco para replay en el siguiente arranque. */
2048
2084
  captureUnhandled(error) {
2085
+ if (isBenignError(error)) return;
2086
+ if (isNonFatalNoise(error)) {
2087
+ this.persist(this.buildRecord(error, "warning", false, false));
2088
+ return;
2089
+ }
2049
2090
  this.persist(this.buildRecord(error, "fatal", false, true));
2050
2091
  }
2051
2092
  /** Persiste un crash no capturado a disco para reenviarlo en el siguiente arranque. */
@@ -2081,7 +2122,7 @@ var CrashReporter = class {
2081
2122
  } catch {
2082
2123
  }
2083
2124
  }
2084
- return queue;
2125
+ return queue.map(reclassify).filter((r) => r !== null);
2085
2126
  }
2086
2127
  /** Instala los handlers globales de errores no capturados (no-op sin `window`). Idempotente. */
2087
2128
  install() {
@@ -2377,6 +2418,7 @@ var ANALYTICS_BACKGROUND_RESUME_WINDOW_MS = 5 * 6e4;
2377
2418
  var RESERVED_EVENT_PREFIX = "deepdots_";
2378
2419
  var CUSTOM_EVENT_PREFIX = "deepdots_event_";
2379
2420
  var MAX_PENDING_TRIGGERS = 20;
2421
+ var CONTACT_SYNC_TIMEOUT_MS = 1500;
2380
2422
  function triggerDelayMs(delaySeconds) {
2381
2423
  const n = typeof delaySeconds === "number" ? delaySeconds : Number(delaySeconds);
2382
2424
  return Number.isFinite(n) && n > 0 ? Math.round(n * 1e3) : 0;
@@ -2449,6 +2491,8 @@ var DeepdotsPopups = class {
2449
2491
  this.engagement = null;
2450
2492
  /** Atributos internos del usuario identificado → POST /sdk/popups/contact. Null si no hay userId. */
2451
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;
2452
2496
  /** Storage resuelto en init() (inyectado por el host o localStorage). Reusado al cambiar de usuario. */
2453
2497
  this.storage = null;
2454
2498
  /** Marca si ya se inició la navegación manual (setScreen) — para RN sin History API. */
@@ -2536,19 +2580,24 @@ var DeepdotsPopups = class {
2536
2580
  post: (body) => this.postContact(body)
2537
2581
  });
2538
2582
  if (config.contactAttributes) {
2539
- void this.setContactAttributes(config.contactAttributes);
2583
+ this.contactSync = this.setContactAttributes(config.contactAttributes);
2540
2584
  }
2541
2585
  }
2542
2586
  this.log("tracking \xB7 user_id:", this.tracking.getUserId(), "\xB7 new_user:", this.tracking.isNewUser(), "\xB7 enabled:", this.tracking.isTrackingEnabled());
2543
- 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;
2544
2593
  const resumable = this.readResumableSession();
2545
2594
  if (resumable) {
2546
2595
  this.analyticsFeedbackSessionId = resumable.sessionId;
2547
2596
  this.suspended = { at: resumable.at, userId: resumable.userId, windowMs: ANALYTICS_RESUME_WINDOW_MS };
2548
2597
  }
2549
- const analyticsSink = config.analytics ? createFeedbackSink({
2598
+ const analyticsSink = analyticsKeys ? createFeedbackSink({
2550
2599
  baseUrl: this.baseUrl,
2551
- keys: config.analytics,
2600
+ keys: analyticsKeys,
2552
2601
  log: (...a) => this.log(...a),
2553
2602
  initialSessionId: resumable?.sessionId,
2554
2603
  // En móvil (RN) la app puede morir con el lote de cierre sin entregar: se
@@ -2596,7 +2645,7 @@ var DeepdotsPopups = class {
2596
2645
  });
2597
2646
  this.installCrashHandlers();
2598
2647
  this.geoEnabled = config.geolocation ?? true;
2599
- this.geoWanted = this.geoEnabled && !!config.analytics;
2648
+ this.geoWanted = this.geoEnabled && !!analyticsKeys;
2600
2649
  this.resolveGeo();
2601
2650
  this.navObserver = new NavigationObserver();
2602
2651
  this.navObserver.onVisit(
@@ -3454,38 +3503,38 @@ var DeepdotsPopups = class {
3454
3503
  this.debug("No language available for lang comparison", { popupId: def.id, langs });
3455
3504
  return true;
3456
3505
  }
3457
- const matches = langs.some(
3506
+ const matches2 = langs.some(
3458
3507
  (lang) => typeof lang === "string" && currentLang.startsWith(lang.toLowerCase())
3459
3508
  );
3460
- if (!matches) {
3509
+ if (!matches2) {
3461
3510
  this.debug("Lang mismatch for popup", { popupId: def.id, langs, currentLang });
3462
3511
  }
3463
- return matches;
3512
+ return matches2;
3464
3513
  }
3465
3514
  /** `segments.path`: rutas donde el popup PUEDE mostrarse. Sin lista, en todas. */
3466
3515
  matchesSegmentsPath(def, pathUrl) {
3467
3516
  const paths = def.segments?.path;
3468
3517
  if (!Array.isArray(paths) || paths.length === 0) return true;
3469
- const location = this.resolveCurrentLocation(pathUrl);
3470
- if (!location) {
3518
+ const location2 = this.resolveCurrentLocation(pathUrl);
3519
+ if (!location2) {
3471
3520
  this.debug("No window.location available for path comparison", { popupId: def.id, paths });
3472
3521
  return true;
3473
3522
  }
3474
- const matches = paths.some((rawCandidate) => {
3475
- const match = this.matchesPathCandidate(rawCandidate, location);
3523
+ const matches2 = paths.some((rawCandidate) => {
3524
+ const match = this.matchesPathCandidate(rawCandidate, location2);
3476
3525
  this.debug("Path comparison", {
3477
3526
  popupId: def.id,
3478
3527
  candidate: rawCandidate,
3479
- currentPath: location.path,
3480
- currentHref: location.href,
3528
+ currentPath: location2.path,
3529
+ currentHref: location2.href,
3481
3530
  match
3482
3531
  });
3483
3532
  return match;
3484
3533
  });
3485
- if (!matches) {
3486
- 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 });
3487
3536
  }
3488
- return matches;
3537
+ return matches2;
3489
3538
  }
3490
3539
  /**
3491
3540
  * `segments.excludedPaths`: rutas donde el popup NO debe mostrarse. Gana sobre
@@ -3495,18 +3544,18 @@ var DeepdotsPopups = class {
3495
3544
  isPathExcluded(def, pathUrl) {
3496
3545
  const excluded = def.segments?.excludedPaths;
3497
3546
  if (!Array.isArray(excluded) || excluded.length === 0) return false;
3498
- const location = this.resolveCurrentLocation(pathUrl);
3499
- if (!location) {
3547
+ const location2 = this.resolveCurrentLocation(pathUrl);
3548
+ if (!location2) {
3500
3549
  this.debug("No window.location available for excluded path comparison", { popupId: def.id, excluded });
3501
3550
  return false;
3502
3551
  }
3503
- const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location));
3552
+ const hit = excluded.find((rawCandidate) => this.matchesPathCandidate(rawCandidate, location2));
3504
3553
  if (hit !== void 0) {
3505
3554
  this.debug("Popup excluded by path", {
3506
3555
  popupId: def.id,
3507
3556
  candidate: hit,
3508
- currentPath: location.path,
3509
- currentHref: location.href
3557
+ currentPath: location2.path,
3558
+ currentHref: location2.href
3510
3559
  });
3511
3560
  return true;
3512
3561
  }
@@ -3522,17 +3571,17 @@ var DeepdotsPopups = class {
3522
3571
  * y no puede tumbar la evaluación del trigger entero (mismo fallo que hubo con
3523
3572
  * `segments.lang`).
3524
3573
  */
3525
- matchesPathCandidate(rawCandidate, location) {
3574
+ matchesPathCandidate(rawCandidate, location2) {
3526
3575
  if (typeof rawCandidate !== "string") return false;
3527
3576
  const candidate = this.normalizeUrl(rawCandidate);
3528
3577
  if (!candidate) return false;
3529
3578
  if (candidate.startsWith("http://") || candidate.startsWith("https://")) {
3530
- return location.href === candidate;
3579
+ return location2.href === candidate;
3531
3580
  }
3532
3581
  if (candidate.startsWith("/")) {
3533
- return location.href.includes(candidate);
3582
+ return location2.href.includes(candidate);
3534
3583
  }
3535
- return location.path === candidate;
3584
+ return location2.path === candidate;
3536
3585
  }
3537
3586
  /** href + pathname normalizados de la ruta a evaluar, o null si no hay `window.location`. */
3538
3587
  resolveCurrentLocation(pathUrl) {
@@ -3698,6 +3747,7 @@ var DeepdotsPopups = class {
3698
3747
  this.log("Missing apiKey or baseUrl. Skipping popups fetch.");
3699
3748
  return [];
3700
3749
  }
3750
+ if (this.contactSync) await this.waitForContactSync();
3701
3751
  const filter = userId ? { where: { userId } } : null;
3702
3752
  const query = filter ? `?filter=${encodeURIComponent(JSON.stringify(filter))}` : "";
3703
3753
  const endpoint = `${baseUrl}/sdk/${encodeURIComponent(apiKey)}/popups${query}`;
@@ -3720,6 +3770,23 @@ var DeepdotsPopups = class {
3720
3770
  return null;
3721
3771
  }
3722
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
+ }
3723
3790
  /**
3724
3791
  * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
3725
3792
  * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché