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
3
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.1.0 to 4.2.0

10

CHANGELOG.md
# Change Log
## 4.2.0 (2024-05-07)
### Features
- New method [`getActiveFeatureFlags`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#getactivefeatureflags) for retrieving feature flags that are active for visitor with detailed variation and variables information.
### Patch Changes
- Improved _Previous Page_ condition logic
## 4.1.0 (2024-04-19)

@@ -4,0 +14,0 @@

7

dist/clientConfiguration/clientConfiguration.d.ts

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

onConfigurationUpdate: (callback: () => void) => void;
readonly featureFlags: FeatureFlagType[];
readonly featureFlags: Map<string, FeatureFlagType>;
readonly configuration: ConfigurationType;

@@ -19,2 +19,5 @@ readonly segments: Map<string, SegmentType>;

private configurationData;
private featureFlagsData;
private isTargetedDeliveryRule;
private segmentsData;
private settings;

@@ -37,3 +40,3 @@ private lastUpdate;

onConfigurationUpdate(callback: () => void): void;
get featureFlags(): FeatureFlagType[];
get featureFlags(): Map<string, FeatureFlagType>;
get configuration(): ConfigurationType;

@@ -40,0 +43,0 @@ get segments(): Map<string, SegmentType>;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_constants=require("./constants"),_types=require("./types"),_utilities=require("../utilities"),_urlProvider=require("../requester/urlProvider");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 ClientConfiguration{constructor(a){let{settings:b,storage:c,requester:d,dataManager:e,externalClientConfiguration:f,offlineTrackingStorage:g,eventSource:h,externalVisitorCodeManager:i}=a;_defineProperty(this,"configurationUpdateCallback",void 0),_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Idle),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"settings",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"mappedRules",new Map),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),this.requester=d,this.settings=b,this.lastUpdate=new Date,this.storage=c,this.dataManager=e,this.externalClientConfiguration=f,this.offlineTrackingStorage=g,this.visitorCodeManager=i,this.eventSource=h}async initialize(){this.readStorageData();const a=!!this.externalClientConfiguration,b=this.checkShouldUpdate(a);if(b){const a=await this.updateClientConfiguration();if(!a.ok)return a;const b=a.data;if(b)return(0,_tsRes.Ok)()}return a?(this.handleExternalUpdates(),(0,_tsRes.Ok)()):this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),(0,_tsRes.Ok)()):(this.updateType=_types.UpdateType.Idle,this.handleRealTimeUpdates(),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleExternalUpdates(){this.cleanupHandlers(),this.configurationData=this.externalClientConfiguration}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(a=>{a.ok&&this.configurationUpdateCallback&&this.configurationUpdateCallback()})};this.eventSource.open(a)}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.settings.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}onConfigurationUpdate(a){this.configurationUpdateCallback=a}get featureFlags(){return this.configurationData.featureFlags}get configuration(){return this.configurationData.configuration}get segments(){const a=new Map;return this.featureFlags.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),a}get ruleMap(){if(this.mappedRules.size)return this.mappedRules;const a=new Map;for(const b of this.featureFlags)for(const c of b.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)}),a.set(d,{featureId:b.id,experimentId:e,variations:g})}return this.mappedRules=a,a}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){return this.featureFlags.some(a=>a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))}checkIntegrity(a){if(!a)return!1;const b=Object.keys(a);if(!b.length)return!1;const c=Object.keys(_constants.DEFAULT_CONFIGURATION_DATA);return b.sort().join()===c.sort().join()}checkShouldUpdate(){let a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0];const{featureFlags:b,configuration:c}=this.configurationData,{updateInterval:d}=this.settings;if(a)return this.updateType=_types.UpdateType.Idle,!1;if(this.updateType=c.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!b.length)return!0;const e=this.lastUpdate.getTime(),f=Date.now()-d;return e<f}readStorageData(){const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data,d=this.checkIntegrity(b);d?(_urlProvider.UrlProvider.setDataApiDomain(b.configuration.dataApiDomain),this.configurationData=b,this.lastUpdate=new Date(Date.parse(c))):(_urlProvider.UrlProvider.setDataApiDomain(_constants.DEFAULT_CONFIGURATION_DATA.configuration.dataApiDomain),this.storage.write({data:_constants.DEFAULT_CONFIGURATION_DATA,lastUpdate:this.lastUpdate.toString()}),this.configurationData=_constants.DEFAULT_CONFIGURATION_DATA)}}async updateClientConfiguration(a){const b=await this.requester.getClientConfiguration(a);if(!b.ok){const{featureFlags:a}=this.configurationData;return a.length?(0,_tsRes.Ok)(!0):b}_utilities.Utilities.sendOfflineTracking({storage:this.offlineTrackingStorage,requester:this.requester});const{configuration:c,customData:d}=b.data;this.configurationData=b.data,null!==d&&void 0!==d&&d.length&&(this.dataManager.customDataIndexes=d),this.dataManager.clearTrees(),this.mappedRules.clear();const e=this.updateStorageData();if(!e.ok)return e;const f=c.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,g=f!==this.updateType;g&&(this.updateType=f,await this.initialize());const h=this.isConsentRequired&&!this.hasAnyTargetedDeliveryRule;return this.visitorCodeManager.consentRequired=h,(0,_tsRes.Ok)(g)}updateStorageData(){this.lastUpdate=new Date;const a={data:this.configurationData,lastUpdate:this.lastUpdate.toString()};return _urlProvider.UrlProvider.setDataApiDomain(this.configurationData.configuration.dataApiDomain),this.storage.write(a)}}exports.ClientConfiguration=ClientConfiguration;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_constants=require("./constants"),_types=require("./types"),_utilities=require("../utilities"),_urlProvider=require("../requester/urlProvider");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 ClientConfiguration{constructor(a){let{settings:b,storage:c,requester:d,dataManager:e,externalClientConfiguration:f,offlineTrackingStorage:g,eventSource:h,externalVisitorCodeManager:i}=a;_defineProperty(this,"configurationUpdateCallback",void 0),_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Idle),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"featureFlagsData",new Map),_defineProperty(this,"isTargetedDeliveryRule",null),_defineProperty(this,"segmentsData",null),_defineProperty(this,"settings",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"mappedRules",null),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),this.requester=d,this.settings=b,this.lastUpdate=new Date,this.storage=c,this.dataManager=e,this.externalClientConfiguration=f,this.offlineTrackingStorage=g,this.visitorCodeManager=i,this.eventSource=h}async initialize(){this.readStorageData();const a=!!this.externalClientConfiguration,b=this.checkShouldUpdate(a);if(b){const a=await this.updateClientConfiguration();if(!a.ok)return a;const b=a.data;if(b)return(0,_tsRes.Ok)()}return a?(this.handleExternalUpdates(),(0,_tsRes.Ok)()):this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),(0,_tsRes.Ok)()):(this.updateType=_types.UpdateType.Idle,this.handleRealTimeUpdates(),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleExternalUpdates(){this.cleanupHandlers();const{customData:a,configuration:b}=this.externalClientConfiguration;this.configurationData={customData:a,configuration:b};for(const a of this.featureFlags.values())this.featureFlagsData.set(a.featureKey,a)}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(a=>{a.ok&&this.configurationUpdateCallback&&this.configurationUpdateCallback()})};this.eventSource.open(a)}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.settings.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}onConfigurationUpdate(a){this.configurationUpdateCallback=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(){if(this.mappedRules)return this.mappedRules;const a=new Map;for(const b of this.featureFlags.values())for(const c of b.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)}),a.set(d,{featureId:b.id,experimentId:e,variations:g})}return this.mappedRules=a,a}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}checkIntegrity(a){if(!a)return!1;const b=Object.keys(a);if(!b.length)return!1;const c=Object.keys(_constants.DEFAULT_CLIENT_CONFIGURATION);return b.sort().join()===c.sort().join()}checkShouldUpdate(){let a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0];const{configuration:b}=this.configurationData,{updateInterval:c}=this.settings;if(a)return this.updateType=_types.UpdateType.Idle,!1;if(this.updateType=b.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!this.featureFlags.size)return!0;const d=this.lastUpdate.getTime(),e=Date.now()-c;return d<e}readStorageData(){const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data,d=this.checkIntegrity(b);if(!d){_urlProvider.UrlProvider.setDataApiDomain(_constants.DEFAULT_CONFIGURATION_DATA.configuration.dataApiDomain);const a=_objectSpread(_objectSpread({},_constants.DEFAULT_CONFIGURATION_DATA),{},{featureFlags:[]});this.storage.write({data:a,lastUpdate:this.lastUpdate.toString()}),this.configurationData=_constants.DEFAULT_CONFIGURATION_DATA}else _urlProvider.UrlProvider.setDataApiDomain(b.configuration.dataApiDomain),this.configurationData=b,this.lastUpdate=new Date(Date.parse(c))}}async updateClientConfiguration(a){var b;const c=await this.requester.getClientConfiguration(a);if(!c.ok)return this.featureFlags.size?(0,_tsRes.Ok)(!0):c;_utilities.Utilities.sendOfflineTracking({storage:this.offlineTrackingStorage,requester:this.requester});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,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 _urlProvider.UrlProvider.setDataApiDomain(this.configurationData.configuration.dataApiDomain),this.storage.write(b)}}exports.ClientConfiguration=ClientConfiguration;
//# sourceMappingURL=clientConfiguration.js.map

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

