@kameleoon/javascript-sdk-core 5.17.3 → 5.18.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 5.18.0 (2026-02-13)
4
+
5
+ ### Features
6
+
7
+ - Updated the allowed range for the [`trackingInterval`][configurationParameters]. The new range is from **`1000` ms** (default) to **`5000` ms**, allowing a reduction in the number of tracking requests.
8
+ - Introduced a new `track` parameter for [`addData`][addData]. When set to `false`, the data is stored locally and used only for targeting evaluation; it is not sent to the Data API, helping to prevent duplicate data from being recorded. The default value is `true`. This behavior is consistent with the `track` parameter used in evaluation methods such as [`getVariation`][getVariation].
9
+
10
+ [configurationParameters](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/nodejs-sdk/#configuration-parameters)
11
+
3
12
  ## 5.17.3 (2026-02-09)
4
13
 
5
14
  ### Patch Changes
package/dist/browser.d.ts CHANGED
@@ -13,7 +13,7 @@ export { SdkLanguageType } from './constants';
13
13
  export { JSONType, ConfigurationDataType } from './clientConfiguration';
14
14
  export { TrackingStatus, VariableType, InternalsType, FeatureFlagType, FlushParamsType, JSONVariableType, SDKCoreParameters, NumberVariableType, StringVariableType, BooleanVariableType, SDKConfigurationType, KameleoonVariableType, KameleoonVariationType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, IsFeatureFlagActiveParamsType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, SimulateRequestDataType, GetVariationParamsType, GetVariationsParamsType, VariationType, Milliseconds, SetForcedVariationParametersType, } from './types';
15
15
  export { Environment, ExternalPackageInfoType } from './sdkInfoTypes';
16
- export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, StaticData, KameleoonData, UniqueIdentifier, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, IDataManager, DataManager, DataProcessor, } from './kameleoonData';
16
+ export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, StaticData, KameleoonData, UniqueIdentifier, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, IDataManager, DataManager, DataProcessor, AddDataParamsType, } from './kameleoonData';
17
17
  export { IExternalEventSource, EventSourceOpenParametersType, } from './eventSource';
18
18
  export { Header, HeadersType, HttpMethod, IExternalRequester, RequestParametersType, RequestType, RetryCountType, KameleoonResponseType, SendRequestParametersType, NUMBER_OF_RETRIES, } from './requester';
19
19
  export { ITracker } from './tracking';
