@liquidcommercedev/rmn-sdk 1.5.0-beta.1 → 1.5.0-beta.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. package/dist/index.cjs +1414 -602
  2. package/dist/index.esm.js +1415 -603
  3. package/dist/types/common/helpers/event-type.helper.d.ts +8 -0
  4. package/dist/types/common/helpers/index.d.ts +4 -0
  5. package/dist/types/common/helpers/utils.helper.d.ts +37 -0
  6. package/dist/types/enums.d.ts +8 -1
  7. package/dist/types/modules/element/element.interface.d.ts +5 -2
  8. package/dist/types/modules/event/event.interface.d.ts +6 -32
  9. package/dist/types/modules/event/event.service.d.ts +7 -22
  10. package/dist/types/modules/event/index.d.ts +0 -1
  11. package/dist/types/modules/{event/helpers → helper-service}/index.d.ts +1 -0
  12. package/dist/types/modules/{event/helpers → helper-service}/intersection.service.d.ts +1 -1
  13. package/dist/types/modules/helper-service/localstorage.service.d.ts +56 -0
  14. package/dist/types/modules/{event/pubsub.d.ts → helper-service/pubsub.service.d.ts} +8 -8
  15. package/dist/types/modules/{event/helpers → helper-service}/resize.service.d.ts +1 -1
  16. package/dist/types/modules/monitor/index.d.ts +2 -0
  17. package/dist/types/modules/monitor/monitor.enums.d.ts +4 -0
  18. package/dist/types/modules/monitor/monitor.interface.d.ts +11 -0
  19. package/dist/types/modules/monitor/monitor.service.d.ts +12 -0
  20. package/dist/types/modules/monitor/monitors/datalayer.monitor.d.ts +12 -0
  21. package/dist/types/modules/selection/selection.interface.d.ts +3 -1
  22. package/dist/types/rmn-client.d.ts +1 -1
  23. package/dist/types/types.d.ts +5 -4
  24. package/package.json +1 -1
  25. package/umd/liquidcommerce-rmn-sdk.min.js +1 -1
  26. package/dist/types/modules/element/component/utils.d.ts +0 -1
  27. package/dist/types/modules/event/helpers/localstorage.service.d.ts +0 -26
  28. /package/dist/types/{static.constant.d.ts → example.constant.d.ts} +0 -0
@@ -0,0 +1,8 @@
1
+ import { RMN_SPOT_EVENT } from 'enums';
2
+ /**
3
+ * Determines the event type from a raw event string by checking for keyword patterns.
4
+ *
5
+ * @param {string} [event] - The raw event string to evaluate
6
+ * @returns {RMN_SPOT_EVENT | null} - The corresponding RMN_SPOT_EVENT or null if no match
7
+ */
8
+ export declare function getEventTypeFromRawEvent(event?: string): RMN_SPOT_EVENT | null;
@@ -1,2 +1,6 @@
1
+ export * from './event-type.helper';
2
+ export * from './helpers.interface';
1
3
  export * from './object.helper';
2
4
  export * from './string.helper';
