@dotcms/experiments 0.0.1-alpha.39 → 0.0.1-alpha.41

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.
Files changed (48) hide show
  1. package/index.esm.d.ts +1 -0
  2. package/index.esm.js +7174 -0
  3. package/package.json +10 -6
  4. package/src/lib/components/{DotExperimentHandlingComponent.tsx → DotExperimentHandlingComponent.d.ts} +3 -20
  5. package/src/lib/components/{DotExperimentsProvider.tsx → DotExperimentsProvider.d.ts} +3 -41
  6. package/src/lib/components/withExperiments.d.ts +20 -0
  7. package/src/lib/contexts/{DotExperimentsContext.tsx → DotExperimentsContext.d.ts} +2 -5
  8. package/src/lib/dot-experiments.d.ts +289 -0
  9. package/src/lib/hooks/useExperimentVariant.d.ts +21 -0
  10. package/src/lib/hooks/useExperiments.d.ts +14 -0
  11. package/src/lib/shared/{constants.ts → constants.d.ts} +18 -35
  12. package/src/lib/shared/mocks/mock.d.ts +43 -0
  13. package/src/lib/shared/{models.ts → models.d.ts} +2 -35
  14. package/src/lib/shared/parser/parser.d.ts +54 -0
  15. package/src/lib/shared/persistence/index-db-database-handler.d.ts +87 -0
  16. package/src/lib/shared/utils/DotLogger.d.ts +15 -0
  17. package/src/lib/shared/utils/memoize.d.ts +7 -0
  18. package/src/lib/shared/utils/utils.d.ts +73 -0
  19. package/src/lib/standalone.d.ts +7 -0
  20. package/.babelrc +0 -12
  21. package/.eslintrc.json +0 -26
  22. package/jest.config.ts +0 -11
  23. package/project.json +0 -55
  24. package/src/lib/components/DotExperimentsProvider.spec.tsx +0 -62
  25. package/src/lib/components/withExperiments.tsx +0 -52
  26. package/src/lib/contexts/DotExperimentsContext.spec.tsx +0 -42
  27. package/src/lib/dot-experiments.spec.ts +0 -285
  28. package/src/lib/dot-experiments.ts +0 -716
  29. package/src/lib/hooks/useExperimentVariant.spec.tsx +0 -111
  30. package/src/lib/hooks/useExperimentVariant.ts +0 -55
  31. package/src/lib/hooks/useExperiments.ts +0 -90
  32. package/src/lib/shared/mocks/mock.ts +0 -209
  33. package/src/lib/shared/parser/parse.spec.ts +0 -187
  34. package/src/lib/shared/parser/parser.ts +0 -171
  35. package/src/lib/shared/persistence/index-db-database-handler.spec.ts +0 -100
  36. package/src/lib/shared/persistence/index-db-database-handler.ts +0 -218
  37. package/src/lib/shared/utils/DotLogger.ts +0 -57
  38. package/src/lib/shared/utils/memoize.spec.ts +0 -49
  39. package/src/lib/shared/utils/memoize.ts +0 -49
  40. package/src/lib/shared/utils/utils.spec.ts +0 -142
  41. package/src/lib/shared/utils/utils.ts +0 -203
  42. package/src/lib/standalone.spec.ts +0 -36
  43. package/src/lib/standalone.ts +0 -28
  44. package/tsconfig.json +0 -20
  45. package/tsconfig.lib.json +0 -20
  46. package/tsconfig.spec.json +0 -9
  47. package/vite.config.ts +0 -41
  48. /package/src/{index.ts → index.d.ts} +0 -0
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dotcms/experiments",
3
- "version": "0.0.1-alpha.39",
3
+ "version": "0.0.1-alpha.41",
4
4
  "description": "Official JavaScript library to use Experiments with DotCMS.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/dotCMS/core.git#master"
7
+ "url": "git+https://github.com/dotCMS/core.git#main"
8
8
  },
9
9
  "keywords": [
10
10
  "dotCMS",
@@ -18,13 +18,17 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/dotCMS/core/issues"
20
20
  },