import { ConfigurationDataType } from '../clientConfiguration';
export declare const DEFAULT_CONFIGURATION_DATA: ConfigurationDataType;
import { ClientConfigurationDataType, ConfigurationDataType } from '../clientConfiguration';
export declare const DEFAULT_CONFIGURATION_DATA: ClientConfigurationDataType;
export declare const DEFAULT_CLIENT_CONFIGURATION: ConfigurationDataType;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_CONFIGURATION_DATA=void 0;var _types=require("./types"),_requester=require("../requester");const DEFAULT_CONFIGURATION_DATA=exports.DEFAULT_CONFIGURATION_DATA={featureFlags:[],customData:[],configuration:{realTimeUpdate:!1,consentType:_types.ConsentType.NotRequired,dataApiDomain:_requester.DATA_API_DOMAIN}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DEFAULT_CONFIGURATION_DATA=exports.DEFAULT_CLIENT_CONFIGURATION=void 0;var _types=require("./types"),_requester=require("../requester");const DEFAULT_CONFIGURATION_DATA=exports.DEFAULT_CONFIGURATION_DATA={customData:[],configuration:{realTimeUpdate:!1,consentType:_types.ConsentType.NotRequired,dataApiDomain:_requester.DATA_API_DOMAIN}},DEFAULT_CLIENT_CONFIGURATION=exports.DEFAULT_CLIENT_CONFIGURATION={customData:[],featureFlags:[],configuration:{realTimeUpdate:!1,consentType:_types.ConsentType.NotRequired,dataApiDomain:_requester.DATA_API_DOMAIN}};
//# sourceMappingURL=constants.js.map

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

export { ConfigurationDataType, CustomDataConfigurationType, CustomDataScope, VariationByExpositionType, FeatureVariableType, FeatureFlagType, ConsentType, RuleItemType, JSONValue, RuleType, JSONType, } from './types';
export { ConfigurationDataType, CustomDataConfigurationType, ClientConfigurationDataType, CustomDataScope, VariationByExpositionType, FeatureVariableType, FeatureFlagType, ConsentType, RuleItemType, JSONValue, RuleType, JSONType, } from './types';
export { ClientConfiguration } from './clientConfiguration';

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ClientConfiguration",{enumerable:!0,get:function(){return _clientConfiguration.ClientConfiguration}}),Object.defineProperty(exports,"ConfigurationDataType",{enumerable:!0,get:function(){return _types.ConfigurationDataType}}),Object.defineProperty(exports,"ConsentType",{enumerable:!0,get:function(){return _types.ConsentType}}),Object.defineProperty(exports,"CustomDataConfigurationType",{enumerable:!0,get:function(){return _types.CustomDataConfigurationType}}),Object.defineProperty(exports,"CustomDataScope",{enumerable:!0,get:function(){return _types.CustomDataScope}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureVariableType",{enumerable:!0,get:function(){return _types.FeatureVariableType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function(){return _types.JSONType}}),Object.defineProperty(exports,"JSONValue",{enumerable:!0,get:function(){return _types.JSONValue}}),Object.defineProperty(exports,"RuleItemType",{enumerable:!0,get:function(){return _types.RuleItemType}}),Object.defineProperty(exports,"RuleType",{enumerable:!0,get:function(){return _types.RuleType}}),Object.defineProperty(exports,"VariationByExpositionType",{enumerable:!0,get:function(){return _types.VariationByExpositionType}});var _types=require("./types"),_clientConfiguration=require("./clientConfiguration");
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ClientConfiguration",{enumerable:!0,get:function(){return _clientConfiguration.ClientConfiguration}}),Object.defineProperty(exports,"ClientConfigurationDataType",{enumerable:!0,get:function(){return _types.ClientConfigurationDataType}}),Object.defineProperty(exports,"ConfigurationDataType",{enumerable:!0,get:function(){return _types.ConfigurationDataType}}),Object.defineProperty(exports,"ConsentType",{enumerable:!0,get:function(){return _types.ConsentType}}),Object.defineProperty(exports,"CustomDataConfigurationType",{enumerable:!0,get:function(){return _types.CustomDataConfigurationType}}),Object.defineProperty(exports,"CustomDataScope",{enumerable:!0,get:function(){return _types.CustomDataScope}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureVariableType",{enumerable:!0,get:function(){return _types.FeatureVariableType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function(){return _types.JSONType}}),Object.defineProperty(exports,"JSONValue",{enumerable:!0,get:function(){return _types.JSONValue}}),Object.defineProperty(exports,"RuleItemType",{enumerable:!0,get:function(){return _types.RuleItemType}}),Object.defineProperty(exports,"RuleType",{enumerable:!0,get:function(){return _types.RuleType}}),Object.defineProperty(exports,"VariationByExpositionType",{enumerable:!0,get:function(){return _types.VariationByExpositionType}});var _types=require("./types"),_clientConfiguration=require("./clientConfiguration");
//# sourceMappingURL=index.js.map

@@ -98,2 +98,3 @@ import { ClientSettingsType } from '../clientSettings';

};
export type ClientConfigurationDataType = Omit<ConfigurationDataType, 'featureFlags'>;
export type CustomDataConfigurationType = {

@@ -100,0 +101,0 @@ index: number;

@@ -11,3 +11,3 @@ export { Ok, Result, Err } from 'ts-res';

export { JSONType, ConfigurationDataType } from './clientConfiguration';
export { Environment, VariableType, FeatureFlagType, SDKCoreParameters, SDKConfigurationType, ExternalPackageInfoType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, Milliseconds, } from './types';
export { Environment, VariableType, FeatureFlagType, SDKCoreParameters, SDKConfigurationType, KameleoonVariationType, ExternalPackageInfoType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, Milliseconds, } from './types';
export { DEFAULT_CLEANUP_INTERVAL } from './kameleoonData';

@@ -14,0 +14,0 @@ export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, KameleoonData, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, } from './kameleoonData';