5
+ export * from './utils.helper';
6
+ export * from './uuid.helper';
@@ -0,0 +1,37 @@
1
+ import type { IFireEventParams } from 'modules/event';
2
+ /**
3
+ * Recursively extracts ID values from a nested data structure.
4
+ * Searches for specified property names and collects their primitive values (strings/numbers).
5
+ *
6
+ * @param data - The data structure to search through (can be nested objects/arrays)
7
+ * @param propertyNames - Array of property names to look for
8
+ * @returns Array of extracted ID values (strings/numbers only)
9
+ *
10
+ * @example
11
+ * const data = {
12
+ * id: [1, 2, 3],
13
+ * nested: { id: 'abc' },
14
+ * items: [{ id: 456 }]
15
+ * };
16
+ * extractDeepIds(data); // Returns [1, 2, 3, 'abc', 456]
17
+ */
18
+ export declare function extractDeepIds(data: any, propertyNames?: string[]): Array<string | number>;
19
+ export declare function fallbackEventFire(url: string): Promise<boolean>;
20
+ /**
21
+ * Extracts and decodes a URL from a base64-encoded query parameter.
22
+ *
23
+ * @param {string} url - The URL containing the base64-encoded query parameter.
24
+ * @returns {string | null} - The decoded URL or null if not found or invalid.
25
+ */
26
+ export declare function getRedirectUrlFromPayload(url: string): string | null;
27
+ /**
28
+ * Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
29
+ * If the event is a click event and a redirect URL is found, it redirects the user to that URL.
30
+ *
31
+ * @param {IFireEventParams} params - The parameters for firing the event.
32
+ * @param {RMN_SPOT_EVENT} params.event - The event type.
33
+ * @param {string} params.eventUrl - The URL to which the event is sent.
34
+ * @returns {Promise<void>} - A promise that resolves when the event is fired.
35
+ */
36
+ export declare function fireEvent({ event, eventUrl }: IFireEventParams): Promise<void>;
37
+ export declare function calculateScaleFactor(elementScale: number): number;
@@ -1,4 +1,5 @@
1
1
  export declare enum RMN_SPOT_TYPE {
2
+ RB_HOMEPAGE_HERO = "rbHomepageHero",
2
3
  RB_HOMEPAGE_HERO_THREE_TILE = "rbHomepageHeroThreeTile",
3
4
  RB_HOMEPAGE_HERO_TWO_TILE = "rbHomepageHeroTwoTile",
4
5
  RB_HOMEPAGE_HERO_FULL_IMAGE = "rbHomepageHeroFullImage",
@@ -48,13 +49,19 @@ export declare enum RMN_FILTER_PROPERTIES {
48
49
  PUBLISHERS = "publishers",
49
50
  SECTION = "section"
50
51
  }
51
- export declare enum RMN_SPOT_EVENT {
52
+ export declare enum RMN_EVENT {
52
53
  LIFECYCLE_STATE = "LIFECYCLE_STATE",
54
+ SPOT_EVENT = "SPOT_EVENT"
55
+ }
56
+ export declare enum RMN_SPOT_EVENT {
53
57
  IMPRESSION = "IMPRESSION",
54
58
  CLICK = "CLICK",
55
59
  PURCHASE = "PURCHASE",
56
60
  ADD_TO_CART = "ADD_TO_CART",
61
+ REMOVE_FROM_CART = "REMOVE_FROM_CART",
62
+ ADD_TO_CART_FROM_DETAILS = "ADD_TO_CART_FROM_DETAILS",
57
63
  ADD_TO_WISHLIST = "ADD_TO_WISHLIST",
64
+ EXPAND_PRODUCT = "EXPAND_PRODUCT",
58
65
  BUY_NOW = "BUY_NOW"
59
66
  }
60
67
  export declare enum RMN_ENV {
@@ -1,4 +1,4 @@
1
- import type { RMN_SPOT_TYPE } from 'enums';
1
+ import type { RMN_FILTER_PROPERTIES, RMN_SPOT_TYPE } from 'enums';
2
2
  import type { ICarouselOptions, ICreateCarouselElementParams } from 'modules/element/component/carousel';
3
3
  import type { ICreateSpotElementParams } from 'modules/element/component/spot';
4
4
  import type { RmnFilterType } from 'modules/selection';
@@ -21,12 +21,15 @@ export interface IInjectSpotElementConfig {
21
21
  overlay?: ISpotOverlay;
22
22
  carousel?: ICarouselOptions;
23
23
  }
24
+ export type IInjectSpotElementFilterType = Partial<Omit<RmnFilterType, RMN_FILTER_PROPERTIES.KEYWORDS> & {
25
+ exactMatch?: string;
26
+ }>;
24
27
  export interface IInjectSpotElement {
25
28
  placementId: string;
26
29
  spotType: RMN_SPOT_TYPE | string;
27
30
  count?: number;
28
31
  config?: Omit<IInjectSpotElementConfig, 'url'>;
29
- filter?: Partial<RmnFilterType>;
32
+ filter?: IInjectSpotElementFilterType;
30
33
  }
31
34
  export interface ICreateElementConfig {
32
35
  spot?: RMN_SPOT_TYPE;
@@ -1,4 +1,4 @@
1
- import type { RMN_SPOT_EVENT } from 'enums';
1
+ import type { RMN_EVENT, RMN_SPOT_EVENT } from 'enums';
2
2
  import type { ISpot } from '../selection';
3
3
  export interface IFireEventParams {
4
4
  event: RMN_SPOT_EVENT;
@@ -30,40 +30,14 @@ export interface ILifecycleState {
30
30
  state?: Partial<ILSState>;
31
31
  displayConfig?: Partial<ILSDisplayConfig>;
32
32
  }
33
- export interface IClickEvent {
34
- placementId: string;
35
- spotId: string;
36
- spotElement: HTMLElement;
37
- }
38
- export interface IImpressionEvent {
39
- placementId: string;
40
- spotId: string;
41
- spotElement: HTMLElement;
42
- }
43
- export interface IAddToCartEvent {
44
- placementId: string;
45
- spotId: string;
46
- }
47
- export interface IAddToWishlistEvent {
48
- placementId: string;
49
- spotId: string;
50
- }
51
- export interface IPurchaseEvent {
52
- placementId: string;
53
- spotId: string;
54
- }
55
- export interface IBuyNowEvent {
33
+ export interface IRmnSpotEvent {
34
+ eventType: RMN_SPOT_EVENT;
56
35
  placementId: string;
57
36
  spotId: string;
58
37
  }
59
- export interface IEventMap {
60
- [RMN_SPOT_EVENT.LIFECYCLE_STATE]: ILifecycleState;
61
- [RMN_SPOT_EVENT.CLICK]: IClickEvent;
62
- [RMN_SPOT_EVENT.IMPRESSION]: IImpressionEvent;
63
- [RMN_SPOT_EVENT.ADD_TO_CART]: IAddToCartEvent;
64
- [RMN_SPOT_EVENT.ADD_TO_WISHLIST]: IAddToWishlistEvent;
65
- [RMN_SPOT_EVENT.PURCHASE]: IPurchaseEvent;
66
- [RMN_SPOT_EVENT.BUY_NOW]: IBuyNowEvent;
38
+ export interface IRmnEventMap {
39
+ [RMN_EVENT.LIFECYCLE_STATE]: ILifecycleState;
40
+ [RMN_EVENT.SPOT_EVENT]: IRmnSpotEvent;
67
41
  }
68
42
  export interface IRegisterSpotParams {
69
43
  placementId: string;
@@ -1,16 +1,16 @@
1
- import { RMN_SPOT_EVENT } from 'enums';
2
- import type { IEventMap, ILifecycleState, IRegisterSpotParams } from './event.interface';
1
+ import { RMN_EVENT } from 'enums';
2
+ import type { ILifecycleState, IRegisterSpotParams, IRmnEventMap } from './event.interface';
3
3
  export declare class EventService {
4
4
  private static instance;
5
- private pubSub;
6
- private localStorage;
5
+ private pubSubService;
6
+ private localStorageService;
7
7
  private intersectionObserver;
8
8
  private spotStates;
9
9
  private activeSpots;
10
10
  private constructor();
11
11
  static getInstance(): EventService;
12
- subscribe(eventType: RMN_SPOT_EVENT, callback: (data: IEventMap[RMN_SPOT_EVENT]) => void): () => void;
13
- publish(eventType: RMN_SPOT_EVENT, data: IEventMap[RMN_SPOT_EVENT]): void;
12
+ subscribe(eventType: RMN_EVENT, callback: (data: IRmnEventMap[RMN_EVENT]) => void): () => void;
13
+ publish(eventType: RMN_EVENT, data: IRmnEventMap[RMN_EVENT]): void;
14
14
  registerSpot(params: IRegisterSpotParams): void;
15
15
  unregisterSpot(placementId: string): void;
16
16
  /**
@@ -23,23 +23,8 @@ 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;
29
- /**
30
- * Fires an event using the navigator.sendBeacon method and redirects the user if the event is a click event.
31
- *
32
- * @param {IFireEventParams} params - The parameters for firing the event.
33
- * @param {RMN_SPOT_EVENT} params.event - The event type.
34
- * @param {string} params.eventUrl - The URL to which the event is sent.
35
- * @returns {Promise<void>} - A promise that resolves when the event is fired.
36
- */
37
- private fireEvent;
38
- /**
39
- * Extracts and decodes a URL from a base64-encoded query parameter.
40
- *
41
- * @param {string} url - The URL containing the base64-encoded query parameter.
42
- * @returns {string} - The decoded URL or an empty string if decoding fails.
43
- */
44
- private getRedirectUrlFromPayload;
45
30
  }
@@ -1,4 +1,3 @@
1
1
  export * from './event.constant';
2
2
  export * from './event.interface';
3
3
  export * from './event.service';
4
- export * from './helpers';
@@ -1,3 +1,4 @@
1
1
  export * from './intersection.service';
2
2
  export * from './localstorage.service';
3
+ export * from './pubsub.service';
3
4
  export * from './resize.service';
@@ -1,6 +1,6 @@
1
1
  export declare class IntersectionObserverService {
2
2
  private observers;
3
- private defaultOptions;
3
+ private readonly defaultOptions;
4
4
  constructor(defaultOptions?: IntersectionObserverInit);
5
5
  observe(element: HTMLElement, callback: (entry: IntersectionObserverEntry) => void, options?: IntersectionObserverInit): void;
6
6
  unobserve(element: HTMLElement): void;
@@ -0,0 +1,56 @@
1
+ import type { RMN_SPOT_TYPE } from 'enums';
2
+ import type { ISpotEvent } from 'modules/selection';
3
+ export interface ILocalStorageSpot {
4
+ placementId: string;
5
+ spotId: string;
6
+ spotType: RMN_SPOT_TYPE;
7
+ events: ISpotEvent[];
8
+ productIds: Array<string | number>;
9
+ createdAt?: number;
10
+ }
11
+ export type LocalStorageSpotsMapType = Map<string, // spotId
12
+ ILocalStorageSpot>;
13
+ export type LocalStorageSpotsObjectType = Record<string, // spotId
14
+ ILocalStorageSpot>;
15
+ export type LocalStorageSpotArray = [
16
+ string,
17
+ string,
18
+ RMN_SPOT_TYPE,
19
+ ISpotEvent[],
20
+ Array<string | number>,
21
+ // PRODUCT_IDS = 4
22
+ number | undefined
23
+ ];
24
+ export declare enum ENUM_LOCAL_STORAGE_SPOT_ARRAY_INDEX {
25
+ PLACEMENT_ID = 0,
26
+ SPOT_ID = 1,
27
+ SPOT_TYPE = 2,
28
+ EVENTS = 3,
29
+ PRODUCT_IDS = 4,
30
+ CREATED_AT = 5
31
+ }
32
+ export type LocalStorageSpotsArrayType = Record<string, // spotId
33
+ LocalStorageSpotArray>;
34
+ export declare class LocalStorageService {
35
+ private spots?;
36
+ private static instance;
37
+ private static readonly localStorageKey;
38
+ private static readonly spotExpirationTime;
39
+ private static readonly encryptData;
40
+ private constructor();
41
+ static getInstance(): LocalStorageService;
42
+ private syncLocalStorage;
43
+ setSpot(spotId: string, data: ILocalStorageSpot): void;
44
+ removeSpot(spotId: string): void;
45
+ getSpot(spotId: string): ILocalStorageSpot | undefined;
46
+ getSpots(): LocalStorageSpotsObjectType | undefined;
47
+ private updateLocalStorage;
48
+ private clearLocalStorage;
49
+ private removeExpiredSpots;
50
+ private mapToObject;
51
+ private objectToMap;
52
+ private objectToArray;
53
+ private arrayToObject;
54
+ private encryptData;
55
+ private decryptData;
56
+ }
@@ -8,13 +8,13 @@ export type PubSubCallback<T> = (data: T) => void;
8
8
  */
9
9
  export type PubSubUnsubscribe = () => void;
10
10
  /**
11
- * PubSub class
11
+ * PubsubService class
12
12
  * Manages event subscriptions and publications
13
- * @template IEventMap A record type defining the structure of events and their data
13
+ * @template IRmnEventMap A record type defining the structure of events and their data
14
14
  */
15
- export declare class PubSub<IEventMap> {
15
+ export declare class PubsubService<IRmnEventMap> {
16
16
  private static instance;
17
- static getInstance<IEventMap>(): PubSub<IEventMap>;
17
+ static getInstance<IRmnEventMap>(): PubsubService<IRmnEventMap>;
18
18
  /**
19
19
  * Object to store subscribers for each event type
20
20
  */
@@ -30,7 +30,7 @@ export declare class PubSub<IEventMap> {
30
30
  * console.log(`User ${data.username} logged in`);
31
31
  * });
32
32
  */
33
- subscribe<K extends keyof IEventMap>(eventType: K, callback: PubSubCallback<IEventMap[K]>): PubSubUnsubscribe;
33
+ subscribe<K extends keyof IRmnEventMap>(eventType: K, callback: PubSubCallback<IRmnEventMap[K]>): PubSubUnsubscribe;
34
34
  /**
35
35
  * Publish an event
36
36
  * @param eventType - The type of event to publish
@@ -39,17 +39,17 @@ export declare class PubSub<IEventMap> {
39
39
  * @Example:
40
40
  * pubSub.publish('userLogin', { username: 'john_doe', timestamp: Date.now() });
41
41
  */
42
- publish<K extends keyof IEventMap>(eventType: K, data: IEventMap[K]): void;
42
+ publish<K extends keyof IRmnEventMap>(eventType: K, data: IRmnEventMap[K]): void;
43
43
  }
44
44
  /**
45
45
  * Usage Example:
46
46
  *
47
- * interface IEventMap {
47
+ * interface IRmnEventMap {
48
48
  * userLogin: { username: string; timestamp: number };
49
49
  * pageView: { url: string; timestamp: number };
50
50
  * }
51
51
  *
52
- * const pubSub = new PubSub<IEventMap>();
52
+ * const pubSub = new PubsubService<IRmnEventMap>();
53
53
  *
54
54
  * // Subscribe to events
55
55
  * const unsubscribeLogin = pubSub.subscribe('userLogin', (data) => {
@@ -18,7 +18,7 @@ export interface ISizeChangedEvent extends CustomEvent {
18
18
  }
19
19
  export declare class ResizeObserverService {
20
20
  private element;
21
- private container;
21
+ private readonly container;
22
22
  private resizeObserver;
23
23
  private maxSize;
24
24
  private minSize;
@@ -0,0 +1,2 @@
1
+ export * from './monitor.interface';
2
+ export * from './monitor.service';
@@ -0,0 +1,4 @@
1
+ export declare enum AnalyticsTool {
2
+ GoogleAnalytics = "google-analytics",
3
+ Other = "Other"
4
+ }
@@ -0,0 +1,11 @@
1
+ import type { RMN_SPOT_EVENT } from 'enums';
2
+ export interface INormalizedEventData {
3
+ event: RMN_SPOT_EVENT;
4
+ productIds: Array<string | number>;
5
+ }
6
+ export interface IFireAndPublishSpotEventParams {
7
+ spotEvent: RMN_SPOT_EVENT;
8
+ eventUrl: string;
9
+ placementId: string;
10
+ spotId: string;
11
+ }
@@ -0,0 +1,12 @@
1
+ export declare class MonitorService {
2
+ private static instance;
3
+ private readonly implementedMonitor?;
4
+ private readonly pubSubService?;
5
+ private readonly localStorageService?;
6
+ private constructor();
7
+ static getInstance(): MonitorService;
8
+ start(): void;
9
+ private matchAndFireEvent;
10
+ private fireAndPublishSpotEvent;
11
+ private detectAnalyticsTool;
12
+ }
@@ -0,0 +1,12 @@
1
+ import type { INormalizedEventData } from '../monitor.interface';
2
+ export declare class DataLayerMonitor {
3
+ private static instance;
4
+ private readonly originalPush;
5
+ private listener?;
6
+ private constructor();
7
+ static getInstance(): DataLayerMonitor;
8
+ setListener(listener: (data: INormalizedEventData) => void): void;
9
+ start(): void;
10
+ private cleanEventData;
11
+ stop(): void;
12
+ }
@@ -30,7 +30,9 @@ export interface ISpot {
30
30
  mobilePrimaryImage?: string;
31
31
  mobileSecondaryImage?: string;
32
32
  productIds?: Array<string | number>;
33
- productUpcs?: string[];
33
+ rbProductUpcs?: Array<string | number>;
34
+ rbProductSalsifyGroupings?: Array<string | number>;
35
+ rbProductSalsifyPids?: Array<string | number>;
34
36
  }
35
37
  export type ISpots = Record<PlacementIdType, ISpot[]>;
36
38
  export interface ISelectionService {
@@ -14,7 +14,7 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
14
14
  *
15
15
  * @param {ISpotSelectionParams} params - Spots selection parameters.
16
16
  *
17
- * @return {Promise<ISpots | {error : string}>} - The spots response object.
17
+ * @return {Promise<ISpots | { error : string }>} - The spots response object.
18
18
  */
19
19
  spotSelection(params: ISpotSelectionParams): Promise<ISpots | {
20
20
  error: string;
@@ -1,10 +1,11 @@
1
- import type { IEventMap } from './modules/event';
2
1
  export type { IInjectSpotElement, IInjectSpotElementConfig, IInjectSpotElementParams, IRmnCreateSpotElementConfig, ISpotColors, ISpotOverlay, } from 'modules/element';
3
2
  export type { CarouselNavPositionType, ICarouselButtonOptions, ICarouselDotOptions, ICarouselOptions, } from 'modules/element/component/carousel';
3
+ export type { ILifecycleState, ILSDisplayConfig, ILSDom, ILSIdentifier, ILSState, IRmnEventMap, IRmnSpotEvent, } from 'modules/event';
4
4
  export type { ISpots, RmnFilterType, RmnSpotType } from 'modules/selection';
5
5
  export { ISpot, ISpotEvent, ISpotSelectionParams } from 'modules/selection';
6
- import type { RMN_ENV, RMN_SPOT_EVENT } from 'enums';
6
+ import type { RMN_ENV, RMN_EVENT } from 'enums';
7
7
  import type { IInjectSpotElementParams } from 'modules/element';
8
+ import type { IRmnEventMap } from 'modules/event';
8
9
  import type { ISpots, ISpotSelectionParams } from 'modules/selection';
9
10
  export interface IRmnClient {
10
11
  spotSelection(params: ISpotSelectionParams): Promise<ISpots | {
@@ -13,8 +14,8 @@ export interface IRmnClient {
13
14
  injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
14
15
  }
15
16
  export interface IRmnEventManager {
16
- subscribe: (eventType: RMN_SPOT_EVENT, callback: (data: IEventMap[RMN_SPOT_EVENT]) => void) => () => void;
17
- publish: (eventType: RMN_SPOT_EVENT, data: IEventMap[RMN_SPOT_EVENT]) => void;
17
+ subscribe: (eventType: RMN_EVENT, callback: (data: IRmnEventMap[RMN_EVENT]) => void) => () => void;
18
+ publish: (eventType: RMN_EVENT, data: IRmnEventMap[RMN_EVENT]) => void;
18
19
  destroySpot: (placementId: string) => void;
19
20
  }
20
21
  export interface IRmnConfig {
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.1",
5
+ "version": "1.5.0-beta.11",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",