@kameleoon/javascript-sdk-core 4.4.4 → 4.4.6
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
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 4.4.6 (2024-08-15)
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed the issue with mapping identifier Custom Data not being set correctly after browser tab reload
|
|
8
|
+
|
|
9
|
+
## 4.4.5 (2024-08-08)
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Fixed an issue that caused duplicate entries in feature flag results for both anonymous and authorized/identified visitors during data reconciliation. This problem occurred when custom data of type mapping ID was not consistently sent for all sessions.
|
|
14
|
+
|
|
3
15
|
## 4.4.4 (2024-07-19)
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_constants=require("./constants"),_types=require("./types"),_utilities=require("../utilities"),_eventManager=require("../eventManager"),_urlProvider=require("../requester/urlProvider");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class ClientConfiguration{constructor(a){let{updateInterval:b,storage:c,requester:d,dataManager:e,externalClientConfiguration:f,offlineTrackingStorage:g,eventSource:h,externalVisitorCodeManager:i,eventManager:j}=a;_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Idle),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"featureFlagsData",new Map),_defineProperty(this,"isTargetedDeliveryRule",null),_defineProperty(this,"segmentsData",null),_defineProperty(this,"updateInterval",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"mappedRules",null),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),this.requester=d,this.updateInterval=b,this.lastUpdate=new Date,this.storage=c,this.dataManager=e,this.eventManager=j,this.externalClientConfiguration=f,this.offlineTrackingStorage=g,this.visitorCodeManager=i,this.eventSource=h}async initialize(){this.readStorageData();const a=!!this.externalClientConfiguration,b=this.checkShouldUpdate(a);if(b){const a=await this.updateClientConfiguration();if(!a.ok)return a;const b=a.data;if(b)return(0,_tsRes.Ok)()}return a?(this.handleExternalUpdates(),(0,_tsRes.Ok)()):this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),(0,_tsRes.Ok)()):(this.updateType=_types.UpdateType.Idle,this.handleRealTimeUpdates(),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleExternalUpdates(){this.cleanupHandlers();const{customData:a,configuration:b,featureFlags:c}=this.externalClientConfiguration;this.configurationData={customData:a,configuration:b};for(const a of c)this.featureFlagsData.set(a.featureKey,a)}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(b=>{b.ok&&this.eventManager.fireEvent(_eventManager.EventType.ConfigurationUpdate,{timestamp:a})})};this.eventSource.open(a)}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}get featureFlags(){return this.featureFlagsData}get configuration(){return this.configurationData.configuration}get segments(){if(this.segmentsData)return this.segmentsData;const a=new Map;return this.featureFlagsData.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),this.segmentsData=a,a}get ruleMap(){if(this.mappedRules)return this.mappedRules;const a=new Map;for(const b of this.featureFlags.values())for(const c of b.rules){const{id:d,experimentId:e,variationByExposition:f}=c,g=new Map;f.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&g.set(b,c)}),a.set(d,{featureId:b.id,experimentId:e,variations:g})}return this.mappedRules=a,a}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){if(null!==this.isTargetedDeliveryRule)return this.isTargetedDeliveryRule;for(const a of this.featureFlags.values())if(a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))return!0;return!1}checkIntegrity(a){if(!a)return!1;const b=Object.keys(a);if(!b.length)return!1;const c=Object.keys(_constants.DEFAULT_CLIENT_CONFIGURATION);return b.sort().join()===c.sort().join()}checkShouldUpdate(){let a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0];const{configuration:b}=this.configurationData;if(a)return this.updateType=_types.UpdateType.Idle,!1;if(this.updateType=b.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!this.featureFlags.size)return!0;const c=this.lastUpdate.getTime(),d=Date.now()-this.updateInterval;return c<d}readStorageData(){const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data,d=this.checkIntegrity(b);if(!d){_urlProvider.UrlProvider.setDataApiDomain(_constants.DEFAULT_CONFIGURATION_DATA.configuration.dataApiDomain);const a=_objectSpread(_objectSpread({},_constants.DEFAULT_CONFIGURATION_DATA),{},{featureFlags:[]});this.storage.write({data:a,lastUpdate:this.lastUpdate.toString()}),this.configurationData=_constants.DEFAULT_CONFIGURATION_DATA}else{_urlProvider.UrlProvider.setDataApiDomain(b.configuration.dataApiDomain);const{featureFlags:a}=b;for(const b of a)this.featureFlagsData.set(b.featureKey,b);this.configurationData=b,this.lastUpdate=new Date(Date.parse(c))}}}async updateClientConfiguration(a){var b;const c=await this.requester.getClientConfiguration(a);if(!c.ok)return this.featureFlags.size?(0,_tsRes.Ok)(!0):c;_utilities.Utilities.sendOfflineTracking({storage:this.offlineTrackingStorage,requester:this.requester});const{configuration:d,customData:e,featureFlags:f}=c.data;this.configurationData={configuration:d,customData:e};for(const b of f)this.featureFlagsData.set(b.featureKey,b);null!==e&&void 0!==e&&e.length&&(this.dataManager.customDataIndexes=e),this.dataManager.clearTrees(),null===(b=this.mappedRules)||void 0===b?void 0:b.clear(),this.isTargetedDeliveryRule=null,this.segmentsData=null;const g=this.updateStorageData();if(!g.ok)return g;const h=d.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,i=h!==this.updateType;i&&(this.updateType=h,await this.initialize());const j=this.isConsentRequired&&!this.hasAnyTargetedDeliveryRule;return this.visitorCodeManager.consentRequired=j,(0,_tsRes.Ok)(i)}updateStorageData(){this.lastUpdate=new Date;const a=_objectSpread(_objectSpread({},this.configurationData),{},{featureFlags:Array.from(this.featureFlags.values())}),b={data:a,lastUpdate:this.lastUpdate.toString()};return _urlProvider.UrlProvider.setDataApiDomain(this.configurationData.configuration.dataApiDomain),this.storage.write(b)}}exports.ClientConfiguration=ClientConfiguration;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_constants=require("./constants"),_types=require("./types"),_utilities=require("../utilities"),_eventManager=require("../eventManager"),_urlProvider=require("../requester/urlProvider");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class ClientConfiguration{constructor(a){let{updateInterval:b,storage:c,requester:d,dataManager:e,externalClientConfiguration:f,offlineTrackingStorage:g,eventSource:h,externalVisitorCodeManager:i,eventManager:j}=a;_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Idle),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"featureFlagsData",new Map),_defineProperty(this,"isTargetedDeliveryRule",null),_defineProperty(this,"segmentsData",null),_defineProperty(this,"updateInterval",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"mappedRules",null),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),this.requester=d,this.updateInterval=b,this.lastUpdate=new Date,this.storage=c,this.dataManager=e,this.eventManager=j,this.externalClientConfiguration=f,this.offlineTrackingStorage=g,this.visitorCodeManager=i,this.eventSource=h}async initialize(){this.readStorageData();const a=!!this.externalClientConfiguration,b=this.checkShouldUpdate(a);if(b){const a=await this.updateClientConfiguration();if(!a.ok)return a;const b=a.data;if(b)return(0,_tsRes.Ok)()}return a?(this.handleExternalUpdates(),(0,_tsRes.Ok)()):this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),(0,_tsRes.Ok)()):(this.updateType=_types.UpdateType.Idle,this.handleRealTimeUpdates(),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleExternalUpdates(){this.cleanupHandlers();const{customData:a,configuration:b,featureFlags:c}=this.externalClientConfiguration;this.configurationData={customData:a,configuration:b};for(const a of c)this.featureFlagsData.set(a.featureKey,a)}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(b=>{b.ok&&this.eventManager.fireEvent(_eventManager.EventType.ConfigurationUpdate,{timestamp:a})})};this.eventSource.open(a)}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}get featureFlags(){return this.featureFlagsData}get configuration(){return this.configurationData.configuration}get segments(){if(this.segmentsData)return this.segmentsData;const a=new Map;return this.featureFlagsData.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),this.segmentsData=a,a}get ruleMap(){if(this.mappedRules)return this.mappedRules;const a=new Map;for(const b of this.featureFlags.values())for(const c of b.rules){const{id:d,experimentId:e,variationByExposition:f}=c,g=new Map;f.forEach(a=>{let{variationKey:b,variationId:c}=a;"number"==typeof c&&g.set(b,c)}),a.set(d,{featureId:b.id,experimentId:e,variations:g})}return this.mappedRules=a,a}get isConsentRequired(){return this.configuration.consentType===_types.ConsentType.Required}get hasAnyTargetedDeliveryRule(){if(null!==this.isTargetedDeliveryRule)return this.isTargetedDeliveryRule;for(const a of this.featureFlags.values())if(a.environmentEnabled&&a.rules.some(a=>a.type===_types.RuleType.TARGETED_DELIVERY))return!0;return!1}checkIntegrity(a){if(!a)return!1;const b=Object.keys(a);if(!b.length)return!1;const c=Object.keys(_constants.DEFAULT_CLIENT_CONFIGURATION);return b.sort().join()===c.sort().join()}checkShouldUpdate(){let a=!!(0<arguments.length&&void 0!==arguments[0])&&arguments[0];const{configuration:b}=this.configurationData;if(a)return this.updateType=_types.UpdateType.Idle,!1;if(this.updateType=b.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,!this.featureFlags.size)return!0;const c=this.lastUpdate.getTime(),d=Date.now()-this.updateInterval;return c<d}readStorageData(){const a=this.storage.read();if(a.ok){const{data:b,lastUpdate:c}=a.data,d=this.checkIntegrity(b);if(!d){_urlProvider.UrlProvider.setDataApiDomain(_constants.DEFAULT_CONFIGURATION_DATA.configuration.dataApiDomain);const a=_objectSpread(_objectSpread({},_constants.DEFAULT_CONFIGURATION_DATA),{},{featureFlags:[]});this.storage.write({data:a,lastUpdate:this.lastUpdate.toString()}),this.configurationData=_constants.DEFAULT_CONFIGURATION_DATA}else{_urlProvider.UrlProvider.setDataApiDomain(b.configuration.dataApiDomain);const{featureFlags:a,customData:d}=b;null!==d&&void 0!==d&&d.length&&(this.dataManager.customDataIndexes=d);for(const b of a)this.featureFlagsData.set(b.featureKey,b);this.configurationData=b,this.lastUpdate=new Date(Date.parse(c))}}}async updateClientConfiguration(a){var b;const c=await this.requester.getClientConfiguration(a);if(!c.ok)return this.featureFlags.size?(0,_tsRes.Ok)(!0):c;_utilities.Utilities.sendOfflineTracking({storage:this.offlineTrackingStorage,requester:this.requester});const{configuration:d,customData:e,featureFlags:f}=c.data;this.configurationData={configuration:d,customData:e};for(const b of f)this.featureFlagsData.set(b.featureKey,b);null!==e&&void 0!==e&&e.length&&(this.dataManager.customDataIndexes=e),this.dataManager.clearTrees(),null===(b=this.mappedRules)||void 0===b?void 0:b.clear(),this.isTargetedDeliveryRule=null,this.segmentsData=null;const g=this.updateStorageData();if(!g.ok)return g;const h=d.realTimeUpdate?_types.UpdateType.RealTime:_types.UpdateType.Polling,i=h!==this.updateType;i&&(this.updateType=h,await this.initialize());const j=this.isConsentRequired&&!this.hasAnyTargetedDeliveryRule;return this.visitorCodeManager.consentRequired=j,(0,_tsRes.Ok)(i)}updateStorageData(){this.lastUpdate=new Date;const a=_objectSpread(_objectSpread({},this.configurationData),{},{featureFlags:Array.from(this.featureFlags.values())}),b={data:a,lastUpdate:this.lastUpdate.toString()};return _urlProvider.UrlProvider.setDataApiDomain(this.configurationData.configuration.dataApiDomain),this.storage.write(b)}}exports.ClientConfiguration=ClientConfiguration;
|
|
2
2
|
//# sourceMappingURL=clientConfiguration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientConfiguration.js","names":["ClientConfiguration","constructor","a","updateInterval","storage","requester","dataManager","externalClientConfiguration","offlineTrackingStorage","eventSource","externalVisitorCodeManager","eventManager","_defineProperty","UpdateType","Idle","DEFAULT_CONFIGURATION_DATA","Map","lastUpdate","Date","visitorCodeManager","initialize","readStorageData","isExternalConfiguration","shouldUpdate","checkShouldUpdate","updateResult","updateClientConfiguration","ok","isUpdateTypeToggled","data","Ok","handleExternalUpdates","updateType","RealTime","isOpen","Polling","handlePollingUpdates","handleRealTimeUpdates","cleanupHandlers","close","updateConfigurationIntervalId","clearInterval","customData","configuration","featureFlags","configurationData","featureFlag","featureFlagsData","set","featureKey","updateEventCallback","timestamp","then","fireEvent","EventType","ConfigurationUpdate","open","setInterval","bind","err","segments","segmentsData","forEach","flag","rules","rule","segment","has","id","ruleMap","mappedRules","values","experimentId","variationByExposition","variationMap","variationKey","variationId","featureId","variations","isConsentRequired","consentType","ConsentType","Required","hasAnyTargetedDeliveryRule","isTargetedDeliveryRule","environmentEnabled","some","type","RuleType","TARGETED_DELIVERY","checkIntegrity","fields","Object","keys","length","requiredFields","DEFAULT_CLIENT_CONFIGURATION","sort","join","skipChecks","arguments","realTimeUpdate","size","lastUpdateTime","getTime","updateWindowEdge","now","result","read","isStorageValid","UrlProvider","setDataApiDomain","dataApiDomain","_objectSpread","write","toString","parse","b","clientConfigurationResult","getClientConfiguration","Utilities","sendOfflineTracking","customDataIndexes","clearTrees","clear","updateStorageData","toggleUpdateType","consentRequired","Array","from","exports"],"sources":["../../src/clientConfiguration/clientConfiguration.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError/kameleoonError';\nimport { DataManager } from 'src/kameleoonData';\nimport { Requester } from 'src/requester';\nimport { SegmentType } from 'src/targeting';\nimport { ClientDataType } from 'src/storage';\nimport { IEventSource } from 'src/eventSource';\nimport {\n DEFAULT_CLIENT_CONFIGURATION,\n DEFAULT_CONFIGURATION_DATA,\n} from './constants';\nimport {\n ClientConfigurationDataType,\n ClientConfigurationParametersType,\n ConfigurationDataType,\n ConfigurationType,\n ConsentType,\n FeatureFlagType,\n MappedRuleType,\n RuleType,\n UpdateType,\n} from './types';\nimport { Utilities } from 'src/utilities';\nimport { IStorage, OfflineTracking } from 'src/storage/types';\nimport { IVisitorCodeManager } from 'src/visitorCodeManager';\nimport { EventManager, EventType } from 'src/eventManager';\nimport { UrlProvider } from 'src/requester/urlProvider';\n\ninterface IClientConfiguration {\n initialize: (useCache?: boolean) => Promise<Result<void, KameleoonError>>;\n readonly featureFlags: Map<string, FeatureFlagType>;\n readonly configuration: ConfigurationType;\n readonly segments: Map<string, SegmentType>;\n readonly ruleMap: Map<number, MappedRuleType>;\n}\n\nexport class ClientConfiguration implements IClientConfiguration {\n private updateConfigurationIntervalId: NodeJS.Timeout | null = null;\n private updateType: UpdateType = UpdateType.Idle;\n private configurationData: ClientConfigurationDataType =\n DEFAULT_CONFIGURATION_DATA;\n private featureFlagsData: Map<string, FeatureFlagType> = new Map();\n private isTargetedDeliveryRule: boolean | null = null;\n private segmentsData: Map<string, SegmentType> | null = null;\n private updateInterval: number;\n private lastUpdate: Date;\n private storage: IStorage<ClientDataType>;\n private offlineTrackingStorage: IStorage<OfflineTracking>;\n private requester: Requester;\n private eventSource: IEventSource;\n private externalClientConfiguration?: ConfigurationDataType;\n private mappedRules: Map<number, MappedRuleType> | null = null;\n private dataManager: DataManager;\n private visitorCodeManager: IVisitorCodeManager;\n private eventManager: EventManager;\n\n constructor({\n updateInterval,\n storage,\n requester,\n dataManager,\n externalClientConfiguration,\n offlineTrackingStorage,\n eventSource,\n externalVisitorCodeManager,\n eventManager,\n }: ClientConfigurationParametersType) {\n this.requester = requester;\n this.updateInterval = updateInterval;\n this.lastUpdate = new Date();\n this.storage = storage;\n this.dataManager = dataManager;\n this.eventManager = eventManager;\n this.externalClientConfiguration = externalClientConfiguration;\n this.offlineTrackingStorage = offlineTrackingStorage;\n this.visitorCodeManager = externalVisitorCodeManager;\n this.eventSource = eventSource;\n }\n\n public async initialize(): Promise<Result<void, KameleoonError>> {\n this.readStorageData();\n\n const isExternalConfiguration = Boolean(this.externalClientConfiguration);\n const shouldUpdate = this.checkShouldUpdate(isExternalConfiguration);\n\n if (shouldUpdate) {\n const updateResult = await this.updateClientConfiguration();\n\n if (!updateResult.ok) {\n return updateResult;\n }\n\n // --- Note ---\n // If update type is being toggled `initialize` will be called again\n // so we don't need to continue execution here\n const isUpdateTypeToggled = updateResult.data;\n\n if (isUpdateTypeToggled) {\n return Ok();\n }\n }\n\n if (isExternalConfiguration) {\n this.handleExternalUpdates();\n\n return Ok();\n }\n\n if (this.updateType === UpdateType.RealTime && !this.eventSource.isOpen) {\n this.updateType = UpdateType.Idle;\n this.handleRealTimeUpdates();\n\n return Ok();\n }\n\n if (this.updateType === UpdateType.Polling) {\n this.handlePollingUpdates();\n }\n\n return Ok();\n }\n\n private cleanupHandlers(): void {\n if (this.eventSource.isOpen) {\n this.eventSource.close();\n }\n\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n }\n\n private handleExternalUpdates(): void {\n this.cleanupHandlers();\n\n const { customData, configuration, featureFlags } =\n this.externalClientConfiguration!;\n this.configurationData = { customData, configuration };\n\n for (const featureFlag of featureFlags) {\n this.featureFlagsData.set(featureFlag.featureKey, featureFlag);\n }\n }\n\n private handleRealTimeUpdates(): void {\n this.cleanupHandlers();\n\n const updateEventCallback = (timestamp: number) => {\n this.updateClientConfiguration(timestamp).then((updateResult) => {\n if (updateResult.ok) {\n this.eventManager.fireEvent(EventType.ConfigurationUpdate, {\n timestamp,\n });\n }\n });\n };\n\n this.eventSource.open(updateEventCallback);\n }\n\n private handlePollingUpdates(): void {\n // --- Note ---\n // If `initialize` is called again the interval will be cleared\n // so theoretically we will constantly defer config update\n // but `this.lastUpdate` with `checkShouldUpdate` will prevent that\n this.cleanupHandlers();\n\n // --- Note ---\n // Error Handling is for `setInterval` emergency cleanup\n try {\n this.updateConfigurationIntervalId = setInterval(\n this.updateClientConfiguration.bind(this),\n this.updateInterval,\n );\n } catch (err) {\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n throw err;\n }\n }\n\n get featureFlags(): Map<string, FeatureFlagType> {\n return this.featureFlagsData;\n }\n\n get configuration(): ConfigurationType {\n return this.configurationData.configuration;\n }\n\n get segments(): Map<string, SegmentType> {\n if (this.segmentsData) {\n return this.segmentsData;\n }\n\n const segmentsData = new Map<string, SegmentType>();\n\n this.featureFlagsData.forEach((flag) => {\n flag.rules.forEach((rule) => {\n if (rule.segment && !segmentsData.has(rule.segment.id)) {\n segmentsData.set(rule.segment.id, rule.segment);\n }\n });\n });\n\n this.segmentsData = segmentsData;\n\n return segmentsData;\n }\n\n get ruleMap(): Map<number, MappedRuleType> {\n if (this.mappedRules) {\n return this.mappedRules;\n }\n\n const mappedRules = new Map<number, MappedRuleType>();\n\n for (const featureFlag of this.featureFlags.values()) {\n for (const rule of featureFlag.rules) {\n const { id, experimentId, variationByExposition } = rule;\n const variationMap = new Map<string, number>();\n\n variationByExposition.forEach(({ variationKey, variationId }) => {\n if (typeof variationId === 'number') {\n variationMap.set(variationKey, variationId);\n }\n });\n\n mappedRules.set(id, {\n featureId: featureFlag.id,\n experimentId,\n variations: variationMap,\n });\n }\n }\n\n this.mappedRules = mappedRules;\n\n return mappedRules;\n }\n\n get isConsentRequired(): boolean {\n return this.configuration.consentType === ConsentType.Required;\n }\n\n get hasAnyTargetedDeliveryRule(): boolean {\n if (this.isTargetedDeliveryRule !== null) {\n return this.isTargetedDeliveryRule;\n }\n\n for (const featureFlag of this.featureFlags.values()) {\n if (\n featureFlag.environmentEnabled &&\n featureFlag.rules.some(\n (rule) => rule.type === RuleType.TARGETED_DELIVERY,\n )\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n // --- Note ---\n // Integrity check covers most of the migration scenarios\n // however in the future it will be changed to a dedicate migration\n // block that can handle all versions migrations\n private checkIntegrity(data: ConfigurationDataType | undefined): boolean {\n if (!data) {\n return false;\n }\n\n const fields = Object.keys(data);\n\n if (!fields.length) {\n return false;\n }\n\n const requiredFields = Object.keys(DEFAULT_CLIENT_CONFIGURATION);\n\n return fields.sort().join() === requiredFields.sort().join();\n }\n\n private checkShouldUpdate(skipChecks = false): boolean {\n const { configuration } = this.configurationData;\n\n // --- Note ---\n // Following `updateType` logic is done for client side\n // edge cases where we have previous campaigns on storage already, but we still want\n // to initialize SSE/Polling after page reload\n if (skipChecks) {\n this.updateType = UpdateType.Idle;\n\n return false;\n }\n\n this.updateType = configuration.realTimeUpdate\n ? UpdateType.RealTime\n : UpdateType.Polling;\n\n if (!this.featureFlags.size) {\n return true;\n }\n\n const lastUpdateTime = this.lastUpdate.getTime();\n const updateWindowEdge = Date.now() - this.updateInterval;\n\n return lastUpdateTime < updateWindowEdge;\n }\n\n private readStorageData(): void {\n const result = this.storage.read();\n\n if (result.ok) {\n const { data, lastUpdate } = result.data;\n\n const isStorageValid = this.checkIntegrity(data);\n\n // --- Note ---\n // Cleaning up storage if it's not valid for migration purposes\n if (!isStorageValid) {\n UrlProvider.setDataApiDomain(\n DEFAULT_CONFIGURATION_DATA.configuration.dataApiDomain,\n );\n\n const data = {\n ...DEFAULT_CONFIGURATION_DATA,\n featureFlags: [],\n };\n\n this.storage.write({\n data,\n lastUpdate: this.lastUpdate.toString(),\n });\n\n this.configurationData = DEFAULT_CONFIGURATION_DATA;\n } else {\n UrlProvider.setDataApiDomain(data.configuration.dataApiDomain);\n\n const { featureFlags } = data;\n\n for (const featureFlag of featureFlags) {\n this.featureFlagsData.set(featureFlag.featureKey, featureFlag);\n }\n\n this.configurationData = data;\n this.lastUpdate = new Date(Date.parse(lastUpdate));\n }\n }\n }\n\n /**\n * Updates client configuration\n *\n * @param timeStamp - timestamp for real-time configuration update\n *\n * @returns `true` if current update type should be toggled (SSE/Polling)\n */\n private async updateClientConfiguration(\n timestamp?: number,\n ): Promise<Result<boolean, KameleoonError>> {\n const clientConfigurationResult =\n await this.requester.getClientConfiguration(timestamp);\n\n if (!clientConfigurationResult.ok) {\n if (this.featureFlags.size) {\n // TODO: the case of silent fail should be logged when logging is implemented\n return Ok(true);\n }\n\n return clientConfigurationResult;\n }\n\n Utilities.sendOfflineTracking({\n storage: this.offlineTrackingStorage,\n requester: this.requester,\n });\n\n const { configuration, customData, featureFlags } =\n clientConfigurationResult.data;\n\n this.configurationData = { configuration, customData };\n\n for (const featureFlag of featureFlags) {\n this.featureFlagsData.set(featureFlag.featureKey, featureFlag);\n }\n\n if (customData?.length) {\n this.dataManager.customDataIndexes = customData;\n }\n\n this.dataManager.clearTrees();\n this.mappedRules?.clear();\n this.isTargetedDeliveryRule = null;\n this.segmentsData = null;\n\n const result = this.updateStorageData();\n\n if (!result.ok) {\n return result;\n }\n\n const updateType = configuration.realTimeUpdate\n ? UpdateType.RealTime\n : UpdateType.Polling;\n\n const toggleUpdateType = updateType !== this.updateType;\n\n if (toggleUpdateType) {\n this.updateType = updateType;\n await this.initialize();\n }\n\n // --- Note ---\n // Regarding GDPR policy we should set visitorCode if legal consent isn't required\n // or we have at least one Targeted Delivery rule in configuration\n const consentRequired =\n this.isConsentRequired && !this.hasAnyTargetedDeliveryRule;\n this.visitorCodeManager.consentRequired = consentRequired;\n\n return Ok(toggleUpdateType);\n }\n\n private updateStorageData(): Result<void, KameleoonError> {\n this.lastUpdate = new Date();\n\n const configurationData = {\n ...this.configurationData,\n featureFlags: Array.from(this.featureFlags.values()),\n };\n\n const data: ClientDataType = {\n data: configurationData,\n lastUpdate: this.lastUpdate.toString(),\n };\n\n UrlProvider.setDataApiDomain(\n this.configurationData.configuration.dataApiDomain,\n );\n\n return this.storage.write(data);\n }\n}\n"],"mappings":"k6CAoCO,KAAM,CAAAA,mBAAoD,CAoB/DC,WAAWA,CAAAC,CAAA,CAU2B,IAV1B,CACVC,cAAc,CAAdA,CAAc,CACdC,OAAO,CAAPA,CAAO,CACPC,SAAS,CAATA,CAAS,CACTC,WAAW,CAAXA,CAAW,CACXC,2BAA2B,CAA3BA,CAA2B,CAC3BC,sBAAsB,CAAtBA,CAAsB,CACtBC,WAAW,CAAXA,CAAW,CACXC,0BAA0B,CAA1BA,C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AC0D,cAAc,CAC3CxF,iBAAU,CAACoB,QAAQ,CACnBpB,iBAAU,CAACsB,OAAO,CAEhB2F,CAAgB,CAAG9F,CAAU,GAAK,IAAI,CAACA,UAAU,CAEnD8F,CAAgB,GAClB,IAAI,CAAC9F,UAAU,CAAGA,CAAU,CAC5B,KAAM,KAAI,CAACZ,UAAU,CAAC,CAAC,EAMzB,KAAM,CAAA2G,CAAe,CACnB,IAAI,CAAChD,iBAAiB,EAAI,CAAC,IAAI,CAACI,0BAA0B,CAG5D,MAFA,KAAI,CAAChE,kBAAkB,CAAC4G,eAAe,CAAGA,CAAe,CAElD,GAAAjG,SAAE,EAACgG,CAAgB,CAC5B,CAEQD,iBAAiBA,CAAA,CAAiC,CACxD,IAAI,CAAC5G,UAAU,CAAG,GAAI,CAAAC,IAAM,MAEtB,CAAA2B,CAAiB,CAAAoE,aAAA,CAAAA,aAAA,IAClB,IAAI,CAACpE,iBAAiB,MACzBD,YAAY,CAAEoF,KAAK,CAACC,IAAI,CAAC,IAAI,CAACrF,YAAY,CAAC2B,MAAM,CAAC,CAAC,CAAC,EACrD,CAEK1C,CAAoB,CAAG,CAC3BA,IAAI,CAAEgB,CAAiB,CACvB5B,UAAU,CAAE,IAAI,CAACA,UAAU,CAACkG,QAAQ,CAAC,CACvC,CAAC,CAMD,MAJA,CAAAL,wBAAW,CAACC,gBAAgB,CAC1B,IAAI,CAAClE,iBAAiB,CAACF,aAAa,CAACqE,aACvC,CAAC,CAEM,IAAI,CAAC5G,OAAO,CAAC8G,KAAK,CAACrF,CAAI,CAChC,CACF,CAACqG,OAAA,CAAAlI,mBAAA,CAAAA,mBAAA"}
|
|
1
|
+
{"version":3,"file":"clientConfiguration.js","names":["ClientConfiguration","constructor","a","updateInterval","storage","requester","dataManager","externalClientConfiguration","offlineTrackingStorage","eventSource","externalVisitorCodeManager","eventManager","_defineProperty","UpdateType","Idle","DEFAULT_CONFIGURATION_DATA","Map","lastUpdate","Date","visitorCodeManager","initialize","readStorageData","isExternalConfiguration","shouldUpdate","checkShouldUpdate","updateResult","updateClientConfiguration","ok","isUpdateTypeToggled","data","Ok","handleExternalUpdates","updateType","RealTime","isOpen","Polling","handlePollingUpdates","handleRealTimeUpdates","cleanupHandlers","close","updateConfigurationIntervalId","clearInterval","customData","configuration","featureFlags","configurationData","featureFlag","featureFlagsData","set","featureKey","updateEventCallback","timestamp","then","fireEvent","EventType","ConfigurationUpdate","open","setInterval","bind","err","segments","segmentsData","forEach","flag","rules","rule","segment","has","id","ruleMap","mappedRules","values","experimentId","variationByExposition","variationMap","variationKey","variationId","featureId","variations","isConsentRequired","consentType","ConsentType","Required","hasAnyTargetedDeliveryRule","isTargetedDeliveryRule","environmentEnabled","some","type","RuleType","TARGETED_DELIVERY","checkIntegrity","fields","Object","keys","length","requiredFields","DEFAULT_CLIENT_CONFIGURATION","sort","join","skipChecks","arguments","realTimeUpdate","size","lastUpdateTime","getTime","updateWindowEdge","now","result","read","isStorageValid","UrlProvider","setDataApiDomain","dataApiDomain","_objectSpread","write","toString","customDataIndexes","parse","b","clientConfigurationResult","getClientConfiguration","Utilities","sendOfflineTracking","clearTrees","clear","updateStorageData","toggleUpdateType","consentRequired","Array","from","exports"],"sources":["../../src/clientConfiguration/clientConfiguration.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError/kameleoonError';\nimport { DataManager } from 'src/kameleoonData';\nimport { Requester } from 'src/requester';\nimport { SegmentType } from 'src/targeting';\nimport { ClientDataType } from 'src/storage';\nimport { IEventSource } from 'src/eventSource';\nimport {\n DEFAULT_CLIENT_CONFIGURATION,\n DEFAULT_CONFIGURATION_DATA,\n} from './constants';\nimport {\n ClientConfigurationDataType,\n ClientConfigurationParametersType,\n ConfigurationDataType,\n ConfigurationType,\n ConsentType,\n FeatureFlagType,\n MappedRuleType,\n RuleType,\n UpdateType,\n} from './types';\nimport { Utilities } from 'src/utilities';\nimport { IStorage, OfflineTracking } from 'src/storage/types';\nimport { IVisitorCodeManager } from 'src/visitorCodeManager';\nimport { EventManager, EventType } from 'src/eventManager';\nimport { UrlProvider } from 'src/requester/urlProvider';\n\ninterface IClientConfiguration {\n initialize: (useCache?: boolean) => Promise<Result<void, KameleoonError>>;\n readonly featureFlags: Map<string, FeatureFlagType>;\n readonly configuration: ConfigurationType;\n readonly segments: Map<string, SegmentType>;\n readonly ruleMap: Map<number, MappedRuleType>;\n}\n\nexport class ClientConfiguration implements IClientConfiguration {\n private updateConfigurationIntervalId: NodeJS.Timeout | null = null;\n private updateType: UpdateType = UpdateType.Idle;\n private configurationData: ClientConfigurationDataType =\n DEFAULT_CONFIGURATION_DATA;\n private featureFlagsData: Map<string, FeatureFlagType> = new Map();\n private isTargetedDeliveryRule: boolean | null = null;\n private segmentsData: Map<string, SegmentType> | null = null;\n private updateInterval: number;\n private lastUpdate: Date;\n private storage: IStorage<ClientDataType>;\n private offlineTrackingStorage: IStorage<OfflineTracking>;\n private requester: Requester;\n private eventSource: IEventSource;\n private externalClientConfiguration?: ConfigurationDataType;\n private mappedRules: Map<number, MappedRuleType> | null = null;\n private dataManager: DataManager;\n private visitorCodeManager: IVisitorCodeManager;\n private eventManager: EventManager;\n\n constructor({\n updateInterval,\n storage,\n requester,\n dataManager,\n externalClientConfiguration,\n offlineTrackingStorage,\n eventSource,\n externalVisitorCodeManager,\n eventManager,\n }: ClientConfigurationParametersType) {\n this.requester = requester;\n this.updateInterval = updateInterval;\n this.lastUpdate = new Date();\n this.storage = storage;\n this.dataManager = dataManager;\n this.eventManager = eventManager;\n this.externalClientConfiguration = externalClientConfiguration;\n this.offlineTrackingStorage = offlineTrackingStorage;\n this.visitorCodeManager = externalVisitorCodeManager;\n this.eventSource = eventSource;\n }\n\n public async initialize(): Promise<Result<void, KameleoonError>> {\n this.readStorageData();\n\n const isExternalConfiguration = Boolean(this.externalClientConfiguration);\n const shouldUpdate = this.checkShouldUpdate(isExternalConfiguration);\n\n if (shouldUpdate) {\n const updateResult = await this.updateClientConfiguration();\n\n if (!updateResult.ok) {\n return updateResult;\n }\n\n // --- Note ---\n // If update type is being toggled `initialize` will be called again\n // so we don't need to continue execution here\n const isUpdateTypeToggled = updateResult.data;\n\n if (isUpdateTypeToggled) {\n return Ok();\n }\n }\n\n if (isExternalConfiguration) {\n this.handleExternalUpdates();\n\n return Ok();\n }\n\n if (this.updateType === UpdateType.RealTime && !this.eventSource.isOpen) {\n this.updateType = UpdateType.Idle;\n this.handleRealTimeUpdates();\n\n return Ok();\n }\n\n if (this.updateType === UpdateType.Polling) {\n this.handlePollingUpdates();\n }\n\n return Ok();\n }\n\n private cleanupHandlers(): void {\n if (this.eventSource.isOpen) {\n this.eventSource.close();\n }\n\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n }\n\n private handleExternalUpdates(): void {\n this.cleanupHandlers();\n\n const { customData, configuration, featureFlags } =\n this.externalClientConfiguration!;\n this.configurationData = { customData, configuration };\n\n for (const featureFlag of featureFlags) {\n this.featureFlagsData.set(featureFlag.featureKey, featureFlag);\n }\n }\n\n private handleRealTimeUpdates(): void {\n this.cleanupHandlers();\n\n const updateEventCallback = (timestamp: number) => {\n this.updateClientConfiguration(timestamp).then((updateResult) => {\n if (updateResult.ok) {\n this.eventManager.fireEvent(EventType.ConfigurationUpdate, {\n timestamp,\n });\n }\n });\n };\n\n this.eventSource.open(updateEventCallback);\n }\n\n private handlePollingUpdates(): void {\n // --- Note ---\n // If `initialize` is called again the interval will be cleared\n // so theoretically we will constantly defer config update\n // but `this.lastUpdate` with `checkShouldUpdate` will prevent that\n this.cleanupHandlers();\n\n // --- Note ---\n // Error Handling is for `setInterval` emergency cleanup\n try {\n this.updateConfigurationIntervalId = setInterval(\n this.updateClientConfiguration.bind(this),\n this.updateInterval,\n );\n } catch (err) {\n if (this.updateConfigurationIntervalId) {\n clearInterval(this.updateConfigurationIntervalId);\n }\n\n throw err;\n }\n }\n\n get featureFlags(): Map<string, FeatureFlagType> {\n return this.featureFlagsData;\n }\n\n get configuration(): ConfigurationType {\n return this.configurationData.configuration;\n }\n\n get segments(): Map<string, SegmentType> {\n if (this.segmentsData) {\n return this.segmentsData;\n }\n\n const segmentsData = new Map<string, SegmentType>();\n\n this.featureFlagsData.forEach((flag) => {\n flag.rules.forEach((rule) => {\n if (rule.segment && !segmentsData.has(rule.segment.id)) {\n segmentsData.set(rule.segment.id, rule.segment);\n }\n });\n });\n\n this.segmentsData = segmentsData;\n\n return segmentsData;\n }\n\n get ruleMap(): Map<number, MappedRuleType> {\n if (this.mappedRules) {\n return this.mappedRules;\n }\n\n const mappedRules = new Map<number, MappedRuleType>();\n\n for (const featureFlag of this.featureFlags.values()) {\n for (const rule of featureFlag.rules) {\n const { id, experimentId, variationByExposition } = rule;\n const variationMap = new Map<string, number>();\n\n variationByExposition.forEach(({ variationKey, variationId }) => {\n if (typeof variationId === 'number') {\n variationMap.set(variationKey, variationId);\n }\n });\n\n mappedRules.set(id, {\n featureId: featureFlag.id,\n experimentId,\n variations: variationMap,\n });\n }\n }\n\n this.mappedRules = mappedRules;\n\n return mappedRules;\n }\n\n get isConsentRequired(): boolean {\n return this.configuration.consentType === ConsentType.Required;\n }\n\n get hasAnyTargetedDeliveryRule(): boolean {\n if (this.isTargetedDeliveryRule !== null) {\n return this.isTargetedDeliveryRule;\n }\n\n for (const featureFlag of this.featureFlags.values()) {\n if (\n featureFlag.environmentEnabled &&\n featureFlag.rules.some(\n (rule) => rule.type === RuleType.TARGETED_DELIVERY,\n )\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n // --- Note ---\n // Integrity check covers most of the migration scenarios\n // however in the future it will be changed to a dedicate migration\n // block that can handle all versions migrations\n private checkIntegrity(data: ConfigurationDataType | undefined): boolean {\n if (!data) {\n return false;\n }\n\n const fields = Object.keys(data);\n\n if (!fields.length) {\n return false;\n }\n\n const requiredFields = Object.keys(DEFAULT_CLIENT_CONFIGURATION);\n\n return fields.sort().join() === requiredFields.sort().join();\n }\n\n private checkShouldUpdate(skipChecks = false): boolean {\n const { configuration } = this.configurationData;\n\n // --- Note ---\n // Following `updateType` logic is done for client side\n // edge cases where we have previous campaigns on storage already, but we still want\n // to initialize SSE/Polling after page reload\n if (skipChecks) {\n this.updateType = UpdateType.Idle;\n\n return false;\n }\n\n this.updateType = configuration.realTimeUpdate\n ? UpdateType.RealTime\n : UpdateType.Polling;\n\n if (!this.featureFlags.size) {\n return true;\n }\n\n const lastUpdateTime = this.lastUpdate.getTime();\n const updateWindowEdge = Date.now() - this.updateInterval;\n\n return lastUpdateTime < updateWindowEdge;\n }\n\n private readStorageData(): void {\n const result = this.storage.read();\n\n if (result.ok) {\n const { data, lastUpdate } = result.data;\n\n const isStorageValid = this.checkIntegrity(data);\n\n // --- Note ---\n // Cleaning up storage if it's not valid for migration purposes\n if (!isStorageValid) {\n UrlProvider.setDataApiDomain(\n DEFAULT_CONFIGURATION_DATA.configuration.dataApiDomain,\n );\n\n const data = {\n ...DEFAULT_CONFIGURATION_DATA,\n featureFlags: [],\n };\n\n this.storage.write({\n data,\n lastUpdate: this.lastUpdate.toString(),\n });\n\n this.configurationData = DEFAULT_CONFIGURATION_DATA;\n } else {\n UrlProvider.setDataApiDomain(data.configuration.dataApiDomain);\n\n const { featureFlags, customData } = data;\n\n if (customData?.length) {\n this.dataManager.customDataIndexes = customData;\n }\n\n for (const featureFlag of featureFlags) {\n this.featureFlagsData.set(featureFlag.featureKey, featureFlag);\n }\n\n this.configurationData = data;\n this.lastUpdate = new Date(Date.parse(lastUpdate));\n }\n }\n }\n\n /**\n * Updates client configuration\n *\n * @param timeStamp - timestamp for real-time configuration update\n *\n * @returns `true` if current update type should be toggled (SSE/Polling)\n */\n private async updateClientConfiguration(\n timestamp?: number,\n ): Promise<Result<boolean, KameleoonError>> {\n const clientConfigurationResult =\n await this.requester.getClientConfiguration(timestamp);\n\n if (!clientConfigurationResult.ok) {\n if (this.featureFlags.size) {\n // TODO: the case of silent fail should be logged when logging is implemented\n return Ok(true);\n }\n\n return clientConfigurationResult;\n }\n\n Utilities.sendOfflineTracking({\n storage: this.offlineTrackingStorage,\n requester: this.requester,\n });\n\n const { configuration, customData, featureFlags } =\n clientConfigurationResult.data;\n\n this.configurationData = { configuration, customData };\n\n for (const featureFlag of featureFlags) {\n this.featureFlagsData.set(featureFlag.featureKey, featureFlag);\n }\n\n if (customData?.length) {\n this.dataManager.customDataIndexes = customData;\n }\n\n this.dataManager.clearTrees();\n this.mappedRules?.clear();\n this.isTargetedDeliveryRule = null;\n this.segmentsData = null;\n\n const result = this.updateStorageData();\n\n if (!result.ok) {\n return result;\n }\n\n const updateType = configuration.realTimeUpdate\n ? UpdateType.RealTime\n : UpdateType.Polling;\n\n const toggleUpdateType = updateType !== this.updateType;\n\n if (toggleUpdateType) {\n this.updateType = updateType;\n await this.initialize();\n }\n\n // --- Note ---\n // Regarding GDPR policy we should set visitorCode if legal consent isn't required\n // or we have at least one Targeted Delivery rule in configuration\n const consentRequired =\n this.isConsentRequired && !this.hasAnyTargetedDeliveryRule;\n this.visitorCodeManager.consentRequired = consentRequired;\n\n return Ok(toggleUpdateType);\n }\n\n private updateStorageData(): Result<void, KameleoonError> {\n this.lastUpdate = new Date();\n\n const configurationData = {\n ...this.configurationData,\n featureFlags: Array.from(this.featureFlags.values()),\n };\n\n const data: ClientDataType = {\n data: configurationData,\n lastUpdate: this.lastUpdate.toString(),\n };\n\n UrlProvider.setDataApiDomain(\n this.configurationData.configuration.dataApiDomain,\n );\n\n return this.storage.write(data);\n }\n}\n"],"mappings":"k6CAoCO,KAAM,CAAAA,mBAAoD,CAoB/DC,WAAWA,CAAAC,CAAA,CAU2B,IAV1B,CACVC,cAAc,CAAdA,CAAc,CACdC,OAAO,CAAPA,CAAO,CACPC,SAAS,CAATA,CAAS,CACTC,WAAW,CAAXA,CAAW,CACXC,2BAA2B,CAA3BA,CAA2B,CAC3BC,sBAAsB,CAAtBA,CAAsB,CACtBC,WAAW,CAAXA,CAAW,CACXC,0BAA0B,CAA1BA,CAA0B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),exports.DataManager=void 0;var _tsRes=require("ts-res"),_targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_utilities=require("../utilities"),_clientConfiguration=require("../clientConfiguration"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{storage:b,cleanupInterval:c}=a;if(_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"cleanupIntervalId",null),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"unsentData",void 0),_defineProperty(this,"sentPageViewTimestamps",new Map),this.dataProcessor=new _dataProcessor.DataProcessor(b),this.unsentData={},c){const a=()=>{this.dataProcessor.cleanupTargetingData(c),this.sentPageViewTimestamps.clear()};try{this.cleanupIntervalId=setInterval(a,c)}catch(a){throw this.cleanupIntervalId&&clearInterval(this.cleanupIntervalId),a}}}addData(a){this.unsentData[a]||(this.unsentData[a]=new Map);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];for(const b of c)switch(this.dataProcessor.updateData(a,b),b.data.type){case _types.KameleoonData.CustomData:{const c=b,d=c.data;this.mappingIdentifierCustomDataIndex===d.index&&(c._isMappingIdentifier=!0,a!==d.value[0]&&this.dataProcessor.createReference(a,d.value[0])),this.localCustomDataIndexes.has(d.index)||b.isSent||this.unsentData[a].set(d.index,c);break}case _types.KameleoonData.PageView:{const c=b.data,d=this.dataProcessor.getTargetingData(a).or({});if(d){const e=d[_types.KameleoonData.PageView],f=e[c.urlAddress];if(!b.isSent)for(const c of f.timestamps)this.sentPageViewTimestamps.has(c)||(this.unsentData[a].set(c,b),this.sentPageViewTimestamps.set(c,!0));else for(const a of f.timestamps)this.sentPageViewTimestamps.has(a)||this.sentPageViewTimestamps.set(a,!0)}break}case _types.KameleoonData.Conversion:{const c=this.unsentData[a];if(!b.isSent)if(c.has(_types.KameleoonData.Conversion)){const a=c.get(_types.KameleoonData.Conversion);a.push(b),c.set(_types.KameleoonData.Conversion,a)}else c.set(_types.KameleoonData.Conversion,[b]);break}default:{const{data:c}=b;b.isSent||this.unsentData[a].set(c.type,b)}}return(0,_tsRes.Ok)()}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()}getUnsentData(a){return this.unsentData[a]}clearUnsentData(a){var b;const c=null===(b=this.unsentData[a])||void 0===b?void 0:b.values();if(c&&this.persistentCustomDataIndexes.size){const b=new Map;for(const a of c)!Array.isArray(a)&&this.isPersistentCustomData(a)&&b.set(a.data.index,a);if(b.size)return void(this.unsentData[a]=b)}delete this.unsentData[a]}clearUnsentDataByKey(a,b){const c=this.unsentData[a];if(c){if(b===_types.KameleoonData.CustomData&&this.persistentCustomDataIndexes.size)for(const[a,d]of c.entries())this.isPersistentCustomData(d)||a===b&&c.delete(a);else if(b===_types.KameleoonData.PageView)for(const a of c.keys())"number"==typeof a&&c.delete(a);else c.delete(b);c.size||delete this.unsentData[a]}}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}getLinkedVisitor(a){return this.dataProcessor.getLinkedVisitor(a,this.mappingIdentifierCustomDataIndex)}getVisitorIdentifier(a){const b=this.getTargetingData(a);if(!b)return a;const c=b[_types.KameleoonData.CustomData];if(!c||null===this.mappingIdentifierCustomDataIndex)return a;const d=c[this.mappingIdentifierCustomDataIndex];return d?d.value[0]:a}getTargetingData(a){const b=this.dataProcessor.getTargetingData(a).or(null);return b?b:void 0}get trees(){return this.targetingTrees}get unsentDataVisitors(){return Object.keys(this.unsentData)}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get storedDataTypes(){return this.dataProcessor.storedDataTypeList}get storedCustomDataIndexes(){return this.dataProcessor.storedCustomDataIndexList}set customDataIndexes(a){const[b,c]=[[],[]];a.forEach(a=>{a.localOnly&&b.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&c.push(a.index),a.isMappingIdentifier&&(this.mappingIdentifierCustomDataIndex=a.index)}),b.length&&(this.localCustomDataIndexes=new Set(b)),c.length&&(this.persistentCustomDataIndexes=new Set(c))}}exports.DataManager=DataManager;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DataManager=void 0;var _tsRes=require("ts-res"),_targeting=require("../targeting"),_dataProcessor=require("./dataProcessor"),_utilities=require("../utilities"),_clientConfiguration=require("../clientConfiguration"),_customData=require("./customData"),_types=require("./types");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class DataManager{constructor(a){let{storage:b,cleanupInterval:c}=a;if(_defineProperty(this,"targetingTrees",new Map),_defineProperty(this,"localCustomDataIndexes",new Set),_defineProperty(this,"persistentCustomDataIndexes",new Set),_defineProperty(this,"mappingIdentifierCustomDataIndex",null),_defineProperty(this,"cleanupIntervalId",null),_defineProperty(this,"dataProcessor",void 0),_defineProperty(this,"unsentData",void 0),_defineProperty(this,"sentPageViewTimestamps",new Map),this.dataProcessor=new _dataProcessor.DataProcessor(b),this.unsentData={},c){const a=()=>{this.dataProcessor.cleanupTargetingData(c),this.sentPageViewTimestamps.clear()};try{this.cleanupIntervalId=setInterval(a,c)}catch(a){throw this.cleanupIntervalId&&clearInterval(this.cleanupIntervalId),a}}}addData(a){this.unsentData[a]||(this.unsentData[a]=new Map);for(var b=arguments.length,c=Array(1<b?b-1:0),d=1;d<b;d++)c[d-1]=arguments[d];for(const b of c)switch(this.dataProcessor.updateData(a,b),b.data.type){case _types.KameleoonData.CustomData:{const c=b,d=c.data;this.mappingIdentifierCustomDataIndex===d.index&&(c._isMappingIdentifier=!0,a!==d.value[0]&&this.dataProcessor.createReference(a,d.value[0])),this.localCustomDataIndexes.has(d.index)||b.isSent||this.unsentData[a].set(d.index,c);break}case _types.KameleoonData.PageView:{const c=b.data,d=this.dataProcessor.getTargetingData(a).or({});if(d){const e=d[_types.KameleoonData.PageView],f=e[c.urlAddress];if(!b.isSent)for(const c of f.timestamps)this.sentPageViewTimestamps.has(c)||(this.unsentData[a].set(c,b),this.sentPageViewTimestamps.set(c,!0));else for(const a of f.timestamps)this.sentPageViewTimestamps.has(a)||this.sentPageViewTimestamps.set(a,!0)}break}case _types.KameleoonData.Conversion:{const c=this.unsentData[a];if(!b.isSent)if(c.has(_types.KameleoonData.Conversion)){const a=c.get(_types.KameleoonData.Conversion);a.push(b),c.set(_types.KameleoonData.Conversion,a)}else c.set(_types.KameleoonData.Conversion,[b]);break}default:{const{data:c}=b;b.isSent||this.unsentData[a].set(c.type,b)}}return(0,_tsRes.Ok)()}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()}getUnsentData(a){if(null!==this.mappingIdentifierCustomDataIndex){const b=this.getTargetingData(a);if(b){const c=b[_types.KameleoonData.CustomData];if(c){const b=c[this.mappingIdentifierCustomDataIndex];if(b){const{index:c,value:d}=b,e=new _customData.CustomData(c,...d);e._isMappingIdentifier=!0,this.unsentData[a]||(this.unsentData[a]=new Map),this.unsentData[a].set(c,e)}}}}return this.unsentData[a]}clearUnsentData(a){var b;const c=null===(b=this.unsentData[a])||void 0===b?void 0:b.values();if(c&&this.persistentCustomDataIndexes.size){const b=new Map;for(const a of c)!Array.isArray(a)&&this.isPersistentCustomData(a)&&b.set(a.data.index,a);if(b.size)return void(this.unsentData[a]=b)}delete this.unsentData[a]}clearUnsentDataByKey(a,b){const c=this.unsentData[a];if(c){if(b===_types.KameleoonData.CustomData&&this.persistentCustomDataIndexes.size)for(const[a,d]of c.entries())this.isPersistentCustomData(d)||a===b&&c.delete(a);else if(b===_types.KameleoonData.PageView)for(const a of c.keys())"number"==typeof a&&c.delete(a);else c.delete(b);c.size||delete this.unsentData[a]}}isPersistentCustomData(a){return!!this.persistentCustomDataIndexes.size&&!!_utilities.Utilities.isCustomData(a)&&this.persistentCustomDataIndexes.has(a.data.index)}getLinkedVisitor(a){return this.dataProcessor.getLinkedVisitor(a,this.mappingIdentifierCustomDataIndex)}getVisitorIdentifier(a){const b=this.getTargetingData(a);if(!b)return a;const c=b[_types.KameleoonData.CustomData];if(!c||null===this.mappingIdentifierCustomDataIndex)return a;const d=c[this.mappingIdentifierCustomDataIndex];return d?d.value[0]:a}getTargetingData(a){const b=this.dataProcessor.getTargetingData(a).or(null);return b?b:void 0}get trees(){return this.targetingTrees}get unsentDataVisitors(){return Object.keys(this.unsentData)}get identifierCustomDataIndex(){return this.mappingIdentifierCustomDataIndex}get storedDataTypes(){return this.dataProcessor.storedDataTypeList}get storedCustomDataIndexes(){return this.dataProcessor.storedCustomDataIndexList}set customDataIndexes(a){const[b,c]=[[],[]];a.forEach(a=>{a.localOnly&&b.push(a.index),a.scope===_clientConfiguration.CustomDataScope.Visitor&&c.push(a.index),a.isMappingIdentifier&&(this.mappingIdentifierCustomDataIndex=a.index)}),b.length&&(this.localCustomDataIndexes=new Set(b)),c.length&&(this.persistentCustomDataIndexes=new Set(c))}}exports.DataManager=DataManager;
|
|
2
2
|
//# sourceMappingURL=dataManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataManager.js","names":["DataManager","constructor","a","storage","cleanupInterval","_defineProperty","Map","Set","dataProcessor","DataProcessor","unsentData","cleanupCallback","cleanupTargetingData","sentPageViewTimestamps","clear","cleanupIntervalId","setInterval","err","clearInterval","addData","visitorCode","b","arguments","length","kameleoonData","Array","d","dataItem","updateData","data","type","KameleoonData","CustomData","customData","mappingIdentifierCustomDataIndex","index","_isMappingIdentifier","value","createReference","localCustomDataIndexes","has","isSent","set","PageView","storedData","getTargetingData","or","storedVisitorData","pageView","urlAddress","timestamp","timestamps","Conversion","existingConversions","get","push","Ok","getTree","segment","targetingTrees","id","targetingTree","Tree","clearTrees","getUnsentData","clearUnsentData","dataItems","values","persistentCustomDataIndexes","size","persistentCustomData","isArray","isPersistentCustomData","clearUnsentDataByKey","key","visitorData","dataKey","entries","delete","keys","Utilities","isCustomData","getLinkedVisitor","getVisitorIdentifier","targetingData","customDataValue","trees","unsentDataVisitors","Object","identifierCustomDataIndex","storedDataTypes","storedDataTypeList","storedCustomDataIndexes","storedCustomDataIndexList","customDataIndexes","customDataLocalOnlyIndexes","forEach","localOnly","scope","CustomDataScope","Visitor","isMappingIdentifier","exports"],"sources":["../../src/kameleoonData/dataManager.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { SegmentType, Tree } from 'src/targeting';\nimport { DataProcessor } from './dataProcessor';\nimport { Utilities } from 'src/utilities';\nimport {\n CustomDataConfigurationType,\n CustomDataScope,\n} from 'src/clientConfiguration';\nimport { CustomData } from './customData';\nimport {\n DataManagerParametersType,\n ExistingPageViewDataType,\n KameleoonData,\n KameleoonDataType,\n KameleoonVisitorDataType,\n PageViewDataType,\n UnsentTargetingDataType,\n UnsentVisitorTargetingDataType,\n} from './types';\n\ninterface IDataManager {\n addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): void;\n getUnsentData: (\n visitorCode: string,\n ) => UnsentTargetingDataType[string] | undefined;\n getTree(segment: SegmentType): Tree;\n clearTrees(): void;\n clearUnsentData: (visitorCode: string) => void;\n isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;\n getLinkedVisitor: (visitorCode: string) => string | null;\n getTargetingData: (\n visitorCode: string,\n ) => KameleoonVisitorDataType | undefined;\n readonly trees: Map<string, Tree>;\n readonly unsentDataVisitors: string[];\n readonly identifierCustomDataIndex: number | null;\n}\n\nexport class DataManager implements IDataManager {\n private targetingTrees: Map<string, Tree> = new Map();\n private localCustomDataIndexes: Set<number> = new Set();\n private persistentCustomDataIndexes: Set<number> = new Set();\n private mappingIdentifierCustomDataIndex: number | null = null;\n private cleanupIntervalId: NodeJS.Timeout | null = null;\n private dataProcessor: DataProcessor;\n private unsentData: UnsentTargetingDataType;\n private sentPageViewTimestamps: Map<number, boolean> = new Map();\n\n constructor({ storage, cleanupInterval }: DataManagerParametersType) {\n this.dataProcessor = new DataProcessor(storage);\n this.unsentData = {};\n\n if (cleanupInterval) {\n const cleanupCallback = () => {\n this.dataProcessor.cleanupTargetingData(cleanupInterval);\n this.sentPageViewTimestamps.clear();\n };\n\n // --- Note ---\n // We can not make delayed code execution recoverable, as it might lead\n // to targeting data storage size overflow\n try {\n this.cleanupIntervalId = setInterval(cleanupCallback, cleanupInterval);\n } catch (err) {\n if (this.cleanupIntervalId) {\n clearInterval(this.cleanupIntervalId);\n }\n\n throw err;\n }\n }\n }\n\n public addData(\n visitorCode: string,\n ...kameleoonData: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n // --- Note ---\n // We assume `this.unsentTargetingData[visitorCode]` is always presents further\n if (!this.unsentData[visitorCode]) {\n this.unsentData[visitorCode] = new Map();\n }\n\n for (const dataItem of kameleoonData) {\n // TODO: this can be optimized to be updated altogether\n // instead of updating each data item separately\n this.dataProcessor.updateData(visitorCode, dataItem);\n\n switch (dataItem.data.type) {\n case KameleoonData.CustomData: {\n const customData = dataItem as CustomData;\n const data = customData.data;\n\n // --- Bug ---\n // - There's a known issue here: `mappingIdentifier` won't be updated\n // in the storage because the data is written before `unsentData` update\n // and we get `mappingIdentifier` only by checking CC here\n // - It doesn't affect the functionality, as stored data is\n // only used for condition evaluation and `Visitor` scoped CD is never removed from `unsentData`\n // still it should be fixed with some `.updateData` refactor\n if (this.mappingIdentifierCustomDataIndex === data.index) {\n customData._isMappingIdentifier = true;\n\n if (visitorCode !== data.value[0]) {\n // --- Note ---\n // Associate linked visitor codes\n this.dataProcessor.createReference(visitorCode, data.value[0]);\n }\n }\n\n if (\n !this.localCustomDataIndexes.has(data.index) &&\n !dataItem.isSent\n ) {\n this.unsentData[visitorCode]!.set(data.index, customData);\n }\n\n break;\n }\n case KameleoonData.PageView: {\n const data = dataItem.data as PageViewDataType;\n\n // --- Note ---\n // `PageViews` can only be processed during storage update as they\n // can't create and merge referrers/titles/timestamps on their own\n // So we have to extract them from storage to update `unsentData` correctly\n const storedData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or({});\n\n if (storedData) {\n const storedVisitorData = storedData[KameleoonData.PageView];\n const pageView = (storedVisitorData as ExistingPageViewDataType)[\n data.urlAddress\n ];\n\n // --- Note ---\n // A case for newly created page view\n if (!dataItem.isSent) {\n for (const timestamp of pageView.timestamps) {\n // --- Note ---\n // As we don't keep `sent` status for each timestamp, we have to\n // check if it was already sent to avoid duplicates\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.unsentData[visitorCode]!.set(timestamp, dataItem);\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n // --- Note ---\n // A case for `getRemoteVisitorData` pre-loaded pages that shouldn't be sent again\n } else {\n for (const timestamp of pageView.timestamps) {\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n }\n }\n\n break;\n }\n case KameleoonData.Conversion: {\n const unsentData = this.unsentData[visitorCode]!;\n\n if (!dataItem.isSent) {\n if (unsentData.has(KameleoonData.Conversion)) {\n const existingConversions = unsentData.get(\n KameleoonData.Conversion,\n ) as KameleoonDataType[];\n\n existingConversions.push(dataItem);\n\n unsentData.set(KameleoonData.Conversion, existingConversions);\n } else {\n unsentData.set(KameleoonData.Conversion, [dataItem]);\n }\n }\n\n break;\n }\n default: {\n const { data } = dataItem;\n\n if (!dataItem.isSent) {\n this.unsentData[visitorCode]!.set(data.type, dataItem);\n }\n }\n }\n }\n\n return Ok();\n }\n\n public getTree(segment: SegmentType): Tree {\n if (this.targetingTrees.has(segment.id)) {\n return this.targetingTrees.get(segment.id)!;\n }\n\n const targetingTree = new Tree(segment);\n this.targetingTrees.set(segment.id, targetingTree);\n\n return targetingTree;\n }\n\n public clearTrees(): void {\n this.targetingTrees.clear();\n }\n\n public getUnsentData(\n visitorCode: string,\n ): UnsentTargetingDataType[string] | undefined {\n return this.unsentData[visitorCode];\n }\n\n public clearUnsentData(visitorCode: string): void {\n const dataItems = this.unsentData[visitorCode]?.values();\n\n if (dataItems && this.persistentCustomDataIndexes.size) {\n const persistentCustomData: UnsentVisitorTargetingDataType = new Map();\n\n for (const dataItem of dataItems) {\n if (!Array.isArray(dataItem) && this.isPersistentCustomData(dataItem)) {\n persistentCustomData.set(dataItem.data.index, dataItem);\n }\n }\n\n if (persistentCustomData.size) {\n this.unsentData[visitorCode] = persistentCustomData;\n return;\n }\n }\n\n delete this.unsentData[visitorCode];\n }\n\n public clearUnsentDataByKey(visitorCode: string, key: KameleoonData): void {\n const visitorData = this.unsentData[visitorCode];\n\n if (!visitorData) {\n return;\n }\n\n if (\n key === KameleoonData.CustomData &&\n this.persistentCustomDataIndexes.size\n ) {\n for (const [dataKey, dataItem] of visitorData.entries()) {\n if (this.isPersistentCustomData(dataItem as KameleoonDataType)) {\n continue;\n }\n\n if (dataKey === key) {\n visitorData.delete(dataKey);\n }\n }\n } else if (key === KameleoonData.PageView) {\n for (const dataKey of visitorData.keys()) {\n if (typeof dataKey === 'number') {\n visitorData.delete(dataKey);\n }\n }\n } else {\n visitorData.delete(key);\n }\n\n if (!visitorData.size) {\n delete this.unsentData[visitorCode];\n }\n }\n\n public isPersistentCustomData(\n dataItem: KameleoonDataType,\n ): dataItem is CustomData {\n if (!this.persistentCustomDataIndexes.size) {\n return false;\n }\n\n if (Utilities.isCustomData(dataItem)) {\n return this.persistentCustomDataIndexes.has(dataItem.data.index);\n }\n\n return false;\n }\n\n public getLinkedVisitor(visitorCode: string): string | null {\n return this.dataProcessor.getLinkedVisitor(\n visitorCode,\n this.mappingIdentifierCustomDataIndex,\n );\n }\n\n public getVisitorIdentifier(visitorCode: string): string {\n const targetingData = this.getTargetingData(visitorCode);\n\n if (!targetingData) {\n return visitorCode;\n }\n\n const customData = targetingData[KameleoonData.CustomData];\n\n if (!customData || this.mappingIdentifierCustomDataIndex === null) {\n return visitorCode;\n }\n\n const customDataValue = customData[this.mappingIdentifierCustomDataIndex];\n\n if (customDataValue) {\n return customDataValue.value[0];\n }\n\n return visitorCode;\n }\n\n public getTargetingData(\n visitorCode: string,\n ): KameleoonVisitorDataType | undefined {\n const targetingData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or(null);\n\n if (!targetingData) {\n return undefined;\n }\n\n return targetingData;\n }\n\n get trees(): Map<string, Tree> {\n return this.targetingTrees;\n }\n\n get unsentDataVisitors(): string[] {\n return Object.keys(this.unsentData);\n }\n\n get identifierCustomDataIndex(): number | null {\n return this.mappingIdentifierCustomDataIndex;\n }\n\n get storedDataTypes(): Set<KameleoonData> {\n return this.dataProcessor.storedDataTypeList;\n }\n\n get storedCustomDataIndexes(): Set<number> {\n return this.dataProcessor.storedCustomDataIndexList;\n }\n\n set customDataIndexes(customData: CustomDataConfigurationType[]) {\n const [customDataLocalOnlyIndexes, persistentCustomDataIndexes]: Array<\n number[]\n > = [[], []];\n\n customData.forEach((customData) => {\n if (customData.localOnly) {\n customDataLocalOnlyIndexes.push(customData.index);\n }\n\n if (customData.scope === CustomDataScope.Visitor) {\n persistentCustomDataIndexes.push(customData.index);\n }\n\n if (customData.isMappingIdentifier) {\n this.mappingIdentifierCustomDataIndex = customData.index;\n }\n });\n\n if (customDataLocalOnlyIndexes.length) {\n this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);\n }\n\n if (persistentCustomDataIndexes.length) {\n this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);\n }\n }\n}\n"],"mappings":"g0BAuCO,KAAM,CAAAA,WAAoC,CAU/CC,WAAWA,CAAAC,CAAA,CAA0D,IAAzD,CAAEC,OAAO,CAAPA,CAAO,CAAEC,eAAe,CAAfA,CAA2C,CAAC,CAAAF,CAAA,CAIjE,GAAAG,eAAA,uBAb0C,GAAI,CAAAC,GAAK,EAAAD,eAAA,+BACP,GAAI,CAAAE,GAAK,EAAAF,eAAA,oCACJ,GAAI,CAAAE,GAAK,EAAAF,eAAA,yCACF,IAAI,EAAAA,eAAA,0BACX,IAAI,EAAAA,eAAA,8BAAAA,eAAA,2BAAAA,eAAA,+BAGA,GAAI,CAAAC,GAAK,EAG9D,IAAI,CAACE,aAAa,CAAG,GAAI,CAAAC,4BAAa,CAACN,CAAO,CAAC,CAC/C,IAAI,CAACO,UAAU,CAAG,CAAC,CAAC,CAEhBN,CAAe,CAAE,CACnB,KAAM,CAAAO,CAAe,CAAGA,CAAA,GAAM,CAC5B,IAAI,CAACH,aAAa,CAACI,oBAAoB,CAACR,CAAe,CAAC,CACxD,IAAI,CAACS,sBAAsB,CAACC,KAAK,CAAC,CACpC,CAAC,CAKD,GAAI,CACF,IAAI,CAACC,iBAAiB,CAAGC,WAAW,CAACL,CAAe,CAAEP,CAAe,CACvE,CAAE,MAAOa,CAAG,CAAE,CAKZ,KAJI,KAAI,CAACF,iBAAiB,EACxBG,aAAa,CAAC,IAAI,CAACH,iBAAiB,CAAC,CAGjCE,CACR,CACF,CACF,CAEOE,OAAOA,CACZC,CAAmB,CAEW,CAG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AACmF,kBAC5B,CAEA,GAAI,CAAAC,uBAAuBA,CAAA,CAAgB,CACzC,MAAO,KAAI,CAACpF,aAAa,CAACqF,yBAC5B,CAEA,GAAI,CAAAC,iBAAiBA,CAAC7D,CAAyC,CAAE,CAC/D,KAAM,CAAC8D,CAA0B,CAAE3B,CAA2B,CAE7D,CAAG,CAAC,EAAE,CAAE,EAAE,CAAC,CAEZnC,CAAU,CAAC+D,OAAO,CAAE/D,CAAU,EAAK,CAC7BA,CAAU,CAACgE,SAAS,EACtBF,CAA0B,CAACxC,IAAI,CAACtB,CAAU,CAACE,KAAK,CAAC,CAG/CF,CAAU,CAACiE,KAAK,GAAKC,oCAAe,CAACC,OAAO,EAC9ChC,CAA2B,CAACb,IAAI,CAACtB,CAAU,CAACE,KAAK,CAAC,CAGhDF,CAAU,CAACoE,mBAAmB,GAChC,IAAI,CAACnE,gCAAgC,CAAGD,CAAU,CAACE,KAAK,CAE5D,CAAC,CAAC,CAEE4D,CAA0B,CAACxE,MAAM,GACnC,IAAI,CAACgB,sBAAsB,CAAG,GAAI,CAAAhC,GAAG,CAACwF,CAA0B,CAAC,EAG/D3B,CAA2B,CAAC7C,MAAM,GACpC,IAAI,CAAC6C,2BAA2B,CAAG,GAAI,CAAA7D,GAAG,CAAC6D,CAA2B,CAAC,CAE3E,CACF,CAACkC,OAAA,CAAAtG,WAAA,CAAAA,WAAA"}
|
|
1
|
+
{"version":3,"file":"dataManager.js","names":["DataManager","constructor","a","storage","cleanupInterval","_defineProperty","Map","Set","dataProcessor","DataProcessor","unsentData","cleanupCallback","cleanupTargetingData","sentPageViewTimestamps","clear","cleanupIntervalId","setInterval","err","clearInterval","addData","visitorCode","b","arguments","length","kameleoonData","Array","d","dataItem","updateData","data","type","KameleoonData","CustomData","customData","mappingIdentifierCustomDataIndex","index","_isMappingIdentifier","value","createReference","localCustomDataIndexes","has","isSent","set","PageView","storedData","getTargetingData","or","storedVisitorData","pageView","urlAddress","timestamp","timestamps","Conversion","existingConversions","get","push","Ok","getTree","segment","targetingTrees","id","targetingTree","Tree","clearTrees","getUnsentData","targetingData","customDataValue","mappingCD","clearUnsentData","dataItems","values","persistentCustomDataIndexes","size","persistentCustomData","isArray","isPersistentCustomData","clearUnsentDataByKey","key","visitorData","dataKey","entries","delete","keys","Utilities","isCustomData","getLinkedVisitor","getVisitorIdentifier","trees","unsentDataVisitors","Object","identifierCustomDataIndex","storedDataTypes","storedDataTypeList","storedCustomDataIndexes","storedCustomDataIndexList","customDataIndexes","customDataLocalOnlyIndexes","forEach","localOnly","scope","CustomDataScope","Visitor","isMappingIdentifier","exports"],"sources":["../../src/kameleoonData/dataManager.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { SegmentType, Tree } from 'src/targeting';\nimport { DataProcessor } from './dataProcessor';\nimport { Utilities } from 'src/utilities';\nimport {\n CustomDataConfigurationType,\n CustomDataScope,\n} from 'src/clientConfiguration';\nimport { CustomData } from './customData';\nimport {\n DataManagerParametersType,\n ExistingPageViewDataType,\n KameleoonData,\n KameleoonDataType,\n KameleoonVisitorDataType,\n PageViewDataType,\n UnsentTargetingDataType,\n UnsentVisitorTargetingDataType,\n} from './types';\n\ninterface IDataManager {\n addData(visitorCode: string, ...kameleoonData: KameleoonDataType[]): void;\n getUnsentData: (\n visitorCode: string,\n ) => UnsentTargetingDataType[string] | undefined;\n getTree(segment: SegmentType): Tree;\n clearTrees(): void;\n clearUnsentData: (visitorCode: string) => void;\n isPersistentCustomData: (dataItem: KameleoonDataType) => boolean;\n getLinkedVisitor: (visitorCode: string) => string | null;\n getTargetingData: (\n visitorCode: string,\n ) => KameleoonVisitorDataType | undefined;\n readonly trees: Map<string, Tree>;\n readonly unsentDataVisitors: string[];\n readonly identifierCustomDataIndex: number | null;\n}\n\nexport class DataManager implements IDataManager {\n private targetingTrees: Map<string, Tree> = new Map();\n private localCustomDataIndexes: Set<number> = new Set();\n private persistentCustomDataIndexes: Set<number> = new Set();\n private mappingIdentifierCustomDataIndex: number | null = null;\n private cleanupIntervalId: NodeJS.Timeout | null = null;\n private dataProcessor: DataProcessor;\n private unsentData: UnsentTargetingDataType;\n private sentPageViewTimestamps: Map<number, boolean> = new Map();\n\n constructor({ storage, cleanupInterval }: DataManagerParametersType) {\n this.dataProcessor = new DataProcessor(storage);\n this.unsentData = {};\n\n if (cleanupInterval) {\n const cleanupCallback = () => {\n this.dataProcessor.cleanupTargetingData(cleanupInterval);\n this.sentPageViewTimestamps.clear();\n };\n\n // --- Note ---\n // We can not make delayed code execution recoverable, as it might lead\n // to targeting data storage size overflow\n try {\n this.cleanupIntervalId = setInterval(cleanupCallback, cleanupInterval);\n } catch (err) {\n if (this.cleanupIntervalId) {\n clearInterval(this.cleanupIntervalId);\n }\n\n throw err;\n }\n }\n }\n\n public addData(\n visitorCode: string,\n ...kameleoonData: KameleoonDataType[]\n ): Result<void, KameleoonError> {\n // --- Note ---\n // We assume `this.unsentTargetingData[visitorCode]` is always presents further\n if (!this.unsentData[visitorCode]) {\n this.unsentData[visitorCode] = new Map();\n }\n\n for (const dataItem of kameleoonData) {\n // TODO: this can be optimized to be updated altogether\n // instead of updating each data item separately\n this.dataProcessor.updateData(visitorCode, dataItem);\n\n switch (dataItem.data.type) {\n case KameleoonData.CustomData: {\n const customData = dataItem as CustomData;\n const data = customData.data;\n\n // --- Bug ---\n // - There's a known issue here: `mappingIdentifier` won't be updated\n // in the storage because the data is written before `unsentData` update\n // and we get `mappingIdentifier` only by checking CC here\n // - It doesn't affect the functionality, as stored data is\n // only used for condition evaluation and `Visitor` scoped CD is never removed from `unsentData`\n // still it should be fixed with some `.updateData` refactor\n if (this.mappingIdentifierCustomDataIndex === data.index) {\n customData._isMappingIdentifier = true;\n\n if (visitorCode !== data.value[0]) {\n // --- Note ---\n // Associate linked visitor codes\n this.dataProcessor.createReference(visitorCode, data.value[0]);\n }\n }\n\n if (\n !this.localCustomDataIndexes.has(data.index) &&\n !dataItem.isSent\n ) {\n this.unsentData[visitorCode]!.set(data.index, customData);\n }\n\n break;\n }\n case KameleoonData.PageView: {\n const data = dataItem.data as PageViewDataType;\n\n // --- Note ---\n // `PageViews` can only be processed during storage update as they\n // can't create and merge referrers/titles/timestamps on their own\n // So we have to extract them from storage to update `unsentData` correctly\n const storedData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or({});\n\n if (storedData) {\n const storedVisitorData = storedData[KameleoonData.PageView];\n const pageView = (storedVisitorData as ExistingPageViewDataType)[\n data.urlAddress\n ];\n\n // --- Note ---\n // A case for newly created page view\n if (!dataItem.isSent) {\n for (const timestamp of pageView.timestamps) {\n // --- Note ---\n // As we don't keep `sent` status for each timestamp, we have to\n // check if it was already sent to avoid duplicates\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.unsentData[visitorCode]!.set(timestamp, dataItem);\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n // --- Note ---\n // A case for `getRemoteVisitorData` pre-loaded pages that shouldn't be sent again\n } else {\n for (const timestamp of pageView.timestamps) {\n if (!this.sentPageViewTimestamps.has(timestamp)) {\n this.sentPageViewTimestamps.set(timestamp, true);\n }\n }\n }\n }\n\n break;\n }\n case KameleoonData.Conversion: {\n const unsentData = this.unsentData[visitorCode]!;\n\n if (!dataItem.isSent) {\n if (unsentData.has(KameleoonData.Conversion)) {\n const existingConversions = unsentData.get(\n KameleoonData.Conversion,\n ) as KameleoonDataType[];\n\n existingConversions.push(dataItem);\n\n unsentData.set(KameleoonData.Conversion, existingConversions);\n } else {\n unsentData.set(KameleoonData.Conversion, [dataItem]);\n }\n }\n\n break;\n }\n default: {\n const { data } = dataItem;\n\n if (!dataItem.isSent) {\n this.unsentData[visitorCode]!.set(data.type, dataItem);\n }\n }\n }\n }\n\n return Ok();\n }\n\n public getTree(segment: SegmentType): Tree {\n if (this.targetingTrees.has(segment.id)) {\n return this.targetingTrees.get(segment.id)!;\n }\n\n const targetingTree = new Tree(segment);\n this.targetingTrees.set(segment.id, targetingTree);\n\n return targetingTree;\n }\n\n public clearTrees(): void {\n this.targetingTrees.clear();\n }\n\n public getUnsentData(\n visitorCode: string,\n ): UnsentTargetingDataType[string] | undefined {\n if (this.mappingIdentifierCustomDataIndex !== null) {\n const targetingData = this.getTargetingData(visitorCode);\n\n if (targetingData) {\n const customData = targetingData[KameleoonData.CustomData];\n\n if (customData) {\n const customDataValue =\n customData[this.mappingIdentifierCustomDataIndex];\n\n if (customDataValue) {\n const { index, value } = customDataValue;\n const mappingCD = new CustomData(index, ...value);\n mappingCD._isMappingIdentifier = true;\n\n if (!this.unsentData[visitorCode]) {\n this.unsentData[visitorCode] = new Map();\n }\n\n this.unsentData[visitorCode]!.set(index, mappingCD);\n }\n }\n }\n }\n\n return this.unsentData[visitorCode];\n }\n\n public clearUnsentData(visitorCode: string): void {\n const dataItems = this.unsentData[visitorCode]?.values();\n\n if (dataItems && this.persistentCustomDataIndexes.size) {\n const persistentCustomData: UnsentVisitorTargetingDataType = new Map();\n\n for (const dataItem of dataItems) {\n if (!Array.isArray(dataItem) && this.isPersistentCustomData(dataItem)) {\n persistentCustomData.set(dataItem.data.index, dataItem);\n }\n }\n\n if (persistentCustomData.size) {\n this.unsentData[visitorCode] = persistentCustomData;\n return;\n }\n }\n\n delete this.unsentData[visitorCode];\n }\n\n public clearUnsentDataByKey(visitorCode: string, key: KameleoonData): void {\n const visitorData = this.unsentData[visitorCode];\n\n if (!visitorData) {\n return;\n }\n\n if (\n key === KameleoonData.CustomData &&\n this.persistentCustomDataIndexes.size\n ) {\n for (const [dataKey, dataItem] of visitorData.entries()) {\n if (this.isPersistentCustomData(dataItem as KameleoonDataType)) {\n continue;\n }\n\n if (dataKey === key) {\n visitorData.delete(dataKey);\n }\n }\n } else if (key === KameleoonData.PageView) {\n for (const dataKey of visitorData.keys()) {\n if (typeof dataKey === 'number') {\n visitorData.delete(dataKey);\n }\n }\n } else {\n visitorData.delete(key);\n }\n\n if (!visitorData.size) {\n delete this.unsentData[visitorCode];\n }\n }\n\n public isPersistentCustomData(\n dataItem: KameleoonDataType,\n ): dataItem is CustomData {\n if (!this.persistentCustomDataIndexes.size) {\n return false;\n }\n\n if (Utilities.isCustomData(dataItem)) {\n return this.persistentCustomDataIndexes.has(dataItem.data.index);\n }\n\n return false;\n }\n\n public getLinkedVisitor(visitorCode: string): string | null {\n return this.dataProcessor.getLinkedVisitor(\n visitorCode,\n this.mappingIdentifierCustomDataIndex,\n );\n }\n\n public getVisitorIdentifier(visitorCode: string): string {\n const targetingData = this.getTargetingData(visitorCode);\n\n if (!targetingData) {\n return visitorCode;\n }\n\n const customData = targetingData[KameleoonData.CustomData];\n\n if (!customData || this.mappingIdentifierCustomDataIndex === null) {\n return visitorCode;\n }\n\n const customDataValue = customData[this.mappingIdentifierCustomDataIndex];\n\n if (customDataValue) {\n return customDataValue.value[0];\n }\n\n return visitorCode;\n }\n\n public getTargetingData(\n visitorCode: string,\n ): KameleoonVisitorDataType | undefined {\n const targetingData = this.dataProcessor\n .getTargetingData(visitorCode)\n .or(null);\n\n if (!targetingData) {\n return undefined;\n }\n\n return targetingData;\n }\n\n get trees(): Map<string, Tree> {\n return this.targetingTrees;\n }\n\n get unsentDataVisitors(): string[] {\n return Object.keys(this.unsentData);\n }\n\n get identifierCustomDataIndex(): number | null {\n return this.mappingIdentifierCustomDataIndex;\n }\n\n get storedDataTypes(): Set<KameleoonData> {\n return this.dataProcessor.storedDataTypeList;\n }\n\n get storedCustomDataIndexes(): Set<number> {\n return this.dataProcessor.storedCustomDataIndexList;\n }\n\n set customDataIndexes(customData: CustomDataConfigurationType[]) {\n const [customDataLocalOnlyIndexes, persistentCustomDataIndexes]: Array<\n number[]\n > = [[], []];\n\n customData.forEach((customData) => {\n if (customData.localOnly) {\n customDataLocalOnlyIndexes.push(customData.index);\n }\n\n if (customData.scope === CustomDataScope.Visitor) {\n persistentCustomDataIndexes.push(customData.index);\n }\n\n if (customData.isMappingIdentifier) {\n this.mappingIdentifierCustomDataIndex = customData.index;\n }\n });\n\n if (customDataLocalOnlyIndexes.length) {\n this.localCustomDataIndexes = new Set(customDataLocalOnlyIndexes);\n }\n\n if (persistentCustomDataIndexes.length) {\n this.persistentCustomDataIndexes = new Set(persistentCustomDataIndexes);\n }\n }\n}\n"],"mappings":"o2BAuCO,KAAM,CAAAA,WAAoC,CAU/CC,WAAWA,CAAAC,CAAA,CAA0D,IAAzD,CAAEC,OAAO,CAAPA,CAAO,CAAEC,eAAe,CAAfA,CAA2C,CAAC,CAAAF,CAAA,CAIjE,GAAAG,eAAA,uBAb0C,GAAI,CAAAC,GAAK,EAAAD,eAAA,+BACP,GAAI,CAAAE,GAAK,EAAAF,eAAA,oCACJ,GAAI,CAAAE,GAAK,EAAAF,eAAA,yCACF,IAAI,EAAAA,eAAA,0BACX,IAAI,EAAAA,eAAA,8BAAAA,eAAA,2BAAAA,eAAA,+BAGA,GAAI,CAAAC,GAAK,EAG9D,IAAI,CAACE,aAAa,CAAG,GAAI,CAAAC,4BAAa,CAACN,CAAO,CAAC,CAC/C,IAAI,CAACO,UAAU,CAAG,CAAC,CAAC,CAEhBN,CAAe,CAAE,CACnB,KAAM,CAAAO,CAAe,CAAGA,CAAA,GAAM,CAC5B,IAAI,CAACH,aAAa,CAACI,oBAAoB,CAACR,CAAe,CAAC,CACxD,IAAI,CAACS,sBAAsB,CAACC,KAAK,CAAC,CACpC,CAAC,CAKD,GAAI,CACF,IAAI,CAACC,iBAAiB,CAAGC,WAAW,CAACL,CAAe,CAAEP,CAAe,CACvE,CAAE,MAAOa,CAAG,CAAE,CAKZ,KAJI,KAAI,CAACF,iBAAiB,EACxBG,aAAa,CAAC,IAAI,CAACH,iBAAiB,CAAC,CAGjCE,CACR,CACF,CACF,CAEOE,OAAOA,CACZC,CAAmB,CAEW,CAGzB,IAAI,CAACV,UAAU,CAACU,CAAW,CAAC,GAC/B,IAAI,CAACV,UAAU,CAACU,CAAW,CAAC,CAAG,GAAI,CAAAd,GAAK,UAAAe,CAAA,CAAAC,SAAA,CAAAC,MA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