@liquidcommercedev/rmn-sdk 1.4.6-beta.4 → 1.4.6-beta.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +463 -152
- package/dist/index.esm.js +463 -152
- package/dist/types/enums.d.ts +2 -0
- package/dist/types/modules/element/component/carousel/carousel.interface.d.ts +3 -3
- package/dist/types/modules/element/component/utils.d.ts +1 -0
- package/dist/types/modules/element/element.interface.d.ts +2 -0
- package/dist/types/modules/element/template/template.service.d.ts +4 -3
- package/dist/types/modules/event/event.interface.d.ts +53 -0
- package/dist/types/modules/event/event.service.d.ts +27 -2
- package/dist/types/modules/event/index.d.ts +1 -0
- package/dist/types/modules/event/pubsub.d.ts +67 -0
- package/dist/types/modules/selection/selection.interface.d.ts +1 -0
- package/dist/types/rmn-client.d.ts +9 -0
- package/dist/types/types.d.ts +4 -1
- package/package.json +1 -1
- package/umd/liquidcommerce-rmn-sdk.min.js +1 -1
package/dist/types/enums.d.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import type { ICreateElementConfig } from 'modules/element';
|
2
|
-
export type
|
2
|
+
export type CarouselNavPositionType = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'middle-left' | 'middle-right' | 'middle-sides';
|
3
3
|
export interface ICarouselDotOptions {
|
4
|
-
position:
|
4
|
+
position: CarouselNavPositionType;
|
5
5
|
color: string;
|
6
6
|
activeColor: string;
|
7
7
|
}
|
8
8
|
export interface ICarouselButtonOptions {
|
9
|
-
position:
|
9
|
+
position: CarouselNavPositionType;
|
10
10
|
together: boolean;
|
11
11
|
textColor: string;
|
12
12
|
backgroundColor: string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function calculateScaleFactor(elementScale: number): number;
|
@@ -13,6 +13,7 @@ export interface ISpotOverlay {
|
|
13
13
|
colorStop: string;
|
14
14
|
}
|
15
15
|
export interface IInjectSpotElementConfig {
|
16
|
+
fluid?: boolean;
|
16
17
|
url?: string;
|
17
18
|
colors?: ISpotColors;
|
18
19
|
minScale?: number;
|
@@ -27,6 +28,7 @@ export interface IInjectSpotElement {
|
|
27
28
|
filter?: Partial<RmnFilterType>;
|
28
29
|
}
|
29
30
|
export interface ICreateElementConfig {
|
31
|
+
spot?: RMN_SPOT_TYPE;
|
30
32
|
width: number;
|
31
33
|
height: number;
|
32
34
|
fluid?: boolean;
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import type { ISpot } from 'types';
|
2
2
|
import type { ISpotTemplateConfig } from './template.type';
|
3
3
|
/**
|
4
|
-
*
|
4
|
+
* Returns the HTML element for the given spot.
|
5
5
|
*
|
6
|
-
* @param {ISpot} spot - The spot
|
6
|
+
* @param {ISpot} spot - The spot object.
|
7
|
+
* @param {ISpotTemplateConfig} config - The spot template configuration.
|
7
8
|
*
|
8
|
-
* @return {
|
9
|
+
* @return {HTMLElement | null} - The HTML element for the given spot or null if the spot template is not found.
|
9
10
|
*/
|
10
11
|
export declare const SPOT_TEMPLATE_HTML_ELEMENT: (spot: ISpot, config?: ISpotTemplateConfig) => HTMLElement | null;
|
@@ -1,5 +1,58 @@
|
|
1
1
|
import type { RMN_SPOT_EVENT } from 'enums';
|
2
|
+
import type { ISpot } from '../selection';
|
2
3
|
export interface IFireEventParams {
|
3
4
|
event: RMN_SPOT_EVENT;
|
4
5
|
eventUrl: string;
|
5
6
|
}
|
7
|
+
export interface IMountedEvent {
|
8
|
+
placementId: string;
|
9
|
+
spotId: string;
|
10
|
+
spotType: string;
|
11
|
+
spotVariant: string;
|
12
|
+
element: HTMLElement;
|
13
|
+
}
|
14
|
+
export interface IUnMountedEvent {
|
15
|
+
placementId: string;
|
16
|
+
spotId: string;
|
17
|
+
}
|
18
|
+
export interface IClickEvent {
|
19
|
+
placementId: string;
|
20
|
+
spotId: string;
|
21
|
+
element: HTMLElement;
|
22
|
+
}
|
23
|
+
export interface IImpressionEvent {
|
24
|
+
placementId: string;
|
25
|
+
spotId: string;
|
26
|
+
element: HTMLElement;
|
27
|
+
}
|
28
|
+
export interface IAddToCartEvent {
|
29
|
+
placementId: string;
|
30
|
+
spotId: string;
|
31
|
+
}
|
32
|
+
export interface IAddToWishlistEvent {
|
33
|
+
placementId: string;
|
34
|
+
spotId: string;
|
35
|
+
}
|
36
|
+
export interface IPurchaseEvent {
|
37
|
+
placementId: string;
|
38
|
+
spotId: string;
|
39
|
+
}
|
40
|
+
export interface IBuyNowEvent {
|
41
|
+
placementId: string;
|
42
|
+
spotId: string;
|
43
|
+
}
|
44
|
+
export interface IEventMap {
|
45
|
+
[RMN_SPOT_EVENT.MOUNTED]: IMountedEvent;
|
46
|
+
[RMN_SPOT_EVENT.UNMOUNTED]: IUnMountedEvent;
|
47
|
+
[RMN_SPOT_EVENT.CLICK]: IClickEvent;
|
48
|
+
[RMN_SPOT_EVENT.IMPRESSION]: IImpressionEvent;
|
49
|
+
[RMN_SPOT_EVENT.ADD_TO_CART]: IAddToCartEvent;
|
50
|
+
[RMN_SPOT_EVENT.ADD_TO_WISHLIST]: IAddToWishlistEvent;
|
51
|
+
[RMN_SPOT_EVENT.PURCHASE]: IPurchaseEvent;
|
52
|
+
[RMN_SPOT_EVENT.BUY_NOW]: IBuyNowEvent;
|
53
|
+
}
|
54
|
+
export interface IRegisterSpotParams {
|
55
|
+
placementId: string;
|
56
|
+
element: HTMLElement;
|
57
|
+
spot: ISpot;
|
58
|
+
}
|
@@ -1,5 +1,30 @@
|
|
1
|
-
import type {
|
1
|
+
import type { IEventMap, IRegisterSpotParams } from './event.interface';
|
2
2
|
export declare class EventService {
|
3
|
-
|
3
|
+
private static instance;
|
4
|
+
private pubSub;
|
5
|
+
private intersectionObserver;
|
6
|
+
private activeSpots;
|
7
|
+
private constructor();
|
8
|
+
static getInstance(): EventService;
|
9
|
+
registerSpot({ placementId, element, spot }: IRegisterSpotParams): void;
|
10
|
+
unregisterSpot(spotId: string): void;
|
11
|
+
private handleIntersectionObserver;
|
12
|
+
subscribe<K extends keyof IEventMap>(eventType: K, callback: (data: IEventMap[K]) => void): () => void;
|
13
|
+
publish<K extends keyof IEventMap>(eventType: K, data: IEventMap[K]): void;
|
14
|
+
/**
|
15
|
+
* Fires an event using the navigator.sendBeacon method and redirects the user if the event is a click event.
|
16
|
+
*
|
17
|
+
* @param {IFireEventParams} params - The parameters for firing the event.
|
18
|
+
* @param {RMN_SPOT_EVENT} params.event - The event type.
|
19
|
+
* @param {string} params.eventUrl - The URL to which the event is sent.
|
20
|
+
* @returns {Promise<void>} - A promise that resolves when the event is fired.
|
21
|
+
*/
|
22
|
+
private fireEvent;
|
23
|
+
/**
|
24
|
+
* Extracts and decodes a URL from a base64-encoded query parameter.
|
25
|
+
*
|
26
|
+
* @param {string} url - The URL containing the base64-encoded query parameter.
|
27
|
+
* @returns {string} - The decoded URL or an empty string if decoding fails.
|
28
|
+
*/
|
4
29
|
private getRedirectUrlFromPayload;
|
5
30
|
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/**
|
2
|
+
* Callback function type for event subscribers
|
3
|
+
* @template T The type of data the callback receives
|
4
|
+
*/
|
5
|
+
export type PSCallback<T> = (data: T) => void;
|
6
|
+
/**
|
7
|
+
* Function type for unsubscribing from an event
|
8
|
+
*/
|
9
|
+
export type PSUnsubscribe = () => void;
|
10
|
+
/**
|
11
|
+
* PubSub class
|
12
|
+
* Manages event subscriptions and publications
|
13
|
+
* @template IEventMap A record type defining the structure of events and their data
|
14
|
+
*/
|
15
|
+
export declare class PubSub<IEventMap> {
|
16
|
+
/**
|
17
|
+
* Object to store subscribers for each event type
|
18
|
+
*/
|
19
|
+
private subscribers;
|
20
|
+
/**
|
21
|
+
* Subscribe to an event
|
22
|
+
* @param eventType - The type of event to subscribe to
|
23
|
+
* @param callback - The function to be called when the event is published
|
24
|
+
* @returns A function to unsubscribe from the event
|
25
|
+
*
|
26
|
+
* @Example:
|
27
|
+
* const unsubscribe = pubSub.subscribe('userLogin', (data) => {
|
28
|
+
* console.log(`User ${data.username} logged in`);
|
29
|
+
* });
|
30
|
+
*/
|
31
|
+
subscribe<K extends keyof IEventMap>(eventType: K, callback: PSCallback<IEventMap[K]>): PSUnsubscribe;
|
32
|
+
/**
|
33
|
+
* Publish an event
|
34
|
+
* @param eventType - The type of event to publish
|
35
|
+
* @param data - The data to be passed to the event subscribers
|
36
|
+
*
|
37
|
+
* @Example:
|
38
|
+
* pubSub.publish('userLogin', { username: 'john_doe', timestamp: Date.now() });
|
39
|
+
*/
|
40
|
+
publish<K extends keyof IEventMap>(eventType: K, data: IEventMap[K]): void;
|
41
|
+
}
|
42
|
+
/**
|
43
|
+
* Usage Example:
|
44
|
+
*
|
45
|
+
* interface IEventMap {
|
46
|
+
* userLogin: { username: string; timestamp: number };
|
47
|
+
* pageView: { url: string; timestamp: number };
|
48
|
+
* }
|
49
|
+
*
|
50
|
+
* const pubSub = new PubSub<IEventMap>();
|
51
|
+
*
|
52
|
+
* // Subscribe to events
|
53
|
+
* const unsubscribeLogin = pubSub.subscribe('userLogin', (data) => {
|
54
|
+
* console.log(`User ${data.username} logged in at ${new Date(data.timestamp)}`);
|
55
|
+
* });
|
56
|
+
*
|
57
|
+
* pubSub.subscribe('pageView', (data) => {
|
58
|
+
* console.log(`Page ${data.url} viewed at ${new Date(data.timestamp)}`);
|
59
|
+
* });
|
60
|
+
*
|
61
|
+
* // Publish events
|
62
|
+
* pubSub.publish('userLogin', { username: 'john_doe', timestamp: Date.now() });
|
63
|
+
* pubSub.publish('pageView', { url: '/home', timestamp: Date.now() });
|
64
|
+
*
|
65
|
+
* // Unsubscribe from an event
|
66
|
+
* unsubscribeLogin();
|
67
|
+
*/
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import type { IAuthCredentials } from 'modules/auth';
|
2
2
|
import type { IInjectSpotElementParams, IRmnCreateSpotElementConfig } from 'modules/element';
|
3
|
+
import { EventService } from 'modules/event';
|
3
4
|
import type { ISpot, ISpots, ISpotSelectionParams } from 'modules/selection';
|
4
5
|
import type { IRmnClient, IRmnConfig } from 'types';
|
5
6
|
export declare class LiquidCommerceRmnClient implements IRmnClient {
|
6
7
|
private readonly selectionService;
|
7
8
|
private readonly elementService;
|
9
|
+
private readonly eventService;
|
8
10
|
constructor(auth: IAuthCredentials);
|
9
11
|
/**
|
10
12
|
* Makes a selection request on our server based on the provided data.
|
@@ -24,6 +26,12 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
24
26
|
* @return {Promise<void>} - A promise that resolves when the spot elements are injected.
|
25
27
|
*/
|
26
28
|
injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
|
29
|
+
/**
|
30
|
+
* Returns the event manager instance.
|
31
|
+
*
|
32
|
+
* @return {EventService} - The event manager instance.
|
33
|
+
*/
|
34
|
+
eventManager(): EventService;
|
27
35
|
/**
|
28
36
|
* Makes a selection request on our server based on the provided data.
|
29
37
|
*
|
@@ -53,6 +61,7 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
53
61
|
* @return {void}
|
54
62
|
*/
|
55
63
|
private injectOneSpotElement;
|
64
|
+
private eventSpotElement;
|
56
65
|
/**
|
57
66
|
* Prevents duplicate placement ids in the inject data.
|
58
67
|
*
|
package/dist/types/types.d.ts
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
import type { EventService } from './modules/event';
|
2
|
+
export type { IInjectSpotElement, IInjectSpotElementConfig, IInjectSpotElementParams, IRmnCreateSpotElementConfig, ISpotColors, ISpotOverlay, } from 'modules/element';
|
3
|
+
export type { CarouselNavPositionType, ICarouselButtonOptions, ICarouselDotOptions, ICarouselOptions, } from 'modules/element/component/carousel';
|
2
4
|
export type { ISpots, RmnFilterType, RmnSpotType } from 'modules/selection';
|
3
5
|
export { ISpot, ISpotEvent, ISpotSelectionParams } from 'modules/selection';
|
4
6
|
import type { RMN_ENV } from 'enums';
|
@@ -7,6 +9,7 @@ import type { ISpots, ISpotSelectionParams } from 'modules/selection';
|
|
7
9
|
export interface IRmnClient {
|
8
10
|
spotSelection(params: ISpotSelectionParams): Promise<ISpots>;
|
9
11
|
injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
|
12
|
+
eventManager(): EventService;
|
10
13
|
}
|
11
14
|
export interface IRmnConfig {
|
12
15
|
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.
|
5
|
+
"version": "1.4.6-beta.6",
|
6
6
|
"homepage": "https://docs.liquidcommerce.co/rmn-sdk",
|
7
7
|
"main": "./dist/index.cjs",
|
8
8
|
"module": "./dist/index.esm.js",
|