@kameleoon/javascript-sdk-core 5.17.3 → 5.18.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 +9 -0
- package/dist/browser.d.ts +1 -1
- package/dist/cacheManager/cacheManager.d.ts +2 -2
- package/dist/clientConfiguration/clientConfiguration.d.ts +9 -9
- package/dist/clientSettings/clientSettings.d.ts +11 -8
- package/dist/index.d.ts +1 -1
- package/dist/javascript-sdk-core.browser.cjs.js +214 -180
- package/dist/javascript-sdk-core.browser.cjs.js.map +1 -1
- package/dist/javascript-sdk-core.browser.es.js +214 -180
- package/dist/javascript-sdk-core.browser.es.js.map +1 -1
- package/dist/javascript-sdk-core.cjs.js +214 -180
- package/dist/javascript-sdk-core.cjs.js.map +1 -1
- package/dist/javascript-sdk-core.es.js +214 -180
- package/dist/javascript-sdk-core.es.js.map +1 -1
- package/dist/kameleoonClient.d.ts +12 -10
- package/dist/kameleoonClientInterface.d.ts +18 -10
- package/dist/kameleoonData/browser.d.ts +2 -2
- package/dist/kameleoonData/conversion.d.ts +3 -3
- package/dist/kameleoonData/customData.d.ts +3 -3
- package/dist/kameleoonData/dataManager.d.ts +11 -4
- package/dist/kameleoonData/device.d.ts +1 -1
- package/dist/kameleoonData/geolocation.d.ts +5 -5
- package/dist/kameleoonData/index.d.ts +1 -1
- package/dist/kameleoonData/pageView.d.ts +3 -3
- package/dist/kameleoonData/targetedSegment.d.ts +1 -1
- package/dist/kameleoonData/types.d.ts +12 -0
- package/dist/kameleoonData/uniqueIdentifier.d.ts +1 -1
- package/dist/kameleoonData/userAgent.d.ts +1 -1
- package/dist/tracking/tracker.d.ts +7 -7
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
|
@@ -3366,6 +3366,7 @@ class Parser {
|
|
|
3366
3366
|
}
|
|
3367
3367
|
}
|
|
3368
3368
|
|
|
3369
|
+
var _a;
|
|
3369
3370
|
class ClientSettings {
|
|
3370
3371
|
constructor(siteCode, configuration) {
|
|
3371
3372
|
KameleoonLogger.debug `CALL: new ClientSettings(siteCode: ${siteCode}, configuration: ${configuration})`;
|
|
@@ -3380,18 +3381,19 @@ class ClientSettings {
|
|
|
3380
3381
|
KameleoonLogger.debug `RETURN: new ClientSettings(siteCode: ${siteCode}, configuration: ${configuration})`;
|
|
3381
3382
|
}
|
|
3382
3383
|
getTrackingInterval(configuration) {
|
|
3384
|
+
const { MIN_TRACKING_INTERVAL_MS, MAX_TRACKING_INTERVAL_MS, DEFAULT_TRACKING_INTERVAL_MS, } = ClientSettings;
|
|
3383
3385
|
if (typeof (configuration === null || configuration === void 0 ? void 0 : configuration.trackingInterval) === 'number') {
|
|
3384
|
-
if (configuration.trackingInterval <
|
|
3385
|
-
KameleoonLogger.warning(
|
|
3386
|
-
return
|
|
3386
|
+
if (configuration.trackingInterval < MIN_TRACKING_INTERVAL_MS) {
|
|
3387
|
+
KameleoonLogger.warning(`Tracking interval must not be shorter than ${MIN_TRACKING_INTERVAL_MS} ms. Minimum possible interval was applied.`);
|
|
3388
|
+
return MIN_TRACKING_INTERVAL_MS;
|
|
3387
3389
|
}
|
|
3388
|
-
if (configuration.trackingInterval >
|
|
3389
|
-
KameleoonLogger.warning(
|
|
3390
|
-
return
|
|
3390
|
+
if (configuration.trackingInterval > MAX_TRACKING_INTERVAL_MS) {
|
|
3391
|
+
KameleoonLogger.warning(`Tracking interval must not be longer than ${MAX_TRACKING_INTERVAL_MS} ms. Maximum possible interval was applied.`);
|
|
3392
|
+
return MAX_TRACKING_INTERVAL_MS;
|
|
3391
3393
|
}
|
|
3392
3394
|
return configuration.trackingInterval;
|
|
3393
3395
|
}
|
|
3394
|
-
return
|
|
3396
|
+
return DEFAULT_TRACKING_INTERVAL_MS;
|
|
3395
3397
|
}
|
|
3396
3398
|
getEnvironment(configuration) {
|
|
3397
3399
|
if (configuration === null || configuration === void 0 ? void 0 : configuration.environment) {
|
|
@@ -3445,6 +3447,10 @@ class ClientSettings {
|
|
|
3445
3447
|
};
|
|
3446
3448
|
}
|
|
3447
3449
|
}
|
|
3450
|
+
_a = ClientSettings;
|
|
3451
|
+
ClientSettings.DEFAULT_TRACKING_INTERVAL_MS = 1000;
|
|
3452
|
+
ClientSettings.MIN_TRACKING_INTERVAL_MS = _a.DEFAULT_TRACKING_INTERVAL_MS;
|
|
3453
|
+
ClientSettings.MAX_TRACKING_INTERVAL_MS = 5000;
|
|
3448
3454
|
|
|
3449
3455
|
/**
|
|
3450
3456
|
* @class
|
|
@@ -5439,7 +5445,6 @@ class StorageCleanupManager {
|
|
|
5439
5445
|
break;
|
|
5440
5446
|
default:
|
|
5441
5447
|
// check if all cases are handled
|
|
5442
|
-
const exhaustiveCheck = storageKey;
|
|
5443
5448
|
KameleoonLogger.error `Unknown storage key: ${storageKey} for initCleanupInterval.`;
|
|
5444
5449
|
}
|
|
5445
5450
|
}
|
|
@@ -5734,7 +5739,7 @@ class DataManager {
|
|
|
5734
5739
|
return resultData;
|
|
5735
5740
|
}
|
|
5736
5741
|
storeTrackedData(data) {
|
|
5737
|
-
this.
|
|
5742
|
+
this.storeDataForVisitors(data, false);
|
|
5738
5743
|
const infoResult = this.infoStorage.read();
|
|
5739
5744
|
if (!infoResult.ok) {
|
|
5740
5745
|
return;
|
|
@@ -5768,30 +5773,31 @@ class DataManager {
|
|
|
5768
5773
|
}
|
|
5769
5774
|
this.infoStorage.write(infoResult.data);
|
|
5770
5775
|
}
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
}
|
|
5778
|
-
if (!infoResult.ok) {
|
|
5779
|
-
return infoResult;
|
|
5780
|
-
}
|
|
5781
|
-
const targetingData = result.data;
|
|
5782
|
-
const infoData = infoResult.data;
|
|
5783
|
-
if (typeof firstParameter === 'string') {
|
|
5776
|
+
/**
|
|
5777
|
+
* Store data for a single visitor
|
|
5778
|
+
*/
|
|
5779
|
+
storeData({ visitorCode, data, track, }) {
|
|
5780
|
+
KameleoonLogger.debug `CALL: DataManager.storeDataForVisitor(vc: ${visitorCode}, track: ${track}, data: ${data})`;
|
|
5781
|
+
const result = this.storeDataInternal((infoData, targetingData) => {
|
|
5784
5782
|
this.mutUpdateTargetingData({
|
|
5785
5783
|
infoData,
|
|
5786
5784
|
targetingData,
|
|
5787
|
-
visitorCode
|
|
5788
|
-
kameleoonData:
|
|
5785
|
+
visitorCode,
|
|
5786
|
+
kameleoonData: data,
|
|
5789
5787
|
extendTtl: true,
|
|
5788
|
+
track,
|
|
5790
5789
|
});
|
|
5791
|
-
}
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5790
|
+
});
|
|
5791
|
+
KameleoonLogger.debug `RETURN: DataManager.storeDataForVisitor(vc: ${visitorCode}, track: ${track}, data: ${data}) -> ${result}`;
|
|
5792
|
+
return result;
|
|
5793
|
+
}
|
|
5794
|
+
/**
|
|
5795
|
+
* Store data for multiple visitors
|
|
5796
|
+
*/
|
|
5797
|
+
storeDataForVisitors(data, extendTtl) {
|
|
5798
|
+
KameleoonLogger.debug `CALL: DataManager.storeDataForVisitors(data: ${data}, extendTtl: ${extendTtl})`;
|
|
5799
|
+
const result = this.storeDataInternal((infoData, targetingData) => {
|
|
5800
|
+
for (const [visitorCode, kameleoonData] of Object.entries(data)) {
|
|
5795
5801
|
this.mutUpdateTargetingData({
|
|
5796
5802
|
infoData,
|
|
5797
5803
|
targetingData,
|
|
@@ -5800,12 +5806,26 @@ class DataManager {
|
|
|
5800
5806
|
extendTtl,
|
|
5801
5807
|
});
|
|
5802
5808
|
}
|
|
5809
|
+
});
|
|
5810
|
+
KameleoonLogger.debug `RETURN: DataManager.storeDataForVisitors(data: ${data}, extendTtl: ${extendTtl}) -> ${result}`;
|
|
5811
|
+
return result;
|
|
5812
|
+
}
|
|
5813
|
+
// ========= Internal shared logic =========
|
|
5814
|
+
storeDataInternal(updater) {
|
|
5815
|
+
const dataResult = this.dataStorage.read();
|
|
5816
|
+
if (!dataResult.ok) {
|
|
5817
|
+
return dataResult;
|
|
5803
5818
|
}
|
|
5819
|
+
const infoResult = this.infoStorage.read();
|
|
5820
|
+
if (!infoResult.ok) {
|
|
5821
|
+
return infoResult;
|
|
5822
|
+
}
|
|
5823
|
+
const targetingData = dataResult.data;
|
|
5824
|
+
const infoData = infoResult.data;
|
|
5825
|
+
updater(infoData, targetingData);
|
|
5804
5826
|
this.cleanupData();
|
|
5805
|
-
this.infoStorage.write(
|
|
5806
|
-
|
|
5807
|
-
KameleoonLogger.debug `RETURN: DataManager.storeData(visitorCode: ${firstParameter}, data: ${secondParameter}) -> (writeResult: ${writeResult})`;
|
|
5808
|
-
return writeResult;
|
|
5827
|
+
this.infoStorage.write(infoData);
|
|
5828
|
+
return this.dataStorage.write(targetingData);
|
|
5809
5829
|
}
|
|
5810
5830
|
getTree(segment) {
|
|
5811
5831
|
if (this.targetingTrees.has(segment.id)) {
|
|
@@ -5894,29 +5914,31 @@ class DataManager {
|
|
|
5894
5914
|
return new Set(Object.keys(targetingData));
|
|
5895
5915
|
}
|
|
5896
5916
|
getLinkedVisitor(visitorCode) {
|
|
5917
|
+
var _a, _b, _c;
|
|
5897
5918
|
const storageData = this.dataStorage.read();
|
|
5898
5919
|
if (!storageData.ok) {
|
|
5899
5920
|
return null;
|
|
5900
5921
|
}
|
|
5901
|
-
|
|
5902
|
-
|
|
5922
|
+
const visitorDataOrRef = storageData.data[visitorCode];
|
|
5923
|
+
// Direct reference case
|
|
5924
|
+
if (typeof visitorDataOrRef === 'string') {
|
|
5925
|
+
return visitorDataOrRef;
|
|
5903
5926
|
}
|
|
5904
|
-
|
|
5927
|
+
// No mapping index or no visitor data
|
|
5928
|
+
if (visitorDataOrRef == null ||
|
|
5929
|
+
this.mappingIdentifierCustomDataIndex == null) {
|
|
5905
5930
|
return null;
|
|
5906
5931
|
}
|
|
5907
|
-
const
|
|
5908
|
-
|
|
5909
|
-
return null;
|
|
5910
|
-
}
|
|
5911
|
-
const customData = visitorData[exports.KameleoonData.CustomData];
|
|
5912
|
-
if (customData && customData[this.mappingIdentifierCustomDataIndex]) {
|
|
5913
|
-
return customData[this.mappingIdentifierCustomDataIndex].value[0];
|
|
5914
|
-
}
|
|
5915
|
-
return null;
|
|
5932
|
+
const value = (_c = (_b = (_a = visitorDataOrRef[exports.KameleoonData.CustomData]) === null || _a === void 0 ? void 0 : _a[this.mappingIdentifierCustomDataIndex]) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c[0];
|
|
5933
|
+
return value !== null && value !== void 0 ? value : null;
|
|
5916
5934
|
}
|
|
5917
|
-
mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, extendTtl, }) {
|
|
5935
|
+
mutUpdateTargetingData({ infoData, visitorCode, kameleoonData, targetingData, extendTtl, track, }) {
|
|
5918
5936
|
var _a, _b, _c;
|
|
5919
5937
|
for (const dataItem of kameleoonData) {
|
|
5938
|
+
// prcoess track status
|
|
5939
|
+
if (track === false) {
|
|
5940
|
+
dataItem.status = exports.TrackingStatus.Sent;
|
|
5941
|
+
}
|
|
5920
5942
|
// process custom data
|
|
5921
5943
|
if (dataItem.data.type === exports.KameleoonData.CustomData) {
|
|
5922
5944
|
const customDataIsValid = this.processCustomData({
|
|
@@ -6074,6 +6096,135 @@ class DataManager {
|
|
|
6074
6096
|
}
|
|
6075
6097
|
}
|
|
6076
6098
|
|
|
6099
|
+
const VISITOR_CODE_LENGTH = 16;
|
|
6100
|
+
const VISITOR_CODE_MAX_LENGTH = 255;
|
|
6101
|
+
const DEFAULT_MAX_AGE = 60 * 60 * 24 * 365;
|
|
6102
|
+
const PATH = '/';
|
|
6103
|
+
|
|
6104
|
+
/**
|
|
6105
|
+
* VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve,
|
|
6106
|
+
* and handle these codes while considering user consent.
|
|
6107
|
+
**/
|
|
6108
|
+
class VisitorCodeManager {
|
|
6109
|
+
constructor() {
|
|
6110
|
+
this.isConsentRequired = false;
|
|
6111
|
+
}
|
|
6112
|
+
set consentRequired(isRequired) {
|
|
6113
|
+
this.isConsentRequired = isRequired;
|
|
6114
|
+
}
|
|
6115
|
+
get consentRequired() {
|
|
6116
|
+
return this.isConsentRequired;
|
|
6117
|
+
}
|
|
6118
|
+
set getData(callback) {
|
|
6119
|
+
this.getDataCallback = callback;
|
|
6120
|
+
}
|
|
6121
|
+
set setData(callback) {
|
|
6122
|
+
this.setDataCallback = callback;
|
|
6123
|
+
}
|
|
6124
|
+
get setData() {
|
|
6125
|
+
if (this.setDataCallback) {
|
|
6126
|
+
return this.setDataCallback;
|
|
6127
|
+
}
|
|
6128
|
+
throw new Error('Missing setDataCallback!');
|
|
6129
|
+
}
|
|
6130
|
+
validateVisitorCode(visitorCode) {
|
|
6131
|
+
if (visitorCode.length === 0) {
|
|
6132
|
+
return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeEmpty));
|
|
6133
|
+
}
|
|
6134
|
+
if (visitorCode.length > VISITOR_CODE_MAX_LENGTH) {
|
|
6135
|
+
return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeMaxLength));
|
|
6136
|
+
}
|
|
6137
|
+
return buildExports.Ok();
|
|
6138
|
+
}
|
|
6139
|
+
getVisitorCode(defaultVisitorCode) {
|
|
6140
|
+
KameleoonLogger.debug `CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode})`;
|
|
6141
|
+
if (!this.getDataCallback || !this.setDataCallback) {
|
|
6142
|
+
throw new Error('Missing getDataCallback or setDataCallback methods in getVisitorCode!');
|
|
6143
|
+
}
|
|
6144
|
+
let visitorCode;
|
|
6145
|
+
const existingVisitorCode = this.getDataCallback(exports.KameleoonStorageKey.VisitorCode);
|
|
6146
|
+
if (existingVisitorCode) {
|
|
6147
|
+
visitorCode = existingVisitorCode;
|
|
6148
|
+
}
|
|
6149
|
+
if (!visitorCode) {
|
|
6150
|
+
if (defaultVisitorCode) {
|
|
6151
|
+
this.validateVisitorCode(defaultVisitorCode).throw();
|
|
6152
|
+
visitorCode = defaultVisitorCode;
|
|
6153
|
+
KameleoonLogger.debug `Used default visitor code: ${visitorCode}`;
|
|
6154
|
+
}
|
|
6155
|
+
else {
|
|
6156
|
+
visitorCode = this.generateVisitorCode();
|
|
6157
|
+
KameleoonLogger.debug `Generated new visitor code: ${visitorCode}`;
|
|
6158
|
+
}
|
|
6159
|
+
}
|
|
6160
|
+
this.processSimulatedVariations(visitorCode);
|
|
6161
|
+
if (!this.isConsentRequired) {
|
|
6162
|
+
this.setDataCallback({
|
|
6163
|
+
visitorCode,
|
|
6164
|
+
key: exports.KameleoonStorageKey.VisitorCode,
|
|
6165
|
+
maxAge: DEFAULT_MAX_AGE,
|
|
6166
|
+
path: PATH,
|
|
6167
|
+
});
|
|
6168
|
+
}
|
|
6169
|
+
KameleoonLogger.debug `RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode}) -> (visitorCode: ${visitorCode})`;
|
|
6170
|
+
return visitorCode;
|
|
6171
|
+
}
|
|
6172
|
+
processSimulatedVariations(visitorCode) {
|
|
6173
|
+
if (this.variationConfiguration) {
|
|
6174
|
+
const simulatedVariationsData = this.getSimulatedVariations(visitorCode);
|
|
6175
|
+
try {
|
|
6176
|
+
this.variationConfiguration.clearSimulatedVariations(visitorCode).throw();
|
|
6177
|
+
if (simulatedVariationsData !== null && simulatedVariationsData.length > 0) {
|
|
6178
|
+
this.variationConfiguration.updateForcedFeatureVariations(visitorCode, simulatedVariationsData).throw();
|
|
6179
|
+
}
|
|
6180
|
+
}
|
|
6181
|
+
catch (error) {
|
|
6182
|
+
if (error instanceof Error) {
|
|
6183
|
+
KameleoonLogger.error `Failed to process simulated variations: ${error.message}`;
|
|
6184
|
+
}
|
|
6185
|
+
}
|
|
6186
|
+
}
|
|
6187
|
+
}
|
|
6188
|
+
getSimulatedVariations(visitorCode) {
|
|
6189
|
+
KameleoonLogger.debug `CALL: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode})`;
|
|
6190
|
+
const simulatedVariationsData = this.getDataCallback(exports.KameleoonStorageKey.KameleoonSimulationFFData);
|
|
6191
|
+
let variations = null;
|
|
6192
|
+
if (typeof simulatedVariationsData === 'string' &&
|
|
6193
|
+
simulatedVariationsData.length > 0) {
|
|
6194
|
+
try {
|
|
6195
|
+
const parsed = JSON.parse(decodeURIComponent(simulatedVariationsData));
|
|
6196
|
+
if (parsed && typeof parsed === 'object') {
|
|
6197
|
+
variations = Object.entries(parsed)
|
|
6198
|
+
.map(([key, value]) => {
|
|
6199
|
+
return this.variationConfiguration.simulatedVariationFromJson(key, value);
|
|
6200
|
+
})
|
|
6201
|
+
.filter((variation) => variation !== null);
|
|
6202
|
+
}
|
|
6203
|
+
}
|
|
6204
|
+
catch (error) {
|
|
6205
|
+
if (error instanceof Error) {
|
|
6206
|
+
KameleoonLogger.error `Failed to parse simulated variations: ${error.message}`;
|
|
6207
|
+
}
|
|
6208
|
+
}
|
|
6209
|
+
}
|
|
6210
|
+
KameleoonLogger.debug `RETURN: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode}) -> (variations: ${variations})`;
|
|
6211
|
+
return variations;
|
|
6212
|
+
}
|
|
6213
|
+
generateVisitorCode() {
|
|
6214
|
+
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
6215
|
+
const randomCharacterArray = [];
|
|
6216
|
+
for (let i = 0; i < VISITOR_CODE_LENGTH; i++) {
|
|
6217
|
+
randomCharacterArray.push(characters[Math.floor(Math.random() * characters.length)]);
|
|
6218
|
+
}
|
|
6219
|
+
return randomCharacterArray.join('');
|
|
6220
|
+
}
|
|
6221
|
+
setVariationConfiguration(variationConfiguration) {
|
|
6222
|
+
if (!this.variationConfiguration) {
|
|
6223
|
+
this.variationConfiguration = variationConfiguration;
|
|
6224
|
+
}
|
|
6225
|
+
}
|
|
6226
|
+
}
|
|
6227
|
+
|
|
6077
6228
|
var sha256$2 = {exports: {}};
|
|
6078
6229
|
|
|
6079
6230
|
function commonjsRequire(path) {
|
|
@@ -7599,135 +7750,6 @@ class KameleoonEventSource {
|
|
|
7599
7750
|
}
|
|
7600
7751
|
}
|
|
7601
7752
|
|
|
7602
|
-
const VISITOR_CODE_LENGTH = 16;
|
|
7603
|
-
const VISITOR_CODE_MAX_LENGTH = 255;
|
|
7604
|
-
const DEFAULT_MAX_AGE = 60 * 60 * 24 * 365;
|
|
7605
|
-
const PATH = '/';
|
|
7606
|
-
|
|
7607
|
-
/**
|
|
7608
|
-
* VisitorCodeManager - a class which manages visitor codes using cookies, offering functions to generate, retrieve,
|
|
7609
|
-
* and handle these codes while considering user consent.
|
|
7610
|
-
**/
|
|
7611
|
-
class VisitorCodeManager {
|
|
7612
|
-
constructor() {
|
|
7613
|
-
this.isConsentRequired = false;
|
|
7614
|
-
}
|
|
7615
|
-
set consentRequired(isRequired) {
|
|
7616
|
-
this.isConsentRequired = isRequired;
|
|
7617
|
-
}
|
|
7618
|
-
get consentRequired() {
|
|
7619
|
-
return this.isConsentRequired;
|
|
7620
|
-
}
|
|
7621
|
-
set getData(callback) {
|
|
7622
|
-
this.getDataCallback = callback;
|
|
7623
|
-
}
|
|
7624
|
-
set setData(callback) {
|
|
7625
|
-
this.setDataCallback = callback;
|
|
7626
|
-
}
|
|
7627
|
-
get setData() {
|
|
7628
|
-
if (this.setDataCallback) {
|
|
7629
|
-
return this.setDataCallback;
|
|
7630
|
-
}
|
|
7631
|
-
throw new Error('Missing setDataCallback!');
|
|
7632
|
-
}
|
|
7633
|
-
validateVisitorCode(visitorCode) {
|
|
7634
|
-
if (visitorCode.length === 0) {
|
|
7635
|
-
return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeEmpty));
|
|
7636
|
-
}
|
|
7637
|
-
if (visitorCode.length > VISITOR_CODE_MAX_LENGTH) {
|
|
7638
|
-
return buildExports.Err(new KameleoonError(exports.KameleoonException.VisitorCodeMaxLength));
|
|
7639
|
-
}
|
|
7640
|
-
return buildExports.Ok();
|
|
7641
|
-
}
|
|
7642
|
-
getVisitorCode(defaultVisitorCode) {
|
|
7643
|
-
KameleoonLogger.debug `CALL: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode})`;
|
|
7644
|
-
if (!this.getDataCallback || !this.setDataCallback) {
|
|
7645
|
-
throw new Error('Missing getDataCallback or setDataCallback methods in getVisitorCode!');
|
|
7646
|
-
}
|
|
7647
|
-
let visitorCode;
|
|
7648
|
-
const existingVisitorCode = this.getDataCallback(exports.KameleoonStorageKey.VisitorCode);
|
|
7649
|
-
if (existingVisitorCode) {
|
|
7650
|
-
visitorCode = existingVisitorCode;
|
|
7651
|
-
}
|
|
7652
|
-
if (!visitorCode) {
|
|
7653
|
-
if (defaultVisitorCode) {
|
|
7654
|
-
this.validateVisitorCode(defaultVisitorCode).throw();
|
|
7655
|
-
visitorCode = defaultVisitorCode;
|
|
7656
|
-
KameleoonLogger.debug `Used default visitor code: ${visitorCode}`;
|
|
7657
|
-
}
|
|
7658
|
-
else {
|
|
7659
|
-
visitorCode = this.generateVisitorCode();
|
|
7660
|
-
KameleoonLogger.debug `Generated new visitor code: ${visitorCode}`;
|
|
7661
|
-
}
|
|
7662
|
-
}
|
|
7663
|
-
this.processSimulatedVariations(visitorCode);
|
|
7664
|
-
if (!this.isConsentRequired) {
|
|
7665
|
-
this.setDataCallback({
|
|
7666
|
-
visitorCode,
|
|
7667
|
-
key: exports.KameleoonStorageKey.VisitorCode,
|
|
7668
|
-
maxAge: DEFAULT_MAX_AGE,
|
|
7669
|
-
path: PATH,
|
|
7670
|
-
});
|
|
7671
|
-
}
|
|
7672
|
-
KameleoonLogger.debug `RETURN: VisitorCodeManager.getVisitorCode(defaultVisitorCode: ${defaultVisitorCode}) -> (visitorCode: ${visitorCode})`;
|
|
7673
|
-
return visitorCode;
|
|
7674
|
-
}
|
|
7675
|
-
processSimulatedVariations(visitorCode) {
|
|
7676
|
-
if (this.variationConfiguration) {
|
|
7677
|
-
const simulatedVariationsData = this.getSimulatedVariations(visitorCode);
|
|
7678
|
-
try {
|
|
7679
|
-
this.variationConfiguration.clearSimulatedVariations(visitorCode).throw();
|
|
7680
|
-
if (simulatedVariationsData !== null && simulatedVariationsData.length > 0) {
|
|
7681
|
-
this.variationConfiguration.updateForcedFeatureVariations(visitorCode, simulatedVariationsData).throw();
|
|
7682
|
-
}
|
|
7683
|
-
}
|
|
7684
|
-
catch (error) {
|
|
7685
|
-
if (error instanceof Error) {
|
|
7686
|
-
KameleoonLogger.error `Failed to process simulated variations: ${error.message}`;
|
|
7687
|
-
}
|
|
7688
|
-
}
|
|
7689
|
-
}
|
|
7690
|
-
}
|
|
7691
|
-
getSimulatedVariations(visitorCode) {
|
|
7692
|
-
KameleoonLogger.debug `CALL: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode})`;
|
|
7693
|
-
const simulatedVariationsData = this.getDataCallback(exports.KameleoonStorageKey.KameleoonSimulationFFData);
|
|
7694
|
-
let variations = null;
|
|
7695
|
-
if (typeof simulatedVariationsData === 'string' &&
|
|
7696
|
-
simulatedVariationsData.length > 0) {
|
|
7697
|
-
try {
|
|
7698
|
-
const parsed = JSON.parse(decodeURIComponent(simulatedVariationsData));
|
|
7699
|
-
if (parsed && typeof parsed === 'object') {
|
|
7700
|
-
variations = Object.entries(parsed)
|
|
7701
|
-
.map(([key, value]) => {
|
|
7702
|
-
return this.variationConfiguration.simulatedVariationFromJson(key, value);
|
|
7703
|
-
})
|
|
7704
|
-
.filter((variation) => variation !== null);
|
|
7705
|
-
}
|
|
7706
|
-
}
|
|
7707
|
-
catch (error) {
|
|
7708
|
-
if (error instanceof Error) {
|
|
7709
|
-
KameleoonLogger.error `Failed to parse simulated variations: ${error.message}`;
|
|
7710
|
-
}
|
|
7711
|
-
}
|
|
7712
|
-
}
|
|
7713
|
-
KameleoonLogger.debug `RETURN: VisitorCodeManager.getSimulatedVariations(visitorCode: ${visitorCode}) -> (variations: ${variations})`;
|
|
7714
|
-
return variations;
|
|
7715
|
-
}
|
|
7716
|
-
generateVisitorCode() {
|
|
7717
|
-
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
7718
|
-
const randomCharacterArray = [];
|
|
7719
|
-
for (let i = 0; i < VISITOR_CODE_LENGTH; i++) {
|
|
7720
|
-
randomCharacterArray.push(characters[Math.floor(Math.random() * characters.length)]);
|
|
7721
|
-
}
|
|
7722
|
-
return randomCharacterArray.join('');
|
|
7723
|
-
}
|
|
7724
|
-
setVariationConfiguration(variationConfiguration) {
|
|
7725
|
-
if (!this.variationConfiguration) {
|
|
7726
|
-
this.variationConfiguration = variationConfiguration;
|
|
7727
|
-
}
|
|
7728
|
-
}
|
|
7729
|
-
}
|
|
7730
|
-
|
|
7731
7753
|
var Byte;
|
|
7732
7754
|
(function (Byte) {
|
|
7733
7755
|
Byte[Byte["Kb"] = 1000] = "Kb";
|
|
@@ -7920,7 +7942,10 @@ class Tracker {
|
|
|
7920
7942
|
const linkedVisitor = this.dataManager.getLinkedVisitor(visitorCode);
|
|
7921
7943
|
const index = this.dataManager.identifierCustomDataIndex;
|
|
7922
7944
|
if (!linkedVisitor && typeof index === 'number') {
|
|
7923
|
-
this.dataManager.storeData(
|
|
7945
|
+
this.dataManager.storeData({
|
|
7946
|
+
visitorCode,
|
|
7947
|
+
data: [new CustomData$1(index, visitorCode)],
|
|
7948
|
+
});
|
|
7924
7949
|
}
|
|
7925
7950
|
else {
|
|
7926
7951
|
isMappingIdentifier = true;
|
|
@@ -8069,7 +8094,7 @@ class Tracker {
|
|
|
8069
8094
|
this.dataManager.storeTrackedData(updatedData);
|
|
8070
8095
|
}
|
|
8071
8096
|
else {
|
|
8072
|
-
this.dataManager.
|
|
8097
|
+
this.dataManager.storeDataForVisitors(updatedData, false);
|
|
8073
8098
|
}
|
|
8074
8099
|
}
|
|
8075
8100
|
getUnsentVisitorData(visitorCode, isConsentProvided) {
|
|
@@ -8252,16 +8277,21 @@ class KameleoonClient {
|
|
|
8252
8277
|
return result.ok;
|
|
8253
8278
|
});
|
|
8254
8279
|
}
|
|
8255
|
-
addData(
|
|
8280
|
+
addData(visitorCodeOrParams, ...dataRest) {
|
|
8256
8281
|
if (this.stubMode) {
|
|
8257
8282
|
throw new KameleoonError(exports.KameleoonException.Initialization);
|
|
8258
8283
|
}
|
|
8284
|
+
const params = typeof visitorCodeOrParams === 'string'
|
|
8285
|
+
? { visitorCode: visitorCodeOrParams, data: dataRest }
|
|
8286
|
+
: visitorCodeOrParams;
|
|
8287
|
+
const { visitorCode, data, track = true } = params;
|
|
8259
8288
|
KameleoonLogger.info `CALL: KameleoonClient.addData(visitorCode: ${visitorCode}, data: ${data})`;
|
|
8260
8289
|
this.visitorCodeManager.validateVisitorCode(visitorCode).throw();
|
|
8261
8290
|
if (!this.initialized) {
|
|
8262
8291
|
throw new KameleoonError(exports.KameleoonException.Initialization);
|
|
8263
8292
|
}
|
|
8264
|
-
|
|
8293
|
+
// assuming DataManager.storeData supports `track` (boolean) as discussed
|
|
8294
|
+
this.dataManager.storeData({ visitorCode, track, data }).throw();
|
|
8265
8295
|
KameleoonLogger.info `RETURN: KameleoonClient.addData(visitorCode: ${visitorCode}, data: ${data})`;
|
|
8266
8296
|
}
|
|
8267
8297
|
getRemoteVisitorData({ visitorCode, shouldAddData = true, filters = DEFAULT_VISITOR_DATA_FILTERS, }) {
|
|
@@ -8605,7 +8635,11 @@ class KameleoonClient {
|
|
|
8605
8635
|
return null;
|
|
8606
8636
|
}
|
|
8607
8637
|
const customData = new CustomData$1(customDataIndex, ...Object.keys(data[WAREHOUSE_AUDIENCE_KEY]));
|
|
8608
|
-
this.dataManager.storeData(
|
|
8638
|
+
this.dataManager.storeData({
|
|
8639
|
+
visitorCode,
|
|
8640
|
+
track: true,
|
|
8641
|
+
data: [customData],
|
|
8642
|
+
});
|
|
8609
8643
|
KameleoonLogger.info `RETURN: KameleoonClient.getVisitorWarehouseAudience(visitorCode: ${visitorCode}, customDataIndex: ${customDataIndex}, warehouseKey: ${warehouseKey}) -> (customData: ${customData})`;
|
|
8610
8644
|
return customData;
|
|
8611
8645
|
});
|
|
@@ -8681,7 +8715,7 @@ class KameleoonClient {
|
|
|
8681
8715
|
}
|
|
8682
8716
|
}
|
|
8683
8717
|
if (targetedSegments.length !== 0) {
|
|
8684
|
-
this.dataManager.storeData(visitorCode,
|
|
8718
|
+
this.dataManager.storeData({ visitorCode, data: targetedSegments });
|
|
8685
8719
|
}
|
|
8686
8720
|
this.flush(visitorCode);
|
|
8687
8721
|
KameleoonLogger.info `RETURN: KameleoonClient.evaluateAudiences(visitorCode: ${visitorCode})`;
|