@liquidcommercedev/rmn-sdk 1.5.0-beta.7 → 1.5.0-beta.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +385 -293
- package/dist/index.esm.js +386 -294
- package/dist/types/common/helpers/utils.helper.d.ts +50 -0
- package/dist/types/enums.d.ts +4 -1
- package/dist/types/modules/event/event.interface.d.ts +6 -36
- package/dist/types/modules/event/event.service.d.ts +5 -23
- package/dist/types/modules/event/index.d.ts +0 -2
- package/dist/types/modules/{event/helpers → helper-service}/index.d.ts +1 -1
- package/dist/types/modules/{event/helpers → helper-service}/localstorage.service.d.ts +2 -2
- package/dist/types/modules/{event/pubsub.d.ts → helper-service/pubsub.service.d.ts} +4 -4
- 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 +12 -0
- package/dist/types/modules/monitor/monitor.service.d.ts +12 -0
- package/dist/types/modules/{event/helpers → monitor/monitors}/datalayer.monitor.d.ts +1 -10
- package/dist/types/types.d.ts +4 -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/utils.d.ts +0 -24
- package/dist/types/modules/event/user.monitor.d.ts +0 -14
- /package/dist/types/modules/{event/helpers → helper-service}/intersection.service.d.ts +0 -0
- /package/dist/types/modules/{event/helpers → helper-service}/resize.service.d.ts +0 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
import { RMN_SPOT_EVENT } from 'enums';
|
2
|
+
import type { IFireEventParams } from 'modules/event';
|
3
|
+
export interface IExtractIdsProps {
|
4
|
+
id?: string | number;
|
5
|
+
upc?: string | number;
|
6
|
+
[key: string]: string | number | undefined;
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* Determines the event type from a raw event string.
|
10
|
+
*
|
11
|
+
* @param {string} [event] - The raw event string to evaluate.
|
12
|
+
* @returns {RMN_SPOT_EVENT | null} - The corresponding RMN_SPOT_EVENT or null if no match is found.
|
13
|
+
*/
|
14
|
+
export declare function getEventTypeFromRawEvent(event?: string): RMN_SPOT_EVENT | null;
|
15
|
+
/**
|
16
|
+
* Recursively extracts ID values from a nested data structure.
|
17
|
+
* Searches for specified property names and collects their primitive values (strings/numbers).
|
18
|
+
*
|
19
|
+
* @param data - The data structure to search through (can be nested objects/arrays)
|
20
|
+
* @param propertyNames - Array of property names to look for
|
21
|
+
* @returns Array of extracted ID values (strings/numbers only)
|
22
|
+
*
|
23
|
+
* @example
|
24
|
+
* const data = {
|
25
|
+
* id: [1, 2, 3],
|
26
|
+
* nested: { id: 'abc' },
|
27
|
+
* items: [{ id: 456 }]
|
28
|
+
* };
|
29
|
+
* extractDeepIds(data); // Returns [1, 2, 3, 'abc', 456]
|
30
|
+
*/
|
31
|
+
export declare function extractDeepIds(data: any, propertyNames?: string[]): Array<string | number>;
|
32
|
+
export declare function fallbackEventFire(url: string): Promise<boolean>;
|
33
|
+
/**
|
34
|
+
* Extracts and decodes a URL from a base64-encoded query parameter.
|
35
|
+
*
|
36
|
+
* @param {string} url - The URL containing the base64-encoded query parameter.
|
37
|
+
* @returns {string | null} - The decoded URL or null if not found or invalid.
|
38
|
+
*/
|
39
|
+
export declare function getRedirectUrlFromPayload(url: string): string | null;
|
40
|
+
/**
|
41
|
+
* Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
|
42
|
+
* If the event is a click event and a redirect URL is found, it redirects the user to that URL.
|
43
|
+
*
|
44
|
+
* @param {IFireEventParams} params - The parameters for firing the event.
|
45
|
+
* @param {RMN_SPOT_EVENT} params.event - The event type.
|
46
|
+
* @param {string} params.eventUrl - The URL to which the event is sent.
|
47
|
+
* @returns {Promise<void>} - A promise that resolves when the event is fired.
|
48
|
+
*/
|
49
|
+
export declare function fireEvent({ event, eventUrl }: IFireEventParams): Promise<void>;
|
50
|
+
export declare function calculateScaleFactor(elementScale: number): number;
|
package/dist/types/enums.d.ts
CHANGED
@@ -49,8 +49,11 @@ export declare enum RMN_FILTER_PROPERTIES {
|
|
49
49
|
PUBLISHERS = "publishers",
|
50
50
|
SECTION = "section"
|
51
51
|
}
|
52
|
-
export declare enum
|
52
|
+
export declare enum RMN_EVENT {
|
53
53
|
LIFECYCLE_STATE = "LIFECYCLE_STATE",
|
54
|
+
SPOT_EVENT = "SPOT_EVENT"
|
55
|
+
}
|
56
|
+
export declare enum RMN_SPOT_EVENT {
|
54
57
|
IMPRESSION = "IMPRESSION",
|
55
58
|
CLICK = "CLICK",
|
56
59
|
PURCHASE = "PURCHASE",
|
@@ -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,45 +30,15 @@ export interface ILifecycleState {
|
|
30
30
|
state?: Partial<ILSState>;
|
31
31
|
displayConfig?: Partial<ILSDisplayConfig>;
|
32
32
|
}
|
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 IRemoveFromCartEvent {
|
48
|
-
placementId: string;
|
49
|
-
spotId: string;
|
50
|
-
}
|
51
|
-
export interface IAddToWishlistEvent {
|
52
|
-
placementId: string;
|
53
|
-
spotId: string;
|
54
|
-
}
|
55
|
-
export interface IPurchaseEvent {
|
56
|
-
placementId: string;
|
57
|
-
spotId: string;
|
58
|
-
}
|
59
|
-
export interface IBuyNowEvent {
|
33
|
+
export interface IRmnSpotEvent {
|
34
|
+
eventType: RMN_SPOT_EVENT;
|
60
35
|
placementId: string;
|
61
36
|
spotId: string;
|
37
|
+
spotElement?: HTMLElement;
|
62
38
|
}
|
63
39
|
export interface IRmnEventMap {
|
64
|
-
[
|
65
|
-
[
|
66
|
-
[RMN_SPOT_EVENT.IMPRESSION]: IImpressionEvent;
|
67
|
-
[RMN_SPOT_EVENT.ADD_TO_CART]: IAddToCartEvent;
|
68
|
-
[RMN_SPOT_EVENT.REMOVE_FROM_CART]: IRemoveFromCartEvent;
|
69
|
-
[RMN_SPOT_EVENT.ADD_TO_WISHLIST]: IAddToWishlistEvent;
|
70
|
-
[RMN_SPOT_EVENT.PURCHASE]: IPurchaseEvent;
|
71
|
-
[RMN_SPOT_EVENT.BUY_NOW]: IBuyNowEvent;
|
40
|
+
[RMN_EVENT.LIFECYCLE_STATE]: ILifecycleState;
|
41
|
+
[RMN_EVENT.SPOT_EVENT]: IRmnSpotEvent;
|
72
42
|
}
|
73
43
|
export interface IRegisterSpotParams {
|
74
44
|
placementId: string;
|
@@ -1,16 +1,16 @@
|
|
1
|
-
import {
|
1
|
+
import { RMN_EVENT } from 'enums';
|
2
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
9
|
private 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
|
/**
|
@@ -27,22 +27,4 @@ export declare class EventService {
|
|
27
27
|
private handleClick;
|
28
28
|
private handleIntersectionObserver;
|
29
29
|
private fireImpressionEvent;
|
30
|
-
/**
|
31
|
-
* Fires an event using the navigator.sendBeacon method or a fallback method if sendBeacon is not available.
|
32
|
-
* If the event is a click event and a redirect URL is found, it redirects the user to that URL.
|
33
|
-
*
|
34
|
-
* @param {IFireEventParams} params - The parameters for firing the event.
|
35
|
-
* @param {RMN_SPOT_EVENT} params.event - The event type.
|
36
|
-
* @param {string} params.eventUrl - The URL to which the event is sent.
|
37
|
-
* @returns {Promise<void>} - A promise that resolves when the event is fired.
|
38
|
-
*/
|
39
|
-
private fireEvent;
|
40
|
-
private fallbackEventFire;
|
41
|
-
/**
|
42
|
-
* Extracts and decodes a URL from a base64-encoded query parameter.
|
43
|
-
*
|
44
|
-
* @param {string} url - The URL containing the base64-encoded query parameter.
|
45
|
-
* @returns {string | null} - The decoded URL or null if not found or invalid.
|
46
|
-
*/
|
47
|
-
private getRedirectUrlFromPayload;
|
48
30
|
}
|
@@ -28,13 +28,13 @@ export declare enum ENUM_LOCAL_STORAGE_SPOT_ARRAY_INDEX {
|
|
28
28
|
}
|
29
29
|
export type LocalStorageSpotsArrayType = Record<string, // spotId
|
30
30
|
LocalStorageSpotArray>;
|
31
|
-
export declare class
|
31
|
+
export declare class LocalStorageService {
|
32
32
|
private spots?;
|
33
33
|
private static instance;
|
34
34
|
private static readonly localStorageKey;
|
35
35
|
private static readonly spotExpirationTime;
|
36
36
|
private constructor();
|
37
|
-
static getInstance():
|
37
|
+
static getInstance(): LocalStorageService;
|
38
38
|
private syncLocalStorage;
|
39
39
|
setSpot(spotId: string, data: ILocalStorageSpot): void;
|
40
40
|
removeSpot(spotId: string): void;
|
@@ -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
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<IRmnEventMap>():
|
17
|
+
static getInstance<IRmnEventMap>(): PubsubService<IRmnEventMap>;
|
18
18
|
/**
|
19
19
|
* Object to store subscribers for each event type
|
20
20
|
*/
|
@@ -49,7 +49,7 @@ export declare class PubSub<IRmnEventMap> {
|
|
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,12 @@
|
|
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
|
+
spotElement?: HTMLElement;
|
12
|
+
}
|
@@ -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
|
+
}
|
@@ -1,13 +1,4 @@
|
|
1
|
-
import type {
|
2
|
-
export interface IDataLayerEvent {
|
3
|
-
event?: string;
|
4
|
-
value?: any[];
|
5
|
-
[key: string]: any;
|
6
|
-
}
|
7
|
-
export interface INormalizedEventData {
|
8
|
-
event: RMN_SPOT_EVENT;
|
9
|
-
productIds: Array<string | number>;
|
10
|
-
}
|
1
|
+
import type { INormalizedEventData } from '../monitor.interface';
|
11
2
|
export declare class DataLayerMonitor {
|
12
3
|
private static instance;
|
13
4
|
private readonly originalPush;
|
package/dist/types/types.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
export type { IInjectSpotElement, IInjectSpotElementConfig, IInjectSpotElementParams, IRmnCreateSpotElementConfig, ISpotColors, ISpotOverlay, } from 'modules/element';
|
2
2
|
export type { CarouselNavPositionType, ICarouselButtonOptions, ICarouselDotOptions, ICarouselOptions, } from 'modules/element/component/carousel';
|
3
|
-
export type {
|
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,
|
6
|
+
import type { RMN_ENV, RMN_EVENT } from 'enums';
|
7
7
|
import type { IInjectSpotElementParams } from 'modules/element';
|
8
8
|
import type { IRmnEventMap } from 'modules/event';
|
9
9
|
import type { ISpots, ISpotSelectionParams } from 'modules/selection';
|
@@ -14,8 +14,8 @@ export interface IRmnClient {
|
|
14
14
|
injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
|
15
15
|
}
|
16
16
|
export interface IRmnEventManager {
|
17
|
-
subscribe: (eventType:
|
18
|
-
publish: (eventType:
|
17
|
+
subscribe: (eventType: RMN_EVENT, callback: (data: IRmnEventMap[RMN_EVENT]) => void) => () => void;
|
18
|
+
publish: (eventType: RMN_EVENT, data: IRmnEventMap[RMN_EVENT]) => void;
|
19
19
|
destroySpot: (placementId: string) => void;
|
20
20
|
}
|
21
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.
|
5
|
+
"version": "1.5.0-beta.9",
|
6
6
|
"homepage": "https://docs.liquidcommerce.co/rmn-sdk",
|
7
7
|
"main": "./dist/index.cjs",
|
8
8
|
"module": "./dist/index.esm.js",
|