@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.
package/dist/index.d.mts CHANGED
@@ -572,7 +572,11 @@ interface ContactManagerOptions {
572
572
  storage: KeyValueStorage;
573
573
  publicKey: string;
574
574
  userId: string;
575
- /** Envío real (inyectable para tests): hace el `POST /sdk/popups/contact`. */
575
+ /**
576
+ * Envío real (inyectable para tests): hace el `POST /sdk/popups/contact`. Tiene que
577
+ * RECHAZAR si la API no acepta el envío (sin red o respuesta no-2xx): solo así se sabe
578
+ * que no hay que guardar la caché y que la llamada siguiente debe reintentar.
579
+ */
576
580
  post: (body: ContactBody) => Promise<void>;
577
581
  }
578
582
  /**
@@ -587,8 +591,9 @@ declare class ContactManager {
587
591
  private readonly post;
588
592
  constructor(options: ContactManagerOptions);
589
593
  /**
590
- * Envía los atributos si cambiaron respecto a lo último enviado.
591
- * @returns `true` si se envió, `false` si no hubo cambios.
594
+ * Envía los atributos si cambiaron respecto a lo último enviado. La caché solo se guarda
595
+ * cuando la API acepta el envío; si falla, la llamada siguiente reintenta. Nunca rechaza.
596
+ * @returns `true` si se envió, `false` si no hubo cambios o el envío falló.
592
597
  */
593
598
  setAttributes(attributes: ContactAttributes): Promise<boolean>;
594
599
  }
@@ -1071,7 +1076,11 @@ declare class DeepdotsPopups {
1071
1076
  private setDeferredExitQueue;
1072
1077
  /** Fetch al servidor para obtener popups. `null` si la carga falló (red, no-2xx, payload inválido). */
1073
1078
  private fetchPopupsFromServer;
1074
- /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
1079
+ /**
1080
+ * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
1081
+ * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché
1082
+ * y la llamada siguiente reintente.
1083
+ */
1075
1084
  private postContact;
1076
1085
  /** Notifica eventos de popup a la API */
1077
1086
  private postPopupEvent;
package/dist/index.d.ts CHANGED
@@ -572,7 +572,11 @@ interface ContactManagerOptions {
572
572
  storage: KeyValueStorage;
573
573
  publicKey: string;
574
574
  userId: string;
575
- /** Envío real (inyectable para tests): hace el `POST /sdk/popups/contact`. */
575
+ /**
576
+ * Envío real (inyectable para tests): hace el `POST /sdk/popups/contact`. Tiene que
577
+ * RECHAZAR si la API no acepta el envío (sin red o respuesta no-2xx): solo así se sabe
578
+ * que no hay que guardar la caché y que la llamada siguiente debe reintentar.
579
+ */
576
580
  post: (body: ContactBody) => Promise<void>;
577
581
  }
578
582
  /**
@@ -587,8 +591,9 @@ declare class ContactManager {
587
591
  private readonly post;
588
592
  constructor(options: ContactManagerOptions);
589
593
  /**
590
- * Envía los atributos si cambiaron respecto a lo último enviado.
591
- * @returns `true` si se envió, `false` si no hubo cambios.
594
+ * Envía los atributos si cambiaron respecto a lo último enviado. La caché solo se guarda
595
+ * cuando la API acepta el envío; si falla, la llamada siguiente reintenta. Nunca rechaza.
596
+ * @returns `true` si se envió, `false` si no hubo cambios o el envío falló.
592
597
  */
593
598
  setAttributes(attributes: ContactAttributes): Promise<boolean>;
594
599
  }
