@kameleoon/javascript-sdk-core 5.9.1 → 5.9.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.
- package/CHANGELOG.md +8 -0
- package/dist/kameleoonClient.js +1 -1
- package/dist/kameleoonData/dataManager.d.ts +1 -0
- package/dist/kameleoonData/dataManager.js +1 -1
- package/dist/targeting/conditions/conditionFactory.js +1 -1
- package/dist/targeting/types.d.ts +0 -1
- package/dist/targeting/types.js +1 -1
- package/dist/tracking/tracker.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 5.9.2 (2025-05-15)
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed an issue with the [session merging][SessionMerging] feature that could prevent registered users from being correctly included in experiment results when they were linked to an anonymous user during the same visitor session.
|
|
8
|
+
|
|
9
|
+
[SessionMerging]: https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#using-custom-data-for-session-merging
|
|
10
|
+
|
|
3
11
|
## 5.9.1 (2025-04-08)
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/dist/kameleoonClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonClient=void 0;var _tsRes=require("ts-res"),_cacheManager=require("./cacheManager"),_clientConfiguration=require("./clientConfiguration"),_clientSettings=require("./clientSettings"),_constants=require("./constants"),_kameleoonData=require("./kameleoonData"),_kameleoonError=require("./kameleoonError"),_requester=require("./requester"),_storage=require("./storage"),_types=require("./types"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_eventSource=require("./eventSource"),_visitorCodeManager=require("./visitorCodeManager"),_eventManager=require("./eventManager"),_tracking=require("./tracking"),_logging=require("./logging"),_hasher=require("./hasher");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class KameleoonClient{constructor(a){var b;let{siteCode:c,dependencies:d,configuration:e,internalConfiguration:f,stubMode:g}=a;if(_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"clientConfiguration",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"consentDataStorage",void 0),_defineProperty(this,"trackingCache",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"externalPackageInfo",void 0),_defineProperty(this,"initialized",!1),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),_defineProperty(this,"tracker",void 0),_defineProperty(this,"environment",void 0),_defineProperty(this,"stubMode",void 0),this.stubMode=g,g)return this.variationConfiguration={},this.clientConfiguration={},this.dataManager={},this.consentDataStorage={},this.trackingCache={},this.requester={},this.externalPackageInfo={},this.visitorCodeManager={},this.eventManager={},this.tracker={},void(this.environment="");const h=null===f||void 0===f?void 0:f.externals.externalLogger;h&&_logging.KameleoonLogger.setLogger(h),_logging.KameleoonLogger.debug`CALL: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`;const{settings:i}=new _clientSettings.ClientSettings(c,e);this.environment=i.environment;const{externalStorage:j,externalEventSource:k,externalPackageInfo:l,externalVisitorCodeManager:m,externalRequester:n,externalPRNG:o}=f.externals,{useAbortController:p}=f.settings,q=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),r=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ClientData),s=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TargetingData),t=new _storage.DataStorage(j,_storage.KameleoonStorageKey.DataInfo),u=new _storage.DataStorage(j,_storage.KameleoonStorageKey.VariationData),v=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedExperimentVariation),w=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedFeatureVariation),x=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ConsentData),y=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TrackingData),z=new _kameleoonData.DataManager({dataStorage:s,infoStorage:t,cleanupInterval:i.cleanupInterval,packageInfo:l}),A=null!==(b=null===d||void 0===d?void 0:d.urlProvider)&&void 0!==b?b:new _requester.UrlProvider;A.initialize({domain:i.networkDomain,siteCode:i.siteCode,packageInfo:l,environment:i.environment});const B=new _requester.Requester({urlProvider:A,useAbortController:p,packageInfo:l,externalRequester:n,requestTimeout:i.requestTimeout,trackRetryDelay:i.trackRetryDelay}),C=new _eventSource.KameleoonEventSource({siteCode:i.siteCode,externalEventSource:k,urlProvider:A}),D=new _eventManager.EventManager,E=new _clientConfiguration.ClientConfiguration({urlProvider:A,storage:r,updateInterval:i.updateInterval,dataManager:z,eventManager:D,requester:B,eventSource:C,externalVisitorCodeManager:m}),F=new _variationConfiguration.VariationConfiguration(u,v,w,m,E),G=new _tracking.Tracker({dataManager:z,trackingStorage:y,variationConfiguration:F,requester:B,trackingInterval:i.trackingInterval,prng:o});this.tracker=G,this.variationConfiguration=F,this.requester=B,this.trackingCache=q,this.dataManager=z,this.clientConfiguration=E,this.externalPackageInfo=l,this.consentDataStorage=x,this.visitorCodeManager=m,this.eventManager=D,null!==i.cleanupInterval&&new _storage.StorageCleanupManager(j,i.cleanupInterval),_logging.KameleoonLogger.debug`RETURN: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`}async initialize(){if(this.stubMode)return!1;_logging.KameleoonLogger.info("CALL: KameleoonClient.initialize()");const a=await this.clientConfiguration.initialize();return a.throw(),this.initialized=!0,_logging.KameleoonLogger.info`RETURN: KameleoonClient.initialize() -> (result: ${a.ok})`,a.ok}addData(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];if(_logging.KameleoonLogger.info`CALL: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`,this.visitorCodeManager.validateVisitorCode(a).throw(),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.dataManager.storeData(a,...c).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`}async getRemoteVisitorData(a){let{visitorCode:b,shouldAddData:c=!0,filters:d=_constants.DEFAULT_VISITOR_DATA_FILTERS}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(b).throw();const{previousVisitAmount:e}=d;if("number"==typeof e&&(1>e||25<e))throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitAmount);const f=this.dataManager.isUniqueIdentifier(b),g=await this.requester.getVisitorData({visitorCode:b,filters:d,isMappingIdentifier:f}),h=g.throw(),{visitorData:i,storageVisitorData:j,visitsData:k,mappingIdentifier:l}=_utilities.Parser.parseVisitorData({data:h,filters:d,visitorCode:b,dataManager:this.dataManager,variationConfiguration:this.variationConfiguration});for(const d of j)(c||this.dataManager.isPersistentCustomData(d))&&this.addData(b,d);return k&&c&&this.addData(b,k),null!==d&&void 0!==d&&d.visitorCode&&l&&this.dataManager.setMappingIdentifier(b,l),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d}) -> (visitorData: ${i})`,i}trackConversion(a){let{visitorCode:b,goalId:c,negative:d,revenue:e,metadata:f}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`,this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:e,negative:d,metadata:f})),this.flush(b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`)}flush(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.flush(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a)return this.visitorCodeManager.validateVisitorCode(a).throw(),this.tracker.scheduleVisitor(a,this._isConsentProvided(a)),void _logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`;for(const b of this.dataManager.unsentDataVisitors)this.tracker.scheduleVisitor(b,this._isConsentProvided(b));_logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`}getFeatureFlags(){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info("CALL: KameleoonClient.getFeatureFlags()"),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);const a=this.clientConfiguration.featureFlags,b=[];return a.forEach(a=>{let{id:c,featureKey:d}=a;b.push({id:c,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlags() -> (FeatureFlags: ${b})`,b}getVisitorFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=[];return b.forEach(a=>{let{featureFlagId:b,featureKey:d}=a;c.push({id:b,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getVariation(a){let{visitorCode:b,featureKey:c,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=this._getFeatureVariation({visitorCode:b,featureKey:c,track:d}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${e})`,e}getVariations(a){let{visitorCode:b,onlyActive:c=!1,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=new Map,f=this.clientConfiguration.featureFlags;for(const g of f.values()){const a=this._getFeatureVariation({visitorCode:b,featureKey:g.featureKey,track:d});a.ok&&(!c||a.data.key!==_constants.OFF_VARIATION_KEY)&&e.set(g.featureKey,a.data)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d}) -> (variations: ${e})`,e}getActiveFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=new Map;return b.forEach(b=>{const{variationKey:d,featureKey:e,variationId:f,experimentId:g}=b;let h=[];null!==f&&null!==g&&(h=this._getFeatureVariables({visitorCode:a,featureKey:e,variationKey:d}));const i=h.map(a=>_utilities.Parser.parseFeatureVariable(a).throw());c.set(b.featureKey,{key:d,id:f,experimentId:g,variables:i})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getFeatureFlagVariationKey(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b}) -> (variationKey: ${c})`,c}getFeatureFlagVariable(a){let{visitorCode:b,featureKey:c,variableKey:d}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const{key:e}=this._getFeatureVariation({visitorCode:b,featureKey:c,track:!0}).throw(),f=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:e}),g=f.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariableNotFound,d,b);const{type:h,value:i}=_utilities.Parser.parseFeatureVariable(g).throw(),j={type:h,value:i};return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d}) -> (FeatureFlagVariable: ${j})`,j}getFeatureFlagVariables(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw(),d=this._getFeatureVariables({visitorCode:a,featureKey:b,variationKey:c}),e=[];for(const c of d){const a=_utilities.Parser.parseFeatureVariable(c).throw();e.push(a)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b}) -> (FeatureFlagVariables: ${e})`,e}isFeatureFlagActive(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);let[c,d,e]=["","",!0];"string"==typeof a?(_logging.KameleoonLogger.info`CALL: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d})`,c=a,d=b):(_logging.KameleoonLogger.info`CALL: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track ${e})`,[c,d]=[a.visitorCode,a.featureKey],a.track!==void 0&&(e=a.track)),this.visitorCodeManager.validateVisitorCode(c).throw();try{const{key:a}=this._getFeatureVariation({visitorCode:c,featureKey:d,track:e}).throw(),b=a!==_constants.OFF_VARIATION_KEY;return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: ${b})`,b}catch(a){if(a instanceof _kameleoonError.KameleoonError&&a.type===_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: false)`,!1;throw a}}async getRemoteData(a){if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteData(key: ${a})`;const b=await this.requester.getRemoteData(a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteData(key: ${a}) -> (remoteData: ${b})`,b.throw()}async getVisitorWarehouseAudience(a){let{visitorCode:b,customDataIndex:c,warehouseKey:d}=a;if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=await this.getRemoteData(d||b);if(!e)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,`No data found for ${d||b} key`);if(!e[_constants.WAREHOUSE_AUDIENCE_KEY]||0===Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]).length)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: null)`,null;const f=new _kameleoonData.CustomData(c,...Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]));return this.dataManager.storeData(b,f),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: ${f})`,f}onEvent(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.onEvent(event: ${a}, callback)`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(a,b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.onEvent(event: ${a}, callback)`}getEngineTrackingCode(a){if(this.stubMode)return"";_logging.KameleoonLogger.info`CALL: KameleoonClient.getEngineTrackingCode(visitorCode: ${a})`,this.visitorCodeManager.validateVisitorCode(a).throw();const b=_utilities.Utilities.getTrackingCode(this.trackingCache,a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getEngineTrackingCode(visitorCode: ${a}) -> (trackingCode: ${b})`,b}isInitialized(){return _logging.KameleoonLogger.debug`CALL/RETURN: KameleoonClient.isInitialized() -> (initialized: ${this.initialized})`,this.initialized}setLogLevel(a){_logging.KameleoonLogger.setLogLevel(a)}setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this._setForcedVariation({visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e}).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`)}setUserConsent(a){let{visitorCode:b,consent:c,setData:d}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this.updateConsentData(b,c),c?d({visitorCode:b,key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.DEFAULT_MAX_AGE,path:_visitorCodeManager.PATH}):this.visitorCodeManager.consentRequired&&d({visitorCode:"",key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.ZERO_MAX_AGE,path:_visitorCodeManager.PATH}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`)}updateConsentData(a,b){const c=this.consentDataStorage.read();if(!c.ok)return void(c.error.type===_kameleoonError.KameleoonException.StorageEmpty&&this.consentDataStorage.write({[a]:{consent:b}}));const d=c.data;d[a]={consent:b},this.consentDataStorage.write(d)}_isConsentProvided(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._isConsentProvided(visitorCode: ${a})`;const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read();let d=!1;if(!b)d=!0;else if(c.ok){const b=c.data[a];d="boolean"==typeof b?b:b&&b.consent}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isConsentProvided(visitorCode: ${a}) -> (isConsentProvided: ${d})`,d}_getFeatureVariables(a){let{visitorCode:b,featureKey:c,variationKey:d}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d})`;const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c);const g=f.variations.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d}) -> (variables: ${g.variables})`,g.variables}_getActiveFeatureVariations(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a})`;const b=this.clientConfiguration.featureFlags,c=[];for(const d of b.values()){if(!d.environmentEnabled)continue;const b=this._evaluate({visitorCode:a,featureFlag:d,track:!1,save:!1});b.variationKey!==_constants.OFF_VARIATION_KEY&&c.push({variationKey:b.variationKey,variationId:b.variationId,experimentId:b.experimentId,featureFlagId:d.id,featureKey:d.featureKey,rule:null,isTargetedRule:b.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY})}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a}) -> (activeVariations: ${c})`,c}_evaluate(a){let{visitorCode:b,featureFlag:c,track:d,save:e}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e})`;let f,g=null;const h=this.variationConfiguration.getForcedFeatureVariation(b,c.featureKey);if(h.ok&&(g=h.data),g)f=KameleoonClient.EvaluatedExperiment.fromForcedFeatureVariation(c.defaultVariationKey,g);else if(this._isVisitorNotInHoldout(b,d,e)&&this._isFFUnrestrictedByMEGroup(b,c)){const a=this.dataManager.getVisitorData(b),g=this.dataManager.getVisitorIdentifier(b),h=this.variationConfiguration.getVariation({visitorCode:b,visitorIdentifier:g,featureFlag:c,track:d,withAssignment:e,targetingData:a,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();f=KameleoonClient.EvaluatedExperiment.fromVariationData(h)}else f=KameleoonClient.EvaluatedExperiment.fromDefaultVariationKey(c.defaultVariationKey);return e&&!f.isSimulated&&null!==f.experimentId&&null!==f.variationId&&this.variationConfiguration.updateStoredVariations(b,{[f.experimentId]:{variationId:f.variationId,isTargetedRule:f.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY,status:d?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}}),this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:c.featureKey,variation:{key:f.variationKey,experimentId:f.experimentId,id:f.variationId}}),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e}) -> (evalExp: ${f})`,f}_isFFUnrestrictedByMEGroup(a,b){const c=b.mutuallyExclusiveGroup;if(!c)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: ${a}, featureFlag: ${b})`;let d=!0;const e=this.clientConfiguration.meGroups.get(c);if(e){const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDoubleForMEGroup(f,c);_logging.KameleoonLogger.debug`Calculated meGroup hash ${g} for code: '${f}', meGroup: '${c}'`,d=e.getFeatureFlagByHash(g)===b}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: '${a}', featureFlag: ${b}) -> (selected: ${d})`,d}_getFeatureVariation(a){let{visitorCode:b,featureKey:c,track:d}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c));if(!f.environmentEnabled)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled,f.featureKey,this.environment));const g=this._evaluate({visitorCode:b,featureFlag:f,track:d,save:!0}),{experimentId:h,variationId:i,variationKey:j,isSimulated:k}=g;let l=new Map,m=!1;try{const a=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:j});a.forEach(a=>{m||a.type!==_types.VariableType.JS&&a.type!==_types.VariableType.CSS||(m=!0);const b=_utilities.Parser.parseFeatureVariable(a).throw();l.set(a.key,b)})}catch(_){}h&&"number"==typeof i&&!k&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,hasJsCssVariables:m,visitorCode:b,experimentId:h,variationId:i}),d&&!k&&this.tracker.scheduleVisitor(b,this._isConsentProvided(b));const n={key:j,id:i,experimentId:h,variables:l};return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${n})`,(0,_tsRes.Ok)(n)}_isVisitorNotInHoldout(a,b,c){const d=this.clientConfiguration.holdout;if(!d)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c})`;let e=!0;const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDouble({visitorIdentifier:f,respoolTime:null,id:d.experimentId+""});_logging.KameleoonLogger.debug`Calculated holdoutHash: ${g} for visitorCode: ${f}`;let h=_utilities.Utilities.getVariationByHash(d.variationByExposition,g);return null!==h&&(e=h.variationKey!==_constants.IN_HOLDOUT_VARIATION_KEY,c&&this.variationConfiguration.updateStoredVariations(a,{[d.experimentId]:{variationId:h.variationId,isTargetedRule:!1,status:b?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}})),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c}) -> (isNotInHoldout: ${e})`,e}_setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,null===d){const a=this.variationConfiguration.updateForcedExperimentVariation(b,c,null);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${a})`,a}let f=null,g=null;if(f=this.clientConfiguration.experimentMap.get(c),!f)return _logging.KameleoonLogger.error`Experiment with id ${c} not found for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagExperimentNotFound,c,b));if(g=f.variations.get(d),void 0===g)return _logging.KameleoonLogger.error`Variation with key ${d} not found in experiment ${f} for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b));f={type:f.type,experimentId:c},g={variationKey:d,variationId:g};const h=this.variationConfiguration.updateForcedExperimentVariation(b,c,{rule:f,varByExp:g,forceTargeting:e});return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${h})`,h}}exports.KameleoonClient=KameleoonClient,_defineProperty(KameleoonClient,"EvaluatedExperiment",class{static fromForcedFeatureVariation(a,b){var c,d,e;let f=a;return b.varByExp?f=b.varByExp.variationKey:b.rule&&b.rule.type===_clientConfiguration.RuleType.EXPERIMENTATION&&(f=_constants.OFF_VARIATION_KEY),{variationKey:f,variationId:(null===(c=b.varByExp)||void 0===c?void 0:c.variationId)||null,experimentId:(null===(d=b.rule)||void 0===d?void 0:d.experimentId)||null,ruleType:(null===(e=b.rule)||void 0===e?void 0:e.type)||null,isSimulated:b.simulated}}static fromVariationData(a){var b,c;return{variationKey:a.variationKey,variationId:a.variationId,experimentId:a.experimentId,ruleType:null!==(b=null===(c=a.rule)||void 0===c?void 0:c.type)&&void 0!==b?b:null,isSimulated:!1}}static fromDefaultVariationKey(a){return{variationKey:a,variationId:null,experimentId:null,ruleType:null,isSimulated:!1}}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonClient=void 0;var _tsRes=require("ts-res"),_cacheManager=require("./cacheManager"),_clientConfiguration=require("./clientConfiguration"),_clientSettings=require("./clientSettings"),_constants=require("./constants"),_kameleoonData=require("./kameleoonData"),_kameleoonError=require("./kameleoonError"),_requester=require("./requester"),_storage=require("./storage"),_types=require("./types"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_eventSource=require("./eventSource"),_visitorCodeManager=require("./visitorCodeManager"),_eventManager=require("./eventManager"),_tracking=require("./tracking"),_logging=require("./logging"),_hasher=require("./hasher");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class KameleoonClient{constructor(a){var b;let{siteCode:c,dependencies:d,configuration:e,internalConfiguration:f,stubMode:g}=a;if(_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"clientConfiguration",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"consentDataStorage",void 0),_defineProperty(this,"trackingCache",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"externalPackageInfo",void 0),_defineProperty(this,"initialized",!1),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),_defineProperty(this,"tracker",void 0),_defineProperty(this,"environment",void 0),_defineProperty(this,"stubMode",void 0),this.stubMode=g,g)return this.variationConfiguration={},this.clientConfiguration={},this.dataManager={},this.consentDataStorage={},this.trackingCache={},this.requester={},this.externalPackageInfo={},this.visitorCodeManager={},this.eventManager={},this.tracker={},void(this.environment="");const h=null===f||void 0===f?void 0:f.externals.externalLogger;h&&_logging.KameleoonLogger.setLogger(h),_logging.KameleoonLogger.debug`CALL: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`;const{settings:i}=new _clientSettings.ClientSettings(c,e);this.environment=i.environment;const{externalStorage:j,externalEventSource:k,externalPackageInfo:l,externalVisitorCodeManager:m,externalRequester:n,externalPRNG:o}=f.externals,{useAbortController:p}=f.settings,q=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),r=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ClientData),s=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TargetingData),t=new _storage.DataStorage(j,_storage.KameleoonStorageKey.DataInfo),u=new _storage.DataStorage(j,_storage.KameleoonStorageKey.VariationData),v=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedExperimentVariation),w=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedFeatureVariation),x=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ConsentData),y=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TrackingData),z=new _kameleoonData.DataManager({dataStorage:s,infoStorage:t,cleanupInterval:i.cleanupInterval,packageInfo:l}),A=null!==(b=null===d||void 0===d?void 0:d.urlProvider)&&void 0!==b?b:new _requester.UrlProvider;A.initialize({domain:i.networkDomain,siteCode:i.siteCode,packageInfo:l,environment:i.environment});const B=new _requester.Requester({urlProvider:A,useAbortController:p,packageInfo:l,externalRequester:n,requestTimeout:i.requestTimeout,trackRetryDelay:i.trackRetryDelay}),C=new _eventSource.KameleoonEventSource({siteCode:i.siteCode,externalEventSource:k,urlProvider:A}),D=new _eventManager.EventManager,E=new _clientConfiguration.ClientConfiguration({urlProvider:A,storage:r,updateInterval:i.updateInterval,dataManager:z,eventManager:D,requester:B,eventSource:C,externalVisitorCodeManager:m}),F=new _variationConfiguration.VariationConfiguration(u,v,w,m,E),G=new _tracking.Tracker({dataManager:z,trackingStorage:y,variationConfiguration:F,requester:B,trackingInterval:i.trackingInterval,prng:o});this.tracker=G,this.variationConfiguration=F,this.requester=B,this.trackingCache=q,this.dataManager=z,this.clientConfiguration=E,this.externalPackageInfo=l,this.consentDataStorage=x,this.visitorCodeManager=m,this.eventManager=D,null!==i.cleanupInterval&&new _storage.StorageCleanupManager(j,i.cleanupInterval),_logging.KameleoonLogger.debug`RETURN: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`}async initialize(){if(this.stubMode)return!1;_logging.KameleoonLogger.info("CALL: KameleoonClient.initialize()");const a=await this.clientConfiguration.initialize();return a.throw(),this.initialized=!0,_logging.KameleoonLogger.info`RETURN: KameleoonClient.initialize() -> (result: ${a.ok})`,a.ok}addData(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];if(_logging.KameleoonLogger.info`CALL: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`,this.visitorCodeManager.validateVisitorCode(a).throw(),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.dataManager.storeData(a,...c).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`}async getRemoteVisitorData(a){let{visitorCode:b,shouldAddData:c=!0,filters:d=_constants.DEFAULT_VISITOR_DATA_FILTERS}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(b).throw();const{previousVisitAmount:e}=d;if("number"==typeof e&&(1>e||25<e))throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitAmount);const f=this.dataManager.isUniqueIdentifier(b),g=await this.requester.getVisitorData({visitorCode:b,filters:d,isMappingIdentifier:f}),h=g.throw(),{visitorData:i,storageVisitorData:j,visitsData:k,mappingIdentifier:l}=_utilities.Parser.parseVisitorData({data:h,filters:d,visitorCode:b,dataManager:this.dataManager,variationConfiguration:this.variationConfiguration});for(const d of j)(c||this.dataManager.isPersistentCustomData(d))&&this.addData(b,d);return k&&c&&this.addData(b,k),null!==d&&void 0!==d&&d.visitorCode&&l&&this.dataManager.setMappingIdentifier(b,l),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d}) -> (visitorData: ${i})`,i}trackConversion(a){let{visitorCode:b,goalId:c,negative:d,revenue:e,metadata:f}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`,this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:e,negative:d,metadata:f})),this.flush(b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`)}flush(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.flush(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a)return this.visitorCodeManager.validateVisitorCode(a).throw(),this.tracker.scheduleVisitor(a,this._isConsentProvided(a)),void _logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`;for(const b of this.dataManager.unsentDataVisitors)this.tracker.scheduleVisitor(b,this._isConsentProvided(b));_logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`}getFeatureFlags(){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info("CALL: KameleoonClient.getFeatureFlags()"),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);const a=this.clientConfiguration.featureFlags,b=[];return a.forEach(a=>{let{id:c,featureKey:d}=a;b.push({id:c,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlags() -> (FeatureFlags: ${b})`,b}getVisitorFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=[];return b.forEach(a=>{let{featureFlagId:b,featureKey:d}=a;c.push({id:b,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getVariation(a){let{visitorCode:b,featureKey:c,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=this._getFeatureVariation({visitorCode:b,featureKey:c,track:d}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${e})`,e}getVariations(a){let{visitorCode:b,onlyActive:c=!1,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=new Map,f=this.clientConfiguration.featureFlags;for(const g of f.values()){const a=this._getFeatureVariation({visitorCode:b,featureKey:g.featureKey,track:d});a.ok&&(!c||a.data.key!==_constants.OFF_VARIATION_KEY)&&e.set(g.featureKey,a.data)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d}) -> (variations: ${e})`,e}getActiveFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=new Map;return b.forEach(b=>{const{variationKey:d,featureKey:e,variationId:f,experimentId:g}=b;let h=[];null!==f&&null!==g&&(h=this._getFeatureVariables({visitorCode:a,featureKey:e,variationKey:d}));const i=h.map(a=>_utilities.Parser.parseFeatureVariable(a).throw());c.set(b.featureKey,{key:d,id:f,experimentId:g,variables:i})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getFeatureFlagVariationKey(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b}) -> (variationKey: ${c})`,c}getFeatureFlagVariable(a){let{visitorCode:b,featureKey:c,variableKey:d}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const{key:e}=this._getFeatureVariation({visitorCode:b,featureKey:c,track:!0}).throw(),f=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:e}),g=f.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariableNotFound,d,b);const{type:h,value:i}=_utilities.Parser.parseFeatureVariable(g).throw(),j={type:h,value:i};return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d}) -> (FeatureFlagVariable: ${j})`,j}getFeatureFlagVariables(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw(),d=this._getFeatureVariables({visitorCode:a,featureKey:b,variationKey:c}),e=[];for(const c of d){const a=_utilities.Parser.parseFeatureVariable(c).throw();e.push(a)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b}) -> (FeatureFlagVariables: ${e})`,e}isFeatureFlagActive(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);let[c,d,e]=["","",!0];"string"==typeof a?(c=a,d=b):([c,d]=[a.visitorCode,a.featureKey],a.track!==void 0&&(e=a.track)),_logging.KameleoonLogger.info`CALL: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track ${e})`,this.visitorCodeManager.validateVisitorCode(c).throw();try{const{key:a}=this._getFeatureVariation({visitorCode:c,featureKey:d,track:e}).throw(),b=a!==_constants.OFF_VARIATION_KEY;return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: ${b})`,b}catch(a){if(a instanceof _kameleoonError.KameleoonError&&a.type===_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: false)`,!1;throw a}}async getRemoteData(a){if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteData(key: ${a})`;const b=await this.requester.getRemoteData(a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteData(key: ${a}) -> (remoteData: ${b})`,b.throw()}async getVisitorWarehouseAudience(a){let{visitorCode:b,customDataIndex:c,warehouseKey:d}=a;if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=await this.getRemoteData(d||b);if(!e)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,`No data found for ${d||b} key`);if(!e[_constants.WAREHOUSE_AUDIENCE_KEY]||0===Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]).length)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: null)`,null;const f=new _kameleoonData.CustomData(c,...Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]));return this.dataManager.storeData(b,f),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: ${f})`,f}onEvent(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.onEvent(event: ${a}, callback)`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(a,b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.onEvent(event: ${a}, callback)`}getEngineTrackingCode(a){if(this.stubMode)return"";_logging.KameleoonLogger.info`CALL: KameleoonClient.getEngineTrackingCode(visitorCode: ${a})`,this.visitorCodeManager.validateVisitorCode(a).throw();const b=_utilities.Utilities.getTrackingCode(this.trackingCache,a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getEngineTrackingCode(visitorCode: ${a}) -> (trackingCode: ${b})`,b}isInitialized(){return _logging.KameleoonLogger.debug`CALL/RETURN: KameleoonClient.isInitialized() -> (initialized: ${this.initialized})`,this.initialized}setLogLevel(a){_logging.KameleoonLogger.setLogLevel(a)}setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this._setForcedVariation({visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e}).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`)}setUserConsent(a){let{visitorCode:b,consent:c,setData:d}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this.updateConsentData(b,c),c?d({visitorCode:b,key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.DEFAULT_MAX_AGE,path:_visitorCodeManager.PATH}):this.visitorCodeManager.consentRequired&&d({visitorCode:"",key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.ZERO_MAX_AGE,path:_visitorCodeManager.PATH}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`)}updateConsentData(a,b){const c=this.consentDataStorage.read();if(!c.ok)return void(c.error.type===_kameleoonError.KameleoonException.StorageEmpty&&this.consentDataStorage.write({[a]:{consent:b}}));const d=c.data;d[a]={consent:b},this.consentDataStorage.write(d)}_isConsentProvided(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._isConsentProvided(visitorCode: ${a})`;const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read();let d=!1;if(!b)d=!0;else if(c.ok){const b=c.data[a];d="boolean"==typeof b?b:b&&b.consent}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isConsentProvided(visitorCode: ${a}) -> (isConsentProvided: ${d})`,d}_getFeatureVariables(a){let{visitorCode:b,featureKey:c,variationKey:d}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d})`;const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c);const g=f.variations.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d}) -> (variables: ${g.variables})`,g.variables}_getActiveFeatureVariations(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a})`;const b=this.clientConfiguration.featureFlags,c=[];for(const d of b.values()){if(!d.environmentEnabled)continue;const b=this._evaluate({visitorCode:a,featureFlag:d,track:!1,save:!1});b.variationKey!==_constants.OFF_VARIATION_KEY&&c.push({variationKey:b.variationKey,variationId:b.variationId,experimentId:b.experimentId,featureFlagId:d.id,featureKey:d.featureKey,rule:null,isTargetedRule:b.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY})}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a}) -> (activeVariations: ${c})`,c}_evaluate(a){let{visitorCode:b,featureFlag:c,track:d,save:e}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e})`;let f,g=null;const h=this.variationConfiguration.getForcedFeatureVariation(b,c.featureKey);if(h.ok&&(g=h.data),g)f=KameleoonClient.EvaluatedExperiment.fromForcedFeatureVariation(c.defaultVariationKey,g);else if(this._isVisitorNotInHoldout(b,d,e)&&this._isFFUnrestrictedByMEGroup(b,c)){const a=this.dataManager.getVisitorData(b),g=this.dataManager.getVisitorIdentifier(b),h=this.variationConfiguration.getVariation({visitorCode:b,visitorIdentifier:g,featureFlag:c,track:d,withAssignment:e,targetingData:a,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();f=KameleoonClient.EvaluatedExperiment.fromVariationData(h)}else f=KameleoonClient.EvaluatedExperiment.fromDefaultVariationKey(c.defaultVariationKey);return e&&!f.isSimulated&&null!==f.experimentId&&null!==f.variationId&&this.variationConfiguration.updateStoredVariations(b,{[f.experimentId]:{variationId:f.variationId,isTargetedRule:f.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY,status:d?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}}),this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:c.featureKey,variation:{key:f.variationKey,experimentId:f.experimentId,id:f.variationId}}),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e}) -> (evalExp: ${f})`,f}_isFFUnrestrictedByMEGroup(a,b){const c=b.mutuallyExclusiveGroup;if(!c)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: ${a}, featureFlag: ${b})`;let d=!0;const e=this.clientConfiguration.meGroups.get(c);if(e){const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDoubleForMEGroup(f,c);_logging.KameleoonLogger.debug`Calculated meGroup hash ${g} for code: '${f}', meGroup: '${c}'`,d=e.getFeatureFlagByHash(g)===b}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: '${a}', featureFlag: ${b}) -> (selected: ${d})`,d}_getFeatureVariation(a){let{visitorCode:b,featureKey:c,track:d}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c));if(!f.environmentEnabled)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled,f.featureKey,this.environment));const g=this._evaluate({visitorCode:b,featureFlag:f,track:d,save:!0}),{experimentId:h,variationId:i,variationKey:j,isSimulated:k}=g;let l=new Map,m=!1;try{const a=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:j});a.forEach(a=>{m||a.type!==_types.VariableType.JS&&a.type!==_types.VariableType.CSS||(m=!0);const b=_utilities.Parser.parseFeatureVariable(a).throw();l.set(a.key,b)})}catch(_){}h&&"number"==typeof i&&!k&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,hasJsCssVariables:m,visitorCode:b,experimentId:h,variationId:i}),d&&!k&&this.tracker.scheduleVisitor(b,this._isConsentProvided(b));const n={key:j,id:i,experimentId:h,variables:l};return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${n})`,(0,_tsRes.Ok)(n)}_isVisitorNotInHoldout(a,b,c){const d=this.clientConfiguration.holdout;if(!d)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c})`;let e=!0;const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDouble({visitorIdentifier:f,respoolTime:null,id:d.experimentId+""});_logging.KameleoonLogger.debug`Calculated holdoutHash: ${g} for visitorCode: ${f}`;let h=_utilities.Utilities.getVariationByHash(d.variationByExposition,g);return null!==h&&(e=h.variationKey!==_constants.IN_HOLDOUT_VARIATION_KEY,c&&this.variationConfiguration.updateStoredVariations(a,{[d.experimentId]:{variationId:h.variationId,isTargetedRule:!1,status:b?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}})),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c}) -> (isNotInHoldout: ${e})`,e}_setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,null===d){const a=this.variationConfiguration.updateForcedExperimentVariation(b,c,null);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${a})`,a}let f=null,g=null;if(f=this.clientConfiguration.experimentMap.get(c),!f)return _logging.KameleoonLogger.error`Experiment with id ${c} not found for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagExperimentNotFound,c,b));if(g=f.variations.get(d),void 0===g)return _logging.KameleoonLogger.error`Variation with key ${d} not found in experiment ${f} for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b));f={type:f.type,experimentId:c},g={variationKey:d,variationId:g};const h=this.variationConfiguration.updateForcedExperimentVariation(b,c,{rule:f,varByExp:g,forceTargeting:e});return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${h})`,h}}exports.KameleoonClient=KameleoonClient,_defineProperty(KameleoonClient,"EvaluatedExperiment",class{static fromForcedFeatureVariation(a,b){var c,d,e;let f=a;return b.varByExp?f=b.varByExp.variationKey:b.rule&&b.rule.type===_clientConfiguration.RuleType.EXPERIMENTATION&&(f=_constants.OFF_VARIATION_KEY),{variationKey:f,variationId:(null===(c=b.varByExp)||void 0===c?void 0:c.variationId)||null,experimentId:(null===(d=b.rule)||void 0===d?void 0:d.experimentId)||null,ruleType:(null===(e=b.rule)||void 0===e?void 0:e.type)||null,isSimulated:b.simulated}}static fromVariationData(a){var b,c;return{variationKey:a.variationKey,variationId:a.variationId,experimentId:a.experimentId,ruleType:null!==(b=null===(c=a.rule)||void 0===c?void 0:c.type)&&void 0!==b?b:null,isSimulated:!1}}static fromDefaultVariationKey(a){return{variationKey:a,variationId:null,experimentId:null,ruleType:null,isSimulated:!1}}});
|
|
@@ -45,6 +45,7 @@ export declare class DataManager implements IDataManager {
|
|
|
45
45
|
isPersistentCustomData(dataItem: KameleoonDataType): dataItem is CustomData;
|
|
46
46
|
isUniqueIdentifier(visitorCode: string): boolean;
|
|
47
47
|
getVisitorIdentifier(visitorCode: string): string;
|
|
48
|
+
getMappingIdentifier(visitorCode: string): MappingIdentifierType | undefined;
|
|
48
49
|
setMappingIdentifier(visitorCode: string, mappingIdentifier: MappingIdentifierType): void;
|
|
49
50
|
getVisitorData(visitorCode: string): KameleoonVisitorDataType | undefined;
|
|
50
51
|
getVisitorStoredDataTypes(visitorCode: string): Set<KameleoonData>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_customData=require("./customData"),_types=require("./types"),_storage=require("../storage"),_clientConfiguration=require("../clientConfiguration"),_utilities=require("../utilities"),_conversion=require("./conversion"),_pageView=require("./pageView"),_browser=require("./browser"),_device=require("./device"),_geolocation=require("./geolocation"),_types2=require("../types"),_operatingSystem=require("./operatingSystem"),_logging=require("../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{dataStorage:b,infoStorage:c,cleanupInterval:d,packageInfo:e}=a;if(_defineProperty(this,"dataStorage",void 0),_defineProperty(this,"infoStorage",void 0),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"cleanupIntervalId",null),_defineProperty(this,"packageInfo",void 0),_logging.KameleoonLogger.debug`CALL: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`,this.dataStorage=b,this.infoStorage=c,this.dataProcessor=new _dataProcessor.DataProcessor(d,e),this.packageInfo=e,d){const a=()=>{this.cleanupData()};try{this.cleanupIntervalId=setInterval(a,d)}catch(a){throw this.cleanupIntervalId&&clearInterval(this.cleanupIntervalId),_logging.KameleoonLogger.error`Failed to set cleanup interval: ${d}`,a}}_logging.KameleoonLogger.debug`RETURN: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`}getUnsentData(a){const b=this.infoStorage.read();if(!b.ok)return[];const c=b.data,d=this.getVisitorData(a);if(!c.unsentData[a]||!d)return[];const e=c.unsentData[a],f=c.nextVisitTime<=Date.now(),g=a=>{let{status:b,key:c,cdIndex:d}=a;return!!("number"==typeof d&&this.persistentCustomDataIndexes.has(d)&&f)||e.includes(c)&&b===_types2.TrackingStatus.Unsent};return f&&(c.nextVisitTime=Date.now()+_storage.VISIT_DURATION,this.infoStorage.write(c)),this.getDataFromRaw(d,g)}getPendingData(a){const b=this.getVisitorData(a);if(!b)return[];return this.getDataFromRaw(b,a=>{let{status:b}=a;return b===_types2.TrackingStatus.Pending})}getDataFromRaw(a,b){const c=[];for(const[d,e]of Object.entries(a))if(e)switch(d){case _types.KameleoonData.CustomData:{for(const a of Object.values(e)){if(!a)continue;const{status:e,index:f}=a;if(b({status:e,key:d,cdIndex:f})){const b=_customData.CustomData._fromRaw(a);c.push(b)}}break}case _types.KameleoonData.Conversion:{for(const a of Object.values(e))if(a&&b({status:a.status,key:d})){const b=_conversion.Conversion._fromRaw(a);c.push(b)}break}case _types.KameleoonData.PageView:{for(const a of Object.values(e))if(b({status:a.status,key:d})){const b=_pageView.PageView._fromRaw(a);c.push(b)}break}case _types.KameleoonData.GeolocationData:{const a=e;if(!e)continue;if(b({status:a.status,key:d})){const b=_geolocation.GeolocationData._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Browser:{const a=e;if(b({status:a.status,key:d})){const b=_browser.Browser._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Device:{const a=e;if(b({status:a.status,key:d})){const b=_device.Device._fromRaw(a);c.push(b)}break}case _types.KameleoonData.OperatingSystem:{const a=e;if(b({status:a.status,key:d})){const b=_operatingSystem.OperatingSystem._fromRaw(a);c.push(b)}}}return c}storeTrackedData(a){this.storeData(a);const b=this.infoStorage.read();if(b.ok){const c=b.data.unsentData;for(const[b,d]of Object.entries(a)){if(!c[b])return;const a=new Set(c[b]);d.forEach(b=>{let{data:c}=b;a.has(c.type)&&a.delete(c.type)});const e=d.some(a=>{let{data:b}=a;if(b.type!==_types.KameleoonData.CustomData)return!1;const{index:c}=b;return this.persistentCustomDataIndexes.has(c)||this.mappingIdentifierCustomDataIndex===c});e&&a.add(_types.KameleoonData.CustomData),c[b]=Array.from(a),c[b].length||delete c[b]}this.infoStorage.write(b.data)}}storeData(a){for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];_logging.KameleoonLogger.debug`CALL: DataManager.storeData(visitorCode: ${a}, data: ${c})`;const e=this.dataStorage.read(),f=this.infoStorage.read();if(!e.ok)return e;if(!f.ok)return f;const g=e.data,h=f.data;if("string"==typeof a)this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:a,kameleoonData:c});else for(const[b,c]of Object.entries(a))this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:b,kameleoonData:c});this.cleanupData(),this.infoStorage.write(f.data);const i=this.dataStorage.write(g);return _logging.KameleoonLogger.debug`RETURN: DataManager.storeData(visitorCode: ${a}, data: ${c}) -> (writeResult: ${i})`,i}getTree(a){if(this.targetingTrees.has(a.id))return this.targetingTrees.get(a.id);const b=new _targeting.Tree(a);return this.targetingTrees.set(a.id,b),b}clearTrees(){this.targetingTrees.clear()}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}isUniqueIdentifier(a){var b;const c=this.getVisitorData(a),d=null===c||void 0===c?void 0:c[_types.KameleoonData.UniqueIdentifier];return!(null===(b=null===d||void 0===d?void 0:d.value)||void 0===b)&&b}getVisitorIdentifier(a){var b,c,d;const e=this.infoStorage.read();if(!e.ok)return a;const f=e.data;return null!==(b=f.mappingIdentifiers)&&void 0!==b?b:f.mappingIdentifiers={},null!==(c=null===(d=f.mappingIdentifiers[a])||void 0===d?void 0:d.mappingIdentifier)&&void 0!==c?c:a}setMappingIdentifier(a,b){var c;const d=this.infoStorage.read();if(d.ok){const e=d.data;null!==(c=e.mappingIdentifiers)&&void 0!==c?c:e.mappingIdentifiers={};const f=e.mappingIdentifiers[a];(!f||f.timestamp<b.timestamp)&&(e.mappingIdentifiers[a]=b,this.infoStorage.write(e))}}getVisitorData(a){this.cleanupData();const b=this.dataStorage.read();if(!b.ok)return;let{visitorReference:c,data:d,isReference:e}=this.dataProcessor.dereferenceData(b.data,a);if(this.packageInfo.isServer&&e&&!d[c]){const b=this.infoStorage.read();b.ok&&b.data.mappingIdentifiers&&delete b.data.mappingIdentifiers[a],delete d[a],c=a}return d[c]}getVisitorStoredDataTypes(a){const b=this.getVisitorData(a);return b?new Set(Object.keys(b)):new Set}getLinkedVisitor(a){const b=this.dataStorage.read();if(!b.ok)return null;if("string"==typeof b.data[a])return b.data[a];if(null===this.mappingIdentifierCustomDataIndex)return null;const c=b.data[a];if(!c)return null;const d=c[_types.KameleoonData.CustomData];return d&&d[this.mappingIdentifierCustomDataIndex]?d[this.mappingIdentifierCustomDataIndex].value[0]:null}mutUpdateTargetingData(a){let{infoData:b,visitorCode:c,kameleoonData:d,targetingData:e}=a;for(const f of d){f.data.type===_types.KameleoonData.CustomData&&this.processCustomData({infoData:b,customData:f,mutData:e,visitorCode:c});const a=this.dataProcessor.mutUpdateData({infoData:b,visitorCode:c,mutData:e,dataItem:f}),d=b.nextDataCleanup;(!d||d&&a<d)&&(b.nextDataCleanup=a),f.data.status===_types2.TrackingStatus.Unsent&&this.dataProcessor.mutAddUnsentData({mutData:b,visitorCode:c,dataType:f.data.type})}}cleanupData(){const a=this.dataStorage.read(),b=this.infoStorage.read();if(!a.ok||!b.ok)return;const c=a.data,d=b.data,e=d.nextDataCleanup;if(e&&e<Date.now()){const a=this.dataProcessor.mutCleanupData(c,d);d.nextDataCleanup=a||void 0,this.infoStorage.write(d),this.dataStorage.write(c)}}processCustomData(a){let{infoData:b,mutData:c,customData:d,visitorCode:e}=a;const{data:f}=d,g=!!(f.value.length&&f.value[0].length);if(this.mappingIdentifierCustomDataIndex===f.index&&g){d._isMappingIdentifier=!0;const a=f.value[0];if(e!==a){var h;_logging.KameleoonLogger.info`Linked anonymous visitor ${e} with user ${a}`,this.dataProcessor.createReference({infoData:b,mutData:c,visitorCode:e,linkedVisitor:f.value[0]}),null!==(h=b.mappingIdentifiers)&&void 0!==h?h:b.mappingIdentifiers={},b.mappingIdentifiers[a]={mappingIdentifier:e,timestamp:Date.now()}}}this.localCustomDataIndexes.has(f.index)&&(d.status=_types2.TrackingStatus.Sent)}get unsentDataVisitors(){const a=this.infoStorage.read();return a.ok?Object.keys(a.data.unsentData):[]}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get trees(){return this.targetingTrees}get storedCustomDataIndexes(){const a=this.dataStorage.read();if(!a.ok)return new Set;const b=a.data;if(!(_types.KameleoonData.CustomData in b))return new Set;const c=new Set;for(const a in Object.keys(b[_types.KameleoonData.CustomData]))c.add(+a);return c}set customDataIndexes(a){var b;const[c,d]=[[],[]];a.forEach(a=>{a.localOnly&&c.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&d.push(a.index)}),this.mappingIdentifierCustomDataIndex=(null===(b=a.find(a=>a.isMappingIdentifier))||void 0===b?void 0:b.index)||null,this.localCustomDataIndexes=new Set(c),this.persistentCustomDataIndexes=new Set(d)}}exports.DataManager=DataManager;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_customData=require("./customData"),_types=require("./types"),_storage=require("../storage"),_clientConfiguration=require("../clientConfiguration"),_utilities=require("../utilities"),_conversion=require("./conversion"),_pageView=require("./pageView"),_browser=require("./browser"),_device=require("./device"),_geolocation=require("./geolocation"),_types2=require("../types"),_operatingSystem=require("./operatingSystem"),_logging=require("../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{dataStorage:b,infoStorage:c,cleanupInterval:d,packageInfo:e}=a;if(_defineProperty(this,"dataStorage",void 0),_defineProperty(this,"infoStorage",void 0),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"cleanupIntervalId",null),_defineProperty(this,"packageInfo",void 0),_logging.KameleoonLogger.debug`CALL: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`,this.dataStorage=b,this.infoStorage=c,this.dataProcessor=new _dataProcessor.DataProcessor(d,e),this.packageInfo=e,d){const a=()=>{this.cleanupData()};try{this.cleanupIntervalId=setInterval(a,d)}catch(a){throw this.cleanupIntervalId&&clearInterval(this.cleanupIntervalId),_logging.KameleoonLogger.error`Failed to set cleanup interval: ${d}`,a}}_logging.KameleoonLogger.debug`RETURN: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`}getUnsentData(a){const b=this.infoStorage.read();if(!b.ok)return[];const c=b.data,d=this.getVisitorData(a);if(!c.unsentData[a]||!d)return[];const e=c.unsentData[a],f=c.nextVisitTime<=Date.now(),g=a=>{let{status:b,key:c,cdIndex:d}=a;return!!("number"==typeof d&&this.persistentCustomDataIndexes.has(d)&&f)||e.includes(c)&&b===_types2.TrackingStatus.Unsent};return f&&(c.nextVisitTime=Date.now()+_storage.VISIT_DURATION,this.infoStorage.write(c)),this.getDataFromRaw(d,g)}getPendingData(a){const b=this.getVisitorData(a);if(!b)return[];return this.getDataFromRaw(b,a=>{let{status:b}=a;return b===_types2.TrackingStatus.Pending})}getDataFromRaw(a,b){const c=[];for(const[d,e]of Object.entries(a))if(e)switch(d){case _types.KameleoonData.CustomData:{for(const a of Object.values(e)){if(!a)continue;const{status:e,index:f}=a;if(b({status:e,key:d,cdIndex:f})){const b=_customData.CustomData._fromRaw(a);c.push(b)}}break}case _types.KameleoonData.Conversion:{for(const a of Object.values(e))if(a&&b({status:a.status,key:d})){const b=_conversion.Conversion._fromRaw(a);c.push(b)}break}case _types.KameleoonData.PageView:{for(const a of Object.values(e))if(b({status:a.status,key:d})){const b=_pageView.PageView._fromRaw(a);c.push(b)}break}case _types.KameleoonData.GeolocationData:{const a=e;if(!e)continue;if(b({status:a.status,key:d})){const b=_geolocation.GeolocationData._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Browser:{const a=e;if(b({status:a.status,key:d})){const b=_browser.Browser._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Device:{const a=e;if(b({status:a.status,key:d})){const b=_device.Device._fromRaw(a);c.push(b)}break}case _types.KameleoonData.OperatingSystem:{const a=e;if(b({status:a.status,key:d})){const b=_operatingSystem.OperatingSystem._fromRaw(a);c.push(b)}}}return c}storeTrackedData(a){this.storeData(a);const b=this.infoStorage.read();if(b.ok){const c=b.data.unsentData;for(const[b,d]of Object.entries(a)){if(!c[b])return;const a=new Set(c[b]);d.forEach(b=>{let{data:c}=b;a.has(c.type)&&a.delete(c.type)});const e=d.some(a=>{let{data:b}=a;if(b.type!==_types.KameleoonData.CustomData)return!1;const{index:c}=b;return this.persistentCustomDataIndexes.has(c)||this.mappingIdentifierCustomDataIndex===c});e&&a.add(_types.KameleoonData.CustomData),c[b]=Array.from(a),c[b].length||delete c[b]}this.infoStorage.write(b.data)}}storeData(a){for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];_logging.KameleoonLogger.debug`CALL: DataManager.storeData(visitorCode: ${a}, data: ${c})`;const e=this.dataStorage.read(),f=this.infoStorage.read();if(!e.ok)return e;if(!f.ok)return f;const g=e.data,h=f.data;if("string"==typeof a)this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:a,kameleoonData:c});else for(const[b,c]of Object.entries(a))this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:b,kameleoonData:c});this.cleanupData(),this.infoStorage.write(f.data);const i=this.dataStorage.write(g);return _logging.KameleoonLogger.debug`RETURN: DataManager.storeData(visitorCode: ${a}, data: ${c}) -> (writeResult: ${i})`,i}getTree(a){if(this.targetingTrees.has(a.id))return this.targetingTrees.get(a.id);const b=new _targeting.Tree(a);return this.targetingTrees.set(a.id,b),b}clearTrees(){this.targetingTrees.clear()}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}isUniqueIdentifier(a){var b;const c=this.getVisitorData(a),d=null===c||void 0===c?void 0:c[_types.KameleoonData.UniqueIdentifier];return!(null===(b=null===d||void 0===d?void 0:d.value)||void 0===b)&&b}getVisitorIdentifier(a){var b,c,d;const e=this.infoStorage.read();if(!e.ok)return a;const f=e.data;return null!==(b=f.mappingIdentifiers)&&void 0!==b?b:f.mappingIdentifiers={},null!==(c=null===(d=f.mappingIdentifiers[a])||void 0===d?void 0:d.mappingIdentifier)&&void 0!==c?c:a}getMappingIdentifier(a){const b=this.infoStorage.read();if(b.ok){const c=b.data;return c.mappingIdentifiers?c.mappingIdentifiers[a]:void 0}}setMappingIdentifier(a,b){var c;const d=this.infoStorage.read();if(d.ok){const e=d.data;null!==(c=e.mappingIdentifiers)&&void 0!==c?c:e.mappingIdentifiers={};const f=e.mappingIdentifiers[a];(!f||f.timestamp<b.timestamp)&&(e.mappingIdentifiers[a]=b,this.infoStorage.write(e))}}getVisitorData(a){this.cleanupData();const b=this.dataStorage.read();if(!b.ok)return;let{visitorReference:c,data:d,isReference:e}=this.dataProcessor.dereferenceData(b.data,a);if(this.packageInfo.isServer&&e&&!d[c]){const b=this.infoStorage.read();b.ok&&b.data.mappingIdentifiers&&delete b.data.mappingIdentifiers[a],delete d[a],c=a}return d[c]}getVisitorStoredDataTypes(a){const b=this.getVisitorData(a);return b?new Set(Object.keys(b)):new Set}getLinkedVisitor(a){const b=this.dataStorage.read();if(!b.ok)return null;if("string"==typeof b.data[a])return b.data[a];if(null===this.mappingIdentifierCustomDataIndex)return null;const c=b.data[a];if(!c)return null;const d=c[_types.KameleoonData.CustomData];return d&&d[this.mappingIdentifierCustomDataIndex]?d[this.mappingIdentifierCustomDataIndex].value[0]:null}mutUpdateTargetingData(a){let{infoData:b,visitorCode:c,kameleoonData:d,targetingData:e}=a;for(const f of d){f.data.type===_types.KameleoonData.CustomData&&this.processCustomData({infoData:b,customData:f,mutData:e,visitorCode:c});const a=this.dataProcessor.mutUpdateData({infoData:b,visitorCode:c,mutData:e,dataItem:f}),d=b.nextDataCleanup;(!d||d&&a<d)&&(b.nextDataCleanup=a),f.data.status===_types2.TrackingStatus.Unsent&&this.dataProcessor.mutAddUnsentData({mutData:b,visitorCode:c,dataType:f.data.type})}}cleanupData(){const a=this.dataStorage.read(),b=this.infoStorage.read();if(!a.ok||!b.ok)return;const c=a.data,d=b.data,e=d.nextDataCleanup;if(e&&e<Date.now()){const a=this.dataProcessor.mutCleanupData(c,d);d.nextDataCleanup=a||void 0,this.infoStorage.write(d),this.dataStorage.write(c)}}processCustomData(a){let{infoData:b,mutData:c,customData:d,visitorCode:e}=a;const{data:f}=d,g=!!(f.value.length&&f.value[0].length);if(this.mappingIdentifierCustomDataIndex===f.index&&g){d._isMappingIdentifier=!0;const a=f.value[0];if(e!==a){var h;_logging.KameleoonLogger.info`Linked anonymous visitor ${e} with user ${a}`,this.dataProcessor.createReference({infoData:b,mutData:c,visitorCode:e,linkedVisitor:f.value[0]}),null!==(h=b.mappingIdentifiers)&&void 0!==h?h:b.mappingIdentifiers={},b.mappingIdentifiers[a]={mappingIdentifier:e,timestamp:Date.now()}}}this.localCustomDataIndexes.has(f.index)&&(d.status=_types2.TrackingStatus.Sent)}get unsentDataVisitors(){const a=this.infoStorage.read();return a.ok?Object.keys(a.data.unsentData):[]}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get trees(){return this.targetingTrees}get storedCustomDataIndexes(){const a=this.dataStorage.read();if(!a.ok)return new Set;const b=a.data;if(!(_types.KameleoonData.CustomData in b))return new Set;const c=new Set;for(const a in Object.keys(b[_types.KameleoonData.CustomData]))c.add(+a);return c}set customDataIndexes(a){var b;const[c,d]=[[],[]];a.forEach(a=>{a.localOnly&&c.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&d.push(a.index)}),this.mappingIdentifierCustomDataIndex=(null===(b=a.find(a=>a.isMappingIdentifier))||void 0===b?void 0:b.index)||null,this.localCustomDataIndexes=new Set(c),this.persistentCustomDataIndexes=new Set(d)}}exports.DataManager=DataManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionFactory=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../../kameleoonError"),_types=require("../types"),_browser=require("./browser"),_conversion=require("./conversion"),_customData=require("./customData"),_device=require("./device"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionFactory=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../../kameleoonError"),_types=require("../types"),_browser=require("./browser"),_conversion=require("./conversion"),_customData=require("./customData"),_device=require("./device"),_pageTitle=require("./pageTitle"),_pageUrl=require("./pageUrl"),_sdkLanguage=require("./sdkLanguage"),_visitorCode=require("./visitorCode"),_cookie=require("./cookie"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_segment=require("./segment"),_targetFeatureFlag=require("./targetFeatureFlag"),_previousPage=require("./previousPage"),_visitedPages=require("./visitedPages"),_firstVisit=require("./firstVisit"),_lastVisit=require("./lastVisit"),_sameDayVisits=require("./sameDayVisits"),_visits=require("./visits"),_newVisitor=require("./newVisitor"),_applicationVersion=require("./applicationVersion"),_conversionLikelihood=require("./conversionLikelihood"),_logging=require("../../logging"),_exclusiveExperiment=require("./exclusiveExperiment"),_targetExperiment=require("./targetExperiment"),_targetPersonalization=require("./targetPersonalization"),_conditionFactoryInstance=require("./conditionFactoryInstance");class ConditionFactory{createCondition(a){const{targetingType:b}=a;return b===_types.TargetingType.CUSTOM_DATUM?(0,_tsRes.Ok)(new _customData.CustomData(a)):b===_types.TargetingType.EXCLUSIVE_EXPERIMENT?(0,_tsRes.Ok)(new _exclusiveExperiment.ExclusiveExperimentCondition(a)):b===_types.TargetingType.TARGET_EXPERIMENT?(0,_tsRes.Ok)(new _targetExperiment.TargetExperimentCondition(a)):b===_types.TargetingType.TARGET_FEATURE_FLAG?(0,_tsRes.Ok)(new _targetFeatureFlag.TargetFeatureFlag(a)):b===_types.TargetingType.TARGET_PERSONALIZATION?(0,_tsRes.Ok)(new _targetPersonalization.TargetPersonalizationCondition(a)):b===_types.TargetingType.DEVICE_TYPE?(0,_tsRes.Ok)(new _device.Device(a)):b===_types.TargetingType.BROWSER?(0,_tsRes.Ok)(new _browser.Browser(a)):b===_types.TargetingType.PAGE_URL?(0,_tsRes.Ok)(new _pageUrl.PageUrl(a)):b===_types.TargetingType.PAGE_TITLE?(0,_tsRes.Ok)(new _pageTitle.PageTitle(a)):b===_types.TargetingType.CONVERSIONS?(0,_tsRes.Ok)(new _conversion.Conversion(a)):b===_types.TargetingType.VISITOR_CODE?(0,_tsRes.Ok)(new _visitorCode.VisitorCode(a)):b===_types.TargetingType.SDK_LANGUAGE?(0,_tsRes.Ok)(new _sdkLanguage.SdkLanguage(a)):b===_types.TargetingType.COOKIE?(0,_tsRes.Ok)(new _cookie.Cookie(a)):b===_types.TargetingType.OPERATING_SYSTEM?(0,_tsRes.Ok)(new _operatingSystem.OperatingSystem(a)):b===_types.TargetingType.GEOLOCATION?(0,_tsRes.Ok)(new _geolocation.GeolocationCondition(a)):b===_types.TargetingType.SEGMENT?(0,_tsRes.Ok)(new _segment.Segment(a)):b===_types.TargetingType.APPLICATION_VERSION?(0,_tsRes.Ok)(new _applicationVersion.ApplicationVersion(a)):b===_types.TargetingType.PREVIOUS_PAGE?(0,_tsRes.Ok)(new _previousPage.PreviousPage(a)):b===_types.TargetingType.PAGE_VIEWS?(0,_tsRes.Ok)(new _visitedPages.VisitedPages(a)):b===_types.TargetingType.LAST_VISIT?(0,_tsRes.Ok)(new _lastVisit.LastVisit(a)):b===_types.TargetingType.FIRST_VISIT?(0,_tsRes.Ok)(new _firstVisit.FirstVisit(a)):b===_types.TargetingType.SAME_DAY_VISITS?(0,_tsRes.Ok)(new _sameDayVisits.SameDayVisits(a)):b===_types.TargetingType.VISITS?(0,_tsRes.Ok)(new _visits.Visits(a)):b===_types.TargetingType.NEW_VISITORS?(0,_tsRes.Ok)(new _newVisitor.NewVisitor(a)):b===_types.TargetingType.HEAT_SLICE?(0,_tsRes.Ok)(new _conversionLikelihood.ConversionLikelihood(a)):(_logging.KameleoonLogger.error`Unsupported targeted condition type found: ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.TargetingCondition,b)))}}exports.ConditionFactory=ConditionFactory,_conditionFactoryInstance.ConditionFactoryInstance.setConditionFactoryInstance(new ConditionFactory);
|
|
@@ -157,7 +157,6 @@ export declare enum TargetingType {
|
|
|
157
157
|
TARGET_FEATURE_FLAG = "TARGET_FEATURE_FLAG",
|
|
158
158
|
TARGET_PERSONALIZATION = "TARGET_PERSONALIZATION",
|
|
159
159
|
EXCLUSIVE_EXPERIMENT = "EXCLUSIVE_EXPERIMENT",
|
|
160
|
-
EXCLUSIVE_FEATURE_FLAG = "EXCLUSIVE_FEATURE_FLAG",
|
|
161
160
|
CONVERSIONS = "CONVERSIONS",
|
|
162
161
|
CUSTOM_DATUM = "CUSTOM_DATUM",
|
|
163
162
|
YSANCE_SEGMENT = "YSANCE_SEGMENT",
|
package/dist/targeting/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorType=exports.VersionMatchType=exports.ValueMatchType=exports.TargetingType=exports.Operator=exports.NameMatchType=exports.MatchTypeVariation=exports.MatchTypeTest=exports.MatchType=exports.CampaignType=void 0;let Operator=exports.Operator=function(a){return a.And="AND",a.Or="OR",a}({}),ValueMatchType=exports.ValueMatchType=function(a){return a.TRUE="TRUE",a.FALSE="FALSE",a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.EQUAL="EQUAL",a.LOWER="LOWER",a.GREATER="GREATER",a.UNDEFINED="UNDEFINED",a.AMONG_VALUES="AMONG_VALUES",a.RANGE="RANGE",a}({}),VisitorType=exports.VisitorType=function(a){return a.NEW="NEW",a.RETURNING="RETURNING",a}({}),MatchTypeVariation=exports.MatchTypeVariation=function(a){return a.ANY="ANY",a.EXACT="EXACT",a}({}),MatchTypeTest=exports.MatchTypeTest=function(a){return a.ALL="ALL",a.TEST="TEST",a.PERSO="PERSO",a}({}),CampaignType=exports.CampaignType=function(a){return a.Experiment="EXPERIMENT",a.Personalization="PERSONALIZATION",a.Any="ANY",a}({}),MatchType=exports.MatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),VersionMatchType=exports.VersionMatchType=function(a){return a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),NameMatchType=exports.NameMatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.OPTIONAL="OPTIONAL",a}({}),TargetingType=exports.TargetingType=function(a){return a.PAGE_URL="PAGE_URL",a.PAGE_TITLE="PAGE_TITLE",a.LANDING_PAGE="LANDING_PAGE",a.ORIGIN="ORIGIN",a.ORIGIN_TYPE="ORIGIN_TYPE",a.REFERRERS="REFERRERS",a.NEW_VISITORS="NEW_VISITORS",a.INTERESTS="INTERESTS",a.BROWSER_LANGUAGE="BROWSER_LANGUAGE",a.GEOLOCATION="GEOLOCATION",a.DEVICE_TYPE="DEVICE_TYPE",a.SCREEN_DIMENSION="SCREEN_DIMENSION",a.VISITOR_IP="VISITOR_IP",a.AD_BLOCKER="AD_BLOCKER",a.PREVIOUS_PAGE="PREVIOUS_PAGE",a.KEY_PAGES="KEY_PAGES",a.PAGE_VIEWS="PAGE_VIEWS",a.FIRST_VISIT="FIRST_VISIT",a.LAST_VISIT="LAST_VISIT",a.ACTIVE_SESSION="ACTIVE_SESSION",a.TIME_SINCE_PAGE_LOAD="TIME_SINCE_PAGE_LOAD",a.SAME_DAY_VISITS="SAME_DAY_VISITS",a.VISITS="VISITS",a.VISITS_BY_PAGE="VISITS_BY_PAGE",a.VISITOR_CODE="VISITOR_CODE",a.SDK_LANGUAGE="SDK_LANGUAGE",a.INTERNAL_SEARCH_KEYWORDS="INTERNAL_SEARCH_KEYWORDS",a.TABS_ON_SITE="TABS_ON_SITE",a.CONVERSION_PROBABILITY="CONVERSION_PROBABILITY",a.HEAT_SLICE="HEAT_SLICE",a.SKY_STATUS="SKY_STATUS",a.TEMPERATURE="TEMPERATURE",a.DAY_NIGHT="DAY_NIGHT",a.FORECAST_SKY_STATUS="FORECAST_SKY_STATUS",a.FORECAST_TEMPERATURE="FORECAST_TEMPERATURE",a.DAY_OF_WEEK="DAY_OF_WEEK",a.TIME_RANGE="TIME_RANGE",a.HOUR_MINUTE_RANGE="HOUR_MINUTE_RANGE",a.JS_CODE="JS_CODE",a.COOKIE="COOKIE",a.EVENT="EVENT",a.BROWSER="BROWSER",a.OPERATING_SYSTEM="OPERATING_SYSTEM",a.DOM_ELEMENT="DOM_ELEMENT",a.MOUSE_OUT="MOUSE_OUT",a.TARGET_EXPERIMENT="TARGET_EXPERIMENT",a.TARGET_FEATURE_FLAG="TARGET_FEATURE_FLAG",a.TARGET_PERSONALIZATION="TARGET_PERSONALIZATION",a.EXCLUSIVE_EXPERIMENT="EXCLUSIVE_EXPERIMENT",a.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorType=exports.VersionMatchType=exports.ValueMatchType=exports.TargetingType=exports.Operator=exports.NameMatchType=exports.MatchTypeVariation=exports.MatchTypeTest=exports.MatchType=exports.CampaignType=void 0;let Operator=exports.Operator=function(a){return a.And="AND",a.Or="OR",a}({}),ValueMatchType=exports.ValueMatchType=function(a){return a.TRUE="TRUE",a.FALSE="FALSE",a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.EQUAL="EQUAL",a.LOWER="LOWER",a.GREATER="GREATER",a.UNDEFINED="UNDEFINED",a.AMONG_VALUES="AMONG_VALUES",a.RANGE="RANGE",a}({}),VisitorType=exports.VisitorType=function(a){return a.NEW="NEW",a.RETURNING="RETURNING",a}({}),MatchTypeVariation=exports.MatchTypeVariation=function(a){return a.ANY="ANY",a.EXACT="EXACT",a}({}),MatchTypeTest=exports.MatchTypeTest=function(a){return a.ALL="ALL",a.TEST="TEST",a.PERSO="PERSO",a}({}),CampaignType=exports.CampaignType=function(a){return a.Experiment="EXPERIMENT",a.Personalization="PERSONALIZATION",a.Any="ANY",a}({}),MatchType=exports.MatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),VersionMatchType=exports.VersionMatchType=function(a){return a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),NameMatchType=exports.NameMatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.OPTIONAL="OPTIONAL",a}({}),TargetingType=exports.TargetingType=function(a){return a.PAGE_URL="PAGE_URL",a.PAGE_TITLE="PAGE_TITLE",a.LANDING_PAGE="LANDING_PAGE",a.ORIGIN="ORIGIN",a.ORIGIN_TYPE="ORIGIN_TYPE",a.REFERRERS="REFERRERS",a.NEW_VISITORS="NEW_VISITORS",a.INTERESTS="INTERESTS",a.BROWSER_LANGUAGE="BROWSER_LANGUAGE",a.GEOLOCATION="GEOLOCATION",a.DEVICE_TYPE="DEVICE_TYPE",a.SCREEN_DIMENSION="SCREEN_DIMENSION",a.VISITOR_IP="VISITOR_IP",a.AD_BLOCKER="AD_BLOCKER",a.PREVIOUS_PAGE="PREVIOUS_PAGE",a.KEY_PAGES="KEY_PAGES",a.PAGE_VIEWS="PAGE_VIEWS",a.FIRST_VISIT="FIRST_VISIT",a.LAST_VISIT="LAST_VISIT",a.ACTIVE_SESSION="ACTIVE_SESSION",a.TIME_SINCE_PAGE_LOAD="TIME_SINCE_PAGE_LOAD",a.SAME_DAY_VISITS="SAME_DAY_VISITS",a.VISITS="VISITS",a.VISITS_BY_PAGE="VISITS_BY_PAGE",a.VISITOR_CODE="VISITOR_CODE",a.SDK_LANGUAGE="SDK_LANGUAGE",a.INTERNAL_SEARCH_KEYWORDS="INTERNAL_SEARCH_KEYWORDS",a.TABS_ON_SITE="TABS_ON_SITE",a.CONVERSION_PROBABILITY="CONVERSION_PROBABILITY",a.HEAT_SLICE="HEAT_SLICE",a.SKY_STATUS="SKY_STATUS",a.TEMPERATURE="TEMPERATURE",a.DAY_NIGHT="DAY_NIGHT",a.FORECAST_SKY_STATUS="FORECAST_SKY_STATUS",a.FORECAST_TEMPERATURE="FORECAST_TEMPERATURE",a.DAY_OF_WEEK="DAY_OF_WEEK",a.TIME_RANGE="TIME_RANGE",a.HOUR_MINUTE_RANGE="HOUR_MINUTE_RANGE",a.JS_CODE="JS_CODE",a.COOKIE="COOKIE",a.EVENT="EVENT",a.BROWSER="BROWSER",a.OPERATING_SYSTEM="OPERATING_SYSTEM",a.DOM_ELEMENT="DOM_ELEMENT",a.MOUSE_OUT="MOUSE_OUT",a.TARGET_EXPERIMENT="TARGET_EXPERIMENT",a.TARGET_FEATURE_FLAG="TARGET_FEATURE_FLAG",a.TARGET_PERSONALIZATION="TARGET_PERSONALIZATION",a.EXCLUSIVE_EXPERIMENT="EXCLUSIVE_EXPERIMENT",a.CONVERSIONS="CONVERSIONS",a.CUSTOM_DATUM="CUSTOM_DATUM",a.YSANCE_SEGMENT="YSANCE_SEGMENT",a.SEGMENT="SEGMENT",a.YSANCE_ATTRIBUT="YSANCE_ATTRIBUT",a.TEALIUM_BADGE="TEALIUM_BADGE",a.TEALIUM_AUDIENCE="TEALIUM_AUDIENCE",a.PRICE_OF_DISPLAYED_PAGE="PRICE_OF_DISPLAYED_PAGE",a.NUMBER_OF_VISITED_PAGES="NUMBER_OF_VISITED_PAGES",a.VISITED_PAGES="VISITED_PAGES",a.CUSTOM="CUSTOM",a.EXPLICIT_TRIGGER="EXPLICIT_TRIGGER",a.APPLICATION_VERSION="APPLICATION_VERSION",a}({});
|
package/dist/tracking/tracker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tracker=void 0;var _kameleoonData=require("../kameleoonData"),_types=require("../types"),_bodyProvider=require("./bodyProvider"),_logging=require("../logging");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tracker=void 0;var _kameleoonData=require("../kameleoonData"),_types=require("../types"),_bodyProvider=require("./bodyProvider"),_logging=require("../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Tracker{constructor(a){let{dataManager:b,trackingStorage:c,variationConfiguration:d,trackingInterval:e,requester:f,prng:g}=a;_defineProperty(this,"dataManager",void 0),_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"bodyProvider",void 0),_defineProperty(this,"intervalId",null),_defineProperty(this,"trackingStorage",void 0),_logging.KameleoonLogger.debug`CALL: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${e}, requester, prng)`,this.dataManager=b,this.trackingStorage=c,this.variationConfiguration=d,this.requester=f,this.bodyProvider=new _bodyProvider.BodyProvider(g);try{this.intervalId=setInterval(()=>{this.sendData()},e)}catch(a){throw this.intervalId&&clearInterval(this.intervalId),a}_logging.KameleoonLogger.debug`RETURN: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${e}, requester, prng)`}scheduleVisitor(a,b){_logging.KameleoonLogger.debug`CALL: Tracker.scheduleVisitor(visitorCode: ${a}, isConsentProvided: ${b})`,this.trackingStorage.read().and(c=>{c.scheduledVisitors[`_${a}`]={isConsentProvided:b},this.trackingStorage.write(c)}),_logging.KameleoonLogger.debug`RETURN: Tracker.scheduleVisitor(visitorCode: ${a}, isConsentProvided: ${b})`}checkIsIdentifier(a){var b,c;const d=this.dataManager.isUniqueIdentifier(a),e=null!==(b=null===(c=this.dataManager.getMappingIdentifier(a))||void 0===c?void 0:c.mappingIdentifier)&&void 0!==b?b:a;let f=!1;if(d){const b=this.dataManager.getLinkedVisitor(a),c=this.dataManager.identifierCustomDataIndex;b||"number"!=typeof c?f=!0:this.dataManager.storeData(a,new _kameleoonData.CustomData(c,a))}return f&&a!=e}getUserAgent(a){const b=this.dataManager.getVisitorData(a);if(b){const a=b[_kameleoonData.KameleoonData.UserAgent];if(a)return a.value}}async sendData(){const a={},b=this.trackingStorage.read();if(!b.ok)return;const{scheduledVisitors:c}=b.data,d=[];let e=!1,f={};for(const[b,{isConsentProvided:g}]of Object.entries(c)){if(e){f[b]={isConsentProvided:g};continue}let c=b.startsWith("_")?b.substring(1):b;const h=this.checkIsIdentifier(c),i=this.getUserAgent(c),j=this.getUnsentVisitorData(c,g),k=this.getUnsentVariationData(c,g),l=this.bodyProvider.addData({visitorCode:c,variationData:k,visitorData:j,userAgent:i,isConsentProvided:g,isMappingIdentifier:h});l.ok?(a[c]={visitorData:j,variationData:k},d.push({visitorCode:c,isConsentProvided:g})):(e=!0,f[b]={isConsentProvided:g},_logging.KameleoonLogger.warning("Visitor data to be tracked exceeded the request size limit. Some visitor data is kept to be sent later. If it is not caused by the peak load, decreasing the tracking interval is recommended."))}const{body:g,hasUserAgent:h}=this.bodyProvider.getTrackingBody();if(g){this.trackingStorage.write({scheduledVisitors:f});const b=await this.requester.track(g,h);if(b.ok)_logging.KameleoonLogger.info`Successful request for tracking visitors: ${d}, data: ${a}`,this.updateDataStatus(a,_types.TrackingStatus.Sent);else{_logging.KameleoonLogger.error("Tracking request failed"),_logging.KameleoonLogger.info`Failed request for tracking visitors: ${d}, data: ${a}`,this.updateDataStatus(a,_types.TrackingStatus.Unsent);let b={};for(let{visitorCode:a,isConsentProvided:c}of d)a=`_${a}`,b[a]={isConsentProvided:c};this.addNotTrackedVisitors(b)}}}addNotTrackedVisitors(a){const b=this.trackingStorage.read();if(!b.ok)return;const{scheduledVisitors:c}=b.data;Object.entries(a).forEach(a=>{let[b,{isConsentProvided:d}]=a;c[b]||(c[b]={isConsentProvided:d})}),this.trackingStorage.write({scheduledVisitors:c})}updateDataStatus(a,b){let c={};for(const[d,{visitorData:e,variationData:f}]of Object.entries(a)){c[d]=e.map(a=>(a.status=b,a));const a=f.map(a=>a.experimentId+"");this.variationConfiguration.updateDataStatus({visitorCode:d,experimentIdList:a,status:b})}b===_types.TrackingStatus.Sent?this.dataManager.storeTrackedData(c):this.dataManager.storeData(c)}getUnsentVisitorData(a,b){const c=this.dataManager.getUnsentData(a),d=[];if(!c.length)return[];for(const e of c)e.url&&(e.data.type===_kameleoonData.KameleoonData.Conversion||b)&&d.push(e);if(d.length){const b=d.map(a=>(a.status=_types.TrackingStatus.Pending,a));this.dataManager.storeTrackedData({[a]:b})}return d}getUnsentVariationData(a,b){const c=this.variationConfiguration.getUnsentData(a),d=new Set;if(!c.length)return[];const e=c.filter(a=>{const c=a.isTargetedRule||b;return c&&d.add(a.experimentId+""),c});return this.variationConfiguration.updateDataStatus({visitorCode:a,experimentIdList:Array.from(d),status:_types.TrackingStatus.Pending}),e}}exports.Tracker=Tracker;
|