@kameleoon/javascript-sdk-core 5.17.0 → 5.17.2

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.
@@ -2907,7 +2907,10 @@ class VisitsData {
2907
2907
  constructor(visits) {
2908
2908
  this.status = exports.TrackingStatus.Sent;
2909
2909
  this.visits = visits;
2910
- this.visitNumber = visits.length ? visits.length - 1 : 0;
2910
+ this._visitNumber = visits.length ? visits.length - 1 : 0;
2911
+ }
2912
+ get visitNumber() {
2913
+ return this._visitNumber;
2911
2914
  }
2912
2915
  get url() {
2913
2916
  return '';
@@ -2915,7 +2918,7 @@ class VisitsData {
2915
2918
  get data() {
2916
2919
  return {
2917
2920
  visits: this.visits,
2918
- visitNumber: this.visitNumber,
2921
+ visitNumber: this._visitNumber,
2919
2922
  type: exports.KameleoonData.VisitsData,
2920
2923
  status: this.status,
2921
2924
  };
@@ -2932,11 +2935,11 @@ class VisitsData {
2932
2935
  list: this.visits,
2933
2936
  visit,
2934
2937
  });
2935
- this.visitNumber = this.visits.length ? this.visits.length - 1 : 0;
2938
+ this._visitNumber = this.visits.length ? this.visits.length - 1 : 0;
2936
2939
  }
2937
2940
  updateVisitNumber(visitNumber) {
2938
- if (visitNumber > this.visitNumber) {
2939
- this.visitNumber = visitNumber;
2941
+ if (visitNumber > this._visitNumber) {
2942
+ this._visitNumber = visitNumber;
2940
2943
  }
2941
2944
  }
2942
2945
  }
@@ -3143,10 +3146,12 @@ class VisitProcessor {
3143
3146
  timeLastActivity: (_a = visit.timeLastEvent) !== null && _a !== void 0 ? _a : visit.timeStarted,
3144
3147
  };
3145
3148
  }
3146
- processVisitNumber(visit, isCurrentVisit) {
3147
- if (visit.staticDataEvent) {
3148
- const visitNumber = visit.staticDataEvent.data.visitNumber + (isCurrentVisit ? 0 : 1);
3149
- this.visitsData.updateVisitNumber(visitNumber);
3149
+ processVisitNumber(visit, visitOffset) {
3150
+ var _a, _b, _c;
3151
+ if (this.visitsData.visitNumber <= visitOffset &&
3152
+ ((_a = visit.staticDataEvent) === null || _a === void 0 ? void 0 : _a.data.visitNumber)) {
3153
+ const visitNumber = (_c = (_b = visit.staticDataEvent) === null || _b === void 0 ? void 0 : _b.data.visitNumber) !== null && _c !== void 0 ? _c : 0;
3154
+ this.visitsData.updateVisitNumber(visitNumber + visitOffset);
3150
3155
  }
3151
3156
  }
3152
3157
  processCbs(cbsData) {
@@ -3320,12 +3325,12 @@ class Parser {
3320
3325
  }
3321
3326
  if (currentVisit) {
3322
3327
  visitProcessor.processVisit(currentVisit);
3323
- visitProcessor.processVisitNumber(currentVisit, true);
3328
+ visitProcessor.processVisitNumber(currentVisit, 0);
3324
3329
  }
3325
- previousVisits === null || previousVisits === void 0 ? void 0 : previousVisits.forEach((visit) => {
3330
+ previousVisits === null || previousVisits === void 0 ? void 0 : previousVisits.forEach((visit, index) => {
3326
3331
  visitProcessor.processVisit(visit);
3327
3332
  visitProcessor.processVisitsData(visit);
3328
- visitProcessor.processVisitNumber(visit, false);
3333
+ visitProcessor.processVisitNumber(visit, index + 1);
3329
3334
  });
3330
3335
  visitProcessor.processKcs(kcs);
3331
3336
  visitProcessor.processCbs(cbs);
@@ -3692,11 +3697,9 @@ class DataProcessor {
3692
3697
  delete infoData.mappingIdentifiers[visitorCode];
3693
3698
  }
3694
3699
  }
3695
- else {
3696
- if (!nextCleanupTime ||
3697
- (closestCleanupTime && closestCleanupTime < nextCleanupTime)) {
3698
- nextCleanupTime = closestCleanupTime;
3699
- }
3700
+ else if (!nextCleanupTime ||
3701
+ (closestCleanupTime && closestCleanupTime < nextCleanupTime)) {
3702
+ nextCleanupTime = closestCleanupTime;
3700
3703
  }
3701
3704
  }
3702
3705
  return nextCleanupTime;
@@ -3925,10 +3928,9 @@ class DataProcessor {
3925
3928
  if (isExpired) {
3926
3929
  delete existingData[nestedKey];
3927
3930
  }
3928
- else {
3929
- if (!closestCleanupTime || value.expirationTime < closestCleanupTime) {
3930
- closestCleanupTime = value.expirationTime;
3931
- }
3931
+ else if (!closestCleanupTime ||
3932
+ value.expirationTime < closestCleanupTime) {
3933
+ closestCleanupTime = value.expirationTime;
3932
3934
  }
3933
3935
  }
3934
3936
  if (!Object.keys(existingData).length) {
@@ -5541,6 +5543,13 @@ class StorageCleanupManager {
5541
5543
  }
5542
5544
  }
5543
5545
 
5546
+ exports.LegalConsent = void 0;
5547
+ (function (LegalConsent) {
5548
+ LegalConsent[LegalConsent["Unknown"] = 0] = "Unknown";
5549
+ LegalConsent[LegalConsent["Given"] = 1] = "Given";
5550
+ LegalConsent[LegalConsent["NotGiven"] = 2] = "NotGiven";
5551
+ })(exports.LegalConsent || (exports.LegalConsent = {}));
5552
+
5544
5553
  class TargetedSegment {
5545
5554
  constructor(id) {
5546
5555
  this.id = id;
@@ -7112,13 +7121,6 @@ class Hasher {
7112
7121
  }
7113
7122
  }
7114
7123
 
7115
- var LegalConsent;
7116
- (function (LegalConsent) {
7117
- LegalConsent[LegalConsent["Unknown"] = 0] = "Unknown";
7118
- LegalConsent[LegalConsent["Given"] = 1] = "Given";
7119
- LegalConsent[LegalConsent["NotGiven"] = 2] = "NotGiven";
7120
- })(LegalConsent || (LegalConsent = {}));
7121
-
7122
7124
  class VariationConfiguration {
7123
7125
  constructor(externalStorage, externalStorageForcedExperimentVariations, externalStorageForcedFeatureVariations, visitorCodeManager, clientConfiguration) {
7124
7126
  this.storage = externalStorage;
@@ -7182,7 +7184,7 @@ class VariationConfiguration {
7182
7184
  const { rules, featureKey, id: featureFlagId, defaultVariationKey, } = featureFlag;
7183
7185
  const consent = clientConfiguration.isConsentRequired
7184
7186
  ? legalConsent
7185
- : LegalConsent.Given;
7187
+ : exports.LegalConsent.Given;
7186
7188
  for (const rule of rules) {
7187
7189
  const { segment, experimentId, id, exposition, respoolTime, variationByExposition, } = rule;
7188
7190
  const forcedVariationData = this.getForcedExperimentVariation(visitorCode, rule.experimentId);
@@ -7230,7 +7232,7 @@ class VariationConfiguration {
7230
7232
  KameleoonLogger.debug `Calculated ruleHash: ${ruleHash} for code: ${visitorIdentifier}`;
7231
7233
  if (ruleHash <= exposition) {
7232
7234
  // Checking if the evaluation is blocked due to the consent policy
7233
- if (consent == LegalConsent.NotGiven &&
7235
+ if (consent == exports.LegalConsent.NotGiven &&
7234
7236
  rule.type == RuleType.EXPERIMENTATION) {
7235
7237
  const behaviour = clientConfiguration.consentBlockingBehaviour;
7236
7238
  if (behaviour == ConsentBlockingBehaviour.PartiallyBlocked) {
@@ -8759,7 +8761,7 @@ class KameleoonClient {
8759
8761
  }
8760
8762
  updateConsentData(visitorCode, consent) {
8761
8763
  const readResult = this.consentDataStorage.read();
8762
- const legalConsent = consent ? LegalConsent.Given : LegalConsent.NotGiven;
8764
+ const legalConsent = consent ? exports.LegalConsent.Given : exports.LegalConsent.NotGiven;
8763
8765
  if (!readResult.ok) {
8764
8766
  if (readResult.error.type === exports.KameleoonException.StorageEmpty) {
8765
8767
  this.consentDataStorage.write({
@@ -8782,26 +8784,26 @@ class KameleoonClient {
8782
8784
  const consentDataResult = this.consentDataStorage.read();
8783
8785
  legalConsent = consentDataResult.ok
8784
8786
  ? this.extractLegalConsent(consentDataResult.data[visitorCode])
8785
- : LegalConsent.Unknown;
8787
+ : exports.LegalConsent.Unknown;
8786
8788
  KameleoonLogger.debug `RETURN: KameleoonClient.getLegalConsent(visitorCode: ${visitorCode}) -> (legalConsent: ${legalConsent})`;
8787
8789
  return legalConsent;
8788
8790
  }
8789
8791
  extractLegalConsent(consentData) {
8790
8792
  if (consentData === undefined)
8791
- return LegalConsent.Unknown;
8793
+ return exports.LegalConsent.Unknown;
8792
8794
  if (typeof consentData === 'boolean') {
8793
- return consentData ? LegalConsent.Given : LegalConsent.NotGiven;
8795
+ return consentData ? exports.LegalConsent.Given : exports.LegalConsent.NotGiven;
8794
8796
  }
8795
8797
  const value = consentData.consent;
8796
8798
  if (typeof value === 'boolean')
8797
- return value ? LegalConsent.Given : LegalConsent.NotGiven;
8799
+ return value ? exports.LegalConsent.Given : exports.LegalConsent.NotGiven;
8798
8800
  return value;
8799
8801
  }
8800
8802
  _isConsentProvided(visitorCode) {
8801
8803
  KameleoonLogger.debug `CALL: KameleoonClient._isConsentProvided(visitorCode: ${visitorCode})`;
8802
8804
  const { isConsentRequired } = this.clientConfiguration;
8803
8805
  const isConsentProvided = !isConsentRequired ||
8804
- this.getLegalConsent(visitorCode) == LegalConsent.Given;
8806
+ this.getLegalConsent(visitorCode) == exports.LegalConsent.Given;
8805
8807
  KameleoonLogger.debug `RETURN: KameleoonClient._isConsentProvided(visitorCode: ${visitorCode}) -> (isConsentProvided: ${isConsentProvided})`;
8806
8808
  return isConsentProvided;
8807
8809
  }
@@ -9007,8 +9009,10 @@ class KameleoonClient {
9007
9009
  KameleoonLogger.debug `CALL: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${visitorCode}, track: ${track}, save: ${save}, featureFlag: ${featureFlag}, visitorData: ${visitorData})`;
9008
9010
  let isNotInHoldout = true;
9009
9011
  // Checking if the evaluation is blocked due to the consent policy
9010
- const legalConsent = this.getLegalConsent(visitorCode);
9011
- if (legalConsent == LegalConsent.NotGiven) {
9012
+ const legalConsent = this.clientConfiguration.isConsentRequired
9013
+ ? this.getLegalConsent(visitorCode)
9014
+ : exports.LegalConsent.Given;
9015
+ if (legalConsent == exports.LegalConsent.NotGiven) {
9012
9016
  const behaviour = this.clientConfiguration.consentBlockingBehaviour;
9013
9017
  if (behaviour == ConsentBlockingBehaviour.CompletelyBlocked) {
9014
9018
  throw new KameleoonError(exports.KameleoonException.FeatureFlagEnvironmentDisabled, `Evaluation of holdout is blocked because consent is not provided for visitor '${visitorCode}'`);