@kameleoon/javascript-sdk-core 5.15.0 → 5.16.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.
@@ -1,6 +1,6 @@
1
1
  import { JSONType } from './clientConfiguration';
2
2
  import { CustomData, KameleoonDataType } from './kameleoonData';
3
- import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType, KameleoonVariationType, VariationType, GetVariationParamsType, GetVariationsParamsType, IsFeatureFlagActiveParamsType, SetForcedVariationParametersType, FlushParamsType } from './types';
3
+ import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType, KameleoonVariationType, GetVariationParamsType, GetVariationsParamsType, IsFeatureFlagActiveParamsType, SetForcedVariationParametersType, FlushParamsType, DataFile, Variable, Variation } from './types';
4
4
  import { IKameleoonClient } from './kameleoonClientInterface';
5
5
  import { EventCallbackType, EventType } from './eventManager';
6
6
  import { Tracker } from './tracking';
@@ -35,12 +35,12 @@ export declare class KameleoonClient implements IKameleoonClient {
35
35
  flush(params?: string | FlushParamsType): void;
36
36
  getFeatureFlags(): FeatureFlagType[];
37
37
  getVisitorFeatureFlags(visitorCode: string): FeatureFlagType[];
38
- getVariation({ visitorCode, featureKey, track, }: GetVariationParamsType): VariationType;
39
- getVariations({ visitorCode, onlyActive, track, }: GetVariationsParamsType): Map<string, VariationType>;
38
+ getVariation({ visitorCode, featureKey, track, }: GetVariationParamsType): Variation;
39
+ getVariations({ visitorCode, onlyActive, track, }: GetVariationsParamsType): Map<string, Variation>;
40
40
  getActiveFeatureFlags(visitorCode: string): Map<string, KameleoonVariationType>;
41
41
  getFeatureFlagVariationKey(visitorCode: string, featureKey: string): string;
42
42
  getFeatureFlagVariable({ visitorCode, featureKey, variableKey, }: GetFeatureFlagVariableParamsType): FeatureFlagVariableType;
43
- getFeatureFlagVariables(visitorCode: string, featureKey: string): FeatureVariableResultType[];
43
+ getFeatureFlagVariables(visitorCode: string, featureKey: string): Variable[];
44
44
  isFeatureFlagActive(visitorCode: string, featureKey: string): boolean;
45
45
  isFeatureFlagActive({ visitorCode, featureKey, track, }: IsFeatureFlagActiveParamsType): boolean;
46
46
  getRemoteData(key: string): Promise<JSONType>;
@@ -51,6 +51,7 @@ export declare class KameleoonClient implements IKameleoonClient {
51
51
  setLogLevel(level: LogLevel): void;
52
52
  setForcedVariation({ visitorCode, experimentId, variationKey, forceTargeting, }: SetForcedVariationParametersType): void;
53
53
  evaluateAudiences(visitorCode: string): void;
54
+ getDataFile(): DataFile;
54
55
  protected setUserConsent({ visitorCode, consent, setData, }: SetUserConsentParametersType): void;
55
56
  private updateConsentData;
56
57
  protected _isConsentProvided(visitorCode: string): boolean;
@@ -1,7 +1,7 @@
1
1
  import { JSONType } from './clientConfiguration';
2
2
  import { EventCallbackType, EventType } from './eventManager';
3
3
  import { CustomData, KameleoonDataType } from './kameleoonData';
4
- import { FeatureFlagType, FeatureFlagVariableType, FeatureVariableResultType, GetFeatureFlagVariableParamsType, GetVariationParamsType, GetVariationsParamsType, GetVisitorWarehouseAudienceParamsType, IsFeatureFlagActiveParamsType, KameleoonVariationType, RemoteVisitorDataParamsType, SetForcedVariationParametersType, TrackConversionParamsType, VariationType } from './types';
4
+ import { DataFile, FeatureFlagType, FeatureFlagVariableType, GetFeatureFlagVariableParamsType, GetVariationParamsType, GetVariationsParamsType, GetVisitorWarehouseAudienceParamsType, IsFeatureFlagActiveParamsType, KameleoonVariationType, RemoteVisitorDataParamsType, SetForcedVariationParametersType, TrackConversionParamsType, Variable, Variation } from './types';
5
5
  import { LogLevel } from './logging';
6
6
  /**
7
7
  * @interface an interface of KameleoonClient instance
@@ -166,7 +166,7 @@ export interface IKameleoonClient {
166
166
  *
167
167
  * @param {GetVariationParamsType} parameters - an object with parameters of a type `GetVariationParamsType`, see the type for details.
168
168
  *
169
- * @returns {VariationType} a variation object containing feature flag `key`, `id`, `experimentId` and `variables`, which is a `Map` of variable keys and values
169
+ * @returns {Variation} a variation object containing feature flag `key`, `id`, `experimentId` and `variables`, which is a `Map` of variable keys and values
170
170
  * @throws `KameleoonError` with one of the following `type` s:
171
171
  *
172
172
  * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
@@ -175,7 +175,7 @@ export interface IKameleoonClient {
175
175
  * - `KameleoonException.FeatureFlagConfigurationNotFound` - No feature flag was found for provided `featureKey`
176
176
  * - `KameleoonException.FeatureFlagEnvironmentDisabled` - The feature flag is disabled for the current environment
177
177
  * */
178
- getVariation: ({ visitorCode, featureKey, track, }: GetVariationParamsType) => VariationType;
178
+ getVariation: ({ visitorCode, featureKey, track, }: GetVariationParamsType) => Variation;
179
179
  /**
180
180
  * @method getVariation - returns all variations for the visitor under `visitorCode` for all the feature flags, this method includes targeting check, finding the according variations exposed to the visitor and saving them to storage. By default the method obtains all the variations, but if `onlyActive` is set to `true`, only active variations will be returned (those that are not `off`)
181
181
  *
@@ -184,14 +184,14 @@ export interface IKameleoonClient {
184
184
  *
185
185
  * @param {GetVariationsParamsType} parameters - an object with parameters of a type `GetVariationsParamsType`, see the type for details.
186
186
  *
187
- * @returns {Map<string, VariationType>} a `Map` with variation keys and values, each value contains an object with feature flag `key`, `id`, `experimentId` and `variables`, which is a `Map` of variable keys and values
187
+ * @returns {Map<string, Variation>} a `Map` with variation keys and values, each value contains an object with feature flag `key`, `id`, `experimentId` and `variables`, which is a `Map` of variable keys and values
188
188
  * @throws `KameleoonError` with one of the following `type` s:
189
189
  *
190
190
  * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
191
191
  * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty
192
192
  * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call
193
193
  */
194
- getVariations: ({ visitorCode, onlyActive, track, }: GetVariationsParamsType) => Map<string, VariationType>;
194
+ getVariations: ({ visitorCode, onlyActive, track, }: GetVariationsParamsType) => Map<string, Variation>;
195
195
  /**
196
196
  * @deprecated this method is deprecated and will be removed in the next major release. Please use `getVariation` instead.
197
197
  * @method getFeatureFlagVariationKey - returns variation key for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request
@@ -241,7 +241,7 @@ export interface IKameleoonClient {
241
241
  *
242
242
  * @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters
243
243
  * @param {string} featureKey - a unique key for feature flag
244
- * @returns {FeatureVariableResultType[]} a list of variable objects containing `key`, `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.
244
+ * @returns {Variable[]} a list of variable objects containing `key`, `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.
245
245
  * @throws `KameleoonError` with one of the following `type` s:
246
246
  *
247
247
  * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded
@@ -253,7 +253,7 @@ export interface IKameleoonClient {
253
253
  * - `KameleoonException.JSONParse` - Couldn't parse JSON value
254
254
  * - `KameleoonException.NumberParse` - Couldn't parse Number value
255
255
  */
256
- getFeatureFlagVariables: (visitorCode: string, featureKey: string) => FeatureVariableResultType[];
256
+ getFeatureFlagVariables: (visitorCode: string, featureKey: string) => Variable[];
257
257
  /**
258
258
  * @method getRemoteData - returns a data which is stored for specified siteCode on a remote Kameleoon server.
259
259
  * @param {string} key - unique key that the data you try to get is associated with.
@@ -338,4 +338,10 @@ export interface IKameleoonClient {
338
338
  * - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed its `initialize` call
339
339
  */
340
340
  evaluateAudiences(visitorCode: string): void;
341
+ /**
342
+ * @method getDataFile - retrieves the current SDK configuration (also known as the data file),
343
+ * containing all feature flags and their variations.
344
+ * @returns {DataFile} - The data file object containing the configuration details.
345
+ */
346
+ getDataFile(): DataFile;
341
347
  }
@@ -1,6 +1,7 @@
1
1
  import { VisitType } from '../requester';
2
2
  import { ConversionDataType, ConversionParametersType, IKameleoonData } from './types';
3
3
  import { TrackingStatus } from '../types';
4
+ import { CustomData } from '../kameleoonData/customData';
4
5
  /**
5
6
  * @class
6
7
  * Conversion - a class for creating an instance for conversion tracking
@@ -20,6 +21,7 @@ export declare class Conversion implements IKameleoonData {
20
21
  set _id(id: number);
21
22
  set _nonce(nonce: string);
22
23
  get url(): string;
24
+ get _metadata(): CustomData[] | undefined;
23
25
  get data(): ConversionDataType;
24
26
  private _encodeMetadata;
25
27
  /**
@@ -6,12 +6,13 @@ import { TrackingStatus } from '../types';
6
6
  * CustomData - a class for creating an instance for user's custom data
7
7
  * */
8
8
  export declare class CustomData implements IKameleoonData {
9
+ static readonly UNDEFINED_INDEX = -1;
9
10
  private _status;
10
- private index;
11
+ private _index;
11
12
  private value;
12
13
  private isIdentifier;
13
14
  private overwrite;
14
- private name?;
15
+ private _name?;
15
16
  /**
16
17
  * @param {number|string} indexOrName - either:
17
18
  * - `number` — an index of custom data (configured in *Advanced Tools* section of Kameleoon Application)
@@ -68,8 +69,18 @@ export declare class CustomData implements IKameleoonData {
68
69
  static _updateFromVisit(visit: VisitType, dataMap: Map<number, CustomData>): void;
69
70
  /**
70
71
  * @private
71
- * @method _index - an internal setter for setting index of custom data
72
+ * @method index - an internal setter for setting index of custom data
72
73
  * @param {number} value - an index value
73
74
  * */
74
- set _index(value: number);
75
+ set index(value: number);
76
+ /**
77
+ * @private
78
+ * @method index - an internal getter for index of custom data
79
+ * */
80
+ get index(): number;
81
+ /**
82
+ * @private
83
+ * @method name - an internal getter for a name of custom data
84
+ * */
85
+ get name(): string | undefined;
75
86
  }
@@ -60,6 +60,7 @@ export declare class DataManager implements IDataManager {
60
60
  private mutUpdateTargetingData;
61
61
  private cleanupData;
62
62
  private processCustomData;
63
+ private trySetCustomDataIndexByName;
63
64
  get unsentDataVisitors(): string[];
64
65
  get identifierCustomDataIndex(): number | null;
65
66
  get trees(): Map<string, Tree>;
package/dist/types.d.ts CHANGED
@@ -228,32 +228,52 @@ export type FeatureFlagType = {
228
228
  key: string;
229
229
  };
230
230
  /**
231
+ * @deprecated Use `Variable` instead.
232
+ *
231
233
  * @type `KameleoonVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
232
234
  * */
233
235
  export type KameleoonVariableType = FeatureVariableResultType;
236
+ /**
237
+ * @type `Variable` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
238
+ * */
239
+ export type Variable = FeatureVariableResultType;
234
240
  /**
235
241
  * @type `KameleoonVariationType` - object containing information about the variation and its variables
242
+ * @param {string} name - name of the variation
236
243
  * @param {string} key - key of the variation
237
244
  * @param {number | null} id - id of the variation or `null` if the visitor hit default variation
238
245
  * @param {number | null} experimentId - id of the experiment or `null` if the visitor hit default variation
239
- * @param {KameleoonVariableType[]} variables - array of variables for the variation
246
+ * @param {Variable[]} variables - array of variables for the variation
240
247
  * */
241
248
  export type KameleoonVariationType = {
249
+ name?: string;
242
250
  key: string;
243
251
  id: number | null;
244
252
  experimentId: number | null;
245
- variables: KameleoonVariableType[];
253
+ variables: Variable[];
246
254
  };
247
255
  /**
256
+ * @deprecated Use `Variation` instead.
257
+ *
248
258
  * @type `VariationType` - an object containing information about the variation and its variables
259
+ * @param {string} name - name of the variation
249
260
  * @param {string} key - key of the variation
250
261
  * @param {number | null} id - id of the variation or `null` if the visitor hit default variation
251
262
  * @param {number | null} experimentId - id of the experiment or `null` if the visitor hit default variation
252
- * @param {Map<string, KameleoonVariableType>} variables - map of variables for the variation, where key is the variable key and value is the variable object
263
+ * @param {Map<string, Variable>} variables - map of variables for the variation, where key is the variable key and value is the variable object
253
264
  * */
254
265
  export type VariationType = Omit<KameleoonVariationType, 'variables'> & {
255
- variables: Map<string, KameleoonVariableType>;
266
+ variables: Map<string, Variable>;
256
267
  };
268
+ /**
269
+ * @type `Variation` - an object containing information about the variation and its variables
270
+ * @param {string} name - name of the variation
271
+ * @param {string} key - key of the variation
272
+ * @param {number | null} id - id of the variation or `null` if the visitor hit default variation
273
+ * @param {number | null} experimentId - id of the experiment or `null` if the visitor hit default variation
274
+ * @param {Map<string, Variable>} variables - map of variables for the variation, where key is the variable key and value is the variable object
275
+ * */
276
+ export type Variation = VariationType;
257
277
  /**
258
278
  * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters
259
279
  * @param {string} featureKey - key of the feature flag to look for, can be found on Kameleoon Platform
@@ -367,3 +387,15 @@ export type SetForcedVariationParametersType = {
367
387
  variationKey: string | null;
368
388
  forceTargeting?: boolean;
369
389
  };
390
+ export type DataFile = {
391
+ featureFlags: Map<string, FeatureFlag>;
392
+ };
393
+ export type FeatureFlag = {
394
+ variations: Map<string, Variation>;
395
+ environmentEnabled: boolean;
396
+ rules: Rule[];
397
+ defaultVariationKey: string;
398
+ };
399
+ export type Rule = {
400
+ variations: Map<string, Variation>;
401
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kameleoon/javascript-sdk-core",
3
- "version": "5.15.0",
3
+ "version": "5.16.1",
4
4
  "description": "Kameleoon JS SDK Core",
5
5
  "main": "dist/javascript-sdk-core.cjs.js",
6
6
  "module": "dist/javascript-sdk-core.es.js",