@kameleoon/javascript-sdk-core 0.0.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/campaignConfiguration/campaignConfiguration.d.ts +46 -0
- package/dist/campaignConfiguration/campaignConfiguration.js +217 -0
- package/dist/campaignConfiguration/campaignConfiguration.js.map +1 -0
- package/dist/campaignConfiguration/constants.d.ts +18 -0
- package/dist/campaignConfiguration/constants.js +23 -0
- package/dist/campaignConfiguration/constants.js.map +1 -0
- package/dist/campaignConfiguration/index.d.ts +2 -0
- package/dist/campaignConfiguration/index.js +8 -0
- package/dist/campaignConfiguration/index.js.map +1 -0
- package/dist/campaignConfiguration/types.d.ts +126 -0
- package/dist/campaignConfiguration/types.js +47 -0
- package/dist/campaignConfiguration/types.js.map +1 -0
- package/dist/clientSettings/clientSettings.d.ts +12 -0
- package/dist/clientSettings/clientSettings.js +29 -0
- package/dist/clientSettings/clientSettings.js.map +1 -0
- package/dist/clientSettings/index.d.ts +2 -0
- package/dist/clientSettings/index.js +6 -0
- package/dist/clientSettings/index.js.map +1 -0
- package/dist/clientSettings/types.d.ts +6 -0
- package/dist/{interfaces/interfaces.js → clientSettings/types.js} +1 -1
- package/dist/clientSettings/types.js.map +1 -0
- package/dist/constants.d.ts +10 -16
- package/dist/constants.js +13 -20
- package/dist/constants.js.map +1 -1
- package/dist/eventSource/constants.d.ts +1 -0
- package/dist/eventSource/constants.js +5 -0
- package/dist/eventSource/constants.js.map +1 -0
- package/dist/eventSource/externalEventSource.d.ts +12 -0
- package/dist/eventSource/externalEventSource.js +26 -0
- package/dist/eventSource/externalEventSource.js.map +1 -0
- package/dist/eventSource/index.d.ts +3 -0
- package/dist/eventSource/index.js +8 -0
- package/dist/eventSource/index.js.map +1 -0
- package/dist/eventSource/types.d.ts +47 -0
- package/dist/eventSource/types.js +3 -0
- package/dist/eventSource/types.js.map +1 -0
- package/dist/hasher/constants.d.ts +1 -0
- package/dist/hasher/constants.js +5 -0
- package/dist/hasher/constants.js.map +1 -0
- package/dist/hasher/hasher.d.ts +6 -0
- package/dist/hasher/hasher.js +34 -0
- package/dist/hasher/hasher.js.map +1 -0
- package/dist/hasher/index.d.ts +1 -0
- package/dist/hasher/index.js +6 -0
- package/dist/hasher/index.js.map +1 -0
- package/dist/hasher/types.d.ts +12 -0
- package/dist/hasher/types.js +3 -0
- package/dist/hasher/types.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/dist/kameleoonClient.d.ts +189 -100
- package/dist/kameleoonClient.js +238 -701
- package/dist/kameleoonClient.js.map +1 -1
- package/dist/kameleoonData/browser.d.ts +21 -0
- package/dist/kameleoonData/browser.js +41 -0
- package/dist/kameleoonData/browser.js.map +1 -0
- package/dist/kameleoonData/constants.d.ts +1 -0
- package/dist/kameleoonData/constants.js +5 -0
- package/dist/kameleoonData/constants.js.map +1 -0
- package/dist/kameleoonData/conversion.d.ts +23 -0
- package/dist/kameleoonData/conversion.js +49 -0
- package/dist/kameleoonData/conversion.js.map +1 -0
- package/dist/kameleoonData/customData.d.ts +33 -0
- package/dist/kameleoonData/customData.js +68 -0
- package/dist/kameleoonData/customData.js.map +1 -0
- package/dist/kameleoonData/device.d.ts +21 -0
- package/dist/kameleoonData/device.js +41 -0
- package/dist/kameleoonData/device.js.map +1 -0
- package/dist/kameleoonData/index.d.ts +7 -0
- package/dist/kameleoonData/index.js +20 -0
- package/dist/kameleoonData/index.js.map +1 -0
- package/dist/kameleoonData/nonce.d.ts +5 -0
- package/dist/kameleoonData/nonce.js +20 -0
- package/dist/kameleoonData/nonce.js.map +1 -0
- package/dist/kameleoonData/pageView.d.ts +24 -0
- package/dist/kameleoonData/pageView.js +54 -0
- package/dist/kameleoonData/pageView.js.map +1 -0
- package/dist/kameleoonData/types.d.ts +100 -0
- package/dist/kameleoonData/types.js +36 -0
- package/dist/kameleoonData/types.js.map +1 -0
- package/dist/kameleoonData/userAgent.d.ts +18 -0
- package/dist/kameleoonData/userAgent.js +33 -0
- package/dist/kameleoonData/userAgent.js.map +1 -0
- package/dist/kameleoonError/constants.d.ts +22 -0
- package/dist/kameleoonError/constants.js +25 -0
- package/dist/kameleoonError/constants.js.map +1 -0
- package/dist/kameleoonError/helpers.d.ts +1 -0
- package/dist/kameleoonError/helpers.js +8 -0
- package/dist/kameleoonError/helpers.js.map +1 -0
- package/dist/kameleoonError/index.d.ts +3 -0
- package/dist/kameleoonError/index.js +10 -0
- package/dist/kameleoonError/index.js.map +1 -0
- package/dist/kameleoonError/kameleoonError.d.ts +24 -0
- package/dist/kameleoonError/kameleoonError.js +64 -0
- package/dist/kameleoonError/kameleoonError.js.map +1 -0
- package/dist/kameleoonError/types.d.ts +20 -0
- package/dist/kameleoonError/types.js +25 -0
- package/dist/kameleoonError/types.js.map +1 -0
- package/dist/kameleoonUtils.d.ts +11 -10
- package/dist/kameleoonUtils.js +42 -128
- package/dist/kameleoonUtils.js.map +1 -1
- package/dist/requester/constants.d.ts +15 -0
- package/dist/requester/constants.js +53 -0
- package/dist/requester/constants.js.map +1 -0
- package/dist/requester/index.d.ts +3 -0
- package/dist/requester/index.js +10 -0
- package/dist/requester/index.js.map +1 -0
- package/dist/requester/requester.d.ts +23 -0
- package/dist/requester/requester.js +121 -0
- package/dist/requester/requester.js.map +1 -0
- package/dist/requester/types.d.ts +43 -0
- package/dist/requester/types.js +39 -0
- package/dist/requester/types.js.map +1 -0
- package/dist/storage/constants.d.ts +9 -0
- package/dist/storage/constants.js +14 -0
- package/dist/storage/constants.js.map +1 -0
- package/dist/storage/externalStorage.d.ts +11 -0
- package/dist/storage/externalStorage.js +34 -0
- package/dist/storage/externalStorage.js.map +1 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.js +8 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/types.d.ts +52 -11
- package/dist/targeting/conditions/conditionFactory.d.ts +6 -0
- package/dist/targeting/conditions/conditionFactory.js +26 -0
- package/dist/targeting/conditions/conditionFactory.js.map +1 -0
- package/dist/targeting/conditions/customDataCondition.d.ts +16 -0
- package/dist/targeting/conditions/customDataCondition.js +99 -0
- package/dist/targeting/conditions/customDataCondition.js.map +1 -0
- package/dist/targeting/conditions/exclusiveExperimentCondition.d.ts +9 -0
- package/dist/targeting/conditions/exclusiveExperimentCondition.js +21 -0
- package/dist/targeting/conditions/exclusiveExperimentCondition.js.map +1 -0
- package/dist/targeting/conditions/index.d.ts +5 -0
- package/dist/targeting/conditions/index.js +12 -0
- package/dist/targeting/conditions/index.js.map +1 -0
- package/dist/targeting/conditions/targetExperimentCondition.d.ts +13 -0
- package/dist/targeting/conditions/targetExperimentCondition.js +42 -0
- package/dist/targeting/conditions/targetExperimentCondition.js.map +1 -0
- package/dist/targeting/conditions/types.d.ts +22 -11
- package/dist/targeting/index.d.ts +3 -0
- package/dist/targeting/index.js +15 -0
- package/dist/targeting/index.js.map +1 -0
- package/dist/targeting/targetingNode.d.ts +21 -0
- package/dist/targeting/targetingNode.js +40 -0
- package/dist/targeting/targetingNode.js.map +1 -0
- package/dist/targeting/targetingTree.d.ts +16 -8
- package/dist/targeting/targetingTree.js +112 -10
- package/dist/targeting/targetingTree.js.map +1 -1
- package/dist/targeting/types.d.ts +127 -0
- package/dist/targeting/types.js +93 -0
- package/dist/targeting/types.js.map +1 -0
- package/dist/types.d.ts +135 -5
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -1
- package/dist/utilities/constants.d.ts +1 -0
- package/dist/utilities/constants.js +5 -0
- package/dist/utilities/constants.js.map +1 -0
- package/dist/utilities/index.d.ts +1 -0
- package/dist/utilities/index.js +6 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/types.d.ts +18 -0
- package/dist/utilities/types.js +3 -0
- package/dist/utilities/types.js.map +1 -0
- package/dist/utilities/utilities.d.ts +13 -0
- package/dist/utilities/utilities.js +119 -0
- package/dist/utilities/utilities.js.map +1 -0
- package/dist/variationConfiguration/index.d.ts +2 -0
- package/dist/variationConfiguration/index.js +6 -0
- package/dist/variationConfiguration/index.js.map +1 -0
- package/dist/variationConfiguration/types.d.ts +25 -0
- package/dist/variationConfiguration/types.js +3 -0
- package/dist/variationConfiguration/types.js.map +1 -0
- package/dist/variationConfiguration/variation.d.ts +13 -0
- package/dist/variationConfiguration/variation.js +38 -0
- package/dist/variationConfiguration/variation.js.map +1 -0
- package/dist/variationConfiguration/variationConfiguration.d.ts +36 -0
- package/dist/variationConfiguration/variationConfiguration.js +248 -0
- package/dist/variationConfiguration/variationConfiguration.js.map +1 -0
- package/package.json +19 -9
- package/dist/configurations/configuration.d.ts +0 -15
- package/dist/configurations/configuration.js +0 -31
- package/dist/configurations/configuration.js.map +0 -1
- package/dist/configurations/experiment.d.ts +0 -13
- package/dist/configurations/experiment.js +0 -54
- package/dist/configurations/experiment.js.map +0 -1
- package/dist/configurations/featureFlag.d.ts +0 -23
- package/dist/configurations/featureFlag.js +0 -105
- package/dist/configurations/featureFlag.js.map +0 -1
- package/dist/configurations/variation.d.ts +0 -15
- package/dist/configurations/variation.js +0 -14
- package/dist/configurations/variation.js.map +0 -1
- package/dist/data.d.ts +0 -67
- package/dist/data.js +0 -127
- package/dist/data.js.map +0 -1
- package/dist/exceptions/credentialsNotFound.d.ts +0 -6
- package/dist/exceptions/credentialsNotFound.js +0 -29
- package/dist/exceptions/credentialsNotFound.js.map +0 -1
- package/dist/exceptions/experimentConfigurationNotFound.d.ts +0 -6
- package/dist/exceptions/experimentConfigurationNotFound.js +0 -29
- package/dist/exceptions/experimentConfigurationNotFound.js.map +0 -1
- package/dist/exceptions/featureConfigurationNotFound.d.ts +0 -6
- package/dist/exceptions/featureConfigurationNotFound.js +0 -29
- package/dist/exceptions/featureConfigurationNotFound.js.map +0 -1
- package/dist/exceptions/notActivated.d.ts +0 -6
- package/dist/exceptions/notActivated.js +0 -29
- package/dist/exceptions/notActivated.js.map +0 -1
- package/dist/exceptions/notTargeted.d.ts +0 -6
- package/dist/exceptions/notTargeted.js +0 -29
- package/dist/exceptions/notTargeted.js.map +0 -1
- package/dist/exceptions/siteCodeDisabled.d.ts +0 -5
- package/dist/exceptions/siteCodeDisabled.js +0 -30
- package/dist/exceptions/siteCodeDisabled.js.map +0 -1
- package/dist/exceptions/variationConfigurationNotFound.d.ts +0 -6
- package/dist/exceptions/variationConfigurationNotFound.js +0 -29
- package/dist/exceptions/variationConfigurationNotFound.js.map +0 -1
- package/dist/exceptions/visitorCodeNotValid.d.ts +0 -5
- package/dist/exceptions/visitorCodeNotValid.js +0 -30
- package/dist/exceptions/visitorCodeNotValid.js.map +0 -1
- package/dist/interfaces/interfaces.d.ts +0 -81
- package/dist/interfaces/interfaces.js.map +0 -1
- package/dist/nonce.d.ts +0 -1
- package/dist/nonce.js +0 -16
- package/dist/nonce.js.map +0 -1
- package/dist/realTimeConfigurationService.d.ts +0 -12
- package/dist/realTimeConfigurationService.js +0 -24
- package/dist/realTimeConfigurationService.js.map +0 -1
- package/dist/storage/variationStorage.d.ts +0 -11
- package/dist/storage/variationStorage.js +0 -159
- package/dist/storage/variationStorage.js.map +0 -1
- package/dist/storage/visitorVariation.d.ts +0 -9
- package/dist/storage/visitorVariation.js +0 -22
- package/dist/storage/visitorVariation.js.map +0 -1
- package/dist/targeting/conditions/customDatum.d.ts +0 -12
- package/dist/targeting/conditions/customDatum.js +0 -129
- package/dist/targeting/conditions/customDatum.js.map +0 -1
- package/dist/targeting/conditions/exclusiveExperiment.d.ts +0 -9
- package/dist/targeting/conditions/exclusiveExperiment.js +0 -45
- package/dist/targeting/conditions/exclusiveExperiment.js.map +0 -1
- package/dist/targeting/conditions/targetExperiment.d.ts +0 -14
- package/dist/targeting/conditions/targetExperiment.js +0 -57
- package/dist/targeting/conditions/targetExperiment.js.map +0 -1
- package/dist/targeting/targetingCondition.d.ts +0 -7
- package/dist/targeting/targetingCondition.js +0 -9
- package/dist/targeting/targetingCondition.js.map +0 -1
- package/dist/targeting/targetingConditionsFactory.d.ts +0 -7
- package/dist/targeting/targetingConditionsFactory.js +0 -30
- package/dist/targeting/targetingConditionsFactory.js.map +0 -1
- package/dist/targeting/targetingData.d.ts +0 -7
- package/dist/targeting/targetingData.js +0 -11
- package/dist/targeting/targetingData.js.map +0 -1
- package/dist/targeting/targetingEngine.d.ts +0 -6
- package/dist/targeting/targetingEngine.js +0 -130
- package/dist/targeting/targetingEngine.js.map +0 -1
- package/dist/targeting/targetingSegment.d.ts +0 -5
- package/dist/targeting/targetingSegment.js +0 -9
- package/dist/targeting/targetingSegment.js.map +0 -1
- package/dist/targeting/targetingTreeBuilder.d.ts +0 -8
- package/dist/targeting/targetingTreeBuilder.js +0 -127
- package/dist/targeting/targetingTreeBuilder.js.map +0 -1
package/dist/kameleoonClient.js
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -27,700 +8,256 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
27
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
9
|
});
|
|
29
10
|
};
|
|
30
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
31
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
32
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
33
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
34
|
-
function step(op) {
|
|
35
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
36
|
-
while (_) try {
|
|
37
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
38
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
39
|
-
switch (op[0]) {
|
|
40
|
-
case 0: case 1: t = op; break;
|
|
41
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
42
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
43
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
44
|
-
default:
|
|
45
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
46
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
47
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
48
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
49
|
-
if (t[2]) _.ops.pop();
|
|
50
|
-
_.trys.pop(); continue;
|
|
51
|
-
}
|
|
52
|
-
op = body.call(thisArg, _);
|
|
53
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
54
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
58
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
59
|
-
};
|
|
60
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
-
exports.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
this.
|
|
87
|
-
this.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
switch (_b.label) {
|
|
99
|
-
case 0:
|
|
100
|
-
if (!(typeof document !== 'undefined')) return [3 /*break*/, 1];
|
|
101
|
-
data = localStorage.getItem('kameleoonJavaScriptClientData');
|
|
102
|
-
return [3 /*break*/, 3];
|
|
103
|
-
case 1:
|
|
104
|
-
if (!(typeof navigator !== 'undefined' &&
|
|
105
|
-
navigator.product === 'ReactNative')) return [3 /*break*/, 3];
|
|
106
|
-
return [4 /*yield*/, async_storage_1.default.getItem('kameleoonJavaScriptClientData')];
|
|
107
|
-
case 2:
|
|
108
|
-
data = _b.sent();
|
|
109
|
-
_b.label = 3;
|
|
110
|
-
case 3:
|
|
111
|
-
if (data) {
|
|
112
|
-
try {
|
|
113
|
-
data = JSON.parse(data);
|
|
114
|
-
}
|
|
115
|
-
catch (e) {
|
|
116
|
-
console.log(e);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (!data) {
|
|
120
|
-
data = {
|
|
121
|
-
kameleoonTargetingData: {},
|
|
122
|
-
kameleoonConfiguration: {},
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
savedTargetingData = data.kameleoonTargetingData;
|
|
126
|
-
if (savedTargetingData) {
|
|
127
|
-
try {
|
|
128
|
-
this.targetingData = savedTargetingData;
|
|
129
|
-
this.emptyTargetingData();
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
this.targetingData = {};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
savedConfiguration = data.kameleoonConfiguration;
|
|
136
|
-
needUpdate = false;
|
|
137
|
-
if (!savedConfiguration || timeStamp != null) {
|
|
138
|
-
// timeStamp != null means update by SSE event and requires force update
|
|
139
|
-
needUpdate = true;
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
try {
|
|
143
|
-
parsedConfiguration = new configuration_1.default(this.siteCode, {
|
|
144
|
-
configuration: savedConfiguration.configuration,
|
|
145
|
-
experiments: savedConfiguration.experiments,
|
|
146
|
-
featureFlags: savedConfiguration.featureFlags,
|
|
147
|
-
updateTime: savedConfiguration.updateTime,
|
|
148
|
-
});
|
|
149
|
-
if (parsedConfiguration.updateTime <
|
|
150
|
-
new Date().getTime() -
|
|
151
|
-
this.minutesBetweenConfigurationUpdate * 1000 * 60 || //refresh by polling interval
|
|
152
|
-
parsedConfiguration.settings.realTimeUpdate) {
|
|
153
|
-
//streaming initial refresh, need to update to recent version of configuration
|
|
154
|
-
needUpdate = true;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
this.configurations = parsedConfiguration;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch (e) {
|
|
161
|
-
needUpdate = true;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (needUpdate) {
|
|
165
|
-
siteCodeStringUrl = "mobile?siteCode=".concat(this.siteCode);
|
|
166
|
-
environmentStringUrl = ((_a = this.environment) === null || _a === void 0 ? void 0 : _a.length)
|
|
167
|
-
? "&environment=".concat(this.environment)
|
|
168
|
-
: '';
|
|
169
|
-
timeStampStringUrl = timeStamp ? "&ts=".concat(timeStamp) : '';
|
|
170
|
-
configurationUrl = constants_1.CONFIGURATION_URL +
|
|
171
|
-
siteCodeStringUrl +
|
|
172
|
-
environmentStringUrl +
|
|
173
|
-
timeStampStringUrl;
|
|
174
|
-
kameleoonUtils_1.default.doRequest(configurationUrl, kameleoonUtils_1.HttpMethod.GET, null, function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
175
|
-
return __generator(this, function (_a) {
|
|
176
|
-
try {
|
|
177
|
-
this.configurations = new configuration_1.default(this.siteCode, JSON.parse(response));
|
|
178
|
-
this.ready = true;
|
|
179
|
-
this.clearCallbacks(true);
|
|
180
|
-
this.saveConfiguration();
|
|
181
|
-
this.fireUpdateConfigurationHandler(Boolean(timeStamp)); //fire handler after configuration was updated with SSE event
|
|
182
|
-
this.manageConfiguraitonUpdate(this.configurations.settings.realTimeUpdate);
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
console.log(e);
|
|
186
|
-
}
|
|
187
|
-
return [2 /*return*/];
|
|
188
|
-
});
|
|
189
|
-
}); }, false);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
this.ready = true;
|
|
193
|
-
this.clearCallbacks(true);
|
|
194
|
-
}
|
|
195
|
-
return [2 /*return*/];
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}); };
|
|
199
|
-
this.runWhenReady = function (successCallback, errorCallback, timeout) {
|
|
200
|
-
if (_this.ready) {
|
|
201
|
-
successCallback && successCallback();
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
_this.readyCallbacks.push({
|
|
205
|
-
error: errorCallback,
|
|
206
|
-
success: successCallback,
|
|
207
|
-
timeout: setTimeout(function () {
|
|
208
|
-
_this.clearCallbacks(false, errorCallback);
|
|
209
|
-
}, timeout),
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
this.clearCallbacks = function (success, errorCallback) {
|
|
214
|
-
var callbacksToKeep = [];
|
|
215
|
-
_this.readyCallbacks.forEach(function (c) {
|
|
216
|
-
if (success) {
|
|
217
|
-
c.success && c.success();
|
|
218
|
-
clearTimeout(c.timeout);
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
if (!success && errorCallback == c.error) {
|
|
222
|
-
c.error && c.error();
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
callbacksToKeep.push(c);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
_this.readyCallbacks = callbacksToKeep;
|
|
230
|
-
};
|
|
231
|
-
this.trackConversion = function (visitorCode, goalId, revenue) {
|
|
232
|
-
_this.validateVisitorCode(visitorCode);
|
|
233
|
-
_this.addData(visitorCode, new data_1.default.Conversion(goalId, revenue, false));
|
|
234
|
-
_this.flush(visitorCode);
|
|
235
|
-
};
|
|
236
|
-
this.flush = function (visitorCode) {
|
|
237
|
-
if (visitorCode != null) {
|
|
238
|
-
var body = _this.getAndClearUnsentData(visitorCode);
|
|
239
|
-
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL + _this.getDataTrackingURL(visitorCode), kameleoonUtils_1.HttpMethod.POST, body, null);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
_this.getUnsentUsers().forEach(function (vc) { return _this.flush(vc); });
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
this.triggerExperiment = function (visitorCode, experimentId) {
|
|
246
|
-
var _a;
|
|
247
|
-
_this.validateVisitorCode(visitorCode);
|
|
248
|
-
var xpConf = (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.experiments[experimentId];
|
|
249
|
-
_this.checkSiteEnabled(xpConf);
|
|
250
|
-
if (_this.checkTargeting(visitorCode, experimentId, false)) {
|
|
251
|
-
var variationId = 0;
|
|
252
|
-
var noneVariation = true;
|
|
253
|
-
var savedVariationId = _this.variationStorage.getVariationId(visitorCode, experimentId);
|
|
254
|
-
if (savedVariationId) {
|
|
255
|
-
variationId = savedVariationId;
|
|
256
|
-
noneVariation = false;
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
if (xpConf) {
|
|
260
|
-
var hashDouble = _this.obtainHashDouble(experimentId, visitorCode, xpConf);
|
|
261
|
-
var total = 0.0;
|
|
262
|
-
for (var key in xpConf.variationConfigurations) {
|
|
263
|
-
var variationConfiguration = xpConf.variationConfigurations[key];
|
|
264
|
-
total += variationConfiguration.deviation;
|
|
265
|
-
if (total >= hashDouble) {
|
|
266
|
-
noneVariation = false;
|
|
267
|
-
variationId = parseInt(key);
|
|
268
|
-
_this.variationStorage.updateVariation(visitorCode, experimentId, variationConfiguration);
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
var body = _this.getAndClearUnsentData(visitorCode);
|
|
273
|
-
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL +
|
|
274
|
-
_this.getExperimentRegisterURL(visitorCode, experimentId, variationId, noneVariation), kameleoonUtils_1.HttpMethod.POST, body);
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
throw new experimentConfigurationNotFound_1.default('KameleoonException.ExperimentConfigurationNotFound');
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
if (noneVariation) {
|
|
281
|
-
throw new notActivated_1.default('KameleoonException.NotActivated');
|
|
282
|
-
}
|
|
283
|
-
return variationId;
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
throw new notTargeted_1.default('KameleoonException.NotTargeted');
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
this.activateFeature = function (visitorCode, featureIdOrName) {
|
|
290
|
-
var _a, _b;
|
|
291
|
-
_this.checkFeatureKeyOrId(featureIdOrName);
|
|
292
|
-
_this.validateVisitorCode(visitorCode);
|
|
293
|
-
var featureFlag = null;
|
|
294
|
-
var featureId = -1;
|
|
295
|
-
for (var key in (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags) {
|
|
296
|
-
var ff = (_b = _this.configurations) === null || _b === void 0 ? void 0 : _b.featureFlags[key];
|
|
297
|
-
if (key == featureIdOrName || (ff === null || ff === void 0 ? void 0 : ff.identificationKey) == featureIdOrName) {
|
|
298
|
-
featureId = parseInt(key);
|
|
299
|
-
featureFlag = ff;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
_this.checkSiteEnabled(featureFlag);
|
|
303
|
-
if (_this.checkTargeting(visitorCode, featureId, true)) {
|
|
304
|
-
if (featureFlag && featureId) {
|
|
305
|
-
var result = false;
|
|
306
|
-
if (featureFlag.isScheduleActive()) {
|
|
307
|
-
var hashDouble = _this.obtainHashDouble(featureId, visitorCode, featureFlag);
|
|
308
|
-
var total = 0.0;
|
|
309
|
-
var variationId = 0;
|
|
310
|
-
var noneVariation = true;
|
|
311
|
-
for (var key in featureFlag.variationConfigurations) {
|
|
312
|
-
var variationConfiguration = featureFlag.variationConfigurations[key];
|
|
313
|
-
total += variationConfiguration.deviation;
|
|
314
|
-
if (total >= hashDouble) {
|
|
315
|
-
noneVariation = false;
|
|
316
|
-
variationId = parseInt(key);
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
var body = _this.getAndClearUnsentData(visitorCode);
|
|
321
|
-
kameleoonUtils_1.default.doRequest(constants_1.API_SSX_URL +
|
|
322
|
-
_this.getExperimentRegisterURL(visitorCode, featureId, variationId, noneVariation), kameleoonUtils_1.HttpMethod.POST, body);
|
|
323
|
-
result = variationId != 0;
|
|
324
|
-
}
|
|
325
|
-
return result;
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
throw new featureConfigurationNotFound_1.default('KameleoonException.FeatureConfigurationNotFound');
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
else {
|
|
332
|
-
throw new notTargeted_1.default('KameleoonException.NotTargeted');
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
this.generateRandomString = function () {
|
|
336
|
-
var alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
337
|
-
var alphabetLength = alphabet.length;
|
|
338
|
-
var randomVisitorCode = '';
|
|
339
|
-
for (var i = 0; i < 16; ++i) {
|
|
340
|
-
var randomNumber = Math.floor(Math.random() * alphabetLength);
|
|
341
|
-
randomVisitorCode += alphabet[randomNumber];
|
|
342
|
-
}
|
|
343
|
-
return randomVisitorCode;
|
|
344
|
-
};
|
|
345
|
-
this.obtainAsyncVisitorCode = function (domain, defaultVisitorCode) { return __awaiter(_this, void 0, void 0, function () {
|
|
346
|
-
var savedVisitorCode;
|
|
347
|
-
return __generator(this, function (_a) {
|
|
348
|
-
switch (_a.label) {
|
|
349
|
-
case 0:
|
|
350
|
-
savedVisitorCode = null;
|
|
351
|
-
return [4 /*yield*/, async_storage_1.default.getItem('kameleoonVisitorCode')];
|
|
352
|
-
case 1:
|
|
353
|
-
savedVisitorCode = _a.sent();
|
|
354
|
-
if (!(savedVisitorCode == null)) return [3 /*break*/, 3];
|
|
355
|
-
savedVisitorCode = defaultVisitorCode || this.generateRandomString();
|
|
356
|
-
return [4 /*yield*/, async_storage_1.default.setItem('kameleoonVisitorCode', savedVisitorCode)];
|
|
357
|
-
case 2:
|
|
358
|
-
_a.sent();
|
|
359
|
-
_a.label = 3;
|
|
360
|
-
case 3: return [2 /*return*/, savedVisitorCode];
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
}); };
|
|
364
|
-
this.obtainVisitorCode = function (domain, defaultVisitorCode) {
|
|
365
|
-
var value;
|
|
366
|
-
var name = 'kameleoonVisitorCode';
|
|
367
|
-
var cookies = document.cookie.split(';');
|
|
368
|
-
for (var i = 0, cookiesLength = cookies.length; i < cookiesLength; ++i) {
|
|
369
|
-
var cookie = cookies[i];
|
|
370
|
-
var valuePos = cookie.indexOf('=');
|
|
371
|
-
if (cookie.substring(0, valuePos).trim() == name) {
|
|
372
|
-
value = cookie.substring(valuePos + 1);
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
if (value) {
|
|
377
|
-
return value;
|
|
378
|
-
}
|
|
379
|
-
value = defaultVisitorCode || _this.generateRandomString();
|
|
380
|
-
document.cookie =
|
|
381
|
-
'kameleoonVisitorCode=' +
|
|
382
|
-
value +
|
|
383
|
-
'; Max-Age=32832000; Path=/; Domain=' +
|
|
384
|
-
domain;
|
|
385
|
-
return value;
|
|
386
|
-
};
|
|
387
|
-
this.obtainHashDouble = function (containerId, visitorCode, xpConf) {
|
|
388
|
-
var joinedRespoolTime = '';
|
|
389
|
-
for (var variationId in xpConf.variationConfigurations) {
|
|
390
|
-
var variation = xpConf.variationConfigurations[variationId];
|
|
391
|
-
if (variation.respoolTime && variation.respoolTime != 0) {
|
|
392
|
-
joinedRespoolTime += variation.respoolTime;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
var identifier = visitorCode + containerId + joinedRespoolTime;
|
|
396
|
-
var buff = kameleoonUtils_1.default.computeStringSha256(identifier);
|
|
397
|
-
return parseInt(buff, 16) / Math.pow(2, 256);
|
|
398
|
-
};
|
|
399
|
-
this.getCommonSSXParameters = function (visitorCode) {
|
|
400
|
-
return ('&nonce=' +
|
|
401
|
-
(0, nonce_1.obtainNonce)() +
|
|
402
|
-
'&siteCode=' +
|
|
403
|
-
_this.siteCode +
|
|
404
|
-
'&visitorCode=' +
|
|
405
|
-
visitorCode);
|
|
406
|
-
};
|
|
407
|
-
this.getDataTrackingURL = function (visitorCode) {
|
|
408
|
-
return 'dataTracking?' + _this.getCommonSSXParameters(visitorCode);
|
|
409
|
-
};
|
|
410
|
-
this.getAPIDataRequestURL = function (key) {
|
|
411
|
-
return "".concat(constants_1.API_DATA_URL, "data?siteCode=").concat(_this.siteCode, "&key=").concat(key);
|
|
412
|
-
};
|
|
413
|
-
this.getEventsRequestURL = function (siteCode) {
|
|
414
|
-
return "".concat(constants_1.EVENTS_URL, "sse?siteCode=").concat(siteCode);
|
|
415
|
-
};
|
|
416
|
-
this.getExperimentRegisterURL = function (visitorCode, experimentId, variationId, noneVariation) {
|
|
417
|
-
var baseURL = 'experimentTracking?' +
|
|
418
|
-
_this.getCommonSSXParameters(visitorCode) +
|
|
419
|
-
'&experimentId=' +
|
|
420
|
-
experimentId;
|
|
421
|
-
if (variationId == null) {
|
|
422
|
-
return baseURL;
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
return (baseURL +
|
|
426
|
-
'&variationId=' +
|
|
427
|
-
variationId +
|
|
428
|
-
(noneVariation ? '&noneVariation=true' : ''));
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
this.getUnsentUsers = function () {
|
|
432
|
-
return Object.getOwnPropertyNames(_this.unsentData);
|
|
433
|
-
};
|
|
434
|
-
this.getUnsentData = function (visitorCode) {
|
|
435
|
-
if (!_this.unsentData[visitorCode]) {
|
|
436
|
-
_this.unsentData[visitorCode] = [];
|
|
437
|
-
}
|
|
438
|
-
return _this.unsentData[visitorCode];
|
|
439
|
-
};
|
|
440
|
-
this.getTargetingData = function (visitorCode) {
|
|
441
|
-
if (_this.targetingData[visitorCode] == null) {
|
|
442
|
-
_this.targetingData[visitorCode] = [];
|
|
443
|
-
}
|
|
444
|
-
return _this.targetingData[visitorCode];
|
|
445
|
-
};
|
|
446
|
-
this.emptyUnsentData = function (visitorCode) {
|
|
447
|
-
delete _this.unsentData[visitorCode];
|
|
448
|
-
};
|
|
449
|
-
this.emptyTargetingData = function () {
|
|
450
|
-
var currentTime = new Date().getTime();
|
|
451
|
-
for (var visitorCode in _this.targetingData) {
|
|
452
|
-
_this.targetingData[visitorCode] = _this.targetingData[visitorCode].reduce(function (arr, data) {
|
|
453
|
-
if (data.lastActivityTime + constants_1.MINUTES_SESSION_DURATION > currentTime) {
|
|
454
|
-
arr.push(data);
|
|
455
|
-
}
|
|
456
|
-
return arr;
|
|
457
|
-
}, []);
|
|
458
|
-
}
|
|
459
|
-
_this.saveConfiguration();
|
|
460
|
-
};
|
|
461
|
-
this.addData = function (visitorCode) {
|
|
462
|
-
var data = [];
|
|
463
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
464
|
-
data[_i - 1] = arguments[_i];
|
|
465
|
-
}
|
|
466
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
467
|
-
var listData, targetingDataList;
|
|
468
|
-
var _this = this;
|
|
469
|
-
return __generator(this, function (_a) {
|
|
470
|
-
this.validateVisitorCode(visitorCode);
|
|
471
|
-
listData = this.getUnsentData(visitorCode);
|
|
472
|
-
targetingDataList = this.getTargetingData(visitorCode);
|
|
473
|
-
data.forEach(function (d) { return __awaiter(_this, void 0, void 0, function () {
|
|
474
|
-
return __generator(this, function (_a) {
|
|
475
|
-
switch (_a.label) {
|
|
476
|
-
case 0:
|
|
477
|
-
listData.push(d);
|
|
478
|
-
if (targetingDataList.length < this.targetingDataNumberEntriesAuthorized) {
|
|
479
|
-
targetingDataList.push(new targetingData_1.default(new Date().getTime(), d));
|
|
480
|
-
}
|
|
481
|
-
else {
|
|
482
|
-
targetingDataList.splice(0, 1);
|
|
483
|
-
targetingDataList.push(new targetingData_1.default(new Date().getTime(), d));
|
|
484
|
-
}
|
|
485
|
-
return [4 /*yield*/, this.saveConfiguration()];
|
|
486
|
-
case 1:
|
|
487
|
-
_a.sent();
|
|
488
|
-
return [2 /*return*/];
|
|
489
|
-
}
|
|
490
|
-
});
|
|
491
|
-
}); });
|
|
492
|
-
return [2 /*return*/];
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
};
|
|
496
|
-
// Targeting Engine
|
|
497
|
-
// check targeting
|
|
498
|
-
this.checkTargeting = function (visitorCode, campaignId, isFF) {
|
|
499
|
-
var _a, _b;
|
|
500
|
-
var targeting = true;
|
|
501
|
-
var xpConf = null;
|
|
502
|
-
// performing targeting
|
|
503
|
-
if (isFF) {
|
|
504
|
-
xpConf = (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags[campaignId];
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
xpConf = (_b = _this.configurations) === null || _b === void 0 ? void 0 : _b.experiments[campaignId];
|
|
508
|
-
}
|
|
509
|
-
if (xpConf != null) {
|
|
510
|
-
if (true == xpConf.forceTargeting) {
|
|
511
|
-
// assigning targeting to container
|
|
512
|
-
targeting = true;
|
|
513
|
-
}
|
|
514
|
-
else {
|
|
515
|
-
var targetingTree = void 0;
|
|
516
|
-
if (null != xpConf.targetingSegment) {
|
|
517
|
-
targetingTree = xpConf.targetingSegment.targetingTree;
|
|
518
|
-
}
|
|
519
|
-
// obtaining targeting checking result and assigning targeting to container
|
|
520
|
-
targeting = targetingEngine_1.TargetingEngine.checkTargetingTree(targetingTree, function (type) {
|
|
521
|
-
return _this.getConditionData(type, visitorCode, campaignId);
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
return targeting;
|
|
526
|
-
};
|
|
527
|
-
this.getConditionData = function (type, visitorCode, campaignId) {
|
|
528
|
-
switch (type) {
|
|
529
|
-
case constants_1.ConditionTypes.CUSTOM_DATUM:
|
|
530
|
-
return {
|
|
531
|
-
targetingData: _this.getTargetingData(visitorCode),
|
|
532
|
-
};
|
|
533
|
-
case constants_1.ConditionTypes.EXCLUSIVE_EXPERIMENT:
|
|
534
|
-
return {
|
|
535
|
-
currentExperimentId: campaignId,
|
|
536
|
-
variationStorage: _this.variationStorage.getMapVariationId(visitorCode),
|
|
537
|
-
};
|
|
538
|
-
case constants_1.ConditionTypes.TARGET_EXPERIMENT:
|
|
539
|
-
return {
|
|
540
|
-
variationStorage: _this.variationStorage.getMapVariationId(visitorCode),
|
|
541
|
-
};
|
|
542
|
-
default:
|
|
543
|
-
return null;
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
this.obtainVariationAssociatedData = function (variationId) {
|
|
547
|
-
var _a, _b, _c;
|
|
548
|
-
for (var vid in (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.experiments) {
|
|
549
|
-
var experiment = (_b = _this.configurations) === null || _b === void 0 ? void 0 : _b.experiments[vid];
|
|
550
|
-
if (experiment === null || experiment === void 0 ? void 0 : experiment.variationConfigurations[variationId]) {
|
|
551
|
-
return ((_c = experiment === null || experiment === void 0 ? void 0 : experiment.variationConfigurations[variationId].customJson) !== null && _c !== void 0 ? _c : {});
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
throw new variationConfigurationNotFound_1.default('KameleoonException.VariationConfigurationNotFound');
|
|
555
|
-
};
|
|
556
|
-
this.obtainFeatureVariable = function (featureIdOrName, variable) {
|
|
557
|
-
var _a, _b, _c, _d;
|
|
558
|
-
_this.checkFeatureKeyOrId(featureIdOrName);
|
|
559
|
-
for (var ffid in (_a = _this.configurations) === null || _a === void 0 ? void 0 : _a.featureFlags) {
|
|
560
|
-
var ff = (_b = _this.configurations) === null || _b === void 0 ? void 0 : _b.featureFlags[ffid];
|
|
561
|
-
if (ffid == featureIdOrName ||
|
|
562
|
-
(ff === null || ff === void 0 ? void 0 : ff.identificationKey) === featureIdOrName) {
|
|
563
|
-
for (var vid in ff === null || ff === void 0 ? void 0 : ff.variationConfigurations) {
|
|
564
|
-
if (vid !== '0') {
|
|
565
|
-
return _this._parseJsonValue((_d = (_c = ff === null || ff === void 0 ? void 0 : ff.variationConfigurations[vid]) === null || _c === void 0 ? void 0 : _c.customJson) === null || _d === void 0 ? void 0 : _d[variable]);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
throw new featureConfigurationNotFound_1.default('KameleoonExceptinpmon.FeatureConfigurationNotFound');
|
|
571
|
-
};
|
|
572
|
-
this.retrieveDataFromRemoteSource = function (key) { return __awaiter(_this, void 0, void 0, function () {
|
|
573
|
-
var _this = this;
|
|
574
|
-
return __generator(this, function (_a) {
|
|
575
|
-
return [2 /*return*/, new Promise(function (resolve) {
|
|
576
|
-
kameleoonUtils_1.default.doRequest(_this.getAPIDataRequestURL(key), kameleoonUtils_1.HttpMethod.GET, null, function (response) {
|
|
577
|
-
resolve(JSON.parse(response));
|
|
578
|
-
});
|
|
579
|
-
})];
|
|
12
|
+
exports.KameleoonClient = void 0;
|
|
13
|
+
const ts_res_1 = require("ts-res");
|
|
14
|
+
const campaignConfiguration_1 = require("./campaignConfiguration");
|
|
15
|
+
const clientSettings_1 = require("./clientSettings");
|
|
16
|
+
const constants_1 = require("./constants");
|
|
17
|
+
const kameleoonData_1 = require("./kameleoonData");
|
|
18
|
+
const kameleoonError_1 = require("./kameleoonError");
|
|
19
|
+
const requester_1 = require("./requester");
|
|
20
|
+
const storage_1 = require("./storage");
|
|
21
|
+
const externalStorage_1 = require("./storage/externalStorage");
|
|
22
|
+
const utilities_1 = require("./utilities");
|
|
23
|
+
const variationConfiguration_1 = require("./variationConfiguration");
|
|
24
|
+
/**
|
|
25
|
+
* @class
|
|
26
|
+
* KameleoonClient - a class for creating kameleoon client instance
|
|
27
|
+
* for communicating with Kameleoon JavaScript SDK Core, when new instance is created
|
|
28
|
+
* */
|
|
29
|
+
class KameleoonClient {
|
|
30
|
+
/**
|
|
31
|
+
* @param {SDKCoreParameters} sdkCoreParameters - parameters for initializing sdk core
|
|
32
|
+
*/
|
|
33
|
+
constructor({ siteCode, configuration, internalConfiguration, }) {
|
|
34
|
+
const { settings: clientSettings } = new clientSettings_1.ClientSettings(siteCode, configuration);
|
|
35
|
+
const requester = new requester_1.Requester(siteCode, clientSettings.environment);
|
|
36
|
+
this.requester = requester;
|
|
37
|
+
this.settings = clientSettings;
|
|
38
|
+
this.internalConfiguration = internalConfiguration;
|
|
39
|
+
}
|
|
40
|
+
initialize() {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const { externalStorage, externalEventSource } = this.internalConfiguration;
|
|
43
|
+
const clientDataStorage = new externalStorage_1.ExternalStorage(externalStorage.initialize(storage_1.KameleoonStorageKey.ClientData));
|
|
44
|
+
const variationDataStorage = new externalStorage_1.ExternalStorage(externalStorage.initialize(storage_1.KameleoonStorageKey.VariationData));
|
|
45
|
+
const campaignConfiguration = new campaignConfiguration_1.CampaignConfiguration({
|
|
46
|
+
settings: this.settings,
|
|
47
|
+
storage: clientDataStorage,
|
|
48
|
+
requester: this.requester,
|
|
580
49
|
});
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
50
|
+
const result = yield campaignConfiguration.initialize(externalEventSource);
|
|
51
|
+
result.throw();
|
|
52
|
+
const variationConfiguration = new variationConfiguration_1.VariationConfiguration(campaignConfiguration.experiments, variationDataStorage);
|
|
53
|
+
this.variationConfiguration = variationConfiguration;
|
|
54
|
+
this.campaignConfiguration = campaignConfiguration;
|
|
55
|
+
return result.ok;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
addData(visitorCode, ...data) {
|
|
59
|
+
utilities_1.Utilities.validateVisitorCode(visitorCode).throw();
|
|
60
|
+
if (!this.campaignConfiguration) {
|
|
61
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
62
|
+
}
|
|
63
|
+
this.campaignConfiguration.addTargetingData(visitorCode, ...data).throw();
|
|
64
|
+
}
|
|
65
|
+
triggerExperiment(visitorCode, experimentId) {
|
|
66
|
+
utilities_1.Utilities.validateVisitorCode(visitorCode).throw();
|
|
67
|
+
if (!this.campaignConfiguration || !this.variationConfiguration) {
|
|
68
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
69
|
+
}
|
|
70
|
+
const experiment = this.campaignConfiguration.experiments.find((item) => item.id === String(experimentId));
|
|
71
|
+
if (!experiment) {
|
|
72
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.ExperimentConfigurationNotFound, experimentId, visitorCode);
|
|
73
|
+
}
|
|
74
|
+
const targetingData = this.campaignConfiguration.storedTargetingData[visitorCode];
|
|
75
|
+
const targetingResult = utilities_1.Utilities.checkTargeting({
|
|
76
|
+
visitorCode,
|
|
77
|
+
experimentId,
|
|
78
|
+
targetingData,
|
|
79
|
+
segment: experiment.segment,
|
|
80
|
+
variationConfiguration: this.variationConfiguration,
|
|
81
|
+
}).throw();
|
|
82
|
+
if (!targetingResult) {
|
|
83
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.NotTargeted, visitorCode);
|
|
84
|
+
}
|
|
85
|
+
const dataUrl = utilities_1.Utilities.getDataUrl(visitorCode, this.campaignConfiguration);
|
|
86
|
+
const trackingParameters = {
|
|
87
|
+
body: dataUrl,
|
|
88
|
+
visitorCode,
|
|
89
|
+
experimentId,
|
|
596
90
|
};
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
91
|
+
const userAgent = utilities_1.Utilities.getUserAgent(visitorCode, this.campaignConfiguration);
|
|
92
|
+
const variationId = this.variationConfiguration
|
|
93
|
+
.getAssociatedVariationId(visitorCode, experimentId)
|
|
94
|
+
.else((error) => {
|
|
95
|
+
if (error.type === kameleoonError_1.KameleoonException.NotAllocated) {
|
|
96
|
+
this.requester.trackExperiment(Object.assign({ variationId: constants_1.UNALLOCATED_VARIATION_ID, isUnallocated: true, userAgent }, trackingParameters));
|
|
97
|
+
return constants_1.UNALLOCATED_VARIATION_ID;
|
|
98
|
+
}
|
|
99
|
+
throw error;
|
|
100
|
+
});
|
|
101
|
+
this.requester.trackExperiment(Object.assign({ variationId, isUnallocated: false, userAgent }, trackingParameters));
|
|
102
|
+
return variationId;
|
|
103
|
+
}
|
|
104
|
+
trackConversion({ visitorCode, goalId, revenue, }) {
|
|
105
|
+
this.addData(visitorCode, new kameleoonData_1.Conversion({ goalId, revenue }));
|
|
106
|
+
this.flushData(visitorCode);
|
|
107
|
+
}
|
|
108
|
+
flushData(visitorCode) {
|
|
109
|
+
if (!this.campaignConfiguration) {
|
|
110
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
111
|
+
}
|
|
112
|
+
const dataUrl = utilities_1.Utilities.getDataUrl(visitorCode, this.campaignConfiguration);
|
|
113
|
+
const userAgent = utilities_1.Utilities.getUserAgent(visitorCode, this.campaignConfiguration);
|
|
114
|
+
this.requester.trackData({ visitorCode, body: dataUrl, userAgent });
|
|
115
|
+
}
|
|
116
|
+
getExperiments() {
|
|
117
|
+
if (!this.campaignConfiguration) {
|
|
118
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
119
|
+
}
|
|
120
|
+
return this.campaignConfiguration.experiments.map(({ id, name }) => ({
|
|
121
|
+
id: Number(id),
|
|
122
|
+
name,
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
getVisitorExperiments(visitorCode, isActive = true) {
|
|
126
|
+
if (!this.variationConfiguration || !this.campaignConfiguration) {
|
|
127
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
128
|
+
}
|
|
129
|
+
utilities_1.Utilities.validateVisitorCode(visitorCode).throw();
|
|
130
|
+
const experiments = this.campaignConfiguration.experiments;
|
|
131
|
+
const result = [];
|
|
132
|
+
const targetingData = this.campaignConfiguration.storedTargetingData[visitorCode];
|
|
133
|
+
for (const experiment of experiments) {
|
|
134
|
+
const { id, name, segment } = experiment;
|
|
135
|
+
const targetingResult = utilities_1.Utilities.checkTargeting({
|
|
136
|
+
targetingData,
|
|
137
|
+
visitorCode,
|
|
138
|
+
segment,
|
|
139
|
+
variationConfiguration: this.variationConfiguration,
|
|
140
|
+
experimentId: Number(id),
|
|
141
|
+
}).throw();
|
|
142
|
+
if (!targetingResult) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
// -- If `isActive=false` then return every experiment
|
|
146
|
+
if (!isActive) {
|
|
147
|
+
result.push({ id: Number(id), name });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
// -- Else first check if there are saved variations for the experiment
|
|
151
|
+
// if there is at least one than it's active
|
|
152
|
+
const experimentVariations = this.variationConfiguration.getAssignedVariations(visitorCode);
|
|
153
|
+
if (experimentVariations.ok) {
|
|
154
|
+
const experimentVariation = experimentVariations.data[experiment.id];
|
|
155
|
+
if (experimentVariation) {
|
|
156
|
+
result.push({ id: Number(id), name });
|
|
157
|
+
continue;
|
|
632
158
|
}
|
|
633
|
-
});
|
|
634
|
-
}); };
|
|
635
|
-
this.validateVisitorCode = function (visitorCode) {
|
|
636
|
-
if (visitorCode == null || visitorCode.length == 0) {
|
|
637
|
-
throw new visitorCodeNotValid_1.VisitorCodeNotValid('Visitor code is empty');
|
|
638
159
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
};
|
|
645
|
-
this.onUpdateConfiguration = function (handler) {
|
|
646
|
-
_this.handlerUpdateConfiguration = handler;
|
|
647
|
-
};
|
|
648
|
-
this.siteCode = siteCode;
|
|
649
|
-
if (configuration) {
|
|
650
|
-
if (configuration.visitor_data_maximum_size) {
|
|
651
|
-
this.visitorDataMaximumSize = configuration.visitor_data_maximum_size;
|
|
652
|
-
}
|
|
653
|
-
if (configuration.actions_configuration_refresh_interval) {
|
|
654
|
-
this.minutesBetweenConfigurationUpdate =
|
|
655
|
-
configuration.actions_configuration_refresh_interval;
|
|
656
|
-
}
|
|
657
|
-
if (configuration.environment) {
|
|
658
|
-
this.environment = configuration.environment;
|
|
160
|
+
// -- Second check if the experiment will have an allocated variation upon triggering
|
|
161
|
+
// if yes than it's active
|
|
162
|
+
const variationResult = this.variationConfiguration.getExperimentVariation(visitorCode, experiment);
|
|
163
|
+
if (variationResult.ok) {
|
|
164
|
+
result.push({ id: Number(id), name });
|
|
659
165
|
}
|
|
660
166
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
this.
|
|
665
|
-
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
getFeatureFlags() {
|
|
170
|
+
if (!this.campaignConfiguration) {
|
|
171
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
172
|
+
}
|
|
173
|
+
return this.campaignConfiguration.featureFlags.map(({ id, featureKey }) => ({ id, key: featureKey }));
|
|
666
174
|
}
|
|
667
|
-
|
|
668
|
-
if (
|
|
669
|
-
|
|
670
|
-
throw new siteCodeDisabled_1.SiteCodeDisabled(this.siteCode);
|
|
175
|
+
getVisitorFeatureFlags(visitorCode) {
|
|
176
|
+
if (!this.variationConfiguration || !this.campaignConfiguration) {
|
|
177
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
671
178
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
179
|
+
const featureFlags = this.campaignConfiguration.featureFlags;
|
|
180
|
+
const resultFeatureFlags = [];
|
|
181
|
+
for (const featureFlag of featureFlags) {
|
|
182
|
+
const variationData = this.variationConfiguration
|
|
183
|
+
.getFeatureFlagVariation({
|
|
184
|
+
visitorCode,
|
|
185
|
+
featureFlag,
|
|
186
|
+
})
|
|
187
|
+
.throw();
|
|
188
|
+
if (variationData.variationKey !== constants_1.OFF_VARIATION_KEY) {
|
|
189
|
+
const { featureFlagId, featureKey } = variationData;
|
|
190
|
+
resultFeatureFlags.push({ id: featureFlagId, key: featureKey });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return resultFeatureFlags;
|
|
194
|
+
}
|
|
195
|
+
getFeatureFlagVariationKey(visitorCode, featureKey) {
|
|
196
|
+
const { variationKey } = this._getFeatureFlagVariation(visitorCode, featureKey).throw();
|
|
197
|
+
return variationKey;
|
|
198
|
+
}
|
|
199
|
+
getFeatureFlagVariable({ visitorCode, featureKey, variableKey, }) {
|
|
200
|
+
var _a, _b;
|
|
201
|
+
const { variationKey } = this._getFeatureFlagVariation(visitorCode, featureKey).throw();
|
|
202
|
+
// --- Note ---
|
|
203
|
+
// `_getFeatureFlagVariation` already checks `campaignConfiguration` initialization
|
|
204
|
+
const featureFlags = this.campaignConfiguration
|
|
205
|
+
.featureFlags;
|
|
206
|
+
const variable = (_b = (_a = featureFlags
|
|
207
|
+
.find((item) => item.featureKey === featureKey)) === null || _a === void 0 ? void 0 : _a.variations.find((item) => item.key === variationKey)) === null || _b === void 0 ? void 0 : _b.variables.find((item) => item.key === variableKey);
|
|
208
|
+
if (!variable) {
|
|
209
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.FeatureFlagConfigurationNotFound, featureKey, visitorCode);
|
|
676
210
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
211
|
+
const featureVariable = utilities_1.Utilities.parseFeatureVariable(variable).throw();
|
|
212
|
+
return featureVariable;
|
|
213
|
+
}
|
|
214
|
+
isFeatureFlagActive(visitorCode, featureKey) {
|
|
215
|
+
const variationKey = this.getFeatureFlagVariationKey(visitorCode, featureKey);
|
|
216
|
+
return variationKey !== constants_1.OFF_VARIATION_KEY;
|
|
217
|
+
}
|
|
218
|
+
getRemoteData(key) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const remoteData = yield this.requester.getRemoteData(key);
|
|
221
|
+
return remoteData.throw();
|
|
682
222
|
});
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
var _this = this;
|
|
688
|
-
if (subsciptionRequired && !this.realTimeConfigurationService) {
|
|
689
|
-
this.realTimeConfigurationService = new realTimeConfigurationService_1.RealTimeConfigurationService(this.getEventsRequestURL(this.siteCode), function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
690
|
-
return __generator(this, function (_a) {
|
|
691
|
-
switch (_a.label) {
|
|
692
|
-
case 0: return [4 /*yield*/, this.updateCampaignConfiguration(event.ts)];
|
|
693
|
-
case 1:
|
|
694
|
-
_a.sent();
|
|
695
|
-
return [2 /*return*/];
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
}); });
|
|
223
|
+
}
|
|
224
|
+
onConfigurationUpdate(callback) {
|
|
225
|
+
if (!this.campaignConfiguration) {
|
|
226
|
+
throw new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization);
|
|
699
227
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
228
|
+
this.campaignConfiguration.onConfigurationUpdate(callback);
|
|
229
|
+
}
|
|
230
|
+
_getFeatureFlagVariation(visitorCode, featureKey) {
|
|
231
|
+
var _a;
|
|
232
|
+
if (!this.variationConfiguration || !this.campaignConfiguration) {
|
|
233
|
+
return (0, ts_res_1.Err)(new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.Initialization));
|
|
706
234
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
235
|
+
const featureFlags = this.campaignConfiguration.featureFlags;
|
|
236
|
+
const featureFlag = featureFlags.find((item) => item.featureKey === featureKey);
|
|
237
|
+
if (!featureFlag) {
|
|
238
|
+
return (0, ts_res_1.Err)(new kameleoonError_1.KameleoonError(kameleoonError_1.KameleoonException.FeatureFlagConfigurationNotFound, featureKey, visitorCode));
|
|
239
|
+
}
|
|
240
|
+
const targetingData = this.campaignConfiguration.storedTargetingData[visitorCode];
|
|
241
|
+
const variationData = this.variationConfiguration
|
|
242
|
+
.getFeatureFlagVariation({
|
|
243
|
+
visitorCode,
|
|
244
|
+
featureFlag,
|
|
245
|
+
targetingData,
|
|
246
|
+
withAssignment: true,
|
|
247
|
+
})
|
|
248
|
+
.throw();
|
|
249
|
+
if (((_a = variationData.rule) === null || _a === void 0 ? void 0 : _a.type) === campaignConfiguration_1.RuleType.EXPERIMENTATION) {
|
|
250
|
+
const userAgent = utilities_1.Utilities.getUserAgent(visitorCode, this.campaignConfiguration);
|
|
251
|
+
utilities_1.Utilities.trackExperimentationRule({
|
|
252
|
+
visitorCode,
|
|
253
|
+
requester: this.requester,
|
|
254
|
+
featureFlagVariation: variationData,
|
|
255
|
+
campaignConfiguration: this.campaignConfiguration,
|
|
256
|
+
userAgent,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
return (0, ts_res_1.Ok)(variationData);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
716
262
|
exports.KameleoonClient = KameleoonClient;
|
|
717
|
-
var KameleoonException = {
|
|
718
|
-
ExperimentConfigurationNotFound: experimentConfigurationNotFound_1.default,
|
|
719
|
-
FeatureConfigurationNotFound: featureConfigurationNotFound_1.default,
|
|
720
|
-
VariationConfigurationNotFound: variationConfigurationNotFound_1.default,
|
|
721
|
-
NotTargeted: notTargeted_1.default,
|
|
722
|
-
NotActivated: notActivated_1.default,
|
|
723
|
-
CredentialsNotFound: credentialsNotFound_1.default,
|
|
724
|
-
};
|
|
725
|
-
exports.KameleoonException = KameleoonException;
|
|
726
263
|
//# sourceMappingURL=kameleoonClient.js.map
|