21
- "homepage": "https://github.com/dotCMS/core/tree/master/core-web/libs/sdk/experiments/README.md",
21
+ "homepage": "https://github.com/dotCMS/core/tree/main/core-web/libs/sdk/experiments/README.md",
22
22
  "dependencies": {
23
23
  "@jitsu/sdk-js": "^3.1.5"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": ">=18",
27
27
  "react-dom": ">=18",
28
- "@dotcms/client": "0.0.1-alpha.39"
29
- }
30
- }
28
+ "@dotcms/client": "0.0.1-alpha.41"
29
+ },
30
+ "module": "./index.esm.js",
31
+ "type": "module",
32
+ "main": "./index.esm.js",
33
+ "types": "./index.esm.d.ts"
34
+ }
@@ -1,11 +1,8 @@
1
+ /// <reference types="react" />
1
2
  import { DotcmsPageProps } from '@dotcms/react';
2
-
3
- import { useExperimentVariant } from '../hooks/useExperimentVariant';
4
-
5
3
  interface ExperimentHandlingProps extends DotcmsPageProps {
6
4
  WrappedComponent: React.ComponentType<DotcmsPageProps>;
7
5
  }
8
-
9
6
  /**
10
7
  * A React functional component that conditionally renders a WrappedComponent based on the
11
8
  * experiment variant state. It uses the `useExperimentVariant` hook to determine if there's a
@@ -20,19 +17,5 @@ interface ExperimentHandlingProps extends DotcmsPageProps {
20
17
  * @returns {React.ReactElement} A React element that either renders the WrappedComponent hidden or visible
21
18
  * based on the experiment variant.
22
19
  */
23
- export const DotExperimentHandlingComponent: React.FC<ExperimentHandlingProps> = ({
24
- WrappedComponent,
25
- ...props
26
- }) => {
27
- const { shouldWaitForVariant } = useExperimentVariant(props.pageContext.pageAsset);
28
-
29
- if (shouldWaitForVariant) {
30
- return (
31
- <div style={{ visibility: 'hidden' }}>
32
- <WrappedComponent {...props} />
33
- </div>
34
- );
35
- }
36
-
37
- return <WrappedComponent {...props} />;
38
- };
20
+ export declare const DotExperimentHandlingComponent: React.FC<ExperimentHandlingProps>;
21
+ export {};
@@ -1,17 +1,9 @@
1
- import { ReactElement, ReactNode, useEffect, useState } from 'react';
2
-
3
- import { isInsideEditor } from '@dotcms/client';
4
-
5
- import DotExperimentsContext from '../contexts/DotExperimentsContext';
6
- import { DotExperiments } from '../dot-experiments';
7
- import { useExperiments } from '../hooks/useExperiments';
1
+ import { ReactElement, ReactNode } from 'react';
8
2
  import { DotExperimentConfig } from '../shared/models';
9
-
10
3
  interface DotExperimentsProviderProps {
11
4
  children?: ReactNode;
12
5
  config: DotExperimentConfig;
13
6
  }
14
-
15
7
  /**
16
8
  * `DotExperimentsProvider` is a component that uses React's Context API to provide
17
9
  * an instance of `DotExperiments` to all of its descendants.
@@ -51,35 +43,5 @@ interface DotExperimentsProviderProps {
51
43
  * @returns {ReactElement} The provider component, which should wrap the components
52
44
  * that need access to the `DotExperiments` instance.
53
45
  */
