@liquidcommercedev/rmn-sdk 1.4.6-beta.3 → 1.4.6-beta.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +351 -47
- package/dist/index.esm.js +351 -47
- package/dist/types/enums.d.ts +4 -0
- package/dist/types/modules/element/component/carousel/carousel.interface.d.ts +3 -3
- package/dist/types/modules/element/element.interface.d.ts +17 -9
- package/dist/types/modules/element/template/template.service.d.ts +4 -3
- package/dist/types/modules/event/event.interface.d.ts +67 -0
- package/dist/types/modules/event/event.service.d.ts +27 -2
- package/dist/types/modules/event/pubsub.d.ts +67 -0
- package/dist/types/modules/selection/selection.interface.d.ts +3 -2
- package/dist/types/modules/selection/selection.type.d.ts +3 -2
- package/dist/types/rmn-client.d.ts +28 -10
- package/dist/types/types.d.ts +7 -4
- package/package.json +1 -1
- package/umd/liquidcommerce-rmn-sdk.min.js +1 -1
@@ -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,5 +1,5 @@
|
|
1
1
|
import type { RMN_SPOT_EVENT, RMN_SPOT_TYPE } from 'enums';
|
2
|
-
import type {
|
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;
|
@@ -11,6 +11,7 @@ export interface ISpotEvent {
|
|
11
11
|
url: string;
|
12
12
|
}
|
13
13
|
export interface ISpot {
|
14
|
+
id: string;
|
14
15
|
events: ISpotEvent[];
|
15
16
|
spot: RMN_SPOT_TYPE;
|
16
17
|
variant: SpotVariantType;
|
@@ -30,7 +31,7 @@ export interface ISpot {
|
|
30
31
|
mobileSecondaryImage?: string;
|
31
32
|
productUpcs?: string[];
|
32
33
|
}
|
33
|
-
export type ISpots = Record<
|
34
|
+
export type ISpots = Record<PlacementIdType, ISpot[]>;
|
34
35
|
export interface ISelectionService {
|
35
36
|
spotSelection(data: ISpotSelectionParams): Promise<ISpots>;
|
36
37
|
}
|
@@ -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
|
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,30 +1,45 @@
|
|
1
1
|
import type { IAuthCredentials } from 'modules/auth';
|
2
|
-
import type {
|
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.
|
11
13
|
*
|
12
14
|
* To create a spot html element, use the RmnCreateSpotElement function.
|
13
15
|
*
|
14
|
-
* @param {ISpotSelectionParams}
|
16
|
+
* @param {ISpotSelectionParams} params - Spots selection parameters.
|
15
17
|
*
|
16
18
|
* @return {Promise<ISpots>} - The spots response object.
|
17
19
|
*/
|
18
|
-
spotSelection(
|
20
|
+
spotSelection(params: ISpotSelectionParams): Promise<ISpots>;
|
19
21
|
/**
|
20
22
|
* Injects the spot elements into their provided placement.
|
21
23
|
*
|
22
|
-
* @param {
|
23
|
-
* @param {IInjectSpotElementConfig} config - The configuration object.
|
24
|
+
* @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
|
24
25
|
*
|
25
26
|
* @return {Promise<void>} - A promise that resolves when the spot elements are injected.
|
26
27
|
*/
|
27
|
-
injectSpotElement(
|
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;
|
35
|
+
/**
|
36
|
+
* Makes a selection request on our server based on the provided data.
|
37
|
+
*
|
38
|
+
* @param {IInjectSpotElementParams} params - Parameters for injecting spot elements.
|
39
|
+
*
|
40
|
+
* @return {Promise<ISpots>} - The spots response object.
|
41
|
+
*/
|
42
|
+
private spotSelectionRequest;
|
28
43
|
/**
|
29
44
|
* Injects a carousel element with the provided spots into the placement.
|
30
45
|
*
|
@@ -46,14 +61,17 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
46
61
|
* @return {void}
|
47
62
|
*/
|
48
63
|
private injectOneSpotElement;
|
64
|
+
private eventSpotElement;
|
49
65
|
/**
|
50
|
-
*
|
66
|
+
* Prevents duplicate placement ids in the inject data.
|
67
|
+
*
|
68
|
+
* @param {IInjectSpotElement[]} inject - The inject data.
|
51
69
|
*
|
52
|
-
* @
|
70
|
+
* @throws {Error} - If a duplicate placement id is found.
|
53
71
|
*
|
54
|
-
* @return {
|
72
|
+
* @return {void}
|
55
73
|
*/
|
56
|
-
private
|
74
|
+
private preventDuplicateSpotPlacementIds;
|
57
75
|
}
|
58
76
|
/**
|
59
77
|
* Creates a new instance of the RmnClient.
|
package/dist/types/types.d.ts
CHANGED
@@ -1,12 +1,15 @@
|
|
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';
|
5
|
-
import type {
|
7
|
+
import type { IInjectSpotElementParams } from 'modules/element';
|
6
8
|
import type { ISpots, ISpotSelectionParams } from 'modules/selection';
|
7
9
|
export interface IRmnClient {
|
8
|
-
spotSelection(
|
9
|
-
injectSpotElement(
|
10
|
+
spotSelection(params: ISpotSelectionParams): Promise<ISpots>;
|
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.5",
|
6
6
|
"homepage": "https://docs.liquidcommerce.co/rmn-sdk",
|
7
7
|
"main": "./dist/index.cjs",
|
8
8
|
"module": "./dist/index.esm.js",
|