@kameleoon/javascript-sdk-core
Advanced tools
Comparing version 2.2.1 to 2.3.0
@@ -15,2 +15,3 @@ import { JSONType } from './campaignConfiguration'; | ||
* - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api | ||
* - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed | ||
*/ | ||
@@ -17,0 +18,0 @@ initialize: () => Promise<boolean>; |
@@ -22,2 +22,3 @@ import { KameleoonStorageKey } from '../storage'; | ||
RemoteData: () => string; | ||
MaximumRetriesReached: () => string; | ||
}; |
@@ -26,5 +26,6 @@ "use strict"; | ||
[_types.KameleoonException.AmongValuesCheck]: (err, value) => `Couldn't parse value "${value}": ${err}`, | ||
[_types.KameleoonException.RemoteData]: () => `Couldn't retrieve data from Kameleoon server` | ||
[_types.KameleoonException.RemoteData]: () => `Couldn't retrieve data from Kameleoon server`, | ||
[_types.KameleoonException.MaximumRetriesReached]: () => `Maximum retries reached, request failed` | ||
}; | ||
exports.ERROR_MESSAGES = ERROR_MESSAGES; | ||
//# sourceMappingURL=constants.js.map |
@@ -13,3 +13,3 @@ import { KameleoonStorageKey } from '../storage'; | ||
* */ | ||
constructor(type: KameleoonException.Initialization | KameleoonException.ClientConfiguration | KameleoonException.VisitorCodeMaxLength | KameleoonException.StorageInitialization | KameleoonException.EventSourceInitialization | KameleoonException.VariationNotFound | KameleoonException.RemoteData); | ||
constructor(type: KameleoonException.Initialization | KameleoonException.ClientConfiguration | KameleoonException.VisitorCodeMaxLength | KameleoonException.StorageInitialization | KameleoonException.EventSourceInitialization | KameleoonException.VariationNotFound | KameleoonException.RemoteData | KameleoonException.MaximumRetriesReached); | ||
constructor(type: KameleoonException.FeatureFlagConfigurationNotFound, featureKey: string, visitorCode: string); | ||
@@ -16,0 +16,0 @@ constructor(type: KameleoonException.NotTargeted | KameleoonException.NotAllocated, visitorCode: string); |
@@ -35,2 +35,3 @@ "use strict"; | ||
case _types.KameleoonException.RemoteData: | ||
case _types.KameleoonException.MaximumRetriesReached: | ||
this.message = _constants.ERROR_MESSAGES[type](); | ||
@@ -37,0 +38,0 @@ break; |
@@ -19,3 +19,4 @@ export declare enum KameleoonException { | ||
NumberParse = "NumberParse", | ||
RemoteData = "RemoteData" | ||
RemoteData = "RemoteData", | ||
MaximumRetriesReached = "MaximumRetriesReached" | ||
} |
@@ -26,2 +26,3 @@ "use strict"; | ||
KameleoonException["RemoteData"] = "RemoteData"; | ||
KameleoonException["MaximumRetriesReached"] = "MaximumRetriesReached"; | ||
return KameleoonException; | ||
@@ -28,0 +29,0 @@ }({}); |
@@ -27,3 +27,3 @@ "use strict"; | ||
const pairs = cookie.split(_constants.Cookie.PairsDelimiter); | ||
const pair = pairs?.find(pair => { | ||
const pair = pairs.find(pair => { | ||
const [key, _] = pair.split(_constants.Cookie.KeyValueDelimiter); | ||
@@ -30,0 +30,0 @@ return key === _constants.KAMELEOON_COOKIE_KEY; |
@@ -35,11 +35,12 @@ "use strict"; | ||
const requestUrl = _constants.URL.CLIENT_CONFIGURATION + _constants.UrlQuery.Mobile + this.siteCode + environmentParam + timeStampParam; | ||
const response = await this.requestDispatcher.get(requestUrl); | ||
if (!response) { | ||
return (0, _tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.ClientConfiguration)); | ||
try { | ||
const response = await this.requestDispatcher.getClientConfiguration(requestUrl); | ||
return (0, _tsRes.Ok)(response); | ||
} catch (error) { | ||
return (0, _tsRes.Err)(error); | ||
} | ||
return (0, _tsRes.Ok)(response); | ||
} | ||
async getRemoteData(key) { | ||
const requestUrl = _constants.URL.DATA + this.siteCode + _constants.UrlParameter.Key + encodeURI(key); | ||
const response = await this.requestDispatcher.get(requestUrl); | ||
const response = await this.requestDispatcher.getRemoteData(requestUrl); | ||
if (!response) { | ||
@@ -46,0 +47,0 @@ return (0, _tsRes.Err)(new _kameleoonError.KameleoonError(_kameleoonError.KameleoonException.RemoteData)); |
@@ -66,7 +66,12 @@ import { JSONType, FeatureFlagType, ConfigurationDataType } from '../campaignConfiguration'; | ||
/** | ||
* @method get - get data | ||
* @method getClientConfiguration - get client configuration | ||
* @param {string} url - url address | ||
* */ | ||
get: (url: string) => Promise<JSONType>; | ||
getClientConfiguration: (url: string) => Promise<JSONType>; | ||
/** | ||
* @method getRemoteData - get data from remote server of Kameleoon | ||
* @param {string} url - url address | ||
* */ | ||
getRemoteData: (url: string) => Promise<JSONType>; | ||
} | ||
export {}; |
@@ -9,3 +9,2 @@ "use strict"; | ||
var _hasher = require("../hasher"); | ||
var _variation = require("./variation"); | ||
var _kameleoonError = require("../kameleoonError"); | ||
@@ -27,6 +26,14 @@ var _utilities = require("../utilities"); | ||
_defineProperty(this, "getAssociatedVariationId", (visitorCode, experimentId) => { | ||
let associatedVariation; | ||
this.storage.read().and(data => { | ||
associatedVariation = data?.[visitorCode]?.[experimentId]; | ||
}); | ||
// TODO: | ||
// --- Variation from storage is not checked anymore | ||
// --- If nothing changes the commented code should be deleted | ||
// along with the `Variation` class and according tests/types | ||
// --- Mind `todo` in `getAssociatedVariationId.spec.ts` | ||
// | ||
// let associatedVariation: VariationType | undefined; | ||
// this.storage.read().and((data) => { | ||
// associatedVariation = data?.[visitorCode]?.[experimentId]; | ||
// }); | ||
const experiment = this.experiments.find(experiment => experiment.id === String(experimentId)); | ||
@@ -36,6 +43,9 @@ if (!experiment) { | ||
} | ||
const variation = new _variation.Variation(associatedVariation); | ||
if (variation.isValid(experiment?.respoolTime)) { | ||
return (0, _tsRes.Ok)(variation.id); | ||
} | ||
// const variation = new Variation(associatedVariation); | ||
// if (variation.isValid(experiment?.respoolTime)) { | ||
// return Ok(variation.id); | ||
// } | ||
return this.assignVariation(visitorCode, experiment); | ||
@@ -42,0 +52,0 @@ }); |
{ | ||
"name": "@kameleoon/javascript-sdk-core", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Kameleoon JS SDK Core", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
476175
5433