54
- export const DotExperimentsProvider = ({
55
- children,
56
- config
57
- }: DotExperimentsProviderProps): ReactElement => {
58
- const [instance, setInstance] = useState<DotExperiments | null>(null);
59
-
60
- // Run Experiments detection
61
- useExperiments(instance);
62
-
63
- // Initialize the DotExperiments instance
64
- useEffect(() => {
65
- const insideEditor = isInsideEditor();
66
-
67
- if (!insideEditor) {
68
- const dotExperimentsInstance = DotExperiments.getInstance(config);
69
-
70
- dotExperimentsInstance.ready().then(() => {
71
- setInstance(dotExperimentsInstance);
72
- });
73
- } else {
74
- if (config.debug) {
75
- console.warn(
76
- 'DotExperimentsProvider: DotExperiments instance not initialized because it is inside the editor.'
77
- );
78
- }
79
- }
80
- }, [config]);
81
-
82
- return (
83
- <DotExperimentsContext.Provider value={instance}>{children}</DotExperimentsContext.Provider>
84
- );
85
- };
46
+ export declare const DotExperimentsProvider: ({ children, config }: DotExperimentsProviderProps) => ReactElement;
47
+ export {};
@@ -0,0 +1,20 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { DotcmsPageProps } from '@dotcms/react';
3
+ import { DotExperimentConfig } from '../shared/models';
4
+ export interface PageProviderProps {
5
+ readonly entity: any;
6
+ readonly children: ReactNode;
7
+ }
8
+ /**
9
+ * Wraps a given component with experiment handling capabilities using the 'useExperimentVariant' hook.
10
+ * This HOC checks if the entity's assigned experiment variant differs from the currently displayed variant.
11
+ * If they differ, the content is hidden until the correct variant is displayed. Once the assigned variant
12
+ * matches the displayed variant, the content of the WrappedComponent is shown.
13
+ *
14
+ * @param {React.ComponentType<DotcmsPageProps>} WrappedComponent - The component to be enhanced.
15
+ * @param {DotExperimentConfig} config - Configuration for experiment handling, including any necessary
16
+ * redirection functions or other settings.
17
+ * @returns {React.FunctionComponent<DotcmsPageProps>} A component that wraps the original component,
18
+ * adding experiment handling based on the specified configuration.
19
+ */
20
+ export declare const withExperiments: (WrappedComponent: React.ComponentType<DotcmsPageProps>, config: DotExperimentConfig) => (props: DotcmsPageProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,5 @@
1
- import { createContext } from 'react';
2
-
1
+ /// <reference types="react" />
3
2
  import { DotExperiments } from '../dot-experiments';
4
-
5
3
  /**
6
4
  * `DotExperimentsContext` is a React context that is designed to provide an instance of
7
5
  * `DotExperiments` to all of the components within its tree that are Consumers of this context.
@@ -11,6 +9,5 @@ import { DotExperiments } from '../dot-experiments';
11
9
  *
12
10
  * @see {@link https://reactjs.org/docs/context.html|React Context}
13
11
  */
14
- const DotExperimentsContext = createContext<DotExperiments | null>(null);
15
-
12
+ declare const DotExperimentsContext: import("react").Context<DotExperiments | null>;
16
13
  export default DotExperimentsContext;
@@ -0,0 +1,289 @@
1
+ import { DotExperimentConfig, Experiment, Variant } from './shared/models';
2
+ /**
3
+ * `DotExperiments` is a Typescript class to handles all operations related to fetching, storing, parsing, and navigating
4
+ * data for Experiments (A/B Testing).
5
+ *
6
+ * It requires a configuration object for instantiation, please instance it using the method `getInstance` sending
7
+ * an object with `api-key`, `server` and `debug`.
8
+ *
9
+ * Here's an example of how you can instantiate DotExperiments class:
10
+ * @example
11
+ * ```typescript
12
+ * const instance = DotExperiments.getInstance({
13
+ * server: "yourServerUrl",
14
+ * "api-key": "yourApiKey"
15
+ * });
16
+ * ```
17
+ *
18
+ * @export
19
+ * @class DotExperiments
20
+ *
21
+ */
22
+ export declare class DotExperiments {
23
+ private readonly config;
24
+ /**
25
+ * The instance of the DotExperiments class.
26
+ * @private
27
+ */
28
+ private static instance;
29
+ /**
30
+ * Represents the default configuration for the DotExperiment library.
31
+ * @property {boolean} trackPageView - Specifies whether to track page view or not. Default value is true.
32
+ */
33
+ private static readonly defaultConfig;
34
+ /**
35
+ * Represents the promise for the initialization process.
36
+ * @private
37
+ */
38
+ private initializationPromise;
39
+ /**
40
+ * Represents the analytics client for Analytics.
41
+ * @private
42
+ */
43
+ private analytics;
44
+ /**
45
+ * Class representing a database handler for IndexDB.
46
+ * @class
47
+ */
48
+ private persistenceHandler;
49
+ /**
50
+ * Represents the stored data in the IndexedDB.
51
+ * @private
52
+ */
53
+ private experimentsAssigned;
54
+ /**
55
+ * A logger utility for logging messages.
56
+ *
57
+ * @class
58
+ */
59
+ private logger;
60
+ /**
61
+ * Represents the current location.
62
+ * @private
63
+ */
64
+ private currentLocation;
65
+ /**
66
+ * Represents the previous location.
67
+ *
68
+ * @type {string}
69
+ */
70
+ private prevLocation;
71
+ private constructor();
72
+ /**
73
+ * Retrieves the array of experiments assigned to an instance of the class.
74
+ *
75
+ * @return {Experiment[]} An array containing the experiments assigned to the instance.
76
+ */
77
+ get experiments(): Experiment[];
78
+ /**
79
+ * Returns a custom redirect function. If a custom redirect function is not configured,
80
+ * the default redirect function will be used.
81
+ *
82
+ * @return {function} A function that accepts a URL string parameter and performs a redirect.
83
+ * If no parameter is provided, the function will not perform any action.
84
+ */
85
+ get customRedirectFn(): (url: string) => void;
86
+ /**
87
+ * Retrieves the current location.
88
+ *
89
+ * @returns {Location} The current location.
90
+ */
91
+ get location(): Location;
92
+ /**
93
+ * Retrieves instance of DotExperiments class if it doesn't exist create a new one.
94
+ * If the instance does not exist, it creates a new instance with the provided configuration and calls the `getExperimentData` method.
95
+ *
96
+ * @param {DotExperimentConfig} config - The configuration object for initializing the DotExperiments instance.
97
+ * @return {DotExperiments} - The instance of the DotExperiments class.
98
+ */
99
+ static getInstance(config?: DotExperimentConfig): DotExperiments;
100
+ /**
101
+ * Waits for the initialization process to be completed.
102
+ *
103
+ * @return {Promise<void>} A Promise that resolves when the initialization is ready.
104
+ */
105
+ ready(): Promise<void>;
106
+ /**
107
+ * This method appends variant parameters to navigation links based on the provided navClass.
108
+ *
109
+ * Note: In order for this method's functionality to apply, you need to define a class for the navigation elements (anchors)
110
+ * to which you would like this functionality applied and pass it as an argument when calling this method.
111
+ *
112
+ * @param {string} navClass - The class of the navigation elements to which variant parameters should be appended. Such elements should be anchors (`<a>`).
113
+ *
114
+ * @example
115
+ * <ul class="navbar-nav me-auto mb-2 mb-md-0">
116
+ * <li class="nav-item">
117
+ * <a class="nav-link " aria-current="page" href="/">Home</a>
118
+ * </li>
119
+ * <li class="nav-item ">
120
+ * <a class="nav-link active" href="/blog">Travel Blog</a>
121
+ * </li>
122
+ * <li class="nav-item">
123
+ * <a class="nav-link" href="/destinations">Destinations</a>
124
+ * </li>
125
+ * </ul>
126
+ *
127
+ * dotExperiment.ready().then(() => {
128
+ * dotExperiment.appendVariantParams('.navbar-nav .nav-link');
129
+ * });
130
+ * appendVariantParams('nav-item-class');
131
+ *
132
+ * @returns {void}
133
+ */
134
+ appendVariantParams(navClass: string): void;
135
+ /**
136
+ * Retrieves the current debug status.
137
+ *
138
+ * @private
139
+ * @returns {boolean} - The debug status.
140
+ */
141
+ getIsDebugActive(): boolean;
142
+ /**
143
+ * Updates the current location and checks if a variant should be applied.
144
+ * Redirects to the variant URL if necessary.
145
+ *
146
+ * @param {Location} location - The new location.
147
+ * @param redirectFunction
148
+ */
149
+ locationChanged(location: Location, redirectFunction?: (url: string) => void): Promise<void>;
150
+ /**
151
+ * Tracks a page view event in the analytics system.
152
+ *
153
+ * @return {void}
154
+ */
155
+ trackPageView(): void;
156
+ /**
157
+ * This method is used to retrieve the variant associated with a given URL.
158
+ *
159
+ * It checks if the URL is part of an experiment by verifying it against an experiment's regex. If the URL matches the regex of an experiment,
160
+ * it returns the variant attached to that experiment; otherwise, it returns null.
161
+ *
162
+ * @param {string | null} path - The URL to check for a variant. This should be the path of the URL.
163
+ *
164
+ * @returns {Variant | null} The variant associated with the URL if it exists, null otherwise.
165
+ */
166
+ getVariantFromHref(path: string | null): Variant | null;
167
+ /**
168
+ * Returns the experiment variant name as a URL search parameter.
169
+ *
170
+ * @param {string|null} path - The path to the current page.
171
+ * @returns {URLSearchParams} - The URL search parameters containing the experiment variant name.
172
+ */
173
+ getVariantAsQueryParam(path: string | null): URLSearchParams;
174
+ /**
175
+ * Determines whether a page view should be tracked.
176
+ *
177
+ * @private
178
+ * @returns {boolean} True if a page view should be tracked, otherwise false.
179
+ */
180
+ private shouldTrackPageView;
181
+ /**
182
+ * Tracks an event using the analytics service.
183
+ *
184
+ * @param {string} typeName - The type of event to track.
185
+ * @param {EventPayload} [payload] - Optional payload associated with the event.
186
+ * @return {void}
187
+ */
188
+ private track;
189
+ /**
190
+ * Initializes the application using lazy initialization. This method performs
191
+ * necessary setup steps and should be invoked to ensure proper execution of the application.
192
+ *
193
+ * Note: This method uses lazy initialization. Make sure to call this method to ensure
194
+ * the application works correctly.
195
+ *
196
+ * @return {Promise<void>} A promise that resolves when the initialization is complete.
197
+ */
198
+ private initialize;
199
+ /**
200
+ * Fetches experiments from the server.
201
+ *
202
+ * @private
203
+ * @returns {Promise<AssignedExperiments>} - The entity object returned from the server.
204
+ * @throws {Error} - If an HTTP error occurs or an error occurs during the fetch request.
205
+ */
206
+ private getExperimentsFromServer;
207
+ /**
208
+ * This method is responsible for retrieving and persisting experiment data from the server to the local indexDB database.
209
+ *
210
+ * - Checks whether making a request to the server to fetch experiment data is required.
211
+ * - Sends the request to the server for data if required.
212
+ * - Parses the fetched data to the form required for storage in the database.
213
+ * - Persists the data in the indexDB database.
214
+ *
215
+ * @private
216
+ * @method verifyExperimentData
217
+ * @async
218
+ * @throws {Error} Throws an error with details if there is any failure in loading the experiments or during their persistence in indexDB.
219
+ *
220
+ * @returns {Promise<void>} An empty promise that fulfills once the experiment data has been successfully loaded and persisted.
221
+ */
222
+ private verifyExperimentData;
223
+ /**
224
+ * Persists the parsed experiment data into the indexDB database.
225
+ *
226
+ * The method does the following:
227
+ * - Receives the parsed data.
228
+ * - Updates the creation date.
229
+ * - Clears existing data from the indexDB database.
230
+ * - Stores the new data in the indexDB database.
231
+ *
232
+ * If there are no experiments in the received data, the method will not attempt to clear or persist anything and will return immediately.
233
+ *.
234
+ *
235
+ * @note This method utilizes Promises for the asynchronous handling of data persistence. Errors during data persistence are caught and logged, but not re-thrown.
236
+ *
237
+ * @private
238
+ * @method persistExperiments
239
+ * @throws Nothing – Errors are caught and logged, but not re-thrown.
240
+ *
241
+ * @param experiments
242
+ */
243
+ private persistExperiments;
244
+ /**
245
+ * Initializes the database handler.
246
+ *
247
+ * This private method instantiates the class handling the IndexDB database
248
+ * and assigns this instance to 'persistenceHandler'.
249
+ *
250
+ * @private
251
+ */
252
+ private initializeDatabaseHandler;
253
+ /**
254
+ * Initializes the Jitsu analytics client.
255
+ *
256
+ * This private method sets up the Jitsu client responsible for sending events
257
+ * to the server with the provided configuration. It also uses the parsed data
258
+ * and registers it as global within Jitsu.
259
+ *
260
+ * @private
261
+ */
262
+ private initAnalyticsClient;
263
+ /**
264
+ * Updates the analytics client's data using the experiments data
265
+ * currently available in the IndexDB database, based on the current location.
266
+ *
267
+ * Retrieves and processes the experiments information according to the
268
+ * current location into a suitable format for `analytics.set()`.
269
+ *
270
+ * @private
271
+ * @method refreshAnalyticsForCurrentLocation
272
+ * @returns {void}
273
+ */
274
+ private refreshAnalyticsForCurrentLocation;
275
+ /**
276
+ * Determines whether analytics should be checked.
277
+ *
278
+ * @private
279
+ * @returns {Promise<boolean>} A boolean value indicating whether analytics should be checked.
280
+ */
281
+ private shouldFetchNewData;
282
+ /**
283
+ * Retrieves persisted data from the database.
284
+ *
285
+ * @private
286
+ * @returns {Promise<void>} A promise that resolves with no value.
287
+ */
288
+ private getPersistedData;
289
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A React Hook that determines whether to wait for the correct variant in an A/B testing scenario.
3
+ * This is used to avoid flickering - showing the original content before redirecting to the assigned variant.
4
+ *
5
+ * The hook uses the running experiment id and viewAs (containing variantId) from the provided data.
6
+ * It then works with the DotExperimentsContext to synchronize between the assigned variant and the one requested.
7
+ * If the hook is executed inside an editor or if no running experiment id is provided, it immediately signals not to wait for the variant.
8
+ * Similarly, if the assigned variant matches the requested one, it signals not to wait for the variant.
9
+ * By default, the hook signals to wait for the variant.
10
+ *
11
+ * @param {Object} data - An object containing the runningExperimentId and viewAs (containing variantId).
12
+ * @returns {Object} An object with a function `shouldWaitForVariant` that, when called, returns `true` if it should wait for the correct variant, `false` otherwise.
13
+ */
14
+ export declare const useExperimentVariant: (data: {
15
+ runningExperimentId?: string;
16
+ viewAs: {
17
+ variantId: string;
18
+ };
19
+ }) => {
20
+ shouldWaitForVariant: boolean;
21
+ };
@@ -0,0 +1,14 @@
1
+ import { DotExperiments } from '../dot-experiments';
2
+ /**
3
+ * Custom hook `useExperiments`.
4
+ *
5
+ * This hook is designed to handle changes in the location of the current DotExperiments
6
+ * instance and set a global click handler that redirects the application when an element with an
7
+ * assigned variant is clicked.
8
+ *
9
+ * It also manages adding or removing the experimentation query parameter from the URL as
10
+ * appropriate when a click occurs.
11
+ *
12
+ * @returns {void}
13
+ */
14
+ export declare const useExperiments: (instance: DotExperiments | null) => void;
@@ -3,39 +3,34 @@
3
3
  *
4
4
  * @constant {string}
5
5
  */
6
- export const EXPERIMENT_WINDOWS_KEY = 'dotExperiment';
7
-
6
+ export declare const EXPERIMENT_WINDOWS_KEY = "dotExperiment";
8
7
  /**
9
8
  * The default variant name for an experiment.
10
9
  *
11
10
  * @type {string}
12
11
  * @constant
13
12
  */
14
- export const EXPERIMENT_DEFAULT_VARIANT_NAME = 'DEFAULT';
15
-
13
+ export declare const EXPERIMENT_DEFAULT_VARIANT_NAME = "DEFAULT";
16
14
  /**
17
15
  * The key used to store or retrieve the information in the SessionStore
18
16
  *
19
17
  * @constant {string}
20
18
  */
21
- export const EXPERIMENT_QUERY_PARAM_KEY = 'variantName';
22
-
19
+ export declare const EXPERIMENT_QUERY_PARAM_KEY = "variantName";
23
20
  /**
24
21
  * The key used to store or retrieve the information in the SessionStore
25
22
  * indicating whether an experiment has already been checked.
26
23
  *
27
24
  * @constant {string}
28
25
  */
29
- export const EXPERIMENT_ALREADY_CHECKED_KEY = 'experimentAlreadyCheck';
30
-
26
+ export declare const EXPERIMENT_ALREADY_CHECKED_KEY = "experimentAlreadyCheck";
31
27
  /**
32
28
  * EXPERIMENT_FETCH_EXPIRE_TIME is a constant that represents the name of the variable used to store
33
29
  * the expire time for experiment fetching. It is a string value 'experimentFetchExpireTime'.
34
30
  *
35
31
  * @constant {string}
36
32
  */
37
- export const EXPERIMENT_FETCH_EXPIRE_TIME_KEY = 'experimentFetchExpireTime';
38
-
33
+ export declare const EXPERIMENT_FETCH_EXPIRE_TIME_KEY = "experimentFetchExpireTime";
39
34
  /**
40
35
  * The duration in milliseconds for which data should be stored in the local storage.
41
36
  *
@@ -44,34 +39,26 @@ export const EXPERIMENT_FETCH_EXPIRE_TIME_KEY = 'experimentFetchExpireTime';
44
39
  * @default 86400000 (A day)
45
40
  *
46
41
  */
47
- export const LOCAL_STORAGE_TIME_DURATION_MILLISECONDS = 86400 * 1000;
48
-
42
+ export declare const LOCAL_STORAGE_TIME_DURATION_MILLISECONDS: number;
49
43
  /**
50
44
  * The name of the experiment script file.
51
45
  *
52
46
  * @constant {string}
53
47
  */
54
- export const EXPERIMENT_SCRIPT_FILE_NAME = 'dot-experiments.min.iife.js';
55
-
48
+ export declare const EXPERIMENT_SCRIPT_FILE_NAME = "dot-experiments.min.iife.js";
56
49
  /**
57
50
  * The prefix used for the experiment script data attributes.
58
51
  *
59
52
  * @constant {string}
60
53
  */
61
- export const EXPERIMENT_SCRIPT_DATA_PREFIX = 'data-experiment-';
62
-
54
+ export declare const EXPERIMENT_SCRIPT_DATA_PREFIX = "data-experiment-";
63
55
  /**
64
56
  * Array containing the allowed data attributes for an experiment.
65
57
  *
66
58
  * @type {Array.<string>}
67
59
  * @constant
68
60
  */
69
- export const EXPERIMENT_ALLOWED_DATA_ATTRIBUTES = [
70
- EXPERIMENT_SCRIPT_DATA_PREFIX + 'api-key',
71
- EXPERIMENT_SCRIPT_DATA_PREFIX + 'server',
72
- EXPERIMENT_SCRIPT_DATA_PREFIX + 'debug'
73
- ];
74
-
61
+ export declare const EXPERIMENT_ALLOWED_DATA_ATTRIBUTES: string[];
75
62
  /**
76
63
  * API_EXPERIMENTS_URL
77
64
  *
@@ -80,33 +67,29 @@ export const EXPERIMENT_ALLOWED_DATA_ATTRIBUTES = [
80
67
  * @type {string}
81
68
  * @constant
82
69
  */
83
- export const API_EXPERIMENTS_URL = 'api/v1/experiments/isUserIncluded';
84
-
70
+ export declare const API_EXPERIMENTS_URL = "api/v1/experiments/isUserIncluded";
85
71
  /**
86
72
  * The name of the experiment database store in indexDB.
87
73
  *
88
74
  * @type {string}
89
75
  * @constant
90
76
  */
91
- export const EXPERIMENT_DB_STORE_NAME = 'dotExperimentStore';
92
-
77
+ export declare const EXPERIMENT_DB_STORE_NAME = "dotExperimentStore";
93
78
  /**
94
79
  * The path to the key in the database IndexDB representing the running experiment data.
95
80
  * @type {string}
96
81
  */
97
- export const EXPERIMENT_DB_KEY_PATH = 'running_experiment';
98
-
82
+ export declare const EXPERIMENT_DB_KEY_PATH = "running_experiment";
99
83
  /**
100
84
  * Enumeration of debug levels.
101
85
  *
102
86
  * @enum {string}
103
87
  * @readonly
104
88
  */
105
- export enum DEBUG_LEVELS {
106
- NONE = 'NONE',
107
- DEBUG = 'DEBUG',
108
- WARN = 'WARN',
109
- ERROR = 'ERROR'
89
+ export declare enum DEBUG_LEVELS {
90
+ NONE = "NONE",
91
+ DEBUG = "DEBUG",
92
+ WARN = "WARN",
93
+ ERROR = "ERROR"
110
94
  }
111
-
112
- export const PAGE_VIEW_EVENT_NAME = 'pageview';
95
+ export declare const PAGE_VIEW_EVENT_NAME = "pageview";
@@ -0,0 +1,43 @@
1
+ import { Experiment, ExperimentEvent, IsUserIncludedApiResponse } from '../models';
2
+ /**
3
+ * Represents the response object for the IsUserIncluded API.
4
+ * @typedef {Object} IsUserIncludedResponse
5
+ * @property {IsUserIncludedApiResponse} entity - The response entity.
6
+ * @property {string[]} errors - Array of error messages, if any.
7
+ * @property {Object} i18nMessagesMap - Map of internationalization messages.
8
+ * @property {string[]} messages - Array of additional messages, if any.
9
+ */
10
+ export declare const IsUserIncludedResponse: IsUserIncludedApiResponse;
11
+ export declare const NewIsUserIncludedResponse: IsUserIncludedApiResponse;
12
+ export declare const After15DaysIsUserIncludedResponse: IsUserIncludedApiResponse;
13
+ export declare const NoExperimentsIsUserIncludedResponse: IsUserIncludedApiResponse;
14
+ export declare const MOCK_CURRENT_TIMESTAMP = 1704096000000;
15
+ export declare const TIME_15_DAYS_MILLISECONDS: number;
16
+ export declare const TIME_5_DAYS_MILLISECONDS: number;
17
+ export declare const MockDataStoredIndexDB: Experiment[];
18
+ export declare const MockDataStoredIndexDBNew: Experiment[];
19
+ export declare const MockDataStoredIndexDBWithNew: Experiment[];
20
+ export declare const MockDataStoredIndexDBWithNew15DaysLater: Experiment[];
21
+ /**
22
+ * Represents an event that indicates the expected experiments parsed from a response to send to Analytics.
23
+ *
24
+ * @typedef {Object} ExpectedExperimentsParsedEvent
25
+ * @property {ExperimentEvent[]} experiments - An array of experiment events.
26
+ */
27
+ export declare const ExpectedExperimentsParsedEvent: ExperimentEvent[];
28
+ /**
29
+ * Represents a mock location object.
30
+ *
31
+ * @typedef {Object} LocationMock
32
+ * @property {string} href - The complete URL.
33
+ *
34
+ */
35
+ export declare const LocationMock: Location;
36
+ export declare const sessionStorageMock: {
37
+ getItem: (key: string) => string | null;
38
+ setItem: (key: string, value: string) => void;
39
+ removeItem: (key: string) => void;
40
+ clear: () => void;
41
+ key: (index: number) => string | null;
42
+ readonly length: number;
43
+ };