@liquidcommercedev/rmn-sdk 1.5.0-beta.15 → 1.5.0-beta.17
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.cjs +1624 -1456
- package/dist/index.esm.js +1624 -1456
- package/dist/types/common/helpers/extract-deep.helper.d.ts +14 -0
- package/dist/types/common/helpers/index.d.ts +1 -0
- package/dist/types/common/helpers/utils.helper.d.ts +13 -16
- package/dist/types/modules/helper-service/localstorage.service.d.ts +9 -1
- package/dist/types/modules/monitor/monitor.interface.d.ts +1 -0
- package/dist/types/modules/selection/selection.interface.d.ts +7 -1
- package/dist/types/modules/selection/selection.service.d.ts +1 -0
- package/dist/types/rmn-client.d.ts +10 -34
- package/dist/types/rmn-client.helper.d.ts +41 -0
- package/package.json +1 -1
- package/umd/liquidcommerce-rmn-sdk.min.js +1 -1
@@ -0,0 +1,14 @@
|
|
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
|
+
export {};
|
@@ -1,28 +1,18 @@
|
|
1
1
|
import type { IFireEventParams } from 'modules/event';
|
2
|
+
export declare function fallbackEventFire(url: string): Promise<boolean>;
|
2
3
|
/**
|
3
|
-
*
|
4
|
-
* Searches for specified property names and collects their primitive values (strings/numbers).
|
5
|
-
* Captures properties ending with 'id' and any additional specified property names.
|
6
|
-
*
|
7
|
-
* @param data - The data structure to search through (can be nested objects/arrays)
|
8
|
-
* @param propertyNames - Array of additional property names to look for (optional)
|
9
|
-
* @returns Array of extracted ID values (strings/numbers only)
|
4
|
+
* Helper function to decode base64 string and parse JSON
|
10
5
|
*
|
11
|
-
* @
|
12
|
-
*
|
13
|
-
* id: [1, 2, 3],
|
14
|
-
* nested: { id: 'abc', userId: 123 },
|
15
|
-
* items: [{ id: 456, productId: '789', sku: 'ABC123' }]
|
16
|
-
* };
|
17
|
-
* extractDeepIds(data); // Returns [1, 2, 3, 'abc', 123, 456, '789', 'ABC123']
|
6
|
+
* @param {string} base64String - The base64 encoded JSON string
|
7
|
+
* @returns {T | null} - Decoded and parsed object or null if invalid
|
18
8
|
*/
|
19
|
-
export declare function
|
20
|
-
export declare function fallbackEventFire(url: string): Promise<boolean>;
|
9
|
+
export declare function decodeBase64Json<T>(base64String: string): T | null;
|
21
10
|
/**
|
22
11
|
* Extracts and decodes a URL from a base64-encoded query parameter.
|
23
12
|
*
|
24
13
|
* @param {string} url - The URL containing the base64-encoded query parameter.
|
25
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.
|
26
16
|
*/
|
27
17
|
export declare function getRedirectUrlFromPayload(url: string): string | null;
|
28
18
|
/**
|
@@ -36,3 +26,10 @@ export declare function getRedirectUrlFromPayload(url: string): string | null;
|
|
36
26
|
*/
|
37
27
|
export declare function fireEvent({ event, eventUrl }: IFireEventParams): Promise<void>;
|
38
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;
|
@@ -45,7 +45,8 @@ LocalStorageSpotArray>;
|
|
45
45
|
export declare class LocalStorageService {
|
46
46
|
private spots?;
|
47
47
|
private static instance;
|
48
|
-
private static readonly
|
48
|
+
private static readonly localStorageKeyPrefix;
|
49
|
+
private static localStorageKey;
|
49
50
|
private static readonly spotExpirationTime;
|
50
51
|
private static readonly encryptData;
|
51
52
|
private constructor();
|
@@ -58,6 +59,13 @@ export declare class LocalStorageService {
|
|
58
59
|
private updateLocalStorage;
|
59
60
|
private clearLocalStorage;
|
60
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;
|
61
69
|
private mapToObject;
|
62
70
|
private objectToMap;
|
63
71
|
private spotEventObjectToArray;
|
@@ -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[];
|
@@ -2,6 +2,10 @@ 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
|
+
* @class
|
8
|
+
*/
|
5
9
|
export declare class LiquidCommerceRmnClient implements IRmnClient {
|
6
10
|
private readonly selectionService;
|
7
11
|
private readonly elementService;
|
@@ -28,21 +32,9 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
28
32
|
* @return {Promise<void>} - A promise that resolves when the spot elements are injected.
|
29
33
|
*/
|
30
34
|
injectSpotElement(params: IInjectSpotElementParams): Promise<void>;
|
31
|
-
/** ========================= HELPER METHODS ========================= **/
|
32
|
-
/**
|
33
|
-
* Injects a carousel element with the provided spots into the placement.
|
34
|
-
*
|
35
|
-
* @param {HTMLElement} placement - The placement element.
|
36
|
-
* @param {ISpot[]} spots - The spot data.
|
37
|
-
* @param {IInjectSpotElementConfig} config - The configuration object.
|
38
|
-
*
|
39
|
-
* @return {void}
|
40
|
-
*/
|
41
|
-
private injectCarouselSpotElement;
|
42
35
|
/**
|
43
36
|
* Injects a single spot element into the provided placement.
|
44
37
|
*
|
45
|
-
* @param {IInjectSpotElement} injectItem - The inject item data.
|
46
38
|
* @param {HTMLElement} placement - The placement element.
|
47
39
|
* @param {ISpot} spot - The spot data.
|
48
40
|
* @param {IInjectSpotElementConfig} config - The configuration object.
|
@@ -51,13 +43,15 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
51
43
|
*/
|
52
44
|
private injectOneSpotElement;
|
53
45
|
/**
|
54
|
-
*
|
46
|
+
* Injects a carousel element with the provided spots into the placement.
|
55
47
|
*
|
56
|
-
* @param {
|
48
|
+
* @param {HTMLElement} placement - The placement element.
|
49
|
+
* @param {ISpot[]} spots - The spot data.
|
50
|
+
* @param {IInjectSpotElementConfig} config - The configuration object.
|
57
51
|
*
|
58
52
|
* @return {void}
|
59
53
|
*/
|
60
|
-
private
|
54
|
+
private injectCarouselSpotElement;
|
61
55
|
/**
|
62
56
|
* Makes a selection request on our server based on the provided data.
|
63
57
|
*
|
@@ -65,25 +59,7 @@ export declare class LiquidCommerceRmnClient implements IRmnClient {
|
|
65
59
|
*
|
66
60
|
* @return {Promise<ISpots | {error: string}>} - The spots response object.
|
67
61
|
*/
|
68
|
-
private
|
69
|
-
/**
|
70
|
-
* Prevents duplicate placement ids in the inject data.
|
71
|
-
*
|
72
|
-
* @param {IInjectSpotElement[]} inject - The inject data.
|
73
|
-
*
|
74
|
-
* @throws {Error} - If a duplicate placement id is found.
|
75
|
-
*
|
76
|
-
* @return {void}
|
77
|
-
*/
|
78
|
-
private preventDuplicateSpotPlacementIds;
|
79
|
-
/**
|
80
|
-
* Prevents non-existent spot types in the inject data.
|
81
|
-
*
|
82
|
-
* @param {IInjectSpotElement[]} inject - The inject data.
|
83
|
-
* @return {IInjectSpotElement[]} - The filtered inject data.
|
84
|
-
*/
|
85
|
-
private preventNonExistentSpotTypes;
|
86
|
-
private useSpotSelectionExample;
|
62
|
+
private injectSpotSelectionRequest;
|
87
63
|
}
|
88
64
|
/**
|
89
65
|
* Creates a new instance of the RmnClient.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import type { IInjectSpotElement } from 'modules/element';
|
2
|
+
import type { ISpots } from 'modules/selection';
|
3
|
+
/**
|
4
|
+
* Checks if the current environment is a browser environment.
|
5
|
+
*
|
6
|
+
* @return {boolean} - Whether the current environment is a browser environment.
|
7
|
+
*/
|
8
|
+
export declare function isBrowserEnvironment(): boolean;
|
9
|
+
/**
|
10
|
+
* Validates the inject data by preventing duplicate placement ids and non-existent spot types.
|
11
|
+
*
|
12
|
+
* @param {IInjectSpotElement[]} inject - The inject data.
|
13
|
+
* @return {IInjectSpotElement[]} - The validated inject data.
|
14
|
+
*/
|
15
|
+
export declare function validateInjectData(inject: IInjectSpotElement[]): IInjectSpotElement[];
|
16
|
+
/**
|
17
|
+
* Clears the placement element by removing all its children.
|
18
|
+
*
|
19
|
+
* @param {string} placementId - The placement id.
|
20
|
+
*
|
21
|
+
* @return {void}
|
22
|
+
*/
|
23
|
+
export declare function clearPlacement(placementId: string): void;
|
24
|
+
/**
|
25
|
+
* Prepares the spot placement for rendering by taking care of its styling.
|
26
|
+
*
|
27
|
+
* @param {HTMLElement} placement - The placement element.
|
28
|
+
*
|
29
|
+
* @return {void}
|
30
|
+
*/
|
31
|
+
export declare function prepareSpotPlacement(placement: HTMLElement): void;
|
32
|
+
/**
|
33
|
+
* Waits for the DOM to be ready before continuing.
|
34
|
+
*
|
35
|
+
* @return {Promise<void>} - A promise that resolves when the DOM is ready.
|
36
|
+
*/
|
37
|
+
export declare function waitForDOM(): Promise<void>;
|
38
|
+
export declare function useSpotSelectionExample(inject: IInjectSpotElement[]): Promise<ISpots | {
|
39
|
+
error: string;
|
40
|
+
}>;
|
41
|
+
export declare function setUserId(): void;
|
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.17",
|
6
6
|
"homepage": "https://docs.liquidcommerce.co/rmn-sdk",
|
7
7
|
"main": "./dist/index.cjs",
|
8
8
|
"module": "./dist/index.esm.js",
|