Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kameleoon/javascript-sdk-core

Package Overview
Dependencies
Maintainers
0
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kameleoon/javascript-sdk-core - npm Package Compare versions

Comparing version 4.4.3 to 4.4.4

6

CHANGELOG.md
# Change Log
## 4.4.4 (2024-07-19)
### Patch Changes
- Fix previous release, which didn't contain all the described changes
## 4.4.3 (2024-07-19)

@@ -4,0 +10,0 @@

6

dist/index.d.ts

@@ -6,4 +6,4 @@ export { Ok, Result, Err } from 'ts-res';

export { KameleoonException, KameleoonError } from './kameleoonError';
export { VisitorDataFiltersType } from './utilities';
export { FeatureFlagVariationsType, KameleoonStorageKey, StorageDataType, IExternalStorage, } from './storage';
export { VisitorDataFiltersType, IExternalPRNG } from './utilities';
export { FeatureFlagVariationsType, KameleoonStorageKey, IExternalStorage, StorageDataType, } from './storage';
export { EventCallbackType, EventDataType, EventType, EvaluationEventDataType, ConfigurationUpdateEventDataType, } from './eventManager';

@@ -13,5 +13,5 @@ export { VisitorCodeManager, IVisitorCodeManager } from './visitorCodeManager';

export { JSONType, ConfigurationDataType } from './clientConfiguration';
export { Environment, VariableType, FeatureFlagType, SDKCoreParameters, SDKConfigurationType, KameleoonVariationType, ExternalPackageInfoType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, SimulateRequestDataType, Milliseconds, } from './types';
export { Environment, VariableType, InternalsType, FeatureFlagType, SDKCoreParameters, SDKConfigurationType, KameleoonVariationType, ExternalPackageInfoType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, SimulateRequestDataType, Milliseconds, } from './types';
export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, KameleoonData, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, } from './kameleoonData';
export { IExternalEventSource, EventSourceOpenParametersType, } from './eventSource';
export { Header, HeadersType, HttpMethod, TrackParametersType, IExternalRequester, RequestParametersType, RequestType, RetryCountType, KameleoonResponseType, SendRequestParametersType, NUMBER_OF_RETRIES, } from './requester';

@@ -1,2 +0,2 @@

"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,"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,"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,"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,"JSONType",{enumerable:!0,get:function(){return _clientConfiguration.JSONType}}),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,"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,"KameleoonVariationType",{enumerable:!0,get:function(){return _types.KameleoonVariationType}}),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,"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,"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,"TrackConversionParamsType",{enumerable:!0,get:function(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackParametersType",{enumerable:!0,get:function(){return _requester.TrackParametersType}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function(){return _constants.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function(){return _types.VariableType}}),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"),_kameleoonClientInterface=require("./kameleoonClientInterface"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonError=require("./kameleoonError"),_utilities=require("./utilities"),_storage=require("./storage"),_eventManager=require("./eventManager"),_visitorCodeManager=require("./visitorCodeManager"),_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,"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,"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,"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,"JSONType",{enumerable:!0,get:function(){return _clientConfiguration.JSONType}}),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,"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,"KameleoonVariationType",{enumerable:!0,get:function(){return _types.KameleoonVariationType}}),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,"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,"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,"TrackConversionParamsType",{enumerable:!0,get:function(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackParametersType",{enumerable:!0,get:function(){return _requester.TrackParametersType}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function(){return _constants.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function(){return _types.VariableType}}),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"),_kameleoonClientInterface=require("./kameleoonClientInterface"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonError=require("./kameleoonError"),_utilities=require("./utilities"),_storage=require("./storage"),_eventManager=require("./eventManager"),_visitorCodeManager=require("./visitorCodeManager"),_constants=require("./constants"),_clientConfiguration=require("./clientConfiguration"),_types=require("./types"),_kameleoonData=require("./kameleoonData"),_eventSource=require("./eventSource"),_requester=require("./requester");
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

