@kameleoon/javascript-sdk-core 5.0.2 → 5.1.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 +42 -0
- package/dist/cacheManager/cacheManager.js +1 -2
- package/dist/cacheManager/index.js +1 -2
- package/dist/cacheManager/types.js +1 -2
- package/dist/clientConfiguration/clientConfiguration.js +1 -2
- package/dist/clientConfiguration/constants.js +1 -2
- package/dist/clientConfiguration/index.js +1 -2
- package/dist/clientConfiguration/types.js +1 -2
- package/dist/clientSettings/clientSettings.js +1 -2
- package/dist/clientSettings/index.js +1 -2
- package/dist/clientSettings/types.js +1 -2
- package/dist/constants.js +1 -2
- package/dist/eventManager/eventManager.js +1 -2
- package/dist/eventManager/index.js +1 -2
- package/dist/eventManager/types.js +1 -2
- package/dist/eventSource/constants.js +1 -2
- package/dist/eventSource/eventSource.js +1 -2
- package/dist/eventSource/index.js +1 -2
- package/dist/eventSource/types.js +1 -2
- package/dist/hasher/hasher.js +1 -2
- package/dist/hasher/index.js +1 -2
- package/dist/hasher/types.js +1 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1 -2
- package/dist/kameleoonClient.d.ts +6 -1
- package/dist/kameleoonClient.js +1 -2
- package/dist/kameleoonClientInterface.d.ts +68 -20
- package/dist/kameleoonClientInterface.js +1 -2
- package/dist/kameleoonData/applicationVersion.js +1 -2
- package/dist/kameleoonData/browser.js +1 -2
- package/dist/kameleoonData/conversion.js +1 -2
- package/dist/kameleoonData/cookie.js +1 -2
- package/dist/kameleoonData/customData.js +1 -2
- package/dist/kameleoonData/dataManager.js +1 -2
- package/dist/kameleoonData/dataProcessor.js +1 -2
- package/dist/kameleoonData/device.js +1 -2
- package/dist/kameleoonData/geolocation.js +1 -2
- package/dist/kameleoonData/helpers.js +1 -2
- package/dist/kameleoonData/index.js +1 -2
- package/dist/kameleoonData/kameleoonConversionScore.js +1 -2
- package/dist/kameleoonData/operatingSystem.js +1 -2
- package/dist/kameleoonData/pageView.js +1 -2
- package/dist/kameleoonData/types.js +1 -2
- package/dist/kameleoonData/uniqueIdentifier.js +1 -2
- package/dist/kameleoonData/userAgent.js +1 -2
- package/dist/kameleoonData/visitProcessor.js +1 -2
- package/dist/kameleoonData/visitsData.js +1 -2
- package/dist/kameleoonError/constants.d.ts +0 -1
- package/dist/kameleoonError/constants.js +1 -2
- package/dist/kameleoonError/helpers.js +1 -2
- package/dist/kameleoonError/index.js +1 -2
- package/dist/kameleoonError/kameleoonError.d.ts +0 -1
- package/dist/kameleoonError/kameleoonError.js +1 -2
- package/dist/kameleoonError/types.d.ts +0 -1
- package/dist/kameleoonError/types.js +1 -2
- package/dist/kameleoonUtils.js +1 -2
- package/dist/logging/defaultLogger.d.ts +14 -0
- package/dist/logging/defaultLogger.js +1 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.js +1 -0
- package/dist/logging/kameleoonLogger.d.ts +14 -0
- package/dist/logging/kameleoonLogger.js +1 -0
- package/dist/logging/types.d.ts +36 -0
- package/dist/logging/types.js +1 -0
- package/dist/requester/constants.js +1 -2
- package/dist/requester/index.js +1 -2
- package/dist/requester/requester.js +1 -2
- package/dist/requester/types.js +1 -2
- package/dist/requester/urlProvider.js +1 -2
- package/dist/storage/constants.js +1 -2
- package/dist/storage/index.js +1 -2
- package/dist/storage/integrityChecker.js +1 -2
- package/dist/storage/storage.js +1 -2
- package/dist/storage/types.js +1 -2
- package/dist/targeting/conditions/applicationVersion.js +1 -2
- package/dist/targeting/conditions/browser.js +1 -2
- package/dist/targeting/conditions/conditionFactory.js +1 -2
- package/dist/targeting/conditions/conversion.js +1 -2
- package/dist/targeting/conditions/conversionLikelihood.js +1 -2
- package/dist/targeting/conditions/cookie.js +1 -2
- package/dist/targeting/conditions/customData.js +1 -2
- package/dist/targeting/conditions/device.js +1 -2
- package/dist/targeting/conditions/exclusiveCampaign.js +1 -2
- package/dist/targeting/conditions/firstVisit.js +1 -2
- package/dist/targeting/conditions/geolocation.js +1 -2
- package/dist/targeting/conditions/index.js +1 -2
- package/dist/targeting/conditions/lastVisit.js +1 -2
- package/dist/targeting/conditions/newVisitor.js +1 -2
- package/dist/targeting/conditions/operatingSystem.js +1 -2
- package/dist/targeting/conditions/pageTitle.js +1 -2
- package/dist/targeting/conditions/pageUrl.js +1 -2
- package/dist/targeting/conditions/previousPage.js +1 -2
- package/dist/targeting/conditions/sameDayVisits.js +1 -2
- package/dist/targeting/conditions/sdkLanguage.js +1 -2
- package/dist/targeting/conditions/segment.js +1 -2
- package/dist/targeting/conditions/targetFeatureFlag.js +1 -2
- package/dist/targeting/conditions/types.js +1 -2
- package/dist/targeting/conditions/utilities.js +1 -2
- package/dist/targeting/conditions/visitedPages.js +1 -2
- package/dist/targeting/conditions/visitorCode.js +1 -2
- package/dist/targeting/conditions/visits.js +1 -2
- package/dist/targeting/index.js +1 -2
- package/dist/targeting/node.js +1 -2
- package/dist/targeting/tree.js +1 -2
- package/dist/targeting/types.js +1 -2
- package/dist/tracking/bodyProvider.js +1 -2
- package/dist/tracking/constants.js +1 -2
- package/dist/tracking/index.js +1 -2
- package/dist/tracking/tracker.js +1 -2
- package/dist/tracking/types.js +1 -2
- package/dist/types.d.ts +52 -0
- package/dist/types.js +1 -2
- package/dist/utilities/constants.d.ts +5 -0
- package/dist/utilities/constants.js +1 -2
- package/dist/utilities/index.js +1 -2
- package/dist/utilities/parser.d.ts +1 -0
- package/dist/utilities/parser.js +1 -2
- package/dist/utilities/types.js +1 -2
- package/dist/utilities/utilities.js +1 -2
- package/dist/utilities/validator.d.ts +1 -0
- package/dist/utilities/validator.js +1 -2
- package/dist/variationConfiguration/index.js +1 -2
- package/dist/variationConfiguration/types.d.ts +1 -0
- package/dist/variationConfiguration/types.js +1 -2
- package/dist/variationConfiguration/variationConfiguration.d.ts +1 -1
- package/dist/variationConfiguration/variationConfiguration.js +1 -2
- package/dist/visitorCodeManager/constants.js +1 -2
- package/dist/visitorCodeManager/index.js +1 -2
- package/dist/visitorCodeManager/types.js +1 -2
- package/dist/visitorCodeManager/visitorCodeManager.js +1 -2
- package/package.json +4 -2
- package/dist/cacheManager/cacheManager.js.map +0 -1
- package/dist/cacheManager/index.js.map +0 -1
- package/dist/cacheManager/types.js.map +0 -1
- package/dist/clientConfiguration/clientConfiguration.js.map +0 -1
- package/dist/clientConfiguration/constants.js.map +0 -1
- package/dist/clientConfiguration/index.js.map +0 -1
- package/dist/clientConfiguration/types.js.map +0 -1
- package/dist/clientSettings/clientSettings.js.map +0 -1
- package/dist/clientSettings/index.js.map +0 -1
- package/dist/clientSettings/types.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/eventManager/eventManager.js.map +0 -1
- package/dist/eventManager/index.js.map +0 -1
- package/dist/eventManager/types.js.map +0 -1
- package/dist/eventSource/constants.js.map +0 -1
- package/dist/eventSource/eventSource.js.map +0 -1
- package/dist/eventSource/index.js.map +0 -1
- package/dist/eventSource/types.js.map +0 -1
- package/dist/hasher/hasher.js.map +0 -1
- package/dist/hasher/index.js.map +0 -1
- package/dist/hasher/types.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/kameleoonClient.js.map +0 -1
- package/dist/kameleoonClientInterface.js.map +0 -1
- package/dist/kameleoonData/applicationVersion.js.map +0 -1
- package/dist/kameleoonData/browser.js.map +0 -1
- package/dist/kameleoonData/conversion.js.map +0 -1
- package/dist/kameleoonData/cookie.js.map +0 -1
- package/dist/kameleoonData/customData.js.map +0 -1
- package/dist/kameleoonData/dataManager.js.map +0 -1
- package/dist/kameleoonData/dataProcessor.js.map +0 -1
- package/dist/kameleoonData/device.js.map +0 -1
- package/dist/kameleoonData/geolocation.js.map +0 -1
- package/dist/kameleoonData/helpers.js.map +0 -1
- package/dist/kameleoonData/index.js.map +0 -1
- package/dist/kameleoonData/kameleoonConversionScore.js.map +0 -1
- package/dist/kameleoonData/operatingSystem.js.map +0 -1
- package/dist/kameleoonData/pageView.js.map +0 -1
- package/dist/kameleoonData/types.js.map +0 -1
- package/dist/kameleoonData/uniqueIdentifier.js.map +0 -1
- package/dist/kameleoonData/userAgent.js.map +0 -1
- package/dist/kameleoonData/visitProcessor.js.map +0 -1
- package/dist/kameleoonData/visitsData.js.map +0 -1
- package/dist/kameleoonError/constants.js.map +0 -1
- package/dist/kameleoonError/helpers.js.map +0 -1
- package/dist/kameleoonError/index.js.map +0 -1
- package/dist/kameleoonError/kameleoonError.js.map +0 -1
- package/dist/kameleoonError/types.js.map +0 -1
- package/dist/kameleoonUtils.js.map +0 -1
- package/dist/requester/constants.js.map +0 -1
- package/dist/requester/index.js.map +0 -1
- package/dist/requester/requester.js.map +0 -1
- package/dist/requester/types.js.map +0 -1
- package/dist/requester/urlProvider.js.map +0 -1
- package/dist/storage/constants.js.map +0 -1
- package/dist/storage/index.js.map +0 -1
- package/dist/storage/integrityChecker.js.map +0 -1
- package/dist/storage/storage.js.map +0 -1
- package/dist/storage/types.js.map +0 -1
- package/dist/targeting/conditions/applicationVersion.js.map +0 -1
- package/dist/targeting/conditions/browser.js.map +0 -1
- package/dist/targeting/conditions/conditionFactory.js.map +0 -1
- package/dist/targeting/conditions/conversion.js.map +0 -1
- package/dist/targeting/conditions/conversionLikelihood.js.map +0 -1
- package/dist/targeting/conditions/cookie.js.map +0 -1
- package/dist/targeting/conditions/customData.js.map +0 -1
- package/dist/targeting/conditions/device.js.map +0 -1
- package/dist/targeting/conditions/exclusiveCampaign.js.map +0 -1
- package/dist/targeting/conditions/firstVisit.js.map +0 -1
- package/dist/targeting/conditions/geolocation.js.map +0 -1
- package/dist/targeting/conditions/index.js.map +0 -1
- package/dist/targeting/conditions/lastVisit.js.map +0 -1
- package/dist/targeting/conditions/newVisitor.js.map +0 -1
- package/dist/targeting/conditions/operatingSystem.js.map +0 -1
- package/dist/targeting/conditions/pageTitle.js.map +0 -1
- package/dist/targeting/conditions/pageUrl.js.map +0 -1
- package/dist/targeting/conditions/previousPage.js.map +0 -1
- package/dist/targeting/conditions/sameDayVisits.js.map +0 -1
- package/dist/targeting/conditions/sdkLanguage.js.map +0 -1
- package/dist/targeting/conditions/segment.js.map +0 -1
- package/dist/targeting/conditions/targetFeatureFlag.js.map +0 -1
- package/dist/targeting/conditions/types.js.map +0 -1
- package/dist/targeting/conditions/utilities.js.map +0 -1
- package/dist/targeting/conditions/visitedPages.js.map +0 -1
- package/dist/targeting/conditions/visitorCode.js.map +0 -1
- package/dist/targeting/conditions/visits.js.map +0 -1
- package/dist/targeting/index.js.map +0 -1
- package/dist/targeting/node.js.map +0 -1
- package/dist/targeting/tree.js.map +0 -1
- package/dist/targeting/types.js.map +0 -1
- package/dist/tracking/bodyProvider.js.map +0 -1
- package/dist/tracking/constants.js.map +0 -1
- package/dist/tracking/index.js.map +0 -1
- package/dist/tracking/tracker.js.map +0 -1
- package/dist/tracking/types.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utilities/constants.js.map +0 -1
- package/dist/utilities/index.js.map +0 -1
- package/dist/utilities/parser.js.map +0 -1
- package/dist/utilities/types.js.map +0 -1
- package/dist/utilities/utilities.js.map +0 -1
- package/dist/utilities/validator.js.map +0 -1
- package/dist/variationConfiguration/index.js.map +0 -1
- package/dist/variationConfiguration/types.js.map +0 -1
- package/dist/variationConfiguration/variationConfiguration.js.map +0 -1
- package/dist/visitorCodeManager/constants.js.map +0 -1
- package/dist/visitorCodeManager/index.js.map +0 -1
- package/dist/visitorCodeManager/types.js.map +0 -1
- package/dist/visitorCodeManager/visitorCodeManager.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","names":["Device","constructor","a","device","_defineProperty","evaluate","targetingData","deviceData","KameleoonData","Ok","exports"],"sources":["../../../src/targeting/conditions/device.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { DeviceType, KameleoonData } from 'src/kameleoonData';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ConditionDataType, ICondition } from './types';\n\nexport class Device implements ICondition {\n private device?: DeviceType | null;\n\n constructor({ device }: ConditionDataType) {\n this.device = device;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const deviceData = targetingData?.[KameleoonData.Device];\n\n if (deviceData) {\n const { device } = deviceData;\n\n return Ok(device === this.device);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"sqBAMO,KAAM,CAAAA,MAA6B,CAGxCC,WAAWA,CAAAC,CAAA,CAAgC,IAA/B,CAAEC,MAAM,CAANA,CAA0B,CAAC,CAAAD,CAAA,CAAAE,eAAA,uBACvC,IAAI,CAACD,MAAM,CAAGA,CAChB,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,CAACR,MAAM,CAAC,CAExD,GAAIO,CAAU,CAAE,CACd,KAAM,CAAEJ,MAAM,CAANA,CAAO,CAAC,CAAGI,CAAU,CAE7B,MAAO,GAAAE,SAAE,EAACN,CAAM,GAAK,IAAI,CAACA,MAAM,CAClC,CAEA,MAAO,GAAAM,SAAE,IAAM,CACjB,CACF,CAACC,OAAA,CAAAV,MAAA,CAAAA,MAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"exclusiveCampaign.js","names":["_tsRes","require","Object","defineProperty","exports","value","ExclusiveCampaign","evaluate","a","variationData","experimentId","keys","isEmpty","length","isExclusive","Ok"],"sources":["../../../src/targeting/conditions/exclusiveCampaign.ts"],"sourcesContent":["import { Ok, Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { EvaluationDataType } from 'src/targeting/types';\nimport { ICondition } from './types';\n\nexport class ExclusiveCampaign implements ICondition {\n evaluate({\n variationData,\n experimentId,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const keys = Object.keys(variationData);\n const isEmpty = !keys.length;\n // --- Note ---\n // Checking exclusiveness is done by checking if there is only one experiment id with variation\n // and the next assigned experiment id will overwrite the previous one\n // (thus, still leaving one exclusive experiment)\n const isExclusive = keys.length === 1 && keys[0] === String(experimentId);\n const isSatisfied = isEmpty || isExclusive;\n\n return Ok(isSatisfied);\n }\n}\n"],"mappings":"aAAA,IAAAA,MAAA,CAAAC,OAAA,WAAoCC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,iBAAA,QAK7B,KAAM,CAAAA,iBAAwC,CACnDC,QAAQA,CAAAC,CAAA,CAGgD,IAH/C,CACPC,aAAa,CAAbA,CAAa,CACbC,YAAY,CAAZA,CACkB,CAAC,CAAAF,CAAA,MACb,CAAAG,CAAI,CAAGT,MAAM,CAACS,IAAI,CAACF,CAAa,CAAC,CACjCG,CAAO,CAAG,CAACD,CAAI,CAACE,MAAM,CAKtBC,CAAW,CAAmB,CAAC,GAAjBH,CAAI,CAACE,MAAY,EAAIF,CAAI,CAAC,CAAC,CAAC,GAAYD,CAAY,GAAC,CAGzE,MAAO,GAAAK,SAAE,EAFWH,CAAO,EAAIE,CAEV,CACvB,CACF,CAACV,OAAA,CAAAE,iBAAA,CAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"firstVisit.js","names":["FirstVisit","constructor","a","matchType","count","unitOfTime","_defineProperty","conditionValue","timeUnit","evaluate","targetingData","visitsData","KameleoonData","VisitsData","visits","length","Ok","firstVisitTimestamp","checkCondition","elapsedTimeMilliseconds","Date","now","elapsedTimeUnit","Utilities","convertTimeUnit","MatchType","GREATER","LOWER","exports"],"sources":["../../../src/targeting/conditions/firstVisit.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 FirstVisit 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 firstVisitTimestamp = visitsData.visits[0];\n\n return Ok(this.checkCondition(firstVisitTimestamp));\n }\n\n private checkCondition(firstVisitTimestamp: 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() - firstVisitTimestamp;\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":"2uBAOO,KAAM,CAAAA,UAAiC,CAK5CC,WAAWA,CAAAC,CAAA,CAAsD,IAArD,CAAEC,SAAS,CAATA,CAAS,CAAEC,KAAK,CAALA,CAAK,CAAEC,UAAU,CAAVA,CAA8B,CAAC,CAAAH,CAAA,CAAAI,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,yBAC7D,IAAI,CAACH,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACI,cAAc,CAAGH,CAAK,CAC3B,IAAI,CAACI,QAAQ,CAAGH,CAClB,CAEOI,QAAQA,CAAAP,CAAA,CAEyC,IAFxC,CACdQ,aAAa,CAAbA,CACkB,CAAC,CAAAR,CAAA,CACnB,KAAM,CAAAS,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,SAACF,CAAU,WAAVA,CAAU,EAAVA,CAAU,CAAEG,MAAM,CAACC,MAAM,EAC5B,MAAO,GAAAC,SAAE,IAAM,CAAC,CAGlB,KAAM,CAAAC,CAAmB,CAAGN,CAAU,CAACG,MAAM,CAAC,CAAC,CAAC,CAEhD,MAAO,GAAAE,SAAE,EAAC,IAAI,CAACE,cAAc,CAACD,CAAmB,CAAC,CACpD,CAEQC,cAAcA,CAACD,CAA2B,CAAW,CAC3D,GACE,CAAC,IAAI,CAACd,SAAS,EACgB,QAAQ,EAAvC,MAAO,KAAI,CAACI,cAA2B,EACvC,CAAC,IAAI,CAACC,QAAQ,CAEd,SACD,KAEK,CAAAW,CAAuB,CAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,CAAGJ,CAAmB,CAC1DK,CAAe,CAAGC,oBAAS,CAACC,eAAe,CAC/CL,CAAuB,CACvB,IAAI,CAACX,QACP,CAAC,CAED,OAAQ,IAAI,CAACL,SAAS,EACpB,IAAK,CAAAsB,gBAAS,CAACC,OAAO,CACpB,MAAO,CAAAJ,CAAe,CAAG,IAAI,CAACf,cAAc,CAC9C,IAAK,CAAAkB,gBAAS,CAACE,KAAK,CAClB,MAAO,CAAAL,CAAe,CAAG,IAAI,CAACf,cAAc,CAC9C,QACE,QACJ,CACF,CACF,CAACqB,OAAA,CAAA5B,UAAA,CAAAA,UAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geolocation.js","names":["GeolocationCondition","constructor","a","country","region","city","_defineProperty","evaluate","targetingData","geolocationData","KameleoonData","GeolocationData","dataCountry","dataRegion","dataCity","conditionCountry","conditionRegion","conditionCity","Ok","result","toLowerCase","exports"],"sources":["../../../src/targeting/conditions/geolocation.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 { ConditionDataType, ICondition } from './types';\n\n// --- Note ---\n// `GeolocationCondition` uses `Condition` in the naming to avoid confusion with\n// native `Geolocation` API\nexport class GeolocationCondition implements ICondition {\n private country?: string | null;\n private region?: string | null;\n private city?: string | null;\n\n constructor({ country, region, city }: ConditionDataType) {\n this.country = country;\n this.region = region;\n this.city = city;\n }\n\n public evaluate({\n targetingData,\n }: EvaluationDataType): Result<boolean, KameleoonError> {\n const geolocationData = targetingData?.[KameleoonData.GeolocationData];\n\n if (geolocationData) {\n const {\n country: dataCountry,\n region: dataRegion,\n city: dataCity,\n } = geolocationData;\n const [conditionCountry, conditionRegion, conditionCity] = [\n this.country,\n this.region,\n this.city,\n ];\n\n if (!conditionCountry || !dataCountry) {\n return Ok(false);\n }\n\n const result =\n dataCountry.toLowerCase() === conditionCountry.toLowerCase() &&\n (!conditionRegion ||\n dataRegion?.toLowerCase() === conditionRegion.toLowerCase()) &&\n (!conditionCity ||\n dataCity?.toLowerCase() === conditionCity.toLowerCase());\n\n return Ok(result);\n }\n\n return Ok(false);\n }\n}\n"],"mappings":"orBASO,KAAM,CAAAA,oBAA2C,CAKtDC,WAAWA,CAAAC,CAAA,CAA+C,IAA9C,CAAEC,OAAO,CAAPA,CAAO,CAAEC,MAAM,CAANA,CAAM,CAAEC,IAAI,CAAJA,CAAwB,CAAC,CAAAH,CAAA,CAAAI,eAAA,wBAAAA,eAAA,uBAAAA,eAAA,qBACtD,IAAI,CAACH,OAAO,CAAGA,CAAO,CACtB,IAAI,CAACC,MAAM,CAAGA,CAAM,CACpB,IAAI,CAACC,IAAI,CAAGA,CACd,CAEOE,QAAQA,CAAAL,CAAA,CAEyC,IAFxC,CACdM,aAAa,CAAbA,CACkB,CAAC,CAAAN,CAAA,CACnB,KAAM,CAAAO,CAAe,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,eAAe,CAAC,CAEtE,GAAIF,CAAe,CAAE,MACb,CACJN,OAAO,CAAES,CAAW,CACpBR,MAAM,CAAES,CAAU,CAClBR,IAAI,CAAES,CACR,CAAC,CAAGL,CAAe,CACb,CAACM,CAAgB,CAAEC,CAAe,CAAEC,CAAa,CAAC,CAAG,CACzD,IAAI,CAACd,OAAO,CACZ,IAAI,CAACC,MAAM,CACX,IAAI,CAACC,IAAI,CACV,CAED,GAAI,CAACU,CAAgB,EAAI,CAACH,CAAW,CACnC,MAAO,GAAAM,SAAE,IAAM,CAAC,CAGlB,KAAM,CAAAC,CAAM,CACVP,CAAW,CAACQ,WAAW,CAAC,CAAC,GAAKL,CAAgB,CAACK,WAAW,CAAC,CAAC,GAC3D,CAACJ,CAAe,EACf,QAAAH,CAAU,WAAVA,CAAU,QAAVA,CAAU,CAAEO,WAAW,CAAC,CAAC,IAAKJ,CAAe,CAACI,WAAW,CAAC,CAAC,CAAC,GAC7D,CAACH,CAAa,EACb,QAAAH,CAAQ,WAARA,CAAQ,QAARA,CAAQ,CAAEM,WAAW,CAAC,CAAC,IAAKH,CAAa,CAACG,WAAW,CAAC,CAAC,CAAC,CAE5D,MAAO,GAAAF,SAAE,EAACC,CAAM,CAClB,CAEA,MAAO,GAAAD,SAAE,IAAM,CACjB,CACF,CAACG,OAAA,CAAArB,oBAAA,CAAAA,oBAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/targeting/conditions/index.ts"],"sourcesContent":["export { Device } from './device';\nexport { ConditionFactory } from './conditionFactory';\nexport { ConditionDataType, ConditionType } from './types';\nexport { CustomData } from './customData';\nexport { ExclusiveCampaign } from './exclusiveCampaign';\nexport { Browser } from './browser';\nexport { PageUrl } from './pageUrl';\nexport { PageTitle } from './pageTitle';\nexport { Conversion } from './conversion';\nexport { VisitorCode } from './visitorCode';\nexport { SdkLanguage } from './sdkLanguage';\nexport { TargetFeatureFlag } from './targetFeatureFlag';\nexport { Cookie } from './cookie';\nexport { OperatingSystem } from './operatingSystem';\nexport { GeolocationCondition } from './geolocation';\nexport { Segment } from './segment';\nexport { PreviousPage } from './previousPage';\nexport { VisitedPages } from './visitedPages';\nexport { FirstVisit } from './firstVisit';\nexport { LastVisit } from './lastVisit';\nexport { Visits } from './visits';\nexport { SameDayVisits } from './sameDayVisits';\nexport { NewVisitor } from './newVisitor';\nexport { ApplicationVersion } from './applicationVersion';\nexport { ConversionLikelihood } from './conversionLikelihood';\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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":"0uBAOO,KAAM,CAAAA,SAAgC,CAK3CC,WAAWA,CAAAC,CAAA,CAAsD,IAArD,CAAEC,SAAS,CAATA,CAAS,CAAEC,KAAK,CAALA,CAAK,CAAEC,UAAU,CAAVA,CAA8B,CAAC,CAAAH,CAAA,CAAAI,eAAA,0BAAAA,eAAA,+BAAAA,eAAA,yBAC7D,IAAI,CAACH,SAAS,CAAGA,CAAS,CAC1B,IAAI,CAACI,cAAc,CAAGH,CAAK,CAC3B,IAAI,CAACI,QAAQ,CAAGH,CAClB,CAEOI,QAAQA,CAAAP,CAAA,CAEyC,IAFxC,CACdQ,aAAa,CAAbA,CACkB,CAAC,CAAAR,CAAA,CACnB,KAAM,CAAAS,CAAU,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,UAAU,CAAC,CAE5D,GAAI,SAACF,CAAU,WAAVA,CAAU,EAAVA,CAAU,CAAEG,MAAM,CAACC,MAAM,EAC5B,MAAO,GAAAC,SAAE,IAAM,CAAC,CACjB,KAEK,CAAEF,MAAM,CAANA,CAAO,CAAC,CAAGH,CAAU,CAIvBM,CAA4B,CAClCH,CAAM,CAACA,CAAM,CAACC,MAAM,CAAG,CAAC,CAAC,CAEzB,MAAO,GAAAC,SAAE,EAAC,IAAI,CAACE,cAAc,CAACD,CAA4B,CAAC,CAC7D,CAEQC,cAAcA,CAACC,CAA0B,CAAW,CAC1D,GACE,CAAC,IAAI,CAAChB,SAAS,EACgB,QAAQ,EAAvC,MAAO,KAAI,CAACI,cAA2B,EACvC,CAAC,IAAI,CAACC,QAAQ,CAEd,SACD,KAEK,CAAAY,CAAuB,CAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,CAAGH,CAAkB,CACzDI,CAAe,CAAGC,oBAAS,CAACC,eAAe,CAC/CL,CAAuB,CACvB,IAAI,CAACZ,QACP,CAAC,CAED,OAAQ,IAAI,CAACL,SAAS,EACpB,IAAK,CAAAuB,gBAAS,CAACC,OAAO,CACpB,MAAO,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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pageTitle.js","names":["PageTitle","constructor","a","matchType","title","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","latestPageView","PageUtils","getLatest","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';\nimport { PageUtils } from './utilities';\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(false);\n }\n\n const latestPageView = PageUtils.getLatest(pageViewData);\n\n return Ok(this.checkCondition(latestPageView.title));\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(this.conditionValue).test(title);\n default:\n return false;\n }\n }\n}\n"],"mappings":"6wBAQO,KAAM,CAAAA,SAAgC,CAI3CC,WAAWA,CAAAC,CAAA,CAA0C,IAAzC,CAAEC,SAAS,CAATA,CAAS,CAAEC,KAAK,CAALA,CAAyB,CAAC,CAAAF,CAAA,CAAAG,eAAA,0BAAAA,eAAA,+BACjD,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,CAE5D,GAAI,CAACF,CAAY,CACf,MAAO,GAAAG,SAAE,IAAM,CAAC,CAGlB,KAAM,CAAAC,CAAc,CAAGC,qBAAS,CAACC,SAAS,CAACN,CAAY,CAAC,CAExD,MAAO,GAAAG,SAAE,EAAC,IAAI,CAACI,cAAc,CAACH,CAAc,CAACT,KAAK,CAAC,CACrD,CAEQY,cAAcA,CAACZ,CAAa,CAAW,CAC7C,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,CAAK,CAACe,QAAQ,CAAC,IAAI,CAACb,cAAc,CAAC,CAC5C,IAAK,CAAAW,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAhB,CAAK,GAAK,IAAI,CAACE,cAAc,CACtC,IAAK,CAAAW,gBAAS,CAACI,kBAAkB,CAC/B,MAAO,CAAAC,iBAAM,CAACC,WAAW,CAAC,IAAI,CAACjB,cAAc,CAAC,CAACkB,IAAI,CAACpB,CAAK,CAAC,CAC5D,QACE,QACJ,CACF,CACF,CAACqB,OAAA,CAAAzB,SAAA,CAAAA,SAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pageUrl.js","names":["PageUrl","constructor","a","matchType","url","_defineProperty","conditionValue","evaluate","targetingData","pageViewData","KameleoonData","PageView","Ok","latestPageView","PageUtils","getLatest","checkCondition","urlAddress","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';\nimport { PageUtils } from './utilities';\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(false);\n }\n\n const latestPageView = PageUtils.getLatest(pageViewData);\n\n return Ok(this.checkCondition(latestPageView.urlAddress));\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":"2wBAQO,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,CAE5D,GAAI,CAACF,CAAY,CACf,MAAO,GAAAG,SAAE,IAAM,CAAC,CAGlB,KAAM,CAAAC,CAAc,CAAGC,qBAAS,CAACC,SAAS,CAACN,CAAY,CAAC,CAExD,MAAO,GAAAG,SAAE,EAAC,IAAI,CAACI,cAAc,CAACH,CAAc,CAACI,UAAU,CAAC,CAC1D,CAEQD,cAAcA,CAACZ,CAAW,CAAW,CAC3C,GAAI,CAAC,IAAI,CAACD,SAAS,EAAI,CAAC,IAAI,CAACG,cAAc,CACzC,SAGF,OAAQ,IAAI,CAACH,SAAS,EACpB,IAAK,CAAAe,gBAAS,CAACC,QAAQ,CACrB,MAAO,CAAAf,CAAG,CAACgB,QAAQ,CAAC,IAAI,CAACd,cAAc,CAAC,CAC1C,IAAK,CAAAY,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAjB,CAAG,GAAK,IAAI,CAACE,cAAc,CACpC,IAAK,CAAAY,gBAAS,CAACI,kBAAkB,CAC/B,MAAO,CAAAC,iBAAM,CAACC,WAAW,CAAC,IAAI,CAAClB,cAAc,CAAC,CAACmB,IAAI,CAACrB,CAAG,CAAC,CAC1D,QACE,QACJ,CACF,CACF,CAACsB,OAAA,CAAA1B,OAAA,CAAAA,OAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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,C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ACH,CAC9B,GAA2B,CAAC,CAAxBA,CAAa,CAACkB,MAAU,CAC1B,OACD,GAKG,CAAAC,CAAsC,CACtCC,CAAsC,CAkC1C,MAhCA,CAAApB,CAAa,CAACqB,OAAO,CAAEC,CAAS,EAAK,CACnC,KAAM,CAAAC,CAAe,CACnBD,CAAS,CAACE,UAAU,CAACF,CAAS,CAACE,UAAU,CAACN,MAAM,CAAG,CAAC,CAAC,CAACO,IAAI,CAG5D,GAAI,CAACN,CAAQ,CAEX,YADAA,CAAQ,CAAGG,CAAS,EAItB,KAAM,CAAAI,CAAQ,CACZP,CAAQ,CAACK,UAAU,CAACL,CAAQ,CAAEK,UAAU,CAACN,MAAM,CAAG,CAAC,CAAC,CAACO,IAAI,CAG3D,GAAIF,CAAe,CAAGG,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 +0,0 @@
|
|
|
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":"wsBAMO,KAAM,CAAAA,aAAoC,CAI/CC,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,CAGlB,GAAI,CAAAC,CAAW,CAAG,CAAC,CAAC,KAEd,CAAAC,CAAc,CAAG,GAAI,CAAAC,IAAI,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC,CAAE,CAAC,CAAE,CAAC,CAAE,CAAC,CAAC,CAChD,CAAEC,MAAM,CAANA,CAAO,CAAC,CAAGR,CAAU,CAY7B,MAVA,CAAAQ,CAAM,CAACC,OAAO,CAAEC,CAAS,EAAK,CACxBA,CAAS,CAAGL,CAAc,EAC5BD,CAAW,EAEf,CAAC,CAAC,CAIFA,CAAW,EAAI,CAAC,CAET,GAAAD,SAAE,EAAC,IAAI,CAACQ,cAAc,CAACP,CAAW,CAAC,CAC5C,CAEQO,cAAcA,CAACC,CAAyB,CAAW,CACzD,GAAI,CAAC,IAAI,CAAClB,SAAS,EAAmC,QAAQ,EAAvC,MAAO,KAAI,CAACG,cAA2B,CAC5D,SAGF,OAAQ,IAAI,CAACH,SAAS,EACpB,IAAK,CAAAmB,gBAAS,CAACC,KAAK,CAClB,MAAO,CAAAF,CAAiB,GAAK,IAAI,CAACf,cAAc,CAClD,IAAK,CAAAgB,gBAAS,CAACE,OAAO,CACpB,MAAO,CAAAH,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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,KAAAD,CAAA,CAAAN,MAAA,CAAAC,cAAA,CAAAK,CAAA,CAAAC,CAAA,EAAAJ,KAAA,CAAAK,CAAA,CAAAE,UAAA,IAAAC,YAAA,IAAAC,QAAA,MAAAN,CAAA,CAAAC,CAAA,EAAAC,CAAA,CAAAF,CAAA,UAAAG,eAAAH,CAAA,MAAAC,CAAA,CAAAM,YAAA,CAAAP,CAAA,kCAAAC,CAAA,CAAAA,CAAA,CAAAA,CAAA,aAAAM,aAAAP,CAAA,CAAAC,CAAA,sBAAAD,CAAA,GAAAA,CAAA,QAAAA,CAAA,KAAAE,CAAA,CAAAF,CAAA,CAAAQ,MAAA,CAAAC,WAAA,cAAAP,CAAA,MAAAQ,CAAA,CAAAR,CAAA,CAAAS,IAAA,CAAAX,CAAA,CAAAC,CAAA,iCAAAS,CAAA,QAAAA,CAAA,WAAAE,SAAA,mEAAAX,CAAA,CAAAY,MAAA,CAAAC,MAAA,EAAAd,CAAA,EAK7B,KAAM,CAAAF,iBAAwC,CAKnDiB,WAAWA,CAAAf,CAAA,CAA6D,IAA5D,CAAEgB,aAAa,CAAbA,CAAa,CAAEC,YAAY,CAAZA,CAAY,CAAEC,MAAM,CAANA,CAA0B,CAAC,CAAAlB,CAAA,CAAAD,eAAA,0BAAAA,eAAA,uBAAAA,eAAA,6BACpE,IAAI,CAACoB,SAAS,CAAGH,CAAa,CAC9B,IA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,SAAE,EACP,EAAQI,CAAW,EACjB,SAAAI,CAAA,CAAAV,CAAa,CAACK,CAAY,CAAC,YAAAK,CAAA,QAA3BA,CAAA,CAA6BJ,WAAW,IAAKA,CACjD,CACF,CAEA,MAAO,GAAAJ,SAAE,UAAAK,CAAA,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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.js","names":["PageUtils","getLatest","pageViewData","Object","values","reduce","latest","current","timestamps","length","time","exports"],"sources":["../../../src/targeting/conditions/utilities.ts"],"sourcesContent":["import { PageViewDataType } from 'src/kameleoonData';\nimport {\n KameleoonData,\n KameleoonVisitorDataType,\n} from 'src/kameleoonData/types';\n\nexport class PageUtils {\n public static getLatest(\n pageViewData: NonNullable<KameleoonVisitorDataType[KameleoonData.PageView]>,\n ): PageViewDataType {\n return Object.values(pageViewData).reduce((latest, current) =>\n latest.timestamps[latest.timestamps.length - 1].time >\n current.timestamps[current.timestamps.length - 1].time\n ? latest\n : current,\n );\n }\n}\n"],"mappings":"6FAMO,KAAM,CAAAA,SAAU,CACrB,MAAc,CAAAC,SAASA,CACrBC,CAA2E,CACzD,CAClB,MAAO,CAAAC,MAAM,CAACC,MAAM,CAACF,CAAY,CAAC,CAACG,MAAM,CAAC,CAACC,CAAM,CAAEC,CAAO,GACxDD,CAAM,CAACE,UAAU,CAACF,CAAM,CAACE,UAAU,CAACC,MAAM,CAAG,CAAC,CAAC,CAACC,IAAI,CACpDH,CAAO,CAACC,UAAU,CAACD,CAAO,CAACC,UAAU,CAACC,MAAM,CAAG,CAAC,CAAC,CAACC,IAAI,CAClDJ,CAAM,CACNC,CACN,CACF,CACF,CAACI,OAAA,CAAAX,SAAA,CAAAA,SAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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,WAAWA,CAAAC,CAAA,CAA8C,IAA7C,CAAEC,SAAS,CAATA,CAAS,CAAEC,SAAS,CAATA,CAA6B,CAAC,CAAAF,CAAA,CAAAG,eAAA,+BAAAA,eAAA,0BACrD,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,CAAa,QAAGD,CAAa,WAAbA,CAAa,QAAbA,CAAa,CAAGE,4BAAa,CAACC,QAAQ,CAAC,CAE7D,GAAI,CAACF,CAAa,CAChB,MAAO,GAAAG,SAAE,IAAM,CAAC,CAGlB,GAAI,CAAAC,CAAW,CAAG,CAAC,CAMnB,MAJA,CAAAC,MAAM,CAACC,MAAM,CAACN,CAAa,CAAC,CAACO,OAAO,CAAEC,CAA0B,EAAK,CACnEJ,CAAW,EAAII,CAAQ,CAACC,UAAU,CAACC,MACrC,CAAC,CAAC,CAEK,GAAAP,SAAE,EAAC,IAAI,CAACQ,cAAc,CAACP,CAAW,CAAC,CAC5C,CAEQO,cAAcA,CAACP,CAAmB,CAAW,CACnD,GAAI,CAAC,IAAI,CAACV,SAAS,EAAmC,QAAQ,EAAvC,MAAO,KAAI,CAACG,cAA2B,CAC5D,SAGF,OAAQ,IAAI,CAACH,SAAS,EACpB,IAAK,CAAAkB,gBAAS,CAACC,KAAK,CAClB,MAAO,CAAAT,CAAW,GAAK,IAAI,CAACP,cAAc,CAC5C,IAAK,CAAAe,gBAAS,CAACE,OAAO,CACpB,MAAO,CAAAV,CAAW,CAAG,IAAI,CAACP,cAAc,CAC1C,IAAK,CAAAe,gBAAS,CAACG,KAAK,CAClB,MAAO,CAAAX,CAAW,CAAG,IAAI,CAACP,cAAc,CAC1C,QACE,QACJ,CACF,CACF,CAACmB,OAAA,CAAAzB,YAAA,CAAAA,YAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node.js","names":["Node","constructor","value","left","right","_defineProperty","isOperator","nodeValue","d","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,KAAAM,CAAA,CACL,KAAM,CAAAC,CAAM,CAAGC,4BAAgB,CAACC,eAAe,CAACT,CAAK,CAAC,CACtD,IAAI,CAACU,aAAa,SAAAJ,CAAA,CAAKN,CAAK,CAACW,SAAS,YAAAL,CAAA,GAAAA,CAAS,CAE3CC,CAAM,CAACK,EAAE,CACX,IAAI,CAACP,SAAS,CAAGE,CAAM,CAACM,IAAI,CAE5B,IAAI,CAACC,SAAS,CAAGP,CAAM,CAACQ,KAE5B,CAEA,IAAI,CAACC,SAAS,CAAGf,CAAI,CACrB,IAAI,CAACgB,UAAU,CAAGf,CACpB,CAEA,GAAI,CAAAF,KAAKA,CAAA,CAA8B,CACrC,MAAO,KAAI,CAACK,SACd,CAEA,GAAI,CAAAU,KAAKA,CAAA,CAA+B,CACtC,MAAO,KAAI,CAACD,SACd,CAEA,GAAI,CAAAb,IAAIA,CAAA,CAAsB,CAC5B,MAAO,KAAI,CAACe,SACd,CAEA,GAAI,CAAAd,KAAKA,CAAA,CAAsB,CAC7B,MAAO,KAAI,CAACe,UACd,CAEA,GAAI,CAAAC,OAAOA,CAAA,CAAY,CACrB,MAAO,KAAI,CAACR,aACd,CAEQN,UAAUA,CAACJ,CAAmC,CAAqB,CACzE,MAAO,CAAAA,CAAK,GAAKmB,eAAQ,CAACC,GAAG,EAAIpB,CAAK,GAAKmB,eAAQ,CAACE,EACtD,CACF,CAACC,OAAA,CAAAxB,IAAA,CAAAA,IAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
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,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G5B,CAAK,CAACiC,KAAK,CAAC,CAAC,CACpBJ,CAAK,CAAG7B,CAAK,CAACiC,KAAK,CAAC,CAAC,CAErBC,CAAO,CAAG,GAAI,CAAA7B,UAAI,CAAC2B,CAAQ,CAAEJ,CAAI,CAAEC,CAAK,CAAC,CAC/C7B,CAAK,CAACmC,OAAO,CAACD,CAAO,CACvB,CAEA,MAAO,CAAAlC,CAAK,CAAC,CAAC,CAChB,CAEQN,cAAcA,CAACL,CAAoB,CAAuB,MAC1D,CAAE+C,UAAU,CAAEtC,CAAU,CAAEuC,qBAAqB,CAAEtC,CAAU,CAAC,CAChEV,CAAO,CAACiD,cAAc,CAElB9C,CAA4C,CAAG,EAAE,CAavD,MAXA,CAAAM,CAAU,CAACyC,OAAO,CAAEtC,CAAS,EAAK,MAC1B,CAAEH,UAAU,CAAE0C,CAAa,CAAEC,WAAW,CAAXA,CAAY,CAAC,CAAGxC,CAAS,CAEtDyC,CAAK,CAAG,CACZ3C,SAAS,CAAE,IAAI,CAAC4C,gBAAgB,CAACF,CAAW,CAAC,CAC7C3C,UAAU,CAAE0C,CACd,CAAC,CAEDhD,CAAgB,CAACoD,IAAI,CAACF,CAAK,CAC7B,CAAC,CAAC,CAEK,CACLjD,iBAAiB,CAAE,IAAI,CAACkD,gBAAgB,CAAC5C,CAAS,CAAC,CACnDP,gBAAgB,CAAhBA,CACF,CACF,CAEQmD,gBAAgBA,CAAC5C,CAAoB,CAAc,CACzD,MAAO,CAAAA,CAAS,CAACH,GAAG,CAAEoC,CAAQ,EAAMA,CAAQ,CAAGN,eAAQ,CAACI,EAAE,CAAGJ,eAAQ,CAACC,GAAI,CAC5E,CACF,CAACkB,OAAA,CAAA1D,IAAA,CAAAA,IAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["Operator","exports","And","Or","ValueMatchType","TRUE","FALSE","EXACT","CONTAINS","REGULAR_EXPRESSION","EQUAL","LOWER","GREATER","UNDEFINED","AMONG_VALUES","RANGE","VisitorType","NEW","RETURNING","MatchTypeVariation","ANY","MatchTypeTest","ALL","TEST","PERSO","MatchType","VersionMatchType","NameMatchType","OPTIONAL","TargetingType","PAGE_URL","PAGE_TITLE","LANDING_PAGE","ORIGIN","ORIGIN_TYPE","REFERRERS","NEW_VISITORS","INTERESTS","BROWSER_LANGUAGE","GEOLOCATION","DEVICE_TYPE","SCREEN_DIMENSION","VISITOR_IP","AD_BLOCKER","PREVIOUS_PAGE","KEY_PAGES","PAGE_VIEWS","FIRST_VISIT","LAST_VISIT","ACTIVE_SESSION","TIME_SINCE_PAGE_LOAD","SAME_DAY_VISITS","VISITS","VISITS_BY_PAGE","VISITOR_CODE","SDK_LANGUAGE","INTERNAL_SEARCH_KEYWORDS","TABS_ON_SITE","CONVERSION_PROBABILITY","HEAT_SLICE","SKY_STATUS","TEMPERATURE","DAY_NIGHT","FORECAST_SKY_STATUS","FORECAST_TEMPERATURE","DAY_OF_WEEK","TIME_RANGE","HOUR_MINUTE_RANGE","JS_CODE","COOKIE","EVENT","BROWSER","OPERATING_SYSTEM","DOM_ELEMENT","MOUSE_OUT","TARGET_EXPERIMENT","TARGET_FEATURE_FLAG","TARGET_PERSONALIZATION","EXCLUSIVE_EXPERIMENT","EXCLUSIVE_FEATURE_FLAG","CONVERSIONS","CUSTOM_DATUM","YSANCE_SEGMENT","SEGMENT","YSANCE_ATTRIBUT","TEALIUM_BADGE","TEALIUM_AUDIENCE","PRICE_OF_DISPLAYED_PAGE","NUMBER_OF_VISITED_PAGES","VISITED_PAGES","CUSTOM","EXPLICIT_TRIGGER","APPLICATION_VERSION"],"sources":["../../src/targeting/types.ts"],"sourcesContent":["import { MappedRuleType } from 'src/clientConfiguration/types';\nimport { KameleoonVisitorDataType } from 'src/kameleoonData/types';\nimport { FeatureFlagVariationsType } from 'src/storage/types';\nimport { ExternalPackageInfoType } from 'src/types';\nimport { ConditionDataType, ConditionType } from './conditions';\nimport { Node } from './node';\nimport { Tree } from './tree';\n\nexport enum Operator {\n And = 'AND',\n Or = 'OR',\n}\n\nexport type NonLeafNodeType = {\n left: Node;\n right: Node;\n value: Operator;\n};\n\nexport type LeafNodeType = {\n left: undefined;\n right: undefined;\n value: ConditionType;\n};\n\nexport type NodeValueType = ConditionType | Operator;\n\nexport type ConditionLevelType = {\n orOperators: boolean[];\n conditions: ConditionDataType[];\n};\n\nexport type SegmentType = {\n id: string;\n name: string;\n conditionsData: {\n firstLevelOrOperators: boolean[];\n firstLevel: ConditionLevelType[];\n };\n};\n\nexport type NestedConditionGroupType = {\n operators: Operator[];\n conditions: ConditionDataType[];\n};\n\nexport type GroupedSegmentsType = {\n topLevelOperators: Operator[];\n nestedConditions: NestedConditionGroupType[];\n};\n\nexport type VisitorReference = string;\n\nexport type TargetingDataType = {\n [visitorCode: string]: KameleoonVisitorDataType | VisitorReference;\n};\n\nexport type DereferencedTargetingDataType = {\n [visitorCode: string]: KameleoonVisitorDataType;\n};\n\nexport type EvaluationDataType = {\n targetingData?: KameleoonVisitorDataType;\n variationData: FeatureFlagVariationsType;\n ruleMap?: Map<number, MappedRuleType>;\n sdkInfo: ExternalPackageInfoType;\n experimentId: number | null;\n visitorCode: string;\n segments?: Map<string, SegmentType>;\n trees?: Map<string, Tree>;\n};\n\nexport enum ValueMatchType {\n TRUE = 'TRUE',\n FALSE = 'FALSE',\n EXACT = 'EXACT',\n CONTAINS = 'CONTAINS',\n REGULAR_EXPRESSION = 'REGULAR_EXPRESSION',\n EQUAL = 'EQUAL',\n LOWER = 'LOWER',\n GREATER = 'GREATER',\n UNDEFINED = 'UNDEFINED',\n AMONG_VALUES = 'AMONG_VALUES',\n RANGE = 'RANGE',\n}\n\nexport enum VisitorType {\n NEW = 'NEW',\n RETURNING = 'RETURNING',\n}\n\nexport enum MatchTypeVariation {\n ANY = 'ANY',\n EXACT = 'EXACT',\n}\n\nexport enum MatchTypeTest {\n ALL = 'ALL',\n TEST = 'TEST',\n PERSO = 'PERSO',\n}\n\n// --- Note ---\n// Starting the merge of `matchType` with the release of new conditions\n// Now it contains a couple of sub types, in future API version all match types\n// will be accumulated in this enum\nexport enum MatchType {\n // -- Sub Type One\n EXACT = 'EXACT',\n CONTAINS = 'CONTAINS',\n REGULAR_EXPRESSION = 'REGULAR_EXPRESSION',\n // -- Sub Type Two\n GREATER = 'GREATER',\n EQUAL = 'EQUAL',\n LOWER = 'LOWER',\n}\n\nexport enum VersionMatchType {\n GREATER = 'GREATER',\n EQUAL = 'EQUAL',\n LOWER = 'LOWER',\n}\n\nexport enum NameMatchType {\n EXACT = 'EXACT',\n CONTAINS = 'CONTAINS',\n REGULAR_EXPRESSION = 'REGULAR_EXPRESSION',\n OPTIONAL = 'OPTIONAL',\n}\n\nexport enum TargetingType {\n PAGE_URL = 'PAGE_URL',\n PAGE_TITLE = 'PAGE_TITLE',\n LANDING_PAGE = 'LANDING_PAGE',\n ORIGIN = 'ORIGIN',\n ORIGIN_TYPE = 'ORIGIN_TYPE',\n REFERRERS = 'REFERRERS',\n NEW_VISITORS = 'NEW_VISITORS',\n INTERESTS = 'INTERESTS',\n BROWSER_LANGUAGE = 'BROWSER_LANGUAGE',\n GEOLOCATION = 'GEOLOCATION',\n DEVICE_TYPE = 'DEVICE_TYPE',\n SCREEN_DIMENSION = 'SCREEN_DIMENSION',\n VISITOR_IP = 'VISITOR_IP',\n AD_BLOCKER = 'AD_BLOCKER',\n PREVIOUS_PAGE = 'PREVIOUS_PAGE',\n KEY_PAGES = 'KEY_PAGES',\n PAGE_VIEWS = 'PAGE_VIEWS',\n FIRST_VISIT = 'FIRST_VISIT',\n LAST_VISIT = 'LAST_VISIT',\n ACTIVE_SESSION = 'ACTIVE_SESSION',\n TIME_SINCE_PAGE_LOAD = 'TIME_SINCE_PAGE_LOAD',\n SAME_DAY_VISITS = 'SAME_DAY_VISITS',\n VISITS = 'VISITS',\n VISITS_BY_PAGE = 'VISITS_BY_PAGE',\n VISITOR_CODE = 'VISITOR_CODE',\n SDK_LANGUAGE = 'SDK_LANGUAGE',\n INTERNAL_SEARCH_KEYWORDS = 'INTERNAL_SEARCH_KEYWORDS',\n TABS_ON_SITE = 'TABS_ON_SITE',\n CONVERSION_PROBABILITY = 'CONVERSION_PROBABILITY',\n HEAT_SLICE = 'HEAT_SLICE',\n SKY_STATUS = 'SKY_STATUS',\n TEMPERATURE = 'TEMPERATURE',\n DAY_NIGHT = 'DAY_NIGHT',\n FORECAST_SKY_STATUS = 'FORECAST_SKY_STATUS',\n FORECAST_TEMPERATURE = 'FORECAST_TEMPERATURE',\n DAY_OF_WEEK = 'DAY_OF_WEEK',\n TIME_RANGE = 'TIME_RANGE',\n HOUR_MINUTE_RANGE = 'HOUR_MINUTE_RANGE',\n JS_CODE = 'JS_CODE',\n COOKIE = 'COOKIE',\n EVENT = 'EVENT',\n BROWSER = 'BROWSER',\n OPERATING_SYSTEM = 'OPERATING_SYSTEM',\n DOM_ELEMENT = 'DOM_ELEMENT',\n MOUSE_OUT = 'MOUSE_OUT',\n TARGET_EXPERIMENT = 'TARGET_EXPERIMENT',\n TARGET_FEATURE_FLAG = 'TARGET_FEATURE_FLAG',\n TARGET_PERSONALIZATION = 'TARGET_PERSONALIZATION',\n EXCLUSIVE_EXPERIMENT = 'EXCLUSIVE_EXPERIMENT',\n EXCLUSIVE_FEATURE_FLAG = 'EXCLUSIVE_FEATURE_FLAG',\n CONVERSIONS = 'CONVERSIONS',\n CUSTOM_DATUM = 'CUSTOM_DATUM',\n YSANCE_SEGMENT = 'YSANCE_SEGMENT',\n SEGMENT = 'SEGMENT',\n YSANCE_ATTRIBUT = 'YSANCE_ATTRIBUT',\n TEALIUM_BADGE = 'TEALIUM_BADGE',\n TEALIUM_AUDIENCE = 'TEALIUM_AUDIENCE',\n PRICE_OF_DISPLAYED_PAGE = 'PRICE_OF_DISPLAYED_PAGE',\n NUMBER_OF_VISITED_PAGES = 'NUMBER_OF_VISITED_PAGES',\n VISITED_PAGES = 'VISITED_PAGES',\n CUSTOM = 'CUSTOM',\n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AAb5B,CAAa,CAAA6B,sBAAA,0BAAb7B,CAAa,CAAA8B,UAAA,cAAb9B,CAAa,CAAA+B,UAAA,cAAb/B,CAAa,CAAAgC,WAAA,eAAbhC,CAAa,CAAAiC,SAAA,aAAbjC,CAAa,CAAAkC,mBAAA,uBAAblC,CAAa,CAAAmC,oBAAA,wBAAbnC,CAAa,CAAAoC,WAAA,eAAbpC,CAAa,CAAAqC,UAAA,cAAbrC,CAAa,CAAAsC,iBAAA,qBAAbtC,CAAa,CAAAuC,OAAA,WAAbvC,CAAa,CAAAwC,MAAA,UAAbxC,CAAa,CAAAyC,KAAA,SAAbzC,CAAa,CAAA0C,OAAA,WAAb1C,CAAa,CAAA2C,gBAAA,oBAAb3C,CAAa,CAAA4C,WAAA,eAAb5C,CAAa,CAAA6C,SAAA,aAAb7C,CAAa,CAAA8C,iBAAA,qBAAb9C,CAAa,CAAA+C,mBAAA,uBAAb/C,CAAa,CAAAgD,sBAAA,0BAAbhD,CAAa,CAAAiD,oBAAA,wBAAbjD,CAAa,CAAAkD,sBAAA,0BAAblD,CAAa,CAAAmD,WAAA,eAAbnD,CAAa,CAAAoD,YAAA,gBAAbpD,CAAa,CAAAqD,cAAA,kBAAbrD,CAAa,CAAAsD,OAAA,WAAbtD,CAAa,CAAAuD,eAAA,mBAAbvD,CAAa,CAAAwD,aAAA,iBAAbxD,CAAa,CAAAyD,gBAAA,oBAAbzD,CAAa,CAAA0D,uBAAA,2BAAb1D,CAAa,CAAA2D,uBAAA,2BAAb3D,CAAa,CAAA4D,aAAA,iBAAb5D,CAAa,CAAA6D,MAAA,UAAb7D,CAAa,CAAA8D,gBAAA,oBAAb9D,CAAa,CAAA+D,mBAAA,uBAAb/D,CAAa","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bodyProvider.js","names":["BodyProvider","constructor","prng","_defineProperty","getTrackingBody","result","body","resultBody","join","hasUserAgent","cleanup","addData","a","visitorCode","variationData","visitorData","userAgent","isConsentProvided","isMappingIdentifier","lines","variationDataLines","getVariationDataLines","visitorDataLines","getVisitorDataLines","push","addVisitorTrackingLines","data","nonce","type","KameleoonData","Conversion","PageView","nonceValue","Utilities","getNonce","url","UrlParameter","Nonce","forEach","item","UrlEventType","Experiment","Id","experimentId","VariationId","variationId","prepareVisitorBody","trackingVisitors","Err","identifier","getIdentifier","length","value","index","activityLine","getActivityLine","UserAgent","checkSize","ok","currentSize","size","reduce","acc","line","SYMBOL_SIZE","MAX_BODY_SIZE","Ok","Activity","MappingValue","VisitorCode","exports"],"sources":["../../src/tracking/bodyProvider.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport {\n Conversion,\n KameleoonData,\n KameleoonDataType,\n PageView,\n} from 'src/kameleoonData';\nimport { UrlEventType, UrlParameter } from 'src/requester';\nimport { IExternalPRNG, Utilities } from 'src/utilities';\nimport {\n AddDataParametersType,\n AddVisitorTrackingLineParametersType,\n GetTrackingBodyResultType,\n VisitorTrackingDataType,\n} from './types';\nimport { MAX_BODY_SIZE, SYMBOL_SIZE } from './constants';\nimport { BaseVariationDataType } from 'src/variationConfiguration/types';\n\ninterface IBodyProvider {\n getTrackingBody: (visitorCode: string) => GetTrackingBodyResultType;\n addData: ({\n visitorCode,\n variationData,\n visitorData,\n userAgent,\n isConsentProvided,\n isMappingIdentifier,\n }: AddDataParametersType) => Result<void, void>;\n}\n\nexport class BodyProvider implements IBodyProvider {\n private prng: IExternalPRNG;\n private currentSize = 0;\n private resultBody: string[] = [];\n private hasUserAgent = false;\n private trackingVisitors: {\n [visitorCode: string]: VisitorTrackingDataType;\n } = {};\n\n constructor(prng: IExternalPRNG) {\n this.prng = prng;\n }\n\n public getTrackingBody(): GetTrackingBodyResultType {\n const result = {\n body: this.resultBody.join('\\n'),\n hasUserAgent: this.hasUserAgent,\n };\n\n this.cleanup();\n\n return result;\n }\n\n public addData({\n visitorCode,\n variationData,\n visitorData,\n userAgent,\n isConsentProvided,\n isMappingIdentifier,\n }: AddDataParametersType): Result<void, void> {\n const lines: string[] = [];\n\n const variationDataLines = this.getVariationDataLines(variationData);\n const visitorDataLines = this.getVisitorDataLines(visitorData);\n\n lines.push(...visitorDataLines, ...variationDataLines);\n\n return this.addVisitorTrackingLines({\n visitorCode,\n lines,\n userAgent,\n isConsentProvided,\n isMappingIdentifier,\n });\n }\n\n private getVisitorDataLines(visitorData: KameleoonDataType[]): string[] {\n const lines: string[] = [];\n\n for (const data of visitorData) {\n let nonce;\n\n if (\n data.data.type === KameleoonData.Conversion ||\n data.data.type === KameleoonData.PageView\n ) {\n const nonceValue = (data as Conversion | PageView).data.nonce;\n\n if (nonceValue) {\n nonce = nonceValue;\n } else {\n nonce = Utilities.getNonce(this.prng);\n (data as Conversion | PageView).data.nonce = nonce;\n }\n }\n\n if (!nonce) {\n nonce = Utilities.getNonce(this.prng);\n }\n\n lines.push(data.url + UrlParameter.Nonce + nonce);\n }\n\n return lines;\n }\n\n private getVariationDataLines(\n variationData: BaseVariationDataType[],\n ): string[] {\n const lines: string[] = [];\n\n variationData.forEach((item) => {\n lines.push(\n UrlEventType.Experiment +\n UrlParameter.Id +\n item.experimentId +\n UrlParameter.VariationId +\n item.variationId +\n UrlParameter.Nonce +\n Utilities.getNonce(this.prng),\n );\n });\n\n return lines;\n }\n\n private prepareVisitorBody(visitorCode: string): Result<void, void> {\n const visitorData = this.trackingVisitors[visitorCode];\n\n if (!visitorData) {\n return Err();\n }\n\n const { lines, userAgent, isMappingIdentifier, isConsentProvided } =\n visitorData;\n\n const identifier = this.getIdentifier(visitorCode, isMappingIdentifier);\n\n if (lines.length) {\n lines.forEach((value, index) => {\n lines[index] = value + identifier;\n });\n } else if (isConsentProvided) {\n const activityLine = this.getActivityLine();\n\n lines.push(activityLine + identifier);\n }\n\n if (userAgent && lines.length) {\n lines[0] += UrlParameter.UserAgent + userAgent;\n this.hasUserAgent = true;\n }\n\n // --- Note ---\n // Improve after `ts-res` chaining update\n const result = this.checkSize(lines);\n\n if (result.ok) {\n this.resultBody.push(...lines);\n }\n\n return result;\n }\n\n private cleanup(): void {\n this.currentSize = 0;\n this.resultBody = [];\n this.hasUserAgent = false;\n this.trackingVisitors = {};\n }\n\n private checkSize(lines: string[]): Result<void, void> {\n let size = 0;\n size += lines.reduce((acc, line) => acc + line.length * SYMBOL_SIZE, 0);\n\n if (size + this.currentSize > MAX_BODY_SIZE) {\n return Err();\n }\n\n this.currentSize += size;\n\n return Ok();\n }\n\n private addVisitorTrackingLines({\n visitorCode,\n lines,\n userAgent,\n isConsentProvided,\n isMappingIdentifier,\n }: AddVisitorTrackingLineParametersType): Result<void, void> {\n if (!this.trackingVisitors[visitorCode]) {\n this.trackingVisitors[visitorCode] = {\n isMappingIdentifier,\n isConsentProvided,\n userAgent,\n lines,\n };\n } else {\n if (userAgent) {\n this.trackingVisitors[visitorCode].userAgent = userAgent;\n }\n\n this.trackingVisitors[visitorCode].lines.push(...lines);\n }\n\n return this.prepareVisitorBody(visitorCode);\n }\n\n private getActivityLine(): string {\n return (\n UrlEventType.Activity + UrlParameter.Nonce + Utilities.getNonce(this.prng)\n );\n }\n\n private getIdentifier(\n visitorCode: string,\n isMappingIdentifier: boolean,\n ): string {\n const identifier = isMappingIdentifier\n ? UrlParameter.MappingValue\n : UrlParameter.VisitorCode;\n\n return identifier + visitorCode;\n }\n}\n"],"mappings":"ixBA8BO,KAAM,CAAAA,YAAsC,CASjDC,WAAWA,CAACC,CAAmB,CAAE,CAAAC,eAAA,qBAAAA,eAAA,oBAPX,CAAC,EAAAA,eAAA,mBACQ,EAAE,EAAAA,eAAA,yBAAAA,eAAA,yBAI7B,CAAC,CAAC,EAGJ,IAAI,CAACD,IAAI,CAAGA,CACd,CAEOE,eAAeA,CAAA,CAA8B,CAClD,KAAM,CAAAC,CAAM,CAAG,CACbC,IAAI,CAAE,IAAI,CAACC,UAAU,CAACC,IAAI,CAAC,IAAI,CAAC,CAChCC,YAAY,CAAE,IAAI,CAACA,YACrB,CAAC,CAID,MAFA,KA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,EAQjCG,CAAS,GACX,IAAI,CAAC+B,gBAAgB,CAAClC,CAAW,CAAC,CAACG,SAAS,CAAGA,CAAS,EAG1D,IAAI,CAAC+B,gBAAgB,CAAClC,CAAW,CAAC,CAACM,KAAK,CAACK,IAAI,CAAC,GAAGL,CAAK,CAAC,EAXvD,IAAI,CAAC4B,gBAAgB,CAAClC,CAAW,CAAC,CAAG,CACnCK,mBAAmB,CAAnBA,CAAmB,CACnBD,iBAAiB,CAAjBA,CAAiB,CACjBD,SAAS,CAATA,CAAS,CACTG,KAAK,CAALA,CACF,CAAC,CASI,IAAI,CAAC2B,kBAAkB,CAACjC,CAAW,CAC5C,CAEQ0C,eAAeA,CAAA,CAAW,CAChC,MACE,CAAAf,uBAAY,CAAC2B,QAAQ,CAAG/B,uBAAY,CAACC,KAAK,CAAGJ,oBAAS,CAACC,QAAQ,CAAC,IAAI,CAAChC,IAAI,CAE7E,CAEQgD,aAAaA,CACnBrC,CAAmB,CACnBK,CAA4B,CACpB,CACR,KAAM,CAAA+B,CAAU,CAAG/B,CAAmB,CAClCkB,uBAAY,CAACgC,YAAY,CACzBhC,uBAAY,CAACiC,WAAW,CAE5B,MAAO,CAAApB,CAAU,CAAGpC,CACtB,CACF,CAACyD,OAAA,CAAAtE,YAAA,CAAAA,YAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["Byte","Kb","Mb","Gb","MAX_BODY_SIZE","exports","SYMBOL_SIZE"],"sources":["../../src/tracking/constants.ts"],"sourcesContent":["enum Byte {\n Kb = 1_000,\n Mb = 1_000 * Byte.Kb,\n Gb = 1_000 * Byte.Mb,\n}\n\nexport const MAX_BODY_SIZE = 10 * Byte.Mb;\nexport const SYMBOL_SIZE = 4;\n"],"mappings":"wHAAK,CAAAA,IAAI,UAAJA,CAAI,QAAJ,CAAAA,CAAI,CAAJA,CAAI,CAAAC,EAAA,YAAJD,CAAI,CAAJA,CAAI,CAAAE,EAAA,CAEF,GAAK,CAAGF,CAAI,CAACC,EAAE,OAFjBD,CAAI,CAAJA,CAAI,CAAAG,EAAA,CAGF,GAAK,CAAGH,CAAI,CAACE,EAAE,OAHjBF,CAAI,EAAJA,IAAI,WAMI,CAAAI,aAAa,CAAAC,OAAA,CAAAD,aAAA,CAAG,EAAE,CAAGJ,IAAI,CAACE,EAAE,CAC5BI,WAAW,CAAAD,OAAA,CAAAC,WAAA,CAAG,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_tracker","require","Object","defineProperty","exports","value","enumerable","get","Tracker"],"sources":["../../src/tracking/index.ts"],"sourcesContent":["export { Tracker } from './tracker';\n"],"mappings":"aAAA,IAAAA,QAAA,CAAAC,OAAA,cAAoCC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAH,MAAA,CAAAC,cAAA,CAAAC,OAAA,YAAAE,UAAA,IAAAC,GAAA,SAAAA,CAAA,SAAAP,QAAA,CAAAQ,OAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.js","names":["Tracker","constructor","a","dataManager","trackingStorage","variationConfiguration","trackingInterval","requester","prng","_defineProperty","bodyProvider","BodyProvider","intervalId","setInterval","sendData","err","clearInterval","scheduleVisitor","visitorCode","isConsentProvided","read","and","trackingData","scheduledVisitors","write","checkIsIdentifier","isUniqueIdentifier","isMappingIdentifier","linkedVisitor","getLinkedVisitor","index","identifierCustomDataIndex","storeData","CustomData","getUserAgent","targetingData","getVisitorData","userAgentData","KameleoonData","UserAgent","value","pendingData","storageResult","ok","data","trackedVisitors","Object","entries","userAgent","visitorData","getUnsentVisitorData","variationData","getUnsentVariationData","result","addData","push","body","hasUserAgent","getTrackingBody","track","updateDataStatus","TrackingStatus","Sent","forEach","Unsent","status","updatedData","map","dataItem","experimentIdList","experimentId","storeTrackedData","unsentData","getUnsentData","resultData","length","url","type","Conversion","Pending","sentExperimentIds","Set","filter","item","isIncluded","isTargetedRule","add","Array","from","exports"],"sources":["../../src/tracking/tracker.ts"],"sourcesContent":["import {\n CustomData,\n DataManager,\n KameleoonData,\n KameleoonDataType,\n} from 'src/kameleoonData';\nimport { Requester } from 'src/requester';\nimport { VariationConfiguration } from 'src/variationConfiguration';\nimport { PendingDataType, TrackerParametersType } from './types';\nimport { TrackingStatus } from 'src/types';\nimport { BaseVariationDataType } from 'src/variationConfiguration/types';\nimport { BodyProvider } from './bodyProvider';\nimport { IStorage, TrackingDataType } from 'src/storage';\n\ninterface ITracker {\n scheduleVisitor: (visitorCode: string, isConsentProvided: boolean) => void;\n}\n\nexport class Tracker implements ITracker {\n private dataManager: DataManager;\n private variationConfiguration: VariationConfiguration;\n private requester: Requester;\n private bodyProvider: BodyProvider;\n private intervalId: NodeJS.Timeout | null = null;\n private trackingStorage: IStorage<TrackingDataType>;\n\n constructor({\n dataManager,\n trackingStorage,\n variationConfiguration,\n trackingInterval,\n requester,\n prng,\n }: TrackerParametersType) {\n this.dataManager = dataManager;\n this.trackingStorage = trackingStorage;\n this.variationConfiguration = variationConfiguration;\n this.requester = requester;\n this.bodyProvider = new BodyProvider(prng);\n\n try {\n this.intervalId = setInterval(() => {\n this.sendData();\n }, trackingInterval);\n } catch (err) {\n this.intervalId && clearInterval(this.intervalId);\n\n throw err;\n }\n }\n\n public scheduleVisitor(\n visitorCode: string,\n isConsentProvided: boolean,\n ): void {\n this.trackingStorage.read().and((trackingData) => {\n trackingData.scheduledVisitors[visitorCode] = { isConsentProvided };\n this.trackingStorage.write(trackingData);\n });\n }\n\n private checkIsIdentifier(visitorCode: string): boolean {\n const isUniqueIdentifier = this.dataManager.isUniqueIdentifier(visitorCode);\n let isMappingIdentifier = false;\n\n // --- Note ---\n // This part is a workaround for Data API\n // If there's is no unique identifier for the visitor\n // We do reconciliation for visitor with himself\n if (isUniqueIdentifier) {\n const linkedVisitor = this.dataManager.getLinkedVisitor(visitorCode);\n const index = this.dataManager.identifierCustomDataIndex;\n\n if (!linkedVisitor && typeof index === 'number') {\n this.dataManager.storeData(\n visitorCode,\n new CustomData(index, visitorCode),\n );\n } else {\n isMappingIdentifier = true;\n }\n }\n\n return isMappingIdentifier;\n }\n\n private getUserAgent(visitorCode: string): string | undefined {\n const targetingData = this.dataManager.getVisitorData(visitorCode);\n\n if (targetingData) {\n const userAgentData = targetingData[KameleoonData.UserAgent];\n\n if (userAgentData) {\n return userAgentData.value;\n }\n }\n\n return undefined;\n }\n\n private async sendData(): Promise<void> {\n const pendingData: PendingDataType = {};\n const storageResult = this.trackingStorage.read();\n\n if (!storageResult.ok) {\n return;\n }\n\n const { scheduledVisitors } = storageResult.data;\n\n const trackedVisitors = [];\n\n for (const [visitorCode, { isConsentProvided }] of Object.entries(\n scheduledVisitors,\n )) {\n const isMappingIdentifier = this.checkIsIdentifier(visitorCode);\n const userAgent = this.getUserAgent(visitorCode);\n\n const visitorData = this.getUnsentVisitorData(\n visitorCode,\n isConsentProvided,\n );\n const variationData = this.getUnsentVariationData(\n visitorCode,\n isConsentProvided,\n );\n\n const result = this.bodyProvider.addData({\n visitorCode,\n variationData,\n visitorData,\n userAgent,\n isConsentProvided,\n isMappingIdentifier,\n });\n\n if (result.ok) {\n pendingData[visitorCode] = {\n visitorData,\n variationData,\n };\n trackedVisitors.push(visitorCode);\n } else {\n break;\n }\n }\n\n const { body, hasUserAgent } = this.bodyProvider.getTrackingBody();\n\n if (!body) {\n return;\n }\n\n const result = await this.requester.track(body, hasUserAgent);\n\n if (result.ok) {\n this.updateDataStatus(pendingData, TrackingStatus.Sent);\n trackedVisitors.forEach((visitorCode) => {\n delete scheduledVisitors[visitorCode];\n });\n this.trackingStorage.write({ scheduledVisitors });\n } else {\n this.updateDataStatus(pendingData, TrackingStatus.Unsent);\n }\n }\n\n private updateDataStatus(\n data: PendingDataType,\n status: TrackingStatus,\n ): void {\n let updatedData: { [visitorCode: string]: KameleoonDataType[] } = {};\n\n for (const [visitorCode, { visitorData, variationData }] of Object.entries(\n data,\n )) {\n updatedData[visitorCode] = visitorData.map((dataItem) => {\n dataItem.status = status;\n return dataItem;\n });\n\n const experimentIdList = variationData.map((dataItem) =>\n String(dataItem.experimentId),\n );\n\n this.variationConfiguration.updateDataStatus({\n visitorCode,\n experimentIdList,\n status,\n });\n }\n\n if (status === TrackingStatus.Sent) {\n this.dataManager.storeTrackedData(updatedData);\n } else {\n this.dataManager.storeData(updatedData);\n }\n }\n\n private getUnsentVisitorData(\n visitorCode: string,\n isConsentProvided: boolean,\n ): KameleoonDataType[] {\n const unsentData = this.dataManager.getUnsentData(visitorCode);\n const resultData: KameleoonDataType[] = [];\n\n if (!unsentData.length) {\n return [];\n }\n\n for (const data of unsentData) {\n if (\n !data.url ||\n (data.data.type !== KameleoonData.Conversion && !isConsentProvided)\n ) {\n continue;\n }\n\n resultData.push(data);\n }\n\n if (resultData.length) {\n const pendingData: KameleoonDataType[] = resultData.map(\n (data: KameleoonDataType) => {\n data.status = TrackingStatus.Pending;\n return data;\n },\n );\n\n this.dataManager.storeTrackedData({\n [visitorCode]: pendingData,\n });\n }\n\n return resultData;\n }\n\n private getUnsentVariationData(\n visitorCode: string,\n isConsentProvided: boolean,\n ): BaseVariationDataType[] {\n const unsentData = this.variationConfiguration.getUnsentData(visitorCode);\n const sentExperimentIds = new Set<string>();\n\n if (!unsentData.length) {\n return [];\n }\n\n const resultData = unsentData.filter((item) => {\n const isIncluded = item.isTargetedRule || isConsentProvided;\n\n if (isIncluded) {\n sentExperimentIds.add(String(item.experimentId));\n }\n\n return isIncluded;\n });\n\n this.variationConfiguration.updateDataStatus({\n visitorCode,\n experimentIdList: Array.from(sentExperimentIds),\n status: TrackingStatus.Pending,\n });\n\n return resultData;\n }\n}\n"],"mappings":"8sBAkBO,KAAM,CAAAA,OAA4B,CAQvCC,WAAWA,CAAAC,CAAA,CAOe,IAPd,CACVC,WAAW,CAAXA,CAAW,CACXC,eAAe,CAAfA,CAAe,CACfC,sBAAsB,CAAtBA,CA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B,OAAO,CAC7BnC,CAAI,CAEf,CAAC,CAED,IAAI,CAACzC,WAAW,CAACoE,gBAAgB,CAAC,CAChC,CAACrD,CAAW,EAAGuB,CACjB,CAAC,CACH,CAEA,MAAO,CAAAiC,CACT,CAEQtB,sBAAsBA,CAC5BlC,CAAmB,CACnBC,CAA0B,CACD,MACnB,CAAAqD,CAAU,CAAG,IAAI,CAACnE,sBAAsB,CAACoE,aAAa,CAACvD,CAAW,CAAC,CACnE8D,CAAiB,CAAG,GAAI,CAAAC,GAAa,CAE3C,GAAI,CAACT,CAAU,CAACG,MAAM,CACpB,MAAO,EAAE,CAGX,KAAM,CAAAD,CAAU,CAAGF,CAAU,CAACU,MAAM,CAAEC,CAAI,EAAK,CAC7C,KAAM,CAAAC,CAAU,CAAGD,CAAI,CAACE,cAAc,EAAIlE,CAAiB,CAM3D,MAJI,CAAAiE,CAAU,EACZJ,CAAiB,CAACM,GAAG,CAAQH,CAAI,CAACb,YAAY,GAAC,CAAC,CAG3Cc,CACT,CAAC,CAAC,CAQF,MANA,KAAI,CAAC/E,sBAAsB,CAACuD,gBAAgB,CAAC,CAC3C1C,WAAW,CAAXA,CAAW,CACXmD,gBAAgB,CAAEkB,KAAK,CAACC,IAAI,CAACR,CAAiB,CAAC,CAC/Cf,MAAM,CAAEJ,qBAAc,CAACkB,OACzB,CAAC,CAAC,CAEKL,CACT,CACF,CAACe,OAAA,CAAAzF,OAAA,CAAAA,OAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/tracking/types.ts"],"sourcesContent":["import { DataManager, KameleoonDataType } from 'src/kameleoonData';\nimport { Requester } from 'src/requester';\nimport { IStorage, TrackingDataType } from 'src/storage';\nimport { IExternalPRNG } from 'src/utilities';\nimport { VariationConfiguration } from 'src/variationConfiguration';\nimport { BaseVariationDataType } from 'src/variationConfiguration/types';\n\nexport type PendingDataType = {\n [visitorCode: string]: {\n visitorData: KameleoonDataType[];\n variationData: BaseVariationDataType[];\n };\n};\n\nexport type VisitorTrackingDataType = {\n isConsentProvided: boolean;\n userAgent: string | undefined;\n isMappingIdentifier: boolean;\n lines: string[];\n};\n\nexport type TrackerParametersType = {\n trackingStorage: IStorage<TrackingDataType>;\n trackingInterval: number;\n dataManager: DataManager;\n variationConfiguration: VariationConfiguration;\n requester: Requester;\n prng: IExternalPRNG;\n};\n\nexport type AddDataParametersType = {\n visitorCode: string;\n userAgent?: string;\n isConsentProvided: boolean;\n variationData: BaseVariationDataType[];\n visitorData: KameleoonDataType[];\n isMappingIdentifier: boolean;\n};\n\nexport type GetTrackingBodyResultType = { body: string; hasUserAgent: boolean };\n\nexport type AddVisitorTrackingLineParametersType = {\n isConsentProvided: boolean;\n isMappingIdentifier: boolean;\n visitorCode: string;\n lines: string[];\n userAgent?: string;\n};\n"],"mappings":"","ignoreList":[]}
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["_requester","require","Object","defineProperty","exports","value","VariableType","TrackingStatus","Milliseconds","Environment","Production","Staging","Development","BOOLEAN","NUMBER","STRING","JSON","JS","CSS","Sent","Unsent","Pending","Second","Minute","Hour","Day","Week","Month"],"sources":["../src/types.ts"],"sourcesContent":["import {\n ClientConfigurationDataType,\n ConfigurationDataType,\n JSONType,\n} from './clientConfiguration/types';\nimport { SdkLanguageType } from './constants';\nimport { IExternalEventSource } from './eventSource';\nimport { IExternalRequester, IUrlProvider, RequestType } from './requester';\nimport { IExternalStorage } from './storage';\nimport { IExternalPRNG, VisitorDataFiltersType } from './utilities';\nimport { IVisitorCodeManager } from './visitorCodeManager';\n\n/**\n * @param {number} updateInterval - update interval in _minutes_ for sdk configuration, minimum value is 1 minute\n * @defaultvalue 60\n *\n * @param {Environment} environment - feature flag environment\n * @defaultvalue Environment.Production\n *\n * @param {number | undefined} targetingDataCleanupInterval - interval in _minutes_ for cleaning up targeting data, minimum value is 1 minute\n * Note: if not specified, default value will be used\n * @defaultvalue\n * - JavaScript SDK: `undefined` (no cleanup)\n * - React/React Native SDK: `undefined` (no cleanup)\n * - NodeJS SDK: `30`\n *\n * @param {string | undefined} cookieDomain - domain which cookie which Kameleoon visitor code belongs to\n * @param {string | undefined} networkDomain - custom domain to be used in place of all requests URL, domain format is `example.com`, if the format is incorrect, default Kameleoon domain will be used\n * @param {number | undefined} requestTimeout - timeout in _milliseconds_ for requests\n * @defaultvalue `10_000` (10 seconds)\n * @param {number | undefined} trackingInterval - interval in _milliseconds_ for performing background tracking requests, must be a value between `100` to `1_000` milliseconds\n * @defaultvalue `1_000` (1 second)\n * */\nexport type SDKConfigurationType = {\n updateInterval?: number;\n environment?: Environment;\n targetingDataCleanupInterval?: number;\n requestTimeout?: number;\n networkDomain?: string;\n cookieDomain?: string;\n trackingInterval?: number;\n};\n\n/**\n * @param {string} urlProvider - main source for all URLs used in the SDK\n * */\nexport type DependenciesType = {\n urlProvider?: IUrlProvider;\n};\n\n/**\n * @param {string} siteCode - client's siteCode defined on Kameleoon platform\n * @param {Partial<SDKConfigurationType>} configuration - client's configuration\n * @param {InternalSDKConfigurationType} internalConfiguration - internal configuration for sdk core to be initialized with certain parameters to certain type of JavaScript SDK\n * @param {DependenciesType | undefined} dependencies - internal dependencies meant primarily for testing purposes\n * */\nexport type SDKCoreParameters = {\n siteCode: string;\n internalConfiguration: InternalSDKConfigurationType;\n configuration?: Partial<SDKConfigurationType>;\n dependencies?: DependenciesType;\n};\n\n/**\n * @param {SdkLanguageType} type - type of the SDK\n * @param {string} version - version of the package\n * */\nexport type ExternalPackageInfoType = {\n type: SdkLanguageType;\n version: string;\n};\n\n/**\n * @param {ExternalPackageInfoType} packageInfo - external package info, used to get package version and name\n * @param {IExternalPRNG | undefined} prng - external PRNG implementation\n * */\nexport type InternalsType = {\n packageInfo: ExternalPackageInfoType;\n prng?: IExternalPRNG;\n};\n\n/**\n * @param {IExternalStorage | undefined} externalStorage - external file system storage implemented outside client initialization\n * @param {IExternalEventSourceConstructor | undefined} externalEventSource - constructor for building external event source implementation\n * @param {ExternalPackageInfoType} externalPackageInfo - external package info, used to get package version and name\n * @param {IExternalRequester} externalRequester - external requester , used to track or get data\n * @param {IVisitorCodeManager} externalVisitorCodeManager - external visitor code manager, used to get or generate visitor code\n * */\nexport type ExternalsType = {\n externalStorage: IExternalStorage;\n externalEventSource: IExternalEventSource;\n externalVisitorCodeManager: IVisitorCodeManager;\n externalPackageInfo: ExternalPackageInfoType;\n externalRequester: IExternalRequester;\n externalPRNG: IExternalPRNG;\n};\n\n/**\n * @param {boolean} useAbortController - a flag to enable or disable usage of `AbortController` for requests allowing for `requestTimeout` to be respected\n * */\nexport type InternalSettingsType = {\n useAbortController: boolean;\n};\n\n/**\n * @param {ExternalsType} externals - external dependencies for the SDK\n * @param {InternalSettingsType} settings - internal settings for the SDK\n * */\nexport type InternalSDKConfigurationType = {\n externals: ExternalsType;\n settings: InternalSettingsType;\n};\n\n/**\n * @readonly\n * @enum {string} an Enum containing all possible variants of environment, passed as an argument to KameleoonClient `configuration`s `environment` field\n * */\nexport enum Environment {\n Production = 'production',\n Staging = 'staging',\n Development = 'development',\n}\n\n/**\n * @readonly\n * @enum {string} an Enum containing all possible variants of feature variable types\n * */\nexport enum VariableType {\n BOOLEAN = 'BOOLEAN',\n NUMBER = 'NUMBER',\n STRING = 'STRING',\n JSON = 'JSON',\n JS = 'JS',\n CSS = 'CSS',\n}\n\n/**\n * @readonly\n * @enum {string} an Enum containing all possible variants for data status\n * */\nexport enum TrackingStatus {\n Sent = 'sent',\n Unsent = 'unsent',\n Pending = 'pending',\n}\n\nexport type BooleanVariableType = {\n key: string;\n type: VariableType.BOOLEAN;\n value: boolean;\n};\n\nexport type NumberVariableType = {\n key: string;\n type: VariableType.NUMBER;\n value: number;\n};\n\nexport type StringVariableType = {\n key: string;\n type: VariableType.STRING;\n value: string;\n};\n\nexport type JSONVariableType = {\n key: string;\n type: VariableType.JSON;\n value: JSONType;\n};\n\nexport type JSVariableType = {\n key: string;\n type: VariableType.JS;\n value: string;\n};\n\nexport type CSSVariableType = {\n key: string;\n type: VariableType.CSS;\n value: string;\n};\n\n/**\n * @type `FeatureVariableResultType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type FeatureVariableResultType =\n | BooleanVariableType\n | NumberVariableType\n | JSVariableType\n | CSSVariableType\n | StringVariableType\n | JSONVariableType;\n\n/**\n * @type `FeatureFlagVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type FeatureFlagVariableType = Omit<FeatureVariableResultType, 'key'>;\n\n/**\n * @readonly\n * @enum {number} a helper Enum for getting milliseconds for a second/minute/hour/day/week/month.\n * Month is considered as an average of 30 days\n * */\nexport enum Milliseconds {\n Second = 1000,\n Minute = 60 * Milliseconds.Second,\n Hour = 60 * Milliseconds.Minute,\n Day = 24 * Milliseconds.Hour,\n Week = 7 * Milliseconds.Day,\n Month = 30 * Milliseconds.Day,\n}\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {number} goalId - an id of a goal to track\n * @param {number | undefined} revenue - an optional parameter for revenue, default value is `0`\n * */\nexport type TrackConversionParamsType = {\n visitorCode: string;\n goalId: number;\n revenue?: number;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {boolean | undefined} shouldAddData - optional parameter for adding retrieved data to the storage like `addData` method does, default value is `true`\n * @param {VisitorDataFiltersType | undefined} filters - optional parameter for specifying the filters for which data should be retrieved from what visit, by default only current and latest previous visits' `customData` is retrieved\n * */\nexport type RemoteVisitorDataParamsType = {\n visitorCode: string;\n shouldAddData?: boolean;\n filters?: VisitorDataFiltersType;\n};\n\nexport type GetFeatureVariablesParamsType = {\n visitorCode: string;\n featureKey: string;\n variationKey: string;\n};\n\nexport type FeatureFlagType = {\n id: number;\n key: string;\n};\n\n/**\n * @type `KameleoonVariableType` - tuple of possible feature variable result types, each possible variation is an object containing `key`, `type` and `value` fields, `type` can be checked against `VariableType` enum, if the `type` is `VariableType.BOOLEAN` then the `value` type will be `boolean` and so on.\n * */\nexport type KameleoonVariableType = FeatureVariableResultType;\n\n/**\n * @type `KameleoonVariationType` - object containing information about the variation and its variables\n * @param {string} key - key of the variation\n * @param {number | null} id - id of the variation or `null` if the visitor hit default variation\n * @param {number | null} experimentId - id of the experiment or `null` if the visitor hit default variation\n * @param {KameleoonVariableType[]} variables - array of variables for the variation\n * */\nexport type KameleoonVariationType = {\n key: string;\n id: number | null;\n experimentId: number | null;\n variables: KameleoonVariableType[];\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {string} featureKey - key of the feature flag to look for, can be found on Kameleoon Platform\n * @param {string} variableKey - key of the variable to be found for a feature flag with provided `featureKey`, can be found on Kameleoon Platform\n * */\nexport type GetFeatureFlagVariableParamsType = {\n visitorCode: string;\n featureKey: string;\n variableKey: string;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identification string, can't exceed 255 characters length\n * @param {number} customDataIndex - index of the custom data in the warehouse audience\n * @param {string | undefined} warehouseKey - unique key to identify the warehouse data (usually internal user ID)\n * If not specified, the `visitorCode` will be used as a `warehouseKey`\n * */\nexport type GetVisitorWarehouseAudienceParamsType = {\n visitorCode: string;\n customDataIndex: number;\n warehouseKey?: string;\n};\n\nexport type WarehouseAudienceType = {\n // --- Note ---\n // Using `unknown` type here because we don't care about the type of the value\n warehouseAudiences: Record<string, unknown>;\n};\n\nexport type TrackingCacheItemType = {\n [experimentId: number]: {\n variationId: number;\n expirationTime: number;\n hasJsCssVariables: boolean;\n };\n};\n\nexport type SetDataCallbackParametersType = {\n visitorCode: string;\n maxAge: number;\n path: string;\n key: string;\n};\n\n/**\n * @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters\n * @param {boolean} consent - a value representing the legal consent status. - 'true' indicates the\n * visitor has given legal consent. - 'false' indicates the visitor has withdrawn or not\n * provided legal consent.\n * @param {(visitorCode: string) => void} setData - a callback to set a visitor code in cookie\n * */\nexport type SetUserConsentParametersType = {\n visitorCode: string;\n consent: boolean;\n setData: ({\n visitorCode,\n maxAge,\n path,\n }: SetDataCallbackParametersType) => void;\n};\n\n/**\n * @type `SimulateRequestDataType` a type of data provided to `simulateSuccessRequest` method depending on `RequestType`\n * */\nexport type SimulateRequestDataType = {\n [RequestType.Configuration]: ClientConfigurationDataType;\n [RequestType.RemoteData]: JSONType;\n [RequestType.Tracking]: null;\n};\n"],"mappings":"aAOA,IAAAA,UAAA,CAAAC,OAAA,gBAA4EC,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAD,OAAA,CAAAE,YAAA,CAAAF,OAAA,CAAAG,cAAA,CAAAH,OAAA,CAAAI,YAAA,CAAAJ,OAAA,CAAAK,WAAA,WA8GhE,CAAAA,WAAW,CAAAL,OAAA,CAAAK,WAAA,UAAXA,CAAW,QAAX,CAAAA,CAAW,CAAAC,UAAA,cAAXD,CAAW,CAAAE,OAAA,WAAXF,CAAW,CAAAG,WAAA,eAAXH,CAAW,MAUXH,YAAY,CAAAF,OAAA,CAAAE,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAAO,OAAA,WAAZP,CAAY,CAAAQ,MAAA,UAAZR,CAAY,CAAAS,MAAA,UAAZT,CAAY,CAAAU,IAAA,QAAZV,CAAY,CAAAW,EAAA,MAAZX,CAAY,CAAAY,GAAA,OAAZZ,CAAY,MAaZC,cAAc,CAAAH,OAAA,CAAAG,cAAA,UAAdA,CAAc,QAAd,CAAAA,CAAc,CAAAY,IAAA,QAAdZ,CAAc,CAAAa,MAAA,UAAdb,CAAc,CAAAc,OAAA,WAAdd,CAAc,MA+DdC,YAAY,CAAAJ,OAAA,CAAAI,YAAA,UAAZA,CAAY,QAAZ,CAAAA,CAAY,CAAZA,CAAY,CAAAc,MAAA,gBAAZd,CAAY,CAAZA,CAAY,CAAAe,MAAA,CAEb,EAAE,CAAGf,CAAY,CAACc,MAAM,WAFvBd,CAAY,CAAZA,CAAY,CAAAgB,IAAA,CAGf,EAAE,CAAGhB,CAAY,CAACe,MAAM,SAHrBf,CAAY,CAAZA,CAAY,CAAAiB,GAAA,CAIhB,EAAE,CAAGjB,CAAY,CAACgB,IAAI,QAJlBhB,CAAY,CAAZA,CAAY,CAAAkB,IAAA,CAKf,CAAC,CAAGlB,CAAY,CAACiB,GAAG,SALjBjB,CAAY,CAAZA,CAAY,CAAAmB,KAAA,CAMd,EAAE,CAAGnB,CAAY,CAACiB,GAAG,UANnBjB,CAAY","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["HEX_CHARACTERS","exports","NONCE_LENGTH"],"sources":["../../src/utilities/constants.ts"],"sourcesContent":["export const HEX_CHARACTERS = '0123456789ABCDEF';\nexport const NONCE_LENGTH = 16;\n"],"mappings":"4HAAa,CAAAA,cAAc,CAAAC,OAAA,CAAAD,cAAA,CAAG,kBAAkB,CACnCE,YAAY,CAAAD,OAAA,CAAAC,YAAA,CAAG,EAAE","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/utilities/index.ts"],"sourcesContent":["export { Utilities } from './utilities';\nexport { Parser } from './parser';\nexport { Validator } from './validator';\nexport {\n VisitorDataFiltersType,\n TimeUnit,\n Order,\n IExternalPRNG,\n} from './types';\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","names":["Parser","parseFeatureVariable","variable","key","type","value","VariableType","BOOLEAN","Ok","JS","CSS","STRING","NUMBER","numberValue","Number","isNaN","Err","KameleoonError","KameleoonException","NumberParse","JSON","jsonValue","parse","err","JSONParse","exhaustCheck","parseVisitorData","a","data","filters","visitorCode","dataManager","variationConfiguration","visitProcessor","VisitProcessor","currentVisit","previousVisits","kcs","visits","push","length","visitorData","storageVisitorData","forEach","visit","processVisit","processKcs","processMultipleDataTypes","visitsData","experimentData","updateStoredVariations","parseRegExp","_","expression","flags","split","RegExp","exports"],"sources":["../../src/utilities/parser.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { FeatureVariableType, JSONType } from 'src/clientConfiguration';\nimport {\n KameleoonError,\n KameleoonException,\n exhaustCheck,\n} from 'src/kameleoonError';\nimport { FeatureVariableResultType, VariableType } from 'src/types';\nimport {\n ParseVisitorDataParametersType,\n ParseVisitorDataResultType,\n} from './types';\nimport { VisitType } from 'src/requester';\nimport { VisitProcessor } from 'src/kameleoonData/visitProcessor';\n\nexport class Parser {\n static parseFeatureVariable(\n variable: FeatureVariableType,\n ): Result<FeatureVariableResultType, KameleoonError> {\n const { key, type, value } = variable;\n\n switch (type) {\n case VariableType.BOOLEAN:\n return Ok({\n key,\n type,\n value: Boolean(value),\n });\n case VariableType.JS:\n case VariableType.CSS:\n case VariableType.STRING:\n return Ok({\n key,\n type,\n value: String(value),\n });\n case VariableType.NUMBER:\n const numberValue = Number(value);\n\n if (Number.isNaN(numberValue)) {\n return Err(\n new KameleoonError(KameleoonException.NumberParse, String(value)),\n );\n }\n\n return Ok({\n key,\n type,\n value: numberValue,\n });\n case VariableType.JSON:\n try {\n const jsonValue: JSONType = JSON.parse(String(variable.value));\n\n return Ok({\n key,\n type,\n value: jsonValue,\n });\n } catch (err) {\n return Err(new KameleoonError(KameleoonException.JSONParse, err));\n }\n default:\n exhaustCheck(type);\n }\n }\n\n static parseVisitorData({\n data,\n filters,\n visitorCode,\n dataManager,\n variationConfiguration,\n }: ParseVisitorDataParametersType): ParseVisitorDataResultType {\n const visitProcessor = new VisitProcessor({\n filters,\n dataManager,\n visitorCode,\n });\n\n const { currentVisit, previousVisits, kcs } = data;\n\n let visits: VisitType[] = [];\n\n if (currentVisit) {\n visits.push(currentVisit);\n }\n\n if (previousVisits) {\n visits.push(...previousVisits);\n }\n\n if (!visits.length) {\n return { visitorData: [], storageVisitorData: [] };\n }\n\n visits.forEach((visit) => {\n visitProcessor.processVisit(visit);\n });\n\n visitProcessor.processKcs(kcs);\n visitProcessor.processMultipleDataTypes();\n\n const { visitorData, storageVisitorData, visitsData, experimentData } =\n visitProcessor.data;\n\n variationConfiguration.updateStoredVariations(visitorCode, experimentData);\n\n return {\n visitorData,\n storageVisitorData,\n visitsData,\n };\n }\n\n static parseRegExp(value: string): RegExp {\n if (value[0] === '/') {\n const [_, expression, flags] = value.split('/');\n\n return new RegExp(expression, flags);\n }\n\n return new RegExp(value);\n }\n}\n"],"mappings":"0PAeO,KAAM,CAAAA,MAAO,CAClB,MAAO,CAAAC,oBAAoBA,CACzBC,CAA6B,CACsB,CACnD,KAAM,CAAEC,GAAG,CAAHA,CAAG,CAAEC,IAAI,CAAJA,CAAI,CAAEC,KAAK,CAALA,CAAM,CAAC,CAAGH,CAAQ,CAErC,OAAQE,CAAI,EACV,IAAK,CAAAE,mBAAY,CAACC,OAAO,CACvB,MAAO,GAAAC,SAAE,EAAC,CACRL,GAAG,CAAHA,CAAG,CACHC,IAAI,CAAJA,CAAI,CACJC,KAAK,GAAUA,CACjB,CAAC,CAAC,CACJ,IAAK,CAAAC,mBAAY,CAACG,EAAE,CACpB,IAAK,CAAAH,mBAAY,CAACI,GAAG,CACrB,IAAK,CAAAJ,mBAAY,CAACK,MAAM,CACtB,MAAO,GAAAH,SAAE,EAAC,CACRL,GAAG,CAAHA,CAAG,CACHC,IAAI,CAAJA,CAAI,CACJC,KAAK,CAASA,CAAK,GACrB,CAAC,CAAC,CACJ,IAAK,CAAAC,mBAAY,CAACM,MAAM,CACtB,KAAM,CAAAC,CAAW,EAAUR,CAAM,CAAC,MAE9B,CAAAS,MAAM,CAACC,KAAK,CAACF,CAAW,CAAC,CACpB,GAAAG,UAAG,EACR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,CAAc,CAAC,CAG5B,CAACE,CAAM,CAACE,MAAM,CAChB,MAAO,CAAEC,WAAW,CAAE,EAAE,CAAEC,kBAAkB,CAAE,EAAG,CAAC,CAGpDJ,CAAM,CAACK,OAAO,CAAEC,CAAK,EAAK,CACxBX,CAAc,CAACY,YAAY,CAACD,CAAK,CACnC,CAAC,CAAC,CAEFX,CAAc,CAACa,UAAU,CAACT,CAAG,CAAC,CAC9BJ,CAAc,CAACc,wBAAwB,CAAC,CAAC,CAEzC,KAAM,CAAEN,WAAW,CAAXA,CAAW,CAAEC,kBAAkB,CAAlBA,CAAkB,CAAEM,UAAU,CAAVA,CAAU,CAAEC,cAAc,CAAdA,CAAe,CAAC,CACnEhB,CAAc,CAACL,IAAI,CAIrB,MAFA,CAAAI,CAAsB,CAACkB,sBAAsB,CAACpB,CAAW,CAAEmB,CAAc,CAAC,CAEnE,CACLR,WAAW,CAAXA,CAAW,CACXC,kBAAkB,CAAlBA,CAAkB,CAClBM,UAAU,CAAVA,CACF,CACF,CAEA,MAAO,CAAAG,WAAWA,CAAC9C,CAAa,CAAU,CACxC,GAAiB,GAAG,GAAhBA,CAAK,CAAC,CAAC,CAAS,CAAE,CACpB,KAAM,CAAC+C,CAAC,CAAEC,CAAU,CAAEC,CAAK,CAAC,CAAGjD,CAAK,CAACkD,KAAK,CAAC,GAAG,CAAC,CAE/C,MAAO,IAAI,CAAAC,MAAM,CAACH,CAAU,CAAEC,CAAK,CACrC,CAEA,MAAO,IAAI,CAAAE,MAAM,CAACnD,CAAK,CACzB,CACF,CAACoD,OAAA,CAAAzD,MAAA,CAAAA,MAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["TimeUnit","exports","Minute","Hour","Day","Week","Month","Order","Ascending","Descending"],"sources":["../../src/utilities/types.ts"],"sourcesContent":["import { CacheManager } from 'src/cacheManager';\nimport { ClientConfiguration } from 'src/clientConfiguration';\nimport { DataManager } from 'src/kameleoonData';\nimport {\n KameleoonDataType,\n KameleoonVisitorDataType,\n} from 'src/kameleoonData/types';\nimport { Requester } from 'src/requester';\nimport { GetVisitorDataResultType } from 'src/requester/types';\nimport { SegmentType } from 'src/targeting';\nimport { ExternalPackageInfoType, TrackingCacheItemType } from 'src/types';\nimport { VariationConfiguration } from 'src/variationConfiguration';\n\nexport type CheckTargetingParametersType = {\n segment: SegmentType | null;\n experimentId: number | null;\n visitorCode: string;\n packageInfo: ExternalPackageInfoType;\n targetingData?: KameleoonVisitorDataType;\n clientConfiguration: ClientConfiguration;\n variationConfiguration?: VariationConfiguration;\n dataManager: DataManager;\n};\n\nexport enum TimeUnit {\n Minute = 'MINUTE',\n Hour = 'HOUR',\n Day = 'DAY',\n Week = 'WEEK',\n Month = 'MONTH',\n}\n\nexport enum Order {\n Ascending = 'asc',\n Descending = 'desc',\n}\n\nexport type InsertInOrderedListParametersType = {\n list: number[];\n element: number;\n order: Order;\n};\n\nexport type ParseVisitorDataParametersType = {\n data: GetVisitorDataResultType;\n filters: VisitorDataFiltersType;\n visitorCode: string;\n dataManager: DataManager;\n variationConfiguration: VariationConfiguration;\n};\n\nexport type ParseVisitorDataResultType = {\n storageVisitorData: KameleoonDataType[];\n visitorData: KameleoonDataType[];\n visitsData?: KameleoonDataType;\n};\n\nexport type ManageCacheParametersType = {\n hasJsCssVariables: boolean;\n cacheManager: CacheManager<TrackingCacheItemType>;\n visitorCode: string;\n experimentId: number;\n variationId: number;\n};\n\nexport type TrackDataParametersType = {\n visitorCode: string;\n dataManager: DataManager;\n requester: Requester;\n isConsentProvided: boolean;\n isOfflineModeOn?: boolean;\n isMappingIdentifier?: boolean;\n};\n\nexport type TrackExperimentParametersType = {\n clientConfiguration: ClientConfiguration;\n visitorCode: string;\n requester: Requester;\n variationId: number;\n experimentId: number;\n isUnallocated: boolean;\n isOfflineModeOn?: boolean;\n};\n\n/**\n * @param {number} previousVisitAmount - Number of previous visits to retrieve data from. Number between `1` and `25`\n * *Default*: `1`.\n * @param {number} currentVisit - If true, current visit data will be retrieved.\n * *Default*: `true`.\n * @param {boolean} customData - If true, custom data will be retrieved.\n * *Default*: `true`.\n * @param {boolean} pageViews - If true, page data will be retrieved.\n * *Default*: `false`.\n * @param {boolean} geolocation - If true, geolocation data will be retrieved.\n * *Default*: `false`.\n * @param {boolean} device - If true, device data will be retrieved.\n * *Default*: `false`.\n * @param {boolean} browser - If true, browser data will be retrieved.\n * *Default*: `false`.\n * @param {boolean} operatingSystem - If true, operating system data will be retrieved.\n * *Default*: `false`.\n * @param {boolean} conversions - If true, conversion data will be retrieved.\n * *Default*: `false`.\n * @param {boolean} experiments - If true, experiment data will be retrieved.\n * *Default*: `false`.\n * @param {boolean} kcs - If true, Kameleoon Conversion Score data will be retrieved.\n * *Default*: `false`.\n * */\nexport type VisitorDataFiltersType = {\n previousVisitAmount?: number;\n currentVisit?: boolean;\n pageViews?: boolean;\n geolocation?: boolean;\n device?: boolean;\n browser?: boolean;\n operatingSystem?: boolean;\n customData?: boolean;\n conversions?: boolean;\n experiments?: boolean;\n kcs?: boolean;\n};\n\n/**\n * @interface `IExternalPRNG` - an interface for external PRNG (Pseudo-Random Number Generator) used to generate secure random numbers depending on the environment and platform\n * */\nexport interface IExternalPRNG {\n /**\n * @method getRandomNumber - a method to generate a secure random number\n * @returns {number} a secure random `number`, which must be a floating-point number between 0 and 1, similarly to `Math.random()`\n * */\n getRandomNumber(): number;\n}\n"],"mappings":"6GAwBY,CAAAA,QAAQ,CAAAC,OAAA,CAAAD,QAAA,UAARA,CAAQ,QAAR,CAAAA,CAAQ,CAAAE,MAAA,UAARF,CAAQ,CAAAG,IAAA,QAARH,CAAQ,CAAAI,GAAA,OAARJ,CAAQ,CAAAK,IAAA,QAARL,CAAQ,CAAAM,KAAA,SAARN,CAAQ,MAQRO,KAAK,CAAAN,OAAA,CAAAM,KAAA,UAALA,CAAK,QAAL,CAAAA,CAAK,CAAAC,SAAA,OAALD,CAAK,CAAAE,UAAA,QAALF,CAAK","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utilities.js","names":["Utilities","getNonce","prng","nonce","i","NONCE_LENGTH","randomNumber","getRandomNumber","randomIndex","Math","floor","HEX_CHARACTERS","charAt","checkTargeting","a","segment","visitorCode","targetingData","experimentId","variationConfiguration","clientConfiguration","packageInfo","dataManager","conditionsData","firstLevel","length","Ok","Err","KameleoonError","KameleoonException","Initialization","variations","assignedVariationsResult","getStoredVariations","ok","data","targetingTree","getTree","trees","ruleMap","segments","hasTargetingType","TargetingType","SEGMENT","TARGET_FEATURE_FLAG","result","evaluate","variationData","sdkInfo","convertTimeUnit","time","timeUnit","timeMap","TimeUnit","Minute","Milliseconds","Hour","Day","Week","Month","isCustomData","dataItem","type","KameleoonData","CustomData","insertInOrderedListMutably","list","element","order","includes","index","findIndex","item","Order","Ascending","push","splice","updateCache","hasJsCssVariables","cacheManager","variationId","cacheData","getAliveItem","newCacheData","_objectSpread","expirationTime","Date","now","CACHE_ITEM_LIFETIME","Second","add","key","lifetime","getTrackingCode","trackingCache","resultString","updatedCacheData","Object","entries","forEach","compareSemVer","version","compareVersion","operator","versionResult","Validator","validateVersion","compareVersionResult","error","major","minor","patch","compareMajor","compareMinor","comparePatch","isMajorEqual","isMinorEqual","isPatchEqual","VersionMatchType","EQUAL","GREATER","LOWER","exhaustCheck","exports"],"sources":["../../src/utilities/utilities.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport {\n KameleoonError,\n KameleoonException,\n exhaustCheck,\n} from 'src/kameleoonError';\nimport { Milliseconds, TrackingCacheItemType } from 'src/types';\nimport {\n CustomData,\n KameleoonData,\n KameleoonDataType,\n} from 'src/kameleoonData';\nimport { CACHE_ITEM_LIFETIME } from 'src/constants';\nimport { CacheManager } from 'src/cacheManager';\nimport { VersionMatchType, TargetingType } from 'src/targeting';\nimport { FeatureFlagVariationsType } from 'src/storage/types';\nimport {\n CheckTargetingParametersType,\n ManageCacheParametersType,\n InsertInOrderedListParametersType,\n Order,\n TimeUnit,\n IExternalPRNG,\n} from './types';\nimport { HEX_CHARACTERS, NONCE_LENGTH } from './constants';\nimport { Validator } from './validator';\n\nexport class Utilities {\n static getNonce(prng: IExternalPRNG): string {\n let nonce: string = '';\n\n for (let i = 0; i < NONCE_LENGTH; i++) {\n const randomNumber = prng.getRandomNumber();\n const randomIndex = Math.floor(randomNumber * NONCE_LENGTH);\n nonce += HEX_CHARACTERS.charAt(randomIndex);\n }\n\n return nonce;\n }\n\n static checkTargeting({\n segment,\n visitorCode,\n targetingData,\n experimentId,\n variationConfiguration,\n clientConfiguration,\n packageInfo,\n dataManager,\n }: CheckTargetingParametersType): Result<boolean, KameleoonError> {\n if (!segment || !segment.conditionsData.firstLevel.length) {\n return Ok(true);\n }\n\n if (!variationConfiguration) {\n return Err(new KameleoonError(KameleoonException.Initialization));\n }\n\n let variations: FeatureFlagVariationsType = {};\n\n const assignedVariationsResult =\n variationConfiguration.getStoredVariations(visitorCode);\n\n if (assignedVariationsResult.ok) {\n variations = assignedVariationsResult.data;\n }\n\n const targetingTree = dataManager.getTree(segment);\n\n let trees = undefined;\n let ruleMap = undefined;\n let segments = undefined;\n\n // --- Note ---\n // Only getting trees and segments targeting type\n if (targetingTree.hasTargetingType(TargetingType.SEGMENT)) {\n trees = dataManager.trees;\n segments = clientConfiguration.segments;\n }\n\n // --- Note ---\n // Only constructing rule map for targeting type\n if (targetingTree.hasTargetingType(TargetingType.TARGET_FEATURE_FLAG)) {\n ruleMap = clientConfiguration.ruleMap;\n }\n\n const result = targetingTree.evaluate({\n variationData: variations,\n sdkInfo: packageInfo,\n segments,\n ruleMap,\n trees,\n targetingData,\n experimentId,\n visitorCode,\n });\n\n return result;\n }\n\n static convertTimeUnit(time: number, timeUnit: TimeUnit): number {\n const timeMap = {\n [TimeUnit.Minute]: Milliseconds.Minute,\n [TimeUnit.Hour]: Milliseconds.Hour,\n [TimeUnit.Day]: Milliseconds.Day,\n [TimeUnit.Week]: Milliseconds.Week,\n [TimeUnit.Month]: Milliseconds.Month,\n };\n\n return time / timeMap[timeUnit];\n }\n\n static isCustomData(dataItem: KameleoonDataType): dataItem is CustomData {\n return dataItem.data.type === KameleoonData.CustomData;\n }\n\n /**\n * Insert element in ordered list, if element already exists in list, does nothing\n * @param list - list to insert element\n * @param element - element to insert\n * @param order - order of list\n */\n static insertInOrderedListMutably({\n list,\n element,\n order,\n }: InsertInOrderedListParametersType): void {\n if (list.includes(element)) {\n return;\n }\n\n const index = list.findIndex((item) =>\n order === Order.Ascending ? item >= element : item <= element,\n );\n\n if (index === -1) {\n list.push(element);\n } else {\n list.splice(index, 0, element);\n }\n }\n\n static updateCache({\n hasJsCssVariables,\n cacheManager,\n visitorCode,\n experimentId,\n variationId,\n }: ManageCacheParametersType): void {\n const cacheData = cacheManager.getAliveItem(visitorCode);\n\n const newCacheData = cacheData ? { ...cacheData } : {};\n\n newCacheData[experimentId] = {\n variationId,\n hasJsCssVariables,\n expirationTime: Date.now() + CACHE_ITEM_LIFETIME * Milliseconds.Second,\n };\n\n cacheManager.add({\n key: visitorCode,\n data: newCacheData,\n lifetime: CACHE_ITEM_LIFETIME,\n });\n }\n\n static getTrackingCode(\n trackingCache: CacheManager<TrackingCacheItemType>,\n visitorCode: string,\n ): string {\n let resultString = 'window.kameleoonQueue=window.kameleoonQueue||[];';\n\n const cacheData = trackingCache.getAliveItem(visitorCode);\n\n if (!cacheData) {\n return resultString;\n }\n\n const updatedCacheData: TrackingCacheItemType = {};\n\n Object.entries(cacheData).forEach(\n ([experimentId, { variationId, expirationTime, hasJsCssVariables }]) => {\n const flag = !hasJsCssVariables;\n\n if (expirationTime > Date.now()) {\n resultString += `window.kameleoonQueue.push(['Experiments.assignVariation',${experimentId},${variationId},true]);`;\n resultString += `window.kameleoonQueue.push(['Experiments.trigger',${experimentId},${flag}]);`;\n\n updatedCacheData[Number(experimentId)] = {\n variationId,\n expirationTime,\n hasJsCssVariables,\n };\n }\n },\n );\n\n // --- Note ---\n // Cache is updated with only alive experiments\n trackingCache.add({\n key: visitorCode,\n data: updatedCacheData,\n lifetime: CACHE_ITEM_LIFETIME,\n });\n\n return resultString;\n }\n\n static compareSemVer({\n version,\n compareVersion,\n operator,\n }: {\n version: string;\n compareVersion: string;\n operator: VersionMatchType;\n }): Result<boolean, KameleoonError> {\n const versionResult = Validator.validateVersion(version);\n const compareVersionResult = Validator.validateVersion(compareVersion);\n\n if (!versionResult.ok) {\n return Err(versionResult.error);\n }\n\n if (!compareVersionResult.ok) {\n return Err(compareVersionResult.error);\n }\n\n const [major, minor, patch] = versionResult.data;\n const [compareMajor, compareMinor, comparePatch] =\n compareVersionResult.data;\n\n const [isMajorEqual, isMinorEqual, isPatchEqual] = [\n major === compareMajor,\n minor === compareMinor,\n patch === comparePatch,\n ];\n\n switch (operator) {\n case VersionMatchType.EQUAL:\n return Ok(isMajorEqual && isMinorEqual && isPatchEqual);\n case VersionMatchType.GREATER:\n return Ok(\n major > compareMajor ||\n (isMajorEqual && minor > compareMinor) ||\n (isMajorEqual && isMinorEqual && patch > comparePatch),\n );\n case VersionMatchType.LOWER:\n return Ok(\n major < compareMajor ||\n (isMajorEqual && minor < compareMinor) ||\n (isMajorEqual && isMinorEqual && patch < comparePatch),\n );\n default:\n exhaustCheck(operator);\n }\n }\n}\n"],"mappings":"s/CA2BO,KAAM,CAAAA,SAAU,CACrB,MAAO,CAAAC,QAAQA,CAACC,CAAmB,CAAU,CAC3C,GAAI,CAAAC,CAAa,CAAG,EAAE,CAEtB,IAAK,GAAI,CAAAC,CAAC,CAAG,CAAC,CAAEA,CAAC,CAAGC,wBAAY,CAAED,CAAC,EAAE,CAAE,MAC/B,CAAAE,CAAY,CAAGJ,CAAI,CAACK,eAAe,CAAC,CAAC,CACrCC,CAAW,CAAGC,IAAI,CAACC,KAAK,CAACJ,CAAY,CAAGD,wBAAY,CAAC,CAC3DF,CAAK,EAAIQ,0BAAc,CAACC,MAAM,CAACJ,CAAW,CAC5C,CAEA,MAAO,C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K,GAAKG,CAAY,CACvB,CAED,OAAQX,CAAQ,EACd,IAAK,CAAAe,2BAAgB,CAACC,KAAK,CACzB,MAAO,GAAA7F,SAAE,EAACyF,CAAY,EAAIC,CAAY,EAAIC,CAAY,CAAC,CACzD,IAAK,CAAAC,2BAAgB,CAACE,OAAO,CAC3B,MAAO,GAAA9F,SAAE,EACPmF,CAAK,CAAGG,CAAY,EACjBG,CAAY,EAAIL,CAAK,CAAGG,CAAa,EACrCE,CAAY,EAAIC,CAAY,EAAIL,CAAK,CAAGG,CAC7C,CAAC,CACH,IAAK,CAAAI,2BAAgB,CAACG,KAAK,CACzB,MAAO,GAAA/F,SAAE,EACPmF,CAAK,CAAGG,CAAY,EACjBG,CAAY,EAAIL,CAAK,CAAGG,CAAa,EACrCE,CAAY,EAAIC,CAAY,EAAIL,CAAK,CAAGG,CAC7C,CAAC,CACH,QACE,GAAAQ,4BAAY,EAACnB,CAAQ,CACzB,CACF,CACF,CAACoB,OAAA,CAAA3H,SAAA,CAAAA,SAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","names":["Validator","validateVersion","version","versionParts","split","map","x","parseInt","length","push","some","item","isNaN","Err","KameleoonError","KameleoonException","SemanticVersionParse","Ok","slice","exports"],"sources":["../../src/utilities/validator.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\n\nexport class Validator {\n static validateVersion(\n version: string,\n ): Result<[number, number, number], KameleoonError> {\n const versionParts = version.split('.').map((x) => parseInt(x, 10));\n\n while (versionParts.length < 3) {\n versionParts.push(0);\n }\n\n if (versionParts.some((item) => isNaN(item))) {\n return Err(\n new KameleoonError(KameleoonException.SemanticVersionParse, version),\n );\n }\n\n return Ok(versionParts.slice(0, 3) as [number, number, number]);\n }\n}\n"],"mappings":"uKAGO,KAAM,CAAAA,SAAU,CACrB,MAAO,CAAAC,eAAeA,CACpBC,CAAe,CACmC,CAClD,KAAM,CAAAC,CAAY,CAAGD,CAAO,CAACE,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAAEC,CAAC,EAAKC,QAAQ,CAACD,CAAC,CAAE,EAAE,CAAC,CAAC,CAAC,KAEvC,CAAC,CAAvBH,CAAY,CAACK,MAAU,EAC5BL,CAAY,CAACM,IAAI,CAAC,CAAC,CAAC,CAAC,MAGnB,CAAAN,CAAY,CAACO,IAAI,CAAEC,CAAI,EAAKC,KAAK,CAACD,CAAI,CAAC,CAAC,CACnC,GAAAE,UAAG,EACR,GAAI,CAAAC,8BAAc,CAACC,kCAAkB,CAACC,oBAAoB,CAAEd,CAAO,CACrE,CAAC,CAGI,GAAAe,SAAE,EAACd,CAAY,CAACe,KAAK,CAAC,CAAC,CAAE,CAAC,CAA6B,CAChE,CACF,CAACC,OAAA,CAAAnB,SAAA,CAAAA,SAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/variationConfiguration/index.ts"],"sourcesContent":["export { VariationConfiguration } from './variationConfiguration';\nexport { FeatureFlagVariationType } from './types';\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/variationConfiguration/types.ts"],"sourcesContent":["import {\n ClientConfiguration,\n FeatureFlagType,\n RuleItemType,\n} from 'src/clientConfiguration';\nimport { DataManager } from 'src/kameleoonData';\nimport { KameleoonVisitorDataType } from 'src/kameleoonData/types';\nimport { ExternalPackageInfoType, TrackingStatus } from 'src/types';\n\nexport type UpdateDataStatusParametersType = {\n visitorCode: string;\n experimentIdList: string[];\n status: TrackingStatus;\n};\n\nexport type FeatureFlagVariationType = {\n variationKey: string;\n variationId: number | null;\n experimentId: number | null;\n featureFlagId: number;\n featureKey: string;\n rule: RuleItemType | null;\n isTargetedRule: boolean;\n};\n\nexport type GetVariationParametersType = {\n visitorCode: string;\n visitorIdentifier: string;\n featureFlag: FeatureFlagType;\n targetingData?: KameleoonVisitorDataType;\n withAssignment?: boolean;\n packageInfo: ExternalPackageInfoType;\n clientConfiguration: ClientConfiguration;\n dataManager: DataManager;\n};\n\nexport type BaseVariationDataType = {\n experimentId: number;\n variationId: number;\n isTargetedRule: boolean;\n};\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"variationConfiguration.js","names":["VariationConfiguration","constructor","externalStorage","visitorCodeManager","_defineProperty","storage","updateDataStatus","a","visitorCode","experimentIdList","status","result","read","ok","updatedVariationData","data","experimentId","_objectSpread","write","getUnsentData","getVariationData","TrackingStatus","Unsent","getPendingData","Pending","getStoredVariations","featureFlagVariations","Ok","Err","KameleoonError","KameleoonException","StorageRead","getVariation","visitorIdentifier","featureFlag","targetingData","packageInfo","clientConfiguration","dataManager","withAssignment","validateResult","validateVisitorCode","error","rules","featureKey","id","featureFlagId","defaultVariationKey","rule","segment","exposition","respoolTime","variationByExposition","targetingResult","Utilities","checkTargeting","variationConfiguration","ruleHash","Hasher","getHashDouble","totalDeviation","variationHash","variation","updateStoredVariations","variationId","isTargetedRule","type","RuleType","TARGETED_DELIVERY","restParameters","_objectWithoutProperties","_excluded","variationKey","variationData","filter","resultData","Object","entries","push","exports"],"sources":["../../src/variationConfiguration/variationConfiguration.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { Hasher } from 'src/hasher';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { VariationDataType } from 'src/storage';\nimport { Utilities } from 'src/utilities';\nimport { RuleType } from 'src/clientConfiguration/types';\nimport {\n BaseVariationDataType,\n FeatureFlagVariationType,\n GetVariationParametersType,\n UpdateDataStatusParametersType,\n} from './types';\nimport { FeatureFlagVariationsType, IStorage } from 'src/storage/types';\nimport { IVisitorCodeManager } from 'src/visitorCodeManager';\nimport { TrackingStatus } from 'src/types';\n\ninterface IVariationConfiguration {\n /**\n * @method getStoredVariations - obtains campaigns with according variations that are *already assigned* and *stored* in the `variationStorage`.\n */\n getStoredVariations(\n visitorCode: string,\n ): Result<FeatureFlagVariationsType, KameleoonError>;\n /**\n * @method updateStoredVariations - updates stored variations for the visitor\n */\n updateStoredVariations: (\n visitorCode: string,\n variationData: FeatureFlagVariationsType,\n ) => void;\n /**\n * @method getVariation - obtains variation for the rule of the feature flag which is both targeted and has a variation, if no such rule was found, returns empty rule with default `variationKey`, given an option `withAssignment` of `true` will also assign a new variation and save it in the storage\n */\n getVariation: (\n params: GetVariationParametersType,\n ) => Result<FeatureFlagVariationType, KameleoonError>;\n /**\n * @method getUnsentData - obtains the list of unsent variations\n */\n getUnsentData: (visitorCode: string) => BaseVariationDataType[];\n /**\n * @method getPendingData - obtains the list of pending variations\n */\n getPendingData: (visitorCode: string) => BaseVariationDataType[];\n /**\n * @method updateDataStatus - updates the status of the variations of given experiment ids with the given status\n */\n updateDataStatus: ({\n visitorCode,\n experimentIdList,\n status,\n }: UpdateDataStatusParametersType) => void;\n}\n\nexport class VariationConfiguration implements IVariationConfiguration {\n private storage: IStorage<VariationDataType>;\n private visitorCodeManager: IVisitorCodeManager;\n\n constructor(\n externalStorage: IStorage<VariationDataType>,\n visitorCodeManager: IVisitorCodeManager,\n ) {\n this.storage = externalStorage;\n this.visitorCodeManager = visitorCodeManager;\n }\n\n public updateDataStatus({\n visitorCode,\n experimentIdList,\n status,\n }: UpdateDataStatusParametersType): Result<void, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n return result;\n }\n\n let updatedVariationData: VariationDataType = result.data;\n\n if (!updatedVariationData[visitorCode]) {\n updatedVariationData[visitorCode] = {};\n }\n\n for (const experimentId of experimentIdList) {\n updatedVariationData[visitorCode][experimentId] = {\n ...updatedVariationData[visitorCode][experimentId],\n status,\n };\n }\n\n return this.storage.write(updatedVariationData);\n }\n\n public getUnsentData(visitorCode: string): BaseVariationDataType[] {\n return this.getVariationData(\n visitorCode,\n (status) => status === TrackingStatus.Unsent,\n );\n }\n\n public getPendingData(visitorCode: string): BaseVariationDataType[] {\n return this.getVariationData(\n visitorCode,\n (status) => status === TrackingStatus.Pending,\n );\n }\n\n public getStoredVariations(\n visitorCode: string,\n ): Result<FeatureFlagVariationsType, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n return result;\n }\n\n const featureFlagVariations = result.data[visitorCode];\n\n if (!featureFlagVariations) {\n return Err(\n new KameleoonError(KameleoonException.StorageRead, visitorCode),\n );\n }\n\n return Ok(featureFlagVariations);\n }\n\n public getVariation({\n visitorCode,\n visitorIdentifier,\n featureFlag,\n targetingData,\n packageInfo,\n clientConfiguration,\n dataManager,\n withAssignment = false,\n }: GetVariationParametersType): Result<\n FeatureFlagVariationType,\n KameleoonError\n > {\n const validateResult =\n this.visitorCodeManager.validateVisitorCode(visitorCode);\n\n if (!validateResult.ok) {\n return Err(validateResult.error);\n }\n\n const {\n rules,\n featureKey,\n id: featureFlagId,\n defaultVariationKey,\n } = featureFlag;\n\n for (const rule of rules) {\n const {\n segment,\n experimentId,\n id,\n exposition,\n respoolTime,\n variationByExposition,\n } = rule;\n\n // --- Check targeting ---\n const targetingResult = Utilities.checkTargeting({\n segment,\n visitorCode,\n experimentId,\n targetingData,\n packageInfo,\n clientConfiguration,\n dataManager,\n variationConfiguration: this,\n });\n\n if (!targetingResult.ok) {\n return targetingResult;\n }\n\n if (!targetingResult.data) {\n continue;\n }\n\n // --- Note ---\n // Calculate new variation (and assign it if `withAssignment` is `true`)\n // First the the exposed rule is calculated and then the variation inside of it\n const ruleHash = Hasher.getHashDouble({\n visitorIdentifier,\n respoolTime,\n id: String(id),\n });\n\n if (ruleHash <= exposition) {\n let totalDeviation = 0;\n\n const variationHash = Hasher.getHashDouble({\n visitorIdentifier,\n respoolTime,\n id: String(experimentId),\n });\n\n for (const variation of variationByExposition) {\n totalDeviation += variation.exposition;\n\n if (variationHash <= totalDeviation) {\n if (withAssignment) {\n this.updateStoredVariations(visitorCode, {\n [experimentId]: {\n variationId: variation.variationId,\n isTargetedRule: rule.type === RuleType.TARGETED_DELIVERY,\n status: TrackingStatus.Unsent,\n },\n });\n }\n\n const { exposition, ...restParameters } = variation;\n\n return Ok({\n ...restParameters,\n rule,\n featureFlagId,\n featureKey,\n experimentId,\n isTargetedRule: rule.type === RuleType.TARGETED_DELIVERY,\n });\n }\n }\n }\n\n if (rule.type === RuleType.TARGETED_DELIVERY) {\n return Ok({\n featureKey,\n featureFlagId,\n experimentId: null,\n variationKey: defaultVariationKey,\n variationId: null,\n rule: null,\n isTargetedRule: true,\n });\n }\n }\n\n return Ok({\n featureKey,\n featureFlagId,\n experimentId: null,\n variationKey: defaultVariationKey,\n variationId: null,\n rule: null,\n isTargetedRule: false,\n });\n }\n\n public updateStoredVariations(\n visitorCode: string,\n variationData: FeatureFlagVariationsType,\n ): Result<void, KameleoonError> {\n const result = this.storage.read();\n\n if (!result.ok) {\n return result;\n }\n\n let updatedVariationData: VariationDataType = result.data;\n\n if (updatedVariationData[visitorCode]) {\n updatedVariationData[visitorCode] = {\n ...updatedVariationData[visitorCode],\n ...variationData,\n };\n } else {\n updatedVariationData = {\n ...updatedVariationData,\n [visitorCode]: {\n ...variationData,\n },\n };\n }\n\n return this.storage.write(updatedVariationData);\n }\n\n private getVariationData(\n visitorCode: string,\n filter: (status: TrackingStatus) => boolean,\n ): BaseVariationDataType[] {\n const result = this.getStoredVariations(visitorCode);\n\n if (!result.ok) {\n return [];\n }\n\n const resultData: BaseVariationDataType[] = [];\n\n for (const [experimentId, variationData] of Object.entries(result.data)) {\n if (filter(variationData.status)) {\n resultData.push({\n experimentId: Number(experimentId),\n variationId: variationData.variationId,\n isTargetedRule: variationData.isTargetedRule,\n });\n }\n }\n\n return resultData;\n }\n}\n"],"mappings":"03DAsDO,KAAM,CAAAA,sBAA0D,CAIrEC,WAAWA,CACTC,CAA4C,CAC5CC,CAAuC,CACvC,CAAAC,eAAA,wBAAAA,eAAA,mCACA,IAAI,CAACC,OAAO,CAAGH,C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,CAAmB,CACnBkE,CAA2C,CAClB,CACzB,KAAM,CAAA/D,CAAM,CAAG,IAAI,CAACc,mBAAmB,CAACjB,CAAW,CAAC,CAEpD,GAAI,CAACG,CAAM,CAACE,EAAE,CACZ,MAAO,EAAE,CAGX,KAAM,CAAA8D,CAAmC,CAAG,EAAE,CAE9C,IAAK,KAAM,CAAC3D,CAAY,CAAEyD,CAAa,CAAC,EAAI,CAAAG,MAAM,CAACC,OAAO,CAAClE,CAAM,CAACI,IAAI,CAAC,CACjE2D,CAAM,CAACD,CAAa,CAAC/D,MAAM,CAAC,EAC9BiE,CAAU,CAACG,IAAI,CAAC,CACd9D,YAAY,EAASA,CAAa,CAClCgD,WAAW,CAAES,CAAa,CAACT,WAAW,CACtCC,cAAc,CAAEQ,CAAa,CAACR,cAChC,CAAC,CAAC,CAIN,MAAO,CAAAU,CACT,CACF,CAACI,OAAA,CAAA/E,sBAAA,CAAAA,sBAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":["VISITOR_CODE_LENGTH","exports","VISITOR_CODE_MAX_LENGTH","DEFAULT_MAX_AGE","ZERO_MAX_AGE","PATH"],"sources":["../../src/visitorCodeManager/constants.ts"],"sourcesContent":["export const VISITOR_CODE_LENGTH = 16;\nexport const VISITOR_CODE_MAX_LENGTH = 255;\nexport const DEFAULT_MAX_AGE = 60 * 60 * 24 * 365;\nexport const ZERO_MAX_AGE = 0;\nexport const PATH = '/';\n"],"mappings":"sMAAa,CAAAA,mBAAmB,CAAAC,OAAA,CAAAD,mBAAA,CAAG,EAAE,CACxBE,uBAAuB,CAAAD,OAAA,CAAAC,uBAAA,CAAG,GAAG,CAC7BC,eAAe,CAAAF,OAAA,CAAAE,eAAA,SAAqB,CACpCC,YAAY,CAAAH,OAAA,CAAAG,YAAA,CAAG,CAAC,CAChBC,IAAI,CAAAJ,OAAA,CAAAI,IAAA,CAAG,GAAG","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_types","require","_constants","_visitorCodeManager","Object","defineProperty","exports","value","enumerable","get","VisitorCodeManager","keys","forEach","a","prototype","hasOwnProperty","call","_exportNames"],"sources":["../../src/visitorCodeManager/index.ts"],"sourcesContent":["export * from './types';\nexport * from './constants';\nexport { VisitorCodeManager } from './visitorCodeManager';\n"],"mappings":"sDAAA,IAAAA,MAAA,CAAAC,OAAA,YACA,IAAAC,UAAA,CAAAD,OAAA,gBACA,IAAAE,mBAAA,CAAAF,OAAA,yBAA0DG,MAAA,CAAAC,cAAA,CAAAC,OAAA,eAAAC,KAAA,MAAAH,MAAA,CAAAC,cAAA,CAAAC,OAAA,uBAAAE,UAAA,IAAAC,GAAA,SAAAA,CAAA,SAAAN,mBAAA,CAAAO,kBAAA,IAAAN,MAAA,CAAAO,IAAA,CAAAX,MAAA,EAAAY,OAAA,UAAAC,CAAA,cAAAA,CAAA,iBAAAA,CAAA,EAAAT,MAAA,CAAAU,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,CAAAJ,CAAA,GAAAA,CAAA,IAAAP,OAAA,EAAAA,OAAA,CAAAO,CAAA,IAAAb,MAAA,CAAAa,CAAA,GAAAT,MAAA,CAAAC,cAAA,CAAAC,OAAA,CAAAO,CAAA,EAAAL,UAAA,IAAAC,GAAA,SAAAA,CAAA,SAAAT,MAAA,CAAAa,CAAA,OAAAT,MAAA,CAAAO,IAAA,CAAAT,UAAA,EAAAU,OAAA,UAAAC,CAAA,cAAAA,CAAA,iBAAAA,CAAA,EAAAT,MAAA,CAAAU,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,CAAAJ,CAAA,GAAAA,CAAA,IAAAP,OAAA,EAAAA,OAAA,CAAAO,CAAA,IAAAX,UAAA,CAAAW,CAAA,GAAAT,MAAA,CAAAC,cAAA,CAAAC,OAAA,CAAAO,CAAA,EAAAL,UAAA,IAAAC,GAAA,SAAAA,CAAA,SAAAP,UAAA,CAAAW,CAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/visitorCodeManager/types.ts"],"sourcesContent":["import { Result } from 'ts-res';\nimport { KameleoonError } from 'src/kameleoonError';\nimport { SetDataCallbackParametersType } from 'src/types';\n\nexport interface IVisitorCodeManager {\n consentRequired: boolean;\n getVisitorCode(defaultVisitorCode?: string): string;\n getData: (key: string) => string | null;\n setData: (params: SetDataCallbackParametersType) => void;\n validateVisitorCode(visitorCode: string): Result<void, KameleoonError>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"visitorCodeManager.js","names":["VisitorCodeManager","constructor","_defineProperty","consentRequired","isRequired","isConsentRequired","getData","callback","getDataCallback","setData","setDataCallback","Error","validateVisitorCode","visitorCode","length","Err","KameleoonError","KameleoonException","VisitorCodeEmpty","VISITOR_CODE_MAX_LENGTH","VisitorCodeMaxLength","Ok","getVisitorCode","defaultVisitorCode","existingVisitorCode","KameleoonStorageKey","VisitorCode","throw","generateVisitorCode","key","maxAge","DEFAULT_MAX_AGE","path","PATH","characters","randomCharacterArray","i","VISITOR_CODE_LENGTH","push","Math","floor","random","join","exports"],"sources":["../../src/visitorCodeManager/visitorCodeManager.ts"],"sourcesContent":["import { Err, Ok, Result } from 'ts-res';\nimport { KameleoonStorageKey } from 'src/storage';\nimport { SetDataCallbackParametersType } from 'src/types';\nimport { KameleoonError, KameleoonException } from 'src/kameleoonError';\nimport { IVisitorCodeManager } from './types';\nimport {\n DEFAULT_MAX_AGE,\n PATH,\n VISITOR_CODE_LENGTH,\n VISITOR_CODE_MAX_LENGTH,\n} from './constants';\n\n/**\n * VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve,\n * and handle these codes while considering user consent.\n **/\nexport class VisitorCodeManager implements IVisitorCodeManager {\n private isConsentRequired: boolean = false;\n private setDataCallback?: (params: SetDataCallbackParametersType) => void;\n private getDataCallback?: (key: string) => string | null;\n\n set consentRequired(isRequired: boolean) {\n this.isConsentRequired = isRequired;\n }\n\n get consentRequired(): boolean {\n return this.isConsentRequired;\n }\n\n set getData(callback: () => string) {\n this.getDataCallback = callback;\n }\n\n set setData(callback: (params: SetDataCallbackParametersType) => void) {\n this.setDataCallback = callback;\n }\n\n get setData(): (params: SetDataCallbackParametersType) => void {\n if (this.setDataCallback) {\n return this.setDataCallback;\n }\n\n throw new Error('Missing setDataCallback!');\n }\n\n public validateVisitorCode(\n visitorCode: string,\n ): Result<void, KameleoonError> {\n if (visitorCode.length === 0) {\n return Err(new KameleoonError(KameleoonException.VisitorCodeEmpty));\n }\n\n if (visitorCode.length > VISITOR_CODE_MAX_LENGTH) {\n return Err(new KameleoonError(KameleoonException.VisitorCodeMaxLength));\n }\n\n return Ok();\n }\n\n public getVisitorCode(defaultVisitorCode?: string): string {\n if (!this.getDataCallback || !this.setDataCallback) {\n throw new Error(\n 'Missing getDataCallback or setDataCallback methods in getVisitorCode!',\n );\n }\n\n let visitorCode;\n\n const existingVisitorCode = this.getDataCallback(\n KameleoonStorageKey.VisitorCode,\n );\n\n if (existingVisitorCode) {\n visitorCode = existingVisitorCode;\n }\n\n if (!visitorCode) {\n if (defaultVisitorCode) {\n this.validateVisitorCode(defaultVisitorCode).throw();\n visitorCode = defaultVisitorCode;\n } else {\n visitorCode = this.generateVisitorCode();\n }\n }\n\n if (!this.isConsentRequired) {\n this.setDataCallback({\n visitorCode,\n key: KameleoonStorageKey.VisitorCode,\n maxAge: DEFAULT_MAX_AGE,\n path: PATH,\n });\n }\n\n return visitorCode;\n }\n\n private generateVisitorCode(): string {\n const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';\n const randomCharacterArray: string[] = [];\n\n for (let i = 0; i < VISITOR_CODE_LENGTH; i++) {\n randomCharacterArray.push(\n characters[Math.floor(Math.random() * characters.length)],\n );\n }\n\n return randomCharacterArray.join('');\n }\n}\n"],"mappings":"kvBAgB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