@kameleoon/javascript-sdk-core 0.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +6 -0
- 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/LICENSE.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Copyright 2023 Kameleoon
|
|
2
|
+
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
+
|
|
5
|
+
THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
6
|
+
|
package/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
# Kameleoon
|
|
1
|
+
# Kameleoon JavaScript SDK Core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This package is a core implementation shared between Kameleoon JavaScript Related SDKs.
|
|
4
|
+
It's not meant for direct usage.
|
|
4
5
|
|
|
5
6
|
## Learn more
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
- [JavaScript SDK](https://developers.kameleoon.com/javascript-sdk.html)
|
|
9
|
+
- [NodeJS SDK](https://developers.kameleoon.com/nodejs-sdk.html)
|
|
10
|
+
- [React/React Native SDK](https://developers.kameleoon.com/react-js-sdk.html)
|
|
11
|
+
|
|
8
12
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Result } from 'ts-res';
|
|
2
|
+
import { KameleoonError } from '../kameleoonError/kameleoonError';
|
|
3
|
+
import { CampaignConfigurationParametersType, ConfigurationType, ExperimentItemType, FeatureFlagType } from './types';
|
|
4
|
+
import { KameleoonDataType } from '../kameleoonData';
|
|
5
|
+
import { TargetingDataType } from '../targeting';
|
|
6
|
+
import { IExternalEventSourceConstructor } from '../eventSource';
|
|
7
|
+
interface ICampaignConfiguration {
|
|
8
|
+
initialize: (eventSource: IExternalEventSourceConstructor) => Promise<Result<void, KameleoonError>>;
|
|
9
|
+
addTargetingData: (visitorCode: string, ...data: KameleoonDataType[]) => Result<void, KameleoonError>;
|
|
10
|
+
getUnsentData: (visitorCode: string) => KameleoonDataType[];
|
|
11
|
+
clearUnsentData: (visitorCode: string) => void;
|
|
12
|
+
onConfigurationUpdate: (callback: () => void) => void;
|
|
13
|
+
readonly experiments: ExperimentItemType[];
|
|
14
|
+
readonly storedTargetingData: TargetingDataType;
|
|
15
|
+
readonly featureFlags: FeatureFlagType[];
|
|
16
|
+
readonly configuration: ConfigurationType;
|
|
17
|
+
}
|
|
18
|
+
export declare class CampaignConfiguration implements ICampaignConfiguration {
|
|
19
|
+
private configurationUpdateCallback?;
|
|
20
|
+
private updateConfigurationIntervalId;
|
|
21
|
+
private targetingDataIntervalId;
|
|
22
|
+
private unsentTargetingData;
|
|
23
|
+
private targetingData;
|
|
24
|
+
private configurationData;
|
|
25
|
+
private settings;
|
|
26
|
+
private lastUpdate;
|
|
27
|
+
private storage;
|
|
28
|
+
private requester;
|
|
29
|
+
private eventSource?;
|
|
30
|
+
constructor({ settings, storage, requester, }: CampaignConfigurationParametersType);
|
|
31
|
+
initialize(externalEventSource: IExternalEventSourceConstructor): Promise<Result<void, KameleoonError>>;
|
|
32
|
+
addTargetingData(visitorCode: string, ...data: KameleoonDataType[]): Result<void, KameleoonError>;
|
|
33
|
+
getUnsentData(visitorCode: string): KameleoonDataType[];
|
|
34
|
+
clearUnsentData(visitorCode: string): void;
|
|
35
|
+
onConfigurationUpdate(callback: () => void): void;
|
|
36
|
+
get storedTargetingData(): TargetingDataType;
|
|
37
|
+
get experiments(): ExperimentItemType[];
|
|
38
|
+
get featureFlags(): FeatureFlagType[];
|
|
39
|
+
get configuration(): ConfigurationType;
|
|
40
|
+
private checkShouldUpdate;
|
|
41
|
+
private cleanupOutdatedTargetingData;
|
|
42
|
+
private readStorageData;
|
|
43
|
+
private updateClientConfiguration;
|
|
44
|
+
private updateStorageData;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CampaignConfiguration = void 0;
|
|
13
|
+
const ts_res_1 = require("ts-res");
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
|
+
const eventSource_1 = require("../eventSource");
|
|
16
|
+
class CampaignConfiguration {
|
|
17
|
+
constructor({ settings, storage, requester, }) {
|
|
18
|
+
this.updateConfigurationIntervalId = null;
|
|
19
|
+
this.targetingDataIntervalId = null;
|
|
20
|
+
this.unsentTargetingData = {};
|
|
21
|
+
this.targetingData = constants_1.DEFAULT_CAMPAIGN_CONFIGURATION.targetingData;
|
|
22
|
+
this.configurationData = constants_1.DEFAULT_CAMPAIGN_CONFIGURATION.configurationData;
|
|
23
|
+
this.requester = requester;
|
|
24
|
+
this.settings = settings;
|
|
25
|
+
this.lastUpdate = new Date();
|
|
26
|
+
this.storage = storage;
|
|
27
|
+
this.readStorageData();
|
|
28
|
+
// --- Note ---
|
|
29
|
+
// We can not make delayed code execution recoverable, as it might lead
|
|
30
|
+
// to targeting data storage size overflow
|
|
31
|
+
try {
|
|
32
|
+
this.targetingDataIntervalId = setInterval(() => this.cleanupOutdatedTargetingData.call(this, this.targetingData), constants_1.CLEANUP_TARGETING_DATA_INTERVAL);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (this.targetingDataIntervalId) {
|
|
36
|
+
clearInterval(this.targetingDataIntervalId);
|
|
37
|
+
}
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
initialize(externalEventSource) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const shouldUpdate = this.checkShouldUpdate();
|
|
44
|
+
// --- Initial data fetch ---
|
|
45
|
+
if (shouldUpdate) {
|
|
46
|
+
const updateResult = yield this.updateClientConfiguration();
|
|
47
|
+
if (!updateResult.ok) {
|
|
48
|
+
return updateResult;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// --- Note ---
|
|
52
|
+
// Interval is cleaned up in case real time update
|
|
53
|
+
// was activated while initialized client already exists
|
|
54
|
+
if (this.configurationData.configuration.realTimeUpdate) {
|
|
55
|
+
if (this.updateConfigurationIntervalId) {
|
|
56
|
+
clearInterval(this.updateConfigurationIntervalId);
|
|
57
|
+
}
|
|
58
|
+
this.eventSource = new eventSource_1.ExternalEventSource(this.settings.siteCode, externalEventSource);
|
|
59
|
+
const updateEventCallback = (_timeStamp) => {
|
|
60
|
+
this.updateClientConfiguration();
|
|
61
|
+
if (this.configurationUpdateCallback) {
|
|
62
|
+
this.configurationUpdateCallback();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
this.eventSource.open(updateEventCallback);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// --- Note ---
|
|
69
|
+
// Event Source is cleaned up in case real time update
|
|
70
|
+
// was disabled while initialized client already exists
|
|
71
|
+
if (this.eventSource) {
|
|
72
|
+
this.eventSource.close();
|
|
73
|
+
}
|
|
74
|
+
if (this.updateConfigurationIntervalId) {
|
|
75
|
+
clearInterval(this.updateConfigurationIntervalId);
|
|
76
|
+
}
|
|
77
|
+
// --- Note ---
|
|
78
|
+
// Same as targeting data interval we don't want to make failed configuration
|
|
79
|
+
// retrieval recoverable
|
|
80
|
+
try {
|
|
81
|
+
this.updateConfigurationIntervalId = setInterval(this.updateClientConfiguration.bind(this), this.settings.updateInterval);
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
if (this.updateConfigurationIntervalId) {
|
|
85
|
+
clearInterval(this.updateConfigurationIntervalId);
|
|
86
|
+
}
|
|
87
|
+
throw err;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return (0, ts_res_1.Ok)();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
addTargetingData(visitorCode, ...data) {
|
|
94
|
+
if (!(visitorCode in this.targetingData)) {
|
|
95
|
+
this.targetingData[visitorCode] = [];
|
|
96
|
+
}
|
|
97
|
+
data.forEach((dataItem) => {
|
|
98
|
+
// --- Note ---
|
|
99
|
+
// Previous check excludes the failure possibility
|
|
100
|
+
this.targetingData[visitorCode].push({
|
|
101
|
+
data: dataItem.data,
|
|
102
|
+
lastActivityTime: Date.now(),
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
// --- Note ---
|
|
106
|
+
// `targetingData` should not refresh `lastUpdate` time
|
|
107
|
+
const result = this.updateStorageData(this.lastUpdate);
|
|
108
|
+
if (result.ok) {
|
|
109
|
+
data.forEach((dataItem) => {
|
|
110
|
+
if (!this.unsentTargetingData[visitorCode]) {
|
|
111
|
+
this.unsentTargetingData[visitorCode] = [];
|
|
112
|
+
}
|
|
113
|
+
this.unsentTargetingData[visitorCode].push(dataItem);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
getUnsentData(visitorCode) {
|
|
119
|
+
const unsentDataItem = this.unsentTargetingData[visitorCode];
|
|
120
|
+
if (!unsentDataItem) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
return unsentDataItem;
|
|
124
|
+
}
|
|
125
|
+
clearUnsentData(visitorCode) {
|
|
126
|
+
this.unsentTargetingData[visitorCode] = [];
|
|
127
|
+
}
|
|
128
|
+
onConfigurationUpdate(callback) {
|
|
129
|
+
this.configurationUpdateCallback = callback;
|
|
130
|
+
}
|
|
131
|
+
get storedTargetingData() {
|
|
132
|
+
return this.targetingData;
|
|
133
|
+
}
|
|
134
|
+
get experiments() {
|
|
135
|
+
return this.configurationData.experiments;
|
|
136
|
+
}
|
|
137
|
+
get featureFlags() {
|
|
138
|
+
return this.configurationData.featureFlags;
|
|
139
|
+
}
|
|
140
|
+
get configuration() {
|
|
141
|
+
return this.configurationData.configuration;
|
|
142
|
+
}
|
|
143
|
+
checkShouldUpdate() {
|
|
144
|
+
const { featureFlags, experiments, configuration } = this.configurationData;
|
|
145
|
+
const { updateInterval } = this.settings;
|
|
146
|
+
if (!featureFlags.length && !experiments.length) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
if (configuration.realTimeUpdate) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
const lastUpdateTime = this.lastUpdate.getTime();
|
|
153
|
+
const updateWindowEdge = Date.now() - updateInterval;
|
|
154
|
+
return lastUpdateTime < updateWindowEdge;
|
|
155
|
+
}
|
|
156
|
+
cleanupOutdatedTargetingData(data) {
|
|
157
|
+
const currentTime = Date.now();
|
|
158
|
+
const resultTargetingData = Object.assign({}, data);
|
|
159
|
+
for (const [key, value] of Object.entries(resultTargetingData)) {
|
|
160
|
+
if (value) {
|
|
161
|
+
const resultValue = value.filter((item) => {
|
|
162
|
+
const isDataExpired = item.lastActivityTime + constants_1.SESSION_DURATION < currentTime;
|
|
163
|
+
return isDataExpired;
|
|
164
|
+
});
|
|
165
|
+
resultTargetingData[key] = resultValue;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
resultTargetingData[key] = [];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
this.targetingData = resultTargetingData;
|
|
172
|
+
// --- Note ---
|
|
173
|
+
// `targetingData` should not refresh `lastUpdate` time
|
|
174
|
+
this.updateStorageData(this.lastUpdate).throw();
|
|
175
|
+
}
|
|
176
|
+
readStorageData() {
|
|
177
|
+
const result = this.storage.read();
|
|
178
|
+
if (result.ok) {
|
|
179
|
+
const { kameleoonTargetingData, kameleoonConfiguration, lastUpdate } = result.data;
|
|
180
|
+
this.configurationData = kameleoonConfiguration;
|
|
181
|
+
this.targetingData = kameleoonTargetingData;
|
|
182
|
+
this.lastUpdate = new Date(Date.parse(lastUpdate));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
updateClientConfiguration(timeStamp) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const clientConfigurationResult = yield this.requester.getClientConfiguration(timeStamp);
|
|
188
|
+
if (!clientConfigurationResult.ok) {
|
|
189
|
+
return clientConfigurationResult;
|
|
190
|
+
}
|
|
191
|
+
// --- Note ---
|
|
192
|
+
// `featureFlags` field is ommited (v1)
|
|
193
|
+
// instead `featureFlagConfigurations` is used (v2)
|
|
194
|
+
const { configuration, experiments, featureFlagConfigurations } = clientConfigurationResult.data;
|
|
195
|
+
this.configurationData = {
|
|
196
|
+
configuration,
|
|
197
|
+
experiments,
|
|
198
|
+
featureFlags: featureFlagConfigurations,
|
|
199
|
+
};
|
|
200
|
+
const result = this.updateStorageData(new Date());
|
|
201
|
+
if (!result.ok) {
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
return (0, ts_res_1.Ok)(true);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
updateStorageData(lastUpdate) {
|
|
208
|
+
const data = {
|
|
209
|
+
kameleoonTargetingData: this.targetingData,
|
|
210
|
+
kameleoonConfiguration: this.configurationData,
|
|
211
|
+
lastUpdate: lastUpdate.toString(),
|
|
212
|
+
};
|
|
213
|
+
return this.storage.write(data);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.CampaignConfiguration = CampaignConfiguration;
|
|
217
|
+
//# sourceMappingURL=campaignConfiguration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"campaignConfiguration.js","sourceRoot":"","sources":["../../src/campaignConfiguration/campaignConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAoC;AAGpC,2CAIqB;AAarB,gDAIwB;AAmBxB,MAAa,qBAAqB;IAehC,YAAY,EACV,QAAQ,EACR,OAAO,EACP,SAAS,GAC2B;QAjB9B,kCAA6B,GAAwB,IAAI,CAAC;QAC1D,4BAAuB,GAAwB,IAAI,CAAC;QACpD,wBAAmB,GAA4B,EAAE,CAAC;QAClD,kBAAa,GACnB,0CAA8B,CAAC,aAAa,CAAC;QACvC,sBAAiB,GACvB,0CAA8B,CAAC,iBAAiB,CAAC;QAYjD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,IAAI,IAAI,EAAE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AAC;IAClC,CAAC;CACF;AAnRD,sDAmRC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @constant default cleanup interval in millisecons
|
|
3
|
+
* */
|
|
4
|
+
export declare const CLEANUP_TARGETING_DATA_INTERVAL: number;
|
|
5
|
+
/**
|
|
6
|
+
* @constant default session duration in millisecons
|
|
7
|
+
* */
|
|
8
|
+
export declare const SESSION_DURATION: number;
|
|
9
|
+
export declare const DEFAULT_CAMPAIGN_CONFIGURATION: {
|
|
10
|
+
targetingData: {};
|
|
11
|
+
configurationData: {
|
|
12
|
+
experiments: never[];
|
|
13
|
+
featureFlags: never[];
|
|
14
|
+
configuration: {
|
|
15
|
+
realTimeUpdate: boolean;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_CAMPAIGN_CONFIGURATION = exports.SESSION_DURATION = exports.CLEANUP_TARGETING_DATA_INTERVAL = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
/**
|
|
6
|
+
* @constant default cleanup interval in millisecons
|
|
7
|
+
* */
|
|
8
|
+
exports.CLEANUP_TARGETING_DATA_INTERVAL = 30 * types_1.Milliseconds.Minute;
|
|
9
|
+
/**
|
|
10
|
+
* @constant default session duration in millisecons
|
|
11
|
+
* */
|
|
12
|
+
exports.SESSION_DURATION = 30 * types_1.Milliseconds.Minute;
|
|
13
|
+
exports.DEFAULT_CAMPAIGN_CONFIGURATION = {
|
|
14
|
+
targetingData: {},
|
|
15
|
+
configurationData: {
|
|
16
|
+
experiments: [],
|
|
17
|
+
featureFlags: [],
|
|
18
|
+
configuration: {
|
|
19
|
+
realTimeUpdate: false,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/campaignConfiguration/constants.ts"],"names":[],"mappings":";;;AAAA,oCAAwC;AAExC;;KAEK;AACQ,QAAA,+BAA+B,GAAG,EAAE,GAAG,oBAAY,CAAC,MAAM,CAAC;AACxE;;KAEK;AACQ,QAAA,gBAAgB,GAAG,EAAE,GAAG,oBAAY,CAAC,MAAM,CAAC;AAE5C,QAAA,8BAA8B,GAAG;IAC5C,aAAa,EAAE,EAAE;IACjB,iBAAiB,EAAE;QACjB,WAAW,EAAE,EAAE;QACf,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE;YACb,cAAc,EAAE,KAAK;SACtB;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { ConfigurationDataType, CampaignConfigurationType, VariationByExpositionType, FeatureVariableType, ExperimentItemType, RespoolTimeType, FeatureFlagType, RuleItemType, JSONValue, RuleType, JSONType, } from './types';
|
|
2
|
+
export { CampaignConfiguration } from './campaignConfiguration';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CampaignConfiguration = exports.RuleType = void 0;
|
|
4
|
+
var types_1 = require("./types");
|
|
5
|
+
Object.defineProperty(exports, "RuleType", { enumerable: true, get: function () { return types_1.RuleType; } });
|
|
6
|
+
var campaignConfiguration_1 = require("./campaignConfiguration");
|
|
7
|
+
Object.defineProperty(exports, "CampaignConfiguration", { enumerable: true, get: function () { return campaignConfiguration_1.CampaignConfiguration; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/campaignConfiguration/index.ts"],"names":[],"mappings":";;;AAAA,iCAYiB;AAFf,iGAAA,QAAQ,OAAA;AAGV,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ClientSettingsType } from '../clientSettings';
|
|
2
|
+
import { KameleoonDataType } from '../kameleoonData';
|
|
3
|
+
import { Requester } from '../requester';
|
|
4
|
+
import { ClientDataType, IStorage } from '../storage';
|
|
5
|
+
import { SegmentType, TargetingDataType } from '../targeting';
|
|
6
|
+
import { VariableType } from '../types';
|
|
7
|
+
export type ScheduleType = {
|
|
8
|
+
dateStart: string;
|
|
9
|
+
dateEnd: string;
|
|
10
|
+
};
|
|
11
|
+
export type JSONValue = string | number | boolean | {
|
|
12
|
+
[x: string]: JSONValue;
|
|
13
|
+
} | JSONValue[];
|
|
14
|
+
export type JSONType = Record<string | number | symbol, JSONValue> | null;
|
|
15
|
+
export declare enum ExperimentType {
|
|
16
|
+
CLASSIC = "CLASSIC",
|
|
17
|
+
SERVER_SIDE = "SERVER_SIDE",
|
|
18
|
+
DEVELOPER = "DEVELOPER",
|
|
19
|
+
MVT = "MVT",
|
|
20
|
+
HYBRID = "HYBRID"
|
|
21
|
+
}
|
|
22
|
+
export declare enum RuleType {
|
|
23
|
+
PROGRESSIVE_DELIVERY = "PROGRESSIVE_DELIVERY",
|
|
24
|
+
TARGETED_DELIVERY = "TARGETED_DELIVERY",
|
|
25
|
+
EXPERIMENTATION = "EXPERIMENTATION"
|
|
26
|
+
}
|
|
27
|
+
export declare enum FeatureFlagSdkLanguageType {
|
|
28
|
+
ANDROID = "ANDROID",
|
|
29
|
+
SWIFT = "SWIFT",
|
|
30
|
+
JAVA = "JAVA",
|
|
31
|
+
CSHARP = "CSHARP",
|
|
32
|
+
NODEJS = "NODEJS",
|
|
33
|
+
PHP = "PHP",
|
|
34
|
+
RUBY = "RUBY",
|
|
35
|
+
GO = "GO",
|
|
36
|
+
FLUTTER = "FLUTTER",
|
|
37
|
+
REACTJS = "REACTJS"
|
|
38
|
+
}
|
|
39
|
+
export declare enum FeatureStatus {
|
|
40
|
+
ACTIVATED = "ACTIVATED",
|
|
41
|
+
DEACTIVATED = "DEACTIVATED",
|
|
42
|
+
SCHEDULED = "SCHEDULED"
|
|
43
|
+
}
|
|
44
|
+
export type ExperimentItemType = {
|
|
45
|
+
id: string;
|
|
46
|
+
name: string;
|
|
47
|
+
type: ExperimentType;
|
|
48
|
+
siteId: string;
|
|
49
|
+
siteCode: string;
|
|
50
|
+
status: ExperimentStatus;
|
|
51
|
+
siteEnabled: boolean;
|
|
52
|
+
variations: ExperimentVariationType[];
|
|
53
|
+
deviations: DeviationType[];
|
|
54
|
+
respoolTime: RespoolTimeType[];
|
|
55
|
+
segment: SegmentType | null;
|
|
56
|
+
};
|
|
57
|
+
export type ExperimentVariationType = {
|
|
58
|
+
id: string;
|
|
59
|
+
customJson: JSONType;
|
|
60
|
+
};
|
|
61
|
+
export type DeviationType = {
|
|
62
|
+
variationId: string;
|
|
63
|
+
value: number;
|
|
64
|
+
};
|
|
65
|
+
export type RespoolTimeType = {
|
|
66
|
+
variationId: string;
|
|
67
|
+
value: number;
|
|
68
|
+
};
|
|
69
|
+
export declare enum ExperimentStatus {
|
|
70
|
+
DRAFT = "DRAFT",
|
|
71
|
+
ACTIVE = "ACTIVE",
|
|
72
|
+
PAUSED = "PAUSED",
|
|
73
|
+
SCHEDULED = "SCHEDULED",
|
|
74
|
+
STOPPED = "STOPPED",
|
|
75
|
+
USED_AS_PERSONALIZATION = "USED_AS_PERSONALIZATION",
|
|
76
|
+
DEVIATED = "DEVIATED"
|
|
77
|
+
}
|
|
78
|
+
export type FeatureFlagType = {
|
|
79
|
+
id: number;
|
|
80
|
+
featureKey: string;
|
|
81
|
+
variations: FeatureVariationType[];
|
|
82
|
+
defaultVariationKey: string;
|
|
83
|
+
rules: RuleItemType[];
|
|
84
|
+
};
|
|
85
|
+
export type FeatureVariationType = {
|
|
86
|
+
key: string;
|
|
87
|
+
variables: FeatureVariableType[];
|
|
88
|
+
};
|
|
89
|
+
export type FeatureVariableType = {
|
|
90
|
+
key: string;
|
|
91
|
+
type: VariableType;
|
|
92
|
+
value: string | number | boolean;
|
|
93
|
+
};
|
|
94
|
+
export type RuleItemType = {
|
|
95
|
+
type: RuleType;
|
|
96
|
+
order: number;
|
|
97
|
+
exposition: number;
|
|
98
|
+
experimentId: number | null;
|
|
99
|
+
variationByExposition: VariationByExpositionType[];
|
|
100
|
+
segment: SegmentType | null;
|
|
101
|
+
};
|
|
102
|
+
export type VariationByExpositionType = {
|
|
103
|
+
variationKey: string;
|
|
104
|
+
variationId: number | null;
|
|
105
|
+
exposition: number;
|
|
106
|
+
};
|
|
107
|
+
export type ConfigurationDataType = {
|
|
108
|
+
experiments: ExperimentItemType[];
|
|
109
|
+
featureFlags: FeatureFlagType[];
|
|
110
|
+
configuration: ConfigurationType;
|
|
111
|
+
};
|
|
112
|
+
export type ConfigurationType = {
|
|
113
|
+
realTimeUpdate: boolean;
|
|
114
|
+
};
|
|
115
|
+
export type CampaignConfigurationType = {
|
|
116
|
+
targetingData: TargetingDataType;
|
|
117
|
+
configurationData: ConfigurationDataType;
|
|
118
|
+
};
|
|
119
|
+
export type UnsentTargetingDataType = {
|
|
120
|
+
[visitorCode: string]: KameleoonDataType[];
|
|
121
|
+
};
|
|
122
|
+
export type CampaignConfigurationParametersType = {
|
|
123
|
+
settings: ClientSettingsType;
|
|
124
|
+
storage: IStorage<ClientDataType>;
|
|
125
|
+
requester: Requester;
|
|
126
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExperimentStatus = exports.FeatureStatus = exports.FeatureFlagSdkLanguageType = exports.RuleType = exports.ExperimentType = void 0;
|
|
4
|
+
var ExperimentType;
|
|
5
|
+
(function (ExperimentType) {
|
|
6
|
+
ExperimentType["CLASSIC"] = "CLASSIC";
|
|
7
|
+
ExperimentType["SERVER_SIDE"] = "SERVER_SIDE";
|
|
8
|
+
ExperimentType["DEVELOPER"] = "DEVELOPER";
|
|
9
|
+
ExperimentType["MVT"] = "MVT";
|
|
10
|
+
ExperimentType["HYBRID"] = "HYBRID";
|
|
11
|
+
})(ExperimentType = exports.ExperimentType || (exports.ExperimentType = {}));
|
|
12
|
+
var RuleType;
|
|
13
|
+
(function (RuleType) {
|
|
14
|
+
RuleType["PROGRESSIVE_DELIVERY"] = "PROGRESSIVE_DELIVERY";
|
|
15
|
+
RuleType["TARGETED_DELIVERY"] = "TARGETED_DELIVERY";
|
|
16
|
+
RuleType["EXPERIMENTATION"] = "EXPERIMENTATION";
|
|
17
|
+
})(RuleType = exports.RuleType || (exports.RuleType = {}));
|
|
18
|
+
var FeatureFlagSdkLanguageType;
|
|
19
|
+
(function (FeatureFlagSdkLanguageType) {
|
|
20
|
+
FeatureFlagSdkLanguageType["ANDROID"] = "ANDROID";
|
|
21
|
+
FeatureFlagSdkLanguageType["SWIFT"] = "SWIFT";
|
|
22
|
+
FeatureFlagSdkLanguageType["JAVA"] = "JAVA";
|
|
23
|
+
FeatureFlagSdkLanguageType["CSHARP"] = "CSHARP";
|
|
24
|
+
FeatureFlagSdkLanguageType["NODEJS"] = "NODEJS";
|
|
25
|
+
FeatureFlagSdkLanguageType["PHP"] = "PHP";
|
|
26
|
+
FeatureFlagSdkLanguageType["RUBY"] = "RUBY";
|
|
27
|
+
FeatureFlagSdkLanguageType["GO"] = "GO";
|
|
28
|
+
FeatureFlagSdkLanguageType["FLUTTER"] = "FLUTTER";
|
|
29
|
+
FeatureFlagSdkLanguageType["REACTJS"] = "REACTJS";
|
|
30
|
+
})(FeatureFlagSdkLanguageType = exports.FeatureFlagSdkLanguageType || (exports.FeatureFlagSdkLanguageType = {}));
|
|
31
|
+
var FeatureStatus;
|
|
32
|
+
(function (FeatureStatus) {
|
|
33
|
+
FeatureStatus["ACTIVATED"] = "ACTIVATED";
|
|
34
|
+
FeatureStatus["DEACTIVATED"] = "DEACTIVATED";
|
|
35
|
+
FeatureStatus["SCHEDULED"] = "SCHEDULED";
|
|
36
|
+
})(FeatureStatus = exports.FeatureStatus || (exports.FeatureStatus = {}));
|
|
37
|
+
var ExperimentStatus;
|
|
38
|
+
(function (ExperimentStatus) {
|
|
39
|
+
ExperimentStatus["DRAFT"] = "DRAFT";
|
|
40
|
+
ExperimentStatus["ACTIVE"] = "ACTIVE";
|
|
41
|
+
ExperimentStatus["PAUSED"] = "PAUSED";
|
|
42
|
+
ExperimentStatus["SCHEDULED"] = "SCHEDULED";
|
|
43
|
+
ExperimentStatus["STOPPED"] = "STOPPED";
|
|
44
|
+
ExperimentStatus["USED_AS_PERSONALIZATION"] = "USED_AS_PERSONALIZATION";
|
|
45
|
+
ExperimentStatus["DEVIATED"] = "DEVIATED";
|
|
46
|
+
})(ExperimentStatus = exports.ExperimentStatus || (exports.ExperimentStatus = {}));
|
|
47
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/campaignConfiguration/types.ts"],"names":[],"mappings":";;;AAqBA,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,qCAAmB,CAAA;IACnB,6CAA2B,CAAA;IAC3B,yCAAuB,CAAA;IACvB,6BAAW,CAAA;IACX,mCAAiB,CAAA;AACnB,CAAC,EANW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAMzB;AAED,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,yDAA6C,CAAA;IAC7C,mDAAuC,CAAA;IACvC,+CAAmC,CAAA;AACrC,CAAC,EAJW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAInB;AAED,IAAY,0BAWX;AAXD,WAAY,0BAA0B;IACpC,iDAAmB,CAAA;IACnB,6CAAe,CAAA;IACf,2CAAa,CAAA;IACb,+CAAiB,CAAA;IACjB,+CAAiB,CAAA;IACjB,yCAAW,CAAA;IACX,2CAAa,CAAA;IACb,uCAAS,CAAA;IACT,iDAAmB,CAAA;IACnB,iDAAmB,CAAA;AACrB,CAAC,EAXW,0BAA0B,GAA1B,kCAA0B,KAA1B,kCAA0B,QAWrC;AAED,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,wCAAuB,CAAA;IACvB,4CAA2B,CAAA;IAC3B,wCAAuB,CAAA;AACzB,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB;AA+BD,IAAY,gBAQX;AARD,WAAY,gBAAgB;IAC1B,mCAAe,CAAA;IACf,qCAAiB,CAAA;IACjB,qCAAiB,CAAA;IACjB,2CAAuB,CAAA;IACvB,uCAAmB,CAAA;IACnB,uEAAmD,CAAA;IACnD,yCAAqB,CAAA;AACvB,CAAC,EARW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAQ3B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SDKConfigurationType } from '../types';
|
|
2
|
+
import { ClientSettingsType } from './types';
|
|
3
|
+
export interface IClientSettings {
|
|
4
|
+
readonly settings: ClientSettingsType;
|
|
5
|
+
}
|
|
6
|
+
export declare class ClientSettings implements IClientSettings {
|
|
7
|
+
private updateInterval;
|
|
8
|
+
private environment;
|
|
9
|
+
private siteCode;
|
|
10
|
+
constructor(siteCode: string, configuration?: Partial<SDKConfigurationType>);
|
|
11
|
+
get settings(): ClientSettingsType;
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientSettings = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class ClientSettings {
|
|
6
|
+
constructor(siteCode, configuration) {
|
|
7
|
+
this.updateInterval = 30 * types_1.Milliseconds.Minute;
|
|
8
|
+
this.environment = null;
|
|
9
|
+
this.siteCode = siteCode;
|
|
10
|
+
if (configuration === null || configuration === void 0 ? void 0 : configuration.environment) {
|
|
11
|
+
this.environment = configuration.environment;
|
|
12
|
+
}
|
|
13
|
+
if (configuration === null || configuration === void 0 ? void 0 : configuration.updateInterval) {
|
|
14
|
+
if (configuration.updateInterval < 1) {
|
|
15
|
+
this.updateInterval = 1 * types_1.Milliseconds.Minute;
|
|
16
|
+
}
|
|
17
|
+
this.updateInterval = configuration.updateInterval * types_1.Milliseconds.Minute;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
get settings() {
|
|
21
|
+
return {
|
|
22
|
+
updateInterval: this.updateInterval,
|
|
23
|
+
environment: this.environment,
|
|
24
|
+
siteCode: this.siteCode,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ClientSettings = ClientSettings;
|
|
29
|
+
//# sourceMappingURL=clientSettings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSettings.js","sourceRoot":"","sources":["../../src/clientSettings/clientSettings.ts"],"names":[],"mappings":";;;AAAA,oCAA2E;AAO3E,MAAa,cAAc;IAKzB,YAAY,QAAgB,EAAE,aAA6C;QAJnE,mBAAc,GAAW,EAAE,GAAG,oBAAY,CAAC,MAAM,CAAC;QAClD,gBAAW,GAAuB,IAAI,CAAC;QAI7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,IAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,WAAW,EAAE;YAC9B,IAAI,CAAC,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC;SAC9C;QAED,IAAI,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,cAAc,EAAE;YACjC,IAAI,aAAa,CAAC,cAAc,GAAG,CAAC,EAAE;gBACpC,IAAI,CAAC,cAAc,GAAG,CAAC,GAAG,oBAAY,CAAC,MAAM,CAAC;aAC/C;YAED,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC,cAAc,GAAG,oBAAY,CAAC,MAAM,CAAC;SAC1E;IACH,CAAC;IAED,IAAI,QAAQ;QACV,OAAO;YACL,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC;IACJ,CAAC;CACF;AA5BD,wCA4BC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientSettings = void 0;
|
|
4
|
+
var clientSettings_1 = require("./clientSettings");
|
|
5
|
+
Object.defineProperty(exports, "ClientSettings", { enumerable: true, get: function () { return clientSettings_1.ClientSettings; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/clientSettings/index.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAAzC,gHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/clientSettings/types.ts"],"names":[],"mappings":""}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare const API_DATA_URL = "https://api-data.kameleoon.com/";
|
|
12
|
-
export declare const CONFIGURATION_URL = "https://client-config.kameleoon.com/";
|
|
13
|
-
export declare enum ConditionTypes {
|
|
14
|
-
CUSTOM_DATUM = "CUSTOM_DATUM",
|
|
15
|
-
EXCLUSIVE_EXPERIMENT = "EXCLUSIVE_EXPERIMENT",
|
|
16
|
-
TARGET_EXPERIMENT = "TARGET_EXPERIMENT"
|
|
1
|
+
export declare const UNALLOCATED_VARIATION_ID = 0;
|
|
2
|
+
export declare const OFF_VARIATION_KEY = "off";
|
|
3
|
+
export declare const KAMELEOON_COOKIE_KEY = "kameleoonVisitorCode";
|
|
4
|
+
export declare const VISITOR_CODE_LENGTH = 16;
|
|
5
|
+
export declare enum Cookie {
|
|
6
|
+
PairsDelimiter = "; ",
|
|
7
|
+
KeyValueDelimiter = "=",
|
|
8
|
+
MaxAge = "MaxAge",
|
|
9
|
+
Path = "Path",
|
|
10
|
+
Domain = "Domain"
|
|
17
11
|
}
|