"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"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_eventManager=require("./eventManager"),_eventSource=require("./eventSource"),_visitorCodeManager=require("./visitorCodeManager");function _defineProperty(a,b,c){return b=_toPropertyKey(b),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){let{siteCode:b,configuration:c,internalConfiguration:d}=a;_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"clientConfiguration",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"offlineTrackingStorage",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,"environment",void 0),_defineProperty(this,"isOfflineModeOn",void 0);const{settings:e}=new _clientSettings.ClientSettings(b,c);this.environment=e.environment;const{externalStorage:f,externalEventSource:g,externalPackageInfo:h,externalVisitorCodeManager:i,externalRequester:j,externalClientConfiguration:k}=d,l=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),m=new _storage.DataStorage(f,_storage.KameleoonStorageKey.ClientData),n=new _storage.DataStorage(f,_storage.KameleoonStorageKey.TargetingData),o=new _storage.DataStorage(f,_storage.KameleoonStorageKey.VariationData),p=new _storage.DataStorage(f,_storage.KameleoonStorageKey.OfflineTracking),q=new _storage.DataStorage(f,_storage.KameleoonStorageKey.ConsentData),r=new _kameleoonData.DataManager({storage:n,cleanupInterval:e.cleanupInterval}),s=new _requester.Requester({siteCode:b,domain:e.networkDomain,environment:e.environment,packageInfo:h,externalRequester:j,requestTimeout:e.requestTimeout,trackRetryDelay:e.trackRetryDelay}),t=new _eventSource.KameleoonEventSource(e.siteCode,g),u=new _eventManager.EventManager,v=new _clientConfiguration.ClientConfiguration({storage:m,updateInterval:e.updateInterval,dataManager:r,eventManager:u,requester:s,externalClientConfiguration:k,offlineTrackingStorage:p,eventSource:t,externalVisitorCodeManager:i}),w=new _variationConfiguration.VariationConfiguration(o);this.variationConfiguration=w,this.requester=s,this.trackingCache=l,this.dataManager=r,this.clientConfiguration=v,this.externalPackageInfo=h,this.offlineTrackingStorage=p,this.consentDataStorage=q,this.visitorCodeManager=i,this.eventManager=u}async initialize(a){const b=await this.clientConfiguration.initialize();return b.throw(),this.isOfflineModeOn=a,this.initialized=!0,b.ok}addData(a){if(_utilities.Utilities.validateVisitorCode(a).throw(),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];this.dataManager.addData(a,...c).throw()}async getRemoteVisitorData(a){let{visitorCode:b,shouldAddData:c=!0,filters:d=_constants.DEFAULT_VISITOR_DATA_FILTERS,isUniqueIdentifier:e=!1}=a;if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_utilities.Utilities.validateVisitorCode(b).throw();const{previousVisitAmount:f}=d;if("number"==typeof f&&(1>f||25<f))throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitAmount);const g=await this.requester.getVisitorData({visitorCode:b,filters:d,isMappingIdentifier:e}),h=g.throw(),{visitorData:i,storageVisitorData:j,visitsData:k}=_utilities.Utilities.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),i}trackConversion(a){let{visitorCode:b,goalId:c,revenue:d,isUniqueIdentifier:e}=a;this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:d})),this.flush(b,e)}flush(a,b){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a&&_utilities.Utilities.validateVisitorCode(a).throw(),a){let c=!1;if(b){const b=this.dataManager.getLinkedVisitor(a),d=this.dataManager.identifierCustomDataIndex;b||"number"!=typeof d?c=!0:this.dataManager.addData(a,new _kameleoonData.CustomData(d,a))}return void _utilities.Utilities.trackData({visitorCode:a,isMappingIdentifier:c,dataManager:this.dataManager,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,isConsentProvided:this._isConsentProvided(a),offlineTrackingStorage:this.offlineTrackingStorage})}if(!this.dataManager.unsentDataVisitors.length)return void _utilities.Utilities.sendOfflineTracking({requester:this.requester,storage:this.offlineTrackingStorage});for(const c of this.dataManager.unsentDataVisitors)_utilities.Utilities.trackData({visitorCode:c,dataManager:this.dataManager,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,isConsentProvided:this._isConsentProvided(c),offlineTrackingStorage:this.offlineTrackingStorage})}getFeatureFlags(){if(!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})}),b}getVisitorFeatureFlags(a){if(!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})}),c}getActiveFeatureFlags(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.Utilities.parseFeatureVariable(a).throw());c.set(b.featureKey,{key:d,id:f,experimentId:g,variables:i})}),c}getFeatureFlagVariationKey(a,b){_utilities.Utilities.validateVisitorCode(a).throw();const{variationKey:c}=this._getFeatureVariation(a,b).throw();return c}getFeatureFlagVariable(a){let{visitorCode:b,featureKey:c,variableKey:d}=a;_utilities.Utilities.validateVisitorCode(b).throw();const{variationKey:e}=this._getFeatureVariation(b,c).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.Utilities.parseFeatureVariable(g).throw();return{type:h,value:i}}getFeatureFlagVariables(a,b){_utilities.Utilities.validateVisitorCode(a).throw();const{variationKey:c}=this._getFeatureVariation(a,b).throw(),d=this._getFeatureVariables({visitorCode:a,featureKey:b,variationKey:c}),e=[];for(const c of d){const a=_utilities.Utilities.parseFeatureVariable(c).throw();e.push(a)}return e}isFeatureFlagActive(a,b){try{const c=this.getFeatureFlagVariationKey(a,b);return c!==_constants.OFF_VARIATION_KEY}catch(a){if(a instanceof _kameleoonError.KameleoonError&&a.type===_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled)return!1;throw a}}async getRemoteData(a){const b=await this.requester.getRemoteData(a);return b.throw()}async getVisitorWarehouseAudience(a){let{visitorCode:b,customDataIndex:c,warehouseKey:d}=a;_utilities.Utilities.validateVisitorCode(b).throw();const e=await this.getRemoteData(d||b);if(!e)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,"No data found for ".concat(d||b," key"));if(!e[_constants.WAREHOUSE_AUDIENCE_KEY]||0===Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]).length)return null;const f=new _kameleoonData.CustomData(c,...Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]));return this.dataManager.addData(b,f),f}onConfigurationUpdate(a){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(_eventManager.EventType.ConfigurationUpdate,a)}onEvent(a,b){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(a,b)}getEngineTrackingCode(a){return _utilities.Utilities.validateVisitorCode(a).throw(),_utilities.Utilities.getTrackingCode(this.trackingCache,a)}isInitialized(){return this.initialized}setUserConsent(a){let{visitorCode:b,consent:c,setData:d}=a;_utilities.Utilities.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})}_isConsentProvided(a){const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read();return!b||c.ok&&c.data[a]}_getFeatureVariables(a){let{visitorCode:b,featureKey:c,variationKey:d}=a;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 g.variables}_getActiveFeatureVariations(a){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);const b=this.clientConfiguration.featureFlags,c=[],d=this.dataManager.getTargetingData(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 c}_getFeatureVariation(a,b){if(!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));const c=this.clientConfiguration.featureFlags,d=c.get(b);if(!d)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,b));if(!d.environmentEnabled)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled,d.featureKey,this.environment));const e=this.dataManager.getTargetingData(a),f=this.dataManager.getVisitorIdentifier(a),g=this.variationConfiguration.getVariation({visitorCode:a,visitorIdentifier:f,featureFlag:d,targetingData:e,withAssignment:!0,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:b,variation:{key:g.variationKey,experimentId:g.experimentId,id:g.variationId}});const{experimentId:h,variationId:i}=g;return"number"==typeof i&&"number"==typeof h&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,visitorCode:a,experimentId:h,variationId:i}),_utilities.Utilities.trackFeatureExperiment({visitorCode:a,requester:this.requester,featureFlagVariation:g,dataManager:this.dataManager,isOfflineModeOn:this.isOfflineModeOn,isConsentProvided:this._isConsentProvided(a),offlineTrackingStorage:this.offlineTrackingStorage,variationConfiguration:this.variationConfiguration}),(0,_tsRes.Ok)(g)}}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"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_eventManager=require("./eventManager"),_eventSource=require("./eventSource"),_visitorCodeManager=require("./visitorCodeManager");function _defineProperty(a,b,c){return b=_toPropertyKey(b),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){let{siteCode:b,configuration:c,internalConfiguration:d}=a;_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"clientConfiguration",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"offlineTrackingStorage",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,"environment",void 0),_defineProperty(this,"isOfflineModeOn",void 0);const{settings:e}=new _clientSettings.ClientSettings(b,c);this.environment=e.environment;const{externalStorage:f,externalEventSource:g,externalPackageInfo:h,externalVisitorCodeManager:i,externalRequester:j,externalClientConfiguration:k,externalPRNG:l}=d,m=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),n=new _storage.DataStorage(f,_storage.KameleoonStorageKey.ClientData),o=new _storage.DataStorage(f,_storage.KameleoonStorageKey.TargetingData),p=new _storage.DataStorage(f,_storage.KameleoonStorageKey.VariationData),q=new _storage.DataStorage(f,_storage.KameleoonStorageKey.OfflineTracking),r=new _storage.DataStorage(f,_storage.KameleoonStorageKey.ConsentData),s=new _kameleoonData.DataManager({storage:o,cleanupInterval:e.cleanupInterval}),t=new _requester.Requester({siteCode:b,domain:e.networkDomain,environment:e.environment,packageInfo:h,externalRequester:j,requestTimeout:e.requestTimeout,trackRetryDelay:e.trackRetryDelay}),u=new _eventSource.KameleoonEventSource(e.siteCode,g),v=new _eventManager.EventManager,w=new _clientConfiguration.ClientConfiguration({storage:n,updateInterval:e.updateInterval,dataManager:s,eventManager:v,requester:t,externalClientConfiguration:k,offlineTrackingStorage:q,eventSource:u,externalVisitorCodeManager:i}),x=new _variationConfiguration.VariationConfiguration(p);_utilities.Utilities.prng=l,this.variationConfiguration=x,this.requester=t,this.trackingCache=m,this.dataManager=s,this.clientConfiguration=w,this.externalPackageInfo=h,this.offlineTrackingStorage=q,this.consentDataStorage=r,this.visitorCodeManager=i,this.eventManager=v}async initialize(a){const b=await this.clientConfiguration.initialize();return b.throw(),this.isOfflineModeOn=a,this.initialized=!0,b.ok}addData(a){if(_utilities.Utilities.validateVisitorCode(a).throw(),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];this.dataManager.addData(a,...c).throw()}async getRemoteVisitorData(a){let{visitorCode:b,shouldAddData:c=!0,filters:d=_constants.DEFAULT_VISITOR_DATA_FILTERS,isUniqueIdentifier:e=!1}=a;if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_utilities.Utilities.validateVisitorCode(b).throw();const{previousVisitAmount:f}=d;if("number"==typeof f&&(1>f||25<f))throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitAmount);const g=await this.requester.getVisitorData({visitorCode:b,filters:d,isMappingIdentifier:e}),h=g.throw(),{visitorData:i,storageVisitorData:j,visitsData:k}=_utilities.Utilities.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),i}trackConversion(a){let{visitorCode:b,goalId:c,revenue:d,isUniqueIdentifier:e}=a;this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:d})),this.flush(b,e)}flush(a,b){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a&&_utilities.Utilities.validateVisitorCode(a).throw(),a){let c=!1;if(b){const b=this.dataManager.getLinkedVisitor(a),d=this.dataManager.identifierCustomDataIndex;b||"number"!=typeof d?c=!0:this.dataManager.addData(a,new _kameleoonData.CustomData(d,a))}return void _utilities.Utilities.trackData({visitorCode:a,isMappingIdentifier:c,dataManager:this.dataManager,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,isConsentProvided:this._isConsentProvided(a),offlineTrackingStorage:this.offlineTrackingStorage})}if(!this.dataManager.unsentDataVisitors.length)return void _utilities.Utilities.sendOfflineTracking({requester:this.requester,storage:this.offlineTrackingStorage});for(const c of this.dataManager.unsentDataVisitors)_utilities.Utilities.trackData({visitorCode:c,dataManager:this.dataManager,requester:this.requester,isOfflineModeOn:this.isOfflineModeOn,isConsentProvided:this._isConsentProvided(c),offlineTrackingStorage:this.offlineTrackingStorage})}getFeatureFlags(){if(!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})}),b}getVisitorFeatureFlags(a){if(!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})}),c}getActiveFeatureFlags(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.Utilities.parseFeatureVariable(a).throw());c.set(b.featureKey,{key:d,id:f,experimentId:g,variables:i})}),c}getFeatureFlagVariationKey(a,b){_utilities.Utilities.validateVisitorCode(a).throw();const{variationKey:c}=this._getFeatureVariation(a,b).throw();return c}getFeatureFlagVariable(a){let{visitorCode:b,featureKey:c,variableKey:d}=a;_utilities.Utilities.validateVisitorCode(b).throw();const{variationKey:e}=this._getFeatureVariation(b,c).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.Utilities.parseFeatureVariable(g).throw();return{type:h,value:i}}getFeatureFlagVariables(a,b){_utilities.Utilities.validateVisitorCode(a).throw();const{variationKey:c}=this._getFeatureVariation(a,b).throw(),d=this._getFeatureVariables({visitorCode:a,featureKey:b,variationKey:c}),e=[];for(const c of d){const a=_utilities.Utilities.parseFeatureVariable(c).throw();e.push(a)}return e}isFeatureFlagActive(a,b){try{const c=this.getFeatureFlagVariationKey(a,b);return c!==_constants.OFF_VARIATION_KEY}catch(a){if(a instanceof _kameleoonError.KameleoonError&&a.type===_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled)return!1;throw a}}async getRemoteData(a){const b=await this.requester.getRemoteData(a);return b.throw()}async getVisitorWarehouseAudience(a){let{visitorCode:b,customDataIndex:c,warehouseKey:d}=a;_utilities.Utilities.validateVisitorCode(b).throw();const e=await this.getRemoteData(d||b);if(!e)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,"No data found for ".concat(d||b," key"));if(!e[_constants.WAREHOUSE_AUDIENCE_KEY]||0===Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]).length)return null;const f=new _kameleoonData.CustomData(c,...Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]));return this.dataManager.addData(b,f),f}onConfigurationUpdate(a){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(_eventManager.EventType.ConfigurationUpdate,a)}onEvent(a,b){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(a,b)}getEngineTrackingCode(a){return _utilities.Utilities.validateVisitorCode(a).throw(),_utilities.Utilities.getTrackingCode(this.trackingCache,a)}isInitialized(){return this.initialized}setUserConsent(a){let{visitorCode:b,consent:c,setData:d}=a;_utilities.Utilities.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})}_isConsentProvided(a){const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read();return!b||c.ok&&c.data[a]}_getFeatureVariables(a){let{visitorCode:b,featureKey:c,variationKey:d}=a;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 g.variables}_getActiveFeatureVariations(a){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);const b=this.clientConfiguration.featureFlags,c=[],d=this.dataManager.getTargetingData(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 c}_getFeatureVariation(a,b){if(!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));const c=this.clientConfiguration.featureFlags,d=c.get(b);if(!d)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,b));if(!d.environmentEnabled)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled,d.featureKey,this.environment));const e=this.dataManager.getTargetingData(a),f=this.dataManager.getVisitorIdentifier(a),g=this.variationConfiguration.getVariation({visitorCode:a,visitorIdentifier:f,featureFlag:d,targetingData:e,withAssignment:!0,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:b,variation:{key:g.variationKey,experimentId:g.experimentId,id:g.variationId}});const{experimentId:h,variationId:i}=g;return"number"==typeof i&&"number"==typeof h&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,visitorCode:a,experimentId:h,variationId:i}),_utilities.Utilities.trackFeatureExperiment({visitorCode:a,featureFlagVariation:g,requester:this.requester,dataManager:this.dataManager,isOfflineModeOn:this.isOfflineModeOn,isConsentProvided:this._isConsentProvided(a),offlineTrackingStorage:this.offlineTrackingStorage,variationConfiguration:this.variationConfiguration}),(0,_tsRes.Ok)(g)}}exports.KameleoonClient=KameleoonClient;
//# sourceMappingURL=kameleoonClient.js.map

