@liquidcommercedev/rmn-sdk 1.5.0-beta.2 → 1.5.0-beta.20
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +2710 -946
- package/dist/index.esm.js +2711 -947
- package/dist/types/common/helpers/event-type.helper.d.ts +8 -0
- package/dist/types/common/helpers/extract-deep.helper.d.ts +28 -0
- package/dist/types/common/helpers/index.d.ts +5 -0
- package/dist/types/common/helpers/utils.helper.d.ts +35 -0
- package/dist/types/enums.d.ts +8 -1
- package/dist/types/modules/element/component/skeleton/index.d.ts +2 -0
- package/dist/types/modules/element/component/skeleton/skeleton.component.d.ts +3 -0
- package/dist/types/modules/element/component/skeleton/skeleton.interface.d.ts +13 -0
- package/dist/types/modules/element/component/skeleton/skeleton.template.d.ts +2 -0
- package/dist/types/modules/element/element.constant.d.ts +3 -0
- package/dist/types/modules/element/element.interface.d.ts +5 -2
- package/dist/types/modules/element/element.service.d.ts +11 -0
- package/dist/types/modules/element/template/helper.d.ts +2 -1
- package/dist/types/modules/event/event.interface.d.ts +11 -32
- package/dist/types/modules/event/event.service.d.ts +11 -27
- package/dist/types/modules/event/index.d.ts +0 -1
- package/dist/types/modules/{event/helpers → helper-service}/index.d.ts +1 -0
- package/dist/types/modules/{event/helpers → helper-service}/intersection.service.d.ts +1 -1
- package/dist/types/modules/helper-service/localstorage.service.d.ts +77 -0
- package/dist/types/modules/{event/pubsub.d.ts → helper-service/pubsub.service.d.ts} +8 -8
- package/dist/types/modules/{event/helpers → helper-service}/resize.service.d.ts +1 -1
- package/dist/types/modules/monitor/index.d.ts +2 -0
- package/dist/types/modules/monitor/monitor.enums.d.ts +4 -0
- package/dist/types/modules/monitor/monitor.interface.d.ts +16 -0
- package/dist/types/modules/monitor/monitor.service.d.ts +12 -0
- package/dist/types/modules/monitor/monitors/datalayer.monitor.d.ts +12 -0
- package/dist/types/modules/selection/selection.interface.d.ts +10 -2
- package/dist/types/modules/selection/selection.service.d.ts +1 -0
- package/dist/types/rmn-client.d.ts +17 -25
- package/dist/types/rmn-client.helper.d.ts +41 -0
- package/dist/types/types.d.ts +5 -4
- package/package.json +1 -1
- package/umd/liquidcommerce-rmn-sdk.min.js +1 -1
- package/dist/types/modules/element/component/utils.d.ts +0 -1
- package/dist/types/modules/event/helpers/localstorage.service.d.ts +0 -26
- /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;
|
@@ -0,0 +1,28 @@
|
|
1
|
+
type ExtractorTarget = 'ids' | 'price';
|
2
|
+
type ExtractedValue = string | number;
|
3
|
+
/**
|
4
|
+
* Extracts deep values from an object based on specified target type
|
5
|
+
* @param data - The source data object to extract values from
|
6
|
+
* @param target - The type of values to extract ('ids' or 'price')
|
7
|
+
* @param options - Optional configuration for the extraction process
|
8
|
+
* @returns Array of extracted values or a single value if onlyFirst is true
|
9
|
+
*/
|
10
|
+
export declare function extractDeepValues(data: unknown, target: ExtractorTarget, options?: {
|
11
|
+
onlyFirst?: boolean;
|
12
|
+
shouldIncludeZero?: boolean;
|
13
|
+
}): ExtractedValue[] | ExtractedValue | undefined;
|
14
|
+
/**
|
15
|
+
* Cleans and normalizes an array of product IDs by:
|
16
|
+
* 1. Converting all IDs to strings
|
17
|
+
* 2. Trimming whitespace
|
18
|
+
* 3. Removing leading zeros while preserving single "0"
|
19
|
+
* 4. Filtering out empty/invalid values
|
20
|
+
*
|
21
|
+
* @param productIds - Array of product IDs that can be either strings or numbers
|
22
|
+
* @returns Array of cleaned string IDs
|
23
|
+
*
|
24
|
+
* @example
|
25
|
+
* cleanProductIds(["001", " 123 ", 456, "0"]) // ["1", "123", "456", "0"]
|
26
|
+
*/
|
27
|
+
export declare function cleanProductIds(productIds: Array<string | number>): string[];
|
28
|
+
export {};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import type { IFireEventParams } from 'modules/event';
|
2
|
+
export declare function fallbackEventFire(url: string): Promise<boolean>;
|
3
|
+
/**
|
4
|
+
* Helper function to decode base64 string and parse JSON
|
5
|
+
*
|
6
|
+
* @param {string} base64String - The base64 encoded JSON string
|
7
|
+
* @returns {T | null} - Decoded and parsed object or null if invalid
|
8
|
+
*/
|
9
|
+
export declare function decodeBase64Json<T>(base64String: string): T | null;
|
10
|
+
/**
|
11
|
+
* Extracts and decodes a URL from a base64-encoded query parameter.
|
12
|
+
*
|
13
|
+
* @param {string} url - The URL containing the base64-encoded query parameter.
|
14
|
+
* @returns {string | null} - The decoded URL or null if not found or invalid.
|
15
|
+
* @throws {Error} - If URL is malformed or payload is invalid.
|
16
|
+
*/
|
17
|
+
export declare function getRedirectUrlFromPayload(url: string): string | null;
|
18
|
+
/**
|
19
|
+
* Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
|
20
|
+
* If the event is a click event and a redirect URL is found, it redirects the user to that URL.
|
21
|
+
*
|
22
|
+
* @param {IFireEventParams} params - The parameters for firing the event.
|
23
|
+
* @param {RMN_SPOT_EVENT} params.event - The event type.
|
24
|
+
* @param {string} params.eventUrl - The URL to which the event is sent.
|
25
|
+
* @returns {Promise<void>} - A promise that resolves when the event is fired.
|
26
|
+
*/
|
27
|
+
export declare function fireEvent({ event, eventUrl }: IFireEventParams): Promise<void>;
|
28
|
+
export declare function calculateScaleFactor(elementScale: number): number;
|
29
|
+
/**
|
30
|
+
* Converts an object to a query string.
|
31
|
+
*
|
32
|
+
* @param {Record<string, string|number|undefined|null>} obj - The object to be converted to a query string.
|
33
|
+
* @returns {string} - The query string.
|
34
|
+
*/
|
35
|
+
export declare function objectToQueryParams(obj?: Record<string, string | number | undefined | null>): string;
|
package/dist/types/enums.d.ts
CHANGED
@@ -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
|
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 {
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import type { RMN_SPOT_TYPE } from 'enums';
|
2
|
+
export interface ICustomSkeletonElementData {
|
3
|
+
fluid: boolean;
|
4
|
+
width: number;
|
5
|
+
height: number;
|
6
|
+
}
|
7
|
+
export interface ICustomSkeletonElement extends HTMLElement {
|
8
|
+
data: ICustomSkeletonElementData;
|
9
|
+
}
|
10
|
+
export interface ICreateSkeletonElementParams {
|
11
|
+
fluid: boolean;
|
12
|
+
spotType: RMN_SPOT_TYPE;
|
13
|
+
}
|
@@ -1,5 +1,8 @@
|
|
1
|
+
import type { SpotDimensionsType } from 'modules/selection';
|
1
2
|
export declare const SPOT_ELEMENT_TAG = "spot-element";
|
2
3
|
export declare const CAROUSEL_ELEMENT_TAG = "spot-carousel-element";
|
4
|
+
export declare const SKELETON_ELEMENT_TAG = "spot-skeleton-element";
|
3
5
|
export declare const GFONT_PRECONNECT = "\n <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n";
|
4
6
|
export declare const GFONT_SOURCE_SANS_3 = "\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css2?family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap\">\n";
|
5
7
|
export declare const GFONT_CORMORANT = "\n <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css2?family=Cormorant:ital,wght@0,300..700;1,300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap\">\n";
|
8
|
+
export declare const SPOT_DIMENSIONS: SpotDimensionsType;
|
@@ -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?:
|
32
|
+
filter?: IInjectSpotElementFilterType;
|
30
33
|
}
|
31
34
|
export interface ICreateElementConfig {
|
32
35
|
spot?: RMN_SPOT_TYPE;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { ISpot } from 'modules/selection';
|
2
2
|
import type { ICreateCarouselElementParams } from './component/carousel';
|
3
|
+
import type { ICreateSkeletonElementParams } from './component/skeleton';
|
3
4
|
import type { ICreateSpotElementParams } from './component/spot';
|
4
5
|
import type { IElementService, ISpotColors } from './element.interface';
|
5
6
|
export declare class ElementService implements IElementService {
|
@@ -24,6 +25,16 @@ export declare class ElementService implements IElementService {
|
|
24
25
|
* @return {HTMLElement | null} - The html element or null if the browser environment is not available.
|
25
26
|
*/
|
26
27
|
createCarouselElement({ slides, config, }: ICreateCarouselElementParams): HTMLElement | null;
|
28
|
+
/**
|
29
|
+
* Creates the skeleton html element based on the provided data using shadow dom.
|
30
|
+
*
|
31
|
+
* This method is only available in browser environments.
|
32
|
+
*
|
33
|
+
* @param {ICreateSkeletonElementParams} params - The parameters to create the final element.
|
34
|
+
*
|
35
|
+
* @return {HTMLElement | null} - The html element or null if the browser environment is not available.
|
36
|
+
*/
|
37
|
+
createSkeletonElement(params: ICreateSkeletonElementParams): HTMLElement | null;
|
27
38
|
/**
|
28
39
|
* Overrides the spot colors with the provided colors.
|
29
40
|
*
|
@@ -1,4 +1,5 @@
|
|
1
|
+
import type { RMN_SPOT_TYPE } from 'enums';
|
1
2
|
import type { ISpotOverlay } from '../element.interface';
|
2
3
|
export declare function convertHexToRgba(hex: string, opacity?: number): string;
|
3
4
|
export declare function generateGradientColor(overlay?: ISpotOverlay, fallback?: string): string;
|
4
|
-
export declare function spotHtmlStringToElement(htmlString: string): HTMLElement;
|
5
|
+
export declare function spotHtmlStringToElement(htmlString: string, spotType: RMN_SPOT_TYPE): HTMLElement;
|
@@ -1,5 +1,10 @@
|
|
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
|
+
export type ActiveSpotsType = Map<string, // spotId
|
4
|
+
{
|
5
|
+
placementId: string;
|
6
|
+
spotElement: HTMLElement;
|
7
|
+
}>;
|
3
8
|
export interface IFireEventParams {
|
4
9
|
event: RMN_SPOT_EVENT;
|
5
10
|
eventUrl: string;
|
@@ -30,40 +35,14 @@ export interface ILifecycleState {
|
|
30
35
|
state?: Partial<ILSState>;
|
31
36
|
displayConfig?: Partial<ILSDisplayConfig>;
|
32
37
|
}
|
33
|
-
export interface
|
34
|
-
|
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 {
|
38
|
+
export interface IRmnSpotEvent {
|
39
|
+
eventType: RMN_SPOT_EVENT;
|
56
40
|
placementId: string;
|
57
41
|
spotId: string;
|
58
42
|
}
|
59
|
-
export interface
|
60
|
-
[
|
61
|
-
[
|
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;
|
43
|
+
export interface IRmnEventMap {
|
44
|
+
[RMN_EVENT.LIFECYCLE_STATE]: ILifecycleState;
|
45
|
+
[RMN_EVENT.SPOT_EVENT]: IRmnSpotEvent;
|
67
46
|
}
|
68
47
|
export interface IRegisterSpotParams {
|
69
48
|
placementId: string;
|
@@ -1,16 +1,16 @@
|
|
1
|
-
import {
|
2
|
-
import type {
|
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
|
6
|
-
private
|
5
|
+
private pubSubService;
|
6
|
+
private localStorageService;
|
7
7
|
private intersectionObserver;
|
8
8
|
private spotStates;
|
9
|
-
private activeSpots;
|
9
|
+
private readonly activeSpots;
|
10
10
|
private constructor();
|
11
11
|
static getInstance(): EventService;
|
12
|
-
subscribe(eventType:
|
13
|
-
publish(eventType:
|
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,25 +23,9 @@ export declare class EventService {
|
|
23
23
|
* @returns {void}
|
24
24
|
*/
|
25
25
|
handleSpotState(placementId: string, updates: Partial<ILifecycleState>, publish?: boolean): void;
|
26
|
-
private
|
26
|
+
private handleClickEvent;
|
27
|
+
private handleImpressionEvent;
|
28
|
+
private getSpotIdByPlacementId;
|
29
|
+
private deepMerge;
|
27
30
|
private handleIntersectionObserver;
|
28
|
-
private fireImpressionEvent;
|
29
|
-
/**
|
30
|
-
* Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
|
31
|
-
* If the event is a click event and a redirect URL is found, it redirects the user to that URL.
|
32
|
-
*
|
33
|
-
* @param {IFireEventParams} params - The parameters for firing the event.
|
34
|
-
* @param {RMN_SPOT_EVENT} params.event - The event type.
|
35
|
-
* @param {string} params.eventUrl - The URL to which the event is sent.
|
36
|
-
* @returns {Promise<void>} - A promise that resolves when the event is fired.
|
37
|
-
*/
|
38
|
-
private fireEvent;
|
39
|
-
private fallbackEventFire;
|
40
|
-
/**
|
41
|
-
* Extracts and decodes a URL from a base64-encoded query parameter.
|
42
|
-
*
|
43
|
-
* @param {string} url - The URL containing the base64-encoded query parameter.
|
44
|
-
* @returns {string | null} - The decoded URL or null if not found or invalid.
|
45
|
-
*/
|
46
|
-
private getRedirectUrlFromPayload;
|
47
31
|
}
|
@@ -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,77 @@
|
|
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
|
+
string[],
|
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 declare const LOCAL_STORAGE_SPOT_EVENTS_ARRAY_INDEX: {
|
33
|
+
readonly IMPRESSION: 0;
|
34
|
+
readonly CLICK: 1;
|
35
|
+
readonly PURCHASE: 2;
|
36
|
+
readonly ADD_TO_CART: 3;
|
37
|
+
readonly REMOVE_FROM_CART: 4;
|
38
|
+
readonly ADD_TO_CART_FROM_DETAILS: 5;
|
39
|
+
readonly ADD_TO_WISHLIST: 6;
|
40
|
+
readonly EXPAND_PRODUCT: 7;
|
41
|
+
readonly BUY_NOW: 8;
|
42
|
+
};
|
43
|
+
export type LocalStorageSpotsArrayType = Record<string, // spotId
|
44
|
+
LocalStorageSpotArray>;
|
45
|
+
export declare class LocalStorageService {
|
46
|
+
private spots?;
|
47
|
+
private static instance;
|
48
|
+
private static readonly localStorageKeyPrefix;
|
49
|
+
private static localStorageKey;
|
50
|
+
private static readonly spotExpirationTime;
|
51
|
+
private static readonly encryptData;
|
52
|
+
private constructor();
|
53
|
+
static getInstance(): LocalStorageService;
|
54
|
+
private syncLocalStorage;
|
55
|
+
setSpot(spotId: string, data: ILocalStorageSpot): void;
|
56
|
+
removeSpot(spotId: string): void;
|
57
|
+
getSpot(spotId: string): ILocalStorageSpot | undefined;
|
58
|
+
getSpots(): LocalStorageSpotsObjectType | undefined;
|
59
|
+
private updateLocalStorage;
|
60
|
+
private clearLocalStorage;
|
61
|
+
private removeExpiredSpots;
|
62
|
+
getUserId(): string;
|
63
|
+
/**
|
64
|
+
* Sets the user ID in the local storage.
|
65
|
+
* If no existing key is found,
|
66
|
+
* it generates a new unique ID and sets it as the local storage key.
|
67
|
+
*/
|
68
|
+
setUserId(): void;
|
69
|
+
private mapToObject;
|
70
|
+
private objectToMap;
|
71
|
+
private spotEventObjectToArray;
|
72
|
+
private spotEventArrayToObject;
|
73
|
+
private spotObjectToArray;
|
74
|
+
private spotArrayToObject;
|
75
|
+
private encryptData;
|
76
|
+
private decryptData;
|
77
|
+
}
|
@@ -8,13 +8,13 @@ export type PubSubCallback<T> = (data: T) => void;
|
|
8
8
|
*/
|
9
9
|
export type PubSubUnsubscribe = () => void;
|
10
10
|
/**
|
11
|
-
*
|
11
|
+
* PubsubService class
|
12
12
|
* Manages event subscriptions and publications
|
13
|
-
* @template
|
13
|
+
* @template IRmnEventMap A record type defining the structure of events and their data
|
14
14
|
*/
|
15
|
-
export declare class
|
15
|
+
export declare class PubsubService<IRmnEventMap> {
|
16
16
|
private static instance;
|
17
|
-
static getInstance<
|
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
|
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
|
42
|
+
publish<K extends keyof IRmnEventMap>(eventType: K, data: IRmnEventMap[K]): void;
|
43
43
|
}
|
44
44
|
/**
|
45
45
|
* Usage Example:
|
46
46
|
*
|
47
|
-
* interface
|
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
|
52
|
+
* const pubSub = new PubsubService<IRmnEventMap>();
|
53
53
|
*
|
54
54
|
* // Subscribe to events
|
55
55
|
* const unsubscribeLogin = pubSub.subscribe('userLogin', (data) => {
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { RMN_SPOT_EVENT } from 'enums';
|
2
|
+
export interface IDataLayerEvent {
|
3
|
+
event: string;
|
4
|
+
[key: string]: any;
|
5
|
+
}
|
6
|
+
export interface INormalizedEventData {
|
7
|
+
event: RMN_SPOT_EVENT;
|
8
|
+
productIds: Array<string | number>;
|
9
|
+
productPrice?: number;
|
10
|
+
}
|
11
|
+
export interface IFireAndPublishSpotEventParams {
|
12
|
+
spotEvent: RMN_SPOT_EVENT;
|
13
|
+
eventUrl: string;
|
14
|
+
placementId: string;
|
15
|
+
spotId: string;
|
16
|
+
}
|
@@ -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
|
+
}
|
@@ -2,14 +2,20 @@ import type { RMN_SPOT_EVENT, RMN_SPOT_TYPE } from 'enums';
|
|
2
2
|
import type { PlacementIdType, SpotVariantType } from 'modules/selection';
|
3
3
|
import type { RmnFilterType, RmnSpotType } from 'types';
|
4
4
|
export interface ISpotSelectionParams {
|
5
|
-
url?: string;
|
6
5
|
spots: RmnSpotType[];
|
7
6
|
filter?: Partial<RmnFilterType>;
|
7
|
+
userId?: string;
|
8
|
+
url?: string;
|
8
9
|
}
|
9
10
|
export interface ISpotEvent {
|
10
11
|
event: RMN_SPOT_EVENT;
|
11
12
|
url: string;
|
12
13
|
}
|
14
|
+
export interface ISpotEventPayload {
|
15
|
+
e: number;
|
16
|
+
u: string;
|
17
|
+
ss: string;
|
18
|
+
}
|
13
19
|
export interface ISpot {
|
14
20
|
id: string;
|
15
21
|
events: ISpotEvent[];
|
@@ -30,7 +36,9 @@ export interface ISpot {
|
|
30
36
|
mobilePrimaryImage?: string;
|
31
37
|
mobileSecondaryImage?: string;
|
32
38
|
productIds?: Array<string | number>;
|
33
|
-
|
39
|
+
rbProductUpcs?: Array<string | number>;
|
40
|
+
rbProductSalsifyGroupings?: Array<string | number>;
|
41
|
+
rbProductSalsifyPids?: Array<string | number>;
|
34
42
|
}
|
35
43
|
export type ISpots = Record<PlacementIdType, ISpot[]>;
|
36
44
|
export interface ISelectionService {
|
@@ -2,10 +2,16 @@ import type { IAuthCredentials } from 'modules/auth';
|
|
2
2
|
import type { IInjectSpotElementParams, IRmnCreateSpotElementConfig } from 'modules/element';
|
3
3
|
import type { ISpot, ISpots, ISpotSelectionParams } from 'modules/selection';
|
4
4
|
import type { IRmnClient, IRmnConfig, IRmnEventManager } from 'types';
|
5
|
+
/**
|
6
|
+
* LiquidCommerce Rmn Client
|
7
|
+
*
|
8
|
+
* @class
|
9
|
+
*/
|
5
10
|
export declare class LiquidCommerceRmnClient implements IRmnClient {
|
6
11
|
private readonly selectionService;
|
7
12
|
private readonly elementService;
|
8
13
|
private readonly eventService;
|
14
|
+
private intersectionObserver;
|
9
15
|
constructor(auth: IAuthCredentials);
|
10
16
|
/**
|
11
17
|
* Makes a selection request on our server based on the provided data.
|
@@ -14,7 +20,7 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
14
20
|
*
|
15
21
|
* @param {ISpotSelectionParams} params - Spots selection parameters.
|
16
22
|
*
|
17
|
-
* @return {Promise<ISpots | {error : string}>} - The spots response object.
|
23
|
+
* @return {Promise<ISpots | { error : string }>} - The spots response object.
|
18
24
|
*/
|
19
25
|
spotSelection(params: ISpotSelectionParams): Promise<ISpots | {
|
20
26
|
error: string;
|
@@ -28,47 +34,33 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
28
34
|
*/
|
29
35
|
injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
|
30
36
|
/**
|
31
|
-
*
|
32
|
-
*
|
33
|
-
* @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
|
34
|
-
*
|
35
|
-
* @return {Promise<ISpots | {error: string}>} - The spots response object.
|
36
|
-
*/
|
37
|
-
private spotSelectionRequest;
|
38
|
-
/**
|
39
|
-
* Injects a carousel element with the provided spots into the placement.
|
37
|
+
* Injects a single spot element into the provided placement.
|
40
38
|
*
|
41
39
|
* @param {HTMLElement} placement - The placement element.
|
42
|
-
* @param {ISpot
|
40
|
+
* @param {ISpot} spot - The spot data.
|
43
41
|
* @param {IInjectSpotElementConfig} config - The configuration object.
|
44
42
|
*
|
45
43
|
* @return {void}
|
46
44
|
*/
|
47
|
-
private
|
45
|
+
private injectOneSpotElement;
|
48
46
|
/**
|
49
|
-
* Injects a
|
47
|
+
* Injects a carousel element with the provided spots into the placement.
|
50
48
|
*
|
51
|
-
* @param {IInjectSpotElement} injectItem - The inject item data.
|
52
49
|
* @param {HTMLElement} placement - The placement element.
|
53
|
-
* @param {ISpot}
|
50
|
+
* @param {ISpot[]} spots - The spot data.
|
54
51
|
* @param {IInjectSpotElementConfig} config - The configuration object.
|
55
52
|
*
|
56
53
|
* @return {void}
|
57
54
|
*/
|
58
|
-
private
|
55
|
+
private injectCarouselSpotElement;
|
59
56
|
/**
|
60
|
-
*
|
61
|
-
*
|
62
|
-
* @param {IInjectSpotElement[]} inject - The inject data.
|
57
|
+
* Makes a selection request on our server based on the provided data.
|
63
58
|
*
|
64
|
-
* @
|
59
|
+
* @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
|
65
60
|
*
|
66
|
-
* @return {
|
61
|
+
* @return {Promise<ISpots | {error: string}>} - The spots response object.
|
67
62
|
*/
|
68
|
-
private
|
69
|
-
private preventNonExistentSpotTypes;
|
70
|
-
private updateSpotsState;
|
71
|
-
private useSpotSelectionExample;
|
63
|
+
private injectSpotSelectionRequest;
|
72
64
|
}
|
73
65
|
/**
|
74
66
|
* Creates a new instance of the RmnClient.
|