@liquidcommercedev/rmn-sdk 1.5.0-beta.39 → 1.5.0-beta.40
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.cjs +90 -58
- package/dist/index.esm.js +90 -58
- package/dist/types/common/helpers/utils.helper.d.ts +3 -1
- package/dist/types/modules/helper-service/index.d.ts +0 -1
- package/dist/types/modules/helper-service/localstorage.service.d.ts +0 -2
- package/package.json +1 -1
- package/umd/liquidcommerce-rmn-sdk.min.js +1 -1
- package/dist/types/modules/helper-service/intersection.service.d.ts +0 -8
package/dist/index.cjs
CHANGED
@@ -7642,31 +7642,36 @@ class ObjectHelper {
|
|
7642
7642
|
}
|
7643
7643
|
}
|
7644
7644
|
|
7645
|
-
|
7646
|
-
async function fallbackEventFire(url) {
|
7645
|
+
function fetchFallbackEventFire(url) {
|
7647
7646
|
try {
|
7648
|
-
|
7649
|
-
|
7650
|
-
|
7651
|
-
|
7652
|
-
|
7653
|
-
|
7654
|
-
|
7655
|
-
|
7656
|
-
|
7657
|
-
|
7658
|
-
|
7659
|
-
|
7660
|
-
|
7661
|
-
|
7662
|
-
|
7663
|
-
|
7664
|
-
|
7647
|
+
fetch === null || fetch === void 0 ? void 0 : fetch(url, {
|
7648
|
+
method: 'POST',
|
7649
|
+
keepalive: true,
|
7650
|
+
}).catch(() => false);
|
7651
|
+
return true;
|
7652
|
+
}
|
7653
|
+
catch (_a) {
|
7654
|
+
return false;
|
7655
|
+
}
|
7656
|
+
}
|
7657
|
+
function xhrFallbackEventFire(url) {
|
7658
|
+
try {
|
7659
|
+
const xhr = new XMLHttpRequest();
|
7660
|
+
xhr.onload = () => xhr.status >= 200 && xhr.status < 300;
|
7661
|
+
xhr.onerror = () => false;
|
7662
|
+
xhr.ontimeout = () => false;
|
7663
|
+
xhr.open('POST', url, true);
|
7664
|
+
xhr.send();
|
7665
|
+
return true;
|
7665
7666
|
}
|
7666
7667
|
catch (_a) {
|
7667
7668
|
return false;
|
7668
7669
|
}
|
7669
7670
|
}
|
7671
|
+
function beaconEventFire(url) {
|
7672
|
+
var _a;
|
7673
|
+
return (_a = navigator === null || navigator === void 0 ? void 0 : navigator.sendBeacon) === null || _a === void 0 ? void 0 : _a.call(navigator, url);
|
7674
|
+
}
|
7670
7675
|
/**
|
7671
7676
|
* Helper function to decode base64 string and parse JSON
|
7672
7677
|
*
|
@@ -7723,21 +7728,30 @@ function getRedirectUrlFromPayload(url) {
|
|
7723
7728
|
* @returns {Promise<void>} - A promise that resolves when the event is fired.
|
7724
7729
|
*/
|
7725
7730
|
async function fireEvent({ spotType, event, eventUrl }) {
|
7726
|
-
|
7727
|
-
|
7728
|
-
const didFireEvent = ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.sendBeacon) === null || _a === void 0 ? void 0 : _a.call(navigator, eventUrl)) || (await fallbackEventFire(eventUrl));
|
7729
|
-
if (!didFireEvent) {
|
7730
|
-
return;
|
7731
|
-
}
|
7732
|
-
// Redirect user if the event is a click event
|
7731
|
+
// Redirect user if the event is a click event
|
7732
|
+
const handleRedirection = () => {
|
7733
7733
|
if (event === exports.RMN_SPOT_EVENT.CLICK && spotType !== exports.RMN_SPOT_TYPE.RB_VIDEO_PLAYER) {
|
7734
7734
|
const redirectUrl = getRedirectUrlFromPayload(eventUrl);
|
7735
7735
|
if (redirectUrl) {
|
7736
7736
|
window.location.href = redirectUrl;
|
7737
7737
|
}
|
7738
7738
|
}
|
7739
|
+
};
|
7740
|
+
try {
|
7741
|
+
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
7742
|
+
beaconEventFire(eventUrl);
|
7743
|
+
handleRedirection();
|
7744
|
+
return;
|
7745
|
+
}
|
7746
|
+
if (typeof fetch !== 'undefined') {
|
7747
|
+
fetchFallbackEventFire(eventUrl);
|
7748
|
+
handleRedirection();
|
7749
|
+
return;
|
7750
|
+
}
|
7751
|
+
xhrFallbackEventFire(eventUrl);
|
7752
|
+
handleRedirection();
|
7739
7753
|
}
|
7740
|
-
catch (
|
7754
|
+
catch (_a) {
|
7741
7755
|
// Handle errors silently
|
7742
7756
|
}
|
7743
7757
|
}
|
@@ -17155,6 +17169,9 @@ const SPOT_EVENTS_ARRAY_INDEX = {
|
|
17155
17169
|
};
|
17156
17170
|
class LocalStorageService {
|
17157
17171
|
constructor() {
|
17172
|
+
if (typeof window.localStorage === 'undefined') {
|
17173
|
+
console.warn('LiquidCommerce Rmn Sdk: Local storage is not supported in this environment.');
|
17174
|
+
}
|
17158
17175
|
this.setUserId();
|
17159
17176
|
this.spots = new Map();
|
17160
17177
|
// Sync local storage with the current state
|
@@ -17175,20 +17192,20 @@ class LocalStorageService {
|
|
17175
17192
|
(_e = this.spots) === null || _e === void 0 ? void 0 : _e.set(spotId, data);
|
17176
17193
|
this.updateLocalStorage();
|
17177
17194
|
}
|
17178
|
-
removeSpot(spotId) {
|
17179
|
-
|
17180
|
-
|
17181
|
-
|
17182
|
-
|
17183
|
-
|
17184
|
-
|
17185
|
-
|
17186
|
-
|
17187
|
-
|
17188
|
-
|
17189
|
-
|
17190
|
-
|
17191
|
-
}
|
17195
|
+
// public removeSpot(spotId: string): void {
|
17196
|
+
// const isExistentSpot = this.spots?.has(spotId);
|
17197
|
+
//
|
17198
|
+
// if (!isExistentSpot) return;
|
17199
|
+
//
|
17200
|
+
// const isDeleted = this.spots?.delete(spotId);
|
17201
|
+
//
|
17202
|
+
// if (!isDeleted) return;
|
17203
|
+
//
|
17204
|
+
// this.updateLocalStorage();
|
17205
|
+
// }
|
17206
|
+
// public getSpot(spotId: string): ILocalStorageSpot | undefined {
|
17207
|
+
// return this.spots?.get(spotId);
|
17208
|
+
// }
|
17192
17209
|
getSpots() {
|
17193
17210
|
if (!this.spots)
|
17194
17211
|
return undefined;
|
@@ -17215,12 +17232,14 @@ class LocalStorageService {
|
|
17215
17232
|
* @return {void} This method does not return a value.
|
17216
17233
|
*/
|
17217
17234
|
setUserId() {
|
17235
|
+
var _a;
|
17218
17236
|
const prefix = LocalStorageService.localStorageKeyPrefix;
|
17219
|
-
const existingKeys = Object.keys(window.localStorage).filter((key) => key.startsWith(prefix));
|
17237
|
+
const existingKeys = Object.keys((_a = window.localStorage) !== null && _a !== void 0 ? _a : {}).filter((key) => key.startsWith(prefix));
|
17220
17238
|
const setNewKey = () => {
|
17239
|
+
var _a;
|
17221
17240
|
const uniqueId = UniqueIdGenerator.generate();
|
17222
17241
|
const newLocalStorageKey = `${prefix}_${uniqueId}`;
|
17223
|
-
window.localStorage.setItem(newLocalStorageKey, '');
|
17242
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(newLocalStorageKey, '');
|
17224
17243
|
LocalStorageService.localStorageKey = newLocalStorageKey;
|
17225
17244
|
};
|
17226
17245
|
if (existingKeys.length === 0) {
|
@@ -17230,8 +17249,9 @@ class LocalStorageService {
|
|
17230
17249
|
const validKey = existingKeys.find((key) => UniqueIdGenerator.isValid(key.replace(`${prefix}_`, '')));
|
17231
17250
|
// Delete all other keys except the valid one
|
17232
17251
|
existingKeys.forEach((key) => {
|
17252
|
+
var _a;
|
17233
17253
|
if (key !== validKey) {
|
17234
|
-
window.localStorage.removeItem(key);
|
17254
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(key);
|
17235
17255
|
}
|
17236
17256
|
});
|
17237
17257
|
if (validKey) {
|
@@ -17246,7 +17266,8 @@ class LocalStorageService {
|
|
17246
17266
|
}
|
17247
17267
|
// ======================== Utility functions ======================== //
|
17248
17268
|
syncLocalStorage() {
|
17249
|
-
|
17269
|
+
var _a;
|
17270
|
+
const localStorageData = (_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(LocalStorageService.localStorageKey);
|
17250
17271
|
if (localStorageData) {
|
17251
17272
|
try {
|
17252
17273
|
const decryptedData = this.decryptData(localStorageData);
|
@@ -17262,28 +17283,30 @@ class LocalStorageService {
|
|
17262
17283
|
this.clearLocalStorage();
|
17263
17284
|
}
|
17264
17285
|
}
|
17265
|
-
catch (
|
17286
|
+
catch (_b) {
|
17266
17287
|
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17267
17288
|
this.clearLocalStorage();
|
17268
17289
|
}
|
17269
17290
|
}
|
17270
17291
|
}
|
17271
17292
|
updateLocalStorage() {
|
17293
|
+
var _a;
|
17272
17294
|
if (!this.spots)
|
17273
17295
|
return undefined;
|
17274
17296
|
const spotsObj = this.mapToObject(this.spots);
|
17275
17297
|
const data = Object.values(spotsObj).map((spot) => this.spotObjectToArray(spot));
|
17276
17298
|
try {
|
17277
17299
|
const encryptedData = this.encryptData(JSON.stringify(data));
|
17278
|
-
window.localStorage.setItem(LocalStorageService.localStorageKey, encryptedData);
|
17300
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(LocalStorageService.localStorageKey, encryptedData);
|
17279
17301
|
}
|
17280
|
-
catch (
|
17302
|
+
catch (_b) {
|
17281
17303
|
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17282
17304
|
this.clearLocalStorage();
|
17283
17305
|
}
|
17284
17306
|
}
|
17285
17307
|
clearLocalStorage() {
|
17286
|
-
|
17308
|
+
var _a;
|
17309
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(LocalStorageService.localStorageKey);
|
17287
17310
|
}
|
17288
17311
|
removeExpiredSpots() {
|
17289
17312
|
var _a;
|
@@ -17405,6 +17428,7 @@ class ProximityObserver {
|
|
17405
17428
|
this.observeExistingElements();
|
17406
17429
|
}
|
17407
17430
|
initializeObservers() {
|
17431
|
+
var _a;
|
17408
17432
|
// Initialize intersection observer to detect when elements are near viewport
|
17409
17433
|
this.intersectionObserver = new IntersectionObserver(this.handleIntersection.bind(this), {
|
17410
17434
|
rootMargin: this.intersectionMargin,
|
@@ -17440,21 +17464,23 @@ class ProximityObserver {
|
|
17440
17464
|
});
|
17441
17465
|
// Start observing DOM changes
|
17442
17466
|
if (document.body) {
|
17443
|
-
this.mutationObserver.observe(document.body, {
|
17467
|
+
(_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(document.body, {
|
17444
17468
|
childList: true,
|
17445
17469
|
subtree: true,
|
17446
17470
|
});
|
17447
17471
|
}
|
17448
17472
|
}
|
17449
17473
|
handleRemovedElement(element) {
|
17474
|
+
var _a;
|
17450
17475
|
if (element.id && this.processedIds.has(element.id)) {
|
17451
17476
|
this.processedIds.delete(element.id);
|
17452
|
-
this.intersectionObserver.unobserve(element);
|
17477
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(element);
|
17453
17478
|
}
|
17454
17479
|
}
|
17455
17480
|
checkElement(element) {
|
17481
|
+
var _a;
|
17456
17482
|
if (element.id && this.targetIds.has(element.id) && !this.processedIds.has(element.id)) {
|
17457
|
-
this.intersectionObserver.observe(element);
|
17483
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(element);
|
17458
17484
|
}
|
17459
17485
|
}
|
17460
17486
|
findNearbyTargetIds(element) {
|
@@ -17497,10 +17523,11 @@ class ProximityObserver {
|
|
17497
17523
|
const groupIdsToProcess = allGroupIds.slice(0, this.maxGroupSize);
|
17498
17524
|
// Mark all found IDs as processed
|
17499
17525
|
groupIdsToProcess.forEach((id) => {
|
17526
|
+
var _a;
|
17500
17527
|
this.processedIds.add(id);
|
17501
17528
|
const el = document.getElementById(id);
|
17502
17529
|
if (el)
|
17503
|
-
this.intersectionObserver.unobserve(el);
|
17530
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(el);
|
17504
17531
|
});
|
17505
17532
|
// Trigger callback with the group
|
17506
17533
|
this.callback(groupIdsToProcess);
|
@@ -17612,6 +17639,10 @@ class PubsubService {
|
|
17612
17639
|
|
17613
17640
|
class ResizeObserverService {
|
17614
17641
|
constructor({ element, maxSize, minScale }) {
|
17642
|
+
var _a;
|
17643
|
+
if (typeof ResizeObserver === 'undefined') {
|
17644
|
+
console.warn('RmnSdk: ResizeObserver is not supported in this browser');
|
17645
|
+
}
|
17615
17646
|
this.element = element;
|
17616
17647
|
if (!element.parentElement) {
|
17617
17648
|
throw new Error('RmnSdk: Spot element must have a parent container.');
|
@@ -17619,7 +17650,7 @@ class ResizeObserverService {
|
|
17619
17650
|
this.container = element.parentElement;
|
17620
17651
|
this.setDimensions(maxSize, minScale);
|
17621
17652
|
this.resizeObserver = new ResizeObserver(() => this.updateElementSize());
|
17622
|
-
this.resizeObserver.observe(this.container);
|
17653
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.container);
|
17623
17654
|
// Initial size update
|
17624
17655
|
this.updateElementSize();
|
17625
17656
|
}
|
@@ -17674,7 +17705,8 @@ class ResizeObserverService {
|
|
17674
17705
|
}));
|
17675
17706
|
}
|
17676
17707
|
disconnect() {
|
17677
|
-
|
17708
|
+
var _a;
|
17709
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
17678
17710
|
}
|
17679
17711
|
}
|
17680
17712
|
|
@@ -21357,7 +21389,7 @@ class BrowserRmnClient {
|
|
21357
21389
|
});
|
21358
21390
|
}
|
21359
21391
|
if (skeletonElement) {
|
21360
|
-
placement.replaceChildren(skeletonElement);
|
21392
|
+
placement === null || placement === void 0 ? void 0 : placement.replaceChildren(skeletonElement);
|
21361
21393
|
}
|
21362
21394
|
validPlacements.set(placementId, placement);
|
21363
21395
|
this.spotManagerService.updateSpotLifecycleState(injectData.placementId, {
|
@@ -21466,7 +21498,7 @@ class BrowserRmnClient {
|
|
21466
21498
|
placementId,
|
21467
21499
|
spotElement,
|
21468
21500
|
});
|
21469
|
-
placement.replaceChildren(spotElement);
|
21501
|
+
placement === null || placement === void 0 ? void 0 : placement.replaceChildren(spotElement);
|
21470
21502
|
if (config === null || config === void 0 ? void 0 : config.listenRenderedSpotData) {
|
21471
21503
|
this.spotManagerService.publish(exports.RMN_EVENT.RENDERED_SPOT_DATA, {
|
21472
21504
|
placementId,
|
@@ -21565,7 +21597,7 @@ class BrowserRmnClient {
|
|
21565
21597
|
clearPlacement(placementId);
|
21566
21598
|
return;
|
21567
21599
|
}
|
21568
|
-
placement.replaceChildren(carouselElement);
|
21600
|
+
placement === null || placement === void 0 ? void 0 : placement.replaceChildren(carouselElement);
|
21569
21601
|
if (config === null || config === void 0 ? void 0 : config.listenRenderedSpotData) {
|
21570
21602
|
this.spotManagerService.publish(exports.RMN_EVENT.RENDERED_SPOT_DATA, {
|
21571
21603
|
placementId,
|
package/dist/index.esm.js
CHANGED
@@ -7640,31 +7640,36 @@ class ObjectHelper {
|
|
7640
7640
|
}
|
7641
7641
|
}
|
7642
7642
|
|
7643
|
-
|
7644
|
-
async function fallbackEventFire(url) {
|
7643
|
+
function fetchFallbackEventFire(url) {
|
7645
7644
|
try {
|
7646
|
-
|
7647
|
-
|
7648
|
-
|
7649
|
-
|
7650
|
-
|
7651
|
-
|
7652
|
-
|
7653
|
-
|
7654
|
-
|
7655
|
-
|
7656
|
-
|
7657
|
-
|
7658
|
-
|
7659
|
-
|
7660
|
-
|
7661
|
-
|
7662
|
-
|
7645
|
+
fetch === null || fetch === void 0 ? void 0 : fetch(url, {
|
7646
|
+
method: 'POST',
|
7647
|
+
keepalive: true,
|
7648
|
+
}).catch(() => false);
|
7649
|
+
return true;
|
7650
|
+
}
|
7651
|
+
catch (_a) {
|
7652
|
+
return false;
|
7653
|
+
}
|
7654
|
+
}
|
7655
|
+
function xhrFallbackEventFire(url) {
|
7656
|
+
try {
|
7657
|
+
const xhr = new XMLHttpRequest();
|
7658
|
+
xhr.onload = () => xhr.status >= 200 && xhr.status < 300;
|
7659
|
+
xhr.onerror = () => false;
|
7660
|
+
xhr.ontimeout = () => false;
|
7661
|
+
xhr.open('POST', url, true);
|
7662
|
+
xhr.send();
|
7663
|
+
return true;
|
7663
7664
|
}
|
7664
7665
|
catch (_a) {
|
7665
7666
|
return false;
|
7666
7667
|
}
|
7667
7668
|
}
|
7669
|
+
function beaconEventFire(url) {
|
7670
|
+
var _a;
|
7671
|
+
return (_a = navigator === null || navigator === void 0 ? void 0 : navigator.sendBeacon) === null || _a === void 0 ? void 0 : _a.call(navigator, url);
|
7672
|
+
}
|
7668
7673
|
/**
|
7669
7674
|
* Helper function to decode base64 string and parse JSON
|
7670
7675
|
*
|
@@ -7721,21 +7726,30 @@ function getRedirectUrlFromPayload(url) {
|
|
7721
7726
|
* @returns {Promise<void>} - A promise that resolves when the event is fired.
|
7722
7727
|
*/
|
7723
7728
|
async function fireEvent({ spotType, event, eventUrl }) {
|
7724
|
-
|
7725
|
-
|
7726
|
-
const didFireEvent = ((_a = navigator === null || navigator === void 0 ? void 0 : navigator.sendBeacon) === null || _a === void 0 ? void 0 : _a.call(navigator, eventUrl)) || (await fallbackEventFire(eventUrl));
|
7727
|
-
if (!didFireEvent) {
|
7728
|
-
return;
|
7729
|
-
}
|
7730
|
-
// Redirect user if the event is a click event
|
7729
|
+
// Redirect user if the event is a click event
|
7730
|
+
const handleRedirection = () => {
|
7731
7731
|
if (event === RMN_SPOT_EVENT.CLICK && spotType !== RMN_SPOT_TYPE.RB_VIDEO_PLAYER) {
|
7732
7732
|
const redirectUrl = getRedirectUrlFromPayload(eventUrl);
|
7733
7733
|
if (redirectUrl) {
|
7734
7734
|
window.location.href = redirectUrl;
|
7735
7735
|
}
|
7736
7736
|
}
|
7737
|
+
};
|
7738
|
+
try {
|
7739
|
+
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
7740
|
+
beaconEventFire(eventUrl);
|
7741
|
+
handleRedirection();
|
7742
|
+
return;
|
7743
|
+
}
|
7744
|
+
if (typeof fetch !== 'undefined') {
|
7745
|
+
fetchFallbackEventFire(eventUrl);
|
7746
|
+
handleRedirection();
|
7747
|
+
return;
|
7748
|
+
}
|
7749
|
+
xhrFallbackEventFire(eventUrl);
|
7750
|
+
handleRedirection();
|
7737
7751
|
}
|
7738
|
-
catch (
|
7752
|
+
catch (_a) {
|
7739
7753
|
// Handle errors silently
|
7740
7754
|
}
|
7741
7755
|
}
|
@@ -17153,6 +17167,9 @@ const SPOT_EVENTS_ARRAY_INDEX = {
|
|
17153
17167
|
};
|
17154
17168
|
class LocalStorageService {
|
17155
17169
|
constructor() {
|
17170
|
+
if (typeof window.localStorage === 'undefined') {
|
17171
|
+
console.warn('LiquidCommerce Rmn Sdk: Local storage is not supported in this environment.');
|
17172
|
+
}
|
17156
17173
|
this.setUserId();
|
17157
17174
|
this.spots = new Map();
|
17158
17175
|
// Sync local storage with the current state
|
@@ -17173,20 +17190,20 @@ class LocalStorageService {
|
|
17173
17190
|
(_e = this.spots) === null || _e === void 0 ? void 0 : _e.set(spotId, data);
|
17174
17191
|
this.updateLocalStorage();
|
17175
17192
|
}
|
17176
|
-
removeSpot(spotId) {
|
17177
|
-
|
17178
|
-
|
17179
|
-
|
17180
|
-
|
17181
|
-
|
17182
|
-
|
17183
|
-
|
17184
|
-
|
17185
|
-
|
17186
|
-
|
17187
|
-
|
17188
|
-
|
17189
|
-
}
|
17193
|
+
// public removeSpot(spotId: string): void {
|
17194
|
+
// const isExistentSpot = this.spots?.has(spotId);
|
17195
|
+
//
|
17196
|
+
// if (!isExistentSpot) return;
|
17197
|
+
//
|
17198
|
+
// const isDeleted = this.spots?.delete(spotId);
|
17199
|
+
//
|
17200
|
+
// if (!isDeleted) return;
|
17201
|
+
//
|
17202
|
+
// this.updateLocalStorage();
|
17203
|
+
// }
|
17204
|
+
// public getSpot(spotId: string): ILocalStorageSpot | undefined {
|
17205
|
+
// return this.spots?.get(spotId);
|
17206
|
+
// }
|
17190
17207
|
getSpots() {
|
17191
17208
|
if (!this.spots)
|
17192
17209
|
return undefined;
|
@@ -17213,12 +17230,14 @@ class LocalStorageService {
|
|
17213
17230
|
* @return {void} This method does not return a value.
|
17214
17231
|
*/
|
17215
17232
|
setUserId() {
|
17233
|
+
var _a;
|
17216
17234
|
const prefix = LocalStorageService.localStorageKeyPrefix;
|
17217
|
-
const existingKeys = Object.keys(window.localStorage).filter((key) => key.startsWith(prefix));
|
17235
|
+
const existingKeys = Object.keys((_a = window.localStorage) !== null && _a !== void 0 ? _a : {}).filter((key) => key.startsWith(prefix));
|
17218
17236
|
const setNewKey = () => {
|
17237
|
+
var _a;
|
17219
17238
|
const uniqueId = UniqueIdGenerator.generate();
|
17220
17239
|
const newLocalStorageKey = `${prefix}_${uniqueId}`;
|
17221
|
-
window.localStorage.setItem(newLocalStorageKey, '');
|
17240
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(newLocalStorageKey, '');
|
17222
17241
|
LocalStorageService.localStorageKey = newLocalStorageKey;
|
17223
17242
|
};
|
17224
17243
|
if (existingKeys.length === 0) {
|
@@ -17228,8 +17247,9 @@ class LocalStorageService {
|
|
17228
17247
|
const validKey = existingKeys.find((key) => UniqueIdGenerator.isValid(key.replace(`${prefix}_`, '')));
|
17229
17248
|
// Delete all other keys except the valid one
|
17230
17249
|
existingKeys.forEach((key) => {
|
17250
|
+
var _a;
|
17231
17251
|
if (key !== validKey) {
|
17232
|
-
window.localStorage.removeItem(key);
|
17252
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(key);
|
17233
17253
|
}
|
17234
17254
|
});
|
17235
17255
|
if (validKey) {
|
@@ -17244,7 +17264,8 @@ class LocalStorageService {
|
|
17244
17264
|
}
|
17245
17265
|
// ======================== Utility functions ======================== //
|
17246
17266
|
syncLocalStorage() {
|
17247
|
-
|
17267
|
+
var _a;
|
17268
|
+
const localStorageData = (_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.getItem(LocalStorageService.localStorageKey);
|
17248
17269
|
if (localStorageData) {
|
17249
17270
|
try {
|
17250
17271
|
const decryptedData = this.decryptData(localStorageData);
|
@@ -17260,28 +17281,30 @@ class LocalStorageService {
|
|
17260
17281
|
this.clearLocalStorage();
|
17261
17282
|
}
|
17262
17283
|
}
|
17263
|
-
catch (
|
17284
|
+
catch (_b) {
|
17264
17285
|
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17265
17286
|
this.clearLocalStorage();
|
17266
17287
|
}
|
17267
17288
|
}
|
17268
17289
|
}
|
17269
17290
|
updateLocalStorage() {
|
17291
|
+
var _a;
|
17270
17292
|
if (!this.spots)
|
17271
17293
|
return undefined;
|
17272
17294
|
const spotsObj = this.mapToObject(this.spots);
|
17273
17295
|
const data = Object.values(spotsObj).map((spot) => this.spotObjectToArray(spot));
|
17274
17296
|
try {
|
17275
17297
|
const encryptedData = this.encryptData(JSON.stringify(data));
|
17276
|
-
window.localStorage.setItem(LocalStorageService.localStorageKey, encryptedData);
|
17298
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.setItem(LocalStorageService.localStorageKey, encryptedData);
|
17277
17299
|
}
|
17278
|
-
catch (
|
17300
|
+
catch (_b) {
|
17279
17301
|
// If there is an error parsing the data, clear the local storage to prevent any issues
|
17280
17302
|
this.clearLocalStorage();
|
17281
17303
|
}
|
17282
17304
|
}
|
17283
17305
|
clearLocalStorage() {
|
17284
|
-
|
17306
|
+
var _a;
|
17307
|
+
(_a = window.localStorage) === null || _a === void 0 ? void 0 : _a.removeItem(LocalStorageService.localStorageKey);
|
17285
17308
|
}
|
17286
17309
|
removeExpiredSpots() {
|
17287
17310
|
var _a;
|
@@ -17403,6 +17426,7 @@ class ProximityObserver {
|
|
17403
17426
|
this.observeExistingElements();
|
17404
17427
|
}
|
17405
17428
|
initializeObservers() {
|
17429
|
+
var _a;
|
17406
17430
|
// Initialize intersection observer to detect when elements are near viewport
|
17407
17431
|
this.intersectionObserver = new IntersectionObserver(this.handleIntersection.bind(this), {
|
17408
17432
|
rootMargin: this.intersectionMargin,
|
@@ -17438,21 +17462,23 @@ class ProximityObserver {
|
|
17438
17462
|
});
|
17439
17463
|
// Start observing DOM changes
|
17440
17464
|
if (document.body) {
|
17441
|
-
this.mutationObserver.observe(document.body, {
|
17465
|
+
(_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(document.body, {
|
17442
17466
|
childList: true,
|
17443
17467
|
subtree: true,
|
17444
17468
|
});
|
17445
17469
|
}
|
17446
17470
|
}
|
17447
17471
|
handleRemovedElement(element) {
|
17472
|
+
var _a;
|
17448
17473
|
if (element.id && this.processedIds.has(element.id)) {
|
17449
17474
|
this.processedIds.delete(element.id);
|
17450
|
-
this.intersectionObserver.unobserve(element);
|
17475
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(element);
|
17451
17476
|
}
|
17452
17477
|
}
|
17453
17478
|
checkElement(element) {
|
17479
|
+
var _a;
|
17454
17480
|
if (element.id && this.targetIds.has(element.id) && !this.processedIds.has(element.id)) {
|
17455
|
-
this.intersectionObserver.observe(element);
|
17481
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.observe(element);
|
17456
17482
|
}
|
17457
17483
|
}
|
17458
17484
|
findNearbyTargetIds(element) {
|
@@ -17495,10 +17521,11 @@ class ProximityObserver {
|
|
17495
17521
|
const groupIdsToProcess = allGroupIds.slice(0, this.maxGroupSize);
|
17496
17522
|
// Mark all found IDs as processed
|
17497
17523
|
groupIdsToProcess.forEach((id) => {
|
17524
|
+
var _a;
|
17498
17525
|
this.processedIds.add(id);
|
17499
17526
|
const el = document.getElementById(id);
|
17500
17527
|
if (el)
|
17501
|
-
this.intersectionObserver.unobserve(el);
|
17528
|
+
(_a = this.intersectionObserver) === null || _a === void 0 ? void 0 : _a.unobserve(el);
|
17502
17529
|
});
|
17503
17530
|
// Trigger callback with the group
|
17504
17531
|
this.callback(groupIdsToProcess);
|
@@ -17610,6 +17637,10 @@ class PubsubService {
|
|
17610
17637
|
|
17611
17638
|
class ResizeObserverService {
|
17612
17639
|
constructor({ element, maxSize, minScale }) {
|
17640
|
+
var _a;
|
17641
|
+
if (typeof ResizeObserver === 'undefined') {
|
17642
|
+
console.warn('RmnSdk: ResizeObserver is not supported in this browser');
|
17643
|
+
}
|
17613
17644
|
this.element = element;
|
17614
17645
|
if (!element.parentElement) {
|
17615
17646
|
throw new Error('RmnSdk: Spot element must have a parent container.');
|
@@ -17617,7 +17648,7 @@ class ResizeObserverService {
|
|
17617
17648
|
this.container = element.parentElement;
|
17618
17649
|
this.setDimensions(maxSize, minScale);
|
17619
17650
|
this.resizeObserver = new ResizeObserver(() => this.updateElementSize());
|
17620
|
-
this.resizeObserver.observe(this.container);
|
17651
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.observe(this.container);
|
17621
17652
|
// Initial size update
|
17622
17653
|
this.updateElementSize();
|
17623
17654
|
}
|
@@ -17672,7 +17703,8 @@ class ResizeObserverService {
|
|
17672
17703
|
}));
|
17673
17704
|
}
|
17674
17705
|
disconnect() {
|
17675
|
-
|
17706
|
+
var _a;
|
17707
|
+
(_a = this.resizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
17676
17708
|
}
|
17677
17709
|
}
|
17678
17710
|
|
@@ -21355,7 +21387,7 @@ class BrowserRmnClient {
|
|
21355
21387
|
});
|
21356
21388
|
}
|
21357
21389
|
if (skeletonElement) {
|
21358
|
-
placement.replaceChildren(skeletonElement);
|
21390
|
+
placement === null || placement === void 0 ? void 0 : placement.replaceChildren(skeletonElement);
|
21359
21391
|
}
|
21360
21392
|
validPlacements.set(placementId, placement);
|
21361
21393
|
this.spotManagerService.updateSpotLifecycleState(injectData.placementId, {
|
@@ -21464,7 +21496,7 @@ class BrowserRmnClient {
|
|
21464
21496
|
placementId,
|
21465
21497
|
spotElement,
|
21466
21498
|
});
|
21467
|
-
placement.replaceChildren(spotElement);
|
21499
|
+
placement === null || placement === void 0 ? void 0 : placement.replaceChildren(spotElement);
|
21468
21500
|
if (config === null || config === void 0 ? void 0 : config.listenRenderedSpotData) {
|
21469
21501
|
this.spotManagerService.publish(RMN_EVENT.RENDERED_SPOT_DATA, {
|
21470
21502
|
placementId,
|
@@ -21563,7 +21595,7 @@ class BrowserRmnClient {
|
|
21563
21595
|
clearPlacement(placementId);
|
21564
21596
|
return;
|
21565
21597
|
}
|
21566
|
-
placement.replaceChildren(carouselElement);
|
21598
|
+
placement === null || placement === void 0 ? void 0 : placement.replaceChildren(carouselElement);
|
21567
21599
|
if (config === null || config === void 0 ? void 0 : config.listenRenderedSpotData) {
|
21568
21600
|
this.spotManagerService.publish(RMN_EVENT.RENDERED_SPOT_DATA, {
|
21569
21601
|
placementId,
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import type { IFireEventParams } from 'modules/spot-manager';
|
2
|
-
export declare function
|
2
|
+
export declare function fetchFallbackEventFire(url: string): boolean;
|
3
|
+
export declare function xhrFallbackEventFire(url: string): boolean;
|
4
|
+
export declare function beaconEventFire(url: string): boolean;
|
3
5
|
/**
|
4
6
|
* Helper function to decode base64 string and parse JSON
|
5
7
|
*
|
@@ -25,8 +25,6 @@ export declare class LocalStorageService {
|
|
25
25
|
private constructor();
|
26
26
|
static getInstance(): LocalStorageService;
|
27
27
|
setSpot(spotId: string, data: ILocalStorageSpot): void;
|
28
|
-
removeSpot(spotId: string): void;
|
29
|
-
getSpot(spotId: string): ILocalStorageSpot | undefined;
|
30
28
|
getSpots(): LocalStorageSpots | undefined;
|
31
29
|
/**
|
32
30
|
* Retrieves the user ID from the local storage key.
|
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@liquidcommercedev/rmn-sdk",
|
3
3
|
"description": "LiquidCommerce RMN SDK",
|
4
4
|
"author": "LiquidCommerce Tech",
|
5
|
-
"version": "1.5.0-beta.
|
5
|
+
"version": "1.5.0-beta.40",
|
6
6
|
"homepage": "https://docs.liquidcommerce.co/rmn-sdk",
|
7
7
|
"main": "./dist/index.cjs",
|
8
8
|
"module": "./dist/index.esm.js",
|