@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.
@@ -2267,25 +2267,22 @@ class PageView {
2267
2267
  * CustomData - a class for creating an instance for user's custom data
2268
2268
  * */
2269
2269
  let CustomData$1 = class CustomData {
2270
- /**
2271
- * @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
2272
- * @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
2273
- * @example
2274
- * ```ts
2275
- * // - Single value
2276
- * const customData = new CustomData(0, 'value_1');
2277
- * // - Variadic number of values
2278
- * const customData = new CustomData(0, 'value_1', 'value_2', 'value_3');
2279
- * // - Array of values
2280
- * const values = ['value_1', 'value_2', 'value_3'];
2281
- * const customData = new CustomData(0, ...values);
2282
- * ```
2283
- * */
2284
- constructor(index, ...value) {
2285
- this.index = index;
2286
- this.value = value;
2270
+ constructor(first, second, ...rest) {
2287
2271
  this._status = exports.TrackingStatus.Unsent;
2288
2272
  this.isIdentifier = false;
2273
+ const isNumber = typeof first === 'number';
2274
+ const isBoolean = typeof second === 'boolean';
2275
+ if (isNumber) {
2276
+ this.index = first;
2277
+ }
2278
+ else {
2279
+ this.name = first;
2280
+ this.index = -1;
2281
+ }
2282
+ this.overwrite = isBoolean ? second : true;
2283
+ this.value = isBoolean
2284
+ ? rest
2285
+ : [second, ...rest].filter((v) => v != null);
2289
2286
  }
2290
2287
  get url() {
2291
2288
  // --- Note ---
@@ -2312,17 +2309,11 @@ let CustomData$1 = class CustomData {
2312
2309
  UrlParameter.ValuesCountMap +
2313
2310
  encodeURIComponent(JSON.stringify(resultValue)) +
2314
2311
  UrlParameter.Overwrite +
2315
- String(true) +
2312
+ String(this.overwrite) +
2316
2313
  identifierParameter);
2317
2314
  }
2318
2315
  get data() {
2319
- return {
2320
- index: this.index,
2321
- value: this.value,
2322
- type: exports.KameleoonData.CustomData,
2323
- isIdentifier: this.isIdentifier,
2324
- status: this.status,
2325
- };
2316
+ return Object.assign(Object.assign({ index: this.index }, (this.name !== undefined ? { name: this.name } : {})), { value: this.value, type: exports.KameleoonData.CustomData, isIdentifier: this.isIdentifier, status: this.status, overwrite: this.overwrite });
2326
2317
  }
2327
2318
  get status() {
2328
2319
  if (this._isMappingIdentifier) {
@@ -2337,8 +2328,15 @@ let CustomData$1 = class CustomData {
2337
2328
  * @return {CustomData} a CustomData instance
2338
2329
  * */
2339
2330
  static _fromRaw(data) {
2340
- const { index, value, status, isIdentifier } = data;
2341
- const customData = new CustomData(index, ...value);
2331
+ const { index, value, status, isIdentifier, name, overwrite } = data;
2332
+ let customData;
2333
+ if (name) {
2334
+ customData = new CustomData(name, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2335
+ customData._index = index;
2336
+ }
2337
+ else {
2338
+ customData = new CustomData(index, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2339
+ }
2342
2340
  customData.status = status;
2343
2341
  customData._isMappingIdentifier = isIdentifier;
2344
2342
  return customData;
@@ -2369,6 +2367,14 @@ let CustomData$1 = class CustomData {
2369
2367
  }
2370
2368
  }
2371
2369
  }
2370
+ /**
2371
+ * @private
2372
+ * @method _index - an internal setter for setting index of custom data
2373
+ * @param {number} value - an index value
2374
+ * */
2375
+ set _index(value) {
2376
+ this.index = value;
2377
+ }
2372
2378
  };
2373
2379
 
2374
2380
  /**
@@ -5503,6 +5509,7 @@ class DataManager {
5503
5509
  this.mappingIdentifierCustomDataIndex = null;
5504
5510
  this.persistentCustomDataIndexes = new Set();
5505
5511
  this.localCustomDataIndexes = new Set();
5512
+ this.customDataIndexByName = new Map();
5506
5513
  this.cleanupIntervalId = null;
5507
5514
  KameleoonLogger.debug `CALL: new DataManager(dataStorage, infoStorage, cleanupInterval: ${cleanupInterval})`;
5508
5515
  this.dataStorage = dataStorage;
@@ -5837,12 +5844,15 @@ class DataManager {
5837
5844
  mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, }) {
5838
5845
  for (const dataItem of kameleoonData) {
5839
5846
  if (dataItem.data.type === exports.KameleoonData.CustomData) {
5840
- this.processCustomData({
5847
+ const customDataIsValid = this.processCustomData({
5841
5848
  infoData,
5842
5849
  customData: dataItem,
5843
5850
  mutData: targetingData,
5844
5851
  visitorCode,
5845
5852
  });
5853
+ if (!customDataIsValid) {
5854
+ continue;
5855
+ }
5846
5856
  }
5847
5857
  const expirationTime = this.dataProcessor.mutUpdateData({
5848
5858
  infoData,
@@ -5883,6 +5893,14 @@ class DataManager {
5883
5893
  var _a;
5884
5894
  const { data } = customData;
5885
5895
  const isDataValid = Boolean(data.value.length && data.value[0].length);
5896
+ if (data.name) {
5897
+ const cdIndex = this.customDataIndexByName.get(data.name);
5898
+ if (cdIndex === undefined) {
5899
+ return false;
5900
+ }
5901
+ data.index = cdIndex;
5902
+ customData._index = cdIndex;
5903
+ }
5886
5904
  if (this.mappingIdentifierCustomDataIndex === data.index && isDataValid) {
5887
5905
  customData._isMappingIdentifier = true;
5888
5906
  const userId = data.value[0];
@@ -5906,6 +5924,7 @@ class DataManager {
5906
5924
  if (this.localCustomDataIndexes.has(data.index)) {
5907
5925
  customData.status = exports.TrackingStatus.Sent;
5908
5926
  }
5927
+ return true;
5909
5928
  }
5910
5929
  get unsentDataVisitors() {
5911
5930
  const infoResult = this.infoStorage.read();
@@ -5938,6 +5957,7 @@ class DataManager {
5938
5957
  set customDataIndexes(customData) {
5939
5958
  var _a;
5940
5959
  const [customDataLocalOnlyIndexes, persistentCustomDataIndexes] = [[], []];
5960
+ const customDataIndexByName = new Map();
5941
5961
  customData.forEach((customData) => {
5942
5962
  if (customData.localOnly) {
5943
5963
  customDataLocalOnlyIndexes.push(customData.index);
@@ -5945,12 +5965,19 @@ class DataManager {
5945
5965
  if (customData.scope === exports.CustomDataScope.Visitor) {
5946
5966
  persistentCustomDataIndexes.push(customData.index);
5947
5967
  }
5968
+ if (customData.name) {
5969
+ customDataIndexByName.set(customData.name, customData.index);
5970
+ }
5948
5971
  });
5949
5972
  this.mappingIdentifierCustomDataIndex =
5950
5973
  ((_a = customData.find((customData) => customData.isMappingIdentifier)) === null || _a === void 0 ? void 0 : _a.index) ||
5951
5974
  null;
5952
5975
  this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);
5953
5976
  this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);
5977
+ this.customDataIndexByName = customDataIndexByName;
5978
+ }
5979
+ getCustomDataIndexByName(name) {
5980
+ return this.customDataIndexByName.get(name);
5954
5981
  }
5955
5982
  }
5956
5983