@kameleoon/javascript-sdk-core 5.7.0 → 5.7.1
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,14 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 5.7.1 (2025-03-14)
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed the evaluation of the targeting condition for [**New or Returning Visitors**](https://developers.kameleoon.com/feature-management-and-experimentation/using-visit-history-in-feature-flags-and-experiments/#targeting-conditions-requiring-getremotevisitordata).
|
|
8
|
+
- Removed incorrect logging for the [`CustomData`](CustomData) condition when using the **has not been defined yet** operator.
|
|
9
|
+
|
|
10
|
+
[CustomData]: https://developers.kameleoon.com/feature-management-and-experimentation/web-sdks/js-sdk/#customdata
|
|
11
|
+
|
|
3
12
|
## 5.7.0 (2025-03-12)
|
|
4
13
|
|
|
5
14
|
### Features
|
|
@@ -6,6 +6,7 @@ interface IVisitProcessor {
|
|
|
6
6
|
processKcs(kcsData?: KCSType): void;
|
|
7
7
|
processMultipleDataTypes(): void;
|
|
8
8
|
processMappingIdentifier(visit?: VisitType): MappingIdentifierType | undefined;
|
|
9
|
+
processVisitsData(visit: VisitType): void;
|
|
9
10
|
}
|
|
10
11
|
export declare class VisitProcessor implements IVisitProcessor {
|
|
11
12
|
private visitsData;
|
|
@@ -22,6 +23,7 @@ export declare class VisitProcessor implements IVisitProcessor {
|
|
|
22
23
|
processVisit(visit: VisitType): void;
|
|
23
24
|
processMultipleDataTypes(): void;
|
|
24
25
|
processKcs(kcsData?: KCSType): void;
|
|
26
|
+
processVisitsData(visit: VisitType): void;
|
|
25
27
|
private processBrowser;
|
|
26
28
|
private processDevice;
|
|
27
29
|
private processOperatingSystem;
|
|
@@ -30,7 +32,6 @@ export declare class VisitProcessor implements IVisitProcessor {
|
|
|
30
32
|
private processConversion;
|
|
31
33
|
private processPageView;
|
|
32
34
|
private processExperiments;
|
|
33
|
-
private processVisitsData;
|
|
34
35
|
private processPersonalization;
|
|
35
36
|
processMappingIdentifier(visit?: VisitType): MappingIdentifierType | undefined;
|
|
36
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitProcessor=void 0;var _pageView=require("./pageView"),_types=require("./types"),_customData=require("./customData"),_conversion=require("./conversion"),_browser=require("./browser"),_device=require("./device"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_visitsData=require("./visitsData"),_kameleoonConversionScore=require("./kameleoonConversionScore"),_types2=require("../types"),_personalization=require("./personalization");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class VisitProcessor{constructor(a){let{filters:b,dataManager:c,visitorCode:d}=a;_defineProperty(this,"visitsData",new _visitsData.VisitsData([])),_defineProperty(this,"visitorData",[]),_defineProperty(this,"storageVisitorData",[]),_defineProperty(this,"experimentData",{}),_defineProperty(this,"filters",void 0),_defineProperty(this,"visitorDataTypes",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"singleDataTypes",{[_types.KameleoonData.Device]:null,[_types.KameleoonData.Browser]:null,[_types.KameleoonData.GeolocationData]:null,[_types.KameleoonData.OperatingSystem]:null,[_types.KameleoonData.KameleoonConversionScore]:null}),_defineProperty(this,"multipleDataTypes",{[_types.KameleoonData.CustomData]:new Map,[_types.KameleoonData.PageView]:new Map,[_types.KameleoonData.Conversion]:new Map,[_types.KameleoonData.Personalization]:new Map}),this.filters=b,this.dataManager=c,this.visitorDataTypes=c.getVisitorStoredDataTypes(d)}get data(){return{visitorData:this.visitorData,storageVisitorData:this.storageVisitorData,visitsData:this.visitsData,experimentData:this.experimentData}}processVisit(a){this.processBrowser(a),this.processDevice(a),this.processOperatingSystem(a),this.processGeolocationData(a),this.processCustomData(a),this.processConversion(a),this.processPageView(a),this.processExperiments(a),this.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitProcessor=void 0;var _pageView=require("./pageView"),_types=require("./types"),_customData=require("./customData"),_conversion=require("./conversion"),_browser=require("./browser"),_device=require("./device"),_operatingSystem=require("./operatingSystem"),_geolocation=require("./geolocation"),_visitsData=require("./visitsData"),_kameleoonConversionScore=require("./kameleoonConversionScore"),_types2=require("../types"),_personalization=require("./personalization");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class VisitProcessor{constructor(a){let{filters:b,dataManager:c,visitorCode:d}=a;_defineProperty(this,"visitsData",new _visitsData.VisitsData([])),_defineProperty(this,"visitorData",[]),_defineProperty(this,"storageVisitorData",[]),_defineProperty(this,"experimentData",{}),_defineProperty(this,"filters",void 0),_defineProperty(this,"visitorDataTypes",void 0),_defineProperty(this,"dataManager",void 0),_defineProperty(this,"singleDataTypes",{[_types.KameleoonData.Device]:null,[_types.KameleoonData.Browser]:null,[_types.KameleoonData.GeolocationData]:null,[_types.KameleoonData.OperatingSystem]:null,[_types.KameleoonData.KameleoonConversionScore]:null}),_defineProperty(this,"multipleDataTypes",{[_types.KameleoonData.CustomData]:new Map,[_types.KameleoonData.PageView]:new Map,[_types.KameleoonData.Conversion]:new Map,[_types.KameleoonData.Personalization]:new Map}),this.filters=b,this.dataManager=c,this.visitorDataTypes=c.getVisitorStoredDataTypes(d)}get data(){return{visitorData:this.visitorData,storageVisitorData:this.storageVisitorData,visitsData:this.visitsData,experimentData:this.experimentData}}processVisit(a){this.processBrowser(a),this.processDevice(a),this.processOperatingSystem(a),this.processGeolocationData(a),this.processCustomData(a),this.processConversion(a),this.processPageView(a),this.processExperiments(a),this.processPersonalization(a)}processMultipleDataTypes(){for(const[a,b]of Object.entries(this.multipleDataTypes))if(b.size)switch(a){case _types.KameleoonData.PageView:{this.visitorData.push(...b.values()),this.storageVisitorData.push(...b.values());break}case _types.KameleoonData.Personalization:case _types.KameleoonData.Conversion:{this.storageVisitorData.push(...b.values());break}case _types.KameleoonData.CustomData:{b.forEach(a=>{this.visitorData.push(a),this.dataManager.storedCustomDataIndexes.has(a.data.index)||this.storageVisitorData.push(a)});break}}}processKcs(a){if(this.filters.kcs&&a){const b=new _kameleoonConversionScore.KameleoonConversionScore(a);this.storageVisitorData.push(b)}}processVisitsData(a){this.visitsData.timestamp=a.timeStarted}processBrowser(a){if(this.filters.browser&&!this.singleDataTypes[_types.KameleoonData.Browser]){const b=_browser.Browser._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.Browser)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.Browser]=b)}}processDevice(a){if(this.filters.device&&!this.singleDataTypes[_types.KameleoonData.Device]){const b=_device.Device._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.Device)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.Device]=b)}}processOperatingSystem(a){if(this.filters.operatingSystem&&!this.singleDataTypes[_types.KameleoonData.OperatingSystem]){const b=_operatingSystem.OperatingSystem._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.OperatingSystem)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.OperatingSystem]=b)}}processGeolocationData(a){if(this.filters.geolocation&&!this.singleDataTypes[_types.KameleoonData.GeolocationData]){const b=_geolocation.GeolocationData._fromVisit(a);b&&(!this.visitorDataTypes.has(_types.KameleoonData.GeolocationData)&&this.storageVisitorData.push(b),this.visitorData.push(b),this.singleDataTypes[_types.KameleoonData.GeolocationData]=b)}}processCustomData(a){this.filters.customData&&_customData.CustomData._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.CustomData])}processConversion(a){if(this.filters.conversions){_conversion.Conversion._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.Conversion]);const b=_conversion.Conversion._listFromVisit(a);b.length&&this.visitorData.push(...b)}}processPageView(a){this.filters.pageViews&&_pageView.PageView._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.PageView])}processExperiments(a){if(this.filters.experiments&&a.experimentEvents)for(const b of a.experimentEvents){const{id:a,variationId:c}=b.data;this.experimentData[a]={variationId:c,isTargetedRule:!1,status:_types2.TrackingStatus.Unsent}}}processPersonalization(a){this.filters.personalization&&_personalization.Personalization._updateFromVisit(a,this.multipleDataTypes[_types.KameleoonData.Personalization])}processMappingIdentifier(a){var b,c;if(a){const d=null===(b=a.customDataEvents)||void 0===b||null===(c=b.find(a=>a.data.mappingIdentifier))||void 0===c?void 0:c.time;if(d&&a.visitorCode)return{mappingIdentifier:a.visitorCode,timestamp:d}}}}exports.VisitProcessor=VisitProcessor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_kameleoonError=require("../../kameleoonError"),_types2=require("../types"),_utilities=require("../../utilities"),_kameleoonLogger=require("../../logging/kameleoonLogger");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class CustomData{constructor(a){let{customDataIndex:b,valueMatchType:c,value:d,range:e}=a;_defineProperty(this,"customDataIndex",void 0),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"error",void 0),_defineProperty(this,"range",void 0),this.customDataIndex=b?+b
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.CustomData=void 0;var _tsRes=require("ts-res"),_types=require("../../kameleoonData/types"),_kameleoonError=require("../../kameleoonError"),_types2=require("../types"),_utilities=require("../../utilities"),_kameleoonLogger=require("../../logging/kameleoonLogger");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class CustomData{constructor(a){let{customDataIndex:b,valueMatchType:c,value:d,range:e}=a;_defineProperty(this,"customDataIndex",void 0),_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"error",void 0),_defineProperty(this,"range",void 0),this.customDataIndex=b?+b:-1,this.matchType=c,this.conditionValue=d,this.range=e}evaluate(a){var b;let{targetingData:c}=a;const d=null===c||void 0===c||null===(b=c[_types.KameleoonData.CustomData])||void 0===b?void 0:b[this.customDataIndex];if(this.matchType===_types2.ValueMatchType.UNDEFINED)return(0,_tsRes.Ok)(!d);if(d){const{value:a}=d,b=this.checkCondition(a);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(b)}return(0,_tsRes.Ok)(!1)}checkCondition(a){if("string"!=typeof this.conditionValue&&this.matchType!==_types2.ValueMatchType.TRUE&&this.matchType!==_types2.ValueMatchType.FALSE&&this.matchType!==_types2.ValueMatchType.RANGE)return _kameleoonLogger.KameleoonLogger.error`Unexpected condition value for CustomData condition: ${this.conditionValue}`,!1;const b=this.conditionValue;if(this.matchType===_types2.ValueMatchType.AMONG_VALUES){const c=this.parseArray(b);if(!c.ok)return this.error=c.error,!1;const d=new Set(c.data);return Array.isArray(a)?a.some(a=>d.has(a)):c.data.includes(a)}if(this.matchType===_types2.ValueMatchType.RANGE){const b=this.parseRange(this.range);if(!b.ok)return this.error=b.error,!1;const[c,d]=b.data,e=a=>a>=c&&a<=d;return Array.isArray(a)?a.some(a=>e(+a)):e(+a)}if(Array.isArray(a))return a.some(a=>this.checkCondition(a));switch(this.matchType){case _types2.ValueMatchType.CONTAINS:return a.includes(b);case _types2.ValueMatchType.EXACT:return a===this.conditionValue;case _types2.ValueMatchType.REGULAR_EXPRESSION:return _utilities.Parser.parseRegExp(b).test(a);case _types2.ValueMatchType.LOWER:return+a<+this.conditionValue;case _types2.ValueMatchType.EQUAL:return+a===+this.conditionValue;case _types2.ValueMatchType.GREATER:return+a>+this.conditionValue;case _types2.ValueMatchType.TRUE:return"true"===a.toLowerCase();case _types2.ValueMatchType.FALSE:return"false"===a.toLowerCase();default:return _kameleoonLogger.KameleoonLogger.error`Unexpected comparing operation for CustomData condition: ${this.matchType}`,!1}}parseArray(a){try{const b=JSON.parse(a);if(Array.isArray(b))return(0,_tsRes.Ok)(b)}catch(b){return _kameleoonLogger.KameleoonLogger.error`Failed to parse array: ${a} in CustomData condition`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.AmongValuesCheck,b,a))}return(0,_tsRes.Ok)([])}parseRange(a){return a&&2===a.length?(0,_tsRes.Ok)(a):(_kameleoonLogger.KameleoonLogger.error`Failed to parse range: ${a} in CustomData condition`,(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RangeCheck,a)))}}exports.CustomData=CustomData;
|
package/dist/utilities/parser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Parser=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants=require("./constants");class Parser{static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.JS:case _types.VariableType.CSS:case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor({filters:c,dataManager:e,visitorCode:d}),{currentVisit:h,previousVisits:i,kcs:j}=b;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Parser=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_types=require("../types"),_visitProcessor=require("../kameleoonData/visitProcessor"),_constants=require("./constants"),_visitsData=require("../kameleoonData/visitsData");class Parser{static parseFeatureVariable(a){const{key:b,type:c,value:d}=a;switch(c){case _types.VariableType.BOOLEAN:return(0,_tsRes.Ok)({key:b,type:c,value:!!d});case _types.VariableType.JS:case _types.VariableType.CSS:case _types.VariableType.STRING:return(0,_tsRes.Ok)({key:b,type:c,value:d+""});case _types.VariableType.NUMBER:const e=+d;return Number.isNaN(e)?(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.NumberParse,d+"")):(0,_tsRes.Ok)({key:b,type:c,value:e});case _types.VariableType.JSON:try{const d=JSON.parse(a.value+"");return(0,_tsRes.Ok)({key:b,type:c,value:d})}catch(a){return(0,_tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.JSONParse,a))}default:(0,_kameleoonError.exhaustCheck)(c)}}static parseVisitorData(a){let{data:b,filters:c,visitorCode:d,dataManager:e,variationConfiguration:f}=a;const g=new _visitProcessor.VisitProcessor({filters:c,dataManager:e,visitorCode:d}),{currentVisit:h,previousVisits:i,kcs:j}=b;if(!(null!==i&&void 0!==i&&i.length)&&!h)return{visitorData:[],storageVisitorData:[],visitsData:new _visitsData.VisitsData([])};h&&g.processVisit(h),null===i||void 0===i?void 0:i.forEach(a=>{g.processVisit(a),g.processVisitsData(a)}),g.processKcs(j),g.processMultipleDataTypes();const k=g.processMappingIdentifier(null!==h&&void 0!==h?h:null===i||void 0===i?void 0:i[0]),{visitorData:l,storageVisitorData:m,visitsData:n,experimentData:o}=g.data;return f.updateStoredVariations(d,o),{visitorData:l,storageVisitorData:m,visitsData:n,mappingIdentifier:k}}static parseRegExp(a){if("/"===a[0]){const[_,b,c]=a.split("/");return new RegExp(b,c)}return new RegExp(a)}static parseSecret(a){if(null===a)return"null";const b=a.length;if(b<=_constants.SECRET_VISIBLE_LENGTH)return _constants.HIDDEN_SECRET_CHAR.repeat(b);const c=Math.max(b-_constants.SECRET_VISIBLE_LENGTH,_constants.SECRET_VISIBLE_LENGTH);return a.substring(0,b-c)+_constants.HIDDEN_SECRET_CHAR.repeat(c)}}exports.Parser=Parser;
|