@kameleoon/javascript-sdk-core
Advanced tools
Comparing version 5.1.3 to 5.2.0
# Change Log | ||
## 5.1.3 | ||
## 5.2.0 (2024-12-09) | ||
### Features | ||
- Added support for **simulated** variations. | ||
- Added the [`setForcedVariation()`][setForcedVariation] method. This method allows explicitly setting a forced variation for a visitor, which will be applied during experiment evaluation. | ||
### Patch Changes | ||
- Resolved an issue where the validation of [cookie domains][cookieDomain] for `localhost` resulted in incorrect failures. The SDK now accepts the provided domain without modification if it is deemed invalid and logs an [error][logLevels] to notify you of any issues with the specified domain. | ||
[setForcedVariation]: https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#setforcedvariation | ||
[cookieDomain]: https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#configuration-parameters | ||
[logLevels]: https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk#log-levels | ||
## 5.1.3 (2024-12-06) | ||
### Patch Changes | ||
- Fixed the issue with `off` variation not being added to `getEngineTrackingCode` result | ||
@@ -8,0 +23,0 @@ |
import { Result } from 'ts-res'; | ||
import { KameleoonError } from '../kameleoonError/kameleoonError'; | ||
import { SegmentType } from '../targeting'; | ||
import { ClientConfigurationParametersType, ConfigurationType, FeatureFlagType, MappedRuleType } from './types'; | ||
import { ClientConfigurationParametersType, ConfigurationType, ExperimentInfoType, FeatureFlagType, MappedRuleType } from './types'; | ||
interface IClientConfiguration { | ||
@@ -11,2 +11,3 @@ initialize: () => Promise<Result<void, KameleoonError>>; | ||
readonly ruleMap: Map<number, MappedRuleType>; | ||
readonly experimentMap: Map<number, ExperimentInfoType>; | ||
} | ||
@@ -26,2 +27,3 @@ export declare class ClientConfiguration implements IClientConfiguration { | ||
private mappedRules; | ||
private mappedExperiments; | ||
private dataManager; | ||
@@ -40,2 +42,3 @@ private visitorCodeManager; | ||
get ruleMap(): Map<number, MappedRuleType>; | ||
get experimentMap(): Map<number, ExperimentInfoType>; | ||
get isConsentRequired(): boolean; | ||
@@ -42,0 +45,0 @@ get hasAnyTargetedDeliveryRule(): boolean; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_types=require("./types"),_eventManager=require("../eventManager"),_constants=require("./constants"),_logging=require("../logging");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}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 ClientConfiguration{constructor(a){let{updateInterval:b,urlProvider:c,storage:d,requester:e,dataManager:f,eventSource:g,externalVisitorCodeManager:h,eventManager:i}=a;_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Polling),_defineProperty(this,"configurationData",_constants.DEFAULT_CLIENT_CONFIGURATION),_defineProperty(this,"featureFlagsData",new Map),_defineProperty(this,"isTargetedDeliveryRule",null),_defineProperty(this,"segmentsData",null),_defineProperty(this,"updateInterval",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"mappedRules",null),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),_defineProperty(this,"urlProvider",void 0),this.urlProvider=c,this.requester=e,this.updateInterval=b,this.lastUpdate=new Date,this.storage=d,this.dataManager=f,this.eventManager=i,this.visitorCodeManager=h,this.eventSource=g}async initialize(){_logging.KameleoonLogger.debug("CALL: ClientConfiguration.initialize()"),this.readStorageData();const a=this.checkShouldUpdate();if(a){const a=await this.updateClientConfiguration();if(!a.ok)return _logging.KameleoonLogger.error("Error occurred during client configuration update"),a;const b=a.data;if(b)return _logging.KameleoonLogger.debug("RETURN: ClientConfiguration.initialize()"),(0,_tsRes.Ok)()}return this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),_logging.KameleoonLogger.debug("RETURN: ClientConfiguration.initialize()"),(0,_tsRes.Ok)()):(_logging.KameleoonLogger.info("Configuration update type was toggled to Polling"),this.handleRealTimeUpdates(),_logging.KameleoonLogger.debug("RETURN: ClientConfiguration.initialize()"),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(b=>{b.ok&&this.eventManager.fireEvent(_eventManager.EventType.ConfigurationUpdate,{timestamp:a})})};this.eventSource.open(a),this.eventSource.onError(a=>{_logging.KameleoonLogger.error`Error occurred during real-time update: ${a}. Switching to polling updates while the connection is not restored.`,this.updateType=_types.UpdateType.Polling,this.handlePollingUpdates()})}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}get featureFlags(){return this.featureFlagsData}get configuration(){return this.configurationData.configuration}get segments(){if(this.segmentsData)return this.segmentsData;const a=new Map;return this.featureFlagsData.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),this.segmentsData=a,a}get ruleMap(){var a;if(null!==(a=this.mappedRules)&&void 0!==a&&a.size)return this.mappedRules;const b=new Map;for(const a of this.featureFlags.values())for(const c of a.rules){const{id:d,experimentId:e,variationByExposition:f}=c,g=new Map;f.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&g.set(b,c)}),b.set(d,{featureId:a.id,experimentId:e,variations:g})}return this.mappedRules=b,b}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){if(null!==this.isTargetedDeliveryRule)return this.isTargetedDeliveryRule;for(const a of this.featureFlags.values())if(a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))return!0;return!1}checkShouldUpdate(){const{configuration:a}=this.configurationData;if(this.updateType=a.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!this.featureFlags.size)return!0;const b=this.lastUpdate.getTime(),c=Date.now()-this.updateInterval;return b<c}readStorageData(){_logging.KameleoonLogger.debug("CALL: ClientConfiguration.readStorageData()");const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data;this.urlProvider.dataApiDomain=b.configuration.dataApiDomain;const{featureFlags:d,customData:e}=b;null!==e&&void 0!==e&&e.length&&(this.dataManager.customDataIndexes=e);for(const a of d)this.featureFlagsData.set(a.featureKey,a);this.configurationData=b,this.lastUpdate=new Date(Date.parse(c))}_logging.KameleoonLogger.debug`RETURN: ClientConfiguration.readStorageData() -> (result: ${a.ok})`}async updateClientConfiguration(a){var b;const c=await this.requester.getClientConfiguration(a);if(!c.ok)return this.featureFlags.size?(_logging.KameleoonLogger.error("Error occurred while updating configuration. Existing configuration will be used as a fallback."),(0,_tsRes.Ok)(!0)):c;const{configuration:d,customData:e,featureFlags:f}=c.data;this.configurationData={configuration:d,customData:e};for(const b of f)this.featureFlagsData.set(b.featureKey,b);null!==e&&void 0!==e&&e.length&&(this.dataManager.customDataIndexes=e),this.dataManager.clearTrees(),null===(b=this.mappedRules)||void 0===b?void 0:b.clear(),this.isTargetedDeliveryRule=null,this.segmentsData=null;const g=this.updateStorageData();if(!g.ok)return g;const h=d.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,i=h!==this.updateType;i&&(this.updateType=h,_logging.KameleoonLogger.debug`Configuration update type was toggled to ${h}`,await this.initialize());const j=this.isConsentRequired&&!this.hasAnyTargetedDeliveryRule;return this.visitorCodeManager.consentRequired=j,(0,_tsRes.Ok)(i)}updateStorageData(){this.lastUpdate=new Date;const a=_objectSpread(_objectSpread({},this.configurationData),{},{featureFlags:Array.from(this.featureFlags.values())}),b={data:a,lastUpdate:this.lastUpdate.toString()};return this.urlProvider.dataApiDomain=this.configurationData.configuration.dataApiDomain,this.storage.write(b)}}exports.ClientConfiguration=ClientConfiguration; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_types=require("./types"),_eventManager=require("../eventManager"),_constants=require("./constants"),_logging=require("../logging");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}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 ClientConfiguration{constructor(a){let{updateInterval:b,urlProvider:c,storage:d,requester:e,dataManager:f,eventSource:g,externalVisitorCodeManager:h,eventManager:i}=a;_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Polling),_defineProperty(this,"configurationData",_constants.DEFAULT_CLIENT_CONFIGURATION),_defineProperty(this,"featureFlagsData",new Map),_defineProperty(this,"isTargetedDeliveryRule",null),_defineProperty(this,"segmentsData",null),_defineProperty(this,"updateInterval",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"mappedRules",null),_defineProperty(this,"mappedExperiments",null),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),_defineProperty(this,"urlProvider",void 0),this.urlProvider=c,this.requester=e,this.updateInterval=b,this.lastUpdate=new Date,this.storage=d,this.dataManager=f,this.eventManager=i,this.visitorCodeManager=h,this.eventSource=g}async initialize(){_logging.KameleoonLogger.debug("CALL: ClientConfiguration.initialize()"),this.readStorageData();const a=this.checkShouldUpdate();if(a){const a=await this.updateClientConfiguration();if(!a.ok)return _logging.KameleoonLogger.error("Error occurred during client configuration update"),a;const b=a.data;if(b)return _logging.KameleoonLogger.debug("RETURN: ClientConfiguration.initialize()"),(0,_tsRes.Ok)()}return this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),_logging.KameleoonLogger.debug("RETURN: ClientConfiguration.initialize()"),(0,_tsRes.Ok)()):(_logging.KameleoonLogger.info("Configuration update type was toggled to Polling"),this.handleRealTimeUpdates(),_logging.KameleoonLogger.debug("RETURN: ClientConfiguration.initialize()"),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(b=>{b.ok&&this.eventManager.fireEvent(_eventManager.EventType.ConfigurationUpdate,{timestamp:a})})};this.eventSource.open(a),this.eventSource.onError(a=>{_logging.KameleoonLogger.error`Error occurred during real-time update: ${a}. Switching to polling updates while the connection is not restored.`,this.updateType=_types.UpdateType.Polling,this.handlePollingUpdates()})}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}get featureFlags(){return this.featureFlagsData}get configuration(){return this.configurationData.configuration}get segments(){if(this.segmentsData)return this.segmentsData;const a=new Map;return this.featureFlagsData.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),this.segmentsData=a,a}get ruleMap(){var a;if(null!==(a=this.mappedRules)&&void 0!==a&&a.size)return this.mappedRules;const b=new Map;for(const a of this.featureFlags.values())for(const c of a.rules){const{id:d,experimentId:e,variationByExposition:f}=c,g=new Map;f.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&g.set(b,c)}),b.set(d,{featureId:a.id,experimentId:e,variations:g})}return this.mappedRules=b,b}get experimentMap(){var a;if(null!==(a=this.mappedExperiments)&&void 0!==a&&a.size)return this.mappedExperiments;const b=new Map;for(const a of this.featureFlags.values())for(const c of a.rules){const{experimentId:a,variationByExposition:d}=c,e=new Map;d.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&e.set(b,c)}),b.set(a,{type:c.type,variations:e})}return this.mappedExperiments=b,b}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){if(null!==this.isTargetedDeliveryRule)return this.isTargetedDeliveryRule;for(const a of this.featureFlags.values())if(a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))return!0;return!1}checkShouldUpdate(){const{configuration:a}=this.configurationData;if(this.updateType=a.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!this.featureFlags.size)return!0;const b=this.lastUpdate.getTime(),c=Date.now()-this.updateInterval;return b<c}readStorageData(){_logging.KameleoonLogger.debug("CALL: ClientConfiguration.readStorageData()");const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data;this.urlProvider.dataApiDomain=b.configuration.dataApiDomain;const{featureFlags:d,customData:e}=b;null!==e&&void 0!==e&&e.length&&(this.dataManager.customDataIndexes=e);for(const a of d)this.featureFlagsData.set(a.featureKey,a);this.configurationData=b,this.lastUpdate=new Date(Date.parse(c))}_logging.KameleoonLogger.debug`RETURN: ClientConfiguration.readStorageData() -> (result: ${a.ok})`}async updateClientConfiguration(a){var b,c;const d=await this.requester.getClientConfiguration(a);if(!d.ok)return this.featureFlags.size?(_logging.KameleoonLogger.error("Error occurred while updating configuration. Existing configuration will be used as a fallback."),(0,_tsRes.Ok)(!0)):d;const{configuration:e,customData:f,featureFlags:g}=d.data;this.configurationData={configuration:e,customData:f};for(const b of g)this.featureFlagsData.set(b.featureKey,b);null!==f&&void 0!==f&&f.length&&(this.dataManager.customDataIndexes=f),this.dataManager.clearTrees(),null===(b=this.mappedRules)||void 0===b?void 0:b.clear(),null===(c=this.experimentMap)||void 0===c?void 0:c.clear(),this.isTargetedDeliveryRule=null,this.segmentsData=null;const h=this.updateStorageData();if(!h.ok)return h;const i=e.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,j=i!==this.updateType;j&&(this.updateType=i,_logging.KameleoonLogger.debug`Configuration update type was toggled to ${i}`,await this.initialize());const k=this.isConsentRequired&&!this.hasAnyTargetedDeliveryRule;return this.visitorCodeManager.consentRequired=k,(0,_tsRes.Ok)(j)}updateStorageData(){this.lastUpdate=new Date;const a=_objectSpread(_objectSpread({},this.configurationData),{},{featureFlags:Array.from(this.featureFlags.values())}),b={data:a,lastUpdate:this.lastUpdate.toString()};return this.urlProvider.dataApiDomain=this.configurationData.configuration.dataApiDomain,this.storage.write(b)}}exports.ClientConfiguration=ClientConfiguration; |
@@ -88,2 +88,6 @@ import { IEventSource } from '../eventSource'; | ||
}; | ||
export type ExperimentInfoType = { | ||
type: RuleType; | ||
variations: Map<string, number>; | ||
}; | ||
export type VariationByExpositionType = { | ||
@@ -90,0 +94,0 @@ variationKey: string; |
@@ -14,5 +14,5 @@ export { Ok, Result, Err } from 'ts-res'; | ||
export { JSONType, ConfigurationDataType } from './clientConfiguration'; | ||
export { TrackingStatus, Environment, VariableType, InternalsType, FeatureFlagType, JSONVariableType, SDKCoreParameters, NumberVariableType, StringVariableType, BooleanVariableType, SDKConfigurationType, KameleoonVariableType, KameleoonVariationType, ExternalPackageInfoType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, IsFeatureFlagActiveParamsType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, SimulateRequestDataType, GetVariationParamsType, GetVariationsParamsType, VariationType, Milliseconds, } from './types'; | ||
export { TrackingStatus, Environment, VariableType, InternalsType, FeatureFlagType, JSONVariableType, SDKCoreParameters, NumberVariableType, StringVariableType, BooleanVariableType, SDKConfigurationType, KameleoonVariableType, KameleoonVariationType, ExternalPackageInfoType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, IsFeatureFlagActiveParamsType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, SimulateRequestDataType, GetVariationParamsType, GetVariationsParamsType, VariationType, Milliseconds, SetForcedVariationParametersType, } from './types'; | ||
export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, KameleoonData, UniqueIdentifier, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, } from './kameleoonData'; | ||
export { IExternalEventSource, EventSourceOpenParametersType, } from './eventSource'; | ||
export { Header, HeadersType, HttpMethod, IExternalRequester, RequestParametersType, RequestType, RetryCountType, KameleoonResponseType, SendRequestParametersType, NUMBER_OF_RETRIES, } from './requester'; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersion}}),Object.defineProperty(exports,"ApplicationVersionDataType",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersionDataType}}),Object.defineProperty(exports,"BooleanVariableType",{enumerable:!0,get:function(){return _types.BooleanVariableType}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function(){return _kameleoonData.Browser}}),Object.defineProperty(exports,"BrowserType",{enumerable:!0,get:function(){return _kameleoonData.BrowserType}}),Object.defineProperty(exports,"ConfigurationDataType",{enumerable:!0,get:function(){return _clientConfiguration.ConfigurationDataType}}),Object.defineProperty(exports,"ConfigurationUpdateEventDataType",{enumerable:!0,get:function(){return _eventManager.ConfigurationUpdateEventDataType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function(){return _kameleoonData.Conversion}}),Object.defineProperty(exports,"ConversionParametersType",{enumerable:!0,get:function(){return _kameleoonData.ConversionParametersType}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function(){return _kameleoonData.Cookie}}),Object.defineProperty(exports,"CookieType",{enumerable:!0,get:function(){return _kameleoonData.CookieType}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function(){return _kameleoonData.CustomData}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function(){return _kameleoonData.Device}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function(){return _kameleoonData.DeviceType}}),Object.defineProperty(exports,"Environment",{enumerable:!0,get:function(){return _types.Environment}}),Object.defineProperty(exports,"Err",{enumerable:!0,get:function(){return _tsRes.Err}}),Object.defineProperty(exports,"EvaluationEventDataType",{enumerable:!0,get:function(){return _eventManager.EvaluationEventDataType}}),Object.defineProperty(exports,"EventCallbackType",{enumerable:!0,get:function(){return _eventManager.EventCallbackType}}),Object.defineProperty(exports,"EventDataType",{enumerable:!0,get:function(){return _eventManager.EventDataType}}),Object.defineProperty(exports,"EventSourceOpenParametersType",{enumerable:!0,get:function(){return _eventSource.EventSourceOpenParametersType}}),Object.defineProperty(exports,"EventType",{enumerable:!0,get:function(){return _eventManager.EventType}}),Object.defineProperty(exports,"ExternalPackageInfoType",{enumerable:!0,get:function(){return _types.ExternalPackageInfoType}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureFlagVariableType",{enumerable:!0,get:function(){return _types.FeatureFlagVariableType}}),Object.defineProperty(exports,"FeatureFlagVariationsType",{enumerable:!0,get:function(){return _storage.FeatureFlagVariationsType}}),Object.defineProperty(exports,"FeatureVariableResultType",{enumerable:!0,get:function(){return _types.FeatureVariableResultType}}),Object.defineProperty(exports,"GeolocationData",{enumerable:!0,get:function(){return _kameleoonData.GeolocationData}}),Object.defineProperty(exports,"GeolocationInfoType",{enumerable:!0,get:function(){return _kameleoonData.GeolocationInfoType}}),Object.defineProperty(exports,"GetFeatureFlagVariableParamsType",{enumerable:!0,get:function(){return _types.GetFeatureFlagVariableParamsType}}),Object.defineProperty(exports,"GetVariationParamsType",{enumerable:!0,get:function(){return _types.GetVariationParamsType}}),Object.defineProperty(exports,"GetVariationsParamsType",{enumerable:!0,get:function(){return _types.GetVariationsParamsType}}),Object.defineProperty(exports,"GetVisitorWarehouseAudienceParamsType",{enumerable:!0,get:function(){return _types.GetVisitorWarehouseAudienceParamsType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function(){return _requester.Header}}),Object.defineProperty(exports,"HeadersType",{enumerable:!0,get:function(){return _requester.HeadersType}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return _requester.HttpMethod}}),Object.defineProperty(exports,"IExternalEventSource",{enumerable:!0,get:function(){return _eventSource.IExternalEventSource}}),Object.defineProperty(exports,"IExternalLogger",{enumerable:!0,get:function(){return _logging.IExternalLogger}}),Object.defineProperty(exports,"IExternalPRNG",{enumerable:!0,get:function(){return _utilities.IExternalPRNG}}),Object.defineProperty(exports,"IExternalRequester",{enumerable:!0,get:function(){return _requester.IExternalRequester}}),Object.defineProperty(exports,"IExternalStorage",{enumerable:!0,get:function(){return _storage.IExternalStorage}}),Object.defineProperty(exports,"IKameleoonCore",{enumerable:!0,get:function(){return _kameleoonClientInterface.IKameleoonClient}}),Object.defineProperty(exports,"IVisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.IVisitorCodeManager}}),Object.defineProperty(exports,"InternalSDKConfigurationType",{enumerable:!0,get:function(){return _types.InternalSDKConfigurationType}}),Object.defineProperty(exports,"InternalsType",{enumerable:!0,get:function(){return _types.InternalsType}}),Object.defineProperty(exports,"IsFeatureFlagActiveParamsType",{enumerable:!0,get:function(){return _types.IsFeatureFlagActiveParamsType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function(){return _clientConfiguration.JSONType}}),Object.defineProperty(exports,"JSONVariableType",{enumerable:!0,get:function(){return _types.JSONVariableType}}),Object.defineProperty(exports,"KameleoonCore",{enumerable:!0,get:function(){return _kameleoonClient.KameleoonClient}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function(){return _kameleoonData.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function(){return _kameleoonData.KameleoonDataType}}),Object.defineProperty(exports,"KameleoonError",{enumerable:!0,get:function(){return _kameleoonError.KameleoonError}}),Object.defineProperty(exports,"KameleoonException",{enumerable:!0,get:function(){return _kameleoonError.KameleoonException}}),Object.defineProperty(exports,"KameleoonLogger",{enumerable:!0,get:function(){return _logging.KameleoonLogger}}),Object.defineProperty(exports,"KameleoonResponseType",{enumerable:!0,get:function(){return _requester.KameleoonResponseType}}),Object.defineProperty(exports,"KameleoonStorageKey",{enumerable:!0,get:function(){return _storage.KameleoonStorageKey}}),Object.defineProperty(exports,"KameleoonUtils",{enumerable:!0,get:function(){return _kameleoonUtils.KameleoonUtils}}),Object.defineProperty(exports,"KameleoonVariableType",{enumerable:!0,get:function(){return _types.KameleoonVariableType}}),Object.defineProperty(exports,"KameleoonVariationType",{enumerable:!0,get:function(){return _types.KameleoonVariationType}}),Object.defineProperty(exports,"LogLevel",{enumerable:!0,get:function(){return _logging.LogLevel}}),Object.defineProperty(exports,"Milliseconds",{enumerable:!0,get:function(){return _types.Milliseconds}}),Object.defineProperty(exports,"NUMBER_OF_RETRIES",{enumerable:!0,get:function(){return _requester.NUMBER_OF_RETRIES}}),Object.defineProperty(exports,"NumberVariableType",{enumerable:!0,get:function(){return _types.NumberVariableType}}),Object.defineProperty(exports,"Ok",{enumerable:!0,get:function(){return _tsRes.Ok}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function(){return _kameleoonData.OperatingSystem}}),Object.defineProperty(exports,"OperatingSystemType",{enumerable:!0,get:function(){return _kameleoonData.OperatingSystemType}}),Object.defineProperty(exports,"PageView",{enumerable:!0,get:function(){return _kameleoonData.PageView}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function(){return _kameleoonData.PageViewParametersType}}),Object.defineProperty(exports,"Parser",{enumerable:!0,get:function(){return _parser.Parser}}),Object.defineProperty(exports,"RemoteVisitorDataParamsType",{enumerable:!0,get:function(){return _types.RemoteVisitorDataParamsType}}),Object.defineProperty(exports,"RequestParametersType",{enumerable:!0,get:function(){return _requester.RequestParametersType}}),Object.defineProperty(exports,"RequestType",{enumerable:!0,get:function(){return _requester.RequestType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function(){return _tsRes.Result}}),Object.defineProperty(exports,"RetryCountType",{enumerable:!0,get:function(){return _requester.RetryCountType}}),Object.defineProperty(exports,"SDKConfigurationType",{enumerable:!0,get:function(){return _types.SDKConfigurationType}}),Object.defineProperty(exports,"SDKCoreParameters",{enumerable:!0,get:function(){return _types.SDKCoreParameters}}),Object.defineProperty(exports,"SdkLanguageType",{enumerable:!0,get:function(){return _constants.SdkLanguageType}}),Object.defineProperty(exports,"SendRequestParametersType",{enumerable:!0,get:function(){return _requester.SendRequestParametersType}}),Object.defineProperty(exports,"SetDataCallbackParametersType",{enumerable:!0,get:function(){return _types.SetDataCallbackParametersType}}),Object.defineProperty(exports,"SimulateRequestDataType",{enumerable:!0,get:function(){return _types.SimulateRequestDataType}}),Object.defineProperty(exports,"StorageDataType",{enumerable:!0,get:function(){return _storage.StorageDataType}}),Object.defineProperty(exports,"StringVariableType",{enumerable:!0,get:function(){return _types.StringVariableType}}),Object.defineProperty(exports,"TrackConversionParamsType",{enumerable:!0,get:function(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackingStatus",{enumerable:!0,get:function(){return _types.TrackingStatus}}),Object.defineProperty(exports,"UniqueIdentifier",{enumerable:!0,get:function(){return _kameleoonData.UniqueIdentifier}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function(){return _visitorCodeManager.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"Validator",{enumerable:!0,get:function(){return _utilities.Validator}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function(){return _types.VariableType}}),Object.defineProperty(exports,"VariationType",{enumerable:!0,get:function(){return _types.VariationType}}),Object.defineProperty(exports,"VisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.VisitorCodeManager}}),Object.defineProperty(exports,"VisitorDataFiltersType",{enumerable:!0,get:function(){return _utilities.VisitorDataFiltersType}});var _tsRes=require("ts-res"),_kameleoonClient=require("./kameleoonClient"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonClientInterface=require("./kameleoonClientInterface"),_kameleoonError=require("./kameleoonError"),_utilities=require("./utilities"),_storage=require("./storage"),_eventManager=require("./eventManager"),_visitorCodeManager=require("./visitorCodeManager"),_logging=require("./logging"),_parser=require("./utilities/parser"),_constants=require("./constants"),_clientConfiguration=require("./clientConfiguration"),_types=require("./types"),_kameleoonData=require("./kameleoonData"),_eventSource=require("./eventSource"),_requester=require("./requester"); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersion}}),Object.defineProperty(exports,"ApplicationVersionDataType",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersionDataType}}),Object.defineProperty(exports,"BooleanVariableType",{enumerable:!0,get:function(){return _types.BooleanVariableType}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function(){return _kameleoonData.Browser}}),Object.defineProperty(exports,"BrowserType",{enumerable:!0,get:function(){return _kameleoonData.BrowserType}}),Object.defineProperty(exports,"ConfigurationDataType",{enumerable:!0,get:function(){return _clientConfiguration.ConfigurationDataType}}),Object.defineProperty(exports,"ConfigurationUpdateEventDataType",{enumerable:!0,get:function(){return _eventManager.ConfigurationUpdateEventDataType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function(){return _kameleoonData.Conversion}}),Object.defineProperty(exports,"ConversionParametersType",{enumerable:!0,get:function(){return _kameleoonData.ConversionParametersType}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function(){return _kameleoonData.Cookie}}),Object.defineProperty(exports,"CookieType",{enumerable:!0,get:function(){return _kameleoonData.CookieType}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function(){return _kameleoonData.CustomData}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function(){return _kameleoonData.Device}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function(){return _kameleoonData.DeviceType}}),Object.defineProperty(exports,"Environment",{enumerable:!0,get:function(){return _types.Environment}}),Object.defineProperty(exports,"Err",{enumerable:!0,get:function(){return _tsRes.Err}}),Object.defineProperty(exports,"EvaluationEventDataType",{enumerable:!0,get:function(){return _eventManager.EvaluationEventDataType}}),Object.defineProperty(exports,"EventCallbackType",{enumerable:!0,get:function(){return _eventManager.EventCallbackType}}),Object.defineProperty(exports,"EventDataType",{enumerable:!0,get:function(){return _eventManager.EventDataType}}),Object.defineProperty(exports,"EventSourceOpenParametersType",{enumerable:!0,get:function(){return _eventSource.EventSourceOpenParametersType}}),Object.defineProperty(exports,"EventType",{enumerable:!0,get:function(){return _eventManager.EventType}}),Object.defineProperty(exports,"ExternalPackageInfoType",{enumerable:!0,get:function(){return _types.ExternalPackageInfoType}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureFlagVariableType",{enumerable:!0,get:function(){return _types.FeatureFlagVariableType}}),Object.defineProperty(exports,"FeatureFlagVariationsType",{enumerable:!0,get:function(){return _storage.FeatureFlagVariationsType}}),Object.defineProperty(exports,"FeatureVariableResultType",{enumerable:!0,get:function(){return _types.FeatureVariableResultType}}),Object.defineProperty(exports,"GeolocationData",{enumerable:!0,get:function(){return _kameleoonData.GeolocationData}}),Object.defineProperty(exports,"GeolocationInfoType",{enumerable:!0,get:function(){return _kameleoonData.GeolocationInfoType}}),Object.defineProperty(exports,"GetFeatureFlagVariableParamsType",{enumerable:!0,get:function(){return _types.GetFeatureFlagVariableParamsType}}),Object.defineProperty(exports,"GetVariationParamsType",{enumerable:!0,get:function(){return _types.GetVariationParamsType}}),Object.defineProperty(exports,"GetVariationsParamsType",{enumerable:!0,get:function(){return _types.GetVariationsParamsType}}),Object.defineProperty(exports,"GetVisitorWarehouseAudienceParamsType",{enumerable:!0,get:function(){return _types.GetVisitorWarehouseAudienceParamsType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function(){return _requester.Header}}),Object.defineProperty(exports,"HeadersType",{enumerable:!0,get:function(){return _requester.HeadersType}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return _requester.HttpMethod}}),Object.defineProperty(exports,"IExternalEventSource",{enumerable:!0,get:function(){return _eventSource.IExternalEventSource}}),Object.defineProperty(exports,"IExternalLogger",{enumerable:!0,get:function(){return _logging.IExternalLogger}}),Object.defineProperty(exports,"IExternalPRNG",{enumerable:!0,get:function(){return _utilities.IExternalPRNG}}),Object.defineProperty(exports,"IExternalRequester",{enumerable:!0,get:function(){return _requester.IExternalRequester}}),Object.defineProperty(exports,"IExternalStorage",{enumerable:!0,get:function(){return _storage.IExternalStorage}}),Object.defineProperty(exports,"IKameleoonCore",{enumerable:!0,get:function(){return _kameleoonClientInterface.IKameleoonClient}}),Object.defineProperty(exports,"IVisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.IVisitorCodeManager}}),Object.defineProperty(exports,"InternalSDKConfigurationType",{enumerable:!0,get:function(){return _types.InternalSDKConfigurationType}}),Object.defineProperty(exports,"InternalsType",{enumerable:!0,get:function(){return _types.InternalsType}}),Object.defineProperty(exports,"IsFeatureFlagActiveParamsType",{enumerable:!0,get:function(){return _types.IsFeatureFlagActiveParamsType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function(){return _clientConfiguration.JSONType}}),Object.defineProperty(exports,"JSONVariableType",{enumerable:!0,get:function(){return _types.JSONVariableType}}),Object.defineProperty(exports,"KameleoonCore",{enumerable:!0,get:function(){return _kameleoonClient.KameleoonClient}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function(){return _kameleoonData.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function(){return _kameleoonData.KameleoonDataType}}),Object.defineProperty(exports,"KameleoonError",{enumerable:!0,get:function(){return _kameleoonError.KameleoonError}}),Object.defineProperty(exports,"KameleoonException",{enumerable:!0,get:function(){return _kameleoonError.KameleoonException}}),Object.defineProperty(exports,"KameleoonLogger",{enumerable:!0,get:function(){return _logging.KameleoonLogger}}),Object.defineProperty(exports,"KameleoonResponseType",{enumerable:!0,get:function(){return _requester.KameleoonResponseType}}),Object.defineProperty(exports,"KameleoonStorageKey",{enumerable:!0,get:function(){return _storage.KameleoonStorageKey}}),Object.defineProperty(exports,"KameleoonUtils",{enumerable:!0,get:function(){return _kameleoonUtils.KameleoonUtils}}),Object.defineProperty(exports,"KameleoonVariableType",{enumerable:!0,get:function(){return _types.KameleoonVariableType}}),Object.defineProperty(exports,"KameleoonVariationType",{enumerable:!0,get:function(){return _types.KameleoonVariationType}}),Object.defineProperty(exports,"LogLevel",{enumerable:!0,get:function(){return _logging.LogLevel}}),Object.defineProperty(exports,"Milliseconds",{enumerable:!0,get:function(){return _types.Milliseconds}}),Object.defineProperty(exports,"NUMBER_OF_RETRIES",{enumerable:!0,get:function(){return _requester.NUMBER_OF_RETRIES}}),Object.defineProperty(exports,"NumberVariableType",{enumerable:!0,get:function(){return _types.NumberVariableType}}),Object.defineProperty(exports,"Ok",{enumerable:!0,get:function(){return _tsRes.Ok}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function(){return _kameleoonData.OperatingSystem}}),Object.defineProperty(exports,"OperatingSystemType",{enumerable:!0,get:function(){return _kameleoonData.OperatingSystemType}}),Object.defineProperty(exports,"PageView",{enumerable:!0,get:function(){return _kameleoonData.PageView}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function(){return _kameleoonData.PageViewParametersType}}),Object.defineProperty(exports,"Parser",{enumerable:!0,get:function(){return _parser.Parser}}),Object.defineProperty(exports,"RemoteVisitorDataParamsType",{enumerable:!0,get:function(){return _types.RemoteVisitorDataParamsType}}),Object.defineProperty(exports,"RequestParametersType",{enumerable:!0,get:function(){return _requester.RequestParametersType}}),Object.defineProperty(exports,"RequestType",{enumerable:!0,get:function(){return _requester.RequestType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function(){return _tsRes.Result}}),Object.defineProperty(exports,"RetryCountType",{enumerable:!0,get:function(){return _requester.RetryCountType}}),Object.defineProperty(exports,"SDKConfigurationType",{enumerable:!0,get:function(){return _types.SDKConfigurationType}}),Object.defineProperty(exports,"SDKCoreParameters",{enumerable:!0,get:function(){return _types.SDKCoreParameters}}),Object.defineProperty(exports,"SdkLanguageType",{enumerable:!0,get:function(){return _constants.SdkLanguageType}}),Object.defineProperty(exports,"SendRequestParametersType",{enumerable:!0,get:function(){return _requester.SendRequestParametersType}}),Object.defineProperty(exports,"SetDataCallbackParametersType",{enumerable:!0,get:function(){return _types.SetDataCallbackParametersType}}),Object.defineProperty(exports,"SetForcedVariationParametersType",{enumerable:!0,get:function(){return _types.SetForcedVariationParametersType}}),Object.defineProperty(exports,"SimulateRequestDataType",{enumerable:!0,get:function(){return _types.SimulateRequestDataType}}),Object.defineProperty(exports,"StorageDataType",{enumerable:!0,get:function(){return _storage.StorageDataType}}),Object.defineProperty(exports,"StringVariableType",{enumerable:!0,get:function(){return _types.StringVariableType}}),Object.defineProperty(exports,"TrackConversionParamsType",{enumerable:!0,get:function(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackingStatus",{enumerable:!0,get:function(){return _types.TrackingStatus}}),Object.defineProperty(exports,"UniqueIdentifier",{enumerable:!0,get:function(){return _kameleoonData.UniqueIdentifier}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function(){return _visitorCodeManager.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"Validator",{enumerable:!0,get:function(){return _utilities.Validator}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function(){return _types.VariableType}}),Object.defineProperty(exports,"VariationType",{enumerable:!0,get:function(){return _types.VariationType}}),Object.defineProperty(exports,"VisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.VisitorCodeManager}}),Object.defineProperty(exports,"VisitorDataFiltersType",{enumerable:!0,get:function(){return _utilities.VisitorDataFiltersType}});var _tsRes=require("ts-res"),_kameleoonClient=require("./kameleoonClient"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonClientInterface=require("./kameleoonClientInterface"),_kameleoonError=require("./kameleoonError"),_utilities=require("./utilities"),_storage=require("./storage"),_eventManager=require("./eventManager"),_visitorCodeManager=require("./visitorCodeManager"),_logging=require("./logging"),_parser=require("./utilities/parser"),_constants=require("./constants"),_clientConfiguration=require("./clientConfiguration"),_types=require("./types"),_kameleoonData=require("./kameleoonData"),_eventSource=require("./eventSource"),_requester=require("./requester"); |
import { JSONType } from './clientConfiguration'; | ||
import { CustomData, KameleoonDataType } from './kameleoonData'; | ||
import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType, KameleoonVariationType, VariationType, GetVariationParamsType, GetVariationsParamsType, IsFeatureFlagActiveParamsType } from './types'; | ||
import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType, KameleoonVariationType, VariationType, GetVariationParamsType, GetVariationsParamsType, IsFeatureFlagActiveParamsType, SetForcedVariationParametersType } from './types'; | ||
import { IKameleoonClient } from './kameleoonClientInterface'; | ||
@@ -50,2 +50,3 @@ import { EventCallbackType, EventType } from './eventManager'; | ||
setLogLevel(level: LogLevel): void; | ||
setForcedVariation({ visitorCode, experimentId, variationKey, forceTargeting, }: SetForcedVariationParametersType): void; | ||
protected setUserConsent({ visitorCode, consent, setData, }: SetUserConsentParametersType): void; | ||
@@ -56,2 +57,3 @@ private _isConsentProvided; | ||
private _getFeatureVariation; | ||
private _setForcedVariation; | ||
} |
@@ -1,1 +0,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");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}=a;_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);const g=null===f||void 0===f?void 0:f.externals.externalLogger;g&&_logging.KameleoonLogger.setLogger(g),_logging.KameleoonLogger.debug`CALL: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e}, internalConfiguration: ${f})`;const{settings:h}=new _clientSettings.ClientSettings(c,e);this.environment=h.environment;const{externalStorage:i,externalEventSource:j,externalPackageInfo:k,externalVisitorCodeManager:l,externalRequester:m,externalPRNG:n}=f.externals,{useAbortController:o}=f.settings,p=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),q=new _storage.DataStorage(i,_storage.KameleoonStorageKey.ClientData),r=new _storage.DataStorage(i,_storage.KameleoonStorageKey.TargetingData),s=new _storage.DataStorage(i,_storage.KameleoonStorageKey.DataInfo),t=new _storage.DataStorage(i,_storage.KameleoonStorageKey.VariationData),u=new _storage.DataStorage(i,_storage.KameleoonStorageKey.ConsentData),v=new _storage.DataStorage(i,_storage.KameleoonStorageKey.TrackingData),w=new _kameleoonData.DataManager({dataStorage:r,infoStorage:s,cleanupInterval:h.cleanupInterval}),x=null!==(b=null===d||void 0===d?void 0:d.urlProvider)&&void 0!==b?b:new _requester.UrlProvider;x.initialize({domain:h.networkDomain,siteCode:h.siteCode,packageInfo:k,environment:h.environment});const y=new _requester.Requester({urlProvider:x,useAbortController:o,packageInfo:k,externalRequester:m,requestTimeout:h.requestTimeout,trackRetryDelay:h.trackRetryDelay}),z=new _eventSource.KameleoonEventSource({siteCode:h.siteCode,externalEventSource:j,urlProvider:x}),A=new _eventManager.EventManager,B=new _clientConfiguration.ClientConfiguration({urlProvider:x,storage:q,updateInterval:h.updateInterval,dataManager:w,eventManager:A,requester:y,eventSource:z,externalVisitorCodeManager:l}),C=new _variationConfiguration.VariationConfiguration(t,l),D=new _tracking.Tracker({dataManager:w,trackingStorage:v,variationConfiguration:C,requester:y,trackingInterval:h.trackingInterval,prng:n});this.tracker=D,this.variationConfiguration=C,this.requester=y,this.trackingCache=p,this.dataManager=w,this.clientConfiguration=B,this.externalPackageInfo=k,this.consentDataStorage=u,this.visitorCodeManager=l,this.eventManager=A,_logging.KameleoonLogger.debug`RETURN: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e}, internalConfiguration: ${f})`}async initialize(){_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){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(_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}=_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),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d}) -> (visitorData: ${i})`,i}trackConversion(a){let{visitorCode:b,goalId:c,revenue:d}=a;_logging.KameleoonLogger.info`CALL: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, revenue: ${d})`,this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:d})),this.flush(b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, revenue: ${d})`}flush(a){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(_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(_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);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;_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`;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;_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d})`;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){_logging.KameleoonLogger.info`CALL: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a})`;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){_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;_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){_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){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){_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;_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(_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){_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)}setUserConsent(a){let{visitorCode:b,consent:c,setData:d}=a;_logging.KameleoonLogger.info`CALL: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this.consentDataStorage.update({[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})`}_isConsentProvided(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._isConsentProvided(visitorCode: ${a})`;const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read(),d=!b||c.ok&&c.data[a];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){if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);const b=this.clientConfiguration.featureFlags,c=[],d=this.dataManager.getVisitorData(a),e=this.dataManager.getVisitorIdentifier(a);for(const f of b.values()){if(!f.environmentEnabled)continue;const b=this.variationConfiguration.getVariation({visitorCode:a,visitorIdentifier:e,targetingData:d,featureFlag:f,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:f.featureKey,variation:{key:b.variationKey,experimentId:b.experimentId,id:b.variationId}}),b.variationKey!==_constants.OFF_VARIATION_KEY&&c.push(b)}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a}) -> (activeVariations: ${c})`,c}_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.dataManager.getVisitorData(b),h=this.dataManager.getVisitorIdentifier(b),i=this.variationConfiguration.getVariation({visitorCode:b,visitorIdentifier:h,featureFlag:f,track:d,withAssignment:!0,targetingData:g,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:c,variation:{key:i.variationKey,experimentId:i.experimentId,id:i.variationId}});const{experimentId:j,variationId:k,variationKey:l}=i;let m=new Map,n=!1;try{const a=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:l});a.forEach(a=>{n||a.type!==_types.VariableType.JS&&a.type!==_types.VariableType.CSS||(n=!0);const b=_utilities.Parser.parseFeatureVariable(a).throw();m.set(a.key,b)})}catch(_){}j&&"number"==typeof k&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,hasJsCssVariables:n,visitorCode:b,experimentId:j,variationId:k}),d&&this.tracker.scheduleVisitor(b,this._isConsentProvided(b));return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${i})`,(0,_tsRes.Ok)({key:l,id:k,experimentId:j,variables:m})}}exports.KameleoonClient=KameleoonClient; | ||
"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");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}=a;_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);const g=null===f||void 0===f?void 0:f.externals.externalLogger;g&&_logging.KameleoonLogger.setLogger(g),_logging.KameleoonLogger.debug`CALL: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`;const{settings:h}=new _clientSettings.ClientSettings(c,e);this.environment=h.environment;const{externalStorage:i,externalEventSource:j,externalPackageInfo:k,externalVisitorCodeManager:l,externalRequester:m,externalPRNG:n}=f.externals,{useAbortController:o}=f.settings,p=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),q=new _storage.DataStorage(i,_storage.KameleoonStorageKey.ClientData),r=new _storage.DataStorage(i,_storage.KameleoonStorageKey.TargetingData),s=new _storage.DataStorage(i,_storage.KameleoonStorageKey.DataInfo),t=new _storage.DataStorage(i,_storage.KameleoonStorageKey.VariationData),u=new _storage.DataStorage(i,_storage.KameleoonStorageKey.ForcedExperimentVariation),v=new _storage.DataStorage(i,_storage.KameleoonStorageKey.ForcedFeatureVariation),w=new _storage.DataStorage(i,_storage.KameleoonStorageKey.ConsentData),x=new _storage.DataStorage(i,_storage.KameleoonStorageKey.TrackingData),y=new _kameleoonData.DataManager({dataStorage:r,infoStorage:s,cleanupInterval:h.cleanupInterval}),z=null!==(b=null===d||void 0===d?void 0:d.urlProvider)&&void 0!==b?b:new _requester.UrlProvider;z.initialize({domain:h.networkDomain,siteCode:h.siteCode,packageInfo:k,environment:h.environment});const A=new _requester.Requester({urlProvider:z,useAbortController:o,packageInfo:k,externalRequester:m,requestTimeout:h.requestTimeout,trackRetryDelay:h.trackRetryDelay}),B=new _eventSource.KameleoonEventSource({siteCode:h.siteCode,externalEventSource:j,urlProvider:z}),C=new _eventManager.EventManager,D=new _clientConfiguration.ClientConfiguration({urlProvider:z,storage:q,updateInterval:h.updateInterval,dataManager:y,eventManager:C,requester:A,eventSource:B,externalVisitorCodeManager:l}),E=new _variationConfiguration.VariationConfiguration(t,u,v,l,D),F=new _tracking.Tracker({dataManager:y,trackingStorage:x,variationConfiguration:E,requester:A,trackingInterval:h.trackingInterval,prng:n});this.tracker=F,this.variationConfiguration=E,this.requester=A,this.trackingCache=p,this.dataManager=y,this.clientConfiguration=D,this.externalPackageInfo=k,this.consentDataStorage=w,this.visitorCodeManager=l,this.eventManager=C,_logging.KameleoonLogger.debug`RETURN: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`}async initialize(){_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){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(_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}=_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),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d}) -> (visitorData: ${i})`,i}trackConversion(a){let{visitorCode:b,goalId:c,revenue:d}=a;_logging.KameleoonLogger.info`CALL: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, revenue: ${d})`,this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:d})),this.flush(b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, revenue: ${d})`}flush(a){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(_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(_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;_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;_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(_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){_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;_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){_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){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){_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;_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(_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){_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;_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;_logging.KameleoonLogger.info`CALL: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this.consentDataStorage.update({[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})`}_isConsentProvided(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._isConsentProvided(visitorCode: ${a})`;const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read(),d=!b||c.ok&&c.data[a];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=[],d=this.dataManager.getVisitorData(a),e=this.dataManager.getVisitorIdentifier(a);for(const f of b.values()){if(!f.environmentEnabled)continue;const b=this.variationConfiguration.getVariation({visitorCode:a,visitorIdentifier:e,targetingData:d,featureFlag:f,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:f.featureKey,variation:{key:b.variationKey,experimentId:b.experimentId,id:b.variationId}}),b.variationKey!==_constants.OFF_VARIATION_KEY&&c.push(b)}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a}) -> (activeVariations: ${c})`,c}_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));let g,h=!1,i=!1;const j=this.variationConfiguration.getForcedFeatureVariation(b,c);if(j.ok){const a=j.data;if(a){var k,l;_logging.KameleoonLogger.debug`Forced variation for visitor ${b} and feature ${c} is found: ${a}`,h=!0,i=!0;let d=f.defaultVariationKey;a.varByExp?d=a.varByExp.variationKey:a.rule&&a.rule.type===_clientConfiguration.RuleType.EXPERIMENTATION&&(d=_constants.OFF_VARIATION_KEY),g={variationKey:d,variationId:(null===(k=a.varByExp)||void 0===k?void 0:k.variationId)||null,experimentId:(null===(l=a.rule)||void 0===l?void 0:l.experimentId)||null,rule:a.rule||null}}}if(!g){const a=this.dataManager.getVisitorData(b),c=this.dataManager.getVisitorIdentifier(b);g=this.variationConfiguration.getVariation({visitorCode:b,visitorIdentifier:c,featureFlag:f,track:d,withAssignment:!0,targetingData:a,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw()}h||(i&&null!==g.experimentId&&null!==g.variationId&&this.variationConfiguration.updateStoredVariations(b,{[g.experimentId]:{variationId:g.variationId,isTargetedRule:g.rule.type===_clientConfiguration.RuleType.TARGETED_DELIVERY,status:d?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}}),this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:c,variation:{key:g.variationKey,experimentId:g.experimentId,id:g.variationId}}));const{experimentId:m,variationId:n,variationKey:o}=g;let p=new Map,q=!1;try{const a=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:o});a.forEach(a=>{q||a.type!==_types.VariableType.JS&&a.type!==_types.VariableType.CSS||(q=!0);const b=_utilities.Parser.parseFeatureVariable(a).throw();p.set(a.key,b)})}catch(_){}m&&"number"==typeof n&&!h&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,hasJsCssVariables:q,visitorCode:b,experimentId:m,variationId:n}),d&&!h&&this.tracker.scheduleVisitor(b,this._isConsentProvided(b));return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${g})`,(0,_tsRes.Ok)({key:o,id:n,experimentId:m,variables:p})}_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; |
import { JSONType } from './clientConfiguration'; | ||
import { EventCallbackType, EventType } from './eventManager'; | ||
import { CustomData, KameleoonDataType } from './kameleoonData'; | ||
import { FeatureFlagType, FeatureFlagVariableType, FeatureVariableResultType, GetFeatureFlagVariableParamsType, GetVariationParamsType, GetVariationsParamsType, GetVisitorWarehouseAudienceParamsType, IsFeatureFlagActiveParamsType, KameleoonVariationType, RemoteVisitorDataParamsType, TrackConversionParamsType, VariationType } from './types'; | ||
import { FeatureFlagType, FeatureFlagVariableType, FeatureVariableResultType, GetFeatureFlagVariableParamsType, GetVariationParamsType, GetVariationsParamsType, GetVisitorWarehouseAudienceParamsType, IsFeatureFlagActiveParamsType, KameleoonVariationType, RemoteVisitorDataParamsType, SetForcedVariationParametersType, TrackConversionParamsType, VariationType } from './types'; | ||
import { LogLevel } from './logging'; | ||
@@ -310,2 +310,20 @@ /** | ||
setLogLevel: (logLevel: LogLevel) => void; | ||
/** | ||
* @method setForcedVariation - Sets or resets a forced variation for a visitor in a specific experiment, so the experiment will | ||
* be evaluated to the variation for the visitor. | ||
* In order to reset the forced variation, set the `variationKey` parameter to `null`. If the forced | ||
* variation you want to reset does not exist, the method will have no effect. | ||
* | ||
* @param {SetForcedVariationParametersType} parameters an object with parameters of a type `SetForcedVariationParametersType`, see the type for details. | ||
* @returns {void} | ||
* @throws `KameleoonError` with one of the following `type` s: | ||
* - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded | ||
* - `KameleoonException.VisitorCodeEmpty` The visitor code is empty | ||
* - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call | ||
* - `KameleoonException.FeatureFlagExperimentNotFound` - The experiment id does not exist in the feature flag. | ||
* - `KameleoonException.FeatureFlagVariationNotFound` - The variation key does not belong to the experiment. | ||
* - `KameleoonException.StorageRead` - Couldn't read storage data | ||
* - `KameleoonException.StorageWrite` - Couldn't update storage data | ||
*/ | ||
setForcedVariation: ({ visitorCode, experimentId, variationKey, forceTargeting, }: SetForcedVariationParametersType) => void; | ||
} |
@@ -17,2 +17,3 @@ import { KameleoonStorageKey } from '../storage'; | ||
FeatureFlagVariationNotFound: (variationKey: string, visitorCode: string) => string; | ||
FeatureFlagExperimentNotFound: (experimentId: number, visitorCode: string) => string; | ||
VisitAmount: () => string; | ||
@@ -19,0 +20,0 @@ VisitorCodeMaxLength: () => string; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _types=require("./types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.ERROR_MESSAGES=void 0;const ERROR_MESSAGES=exports.ERROR_MESSAGES={[_types.KameleoonException.CookieParse]:a=>`Couldn't parse cookie string: ${a}`,[_types.KameleoonException.JSONParse]:a=>`Couldn't parse JSON variable: ${a}`,[_types.KameleoonException.NumberParse]:a=>`It's not possible to parse value ${a} to Number`,[_types.KameleoonException.VersionParse]:a=>`It's not possible to parse a version value ${a} to Number, version should be in format x.x`,[_types.KameleoonException.SemanticVersionParse]:a=>`It's not possible to parse a version value ${a} to Number, version should be in format x.x.x`,[_types.KameleoonException.Initialization]:()=>"It seems that the client wasn't properly initialized, make sure to run `initialize` method before invoking other methods",[_types.KameleoonException.Credentials]:()=>"KameleoonClient can not be created without credentials",[_types.KameleoonException.StorageInitialization]:()=>"There was an error while initializing React Native SDK storage, it seems that the storage library dependency wasn't installed",[_types.KameleoonException.EventSourceInitialization]:()=>"There was an error while initializing Real Time Update service, it seems that the event source library dependency wasn't installed",[_types.KameleoonException.FeatureFlagConfigurationNotFound]:a=>`No feature flag with key ${a} was found.`,[_types.KameleoonException.FeatureFlagEnvironmentDisabled]:(a,b)=>`Feature flag with key ${a} is disabled in ${b} environment.`,[_types.KameleoonException.FeatureFlagVariableNotFound]:(a,b)=>`No feature flag variable with key ${a} was found for ${b} visitorCode.`,[_types.KameleoonException.FeatureFlagVariationNotFound]:(a,b)=>`No feature flag variation with key ${a} was found for ${b} visitorCode.`,[_types.KameleoonException.VisitAmount]:()=>"Visit amount must be a number between 1 and 25",[_types.KameleoonException.VisitorCodeMaxLength]:()=>"Visitor code can not be more than 255 characters long",[_types.KameleoonException.VisitorCodeEmpty]:()=>"Visitor code can not be empty",[_types.KameleoonException.StorageWrite]:a=>`Couldn't update storage for kameleoonClient: ${a}`,[_types.KameleoonException.StorageRead]:a=>`No data found in storage under ${a} key`,[_types.KameleoonException.StorageEmpty]:()=>"No data found in storage",[_types.KameleoonException.StorageParse]:(a,b)=>`Couldn't parse ${b} storage data, the data may be corrupted. Error: ${a}`,[_types.KameleoonException.ClientConfiguration]:a=>`Couldn't retrieve client configuration from Kameleoon Api. Error: ${a}`,[_types.KameleoonException.TargetingCondition]:a=>`${a} targeting condition is not yet supported.`,[_types.KameleoonException.AmongValuesCheck]:(a,b)=>`Couldn't parse value "${b}": ${a}`,[_types.KameleoonException.RangeCheck]:a=>`Couldn't parse value "${a}" as a range, value should be in format [x: number, y: number]`,[_types.KameleoonException.RemoteData]:a=>`Couldn't retrieve data from Kameleoon server. Error: ${a}`,[_types.KameleoonException.MaximumRetriesReached]:a=>`Maximum retries reached, request failed. Reason: ${a}`}; | ||
"use strict";var _types=require("./types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.ERROR_MESSAGES=void 0;const ERROR_MESSAGES=exports.ERROR_MESSAGES={[_types.KameleoonException.CookieParse]:a=>`Couldn't parse cookie string: ${a}`,[_types.KameleoonException.JSONParse]:a=>`Couldn't parse JSON variable: ${a}`,[_types.KameleoonException.NumberParse]:a=>`It's not possible to parse value ${a} to Number`,[_types.KameleoonException.VersionParse]:a=>`It's not possible to parse a version value ${a} to Number, version should be in format x.x`,[_types.KameleoonException.SemanticVersionParse]:a=>`It's not possible to parse a version value ${a} to Number, version should be in format x.x.x`,[_types.KameleoonException.Initialization]:()=>"It seems that the client wasn't properly initialized, make sure to run `initialize` method before invoking other methods",[_types.KameleoonException.Credentials]:()=>"KameleoonClient can not be created without credentials",[_types.KameleoonException.StorageInitialization]:()=>"There was an error while initializing React Native SDK storage, it seems that the storage library dependency wasn't installed",[_types.KameleoonException.EventSourceInitialization]:()=>"There was an error while initializing Real Time Update service, it seems that the event source library dependency wasn't installed",[_types.KameleoonException.FeatureFlagConfigurationNotFound]:a=>`No feature flag with key ${a} was found.`,[_types.KameleoonException.FeatureFlagEnvironmentDisabled]:(a,b)=>`Feature flag with key ${a} is disabled in ${b} environment.`,[_types.KameleoonException.FeatureFlagVariableNotFound]:(a,b)=>`No feature flag variable with key ${a} was found for ${b} visitorCode.`,[_types.KameleoonException.FeatureFlagVariationNotFound]:(a,b)=>`No feature flag variation with key ${a} was found for ${b} visitorCode.`,[_types.KameleoonException.FeatureFlagExperimentNotFound]:(a,b)=>`No feature flag experiment with id ${a} was found for ${b} visitorCode.`,[_types.KameleoonException.VisitAmount]:()=>"Visit amount must be a number between 1 and 25",[_types.KameleoonException.VisitorCodeMaxLength]:()=>"Visitor code can not be more than 255 characters long",[_types.KameleoonException.VisitorCodeEmpty]:()=>"Visitor code can not be empty",[_types.KameleoonException.StorageWrite]:a=>`Couldn't update storage for kameleoonClient: ${a}`,[_types.KameleoonException.StorageRead]:a=>`No data found in storage under ${a} key`,[_types.KameleoonException.StorageEmpty]:()=>"No data found in storage",[_types.KameleoonException.StorageParse]:(a,b)=>`Couldn't parse ${b} storage data, the data may be corrupted. Error: ${a}`,[_types.KameleoonException.ClientConfiguration]:a=>`Couldn't retrieve client configuration from Kameleoon Api. Error: ${a}`,[_types.KameleoonException.TargetingCondition]:a=>`${a} targeting condition is not yet supported.`,[_types.KameleoonException.AmongValuesCheck]:(a,b)=>`Couldn't parse value "${b}": ${a}`,[_types.KameleoonException.RangeCheck]:a=>`Couldn't parse value "${a}" as a range, value should be in format [x: number, y: number]`,[_types.KameleoonException.RemoteData]:a=>`Couldn't retrieve data from Kameleoon server. Error: ${a}`,[_types.KameleoonException.MaximumRetriesReached]:a=>`Maximum retries reached, request failed. Reason: ${a}`}; |
@@ -18,2 +18,3 @@ import { KameleoonStorageKey } from '../storage'; | ||
constructor(type: KameleoonException.FeatureFlagVariationNotFound, variationKey: string, visitorCode: string); | ||
constructor(type: KameleoonException.FeatureFlagExperimentNotFound, experimentId: number, visitorCode: string); | ||
constructor(type: KameleoonException.CookieParse, message: string); | ||
@@ -20,0 +21,0 @@ constructor(type: KameleoonException.StorageWrite | KameleoonException.JSONParse | KameleoonException.RemoteData | KameleoonException.MaximumRetriesReached | KameleoonException.ClientConfiguration, err: unknown); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonError=void 0;var _constants=require("./constants"),_helpers=require("./helpers"),_types=require("./types");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 KameleoonError extends Error{constructor(a,b,c){super(`Error: ${a}`),_defineProperty(this,"errorType",void 0),this.name="KameleoonError",this.errorType=a;a===_types.KameleoonException.Initialization||a===_types.KameleoonException.Credentials||a===_types.KameleoonException.VisitorCodeMaxLength||a===_types.KameleoonException.VisitorCodeEmpty||a===_types.KameleoonException.StorageInitialization||a===_types.KameleoonException.VisitAmount||a===_types.KameleoonException.EventSourceInitialization||a===_types.KameleoonException.StorageEmpty?this.message=_constants.ERROR_MESSAGES[a]():a===_types.KameleoonException.CookieParse||a===_types.KameleoonException.FeatureFlagConfigurationNotFound||a===_types.KameleoonException.NumberParse||a===_types.KameleoonException.ClientConfiguration||a===_types.KameleoonException.MaximumRetriesReached||a===_types.KameleoonException.RemoteData||a===_types.KameleoonException.VersionParse||a===_types.KameleoonException.SemanticVersionParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.FeatureFlagVariationNotFound||a===_types.KameleoonException.FeatureFlagEnvironmentDisabled||a===_types.KameleoonException.FeatureFlagVariableNotFound?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.StorageWrite||a===_types.KameleoonException.JSONParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageRead?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageParse?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.TargetingCondition?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.AmongValuesCheck?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.RangeCheck?this.message=_constants.ERROR_MESSAGES[a](b):(0,_helpers.exhaustCheck)(a)}get type(){return this.errorType}}exports.KameleoonError=KameleoonError; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonError=void 0;var _constants=require("./constants"),_helpers=require("./helpers"),_types=require("./types");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 KameleoonError extends Error{constructor(a,b,c){super(`Error: ${a}`),_defineProperty(this,"errorType",void 0),this.name="KameleoonError",this.errorType=a;a===_types.KameleoonException.Initialization||a===_types.KameleoonException.Credentials||a===_types.KameleoonException.VisitorCodeMaxLength||a===_types.KameleoonException.VisitorCodeEmpty||a===_types.KameleoonException.StorageInitialization||a===_types.KameleoonException.VisitAmount||a===_types.KameleoonException.EventSourceInitialization||a===_types.KameleoonException.StorageEmpty?this.message=_constants.ERROR_MESSAGES[a]():a===_types.KameleoonException.CookieParse||a===_types.KameleoonException.FeatureFlagConfigurationNotFound||a===_types.KameleoonException.NumberParse||a===_types.KameleoonException.ClientConfiguration||a===_types.KameleoonException.MaximumRetriesReached||a===_types.KameleoonException.RemoteData||a===_types.KameleoonException.VersionParse||a===_types.KameleoonException.SemanticVersionParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.FeatureFlagExperimentNotFound?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.FeatureFlagVariationNotFound||a===_types.KameleoonException.FeatureFlagEnvironmentDisabled||a===_types.KameleoonException.FeatureFlagVariableNotFound?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.StorageWrite||a===_types.KameleoonException.JSONParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageRead?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageParse?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.TargetingCondition?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.AmongValuesCheck?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.RangeCheck?this.message=_constants.ERROR_MESSAGES[a](b):(0,_helpers.exhaustCheck)(a)}get type(){return this.errorType}}exports.KameleoonError=KameleoonError; |
@@ -11,2 +11,3 @@ /** | ||
FeatureFlagVariationNotFound = "FeatureFlagVariationNotFound", | ||
FeatureFlagExperimentNotFound = "FeatureFlagExperimentNotFound", | ||
FeatureFlagEnvironmentDisabled = "FeatureFlagEnvironmentDisabled", | ||
@@ -13,0 +14,0 @@ VisitAmount = "VisitAmount", |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonException=void 0;let KameleoonException=exports.KameleoonException=function(a){return a.Credentials="Credentials",a.EventSourceInitialization="EventSourceInitialization",a.FeatureFlagConfigurationNotFound="FeatureFlagConfigurationNotFound",a.FeatureFlagVariableNotFound="FeatureFlagVariableNotFound",a.FeatureFlagVariationNotFound="FeatureFlagVariationNotFound",a.FeatureFlagEnvironmentDisabled="FeatureFlagEnvironmentDisabled",a.VisitAmount="VisitAmount",a.VisitorCodeMaxLength="VisitorCodeMaxLength",a.VisitorCodeEmpty="VisitorCodeEmpty",a.StorageInitialization="StorageInitialization",a.StorageWrite="StorageWrite",a.StorageRead="StorageRead",a.StorageParse="StorageParse",a.StorageEmpty="StorageEmpty",a.ClientConfiguration="ClientConfiguration",a.TargetingCondition="TargetingCondition",a.AmongValuesCheck="AmongValuesCheck",a.RangeCheck="RangeCheck",a.Initialization="Initialization",a.JSONParse="JSONParse",a.NumberParse="NumberParse",a.VersionParse="VersionParse",a.CookieParse="CookieParse",a.SemanticVersionParse="SemanticVersionParse",a.RemoteData="RemoteData",a.MaximumRetriesReached="MaximumRetriesReached",a}({}); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonException=void 0;let KameleoonException=exports.KameleoonException=function(a){return a.Credentials="Credentials",a.EventSourceInitialization="EventSourceInitialization",a.FeatureFlagConfigurationNotFound="FeatureFlagConfigurationNotFound",a.FeatureFlagVariableNotFound="FeatureFlagVariableNotFound",a.FeatureFlagVariationNotFound="FeatureFlagVariationNotFound",a.FeatureFlagExperimentNotFound="FeatureFlagExperimentNotFound",a.FeatureFlagEnvironmentDisabled="FeatureFlagEnvironmentDisabled",a.VisitAmount="VisitAmount",a.VisitorCodeMaxLength="VisitorCodeMaxLength",a.VisitorCodeEmpty="VisitorCodeEmpty",a.StorageInitialization="StorageInitialization",a.StorageWrite="StorageWrite",a.StorageRead="StorageRead",a.StorageParse="StorageParse",a.StorageEmpty="StorageEmpty",a.ClientConfiguration="ClientConfiguration",a.TargetingCondition="TargetingCondition",a.AmongValuesCheck="AmongValuesCheck",a.RangeCheck="RangeCheck",a.Initialization="Initialization",a.JSONParse="JSONParse",a.NumberParse="NumberParse",a.VersionParse="VersionParse",a.CookieParse="CookieParse",a.SemanticVersionParse="SemanticVersionParse",a.RemoteData="RemoteData",a.MaximumRetriesReached="MaximumRetriesReached",a}({}); |
@@ -13,5 +13,8 @@ import { ClientDataType } from './types'; | ||
ConsentData = "kameleoonConsentData", | ||
DataInfo = "kameleoonDataInfo" | ||
DataInfo = "kameleoonDataInfo", | ||
KameleoonSimulationFFData = "kameleoonSimulationFFData", | ||
ForcedFeatureVariation = "forcedFeatureVariation", | ||
ForcedExperimentVariation = "forcedExperimentVariation" | ||
} | ||
export declare const DEFAULT_CLIENT_CONFIGURATION: ClientDataType; | ||
export declare const VISIT_DURATION: number; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VISIT_DURATION=exports.KameleoonStorageKey=exports.DEFAULT_CLIENT_CONFIGURATION=void 0;var _clientConfiguration=require("../clientConfiguration"),_types=require("../types");let KameleoonStorageKey=exports.KameleoonStorageKey=function(a){return a.ClientData="kameleoonClientData",a.TargetingData="kameleoonTargetingData",a.TrackingData="kameleoonTrackingData",a.VariationData="kameleoonVariationData",a.VisitorCode="kameleoonVisitorCode",a.ConsentData="kameleoonConsentData",a.DataInfo="kameleoonDataInfo",a}({});const DEFAULT_CLIENT_CONFIGURATION=exports.DEFAULT_CLIENT_CONFIGURATION={data:{customData:[],featureFlags:[],configuration:{realTimeUpdate:!1,consentType:_clientConfiguration.ConsentType.NotRequired,dataApiDomain:"data.kameleoon.io"}},lastUpdate:""},VISIT_DURATION=exports.VISIT_DURATION=29*_types.Milliseconds.Minute; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VISIT_DURATION=exports.KameleoonStorageKey=exports.DEFAULT_CLIENT_CONFIGURATION=void 0;var _clientConfiguration=require("../clientConfiguration"),_types=require("../types");let KameleoonStorageKey=exports.KameleoonStorageKey=function(a){return a.ClientData="kameleoonClientData",a.TargetingData="kameleoonTargetingData",a.TrackingData="kameleoonTrackingData",a.VariationData="kameleoonVariationData",a.VisitorCode="kameleoonVisitorCode",a.ConsentData="kameleoonConsentData",a.DataInfo="kameleoonDataInfo",a.KameleoonSimulationFFData="kameleoonSimulationFFData",a.ForcedFeatureVariation="forcedFeatureVariation",a.ForcedExperimentVariation="forcedExperimentVariation",a}({});const DEFAULT_CLIENT_CONFIGURATION=exports.DEFAULT_CLIENT_CONFIGURATION={data:{customData:[],featureFlags:[],configuration:{realTimeUpdate:!1,consentType:_clientConfiguration.ConsentType.NotRequired,dataApiDomain:"data.kameleoon.io"}},lastUpdate:""},VISIT_DURATION=exports.VISIT_DURATION=29*_types.Milliseconds.Minute; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IntegrityChecker=void 0;var _constants=require("./constants"),_kameleoonData=require("../kameleoonData"),_kameleoonError=require("../kameleoonError");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}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 IntegrityChecker{constructor(a){_defineProperty(this,"key",void 0),this.key=a}isDataValid(a){switch(this.key){case _constants.KameleoonStorageKey.ClientData:return this.checkClientDataIntegrity(a);case _constants.KameleoonStorageKey.TargetingData:return this.checkTargetingDataIntegrity(a);case _constants.KameleoonStorageKey.DataInfo:return this.checkDataInfoIntegrity(a);case _constants.KameleoonStorageKey.VariationData:return this.checkVariationDataIntegrity(a);case _constants.KameleoonStorageKey.TrackingData:return this.checkTrackingDataIntegrity(a);default:return!0}}getDefaultData(){switch(this.key){case _constants.KameleoonStorageKey.ClientData:return this.getDefaultClientData();case _constants.KameleoonStorageKey.DataInfo:return{unsentData:{},nextVisitTime:0};case _constants.KameleoonStorageKey.TrackingData:return{scheduledVisitors:{}};case _constants.KameleoonStorageKey.TargetingData:case _constants.KameleoonStorageKey.VariationData:case _constants.KameleoonStorageKey.ConsentData:return{};case _constants.KameleoonStorageKey.VisitorCode:return"";default:(0,_kameleoonError.exhaustCheck)(this.key)}}checkTrackingDataIntegrity(a){return this.hasFields(a,["scheduledVisitors"])}checkDataInfoIntegrity(a){return this.hasFields(a,["unsentData","nextVisitTime"])}checkVariationDataIntegrity(a){const b=Object.values(a);if(!b.length)return!0;const c=a=>!this.hasFields(a,["status"])||this.hasFields(a,["isSent"]);for(const d of b)for(const a of Object.values(d))if(c(a))return!1;return!0}checkClientDataIntegrity(a){return this.hasFields(a,Object.keys(_constants.DEFAULT_CLIENT_CONFIGURATION))}checkTargetingDataIntegrity(a){const b=Object.values(a);if(!b.length)return!0;for(const c of b){if("string"==typeof c)continue;const a=a=>!this.hasFields(a,["status"])||this.hasFields(a,["sent"])||this.hasFields(a,["timestampList"]);for(const[b,d]of Object.entries(c)){if(Array.isArray(d))return!1;switch(b){case _kameleoonData.KameleoonData.PageView:case _kameleoonData.KameleoonData.Conversion:case _kameleoonData.KameleoonData.CustomData:{const b=Object.values(d).some(b=>a(b));if(b)return!1;continue}default:if(a(d))return!1}}}return!0}getDefaultClientData(){return _objectSpread(_objectSpread({},_constants.DEFAULT_CLIENT_CONFIGURATION),{},{lastUpdate:new Date().toString()})}hasFields(a,b){const c=Object.keys(a);return!!(c.length&&b.length)&&b.every(a=>c.includes(a))}}exports.IntegrityChecker=IntegrityChecker; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.IntegrityChecker=void 0;var _constants=require("./constants"),_kameleoonData=require("../kameleoonData"),_kameleoonError=require("../kameleoonError");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}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 IntegrityChecker{constructor(a){_defineProperty(this,"key",void 0),this.key=a}isDataValid(a){switch(this.key){case _constants.KameleoonStorageKey.ClientData:return this.checkClientDataIntegrity(a);case _constants.KameleoonStorageKey.TargetingData:return this.checkTargetingDataIntegrity(a);case _constants.KameleoonStorageKey.DataInfo:return this.checkDataInfoIntegrity(a);case _constants.KameleoonStorageKey.VariationData:return this.checkVariationDataIntegrity(a);case _constants.KameleoonStorageKey.TrackingData:return this.checkTrackingDataIntegrity(a);default:return!0}}getDefaultData(){switch(this.key){case _constants.KameleoonStorageKey.ClientData:return this.getDefaultClientData();case _constants.KameleoonStorageKey.DataInfo:return{unsentData:{},nextVisitTime:0};case _constants.KameleoonStorageKey.TrackingData:return{scheduledVisitors:{}};case _constants.KameleoonStorageKey.TargetingData:case _constants.KameleoonStorageKey.VariationData:case _constants.KameleoonStorageKey.ConsentData:return{};case _constants.KameleoonStorageKey.VisitorCode:return"";case _constants.KameleoonStorageKey.KameleoonSimulationFFData:return"";case _constants.KameleoonStorageKey.ForcedExperimentVariation:return{};case _constants.KameleoonStorageKey.ForcedFeatureVariation:return{};default:(0,_kameleoonError.exhaustCheck)(this.key)}}checkTrackingDataIntegrity(a){return this.hasFields(a,["scheduledVisitors"])}checkDataInfoIntegrity(a){return this.hasFields(a,["unsentData","nextVisitTime"])}checkVariationDataIntegrity(a){const b=Object.values(a);if(!b.length)return!0;const c=a=>!this.hasFields(a,["status"])||this.hasFields(a,["isSent"]);for(const d of b)for(const a of Object.values(d))if(c(a))return!1;return!0}checkClientDataIntegrity(a){return this.hasFields(a,Object.keys(_constants.DEFAULT_CLIENT_CONFIGURATION))}checkTargetingDataIntegrity(a){const b=Object.values(a);if(!b.length)return!0;for(const c of b){if("string"==typeof c)continue;const a=a=>!this.hasFields(a,["status"])||this.hasFields(a,["sent"])||this.hasFields(a,["timestampList"]);for(const[b,d]of Object.entries(c)){if(Array.isArray(d))return!1;switch(b){case _kameleoonData.KameleoonData.PageView:case _kameleoonData.KameleoonData.Conversion:case _kameleoonData.KameleoonData.CustomData:{const b=Object.values(d).some(b=>a(b));if(b)return!1;continue}default:if(a(d))return!1}}}return!0}getDefaultClientData(){return _objectSpread(_objectSpread({},_constants.DEFAULT_CLIENT_CONFIGURATION),{},{lastUpdate:new Date().toString()})}hasFields(a,b){const c=Object.keys(a);return!!(c.length&&b.length)&&b.every(a=>c.includes(a))}}exports.IntegrityChecker=IntegrityChecker; |
import { Result } from 'ts-res'; | ||
import { ConfigurationDataType } from '../clientConfiguration'; | ||
import { ConfigurationDataType, RuleType } from '../clientConfiguration'; | ||
import { KameleoonError } from '../kameleoonError'; | ||
@@ -29,2 +29,43 @@ import { KameleoonData } from '../kameleoonData'; | ||
}; | ||
export type ForcedFeatureVariationType = { | ||
featureKey: string; | ||
rule: ForcedVariationRuleType | null; | ||
varByExp: ForcedVariationVarByExpType | null; | ||
simulated: boolean; | ||
}; | ||
export type ForcedExperimentVariationType = { | ||
rule: ForcedVariationRuleType; | ||
varByExp: ForcedVariationVarByExpType; | ||
forceTargeting: boolean; | ||
}; | ||
export type ForcedVariationRuleType = { | ||
type: RuleType; | ||
experimentId: number; | ||
}; | ||
export type ForcedVariationVarByExpType = { | ||
variationKey: string; | ||
variationId: number; | ||
}; | ||
export type SimulatedVariationType = { | ||
featureKey: string; | ||
variationId: number | null; | ||
experimentId: number; | ||
}; | ||
export type ForcedExperimentVariationDataType = { | ||
[visitorCode: string]: { | ||
[experimentId: number]: ForcedExperimentVariationType; | ||
}; | ||
}; | ||
export type ForcedFeatureVariationDataType = { | ||
[simulated: number]: { | ||
[visitorCode: string]: { | ||
[featureKey: string]: ForcedFeatureVariationType; | ||
}; | ||
}; | ||
}; | ||
export type ForcedVariationDataType = { | ||
[visitorCode: string]: { | ||
[featureKey: string]: ForcedFeatureVariationType; | ||
}; | ||
}; | ||
export type ConsentDataType = { | ||
@@ -31,0 +72,0 @@ [visitorCode: string]: boolean; |
@@ -337,1 +337,16 @@ import { ClientConfigurationDataType, JSONType } from './clientConfiguration/types'; | ||
}; | ||
/** | ||
* @param {string} visitorCode - The unique visitor code identifying the visitor. | ||
* @param {number} experimentId - The identifier of the experiment you want to set/reset the forced variation for. | ||
* @param {string | null} variationKey - The identifier of the variation you want the experiment to be evaluated to. | ||
* Set to `null` to reset the forced variation. | ||
* @param {boolean} [forceTargeting=true] - If `true`, the visitor will be targeted to the experiment | ||
* regardless of its conditions. Otherwise, the normal targeting logic will be preserved. | ||
* Optional (defaults to `true`). | ||
*/ | ||
export type SetForcedVariationParametersType = { | ||
visitorCode: string; | ||
experimentId: number; | ||
variationKey: string | null; | ||
forceTargeting?: boolean; | ||
}; |
@@ -5,4 +5,5 @@ export declare const HEX_CHARACTERS = "0123456789ABCDEF"; | ||
export declare const HTTPS = "https://"; | ||
export declare const LOCALHOST = "localhost"; | ||
export declare const REGEX_DOMAIN: RegExp; | ||
export declare const HIDDEN_SECRET_CHAR = "*"; | ||
export declare const SECRET_VISIBLE_LENGTH = 4; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SECRET_VISIBLE_LENGTH=exports.REGEX_DOMAIN=exports.NONCE_LENGTH=exports.HTTPS=exports.HTTP=exports.HIDDEN_SECRET_CHAR=exports.HEX_CHARACTERS=void 0;const HEX_CHARACTERS=exports.HEX_CHARACTERS="0123456789ABCDEF",NONCE_LENGTH=exports.NONCE_LENGTH=16,HTTP=exports.HTTP="http://",HTTPS=exports.HTTPS="https://",REGEX_DOMAIN=exports.REGEX_DOMAIN=/^(\.?(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d]))(\.(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d])){1,126}$/,HIDDEN_SECRET_CHAR=exports.HIDDEN_SECRET_CHAR="*",SECRET_VISIBLE_LENGTH=exports.SECRET_VISIBLE_LENGTH=4; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SECRET_VISIBLE_LENGTH=exports.REGEX_DOMAIN=exports.NONCE_LENGTH=exports.LOCALHOST=exports.HTTPS=exports.HTTP=exports.HIDDEN_SECRET_CHAR=exports.HEX_CHARACTERS=void 0;const HEX_CHARACTERS=exports.HEX_CHARACTERS="0123456789ABCDEF",NONCE_LENGTH=exports.NONCE_LENGTH=16,HTTP=exports.HTTP="http://",HTTPS=exports.HTTPS="https://",LOCALHOST=exports.LOCALHOST="localhost",REGEX_DOMAIN=exports.REGEX_DOMAIN=/^(\.?(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d]))(\.(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d])){1,126}$/,HIDDEN_SECRET_CHAR=exports.HIDDEN_SECRET_CHAR="*",SECRET_VISIBLE_LENGTH=exports.SECRET_VISIBLE_LENGTH=4; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Validator=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_constants=require("./constants"),_logging=require("../logging");class Validator{static validateVersion(a){const b=a.split(".").map(a=>parseInt(a,10));for(;3>b.length;)b.push(0);return b.some(a=>isNaN(a))?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.SemanticVersionParse,a)):(0,_tsRes.Ok)(b.slice(0,3))}static validateDomain(a){if(!a)return(0,_tsRes.Err)();a=a.toLowerCase();const b=[_constants.HTTP,_constants.HTTPS];for(const c of b)if(a.startsWith(c)){a=a.substring(c.length),_logging.KameleoonLogger.warning`The top-level domain contains ${c}. Domain after protocol trimming: ${a}`;break}return _constants.REGEX_DOMAIN.test(a)?(0,_tsRes.Ok)(a):(_logging.KameleoonLogger.error`The top-level domain ${a} is invalid.`,(0,_tsRes.Err)())}}exports.Validator=Validator; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Validator=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_constants=require("./constants"),_logging=require("../logging");class Validator{static validateVersion(a){const b=a.split(".").map(a=>parseInt(a,10));for(;3>b.length;)b.push(0);return b.some(a=>isNaN(a))?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.SemanticVersionParse,a)):(0,_tsRes.Ok)(b.slice(0,3))}static validateDomain(a){if(!a)return(0,_tsRes.Err)();a=a.toLowerCase();const b=[_constants.HTTP,_constants.HTTPS];for(const c of b)if(a.startsWith(c)){a=a.substring(c.length),_logging.KameleoonLogger.warning`The top-level domain contains ${c}. Domain after protocol trimming: ${a}`;break}return _constants.REGEX_DOMAIN.test(a)||a===_constants.LOCALHOST?(0,_tsRes.Ok)(a):(_logging.KameleoonLogger.error`The top-level domain ${a} is invalid. The value has been set as provided, but it does not meet the required format for proper SDK functionality. Please check the domain for correctness.`,(0,_tsRes.Ok)(a))}}exports.Validator=Validator; |
@@ -35,1 +35,5 @@ import { ClientConfiguration, FeatureFlagType, RuleItemType } from '../clientConfiguration'; | ||
}; | ||
export type SimulatedVariationJson = { | ||
varId: number | null; | ||
expId: number; | ||
}; |
@@ -5,4 +5,5 @@ import { Result } from 'ts-res'; | ||
import { BaseVariationDataType, FeatureFlagVariationType, GetVariationParametersType, UpdateDataStatusParametersType } from './types'; | ||
import { FeatureFlagVariationsType, IStorage } from '../storage/types'; | ||
import { FeatureFlagVariationsType, ForcedExperimentVariationDataType, ForcedFeatureVariationDataType, ForcedFeatureVariationType, IStorage, ForcedExperimentVariationType } from '../storage/types'; | ||
import { IVisitorCodeManager } from '../visitorCodeManager'; | ||
import { ClientConfiguration } from '../clientConfiguration'; | ||
interface IVariationConfiguration { | ||
@@ -33,7 +34,30 @@ /** | ||
updateDataStatus: ({ visitorCode, experimentIdList, status, }: UpdateDataStatusParametersType) => void; | ||
/** | ||
* @method updateForcedExperimentVariation - updates the forced variation for the visitor | ||
*/ | ||
updateForcedExperimentVariation: (visitorCode: string, experimentId: number, forcedExperimentVariation: ForcedExperimentVariationType | null) => void; | ||
/** | ||
* @method updateForcedFeatureVariations - updates the simulated variations for the visitor | ||
*/ | ||
updateForcedFeatureVariations: (visitorCode: string, forcedFeatureVariations: ForcedFeatureVariationType[]) => void; | ||
/** | ||
* @method clearSimulatedVariations - clears the simulated feature variations for the visitor | ||
*/ | ||
clearSimulatedVariations: (visitorCode: string) => void; | ||
/** | ||
* @method getForcedFeatureVariation - obtains the forced feature variation for the visitor | ||
*/ | ||
getForcedFeatureVariation: (visitorCode: string, featureKey: string) => Result<ForcedFeatureVariationType | null, KameleoonError>; | ||
/** | ||
* @method getForcedExperimentVariation - obtains the forced experiment variation for the visitor | ||
*/ | ||
getForcedExperimentVariation: (visitorCode: string, experimentId: number) => Result<ForcedExperimentVariationType | null, KameleoonError>; | ||
} | ||
export declare class VariationConfiguration implements IVariationConfiguration { | ||
private storage; | ||
private storageForcedExperimentVariations; | ||
private storageForcedFeatureVariations; | ||
private visitorCodeManager; | ||
constructor(externalStorage: IStorage<VariationDataType>, visitorCodeManager: IVisitorCodeManager); | ||
private clientConfiguration; | ||
constructor(externalStorage: IStorage<VariationDataType>, externalStorageForcedExperimentVariations: IStorage<ForcedExperimentVariationDataType>, externalStorageForcedFeatureVariations: IStorage<ForcedFeatureVariationDataType>, visitorCodeManager: IVisitorCodeManager, clientConfiguration: ClientConfiguration); | ||
updateDataStatus({ visitorCode, experimentIdList, status, }: UpdateDataStatusParametersType): Result<void, KameleoonError>; | ||
@@ -44,5 +68,14 @@ getUnsentData(visitorCode: string): BaseVariationDataType[]; | ||
getVariation({ visitorCode, visitorIdentifier, featureFlag, targetingData, packageInfo, clientConfiguration, dataManager, track, withAssignment, }: GetVariationParametersType): Result<FeatureFlagVariationType, KameleoonError>; | ||
private createAndSaveForcedTargetedVariation; | ||
updateStoredVariations(visitorCode: string, variationData: FeatureFlagVariationsType): Result<void, KameleoonError>; | ||
private getVariationData; | ||
updateForcedExperimentVariation(visitorCode: string, experimentId: number, forcedExperimentVariation: ForcedExperimentVariationType | null): Result<void, KameleoonError>; | ||
updateForcedFeatureVariations(visitorCode: string, forcedFeatureVariations: ForcedFeatureVariationType[]): Result<void, KameleoonError>; | ||
clearSimulatedVariations(visitorCode: string): Result<void, KameleoonError>; | ||
getForcedFeatureVariation(visitorCode: string, featureKey: string): Result<ForcedFeatureVariationType | null, KameleoonError>; | ||
getForcedExperimentVariation(visitorCode: string, experimentId: number): Result<ForcedExperimentVariationType | null, KameleoonError>; | ||
private parseForcedVariationData; | ||
simulatedVariationFromJson(featureKey: string, data: any): ForcedFeatureVariationType | null; | ||
private isSimulatedVariationJson; | ||
} | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use strict";const _excluded=["exposition"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.VariationConfiguration=void 0;var _tsRes=require("ts-res"),_hasher=require("../hasher"),_kameleoonError=require("../kameleoonError"),_utilities=require("../utilities"),_types=require("../clientConfiguration/types"),_types2=require("../types"),_logging=require("../logging");function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],b.includes(c)||{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(b.includes(d))continue;c[d]=a[d]}return c}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}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 VariationConfiguration{constructor(a,b){_defineProperty(this,"storage",void 0),_defineProperty(this,"visitorCodeManager",void 0),this.storage=a,this.visitorCodeManager=b}updateDataStatus(a){let{visitorCode:b,experimentIdList:c,status:d}=a;const e=this.storage.read();if(!e.ok)return e;let f=e.data;f[b]||(f[b]={});for(const e of c)f[b][e]=_objectSpread(_objectSpread({},f[b][e]),{},{status:d});return this.storage.write(f)}getUnsentData(a){return this.getVariationData(a,a=>a===_types2.TrackingStatus.Unsent)}getPendingData(a){return this.getVariationData(a,a=>a===_types2.TrackingStatus.Pending)}getStoredVariations(a){const b=this.storage.read();if(!b.ok)return b;const c=b.data[a];return c?(0,_tsRes.Ok)(c):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.StorageRead,a))}getVariation(a){let{visitorCode:b,visitorIdentifier:c,featureFlag:d,targetingData:e,packageInfo:f,clientConfiguration:g,dataManager:h,track:i=!0,withAssignment:j=!1}=a;_logging.KameleoonLogger.debug`CALL: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j})`;const k=this.visitorCodeManager.validateVisitorCode(b);if(!k.ok)return(0,_tsRes.Err)(k.error);const{rules:l,featureKey:m,id:n,defaultVariationKey:o}=d;for(const k of l){const{segment:a,experimentId:l,id:p,exposition:q,respoolTime:r,variationByExposition:s}=k,t=_utilities.Utilities.checkTargeting({segment:a,visitorCode:b,experimentId:l,targetingData:e,packageInfo:f,clientConfiguration:g,dataManager:h,variationConfiguration:this});if(!t.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${t})`,t;if(!t.data)continue;_logging.KameleoonLogger.info`Visitor ${b} has been targeted for ${k}`;const u=_hasher.Hasher.getHashDouble({visitorIdentifier:c,respoolTime:r,id:p+""});if(_logging.KameleoonLogger.debug`Calculated ruleHash: ${u} for visitorCode: ${b}`,u<=q){let a=0;const g=_hasher.Hasher.getHashDouble({visitorIdentifier:c,respoolTime:r,id:l+""});_logging.KameleoonLogger.debug`Calculated variationHash: ${g} for visitorCode: ${b}`;for(const h of s)if(a+=h.exposition,g<=a){j&&this.updateStoredVariations(b,{[l]:{variationId:h.variationId,isTargetedRule:k.type===_types.RuleType.TARGETED_DELIVERY,status:i?_types2.TrackingStatus.Unsent:_types2.TrackingStatus.Sent}});const{exposition:a}=h,g=_objectWithoutProperties(h,_excluded),o=_objectSpread(_objectSpread({},g),{},{rule:k,featureFlagId:n,featureKey:m,experimentId:l,isTargetedRule:k.type===_types.RuleType.TARGETED_DELIVERY});return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${o})`,(0,_tsRes.Ok)(o)}}if(k.type===_types.RuleType.TARGETED_DELIVERY){const a={featureKey:m,featureFlagId:n,experimentId:null,variationKey:o,variationId:null,rule:null,isTargetedRule:!0};return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${a})`,(0,_tsRes.Ok)(a)}}const p={featureKey:m,featureFlagId:n,experimentId:null,variationKey:o,variationId:null,rule:null,isTargetedRule:!1};return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${p})`,(0,_tsRes.Ok)(p)}updateStoredVariations(a,b){const c=this.storage.read();if(!c.ok)return c;let d=c.data;for(const c in d[a]||(d[a]={}),b)d[a][c]=b[c];return this.storage.write(d)}getVariationData(a,b){const c=this.getStoredVariations(a);if(!c.ok)return[];const d=[];for(const[e,f]of Object.entries(c.data))b(f.status)&&d.push({experimentId:+e,variationId:f.variationId,isTargetedRule:f.isTargetedRule});return d}}exports.VariationConfiguration=VariationConfiguration; | ||
"use strict";const _excluded=["exposition"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.VariationConfiguration=void 0;var _tsRes=require("ts-res"),_hasher=require("../hasher"),_kameleoonError=require("../kameleoonError"),_utilities=require("../utilities"),_types=require("../clientConfiguration/types"),_types2=require("../types"),_logging=require("../logging");function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],b.includes(c)||{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(b.includes(d))continue;c[d]=a[d]}return c}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}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 VariationConfiguration{constructor(a,b,c,d,e){_defineProperty(this,"storage",void 0),_defineProperty(this,"storageForcedExperimentVariations",void 0),_defineProperty(this,"storageForcedFeatureVariations",void 0),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"clientConfiguration",void 0),this.storage=a,this.storageForcedExperimentVariations=b,this.storageForcedFeatureVariations=c,this.visitorCodeManager=d,this.clientConfiguration=e,d.setVariationConfiguration(this)}updateDataStatus(a){let{visitorCode:b,experimentIdList:c,status:d}=a;const e=this.storage.read();if(!e.ok)return e;let f=e.data;f[b]||(f[b]={});for(const e of c)f[b][e]=_objectSpread(_objectSpread({},f[b][e]),{},{status:d});return this.storage.write(f)}getUnsentData(a){return this.getVariationData(a,a=>a===_types2.TrackingStatus.Unsent)}getPendingData(a){return this.getVariationData(a,a=>a===_types2.TrackingStatus.Pending)}getStoredVariations(a){const b=this.storage.read();if(!b.ok)return b;const c=b.data[a];return c?(0,_tsRes.Ok)(c):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.StorageRead,a))}getVariation(a){let{visitorCode:b,visitorIdentifier:c,featureFlag:d,targetingData:e,packageInfo:f,clientConfiguration:g,dataManager:h,track:i=!0,withAssignment:j=!1}=a;_logging.KameleoonLogger.debug`CALL: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j})`;const{rules:k,featureKey:l,id:m,defaultVariationKey:n}=d;for(const o of k){const{segment:a,experimentId:k,id:p,exposition:q,respoolTime:r,variationByExposition:s}=o,t=this.getForcedExperimentVariation(b,o.experimentId);let u=null;if(t.ok&&(u=t.data,u&&u.forceTargeting)){_logging.KameleoonLogger.info`Visitor ${b} has been forced targeted for ${o}`;const a=this.createAndSaveForcedTargetedVariation(b,d,o,u,i,j);return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${a})`,(0,_tsRes.Ok)(a)}const v=_utilities.Utilities.checkTargeting({segment:a,visitorCode:b,experimentId:k,targetingData:e,packageInfo:f,clientConfiguration:g,dataManager:h,variationConfiguration:this});if(!v.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${v})`,v;if(!v.data)continue;if(_logging.KameleoonLogger.info`Visitor ${b} has been targeted for ${o}`,u){const a=this.createAndSaveForcedTargetedVariation(b,d,o,u,i,j);return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${a})`,(0,_tsRes.Ok)(a)}const w=_hasher.Hasher.getHashDouble({visitorIdentifier:c,respoolTime:r,id:p+""});if(_logging.KameleoonLogger.debug`Calculated ruleHash: ${w} for visitorCode: ${b}`,w<=q){let a=0;const g=_hasher.Hasher.getHashDouble({visitorIdentifier:c,respoolTime:r,id:k+""});_logging.KameleoonLogger.debug`Calculated variationHash: ${g} for visitorCode: ${b}`;for(const h of s)if(a+=h.exposition,g<=a){j&&this.updateStoredVariations(b,{[k]:{variationId:h.variationId,isTargetedRule:o.type===_types.RuleType.TARGETED_DELIVERY,status:i?_types2.TrackingStatus.Unsent:_types2.TrackingStatus.Sent}});const{exposition:a}=h,g=_objectWithoutProperties(h,_excluded),n=_objectSpread(_objectSpread({},g),{},{rule:o,featureFlagId:m,featureKey:l,experimentId:k,isTargetedRule:o.type===_types.RuleType.TARGETED_DELIVERY});return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${n})`,(0,_tsRes.Ok)(n)}}if(o.type===_types.RuleType.TARGETED_DELIVERY){const a={featureKey:l,featureFlagId:m,experimentId:null,variationKey:n,variationId:null,rule:null,isTargetedRule:!0};return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${a})`,(0,_tsRes.Ok)(a)}}const o={featureKey:l,featureFlagId:m,experimentId:null,variationKey:n,variationId:null,rule:null,isTargetedRule:!1};return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getVariation(visitorCode: ${b}, visitorIdentifier: ${c}, featureFlag: ${d}, targetingData: ${e}, packageInfo: ${f}, clientConfiguration, dataManager, withAssignment: ${j}) -> (targetedVariation: ${o})`,(0,_tsRes.Ok)(o)}createAndSaveForcedTargetedVariation(a,b,c,d,e,f){const g={variationKey:d.varByExp.variationKey,variationId:d.varByExp.variationId,rule:c,featureFlagId:b.id,featureKey:b.featureKey,experimentId:c.experimentId,isTargetedRule:c.type===_types.RuleType.TARGETED_DELIVERY};return f&&this.updateStoredVariations(a,{[c.experimentId]:{variationId:g.variationId,isTargetedRule:c.type===_types.RuleType.TARGETED_DELIVERY,status:e?_types2.TrackingStatus.Unsent:_types2.TrackingStatus.Sent}}),g}updateStoredVariations(a,b){_logging.KameleoonLogger.debug`CALL: VariationConfiguration.updateStoredVariations(visitorCode: ${a}, variationData: ${b})`;const c=this.storage.read();if(!c.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.updateStoredVariations(visitorCode: ${a}, variationData: ${b}) -> (result: ${c})`,c;let d=c.data;for(const c in d[a]||(d[a]={}),b)d[a][c]=b[c];const e=this.storage.write(d);return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.updateStoredVariations(visitorCode: ${a}, variationData: ${b}) -> (resultWrite: ${e})`,e}getVariationData(a,b){const c=this.getStoredVariations(a);if(!c.ok)return[];const d=[];for(const[e,f]of Object.entries(c.data))b(f.status)&&d.push({experimentId:+e,variationId:f.variationId,isTargetedRule:f.isTargetedRule});return d}updateForcedExperimentVariation(a,b,c){_logging.KameleoonLogger.debug`CALL: VariationConfiguration.updateForcedExperimentVariation(visitorCode: ${a}, experimentId: ${b}, forcedExperimentVariation: ${c})`;const d=this.storageForcedExperimentVariations.read();if(!d.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.updateForcedExperimentVariation(visitorCode: ${a}, experimentId: ${b}, forcedExperimentVariation: ${c}) -> (result: ${d})`,d;let e=d.data;e[a]??={},c?e[a][b]=c:delete e[a][b];const f=this.storageForcedExperimentVariations.write(e);return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.updateForcedExperimentVariation(visitorCode: ${a}, experimentId: ${b}, forcedExperimentVariation: ${c}) -> (resultWrite: ${f})`,f}updateForcedFeatureVariations(a,b){_logging.KameleoonLogger.debug`CALL: VariationConfiguration.updateForcedFeatureVariations(visitorCode: ${a}, forcedFeatureVariations: ${b})`;const c=this.storageForcedFeatureVariations.read();if(!c.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.updateForcedFeatureVariations(visitorCode: ${a}, forcedFeatureVariations: ${b}) -> (result: ${c})`,c;let d=c.data;d[0]??={},d[1]??={};const e=d[0],f=d[1];f[a]??={},e[a]??={},b.forEach(b=>{const c=b.simulated?f[a]:e[a];c[b.featureKey]=b});const g=this.storageForcedFeatureVariations.write(d);return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.updateForcedFeatureVariations(visitorCode: ${a}, forcedFeatureVariations: ${b}) -> (resultWrite: ${g})`,g}clearSimulatedVariations(a){var b;_logging.KameleoonLogger.debug`CALL: VariationConfiguration.clearSimulatedVariations(visitorCode: ${a})`;const c=this.storageForcedFeatureVariations.read();if(!c.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.clearSimulatedVariations(visitorCode: ${a}) -> (result: ${c})`,c;let d;const e=c.data;return null!==e&&void 0!==e&&null!==(b=e[1])&&void 0!==b&&b[a]?(delete e[1][a],d=this.storageForcedFeatureVariations.write(e)):d=(0,_tsRes.Ok)(),_logging.KameleoonLogger.debug`RETURN: VariationConfiguration.clearSimulatedVariations(visitorCode: ${a}) -> (resultWrite: ${d})`,d}getForcedFeatureVariation(a,b){var c,d,e,f;_logging.KameleoonLogger.debug`CALL: VariationConfiguration.getForcedFeatureVariation(visitorCode: ${a}, featureKey: ${b})`;const g=this.storageForcedFeatureVariations.read();if(!g.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getForcedFeatureVariation(visitorCode: ${a}, featureKey: ${b}) -> (simulatedResult: ${g})`,g;const h=null===(c=g.data[1])||void 0===c||null===(d=c[a])||void 0===d?void 0:d[b];if(h)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getForcedFeatureVariation(visitorCode: ${a}, featureKey: ${b}) -> (simulatedData: ${h})`,(0,_tsRes.Ok)(h);const i=null===(e=g.data[0])||void 0===e||null===(f=e[a])||void 0===f?void 0:f[b];return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getForcedFeatureVariation(visitorCode: ${a}, featureKey: ${b}) -> (forcedData: ${i})`,(0,_tsRes.Ok)(i)}getForcedExperimentVariation(a,b){var c;_logging.KameleoonLogger.debug`CALL: VariationConfiguration.getForcedExperimentVariation(visitorCode: ${a}, experimentId: ${b})`;const d=this.storageForcedExperimentVariations.read();if(!d.ok)return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getForcedExperimentVariation(visitorCode: ${a}, experimentId: ${b}) -> (forcedResult: ${d})`,d;const e=null===(c=d.data[a])||void 0===c?void 0:c[b];return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.getForcedExperimentVariation(visitorCode: ${a}, experimentId: ${b}) -> (forcedExperiment: ${e})`,(0,_tsRes.Ok)(e)}parseForcedVariationData(a){let b=!!(1<arguments.length&&void 0!==arguments[1])&&arguments[1];const c=this.clientConfiguration.featureFlags.get(a.featureKey);if(!c)return _logging.KameleoonLogger.error`Simulated feature flag '${a.featureKey}' not found`,null;let d=null;if(0===a.experimentId)return d={featureKey:a.featureKey,rule:null,varByExp:null,simulated:b},d;for(const e of c.rules){if(a.experimentId!==e.experimentId)continue;const c=e.variationByExposition.find(b=>b.variationId===a.variationId);if(c)return d={featureKey:a.featureKey,rule:{type:e.type,experimentId:e.experimentId},varByExp:{variationKey:c.variationKey,variationId:c.variationId},simulated:b},d}return _logging.KameleoonLogger.error`Simulated variation ${a.variationId} not found`,null}simulatedVariationFromJson(a,b){if(_logging.KameleoonLogger.debug`CALL: VariationConfiguration.simulatedVariationFromJson(featureKey: ${a}, data: ${b})`,!this.isSimulatedVariationJson(b))return null;const c=this.parseForcedVariationData({featureKey:a,variationId:b.varId,experimentId:b.expId},!0);return _logging.KameleoonLogger.debug`RETURN: VariationConfiguration.simulatedVariationFromJson(featureKey: ${a}, data: ${b}) -> (forcedVariation: ${c})`,c}isSimulatedVariationJson(a){return a&&("number"==typeof a.expId||null===a.expId)}}exports.VariationConfiguration=VariationConfiguration; |
import { Result } from 'ts-res'; | ||
import { KameleoonError } from '../kameleoonError'; | ||
import { SetDataCallbackParametersType } from '../types'; | ||
import { VariationConfiguration } from "../variationConfiguration"; | ||
export interface IVisitorCodeManager { | ||
consentRequired: boolean; | ||
setVariationConfiguration(variationConfiguration: VariationConfiguration): void; | ||
getVisitorCode(defaultVisitorCode?: string): string; | ||
@@ -7,0 +9,0 @@ getData: (key: string) => string | null; |
@@ -5,2 +5,3 @@ import { Result } from 'ts-res'; | ||
import { IVisitorCodeManager } from './types'; | ||
import { VariationConfiguration } from "../variationConfiguration"; | ||
/** | ||
@@ -11,2 +12,3 @@ * VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve, | ||
export declare class VisitorCodeManager implements IVisitorCodeManager { | ||
private variationConfiguration?; | ||
private isConsentRequired; | ||
@@ -17,3 +19,3 @@ private setDataCallback?; | ||
get consentRequired(): boolean; | ||
set getData(callback: () => string); | ||
set getData(callback: (key: string) => string); | ||
set setData(callback: (params: SetDataCallbackParametersType) => void); | ||
@@ -23,3 +25,6 @@ get setData(): (params: SetDataCallbackParametersType) => void; | ||
getVisitorCode(defaultVisitorCode?: string): string; | ||
private processSimulatedVariations; | ||
private getSimulatedVariations; | ||
private generateVisitorCode; | ||
setVariationConfiguration(variationConfiguration: VariationConfiguration): void; | ||
} |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorCodeManager=void 0;var _tsRes=require("ts-res"),_storage=require("../storage"),_kameleoonError=require("../kameleoonError"),_constants=require("./constants"),_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 VisitorCodeManager{constructor(){_defineProperty(this,"isConsentRequired",!1),_defineProperty(this,"setDataCallback",void 0),_defineProperty(this,"getDataCallback",void 0)}set consentRequired(a){this.isConsentRequired=a}get consentRequired(){return this.isConsentRequired}set getData(a){this.getDataCallback=a}set setData(a){this.setDataCallback=a}get setData(){if(this.setDataCallback)return this.setDataCallback;throw new Error("Missing setDataCallback!")}validateVisitorCode(a){return 0===a.length?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeEmpty)):a.length>_constants.VISITOR_CODE_MAX_LENGTH?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeMaxLength)):(0,_tsRes.Ok)()}getVisitorCode(a){if(_logging.KameleoonLogger.debug`CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${a})`,!this.getDataCallback||!this.setDataCallback)throw new Error("Missing getDataCallback or setDataCallback methods in getVisitorCode!");let b;const c=this.getDataCallback(_storage.KameleoonStorageKey.VisitorCode);return c&&(b=c),b||(a?(this.validateVisitorCode(a).throw(),b=a,_logging.KameleoonLogger.debug`Used default visitor code: ${b}`):(b=this.generateVisitorCode(),_logging.KameleoonLogger.debug`Generated new visitor code: ${b}`)),this.isConsentRequired||this.setDataCallback({visitorCode:b,key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_constants.DEFAULT_MAX_AGE,path:_constants.PATH}),_logging.KameleoonLogger.debug`RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${a}) -> (visitorCode: ${b})`,b}generateVisitorCode(){const a="abcdefghijklmnopqrstuvwxyz0123456789",b=[];for(let c=0;c<_constants.VISITOR_CODE_LENGTH;c++)b.push(a[Math.floor(Math.random()*a.length)]);return b.join("")}}exports.VisitorCodeManager=VisitorCodeManager; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorCodeManager=void 0;var _tsRes=require("ts-res"),_storage=require("../storage"),_kameleoonError=require("../kameleoonError"),_constants=require("./constants"),_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 VisitorCodeManager{constructor(){_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"isConsentRequired",!1),_defineProperty(this,"setDataCallback",void 0),_defineProperty(this,"getDataCallback",void 0)}set consentRequired(a){this.isConsentRequired=a}get consentRequired(){return this.isConsentRequired}set getData(a){this.getDataCallback=a}set setData(a){this.setDataCallback=a}get setData(){if(this.setDataCallback)return this.setDataCallback;throw new Error("Missing setDataCallback!")}validateVisitorCode(a){return 0===a.length?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeEmpty)):a.length>_constants.VISITOR_CODE_MAX_LENGTH?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeMaxLength)):(0,_tsRes.Ok)()}getVisitorCode(a){if(_logging.KameleoonLogger.debug`CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${a})`,!this.getDataCallback||!this.setDataCallback)throw new Error("Missing getDataCallback or setDataCallback methods in getVisitorCode!");let b;const c=this.getDataCallback(_storage.KameleoonStorageKey.VisitorCode);return c&&(b=c),b||(a?(this.validateVisitorCode(a).throw(),b=a,_logging.KameleoonLogger.debug`Used default visitor code: ${b}`):(b=this.generateVisitorCode(),_logging.KameleoonLogger.debug`Generated new visitor code: ${b}`)),this.processSimulatedVariations(b),this.isConsentRequired||this.setDataCallback({visitorCode:b,key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_constants.DEFAULT_MAX_AGE,path:_constants.PATH}),_logging.KameleoonLogger.debug`RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${a}) -> (visitorCode: ${b})`,b}processSimulatedVariations(a){if(this.variationConfiguration){const b=this.getSimulatedVariations(a);try{this.variationConfiguration.clearSimulatedVariations(a).throw(),null!==b&&0<b.length&&this.variationConfiguration.updateForcedFeatureVariations(a,b).throw()}catch(a){a instanceof Error&&_logging.KameleoonLogger.error`Failed to process simulated variations: ${a.message}`}}}getSimulatedVariations(a){_logging.KameleoonLogger.debug`CALL: VisitorCodeManager.getSimulatedVariations(visitorCode: ${a})`;const b=this.getDataCallback(_storage.KameleoonStorageKey.KameleoonSimulationFFData);let c=null;if("string"==typeof b&&0<b.length)try{const a=JSON.parse(decodeURIComponent(b));a&&"object"==typeof a&&(c=Object.entries(a).map(a=>{let[b,c]=a;return this.variationConfiguration.simulatedVariationFromJson(b,c)}).filter(a=>null!==a))}catch(a){a instanceof Error&&_logging.KameleoonLogger.error`Failed to parse simulated variations: ${a.message}`}return _logging.KameleoonLogger.debug`RETURN: VisitorCodeManager.getSimulatedVariations(visitorCode: ${a}) -> (variations: ${c})`,c}generateVisitorCode(){const a="abcdefghijklmnopqrstuvwxyz0123456789",b=[];for(let c=0;c<_constants.VISITOR_CODE_LENGTH;c++)b.push(a[Math.floor(Math.random()*a.length)]);return b.join("")}setVariationConfiguration(a){this.variationConfiguration||(this.variationConfiguration=a)}}exports.VisitorCodeManager=VisitorCodeManager; |
{ | ||
"name": "@kameleoon/javascript-sdk-core", | ||
"version": "5.1.3", | ||
"version": "5.2.0", | ||
"description": "Kameleoon JS SDK Core", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
444065
3728