@kameleoon/javascript-sdk-core 5.9.1 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +1 -1
- package/dist/kameleoonClient.d.ts +5 -4
- package/dist/kameleoonClient.js +1 -1
- package/dist/kameleoonData/dataManager.d.ts +20 -15
- package/dist/kameleoonData/dataManager.js +1 -1
- package/dist/kameleoonData/dataProcessor.js +1 -1
- package/dist/kameleoonData/index.d.ts +3 -1
- package/dist/kameleoonData/index.js +1 -1
- package/dist/kameleoonData/staticData.d.ts +15 -0
- package/dist/kameleoonData/staticData.js +1 -0
- package/dist/kameleoonData/types.d.ts +14 -1
- package/dist/kameleoonData/visitProcessor.d.ts +1 -0
- package/dist/kameleoonData/visitProcessor.js +1 -1
- package/dist/kameleoonData/visitsData.d.ts +6 -4
- package/dist/kameleoonData/visitsData.js +1 -1
- package/dist/requester/constants.js +1 -1
- package/dist/requester/types.d.ts +2 -1
- package/dist/requester/types.js +1 -1
- package/dist/requester/urlProvider.js +1 -1
- package/dist/targeting/conditions/conditionFactory.js +1 -1
- package/dist/targeting/conditions/firstVisit.d.ts +1 -1
- package/dist/targeting/conditions/firstVisit.js +1 -1
- package/dist/targeting/conditions/lastVisit.d.ts +1 -1
- package/dist/targeting/conditions/lastVisit.js +1 -1
- package/dist/targeting/conditions/newVisitor.d.ts +1 -1
- package/dist/targeting/conditions/newVisitor.js +1 -1
- package/dist/targeting/conditions/sameDayVisits.d.ts +1 -1
- package/dist/targeting/conditions/sameDayVisits.js +1 -1
- package/dist/targeting/conditions/visits.d.ts +1 -1
- package/dist/targeting/conditions/visits.js +1 -1
- package/dist/targeting/types.d.ts +0 -1
- package/dist/targeting/types.js +1 -1
- package/dist/tracking/bodyProvider.js +1 -1
- package/dist/tracking/index.d.ts +1 -1
- package/dist/tracking/index.js +1 -1
- package/dist/tracking/tracker.d.ts +1 -2
- package/dist/tracking/tracker.js +1 -1
- package/dist/tracking/types.d.ts +3 -2
- package/dist/types.d.ts +5 -2
- package/dist/utilities/constants.d.ts +1 -0
- package/dist/utilities/constants.js +1 -1
- package/dist/utilities/listUtilities.d.ts +7 -1
- package/dist/utilities/listUtilities.js +1 -1
- package/dist/utilities/parser.js +1 -1
- package/dist/utilities/types.d.ts +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 5.10.0 (2025-05-26)
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- Added support for a **New**/**Returning** visitor breakdown filter in reports (requires calling [`getRemoteVisitorData`][getRemoteVisitorData]).
|
|
8
|
+
|
|
9
|
+
## 5.9.2 (2025-05-15)
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Fixed an issue with the [session merging][SessionMerging] feature that could prevent registered users from being correctly included in experiment results when they were linked to an anonymous user during the same visitor session.
|
|
14
|
+
|
|
15
|
+
[SessionMerging]: https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#using-custom-data-for-session-merging
|
|
16
|
+
|
|
3
17
|
## 5.9.1 (2025-04-08)
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,13 @@ export { SdkLanguageType } from './constants';
|
|
|
13
13
|
export { JSONType, ConfigurationDataType } from './clientConfiguration';
|
|
14
14
|
export { TrackingStatus, VariableType, InternalsType, FeatureFlagType, JSONVariableType, SDKCoreParameters, NumberVariableType, StringVariableType, BooleanVariableType, SDKConfigurationType, KameleoonVariableType, KameleoonVariationType, FeatureFlagVariableType, TrackConversionParamsType, FeatureVariableResultType, RemoteVisitorDataParamsType, InternalSDKConfigurationType, IsFeatureFlagActiveParamsType, SetDataCallbackParametersType, GetFeatureFlagVariableParamsType, GetVisitorWarehouseAudienceParamsType, SimulateRequestDataType, GetVariationParamsType, GetVariationsParamsType, VariationType, Milliseconds, SetForcedVariationParametersType, } from './types';
|
|
15
15
|
export { Environment, ExternalPackageInfoType } from './sdkInfoTypes';
|
|
16
|
-
export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, KameleoonData, UniqueIdentifier, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, } from './kameleoonData';
|
|
16
|
+
export { ApplicationVersion, CustomData, Conversion, Device, Cookie, Browser, UserAgent, DeviceType, CookieType, GeolocationData, GeolocationInfoType, OperatingSystemType, OperatingSystem, BrowserType, PageView, StaticData, KameleoonData, UniqueIdentifier, KameleoonDataType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, IDataManager, DataManager, DataProcessor, } from './kameleoonData';
|
|
17
17
|
export { IExternalEventSource, EventSourceOpenParametersType, } from './eventSource';
|
|
18
18
|
export { Header, HeadersType, HttpMethod, IExternalRequester, RequestParametersType, RequestType, RetryCountType, KameleoonResponseType, SendRequestParametersType, NUMBER_OF_RETRIES, } from './requester';
|
|
19
|
+
export { ITracker } from './tracking';
|
|
20
|
+
export { SegmentType, TargetingDataType, Tree } from './targeting';
|
|
21
|
+
export { DataInfoType, IStorage, VISIT_DURATION, DataStorage } from './storage';
|
|
22
|
+
export { MappingIdentifierType } from './storage/types';
|
|
23
|
+
export { CustomDataConfigurationType, CustomDataScope, } from './clientConfiguration';
|
|
24
|
+
export { ListUtilities, Utilities } from './utilities';
|
|
25
|
+
export { BrowserDataType, CustomDataType, DataFilterType, DataManagerParametersType, DeviceDataType, GeolocationDataType, KameleoonVisitorDataType, MutUpdateTargetingDataParametersType, OperatingSystemDataType, PageViewDataType, ProcessCustomDataManagerParametersType, VisitDataType, VisitorsDataType, } from './kameleoonData/types';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersion}}),Object.defineProperty(exports,"ApplicationVersionDataType",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersionDataType}}),Object.defineProperty(exports,"BooleanVariableType",{enumerable:!0,get:function(){return _types.BooleanVariableType}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function(){return _kameleoonData.Browser}}),Object.defineProperty(exports,"BrowserType",{enumerable:!0,get:function(){return _kameleoonData.BrowserType}}),Object.defineProperty(exports,"ConfigurationDataType",{enumerable:!0,get:function(){return _clientConfiguration.ConfigurationDataType}}),Object.defineProperty(exports,"ConfigurationUpdateEventDataType",{enumerable:!0,get:function(){return _eventManager.ConfigurationUpdateEventDataType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function(){return _kameleoonData.Conversion}}),Object.defineProperty(exports,"ConversionParametersType",{enumerable:!0,get:function(){return _kameleoonData.ConversionParametersType}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function(){return _kameleoonData.Cookie}}),Object.defineProperty(exports,"CookieType",{enumerable:!0,get:function(){return _kameleoonData.CookieType}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function(){return _kameleoonData.CustomData}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function(){return _kameleoonData.Device}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function(){return _kameleoonData.DeviceType}}),Object.defineProperty(exports,"Environment",{enumerable:!0,get:function(){return _sdkInfoTypes.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 _sdkInfoTypes.ExternalPackageInfoType}}),Object.defineProperty(exports,"FeatureFlagType",{enumerable:!0,get:function(){return _types.FeatureFlagType}}),Object.defineProperty(exports,"FeatureFlagVariableType",{enumerable:!0,get:function(){return _types.FeatureFlagVariableType}}),Object.defineProperty(exports,"FeatureFlagVariationsType",{enumerable:!0,get:function(){return _storage.FeatureFlagVariationsType}}),Object.defineProperty(exports,"FeatureVariableResultType",{enumerable:!0,get:function(){return _types.FeatureVariableResultType}}),Object.defineProperty(exports,"GeolocationData",{enumerable:!0,get:function(){return _kameleoonData.GeolocationData}}),Object.defineProperty(exports,"GeolocationInfoType",{enumerable:!0,get:function(){return _kameleoonData.GeolocationInfoType}}),Object.defineProperty(exports,"GetFeatureFlagVariableParamsType",{enumerable:!0,get:function(){return _types.GetFeatureFlagVariableParamsType}}),Object.defineProperty(exports,"GetVariationParamsType",{enumerable:!0,get:function(){return _types.GetVariationParamsType}}),Object.defineProperty(exports,"GetVariationsParamsType",{enumerable:!0,get:function(){return _types.GetVariationsParamsType}}),Object.defineProperty(exports,"GetVisitorWarehouseAudienceParamsType",{enumerable:!0,get:function(){return _types.GetVisitorWarehouseAudienceParamsType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function(){return _requester.Header}}),Object.defineProperty(exports,"HeadersType",{enumerable:!0,get:function(){return _requester.HeadersType}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return _requester.HttpMethod}}),Object.defineProperty(exports,"IExternalEventSource",{enumerable:!0,get:function(){return _eventSource.IExternalEventSource}}),Object.defineProperty(exports,"IExternalLogger",{enumerable:!0,get:function(){return _logging.IExternalLogger}}),Object.defineProperty(exports,"IExternalPRNG",{enumerable:!0,get:function(){return _utilities.IExternalPRNG}}),Object.defineProperty(exports,"IExternalRequester",{enumerable:!0,get:function(){return _requester.IExternalRequester}}),Object.defineProperty(exports,"IExternalStorage",{enumerable:!0,get:function(){return _storage.IExternalStorage}}),Object.defineProperty(exports,"IKameleoonCore",{enumerable:!0,get:function(){return _kameleoonClientInterface.IKameleoonClient}}),Object.defineProperty(exports,"IVisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.IVisitorCodeManager}}),Object.defineProperty(exports,"InternalSDKConfigurationType",{enumerable:!0,get:function(){return _types.InternalSDKConfigurationType}}),Object.defineProperty(exports,"InternalsType",{enumerable:!0,get:function(){return _types.InternalsType}}),Object.defineProperty(exports,"IsFeatureFlagActiveParamsType",{enumerable:!0,get:function(){return _types.IsFeatureFlagActiveParamsType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function(){return _clientConfiguration.JSONType}}),Object.defineProperty(exports,"JSONVariableType",{enumerable:!0,get:function(){return _types.JSONVariableType}}),Object.defineProperty(exports,"KameleoonCore",{enumerable:!0,get:function(){return _kameleoonClient.KameleoonClient}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function(){return _kameleoonData.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function(){return _kameleoonData.KameleoonDataType}}),Object.defineProperty(exports,"KameleoonError",{enumerable:!0,get:function(){return _kameleoonError.KameleoonError}}),Object.defineProperty(exports,"KameleoonException",{enumerable:!0,get:function(){return _kameleoonError.KameleoonException}}),Object.defineProperty(exports,"KameleoonLogger",{enumerable:!0,get:function(){return _logging.KameleoonLogger}}),Object.defineProperty(exports,"KameleoonResponseType",{enumerable:!0,get:function(){return _requester.KameleoonResponseType}}),Object.defineProperty(exports,"KameleoonStorageKey",{enumerable:!0,get:function(){return _storage.KameleoonStorageKey}}),Object.defineProperty(exports,"KameleoonUtils",{enumerable:!0,get:function(){return _kameleoonUtils.KameleoonUtils}}),Object.defineProperty(exports,"KameleoonVariableType",{enumerable:!0,get:function(){return _types.KameleoonVariableType}}),Object.defineProperty(exports,"KameleoonVariationType",{enumerable:!0,get:function(){return _types.KameleoonVariationType}}),Object.defineProperty(exports,"LogLevel",{enumerable:!0,get:function(){return _logging.LogLevel}}),Object.defineProperty(exports,"Milliseconds",{enumerable:!0,get:function(){return _types.Milliseconds}}),Object.defineProperty(exports,"NUMBER_OF_RETRIES",{enumerable:!0,get:function(){return _requester.NUMBER_OF_RETRIES}}),Object.defineProperty(exports,"NumberVariableType",{enumerable:!0,get:function(){return _types.NumberVariableType}}),Object.defineProperty(exports,"Ok",{enumerable:!0,get:function(){return _tsRes.Ok}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function(){return _kameleoonData.OperatingSystem}}),Object.defineProperty(exports,"OperatingSystemType",{enumerable:!0,get:function(){return _kameleoonData.OperatingSystemType}}),Object.defineProperty(exports,"PageView",{enumerable:!0,get:function(){return _kameleoonData.PageView}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function(){return _kameleoonData.PageViewParametersType}}),Object.defineProperty(exports,"Parser",{enumerable:!0,get:function(){return _parser.Parser}}),Object.defineProperty(exports,"RemoteVisitorDataParamsType",{enumerable:!0,get:function(){return _types.RemoteVisitorDataParamsType}}),Object.defineProperty(exports,"RequestParametersType",{enumerable:!0,get:function(){return _requester.RequestParametersType}}),Object.defineProperty(exports,"RequestType",{enumerable:!0,get:function(){return _requester.RequestType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function(){return _tsRes.Result}}),Object.defineProperty(exports,"RetryCountType",{enumerable:!0,get:function(){return _requester.RetryCountType}}),Object.defineProperty(exports,"SDKConfigurationType",{enumerable:!0,get:function(){return _types.SDKConfigurationType}}),Object.defineProperty(exports,"SDKCoreParameters",{enumerable:!0,get:function(){return _types.SDKCoreParameters}}),Object.defineProperty(exports,"SdkLanguageType",{enumerable:!0,get:function(){return _constants.SdkLanguageType}}),Object.defineProperty(exports,"SendRequestParametersType",{enumerable:!0,get:function(){return _requester.SendRequestParametersType}}),Object.defineProperty(exports,"SetDataCallbackParametersType",{enumerable:!0,get:function(){return _types.SetDataCallbackParametersType}}),Object.defineProperty(exports,"SetForcedVariationParametersType",{enumerable:!0,get:function(){return _types.SetForcedVariationParametersType}}),Object.defineProperty(exports,"SimulateRequestDataType",{enumerable:!0,get:function(){return _types.SimulateRequestDataType}}),Object.defineProperty(exports,"StorageDataType",{enumerable:!0,get:function(){return _storage.StorageDataType}}),Object.defineProperty(exports,"StringVariableType",{enumerable:!0,get:function(){return _types.StringVariableType}}),Object.defineProperty(exports,"TrackConversionParamsType",{enumerable:!0,get:function(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackingStatus",{enumerable:!0,get:function(){return _types.TrackingStatus}}),Object.defineProperty(exports,"UniqueIdentifier",{enumerable:!0,get:function(){return _kameleoonData.UniqueIdentifier}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function(){return _visitorCodeManager.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"Validator",{enumerable:!0,get:function(){return _utilities.Validator}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function(){return _types.VariableType}}),Object.defineProperty(exports,"VariationType",{enumerable:!0,get:function(){return _types.VariationType}}),Object.defineProperty(exports,"VisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.VisitorCodeManager}}),Object.defineProperty(exports,"VisitorDataFiltersType",{enumerable:!0,get:function(){return _utilities.VisitorDataFiltersType}});var _tsRes=require("ts-res"),_kameleoonClient=require("./kameleoonClient"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonClientInterface=require("./kameleoonClientInterface"),_kameleoonError=require("./kameleoonError"),_utilities=require("./utilities"),_storage=require("./storage"),_eventManager=require("./eventManager"),_visitorCodeManager=require("./visitorCodeManager"),_logging=require("./logging"),_parser=require("./utilities/parser"),_constants=require("./constants"),_clientConfiguration=require("./clientConfiguration"),_types=require("./types"),_sdkInfoTypes=require("./sdkInfoTypes"),_kameleoonData=require("./kameleoonData"),_eventSource=require("./eventSource"),_requester=require("./requester");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersion}}),Object.defineProperty(exports,"ApplicationVersionDataType",{enumerable:!0,get:function(){return _kameleoonData.ApplicationVersionDataType}}),Object.defineProperty(exports,"BooleanVariableType",{enumerable:!0,get:function(){return _types.BooleanVariableType}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function(){return _kameleoonData.Browser}}),Object.defineProperty(exports,"BrowserDataType",{enumerable:!0,get:function(){return _types3.BrowserDataType}}),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,"CustomDataConfigurationType",{enumerable:!0,get:function(){return _clientConfiguration.CustomDataConfigurationType}}),Object.defineProperty(exports,"CustomDataScope",{enumerable:!0,get:function(){return _clientConfiguration.CustomDataScope}}),Object.defineProperty(exports,"CustomDataType",{enumerable:!0,get:function(){return _types3.CustomDataType}}),Object.defineProperty(exports,"DataFilterType",{enumerable:!0,get:function(){return _types3.DataFilterType}}),Object.defineProperty(exports,"DataInfoType",{enumerable:!0,get:function(){return _storage.DataInfoType}}),Object.defineProperty(exports,"DataManager",{enumerable:!0,get:function(){return _kameleoonData.DataManager}}),Object.defineProperty(exports,"DataManagerParametersType",{enumerable:!0,get:function(){return _types3.DataManagerParametersType}}),Object.defineProperty(exports,"DataProcessor",{enumerable:!0,get:function(){return _kameleoonData.DataProcessor}}),Object.defineProperty(exports,"DataStorage",{enumerable:!0,get:function(){return _storage.DataStorage}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function(){return _kameleoonData.Device}}),Object.defineProperty(exports,"DeviceDataType",{enumerable:!0,get:function(){return _types3.DeviceDataType}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function(){return _kameleoonData.DeviceType}}),Object.defineProperty(exports,"Environment",{enumerable:!0,get:function(){return _sdkInfoTypes.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 _sdkInfoTypes.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,"GeolocationDataType",{enumerable:!0,get:function(){return _types3.GeolocationDataType}}),Object.defineProperty(exports,"GeolocationInfoType",{enumerable:!0,get:function(){return _kameleoonData.GeolocationInfoType}}),Object.defineProperty(exports,"GetFeatureFlagVariableParamsType",{enumerable:!0,get:function(){return _types.GetFeatureFlagVariableParamsType}}),Object.defineProperty(exports,"GetVariationParamsType",{enumerable:!0,get:function(){return _types.GetVariationParamsType}}),Object.defineProperty(exports,"GetVariationsParamsType",{enumerable:!0,get:function(){return _types.GetVariationsParamsType}}),Object.defineProperty(exports,"GetVisitorWarehouseAudienceParamsType",{enumerable:!0,get:function(){return _types.GetVisitorWarehouseAudienceParamsType}}),Object.defineProperty(exports,"Header",{enumerable:!0,get:function(){return _requester.Header}}),Object.defineProperty(exports,"HeadersType",{enumerable:!0,get:function(){return _requester.HeadersType}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return _requester.HttpMethod}}),Object.defineProperty(exports,"IDataManager",{enumerable:!0,get:function(){return _kameleoonData.IDataManager}}),Object.defineProperty(exports,"IExternalEventSource",{enumerable:!0,get:function(){return _eventSource.IExternalEventSource}}),Object.defineProperty(exports,"IExternalLogger",{enumerable:!0,get:function(){return _logging.IExternalLogger}}),Object.defineProperty(exports,"IExternalPRNG",{enumerable:!0,get:function(){return _utilities.IExternalPRNG}}),Object.defineProperty(exports,"IExternalRequester",{enumerable:!0,get:function(){return _requester.IExternalRequester}}),Object.defineProperty(exports,"IExternalStorage",{enumerable:!0,get:function(){return _storage.IExternalStorage}}),Object.defineProperty(exports,"IKameleoonCore",{enumerable:!0,get:function(){return _kameleoonClientInterface.IKameleoonClient}}),Object.defineProperty(exports,"IStorage",{enumerable:!0,get:function(){return _storage.IStorage}}),Object.defineProperty(exports,"ITracker",{enumerable:!0,get:function(){return _tracking.ITracker}}),Object.defineProperty(exports,"IVisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.IVisitorCodeManager}}),Object.defineProperty(exports,"InternalSDKConfigurationType",{enumerable:!0,get:function(){return _types.InternalSDKConfigurationType}}),Object.defineProperty(exports,"InternalsType",{enumerable:!0,get:function(){return _types.InternalsType}}),Object.defineProperty(exports,"IsFeatureFlagActiveParamsType",{enumerable:!0,get:function(){return _types.IsFeatureFlagActiveParamsType}}),Object.defineProperty(exports,"JSONType",{enumerable:!0,get:function(){return _clientConfiguration.JSONType}}),Object.defineProperty(exports,"JSONVariableType",{enumerable:!0,get:function(){return _types.JSONVariableType}}),Object.defineProperty(exports,"KameleoonCore",{enumerable:!0,get:function(){return _kameleoonClient.KameleoonClient}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function(){return _kameleoonData.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function(){return _kameleoonData.KameleoonDataType}}),Object.defineProperty(exports,"KameleoonError",{enumerable:!0,get:function(){return _kameleoonError.KameleoonError}}),Object.defineProperty(exports,"KameleoonException",{enumerable:!0,get:function(){return _kameleoonError.KameleoonException}}),Object.defineProperty(exports,"KameleoonLogger",{enumerable:!0,get:function(){return _logging.KameleoonLogger}}),Object.defineProperty(exports,"KameleoonResponseType",{enumerable:!0,get:function(){return _requester.KameleoonResponseType}}),Object.defineProperty(exports,"KameleoonStorageKey",{enumerable:!0,get:function(){return _storage.KameleoonStorageKey}}),Object.defineProperty(exports,"KameleoonUtils",{enumerable:!0,get:function(){return _kameleoonUtils.KameleoonUtils}}),Object.defineProperty(exports,"KameleoonVariableType",{enumerable:!0,get:function(){return _types.KameleoonVariableType}}),Object.defineProperty(exports,"KameleoonVariationType",{enumerable:!0,get:function(){return _types.KameleoonVariationType}}),Object.defineProperty(exports,"KameleoonVisitorDataType",{enumerable:!0,get:function(){return _types3.KameleoonVisitorDataType}}),Object.defineProperty(exports,"ListUtilities",{enumerable:!0,get:function(){return _utilities.ListUtilities}}),Object.defineProperty(exports,"LogLevel",{enumerable:!0,get:function(){return _logging.LogLevel}}),Object.defineProperty(exports,"MappingIdentifierType",{enumerable:!0,get:function(){return _types2.MappingIdentifierType}}),Object.defineProperty(exports,"Milliseconds",{enumerable:!0,get:function(){return _types.Milliseconds}}),Object.defineProperty(exports,"MutUpdateTargetingDataParametersType",{enumerable:!0,get:function(){return _types3.MutUpdateTargetingDataParametersType}}),Object.defineProperty(exports,"NUMBER_OF_RETRIES",{enumerable:!0,get:function(){return _requester.NUMBER_OF_RETRIES}}),Object.defineProperty(exports,"NumberVariableType",{enumerable:!0,get:function(){return _types.NumberVariableType}}),Object.defineProperty(exports,"Ok",{enumerable:!0,get:function(){return _tsRes.Ok}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function(){return _kameleoonData.OperatingSystem}}),Object.defineProperty(exports,"OperatingSystemDataType",{enumerable:!0,get:function(){return _types3.OperatingSystemDataType}}),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,"PageViewDataType",{enumerable:!0,get:function(){return _types3.PageViewDataType}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function(){return _kameleoonData.PageViewParametersType}}),Object.defineProperty(exports,"Parser",{enumerable:!0,get:function(){return _parser.Parser}}),Object.defineProperty(exports,"ProcessCustomDataManagerParametersType",{enumerable:!0,get:function(){return _types3.ProcessCustomDataManagerParametersType}}),Object.defineProperty(exports,"RemoteVisitorDataParamsType",{enumerable:!0,get:function(){return _types.RemoteVisitorDataParamsType}}),Object.defineProperty(exports,"RequestParametersType",{enumerable:!0,get:function(){return _requester.RequestParametersType}}),Object.defineProperty(exports,"RequestType",{enumerable:!0,get:function(){return _requester.RequestType}}),Object.defineProperty(exports,"Result",{enumerable:!0,get:function(){return _tsRes.Result}}),Object.defineProperty(exports,"RetryCountType",{enumerable:!0,get:function(){return _requester.RetryCountType}}),Object.defineProperty(exports,"SDKConfigurationType",{enumerable:!0,get:function(){return _types.SDKConfigurationType}}),Object.defineProperty(exports,"SDKCoreParameters",{enumerable:!0,get:function(){return _types.SDKCoreParameters}}),Object.defineProperty(exports,"SdkLanguageType",{enumerable:!0,get:function(){return _constants.SdkLanguageType}}),Object.defineProperty(exports,"SegmentType",{enumerable:!0,get:function(){return _targeting.SegmentType}}),Object.defineProperty(exports,"SendRequestParametersType",{enumerable:!0,get:function(){return _requester.SendRequestParametersType}}),Object.defineProperty(exports,"SetDataCallbackParametersType",{enumerable:!0,get:function(){return _types.SetDataCallbackParametersType}}),Object.defineProperty(exports,"SetForcedVariationParametersType",{enumerable:!0,get:function(){return _types.SetForcedVariationParametersType}}),Object.defineProperty(exports,"SimulateRequestDataType",{enumerable:!0,get:function(){return _types.SimulateRequestDataType}}),Object.defineProperty(exports,"StaticData",{enumerable:!0,get:function(){return _kameleoonData.StaticData}}),Object.defineProperty(exports,"StorageDataType",{enumerable:!0,get:function(){return _storage.StorageDataType}}),Object.defineProperty(exports,"StringVariableType",{enumerable:!0,get:function(){return _types.StringVariableType}}),Object.defineProperty(exports,"TargetingDataType",{enumerable:!0,get:function(){return _targeting.TargetingDataType}}),Object.defineProperty(exports,"TrackConversionParamsType",{enumerable:!0,get:function(){return _types.TrackConversionParamsType}}),Object.defineProperty(exports,"TrackingStatus",{enumerable:!0,get:function(){return _types.TrackingStatus}}),Object.defineProperty(exports,"Tree",{enumerable:!0,get:function(){return _targeting.Tree}}),Object.defineProperty(exports,"UniqueIdentifier",{enumerable:!0,get:function(){return _kameleoonData.UniqueIdentifier}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _kameleoonData.UserAgent}}),Object.defineProperty(exports,"Utilities",{enumerable:!0,get:function(){return _utilities.Utilities}}),Object.defineProperty(exports,"VISITOR_CODE_LENGTH",{enumerable:!0,get:function(){return _visitorCodeManager.VISITOR_CODE_LENGTH}}),Object.defineProperty(exports,"VISIT_DURATION",{enumerable:!0,get:function(){return _storage.VISIT_DURATION}}),Object.defineProperty(exports,"Validator",{enumerable:!0,get:function(){return _utilities.Validator}}),Object.defineProperty(exports,"VariableType",{enumerable:!0,get:function(){return _types.VariableType}}),Object.defineProperty(exports,"VariationType",{enumerable:!0,get:function(){return _types.VariationType}}),Object.defineProperty(exports,"VisitDataType",{enumerable:!0,get:function(){return _types3.VisitDataType}}),Object.defineProperty(exports,"VisitorCodeManager",{enumerable:!0,get:function(){return _visitorCodeManager.VisitorCodeManager}}),Object.defineProperty(exports,"VisitorDataFiltersType",{enumerable:!0,get:function(){return _utilities.VisitorDataFiltersType}}),Object.defineProperty(exports,"VisitorsDataType",{enumerable:!0,get:function(){return _types3.VisitorsDataType}});var _tsRes=require("ts-res"),_kameleoonClient=require("./kameleoonClient"),_kameleoonUtils=require("./kameleoonUtils"),_kameleoonClientInterface=require("./kameleoonClientInterface"),_kameleoonError=require("./kameleoonError"),_utilities=require("./utilities"),_storage=require("./storage"),_eventManager=require("./eventManager"),_visitorCodeManager=require("./visitorCodeManager"),_logging=require("./logging"),_parser=require("./utilities/parser"),_constants=require("./constants"),_clientConfiguration=require("./clientConfiguration"),_types=require("./types"),_sdkInfoTypes=require("./sdkInfoTypes"),_kameleoonData=require("./kameleoonData"),_eventSource=require("./eventSource"),_requester=require("./requester"),_tracking=require("./tracking"),_targeting=require("./targeting"),_types2=require("./storage/types"),_types3=require("./kameleoonData/types");
|
|
@@ -3,6 +3,7 @@ import { CustomData, KameleoonDataType } from './kameleoonData';
|
|
|
3
3
|
import { TrackConversionParamsType, FeatureFlagType, GetFeatureFlagVariableParamsType, FeatureVariableResultType, SDKCoreParameters, RemoteVisitorDataParamsType, GetVisitorWarehouseAudienceParamsType, SetUserConsentParametersType, FeatureFlagVariableType, KameleoonVariationType, VariationType, GetVariationParamsType, GetVariationsParamsType, IsFeatureFlagActiveParamsType, SetForcedVariationParametersType } from './types';
|
|
4
4
|
import { IKameleoonClient } from './kameleoonClientInterface';
|
|
5
5
|
import { EventCallbackType, EventType } from './eventManager';
|
|
6
|
+
import { Tracker } from './tracking';
|
|
6
7
|
import { LogLevel } from './logging';
|
|
7
8
|
/**
|
|
8
9
|
* @class
|
|
@@ -17,16 +18,16 @@ export declare class KameleoonClient implements IKameleoonClient {
|
|
|
17
18
|
private trackingCache;
|
|
18
19
|
private requester;
|
|
19
20
|
private externalPackageInfo;
|
|
20
|
-
|
|
21
|
+
protected initialized: boolean;
|
|
21
22
|
private visitorCodeManager;
|
|
22
23
|
private eventManager;
|
|
23
|
-
|
|
24
|
+
protected readonly tracker: Tracker;
|
|
24
25
|
private environment;
|
|
25
26
|
protected readonly stubMode?: boolean;
|
|
26
27
|
/**
|
|
27
28
|
* @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core
|
|
28
29
|
*/
|
|
29
|
-
constructor({ siteCode, dependencies, configuration, internalConfiguration, stubMode }: SDKCoreParameters);
|
|
30
|
+
constructor({ siteCode, dependencies, configuration, internalConfiguration, stubMode, }: SDKCoreParameters);
|
|
30
31
|
initialize(): Promise<boolean>;
|
|
31
32
|
addData(visitorCode: string, ...data: KameleoonDataType[]): void;
|
|
32
33
|
getRemoteVisitorData({ visitorCode, shouldAddData, filters, }: RemoteVisitorDataParamsType): Promise<KameleoonDataType[]>;
|
|
@@ -51,7 +52,7 @@ export declare class KameleoonClient implements IKameleoonClient {
|
|
|
51
52
|
setForcedVariation({ visitorCode, experimentId, variationKey, forceTargeting, }: SetForcedVariationParametersType): void;
|
|
52
53
|
protected setUserConsent({ visitorCode, consent, setData, }: SetUserConsentParametersType): void;
|
|
53
54
|
private updateConsentData;
|
|
54
|
-
|
|
55
|
+
protected _isConsentProvided(visitorCode: string): boolean;
|
|
55
56
|
private _getFeatureVariables;
|
|
56
57
|
private _getActiveFeatureVariations;
|
|
57
58
|
private _evaluate;
|
package/dist/kameleoonClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonClient=void 0;var _tsRes=require("ts-res"),_cacheManager=require("./cacheManager"),_clientConfiguration=require("./clientConfiguration"),_clientSettings=require("./clientSettings"),_constants=require("./constants"),_kameleoonData=require("./kameleoonData"),_kameleoonError=require("./kameleoonError"),_requester=require("./requester"),_storage=require("./storage"),_types=require("./types"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_eventSource=require("./eventSource"),_visitorCodeManager=require("./visitorCodeManager"),_eventManager=require("./eventManager"),_tracking=require("./tracking"),_logging=require("./logging"),_hasher=require("./hasher");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class KameleoonClient{constructor(a){var b;let{siteCode:c,dependencies:d,configuration:e,internalConfiguration:f,stubMode:g}=a;if(_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"clientConfiguration",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"consentDataStorage",void 0),_defineProperty(this,"trackingCache",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"externalPackageInfo",void 0),_defineProperty(this,"initialized",!1),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),_defineProperty(this,"tracker",void 0),_defineProperty(this,"environment",void 0),_defineProperty(this,"stubMode",void 0),this.stubMode=g,g)return this.variationConfiguration={},this.clientConfiguration={},this.dataManager={},this.consentDataStorage={},this.trackingCache={},this.requester={},this.externalPackageInfo={},this.visitorCodeManager={},this.eventManager={},this.tracker={},void(this.environment="");const h=null===f||void 0===f?void 0:f.externals.externalLogger;h&&_logging.KameleoonLogger.setLogger(h),_logging.KameleoonLogger.debug`CALL: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`;const{settings:i}=new _clientSettings.ClientSettings(c,e);this.environment=i.environment;const{externalStorage:j,externalEventSource:k,externalPackageInfo:l,externalVisitorCodeManager:m,externalRequester:n,externalPRNG:o}=f.externals,{useAbortController:p}=f.settings,q=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),r=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ClientData),s=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TargetingData),t=new _storage.DataStorage(j,_storage.KameleoonStorageKey.DataInfo),u=new _storage.DataStorage(j,_storage.KameleoonStorageKey.VariationData),v=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedExperimentVariation),w=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedFeatureVariation),x=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ConsentData),y=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TrackingData),z=new _kameleoonData.DataManager({dataStorage:s,infoStorage:t,cleanupInterval:i.cleanupInterval,packageInfo:l}),A=null!==(b=null===d||void 0===d?void 0:d.urlProvider)&&void 0!==b?b:new _requester.UrlProvider;A.initialize({domain:i.networkDomain,siteCode:i.siteCode,packageInfo:l,environment:i.environment});const B=new _requester.Requester({urlProvider:A,useAbortController:p,packageInfo:l,externalRequester:n,requestTimeout:i.requestTimeout,trackRetryDelay:i.trackRetryDelay}),C=new _eventSource.KameleoonEventSource({siteCode:i.siteCode,externalEventSource:k,urlProvider:A}),D=new _eventManager.EventManager,E=new _clientConfiguration.ClientConfiguration({urlProvider:A,storage:r,updateInterval:i.updateInterval,dataManager:z,eventManager:D,requester:B,eventSource:C,externalVisitorCodeManager:m}),F=new _variationConfiguration.VariationConfiguration(u,v,w,m,E),G=new _tracking.Tracker({dataManager:z,trackingStorage:y,variationConfiguration:F,requester:B,trackingInterval:i.trackingInterval,prng:o});this.tracker=G,this.variationConfiguration=F,this.requester=B,this.trackingCache=q,this.dataManager=z,this.clientConfiguration=E,this.externalPackageInfo=l,this.consentDataStorage=x,this.visitorCodeManager=m,this.eventManager=D,null!==i.cleanupInterval&&new _storage.StorageCleanupManager(j,i.cleanupInterval),_logging.KameleoonLogger.debug`RETURN: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`}async initialize(){if(this.stubMode)return!1;_logging.KameleoonLogger.info("CALL: KameleoonClient.initialize()");const a=await this.clientConfiguration.initialize();return a.throw(),this.initialized=!0,_logging.KameleoonLogger.info`RETURN: KameleoonClient.initialize() -> (result: ${a.ok})`,a.ok}addData(a){if(this.stubMode)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];if(_logging.KameleoonLogger.info`CALL: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`,this.visitorCodeManager.validateVisitorCode(a).throw(),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.dataManager.storeData(a,...c).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`}async getRemoteVisitorData(a){let{visitorCode:b,shouldAddData:c=!0,filters:d=_constants.DEFAULT_VISITOR_DATA_FILTERS}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(b).throw();const{previousVisitAmount:e}=d;if("number"==typeof e&&(1>e||25<e))throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitAmount);const f=this.dataManager.isUniqueIdentifier(b),g=await this.requester.getVisitorData({visitorCode:b,filters:d,isMappingIdentifier:f}),h=g.throw(),{visitorData:i,storageVisitorData:j,visitsData:k,mappingIdentifier:l}=_utilities.Parser.parseVisitorData({data:h,filters:d,visitorCode:b,dataManager:this.dataManager,variationConfiguration:this.variationConfiguration});for(const d of j)(c||this.dataManager.isPersistentCustomData(d))&&this.addData(b,d);return k&&c&&this.addData(b,k),null!==d&&void 0!==d&&d.visitorCode&&l&&this.dataManager.setMappingIdentifier(b,l),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d}) -> (visitorData: ${i})`,i}trackConversion(a){let{visitorCode:b,goalId:c,negative:d,revenue:e,metadata:f}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`,this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:e,negative:d,metadata:f})),this.flush(b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`)}flush(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.flush(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a)return this.visitorCodeManager.validateVisitorCode(a).throw(),this.tracker.scheduleVisitor(a,this._isConsentProvided(a)),void _logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`;for(const b of this.dataManager.unsentDataVisitors)this.tracker.scheduleVisitor(b,this._isConsentProvided(b));_logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`}getFeatureFlags(){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info("CALL: KameleoonClient.getFeatureFlags()"),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);const a=this.clientConfiguration.featureFlags,b=[];return a.forEach(a=>{let{id:c,featureKey:d}=a;b.push({id:c,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlags() -> (FeatureFlags: ${b})`,b}getVisitorFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=[];return b.forEach(a=>{let{featureFlagId:b,featureKey:d}=a;c.push({id:b,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getVariation(a){let{visitorCode:b,featureKey:c,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=this._getFeatureVariation({visitorCode:b,featureKey:c,track:d}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${e})`,e}getVariations(a){let{visitorCode:b,onlyActive:c=!1,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=new Map,f=this.clientConfiguration.featureFlags;for(const g of f.values()){const a=this._getFeatureVariation({visitorCode:b,featureKey:g.featureKey,track:d});a.ok&&(!c||a.data.key!==_constants.OFF_VARIATION_KEY)&&e.set(g.featureKey,a.data)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d}) -> (variations: ${e})`,e}getActiveFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=new Map;return b.forEach(b=>{const{variationKey:d,featureKey:e,variationId:f,experimentId:g}=b;let h=[];null!==f&&null!==g&&(h=this._getFeatureVariables({visitorCode:a,featureKey:e,variationKey:d}));const i=h.map(a=>_utilities.Parser.parseFeatureVariable(a).throw());c.set(b.featureKey,{key:d,id:f,experimentId:g,variables:i})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getFeatureFlagVariationKey(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b}) -> (variationKey: ${c})`,c}getFeatureFlagVariable(a){let{visitorCode:b,featureKey:c,variableKey:d}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const{key:e}=this._getFeatureVariation({visitorCode:b,featureKey:c,track:!0}).throw(),f=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:e}),g=f.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariableNotFound,d,b);const{type:h,value:i}=_utilities.Parser.parseFeatureVariable(g).throw(),j={type:h,value:i};return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d}) -> (FeatureFlagVariable: ${j})`,j}getFeatureFlagVariables(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw(),d=this._getFeatureVariables({visitorCode:a,featureKey:b,variationKey:c}),e=[];for(const c of d){const a=_utilities.Parser.parseFeatureVariable(c).throw();e.push(a)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b}) -> (FeatureFlagVariables: ${e})`,e}isFeatureFlagActive(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);let[c,d,e]=["","",!0];"string"==typeof a?(_logging.KameleoonLogger.info`CALL: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d})`,c=a,d=b):(_logging.KameleoonLogger.info`CALL: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track ${e})`,[c,d]=[a.visitorCode,a.featureKey],a.track!==void 0&&(e=a.track)),this.visitorCodeManager.validateVisitorCode(c).throw();try{const{key:a}=this._getFeatureVariation({visitorCode:c,featureKey:d,track:e}).throw(),b=a!==_constants.OFF_VARIATION_KEY;return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: ${b})`,b}catch(a){if(a instanceof _kameleoonError.KameleoonError&&a.type===_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: false)`,!1;throw a}}async getRemoteData(a){if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteData(key: ${a})`;const b=await this.requester.getRemoteData(a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteData(key: ${a}) -> (remoteData: ${b})`,b.throw()}async getVisitorWarehouseAudience(a){let{visitorCode:b,customDataIndex:c,warehouseKey:d}=a;if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=await this.getRemoteData(d||b);if(!e)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,`No data found for ${d||b} key`);if(!e[_constants.WAREHOUSE_AUDIENCE_KEY]||0===Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]).length)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: null)`,null;const f=new _kameleoonData.CustomData(c,...Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]));return this.dataManager.storeData(b,f),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: ${f})`,f}onEvent(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.onEvent(event: ${a}, callback)`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(a,b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.onEvent(event: ${a}, callback)`}getEngineTrackingCode(a){if(this.stubMode)return"";_logging.KameleoonLogger.info`CALL: KameleoonClient.getEngineTrackingCode(visitorCode: ${a})`,this.visitorCodeManager.validateVisitorCode(a).throw();const b=_utilities.Utilities.getTrackingCode(this.trackingCache,a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getEngineTrackingCode(visitorCode: ${a}) -> (trackingCode: ${b})`,b}isInitialized(){return _logging.KameleoonLogger.debug`CALL/RETURN: KameleoonClient.isInitialized() -> (initialized: ${this.initialized})`,this.initialized}setLogLevel(a){_logging.KameleoonLogger.setLogLevel(a)}setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this._setForcedVariation({visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e}).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`)}setUserConsent(a){let{visitorCode:b,consent:c,setData:d}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this.updateConsentData(b,c),c?d({visitorCode:b,key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.DEFAULT_MAX_AGE,path:_visitorCodeManager.PATH}):this.visitorCodeManager.consentRequired&&d({visitorCode:"",key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.ZERO_MAX_AGE,path:_visitorCodeManager.PATH}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`)}updateConsentData(a,b){const c=this.consentDataStorage.read();if(!c.ok)return void(c.error.type===_kameleoonError.KameleoonException.StorageEmpty&&this.consentDataStorage.write({[a]:{consent:b}}));const d=c.data;d[a]={consent:b},this.consentDataStorage.write(d)}_isConsentProvided(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._isConsentProvided(visitorCode: ${a})`;const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read();let d=!1;if(!b)d=!0;else if(c.ok){const b=c.data[a];d="boolean"==typeof b?b:b&&b.consent}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isConsentProvided(visitorCode: ${a}) -> (isConsentProvided: ${d})`,d}_getFeatureVariables(a){let{visitorCode:b,featureKey:c,variationKey:d}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d})`;const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c);const g=f.variations.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d}) -> (variables: ${g.variables})`,g.variables}_getActiveFeatureVariations(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a})`;const b=this.clientConfiguration.featureFlags,c=[];for(const d of b.values()){if(!d.environmentEnabled)continue;const b=this._evaluate({visitorCode:a,featureFlag:d,track:!1,save:!1});b.variationKey!==_constants.OFF_VARIATION_KEY&&c.push({variationKey:b.variationKey,variationId:b.variationId,experimentId:b.experimentId,featureFlagId:d.id,featureKey:d.featureKey,rule:null,isTargetedRule:b.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY})}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a}) -> (activeVariations: ${c})`,c}_evaluate(a){let{visitorCode:b,featureFlag:c,track:d,save:e}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e})`;let f,g=null;const h=this.variationConfiguration.getForcedFeatureVariation(b,c.featureKey);if(h.ok&&(g=h.data),g)f=KameleoonClient.EvaluatedExperiment.fromForcedFeatureVariation(c.defaultVariationKey,g);else if(this._isVisitorNotInHoldout(b,d,e)&&this._isFFUnrestrictedByMEGroup(b,c)){const a=this.dataManager.getVisitorData(b),g=this.dataManager.getVisitorIdentifier(b),h=this.variationConfiguration.getVariation({visitorCode:b,visitorIdentifier:g,featureFlag:c,track:d,withAssignment:e,targetingData:a,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();f=KameleoonClient.EvaluatedExperiment.fromVariationData(h)}else f=KameleoonClient.EvaluatedExperiment.fromDefaultVariationKey(c.defaultVariationKey);return e&&!f.isSimulated&&null!==f.experimentId&&null!==f.variationId&&this.variationConfiguration.updateStoredVariations(b,{[f.experimentId]:{variationId:f.variationId,isTargetedRule:f.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY,status:d?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}}),this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:c.featureKey,variation:{key:f.variationKey,experimentId:f.experimentId,id:f.variationId}}),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e}) -> (evalExp: ${f})`,f}_isFFUnrestrictedByMEGroup(a,b){const c=b.mutuallyExclusiveGroup;if(!c)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: ${a}, featureFlag: ${b})`;let d=!0;const e=this.clientConfiguration.meGroups.get(c);if(e){const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDoubleForMEGroup(f,c);_logging.KameleoonLogger.debug`Calculated meGroup hash ${g} for code: '${f}', meGroup: '${c}'`,d=e.getFeatureFlagByHash(g)===b}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: '${a}', featureFlag: ${b}) -> (selected: ${d})`,d}_getFeatureVariation(a){let{visitorCode:b,featureKey:c,track:d}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c));if(!f.environmentEnabled)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled,f.featureKey,this.environment));const g=this._evaluate({visitorCode:b,featureFlag:f,track:d,save:!0}),{experimentId:h,variationId:i,variationKey:j,isSimulated:k}=g;let l=new Map,m=!1;try{const a=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:j});a.forEach(a=>{m||a.type!==_types.VariableType.JS&&a.type!==_types.VariableType.CSS||(m=!0);const b=_utilities.Parser.parseFeatureVariable(a).throw();l.set(a.key,b)})}catch(_){}h&&"number"==typeof i&&!k&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,hasJsCssVariables:m,visitorCode:b,experimentId:h,variationId:i}),d&&!k&&this.tracker.scheduleVisitor(b,this._isConsentProvided(b));const n={key:j,id:i,experimentId:h,variables:l};return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${n})`,(0,_tsRes.Ok)(n)}_isVisitorNotInHoldout(a,b,c){const d=this.clientConfiguration.holdout;if(!d)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c})`;let e=!0;const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDouble({visitorIdentifier:f,respoolTime:null,id:d.experimentId+""});_logging.KameleoonLogger.debug`Calculated holdoutHash: ${g} for visitorCode: ${f}`;let h=_utilities.Utilities.getVariationByHash(d.variationByExposition,g);return null!==h&&(e=h.variationKey!==_constants.IN_HOLDOUT_VARIATION_KEY,c&&this.variationConfiguration.updateStoredVariations(a,{[d.experimentId]:{variationId:h.variationId,isTargetedRule:!1,status:b?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}})),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c}) -> (isNotInHoldout: ${e})`,e}_setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,null===d){const a=this.variationConfiguration.updateForcedExperimentVariation(b,c,null);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${a})`,a}let f=null,g=null;if(f=this.clientConfiguration.experimentMap.get(c),!f)return _logging.KameleoonLogger.error`Experiment with id ${c} not found for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagExperimentNotFound,c,b));if(g=f.variations.get(d),void 0===g)return _logging.KameleoonLogger.error`Variation with key ${d} not found in experiment ${f} for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b));f={type:f.type,experimentId:c},g={variationKey:d,variationId:g};const h=this.variationConfiguration.updateForcedExperimentVariation(b,c,{rule:f,varByExp:g,forceTargeting:e});return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${h})`,h}}exports.KameleoonClient=KameleoonClient,_defineProperty(KameleoonClient,"EvaluatedExperiment",class{static fromForcedFeatureVariation(a,b){var c,d,e;let f=a;return b.varByExp?f=b.varByExp.variationKey:b.rule&&b.rule.type===_clientConfiguration.RuleType.EXPERIMENTATION&&(f=_constants.OFF_VARIATION_KEY),{variationKey:f,variationId:(null===(c=b.varByExp)||void 0===c?void 0:c.variationId)||null,experimentId:(null===(d=b.rule)||void 0===d?void 0:d.experimentId)||null,ruleType:(null===(e=b.rule)||void 0===e?void 0:e.type)||null,isSimulated:b.simulated}}static fromVariationData(a){var b,c;return{variationKey:a.variationKey,variationId:a.variationId,experimentId:a.experimentId,ruleType:null!==(b=null===(c=a.rule)||void 0===c?void 0:c.type)&&void 0!==b?b:null,isSimulated:!1}}static fromDefaultVariationKey(a){return{variationKey:a,variationId:null,experimentId:null,ruleType:null,isSimulated:!1}}});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.KameleoonClient=void 0;var _tsRes=require("ts-res"),_cacheManager=require("./cacheManager"),_clientConfiguration=require("./clientConfiguration"),_clientSettings=require("./clientSettings"),_constants=require("./constants"),_kameleoonData=require("./kameleoonData"),_kameleoonError=require("./kameleoonError"),_requester=require("./requester"),_storage=require("./storage"),_types=require("./types"),_utilities=require("./utilities"),_variationConfiguration=require("./variationConfiguration"),_eventSource=require("./eventSource"),_visitorCodeManager=require("./visitorCodeManager"),_eventManager=require("./eventManager"),_tracking=require("./tracking"),_logging=require("./logging"),_hasher=require("./hasher");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class KameleoonClient{constructor(a){var b;let{siteCode:c,dependencies:d,configuration:e,internalConfiguration:f,stubMode:g}=a;if(_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"clientConfiguration",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"consentDataStorage",void 0),_defineProperty(this,"trackingCache",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"externalPackageInfo",void 0),_defineProperty(this,"initialized",!1),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),_defineProperty(this,"tracker",void 0),_defineProperty(this,"environment",void 0),_defineProperty(this,"stubMode",void 0),this.stubMode=g,g)return this.variationConfiguration={},this.clientConfiguration={},this.dataManager={},this.consentDataStorage={},this.trackingCache={},this.requester={},this.externalPackageInfo={},this.visitorCodeManager={},this.eventManager={},this.tracker={},void(this.environment="");const h=null===f||void 0===f?void 0:f.externals.externalLogger;h&&_logging.KameleoonLogger.setLogger(h),_logging.KameleoonLogger.debug`CALL: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`;const{settings:i}=new _clientSettings.ClientSettings(c,e);this.environment=i.environment;const{externalStorage:j,externalEventSource:k,externalPackageInfo:l,externalVisitorCodeManager:m,externalRequester:n,externalPRNG:o,customDataManager:p}=f.externals,{useAbortController:q}=f.settings,r=new _cacheManager.CacheManager(_constants.CACHE_CLEANUP_TIMEOUT),s=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ClientData),t=new _storage.DataStorage(j,_storage.KameleoonStorageKey.VariationData),u=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedExperimentVariation),v=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ForcedFeatureVariation),w=new _storage.DataStorage(j,_storage.KameleoonStorageKey.ConsentData),x=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TrackingData);let y=p;if(!y){const a=new _storage.DataStorage(j,_storage.KameleoonStorageKey.TargetingData),b=new _storage.DataStorage(j,_storage.KameleoonStorageKey.DataInfo);y=new _kameleoonData.DataManager({dataStorage:a,infoStorage:b,cleanupInterval:i.cleanupInterval,packageInfo:l})}const z=null!==(b=null===d||void 0===d?void 0:d.urlProvider)&&void 0!==b?b:new _requester.UrlProvider;z.initialize({domain:i.networkDomain,siteCode:i.siteCode,packageInfo:l,environment:i.environment});const A=new _requester.Requester({urlProvider:z,useAbortController:q,packageInfo:l,externalRequester:n,requestTimeout:i.requestTimeout,trackRetryDelay:i.trackRetryDelay}),B=new _eventSource.KameleoonEventSource({siteCode:i.siteCode,externalEventSource:k,urlProvider:z}),C=new _eventManager.EventManager,D=new _clientConfiguration.ClientConfiguration({urlProvider:z,storage:s,updateInterval:i.updateInterval,dataManager:y,eventManager:C,requester:A,eventSource:B,externalVisitorCodeManager:m}),E=new _variationConfiguration.VariationConfiguration(t,u,v,m,D),F=new _tracking.Tracker({dataManager:y,trackingStorage:x,variationConfiguration:E,requester:A,trackingInterval:i.trackingInterval,prng:o});this.tracker=F,this.variationConfiguration=E,this.requester=A,this.trackingCache=r,this.dataManager=y,this.clientConfiguration=D,this.externalPackageInfo=l,this.consentDataStorage=w,this.visitorCodeManager=m,this.eventManager=C,null!==i.cleanupInterval&&new _storage.StorageCleanupManager(j,i.cleanupInterval),_logging.KameleoonLogger.debug`RETURN: new KameleoonClient(siteCode: ${c}, dependencies: ${d}, configuration: ${e})`}async initialize(){if(this.stubMode)return!1;_logging.KameleoonLogger.info("CALL: KameleoonClient.initialize()");const a=await this.clientConfiguration.initialize();return a.throw(),this.initialized=!0,_logging.KameleoonLogger.info`RETURN: KameleoonClient.initialize() -> (result: ${a.ok})`,a.ok}addData(a){if(this.stubMode)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];if(_logging.KameleoonLogger.info`CALL: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`,this.visitorCodeManager.validateVisitorCode(a).throw(),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.dataManager.storeData(a,...c).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.addData(visitorCode: ${a}, data: ${c})`}async getRemoteVisitorData(a){let{visitorCode:b,shouldAddData:c=!0,filters:d=_constants.DEFAULT_VISITOR_DATA_FILTERS}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(b).throw();const{previousVisitAmount:e}=d;if("number"==typeof e&&(1>e||25<e))throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.VisitAmount);const f=this.dataManager.isUniqueIdentifier(b),g=await this.requester.getVisitorData({visitorCode:b,filters:d,isMappingIdentifier:f}),h=g.throw(),{visitorData:i,storageVisitorData:j,visitsData:k,mappingIdentifier:l}=_utilities.Parser.parseVisitorData({data:h,filters:d,visitorCode:b,dataManager:this.dataManager,variationConfiguration:this.variationConfiguration});for(const d of j)(c||this.dataManager.isPersistentCustomData(d))&&this.addData(b,d);return k&&c&&this.addData(b,k),null!==d&&void 0!==d&&d.visitorCode&&l&&this.dataManager.setMappingIdentifier(b,l),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteVisitorData(visitorCode: ${b}, shouldAddData: ${c}, filters: ${d}) -> (visitorData: ${i})`,i}trackConversion(a){let{visitorCode:b,goalId:c,negative:d,revenue:e,metadata:f}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`,this.addData(b,new _kameleoonData.Conversion({goalId:c,revenue:e,negative:d,metadata:f})),this.flush(b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.trackConversion(visitorCode: ${b}, goalId: ${c}, negative: ${d}, revenue: ${e}, metadata: ${f})`)}flush(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.flush(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if("string"==typeof a)return this.visitorCodeManager.validateVisitorCode(a).throw(),this.tracker.scheduleVisitor(a,this._isConsentProvided(a)),void _logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`;for(const b of this.dataManager.unsentDataVisitors)this.tracker.scheduleVisitor(b,this._isConsentProvided(b));_logging.KameleoonLogger.info`RETURN: KameleoonClient.flush(visitorCode: ${a})`}getFeatureFlags(){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info("CALL: KameleoonClient.getFeatureFlags()"),!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);const a=this.clientConfiguration.featureFlags,b=[];return a.forEach(a=>{let{id:c,featureKey:d}=a;b.push({id:c,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlags() -> (FeatureFlags: ${b})`,b}getVisitorFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=[];return b.forEach(a=>{let{featureFlagId:b,featureKey:d}=a;c.push({id:b,key:d})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getVariation(a){let{visitorCode:b,featureKey:c,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=this._getFeatureVariation({visitorCode:b,featureKey:c,track:d}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${e})`,e}getVariations(a){let{visitorCode:b,onlyActive:c=!1,track:d=!0}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=new Map,f=this.clientConfiguration.featureFlags;for(const g of f.values()){const a=this._getFeatureVariation({visitorCode:b,featureKey:g.featureKey,track:d});a.ok&&(!c||a.data.key!==_constants.OFF_VARIATION_KEY)&&e.set(g.featureKey,a.data)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVariations(visitorCode: ${b}, onlyActive: ${c}, track: ${d}) -> (variations: ${e})`,e}getActiveFeatureFlags(a){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a})`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.visitorCodeManager.validateVisitorCode(a).throw();const b=this._getActiveFeatureVariations(a),c=new Map;return b.forEach(b=>{const{variationKey:d,featureKey:e,variationId:f,experimentId:g}=b;let h=[];null!==f&&null!==g&&(h=this._getFeatureVariables({visitorCode:a,featureKey:e,variationKey:d}));const i=h.map(a=>_utilities.Parser.parseFeatureVariable(a).throw());c.set(b.featureKey,{key:d,id:f,experimentId:g,variables:i})}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getActiveFeatureFlags(visitorCode: ${a}) -> (FeatureFlags: ${c})`,c}getFeatureFlagVariationKey(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw();return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariationKey(visitorCode: ${a}, featureKey: ${b}) -> (variationKey: ${c})`,c}getFeatureFlagVariable(a){let{visitorCode:b,featureKey:c,variableKey:d}=a;if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const{key:e}=this._getFeatureVariation({visitorCode:b,featureKey:c,track:!0}).throw(),f=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:e}),g=f.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariableNotFound,d,b);const{type:h,value:i}=_utilities.Parser.parseFeatureVariable(g).throw(),j={type:h,value:i};return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariable(visitorCode: ${b}, featureKey: ${c}, variableKey: ${d}) -> (FeatureFlagVariable: ${j})`,j}getFeatureFlagVariables(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);_logging.KameleoonLogger.info`CALL: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b})`,this.visitorCodeManager.validateVisitorCode(a).throw();const{key:c}=this._getFeatureVariation({visitorCode:a,featureKey:b,track:!0}).throw(),d=this._getFeatureVariables({visitorCode:a,featureKey:b,variationKey:c}),e=[];for(const c of d){const a=_utilities.Parser.parseFeatureVariable(c).throw();e.push(a)}return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getFeatureFlagVariables(visitorCode: ${a}, featureKey: ${b}) -> (FeatureFlagVariables: ${e})`,e}isFeatureFlagActive(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);let[c,d,e]=["","",!0];"string"==typeof a?(c=a,d=b):([c,d]=[a.visitorCode,a.featureKey],a.track!==void 0&&(e=a.track)),_logging.KameleoonLogger.info`CALL: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track ${e})`,this.visitorCodeManager.validateVisitorCode(c).throw();try{const{key:a}=this._getFeatureVariation({visitorCode:c,featureKey:d,track:e}).throw(),b=a!==_constants.OFF_VARIATION_KEY;return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: ${b})`,b}catch(a){if(a instanceof _kameleoonError.KameleoonError&&a.type===_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.isFeatureFlagActive(visitorCode: ${c}, featureKey: ${d}, track: ${e}) -> (isActive: false)`,!1;throw a}}async getRemoteData(a){if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getRemoteData(key: ${a})`;const b=await this.requester.getRemoteData(a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getRemoteData(key: ${a}) -> (remoteData: ${b})`,b.throw()}async getVisitorWarehouseAudience(a){let{visitorCode:b,customDataIndex:c,warehouseKey:d}=a;if(this.stubMode)return null;_logging.KameleoonLogger.info`CALL: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw();const e=await this.getRemoteData(d||b);if(!e)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData,`No data found for ${d||b} key`);if(!e[_constants.WAREHOUSE_AUDIENCE_KEY]||0===Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]).length)return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: null)`,null;const f=new _kameleoonData.CustomData(c,...Object.keys(e[_constants.WAREHOUSE_AUDIENCE_KEY]));return this.dataManager.storeData(b,f),_logging.KameleoonLogger.info`RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${b}, customDataIndex: ${c}, warehouseKey: ${d}) -> (customData: ${f})`,f}onEvent(a,b){if(this.stubMode)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);if(_logging.KameleoonLogger.info`CALL: KameleoonClient.onEvent(event: ${a}, callback)`,!this.initialized)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization);this.eventManager.addEventHandler(a,b),_logging.KameleoonLogger.info`RETURN: KameleoonClient.onEvent(event: ${a}, callback)`}getEngineTrackingCode(a){if(this.stubMode)return"";_logging.KameleoonLogger.info`CALL: KameleoonClient.getEngineTrackingCode(visitorCode: ${a})`,this.visitorCodeManager.validateVisitorCode(a).throw();const b=_utilities.Utilities.getTrackingCode(this.trackingCache,a);return _logging.KameleoonLogger.info`RETURN: KameleoonClient.getEngineTrackingCode(visitorCode: ${a}) -> (trackingCode: ${b})`,b}isInitialized(){return _logging.KameleoonLogger.debug`CALL/RETURN: KameleoonClient.isInitialized() -> (initialized: ${this.initialized})`,this.initialized}setLogLevel(a){_logging.KameleoonLogger.setLogLevel(a)}setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this._setForcedVariation({visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e}).throw(),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`)}setUserConsent(a){let{visitorCode:b,consent:c,setData:d}=a;this.stubMode||(_logging.KameleoonLogger.info`CALL: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`,this.visitorCodeManager.validateVisitorCode(b).throw(),this.updateConsentData(b,c),c?d({visitorCode:b,key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.DEFAULT_MAX_AGE,path:_visitorCodeManager.PATH}):this.visitorCodeManager.consentRequired&&d({visitorCode:"",key:_storage.KameleoonStorageKey.VisitorCode,maxAge:_visitorCodeManager.ZERO_MAX_AGE,path:_visitorCodeManager.PATH}),_logging.KameleoonLogger.info`RETURN: KameleoonClient.setUserConsent(visitorCode: ${b}, consent: ${c}, setData: ${d})`)}updateConsentData(a,b){const c=this.consentDataStorage.read();if(!c.ok)return void(c.error.type===_kameleoonError.KameleoonException.StorageEmpty&&this.consentDataStorage.write({[a]:{consent:b}}));const d=c.data;d[a]={consent:b},this.consentDataStorage.write(d)}_isConsentProvided(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._isConsentProvided(visitorCode: ${a})`;const{isConsentRequired:b}=this.clientConfiguration,c=this.consentDataStorage.read();let d=!1;if(!b)d=!0;else if(c.ok){const b=c.data[a];d="boolean"==typeof b?b:b&&b.consent}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isConsentProvided(visitorCode: ${a}) -> (isConsentProvided: ${d})`,d}_getFeatureVariables(a){let{visitorCode:b,featureKey:c,variationKey:d}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d})`;const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c);const g=f.variations.find(a=>a.key===d);if(!g)throw new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariables(visitorCode: ${b}, featureKey: ${c}, variationKey: ${d}) -> (variables: ${g.variables})`,g.variables}_getActiveFeatureVariations(a){_logging.KameleoonLogger.debug`CALL: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a})`;const b=this.clientConfiguration.featureFlags,c=[];for(const d of b.values()){if(!d.environmentEnabled)continue;const b=this._evaluate({visitorCode:a,featureFlag:d,track:!1,save:!1});b.variationKey!==_constants.OFF_VARIATION_KEY&&c.push({variationKey:b.variationKey,variationId:b.variationId,experimentId:b.experimentId,featureFlagId:d.id,featureKey:d.featureKey,rule:null,isTargetedRule:b.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY})}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getActiveFeatureVariations(visitorCode: ${a}) -> (activeVariations: ${c})`,c}_evaluate(a){let{visitorCode:b,featureFlag:c,track:d,save:e}=a;_logging.KameleoonLogger.debug`CALL: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e})`;let f,g=null;const h=this.variationConfiguration.getForcedFeatureVariation(b,c.featureKey);if(h.ok&&(g=h.data),g)f=KameleoonClient.EvaluatedExperiment.fromForcedFeatureVariation(c.defaultVariationKey,g);else if(this._isVisitorNotInHoldout(b,d,e)&&this._isFFUnrestrictedByMEGroup(b,c)){const a=this.dataManager.getVisitorData(b),g=this.dataManager.getVisitorIdentifier(b),h=this.variationConfiguration.getVariation({visitorCode:b,visitorIdentifier:g,featureFlag:c,track:d,withAssignment:e,targetingData:a,clientConfiguration:this.clientConfiguration,dataManager:this.dataManager,packageInfo:this.externalPackageInfo}).throw();f=KameleoonClient.EvaluatedExperiment.fromVariationData(h)}else f=KameleoonClient.EvaluatedExperiment.fromDefaultVariationKey(c.defaultVariationKey);return e&&!f.isSimulated&&null!==f.experimentId&&null!==f.variationId&&this.variationConfiguration.updateStoredVariations(b,{[f.experimentId]:{variationId:f.variationId,isTargetedRule:f.ruleType===_clientConfiguration.RuleType.TARGETED_DELIVERY,status:d?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}}),this.eventManager.fireEvent(_eventManager.EventType.Evaluation,{featureKey:c.featureKey,variation:{key:f.variationKey,experimentId:f.experimentId,id:f.variationId}}),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._evaluate(visitorCode: ${b}, featureFlag: ${c}, track: ${d}, save: ${e}) -> (evalExp: ${f})`,f}_isFFUnrestrictedByMEGroup(a,b){const c=b.mutuallyExclusiveGroup;if(!c)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: ${a}, featureFlag: ${b})`;let d=!0;const e=this.clientConfiguration.meGroups.get(c);if(e){const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDoubleForMEGroup(f,c);_logging.KameleoonLogger.debug`Calculated meGroup hash ${g} for code: '${f}', meGroup: '${c}'`,d=e.getFeatureFlagByHash(g)===b}return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._isFFUnrestrictedByMEGroup(visitorCode: '${a}', featureFlag: ${b}) -> (selected: ${d})`,d}_getFeatureVariation(a){let{visitorCode:b,featureKey:c,track:d}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d})`,!this.initialized)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.Initialization));const e=this.clientConfiguration.featureFlags,f=e.get(c);if(!f)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagConfigurationNotFound,c));if(!f.environmentEnabled)return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagEnvironmentDisabled,f.featureKey,this.environment));const g=this._evaluate({visitorCode:b,featureFlag:f,track:d,save:!0}),{experimentId:h,variationId:i,variationKey:j,isSimulated:k}=g;let l=new Map,m=!1;try{const a=this._getFeatureVariables({visitorCode:b,featureKey:c,variationKey:j});a.forEach(a=>{m||a.type!==_types.VariableType.JS&&a.type!==_types.VariableType.CSS||(m=!0);const b=_utilities.Parser.parseFeatureVariable(a).throw();l.set(a.key,b)})}catch(_){}h&&"number"==typeof i&&!k&&_utilities.Utilities.updateCache({cacheManager:this.trackingCache,hasJsCssVariables:m,visitorCode:b,experimentId:h,variationId:i}),d&&!k&&this.tracker.scheduleVisitor(b,this._isConsentProvided(b));const n={key:j,id:i,experimentId:h,variables:l};return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._getFeatureVariation(visitorCode: ${b}, featureKey: ${c}, track: ${d}) -> (variation: ${n})`,(0,_tsRes.Ok)(n)}_isVisitorNotInHoldout(a,b,c){const d=this.clientConfiguration.holdout;if(!d)return!0;_logging.KameleoonLogger.debug`CALL: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c})`;let e=!0;const f=this.dataManager.getVisitorIdentifier(a),g=_hasher.Hasher.getHashDouble({visitorIdentifier:f,respoolTime:null,id:d.experimentId+""});_logging.KameleoonLogger.debug`Calculated holdoutHash: ${g} for visitorCode: ${f}`;let h=_utilities.Utilities.getVariationByHash(d.variationByExposition,g);return null!==h&&(e=h.variationKey!==_constants.IN_HOLDOUT_VARIATION_KEY,c&&this.variationConfiguration.updateStoredVariations(a,{[d.experimentId]:{variationId:h.variationId,isTargetedRule:!1,status:b?_types.TrackingStatus.Unsent:_types.TrackingStatus.Sent}})),_logging.KameleoonLogger.debug`RETURN: KameleoonClient._isVisitorNotInHoldout(visitorCode: ${a}, track: ${b}, save: ${c}) -> (isNotInHoldout: ${e})`,e}_setForcedVariation(a){let{visitorCode:b,experimentId:c,variationKey:d,forceTargeting:e=!0}=a;if(_logging.KameleoonLogger.debug`CALL: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e})`,null===d){const a=this.variationConfiguration.updateForcedExperimentVariation(b,c,null);return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${a})`,a}let f=null,g=null;if(f=this.clientConfiguration.experimentMap.get(c),!f)return _logging.KameleoonLogger.error`Experiment with id ${c} not found for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagExperimentNotFound,c,b));if(g=f.variations.get(d),void 0===g)return _logging.KameleoonLogger.error`Variation with key ${d} not found in experiment ${f} for visitor ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.FeatureFlagVariationNotFound,d,b));f={type:f.type,experimentId:c},g={variationKey:d,variationId:g};const h=this.variationConfiguration.updateForcedExperimentVariation(b,c,{rule:f,varByExp:g,forceTargeting:e});return _logging.KameleoonLogger.debug`RETURN: KameleoonClient._setForcedVariation(visitorCode: '${b}', experimentId: ${c}, variationKey: '${d}', forceTargeting: ${e}) -> (writeResult: ${h})`,h}}exports.KameleoonClient=KameleoonClient,_defineProperty(KameleoonClient,"EvaluatedExperiment",class{static fromForcedFeatureVariation(a,b){var c,d,e;let f=a;return b.varByExp?f=b.varByExp.variationKey:b.rule&&b.rule.type===_clientConfiguration.RuleType.EXPERIMENTATION&&(f=_constants.OFF_VARIATION_KEY),{variationKey:f,variationId:(null===(c=b.varByExp)||void 0===c?void 0:c.variationId)||null,experimentId:(null===(d=b.rule)||void 0===d?void 0:d.experimentId)||null,ruleType:(null===(e=b.rule)||void 0===e?void 0:e.type)||null,isSimulated:b.simulated}}static fromVariationData(a){var b,c;return{variationKey:a.variationKey,variationId:a.variationId,experimentId:a.experimentId,ruleType:null!==(b=null===(c=a.rule)||void 0===c?void 0:c.type)&&void 0!==b?b:null,isSimulated:!1}}static fromDefaultVariationKey(a){return{variationKey:a,variationId:null,experimentId:null,ruleType:null,isSimulated:!1}}});
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Result } from 'ts-res';
|
|
2
3
|
import { KameleoonError } from '../kameleoonError';
|
|
3
|
-
import { SegmentType, Tree } from '../targeting';
|
|
4
|
+
import { SegmentType, TargetingDataType, Tree } from '../targeting';
|
|
5
|
+
import { DataProcessor } from './dataProcessor';
|
|
4
6
|
import { CustomData } from './customData';
|
|
5
7
|
import { DataManagerParametersType, KameleoonData, KameleoonDataType, KameleoonVisitorDataType, VisitorsDataType } from './types';
|
|
8
|
+
import { IStorage } from '../storage';
|
|
6
9
|
import { CustomDataConfigurationType } from '../clientConfiguration';
|
|
7
|
-
import { MappingIdentifierType } from '../storage/types';
|
|
8
|
-
|
|
10
|
+
import { DataInfoType, MappingIdentifierType } from '../storage/types';
|
|
11
|
+
import { ExternalPackageInfoType } from '../sdkInfoTypes';
|
|
12
|
+
import { StaticData } from '../kameleoonData/staticData';
|
|
13
|
+
export interface IDataManager {
|
|
9
14
|
storeData(data: VisitorsDataType): Result<void, KameleoonError>;
|
|
10
15
|
storeTrackedData(data: VisitorsDataType): void;
|
|
11
16
|
getTree(segment: SegmentType): Tree;
|
|
@@ -16,7 +21,7 @@ interface IDataManager {
|
|
|
16
21
|
getVisitorData(visitorCode: string): KameleoonVisitorDataType | undefined;
|
|
17
22
|
getVisitorIdentifier(visitorCode: string): string;
|
|
18
23
|
getPendingData(visitorCode: string): KameleoonDataType[];
|
|
19
|
-
getUnsentData(visitorCode: string): KameleoonDataType[];
|
|
24
|
+
getUnsentData(visitorCode: string): (KameleoonDataType | StaticData)[];
|
|
20
25
|
getVisitorStoredDataTypes(visitorCode: string): Set<KameleoonData>;
|
|
21
26
|
readonly identifierCustomDataIndex: number | null;
|
|
22
27
|
readonly storedCustomDataIndexes: Set<number>;
|
|
@@ -24,17 +29,17 @@ interface IDataManager {
|
|
|
24
29
|
readonly unsentDataVisitors: string[];
|
|
25
30
|
}
|
|
26
31
|
export declare class DataManager implements IDataManager {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
protected dataStorage: IStorage<TargetingDataType>;
|
|
33
|
+
protected infoStorage: IStorage<DataInfoType>;
|
|
34
|
+
protected dataProcessor: DataProcessor;
|
|
35
|
+
protected targetingTrees: Map<string, Tree>;
|
|
36
|
+
protected mappingIdentifierCustomDataIndex: number | null;
|
|
37
|
+
protected persistentCustomDataIndexes: Set<number>;
|
|
38
|
+
protected localCustomDataIndexes: Set<number>;
|
|
39
|
+
protected cleanupIntervalId: NodeJS.Timeout | null;
|
|
40
|
+
protected packageInfo: ExternalPackageInfoType;
|
|
36
41
|
constructor({ dataStorage, infoStorage, cleanupInterval, packageInfo, }: DataManagerParametersType);
|
|
37
|
-
getUnsentData(visitorCode: string): KameleoonDataType[];
|
|
42
|
+
getUnsentData(visitorCode: string): (KameleoonDataType | StaticData)[];
|
|
38
43
|
getPendingData(visitorCode: string): KameleoonDataType[];
|
|
39
44
|
private getDataFromRaw;
|
|
40
45
|
storeTrackedData(data: VisitorsDataType): void;
|
|
@@ -45,6 +50,7 @@ export declare class DataManager implements IDataManager {
|
|
|
45
50
|
isPersistentCustomData(dataItem: KameleoonDataType): dataItem is CustomData;
|
|
46
51
|
isUniqueIdentifier(visitorCode: string): boolean;
|
|
47
52
|
getVisitorIdentifier(visitorCode: string): string;
|
|
53
|
+
getMappingIdentifier(visitorCode: string): MappingIdentifierType | undefined;
|
|
48
54
|
setMappingIdentifier(visitorCode: string, mappingIdentifier: MappingIdentifierType): void;
|
|
49
55
|
getVisitorData(visitorCode: string): KameleoonVisitorDataType | undefined;
|
|
50
56
|
getVisitorStoredDataTypes(visitorCode: string): Set<KameleoonData>;
|
|
@@ -58,4 +64,3 @@ export declare class DataManager implements IDataManager {
|
|
|
58
64
|
get storedCustomDataIndexes(): Set<number>;
|
|
59
65
|
set customDataIndexes(customData: CustomDataConfigurationType[]);
|
|
60
66
|
}
|
|
61
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_customData=require("./customData"),_types=require("./types"),_storage=require("../storage"),_clientConfiguration=require("../clientConfiguration"),_utilities=require("../utilities"),_conversion=require("./conversion"),_pageView=require("./pageView"),_browser=require("./browser"),_device=require("./device"),_geolocation=require("./geolocation"),_types2=require("../types"),_operatingSystem=require("./operatingSystem"),_logging=require("../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{dataStorage:b,infoStorage:c,cleanupInterval:d,packageInfo:e}=a;if(_defineProperty(this,"dataStorage",void 0),_defineProperty(this,"infoStorage",void 0),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"cleanupIntervalId",null),_defineProperty(this,"packageInfo",void 0),_logging.KameleoonLogger.debug`CALL: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`,this.dataStorage=b,this.infoStorage=c,this.dataProcessor=new _dataProcessor.DataProcessor(d,e),this.packageInfo=e,d){const a=()=>{this.cleanupData()};try{this.cleanupIntervalId=setInterval(a,d)}catch(a){throw this.cleanupIntervalId&&clearInterval(this.cleanupIntervalId),_logging.KameleoonLogger.error`Failed to set cleanup interval: ${d}`,a}}_logging.KameleoonLogger.debug`RETURN: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`}getUnsentData(a){const b=this.infoStorage.read();if(!b.ok)return[];const c=b.data,d=this.getVisitorData(a);if(!c.unsentData[a]||!d)return[];const e=c.unsentData[a],f=c.nextVisitTime<=Date.now(),g=a=>{let{status:b,key:c,cdIndex:d}=a;return!!("number"==typeof d&&this.persistentCustomDataIndexes.has(d)&&f)||e.includes(c)&&b===_types2.TrackingStatus.Unsent};return f&&(c.nextVisitTime=Date.now()+_storage.VISIT_DURATION,this.infoStorage.write(c)),this.getDataFromRaw(d,g)}getPendingData(a){const b=this.getVisitorData(a);if(!b)return[];return this.getDataFromRaw(b,a=>{let{status:b}=a;return b===_types2.TrackingStatus.Pending})}getDataFromRaw(a,b){const c=[];for(const[d,e]of Object.entries(a))if(e)switch(d){case _types.KameleoonData.CustomData:{for(const a of Object.values(e)){if(!a)continue;const{status:e,index:f}=a;if(b({status:e,key:d,cdIndex:f})){const b=_customData.CustomData._fromRaw(a);c.push(b)}}break}case _types.KameleoonData.Conversion:{for(const a of Object.values(e))if(a&&b({status:a.status,key:d})){const b=_conversion.Conversion._fromRaw(a);c.push(b)}break}case _types.KameleoonData.PageView:{for(const a of Object.values(e))if(b({status:a.status,key:d})){const b=_pageView.PageView._fromRaw(a);c.push(b)}break}case _types.KameleoonData.GeolocationData:{const a=e;if(!e)continue;if(b({status:a.status,key:d})){const b=_geolocation.GeolocationData._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Browser:{const a=e;if(b({status:a.status,key:d})){const b=_browser.Browser._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Device:{const a=e;if(b({status:a.status,key:d})){const b=_device.Device._fromRaw(a);c.push(b)}break}case _types.KameleoonData.OperatingSystem:{const a=e;if(b({status:a.status,key:d})){const b=_operatingSystem.OperatingSystem._fromRaw(a);c.push(b)}}}return c}storeTrackedData(a){this.storeData(a);const b=this.infoStorage.read();if(b.ok){const c=b.data.unsentData;for(const[b,d]of Object.entries(a)){if(!c[b])return;const a=new Set(c[b]);d.forEach(b=>{let{data:c}=b;a.has(c.type)&&a.delete(c.type)});const e=d.some(a=>{let{data:b}=a;if(b.type!==_types.KameleoonData.CustomData)return!1;const{index:c}=b;return this.persistentCustomDataIndexes.has(c)||this.mappingIdentifierCustomDataIndex===c});e&&a.add(_types.KameleoonData.CustomData),c[b]=Array.from(a),c[b].length||delete c[b]}this.infoStorage.write(b.data)}}storeData(a){for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];_logging.KameleoonLogger.debug`CALL: DataManager.storeData(visitorCode: ${a}, data: ${c})`;const e=this.dataStorage.read(),f=this.infoStorage.read();if(!e.ok)return e;if(!f.ok)return f;const g=e.data,h=f.data;if("string"==typeof a)this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:a,kameleoonData:c});else for(const[b,c]of Object.entries(a))this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:b,kameleoonData:c});this.cleanupData(),this.infoStorage.write(f.data);const i=this.dataStorage.write(g);return _logging.KameleoonLogger.debug`RETURN: DataManager.storeData(visitorCode: ${a}, data: ${c}) -> (writeResult: ${i})`,i}getTree(a){if(this.targetingTrees.has(a.id))return this.targetingTrees.get(a.id);const b=new _targeting.Tree(a);return this.targetingTrees.set(a.id,b),b}clearTrees(){this.targetingTrees.clear()}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}isUniqueIdentifier(a){var b;const c=this.getVisitorData(a),d=null===c||void 0===c?void 0:c[_types.KameleoonData.UniqueIdentifier];return!(null===(b=null===d||void 0===d?void 0:d.value)||void 0===b)&&b}getVisitorIdentifier(a){var b,c,d;const e=this.infoStorage.read();if(!e.ok)return a;const f=e.data;return null!==(b=f.mappingIdentifiers)&&void 0!==b?b:f.mappingIdentifiers={},null!==(c=null===(d=f.mappingIdentifiers[a])||void 0===d?void 0:d.mappingIdentifier)&&void 0!==c?c:a}setMappingIdentifier(a,b){var c;const d=this.infoStorage.read();if(d.ok){const e=d.data;null!==(c=e.mappingIdentifiers)&&void 0!==c?c:e.mappingIdentifiers={};const f=e.mappingIdentifiers[a];(!f||f.timestamp<b.timestamp)&&(e.mappingIdentifiers[a]=b,this.infoStorage.write(e))}}getVisitorData(a){this.cleanupData();const b=this.dataStorage.read();if(!b.ok)return;let{visitorReference:c,data:d,isReference:e}=this.dataProcessor.dereferenceData(b.data,a);if(this.packageInfo.isServer&&e&&!d[c]){const b=this.infoStorage.read();b.ok&&b.data.mappingIdentifiers&&delete b.data.mappingIdentifiers[a],delete d[a],c=a}return d[c]}getVisitorStoredDataTypes(a){const b=this.getVisitorData(a);return b?new Set(Object.keys(b)):new Set}getLinkedVisitor(a){const b=this.dataStorage.read();if(!b.ok)return null;if("string"==typeof b.data[a])return b.data[a];if(null===this.mappingIdentifierCustomDataIndex)return null;const c=b.data[a];if(!c)return null;const d=c[_types.KameleoonData.CustomData];return d&&d[this.mappingIdentifierCustomDataIndex]?d[this.mappingIdentifierCustomDataIndex].value[0]:null}mutUpdateTargetingData(a){let{infoData:b,visitorCode:c,kameleoonData:d,targetingData:e}=a;for(const f of d){f.data.type===_types.KameleoonData.CustomData&&this.processCustomData({infoData:b,customData:f,mutData:e,visitorCode:c});const a=this.dataProcessor.mutUpdateData({infoData:b,visitorCode:c,mutData:e,dataItem:f}),d=b.nextDataCleanup;(!d||d&&a<d)&&(b.nextDataCleanup=a),f.data.status===_types2.TrackingStatus.Unsent&&this.dataProcessor.mutAddUnsentData({mutData:b,visitorCode:c,dataType:f.data.type})}}cleanupData(){const a=this.dataStorage.read(),b=this.infoStorage.read();if(!a.ok||!b.ok)return;const c=a.data,d=b.data,e=d.nextDataCleanup;if(e&&e<Date.now()){const a=this.dataProcessor.mutCleanupData(c,d);d.nextDataCleanup=a||void 0,this.infoStorage.write(d),this.dataStorage.write(c)}}processCustomData(a){let{infoData:b,mutData:c,customData:d,visitorCode:e}=a;const{data:f}=d,g=!!(f.value.length&&f.value[0].length);if(this.mappingIdentifierCustomDataIndex===f.index&&g){d._isMappingIdentifier=!0;const a=f.value[0];if(e!==a){var h;_logging.KameleoonLogger.info`Linked anonymous visitor ${e} with user ${a}`,this.dataProcessor.createReference({infoData:b,mutData:c,visitorCode:e,linkedVisitor:f.value[0]}),null!==(h=b.mappingIdentifiers)&&void 0!==h?h:b.mappingIdentifiers={},b.mappingIdentifiers[a]={mappingIdentifier:e,timestamp:Date.now()}}}this.localCustomDataIndexes.has(f.index)&&(d.status=_types2.TrackingStatus.Sent)}get unsentDataVisitors(){const a=this.infoStorage.read();return a.ok?Object.keys(a.data.unsentData):[]}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get trees(){return this.targetingTrees}get storedCustomDataIndexes(){const a=this.dataStorage.read();if(!a.ok)return new Set;const b=a.data;if(!(_types.KameleoonData.CustomData in b))return new Set;const c=new Set;for(const a in Object.keys(b[_types.KameleoonData.CustomData]))c.add(+a);return c}set customDataIndexes(a){var b;const[c,d]=[[],[]];a.forEach(a=>{a.localOnly&&c.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&d.push(a.index)}),this.mappingIdentifierCustomDataIndex=(null===(b=a.find(a=>a.isMappingIdentifier))||void 0===b?void 0:b.index)||null,this.localCustomDataIndexes=new Set(c),this.persistentCustomDataIndexes=new Set(d)}}exports.DataManager=DataManager;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_customData=require("./customData"),_types=require("./types"),_storage=require("../storage"),_clientConfiguration=require("../clientConfiguration"),_utilities=require("../utilities"),_conversion=require("./conversion"),_pageView=require("./pageView"),_browser=require("./browser"),_device=require("./device"),_geolocation=require("./geolocation"),_types2=require("../types"),_operatingSystem=require("./operatingSystem"),_logging=require("../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{dataStorage:b,infoStorage:c,cleanupInterval:d,packageInfo:e}=a;if(_defineProperty(this,"dataStorage",void 0),_defineProperty(this,"infoStorage",void 0),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"cleanupIntervalId",null),_defineProperty(this,"packageInfo",void 0),_logging.KameleoonLogger.debug`CALL: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`,this.dataStorage=b,this.infoStorage=c,this.dataProcessor=new _dataProcessor.DataProcessor(d,e),this.packageInfo=e,d){const a=()=>{this.cleanupData()};try{this.cleanupIntervalId=setInterval(a,d)}catch(a){throw this.cleanupIntervalId&&clearInterval(this.cleanupIntervalId),_logging.KameleoonLogger.error`Failed to set cleanup interval: ${d}`,a}}_logging.KameleoonLogger.debug`RETURN: new DataManager(dataStorage, infoStorage, cleanupInterval: ${d})`}getUnsentData(a){const b=this.infoStorage.read();if(!b.ok)return[];const c=b.data,d=this.getVisitorData(a);if(!c.unsentData[a]||!d)return[];const e=c.unsentData[a],f=c.nextVisitTime<=Date.now(),g=a=>{let{status:b,key:c,cdIndex:d}=a;return!!("number"==typeof d&&this.persistentCustomDataIndexes.has(d)&&f)||e.includes(c)&&b===_types2.TrackingStatus.Unsent};return f&&(c.nextVisitTime=Date.now()+_storage.VISIT_DURATION,this.infoStorage.write(c)),this.getDataFromRaw(d,g)}getPendingData(a){const b=this.getVisitorData(a);if(!b)return[];return this.getDataFromRaw(b,a=>{let{status:b}=a;return b===_types2.TrackingStatus.Pending})}getDataFromRaw(a,b){const c=[];for(const[d,e]of Object.entries(a))if(e)switch(d){case _types.KameleoonData.CustomData:{for(const a of Object.values(e)){if(!a)continue;const{status:e,index:f}=a;if(b({status:e,key:d,cdIndex:f})){const b=_customData.CustomData._fromRaw(a);c.push(b)}}break}case _types.KameleoonData.Conversion:{for(const a of Object.values(e))if(a&&b({status:a.status,key:d})){const b=_conversion.Conversion._fromRaw(a);c.push(b)}break}case _types.KameleoonData.PageView:{for(const a of Object.values(e))if(b({status:a.status,key:d})){const b=_pageView.PageView._fromRaw(a);c.push(b)}break}case _types.KameleoonData.GeolocationData:{const a=e;if(!e)continue;if(b({status:a.status,key:d})){const b=_geolocation.GeolocationData._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Browser:{const a=e;if(b({status:a.status,key:d})){const b=_browser.Browser._fromRaw(a);c.push(b)}break}case _types.KameleoonData.Device:{const a=e;if(b({status:a.status,key:d})){const b=_device.Device._fromRaw(a);c.push(b)}break}case _types.KameleoonData.OperatingSystem:{const a=e;if(b({status:a.status,key:d})){const b=_operatingSystem.OperatingSystem._fromRaw(a);c.push(b)}}}return c}storeTrackedData(a){this.storeData(a);const b=this.infoStorage.read();if(b.ok){const c=b.data.unsentData;for(const[b,d]of Object.entries(a)){if(!c[b])return;const a=new Set(c[b]);d.forEach(b=>{let{data:c}=b;a.has(c.type)&&a.delete(c.type)});const e=d.some(a=>{let{data:b}=a;if(b.type!==_types.KameleoonData.CustomData)return!1;const{index:c}=b;return this.persistentCustomDataIndexes.has(c)||this.mappingIdentifierCustomDataIndex===c});e&&a.add(_types.KameleoonData.CustomData),c[b]=Array.from(a),c[b].length||delete c[b]}this.infoStorage.write(b.data)}}storeData(a){for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];_logging.KameleoonLogger.debug`CALL: DataManager.storeData(visitorCode: ${a}, data: ${c})`;const e=this.dataStorage.read(),f=this.infoStorage.read();if(!e.ok)return e;if(!f.ok)return f;const g=e.data,h=f.data;if("string"==typeof a)this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:a,kameleoonData:c});else for(const[b,c]of Object.entries(a))this.mutUpdateTargetingData({infoData:h,targetingData:g,visitorCode:b,kameleoonData:c});this.cleanupData(),this.infoStorage.write(f.data);const i=this.dataStorage.write(g);return _logging.KameleoonLogger.debug`RETURN: DataManager.storeData(visitorCode: ${a}, data: ${c}) -> (writeResult: ${i})`,i}getTree(a){if(this.targetingTrees.has(a.id))return this.targetingTrees.get(a.id);const b=new _targeting.Tree(a);return this.targetingTrees.set(a.id,b),b}clearTrees(){this.targetingTrees.clear()}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}isUniqueIdentifier(a){var b;const c=this.getVisitorData(a),d=null===c||void 0===c?void 0:c[_types.KameleoonData.UniqueIdentifier];return!(null===(b=null===d||void 0===d?void 0:d.value)||void 0===b)&&b}getVisitorIdentifier(a){var b,c,d;const e=this.infoStorage.read();if(!e.ok)return a;const f=e.data;return null!==(b=f.mappingIdentifiers)&&void 0!==b?b:f.mappingIdentifiers={},null!==(c=null===(d=f.mappingIdentifiers[a])||void 0===d?void 0:d.mappingIdentifier)&&void 0!==c?c:a}getMappingIdentifier(a){const b=this.infoStorage.read();if(b.ok){const c=b.data;return c.mappingIdentifiers?c.mappingIdentifiers[a]:void 0}}setMappingIdentifier(a,b){var c;const d=this.infoStorage.read();if(d.ok){const e=d.data;null!==(c=e.mappingIdentifiers)&&void 0!==c?c:e.mappingIdentifiers={};const f=e.mappingIdentifiers[a];(!f||f.timestamp<b.timestamp)&&(e.mappingIdentifiers[a]=b,this.infoStorage.write(e))}}getVisitorData(a){this.cleanupData();const b=this.dataStorage.read();if(!b.ok)return;let{visitorReference:c,data:d,isReference:e}=this.dataProcessor.dereferenceData(b.data,a);if(this.packageInfo.isServer&&e&&!d[c]){const b=this.infoStorage.read();b.ok&&b.data.mappingIdentifiers&&delete b.data.mappingIdentifiers[a],delete d[a],c=a}return d[c]}getVisitorStoredDataTypes(a){const b=this.getVisitorData(a);return b?new Set(Object.keys(b)):new Set}getLinkedVisitor(a){const b=this.dataStorage.read();if(!b.ok)return null;if("string"==typeof b.data[a])return b.data[a];if(null===this.mappingIdentifierCustomDataIndex)return null;const c=b.data[a];if(!c)return null;const d=c[_types.KameleoonData.CustomData];return d&&d[this.mappingIdentifierCustomDataIndex]?d[this.mappingIdentifierCustomDataIndex].value[0]:null}mutUpdateTargetingData(a){let{infoData:b,visitorCode:c,kameleoonData:d,targetingData:e}=a;for(const f of d){f.data.type===_types.KameleoonData.CustomData&&this.processCustomData({infoData:b,customData:f,mutData:e,visitorCode:c});const a=this.dataProcessor.mutUpdateData({infoData:b,visitorCode:c,mutData:e,dataItem:f}),d=b.nextDataCleanup;(!d||d&&a<d)&&(b.nextDataCleanup=a),f.data.status===_types2.TrackingStatus.Unsent&&this.dataProcessor.mutAddUnsentData({mutData:b,visitorCode:c,dataType:f.data.type})}}cleanupData(){const a=this.dataStorage.read(),b=this.infoStorage.read();if(!a.ok||!b.ok)return;const c=a.data,d=b.data,e=d.nextDataCleanup;if(e&&e<Date.now()){const a=this.dataProcessor.mutCleanupData(c,d);d.nextDataCleanup=a||void 0,this.infoStorage.write(d),this.dataStorage.write(c)}}processCustomData(a){let{infoData:b,mutData:c,customData:d,visitorCode:e}=a;const{data:f}=d,g=!!(f.value.length&&f.value[0].length);if(this.mappingIdentifierCustomDataIndex===f.index&&g){d._isMappingIdentifier=!0;const a=f.value[0];if(e!==a){var h;_logging.KameleoonLogger.info`Linked anonymous visitor ${e} with user ${a}`,this.dataProcessor.createReference({infoData:b,mutData:c,visitorCode:e,linkedVisitor:f.value[0]}),null!==(h=b.mappingIdentifiers)&&void 0!==h?h:b.mappingIdentifiers={},b.mappingIdentifiers[a]={mappingIdentifier:e,timestamp:Date.now()}}}this.localCustomDataIndexes.has(f.index)&&(d.status=_types2.TrackingStatus.Sent)}get unsentDataVisitors(){const a=this.infoStorage.read();return a.ok?Object.keys(a.data.unsentData):[]}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get trees(){return this.targetingTrees}get storedCustomDataIndexes(){const a=this.dataStorage.read();if(!a.ok)return new Set;const b=a.data;if(!(_types.KameleoonData.CustomData in b))return new Set;const c=new Set;for(const a in Object.keys(b[_types.KameleoonData.CustomData]))c.add(+a);return c}set customDataIndexes(a){var b;const[c,d]=[[],[]];a.forEach(a=>{a.localOnly&&c.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&d.push(a.index)}),this.mappingIdentifierCustomDataIndex=(null===(b=a.find(a=>a.isMappingIdentifier))||void 0===b?void 0:b.index)||null,this.localCustomDataIndexes=new Set(c),this.persistentCustomDataIndexes=new Set(d)}}exports.DataManager=DataManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataProcessor=void 0;var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataProcessor=void 0;var _listUtilities=require("../utilities/listUtilities"),_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))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 DataProcessor{constructor(){let a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:null,b=1<arguments.length?arguments[1]:void 0;_defineProperty(this,"cleanupInterval",void 0),_defineProperty(this,"packageInfo",void 0),this.cleanupInterval=a,this.packageInfo=b}mutUpdateData(a){let{infoData:b,visitorCode:c,mutData:d,dataItem:e}=a,{visitorReference:f,data:g,isReference:h}=this.dereferenceData(d,c);this.packageInfo.isServer&&h&&!d[f]&&(b.mappingIdentifiers&&delete b.mappingIdentifiers[c],delete d[c],f=c);const i=this.cleanupInterval?Date.now()+this.cleanupInterval:0;switch(e.data.type){case _types.KameleoonData.CustomData:{this.updateCustomData({expirationTime:i,customData:e,visitorCode:f,mutData:g});break}case _types.KameleoonData.PageView:{this.updatePageView({expirationTime:i,pageView:e,visitorCode:f,mutData:g});break}case _types.KameleoonData.Conversion:{this.updateConversion({expirationTime:i,conversion:e,visitorCode:f,mutData:g});break}case _types.KameleoonData.VisitsData:{this.updateVisitsData({expirationTime:i,visitsData:e,visitorCode:f,mutData:g});break}case _types.KameleoonData.Personalization:{this.updatePersonalization({expirationTime:i,personalization:e,visitorCode:f,mutData:g});break}default:this.updateCommonData({expirationTime:i,commonData:e,visitorCode:f,mutData:g})}return i}mutCleanupData(a,b){if(!this.cleanupInterval)return null;let c=0;for(const[e,f]of Object.entries(a)){if("string"==typeof f){this.removeReference({mutData:a,visitorCode:e,linkedVisitor:f,infoData:b});continue}let g=0;for(const a of Object.keys(f)){const b=a;let c;switch(b){case _types.KameleoonData.CustomData:case _types.KameleoonData.PageView:case _types.KameleoonData.Conversion:case _types.KameleoonData.Personalization:{c=this.deleteNestedExpiredField(f,b);break}default:c=this.deleteExpiredField(f,b)}(!g||c&&c<g)&&(g=c)}if(!!Object.keys(a[e]).length)(!c||g&&g<c)&&(c=g);else if(delete a[e],this.packageInfo.isServer){var d;null!==(d=b.mappingIdentifiers)&&void 0!==d?d:b.mappingIdentifiers={},delete b.mappingIdentifiers[e]}}return c}mutAddUnsentData(a){let{mutData:b,visitorCode:c,dataType:d}=a;const e=b.unsentData[c];if(!e||!e.length)b.unsentData[c]=[d];else{const a=new Set([...e]);a.add(d),b.unsentData[c]=Array.from(a)}}createReference(a){let{mutData:b,visitorCode:c,linkedVisitor:d}=a;b[d]=c}removeReference(a){let{mutData:b,visitorCode:c,linkedVisitor:d,infoData:e}=a;this.packageInfo.isServer&&!b[d]&&(delete b[c],e.mappingIdentifiers&&delete e.mappingIdentifiers[c])}updatePageView(a){let{visitorCode:b,mutData:c,pageView:d,expirationTime:e}=a;const{data:f}=d,g=c[b]&&_types.KameleoonData.PageView in c[b]&&f.urlAddress in c[b][_types.KameleoonData.PageView],h={expirationTime:e,visitorCode:b,data:c,key:_types.KameleoonData.PageView,nestedKey:f.urlAddress,value:f};if(g){const a=c[b][_types.KameleoonData.PageView][f.urlAddress],d=a.timestamps;for(const a of d){const{time:b}=a;if(f.timestamps.some(a=>{let{time:c}=a;return c===b}))continue;const c=f.timestamps.findIndex(a=>{let{time:c}=a;return c>=b});-1===c?f.timestamps.push(a):f.timestamps.splice(c,0,a)}this.updateNestedField(h)}else this.createNestedField(h)}updateCustomData(a){let{visitorCode:b,customData:c,mutData:d,expirationTime:e}=a;const{data:f}=c,g=d[b]&&_types.KameleoonData.CustomData in d[b],h={expirationTime:e,visitorCode:b,data:d,key:_types.KameleoonData.CustomData,nestedKey:f.index.toString(),value:f};g?this.updateNestedField(h):this.createNestedField(h)}updateConversion(a){let{conversion:b,mutData:c,visitorCode:d,expirationTime:e}=a;const{data:f}=b,g=c[d]&&_types.KameleoonData.Conversion in c[d],h={expirationTime:e,visitorCode:d,data:c,key:_types.KameleoonData.Conversion,nestedKey:f.id.toString(),value:f};g?this.updateNestedField(h):this.createNestedField(h)}updateVisitsData(a){let{visitorCode:b,mutData:c,visitsData:d,expirationTime:e}=a;const{data:f}=d,g=c[b]&&_types.KameleoonData.VisitsData in c[b],h={expirationTime:e,data:c,key:_types.KameleoonData.VisitsData,value:f,visitorCode:b};if(g){var i,j;const a=c[b][_types.KameleoonData.VisitsData];a.visits.forEach(a=>{_listUtilities.ListUtilities.insertVisitInOrderedListMutably({list:f.visits,visit:a})});const d=Math.max(null!==(i=f.visitNumber)&&void 0!==i?i:f.visits.length-1,f.visits.length-1,null!==(j=a.visitNumber)&&void 0!==j?j:0);this.updateField(_objectSpread(_objectSpread({},h),{},{value:_objectSpread(_objectSpread({},f),{},{visits:f.visits,visitNumber:d})}))}else this.createField(h)}updatePersonalization(a){let{visitorCode:b,mutData:c,personalization:d,expirationTime:e}=a;const{data:f}=d,g=c[b]&&_types.KameleoonData.Personalization in c[b],h={expirationTime:e,visitorCode:b,data:c,key:_types.KameleoonData.Personalization,nestedKey:f.id.toString(),value:f};g?this.updateNestedField(h):this.createNestedField(h)}updateCommonData(a){let{visitorCode:b,mutData:c,commonData:d,expirationTime:e}=a;const{data:f}=d,g=c[b]&&f.type in c[b],h={expirationTime:e,data:c,key:f.type,visitorCode:b,value:f};g?this.updateField(h):this.createField(h)}dereferenceData(a,b){return"string"==typeof a[b]?{visitorReference:a[b],data:a,isReference:!0}:{visitorReference:b,data:a,isReference:!1}}deleteExpiredField(a,b){if(!a)return 0;const c=b,d=a[c].expirationTime<Date.now();return d?(delete a[c],0):a[c].expirationTime}deleteNestedExpiredField(a,b){if(!a[b])return 0;const c=a[b];let d;for(const[e,f]of Object.entries(c)){if(!f)continue;const a=f.expirationTime<Date.now();a?delete c[e]:(!d||f.expirationTime<d)&&(d=f.expirationTime)}return Object.keys(c).length||delete a[b],d}updateField(a){let{key:b,value:c,data:d,visitorCode:e,expirationTime:f}=a;d[e][b]=_objectSpread(_objectSpread({},c),{},{expirationTime:f})}createField(a){let{key:b,value:c,data:d,visitorCode:e,expirationTime:f}=a;d[e]=_objectSpread(_objectSpread({},d[e]),{},{[b]:_objectSpread(_objectSpread({},c),{},{expirationTime:f})})}updateNestedField(a){let{key:b,nestedKey:c,value:d,data:e,visitorCode:f,expirationTime:g}=a;e[f][b][c]=_objectSpread(_objectSpread({},d),{},{expirationTime:g})}createNestedField(a){var b;let{key:c,nestedKey:d,value:e,data:f,visitorCode:g,expirationTime:h}=a;f[g]=null!==(b=f[g])&&void 0!==b&&b[c]?_objectSpread(_objectSpread({},f[g]),{},{[c]:_objectSpread(_objectSpread({},f[g][c]),{},{[d]:_objectSpread(_objectSpread({},e),{},{expirationTime:h})})}):_objectSpread(_objectSpread({},f[g]),{},{[c]:{[d]:_objectSpread(_objectSpread({},e),{},{expirationTime:h})}})}}exports.DataProcessor=DataProcessor;
|
|
@@ -11,5 +11,7 @@ export { UniqueIdentifier } from './uniqueIdentifier';
|
|
|
11
11
|
export { ApplicationVersion } from './applicationVersion';
|
|
12
12
|
export { VisitsData } from './visitsData';
|
|
13
13
|
export { KameleoonConversionScore } from './kameleoonConversionScore';
|
|
14
|
+
export { DataProcessor } from './dataProcessor';
|
|
15
|
+
export { StaticData } from './staticData';
|
|
14
16
|
export { DeviceType, CookieType, VisitsDataType, BrowserType, KameleoonData, DeviceDataType, CustomDataType, BrowserDataType, BrowserIndexMap, PageViewDataType, KameleoonDataType, UserAgentDataType, IdentifierDataType, ConversionDataType, OperatingSystemType, GeolocationInfoType, KameleoonDataItemType, PageViewParametersType, ConversionParametersType, ApplicationVersionDataType, } from './types';
|
|
15
|
-
export { DataManager } from './dataManager';
|
|
17
|
+
export { DataManager, IDataManager } from './dataManager';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function(){return _applicationVersion.ApplicationVersion}}),Object.defineProperty(exports,"ApplicationVersionDataType",{enumerable:!0,get:function(){return _types.ApplicationVersionDataType}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function(){return _browser.Browser}}),Object.defineProperty(exports,"BrowserDataType",{enumerable:!0,get:function(){return _types.BrowserDataType}}),Object.defineProperty(exports,"BrowserIndexMap",{enumerable:!0,get:function(){return _types.BrowserIndexMap}}),Object.defineProperty(exports,"BrowserType",{enumerable:!0,get:function(){return _types.BrowserType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function(){return _conversion.Conversion}}),Object.defineProperty(exports,"ConversionDataType",{enumerable:!0,get:function(){return _types.ConversionDataType}}),Object.defineProperty(exports,"ConversionParametersType",{enumerable:!0,get:function(){return _types.ConversionParametersType}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function(){return _cookie.Cookie}}),Object.defineProperty(exports,"CookieType",{enumerable:!0,get:function(){return _types.CookieType}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function(){return _customData.CustomData}}),Object.defineProperty(exports,"CustomDataType",{enumerable:!0,get:function(){return _types.CustomDataType}}),Object.defineProperty(exports,"DataManager",{enumerable:!0,get:function(){return _dataManager.DataManager}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function(){return _device.Device}}),Object.defineProperty(exports,"DeviceDataType",{enumerable:!0,get:function(){return _types.DeviceDataType}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function(){return _types.DeviceType}}),Object.defineProperty(exports,"GeolocationData",{enumerable:!0,get:function(){return _geolocation.GeolocationData}}),Object.defineProperty(exports,"GeolocationInfoType",{enumerable:!0,get:function(){return _types.GeolocationInfoType}}),Object.defineProperty(exports,"IdentifierDataType",{enumerable:!0,get:function(){return _types.IdentifierDataType}}),Object.defineProperty(exports,"KameleoonConversionScore",{enumerable:!0,get:function(){return _kameleoonConversionScore.KameleoonConversionScore}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function(){return _types.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataItemType",{enumerable:!0,get:function(){return _types.KameleoonDataItemType}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function(){return _types.KameleoonDataType}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function(){return _operatingSystem.OperatingSystem}}),Object.defineProperty(exports,"OperatingSystemType",{enumerable:!0,get:function(){return _types.OperatingSystemType}}),Object.defineProperty(exports,"PageView",{enumerable:!0,get:function(){return _pageView.PageView}}),Object.defineProperty(exports,"PageViewDataType",{enumerable:!0,get:function(){return _types.PageViewDataType}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function(){return _types.PageViewParametersType}}),Object.defineProperty(exports,"UniqueIdentifier",{enumerable:!0,get:function(){return _uniqueIdentifier.UniqueIdentifier}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _userAgent.UserAgent}}),Object.defineProperty(exports,"UserAgentDataType",{enumerable:!0,get:function(){return _types.UserAgentDataType}}),Object.defineProperty(exports,"VisitsData",{enumerable:!0,get:function(){return _visitsData.VisitsData}}),Object.defineProperty(exports,"VisitsDataType",{enumerable:!0,get:function(){return _types.VisitsDataType}});var _device=require("./device"),_cookie=require("./cookie"),_browser=require("./browser"),_pageView=require("./pageView"),_userAgent=require("./userAgent"),_customData=require("./customData"),_conversion=require("./conversion"),_geolocation=require("./geolocation"),_operatingSystem=require("./operatingSystem"),_uniqueIdentifier=require("./uniqueIdentifier"),_applicationVersion=require("./applicationVersion"),_visitsData=require("./visitsData"),_kameleoonConversionScore=require("./kameleoonConversionScore"),_types=require("./types"),_dataManager=require("./dataManager");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ApplicationVersion",{enumerable:!0,get:function(){return _applicationVersion.ApplicationVersion}}),Object.defineProperty(exports,"ApplicationVersionDataType",{enumerable:!0,get:function(){return _types.ApplicationVersionDataType}}),Object.defineProperty(exports,"Browser",{enumerable:!0,get:function(){return _browser.Browser}}),Object.defineProperty(exports,"BrowserDataType",{enumerable:!0,get:function(){return _types.BrowserDataType}}),Object.defineProperty(exports,"BrowserIndexMap",{enumerable:!0,get:function(){return _types.BrowserIndexMap}}),Object.defineProperty(exports,"BrowserType",{enumerable:!0,get:function(){return _types.BrowserType}}),Object.defineProperty(exports,"Conversion",{enumerable:!0,get:function(){return _conversion.Conversion}}),Object.defineProperty(exports,"ConversionDataType",{enumerable:!0,get:function(){return _types.ConversionDataType}}),Object.defineProperty(exports,"ConversionParametersType",{enumerable:!0,get:function(){return _types.ConversionParametersType}}),Object.defineProperty(exports,"Cookie",{enumerable:!0,get:function(){return _cookie.Cookie}}),Object.defineProperty(exports,"CookieType",{enumerable:!0,get:function(){return _types.CookieType}}),Object.defineProperty(exports,"CustomData",{enumerable:!0,get:function(){return _customData.CustomData}}),Object.defineProperty(exports,"CustomDataType",{enumerable:!0,get:function(){return _types.CustomDataType}}),Object.defineProperty(exports,"DataManager",{enumerable:!0,get:function(){return _dataManager.DataManager}}),Object.defineProperty(exports,"DataProcessor",{enumerable:!0,get:function(){return _dataProcessor.DataProcessor}}),Object.defineProperty(exports,"Device",{enumerable:!0,get:function(){return _device.Device}}),Object.defineProperty(exports,"DeviceDataType",{enumerable:!0,get:function(){return _types.DeviceDataType}}),Object.defineProperty(exports,"DeviceType",{enumerable:!0,get:function(){return _types.DeviceType}}),Object.defineProperty(exports,"GeolocationData",{enumerable:!0,get:function(){return _geolocation.GeolocationData}}),Object.defineProperty(exports,"GeolocationInfoType",{enumerable:!0,get:function(){return _types.GeolocationInfoType}}),Object.defineProperty(exports,"IDataManager",{enumerable:!0,get:function(){return _dataManager.IDataManager}}),Object.defineProperty(exports,"IdentifierDataType",{enumerable:!0,get:function(){return _types.IdentifierDataType}}),Object.defineProperty(exports,"KameleoonConversionScore",{enumerable:!0,get:function(){return _kameleoonConversionScore.KameleoonConversionScore}}),Object.defineProperty(exports,"KameleoonData",{enumerable:!0,get:function(){return _types.KameleoonData}}),Object.defineProperty(exports,"KameleoonDataItemType",{enumerable:!0,get:function(){return _types.KameleoonDataItemType}}),Object.defineProperty(exports,"KameleoonDataType",{enumerable:!0,get:function(){return _types.KameleoonDataType}}),Object.defineProperty(exports,"OperatingSystem",{enumerable:!0,get:function(){return _operatingSystem.OperatingSystem}}),Object.defineProperty(exports,"OperatingSystemType",{enumerable:!0,get:function(){return _types.OperatingSystemType}}),Object.defineProperty(exports,"PageView",{enumerable:!0,get:function(){return _pageView.PageView}}),Object.defineProperty(exports,"PageViewDataType",{enumerable:!0,get:function(){return _types.PageViewDataType}}),Object.defineProperty(exports,"PageViewParametersType",{enumerable:!0,get:function(){return _types.PageViewParametersType}}),Object.defineProperty(exports,"StaticData",{enumerable:!0,get:function(){return _staticData.StaticData}}),Object.defineProperty(exports,"UniqueIdentifier",{enumerable:!0,get:function(){return _uniqueIdentifier.UniqueIdentifier}}),Object.defineProperty(exports,"UserAgent",{enumerable:!0,get:function(){return _userAgent.UserAgent}}),Object.defineProperty(exports,"UserAgentDataType",{enumerable:!0,get:function(){return _types.UserAgentDataType}}),Object.defineProperty(exports,"VisitsData",{enumerable:!0,get:function(){return _visitsData.VisitsData}}),Object.defineProperty(exports,"VisitsDataType",{enumerable:!0,get:function(){return _types.VisitsDataType}});var _device=require("./device"),_cookie=require("./cookie"),_browser=require("./browser"),_pageView=require("./pageView"),_userAgent=require("./userAgent"),_customData=require("./customData"),_conversion=require("./conversion"),_geolocation=require("./geolocation"),_operatingSystem=require("./operatingSystem"),_uniqueIdentifier=require("./uniqueIdentifier"),_applicationVersion=require("./applicationVersion"),_visitsData=require("./visitsData"),_kameleoonConversionScore=require("./kameleoonConversionScore"),_dataProcessor=require("./dataProcessor"),_staticData=require("./staticData"),_types=require("./types"),_dataManager=require("./dataManager");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { StaticDataType } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* @class
|
|
4
|
+
* StaticData - a class for creating static data for Kameleoon.
|
|
5
|
+
* */
|
|
6
|
+
export declare class StaticData {
|
|
7
|
+
private browserType?;
|
|
8
|
+
private browserVersion?;
|
|
9
|
+
private visitNumber?;
|
|
10
|
+
private timeSincePreviousVisit?;
|
|
11
|
+
private deviceType?;
|
|
12
|
+
private os?;
|
|
13
|
+
constructor({ browserType, visitNumber, timeSincePreviousVisit, os, deviceType, browserVersion, }: StaticDataType);
|
|
14
|
+
get url(): string;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.StaticData=void 0;var _requester=require("../requester"),_types=require("./types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class StaticData{constructor(a){let{browserType:b,visitNumber:c,timeSincePreviousVisit:d,os:e,deviceType:f,browserVersion:g}=a;_defineProperty(this,"browserType",void 0),_defineProperty(this,"browserVersion",void 0),_defineProperty(this,"visitNumber",void 0),_defineProperty(this,"timeSincePreviousVisit",void 0),_defineProperty(this,"deviceType",void 0),_defineProperty(this,"os",void 0),this.browserType=b,this.visitNumber=c,this.timeSincePreviousVisit=d,this.os=e,this.deviceType=f,this.browserVersion=g}get url(){const a=this.browserVersion?_requester.UrlParameter.BrowserVersion+this.browserVersion:"",b=this.browserType?_requester.UrlParameter.Browser+this.browserType:"",c=this.browserType?_requester.UrlParameter.BrowserIndex+_types.BrowserIndexMap[this.browserType]:"",d=this.os?_requester.UrlParameter.Os+this.os:"",e=this.os?_requester.UrlParameter.OsIndex+_types.OperatingSystemIndexMap[this.os]:"",f=this.deviceType?_requester.UrlParameter.DeviceType+this.deviceType:"",g=this.visitNumber===void 0?"":_requester.UrlParameter.VisitNumber+this.visitNumber,h=this.timeSincePreviousVisit===void 0?"":_requester.UrlParameter.TimeSincePreviousVisit+this.timeSincePreviousVisit;return _requester.UrlEventType.StaticData+b+c+a+g+h+d+e+f}}exports.StaticData=StaticData;
|
|
@@ -211,8 +211,13 @@ export type PersonalizationDataType = {
|
|
|
211
211
|
variationId: number;
|
|
212
212
|
} & SharedDataPropertiesType;
|
|
213
213
|
export type VisitsDataType = {
|
|
214
|
-
visits: number[];
|
|
214
|
+
visits: VisitDataType[] | number[];
|
|
215
|
+
visitNumber?: number;
|
|
215
216
|
} & SharedDataPropertiesType;
|
|
217
|
+
export type VisitDataType = {
|
|
218
|
+
timeStarted: number;
|
|
219
|
+
timeLastActivity: number;
|
|
220
|
+
};
|
|
216
221
|
export type OperatingSystemDataType = {
|
|
217
222
|
operatingSystem: OperatingSystemType;
|
|
218
223
|
} & SharedDataPropertiesType;
|
|
@@ -372,4 +377,12 @@ export type VisitProcessorDataType = {
|
|
|
372
377
|
visitsData: VisitsData;
|
|
373
378
|
experimentData: FeatureFlagVariationsType;
|
|
374
379
|
};
|
|
380
|
+
export type StaticDataType = {
|
|
381
|
+
browserType?: BrowserType;
|
|
382
|
+
browserVersion?: number;
|
|
383
|
+
visitNumber?: number;
|
|
384
|
+
timeSincePreviousVisit?: number;
|
|
385
|
+
deviceType?: DeviceType;
|
|
386
|
+
os?: OperatingSystemType;
|
|
387
|
+
};
|
|
375
388
|
export {};
|
|
@@ -25,6 +25,7 @@ export declare class VisitProcessor implements IVisitProcessor {
|
|
|
25
25
|
processMultipleDataTypes(): void;
|
|
26
26
|
processKcs(kcsData?: KCSType): void;
|
|
27
27
|
processVisitsData(visit: VisitType): void;
|
|
28
|
+
processVisitNumber(visit: VisitType, isCurrentVisit: boolean): void;
|
|
28
29
|
processCbs(cbsData?: CBSType): void;
|
|
29
30
|
private processBrowser;
|
|
30
31
|
private processDevice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitProcessor=void 0;var _pageView=require("./pageView"),_types=require("./types"),_customData=require("./customData"),_conversion=require("./conversion"),_browser=require("./browser"),_device=require("./device"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_visitsData=require("./visitsData"),_kameleoonConversionScore=require("./kameleoonConversionScore"),_types2=require("../types"),_personalization=require("./personalization"),_cbScores=require("./cbScores");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class VisitProcessor{constructor(a){let{filters:b,dataManager:c,visitorCode:d}=a;_defineProperty(this,"visitsData",new _visitsData.VisitsData([])),_defineProperty(this,"visitorData",[]),_defineProperty(this,"storageVisitorData",[]),_defineProperty(this,"experimentData",{}),_defineProperty(this,"filters",void 0),_defineProperty(this,"visitorDataTypes",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"singleDataTypes",{[_types.KameleoonData.Device]:null,[_types.KameleoonData.Browser]:null,[_types.KameleoonData.GeolocationData]:null,[_types.KameleoonData.OperatingSystem]:null,[_types.KameleoonData.KameleoonConversionScore]:null,[_types.KameleoonData.CBScores]:null}),_defineProperty(this,"multipleDataTypes",{[_types.KameleoonData.CustomData]:new Map,[_types.KameleoonData.PageView]:new Map,[_types.KameleoonData.Conversion]:new Map,[_types.KameleoonData.Personalization]:new Map}),this.filters=b,this.dataManager=c,this.visitorDataTypes=c.getVisitorStoredDataTypes(d)}get data(){return{visitorData:this.visitorData,storageVisitorData:this.storageVisitorData,visitsData:this.visitsData,experimentData:this.experimentData}}processVisit(a){this.processBrowser(a),this.processDevice(a),this.processOperatingSystem(a),this.processGeolocationData(a),this.processCustomData(a),this.processConversion(a),this.processPageView(a),this.processExperiments(a),this.processPersonalization(a)}processMultipleDataTypes(){for(const[a,b]of Object.entries(this.multipleDataTypes))if(b.size)switch(a){case _types.KameleoonData.PageView:{this.visitorData.push(...b.values()),this.storageVisitorData.push(...b.values());break}case _types.KameleoonData.Personalization:case _types.KameleoonData.Conversion:{this.storageVisitorData.push(...b.values());break}case _types.KameleoonData.CustomData:{b.forEach(a=>{this.visitorData.push(a),this.dataManager.storedCustomDataIndexes.has(a.data.index)||this.storageVisitorData.push(a)});break}}}processKcs(a){if(this.filters.kcs&&a){const b=new _kameleoonConversionScore.KameleoonConversionScore(a);this.storageVisitorData.push(b)}}processVisitsData(a){this.visitsData.timestamp=a.timeStarted}processCbs(a){if(this.filters.cbs&&a){const b=new _cbScores.CBScores(a);this.storageVisitorData.push(b)}}processBrowser(a){if(this.filters.browser&&!this.singleDataTypes[_types.KameleoonData.Browser]){const b=_browser.Browser._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.Browser)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.Browser]=b)}}processDevice(a){if(this.filters.device&&!this.singleDataTypes[_types.KameleoonData.Device]){const b=_device.Device._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.Device)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.Device]=b)}}processOperatingSystem(a){if(this.filters.operatingSystem&&!this.singleDataTypes[_types.KameleoonData.OperatingSystem]){const b=_operatingSystem.OperatingSystem._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.OperatingSystem)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.OperatingSystem]=b)}}processGeolocationData(a){if(this.filters.geolocation&&!this.singleDataTypes[_types.KameleoonData.GeolocationData]){const b=_geolocation.GeolocationData._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.GeolocationData)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.GeolocationData]=b)}}processCustomData(a){this.filters.customData&&_customData.CustomData._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.CustomData])}processConversion(a){if(this.filters.conversions){_conversion.Conversion._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.Conversion]);const b=_conversion.Conversion._listFromVisit(a);b.length&&this.visitorData.push(...b)}}processPageView(a){this.filters.pageViews&&_pageView.PageView._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.PageView])}processExperiments(a){if(this.filters.experiments&&a.experimentEvents)for(const b of a.experimentEvents){const{id:a,variationId:c}=b.data;this.experimentData[a]={variationId:c,isTargetedRule:!1,status:_types2.TrackingStatus.Unsent}}}processPersonalization(a){this.filters.personalization&&_personalization.Personalization._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.Personalization])}processMappingIdentifier(a){var b,c;if(a){const d=null===(b=a.customDataEvents)||void 0===b||null===(c=b.find(a=>a.data.mappingIdentifier))||void 0===c?void 0:c.time;if(d&&a.visitorCode)return{mappingIdentifier:a.visitorCode,timestamp:d}}}}exports.VisitProcessor=VisitProcessor;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitProcessor=void 0;var _pageView=require("./pageView"),_types=require("./types"),_customData=require("./customData"),_conversion=require("./conversion"),_browser=require("./browser"),_device=require("./device"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_visitsData=require("./visitsData"),_kameleoonConversionScore=require("./kameleoonConversionScore"),_types2=require("../types"),_personalization=require("./personalization"),_cbScores=require("./cbScores");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class VisitProcessor{constructor(a){let{filters:b,dataManager:c,visitorCode:d}=a;_defineProperty(this,"visitsData",new _visitsData.VisitsData([])),_defineProperty(this,"visitorData",[]),_defineProperty(this,"storageVisitorData",[]),_defineProperty(this,"experimentData",{}),_defineProperty(this,"filters",void 0),_defineProperty(this,"visitorDataTypes",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"singleDataTypes",{[_types.KameleoonData.Device]:null,[_types.KameleoonData.Browser]:null,[_types.KameleoonData.GeolocationData]:null,[_types.KameleoonData.OperatingSystem]:null,[_types.KameleoonData.KameleoonConversionScore]:null,[_types.KameleoonData.CBScores]:null}),_defineProperty(this,"multipleDataTypes",{[_types.KameleoonData.CustomData]:new Map,[_types.KameleoonData.PageView]:new Map,[_types.KameleoonData.Conversion]:new Map,[_types.KameleoonData.Personalization]:new Map}),this.filters=b,this.dataManager=c,this.visitorDataTypes=c.getVisitorStoredDataTypes(d)}get data(){return{visitorData:this.visitorData,storageVisitorData:this.storageVisitorData,visitsData:this.visitsData,experimentData:this.experimentData}}processVisit(a){this.processBrowser(a),this.processDevice(a),this.processOperatingSystem(a),this.processGeolocationData(a),this.processCustomData(a),this.processConversion(a),this.processPageView(a),this.processExperiments(a),this.processPersonalization(a)}processMultipleDataTypes(){for(const[a,b]of Object.entries(this.multipleDataTypes))if(b.size)switch(a){case _types.KameleoonData.PageView:{this.visitorData.push(...b.values()),this.storageVisitorData.push(...b.values());break}case _types.KameleoonData.Personalization:case _types.KameleoonData.Conversion:{this.storageVisitorData.push(...b.values());break}case _types.KameleoonData.CustomData:{b.forEach(a=>{this.visitorData.push(a),this.dataManager.storedCustomDataIndexes.has(a.data.index)||this.storageVisitorData.push(a)});break}}}processKcs(a){if(this.filters.kcs&&a){const b=new _kameleoonConversionScore.KameleoonConversionScore(a);this.storageVisitorData.push(b)}}processVisitsData(a){var b;this.visitsData.timestamp={timeStarted:a.timeStarted,timeLastActivity:null!==(b=a.timeLastEvent)&&void 0!==b?b:a.timeStarted}}processVisitNumber(a,b){if(a.staticDataEvent){const c=a.staticDataEvent.data.visitNumber+(b?0:1);this.visitsData.updateVisitNumber(c)}}processCbs(a){if(this.filters.cbs&&a){const b=new _cbScores.CBScores(a);this.storageVisitorData.push(b)}}processBrowser(a){if(this.filters.browser&&!this.singleDataTypes[_types.KameleoonData.Browser]){const b=_browser.Browser._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.Browser)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.Browser]=b)}}processDevice(a){if(this.filters.device&&!this.singleDataTypes[_types.KameleoonData.Device]){const b=_device.Device._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.Device)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.Device]=b)}}processOperatingSystem(a){if(this.filters.operatingSystem&&!this.singleDataTypes[_types.KameleoonData.OperatingSystem]){const b=_operatingSystem.OperatingSystem._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.OperatingSystem)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.OperatingSystem]=b)}}processGeolocationData(a){if(this.filters.geolocation&&!this.singleDataTypes[_types.KameleoonData.GeolocationData]){const b=_geolocation.GeolocationData._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.GeolocationData)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.GeolocationData]=b)}}processCustomData(a){this.filters.customData&&_customData.CustomData._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.CustomData])}processConversion(a){if(this.filters.conversions){_conversion.Conversion._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.Conversion]);const b=_conversion.Conversion._listFromVisit(a);b.length&&this.visitorData.push(...b)}}processPageView(a){this.filters.pageViews&&_pageView.PageView._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.PageView])}processExperiments(a){if(this.filters.experiments&&a.experimentEvents)for(const b of a.experimentEvents){const{id:a,variationId:c}=b.data;this.experimentData[a]={variationId:c,isTargetedRule:!1,status:_types2.TrackingStatus.Unsent}}}processPersonalization(a){this.filters.personalization&&_personalization.Personalization._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.Personalization])}processMappingIdentifier(a){var b,c;if(a){const d=null===(b=a.customDataEvents)||void 0===b||null===(c=b.find(a=>a.data.mappingIdentifier))||void 0===c?void 0:c.time;if(d&&a.visitorCode)return{mappingIdentifier:a.visitorCode,timestamp:d}}}}exports.VisitProcessor=VisitProcessor;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IKameleoonData, VisitsDataType } from './types';
|
|
1
|
+
import { IKameleoonData, VisitDataType, VisitsDataType } from './types';
|
|
2
2
|
import { TrackingStatus } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* @class
|
|
@@ -6,17 +6,19 @@ import { TrackingStatus } from '../types';
|
|
|
6
6
|
* */
|
|
7
7
|
export declare class VisitsData implements IKameleoonData {
|
|
8
8
|
private visits;
|
|
9
|
+
private visitNumber;
|
|
9
10
|
status: TrackingStatus;
|
|
10
11
|
/**
|
|
11
12
|
* @param {number[]} visits - a list of visits
|
|
12
13
|
* */
|
|
13
|
-
constructor(visits:
|
|
14
|
+
constructor(visits: VisitDataType[]);
|
|
14
15
|
get url(): string;
|
|
15
16
|
get data(): VisitsDataType;
|
|
16
17
|
get isSent(): boolean;
|
|
17
18
|
/**
|
|
18
19
|
* Adds a single timestamp while ensuring the list remains sorted and unique
|
|
19
|
-
* @param {
|
|
20
|
+
* @param {VisitDataType} visit - The visit data to be added
|
|
20
21
|
*/
|
|
21
|
-
set timestamp(
|
|
22
|
+
set timestamp(visit: VisitDataType);
|
|
23
|
+
updateVisitNumber(visitNumber: number): void;
|
|
22
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitsData=void 0;var _listUtilities=require("../utilities/listUtilities"),_types=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitsData=void 0;var _listUtilities=require("../utilities/listUtilities"),_types=require("./types"),_types2=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class VisitsData{constructor(a){_defineProperty(this,"visits",void 0),_defineProperty(this,"visitNumber",void 0),_defineProperty(this,"status",_types2.TrackingStatus.Sent),this.visits=a,this.visitNumber=a.length?a.length-1:0}get url(){return""}get data(){return{visits:this.visits,visitNumber:this.visitNumber,type:_types.KameleoonData.VisitsData,status:this.status}}get isSent(){return!0}set timestamp(a){_listUtilities.ListUtilities.insertVisitInOrderedListMutably({list:this.visits,visit:a}),this.visitNumber=this.visits.length?this.visits.length-1:0}updateVisitNumber(a){a>this.visitNumber&&(this.visitNumber=a)}}exports.VisitsData=VisitsData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"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:"¤tVisit=",MaxNumberPreviousVisits:"&maxNumberPreviousVisits=",Os:"&os=",OsIndex:"&osIndex=",Country:"&country=",City:"&city=",Region:"®ion=",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=",Personalization:"&personalization=",UserAgent:"&userAgent=",BodyUa:"&bodyUa=",Cbs:"&cbs=",Metadata:"&metadata="},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=",Personalization:"?personalization=",UserAgent:"?userAgent=",BodyUa:"?bodyUa=",Cbs:"?cbs=",Metadata:"?metadata="},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]:"data.kameleoon.io",[_types.UrlType.Events]:"events.kameleoon.eu",[_types.UrlType.ClientConfiguration]:"sdk-config.kameleoon.eu"};
|
|
1
|
+
"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:"¤tVisit=",MaxNumberPreviousVisits:"&maxNumberPreviousVisits=",Os:"&os=",OsIndex:"&osIndex=",Country:"&country=",City:"&city=",Region:"®ion=",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=",Personalization:"&personalization=",UserAgent:"&userAgent=",BodyUa:"&bodyUa=",Cbs:"&cbs=",Metadata:"&metadata=",VisitNumber:"&visitNumber=",TimeSincePreviousVisit:"&timeSincePreviousVisit="},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=",Personalization:"?personalization=",UserAgent:"?userAgent=",BodyUa:"?bodyUa=",Cbs:"?cbs=",Metadata:"?metadata=",VisitNumber:"?visitNumber=",TimeSincePreviousVisit:"?timeSincePreviousVisit="},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]:"data.kameleoon.io",[_types.UrlType.Events]:"events.kameleoon.eu",[_types.UrlType.ClientConfiguration]:"sdk-config.kameleoon.eu"};
|
|
@@ -127,6 +127,7 @@ export type VisitType = {
|
|
|
127
127
|
siteCode: string;
|
|
128
128
|
visitorCode: string;
|
|
129
129
|
timeStarted: number;
|
|
130
|
+
timeLastEvent?: number;
|
|
130
131
|
customDataEvents?: CustomDataEventType[];
|
|
131
132
|
experimentEvents?: ExperimentEventType[];
|
|
132
133
|
conversionEvents?: ConversionEventType[];
|
|
@@ -151,7 +152,7 @@ export declare enum DataApiQuery {
|
|
|
151
152
|
DataMap = 2
|
|
152
153
|
}
|
|
153
154
|
declare const EVENT_TYPE_KEYS: readonly ["customData", "staticData", "page", "conversion", "geolocation", "activity", "experiment"];
|
|
154
|
-
declare const PARAMETER_KEYS: readonly ["valuesCountMap", "mappingValue", "id", "nonce", "country", "environment", "city", "region", "latitude", "geolocation", "longitude", "mappingIdentifier", "postalCode", "sdkName", "sdkVersion", "kcs", "cbs", "personalization", "browserIndex", "browserVersion", "siteCode", "visitorCode", "currentVisit", "maxNumberPreviousVisits", "customData", "negative", "metadata", "revenue", "title", "os", "conversion", "staticData", "osIndex", "browser", "referrersIndices", "overwrite", "index", "href", "experiment", "page", "variationId", "deviceType", "goalId", "ts", "key", "userAgent", "bodyUa"];
|
|
155
|
+
declare const PARAMETER_KEYS: readonly ["valuesCountMap", "mappingValue", "id", "nonce", "country", "environment", "city", "region", "latitude", "geolocation", "longitude", "mappingIdentifier", "postalCode", "sdkName", "sdkVersion", "kcs", "cbs", "personalization", "browserIndex", "browserVersion", "siteCode", "visitorCode", "currentVisit", "maxNumberPreviousVisits", "customData", "negative", "metadata", "revenue", "title", "os", "conversion", "staticData", "osIndex", "browser", "referrersIndices", "overwrite", "index", "href", "experiment", "page", "variationId", "deviceType", "goalId", "ts", "key", "userAgent", "bodyUa", "timeSincePreviousVisit", "visitNumber"];
|
|
155
156
|
declare const TRACKING_KEYS: readonly ["visit", "map"];
|
|
156
157
|
declare const QUERY_KEYS: readonly ["sse", "visitor", "map", "events"];
|
|
157
158
|
export type TrackingType = Record<Capitalize<(typeof TRACKING_KEYS)[number]>, string>;
|
package/dist/requester/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlType=exports.RequestType=exports.HttpMethod=exports.DataApiQuery=void 0;let UrlType=exports.UrlType=function(a){return a.DataApi="dataApi",a.Events="events",a.ClientConfiguration="clientConfiguration",a}({}),HttpMethod=exports.HttpMethod=function(a){return a.Get="GET",a.Post="POST",a}({}),DataApiQuery=exports.DataApiQuery=function(a){return a[a.VisitEvent=0]="VisitEvent",a[a.VisitData=1]="VisitData",a[a.DataMap=2]="DataMap",a}({});const EVENT_TYPE_KEYS=["customData","staticData","page","conversion","geolocation","activity","experiment"],PARAMETER_KEYS=["valuesCountMap","mappingValue","id","nonce","country","environment","city","region","latitude","geolocation","longitude","mappingIdentifier","postalCode","sdkName","sdkVersion","kcs","cbs","personalization","browserIndex","browserVersion","siteCode","visitorCode","currentVisit","maxNumberPreviousVisits","customData","negative","metadata","revenue","title","os","conversion","staticData","osIndex","browser","referrersIndices","overwrite","index","href","experiment","page","variationId","deviceType","goalId","ts","key","userAgent","bodyUa"],TRACKING_KEYS=["visit","map"],QUERY_KEYS=["sse","visitor","map","events"];let RequestType=exports.RequestType=function(a){return a.Configuration="configuration",a.Tracking="tracking",a.RemoteData="remoteData",a}({});
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlType=exports.RequestType=exports.HttpMethod=exports.DataApiQuery=void 0;let UrlType=exports.UrlType=function(a){return a.DataApi="dataApi",a.Events="events",a.ClientConfiguration="clientConfiguration",a}({}),HttpMethod=exports.HttpMethod=function(a){return a.Get="GET",a.Post="POST",a}({}),DataApiQuery=exports.DataApiQuery=function(a){return a[a.VisitEvent=0]="VisitEvent",a[a.VisitData=1]="VisitData",a[a.DataMap=2]="DataMap",a}({});const EVENT_TYPE_KEYS=["customData","staticData","page","conversion","geolocation","activity","experiment"],PARAMETER_KEYS=["valuesCountMap","mappingValue","id","nonce","country","environment","city","region","latitude","geolocation","longitude","mappingIdentifier","postalCode","sdkName","sdkVersion","kcs","cbs","personalization","browserIndex","browserVersion","siteCode","visitorCode","currentVisit","maxNumberPreviousVisits","customData","negative","metadata","revenue","title","os","conversion","staticData","osIndex","browser","referrersIndices","overwrite","index","href","experiment","page","variationId","deviceType","goalId","ts","key","userAgent","bodyUa","timeSincePreviousVisit","visitNumber"],TRACKING_KEYS=["visit","map"],QUERY_KEYS=["sse","visitor","map","events"];let RequestType=exports.RequestType=function(a){return a.Configuration="configuration",a.Tracking="tracking",a.RemoteData="remoteData",a}({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlProvider=void 0;var _sdkInfoTypes=require("../sdkInfoTypes"),_constants=require("./constants"),_types=require("./types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class 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)return void(this.domains[_types.UrlType.DataApi]=a);const b=a.split(".")[0],c=this.domains[_types.UrlType.DataApi];this.domains[_types.UrlType.DataApi]=c.replace(/^[^.]+/,b)}getClientConfigurationUrl(a){this.isInitialized();const b=`https://${this.domains[_types.UrlType.ClientConfiguration]}/`,c=this.environment===_sdkInfoTypes.Environment.Production?"":_constants.UrlFirstParameter.Environment+encodeURIComponent(this.environment);let d="";return a&&(c?d=_constants.UrlParameter.Ts+a:d=_constants.UrlFirstParameter.Ts+a),b+this.siteCode+c+d}getEventSourceUrl(){return this.isInitialized(),`https://${this.domains[_types.UrlType.Events]}:8110/${_constants.UrlQuery.Sse}${this.siteCode}`}getRemoteDataUrl(a){return this.isInitialized(),this.getDataApiUrl(_types.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,personalization:p,visitorCode:q,cbs:r}=c,s=d?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode,t=e||q?_constants.UrlParameter.CustomData+!0:"",u=h?_constants.UrlParameter.Conversion+!0:"",v=i?_constants.UrlParameter.Geolocation+!0:"",w=j?_constants.UrlParameter.Experiment+!0:"",x=k?_constants.UrlParameter.Page+!0:"",y
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.UrlProvider=void 0;var _sdkInfoTypes=require("../sdkInfoTypes"),_constants=require("./constants"),_types=require("./types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class 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)return void(this.domains[_types.UrlType.DataApi]=a);const b=a.split(".")[0],c=this.domains[_types.UrlType.DataApi];this.domains[_types.UrlType.DataApi]=c.replace(/^[^.]+/,b)}getClientConfigurationUrl(a){this.isInitialized();const b=`https://${this.domains[_types.UrlType.ClientConfiguration]}/`,c=this.environment===_sdkInfoTypes.Environment.Production?"":_constants.UrlFirstParameter.Environment+encodeURIComponent(this.environment);let d="";return a&&(c?d=_constants.UrlParameter.Ts+a:d=_constants.UrlFirstParameter.Ts+a),b+this.siteCode+c+d}getEventSourceUrl(){return this.isInitialized(),`https://${this.domains[_types.UrlType.Events]}:8110/${_constants.UrlQuery.Sse}${this.siteCode}`}getRemoteDataUrl(a){return this.isInitialized(),this.getDataApiUrl(_types.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,personalization:p,visitorCode:q,cbs:r}=c,s=d?_constants.UrlParameter.MappingValue:_constants.UrlParameter.VisitorCode,t=e||q?_constants.UrlParameter.CustomData+!0:"",u=h?_constants.UrlParameter.Conversion+!0:"",v=i?_constants.UrlParameter.Geolocation+!0:"",w=j?_constants.UrlParameter.Experiment+!0:"",x=k?_constants.UrlParameter.Page+!0:"",y=_constants.UrlParameter.StaticData+!0,z=g?_constants.UrlParameter.CurrentVisit+!0:"",A=o?_constants.UrlParameter.Kcs+!0:"",B=p?_constants.UrlParameter.Personalization+!0:"",C="number"==typeof f?_constants.UrlParameter.MaxNumberPreviousVisits+f:_constants.UrlParameter.MaxNumberPreviousVisits+1,D=r?_constants.UrlParameter.Cbs+!0:"";return this.getDataApiUrl(_types.DataApiQuery.VisitData)+this.siteCode+s+b+C+t+u+v+w+x+y+z+A+B+D}getTrackingUrl(a){this.isInitialized();const{type:b,version:c}=this.packageInfo;let d=this.getDataApiUrl(_types.DataApiQuery.VisitEvent)+this.siteCode+_constants.UrlParameter.SdkName+b.toLowerCase()+_constants.UrlParameter.SdkVersion+c;return a&&(d+=_constants.UrlParameter.BodyUa+!0),d}isInitialized(){if(!this.ready)throw new Error("UrlProvider is not initialized")}getDataApiUrl(a){if(!this.domains[_types.UrlType.DataApi])throw new Error("Data API domain is not set");const b=`https://${this.domains[_types.UrlType.DataApi]}`;return a===_types.DataApiQuery.VisitEvent?`${b}/${_constants.UrlTracking.Visit+_constants.UrlQuery.Events}`:a===_types.DataApiQuery.VisitData?`${b}/${_constants.UrlTracking.Visit+_constants.UrlQuery.Visitor}`:a===_types.DataApiQuery.DataMap?`${b}/${_constants.UrlTracking.Map+_constants.UrlQuery.Map}`:void 0}setDomains(a){a&&(this.isCustomDomain=!0,this.domains[_types.UrlType.DataApi]="data."+a,this.domains[_types.UrlType.Events]="events."+a,this.domains[_types.UrlType.ClientConfiguration]="sdk-config."+a)}}exports.UrlProvider=UrlProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionFactory=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../../kameleoonError"),_types=require("../types"),_browser=require("./browser"),_conversion=require("./conversion"),_customData=require("./customData"),_device=require("./device"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ConditionFactory=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../../kameleoonError"),_types=require("../types"),_browser=require("./browser"),_conversion=require("./conversion"),_customData=require("./customData"),_device=require("./device"),_pageTitle=require("./pageTitle"),_pageUrl=require("./pageUrl"),_sdkLanguage=require("./sdkLanguage"),_visitorCode=require("./visitorCode"),_cookie=require("./cookie"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_segment=require("./segment"),_targetFeatureFlag=require("./targetFeatureFlag"),_previousPage=require("./previousPage"),_visitedPages=require("./visitedPages"),_firstVisit=require("./firstVisit"),_lastVisit=require("./lastVisit"),_sameDayVisits=require("./sameDayVisits"),_visits=require("./visits"),_newVisitor=require("./newVisitor"),_applicationVersion=require("./applicationVersion"),_conversionLikelihood=require("./conversionLikelihood"),_logging=require("../../logging"),_exclusiveExperiment=require("./exclusiveExperiment"),_targetExperiment=require("./targetExperiment"),_targetPersonalization=require("./targetPersonalization"),_conditionFactoryInstance=require("./conditionFactoryInstance");class ConditionFactory{createCondition(a){const{targetingType:b}=a;return b===_types.TargetingType.CUSTOM_DATUM?(0,_tsRes.Ok)(new _customData.CustomData(a)):b===_types.TargetingType.EXCLUSIVE_EXPERIMENT?(0,_tsRes.Ok)(new _exclusiveExperiment.ExclusiveExperimentCondition(a)):b===_types.TargetingType.TARGET_EXPERIMENT?(0,_tsRes.Ok)(new _targetExperiment.TargetExperimentCondition(a)):b===_types.TargetingType.TARGET_FEATURE_FLAG?(0,_tsRes.Ok)(new _targetFeatureFlag.TargetFeatureFlag(a)):b===_types.TargetingType.TARGET_PERSONALIZATION?(0,_tsRes.Ok)(new _targetPersonalization.TargetPersonalizationCondition(a)):b===_types.TargetingType.DEVICE_TYPE?(0,_tsRes.Ok)(new _device.Device(a)):b===_types.TargetingType.BROWSER?(0,_tsRes.Ok)(new _browser.Browser(a)):b===_types.TargetingType.PAGE_URL?(0,_tsRes.Ok)(new _pageUrl.PageUrl(a)):b===_types.TargetingType.PAGE_TITLE?(0,_tsRes.Ok)(new _pageTitle.PageTitle(a)):b===_types.TargetingType.CONVERSIONS?(0,_tsRes.Ok)(new _conversion.Conversion(a)):b===_types.TargetingType.VISITOR_CODE?(0,_tsRes.Ok)(new _visitorCode.VisitorCode(a)):b===_types.TargetingType.SDK_LANGUAGE?(0,_tsRes.Ok)(new _sdkLanguage.SdkLanguage(a)):b===_types.TargetingType.COOKIE?(0,_tsRes.Ok)(new _cookie.Cookie(a)):b===_types.TargetingType.OPERATING_SYSTEM?(0,_tsRes.Ok)(new _operatingSystem.OperatingSystem(a)):b===_types.TargetingType.GEOLOCATION?(0,_tsRes.Ok)(new _geolocation.GeolocationCondition(a)):b===_types.TargetingType.SEGMENT?(0,_tsRes.Ok)(new _segment.Segment(a)):b===_types.TargetingType.APPLICATION_VERSION?(0,_tsRes.Ok)(new _applicationVersion.ApplicationVersion(a)):b===_types.TargetingType.PREVIOUS_PAGE?(0,_tsRes.Ok)(new _previousPage.PreviousPage(a)):b===_types.TargetingType.PAGE_VIEWS?(0,_tsRes.Ok)(new _visitedPages.VisitedPages(a)):b===_types.TargetingType.LAST_VISIT?(0,_tsRes.Ok)(new _lastVisit.LastVisit(a)):b===_types.TargetingType.FIRST_VISIT?(0,_tsRes.Ok)(new _firstVisit.FirstVisit(a)):b===_types.TargetingType.SAME_DAY_VISITS?(0,_tsRes.Ok)(new _sameDayVisits.SameDayVisits(a)):b===_types.TargetingType.VISITS?(0,_tsRes.Ok)(new _visits.Visits(a)):b===_types.TargetingType.NEW_VISITORS?(0,_tsRes.Ok)(new _newVisitor.NewVisitor(a)):b===_types.TargetingType.HEAT_SLICE?(0,_tsRes.Ok)(new _conversionLikelihood.ConversionLikelihood(a)):(_logging.KameleoonLogger.error`Unsupported targeted condition type found: ${b}`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.TargetingCondition,b)))}}exports.ConditionFactory=ConditionFactory,_conditionFactoryInstance.ConditionFactoryInstance.setConditionFactoryInstance(new ConditionFactory);
|
|
@@ -7,6 +7,6 @@ export declare class FirstVisit implements ICondition {
|
|
|
7
7
|
private conditionValue?;
|
|
8
8
|
private timeUnit?;
|
|
9
9
|
constructor({ matchType, count, unitOfTime }: ConditionDataType);
|
|
10
|
-
evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
10
|
+
evaluate({ targetingData, sdkInfo, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
11
11
|
private checkCondition;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirstVisit=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_utilities=require("../../utilities"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class FirstVisit{constructor(a){let{matchType:b,count:c,unitOfTime:d}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=b,this.conditionValue=c,this.timeUnit=d}evaluate(a){let{targetingData:b}=a;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirstVisit=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_utilities=require("../../utilities"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class FirstVisit{constructor(a){let{matchType:b,count:c,unitOfTime:d}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=b,this.conditionValue=c,this.timeUnit=d}evaluate(a){let{targetingData:b,sdkInfo:c}=a;const d=null===b||void 0===b?void 0:b[_types.KameleoonData.VisitsData];if(c.isServer?!(null!==d&&void 0!==d&&d.visits.length):!(null!==d&&void 0!==d&&d.visits)||2>d.visits.length)return(0,_tsRes.Ok)(!1);const e=d.visits[0];return(0,_tsRes.Ok)(this.checkCondition("number"==typeof e?e:e.timeStarted))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue||!this.timeUnit)return!1;const b=Date.now()-a,c=_utilities.Utilities.convertTimeUnit(b,this.timeUnit);switch(this.matchType){case _types2.MatchType.GREATER:return c>this.conditionValue;case _types2.MatchType.LOWER:return c<this.conditionValue;default:return _logging.KameleoonLogger.error`Unexpected comparing operation for FirstVisit condition: ${this.matchType}`,!1}}}exports.FirstVisit=FirstVisit;
|
|
@@ -7,6 +7,6 @@ export declare class LastVisit implements ICondition {
|
|
|
7
7
|
private conditionValue?;
|
|
8
8
|
private timeUnit?;
|
|
9
9
|
constructor({ matchType, count, unitOfTime }: ConditionDataType);
|
|
10
|
-
evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
10
|
+
evaluate({ targetingData, sdkInfo, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
11
11
|
private checkCondition;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LastVisit=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_utilities=require("../../utilities"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class LastVisit{constructor(a){let{matchType:b,count:c,unitOfTime:d}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=b,this.conditionValue=c,this.timeUnit=d}evaluate(a){let{targetingData:b}=a;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LastVisit=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_utilities=require("../../utilities"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class LastVisit{constructor(a){let{matchType:b,count:c,unitOfTime:d}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=b,this.conditionValue=c,this.timeUnit=d}evaluate(a){let{targetingData:b,sdkInfo:c}=a;const d=null===b||void 0===b?void 0:b[_types.KameleoonData.VisitsData];if(c.isServer?!(null!==d&&void 0!==d&&d.visits.length):!(null!==d&&void 0!==d&&d.visits)||2>d.visits.length)return(0,_tsRes.Ok)(!1);const e=d.visits,f=c.isServer?e.length-1:e.length-2,g=e[f];return(0,_tsRes.Ok)(this.checkCondition("number"==typeof g?g:g.timeStarted))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue||!this.timeUnit)return!1;const b=Date.now()-a,c=_utilities.Utilities.convertTimeUnit(b,this.timeUnit);switch(this.matchType){case _types2.MatchType.GREATER:return c>this.conditionValue;case _types2.MatchType.LOWER:return c<this.conditionValue;default:return _logging.KameleoonLogger.error`Unexpected comparing operation for LastVisit condition: ${this.matchType}`,!1}}}exports.LastVisit=LastVisit;
|
|
@@ -5,5 +5,5 @@ import { ConditionDataType, ICondition } from './types';
|
|
|
5
5
|
export declare class NewVisitor implements ICondition {
|
|
6
6
|
private visitorType?;
|
|
7
7
|
constructor({ visitorType }: ConditionDataType);
|
|
8
|
-
evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
8
|
+
evaluate({ targetingData, sdkInfo, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
9
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NewVisitor=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_kameleoonError=require("../../kameleoonError"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class NewVisitor{constructor(a){let{visitorType:b}=a;_defineProperty(this,"visitorType",void 0),this.visitorType=b}evaluate(a){let{targetingData:b}=a;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NewVisitor=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_kameleoonError=require("../../kameleoonError"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class NewVisitor{constructor(a){let{visitorType:b}=a;_defineProperty(this,"visitorType",void 0),this.visitorType=b}evaluate(a){let{targetingData:b,sdkInfo:c}=a;const d=null===b||void 0===b?void 0:b[_types.KameleoonData.VisitsData];if(!d||!this.visitorType)return(0,_tsRes.Ok)(!1);const{visits:e}=d,f=c.isServer?!e.length:1>=e.length;switch(this.visitorType){case _types2.VisitorType.NEW:return(0,_tsRes.Ok)(f);case _types2.VisitorType.RETURNING:return(0,_tsRes.Ok)(!f);default:_logging.KameleoonLogger.error`Unexpected visitor type for NewVisitor condition: ${this.visitorType}`,(0,_kameleoonError.exhaustCheck)(this.visitorType)}}}exports.NewVisitor=NewVisitor;
|
|
@@ -6,6 +6,6 @@ export declare class SameDayVisits implements ICondition {
|
|
|
6
6
|
private matchType?;
|
|
7
7
|
private conditionValue?;
|
|
8
8
|
constructor({ matchType, visitCount }: ConditionDataType);
|
|
9
|
-
evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
9
|
+
evaluate({ targetingData, sdkInfo, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
10
10
|
private checkCondition;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SameDayVisits=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class SameDayVisits{constructor(a){let{matchType:b,visitCount:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SameDayVisits=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class SameDayVisits{constructor(a){let{matchType:b,visitCount:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b,sdkInfo:c}=a;const d=null===b||void 0===b?void 0:b[_types.KameleoonData.VisitsData];if(!d)return(0,_tsRes.Ok)(!1);let e=0;const f=new Date().setHours(0,0,0,0),{visits:g}=d;return g.forEach(a=>{let b;b="number"==typeof a?a:a.timeStarted,b>=f&&e++}),c.isServer&&(e+=1),(0,_tsRes.Ok)(this.checkCondition(e))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue)return!1;switch(this.matchType){case _types2.MatchType.EQUAL:return a===this.conditionValue;case _types2.MatchType.GREATER:return a>this.conditionValue;case _types2.MatchType.LOWER:return a<this.conditionValue;default:return _logging.KameleoonLogger.error`Unexpected comparing operation for SameDayVisits condition: ${this.matchType}`,!1}}}exports.SameDayVisits=SameDayVisits;
|
|
@@ -6,6 +6,6 @@ export declare class Visits implements ICondition {
|
|
|
6
6
|
private matchType?;
|
|
7
7
|
private conditionValue?;
|
|
8
8
|
constructor({ matchType, visitCount }: ConditionDataType);
|
|
9
|
-
evaluate({ targetingData, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
9
|
+
evaluate({ targetingData, sdkInfo, }: EvaluationDataType): Result<boolean, KameleoonError>;
|
|
10
10
|
private checkCondition;
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Visits=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Visits{constructor(a){let{matchType:b,visitCount:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Visits=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_types2=require("../types"),_logging=require("../../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Visits{constructor(a){let{matchType:b,visitCount:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b,sdkInfo:c}=a;const d=null===b||void 0===b?void 0:b[_types.KameleoonData.VisitsData];if(!d)return(0,_tsRes.Ok)(!1);const e=d.visits.length+(c.isServer?1:0);return(0,_tsRes.Ok)(this.checkCondition(e))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue)return!1;switch(this.matchType){case _types2.MatchType.EQUAL:return a===this.conditionValue;case _types2.MatchType.GREATER:return a>this.conditionValue;case _types2.MatchType.LOWER:return a<this.conditionValue;default:return _logging.KameleoonLogger.error`Unexpected comparing operation for Visits condition: ${this.matchType}`,!1}}}exports.Visits=Visits;
|
|
@@ -157,7 +157,6 @@ export declare enum TargetingType {
|
|
|
157
157
|
TARGET_FEATURE_FLAG = "TARGET_FEATURE_FLAG",
|
|
158
158
|
TARGET_PERSONALIZATION = "TARGET_PERSONALIZATION",
|
|
159
159
|
EXCLUSIVE_EXPERIMENT = "EXCLUSIVE_EXPERIMENT",
|
|
160
|
-
EXCLUSIVE_FEATURE_FLAG = "EXCLUSIVE_FEATURE_FLAG",
|
|
161
160
|
CONVERSIONS = "CONVERSIONS",
|
|
162
161
|
CUSTOM_DATUM = "CUSTOM_DATUM",
|
|
163
162
|
YSANCE_SEGMENT = "YSANCE_SEGMENT",
|
package/dist/targeting/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"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=exports.CampaignType=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}({}),CampaignType=exports.CampaignType=function(a){return a.Experiment="EXPERIMENT",a.Personalization="PERSONALIZATION",a.Any="ANY",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.
|
|
1
|
+
"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=exports.CampaignType=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}({}),CampaignType=exports.CampaignType=function(a){return a.Experiment="EXPERIMENT",a.Personalization="PERSONALIZATION",a.Any="ANY",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.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}({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BodyProvider=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../kameleoonData"),_requester=require("../requester"),_utilities=require("../utilities"),_constants=require("./constants"),_logging=require("../logging");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class BodyProvider{constructor(a){_defineProperty(this,"prng",void 0),_defineProperty(this,"currentSize",0),_defineProperty(this,"resultBody",[]),_defineProperty(this,"hasUserAgent",!1),_defineProperty(this,"trackingVisitors",{}),this.prng=a}getTrackingBody(){const a={body:this.resultBody.join("\n"),hasUserAgent:this.hasUserAgent};return this.cleanup(),a}addData(a){let{visitorCode:b,variationData:c,visitorData:d,userAgent:e,isConsentProvided:f,isMappingIdentifier:g}=a;const h=[],i=this.getVariationDataLines(c),j=this.getVisitorDataLines(d);return h.push(...i,...j),this.addVisitorTrackingLines({visitorCode:b,lines:h,userAgent:e,isConsentProvided:f,isMappingIdentifier:g})}getVisitorDataLines(a){const b=[];for(const c of a){let a;if(c.data.type===_kameleoonData.KameleoonData.Conversion||c.data.type===_kameleoonData.KameleoonData.PageView){const b=c.data.nonce;b?a=b:(a=_utilities.Utilities.getNonce(this.prng),c.data.nonce=a)}a||(a=_utilities.Utilities.getNonce(this.prng)),b.push(c.url+_requester.UrlParameter.Nonce+a)}return b}getVariationDataLines(a){const b=[];return a.forEach(a=>{b.push(_requester.UrlEventType.Experiment+_requester.UrlParameter.Id+a.experimentId+_requester.UrlParameter.VariationId+a.variationId+_requester.UrlParameter.Nonce+_utilities.Utilities.getNonce(this.prng))}),b}prepareVisitorBody(a){const b=this.trackingVisitors[a];if(!b)return(0,_tsRes.Err)();const{lines:c,userAgent:d,isMappingIdentifier:e,isConsentProvided:f}=b,g=this.getIdentifier(a,e);if(c.length)c.forEach((a,b)=>{c[b]=a+g}),_logging.KameleoonLogger.debug`Sending tracking request for unsent data ${c} of visitor ${a} with given (or not required) consent ${f}`;else if(f){const b=this.getActivityLine();c.push(b+g),_logging.KameleoonLogger.debug`Sending tracking request for activity of visitor ${a} with given consent`}else _logging.KameleoonLogger.debug`No data to send for visitor ${a} with no consent`;d&&c.length&&(c[0]+=_requester.UrlParameter.UserAgent+d,this.hasUserAgent=!0);const h=this.checkSize(c);return h.ok&&this.resultBody.push(...c),h}cleanup(){this.currentSize=0,this.resultBody=[],this.hasUserAgent=!1,this.trackingVisitors={}}checkSize(a){let b=0;return(b+=a.reduce((a,b)=>a+b.length*_constants.SYMBOL_SIZE,0),b+this.currentSize>_constants.MAX_BODY_SIZE)?(0,_tsRes.Err)():(this.currentSize+=b,(0,_tsRes.Ok)())}addVisitorTrackingLines(a){let{visitorCode:b,lines:c,userAgent:d,isConsentProvided:e,isMappingIdentifier:f}=a;return this.trackingVisitors[b]?(d&&(this.trackingVisitors[b].userAgent=d),this.trackingVisitors[b].lines.push(...c)):this.trackingVisitors[b]={isMappingIdentifier:f,isConsentProvided:e,userAgent:d,lines:c},this.prepareVisitorBody(b)}getActivityLine(){return _requester.UrlEventType.Activity+_requester.UrlParameter.Nonce+_utilities.Utilities.getNonce(this.prng)}getIdentifier(a,b){const c=b?_requester.UrlParameter.MappingValue:_requester.UrlParameter.VisitorCode;return c+a}}exports.BodyProvider=BodyProvider;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BodyProvider=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../kameleoonData"),_requester=require("../requester"),_utilities=require("../utilities"),_constants=require("./constants"),_logging=require("../logging"),_staticData=require("../kameleoonData/staticData");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class BodyProvider{constructor(a){_defineProperty(this,"prng",void 0),_defineProperty(this,"currentSize",0),_defineProperty(this,"resultBody",[]),_defineProperty(this,"hasUserAgent",!1),_defineProperty(this,"trackingVisitors",{}),this.prng=a}getTrackingBody(){const a={body:this.resultBody.join("\n"),hasUserAgent:this.hasUserAgent};return this.cleanup(),a}addData(a){let{visitorCode:b,variationData:c,visitorData:d,userAgent:e,isConsentProvided:f,isMappingIdentifier:g}=a;const h=[],i=this.getVariationDataLines(c),j=this.getVisitorDataLines(d);return h.push(...i,...j),this.addVisitorTrackingLines({visitorCode:b,lines:h,userAgent:e,isConsentProvided:f,isMappingIdentifier:g})}getVisitorDataLines(a){const b=[];for(const c of a){let a;if(!(c instanceof _staticData.StaticData)&&(c.data.type===_kameleoonData.KameleoonData.Conversion||c.data.type===_kameleoonData.KameleoonData.PageView)){const b=c.data.nonce;b?a=b:(a=_utilities.Utilities.getNonce(this.prng),c.data.nonce=a)}a||(a=_utilities.Utilities.getNonce(this.prng)),b.push(c.url+_requester.UrlParameter.Nonce+a)}return b}getVariationDataLines(a){const b=[];return a.forEach(a=>{b.push(_requester.UrlEventType.Experiment+_requester.UrlParameter.Id+a.experimentId+_requester.UrlParameter.VariationId+a.variationId+_requester.UrlParameter.Nonce+_utilities.Utilities.getNonce(this.prng))}),b}prepareVisitorBody(a){const b=this.trackingVisitors[a];if(!b)return(0,_tsRes.Err)();const{lines:c,userAgent:d,isMappingIdentifier:e,isConsentProvided:f}=b,g=this.getIdentifier(a,e);if(c.length)c.forEach((a,b)=>{c[b]=a+g}),_logging.KameleoonLogger.debug`Sending tracking request for unsent data ${c} of visitor ${a} with given (or not required) consent ${f}`;else if(f){const b=this.getActivityLine();c.push(b+g),_logging.KameleoonLogger.debug`Sending tracking request for activity of visitor ${a} with given consent`}else _logging.KameleoonLogger.debug`No data to send for visitor ${a} with no consent`;d&&c.length&&(c[0]+=_requester.UrlParameter.UserAgent+d,this.hasUserAgent=!0);const h=this.checkSize(c);return h.ok&&this.resultBody.push(...c),h}cleanup(){this.currentSize=0,this.resultBody=[],this.hasUserAgent=!1,this.trackingVisitors={}}checkSize(a){let b=0;return(b+=a.reduce((a,b)=>a+b.length*_constants.SYMBOL_SIZE,0),b+this.currentSize>_constants.MAX_BODY_SIZE)?(0,_tsRes.Err)():(this.currentSize+=b,(0,_tsRes.Ok)())}addVisitorTrackingLines(a){let{visitorCode:b,lines:c,userAgent:d,isConsentProvided:e,isMappingIdentifier:f}=a;return this.trackingVisitors[b]?(d&&(this.trackingVisitors[b].userAgent=d),this.trackingVisitors[b].lines.push(...c)):this.trackingVisitors[b]={isMappingIdentifier:f,isConsentProvided:e,userAgent:d,lines:c},this.prepareVisitorBody(b)}getActivityLine(){return _requester.UrlEventType.Activity+_requester.UrlParameter.Nonce+_utilities.Utilities.getNonce(this.prng)}getIdentifier(a,b){const c=b?_requester.UrlParameter.MappingValue:_requester.UrlParameter.VisitorCode;return c+a}}exports.BodyProvider=BodyProvider;
|
package/dist/tracking/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Tracker } from './tracker';
|
|
1
|
+
export { Tracker, ITracker } from './tracker';
|
package/dist/tracking/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _tracker=require("./tracker");Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Tracker",{enumerable:!0,get:function(){return _tracker.Tracker}});
|
|
1
|
+
"use strict";var _tracker=require("./tracker");Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"ITracker",{enumerable:!0,get:function(){return _tracker.ITracker}}),Object.defineProperty(exports,"Tracker",{enumerable:!0,get:function(){return _tracker.Tracker}});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TrackerParametersType } from './types';
|
|
2
|
-
interface ITracker {
|
|
2
|
+
export interface ITracker {
|
|
3
3
|
scheduleVisitor: (visitorCode: string, isConsentProvided: boolean) => void;
|
|
4
4
|
}
|
|
5
5
|
export declare class Tracker implements ITracker {
|
|
@@ -19,4 +19,3 @@ export declare class Tracker implements ITracker {
|
|
|
19
19
|
private getUnsentVisitorData;
|
|
20
20
|
private getUnsentVariationData;
|
|
21
21
|
}
|
|
22
|
-
export {};
|
package/dist/tracking/tracker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tracker=void 0;var _kameleoonData=require("../kameleoonData"),_types=require("../types"),_bodyProvider=require("./bodyProvider"),_logging=require("../logging")
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tracker=void 0;var _kameleoonData=require("../kameleoonData"),_types=require("../types"),_bodyProvider=require("./bodyProvider"),_logging=require("../logging"),_staticData=require("../kameleoonData/staticData");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Tracker{constructor(a){let{dataManager:b,trackingStorage:c,variationConfiguration:d,trackingInterval:e,requester:f,prng:g}=a;_defineProperty(this,"dataManager",void 0),_defineProperty(this,"variationConfiguration",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"bodyProvider",void 0),_defineProperty(this,"intervalId",null),_defineProperty(this,"trackingStorage",void 0),_logging.KameleoonLogger.debug`CALL: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${e}, requester, prng)`,this.dataManager=b,this.trackingStorage=c,this.variationConfiguration=d,this.requester=f,this.bodyProvider=new _bodyProvider.BodyProvider(g);try{this.intervalId=setInterval(()=>{this.sendData()},e)}catch(a){throw this.intervalId&&clearInterval(this.intervalId),a}_logging.KameleoonLogger.debug`RETURN: new Tracker(dataManager, trackingStorage, variationConfiguration, trackingInterval: ${e}, requester, prng)`}scheduleVisitor(a,b){_logging.KameleoonLogger.debug`CALL: Tracker.scheduleVisitor(visitorCode: ${a}, isConsentProvided: ${b})`,this.trackingStorage.read().and(c=>{c.scheduledVisitors[`_${a}`]={isConsentProvided:b},this.trackingStorage.write(c)}),_logging.KameleoonLogger.debug`RETURN: Tracker.scheduleVisitor(visitorCode: ${a}, isConsentProvided: ${b})`}checkIsIdentifier(a){var b,c;const d=this.dataManager.isUniqueIdentifier(a),e=null!==(b=null===(c=this.dataManager.getMappingIdentifier(a))||void 0===c?void 0:c.mappingIdentifier)&&void 0!==b?b:a;let f=!1;if(d){const b=this.dataManager.getLinkedVisitor(a),c=this.dataManager.identifierCustomDataIndex;b||"number"!=typeof c?f=!0:this.dataManager.storeData(a,new _kameleoonData.CustomData(c,a))}return f&&a!=e}getUserAgent(a){const b=this.dataManager.getVisitorData(a);if(b){const a=b[_kameleoonData.KameleoonData.UserAgent];if(a)return a.value}}async sendData(){const a={},b=this.trackingStorage.read();if(!b.ok)return;const{scheduledVisitors:c}=b.data,d=[];let e=!1,f={};for(const[b,{isConsentProvided:g}]of Object.entries(c)){if(e){f[b]={isConsentProvided:g};continue}let c=b.startsWith("_")?b.substring(1):b;const h=this.checkIsIdentifier(c),i=this.getUserAgent(c),j=this.getUnsentVisitorData(c,g),k=this.getUnsentVariationData(c,g),l=this.bodyProvider.addData({visitorCode:c,variationData:k,visitorData:j,userAgent:i,isConsentProvided:g,isMappingIdentifier:h});l.ok?(a[c]={visitorData:j,variationData:k},d.push({visitorCode:c,isConsentProvided:g})):(e=!0,f[b]={isConsentProvided:g},_logging.KameleoonLogger.warning("Visitor data to be tracked exceeded the request size limit. Some visitor data is kept to be sent later. If it is not caused by the peak load, decreasing the tracking interval is recommended."))}const{body:g,hasUserAgent:h}=this.bodyProvider.getTrackingBody();if(g){this.trackingStorage.write({scheduledVisitors:f});const b=await this.requester.track(g,h);if(b.ok)_logging.KameleoonLogger.info`Successful request for tracking visitors: ${d}, data: ${a}`,this.updateDataStatus(a,_types.TrackingStatus.Sent);else{_logging.KameleoonLogger.error("Tracking request failed"),_logging.KameleoonLogger.info`Failed request for tracking visitors: ${d}, data: ${a}`,this.updateDataStatus(a,_types.TrackingStatus.Unsent);let b={};for(let{visitorCode:a,isConsentProvided:c}of d)a=`_${a}`,b[a]={isConsentProvided:c};this.addNotTrackedVisitors(b)}}}addNotTrackedVisitors(a){const b=this.trackingStorage.read();if(!b.ok)return;const{scheduledVisitors:c}=b.data;Object.entries(a).forEach(a=>{let[b,{isConsentProvided:d}]=a;c[b]||(c[b]={isConsentProvided:d})}),this.trackingStorage.write({scheduledVisitors:c})}updateDataStatus(a,b){let c={};for(const[d,{visitorData:e,variationData:f}]of Object.entries(a)){const a=e.filter(a=>!(a instanceof _staticData.StaticData)).map(a=>{const c=a;return c.status=b,c});a.length&&(c[d]=a);const g=f.map(a=>a.experimentId+"");this.variationConfiguration.updateDataStatus({visitorCode:d,experimentIdList:g,status:b})}0===Object.keys(c).length||(b===_types.TrackingStatus.Sent?this.dataManager.storeTrackedData(c):this.dataManager.storeData(c))}getUnsentVisitorData(a,b){const c=this.dataManager.getUnsentData(a),d=[];if(!c.length)return[];for(const e of c)e.url&&(e instanceof _staticData.StaticData||e.data.type===_kameleoonData.KameleoonData.Conversion||b)&&d.push(e);if(d.length){const b=d.filter(a=>!(a instanceof _staticData.StaticData)).map(a=>{const b=a;return b.status=_types.TrackingStatus.Pending,b});this.dataManager.storeTrackedData({[a]:b})}return d}getUnsentVariationData(a,b){const c=this.variationConfiguration.getUnsentData(a),d=new Set;if(!c.length)return[];const e=c.filter(a=>{const c=a.isTargetedRule||b;return c&&d.add(a.experimentId+""),c});return this.variationConfiguration.updateDataStatus({visitorCode:a,experimentIdList:Array.from(d),status:_types.TrackingStatus.Pending}),e}}exports.Tracker=Tracker;
|
package/dist/tracking/types.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { IStorage, TrackingDataType } from '../storage';
|
|
|
4
4
|
import { IExternalPRNG } from '../utilities';
|
|
5
5
|
import { VariationConfiguration } from '../variationConfiguration';
|
|
6
6
|
import { BaseVariationDataType } from '../variationConfiguration/types';
|
|
7
|
+
import { StaticData } from '../kameleoonData/staticData';
|
|
7
8
|
export type PendingDataType = {
|
|
8
9
|
[visitorCode: string]: {
|
|
9
|
-
visitorData: KameleoonDataType[];
|
|
10
|
+
visitorData: (KameleoonDataType | StaticData)[];
|
|
10
11
|
variationData: BaseVariationDataType[];
|
|
11
12
|
};
|
|
12
13
|
};
|
|
@@ -29,7 +30,7 @@ export type AddDataParametersType = {
|
|
|
29
30
|
userAgent?: string;
|
|
30
31
|
isConsentProvided: boolean;
|
|
31
32
|
variationData: BaseVariationDataType[];
|
|
32
|
-
visitorData: KameleoonDataType[];
|
|
33
|
+
visitorData: (KameleoonDataType | StaticData)[];
|
|
33
34
|
isMappingIdentifier: boolean;
|
|
34
35
|
};
|
|
35
36
|
export type GetTrackingBodyResultType = {
|
package/dist/types.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { IVisitorCodeManager } from './visitorCodeManager';
|
|
|
7
7
|
import { IExternalLogger } from './logging';
|
|
8
8
|
import { FeatureFlagType as ConfigFeatureFlagType } from './clientConfiguration/types';
|
|
9
9
|
import { Environment, ExternalPackageInfoType } from './sdkInfoTypes';
|
|
10
|
-
import { CustomData } from './kameleoonData';
|
|
10
|
+
import { CustomData, DataManager } from './kameleoonData';
|
|
11
11
|
/**
|
|
12
12
|
* @param {number} updateInterval - update interval in _minutes_ for sdk configuration, minimum value is 1 minute
|
|
13
13
|
* @defaultvalue 60
|
|
@@ -94,9 +94,12 @@ export type InternalSettingsType = {
|
|
|
94
94
|
* @param {InternalSettingsType} settings - internal settings for the SDK
|
|
95
95
|
* */
|
|
96
96
|
export type InternalSDKConfigurationType = {
|
|
97
|
-
externals: ExternalsType;
|
|
97
|
+
externals: ExternalsType & InternalDependencies;
|
|
98
98
|
settings: InternalSettingsType;
|
|
99
99
|
};
|
|
100
|
+
export type InternalDependencies = {
|
|
101
|
+
customDataManager?: DataManager;
|
|
102
|
+
};
|
|
100
103
|
/**
|
|
101
104
|
* @readonly
|
|
102
105
|
* @enum {string} an Enum containing all possible variants of feature variable types
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SECRET_VISIBLE_LENGTH=exports.REGEX_DOMAIN=exports.NONCE_LENGTH=exports.LOCALHOST=exports.HTTPS=exports.HTTP=exports.HIDDEN_SECRET_CHAR=exports.HEX_CHARACTERS=void 0;const HEX_CHARACTERS=exports.HEX_CHARACTERS="0123456789ABCDEF",NONCE_LENGTH=exports.NONCE_LENGTH=16,HTTP=exports.HTTP="http://",HTTPS=exports.HTTPS="https://",LOCALHOST=exports.LOCALHOST="localhost",REGEX_DOMAIN=exports.REGEX_DOMAIN=/^(\.?(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d]))(\.(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d])){1,126}$/,HIDDEN_SECRET_CHAR=exports.HIDDEN_SECRET_CHAR="*",SECRET_VISIBLE_LENGTH=exports.SECRET_VISIBLE_LENGTH=4;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VISITOR_VISIT_MAX_LENGTH=exports.SECRET_VISIBLE_LENGTH=exports.REGEX_DOMAIN=exports.NONCE_LENGTH=exports.LOCALHOST=exports.HTTPS=exports.HTTP=exports.HIDDEN_SECRET_CHAR=exports.HEX_CHARACTERS=void 0;const HEX_CHARACTERS=exports.HEX_CHARACTERS="0123456789ABCDEF",NONCE_LENGTH=exports.NONCE_LENGTH=16,HTTP=exports.HTTP="http://",HTTPS=exports.HTTPS="https://",LOCALHOST=exports.LOCALHOST="localhost",REGEX_DOMAIN=exports.REGEX_DOMAIN=/^(\.?(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d]))(\.(([a-zA-Z\d][a-zA-Z\d-]*[a-zA-Z\d])|[a-zA-Z\d])){1,126}$/,HIDDEN_SECRET_CHAR=exports.HIDDEN_SECRET_CHAR="*",SECRET_VISIBLE_LENGTH=exports.SECRET_VISIBLE_LENGTH=4,VISITOR_VISIT_MAX_LENGTH=exports.VISITOR_VISIT_MAX_LENGTH=26;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InsertInOrderedListParametersType } from '../utilities/types';
|
|
1
|
+
import { InsertInOrderedListParametersType, InsertVisitInOrderedListParametersType } from '../utilities/types';
|
|
2
2
|
export declare class ListUtilities {
|
|
3
3
|
/**
|
|
4
4
|
* Insert element in ordered list, if element already exists in list, does nothing
|
|
@@ -7,4 +7,10 @@ export declare class ListUtilities {
|
|
|
7
7
|
* @param order - order of list
|
|
8
8
|
*/
|
|
9
9
|
static insertInOrderedListMutably({ list, element, order, }: InsertInOrderedListParametersType): void;
|
|
10
|
+
/**
|
|
11
|
+
* Insert visit in ordered list, if visit already exists in list, does nothing
|
|
12
|
+
* @param list - list to insert element
|
|
13
|
+
* @param visit - visit to insert
|
|
14
|
+
*/
|
|
15
|
+
static insertVisitInOrderedListMutably({ list, visit, }: InsertVisitInOrderedListParametersType): void;
|
|
10
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ListUtilities=void 0;var _types=require("./types"),_constants=require("./constants");class ListUtilities{static insertInOrderedListMutably(a){let{list:b,element:c,order:d}=a;if(!b.includes(c)){const a=b.findIndex(a=>d===_types.Order.Ascending?a>=c:a<=c);-1===a?b.push(c):b.splice(a,0,c)}}static insertVisitInOrderedListMutably(a){let{list:b,visit:c}=a;const d=b.find(a=>"number"==typeof a?a===c.timeStarted:a.timeStarted===c.timeStarted);if(!d){const a=b.findIndex(a=>"number"==typeof a?a>=c.timeStarted:a.timeStarted>=c.timeStarted);-1===a?b.push(c):b.splice(a,0,c),b.length>_constants.VISITOR_VISIT_MAX_LENGTH&&b.splice(0,b.length-_constants.VISITOR_VISIT_MAX_LENGTH)}}}exports.ListUtilities=ListUtilities;
|
package/dist/utilities/parser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Parser=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants=require("./constants"),_visitsData=require("../kameleoonData/visitsData");class Parser{static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.JS:case _types.VariableType.CSS:case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor({filters:c,dataManager:e,visitorCode:d}),{currentVisit:h,previousVisits:i,kcs:j,cbs:k}=b;if(!(null!==i&&void 0!==i&&i.length)&&!h)return{visitorData:[],storageVisitorData:[],visitsData:new _visitsData.VisitsData([])};h&&g.processVisit(h),null===i||void 0===i?void 0:i.forEach(a=>{g.processVisit(a),g.processVisitsData(a)}),g.processKcs(j),g.processCbs(k),g.processMultipleDataTypes();const l=g.processMappingIdentifier(null!==h&&void 0!==h?h:null===i||void 0===i?void 0:i[0]),{visitorData:m,storageVisitorData:n,visitsData:o,experimentData:p}=g.data;return f.updateStoredVariations(d,p),{visitorData:m,storageVisitorData:n,visitsData:o,mappingIdentifier:l}}static parseRegExp(a){if("/"===a[0]){const[_,b,c]=a.split("/");return new RegExp(b,c)}return new RegExp(a)}static parseSecret(a){if(null===a)return"null";const b=a.length;if(b<=_constants.SECRET_VISIBLE_LENGTH)return _constants.HIDDEN_SECRET_CHAR.repeat(b);const c=Math.max(b-_constants.SECRET_VISIBLE_LENGTH,_constants.SECRET_VISIBLE_LENGTH);return a.substring(0,b-c)+_constants.HIDDEN_SECRET_CHAR.repeat(c)}}exports.Parser=Parser;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Parser=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants=require("./constants"),_visitsData=require("../kameleoonData/visitsData");class Parser{static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.JS:case _types.VariableType.CSS:case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor({filters:c,dataManager:e,visitorCode:d}),{currentVisit:h,previousVisits:i,kcs:j,cbs:k}=b;if(!(null!==i&&void 0!==i&&i.length)&&!h)return{visitorData:[],storageVisitorData:[],visitsData:new _visitsData.VisitsData([])};h&&(g.processVisit(h),g.processVisitNumber(h,!0)),null===i||void 0===i?void 0:i.forEach(a=>{g.processVisit(a),g.processVisitsData(a),g.processVisitNumber(a,!1)}),g.processKcs(j),g.processCbs(k),g.processMultipleDataTypes();const l=g.processMappingIdentifier(null!==h&&void 0!==h?h:null===i||void 0===i?void 0:i[0]),{visitorData:m,storageVisitorData:n,visitsData:o,experimentData:p}=g.data;return f.updateStoredVariations(d,p),{visitorData:m,storageVisitorData:n,visitsData:o,mappingIdentifier:l}}static parseRegExp(a){if("/"===a[0]){const[_,b,c]=a.split("/");return new RegExp(b,c)}return new RegExp(a)}static parseSecret(a){if(null===a)return"null";const b=a.length;if(b<=_constants.SECRET_VISIBLE_LENGTH)return _constants.HIDDEN_SECRET_CHAR.repeat(b);const c=Math.max(b-_constants.SECRET_VISIBLE_LENGTH,_constants.SECRET_VISIBLE_LENGTH);return a.substring(0,b-c)+_constants.HIDDEN_SECRET_CHAR.repeat(c)}}exports.Parser=Parser;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CacheManager } from '../cacheManager';
|
|
2
2
|
import { ClientConfiguration } from '../clientConfiguration';
|
|
3
3
|
import { DataManager } from '../kameleoonData';
|
|
4
|
-
import { KameleoonDataType, KameleoonVisitorDataType } from '../kameleoonData/types';
|
|
4
|
+
import { KameleoonDataType, KameleoonVisitorDataType, VisitDataType } from '../kameleoonData/types';
|
|
5
5
|
import { Requester } from '../requester';
|
|
6
6
|
import { GetVisitorDataResultType } from '../requester/types';
|
|
7
7
|
import { SegmentType } from '../targeting';
|
|
@@ -35,6 +35,10 @@ export type InsertInOrderedListParametersType = {
|
|
|
35
35
|
element: number;
|
|
36
36
|
order: Order;
|
|
37
37
|
};
|
|
38
|
+
export type InsertVisitInOrderedListParametersType = {
|
|
39
|
+
list: VisitDataType[];
|
|
40
|
+
visit: VisitDataType;
|
|
41
|
+
};
|
|
38
42
|
export type ParseVisitorDataParametersType = {
|
|
39
43
|
data: GetVisitorDataResultType;
|
|
40
44
|
filters: VisitorDataFiltersType;
|