@liquidcommercedev/rmn-sdk 1.4.6-beta.3 → 1.4.6-beta.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/index.cjs CHANGED
@@ -44,6 +44,7 @@ exports.RMN_SPOT_TYPE = void 0;
44
44
  exports.RMN_FILTER_PROPERTIES = void 0;
45
45
  (function (RMN_FILTER_PROPERTIES) {
46
46
  RMN_FILTER_PROPERTIES["KEYWORDS"] = "keywords";
47
+ RMN_FILTER_PROPERTIES["PAGE_LOCATION"] = "pageLocation";
47
48
  RMN_FILTER_PROPERTIES["PARENTCO"] = "parentCo";
48
49
  RMN_FILTER_PROPERTIES["BRAND"] = "brand";
49
50
  RMN_FILTER_PROPERTIES["CATEGORY"] = "category";
@@ -17656,40 +17657,32 @@ class LiquidCommerceRmnClient {
17656
17657
  *
17657
17658
  * To create a spot html element, use the RmnCreateSpotElement function.
17658
17659
  *
17659
- * @param {ISpotSelectionParams} data - Spots selection parameters.
17660
+ * @param {ISpotSelectionParams} params - Spots selection parameters.
17660
17661
  *
17661
17662
  * @return {Promise<ISpots>} - The spots response object.
17662
17663
  */
17663
- async spotSelection(data) {
17664
- return this.selectionService.spotSelection(data);
17664
+ async spotSelection(params) {
17665
+ return this.selectionService.spotSelection(params);
17665
17666
  }
17666
17667
  /**
17667
17668
  * Injects the spot elements into their provided placement.
17668
17669
  *
17669
- * @param {IInjectSpotElement[]} data - The spot element's data.
17670
- * @param {IInjectSpotElementConfig} config - The configuration object.
17670
+ * @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
17671
17671
  *
17672
17672
  * @return {Promise<void>} - A promise that resolves when the spot elements are injected.
17673
17673
  */
17674
- async injectSpotElement(data, config) {
17675
- if (!data.length) {
17676
- console.warn('RmnSdk: Failed to request spot selection. No spot elements provided.');
17674
+ async injectSpotElement(params) {
17675
+ var _a;
17676
+ const { inject, config } = params;
17677
+ if (!inject.length) {
17678
+ console.warn('RmnSdk: Failed to inject spot element. Please provide at least one spot element to inject.');
17677
17679
  return;
17678
17680
  }
17679
- const spotSelectionRequest = data.map((item) => {
17680
- var _a;
17681
- return ({
17682
- spot: item.spotType,
17683
- count: (_a = item === null || item === void 0 ? void 0 : item.count) !== null && _a !== void 0 ? _a : 1,
17684
- });
17685
- });
17686
- const response = await this.spotSelection({
17687
- spots: spotSelectionRequest,
17688
- url: config === null || config === void 0 ? void 0 : config.url,
17689
- });
17690
- const normalizedData = this.normalizeDataSpotType(data);
17691
- for (const item of normalizedData) {
17692
- const spots = response[item.spotType];
17681
+ this.preventDuplicateSpotPlacementIds(inject);
17682
+ const response = await this.spotSelectionRequest(params);
17683
+ for (const item of inject) {
17684
+ const itemConfig = (_a = item.config) !== null && _a !== void 0 ? _a : config;
17685
+ const spots = response[item.placementId];
17693
17686
  if (!(spots === null || spots === void 0 ? void 0 : spots.length)) {
17694
17687
  console.warn(`RmnSdk: Failed to inject spot element. No spots found for type "${item.spotType}".`);
17695
17688
  continue;
@@ -17701,13 +17694,34 @@ class LiquidCommerceRmnClient {
17701
17694
  continue;
17702
17695
  }
17703
17696
  if (spots.length === 1) {
17704
- this.injectOneSpotElement(item, placement, spots[0], config);
17697
+ this.injectOneSpotElement(item, placement, spots[0], itemConfig);
17705
17698
  }
17706
17699
  if (spots.length > 1) {
17707
- this.injectCarouselSpotElement(placement, spots, config);
17700
+ this.injectCarouselSpotElement(placement, spots, itemConfig);
17708
17701
  }
17709
17702
  }
17710
17703
  }
17704
+ /**
17705
+ * Makes a selection request on our server based on the provided data.
17706
+ *
17707
+ * @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
17708
+ *
17709
+ * @return {Promise<ISpots>} - The spots response object.
17710
+ */
17711
+ async spotSelectionRequest(params) {
17712
+ const { inject, filter, config } = params;
17713
+ const request = {
17714
+ url: config === null || config === void 0 ? void 0 : config.url,
17715
+ filter,
17716
+ spots: inject.map((item) => ({
17717
+ placementId: item.placementId,
17718
+ spot: item.spotType,
17719
+ count: item === null || item === void 0 ? void 0 : item.count,
17720
+ ...item === null || item === void 0 ? void 0 : item.filter,
17721
+ })),
17722
+ };
17723
+ return this.spotSelection(request);
17724
+ }
17711
17725
  /**
17712
17726
  * Injects a carousel element with the provided spots into the placement.
17713
17727
  *
@@ -17781,25 +17795,22 @@ class LiquidCommerceRmnClient {
17781
17795
  placement.replaceChildren(spotElement);
17782
17796
  }
17783
17797
  /**
17784
- * Normalizes the spot type data by adding a number suffix to the spot type.
17798
+ * Prevents duplicate placement ids in the inject data.
17799
+ *
17800
+ * @param {IInjectSpotElement[]} inject - The inject data.
17785
17801
  *
17786
- * @param {IInjectSpotElement[]} spots - The spot type data.
17802
+ * @throws {Error} - If a duplicate placement id is found.
17787
17803
  *
17788
- * @return {IInjectSpotElement[]} - The normalized spot type data.
17804
+ * @return {void}
17789
17805
  */
17790
- normalizeDataSpotType(spots) {
17791
- const spotTypeCounts = {};
17792
- return spots.map((spot) => {
17793
- const { spotType } = spot;
17794
- spotTypeCounts[spotType] = (spotTypeCounts[spotType] || 0) + 1;
17795
- if (spotTypeCounts[spotType] === 1) {
17796
- return spot;
17806
+ preventDuplicateSpotPlacementIds(inject) {
17807
+ const placementIds = new Set();
17808
+ for (const item of inject) {
17809
+ if (placementIds.has(item.placementId)) {
17810
+ throw new Error(`RmnSdk: Duplicate placement id (${item.placementId}) found. Please provide a unique placement id for each spot element.`);
17797
17811
  }
17798
- return {
17799
- ...spot,
17800
- spotType: `${spotType}${spotTypeCounts[spotType]}`,
17801
- };
17802
- });
17812
+ placementIds.add(item.placementId);
17813
+ }
17803
17814
  }
17804
17815
  }
17805
17816
  /**
package/dist/index.esm.js CHANGED
@@ -42,6 +42,7 @@ var RMN_SPOT_TYPE;
42
42
  var RMN_FILTER_PROPERTIES;
43
43
  (function (RMN_FILTER_PROPERTIES) {
44
44
  RMN_FILTER_PROPERTIES["KEYWORDS"] = "keywords";
45
+ RMN_FILTER_PROPERTIES["PAGE_LOCATION"] = "pageLocation";
45
46
  RMN_FILTER_PROPERTIES["PARENTCO"] = "parentCo";
46
47
  RMN_FILTER_PROPERTIES["BRAND"] = "brand";
47
48
  RMN_FILTER_PROPERTIES["CATEGORY"] = "category";
@@ -17654,40 +17655,32 @@ class LiquidCommerceRmnClient {
17654
17655
  *
17655
17656
  * To create a spot html element, use the RmnCreateSpotElement function.
17656
17657
  *
17657
- * @param {ISpotSelectionParams} data - Spots selection parameters.
17658
+ * @param {ISpotSelectionParams} params - Spots selection parameters.
17658
17659
  *
17659
17660
  * @return {Promise<ISpots>} - The spots response object.
17660
17661
  */
17661
- async spotSelection(data) {
17662
- return this.selectionService.spotSelection(data);
17662
+ async spotSelection(params) {
17663
+ return this.selectionService.spotSelection(params);
17663
17664
  }
17664
17665
  /**
17665
17666
  * Injects the spot elements into their provided placement.
17666
17667
  *
17667
- * @param {IInjectSpotElement[]} data - The spot element's data.
17668
- * @param {IInjectSpotElementConfig} config - The configuration object.
17668
+ * @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
17669
17669
  *
17670
17670
  * @return {Promise<void>} - A promise that resolves when the spot elements are injected.
17671
17671
  */
17672
- async injectSpotElement(data, config) {
17673
- if (!data.length) {
17674
- console.warn('RmnSdk: Failed to request spot selection. No spot elements provided.');
17672
+ async injectSpotElement(params) {
17673
+ var _a;
17674
+ const { inject, config } = params;
17675
+ if (!inject.length) {
17676
+ console.warn('RmnSdk: Failed to inject spot element. Please provide at least one spot element to inject.');
17675
17677
  return;
17676
17678
  }
17677
- const spotSelectionRequest = data.map((item) => {
17678
- var _a;
17679
- return ({
17680
- spot: item.spotType,
17681
- count: (_a = item === null || item === void 0 ? void 0 : item.count) !== null && _a !== void 0 ? _a : 1,
17682
- });
17683
- });
17684
- const response = await this.spotSelection({
17685
- spots: spotSelectionRequest,
17686
- url: config === null || config === void 0 ? void 0 : config.url,
17687
- });
17688
- const normalizedData = this.normalizeDataSpotType(data);
17689
- for (const item of normalizedData) {
17690
- const spots = response[item.spotType];
17679
+ this.preventDuplicateSpotPlacementIds(inject);
17680
+ const response = await this.spotSelectionRequest(params);
17681
+ for (const item of inject) {
17682
+ const itemConfig = (_a = item.config) !== null && _a !== void 0 ? _a : config;
17683
+ const spots = response[item.placementId];
17691
17684
  if (!(spots === null || spots === void 0 ? void 0 : spots.length)) {
17692
17685
  console.warn(`RmnSdk: Failed to inject spot element. No spots found for type "${item.spotType}".`);
17693
17686
  continue;
@@ -17699,13 +17692,34 @@ class LiquidCommerceRmnClient {
17699
17692
  continue;
17700
17693
  }
17701
17694
  if (spots.length === 1) {
17702
- this.injectOneSpotElement(item, placement, spots[0], config);
17695
+ this.injectOneSpotElement(item, placement, spots[0], itemConfig);
17703
17696
  }
17704
17697
  if (spots.length > 1) {
17705
- this.injectCarouselSpotElement(placement, spots, config);
17698
+ this.injectCarouselSpotElement(placement, spots, itemConfig);
17706
17699
  }
17707
17700
  }
17708
17701
  }
17702
+ /**
17703
+ * Makes a selection request on our server based on the provided data.
17704
+ *
17705
+ * @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
17706
+ *
17707
+ * @return {Promise<ISpots>} - The spots response object.
17708
+ */
17709
+ async spotSelectionRequest(params) {
17710
+ const { inject, filter, config } = params;
17711
+ const request = {
17712
+ url: config === null || config === void 0 ? void 0 : config.url,
17713
+ filter,
17714
+ spots: inject.map((item) => ({
17715
+ placementId: item.placementId,
17716
+ spot: item.spotType,
17717
+ count: item === null || item === void 0 ? void 0 : item.count,
17718
+ ...item === null || item === void 0 ? void 0 : item.filter,
17719
+ })),
17720
+ };
17721
+ return this.spotSelection(request);
17722
+ }
17709
17723
  /**
17710
17724
  * Injects a carousel element with the provided spots into the placement.
17711
17725
  *
@@ -17779,25 +17793,22 @@ class LiquidCommerceRmnClient {
17779
17793
  placement.replaceChildren(spotElement);
17780
17794
  }
17781
17795
  /**
17782
- * Normalizes the spot type data by adding a number suffix to the spot type.
17796
+ * Prevents duplicate placement ids in the inject data.
17797
+ *
17798
+ * @param {IInjectSpotElement[]} inject - The inject data.
17783
17799
  *
17784
- * @param {IInjectSpotElement[]} spots - The spot type data.
17800
+ * @throws {Error} - If a duplicate placement id is found.
17785
17801
  *
17786
- * @return {IInjectSpotElement[]} - The normalized spot type data.
17802
+ * @return {void}
17787
17803
  */
17788
- normalizeDataSpotType(spots) {
17789
- const spotTypeCounts = {};
17790
- return spots.map((spot) => {
17791
- const { spotType } = spot;
17792
- spotTypeCounts[spotType] = (spotTypeCounts[spotType] || 0) + 1;
17793
- if (spotTypeCounts[spotType] === 1) {
17794
- return spot;
17804
+ preventDuplicateSpotPlacementIds(inject) {
17805
+ const placementIds = new Set();
17806
+ for (const item of inject) {
17807
+ if (placementIds.has(item.placementId)) {
17808
+ throw new Error(`RmnSdk: Duplicate placement id (${item.placementId}) found. Please provide a unique placement id for each spot element.`);
17795
17809
  }
17796
- return {
17797
- ...spot,
17798
- spotType: `${spotType}${spotTypeCounts[spotType]}`,
17799
- };
17800
- });
17810
+ placementIds.add(item.placementId);
17811
+ }
17801
17812
  }
17802
17813
  }
17803
17814
  /**
@@ -38,6 +38,7 @@ export declare enum RMN_SPOT_TYPE {
38
38
  }
39
39
  export declare enum RMN_FILTER_PROPERTIES {
40
40
  KEYWORDS = "keywords",
41
+ PAGE_LOCATION = "pageLocation",
41
42
  PARENTCO = "parentCo",
42
43
  BRAND = "brand",
43
44
  CATEGORY = "category",
@@ -1,6 +1,7 @@
1
1
  import type { RMN_SPOT_TYPE } from 'enums';
2
- import type { ICarouselOptions, ICreateCarouselElementParams } from './component/carousel';
3
- import type { ICreateSpotElementParams } from './component/spot';
2
+ import type { ICarouselOptions, ICreateCarouselElementParams } from 'modules/element/component/carousel';
3
+ import type { ICreateSpotElementParams } from 'modules/element/component/spot';
4
+ import type { RmnFilterType } from 'modules/selection';
4
5
  export interface ISpotColors {
5
6
  textColor?: string;
6
7
  backgroundColor?: string;
@@ -11,11 +12,6 @@ export interface ISpotOverlay {
11
12
  color: string;
12
13
  colorStop: string;
13
14
  }
14
- export interface IInjectSpotElement {
15
- placementId: string;
16
- spotType: RMN_SPOT_TYPE | string;
17
- count?: number;
18
- }
19
15
  export interface IInjectSpotElementConfig {
20
16
  url?: string;
21
17
  colors?: ISpotColors;
@@ -23,15 +19,27 @@ export interface IInjectSpotElementConfig {
23
19
  overlay?: ISpotOverlay[];
24
20
  carousel?: ICarouselOptions;
25
21
  }
22
+ export interface IInjectSpotElement {
23
+ placementId: string;
24
+ spotType: RMN_SPOT_TYPE | string;
25
+ count?: number;
26
+ config?: Omit<IInjectSpotElementConfig, 'url'>;
27
+ filter?: Partial<RmnFilterType>;
28
+ }
26
29
  export interface ICreateElementConfig {
27
30
  width: number;
28
31
  height: number;
29
32
  fluid?: boolean;
30
33
  minScale: number;
31
34
  }
35
+ export interface IInjectSpotElementParams {
36
+ inject: IInjectSpotElement[];
37
+ config?: IInjectSpotElementConfig;
38
+ filter?: Partial<RmnFilterType>;
39
+ }
32
40
  export interface IElementService {
33
- createSpotElement(data: ICreateSpotElementParams): HTMLElement | null;
34
- createCarouselElement(data: ICreateCarouselElementParams): HTMLElement | null;
41
+ createSpotElement(params: ICreateSpotElementParams): HTMLElement | null;
42
+ createCarouselElement(params: ICreateCarouselElementParams): HTMLElement | null;
35
43
  }
36
44
  export interface IRmnCreateSpotElementConfig {
37
45
  fluid?: boolean;
@@ -1,5 +1,5 @@
1
1
  import type { RMN_SPOT_EVENT, RMN_SPOT_TYPE } from 'enums';
2
- import type { SpotIdentifierType, SpotVariantType } from 'modules/selection';
2
+ import type { PlacementIdType, SpotVariantType } from 'modules/selection';
3
3
  import type { RmnFilterType, RmnSpotType } from 'types';
4
4
  export interface ISpotSelectionParams {
5
5
  url?: string;
@@ -30,7 +30,7 @@ export interface ISpot {
30
30
  mobileSecondaryImage?: string;
31
31
  productUpcs?: string[];
32
32
  }
33
- export type ISpots = Record<SpotIdentifierType, ISpot[]>;
33
+ export type ISpots = Record<PlacementIdType, ISpot[]>;
34
34
  export interface ISelectionService {
35
35
  spotSelection(data: ISpotSelectionParams): Promise<ISpots>;
36
36
  }
@@ -2,12 +2,13 @@ import type { RMN_FILTER_PROPERTIES, RMN_SPOT_TYPE } from 'enums';
2
2
  export type RmnFilterType = {
3
3
  [key in RMN_FILTER_PROPERTIES]?: string[];
4
4
  };
5
+ export type PlacementIdType = RMN_SPOT_TYPE | `${RMN_SPOT_TYPE}${number}` | string;
5
6
  export type SpotFilterType = {
7
+ placementId?: PlacementIdType;
6
8
  spot: RMN_SPOT_TYPE | string;
7
- count: number;
9
+ count?: number;
8
10
  exactMatch?: string;
9
11
  } & Omit<RmnFilterType, RMN_FILTER_PROPERTIES.KEYWORDS>;
10
- export type SpotIdentifierType = RMN_SPOT_TYPE | `${RMN_SPOT_TYPE}${number}`;
11
12
  export type RmnSpotType = RMN_SPOT_TYPE | string | SpotFilterType;
12
13
  type RBSpotTypeKeys = keyof {
13
14
  [K in keyof typeof RMN_SPOT_TYPE as K extends `RB_${string}` ? K : never]: (typeof RMN_SPOT_TYPE)[K];
@@ -1,5 +1,5 @@
1
1
  import type { IAuthCredentials } from 'modules/auth';
2
- import type { IInjectSpotElement, IInjectSpotElementConfig, IRmnCreateSpotElementConfig } from 'modules/element';
2
+ import type { IInjectSpotElementParams, IRmnCreateSpotElementConfig } from 'modules/element';
3
3
  import type { ISpot, ISpots, ISpotSelectionParams } from 'modules/selection';
4
4
  import type { IRmnClient, IRmnConfig } from 'types';
5
5
  export declare class LiquidCommerceRmnClient implements IRmnClient {
@@ -11,20 +11,27 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
11
11
  *
12
12
  * To create a spot html element, use the RmnCreateSpotElement function.
13
13
  *
14
- * @param {ISpotSelectionParams} data - Spots selection parameters.
14
+ * @param {ISpotSelectionParams} params - Spots selection parameters.
15
15
  *
16
16
  * @return {Promise<ISpots>} - The spots response object.
17
17
  */
18
- spotSelection(data: ISpotSelectionParams): Promise<ISpots>;
18
+ spotSelection(params: ISpotSelectionParams): Promise<ISpots>;
19
19
  /**
20
20
  * Injects the spot elements into their provided placement.
21
21
  *
22
- * @param {IInjectSpotElement[]} data - The spot element's data.
23
- * @param {IInjectSpotElementConfig} config - The configuration object.
22
+ * @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
24
23
  *
25
24
  * @return {Promise<void>} - A promise that resolves when the spot elements are injected.
26
25
  */
27
- injectSpotElement(data: IInjectSpotElement[], config?: IInjectSpotElementConfig): Promise<void>;
26
+ injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
27
+ /**
28
+ * Makes a selection request on our server based on the provided data.
29
+ *
30
+ * @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
31
+ *
32
+ * @return {Promise<ISpots>} - The spots response object.
33
+ */
34
+ private spotSelectionRequest;
28
35
  /**
29
36
  * Injects a carousel element with the provided spots into the placement.
30
37
  *
@@ -47,13 +54,15 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
47
54
  */
48
55
  private injectOneSpotElement;
49
56
  /**
50
- * Normalizes the spot type data by adding a number suffix to the spot type.
57
+ * Prevents duplicate placement ids in the inject data.
51
58
  *
52
- * @param {IInjectSpotElement[]} spots - The spot type data.
59
+ * @param {IInjectSpotElement[]} inject - The inject data.
53
60
  *
54
- * @return {IInjectSpotElement[]} - The normalized spot type data.
61
+ * @throws {Error} - If a duplicate placement id is found.
62
+ *
63
+ * @return {void}
55
64
  */
56
- private normalizeDataSpotType;
65
+ private preventDuplicateSpotPlacementIds;
57
66
  }
58
67
  /**
59
68
  * Creates a new instance of the RmnClient.
@@ -2,11 +2,11 @@ export type { IInjectSpotElement, IInjectSpotElementConfig, IRmnCreateSpotElemen
2
2
  export type { ISpots, RmnFilterType, RmnSpotType } from 'modules/selection';
3
3
  export { ISpot, ISpotEvent, ISpotSelectionParams } from 'modules/selection';
4
4
  import type { RMN_ENV } from 'enums';
5
- import type { IInjectSpotElement, IInjectSpotElementConfig } from 'modules/element';
5
+ import type { IInjectSpotElementParams } from 'modules/element';
6
6
  import type { ISpots, ISpotSelectionParams } from 'modules/selection';
7
7
  export interface IRmnClient {
8
- spotSelection(data: ISpotSelectionParams): Promise<ISpots>;
9
- injectSpotElement(spots: IInjectSpotElement[], config?: IInjectSpotElementConfig): Promise<void>;
8
+ spotSelection(params: ISpotSelectionParams): Promise<ISpots>;
9
+ injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
10
10
  }
11
11
  export interface IRmnConfig {
12
12
  env: RMN_ENV;
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.4.6-beta.3",
5
+ "version": "1.4.6-beta.4",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",