@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.
@@ -2271,11 +2271,11 @@ let CustomData$1 = class CustomData {
2271
2271
  const isNumber = typeof first === 'number';
2272
2272
  const isBoolean = typeof second === 'boolean';
2273
2273
  if (isNumber) {
2274
- this.index = first;
2274
+ this._index = first;
2275
2275
  }
2276
2276
  else {
2277
- this.name = first;
2278
- this.index = -1;
2277
+ this._name = first;
2278
+ this._index = CustomData.UNDEFINED_INDEX;
2279
2279
  }
2280
2280
  this.overwrite = isBoolean ? second : true;
2281
2281
  this.value = isBoolean
@@ -2286,7 +2286,7 @@ let CustomData$1 = class CustomData {
2286
2286
  // --- Note ---
2287
2287
  // If SDK is used in vanilla JS codebase, then you're also able to create an instance
2288
2288
  // with no required data, we don't want send anything to tracking in that case
2289
- if (typeof this.index !== 'number') {
2289
+ if (typeof this._index !== 'number') {
2290
2290
  return '';
2291
2291
  }
2292
2292
  const uniqueValues = [...new Set(this.value)];
@@ -2303,7 +2303,7 @@ let CustomData$1 = class CustomData {
2303
2303
  }
2304
2304
  return (UrlEventType.CustomData +
2305
2305
  UrlParameter.Index +
2306
- this.index +
2306
+ this._index +
2307
2307
  UrlParameter.ValuesCountMap +
2308
2308
  encodeURIComponent(JSON.stringify(resultValue)) +
2309
2309
  UrlParameter.Overwrite +
@@ -2311,7 +2311,7 @@ let CustomData$1 = class CustomData {
2311
2311
  identifierParameter);
2312
2312
  }
2313
2313
  get data() {
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 });
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 });
2315
2315
  }
