@liquidcommercedev/rmn-sdk 1.4.6-beta.8 → 1.5.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,49 @@
1
+ export declare class UniqueIdGenerator {
2
+ private static readonly epoch;
3
+ private static readonly nodeBits;
4
+ private static readonly sequenceBits;
5
+ private static lastTimestamp;
6
+ private static sequence;
7
+ private static nodeId;
8
+ private static readonly base32Chars;
9
+ /**
10
+ * Initialize the generator with a node ID
11
+ * @param nodeId Number between 0-1023 to identify this instance
12
+ */
13
+ static initialize(nodeId?: number): void;
14
+ /**
15
+ * Convert a number to base32 string with specified length
16
+ */
17
+ private static toBase32;
18
+ /**
19
+ * Generate a cryptographically secure random number
20
+ */
21
+ private static getSecureRandom;
22
+ /**
23
+ * Wait until next millisecond
24
+ */
25
+ private static waitNextMillis;
26
+ /**
27
+ * Generates a highly unique ID with the following format:
28
+ * TTTTTTTTTTCCCCNNNNNRRRR
29
+ * T: Timestamp (10 chars)
30
+ * C: Counter (4 chars)
31
+ * N: Node ID (5 chars)
32
+ * R: Random (4 chars)
33
+ *
34
+ * Total length: 23 characters, always uppercase alphanumeric
35
+ */
36
+ static generate(): string;
37
+ /**
38
+ * Validates if a string matches the expected ID format
39
+ */
40
+ static isValid(id: string): boolean;
41
+ /**
42
+ * Decode base32 string to number
43
+ */
44
+ private static decodeBase32;
45
+ /**
46
+ * Extract timestamp from ID
47
+ */
48
+ static getTimestamp(id: string): Date;
49
+ }
@@ -1,2 +1,2 @@
1
- import { RmnClient, RmnCreateSpotElement } from './index';
2
- export { RmnClient, RmnCreateSpotElement };
1
+ import { RmnClient, RmnCreateSpotElement, RmnEventManager } from './index';
2
+ export { RmnClient, RmnCreateSpotElement, RmnEventManager };
@@ -4,6 +4,8 @@ export interface ICarouselDotOptions {
4
4
  position: CarouselNavPositionType;
5
5
  color: string;
6
6
  activeColor: string;
7
+ size: 'small' | 'base' | 'large';
8
+ opacity: number;
7
9
  }