@@ -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,"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,"DEFAULT_CLEANUP_INTERVAL",{enumerable:!0,get:function(){return _kameleoonData.DEFAULT_CLEANUP_INTERVAL}}),Object.defineProperty(exports,"DEFAULT_REQUEST_TIMEOUT",{enumerable:!0,get:function(){return _requester.DEFAULT_REQUEST_TIMEOUT}}),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,"EventSourceOpenParametersType",{enumerable:!0,get:function(){return _eventSource.EventSourceOpenParametersType}}),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,"IExternalRequestDispatcher",{enumerable:!0,get:function(){return _requester.IExternalRequestDispatcher}}),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,"KameleoonCoreUtils",{enumerable:!0,get:function(){return _kameleoonUtils.KameleoonUtils}}),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,"KameleoonStorageKey",{enumerable:!0,get:function(){return _storage.KameleoonStorageKey}}),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,"RETRIES_DELAY",{enumerable:!0,get:function(){return _requester.RETRIES_DELAY}}),Object.defineProperty(exports,"RemoteVisitorDataParamsType",{enumerable:!0,get:function(){return _types.RemoteVisitorDataParamsType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function(){return _tsRes.Result}}),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,"SetDataCallbackParametersType",{enumerable:!0,get:function(){return _types.SetDataCallbackParametersType}}),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"),_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,"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,"DEFAULT_CLEANUP_INTERVAL",{enumerable:!0,get:function(){return _kameleoonData.DEFAULT_CLEANUP_INTERVAL}}),Object.defineProperty(exports,"DEFAULT_REQUEST_TIMEOUT",{enumerable:!0,get:function(){return _requester.DEFAULT_REQUEST_TIMEOUT}}),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,"EventSourceOpenParametersType",{enumerable:!0,get:function(){return _eventSource.EventSourceOpenParametersType}}),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,"IExternalRequestDispatcher",{enumerable:!0,get:function(){return _requester.IExternalRequestDispatcher}}),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,"KameleoonCoreUtils",{enumerable:!0,get:function(){return _kameleoonUtils.KameleoonUtils}}),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,"KameleoonStorageKey",{enumerable:!0,get:function(){return _storage.KameleoonStorageKey}}),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,"RETRIES_DELAY",{enumerable:!0,get:function(){return _requester.RETRIES_DELAY}}),Object.defineProperty(exports,"RemoteVisitorDataParamsType",{enumerable:!0,get:function(){return _types.RemoteVisitorDataParamsType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function(){return _tsRes.Result}}),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,"SetDataCallbackParametersType",{enumerable:!0,get:function(){return _types.SetDataCallbackParametersType}}),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"),_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
import { JSONType } from './clientConfiguration';
import { CustomData, KameleoonDataType } from './kameleoonData';
import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType } from './types';
import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType, KameleoonVariationType } from './types';
import { IKameleoonClient } from './kameleoonClientInterface';

