@magicfeedback/popup-sdk 1.16.0 → 1.16.1

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.
@@ -737,7 +737,11 @@ declare class DeepdotsPopups {
737
737
  private setDeferredExitQueue;
738
738
  /** Fetch al servidor para obtener popups. `null` si la carga falló (red, no-2xx, payload inválido). */
739
739
  private fetchPopupsFromServer;
740
- /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
740
+ /**
741
+ * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
742
+ * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché
743
+ * y la llamada siguiente reintente.
744
+ */
741
745
  private postContact;
742
746
  /** Notifica eventos de popup a la API */
743
747
  private postPopupEvent;
@@ -737,7 +737,11 @@ declare class DeepdotsPopups {
737
737
  private setDeferredExitQueue;
738
738
  /** Fetch al servidor para obtener popups. `null` si la carga falló (red, no-2xx, payload inválido). */
739
739
  private fetchPopupsFromServer;
740
- /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
740
+ /**
741
+ * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
742
+ * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché
743
+ * y la llamada siguiente reintente.
744
+ */
741
745
  private postContact;
742
746
  /** Notifica eventos de popup a la API */
743
747
  private postPopupEvent;
@@ -5299,12 +5299,12 @@ var EngagementTracker = class {
5299
5299
 
5300
5300
  // src/contact/contact-manager.ts
5301
5301
  init_tracking_manager();
5302
- function stableSerialize(attrs) {
5302
+ function stableSerialize(userId, attrs) {
5303
5303
  const sorted = {};
5304
5304
  for (const key of Object.keys(attrs).sort()) {
5305
5305
  sorted[key] = attrs[key];
5306
5306
  }
5307
- return JSON.stringify(sorted);
5307
+ return JSON.stringify({ userId, attributes: sorted });
5308
5308
  }
5309
5309
  var ContactManager = class {
5310
5310
  constructor(options) {
@@ -5314,18 +5314,23 @@ var ContactManager = class {
5314
5314
  this.post = options.post;
5315
5315
  }
5316
5316
  /**
5317
- * Envía los atributos si cambiaron respecto a lo último enviado.
5318
- * @returns `true` si se envió, `false` si no hubo cambios.
5317
+ * Envía los atributos si cambiaron respecto a lo último enviado. La caché solo se guarda
5318
+ * cuando la API acepta el envío; si falla, la llamada siguiente reintenta. Nunca rechaza.
5319
+ * @returns `true` si se envió, `false` si no hubo cambios o el envío falló.
5319
5320
  */
5320
5321
  async setAttributes(attributes) {
5321
- const serialized = stableSerialize(attributes);
5322
+ const serialized = stableSerialize(this.userId, attributes);
5322
5323
  const last = this.storage.getItem(STORAGE_KEYS.contactAttributes);
5323
5324
  if (last === serialized) return false;
5324
- await this.post({
5325
- publicKey: this.publicKey,
5326
- userId: this.userId,
5327
- userAttributes: attributes
5328
- });
5325
+ try {
5326
+ await this.post({
5327
+ publicKey: this.publicKey,
5328
+ userId: this.userId,
5329
+ userAttributes: attributes
5330
+ });
5331
+ } catch {
5332
+ return false;
5333
+ }
5329
5334
  this.storage.setItem(STORAGE_KEYS.contactAttributes, serialized);
5330
5335
  return true;
5331
5336
  }
@@ -6722,25 +6727,31 @@ var DeepdotsPopups = class {
6722
6727
  return null;
6723
6728
  }
6724
6729
  }
6725
- /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
6730
+ /**
6731
+ * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
6732
+ * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché
6733
+ * y la llamada siguiente reintente.
6734
+ */
6726
6735
  async postContact(body) {
6727
6736
  const baseUrl = this.baseUrl;
6728
- if (!baseUrl) return;
6737
+ if (!baseUrl) throw new Error("no base URL");
6729
6738
  const endpoint = `${baseUrl}/sdk/popups/contact`;
6739
+ let response;
6730
6740
  try {
6731
- const response = await fetch(endpoint, {
6741
+ response = await fetch(endpoint, {
6732
6742
  method: "POST",
6733
6743
  headers: { "Content-Type": "application/json" },
6734
6744
  body: JSON.stringify(body)
6735
6745
  });
6736
- if (!response.ok) {
6737
- this.log("Failed to post contact", response.status, response.statusText);
6738
- return;
6739
- }
6740
- this.log("contact \xB7 sent attributes for user:", body.userId);
6741
6746
  } catch (error) {
6742
6747
  this.log("Error posting contact", error);
6748
+ throw error;
6749
+ }
6750
+ if (!response.ok) {
6751
+ this.log("Failed to post contact", response.status, response.statusText);
6752
+ throw new Error(`HTTP ${response.status}`);
6743
6753
  }
6754
+ this.log("contact \xB7 sent attributes for user:", body.userId);
6744
6755
  }
6745
6756
  /** Notifica eventos de popup a la API */
6746
6757
  async postPopupEvent(status, popupId, userId) {