@@ -1071,7 +1076,11 @@ declare class DeepdotsPopups {
1071
1076
  private setDeferredExitQueue;
1072
1077
  /** Fetch al servidor para obtener popups. `null` si la carga falló (red, no-2xx, payload inválido). */
1073
1078
  private fetchPopupsFromServer;
1074
- /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
1079
+ /**
1080
+ * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
1081
+ * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché
1082
+ * y la llamada siguiente reintente.
1083
+ */
1075
1084
  private postContact;
1076
1085
  /** Notifica eventos de popup a la API */
1077
1086
  private postPopupEvent;
package/dist/index.js CHANGED
@@ -8154,12 +8154,12 @@ var EngagementTracker = class {
8154
8154
 
8155
8155
  // src/contact/contact-manager.ts
8156
8156
  init_tracking_manager();
8157
- function stableSerialize(attrs) {
8157
+ function stableSerialize(userId, attrs) {
8158
8158
  const sorted = {};
8159
8159
  for (const key of Object.keys(attrs).sort()) {
8160
8160
  sorted[key] = attrs[key];
8161
8161
  }
8162
- return JSON.stringify(sorted);
8162
+ return JSON.stringify({ userId, attributes: sorted });
8163
8163
  }
8164
8164
  var ContactManager = class {
8165
8165
  constructor(options) {
@@ -8169,18 +8169,23 @@ var ContactManager = class {
8169
8169
  this.post = options.post;
8170
8170
  }
8171
8171
  /**
8172
- * Envía los atributos si cambiaron respecto a lo último enviado.
8173
- * @returns `true` si se envió, `false` si no hubo cambios.
8172
+ * Envía los atributos si cambiaron respecto a lo último enviado. La caché solo se guarda
8173
+ * cuando la API acepta el envío; si falla, la llamada siguiente reintenta. Nunca rechaza.
8174
+ * @returns `true` si se envió, `false` si no hubo cambios o el envío falló.
8174
8175
  */
8175
8176
  async setAttributes(attributes) {
8176
- const serialized = stableSerialize(attributes);
8177
+ const serialized = stableSerialize(this.userId, attributes);
8177
8178
  const last = this.storage.getItem(STORAGE_KEYS.contactAttributes);
8178
8179
  if (last === serialized) return false;
8179
- await this.post({
8180
- publicKey: this.publicKey,
8181
- userId: this.userId,
8182
- userAttributes: attributes
8183
- });
8180
+ try {
8181
+ await this.post({
8182
+ publicKey: this.publicKey,
8183
+ userId: this.userId,
8184
+ userAttributes: attributes
8185
+ });
8186
+ } catch {
8187
+ return false;
8188
+ }
8184
8189
  this.storage.setItem(STORAGE_KEYS.contactAttributes, serialized);
8185
8190
  return true;
8186
8191
  }
@@ -9577,25 +9582,31 @@ var DeepdotsPopups = class {
9577
9582
  return null;
9578
9583
  }
9579
9584
  }
9580
- /** Envía los atributos de contact a la API (`POST /sdk/popups/contact`). */
9585
+ /**
9586
+ * Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
9587
+ * pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché
9588
+ * y la llamada siguiente reintente.
9589
+ */
9581
9590
  async postContact(body) {
9582
9591
  const baseUrl = this.baseUrl;
9583
- if (!baseUrl) return;
9592
+ if (!baseUrl) throw new Error("no base URL");
9584
9593
  const endpoint = `${baseUrl}/sdk/popups/contact`;
9594
+ let response;
9585
9595
  try {
9586
- const response = await fetch(endpoint, {
9596
+ response = await fetch(endpoint, {
9587
9597
  method: "POST",
9588
9598
  headers: { "Content-Type": "application/json" },
9589
9599
  body: JSON.stringify(body)
9590
9600
  });
9591
- if (!response.ok) {
9592
- this.log("Failed to post contact", response.status, response.statusText);
9593
- return;
9594
- }
9595
- this.log("contact \xB7 sent attributes for user:", body.userId);
9596
9601
  } catch (error) {
9597
9602
  this.log("Error posting contact", error);
9603
+ throw error;
9604
+ }
9605
+ if (!response.ok) {
9606
+ this.log("Failed to post contact", response.status, response.statusText);
9607
+ throw new Error(`HTTP ${response.status}`);
9598
9608
  }
9609
+ this.log("contact \xB7 sent attributes for user:", body.userId);
9599
9610
  }
9600
9611
  /** Notifica eventos de popup a la API */
9601
9612
  async postPopupEvent(status, popupId, userId) {