@@ -34,2 +34,3 @@ /**

getVisitorFeatureFlags(visitorCode: string): FeatureFlagType[];
getActiveFeatureFlags(visitorCode: string): Map<string, KameleoonVariationType>;
getFeatureFlagVariationKey(visitorCode: string, featureKey: string): string;

@@ -46,3 +47,5 @@ getFeatureFlagVariable({ visitorCode, featureKey, variableKey, }: GetFeatureFlagVariableParamsType): FeatureFlagVariableType;

private _isConsentProvided;
private _getFeatureFlagVariation;
private _getFeatureVariables;
private _getActiveFeatureVariations;
private _getFeatureVariation;
}

@@ -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"),_types=require("./types"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_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,"isOfflineModeOn",void 0),_defineProperty(this,"initialized",!1),_defineProperty(this,"environment",void 0),_defineProperty(this,"visitorCodeManager",void 0);const{settings:e}=new _clientSettings.ClientSettings(b,c);this.environment=e.environment;const{externalStorage:f,externalEventSource:g,externalPackageInfo:h,externalVisitorCodeManager:i,externalRequestDispatcher: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,targetingCleanupInterval:null===c||void 0===c?void 0:c.targetingDataCleanupInterval}),s=new _eventSource.KameleoonEventSource(e.siteCode,g),t=new _requester.Requester({siteCode:b,environment:e.environment,packageInfo:h,requestDispatcher:j}),u=new _clientConfiguration.ClientConfiguration({settings:e,storage:m,dataManager:r,requester:t,externalClientConfiguration:k,offlineTrackingStorage:p,eventSource:s,externalVisitorCodeManager:i}),v=new _variationConfiguration.VariationConfiguration(o);this.variationConfiguration=v,this.requester=t,this.trackingCache=l,this.dataManager=r,this.clientConfiguration=u,this.externalPackageInfo=h,this.offlineTrackingStorage=p,this.consentDataStorage=q,this.visitorCodeManager=i}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);return this.clientConfiguration.featureFlags.map(a=>{let{id:b,featureKey:c}=a;return{id:b,key:c}})}getVisitorFeatureFlags(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){const b=this.variationConfiguration.getVariation({visitorCode:a,visitorIdentifier:e,targetingData:d,featureFlag:f,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();if(b.variationKey!==_constants.OFF_VARIATION_KEY&&f.environmentEnabled){const{featureFlagId:a,featureKey:d}=b;c.push({id:a,key:d})}}return c}getFeatureFlagVariationKey(a,b){_utilities.Utilities.validateVisitorCode(a).throw();const{variationKey:c}=this._getFeatureFlagVariation(a,b).throw();return c}getFeatureFlagVariable(a){var b;let{visitorCode:c,featureKey:d,variableKey:e}=a;_utilities.Utilities.validateVisitorCode(c).throw();const{variationKey:f}=this._getFeatureFlagVariation(c,d).throw(),g=this.clientConfiguration.featureFlags,h=g.find(a=>a.featureKey===d);if(!h)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,d);const i=null===(b=h.variations.find(a=>a.key===f))||void 0===b?void 0:b.variables.find(a=>a.key===e);if(!i)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariableNotFound,e,c);const{type:j,value:k}=_utilities.Utilities.parseFeatureVariable(i).throw();return{type:j,value:k}}getFeatureFlagVariables(a,b){if(!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_utilities.Utilities.validateVisitorCode(a).throw();const{variationKey:c}=this._getFeatureFlagVariation(a,b).throw(),d=this.clientConfiguration.featureFlags,e=d.find(a=>a.featureKey===b);if(!e)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,b);const f=e.variations.find(a=>a.key===c);if(!f)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,c,a);const g=[];for(const c of f.variables){const a=_utilities.Utilities.parseFeatureVariable(c).throw();g.push(a)}return g}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);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.clientConfiguration.onConfigurationUpdate(a)}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]}_getFeatureFlagVariation(a,b){if(!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));const c=this.clientConfiguration.featureFlags,d=c.find(a=>a.featureKey===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||_types.Environment.Production));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(),{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"),_types=require("./types"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_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,"isOfflineModeOn",void 0),_defineProperty(this,"initialized",!1),_defineProperty(this,"environment",void 0),_defineProperty(this,"visitorCodeManager",void 0);const{settings:e}=new _clientSettings.ClientSettings(b,c);this.environment=e.environment;const{externalStorage:f,externalEventSource:g,externalPackageInfo:h,externalVisitorCodeManager:i,externalRequestDispatcher: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,targetingCleanupInterval:null===c||void 0===c?void 0:c.targetingDataCleanupInterval}),s=new _eventSource.KameleoonEventSource(e.siteCode,g),t=new _requester.Requester({siteCode:b,environment:e.environment,packageInfo:h,requestDispatcher:j}),u=new _clientConfiguration.ClientConfiguration({settings:e,storage:m,dataManager:r,requester:t,externalClientConfiguration:k,offlineTrackingStorage:p,eventSource:s,externalVisitorCodeManager:i}),v=new _variationConfiguration.VariationConfiguration(o);this.variationConfiguration=v,this.requester=t,this.trackingCache=l,this.dataManager=r,this.clientConfiguration=u,this.externalPackageInfo=h,this.offlineTrackingStorage=p,this.consentDataStorage=q,this.visitorCodeManager=i}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);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.clientConfiguration.onConfigurationUpdate(a)}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();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||_types.Environment.Production));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(),{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;
//# sourceMappingURL=kameleoonClient.js.map
import { JSONType } from './clientConfiguration';
import { CustomData, KameleoonDataType } from './kameleoonData';
import { FeatureFlagType, FeatureFlagVariableType, FeatureVariableResultType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, RemoteVisitorDataParamsType, TrackConversionParamsType } from './types';
import { FeatureFlagType, FeatureFlagVariableType, FeatureVariableResultType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, KameleoonVariationType, RemoteVisitorDataParamsType, TrackConversionParamsType } from './types';
/**

@@ -74,2 +74,5 @@ * @interface an interface of KameleoonClient instance

* @method getFeatureFlags - returns a list of feature flags stored in the client configuration
*
* Note: This method **doesn't send** tracking data
*
* @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields

@@ -83,2 +86,5 @@ * @throws `KameleoonError` with one of the following `type` s:

* @method getVisitorFeatureFlags - returns a list of feature flags that the visitor with `visitorCode` that is targeted by and that are *active* for the visitor (visitor will have one of the variations allocated).
*
* Note: This method **doesn't send** tracking data
*
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length

@@ -96,3 +102,23 @@ * @returns {FeatureFlagType[]} a list of all feature flags items with `id` and `key` fields

/**
* @method getActiveFeatureFlags - method collecting all active feature flags information including it's variation and variables for the visitor
*
* Note: This method **doesn't send** tracking data
*
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length
* @returns {Map<string, KameleoonVariationType>} a map of feature flags with `featureKey` as a key and `KameleoonVariationType` as a value
* @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 `initialize` was done for `kameleoonClient`
* - `KameleoonException.StorageRead` - Couldn't read storage data
* - `KameleoonException.JSONParse` - Couldn't parse JSON value
* - `KameleoonException.NumberParse` - Couldn't parse Number value
*/
getActiveFeatureFlags: (visitorCode: string) => Map<string, KameleoonVariationType>;
/**
* @method isFeatureFlagActive - returns a boolean indicating whether the visitor with `visitorCode` has `featureKey` active for him, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request
*
* Note: This method **sends** tracking data
*
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length

@@ -113,2 +139,5 @@ * @param {string} featureKey - a unique key for feature flag

* @method getFeatureFlagVariationKey - returns variation key for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request
*
* Note: This method **sends** tracking data
*
* @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length

@@ -129,2 +158,5 @@ * @param {string} featureKey - a unique key for feature flag

* @method getFeatureFlagVariable - returns a variable for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request
*
* Note: This method **sends** tracking data
*
* @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details.

@@ -147,2 +179,5 @@ * @returns {FeatureFlagVariableType} a variable object containing `type` and `value` fields. You can check the `type` field against `VariableType` enum. For example, if the `type` is `VariableType.BOOLEAN` then `value` will be a `boolean` type.

* @method getFeatureFlagVariables - returns a list of variables for the visitor under `visitorCode` in the found feature flag, this method includes targeting check, finding the according variation exposed to the visitor and saving it to storage along with sending tracking request
*
* Note: This method **sends** tracking data
*
* @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters

@@ -149,0 +184,0 @@ * @param {string} featureKey - a unique key for feature flag

@@ -164,3 +164,3 @@ import { JSONType } from '../clientConfiguration';

/**
* @type HeadersType - a type of headers available in the request
* @type `HeadersType` - a type of headers available in the request
* */

