@kameleoon/javascript-sdk-core
Advanced tools
Comparing version 4.2.0 to 4.3.0
# Change Log | ||
## 4.3.0 (2024-05-24) | ||
### Features | ||
- Added new [`onEvent`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#onevent) method to handle SDK events with a callback. | ||
- Method [`onConfigurationUpdate`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#onConfigurationUpdate) is now marked as `deprecated` and will be removed in the next major release. Use [`onEvent(EventType.ConfigurationUpdate, callback)`](https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#onevent) instead. | ||
- Added support of range match type for numeric Custom Data values. | ||
## 4.2.0 (2024-05-07) | ||
@@ -4,0 +12,0 @@ |
@@ -7,3 +7,2 @@ import { Result } from 'ts-res'; | ||
initialize: (useCache?: boolean) => Promise<Result<void, KameleoonError>>; | ||
onConfigurationUpdate: (callback: () => void) => void; | ||
readonly featureFlags: Map<string, FeatureFlagType>; | ||
@@ -15,3 +14,2 @@ readonly configuration: ConfigurationType; | ||
export declare class ClientConfiguration implements IClientConfiguration { | ||
private configurationUpdateCallback?; | ||
private updateConfigurationIntervalId; | ||
@@ -33,3 +31,4 @@ private updateType; | ||
private visitorCodeManager; | ||
constructor({ settings, storage, requester, dataManager, externalClientConfiguration, offlineTrackingStorage, eventSource, externalVisitorCodeManager, }: ClientConfigurationParametersType); | ||
private eventManager; | ||
constructor({ settings, storage, requester, dataManager, externalClientConfiguration, offlineTrackingStorage, eventSource, externalVisitorCodeManager, eventManager, }: ClientConfigurationParametersType); | ||
initialize(): Promise<Result<void, KameleoonError>>; | ||
@@ -40,3 +39,2 @@ private cleanupHandlers; | ||
private handlePollingUpdates; | ||
onConfigurationUpdate(callback: () => void): void; | ||
get featureFlags(): Map<string, FeatureFlagType>; | ||
@@ -43,0 +41,0 @@ get configuration(): ConfigurationType; |
@@ -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 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; | ||
"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"),_eventManager=require("../eventManager"),_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,eventManager:j}=a;_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),_defineProperty(this,"eventManager",void 0),this.requester=d,this.settings=b,this.lastUpdate=new Date,this.storage=c,this.dataManager=e,this.eventManager=j,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(b=>{b.ok&&this.eventManager.fireEvent(_eventManager.EventType.ConfigurationUpdate,{timestamp:a})})};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}}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 |
@@ -9,2 +9,3 @@ import { ClientSettingsType } from '../clientSettings'; | ||
import { VariableType } from '../types'; | ||
import { EventManager } from '../eventManager'; | ||
export type ScheduleType = { | ||
@@ -117,2 +118,3 @@ dateStart: string; | ||
eventSource: IEventSource; | ||
eventManager: EventManager; | ||
offlineTrackingStorage: IStorage<OfflineTracking>; | ||
@@ -119,0 +121,0 @@ externalClientConfiguration?: ConfigurationDataType; |
@@ -8,2 +8,3 @@ export { Ok, Result, Err } from 'ts-res'; | ||
export { FeatureFlagVariationsType, KameleoonStorageKey, StorageDataType, IExternalStorage, } from './storage'; | ||
export { EventCallbackType, EventDataType, EventType, EvaluationEventDataType, ConfigurationUpdateEventDataType, } from './eventManager'; | ||
export { VisitorCodeManager, IVisitorCodeManager } from './visitorCodeManager'; | ||
@@ -10,0 +11,0 @@ export { VISITOR_CODE_LENGTH, SdkLanguageType } from './constants'; |
@@ -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,"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"); | ||
"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,"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,"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,"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"),_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 |
import { JSONType } from './clientConfiguration'; | ||
import { CustomData, KameleoonDataType } from './kameleoonData'; | ||
import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType, KameleoonVariationType } from './types'; | ||
import { EventCallbackType, EventType } from './eventManager'; | ||
import { IKameleoonClient } from './kameleoonClientInterface'; | ||
@@ -19,6 +20,7 @@ /** | ||
private externalPackageInfo; | ||
private isOfflineModeOn?; | ||
private initialized; | ||
private visitorCodeManager; | ||
private eventManager; | ||
private environment?; | ||
private visitorCodeManager; | ||
private isOfflineModeOn?; | ||
/** | ||
@@ -42,3 +44,9 @@ * @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core | ||
getVisitorWarehouseAudience({ visitorCode, customDataIndex, warehouseKey, }: GetVisitorWarehouseAudienceParamsType): Promise<CustomData | null>; | ||
/** | ||
* @deprecated | ||
* use `onEvent(EventType.ConfigurationUpdate, callback)` instead | ||
* Will be removed in the next major release | ||
* */ | ||
onConfigurationUpdate(callback: () => void): void; | ||
onEvent<E extends EventType>(event: E, callback: EventCallbackType<E>): void; | ||
getEngineTrackingCode(visitorCode: string): string; | ||
@@ -45,0 +53,0 @@ isInitialized(): boolean; |
@@ -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);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; | ||
"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"),_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,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 _eventManager.EventManager,v=new _clientConfiguration.ClientConfiguration({settings:e,storage:m,dataManager:r,eventManager:u,requester:t,externalClientConfiguration:k,offlineTrackingStorage:p,eventSource:s,externalVisitorCodeManager:i}),w=new _variationConfiguration.VariationConfiguration(o);this.variationConfiguration=w,this.requester=t,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);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||_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();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; | ||
//# sourceMappingURL=kameleoonClient.js.map |
import { JSONType } from './clientConfiguration'; | ||
import { EventCallbackType, EventType } from './eventManager'; | ||
import { CustomData, KameleoonDataType } from './kameleoonData'; | ||
@@ -10,2 +11,5 @@ import { FeatureFlagType, FeatureFlagVariableType, FeatureVariableResultType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, KameleoonVariationType, RemoteVisitorDataParamsType, TrackConversionParamsType } from './types'; | ||
* @method initialize - an asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached | ||
* | ||
* Triggered Events: `EventType.ConfigurationUpdate` (On each successful configuration update while using Real Time Update) | ||
* | ||
* @param {boolean | undefined} useCache - optional parameter for activating SDK offline mode, if `true` is passed failed polls will not return error and will use cached data if such data is available, default value is `false`. Note: if offline mode is on, SDK will still try to retrieve the latest data. | ||
@@ -88,2 +92,3 @@ * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail | ||
* Note: This method **doesn't send** tracking data | ||
* Triggered Events: `EventType.Evaluation` (For each feature flag evaluated) | ||
* | ||
@@ -105,2 +110,3 @@ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length | ||
* Note: This method **doesn't send** tracking data | ||
* Triggered Events: `EventType.Evaluation` (For each feature flag evaluated) | ||
* | ||
@@ -123,2 +129,3 @@ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length | ||
* Note: This method **sends** tracking data | ||
* Triggered Events: `EventType.Evaluation` | ||
* | ||
@@ -142,2 +149,3 @@ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length | ||
* Note: This method **sends** tracking data | ||
* Triggered Events: `EventType.Evaluation` | ||
* | ||
@@ -161,2 +169,3 @@ * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length | ||
* Note: This method **sends** tracking data | ||
* Triggered Events: `EventType.Evaluation` | ||
* | ||
@@ -182,2 +191,3 @@ * @param {GetFeatureFlagVariableParamsType} parameters - an object with parameters of a type `GetFeatureFlagVariableParamsType`, see the type for details. | ||
* Note: This method **sends** tracking data | ||
* Triggered Events: `EventType.Evaluation` | ||
* | ||
@@ -241,2 +251,18 @@ * @param {string} visitorCode - a unique visitor identifier, shouldn't exceed 255 characters | ||
onConfigurationUpdate: (callback: () => void) => void; | ||
/** | ||
* @method onEvent - fires a callback on a specified Kameleoon `EventType`. Each event can only have one according callback. | ||
* | ||
* Note: SDK methods are marked with the `EventType` they trigger if any. | ||
* | ||
* @param {EventCallbackType<EventType>} callback - callback function with parameters that will be called upon event | ||
* | ||
* Parameter type depends on the `EventType` passed: | ||
* - `EventType.Evaluation` - `EvaluationEventDataType` | ||
* - `EventType.ConfigurationUpdate` - `ConfigurationUpdateEventDataType` | ||
* @returns {void} | ||
* @throws `KameleoonError` with one of the following `type` s: | ||
* | ||
* - `KameleoonException.Initialization` - Method was executed before the `kameleoonClient` completed it's `initialize` call | ||
*/ | ||
onEvent: (event: EventType, callback: EventCallbackType<EventType>) => void; | ||
} |
@@ -28,4 +28,5 @@ import { KameleoonStorageKey } from '../storage'; | ||
AmongValuesCheck: (err: unknown, value: string) => string; | ||
RangeCheck: (value?: number[] | null) => string; | ||
RemoteData: () => string; | ||
MaximumRetriesReached: () => string; | ||
}; |
@@ -1,2 +0,2 @@ | ||
"use strict";var _types=require("./types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.ERROR_MESSAGES=void 0;const ERROR_MESSAGES=exports.ERROR_MESSAGES={[_types.KameleoonException.CookieParse]:a=>"Couldn't parse cookie string: ".concat(a),[_types.KameleoonException.JSONParse]:a=>"Couldn't parse JSON variable: ".concat(a),[_types.KameleoonException.NumberParse]:a=>"It's not possible to parse value ".concat(a," to Number"),[_types.KameleoonException.VersionParse]:a=>"It's not possible to parse a version value ".concat(a," to Number, version should be in format x.x"),[_types.KameleoonException.SemanticVersionParse]:a=>"It's not possible to parse a version value ".concat(a," to Number, version should be in format x.x.x"),[_types.KameleoonException.Initialization]:()=>"It seems that the client wasn't properly initialized, make sure to run `initialize` method before invoking other methods",[_types.KameleoonException.Credentials]:()=>"KameleoonClient can not be created without credentials",[_types.KameleoonException.StorageInitialization]:()=>"There was an error while initializing React Native SDK storage, it seems that the storage library dependency wasn't installed",[_types.KameleoonException.EventSourceInitialization]:()=>"There was an error while initializing Real Time Update service, it seems that the event source library dependency wasn't installed",[_types.KameleoonException.FeatureFlagConfigurationNotFound]:a=>"No feature flag with key ".concat(a," was found."),[_types.KameleoonException.FeatureFlagEnvironmentDisabled]:(a,b)=>"Feature flag with key ".concat(a," is disabled in ").concat(b," environment."),[_types.KameleoonException.FeatureFlagVariableNotFound]:(a,b)=>"No feature flag variable with key ".concat(a," was found for ").concat(b," visitorCode."),[_types.KameleoonException.FeatureFlagVariationNotFound]:(a,b)=>"No feature flag variation with key ".concat(a," was found for ").concat(b," visitorCode."),[_types.KameleoonException.NotTargeted]:a=>"Visitor code ".concat(a," is not targeted"),[_types.KameleoonException.VisitAmount]:()=>"Visit amount must be a number between 1 and 25",[_types.KameleoonException.VisitorCodeMaxLength]:()=>"Visitor code can not be more than 255 characters long",[_types.KameleoonException.VisitorCodeEmpty]:()=>"Visitor code can not be empty",[_types.KameleoonException.StorageWrite]:a=>"Couldn't update storage for kameleoonClient: ".concat(a),[_types.KameleoonException.StorageRead]:a=>"No data found in storage under ".concat(a," key"),[_types.KameleoonException.StorageEmpty]:()=>"No data found in storage",[_types.KameleoonException.StorageParse]:(a,b)=>"Couldn't parse ".concat(b," storage data, the data may be corrupted. Error: ").concat(a),[_types.KameleoonException.ClientConfiguration]:()=>"Couldn't retrieve client configuration from Kameleoon Api",[_types.KameleoonException.TargetingCondition]:a=>"".concat(a," targeting condition is not yet supported."),[_types.KameleoonException.AmongValuesCheck]:(a,b)=>"Couldn't parse value \"".concat(b,"\": ").concat(a),[_types.KameleoonException.RemoteData]:()=>"Couldn't retrieve data from Kameleoon server",[_types.KameleoonException.MaximumRetriesReached]:()=>"Maximum retries reached, request failed"}; | ||
"use strict";var _types=require("./types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.ERROR_MESSAGES=void 0;const ERROR_MESSAGES=exports.ERROR_MESSAGES={[_types.KameleoonException.CookieParse]:a=>"Couldn't parse cookie string: ".concat(a),[_types.KameleoonException.JSONParse]:a=>"Couldn't parse JSON variable: ".concat(a),[_types.KameleoonException.NumberParse]:a=>"It's not possible to parse value ".concat(a," to Number"),[_types.KameleoonException.VersionParse]:a=>"It's not possible to parse a version value ".concat(a," to Number, version should be in format x.x"),[_types.KameleoonException.SemanticVersionParse]:a=>"It's not possible to parse a version value ".concat(a," to Number, version should be in format x.x.x"),[_types.KameleoonException.Initialization]:()=>"It seems that the client wasn't properly initialized, make sure to run `initialize` method before invoking other methods",[_types.KameleoonException.Credentials]:()=>"KameleoonClient can not be created without credentials",[_types.KameleoonException.StorageInitialization]:()=>"There was an error while initializing React Native SDK storage, it seems that the storage library dependency wasn't installed",[_types.KameleoonException.EventSourceInitialization]:()=>"There was an error while initializing Real Time Update service, it seems that the event source library dependency wasn't installed",[_types.KameleoonException.FeatureFlagConfigurationNotFound]:a=>"No feature flag with key ".concat(a," was found."),[_types.KameleoonException.FeatureFlagEnvironmentDisabled]:(a,b)=>"Feature flag with key ".concat(a," is disabled in ").concat(b," environment."),[_types.KameleoonException.FeatureFlagVariableNotFound]:(a,b)=>"No feature flag variable with key ".concat(a," was found for ").concat(b," visitorCode."),[_types.KameleoonException.FeatureFlagVariationNotFound]:(a,b)=>"No feature flag variation with key ".concat(a," was found for ").concat(b," visitorCode."),[_types.KameleoonException.NotTargeted]:a=>"Visitor code ".concat(a," is not targeted"),[_types.KameleoonException.VisitAmount]:()=>"Visit amount must be a number between 1 and 25",[_types.KameleoonException.VisitorCodeMaxLength]:()=>"Visitor code can not be more than 255 characters long",[_types.KameleoonException.VisitorCodeEmpty]:()=>"Visitor code can not be empty",[_types.KameleoonException.StorageWrite]:a=>"Couldn't update storage for kameleoonClient: ".concat(a),[_types.KameleoonException.StorageRead]:a=>"No data found in storage under ".concat(a," key"),[_types.KameleoonException.StorageEmpty]:()=>"No data found in storage",[_types.KameleoonException.StorageParse]:(a,b)=>"Couldn't parse ".concat(b," storage data, the data may be corrupted. Error: ").concat(a),[_types.KameleoonException.ClientConfiguration]:()=>"Couldn't retrieve client configuration from Kameleoon Api",[_types.KameleoonException.TargetingCondition]:a=>"".concat(a," targeting condition is not yet supported."),[_types.KameleoonException.AmongValuesCheck]:(a,b)=>"Couldn't parse value \"".concat(b,"\": ").concat(a),[_types.KameleoonException.RangeCheck]:a=>"Couldn't parse value \"".concat(a,"\" as a range, value should be in format [x: number, y: number]"),[_types.KameleoonException.RemoteData]:()=>"Couldn't retrieve data from Kameleoon server",[_types.KameleoonException.MaximumRetriesReached]:()=>"Maximum retries reached, request failed"}; | ||
//# sourceMappingURL=constants.js.map |
@@ -25,4 +25,5 @@ import { KameleoonStorageKey } from '../storage'; | ||
constructor(type: KameleoonException.AmongValuesCheck, err: unknown, value: string); | ||
constructor(type: KameleoonException.RangeCheck, value?: number[] | null); | ||
constructor(type: KameleoonException.NumberParse | KameleoonException.VersionParse | KameleoonException.SemanticVersionParse, value: string); | ||
get type(): KameleoonException; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonError=void 0;var _constants=require("./constants"),_helpers=require("./helpers"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class KameleoonError extends Error{constructor(a,b,c){super("Error: ".concat(a)),_defineProperty(this,"errorType",void 0),this.name="KameleoonError",this.errorType=a;a===_types.KameleoonException.Initialization||a===_types.KameleoonException.Credentials||a===_types.KameleoonException.ClientConfiguration||a===_types.KameleoonException.VisitorCodeMaxLength||a===_types.KameleoonException.VisitorCodeEmpty||a===_types.KameleoonException.StorageInitialization||a===_types.KameleoonException.VisitAmount||a===_types.KameleoonException.EventSourceInitialization||a===_types.KameleoonException.RemoteData||a===_types.KameleoonException.MaximumRetriesReached||a===_types.KameleoonException.StorageEmpty?this.message=_constants.ERROR_MESSAGES[a]():a===_types.KameleoonException.CookieParse||a===_types.KameleoonException.NotTargeted||a===_types.KameleoonException.FeatureFlagConfigurationNotFound||a===_types.KameleoonException.NumberParse||a===_types.KameleoonException.VersionParse||a===_types.KameleoonException.SemanticVersionParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.FeatureFlagVariationNotFound||a===_types.KameleoonException.FeatureFlagEnvironmentDisabled||a===_types.KameleoonException.FeatureFlagVariableNotFound?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.StorageWrite||a===_types.KameleoonException.JSONParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageRead?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageParse?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.TargetingCondition?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.AmongValuesCheck?this.message=_constants.ERROR_MESSAGES[a](b,c):(0,_helpers.exhaustCheck)(a)}get type(){return this.errorType}}exports.KameleoonError=KameleoonError; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonError=void 0;var _constants=require("./constants"),_helpers=require("./helpers"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class KameleoonError extends Error{constructor(a,b,c){super("Error: ".concat(a)),_defineProperty(this,"errorType",void 0),this.name="KameleoonError",this.errorType=a;a===_types.KameleoonException.Initialization||a===_types.KameleoonException.Credentials||a===_types.KameleoonException.ClientConfiguration||a===_types.KameleoonException.VisitorCodeMaxLength||a===_types.KameleoonException.VisitorCodeEmpty||a===_types.KameleoonException.StorageInitialization||a===_types.KameleoonException.VisitAmount||a===_types.KameleoonException.EventSourceInitialization||a===_types.KameleoonException.RemoteData||a===_types.KameleoonException.MaximumRetriesReached||a===_types.KameleoonException.StorageEmpty?this.message=_constants.ERROR_MESSAGES[a]():a===_types.KameleoonException.CookieParse||a===_types.KameleoonException.NotTargeted||a===_types.KameleoonException.FeatureFlagConfigurationNotFound||a===_types.KameleoonException.NumberParse||a===_types.KameleoonException.VersionParse||a===_types.KameleoonException.SemanticVersionParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.FeatureFlagVariationNotFound||a===_types.KameleoonException.FeatureFlagEnvironmentDisabled||a===_types.KameleoonException.FeatureFlagVariableNotFound?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.StorageWrite||a===_types.KameleoonException.JSONParse?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageRead?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.StorageParse?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.TargetingCondition?this.message=_constants.ERROR_MESSAGES[a](b):a===_types.KameleoonException.AmongValuesCheck?this.message=_constants.ERROR_MESSAGES[a](b,c):a===_types.KameleoonException.RangeCheck?this.message=_constants.ERROR_MESSAGES[a](b):(0,_helpers.exhaustCheck)(a)}get type(){return this.errorType}}exports.KameleoonError=KameleoonError; | ||
//# sourceMappingURL=kameleoonError.js.map |
@@ -24,2 +24,3 @@ /** | ||
AmongValuesCheck = "AmongValuesCheck", | ||
RangeCheck = "RangeCheck", | ||
Initialization = "Initialization", | ||
@@ -26,0 +27,0 @@ JSONParse = "JSONParse", |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonException=void 0;let KameleoonException=exports.KameleoonException=function(a){return a.Credentials="Credentials",a.EventSourceInitialization="EventSourceInitialization",a.FeatureFlagConfigurationNotFound="FeatureFlagConfigurationNotFound",a.FeatureFlagVariableNotFound="FeatureFlagVariableNotFound",a.FeatureFlagVariationNotFound="FeatureFlagVariationNotFound",a.FeatureFlagEnvironmentDisabled="FeatureFlagEnvironmentDisabled",a.NotTargeted="NotTargeted",a.VisitAmount="VisitAmount",a.VisitorCodeMaxLength="VisitorCodeMaxLength",a.VisitorCodeEmpty="VisitorCodeEmpty",a.StorageInitialization="StorageInitialization",a.StorageWrite="StorageWrite",a.StorageRead="StorageRead",a.StorageParse="StorageParse",a.StorageEmpty="StorageEmpty",a.ClientConfiguration="ClientConfiguration",a.TargetingCondition="TargetingCondition",a.AmongValuesCheck="AmongValuesCheck",a.Initialization="Initialization",a.JSONParse="JSONParse",a.NumberParse="NumberParse",a.VersionParse="VersionParse",a.CookieParse="CookieParse",a.SemanticVersionParse="SemanticVersionParse",a.RemoteData="RemoteData",a.MaximumRetriesReached="MaximumRetriesReached",a}({}); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonException=void 0;let KameleoonException=exports.KameleoonException=function(a){return a.Credentials="Credentials",a.EventSourceInitialization="EventSourceInitialization",a.FeatureFlagConfigurationNotFound="FeatureFlagConfigurationNotFound",a.FeatureFlagVariableNotFound="FeatureFlagVariableNotFound",a.FeatureFlagVariationNotFound="FeatureFlagVariationNotFound",a.FeatureFlagEnvironmentDisabled="FeatureFlagEnvironmentDisabled",a.NotTargeted="NotTargeted",a.VisitAmount="VisitAmount",a.VisitorCodeMaxLength="VisitorCodeMaxLength",a.VisitorCodeEmpty="VisitorCodeEmpty",a.StorageInitialization="StorageInitialization",a.StorageWrite="StorageWrite",a.StorageRead="StorageRead",a.StorageParse="StorageParse",a.StorageEmpty="StorageEmpty",a.ClientConfiguration="ClientConfiguration",a.TargetingCondition="TargetingCondition",a.AmongValuesCheck="AmongValuesCheck",a.RangeCheck="RangeCheck",a.Initialization="Initialization",a.JSONParse="JSONParse",a.NumberParse="NumberParse",a.VersionParse="VersionParse",a.CookieParse="CookieParse",a.SemanticVersionParse="SemanticVersionParse",a.RemoteData="RemoteData",a.MaximumRetriesReached="MaximumRetriesReached",a}({}); | ||
//# sourceMappingURL=types.js.map |
import { Result } from 'ts-res'; | ||
import { KameleoonError } from '../../kameleoonError'; | ||
import { EvaluationDataType } from '../../targeting/types'; | ||
import { EvaluationDataType } from '../../targeting'; | ||
import { ConditionDataType, ICondition } from './types'; | ||
@@ -10,6 +10,8 @@ export declare class CustomData implements ICondition { | ||
private error?; | ||
constructor({ customDataIndex, valueMatchType, value }: ConditionDataType); | ||
private range?; | ||
constructor({ customDataIndex, valueMatchType, value, range, }: ConditionDataType); | ||
evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>; | ||
private checkCondition; | ||
private parseArray; | ||
private parseRange; | ||
} |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_utilities=require("../../utilities"),_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 CustomData{constructor(a){let{customDataIndex:b,valueMatchType:c,value:d}=a;_defineProperty(this,"customDataIndex",void 0),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"error",void 0),this.customDataIndex=b?+b:null,this.matchType=c,this.conditionValue=d}evaluate(a){let{targetingData:b}=a;if("number"==typeof this.customDataIndex){var c;const a=null===b||void 0===b||null===(c=b[_kameleoonData.KameleoonData.CustomData])||void 0===c?void 0:c[this.customDataIndex];if(a){const{value:b}=a,c=this.checkCondition(b);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(c)}}return(0,_tsRes.Ok)(this.matchType===_types.ValueMatchType.UNDEFINED)}checkCondition(a){if("string"!=typeof this.conditionValue&&this.matchType!==_types.ValueMatchType.TRUE&&this.matchType!==_types.ValueMatchType.FALSE)return!1;const b=this.conditionValue;if(this.matchType===_types.ValueMatchType.AMONG_VALUES){const c=this.parseArray(b);if(!c.ok)return this.error=c.error,!1;const d=new Set(c.data);return Array.isArray(a)?a.some(a=>d.has(a)):c.data.includes(a)}if(Array.isArray(a))return a.some(a=>this.checkCondition(a));switch(this.matchType){case _types.ValueMatchType.CONTAINS:return a.includes(b);case _types.ValueMatchType.EXACT:return a===this.conditionValue;case _types.ValueMatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(b).test(a);case _types.ValueMatchType.LOWER:return+a<+this.conditionValue;case _types.ValueMatchType.EQUAL:return+a===+this.conditionValue;case _types.ValueMatchType.GREATER:return+a>+this.conditionValue;case _types.ValueMatchType.TRUE:return"true"===a.toLowerCase();case _types.ValueMatchType.FALSE:return"false"===a.toLowerCase();default:return!1}}parseArray(a){try{const b=JSON.parse(a);if(Array.isArray(b))return(0,_tsRes.Ok)(b)}catch(b){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.AmongValuesCheck,b,a))}return(0,_tsRes.Ok)([])}}exports.CustomData=CustomData; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_=require("./.."),_utilities=require("../../utilities");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 CustomData{constructor(a){let{customDataIndex:b,valueMatchType:c,value:d,range:e}=a;_defineProperty(this,"customDataIndex",void 0),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"error",void 0),_defineProperty(this,"range",void 0),this.customDataIndex=b?+b:null,this.matchType=c,this.conditionValue=d,this.range=e}evaluate(a){let{targetingData:b}=a;if("number"==typeof this.customDataIndex){var c;const a=null===b||void 0===b||null===(c=b[_kameleoonData.KameleoonData.CustomData])||void 0===c?void 0:c[this.customDataIndex];if(a){const{value:b}=a,c=this.checkCondition(b);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(c)}}return(0,_tsRes.Ok)(this.matchType===_.ValueMatchType.UNDEFINED)}checkCondition(a){if("string"!=typeof this.conditionValue&&this.matchType!==_.ValueMatchType.TRUE&&this.matchType!==_.ValueMatchType.FALSE&&this.matchType!==_.ValueMatchType.RANGE)return!1;const b=this.conditionValue;if(this.matchType===_.ValueMatchType.AMONG_VALUES){const c=this.parseArray(b);if(!c.ok)return this.error=c.error,!1;const d=new Set(c.data);return Array.isArray(a)?a.some(a=>d.has(a)):c.data.includes(a)}if(this.matchType===_.ValueMatchType.RANGE){const b=this.parseRange(this.range);if(!b.ok)return this.error=b.error,!1;const[c,d]=b.data,e=a=>a>=c&&a<=d;return Array.isArray(a)?a.some(a=>e(+a)):e(+a)}if(Array.isArray(a))return a.some(a=>this.checkCondition(a));switch(this.matchType){case _.ValueMatchType.CONTAINS:return a.includes(b);case _.ValueMatchType.EXACT:return a===this.conditionValue;case _.ValueMatchType.REGULAR_EXPRESSION:return _utilities.Utilities.parseRegExp(b).test(a);case _.ValueMatchType.LOWER:return+a<+this.conditionValue;case _.ValueMatchType.EQUAL:return+a===+this.conditionValue;case _.ValueMatchType.GREATER:return+a>+this.conditionValue;case _.ValueMatchType.TRUE:return"true"===a.toLowerCase();case _.ValueMatchType.FALSE:return"false"===a.toLowerCase();default:return!1}}parseArray(a){try{const b=JSON.parse(a);if(Array.isArray(b))return(0,_tsRes.Ok)(b)}catch(b){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.AmongValuesCheck,b,a))}return(0,_tsRes.Ok)([])}parseRange(a){return a&&2===a.length?(0,_tsRes.Ok)(a):(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RangeCheck,a))}}exports.CustomData=CustomData; | ||
//# sourceMappingURL=customData.js.map |
@@ -49,2 +49,3 @@ import { Result } from 'ts-res'; | ||
visitorCode?: string | null; | ||
range?: number[] | null; | ||
lowerBound?: number; | ||
@@ -51,0 +52,0 @@ upperBound?: number; |
@@ -70,3 +70,4 @@ import { MappedRuleType } from '../clientConfiguration/types'; | ||
UNDEFINED = "UNDEFINED", | ||
AMONG_VALUES = "AMONG_VALUES" | ||
AMONG_VALUES = "AMONG_VALUES", | ||
RANGE = "RANGE" | ||
} | ||
@@ -73,0 +74,0 @@ export declare enum VisitorType { |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorType=exports.VersionMatchType=exports.ValueMatchType=exports.TargetingType=exports.Operator=exports.NameMatchType=exports.MatchTypeVariation=exports.MatchTypeTest=exports.MatchType=void 0;let Operator=exports.Operator=function(a){return a.And="AND",a.Or="OR",a}({}),ValueMatchType=exports.ValueMatchType=function(a){return a.TRUE="TRUE",a.FALSE="FALSE",a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.EQUAL="EQUAL",a.LOWER="LOWER",a.GREATER="GREATER",a.UNDEFINED="UNDEFINED",a.AMONG_VALUES="AMONG_VALUES",a}({}),VisitorType=exports.VisitorType=function(a){return a.NEW="NEW",a.RETURNING="RETURNING",a}({}),MatchTypeVariation=exports.MatchTypeVariation=function(a){return a.ANY="ANY",a.EXACT="EXACT",a}({}),MatchTypeTest=exports.MatchTypeTest=function(a){return a.ALL="ALL",a.TEST="TEST",a.PERSO="PERSO",a}({}),MatchType=exports.MatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),VersionMatchType=exports.VersionMatchType=function(a){return a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),NameMatchType=exports.NameMatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.OPTIONAL="OPTIONAL",a}({}),TargetingType=exports.TargetingType=function(a){return a.PAGE_URL="PAGE_URL",a.PAGE_TITLE="PAGE_TITLE",a.LANDING_PAGE="LANDING_PAGE",a.ORIGIN="ORIGIN",a.ORIGIN_TYPE="ORIGIN_TYPE",a.REFERRERS="REFERRERS",a.NEW_VISITORS="NEW_VISITORS",a.INTERESTS="INTERESTS",a.BROWSER_LANGUAGE="BROWSER_LANGUAGE",a.GEOLOCATION="GEOLOCATION",a.DEVICE_TYPE="DEVICE_TYPE",a.SCREEN_DIMENSION="SCREEN_DIMENSION",a.VISITOR_IP="VISITOR_IP",a.AD_BLOCKER="AD_BLOCKER",a.PREVIOUS_PAGE="PREVIOUS_PAGE",a.KEY_PAGES="KEY_PAGES",a.PAGE_VIEWS="PAGE_VIEWS",a.FIRST_VISIT="FIRST_VISIT",a.LAST_VISIT="LAST_VISIT",a.ACTIVE_SESSION="ACTIVE_SESSION",a.TIME_SINCE_PAGE_LOAD="TIME_SINCE_PAGE_LOAD",a.SAME_DAY_VISITS="SAME_DAY_VISITS",a.VISITS="VISITS",a.VISITS_BY_PAGE="VISITS_BY_PAGE",a.VISITOR_CODE="VISITOR_CODE",a.SDK_LANGUAGE="SDK_LANGUAGE",a.INTERNAL_SEARCH_KEYWORDS="INTERNAL_SEARCH_KEYWORDS",a.TABS_ON_SITE="TABS_ON_SITE",a.CONVERSION_PROBABILITY="CONVERSION_PROBABILITY",a.HEAT_SLICE="HEAT_SLICE",a.SKY_STATUS="SKY_STATUS",a.TEMPERATURE="TEMPERATURE",a.DAY_NIGHT="DAY_NIGHT",a.FORECAST_SKY_STATUS="FORECAST_SKY_STATUS",a.FORECAST_TEMPERATURE="FORECAST_TEMPERATURE",a.DAY_OF_WEEK="DAY_OF_WEEK",a.TIME_RANGE="TIME_RANGE",a.HOUR_MINUTE_RANGE="HOUR_MINUTE_RANGE",a.JS_CODE="JS_CODE",a.COOKIE="COOKIE",a.EVENT="EVENT",a.BROWSER="BROWSER",a.OPERATING_SYSTEM="OPERATING_SYSTEM",a.DOM_ELEMENT="DOM_ELEMENT",a.MOUSE_OUT="MOUSE_OUT",a.TARGET_EXPERIMENT="TARGET_EXPERIMENT",a.TARGET_FEATURE_FLAG="TARGET_FEATURE_FLAG",a.TARGET_PERSONALIZATION="TARGET_PERSONALIZATION",a.EXCLUSIVE_EXPERIMENT="EXCLUSIVE_EXPERIMENT",a.EXCLUSIVE_FEATURE_FLAG="EXCLUSIVE_FEATURE_FLAG",a.CONVERSIONS="CONVERSIONS",a.CUSTOM_DATUM="CUSTOM_DATUM",a.YSANCE_SEGMENT="YSANCE_SEGMENT",a.SEGMENT="SEGMENT",a.YSANCE_ATTRIBUT="YSANCE_ATTRIBUT",a.TEALIUM_BADGE="TEALIUM_BADGE",a.TEALIUM_AUDIENCE="TEALIUM_AUDIENCE",a.PRICE_OF_DISPLAYED_PAGE="PRICE_OF_DISPLAYED_PAGE",a.NUMBER_OF_VISITED_PAGES="NUMBER_OF_VISITED_PAGES",a.VISITED_PAGES="VISITED_PAGES",a.CUSTOM="CUSTOM",a.EXPLICIT_TRIGGER="EXPLICIT_TRIGGER",a.APPLICATION_VERSION="APPLICATION_VERSION",a}({}); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorType=exports.VersionMatchType=exports.ValueMatchType=exports.TargetingType=exports.Operator=exports.NameMatchType=exports.MatchTypeVariation=exports.MatchTypeTest=exports.MatchType=void 0;let Operator=exports.Operator=function(a){return a.And="AND",a.Or="OR",a}({}),ValueMatchType=exports.ValueMatchType=function(a){return a.TRUE="TRUE",a.FALSE="FALSE",a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.EQUAL="EQUAL",a.LOWER="LOWER",a.GREATER="GREATER",a.UNDEFINED="UNDEFINED",a.AMONG_VALUES="AMONG_VALUES",a.RANGE="RANGE",a}({}),VisitorType=exports.VisitorType=function(a){return a.NEW="NEW",a.RETURNING="RETURNING",a}({}),MatchTypeVariation=exports.MatchTypeVariation=function(a){return a.ANY="ANY",a.EXACT="EXACT",a}({}),MatchTypeTest=exports.MatchTypeTest=function(a){return a.ALL="ALL",a.TEST="TEST",a.PERSO="PERSO",a}({}),MatchType=exports.MatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),VersionMatchType=exports.VersionMatchType=function(a){return a.GREATER="GREATER",a.EQUAL="EQUAL",a.LOWER="LOWER",a}({}),NameMatchType=exports.NameMatchType=function(a){return a.EXACT="EXACT",a.CONTAINS="CONTAINS",a.REGULAR_EXPRESSION="REGULAR_EXPRESSION",a.OPTIONAL="OPTIONAL",a}({}),TargetingType=exports.TargetingType=function(a){return a.PAGE_URL="PAGE_URL",a.PAGE_TITLE="PAGE_TITLE",a.LANDING_PAGE="LANDING_PAGE",a.ORIGIN="ORIGIN",a.ORIGIN_TYPE="ORIGIN_TYPE",a.REFERRERS="REFERRERS",a.NEW_VISITORS="NEW_VISITORS",a.INTERESTS="INTERESTS",a.BROWSER_LANGUAGE="BROWSER_LANGUAGE",a.GEOLOCATION="GEOLOCATION",a.DEVICE_TYPE="DEVICE_TYPE",a.SCREEN_DIMENSION="SCREEN_DIMENSION",a.VISITOR_IP="VISITOR_IP",a.AD_BLOCKER="AD_BLOCKER",a.PREVIOUS_PAGE="PREVIOUS_PAGE",a.KEY_PAGES="KEY_PAGES",a.PAGE_VIEWS="PAGE_VIEWS",a.FIRST_VISIT="FIRST_VISIT",a.LAST_VISIT="LAST_VISIT",a.ACTIVE_SESSION="ACTIVE_SESSION",a.TIME_SINCE_PAGE_LOAD="TIME_SINCE_PAGE_LOAD",a.SAME_DAY_VISITS="SAME_DAY_VISITS",a.VISITS="VISITS",a.VISITS_BY_PAGE="VISITS_BY_PAGE",a.VISITOR_CODE="VISITOR_CODE",a.SDK_LANGUAGE="SDK_LANGUAGE",a.INTERNAL_SEARCH_KEYWORDS="INTERNAL_SEARCH_KEYWORDS",a.TABS_ON_SITE="TABS_ON_SITE",a.CONVERSION_PROBABILITY="CONVERSION_PROBABILITY",a.HEAT_SLICE="HEAT_SLICE",a.SKY_STATUS="SKY_STATUS",a.TEMPERATURE="TEMPERATURE",a.DAY_NIGHT="DAY_NIGHT",a.FORECAST_SKY_STATUS="FORECAST_SKY_STATUS",a.FORECAST_TEMPERATURE="FORECAST_TEMPERATURE",a.DAY_OF_WEEK="DAY_OF_WEEK",a.TIME_RANGE="TIME_RANGE",a.HOUR_MINUTE_RANGE="HOUR_MINUTE_RANGE",a.JS_CODE="JS_CODE",a.COOKIE="COOKIE",a.EVENT="EVENT",a.BROWSER="BROWSER",a.OPERATING_SYSTEM="OPERATING_SYSTEM",a.DOM_ELEMENT="DOM_ELEMENT",a.MOUSE_OUT="MOUSE_OUT",a.TARGET_EXPERIMENT="TARGET_EXPERIMENT",a.TARGET_FEATURE_FLAG="TARGET_FEATURE_FLAG",a.TARGET_PERSONALIZATION="TARGET_PERSONALIZATION",a.EXCLUSIVE_EXPERIMENT="EXCLUSIVE_EXPERIMENT",a.EXCLUSIVE_FEATURE_FLAG="EXCLUSIVE_FEATURE_FLAG",a.CONVERSIONS="CONVERSIONS",a.CUSTOM_DATUM="CUSTOM_DATUM",a.YSANCE_SEGMENT="YSANCE_SEGMENT",a.SEGMENT="SEGMENT",a.YSANCE_ATTRIBUT="YSANCE_ATTRIBUT",a.TEALIUM_BADGE="TEALIUM_BADGE",a.TEALIUM_AUDIENCE="TEALIUM_AUDIENCE",a.PRICE_OF_DISPLAYED_PAGE="PRICE_OF_DISPLAYED_PAGE",a.NUMBER_OF_VISITED_PAGES="NUMBER_OF_VISITED_PAGES",a.VISITED_PAGES="VISITED_PAGES",a.CUSTOM="CUSTOM",a.EXPLICIT_TRIGGER="EXPLICIT_TRIGGER",a.APPLICATION_VERSION="APPLICATION_VERSION",a}({}); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@kameleoon/javascript-sdk-core", | ||
"version": "4.2.0", | ||
"version": "4.3.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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
843534
305
3756
74