@magicfeedback/popup-sdk 1.8.5 → 1.9.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.
@@ -18,7 +18,7 @@ import {
18
18
  sdkWarn,
19
19
  setLogger,
20
20
  style_default
21
- } from "./chunk-EBJZDVC6.mjs";
21
+ } from "./chunk-AKVMUQXO.mjs";
22
22
 
23
23
  // src/react-native/index.tsx
24
24
  import { createContext, useContext, useEffect, useRef, useState } from "react";
@@ -870,7 +870,7 @@ function createReactNativeRenderer() {
870
870
  }
871
871
 
872
872
  // src/ui/preload.ts
873
- var defaultLoader = () => import("./renderPopup-E2OLIXIQ.mjs");
873
+ var defaultLoader = () => import("./renderPopup-LEM2MLWT.mjs");
874
874
  var pending = null;
875
875
  function preloadRenderPopup(loader = defaultLoader) {
876
876
  if (pending) return pending;
@@ -943,7 +943,7 @@ var BrowserPopupRenderer = class {
943
943
  if (!this.container) return;
944
944
  this.visible = true;
945
945
  const container = this.container;
946
- void import("./renderPopup-E2OLIXIQ.mjs").then(({ renderPopup }) => {
946
+ void import("./renderPopup-LEM2MLWT.mjs").then(({ renderPopup }) => {
947
947
  renderPopup(container, surveyId, productId, actions, emit, onClose, env, userId, style, sessionId, miniService, analyticsFeedbackSessionId, options);
948
948
  });
949
949
  }
@@ -1220,8 +1220,10 @@ async function safeBodyText(res) {
1220
1220
  function createFeedbackSink(options) {
1221
1221
  let feedbackSessionId;
1222
1222
  let firstPostInFlight = null;
1223
+ let generation = 0;
1223
1224
  const url = `${options.baseUrl}/sdk/feedback`;
1224
1225
  const post = async (body, final, sessionEnd = false) => {
1226
+ const postGeneration = generation;
1225
1227
  const json = JSON.stringify(body);
1226
1228
  const small = json.length <= KEEPALIVE_MAX_BYTES;
1227
1229
  if (final) options.log?.("[DeepdotsAnalytics] final flush via fetch keepalive");
@@ -1251,9 +1253,25 @@ function createFeedbackSink(options) {
1251
1253
  );
1252
1254
  return;
1253
1255
  }
1254
- if (sessionEnd) return;
1256
+ if (sessionEnd) {
1257
+ let closedId = body.sessionId;
1258
+ try {
1259
+ const data = await res.json();
1260
+ closedId = data?.sessionId ?? closedId;
1261
+ } catch {
1262
+ }
1263
+ try {
1264
+ if (closedId) options.onSessionClosed?.(closedId);
1265
+ } catch {
1266
+ }
1267
+ return;
1268
+ }
1255
1269
  try {
1256
1270
  const data = await res.json();
1271
+ if (postGeneration !== generation) {
1272
+ options.log?.("[DeepdotsAnalytics] sessionId of a closed session ignored:", data?.sessionId);
1273
+ return;
1274
+ }
1257
1275
  if (data?.sessionId && data.sessionId !== feedbackSessionId) {
1258
1276
  feedbackSessionId = data.sessionId;
1259
1277
  options.log?.("[DeepdotsAnalytics] feedbackSessionId cached:", feedbackSessionId);
@@ -1266,6 +1284,7 @@ function createFeedbackSink(options) {
1266
1284
  if (meta?.resetSession) {
1267
1285
  feedbackSessionId = void 0;
1268
1286
  firstPostInFlight = null;
1287
+ generation++;
1269
1288
  options.onSessionReset?.();
1270
1289
  return;
1271
1290
  }
@@ -1280,6 +1299,7 @@ function createFeedbackSink(options) {
1280
1299
  if (sessionEnd) {
1281
1300
  feedbackSessionId = void 0;
1282
1301
  firstPostInFlight = null;
1302
+ generation++;
1283
1303
  options.onSessionReset?.();
1284
1304
  } else if (!feedbackSessionId) {
1285
1305
  firstPostInFlight = sent.then(
@@ -1926,6 +1946,8 @@ var DeepdotsPopups = class {
1926
1946
  this.analytics = null;
1927
1947
  /** feedbackSessionId cacheado del canal de analytics (devuelto por POST /sdk/feedback). */
1928
1948
  this.analyticsFeedbackSessionId = void 0;
1949
+ /** `init({ onFeedbackSession })`: avisa al host al abrir y cerrar cada registro. */
1950
+ this.onFeedbackSession = void 0;
1929
1951
  /** Timer del flush periódico de analytics (cada ANALYTICS_FLUSH_INTERVAL_MS). */
1930
1952
  this.analyticsFlushTimer = void 0;
1931
1953
  /** Crash & error reporting (#14–17). Null hasta init(). */
@@ -1983,6 +2005,7 @@ var DeepdotsPopups = class {
1983
2005
  this.renderChrome = config.renderChrome ?? true;
1984
2006
  this.showProgressBar = config.showProgressBar;
1985
2007
  this.surveyCss = config.surveyCss;
2008
+ this.onFeedbackSession = config.onFeedbackSession;
1986
2009
  this.config = {
1987
2010
  apiKey: config.apiKey || void 0,
1988
2011
  debug: config.debug || false,
@@ -2016,7 +2039,9 @@ var DeepdotsPopups = class {
2016
2039
  log: (...a) => this.log(...a),
2017
2040
  onSessionId: (id) => {
2018
2041
  this.analyticsFeedbackSessionId = id;
2042
+ this.notifyFeedbackSession(id, "open");
2019
2043
  },
2044
+ onSessionClosed: (id) => this.notifyFeedbackSession(id, "closed"),
2020
2045
  onSessionReset: () => {
2021
2046
  this.analyticsFeedbackSessionId = void 0;
2022
2047
  }
@@ -2091,6 +2116,23 @@ var DeepdotsPopups = class {
2091
2116
  getSessionId() {
2092
2117
  return this.tracking?.getSessionId() ?? null;
2093
2118
  }
2119
+ /**
2120
+ * Id del registro de analytics abierto: el `sessionId` que devolvió `POST /sdk/feedback`,
2121
+ * que la API guarda como `sdkSessionId` en el Feedback en que se convierte la sesión. No es
2122
+ * `getSessionId()`. Null hasta que el backend acepta el primer lote y de nuevo al cerrar la
2123
+ * sesión: para saber también qué registro se cerró, usa `init({ onFeedbackSession })`.
2124
+ */
2125
+ getFeedbackSessionId() {
2126
+ return this.analyticsFeedbackSessionId ?? null;
2127
+ }
2128
+ /** Avisa al host del registro abierto o cerrado; un fallo del host no corta el envío. */
2129
+ notifyFeedbackSession(sessionId, status) {
2130
+ try {
2131
+ this.onFeedbackSession?.({ sessionId, status });
2132
+ } catch (error) {
2133
+ this.log("analytics \xB7 onFeedbackSession threw:", error);
2134
+ }
2135
+ }
2094
2136
  /** Activa/desactiva el tracking (identidad + sesión + analytics). Kill-switch del contrato §7bis. */
2095
2137
  setTrackingEnabled(enabled) {
2096
2138
  if (!enabled) this.closeSession("tracking_disabled");
@@ -2931,7 +2973,7 @@ var DeepdotsPopups = class {
2931
2973
  }
2932
2974
  if (!this.popupContainer) return;
2933
2975
  const container = this.popupContainer;
2934
- void import("./renderPopup-E2OLIXIQ.mjs").then(({ renderPopup }) => {
2976
+ void import("./renderPopup-LEM2MLWT.mjs").then(({ renderPopup }) => {
2935
2977
  renderPopup(
2936
2978
  container,
2937
2979
  surveyId,