@@ -167,0 +167,0 @@ export type HeadersType = Partial<Record<Header, string>>;

@@ -31,3 +31,3 @@ import { Result } from 'ts-res';

/**
* @type StorageDataType - an enumeration type which represents a data stored on SDK storage
* @type `StorageDataType` - an enumeration type which represents a data stored on SDK storage
*

@@ -34,0 +34,0 @@ * `string` represents visitor code storage with only one string value

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreviousPage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");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 PreviousPage{constructor(a){let{matchType:b,url:c}=a;_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"matchType",void 0),this.conditionValue=c,this.matchType=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];if(!c)return(0,_tsRes.Ok)(!1);const d=this.getSecondLatestPageView(Object.values(c));if(!d)return(0,_tsRes.Ok)(!1);const e=d.urlAddress;return(0,_tsRes.Ok)(this.checkCondition(e))}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1}}getSecondLatestPageView(a){if(2>a.length)return;let b,c;return a.forEach(a=>{var d,e;const f=a.timestamps[a.timestamps.length-1],g=a.timestamps[a.timestamps.length-2];if(!b&&!c)return b=a,void(g&&(c=a));const h=null!==(d=b.timestamps[b.timestamps.length-1])&&void 0!==d?d:0;if(f>h){var i,j;c=b,b=a;const d=null===(i=c)||void 0===i?void 0:i.timestamps[(null===(j=c)||void 0===j?void 0:j.timestamps.length)-1];return void(g&&g>d&&(c=a))}let k;if(b.urlAddress===(null===(e=c)||void 0===e?void 0:e.urlAddress))k=c.timestamps[c.timestamps.length-2];else{var l,m,n;k=null!==(l=null===(m=c)||void 0===m?void 0:m.timestamps[(null===(n=c)||void 0===n?void 0:n.timestamps.length)-1])&&void 0!==l?l:0}f&&f>k&&(c=a)}),c}}exports.PreviousPage=PreviousPage;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreviousPage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");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 PreviousPage{constructor(a){let{matchType:b,url:c}=a;_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"matchType",void 0),this.conditionValue=c,this.matchType=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];if(!c)return(0,_tsRes.Ok)(!1);const d=this.getSecondLatestPageView(Object.values(c));if(!d)return(0,_tsRes.Ok)(!1);const e=d.urlAddress;return(0,_tsRes.Ok)(this.checkCondition(e))}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(this.conditionValue).test(a);default:return!1}}getSecondLatestPageView(a){if(2>a.length)return;let b,c;return a.forEach(a=>{const d=a.timestamps[a.timestamps.length-1];if(!b)return void(b=a);const e=b.timestamps[b.timestamps.length-1];if(d>e)return c=b,void(b=a);const f=c?c.timestamps[c.timestamps.length-1]:0;d>f&&(c=a)}),c}}exports.PreviousPage=PreviousPage;
//# sourceMappingURL=previousPage.js.map

@@ -108,7 +108,7 @@ import { ConfigurationDataType, JSONType } from './clientConfiguration/types';

/**
* @type FeatureVariableResultType - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
* @type `FeatureVariableResultType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
* */
export type FeatureVariableResultType = BooleanVariableType | NumberVariableType | StringVariableType | JSONVariableType;
/**
* @type FeatureFlagVariableType - tuple of possible feature variable result types, each possible variation is an object containing `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
* @type `FeatureFlagVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
* */

@@ -153,2 +153,7 @@ export type FeatureFlagVariableType = Omit<FeatureVariableResultType, 'key'>;

};
export type GetFeatureVariablesParamsType = {
visitorCode: string;
featureKey: string;
variationKey: string;
};
export type FeatureFlagType = {

@@ -159,2 +164,19 @@ id: number;

/**
* @type `KameleoonVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.
* */
export type KameleoonVariableType = FeatureVariableResultType;
/**
* @type `KameleoonVariationType` - object containing information about the variation and its variables
* @param {string} key - key of the variation
* @param {number | null} id - id of the variation or `null` if the visitor hit default variation
* @param {number | null} experimentId - id of the experiment or `null` if the visitor hit default variation
* @param {KameleoonVariableType[]} variables - array of variables for the variation
* */
export type KameleoonVariationType = {
key: string;
id: number | null;
experimentId: number | null;
variables: KameleoonVariableType[];
};
/**
* @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters

@@ -161,0 +183,0 @@ * @param {string} featureKey - key of the feature flag to look for, can be found on Kameleoon Platform

{
"name": "@kameleoon/javascript-sdk-core",
"version": "4.1.0",
"version": "4.2.0",
"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

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