@@ -6,3 +6,3 @@ import { ClientConfigurationDataType, ConfigurationDataType, JSONType } from './clientConfiguration/types';

import { IExternalStorage } from './storage';
import { VisitorDataFiltersType } from './utilities';
import { IExternalPRNG, VisitorDataFiltersType } from './utilities';
import { IVisitorCodeManager } from './visitorCodeManager';

@@ -57,2 +57,10 @@ /**

/**
* @param {ExternalPackageInfoType} packageInfo - external package info, used to get package version and name
* @param {IExternalPRNG | undefined} prng - external PRNG implementation
* */
export type InternalsType = {
packageInfo: ExternalPackageInfoType;
prng?: IExternalPRNG;
};
/**
* @param {IExternalStorage | undefined} externalStorage - external file system storage implemented outside client initialization

@@ -62,2 +70,3 @@ * @param {IExternalEventSourceConstructor | undefined} externalEventSource - constructor for building external event source implementation

* @param {ConfigurationDataType} externalClientConfiguration - external fetched client configuration
* Note: _Deprecated_ - to be removed in the next major update
* @param {IExternalRequester} externalRequester - external requester , used to track or get data

@@ -73,2 +82,3 @@ * @param {IVisitorCodeManager} externalVisitorCodeManager - external visitor code manager, used to get or generate visitor code

externalRequester: IExternalRequester;
externalPRNG: IExternalPRNG;
externalClientConfiguration?: ConfigurationDataType;

@@ -75,0 +85,0 @@ };

export { Utilities } from './utilities';
export { HEX_CHARACTERS } from './constants';
export { VisitorDataFiltersType, TimeUnit } from './types';
export { VisitorDataFiltersType, TimeUnit, IExternalPRNG } from './types';

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"HEX_CHARACTERS",{enumerable:!0,get:function(){return _constants.HEX_CHARACTERS}}),Object.defineProperty(exports,"TimeUnit",{enumerable:!0,get:function(){return _types.TimeUnit}}),Object.defineProperty(exports,"Utilities",{enumerable:!0,get:function(){return _utilities.Utilities}}),Object.defineProperty(exports,"VisitorDataFiltersType",{enumerable:!0,get:function(){return _types.VisitorDataFiltersType}});var _utilities=require("./utilities"),_constants=require("./constants"),_types=require("./types");
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"HEX_CHARACTERS",{enumerable:!0,get:function(){return _constants.HEX_CHARACTERS}}),Object.defineProperty(exports,"IExternalPRNG",{enumerable:!0,get:function(){return _types.IExternalPRNG}}),Object.defineProperty(exports,"TimeUnit",{enumerable:!0,get:function(){return _types.TimeUnit}}),Object.defineProperty(exports,"Utilities",{enumerable:!0,get:function(){return _utilities.Utilities}}),Object.defineProperty(exports,"VisitorDataFiltersType",{enumerable:!0,get:function(){return _types.VisitorDataFiltersType}});var _utilities=require("./utilities"),_constants=require("./constants"),_types=require("./types");
//# sourceMappingURL=index.js.map

@@ -146,1 +146,11 @@ import { CacheManager } from '../cacheManager';

};
/**
* @interface `IExternalPRNG` - an interface for external PRNG (Pseudo-Random Number Generator) used to generate secure random numbers depending on the environment and platform
* */
export interface IExternalPRNG {
/**
* @method getRandomNumber - a method to generate a secure random number
* @returns {number} a secure random `number`, which must be a floating-point number between 0 and 1, similarly to `Math.random()`
* */
getRandomNumber(): number;
}

