@cshah18/sdk 3.0.2 → 3.0.4
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.esm.js +56 -1
- package/dist/cobuy-sdk.esm.js.map +1 -1
- package/dist/cobuy-sdk.umd.js +56 -1
- package/dist/cobuy-sdk.umd.js.map +1 -1
- package/dist/types/core/cobuy.d.ts +1 -0
- package/dist/types/core/group-channel-manager.d.ts +74 -0
- package/dist/types/ui/widget/widget-root.d.ts +8 -0
- package/package.json +1 -1
- package/dist/types/core/socket-client.d.ts +0 -126
package/dist/cobuy-sdk.umd.js
CHANGED
|
@@ -2636,6 +2636,7 @@ var CoBuySDK = (function (exports) {
|
|
|
2636
2636
|
}
|
|
2637
2637
|
/** Fetch latest group data and re-render containers */
|
|
2638
2638
|
async refreshGroupDataFromRealtime() {
|
|
2639
|
+
console.log("request group data realtime callledddd");
|
|
2639
2640
|
// Debounce rapid refreshes to prevent loops and reduce API load
|
|
2640
2641
|
const now = Date.now();
|
|
2641
2642
|
if (now - this.lastGroupDataRefreshTime < this.GROUP_REFRESH_DEBOUNCE) {
|
|
@@ -3050,6 +3051,7 @@ var CoBuySDK = (function (exports) {
|
|
|
3050
3051
|
let groupData = null;
|
|
3051
3052
|
if (this.apiClient) {
|
|
3052
3053
|
rewardData = await this.fetchRewardWithRetry(options.productId);
|
|
3054
|
+
console.log("from renderrrr");
|
|
3053
3055
|
groupData = await this.fetchPrimaryGroup(options.productId);
|
|
3054
3056
|
this.currentGroupData = groupData;
|
|
3055
3057
|
this.currentGroupId = (groupData === null || groupData === void 0 ? void 0 : groupData.id) || null;
|
|
@@ -3306,6 +3308,7 @@ var CoBuySDK = (function (exports) {
|
|
|
3306
3308
|
*/
|
|
3307
3309
|
async fetchPrimaryGroup(productId) {
|
|
3308
3310
|
var _a;
|
|
3311
|
+
console.log("fetch primary group called");
|
|
3309
3312
|
if (!this.apiClient) {
|
|
3310
3313
|
return null;
|
|
3311
3314
|
}
|
|
@@ -3891,6 +3894,18 @@ var CoBuySDK = (function (exports) {
|
|
|
3891
3894
|
const rewardText = this.formatRewardText(reward);
|
|
3892
3895
|
return rewardText ? `Save up to ${rewardText} with CoBuy` : "CoBuy reward available";
|
|
3893
3896
|
}
|
|
3897
|
+
/**
|
|
3898
|
+
* Public hook to request a realtime refresh from external callers
|
|
3899
|
+
*/
|
|
3900
|
+
async requestRefresh() {
|
|
3901
|
+
await this.refreshGroupDataFromRealtime();
|
|
3902
|
+
}
|
|
3903
|
+
/**
|
|
3904
|
+
* Expose current product id for optional filtering by host
|
|
3905
|
+
*/
|
|
3906
|
+
getProductId() {
|
|
3907
|
+
return this.currentProductId;
|
|
3908
|
+
}
|
|
3894
3909
|
}
|
|
3895
3910
|
|
|
3896
3911
|
/**
|
|
@@ -8854,6 +8869,7 @@ var CoBuySDK = (function (exports) {
|
|
|
8854
8869
|
this.lobbyModal = null;
|
|
8855
8870
|
this.modals = new Map();
|
|
8856
8871
|
this.socketManager = null;
|
|
8872
|
+
this.widgets = new Set();
|
|
8857
8873
|
this.configManager = new ConfigManager();
|
|
8858
8874
|
this.logger = new Logger(false);
|
|
8859
8875
|
}
|
|
@@ -8938,7 +8954,9 @@ var CoBuySDK = (function (exports) {
|
|
|
8938
8954
|
const ref = window.localStorage.getItem(key);
|
|
8939
8955
|
if (ref) {
|
|
8940
8956
|
this.logger.debug(`[SDK] Retrieved checkout reference via prefix: ${key}`);
|
|
8941
|
-
const parsedGroupId = key.startsWith(`${basePrefix}_`)
|
|
8957
|
+
const parsedGroupId = key.startsWith(`${basePrefix}_`)
|
|
8958
|
+
? key.substring(basePrefix.length + 1)
|
|
8959
|
+
: null;
|
|
8942
8960
|
return { key, checkoutRef: ref, groupId: parsedGroupId };
|
|
8943
8961
|
}
|
|
8944
8962
|
}
|
|
@@ -9098,6 +9116,8 @@ var CoBuySDK = (function (exports) {
|
|
|
9098
9116
|
const config = this.configManager.getConfig();
|
|
9099
9117
|
const widget = new WidgetRoot(config, this.apiClient, this.analyticsClient);
|
|
9100
9118
|
widget.render(options);
|
|
9119
|
+
// Track widget instance so we can refresh it on important lifecycle events
|
|
9120
|
+
this.widgets.add(widget);
|
|
9101
9121
|
}
|
|
9102
9122
|
catch (error) {
|
|
9103
9123
|
this.logger.error("Failed to render widget", error);
|
|
@@ -9328,6 +9348,41 @@ var CoBuySDK = (function (exports) {
|
|
|
9328
9348
|
const response = await this.apiClient.confirmCheckout(groupId, checkoutRef);
|
|
9329
9349
|
if (response.success) {
|
|
9330
9350
|
this.logger.info(`Checkout confirmed successfully for group: ${groupId}`);
|
|
9351
|
+
// Directly refresh widgets. If we can infer productId, refresh only matching widgets.
|
|
9352
|
+
let productId = null;
|
|
9353
|
+
try {
|
|
9354
|
+
if (typeof window !== "undefined") {
|
|
9355
|
+
const basePrefix = `${this.CHECKOUT_REF_PREFIX}_${this.sessionId}_`;
|
|
9356
|
+
const ls = window.localStorage;
|
|
9357
|
+
for (let i = 0; i < ls.length; i++) {
|
|
9358
|
+
const key = ls.key(i);
|
|
9359
|
+
if (!key)
|
|
9360
|
+
continue;
|
|
9361
|
+
if (key.startsWith(basePrefix) && key.endsWith(`_${groupId}`)) {
|
|
9362
|
+
const remainder = key.substring(basePrefix.length); // <productId>_<groupId>
|
|
9363
|
+
const idx = remainder.lastIndexOf("_");
|
|
9364
|
+
if (idx > 0) {
|
|
9365
|
+
productId = remainder.substring(0, idx);
|
|
9366
|
+
}
|
|
9367
|
+
break;
|
|
9368
|
+
}
|
|
9369
|
+
}
|
|
9370
|
+
}
|
|
9371
|
+
}
|
|
9372
|
+
catch (e) {
|
|
9373
|
+
this.logger.debug("[SDK] Could not resolve productId for direct widget refresh", e);
|
|
9374
|
+
}
|
|
9375
|
+
const refreshPromises = [];
|
|
9376
|
+
this.widgets.forEach((w) => {
|
|
9377
|
+
const pid = typeof w.getProductId === "function" ? w.getProductId() : null;
|
|
9378
|
+
if (!productId || pid === productId) {
|
|
9379
|
+
if (typeof w.requestRefresh === "function") {
|
|
9380
|
+
console.log("calling refresshh now");
|
|
9381
|
+
refreshPromises.push(w.requestRefresh());
|
|
9382
|
+
}
|
|
9383
|
+
}
|
|
9384
|
+
});
|
|
9385
|
+
await Promise.all(refreshPromises.map((p) => p.then(() => undefined).catch(() => undefined)));
|
|
9331
9386
|
}
|
|
9332
9387
|
else {
|
|
9333
9388
|
this.logger.error("Failed to confirm checkout", response.error);
|