@liquidcommercedev/rmn-sdk 1.5.0-beta.6 → 1.5.0-beta.7

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 CHANGED
@@ -18388,11 +18388,38 @@ class EventService {
18388
18388
  },
18389
18389
  };
18390
18390
  }
18391
- this.spotStates.set(placementId, { ...currentState, ...updates });
18391
+ const merged = this.deepMerge(currentState, updates);
18392
+ this.spotStates.set(placementId, merged);
18392
18393
  if (publish) {
18393
18394
  this.pubSub.publish(exports.RMN_SPOT_EVENT.LIFECYCLE_STATE, this.spotStates.get(placementId));
18394
18395
  }
18395
18396
  }
18397
+ deepMerge(current, updates) {
18398
+ return {
18399
+ identifier: {
18400
+ ...current.identifier,
18401
+ ...updates.identifier,
18402
+ },
18403
+ dom: updates.dom
18404
+ ? {
18405
+ ...current.dom,
18406
+ ...updates.dom,
18407
+ }
18408
+ : current.dom,
18409
+ state: updates.state
18410
+ ? {
18411
+ ...current.state,
18412
+ ...updates.state,
18413
+ }
18414
+ : current.state,
18415
+ displayConfig: updates.displayConfig
18416
+ ? {
18417
+ ...current.displayConfig,
18418
+ ...updates.displayConfig,
18419
+ }
18420
+ : current.displayConfig,
18421
+ };
18422
+ }
18396
18423
  async handleClick({ placementId, spot, spotElement, }) {
18397
18424
  var _a, _b, _c;
18398
18425
  // Publish click event
@@ -18747,10 +18774,12 @@ class LiquidCommerceRmnClient {
18747
18774
  const config = params.config;
18748
18775
  let inject = params.inject;
18749
18776
  if (!inject.length) {
18777
+ // Handle no spots error state
18750
18778
  this.eventService.handleSpotState('all', {
18751
18779
  state: {
18752
18780
  error: 'No spot elements provided for injection.',
18753
18781
  loading: false,
18782
+ mounted: false,
18754
18783
  },
18755
18784
  });
18756
18785
  return;
@@ -18769,9 +18798,12 @@ class LiquidCommerceRmnClient {
18769
18798
  // const response = await this.useSpotSelectionExample(inject);
18770
18799
  // Handle the response
18771
18800
  if (typeof response === 'object' && 'error' in response) {
18801
+ // Handle request error state
18772
18802
  this.eventService.handleSpotState('all', {
18773
18803
  state: {
18774
18804
  error: response.error,
18805
+ mounted: false,
18806
+ loading: false,
18775
18807
  },
18776
18808
  });
18777
18809
  return;
@@ -18780,9 +18812,11 @@ class LiquidCommerceRmnClient {
18780
18812
  const itemConfig = (_a = item.config) !== null && _a !== void 0 ? _a : config;
18781
18813
  const spots = response[item.placementId];
18782
18814
  if (!(spots === null || spots === void 0 ? void 0 : spots.length)) {
18815
+ // Handle no spots found error state
18783
18816
  this.eventService.handleSpotState(item.placementId, {
18784
18817
  state: {
18785
18818
  error: `No spots found for type "${item.spotType}".`,
18819
+ mounted: false,
18786
18820
  loading: false,
18787
18821
  },
18788
18822
  });
@@ -18791,9 +18825,11 @@ class LiquidCommerceRmnClient {
18791
18825
  const placementId = item.placementId.replace('#', '');
18792
18826
  const placement = document.getElementById(placementId);
18793
18827
  if (!placement) {
18828
+ // Handle placement not found error state
18794
18829
  this.eventService.handleSpotState(item.placementId, {
18795
18830
  state: {
18796
18831
  error: `Placement not found for id "${placementId}".`,
18832
+ mounted: false,
18797
18833
  loading: false,
18798
18834
  },
18799
18835
  });
@@ -18808,12 +18844,14 @@ class LiquidCommerceRmnClient {
18808
18844
  display: 'flex',
18809
18845
  justifyContent: 'center',
18810
18846
  });
18847
+ // Handle single spot
18811
18848
  if (spots.length === 1) {
18812
18849
  const isInjected = this.injectOneSpotElement(item, placement, spots[0], itemConfig);
18813
18850
  if (!isInjected) {
18814
18851
  continue;
18815
18852
  }
18816
18853
  }
18854
+ // Handle multiple spots (carousel)
18817
18855
  if (spots.length > 1) {
18818
18856
  const isInjected = this.injectCarouselSpotElement(placement, spots, itemConfig);
18819
18857
  if (!isInjected) {
@@ -18857,18 +18895,24 @@ class LiquidCommerceRmnClient {
18857
18895
  const carouselSlides = [];
18858
18896
  for (const spotItem of spots) {
18859
18897
  this.eventService.handleSpotState(placement.id, {
18898
+ identifier: {
18899
+ placementId: placement.id,
18900
+ spotType: spotItem.spot,
18901
+ spotId: spotItem.id,
18902
+ },
18860
18903
  displayConfig: {
18904
+ isSingleItem: false,
18861
18905
  isCarousel: true,
18862
18906
  isCarouselItem: true,
18863
- isSingleItem: false,
18864
18907
  },
18865
- }, false);
18908
+ });
18866
18909
  const spot = this.elementService.overrideSpotColors(spotItem, config === null || config === void 0 ? void 0 : config.colors);
18867
18910
  const content = SPOT_TEMPLATE_HTML_ELEMENT(spot, { overlay: config === null || config === void 0 ? void 0 : config.overlay });
18868
18911
  if (!content) {
18869
18912
  this.eventService.handleSpotState(placement.id, {
18870
18913
  state: {
18871
18914
  error: `Failed to inject carousel spot item element. Could not create element for type "${spot.spot}".`,
18915
+ mounted: false,
18872
18916
  loading: false,
18873
18917
  },
18874
18918
  });
@@ -18901,6 +18945,7 @@ class LiquidCommerceRmnClient {
18901
18945
  this.eventService.handleSpotState(placement.id, {
18902
18946
  state: {
18903
18947
  error: `Failed to inject spot carousel element. Could not create spot carousel element.`,
18948
+ mounted: false,
18904
18949
  loading: false,
18905
18950
  },
18906
18951
  });
@@ -18910,10 +18955,12 @@ class LiquidCommerceRmnClient {
18910
18955
  this.eventService.handleSpotState(placement.id, {
18911
18956
  dom: {
18912
18957
  spotElement: carouselElement,
18958
+ visibleOnViewport: false,
18913
18959
  },
18914
18960
  state: {
18915
18961
  mounted: true,
18916
18962
  loading: false,
18963
+ error: undefined,
18917
18964
  },
18918
18965
  });
18919
18966
  return true;
@@ -18930,18 +18977,25 @@ class LiquidCommerceRmnClient {
18930
18977
  */
18931
18978
  injectOneSpotElement(injectItem, placement, spot, config) {
18932
18979
  var _a;
18933
- const spotData = this.elementService.overrideSpotColors(spot, config === null || config === void 0 ? void 0 : config.colors);
18934
18980
  this.eventService.handleSpotState(injectItem.placementId, {
18981
+ identifier: {
18982
+ placementId: injectItem.placementId,
18983
+ spotType: injectItem.spotType,
18984
+ spotId: spot.id,
18985
+ },
18935
18986
  displayConfig: {
18936
18987
  isSingleItem: true,
18988
+ isCarousel: false,
18989
+ isCarouselItem: false,
18937
18990
  },
18938
- }, false);
18939
- // Create the spot template element
18991
+ });
18992
+ const spotData = this.elementService.overrideSpotColors(spot, config === null || config === void 0 ? void 0 : config.colors);
18940
18993
  const content = SPOT_TEMPLATE_HTML_ELEMENT(spotData, { overlay: config === null || config === void 0 ? void 0 : config.overlay });
18941
18994
  if (!content) {
18942
18995
  this.eventService.handleSpotState(injectItem.placementId, {
18943
18996
  state: {
18944
18997
  error: `Failed to inject spot element. Could not create element for type "${injectItem.spotType}".`,
18998
+ mounted: false,
18945
18999
  loading: false,
18946
19000
  },
18947
19001
  });
@@ -18962,6 +19016,7 @@ class LiquidCommerceRmnClient {
18962
19016
  this.eventService.handleSpotState(injectItem.placementId, {
18963
19017
  state: {
18964
19018
  error: `Failed to inject spot element. Could not create element for type "${injectItem.spotType}".`,
19019
+ mounted: false,
18965
19020
  loading: false,
18966
19021
  },
18967
19022
  });
@@ -18976,10 +19031,12 @@ class LiquidCommerceRmnClient {
18976
19031
  this.eventService.handleSpotState(injectItem.placementId, {
18977
19032
  dom: {
18978
19033
  spotElement,
19034
+ visibleOnViewport: false,
18979
19035
  },
18980
19036
  state: {
18981
19037
  mounted: true,
18982
19038
  loading: false,
19039
+ error: undefined,
18983
19040
  },
18984
19041
  });
18985
19042
  return true;
@@ -19000,6 +19057,8 @@ class LiquidCommerceRmnClient {
19000
19057
  this.eventService.handleSpotState(item.placementId, {
19001
19058
  state: {
19002
19059
  error: `Duplicate placement id (${item.placementId}) found. Please provide a unique placement id for each spot element.`,
19060
+ mounted: false,
19061
+ loading: false,
19003
19062
  },
19004
19063
  });
19005
19064
  return false;
@@ -19015,6 +19074,8 @@ class LiquidCommerceRmnClient {
19015
19074
  this.eventService.handleSpotState(item.placementId, {
19016
19075
  state: {
19017
19076
  error: `Invalid spot type (${item.spotType}) found. Please provide a valid spot type for each spot element.`,
19077
+ mounted: false,
19078
+ loading: false,
19018
19079
  },
19019
19080
  });
19020
19081
  continue;
@@ -19023,6 +19084,7 @@ class LiquidCommerceRmnClient {
19023
19084
  }
19024
19085
  return newInject;
19025
19086
  }
19087
+ // Initialize spots with loading state and identifiers
19026
19088
  updateSpotsState(inject) {
19027
19089
  for (const item of inject) {
19028
19090
  this.eventService.handleSpotState(item.placementId, {
@@ -19032,6 +19094,8 @@ class LiquidCommerceRmnClient {
19032
19094
  },
19033
19095
  state: {
19034
19096
  loading: true,
19097
+ mounted: false,
19098
+ error: undefined,
19035
19099
  },
19036
19100
  });
19037
19101
  }
package/dist/index.esm.js CHANGED
@@ -18386,11 +18386,38 @@ class EventService {
18386
18386
  },
18387
18387
  };
18388
18388
  }
18389
- this.spotStates.set(placementId, { ...currentState, ...updates });
18389
+ const merged = this.deepMerge(currentState, updates);
18390
+ this.spotStates.set(placementId, merged);
18390
18391
  if (publish) {
18391
18392
  this.pubSub.publish(RMN_SPOT_EVENT.LIFECYCLE_STATE, this.spotStates.get(placementId));
18392
18393
  }
18393
18394
  }
18395
+ deepMerge(current, updates) {
18396
+ return {
18397
+ identifier: {
18398
+ ...current.identifier,
18399
+ ...updates.identifier,
18400
+ },
18401
+ dom: updates.dom
18402
+ ? {
18403
+ ...current.dom,
18404
+ ...updates.dom,
18405
+ }
18406
+ : current.dom,
18407
+ state: updates.state
18408
+ ? {
18409
+ ...current.state,
18410
+ ...updates.state,
18411
+ }
18412
+ : current.state,
18413
+ displayConfig: updates.displayConfig
18414
+ ? {
18415
+ ...current.displayConfig,
18416
+ ...updates.displayConfig,
18417
+ }
18418
+ : current.displayConfig,
18419
+ };
18420
+ }
18394
18421
  async handleClick({ placementId, spot, spotElement, }) {
18395
18422
  var _a, _b, _c;
18396
18423
  // Publish click event
@@ -18745,10 +18772,12 @@ class LiquidCommerceRmnClient {
18745
18772
  const config = params.config;
18746
18773
  let inject = params.inject;
18747
18774
  if (!inject.length) {
18775
+ // Handle no spots error state
18748
18776
  this.eventService.handleSpotState('all', {
18749
18777
  state: {
18750
18778
  error: 'No spot elements provided for injection.',
18751
18779
  loading: false,
18780
+ mounted: false,
18752
18781
  },
18753
18782
  });
18754
18783
  return;
@@ -18767,9 +18796,12 @@ class LiquidCommerceRmnClient {
18767
18796
  // const response = await this.useSpotSelectionExample(inject);
18768
18797
  // Handle the response
18769
18798
  if (typeof response === 'object' && 'error' in response) {
18799
+ // Handle request error state
18770
18800
  this.eventService.handleSpotState('all', {
18771
18801
  state: {
18772
18802
  error: response.error,
18803
+ mounted: false,
18804
+ loading: false,
18773
18805
  },
18774
18806
  });
18775
18807
  return;
@@ -18778,9 +18810,11 @@ class LiquidCommerceRmnClient {
18778
18810
  const itemConfig = (_a = item.config) !== null && _a !== void 0 ? _a : config;
18779
18811
  const spots = response[item.placementId];
18780
18812
  if (!(spots === null || spots === void 0 ? void 0 : spots.length)) {
18813
+ // Handle no spots found error state
18781
18814
  this.eventService.handleSpotState(item.placementId, {
18782
18815
  state: {
18783
18816
  error: `No spots found for type "${item.spotType}".`,
18817
+ mounted: false,
18784
18818
  loading: false,
18785
18819
  },
18786
18820
  });
@@ -18789,9 +18823,11 @@ class LiquidCommerceRmnClient {
18789
18823
  const placementId = item.placementId.replace('#', '');
18790
18824
  const placement = document.getElementById(placementId);
18791
18825
  if (!placement) {
18826
+ // Handle placement not found error state
18792
18827
  this.eventService.handleSpotState(item.placementId, {
18793
18828
  state: {
18794
18829
  error: `Placement not found for id "${placementId}".`,
18830
+ mounted: false,
18795
18831
  loading: false,
18796
18832
  },
18797
18833
  });
@@ -18806,12 +18842,14 @@ class LiquidCommerceRmnClient {
18806
18842
  display: 'flex',
18807
18843
  justifyContent: 'center',
18808
18844
  });
18845
+ // Handle single spot
18809
18846
  if (spots.length === 1) {
18810
18847
  const isInjected = this.injectOneSpotElement(item, placement, spots[0], itemConfig);
18811
18848
  if (!isInjected) {
18812
18849
  continue;
18813
18850
  }
18814
18851
  }
18852
+ // Handle multiple spots (carousel)
18815
18853
  if (spots.length > 1) {
18816
18854
  const isInjected = this.injectCarouselSpotElement(placement, spots, itemConfig);
18817
18855
  if (!isInjected) {
@@ -18855,18 +18893,24 @@ class LiquidCommerceRmnClient {
18855
18893
  const carouselSlides = [];
18856
18894
  for (const spotItem of spots) {
18857
18895
  this.eventService.handleSpotState(placement.id, {
18896
+ identifier: {
18897
+ placementId: placement.id,
18898
+ spotType: spotItem.spot,
18899
+ spotId: spotItem.id,
18900
+ },
18858
18901
  displayConfig: {
18902
+ isSingleItem: false,
18859
18903
  isCarousel: true,
18860
18904
  isCarouselItem: true,
18861
- isSingleItem: false,
18862
18905
  },
18863
- }, false);
18906
+ });
18864
18907
  const spot = this.elementService.overrideSpotColors(spotItem, config === null || config === void 0 ? void 0 : config.colors);
18865
18908
  const content = SPOT_TEMPLATE_HTML_ELEMENT(spot, { overlay: config === null || config === void 0 ? void 0 : config.overlay });
18866
18909
  if (!content) {
18867
18910
  this.eventService.handleSpotState(placement.id, {
18868
18911
  state: {
18869
18912
  error: `Failed to inject carousel spot item element. Could not create element for type "${spot.spot}".`,
18913
+ mounted: false,
18870
18914
  loading: false,
18871
18915
  },
18872
18916
  });
@@ -18899,6 +18943,7 @@ class LiquidCommerceRmnClient {
18899
18943
  this.eventService.handleSpotState(placement.id, {
18900
18944
  state: {
18901
18945
  error: `Failed to inject spot carousel element. Could not create spot carousel element.`,
18946
+ mounted: false,
18902
18947
  loading: false,
18903
18948
  },
18904
18949
  });
@@ -18908,10 +18953,12 @@ class LiquidCommerceRmnClient {
18908
18953
  this.eventService.handleSpotState(placement.id, {
18909
18954
  dom: {
18910
18955
  spotElement: carouselElement,
18956
+ visibleOnViewport: false,
18911
18957
  },
18912
18958
  state: {
18913
18959
  mounted: true,
18914
18960
  loading: false,
18961
+ error: undefined,
18915
18962
  },
18916
18963
  });
18917
18964
  return true;
@@ -18928,18 +18975,25 @@ class LiquidCommerceRmnClient {
18928
18975
  */
18929
18976
  injectOneSpotElement(injectItem, placement, spot, config) {
18930
18977
  var _a;
18931
- const spotData = this.elementService.overrideSpotColors(spot, config === null || config === void 0 ? void 0 : config.colors);
18932
18978
  this.eventService.handleSpotState(injectItem.placementId, {
18979
+ identifier: {
18980
+ placementId: injectItem.placementId,
18981
+ spotType: injectItem.spotType,
18982
+ spotId: spot.id,
18983
+ },
18933
18984
  displayConfig: {
18934
18985
  isSingleItem: true,
18986
+ isCarousel: false,
18987
+ isCarouselItem: false,
18935
18988
  },
18936
- }, false);
18937
- // Create the spot template element
18989
+ });
18990
+ const spotData = this.elementService.overrideSpotColors(spot, config === null || config === void 0 ? void 0 : config.colors);
18938
18991
  const content = SPOT_TEMPLATE_HTML_ELEMENT(spotData, { overlay: config === null || config === void 0 ? void 0 : config.overlay });
18939
18992
  if (!content) {
18940
18993
  this.eventService.handleSpotState(injectItem.placementId, {
18941
18994
  state: {
18942
18995
  error: `Failed to inject spot element. Could not create element for type "${injectItem.spotType}".`,
18996
+ mounted: false,
18943
18997
  loading: false,
18944
18998
  },
18945
18999
  });
@@ -18960,6 +19014,7 @@ class LiquidCommerceRmnClient {
18960
19014
  this.eventService.handleSpotState(injectItem.placementId, {
18961
19015
  state: {
18962
19016
  error: `Failed to inject spot element. Could not create element for type "${injectItem.spotType}".`,
19017
+ mounted: false,
18963
19018
  loading: false,
18964
19019
  },
18965
19020
  });
@@ -18974,10 +19029,12 @@ class LiquidCommerceRmnClient {
18974
19029
  this.eventService.handleSpotState(injectItem.placementId, {
18975
19030
  dom: {
18976
19031
  spotElement,
19032
+ visibleOnViewport: false,
18977
19033
  },
18978
19034
  state: {
18979
19035
  mounted: true,
18980
19036
  loading: false,
19037
+ error: undefined,
18981
19038
  },
18982
19039
  });
18983
19040
  return true;
@@ -18998,6 +19055,8 @@ class LiquidCommerceRmnClient {
18998
19055
  this.eventService.handleSpotState(item.placementId, {
18999
19056
  state: {
19000
19057
  error: `Duplicate placement id (${item.placementId}) found. Please provide a unique placement id for each spot element.`,
19058
+ mounted: false,
19059
+ loading: false,
19001
19060
  },
19002
19061
  });
19003
19062
  return false;
@@ -19013,6 +19072,8 @@ class LiquidCommerceRmnClient {
19013
19072
  this.eventService.handleSpotState(item.placementId, {
19014
19073
  state: {
19015
19074
  error: `Invalid spot type (${item.spotType}) found. Please provide a valid spot type for each spot element.`,
19075
+ mounted: false,
19076
+ loading: false,
19016
19077
  },
19017
19078
  });
19018
19079
  continue;
@@ -19021,6 +19082,7 @@ class LiquidCommerceRmnClient {
19021
19082
  }
19022
19083
  return newInject;
19023
19084
  }
19085
+ // Initialize spots with loading state and identifiers
19024
19086
  updateSpotsState(inject) {
19025
19087
  for (const item of inject) {
19026
19088
  this.eventService.handleSpotState(item.placementId, {
@@ -19030,6 +19092,8 @@ class LiquidCommerceRmnClient {
19030
19092
  },
19031
19093
  state: {
19032
19094
  loading: true,
19095
+ mounted: false,
19096
+ error: undefined,
19033
19097
  },
19034
19098
  });
19035
19099
  }
@@ -23,6 +23,7 @@ export declare class EventService {
23
23
  * @returns {void}
24
24
  */
25
25
  handleSpotState(placementId: string, updates: Partial<ILifecycleState>, publish?: boolean): void;
26
+ private deepMerge;
26
27
  private handleClick;
27
28
  private handleIntersectionObserver;
28
29
  private fireImpressionEvent;
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.6",
5
+ "version": "1.5.0-beta.7",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",