2316
2316
  get status() {
2317
2317
  if (this._isMappingIdentifier) {
@@ -2330,7 +2330,7 @@ let CustomData$1 = class CustomData {
2330
2330
  let customData;
2331
2331
  if (name) {
2332
2332
  customData = new CustomData(name, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
2333
- customData._index = index;
2333
+ customData.index = index;
2334
2334
  }
2335
2335
  else {
2336
2336
  customData = new CustomData(index, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
@@ -2367,13 +2367,28 @@ let CustomData$1 = class CustomData {
2367
2367
  }
2368
2368
  /**
2369
2369
  * @private
2370
- * @method _index - an internal setter for setting index of custom data
2370
+ * @method index - an internal setter for setting index of custom data
2371
2371
  * @param {number} value - an index value
2372
2372
  * */
2373
- set _index(value) {
2374
- this.index = value;
2373
+ set index(value) {
2374
+ this._index = value;
2375
+ }
2376
+ /**
2377
+ * @private
2378
+ * @method index - an internal getter for index of custom data
2379
+ * */
2380
+ get index() {
2381
+ return this._index;
2382
+ }
2383
+ /**
2384
+ * @private
2385
+ * @method name - an internal getter for a name of custom data
2386
+ * */
2387
+ get name() {
2388
+ return this._name;
2375
2389
  }
2376
2390
  };
2391
+ CustomData$1.UNDEFINED_INDEX = -1;
2377
2392
 
2378
2393
  /**
2379
2394
  * @class
@@ -2410,6 +2425,9 @@ let Conversion$1 = class Conversion {
2410
2425
  ? UrlParameter.Metadata + this._encodeMetadata()
2411
2426
  : ''));
2412
2427
  }
2428
+ get _metadata() {
2429
+ return this.metadata;
2430
+ }
2413
2431
  get data() {
2414
2432
  var _a;
2415
2433
  return {
@@ -5118,7 +5136,7 @@ class ConditionFactory {
5118
5136
  case TargetingType.HEAT_SLICE:
5119
5137
  return buildExports.Ok(new ConversionLikelihood(data));
5120
5138
  default:
5121
- KameleoonLogger.error `Unsupported targeted condition type found: ${targetingType}`;
5139
+ KameleoonLogger.info `Unsupported targeted condition type found: ${targetingType}`;
5122
5140
  return buildExports.Err(new KameleoonError(KameleoonException.TargetingCondition, targetingType));
5123
5141
  }
5124
5142
  }
@@ -5840,7 +5858,9 @@ class DataManager {
5840
5858
  return null;
5841
5859
  }
5842
5860
  mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, }) {
5861
+ var _a;
5843
5862
  for (const dataItem of kameleoonData) {
5863
+ // process custom data
5844
5864
  if (dataItem.data.type === KameleoonData.CustomData) {
5845
5865
  const customDataIsValid = this.processCustomData({
5846
5866
  infoData,
@@ -5852,6 +5872,10 @@ class DataManager {
5852
5872
  continue;
5853
5873
  }
5854
5874
  }
5875
+ // process metadata of conversions
5876
+ if (dataItem.data.type === KameleoonData.Conversion) {
5877
+ (_a = dataItem._metadata) === null || _a === void 0 ? void 0 : _a.forEach((item) => this.trySetCustomDataIndexByName(item));
5878
+ }
5855
5879
  const expirationTime = this.dataProcessor.mutUpdateData({
5856
5880
  infoData,
5857
5881
  visitorCode,
@@ -5891,13 +5915,9 @@ class DataManager {
5891
5915
  var _a;
5892
5916
  const { data } = customData;
5893
5917
  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;
5918
+ this.trySetCustomDataIndexByName(customData);
5919
+ if (data.index == CustomData$1.UNDEFINED_INDEX) {
5920
+ data.index = customData.index;
5901
5921
  }
5902
5922
  if (this.mappingIdentifierCustomDataIndex === data.index && isDataValid) {
5903
5923
  customData._isMappingIdentifier = true;
@@ -5924,6 +5944,15 @@ class DataManager {
5924
5944
  }
5925
5945
  return true;
5926
5946
  }
5947
+ trySetCustomDataIndexByName(customData) {
5948
+ if (customData.index == CustomData$1.UNDEFINED_INDEX && customData.name) {
5949
+ const cdIndex = this.customDataIndexByName.get(customData.name);
5950
+ if (cdIndex === undefined) {
5951
+ return;
5952
+ }
5953
+ customData.index = cdIndex;
5954
+ }
5955
+ }
5927
5956
  get unsentDataVisitors() {
5928
5957
  const infoResult = this.infoStorage.read();
5929
5958
  if (!infoResult.ok) {
@@ -7767,7 +7796,7 @@ class BodyProvider {
7767
7796
  const identifier = isMappingIdentifier
7768
7797
  ? UrlParameter.MappingValue
7769
7798
  : UrlParameter.VisitorCode;
7770
- return identifier + visitorCode;
7799
+ return identifier + encodeURIComponent(visitorCode);
7771
7800
  }
7772
7801
  }
7773
7802
 
@@ -8351,6 +8380,7 @@ class KameleoonClient {
8351
8380
  }
8352
8381
  const resultVariables = variables.map((variable) => Parser.parseFeatureVariable(variable).throw());
8353
8382
  resultFeatureList.set(variation.featureKey, {
8383
+ name: '',
8354
8384
  key: variationKey,
8355
8385
  id: variationId,
8356
8386
  experimentId,
@@ -8571,6 +8601,62 @@ class KameleoonClient {
8571
8601
  this.flush(visitorCode);
8572
8602
  KameleoonLogger.info `RETURN: KameleoonClient.evaluateAudiences(visitorCode: ${visitorCode})`;
8573
8603
  }
8604
+ getDataFile() {
8605
+ const dataFile = {
8606
+ featureFlags: new Map(),
8607
+ };
8608
+ if (this.stubMode) {
8609
+ return dataFile;
8610
+ }
8611
+ KameleoonLogger.debug `CALL: KameleoonClient.getDataFile()`;
8612
+ this.clientConfiguration.featureFlags.forEach((featureFlag, key) => {
8613
+ const variationsMap = new Map();
8614
+ featureFlag.variations.forEach((sourceVariation) => {
8615
+ var _a;
8616
+ const variablesMap = new Map();
8617
+ sourceVariation.variables.forEach((variable) => {
8618
+ try {
8619
+ const parsedVariable = Parser.parseFeatureVariable(variable).throw();
8620
+ variablesMap.set(variable.key, parsedVariable);
8621
+ }
8622
+ catch (err) {
8623
+ KameleoonLogger.error `Error parsing variable ${variable.key} of feature flag ${featureFlag.featureKey}: ${err}`;
8624
+ }
8625
+ });
8626
+ variationsMap.set(sourceVariation.key, {
8627
+ name: (_a = sourceVariation.name) !== null && _a !== void 0 ? _a : '',
8628
+ key: sourceVariation.key,
8629
+ id: null,
8630
+ experimentId: null,
8631
+ variables: variablesMap,
8632
+ });
8633
+ });
8634
+ const rules = featureFlag.rules.map((rule) => {
8635
+ const ruleVariations = new Map();
8636
+ rule.variationByExposition.forEach((varByExp) => {
8637
+ const baseVariation = variationsMap.get(varByExp.variationKey);
8638
+ if (!baseVariation)
8639
+ return;
8640
+ ruleVariations.set(baseVariation.key, {
8641
+ name: baseVariation.name,
8642
+ key: baseVariation.key,
8643
+ id: varByExp.variationId,
8644
+ experimentId: rule.experimentId,
8645
+ variables: baseVariation.variables,
8646
+ });
8647
+ });
8648
+ return { variations: ruleVariations };
8649
+ });
8650
+ dataFile.featureFlags.set(key, {
8651
+ variations: variationsMap,
8652
+ environmentEnabled: featureFlag.environmentEnabled,
8653
+ rules,
8654
+ defaultVariationKey: featureFlag.defaultVariationKey,
8655
+ });
8656
+ });
8657
+ KameleoonLogger.debug `RETURN: KameleoonClient.getDataFile() -> (dataFile: ${dataFile})`;
8658
+ return dataFile;
8659
+ }
8574
8660
  setUserConsent({ visitorCode, consent, setData, }) {
8575
8661
  if (this.stubMode) {
8576
8662
  return;
@@ -8757,6 +8843,7 @@ class KameleoonClient {
8757
8843
  return selected;
8758
8844
  }
8759
8845
  _getFeatureVariation({ visitorCode, featureKey, track, }) {
8846
+ var _a, _b;
8760
8847
  KameleoonLogger.debug `CALL: KameleoonClient._getFeatureVariation(visitorCode: ${visitorCode}, featureKey: ${featureKey}, track: ${track})`;
8761
8848
  if (!this.initialized) {
8762
8849
  return buildExports.Err(new KameleoonError(KameleoonException.Initialization));
@@ -8807,7 +8894,9 @@ class KameleoonClient {
8807
8894
  if (track && !isSimulated) {
8808
8895
  this.tracker.scheduleVisitor(visitorCode, this._isConsentProvided(visitorCode));
8809
8896
  }
8897
+ const variationName = (_b = (_a = featureFlag.variations.find((item) => item.key === variationKey)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
8810
8898
  const resultData = {
8899
+ name: variationName,
8811
8900
  key: variationKey,
8812
8901
  id: variationId,
8813
8902
  experimentId,