8
10
  export interface ICarouselButtonOptions {
9
11
  position: CarouselNavPositionType;
@@ -11,6 +13,8 @@ export interface ICarouselButtonOptions {
11
13
  textColor: string;
12
14
  backgroundColor: string;
13
15
  borderRadius: string;
16
+ size: 'small' | 'base' | 'large';
17
+ opacity: number;
14
18
  prev: string;
15
19
  next: string;
16
20
  }
@@ -9,15 +9,16 @@ export interface ISpotColors {
9
9
  ctaBorderColor?: string;
10
10
  }
11
11
  export interface ISpotOverlay {
12
+ size: 'small' | 'base' | 'large';
12
13
  color: string;
13
- colorStop: string;
14
+ opacity: 'light' | 'medium' | 'dark';
14
15
  }
15
16
  export interface IInjectSpotElementConfig {
16
17
  fluid?: boolean;
17
18
  url?: string;
18
19
  colors?: ISpotColors;
19
20
  minScale?: number;
20
- overlay?: ISpotOverlay[];
21
+ overlay?: ISpotOverlay;
21
22
  carousel?: ICarouselOptions;
22
23
  }
23
24
  export interface IInjectSpotElement {
@@ -46,6 +47,6 @@ export interface IElementService {
46
47
  export interface IRmnCreateSpotElementConfig {
47
48
  fluid?: boolean;
48
49
  colors?: ISpotColors;
49
- overlay?: ISpotOverlay[];
50
+ overlay?: ISpotOverlay;
50
51
  minScale?: number;
51
52
  }
@@ -1,3 +1,4 @@
1
1
  import type { ISpotOverlay } from '../element.interface';
2
- export declare function linearGradientColorStop(overlay: ISpotOverlay[], fallback: string): string;
2
+ export declare function convertHexToRgba(hex: string, opacity?: number): string;
3
+ export declare function generateGradientColor(overlay?: ISpotOverlay, fallback?: string): string;
3
4
  export declare function spotHtmlStringToElement(htmlString: string): HTMLElement;
@@ -3,7 +3,7 @@ import type { SpotVariantType } from 'modules/selection';
3
3
  import type { ISpot } from 'types';
4
4
  import type { ISpotOverlay } from '../element.interface';
5
5
  export interface ISpotTemplateConfig {
6
- overlay?: ISpotOverlay[];
6
+ overlay?: ISpotOverlay;
7
7
  prefix?: string;
8
8
  }
9
9
  export type TemplateFunction = (spot: ISpot, config: ISpotTemplateConfig) => string;
@@ -10,8 +10,8 @@ export interface ILSIdentifier {
10
10
  spotType: string;
11
11
  }
12
12
  export interface ILSDom {
13
- visible: boolean;
14
- element?: HTMLElement;
13
+ visibleOnViewport: boolean;
14
+ spotElement?: HTMLElement;
15
15
  }
16
16
  export interface ILSState {
17
17
  mounted: boolean;
@@ -33,12 +33,12 @@ export interface ILifecycleState {
33
33
  export interface IClickEvent {
34
34
  placementId: string;
35
35
  spotId: string;
36
- element: HTMLElement;
36
+ spotElement: HTMLElement;
37
37
  }
38
38
  export interface IImpressionEvent {
39
39
  placementId: string;
40
40
  spotId: string;
41
- element: HTMLElement;
41
+ spotElement: HTMLElement;
42
42
  }
43
43
  export interface IAddToCartEvent {
44
44
  placementId: string;
@@ -67,6 +67,6 @@ export interface IEventMap {
67
67
  }
68
68
  export interface IRegisterSpotParams {
69
69
  placementId: string;
70
- element: HTMLElement;
70
+ spotElement: HTMLElement;
71
71
  spot: ISpot;
72
72
  }
@@ -3,6 +3,7 @@ import type { IEventMap, ILifecycleState, IRegisterSpotParams } from './event.in
3
3
  export declare class EventService {
4
4
  private static instance;
5
5
  private pubSub;
6
+ private localStorage;
6
7
  private intersectionObserver;
7
8
  private spotStates;
8
9
  private activeSpots;
@@ -10,10 +11,21 @@ export declare class EventService {
10
11
  static getInstance(): EventService;
11
12
  subscribe(eventType: RMN_SPOT_EVENT, callback: (data: IEventMap[RMN_SPOT_EVENT]) => void): () => void;
12
13
  publish(eventType: RMN_SPOT_EVENT, data: IEventMap[RMN_SPOT_EVENT]): void;
14
+ registerSpot(params: IRegisterSpotParams): void;
15
+ unregisterSpot(placementId: string): void;
16
+ /**
17
+ * Updates the state of a spot.
18
+ *
19
+ * @param {string} placementId - The placement ID of the spot.
20
+ * @param {Partial<ILifecycleState>} updates - The updates to apply to the spot state.
21
+ * @param {boolean} publish - Whether to publish the updated state.
22
+ *
23
+ * @returns {void}
24
+ */
13
25
  handleSpotState(placementId: string, updates: Partial<ILifecycleState>, publish?: boolean): void;
14
- registerSpot({ placementId, element, spot }: IRegisterSpotParams): void;
15
- unregisterSpot(spotId: string): void;
26
+ private handleClick;
16
27
  private handleIntersectionObserver;
28
+ private fireImpressionEvent;
17
29
  /**
18
30
  * Fires an event using the navigator.sendBeacon method and redirects the user if the event is a click event.
19
31
  *
@@ -1,2 +1,3 @@
1
1
  export * from './intersection.service';
2
+ export * from './localstorage.service';
2
3
  export * from './resize.service';
@@ -0,0 +1,26 @@
1
+ import type { RMN_SPOT_TYPE } from 'enums';
2
+ import type { ISpotEvent } from 'modules/selection';
3
+ export interface ILocalStorageSpot {
4
+ spotId: string;
5
+ spotType: RMN_SPOT_TYPE;
6
+ events: ISpotEvent[];
7
+ productIds: Array<string | number>;
8
+ createdAt?: number;
9
+ }
10
+ export declare class LocalStorage {
11
+ private spots;
12
+ private static instance;
13
+ private static readonly localStorageKey;
14
+ private static readonly spotExpirationTime;
15
+ private constructor();
16
+ static getInstance(): LocalStorage;
17
+ private syncLocalStorage;
18
+ setSpot(spotId: string, data: ILocalStorageSpot): void;
19
+ getSpot(spotId: string): ILocalStorageSpot | undefined;
20
+ removeSpot(spotId: string): void;
21
+ private updateLocalStorage;
22
+ clearLocalStorage(): void;
23
+ private removeExpiredSpots;
24
+ private mapToObj;
25
+ private objToMap;
26
+ }
@@ -2,17 +2,19 @@
2
2
  * Callback function type for event subscribers
3
3
  * @template T The type of data the callback receives
4
4
  */
5
- export type PSCallback<T> = (data: T) => void;
5
+ export type PubSubCallback<T> = (data: T) => void;
6
6
  /**
7
7
  * Function type for unsubscribing from an event
8
8
  */
9
- export type PSUnsubscribe = () => void;
9
+ export type PubSubUnsubscribe = () => void;
10
10
  /**
11
11
  * PubSub class
12
12
  * Manages event subscriptions and publications
13
13
  * @template IEventMap A record type defining the structure of events and their data
14
14
  */
15
15
  export declare class PubSub<IEventMap> {
16
+ private static instance;
17
+ static getInstance<IEventMap>(): PubSub<IEventMap>;
16
18
  /**
17
19
  * Object to store subscribers for each event type
18
20
  */
@@ -28,7 +30,7 @@ export declare class PubSub<IEventMap> {
28
30
  * console.log(`User ${data.username} logged in`);
29
31
  * });
30
32
  */
31
- subscribe<K extends keyof IEventMap>(eventType: K, callback: PSCallback<IEventMap[K]>): PSUnsubscribe;
33
+ subscribe<K extends keyof IEventMap>(eventType: K, callback: PubSubCallback<IEventMap[K]>): PubSubUnsubscribe;
32
34
  /**
33
35
  * Publish an event
34
36
  * @param eventType - The type of event to publish
@@ -29,6 +29,7 @@ export interface ISpot {
29
29
  secondaryImage?: string;
30
30
  mobilePrimaryImage?: string;
31
31
  mobileSecondaryImage?: string;
32
+ productIds?: Array<string | number>;
32
33
  productUpcs?: string[];
33
34
  }
34
35
  export type ISpots = Record<PlacementIdType, ISpot[]>;
@@ -1,9 +1,7 @@
1
1
  import type { IAuthCredentials } from 'modules/auth';
2
2
  import type { IInjectSpotElementParams, IRmnCreateSpotElementConfig } from 'modules/element';
3
- import { type IEventMap } from 'modules/event';
4
3
  import type { ISpot, ISpots, ISpotSelectionParams } from 'modules/selection';
5
- import type { IRmnClient, IRmnConfig } from 'types';
6
- import type { RMN_SPOT_EVENT } from './enums';
4
+ import type { IRmnClient, IRmnConfig, IRmnEventManager } from 'types';
7
5
  export declare class LiquidCommerceRmnClient implements IRmnClient {
8
6
  private readonly selectionService;
9
7
  private readonly elementService;
@@ -29,15 +27,6 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
29
27
  * @return {Promise<void>} - A promise that resolves when the spot elements are injected.
30
28
  */
31
29
  injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
32
- /**
33
- * Returns the event manager instance.
34
- *
35
- * @return {EventService} - The event manager instance.
36
- */
37
- eventManager: {
38
- subscribe: (eventType: RMN_SPOT_EVENT, callback: (data: IEventMap[RMN_SPOT_EVENT]) => void) => (() => void);
39
- publish: (eventType: RMN_SPOT_EVENT, data: IEventMap[RMN_SPOT_EVENT]) => void;
40
- };
41
30
  /**
42
31
  * Makes a selection request on our server based on the provided data.
43
32
  *
@@ -79,6 +68,7 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
79
68
  private preventDuplicateSpotPlacementIds;
80
69
  private preventNonExistentSpotTypes;
81
70
  private updateSpotsState;
71
+ private useSpotSelectionExample;
82
72
  }
83
73
  /**
84
74
  * Creates a new instance of the RmnClient.
@@ -89,6 +79,12 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
89
79
  * @return {Promise<IRmnClient>} - The RmnClient instance.
90
80
  */
91
81
  declare function RmnClient(apiKey: string, config: IRmnConfig): Promise<IRmnClient>;
82
+ /**
83
+ * Creates a new instance of the RmnEventManager.
84
+ *
85
+ * @return {IRmnEventManager} - The RmnEventManager instance.
86
+ */
87
+ declare function RmnEventManager(): IRmnEventManager;
92
88
  /**
93
89
  * Creates the spot html element based on the provided data using shadow dom.
94
90
  *
@@ -102,4 +98,4 @@ declare function RmnClient(apiKey: string, config: IRmnConfig): Promise<IRmnClie
102
98
  * @return {HTMLElement | null} - The spot html element or null if the browser environment is not available.
103
99
  */
104
100
  declare function RmnCreateSpotElement(spot: ISpot, config?: IRmnCreateSpotElementConfig): HTMLElement | null;
105
- export { RmnClient, RmnCreateSpotElement };
101
+ export { RmnClient, RmnCreateSpotElement, RmnEventManager };
@@ -1,3 +1,4 @@
1
1
  import type { ISpotEvent, ISpots } from 'types';
2
2
  export declare const SPOT_EVENTS_EXAMPLE: ISpotEvent[];
3
3
  export declare const RB_SPOTS_SELECTION_EXAMPLE: Partial<ISpots>;
4
+ export declare const IAB_SPOTS_SELECTION_EXAMPLE: Partial<ISpots>;
@@ -11,10 +11,11 @@ export interface IRmnClient {
11
11
  error: string;
12
12
  }>;
13
13
  injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
14
- eventManager: {
15
- subscribe: (eventType: RMN_SPOT_EVENT, callback: (data: IEventMap[RMN_SPOT_EVENT]) => void) => () => void;
16
- publish: (eventType: RMN_SPOT_EVENT, data: IEventMap[RMN_SPOT_EVENT]) => void;
17
- };
14
+ }
15
+ 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;
18
+ destroySpot: (placementId: string) => void;
18
19
  }
19
20
  export interface IRmnConfig {
20
21
  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.8",
5
+ "version": "1.5.0-beta.1",
6
6
  "homepage": "https://docs.liquidcommerce.co/rmn-sdk",
7
7
  "main": "./dist/index.cjs",
8
8
  "module": "./dist/index.esm.js",