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

@kameleoon/javascript-sdk-core

Package Overview
Dependencies
Maintainers
0
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 4.4.7 to 4.4.8

6

CHANGELOG.md
# Change Log
## 4.4.8 (2024-09-09)
### Patch Changes
- It's now possible to create several SDK instances with different site codes
## 4.4.7 (2024-08-30)

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

3

dist/clientConfiguration/clientConfiguration.d.ts

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

private eventManager;
constructor({ updateInterval, storage, requester, dataManager, externalClientConfiguration, offlineTrackingStorage, eventSource, externalVisitorCodeManager, eventManager, }: ClientConfigurationParametersType);
private urlProvider;
constructor({ updateInterval, urlProvider, storage, requester, dataManager, externalClientConfiguration, offlineTrackingStorage, eventSource, externalVisitorCodeManager, eventManager, }: ClientConfigurationParametersType);
initialize(): Promise<Result<void, KameleoonError>>;

@@ -33,0 +34,0 @@ private cleanupHandlers;

@@ -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"),_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{updateInterval: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,"updateInterval",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.updateInterval=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,featureFlags:c}=this.externalClientConfiguration;this.configurationData={customData:a,configuration:b};for(const a of c)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.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}get featureFlags(){return this.featureFlagsData}get configuration(){return this.configurationData.configuration}get segments(){if(this.segmentsData)return this.segmentsData;const a=new Map;return this.featureFlagsData.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),this.segmentsData=a,a}get ruleMap(){var a;if(null!==(a=this.mappedRules)&&void 0!==a&&a.size)return this.mappedRules;const b=new Map;for(const a of this.featureFlags.values())for(const c of a.rules){const{id:d,experimentId:e,variationByExposition:f}=c,g=new Map;f.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&g.set(b,c)}),b.set(d,{featureId:a.id,experimentId:e,variations:g})}return this.mappedRules=b,b}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){if(null!==this.isTargetedDeliveryRule)return this.isTargetedDeliveryRule;for(const a of this.featureFlags.values())if(a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))return!0;return!1}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;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 c=this.lastUpdate.getTime(),d=Date.now()-this.updateInterval;return c<d}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);const{featureFlags:a,customData:d}=b;null!==d&&void 0!==d&&d.length&&(this.dataManager.customDataIndexes=d);for(const b of a)this.featureFlagsData.set(b.featureKey,b);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");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{updateInterval:b,urlProvider:c,storage:d,requester:e,dataManager:f,externalClientConfiguration:g,offlineTrackingStorage:h,eventSource:i,externalVisitorCodeManager:j,eventManager:k}=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,"updateInterval",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),_defineProperty(this,"urlProvider",void 0),this.urlProvider=c,this.requester=e,this.updateInterval=b,this.lastUpdate=new Date,this.storage=d,this.dataManager=f,this.eventManager=k,this.externalClientConfiguration=g,this.offlineTrackingStorage=h,this.visitorCodeManager=j,this.eventSource=i}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,featureFlags:c}=this.externalClientConfiguration;this.configurationData={customData:a,configuration:b};for(const a of c)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.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}get featureFlags(){return this.featureFlagsData}get configuration(){return this.configurationData.configuration}get segments(){if(this.segmentsData)return this.segmentsData;const a=new Map;return this.featureFlagsData.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),this.segmentsData=a,a}get ruleMap(){var a;if(null!==(a=this.mappedRules)&&void 0!==a&&a.size)return this.mappedRules;const b=new Map;for(const a of this.featureFlags.values())for(const c of a.rules){const{id:d,experimentId:e,variationByExposition:f}=c,g=new Map;f.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&g.set(b,c)}),b.set(d,{featureId:a.id,experimentId:e,variations:g})}return this.mappedRules=b,b}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){if(null!==this.isTargetedDeliveryRule)return this.isTargetedDeliveryRule;for(const a of this.featureFlags.values())if(a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))return!0;return!1}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;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 c=this.lastUpdate.getTime(),d=Date.now()-this.updateInterval;return c<d}readStorageData(){const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data,d=this.checkIntegrity(b);if(!d){this.urlProvider.dataApiDomain=_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{this.urlProvider.dataApiDomain=b.configuration.dataApiDomain;const{featureFlags:a,customData:d}=b;null!==d&&void 0!==d&&d.length&&(this.dataManager.customDataIndexes=d);for(const b of a)this.featureFlagsData.set(b.featureKey,b);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 this.urlProvider.dataApiDomain=this.configurationData.configuration.dataApiDomain,this.storage.write(b)}}exports.ClientConfiguration=ClientConfiguration;
//# sourceMappingURL=clientConfiguration.js.map

@@ -9,2 +9,3 @@ import { IEventSource } from '../eventSource';

import { EventManager } from '../eventManager';
import { IUrlProvider } from '../requester/urlProvider';
export type ScheduleType = {

@@ -112,2 +113,3 @@ dateStart: string;

export type ClientConfigurationParametersType = {
urlProvider: IUrlProvider;
updateInterval: number;

@@ -114,0 +116,0 @@ storage: IStorage<ClientDataType>;

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

import { EventHandlerType, IExternalEventSource } from './types';
import { EventHandlerType, EventSourceParametersType } from './types';
export interface IEventSource {

@@ -12,3 +12,3 @@ readonly isOpen: boolean;

private isConnectionOpen;
constructor(siteCode: string, externalEventSource: IExternalEventSource);
constructor({ siteCode, externalEventSource, urlProvider, }: EventSourceParametersType);
get isOpen(): boolean;

@@ -15,0 +15,0 @@ open(onEvent: EventHandlerType): void;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonEventSource=void 0;var _urlProvider=require("../requester/urlProvider"),_constants=require("./constants");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 KameleoonEventSource{constructor(a,b){_defineProperty(this,"eventSource",void 0),_defineProperty(this,"siteCode",void 0),_defineProperty(this,"url",void 0),_defineProperty(this,"isConnectionOpen",void 0),this.url=_urlProvider.UrlProvider.getEventSourceUrl(),this.siteCode=a,this.eventSource=b,this.isConnectionOpen=!1}get isOpen(){return this.isConnectionOpen}open(a){this.eventSource.open({onEvent:this.handleMessage(a),url:this.url,eventType:_constants.REAL_TIME_EVENT}),this.isConnectionOpen=!0}close(){this.eventSource.close(),this.isConnectionOpen=!1}handleMessage(a){const b=b=>{const c=JSON.parse(b.data),{siteCode:d,ts:e}=c;this.siteCode===d&&a(e)};return b}}exports.KameleoonEventSource=KameleoonEventSource;
"use strict";var _constants=require("./constants");Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonEventSource=void 0;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 KameleoonEventSource{constructor(a){let{siteCode:b,externalEventSource:c,urlProvider:d}=a;_defineProperty(this,"eventSource",void 0),_defineProperty(this,"siteCode",void 0),_defineProperty(this,"url",void 0),_defineProperty(this,"isConnectionOpen",void 0),this.url=d.getEventSourceUrl(),this.siteCode=b,this.eventSource=c,this.isConnectionOpen=!1}get isOpen(){return this.isConnectionOpen}open(a){this.eventSource.open({onEvent:this.handleMessage(a),url:this.url,eventType:_constants.REAL_TIME_EVENT}),this.isConnectionOpen=!0}close(){this.eventSource.close(),this.isConnectionOpen=!1}handleMessage(a){const b=b=>{const c=JSON.parse(b.data),{siteCode:d,ts:e}=c;this.siteCode===d&&a(e)};return b}}exports.KameleoonEventSource=KameleoonEventSource;
//# sourceMappingURL=eventSource.js.map

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

import { IUrlProvider } from '../requester';
/**

@@ -37,1 +38,6 @@ * @param {number} timestamp - timestamp of when the event has happened

};
export type EventSourceParametersType = {
siteCode: string;
urlProvider: IUrlProvider;
externalEventSource: IExternalEventSource;
};

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

*/
constructor({ siteCode, configuration, internalConfiguration, }: SDKCoreParameters);
constructor({ siteCode, dependencies, configuration, internalConfiguration, }: SDKCoreParameters);
initialize(useCache?: boolean): Promise<boolean>;

@@ -31,0 +31,0 @@ addData(visitorCode: string, ...data: KameleoonDataType[]): void;

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

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

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

import { EventType, ParameterType, QueryType, StrictEventTypeRecord, StrictFirstParameterRecord, StrictParameterRecord, StrictQueryRecord, StrictTrackingRecord, TrackingType } from './types';
import { DomainsType, EventType, ParameterType, QueryType, StrictEventTypeRecord, StrictFirstParameterRecord, StrictParameterRecord, StrictQueryRecord, StrictTrackingRecord, TrackingType } from './types';
export declare const NUMBER_OF_RETRIES = 2;

@@ -16,1 +16,2 @@ export declare enum Header {

export declare const UrlTracking: StrictTrackingRecord<TrackingType>;
export declare const DEFAULT_DOMAINS: DomainsType;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlTracking=exports.UrlQuery=exports.UrlParameter=exports.UrlFirstParameter=exports.UrlEventType=exports.NUMBER_OF_RETRIES=exports.Header=void 0;const NUMBER_OF_RETRIES=exports.NUMBER_OF_RETRIES=2;let Header=exports.Header=function(a){return a.UserAgent="User-Agent",a.ContentType="Content-Type",a.SdkVersion="X-Kameleoon-SDK-Version",a.SdkType="X-Kameleoon-SDK-Type",a.Authorization="Authorization",a.AcceptEncoding="Accept-Encoding",a}({});const UrlEventType=exports.UrlEventType={CustomData:"eventType=customData",StaticData:"eventType=staticData",Page:"eventType=page",Conversion:"eventType=conversion",Activity:"eventType=activity",Experiment:"eventType=experiment",Geolocation:"eventType=geolocation"},UrlParameter=exports.UrlParameter={Title:"&title=",ReferrersIndices:"&referrersIndices=",Negative:"&negative=",Revenue:"&revenue=",Overwrite:"&overwrite=",Index:"&index=",BrowserIndex:"&browserIndex=",BrowserVersion:"&browserVersion=",Href:"&href=",DeviceType:"&deviceType=",SiteCode:"&siteCode=",GoalId:"&goalId=",VisitorCode:"&visitorCode=",VariationId:"&variationId=",Ts:"&ts=",Key:"&key=",SdkName:"&sdkName=",SdkVersion:"&sdkVersion=",ValuesCountMap:"&valuesCountMap=",Nonce:"&nonce=",Id:"&id=",CustomData:"&customData=",CurrentVisit:"&currentVisit=",MaxNumberPreviousVisits:"&maxNumberPreviousVisits=",Os:"&os=",OsIndex:"&osIndex=",Country:"&country=",City:"&city=",Region:"&region=",Latitude:"&latitude=",Longitude:"&longitude=",PostalCode:"&postalCode=",Conversion:"&conversion=",StaticData:"&staticData=",Geolocation:"&geolocation=",Page:"&page=",Experiment:"&experiment=",Browser:"&browser=",Environment:"&environment=",MappingIdentifier:"&mappingIdentifier=",MappingValue:"&mappingValue=",Kcs:"&kcs="},UrlFirstParameter=exports.UrlFirstParameter={CustomData:"?customData=",StaticData:"?staticData=",Page:"?page=",Conversion:"?conversion=",Geolocation:"?geolocation=",Experiment:"?experiment=",ValuesCountMap:"?valuesCountMap=",Id:"?id=",Nonce:"?nonce=",Country:"?country=",Environment:"?environment=",City:"?city=",Region:"?region=",Latitude:"?latitude=",Longitude:"?longitude=",PostalCode:"?postalCode=",SdkName:"?sdkName=",SdkVersion:"?sdkVersion=",BrowserIndex:"?browserIndex=",BrowserVersion:"?browserVersion=",SiteCode:"?siteCode=",VisitorCode:"?visitorCode=",CurrentVisit:"?currentVisit=",MaxNumberPreviousVisits:"?maxNumberPreviousVisits=",Negative:"?negative=",Revenue:"?revenue=",Title:"?title=",Os:"?os=",OsIndex:"?osIndex=",Browser:"?browser=",ReferrersIndices:"?referrersIndices=",Overwrite:"?overwrite=",Index:"?index=",Href:"?href=",VariationId:"?variationId=",DeviceType:"?deviceType=",GoalId:"?goalId=",Ts:"?ts=",Key:"?key=",MappingIdentifier:"?mappingIdentifier=",MappingValue:"?mappingValue=",Kcs:"?kcs="},UrlQuery=exports.UrlQuery={Sse:"sse?siteCode=",Map:"map?siteCode=",Events:"events?siteCode=",Visitor:"visitor?siteCode="},UrlTracking=exports.UrlTracking={Visit:"visit/",Map:"map/"};
"use strict";var _types=require("./types");Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlTracking=exports.UrlQuery=exports.UrlParameter=exports.UrlFirstParameter=exports.UrlEventType=exports.NUMBER_OF_RETRIES=exports.Header=exports.DEFAULT_DOMAINS=void 0;const NUMBER_OF_RETRIES=exports.NUMBER_OF_RETRIES=2;let Header=exports.Header=function(a){return a.UserAgent="User-Agent",a.ContentType="Content-Type",a.SdkVersion="X-Kameleoon-SDK-Version",a.SdkType="X-Kameleoon-SDK-Type",a.Authorization="Authorization",a.AcceptEncoding="Accept-Encoding",a}({});const UrlEventType=exports.UrlEventType={CustomData:"eventType=customData",StaticData:"eventType=staticData",Page:"eventType=page",Conversion:"eventType=conversion",Activity:"eventType=activity",Experiment:"eventType=experiment",Geolocation:"eventType=geolocation"},UrlParameter=exports.UrlParameter={Title:"&title=",ReferrersIndices:"&referrersIndices=",Negative:"&negative=",Revenue:"&revenue=",Overwrite:"&overwrite=",Index:"&index=",BrowserIndex:"&browserIndex=",BrowserVersion:"&browserVersion=",Href:"&href=",DeviceType:"&deviceType=",SiteCode:"&siteCode=",GoalId:"&goalId=",VisitorCode:"&visitorCode=",VariationId:"&variationId=",Ts:"&ts=",Key:"&key=",SdkName:"&sdkName=",SdkVersion:"&sdkVersion=",ValuesCountMap:"&valuesCountMap=",Nonce:"&nonce=",Id:"&id=",CustomData:"&customData=",CurrentVisit:"&currentVisit=",MaxNumberPreviousVisits:"&maxNumberPreviousVisits=",Os:"&os=",OsIndex:"&osIndex=",Country:"&country=",City:"&city=",Region:"&region=",Latitude:"&latitude=",Longitude:"&longitude=",PostalCode:"&postalCode=",Conversion:"&conversion=",StaticData:"&staticData=",Geolocation:"&geolocation=",Page:"&page=",Experiment:"&experiment=",Browser:"&browser=",Environment:"&environment=",MappingIdentifier:"&mappingIdentifier=",MappingValue:"&mappingValue=",Kcs:"&kcs="},UrlFirstParameter=exports.UrlFirstParameter={CustomData:"?customData=",StaticData:"?staticData=",Page:"?page=",Conversion:"?conversion=",Geolocation:"?geolocation=",Experiment:"?experiment=",ValuesCountMap:"?valuesCountMap=",Id:"?id=",Nonce:"?nonce=",Country:"?country=",Environment:"?environment=",City:"?city=",Region:"?region=",Latitude:"?latitude=",Longitude:"?longitude=",PostalCode:"?postalCode=",SdkName:"?sdkName=",SdkVersion:"?sdkVersion=",BrowserIndex:"?browserIndex=",BrowserVersion:"?browserVersion=",SiteCode:"?siteCode=",VisitorCode:"?visitorCode=",CurrentVisit:"?currentVisit=",MaxNumberPreviousVisits:"?maxNumberPreviousVisits=",Negative:"?negative=",Revenue:"?revenue=",Title:"?title=",Os:"?os=",OsIndex:"?osIndex=",Browser:"?browser=",ReferrersIndices:"?referrersIndices=",Overwrite:"?overwrite=",Index:"?index=",Href:"?href=",VariationId:"?variationId=",DeviceType:"?deviceType=",GoalId:"?goalId=",Ts:"?ts=",Key:"?key=",MappingIdentifier:"?mappingIdentifier=",MappingValue:"?mappingValue=",Kcs:"?kcs="},UrlQuery=exports.UrlQuery={Sse:"sse?siteCode=",Map:"map?siteCode=",Events:"events?siteCode=",Visitor:"visitor?siteCode="},UrlTracking=exports.UrlTracking={Visit:"visit/",Map:"map/"},DEFAULT_DOMAINS=exports.DEFAULT_DOMAINS={[_types.UrlType.DataApi]:{subdomain:"data",topLevelDomain:"io",secondLevelDomain:"kameleoon"},[_types.UrlType.Events]:{subdomain:"events",topLevelDomain:"com",secondLevelDomain:"kameleoon"},[_types.UrlType.ClientConfiguration]:{subdomain:"sdk-config",topLevelDomain:"eu",secondLevelDomain:"kameleoon"}};
//# sourceMappingURL=constants.js.map
export { Requester } from './requester';
export { NUMBER_OF_RETRIES, UrlQuery, UrlEventType, UrlParameter, UrlFirstParameter, Header, } from './constants';
export { HttpMethod, HeadersType, VisitType, RetryCountType, TrackParametersType, StaticDataEventType, TrackExperimentParamsType, TrackDataParamsType, GetVisitorDataResultType, IExternalRequester, KameleoonResponseType, RequestType, SendRequestParametersType, RequestParametersType, } from './types';
export { IUrlProvider, UrlProvider } from './urlProvider';
export { NUMBER_OF_RETRIES, UrlQuery, UrlEventType, UrlParameter, UrlFirstParameter, DEFAULT_DOMAINS, Header, } from './constants';
export { HttpMethod, HeadersType, VisitType, UrlType, DomainType, RetryCountType, TrackParametersType, StaticDataEventType, TrackExperimentParamsType, TrackDataParamsType, GetVisitorDataResultType, IExternalRequester, KameleoonResponseType, RequestType, SendRequestParametersType, RequestParametersType, } from './types';

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"GetVisitorDataResultType",{enumerable:!0,get:function(){return _types.GetVisitorDataResultType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function(){return _constants.Header}}),Object.defineProperty(exports,"HeadersType",{enumerable:!0,get:function(){return _types.HeadersType}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return _types.HttpMethod}}),Object.defineProperty(exports,"IExternalRequester",{enumerable:!0,get:function(){return _types.IExternalRequester}}),Object.defineProperty(exports,"KameleoonResponseType",{enumerable:!0,get:function(){return _types.KameleoonResponseType}}),Object.defineProperty(exports,"NUMBER_OF_RETRIES",{enumerable:!0,get:function(){return _constants.NUMBER_OF_RETRIES}}),Object.defineProperty(exports,"RequestParametersType",{enumerable:!0,get:function(){return _types.RequestParametersType}}),Object.defineProperty(exports,"RequestType",{enumerable:!0,get:function(){return _types.RequestType}}),Object.defineProperty(exports,"Requester",{enumerable:!0,get:function(){return _requester.Requester}}),Object.defineProperty(exports,"RetryCountType",{enumerable:!0,get:function(){return _types.RetryCountType}}),Object.defineProperty(exports,"SendRequestParametersType",{enumerable:!0,get:function(){return _types.SendRequestParametersType}}),Object.defineProperty(exports,"StaticDataEventType",{enumerable:!0,get:function(){return _types.StaticDataEventType}}),Object.defineProperty(exports,"TrackDataParamsType",{enumerable:!0,get:function(){return _types.TrackDataParamsType}}),Object.defineProperty(exports,"TrackExperimentParamsType",{enumerable:!0,get:function(){return _types.TrackExperimentParamsType}}),Object.defineProperty(exports,"TrackParametersType",{enumerable:!0,get:function(){return _types.TrackParametersType}}),Object.defineProperty(exports,"UrlEventType",{enumerable:!0,get:function(){return _constants.UrlEventType}}),Object.defineProperty(exports,"UrlFirstParameter",{enumerable:!0,get:function(){return _constants.UrlFirstParameter}}),Object.defineProperty(exports,"UrlParameter",{enumerable:!0,get:function(){return _constants.UrlParameter}}),Object.defineProperty(exports,"UrlQuery",{enumerable:!0,get:function(){return _constants.UrlQuery}}),Object.defineProperty(exports,"VisitType",{enumerable:!0,get:function(){return _types.VisitType}});var _requester=require("./requester"),_constants=require("./constants"),_types=require("./types");
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"DEFAULT_DOMAINS",{enumerable:!0,get:function(){return _constants.DEFAULT_DOMAINS}}),Object.defineProperty(exports,"DomainType",{enumerable:!0,get:function(){return _types.DomainType}}),Object.defineProperty(exports,"GetVisitorDataResultType",{enumerable:!0,get:function(){return _types.GetVisitorDataResultType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function(){return _constants.Header}}),Object.defineProperty(exports,"HeadersType",{enumerable:!0,get:function(){return _types.HeadersType}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return _types.HttpMethod}}),Object.defineProperty(exports,"IExternalRequester",{enumerable:!0,get:function(){return _types.IExternalRequester}}),Object.defineProperty(exports,"IUrlProvider",{enumerable:!0,get:function(){return _urlProvider.IUrlProvider}}),Object.defineProperty(exports,"KameleoonResponseType",{enumerable:!0,get:function(){return _types.KameleoonResponseType}}),Object.defineProperty(exports,"NUMBER_OF_RETRIES",{enumerable:!0,get:function(){return _constants.NUMBER_OF_RETRIES}}),Object.defineProperty(exports,"RequestParametersType",{enumerable:!0,get:function(){return _types.RequestParametersType}}),Object.defineProperty(exports,"RequestType",{enumerable:!0,get:function(){return _types.RequestType}}),Object.defineProperty(exports,"Requester",{enumerable:!0,get:function(){return _requester.Requester}}),Object.defineProperty(exports,"RetryCountType",{enumerable:!0,get:function(){return _types.RetryCountType}}),Object.defineProperty(exports,"SendRequestParametersType",{enumerable:!0,get:function(){return _types.SendRequestParametersType}}),Object.defineProperty(exports,"StaticDataEventType",{enumerable:!0,get:function(){return _types.StaticDataEventType}}),Object.defineProperty(exports,"TrackDataParamsType",{enumerable:!0,get:function(){return _types.TrackDataParamsType}}),Object.defineProperty(exports,"TrackExperimentParamsType",{enumerable:!0,get:function(){return _types.TrackExperimentParamsType}}),Object.defineProperty(exports,"TrackParametersType",{enumerable:!0,get:function(){return _types.TrackParametersType}}),Object.defineProperty(exports,"UrlEventType",{enumerable:!0,get:function(){return _constants.UrlEventType}}),Object.defineProperty(exports,"UrlFirstParameter",{enumerable:!0,get:function(){return _constants.UrlFirstParameter}}),Object.defineProperty(exports,"UrlParameter",{enumerable:!0,get:function(){return _constants.UrlParameter}}),Object.defineProperty(exports,"UrlProvider",{enumerable:!0,get:function(){return _urlProvider.UrlProvider}}),Object.defineProperty(exports,"UrlQuery",{enumerable:!0,get:function(){return _constants.UrlQuery}}),Object.defineProperty(exports,"UrlType",{enumerable:!0,get:function(){return _types.UrlType}}),Object.defineProperty(exports,"VisitType",{enumerable:!0,get:function(){return _types.VisitType}});var _requester=require("./requester"),_urlProvider=require("./urlProvider"),_constants=require("./constants"),_types=require("./types");
//# sourceMappingURL=index.js.map

@@ -13,6 +13,7 @@ import { Result } from 'ts-res';

private externalRequester;
private urlProvider;
private packageInfo;
private trackRetryDelay;
private timeout;
constructor({ siteCode, environment, packageInfo, domain, externalRequester, requestTimeout, trackRetryDelay, }: RequesterParamsType);
constructor({ urlProvider, packageInfo, externalRequester, requestTimeout, trackRetryDelay, }: RequesterParamsType);
getClientConfiguration(timeStamp?: number): Promise<Result<ConfigurationDataType, KameleoonError>>;

@@ -19,0 +20,0 @@ getRemoteData(key: string): Promise<Result<JSONType, KameleoonError>>;

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Requester=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_utilities=require("../utilities"),_constants=require("./constants"),_types=require("./types"),_urlProvider=require("./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 Requester{constructor(a){let{siteCode:b,environment:c,packageInfo:d,domain:e,externalRequester:f,requestTimeout:g,trackRetryDelay:h}=a;_defineProperty(this,"externalRequester",void 0),_defineProperty(this,"packageInfo",void 0),_defineProperty(this,"trackRetryDelay",void 0),_defineProperty(this,"timeout",void 0),this.externalRequester=f,this.trackRetryDelay=h,this.packageInfo=d,this.timeout=g,_urlProvider.UrlProvider.initialize({siteCode:b,domain:e,packageInfo:d,environment:c})}async getClientConfiguration(a){const b=_urlProvider.UrlProvider.getClientConfigurationUrl(a),c={[_constants.Header.SdkType]:this.packageInfo.type.toLowerCase(),[_constants.Header.SdkVersion]:this.packageInfo.version},d=_constants.NUMBER_OF_RETRIES+1;try{let a={message:""};for(let e=0;e<d;e++){const d=await this.sendRequest({url:b,requestType:_types.RequestType.Configuration,retryCount:e,headers:c});if(d.ok){const a=await d.json();return(0,_tsRes.Ok)(a)}if(e===_constants.NUMBER_OF_RETRIES&&d.text){const b=await d.text();a=JSON.parse(b)}}return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.MaximumRetriesReached,a.message))}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.ClientConfiguration,a))}}async getRemoteData(a){const b=_urlProvider.UrlProvider.getRemoteDataUrl(a);try{const a=await this.sendRequest({url:b,requestType:_types.RequestType.RemoteData,retryCount:0});if(!a.ok){if(a.text){var c;const b=await a.text(),d=null===(c=JSON.parse(b))||void 0===c?void 0:c.message;return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,d))}return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,"Unknown Reason - no `text()` was found for a response"))}const d=await a.json();return(0,_tsRes.Ok)(d)}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,a))}}async getVisitorData(a){let{visitorCode:b,filters:c,isMappingIdentifier:d}=a;const e=_urlProvider.UrlProvider.getVisitorDataUrl({visitorCode:b,filters:c,isMappingIdentifier:d});try{const a=await this.sendRequest({url:e,requestType:_types.RequestType.RemoteData,retryCount:0});if(!a.ok){if(a.text){var f;const b=await a.text(),c=null===(f=JSON.parse(b))||void 0===f?void 0:f.message;return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,c))}return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,"Unknown Reason - no 'text()' was found for a response"))}const b=await a.json();return(0,_tsRes.Ok)(b)}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,a))}}async trackExperiment(a){let{visitorCode:b,dataUrl:c,variationDataUrl:d,userAgent:e,isUnallocated:f}=a;const g=_urlProvider.UrlProvider.getTrackingUrl(b),h=c?"":_constants.UrlEventType.Activity+_constants.UrlParameter.Nonce+_utilities.Utilities.getNonce(),i=f?h:d,j=i?c+"\n"+i:c,k=e?{[_constants.Header.UserAgent]:e}:void 0;try{const a=await this.track({url:g,headers:k,requestType:_types.RequestType.Tracking,body:j});return(0,_tsRes.Ok)(a)}catch(_){return(0,_tsRes.Err)()}}async trackData(a){let{visitorCode:b,body:c,userAgent:d,isMappingIdentifier:e}=a;const f=_urlProvider.UrlProvider.getTrackingUrl(b,e),g=c||_constants.UrlEventType.Activity+_constants.UrlParameter.Nonce+_utilities.Utilities.getNonce(),h=d?{[_constants.Header.UserAgent]:d}:void 0;try{const a=await this.track({url:f,requestType:_types.RequestType.Tracking,headers:h,body:g});return(0,_tsRes.Ok)(a)}catch(_){return(0,_tsRes.Err)()}}async track(a){const b=_constants.NUMBER_OF_RETRIES+1;for(let c=0;c<b;c++){const b=await this.sendRequest(_objectSpread(_objectSpread({},a),{},{retryCount:c}));if(b.ok)return!0;await new Promise(a=>setTimeout(a,this.trackRetryDelay))}return!1}async sendRequest(a){let{requestType:b,url:c,retryCount:d,headers:e,body:f}=a;const g=new AbortController,h=setTimeout(()=>g.abort(),this.timeout);let i;switch(b){case _types.RequestType.RemoteData:case _types.RequestType.Configuration:i={headers:e,signal:g.signal,method:_types.HttpMethod.Get};break;case _types.RequestType.Tracking:if(!f)throw new Error("Internal Error: Tracking request should always contain body");i={method:_types.HttpMethod.Post,headers:e,signal:g.signal,body:f}}const j=_objectSpread(_objectSpread({},i),{},{headers:e,signal:g.signal}),k=await this.externalRequester.sendRequest({url:c,retryCount:d,requestType:b,parameters:j});return clearTimeout(h),k}}exports.Requester=Requester;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Requester=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_utilities=require("../utilities"),_constants=require("./constants"),_types=require("./types");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 Requester{constructor(a){let{urlProvider:b,packageInfo:c,externalRequester:d,requestTimeout:e,trackRetryDelay:f}=a;_defineProperty(this,"externalRequester",void 0),_defineProperty(this,"urlProvider",void 0),_defineProperty(this,"packageInfo",void 0),_defineProperty(this,"trackRetryDelay",void 0),_defineProperty(this,"timeout",void 0),this.urlProvider=b,this.externalRequester=d,this.trackRetryDelay=f,this.packageInfo=c,this.timeout=e}async getClientConfiguration(a){const b=this.urlProvider.getClientConfigurationUrl(a),c={[_constants.Header.SdkType]:this.packageInfo.type.toLowerCase(),[_constants.Header.SdkVersion]:this.packageInfo.version},d=_constants.NUMBER_OF_RETRIES+1;try{let a={message:""};for(let e=0;e<d;e++){const d=await this.sendRequest({url:b,requestType:_types.RequestType.Configuration,retryCount:e,headers:c});if(d.ok){const a=await d.json();return(0,_tsRes.Ok)(a)}if(e===_constants.NUMBER_OF_RETRIES&&d.text){const b=await d.text();a=JSON.parse(b)}}return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.MaximumRetriesReached,a.message))}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.ClientConfiguration,a))}}async getRemoteData(a){const b=this.urlProvider.getRemoteDataUrl(a);try{const a=await this.sendRequest({url:b,requestType:_types.RequestType.RemoteData,retryCount:0});if(!a.ok){if(a.text){var c;const b=await a.text(),d=null===(c=JSON.parse(b))||void 0===c?void 0:c.message;return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,d))}return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,"Unknown Reason - no `text()` was found for a response"))}const d=await a.json();return(0,_tsRes.Ok)(d)}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,a))}}async getVisitorData(a){let{visitorCode:b,filters:c,isMappingIdentifier:d}=a;const e=this.urlProvider.getVisitorDataUrl({visitorCode:b,filters:c,isMappingIdentifier:d});try{const a=await this.sendRequest({url:e,requestType:_types.RequestType.RemoteData,retryCount:0});if(!a.ok){if(a.text){var f;const b=await a.text(),c=null===(f=JSON.parse(b))||void 0===f?void 0:f.message;return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,c))}return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,"Unknown Reason - no 'text()' was found for a response"))}const b=await a.json();return(0,_tsRes.Ok)(b)}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,a))}}async trackExperiment(a){let{visitorCode:b,dataUrl:c,variationDataUrl:d,userAgent:e,isUnallocated:f}=a;const g=this.urlProvider.getTrackingUrl(b),h=c?"":_constants.UrlEventType.Activity+_constants.UrlParameter.Nonce+_utilities.Utilities.getNonce(),i=f?h:d,j=i?c+"\n"+i:c,k=e?{[_constants.Header.UserAgent]:e}:void 0;try{const a=await this.track({url:g,headers:k,requestType:_types.RequestType.Tracking,body:j});return(0,_tsRes.Ok)(a)}catch(_){return(0,_tsRes.Err)()}}async trackData(a){let{visitorCode:b,body:c,userAgent:d,isMappingIdentifier:e}=a;const f=this.urlProvider.getTrackingUrl(b,e),g=c||_constants.UrlEventType.Activity+_constants.UrlParameter.Nonce+_utilities.Utilities.getNonce(),h=d?{[_constants.Header.UserAgent]:d}:void 0;try{const a=await this.track({url:f,requestType:_types.RequestType.Tracking,headers:h,body:g});return(0,_tsRes.Ok)(a)}catch(_){return(0,_tsRes.Err)()}}async track(a){const b=_constants.NUMBER_OF_RETRIES+1;for(let c=0;c<b;c++){const b=await this.sendRequest(_objectSpread(_objectSpread({},a),{},{retryCount:c}));if(b.ok)return!0;await new Promise(a=>setTimeout(a,this.trackRetryDelay))}return!1}async sendRequest(a){let{requestType:b,url:c,retryCount:d,headers:e,body:f}=a;const g=new AbortController,h=setTimeout(()=>g.abort(),this.timeout);let i;switch(b){case _types.RequestType.RemoteData:case _types.RequestType.Configuration:i={headers:e,signal:g.signal,method:_types.HttpMethod.Get};break;case _types.RequestType.Tracking:if(!f)throw new Error("Internal Error: Tracking request should always contain body");i={method:_types.HttpMethod.Post,headers:e,signal:g.signal,body:f}}const j=_objectSpread(_objectSpread({},i),{},{headers:e,signal:g.signal}),k=await this.externalRequester.sendRequest({url:c,retryCount:d,requestType:b,parameters:j});return clearTimeout(h),k}}exports.Requester=Requester;
//# sourceMappingURL=requester.js.map

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

import { VisitorDataFiltersType } from '../utilities';
import { IUrlProvider } from './urlProvider';
export declare enum UrlType {

@@ -22,4 +23,4 @@ DataApi = "dataApi",

export type UrlProviderInitializeParamsType = {
domain: string | null;
siteCode: string;
domain: string | null;
packageInfo: ExternalPackageInfoType;

@@ -29,5 +30,3 @@ environment: Environment;

export type RequesterParamsType = {
siteCode: string;
domain: string | null;
environment: Environment;
urlProvider: IUrlProvider;
packageInfo: ExternalPackageInfoType;

@@ -34,0 +33,0 @@ externalRequester: IExternalRequester;

import { GetVisitorDataUrlParamsType, UrlProviderInitializeParamsType } from './types';
export declare class UrlProvider {
private static ready;
private static siteCode;
private static isCustomDomain;
private static environment;
private static packageInfo;
private static domains;
static dataApiTopLevelDomain?: string;
static initialize({ siteCode, domain, packageInfo, environment, }: UrlProviderInitializeParamsType): void;
static setDataApiDomain(domain: string): void;
static getClientConfigurationUrl(timeStamp?: number): string;
static getEventSourceUrl(): string;
static getRemoteDataUrl(key: string): string;
static getVisitorDataUrl({ visitorCode, filters, isMappingIdentifier, }: GetVisitorDataUrlParamsType): string;
static getTrackingUrl(visitorCode: string, isMappingIdentifier?: boolean): string;
private static isInitialized;
private static getDataApiUrl;
private static setDomains;
export interface IUrlProvider {
initialize(params: UrlProviderInitializeParamsType): void;
getClientConfigurationUrl(timeStamp?: number): string;
getEventSourceUrl(): string;
getRemoteDataUrl(key: string): string;
getVisitorDataUrl(params: GetVisitorDataUrlParamsType): string;
getTrackingUrl(visitorCode: string, isMappingIdentifier?: boolean): string;
dataApiDomain: string;
}
export declare class UrlProvider implements IUrlProvider {
private ready;
private isCustomDomain;
private domains;
private siteCode?;
private environment?;
private packageInfo?;
initialize({ domain, siteCode, packageInfo, environment, }: UrlProviderInitializeParamsType): void;
set dataApiDomain(domain: string);
getClientConfigurationUrl(timeStamp?: number): string;
getEventSourceUrl(): string;
getRemoteDataUrl(key: string): string;
getVisitorDataUrl({ visitorCode, filters, isMappingIdentifier, }: GetVisitorDataUrlParamsType): string;
getTrackingUrl(visitorCode: string, isMappingIdentifier?: boolean): string;
private isInitialized;
private getDataApiUrl;
private setDomains;
}

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlProvider=void 0;var _types=require("../types"),_constants=require("./constants"),_types2=require("./types");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 UrlProvider{static initialize(a){let{siteCode:b,domain:c,packageInfo:d,environment:e}=a;this.siteCode=b,this.environment=e,this.packageInfo=d,this.ready=!0,this.setDomains(c)}static setDataApiDomain(a){var b;if(!this.isCustomDomain){const c=a.split(".");if(3===c.length){const[a,d,e]=c;this.domains[_types2.UrlType.DataApi]={subdomain:a,secondLevelDomain:d,topLevelDomain:null!==(b=this.dataApiTopLevelDomain)&&void 0!==b?b:e}}}}static getClientConfigurationUrl(a){this.isInitialized();const{subdomain:b,topLevelDomain:c,secondLevelDomain:d}=this.domains[_types2.UrlType.ClientConfiguration],e="https://".concat(b,".").concat(d,".").concat(c,"/"),f=this.environment===_types.Environment.Production?"":_constants.UrlFirstParameter.Environment+this.environment;let g="";return a&&(f?g=_constants.UrlParameter.Ts+a:g=_constants.UrlFirstParameter.Ts+a),e+this.siteCode+f+g}static getEventSourceUrl(){this.isInitialized();const{subdomain:a,topLevelDomain:b,secondLevelDomain:c}=this.domains[_types2.UrlType.Events];return"https://".concat(a,".").concat(c,".").concat(b,":8110/").concat(_constants.UrlQuery.Sse).concat(this.siteCode)}static getRemoteDataUrl(a){return this.isInitialized(),this.getDataApiUrl(_types2.DataApiQuery.DataMap)+this.siteCode+_constants.UrlParameter.Key+encodeURI(a)}static getVisitorDataUrl(a){let{visitorCode:b,filters:c,isMappingIdentifier:d}=a;this.isInitialized();const{customData:e,previousVisitAmount:f,currentVisit:g,conversions:h,geolocation:i,experiments:j,pageViews:k,device:l,browser:m,operatingSystem:n,kcs:o}=c,p=d?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode,q=e?_constants.UrlParameter.CustomData+!0:"",r=h?_constants.UrlParameter.Conversion+!0:"",s=i?_constants.UrlParameter.Geolocation+!0:"",t=j?_constants.UrlParameter.Experiment+!0:"",u=k?_constants.UrlParameter.Page+!0:"",v=!!(l||m||n)?_constants.UrlParameter.StaticData+!0:"",w=g?_constants.UrlParameter.CurrentVisit+!0:"",x=o?_constants.UrlParameter.Kcs+!0:"",y="number"==typeof f?_constants.UrlParameter.MaxNumberPreviousVisits+f:_constants.UrlParameter.MaxNumberPreviousVisits+1;return this.getDataApiUrl(_types2.DataApiQuery.VisitData)+this.siteCode+p+b+y+q+r+s+t+u+v+w+x}static getTrackingUrl(a,b){this.isInitialized();const{type:c,version:d}=this.packageInfo,e=b?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode;return this.getDataApiUrl(_types2.DataApiQuery.VisitEvent)+this.siteCode+e+a+_constants.UrlParameter.SdkName+c.toLowerCase()+_constants.UrlParameter.SdkVersion+d}static isInitialized(){if(!this.ready)throw new Error("UrlProvider is not initialized")}static getDataApiUrl(a){const{subdomain:b,topLevelDomain:c,secondLevelDomain:d}=this.domains[_types2.UrlType.DataApi];if(!b||!c||!d)throw new Error("Data API domain is not set");const e="https://".concat(b,".").concat(d,".").concat(c);return a===_types2.DataApiQuery.VisitEvent?"".concat(e,"/").concat(_constants.UrlTracking.Visit+_constants.UrlQuery.Events):a===_types2.DataApiQuery.VisitData?"".concat(e,"/").concat(_constants.UrlTracking.Visit+_constants.UrlQuery.Visitor):a===_types2.DataApiQuery.DataMap?"".concat(e,"/").concat(_constants.UrlTracking.Map+_constants.UrlQuery.Map):void 0}static setDomains(a){if(!a)return;this.isCustomDomain=!0;const b=a.split("."),[c,d]=b,e={secondLevelDomain:c,topLevelDomain:d};this.domains={[_types2.UrlType.DataApi]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.DataApi]),e),[_types2.UrlType.Events]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.Events]),e),[_types2.UrlType.ClientConfiguration]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.ClientConfiguration]),e)}}}exports.UrlProvider=UrlProvider,_defineProperty(UrlProvider,"ready",!1),_defineProperty(UrlProvider,"siteCode",void 0),_defineProperty(UrlProvider,"isCustomDomain",!1),_defineProperty(UrlProvider,"environment",void 0),_defineProperty(UrlProvider,"packageInfo",void 0),_defineProperty(UrlProvider,"domains",{[_types2.UrlType.DataApi]:{subdomain:"data",topLevelDomain:"io",secondLevelDomain:"kameleoon"},[_types2.UrlType.Events]:{subdomain:"events",topLevelDomain:"com",secondLevelDomain:"kameleoon"},[_types2.UrlType.ClientConfiguration]:{subdomain:"sdk-config",topLevelDomain:"eu",secondLevelDomain:"kameleoon"}}),_defineProperty(UrlProvider,"dataApiTopLevelDomain",void 0);
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlProvider=void 0;var _types=require("../types"),_constants=require("./constants"),_types2=require("./types");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 UrlProvider{constructor(){_defineProperty(this,"ready",!1),_defineProperty(this,"isCustomDomain",!1),_defineProperty(this,"domains",_constants.DEFAULT_DOMAINS),_defineProperty(this,"siteCode",void 0),_defineProperty(this,"environment",void 0),_defineProperty(this,"packageInfo",void 0)}initialize(a){let{domain:b,siteCode:c,packageInfo:d,environment:e}=a;this.siteCode=c,this.environment=e,this.packageInfo=d,this.ready=!0,this.setDomains(b)}set dataApiDomain(a){if(!this.isCustomDomain){const b=a.split(".");if(3===b.length){const[a,c,d]=b;this.domains[_types2.UrlType.DataApi]={subdomain:a,secondLevelDomain:c,topLevelDomain:d}}}}getClientConfigurationUrl(a){this.isInitialized();const{subdomain:b,topLevelDomain:c,secondLevelDomain:d}=this.domains[_types2.UrlType.ClientConfiguration],e="https://".concat(b,".").concat(d,".").concat(c,"/"),f=this.environment===_types.Environment.Production?"":_constants.UrlFirstParameter.Environment+this.environment;let g="";return a&&(f?g=_constants.UrlParameter.Ts+a:g=_constants.UrlFirstParameter.Ts+a),e+this.siteCode+f+g}getEventSourceUrl(){this.isInitialized();const{subdomain:a,topLevelDomain:b,secondLevelDomain:c}=this.domains[_types2.UrlType.Events];return"https://".concat(a,".").concat(c,".").concat(b,":8110/").concat(_constants.UrlQuery.Sse).concat(this.siteCode)}getRemoteDataUrl(a){return this.isInitialized(),this.getDataApiUrl(_types2.DataApiQuery.DataMap)+this.siteCode+_constants.UrlParameter.Key+encodeURI(a)}getVisitorDataUrl(a){let{visitorCode:b,filters:c,isMappingIdentifier:d}=a;this.isInitialized();const{customData:e,previousVisitAmount:f,currentVisit:g,conversions:h,geolocation:i,experiments:j,pageViews:k,device:l,browser:m,operatingSystem:n,kcs:o}=c,p=d?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode,q=e?_constants.UrlParameter.CustomData+!0:"",r=h?_constants.UrlParameter.Conversion+!0:"",s=i?_constants.UrlParameter.Geolocation+!0:"",t=j?_constants.UrlParameter.Experiment+!0:"",u=k?_constants.UrlParameter.Page+!0:"",v=!!(l||m||n)?_constants.UrlParameter.StaticData+!0:"",w=g?_constants.UrlParameter.CurrentVisit+!0:"",x=o?_constants.UrlParameter.Kcs+!0:"",y="number"==typeof f?_constants.UrlParameter.MaxNumberPreviousVisits+f:_constants.UrlParameter.MaxNumberPreviousVisits+1;return this.getDataApiUrl(_types2.DataApiQuery.VisitData)+this.siteCode+p+b+y+q+r+s+t+u+v+w+x}getTrackingUrl(a,b){this.isInitialized();const{type:c,version:d}=this.packageInfo,e=b?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode;return this.getDataApiUrl(_types2.DataApiQuery.VisitEvent)+this.siteCode+e+a+_constants.UrlParameter.SdkName+c.toLowerCase()+_constants.UrlParameter.SdkVersion+d}isInitialized(){if(!this.ready)throw new Error("UrlProvider is not initialized")}getDataApiUrl(a){const{subdomain:b,topLevelDomain:c,secondLevelDomain:d}=this.domains[_types2.UrlType.DataApi];if(!b||!c||!d)throw new Error("Data API domain is not set");const e="https://".concat(b,".").concat(d,".").concat(c);return a===_types2.DataApiQuery.VisitEvent?"".concat(e,"/").concat(_constants.UrlTracking.Visit+_constants.UrlQuery.Events):a===_types2.DataApiQuery.VisitData?"".concat(e,"/").concat(_constants.UrlTracking.Visit+_constants.UrlQuery.Visitor):a===_types2.DataApiQuery.DataMap?"".concat(e,"/").concat(_constants.UrlTracking.Map+_constants.UrlQuery.Map):void 0}setDomains(a){if(!a)return;this.isCustomDomain=!0;const b=a.split("."),[c,d]=b,e={secondLevelDomain:c,topLevelDomain:d};this.domains={[_types2.UrlType.DataApi]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.DataApi]),e),[_types2.UrlType.Events]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.Events]),e),[_types2.UrlType.ClientConfiguration]:_objectSpread(_objectSpread({},this.domains[_types2.UrlType.ClientConfiguration]),e)}}}exports.UrlProvider=UrlProvider;
//# sourceMappingURL=urlProvider.js.map
import { ClientConfigurationDataType, ConfigurationDataType, JSONType } from './clientConfiguration/types';
import { SdkLanguageType } from './constants';
import { IExternalEventSource } from './eventSource';
import { IExternalRequester, RequestType } from './requester';
import { IExternalRequester, IUrlProvider, RequestType } from './requester';
import { IExternalStorage } from './storage';

@@ -38,10 +38,18 @@ import { IExternalPRNG, VisitorDataFiltersType } from './utilities';

/**
* @param {string} urlProvider - main source for all URLs used in the SDK
* */
export type DependenciesType = {
urlProvider?: IUrlProvider;
};
/**
* @param {string} siteCode - client's siteCode defined on Kameleoon platform
* @param {Partial<SDKConfigurationType>} configuration - client's configuration
* @param {InternalSDKConfigurationType} internalConfiguration - internal configuration for sdk core to be initialized with certain parameters to certain type of JavaScript SDK
* @param {DependenciesType | undefined} dependencies - internal dependencies meant primarily for testing purposes
* */
export type SDKCoreParameters = {
siteCode: string;
internalConfiguration: InternalSDKConfigurationType;
configuration?: Partial<SDKConfigurationType>;
internalConfiguration: InternalSDKConfigurationType;
dependencies?: DependenciesType;
};

@@ -48,0 +56,0 @@ /**

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc