@dotcms/experiments 0.0.1-alpha.37 → 0.0.1-alpha.39
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.
- package/.babelrc +12 -0
- package/.eslintrc.json +26 -0
- package/jest.config.ts +11 -0
- package/package.json +4 -8
- package/project.json +55 -0
- package/src/lib/components/{DotExperimentHandlingComponent.d.ts → DotExperimentHandlingComponent.tsx} +20 -3
- package/src/lib/components/DotExperimentsProvider.spec.tsx +62 -0
- package/src/lib/components/{DotExperimentsProvider.d.ts → DotExperimentsProvider.tsx} +41 -3
- package/src/lib/components/withExperiments.tsx +52 -0
- package/src/lib/contexts/DotExperimentsContext.spec.tsx +42 -0
- package/src/lib/contexts/{DotExperimentsContext.d.ts → DotExperimentsContext.tsx} +5 -2
- package/src/lib/dot-experiments.spec.ts +285 -0
- package/src/lib/dot-experiments.ts +716 -0
- package/src/lib/hooks/useExperimentVariant.spec.tsx +111 -0
- package/src/lib/hooks/useExperimentVariant.ts +55 -0
- package/src/lib/hooks/useExperiments.ts +90 -0
- package/src/lib/shared/{constants.d.ts → constants.ts} +35 -18
- package/src/lib/shared/mocks/mock.ts +209 -0
- package/src/lib/shared/{models.d.ts → models.ts} +35 -2
- package/src/lib/shared/parser/parse.spec.ts +187 -0
- package/src/lib/shared/parser/parser.ts +171 -0
- package/src/lib/shared/persistence/index-db-database-handler.spec.ts +100 -0
- package/src/lib/shared/persistence/index-db-database-handler.ts +218 -0
- package/src/lib/shared/utils/DotLogger.ts +57 -0
- package/src/lib/shared/utils/memoize.spec.ts +49 -0
- package/src/lib/shared/utils/memoize.ts +49 -0
- package/src/lib/shared/utils/utils.spec.ts +142 -0
- package/src/lib/shared/utils/utils.ts +203 -0
- package/src/lib/standalone.spec.ts +36 -0
- package/src/lib/standalone.ts +28 -0
- package/tsconfig.json +20 -0
- package/tsconfig.lib.json +20 -0
- package/tsconfig.spec.json +9 -0
- package/vite.config.ts +41 -0
- package/index.esm.d.ts +0 -1
- package/index.esm.js +0 -7174
- package/src/lib/components/withExperiments.d.ts +0 -20
- package/src/lib/dot-experiments.d.ts +0 -289
- package/src/lib/hooks/useExperimentVariant.d.ts +0 -21
- package/src/lib/hooks/useExperiments.d.ts +0 -14
- package/src/lib/shared/mocks/mock.d.ts +0 -43
- package/src/lib/shared/parser/parser.d.ts +0 -54
- package/src/lib/shared/persistence/index-db-database-handler.d.ts +0 -87
- package/src/lib/shared/utils/DotLogger.d.ts +0 -15
- package/src/lib/shared/utils/memoize.d.ts +0 -7
- package/src/lib/shared/utils/utils.d.ts +0 -73
- package/src/lib/standalone.d.ts +0 -7
- /package/src/{index.d.ts → index.ts} +0 -0
|
@@ -1,20 +0,0 @@
|
|
|
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,289 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -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;
|
package/src/lib/standalone.d.ts
DELETED
|
File without changes
|