@kameleoon/javascript-sdk-core 5.14.4 → 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.
@@ -2265,25 +2265,22 @@ class PageView {
2265
2265
  * CustomData - a class for creating an instance for user's custom data
2266
2266
  * */
2267
2267
  let CustomData$1 = class CustomData {
2268
- /**
2269
- * @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
2270
- * @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
2271
- * @example
2272
- * ```ts
2273
- * // - Single value
2274
- * const customData = new CustomData(0, 'value_1');
2275
- * // - Variadic number of values
2276
- * const customData = new CustomData(0, 'value_1', 'value_2', 'value_3');
2277
- * // - Array of values
2278
- * const values = ['value_1', 'value_2', 'value_3'];
2279
- * const customData = new CustomData(0, ...values);
2280
- * ```
2281
- * */
2282
- constructor(index, ...value) {
2283
- this.index = index;
2284
- this.value = value;
2268
+ constructor(first, second, ...rest) {
2285
2269
  this._status = TrackingStatus.Unsent;
2286
2270
  this.isIdentifier = false;
2271
+ const isNumber = typeof first === 'number';
2272
+ const isBoolean = typeof second === 'boolean';
2273
+ if (isNumber) {
2274
+ this.index = first;
2275
+ }
2276
+ else {
2277
+ this.name = first;
2278
+ this.index = -1;
2279
+ }
2280
+ this.overwrite = isBoolean ? second : true;
2281
+ this.value = isBoolean
2282
+ ? rest
2283
+ : [second, ...rest].filter((v) => v != null);
2287
2284
  }
2288
2285
  get url() {
2289
2286
  // --- Note ---
@@ -2310,17 +2307,11 @@ let CustomData$1 = class CustomData {
2310
2307
  UrlParameter.ValuesCountMap +
2311
2308
  encodeURIComponent(JSON.stringify(resultValue)) +
2312
2309
  UrlParameter.Overwrite +
2313
- String(true) +
2310
+ String(this.overwrite) +
2314
2311
  identifierParameter);
2315
2312
  }
2316
2313
  get data() {
2317
- return {
2318
- index: this.index,
2319
- value: this.value,
2320
- type: KameleoonData.CustomData,
2321
- isIdentifier: this.isIdentifier,
2322
- status: this.status,
2323
- };
2314
+ 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 });
2324
2315
  }
2325
2316
  get status() {
2326
2317
  if (this._isMappingIdentifier) {
@@ -2335,8 +2326,15 @@ let CustomData$1 = class CustomData {
2335
2326
  * @return {CustomData} a CustomData instance
2336
2327
  * */
2337
2328
  static _fromRaw(data) {
2338
- const { index, value, status, isIdentifier } = data;
2339
- const customData = new CustomData(index, ...value);
2329
+ const { index, value, status, isIdentifier, name, overwrite } = data;
2330
+ let customData;
2331
+ if (name) {
2332
+ customData = new CustomData(name, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2333
+ customData._index = index;
2334
+ }
2335
+ else {
2336
+ customData = new CustomData(index, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2337
+ }
2340
2338
  customData.status = status;
2341
2339
  customData._isMappingIdentifier = isIdentifier;
2342
2340
  return customData;
@@ -2367,6 +2365,14 @@ let CustomData$1 = class CustomData {
2367
2365
  }
2368
2366
  }
2369
2367
  }
2368
+ /**
2369
+ * @private
2370
+ * @method _index - an internal setter for setting index of custom data
2371
+ * @param {number} value - an index value
2372
+ * */
2373
+ set _index(value) {
2374
+ this.index = value;
2375
+ }
2370
2376
  };
2371
2377
 
2372
2378
  /**
@@ -5501,6 +5507,7 @@ class DataManager {
5501
5507
  this.mappingIdentifierCustomDataIndex = null;
5502
5508
  this.persistentCustomDataIndexes = new Set();
5503
5509
  this.localCustomDataIndexes = new Set();
5510
+ this.customDataIndexByName = new Map();
5504
5511
  this.cleanupIntervalId = null;
5505
5512
  KameleoonLogger.debug `CALL: new DataManager(dataStorage, infoStorage, cleanupInterval: ${cleanupInterval})`;
5506
5513
  this.dataStorage = dataStorage;
@@ -5835,12 +5842,15 @@ class DataManager {
5835
5842
  mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, }) {
5836
5843
  for (const dataItem of kameleoonData) {
5837
5844
  if (dataItem.data.type === KameleoonData.CustomData) {
5838
- this.processCustomData({
5845
+ const customDataIsValid = this.processCustomData({
5839
5846
  infoData,
5840
5847
  customData: dataItem,
5841
5848
  mutData: targetingData,
5842
5849
  visitorCode,
5843
5850
  });
5851
+ if (!customDataIsValid) {
5852
+ continue;
5853
+ }
5844
5854
  }
5845
5855
  const expirationTime = this.dataProcessor.mutUpdateData({
5846
5856
  infoData,
@@ -5881,6 +5891,14 @@ class DataManager {
5881
5891
  var _a;
5882
5892
  const { data } = customData;
5883
5893
  const isDataValid = Boolean(data.value.length && data.value[0].length);
5894
+ if (data.name) {
5895
+ const cdIndex = this.customDataIndexByName.get(data.name);
5896
+ if (cdIndex === undefined) {
5897
+ return false;
5898
+ }
5899
+ data.index = cdIndex;
5900
+ customData._index = cdIndex;
5901
+ }
5884
5902
  if (this.mappingIdentifierCustomDataIndex === data.index && isDataValid) {
5885
5903
  customData._isMappingIdentifier = true;
5886
5904
  const userId = data.value[0];
@@ -5904,6 +5922,7 @@ class DataManager {
5904
5922
  if (this.localCustomDataIndexes.has(data.index)) {
5905
5923
  customData.status = TrackingStatus.Sent;
5906
5924
  }
5925
+ return true;
5907
5926
  }
5908
5927
  get unsentDataVisitors() {
5909
5928
  const infoResult = this.infoStorage.read();
@@ -5936,6 +5955,7 @@ class DataManager {
5936
5955
  set customDataIndexes(customData) {
5937
5956
  var _a;
5938
5957
  const [customDataLocalOnlyIndexes, persistentCustomDataIndexes] = [[], []];
5958
+ const customDataIndexByName = new Map();
5939
5959
  customData.forEach((customData) => {
5940
5960
  if (customData.localOnly) {
5941
5961
  customDataLocalOnlyIndexes.push(customData.index);
@@ -5943,12 +5963,19 @@ class DataManager {
5943
5963
  if (customData.scope === CustomDataScope.Visitor) {
5944
5964
  persistentCustomDataIndexes.push(customData.index);
5945
5965
  }
5966
+ if (customData.name) {
5967
+ customDataIndexByName.set(customData.name, customData.index);
5968
+ }
5946
5969
  });
5947
5970
  this.mappingIdentifierCustomDataIndex =
5948
5971
  ((_a = customData.find((customData) => customData.isMappingIdentifier)) === null || _a === void 0 ? void 0 : _a.index) ||
5949
5972
  null;
5950
5973
  this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);
5951
5974
  this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);
5975
+ this.customDataIndexByName = customDataIndexByName;
5976
+ }
5977
+ getCustomDataIndexByName(name) {
5978
+ return this.customDataIndexByName.get(name);
5952
5979
  }
5953
5980
  }
5954
5981
 
@@ -7745,14 +7772,15 @@ class BodyProvider {
7745
7772
  }
7746
7773
 
7747
7774
  class Tracker {
7748
- constructor({ dataManager, trackingStorage, variationConfiguration, trackingInterval, requester, prng, }) {
7775
+ constructor({ dataManager, trackingStorage, variationConfiguration, trackingInterval, requester, prng, clientConfiguration, }) {
7749
7776
  this.intervalId = null;
7750
- KameleoonLogger.debug `CALL: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${trackingInterval}, requester, prng)`;
7777
+ KameleoonLogger.debug `CALL: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${trackingInterval}, requester, prng, clientConfiguration)`;
7751
7778
  this.dataManager = dataManager;
7752
7779
  this.trackingStorage = trackingStorage;
7753
7780
  this.variationConfiguration = variationConfiguration;
7754
7781
  this.requester = requester;
7755
7782
  this.bodyProvider = new BodyProvider(prng);
7783
+ this.clientConfiguration = clientConfiguration;
7756
7784
  try {
7757
7785
  this.intervalId = setInterval(() => {
7758
7786
  this.sendDataAll();
@@ -7762,7 +7790,7 @@ class Tracker {
7762
7790
  this.intervalId && clearInterval(this.intervalId);
7763
7791
  throw err;
7764
7792
  }
7765
- KameleoonLogger.debug `RETURN: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${trackingInterval}, requester, prng)`;
7793
+ KameleoonLogger.debug `RETURN: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${trackingInterval}, requester, prng, clientConfiguration)`;
7766
7794
  }
7767
7795
  scheduleVisitor(visitorCode, isConsentProvided) {
7768
7796
  KameleoonLogger.debug `CALL: Tracker.scheduleVisitor(visitorCode: ${visitorCode}, isConsentProvided: ${isConsentProvided})`;
@@ -7947,8 +7975,10 @@ class Tracker {
7947
7975
  if (!data.url) {
7948
7976
  continue;
7949
7977
  }
7950
- if (!isConsentProvided && (data instanceof StaticData ||
7951
- data.data.type !== KameleoonData.Conversion)) {
7978
+ if (!isConsentProvided &&
7979
+ (!this.clientConfiguration.hasAnyTargetedDeliveryRule ||
7980
+ data instanceof StaticData ||
7981
+ data.data.type !== KameleoonData.Conversion)) {
7952
7982
  continue;
7953
7983
  }
7954
7984
  resultData.push(data);
@@ -8085,6 +8115,7 @@ class KameleoonClient {
8085
8115
  requester,
8086
8116
  trackingInterval: clientSettings.trackingInterval,
8087
8117
  prng: externalPRNG,
8118
+ clientConfiguration,
8088
8119
  });
8089
8120
  this.tracker = tracker;
8090
8121
  this.variationConfiguration = variationConfiguration;