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

@kameleoon/javascript-sdk-core

Package Overview
Dependencies
Maintainers
0
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 4.4.5 to 4.4.6

6

CHANGELOG.md
# Change Log
## 4.4.6 (2024-08-15)
### Patch Changes
- Fixed the issue with mapping identifier Custom Data not being set correctly after browser tab reload
## 4.4.5 (2024-08-08)

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

2

dist/clientConfiguration/clientConfiguration.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ClientConfiguration=void 0;var _tsRes=require("ts-res"),_constants=require("./constants"),_types=require("./types"),_utilities=require("../utilities"),_eventManager=require("../eventManager"),_urlProvider=require("../requester/urlProvider");function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class ClientConfiguration{constructor(a){let{updateInterval:b,storage:c,requester:d,dataManager:e,externalClientConfiguration:f,offlineTrackingStorage:g,eventSource:h,externalVisitorCodeManager:i,eventManager:j}=a;_defineProperty(this,"updateConfigurationIntervalId",null),_defineProperty(this,"updateType",_types.UpdateType.Idle),_defineProperty(this,"configurationData",_constants.DEFAULT_CONFIGURATION_DATA),_defineProperty(this,"featureFlagsData",new Map),_defineProperty(this,"isTargetedDeliveryRule",null),_defineProperty(this,"segmentsData",null),_defineProperty(this,"updateInterval",void 0),_defineProperty(this,"lastUpdate",void 0),_defineProperty(this,"storage",void 0),_defineProperty(this,"offlineTrackingStorage",void 0),_defineProperty(this,"requester",void 0),_defineProperty(this,"eventSource",void 0),_defineProperty(this,"externalClientConfiguration",void 0),_defineProperty(this,"mappedRules",null),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"visitorCodeManager",void 0),_defineProperty(this,"eventManager",void 0),this.requester=d,this.updateInterval=b,this.lastUpdate=new Date,this.storage=c,this.dataManager=e,this.eventManager=j,this.externalClientConfiguration=f,this.offlineTrackingStorage=g,this.visitorCodeManager=i,this.eventSource=h}async initialize(){this.readStorageData();const a=!!this.externalClientConfiguration,b=this.checkShouldUpdate(a);if(b){const a=await this.updateClientConfiguration();if(!a.ok)return a;const b=a.data;if(b)return(0,_tsRes.Ok)()}return a?(this.handleExternalUpdates(),(0,_tsRes.Ok)()):this.updateType!==_types.UpdateType.RealTime||this.eventSource.isOpen?(this.updateType===_types.UpdateType.Polling&&this.handlePollingUpdates(),(0,_tsRes.Ok)()):(this.updateType=_types.UpdateType.Idle,this.handleRealTimeUpdates(),(0,_tsRes.Ok)())}cleanupHandlers(){this.eventSource.isOpen&&this.eventSource.close(),this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId)}handleExternalUpdates(){this.cleanupHandlers();const{customData:a,configuration:b,featureFlags:c}=this.externalClientConfiguration;this.configurationData={customData:a,configuration:b};for(const a of c)this.featureFlagsData.set(a.featureKey,a)}handleRealTimeUpdates(){this.cleanupHandlers();const a=a=>{this.updateClientConfiguration(a).then(b=>{b.ok&&this.eventManager.fireEvent(_eventManager.EventType.ConfigurationUpdate,{timestamp:a})})};this.eventSource.open(a)}handlePollingUpdates(){this.cleanupHandlers();try{this.updateConfigurationIntervalId=setInterval(this.updateClientConfiguration.bind(this),this.updateInterval)}catch(a){throw this.updateConfigurationIntervalId&&clearInterval(this.updateConfigurationIntervalId),a}}get featureFlags(){return this.featureFlagsData}get configuration(){return this.configurationData.configuration}get segments(){if(this.segmentsData)return this.segmentsData;const a=new Map;return this.featureFlagsData.forEach(b=>{b.rules.forEach(b=>{b.segment&&!a.has(b.segment.id)&&a.set(b.segment.id,b.segment)})}),this.segmentsData=a,a}get ruleMap(){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;
"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;
//# sourceMappingURL=clientConfiguration.js.map
{
"name": "@kameleoon/javascript-sdk-core",
"version": "4.4.5",
"version": "4.4.6",
"description": "Kameleoon JS SDK Core",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc