@kameleoon/javascript-sdk-core 5.15.0 → 5.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/browser.d.ts +1 -0
- package/dist/clientConfiguration/types.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/javascript-sdk-core-browser.cjs.js +108 -19
- package/dist/javascript-sdk-core-browser.cjs.js.map +1 -1
- package/dist/javascript-sdk-core-browser.es.js +108 -19
- package/dist/javascript-sdk-core-browser.es.js.map +1 -1
- package/dist/javascript-sdk-core.cjs.js +108 -19
- package/dist/javascript-sdk-core.cjs.js.map +1 -1
- package/dist/javascript-sdk-core.es.js +108 -19
- package/dist/javascript-sdk-core.es.js.map +1 -1
- package/dist/kameleoonClient.d.ts +5 -4
- package/dist/kameleoonClientInterface.d.ts +13 -7
- package/dist/kameleoonData/conversion.d.ts +2 -0
- package/dist/kameleoonData/customData.d.ts +15 -4
- package/dist/kameleoonData/dataManager.d.ts +1 -0
- package/dist/types.d.ts +36 -4
- package/package.json +1 -1
|
@@ -2273,11 +2273,11 @@ let CustomData$1 = class CustomData {
|
|
|
2273
2273
|
const isNumber = typeof first === 'number';
|
|
2274
2274
|
const isBoolean = typeof second === 'boolean';
|
|
2275
2275
|
if (isNumber) {
|
|
2276
|
-
this.
|
|
2276
|
+
this._index = first;
|
|
2277
2277
|
}
|
|
2278
2278
|
else {
|
|
2279
|
-
this.
|
|
2280
|
-
this.
|
|
2279
|
+
this._name = first;
|
|
2280
|
+
this._index = CustomData.UNDEFINED_INDEX;
|
|
2281
2281
|
}
|
|
2282
2282
|
this.overwrite = isBoolean ? second : true;
|
|
2283
2283
|
this.value = isBoolean
|
|
@@ -2288,7 +2288,7 @@ let CustomData$1 = class CustomData {
|
|
|
2288
2288
|
// --- Note ---
|
|
2289
2289
|
// If SDK is used in vanilla JS codebase, then you're also able to create an instance
|
|
2290
2290
|
// with no required data, we don't want send anything to tracking in that case
|
|
2291
|
-
if (typeof this.
|
|
2291
|
+
if (typeof this._index !== 'number') {
|
|
2292
2292
|
return '';
|
|
2293
2293
|
}
|
|
2294
2294
|
const uniqueValues = [...new Set(this.value)];
|
|
@@ -2305,7 +2305,7 @@ let CustomData$1 = class CustomData {
|
|
|
2305
2305
|
}
|
|
2306
2306
|
return (UrlEventType.CustomData +
|
|
2307
2307
|
UrlParameter.Index +
|
|
2308
|
-
this.
|
|
2308
|
+
this._index +
|
|
2309
2309
|
UrlParameter.ValuesCountMap +
|
|
2310
2310
|
encodeURIComponent(JSON.stringify(resultValue)) +
|
|
2311
2311
|
UrlParameter.Overwrite +
|
|
@@ -2313,7 +2313,7 @@ let CustomData$1 = class CustomData {
|
|
|
2313
2313
|
identifierParameter);
|
|
2314
2314
|
}
|
|
2315
2315
|
get data() {
|
|
2316
|
-
return Object.assign(Object.assign({ index: this.
|
|
2316
|
+
return Object.assign(Object.assign({ index: this._index }, (this._name !== undefined ? { name: this._name } : {})), { value: this.value, type: exports.KameleoonData.CustomData, isIdentifier: this.isIdentifier, status: this.status, overwrite: this.overwrite });
|
|
2317
2317
|
}
|
|
2318
2318
|
get status() {
|
|
2319
2319
|
if (this._isMappingIdentifier) {
|
|
@@ -2332,7 +2332,7 @@ let CustomData$1 = class CustomData {
|
|
|
2332
2332
|
let customData;
|
|
2333
2333
|
if (name) {
|
|
2334
2334
|
customData = new CustomData(name, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
|
|
2335
|
-
customData.
|
|
2335
|
+
customData.index = index;
|
|
2336
2336
|
}
|
|
2337
2337
|
else {
|
|
2338
2338
|
customData = new CustomData(index, overwrite !== null && overwrite !== void 0 ? overwrite : true, ...value);
|
|
@@ -2369,13 +2369,28 @@ let CustomData$1 = class CustomData {
|
|
|
2369
2369
|
}
|
|
2370
2370
|
/**
|
|
2371
2371
|
* @private
|
|
2372
|
-
* @method
|
|
2372
|
+
* @method index - an internal setter for setting index of custom data
|
|
2373
2373
|
* @param {number} value - an index value
|
|
2374
2374
|
* */
|
|
2375
|
-
set
|
|
2376
|
-
this.
|
|
2375
|
+
set index(value) {
|
|
2376
|
+
this._index = value;
|
|
2377
|
+
}
|
|
2378
|
+
/**
|
|
2379
|
+
* @private
|
|
2380
|
+
* @method index - an internal getter for index of custom data
|
|
2381
|
+
* */
|
|
2382
|
+
get index() {
|
|
2383
|
+
return this._index;
|
|
2384
|
+
}
|
|
2385
|
+
/**
|
|
2386
|
+
* @private
|
|
2387
|
+
* @method name - an internal getter for a name of custom data
|
|
2388
|
+
* */
|
|
2389
|
+
get name() {
|
|
2390
|
+
return this._name;
|
|
2377
2391
|
}
|
|
2378
2392
|
};
|
|
2393
|
+
CustomData$1.UNDEFINED_INDEX = -1;
|
|
2379
2394
|
|
|
2380
2395
|
/**
|
|
2381
2396
|
* @class
|
|
@@ -2412,6 +2427,9 @@ let Conversion$1 = class Conversion {
|
|
|
2412
2427
|
? UrlParameter.Metadata + this._encodeMetadata()
|
|
2413
2428
|
: ''));
|
|
2414
2429
|
}
|
|
2430
|
+
get _metadata() {
|
|
2431
|
+
return this.metadata;
|
|
2432
|
+
}
|
|
2415
2433
|
get data() {
|
|
2416
2434
|
var _a;
|
|
2417
2435
|
return {
|
|
@@ -5120,7 +5138,7 @@ class ConditionFactory {
|
|
|
5120
5138
|
case TargetingType.HEAT_SLICE:
|
|
5121
5139
|
return buildExports.Ok(new ConversionLikelihood(data));
|
|
5122
5140
|
default:
|
|
5123
|
-
KameleoonLogger.
|
|
5141
|
+
KameleoonLogger.info `Unsupported targeted condition type found: ${targetingType}`;
|
|
5124
5142
|
return buildExports.Err(new KameleoonError(exports.KameleoonException.TargetingCondition, targetingType));
|
|
5125
5143
|
}
|
|
5126
5144
|
}
|
|
@@ -5842,7 +5860,9 @@ class DataManager {
|
|
|
5842
5860
|
return null;
|
|
5843
5861
|
}
|
|
5844
5862
|
mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, }) {
|
|
5863
|
+
var _a;
|
|
5845
5864
|
for (const dataItem of kameleoonData) {
|
|
5865
|
+
// process custom data
|
|
5846
5866
|
if (dataItem.data.type === exports.KameleoonData.CustomData) {
|
|
5847
5867
|
const customDataIsValid = this.processCustomData({
|
|
5848
5868
|
infoData,
|
|
@@ -5854,6 +5874,10 @@ class DataManager {
|
|
|
5854
5874
|
continue;
|
|
5855
5875
|
}
|
|
5856
5876
|
}
|
|
5877
|
+
// process metadata of conversions
|
|
5878
|
+
if (dataItem.data.type === exports.KameleoonData.Conversion) {
|
|
5879
|
+
(_a = dataItem._metadata) === null || _a === void 0 ? void 0 : _a.forEach((item) => this.trySetCustomDataIndexByName(item));
|
|
5880
|
+
}
|
|
5857
5881
|
const expirationTime = this.dataProcessor.mutUpdateData({
|
|
5858
5882
|
infoData,
|
|
5859
5883
|
visitorCode,
|
|
@@ -5893,13 +5917,9 @@ class DataManager {
|
|
|
5893
5917
|
var _a;
|
|
5894
5918
|
const { data } = customData;
|
|
5895
5919
|
const isDataValid = Boolean(data.value.length && data.value[0].length);
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
return false;
|
|
5900
|
-
}
|
|
5901
|
-
data.index = cdIndex;
|
|
5902
|
-
customData._index = cdIndex;
|
|
5920
|
+
this.trySetCustomDataIndexByName(customData);
|
|
5921
|
+
if (data.index == CustomData$1.UNDEFINED_INDEX) {
|
|
5922
|
+
data.index = customData.index;
|
|
5903
5923
|
}
|
|
5904
5924
|
if (this.mappingIdentifierCustomDataIndex === data.index && isDataValid) {
|
|
5905
5925
|
customData._isMappingIdentifier = true;
|
|
@@ -5926,6 +5946,15 @@ class DataManager {
|
|
|
5926
5946
|
}
|
|
5927
5947
|
return true;
|
|
5928
5948
|
}
|
|
5949
|
+
trySetCustomDataIndexByName(customData) {
|
|
5950
|
+
if (customData.index == CustomData$1.UNDEFINED_INDEX && customData.name) {
|
|
5951
|
+
const cdIndex = this.customDataIndexByName.get(customData.name);
|
|
5952
|
+
if (cdIndex === undefined) {
|
|
5953
|
+
return;
|
|
5954
|
+
}
|
|
5955
|
+
customData.index = cdIndex;
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5929
5958
|
get unsentDataVisitors() {
|
|
5930
5959
|
const infoResult = this.infoStorage.read();
|
|
5931
5960
|
if (!infoResult.ok) {
|
|
@@ -7769,7 +7798,7 @@ class BodyProvider {
|
|
|
7769
7798
|
const identifier = isMappingIdentifier
|
|
7770
7799
|
? UrlParameter.MappingValue
|
|
7771
7800
|
: UrlParameter.VisitorCode;
|
|
7772
|
-
return identifier + visitorCode;
|
|
7801
|
+
return identifier + encodeURIComponent(visitorCode);
|
|
7773
7802
|
}
|
|
7774
7803
|
}
|
|
7775
7804
|
|
|
@@ -8353,6 +8382,7 @@ class KameleoonClient {
|
|
|
8353
8382
|
}
|
|
8354
8383
|
const resultVariables = variables.map((variable) => Parser.parseFeatureVariable(variable).throw());
|
|
8355
8384
|
resultFeatureList.set(variation.featureKey, {
|
|
8385
|
+
name: '',
|
|
8356
8386
|
key: variationKey,
|
|
8357
8387
|
id: variationId,
|
|
8358
8388
|
experimentId,
|
|
@@ -8573,6 +8603,62 @@ class KameleoonClient {
|
|
|
8573
8603
|
this.flush(visitorCode);
|
|
8574
8604
|
KameleoonLogger.info `RETURN: KameleoonClient.evaluateAudiences(visitorCode: ${visitorCode})`;
|
|
8575
8605
|
}
|
|
8606
|
+
getDataFile() {
|
|
8607
|
+
const dataFile = {
|
|
8608
|
+
featureFlags: new Map(),
|
|
8609
|
+
};
|
|
8610
|
+
if (this.stubMode) {
|
|
8611
|
+
return dataFile;
|
|
8612
|
+
}
|
|
8613
|
+
KameleoonLogger.debug `CALL: KameleoonClient.getDataFile()`;
|
|
8614
|
+
this.clientConfiguration.featureFlags.forEach((featureFlag, key) => {
|
|
8615
|
+
const variationsMap = new Map();
|
|
8616
|
+
featureFlag.variations.forEach((sourceVariation) => {
|
|
8617
|
+
var _a;
|
|
8618
|
+
const variablesMap = new Map();
|
|
8619
|
+
sourceVariation.variables.forEach((variable) => {
|
|
8620
|
+
try {
|
|
8621
|
+
const parsedVariable = Parser.parseFeatureVariable(variable).throw();
|
|
8622
|
+
variablesMap.set(variable.key, parsedVariable);
|
|
8623
|
+
}
|
|
8624
|
+
catch (err) {
|
|
8625
|
+
KameleoonLogger.error `Error parsing variable ${variable.key} of feature flag ${featureFlag.featureKey}: ${err}`;
|
|
8626
|
+
}
|
|
8627
|
+
});
|
|
8628
|
+
variationsMap.set(sourceVariation.key, {
|
|
8629
|
+
name: (_a = sourceVariation.name) !== null && _a !== void 0 ? _a : '',
|
|
8630
|
+
key: sourceVariation.key,
|
|
8631
|
+
id: null,
|
|
8632
|
+
experimentId: null,
|
|
8633
|
+
variables: variablesMap,
|
|
8634
|
+
});
|
|
8635
|
+
});
|
|
8636
|
+
const rules = featureFlag.rules.map((rule) => {
|
|
8637
|
+
const ruleVariations = new Map();
|
|
8638
|
+
rule.variationByExposition.forEach((varByExp) => {
|
|
8639
|
+
const baseVariation = variationsMap.get(varByExp.variationKey);
|
|
8640
|
+
if (!baseVariation)
|
|
8641
|
+
return;
|
|
8642
|
+
ruleVariations.set(baseVariation.key, {
|
|
8643
|
+
name: baseVariation.name,
|
|
8644
|
+
key: baseVariation.key,
|
|
8645
|
+
id: varByExp.variationId,
|
|
8646
|
+
experimentId: rule.experimentId,
|
|
8647
|
+
variables: baseVariation.variables,
|
|
8648
|
+
});
|
|
8649
|
+
});
|
|
8650
|
+
return { variations: ruleVariations };
|
|
8651
|
+
});
|
|
8652
|
+
dataFile.featureFlags.set(key, {
|
|
8653
|
+
variations: variationsMap,
|
|
8654
|
+
environmentEnabled: featureFlag.environmentEnabled,
|
|
8655
|
+
rules,
|
|
8656
|
+
defaultVariationKey: featureFlag.defaultVariationKey,
|
|
8657
|
+
});
|
|
8658
|
+
});
|
|
8659
|
+
KameleoonLogger.debug `RETURN: KameleoonClient.getDataFile() -> (dataFile: ${dataFile})`;
|
|
8660
|
+
return dataFile;
|
|
8661
|
+
}
|
|
8576
8662
|
setUserConsent({ visitorCode, consent, setData, }) {
|
|
8577
8663
|
if (this.stubMode) {
|
|
8578
8664
|
return;
|
|
@@ -8759,6 +8845,7 @@ class KameleoonClient {
|
|
|
8759
8845
|
return selected;
|
|
8760
8846
|
}
|
|
8761
8847
|
_getFeatureVariation({ visitorCode, featureKey, track, }) {
|
|
8848
|
+
var _a, _b;
|
|
8762
8849
|
KameleoonLogger.debug `CALL: KameleoonClient._getFeatureVariation(visitorCode: ${visitorCode}, featureKey: ${featureKey}, track: ${track})`;
|
|
8763
8850
|
if (!this.initialized) {
|
|
8764
8851
|
return buildExports.Err(new KameleoonError(exports.KameleoonException.Initialization));
|
|
@@ -8809,7 +8896,9 @@ class KameleoonClient {
|
|
|
8809
8896
|
if (track && !isSimulated) {
|
|
8810
8897
|
this.tracker.scheduleVisitor(visitorCode, this._isConsentProvided(visitorCode));
|
|
8811
8898
|
}
|
|
8899
|
+
const variationName = (_b = (_a = featureFlag.variations.find((item) => item.key === variationKey)) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : '';
|
|
8812
8900
|
const resultData = {
|
|
8901
|
+
name: variationName,
|
|
8813
8902
|
key: variationKey,
|
|
8814
8903
|
id: variationId,
|
|
8815
8904
|
experimentId,
|