@@ -18,9 +18,9 @@ interface ICacheManager<T> {
18
18
  * CacheManager - a class for managing cache
19
19
  */
20
20
  export declare class CacheManager<T> implements ICacheManager<T> {
21
- private cacheMap;
21
+ private readonly cacheMap;
22
22
  private intervalId;
23
- private cleanupTimeout;
23
+ private readonly cleanupTimeout;
24
24
  /**
25
25
  * @param {number} cleanupTimeout - timeout for cleaning cache in seconds
26
26
  * generic type `T` is a type of data that will be stored in cache
@@ -22,20 +22,20 @@ export declare class ClientConfiguration implements IClientConfiguration {
22
22
  private segmentsData;
23
23
  private holdoutData;
24
24
  private meGroupsData;
25
- private updateInterval;
25
+ private readonly updateInterval;
26
26
  private lastUpdate;
27
- private storage;
28
- private requester;
29
- private eventSource;
27
+ private readonly storage;
28
+ private readonly requester;
29
+ private readonly eventSource;
30
30
  private mappedRules;
31
31
  private mappedExperiments;
32
- private dataManager;
33
- private visitorCodeManager;
34
- private eventManager;
35
- private urlProvider;
32
+ private readonly dataManager;
33
+ private readonly visitorCodeManager;
34
+ private readonly eventManager;
35
+ private readonly urlProvider;
36
36
  private lastModified?;
37
37
  private requestTime?;
38
- private externalPackageInfo;
38
+ private readonly externalPackageInfo;
39
39
  private usedDefaultDataFile;
40
40
  private defaultDataFile?;
41
41
  private blockingBehaviourMode;
@@ -4,14 +4,17 @@ export interface IClientSettings {
4
4
  readonly settings: ClientSettingsType;
5
5
  }
6
6
  export declare class ClientSettings implements IClientSettings {
7
- private updateInterval;
8
- private environment;
9
- private networkDomain;
10
- private requestTimeout;
11
- private siteCode;
12
- private cleanupInterval;
13
- private trackRetryDelay;
14
- private trackingInterval;
7
+ static readonly DEFAULT_TRACKING_INTERVAL_MS = 1000;
8
+ static readonly MIN_TRACKING_INTERVAL_MS = 1000;
9
+ static readonly MAX_TRACKING_INTERVAL_MS = 5000;
10
+ private readonly updateInterval;
11
+ private readonly environment;
12
+ private readonly networkDomain;
13
+ private readonly requestTimeout;
14
+ private readonly siteCode;
15
+ private readonly cleanupInterval;
16
+ private readonly trackRetryDelay;
17
+ private readonly trackingInterval;
15
18
  constructor(siteCode: string, configuration?: Partial<SDKConfigurationType>);
16
19
  private getTrackingInterval;
17
20
  private getEnvironment;
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { SdkLanguageType } from './constants';
13
13
  export { JSONType, ConfigurationDataType } from './clientConfiguration';
14
14
  export { TrackingStatus, VariableType, InternalsType, FeatureFlagType, FlushParamsType, JSONVariableType, SDKCoreParameters, NumberVariableType, StringVariableType, BooleanVariableType, SDKConfigurationType, KameleoonVariableType, KameleoonVariationType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, IsFeatureFlagActiveParamsType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, SimulateRequestDataType, GetVariationParamsType, GetVariationsParamsType, VariationType, Milliseconds, SetForcedVariationParametersType, } from './types';
15
15
  export { Environment, ExternalPackageInfoType } from './sdkInfoTypes';
16
- export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, StaticData, KameleoonData, UniqueIdentifier, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, IDataManager, DataManager, DataProcessor, } from './kameleoonData';
16
+ export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, StaticData, KameleoonData, UniqueIdentifier, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, IDataManager, DataManager, DataProcessor, AddDataParamsType, } from './kameleoonData';
17
17
  export { IExternalEventSource, EventSourceOpenParametersType, } from './eventSource';
18
18
  export { Header, HeadersType, HttpMethod, IExternalRequester, RequestParametersType, RequestType, RetryCountType, KameleoonResponseType, SendRequestParametersType, NUMBER_OF_RETRIES, } from './requester';
19
19
  export { ITracker } from './tracking';
@@ -3395,6 +3395,7 @@ class Parser {
3395
3395
  }
3396
3396
  }
3397
3397
 
3398
+ var _a;
3398
3399
  class ClientSettings {
3399
3400
  constructor(siteCode, configuration) {
3400
3401
  KameleoonLogger.debug `CALL: new ClientSettings(siteCode: ${siteCode}, configuration: ${configuration})`;
@@ -3409,18 +3410,19 @@ class ClientSettings {
3409
3410
  KameleoonLogger.debug `RETURN: new ClientSettings(siteCode: ${siteCode}, configuration: ${configuration})`;
3410
3411
  }
3411
3412
  getTrackingInterval(configuration) {
3413
+ const { MIN_TRACKING_INTERVAL_MS, MAX_TRACKING_INTERVAL_MS, DEFAULT_TRACKING_INTERVAL_MS, } = ClientSettings;
3412
3414
  if (typeof (configuration === null || configuration === void 0 ? void 0 : configuration.trackingInterval) === 'number') {
3413
- if (configuration.trackingInterval < 100) {
3414
- KameleoonLogger.warning('Tracking interval must not be shorter than 100 ms. Minimum possible interval was applied.');
3415
- return 100;
3415
+ if (configuration.trackingInterval < MIN_TRACKING_INTERVAL_MS) {
3416
+ KameleoonLogger.warning(`Tracking interval must not be shorter than ${MIN_TRACKING_INTERVAL_MS} ms. Minimum possible interval was applied.`);
3417
+ return MIN_TRACKING_INTERVAL_MS;
3416
3418
  }
3417
- if (configuration.trackingInterval > 1000) {
3418
- KameleoonLogger.warning('Tracking interval must not be longer than 1000 ms. Maximum possible interval was applied.');
3419
- return 1000;
3419
+ if (configuration.trackingInterval > MAX_TRACKING_INTERVAL_MS) {
3420
+ KameleoonLogger.warning(`Tracking interval must not be longer than ${MAX_TRACKING_INTERVAL_MS} ms. Maximum possible interval was applied.`);
3421
+ return MAX_TRACKING_INTERVAL_MS;
3420
3422
  }
3421
3423
  return configuration.trackingInterval;
3422
3424
  }
3423
- return 1000;
3425
+ return DEFAULT_TRACKING_INTERVAL_MS;
3424
3426
  }
3425
3427
  getEnvironment(configuration) {
3426
3428
  if (configuration === null || configuration === void 0 ? void 0 : configuration.environment) {
@@ -3474,6 +3476,10 @@ class ClientSettings {
3474
3476
  };
3475
3477
  }
3476
3478
  }
3479
+ _a = ClientSettings;
3480
+ ClientSettings.DEFAULT_TRACKING_INTERVAL_MS = 1000;
3481
+ ClientSettings.MIN_TRACKING_INTERVAL_MS = _a.DEFAULT_TRACKING_INTERVAL_MS;
3482
+ ClientSettings.MAX_TRACKING_INTERVAL_MS = 5000;
3477
3483
 
3478
3484
  /**
3479
3485
  * @class
@@ -5468,7 +5474,6 @@ class StorageCleanupManager {
5468
5474
  break;
5469
5475
  default:
5470
5476
  // check if all cases are handled
5471
- const exhaustiveCheck = storageKey;
5472
5477
  KameleoonLogger.error `Unknown storage key: ${storageKey} for initCleanupInterval.`;
5473
5478
  }
5474
5479
  }
@@ -5763,7 +5768,7 @@ class DataManager {
5763
5768
  return resultData;
5764
5769
  }
5765
5770
  storeTrackedData(data) {
5766
- this.storeData(data, false);
5771
+ this.storeDataForVisitors(data, false);
5767
5772
  const infoResult = this.infoStorage.read();
5768
5773
  if (!infoResult.ok) {
5769
5774
  return;
@@ -5797,30 +5802,31 @@ class DataManager {
5797
5802
  }
5798
5803
  this.infoStorage.write(infoResult.data);
5799
5804
  }
5800
- storeData(firstParameter, ...secondParameter) {
5801
- KameleoonLogger.debug `CALL: DataManager.storeData(visitorCode: ${firstParameter}, data: ${secondParameter})`;
5802
- const result = this.dataStorage.read();
5803
- const infoResult = this.infoStorage.read();
5804
- if (!result.ok) {
5805
- return result;
5806
- }
5807
- if (!infoResult.ok) {
5808
- return infoResult;
5809
- }
5810
- const targetingData = result.data;
5811
- const infoData = infoResult.data;
5812
- if (typeof firstParameter === 'string') {
5805
+ /**
5806
+ * Store data for a single visitor
5807
+ */
5808
+ storeData({ visitorCode, data, track, }) {
5809
+ KameleoonLogger.debug `CALL: DataManager.storeDataForVisitor(vc: ${visitorCode}, track: ${track}, data: ${data})`;
5810
+ const result = this.storeDataInternal((infoData, targetingData) => {
5813
5811
  this.mutUpdateTargetingData({
5814
5812
  infoData,
5815
5813
  targetingData,
5816
- visitorCode: firstParameter,
5817
- kameleoonData: secondParameter,
5814
+ visitorCode,
5815
+ kameleoonData: data,
5818
5816
  extendTtl: true,
5817
+ track,
5819
5818
  });
5820
- }
5821
- else {
5822
- for (const [visitorCode, kameleoonData] of Object.entries(firstParameter)) {
5823
- const extendTtl = typeof secondParameter[0] === 'boolean' ? secondParameter[0] : true;
5819
+ });
5820
+ KameleoonLogger.debug `RETURN: DataManager.storeDataForVisitor(vc: ${visitorCode}, track: ${track}, data: ${data}) -> ${result}`;
5821
+ return result;
5822
+ }
5823
+ /**
5824
+ * Store data for multiple visitors
5825
+ */
5826
+ storeDataForVisitors(data, extendTtl) {
5827
+ KameleoonLogger.debug `CALL: DataManager.storeDataForVisitors(data: ${data}, extendTtl: ${extendTtl})`;
5828
+ const result = this.storeDataInternal((infoData, targetingData) => {
5829
+ for (const [visitorCode, kameleoonData] of Object.entries(data)) {
5824
5830
  this.mutUpdateTargetingData({
5825
5831
  infoData,
5826
5832
  targetingData,
@@ -5829,12 +5835,26 @@ class DataManager {
5829
5835
  extendTtl,
5830
5836
  });
5831
5837
  }
5838
+ });
5839
+ KameleoonLogger.debug `RETURN: DataManager.storeDataForVisitors(data: ${data}, extendTtl: ${extendTtl}) -> ${result}`;
5840
+ return result;
5841
+ }
5842
+ // ========= Internal shared logic =========
5843
+ storeDataInternal(updater) {
5844
+ const dataResult = this.dataStorage.read();
5845
+ if (!dataResult.ok) {
5846
+ return dataResult;
5832
5847
  }
5848
+ const infoResult = this.infoStorage.read();
5849
+ if (!infoResult.ok) {
5850
+ return infoResult;
5851
+ }
5852
+ const targetingData = dataResult.data;
5853
+ const infoData = infoResult.data;
5854
+ updater(infoData, targetingData);
5833
5855
  this.cleanupData();
5834
- this.infoStorage.write(infoResult.data);
5835
- const writeResult = this.dataStorage.write(targetingData);
5836
- KameleoonLogger.debug `RETURN: DataManager.storeData(visitorCode: ${firstParameter}, data: ${secondParameter}) -> (writeResult: ${writeResult})`;
5837
- return writeResult;
5856
+ this.infoStorage.write(infoData);
5857
+ return this.dataStorage.write(targetingData);
5838
5858
  }
5839
5859
  getTree(segment) {
5840
5860
  if (this.targetingTrees.has(segment.id)) {
@@ -5923,29 +5943,31 @@ class DataManager {
5923
5943
  return new Set(Object.keys(targetingData));
5924
5944
  }
5925
5945
  getLinkedVisitor(visitorCode) {
5946
+ var _a, _b, _c;
5926
5947
  const storageData = this.dataStorage.read();
5927
5948
  if (!storageData.ok) {
5928
5949
  return null;
5929
5950
  }
5930
- if (typeof storageData.data[visitorCode] === 'string') {
5931
- return storageData.data[visitorCode];
5951
+ const visitorDataOrRef = storageData.data[visitorCode];
5952
+ // Direct reference case
5953
+ if (typeof visitorDataOrRef === 'string') {
5954
+ return visitorDataOrRef;
5932
5955
  }
5933
- if (this.mappingIdentifierCustomDataIndex === null) {
5956
+ // No mapping index or no visitor data
5957
+ if (visitorDataOrRef == null ||
5958
+ this.mappingIdentifierCustomDataIndex == null) {
5934
5959
  return null;
5935
5960
  }
5936
- const visitorData = storageData.data[visitorCode];
5937
- if (!visitorData) {
5938
- return null;
5939
- }
5940
- const customData = visitorData[exports.KameleoonData.CustomData];
5941
- if (customData && customData[this.mappingIdentifierCustomDataIndex]) {
5942
- return customData[this.mappingIdentifierCustomDataIndex].value[0];
5943
- }
5944
- return null;
5961
+ const value = (_c = (_b = (_a = visitorDataOrRef[exports.KameleoonData.CustomData]) === null || _a === void 0 ? void 0 : _a[this.mappingIdentifierCustomDataIndex]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c[0];
5962
+ return value !== null && value !== void 0 ? value : null;
5945
5963
  }
5946
- mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, extendTtl, }) {
5964
+ mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, extendTtl, track, }) {
5947
5965
  var _a, _b, _c;
5948
5966
  for (const dataItem of kameleoonData) {
5967
+ // prcoess track status
5968
+ if (track === false) {
5969
+ dataItem.status = exports.TrackingStatus.Sent;
5970
+ }
5949
5971
  // process custom data
5950
5972
  if (dataItem.data.type === exports.KameleoonData.CustomData) {
5951
5973
  const customDataIsValid = this.processCustomData({
@@ -6103,6 +6125,135 @@ class DataManager {
6103
6125
  }
6104
6126
  }
6105
6127
 
6128
+ const VISITOR_CODE_LENGTH = 16;
6129
+ const VISITOR_CODE_MAX_LENGTH = 255;
6130
+ const DEFAULT_MAX_AGE = 60 * 60 * 24 * 365;
6131
+ const PATH = '/';
6132
+
6133
+ /**
6134
+ * VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve,
6135
+ * and handle these codes while considering user consent.
6136
+ **/
6137
+ class VisitorCodeManager {
6138
+ constructor() {
6139
+ this.isConsentRequired = false;
6140
+ }
6141
+ set consentRequired(isRequired) {
6142
+ this.isConsentRequired = isRequired;
6143
+ }
6144
+ get consentRequired() {
6145
+ return this.isConsentRequired;
6146
+ }
6147
+ set getData(callback) {
6148
+ this.getDataCallback = callback;
6149
+ }
6150
+ set setData(callback) {
6151
+ this.setDataCallback = callback;
6152
+ }
6153
+ get setData() {
6154
+ if (this.setDataCallback) {
6155
+ return this.setDataCallback;
6156
+ }
6157
+ throw new Error('Missing setDataCallback!');
6158
+ }
6159
+ validateVisitorCode(visitorCode) {
6160
+ if (visitorCode.length === 0) {
6161
+ return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeEmpty));
6162
+ }
6163
+ if (visitorCode.length > VISITOR_CODE_MAX_LENGTH) {
6164
+ return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeMaxLength));
6165
+ }
6166
+ return buildExports.Ok();
6167
+ }
6168
+ getVisitorCode(defaultVisitorCode) {
6169
+ KameleoonLogger.debug `CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode})`;
6170
+ if (!this.getDataCallback || !this.setDataCallback) {
6171
+ throw new Error('Missing getDataCallback or setDataCallback methods in getVisitorCode!');
6172
+ }
6173
+ let visitorCode;
6174
+ const existingVisitorCode = this.getDataCallback(exports.KameleoonStorageKey.VisitorCode);
6175
+ if (existingVisitorCode) {
6176
+ visitorCode = existingVisitorCode;
6177
+ }
6178
+ if (!visitorCode) {
6179
+ if (defaultVisitorCode) {
6180
+ this.validateVisitorCode(defaultVisitorCode).throw();
6181
+ visitorCode = defaultVisitorCode;
6182
+ KameleoonLogger.debug `Used default visitor code: ${visitorCode}`;
6183
+ }
6184
+ else {
6185
+ visitorCode = this.generateVisitorCode();
6186
+ KameleoonLogger.debug `Generated new visitor code: ${visitorCode}`;
6187
+ }
6188
+ }
6189
+ this.processSimulatedVariations(visitorCode);
6190
+ if (!this.isConsentRequired) {
6191
+ this.setDataCallback({
6192
+ visitorCode,
6193
+ key: exports.KameleoonStorageKey.VisitorCode,
6194
+ maxAge: DEFAULT_MAX_AGE,
6195
+ path: PATH,
6196
+ });
6197
+ }
6198
+ KameleoonLogger.debug `RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode}) -> (visitorCode: ${visitorCode})`;
6199
+ return visitorCode;
6200
+ }
6201
+ processSimulatedVariations(visitorCode) {
6202
+ if (this.variationConfiguration) {
6203
+ const simulatedVariationsData = this.getSimulatedVariations(visitorCode);
6204
+ try {
6205
+ this.variationConfiguration.clearSimulatedVariations(visitorCode).throw();
6206
+ if (simulatedVariationsData !== null && simulatedVariationsData.length > 0) {
6207
+ this.variationConfiguration.updateForcedFeatureVariations(visitorCode, simulatedVariationsData).throw();
6208
+ }
6209
+ }
6210
+ catch (error) {
6211
+ if (error instanceof Error) {
6212
+ KameleoonLogger.error `Failed to process simulated variations: ${error.message}`;
6213
+ }
6214
+ }
6215
+ }
6216
+ }
6217
+ getSimulatedVariations(visitorCode) {
6218
+ KameleoonLogger.debug `CALL: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode})`;
6219
+ const simulatedVariationsData = this.getDataCallback(exports.KameleoonStorageKey.KameleoonSimulationFFData);
6220
+ let variations = null;
6221
+ if (typeof simulatedVariationsData === 'string' &&
6222
+ simulatedVariationsData.length > 0) {
6223
+ try {
6224
+ const parsed = JSON.parse(decodeURIComponent(simulatedVariationsData));
6225
+ if (parsed && typeof parsed === 'object') {
6226
+ variations = Object.entries(parsed)
6227
+ .map(([key, value]) => {
6228
+ return this.variationConfiguration.simulatedVariationFromJson(key, value);
6229
+ })
6230
+ .filter((variation) => variation !== null);
6231
+ }
6232
+ }
6233
+ catch (error) {
6234
+ if (error instanceof Error) {
6235
+ KameleoonLogger.error `Failed to parse simulated variations: ${error.message}`;
6236
+ }
6237
+ }
6238
+ }
6239
+ KameleoonLogger.debug `RETURN: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode}) -> (variations: ${variations})`;
6240
+ return variations;
6241
+ }
6242
+ generateVisitorCode() {
6243
+ const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
6244
+ const randomCharacterArray = [];
6245
+ for (let i = 0; i < VISITOR_CODE_LENGTH; i++) {
6246
+ randomCharacterArray.push(characters[Math.floor(Math.random() * characters.length)]);
6247
+ }
6248
+ return randomCharacterArray.join('');
6249
+ }
6250
+ setVariationConfiguration(variationConfiguration) {
6251
+ if (!this.variationConfiguration) {
6252
+ this.variationConfiguration = variationConfiguration;
6253
+ }
6254
+ }
6255
+ }
6256
+
6106
6257
  var sha256$2 = {exports: {}};
6107
6258
 
6108
6259
  function commonjsRequire(path) {
@@ -7637,135 +7788,6 @@ class KameleoonEventSource {
7637
7788
  }
7638
7789
  }
7639
7790
 
7640
- const VISITOR_CODE_LENGTH = 16;
7641
- const VISITOR_CODE_MAX_LENGTH = 255;
7642
- const DEFAULT_MAX_AGE = 60 * 60 * 24 * 365;
7643
- const PATH = '/';
7644
-
7645
- /**
7646
- * VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve,
7647
- * and handle these codes while considering user consent.
7648
- **/
7649
- class VisitorCodeManager {
7650
- constructor() {
7651
- this.isConsentRequired = false;
7652
- }
7653
- set consentRequired(isRequired) {
7654
- this.isConsentRequired = isRequired;
7655
- }
7656
- get consentRequired() {
7657
- return this.isConsentRequired;
7658
- }
7659
- set getData(callback) {
7660
- this.getDataCallback = callback;
7661
- }
7662
- set setData(callback) {
7663
- this.setDataCallback = callback;
7664
- }
7665
- get setData() {
7666
- if (this.setDataCallback) {
7667
- return this.setDataCallback;
7668
- }
7669
- throw new Error('Missing setDataCallback!');
7670
- }
7671
- validateVisitorCode(visitorCode) {
7672
- if (visitorCode.length === 0) {
7673
- return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeEmpty));
7674
- }
7675
- if (visitorCode.length > VISITOR_CODE_MAX_LENGTH) {
7676
- return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeMaxLength));
7677
- }
7678
- return buildExports.Ok();
7679
- }
7680
- getVisitorCode(defaultVisitorCode) {
7681
- KameleoonLogger.debug `CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode})`;
7682
- if (!this.getDataCallback || !this.setDataCallback) {
7683
- throw new Error('Missing getDataCallback or setDataCallback methods in getVisitorCode!');
7684
- }
7685
- let visitorCode;
7686
- const existingVisitorCode = this.getDataCallback(exports.KameleoonStorageKey.VisitorCode);
7687
- if (existingVisitorCode) {
7688
- visitorCode = existingVisitorCode;
7689
- }
7690
- if (!visitorCode) {
7691
- if (defaultVisitorCode) {
7692
- this.validateVisitorCode(defaultVisitorCode).throw();
7693
- visitorCode = defaultVisitorCode;
7694
- KameleoonLogger.debug `Used default visitor code: ${visitorCode}`;
7695
- }
7696
- else {
7697
- visitorCode = this.generateVisitorCode();
7698
- KameleoonLogger.debug `Generated new visitor code: ${visitorCode}`;
7699
- }
7700
- }
7701
- this.processSimulatedVariations(visitorCode);
7702
- if (!this.isConsentRequired) {
7703
- this.setDataCallback({
7704
- visitorCode,
7705
- key: exports.KameleoonStorageKey.VisitorCode,
7706
- maxAge: DEFAULT_MAX_AGE,
7707
- path: PATH,
7708
- });
7709
- }
7710
- KameleoonLogger.debug `RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode}) -> (visitorCode: ${visitorCode})`;
7711
- return visitorCode;
7712
- }
7713
- processSimulatedVariations(visitorCode) {
7714
- if (this.variationConfiguration) {
7715
- const simulatedVariationsData = this.getSimulatedVariations(visitorCode);
7716
- try {
7717
- this.variationConfiguration.clearSimulatedVariations(visitorCode).throw();
7718
- if (simulatedVariationsData !== null && simulatedVariationsData.length > 0) {
7719
- this.variationConfiguration.updateForcedFeatureVariations(visitorCode, simulatedVariationsData).throw();
7720
- }
7721
- }
7722
- catch (error) {
7723
- if (error instanceof Error) {
7724
- KameleoonLogger.error `Failed to process simulated variations: ${error.message}`;
7725
- }
7726
- }
7727
- }
7728
- }
7729
- getSimulatedVariations(visitorCode) {
7730
- KameleoonLogger.debug `CALL: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode})`;
7731
- const simulatedVariationsData = this.getDataCallback(exports.KameleoonStorageKey.KameleoonSimulationFFData);
7732
- let variations = null;
7733
- if (typeof simulatedVariationsData === 'string' &&
7734
- simulatedVariationsData.length > 0) {
7735
- try {
7736
- const parsed = JSON.parse(decodeURIComponent(simulatedVariationsData));
7737
- if (parsed && typeof parsed === 'object') {
7738
- variations = Object.entries(parsed)
7739
- .map(([key, value]) => {
7740
- return this.variationConfiguration.simulatedVariationFromJson(key, value);
7741
- })
7742
- .filter((variation) => variation !== null);
7743
- }
7744
- }
7745
- catch (error) {
7746
- if (error instanceof Error) {
7747
- KameleoonLogger.error `Failed to parse simulated variations: ${error.message}`;
7748
- }
7749
- }
7750
- }
7751
- KameleoonLogger.debug `RETURN: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode}) -> (variations: ${variations})`;
7752
- return variations;
7753
- }
7754
- generateVisitorCode() {
7755
- const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
7756
- const randomCharacterArray = [];
7757
- for (let i = 0; i < VISITOR_CODE_LENGTH; i++) {
7758
- randomCharacterArray.push(characters[Math.floor(Math.random() * characters.length)]);
7759
- }
7760
- return randomCharacterArray.join('');
7761
- }
7762
- setVariationConfiguration(variationConfiguration) {
7763
- if (!this.variationConfiguration) {
7764
- this.variationConfiguration = variationConfiguration;
7765
- }
7766
- }
7767
- }
7768
-
7769
7791
  var Byte;
7770
7792
  (function (Byte) {
7771
7793
  Byte[Byte["Kb"] = 1000] = "Kb";
@@ -7958,7 +7980,10 @@ class Tracker {
7958
7980
  const linkedVisitor = this.dataManager.getLinkedVisitor(visitorCode);
7959
7981
  const index = this.dataManager.identifierCustomDataIndex;
7960
7982
  if (!linkedVisitor && typeof index === 'number') {
7961
- this.dataManager.storeData(visitorCode, new CustomData$1(index, visitorCode));
7983
+ this.dataManager.storeData({
7984
+ visitorCode,
7985
+ data: [new CustomData$1(index, visitorCode)],
7986
+ });
7962
7987
  }
7963
7988
  else {
7964
7989
  isMappingIdentifier = true;
@@ -8107,7 +8132,7 @@ class Tracker {
8107
8132
  this.dataManager.storeTrackedData(updatedData);
8108
8133
  }
8109
8134
  else {
8110
- this.dataManager.storeData(updatedData, false);
8135
+ this.dataManager.storeDataForVisitors(updatedData, false);
8111
8136
  }
8112
8137
  }
8113
8138
  getUnsentVisitorData(visitorCode, isConsentProvided) {
@@ -8290,16 +8315,21 @@ class KameleoonClient {
8290
8315
  return result.ok;
8291
8316
  });
8292
8317
  }
8293
- addData(visitorCode, ...data) {
8318
+ addData(visitorCodeOrParams, ...dataRest) {
8294
8319
  if (this.stubMode) {
8295
8320
  throw new KameleoonError(exports.KameleoonException.Initialization);
8296
8321
  }
8322
+ const params = typeof visitorCodeOrParams === 'string'
8323
+ ? { visitorCode: visitorCodeOrParams, data: dataRest }
8324
+ : visitorCodeOrParams;
8325
+ const { visitorCode, data, track = true } = params;
8297
8326
  KameleoonLogger.info `CALL: KameleoonClient.addData(visitorCode: ${visitorCode}, data: ${data})`;
8298
8327
  this.visitorCodeManager.validateVisitorCode(visitorCode).throw();
8299
8328
  if (!this.initialized) {
8300
8329
  throw new KameleoonError(exports.KameleoonException.Initialization);
8301
8330
  }
8302
- this.dataManager.storeData(visitorCode, ...data).throw();
8331
+ // assuming DataManager.storeData supports `track` (boolean) as discussed
8332
+ this.dataManager.storeData({ visitorCode, track, data }).throw();
8303
8333
  KameleoonLogger.info `RETURN: KameleoonClient.addData(visitorCode: ${visitorCode}, data: ${data})`;
8304
8334
  }
8305
8335
  getRemoteVisitorData({ visitorCode, shouldAddData = true, filters = DEFAULT_VISITOR_DATA_FILTERS, }) {
@@ -8643,7 +8673,11 @@ class KameleoonClient {
8643
8673
  return null;
8644
8674
  }
8645
8675
  const customData = new CustomData$1(customDataIndex, ...Object.keys(data[WAREHOUSE_AUDIENCE_KEY]));
8646
- this.dataManager.storeData(visitorCode, customData);
8676
+ this.dataManager.storeData({
8677
+ visitorCode,
8678
+ track: true,
8679
+ data: [customData],
8680
+ });
8647
8681
  KameleoonLogger.info `RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${visitorCode}, customDataIndex: ${customDataIndex}, warehouseKey: ${warehouseKey}) -> (customData: ${customData})`;
8648
8682
  return customData;
8649
8683
  });
@@ -8719,7 +8753,7 @@ class KameleoonClient {
8719
8753
  }
8720
8754
  }
8721
8755
  if (targetedSegments.length !== 0) {
8722
- this.dataManager.storeData(visitorCode, ...targetedSegments);
8756
+ this.dataManager.storeData({ visitorCode, data: targetedSegments });
8723
8757
  }
8724
8758
  this.flush(visitorCode);
8725
8759
  KameleoonLogger.info `RETURN: KameleoonClient.evaluateAudiences(visitorCode: ${visitorCode})`;