@cshah18/sdk 3.0.2 → 3.0.3
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/cobuy-sdk.umd.js
CHANGED
|
@@ -3891,6 +3891,18 @@ var CoBuySDK = (function (exports) {
|
|
|
3891
3891
|
const rewardText = this.formatRewardText(reward);
|
|
3892
3892
|
return rewardText ? `Save up to ${rewardText} with CoBuy` : "CoBuy reward available";
|
|
3893
3893
|
}
|
|
3894
|
+
/**
|
|
3895
|
+
* Public hook to request a realtime refresh from external callers
|
|
3896
|
+
*/
|
|
3897
|
+
async requestRefresh() {
|
|
3898
|
+
await this.refreshGroupDataFromRealtime();
|
|
3899
|
+
}
|
|
3900
|
+
/**
|
|
3901
|
+
* Expose current product id for optional filtering by host
|
|
3902
|
+
*/
|
|
3903
|
+
getProductId() {
|
|
3904
|
+
return this.currentProductId;
|
|
3905
|
+
}
|
|
3894
3906
|
}
|
|
3895
3907
|
|
|
3896
3908
|
/**
|
|
@@ -8854,6 +8866,7 @@ var CoBuySDK = (function (exports) {
|
|
|
8854
8866
|
this.lobbyModal = null;
|
|
8855
8867
|
this.modals = new Map();
|
|
8856
8868
|
this.socketManager = null;
|
|
8869
|
+
this.widgets = new Set();
|
|
8857
8870
|
this.configManager = new ConfigManager();
|
|
8858
8871
|
this.logger = new Logger(false);
|
|
8859
8872
|
}
|
|
@@ -9098,6 +9111,8 @@ var CoBuySDK = (function (exports) {
|
|
|
9098
9111
|
const config = this.configManager.getConfig();
|
|
9099
9112
|
const widget = new WidgetRoot(config, this.apiClient, this.analyticsClient);
|
|
9100
9113
|
widget.render(options);
|
|
9114
|
+
// Track widget instance so we can refresh it on important lifecycle events
|
|
9115
|
+
this.widgets.add(widget);
|
|
9101
9116
|
}
|
|
9102
9117
|
catch (error) {
|
|
9103
9118
|
this.logger.error("Failed to render widget", error);
|
|
@@ -9328,6 +9343,40 @@ var CoBuySDK = (function (exports) {
|
|
|
9328
9343
|
const response = await this.apiClient.confirmCheckout(groupId, checkoutRef);
|
|
9329
9344
|
if (response.success) {
|
|
9330
9345
|
this.logger.info(`Checkout confirmed successfully for group: ${groupId}`);
|
|
9346
|
+
// Directly refresh widgets. If we can infer productId, refresh only matching widgets.
|
|
9347
|
+
let productId = null;
|
|
9348
|
+
try {
|
|
9349
|
+
if (typeof window !== "undefined") {
|
|
9350
|
+
const basePrefix = `${this.CHECKOUT_REF_PREFIX}_${this.sessionId}_`;
|
|
9351
|
+
const ls = window.localStorage;
|
|
9352
|
+
for (let i = 0; i < ls.length; i++) {
|
|
9353
|
+
const key = ls.key(i);
|
|
9354
|
+
if (!key)
|
|
9355
|
+
continue;
|
|
9356
|
+
if (key.startsWith(basePrefix) && key.endsWith(`_${groupId}`)) {
|
|
9357
|
+
const remainder = key.substring(basePrefix.length); // <productId>_<groupId>
|
|
9358
|
+
const idx = remainder.lastIndexOf("_");
|
|
9359
|
+
if (idx > 0) {
|
|
9360
|
+
productId = remainder.substring(0, idx);
|
|
9361
|
+
}
|
|
9362
|
+
break;
|
|
9363
|
+
}
|
|
9364
|
+
}
|
|
9365
|
+
}
|
|
9366
|
+
}
|
|
9367
|
+
catch (e) {
|
|
9368
|
+
this.logger.debug("[SDK] Could not resolve productId for direct widget refresh", e);
|
|
9369
|
+
}
|
|
9370
|
+
const refreshPromises = [];
|
|
9371
|
+
this.widgets.forEach((w) => {
|
|
9372
|
+
const pid = typeof w.getProductId === "function" ? w.getProductId() : null;
|
|
9373
|
+
if (!productId || pid === productId) {
|
|
9374
|
+
if (typeof w.requestRefresh === "function") {
|
|
9375
|
+
refreshPromises.push(w.requestRefresh());
|
|
9376
|
+
}
|
|
9377
|
+
}
|
|
9378
|
+
});
|
|
9379
|
+
await Promise.all(refreshPromises.map((p) => p.then(() => undefined).catch(() => undefined)));
|
|
9331
9380
|
}
|
|
9332
9381
|
else {
|
|
9333
9382
|
this.logger.error("Failed to confirm checkout", response.error);
|