@@ -8,4 +8,5 @@ import { Result } from 'ts-res';

import { VersionMatchType } from '../targeting';
import { CheckTargetingParametersType, ManageCacheParametersType, TrackDataParametersType, TrackRuleParametersType, SendOfflineTrackingParametersType, ParseVisitorDataParametersType, InsertInOrderedListParametersType, TimeUnit, GetDataUrlParametersType, GetVariationDataUrlParametersType, ParseVisitorDataResultType } from './types';
import { CheckTargetingParametersType, ManageCacheParametersType, TrackDataParametersType, TrackRuleParametersType, SendOfflineTrackingParametersType, ParseVisitorDataParametersType, InsertInOrderedListParametersType, TimeUnit, GetDataUrlParametersType, GetVariationDataUrlParametersType, ParseVisitorDataResultType, IExternalPRNG } from './types';
export declare class Utilities {
static prng: IExternalPRNG | undefined;
static checkTargeting({ segment, visitorCode, targetingData, experimentId, variationConfiguration, clientConfiguration, packageInfo, dataManager, }: CheckTargetingParametersType): Result<boolean, KameleoonError>;

@@ -12,0 +13,0 @@ static validateVisitorCode(visitorCode: string): Result<void, KameleoonError>;

@@ -1,2 +0,2 @@

"use strict";const _excluded=["timestamp","isExperiment"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.Utilities=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_kameleoonData=require("../kameleoonData"),_constants=require("../constants"),_requester=require("../requester"),_targeting=require("../targeting"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants2=require("./constants"),_types2=require("./types");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],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}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),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 Utilities{static checkTargeting(a){let{segment:b,visitorCode:c,targetingData:d,experimentId:e,variationConfiguration:f,clientConfiguration:g,packageInfo:h,dataManager:i}=a;if(!b||!b.conditionsData.firstLevel.length)return(0,_tsRes.Ok)(!0);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));let j={};const k=f.getStoredVariations(c);k.ok&&(j=k.data);const l=i.getTree(b);let m,n,o;l.hasTargetingType(_targeting.TargetingType.SEGMENT)&&(m=i.trees,n=g.segments),l.hasTargetingType(_targeting.TargetingType.TARGET_FEATURE_FLAG)&&(o=g.ruleMap);const p=l.evaluate({variationData:j,sdkInfo:h,segments:n,ruleMap:o,trees:m,targetingData:d,experimentId:e,visitorCode:c});return p}static validateVisitorCode(a){return 0===a.length?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeEmpty)):a.length>_constants2.VISITOR_CODE_MAX_LENGTH?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeMaxLength)):(0,_tsRes.Ok)()}static getDataUrl(a){function b(a){if(!a.url)return;const b=a.data.type===_kameleoonData.KameleoonData.Conversion;if(e||b){const c=b?"":_requester.UrlParameter.Nonce+Utilities.getNonce();g.push(a.url+c+"\n")}}let{visitorCode:c,dataManager:d,isConsentProvided:e}=a;const f=d.getUnsentData(c),g=[];if(!f||!f.size)return"";for(const c of f.values())Array.isArray(c)?c.forEach(a=>b(a)):b(c);return g.join("")}static getVariationDataUrlAndSentExperimentIds(a){let{visitorCode:b,isConsentProvided:c,variationConfiguration:d}=a;const e=[],f=new Set,g=d.getUnsentData(b);g.ok&&g.data.length&&g.data.forEach(a=>{(a.isTargetedRule||c)&&(e.push(_requester.UrlEventType.Experiment+_requester.UrlParameter.Id+a.experimentId+_requester.UrlParameter.VariationId+a.variationId+_requester.UrlParameter.Nonce+Utilities.getNonce()+"\n"),f.add(a.experimentId+""))});const h=e.join(""),i=Array.from(f);return[h,i]}static async trackFeatureExperiment(a){let{featureFlagVariation:b,dataManager:c,visitorCode:d,requester:e,isOfflineModeOn:f,isConsentProvided:g,offlineTrackingStorage:h,variationConfiguration:i}=a;const{variationId:j,rule:k}=b,l=this.getUserAgent(d,c),m=this.getDataUrl({visitorCode:d,dataManager:c,isConsentProvided:g}),n=k?k.experimentId:0,[o,p]=this.getVariationDataUrlAndSentExperimentIds({visitorCode:d,isConsentProvided:g,variationConfiguration:i});if(!g&&!m&&!k)return;const q={visitorCode:d,dataUrl:m,variationDataUrl:o,experimentId:n,variationId:j||0,userAgent:l,isUnallocated:null===j},r=await e.trackExperiment(q);r.ok&&(g?c.clearUnsentData(d):c.clearUnsentDataByKey(d,_kameleoonData.KameleoonData.Conversion),p.forEach(a=>{i.markUnsentDataAsSent(d,a)})),!r.ok&&f&&this.addItemToOfflineTracking({item:q,storage:h,isExperiment:!0})}static convertTimeUnit(a,b){const c={[_types2.TimeUnit.Minute]:_types.Milliseconds.Minute,[_types2.TimeUnit.Hour]:_types.Milliseconds.Hour,[_types2.TimeUnit.Day]:_types.Milliseconds.Day,[_types2.TimeUnit.Week]:_types.Milliseconds.Week,[_types2.TimeUnit.Month]:_types.Milliseconds.Month};return a/c[b]}static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor(c,e),{currentVisit:h,previousVisits:i,kcs:j}=b;let k=[];if(h&&k.push(h),i&&k.push(...i),!k.length)return{visitorData:[],storageVisitorData:[]};k.forEach(a=>{g.processVisit(a)}),g.processKcs(j),g.processMultipleDataTypes();const{visitorData:l,storageVisitorData:m,visitsData:n,experimentData:o}=g.data;return f.updateStoredVariations(d,o),{visitorData:l,storageVisitorData:m,visitsData:n}}static parseRegExp(a){if("/"===a[0]){const[_,b,c]=a.split("/");return new RegExp(b,c)}return new RegExp(a)}static getUserAgent(a,b){const c=b.getTargetingData(a);if(c){const a=c[_kameleoonData.KameleoonData.UserAgent];if(a)return a.value}}static isCustomData(a){return a.data.type===_kameleoonData.KameleoonData.CustomData}static insertInOrderedListMutably(a){let{list:b,element:c,order:d}=a;if(!b.includes(c)){const a=b.findIndex(a=>d===_types2.Order.Ascending?a>=c:a<=c);-1===a?b.push(c):b.splice(a,0,c)}}static updateCache(a){let{cacheManager:b,visitorCode:c,experimentId:d,variationId:e}=a;const f=b.getAliveItem(c),g=f?_objectSpread({},f):{};g[d]={variationId:e,expirationTime:Date.now()+_constants.CACHE_ITEM_LIFETIME*_types.Milliseconds.Second},b.add({key:c,data:g,lifetime:_constants.CACHE_ITEM_LIFETIME})}static getTrackingCode(a,b){let c="window.kameleoonQueue=window.kameleoonQueue||[];";const d=a.getAliveItem(b);if(!d)return c;const e={};return Object.entries(d).forEach(a=>{let[b,{variationId:d,expirationTime:f}]=a;f>Date.now()&&(c+="window.kameleoonQueue.push(['Experiments.assignVariation',".concat(b,",").concat(d,",true]);"),c+="window.kameleoonQueue.push(['Experiments.trigger',".concat(b,",true]);"),e[+b]={variationId:d,expirationTime:f})}),a.add({key:b,data:e,lifetime:_constants.CACHE_ITEM_LIFETIME}),c}static async trackData(a){let{visitorCode:b,dataManager:c,requester:d,isOfflineModeOn:e,offlineTrackingStorage:f,isConsentProvided:g,isMappingIdentifier:h}=a;const i=this.getDataUrl({visitorCode:b,dataManager:c,isConsentProvided:g});if(!g&&!i)return;const j=this.getUserAgent(b,c),k={visitorCode:b,body:i,userAgent:j,isMappingIdentifier:h},l=await d.trackData(k),m=()=>g?c.clearUnsentData(b):c.clearUnsentDataByKey(b,_kameleoonData.KameleoonData.Conversion);l.ok&&m(),!l.ok&&e&&this.addItemToOfflineTracking({item:k,storage:f,isExperiment:!1,onSuccess:m}),await this.sendOfflineTracking({requester:d,storage:f})}static getNonce(){let a="";for(let b=0;b<_constants2.NONCE_LENGTH;b++){const b=Math.floor(Math.random()*_constants2.NONCE_LENGTH);a+=_constants2.HEX_CHARACTERS.charAt(b)}return a}static compareSemVer(a){let{version:b,compareVersion:c,operator:d}=a;const e=this.validateVersion(b),f=this.validateVersion(c);if(!e.ok)return(0,_tsRes.Err)(e.error);if(!f.ok)return(0,_tsRes.Err)(f.error);const[g,h,i]=e.data,[j,k,l]=f.data,[m,n,o]=[g===j,h===k,i===l];switch(d){case _targeting.VersionMatchType.EQUAL:return(0,_tsRes.Ok)(m&&n&&o);case _targeting.VersionMatchType.GREATER:return(0,_tsRes.Ok)(g>j||m&&h>k||m&&n&&i>l);case _targeting.VersionMatchType.LOWER:return(0,_tsRes.Ok)(g<j||m&&h<k||m&&n&&i<l);default:(0,_kameleoonError.exhaustCheck)(d)}}static generateRandomString(a){const b="abcdefghijklmnopqrstuvwxyz0123456789",c=[];if(0>a)return"";for(let d=0;d<a;d++)c.push(b[Math.floor(Math.random()*b.length)]);return c.join("")}static async sendOfflineTracking(a){let{requester:b,storage:c}=a;const d=c.read();if(d.ok&&d.data.requestParameters){const{requestParameters:a}=d.data,e=[];for(const c of a){const{timestamp:a,isExperiment:d}=c,f=_objectWithoutProperties(c,_excluded);let g;g=d?await b.trackExperiment(f):await b.trackData(f),g.ok&&g.data&&e.push(a)}this.deleteFromOfflineTracking({storage:c,timestamps:e})}}static addItemToOfflineTracking(a){let{item:b,isExperiment:c,storage:d,onSuccess:e}=a;const f=d.read(),g=f.ok?f.data:{},{requestParameters:h}=g,i=_objectSpread(_objectSpread({},b),{},{timestamp:new Date().getTime(),isExperiment:c}),j=h?[...h,i]:[i],k=d.write({requestParameters:j});k.ok&&e&&e()}static deleteFromOfflineTracking(a){let{timestamps:b,storage:c}=a;const d=c.read();if(d.ok){const{requestParameters:a}=d.data,e=null===a||void 0===a?void 0:a.filter(a=>!b.includes(a.timestamp));c.write({requestParameters:e})}}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))}}exports.Utilities=Utilities;
"use strict";const _excluded=["timestamp","isExperiment"];Object.defineProperty(exports,"__esModule",{value:!0}),exports.Utilities=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_kameleoonData=require("../kameleoonData"),_constants=require("../constants"),_requester=require("../requester"),_targeting=require("../targeting"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants2=require("./constants"),_types2=require("./types");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],0<=b.indexOf(c)||Object.prototype.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}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),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 Utilities{static checkTargeting(a){let{segment:b,visitorCode:c,targetingData:d,experimentId:e,variationConfiguration:f,clientConfiguration:g,packageInfo:h,dataManager:i}=a;if(!b||!b.conditionsData.firstLevel.length)return(0,_tsRes.Ok)(!0);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));let j={};const k=f.getStoredVariations(c);k.ok&&(j=k.data);const l=i.getTree(b);let m,n,o;l.hasTargetingType(_targeting.TargetingType.SEGMENT)&&(m=i.trees,n=g.segments),l.hasTargetingType(_targeting.TargetingType.TARGET_FEATURE_FLAG)&&(o=g.ruleMap);const p=l.evaluate({variationData:j,sdkInfo:h,segments:n,ruleMap:o,trees:m,targetingData:d,experimentId:e,visitorCode:c});return p}static validateVisitorCode(a){return 0===a.length?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeEmpty)):a.length>_constants2.VISITOR_CODE_MAX_LENGTH?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitorCodeMaxLength)):(0,_tsRes.Ok)()}static getDataUrl(a){function b(a){if(!a.url)return;const b=a.data.type===_kameleoonData.KameleoonData.Conversion;if(e||b){const c=b?"":_requester.UrlParameter.Nonce+Utilities.getNonce();g.push(a.url+c+"\n")}}let{visitorCode:c,dataManager:d,isConsentProvided:e}=a;const f=d.getUnsentData(c),g=[];if(!f||!f.size)return"";for(const c of f.values())Array.isArray(c)?c.forEach(a=>b(a)):b(c);return g.join("")}static getVariationDataUrlAndSentExperimentIds(a){let{visitorCode:b,isConsentProvided:c,variationConfiguration:d}=a;const e=[],f=new Set,g=d.getUnsentData(b);g.ok&&g.data.length&&g.data.forEach(a=>{(a.isTargetedRule||c)&&(e.push(_requester.UrlEventType.Experiment+_requester.UrlParameter.Id+a.experimentId+_requester.UrlParameter.VariationId+a.variationId+_requester.UrlParameter.Nonce+Utilities.getNonce()+"\n"),f.add(a.experimentId+""))});const h=e.join(""),i=Array.from(f);return[h,i]}static async trackFeatureExperiment(a){let{featureFlagVariation:b,dataManager:c,visitorCode:d,requester:e,isOfflineModeOn:f,isConsentProvided:g,offlineTrackingStorage:h,variationConfiguration:i}=a;const{variationId:j,rule:k}=b,l=this.getUserAgent(d,c),m=this.getDataUrl({visitorCode:d,dataManager:c,isConsentProvided:g}),n=k?k.experimentId:0,[o,p]=this.getVariationDataUrlAndSentExperimentIds({visitorCode:d,isConsentProvided:g,variationConfiguration:i});if(!g&&!m&&!k)return;const q={visitorCode:d,dataUrl:m,variationDataUrl:o,experimentId:n,variationId:j||0,userAgent:l,isUnallocated:null===j},r=await e.trackExperiment(q);r.ok&&(g?c.clearUnsentData(d):c.clearUnsentDataByKey(d,_kameleoonData.KameleoonData.Conversion),p.forEach(a=>{i.markUnsentDataAsSent(d,a)})),!r.ok&&f&&this.addItemToOfflineTracking({item:q,storage:h,isExperiment:!0})}static convertTimeUnit(a,b){const c={[_types2.TimeUnit.Minute]:_types.Milliseconds.Minute,[_types2.TimeUnit.Hour]:_types.Milliseconds.Hour,[_types2.TimeUnit.Day]:_types.Milliseconds.Day,[_types2.TimeUnit.Week]:_types.Milliseconds.Week,[_types2.TimeUnit.Month]:_types.Milliseconds.Month};return a/c[b]}static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor(c,e),{currentVisit:h,previousVisits:i,kcs:j}=b;let k=[];if(h&&k.push(h),i&&k.push(...i),!k.length)return{visitorData:[],storageVisitorData:[]};k.forEach(a=>{g.processVisit(a)}),g.processKcs(j),g.processMultipleDataTypes();const{visitorData:l,storageVisitorData:m,visitsData:n,experimentData:o}=g.data;return f.updateStoredVariations(d,o),{visitorData:l,storageVisitorData:m,visitsData:n}}static parseRegExp(a){if("/"===a[0]){const[_,b,c]=a.split("/");return new RegExp(b,c)}return new RegExp(a)}static getUserAgent(a,b){const c=b.getTargetingData(a);if(c){const a=c[_kameleoonData.KameleoonData.UserAgent];if(a)return a.value}}static isCustomData(a){return a.data.type===_kameleoonData.KameleoonData.CustomData}static insertInOrderedListMutably(a){let{list:b,element:c,order:d}=a;if(!b.includes(c)){const a=b.findIndex(a=>d===_types2.Order.Ascending?a>=c:a<=c);-1===a?b.push(c):b.splice(a,0,c)}}static updateCache(a){let{cacheManager:b,visitorCode:c,experimentId:d,variationId:e}=a;const f=b.getAliveItem(c),g=f?_objectSpread({},f):{};g[d]={variationId:e,expirationTime:Date.now()+_constants.CACHE_ITEM_LIFETIME*_types.Milliseconds.Second},b.add({key:c,data:g,lifetime:_constants.CACHE_ITEM_LIFETIME})}static getTrackingCode(a,b){let c="window.kameleoonQueue=window.kameleoonQueue||[];";const d=a.getAliveItem(b);if(!d)return c;const e={};return Object.entries(d).forEach(a=>{let[b,{variationId:d,expirationTime:f}]=a;f>Date.now()&&(c+="window.kameleoonQueue.push(['Experiments.assignVariation',".concat(b,",").concat(d,",true]);"),c+="window.kameleoonQueue.push(['Experiments.trigger',".concat(b,",true]);"),e[+b]={variationId:d,expirationTime:f})}),a.add({key:b,data:e,lifetime:_constants.CACHE_ITEM_LIFETIME}),c}static async trackData(a){let{visitorCode:b,dataManager:c,requester:d,isOfflineModeOn:e,offlineTrackingStorage:f,isConsentProvided:g,isMappingIdentifier:h}=a;const i=this.getDataUrl({visitorCode:b,dataManager:c,isConsentProvided:g});if(!g&&!i)return;const j=this.getUserAgent(b,c),k={visitorCode:b,body:i,userAgent:j,isMappingIdentifier:h},l=await d.trackData(k),m=()=>g?c.clearUnsentData(b):c.clearUnsentDataByKey(b,_kameleoonData.KameleoonData.Conversion);l.ok&&m(),!l.ok&&e&&this.addItemToOfflineTracking({item:k,storage:f,isExperiment:!1,onSuccess:m}),await this.sendOfflineTracking({requester:d,storage:f})}static getNonce(){let a="";for(let d=0;d<_constants2.NONCE_LENGTH;d++){var b,c;const d=null!==(b=null===(c=this.prng)||void 0===c?void 0:c.getRandomNumber())&&void 0!==b?b:Math.random(),e=Math.floor(d*_constants2.NONCE_LENGTH);a+=_constants2.HEX_CHARACTERS.charAt(e)}return a}static compareSemVer(a){let{version:b,compareVersion:c,operator:d}=a;const e=this.validateVersion(b),f=this.validateVersion(c);if(!e.ok)return(0,_tsRes.Err)(e.error);if(!f.ok)return(0,_tsRes.Err)(f.error);const[g,h,i]=e.data,[j,k,l]=f.data,[m,n,o]=[g===j,h===k,i===l];switch(d){case _targeting.VersionMatchType.EQUAL:return(0,_tsRes.Ok)(m&&n&&o);case _targeting.VersionMatchType.GREATER:return(0,_tsRes.Ok)(g>j||m&&h>k||m&&n&&i>l);case _targeting.VersionMatchType.LOWER:return(0,_tsRes.Ok)(g<j||m&&h<k||m&&n&&i<l);default:(0,_kameleoonError.exhaustCheck)(d)}}static generateRandomString(a){const b="abcdefghijklmnopqrstuvwxyz0123456789",c=[];if(0>a)return"";for(let d=0;d<a;d++)c.push(b[Math.floor(Math.random()*b.length)]);return c.join("")}static async sendOfflineTracking(a){let{requester:b,storage:c}=a;const d=c.read();if(d.ok&&d.data.requestParameters){const{requestParameters:a}=d.data,e=[];for(const c of a){const{timestamp:a,isExperiment:d}=c,f=_objectWithoutProperties(c,_excluded);let g;g=d?await b.trackExperiment(f):await b.trackData(f),g.ok&&g.data&&e.push(a)}this.deleteFromOfflineTracking({storage:c,timestamps:e})}}static addItemToOfflineTracking(a){let{item:b,isExperiment:c,storage:d,onSuccess:e}=a;const f=d.read(),g=f.ok?f.data:{},{requestParameters:h}=g,i=_objectSpread(_objectSpread({},b),{},{timestamp:new Date().getTime(),isExperiment:c}),j=h?[...h,i]:[i],k=d.write({requestParameters:j});k.ok&&e&&e()}static deleteFromOfflineTracking(a){let{timestamps:b,storage:c}=a;const d=c.read();if(d.ok){const{requestParameters:a}=d.data,e=null===a||void 0===a?void 0:a.filter(a=>!b.includes(a.timestamp));c.write({requestParameters:e})}}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))}}exports.Utilities=Utilities,_defineProperty(Utilities,"prng",void 0);
//# sourceMappingURL=utilities.js.map
{
"name": "@kameleoon/javascript-sdk-core",
"version": "4.4.3",
"version": "4.4.4",
"description": "Kameleoon JS SDK Core",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc