@kameleoon/javascript-sdk-core 5.14.5 → 5.15.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.
@@ -2294,25 +2294,22 @@ class PageView {
2294
2294
  * CustomData - a class for creating an instance for user's custom data
2295
2295
  * */
2296
2296
  let CustomData$1 = class CustomData {
2297
- /**
2298
- * @param {number} index - an index of custom data to be stored under in a state, an index of custom data can be specified in `Advanced Tools` section of Kameleoon Application
2299
- * @param {string[]} value - custom value to store under the specified id, value can be anything but has to be stringified to match the `string` type. *Note* value is variadic parameter and can be used as follows
2300
- * @example
2301
- * ```ts
2302
- * // - Single value
2303
- * const customData = new CustomData(0, 'value_1');
2304
- * // - Variadic number of values
2305
- * const customData = new CustomData(0, 'value_1', 'value_2', 'value_3');
2306
- * // - Array of values
2307
- * const values = ['value_1', 'value_2', 'value_3'];
2308
- * const customData = new CustomData(0, ...values);
2309
- * ```
2310
- * */
2311
- constructor(index, ...value) {
2312
- this.index = index;
2313
- this.value = value;
2297
+ constructor(first, second, ...rest) {
2314
2298
  this._status = TrackingStatus.Unsent;
2315
2299
  this.isIdentifier = false;
2300
+ const isNumber = typeof first === 'number';
2301
+ const isBoolean = typeof second === 'boolean';
2302
+ if (isNumber) {
2303
+ this.index = first;
2304
+ }
2305
+ else {
2306
+ this.name = first;
2307
+ this.index = -1;
2308
+ }
2309
+ this.overwrite = isBoolean ? second : true;
2310
+ this.value = isBoolean
2311
+ ? rest
2312
+ : [second, ...rest].filter((v) => v != null);
2316
2313
  }
2317
2314
  get url() {
2318
2315
  // --- Note ---
@@ -2339,17 +2336,11 @@ let CustomData$1 = class CustomData {
2339
2336
  UrlParameter.ValuesCountMap +
2340
2337
  encodeURIComponent(JSON.stringify(resultValue)) +
2341
2338
  UrlParameter.Overwrite +
2342
- String(true) +
2339
+ String(this.overwrite) +
2343
2340
  identifierParameter);
2344
2341
  }
2345
2342
  get data() {
2346
- return {
2347
- index: this.index,
2348
- value: this.value,
2349
- type: KameleoonData.CustomData,
2350
- isIdentifier: this.isIdentifier,
2351
- status: this.status,
2352
- };
2343
+ return Object.assign(Object.assign({ index: this.index }, (this.name !== undefined ? { name: this.name } : {})), { value: this.value, type: KameleoonData.CustomData, isIdentifier: this.isIdentifier, status: this.status, overwrite: this.overwrite });
2353
2344
  }
2354
2345
  get status() {
2355
2346
  if (this._isMappingIdentifier) {
@@ -2364,8 +2355,15 @@ let CustomData$1 = class CustomData {
2364
2355
  * @return {CustomData} a CustomData instance
2365
2356
  * */
2366
2357
  static _fromRaw(data) {
2367
- const { index, value, status, isIdentifier } = data;
2368
- const customData = new CustomData(index, ...value);
2358
+ const { index, value, status, isIdentifier, name, overwrite } = data;
2359
+ let customData;
2360
+ if (name) {
2361
+ customData = new CustomData(name, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2362
+ customData._index = index;
2363
+ }
2364
+ else {
2365
+ customData = new CustomData(index, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2366
+ }
2369
2367
  customData.status = status;
2370
2368
  customData._isMappingIdentifier = isIdentifier;
2371
2369
  return customData;
@@ -2396,6 +2394,14 @@ let CustomData$1 = class CustomData {
2396
2394
  }
2397
2395
  }
2398
2396
  }
2397
+ /**
2398
+ * @private
2399
+ * @method _index - an internal setter for setting index of custom data
2400
+ * @param {number} value - an index value
2401
+ * */
2402
+ set _index(value) {
2403
+ this.index = value;
2404
+ }
2399
2405
  };
2400
2406
 
2401
2407
  /**
@@ -5530,6 +5536,7 @@ class DataManager {
5530
5536
  this.mappingIdentifierCustomDataIndex = null;
5531
5537
  this.persistentCustomDataIndexes = new Set();
5532
5538
  this.localCustomDataIndexes = new Set();
5539
+ this.customDataIndexByName = new Map();
5533
5540
  this.cleanupIntervalId = null;
5534
5541
  KameleoonLogger.debug `CALL: new DataManager(dataStorage, infoStorage, cleanupInterval: ${cleanupInterval})`;
5535
5542
  this.dataStorage = dataStorage;
@@ -5864,12 +5871,15 @@ class DataManager {
5864
5871
  mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, }) {
5865
5872
  for (const dataItem of kameleoonData) {
5866
5873
  if (dataItem.data.type === KameleoonData.CustomData) {
5867
- this.processCustomData({
5874
+ const customDataIsValid = this.processCustomData({
5868
5875
  infoData,
5869
5876
  customData: dataItem,
5870
5877
  mutData: targetingData,
5871
5878
  visitorCode,
5872
5879
  });
5880
+ if (!customDataIsValid) {
5881
+ continue;
5882
+ }
5873
5883
  }
5874
5884
  const expirationTime = this.dataProcessor.mutUpdateData({
5875
5885
  infoData,
@@ -5910,6 +5920,14 @@ class DataManager {
5910
5920
  var _a;
5911
5921
  const { data } = customData;
5912
5922
  const isDataValid = Boolean(data.value.length && data.value[0].length);
5923
+ if (data.name) {
5924
+ const cdIndex = this.customDataIndexByName.get(data.name);
5925
+ if (cdIndex === undefined) {
5926
+ return false;
5927
+ }
5928
+ data.index = cdIndex;
5929
+ customData._index = cdIndex;
5930
+ }
5913
5931
  if (this.mappingIdentifierCustomDataIndex === data.index && isDataValid) {
5914
5932
  customData._isMappingIdentifier = true;
5915
5933
  const userId = data.value[0];
@@ -5933,6 +5951,7 @@ class DataManager {
5933
5951
  if (this.localCustomDataIndexes.has(data.index)) {
5934
5952
  customData.status = TrackingStatus.Sent;
5935
5953
  }
5954
+ return true;
5936
5955
  }
5937
5956
  get unsentDataVisitors() {
5938
5957
  const infoResult = this.infoStorage.read();
@@ -5965,6 +5984,7 @@ class DataManager {
5965
5984
  set customDataIndexes(customData) {
5966
5985
  var _a;
5967
5986
  const [customDataLocalOnlyIndexes, persistentCustomDataIndexes] = [[], []];
5987
+ const customDataIndexByName = new Map();
5968
5988
  customData.forEach((customData) => {
5969
5989
  if (customData.localOnly) {
5970
5990
  customDataLocalOnlyIndexes.push(customData.index);
@@ -5972,12 +5992,19 @@ class DataManager {
5972
5992
  if (customData.scope === CustomDataScope.Visitor) {
5973
5993
  persistentCustomDataIndexes.push(customData.index);
5974
5994
  }
5995
+ if (customData.name) {
5996
+ customDataIndexByName.set(customData.name, customData.index);
5997
+ }
5975
5998
  });
5976
5999
  this.mappingIdentifierCustomDataIndex =
5977
6000
  ((_a = customData.find((customData) => customData.isMappingIdentifier)) === null || _a === void 0 ? void 0 : _a.index) ||
5978
6001
  null;
5979
6002
  this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);
5980
6003
  this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);
6004
+ this.customDataIndexByName = customDataIndexByName;
6005
+ }
6006
+ getCustomDataIndexByName(name) {
6007
+ return this.customDataIndexByName.get(name);
5981
6008
  }
5982
6009
  }
5983
6010