@kameleoon/javascript-sdk-core 4.4.7 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/dist/cacheManager/cacheManager.js +1 -1
- package/dist/cacheManager/cacheManager.js.map +1 -1
- package/dist/cacheManager/index.js.map +1 -1
- package/dist/cacheManager/types.js.map +1 -1
- package/dist/clientConfiguration/clientConfiguration.d.ts +3 -6
- package/dist/clientConfiguration/clientConfiguration.js +1 -1
- package/dist/clientConfiguration/clientConfiguration.js.map +1 -1
- package/dist/clientConfiguration/constants.js.map +1 -1
- package/dist/clientConfiguration/index.js.map +1 -1
- package/dist/clientConfiguration/types.d.ts +4 -5
- package/dist/clientConfiguration/types.js +1 -1
- package/dist/clientConfiguration/types.js.map +1 -1
- package/dist/clientSettings/clientSettings.d.ts +2 -1
- package/dist/clientSettings/clientSettings.js +1 -1
- package/dist/clientSettings/clientSettings.js.map +1 -1
- package/dist/clientSettings/index.js.map +1 -1
- package/dist/clientSettings/types.d.ts +1 -0
- package/dist/clientSettings/types.js.map +1 -1
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/eventManager/eventManager.js +1 -1
- package/dist/eventManager/eventManager.js.map +1 -1
- package/dist/eventManager/index.js.map +1 -1
- package/dist/eventManager/types.js.map +1 -1
- package/dist/eventSource/constants.js.map +1 -1
- package/dist/eventSource/eventSource.d.ts +2 -2
- package/dist/eventSource/eventSource.js +1 -1
- package/dist/eventSource/eventSource.js.map +1 -1
- package/dist/eventSource/index.js.map +1 -1
- package/dist/eventSource/types.d.ts +6 -0
- package/dist/eventSource/types.js.map +1 -1
- package/dist/hasher/hasher.js.map +1 -1
- package/dist/hasher/index.js.map +1 -1
- package/dist/hasher/types.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +7 -14
- package/dist/kameleoonClient.js +1 -1
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonClientInterface.d.ts +18 -16
- package/dist/kameleoonClientInterface.js.map +1 -1
- package/dist/kameleoonData/applicationVersion.d.ts +2 -3
- package/dist/kameleoonData/applicationVersion.js +1 -1
- package/dist/kameleoonData/applicationVersion.js.map +1 -1
- package/dist/kameleoonData/browser.d.ts +9 -3
- package/dist/kameleoonData/browser.js +1 -1
- package/dist/kameleoonData/browser.js.map +1 -1
- package/dist/kameleoonData/conversion.d.ts +12 -3
- package/dist/kameleoonData/conversion.js +1 -1
- package/dist/kameleoonData/conversion.js.map +1 -1
- package/dist/kameleoonData/cookie.d.ts +2 -3
- package/dist/kameleoonData/cookie.js +1 -1
- package/dist/kameleoonData/cookie.js.map +1 -1
- package/dist/kameleoonData/customData.d.ts +11 -3
- package/dist/kameleoonData/customData.js +1 -1
- package/dist/kameleoonData/customData.js.map +1 -1
- package/dist/kameleoonData/dataManager.d.ts +34 -23
- package/dist/kameleoonData/dataManager.js +1 -1
- package/dist/kameleoonData/dataManager.js.map +1 -1
- package/dist/kameleoonData/dataProcessor.d.ts +22 -24
- package/dist/kameleoonData/dataProcessor.js +1 -1
- package/dist/kameleoonData/dataProcessor.js.map +1 -1
- package/dist/kameleoonData/device.d.ts +9 -3
- package/dist/kameleoonData/device.js +1 -1
- package/dist/kameleoonData/device.js.map +1 -1
- package/dist/kameleoonData/geolocation.d.ts +9 -3
- package/dist/kameleoonData/geolocation.js +1 -1
- package/dist/kameleoonData/geolocation.js.map +1 -1
- package/dist/kameleoonData/helpers.js.map +1 -1
- package/dist/kameleoonData/index.d.ts +2 -1
- package/dist/kameleoonData/index.js +1 -1
- package/dist/kameleoonData/index.js.map +1 -1
- package/dist/kameleoonData/kameleoonConversionScore.d.ts +2 -1
- package/dist/kameleoonData/kameleoonConversionScore.js +1 -1
- package/dist/kameleoonData/kameleoonConversionScore.js.map +1 -1
- package/dist/kameleoonData/operatingSystem.d.ts +9 -3
- package/dist/kameleoonData/operatingSystem.js +1 -1
- package/dist/kameleoonData/operatingSystem.js.map +1 -1
- package/dist/kameleoonData/pageView.d.ts +12 -8
- package/dist/kameleoonData/pageView.js +1 -1
- package/dist/kameleoonData/pageView.js.map +1 -1
- package/dist/kameleoonData/types.d.ts +97 -31
- package/dist/kameleoonData/types.js +1 -1
- package/dist/kameleoonData/types.js.map +1 -1
- package/dist/kameleoonData/uniqueIdentifier.d.ts +19 -0
- package/dist/kameleoonData/uniqueIdentifier.js +2 -0
- package/dist/kameleoonData/uniqueIdentifier.js.map +1 -0
- package/dist/kameleoonData/userAgent.d.ts +2 -3
- package/dist/kameleoonData/userAgent.js +1 -1
- package/dist/kameleoonData/userAgent.js.map +1 -1
- package/dist/kameleoonData/visitProcessor.d.ts +3 -4
- package/dist/kameleoonData/visitProcessor.js +1 -1
- package/dist/kameleoonData/visitProcessor.js.map +1 -1
- package/dist/kameleoonData/visitsData.d.ts +2 -0
- package/dist/kameleoonData/visitsData.js +1 -1
- package/dist/kameleoonData/visitsData.js.map +1 -1
- package/dist/kameleoonError/constants.js +1 -1
- package/dist/kameleoonError/constants.js.map +1 -1
- package/dist/kameleoonError/helpers.js +1 -1
- package/dist/kameleoonError/helpers.js.map +1 -1
- package/dist/kameleoonError/index.js.map +1 -1
- package/dist/kameleoonError/kameleoonError.js +1 -1
- package/dist/kameleoonError/kameleoonError.js.map +1 -1
- package/dist/kameleoonError/types.js.map +1 -1
- package/dist/kameleoonUtils.d.ts +1 -11
- package/dist/kameleoonUtils.js +1 -1
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.d.ts +2 -1
- package/dist/requester/constants.js +1 -1
- package/dist/requester/constants.js.map +1 -1
- package/dist/requester/index.d.ts +3 -2
- package/dist/requester/index.js +1 -1
- package/dist/requester/index.js.map +1 -1
- package/dist/requester/requester.d.ts +6 -7
- package/dist/requester/requester.js +1 -1
- package/dist/requester/requester.js.map +1 -1
- package/dist/requester/types.d.ts +10 -30
- package/dist/requester/types.js +1 -1
- package/dist/requester/types.js.map +1 -1
- package/dist/requester/urlProvider.d.ts +26 -18
- package/dist/requester/urlProvider.js +1 -1
- package/dist/requester/urlProvider.js.map +1 -1
- package/dist/storage/constants.d.ts +6 -2
- package/dist/storage/constants.js +1 -1
- package/dist/storage/constants.js.map +1 -1
- package/dist/storage/index.d.ts +3 -2
- package/dist/storage/index.js +1 -1
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/integrityChecker.d.ts +20 -0
- package/dist/storage/integrityChecker.js +2 -0
- package/dist/storage/integrityChecker.js.map +1 -0
- package/dist/storage/storage.d.ts +0 -1
- package/dist/storage/storage.js +1 -1
- package/dist/storage/storage.js.map +1 -1
- package/dist/storage/types.d.ts +25 -17
- package/dist/storage/types.js.map +1 -1
- package/dist/targeting/conditions/applicationVersion.js +1 -1
- package/dist/targeting/conditions/applicationVersion.js.map +1 -1
- package/dist/targeting/conditions/browser.js +1 -1
- package/dist/targeting/conditions/browser.js.map +1 -1
- package/dist/targeting/conditions/conditionFactory.js.map +1 -1
- package/dist/targeting/conditions/conversion.js +1 -1
- package/dist/targeting/conditions/conversion.js.map +1 -1
- package/dist/targeting/conditions/conversionLikelihood.js +1 -1
- package/dist/targeting/conditions/conversionLikelihood.js.map +1 -1
- package/dist/targeting/conditions/cookie.js +1 -1
- package/dist/targeting/conditions/cookie.js.map +1 -1
- package/dist/targeting/conditions/customData.js +1 -1
- package/dist/targeting/conditions/customData.js.map +1 -1
- package/dist/targeting/conditions/device.js +1 -1
- package/dist/targeting/conditions/device.js.map +1 -1
- package/dist/targeting/conditions/exclusiveCampaign.js.map +1 -1
- package/dist/targeting/conditions/firstVisit.js +1 -1
- package/dist/targeting/conditions/firstVisit.js.map +1 -1
- package/dist/targeting/conditions/geolocation.js +1 -1
- package/dist/targeting/conditions/geolocation.js.map +1 -1
- package/dist/targeting/conditions/index.js.map +1 -1
- package/dist/targeting/conditions/lastVisit.js +1 -1
- package/dist/targeting/conditions/lastVisit.js.map +1 -1
- package/dist/targeting/conditions/newVisitor.js +1 -1
- package/dist/targeting/conditions/newVisitor.js.map +1 -1
- package/dist/targeting/conditions/operatingSystem.js +1 -1
- package/dist/targeting/conditions/operatingSystem.js.map +1 -1
- package/dist/targeting/conditions/pageTitle.js +1 -1
- package/dist/targeting/conditions/pageTitle.js.map +1 -1
- package/dist/targeting/conditions/pageUrl.js +1 -1
- package/dist/targeting/conditions/pageUrl.js.map +1 -1
- package/dist/targeting/conditions/previousPage.js +1 -1
- package/dist/targeting/conditions/previousPage.js.map +1 -1
- package/dist/targeting/conditions/sameDayVisits.js +1 -1
- package/dist/targeting/conditions/sameDayVisits.js.map +1 -1
- package/dist/targeting/conditions/sdkLanguage.js +1 -1
- package/dist/targeting/conditions/sdkLanguage.js.map +1 -1
- package/dist/targeting/conditions/segment.js +1 -1
- package/dist/targeting/conditions/segment.js.map +1 -1
- package/dist/targeting/conditions/targetFeatureFlag.js +1 -1
- package/dist/targeting/conditions/targetFeatureFlag.js.map +1 -1
- package/dist/targeting/conditions/types.js.map +1 -1
- package/dist/targeting/conditions/visitedPages.js +1 -1
- package/dist/targeting/conditions/visitedPages.js.map +1 -1
- package/dist/targeting/conditions/visitorCode.js +1 -1
- package/dist/targeting/conditions/visitorCode.js.map +1 -1
- package/dist/targeting/conditions/visits.js +1 -1
- package/dist/targeting/conditions/visits.js.map +1 -1
- package/dist/targeting/index.d.ts +1 -1
- package/dist/targeting/index.js.map +1 -1
- package/dist/targeting/node.js +1 -1
- package/dist/targeting/node.js.map +1 -1
- package/dist/targeting/tree.js +1 -1
- package/dist/targeting/tree.js.map +1 -1
- package/dist/targeting/types.js.map +1 -1
- package/dist/tracking/bodyProvider.d.ts +26 -0
- package/dist/tracking/bodyProvider.js +2 -0
- package/dist/tracking/bodyProvider.js.map +1 -0
- package/dist/tracking/constants.d.ts +2 -0
- package/dist/tracking/constants.js +2 -0
- package/dist/tracking/constants.js.map +1 -0
- package/dist/tracking/index.d.ts +1 -0
- package/dist/tracking/index.js +2 -0
- package/dist/tracking/index.js.map +1 -0
- package/dist/tracking/tracker.d.ts +21 -0
- package/dist/tracking/tracker.js +2 -0
- package/dist/tracking/tracker.js.map +1 -0
- package/dist/tracking/types.d.ts +45 -0
- package/dist/tracking/types.js +2 -0
- package/dist/tracking/types.js.map +1 -0
- package/dist/types.d.ts +54 -17
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/constants.d.ts +0 -1
- package/dist/utilities/constants.js +1 -1
- package/dist/utilities/constants.js.map +1 -1
- package/dist/utilities/index.d.ts +3 -2
- package/dist/utilities/index.js +1 -1
- package/dist/utilities/index.js.map +1 -1
- package/dist/utilities/parser.d.ts +10 -0
- package/dist/utilities/parser.js +2 -0
- package/dist/utilities/parser.js.map +1 -0
- package/dist/utilities/types.d.ts +3 -40
- package/dist/utilities/types.js.map +1 -1
- package/dist/utilities/utilities.d.ts +5 -21
- package/dist/utilities/utilities.js +1 -1
- package/dist/utilities/utilities.js.map +1 -1
- package/dist/utilities/validator.d.ts +5 -0
- package/dist/utilities/validator.js +2 -0
- package/dist/utilities/validator.js.map +1 -0
- package/dist/variationConfiguration/index.js.map +1 -1
- package/dist/variationConfiguration/types.d.ts +7 -2
- package/dist/variationConfiguration/types.js.map +1 -1
- package/dist/variationConfiguration/variationConfiguration.d.ts +15 -7
- package/dist/variationConfiguration/variationConfiguration.js +1 -1
- package/dist/variationConfiguration/variationConfiguration.js.map +1 -1
- package/dist/visitorCodeManager/constants.d.ts +2 -0
- package/dist/visitorCodeManager/constants.js +1 -1
- package/dist/visitorCodeManager/constants.js.map +1 -1
- package/dist/visitorCodeManager/index.js.map +1 -1
- package/dist/visitorCodeManager/types.d.ts +3 -0
- package/dist/visitorCodeManager/types.js.map +1 -1
- package/dist/visitorCodeManager/visitorCodeManager.d.ts +4 -0
- package/dist/visitorCodeManager/visitorCodeManager.js +1 -1
- package/dist/visitorCodeManager/visitorCodeManager.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LastVisit=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.LastVisit=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class LastVisit{constructor(a){let{matchType:b,count:c,unitOfTime:d}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"timeUnit",void 0),this.matchType=b,this.conditionValue=c,this.timeUnit=d}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.VisitsData];if(!(null!==c&&void 0!==c&&c.visits.length))return(0,_tsRes.Ok)(!1);const{visits:d}=c,e=d[d.length-1];return(0,_tsRes.Ok)(this.checkCondition(e))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue||!this.timeUnit)return!1;const b=Date.now()-a,c=_utilities.Utilities.convertTimeUnit(b,this.timeUnit);switch(this.matchType){case _types.MatchType.GREATER:return c>this.conditionValue;case _types.MatchType.LOWER:return c<this.conditionValue;default:return!1}}}exports.LastVisit=LastVisit;
|
|
2
2
|
//# sourceMappingURL=lastVisit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lastVisit.js","names":["LastVisit","constructor","a","matchType","count","unitOfTime","_defineProperty","conditionValue","timeUnit","evaluate","targetingData","visitsData","KameleoonData","VisitsData","visits","length","Ok","latestPreviousVisitTimestamp","checkCondition","lastVisitTimestamp","elapsedTimeMilliseconds","Date","now","elapsedTimeUnit","Utilities","convertTimeUnit","MatchType","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/lastVisit.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities, TimeUnit } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class LastVisit implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n private timeUnit?: TimeUnit | null;\n\n constructor({ matchType, count, unitOfTime }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = count;\n this.timeUnit = unitOfTime;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData?.visits.length) {\n return Ok(false);\n }\n\n const { visits } = visitsData;\n\n // --- Note ---\n // Takes the timestamp of latest previous visit\n const latestPreviousVisitTimestamp =\n visits[visits.length - 1];\n\n return Ok(this.checkCondition(latestPreviousVisitTimestamp));\n }\n\n private checkCondition(lastVisitTimestamp: number): boolean {\n if (\n !this.matchType ||\n typeof this.conditionValue !== 'number' ||\n !this.timeUnit\n ) {\n return false;\n }\n\n const elapsedTimeMilliseconds = Date.now() - lastVisitTimestamp;\n const elapsedTimeUnit = Utilities.convertTimeUnit(\n elapsedTimeMilliseconds,\n this.timeUnit,\n );\n\n switch (this.matchType) {\n case MatchType.GREATER:\n return elapsedTimeUnit > this.conditionValue;\n case MatchType.LOWER:\n return elapsedTimeUnit < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"lastVisit.js","names":["LastVisit","constructor","a","matchType","count","unitOfTime","_defineProperty","conditionValue","timeUnit","evaluate","targetingData","visitsData","KameleoonData","VisitsData","visits","length","Ok","latestPreviousVisitTimestamp","checkCondition","lastVisitTimestamp","elapsedTimeMilliseconds","Date","now","elapsedTimeUnit","Utilities","convertTimeUnit","MatchType","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/lastVisit.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities, TimeUnit } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class LastVisit implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n private timeUnit?: TimeUnit | null;\n\n constructor({ matchType, count, unitOfTime }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = count;\n this.timeUnit = unitOfTime;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData?.visits.length) {\n return Ok(false);\n }\n\n const { visits } = visitsData;\n\n // --- Note ---\n // Takes the timestamp of latest previous visit\n const latestPreviousVisitTimestamp =\n visits[visits.length - 1];\n\n return Ok(this.checkCondition(latestPreviousVisitTimestamp));\n }\n\n private checkCondition(lastVisitTimestamp: number): boolean {\n if (\n !this.matchType ||\n typeof this.conditionValue !== 'number' ||\n !this.timeUnit\n ) {\n return false;\n }\n\n const elapsedTimeMilliseconds = Date.now() - lastVisitTimestamp;\n const elapsedTimeUnit = Utilities.convertTimeUnit(\n elapsedTimeMilliseconds,\n this.timeUnit,\n );\n\n switch (this.matchType) {\n case MatchType.GREATER:\n return elapsedTimeUnit > this.conditionValue;\n case MatchType.LOWER:\n return elapsedTimeUnit < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings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O,CAAAJ,CAAe,CAAG,IAAI,CAAChB,cAAc,CAC9C,IAAK,CAAAmB,gBAAS,CAACE,KAAK,CAClB,MAAO,CAAAL,CAAe,CAAG,IAAI,CAAChB,cAAc,CAC9C,QACE,QACJ,CACF,CACF,CAACsB,OAAA,CAAA7B,SAAA,CAAAA,SAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NewVisitor=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.NewVisitor=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_kameleoonError=require("../../kameleoonError"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class NewVisitor{constructor(a){let{visitorType:b}=a;_defineProperty(this,"visitorType",void 0),this.visitorType=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.VisitsData];if(!c||!this.visitorType)return(0,_tsRes.Ok)(!1);const{visits:d}=c,e=!d.length;switch(this.visitorType){case _types.VisitorType.NEW:return(0,_tsRes.Ok)(e);case _types.VisitorType.RETURNING:return(0,_tsRes.Ok)(!e);default:(0,_kameleoonError.exhaustCheck)(this.visitorType)}}}exports.NewVisitor=NewVisitor;
|
|
2
2
|
//# sourceMappingURL=newVisitor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"newVisitor.js","names":["NewVisitor","constructor","a","visitorType","_defineProperty","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","visits","isNewVisitor","length","VisitorType","NEW","RETURNING","exhaustCheck","exports"],"sources":["../../../src/targeting/conditions/newVisitor.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, VisitorType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class NewVisitor implements ICondition {\n private visitorType?: VisitorType | null;\n\n constructor({ visitorType }: ConditionDataType) {\n this.visitorType = visitorType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData || !this.visitorType) {\n return Ok(false);\n }\n\n const { visits } = visitsData;\n\n // --- Note ---\n // Second case handles situation when user didn't use `addData` that\n // creates new current visit\n const isNewVisitor = !visits.length;\n\n switch (this.visitorType) {\n case VisitorType.NEW:\n return Ok(isNewVisitor);\n case VisitorType.RETURNING:\n return Ok(!isNewVisitor);\n default:\n exhaustCheck(this.visitorType);\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"newVisitor.js","names":["NewVisitor","constructor","a","visitorType","_defineProperty","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","visits","isNewVisitor","length","VisitorType","NEW","RETURNING","exhaustCheck","exports"],"sources":["../../../src/targeting/conditions/newVisitor.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { exhaustCheck, KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, VisitorType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class NewVisitor implements ICondition {\n private visitorType?: VisitorType | null;\n\n constructor({ visitorType }: ConditionDataType) {\n this.visitorType = visitorType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData || !this.visitorType) {\n return Ok(false);\n }\n\n const { visits } = visitsData;\n\n // --- Note ---\n // Second case handles situation when user didn't use `addData` that\n // creates new current visit\n const isNewVisitor = !visits.length;\n\n switch (this.visitorType) {\n case VisitorType.NEW:\n return Ok(isNewVisitor);\n case VisitorType.RETURNING:\n return Ok(!isNewVisitor);\n default:\n exhaustCheck(this.visitorType);\n }\n }\n}\n"],"mappings":"qvBAMO,KAAM,CAAAA,UAAiC,CAG5CC,WAAWA,CAAAC,CAAA,CAAqC,IAApC,CAAEC,WAAW,CAAXA,CAA+B,CAAC,CAAAD,CAAA,CAAAE,eAAA,4BAC5C,IAAI,CAACD,WAAW,CAAGA,CACrB,CAEOE,QAAQA,CAAAH,CAAA,CAEyC,IAFxC,CACdI,aAAa,CAAbA,CACkB,CAAC,CAAAJ,CAAA,CACnB,KAAM,CAAAK,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,CAACF,CAAU,EAAI,CAAC,IAAI,CAACJ,WAAW,CAClC,MAAO,GAAAO,SAAE,IAAM,CAAC,CACjB,KAEK,CAAEC,MAAM,CAANA,CAAO,CAAC,CAAGJ,CAAU,CAKvBK,CAAY,CAAG,CAACD,CAAM,CAACE,MAAM,CAEnC,OAAQ,IAAI,CAACV,WAAW,EACtB,IAAK,CAAAW,kBAAW,CAACC,GAAG,CAClB,MAAO,GAAAL,SAAE,EAACE,CAAY,CAAC,CACzB,IAAK,CAAAE,kBAAW,CAACE,SAAS,CACxB,MAAO,GAAAN,SAAE,EAAC,CAACE,CAAY,CAAC,CAC1B,QACE,GAAAK,4BAAY,EAAC,IAAI,CAACd,WAAW,CACjC,CACF,CACF,CAACe,OAAA,CAAAlB,UAAA,CAAAA,UAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OperatingSystem=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.OperatingSystem=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData");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 OperatingSystem{constructor(a){let{os:b}=a;_defineProperty(this,"operatingSystem",void 0),this.operatingSystem=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.OperatingSystem];if(c){const{operatingSystem:a}=c;return(0,_tsRes.Ok)(a===this.operatingSystem)}return(0,_tsRes.Ok)(!1)}}exports.OperatingSystem=OperatingSystem;
|
|
2
2
|
//# sourceMappingURL=operatingSystem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operatingSystem.js","names":["OperatingSystem","constructor","a","os","_defineProperty","operatingSystem","evaluate","targetingData","operatingSystemData","KameleoonData","Ok","exports"],"sources":["../../../src/targeting/conditions/operatingSystem.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { OperatingSystemType } from 'src/kameleoonData/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class OperatingSystem implements ICondition {\n private operatingSystem?: OperatingSystemType | null;\n\n constructor({ os }: ConditionDataType) {\n this.operatingSystem = os;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const operatingSystemData = targetingData?.[KameleoonData.OperatingSystem];\n\n if (operatingSystemData) {\n const { operatingSystem } = operatingSystemData;\n\n return Ok(operatingSystem === this.operatingSystem);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"operatingSystem.js","names":["OperatingSystem","constructor","a","os","_defineProperty","operatingSystem","evaluate","targetingData","operatingSystemData","KameleoonData","Ok","exports"],"sources":["../../../src/targeting/conditions/operatingSystem.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { OperatingSystemType } from 'src/kameleoonData/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class OperatingSystem implements ICondition {\n private operatingSystem?: OperatingSystemType | null;\n\n constructor({ os }: ConditionDataType) {\n this.operatingSystem = os;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const operatingSystemData = targetingData?.[KameleoonData.OperatingSystem];\n\n if (operatingSystemData) {\n const { operatingSystem } = operatingSystemData;\n\n return Ok(operatingSystem === this.operatingSystem);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"+qBAOO,KAAM,CAAAA,eAAsC,CAGjDC,WAAWA,CAAAC,CAAA,CAA4B,IAA3B,CAAEC,EAAE,CAAFA,CAAsB,CAAC,CAAAD,CAAA,CAAAE,eAAA,gCACnC,IAAI,CAACC,eAAe,CAAGF,CACzB,CAEOG,QAAQA,CAAAJ,CAAA,CAEyC,IAFxC,CACdK,aAAa,CAAbA,CACkB,CAAC,CAAAL,CAAA,CACnB,KAAM,CAAAM,CAAmB,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACT,eAAe,CAAC,CAE1E,GAAIQ,CAAmB,CAAE,CACvB,KAAM,CAAEH,eAAe,CAAfA,CAAgB,CAAC,CAAGG,CAAmB,CAE/C,MAAO,GAAAE,SAAE,EAACL,CAAe,GAAK,IAAI,CAACA,eAAe,CACpD,CAEA,MAAO,GAAAK,SAAE,IAAM,CACjB,CACF,CAACC,OAAA,CAAAX,eAAA,CAAAA,eAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageTitle=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageTitle=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class PageTitle{constructor(a){let{matchType:b,title:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];return c?(0,_tsRes.Ok)(Object.values(c).some(a=>this.checkCondition(a.title))):(0,_tsRes.Ok)(!1)}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Parser.parseRegExp(this.conditionValue).test(a);default:return!1}}}exports.PageTitle=PageTitle;
|
|
2
2
|
//# sourceMappingURL=pageTitle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageTitle.js","names":["PageTitle","constructor","a","matchType","title","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","values","some","data","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","
|
|
1
|
+
{"version":3,"file":"pageTitle.js","names":["PageTitle","constructor","a","matchType","title","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","values","some","data","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Parser","parseRegExp","test","exports"],"sources":["../../../src/targeting/conditions/pageTitle.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Parser } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class PageTitle implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: string | null;\n\n constructor({ matchType, title }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = title;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewData = targetingData?.[KameleoonData.PageView];\n\n if (pageViewData) {\n return Ok(\n Object.values(pageViewData).some((data) => {\n return this.checkCondition(data.title);\n }),\n );\n }\n\n return Ok(false);\n }\n\n private checkCondition(title: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return title.includes(this.conditionValue);\n case MatchType.EXACT:\n return title === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Parser.parseRegExp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AAAA,SAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageUrl=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PageUrl=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class PageUrl{constructor(a){let{matchType:b,url:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];return c?(0,_tsRes.Ok)(Object.keys(c).some(a=>this.checkCondition(a))):(0,_tsRes.Ok)(!1)}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Parser.parseRegExp(this.conditionValue).test(a);default:return!1}}}exports.PageUrl=PageUrl;
|
|
2
2
|
//# sourceMappingURL=pageUrl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pageUrl.js","names":["PageUrl","constructor","a","matchType","url","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","keys","some","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","
|
|
1
|
+
{"version":3,"file":"pageUrl.js","names":["PageUrl","constructor","a","matchType","url","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","Object","keys","some","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Parser","parseRegExp","test","exports"],"sources":["../../../src/targeting/conditions/pageUrl.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Parser } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class PageUrl implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: string | null;\n\n constructor({ matchType, url }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = url;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewData = targetingData?.[KameleoonData.PageView];\n\n if (pageViewData) {\n return Ok(\n Object.keys(pageViewData).some((url) => this.checkCondition(url)),\n );\n }\n\n return Ok(false);\n }\n\n private checkCondition(url: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return url.includes(this.conditionValue);\n case MatchType.EXACT:\n return url === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Parser.parseRegExp(this.conditionValue).test(url);\n default:\n return false;\n }\n }\n}\n"],"mappings":"wuBAOO,KAAM,CAAAA,OAA8B,CAIzCC,WAAWA,CAAAC,CAAA,CAAwC,IAAvC,CAAEC,SAAS,CAATA,CAAS,CAAEC,GAAG,CAAHA,CAAuB,CAAC,CAAAF,CAAA,CAAAG,eAAA,0BAAAA,eAAA,+BAC/C,IAAI,CAACF,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACG,cAAc,CAAGF,CACxB,CAEOG,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdM,aAAa,CAAbA,CACkB,CAAC,CAAAN,CAAA,CACnB,KAAM,CAAAO,CAAY,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,QAAQ,CAAC,CAAC,MAEzD,CAAAF,CAAY,CACP,GAAAG,SAAE,EACPC,MAAM,CAACC,IAAI,CAACL,CAAY,CAAC,CAACM,IAAI,CAAEX,CAAG,EAAK,IAAI,CAACY,cAAc,CAACZ,CAAG,CAAC,CAClE,CAAC,CAGI,GAAAQ,SAAE,IAAM,CACjB,CAEQI,cAAcA,CAACZ,CAAW,CAAW,CAC3C,GAAI,CAAC,IAAI,CAACD,SAAS,EAAI,CAAC,IAAI,CAACG,cAAc,CACzC,SAGF,OAAQ,IAAI,CAACH,SAAS,EACpB,IAAK,CAAAc,gBAAS,CAACC,QAAQ,CACrB,MAAO,CAAAd,CAAG,CAACe,QAAQ,CAAC,IAAI,CAACb,cAAc,CAAC,CAC1C,IAAK,CAAAW,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAhB,CAAG,GAAK,IAAI,CAACE,cAAc,CACpC,IAAK,CAAAW,gBAAS,CAACI,kBAAkB,CAC/B,MAAO,CAAAC,iBAAM,CAACC,WAAW,CAAC,IAAI,CAACjB,cAAc,CAAC,CAACkB,IAAI,CAACpB,CAAG,CAAC,CAC1D,QACE,QACJ,CACF,CACF,CAACqB,OAAA,CAAAzB,OAAA,CAAAA,OAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreviousPage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PreviousPage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class PreviousPage{constructor(a){let{matchType:b,url:c}=a;_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"matchType",void 0),this.conditionValue=c,this.matchType=b}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];if(!c)return(0,_tsRes.Ok)(!1);const d=this.getSecondLatestPageView(Object.values(c));if(!d)return(0,_tsRes.Ok)(!1);const e=d.urlAddress;return(0,_tsRes.Ok)(this.checkCondition(e))}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Parser.parseRegExp(this.conditionValue).test(a);default:return!1}}getSecondLatestPageView(a){if(2>a.length)return;let b,c;return a.forEach(a=>{const d=a.timestamps[a.timestamps.length-1].time;if(!b)return void(b=a);const e=b.timestamps[b.timestamps.length-1].time;if(d>e)return c=b,void(b=a);const f=c?c.timestamps[c.timestamps.length-1].time:0;d>f&&(c=a)}),c}}exports.PreviousPage=PreviousPage;
|
|
2
2
|
//# sourceMappingURL=previousPage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"previousPage.js","names":["PreviousPage","constructor","a","matchType","url","_defineProperty","conditionValue","evaluate","targetingData","pageViewsData","KameleoonData","PageView","Ok","secondLatestPageView","getSecondLatestPageView","Object","values","urlAddress","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","
|
|
1
|
+
{"version":3,"file":"previousPage.js","names":["PreviousPage","constructor","a","matchType","url","_defineProperty","conditionValue","evaluate","targetingData","pageViewsData","KameleoonData","PageView","Ok","secondLatestPageView","getSecondLatestPageView","Object","values","urlAddress","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Parser","parseRegExp","test","length","latestPV","secondPV","forEach","currentPV","currentLatestTs","timestamps","time","latestTs","secondTs","exports"],"sources":["../../../src/targeting/conditions/previousPage.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { Parser } from 'src/utilities';\nimport { KameleoonData, PageViewDataType } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class PreviousPage implements ICondition {\n private conditionValue?: string | null;\n private matchType?: MatchType | null;\n\n constructor({ matchType, url }: ConditionDataType) {\n this.conditionValue = url;\n this.matchType = matchType;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewsData = targetingData?.[KameleoonData.PageView];\n\n if (!pageViewsData) {\n return Ok(false);\n }\n\n // --- Note ---\n // There is more concise way to find previous latest page, but it's less performant,\n // here we only ever check two latest timestamps of page and use one loop\n // The second latest can't be equal to the latest\n const secondLatestPageView = this.getSecondLatestPageView(\n Object.values(pageViewsData),\n );\n\n if (!secondLatestPageView) {\n return Ok(false);\n }\n\n const url = secondLatestPageView.urlAddress;\n\n return Ok(this.checkCondition(url));\n }\n\n private checkCondition(url: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return url.includes(this.conditionValue);\n case MatchType.EXACT:\n return url === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Parser.parseRegExp(this.conditionValue).test(url);\n default:\n return false;\n }\n }\n\n private getSecondLatestPageView(\n pageViewsData: PageViewDataType[],\n ): PageViewDataType | undefined {\n if (pageViewsData.length < 2) {\n return undefined;\n }\n\n // --- Note ---\n // Arguments and variables named with abbreviations for better readability\n // `second` in this context is `second to latest`\n let latestPV: PageViewDataType | undefined;\n let secondPV: PageViewDataType | undefined;\n\n pageViewsData.forEach((currentPV) => {\n const currentLatestTs =\n currentPV.timestamps[currentPV.timestamps.length - 1].time;\n\n // -- Initial check\n if (!latestPV) {\n latestPV = currentPV;\n return;\n }\n\n const latestTs =\n latestPV.timestamps[latestPV!.timestamps.length - 1].time;\n\n // -- Covering a case where latest needs to be updated\n if (currentLatestTs > latestTs) {\n secondPV = latestPV;\n latestPV = currentPV;\n\n return;\n }\n\n // -- Covering a case where only second needs to be updated\n const secondTs = secondPV\n ? secondPV.timestamps[secondPV.timestamps.length - 1].time\n : 0;\n\n // -- Second may need to be updated\n if (currentLatestTs > secondTs) {\n secondPV = currentPV;\n }\n });\n\n return secondPV;\n }\n}\n"],"mappings":"6uBAOO,KAAM,CAAAA,YAAmC,CAI9CC,WAAWA,CAAAC,CAAA,CAAwC,IAAvC,CAAEC,SAAS,CAATA,CAAS,CAAEC,GAAG,CAAHA,CAAuB,CAAC,CAAAF,CAAA,CAAAG,eAAA,+BAAAA,eAAA,0BAC/C,IAAI,CAACC,cAAc,CAAGF,CAAG,CACzB,IAAI,CAACD,SAAS,CAAGA,CACnB,CAEOI,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdM,aAAa,CAAbA,CACkB,CAAC,CAAAN,CAAA,CACnB,KAAM,CAAAO,CAAa,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,QAAQ,CAAC,CAE7D,GAAI,CAACF,CAAa,CAChB,MAAO,GAAAG,SAAE,IAAM,CAAC,CAOlB,KAAM,CAAAC,CAAoB,CAAG,IAAI,CAACC,uBAAuB,CACvDC,MAAM,CAACC,MAAM,CAACP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,CAAQ,CAI5B,MAHA,CAAAN,CAAQ,CAAGD,CAAQ,MACnBA,CAAQ,CAAGG,CAAS,EAMtB,KAAM,CAAAK,CAAQ,CAAGP,CAAQ,CACrBA,CAAQ,CAACI,UAAU,CAACJ,CAAQ,CAACI,UAAU,CAACN,MAAM,CAAG,CAAC,CAAC,CAACO,IAAI,CACxD,CAAC,CAGDF,CAAe,CAAGI,CAAQ,GAC5BP,CAAQ,CAAGE,CAAS,CAExB,CAAC,CAAC,CAEKF,CACT,CACF,CAACQ,OAAA,CAAArC,YAAA,CAAAA,YAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SameDayVisits=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SameDayVisits=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class SameDayVisits{constructor(a){let{matchType:b,visitCount:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.VisitsData];if(!c)return(0,_tsRes.Ok)(!1);let d=0;const e=new Date().setHours(0,0,0,0),{visits:f}=c;return f.forEach(a=>{a>e&&d++}),d+=1,(0,_tsRes.Ok)(this.checkCondition(d))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.EQUAL:return a===this.conditionValue;case _types.MatchType.GREATER:return a>this.conditionValue;case _types.MatchType.LOWER:return a<this.conditionValue;default:return!1}}}exports.SameDayVisits=SameDayVisits;
|
|
2
2
|
//# sourceMappingURL=sameDayVisits.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sameDayVisits.js","names":["SameDayVisits","constructor","a","matchType","visitCount","_defineProperty","conditionValue","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","todayVisits","todayTimestamp","Date","setHours","visits","forEach","timestamp","checkCondition","todayVisitsAmount","MatchType","EQUAL","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/sameDayVisits.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class SameDayVisits implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n\n constructor({ matchType, visitCount }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = visitCount;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n let todayVisits = 0;\n\n const todayTimestamp = new Date().setHours(0, 0, 0, 0);\n const { visits } = visitsData;\n\n visits.forEach((timestamp) => {\n if (timestamp > todayTimestamp) {\n todayVisits++;\n }\n });\n\n // --- Note ---\n // +1 is current visit\n todayVisits += 1;\n\n return Ok(this.checkCondition(todayVisits));\n }\n\n private checkCondition(todayVisitsAmount: number): boolean {\n if (!this.matchType || typeof this.conditionValue !== 'number') {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.EQUAL:\n return todayVisitsAmount === this.conditionValue;\n case MatchType.GREATER:\n return todayVisitsAmount > this.conditionValue;\n case MatchType.LOWER:\n return todayVisitsAmount < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sameDayVisits.js","names":["SameDayVisits","constructor","a","matchType","visitCount","_defineProperty","conditionValue","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","todayVisits","todayTimestamp","Date","setHours","visits","forEach","timestamp","checkCondition","todayVisitsAmount","MatchType","EQUAL","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/sameDayVisits.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class SameDayVisits implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n\n constructor({ matchType, visitCount }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = visitCount;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n let todayVisits = 0;\n\n const todayTimestamp = new Date().setHours(0, 0, 0, 0);\n const { visits } = visitsData;\n\n visits.forEach((timestamp) => {\n if (timestamp > todayTimestamp) {\n todayVisits++;\n }\n });\n\n // --- Note ---\n // +1 is current visit\n todayVisits += 1;\n\n return Ok(this.checkCondition(todayVisits));\n }\n\n private checkCondition(todayVisitsAmount: number): boolean {\n if (!this.matchType || typeof this.conditionValue !== 'number') {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.EQUAL:\n return todayVisitsAmount === this.conditionValue;\n case MatchType.GREATER:\n return todayVisitsAmount > this.conditionValue;\n case MatchType.LOWER:\n return todayVisitsAmount < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"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AAH,CAAiB,CAAG,IAAI,CAACf,cAAc,CAChD,IAAK,CAAAgB,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAJ,CAAiB,CAAG,IAAI,CAACf,cAAc,CAChD,QACE,QACJ,CACF,CACF,CAACoB,OAAA,CAAA1B,aAAA,CAAAA,aAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SdkLanguage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SdkLanguage=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities");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 SdkLanguage{constructor(a){let{sdkLanguage:b,version:c,versionMatchType:d}=a;_defineProperty(this,"sdkLanguage",void 0),_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"versionMatchType",void 0),this.sdkLanguage=b,this.conditionValue=c,this.versionMatchType=d}evaluate(a){let{sdkInfo:b}=a;return this.checkCondition(b)}checkCondition(a){const{type:b,version:c}=a;if(!this.sdkLanguage)return(0,_tsRes.Ok)(!1);if("string"!=typeof this.conditionValue)return(0,_tsRes.Ok)(b===this.sdkLanguage);if(!this.versionMatchType)return(0,_tsRes.Ok)(!1);const d=_utilities.Utilities.compareSemVer({version:c,compareVersion:this.conditionValue,operator:this.versionMatchType});return d.ok?(0,_tsRes.Ok)(b===this.sdkLanguage&&d.data):(0,_tsRes.Err)(d.error)}}exports.SdkLanguage=SdkLanguage;
|
|
2
2
|
//# sourceMappingURL=sdkLanguage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkLanguage.js","names":["SdkLanguage","constructor","a","sdkLanguage","version","versionMatchType","_defineProperty","conditionValue","evaluate","sdkInfo","checkCondition","type","sdkType","Ok","result","Utilities","compareSemVer","compareVersion","operator","ok","data","Err","error","exports"],"sources":["../../../src/targeting/conditions/sdkLanguage.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { SdkLanguageType } from 'src/constants';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities } from 'src/utilities';\nimport { ExternalPackageInfoType } from 'src/types';\nimport { EvaluationDataType, VersionMatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class SdkLanguage implements ICondition {\n private sdkLanguage?: SdkLanguageType | null;\n private conditionValue?: string | null;\n private versionMatchType?: VersionMatchType | null;\n\n constructor({ sdkLanguage, version, versionMatchType }: ConditionDataType) {\n this.sdkLanguage = sdkLanguage;\n this.conditionValue = version;\n this.versionMatchType = versionMatchType;\n }\n\n public evaluate({\n sdkInfo,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n return this.checkCondition(sdkInfo);\n }\n\n private checkCondition(\n sdkInfo: ExternalPackageInfoType,\n ): Result<boolean, KameleoonError> {\n const { type: sdkType, version } = sdkInfo;\n\n if (!this.sdkLanguage) {\n return Ok(false);\n }\n\n if (typeof this.conditionValue !== 'string') {\n return Ok(sdkType === this.sdkLanguage);\n }\n\n if (!this.versionMatchType) {\n return Ok(false);\n }\n\n const result = Utilities.compareSemVer({\n version,\n compareVersion: this.conditionValue,\n operator: this.versionMatchType,\n });\n\n if (!result.ok) {\n return Err(result.error);\n }\n\n return Ok(sdkType === this.sdkLanguage && result.data);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sdkLanguage.js","names":["SdkLanguage","constructor","a","sdkLanguage","version","versionMatchType","_defineProperty","conditionValue","evaluate","sdkInfo","checkCondition","type","sdkType","Ok","result","Utilities","compareSemVer","compareVersion","operator","ok","data","Err","error","exports"],"sources":["../../../src/targeting/conditions/sdkLanguage.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { SdkLanguageType } from 'src/constants';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Utilities } from 'src/utilities';\nimport { ExternalPackageInfoType } from 'src/types';\nimport { EvaluationDataType, VersionMatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class SdkLanguage implements ICondition {\n private sdkLanguage?: SdkLanguageType | null;\n private conditionValue?: string | null;\n private versionMatchType?: VersionMatchType | null;\n\n constructor({ sdkLanguage, version, versionMatchType }: ConditionDataType) {\n this.sdkLanguage = sdkLanguage;\n this.conditionValue = version;\n this.versionMatchType = versionMatchType;\n }\n\n public evaluate({\n sdkInfo,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n return this.checkCondition(sdkInfo);\n }\n\n private checkCondition(\n sdkInfo: ExternalPackageInfoType,\n ): Result<boolean, KameleoonError> {\n const { type: sdkType, version } = sdkInfo;\n\n if (!this.sdkLanguage) {\n return Ok(false);\n }\n\n if (typeof this.conditionValue !== 'string') {\n return Ok(sdkType === this.sdkLanguage);\n }\n\n if (!this.versionMatchType) {\n return Ok(false);\n }\n\n const result = Utilities.compareSemVer({\n version,\n compareVersion: this.conditionValue,\n operator: this.versionMatchType,\n });\n\n if (!result.ok) {\n return Err(result.error);\n }\n\n return Ok(sdkType === this.sdkLanguage && result.data);\n }\n}\n"],"mappings":"mqBAQO,KAAM,CAAAA,WAAkC,CAK7CC,WAAWA,CAAAC,CAAA,CAAgE,IAA/D,CAAEC,WAAW,CAAXA,CAAW,CAAEC,OAAO,CAAPA,CAAO,CAAEC,gBAAgB,CAAhBA,CAAoC,CAAC,CAAAH,CAAA,CAAAI,eAAA,4BAAAA,eAAA,+BAAAA,eAAA,iCACvE,IAAI,CAACH,WAAW,CAAGA,CAAW,CAC9B,IAAI,CAACI,cAAc,CAAGH,CAAO,CAC7B,IAAI,CAACC,gBAAgB,CAAGA,CAC1B,CAEOG,QAAQA,CAAAN,CAAA,CAEyC,IAFxC,CACdO,OAAO,CAAPA,CACkB,CAAC,CAAAP,CAAA,CACnB,MAAO,KAAI,CAACQ,cAAc,CAACD,CAAO,CACpC,CAEQC,cAAcA,CACpBD,CAAgC,CACC,CACjC,KAAM,CAAEE,IAAI,CAAEC,CAAO,CAAER,OAAO,CAAPA,CAAQ,CAAC,CAAGK,CAAO,CAE1C,GAAI,CAAC,IAAI,CAACN,WAAW,CACnB,MAAO,GAAAU,SAAE,IAAM,CAAC,CAGlB,GAAmC,QAAQ,EAAvC,MAAO,KAAI,CAACN,cAA2B,CACzC,MAAO,GAAAM,SAAE,EAACD,CAAO,GAAK,IAAI,CAACT,WAAW,CAAC,CAGzC,GAAI,CAAC,IAAI,CAACE,gBAAgB,CACxB,MAAO,GAAAQ,SAAE,IAAM,CAAC,CAGlB,KAAM,CAAAC,CAAM,CAAGC,oBAAS,CAACC,aAAa,CAAC,CACrCZ,OAAO,CAAPA,CAAO,CACPa,cAAc,CAAE,IAAI,CAACV,cAAc,CACnCW,QAAQ,CAAE,IAAI,CAACb,gBACjB,CAAC,CAAC,CAAC,MAEE,CAAAS,CAAM,CAACK,EAAE,CAIP,GAAAN,SAAE,EAACD,CAAO,GAAK,IAAI,CAACT,WAAW,EAAIW,CAAM,CAACM,IAAI,CAAC,CAH7C,GAAAC,UAAG,EAACP,CAAM,CAACQ,KAAK,CAI3B,CACF,CAACC,OAAA,CAAAvB,WAAA,CAAAA,WAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Segment=void 0;var _tsRes=require("ts-res"),_tree=require("../tree");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Segment=void 0;var _tsRes=require("ts-res"),_tree=require("../tree");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 Segment{constructor(a){let{segmentId:b}=a;_defineProperty(this,"segmentId",void 0),this.segmentId=b}evaluate(a){const{segments:b,trees:c}=a;if(!this.segmentId)return(0,_tsRes.Ok)(!1);const d=null===b||void 0===b?void 0:b.get(this.segmentId.toString());if(!d)return(0,_tsRes.Ok)(!1);const e=null===c||void 0===c?void 0:c.get(this.segmentId.toString());return e?e.evaluate(a):new _tree.Tree(d).evaluate(a)}}exports.Segment=Segment;
|
|
2
2
|
//# sourceMappingURL=segment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segment.js","names":["Segment","constructor","a","segmentId","_defineProperty","evaluate","evaluationData","segments","trees","Ok","segment","get","toString","tree","Tree","exports"],"sources":["../../../src/targeting/conditions/segment.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\nimport { Tree } from 'src/targeting/tree';\n\nexport class Segment implements ICondition {\n segmentId?: number | null;\n\n constructor({ segmentId }: ConditionDataType) {\n this.segmentId = segmentId;\n }\n\n public evaluate(\n evaluationData: EvaluationDataType,\n ): Result<boolean, KameleoonError> {\n const { segments, trees } = evaluationData;\n\n if (!this.segmentId) {\n return Ok(false);\n }\n\n const segment = segments?.get(this.segmentId.toString());\n\n if (!segment) {\n return Ok(false);\n }\n\n const tree = trees?.get(this.segmentId.toString());\n\n if (tree) {\n return tree.evaluate(evaluationData);\n }\n\n return new Tree(segment).evaluate(evaluationData);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"segment.js","names":["Segment","constructor","a","segmentId","_defineProperty","evaluate","evaluationData","segments","trees","Ok","segment","get","toString","tree","Tree","exports"],"sources":["../../../src/targeting/conditions/segment.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\nimport { Tree } from 'src/targeting/tree';\n\nexport class Segment implements ICondition {\n segmentId?: number | null;\n\n constructor({ segmentId }: ConditionDataType) {\n this.segmentId = segmentId;\n }\n\n public evaluate(\n evaluationData: EvaluationDataType,\n ): Result<boolean, KameleoonError> {\n const { segments, trees } = evaluationData;\n\n if (!this.segmentId) {\n return Ok(false);\n }\n\n const segment = segments?.get(this.segmentId.toString());\n\n if (!segment) {\n return Ok(false);\n }\n\n const tree = trees?.get(this.segmentId.toString());\n\n if (tree) {\n return tree.evaluate(evaluationData);\n }\n\n return new Tree(segment).evaluate(evaluationData);\n }\n}\n"],"mappings":"kpBAMO,KAAM,CAAAA,OAA8B,CAGzCC,WAAWA,CAAAC,CAAA,CAAmC,IAAlC,CAAEC,SAAS,CAATA,CAA6B,CAAC,CAAAD,CAAA,CAAAE,eAAA,0BAC1C,IAAI,CAACD,SAAS,CAAGA,CACnB,CAEOE,QAAQA,CACbC,CAAkC,CACD,CACjC,KAAM,CAAEC,QAAQ,CAARA,CAAQ,CAAEC,KAAK,CAALA,CAAM,CAAC,CAAGF,CAAc,CAE1C,GAAI,CAAC,IAAI,CAACH,SAAS,CACjB,MAAO,GAAAM,SAAE,IAAM,CAAC,CAGlB,KAAM,CAAAC,CAAO,QAAGH,CAAQ,WAARA,CAAQ,QAARA,CAAQ,CAAEI,GAAG,CAAC,IAAI,CAACR,SAAS,CAACS,QAAQ,CAAC,CAAC,CAAC,CAExD,GAAI,CAACF,CAAO,CACV,MAAO,GAAAD,SAAE,IAAM,CAAC,CAGlB,KAAM,CAAAI,CAAI,QAAGL,CAAK,WAALA,CAAK,QAALA,CAAK,CAAEG,GAAG,CAAC,IAAI,CAACR,SAAS,CAACS,QAAQ,CAAC,CAAC,CAAC,CAAC,MAE/C,CAAAC,CAAI,CACCA,CAAI,CAACR,QAAQ,CAACC,CAAc,CAAC,CAG/B,GAAI,CAAAQ,UAAI,CAACJ,CAAO,CAAC,CAACL,QAAQ,CAACC,CAAc,CAClD,CACF,CAACS,OAAA,CAAAf,OAAA,CAAAA,OAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var _tsRes=require("ts-res");Object.defineProperty(exports,"__esModule",{value:!0}),exports.TargetFeatureFlag=void 0;function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";var _tsRes=require("ts-res");Object.defineProperty(exports,"__esModule",{value:!0}),exports.TargetFeatureFlag=void 0;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 TargetFeatureFlag{constructor(a){let{featureFlagId:b,variationKey:c,ruleId:d}=a;_defineProperty(this,"featureId",void 0),_defineProperty(this,"ruleId",void 0),_defineProperty(this,"variationKey",void 0),this.featureId=b,this.ruleId=d,this.variationKey=c}evaluate(a){let{variationData:b,ruleMap:c}=a;if(!this.featureId||!c)return(0,_tsRes.Ok)(!1);if(this.featureId&&!this.ruleId&&!this.variationKey){for(const[_,a]of c){var d;const{featureId:c,experimentId:e}=a;if(c===this.featureId&&"number"==typeof(null===(d=b[e])||void 0===d?void 0:d.variationId))return(0,_tsRes.Ok)(!0)}return(0,_tsRes.Ok)(!1)}if(this.featureId&&this.ruleId){var e;const a=c.get(this.ruleId);if(!a)return(0,_tsRes.Ok)(!1);const{experimentId:d,variations:g}=a;if(this.variationKey){var f;const a=g.get(this.variationKey);return(0,_tsRes.Ok)(!!a&&(null===(f=b[d])||void 0===f?void 0:f.variationId)===a)}return(0,_tsRes.Ok)(null!==(e=b[a.experimentId])&&void 0!==e&&e.variationId)}if(this.featureId&&!this.ruleId&&this.variationKey)for(const[_,a]of c){const{featureId:c,experimentId:d,variations:e}=a;if(c===this.featureId&&e.has(this.variationKey)){var g;const a=e.get(this.variationKey);return(0,_tsRes.Ok)(!!a&&(null===(g=b[d])||void 0===g?void 0:g.variationId)===a)}}return(0,_tsRes.Ok)(!1)}}exports.TargetFeatureFlag=TargetFeatureFlag;
|
|
2
2
|
//# sourceMappingURL=targetFeatureFlag.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"targetFeatureFlag.js","names":["_tsRes","require","Object","defineProperty","exports","value","TargetFeatureFlag","_defineProperty","a","b","c","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","d","call","TypeError","String","Number","constructor","featureFlagId","variationKey","ruleId","featureId","evaluate","variationData","ruleMap","Ok","_","rule","experimentId","variationId","e","get","variations","f","has","g"],"sources":["../../../src/targeting/conditions/targetFeatureFlag.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class TargetFeatureFlag implements ICondition {\n private featureId?: number | null;\n private ruleId?: number | null;\n private variationKey?: string | null;\n\n constructor({ featureFlagId, variationKey, ruleId }: ConditionDataType) {\n this.featureId = featureFlagId;\n this.ruleId = ruleId;\n this.variationKey = variationKey;\n }\n\n public evaluate({\n variationData,\n ruleMap,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n if (!this.featureId || !ruleMap) {\n return Ok(false);\n }\n\n // -- Visitor took part in any experiment of the feature flag\n // with any variation\n if (this.featureId && !this.ruleId && !this.variationKey) {\n for (const [_, rule] of ruleMap) {\n const { featureId, experimentId } = rule;\n\n if (\n featureId === this.featureId &&\n typeof variationData[experimentId]?.variationId === 'number'\n ) {\n return Ok(true);\n }\n }\n\n return Ok(false);\n }\n\n // -- Visitor took part in certain experiment of the feature flag\n // with any/exact variation\n if (this.featureId && this.ruleId) {\n const rule = ruleMap.get(this.ruleId);\n\n if (!rule) {\n return Ok(false);\n }\n\n const { experimentId, variations } = rule;\n\n if (this.variationKey) {\n const variationId = variations.get(this.variationKey);\n\n return Ok(\n Boolean(variationId) &&\n variationData[experimentId]?.variationId === variationId,\n );\n }\n\n return Ok(Boolean(variationData[rule.experimentId]?.variationId));\n }\n\n // -- Visitor took part in any experiment of the feature flag\n // with certain variation\n if (this.featureId && !this.ruleId && this.variationKey) {\n for (const [_, rule] of ruleMap) {\n const { featureId, experimentId, variations } = rule;\n\n if (featureId === this.featureId && variations.has(this.variationKey)) {\n const variationId = variations.get(this.variationKey);\n\n return Ok(\n Boolean(variationId) &&\n variationData[experimentId]?.variationId === variationId,\n );\n }\n }\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"aAAA,IAAAA,MAAA,CAAAC,OAAA,WAAoCC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,iBAAA,iBAAAC,gBAAAC,CAAA,CAAAC,CAAA,CAAAC,CAAA,SAAAD,CAAA,CAAAE,cAAA,CAAAF,CAAA,
|
|
1
|
+
{"version":3,"file":"targetFeatureFlag.js","names":["_tsRes","require","Object","defineProperty","exports","value","TargetFeatureFlag","_defineProperty","a","b","c","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","Symbol","toPrimitive","d","call","TypeError","String","Number","constructor","featureFlagId","variationKey","ruleId","featureId","evaluate","variationData","ruleMap","Ok","_","rule","experimentId","variationId","e","get","variations","f","has","g"],"sources":["../../../src/targeting/conditions/targetFeatureFlag.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class TargetFeatureFlag implements ICondition {\n private featureId?: number | null;\n private ruleId?: number | null;\n private variationKey?: string | null;\n\n constructor({ featureFlagId, variationKey, ruleId }: ConditionDataType) {\n this.featureId = featureFlagId;\n this.ruleId = ruleId;\n this.variationKey = variationKey;\n }\n\n public evaluate({\n variationData,\n ruleMap,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n if (!this.featureId || !ruleMap) {\n return Ok(false);\n }\n\n // -- Visitor took part in any experiment of the feature flag\n // with any variation\n if (this.featureId && !this.ruleId && !this.variationKey) {\n for (const [_, rule] of ruleMap) {\n const { featureId, experimentId } = rule;\n\n if (\n featureId === this.featureId &&\n typeof variationData[experimentId]?.variationId === 'number'\n ) {\n return Ok(true);\n }\n }\n\n return Ok(false);\n }\n\n // -- Visitor took part in certain experiment of the feature flag\n // with any/exact variation\n if (this.featureId && this.ruleId) {\n const rule = ruleMap.get(this.ruleId);\n\n if (!rule) {\n return Ok(false);\n }\n\n const { experimentId, variations } = rule;\n\n if (this.variationKey) {\n const variationId = variations.get(this.variationKey);\n\n return Ok(\n Boolean(variationId) &&\n variationData[experimentId]?.variationId === variationId,\n );\n }\n\n return Ok(Boolean(variationData[rule.experimentId]?.variationId));\n }\n\n // -- Visitor took part in any experiment of the feature flag\n // with certain variation\n if (this.featureId && !this.ruleId && this.variationKey) {\n for (const [_, rule] of ruleMap) {\n const { featureId, experimentId, variations } = rule;\n\n if (featureId === this.featureId && variations.has(this.variationKey)) {\n const variationId = variations.get(this.variationKey);\n\n return Ok(\n Boolean(variationId) &&\n variationData[experimentId]?.variationId === variationId,\n );\n }\n }\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"aAAA,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CAASP,CAAa,CAACI,CAAI,CAACC,YAAY,CAAC,YAAAE,CAAA,EAAhCA,CAAA,CAAkCD,WAAY,CAClE,CAIA,GAAI,IAAI,CAACR,SAAS,EAAI,CAAC,IAAI,CAACD,MAAM,EAAI,IAAI,CAACD,YAAY,CACrD,IAAK,KAAM,CAACO,CAAC,CAAEC,CAAI,CAAC,EAAI,CAAAH,CAAO,CAAE,CAC/B,KAAM,CAAEH,SAAS,CAATA,CAAS,CAAEO,YAAY,CAAZA,CAAY,CAAEI,UAAU,CAAVA,CAAW,CAAC,CAAGL,CAAI,CAEpD,GAAIN,CAAS,GAAK,IAAI,CAACA,SAAS,EAAIW,CAAU,CAACE,GAAG,CAAC,IAAI,CAACf,YAAY,CAAC,CAAE,KAAAgB,CAAA,CACrE,KAAM,CAAAN,CAAW,CAAGG,CAAU,CAACD,GAAG,CAAC,IAAI,CAACZ,YAAY,CAAC,CAErD,MAAO,GAAAM,SAAE,EACP,EAAQI,CAAW,EACjB,SAAAM,CAAA,CAAAZ,CAAa,CAACK,CAAY,CAAC,YAAAO,CAAA,QAA3BA,CAAA,CAA6BN,WAAW,IAAKA,CACjD,CACF,CACF,CAGF,MAAO,GAAAJ,SAAE,IAAM,CACjB,CACF,CAAC3B,OAAA,CAAAE,iBAAA,CAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/targeting/conditions/types.ts"],"sourcesContent":["import { Result } from 'ts-res';\nimport { SdkLanguageType } from 'src/constants';\nimport { BrowserType, DeviceType } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport {\n EvaluationDataType,\n MatchType,\n MatchTypeTest,\n MatchTypeVariation,\n NameMatchType,\n TargetingType,\n ValueMatchType,\n VersionMatchType,\n VisitorType,\n} from 'src/targeting/types';\nimport { OperatingSystemType } from 'src/kameleoonData/types';\nimport { TimeUnit } from 'src/utilities';\n\nexport interface ICondition {\n evaluate: (data: EvaluationDataType) => Result<boolean, KameleoonError>;\n}\n\nexport type ConditionType = ICondition;\n\nexport type ConditionDataType = {\n id: number;\n targetingType: TargetingType;\n isInclude: boolean | null;\n weight: number;\n customDataIndex?: string | null;\n pageCount?: number | null;\n value?: string | null;\n valueMatchType?: ValueMatchType | null;\n experiment?: number | null;\n variation?: number | null;\n visitCount?: number | null;\n variationKey?: string | null;\n featureFlagId?: number | null;\n ruleId?: number | null;\n variationMatchType?: MatchTypeVariation | null;\n testMatchType?: MatchTypeTest | null;\n matchType?: MatchType | null;\n device?: DeviceType | null;\n browser?: BrowserType | null;\n os?: OperatingSystemType | null;\n name?: string | null;\n nameMatchType?: NameMatchType | null;\n country?: string | null;\n region?: string | null;\n city?: string | null;\n segmentId?: number | null;\n version?: string | null;\n versionMatchType?: VersionMatchType | null;\n visitorType?: VisitorType | null;\n count?: number | null;\n unitOfTime?: TimeUnit | null;\n title?: string | null;\n url?: string | null;\n goalId?: number | null;\n sdkLanguage?: SdkLanguageType | null;\n visitorCode?: string | null;\n range?: number[] | null;\n lowerBound?: number;\n upperBound?: number;\n keyMomentId?: number;\n};\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/targeting/conditions/types.ts"],"sourcesContent":["import { Result } from 'ts-res';\nimport { SdkLanguageType } from 'src/constants';\nimport { BrowserType, DeviceType } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport {\n EvaluationDataType,\n MatchType,\n MatchTypeTest,\n MatchTypeVariation,\n NameMatchType,\n TargetingType,\n ValueMatchType,\n VersionMatchType,\n VisitorType,\n} from 'src/targeting/types';\nimport { OperatingSystemType } from 'src/kameleoonData/types';\nimport { TimeUnit } from 'src/utilities';\n\nexport interface ICondition {\n evaluate: (data: EvaluationDataType) => Result<boolean, KameleoonError>;\n}\n\nexport type ConditionType = ICondition;\n\nexport type ConditionDataType = {\n id: number;\n targetingType: TargetingType;\n isInclude: boolean | null;\n weight: number;\n customDataIndex?: string | null;\n pageCount?: number | null;\n value?: string | null;\n valueMatchType?: ValueMatchType | null;\n experiment?: number | null;\n variation?: number | null;\n visitCount?: number | null;\n variationKey?: string | null;\n featureFlagId?: number | null;\n ruleId?: number | null;\n variationMatchType?: MatchTypeVariation | null;\n testMatchType?: MatchTypeTest | null;\n matchType?: MatchType | null;\n device?: DeviceType | null;\n browser?: BrowserType | null;\n os?: OperatingSystemType | null;\n name?: string | null;\n nameMatchType?: NameMatchType | null;\n country?: string | null;\n region?: string | null;\n city?: string | null;\n segmentId?: number | null;\n version?: string | null;\n versionMatchType?: VersionMatchType | null;\n visitorType?: VisitorType | null;\n count?: number | null;\n unitOfTime?: TimeUnit | null;\n title?: string | null;\n url?: string | null;\n goalId?: number | null;\n sdkLanguage?: SdkLanguageType | null;\n visitorCode?: string | null;\n range?: number[] | null;\n lowerBound?: number;\n upperBound?: number;\n keyMomentId?: number;\n};\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitedPages=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitedPages=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class VisitedPages{constructor(a){let{matchType:b,pageCount:c}=a;_defineProperty(this,"conditionValue",void 0),_defineProperty(this,"matchType",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.PageView];if(!c)return(0,_tsRes.Ok)(!1);let d=0;return Object.values(c).forEach(a=>{d+=a.timestamps.length}),(0,_tsRes.Ok)(this.checkCondition(d))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.EQUAL:return a===this.conditionValue;case _types.MatchType.GREATER:return a>this.conditionValue;case _types.MatchType.LOWER:return a<this.conditionValue;default:return!1}}}exports.VisitedPages=VisitedPages;
|
|
2
2
|
//# sourceMappingURL=visitedPages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visitedPages.js","names":["VisitedPages","constructor","a","matchType","pageCount","_defineProperty","conditionValue","evaluate","targetingData","pageViewsData","KameleoonData","PageView","Ok","pagesAmount","Object","values","forEach","pageView","timestamps","length","checkCondition","MatchType","EQUAL","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/visitedPages.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData, PageViewDataType } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class VisitedPages implements ICondition {\n private conditionValue?: number | null;\n private matchType?: MatchType | null;\n\n constructor({ matchType, pageCount }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = pageCount;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewsData = targetingData?.[KameleoonData.PageView];\n\n if (!pageViewsData) {\n return Ok(false);\n }\n\n let pagesAmount = 0;\n\n Object.values(pageViewsData).forEach((pageView: PageViewDataType) => {\n pagesAmount += pageView.timestamps.length;\n });\n\n return Ok(this.checkCondition(pagesAmount));\n }\n\n private checkCondition(pagesAmount: number): boolean {\n if (!this.matchType || typeof this.conditionValue !== 'number') {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.EQUAL:\n return pagesAmount === this.conditionValue;\n case MatchType.GREATER:\n return pagesAmount > this.conditionValue;\n case MatchType.LOWER:\n return pagesAmount < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"visitedPages.js","names":["VisitedPages","constructor","a","matchType","pageCount","_defineProperty","conditionValue","evaluate","targetingData","pageViewsData","KameleoonData","PageView","Ok","pagesAmount","Object","values","forEach","pageView","timestamps","length","checkCondition","MatchType","EQUAL","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/visitedPages.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData, PageViewDataType } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class VisitedPages implements ICondition {\n private conditionValue?: number | null;\n private matchType?: MatchType | null;\n\n constructor({ matchType, pageCount }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = pageCount;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const pageViewsData = targetingData?.[KameleoonData.PageView];\n\n if (!pageViewsData) {\n return Ok(false);\n }\n\n let pagesAmount = 0;\n\n Object.values(pageViewsData).forEach((pageView: PageViewDataType) => {\n pagesAmount += pageView.timestamps.length;\n });\n\n return Ok(this.checkCondition(pagesAmount));\n }\n\n private checkCondition(pagesAmount: number): boolean {\n if (!this.matchType || typeof this.conditionValue !== 'number') {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.EQUAL:\n return pagesAmount === this.conditionValue;\n case MatchType.GREATER:\n return pagesAmount > this.conditionValue;\n case MatchType.LOWER:\n return pagesAmount < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"usBAMO,KAAM,CAAAA,YAAmC,CAI9CC,W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,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorCode=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.VisitorCode=void 0;var _tsRes=require("ts-res"),_utilities=require("../../utilities"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class VisitorCode{constructor(a){let{visitorCode:b,matchType:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=c,this.conditionValue=b}evaluate(a){let{visitorCode:b}=a;return(0,_tsRes.Ok)(this.checkCondition(b))}checkCondition(a){if(!this.matchType||!this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.CONTAINS:return a.includes(this.conditionValue);case _types.MatchType.EXACT:return a===this.conditionValue;case _types.MatchType.REGULAR_EXPRESSION:return _utilities.Parser.parseRegExp(this.conditionValue).test(a);default:return!1}}}exports.VisitorCode=VisitorCode;
|
|
2
2
|
//# sourceMappingURL=visitorCode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visitorCode.js","names":["VisitorCode","constructor","a","visitorCode","matchType","_defineProperty","conditionValue","evaluate","Ok","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","
|
|
1
|
+
{"version":3,"file":"visitorCode.js","names":["VisitorCode","constructor","a","visitorCode","matchType","_defineProperty","conditionValue","evaluate","Ok","checkCondition","MatchType","CONTAINS","includes","EXACT","REGULAR_EXPRESSION","Parser","parseRegExp","test","exports"],"sources":["../../../src/targeting/conditions/visitorCode.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { Parser } from 'src/utilities';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class VisitorCode implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: string | null;\n\n constructor({ visitorCode, matchType }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = visitorCode;\n }\n\n public evaluate({\n visitorCode,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n return Ok(this.checkCondition(visitorCode));\n }\n\n private checkCondition(visitorCode: string): boolean {\n if (!this.matchType || !this.conditionValue) {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.CONTAINS:\n return visitorCode.includes(this.conditionValue);\n case MatchType.EXACT:\n return visitorCode === this.conditionValue;\n case MatchType.REGULAR_EXPRESSION:\n return Parser.parseRegExp(this.conditionValue).test(visitorCode);\n default:\n return false;\n }\n }\n}\n"],"mappings":"8rBAMO,KAAM,CAAAA,WAAkC,CAI7CC,WAAWA,CAAAC,CAAA,CAAgD,IAA/C,CAAEC,WAAW,CAAXA,CAAW,CAAEC,SAAS,CAATA,CAA6B,CAAC,CAAAF,CAAA,CAAAG,eAAA,0BAAAA,eAAA,+BACvD,IAAI,CAACD,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACE,cAAc,CAAGH,CACxB,CAEOI,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdC,WAAW,CAAXA,CACkB,CAAC,CAAAD,CAAA,CACnB,MAAO,GAAAM,SAAE,EAAC,IAAI,CAACC,cAAc,CAACN,CAAW,CAAC,CAC5C,CAEQM,cAAcA,CAACN,CAAmB,CAAW,CACnD,GAAI,CAAC,IAAI,CAACC,SAAS,EAAI,CAAC,IAAI,CAACE,cAAc,CACzC,SAGF,OAAQ,IAAI,CAACF,SAAS,EACpB,IAAK,CAAAM,gBAAS,CAACC,QAAQ,CACrB,MAAO,CAAAR,CAAW,CAACS,QAAQ,CAAC,IAAI,CAACN,cAAc,CAAC,CAClD,IAAK,CAAAI,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAV,CAAW,GAAK,IAAI,CAACG,cAAc,CAC5C,IAAK,CAAAI,gBAAS,CAACI,kBAAkB,CAC/B,MAAO,CAAAC,iBAAM,CAACC,WAAW,CAAC,IAAI,CAACV,cAAc,CAAC,CAACW,IAAI,CAACd,CAAW,CAAC,CAClE,QACE,QACJ,CACF,CACF,CAACe,OAAA,CAAAlB,WAAA,CAAAA,WAAA","ignoreList":[]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Visits=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Visits=void 0;var _tsRes=require("ts-res"),_kameleoonData=require("../../kameleoonData"),_types=require("../types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Visits{constructor(a){let{matchType:b,visitCount:c}=a;_defineProperty(this,"matchType",void 0),_defineProperty(this,"conditionValue",void 0),this.matchType=b,this.conditionValue=c}evaluate(a){let{targetingData:b}=a;const c=null===b||void 0===b?void 0:b[_kameleoonData.KameleoonData.VisitsData];if(!c)return(0,_tsRes.Ok)(!1);const d=c.visits.length+1;return(0,_tsRes.Ok)(this.checkCondition(d))}checkCondition(a){if(!this.matchType||"number"!=typeof this.conditionValue)return!1;switch(this.matchType){case _types.MatchType.EQUAL:return a===this.conditionValue;case _types.MatchType.GREATER:return a>this.conditionValue;case _types.MatchType.LOWER:return a<this.conditionValue;default:return!1}}}exports.Visits=Visits;
|
|
2
2
|
//# sourceMappingURL=visits.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visits.js","names":["Visits","constructor","a","matchType","visitCount","_defineProperty","conditionValue","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","visits","length","checkCondition","visitsAmount","MatchType","EQUAL","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/visits.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class Visits implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n\n constructor({ matchType, visitCount }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = visitCount;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n // --- Note ---\n // +1 is current visit\n const visits = visitsData.visits.length + 1;\n\n return Ok(this.checkCondition(visits));\n }\n\n private checkCondition(visitsAmount: number): boolean {\n if (!this.matchType || typeof this.conditionValue !== 'number') {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.EQUAL:\n return visitsAmount === this.conditionValue;\n case MatchType.GREATER:\n return visitsAmount > this.conditionValue;\n case MatchType.LOWER:\n return visitsAmount < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"visits.js","names":["Visits","constructor","a","matchType","visitCount","_defineProperty","conditionValue","evaluate","targetingData","visitsData","KameleoonData","VisitsData","Ok","visits","length","checkCondition","visitsAmount","MatchType","EQUAL","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/visits.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType, MatchType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class Visits implements ICondition {\n private matchType?: MatchType | null;\n private conditionValue?: number | null;\n\n constructor({ matchType, visitCount }: ConditionDataType) {\n this.matchType = matchType;\n this.conditionValue = visitCount;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const visitsData = targetingData?.[KameleoonData.VisitsData];\n\n if (!visitsData) {\n return Ok(false);\n }\n\n // --- Note ---\n // +1 is current visit\n const visits = visitsData.visits.length + 1;\n\n return Ok(this.checkCondition(visits));\n }\n\n private checkCondition(visitsAmount: number): boolean {\n if (!this.matchType || typeof this.conditionValue !== 'number') {\n return false;\n }\n\n switch (this.matchType) {\n case MatchType.EQUAL:\n return visitsAmount === this.conditionValue;\n case MatchType.GREATER:\n return visitsAmount > this.conditionValue;\n case MatchType.LOWER:\n return visitsAmount < this.conditionValue;\n default:\n return false;\n }\n }\n}\n"],"mappings":"isBAMO,KAAM,CAAAA,MAA6B,CAIxCC,WAAWA,CAAAC,CAAA,CAA+C,IAA9C,CAAEC,SAAS,CAATA,CAAS,CAAEC,UAAU,CAAVA,CAA8B,CAAC,CAAAF,CAAA,CAAAG,eAAA,0BAAAA,eAAA,+BACtD,IAAI,CAACF,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACG,cAAc,CAAGF,CACxB,CAEOG,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdM,aAAa,CAAbA,CACkB,CAAC,CAAAN,CAAA,CACnB,KAAM,CAAAO,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,CAACF,CAAU,CACb,MAAO,GAAAG,SAAE,IAAM,CAAC,CAKlB,KAAM,CAAAC,CAAM,CAAGJ,CAAU,CAACI,MAAM,CAACC,MAAM,CAAG,CAAC,CAE3C,MAAO,GAAAF,SAAE,EAAC,IAAI,CAACG,cAAc,CAACF,CAAM,CAAC,CACvC,CAEQE,cAAcA,CAACC,CAAoB,CAAW,CACpD,GAAI,CAAC,IAAI,CAACb,SAAS,EAAmC,QAAQ,EAAvC,MAAO,KAAI,CAACG,cAA2B,CAC5D,SAGF,OAAQ,IAAI,CAACH,SAAS,EACpB,IAAK,CAAAc,gBAAS,CAACC,KAAK,CAClB,MAAO,CAAAF,CAAY,GAAK,IAAI,CAACV,cAAc,CAC7C,IAAK,CAAAW,gBAAS,CAACE,OAAO,CACpB,MAAO,CAAAH,CAAY,CAAG,IAAI,CAACV,cAAc,CAC3C,IAAK,CAAAW,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAJ,CAAY,CAAG,IAAI,CAACV,cAAc,CAC3C,QACE,QACJ,CACF,CACF,CAACe,OAAA,CAAArB,MAAA,CAAAA,MAAA","ignoreList":[]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Tree } from './tree';
|
|
2
|
-
export { Operator, TargetingType, SegmentType, TargetingDataType, EvaluationDataType, ValueMatchType, MatchTypeVariation, MatchType, VersionMatchType, VisitorReference,
|
|
2
|
+
export { Operator, TargetingType, SegmentType, TargetingDataType, EvaluationDataType, ValueMatchType, MatchTypeVariation, DereferencedTargetingDataType, MatchType, VersionMatchType, VisitorReference, } from './types';
|
|
3
3
|
export { CustomData, ExclusiveCampaign, Browser, PageUrl, PageTitle, Conversion, VisitorCode, SdkLanguage, Device, PreviousPage, VisitedPages, ConditionFactory, TargetFeatureFlag, Cookie, GeolocationCondition, OperatingSystem, Segment, FirstVisit, LastVisit, SameDayVisits, Visits, ConversionLikelihood, NewVisitor, } from './conditions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/targeting/index.ts"],"sourcesContent":["export { Tree } from './tree';\nexport {\n Operator,\n TargetingType,\n SegmentType,\n TargetingDataType,\n EvaluationDataType,\n ValueMatchType,\n MatchTypeVariation,\n MatchType,\n VersionMatchType,\n VisitorReference,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/targeting/index.ts"],"sourcesContent":["export { Tree } from './tree';\nexport {\n Operator,\n TargetingType,\n SegmentType,\n TargetingDataType,\n EvaluationDataType,\n ValueMatchType,\n MatchTypeVariation,\n DereferencedTargetingDataType,\n MatchType,\n VersionMatchType,\n VisitorReference,\n} from './types';\nexport {\n CustomData,\n ExclusiveCampaign,\n Browser,\n PageUrl,\n PageTitle,\n Conversion,\n VisitorCode,\n SdkLanguage,\n Device,\n PreviousPage,\n VisitedPages,\n ConditionFactory,\n TargetFeatureFlag,\n Cookie,\n GeolocationCondition,\n OperatingSystem,\n Segment,\n FirstVisit,\n LastVisit,\n SameDayVisits,\n Visits,\n ConversionLikelihood,\n NewVisitor,\n} from './conditions';\n"],"mappings":"","ignoreList":[]}
|
package/dist/targeting/node.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Node=void 0;var _conditions=require("./conditions"),_types=require("./types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Node=void 0;var _conditions=require("./conditions"),_types=require("./types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Node{constructor(a,b,c){if(_defineProperty(this,"nodeValue",void 0),_defineProperty(this,"nodeError",void 0),_defineProperty(this,"leftChild",void 0),_defineProperty(this,"rightChild",void 0),_defineProperty(this,"inverseResult",!1),this.isOperator(a))this.nodeValue=a;else{const b=_conditions.ConditionFactory.createCondition(a);this.inverseResult=!a.isInclude&&0,b.ok?this.nodeValue=b.data:this.nodeError=b.error}this.leftChild=b,this.rightChild=c}get value(){return this.nodeValue}get error(){return this.nodeError}get left(){return this.leftChild}get right(){return this.rightChild}get inverse(){return this.inverseResult}isOperator(a){return a===_types.Operator.And||a===_types.Operator.Or}}exports.Node=Node;
|
|
2
2
|
//# sourceMappingURL=node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":["Node","constructor","value","left","right","_defineProperty","isOperator","nodeValue","
|
|
1
|
+
{"version":3,"file":"node.js","names":["Node","constructor","value","left","right","_defineProperty","isOperator","nodeValue","result","ConditionFactory","createCondition","inverseResult","isInclude","ok","data","nodeError","error","leftChild","rightChild","inverse","Operator","And","Or","exports"],"sources":["../../src/targeting/node.ts"],"sourcesContent":["import { KameleoonError } from 'src/kameleoonError';\nimport { ConditionFactory, ConditionDataType } from './conditions';\nimport { NodeValueType, Operator } from './types';\n\nexport interface INode {\n readonly value?: NodeValueType;\n readonly left?: INode;\n readonly right?: INode;\n readonly error?: KameleoonError;\n}\n\nexport class Node implements INode {\n private nodeValue?: NodeValueType;\n private nodeError?: KameleoonError;\n private leftChild?: INode;\n private rightChild?: INode;\n private inverseResult: boolean = false;\n\n constructor(\n value: ConditionDataType | Operator,\n left?: INode,\n right?: INode,\n ) {\n if (this.isOperator(value)) {\n this.nodeValue = value;\n } else {\n const result = ConditionFactory.createCondition(value);\n this.inverseResult = !(value.isInclude ?? true);\n\n if (result.ok) {\n this.nodeValue = result.data;\n } else {\n this.nodeError = result.error;\n }\n }\n\n this.leftChild = left;\n this.rightChild = right;\n }\n\n get value(): NodeValueType | undefined {\n return this.nodeValue;\n }\n\n get error(): KameleoonError | undefined {\n return this.nodeError;\n }\n\n get left(): INode | undefined {\n return this.leftChild;\n }\n\n get right(): INode | undefined {\n return this.rightChild;\n }\n\n get inverse(): boolean {\n return this.inverseResult;\n }\n\n private isOperator(value: ConditionDataType | Operator): value is Operator {\n return value === Operator.And || value === Operator.Or;\n }\n}\n"],"mappings":"2pBAWO,KAAM,CAAAA,IAAsB,CAOjCC,WAAWA,CACTC,CAAmC,CACnCC,CAAY,CACZC,CAAa,CACb,CACA,GAAAC,eAAA,0BAAAA,eAAA,0BAAAA,eAAA,0BAAAA,eAAA,2BAAAA,eAAA,0BAAI,IAAI,CAACC,UAAU,CAACJ,CAAK,CAAC,CACxB,IAAI,CAACK,SAAS,CAAGL,CAAK,KACjB,CACL,KAAM,CAAAM,CAAM,CAAGC,4BAAgB,CAACC,eAAe,CAACR,CAAK,CAAC,CACtD,IAAI,CAACS,aAAa,CAAK,CAAAT,CAAK,CAACU,SAAS,GAAS,CAE3CJ,CAAM,CAACK,EAAE,CACX,IAAI,CAACN,SAAS,CAAGC,CAAM,CAACM,IAAI,CAE5B,IAAI,CAACC,SAAS,CAAGP,CAAM,CAACQ,KAE5B,CAEA,IAAI,CAACC,SAAS,CAAGd,CAAI,CACrB,IAAI,CAACe,UAAU,CAAGd,CACpB,CAEA,GAAI,CAAAF,KAAKA,CAAA,CAA8B,CACrC,MAAO,KAAI,CAACK,SACd,CAEA,GAAI,CAAAS,KAAKA,CAAA,CAA+B,CACtC,MAAO,KAAI,CAACD,SACd,CAEA,GAAI,CAAAZ,IAAIA,CAAA,CAAsB,CAC5B,MAAO,KAAI,CAACc,SACd,CAEA,GAAI,CAAAb,KAAKA,CAAA,CAAsB,CAC7B,MAAO,KAAI,CAACc,UACd,CAEA,GAAI,CAAAC,OAAOA,CAAA,CAAY,CACrB,MAAO,KAAI,CAACR,aACd,CAEQL,UAAUA,CAACJ,CAAmC,CAAqB,CACzE,MAAO,CAAAA,CAAK,GAAKkB,eAAQ,CAACC,GAAG,EAAInB,CAAK,GAAKkB,eAAQ,CAACE,EACtD,CACF,CAACC,OAAA,CAAAvB,IAAA,CAAAA,IAAA","ignoreList":[]}
|
package/dist/targeting/tree.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tree=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_node=require("./node"),_types=require("./types");function _defineProperty(a,b,c){return
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Tree=void 0;var _tsRes=require("ts-res"),_kameleoonError=require("../kameleoonError"),_node=require("./node"),_types=require("./types");function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}class Tree{constructor(a){_defineProperty(this,"tree",void 0),_defineProperty(this,"error",null),_defineProperty(this,"targetingTypes",new Set);const{nestedConditions:b,topLevelOperators:c}=this.flattenSegment(a),d=b.map(a=>{let{conditions:b,operators:c}=a;const d=b.map(a=>(this.targetingTypes.add(a.targetingType),new _node.Node(a)));return this.buildTree(d,c)});this.tree=this.buildTree(d,c)}evaluate(a){const b=this.evaluateNode(this.tree,a);return this.error?(0,_tsRes.Err)(this.error):(0,_tsRes.Ok)(b)}hasTargetingType(a){return this.targetingTypes.has(a)}evaluateNode(a,b){if(this.isLeafNode(a)){if(a.error)return a.error.type===_kameleoonError.KameleoonException.TargetingCondition;const c=a.value.evaluate(b);return c.ok?a.inverse?!c.data:c.data:(this.error=c.error,!1)}if(this.isNonLeafNode(a))switch(a.value){case _types.Operator.And:return this.evaluateNode(a.left,b)&&this.evaluateNode(a.right,b);case _types.Operator.Or:return this.evaluateNode(a.left,b)||this.evaluateNode(a.right,b);default:}return!1}isLeafNode(a){return!!!(a.left&&a.right)}isNonLeafNode(a){return!!(a.left&&a.right&&(a.value===_types.Operator.Or||a.value===_types.Operator.And))}buildTree(a,b){if(1===a.length)return a[0];for(const c of b){const b=a.shift(),d=a.shift(),e=new _node.Node(c,b,d);a.unshift(e)}return a[0]}flattenSegment(a){const{firstLevel:b,firstLevelOrOperators:c}=a.conditionsData,d=[];return b.forEach(a=>{const{conditions:b,orOperators:c}=a,e={operators:this.convertOperators(c),conditions:b};d.push(e)}),{topLevelOperators:this.convertOperators(c),nestedConditions:d}}convertOperators(a){return a.map(a=>a?_types.Operator.Or:_types.Operator.And)}}exports.Tree=Tree;
|
|
2
2
|
//# sourceMappingURL=tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree.js","names":["Tree","constructor","segment","_defineProperty","Set","nestedConditions","topLevelOperators","flattenSegment","nestedNodes","map","a","conditions","operators","nodes","condition","targetingTypes","add","targetingType","Node","buildTree","tree","evaluate","data","result","evaluateNode","error","Err","Ok","hasTargetingType","has","node","isLeafNode","type","KameleoonException","TargetingCondition","value","ok","inverse","isNonLeafNode","Operator","And","left","right","Or","length","operator","shift","newNode","unshift","firstLevel","firstLevelOrOperators","conditionsData","forEach","conditionList","orOperators","group","convertOperators","push","exports"],"sources":["../../src/targeting/tree.ts"],"sourcesContent":["import { Result, Ok, Err } from 'ts-res';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { INode, Node } from './node';\nimport {\n EvaluationDataType,\n GroupedSegmentsType,\n LeafNodeType,\n NestedConditionGroupType,\n NonLeafNodeType,\n Operator,\n SegmentType,\n TargetingType,\n} from './types';\n\ninterface ITree {\n evaluate: (data: EvaluationDataType) => Result<boolean, KameleoonError>;\n hasTargetingType: (targetingType: TargetingType) => boolean;\n}\n\nexport class Tree implements ITree {\n private tree: Node;\n private error: KameleoonError | null = null;\n private targetingTypes: Set<TargetingType> = new Set();\n\n constructor(segment: SegmentType) {\n const { nestedConditions, topLevelOperators } =\n this.flattenSegment(segment);\n\n // --- Note ---\n // - Targeting tree is built bottom-up, it's the only way to both get the consistent logic\n // (grouping nested conditions) and have human readable tree representation.\n // - Here is an example of how tree is built (we use strict complete binary tree)\n // Let's say we have such a condition `value < 10 || value > 20 && value < 30`\n // Following is pseudo code for building tree:\n //\n // `const operators = [Operator.Or, Operator.And]`\n // `const conditions = [\n // {type: Condition.Less, value: 10},\n // {type: Condition.Greater, value: 20},\n // {type: Condition.Less, value: 30},\n // ]`\n //\n // After the first iteration we have node like this:\n // AND\n // / \\\n // <30 >20\n //\n // After the second iteration tree looks as follows:\n // OR\n // / \\\n // AND <10\n // / \\\n // <30 >20\n //\n // As you can see Leaf Nodes contain conditions and Non-Leaf Nodes contain logical operators\n const nestedNodes = nestedConditions.map(({ conditions, operators }) => {\n const nodes = conditions.map((condition) => {\n // --- Note ---\n // We keep condition types to optimize\n // some external operations depending on what conditions are present\n // in a tree\n this.targetingTypes.add(condition.targetingType);\n\n return new Node(condition);\n });\n\n return this.buildTree(nodes, operators);\n });\n\n this.tree = this.buildTree(nestedNodes, topLevelOperators);\n }\n\n public evaluate(data: EvaluationDataType): Result<boolean, KameleoonError> {\n const result = this.evaluateNode(this.tree, data);\n\n if (this.error) {\n return Err(this.error);\n }\n\n return Ok(result);\n }\n\n public hasTargetingType(targetingType: TargetingType): boolean {\n return this.targetingTypes.has(targetingType);\n }\n\n private evaluateNode(node: Node, data: EvaluationDataType): boolean {\n if (this.isLeafNode(node)) {\n if (node.error) {\n // --- Note ---\n // Non-existing condition should not break targeting tree\n // instead it should be treated as `true` condition\n if (node.error.type === KameleoonException.TargetingCondition) {\n return true;\n }\n\n return false;\n }\n\n const result = node.value.evaluate(data);\n\n if (!result.ok) {\n this.error = result.error;\n\n return false;\n }\n\n return node.inverse ? !result.data : result.data;\n }\n\n if (this.isNonLeafNode(node)) {\n switch (node.value) {\n case Operator.And: {\n return (\n this.evaluateNode(node.left, data) &&\n this.evaluateNode(node.right, data)\n );\n }\n case Operator.Or: {\n return (\n this.evaluateNode(node.left, data) ||\n this.evaluateNode(node.right, data)\n );\n }\n default:\n break;\n }\n }\n\n return false;\n }\n\n private isLeafNode(node: INode): node is LeafNodeType {\n return !Boolean(node.left && node.right);\n }\n\n private isNonLeafNode(node: INode): node is NonLeafNodeType {\n return Boolean(\n node.left &&\n node.right &&\n (node.value === Operator.Or || node.value === Operator.And),\n );\n }\n\n // --- Note ---\n // This method mutates `nodes` array\n // It's done for the sake of performance\n private buildTree(nodes: Node[], operators: Operator[]): Node {\n if (nodes.length === 1) {\n return nodes[0];\n }\n\n for (const operator of operators) {\n const left = nodes.shift();\n const right = nodes.shift();\n\n const newNode = new Node(operator, left, right);\n nodes.unshift(newNode);\n }\n\n return nodes[0];\n }\n\n private flattenSegment(segment: SegmentType): GroupedSegmentsType {\n const { firstLevel: conditions, firstLevelOrOperators: operators } =\n segment.conditionsData;\n\n const nestedConditions: NestedConditionGroupType[] = [];\n\n conditions.forEach((condition) => {\n const { conditions: conditionList, orOperators } = condition;\n\n const group = {\n operators: this.convertOperators(orOperators),\n conditions: conditionList,\n };\n\n nestedConditions.push(group);\n });\n\n return {\n topLevelOperators: this.convertOperators(operators),\n nestedConditions,\n };\n }\n\n private convertOperators(operators: boolean[]): Operator[] {\n return operators.map((operator) => (operator ? Operator.Or : Operator.And));\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tree.js","names":["Tree","constructor","segment","_defineProperty","Set","nestedConditions","topLevelOperators","flattenSegment","nestedNodes","map","a","conditions","operators","nodes","condition","targetingTypes","add","targetingType","Node","buildTree","tree","evaluate","data","result","evaluateNode","error","Err","Ok","hasTargetingType","has","node","isLeafNode","type","KameleoonException","TargetingCondition","value","ok","inverse","isNonLeafNode","Operator","And","left","right","Or","length","operator","shift","newNode","unshift","firstLevel","firstLevelOrOperators","conditionsData","forEach","conditionList","orOperators","group","convertOperators","push","exports"],"sources":["../../src/targeting/tree.ts"],"sourcesContent":["import { Result, Ok, Err } from 'ts-res';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { INode, Node } from './node';\nimport {\n EvaluationDataType,\n GroupedSegmentsType,\n LeafNodeType,\n NestedConditionGroupType,\n NonLeafNodeType,\n Operator,\n SegmentType,\n TargetingType,\n} from './types';\n\ninterface ITree {\n evaluate: (data: EvaluationDataType) => Result<boolean, KameleoonError>;\n hasTargetingType: (targetingType: TargetingType) => boolean;\n}\n\nexport class Tree implements ITree {\n private tree: Node;\n private error: KameleoonError | null = null;\n private targetingTypes: Set<TargetingType> = new Set();\n\n constructor(segment: SegmentType) {\n const { nestedConditions, topLevelOperators } =\n this.flattenSegment(segment);\n\n // --- Note ---\n // - Targeting tree is built bottom-up, it's the only way to both get the consistent logic\n // (grouping nested conditions) and have human readable tree representation.\n // - Here is an example of how tree is built (we use strict complete binary tree)\n // Let's say we have such a condition `value < 10 || value > 20 && value < 30`\n // Following is pseudo code for building tree:\n //\n // `const operators = [Operator.Or, Operator.And]`\n // `const conditions = [\n // {type: Condition.Less, value: 10},\n // {type: Condition.Greater, value: 20},\n // {type: Condition.Less, value: 30},\n // ]`\n //\n // After the first iteration we have node like this:\n // AND\n // / \\\n // <30 >20\n //\n // After the second iteration tree looks as follows:\n // OR\n // / \\\n // AND <10\n // / \\\n // <30 >20\n //\n // As you can see Leaf Nodes contain conditions and Non-Leaf Nodes contain logical operators\n const nestedNodes = nestedConditions.map(({ conditions, operators }) => {\n const nodes = conditions.map((condition) => {\n // --- Note ---\n // We keep condition types to optimize\n // some external operations depending on what conditions are present\n // in a tree\n this.targetingTypes.add(condition.targetingType);\n\n return new Node(condition);\n });\n\n return this.buildTree(nodes, operators);\n });\n\n this.tree = this.buildTree(nestedNodes, topLevelOperators);\n }\n\n public evaluate(data: EvaluationDataType): Result<boolean, KameleoonError> {\n const result = this.evaluateNode(this.tree, data);\n\n if (this.error) {\n return Err(this.error);\n }\n\n return Ok(result);\n }\n\n public hasTargetingType(targetingType: TargetingType): boolean {\n return this.targetingTypes.has(targetingType);\n }\n\n private evaluateNode(node: Node, data: EvaluationDataType): boolean {\n if (this.isLeafNode(node)) {\n if (node.error) {\n // --- Note ---\n // Non-existing condition should not break targeting tree\n // instead it should be treated as `true` condition\n if (node.error.type === KameleoonException.TargetingCondition) {\n return true;\n }\n\n return false;\n }\n\n const result = node.value.evaluate(data);\n\n if (!result.ok) {\n this.error = result.error;\n\n return false;\n }\n\n return node.inverse ? !result.data : result.data;\n }\n\n if (this.isNonLeafNode(node)) {\n switch (node.value) {\n case Operator.And: {\n return (\n this.evaluateNode(node.left, data) &&\n this.evaluateNode(node.right, data)\n );\n }\n case Operator.Or: {\n return (\n this.evaluateNode(node.left, data) ||\n this.evaluateNode(node.right, data)\n );\n }\n default:\n break;\n }\n }\n\n return false;\n }\n\n private isLeafNode(node: INode): node is LeafNodeType {\n return !Boolean(node.left && node.right);\n }\n\n private isNonLeafNode(node: INode): node is NonLeafNodeType {\n return Boolean(\n node.left &&\n node.right &&\n (node.value === Operator.Or || node.value === Operator.And),\n );\n }\n\n // --- Note ---\n // This method mutates `nodes` array\n // It's done for the sake of performance\n private buildTree(nodes: Node[], operators: Operator[]): Node {\n if (nodes.length === 1) {\n return nodes[0];\n }\n\n for (const operator of operators) {\n const left = nodes.shift();\n const right = nodes.shift();\n\n const newNode = new Node(operator, left, right);\n nodes.unshift(newNode);\n }\n\n return nodes[0];\n }\n\n private flattenSegment(segment: SegmentType): GroupedSegmentsType {\n const { firstLevel: conditions, firstLevelOrOperators: operators } =\n segment.conditionsData;\n\n const nestedConditions: NestedConditionGroupType[] = [];\n\n conditions.forEach((condition) => {\n const { conditions: conditionList, orOperators } = condition;\n\n const group = {\n operators: this.convertOperators(orOperators),\n conditions: conditionList,\n };\n\n nestedConditions.push(group);\n });\n\n return {\n topLevelOperators: this.convertOperators(operators),\n nestedConditions,\n };\n }\n\n private convertOperators(operators: boolean[]): Operator[] {\n return operators.map((operator) => (operator ? Operator.Or : Operator.And));\n }\n}\n"],"mappings":"qtBAmBO,KAAM,CAAAA,IAAsB,CAKjCC,WAAWA,CAACC,CAAoB,CAAE,CAAAC,eAAA,qBAAAA,eAAA,cAHK,IAAI,EAAAA,eAAA,uBACE,GAAI,CAAAC,GAAK,OAG9C,CAAEC,gBAAgB,CAAhBA,CAAgB,CAAEC,iBAAiB,CAAjBA,CAAkB,CAAC,CAC3C,IAAI,CAACC,cAAc,CAACL,CAAO,CAAC,CA6BxBM,CAAW,CAAGH,CAAgB,CAACI,GAAG,CAACC,CAAA,EAA+B,IAA9B,CAAEC,UAAU,CAAVA,CAAU,CAAEC,SAAS,CAATA,CAAU,CAAC,CAAAF,CAAA,CACjE,KAAM,CAAAG,CAAK,CAAGF,CAAU,CAACF,GAAG,CAAEK,CAAS,GAKrC,IAAI,CAACC,cAAc,CAACC,GAAG,CAACF,CAAS,CAACG,aAAa,CAAC,CAEzC,GAAI,CAAAC,UAAI,CAACJ,CAAS,CAAC,CAC3B,CAAC,CAEF,MAAO,KAAI,CAACK,SAAS,CAACN,CAAK,CAAED,CAAS,CACxC,CAAC,CAAC,CAEF,IAAI,CAACQ,IAAI,CAAG,IAAI,CAACD,SAAS,CAACX,CAAW,CAAEF,CAAiB,CAC3D,CAEOe,QAAQA,CAACC,CAAwB,CAAmC,CACzE,KAAM,CAAAC,CAAM,CAAG,IAAI,CAACC,YAAY,CAAC,IAAI,CAACJ,IAAI,CAAEE,CAAI,CAAC,CAAC,MAE9C,KAAI,CAACG,KAAK,CACL,GAAAC,UAAG,EAAC,IAAI,CAACD,KAAK,CAAC,CAGjB,GAAAE,SAAE,EAACJ,CAAM,CAClB,CAEOK,gBAAgBA,CAACX,CAA4B,CAAW,CAC7D,MAAO,KAAI,CAACF,cAAc,CAACc,GAAG,CAACZ,CAAa,CAC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