@dotcms/experiments 1.4.0-next.2 → 1.4.0-next.3

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.
@@ -1,54 +0,0 @@
1
- import { Experiment, ExperimentParsed, FetchExperiments } from '../models';
2
- /**
3
- * This arrow function parses a given set of assigned experiments for analytics.
4
- *
5
- * This process involves iterating over the experiments, which are currently in the "Running" state as received from the DotCMS endpoint,
6
- * analyzing each experiment's relevant data such as running ID, variant name, and look back window value.
7
- * It also performs regular expression verification for both 'isExperimentPage' and 'isTargetPage' against the current URL.
8
- *
9
- * The parsed data is useful for tracking and understanding the user's interaction with the experiment-targeted components during their visit.
10
- *
11
- * Contains an object with experiments information.
12
- *
13
- * @param experiments
14
- * @param {Location} location - This parameter is the object representing the current location (URL) of the user.
15
- * Mostly employed for matching the regular expressions to detect whether the current page is an 'ExperimentPage' or a 'TargetPage'.
16
- *
17
- * @returns {ExperimentParsed} - The function returns an object with the original URL and an array of each experiment's comprehensive detail.
18
- * The return object is suitable for further analytical operations. Each experiment's detail includes the experiment ID, running ID, variant name,
19
- * look back window value, and booleans that represent whether current URL is 'isExperimentPage' or 'isTargetPage' for the respective experiment.
20
- */
21
- export declare const parseDataForAnalytics: (experiments: Experiment[], location: Location) => ExperimentParsed;
22
- /**
23
- * This utility function performs regular expression (regex) matching on a supplied URL.
24
- *
25
- * @param {string | null} regexToCheck - The regular expression to match against the URL.
26
- * @param {string} href - This is the target URL, which is aimed to be matched against the provided regular expression.
27
- * @returns {boolean} -The function returns a Boolean value.
28
- */
29
- export declare const verifyRegex: (regexToCheck: string | null, href: string) => boolean;
30
- /**
31
- * This function merges newly fetched data with the data stored from IndexedDB, preparing it for re-storage in IndexedDB.
32
- *
33
- * @param { AssignedExperiments | null } fetchExperiments - The experiment data fetched from the API.
34
- * @param { AssignedExperiments | null } storedExperiments - The experiment data currently stored in IndexedDB.
35
- *
36
- * @returns { AssignedExperiments } - The parsed experiment data ready for storing.
37
- *
38
- * Following cases are handled -
39
- * 1) When new Data is received without Old data. This is assumed to be the first time data is received.
40
- * 2) When only old data is received, implying that the timestamp hasn't expired and the data is available in IndexedDB.
41
- * The data is verified and any expired experiment is removed before being assigned to dataToStorage.
42
- * 3) When both old data and new data is present. This implies that the record existed in IndexedDB but was fetched because the flag had expired.
43
- * Additional operations are performed to add expiry time to experiments, merging all experiments, and storing them.
44
- *
45
- * There could be scenarios where none of these conditions are met, in that case, dataToStorage will be the default empty object.
46
- */
47
- export declare const parseData: (fetchExperiments: FetchExperiments, storedExperiments: Experiment[] | undefined) => Experiment[];
48
- /**
49
- * Retrieves the array of experiment IDs from the given AssignedExperiments..
50
- *
51
- * @returns {string[]} Returns an array of experiment IDs if available, otherwise an empty array.
52
- * @param experiments
53
- */
54
- export declare const getExperimentsIds: (experiments: Experiment[]) => string[];
@@ -1,87 +0,0 @@
1
- /**
2
- * Represents the configuration for a database connection.
3
- * @interface
4
- */
5
- interface DbConfig {
6
- db_name: string;
7
- db_store: string;
8
- db_key_path: string;
9
- }
10
- /**
11
- * The `DatabaseHandler` class offers specific methods to store and get data
12
- * from IndexedDB.
13
- *
14
- * @example
15
- * // To fetch data from the IndexedDB
16
- * const data = await DatabaseHandler.getData();
17
- *
18
- * @example
19
- * // To store an object of type AssignedExperiments to IndexedDB
20
- * await DatabaseHandler.persistData(anAssignedExperiment);
21
- *
22
- * @example
23
- * // To get an object of type AssignedExperiments to IndexedDB
24
- * await DatabaseHandler.persistData(anAssignedExperiment);
25
- *
26
- */
27
- export declare class IndexDBDatabaseHandler {
28
- private config;
29
- constructor(config: DbConfig);
30
- /**
31
- * Saves the provided data to indexDB.
32
- *
33
- * @async
34
- * @param {AssignedExperiments} data - The data to be saved.
35
- * @returns {Promise<any>} - The result of the save operation.
36
- */
37
- persistData<T>(data: T): Promise<IDBValidKey>;
38
- /**
39
- * Retrieves data from the database using a specific key.
40
- *
41
- * @async
42
- * @returns {Promise<any>} A promise that resolves with the data retrieved from the database.
43
- */
44
- getData<T>(): Promise<T>;
45
- /**
46
- * Deletes all the data from the IndexedDB store.
47
- *
48
- * @async
49
- * @returns {Promise<void>} - The result of the delete operation.
50
- */
51
- clearData(): Promise<void>;
52
- /**
53
- * Sets the flag indicating that the experiment has already been checked.
54
- *
55
- * @function setFlagExperimentAlreadyChecked
56
- * @returns {void}
57
- */
58
- setFlagExperimentAlreadyChecked(): void;
59
- /**
60
- * Sets the fetch expired time in the local storage.
61
- *
62
- * @return {void}
63
- */
64
- setFetchExpiredTime(): void;
65
- /**
66
- * Builds an error message based on the provided error object.
67
- * @param {DOMException | null} error - The error object to build the message from.
68
- * @returns {string} The constructed error message.
69
- */
70
- private getOnErrorMessage;
71
- /**
72
- * Creates or opens a IndexedDB database with the specified version.
73
- *
74
- *
75
- * @returns {Promise<IDBDatabase>} A promise that resolves to the opened database.
76
- * The promise will be rejected with an error message if there was a database error.
77
- */
78
- private openDB;
79
- /**
80
- * Retrieves the result of a database request from an Event object.
81
- *
82
- * @param {Event} event - The Event object containing the database request.
83
- * @returns {IDBDatabase} - The result of the database request, casted as an IDBDatabase object.
84
- */
85
- private getRequestResult;
86
- }
87
- export {};
@@ -1,15 +0,0 @@
1
- /**
2
- * Logger for the dotCMS SDK
3
- */
4
- export declare class DotLogger {
5
- private readonly isDebug;
6
- private readonly packageName;
7
- constructor(isDebug: boolean, packageName: string);
8
- group(label: string): void;
9
- groupEnd(): void;
10
- time(label: string): void;
11
- timeEnd(label: string): void;
12
- log(message: string): void;
13
- warn(message: string): void;
14
- error(message: string): void;
15
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Memoizes an object and returns the memoized object.
3
- * Mantaing the same reference if the object is the same independently if is called inside any component.
4
- * @param object
5
- * @returns
6
- */
7
- export declare function useMemoizedObject<T extends object>(object: T): T;
@@ -1,73 +0,0 @@
1
- import { DotExperimentConfig, Experiment, Variant } from '../models';
2
- /**
3
- * Returns the first script element that includes the experiment script identifier.
4
- *
5
- * @return {HTMLScriptElement|undefined} - The found script element or undefined if none is found.
6
- */
7
- export declare const getExperimentScriptTag: () => HTMLScriptElement;
8
- /**
9
- * Retrieves experiment attributes from a given script element.
10
- *
11
- *
12
- * @return {DotExperimentConfig | null} - The experiment attributes or null if there are no valid attributes present.
13
- */
14
- export declare const getDataExperimentAttributes: (location: Location) => DotExperimentConfig | null;
15
- /**
16
- * Retrieves the data attributes from the experiment script tag.
17
- *
18
- * @example
19
- * Given the custom script tag in your HTML:
20
- * <script src="/dot-experiments.iife.js"
21
- * defer=""
22
- * data-experiment-api-key="api-token"
23
- * data-experiment-server="http://localhost:8080/"
24
- * data-experiment-debug>
25
- * </script>
26
- *
27
- * @returns {DotExperimentConfig | null} The data attributes of the experiment script tag, or null if no experiment script is found.
28
- */
29
- export declare const getScriptDataAttributes: (location: Location) => DotExperimentConfig | null;
30
- /**
31
- * Checks the flag indicating whether the experiment has already been checked.
32
- *
33
- * @function checkFlagExperimentAlreadyChecked
34
- * @returns {boolean} - returns true if experiment has already been checked, otherwise false.
35
- */
36
- export declare const checkFlagExperimentAlreadyChecked: () => boolean;
37
- /**
38
- * Checks if the data needs to be invalidated based on the creation date.
39
- *
40
- * @returns {boolean} - True if the data needs to be invalidated, false otherwise.
41
- */
42
- export declare const isDataCreateValid: () => boolean;
43
- /**
44
- * Ad to an absolute path the baseUrl depending on the location.
45
- *
46
- * @param {string | null} absolutePath - The absolute path of the URL.
47
- * @param {Location} location - The location object representing the current URL.
48
- * @returns {string | null} - The full URL or null if absolutePath is null.
49
- */
50
- export declare const getFullUrl: (location: Location, absolutePath: string | null) => string | null;
51
- /**
52
- * Updates the URL with the queryParam with the experiment variant name.
53
- *
54
- * @param {Location|string} location - The current location object or the URL string.
55
- * @param {Variant} variant - The experiment variant to update the URL with.
56
- * @returns {string} The updated URL string.
57
- */
58
- export declare const updateUrlWithExperimentVariant: (location: Location | string, variant: Variant | null) => string;
59
- /**
60
- * Check if two arrays of Experiment objects are equal.
61
- *
62
- * @param {Experiment[]} obj1 - The first array of Experiment objects.
63
- * @param {Experiment[]} obj2 - The second array of Experiment objects.
64
- * @return {boolean} - True if the arrays are equal, false otherwise.
65
- */
66
- export declare const objectsAreEqual: (obj1: Experiment[], obj2: Experiment[]) => boolean;
67
- /**
68
- * A function to redirect the user to a new URL.
69
- *
70
- * @param {string} href - The URL to redirect to.
71
- * @returns {void}
72
- */
73
- export declare const defaultRedirectFn: (href: string) => string;
@@ -1,7 +0,0 @@
1
- import { DotExperiments } from './dot-experiments';
2
- import { EXPERIMENT_WINDOWS_KEY } from './shared/constants';
3
- declare global {
4
- interface Window {
5
- [EXPERIMENT_WINDOWS_KEY]: DotExperiments;
6
- }
7
- }