@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 +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +29 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -18
- package/dist/index.mjs.map +1 -1
- package/dist/react-native.d.mts +5 -1
- package/dist/react-native.d.ts +5 -1
- package/dist/react-native.js +29 -18
- package/dist/react-native.js.map +1 -1
- package/dist/react-native.mjs +29 -18
- package/dist/react-native.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react-native.mjs
CHANGED
|
@@ -1726,12 +1726,12 @@ var EngagementTracker = class {
|
|
|
1726
1726
|
};
|
|
1727
1727
|
|
|
1728
1728
|
// src/contact/contact-manager.ts
|
|
1729
|
-
function stableSerialize(attrs) {
|
|
1729
|
+
function stableSerialize(userId, attrs) {
|
|
1730
1730
|
const sorted = {};
|
|
1731
1731
|
for (const key of Object.keys(attrs).sort()) {
|
|
1732
1732
|
sorted[key] = attrs[key];
|
|
1733
1733
|
}
|
|
1734
|
-
return JSON.stringify(sorted);
|
|
1734
|
+
return JSON.stringify({ userId, attributes: sorted });
|
|
1735
1735
|
}
|
|
1736
1736
|
var ContactManager = class {
|
|
1737
1737
|
constructor(options) {
|
|
@@ -1741,18 +1741,23 @@ var ContactManager = class {
|
|
|
1741
1741
|
this.post = options.post;
|
|
1742
1742
|
}
|
|
1743
1743
|
/**
|
|
1744
|
-
* Envía los atributos si cambiaron respecto a lo último enviado.
|
|
1745
|
-
*
|
|
1744
|
+
* Envía los atributos si cambiaron respecto a lo último enviado. La caché solo se guarda
|
|
1745
|
+
* cuando la API acepta el envío; si falla, la llamada siguiente reintenta. Nunca rechaza.
|
|
1746
|
+
* @returns `true` si se envió, `false` si no hubo cambios o el envío falló.
|
|
1746
1747
|
*/
|
|
1747
1748
|
async setAttributes(attributes) {
|
|
1748
|
-
const serialized = stableSerialize(attributes);
|
|
1749
|
+
const serialized = stableSerialize(this.userId, attributes);
|
|
1749
1750
|
const last = this.storage.getItem(STORAGE_KEYS.contactAttributes);
|
|
1750
1751
|
if (last === serialized) return false;
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1752
|
+
try {
|
|
1753
|
+
await this.post({
|
|
1754
|
+
publicKey: this.publicKey,
|
|
1755
|
+
userId: this.userId,
|
|
1756
|
+
userAttributes: attributes
|
|
1757
|
+
});
|
|
1758
|
+
} catch {
|
|
1759
|
+
return false;
|
|
1760
|
+
}
|
|
1756
1761
|
this.storage.setItem(STORAGE_KEYS.contactAttributes, serialized);
|
|
1757
1762
|
return true;
|
|
1758
1763
|
}
|
|
@@ -3146,25 +3151,31 @@ var DeepdotsPopups = class {
|
|
|
3146
3151
|
return null;
|
|
3147
3152
|
}
|
|
3148
3153
|
}
|
|
3149
|
-
/**
|
|
3154
|
+
/**
|
|
3155
|
+
* Envía los atributos de contact a la API (`POST /sdk/popups/contact`). Rechaza si no se
|
|
3156
|
+
* pudo enviar (sin red o respuesta no-2xx), para que `ContactManager` no guarde la caché
|
|
3157
|
+
* y la llamada siguiente reintente.
|
|
3158
|
+
*/
|
|
3150
3159
|
async postContact(body) {
|
|
3151
3160
|
const baseUrl = this.baseUrl;
|
|
3152
|
-
if (!baseUrl)
|
|
3161
|
+
if (!baseUrl) throw new Error("no base URL");
|
|
3153
3162
|
const endpoint = `${baseUrl}/sdk/popups/contact`;
|
|
3163
|
+
let response;
|
|
3154
3164
|
try {
|
|
3155
|
-
|
|
3165
|
+
response = await fetch(endpoint, {
|
|
3156
3166
|
method: "POST",
|
|
3157
3167
|
headers: { "Content-Type": "application/json" },
|
|
3158
3168
|
body: JSON.stringify(body)
|
|
3159
3169
|
});
|
|
3160
|
-
if (!response.ok) {
|
|
3161
|
-
this.log("Failed to post contact", response.status, response.statusText);
|
|
3162
|
-
return;
|
|
3163
|
-
}
|
|
3164
|
-
this.log("contact \xB7 sent attributes for user:", body.userId);
|
|
3165
3170
|
} catch (error) {
|
|
3166
3171
|
this.log("Error posting contact", error);
|
|
3172
|
+
throw error;
|
|
3173
|
+
}
|
|
3174
|
+
if (!response.ok) {
|
|
3175
|
+
this.log("Failed to post contact", response.status, response.statusText);
|
|
3176
|
+
throw new Error(`HTTP ${response.status}`);
|
|
3167
3177
|
}
|
|
3178
|
+
this.log("contact \xB7 sent attributes for user:", body.userId);
|
|
3168
3179
|
}
|
|
3169
3180
|
/** Notifica eventos de popup a la API */
|
|
3170
3181
|
async postPopupEvent(status, popupId, userId) {
|